Spaces:
Runtime error
Runtime error
import{S as se,i as ne,s as ie,e as C,k as A,c as T,a as z,m as D,d as I,b as s,K as Oe,g as Z,J as p,t as V,h as F,L as U,E as Q,M as Ne,N as Y,O as K,P as me,Q as ge,j as Le,f as $e,R as oe,T as Se,U as Ue,V as ct,W as Re,w as ue,x as pe,y as de,q as he,o as fe,B as ve,v as ut}from"../chunks/index-bcf2726a.js";import{w as ae,b as at}from"../chunks/paths-d3bcbd10.js";const Pe=[{color:[219,14,154],label:"building"},{color:[147,142,123],label:"pervious surface"},{color:[248,12,0],label:"impervious surface"},{color:[169,113,1],label:"bare soil"},{color:[21,83,174],label:"water"},{color:[25,74,38],label:"coniferous"},{color:[70,228,131],label:"deciduous"},{color:[243,166,13],label:"brushwood"},{color:[102,0,130],label:"vineyard"},{color:[85,255,0],label:"herbaceous vegetation"},{color:[255,243,13],label:"agricultural land"},{color:[228,223,124],label:"plowed land"},{color:[61,230,235],label:"swimming pool"},{color:[255,255,255],label:"snow"},{color:[138,179,160],label:"clear cut"},{color:[107,113,79],label:"mixed"}],Be=["/samples/default.jpg","/samples/example0.png","/samples/example1.png","/samples/example2.png","/samples/example3.png","/samples/example4.png","/samples/example5.png","/samples/example6.jpg"],ke=[["High resolution satellite image, 4K, ultra detailed","Realistic"],["Colorful lego bricks","Lego brick"],["Black and white paper pencil drawing","Pencil"],["Oil on canvas painting","Painting"]];function st(){return BigInt(0xb7dd73e137d20800&((1<<63)-1)*Math.random())}const _e=ae(new Map),je=ae(),Ae=ae(),De=ae(),xe=ae(),Ie=ae({prompt:"Aerial view of rue des Lilas, Toulouse, Haute-Garonne, France",modifier:ke[0][0],seed:st(),steps:20}),be=ae(!1),Me=ae(!1);function Ye(l,e,t){const r=l.slice();return r[3]=e[t],r[5]=t,r}function Je(l){let e,t,r,a,o,n,d,i,k,E,b,P;return{c(){e=C("div"),t=C("input"),n=A(),d=C("label"),i=C("img"),P=A(),this.h()},l(g){e=T(g,"DIV",{class:!0});var v=z(e);t=T(v,"INPUT",{type:!0,name:!0,id:!0,class:!0}),n=D(v),d=T(v,"LABEL",{for:!0,class:!0});var x=z(d);i=T(x,"IMG",{src:!0,alt:!0,class:!0}),x.forEach(I),P=D(v),v.forEach(I),this.h()},h(){s(t,"type","radio"),s(t,"name","samples"),s(t,"id",r="sample-"+l[5]),t.value=a=l[5],t.disabled=o=l[0]===!0,s(t,"class","svelte-1gwcbp"),Oe(i.src,k=at+l[3])||s(i,"src",k),s(i,"alt",E=l[3]),s(i,"class","svelte-1gwcbp"),s(d,"for",b="sample-"+l[5]),s(d,"class","svelte-1gwcbp"),s(e,"class","snap-always snap-start")},m(g,v){Z(g,e,v),p(e,t),p(e,n),p(e,d),p(d,i),p(e,P)},p(g,v){v&1&&o!==(o=g[0]===!0)&&(t.disabled=o)},d(g){g&&I(e)}}}function pt(l){let e,t,r,a,o,n,d,i,k=Be,E=[];for(let b=0;b<k.length;b+=1)E[b]=Je(Ye(l,k,b));return{c(){e=C("div"),t=C("h4"),r=V("Select a Template"),a=A(),o=C("form"),n=C("div");for(let b=0;b<E.length;b+=1)E[b].c();this.h()},l(b){e=T(b,"DIV",{});var P=z(e);t=T(P,"H4",{class:!0});var g=z(t);r=F(g,"Select a Template"),g.forEach(I),a=D(P),o=T(P,"FORM",{class:!0});var v=z(o);n=T(v,"DIV",{class:!0});var x=z(n);for(let u=0;u<E.length;u+=1)E[u].l(x);x.forEach(I),v.forEach(I),P.forEach(I),this.h()},h(){s(t,"class","font-bold mt-6 mb-2 my-6 leading-6"),s(n,"class","samples svelte-1gwcbp"),s(o,"class","svelte-1gwcbp")},m(b,P){Z(b,e,P),p(e,t),p(t,r),p(e,a),p(e,o),p(o,n);for(let g=0;g<E.length;g+=1)E[g].m(n,null);d||(i=U(o,"input",l[1]),d=!0)},p(b,[P]){if(P&1){k=Be;let g;for(g=0;g<k.length;g+=1){const v=Ye(b,k,g);E[g]?E[g].p(v,P):(E[g]=Je(v),E[g].c(),E[g].m(n,null))}for(;g<E.length;g+=1)E[g].d(1);E.length=k.length}},i:Q,o:Q,d(b){b&&I(e),Ne(E,b),d=!1,i()}}}async function dt(l){return new Promise((e,t)=>{const r=new Image;r.onload=()=>{URL.revokeObjectURL(r.src),e(r)},r.onerror=a=>{t(a)},r.src=URL.createObjectURL(l)})}function ht(l,e,t){let r,a;return Y(l,De,n=>t(2,r=n)),Y(l,be,n=>t(0,a=n)),[a,async n=>{n.preventDefault();const d=Be[parseInt(n.target.value)];if(d){const i=await fetch(at+d).then(E=>E.blob()),k=await dt(i);K(De,r=k,r)}}]}class ft extends se{constructor(e){super(),ne(this,e,ht,pt,ie,{})}}function Xe(l,e,t){const r=l.slice();return r[2]=e[t],r[7]=t,r}function Ke(l){let e,t,r,a,o,n,d,i,k,E,b,P,g=l[2].label+"",v,x,u;return{c(){e=C("div"),t=C("input"),n=A(),d=C("label"),i=me("svg"),k=me("rect"),b=A(),P=C("span"),v=V(g),u=A(),this.h()},l(f){e=T(f,"DIV",{class:!0});var h=z(e);t=T(h,"INPUT",{name:!0,type:!0,id:!0,class:!0}),n=D(h),d=T(h,"LABEL",{for:!0,class:!0});var c=z(d);i=ge(c,"svg",{width:!0,height:!0,viewBox:!0,class:!0});var m=z(i);k=ge(m,"rect",{x:!0,y:!0,width:!0,height:!0,fill:!0}),z(k).forEach(I),m.forEach(I),b=D(c),P=T(c,"SPAN",{class:!0});var w=z(P);v=F(w,g),w.forEach(I),c.forEach(I),u=D(h),h.forEach(I),this.h()},h(){s(t,"name","color"),t.checked=r=l[7]==nt,s(t,"type","radio"),s(t,"id",a="color-"+l[7]),t.value=o=l[7],s(t,"class","svelte-1oy4poo"),s(k,"x","0"),s(k,"y","0"),s(k,"width","20"),s(k,"height","20"),s(k,"fill",E="rgb("+l[2].color.join(",")+")"),s(i,"width","20"),s(i,"height","20"),s(i,"viewBox","0 0 20 20"),s(i,"class","svelte-1oy4poo"),s(P,"class","svelte-1oy4poo"),s(d,"for",x="color-"+l[7]),s(d,"class","svelte-1oy4poo"),s(e,"class","snap-always snap-start")},m(f,h){Z(f,e,h),p(e,t),p(e,n),p(e,d),p(d,i),p(i,k),p(d,b),p(d,P),p(P,v),p(e,u)},p:Q,d(f){f&&I(e)}}}function vt(l){let e,t,r,a,o,n,d,i,k,E,b,P,g,v=l[0].size+"",x,u,f,h=Pe,c=[];for(let m=0;m<h.length;m+=1)c[m]=Ke(Xe(l,h,m));return{c(){e=C("form"),t=C("h4"),r=V("Brush Type"),a=A(),o=C("div");for(let m=0;m<c.length;m+=1)c[m].c();n=A(),d=C("h4"),i=V("Brush Size"),k=A(),E=C("div"),b=C("input"),P=A(),g=C("label"),x=V(v),this.h()},l(m){e=T(m,"FORM",{});var w=z(e);t=T(w,"H4",{class:!0});var y=z(t);r=F(y,"Brush Type"),y.forEach(I),a=D(w),o=T(w,"DIV",{class:!0,name:!0});var M=z(o);for(let B=0;B<c.length;B+=1)c[B].l(M);M.forEach(I),n=D(w),d=T(w,"H4",{class:!0});var _=z(d);i=F(_,"Brush Size"),_.forEach(I),k=D(w),E=T(w,"DIV",{class:!0});var S=z(E);b=T(S,"INPUT",{min:!0,max:!0,step:!0,name:!0,type:!0}),P=D(S),g=T(S,"LABEL",{class:!0,for:!0});var N=z(g);x=F(N,v),N.forEach(I),S.forEach(I),w.forEach(I),this.h()},h(){s(t,"class","font-bold mt-6 mb-2 leading-6 my-3"),s(o,"class","colors svelte-1oy4poo"),s(o,"name","colors"),s(d,"class","font-bold mt-6 mb-2 my-6 leading-6"),b.value="10",s(b,"min","1"),s(b,"max","150"),s(b,"step","1"),s(b,"name","brush"),s(b,"type","range"),s(g,"class","pl-2 svelte-1oy4poo"),s(g,"for","brush"),s(E,"class","brush svelte-1oy4poo")},m(m,w){Z(m,e,w),p(e,t),p(t,r),p(e,a),p(e,o);for(let y=0;y<c.length;y+=1)c[y].m(o,null);p(e,n),p(e,d),p(d,i),p(e,k),p(e,E),p(E,b),p(E,P),p(E,g),p(g,x),u||(f=U(e,"input",l[1]),u=!0)},p(m,[w]){if(w&0){h=Pe;let y;for(y=0;y<h.length;y+=1){const M=Xe(m,h,y);c[y]?c[y].p(M,w):(c[y]=Ke(M),c[y].c(),c[y].m(o,null))}for(;y<c.length;y+=1)c[y].d(1);c.length=h.length}w&1&&v!==(v=m[0].size+"")&&Le(x,v)},i:Q,o:Q,d(m){m&&I(e),Ne(c,m),u=!1,f()}}}const nt=6;function mt(l,e,t){let r;Y(l,xe,k=>t(0,r=k));const{color:a,label:o}=Pe[nt];let n=`rgb(${a.join(",")})`,d=40;return K(xe,r={color:n,size:d,label:o},r),[r,async k=>{const E=k.target;if(E.name==="color"){const b=parseInt(E.value),{color:P,label:g}=Pe[b];n=`rgb(${P.join(",")})`,K(xe,r={color:n,size:d,label:g},r)}else E.name==="brush"&&(d=parseInt(E.value),K(xe,r={color:n,size:d,label:o},r))},a]}class gt extends se{constructor(e){super(),ne(this,e,mt,vt,ie,{})}}function Ze(l,e,t){const r=l.slice();return r[15]=e[t],r}function Qe(l){let e,t=l[15][1]+"",r,a,o;return{c(){e=C("option"),r=V(t),o=V("`"),this.h()},l(n){e=T(n,"OPTION",{});var d=z(e);r=F(d,t),d.forEach(I),o=F(n,"`"),this.h()},h(){e.__value=a=l[15][0],e.value=e.__value},m(n,d){Z(n,e,d),p(e,r),Z(n,o,d)},p:Q,d(n){n&&I(e),n&&I(o)}}}function bt(l){let e,t,r,a,o,n,d,i,k,E,b,P,g,v,x,u,f,h,c,m,w,y,M,_,S,N,B,q,$,J,te,X,O,L,re,ee,le,ce,ye,W=ke,G=[];for(let j=0;j<W.length;j+=1)G[j]=Qe(Ze(l,W,j));return{c(){e=C("form"),t=C("h4"),r=V("Prompt"),a=A(),o=C("input"),d=A(),i=C("h4"),k=V("Modifier"),E=A(),b=C("input"),g=A(),v=C("select"),x=C("option"),u=V("preset");for(let j=0;j<G.length;j+=1)G[j].c();h=A(),c=C("h4"),m=V("Random Seed"),w=A(),y=C("input"),_=A(),S=C("button"),N=V("Random"),q=A(),$=C("h4"),J=V("Sample Steps"),te=A(),X=C("div"),O=C("input"),re=A(),ee=C("label"),le=V(l[2]),this.h()},l(j){e=T(j,"FORM",{});var R=z(e);t=T(R,"H4",{class:!0});var H=z(t);r=F(H,"Prompt"),H.forEach(I),a=D(R),o=T(R,"INPUT",{name:!0,placeholder:!0,style:!0,class:!0}),d=D(R),i=T(R,"H4",{class:!0});var we=z(i);k=F(we,"Modifier"),we.forEach(I),E=D(R),b=T(R,"INPUT",{name:!0,placeholder:!0,style:!0,class:!0}),g=D(R),v=T(R,"SELECT",{name:!0,class:!0});var Ce=z(v);x=T(Ce,"OPTION",{});var Ve=z(x);u=F(Ve,"preset"),Ve.forEach(I);for(let Te=0;Te<G.length;Te+=1)G[Te].l(Ce);Ce.forEach(I),h=D(R),c=T(R,"H4",{class:!0});var Fe=z(c);m=F(Fe,"Random Seed"),Fe.forEach(I),w=D(R),y=T(R,"INPUT",{type:!0,name:!0,placeholder:!0,class:!0}),_=D(R),S=T(R,"BUTTON",{class:!0});var Ge=z(S);N=F(Ge,"Random"),Ge.forEach(I),q=D(R),$=T(R,"H4",{class:!0});var He=z($);J=F(He,"Sample Steps"),He.forEach(I),te=D(R),X=T(R,"DIV",{class:!0});var Ee=z(X);O=T(Ee,"INPUT",{type:!0,name:!0,min:!0,max:!0,step:!0,class:!0}),re=D(Ee),ee=T(Ee,"LABEL",{class:!0,for:!0});var qe=z(ee);le=F(qe,l[2]),qe.forEach(I),Ee.forEach(I),R.forEach(I),this.h()},h(){s(t,"class","font-bold mt-6 mb-2 my-6 leading-6"),s(o,"name","prompt"),s(o,"placeholder","Aerial view of ..., France."),o.disabled=n=l[6]===!0,$e(o,"width","500px"),s(o,"class","svelte-7to72y"),s(i,"class","font-bold mt-6 mb-2 my-6 leading-6"),s(b,"name","modifier"),s(b,"placeholder","High resolution satellite image"),b.disabled=P=l[6]===!0,$e(b,"width","500px"),s(b,"class","svelte-7to72y"),x.disabled=!0,x.selected=!0,x.__value="preset",x.value=x.__value,s(v,"name","presets"),v.disabled=f=l[6]===!0,s(v,"class","svelte-7to72y"),s(c,"class","font-bold mt-6 mb-2 my-6 leading-6"),s(y,"type","Number"),s(y,"name","seed"),s(y,"placeholder","Integer Seed"),y.disabled=M=l[6]===!0,s(y,"class","svelte-7to72y"),S.disabled=B=l[6]===!0,s(S,"class","svelte-7to72y"),s($,"class","font-bold mt-6 mb-2 my-6 leading-6"),s(O,"type","range"),s(O,"name","steps"),s(O,"min","10"),s(O,"max","30"),s(O,"step","1"),O.disabled=L=l[6]===!0,s(O,"class","svelte-7to72y"),s(ee,"class","pl-2 svelte-7to72y"),s(ee,"for","steps"),s(X,"class","flex")},m(j,R){Z(j,e,R),p(e,t),p(t,r),p(e,a),p(e,o),oe(o,l[3]),p(e,d),p(e,i),p(i,k),p(e,E),p(e,b),oe(b,l[4]),p(e,g),p(e,v),p(v,x),p(x,u);for(let H=0;H<G.length;H+=1)G[H].m(v,null);p(e,h),p(e,c),p(c,m),p(e,w),p(e,y),oe(y,l[1]),p(e,_),p(e,S),p(S,N),p(e,q),p(e,$),p($,J),p(e,te),p(e,X),p(X,O),oe(O,l[2]),p(X,re),p(X,ee),p(ee,le),l[14](e),ce||(ye=[U(o,"input",l[8]),U(b,"input",l[9]),U(v,"change",l[10]),U(y,"input",l[11]),U(S,"click",Se(l[12])),U(O,"change",l[13]),U(O,"input",l[13]),U(e,"input",l[7])],ce=!0)},p(j,[R]){if(R&64&&n!==(n=j[6]===!0)&&(o.disabled=n),R&8&&o.value!==j[3]&&oe(o,j[3]),R&64&&P!==(P=j[6]===!0)&&(b.disabled=P),R&16&&b.value!==j[4]&&oe(b,j[4]),R&0){W=ke;let H;for(H=0;H<W.length;H+=1){const we=Ze(j,W,H);G[H]?G[H].p(we,R):(G[H]=Qe(we),G[H].c(),G[H].m(v,null))}for(;H<G.length;H+=1)G[H].d(1);G.length=W.length}R&64&&f!==(f=j[6]===!0)&&(v.disabled=f),R&64&&M!==(M=j[6]===!0)&&(y.disabled=M),R&2&&oe(y,j[1]),R&64&&B!==(B=j[6]===!0)&&(S.disabled=B),R&64&&L!==(L=j[6]===!0)&&(O.disabled=L),R&4&&oe(O,j[2]),R&4&&Le(le,j[2])},i:Q,o:Q,d(j){j&&I(e),Ne(G,j),l[14](null),ce=!1,Ue(ye)}}}function yt(l,e,t){let r,a;Y(l,Ie,h=>t(5,r=h)),Y(l,be,h=>t(6,a=h));function o(){const h=n.elements;K(Ie,r={prompt:h.prompt.value,modifier:h.modifier.value,seed:BigInt(h.seed.value),steps:parseInt(h.steps.value)},r)}let n,d=r.seed,i=r.steps,k=r.prompt,E=r.modifier;function b(){k=this.value,t(3,k)}function P(){E=this.value,t(4,E)}const g=h=>{const c=h.currentTarget.selectedIndex-1;t(4,E=ke[c][0]),K(Ie,r.modifier=ke[c][0],r)};function v(){d=this.value,t(1,d)}const x=()=>{t(1,d=st()),o()};function u(){i=ct(this.value),t(2,i)}function f(h){Re[h?"unshift":"push"](()=>{n=h,t(0,n)})}return[n,d,i,k,E,r,a,o,b,P,g,v,x,u,f]}class wt extends se{constructor(e){super(),ne(this,e,yt,bt,ie,{})}}let _t=(l=21)=>crypto.getRandomValues(new Uint8Array(l)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),"");var xt=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function kt(l){return l&&l.__esModule&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l}var it={exports:{}};(function(l,e){(function(t,r){l.exports=r()})(typeof self!="undefined"?self:xt,function(){return function(t){var r={};function a(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,a),n.l=!0,n.exports}return a.m=t,a.c=r,a.d=function(o,n,d){a.o(o,n)||Object.defineProperty(o,n,{enumerable:!0,get:d})},a.r=function(o){typeof Symbol!="undefined"&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})},a.t=function(o,n){if(1&n&&(o=a(o)),8&n||4&n&&typeof o=="object"&&o&&o.__esModule)return o;var d=Object.create(null);if(a.r(d),Object.defineProperty(d,"default",{enumerable:!0,value:o}),2&n&&typeof o!="string")for(var i in o)a.d(d,i,function(k){return o[k]}.bind(null,i));return d},a.n=function(o){var n=o&&o.__esModule?function(){return o.default}:function(){return o};return a.d(n,"a",n),n},a.o=function(o,n){return Object.prototype.hasOwnProperty.call(o,n)},a.p="",a(a.s=0)}([function(t,r,a){function o(g,v){return function(x){if(Array.isArray(x))return x}(g)||function(x,u){if(Symbol.iterator in Object(x)||Object.prototype.toString.call(x)==="[object Arguments]"){var f=[],h=!0,c=!1,m=void 0;try{for(var w,y=x[Symbol.iterator]();!(h=(w=y.next()).done)&&(f.push(w.value),!u||f.length!==u);h=!0);}catch(M){c=!0,m=M}finally{try{h||y.return==null||y.return()}finally{if(c)throw m}}return f}}(g,v)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function n(g){return function(v){if(Array.isArray(v)){for(var x=0,u=new Array(v.length);x<v.length;x++)u[x]=v[x];return u}}(g)||function(v){if(Symbol.iterator in Object(v)||Object.prototype.toString.call(v)==="[object Arguments]")return Array.from(v)}(g)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function d(g,v){for(var x=0;x<v.length;x++){var u=v[x];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(g,u.key,u)}}a.r(r);var i=/^#?[0-9A-Fa-f]{1,2}[0-9A-Fa-f]{1,2}[0-9A-Fa-f]{1,2}$/,k=/^rgb\((\s+)?[0-9]{1,3},(\s+)?[0-9]{1,3},(\s+)?[0-9]{1,3}(\s+)?\)$/,E=function(){function g(){(function(u,f){if(!(u instanceof f))throw new TypeError("Cannot call a class as a function")})(this,g),this.canvases={}}var v,x;return v=g,(x=[{key:"parseColor",value:function(u){var f=i.test(u),h=k.test(u);if(!f&&!h)throw new Error("Color is not correct format. #123123 or rgb(123, 123, 123) format required.");if(f){var c=u[0]==="#"?u.slice(1):u;return c=c.length===3?c.split("").reduce(function(_,S){return[].concat(n(_),[S,S])},[]).join(""):c,{r:parseInt(c.slice(0,2),16),g:parseInt(c.slice(2,4),16),b:parseInt(c.slice(4,6),16)}}if(h){var m=o(u.replace(/rgb|\s+|\(|\)/g,"").split(",").map(function(_){return parseInt(_)}),3),w=m[0],y=m[1],M=m[2];return{r:w=w>255?255:w,g:y=y>255?255:y,b:M=M>255?255:M}}}},{key:"make",value:function(u){var f=u.size,h=u.color;try{f*=window.devicePixelRatio;var c=this.parseColor(h),m=JSON.stringify(c);if(this.canvases[m]=this.canvases[m]||{},this.canvases[m][f]!=null)return this.canvases[m][f];var w=document.createElement("canvas");f+=f%2,w.width=f,w.height=f;for(var y=w.getContext("2d"),M=y.createImageData(f,f),_=0;_<M.data.length;_+=4)M.data[_]=255,M.data[_+1]=255,M.data[_+2]=255,M.data[_+3]=0;return this.plotCircle(2*f,4*f*(f/2),f/2,M,f,c),this.fillCircle(M,c),y.putImageData(M,0,0),this.canvases[m][f]=w,w}catch(S){console.error(S)}}},{key:"plotCircle",value:function(u,f,h,c,m,w){var y=-h,M=0,_=2-2*h;do{var S=u-4*(y+1)+(f+4*m*(M-1));c.data[S+0]=w.r,c.data[S+1]=w.g,c.data[S+2]=w.b,c.data[S+3]=255;var N=u-M*(4*m)+(f-4*(y+1));c.data[N+0]=w.r,c.data[N+1]=w.g,c.data[N+2]=w.b,c.data[N+3]=255;var B=u+4*y+(f-M*(4*m));c.data[B+0]=w.r,c.data[B+1]=w.g,c.data[B+2]=w.b,c.data[B+3]=255;var q=u+4*m*(M-1)+(f+4*y);c.data[q+0]=w.r,c.data[q+1]=w.g,c.data[q+2]=w.b,c.data[q+3]=255,(h=_)<=M&&(_+=2*++M+1),(h>y||_>M)&&(_+=2*++y+1)}while(y<0)}},{key:"fillCircle",value:function(u,f){for(var h=4*u.width,c=1;c<u.height-1;c+=1)for(var m=!1,w=!1,y=!1,M=0;M<h;M+=4){var _=h*c+M,S=u.data[_+3],N=S===255;N&&!m?m=!0:S===0&&m?w=!0:N&&m&&w&&(y=!0),m&&w&&!y&&(u.data[_]=f.r,u.data[_+1]=f.g,u.data[_+2]=f.b,u.data[_+3]=255)}}}])&&d(v.prototype,x),g}();function b(g,v){for(var x=0;x<v.length;x++){var u=v[x];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(g,u.key,u)}}var P=function(){function g(u){(function(f,h){if(!(f instanceof h))throw new TypeError("Cannot call a class as a function")})(this,g),this.canvas=u,this.context=u.getContext("2d"),this.stampMaker=new E,this.configPixelRatio()}var v,x;return v=g,(x=[{key:"configPixelRatio",value:function(){var u=this.canvas,f=u.width,h=u.height;this.canvas.width=f*this.dpr,this.canvas.height=h*this.dpr,this.canvas.style.width="".concat(f,"px"),this.canvas.style.height="".concat(h,"px"),this.context.scale(this.dpr,this.dpr),this.context.imageSmoothingEnabled=!1}},{key:"exportAsPNG",value:function(u){var f=this;return new Promise(function(h){var c=document.createElement("canvas"),m=c.getContext("2d"),w=f.canvas,y=w.width,M=w.height,_=y/f.dpr,S=M/f.dpr;c.width=_,c.height=S,m.imageSmoothingEnabled=!1,m.drawImage(f.canvas,0,0,y,M,0,0,_,S),c.toBlob(function(N){N.lastModifedDate=new Date,N.name=u,h(N)})})}},{key:"distanceBetween",value:function(u,f){return Math.sqrt(Math.pow(f.x-u.x,2)+Math.pow(f.y-u.y,2))}},{key:"angleBetween",value:function(u,f){return Math.atan2(f.x-u.x,f.y-u.y)}},{key:"draw",value:function(u){var f=u.from,h=u.to,c=u.size,m=u.color;this.context.globalCompositeOperation="source-over",this.brush({from:f,to:h,size:c,color:m})}},{key:"erase",value:function(u){var f=u.from,h=u.to,c=u.size;this.context.globalCompositeOperation="destination-out",this.brush({from:f,to:h,size:c,color:"#000000"})}},{key:"brush",value:function(u){var f=this,h=u.from,c=u.to,m=u.size,w=u.color,y=(m-m%2)/2,M=this.stampMaker.make({size:m,color:w});if(h.x!==c.x||h.y!==c.y)for(var _=this.distanceBetween(h,c),S=this.angleBetween(h,c),N=function(J){var te=h.x+Math.sin(S)*J-y,X=h.y+Math.cos(S)*J-y;window.requestAnimationFrame(function(){f.context.drawImage(M,Math.round(te),Math.round(X),m,m)})},B=0;B<_;B+=1)N(B);else{var q=h.x-y,$=h.y-y;this.context.drawImage(M,Math.round(q),Math.round($),m,m)}}},{key:"dpr",get:function(){return window.devicePixelRatio||1}}])&&b(v.prototype,x),g}();r.default=P}])})})(it);var We=kt(it.exports);function Et(l){let e,t;return{c(){e=me("svg"),t=me("path"),this.h()},l(r){e=ge(r,"svg",{xmlns:!0,width:!0,viewBox:!0,class:!0});var a=z(e);t=ge(a,"path",{fill:!0,stroke:!0,"stroke-width":!0,d:!0}),z(t).forEach(I),a.forEach(I),this.h()},h(){s(t,"fill","white"),s(t,"stroke","black"),s(t,"stroke-width","30"),s(t,"d","M480 256c0 123.4-100.5 223.9-223.9 223.9c-48.84 0-95.17-15.58-134.2-44.86c-14.12-10.59-16.97-30.66-6.375-44.81c10.59-14.12 30.62-16.94 44.81-6.375c27.84 20.91 61 31.94 95.88 31.94C344.3 415.8 416 344.1 416 256s-71.69-159.8-159.8-159.8c-37.46 0-73.09 13.49-101.3 36.64l45.12 45.14c17.01 17.02 4.955 46.1-19.1 46.1H35.17C24.58 224.1 16 215.5 16 204.9V59.04c0-24.04 29.07-36.08 46.07-19.07l47.6 47.63C149.9 52.71 201.5 32.11 256.1 32.11C379.5 32.11 480 132.6 480 256z"),s(e,"xmlns","http://www.w3.org/2000/svg"),s(e,"width","20"),s(e,"viewBox","0 0 512 512"),s(e,"class",l[0])},m(r,a){Z(r,e,a),p(e,t)},p(r,[a]){a&1&&s(e,"class",r[0])},i:Q,o:Q,d(r){r&&I(e)}}}function It(l,e,t){let{classNames:r=""}=e;return l.$$set=a=>{"classNames"in a&&t(0,r=a.classNames)},[r]}class St extends se{constructor(e){super(),ne(this,e,It,Et,ie,{classNames:0})}}function Pt(l){var f;let e,t,r,a,o,n,d,i=((f=l[0])==null?void 0:f.label)+"",k,E,b,P,g,v,x,u;return P=new St({}),{c(){e=C("div"),t=C("div"),r=C("canvas"),a=A(),o=C("canvas"),n=A(),d=C("span"),k=V(i),E=A(),b=C("button"),ue(P.$$.fragment),this.h()},l(h){e=T(h,"DIV",{});var c=z(e);t=T(c,"DIV",{class:!0});var m=z(t);r=T(m,"CANVAS",{class:!0,width:!0,height:!0}),z(r).forEach(I),a=D(m),o=T(m,"CANVAS",{class:!0,width:!0,height:!0}),z(o).forEach(I),n=D(m),d=T(m,"SPAN",{class:!0});var w=z(d);k=F(w,i),w.forEach(I),E=D(m),b=T(m,"BUTTON",{class:!0});var y=z(b);pe(P.$$.fragment,y),y.forEach(I),m.forEach(I),c.forEach(I),this.h()},h(){s(r,"class","canvas svelte-vhujxn"),s(r,"width","512"),s(r,"height","512"),s(o,"class","brush svelte-vhujxn"),s(o,"width","10"),s(o,"height","10"),s(d,"class","label svelte-vhujxn"),s(b,"class","absolute bottom-0 left-0 p-3"),b.disabled=g=l[3].size<=0,s(t,"class","relative overflow-clip")},m(h,c){Z(h,e,c),p(e,t),p(t,r),l[11](r),p(t,a),p(t,o),l[12](o),p(t,n),p(t,d),p(d,k),p(t,E),p(t,b),de(P,b,null),v=!0,x||(u=[U(r,"touchmove",Ct),U(r,"pointerenter",Mt),U(r,"pointerup",l[4]),U(r,"pointerleave",l[4]),U(r,"pointercancel",l[4]),U(r,"pointerout",l[4]),U(r,"pointermove",l[6]),U(r,"pointerdown",l[5]),U(b,"click",Se(l[13]))],x=!0)},p(h,[c]){var m;(!v||c&1)&&i!==(i=((m=h[0])==null?void 0:m.label)+"")&&Le(k,i),(!v||c&8&&g!==(g=h[3].size<=0))&&(b.disabled=g)},i(h){v||(he(P.$$.fragment,h),v=!0)},o(h){fe(P.$$.fragment,h),v=!1},d(h){h&&I(e),l[11](null),l[12](null),ve(P),x=!1,Ue(u)}}}function Mt(){}function et(l,e){const t=l.getBoundingClientRect();return{x:(e.clientX-t.left)*(l.width/t.width),y:(e.clientY-t.top)*(l.height/t.height)}}function tt(l){l.fillStyle="#46e483",l.fillRect(0,0,l.canvas.width,l.canvas.height)}function ze(l,e){l.drawImage(e,0,0,l.canvas.width,l.canvas.height)}const Ct=l=>l.preventDefault();function Tt(l,e,t){let r,a,o,n;Y(l,_e,_=>t(3,r=_)),Y(l,De,_=>t(10,a=_)),Y(l,xe,_=>t(0,o=_)),Y(l,Ae,_=>t(18,n=_));let d,i,k,E,b={x:0,y:0},P;ut(()=>{t(9,E=d.getContext("2d")),t(8,k=i.getContext("2d")),window.devicePixelRatio=1,P=new We(d),t(1,d.style.height="unset",d),t(1,d.style.width="unset",d),K(Ae,n=d,n),tt(E)});let g=!1,v;function x(){t(2,i.style.top=`${10+o.size/2}px`,i),t(2,i.style.left=`${10+o.size/2}px`,i),g=!1}function u(_){g=!0,b=et(d,_),P.draw({from:b,to:b,size:o.size,color:o.color}),v=_t(),_e.update(S=>(S.set(v,{brush:o,points:[{from:b,to:b}]}),S))}function f(_){const S=et(d,_);t(2,i.style.top=`${_.offsetY}px`,i),t(2,i.style.left=`${_.offsetX}px`,i),g&&(P.draw({from:b,to:S,size:o.size,color:o.color}),_e.update(N=>{const B=N.get(v);return B==null||B.points.push({from:b,to:S}),N}),b=S)}function h(_){const{size:S,color:N}=_;t(2,i.width=S,i),t(2,i.height=S,i),t(8,k.fillStyle=N,k),k.arc(S/2,S/2,S/2,0,2*Math.PI),k.fill()}function c(){if(r.size<=0)return;const _=Array.from(r.keys());_e.update(S=>(S.delete(_[_.length-1]),S)),m(E)}function m(_){const S=document.createElement("canvas");S.width=512,S.height=512,window.devicePixelRatio=1;const N=new We(S);tt(_),a&&ze(_,a),Array.from(r.values()).forEach(B=>{B.points.forEach((q,$)=>{N.draw({from:q.from,to:q.to,size:B.brush.size,color:B.brush.color})})}),requestAnimationFrame(()=>{ze(_,S)})}function w(_){Re[_?"unshift":"push"](()=>{d=_,t(1,d)})}function y(_){Re[_?"unshift":"push"](()=>{i=_,t(2,i),t(8,k),t(0,o)})}const M=()=>c();return l.$$.update=()=>{l.$$.dirty&257&&k&&o&&(h(o),t(2,i.style.top=`${10+o.size/2}px`,i),t(2,i.style.left=`${10+o.size/2}px`,i)),l.$$.dirty&1536&&a&&(ze(E,a),K(_e,r=new Map,r))},[o,d,i,r,x,u,f,c,k,E,a,w,y,M]}class zt extends se{constructor(e){super(),ne(this,e,Tt,Pt,ie,{})}}function rt(l){let e,t,r;return{c(){e=C("img"),this.h()},l(a){e=T(a,"IMG",{class:!0,alt:!0,src:!0,width:!0,height:!0}),this.h()},h(){s(e,"class",t="image "+(l[1]?"opacity-30":"")+" svelte-1t0h0rs"),s(e,"alt","Generative Map Result"),Oe(e.src,r=l[0])||s(e,"src",r),s(e,"width","512"),s(e,"height","512")},m(a,o){Z(a,e,o)},p(a,o){o&2&&t!==(t="image "+(a[1]?"opacity-30":"")+" svelte-1t0h0rs")&&s(e,"class",t),o&1&&!Oe(e.src,r=a[0])&&s(e,"src",r)},d(a){a&&I(e)}}}function lt(l){let e,t,r,a,o,n;return{c(){e=C("div"),t=me("svg"),r=me("path"),a=A(),o=C("span"),n=V(ot),this.h()},l(d){e=T(d,"DIV",{class:!0});var i=z(e);t=ge(i,"svg",{xmlns:!0,fill:!0,viewBox:!0,class:!0});var k=z(t);r=ge(k,"path",{fill:!0,d:!0}),z(r).forEach(I),k.forEach(I),a=D(i),o=T(i,"SPAN",{class:!0});var E=z(o);n=F(E,ot),E.forEach(I),i.forEach(I),this.h()},h(){s(r,"fill","currentColor"),s(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"),s(t,"xmlns","http://www.w3.org/2000/svg"),s(t,"fill","none"),s(t,"viewBox","0 0 24 24"),s(t,"class","animate-spin max-w-[3rem]"),s(o,"class","text-xs"),s(e,"class","loading svelte-1t0h0rs")},m(d,i){Z(d,e,i),p(e,t),p(t,r),p(e,a),p(e,o),p(o,n)},p:Q,d(d){d&&I(e)}}}function Ot(l){let e,t,r=l[0]&&rt(l),a=l[1]&<();return{c(){e=C("div"),r&&r.c(),t=A(),a&&a.c(),this.h()},l(o){e=T(o,"DIV",{class:!0});var n=z(e);r&&r.l(n),t=D(n),a&&a.l(n),n.forEach(I),this.h()},h(){s(e,"class","relative overflow-clip flex flex-col justify-center items-center w-full h-full")},m(o,n){Z(o,e,n),r&&r.m(e,null),p(e,t),a&&a.m(e,null)},p(o,[n]){o[0]?r?r.p(o,n):(r=rt(o),r.c(),r.m(e,t)):r&&(r.d(1),r=null),o[1]?a?a.p(o,n):(a=lt(),a.c(),a.m(e,null)):a&&(a.d(1),a=null)},i:Q,o:Q,d(o){o&&I(e),r&&r.d(),a&&a.d()}}}let ot="";async function Rt(l){return new Promise((e,t)=>{try{const r=document.createElement("a");r.download=`sucess-${Date.now()}.png`,r.target="_self",r.onclick=async a=>{r.href&&URL.revokeObjectURL(r.href),r.href=l},requestAnimationFrame(()=>{console.log("Downloading image."),r.click(),e(null)})}catch{t()}})}async function Bt(l,{prompt:e,modifier:t,steps:r,seed:a}){const o=await fetch("/predict",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:[l,e+". "+t,r,a.toString()]})});if(!o.ok)throw new Error("Prediction request failed.");return await o.text()}function jt(l,e,t){let r,a,o,n,d;return Y(l,Me,i=>t(2,r=i)),Y(l,je,i=>t(0,a=i)),Y(l,be,i=>t(1,o=i)),Y(l,Ie,i=>t(3,n=i)),Y(l,Ae,i=>t(4,d=i)),l.$$.update=()=>{l.$$.dirty&26&&(async()=>{if(o){const i=await Bt(d.toDataURL(),n);K(je,a=i,a),K(be,o=!1,o)}})(),l.$$.dirty&5&&(async()=>r&&(await Rt(a),K(Me,r=!1,r)))()},[a,o,r,n,d]}class At extends se{constructor(e){super(),ne(this,e,jt,Ot,ie,{})}}function Dt(l){let e,t,r,a,o,n,d,i,k,E,b,P,g,v,x,u,f,h,c,m,w,y,M,_,S,N,B,q,$,J,te,X;return P=new gt({}),x=new zt({}),f=new At({}),B=new ft({}),$=new wt({}),{c(){e=C("div"),t=C("article"),r=C("h1"),a=V("Drawing to Map"),o=A(),n=C("p"),d=V("This space is for the ControlNet model "),i=C("a"),k=C("span"),E=V("Drawing2Map"),b=A(),ue(P.$$.fragment),g=A(),v=C("div"),ue(x.$$.fragment),u=A(),ue(f.$$.fragment),h=A(),c=C("button"),m=V("Generate Map"),y=A(),M=C("button"),_=V("Save Result"),N=A(),ue(B.$$.fragment),q=A(),ue($.$$.fragment),this.h()},l(O){e=T(O,"DIV",{class:!0});var L=z(e);t=T(L,"ARTICLE",{class:!0});var re=z(t);r=T(re,"H1",{});var ee=z(r);a=F(ee,"Drawing to Map"),ee.forEach(I),o=D(re),n=T(re,"P",{});var le=z(n);d=F(le,"This space is for the ControlNet model "),i=T(le,"A",{href:!0,target:!0});var ce=z(i);k=T(ce,"SPAN",{});var ye=z(k);E=F(ye,"Drawing2Map"),ye.forEach(I),ce.forEach(I),le.forEach(I),re.forEach(I),b=D(L),pe(P.$$.fragment,L),g=D(L),v=T(L,"DIV",{class:!0});var W=z(v);pe(x.$$.fragment,W),u=D(W),pe(f.$$.fragment,W),W.forEach(I),h=D(L),c=T(L,"BUTTON",{class:!0});var G=z(c);m=F(G,"Generate Map"),G.forEach(I),y=D(L),M=T(L,"BUTTON",{class:!0});var j=z(M);_=F(j,"Save Result"),j.forEach(I),N=D(L),pe(B.$$.fragment,L),q=D(L),pe($.$$.fragment,L),L.forEach(I),this.h()},h(){s(i,"href","https://github.com/RubenGres/Drawing2Map"),s(i,"target","_blank"),s(t,"class","prose"),s(v,"class","drawings py-3 -mx-3 svelte-1sy339h"),c.disabled=w=l[0]===!0,s(c,"class","green svelte-1sy339h"),M.disabled=S=l[1]===!0||!l[2],s(M,"class","svelte-1sy339h"),s(e,"class","max-w-screen-md mx-auto px-3 py-5 relative z-0")},m(O,L){Z(O,e,L),p(e,t),p(t,r),p(r,a),p(t,o),p(t,n),p(n,d),p(n,i),p(i,k),p(k,E),p(e,b),de(P,e,null),p(e,g),p(e,v),de(x,v,null),p(v,u),de(f,v,null),p(e,h),p(e,c),p(c,m),p(e,y),p(e,M),p(M,_),p(e,N),de(B,e,null),p(e,q),de($,e,null),J=!0,te||(X=[U(c,"click",Se(l[3])),U(M,"click",Se(l[4]))],te=!0)},p(O,[L]){(!J||L&1&&w!==(w=O[0]===!0))&&(c.disabled=w),(!J||L&6&&S!==(S=O[1]===!0||!O[2]))&&(M.disabled=S)},i(O){J||(he(P.$$.fragment,O),he(x.$$.fragment,O),he(f.$$.fragment,O),he(B.$$.fragment,O),he($.$$.fragment,O),J=!0)},o(O){fe(P.$$.fragment,O),fe(x.$$.fragment,O),fe(f.$$.fragment,O),fe(B.$$.fragment,O),fe($.$$.fragment,O),J=!1},d(O){O&&I(e),ve(P),ve(x),ve(f),ve(B),ve($),te=!1,Ue(X)}}}function Nt(l,e,t){let r,a,o;return Y(l,be,i=>t(0,r=i)),Y(l,Me,i=>t(1,a=i)),Y(l,je,i=>t(2,o=i)),[r,a,o,()=>K(be,r=!0,r),()=>K(Me,a=!0,a)]}class Vt extends se{constructor(e){super(),ne(this,e,Nt,Dt,ie,{})}}export{Vt as default}; | |