Drawing2Sat / static /_app /immutable /pages /index.svelte-6350336a.js
Ruben Gres
first commit
ec3efd7
raw
history blame
27.7 kB
import{S as W,i as ee,s as te,e as M,k as D,c as O,a as T,m as j,d as E,b as c,K as ke,g as $,J as d,t as V,h as F,L as N,E as Y,M as Oe,N as G,O as J,P as pe,Q as de,j as Te,f as tt,R as ae,T as ge,U as Be,V as rt,W as Ee,w as oe,x as se,y as ne,q as ie,o as ce,B as ue,v as lt}from"../chunks/index-bcf2726a.js";import{w as Q,b as Ze}from"../chunks/paths-d3bcbd10.js";const ye=[{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"},{color:[197,220,66],label:"ligneous"},{color:[153,153,255],label:"greenhouse"},{color:[0,0,0],label:"other"}],Ie=["/samples/example0.png","/samples/example1.png","/samples/example2.png","/samples/example3.png","/samples/example4.png","/samples/example5.png"],Se=[["Aerial view, France. High resolution image, 4K, ultra detailed","Realistic"],["Aerial view, France. Colorful lego bricks","Lego brick"],["Aerial view, France. Black and white paper pencil drawing","Pencil"],["Aerial view, France. Oil on canvas painting","Painting"]];function Qe(){return BigInt(0xb7dd73e137d20800&((1<<63)-1)*Math.random())}const ve=Q(new Map),ze=Q(),Pe=Q(),Ce=Q(),me=Q(),Me=Q({prompt:Se[0][0],seed:Qe(),steps:20}),he=Q(!1),we=Q(!1);function Ne(l,e,t){const r=l.slice();return r[3]=e[t],r[5]=t,r}function Ue(l){let e,t,r,s,a,i,p,n,m,k,g,C;return{c(){e=M("div"),t=M("input"),i=D(),p=M("label"),n=M("img"),C=D(),this.h()},l(h){e=O(h,"DIV",{class:!0});var w=T(e);t=O(w,"INPUT",{type:!0,name:!0,id:!0,class:!0}),i=j(w),p=O(w,"LABEL",{for:!0,class:!0});var S=T(p);n=O(S,"IMG",{src:!0,alt:!0,class:!0}),S.forEach(E),C=j(w),w.forEach(E),this.h()},h(){c(t,"type","radio"),c(t,"name","samples"),c(t,"id",r="sample-"+l[5]),t.value=s=l[5],t.disabled=a=l[0]===!0,c(t,"class","svelte-1gwcbp"),ke(n.src,m=Ze+l[3])||c(n,"src",m),c(n,"alt",k=l[3]),c(n,"class","svelte-1gwcbp"),c(p,"for",g="sample-"+l[5]),c(p,"class","svelte-1gwcbp"),c(e,"class","snap-always snap-start")},m(h,w){$(h,e,w),d(e,t),d(e,i),d(e,p),d(p,n),d(e,C)},p(h,w){w&1&&a!==(a=h[0]===!0)&&(t.disabled=a)},d(h){h&&E(e)}}}function at(l){let e,t,r,s,a,i,p,n,m=Ie,k=[];for(let g=0;g<m.length;g+=1)k[g]=Ue(Ne(l,m,g));return{c(){e=M("div"),t=M("h4"),r=V("Select a Template"),s=D(),a=M("form"),i=M("div");for(let g=0;g<k.length;g+=1)k[g].c();this.h()},l(g){e=O(g,"DIV",{});var C=T(e);t=O(C,"H4",{class:!0});var h=T(t);r=F(h,"Select a Template"),h.forEach(E),s=j(C),a=O(C,"FORM",{class:!0});var w=T(a);i=O(w,"DIV",{class:!0});var S=T(i);for(let o=0;o<k.length;o+=1)k[o].l(S);S.forEach(E),w.forEach(E),C.forEach(E),this.h()},h(){c(t,"class","font-bold mt-6 mb-2 my-6 leading-6"),c(i,"class","samples svelte-1gwcbp"),c(a,"class","svelte-1gwcbp")},m(g,C){$(g,e,C),d(e,t),d(t,r),d(e,s),d(e,a),d(a,i);for(let h=0;h<k.length;h+=1)k[h].m(i,null);p||(n=N(a,"input",l[1]),p=!0)},p(g,[C]){if(C&1){m=Ie;let h;for(h=0;h<m.length;h+=1){const w=Ne(g,m,h);k[h]?k[h].p(w,C):(k[h]=Ue(w),k[h].c(),k[h].m(i,null))}for(;h<k.length;h+=1)k[h].d(1);k.length=m.length}},i:Y,o:Y,d(g){g&&E(e),Oe(k,g),p=!1,n()}}}async function ot(l){return new Promise((e,t)=>{const r=new Image;r.onload=()=>{URL.revokeObjectURL(r.src),e(r)},r.onerror=s=>{t(s)},r.src=URL.createObjectURL(l)})}function st(l,e,t){let r,s;return G(l,Ce,i=>t(2,r=i)),G(l,he,i=>t(0,s=i)),[s,async i=>{i.preventDefault();const p=Ie[parseInt(i.target.value)];if(p){const n=await fetch(Ze+p).then(k=>k.blob()),m=await ot(n);J(Ce,r=m,r)}}]}class nt extends W{constructor(e){super(),ee(this,e,st,at,te,{})}}function Ve(l,e,t){const r=l.slice();return r[2]=e[t],r[7]=t,r}function Fe(l){let e,t,r,s,a,i,p,n,m,k,g,C,h=l[2].label+"",w,S,o;return{c(){e=M("div"),t=M("input"),i=D(),p=M("label"),n=pe("svg"),m=pe("rect"),g=D(),C=M("span"),w=V(h),o=D(),this.h()},l(f){e=O(f,"DIV",{class:!0});var b=T(e);t=O(b,"INPUT",{name:!0,type:!0,id:!0,class:!0}),i=j(b),p=O(b,"LABEL",{for:!0,class:!0});var u=T(p);n=de(u,"svg",{width:!0,height:!0,viewBox:!0,class:!0});var v=T(n);m=de(v,"rect",{x:!0,y:!0,width:!0,height:!0,fill:!0}),T(m).forEach(E),v.forEach(E),g=j(u),C=O(u,"SPAN",{class:!0});var y=T(C);w=F(y,h),y.forEach(E),u.forEach(E),o=j(b),b.forEach(E),this.h()},h(){c(t,"name","color"),t.checked=r=l[7]==We,c(t,"type","radio"),c(t,"id",s="color-"+l[7]),t.value=a=l[7],c(t,"class","svelte-1oy4poo"),c(m,"x","0"),c(m,"y","0"),c(m,"width","20"),c(m,"height","20"),c(m,"fill",k="rgb("+l[2].color.join(",")+")"),c(n,"width","20"),c(n,"height","20"),c(n,"viewBox","0 0 20 20"),c(n,"class","svelte-1oy4poo"),c(C,"class","svelte-1oy4poo"),c(p,"for",S="color-"+l[7]),c(p,"class","svelte-1oy4poo"),c(e,"class","snap-always snap-start")},m(f,b){$(f,e,b),d(e,t),d(e,i),d(e,p),d(p,n),d(n,m),d(p,g),d(p,C),d(C,w),d(e,o)},p:Y,d(f){f&&E(e)}}}function it(l){let e,t,r,s,a,i,p,n,m,k,g,C,h,w=l[0].size+"",S,o,f,b=ye,u=[];for(let v=0;v<b.length;v+=1)u[v]=Fe(Ve(l,b,v));return{c(){e=M("form"),t=M("h4"),r=V("Brush Type"),s=D(),a=M("div");for(let v=0;v<u.length;v+=1)u[v].c();i=D(),p=M("h4"),n=V("Brush Size"),m=D(),k=M("div"),g=M("input"),C=D(),h=M("label"),S=V(w),this.h()},l(v){e=O(v,"FORM",{});var y=T(e);t=O(y,"H4",{class:!0});var x=T(t);r=F(x,"Brush Type"),x.forEach(E),s=j(y),a=O(y,"DIV",{class:!0,name:!0});var z=T(a);for(let I=0;I<u.length;I+=1)u[I].l(z);z.forEach(E),i=j(y),p=O(y,"H4",{class:!0});var _=T(p);n=F(_,"Brush Size"),_.forEach(E),m=j(y),k=O(y,"DIV",{class:!0});var P=T(k);g=O(P,"INPUT",{min:!0,max:!0,step:!0,name:!0,type:!0}),C=j(P),h=O(P,"LABEL",{class:!0,for:!0});var B=T(h);S=F(B,w),B.forEach(E),P.forEach(E),y.forEach(E),this.h()},h(){c(t,"class","font-bold mt-6 mb-2 leading-6 my-3"),c(a,"class","colors svelte-1oy4poo"),c(a,"name","colors"),c(p,"class","font-bold mt-6 mb-2 my-6 leading-6"),g.value="10",c(g,"min","1"),c(g,"max","150"),c(g,"step","1"),c(g,"name","brush"),c(g,"type","range"),c(h,"class","pl-2 svelte-1oy4poo"),c(h,"for","brush"),c(k,"class","brush svelte-1oy4poo")},m(v,y){$(v,e,y),d(e,t),d(t,r),d(e,s),d(e,a);for(let x=0;x<u.length;x+=1)u[x].m(a,null);d(e,i),d(e,p),d(p,n),d(e,m),d(e,k),d(k,g),d(k,C),d(k,h),d(h,S),o||(f=N(e,"input",l[1]),o=!0)},p(v,[y]){if(y&0){b=ye;let x;for(x=0;x<b.length;x+=1){const z=Ve(v,b,x);u[x]?u[x].p(z,y):(u[x]=Fe(z),u[x].c(),u[x].m(a,null))}for(;x<u.length;x+=1)u[x].d(1);u.length=b.length}y&1&&w!==(w=v[0].size+"")&&Te(S,w)},i:Y,o:Y,d(v){v&&E(e),Oe(u,v),o=!1,f()}}}const We=6;function ct(l,e,t){let r;G(l,me,m=>t(0,r=m));const{color:s,label:a}=ye[We];let i=`rgb(${s.join(",")})`,p=40;return J(me,r={color:i,size:p,label:a},r),[r,async m=>{const k=m.target;if(k.name==="color"){const g=parseInt(k.value),{color:C,label:h}=ye[g];i=`rgb(${C.join(",")})`,J(me,r={color:i,size:p,label:h},r)}else k.name==="brush"&&(p=parseInt(k.value),J(me,r={color:i,size:p,label:a},r))},s]}class ut extends W{constructor(e){super(),ee(this,e,ct,it,te,{})}}function Ge(l,e,t){const r=l.slice();return r[13]=e[t],r}function qe(l){let e,t=l[13][1]+"",r,s,a;return{c(){e=M("option"),r=V(t),a=V("`"),this.h()},l(i){e=O(i,"OPTION",{});var p=T(e);r=F(p,t),p.forEach(E),a=F(i,"`"),this.h()},h(){e.__value=s=l[13][0],e.value=e.__value},m(i,p){$(i,e,p),d(e,r),$(i,a,p)},p:Y,d(i){i&&E(e),i&&E(a)}}}function pt(l){let e,t,r,s,a,i,p,n,m,k,g,C,h,w,S,o,f,b,u,v,y,x,z,_,P,B,I,R,K,H,X,Z,fe,re=Se,q=[];for(let L=0;L<re.length;L+=1)q[L]=qe(Ge(l,re,L));return{c(){e=M("form"),t=M("h4"),r=V("Prompt"),s=D(),a=M("input"),p=D(),n=M("select"),m=M("option"),k=V("preset");for(let L=0;L<q.length;L+=1)q[L].c();C=D(),h=M("h4"),w=V("Random Seed"),S=D(),o=M("input"),b=D(),u=M("button"),v=V("Random"),x=D(),z=M("h4"),_=V("Sample Steps"),P=D(),B=M("div"),I=M("input"),K=D(),H=M("label"),X=V(l[2]),this.h()},l(L){e=O(L,"FORM",{});var A=T(e);t=O(A,"H4",{class:!0});var U=T(t);r=F(U,"Prompt"),U.forEach(E),s=j(A),a=O(A,"INPUT",{name:!0,placeholder:!0,style:!0,class:!0}),p=j(A),n=O(A,"SELECT",{name:!0,class:!0});var le=T(n);m=O(le,"OPTION",{});var Re=T(m);k=F(Re,"preset"),Re.forEach(E);for(let _e=0;_e<q.length;_e+=1)q[_e].l(le);le.forEach(E),C=j(A),h=O(A,"H4",{class:!0});var Ae=T(h);w=F(Ae,"Random Seed"),Ae.forEach(E),S=j(A),o=O(A,"INPUT",{type:!0,name:!0,placeholder:!0,class:!0}),b=j(A),u=O(A,"BUTTON",{class:!0});var De=T(u);v=F(De,"Random"),De.forEach(E),x=j(A),z=O(A,"H4",{class:!0});var je=T(z);_=F(je,"Sample Steps"),je.forEach(E),P=j(A),B=O(A,"DIV",{class:!0});var be=T(B);I=O(be,"INPUT",{type:!0,name:!0,min:!0,max:!0,step:!0,class:!0}),K=j(be),H=O(be,"LABEL",{class:!0,for:!0});var Le=T(H);X=F(Le,l[2]),Le.forEach(E),be.forEach(E),A.forEach(E),this.h()},h(){c(t,"class","font-bold mt-6 mb-2 my-6 leading-6"),c(a,"name","prompt"),c(a,"placeholder","Aerial view of ..., France."),a.disabled=i=l[4]===!0,tt(a,"width","500px"),c(a,"class","svelte-uoay71"),m.disabled=!0,m.selected=!0,m.__value="preset",m.value=m.__value,c(n,"name","presets"),n.disabled=g=l[4]===!0,c(n,"class","svelte-uoay71"),c(h,"class","font-bold mt-6 mb-2 my-6 leading-6"),c(o,"type","Number"),c(o,"name","seed"),c(o,"placeholder","Integer Seed"),o.disabled=f=l[4]===!0,c(o,"class","svelte-uoay71"),u.disabled=y=l[4]===!0,c(u,"class","svelte-uoay71"),c(z,"class","font-bold mt-6 mb-2 my-6 leading-6"),c(I,"type","range"),c(I,"name","steps"),c(I,"min","10"),c(I,"max","30"),c(I,"step","1"),I.disabled=R=l[4]===!0,c(I,"class","svelte-uoay71"),c(H,"class","pl-2 svelte-uoay71"),c(H,"for","steps"),c(B,"class","flex")},m(L,A){$(L,e,A),d(e,t),d(t,r),d(e,s),d(e,a),ae(a,l[3]),d(e,p),d(e,n),d(n,m),d(m,k);for(let U=0;U<q.length;U+=1)q[U].m(n,null);d(e,C),d(e,h),d(h,w),d(e,S),d(e,o),ae(o,l[1]),d(e,b),d(e,u),d(u,v),d(e,x),d(e,z),d(z,_),d(e,P),d(e,B),d(B,I),ae(I,l[2]),d(B,K),d(B,H),d(H,X),l[11](e),Z||(fe=[N(a,"input",l[6]),N(n,"change",l[7]),N(o,"input",l[8]),N(u,"click",ge(l[9])),N(I,"change",l[10]),N(I,"input",l[10]),N(e,"input",l[5])],Z=!0)},p(L,[A]){if(A&16&&i!==(i=L[4]===!0)&&(a.disabled=i),A&8&&a.value!==L[3]&&ae(a,L[3]),A&0){re=Se;let U;for(U=0;U<re.length;U+=1){const le=Ge(L,re,U);q[U]?q[U].p(le,A):(q[U]=qe(le),q[U].c(),q[U].m(n,null))}for(;U<q.length;U+=1)q[U].d(1);q.length=re.length}A&16&&g!==(g=L[4]===!0)&&(n.disabled=g),A&16&&f!==(f=L[4]===!0)&&(o.disabled=f),A&2&&ae(o,L[1]),A&16&&y!==(y=L[4]===!0)&&(u.disabled=y),A&16&&R!==(R=L[4]===!0)&&(I.disabled=R),A&4&&ae(I,L[2]),A&4&&Te(X,L[2])},i:Y,o:Y,d(L){L&&E(e),Oe(q,L),l[11](null),Z=!1,Be(fe)}}}function dt(l,e,t){let r,s;G(l,Me,o=>t(12,r=o)),G(l,he,o=>t(4,s=o));function a(){const o=i.elements;J(Me,r={prompt:o.prompt.value,seed:BigInt(o.seed.value),steps:parseInt(o.steps.value)},r)}let i,p=r.seed,n=r.steps,m=r.prompt;function k(){m=this.value,t(3,m)}const g=o=>{t(3,m=o.currentTarget.value)};function C(){p=this.value,t(1,p)}const h=()=>{t(1,p=Qe()),a()};function w(){n=rt(this.value),t(2,n)}function S(o){Ee[o?"unshift":"push"](()=>{i=o,t(0,i)})}return[i,p,n,m,s,a,k,g,C,h,w,S]}class ht extends W{constructor(e){super(),ee(this,e,dt,pt,te,{})}}let ft=(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 vt=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function mt(l){return l&&l.__esModule&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l}var et={exports:{}};(function(l,e){(function(t,r){l.exports=r()})(typeof self!="undefined"?self:vt,function(){return function(t){var r={};function s(a){if(r[a])return r[a].exports;var i=r[a]={i:a,l:!1,exports:{}};return t[a].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=t,s.c=r,s.d=function(a,i,p){s.o(a,i)||Object.defineProperty(a,i,{enumerable:!0,get:p})},s.r=function(a){typeof Symbol!="undefined"&&Symbol.toStringTag&&Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(a,"__esModule",{value:!0})},s.t=function(a,i){if(1&i&&(a=s(a)),8&i||4&i&&typeof a=="object"&&a&&a.__esModule)return a;var p=Object.create(null);if(s.r(p),Object.defineProperty(p,"default",{enumerable:!0,value:a}),2&i&&typeof a!="string")for(var n in a)s.d(p,n,function(m){return a[m]}.bind(null,n));return p},s.n=function(a){var i=a&&a.__esModule?function(){return a.default}:function(){return a};return s.d(i,"a",i),i},s.o=function(a,i){return Object.prototype.hasOwnProperty.call(a,i)},s.p="",s(s.s=0)}([function(t,r,s){function a(h,w){return function(S){if(Array.isArray(S))return S}(h)||function(S,o){if(Symbol.iterator in Object(S)||Object.prototype.toString.call(S)==="[object Arguments]"){var f=[],b=!0,u=!1,v=void 0;try{for(var y,x=S[Symbol.iterator]();!(b=(y=x.next()).done)&&(f.push(y.value),!o||f.length!==o);b=!0);}catch(z){u=!0,v=z}finally{try{b||x.return==null||x.return()}finally{if(u)throw v}}return f}}(h,w)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function i(h){return function(w){if(Array.isArray(w)){for(var S=0,o=new Array(w.length);S<w.length;S++)o[S]=w[S];return o}}(h)||function(w){if(Symbol.iterator in Object(w)||Object.prototype.toString.call(w)==="[object Arguments]")return Array.from(w)}(h)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function p(h,w){for(var S=0;S<w.length;S++){var o=w[S];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(h,o.key,o)}}s.r(r);var n=/^#?[0-9A-Fa-f]{1,2}[0-9A-Fa-f]{1,2}[0-9A-Fa-f]{1,2}$/,m=/^rgb\((\s+)?[0-9]{1,3},(\s+)?[0-9]{1,3},(\s+)?[0-9]{1,3}(\s+)?\)$/,k=function(){function h(){(function(o,f){if(!(o instanceof f))throw new TypeError("Cannot call a class as a function")})(this,h),this.canvases={}}var w,S;return w=h,(S=[{key:"parseColor",value:function(o){var f=n.test(o),b=m.test(o);if(!f&&!b)throw new Error("Color is not correct format. #123123 or rgb(123, 123, 123) format required.");if(f){var u=o[0]==="#"?o.slice(1):o;return u=u.length===3?u.split("").reduce(function(_,P){return[].concat(i(_),[P,P])},[]).join(""):u,{r:parseInt(u.slice(0,2),16),g:parseInt(u.slice(2,4),16),b:parseInt(u.slice(4,6),16)}}if(b){var v=a(o.replace(/rgb|\s+|\(|\)/g,"").split(",").map(function(_){return parseInt(_)}),3),y=v[0],x=v[1],z=v[2];return{r:y=y>255?255:y,g:x=x>255?255:x,b:z=z>255?255:z}}}},{key:"make",value:function(o){var f=o.size,b=o.color;try{f*=window.devicePixelRatio;var u=this.parseColor(b),v=JSON.stringify(u);if(this.canvases[v]=this.canvases[v]||{},this.canvases[v][f]!=null)return this.canvases[v][f];var y=document.createElement("canvas");f+=f%2,y.width=f,y.height=f;for(var x=y.getContext("2d"),z=x.createImageData(f,f),_=0;_<z.data.length;_+=4)z.data[_]=255,z.data[_+1]=255,z.data[_+2]=255,z.data[_+3]=0;return this.plotCircle(2*f,4*f*(f/2),f/2,z,f,u),this.fillCircle(z,u),x.putImageData(z,0,0),this.canvases[v][f]=y,y}catch(P){console.error(P)}}},{key:"plotCircle",value:function(o,f,b,u,v,y){var x=-b,z=0,_=2-2*b;do{var P=o-4*(x+1)+(f+4*v*(z-1));u.data[P+0]=y.r,u.data[P+1]=y.g,u.data[P+2]=y.b,u.data[P+3]=255;var B=o-z*(4*v)+(f-4*(x+1));u.data[B+0]=y.r,u.data[B+1]=y.g,u.data[B+2]=y.b,u.data[B+3]=255;var I=o+4*x+(f-z*(4*v));u.data[I+0]=y.r,u.data[I+1]=y.g,u.data[I+2]=y.b,u.data[I+3]=255;var R=o+4*v*(z-1)+(f+4*x);u.data[R+0]=y.r,u.data[R+1]=y.g,u.data[R+2]=y.b,u.data[R+3]=255,(b=_)<=z&&(_+=2*++z+1),(b>x||_>z)&&(_+=2*++x+1)}while(x<0)}},{key:"fillCircle",value:function(o,f){for(var b=4*o.width,u=1;u<o.height-1;u+=1)for(var v=!1,y=!1,x=!1,z=0;z<b;z+=4){var _=b*u+z,P=o.data[_+3],B=P===255;B&&!v?v=!0:P===0&&v?y=!0:B&&v&&y&&(x=!0),v&&y&&!x&&(o.data[_]=f.r,o.data[_+1]=f.g,o.data[_+2]=f.b,o.data[_+3]=255)}}}])&&p(w.prototype,S),h}();function g(h,w){for(var S=0;S<w.length;S++){var o=w[S];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(h,o.key,o)}}var C=function(){function h(o){(function(f,b){if(!(f instanceof b))throw new TypeError("Cannot call a class as a function")})(this,h),this.canvas=o,this.context=o.getContext("2d"),this.stampMaker=new k,this.configPixelRatio()}var w,S;return w=h,(S=[{key:"configPixelRatio",value:function(){var o=this.canvas,f=o.width,b=o.height;this.canvas.width=f*this.dpr,this.canvas.height=b*this.dpr,this.canvas.style.width="".concat(f,"px"),this.canvas.style.height="".concat(b,"px"),this.context.scale(this.dpr,this.dpr),this.context.imageSmoothingEnabled=!1}},{key:"exportAsPNG",value:function(o){var f=this;return new Promise(function(b){var u=document.createElement("canvas"),v=u.getContext("2d"),y=f.canvas,x=y.width,z=y.height,_=x/f.dpr,P=z/f.dpr;u.width=_,u.height=P,v.imageSmoothingEnabled=!1,v.drawImage(f.canvas,0,0,x,z,0,0,_,P),u.toBlob(function(B){B.lastModifedDate=new Date,B.name=o,b(B)})})}},{key:"distanceBetween",value:function(o,f){return Math.sqrt(Math.pow(f.x-o.x,2)+Math.pow(f.y-o.y,2))}},{key:"angleBetween",value:function(o,f){return Math.atan2(f.x-o.x,f.y-o.y)}},{key:"draw",value:function(o){var f=o.from,b=o.to,u=o.size,v=o.color;this.context.globalCompositeOperation="source-over",this.brush({from:f,to:b,size:u,color:v})}},{key:"erase",value:function(o){var f=o.from,b=o.to,u=o.size;this.context.globalCompositeOperation="destination-out",this.brush({from:f,to:b,size:u,color:"#000000"})}},{key:"brush",value:function(o){var f=this,b=o.from,u=o.to,v=o.size,y=o.color,x=(v-v%2)/2,z=this.stampMaker.make({size:v,color:y});if(b.x!==u.x||b.y!==u.y)for(var _=this.distanceBetween(b,u),P=this.angleBetween(b,u),B=function(H){var X=b.x+Math.sin(P)*H-x,Z=b.y+Math.cos(P)*H-x;window.requestAnimationFrame(function(){f.context.drawImage(z,Math.round(X),Math.round(Z),v,v)})},I=0;I<_;I+=1)B(I);else{var R=b.x-x,K=b.y-x;this.context.drawImage(z,Math.round(R),Math.round(K),v,v)}}},{key:"dpr",get:function(){return window.devicePixelRatio||1}}])&&g(w.prototype,S),h}();r.default=C}])})})(et);var He=mt(et.exports);function bt(l){let e,t;return{c(){e=pe("svg"),t=pe("path"),this.h()},l(r){e=de(r,"svg",{xmlns:!0,width:!0,viewBox:!0,class:!0});var s=T(e);t=de(s,"path",{fill:!0,stroke:!0,"stroke-width":!0,d:!0}),T(t).forEach(E),s.forEach(E),this.h()},h(){c(t,"fill","white"),c(t,"stroke","black"),c(t,"stroke-width","30"),c(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"),c(e,"xmlns","http://www.w3.org/2000/svg"),c(e,"width","20"),c(e,"viewBox","0 0 512 512"),c(e,"class",l[0])},m(r,s){$(r,e,s),d(e,t)},p(r,[s]){s&1&&c(e,"class",r[0])},i:Y,o:Y,d(r){r&&E(e)}}}function gt(l,e,t){let{classNames:r=""}=e;return l.$$set=s=>{"classNames"in s&&t(0,r=s.classNames)},[r]}class yt extends W{constructor(e){super(),ee(this,e,gt,bt,te,{classNames:0})}}function wt(l){var f;let e,t,r,s,a,i,p,n=((f=l[0])==null?void 0:f.label)+"",m,k,g,C,h,w,S,o;return C=new yt({}),{c(){e=M("div"),t=M("div"),r=M("canvas"),s=D(),a=M("canvas"),i=D(),p=M("span"),m=V(n),k=D(),g=M("button"),oe(C.$$.fragment),this.h()},l(b){e=O(b,"DIV",{});var u=T(e);t=O(u,"DIV",{class:!0});var v=T(t);r=O(v,"CANVAS",{class:!0,width:!0,height:!0}),T(r).forEach(E),s=j(v),a=O(v,"CANVAS",{class:!0,width:!0,height:!0}),T(a).forEach(E),i=j(v),p=O(v,"SPAN",{class:!0});var y=T(p);m=F(y,n),y.forEach(E),k=j(v),g=O(v,"BUTTON",{class:!0});var x=T(g);se(C.$$.fragment,x),x.forEach(E),v.forEach(E),u.forEach(E),this.h()},h(){c(r,"class","canvas svelte-pr47cz"),c(r,"width","512"),c(r,"height","512"),c(a,"class","brush svelte-pr47cz"),c(a,"width","10"),c(a,"height","10"),c(p,"class","label svelte-pr47cz"),c(g,"class","absolute bottom-0 left-0 p-3"),g.disabled=h=l[3].size<=0,c(t,"class","relative overflow-clip")},m(b,u){$(b,e,u),d(e,t),d(t,r),l[11](r),d(t,s),d(t,a),l[12](a),d(t,i),d(t,p),d(p,m),d(t,k),d(t,g),ne(C,g,null),w=!0,S||(o=[N(r,"touchmove",xt),N(r,"pointerenter",_t),N(r,"pointerup",l[4]),N(r,"pointerleave",l[4]),N(r,"pointercancel",l[4]),N(r,"pointerout",l[4]),N(r,"pointermove",l[6]),N(r,"pointerdown",l[5]),N(g,"click",ge(l[13]))],S=!0)},p(b,[u]){var v;(!w||u&1)&&n!==(n=((v=b[0])==null?void 0:v.label)+"")&&Te(m,n),(!w||u&8&&h!==(h=b[3].size<=0))&&(g.disabled=h)},i(b){w||(ie(C.$$.fragment,b),w=!0)},o(b){ce(C.$$.fragment,b),w=!1},d(b){b&&E(e),l[11](null),l[12](null),ue(C),S=!1,Be(o)}}}function _t(){}function $e(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 Ye(l){l.fillStyle="#000000",l.fillRect(0,0,l.canvas.width,l.canvas.height)}function xe(l,e){l.drawImage(e,0,0,l.canvas.width,l.canvas.height)}const xt=l=>l.preventDefault();function kt(l,e,t){let r,s,a,i;G(l,ve,_=>t(3,r=_)),G(l,Ce,_=>t(10,s=_)),G(l,me,_=>t(0,a=_)),G(l,Pe,_=>t(18,i=_));let p,n,m,k,g={x:0,y:0},C;lt(()=>{t(9,k=p.getContext("2d")),t(8,m=n.getContext("2d")),window.devicePixelRatio=1,C=new He(p),t(1,p.style.height="unset",p),t(1,p.style.width="unset",p),J(Pe,i=p,i),Ye(k)});let h=!1,w;function S(){t(2,n.style.top=`${10+a.size/2}px`,n),t(2,n.style.left=`${10+a.size/2}px`,n),h=!1}function o(_){h=!0,g=$e(p,_),C.draw({from:g,to:g,size:a.size,color:a.color}),w=ft(),ve.update(P=>(P.set(w,{brush:a,points:[{from:g,to:g}]}),P))}function f(_){const P=$e(p,_);t(2,n.style.top=`${_.offsetY}px`,n),t(2,n.style.left=`${_.offsetX}px`,n),h&&(C.draw({from:g,to:P,size:a.size,color:a.color}),ve.update(B=>{const I=B.get(w);return I==null||I.points.push({from:g,to:P}),B}),g=P)}function b(_){const{size:P,color:B}=_;t(2,n.width=P,n),t(2,n.height=P,n),t(8,m.fillStyle=B,m),m.arc(P/2,P/2,P/2,0,2*Math.PI),m.fill()}function u(){if(r.size<=0)return;const _=Array.from(r.keys());ve.update(P=>(P.delete(_[_.length-1]),P)),v(k)}function v(_){const P=document.createElement("canvas");P.width=512,P.height=512,window.devicePixelRatio=1;const B=new He(P);Ye(_),s&&xe(_,s),Array.from(r.values()).forEach(I=>{I.points.forEach((R,K)=>{B.draw({from:R.from,to:R.to,size:I.brush.size,color:I.brush.color})})}),requestAnimationFrame(()=>{xe(_,P)})}function y(_){Ee[_?"unshift":"push"](()=>{p=_,t(1,p)})}function x(_){Ee[_?"unshift":"push"](()=>{n=_,t(2,n),t(8,m),t(0,a)})}const z=()=>u();return l.$$.update=()=>{l.$$.dirty&257&&m&&a&&(b(a),t(2,n.style.top=`${10+a.size/2}px`,n),t(2,n.style.left=`${10+a.size/2}px`,n)),l.$$.dirty&1536&&s&&(xe(k,s),J(ve,r=new Map,r))},[a,p,n,r,S,o,f,u,m,k,s,y,x,z]}class Et extends W{constructor(e){super(),ee(this,e,kt,wt,te,{})}}function Je(l){let e,t,r;return{c(){e=M("img"),this.h()},l(s){e=O(s,"IMG",{class:!0,alt:!0,src:!0,width:!0,height:!0}),this.h()},h(){c(e,"class",t="image "+(l[1]?"opacity-30":"")+" svelte-1t0h0rs"),c(e,"alt","Generative Map Result"),ke(e.src,r=l[0])||c(e,"src",r),c(e,"width","512"),c(e,"height","512")},m(s,a){$(s,e,a)},p(s,a){a&2&&t!==(t="image "+(s[1]?"opacity-30":"")+" svelte-1t0h0rs")&&c(e,"class",t),a&1&&!ke(e.src,r=s[0])&&c(e,"src",r)},d(s){s&&E(e)}}}function Xe(l){let e,t,r,s,a,i;return{c(){e=M("div"),t=pe("svg"),r=pe("path"),s=D(),a=M("span"),i=V(Ke),this.h()},l(p){e=O(p,"DIV",{class:!0});var n=T(e);t=de(n,"svg",{xmlns:!0,fill:!0,viewBox:!0,class:!0});var m=T(t);r=de(m,"path",{fill:!0,d:!0}),T(r).forEach(E),m.forEach(E),s=j(n),a=O(n,"SPAN",{class:!0});var k=T(a);i=F(k,Ke),k.forEach(E),n.forEach(E),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-[3rem]"),c(a,"class","text-xs"),c(e,"class","loading svelte-1t0h0rs")},m(p,n){$(p,e,n),d(e,t),d(t,r),d(e,s),d(e,a),d(a,i)},p:Y,d(p){p&&E(e)}}}function It(l){let e,t,r=l[0]&&Je(l),s=l[1]&&Xe();return{c(){e=M("div"),r&&r.c(),t=D(),s&&s.c(),this.h()},l(a){e=O(a,"DIV",{class:!0});var i=T(e);r&&r.l(i),t=j(i),s&&s.l(i),i.forEach(E),this.h()},h(){c(e,"class","relative overflow-clip flex flex-col justify-center items-center w-full h-full")},m(a,i){$(a,e,i),r&&r.m(e,null),d(e,t),s&&s.m(e,null)},p(a,[i]){a[0]?r?r.p(a,i):(r=Je(a),r.c(),r.m(e,t)):r&&(r.d(1),r=null),a[1]?s?s.p(a,i):(s=Xe(),s.c(),s.m(e,null)):s&&(s.d(1),s=null)},i:Y,o:Y,d(a){a&&E(e),r&&r.d(),s&&s.d()}}}let Ke="";async function St(l){return new Promise((e,t)=>{try{const r=document.createElement("a");r.download=`sucess-${Date.now()}.png`,r.target="_self",r.onclick=async s=>{r.href&&URL.revokeObjectURL(r.href),r.href=l},requestAnimationFrame(()=>{console.log("Downloading image."),r.click(),e(null)})}catch{t()}})}async function zt(l,{prompt:e,steps:t,seed:r}){const s=await fetch("/predict",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:[l,e,t,r.toString()]})});if(!s.ok)throw new Error("Prediction request failed.");return await s.text()}function Pt(l,e,t){let r,s,a,i,p;return G(l,we,n=>t(2,r=n)),G(l,ze,n=>t(0,s=n)),G(l,he,n=>t(1,a=n)),G(l,Me,n=>t(3,i=n)),G(l,Pe,n=>t(4,p=n)),l.$$.update=()=>{l.$$.dirty&26&&(async()=>{if(a){const n=await zt(p.toDataURL(),i);J(ze,s=n,s),J(he,a=!1,a)}})(),l.$$.dirty&5&&(async()=>r&&(await St(s),J(we,r=!1,r)))()},[s,a,r,i,p]}class Ct extends W{constructor(e){super(),ee(this,e,Pt,It,te,{})}}function Mt(l){let e,t,r,s,a,i,p,n,m,k,g,C,h,w,S,o,f,b,u,v,y,x,z,_,P,B;return i=new ut({}),m=new Et({}),g=new Ct({}),y=new nt({}),z=new ht({}),{c(){e=M("div"),t=M("article"),r=M("h1"),s=V("Drawing to Map"),a=D(),oe(i.$$.fragment),p=D(),n=M("div"),oe(m.$$.fragment),k=D(),oe(g.$$.fragment),C=D(),h=M("button"),w=V("Generate Map"),o=D(),f=M("button"),b=V("Save Result"),v=D(),oe(y.$$.fragment),x=D(),oe(z.$$.fragment),this.h()},l(I){e=O(I,"DIV",{class:!0});var R=T(e);t=O(R,"ARTICLE",{class:!0});var K=T(t);r=O(K,"H1",{});var H=T(r);s=F(H,"Drawing to Map"),H.forEach(E),K.forEach(E),a=j(R),se(i.$$.fragment,R),p=j(R),n=O(R,"DIV",{class:!0});var X=T(n);se(m.$$.fragment,X),k=j(X),se(g.$$.fragment,X),X.forEach(E),C=j(R),h=O(R,"BUTTON",{class:!0});var Z=T(h);w=F(Z,"Generate Map"),Z.forEach(E),o=j(R),f=O(R,"BUTTON",{class:!0});var fe=T(f);b=F(fe,"Save Result"),fe.forEach(E),v=j(R),se(y.$$.fragment,R),x=j(R),se(z.$$.fragment,R),R.forEach(E),this.h()},h(){c(t,"class","prose dark:prose-invert"),c(n,"class","drawings py-3 -mx-3 svelte-237ry5"),h.disabled=S=l[0]===!0,c(h,"class","svelte-237ry5"),f.disabled=u=l[1]===!0||!l[2],c(f,"class","svelte-237ry5"),c(e,"class","max-w-screen-md mx-auto px-3 py-5 relative z-0")},m(I,R){$(I,e,R),d(e,t),d(t,r),d(r,s),d(e,a),ne(i,e,null),d(e,p),d(e,n),ne(m,n,null),d(n,k),ne(g,n,null),d(e,C),d(e,h),d(h,w),d(e,o),d(e,f),d(f,b),d(e,v),ne(y,e,null),d(e,x),ne(z,e,null),_=!0,P||(B=[N(h,"click",ge(l[3])),N(f,"click",ge(l[4]))],P=!0)},p(I,[R]){(!_||R&1&&S!==(S=I[0]===!0))&&(h.disabled=S),(!_||R&6&&u!==(u=I[1]===!0||!I[2]))&&(f.disabled=u)},i(I){_||(ie(i.$$.fragment,I),ie(m.$$.fragment,I),ie(g.$$.fragment,I),ie(y.$$.fragment,I),ie(z.$$.fragment,I),_=!0)},o(I){ce(i.$$.fragment,I),ce(m.$$.fragment,I),ce(g.$$.fragment,I),ce(y.$$.fragment,I),ce(z.$$.fragment,I),_=!1},d(I){I&&E(e),ue(i),ue(m),ue(g),ue(y),ue(z),P=!1,Be(B)}}}function Ot(l,e,t){let r,s,a;return G(l,he,n=>t(0,r=n)),G(l,we,n=>t(1,s=n)),G(l,ze,n=>t(2,a=n)),[r,s,a,()=>J(he,r=!0,r),()=>J(we,s=!0,s)]}class Rt extends W{constructor(e){super(),ee(this,e,Ot,Mt,te,{})}}export{Rt as default};