Spaces:
Running
Running
import{S as se,i as ne,s as re,k as v,a as V,q as G,H as oe,l as y,m as S,h as c,c as U,r as Q,n as i,I as J,F as d,b as X,J as Z,K as $,A as ee,L as ie,o as le,z as ce,M as de,N as te}from"../../chunks/index-3db9fbe0.js";const{document:W}=de;function pe(f){let j,a,k,h,z,l,g,M,m,E,w,p,s,o,q,_,u,F,D,R,P,L,B,O,e,n,b;return{c(){j=v("link"),a=v("script"),h=v("script"),l=v("script"),M=V(),m=v("div"),E=v("canvas"),p=V(),s=v("div"),o=v("div"),q=V(),_=v("div"),u=v("input"),F=V(),D=v("button"),R=G("diffuse the f rest"),L=V(),B=v("p"),O=G("pro tip: upload img by dropping on the canvas"),this.h()},l(r){const t=oe('[data-svelte="svelte-ah0n0z"]',W.head);j=y(t,"LINK",{href:!0,rel:!0}),a=y(t,"SCRIPT",{src:!0});var N=S(a);N.forEach(c),h=y(t,"SCRIPT",{src:!0});var I=S(h);I.forEach(c),l=y(t,"SCRIPT",{src:!0});var C=S(l);C.forEach(c),t.forEach(c),M=U(r),m=y(r,"DIV",{class:!0});var T=S(m);E=y(T,"CANVAS",{class:!0}),S(E).forEach(c),p=U(T),s=y(T,"DIV",{class:!0});var x=S(s);o=y(x,"DIV",{id:!0}),S(o).forEach(c),q=U(x),_=y(x,"DIV",{class:!0});var A=S(_);u=y(A,"INPUT",{type:!0,class:!0,placeholder:!0}),F=U(A),D=y(A,"BUTTON",{class:!0});var H=S(D);R=Q(H,"diffuse the f rest"),H.forEach(c),A.forEach(c),L=U(x),B=y(x,"P",{class:!0});var Y=S(B);O=Q(Y,"pro tip: upload img by dropping on the canvas"),Y.forEach(c),x.forEach(c),T.forEach(c),this.h()},h(){i(j,"href","https://cdnjs.cloudflare.com/ajax/libs/drawingboard.js/0.4.2/drawingboard.css"),i(j,"rel","stylesheet"),J(a.src,k="https://code.jquery.com/jquery-1.12.4.min.js")||i(a,"src",k),J(h.src,z="https://cdnjs.cloudflare.com/ajax/libs/drawingboard.js/0.4.2/drawingboard.min.js")||i(h,"src",z),J(l.src,g="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js")||i(l,"src",g),i(E,"class",w="border-2 "+(f[4]?"":"hidden")),i(o,"id","board-container"),i(u,"type","text"),i(u,"class","border-2 "),i(u,"placeholder","Add prompt"),i(D,"class","bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4"),i(_,"class",P="flex gap-x-2 mt-4 items-center justify-center "+(f[1]?"animate-pulse":"")),i(B,"class","mt-2 opacity-50"),i(s,"class",e="flex flex-col items-center "+(f[1]?"pointer-events-none":"")),i(m,"class","flex flex-wrap gap-x-4 gap-y-2 justify-center mt-8")},m(r,t){d(W.head,j),d(W.head,a),d(W.head,h),d(W.head,l),X(r,M,t),X(r,m,t),d(m,E),f[6](E),d(m,p),d(m,s),d(s,o),f[7](o),d(s,q),d(s,_),d(_,u),Z(u,f[0]),d(_,F),d(_,D),d(D,R),d(s,L),d(s,B),d(B,O),n||(b=[$(u,"input",f[8]),$(D,"click",f[5])],n=!0)},p(r,[t]){t&16&&w!==(w="border-2 "+(r[4]?"":"hidden"))&&i(E,"class",w),t&1&&u.value!==r[0]&&Z(u,r[0]),t&2&&P!==(P="flex gap-x-2 mt-4 items-center justify-center "+(r[1]?"animate-pulse":""))&&i(_,"class",P),t&2&&e!==(e="flex flex-col items-center "+(r[1]?"pointer-events-none":""))&&i(s,"class",e)},i:ee,o:ee,d(r){c(j),c(a),c(h),c(l),r&&c(M),r&&c(m),f[6](null),f[7](null),n=!1,ie(b)}}}const K=500,ae=3e3;function ue(f,j,a){let k="",h=!1,z=!1,l,g,M,m,E,w,p=400,s,o,q=!1;async function _(){if(!g)return;const e=g.createImageData(l.width,l.height),n=e.data;for(let t=0,N=n.length;t<N;t+=4)n[t]=40*Math.random()*7,n[t+1]=40*Math.random()*7,n[t+2]=40*Math.random()*7,n[t+3]=255;const b=await createImageBitmap(e),r=performance.now()-M;g.globalAlpha=Math.min(r,ae)/ae,g.drawImage(b,0,0,p,p),h&&window.requestAnimationFrame(_)}function u(e){if(!g)return;const n=performance.now()-m;g.globalAlpha=Math.min(n,K)/K,g.drawImage(e,0,0,p,p),n<K&&window.requestAnimationFrame(()=>u(e))}async function F(e){const n=e.toDataURL("png"),r=await(await fetch(n)).blob(),t=new File([r],"canvas shot.png",{type:"image/png"}),N=e.getContext("2d").getImageData(0,0,p,p),I=await createImageBitmap(N);return{imgFile:t,imgBitmap:I}}async function D(){if(!k)return alert("Please add prompt");if(!l||!g)return;a(1,h=!0),a(4,q=!1),P(),M=performance.now(),_();const{imgFile:e,imgBitmap:n}=await F(l),b=new FormData;b.append("prompt",k),b.append("image",e);const r=await fetch("https://sdb.pcuenca.net/i2i",{method:"POST",body:b});try{const t=JSON.parse(await r.text()),{images:N}=t,I=await Promise.all(N.map(async T=>{const x=new Image;return x.src=`data:image/png;base64, ${T}`,await new Promise((A,H)=>{x.onload=()=>A(x)}),x}));a(1,h=!1),w&&clearInterval(w),a(4,q=!0);let C=0;m=performance.now(),u(I[C%I.length]),E=()=>{w&&clearInterval(w),m=performance.now(),C=C+1,u(I[C%I.length])},w=setInterval(()=>{C=C+1,m=performance.now(),u(I[C%I.length])},2500),z||R()}catch(t){console.error(t),alert("Error happened: please see console")}}function R(){const e=document.createElement("div");e.className="drawing-board-control";const n=document.createElement("button");n.innerHTML="\u23EF",n.onclick=E,e.append(n);const b=document.querySelector(".drawing-board-controls");b&&(b.appendChild(e),z=!0,a(2,s.onclick=()=>{w&&clearInterval(w)},s))}function P(){const e=o.getContext("2d");a(3,o.width=l.width,o),a(3,o.height=l.height,o),e.drawImage(l,0,0)}le(async()=>{const{innerWidth:e}=window;p=Math.min(p,Math.floor(e*.75)),a(2,s.style.width=`${p}px`,s),a(2,s.style.height=`${p}px`,s),a(3,o.style.width=`${p}px`,o),a(3,o.style.height=`${p}px`,o),await ce(),l=new window.DrawingBoard.Board("board-container",{size:10,controls:["Color",{Size:{type:"dropdown"}},{DrawingMode:{filler:!1}}],droppable:!0,webStorage:!1,enlargeYourContainer:!0}).canvas,g=l.getContext("2d")});function L(e){te[e?"unshift":"push"](()=>{o=e,a(3,o)})}function B(e){te[e?"unshift":"push"](()=>{s=e,a(2,s)})}function O(){k=this.value,a(0,k)}return[k,h,s,o,q,D,L,B,O]}class fe extends se{constructor(j){super(),ne(this,j,ue,pe,re,{})}}export{fe as default}; | |