import{S as Se,i as ze,s as Re,k as D,l as H,m as P,h as y,n as g,b as Q,F as v,A as Ve,H as ft,I as ye,a as U,q as j,J as ke,c as V,r as A,p as ve,K as ie,u as he,v as ut,w as ht,L as je,x as dt,f as te,t as ce,y as pt,M as gt,N as Ct,O as Ae,P as Fe,d as mt,G as Ge,o as Mt,e as Je,g as bt,Q as T,R as Pt}from"../../chunks/index-5559954d.js";import{w as xt}from"../../chunks/index-3bda1050.js";if(!Y)var Y={map:function(e,t){var r={};return t?e.map(function(s,n){return r.index=n,t.call(r,s)}):e.slice()},naturalOrder:function(e,t){return et?1:0},sum:function(e,t){var r={};return e.reduce(t?function(s,n,i){return r.index=i,s+t.call(r,n)}:function(s,n){return s+n},0)},max:function(e,t){return Math.max.apply(null,t?Y.map(e,t):e)}};var Dt=function(){var e=5,t=8-e,r=1e3,s=.75;function n(c,a,h){return(c<<2*e)+(a<>t;return gval=c[1]>>t,bval=c[2]>>t,h>=a.r1&&h<=a.r2&&gval>=a.g1&&gval<=a.g2&&bval>=a.b1&&bval<=a.b2}};function o(){this.vboxes=new i(function(c,a){return Y.naturalOrder(c.vbox.count()*c.vbox.volume(),a.vbox.count()*a.vbox.volume())})}o.prototype={push:function(c){this.vboxes.push({vbox:c,color:c.avg()})},palette:function(){return this.vboxes.map(function(c){return c.color})},size:function(){return this.vboxes.size()},map:function(c){for(var a=this.vboxes,h=0;h251&&u[1]>251&&u[2]>251&&(c[h].color=[255,255,255])}};function f(c){var a=1<<3*e,h=new Array(a),u,b,x,N;return c.forEach(function(d){b=d[0]>>t,x=d[1]>>t,N=d[2]>>t,u=n(b,x,N),h[u]=(h[u]||0)+1}),h}function _(c,a){var h=1e6,u=0,b=1e6,x=0,N=1e6,d=0,w,p,m;return c.forEach(function(k){w=k[0]>>t,p=k[1]>>t,m=k[2]>>t,wu&&(u=w),px&&(x=p),md&&(d=m)}),new l(h,u,b,x,N,d,a)}function C(c,a){if(!a.count())return;var h=a.r2-a.r1+1,u=a.g2-a.g1+1,b=a.b2-a.b1+1,x=Y.max([h,u,b]);if(a.count()==1)return[a.copy()];var N=0,d=[],w=[],p,m,k,E,I;if(x==h)for(p=a.r1;p<=a.r2;p++){for(E=0,m=a.g1;m<=a.g2;m++)for(k=a.b1;k<=a.b2;k++)I=n(p,m,k),E+=c[I]||0;N+=E,d[p]=N}else if(x==u)for(p=a.g1;p<=a.g2;p++){for(E=0,m=a.r1;m<=a.r2;m++)for(k=a.b1;k<=a.b2;k++)I=n(m,p,k),E+=c[I]||0;N+=E,d[p]=N}else for(p=a.b1;p<=a.b2;p++){for(E=0,m=a.r1;m<=a.r2;m++)for(k=a.g1;k<=a.g2;k++)I=n(m,k,p),E+=c[I]||0;N+=E,d[p]=N}d.forEach(function(B,R){w[R]=N-B});function $(B){var R=B+"1",F=B+"2",X,O,q,S,M,Z=0;for(p=a[R];p<=a[F];p++)if(d[p]>N/2){for(q=a.copy(),S=a.copy(),X=p-a[R],O=a[F]-p,X<=O?M=Math.min(a[F]-1,~~(p+O/2)):M=Math.max(a[R],~~(p-1-X/2));!d[M];)M++;for(Z=w[M];!Z&&d[M-1];)Z=w[--M];return q[F]=M,S[R]=q[F]+1,[q,S]}}return x==h?$("r"):x==u?$("g"):$("b")}function z(c,a){if(!c.length||a<2||a>256)return!1;var h=f(c);h.forEach(function(){});var u=_(c,h),b=new i(function(w,p){return Y.naturalOrder(w.count(),p.count())});b.push(u);function x(w,p){for(var m=1,k=0,E;k=p)||k++>r)return}}x(b,s*a);for(var N=new i(function(w,p){return Y.naturalOrder(w.count()*w.volume(),p.count()*p.volume())});b.size();)N.push(b.pop());x(N,a-N.size());for(var d=new o;N.size();)d.push(N.pop());return d}return{quantize:z}}(),Ht=Dt.quantize;function ge(e,t,r){e.prototype=t.prototype=r,r.constructor=e}function Ie(e,t){var r=Object.create(e.prototype);for(var s in t)r[s]=t[s];return r}function ae(){}var de=.7,Ne=1/de,le="\\s*([+-]?\\d+)\\s*",pe="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",W="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",qt=/^#([0-9a-f]{3,8})$/,St=new RegExp(`^rgb\\(${le},${le},${le}\\)$`),zt=new RegExp(`^rgb\\(${W},${W},${W}\\)$`),Rt=new RegExp(`^rgba\\(${le},${le},${le},${pe}\\)$`),Ot=new RegExp(`^rgba\\(${W},${W},${W},${pe}\\)$`),Bt=new RegExp(`^hsl\\(${pe},${W},${W}\\)$`),Tt=new RegExp(`^hsla\\(${pe},${W},${W},${pe}\\)$`),Qe={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};ge(ae,Oe,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:We,formatHex:We,formatHex8:Lt,formatHsl:Ut,formatRgb:Ke,toString:Ke});function We(){return this.rgb().formatHex()}function Lt(){return this.rgb().formatHex8()}function Ut(){return wt(this).formatHsl()}function Ke(){return this.rgb().formatRgb()}function Oe(e){var t,r;return e=(e+"").trim().toLowerCase(),(t=qt.exec(e))?(r=t[1].length,t=parseInt(t[1],16),r===6?Xe(t):r===3?new L(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):r===8?we(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):r===4?we(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=St.exec(e))?new L(t[1],t[2],t[3],1):(t=zt.exec(e))?new L(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Rt.exec(e))?we(t[1],t[2],t[3],t[4]):(t=Ot.exec(e))?we(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Bt.exec(e))?et(t[1],t[2]/100,t[3]/100,1):(t=Tt.exec(e))?et(t[1],t[2]/100,t[3]/100,t[4]):Qe.hasOwnProperty(e)?Xe(Qe[e]):e==="transparent"?new L(NaN,NaN,NaN,0):null}function Xe(e){return new L(e>>16&255,e>>8&255,e&255,1)}function we(e,t,r,s){return s<=0&&(e=t=r=NaN),new L(e,t,r,s)}function vt(e){return e instanceof ae||(e=Oe(e)),e?(e=e.rgb(),new L(e.r,e.g,e.b,e.opacity)):new L}function Be(e,t,r,s){return arguments.length===1?vt(e):new L(e,t,r,s==null?1:s)}function L(e,t,r,s){this.r=+e,this.g=+t,this.b=+r,this.opacity=+s}ge(L,Be,Ie(ae,{brighter(e){return e=e==null?Ne:Math.pow(Ne,e),new L(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?de:Math.pow(de,e),new L(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new L(ne(this.r),ne(this.g),ne(this.b),Ee(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Ze,formatHex:Ze,formatHex8:Vt,formatRgb:Ye,toString:Ye}));function Ze(){return`#${re(this.r)}${re(this.g)}${re(this.b)}`}function Vt(){return`#${re(this.r)}${re(this.g)}${re(this.b)}${re((isNaN(this.opacity)?1:this.opacity)*255)}`}function Ye(){const e=Ee(this.opacity);return`${e===1?"rgb(":"rgba("}${ne(this.r)}, ${ne(this.g)}, ${ne(this.b)}${e===1?")":`, ${e})`}`}function Ee(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function ne(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function re(e){return e=ne(e),(e<16?"0":"")+e.toString(16)}function et(e,t,r,s){return s<=0?e=t=r=NaN:r<=0||r>=1?e=t=NaN:t<=0&&(e=NaN),new J(e,t,r,s)}function wt(e){if(e instanceof J)return new J(e.h,e.s,e.l,e.opacity);if(e instanceof ae||(e=Oe(e)),!e)return new J;if(e instanceof J)return e;e=e.rgb();var t=e.r/255,r=e.g/255,s=e.b/255,n=Math.min(t,r,s),i=Math.max(t,r,s),l=NaN,o=i-n,f=(i+n)/2;return o?(t===i?l=(r-s)/o+(r0&&f<1?0:l,new J(l,o,f,e.opacity)}function jt(e,t,r,s){return arguments.length===1?wt(e):new J(e,t,r,s==null?1:s)}function J(e,t,r,s){this.h=+e,this.s=+t,this.l=+r,this.opacity=+s}ge(J,jt,Ie(ae,{brighter(e){return e=e==null?Ne:Math.pow(Ne,e),new J(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?de:Math.pow(de,e),new J(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,r=this.l,s=r+(r<.5?r:1-r)*t,n=2*r-s;return new L(Me(e>=240?e-240:e+120,n,s),Me(e,n,s),Me(e<120?e+240:e-120,n,s),this.opacity)},clamp(){return new J(tt(this.h),_e(this.s),_e(this.l),Ee(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Ee(this.opacity);return`${e===1?"hsl(":"hsla("}${tt(this.h)}, ${_e(this.s)*100}%, ${_e(this.l)*100}%${e===1?")":`, ${e})`}`}}));function tt(e){return e=(e||0)%360,e<0?e+360:e}function _e(e){return Math.max(0,Math.min(1,e||0))}function Me(e,t,r){return(e<60?t+(r-t)*e/60:e<180?r:e<240?t+(r-t)*(240-e)/60:t)*255}const At=Math.PI/180,Ft=180/Math.PI,$e=18,_t=.96422,yt=1,kt=.82521,Nt=4/29,oe=6/29,Et=3*oe*oe,Gt=oe*oe*oe;function $t(e){if(e instanceof K)return new K(e.l,e.a,e.b,e.opacity);if(e instanceof ee)return It(e);e instanceof L||(e=vt(e));var t=qe(e.r),r=qe(e.g),s=qe(e.b),n=Pe((.2225045*t+.7168786*r+.0606169*s)/yt),i,l;return t===r&&r===s?i=l=n:(i=Pe((.4360747*t+.3850649*r+.1430804*s)/_t),l=Pe((.0139322*t+.0971045*r+.7141733*s)/kt)),new K(116*n-16,500*(i-n),200*(n-l),e.opacity)}function Jt(e,t,r,s){return arguments.length===1?$t(e):new K(e,t,r,s==null?1:s)}function K(e,t,r,s){this.l=+e,this.a=+t,this.b=+r,this.opacity=+s}ge(K,Jt,Ie(ae,{brighter(e){return new K(this.l+$e*(e==null?1:e),this.a,this.b,this.opacity)},darker(e){return new K(this.l-$e*(e==null?1:e),this.a,this.b,this.opacity)},rgb(){var e=(this.l+16)/116,t=isNaN(this.a)?e:e+this.a/500,r=isNaN(this.b)?e:e-this.b/200;return t=_t*De(t),e=yt*De(e),r=kt*De(r),new L(He(3.1338561*t-1.6168667*e-.4906146*r),He(-.9787684*t+1.9161415*e+.033454*r),He(.0719453*t-.2289914*e+1.4052427*r),this.opacity)}}));function Pe(e){return e>Gt?Math.pow(e,1/3):e/Et+Nt}function De(e){return e>oe?e*e*e:Et*(e-Nt)}function He(e){return 255*(e<=.0031308?12.92*e:1.055*Math.pow(e,1/2.4)-.055)}function qe(e){return(e/=255)<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function Qt(e){if(e instanceof ee)return new ee(e.h,e.c,e.l,e.opacity);if(e instanceof K||(e=$t(e)),e.a===0&&e.b===0)return new ee(NaN,0ue(t)).sort((t,r)=>{const s=t.h,n=r.h;return n-s||isNaN(n)-isNaN(s)})}function Xt(e,t,r){const s=e,n=[];for(let i=0,l,o,f,_,C;i"u"||C>=125)&&(o>250&&f>250&&_>250||n.push([o,f,_]));return n}function Zt(e,t=5,r=1){return new Promise(s=>{const n=new Image;n.onload=async()=>{const i=n.width,l=n.height,o=document.createElement("canvas");o.width=i,o.height=l;const f=o.getContext("2d");f.drawImage(n,0,0,i,l);const _=f.getImageData(0,0,i,l),C=Xt(_.data,i*l,r),c=Ht(C,t).palette(),a=await new Promise(u=>o.toBlob(u,"image/jpeg",.95)),h=c.map(u=>Be(...u));s({colors:Kt(h),imgBlob:a})},n.src=e})}async function Yt(e,t){const r=er(t),s="https://huggingface.co/uploads",i=`color-palette-${crypto.randomUUID().split("-")[0]}-${r}.jpeg`,l=new File([e],i,{type:"image/jpeg"});console.log("uploading image",l);const f=await(await fetch(s,{method:"POST",headers:{"Content-Type":l.type,"X-Requested-With":"XMLHttpRequest"},body:l})).text();return console.log("uploaded images",f),f}function er(e){return e?e.toString().toLowerCase().replace(/\s+/g,"-").replace(/[^\w\-]+/g,"").replace(/\-\-+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}const G=xt(""),se=xt(!1),tr="wss://spaces.huggingface.tech/stabilityai/stable-diffusion/queue/join";function rt(e,t,r){const s=e.slice();return s[6]=t[r],s[8]=r,s}function nt(e){let t,r,s,n,i,l,o=(e[1]===e[8]?"copied":e[6].formatHex())+"",f,_,C,z,c;function a(){return e[4](e[6],e[8])}return{c(){t=D("div"),r=ye("svg"),s=ye("rect"),i=U(),l=D("span"),f=j(o),_=U(),this.h()},l(h){t=H(h,"DIV",{class:!0,style:!0});var u=P(t);r=ke(u,"svg",{class:!0,width:!0,viewBox:!0});var b=P(r);s=ke(b,"rect",{x:!0,y:!0,width:!0,height:!0,fill:!0}),P(s).forEach(y),b.forEach(y),i=V(u),l=H(u,"SPAN",{title:!0,class:!0,style:!0});var x=P(l);f=A(x,o),x.forEach(y),_=V(u),u.forEach(y),this.h()},h(){g(s,"x","0"),g(s,"y","0"),g(s,"width","50"),g(s,"height","50"),g(s,"fill",n=e[6].formatHex()),g(r,"class","block max-w-full aspect-square"),g(r,"width","100"),g(r,"viewBox","0 0 50 50"),g(l,"title","Copy single color"),g(l,"class","absolute bottom-0 text-center text-xs pl-1 font-bold uppercase"),ve(l,"color",e[2](e[6])),g(t,"class",C=(e[1]===e[8]?"":"cursor-pointer")+" aspect-square relative"),ve(t,"background-color",e[6].formatHex())},m(h,u){Q(h,t,u),v(t,r),v(r,s),v(t,i),v(t,l),v(l,f),v(t,_),z||(c=ie(t,"click",a),z=!0)},p(h,u){e=h,u&1&&n!==(n=e[6].formatHex())&&g(s,"fill",n),u&3&&o!==(o=(e[1]===e[8]?"copied":e[6].formatHex())+"")&&he(f,o),u&1&&ve(l,"color",e[2](e[6])),u&2&&C!==(C=(e[1]===e[8]?"":"cursor-pointer")+" aspect-square relative")&&g(t,"class",C),u&1&&ve(t,"background-color",e[6].formatHex())},d(h){h&&y(t),z=!1,c()}}}function rr(e){let t,r,s=e[0],n=[];for(let i=0;i50?ue(_.h,_.c,0).formatHex():ue(_.h,_.c,100).formatHex()}let i=-1;async function l(f,_){i>-1||(r(1,i=_),await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([f],{type:"text/plain"})})]),setTimeout(()=>{r(1,i=-1)},800))}const o=(f,_)=>l(f.formatHex(),_);return e.$$set=f=>{"colors"in f&&r(0,s=f.colors)},[s,i,n,l,o]}class ar extends Se{constructor(t){super(),ze(this,t,nr,rr,Re,{colors:0})}}function sr(e){let t,r,s,n,i,l,o,f,_,C,z,c,a,h,u,b,x,N,d,w=e[0]?"Copied":"Copy",p,m,k,E;return o=new ar({props:{colors:e[2]}}),{c(){t=D("div"),r=D("blockquote"),s=D("p"),n=j(e[3]),i=U(),l=D("div"),ut(o.$$.fragment),f=U(),_=D("div"),C=D("div"),z=D("img"),a=U(),h=D("div"),u=D("div"),b=D("button"),x=j("Remix"),N=U(),d=D("button"),p=j(w),this.h()},l(I){t=H(I,"DIV",{class:!0});var $=P(t);r=H($,"BLOCKQUOTE",{class:!0,title:!0});var B=P(r);s=H(B,"P",{});var R=P(s);n=A(R,e[3]),R.forEach(y),B.forEach(y),i=V($),l=H($,"DIV",{class:!0});var F=P(l);ht(o.$$.fragment,F),F.forEach(y),f=V($),_=H($,"DIV",{class:!0});var X=P(_);C=H(X,"DIV",{class:!0});var O=P(C);z=H(O,"IMG",{loading:!0,class:!0,src:!0,alt:!0}),O.forEach(y),X.forEach(y),a=V($),h=H($,"DIV",{class:!0});var q=P(h);u=H(q,"DIV",{class:!0});var S=P(u);b=H(S,"BUTTON",{class:!0,title:!0});var M=P(b);x=A(M,"Remix"),M.forEach(y),N=V(S),d=H(S,"BUTTON",{class:!0,title:!0});var Z=P(d);p=A(Z,w),Z.forEach(y),S.forEach(y),q.forEach(y),$.forEach(y),this.h()},h(){g(r,"class","row-start-1 mx-auto col-span-6 italic font-semibold max-w-prose text-base text-center line-clamp-3 my-3"),g(r,"title",e[3]),g(l,"class","row-start-3 md:row-start-2 col-span-6 md:col-span-4 flex items-center justify-center"),g(z,"loading","lazy"),g(z,"class","relative max-w-[100px] w-full aspect-square"),je(z.src,c=e[1])||g(z,"src",c),g(z,"alt",e[3]),g(C,"class","relative"),g(_,"class","row-start-2 col-span-6 md:col-span-2 flex justify-center md:justify-end pb-3"),g(b,"class","button svelte-8zu88a"),g(b,"title","Send this prompt to input so you can remix it"),g(d,"class","button svelte-8zu88a"),g(d,"title","Copy all colors to clipboard"),d.disabled=e[0],g(u,"class","flex justify-center items-center"),g(h,"class","row-start-4 col-span-6 md:col-span-2 md:col-start-5 flex justify-center md:justify-end"),g(t,"class","grid grid-cols-6 gap-3")},m(I,$){Q(I,t,$),v(t,r),v(r,s),v(s,n),v(t,i),v(t,l),dt(o,l,null),v(t,f),v(t,_),v(_,C),v(C,z),v(t,a),v(t,h),v(h,u),v(u,b),v(b,x),v(u,N),v(u,d),v(d,p),m=!0,k||(E=[ie(b,"click",e[7]),ie(d,"click",e[8])],k=!0)},p(I,[$]){(!m||$&8)&&he(n,I[3]),(!m||$&8)&&g(r,"title",I[3]);const B={};$&4&&(B.colors=I[2]),o.$set(B),(!m||$&2&&!je(z.src,c=I[1]))&&g(z,"src",c),(!m||$&8)&&g(z,"alt",I[3]),(!m||$&1)&&w!==(w=I[0]?"Copied":"Copy")&&he(p,w),(!m||$&1)&&(d.disabled=I[0])},i(I){m||(te(o.$$.fragment,I),m=!0)},o(I){ce(o.$$.fragment,I),m=!1},d(I){I&&y(t),pt(o),k=!1,gt(E)}}}function ir(e,t,r){let s,n,i;const l=Ct();let{promptData:o}=t,f=!1;async function _(c){f||(r(0,f=!0),await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([c],{type:"text/plain"})})]),setTimeout(()=>{r(0,f=!1)},1e3))}const C=()=>l("remix",{prompt:s}),z=()=>_(n.map(c=>c.formatHex()).join(", "));return e.$$set=c=>{"promptData"in c&&r(6,o=c.promptData)},e.$$.update=()=>{e.$$.dirty&64&&r(3,s=o.prompt),e.$$.dirty&64&&r(2,n=o.images[0].colors.map(c=>Be(c))),e.$$.dirty&64&&r(1,i=o.images[0].imgURL)},[f,i,n,s,l,_,o,C,z]}class lr extends Se{constructor(t){super(),ze(this,t,ir,sr,Re,{promptData:6})}}function at(e,t,r){const s=e.slice();return s[16]=t[r],s}function st(e){let t,r,s,n,i=e[5]&&it();return{c(){t=D("h3"),r=j(e[4]),s=U(),i&&i.c(),n=Je(),this.h()},l(l){t=H(l,"H3",{class:!0});var o=P(t);r=A(o,e[4]),o.forEach(y),s=V(l),i&&i.l(l),n=Je(),this.h()},h(){g(t,"class","text-xs font-bold ml-3 inline-block")},m(l,o){Q(l,t,o),v(t,r),Q(l,s,o),i&&i.m(l,o),Q(l,n,o)},p(l,o){o&16&&he(r,l[4]),l[5]?i||(i=it(),i.c(),i.m(n.parentNode,n)):i&&(i.d(1),i=null)},d(l){l&&y(t),l&&y(s),i&&i.d(l),l&&y(n)}}}function it(e){let t,r;return{c(){t=ye("svg"),r=ye("path"),this.h()},l(s){t=ke(s,"svg",{xmlns:!0,fill:!0,viewBox:!0,class:!0});var n=P(t);r=ke(n,"path",{fill:!0,d:!0}),P(r).forEach(y),n.forEach(y),this.h()},h(){g(r,"fill","currentColor"),g(r,"d","M20 12a8 8 0 0 1-8 8v4a12 12 0 0 0 12-12h-4Zm-2-5.3a8 8 0 0 1 2 5.3h4c0-3-1.1-5.8-3-8l-3 2.7Z"),g(t,"xmlns","http://www.w3.org/2000/svg"),g(t,"fill","none"),g(t,"viewBox","0 0 24 24"),g(t,"class","animate-spin max-w-[1rem] inline-block")},m(s,n){Q(s,t,n),v(t,r)},d(s){s&&y(t)}}}function lt(e){let t,r,s=e[0],n=[];for(let l=0;lce(n[l],1,1,()=>{n[l]=null});return{c(){t=D("div");for(let l=0;l{q=null}),mt())},i(S){R||(te(q),R=!0)},o(S){ce(q),R=!1},d(S){S&&y(t),e[8](null),O&&O.d(),q&&q.d(),F=!1,gt(X)}}}function ct(e){return e.sort((t,r)=>r.id-t.id).map(t=>t.data)}function cr(e,t,r){let s,n,i;Ge(e,G,d=>r(4,n=d)),Ge(e,se,d=>r(5,i=d));const l="/embed/huggingface-projects/color-palette-generator-sd";let o,f,_;Mt(()=>{C();const d=window.setInterval(C,5e3);return()=>{clearInterval(d)}});async function C(){const d=await fetch(l+"/data").then(w=>w.json());(!o||d.length>o.length)&&r(0,o=ct(d))}async function z(d){try{const w=await fetch(l+"/new_palette",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:d.prompt,images:d.images.map(p=>({imgURL:p.imgURL,colors:p.colors.map(m=>m.formatHex())}))})}).then(p=>p.json());r(0,o=ct(w))}catch(w){console.error(w)}}async function c(d){if(!d||i==!0)return;T(G,n="Pending",n),T(se,i=!0,i);const w=crypto.randomUUID(),p={fn_index:2,data:[d,1,40,7.5,Number(Wt())]},m=new WebSocket(tr);m.onopen=async function(k){m.send(JSON.stringify({hash:w}))},m.onclose=k=>{k.wasClean||(T(G,n="Error",n),T(se,i=!1,i))},m.onmessage=async function(k){try{const E=JSON.parse(k.data);switch(T(G,n="",n),E.msg){case"send_data":T(G,n="Sending Data",n),m.send(JSON.stringify(p));break;case"queue_full":T(G,n="Queue full",n),m.close(),T(se,i=!1,i);return;case"estimation":const{msg:I,rank:$,queue_size:B}=E;T(G,n=`On queue ${$}/${B}`,n);break;case"process_generating":T(G,n=E.success?"Generating":"Error",n);break;case"process_completed":try{const R=await a(E.output.data[0],d);z({prompt:d,images:R}),T(G,n=E.success?"Complete":"Error",n)}catch(R){T(G,n=R.message,n)}m.close(),T(se,i=!1,i);return;case"process_starts":T(G,n="Processing",n);break}}catch(E){console.error(E),T(se,i=!1,i),T(G,n="Error",n)}}}async function a(d,w){const p=["#040404","#B7B7B7","#565656","#747474","#6C6C6C"],m=[];for(const k of d){const{colors:E,imgBlob:I}=await Zt(k);if(E.map(R=>R.formatHex().toUpperCase()).every(R=>p.includes(R)))throw console.error("Possible NSFW image"),new Error("Possible NSFW image");const $=await Yt(I,w),B={colors:E,imgURL:$};m.push(B)}return m}function h(d){r(1,f=d.detail.prompt),_.scrollIntoView({behavior:"smooth"}),"parentIFrame"in window&&window.parentIFrame.scrollTo(0,_.offsetTop)}function u(d){Pt[d?"unshift":"push"](()=>{_=d,r(2,_)})}function b(){f=this.value,r(1,f)}const x=()=>c(f),N=()=>c(f);return e.$$.update=()=>{e.$$.dirty&1&&r(3,s=(o==null?void 0:o.length)||0)},[o,f,_,s,n,i,c,h,u,b,x,N]}class hr extends Se{constructor(t){super(),ze(this,t,cr,or,Re,{})}}export{hr as default};