Spaces:
Runtime error
Runtime error
import{S as Ee,i as Ne,s as $e,k as S,l as z,m as M,h as w,n as c,b as J,F as m,A as ue,H as Ge,I as he,a as T,q as j,J as de,c as U,r as F,p as Ce,K as se,u as me,L as Ze,f as Q,g as Je,t as ae,d as Qe,M as Oe,N as Rt,v as He,w as qe,x as Re,y as Le,O as et,P as Se,G as tt,o as Lt,e as rt,Q as W,R as St}from"../../chunks/index-5559954d.js";import{w as kt}from"../../chunks/index-3bda1050.js";if(!oe)var oe={map:function(e,t){var r={};return t?e.map(function(n,s){return r.index=s,t.call(r,n)}):e.slice()},naturalOrder:function(e,t){return e<t?-1:e>t?1:0},sum:function(e,t){var r={};return e.reduce(t?function(n,s,l){return r.index=l,n+t.call(r,s)}:function(n,s){return n+s},0)},max:function(e,t){return Math.max.apply(null,t?oe.map(e,t):e)}};var zt=function(){var e=5,t=8-e,r=1e3,n=.75;function s(u,a,g){return(u<<2*e)+(a<<e)+g}function l(u){var a=[],g=!1;function f(){a.sort(u),g=!0}return{push:function(x){a.push(x),g=!1},peek:function(x){return g||f(),x===void 0&&(x=a.length-1),a[x]},pop:function(){return g||f(),a.pop()},size:function(){return a.length},map:function(x){return a.map(x)},debug:function(){return g||f(),a}}}function i(u,a,g,f,x,b,N){var H=this;H.r1=u,H.r2=a,H.g1=g,H.g2=f,H.b1=x,H.b2=b,H.histo=N}i.prototype={volume:function(u){var a=this;return(!a._volume||u)&&(a._volume=(a.r2-a.r1+1)*(a.g2-a.g1+1)*(a.b2-a.b1+1)),a._volume},count:function(u){var a=this,g=a.histo;if(!a._count_set||u){var f=0,x,b,N,H;for(x=a.r1;x<=a.r2;x++)for(b=a.g1;b<=a.g2;b++)for(N=a.b1;N<=a.b2;N++)H=s(x,b,N),f+=g[H]||0;a._count=f,a._count_set=!0}return a._count},copy:function(){var u=this;return new i(u.r1,u.r2,u.g1,u.g2,u.b1,u.b2,u.histo)},avg:function(u){var a=this,g=a.histo;if(!a._avg||u){var f=0,x=1<<8-e,b=0,N=0,H=0,R,v,$,I,B;for(v=a.r1;v<=a.r2;v++)for($=a.g1;$<=a.g2;$++)for(I=a.b1;I<=a.b2;I++)B=s(v,$,I),R=g[B]||0,f+=R,b+=R*(v+.5)*x,N+=R*($+.5)*x,H+=R*(I+.5)*x;f?a._avg=[~~(b/f),~~(N/f),~~(H/f)]:a._avg=[~~(x*(a.r1+a.r2+1)/2),~~(x*(a.g1+a.g2+1)/2),~~(x*(a.b1+a.b2+1)/2)]}return a._avg},contains:function(u){var a=this,g=u[0]>>t;return gval=u[1]>>t,bval=u[2]>>t,g>=a.r1&&g<=a.r2&&gval>=a.g1&&gval<=a.g2&&bval>=a.b1&&bval<=a.b2}};function o(){this.vboxes=new l(function(u,a){return oe.naturalOrder(u.vbox.count()*u.vbox.volume(),a.vbox.count()*a.vbox.volume())})}o.prototype={push:function(u){this.vboxes.push({vbox:u,color:u.avg()})},palette:function(){return this.vboxes.map(function(u){return u.color})},size:function(){return this.vboxes.size()},map:function(u){for(var a=this.vboxes,g=0;g<a.size();g++)if(a.peek(g).vbox.contains(u))return a.peek(g).color;return this.nearest(u)},nearest:function(u){for(var a=this.vboxes,g,f,x,b=0;b<a.size();b++)f=Math.sqrt(Math.pow(u[0]-a.peek(b).color[0],2)+Math.pow(u[1]-a.peek(b).color[1],2)+Math.pow(u[2]-a.peek(b).color[2],2)),(f<g||g===void 0)&&(g=f,x=a.peek(b).color);return x},forcebw:function(){var u=this.vboxes;u.sort(function(x,b){return oe.naturalOrder(oe.sum(x.color),oe.sum(b.color))});var a=u[0].color;a[0]<5&&a[1]<5&&a[2]<5&&(u[0].color=[0,0,0]);var g=u.length-1,f=u[g].color;f[0]>251&&f[1]>251&&f[2]>251&&(u[g].color=[255,255,255])}};function d(u){var a=1<<3*e,g=new Array(a),f,x,b,N;return u.forEach(function(H){x=H[0]>>t,b=H[1]>>t,N=H[2]>>t,f=s(x,b,N),g[f]=(g[f]||0)+1}),g}function y(u,a){var g=1e6,f=0,x=1e6,b=0,N=1e6,H=0,R,v,$;return u.forEach(function(I){R=I[0]>>t,v=I[1]>>t,$=I[2]>>t,R<g?g=R:R>f&&(f=R),v<x?x=v:v>b&&(b=v),$<N?N=$:$>H&&(H=$)}),new i(g,f,x,b,N,H,a)}function L(u,a){if(!a.count())return;var g=a.r2-a.r1+1,f=a.g2-a.g1+1,x=a.b2-a.b1+1,b=oe.max([g,f,x]);if(a.count()==1)return[a.copy()];var N=0,H=[],R=[],v,$,I,B,E;if(b==g)for(v=a.r1;v<=a.r2;v++){for(B=0,$=a.g1;$<=a.g2;$++)for(I=a.b1;I<=a.b2;I++)E=s(v,$,I),B+=u[E]||0;N+=B,H[v]=N}else if(b==f)for(v=a.g1;v<=a.g2;v++){for(B=0,$=a.r1;$<=a.r2;$++)for(I=a.b1;I<=a.b2;I++)E=s($,v,I),B+=u[E]||0;N+=B,H[v]=N}else for(v=a.b1;v<=a.b2;v++){for(B=0,$=a.r1;$<=a.r2;$++)for(I=a.g1;I<=a.g2;I++)E=s($,I,v),B+=u[E]||0;N+=B,H[v]=N}H.forEach(function(O,q){R[q]=N-O});function C(O){var q=O+"1",p=O+"2",D,h,k,_,P,V=0;for(v=a[q];v<=a[p];v++)if(H[v]>N/2){for(k=a.copy(),_=a.copy(),D=v-a[q],h=a[p]-v,D<=h?P=Math.min(a[p]-1,~~(v+h/2)):P=Math.max(a[q],~~(v-1-D/2));!H[P];)P++;for(V=R[P];!V&&H[P-1];)V=R[--P];return k[p]=P,_[q]=k[p]+1,[k,_]}}return b==g?C("r"):b==f?C("g"):C("b")}function A(u,a){if(!u.length||a<2||a>256)return!1;var g=d(u);g.forEach(function(){});var f=y(u,g),x=new l(function(R,v){return oe.naturalOrder(R.count(),v.count())});x.push(f);function b(R,v){for(var $=1,I=0,B;I<r;){if(B=R.pop(),!B.count()){R.push(B),I++;continue}var E=L(g,B),C=E[0],O=E[1];if(!C||(R.push(C),O&&(R.push(O),$++),$>=v)||I++>r)return}}b(x,n*a);for(var N=new l(function(R,v){return oe.naturalOrder(R.count()*R.volume(),v.count()*v.volume())});x.size();)N.push(x.pop());b(N,a-N.size());for(var H=new o;N.size();)H.push(N.pop());return H}return{quantize:A}}(),Bt=zt.quantize;function Ie(e,t,r){e.prototype=t.prototype=r,r.constructor=e}function Ae(e,t){var r=Object.create(e.prototype);for(var n in t)r[n]=t[n];return r}function be(){}var ye=.7,ze=1/ye,ve="\\s*([+-]?\\d+)\\s*",ke="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",le="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Dt=/^#([0-9a-f]{3,8})$/,Ot=new RegExp(`^rgb\\(${ve},${ve},${ve}\\)$`),At=new RegExp(`^rgb\\(${le},${le},${le}\\)$`),Tt=new RegExp(`^rgba\\(${ve},${ve},${ve},${ke}\\)$`),Ut=new RegExp(`^rgba\\(${le},${le},${le},${ke}\\)$`),Vt=new RegExp(`^hsl\\(${ke},${le},${le}\\)$`),jt=new RegExp(`^hsla\\(${ke},${le},${le},${ke}\\)$`),nt={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};Ie(be,Ke,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:at,formatHex:at,formatHex8:Ft,formatHsl:Wt,formatRgb:st,toString:st});function at(){return this.rgb().formatHex()}function Ft(){return this.rgb().formatHex8()}function Wt(){return Nt(this).formatHsl()}function st(){return this.rgb().formatRgb()}function Ke(e){var t,r;return e=(e+"").trim().toLowerCase(),(t=Dt.exec(e))?(r=t[1].length,t=parseInt(t[1],16),r===6?lt(t):r===3?new G(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):r===8?Pe(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):r===4?Pe(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=Ot.exec(e))?new G(t[1],t[2],t[3],1):(t=At.exec(e))?new G(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Tt.exec(e))?Pe(t[1],t[2],t[3],t[4]):(t=Ut.exec(e))?Pe(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Vt.exec(e))?ct(t[1],t[2]/100,t[3]/100,1):(t=jt.exec(e))?ct(t[1],t[2]/100,t[3]/100,t[4]):nt.hasOwnProperty(e)?lt(nt[e]):e==="transparent"?new G(NaN,NaN,NaN,0):null}function lt(e){return new G(e>>16&255,e>>8&255,e&255,1)}function Pe(e,t,r,n){return n<=0&&(e=t=r=NaN),new G(e,t,r,n)}function Et(e){return e instanceof be||(e=Ke(e)),e?(e=e.rgb(),new G(e.r,e.g,e.b,e.opacity)):new G}function Xe(e,t,r,n){return arguments.length===1?Et(e):new G(e,t,r,n==null?1:n)}function G(e,t,r,n){this.r=+e,this.g=+t,this.b=+r,this.opacity=+n}Ie(G,Xe,Ae(be,{brighter(e){return e=e==null?ze:Math.pow(ze,e),new G(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?ye:Math.pow(ye,e),new G(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new G(pe(this.r),pe(this.g),pe(this.b),Be(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:it,formatHex:it,formatHex8:Gt,formatRgb:ot,toString:ot}));function it(){return`#${ge(this.r)}${ge(this.g)}${ge(this.b)}`}function Gt(){return`#${ge(this.r)}${ge(this.g)}${ge(this.b)}${ge((isNaN(this.opacity)?1:this.opacity)*255)}`}function ot(){const e=Be(this.opacity);return`${e===1?"rgb(":"rgba("}${pe(this.r)}, ${pe(this.g)}, ${pe(this.b)}${e===1?")":`, ${e})`}`}function Be(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function pe(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function ge(e){return e=pe(e),(e<16?"0":"")+e.toString(16)}function ct(e,t,r,n){return n<=0?e=t=r=NaN:r<=0||r>=1?e=t=NaN:t<=0&&(e=NaN),new Z(e,t,r,n)}function Nt(e){if(e instanceof Z)return new Z(e.h,e.s,e.l,e.opacity);if(e instanceof be||(e=Ke(e)),!e)return new Z;if(e instanceof Z)return e;e=e.rgb();var t=e.r/255,r=e.g/255,n=e.b/255,s=Math.min(t,r,n),l=Math.max(t,r,n),i=NaN,o=l-s,d=(l+s)/2;return o?(t===l?i=(r-n)/o+(r<n)*6:r===l?i=(n-t)/o+2:i=(t-r)/o+4,o/=d<.5?l+s:2-l-s,i*=60):o=d>0&&d<1?0:i,new Z(i,o,d,e.opacity)}function Jt(e,t,r,n){return arguments.length===1?Nt(e):new Z(e,t,r,n==null?1:n)}function Z(e,t,r,n){this.h=+e,this.s=+t,this.l=+r,this.opacity=+n}Ie(Z,Jt,Ae(be,{brighter(e){return e=e==null?ze:Math.pow(ze,e),new Z(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?ye:Math.pow(ye,e),new Z(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,n=r+(r<.5?r:1-r)*t,s=2*r-n;return new G(Te(e>=240?e-240:e+120,s,n),Te(e,s,n),Te(e<120?e+240:e-120,s,n),this.opacity)},clamp(){return new Z(ft(this.h),Me(this.s),Me(this.l),Be(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=Be(this.opacity);return`${e===1?"hsl(":"hsla("}${ft(this.h)}, ${Me(this.s)*100}%, ${Me(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ft(e){return e=(e||0)%360,e<0?e+360:e}function Me(e){return Math.max(0,Math.min(1,e||0))}function Te(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 Qt=Math.PI/180,Kt=180/Math.PI,De=18,$t=.96422,It=1,Ct=.82521,Pt=4/29,we=6/29,Mt=3*we*we,Xt=we*we*we;function Ht(e){if(e instanceof ie)return new ie(e.l,e.a,e.b,e.opacity);if(e instanceof ce)return qt(e);e instanceof G||(e=Et(e));var t=Fe(e.r),r=Fe(e.g),n=Fe(e.b),s=Ue((.2225045*t+.7168786*r+.0606169*n)/It),l,i;return t===r&&r===n?l=i=s:(l=Ue((.4360747*t+.3850649*r+.1430804*n)/$t),i=Ue((.0139322*t+.0971045*r+.7141733*n)/Ct)),new ie(116*s-16,500*(l-s),200*(s-i),e.opacity)}function Yt(e,t,r,n){return arguments.length===1?Ht(e):new ie(e,t,r,n==null?1:n)}function ie(e,t,r,n){this.l=+e,this.a=+t,this.b=+r,this.opacity=+n}Ie(ie,Yt,Ae(be,{brighter(e){return new ie(this.l+De*(e==null?1:e),this.a,this.b,this.opacity)},darker(e){return new ie(this.l-De*(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*Ve(t),e=It*Ve(e),r=Ct*Ve(r),new G(je(3.1338561*t-1.6168667*e-.4906146*r),je(-.9787684*t+1.9161415*e+.033454*r),je(.0719453*t-.2289914*e+1.4052427*r),this.opacity)}}));function Ue(e){return e>Xt?Math.pow(e,1/3):e/Mt+Pt}function Ve(e){return e>we?e*e*e:Mt*(e-Pt)}function je(e){return 255*(e<=.0031308?12.92*e:1.055*Math.pow(e,1/2.4)-.055)}function Fe(e){return(e/=255)<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function Zt(e){if(e instanceof ce)return new ce(e.h,e.c,e.l,e.opacity);if(e instanceof ie||(e=Ht(e)),e.a===0&&e.b===0)return new ce(NaN,0<e.l&&e.l<100?0:NaN,e.l,e.opacity);var t=Math.atan2(e.b,e.a)*Kt;return new ce(t<0?t+360:t,Math.sqrt(e.a*e.a+e.b*e.b),e.l,e.opacity)}function _e(e,t,r,n){return arguments.length===1?Zt(e):new ce(e,t,r,n==null?1:n)}function ce(e,t,r,n){this.h=+e,this.c=+t,this.l=+r,this.opacity=+n}function qt(e){if(isNaN(e.h))return new ie(e.l,0,0,e.opacity);var t=e.h*Qt;return new ie(e.l,Math.cos(t)*e.c,Math.sin(t)*e.c,e.opacity)}Ie(ce,_e,Ae(be,{brighter(e){return new ce(this.h,this.c,this.l+De*(e==null?1:e),this.opacity)},darker(e){return new ce(this.h,this.c,this.l-De*(e==null?1:e),this.opacity)},rgb(){return qt(this).rgb()}}));function er(e){return e.map(t=>_e(t)).sort((t,r)=>{const n=t.h,s=r.h;return s-n||isNaN(s)-isNaN(n)})}function tr(e,t,r){const n=e,s=[];for(let l=0,i,o,d,y,L;l<t;l=l+r)i=l*4,o=n[i+0],d=n[i+1],y=n[i+2],L=n[i+3],(typeof L>"u"||L>=125)&&(o>250&&d>250&&y>250||s.push([o,d,y]));return s}function rr(e,t=5,r=1){return new Promise(n=>{const s=new Image;s.onload=async()=>{const l=s.width,i=s.height,o=document.createElement("canvas");o.width=l,o.height=i;const d=o.getContext("2d");d.drawImage(s,0,0,l,i);const y=d.getImageData(0,0,l,i),L=tr(y.data,l*i,r),u=Bt(L,t).palette(),a=document.createElement("canvas");a.width=l/5,a.height=i/5,a.getContext("2d").drawImage(s,0,0,l,i,0,0,l/5,i/5);const f=await new Promise(b=>a.toBlob(b,"image/jpeg",.8)),x=u.map(b=>Xe(...b));n({colors:er(x),imgBlob:f})},s.src=e})}async function nr(e,t){const r=ar(t),n="https://huggingface.co/uploads",l=`color-palette-${crypto.randomUUID().split("-")[0]}-${r}.jpeg`,i=new File([e],l,{type:"image/jpeg"});console.log("uploading image",i);const d=await(await fetch(n,{method:"POST",headers:{"Content-Type":i.type,"X-Requested-With":"XMLHttpRequest"},body:i})).text();return console.log("uploaded images",d),d}function ar(e){return e?e.toString().toLowerCase().replace(/\s+/g,"-").replace(/[^\w\-]+/g,"").replace(/\-\-+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}const X=kt(""),xe=kt(!1),sr="wss://stabilityai-stable-diffusion-1.hf.space/queue/join",ut="";function ht(e,t,r){const n=e.slice();return n[6]=t[r],n[8]=r,n}function dt(e){let t,r,n,s,l,i,o=(e[1]===e[8]?"copied":e[6].formatHex())+"",d,y,L,A,u;function a(){return e[4](e[6],e[8])}return{c(){t=S("div"),r=he("svg"),n=he("rect"),l=T(),i=S("span"),d=j(o),y=T(),this.h()},l(g){t=z(g,"DIV",{class:!0,style:!0});var f=M(t);r=de(f,"svg",{class:!0,width:!0,viewBox:!0});var x=M(r);n=de(x,"rect",{x:!0,y:!0,width:!0,height:!0,fill:!0}),M(n).forEach(w),x.forEach(w),l=U(f),i=z(f,"SPAN",{title:!0,class:!0,style:!0});var b=M(i);d=F(b,o),b.forEach(w),y=U(f),f.forEach(w),this.h()},h(){c(n,"x","0"),c(n,"y","0"),c(n,"width","50"),c(n,"height","50"),c(n,"fill",s=e[6].formatHex()),c(r,"class","block max-w-full aspect-square"),c(r,"width","100"),c(r,"viewBox","0 0 50 50"),c(i,"title","Copy single color"),c(i,"class","absolute bottom-0 text-center text-xs pl-1 font-bold uppercase"),Ce(i,"color",e[2](e[6])),c(t,"class",L=(e[1]===e[8]?"":"cursor-pointer")+" aspect-square relative"),Ce(t,"background-color",e[6].formatHex())},m(g,f){J(g,t,f),m(t,r),m(r,n),m(t,l),m(t,i),m(i,d),m(t,y),A||(u=se(t,"click",a),A=!0)},p(g,f){e=g,f&1&&s!==(s=e[6].formatHex())&&c(n,"fill",s),f&3&&o!==(o=(e[1]===e[8]?"copied":e[6].formatHex())+"")&&me(d,o),f&1&&Ce(i,"color",e[2](e[6])),f&2&&L!==(L=(e[1]===e[8]?"":"cursor-pointer")+" aspect-square relative")&&c(t,"class",L),f&1&&Ce(t,"background-color",e[6].formatHex())},d(g){g&&w(t),A=!1,u()}}}function lr(e){let t,r,n=e[0],s=[];for(let l=0;l<n.length;l+=1)s[l]=dt(ht(e,n,l));return{c(){t=S("div"),r=S("div");for(let l=0;l<s.length;l+=1)s[l].c();this.h()},l(l){t=z(l,"DIV",{class:!0});var i=M(t);r=z(i,"DIV",{class:!0});var o=M(r);for(let d=0;d<s.length;d+=1)s[d].l(o);o.forEach(w),i.forEach(w),this.h()},h(){c(r,"class","flex"),c(t,"class","flex flex-col items-center")},m(l,i){J(l,t,i),m(t,r);for(let o=0;o<s.length;o+=1)s[o].m(r,null)},p(l,[i]){if(i&15){n=l[0];let o;for(o=0;o<n.length;o+=1){const d=ht(l,n,o);s[o]?s[o].p(d,i):(s[o]=dt(d),s[o].c(),s[o].m(r,null))}for(;o<s.length;o+=1)s[o].d(1);s.length=n.length}},i:ue,o:ue,d(l){l&&w(t),Ge(s,l)}}}function ir(e,t,r){let{colors:n}=t;n.length;function s(d){const y=_e(d);return y.l>50?_e(y.h,y.c,0).formatHex():_e(y.h,y.c,100).formatHex()}let l=-1;async function i(d,y){l>-1||(r(1,l=y),await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([d],{type:"text/plain"})})]),setTimeout(()=>{r(1,l=-1)},800))}const o=(d,y)=>i(d.formatHex(),y);return e.$$set=d=>{"colors"in d&&r(0,n=d.colors)},[n,l,s,i,o]}class or extends Ee{constructor(t){super(),Ne(this,t,ir,lr,$e,{colors:0})}}function gt(e,t,r){const n=e.slice();return n[12]=t[r],n[14]=r,n}function pt(e){let t,r;return t=new or({props:{colors:e[4]}}),{c(){He(t.$$.fragment)},l(n){qe(t.$$.fragment,n)},m(n,s){Re(t,n,s),r=!0},p(n,s){const l={};s&16&&(l.colors=n[4]),t.$set(l)},i(n){r||(Q(t.$$.fragment,n),r=!0)},o(n){ae(t.$$.fragment,n),r=!1},d(n){Le(t,n)}}}function mt(e){let t,r,n,s;function l(){return e[8](e[14])}function i(){return e[9](e[14])}return{c(){t=S("button"),this.h()},l(o){t=z(o,"BUTTON",{class:!0}),M(t).forEach(w),this.h()},h(){c(t,"class",r=(e[1]===e[14]?"bg-black dark:bg-white":"bg-white dark:bg-black")+" dark:bg-slate-300 rounded-full h-3 w-3 m-1 border border-black dark:border-white")},m(o,d){J(o,t,d),n||(s=[se(t,"click",l),se(t,"mousemove",i)],n=!0)},p(o,d){e=o,d&2&&r!==(r=(e[1]===e[14]?"bg-black dark:bg-white":"bg-white dark:bg-black")+" dark:bg-slate-300 rounded-full h-3 w-3 m-1 border border-black dark:border-white")&&c(t,"class",r)},d(o){o&&w(t),n=!1,Oe(s)}}}function cr(e){let t,r,n,s,l,i,o,d,y,L,A,u,a,g,f,x,b,N,H,R,v=e[2]?"Copied":"Copy",$,I,B,E,C=e[4]&&pt(e),O=e[0].images,q=[];for(let p=0;p<O.length;p+=1)q[p]=mt(gt(e,O,p));return{c(){t=S("div"),r=S("blockquote"),n=S("p"),s=j(e[5]),l=T(),i=S("div"),C&&C.c(),o=T(),d=S("div"),y=S("div"),L=S("img"),u=T(),a=S("div");for(let p=0;p<q.length;p+=1)q[p].c();g=T(),f=S("div"),x=S("div"),b=S("button"),N=j("Remix"),H=T(),R=S("button"),$=j(v),this.h()},l(p){t=z(p,"DIV",{class:!0});var D=M(t);r=z(D,"BLOCKQUOTE",{class:!0,title:!0});var h=M(r);n=z(h,"P",{});var k=M(n);s=F(k,e[5]),k.forEach(w),h.forEach(w),l=U(D),i=z(D,"DIV",{class:!0});var _=M(i);C&&C.l(_),_.forEach(w),o=U(D),d=z(D,"DIV",{class:!0});var P=M(d);y=z(P,"DIV",{class:!0});var V=M(y);L=z(V,"IMG",{loading:!0,class:!0,src:!0,alt:!0}),u=U(V),a=z(V,"DIV",{class:!0});var K=M(a);for(let ne=0;ne<q.length;ne+=1)q[ne].l(K);K.forEach(w),V.forEach(w),P.forEach(w),g=U(D),f=z(D,"DIV",{class:!0});var ee=M(f);x=z(ee,"DIV",{class:!0});var Y=M(x);b=z(Y,"BUTTON",{class:!0,title:!0});var te=M(b);N=F(te,"Remix"),te.forEach(w),H=U(Y),R=z(Y,"BUTTON",{class:!0,title:!0});var re=M(R);$=F(re,v),re.forEach(w),Y.forEach(w),ee.forEach(w),D.forEach(w),this.h()},h(){c(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"),c(r,"title",e[5]),c(i,"class","row-start-3 md:row-start-2 col-span-6 md:col-span-4 flex items-center justify-center"),c(L,"loading","lazy"),c(L,"class","relative max-w-[100px] w-full aspect-square"),Ze(L.src,A=e[3])||c(L,"src",A),c(L,"alt",e[5]),c(a,"class","absolute flex justify-around w-full"),c(y,"class","relative"),c(d,"class","row-start-2 col-span-6 md:col-span-2 flex justify-center md:justify-end pb-3"),c(b,"class","button svelte-8zu88a"),c(b,"title","Send this prompt to input so you can remix it"),c(R,"class","button svelte-8zu88a"),c(R,"title","Copy all colors to clipboard"),R.disabled=e[2],c(x,"class","flex justify-center items-center"),c(f,"class","row-start-4 col-span-6 md:col-span-2 md:col-start-5 flex justify-center md:justify-end"),c(t,"class","grid grid-cols-6 gap-3")},m(p,D){J(p,t,D),m(t,r),m(r,n),m(n,s),m(t,l),m(t,i),C&&C.m(i,null),m(t,o),m(t,d),m(d,y),m(y,L),m(y,u),m(y,a);for(let h=0;h<q.length;h+=1)q[h].m(a,null);m(t,g),m(t,f),m(f,x),m(x,b),m(b,N),m(x,H),m(x,R),m(R,$),I=!0,B||(E=[se(b,"click",e[10]),se(R,"click",e[11])],B=!0)},p(p,[D]){if((!I||D&32)&&me(s,p[5]),(!I||D&32)&&c(r,"title",p[5]),p[4]?C?(C.p(p,D),D&16&&Q(C,1)):(C=pt(p),C.c(),Q(C,1),C.m(i,null)):C&&(Je(),ae(C,1,1,()=>{C=null}),Qe()),(!I||D&8&&!Ze(L.src,A=p[3]))&&c(L,"src",A),(!I||D&32)&&c(L,"alt",p[5]),D&3){O=p[0].images;let h;for(h=0;h<O.length;h+=1){const k=gt(p,O,h);q[h]?q[h].p(k,D):(q[h]=mt(k),q[h].c(),q[h].m(a,null))}for(;h<q.length;h+=1)q[h].d(1);q.length=O.length}(!I||D&4)&&v!==(v=p[2]?"Copied":"Copy")&&me($,v),(!I||D&4)&&(R.disabled=p[2])},i(p){I||(Q(C),I=!0)},o(p){ae(C),I=!1},d(p){p&&w(t),C&&C.d(),Ge(q,p),B=!1,Oe(E)}}}function fr(e,t,r){let n,s,l;const i=Rt();let{promptData:o}=t,d=0,y=!1;async function L(f){y||(r(2,y=!0),await navigator.clipboard.write([new ClipboardItem({"text/plain":new Blob([f],{type:"text/plain"})})]),setTimeout(()=>{r(2,y=!1)},1e3))}const A=f=>r(1,d=f),u=f=>r(1,d=f),a=()=>i("remix",{prompt:n}),g=()=>L(s.map(f=>f.formatHex()).join(", "));return e.$$set=f=>{"promptData"in f&&r(0,o=f.promptData)},e.$$.update=()=>{var f,x;e.$$.dirty&1&&r(5,n=o==null?void 0:o.prompt),e.$$.dirty&3&&r(4,s=((f=o==null?void 0:o.images[d])==null?void 0:f.colors.map(b=>Xe(b)))||[]),e.$$.dirty&3&&r(3,l=(x=o==null?void 0:o.images[d])==null?void 0:x.imgURL)},[o,d,y,l,s,n,i,L,A,u,a,g]}class ur extends Ee{constructor(t){super(),Ne(this,t,fr,cr,$e,{promptData:0})}}function hr(e){let t,r;return{c(){t=he("svg"),r=he("path"),this.h()},l(n){t=de(n,"svg",{class:!0,xmlns:!0,"xmlns:xlink":!0,"aria-hidden":!0,focusable:!0,role:!0,width:!0,height:!0,preserveAspectRatio:!0,viewBox:!0});var s=M(t);r=de(s,"path",{d:!0,fill:!0}),M(r).forEach(w),s.forEach(w),this.h()},h(){c(r,"d","M10 16L20 6l1.4 1.4l-8.6 8.6l8.6 8.6L20 26z"),c(r,"fill","currentColor"),c(t,"class","ml-1.5 transform rotate-180"),c(t,"xmlns","http://www.w3.org/2000/svg"),c(t,"xmlns:xlink","http://www.w3.org/1999/xlink"),c(t,"aria-hidden","true"),c(t,"focusable","false"),c(t,"role","img"),c(t,"width","1em"),c(t,"height","1em"),c(t,"preserveAspectRatio","xMidYMid meet"),c(t,"viewBox","0 0 32 32")},m(n,s){J(n,t,s),m(t,r)},p:ue,i:ue,o:ue,d(n){n&&w(t)}}}class dr extends Ee{constructor(t){super(),Ne(this,t,null,hr,$e,{})}}function gr(e){let t,r;return{c(){t=he("svg"),r=he("path"),this.h()},l(n){t=de(n,"svg",{class:!0,xmlns:!0,"xmlns:xlink":!0,"aria-hidden":!0,focusable:!0,role:!0,width:!0,height:!0,preserveAspectRatio:!0,viewBox:!0});var s=M(t);r=de(s,"path",{d:!0,fill:!0}),M(r).forEach(w),s.forEach(w),this.h()},h(){c(r,"d","M10 16L20 6l1.4 1.4l-8.6 8.6l8.6 8.6L20 26z"),c(r,"fill","currentColor"),c(t,"class","mr-1.5"),c(t,"xmlns","http://www.w3.org/2000/svg"),c(t,"xmlns:xlink","http://www.w3.org/1999/xlink"),c(t,"aria-hidden","true"),c(t,"focusable","false"),c(t,"role","img"),c(t,"width","1em"),c(t,"height","1em"),c(t,"preserveAspectRatio","xMidYMid meet"),c(t,"viewBox","0 0 32 32")},m(n,s){J(n,t,s),m(t,r)},p:ue,i:ue,o:ue,d(n){n&&w(t)}}}class pr extends Ee{constructor(t){super(),Ne(this,t,null,gr,$e,{})}}function bt(e,t,r){const n=e.slice();return n[22]=t[r],n}function xt(e){let t,r,n,s,l=e[7]&&vt();return{c(){t=S("h3"),r=j(e[6]),n=T(),l&&l.c(),s=rt(),this.h()},l(i){t=z(i,"H3",{class:!0});var o=M(t);r=F(o,e[6]),o.forEach(w),n=U(i),l&&l.l(i),s=rt(),this.h()},h(){c(t,"class","text-xs font-bold ml-3 inline-block")},m(i,o){J(i,t,o),m(t,r),J(i,n,o),l&&l.m(i,o),J(i,s,o)},p(i,o){o&64&&me(r,i[6]),i[7]?l||(l=vt(),l.c(),l.m(s.parentNode,s)):l&&(l.d(1),l=null)},d(i){i&&w(t),i&&w(n),l&&l.d(i),i&&w(s)}}}function vt(e){let t,r;return{c(){t=he("svg"),r=he("path"),this.h()},l(n){t=de(n,"svg",{xmlns:!0,fill:!0,viewBox:!0,class:!0});var s=M(t);r=de(s,"path",{fill:!0,d:!0}),M(r).forEach(w),s.forEach(w),this.h()},h(){c(r,"fill","currentColor"),c(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"),c(t,"xmlns","http://www.w3.org/2000/svg"),c(t,"fill","none"),c(t,"viewBox","0 0 24 24"),c(t,"class","animate-spin max-w-[1rem] inline-block")},m(n,s){J(n,t,s),m(t,r)},d(n){n&&w(t)}}}function wt(e){let t,r,n,s,l,i,o,d,y,L,A,u,a,g=e[0]+1+"",f,x,b,N,H,R,v,$,I,B,E,C,O,q=e[4],p=[];for(let h=0;h<q.length;h+=1)p[h]=_t(bt(e,q,h));const D=h=>ae(p[h],1,1,()=>{p[h]=null});return y=new pr({}),B=new dr({}),{c(){t=S("div");for(let h=0;h<p.length;h+=1)p[h].c();r=T(),n=S("nav"),s=S("ul"),l=S("li"),i=T(),o=S("li"),d=S("a"),He(y.$$.fragment),L=j(" Previous"),A=T(),u=S("li"),a=S("span"),f=j(g),x=T(),b=j("/"),N=S("span"),H=j(e[1]),R=T(),v=S("li"),$=S("a"),I=j("Next "),He(B.$$.fragment),this.h()},l(h){t=z(h,"DIV",{});var k=M(t);for(let fe=0;fe<p.length;fe+=1)p[fe].l(k);k.forEach(w),r=U(h),n=z(h,"NAV",{role:!0});var _=M(n);s=z(_,"UL",{class:!0});var P=M(s);l=z(P,"LI",{}),M(l).forEach(w),i=U(P),o=z(P,"LI",{});var V=M(o);d=z(V,"A",{class:!0,href:!0});var K=M(d);qe(y.$$.fragment,K),L=F(K," Previous"),K.forEach(w),V.forEach(w),A=U(P),u=z(P,"LI",{class:!0});var ee=M(u);a=z(ee,"SPAN",{class:!0});var Y=M(a);f=F(Y,g),x=U(Y),Y.forEach(w),b=F(ee,"/"),N=z(ee,"SPAN",{class:!0});var te=M(N);H=F(te,e[1]),te.forEach(w),ee.forEach(w),R=U(P),v=z(P,"LI",{});var re=M(v);$=z(re,"A",{class:!0,href:!0});var ne=M($);I=F(ne,"Next "),qe(B.$$.fragment,ne),ne.forEach(w),re.forEach(w),P.forEach(w),_.forEach(w),this.h()},h(){c(d,"class","px-2.5 py-1 hover:bg-gray-50 dark:hover:bg-gray-800 flex items-center rounded-lg"),c(d,"href","#"),c(a,"class","inline-block min-w-[3ch] text-right"),c(N,"class","inline-block min-w-[3ch]"),c(u,"class","text-sm"),c($,"class","px-2.5 py-1 hover:bg-gray-50 dark:hover:bg-gray-800 flex items-center rounded-lg"),c($,"href","#"),c(s,"class","items-center sm:justify-center space-x-2 select-none w-full flex justify-center mt-6 mb-4"),c(n,"role","navigation")},m(h,k){J(h,t,k);for(let _=0;_<p.length;_+=1)p[_].m(t,null);J(h,r,k),J(h,n,k),m(n,s),m(s,l),m(s,i),m(s,o),m(o,d),Re(y,d,null),m(d,L),m(s,A),m(s,u),m(u,a),m(a,f),m(a,x),m(u,b),m(u,N),m(N,H),m(s,R),m(s,v),m(v,$),m($,I),Re(B,$,null),E=!0,C||(O=[se(d,"click",Se(e[17])),se($,"click",Se(e[18]))],C=!0)},p(h,k){if(k&528){q=h[4];let _;for(_=0;_<q.length;_+=1){const P=bt(h,q,_);p[_]?(p[_].p(P,k),Q(p[_],1)):(p[_]=_t(P),p[_].c(),Q(p[_],1),p[_].m(t,null))}for(Je(),_=q.length;_<p.length;_+=1)D(_);Qe()}(!E||k&1)&&g!==(g=h[0]+1+"")&&me(f,g),(!E||k&2)&&me(H,h[1])},i(h){if(!E){for(let k=0;k<q.length;k+=1)Q(p[k]);Q(y.$$.fragment,h),Q(B.$$.fragment,h),E=!0}},o(h){p=p.filter(Boolean);for(let k=0;k<p.length;k+=1)ae(p[k]);ae(y.$$.fragment,h),ae(B.$$.fragment,h),E=!1},d(h){h&&w(t),Ge(p,h),h&&w(r),h&&w(n),Le(y),Le(B),C=!1,Oe(O)}}}function _t(e){let t,r,n,s;return t=new ur({props:{promptData:e[22]}}),t.$on("remix",e[9]),{c(){He(t.$$.fragment),r=T(),n=S("div"),this.h()},l(l){qe(t.$$.fragment,l),r=U(l),n=z(l,"DIV",{class:!0}),M(n).forEach(w),this.h()},h(){c(n,"class","border-b border-gray-200 py-2")},m(l,i){Re(t,l,i),J(l,r,i),J(l,n,i),s=!0},p(l,i){const o={};i&16&&(o.promptData=l[22]),t.$set(o)},i(l){s||(Q(t.$$.fragment,l),s=!0)},o(l){ae(t.$$.fragment,l),s=!1},d(l){Le(t,l),l&&w(r),l&&w(n)}}}function mr(e){let t,r,n,s,l,i,o,d,y,L,A,u,a,g,f,x,b,N,H,R,v,$,I=e[5]?`${e[5]} submitted palettes`:"Loading...",B,E,C,O,q,p,D,h=e[6]&&xt(e),k=e[4]&&wt(e);return{c(){t=S("div"),r=S("h1"),n=j("Palette generation with Stable Diffusion"),s=T(),l=S("p"),i=j(`Original ideas: | |
`),o=S("a"),d=j(`Matt DesLauriers | |
`),y=j(`, | |
`),L=S("a"),A=j("dribnet"),u=T(),a=S("div"),g=S("form"),f=S("input"),x=T(),b=S("button"),N=j("Create Palette"),H=T(),h&&h.c(),R=T(),v=S("div"),$=S("div"),B=j(I),E=T(),C=S("div"),O=T(),k&&k.c(),this.h()},l(_){t=z(_,"DIV",{class:!0});var P=M(t);r=z(P,"H1",{class:!0});var V=M(r);n=F(V,"Palette generation with Stable Diffusion"),V.forEach(w),s=U(P),l=z(P,"P",{class:!0});var K=M(l);i=F(K,`Original ideas: | |
`),o=z(K,"A",{class:!0,target:!0,rel:!0,href:!0});var ee=M(o);d=F(ee,`Matt DesLauriers | |
`),ee.forEach(w),y=F(K,`, | |
`),L=z(K,"A",{class:!0,href:!0});var Y=M(L);A=F(Y,"dribnet"),Y.forEach(w),K.forEach(w),u=U(P),a=z(P,"DIV",{class:!0});var te=M(a);g=z(te,"FORM",{class:!0});var re=M(g);f=z(re,"INPUT",{class:!0,placeholder:!0,title:!0,type:!0,name:!0}),x=U(re),b=z(re,"BUTTON",{class:!0,title:!0});var ne=M(b);N=F(ne,"Create Palette"),ne.forEach(w),re.forEach(w),H=U(te),h&&h.l(te),te.forEach(w),R=U(P),v=z(P,"DIV",{class:!0});var fe=M(v);$=z(fe,"DIV",{class:!0});var Ye=M($);B=F(Ye,I),Ye.forEach(w),E=U(fe),C=z(fe,"DIV",{class:!0}),M(C).forEach(w),fe.forEach(w),O=U(P),k&&k.l(P),P.forEach(w),this.h()},h(){c(r,"class","text-3xl font-bold leading-normal"),c(o,"class","link svelte-zbscw1"),c(o,"target","_blank"),c(o,"rel","nofollow noopener"),c(o,"href","https://twitter.com/mattdesl/status/1569457653298139136"),c(L,"class","link svelte-zbscw1"),c(L,"href","https://drib.net/homage"),c(l,"class","text-sm"),c(f,"class","input svelte-zbscw1"),c(f,"placeholder","A photo of a beautiful sunset in San Francisco"),c(f,"title","Input prompt to generate image and obtain palette"),c(f,"type","text"),c(f,"name","prompt"),f.disabled=e[7],c(b,"class","button svelte-zbscw1"),b.disabled=e[7],c(b,"title","Generate Palette"),c(g,"class","grid grid-cols-6"),c(a,"class","relative top-0 z-50 bg-white dark:bg-black py-3"),c($,"class","font-bold text-sm"),c(C,"class","grow border-b border-gray-200"),c(v,"class","flex items-center gap-4 my-10"),c(t,"class","max-w-screen-md mx-auto px-3 py-8 relative z-0")},m(_,P){J(_,t,P),m(t,r),m(r,n),m(t,s),m(t,l),m(l,i),m(l,o),m(o,d),m(l,y),m(l,L),m(L,A),m(t,u),m(t,a),m(a,g),m(g,f),e[13](f),et(f,e[2]),m(g,x),m(g,b),m(b,N),m(a,H),h&&h.m(a,null),m(t,R),m(t,v),m(v,$),m($,B),m(v,E),m(v,C),m(t,O),k&&k.m(t,null),q=!0,p||(D=[se(f,"input",e[14]),se(b,"click",Se(e[15])),se(g,"submit",Se(e[16]))],p=!0)},p(_,[P]){(!q||P&128)&&(f.disabled=_[7]),P&4&&f.value!==_[2]&&et(f,_[2]),(!q||P&128)&&(b.disabled=_[7]),_[6]?h?h.p(_,P):(h=xt(_),h.c(),h.m(a,null)):h&&(h.d(1),h=null),(!q||P&32)&&I!==(I=_[5]?`${_[5]} submitted palettes`:"Loading...")&&me(B,I),_[4]?k?(k.p(_,P),P&16&&Q(k,1)):(k=wt(_),k.c(),Q(k,1),k.m(t,null)):k&&(Je(),ae(k,1,1,()=>{k=null}),Qe())},i(_){q||(Q(k),q=!0)},o(_){ae(k),q=!1},d(_){_&&w(t),e[13](null),h&&h.d(),k&&k.d(),p=!1,Oe(D)}}}const We=10;function yt(e){return e.sort((t,r)=>r.id-t.id).map(t=>t.data).filter(t=>t.images.length>0)}function br(e,t,r){let n,s,l,i,o;tt(e,X,E=>r(6,i=E)),tt(e,xe,E=>r(7,o=E));let d=[],y,L;Lt(()=>{A();const E=window.setInterval(A,5e3);return()=>{clearInterval(E)}});async function A(){const E=await fetch(ut+"/data").then(C=>C.json());(!d||(E==null?void 0:E.length)>(d==null?void 0:d.length))&&r(11,d=yt(E))}let u=0,a=[];async function g(E){try{const C=await fetch(ut+"/new_palette",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:E.prompt,images:E.images.map(O=>({imgURL:O.imgURL,colors:O.colors.map(q=>q.formatHex())}))})}).then(O=>O.json());r(11,d=yt(C))}catch(C){console.error(C)}}async function f(E){if(!E||o==!0)return;W(X,i="Pending",i),W(xe,o=!0,o);const C=crypto.randomUUID(),O={fn_index:2,session_hash:C},q={data:[E]},p=new WebSocket(sr);p.onclose=D=>{D.wasClean||(W(X,i="Error",i),W(xe,o=!1,o))},p.onmessage=async function(D){try{const h=JSON.parse(D.data);switch(W(X,i="",i),h.msg){case"send_hash":p.send(JSON.stringify(O));break;case"send_data":W(X,i="Sending Data",i),p.send(JSON.stringify({...O,...q}));break;case"queue_full":W(X,i="Queue full",i),p.close(),W(xe,o=!1,o);return;case"estimation":const{msg:k,rank:_,queue_size:P}=h;W(X,i=`On queue ${_}/${P}`,i);break;case"process_generating":W(X,i=h.success?"Generating":"Error",i);break;case"process_completed":try{const V=await x(h.output.data[0],E);g({prompt:E,images:V}),W(X,i=h.success?"Complete":"Error",i)}catch(V){W(X,i=V.message,i)}p.close(),W(xe,o=!1,o);return;case"process_starts":W(X,i="Processing",i);break}}catch(h){console.error(h),W(xe,o=!1,o),W(X,i="Error",i)}}}async function x(E,C){const O=["#040404","#B7B7B7","#565656","#747474","#6C6C6C"],q=[];let p=!1;for(const D of E){const{colors:h,imgBlob:k}=await rr(D);if(h.map(_=>_.formatHex().toUpperCase()).every(_=>O.includes(_)))p=!0;else{const _=await nr(k,C),P={colors:h,imgURL:_};q.push(P)}}if(q.length===0&&p)throw console.error("Possible NSFW image"),new Error("Possible NSFW image");return q}function b(E){r(2,y=E.detail.prompt),L.scrollIntoView({behavior:"smooth"}),N()}function N(){window.scrollTo(0,0),"parentIFrame"in window&&window.parentIFrame.scrollTo(0,L.offsetTop)}function H(E){St[E?"unshift":"push"](()=>{L=E,r(3,L)})}function R(){y=this.value,r(2,y)}const v=()=>f(y),$=()=>f(y),I=()=>{r(0,u=u-1<0?0:u-1),N()},B=()=>{r(0,u=u+1>=s-1?s-1:u+1),N()};return e.$$.update=()=>{if(e.$$.dirty&2048&&r(5,n=(d==null?void 0:d.length)||null),e.$$.dirty&2048&&r(1,s=Math.ceil((d==null?void 0:d.length)/We)||0),e.$$.dirty&2049&&r(4,l=[...d].slice(u*We,(u+1)*We)),e.$$.dirty&4098&&s){const E=Array(s).fill([]).map((C,O)=>({value:O,label:O+1}));r(12,a=E.slice(0,3).concat([{value:-1,label:"..."}]).concat(E.length>3?E.slice(-1):[])),console.log(a)}},[u,s,y,L,l,n,i,o,f,b,N,d,a,H,R,v,$,I,B]}class wr extends Ee{constructor(t){super(),Ne(this,t,br,mr,$e,{})}}export{wr as default}; | |