|
import{S as fe,i as me,s as he,k as f,a as z,q as ae,H as ge,l as m,m as D,h as d,c as H,r as ne,n as o,I as se,p as we,F as s,b as le,J as ce,K as Q,L as ve,M as be,A as de,N as _e,o as ye,z as Ie,O as Ee,P as re}from"../../chunks/index-c0a82f06.js";const{document:X,window:pe}=Ee;function De(i){let P,n,_,g,M,w,y,c,C,x,N,I,a,u,A,r,E,p,O,S,W,F,J,L,K,U,R,B,k,Y,V,G,Z;return{c(){P=f("link"),n=f("script"),g=f("script"),w=f("script"),c=z(),C=f("div"),x=f("canvas"),I=z(),a=f("div"),u=f("div"),A=z(),r=f("div"),E=f("div"),p=f("input"),O=z(),S=f("button"),W=ae("diffuse the f rest"),J=z(),L=f("p"),K=ae("pro tip: upload img by pasting OR dropping on the canvas"),U=z(),R=f("div"),B=f("label"),k=f("input"),Y=ae(` |
|
upload img`),te.forEach(d),ie.forEach(d),q.forEach(d),h.forEach(d),j.forEach(d),this.h()},h(){o(P,"href","https://cdnjs.cloudflare.com/ajax/libs/drawingboard.js/0.4.2/drawingboard.css"),o(P,"rel","stylesheet"),se(n.src,_="https://code.jquery.com/jquery-1.12.4.min.js")||o(n,"src",_),se(g.src,M="https://cdnjs.cloudflare.com/ajax/libs/drawingboard.js/0.4.2/drawingboard.min.js")||o(g,"src",M),se(w.src,y="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js")||o(w,"src",y),o(x,"class",N="border-[1.2px] desktop:mt-[34px] "+(i[5]?"":"hidden")),o(u,"id","board-container"),o(p,"type","text"),o(p,"class","border-2 py-1"),o(p,"placeholder","Add prompt"),o(S,"class","bg-blue-500 hover:bg-blue-700 text-white font-bold py-1.5 px-4"),o(E,"class",F="flex gap-x-2 mt-3 items-center justify-center "+(i[1]?"animate-pulse":"")),o(L,"class","no-hover:hidden mt-2 opacity-50"),o(k,"accept","image/*"),we(k,"display","none"),o(k,"type","file"),o(B,"class","with-hover:hidden border py-1 px-1.5 bg-slate-200 cursor-pointer"),o(R,"class","mt-2"),o(a,"class",V="flex flex-col items-center "+(i[1]?"pointer-events-none":"")),o(C,"class","flex flex-wrap gap-x-4 gap-y-2 justify-center my-8")},m(e,t){s(X.head,P),s(X.head,n),s(X.head,g),s(X.head,w),le(e,c,t),le(e,C,t),s(C,x),i[10](x),s(C,I),s(C,a),s(a,u),i[11](u),s(a,A),s(a,r),s(r,E),s(E,p),ce(p,i[0]),s(E,O),s(E,S),s(S,W),s(r,J),s(r,L),s(L,K),s(r,U),s(r,R),s(R,B),s(B,k),i[13](k),s(B,Y),G||(Z=[Q(pe,"drop",ve(be(i[8]))),Q(pe,"paste",i[9]),Q(p,"input",i[12]),Q(S,"click",i[6]),Q(k,"change",i[7])],G=!0)},p(e,[t]){t&32&&N!==(N="border-[1.2px] desktop:mt-[34px] "+(e[5]?"":"hidden"))&&o(x,"class",N),t&1&&p.value!==e[0]&&ce(p,e[0]),t&2&&F!==(F="flex gap-x-2 mt-3 items-center justify-center "+(e[1]?"animate-pulse":""))&&o(E,"class",F),t&2&&V!==(V="flex flex-col items-center "+(e[1]?"pointer-events-none":""))&&o(a,"class",V)},i:de,o:de,d(e){d(P),d(n),d(g),d(w),e&&d(c),e&&d(C),i[10](null),i[11](null),i[13](null),G=!1,_e(Z)}}}const oe=500,ue=3e3;function Ce(){window.createImageBitmap=async function(i){return new Promise((P,n)=>{const _=document.createElement("canvas"),g=_.getContext("2d");_.width=i.width,_.height=i.height,g.putImageData(i,0,0);const M=_.toDataURL(),w=document.createElement("img");w.addEventListener("load",()=>{P(w)}),w.src=M})}}function xe(i,P,n){let _="",g=!1,M=!1,w,y,c,C,x,N,I,a=400,u,A,r,E=!1,p=[];async function O(){if(!c)return;const e=c.createImageData(y.width,y.height),t=e.data;for(let b=0,j=t.length;b<j;b+=4)t[b]=40*Math.random()*7,t[b+1]=40*Math.random()*7,t[b+2]=40*Math.random()*7,t[b+3]=255;const l=await createImageBitmap(e),v=performance.now()-C;c.globalAlpha=Math.min(v,ue)/ue,c.drawImage(l,0,0,a,a),g&&window.requestAnimationFrame(O)}function S(e){if(!c)return;const t=performance.now()-x;c.globalAlpha=Math.min(t,oe)/oe,c.drawImage(e,0,0,a,a),t<oe&&window.requestAnimationFrame(()=>S(e))}async function W(e){const t=e.toDataURL("png"),v=await(await fetch(t)).blob(),b=new File([v],"canvas shot.png",{type:"image/png"}),j=e.getContext("2d").getImageData(0,0,a,a),h=await createImageBitmap(j);return{imgFile:b,imgBitmap:h}}async function F(){if(!_)return alert("Please add prompt");if(!y||!c)return;n(1,g=!0),n(5,E=!1),K(),C=performance.now(),O();const{imgFile:e,imgBitmap:t}=await W(y),l=new FormData;l.append("prompt",_),l.append("strength","0.85"),l.append("image",e);try{const v=await fetch("https://sdb.pcuenca.net/i2i",{method:"POST",body:l}),b=JSON.parse(await v.text()),{images:j}=b;if(!j.length)return alert("All the results were flagged. Please try again with diffeerent sketch + prompt");p=await Promise.all(j.map(async q=>{const T=new Image;return T.src=`data:image/png;base64, ${q}`,await new Promise(($,ee)=>{T.onload=()=>$(T)}),T})),n(1,g=!1),I&&clearInterval(I),n(5,E=!0);let h=0;x=performance.now(),S(p[h%p.length]),N=()=>{I&&clearInterval(I),x=performance.now(),h=h+1,S(p[h%p.length])},I=setInterval(()=>{h=h+1,x=performance.now(),S(p[h%p.length])},2500),!M&&p.length>1&&J()}catch(v){console.error(v),alert("Error happened, queue might be full. Please try again in a bit :)")}}function J(){const e=document.createElement("div");e.className="drawing-board-control";const t=document.createElement("button");t.innerHTML="\u23EF",t.onclick=N,e.append(t);const l=document.querySelector(".drawing-board-controls");l&&(l.appendChild(e),M=!0,n(2,u.onclick=()=>{I&&clearInterval(I)},u))}function L(){const e=document.createElement("div");e.className="drawing-board-control";const t=document.createElement("button");t.innerHTML="\u{1F9F9}",t.onclick=()=>{c==null||c.clearRect(0,0,a,a)},e.append(t);const l=document.querySelector(".drawing-board-controls");l&&l.appendChild(e)}function K(){const e=r.getContext("2d");n(4,r.width=y.width,r),n(4,r.height=y.height,r),e.drawImage(y,0,0)}async function U(e){I&&clearInterval(I);const t=new Image;t.src=URL.createObjectURL(e),await new Promise((b,j)=>{t.onload=()=>b(t)});const{width:l,height:v}=t;c==null||c.drawImage(t,0,0,l,v,0,0,a,a)}function R(){var t;const e=(t=A.files)==null?void 0:t[0];e&&U(e)}function B(e){var v;if(!((v=e.dataTransfer)!=null&&v.files))return;e.preventDefault();const l=Array.from(e.dataTransfer.files)[0];U(l)}function k(e){if(!e.clipboardData)return;const t=Array.from(e.clipboardData.files);if(t.length===0)return;e.preventDefault();const l=t[0];U(l)}ye(async()=>{typeof createImageBitmap>"u"&&Ce();const{innerWidth:e}=window;a=Math.min(a,Math.floor(e*.75)),n(2,u.style.width=`${a}px`,u),n(2,u.style.height=`${a}px`,u),n(4,r.style.width=`${a}px`,r),n(4,r.style.height=`${a}px`,r),await Ie(),w=new window.DrawingBoard.Board("board-container",{size:10,controls:["Color",{Size:{type:"dropdown"}},{DrawingMode:{filler:!1}}],webStorage:!1,enlargeYourContainer:!0}),y=w.canvas,c=y.getContext("2d"),y.ondragover=function(t){return t.preventDefault(),!1},L()});function Y(e){re[e?"unshift":"push"](()=>{r=e,n(4,r)})}function V(e){re[e?"unshift":"push"](()=>{u=e,n(2,u)})}function G(){_=this.value,n(0,_)}function Z(e){re[e?"unshift":"push"](()=>{A=e,n(3,A)})}return[_,g,u,A,r,E,F,R,B,k,Y,V,G,Z]}class je extends fe{constructor(P){super(),me(this,P,xe,De,he,{})}}export{je as default}; |