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