0x96a8…d253

All memos sent from and to 0x96a8…d253.

Ii=!1,Ni=!1;function Ui(){F.save(),F.scale(D,D),Ni||(F.fillStyle="#FFF",F.rect(0,0,Y,P),F.fill(),Ni=!0)}function Di(){F.restore()}function Oi(){Ni=!1}function Bi(e,t="red",n=!0){if(e.length){Ui(),F.beginPath(),F.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;t++)F.lineTo(e[t].x,e[t].y);F.closePath(),F.lineCap="round",n?(F.fillStyle=t,F.fill()):(F.lineWidth=3,F.strokeStyle=t,F.stroke()),Di()}}function Qi(e,t="red",n=!1,l=1){Ui(),F.beginPath(),F.lineCap="round",F.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;t++)F.lineTo(e[t].x,e[t].y);n&&F.closePath(),F.lineWidth=l,F.strokeStyle=t,F.stroke(),Di()}function ji(){Oi();for(let e of[...hn,...Si])if(e.category==mn.foreground){let t=e?.detailObjectProps?.inDominantShapes?.length>0;Bi(e.polygon,t?"blue":"red",!0),Bi(e.polygon,"black",!1)}return!1}function Ji(){Oi();for(let e of[...hn,...Si])if(e.category==mn.foreground){let t=tl(e.detailObject?.[0].lineColor||[0,0,0]);Bi(e.polygon,t,!0),Bi(e.polygon,"black",!1)}return!1}function Ai(){Oi();for(let e of[...hn,...Si])if(e.category==mn.foreground){let t=e.lightingIntensity||Ie.default,n=fe(t,Ie.min,Ie.max,0,255);Bi(e.polygon,`rgba(${n},${n},${n},1)`,!0)}return!1}function Ei(){Oi();for(let e of[...hn,...Si])if(e.category==mn.foreground&&Bi(e.polygon,"black",!1),e?.detailObject?.length)for(let t of e.detailObject)for(let e of t.lines)Qi(e.map((e=>new Ut(...e))),"black",!1,.5);return!1}function _i(){return Oi(),Wi&&Wi.getAllLines().forEach((e=>{Qi(e.line.map((e=>(new ie).fromArray(e))),"black",e.meta.isClosed)})),!1}function qi(){return Oi(),Gi&&Gi.internalFaces().forEach(((e,t)=>{Bi(e.vertexlist,`rgba(${J.num(0,255)},${J.num(0,255)},${J.num(0,255)},0.9)`)})),!1}let $i=!1;function ea(e){let{verts:t,parentSvg:n,strokeColor:l="black",strokeWidth:i=1,className:a="path",isClosed:s=!1}=e,o=`M ${t[0].x} ${t[0].y}`;for(let e=1;e<t.length;e++)o+=` L ${t[e].x} ${t[e].y}`;s&&(o+=" Z");const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d",o),r.setAttribute("fill","none"),r.setAttribute("stroke",l),r.setAttribute("stroke-width",i.toString()),r.setAttribute("class",a),n.appendChild(r),r}let ta=()=>{let e=document.querySelector("svg");e?($i=!1,e.remove(),R()):(k(),e=(()=>{let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("width",O+"px"),e.setAttribute("height",B+"px"),e.setAttribute("style","position: relative; background-color: white;"),e.setAttribute("viewBox",`0 0 ${Y} ${P}`),e.setAttribute("preserveAspectRatio","xMinYMin meet"),e.setAttribute("xmlns","http://www.w3.org/2000/svg");let t=[[new Ut(0,5),new Ut(0,0),new Ut(5,0)],[new Ut(0,P-5),new Ut(0,P),new Ut(5,P)],[new Ut(Y-5,0),new Ut(Y,0),new Ut(Y,5)],[new Ut(Y-5,P),new Ut(Y,P),new Ut(Y,P-5)]];for(let n=0;n<t.length;n++)ea({verts:t[n],parentSvg:e,strokeWidth:2,className:"marker",isClosed:!1,strokeColor:"rgb(1, 0, 0)"});for(let t of[...Si,...hn])if(t.category==mn.foreground){if(ea({verts:t.polygon,parentSvg:e,strokeWidth:2,className:"outline",isClosed:!0,strokeColor:t?.detailObjectProps?.inDominantShapes?.length>0?"rgb(0, 0, 0)":"rgb(1, 1, 1)"}),!t?.detailObject?.length)continue;for(let n of t?.detailObject)if("detail"===n.type)for(let t of n?.lines)ea({verts:t.map((e=>new Ut(...e))),parentSvg:e,strokeWidth:1,className:"detail",strokeColor:"rgb(5, 5, 5)"})}else if(t.category==mn.walker){if(!t?.detailObject?.length)continue;for(let n of t.detailObject)for(let t of n.lines)ea({verts:t.map((e=>new Ut(...e))),parentSvg:e,strokeWidth:4,className:"topline",isClosed:!1,strokeColor:"rgb(10, 10, 10)"})}else if(t.category==mn.overlay){let n=2;for(let l=0;l<n;l++)ea({verts:t.polygon,parentSvg:e,strokeWidth:2,className:"oerlay",isClosed:!0,strokeColor:"rgb(15, 15, 15)"})}return e})(),document.body.appendChild(e),$i=!0)},na=!1;const la=()=>{Fi()[Hi]()?(H(),R()):(k(),M.style.display="block"),Ii=!Ii,Hi=(Hi+1)%Fi().length},ia=()=>{na=!na};var aa;document.complete=!1,(()=>{let n=new URL(window.location.href),l=n.searchParams.get("noFrame");const{innerWidth:i,innerHeight:a}=window;if(l&&(E=0,globalThis.document.body.classList.add("noFrame")),n.searchParams.get("unlockAspect")){let e=N/(i/a);N=i/a,e>1&&(I=a/i*(I-400)),E=0,globalThis.document.body.classList.add("noFrame")}S=document.createElement("canvas"),S.style.backgroundColor="#000",w=S.getContext("webgl2",{colorSpace:"display-p3",preserveDrawingBuffer:!0,stencil:!1,alpha:!1,premultipliedAlpha:!1}),X=new e.WebGLRenderer({canvas:S,context:w,preserveDrawingBuffer:!0,precision:"highp",alpha:!1,premultipliedAlpha:!1,antialias:!1,stencil:!1,depth:!0,powerPreference:"high-performance"}),K=!!w.getExtension("OES_texture_float_linear"),w.getParameter(w.MAX_UNIFORM_BLOCK_SIZE),X.setClearColor(new e.Color(1,1,1),1),C=X.capabilities.maxTextureSize,V=X.capabilities.getMaxAnisotropy(),X.shadowMap.enabled=!0,X.outputColorSpace=e.DisplayP3ColorSpace,X.shadowMap.type=e.PCFSoftShadowMap,document.body.appendChild(S),M=document.createElement("canvas"),M.style.backgroundColor="#000",z=M.style,F=M.getContext("2d",{alpha:!1,colorSpace:"display-p3"}),document.body.appendChild(M),H(),Y=t(I*N),P=t(I);let s=E/100*o(i,a);i<a*N?(B=t(1/N*(i-s)),O=t(i-s)):(B=t(a-s),O=t((a-s)*N)),X.setSize(O,B),X.setPixelRatio(U),Q=O*U,j=B*U,((e,t)=>{M.width=e,M.height=t,z.width=O+"px",z.height=B+"px"})(Q,j),D=Q/Y})(),aa=$(),J=new _(aa||""),(()=>{let t=document.createElement("a");addEventListener("keydown",(n=>{if("s"===n.key&&$i){let e=document.querySelector("svg");if(!e)return;let n=A+".svg";t.setAttribute("download",n);const l=new Blob([e.outerHTML],{type:"image/svg+xml"});t.href=URL.createObjectURL(l),t.click()}else if("s"===n.key){let e=A+".png";se.countX>1&&(e=`${A}-${se.index.x}-${se.index.y}.png`),t.setAttribute("download",e),S.toBlob((e=>{t.href=URL.createObjectURL(e),t.click()}))}"Space"===n.code&&ia(),"x"===n.key&&function(){v({showUpdate:!0,message:"Sending Data Buffer",value:A});let t=new e.WebGLRenderTarget(Q,j,{anisotropy:V,colorSpace:e.DisplayP3ColorSpace,minFilter:e.LinearFilter,magFilter:e.LinearFilter,format:e.RGBAFormat,type:e.FloatType,internalFormat:"RGBA32F"});Yt(Ft.getReadBuffer().texture,t);const n=new Float32Array(Q*j*4);X.readRenderTargetPixels(t,0,0,Q,j,n);let l=""+A;se.countX>1&&(l=`${A}-tiled-${se.index.x}-${se.index.y}`),void 0!==window?.electronAPI?.sendPixelData?window.electronAPI.sendPixelData({buffer:Buffer.from(n.buffer),width:Q,height:j,filename:l}):window.framebuffer=n,setTimeout((()=>{L()}),1e3)}(),"v"===n.key&&(Ii&&la(),ta()),"d"===n.key&&($i&&ta(),la())}))})(),document.metaData=(()=>{ke=[J.num(-1,1),J.num(-1,1)];for(let e=0;e<1e3;e++)He.push(J.dec());Re=J.choice(ue),rt=Re.bg[0][0]<.5,J.weightedChoice([20,Gt],[rt?0:1,Wt])();let e={"Genome base":yt||ot,Palette:Re.name,Mutated:"none"!==et.mutation};const t=[{name:"Name",value:ot},{name:"Meta",value:e},{name:"Divisions",value:it},{name:"Division Props",value:nt},{name:"Line Removal",value:at},{name:"Division Chances",value:Object.fromEntries(Object.entries(Ee).map((([e,t])=>[Se[Number(e)],t])))},{name:"lighting",value:Ie},{name:"color props",value:et},{name:"topLines",value:Ne},{name:"dominantLines",value:Oe},{name:"fillStyles",value:je},{name:"detailStyles",value:Qe},{name:"constructionLineProps",value:Ae},{name:"sceneObjects",value:Ue},{name:"colorProps",value:et},{name:"curveProps",value:qe},{name:"fillMargin",value:tt},{name:"grid",value:Be}];for(let e of t);return e})(),S.addEventListener("click",(e=>{let t=e.clientX,n=e.clientY,l=S.getBoundingClientRect();t-=l.left,n-=l.top;let i=new Ut(t*U/D,n*U/D);for(let e of[...hn,...Si])e.category==mn.foreground&&In(e.polygon,i)})),ci();
ion:i,maxPointUse:a,layers:s,maxLinePoints:o,pointsToConsider:r,insetMult:c}=qe,d=Wi.getAllLines().filter((e=>e.meta.lineCategory==Se.objects&&e.meta.isClosed&&J.bool(50))).map((e=>Dn(e.line.map((e=>new Ut(...e))))));for(let u=0;u<s;u++){let s=function(t,l){return yn(t,l,0,400,e,e*n)},u=Ae.margin+e*c,h=Ae.margin+e*c,m=new pi({maxDist:e*n,bounds:{topLeft:Bt(new Ut(u,h)).toArray(),bottomRight:Bt(new Ut(Y-u,P-h)).toArray()},noiseField:s,seedPoints:d}),p=m.generate();for(let e of p)yield;let b,g=m.kTree,f=[],x=new Set,Z=new Map,y=e=>{x.add(b);let t=Z.get(e)||0;Z.set(e,t+1),Z.get(e)>=a&&g.remove(e)};for(;!(g.count<=0);){if(!b){let e={point:new Ut(J.num(0,Y),J.num(0,P)),minDist:1/0};b=g.findNearest(e),y(b)}let e=J.choice(g.findKNearest(b,r).filter((e=>!x.has(e)&&e.point.distanceTo(b.point)<b.minDist*l)));!e||x.size>=o||g.count<=0?(f.push([...x].map((e=>e.point))),x=new Set,b=null):(b=e,y(b))}let G=[];for(let e of f){if(e.length<3)continue;let t=Zi(xi(e,{tension:J.num(i.min,i.max),cyclic:!1}),6,!1).map((e=>new Ut(e.x,e.y)));G.push(t)}for(let n of G){if(n.length<3)continue;let l=hi(n.map((e=>e.toArray())),J.int(e*(1-t),e*(1+t)),120);Xi.push({line:l,id:Jn(),meta:{lineCategory:Se.curves,isClosed:!0}}),Wi.addLine(l,{lineCategory:Se.curves,isClosed:!0})}}}],[function*(){for(let e=0;e<Ue.layers;e++){let{maxDist:t,minDist:n,bnFreq:l,minSizeMult:i,maxSizeMult:a,fieldFreq:s,maxSides:o,minSides:r,clampRotationTo:c,layerScaleMult:d,perspective:u}=Ue,h=0==e?1:e*d,m=Ue.cropTo==Ce.border?Li:Ue.cropTo==Ce.scene?[[0,0],[Y,P]]:null,p=null;null!==m&&(p=new dn,p.expandsByPoint(m));let b=function(e,i){return yn(e,i,0,l,n*h,t*h)},g=new pi({maxDist:t*h,bounds:{topLeft:Li[0],bottomRight:Li[2]},noiseField:b}).generate(),f=J.num(150,300)*J.choice([-1,1]),x=40;for(let t of g){let n=Ue.forceYUp?0:yn(t.point.x,t.point.y,1e3,s,-40,x),l=yn(t.point.x+1e3,t.point.y+1e3,2e3,s,-(x+f),x+f),d=Ue.forceYUp?0:yn(t.point.x-1e3,t.point.y-1e3,-1e3,s,-40,x),h={w:i,h:i,d:i},m={w:a,h:a,d:a},b=J.weightedChoice([1,"w"],[3,"h"],[0,"d"]),g=J.weightedChoice([1,1],[3,2],[1,3]);h[b]*=g,m[b]*=g;let Z=Mi({sides:J.easedInt(ve,r,o),perspectiveCenter:vi,perspectiveStrength:u,width:J.num(t.minDist*h.w,t.minDist*m.w),height:J.num(t.minDist*h.h,t.minDist*m.h),depth:J.num(t.minDist*h.d,t.minDist*m.d*(0==e?Ue.zDepthMaxMult:1)),center:[t.point.x,t.point.y],rotationProps:{x:xe(n,c),y:xe(l,c),z:xe(d,c)}}),y=J.int(0,1e10),G=Z.faces.reduce(((e,t)=>e+Un(t.vertices.map((e=>new Ut(...e))))),0);Z.faces=Z.faces.filter((e=>null===p||!e.vertices.some((e=>!p.containsPoint(new Ut(...e))))));for(let e of Z.faces)e.vertices=e.vertices.map((t=>{if(!(t[0]>=Li[0][0]&&t[1]>=Li[0][1]&&t[0]<=Li[2][0]&&t[1]<=Li[2][1]))return t;let n=new dn;n.expandsByPoint(e.vertices),n.expandByValue(20);let l=Wi.getLinesIntersectingOrContainedWithinAABB(n).filter((e=>{let t=e.meta.lineCategory;return t==Se.horizontal||t==Se.vertical||t==Se.perspective}));if(!l.length)return t;let i=l.reduce(((e,n)=>Ln(t,e.line)<Ln(t,n.line)?e:n),l[0]);return vn(t,i.line)}));for(let e of Z.faces)Ki.addPolygon(e.vertices,{category:"face",meta:{id:y,lightingIntensity:e.lighting,normal:e.normal,area:Un(e.vertices.map((e=>new Ut(...e)))),totalArea:G}});wi.push(Z),yield{showUpdate:!0,message:"Generating Scene",isPercent:!1,value:""}}}let e=Ki.getAllPolygons();const n=e.map((e=>e.meta.meta.lightingIntensity));let l,i;if(n.length>4){const e=[...n].sort(((e,t)=>e-t)),a=e[t(.25*e.length)],s=e[.75*t(e.length)],o=s-a,r=a-2*o,c=s+2*o,d=n.filter((e=>e>=r&&e<=c)),u=d.length>=2?d:n;l=.9*Math.min(...u),i=Math.max(...u)}else l=.9*Math.min(...n),i=Math.max(...n);e.forEach((e=>{const t=e.meta.meta.lightingIntensity;let n=ye(t,l,i,0,1),a=ye(We(n),-0,1,Ie.min,Ie.max);e.meta.meta.lightingIntensity=a}));for(let t of e){let e={line:t.verts,id:Jn(),meta:{lineCategory:Se.objects,id:t.meta.meta.id,isClosed:!0}};Xi.push(e),Wi.addLine(t.verts,e.meta)}}],[function*(){let e=yi.internalFaces().sort(((e,t)=>t.area-e.area))[0],n=e.area,l=n,i=e,s=new Set,r=_e;for(Ee[Se.objects]>0&&r.push(Se.objects);l/n>.95+g;){let e=Wi.getAllLines().filter((e=>e.meta.lineCategory==Se.vertical||e.meta.lineCategory==Se.horizontal)),t=J.choice(e);yi.splitFaceByPolyLine(i,t.line,t.meta.isClosed,!1),s.add(t),i=yi.internalFaces().sort(((e,t)=>t.area-e.area))[0],l=i.area,yield{showUpdate:!0,message:"Searching for initial structure",isPercent:!0,value:o(.95*n/l*100,100)}}yi.cleanupTrailingEdges();let c=!0,d=new Map;for(let e=0;e<it;e++){if(e%t(it/5)==0&&e>0&&e<t(it-it/5)){let e=new Ql(yi,.75).findDominantPaths(),t=[];for(let n of e)t.push(n);[...t.filter((e=>e.curviness>.02)).sort(((e,t)=>t.length-e.length)).slice(0,2),...t.filter((e=>e.curviness<.02)).sort(((e,t)=>t.length-e.length)).slice(0,2)].forEach((e=>{let t=e.vertices;if(c){for(let e=1;e<t.length-2;e++){let n=[t[e],t[e+1]],l=yi.findHedge(n[0].x,n[0].y,n[1].x,n[1].y);l?.face?.area>0&&yi.removeEdge(n[0].x,n[0].y,n[1].x,n[1].y)}c=!1}else{let e=[t[0],t[1]],n=e[0].distanceTo(e[1]);for(let l=1;l<t.length-2;l++){let i=t[l].distanceTo(t[l+1]);i>n&&(e=[t[l],t[l+1]],n=i);let a=yi.findHedge(e[0].x,e[0].y,e[1].x,e[1].y);a?.face?.area>0&&a.twin.face?.area>0&&yi.removeEdge(e[0].x,e[0].y,e[1].x,e[1].y)}}})),yi.cleanupDegenerateHoles(),yi.cleanupTrailingEdges(),Ri.clear()}yi.cleanupTrailingEdges(),yi.insertPolygon(Li,!0);let l,i=yi.internalFaces();Ri.update(i);let s=Ri.topN(1e3).filter((e=>!Ti.has(e.id))),o=[];for(let e of s){let t=new kn([],[]);t.insertPolygon(e.vertexlist.map((e=>e.toArray())),!0);let i=t.faces[0],a=new Set,s=()=>{const n=[];for(let l=0;l<o.length;l++){const s=o[l];if(a.has(s.constructionLine.id))continue;const r=s.constructionLine.meta.lineCategory,c=s.constructionLine.meta.lineSubCategory;if(Pi(r,e.aabb.center,Ee[r],c)<=0)continue;const d=s.constructionLine.line;let u=s?.constructionLine?.meta?.aabb;if(u||(u=new dn,u.expandsByPoint(d),s.constructionLine.meta.aabb=u),!e.aabb.intersects(u))continue;const h=s?.constructionLine?.meta?.isClosed,m=t.splitFaceByPolyLine(i,d,h,!0);m?.lines?.length>0&&m?.intersectionCount>=2&&n.push(s)}o=n},r=e,c=n/10;if(e.area>c){let t=100,n=new dn;for(n.expand(e.center);!o.length&&n.area<c&&n.area<e.area;){n.expandByValue(t),o=Wi.linesIntersectingAABB(n),t+=50,s();for(let e of o)a.add(e.constructionLine.id)}}if(o.length||(o=Wi.getLinesIntersectingFace(r,!1),s()),o.length>0){l={face:e,intersecting:o},t.dispose();break}}if(!l)break;let{face:r,intersecting:h}=l,m=new Map;Object.values(Se).forEach((e=>{"string"!=typeof e&&0!=Ee[e]&&m.set(e,h.filter((t=>{let n=t.constructionLine.meta;return n.lineCategory===e&&!(n.unableToSplitFaces&&n.unableToSplitFaces.has(r.id))})))}));let p=[];if(m.forEach(((e,t)=>{if(!e.length)return;let n=Pi(t,r.aabb.center,Ee[t]);if(n>0)if(e.some((e=>e.constructionLine.meta?.lineSubCategory))){let n=new Map;e.map((e=>{let t=e.constructionLine.meta.lineSubCategory;n.has(t)?n.get(t).push(e):n.set(t,[e])}));for(let[e,l]of n){let n=Pi(t,r.aabb.center,Ee[t],e);p.push([n,l.reduce(((e,t)=>{let n=Ln(r.aabb.center.toArray(),t.constructionLine.line);return n<e.distance-g?{distance:n,line:t}:e}),{distance:1/0,line:null}).line])}}else p.push([n,e.reduce(((e,t)=>{let n=Ln(r.aabb.center.toArray(),t.constructionLine.line);return n<e.distance-g?{distance:n,line:t}:e}),{distance:1/0,line:null}).line])})),st>0){let e=h.filter((e=>e.constructionLine?.meta?.used&&!e.constructionLine?.meta?.unableToSplitFaces?.has(r.id)&&e.constructionLine.meta.lineCategory==Se.objects)).reduce(((e,t)=>{let n=Ln(r.aabb.center.toArray(),t.constructionLine.line);return n<e.distance?{distance:n,line:t}:e}),{distance:1/0,line:null}).line;e&&p.push([Pi(Se.used,r.aabb.center,st),e])}if(p=p.filter((e=>e[1])),0==p.length){Ti.add(r.id);continue}let b=J.weightedChoice(...p),f=yi.splitFaceByPolyLine(r,b.constructionLine.line,b.constructionLine.meta.isClosed,!1,J.bool(nt.longestSplitOnlyChance));if(f&&(b.constructionLine.meta.used=!0),!f&&(d.set(r.id,(d.get(r.id)||0)+1),e--,!b.constructionLine.meta.unableToSplitFaces&&(b.constructionLine.meta.unableToSplitFaces=new Set),b.constructionLine.meta.unableToSplitFaces.add(r.id),d.get(r.id)>5)){let e=yi.faces.find((e=>e.id==r.id));for(let t of e.hedges.filter((t=>t.face==e)))yi.removeEdge(t.origin.x,t.origin.y,t.twin.origin.x,t.twin.origin.y);yi.cleanupTrailingEdges()}yield{showUpdate:!0,message:"Composing",isPercent:!0,value:t(100*(u=e/it,1-a(1-u,3)))}}var u}],[function*(){wi.sort(((e,t)=>e.faces.reduce(((e,t)=>e+Un(t.vertices.map((e=>new Ut(...e))))),0)-t.faces.reduce(((e,t)=>e+Un(t.vertices.map((e=>new Ut(...e))))),0))),wi=ll(wi.slice(t(wi.length/4),n(wi.length/4*2)));for(let e=0;e<wi.length;e++){if(J.bool(100-De.forceInsertObjectsChance))continue;let t=wi[e];for(let e of t.faces)J.bool(50)||(yi.insertPolygon(e.vertices,!0),J.bool(50)&&yi.removeEdgesInsidePolygon(e.vertices))}let e=Xi.filter((e=>e.meta.lineCategory==Se.curves)).sort(((e,t)=>{let n=Un(e.line.map((e=>new Ut(...e))));return Un(t.line.map((e=>new Ut(...e))))-n}));for(let n=0;n<e.length;n++){if(J.bool(100-De.forceInsertCurvesChance))continue;let l=e[n];n<t(e.length/10)&&(yi.insertPolygon(l.line,!0),yi.removeEdgesInsidePolygon(l.line,10))}}],[function*(){let e=yi.internalFaces().filter((e=>e.area>1)),n=e.length*at;for(let l=0;l<n&&!(e.length<10);l++){let i=J.choice(e.sort(((e,t)=>{const n=e.area-t.area;return Math.abs(n)<g?e.id-t.id:n})).slice(0,100));if(!i)continue;let a=i.hedges.filter((e=>e.twin&&e.face!==e.twin.face&&e.twin.face.area>0&&e.face.area>0)),s=J.choice(a);s&&yi.removeEdge(s.origin.x,s.origin.y,s.twin.origin.x,s.twin.origin.y),yi.cleanupTrailingEdges(),e=yi.internalFaces().filter((e=>e.area>1)),yield{showUpdate:!0,message:"Deconstructing",isPercent:!0,value:t(l/n*100)}}}],[function*(){yi.insertPolygon(Li,!0)}],[function*(){let e=new Ql(yi,.4).findDominantPaths();for(let t of e)Ci.push(t),yield{showUpdate:!0,message:"Walking Paths",isPercent:!1,value:Ci.length}}],[function*(){Gi=new kn(Li,[[0,1],[1,2],[2,3],[3,0]]);let e=Oe.meshDensity,t=Gi.internalFaces()[0].area;Gi.dispose();let n=P/15,l=[J.num(Y/2,Y/2),J.num(P/2-n,P/2+n)],i=Ci.sort(((e,t)=>Ln(l,e.vertices.map((e=>e.toArray())))-Ln(l,t.vertices.map((e=>e.toArray()))))).slice(0,Ci.length),a=[],s=0;for(;s<e&&i.length>0;){let n=i.shift();Gi.insertPolygon(n.vertices.map((e=>[e.x,e.y])),!1),a.push(n),s=Gi.internalFaces().reduce(((e,t)=>e+t.area),0)/t*100,yield{showUpdate:!0,message:"Defining subject",isPercent:!0,value:s/e*100}}Gi.cleanupTrailingEdges();let o=Gi.vertices.filter((e=>e.y<.75*P&&Mn(e.toArray(),Li)));for(let e of o)for(let t of e.hedgelist){let e=[t.origin.x,t.origin.y],n=[t.twin.origin.x,t.twin.origin.y];if(Mn(e,Li)&&Mn(n,Li)){if(t.origin.distanceTo(t.twin.origin)<10)continue;Gi.removeEdge(e[0],e[1],n[0],n[1])}}Gi.cleanupTrailingEdges(),Vi.push(...a.sort(((e,t)=>t.length-e.length)))}],[function*(){let e=Ci.filter((e=>{let t=(tt.cropToMargin?tt.margin:Ae.margin)*Oe.dominantLineInsetMultiplier;return!e.vertices.some((e=>e.x<=t||e.x>=Y-t||e.y<=t||e.y>=P-t))}));"none"!==Oe.lineFilter&&(e=e.filter((e=>{let t=e.curviness>.01;return"curves"==Oe.lineFilter?t:!t})));let n=[];for(let l of e){let e=t(l.vertices.length/2),i=!1;for(let t of n){let n=0;for(let a of l.vertices){for(let l of t.vertices)if(a.isEqualTo(l)&&(n++,n>=e)){i=!0;break}if(i)break}if(i)break}i||n.push(l)}e=n,Oe.cropToDominantShape&&(e=e.filter((e=>Gi.getFacesAtPoint(e.vertices[0].toArray()).length>0&&Gi.getFacesAtPoint(e.vertices[e.vertices.length-1].toArray()).length>0)));let a=t(e.length/100*Oe.skipLongest),s=e.sort(((e,t)=>t.length-e.length)).slice(a,e.length/100*Oe.percentage+a),o=Re.bg[0][0]>.5?Re.line[0]:[...Re.line,...Re.base,...Re.accent].filter((e=>e[1]<.05)).reduce(((e,t)=>t[0]>e[0]?t:e),Re.line[0]),r=[...Re.line,...Re.base,...Re.accent].filter((e=>e[1]<.05)).reduce(((e,t)=>t[0]>e[0]?t:e),Re.line[0]);for(let e of s){if(J.bool(50)){let t=e.vertices.reduce(((t,n,l)=>0===l?0:t+n.distanceTo(e.vertices[l-1])),0)/J.num(10,15),n=e.vertices[1].angleTo(e.vertices[0]),a=new Ut(e.vertices[0].x+i(n)*t,e.vertices[0].y+l(n)*t),s=e.vertices[e.vertices.length-2].angleTo(e.vertices[e.vertices.length-1]),o=new Ut(e.vertices[e.vertices.length-1].x+i(s)*t,e.vertices[e.vertices.length-1].y+l(s)*t);e.vertices=[a,...e.vertices,o]}let t=new dn;t.expands(e.vertices),t.expandByValue(Oe.thickness.max+3);let n={polygon:t.vertexList,faceRef:null,category:mn.walker,readyForRender:!0,detailObject:[{lines:[e.vertices.map((e=>e.toArray()))],noiseOffset:[J.num(-1,1),J.num(-1,1)],closedPolyOrLine:!1,materialHardness:J.num(Oe.materialHardness.min,Oe.materialHardness.max),linePressure:J.num(Oe.linePressure.min,Oe.linePressure.max),canWarp:!0,lineTapering:Il(Oe.lineTapering,J),lineWeight:J.num(Oe.thickness.min,Oe.thickness.max),lineColor:Oe.backgroundColor?r:Oe.colors?J.choice([...Re.accent,...Re.base,...Re.line]):o}]};Si.push(n)}}],[function*(){let e=Ne.count;for(let t=0;t<e;t++){let e=new Ql(yi),t=Bl(yi);if(!t)break;e.walk(t,J.int(Ne.length.min,Ne.length.max),!0),e.AABB.expandByValue(10);let n=Ne.isLineColor?Re.line[0]:Ne.colors?J.weightedChoice([1,J.choice(Re.accent)],[0,J.choice(Re.line)],[1,J.choice(Re.base)]):J.choice(Re.bg),{fade:l,scale:i}=Ne.lineTapering,a={polygon:e.AABB.vertexList,faceRef:null,category:mn.walker,readyForRender:!0,detailObject:[{lines:[e.pathVerts.map((e=>e.toArray()))],closedPolyOrLine:!1,noiseOffset:[J.num(-1,1),J.num(-1,1)],lineTapering:{fade:{in:{enabled:J.bool(l.in.enabledChance),length:J.num(l.in.min,l.in.max)},out:{enabled:J.bool(l.out.enabledChance),length:J.num(l.out.min,l.out.max)}},scale:{in:{enabled:J.bool(i.in.enabledChance),length:J.num(i.in.min,i.in.max)},out:{enabled:J.bool(i.out.enabledChance),length:J.num(i.out.min,i.out.max)}}},linePressure:J.num(Ne.hardness.min,Ne.hardness.max),canWarp:J.bool(Ne.warpChance),lineWeight:J.num(Ne.thickness.min,Ne.thickness.max),lineColor:n}]};Si.push(a)}}],[function*(){let e=yi.internalFaces().filter((e=>e.area>1));const n=e.map((e=>e.area));if(n.length>4){const l=[...n].sort(((e,t)=>e-t)),i=l[t(.25*l.length)],a=l[t(.75*l.length)],s=a+10*(a-i);e.length,e=e.filter((e=>e.area<=s)),e.length}let l=new dn;l.expandsByPoint(Li),e=e.filter((e=>l.containsPoint(e.center))),tt.cropToMargin&&(e=e.filter((e=>e.center.x>tt.margin&&e.center.x<Y-tt.margin&&e.center.y>tt.margin&&e.center.y<P-tt.margin)));let i=Wi.getAllLines().filter((e=>e.meta.lineCategory==Se.curves&&e.meta.used)),a=e=>{let n=e.aabb;for(let l of i){let i=l.line.map((e=>new Ut(...e)));if(l.meta?.aabb||(l.meta.aabb=new dn,l.meta.aabb.expands(i)),l.meta.aabb.intersects(n)){let n=t(.9*e.vertexlist.length),a=0;for(let t=0;t<e.vertexlist.length;t++){if(a>=n)return l;let s=e.vertexlist[t],o=!1;for(let e of i)if(s.isEqualTo(e)){a++,o=!0;break}!o&&In(i,s)&&a++}}}},s=e=>Ki.getPolygonsAtPoint(e.center.toArray()).sort(((e,t)=>e.meta.meta.totalArea-t.meta.meta.totalArea)),o=e=>{const t=Gi.getFacesIntersectingPoly(e.vertexlist.map((e=>[e.x,e.y])));return e.vertexlist.every((e=>t.some((t=>Mn(e.toArray(),t.face.vertexlist.map((e=>e.toArray())))||In(t.face.vertexlist,e)))))?t:[]};for(let n=0;n<e.length;n++){let l=e[n],i=n,r=s(l),c=a(l),d=o(l),u=r.length?r[0].meta.meta.lightingIntensity:Ie.default,h={polygon:l.vertexlist,faceRef:l,lightingIntensity:u,category:mn.foreground,isInCurve:c,detailObjectProps:{inObject:r,inDominantShapes:d}};Si.push(h),yield{showUpdate:!0,message:"Determining Layout",isPercent:!0,value:t(i/e.length*100)}}const r=[...Si.filter((e=>e.category==mn.foreground&&e.lightingIntensity)).map((e=>e.lightingIntensity))].sort(((e,t)=>e-t));for(let e of Si){const t=(c=e.lightingIntensity,(r.indexOf(c)+r.lastIndexOf(c))/2/(r.length-1));e.lightingIntensity=ge(fe(Le(t),0,1,Ie.min,Ie.max),e.lightingIntensity,.9)}var c}],[function*(){let{freqMultiplier:e}=et,t=e,n=500*e;Wi.getAllLines().filter((e=>e.meta.lineCategory==Se.objects&&e.meta.used)).forEach((e=>{vl.add(e.meta.id)}));let l=Si.filter((e=>e.category==mn.foreground)),{base:i,accent:a,line:s,bg:o}=Re,r=ll([...i,...a,s[0],...o]),c=J.int(0,r.length-1);ol=function(e,t,n="right"){let l=e.slice();for(let e=0;e<t;e++)l=il(l,n);return l}(r,c),ol.length>et.maxAccents&&(ol=ol.slice(0,et.maxAccents));let d=et.mutation;if("none"!==d){let e=e=>{let t,n=hl;switch(d){case"offsetUp":t=n;break;case"offsetDown":t=-30}return J.choice(xl(e,cl,t,et.samplesForPaletteOffset))},t=[];for(let n=1;n<ol.length;n++){let l=ol[n],i=ol[n-1],a=J.bool(50);if(i&&a){let n=e(i);t.push(n)}else t.push(l)}ol=t}yl=sl(t,ol.length,0,ml,l.filter((e=>e.detailObjectProps?.inDominantShapes?.length>0)).map((e=>e.faceRef.center))),Gl=sl(n,rl.length,0,ml,l.filter((e=>!e.detailObjectProps?.inDominantShapes?.length)).map((e=>e.faceRef.center))),rl=fl(Gl,rl),ol=fl(yl,ol)}],[function*(){let e=Si.filter((e=>e.category==mn.foreground&&e.detailObjectProps?.inDominantShapes?.length>0)),t=new Ut(Y/2,P/2),n=e.map((e=>e.faceRef.hedges.reduce(((e,n)=>e.origin?n.origin?t.distanceTo(e.origin)<t.distanceTo(n.origin)?e:n:e:n),e.faceRef.hedges[0])));for(let e=0;e<lt.count;e++){let e=xe(J.num(Be.scale*lt.size.min,Be.scale*lt.size.max),Be.scale),t=n.map((e=>{let t=e.origin.lerp(e.twin.origin,.5);return{distance:Ln(t.toArray(),Li,!0),edge:e,point:t}})).filter((t=>t.distance>1.25*e)),l=2.5*e;t.sort(((e,t)=>Math.abs(e.distance-l)-Math.abs(t.distance-l)));let i=t[0];n.splice(n.indexOf(i.edge),1);let a=i.point,s=J.num(0,360),o=_n({center:a.toArray(),radius:e,startAngle:s,endAngle:s+359.5}),r=new Al([o],{x:J.num(-15,15),y:J.num(-15,15),z:J.num(-15,15)},1200,0,{x:vi[0],y:vi[1]}).getLineSegments(),c={polygon:r[0].map((e=>new Ut(...e))),faceRef:null,category:mn.overlay,readyForRender:!1,detailObjectProps:{}};if(Si.push(c),lt.outline){let e=r[0],t=new dn;t.expandsByPoint(e),t.expandByValue(2*Oe.thickness.max);let n={polygon:t.vertexList,faceRef:null,category:mn.overlayOutline,readyForRender:!0,detailObject:[{lines:[e],noiseOffset:[J.num(-1,1),J.num(-1,1)],closedPolyOrLine:!1,materialHardness:J.num(Oe.materialHardness.min,Oe.materialHardness.max),linePressure:J.num(Oe.linePressure.min,Oe.linePressure.max),canWarp:!1,lineTapering:Il(Oe.lineTapering,J),lineWeight:J.num(Oe.thickness.min,Oe.thickness.max),lineColor:Oe.backgroundColor?Re.bg[0]:Oe.colors?J.choice([...Re.accent,...Re.base,...Re.line]):Re.line[0]}]};Si.push(n)}}}],[function*(){let{enabled:e,linePressure:t,materialHardness:n,lineWeight:l,percentage:i,lineTapering:a}=Je;if(!e)return;let s=Xi.filter((e=>e.meta.used)).filter((()=>J.bool(i))),o=new dn;o.expands([new Ut(0,0),new Ut(Y,P)]);let r={polygon:o.vertexList,faceRef:null,category:mn.constructionLine,readyForRender:!0,detailObject:[{lines:s.map((e=>e.line)),closedPolyOrLine:!1,noiseOffset:[J.num(-1,1),J.num(-1,1)],linePressure:J.num(t.min,t.max),materialHardness:J.num(n.min,n.max),canWarp:!1,lineTapering:Il(a,J),lineWeight:J.num(l.min,l.max),lineColor:Re.line[0]}]};Si.push(r)}],[function*(){const e={[mn.constructionLine]:0,[mn.background]:1,[mn.foreground]:2,[mn.detail]:3,[mn.walker]:3,[mn.overlay]:4,[mn.overlayOutline]:5};Si.sort(((t,n)=>{if(e[t.category]<e[n.category])return-1;if(e[t.category]>e[n.category])return 1;let l=new dn;l.expands(t.polygon);let i=new dn;return i.expands(n.polygon),new Ut(l.maxX,l.maxY).distanceTo(new Ut(0,0))-new Ut(i.maxX,i.maxY).distanceTo(new Ut(0,0))}))}],[function*(){let e=new Map,n=0,l="◴ ◷ ◶ ◵".split(" "),i=function*(){let e=oe(!0),t=new dn;for(t.expands([new Ut(e.xOff,e.yOff),new Ut(e.xOff+e.width,e.yOff+e.height)]),t.expandByValue(10);Si.length;){let e=Si[0];if(e.readyForRender){if(e.detailObject?.length){let n=new dn;if(n.expands(e.polygon),t.intersects(n)){bn(e);for(let t=0;t<e.detailObject.length;t++)rn(e.detailObject[t]);w.flush(),Ft.copyBufferToScreen(),yield{rendering:!0}}}let n=Si.splice(0,1);hn.push(...n)}else yield{rendering:!1}}Ft.copyBufferToScreen()}(),a=!1,s=[];for(let e=0;e<1e3;e++)s.push(q());let o=0;for(;!a;){if(na){yield{showUpdate:!0,message:"Rendering Paused",value:"press space to continue",isPercent:!1};continue}for(let t=0;t<Si.length;t++){let l=Si[t];if((l.category==mn.foreground||l.category==mn.detail||l.category==mn.overlay)&&!l.detailsProcessed){l.detailsProcessed=!0,e.set(n,!1);let t=n;Nl(l,s[o++%s.length]).then((()=>{e.set(t,!0)})),n++}}let r=i.next();a=r.done;let c=r.value?.rendering||!1,d=0;for(let e of Object.keys(Rl))0==Rl[e]&&(d+=1);let u=[...e.values()].reduce(((e,t)=>e+(t?0:1)),0);if(yield{showUpdate:!c&&(u>0||d>0||u>0),message:""+l[t(oi/4)%4],isPercent:!1,value:`${d>0?`Waiting on 1 of ${d} threads, `:"Waiting for"} ${u} jobs queued`},0==u&&0==kl.length&&0==d&&a)break}yield{showUpdate:!1},Ft.copyBufferToScreen()},!0]],Ri=new class{heap;constructor(e){this.heap=new jl(1e10,e)}clear(){this.heap.clear()}topN(e){return this.heap.toArray().slice(0,e)}update(e){const t=new Set(this.heap.toArray());for(const n of e)t.has(n)?t.delete(n):this.heap.push(n);for(const e of t)this.heap.remove(e);return this.heap.toArray()}}((e=>{let{polyOverfitting:t,noiseOverfittingSpread:n,noiseOverfitFreq:l}=nt,i=e.area;if(1!==t&&(i*=Ki.getPolygonsAtPoint(e.center.toArray()).length>0?1:t),n>0){let t=n/2,a=sl(l,10,0,Ge);i*=xe(ye(yn(e.center.x,e.center.y,0,l,1-t,1+t),0,1,a.min,a.max),.001)}return xe(i,.001)})),Ti=new Set;function Mi(e){let t={x:e.center[0],y:e.center[1],z:-100},n={width:e.width,height:e.height,depth:e.depth};return{faces:new Jl(t,e.rotationProps,n,e.sides,{x:e.perspectiveCenter[0],y:e.perspectiveCenter[1],z:-1e3},90,Y/P,.001,1e3,[{position:Ie.position,brightness:1},{position:{x:-Ie.position.x,y:-Ie.position.y,z:Ie.position.z},brightness:.95},{position:{x:0,y:Ie.position.y,z:-1e3},brightness:.2},{position:{x:0,y:-Ie.position.y,z:-1e3},brightness:.2}],!0).getFaces2D(),shapeArgs:e}}let zi,Yi=!1,Pi=(e,t,n,l=0)=>{let i=1e3*n,a=1e3*l;if(!Yi){let e=J.num(800,1600),t=nt.noiseFieldCategoryInfluence;zi={[Se.used]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[Se.horizontal]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[Se.vertical]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[Se.perspective]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[Se.circle]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[Se.wobbles]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[Se.curves]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[Se.rects]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[Se.borderRect]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[Se.triangle]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[Se.objects]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)}},Yi=!0}let s=ve,o=sl(zi[e].freq,10,zi[e].offset,s),r=ye(s(xe(yn(t.x+zi[e].offset,t.y+zi[e].offset,zi[e].offset-a,zi[e].freq,0,1),.3)),o.min,o.max,zi[e].min,zi[e].max);return c(i*r)},Fi=()=>[Ai,ji,Ji,qi,_i,Ei,()=>!0],Hi=0,
this.kTree.pointsWithinDistanceGenerator(e,this.maxDist+g))if(t.point.distanceTo(e.point)+this.epsilon<Math.max(t.minDist,e.minDist))return!1;return!0}placePoint(e){this.kTree.insert(e)}}const bi=function(e,t,n){const l=1/t,i=1/n;return Math.min(4,((3-l)*l**2*e+i**3)/(l**3*e+(3-i)*i**2))},gi=(e,t,n,l,i)=>Math.min(4,(2+Math.sqrt(2)*(e-n/16)*(n-e/16)*(t-l))/(1.5*i*(2+(Math.sqrt(5)-1)*t+(3-Math.sqrt(5))*l))),fi=(e,t)=>{const n=Math.sin(e.theta),l=Math.cos(e.theta),i=Math.sin(t.phi),a=Math.cos(t.phi),s=t.leftY,o=e.rightY,r=gi(n,l,i,a,s),c=gi(i,a,n,l,o);e.rightX=e.x+(e.deltaX*l-e.deltaY*n)*r,e.rightY=e.y+(e.deltaY*l+e.deltaX*n)*r,t.leftX=t.x-(e.deltaX*a+e.deltaY*i)*c,t.leftY=t.y-(e.deltaY*a-e.deltaX*i)*c},xi=(e,{tension:t=1,cyclic:n=!1}={})=>{const l=((e,t=1,n=!1)=>{const l=e.map((({x:e,y:n})=>((e,t,n)=>({x:e,y:t,leftY:n,rightY:n,leftX:n,rightX:n,deltaX:0,deltaY:0,delta:0,theta:0,phi:0,psi:0}))(e,n,t))),i=l[0],a=l[l.length-1];for(let e=0;e<l.length;e++)l[e].next=l[e+1]??i,l[e].prev=l[e-1]??a;if(((e,t)=>{const n=t?e.length:e.length-1;for(let t=0;t<n;t++){const n=e[t],l=e[t+1]??e[0];n.deltaX=l.x-n.x,n.deltaY=l.y-n.y,n.delta=Math.hypot(n.deltaX,n.deltaY)}})(l,n),2===e.length&&!n)return((e,t)=>{let n=1/(3*e.rightY);e.rightX=e.x+e.deltaX*n,e.rightY=e.y+e.deltaY*n,n=1/(3*t.leftY),t.leftX=t.x-e.deltaX*n,t.leftY=t.y-e.deltaY*n})(i,a),l;((e,t)=>{const[n,l]=t?[0,e.length]:[1,e.length-1];for(let t=n;t<l;t++){const n=e[t],l=n.prev,i=l.deltaY/l.delta,a=l.deltaX/l.delta;n.psi=Math.atan2(n.deltaY*a-n.deltaX*i,n.deltaX*a+n.deltaY*i)}})(l,n),function(e,t){const n=[],l=[],i=[],a=e[0],s=e[1],o=e[e.length-1],r=t?e.length+1:e.length;if(t)n[0]=0,i[0]=0,l[0]=1;else{const e=a.next,t=a.rightX,o=Math.abs(e.leftY),r=Math.abs(a.rightY);n[0]=bi(t,r,o),i[0]=-s.psi*n[0],l[0]=0}for(let s=1;s<r;s++){const c=e[s]??a,d=c.next,u=c.prev,h=s===r-1;if(!t&&h){const e=c.leftX,t=Math.abs(c.leftY),l=Math.abs(u.rightY),a=bi(e,t,l);o.theta=-i[r-2]*a/(1-a*n[r-2]);break}{let e=1/(3*Math.abs(u.rightY)-1),o=c.delta*(3-1/Math.abs(u.rightY)),m=1/(3*Math.abs(d.leftY)-1),p=u.delta*(3-1/Math.abs(d.leftY));const b=1-n[s-1]*e;o*=b;const g=Math.abs(c.leftY),f=Math.abs(c.rightY);g<f?o*=(g/f)**2:p*=(f/g)**2;let x=p/(p+o);n[s]=x*m;let Z=-d.psi*n[s];if(x=(1-x)/b,Z-=c.psi*x,x*=e,i[s]=Z-i[s-1]*x,l[s]=-l[s-1]*x,t&&h){let e=0,t=1;for(let a=s-1;a>=0;a--){const s=0===a?r-1:a;e=i[s]-e*n[s],t=l[s]-t*n[s]}e/=1-t,a.theta=e,i[0]=e;for(let t=1;t<r-1;t++)i[t]=i[t]+e*l[t];break}}}for(let t=r-2;t>=0;t-=1)e[t].theta=i[t]-e[t].next.theta*n[t]}(l,n),(e=>{for(let t=0;t<e.length;t++){const n=e[t];n.phi=-n.psi-n.theta}})(l);const s=n?l.length:l.length-1;for(let e=0;e<s;e++)fi(l[e],l[e].next);return l})(e,t,n),i=[],a=n?l.length:l.length-1;for(let e=0;e<a;e++){const t=l[e];i.push({startControl:{x:t.rightX,y:t.rightY},endControl:{x:t.next.leftX,y:t.next.leftY},point:{x:t.next.x,y:t.next.y}})}return i};function Zi(e,t,n=!1,l=.01){const i=[],a=e.length;if(a<2)return i;const s=n?a:a-1;let o=null;for(let n=1;n<=s;n++){const s=n%a,r=e[(n-1)%a].point,c=e[s].startControl,d=e[s].endControl,u=e[s].point;let h=0;for(;h<=1;){const e=1-h,n={x:e**3*r.x+3*e**2*h*c.x+3*e*h**2*d.x+h**3*u.x,y:e**3*r.y+3*e**2*h*c.y+3*e*h**2*d.y+h**3*u.y};if(o){const e=n.x-o.x,l=n.y-o.y;e*e+l*l>=t*t&&(i.push(n),o=n)}else i.push(n),o=n;h+=l}const m={x:u.x,y:u.y};!o||o.x===m.x&&o.y===m.y||(i.push(m),o=m)}if(!n){const t=e[a-1].point,n=i[i.length-1];n.x===t.x&&n.y===t.y||i.push(t)}return i}let yi,Gi,Wi,vi,Li,Si=[],Xi=[],Ci=[],Vi=[],Ki=new class{cells=new Map;polygons=new Map;polygonMeta=new Map;nextPolygonId=0;cellSize;constructor(e,t){this.cellSize=e,t&&this.addPolygons(t)}getCellIndex(e,t){return`${f(e)},${f(t)}`}clear(){this.cells.clear(),this.polygons.clear(),this.polygonMeta.clear()}getCellTestVertices(e,t){let{cellSize:n}=this;return[new Ut(e*n,t*n),new Ut((e+1)*n,t*n),new Ut((e+1)*n,(t+1)*n),new Ut(e*n,(t+1)*n)]}addPolygons(e){e.forEach((e=>this.addPolygon(e.verts,e.meta)))}getPolygonsAtPoint(e){let{cellSize:t}=this,n=f(e[0]/t),l=f(e[1]/t);const i=this.getCellIndex(n,l);let a=new Set;return this.cells.has(i)&&Array.from(this.cells.get(i)).map((t=>{In(this.polygons.get(t).map((e=>(new Ut).fromArray(e))),new Ut(e[0],e[1]))&&a.add(t)})),Array.from(a).map((e=>({verts:this.polygons.get(e),meta:this.polygonMeta.get(e)})))}addPolygon(e,t){let{cellSize:n}=this;const l=this.nextPolygonId++;this.polygons.set(l,e),this.polygonMeta.set(l,t);let i=e.map((e=>(new Ut).fromArray(e))),a=new dn;a.expands(i);const s=f(a.minX/n),o=x(a.maxX/n)-1,r=f(a.minY/n),c=x(a.maxY/n)-1;for(let e=s;e<=o;e++)for(let t=r;t<=c;t++){const n=this.getCellIndex(e,t),a=this.getCellTestVertices(e,t);if(a.some((e=>In(i,e))))this.cells.has(n)||this.cells.set(n,new Set),this.cells.get(n).add(l);else for(let e=0;e<a.length;e++)if(Qn([a[e],a[(e+1)%a.length]],i)){this.cells.has(n)||this.cells.set(n,new Set),this.cells.get(n).add(l);break}}return l}checkIntersections(e){let{cellSize:t}=this,n=e.map((e=>(new Ut).fromArray(e))),l=new dn;l.expands(n);const i=f(l.minX/t),a=x(l.maxX/t)-1,s=f(l.minY/t),o=x(l.maxY/t)-1;let r=new Set;for(let e=i;e<=a;e++)for(let t=s;t<=o;t++){const l=this.getCellIndex(e,t),i=this.getCellTestVertices(e,t);this.cells.has(l)&&this.cells.get(l).forEach((e=>{if(i.some((e=>In(n,e))))r.add(e);else for(let t=0;t<i.length;t++)if(Qn([i[t],i[(t+1)%i.length]],n)){r.add(e);break}}))}return Array.from(r).map((e=>({verts:this.polygons.get(e),meta:this.polygonMeta.get(e)})))}getAllPolygons(){return Array.from(this.polygons).map((([e,t])=>({verts:t,meta:this.polygonMeta.get(e)})))}}(10),wi=[],ki=[[function*(){Zn()}],[function*(){ml=et.curveMap;let e=Re.bg[0][0]>=.5,t=e?1:1.0012,n=e?1:1.001;cl=cl.length?cl:he.filter((e=>e!==Re)).map((e=>[...e.accent,...e.base,...e.line])).flat().map((e=>(e[0]*=n,e[1]*=t,e))),[...Re.accent,...Re.base,...Re.line].forEach((e=>{e[0]*=n,e[1]*=t}));let l=[...Re.accent,...Re.base,...Re.line];ol=l,rl=[...Re.base].sort(((e,t)=>t[0]-e[0])),ol=[...ol].sort(((e,t)=>t[2]-e[2])),nl([...ol]),nl([...rl])}],[function*(){let t=K?e.LinearFilter:e.NearestFilter,n={anisotropy:V,colorSpace:e.LinearDisplayP3ColorSpace,minFilter:t,magFilter:t,type:e.FloatType};Ft=new Pt(Q,j,{stencilBuffer:!1,depthBuffer:!1}),Ht={paperTexture:{target:new e.WebGLRenderTarget(Q,j,{...n,format:e.RedFormat,internalFormat:"R32F"}),pass:()=>{let t=new e.ShaderMaterial({uniforms:{resolution:{value:new e.Vector2(Q,j)},noiseOffset:{value:new e.Vector2(ke[0],ke[1])},...ce()},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:le,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform highp sampler2D tTex;\n uniform vec2 resolution;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n uniform vec3 backgroundColor;\n uniform vec3 lineColor;\n uniform vec2 noiseOffset;\n\n ${ee}\n ${te}\n\n varying vec2 vUv;\n out vec4 outColor;\n\n #include <packing>\n\n ${ne}\n\n vec4 render(vec2 uv) {\n\n float noiseTex1 = fbm(uv - noiseOffset, 5, 300., 0.9) - 0.5;\n float noiseTex2 = fbm(uv - noiseOffset, 3, 400., 0.9) - 0.5;\n float texCombined = step(0.001, -(noiseTex1 * noiseTex2)) * .05;\n\n float noiseTexDark1 = fbm(uv + noiseOffset + 1., 5, 280., 0.9) - 0.5;\n float noiseTexDark2 = fbm(uv + noiseOffset + 1., 3, 300., 0.9) - 0.5;\n float texDarkCombined = step(0.0001, -(noiseTexDark1 * noiseTexDark2)) * .05;\n\n float smoothNoise1 = smoothstep(0., 0.6, fbm(uv, 3, 420., 0.9)) * 0.03;\n\n // vec3 lchColor = vec3(0., 0.5, 0.5);\n float result;\n result += texCombined;\n result -= texDarkCombined;\n result += smoothNoise1;\n \n // vec3 colorRGB = OKLCHtoP3LRGB(lchColor);\n // float canvasTexture = fbm(uv, 6, 120., 0.7);\n return vec4(vec3(result), 1.);\n }\n\n \n\n void main() {\n // A pseudo-random distribution for multi-sample\n const vec2 H2 = vec2(0.56984029, 0.75487766);\n // We do sub-pixel offsets relative to tile size, \n // because each tile is scaled to fill the entire local canvas\n vec2 px = 1.0 / resolution.xy;\n px *= 1.25;\n\n // We'll accumulate color across multiple samples\n const float samples = 6.0;\n vec4 sumColour = vec4(0.0);\n \n // Vary the random offset per pixel\n vec2 d0 = vec2(randomNonDet(vUv), randomNonDet(vUv + 1.0));\n\n for (float i = 0.0; i < samples; i++) {\n vec2 d = fract(i * H2 + d0) - 0.5;\n // localCoord in [0..1] in the local canvas\n vec2 sampleCoord = vUv + d * px;\n\n // Now map that to the large “full” coordinate space \n // subregion given by uTileOffset..uTileOffset+uTileSize\n vec2 screenCoord = uTileOffset + sampleCoord * uTileSize;\n\n // Next convert to [0..1] over the entire original geometry\n vec2 globalUV = screenCoord / resolution;\n\n vec4 sampleColor = render(globalUV);\n sumColour += sampleColor;\n }\n\n vec4 finalColor = clamp(sumColour / samples, 0.0, 1.0);\n outColor = finalColor;\n }\n `});re(t),It.material=t,X.setRenderTarget(Ht.paperTexture.target),It.render(X)}},displacementMap:{target:new e.WebGLRenderTarget(Q,j,{...n,format:e.RGFormat,internalFormat:"RG32F"}),pass:()=>{let e=Kt();re(e),It.material=e,X.setRenderTarget(Ht.displacementMap.target),It.render(X)}},displacementMapWarped:{target:new e.WebGLRenderTarget(Q,j,{...n,format:e.RGFormat,internalFormat:"RG32F"}),pass:()=>{let e=Kt();re(e),e.uniforms.uWarpEnabled.value=!0,It.material=e,X.setRenderTarget(Ht.displacementMapWarped.target),It.render(X)}},polyEdgeDistance:{target:new e.WebGLRenderTarget(Q,j,{...n,format:e.RedFormat,internalFormat:"R32F"}),skipSetup:!0}};let l=function*(){for(let e of Object.keys(Ht)){const t=Ht[e];t.skipSetup||t.pass&&t.pass()}return X.shadowMap.enabled=!0,void X.setRenderTarget(null)}();for(;!l.next().done;)yield}],[function*(){let e=Rt();It.material=e;for(let t of Object.keys(Ht)){if(!Ht[t].debug)continue;let n=Ht[t].target.texture;e.uniforms.tTex.value=n,X.setRenderTarget(null),It.render(X),ia(),yield}}],[function*(){let t=(n=Ht.paperTexture.target.texture,new e.ShaderMaterial({uniforms:{grid:{value:{...Be}},...ce(),tWarpTex:{value:Ht.displacementMap.target.texture},resolution:{value:new e.Vector2(Q,j)},coordsResolution:{value:new e.Vector2(Y,P)},noiseOffset:{value:new e.Vector2(0,0)},tPaperTexture:{value:n},backgroundColor:{value:new e.Vector3(0,0,0)},lineColor:{value:new e.Vector3(0,0,0)},uGridStrength:{value:.3}},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:le,fragmentShader:`\n precision highp float;\n\t\t\tprecision highp int;\n \n // uniform highp sampler2D tTex;\n uniform vec2 resolution;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n uniform vec2 coordsResolution;\n uniform vec3 backgroundColor;\n uniform vec3 lineColor;\n uniform vec2 noiseOffset;\n uniform float uGridStrength;\n uniform highp sampler2D tPaperTexture;\n uniform highp sampler2D tWarpTex;\n\n struct Grid {\n float countX;\n float countY;\n float marginX;\n float marginY;\n float w;\n float h;\n float scale;\n };\n uniform Grid grid;\n\n ${ee}\n ${Et}\n ${te}\n \n float drawGridLines(vec2 uv, float lineWeight, float gridScale) {\n vec2 scale = resolution / coordsResolution;\n // This should be the desired line width in pixels\n float lineWeightNoise = snoise2D(uv * 200.f) * .09f;\n float gridLineWeight = (lineWeight + lineWeightNoise) * scale.y; // Width of the grid lines in pixels\n\n vec2 offset = vec2(grid.marginX, grid.marginY) * scale; // Applying scale to margins\n\n // Compute UVs for grid lines based on actual screen resolution and grid scaling\n vec2 gridUV = (uv * resolution - offset);\n\n // Convert grid dimensions from whatever space they are in to pixel space directly\n float gridWidthInPixelsX = grid.w * (resolution.x / coordsResolution.x) * 1.;\n float gridWidthInPixelsY = grid.h * (resolution.y / coordsResolution.y) * 1.;\n\n // Calculate the distance to the nearest grid line in pixels\n float lineDistX = min(mod(gridUV.x, gridWidthInPixelsX / gridScale), gridWidthInPixelsX - mod(gridUV.x, gridWidthInPixelsX / gridScale));\n float lineDistY = min(mod(gridUV.y, gridWidthInPixelsY / gridScale), gridWidthInPixelsY - mod(gridUV.y, gridWidthInPixelsY / gridScale));\n float lineDist = min(lineDistX, lineDistY);\n\n // Use smoothstep to create anti-aliased lines with a specified pixel width\n float lineFactor = 1.0 - smoothstep(gridLineWeight - 0.1, gridLineWeight + 0.1, lineDist);\n\n return lineFactor;\n }\n\n float drawGridBlocks(vec2 uv, float gridScale ) {\n vec2 scale = resolution / coordsResolution;\n vec2 offset = vec2(grid.marginX, grid.marginY) * scale; // Applying scale to margins\n vec2 gridUV = (uv * resolution - offset); // Apply resolution scaling to UV, then subtract offset\n\n float tileX = floor(gridUV.x / (grid.w * scale.x));\n float tileY = floor(gridUV.y / (grid.h * scale.y));\n\n vec2 centerUV = (vec2(tileX, tileY)) * vec2(grid.w, grid.h) / resolution;\n\n float noiseValue = clamp(fbm(centerUV, 3, 300., 0.5) + .5, 0.0, 1.); // Adjust for correct scaling if necessary\n\n return noiseValue;\n\n // float checker = mod(tileX + tileY, 2.0);\n \n // return checker == 0.0;\n }\n\n ${Ct}\n\n varying vec2 vUv;\n out vec4 outColor;\n\n #include <packing>\n\n ${ne}\n ${At}\n\n vec4 render(vec2 uv, vec2 texUv, vec2 msaaOffset) {\n\n // vec2 uvOffset = lookupWarpSample(uv).xy;\n\n // vec2 offsetUV = uv + uvOffset;\n vec2 offsetUV = uv;\n\n float gridNoise = fbm(uv, 3, 10., 0.9);\n float gridNoise2 = fbm(uv + 2., 3, 600., 0.9);\n\n float tileScaleFactor = resolution.x / uTileSize.x;\n\n // float gridFactor = clamp(0., .12, drawGridLines(uv, 38.));\n float aspectRatio = resolution.x / resolution.y;\n vec2 uvNormalised = offsetUV * vec2(aspectRatio, 1.);\n\n const float gridDarkness = 0.3;\n\n float gridDivisor = 1.;\n float edgeFactor = smoothstep(0.2f, 1.f, screenEdgeDist(uvNormalised, 0.22 - (gridNoise * .06)));\n \n float gridFactor = clamp(0., gridDarkness, drawGridLines(offsetUV, .3 , 5.) * edgeFactor);\n float gridFactor2 = clamp(0., gridDarkness + 0.025, drawGridLines(offsetUV, .5 , 1.) * edgeFactor);\n \n vec3 lineCol = lineColor;\n \n lineCol.x += (step(0.6, gridNoise - gridNoise2) * 0.4);\n \n float gridTextureNoise = fbm(uv + noiseOffset, 6, 700., 0.7) * 0.5;\n vec3 lchColor = mix(backgroundColor, lineCol, clamp((gridFactor2 - gridTextureNoise) * uGridStrength, 0., 1.));\n \n float smoothNoise1 = texture(tPaperTexture, texUv + msaaOffset).x * 0.8;\n\n float colourNoise = fbm(uv + noiseOffset, 12, 5., 0.7) * 0.001;\n float colourNoise2 = fbm(uv - noiseOffset + 1., 12, 3., 0.7) * 0.001;\n\n lchColor.x += smoothNoise1 - colourNoise + colourNoise2;\n\n float edgeFactorVignette = smoothstep(0.2f, 1.f, screenEdgeDist(uvNormalised, 0.5));\n lchColor.x -= (1. - edgeFactorVignette) * 0.005;\n lchColor.y += (1. - edgeFactorVignette) * 0.005;\n // lchColor.y *= colourNoise;\n \n\n // lchColor = vec3(lchColor.x, lchColor.y, lchColor.z);\n\n vec3 colorRGB = OKLCHtoP3LRGB(lchColor);\n\n vec3 lightDir = normalize(vec3(.6f, 1.6f, 1.6f));\n vec3 lightColor = vec3(1.0f) * 1.7f;\n\n vec3 paperTextureNormals = calculateNormals(texUv + msaaOffset, 0.0002 * tileScaleFactor, 2.);\n vec3 diffuse = calculateDiffuse(paperTextureNormals, lightDir, lightColor);\n\n colorRGB *= diffuse;\n \n // float canvasTexture = fbm(uv, 6, 120., 0.7);\n return vec4(colorRGB, 1.);\n }\n\n \n\n void main() {\n // A pseudo-random distribution for multi-sample\n const vec2 H2 = vec2(0.56984029, 0.75487766);\n // We do sub-pixel offsets relative to tile size, \n // because each tile is scaled to fill the entire local canvas\n vec2 px = 1.0 / resolution.xy;\n px *= 1.25;\n\n // We'll accumulate color across multiple samples\n const float samples = 16.0;\n vec4 sumColour = vec4(0.0);\n \n // Vary the random offset per pixel\n vec2 d0 = vec2(randomNonDet(vUv), randomNonDet(vUv + 1.0));\n\n for (float i = 0.0; i < samples; i++) {\n vec2 d = fract(i * H2 + d0) - 0.5;\n // localCoord in [0..1] in the local canvas\n vec2 sampleCoord = vUv + d * px;\n\n // Now map that to the large “full” coordinate space \n // subregion given by uTileOffset..uTileOffset+uTileSize\n vec2 screenCoord = uTileOffset + sampleCoord * uTileSize;\n\n // Next convert to [0..1] over the entire original geometry\n vec2 globalUV = screenCoord / resolution;\n\n vec4 sampleColor = render(globalUV, vUv, d * px);\n sumColour += sampleColor;\n }\n\n vec4 finalColor = clamp(sumColour / samples, 0.0, 1.0);\n outColor = finalColor;\n }\n `}));var n;It.material=t,re(t);let l=Qt(J.choice(Re.bg)),i=Qt(J.choice(Re.line));t.uniforms.backgroundColor.value=(new e.Vector3).fromArray(l),t.uniforms.lineColor.value=(new e.Vector3).fromArray(i),t.uniforms.noiseOffset.value=new e.Vector2(ke[0],ke[1]),t.uniforms.uGridStrength.value=.2,X.setRenderTarget(Ft.getWriteBuffer()),It.render(X),Ft.copyAndSwapBuffers(),Ft.copyBufferToScreen()}],[function*(){let e=Ae.margin+Be.marginX,n=Ae.margin+Be.marginY,l=new Ut(e,n),i=new Ut(Y-e,P-n);(function(e,t,n=0){let l=[],i=[],a=J.weightedChoice([0,J.easedNum(Le,Ae.HVariance.min,Ae.HVariance.max)]),s=J.weightedChoice([0,J.easedNum(Le,Ae.VVariance.min,Ae.VVariance.max)]);for(let i=e.y;i<t.y;i+=Be.scale/2)J.gaussianBool(Ae.HVariance.threshold,Ae.HVariance.mean,Ae.HVariance.stdDev)||l.push({id:Jn(),meta:{lineCategory:Se.horizontal},line:[[e.x-Be.scale*n,i+J.num(-Be.scale*a,Be.scale*a)],[t.x+Be.scale*n,i+J.num(-Be.scale*a,Be.scale*a)]]});for(let l=e.x;l<t.x;l+=Be.scale/2)J.gaussianBool(Ae.VVariance.threshold,Ae.VVariance.mean,Ae.VVariance.stdDev)||i.push({id:Jn(),meta:{lineCategory:Se.vertical},line:[[l+J.num(-Be.scale*s,Be.scale*s),e.y-Be.scale*n],[l+J.num(-Be.scale*s,Be.scale*s),t.y+Be.scale*n]]});Xi.push(...l,...i)})(l,i),vi=function(e,t){let n;if(!Ae.perspectiveBox.enabled)return;let l=[e,new Ut(t.x,e.y),t,new Ut(e.x,t.y)].map((e=>e.toArray())),i=new kn(l,[[0,1],[1,2],[2,3],[3,0]]);for(let e=0;e<Ae.perspectiveBox.count;e++){let e,t=i.internalFaces(),n=J.choice(t),l=n.aabb,a=J.bool(50),s=o(l.height,l.width)/4;if(a){let t=J.num(l.minX+s,l.maxX-s);e=[[t,l.minY],[t,l.maxY]]}else{let t=J.num(l.minY+s,l.maxY-s);e=[[l.minX,t],[l.maxX,t]]}i.splitFaceByPolyLine(n,e)}let a=i.internalFaces(),s=!1,r=!1,c=!1,d=Ae.perspectiveBox.firstFull;for(let e of a){if(-1==Ae.perspectiveBox.count)break;let t=e.aabb,l=t.width*J.num(.75,1.25),i=t.height*J.num(.75,1.25),a=!(!d||c)||J.bool(s?0:50),o=!(!d||c)||J.bool(r?0:50);a&&(r=!0),o&&(s=!0);let u=[a?Y/2:t.center.x,o?P/2:t.center.y];c||(n=u),c=!0,Ee[Se.perspective]>1&&Xi.push(...An({gStdDev:Ae.perspectiveBox.threshold,gMean:Ae.perspectiveBox.mean,gThreshold:Ae.perspectiveBox.stdDev,boxCenter:u,perspectiveCenter:[t.center.x+J.int(-l/4,l/4),t.center.y+J.int(-i/4,i/4)],width:a?4*Y:l*J.num(.75,1.25),height:o?P:i*J.num(.75,1.25),centerBoxMaskDimensions:[J.int(1,l/Be.scale*.5),J.int(1,i/Be.scale*.5)]}).map((e=>({id:Jn(),line:e,meta:{lineCategory:Se.perspective}}))))}return n}(l,i),function(){for(let e=0;e<Ae.circles.count;e++){let e=xe(J.num(Be.scale*Ae.circles.minRadius,Be.scale*Ae.circles.maxRadius),Be.scale),t=e/2,n=[Y/2+J.num(-Y/2+t,Y/2-t),P/2+J.num(-P/2+t,P/2-t)],l=J.num(0,360),i=_n({center:n,radius:e,startAngle:l,endAngle:l+J.int(25,360)});i.length>3&&Xi.push({id:Jn(),line:i,meta:{lineCategory:Se.circle}})}}(),function(){if(!Ae.rects.spiralRectsEnabled)return;let e=Ot(new Ut(J.num(.4*Y,.6*Y),J.num(.4*P,.6*P))).toArray(),t=J.num(0,22.5)*J.choice([-1,1]),n=Be.scale*J.int(5,10),l=J.num(0,360),i=Be.scale*(2*J.int(1,8));for(;n<P;){let a=En({width:n,height:n,center:e,angle:l});Xi.push({id:Jn(),line:a,meta:{lineCategory:Se.rects,isClosed:!0}}),n+=i,l+=t}}(),function(){if(!Ae.rects.insetRectEnabled)return;let e=2*Ae.margin+Be.scale*(2*J.int(1,4)),t=Ot(new Ut(J.num(Y/2,Y/2),J.num(P/2,P/2))).toArray(),n=En({width:Y-e,height:P-e,center:t,angle:J.num(-1,1)});Xi.push({id:Jn(),line:n,meta:{lineCategory:Se.borderRect,isClosed:!0}})}();let a=function(){let e=J.num(Ae.wobble.warpFreq.min,Ae.wobble.warpFreq.max),t=[];for(let n=0;n<Ae.wobble.layers;n++){let l=me(180/Ae.wobble.layers*n);for(let n=0;n<Ae.wobble.multiLayers;n++){let i=n*Ae.wobble.offsetMultiplier,a={warpStrength:e,rotationAngleAddition:l,wobbleOffset:i};zl.push(a);let s=new dn;s.expands([new Ut(-Y/4,-P/4),new Ut(Y+Y/4,P+P/4)]);let o=s.vertexList.map((e=>e.toArray())),r=xe(Be.scale/Ae.wobble.gridDivisions,.1),c=Ml({streamlineWorkerProps:{vectorFieldType:"bnnoise",addOutline:!1,vectorFieldNoiseProps:{warpStrength:xe(e,.01),rotationAngleAddition:xe(l+J.num(-.1,.1),.01),wobbleOffset:i,wobbleDetail:J.int(0,1)},postProcessingArgs:{directional:!1,wobbleFreq:.5,wobbleAmplitude:.5},maxStreamlines:Ae.wobble.count,minLength:xe(Be.scale*Ae.wobble.minLength,.1),maxLength:xe(3*P,.1),stepSize:r/4,minDistance:r,bounds:{topLeft:o[0],bottomRight:o[2]},boundingGeometry:o},noiseSeed:xn,randomSeed:q(J)});t.push(c)}}return t}(),s=new Map,r=0,c="◴ ◷ ◶ ◵".split(" "),d=Array(a.length);for(let e=0;e<a.length;e++){let t=a[e];s.set(r,!1);let n=r;t.then((t=>{d[e]=t,s.set(n,!0)})),r++}for(;;){let e=[...s.values()].reduce(((e,t)=>e+(t?0:1)),0);if(yield{showUpdate:e>0,message:""+c[t(oi/4)%4],isPercent:!1,value:`${e>0?"Pausing for":"Waiting for"} ${e} tasks`},0==e)break}for(let e=0;e<d.length;e++){let t=d[e];if(Ee[Se.wobbles]>0)for(let n of t)Xi.push({line:n,id:Jn(),meta:{lineCategory:Se.wobbles,lineSubCategory:e}})}}],[function*(){let e=Ae.margin+Be.marginX,t=Ae.margin+Be.marginY,n=new ie(e,t),l=new ie(Y-e,P-t);Wi=new el(Be.scale/2,Xi),Li=[n,new Ut(l.x,n.y),l,new Ut(n.x,l.y)].map((e=>e.toArray())),yi=new kn(Li,[[0,1],[1,2],[2,3],[3,0]])}],[function*(){let{maxWidth:e,widthRange:t,spread:n,maxDivergence:l,tens
th:b,insetFromGeometry:s,addOutline:i,insetFromGeometryDistance:c,minDistance:p,bounds:{topLeft:[l.minX,l.minY],bottomRight:[l.maxX,l.maxY]},postProcessingArgs:{directional:!0,scribbleStrength:u?h:0,wobbleFreq:f,wobbleAmplitude:d*g}};switch(t){case"noise":case"bnnoise":return{...Z,vectorFieldType:t,boundingGeometry:a,vectorFieldNoiseProps:{...x,wobbleDetail:e.num(1,2)}};case"outline":return{...Z,vectorFieldType:t,boundingGeometry:a};case"directional":return{...Z,vectorFieldType:t,boundingGeometry:a,vectorFieldDirectionalProps:{direction:n}};case"wobbles":return{...Z,vectorFieldType:"wobbles",boundingGeometry:a,blueNoiseProps:{warpStrength:1e3,minDist:1*p,maxDist:1.5*p},wobbleProps:{tension:{min:.5,max:3},maxPointUse:1,maxDivergence:4,maxLinePoints:30}};case"bluenoise":return{...Z,vectorFieldType:t,boundingGeometry:a,vectorFieldNoiseProps:{...x,wobbleDetail:1},blueNoiseProps:{warpStrength:100,minDist:p+d,maxDist:4*(p+d)}};case"edgefill":return{...Z,vectorFieldType:t,boundingGeometry:a,blueNoiseProps:{warpStrength:100,minDist:2*(p+d),maxDist:2.2*(p+d)}}}},Hl=(e,t,n=[],l)=>{if(n.length){let e=n[0],t=l.int(0,e.verts.length-1),i=(t+1)%e.verts.length;return new Ut(...e.verts[t]).angleTo(new Ut(...e.verts[i]))}let i=Wi.getLinesIntersectingFace(e,!1),a=e.center,s=new Set([...t].map((e=>e.meta.lineCategory))),o=[Se.horizontal,Se.vertical,Se.perspective,Se.objects].filter((e=>!s.has(e))),r=i.filter((e=>!t.has(e.constructionLine)&&o.some((t=>t==e.constructionLine.meta.lineCategory))));if(r.length){let e=r.reduce(((e,t)=>Ln(a.toArray(),e.constructionLine.line)<Ln(a.toArray(),t.constructionLine.line)?e:t),r[0]);t.add(e.constructionLine);let n=e.constructionLine.line.map((e=>new Ut(...e)));return n[0].angleTo(n[n.length-1])}},Il=(e,t)=>{let{fade:n,scale:l}=e;return{fade:{in:{enabled:t.bool(n.in.enabledChance),length:t.num(n.in.min,n.in.max)},out:{enabled:t.bool(n.out.enabledChance),length:t.num(n.out.min,n.out.max)}},scale:{in:{enabled:t.bool(l.in.enabledChance),length:t.num(l.in.min,l.in.max)},out:{enabled:t.bool(l.out.enabledChance),length:t.num(l.out.min,l.out.max)}}}};async function Nl(e,t){let{colorOverride:n}=e?.detailObjectProps||{};const l=new _(e?.detailObjectProps?.noiseSeedOverride||t),i=new dn;i.expands(e.polygon),i.expandByValue(10);const a=e.faceRef?.center||i.center,s=e?.detailObjectProps?.inDominantShapes||[],o=e?.detailObjectProps?.inObject||[],d=s.length>0,u=!!e?.isInCurve,h=!!e?.detailObjectProps?.inObject?.length,m=e?.detailObjectProps?.isFineDetail,p=xe(e.lightingIntensity||Ie.default,Ie.clamp),{skipFill:b,skipDetails:g}=e.detailObjectProps||{};let f=Yl(je,{isInDominantPoly:m||d,normal:p,isOverlay:e.category==mn.overlay,isInCurveOrObject:h||u}),x=Yl(Qe,{isInDominantPoly:m||d,normal:p,isOverlay:e.category==mn.overlay,isInCurveOrObject:h||u});const Z=!b&&l.bool(f.fillChance),y=!g&&l.bool(x.fillChance),G=l.bool(f.insetChance),W=l.bool(x.insetChance),v=Z?l.weightedChoice(...f.layerCountChances):0,L=u?0:y?l.weightedChoice(...x.layerCountChances):0;let S=new Set,X=new Set,C=new Set,V=[],K=[],w=!1;function k(t,l,c){const h=[];for(let b=0;b<c;b++){const c=Pl("fill"===l?f:x,b);let g,Z=t.num(c.lineWeight.min,c.lineWeight.max),y=t.num(c.linePressure.min,c.linePressure.max);g=r(.4,Z*t.num(c.minDistanceMult.min,c.minDistanceMult.max)),m&&"detail"===l&&(Z*=.75,g*=.25);const v="fill"===l?zl.filter((e=>!S.has(e))):zl.filter((e=>!X.has(e)));let L,k=t.choice(v);v.length||("fill"===l?S.clear():X.clear(),k=t.choice(zl)),"fill"===l?S.add(k):X.add(k),d&&("fill"===l&&G||"detail"===l&&W)&&(L=u?e.isInCurve.line:s[0].face.vertexlist.map((e=>e.toArray())));let R=c.colorMap[b]||c.colorMap[0],T=t.weightedChoice(...R),M=bl(t,T,a,p,c.colorPalette,"fill"==l?V:K),z=null;if(t.bool(c.fadeAtLineSegmentChance)){let n,l,a=t.int(0,i.vertexList.length-1),s=[i.vertexList[a],i.vertexList[(a+1)%i.vertexList.length]],o=s[0].lerp(s[1],t.num(.01,.99));for(let t=0;t<e.polygon.length;t++){let n=[e.polygon[t],e.polygon[(t+1)%e.polygon.length]],i=Sn(o.toArray(),n[0].toArray(),n[1].toArray());(!l||i<l.dist)&&(l={seg:n,dist:i})}n=l.seg;const{fadeAtLineSegmentDistanceMult:r,fadeAtLineSegmentStrengthMult:d}=c;let u=i.center.distanceTo(n[0].lerp(n[1],.5));z={segment:n,distance:2*u*t.num(r.min,r.max),strength:t.num(d.min,d.max)}}let Y=t.weightedChoice(...c.styleChances),P=0;"directional"===Y&&(P=Hl(e.faceRef,C,o,t));let F,H,I="fill"==l&&u&&(w||0==b&&t.bool(qe.renderLightChance));w=I,"fill"===l?(n?M=n:I&&(M=bl(t,Ke.lightestOrDarkestBasedOnBg,a,p,c.colorPalette,V)),V.push(M)):"detail"==l&&K.push(M);const N=t.bool(c.ignoreLightingChance);F=!(u&&qe.ignoreLighting||N),H=!!(u&&qe.ignoreLighting||N),h.push({paintLineObj:{colorLayerType:T,lineBrightness:F?ye(p,Ie.min,Ie.max,ge(Ie.default,Ie.min,Ie.influencesBrightnessMult),ge(Ie.default,Ie.max,Ie.influencesBrightnessMult)):Ie.default,type:l,lines:[],closedPolyOrLine:!1,noiseOffset:[t.num(-1,1),t.num(-1,1)],canBulge:!0,isShading:!0,canWarp:!0,fadeAtLineSegment:z,lineTapering:Il("bluenoise"==Y&&"detail"==l?{fade:{in:{enabledChance:0,min:1,max:1},out:{enabledChance:0,min:4,max:6}},scale:{in:{enabledChance:100,min:.5,max:.8},out:{enabledChance:100,min:.5,max:.8}}}:c.lineTapering,t),disableSaturationShift:H,linePressure:y*ye(p,Ie.max,Ie.min,ye(Ie.influencesPressureMult,1,0,.5,1),1),edgeSharpness:t.num(c.edgeSharpness.min,c.edgeSharpness.max),accumulationStrength:t.num(c.accumulationStrength.min,c.accumulationStrength.max),materialHardness:t.num(c.materialHardness.min,c.materialHardness.max),lineWeight:.8*Z,lineColor:M},workerData:{streamlineWorkerProps:Fl({type:Y,direction:P,addOutline:"edgefill"==Y,scribble:d?!u&&t.bool(c.scribbleChance):t.bool(c.scribbleChance),scribbleStrength:t.num(c.scribbleStrength.min,c.scribbleStrength.max),random:t,insetFromGeometry:L,insetFromGeometryDistance:{min:c.insetDistance.min,max:c.insetDistance.max},objAABB:i,boundingGeometry:e.polygon.map((e=>e.toArray())),lineWeight:Z,minDistance:"bluenoise"==Y&&"detail"==l?.4*g:r(.4,"fill"==l?g*fe(p,Ie.max,Ie.min,fe(Ie.influencesMinDistanceMult,1,0,1,1),fe(Ie.influencesMinDistanceMult,0,1,1,.5)):g),maxLength:c.maxLength?t.num(c.maxLength.min,c.maxLength.max):1e10,wobbleAmplitude:t.easedNum(We,c.wobbleAmplitude.min,c.wobbleAmplitude.max),wobbleFreq:t.easedNum(We,c.wobbleFreq.min,c.wobbleFreq.max),streamLineProps:{...k,wobbleDetail:t.int(1,2)}}),noiseSeed:xn,randomSeed:q(t)}})}return h}const R=[...k(l,"fill",v),...k(l,"detail",L)],T=R.map((e=>Ml(e.workerData))),M=await Promise.all(T);e.allowExtraDetails=!1,R.filter((e=>"detail"==e.paintLineObj.type)).length>=2&&R.filter((e=>"detail"==e.paintLineObj.type)).every((e=>"directional"==e.workerData.streamlineWorkerProps.vectorFieldType))&&(e.allowExtraDetails=!0);for(let t=0;t<M.length;t++){const n=[],l=M[t],i=R[t].paintLineObj;"detail"==i.type&&"bluenoise"==R[t].workerData.streamlineWorkerProps.vectorFieldType&&(i.lineWeight*=1.5);for(let e of l){const t=e;t.length&&n.push(t)}n.length<1||(i.lines=n,e.detailObject=e.detailObject||[],e.detailObject.push(i))}if(e?.detailObject?.length){let t=[];for(let n=e.detailObject.length-1;n>0;n--){let l=e.detailObject[n-1],i=e.detailObject[n];i.colorLayerType===Ke.previous&&l?.lines?.length&&i?.lines?.length&&(l.lines=[...l.lines,...i.lines],t.push(i))}t.length>0&&(e.detailObject=e.detailObject.filter((e=>!t.includes(e))))}e.allowExtraDetails&&e?.detailObject?.length&&!m&&l.bool(d?80:40)&&async function(e,t){let n=[...Si,...hn].filter((e=>e.category==mn.overlay));for(let t of n){let n=new dn;if(n.expands(t.polygon),e.faceRef.aabb.intersects(n))return}let l=e.detailObject.filter((e=>"detail"==e.type));const i=new dn;i.expands(e.polygon),i.expandByValue(10);const a=e.faceRef?.center||i.center;let s=new kn([],[]);s.insertPolygon(e.polygon.map((e=>e.toArray())),!0);for(let e=0;e<l.length;e++){let t=l[e];for(let e of t.lines)s.insertPolygon(e,!1),await new Promise((e=>setTimeout(e,0)))}s.cleanupTrailingEdges();let o=s.internalFaces(),r=c(yn(a.x,a.y,100,5,40,100)),d=yn(a.x,a.y,600,0,100)>60;if(o.length>2)for(let n of o.filter((e=>e.area>100)))if(n.hedges.every((e=>e.face&&e.twin.face&&e.face!==e.twin.face))&&t.bool(r)){let l=t.num(.35,.45),i=n.vertexlist.map((e=>e.addPolar(e.angleTo(n.center),e.distanceTo(n.center)*l))),a={category:mn.detail,faceRef:n,polygon:i,detailObject:[],detailObjectProps:{isFineDetail:!0,skipDetails:!d,skipFill:!!d,inObject:e.detailObjectProps?.inObject,inDominantShapes:e.detailObjectProps?.inDominantShapes,noiseSeedOverride:q(t)}};Si.push(a)}}(e,l),e.readyForRender=!0}let Ul,Dl,Ol=new Set;function Bl(e){let t,n=0;for(;!t&&n++<200;){let n=J.choice(e.internalFaces()),l=J.choice(n.vertexlist);Ol.has(l)||(t=l)}return t}class Ql{dcel;maxAngle;pathVerts=[];AABB=new dn;constructor(e,t=.3){this.dcel=e,this.maxAngle=t}*findDominantPaths(e=!1){let t=new Set(this.dcel.hedges.filter((e=>e.face&&e.face.area>0&&e.twin.face&&e.twin.face.area>0&&e.origin!==e.twin.origin&&e.face!==e.twin.face)));for(;t.size>0;){let n=t.values().next().value;t.delete(n),t.delete(n.twin);let l=[n.twin.origin],i=[n.origin],a=new Set;a.add(n.origin),a.add(n.twin.origin);let o=0;for(let r of[n,n.twin]){let c=r.twin.origin,d=r===n?l:i,u=r.origin,h=u.angleTo(c);for(;;){const n=c.hedgelist.filter((t=>(!e||t.twin.face&&t.twin.face.area>0)&&t.face&&t.face.area>0&&!a.has(t.twin.origin)&&s(c.angleTo(t.twin.origin)-h)<this.maxAngle)).sort(((e,t)=>s(c.angleTo(e.twin.origin)-h)-s(c.angleTo(t.twin.origin)-h)));if(!n.length)break;let l=n[0];o+=s(c.angleTo(l.twin.origin)-h),t.delete(l),t.delete(l.twin),u=c,c=l.twin.origin,d.push(c),a.add(c),h=u.angleTo(c)}}i.reverse();let r=i.concat(l),c=r.reduce(((e,t,n)=>0===n?0:e+t.distanceTo(r[n-1])),0);yield{vertices:r,length:c,curviness:o/r.length}}}walk(e,t,n=!0){let l=e;if(!l)return;let i=0,a=0;this.AABB.expand(l);let s=new Set;for(s.add(l),Ol.add(l);i<=t&&a++<400;){const e=l.hedgelist.filter((e=>!s.has(e.twin.origin)&&!Ol.has(e.twin.origin)));if(e.sort(((e,t)=>{let n=e.twin.origin,l=t.twin.origin,i=this.AABB.center.distanceTo(n);return this.AABB.center.distanceTo(l)-i})),0===e.length)break;let a=e[0].twin.origin;if(i+=l.distanceTo(a),n&&i>t){let e=(o=l,r=a,c=1-(i-t)/l.distanceTo(a),new Ut(ge(o.x,r.x,c),ge(o.y,r.y,c)));s.add(e),this.AABB.expand(e);break}s.add(a),Ol.add(a),this.AABB.expand(a),l=a}var o,r,c;this.pathVerts.push(...Array.from(s))}}class jl{heap;maxSize;valueFunction;epsilon=g;constructor(e,t){this.valueFunction=t,this.heap=[],this.maxSize=e}size(){return this.heap.length}push(e){this.heap.push(e),this.siftUp(this.heap.length-1),this.heap.length>this.maxSize&&this.heap.pop()}clear(){this.heap=[]}peek(){return this.heap[0]}remove(e){const t=this.heap.findIndex((t=>t===e));-1!==t&&(this.heap[t]=this.heap[this.heap.length-1],this.heap.pop(),t<this.heap.length&&this.siftDown(t))}replaceTop(e){this.heap[0]=e,this.siftDown(0)}toArray(){return[...this.heap]}siftUp(e){for(;e>0;){const t=Math.floor((e-1)/2),n=this.valueFunction(this.heap[e])-this.valueFunction(this.heap[t]);if(n<this.epsilon&&n>-this.epsilon)break;if(n<=0)break;[this.heap[e],this.heap[t]]=[this.heap[t],this.heap[e]],e=t}}siftDown(e){const t=this.heap.length;for(;;){let n=e;const l=2*e+1,i=2*e+2,a=this.valueFunction(this.heap[n]);if(l<t&&this.valueFunction(this.heap[l])-a>this.epsilon&&(n=l),i<t){const e=this.valueFunction(this.heap[n]);this.valueFunction(this.heap[i])-e>this.epsilon&&(n=i)}if(n===e)break;[this.heap[e],this.heap[n]]=[this.heap[n],this.heap[e]],e=n}}}class Jl{position;rotation;dimensions;numSides;cameraPos;fov;aspect;near;far;lights;cullBackfaces;localVertices=[];worldVertices=[];screenVertices=[];constructor(e,t,n,l,i,a=90,s=Y/P,o=.1,r=1e4,c=[],d=!1){this.position=e,this.rotation=t,this.dimensions=n,this.numSides=l,this.cameraPos=i,this.fov=a,this.aspect=s,this.near=o,this.far=r,this.lights=c,this.cullBackfaces=d,this._buildLocalGeometry()}_buildLocalGeometry(){const{width:e,height:t,depth:n}=this.dimensions,l=e/2,i=t/2,a=n/2,s=2*Math.PI/this.numSides,o=this.numSides%2==0?-Math.PI/this.numSides:-Math.PI/2;if(0===n)for(let e=0;e<this.numSides;e++){const t=o+s*e,n=Math.cos(t)*l,a=Math.sin(t)*i;this.localVertices.push({x:n,y:a,z:0})}else for(let e=0;e<this.numSides;e++){const t=o+s*e,n=Math.cos(t),r=Math.sin(t);this.localVertices.push({x:n*l,y:r*i,z:+a}),this.localVertices.push({x:n*l,y:r*i,z:-a})}}getFaces2D(){const e=function(e,t,n,l,i,a){const s=El(e*Math.PI/180),o=_l(t*Math.PI/180),r=ql(n*Math.PI/180),c=$l(l,i,a),d=ei(r,ei(o,s));return ei(c,d)}(this.rotation.x,this.rotation.y,this.rotation.z,this.position.x,this.position.y,this.position.z),t=$l(-this.cameraPos.x,-this.cameraPos.y,-this.cameraPos.z),n=ei(function(e,t,n,l){const i=1/Math.tan(e*Math.PI/180/2),a=1/(n-l);return[[i/t,0,0,0],[0,i,0,0],[0,0,(n+l)*a,n*l*a*2],[0,0,-1,0]]}(this.fov,this.aspect,this.near,this.far),ei(t,e));this.worldVertices=[],this.screenVertices=[];for(const t of this.localVertices){const l=ti(e,[t.x,t.y,t.z,1]);this.worldVertices.push({x:l[0],y:l[1],z:l[2]});const i=ti(n,[t.x,t.y,t.z,1]);0!==i[3]&&(i[0]/=i[3],i[1]/=i[3],i[2]/=i[3]);const a=(.5*i[0]+.5)*Y,s=(1-(.5*i[1]+.5))*P;this.screenVertices.push([a,s])}const l=this._buildFaces(),i=this.cameraPos.x,a=this.cameraPos.y,s=this.cameraPos.z,o=[];for(let e of l){const t=e.indices.map((e=>this.worldVertices[e])),n=e.indices.map((e=>this.screenVertices[e])),l=ni(t),r=li(t),c=ii(l,r,this.lights);if(this.cullBackfaces){const e={x:r.x-i,y:r.y-a,z:r.z-s};l[0]*e.x+l[1]*e.y+l[2]*e.z<0&&o.push({vertices:n,normal:l,lighting:c})}else o.push({vertices:n,normal:l,lighting:c})}return o}_buildFaces(){const e=[],t=this.numSides;if(0!==this.dimensions.depth){const n=[];for(let e=0;e<t;e++)n.push(2*e);e.push({indices:n});const l=[];for(let e=t-1;e>=0;e--)l.push(2*e+1);e.push({indices:l});for(let n=0;n<t;n++){const l=(n+1)%t,i=[2*n,2*n+1,2*l+1,2*l];e.push({indices:i})}}else e.push({indices:Array.from({length:t},((e,t)=>t))});return e}}class Al{vertices;rotation;perspective;zShift;transformOrigin;projectedVertices;vertices3D;constructor(e,t,n=800,l=-50,i={x:Y/2,y:P/2}){this.vertices=e,this.rotation=t,this.perspective=n,this.zShift=l,this.transformOrigin=i}getLineSegments(){let e=new dn;for(let t of this.vertices)e.expands(t.map((e=>new Ut(...e))));const{x:t,y:n,z:l}={...e.center,z:this.zShift},{x:i,y:a,z:s}=this.rotation,o=this.perspective,r=e.center,c=this.vertices.map((e=>e.map((e=>new Ut(...e).subtract(r)))));this.vertices3D=[];for(let e=0;e<c.length;e++){this.vertices3D.push([]);for(const t of c[e])this.vertices3D[e].push({x:t.x,y:t.y,z:0})}const d=function(e,t,n,l,i,a){const s=t*Math.PI/180,o=n*Math.PI/180,r=El(e*Math.PI/180),c=_l(s);let d=ei(ql(o),ei(c,r));return ei($l(l,i,a),d)}(i,a,s,t,n,l),u=this.vertices3D.map((e=>e.map((e=>{const t=[e.x,e.y,e.z,1],n=ti(d,t);return{x:n[0],y:n[1],z:n[2]}}))));return this.projectedVertices=u.map((e=>e.map((e=>function(e,t,n={x:Y/2,y:P/2}){const{x:l,y:i,z:a}=e,s=l-n.x,o=(i-n.y)*t/(t+a);return t+a<=0?null:[s*t/(t+a)+n.x,o+n.y]}(e,o,this.transformOrigin))).filter((e=>null!==e)))).map((e=>e.filter((e=>e[0]>=-100&&e[0]<=Y+100&&e[1]>=-100&&e[1]<=P+100)))).filter((e=>e.length>0)),this.projectedVertices}}function El(e){const t=Math.cos(e),n=Math.sin(e);return[[1,0,0,0],[0,t,-n,0],[0,n,t,0],[0,0,0,1]]}function _l(e){const t=Math.cos(e),n=Math.sin(e);return[[t,0,n,0],[0,1,0,0],[-n,0,t,0],[0,0,0,1]]}function ql(e){const t=Math.cos(e),n=Math.sin(e);return[[t,-n,0,0],[n,t,0,0],[0,0,1,0],[0,0,0,1]]}function $l(e,t,n=0){return[[1,0,0,e],[0,1,0,t],[0,0,1,n],[0,0,0,1]]}function ei(e,t){const n=Array.from(Array(e.length),(()=>Array(t[0].length).fill(0)));for(let l=0;l<e.length;l++)for(let i=0;i<t[0].length;i++)for(let a=0;a<e[0].length;a++)n[l][i]+=e[l][a]*t[a][i];return n}function ti(e,t){const n=[];for(let l=0;l<e.length;l++){let i=0;for(let n=0;n<t.length;n++)i+=e[l][n]*t[n];n.push(i)}return n}function ni(e){const t=e[0],n=e[1],l=e[2],i=[n.x-t.x,n.y-t.y,n.z-t.z],a=[l.x-t.x,l.y-t.y,l.z-t.z],s=[i[1]*a[2]-i[2]*a[1],i[2]*a[0]-i[0]*a[2],i[0]*a[1]-i[1]*a[0]],o=Math.sqrt(s[0]**2+s[1]**2+s[2]**2);return s.map((e=>e/o))}function li(e){const t=e.reduce(((e,t)=>(e.x+=t.x,e.y+=t.y,e.z+=t.z,e)),{x:0,y:0,z:0}),n=e.length;return{x:t.x/n,y:t.y/n,z:t.z/n}}function ii(e,t,n){let l=0;for(const i of n){const n={x:i.position.x-t.x,y:i.position.y-t.y,z:i.position.z-t.z},a=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z);if(0===a)continue;const s=n.x/a,o=n.y/a,r=n.z/a;l+=(e[0]*s+e[1]*o+e[2]*r)*i.brightness}return l}let ai=!1,si=0,oi=0;T();let ri=T();const ci=()=>{if(!ki[si])return void ui();const e=ki[si][0](),t=ki[si][1]||!1;let n,l=!1;const i=()=>{n=e.next(),na?l=!1:(l=!0,n?.done||function(e){ai||(Ul=w.getParameter(w.MAX_CLIENT_WAIT_TIMEOUT_WEBGL),Dl=w.SYNC_FLUSH_COMMANDS_BIT,ai=!0);const t=w.fenceSync(w.SYNC_GPU_COMMANDS_COMPLETE,0);!function n(){const l=w.clientWaitSync(t,Dl,Ul);l===w.ALREADY_SIGNALED||l===w.CONDITION_SATISFIED||na?(clearTimeout(void 0),w.deleteSync(t),e()):setTimeout(n,0)}()}(i))},a=()=>{const s=T();if(t)!l&&!na&&i();else for(;T()-s<1e3/30&&!na&&!n?.done;)n=e.next();oi++,n?.done?(di("Step took"),Ft?.copyBufferToScreen(),l=!1,n=null,si++,ci()):(v(n.value||{showUpdate:!1}),setTimeout(a,0))};a()};function di(e="",t=!1){T(),ri=T()}const ui=()=>{document.complete=!0,nl(gl([...dl][0],[...dl],dl.size)),di("Total render time",!0),function(){for(let e=0;e<Vl.length;e++){const t=Vl[e];t&&t.terminate()}}()};function hi(e,t,n=4){const l=t/2,i=[];for(let t=0;t<e.length-1;t++){const[n,l]=e[t],[a,s]=e[t+1],o=a-n,r=s-l,c=Math.hypot(o,r);if(0===c){i.push([0,0]);continue}const d=-r/c,u=o/c;i.push([d,u])}const a=[],s=[];for(let t=0;t<e.length;t++){const[o,r]=e[t];if(0===t){const[e,t]=i[0],n=e*l,c=t*l;a.push([o+n,r+c]),s.push([o-n,r-c])}else if(t===e.length-1){const[e,t]=i[i.length-1],n=e*l,c=t*l;a.push([o+n,r+c]),s.push([o-n,r-c])}else{const[e,c]=i[t-1],[d,u]=i[t],h=Math.sqrt((e*d+c*u+1)/2);if(0===h){const t=e*l,n=c*l;a.push([o+t,r+n]),s.push([o-t,r-n]);continue}const m=l/h;if(m>n*l){const[t,n]=[e*l,c*l],[i,h]=[d*l,u*l];a.push([o+t,r+n]),a.push([o+i,r+h]),s.push([o-t,r-n]),s.push([o-i,r-h])}else{const[t,n]=[e+d,c+u],i=Math.hypot(t,n);if(0===i){const t=e*l,n=c*l;a.push([o+t,r+n]),s.push([o-t,r-n])}else{const[e,l]=[t/i,n/i],c=e*m,d=l*m;a.push([o+c,r+d]),s.push([o-c,r-d])}}}}return[...a.reverse(),...s]}class mi{root=null;epsilon=g;count=0;wasRemoved=!1;insert(e){this.root=this.insertRec(this.root,e,0),this.count++}compareCoord(e,t){const n=e-t;return Math.abs(n)<this.epsilon||n<0?-1:1}insertRec(e,t,n){return e?((0===e.axis?this.compareCoord(t.point.x,e.point.point.x):this.compareCoord(t.point.y,e.point.point.y))<0?e.left=this.insertRec(e.left,t,n+1):e.right=this.insertRec(e.right,t,n+1),e):{point:t,axis:n%2,left:null,right:null}}remove(e){this.wasRemoved=!1,this.root=this.removeRec(this.root,e,0),this.wasRemoved&&this.count--}removeRec(e,t,n){if(!e)return null;const l=e.axis;if(this.equals(e.point,t)){if(this.wasRemoved=!0,e.right){const t=this.findMin(e.right,l,n+1);e.point=t.point,e.right=this.removeRec(e.right,t.point,n+1)}else{if(!e.left)return null;{const t=this.findMin(e.left,l,n+1);e.point=t.point,e.right=this.removeRec(e.left,t.point,n+1),e.left=null}}return e}{let i;i=0===l?this.compareCoord(t.point.x,e.point.point.x):this.compareCoord(t.point.y,e.point.point.y),i<0?e.left=this.removeRec(e.left,t,n+1):e.right=this.removeRec(e.right,t,n+1)}return e}findMin(e,t,n){if(!e)throw Error("Empty subtree when finding min.");if(e.axis===t)return e.left?this.findMin(e.left,t,n+1):e;const l=e.left?this.findMin(e.left,t,n+1):e,i=e.right?this.findMin(e.right,t,n+1):e;let a=e;return this.compareAxis(l.point,a.point,t)<0&&(a=l),this.compareAxis(i.point,a.point,t)<0&&(a=i),a}findNearest(e){return this.root?this.findNearestRec(this.root,e,this.root.point,0):null}findNearestRec(e,t,n,l){if(!e)return n;let i=n;this.distanceSq(e.point,t)<this.distanceSq(i,t)&&(i=e.point);const a=0===e.axis?t.point.x-e.point.point.x:t.point.y-e.point.point.y;let s,o;return a<-this.epsilon?(s=e.left,o=e.right):a>this.epsilon?(s=e.right,o=e.left):(s=e.left,o=e.right),i=this.findNearestRec(s,t,i,l+1),a**2<this.distanceSq(i,t)&&(i=this.findNearestRec(o,t,i,l+1)),i}findKNearest(e,t){if(!this.root)return[];const n=new jl(t,(e=>e.dist));return this.findKNearestRec(this.root,e,t,n),n.toArray().map((e=>e.point))}getTotalNodes(){return this.count}*pointsWithinDistanceGenerator(e,t){const n=t*t;yield*this.pointsWithinDistanceRecGen(this.root,e,n)}*pointsWithinDistanceRecGen(e,t,n,l=0){if(!e)return;this.distanceSq(e.point,t)<=n&&(yield e.point);const i=0===e.axis?t.point.x-e.point.point.x:t.point.y-e.point.point.y;let a,s;i<-this.epsilon?(a=e.left,s=e.right):(a=e.right,s=e.left),yield*this.pointsWithinDistanceRecGen(a,t,n,l+1),i**2<=n&&(yield*this.pointsWithinDistanceRecGen(s,t,n,l+1))}findKNearestRec(e,t,n,l,i=0){if(!e)return;const a=e.axis,s=this.distanceSq(e.point,t);if(l.size()<n)l.push({dist:s,point:e.point});else{const t=l.peek();t&&s<t.dist&&l.replaceTop({dist:s,point:e.point})}const o=0===a?t.point.x-e.point.point.x:t.point.y-e.point.point.y;let r,c;o<-this.epsilon?(r=e.left,c=e.right):o>this.epsilon?(r=e.right,c=e.left):(r=e.left,c=e.right),this.findKNearestRec(r,t,n,l,i+1);const d=l.peek();d&&o**2<d.dist&&this.findKNearestRec(c,t,n,l,i+1)}distanceSq(e,t){const n=e.point.x-t.point.x,l=e.point.y-t.point.y;return n*n+l*l}compareAxis(e,t,n){const l=0===n?e.point.x-t.point.x:e.point.y-t.point.y;return Math.abs(l)<this.epsilon?0:l}equals(e,t){const n=e.point.x-t.point.x,l=e.point.y-t.point.y;return n*n+l*l<this.epsilon*this.epsilon}}class pi{opts;kTree=new mi;activeList=[];random;epsilon=g;maxDist;constructor(e){this.opts=e,this.random=e.random||J,this.maxDist=e.maxDist||1}*generate(){const{bounds:e,noiseField:t,initialCount:n=1,k:l=50}=this.opts;if(this.opts.seedPoints&&this.opts.seedPoints.length>0)for(let e of this.opts.seedPoints){const n={point:e,minDist:t(e.x,e.y)};this.placePoint(n),this.activeList.push(n),yield n}else for(let l=0;l<n;l++){const n=this.random.num(e.topLeft[0],e.bottomRight[0]),l=this.random.num(e.topLeft[1],e.bottomRight[1]),i=t(n,l),a={point:new Ut(n,l),minDist:i};this.placePoint(a),this.activeList.push(a),yield a}for(;this.activeList.length>0;){const n=0,i=this.activeList[n];let a=!1;for(let n=1;n<l;n++){const s=i.minDist*(.5+l/n),o=this.random.dec()*Math.PI*2,r=i.point.x+Math.cos(o)*s,c=i.point.y+Math.sin(o)*s;if(r<e.topLeft[0]||r>e.bottomRight[0]||c<e.topLeft[1]||c>e.bottomRight[1])continue;const d=t(r,c),u={point:new Ut(r,c),minDist:d};if(this.canPlace(u)){this.placePoint(u),this.activeList.push(u),yield u,a=!0;break}}a||this.activeList.splice(n,1)}}canPlace(e){for(let t of
1lLHRoaXMuc2lmdERvd24oMCl9dG9BcnJheSgpe3JldHVyblsuLi50aGlzLmhlYXBdfXNpZnRVcChlKXtmb3IoO2U+MDspe2NvbnN0IHQ9TWF0aC5mbG9vcigoZS0xKS8yKSxpPXRoaXMudmFsdWVGdW5jdGlvbih0aGlzLmhlYXBbZV0pLXRoaXMudmFsdWVGdW5jdGlvbih0aGlzLmhlYXBbdF0pO2lmKGk8dGhpcy5lcHNpbG9uJiZpPi10aGlzLmVwc2lsb24pYnJlYWs7aWYoaTw9MClicmVhaztbdGhpcy5oZWFwW2VdLHRoaXMuaGVhcFt0XV09W3RoaXMuaGVhcFt0XSx0aGlzLmhlYXBbZV1dLGU9dH19c2lmdERvd24oZSl7Y29uc3QgdD10aGlzLmhlYXAubGVuZ3RoO2Zvcig7Oyl7bGV0IGk9ZTtjb25zdCBuPTIqZSsxLHM9MiplKzIscj10aGlzLnZhbHVlRnVuY3Rpb24odGhpcy5oZWFwW2ldKTtpZihuPHQmJnRoaXMudmFsdWVGdW5jdGlvbih0aGlzLmhlYXBbbl0pLXI+dGhpcy5lcHNpbG9uJiYoaT1uKSxzPHQpe2NvbnN0IGU9dGhpcy52YWx1ZUZ1bmN0aW9uKHRoaXMuaGVhcFtpXSk7dGhpcy52YWx1ZUZ1bmN0aW9uKHRoaXMuaGVhcFtzXSktZT50a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13ZShlLDApO3lpZWxkIHR9KHIpO2JyZWFrO2RlZmF1bHQ6dGhyb3cgRXJyb3IoIkludmFsaWQgZmllbGQgdHlwZSIpfWZvcihsZXQgZSBvZiBnKXtpZighZXx8ZS5sZW5ndGg8Miljb250aW51ZTtpZigib3V0bGluZSI9PT10KXtwb3N0TWVzc2FnZSh7cmVzdWx0OltlXSxkb25lOiExLGVycm9yOm51bGwsd29ya2VySWQ6ZH0pO2JyZWFrfWxldCBpPW1lKGUpO2lmKHIucG9zdFByb2Nlc3NpbmdBcmdzKXtpPXZlKGkscik7bGV0IGU9ZihpKTtpZighZS5sZW5ndGgpY29udGludWU7ZT1lLm1hcCgoZT0+TWUoZSxyKSkpLmZpbHRlcigoZT0+ZS5sZW5ndGg+PTIpKSx1LnB1c2goLi4uZSkscCgpfWVsc2UgdS5wdXNoKGkpLHAoKX1pZigib3V0bGluZSIhPT10JiZyLmFkZE91dGxpbmUmJiFyLmluc2V0RnJvbUdlb21ldHJ5JiZyLmJvdW5kaW5nR2VvbWV0cnkpe2xldCBlPXdlKHIpO3UucHVzaChlKX1wKCEwKX1jYXRjaChlKXtwb3N0TWVzc2FnZSh7cmVzdWx0Om51bGwsZXJyb3I6ZS5tZXNzYWdlLHdvcmtlcklkOmR9KX19fSgpOwovLyMgc291cmNlTWFwcGluZ1VSTD1zdHJlYW1saW5lcy53b3JrZXIuanMubWFwCgo=");const Cl=navigator.hardwareConcurrency||4,Vl=[],Kl={},wl={},kl=[],Rl={};for(let e=0;e<Cl;e++){const t=new Xl;Vl.push(t),Rl[e]=!0,wl[e]=[],t.onmessage=function(e){const{result:t,done:n,error:l,workerId:i}=e.data;if(t?.length>0&&wl[i].push(...t),n||l){const e=Kl[i];if(l?e.reject(l):e.resolve(wl[i]),delete Kl[i],Rl[i]=!0,wl[i]=[],kl.length>0){const e=kl.shift();e.data.workerId=i,Tl(i,e)}}}}function Tl(e,t){const n=Vl[e];Rl[e]=!1,Kl[e]=t,n.postMessage(t.data)}async function Ml(e){return new Promise(((t,n)=>{const l={data:e,resolve:t,reject:n};kl.push(l),function(){for(let e=0;e<Vl.length&&0!==kl.length;e++)if(Rl[e]){const t=kl.shift();t.data.workerId=e,Tl(e,t)}}()}))}let zl=[],Yl=(e,{isInDominantPoly:t,normal:n,isOverlay:l=!1,isInCurveOrObject:i=!1})=>{const a=[{condition:l,key:we.overlay},{condition:!0,key:we.override},{condition:t,key:we.dominant},{condition:!t,key:we.nonDominant},{condition:n>Ie.default,key:we.normalHigh},{condition:n<Ie.default,key:we.normalLow},{condition:i,key:we.inCurveOrObject},{condition:!i,key:we.notInCurveOrObject}].filter((({key:t})=>e.spatialOverride?.[t]));for(const{condition:t,key:n}of a)if(t&&e.spatialOverride[n])return be(e,e.spatialOverride[n]);return e},Pl=(e,t)=>e?.layerOverride?.[t]?be(e,e.layerOverride[t]):e,Fl=({random:e,type:t="noise",direction:n=e.num(0,360),objAABB:l,addOutline:i=!1,boundingGeometry:a,insetFromGeometry:s,insetFromGeometryDistance:c={min:2,max:4},lineWeight:d,scribble:u=!1,scribbleStrength:h=0,maxLength:m=1e10,minDistance:p=r(.2,.75*d),minLength:b=2*p,wobbleAmplitude:g=e.easedNum(We,.5,2),wobbleFreq:f=e.easedNum(We,10*d,20*d),streamLineProps:x})=>{const Z={stepSize:o(p/2,1),maxLength:m,minLeng
xlLHRoaXMudG9sZXJhbmNlKSYmbCsrfSkpLGw+MXx8ci5wdXNoKFtzLG9dKX19Zm9yKGxldCBlIG9mIHIpdi5ib29sKHQpJiZ0aGlzLnJlbW92ZUVkZ2UoZVswXS54LGVbMF0ueSxlWzFdLngsZVsxXS55KTt0aGlzLmNsZWFudXBUcmFpbGluZ0VkZ2VzKCl9aW5zZXJ0UG9seWdvbihlLHQ9ITApe2xldCBpPVtdLG49bmV3IE47bi5leHBhbmRzKGUubWFwKChlPT4obmV3IEQpLmZyb21BcnJheShlKSkpKSxuLmV4cGFuZEJ5VmFsdWUodGhpcy50b2xlcmFuY2UpO2xldCBz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1LS0pfXJldHVybiBwfSgodCsxMDApL3MsKGkrMTAwKS9zLChuKzEwMCkvcyksMCwxLHIsbyk7Y2xhc3MgY2V7aGVhcDttYXhTaXplO3ZhbHVlRnVuY3Rpb247ZXBzaWxvbj1wO2NvbnN0cnVjdG9yKGUsdCl7dGhpcy52YWx1ZUZ1bmN0aW9uPXQsdGhpcy5oZWFwPVtdLHRoaXMubWF4U2l6ZT1lfXNpemUoKXtyZXR1cm4gdGhpcy5oZWFwLmxlbmd0aH1wdXNoKGUpe3RoaXMuaGVhcC5wdXNoKGUpLHRoaXMuc2lmdFVwKHRoaXMuaGVhcC5sZW5ndGgtMSksdGhpcy5oZWFwLmxlbmd0aD50aGlzLm1heFNpemUmJnRoaXMuaGVhcC5wb3AoKX1jbGVhcigpe3RoaXMuaGVhcD1bXX1wZWVrKCl7cmV0dXJuIHRoaXMuaGVhcFswXX1yZW1vdmUoZSl7Y29uc3QgdD10aGlzLmhlYXAuZmluZEluZGV4KCh0PT50PT09ZSkpOy0xIT09dCYmKHRoaXMuaGVhcFt0XT10aGlzLmhlYXBbdGhpcy5oZWFwLmxlbmd0aC0xXSx0aGlzLmhlYXAucG9wKCksdDx0aGlzLmhlYXAubGVuZ3RoJiZ0aGlzLnNpZnREb3duKHQpKX1yZXBsYWNlVG9wKGUpe3RoaXMuaGVhcFswXT
h,h};let ol=[],rl=[],cl=[],dl=new Set,ul={L:1,C:1,H:2/Math.PI},hl=30,ml=ve;function pl(e,t,n=ul){e=Jt(e),t=Jt(t);const{L:l,C:i,H:a}=n,s=e[0]-t[0],o=e[1]-t[1];let r=e[2]-t[2];r=(r+180)%360-180;const c=r*Math.PI/180;return Math.sqrt(s*s*l+o*o*i+c*c*a)}function bl(e,t,n,l=1,i="fg",a=[]){let s,o=t,r=Re.bg[0][0]>=.5,c=a?.[0];if(o==Ke.previous)return c;if(o==Ke.brightnessBasedShadowOrHighlight){let t,a=c||Ll(e,n,l,null,i),s=l>=ge(Ie.max,Ie.min,.5),o=.2;if(a[0]>.75&&!s&&(o=.02),s){let e=Zl(a,cl,o);t=[ge(a[0]+o,e[0],.5),e[1],e[2]]}else{let e=Zl(a,cl,-o);t=[ge(a[0]+-o,e[0],.5),e[1],e[2]]}return Jt(t)}Ke.lightestOrDarkestBasedOnBg==o&&(o=r?Ke.lightest:Ke.darkest);let d=c||Ll(e,n,l,null,i),u=d[0]>.7&&d[1]<.05;switch(o){case Ke.color:s=Ll(e,n,l,null,i);break;case Ke.randomAccent:s=e.choice(ol);break;case Ke.base:s=Re.base[0];break;case Ke.line:s=Re.line.reduce(((e,t)=>r?e[0]<t[0]?e:t:e[0]>t[0]?e:t),Re.line[0]);break;case Ke.shadow:let t=c||Ll(e,n,l,null,i);s=xl([.3*t[0],t[1],t[2]],cl,0)[0];break;case Ke.highlight:let a=c||Ll(e,n,l,null,i);s=xl([Ze(0,1,1.5*a[0]),a[1],a[2]],cl,0)[0];break;case Ke.offset:s=u?d:xl(c||d,cl,hl*e.choice([-1,1]),1)[0];break;case Ke.offsetUp:s=u?d:xl(c||d,cl,hl,1)[0];break;case Ke.palettecomplement:s=xl(c||d,ol,180)[0];break;case Ke.offsetDown:s=u?d:xl(c||d,cl,hl,-1)[0];break;case Ke.darkest:s=ol.reduce(((e,t)=>e[0]<t[0]?e:t),ol[0]);break;case Ke.lightest:s=ol.reduce(((e,t)=>e[0]>t[0]?e:t),ol[0])}return dl.add(s),s}function gl(e,t,n=0){if(0===t.length)throw Error("Palette is empty.");const l=t.map((t=>({color:t,dist:pl(e,t)})));return l.sort(((e,t)=>e.dist-t.dist)),l.slice(0,n).map((e=>e.color))}function fl(e,t){let n=e.leastCommonIndex,l=e.mostCommonIndex,i=t.reduce(((e,t)=>e[0]<t[0]?e:t),t[0]),a=t.reduce(((e,t)=>e[0]>t[0]?e:t),t[0]);const s=(t.indexOf(i)-n+t.length)%t.length;let o=t.slice(s).concat(t.slice(0,s));if(o.indexOf(a)===l){const e=[];for(let t=0;t<o.length;t++)t!==l&&t!==n&&e.push(t);if(e.length>0){const t=J.choice(e);[o[l],o[t]]=[o[t],o[l]]}}return o}function xl(e,t,n=20,l=1){return gl([e[0],e[1],jt(e[2]+n)],t.filter((e=>e)),l)}function Zl(e,t,n=1){const l=[Ze(0,1,e[0]+n),e[1],e[2]];let i;for(let e of t){let t=pl(l,e,ul);(!i||t<i.dist)&&(i={color:e,dist:t})}return i.color}let yl,Gl,Wl=new Map,vl=new Set;function Ll(e,t,n=1,l=null,i="fg",a=null){let{freqMultiplier:o,singleAccent:r,usePolyIDColorOffset:d}=et,u=0,h="fg"==i?ol:rl,m="fg"==i?yl:Gl,p="fg"==i?o:500*o,b="bg"==i?ye(t.y,0,P,0,h.length-1):ye(ml(yn(t.x,t.y,0,p,0,1)),m.min,m.max,0,h.length-1);if(d){let n=Ki.getPolygonsAtPoint(t.toArray()).filter((e=>vl.has(e.meta.meta.id))).sort(((e,t)=>e.meta.meta.totalArea-t.meta.meta.totalArea)),l=n?.[0];if(l){let t=l.meta.meta.id;Wl.has(t)||Wl.set(t,e.int(1,h.length-1)),u+=Wl.get(t)}}if(null!==l){let t=xl(a||h[c(s(b+u))%h.length],cl,hl*l,et.samplesForComplimentary);return e.choice(t)}return h[c(s(b+u))%h.length]}function Sl(e,t,n){var l;return function(t){return l=l||function(e){var t=function(e){return atob(e)}(e),n=t.indexOf("\n",10)+1,l=t.substring(n)+"",i=new Blob([l],{type:"application/javascript"});return URL.createObjectURL(i)}(e),new Worker(l,t)}}var Xl=Sl("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y29uc3R7Zmxvb3I6ZSxjZWlsOnQsc2luOmksY29zOm4scG93OnMsYWJzOnIsbWluOm8sbWF4OmwsaHlwb3Q6aCxyb3VuZDphLHNxcnQ6YyxhY29zOmQsc2lnbjpnLGxvZzpmLFBJOnV9PU1hdGgscD0xZS03O2Z1bmN0aW9uIHgodCxpPXApe3JldHVybi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LnRvbGVyYW5jZSlyZXR1cm4hMH19aXNMaW5lU2VnbWVudE9uRWRnZU9mRmFjZShlLHQsaT1wKXtmb3IobGV0IG49MDtuPGUudmVydGV4bGlzdC5sZW5ndGg7bisrKWlmKEgoW2UudmVydGV4bGlzdFtuXS50b0FycmF5KCksZS52ZXJ0ZXhsaXN0WyhuKzEpJWUudmVydGV4bGlzdC5sZW5ndGhdLnRvQXJyYXkoKV0sdCksaSlyZXR1cm4hMDtyZXR1cm4hMX1nZXRGYWNlc0ludGVyc2VjdGluZ0FBQkIoZSl7bGV0IHQ9W107Zm9yKGxldCBpIG9mIHRoaXMuZmFjZXMuZmlsdGVyKChlPT5lLmFyZWE+MCkpKWUuaW50ZXJzZWN0cyhpLmFhYmIsdGhpcy50b2xlcmFuY2UpJiZ0LnB1c2goaSk7cmV0dXJuIHR9cmVtb3ZlRWRnZXNJbnNpZGVQb2x5Z29uKGUsdD0xMDApe2xldCBpPW5ldyBOO2kuZXhwYW5kcyhlLm1hcCgoZT0+KG5ldyBEKS5mcm9tQXJyYXkoZSkpKSk7bGV0IG49ZS5tYXAoKGU9PihuZXcgRCkuZnJvbUFycmF5KGUpKSkscz10aGlzLmdldEZhY2VzSW50ZXJzZWN0aW5nQUFCQihpKSxyPVtdO2ZvcihsZXQgdCBvZiBzKXtsZXQgaT10LnZlcnRleGxpc3Q7Zm9yKGxldCB0PTA7dDxpLmxlbmd0aDt0Kyspe2xldCBzPWlbdF0sbz1pWyh0KzEpJWkubGVuZ3RoXTtpZighZWUobixzLHRoaXMudG9sZXJhbmNlKXx8IWVlKG4sbyx0aGlzLnRvbGVyYW5jZSkpY29udGludWU7bGV0IGw9MDtbcyxvXS5mb3JFYWNoKCh0PT57VSh0LnRvQXJyYXkoKS
).fromArray(e))),n=new dn;n.expands(t);let l=[];for(let i of this.faces)if(!(i.area<=this.tolerance)&&n.intersects(i.aabb)){if(Nn(t,i.vertexlist)){l.push({face:i,intersections:[],isContained:!0});continue}let n=[];for(let l=0;l<e.length;l++){let a=[t[l],t[(l+1)%e.length]];n.push(...i.intersectWithLineSeg(a))}n.length>0&&l.push({face:i,intersections:n,isContained:!1})}return l}}class kn extends wn{tolerance;constructor(e,t,n=Kn){super(e,t,n),this.tolerance=n}isPolyLineSegmentOnEdge(e,t){for(let n=0;n<t.length-1;n++){let l=[t[n],t[n+1]];if(this.isLineSegmentOnEdgeOfFace(e,l),this.tolerance)return!0}}isLineSegmentOnEdgeOfFace(e,t,n=g){for(let l=0;l<e.vertexlist.length;l++)if(Rn([e.vertexlist[l].toArray(),e.vertexlist[(l+1)%e.vertexlist.length].toArray()],t),n)return!0;return!1}getFacesIntersectingAABB(e){let t=[];for(let n of this.faces.filter((e=>e.area>0)))e.intersects(n.aabb,this.tolerance)&&t.push(n);return t}removeEdgesInsidePolygon(e,t=100){let n=new dn;n.expands(e.map((e=>(new Ut).fromArray(e))));let l=e.map((e=>(new Ut).fromArray(e))),i=this.getFacesIntersectingAABB(n),a=[];for(let t of i){let n=t.vertexlist;for(let t=0;t<n.length;t++){let i=n[t],s=n[(t+1)%n.length];if(!In(l,i,this.tolerance)||!In(l,s,this.tolerance))continue;let o=0;[i,s].forEach((t=>{Mn(t.toArray(),e,this.tolerance)&&o++})),o>1||a.push([i,s])}}for(let e of a)J.bool(t)&&this.removeEdge(e[0].x,e[0].y,e[1].x,e[1].y);this.cleanupTrailingEdges()}insertPolygon(e,t=!0){let n=[],l=new dn;l.expands(e.map((e=>(new Ut).fromArray(e)))),l.expandByValue(this.tolerance);let i=this.getFacesIntersectingAABB(l),a=new Set;for(let e of i){let t=e.vertexlist;for(let e=0;e<t.length;e++){let n=t[e],l=t[(e+1)%t.length],i=this.findHedge(n.x,n.y,l.x,l.y);a.has(i.twin)||a.add(i)}}for(let t of e)n.push({type:"addVertex",data:{x:t[0],y:t[1]}});for(let l of a){let i=[];e:for(let a=0;a<(t?e.length:e.length-1);a++){let t=[new Ut(...e[a]),new Ut(...e[(a+1)%e.length])],s=l.intersectWithLineSegment(t);if(s.type==Wn.intersecting){for(let e of i)if(e.isEqualTo(s.point))continue e;n.push({type:"addVertex",data:{x:s.point.x,y:s.point.y}})}}}for(let l=0;l<(t?e.length:e.length-1);l++){let t=[e[l],e[(l+1)%e.length]];n.push({type:"addEdge",data:{from:{x:t[0][0],y:t[0][1]},to:{x:t[1][0],y:t[1][1]}}})}this.executeAddOperations(n)}splitFaceByPolyLine(e,t,n=!1,l=!1,i=!1){const a=(e,t,n,l)=>{const i=[.5,.25,.75];for(let a of i){let i=e.lerp(t,a);if(n.containsPoint(i)&&!n.isPointOnBoundary(i,l))return!0}return!1},s=(e,t,n,l)=>{let i=[.25,.5,.75],a=0;for(let s of i){let i=e.lerp(t,s);if(n.isPointOnBoundary(i,l)&&(a++,a>=2))return!0}return a>=2};let o=[],r=[],c=!1,d=0;if(n){let n=t.findIndex((t=>!e.containsPoint(new Ut(...t))||e.isPointOnBoundary(new Ut(...t),this.tolerance)));if(!(n>=0))return!1;t=t.slice(n).concat(t.slice(0,n))}const u=n?t.length:t.length-1;for(let n=0;n<u;n++){let l=new Ut(...t[n]),i=new Ut(...t[(n+1)%t.length]),u=[l,i],h=e.intersectWithLineSeg(u);d+=h.length;let m=[l,...h.map((e=>e.point)),i];m=Tn(l,i,m,!0,this.tolerance);for(let t=0;t<m.length-1;t++){let n=m[t],l=m[t+1];a(n,l,e,this.tolerance)&&!s(n,l,e,this.tolerance)?(c||(r=[n],c=!0),r.push(l)):c&&(o.push(r),r=[],c=!1)}}if(!n&&c&&r.length>1&&o.push(r),l||(o=o.filter((t=>{let n=t[Math.floor(t.length/2)].lerp(t[Math.ceil(t.length/2)],.5);return e.containsPoint(n)}))),o.length>1&&i){let e=null;for(let t of o){let l=0;for(let e=0;e<(n?t.length:t.length-1);e++)l+=t[e].distanceTo(t[(e+1)%t.length]);(!e||l>e.length)&&(e={length:l,line:t})}if(!e)return!1;o=[e.line]}if(0===o.length)return!1;if(l)return{lines:o,intersectionCount:d};let h=[];for(let e of o)for(let t of e)h.push({type:"addVertex",data:{x:t.x,y:t.y}});for(let e of o)for(let t=0;t<e.length-1;t++)h.push({type:"addEdge",data:{from:{x:e[t].x,y:e[t].y},to:{x:e[t+1].x,y:e[t+1].y}}});return this.executeAddOperations(h),!0}executeAddOperations(e){const t=e.filter((e=>"addVertex"===e.type)),n=e.filter((e=>"addEdge"===e.type));let l=[];for(const e of n){let t=new dn,n=new Ut(e.data.from.x,e.data.from.y),i=new Ut(e.data.to.x,e.data.to.y);t.expands([n,i]),t.expandByValue(this.tolerance);let a=new Set;for(let e of this.hedges){let l=e.getAABB();if(l.expandByValue(this.tolerance),l.intersects(t)){let t=e.intersectWithLineSegment([n,i]);t.type==Wn.intersecting&&(a.add(t.point),this.findVertex(t.point.x,t.point.y)||this.splitEdge(e.origin.x,e.origin.y,e.twin.origin.x,e.twin.origin.y,t.point.x,t.point.y))}}if(a.size>1){let e=Tn(n,i,[n,...a,i],!0,this.tolerance);for(let t=0;t<e.length-1;t++)l.push({type:"addEdge",data:{from:{x:e[t].x,y:e[t].y},to:{x:e[t+1].x,y:e[t+1].y}}})}else l.push(e)}for(const e of t){let{x:t,y:n}=e.data;if(!this.findVertex(t,n)){let e=!1;for(let l of this.hedges){let i=l.getAABB();i.expandByValue(this.tolerance),i.containsPoint(new Ut(t,n))&&!this.findVertex(t,n)&&zn([t,n],[l.origin.toArray(),l.twin.origin.toArray()])&&(e=!1!==this.splitEdge(l.origin.x,l.origin.y,l.twin.origin.x,l.twin.origin.y,t,n))}!e&&this.addVertex(t,n)}}for(const e of l.filter((e=>"addEdge"===e.type))){let{from:t,to:n}=e.data,l=this.findVertex(t.x,t.y),i=this.findVertex(n.x,n.y);if(l&&i){let e=new Set;e.add(l);let t=new dn;t.expands([l,i]),t.expandByValue(this.tolerance);for(let n of this.verticesInBB(t))zn(n.toArray(),[l.toArray(),i.toArray()])&&e.add(n);e.add(i);let n=Tn(l,i,Array.from(e),!0);for(let e=0;e<n.length-1;e++)this.findHedge(n[e].x,n[e].y,n[e+1].x,n[e+1].y)||this.addEdge(n[e].x,n[e].y,n[e+1].x,n[e+1].y)}}}cleanupDegenerateHoles(){let e=new Set;this.faces.forEach((t=>{for(let n of this.faces)t!=n&&t.aabb.containsBB(n.aabb)&&t.vertexlist.every((e=>n.containsPoint(e)))&&n.hedges.forEach((t=>{t.face==n&&e.add(t)}))})),this.faces.filter((e=>e.area>0)).forEach((t=>{t.holes.forEach((n=>{n.hedges.forEach((n=>{n.face==t&&e.add(n)}))}))}));for(const t of e)t.origin&&t.twin.origin&&this.removeEdge(t.origin.x,t.origin.y,t.twin.origin.x,t.twin.origin.y)}cleanupTrailingEdges(){this.hedges.forEach((e=>{e.face==e.twin.face&&this.removeEdge(e.origin.x,e.origin.y,e.twin.origin.x,e.twin.origin.y)}))}}function Rn(e,t,n=g){let[l,i]=e,[a,o]=t;const r=i[0]-l[0],c=i[1]-l[1],u=o[0]-a[0],h=o[1]-a[1];if(s(r*h-c*u)>n)return!1;const m=s(r*(l[1]-a[1])-(l[0]-a[0])*c),p=d(r*r+c*c);return!(p<n)&&m/p<n}function Tn(e,t,n,l=!1,i=g){const a=t.x-e.x,s=t.y-e.y;let o=a*a+s*s;if(o<i)return n;const r=1/o,c=n.map((t=>{const n=((t.x-e.x)*a+(t.y-e.y)*s)*r;return{point:t,t:Math.max(0,Math.min(1,n))}}));c.sort(((t,n)=>{const l=t.t-n.t;return Math.abs(l)>i?l:(t.point.x-e.x)**2+(t.point.y-e.y)**2-((n.point.x-e.x)**2+(n.point.y-e.y)**2)}));let d=c.map((e=>e.point));return l&&(d=function(e,t){const n=[],l=new Map;for(const i of e){const e=`${Math.round(i.x/t)},${Math.round(i.y/t)}`;l.has(e)||(l.set(e,!0),n.push(i))}return n}(d,i)),d}function Mn(e,t,n=g){for(let l=0;l<t.length;l++){const i=t[l],a=t[(l+1)%t.length],s=o(i[0],a[0])-n,c=r(i[0],a[0])+n,d=o(i[1],a[1])+-n,u=r(i[1],a[1])+n;if(e[0]>=s&&e[0]<=c&&e[1]>=d&&e[1]<=u&&Yn(e,i,a)<=n*n)return!0}return!1}function zn(e,t,n=g){const[l,i]=t,a=(e[1]-l[1])*(i[0]-l[0])-(e[0]-l[0])*(i[1]-l[1]);if(Math.abs(a)>n)return!1;const s=(e[0]-l[0])*(i[0]-l[0])+(e[1]-l[1])*(i[1]-l[1]);return!(s<-n||s-((i[0]-l[0])*(i[0]-l[0])+(i[1]-l[1])*(i[1]-l[1]))>n)}function Yn(e,t,n){const l=n[0]-t[0],i=n[1]-t[1],a=l*l+i*i;if(a<1e-14){const n=e[0]-t[0],l=e[1]-t[1];return n*n+l*l}let s=((e[0]-t[0])*l+(e[1]-t[1])*i)/a;s=Math.max(0,Math.min(1,s));const o=t[0]+s*l,r=t[1]+s*i,c=e[0]-o,d=e[1]-r;return c*c+d*d}let Pn=0;class Fn{_dcel;id=Pn++;changeIndex=0;wedge=null;_area=0;_areaDirty=!0;_vertexlist=[];_vertexlistDirty=!0;_centerDirty=!0;_hedges=[];_hedgesDirty=!0;_center=null;_hasInsertedIntoPQ=!1;_holes=[];_holesDirty=!0;_aabb=null;_aabbDirty=!0;constructor(e){this._dcel=e}get area(){return this._areaDirty&&(this._area=Un(this.vertexlist),this._areaDirty=!1),this._area}get areaExceptHoles(){const e=this.holes;let t=this.area;for(let n=0,l=e.length;n<l;n++)t+=e[n].area;return t}get internal(){return this.area>Kn}get external(){return this.area<=Kn}get hedges(){if(this._hedgesDirty){const e=[];let t=this.wedge,n=0;const l=1e6;for(e.push(t);t.nexthedge!==this.wedge&&n<l;)t=t.nexthedge,e.push(t),n++;if(n>=l)throw Error("Face vertex list is too long");this._hedges=e,this._hedgesDirty=!1}return this._hedges}get center(){if(this._centerDirty){const e=this.vertexlist;let t=0,n=0,l=0;for(let i=0;i<e.length;i++){const a=e[i].x,s=e[i].y,o=e[(i+1)%e.length].x,r=e[(i+1)%e.length].y,c=a*r-s*o;t+=c,n+=(a+o)*c,l+=(s+r)*c}t*=.5,n/=6*t,l/=6*t,this._center=new Ut(n,l),this._centerDirty=!1}return this._center}get vertexlist(){return this._vertexlistDirty&&this.cleanVertexList(),this._vertexlist}cleanVertexList(){if(!this._vertexlistDirty)return;let e=this.wedge;const t=this._vertexlist;t.length=0;let n=0;const l=1e6;for(t.push(e.origin);e.nexthedge!==this.wedge&&n<l;)e=e.nexthedge,t.push(e.origin),n++;if(n>=l)throw Error("Face vertex list is too long");this._vertexlistDirty=!1}get holes(){if(this._holesDirty&&(this._holesDirty=!1,this._holes.length=0,this.internal)){const e=this._dcel.faces;for(let t=0,n=e.length;t<n;t++)this._tryAddHole(e[t])}return this._holes}get aabb(){return this._aabb||(this._aabb=new dn),this._aabbDirty&&(this._aabb.reset(),this._aabb.expands(this.vertexlist),this._aabbDirty=!1),this._aabb}equals(e){const t=this.vertexlist,n=e.vertexlist;if(t.length!==n.length)return!1;const l=t.length;for(let e=0;e<l;e++)for(let i=0;i<l&&t[i]===n[(e+i)%l];i++)if(i===l-1)return!0;return!1}findNearestEdge(e){return function(e,t){const n=Dn(e);let l=[e[0],e[1]],i=1e10,a=-1/0,s=null;for(let o=0;o<e.length;o++){const r=[e[o],e[(o+1)%e.length]],{distance:c,projection:d}=On(t,r[0],r[1]),u={x:r[1].x-r[0].x,y:r[1].y-r[0].y};let h={x:-u.y,y:u.x},m={x:(r[0].x+r[1].x)/2-n.x,y:(r[0].y+r[1].y)/2-n.y};h.x*m.x+h.y*m.y<0&&(h={x:u.y,y:-u.x});const p={x:t.x-(r[0].x+r[1].x)/2,y:t.y-(r[0].y+r[1].y)/2},b=h.x*p.x+h.y*p.y;(c<i||c===i&&b>a)&&b>0&&(i=c,l=r,a=b,s=d)}return{edge:l,distance:i,edgePoint:s}}(this.vertexlist,e)}containsPoint(e){return!(!this.aabb.containsPoint(e)||!In(this.vertexlist,e))}isPointOnBoundary(e,t=Kn){let n=this.vertexlist.map((e=>e.toArray()));return!!Mn(e.toArray(),n,t)}intersectWithPolyLine(e,t=!1){let n=[];const l=t?e.length:e.length-1;for(let i=0;i<l;i++){const l=t?(i+1)%e.length:i+1,a=[e[i],e[l]];n.push(...this.intersectWithLineSeg(a))}return n}intersectWithLineSeg(e){const t=[],n=this.hedges.filter((e=>e.face==this)),l=(new dn).expands(e);for(let i of n){if(!i.getAABB().intersects(l))continue;const n=i.intersectWithLineSegment(e);n.type===Wn.intersecting&&t.push({point:n.point,edge:[i.origin,i.twin.origin]})}return t}dirty(){this._areaDirty=!0,this._hedgesDirty=!0,this._centerDirty=!0,this._vertexlistDirty=!0,this._holesDirty=!0,this._aabbDirty=!0,this.changeIndex++}dispose(){this.wedge=null,this._vertexlist.length=0,this._holes.length=0,this._aabb=null,this._dcel=null}_tryAddHole(e){this._holesDirty||e.external&&this.area-Math.abs(e.area)>Kn&&this.aabb.containsPoints(e.vertexlist)&&Nn(this.vertexlist,e.vertexlist,Kn)&&this._holes.push(e)}}function Hn(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}function In(e,t,n=Kn){if(Mn([t.x,t.y],e.map((e=>e.toArray())),n))return!0;let l=0;for(let n=0;n<e.length;n++){const i=e[n],a=e[(n+1)%e.length];i.y<=t.y?a.y>t.y&&Hn(i,a,t)>0&&l++:a.y<=t.y&&Hn(i,a,t)<0&&l--}return 0!==l}function Nn(e,t,n=Kn){for(let l=0,i=t.length;l<i;l++)if(!In(e,t[l],n))return!1;return!0}function Un(e){if(e.length<3)return 0;let t=0;for(let n=0;n<e.length;n++){const l=(n+1)%e.length;t+=e[n].x*e[l].y-e[n].y*e[l].x}return.5*t}function Dn(e){let t=0,n=0;for(let l=0;l<e.length;l++)t+=e[l].x,n+=e[l].y;return new Ut(t/e.length,n/e.length)}function On(e,t,n,l=Kn){const i=(n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y);if(i<l)return{distance:e.distanceTo(t),projection:t};let a=((e.x-t.x)*(n.x-t.x)+(e.y-t.y)*(n.y-t.y))/i;a<-l?a=0:a>1+l&&(a=1);const s=new Ut(t.x+a*(n.x-t.x),t.y+a*(n.y-t.y));return{distance:e.distanceTo(s),projection:s}}function Bn(e,t,n=g){const[{x:l,y:i},{x:a,y:s}]=e,[{x:o,y:r},{x:c,y:d}]=t,u=(l-a)*(r-d)-(i-s)*(o-c);if(Math.abs(u)<n)return null;const h=((l-o)*(r-d)-(i-r)*(o-c))/u,m=((a-l)*(i-r)-(s-i)*(l-o))/u;return h>=-n&&h<=1+n&&m>=-n&&m<=1+n?new Ut(l+h*(a-l),i+h*(s-i)):null}function Qn(e,t){const n=[];for(let l=0;l<t.length;l++){const i=[t[l],t[(l+1)%t.length]],a=Bn(e,i);a&&n.push({point:a,edge:i})}return n}let jn=0;function Jn(){return jn++,jn}function An(e){let{boxCenter:t,perspectiveCenter:n,centerBoxMaskDimensions:l=[0,0],width:i,height:a,gThreshold:s=2.5,gMean:o=1,gStdDev:r=1.5}=e;n||(n=t);const[c,d]=t;let[u,h]=n;u=Ot(new Ut(u,h)).x,h=Ot(new Ut(u,h)).y;let m=[l[0]*Be.scale,l[1]*Be.scale];i=xe(i,Be.scale),a=xe(a,Be.scale);let p=[];const b=2*(i+a),g=b/Be.scale,f=b/g;let x=[[u-m[0],h-m[1]],[u+m[0],h-m[1]],[u+m[0],h+m[1]],[u-m[0],h+m[1]]],Z=0,y=0,G=0;for(let e=0;e<g;e++){if(G<i?(Z=c-i/2+G,y=d-a/2):G<i+a?(Z=c+i/2,y=d-a/2+(G-i)):G<2*i+a?(Z=c+i/2-(G-(i+a)),y=d+a/2):(Z=c-i/2,y=d+a/2-(G-(2*i+a))),J.gaussianBool(s,o,r)){let e=Qn([[u,h],[Z,y]].map((e=>new Ut(...e))),x.map((e=>new Ut(...e))));if(!e[0])continue;let t=[e[0].point.toArray(),[Z,y]];if(p.push(t),J.bool(0)){let e=J.int(1,3)*Be.scale;J.bool(50)&&(e*=-1);let n=[[t[0][0]+e,t[0][1]],[t[1][0]+e,t[1][1]]];p.push(n)}}G+=f}return p}function En({center:e,width:t,height:n,angle:a=0}){let[s,o]=e,r=t/2,c=n/2,d=[[s-r,o-c],[s+r,o-c],[s+r,o+c],[s-r,o+c]];return 0!==a&&(d=function(e,t,n){const a=n||function(e){const t=e.reduce(((e,t)=>[e[0]+t[0],e[1]+t[1]]),[0,0]);return[t[0]/e.length,t[1]/e.length]}(e),s=t*b/180;return e.map((e=>{const t=[e[0]-a[0],e[1]-a[1]],n=[t[0]*i(s)-t[1]*l(s),t[0]*l(s)+t[1]*i(s)];return[n[0]+a[0],n[1]+a[1]]}))}(d,a,e)),d}function _n(e){let{center:n,radius:l,startAngle:i=0,endAngle:a=180}=e,s=[],[o,r]=n;i=me(i),a=me(a);let c=t(l*Math.abs(a-i)*.125);for(let e=0;e<=c;e++){let t=i+e/c*(a-i),n=o+l*Math.cos(t),d=r+l*Math.sin(t);s.push([n,d])}let d=function(e){let t=0,n=0;for(let l=0;l<e.length;l++)t+=e[l][0],n+=e[l][1];return[t/e.length,n/e.length]}(s),u=[o-d[0],r-d[1]];return s=s.map((e=>[e[0]+u[0],e[1]+u[1]])),s}class qn{startX;startY;endX;endY;distances;constructor(e,t,n,l){this.startX=e,this.startY=t,this.endX=n,this.endY=l;const i=n-e+1,a=l-t+1;this.distances=Array(a).fill(null).map((()=>Array(i).fill(1/0)))}initializeWithEmptyCells(e,t){for(let e=0;e<this.distances.length;e++)for(let t=0;t<this.distances[0].length;t++)this.distances[e][t]=0;e.forEach((e=>{const[n,l]=t(e),i=n-this.startX,a=l-this.startY;i>=0&&a>=0&&i<this.distances[0].length&&a<this.distances.length&&(this.distances[a][i]=1/0)}));for(let e=0;e<this.distances.length;e++)this.distances[e][0]=0,this.distances[e][this.distances[0].length-1]=0;for(let e=0;e<this.distances[0].length;e++)this.distances[0][e]=0,this.distances[this.distances.length-1][e]=0;this.performJFA()}performJFA(){const e=this.distances.length,t=this.distances[0].length;let n=[];for(let l=0;l<e;l++)for(let e=0;e<t;e++)0===this.distances[l][e]&&n.push([e,l]);for(;n.length>0;){let e=n.length;for(let t=0;t<e;t++){const[e,t]=n.shift();this.checkAndUpdate(e,t,n)}}}checkAndUpdate(e,t,n){const l=[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]];for(const[i,a]of l){const l=e+i,s=t+a;l>=0&&l<this.distances[0].length&&s>=0&&s<this.distances.length&&this.distances[s][l]>this.distances[t][e]+1&&(this.distances[s][l]=this.distances[t][e]+1,n.push([l,s]))}}getDistance(e,t){const n=e-this.startX,l=t-this.startY;return n>=0&&l>=0&&n<this.distances[0].length&&l<this.distances.length?this.distances[l][n]:1/0}}var $n;!function(e){e.intersecting="INTERSECTING",e.contained="CONTAINED"}($n||($n={}));class el{cells=new Map;lines=new Map;lineMeta=new Map;distanceCalculator;nextLineId=0;cellSize;faceCellIndicesCache=new Map;aabbLineIntersectionCache=new Map;constructor(e,t){this.cellSize=e,t&&this.addLines(t)}getCellBounds(){let e=0,t=0,n=0,l=0;return this.cells.forEach(((i,a)=>{const[s,o]=this.getCellXYfromIndex(a);e=Math.min(e,s),t=Math.min(t,o),n=Math.max(n,s),l=Math.max(l,o)})),{width:n-e,height:l-t,minX:e,minY:t,maxX:n,maxY:l}}getCellIndex(e,t){return`${f(e)},${f(t)}`}getCellXYfromIndex(e){return e.split(",").map(Number)}getCellVertexFromIndex(e){let[t,n]=this.getCellXYfromIndex(e);return new Ut(t*this.cellSize,n*this.cellSize)}clear(){this.cells.clear(),this.lines.clear(),this.lineMeta.clear(),this.faceCellIndicesCache.clear(),this.aabbLineIntersectionCache.clear()}addLines(e){e.forEach((e=>this.addLine(e.line,e.meta)))}addLine(e,t){const n=this.nextLineId++;this.lines.set(n,e),this.lineMeta.set(n,t);let l=t.isClosed?e.length:e.length-1;for(let t=0;t<l;t++)this.addSegment(e[t],e[(t+1)%e.length],n);return this.aabbLineIntersectionCache.clear(),n}removeLineById(e){if(this.lines.get(e)){for(let t of this.cells.values())t.delete(e);this.lines.delete(e),this.lineMeta.delete(e),this.aabbLineIntersectionCache.clear()}}addSegment(e,t,n){let l,[i,a]=e,[o,r]=t,c=f(i/this.cellSize),d=f(a/this.cellSize),u=f(o/this.cellSize),h=f(r/this.cellSize),m=s(u-c),p=-s(h-d),b=c<u?1:-1,g=d<h?1:-1,x=m+p;for(;;){const e=this.getCellIndex(c,d);if(this.cells.has(e)||this.cells.set(e,new Set),this.cells.get(e).add(n),c===u&&d===h)break;l=2*x,l>=p&&(x+=p,c+=b),l<=m&&(x+=m,d+=g)}}getLinesIntersectingOrContainedWithinAABB(e){let t=new Set,n=f(e.minX/this.cellSize),l=f(e.maxX/this.cellSize),i=f(e.minY/this.cellSize),a=f(e.maxY/this.cellSize);for(let e=n;e<=l;e++)for(let n=i;n<=a;n++){const l=this.getCellIndex(e,n);this.cells.has(l)&&this.cells.get(l).forEach((e=>t.add(e)))}return Array.from(t).map((e=>({id:Jn(),line:this.lines.get(e),meta:this.lineMeta.get(e)})))}getAllLines(){return Array.from(this.lines).map((([e,t])=>({id:e,line:t,meta:this.lineMeta.get(e)})))}getCellsIntersectedByFace(e){const t=this.faceCellIndicesCache.get(e.id);if(t&&t.changeIndex===e.changeIndex)return t.cellIndices;const n=new Set,l=e.aabb,i=f(l.minX/this.cellSize),a=f(l.maxX/this.cellSize),s=f(l.minY/this.cellSize),o=f(l.maxY/this.cellSize);for(let t=i;t<=a;t++)for(let l=s;l<=o;l++){const i=new dn;i.expands([new Ut(t*this.cellSize,l*this.cellSize),new Ut((t+1)*this.cellSize,(l+1)*this.cellSize)]);for(let a of i.vertexList)if(e.containsPoint(a)){n.add(this.getCellIndex(t,l));break}}return this.faceCellIndicesCache.set(e.id,{changeIndex:e.changeIndex,cellIndices:n}),n}doesLineFullyIntersectFace(e,t){const n=this.lines.get(e),l=this.lineMeta.get(e);if(!n||!l)return!1;const i=t.hedges.map((e=>{let t=new dn;return t.expands([e.origin,e.nexthedge.origin]),{aabb:t,edge:e}})),a=[],s=l.isClosed?n.length:n.length-1;for(let e=0;e<s;e++){const t=new Ut(...n[e]),l=new Ut(...n[(e+1)%n.length]),s=l.x-t.x,o=l.y-t.y,r=s*s+o*o;let c=new dn;c.expands([t,l]);for(const{aabb:n,edge:d}of i){if(!n.intersects(c))continue;const i=d.intersectWithLineSegment([t,l]);if(i?.type===Wn.intersecting&&i.point){const n=((i.point.x-t.x)*s+(i.point.y-t.y)*o)/r;a.push(e+n)}}}a.sort(((e,t)=>e-t));const o=a.filter(((e,t)=>0===t||Math.abs(e-a[t-1])>g));if(o.length<2)return!1;const r=new Ut(...n[0]);let c=t.containsPoint(r)&&!t.isPointOnBoundary(r);for(let e=0;e<o.length-1;e++){c=!c;const l=o[e],i=o[e+1];if(l<g||i>s-g)continue;if(!c)continue;const a=(l+i)/2,r=Math.floor(a)%n.length,d=a-Math.floor(a),u=new Ut(...n[r]),h=new Ut(...n[(r+1)%n.length]),m=new Ut(u.x+(h.x-u.x)*d,u.y+(h.y-u.y)*d);if(t.containsPoint(m)&&!t.isPointOnBoundary(m))return!0}return!1}linesIntersectingAABB(e){const t=this.aabbLineIntersectionCache.get(e);if(t)return t;const n=new Set,l=f(e.minX/this.cellSize),i=f(e.maxX/this.cellSize),a=f(e.minY/this.cellSize),s=f(e.maxY/this.cellSize);for(let e=l;e<=i;e++)for(let t=a;t<=s;t++){const l=this.getCellIndex(e,t);this.cells.has(l)&&this.cells.get(l).forEach((e=>n.add(e)))}const o=[...n].map((e=>({constructionLine:{id:e,line:this.lines.get(e),meta:this.lineMeta.get(e)},intersectionType:$n.intersecting})));return this.aabbLineIntersectionCache.set(e,o),o}getLinesIntersectingFace(e,t=!0){const n=this.getCellsIntersectedByFace(e),l=new Set;for(const e of n){const t=this.cells.get(e);if(t)for(const e of t)l.add(e)}let i=Array.from(l);return t&&(i=i.filter((t=>this.doesLineFullyIntersectFace(t,e)))),i.map((e=>({constructionLine:{id:e,line:this.lines.get(e),meta:this.lineMeta.get(e)},intersectionType:$n.intersecting})))}getGridDistanceField(e=0,t=0){let{cellSize:n}=this;const l=new Set,i=new Set,a=[];let s=f(t/n),o=f((Y-2*t)/n),r=f(t/n),c=f((P-2*t)/n);for(let t=s;t<=o;t++)for(let n=r;n<=c;n++){const i=this.getCellIndex(t,n);(!this.cells.has(i)||this.cells.get(i)?.size<=e)&&l.add(i)}const d=(e,t)=>{const n=[e];for(;n.length>0;){const e=n.pop();if(!e||i.has(e)||!l.has(e))continue;i.add(e);const[a,s]=this.getCellXYfromIndex(e);t.indices.push(e);const o=[this.getCellIndex(a-1,s),this.getCellIndex(a+1,s),this.getCellIndex(a,s-1),this.getCellIndex(a,s+1)];for(const e of o)!i.has(e)&&l.has(e)&&n.push(e)}};l.forEach((e=>{if(!i.has(e)){const t={vertices:[],indices:[]};d(e,t),t.indices.length>1&&a.push(t)}}));let u=this.distanceCalculator||new qn(s,r,o,c);return u.initializeWithEmptyCells(l,this.getCellXYfromIndex.bind(this)),a.map((e=>{const t=new dn;let n=[];e.indices.forEach((e=>{const[t,l]=this.getCellXYfromIndex(e),i=u.getDistance(t,l);n.push([i,this.getCellVertexFromIndex(e)])}));let l=n.reduce(((e,t)=>e[0]>t[0]?e:t));return t.expands(n.map((([,e])=>e))),{aabb:t,cellCount:e.indices.length,maxDistance:l[0],cellsByDistance:n,indices:e.indices.map((e=>this.getCellVertexFromIndex(e)))}}))}}function tl(e){const[t,n,l]=e;return`oklch(${(100*(t||0)).toFixed(2)}% ${(n||0).toFixed(2)} ${(l||0).toFixed(2)})`}function nl(e){e.forEach((e=>{const[t,n,l]=e;tl(e)}))}function ll(e){const n=e.slice();for(let e=n.length-1;e>0;e--){const l=t(J.dec()*(e+1));[n[e],n[l]]=[n[l],n[e]]}return n}function il(e,t="right"){const n=e.slice();if("right"===t){const e=n.pop();void 0!==e&&n.unshift(e)}else if("left"===t){const e=n.shift();void 0!==e&&n.push(e)}return n}let al={};const sl=(e,t=5,n=0,l=Ge,i=[])=>{const a=`${e}-${n}-${t}`;if(al[a]?.min)return al[a];let s=0,o=-1/0,r=1/0,c=0,d=[],u=(t,i)=>{let a=l(yn(t,i,n,e));s+=a,c+=1,a>o&&(o=a),a<r&&(r=a),d.push(a)};if(i.length)for(let e of i)u(e.x,e.y);else for(let e=0;e<20*Be.countX;e+=Be.w/20)for(let t=0;t<20*Be.countY;t+=Be.h/20)u(e,t);let h={max:o,min:r,mean:s/c,indexValues:[],mostCommonIndex:0,leastCommonIndex:0};return d.map((e=>{let n=f(ye(e,h.min,h.max,0,t-1));h.indexValues[n]=h.indexValues[n]?h.indexValues[n]+1:1})),h.mostCommonIndex=h.indexValues.reduce(((e,t,n)=>t>h.indexValues[e]?n:e),0),h.leastCommonIndex=h.indexValues.reduce(((e,t,n)=>t<h.indexValues[e]?n:e),0),al[a]=
= clamp(\n (step(lineDistance, alphaSoftLineSpread) * alphaSoftLineNoise) * maxLineHardness,\n 0., .7);\n }\n \n\n float lineAlpha = max(alphaSoftLine, alphaHardLine) * segmentDistanceAlphaMult;\n \n accumulationValue = clamp(accumulationValue + (1.0 - accumulationValue) * lineAlpha * 0.1, 0., 5.);\n \n alpha = clamp(1.0 - (1.0 - alpha) * (1.0 - lineAlpha * alphaIncrement), 0., 1.);\n color.x = clamp(\n 1.0 - (1.0 - localColor.x) * (1.0 - lineAlpha * lightnessIncrement), \n originalColor.x - accumulationClamp.x, \n originalColor.x + accumulationClamp.x\n );\n if(!uDisableSaturationShift) {\n color.y = clamp(1.0 - (1.0 - localColor.y) * (1.0 - lineAlpha * chromaIncrement), \n originalColor.y - accumulationClamp.y, \n originalColor.y + accumulationClamp.y\n );\n }\n \n \n }\n\n if(alpha <= 0.) {\n return vec4(frameBuffer, 1.);\n }\n\n\n float brightnessNoiseInfluence = smoothstep(-1., 1., fbm(uv + uNoiseOffset, 2, 50., 0.9)) + 0.4;\n float brightnessNoise = smoothstep(0.1, 0.31, fbm(uv + uNoiseOffset, 2, 1800., 0.5)) * brightnessNoiseInfluence * 0.002;\n color.x += brightnessNoise;\n\n float alphaNoise2 = smoothstep(-1., 1., fbm(uv, 1, 1000., 0.1)) * 0.02;\n float alphaNoise = smoothstep(-0.6, 1., fbm(uv, 2, 1200., 0.1)) * 0.12;\n alpha -= (alphaNoise + alphaNoise2);\n alpha = clamp(alpha, 0., 1.);\n\n \n float colorBrightWobble = fbm(uv + uNoiseOffset, 2, 20., 0.9) * 0.001;\n float colorEase = (\n easeOut(smoothstep(.02, .0, sdf + colorBrightWobble), 1.) \n * (0.01 + (accumulationValue * 0.02))\n );\n\n float colorBrightNoise = smoothstep(-0.4, 0.4, fbm(uv + uNoiseOffset, 2, 700., 0.9));\n float darkenEdge = easeOut(smoothstep(.0035, .0, sdf - (colorBrightWobble * 4.)), 1.) \n * (0.06 + (accumulationValue * 0.02)) * colorBrightNoise;\n\n colorEase += darkenEdge;\n \n color.x -= colorEase;\n color.y += (colorEase * 0.4);\n\n color.x = clamp(color.x, 0., .84);\n color.y = clamp(color.y, 0., .4); \n\n // LIGHTING\n vec3 lightDir = normalize(vec3(.6f, 1.6f, 1.6f));\n vec3 lightColor = vec3(1.0f) * 1.7f;\n \n vec3 paperTextureNormals = calculateNormals(screenSpaceUV + msaaOffset, 0.0002 * tileScaleFactor.x, 4.);\n vec3 diffuse = calculateDiffuse(paperTextureNormals, lightDir, lightColor);\n\n vec3 colorRGB = OKLCHtoP3LRGB(color) * diffuse;\n vec3 colorMult = (frameBuffer * colorRGB) * diffuse;\n\n colorRGB = mix(frameBuffer, mix(colorMult, colorRGB * diffuse, clamp(0.9, 1., alpha + 0.3)), alpha);\n\n return vec4(colorRGB, 1.0);\n }\n\n void main() {\n const vec2 H2 = vec2(0.5698402909980532f, 0.7548776662466927f);\n vec2 px = 1.f / resolution;\n px *= 1.25;\n vec2 uv = vUv;\n\n \n // Check if this fragment is within the SDF\n vec2 uvOffset = lookupWarpSample(uv).xy;\n float texCheck = (texture(tPolyEdgeDistance, uv + uvOffset).r - 0.5) * 2.0;\n if(texCheck < -0.1) {\n discard;\n }\n\n vec3 frameBuffer = texture(tScreenBuffer, vUv).rgb;\n\n\n const float samples = 4.f;\n \n vec4 sumColour;\n vec2 d0 = vec2(randomNonDet(uv), randomNonDet(uv + 1.f));\n\n \n for(float i = 0.f; i < samples; i++) {\n vec2 d = (fract(i * H2 + d0) - .5f);\n\n vec2 localCoord = vUv + d * px;\n vec2 screenCoord = uTileOffset + localCoord * uTileSize;\n vec2 globalUV = screenCoord / resolution;\n\n \n vec4 sampleColor = render(globalUV, vUv, d * px, frameBuffer);\n sumColour += sampleColor;\n }\n \n vec4 averageColor = clamp(sumColour / samples, 0., 1.);\n \n outColor = averageColor;\n }\n `});let n=t.isShading?nn:ln;n.updatePolylines(t.lines,t.closedPolyOrLine);let l=tn.uniforms;re(tn),It.material=tn,l.tScreenBuffer.value=Ft.getReadBuffer().texture;let i=t.lineColor;if(l.uLineColor.value=Qt(i),l.uDisableSaturationShift.value=t.disableSaturationShift||!1,l.uLineWeight.value=t.lineWeight,l.uLineHardness.value=t.linePressure,l.uMaterialHardness.value=t.materialHardness||1,l.uIsShading.value=t.isShading||!1,l.tWarpTex.value=t.canWarp?Ht.displacementMapWarped.target.texture:Ht.displacementMap.target.texture,l.uNoiseOffset.value=new ie(...t.noiseOffset),l.uFaceIndex.value=an++,l.uLineWeight.value=t.lineWeight,l.uTaperingFadeIn.value=t.lineTapering.fade.in.enabled?t.lineTapering.fade.in.length:0,l.uTaperingFadeOut.value=t.lineTapering.fade.out.enabled?t.lineTapering.fade.out.length:0,l.uTaperingScaleIn.value=t.lineTapering.scale.in.enabled?t.lineTapering.scale.in.length:0,l.uTaperingScaleOut.value=t.lineTapering.scale.out.enabled?t.lineTapering.scale.out.length:0,l.uBrightness.value=t.lineBrightness||1,l.uEdgeSharpness.value=t.edgeSharpness||1,l.uAccumulationStrength.value=t.accumulationStrength||1,t?.fadeAtLineSegment){let e=_t(t.fadeAtLineSegment.segment);const n=l.uFadeAtLineSegmentVertices.value;n[0]=e[0][0],n[1]=e[0][1],n[2]=e[1][0],n[3]=e[1][1],l.uFadeAtLineSegmentDistance.value=t.fadeAtLineSegment.distance,l.uFadeAtLineSegmentStrength.value=t.fadeAtLineSegment.strength,l.uEnableFadeAtLineSegment.value=!0,tn.needsUpdate=!0}else l.uEnableFadeAtLineSegment.value=!1;if(!sn||on!==n){const{cellsWide:e,cellsHigh:t,cellSize:i}=n,{segmentDataTexture:a,segmentMetaDataTexture:s,segmentIndexTexture:o}=n.getTextures();l.uSegmentDataTex.value=a,l.uSegmentMetaDataTex.value=s,l.uSegmentIndexTex.value=o,l.tPolyLineGrid.value={width:e*i,height:t*i,cellSize:i},sn=!0}l.uIsClosedPoly.value=t.closedPolyOrLine,X.setRenderTarget(Ft.getWriteBuffer()),It.render(),Ft.copyAndSwapBuffers(),on=n}let cn=new e.Vector4;class dn{minX=1/0;minY=1/0;maxX=-1/0;maxY=-1/0;constructor(){}get width(){return this.maxX-this.minX}get height(){return this.maxY-this.minY}get center(){return new Ut((this.minX+this.maxX)/2,(this.minY+this.maxY)/2)}get vertexList(){return[new Ut(this.minX,this.minY),new Ut(this.maxX,this.minY),new Ut(this.maxX,this.maxY),new Ut(this.minX,this.maxY)]}get area(){return this.width*this.height}reset(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0}expand(e){this.minX=Math.min(e.x,this.minX),this.minY=Math.min(e.y,this.minY),this.maxX=Math.max(e.x,this.maxX),this.maxY=Math.max(e.y,this.maxY)}expands(e){for(let t=0,n=e.length;t<n;t++)this.expand(e[t]);return this}expandByPoint(e){return this.minX=Math.min(e[0],this.minX),this.minY=Math.min(e[1],this.minY),this.maxX=Math.max(e[0],this.maxX),this.maxY=Math.max(e[1],this.maxY),this}expandsByPoint(e){for(let t=0,n=e.length;t<n;t++)this.expandByPoint(e[t])}intersects(e,t=g){return!(e.maxX<this.minX-t||e.minX>this.maxX+t||e.maxY<this.minY-t||e.minY>this.maxY+t)}expandByValue(e){return this.minX-=e,this.minY-=e,this.maxX+=e,this.maxY+=e,this}containsPoint(e){return e.x<=this.maxX+g&&e.x>=this.minX-g&&e.y<=this.maxY+g&&e.y>=this.minY-g}distanceToPoint(e){const t=r(this.minX-e.x,0,e.x-this.maxX),n=r(this.minY-e.y,0,e.y-this.maxY);return d(t*t+n*n)}containsBB(e){return e.minX>=this.minX-g&&e.maxX<=this.maxX+g&&e.minY>=this.minY-g&&e.maxY<=this.maxY+g}containsPoints(e){for(let t=0,n=e.length;t<n;t++)if(!this.containsPoint(e[t]))return!1;return!0}size(){return{width:this.maxX-this.minX,height:this.maxY-this.minY}}}let un,hn=[];var mn,pn;function bn(l){un=un||new e.ShaderMaterial({uniforms:{resolution:{value:new e.Vector2(Q,j)},tPositions:{value:new e.DataTexture},uPositionsCount:{value:0},...ce()},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:le,fragmentShader:`\n precision highp float;\n\t\t\tprecision highp int;\n \n uniform highp sampler2D tPositions;\n uniform vec2 resolution;\n uniform int uPositionsCount;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n \n varying vec2 vUv;\n out vec4 outColor;\n\n ${ne}\n\n float pointLineSegSDF(vec2 p, vec2 a, vec2 b) {\n vec2 pa = p - a;\n vec2 ba = b - a;\n float t = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);\n return length(pa - ba * t);\n }\n \n bool isIntersecting(vec2 point, vec2 p1, vec2 p2) {\n if(p1.y == p2.y) {\n return false;\n }\n \n if(p1.y > point.y && p2.y > point.y) {\n return false;\n }\n \n if(p1.y < point.y && p2.y < point.y) {\n return false;\n }\n \n float intersectionX = p1.x + (point.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y);\n return intersectionX > point.x;\n }\n\n vec2 fetchVertex(int vertexIndex) {\n int textureWidth = textureSize(tPositions, 0).x;\n int x = vertexIndex % textureWidth;\n int y = vertexIndex / textureWidth;\n return texelFetch(tPositions, ivec2(x, y), 0).rg;\n }\n \n float polyDistanceSDF(vec2 uv) {\n float minDist = 1e20;\n int intersections = 0;\n \n for(int i = 0; i < uPositionsCount; i++) {\n vec2 vertex1 = fetchVertex(i) / resolution.xy;\n vec2 vertex2 = fetchVertex((i + 1) % uPositionsCount) / resolution.xy;\n \n minDist = min(minDist, pointLineSegSDF(uv, vertex1, vertex2));\n \n if(isIntersecting(uv, vertex1, vertex2)) {\n intersections++;\n }\n }\n return float(intersections % 2 == 1 ? minDist : -minDist);\n // return float(intersections % 2 == 1 ? minDist : 1.5);\n }\n \n vec4 render(vec2 uv) {\n float dist = polyDistanceSDF(uv);\n return vec4(dist) * 0.5 + .5;\n }\n \n\n void main() {\n // A pseudo-random distribution for multi-sample\n const vec2 H2 = vec2(0.56984029, 0.75487766);\n // We do sub-pixel offsets relative to tile size, \n // because each tile is scaled to fill the entire local canvas\n vec2 px = 1.0 / resolution.xy;\n px *= 1.25;\n\n // We'll accumulate color across multiple samples\n const float samples = 4.0;\n vec4 sumColour = vec4(0.0);\n \n // Vary the random offset per pixel\n vec2 d0 = vec2(randomNonDet(vUv), randomNonDet(vUv + 1.0));\n\n for (float i = 0.0; i < samples; i++) {\n vec2 d = fract(i * H2 + d0) - 0.5;\n // localCoord in [0..1] in the local canvas\n vec2 sampleCoord = vUv + d * px;\n\n // Now map that to the large “full” coordinate space \n // subregion given by uTileOffset..uTileOffset+uTileSize\n vec2 screenCoord = uTileOffset + sampleCoord * uTileSize;\n\n // Next convert to [0..1] over the entire original geometry\n vec2 globalUV = screenCoord / resolution;\n\n vec4 sampleColor = render(globalUV);\n sumColour += sampleColor;\n }\n\n vec4 finalColor = clamp(sumColour / samples, 0.0, 1.0);\n outColor = finalColor;\n }\n `});let i=_t(l.polygon);un.uniforms.uPositionsCount.value=i.length;let a=function(t){const l=t.flat(),i=l.length/2,a=o(C,i),s=n(i/C),r=new Float32Array(a*s*2);for(let e=0;e<i;e++){const t=2*e;r[t]=l[t]||0,r[t+1]=l[t+1]||0}let c=new e.DataTexture(r,a,s,e.RGFormat,e.FloatType);return c.needsUpdate=!0,{texture:c,width:a,height:s}}(i);un.uniforms.tPositions.value=a.texture,re(un),It.material=un,X.setRenderTarget(Ht.polyEdgeDistance.target),X.setClearColor(1,0),X.clear();let s=oe();var c;((e,l=5)=>{l/=D,X.setScissorTest(!0),X.setScissor(((e,l=5)=>{let i=l*D,a=o(...e.map((e=>e.x)))-i,s=r(...e.map((e=>e.x)))+i,c=o(...e.map((e=>e.y)))-i,d=r(...e.map((e=>e.y)))+i,u=s-a,h=d-c;return cn.set(Ze(t(a),0,Q),Ze(t(j-d),0,j),n(o(u,Q)),n(o(h,j))).divideScalar(U).round()})(e,l))})((c=l.polygon.map((e=>new ie(e.x,e.y))),c.map((e=>e.clone().multiplyScalar(D)))).map((e=>(e.x=t((e.x-s.xOff)*(Q/s.width)),e.y=n((e.y-s.yOff)*(j/s.height)),e))),n(10*D*(Q/s.width))),It.render(),X.setScissorTest(!1)}!function(e){e[e.constructionLine=0]="constructionLine",e[e.detail=1]="detail",e[e.foreground=2]="foreground",e[e.background=3]="background",e[e.shadow=4]="shadow",e[e.walker=5]="walker",e[e.overlay=6]="overlay",e[e.overlayOutline=7]="overlayOutline"}(mn||(mn={})),function(e){e[e.regular=0]="regular",e[e.warped=1]="warped"}(pn||(pn={}));const gn=4095,fn=e=>.5*(1-i(e*b));let xn;function Zn(e){xn=new Float32Array(4096);for(let e=0;e<4096;e++)xn[e]=J.dec()}let yn=(e,n,l=0,i=5,a=0,s=1)=>fe(function(e,n=0,l=0){xn||Zn(),e<0&&(e=-e),n<0&&(n=-n),l<0&&(l=-l);let i,a,s,o,r,c=t(e),d=t(n),u=t(l),h=e-c,m=n-d,p=l-u,b=0,g=.5;for(let e=0;e<3;e++){let e=c+(d<<4)+(u<<8);i=fn(h),a=fn(m),s=xn[e&gn],s+=i*(xn[e+1&gn]-s),o=xn[e+16&gn],o+=i*(xn[e+16+1&gn]-o),s+=a*(o-s),e+=256,o=xn[e&gn],o+=i*(xn[e+1&gn]-o),r=xn[e+16&gn],r+=i*(xn[e+16+1&gn]-r),o+=a*(r-o),s+=fn(p)*(o-s),b+=s*g,g*=.8,c<<=1,h*=2,d<<=1,m*=2,u<<=1,p*=2,h>=1&&(c++,h--),m>=1&&(d++,m--),p>=1&&(u++,p--)}return b}((e+100)/i,(n+100)/i,(l+100)/i),0,1,a,s);const Gn=g;var Wn;function vn(e,t,n=!1){if(0===t.length)return e;if(1===t.length)return t[0];let l,i=1/0,a=n?t.length:t.length-1;for(let n=0;n<a;n++){const a=t[n],s=t[(n+1)%t.length],o=Sn(e,a,s);o<i&&(i=o,l=[a,s])}return l?function(e,t,n){const[l,i]=t,[a,s]=n,[o,r]=e,c=a-l,d=s-i,u=c*c+d*d;if(u<Gn)return[l,i];let h=((o-l)*c+(r-i)*d)/u;return h<-1e-7?h=0:h>1+Gn&&(h=1),[l+h*c,i+h*d]}(e,...l):e}function Ln(e,t,n=!1){let l=1/0;const i=t.length,a=n?i:i-1;for(let n=0;n<a;n++){const a=Xn(e,t[n],n===i-1?t[0]:t[n+1]);if(a<Gn)return 0;l=Math.min(l,a)}return Math.sqrt(l)}function Sn(e,t,n){return d(Xn(e,t,n))}function Xn(e,t,n){const[l,i]=t,[a,s]=n,[o,r]=e,c=a-l,d=s-i,u=c*c+d*d;if(u<Gn){const e=o-l,t=r-i;return e*e+t*t}let h=((o-l)*c+(r-i)*d)/u;h<-1e-7?h=0:h>1+Gn&&(h=1);const m=o-(l+h*c),p=r-(i+h*d);return m*m+p*p}!function(e){e[e.intersecting=0]="intersecting",e[e.colinear=1]="colinear",e[e.parallel=2]="parallel"}(Wn||(Wn={}));let Cn=0;class Vn{v1;v2;id=Cn++;origin;angle;length;twin=null;nexthedge=null;prevhedge=null;face=null;constructor(e,t){this.v1=e,this.v2=t,this.id=Cn++,this.origin=t,this.angle=function(e,t){let n=t.x-e.x,l=t.y-e.y;const i=d(n*n+l*l);return l>0?u(n/i):2*b-u(n/i)}(e,t),this.length=d(a(t.x-e.x,2)+a(t.y-e.y,2))}dispose(){this.origin=null,this.twin=null,this.nexthedge=null,this.prevhedge=null,this.face=null}getAABB(){let e=new dn;return e.expands([this.origin,this.twin.origin]),e}intersectWithLineSegment([e,t]){return function(e,t,n,l){const{x:i,y:a}=e,{x:s,y:o}=t,{x:r,y:c}=n,{x:d,y:u}=l,h=(u-c)*(s-i)-(d-r)*(o-a),m=(d-r)*(a-c)-(u-c)*(i-r),p=(s-i)*(a-c)-(o-a)*(i-r);if(Math.abs(h)<Gn)return Math.abs(m)<Gn&&Math.abs(p)<Gn?{type:Wn.colinear,point:null,ua:0,ub:0}:{type:Wn.parallel,point:null,ua:0,ub:0};const b=m/h,g=p/h;return b>=-1e-7&&b<=1+Gn&&g>=-1e-7&&g<=1+Gn?{type:Wn.intersecting,point:new Ut(i+b*(s-i),a+b*(o-a)),ua:b,ub:g}:{type:null,point:null,ua:b,ub:g}}(this.origin,this.twin.origin,e,t)}}const Kn=g;class wn{tolerance;vertices=[];hedges=[];faces=[];vertexMap=new Map;constructor(e,t,n=Kn){this.tolerance=n,e&&t&&this.setDatas(e,t)}getVertexKey(e,t){const n=e/this.tolerance,l=t/this.tolerance;return`${Z(n,this.tolerance)},${Z(l,this.tolerance)}`}addVertex(e,t){const n=this.getVertexKey(e,t);let l=this.vertexMap.get(n);l||(l=[],this.vertexMap.set(n,l));for(const n of l)if(this.isClose(n.x,e)&&this.isClose(n.y,t))return n;const i=new Ut(e,t);return this.vertices.push(i),l.push(i),i}deleteVertex(e){const t=this.getVertexKey(e.x,e.y),n=this.vertexMap.get(t);if(n){const l=n.indexOf(e);l>-1&&(n.splice(l,1),0===n.length&&this.vertexMap.delete(t))}const l=this.vertices.indexOf(e);l>-1&&this.vertices.splice(l,1),e.dispose()}findVertex(e,t){const n=this.getVertexKey(e,t),l=this.vertexMap.get(n);if(l)for(const n of l)if(this.isClose(n.x,e)&&this.isClose(n.y,t))return n;return null}verticesInPoly(e){let t=e.map((e=>(new Ut).fromArray(e))),n=new dn;n.expands(t);let l=[],i=this.verticesInBB(n);for(let e of i)In(t,e)&&l.push(e);return l}verticesInBB(e){const t=[];for(let n of this.vertices)e.containsPoint(n)&&t.push(n);return t}setDatas(e,t){const{vertices:n,hedges:l,faces:i}=this;for(let t=0,n=e.length;t<n;t++){const n=e[t];this.addVertex(n[0],n[1])}for(let e=0,i=t.length;e<i;e++){const i=t[e],a=new Vn(n[i[0]],n[i[1]]),s=new Vn(n[i[1]],n[i[0]]);a.twin=s,s.twin=a,n[i[1]].hedgelist.push(a),n[i[0]].hedgelist.push(s),l.push(s),l.push(a)}for(let e=0,t=n.length;e<t;e++){const t=n[e];t.sortincident();const l=t.hedgelist.length;if(0!=l)if(l<2)t.hedgelist[0].prevhedge=t.hedgelist[0].twin,t.hedgelist[0].twin.nexthedge=t.hedgelist[0];else{for(let e=0;e<l-1;e++)t.hedgelist[e].twin.nexthedge=t.hedgelist[e+1],t.hedgelist[e+1].prevhedge=t.hedgelist[e].twin;t.hedgelist[l-1].twin.nexthedge=t.hedgelist[0],t.hedgelist[0].prevhedge=t.hedgelist[l-1].twin}}const a=l.slice(0);let s=l.length;for(;s>0;){let e=a.pop();if(s-=1,null==e.face){const t=new Fn(this);for(t.wedge=e,t.wedge.face=t;e.nexthedge!==t.wedge;)e=e.nexthedge,e.face=t;i.push(t)}}}internalFaces(){const e=[],t=this.faces;for(let n=0,l=t.length;n<l;n++){const l=t[n];l.internal&&e.push(l)}return e}externalFaces(){const e=[],t=this.faces;for(let n=0,l=t.length;n<l;n++){const l=t[n];l.external&&e.push(l)}return e}dispose(){const{vertices:e,hedges:t,faces:n}=this;for(let t=0,n=e.length;t<n;t++)e[t].dispose();for(let e=0,n=t.length;e<n;e++)t[e].dispose();for(let e=0,t=n.length;e<t;e++)n[e].dispose();e.length=0,t.length=0,n.length=0}isClose=(e,t)=>s(e-t)<this.tolerance;findHedge(e,t,n,l){const{isClose:i}=this,a=this.findVertex(e,t);if(a)for(const e of a.hedgelist){const t=e.twin.origin;if(i(t.x,n)&&i(t.y,l))return e}const s=this.findVertex(n,l);if(s)for(const n of s.hedgelist){const l=n.twin.origin;if(i(l.x,e)&&i(l.y,t))return n}return null}addEdge(e,t,n,l){const{vertices:i,hedges:a,faces:s}=this;let o=!1,r=!1,c=!1,d=this.findVertex(e,t);d||(d=this.addVertex(e,t),o=!0);let u=this.findVertex(n,l);u||(u=this.addVertex(n,l),r=!0);const h=new Vn(u,d);a.push(h),d.hedgelist.push(h),d.sortincident();const m=new Vn(d,u);if(a.push(m),u.hedgelist.push(m),u.sortincident(),h.twin=m,m.twin=h,o)h.prevhedge=m,m.nexthedge=h;else{const e=d.hedgelist.indexOf(h);let t,n;0===e?(t=d.hedgelist[d.hedgelist.length-1],n=d.hedgelist[(e+1)%d.hedgelist.length]):(t=d.hedgelist[e-1],n=d.hedgelist[(e+1)%d.hedgelist.length]),h.prevhedge=t.twin,t.twin.nexthedge=h,m.nexthedge=n,n.prevhedge=m}if(r)m.prevhedge=h,h.nexthedge=m;else{const e=u.hedgelist.indexOf(m);let t,n;0===e?(t=u.hedgelist[u.hedgelist.length-1],n=u.hedgelist[(e+1)%u.hedgelist.length]):(t=u.hedgelist[e-1],n=u.hedgelist[(e+1)%u.hedgelist.length]),m.prevhedge=t.twin,t.twin.nexthedge=m,h.nexthedge=n,n.prevhedge=h}const p=h.nexthedge,b=m.nexthedge;if(p.face){const e=s.indexOf(p.face);e>-1&&s.splice(e,1),p.face.dispose(),p.face.area<=this.tolerance&&(c=!0)}if(b.face){const e=s.indexOf(b.face);e>-1&&s.splice(e,1),b.face.dispose(),b.face.area<=this.tolerance&&(c=!0)}const g=new Fn(this);g.wedge=p;let f=new Fn(this);if(f.wedge=b,g.equals(f)&&(f.dispose(),f=null),g){let e=g.wedge;for(e.face=g;e.nexthedge!==g.wedge;)e=e.nexthedge,e.face=g;g.area<=this.tolerance&&(c=!0),s.push(g)}if(f){let e=f.wedge;for(e.face=f;e.nexthedge!==f.wedge;)e=e.nexthedge,e.face=f;f.area<=this.tolerance&&(c=!0),s.push(f)}if(c)for(let e=0,t=s.length;e<t;e++)s[e]._holesDirty=!0}removeEdge(e,t,n,l){const{vertices:i,hedges:a,faces:s}=this,o=this.findHedge(e,t,n,l);if(!o)return;const r=o.twin,c=o.nexthedge,d=r.nexthedge;let u,h=!0,m=!0,p=!1;if(u=a.indexOf(o),a.splice(u,1),u=a.indexOf(r),a.splice(u,1),u=s.indexOf(o.face),u>-1&&s.splice(u,1),o.face.dispose(),o.face.area<=this.tolerance&&(p=!0),u=s.indexOf(r.face),u>-1&&s.splice(u,1),r.face.dispose(),r.face.area<=this.tolerance&&(p=!0),u=o.origin.hedgelist.indexOf(o),o.origin.hedgelist.splice(u,1),o.origin.hedgelist.length>0){let e,t;0===u?(e=o.origin.hedgelist[o.origin.hedgelist.length-1],t=o.origin.hedgelist[u]):(e=o.origin.hedgelist[u-1],t=o.origin.hedgelist[u%o.origin.hedgelist.length]),t.prevhedge=e.twin,e.twin.nexthedge=t}else this.deleteVertex(o.origin),m=!1;if(u=r.origin.hedgelist.indexOf(r),r.origin.hedgelist.splice(u,1),r.origin.hedgelist.length>0){let e,t;0===u?(e=r.origin.hedgelist[r.origin.hedgelist.length-1],t=r.origin.hedgelist[u]):(e=r.origin.hedgelist[u-1],t=r.origin.hedgelist[u%r.origin.hedgelist.length]),t.prevhedge=e.twin,e.twin.nexthedge=t}else this.deleteVertex(r.origin),h=!1;o.dispose(),r.dispose();const b=h?new Fn(this):null;b&&(b.wedge=c);let g=m?new Fn(this):null;if(g&&(g.wedge=d),b&&g)try{b.equals(g)&&(g.dispose(),g=null)}catch{g=null}if(b){let e=b.wedge;for(e.face=b;e.nexthedge!==b.wedge;){if(e=e.nexthedge,!e.face)return;e.face=b}b.area<=this.tolerance&&(p=!0),s.push(b)}if(g){let e=g.wedge;for(e.face=g;e.nexthedge!==g.wedge;)e=e.nexthedge,e.face=g;g.area<=this.tolerance&&(p=!0),s.push(g)}if(p)for(let e=0,t=s.length;e<t;e++)s[e]._holesDirty=!0}splitEdge(e,t,n,l,i,a){const{vertices:s,hedges:o}=this;let r=this.findVertex(i,a),c=this.findHedge(e,t,n,l);if(!c)return!1;if(r)return!0;const d=c.twin;let u;const h=this.addVertex(i,a),m=new Vn(h,c.origin),p=new Vn(d.origin,h);o.push(m),o.push(p);const b=new Vn(h,d.origin),g=new Vn(c.origin,h);return o.push(b),o.push(g),c.face.wedge===c&&(c.face.wedge=m),c.face._vertexlistDirty=!0,m.face=c.face,p.face=c.face,d.face.wedge===d&&(d.face.wedge=b),d.face._vertexlistDirty=!0,b.face=d.face,g.face=d.face,m.nexthedge=p,p.prevhedge=m,b.nexthedge=g,g.prevhedge=b,m.prevhedge=c.prevhedge!==d?c.prevhedge:g,m.prevhedge.nexthedge=m,p.nexthedge=c.nexthedge!==d?c.nexthedge:b,p.nexthedge.prevhedge=p,b.prevhedge=d.prevhedge!==c?d.prevhedge:p,b.prevhedge.nexthedge=b,g.nexthedge=d.nexthedge!==c?d.nexthedge:m,g.nexthedge.prevhedge=g,m.twin=g,p.twin=b,b.twin=p,g.twin=m,h.hedgelist.push(p,g),u=c.origin.hedgelist.indexOf(c),c.origin.hedgelist.splice(u,1,m),u=d.origin.hedgelist.indexOf(d),d.origin.hedgelist.splice(u,1,b),c.dispose(),d.dispose(),u=o.indexOf(c),o.splice(u,1),u=o.indexOf(d),o.splice(u,1),{h1:m,h2:p}}intersectFaceWithPolyLine(e,t,n=!1,l=!1){let i=[],a=l?t.length:t.length-1;for(let l=0;l<a;l++){let a=[t[l],t[(l+1)%t.length]];if(i.push(...e.intersectWithLineSeg(a.map((e=>(new Ut).fromArray(e))))),n&&i.length>=2)break}return i}getFacesAtPoint(e){let t=[],n=new Ut(...e);for(let e of this.faces)e.aabb.containsPoint(n)&&e.containsPoint(n)&&t.push(e);return t}getFacesIntersectingPoly(e){let t=e.map((e=>(new Ut
his.cellsWide=t(Y/this.cellSize),this.cellsHigh=t(P/this.cellSize);const{cellsWide:l,cellsHigh:i}=this;this.segmentMetaDataTexture={texture:new e.DataTexture(new Float32Array(l*i*2),l,i,e.RGFormat,e.FloatType),width:l,height:i},this.segmentMetaDataTexture.texture.needsUpdate=!0,this.segmentIndexTexture={texture:new qt(n,n,e.RedFormat,e.FloatType,new Float32Array(n*n)),width:n,height:n},this.segmentIndexTexture.texture.setRenderer(X)}updatePolylines(e,t=!1){this.isClosed=t,this.polyLines=e,this.texturesInitialised||(this.initializeTextures(),this.texturesInitialised=!0),this.buildSegmentRecords(),this.buildSegmentCellIndex(),this.buildSegmentDataTextures()}buildSegmentRecords(){const e=this.polyLines.reduce(((e,t)=>{const n=this.isClosed?t.length:t.length-1;return n>0?e+n:e}),0);this._segmentRecords=new Float32Array(8*e);let t=0;this.polyLines.forEach(((e,n)=>{let l=0;for(let t=0;t<e.length-1;t++)l+=$t(e[t],e[t+1]);this.isClosed&&e.length>1&&(l+=$t(e[e.length-1],e[0]));let i=0;const a=this.isClosed?e.length:e.length-1;for(let s=0;s<a;s++){const a=e[s],o=e[(s+1)%e.length],r=$t(a,o);this._segmentRecords[t++]=a[0],this._segmentRecords[t++]=a[1],this._segmentRecords[t++]=o[0],this._segmentRecords[t++]=o[1],this._segmentRecords[t++]=n,this._segmentRecords[t++]=i,this._segmentRecords[t++]=i+r,this._segmentRecords[t++]=l,i+=r}}))}buildSegmentCellIndex(){const e=this.cellsWide*this.cellsHigh;this._cellCounts=new Float32Array(e),this._cellOffsets=new Float32Array(e);const n=this._segmentRecords.length/8;let l=0;for(let e=0;e<n;e++){const e=this._segmentRecords[l+0],n=this._segmentRecords[l+1],i=this._segmentRecords[l+2],a=this._segmentRecords[l+3];l+=8;const o=t(e/this.cellSize),r=t(n/this.cellSize),c=t(i/this.cellSize),d=t(a/this.cellSize);let u=s(c-o),h=s(d-r),m=o,p=r,b=1+u+h;const g=c>o?1:-1,f=d>r?1:-1;let x=u-h;for(u*=2,h*=2;b--;){if(m>=0&&m<this.cellsWide&&p>=0&&p<this.cellsHigh){const e=p*this.cellsWide+m;this._cellCounts[e]++}if(x>0)m+=g,x-=h;else if(x<0)p+=f,x+=u;else{if(m+=g,p+=f,x+=u-h,b--,b<0)break;if(m>=0&&m<this.cellsWide&&p>=0&&p<this.cellsHigh){const e=p*this.cellsWide+m;this._cellCounts[e]++}}}}let i=0;for(let t=0;t<e;t++){const e=this._cellCounts[t];this._cellOffsets[t]=i,i+=e}this._indexData=new Float32Array(i),l=0;for(let e=0;e<n;e++){const n=this._segmentRecords[l+0],i=this._segmentRecords[l+1],a=this._segmentRecords[l+2],o=this._segmentRecords[l+3];l+=8;const r=t(n/this.cellSize),c=t(i/this.cellSize),d=t(a/this.cellSize),u=t(o/this.cellSize);let h=s(d-r),m=s(u-c),p=r,b=c,g=1+h+m;const f=d>r?1:-1,x=u>c?1:-1;let Z=h-m;for(h*=2,m*=2;g--;){if(p>=0&&p<this.cellsWide&&b>=0&&b<this.cellsHigh){const t=b*this.cellsWide+p,n=this._cellOffsets[t];this._indexData[n]=e,this._cellOffsets[t]=n+1}if(Z>0)p+=f,Z-=m;else if(Z<0)b+=x,Z+=h;else{if(p+=f,b+=x,Z+=h-m,g--,g<0)break;if(p>=0&&p<this.cellsWide&&b>=0&&b<this.cellsHigh){const t=b*this.cellsWide+p,n=this._cellOffsets[t];this._indexData[n]=e,this._cellOffsets[t]=n+1}}}}}buildSegmentDataTextures(){const e=this.segmentDataTexture.texture.texture.image.data,t=this.segmentDataTexture.width,n=this.segmentDataTexture.height,l=this._segmentRecords.length/8,i=o(2*l,t*n);let a=0,s=0;for(let t=0;t<l&&!(2*t+1>=i);t++){const n=2*t*4,l=4*(2*t+1),i=this._segmentRecords[a+0],o=this._segmentRecords[a+1],r=this._segmentRecords[a+2],c=this._segmentRecords[a+3],d=this._segmentRecords[a+4],u=this._segmentRecords[a+5],h=this._segmentRecords[a+6],m=this._segmentRecords[a+7];e[n+0]=i,e[n+1]=o,e[n+2]=r,e[n+3]=c,e[l+0]=d,e[l+1]=u,e[l+2]=h,e[l+3]=m,a+=8,s+=8}this.segmentDataTexture.texture.uploadSubData(s);const r=this.segmentMetaDataTexture.texture.image.data,c=this.segmentMetaDataTexture.width*this.segmentMetaDataTexture.height;for(let e=0;e<c;e++){const t=this._cellCounts[e],n=this._cellOffsets[e]-t,l=2*e;r[l+0]=n,r[l+1]=t}this.segmentMetaDataTexture.texture.needsUpdate=!0;const d=this.segmentIndexTexture.texture.texture.image.data,u=d.length,h=Math.min(this._indexData.length,u);d.set(this._indexData.subarray(0,h)),this.segmentIndexTexture.texture.uploadSubData(this._indexData.length)}getTextures(){return{segmentMetaDataTexture:this.segmentMetaDataTexture.texture,segmentDataTexture:this.segmentDataTexture.texture.texture,segmentIndexTexture:this.segmentIndexTexture.texture.texture}}reset(){this._segmentRecords=new Float32Array(0),this._cellCounts=new Float32Array(0),this._cellOffsets=new Float32Array(0),this._indexData=new Float32Array(0)}dispose(){this.segmentDataTexture.texture.texture.dispose(),this.segmentMetaDataTexture.texture.dispose(),this.segmentIndexTexture.texture.texture.dispose()}}let tn,nn=new en(4),ln=new en(20),an=0,sn=!1,on=null;function rn(t){if(0===t.lines.length)return;tn=tn||new e.ShaderMaterial({uniforms:{resolution:{value:new e.Vector2(Q,j)},uInternalResolution:{value:new e.Vector2(Y,P)},uFaceIndex:{value:0},tPaperTexture:{value:Ht.paperTexture.target.texture},uSegmentDataTex:{value:null},uSegmentIndexTex:{value:null},uSegmentMetaDataTex:{value:null},uBrightness:{value:1},...ce(),uAccumulationStrength:{value:1},uEdgeSharpness:{value:1},uTaperingFadeIn:{value:0},uTaperingFadeOut:{value:0},uTaperingScaleIn:{value:0},uTaperingScaleOut:{value:0},uFadeAtLineSegmentVertices:{value:new Float32Array([0,0,0,0])},uFadeAtLineSegmentDistance:{value:0},uFadeAtLineSegmentStrength:{value:1},uEnableFadeAtLineSegment:{value:!1},uIsShading:{value:!0},uDisableSaturationShift:{value:!1},uIsClosedPoly:{value:!1},tScreenBuffer:{value:Ft.getReadBuffer().texture},tPolyEdgeDistance:{value:Ht.polyEdgeDistance.target.texture},uNoiseOffset:{value:new ie(0,0)},tWarpTex:{value:Ht.displacementMap.target.texture},uLineColor:{value:new e.Vector3(1,0,0)},uLineHardness:{value:1},uLineWeight:{value:1},uMaterialHardness:{value:1},uLighting:{value:{center:Ie.default,min:ge(Ie.default,Ie.min,Ie.influencesBrightnessMult),max:ge(Ie.default,Ie.max,Ie.influencesBrightnessMult)}},tPolyLineGrid:{value:{width:0,height:0,cellSize:0}}},vertexShader:le,glslVersion:e.GLSL3,fragmentShader:`\n precision highp float;\n precision highp int;\n\n uniform highp sampler2D tWarpTex;\n uniform highp sampler2D tScreenBuffer;\n uniform highp sampler2D tPaperTexture;\n uniform highp sampler2D tPolyEdgeDistance;\n\n uniform highp sampler2D uSegmentDataTex;\n uniform highp sampler2D uSegmentMetaDataTex;\n uniform highp sampler2D uSegmentIndexTex;\n\n struct TPolyLineGrid {\n float width;\n float height;\n float cellSize;\n };\n\n uniform TPolyLineGrid tPolyLineGrid;\n\n\n struct Lighting {\n float center;\n float min;\n float max;\n };\n\n uniform Lighting uLighting;\n \n // uniform int uPositionsCount;\n uniform bool uIsClosedPoly;\n \n uniform vec2 resolution;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n\n uniform vec2 uInternalResolution;\n uniform vec2 uNoiseOffset;\n uniform bool uIsShading;\n // uniform bool uBulge;\n\n uniform float uTaperingFadeIn;\n uniform float uTaperingFadeOut;\n uniform float uTaperingScaleIn;\n uniform float uTaperingScaleOut;\n\n uniform bool uEnableFadeAtLineSegment;\n uniform vec2 uFadeAtLineSegmentVertices[2];\n uniform float uFadeAtLineSegmentDistance;\n uniform float uFadeAtLineSegmentStrength;\n\n uniform float uBrightness;\n uniform float uEdgeSharpness;\n uniform float uAccumulationStrength;\n uniform float uMaterialHardness;\n uniform vec3 uLineColor;\n uniform float uLineHardness;\n uniform float uLineWeight;\n uniform float uFaceIndex;\n uniform bool uDisableSaturationShift;\n\n // Max number of lines to consider for this fragment\n const int MAX_LINE_COUNT = 64;\n\n in vec2 vUv;\n out vec4 outColor;\n\n ${Et}\n ${te}\n ${Vt}\n ${Ct}\n ${ee}\n ${ne}\n ${At}\n\n //-----------------------------------------\n \n\n vec2 pointLineSDFInfinite(vec2 p, vec2 a, vec2 b) {\n vec2 pa = p - a;\n vec2 ba = b - a;\n float t = dot(pa, ba) / dot(ba, ba);\n float dist = length(pa - ba * t);\n return vec2(dist, t);\n }\n\n // 1) Helper to fetch offset+count from segmentMetaDataTexture\n vec2 getSegmentMeta(ivec2 cellCoords) {\n // each pixel stores (offset, count)\n return texelFetch(uSegmentMetaDataTex, cellCoords, 0).rg;\n }\n \n ivec2 getCellCounts() {\n return ivec2(\n int(tPolyLineGrid.width / tPolyLineGrid.cellSize),\n int(tPolyLineGrid.height / tPolyLineGrid.cellSize)\n );\n }\n\n ivec2 getGridCoords(vec2 uv) {\n ivec2 cellCount = getCellCounts();\n \n // Flip Y so top-left is (0,0)\n float flippedY = 1.0 - uv.y;\n \n int x = int(floor(uv.x * float(cellCount.x)));\n int y = int(floor(flippedY * float(cellCount.y)));\n \n return ivec2(x, y);\n }\n\n\n // 2) Helper to read the segment ID from segmentIndexTexture\n int getSegmentID(int globalIndex) {\n ivec2 size = textureSize(uSegmentIndexTex, 0);\n // clamp the fetch\n globalIndex = clamp(globalIndex, 0, size.x*size.y - 1);\n int x = globalIndex % size.x;\n int y = globalIndex / size.x;\n return int(texelFetch(uSegmentIndexTex, ivec2(x,y), 0).r);\n }\n\n // 3) Helper to read the 2 texels for the given segment\n struct SegmentData {\n vec2 a; // x1,y1\n vec2 b; // x2,y2\n float lineIndex; \n float segStart;\n float segEnd;\n float totalLen;\n };\n\n SegmentData getSegmentData(int segmentID) {\n SegmentData seg;\n\n // each segment uses 2 RGBA texels = 8 floats\n // texel1 => (x1, y1, x2, y2)\n // texel2 => (lineIndex, segStartLen, segEndLen, totalLineLen)\n int texelIndex1 = segmentID * 2;\n int texelIndex2 = segmentID * 2 + 1;\n\n ivec2 size = textureSize(uSegmentDataTex, 0);\n\n // clamp fetch\n int maxTexels = size.x * size.y;\n texelIndex1 = clamp(texelIndex1, 0, maxTexels-1);\n texelIndex2 = clamp(texelIndex2, 0, maxTexels-1);\n\n // decode coordinates\n int x1 = texelIndex1 % size.x;\n int y1 = texelIndex1 / size.x;\n int x2 = texelIndex2 % size.x;\n int y2 = texelIndex2 / size.x;\n\n vec4 d1 = texelFetch(uSegmentDataTex, ivec2(x1,y1), 0);\n vec4 d2 = texelFetch(uSegmentDataTex, ivec2(x2,y2), 0);\n\n seg.a = d1.xy / uInternalResolution;\n seg.b = d1.zw / uInternalResolution;\n\n seg.a = vec2(seg.a.x, 1.0 - seg.a.y);\n seg.b = vec2(seg.b.x, 1.0 - seg.b.y);\n\n seg.lineIndex = d2.x;\n seg.segEnd = d2.z / uInternalResolution.x;\n seg.segStart = d2.y / uInternalResolution.x;\n seg.totalLen = d2.w / uInternalResolution.x; // scale to pixel space\n\n return seg;\n }\n\n vec2 pointLineSegSDF(vec2 p, vec2 a, vec2 b) {\n vec2 pa = p - a;\n vec2 ba = b - a;\n float t = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);\n float dist = length(pa - ba * t);\n return vec2(dist, t);\n }\n\n\n // This struct stores the final line-based result\n struct LineDistanceResult {\n float dist; // nearest distance for this line\n float lineT; // fraction along the entire line\n float lineIndex; // which line\n };\n \n const ivec2 offsets[9] = ivec2[](\n ivec2(-1,-1), ivec2(0,-1), ivec2(1,-1),\n ivec2(-1, 0), ivec2(0, 0), ivec2(1, 0),\n ivec2(-1, 1), ivec2(0, 1), ivec2(1, 1)\n );\n\n // This function will find the closest lines to the given uv coordinate\n void lineDistanceSDFSegments(\n vec2 uv,\n float distanceThreshold,\n out LineDistanceResult linesWithin[MAX_LINE_COUNT],\n out int linesCount\n ){\n linesCount = 0;\n \n // Keep track of each line's nearest distance\n float lineDistances[MAX_LINE_COUNT];\n float lineTvalues[MAX_LINE_COUNT];\n int lineIDs[MAX_LINE_COUNT];\n \n // Initialize with defaults\n for (int i = 0; i < MAX_LINE_COUNT; i++) {\n lineDistances[i] = 1e20;\n lineTvalues[i] = 0.0;\n lineIDs[i] = -1;\n }\n \n // Figure out the base cell coords from uv\n ivec2 baseCellCoords = getGridCoords(uv);\n ivec2 cellCount = getCellCounts();\n \n // For each of the 9 offsets, gather segments from neighboring cells.\n for (int c = 0; c < 9; c++) {\n ivec2 cellCoords = baseCellCoords + offsets[c];\n \n // clamp cellCoords to grid boundaries\n if(cellCoords.x < 0 || cellCoords.x >= cellCount.x) continue;\n if(cellCoords.y < 0 || cellCoords.y >= cellCount.y) continue;\n \n // 1) fetch offset+count from the segmentMetaDataTexture\n vec2 meta = getSegmentMeta(cellCoords);\n int segOffset = int(meta.r);\n int segCount = int(meta.g);\n \n // 2) read each segment\n for (int i = 0; i < 1024; i++) {\n if (i >= segCount) break;\n \n int segID = getSegmentID(segOffset + i);\n SegmentData seg = getSegmentData(segID);\n \n // compute distance to this segment\n vec2 dt = pointLineSegSDF(uv, seg.a, seg.b);\n float dist = dt.x;\n float localT = dt.y;\n \n float segLen = seg.segEnd - seg.segStart;\n float absoluteDistanceAlongLine = seg.segStart + localT * segLen;\n float fraction = (seg.totalLen > 0.0) ? (absoluteDistanceAlongLine / seg.totalLen) : 0.0;\n \n // if within threshold\n if (dist <= distanceThreshold) {\n int lineID = int(seg.lineIndex);\n \n // check if we already have that line\n int foundIndex = -1;\n for (int j = 0; j < MAX_LINE_COUNT; j++) {\n if (lineIDs[j] == lineID) {\n foundIndex = j;\n break;\n }\n }\n \n if (foundIndex == -1) {\n // new line\n for (int j = 0; j < MAX_LINE_COUNT; j++) {\n if (lineIDs[j] < 0) {\n lineIDs[j] = lineID;\n lineDistances[j] = dist;\n lineTvalues[j] = fraction;\n break;\n }\n }\n } else {\n // line already exists => keep closer distance\n if (dist < lineDistances[foundIndex]) {\n lineDistances[foundIndex] = dist;\n lineTvalues[foundIndex] = fraction;\n }\n }\n }\n }\n }\n \n // Final pass: gather valid lines into linesWithin\n int validCount = 0;\n for (int i = 0; i < MAX_LINE_COUNT; i++) {\n if (lineIDs[i] >= 0) {\n linesWithin[validCount].dist = lineDistances[i];\n linesWithin[validCount].lineT = lineTvalues[i];\n linesWithin[validCount].lineIndex = float(lineIDs[i]);\n validCount++;\n if (validCount >= MAX_LINE_COUNT) break;\n }\n }\n\n // Now 'validCount' lines are in linesWithin[0..validCount-1].\n // Sort them by dist ascending.\n for (int i = 0; i < MAX_LINE_COUNT - 1; i++) {\n // If 'i' >= validCount - 1, break\n if (i >= validCount - 1) break;\n\n for (int j = i + 1; j < MAX_LINE_COUNT; j++) {\n // If 'j' >= validCount, break\n if (j >= validCount) break;\n\n if (linesWithin[j].dist < linesWithin[i].dist) {\n // Swap\n LineDistanceResult tmp = linesWithin[i];\n linesWithin[i] = linesWithin[j];\n linesWithin[j] = tmp;\n }\n }\n }\n \n linesCount = validCount;\n }\n\n\n float easeOut(float t, float strength) {\n return 1.0 - pow(1.0 - t, strength);\n }\n\n vec4 render(vec2 uv, vec2 screenSpaceUV, vec2 msaaOffset, vec3 frameBuffer) {\n\n float scaleFactor = (1. / uInternalResolution.x);\n vec2 tileScaleFactor = resolution / uTileSize;\n \n \n vec2 uvWarp = lookupWarpSample(screenSpaceUV + msaaOffset).xy;\n vec2 ssLookupWarp = uvWarp * tileScaleFactor;\n\n uv += uvWarp;\n\n float sdf = (texture(tPolyEdgeDistance, screenSpaceUV + ssLookupWarp + msaaOffset).r - 0.5) * 2.0;\n\n \n vec3 color = uLineColor;\n float rampStart = 0.7;\n float rampEnd = 1.0;\n float lowValue = 0.015;\n float highValue = 0.06;\n\n float t = clamp((color.x - rampStart) / (rampEnd - rampStart), 0.0, 1.0);\n \n float accumulationClampMax = 0.15;\n float accumulationIncrement = mix(lowValue, highValue, smoothstep(rampStart, rampEnd, color.x));\n vec2 accumulationClamp = vec2(accumulationClampMax, accumulationClampMax * 0.4);\n float chromaIncrement = (accumulationIncrement * 0.4) * uAccumulationStrength;\n float lightnessIncrement = (-accumulationIncrement) * uAccumulationStrength;\n float alphaIncrement = uIsShading ? .95 : 1.5;\n \n if(uIsShading) {\n float colorShift = uBrightness - uLighting.center;\n float shiftFactor = (colorShift > 0. && color.x > 0.6) ? (1.0 - clamp(color.x / 0.82, 0., 1.)) : 1.0;\n float newMult = ((colorShift * 1.5 * shiftFactor) + 1.0);\n \n color.x *= newMult;\n \n color.x -= 0.0;\n color.y -= 0.025;\n \n color.x = clamp(color.x, 0., 0.82);\n }\n\n color.x = clamp(color.x, 0., .81);\n color.y = clamp(color.y, 0., .4);\n \n vec3 originalColor = color;\n\n // SHAPE SDF\n \n float alpha = 0.0;\n \n float segmentDistanceAlphaMult = 1.;\n\n if(uEnableFadeAtLineSegment) {\n vec2 fadeStartVert = uFadeAtLineSegmentVertices[0] / resolution.xy;\n vec2 fadeEndVert = uFadeAtLineSegmentVertices[1] / resolution.xy;\n float fadeDistance = uFadeAtLineSegmentDistance * scaleFactor;\n float fadeAlpha = pointLineSDFInfinite(uv, fadeStartVert, fadeEndVert).x;\n float fadeLerp = smoothstep(0., fadeDistance, fadeAlpha);\n fadeLerp = clamp(remap(fadeLerp, 0., 1., 1. - uFadeAtLineSegmentStrength, 1.), 0., 1.);\n segmentDistanceAlphaMult = fadeLerp;\n }\n\n float edgeSharpness = remap(uEdgeSharpness, 0., 1., -0.1, -0.0015);\n\n segmentDistanceAlphaMult *= smoothstep(edgeSharpness, -0.0, sdf);\n\n if(segmentDistanceAlphaMult <= 0.) {\n return vec4(frameBuffer, 1.);\n }\n\n\n float accumulationValue = 0.0;\n float lineSampleDistanceMax = scaleFactor * (uLineWeight * 2.);\n\n LineDistanceResult linesWithin[MAX_LINE_COUNT];\n int linesCount;\n lineDistanceSDFSegments(uv, lineSampleDistanceMax, linesWithin, linesCount);\n\n for(int i = 0; i < linesCount; i++) {\n vec3 localColor = color;\n \n float lineSDF = linesWithin[i].dist;\n float lineT = linesWithin[i].lineT;\n float lineIndex = linesWithin[i].lineIndex;\n\n float currentLineNoiseOffset = float(lineIndex) * 10.;\n\n // Line Tapering and Fade\n float fadeLineCap = 1.;\n float scaleLineCap = 1.;\n \n if(uTaperingFadeIn > 0. || uTaperingFadeOut > 0.) {\n float fadeWarp = abs(fbm(uv + uNoiseOffset + currentLineNoiseOffset, 1, 10., 0.9)) * 0.05;\n \n if(uTaperingFadeIn > 0.) {\n fadeLineCap = easeOut(smoothstep(0.0, (uTaperingFadeIn / 2.) - fadeWarp, lineT), 10.);\n }\n\n if(uTaperingFadeOut > 0.) {\n fadeLineCap *= easeOut(smoothstep(1., 1. - (uTaperingFadeOut / 2.) - fadeWarp, lineT), 10.);\n }\n }\n\n if(uTaperingScaleIn > 0. || uTaperingScaleOut > 0.) {\n float scaleWarp = abs(fbm(uv + uNoiseOffset + currentLineNoiseOffset, 1, 10., 0.9)) * 0.05;\n if(uTaperingScaleIn > 0.) {\n scaleLineCap = easeOut(smoothstep(0.0, (uTaperingScaleIn / 2.), lineT + scaleWarp), 1.);\n }\n\n if(uTaperingScaleOut > 0.) {\n scaleLineCap *= easeOut(smoothstep(1., 1. - (uTaperingScaleOut / 2.), lineT + scaleWarp), 1.);\n }\n }\n\n float lineHardness = uLineHardness * fadeLineCap;\n float lineWeight = uLineWeight;\n \n float lineDistanceMax = (scaleFactor * lineWeight) * scaleLineCap;\n float lineWeightWobble = fbm(uv + currentLineNoiseOffset, 3, 8., 0.6) * (lineDistanceMax / (uIsShading ? 2. : 2.));\n \n float lineWeightEdgeNoise = fbm(uv + uNoiseOffset + currentLineNoiseOffset, 3, 300., 0.54) * (lineDistanceMax / 10.);\n\n float lineDistance = (lineSDF + lineWeightWobble + lineWeightEdgeNoise); \n \n \n float lineFineNoise = clamp(\n smoothstep(0., 0.9, fbm(uv + currentLineNoiseOffset, 2, 700., 0.9) - 0.1) + remap(lineHardness, 1., 0., 1. - uMaterialHardness, 0.5),\n 0., 1.);\n\n float lineFineNoise2 = clamp(\n smoothstep(0., 0.9, fbm(uv, 1, 900., 0.9)) + remap(lineHardness, 1., 0., 0.01, 0.5),\n 0., (1. - uMaterialHardness) + .1);\n \n\n float alphaWobblePerLine = fbm(uNoiseOffset + currentLineNoiseOffset, 1, 300., 0.9) * 0.015;\n\n float lineColorWobble = 0.008;\n \n float lightnessWobblePerLine = ((fbm(uNoiseOffset + (currentLineNoiseOffset / 1.), 1, 1000., 0.9) + .5) / 2. ) * lineColorWobble;\n localColor.x += lightnessWobblePerLine;\n\n float saturationWobblePerLine = ((fbm(uNoiseOffset + (currentLineNoiseOffset / 1.1), 1, 1100., 0.9) + .5) / 2. ) * (lineColorWobble * 0.4);\n localColor.y += saturationWobblePerLine;\n \n float maxLineHardness = clamp(smoothstep(0., 1., lineHardness - alphaWobblePerLine), 0., 1.);\n\n float lineRolloff = 0.0001;\n float alphaHardLineSpread = lineDistanceMax * 1.;\n float hardLineSS = smoothstep(alphaHardLineSpread + lineRolloff, alphaHardLineSpread - lineRolloff, lineDistance);\n\n float alphaHardLine = clamp(\n (hardLineSS * (1. - lineFineNoise) * (1. - lineFineNoise2)) * maxLineHardness,\n 0., 1.);\n\n float alphaSoftLine = 0.;\n\n if(!uIsShading) {\n float alphaSoftLineNoise = clamp((fbm(uv + currentLineNoiseOffset, 1, 800., 0.9) - 0.3), 0., 1.);\n\n\n float alphaSoftLineSpread = lineDistanceMax * 1.5;\n float softLineSS = smoothstep(alphaSoftLineSpread + lineRolloff, alphaSoftLineSpread - lineRolloff, lineDistance);\n\n alphaSoftLine
m]:J.int(4,4),[ut.md]:J.int(4,4),[ut.lg]:J.int(4,4),default:2});Ae=be(Ae,{margin:c*Be.scale,HVariance:{min:-r,max:r,threshold:1,mean:1,stdDev:1},VVariance:{min:-r,max:r,threshold:1,mean:1,stdDev:1},circles:{count:5,minRadius:5,maxRadius:18},wobble:{enabled:!0,count:1e10,minLength:2,layers:4,multiLayers:1,gridDivisions:1,warpFreq:{min:800,max:2e3},offsetMultiplier:.6},perspectiveBox:{enabled:!0,threshold:4,mean:2,stdDev:8,firstFull:!0,count:1}}),tt={...tt,cropToMargin:!1,margin:6*Be.scale}},vt=new e.OrthographicCamera(-1,1,1,-1,0,1);class Lt extends e.BufferGeometry{constructor(){super(),this.setAttribute("position",new e.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new e.Float32BufferAttribute([0,2,0,0,2,0],2))}}const St=new Lt;class Xt{_mesh;constructor(t){this._mesh=new e.Mesh(St,t)}dispose(){this._mesh.geometry.dispose()}render(e=X){e.render(this._mesh,vt)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}let Ct="\n vec2 lookupWarpSample(const vec2 uv) {\n\n // vec2 offset = vec2(0.2);\n return ((texture(tWarpTex, uv).xy - 0.5) * 2.);\n }\n",Vt="\n float remap(float t, float a1, float b1, float a2, float b2) {\n return a2 + (b2 - a2) * ((t - a1) / (b1 - a1));\n }\n";function Kt(){return new e.ShaderMaterial({uniforms:{resolution:{value:new e.Vector2(Q,j)},noiseOffset:{value:new e.Vector2(ke[0],ke[1])},...ce(),wave:{value:{...$e}},uWarpEnabled:{value:!1},grid:{value:{...Be}}},depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:le,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform vec2 resolution;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n uniform vec2 noiseOffset;\n uniform bool uWarpEnabled;\n\n struct Wave {\n bool warpX;\n bool warpY;\n\n bool offAxisY;\n bool offAxisX;\n\n float warpXMult;\n float warpYMult;\n\n float displacementStrength;\n \n bool noiseMapEnabled;\n };\n \n uniform Wave wave;\n\n struct Grid {\n float countX;\n float countY;\n float marginX;\n float marginY;\n float w;\n float h;\n float scale;\n };\n\n uniform Grid grid;\n\n varying vec2 vUv;\n out vec4 outColor;\n\n // const float scale = 10.;\n\n #include <packing>\n\n ${ee}\n ${Vt}\n ${te}\n \n // Third compomnent is the intersection\n // const float PI2 = acos(-1.);\n \n float noiseLookup(vec2 uv, float freq) {\n float influence = fbm(uv + noiseOffset, 2, freq + 0.2, 0.8);\n return smoothstep(0., 1., abs(fbm(uv - influence, 2, freq, 0.5)));\n }\n\n// vec2 warpTextureSampleUv(const vec2 uv) {\n// // Center of the drop\n// vec2 center = vec2(0.5, 0.5);\n// // Spacing between each ripple (distance in UV space)\n// float ringSpacing = 0.1;\n\n// // Thickness of each ripple peak\n// float ringThickness = 0.01;\n\n// // Overall ripple strength\n// float amplitude = 0.05;\n\n// // Distance from UV to the center\n// float dist = distance(uv, center);\n\n// // We compute the ripple shape by creating rings around the center at multiples of ringSpacing\n// // - sector is how far dist is from the last multiple of ringSpacing\n// // - ringDist is how far we are from the center of that ring\n// float sector = mod(dist, ringSpacing);\n// float ringDist = abs(sector - (ringSpacing * 0.5));\n\n// // Create a peak shape at the ring center\n// // wave is 1.0 near the ring center and 0.0 outside\n// float wave = 1.0 - smoothstep(0.0, ringThickness, ringDist);\n\n// // Convert wave to displacement strength\n// float offsetStrength = wave * amplitude;\n\n// // Direction outward from the center\n// vec2 direction = normalize(uv - center);\n\n// return direction * offsetStrength;\n// }\n \n vec2 warpTextureSampleUv(const vec2 uv) {\n\n float PI = acos(-1.);\n float gridSize = grid.w / 1000.;\n float strength = gridSize * .2;\n float edgeFalloff = 1.;\n\n // strength *= 50.; \n\n vec2 warpSpread = vec2(1.) * .1;\n\n float aspectRatio = resolution.x / resolution.y;\n\n vec2 offsetUV = uv + (noiseOffset * 2.);\n\n offsetUV.x *= 1.;\n offsetUV.y *= 1.2;\n\n // float noiseMask = snoise2D(offsetUV / .2) ;\n // float noiseMask2 = snoise2D(offsetUV / .18);\n // float noiseWarped = snoise2D(vec2((offsetUV.x + 1.) / .1 * noiseMask2, uv.y / 1.2 * noiseMask));\n // float noiseWarped2 = snoise2D(vec2((offsetUV.x + .8) / .25 * noiseMask2, uv.y / 1.2 * noiseMask));\n \n float freq = 10.1;\n float warpedDivisor = .5;\n\n float noiseMaskMask = smoothstep(0.95, 1., fbm(offsetUV, 1, freq * 3., 0.5));\n float noiseMask = (fbm(offsetUV, 1, freq + 0.001, 0.5) + 0.01) - fbm(offsetUV, 1, freq, 0.5);\n noiseMask *= 50.;\n noiseMask *= clamp(abs(noiseMaskMask), .5, 1e6);\n // float direction = smoothstep(-1., 1., fbm(offsetUV, 2, freq * .1, 0.5));\n\n // float noiseY = fbm(offsetUV * .5, 2, freq, 0.1);\n // float noiseX = fbm(offsetUV * .5, 3, freq/2., 0.2);\n\n float epsilon = 0.01;\n\n\n\n\n float noiseWarpedCenter = noiseLookup(offsetUV , warpedDivisor);\n float noiseWarpedY = noiseLookup(offsetUV + vec2(epsilon, 0.), warpedDivisor);\n float noiseWarpedX = noiseLookup(offsetUV + vec2(0., epsilon), warpedDivisor);\n\n // float dFdx = (noiseWarpedX - noiseWarpedCenter) / epsilon;\n // float dFdy = (noiseWarpedY - noiseWarpedCenter) / epsilon;\n\n // vec2 gradient = vec2(dFdx, dFdy);\n // gradient = vec2(-gradient.y, gradient.x);\n \n // gradient = normalize(gradient);\n\n // float projection = dot(uv, gradient);\n // float wave = sin(projection * .1); \n // gradient = vec2(-gradient.y, gradient.x);\n // float noiseWarped2 = fbm(offsetUV + vec2(freq/2.) * vec2(1.) * warpedUV, 1, freq * .5, 0.1);\n \n\n // float nNoise = snoise2D(offsetUV * .5);\n // float result = ((noiseWarped * 1.f) * (noiseWarped2 * 1.f)) * noiseMask;\n // float noiseSwirl = noiseMask;\n // float result = noiseWarped1 * 2. * PI - (PI * .5);\n\n vec2 divergence = vec2(0.);\n // divergence += vec2(cos(result), sin(result));\n // divergence += (result * strength) * noiseMask;\n divergence += noiseWarpedCenter * strength * noiseMask;\n // divergence *= screenEdgeDist(uv, edgeFalloff);\n \n // float simpleWarp = fbm(offsetUV, 6, 600.6, .9);\n\n // divergence += simpleWarp * .0003;\n\n return vec2(divergence); \n }\n\n\n const float PI = acos(-1.);\n\n const float waveWarpDivisor = 1.;\n // const int waveNoiseMapEnabled = 0;\n\n \n\n vec2 waveUv(vec2 uv) {\n\n vec2 margins = vec2(grid.marginX / resolution.x, grid.marginY / resolution.y);\n float width = grid.w / resolution.x;\n\n float lookupRemap = noiseOffset.x;\n \n // float influence = clamp(snoise2D((uv + lookupRemap)), 0.f, 1.f);\n float influence = grid.countX * wave.displacementStrength;\n \n // if(wave.noiseMapEnabled == 1)\n // influence = .9f + (influence / 10.f);\n \n float strength = (width / (waveWarpDivisor * PI) - 2.f) * (width / grid.countX) * influence;\n float sinX = sin(wave.warpXMult * PI * ((uv.x / width) + margins.x) - PI /2.) * strength;\n float sinY = sin(wave.warpYMult * PI * ((uv.y / width) + margins.y) - PI /2.) * strength;\n \n vec2 result = vec2(0.);\n \n if(wave.warpX)\n result.x += sinX;\n \n if(wave.warpY)\n result.y += sinY;\n \n if(wave.offAxisY)\n result.y += sinX;\n \n if(wave.offAxisX)\n result.x += sinY;\n \n // result.y = sin(waveWarpXMult * PI * ((uv.x + margins.y) / width)) * strength;\n // result.x = sin(waveWarpYMult * PI * ((uv.x + margins.x) / width)) * strength;\n\n return result;\n }\n\n // vec2 calculatePerspectiveOffset(vec2 uv) {\n // // Store the original UV coordinates\n // vec2 originalUv = uv;\n \n // // Define perspective depth factors\n // float perspectiveStrength = .0; // Controls the overall perspective effect\n // float tiltX = -0.3; // Controls the leftward skew\n // float tiltY = 0.2; // Controls the backward tilt\n \n // // Shift UVs to the center of the texture\n // uv -= 0.5;\n \n // // Apply perspective transformation\n // float depth = 1.0 - perspectiveStrength * (tiltX * uv.x + tiltY * uv.y);\n // uv /= depth;\n \n // // Calculate the min and max bounds of the transformed UVs\n // vec2 minBounds = vec2(-0.5) / (1.0 - perspectiveStrength * vec2(-tiltX, -tiltY));\n // vec2 maxBounds = vec2(0.5) / (1.0 - perspectiveStrength * vec2(tiltX, tiltY));\n \n // // Normalize the UV coordinates to the [0, 1] range\n // uv = (uv - minBounds) / (maxBounds - minBounds);\n \n // // Apply scaling to fill the scene\n // uv = uv * (maxBounds - minBounds);\n \n // // Calculate the offset by subtracting the original UV from the transformed and normalized UV\n // vec2 offset = uv - originalUv;\n \n // return offset;\n // }\n\n vec4 render(vec2 uv, vec2 screenSpaceUV, vec2 msaaOffset) {\n vec2 offset = uWarpEnabled ? warpTextureSampleUv(uv) : vec2(0.);\n vec2 warpedUv = waveUv(uv);\n offset += warpedUv;\n // offset += calculatePerspectiveOffset(uv);\n return(vec4(offset * 0.5 + 0.5, 0., 1.0));\n }\n\n float randomNonDet(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n }\n\n void main() {\n const vec2 H2 = vec2(0.5698402909980532f, 0.7548776662466927f);\n vec2 px = 1.f / resolution;\n px *= 1.25;\n vec2 uv = vUv;\n\n \n // Check if this fragment is within the SDF\n // vec2 uvOffset = lookupWarpSample(uv).xy;\n // float texCheck = (texture(tPolyEdgeDistance, uv + uvOffset).r - 0.5) * 2.0;\n // if(texCheck < -0.1) {\n // discard;\n // }\n\n\n const float samples = 6.f;\n \n vec4 sumColour;\n vec2 d0 = vec2(randomNonDet(uv), randomNonDet(uv + 1.f));\n\n \n for(float i = 0.f; i < samples; i++) {\n vec2 d = (fract(i * H2 + d0) - .5f);\n\n vec2 localCoord = vUv + d * px; /* changed */\n vec2 screenCoord = uTileOffset + localCoord * uTileSize; /* changed */\n vec2 globalUV = screenCoord / resolution; /* changed */\n\n // vec4 sampleColor = render(globalUV, vUv, d * px);\n vec4 sampleColor = render(globalUV, vUv, d * px);\n // sampleColor.rgb *= sampleColor.a; // Convert to premultiplied alpha\n sumColour += sampleColor;\n }\n \n vec4 averageColor = clamp(sumColour / samples, 0., 1.);\n \n outColor = averageColor;\n }\n `})}let wt="\n\n vec3 sCurve(vec3 c, float contrast, float midpoint) {\n // c in [0, 1], midpoint could be 0.5 or 0.18\n // contrast is how steep the curve is\n // A simple logistic-based S-curve\n return 1.0 / (1.2 + exp(-(c - midpoint) * contrast)) ;\n }\n\n vec4 adjustContrast(vec4 color, float factor) {\n float midpoint = 0.3; // 0.18\n // Factor is effectively the steepness of the slope\n vec3 curved = sCurve(color.rgb, factor, midpoint);\n return vec4(curved, color.a);\n }\n",kt="\n const float l2p3alpha = 1.055;\n const float l2p3beta = 0.00304;\n const float l2p3gamma = 2.4;\n const float l2p3delta = 0.055;\n\n vec3 linear2P3(vec3 linearRgb) {\n vec3 a = l2p3alpha * pow(linearRgb, vec3(1.0 / l2p3gamma)) - l2p3delta;\n vec3 b = linearRgb / 12.92;\n vec3 mask = step(vec3(l2p3beta), linearRgb);\n\n return mix(b, a, mask);\n }\n";function Rt(){return new e.ShaderMaterial({uniforms:{tTex:{value:null}},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:le,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform highp sampler2D tTex;\n in vec2 vUv;\n out vec4 outColor;\n\n ${kt}\n ${wt}\n\n // vec4 desaturateRGBA(vec4 color, float factor) {\n // float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));\n // vec3 desaturatedColor = mix(color.rgb, vec3(gray), factor);\n // return vec4(desaturatedColor, color.a);\n // }\n\n void main() {\n vec4 color = vec4(texture2D(tTex, vUv).rgb, 1.);\n // vec4 contrasty = adjustContrast(color, 12.);\n // color = mix(color, contrasty, 0.05);\n // color = adjustBrightness(color, 1.001);\n // color *= 0.95;\n // color = desaturateRGBA(color, 0.001);\n outColor = vec4(linear2P3(vec3(color)), 1.);\n }\n `})}const Tt=Rt(),Mt=new e.ShaderMaterial({uniforms:{tTex:{value:null},uChannel:{value:0}},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:le,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform highp sampler2D tTex;\n uniform int uChannel;\n\n in vec2 vUv;\n out vec4 outColor;\n\n // ${kt}\n // ${wt}\n\n void main() {\n vec4 color = vec4(texture2D(tTex, vUv).rgba);\n if(uChannel == -1) {\n outColor = color;\n return;\n }\n float channelColor = color[ int(uChannel) ];\n outColor = vec4(vec3(channelColor), 1.0);\n }\n `}),zt=new Xt(Tt);function Yt(e,t){zt.material=Tt,Tt.uniforms.tTex.value=e,X.setRenderTarget(t||null),zt.render(X)}class Pt{width;height;bufferIdx=0;textureCount=1;renderBuffers=[];renderBufferProps;maskEnabled=!1;constructor(t=Q,n=j,l){this.width=t,this.height=n;let i=K?e.LinearFilter:e.NearestFilter;this.renderBufferProps={anisotropy:V,minFilter:i,magFilter:i,stencilBuffer:!1,premultipliedAlpha:!0,alpha:!0,depthBuffer:!1,colorSpace:e.LinearDisplayP3ColorSpace,generateMipmaps:!1,format:e.RGBAFormat,type:e.FloatType,internalFormat:"RGBA32F",...l},this.setupFrameBuffers(),this.clearFrameBuffers(),X.autoClear=!1}setupFrameBuffers(){for(let t=0;t<2;t++)this.renderBuffers.push(new e.WebGLRenderTarget(this.width,this.height,this.renderBufferProps))}clearFrameBuffers(e=!0,t=!0,n=!0){X.setClearColor(16777215,0);const{stencil:l,color:i,depth:a}=X.state.buffers;this.renderBuffers.forEach((s=>{X.setRenderTarget(s),e&&i.setLocked(!1),t&&a.setLocked(!1),n&&l.setLocked(!1),X.clear(e,t,n)}))}enableMask(e=1){this.maskEnabled=!0;const{stencil:t}=X.state.buffers,n=X.getContext();t.setLocked(!1),t.setTest(!0),t.setFunc(n.EQUAL,e,4294967295),t.setOp(n.KEEP,n.KEEP,n.KEEP),t.setLocked(!0)}disableMask(){this.maskEnabled=!1;const{stencil:e}=X.state.buffers;e.setLocked(!1),e.setTest(!1),e.setLocked(!0)}renderMaterialAsMask(e,t=1){if(!this.renderBufferProps.stencilBuffer)throw Error("Stencil buffer not enabled in render buffer properties");const n=X.getContext(),{color:l,depth:i,stencil:a}=X.state.buffers;i.setMask(!1),i.setLocked(!0),l.setMask(!1),l.setLocked(!0),a.setLocked(!1),a.setTest(!0),a.setOp(n.KEEP,n.KEEP,n.REPLACE),a.setFunc(n.ALWAYS,t,4294967295),a.setClear(0),a.setLocked(!0),zt.material=e,X.setRenderTarget(this.getReadBuffer()),zt.render(),X.setRenderTarget(this.getWriteBuffer()),zt.render(),l.setLocked(!1),l.setMask(!0),i.setLocked(!1),i.setMask(!0)}getWriteBuffer(){return this.renderBuffers[(this.bufferIdx+1)%2]}getReadBuffer(){return this.renderBuffers[this.bufferIdx%2]}copyBufferChannelToScreen(e=0,t=this.getReadBuffer()){let n=this.maskEnabled;n&&this.disableMask(),X.setRenderTarget(null),zt.material=Mt,Mt.uniforms.tTex.value=t.texture,Mt.uniforms.uChannel.value=e,zt.render(),n&&this.enableMask()}copyBufferToBuffer(e){let t=this.maskEnabled;t&&this.disableMask(),X.setRenderTarget(e),X.copyFramebufferToTexture(this.getReadBuffer().texture),t&&this.enableMask()}copyAndSwapBuffers(){this.copyBufferToBuffer(this.getWriteBuffer()),this.bufferIdx++}copyBufferToScreen(e=this.getReadBuffer()){let t=this.maskEnabled;t&&this.disableMask(),Yt(e.texture),t&&this.enableMask()}}let Ft,Ht={},It=new Xt(null),Nt=0;class Ut{x;y;id=Nt++;hedgelist=[];constructor(e=0,t=0){this.x=e,this.y=t}sortincident(){this.hedgelist&&this.hedgelist.sort(Dt)}subtract(e){return new Ut(this.x-e.x,this.y-e.y)}addPolar(e,t){return new Ut(this.x+t*i(e),this.y+t*l(e))}normalize(e=g){const t=d(this.x*this.x+this.y*this.y);return t<e?new Ut(0,0):new Ut(this.x/t,this.y/t)}multiply(e){return new Ut(this.x*e,this.y*e)}add(e){return new Ut(this.x+e.x,this.y+e.y)}toArray(){return[this.x,this.y]}fromArray(e){return this.x=e[0],this.y=e[1],this}distanceTo(e){return d(a(e.x-this.x,2)+a(e.y-this.y,2))}angleTo(e){return Math.atan2(e.y-this.y,e.x-this.x)}lerp(e,t){return new Ut(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t)}translate(e,t){this.x+=t*i(e),this.y+=t*l(e)}clone(){return new Ut(this.x,this.y)}isEqualTo(e,t=g){const n=e.x-this.x,l=e.y-this.y;return n*n+l*l<=t*t}isCloseTo(e,t=g){return this.distanceTo(e)<t}dispose(){this.hedgelist.length=0}}function Dt(e,t){return t.angle-e.angle}function Ot(e,t=1){if(0===t)return e;let n=Be.w/t,l=Be.h/t,i=xe(e.x,n),a=xe(e.y,l);return new Ut(i,a)}function Bt(e,t=1){return function(e){return new Ut(e.x+Be.marginX,e.y+Be.marginY)}(Ot(new Ut(e.x,e.y),t))}function Qt(e){return[e[0],e[1],e[2]*Math.PI/180]}function jt(e){return(e%360+360)%360}function Jt(e){return[Ze(e[0],0,1),Ze(e[1],0,1),jt(e[2])]}let At="\n float getPaperTexture( const vec2 screenPosition ) {\n return texture(tPaperTexture, screenPosition).x;\n }\n\n vec3 calculateNormals(vec2 uv, float offsetScale, float scale) {\n // float offsetScale = .5;\n vec2 offset = vec2(offsetScale, offsetScale);\n // float scale = 1.;\n\n float left = getPaperTexture(vec2(uv.x + offset.x, uv.y));\n float right = getPaperTexture(vec2(uv.x - offset.x, uv.y));\n float up = getPaperTexture(vec2(uv.x, uv.y + offset.y));\n float down = getPaperTexture(vec2(uv.x, uv.y - offset.y));\n\n vec3 dx = vec3(1.0, 0.0, (left - right) * scale);\n vec3 dy = vec3(0.0, 1.0, (up - down) * scale);\n\n vec3 normal = normalize(cross(dy, dx));\n\n return -normal;\n }\n\n vec3 calculateDiffuse(vec3 normal, vec3 lightDir, vec3 lightColor) {\n // Calculate the diffuse component\n float diff = max(dot(normal, lightDir), 0.0);\n float angleAttenuation = pow(diff, 1.);\n return angleAttenuation * lightColor;\n }\n",Et="\n // Partially adapted from - https://github.com/yum-food/HLSL_OKLAB/blob/main/oklab.cginc\n const mat3 m1i = mat3(vec3(1.22700842, -0.5576564, 0.28111404), vec3(-0.04047048, 1.11219073, -0.07157255), vec3(-0.07643651, -0.42138367, 1.58625265));\n const mat3 m2i = mat3(vec3(1.00003964, 0.39638005, 0.21589049), vec3(0.99998945, -0.10553958, -0.06374665), vec3(0.99999105, -0.08946276, -1.291495));\n // XYZ -> linear RGB (p3) from colorjs.io - https://github.com/color-js/color.js/blob/main/src/spaces/p3-linear.js\n const mat3 xyz_to_rgb_p3 = mat3(vec3(2.493496911941425, -0.9313836179191239, -0.40271078445071684), vec3(-0.8294889695615747, 1.7626640603183463, 0.023624685841943577), vec3(0.03584583024378447, -0.07617238926804182, 0.9568845240076872));\n\n // Functions for matrix multiplication and power, as GLSL doesn't have built-in matrix multiplication for 3x3 matrices\n vec3 mat3_mul_vec3(mat3 m, vec3 v) {\n return vec3(dot(m[0], v), dot(m[1], v), dot(m[2], v));\n }\n\n vec3 vec3_pow(vec3 v, float p) {\n return vec3(pow(v.x, p), pow(v.y, p), pow(v.z, p));\n }\n\n // Converts OKLCH color to XYZ color space\n vec3 OKLCHtoXYZ(vec3 c) {\n // Convert OKLCH to OKLAB\n float a = c.y * cos(c.z);\n float b = c.y * sin(c.z);\n vec3 oklab = vec3(c.x, a, b);\n\n // Convert OKLAB to XYZ\n oklab = mat3_mul_vec3(m2i, oklab);\n oklab = vec3_pow(oklab, 3.0);\n return mat3_mul_vec3(m1i, oklab);\n }\n\n // Converts XYZ color to linear RGB color space (p3)\n vec3 XYZtoP3LRGB(vec3 c) {\n return mat3_mul_vec3(xyz_to_rgb_p3, c);\n }\n\n // Main function to convert OKLCH to Linear RGB\n vec3 OKLCHtoP3LRGB(vec3 oklchColor) {\n vec3 xyzColor = OKLCHtoXYZ(oklchColor);\n vec3 lrgbColor = XYZtoP3LRGB(xyzColor);\n return lrgbColor;\n }\n";const _t=e=>e.map((({x:e,y:t})=>[e*D,j-t*D]));class qt{width;height;format;type;channels;texture;gl;_glFormat;_glType;_glTexture;renderer;constructor(t,n,l,i,a){if(this.width=t,this.height=n,this.format=l,this.type=i,l===e.RGBAFormat)this.channels=4;else if(l===e.RGFormat)this.channels=2;else{if(l!==e.RedFormat)throw Error("Unsupported format for PartialDataTexture.");this.channels=1}const s=t*n*this.channels,o=a||new Float32Array(s);if(o.length!==s)throw Error("Initial data length does not match texture dimensions.");this.texture=new e.DataTexture(o,t,n,l,i),this.texture.needsUpdate=!0,this.gl=null,this._glFormat=null,this._glType=null,this._glTexture=null}setRenderer(t){this.renderer=t;const n=t.getContext();if(this.gl=n,this.format===e.RGBAFormat)this._glFormat=n.RGBA;else if(this.format===e.RGFormat)this._glFormat=n.RG;else{if(this.format!==e.RedFormat)throw Error("Unsupported format for PartialDataTexture.");this._glFormat=n.RED}if(this.type!==e.FloatType)throw Error("PartialDataTexture currently only supports Float32 data type.");this._glType=n.FLOAT,t.initTexture(this.texture);const l=t.properties.get(this.texture);this._glTexture=l.__webglTexture}uploadSubData(e){if(!this.gl||!this._glTexture)throw Error("Renderer not set or texture not initialized. Call setRenderer() before updating.");const t=this.gl,n=Math.floor(e/this.channels);if(n<=0)return;const l=this.width*this.height,i=Math.min(n,l),a=Math.floor(i/this.width),s=i%this.width,o=this.texture.image.data,r=t.getParameter(t.TEXTURE_BINDING_2D);if(t.bindTexture(t.TEXTURE_2D,this._glTexture),a>0){const e=o.subarray(0,a*this.width*this.channels);t.texSubImage2D(t.TEXTURE_2D,0,0,0,this.width,a,this._glFormat,this._glType,e)}if(s>0){const e=a*this.width*this.channels,n=o.subarray(e,e+s*this.channels);t.texSubImage2D(t.TEXTURE_2D,0,0,a,s,1,this._glFormat,this._glType,n)}t.bindTexture(t.TEXTURE_2D,r)}}function $t(e,t){const n=t[0]-e[0],l=t[1]-e[1];return d(n*n+l*l)}class en{polyLines=[];isClosed;cellSize;cellsWide;cellsHigh;_segmentRecords;_cellCounts;_cellOffsets;_indexData;segmentDataTexture;segmentIndexTexture;segmentMetaDataTexture;texturesInitialised=!1;constructor(e=1){this.cellSize=e}initializeTextures(){const n=o(C,2048);this.segmentDataTexture={texture:new qt(n,n,e.RGBAFormat,e.FloatType,new Float32Array(n*n*4)),width:n,height:n},this.segmentDataTexture.texture.setRenderer(X),t
ce:2,tension:{min:.9,max:1.2},maxPointUse:1,pointsToConsider:30,maxLinePoints:30},$e={warpX:!0,warpY:!1,offAxisX:!0,offAxisY:!1,warpXMult:.05,warpYMult:.05,displacementStrength:.05,noiseMapEnabled:!0},et=Pe,tt={cropToMargin:!0,cropBGShapesAtMargin:!0,cropToMarginFillDark:!1,margin:30},nt={count:100,lineRemoveStrength:.1,polyOverfitting:.75,noiseOverfittingSpread:0,noiseOverfitFreq:100,excludeWeakSplits:!1,longestSplitOnlyChance:50,noiseFieldCategoryInfluence:1e3},lt=Fe,it=100,at=.1,st=0,ot="",rt=!1;const ct=(e,t)=>{Be.scale=J.int(e,t);const n=Y/Be.scale,l=P/Be.scale;Be.countX=Math.ceil(n),Be.countY=Math.ceil(l);const i=Be.countX*Be.scale,a=Be.countY*Be.scale;Be.marginX=(Y-i)/2,Be.marginY=(P-a)/2,Be.w=Be.scale,Be.h=Be.scale};var dt,ut,ht,mt,pt,bt;function gt(e,t){return function(e){return void 0!==e[t]?e[t]:e.default}}!function(e){e.filledFractured="filledFractured",e.centralNatural="centralNatural",e.sparseFractured="sparseFractured",e.sparseBlockyFracture="sparseBlockFracture",e.smoothObjects="flowingObjects",e.islands="islands",e.bigObjects="focusedObjects",e.fractures="fractures"}(dt||(dt={})),function(e){e.xs="xsmall",e.sm="small",e.md="medium",e.lg="large",e.xl="xlarge"}(ut||(ut={})),function(e){e.none="none",e.sparse="sparse",e.light="light",e.dense="dense",e.filled="filled",e.detailOnly="detailOnly"}(ht||(ht={})),function(e){e.light="light",e.medium="medium",e.heavy="heavy"}(mt||(mt={})),function(e){e.color="color",e.dark="dark",e.light="light"}(pt||(pt={})),function(e){e.objects="objects",e.curves="curves",e.angles="angles",e.grid="grid",e.mesh="mesh",e.all="all",e.random="random"}(bt||(bt={}));const ft=()=>({[bt.objects]:{splits:{[Se.horizontal]:1,[Se.vertical]:2,[Se.perspective]:0,[Se.circle]:2,[Se.wobbles]:3,[Se.objects]:15,[Se.curves]:5,[Se.rects]:1,[Se.borderRect]:1},meta:{forceSplit:{forceInsertCurvesChance:J.choice([10,0]),forceInsertObjectsChance:J.choice([20,0])}}},[bt.grid]:{splits:{[Se.horizontal]:2,[Se.vertical]:4,[Se.perspective]:0,[Se.circle]:4,[Se.wobbles]:1,[Se.objects]:10,[Se.curves]:0,[Se.rects]:0,[Se.borderRect]:0},meta:{forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:0}}},[bt.curves]:{splits:{[Se.horizontal]:1,[Se.vertical]:2,[Se.perspective]:0,[Se.circle]:10,[Se.wobbles]:10,[Se.objects]:J.choice([10,1]),[Se.curves]:10,[Se.rects]:0,[Se.borderRect]:1},meta:{usedLineReplayChance:10,forceSplit:{forceInsertCurvesChance:J.choice([0,20]),forceInsertObjectsChance:J.choice([0,20])}}},[bt.angles]:{splits:{[Se.horizontal]:2,[Se.vertical]:3,[Se.perspective]:3,[Se.circle]:0,[Se.wobbles]:0,[Se.objects]:3,[Se.curves]:2,[Se.rects]:0,[Se.borderRect]:1},meta:{forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:0}}},[bt.mesh]:{splits:{[Se.horizontal]:1,[Se.vertical]:1,[Se.perspective]:1,[Se.circle]:1,[Se.wobbles]:0,[Se.objects]:1,[Se.curves]:0,[Se.rects]:0,[Se.borderRect]:0},meta:{objectProps:{forceYUp:!0},forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:50}}},[bt.all]:{splits:{[Se.horizontal]:2,[Se.vertical]:2,[Se.perspective]:2,[Se.circle]:2,[Se.wobbles]:2,[Se.objects]:4,[Se.curves]:2,[Se.rects]:1,[Se.borderRect]:2},meta:{forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:0}}}});let xt,Zt,yt;const Gt=()=>{let e=ft();yt=J.weightedChoice([8,dt.filledFractured],[10,dt.sparseFractured],[rt?0:14,dt.centralNatural],[8,dt.sparseBlockyFracture],[8,dt.smoothObjects],[8,dt.islands],[8,dt.bigObjects],[8,dt.fractures]);let n=gt(0,yt);ot="Pencils",ct(20,20),Zt=n({[dt.filledFractured]:ut.lg,[dt.sparseFractured]:ut.lg,[dt.centralNatural]:ut.md,[dt.sparseBlockyFracture]:ut.md,[dt.smoothObjects]:ut.sm,[dt.islands]:J.choice([ut.lg,ut.md]),[dt.bigObjects]:ut.sm,[dt.fractures]:ut.lg});let l=gt(0,Zt);xt=J.weightedChoice([n({[dt.centralNatural]:1,default:0}),ht.light],[n({default:0}),ht.dense],[n({[dt.filledFractured]:1,[dt.sparseFractured]:1,[dt.sparseBlockyFracture]:1,[dt.smoothObjects]:1,[dt.bigObjects]:1,default:0}),ht.filled],[n({[dt.islands]:1,[dt.fractures]:1,default:0}),ht.detailOnly]);let i=gt(0,xt),a=J.weightedChoice([n({[dt.filledFractured]:1,[dt.sparseFractured]:1,[dt.smoothObjects]:1,[dt.islands]:1,[dt.bigObjects]:1,default:0}),bt.objects],[n({[dt.filledFractured]:1,[dt.islands]:1,default:0}),bt.curves],[n({[dt.centralNatural]:2,[dt.sparseBlockyFracture]:1,[dt.islands]:1,default:0}),bt.angles],[n({[dt.fractures]:1,default:0}),bt.grid]),s=e[a];Ee=be(Ee,s.splits),De=be(De,s.meta.forceSplit),nt=be(nt,{noiseOverfittingSpread:n({[dt.filledFractured]:J.num(.2,.5),[dt.sparseFractured]:J.num(.2,.5),[dt.centralNatural]:J.num(.2,1),[dt.sparseBlockyFracture]:J.num(.25,.35),[dt.smoothObjects]:J.num(.001,.01),[dt.islands]:J.num(0,.3),[dt.bigObjects]:J.num(.25,.35),[dt.fractures]:J.num(.13,.19),default:J.num(0,1)}),noiseOverfitFreq:1200,polyOverfitting:n({[dt.bigObjects]:.97,default:1}),longestSplitOnlyChance:n({default:50}),noiseFieldCategoryInfluence:n({[dt.filledFractured]:1,[dt.sparseFractured]:1,[dt.centralNatural]:4,[dt.sparseBlockyFracture]:4,[dt.smoothObjects]:4,[dt.islands]:1,[dt.bigObjects]:4,[dt.fractures]:4,default:J.int(1,4)})}),st=s.meta?.usedLineReplayChance||4,it=t(n({[dt.filledFractured]:J.easedInt(ve,250,450),[dt.sparseFractured]:J.easedInt(ve,260,450),[dt.centralNatural]:J.easedInt(ve,200,240),[dt.sparseBlockyFracture]:J.easedInt(ve,240,400),[dt.smoothObjects]:J.easedInt(ve,170,260),[dt.islands]:l({[ut.lg]:J.easedInt(ve,250,660),default:J.easedInt(ve,230,400)}),[dt.bigObjects]:J.easedInt(ve,170,220),[dt.fractures]:J.easedInt(ve,290,330)})*J.num(.95,1.05)),at=n({[dt.filledFractured]:J.num(.003,.01),[dt.sparseFractured]:J.num(.003,.01),[dt.centralNatural]:J.num(.025,.035),[dt.sparseBlockyFracture]:J.num(.11,.15),[dt.smoothObjects]:J.num(.001,.006),[dt.islands]:J.num(.1,.27),[dt.bigObjects]:J.num(0,.008),[dt.fractures]:J.num(.03,.05),default:J.num(0,.3)});let o=n({[dt.centralNatural]:J.bool(20),[dt.filledFractured]:!0,default:J.bool(50)});et={...et,curveMap:n({[dt.filledFractured]:J.choice([Ge,ve]),[dt.sparseFractured]:J.choice([Ge,ve]),default:We}),mutation:rt?"none":n({default:J.weightedChoice([1,"offsetUp"],[3,"none"])}),addBGContrast:i({[ht.detailOnly]:!1,default:!0}),useNoiseLookup:!0,samplesForComplimentary:n({[dt.filledFractured]:J.int(1,2),default:J.weightedChoice([3,1],[2,2])}),samplesForPaletteOffset:1,singleAccent:!1,freqMultiplier:n({[dt.filledFractured]:J.num(300,400),[dt.sparseFractured]:J.num(300,400),[dt.centralNatural]:J.num(280,320),default:J.num(100,500)}),usePolyIDColorOffset:o,maxAccents:n({[dt.centralNatural]:J.choice([4,6,100]),default:J.weightedChoice([0,4],[2,6],[4,100])}),darksOnly:!1};let r=gt(0,J.weightedChoice([10,pt.color],[n({default:0}),pt.dark],[n({default:0}),pt.light]));lt={...lt,size:l({[ut.md]:{min:5,max:6},[ut.lg]:{min:4,max:5},[ut.sm]:{min:6,max:8}})},_e=[Se.horizontal,Se.vertical],Ie={...Ie,default:1,clamp:.01,min:.6,max:.99,influencesPressureMult:0,influencesBrightnessMult:1,influencesMinDistanceMult:.2},xt!=ht.filled||Zt!=ut.lg&&Zt!=ut.md||!J.bool(10)||(Ie={...Ie,default:1,clamp:.025,min:.5,max:.55,influencesPressureMult:0,influencesBrightnessMult:1,influencesMinDistanceMult:0});let c=n({[dt.filledFractured]:!1,[dt.sparseBlockyFracture]:!1,[dt.centralNatural]:!0,[dt.sparseFractured]:!0,[dt.smoothObjects]:!1,[dt.islands]:!1,[dt.bigObjects]:!1,[dt.fractures]:!0,default:J.bool(40)});qe={...qe,ignoreLighting:J.bool(50),maxWidth:n({[dt.filledFractured]:J.num(35,45),[dt.sparseFractured]:J.num(35,45),[dt.centralNatural]:J.int(38,42),[dt.sparseBlockyFracture]:J.int(38,42),[dt.smoothObjects]:J.int(31,36),[dt.islands]:l({[ut.lg]:J.int(30,40),default:J.int(30,45)}),[dt.bigObjects]:J.num(30,35),[dt.fractures]:J.num(35,37)}),renderLightChance:n({[dt.filledFractured]:7,[dt.sparseFractured]:J.int(0,10),[dt.centralNatural]:J.int(0,1),[dt.sparseBlockyFracture]:J.int(5,9),[dt.smoothObjects]:J.int(0,1),[dt.islands]:J.int(0,20),default:0}),maxPointUse:1,maxDivergence:2,pointsToConsider:10},Ue=be({...Ue,layers:n({default:2}),layerScaleMult:2.5,zDepthMaxMult:J.int(1,2),cropTo:n({[dt.islands]:Ce.scene,[dt.fractures]:Ce.border,default:Ce.none}),forceYUp:a==bt.grid||J.bool(30),clampVertsToGrid:!1,...n({[dt.sparseBlockyFracture]:{maxDist:230,minDist:150},[dt.centralNatural]:{maxDist:J.num(105,190),minDist:J.num(70,100)},[dt.filledFractured]:{maxDist:J.num(140,180),minDist:95},[dt.sparseFractured]:{maxDist:J.num(140,180),minDist:103},[dt.smoothObjects]:{minDist:170,maxDist:262},[dt.islands]:J.choice([{minDist:85,maxDist:150},{minDist:125,maxDist:260}]),[dt.bigObjects]:{minDist:176,maxDist:271},[dt.fractures]:{minDist:243,maxDist:216}}),bnFreq:n({[dt.sparseBlockyFracture]:J.int(280,320),[dt.filledFractured]:J.int(200,210),[dt.sparseFractured]:J.int(180,190),[dt.centralNatural]:J.int(500,600),[dt.smoothObjects]:J.int(200,230),[dt.islands]:J.int(150,170),[dt.bigObjects]:J.int(470,480),[dt.fractures]:J.int(220,221)}),fieldFreq:n({[dt.sparseBlockyFracture]:J.int(1350,1450),[dt.filledFractured]:J.int(6e3,6100),[dt.sparseFractured]:J.int(6500,7500),[dt.centralNatural]:J.int(1e3,1200),[dt.smoothObjects]:J.int(1e3,1200),[dt.islands]:J.int(6e3,7500),[dt.bigObjects]:J.int(1500,1600),[dt.fractures]:J.int(4700,4800)}),clampRotationTo:n({[dt.sparseBlockyFracture]:11.25,[dt.bigObjects]:22.5,default:1}),minSizeMult:n({[dt.smoothObjects]:J.num(.6,.8),[dt.islands]:J.num(.6,.8),default:.75}),maxSizeMult:n({[dt.smoothObjects]:J.num(.9,1.1),[dt.islands]:J.num(1,1.1),default:1}),maxSides:5,minSides:3,perspective:2e4},s.meta?.objectProps||{});let d={edgeSharpness:{min:.8,max:1},fillChance:100,insetChance:n({[dt.sparseBlockyFracture]:0,[dt.filledFractured]:0,[dt.centralNatural]:0,[dt.sparseFractured]:J.int(3,20),[dt.smoothObjects]:J.int(0,10),[dt.islands]:J.int(0,10),default:J.choice([8,5,0])}),wobbleFreq:{min:40,max:80},wobbleAmplitude:{min:1,max:3},accumulationStrength:{min:1,max:1},materialHardness:i({[ht.light]:{min:.9,max:.97},default:{min:.93,max:.99}}),linePressure:{min:.65,max:.7},minDistanceMult:l({default:J.choice([{min:.7,max:.8}])}),lineTapering:{fade:{in:{enabledChance:0,min:0,max:0},out:{enabledChance:0,min:0,max:0}},scale:{in:{enabledChance:0,min:0,max:0},out:{enabledChance:0,min:0,max:0}}},layerCountChances:n({[dt.sparseBlockyFracture]:J.choice([[[1,4],[1,6]],[[1,6]]]),[dt.filledFractured]:J.choice([[[1,4],[1,6]],[[1,6]]]),[dt.sparseFractured]:J.choice([[[1,4],[1,6]],[[1,6]]]),[dt.smoothObjects]:J.choice([[[1,4],[1,6]],[[1,6]]]),[dt.centralNatural]:[[1,6]],[dt.islands]:[[1,6]],[dt.bigObjects]:J.choice([[[1,4]],[[1,6]],[[1,4],[1,6]]]),[dt.fractures]:J.choice([[[1,4]],[[1,6]],[[1,4],[1,6]]]),default:[[1,6]]}),lineWeight:l({[ut.sm]:{min:1.4,max:1.5},default:{min:1.4,max:1.5}}),layerOverride:[{fadeAtLineSegmentChance:0,lineTapering:{fade:{out:{enabledChance:l({[ut.sm]:50,[ut.md]:J.int(0,20),[ut.lg]:J.int(0,20),default:0}),min:1,max:2}}},wobbleAmplitude:{min:5,max:6},wobbleFreq:{min:50,max:70},styleChances:[[1,"bnnoise"]],colorMap:"none"===et.mutation&&J.bool(rt?0:10)?[[[100,J.choice([Ke.offsetDown,Ke.offsetUp])],[J.weightedChoice([2,0],[1,J.int(0,15)]),Ke.color]]]:[[[100,Ke.color],[J.weightedChoice([2,0],[1,J.int(0,15)]),Ke.offsetUp]]]},{fadeAtLineSegmentChance:0,styleChances:[[1,"edgefill"]],colorMap:[[[1,Ke.previous]]],wobbleAmplitude:{min:5,max:6},wobbleFreq:{min:40,max:100}},J.weightedChoice([0,{scribbleChance:100,scribbleStrength:{min:.2,max:.4},colorMap:[[[1,Ke.offset]]],styleChances:[[1,"bnnoise"]],linePressure:{min:.9,max:.95},lineTapering:{scale:{out:{enabledChance:100,min:0,max:.2},in:{enabledChance:100,min:0,max:.2}}}}],[2,{scribbleChance:0,colorMap:[[[1,Ke.offsetUp]]],wobbleAmplitude:{min:1,max:1},styleChances:[[1,"bnnoise"]],fadeAtLineSegmentChance:100,fadeAtLineSegmentDistanceMult:{min:.6,max:1},fadeAtLineSegmentStrengthMult:{min:1,max:1.1},linePressure:{min:1.2,max:1.25},materialHardness:{min:.9,max:.95},lineTapering:{fade:{in:{enabledChance:0,min:1,max:1},out:{enabledChance:100,min:3,max:8}}}}]),{styleChances:[[1,"directional"],[1,"bnnoise"]],colorMap:[[[1,Ke.previous]]],wobbleAmplitude:{min:4,max:8},wobbleFreq:{min:40,max:60}},{colorMap:[[[1,Ke.brightnessBasedShadowOrHighlight]]],fadeAtLineSegmentChance:100,fadeAtLineSegmentDistanceMult:{min:1.5,max:1.5},fadeAtLineSegmentStrengthMult:{min:1,max:1},materialHardness:{min:.7,max:.8},linePressure:{min:1.3,max:1.4},minDistanceMult:{min:.5,max:.6},wobbleAmplitude:{min:1,max:2},wobbleFreq:{min:50,max:100},styleChances:[[1,"bnnoise"],[0,"directional"],[0,"wobbles"],[0,"bluenoise"],[0,"edgefill"]],lineTapering:{fade:{in:{enabledChance:0,min:.1,max:.2},out:{enabledChance:100,min:2,max:4}}}},{styleChances:[[1,"bnnoise"]],colorMap:[[[1,Ke.previous]]],wobbleAmplitude:{min:5,max:6},wobbleFreq:{min:80,max:200}}]};je=be(je,{ignoreLightingChance:0,wobbleAmplitude:{min:2,max:2},wobbleFreq:{min:35,max:45},materialHardness:{min:.8,max:.85},linePressure:{min:.7,max:.9},minDistanceMult:i({[ht.sparse]:{min:2.7,max:3.8},default:{min:1.4,max:1.5}}),spatialOverride:{[we.notInCurveOrObject]:{fillChance:100,colorMap:[[[1,Ke.offset]]],colorPalette:"fg",ignoreLightingChance:100,insetChance:100,scribbleChance:0,insetDistance:{min:10,max:20},minDistanceMult:{min:2.5,max:5},linePressure:{min:.8,max:.9},lineWeight:{min:.8,max:1.6},fadeAtLineSegmentChance:0},[we.nonDominant]:i({[ht.light]:be(d,{colorPalette:"bg",fillChance:100,layerCountChances:[[1,2]],minDistanceMult:{min:1,max:1.3},lineWeight:{min:1.1,max:1.2},layerOverride:[be(d.layerOverride[0],{colorPalette:"bg",colorMap:[[[1,Ke.color]]],linePressure:{min:.15,max:.2},styleChances:[[1,"bnnoise"]]}),be(d.layerOverride[1],{linePressure:{min:.5,max:.6},colorMap:[[[1,Ke.previous]]],styleChances:[[1,"edgefill"]]})]}),[ht.detailOnly]:{fillChance:0},default:d}),[we.overlay]:{lineWeight:{min:1.6,max:1.7},materialHardness:{min:.6,max:.75},minDistanceMult:{min:1,max:1},layerCountChances:[[1,2]],linePressure:{min:.99,max:.99},layerOverride:{0:{styleChances:[[1,"bnnoise"]],colorMap:[[[1,Ke.lightest]]],fadeAtLineSegmentChance:0,scribbleChance:0},1:{fadeAtLineSegmentChance:0,styleChances:[[1,"edgefill"]],colorMap:[[[1,Ke.brightnessBasedShadowOrHighlight]]],wobbleAmplitude:{min:6,max:8},wobbleFreq:{min:60,max:90}}}},[n({default:c?we.inCurveOrObject:we.dominant})]:be(d,{fillChance:100,insetDistance:{min:6,max:12}})}}),Qe=be(Qe,{insetChance:50,detailMinScaleDivisor:10,insetDistance:{min:4,max:12},wobbleAmplitude:{min:2,max:4},wobbleFreq:{min:55,max:200},fadeAtLineSegmentChance:0,fillChance:0,layerCountChances:[[1,2],[1,1]],colorMap:i({[ht.detailOnly]:[[[1,Ke.color]],[[1,Ke.previous]]],default:[[[1,Ke.line]]]}),lineTapering:{fade:{out:{enabledChance:0,min:1,max:2}},scale:{in:{enabledChance:100,min:.01,max:.2},out:{enabledChance:100,min:.01,max:.2}}},linePressure:{min:.9,max:.95},materialHardness:{min:.9,max:.95},lineWeight:{min:.6,max:1.5},minDistanceMult:{min:3,max:5},spatialOverride:{[we.nonDominant]:{scribbleChance:0,lineWeight:{min:1,max:1.5},colorMap:[J.choice([[[100,Ke.line]]])],colorPalette:J.choice(["bg","fg"]),insetChance:100,insetDistance:{min:7,max:12},fillChance:i({[ht.detailOnly]:100,default:0}),linePressure:i({[ht.light]:{min:.5,max:.6},default:{min:.5,max:.6}}),minDistanceMult:l({[ut.sm]:{min:5,max:7},default:{min:4,max:6}}),styleChances:J.weightedChoice([1,[[1,"directional"]]],[1,[[1,"bnnoise"]]],[1,[[2,"bnnoise"],[2,"directional"],[0,"wobbles"],[0,"bluenoise"]]],[2,[[1,"bluenoise"]]])},[we.dominant]:{ignoreLightingChance:100,fillChance:l({[ut.sm]:i({[ht.detailOnly]:J.int(30,40),default:J.int(40,60)}),default:J.weightedChoice([1,30],[1,J.num(40,70)])}),layerCountChances:[[2,2],[1,1]],linePressure:{min:.7,max:.9},styleChances:[[5,"bnnoise"],[5,"directional"],[1,"wobbles"],[4,"bluenoise"]],materialHardness:{min:.8,max:.9},colorMap:[[[100,Ke.randomAccent]],[[100,Ke.previous]]],minDistanceMult:{min:6,max:15},lineWeight:l({[ut.lg]:{min:1,max:1.25},default:{min:1,max:1.25}})}}}),Ne=be(Ne,{count:10,warpChance:100,length:{min:100,max:200},thickness:{min:1,max:1.5}});let u=n({[dt.sparseBlockyFracture]:J.int(70,80),[dt.filledFractured]:J.int(80,90),[dt.sparseFractured]:J.int(80,89),[dt.centralNatural]:J.int(70,80),[dt.smoothObjects]:J.int(90,99.9),[dt.islands]:J.int(65,70),[dt.bigObjects]:J.int(90,99.9),[dt.fractures]:J.int(95,99)}),h=J.num(.75,1);Oe=be(Oe,{meshInsetMuliplier:0,lineFilter:u<80?"none":n({[dt.filledFractured]:"none",[dt.sparseFractured]:"none",[dt.centralNatural]:"none",default:J.weightedChoice([0,"curves"],[0,"straight"],[3,"none"])}),meshDensity:u,skipLongest:l({[ut.lg]:J.int(0,10),default:0}),percentage:n({[dt.sparseBlockyFracture]:J.int(50,70),[dt.filledFractured]:J.int(50,80),[dt.sparseFractured]:J.int(50,80),[dt.centralNatural]:J.int(70,85),[dt.smoothObjects]:J.int(60,80),[dt.islands]:J.int(60,75),[dt.bigObjects]:J.int(50,70),[dt.fractures]:J.choice([0,J.int(60,75)])}),cropToDominantShape:!1,colors:r({[pt.color]:!0,default:!1}),backgroundColor:r({[pt.light]:!(xt!==ht.filled&&u<80),default:!1}),materialHardness:{min:.9,max:.96},linePressure:{min:.9,max:.95},thickness:l({[ut.lg]:{min:2.85*h,max:3*h},[ut.md]:{min:2.25*h,max:3.65*h},default:{min:2.25*h,max:4.25*h}})});let m=J.weightedChoice([3,J.int(0,1)],[1,J.int(2,10)]),p=n({[dt.fractures]:3,default:4});Ae=be(Ae,{margin:p*Be.scale,HVariance:{min:-m,max:m,threshold:1,mean:1,stdDev:1},VVariance:{min:-m,max:m,threshold:1,mean:1,stdDev:1},circles:{count:5,minRadius:5,maxRadius:18},wobble:{enabled:!0,count:1e10,minLength:2,layers:4,multiLayers:1,gridDivisions:1,warpFreq:{min:800,max:2e3},offsetMultiplier:.6},perspectiveBox:{enabled:!0,threshold:4,mean:2,stdDev:8,firstFull:!0,count:1}}),tt={...tt,cropToMargin:!1,margin:6*Be.scale}},Wt=()=>{ot="Sparse",ct(20,20);let e=gt(0,J.weightedChoice([1,ut.sm],[1,ut.md],[1,ut.lg]));J.weightedChoice([1,mt.heavy]);let t=J.weightedChoice([e({[ut.sm]:1,default:1}),bt.objects],[e({[ut.sm]:0,default:2}),bt.curves],[e({[ut.sm]:0,default:1}),bt.angles],[e({[ut.sm]:0,default:1}),bt.grid]),n=ft()[t];n.splits[Se.circle]=3,Ee=be(Ee,n.splits),De=be(De,n.meta.forceSplit),nt=be(nt,{noiseOverfittingSpread:e({[ut.sm]:J.num(0,1),default:J.num(0,1)}),noiseOverfitFreq:1200,polyOverfitting:J.num(.5,1.5)}),st=e({default:n.meta?.usedLineReplayChance||4}),it=J.int(200,800),at=.1;let l=J.weightedChoice([1,!1],[1,!0]);et={...et,mutation:J.weightedChoice([0,"offsetUp"],[0,"offsetDown"],[3,"none"]),useNoiseLookup:!0,samplesForComplimentary:J.int(1,2),samplesForPaletteOffset:1,singleAccent:!1,freqMultiplier:e({default:l?J.num(600,1e3):J.num(100,200)}),usePolyIDColorOffset:l,maxAccents:e({default:J.weightedChoice([0,4],[1,6],[2,100])}),darksOnly:!1};let i=gt(0,J.weightedChoice([e({[ut.lg]:1,default:1}),pt.dark]));lt={...lt,count:0},_e=[Se.horizontal,Se.vertical],Ie={...Ie,default:1,clamp:.05,min:.9,max:1.1,influencesBrightnessMult:1,influencesMinDistanceMult:0,influencesPressureMult:0},qe={...qe,maxWidth:.75*e({[ut.sm]:J.int(40,50),[ut.md]:J.int(40,50),default:J.num(35,45)}),renderLightChance:100,maxPointUse:J.int(1,2),maxDivergence:J.int(2,4),pointsToConsider:10};let a=J.num(.75,1.5);Ue=be({...Ue,layers:2,layerScaleMult:2.5,zDepthMaxMult:J.int(1,2),cropTo:e({default:J.choice([Ce.none])}),forceYUp:!0,...e({[ut.sm]:{maxDist:200*a,minDist:130*a},[ut.md]:{maxDist:150*a,minDist:100*a},[ut.lg]:J.weightedChoice([5,{maxDist:150*a,minDist:100*a}])}),bnFreq:J.num(10,1e3),fieldFreq:e({[ut.lg]:J.int(4e3,1e4),[ut.sm]:J.int(1e3,2e3),default:J.choice([J.int(1e3,4e3),J.int(4e3,1e4)])}),clampRotationTo:J.weightedChoice([1,22.5],[4,1],[1,11.25]),minSizeMult:1,maxSizeMult:e({default:.75}),maxSides:5,minSides:3,perspective:2e4},n.meta?.objectProps||{}),Je=be(Je,{});let s={edgeSharpness:{min:0,max:0},fillChance:90,insetChance:10,wobbleFreq:{min:30,max:60},wobbleAmplitude:{min:3,max:8},accumulationStrength:{min:10,max:10},materialHardness:{min:.4,max:.45},linePressure:{min:1.3,max:1.3},lineWeight:it<300?{min:1.9,max:2}:{min:1.6,max:1.7},minDistanceMult:{min:.45,max:.5},lineTapering:{scale:{in:{enabledChance:0,min:.1,max:.2},out:{enabledChance:0,min:1.5,max:2}},fade:{in:{enabledChance:0,min:0,max:0},out:{enabledChance:100,min:3,max:8}}},layerCountChances:[[1,3]],layerOverride:[{fadeAtLineSegmentChance:0,scribbleChance:10,scribbleStrength:{min:.2,max:.4},styleChances:[[1,"bnnoise"],[1,"directional"],[0,"edgefill"],[1,"bluenoise"]],colorMap:"none"===et.mutation&&J.bool(50)?[[[100,Ke.offsetUp],[1,Ke.color]]]:[[[100,Ke.color],[1,Ke.offsetUp]]]},{fadeAtLineSegmentChance:0,styleChances:[[2,"bnnoise"],[2,"directional"],[0,"edgefill"],[1,"bluenoise"]],colorMap:[[[100,Ke.previous]]]},{styleChances:[[1,"bnnoise"]],colorMap:[[[1,Ke.brightnessBasedShadowOrHighlight]]]}]};je=be(je,{ignoreLightingChance:0,spatialOverride:{[we.nonDominant]:s,[we.overlay]:{lineWeight:{min:1.6,max:1.7},materialHardness:{min:.6,max:.75},minDistanceMult:{min:1,max:1},layerCountChances:[[1,2]],linePressure:{min:.99,max:.99},layerOverride:[{styleChances:[[1,"bnnoise"]],colorMap:[[[1,Ke.lightest]]],fadeAtLineSegmentChance:0,scribbleChance:0},{fadeAtLineSegmentChance:0,styleChances:[[1,"bnnoise"]],colorMap:[[[1,Ke.lightest],[1,Ke.darkest]]],wobbleAmplitude:{min:6,max:8},wobbleFreq:{min:60,max:90}}]},[we.dominant]:be(s,{fillChance:100,lineTapering:{fade:{in:{enabledChance:0,min:1,max:1},out:{enabledChance:50,min:6,max:8}}},insetChance:20,insetDistance:{min:6,max:12}})}}),Qe=be(Qe,{insetChance:50,fillChance:50,detailMinScaleDivisor:10,insetDistance:{min:4,max:12},wobbleAmplitude:{min:2,max:4},wobbleFreq:{min:55,max:200},fadeAtLineSegmentChance:0,layerCountChances:[[1,2],[1,1]],colorMap:[[[1,Ke.line]]],lineTapering:{fade:{out:{enabledChance:50,min:1,max:2}},scale:{in:{enabledChance:100,min:.01,max:.2},out:{enabledChance:100,min:.01,max:.2}}},linePressure:{min:.8,max:1},materialHardness:{min:.65,max:.82},lineWeight:{min:1.25,max:1.5},ignoreLightingChance:100,styleChances:[[6,"bnnoise"],[6,"directional"],[1,"wobbles"],[1,"bluenoise"]],minDistanceMult:{min:4,max:8}}),Ne=be(Ne,{count:0,warpChance:100,length:{min:100,max:200},thickness:{min:1,max:1.5}});let o=e({[ut.sm]:J.int(95,100),[ut.lg]:J.int(65,90),default:J.int(70,100)});Oe=be(Oe,{meshInsetMuliplier:0,lineFilter:"none",meshDensity:o,skipLongest:0,percentage:100,cropToDominantShape:!1,colors:i({default:!1}),backgroundColor:i({default:!1}),linePressure:{min:1.1,max:1.4},materialHardness:{min:.75,max:.82},lineTapering:{fade:{in:{enabledChance:0,min:0,max:1},out:{enabledChance:0,min:1,max:2}},scale:{in:{enabledChance:100,min:.1,max:.5},out:{enabledChance:100,min:.1,max:.5}}},thickness:e({default:it<600?{min:2,max:2.5}:{min:1.5,max:2}})});let r=J.weightedChoice([1,J.int(0,1)],[1,J.int(2,10)]),c=e({[ut.s
import*as e from"three";const{floor:t,ceil:n,sin:l,cos:i,pow:a,abs:s,min:o,max:r,round:c,sqrt:d,acos:u,sign:h,log:m,random:p,PI:b}=Math,g=1e-7;function f(e,n=g){return t(e+n)}function x(e,t=g){return n(e-t)}function Z(e,t=g){const n=t*h(e);return c(e+n)}let y,G,W="#fff";const v=e=>{e.showUpdate?(!G&&(()=>{y=document.createElement("div"),y.id="loading";const e=y.style;e.position="absolute",e.fontSize="1vmax",e.top=e.left="0",e.width="100%",e.height="100%",e.zIndex="1000",G=document.createElement("div");const t=G.style;t.textTransform="uppercase",t.position="fixed",t.lineHeight="0",t.top=t.left="0",t.width="100vw",t.height="100vh",t.height="fill-available",t.display="flex",t.justifyContent=t.alignItems="center",t.flexDirection="column",t.color=W,t.fontFamily="system-ui",t.fontWeight="500",y.appendChild(G),document.body.appendChild(y)})(),G.innerHTML=(e=>{const{message:t="",value:n=0,isPercent:l=!1}=e;let i=`<p>${t}</p>`,a="";return a=l?`<div style="max-width: 15vmin; margin-top: 1.25em; width: 100%; border: .5px solid ${W}"><div style="width: ${e.value||0}%; height: .75vmin; background-color: ${W}; overflow: hidden;"></div>`:`<p style="margin-top: 1.5em">${n}</p>`,""+(i+a)})(e)):G&&L()},L=()=>{let e=document.getElementById("loading");e&&document.body.removeChild(e),G=null};let S,X,C,V,K,w,k=()=>{S.style.display="none"},R=()=>{S.style.display="block"};const T=performance.now.bind(performance);let M,z,Y,P,F=null,H=()=>{M.style.display="none"},I=2200,N=.72;const U=r(window.devicePixelRatio,2);let D,O,B,Q,j,J,A,E=0;class _{useA;prngA;prngB;hash;constructor(e){this.useA=!1,this.hash=e;const t=globalThis.parseInt;let n=function(e){let n=t(e.substring(0,8),16),l=t(e.substring(8,16),16),i=t(e.substring(16,24),16),a=t(e.substring(24,32),16);return function(){n|=0,l|=0,i|=0,a|=0;let e=(n+l|0)+a|0;return a=a+1|0,n=l^l>>>9,l=i+(i<<3)|0,i=i<<21|i>>>11,i=i+e|0,(e>>>0)/4294967296}};this.prngA=n(this.hash.substring(2,34)),this.prngB=n(this.hash.substring(34,66))}dec(){return this.useA=!this.useA,this.useA?this.prngA():this.prngB()}num(e,t){return e+(t-e)*this.dec()}int(e,n){return t(this.num(e,n+1))}bool(e=50){return this.dec()<e/100}choice(e){return e[this.int(0,e.length-1)]}easedDec(e){return e(this.dec())}easedInt(e,n,l){return t(this.easedNum(e,n,l))}easedNum(e,t,n){return t+(n-t)*this.easedDec(e)}weightedChoice(...e){const t=e.reduce(((e,[t])=>e+t),0);let n=this.dec()*t;for(const[t,l]of e)if((n-=t)<0)return l;return e[e.length-1][1]}gaussian(e=0,t=1){let n=0,l=0;for(;0===n;)n=this.dec();for(;0===l;)l=this.dec();return d(-2*m(n))*i(2*b*l)*t+e}gaussianBool(e=0,t=0,n=1){return this.gaussian(t,n)>=e}}function q(e=J){let t="0x";for(let n=0;n<64;n++)t+=Math.floor(16*e.dec()).toString(16);return t}function $(){let e="0x";for(var n=0;n<64;n++)e+=t(16*p()).toString(16);return new URLSearchParams(globalThis.location.search).get("hash")||("undefined"!=typeof tokenData&&tokenData?.hash?tokenData.hash:e)}A=$();let ee="\n vec3 mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n }\n\n vec2 mod289(vec2 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n }\n\n vec3 permute(vec3 x) {\n return mod289(((x * 34.0) + 10.0) * x);\n }\n\n // Noise\n float snoise2D(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n\n // Permutations\n i = mod289(i);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));\n\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n float fbm(const vec2 v, const int octaves, float frequency, float amplitude) {\n float total = 0.0;\n float maxAmplitude = 0.0;\n for(int i = 0; i < octaves; i++) {\n total += snoise2D(v * frequency) * amplitude;\n maxAmplitude += amplitude;\n frequency *= 2.0;\n amplitude *= 0.5;\n }\n return total / maxAmplitude;\n }\n\n",te="\n float screenEdgeDist(vec2 uv, const float falloff) {\n vec2 normalizedCoords = gl_FragCoord.xy / resolution;\n\n // Calculate distances to the nearest edges\n float distanceToLeftEdge = normalizedCoords.x;\n float distanceToRightEdge = 1.0 - normalizedCoords.x;\n float distanceToBottomEdge = normalizedCoords.y;\n float distanceToTopEdge = 1.0 - normalizedCoords.y;\n\n // Find the minimum distance to any edge\n float minDistanceToEdge = min(min(distanceToLeftEdge, distanceToRightEdge), min(distanceToBottomEdge, distanceToTopEdge));\n\n float scaledDistance = 1.0 - abs(2.0 * minDistanceToEdge - 1.0);\n\n // Apply customizable falloff\n float falloffEffect = pow(scaledDistance, falloff);\n\n return falloffEffect;\n }\n",ne="\n float randomNonDet(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n }\n",le="\n out vec2 vUv;\n\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n";const ie=e.Vector2;let ae=!1,se={countX:1,countY:1,index:{x:0,y:0}},oe=(e=!1)=>{let t=e?P:j,l=n((e?Y:Q)/se.countX),i=n(t/se.countY);return{width:l,height:i,xOff:se.index.x*l,yOff:se.index.y*i,yOffFlippedY:(se.countY-1-se.index.y)*i}},re=t=>{let n=t.uniforms,{width:l,height:i,xOff:a,yOffFlippedY:s}=oe();n.uTileOffset.value=new e.Vector2(a,s),n.uTileSize.value=new e.Vector2(l,i)},ce=()=>(!ae&&(()=>{ae=!0;let e=new URL(window.location.href),t=e.searchParams.get("tileCount"),n=e.searchParams.get("index");if(t){let e=parseInt(t);se.countX=e,se.countY=e}if(n){let[e,t]=n.split(",").map((e=>parseInt(e)));se.index.x=o(e,se.countX-1),se.index.y=o(t,se.countY-1)}})(),{uTileOffset:{value:new e.Vector2(0,0)},uTileSize:{value:new e.Vector2(Q,j)}});var de=[{name:"Faces",bg:[[.7409,.0057,69.9871]],line:[[.12,0,68]],base:[[.7995,.0104,53.9144]],accent:[[.55,.092,133],[.37,.1,8],[.47,.124,28],[.7,.112,90],[.48,.088,247],[.59,.048,197],[.78,.012,56.581],[.12,0,68],[.52,.12,342],[.71,.068,44],[.44,.04,299],[.21,.004,329],[.7883,.0264,44]],commonPool:!0,solo:!1},{name:"Chalks",bg:[[.6919,.0323,69.9871]],line:[[.1285578041548887,4.7918630361524376e-9,null]],stroke:[[.9104718532196331,.02929501882422003,89.58052190776175]],base:[[.7968,.033,55.4365]],accent:[[.4391005470961144,.053143667197297274,179.45284673806202],[.7430751481851373,.0929,39.83760570859084],[.7703,.0895,64.56344067218811],[.6641410434441858,.15689118437280108,37.13690468980104],[.7559,.0178,222.564179724743]],disabled:!1,commonPool:!0,solo:!1},{name:"Beach",bg:[[.6835,.03883960001602766,67.25848906440592]],stroke:[[.9372288972261885,.020696467664658196,67.57155893750883]],line:[[.23356138751632896,.02729114952576314,246.90070685897228]],base:[[.8371,.0215,57.0279]],accent:[[.2774185198607467,.04318925551193144,167.75274001919718],[.42064998654759594,.03120177133138129,171.32246538045877],[.4311384415174281,.02336516751567073,241.2330314983908],[.6176019379584577,.1270253885540799,74.1805651416355],[.7260022319511451,.09724578337934522,55.06470317899317],[.7582608113288266,.02549172589125699,166.85185191796654],[.8204,.023,61.9891]],commonPool:!0,solo:!1},{name:"Morning Sun In A Dusty Room",bg:[[.25615282357231434,.011591200093299888,338.1519820725431]],line:[[.14287287327771095,.004143654188326715,345.4391631242127],[.7742,.0276,98.479]],stroke:[[.9136637420289497,.02687443532425364,80.24542314462997]],base:[[.7783871111844314,.042589978975680454,25.529877185969667]],accent:[[.2152,.011591200093299888,338.1519820725431],[.4974379254425503,.08269393625659356,333.938678657093],[.6377751669772775,.16624575588870555,29.858240404234152],[.7303722440997971,.14878423535567212,65.78690162717032],[.525648519572251,.044624199378743616,227.89564437801943]],commonPool:!0,solo:!1},{name:"Jazz",stroke:[[.2866006793419412,.021957785534446477,88.03909075711272]],bg:[[.7399,.0328,69.58004864146267]],base:[[.8051,.0372,74.6117]],line:[[.1285578041548887,4.7918630361524376e-9,null]],accent:[[.6315375414148215,.1638,34.478822707810366],[.5221231161993111,.0802,231.97797627692054],[.7332,.1561,64.69716240181685],[.7786,.0269,54.0471]],disabled:!1,commonPool:!0,solo:!1},{name:"Beige Box",bg:[[.2169,.004109954650405697,264.48855986171543]],line:[[.1921,.004109954650405697,264.48855986171543],[.7094,.004109954650405697,264.48855986171543]],base:[[.7044,.0027,264.3],[.2582,0,264.15]],stroke:[[.6451555150878627,.1324103074498338,351.3679204443482]],accent:[[.2944,0,264.1525],[.6471384357175027,.0950806296946004,146.09535186981566],[.6248985136009452,.08343861458985488,258.09336743754636],[.6419604611344321,.1604756929950665,39.9727943299859],[.6451555150878627,.1324103074498338,351.3679204443482],[.7812,.1276,96.14554462682747],[.7098,.1359,63.701],[.6861,.007,63.701]],commonPool:!0,solo:!1},{name:"Master",bg:[[.6936,.0211,82.40092539697929]],line:[[.2507780863015607,.009572580032197206,67.3680640985574]],base:[[.7269,.0162,157.61886984444504]],stroke:[[.9060102804608031,.012170144621286422,23.7150415636807]],accent:[[.6295566765037485,.1211519827044528,67.32018448430034],[.7605,.0195,238.616994352628],[.6174604546514465,.05042117055871639,256.5164449583005],[.4181072443550769,.072,173.90831954879036],[.6627,.1667,37.60803793025025],[.8234,.0071,74.2545],[.7783,.073,8.0298]],commonPool:!0,solo:!1},{name:"New York Autumn",bg:[[.7037,.0281,65.28937708039064]],stroke:[[.8626142182586253,.08537649420452362,82.03909126824601]],line:[[.19548782481388519,.00430705323020645,264.468763979492]],base:[[.7661,.0329,58.25082050504636]],accent:[[.45478156079252346,.039285338382841796,179.22836606186138],[.7553531036330657,.08130837219892006,99.24794847558877],[.5594780208031984,.07916054354499198,245.43994841186026],[.42899728927916636,.04922887943462986,76.52219098535193],[.8309661998821414,.04281039028933322,48.183040275461394],[.7850648916204185,.1273241170717795,79.558262732039],[.8022,.1082,91.79312487991842],[.5727044802833001,.1271825150640351,18.826326398068147],[.5371544884294275,.13634924860871195,21.160585432853736]],commonPool:!0,solo:!1},{name:"The Coast",bg:[[.6974,.0085,76.58691599832048]],stroke:[[.8444869430616695,.08523591444134622,87.01376484878972]],line:[[.22755957415683586,.0015428045966122382,17.270340681712298]],base:[[.7669770002469423,.0030391208463875215,84.56153889362372]],accent:[[.3779357986919375,.0535,176.4086979076003],[.6184542058002529,.0765,130.0878133972343],[.8444869430616695,.0863,87.01376484878972],[.8204404719119529,.0562,13.36293462743373],[.6466292227896673,.1007,248.2503623167608],[.6163,.1335,21.160585432853736],[.7968000000000001,.01676,79.345]],commonPool:!0,solo:!1},{name:"Aged",bg:[[.7084,.0396,87.75614537114114]],stroke:[[.94095456060748,.015612821171329101,86.4264441546818]],line:[[.2703834919362128,.003498268640239951,48.59454667339406]],base:[[.7841,.021041287596747362,75.5028]],accent:[[.6599008372479219,.14410614712594896,43.767864491957255],[.5406041428443183,.0810794492722289,156.20612626175443],[.5030711080692698,.15264841257121137,26.608155858968416],[.7691417851736347,.1353050284474489,77.87710240074239],[.7874426063872318,.04659921665479499,51.68182155996902],[.467824859321765,.056096190272488924,217.56676918001241]],commonPool:!0,solo:!1},{name:"Ink & Colour",bg:[[.7601,.014,255.4795978283716]],stroke:[[.9553483843727791,.002877617626355211,84.55913178523588]],line:[[.23724829442832204,.009300030023333045,159.3038618360598]],base:[[.5326,.0294,169.58],[.5352,.1055,153.65],[.7482,.0675,265.537],[.5786,.1009,265.537]],accent:[[.3475,.065,169.58],[.4333,.08067410261737115,292.88016945552295],[.8007868908561364,.0333,7.942656494991638],[.6086666969575215,.1634,28.003190670134757],[.3195,.034575073883449464,254.02069392111645],[.6738,.1201,79.6718],[.8711,.00292,264.54],[.6613,.0632,169.58],[.5352,.1055,153.6549],[.6531,.1061,265.54]],disabled:!1,commonPool:!0,solo:!1},{name:"Oranges",bg:[[.705,.0354,65.1718]],stroke:[[.9912189562526743,.006931254927170287,88.6413010074412]],base:[[.7842,.0305,86.3684]],line:[[.18797280274608968,.026745997001574016,159.25756384014687]],accent:[[.35508002090426666,.043787467826530785,211.52484726500788],[.5510005837793092,.08755866639046411,103.27386758796968],[.691,.1582,47.266522185041936],[.7373,.1324,67.62887023877073],[.7999,.0316,88.72052641225343],[.7631,.0647,19.8072]],commonPool:!0,solo:!1},{name:"Henri",bg:[[.7213,.0319,80.6824944352112]],stroke:[[.7121124312829297,.09603422725607345,34.15613531599104]],line:[[.24303319779115856,.004923290798673418,355.16568727574077]],base:[[.8256,.0305,76.17859369988122]],accent:[[.4159,.0591,191.39940656052516],[.7920378039704564,.1352,73.45878915862028],[.7593,.0165,220.7288245953125],[.4637,.0738,237.7123227684075]],disabled:!1,commonPool:!0,solo:!1},{name:"Rand-ey",bg:[[.7426,.0171,87.52315695161104]],line:[[.19419793765469762,.0219,297.0814230776026]],stroke:[[.9076072420048279,.019870599528847212,87.51855970858247]],base:[[.595,.0433,247.9],[.7126,.0966,68.946],[.7791,0,64.059],[.5968,.1097,151.59]],accent:[[.575943267748716,.1486,29.4685],[.5129975835116938,.0741,305.527422000483],[.7538026010313094,.139,68.94572099685297],[.6147,.1332,247.9],[.8423,0,64.0592],[.53766,.1084,167.07]],disabled:!0,commonPool:!0,solo:!1},{name:"Olivetti",bg:[[.2222,.004109954650405697,264.48855986171543]],line:[[.234784254171478,.004109954650405697,264.48855986171543]],stroke:[[.7186588335782654,.1392507657144271,63.7012930132442]],base:[[.2551,0,34.30274488067005]],accent:[[.7186588335782654,.1392507657144271,63.7012930132442],[.6471384357175027,.0950806296946004,146.09535186981566],[.6248985136009452,.08343861458985488,258.09336743754636],[.6419604611344321,.1604756929950665,39.9727943299859],[.6451555150878627,.1324103074498338,351.3679204443482],[.8373623117765204,.15785248852128372,95.6270196002983],[.2582,.0037,275.8924],[.5803,.0037,275.8924]],disabled:!0,commonPool:!0,solo:!1},{name:"Toddler",bg:[[.7421,.0212,48.4352]],line:[[.18797280274608968,.026745997001574016,159.25756384014687]],stroke:[[.18797280274608968,.026745997001574016,159.25756384014687]],base:[[.6859848282821445,.008266766434931419,61.396302349703944],[.9349265127013049,.01153735356888476,84.57925253447382],[.7688,.0216,61.396302349703944]],accent:[[.3500879126177943,.0865,264.1433132212142],[.4453610930960556,.02928835497819446,336.8043193096847],[.569281111283594,.1860449489679648,25.02687693308303],[.5558543866168449,.054963958871380815,108.06205545681729],[.7052281079548163,.16337391917830385,43.93536507302679],[.8036,.1343,80.58696151433355],[.6763,.0745,108.06205545681729],[.7615,.0782,25.02687693308303]],disabled:!0,commonPool:!0,solo:!1}];let ue=(de.some((e=>e.solo))?de.filter((e=>e.solo)):de.filter((e=>!e.disabled))).map((e=>({name:e.name,disabled:e.disabled,commonPool:e.commonPool,base:e.base,bg:e.bg,line:e.line,accent:e.accent}))),he=de.filter((e=>e.commonPool)).map((e=>({name:e.name,disabled:e.disabled,commonPool:e.commonPool,base:e.base,bg:e.bg,line:e.line,accent:e.accent})));function me(e){return e*b/180}function pe(e){return function(e){return null!==e&&"object"==typeof e}(e)&&!Array.isArray(e)}function be(...e){const t={};for(const n of e)if(n)for(const e of Object.keys(n)){const l=n[e];if(Array.isArray(l))t[e]=[...l];else if(pe(l)){const n=t[e];pe(n)?t[e]=be(n,l):t[e]=be({},l)}else t[e]=l}return t}const ge=(e,t,n)=>(t-e)*n+e,fe=(e,t,n,l,i)=>ge(l,i,((e,t,n)=>(n-e)/(t-e))(t,n,e));function xe(e,t,n=g){if(0===t)return e;const l=n*Math.sign(e);return Math.round((e+l)/t)*t}function Ze(e,t,n){return o(r(e,t),n)}const ye=(e,t,n,l,i)=>Ze(fe(e,t,n,l,i),l,i),Ge=e=>e,We=e=>1-i(e*b/2),ve=e=>-(i(b*e)-1)/2,Le=e=>e<.5?(1-d(1-a(2*e,2)))/2:(d(1-a(-2*e+2,2))+1)/2;var Se,Xe,Ce;!function(e){e[e.horizontal=0]="horizontal",e[e.vertical=1]="vertical",e[e.perspective=2]="perspective",e[e.circle=3]="circle",e[e.wobbles=4]="wobbles",e[e.curves=5]="curves",e[e.rects=6]="rects",e[e.borderRect=7]="borderRect",e[e.triangle=8]="triangle",e[e.objects=9]="objects",e[e.used=10]="used"}(Se||(Se={})),function(e){e[e.front=0]="front",e[e.up=1]="up",e[e.right=2]="right",e[e.down=3]="down",e[e.left=4]="left"}(Xe||(Xe={})),function(e){e.border="border",e.scene="scene",e.none="none"}(Ce||(Ce={}));let Ve={layers:2,layerScaleMult:2.5,zDepthMaxMult:1,cropTo:Ce.none,forceYUp:!0,clampVertsToGrid:!1,maxDist:200,minDist:130,bnFreq:500,fieldFreq:1500,clampRotationTo:1,minSizeMult:1,maxSizeMult:.75,maxSides:5,minSides:3,perspective:2e4};var Ke,we;!function(e){e[e.color=0]="color",e[e.line=1]="line",e[e.palettecomplement=2]="palettecomplement",e[e.previous=3]="previous",e[e.base=4]="base",e[e.paletteOffset=5]="paletteOffset",e[e.shadow=6]="shadow",e[e.highlight=7]="highlight",e[e.randomAccent=8]="randomAccent",e[e.offset=9]="offset",e[e.offsetUp=10]="offsetUp",e[e.lightestOrDarkestBasedOnBg=11]="lightestOrDarkestBasedOnBg",e[e.brightnessBasedShadowOrHighlight=12]="brightnessBasedShadowOrHighlight",e[e.offsetDown=13]="offsetDown",e[e.darkest=14]="darkest",e[e.lightest=15]="lightest"}(Ke||(Ke={})),function(e){e.override="override",e.dominant="dominant",e.inCurveOrObject="inCurveOrObject",e.notInCurveOrObject="notInCurveOrObject",e.nonDominant="nonDominant",e.normalHigh="normalHigh",e.normalLow="normalLow",e.overlay="overlay",e.noop="noop"}(we||(we={}));let ke,Re,Te={scribbleChance:0,edgeSharpness:{min:.2,max:.2},scribbleStrength:{min:.5,max:.5},accumulationStrength:{min:1,max:1},materialHardness:{min:1,max:1},fillChance:100,fadeAtLineSegmentDistanceMult:{min:.5,max:1.5},fadeAtLineSegmentStrengthMult:{min:1,max:1},minDistanceMult:{min:5,max:5},linePressure:{min:.8,max:.9},brightnessHighLowThreshold:.75,fadeAtLineSegmentChance:0,detailMinScaleDivisor:30,ignoreLightingChance:0,colorMap:[[[1,Ke.color]],[[1,Ke.color]]],dominantMeshWeight:100,insetChance:0,insetDistance:{min:2,max:4},wobbleAmplitude:{min:.5,max:1},wobbleFreq:{min:.5,max:1},layerCountChances:[[0,0],[1,1],[2,2]],styleChances:[[3,"bnnoise"],[4,"directional"],[1,"wobbles"],[3,"bluenoise"]],lineTapering:{scale:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:1,max:1}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},lineWeight:{min:1.1,max:1.1},spatialOverride:{[we.overlay]:{fillChance:0}}},Me={scribbleChance:0,edgeSharpness:{min:.5,max:.5},scribbleStrength:{min:.3,max:.3},fillChance:100,accumulationStrength:{min:1,max:1},fadeAtLineSegmentDistanceMult:{min:.5,max:1.5},fadeAtLineSegmentStrengthMult:{min:1,max:1},colorMap:[[[1,Ke.color]]],fadeAtLineSegmentChance:100,brightnessHighLowThreshold:.75,ignoreLightingChance:0,detailMinScaleDivisor:30,minDistanceMult:{min:.75,max:.75},dominantMeshWeight:100,insetChance:0,insetDistance:{min:2,max:4},wobbleAmplitude:{min:2,max:3},wobbleFreq:{min:20,max:40},layerCountChances:[[1,1]],styleChances:[[1,"noise"],[0,"directional"],[0,"wobbles"],[0,"bluenoise"]],lineTapering:{scale:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:1,max:1}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},linePressure:{min:1,max:1},materialHardness:{min:1,max:1},lineWeight:{min:1.1,max:1.1},spatialOverride:{[we.overlay]:{fillChance:100,lineWeight:{min:2.5,max:2.5},fadeAtLineSegmentChance:0,insetChance:0,ignoreLightingChance:100,styleChances:[[1,"noise"],[0,"directional"],[0,"wobbles"],[0,"bluenoise"]],minDistanceMult:{min:.75,max:.75},lineTapering:{scale:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:1,max:1}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},layerCountChances:[[1,2]]}}},ze={[Se.horizontal]:0,[Se.vertical]:10,[Se.perspective]:0,[Se.circle]:10,[Se.wobbles]:0,[Se.objects]:8,[Se.curves]:10,[Se.rects]:5,[Se.borderRect]:10},Ye=[Se.horizontal,Se.vertical,Se.perspective],Pe={maxAccents:4,mutation:"none",dominantIsAccentChance:50,curveMap:ve,useNoiseLookup:!0,samplesForComplimentary:3,samplesForPaletteOffset:2,addBGContrast:!1,freqMultiplier:10,usePolyIDColorOffset:!0,singleAccent:!1,darksOnly:!1},Fe={count:1,outline:!0,colors:[[0,Ke.color],[0,Ke.offset],[0,Ke.base],[0,Ke.line],[0,Ke.darkest],[1,Ke.lightest]],colorOffsets:!1,size:{min:4,max:9}},He=[],Ie={default:1,min:.45,max:1.12,clamp:.001,influencesPressureMult:0,influencesBrightnessMult:1,influencesMinDistanceMult:.3,position:{x:-10005.5,y:-1e4,z:-12e3}},Ne={colors:!1,isLineColor:!1,count:50,warpChance:100,lineTapering:{scale:{in:{enabledChance:100,min:.5,max:.8},out:{enabledChance:100,min:.5,max:.8}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},length:{min:20,max:100},hardness:{min:1,max:1},thickness:{min:.5,max:5}},Ue=Ve,De={forceInsertCurvesChance:0,forceInsertObjectsChance:0},Oe={meshDensity:80,lineFilter:"none",meshInsetMuliplier:1,dominantLineInsetMultiplier:1,percentage:50,skipLongest:3,cropToDominantShape:!1,materialHardness:{min:.9,max:.95},colors:!1,backgroundColor:!1,lineTapering:{scale:{in:{enabledChance:100,min:.3,max:.6},out:{enabledChance:100,min:.3,max:.6}},fade:{in:{enabledChance:50,min:.1,max:.2},out:{enabledChance:50,min:.1,max:.2}}},linePressure:{min:.9,max:.95},thickness:{min:.5,max:3}},Be={countX:0,countY:0,marginX:0,marginY:0,w:0,h:0,scale:0},Qe=Te,je=Me,Je={enabled:!0,percentage:60,materialHardness:{min:.4,max:.4},lineTapering:{scale:{in:{enabledChance:100,min:.01,max:.1},out:{enabledChance:100,min:.01,max:.1}},fade:{in:{enabledChance:100,min:.01,max:.1},out:{enabledChance:100,min:.01,max:.1}}},linePressure:{min:.5,max:.5},lineWeight:{min:.6,max:.6}},Ae={margin:0,HVariance:{min:0,max:10,threshold:2,mean:1,stdDev:1},VVariance:{min:0,max:10,threshold:2,mean:1,stdDev:1},rects:{insetRectEnabled:!0,spiralRectsEnabled:!0},circles:{count:0,minRadius:2,maxRadius:30},wobble:{enabled:!1,count:1e10,layers:2,multiLayers:1,minLength:5,gridDivisions:1,warpFreq:{min:600,max:800},offsetMultiplier:1},perspectiveBox:{enabled:!0,threshold:2,mean:1,stdDev:1,count:1,firstFull:!0}},Ee=ze,_e=Ye,qe={layers:1,renderLightChance:0,ignoreLighting:!0,renderAccentChance:0,insetMult:2,maxWidth:80,spread:4,widthRange:.3,maxDivergen
nWarp:!1,lineTapering:Pi(a,J),lineWeight:J.num(i.min,i.max),lineColor:ve.line[0]}]};Wl.push(r)}],[function*(){const e={[sn.constructionLine]:0,[sn.background]:1,[sn.foreground]:2,[sn.detail]:3,[sn.walker]:3,[sn.overlay]:4,[sn.overlayOutline]:5};Wl.sort(((t,n)=>{if(e[t.category]<e[n.category])return-1;if(e[t.category]>e[n.category])return 1;let i=new nn;i.expands(t.polygon);let l=new nn;return l.expands(n.polygon),new zt(i.maxX,i.maxY).distanceTo(new zt(0,0))-new zt(l.maxX,l.maxY).distanceTo(new zt(0,0))}))}],[function*(){let e=new Map,n=0,i="◴ ◷ ◶ ◵".split(" "),l=function*(){let e=oe(!0),t=new nn;for(t.expands([new zt(e.xOff,e.yOff),new zt(e.xOff+e.width,e.yOff+e.height)]),t.expandByValue(10);Wl.length;){let e=Wl[0];if(e.readyForRender){if(e.detailObject?.length){let n=new nn;if(n.expands(e.polygon),t.intersects(n)){rn(e);for(let t=0;t<e.detailObject.length;t++)en(e.detailObject[t]);Xt.copyBufferToScreen(),yield{rendering:!0}}}let n=Wl.splice(0,1);an.push(...n)}else yield{rendering:!1}}Xt.copyBufferToScreen()}(),a=!1,s=[];for(let e=0;e<1e3;e++)s.push(E());let o=0;for(;!a;){if($l){yield{showUpdate:!0,message:"Rendering Paused",value:"press space to continue",isPercent:!1};continue}for(let t=0;t<Wl.length;t++){let i=Wl[t];if((i.category==sn.foreground||i.category==sn.detail||i.category==sn.overlay)&&!i.detailsProcessed){i.detailsProcessed=!0,e.set(n,!1);let t=n;Ii(i,s[o++%s.length]).then((()=>{e.set(t,!0)})),n++}}let r=l.next();a=r.done;let c=r.value?.rendering||!1,d=0;for(let e of Object.keys(wi))0==wi[e]&&(d+=1);let u=[...e.values()].reduce(((e,t)=>e+(t?0:1)),0);if(yield{showUpdate:!c&&(u>0||d>0||u>0),message:""+i[t(ll/4)%4],isPercent:!1,value:`${d>0?`Waiting on 1 of ${d} threads, `:"Waiting for"} ${u} jobs queued`},0==u&&0==Vi.length&&0==d&&a)break}yield{showUpdate:!1},Xt.copyBufferToScreen()},!0]],wl=new class{heap;constructor(e){this.heap=new Oi(1e10,e)}clear(){this.heap.clear()}topN(e){return this.heap.toArray().slice(0,e)}update(e){const t=new Set(this.heap.toArray());for(const n of e)t.has(n)?t.delete(n):this.heap.push(n);for(const e of t)this.heap.remove(e);return this.heap.toArray()}}((e=>{let{polyOverfitting:t,noiseOverfittingSpread:n,noiseOverfitFreq:i}=Qe,l=e.area;if(1!=t&&(l*=Xl.getPolygonsAtPoint(e.center.toArray()).length>0?1:t),n>0){let t=n/2;l*=Rt(mn(e.center.x,e.center.y,0,i,1-t,1+t),.001)}return Rt(l,.001)})),Kl=new Set;function Rl(e){let t={x:e.center[0],y:e.center[1],z:-100},n={width:e.width,height:e.height,depth:e.depth};return{faces:new Bi(t,e.rotationProps,n,e.sides,{x:e.perspectiveCenter[0],y:e.perspectiveCenter[1],z:-1e3},90,Y/P,.001,1e3,[{position:Ke.position,brightness:1},{position:{x:-Ke.position.x,y:-Ke.position.y,z:Ke.position.z},brightness:.95},{position:{x:0,y:Ke.position.y,z:-1e3},brightness:.2},{position:{x:0,y:-Ke.position.y,z:-1e3},brightness:.2}],!0).getFaces2D(),shapeArgs:e}}let kl,Tl=!1,Ml=(e,t,n,i=0)=>{let l=1e3*n,a=1e3*i;if(!Tl){let e=J.num(800,1600),t=Qe.noiseFieldCategoryInfluence;kl={[be.used]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[be.horizontal]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[be.vertical]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[be.perspective]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[be.circle]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[be.wobbles]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[be.curves]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[be.rects]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[be.borderRect]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[be.triangle]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)},[be.objects]:{freq:e,min:1,max:t,offset:J.int(-4e3,4e3)}},Tl=!0}let s=ei,o=ii(kl[e].freq,10,kl[e].offset,s),r=Tt(s(Rt(mn(t.x+kl[e].offset,t.y+kl[e].offset,kl[e].offset-a,kl[e].freq,0,1),.3)),o.min,o.max,kl[e].min,kl[e].max);return c(l*r)},zl=()=>[Ql,Ol,Bl,Al,jl,Jl,()=>!0],Yl=0,Pl=!1,Il=!1;function Hl(){I.save(),I.scale(U,U),Il||(I.fillStyle="#FFF",I.rect(0,0,Y,P),I.fill(),Il=!0)}function Fl(){I.restore()}function Nl(){Il=!1}function Ul(e,t="red",n=!0){if(e.length){Hl(),I.beginPath(),I.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;t++)I.lineTo(e[t].x,e[t].y);I.closePath(),I.lineCap="round",n?(I.fillStyle=t,I.fill()):(I.lineWidth=3,I.strokeStyle=t,I.stroke()),Fl()}}function Dl(e,t="red",n=!1,i=1){Hl(),I.beginPath(),I.lineCap="round",I.moveTo(e[0].x,e[0].y);for(let t=1;t<e.length;t++)I.lineTo(e[t].x,e[t].y);n&&I.closePath(),I.lineWidth=i,I.strokeStyle=t,I.stroke(),Fl()}function Ol(){Nl();for(let e of[...an,...Wl])if(e.category==sn.foreground){let t=e?.detailObjectProps?.inDominantShapes?.length>0;Ul(e.polygon,t?"blue":"red",!0),Ul(e.polygon,"black",!1)}return!1}function Bl(){Nl();for(let e of[...an,...Wl])if(e.category==sn.foreground){let t=jn(e.detailObject?.[0].lineColor||[0,0,0]);Ul(e.polygon,t,!0),Ul(e.polygon,"black",!1)}return!1}function Ql(){Nl();for(let e of[...an,...Wl])if(e.category==sn.foreground){let t=e.lightingIntensity||Ke.default,n=Kt(t,Ke.min,Ke.max,0,255);Ul(e.polygon,`rgba(${n},${n},${n},1)`,!0)}return!1}function Jl(){Nl();for(let e of[...an,...Wl])if(e.category==sn.foreground&&Ul(e.polygon,"black",!1),e?.detailObject?.length)for(let t of e.detailObject)for(let e of t.lines)Dl(e.map((e=>new zt(...e))),"black",!1,.5);return!1}function jl(){return Nl(),Zl&&Zl.getAllLines().forEach((e=>{Dl(e.line.map((e=>(new le).fromArray(e))),"black",e.meta.isClosed)})),!1}function Al(){return Nl(),xl&&xl.internalFaces().forEach(((e,t)=>{Ul(e.vertexlist,`rgba(${J.num(0,255)},${J.num(0,255)},${J.num(0,255)},0.9)`)})),!1}let El=!1;function _l(e){let{verts:t,parentSvg:n,strokeColor:i="black",strokeWidth:l=1,className:a="path",isClosed:s=!1}=e,o=`M ${t[0].x} ${t[0].y}`;for(let e=1;e<t.length;e++)o+=` L ${t[e].x} ${t[e].y}`;s&&(o+=" Z");const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d",o),r.setAttribute("fill","none"),r.setAttribute("stroke",i),r.setAttribute("stroke-width",l.toString()),r.setAttribute("class",a),n.appendChild(r),r}let ql=()=>{let e=document.querySelector("svg");e?(El=!1,e.remove(),k()):(R(),e=(()=>{let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("width",D+"px"),e.setAttribute("height",O+"px"),e.setAttribute("style","position: relative; background-color: white;"),e.setAttribute("viewBox",`0 0 ${Y} ${P}`),e.setAttribute("preserveAspectRatio","xMinYMin meet"),e.setAttribute("xmlns","http://www.w3.org/2000/svg");let t=[[new zt(0,5),new zt(0,0),new zt(5,0)],[new zt(0,P-5),new zt(0,P),new zt(5,P)],[new zt(Y-5,0),new zt(Y,0),new zt(Y,5)],[new zt(Y-5,P),new zt(Y,P),new zt(Y,P-5)]];for(let n=0;n<t.length;n++)_l({verts:t[n],parentSvg:e,strokeWidth:2,className:"marker",isClosed:!1,strokeColor:"rgb(1, 0, 0)"});for(let t of[...Wl,...an])if(t.category==sn.foreground){if(_l({verts:t.polygon,parentSvg:e,strokeWidth:2,className:"outline",isClosed:!0,strokeColor:t?.detailObjectProps?.inDominantShapes?.length>0?"rgb(0, 0, 0)":"rgb(1, 1, 1)"}),!t?.detailObject?.length)continue;for(let n of t?.detailObject)if("detail"===n.type)for(let t of n?.lines)_l({verts:t.map((e=>new zt(...e))),parentSvg:e,strokeWidth:1,className:"detail",strokeColor:"rgb(5, 5, 5)"})}else if(t.category==sn.walker){if(!t?.detailObject?.length)continue;for(let n of t.detailObject)for(let t of n.lines)_l({verts:t.map((e=>new zt(...e))),parentSvg:e,strokeWidth:4,className:"topline",isClosed:!1,strokeColor:"rgb(10, 10, 10)"})}else if(t.category==sn.overlay){let n=2;for(let i=0;i<n;i++)_l({verts:t.polygon,parentSvg:e,strokeWidth:2,className:"oerlay",isClosed:!0,strokeColor:"rgb(15, 15, 15)"})}return e})(),document.body.appendChild(e),El=!0)},$l=!1;const ea=()=>{zl()[Yl]()?(H(),k()):(R(),M.style.display="block"),Pl=!Pl,Yl=(Yl+1)%zl().length},ta=()=>{$l=!$l};var na;document.complete=!1,(()=>{new URL(window.location.href).searchParams.get("noFrame")&&(j=0);const{innerWidth:n,innerHeight:i}=window;S=document.createElement("canvas"),S.style.backgroundColor="#000",K=S.getContext("webgl2",{colorSpace:"display-p3",preserveDrawingBuffer:!0,stencil:!1,alpha:!1,premultipliedAlpha:!1}),X=new e.WebGLRenderer({canvas:S,context:K,preserveDrawingBuffer:!0,precision:"highp",alpha:!1,premultipliedAlpha:!1,antialias:!1,stencil:!1,depth:!0,powerPreference:"high-performance"}),w=!!K.getExtension("OES_texture_float_linear"),K.getParameter(K.MAX_UNIFORM_BLOCK_SIZE),X.setClearColor(new e.Color(1,1,1),1),C=X.capabilities.maxTextureSize,V=X.capabilities.getMaxAnisotropy(),X.shadowMap.enabled=!0,X.outputColorSpace=e.DisplayP3ColorSpace,X.shadowMap.type=e.PCFSoftShadowMap,document.body.appendChild(S),M=document.createElement("canvas"),M.style.backgroundColor="#000",z=M.style,I=M.getContext("2d",{alpha:!1,colorSpace:"display-p3"}),document.body.appendChild(M),H(),Y=t(1584),P=t(2200);let l=j/100*o(n,i);n<i*F?(O=t(1/F*(n-l)),D=t(n-l)):(O=t(i-l),D=t((i-l)*F)),X.setSize(D,O),X.setPixelRatio(N),B=D*N,Q=O*N,((e,t)=>{M.width=e,M.height=t,z.width=D+"px",z.height=O+"px"})(B,Q),U=B/Y})(),na=$(),J=new A(na||""),(()=>{let t=document.createElement("a");addEventListener("keydown",(n=>{if("s"===n.key&&El){let e=document.querySelector("svg");if(!e)return;let n=_+".svg";t.setAttribute("download",n);const i=new Blob([e.outerHTML],{type:"image/svg+xml"});t.href=URL.createObjectURL(i),t.click()}else if("s"===n.key){let e=_+".png";se.countX>1&&(e=`${_}-${se.index.x}-${se.index.y}.png`),t.setAttribute("download",e),S.toBlob((e=>{t.href=URL.createObjectURL(e),t.click()}))}"x"===n.key&&function(){v({showUpdate:!0,message:"Sending PNG Export",value:_});let t=new e.WebGLRenderTarget(B,Q,{anisotropy:V,colorSpace:e.DisplayP3ColorSpace,minFilter:e.LinearFilter,magFilter:e.LinearFilter,format:e.RGBAFormat,type:e.FloatType,internalFormat:"RGBA32F"});Lt(Xt.getReadBuffer().texture,t);const n=new Float32Array(B*Q*4);X.readRenderTargetPixels(t,0,0,B,Q,n);let i=""+_;if(se.countX>1&&(i=`${_}-tiled-${se.index.x}-${se.index.y}`),void 0!==window?.electronAPI?.sendPixelData){const e=Buffer.from(n.buffer);window?.electronAPI.sendPixelData({buffer:e,width:B,height:Q,filename:i})}else window.framebuffer=n;setTimeout((()=>{L()}),1e3)}(),"Space"===n.code&&ta(),"v"===n.key&&(Pl&&ea(),ql()),"d"===n.key&&(El&&ql(),ea())}))})(),document.metaData=(()=>{We=[J.num(-1,1),J.num(-1,1)];for(let e=0;e<1e3;e++)we.push(J.dec());ve=J.choice(ue),J.weightedChoice([3,rt],[1,ct],[1,dt])();let e={"Artist Curated":q.includes(_),"Input Hash":_};const t=[{name:"Name",value:_e},{name:"Meta",value:e},{name:"Divisions",value:je},{name:"Division Props",value:Qe},{name:"Line Removal",value:Ae},{name:"Division Chances",value:Object.fromEntries(Object.entries(Fe).map((([e,t])=>[be[Number(e)],t])))},{name:"lighting",value:Ke},{name:"color props",value:Oe},{name:"topLines",value:Re},{name:"dominantLines",value:Me},{name:"fillStyles",value:Pe},{name:"detailStyles",value:Ye},{name:"constructionLineProps",value:He},{name:"sceneObjects",value:ke},{name:"colorProps",value:Oe},{name:"curveProps",value:Ue},{name:"fillMargin",value:Be},{name:"grid",value:ze}];for(let e of t);return e})(),S.addEventListener("click",(e=>{let t=e.clientX,n=e.clientY,i=S.getBoundingClientRect();t-=i.left,n-=i.top;let l=new zt(t*N/U,n*N/U);for(let e of[...an,...Wl])e.category==sn.foreground&&Tn(e.polygon,l)})),sl();
});for(let i=e.x;i<t.x;i+=ze.scale/2)J.gaussianBool(He.VVariance.threshold,He.VVariance.mean,He.VVariance.stdDev)||l.push({id:Nn(),meta:{lineCategory:be.vertical},line:[[i+J.num(-ze.scale*s,ze.scale*s),e.y-ze.scale*n],[i+J.num(-ze.scale*s,ze.scale*s),t.y+ze.scale*n]]});vl.push(...i,...l)})(i,l),yl=function(e,t){let n;if(!He.perspectiveBox.enabled)return;let i=[e,new zt(t.x,e.y),t,new zt(e.x,t.y)].map((e=>e.toArray())),l=new Ln(i,[[0,1],[1,2],[2,3],[3,0]]);for(let e=0;e<He.perspectiveBox.count;e++){let e,t=l.internalFaces(),n=J.choice(t),i=n.aabb,a=J.bool(50),s=o(i.height,i.width)/4;if(a){let t=J.num(i.minX+s,i.maxX-s);e=[[t,i.minY],[t,i.maxY]]}else{let t=J.num(i.minY+s,i.maxY-s);e=[[i.minX,t],[i.maxX,t]]}l.splitFaceByPolyLine(n,e)}let a=l.internalFaces(),s=!1,r=!1,c=!1,d=He.perspectiveBox.firstFull;for(let e of a){if(-1==He.perspectiveBox.count)break;let t=e.aabb,i=t.width*J.num(.75,1.25),l=t.height*J.num(.75,1.25),a=!(!d||c)||J.bool(s?0:50),o=!(!d||c)||J.bool(r?0:50);a&&(r=!0),o&&(s=!0);let u=[a?Y/2:t.center.x,o?P/2:t.center.y];c||(n=u),c=!0,Fe[be.perspective]>1&&vl.push(...Un({gStdDev:He.perspectiveBox.threshold,gMean:He.perspectiveBox.mean,gThreshold:He.perspectiveBox.stdDev,boxCenter:u,perspectiveCenter:[t.center.x+J.int(-i/4,i/4),t.center.y+J.int(-l/4,l/4)],width:a?4*Y:i*J.num(.75,1.25),height:o?P:l*J.num(.75,1.25),centerBoxMaskDimensions:[J.int(1,i/ze.scale*.5),J.int(1,l/ze.scale*.5)]}).map((e=>({id:Nn(),line:e,meta:{lineCategory:be.perspective}}))))}return n}(i,l),function(){for(let e=0;e<He.circles.count;e++){let e=Rt(J.num(ze.scale*He.circles.minRadius,ze.scale*He.circles.maxRadius),ze.scale),t=e/2,n=[Y/2+J.num(-Y/2+t,Y/2-t),P/2+J.num(-P/2+t,P/2-t)],i=J.num(0,360),l=On({center:n,radius:e,startAngle:i,endAngle:i+J.int(25,360)});l.length>3&&vl.push({id:Nn(),line:l,meta:{lineCategory:be.circle}})}}(),function(){if(!He.rects.spiralRectsEnabled)return;let e=Pt(new zt(J.num(.4*Y,.6*Y),J.num(.4*P,.6*P))).toArray(),t=J.num(0,22.5)*J.choice([-1,1]),n=ze.scale*J.int(5,10),i=J.num(0,360),l=ze.scale*(2*J.int(1,8));for(;n<P;){let a=Dn({width:n,height:n,center:e,angle:i});vl.push({id:Nn(),line:a,meta:{lineCategory:be.rects,isClosed:!0}}),n+=l,i+=t}}(),function(){if(!He.rects.insetRectEnabled)return;let e=2*He.margin+ze.scale*(2*J.int(1,4)),t=Pt(new zt(J.num(Y/2,Y/2),J.num(P/2,P/2))).toArray(),n=Dn({width:Y-e,height:P-e,center:t,angle:J.num(-1,1)});vl.push({id:Nn(),line:n,meta:{lineCategory:be.borderRect,isClosed:!0}})}();let a=function(){let e=J.num(He.wobble.warpFreq.min,He.wobble.warpFreq.max),t=[];for(let n=0;n<He.wobble.layers;n++){let i=me(180/He.wobble.layers*n);for(let n=0;n<He.wobble.multiLayers;n++){let l=n*He.wobble.offsetMultiplier,a={warpStrength:e,rotationAngleAddition:i,wobbleOffset:l};ki.push(a);let s=new nn;s.expands([new zt(-Y/4,-P/4),new zt(Y+Y/4,P+P/4)]);let o=s.vertexList.map((e=>e.toArray())),r=Rt(ze.scale/He.wobble.gridDivisions,.1),c=Ri({streamlineWorkerProps:{vectorFieldType:"bnnoise",addOutline:!1,vectorFieldNoiseProps:{warpStrength:Rt(e,.01),rotationAngleAddition:Rt(i+J.num(-.1,.1),.01),wobbleOffset:l,wobbleDetail:J.int(0,1)},postProcessingArgs:{directional:!1,wobbleFreq:.5,wobbleAmplitude:.5},maxStreamlines:He.wobble.count,minLength:Rt(ze.scale*He.wobble.minLength,.1),maxLength:Rt(3*P,.1),stepSize:r/4,minDistance:r,bounds:{topLeft:o[0],bottomRight:o[2]},boundingGeometry:o},noiseSeed:un,randomSeed:E(J)});t.push(c)}}return t}(),s=new Map,r=0,c="◴ ◷ ◶ ◵".split(" "),d=Array(a.length);for(let e=0;e<a.length;e++){let t=a[e];s.set(r,!1);let n=r;t.then((t=>{d[e]=t,s.set(n,!0)})),r++}for(;;){let e=[...s.values()].reduce(((e,t)=>e+(t?0:1)),0);if(yield{showUpdate:e>0,message:""+c[t(ll/4)%4],isPercent:!1,value:`${e>0?"Pausing for":"Waiting for"} ${e} tasks`},0==e)break}for(let e=0;e<d.length;e++){let t=d[e];if(Fe[be.wobbles]>0)for(let n of t)vl.push({line:n,id:Nn(),meta:{lineCategory:be.wobbles,lineSubCategory:e}})}}],[function*(){let e=He.margin+ze.marginX,t=He.margin+ze.marginY,n=new le(e,t),i=new le(Y-e,P-t);Zl=new Jn(ze.scale/2,vl),Gl=[n,new zt(i.x,n.y),i,new zt(n.x,i.y)].map((e=>e.toArray())),fl=new Ln(Gl,[[0,1],[1,2],[2,3],[3,0]])}],[function*(){let{maxWidth:e,widthRange:t,spread:n,maxDivergence:i,tension:l,maxPointUse:a,layers:s,maxLinePoints:o,pointsToConsider:r,insetMult:c}=Ue,d=Zl.getAllLines().filter((e=>e.meta.lineCategory==be.objects&&e.meta.isClosed&&J.bool(50))).map((e=>Yn(e.line.map((e=>new zt(...e))))));for(let u=0;u<s;u++){let s=function(t,i){return mn(t,i,0,400,e,e*n)},u=He.margin+e*c,h=He.margin+e*c,m=new ul({maxDist:e*n,bounds:{topLeft:It(new zt(u,h)).toArray(),bottomRight:It(new zt(Y-u,P-h)).toArray()},noiseField:s,seedPoints:d}),p=m.generate();for(let e of p)yield;let g,b=m.kTree,f=[],x=new Set,Z=new Map,y=e=>{x.add(g);let t=Z.get(e)||0;Z.set(e,t+1),Z.get(e)>=a&&b.remove(e)};for(;!(b.count<=0);){if(!g){let e={point:new zt(J.num(0,Y),J.num(0,P)),minDist:1/0};g=b.findNearest(e),y(g)}let e=J.choice(b.findKNearest(g,r).filter((e=>!x.has(e)&&e.point.distanceTo(g.point)<g.minDist*i)));!e||x.size>=o||b.count<=0?(f.push([...x].map((e=>e.point))),x=new Set,g=null):(g=e,y(g))}let G=[];for(let e of f){if(e.length<3)continue;let t=bl(gl(e,{tension:J.num(l.min,l.max),cyclic:!1}),6,!1).map((e=>new zt(e.x,e.y)));G.push(t)}for(let n of G){if(n.length<3)continue;let i=cl(n.map((e=>e.toArray())),J.int(e*(1-t),e*(1+t)),120);vl.push({line:i,id:Nn(),meta:{lineCategory:be.curves,isClosed:!0}}),Zl.addLine(i,{lineCategory:be.curves,isClosed:!0})}}}],[function*(){for(let e=0;e<ke.layers;e++){let{maxDist:t,minDist:n,bnFreq:i,minSizeMult:l,maxSizeMult:a,fieldFreq:s,maxSides:o,minSides:r,clampVertsToGrid:c,clampRotationTo:d,layerScaleMult:u,perspective:h}=ke,m=0==e?1:e*u,p=ke.cropTo==xe.border?Gl:ke.cropTo==xe.scene?[[0,0],[Y,P]]:null,g=null;null!==p&&(g=new nn,g.expandsByPoint(p));let b=function(e,l){return mn(e,l,0,i,n*m,t*m)},f=new ul({maxDist:t*m,bounds:{topLeft:Gl[0],bottomRight:Gl[2]},noiseField:b}).generate(),x=J.num(150,300)*J.choice([-1,1]),Z=40;for(let t of f){let n=ke.forceYUp?0:mn(t.point.x,t.point.y,1e3,s,-40,Z),i=mn(t.point.x+1e3,t.point.y+1e3,2e3,s,-(Z+x),Z+x),c=ke.forceYUp?0:mn(t.point.x-1e3,t.point.y-1e3,-1e3,s,-40,Z),u={w:l,h:l,d:l},m={w:a,h:a,d:a},p=J.weightedChoice([1,"w"],[3,"h"],[0,"d"]),b=J.weightedChoice([1,1],[3,2],[1,3]);u[p]*=b,m[p]*=b;let f=Rl({sides:J.easedInt(ei,r,o),perspectiveCenter:yl,perspectiveStrength:h,width:J.num(t.minDist*u.w,t.minDist*m.w),height:J.num(t.minDist*u.h,t.minDist*m.h),depth:J.num(t.minDist*u.d,t.minDist*m.d*(0==e?ke.zDepthMaxMult:1)),center:[t.point.x,t.point.y],rotationProps:{x:Rt(n,d),y:Rt(i,d),z:Rt(c,d)}}),y=J.int(0,1e10),G=f.faces.reduce(((e,t)=>e+zn(t.vertices.map((e=>new zt(...e))))),0);f.faces=f.faces.filter((e=>null===g||!e.vertices.some((e=>!g.containsPoint(new zt(...e))))));for(let e of f.faces)e.vertices=e.vertices.map((t=>{if(!(t[0]>=Gl[0][0]&&t[1]>=Gl[0][1]&&t[0]<=Gl[2][0]&&t[1]<=Gl[2][1]))return t;let n=new nn;n.expandsByPoint(e.vertices),n.expandByValue(20);let i=Zl.getLinesIntersectingOrContainedWithinAABB(n).filter((e=>{let t=e.meta.lineCategory;return t==be.horizontal||t==be.vertical||t==be.perspective}));if(!i.length)return t;let l=i.reduce(((e,n)=>fn(t,e.line)<fn(t,n.line)?e:n),i[0]);return bn(t,l.line)}));for(let e of f.faces)Xl.addPolygon(e.vertices,{category:"face",meta:{id:y,lightingIntensity:e.lighting,normal:e.normal,area:zn(e.vertices.map((e=>new zt(...e)))),totalArea:G}});Cl.push(f),yield{showUpdate:!0,message:"Generating Scene",isPercent:!1,value:""}}}let e=Xl.getAllPolygons(),t=.8*Math.min(...e.map((e=>e.meta.meta.lightingIntensity))),n=.95*Math.max(...e.map((e=>e.meta.meta.lightingIntensity)));e.forEach((e=>{const i=e.meta.meta.lightingIntensity;let l=Tt(i,t,n,0,1),a=Tt($n(l),-0,1,Ke.min,Ke.max);e.meta.meta.lightingIntensity=a}));for(let t of e){let e={line:t.verts,id:Nn(),meta:{lineCategory:be.objects,id:t.meta.meta.id,isClosed:!0}};vl.push(e),Zl.addLine(t.verts,e.meta)}}],[function*(){let e=fl.internalFaces().sort(((e,t)=>t.area-e.area))[0],n=e.area,i=n,l=e,s=new Set,r=Ne;for(Fe[be.objects]>0&&r.push(be.objects);i/n>.95+b;){let e=Zl.getAllLines().filter((e=>e.meta.lineCategory==be.vertical||e.meta.lineCategory==be.horizontal)),t=J.choice(e);fl.splitFaceByPolyLine(l,t.line,t.meta.isClosed,!1),s.add(t),l=fl.internalFaces().sort(((e,t)=>t.area-e.area))[0],i=l.area,yield{showUpdate:!0,message:"Searching for initial structure",isPercent:!0,value:o(.95*n/i*100,100)}}fl.cleanupTrailingEdges();let c=!0,d=new Map;for(let e=0;e<je;e++){if(e%t(je/5)==0&&e>0&&e<t(je-je/5)){let e=new Di(fl,.75).findDominantPaths(),t=[];for(let n of e)t.push(n);[...t.filter((e=>e.curviness>.02)).sort(((e,t)=>t.length-e.length)).slice(0,2),...t.filter((e=>e.curviness<.02)).sort(((e,t)=>t.length-e.length)).slice(0,2)].forEach((e=>{let t=e.vertices;if(c){for(let e=1;e<t.length-2;e++){let n=[t[e],t[e+1]],i=fl.findHedge(n[0].x,n[0].y,n[1].x,n[1].y);i?.face?.area>0&&fl.removeEdge(n[0].x,n[0].y,n[1].x,n[1].y)}c=!1}else{let e=[t[0],t[1]],n=e[0].distanceTo(e[1]);for(let i=1;i<t.length-2;i++){let l=t[i].distanceTo(t[i+1]);l>n&&(e=[t[i],t[i+1]],n=l);let a=fl.findHedge(e[0].x,e[0].y,e[1].x,e[1].y);a?.face?.area>0&&a.twin.face?.area>0&&fl.removeEdge(e[0].x,e[0].y,e[1].x,e[1].y)}}})),fl.cleanupDegenerateHoles(),fl.cleanupTrailingEdges()}fl.cleanupTrailingEdges(),fl.insertPolygon(Gl,!0);let i,l=fl.internalFaces();wl.update(l);let s=wl.topN(1e3).filter((e=>!Kl.has(e.id))),o=[];for(let e of s){let t=new Ln([],[]);t.insertPolygon(e.vertexlist.map((e=>e.toArray())),!0);let l=t.faces[0],a=new Set,s=()=>{const n=[];for(let i=0;i<o.length;i++){const s=o[i];if(a.has(s.constructionLine.id))continue;const r=s.constructionLine.meta.lineCategory,c=s.constructionLine.meta.lineSubCategory;if(Ml(r,e.aabb.center,Fe[r],c)<=0)continue;const d=s.constructionLine.line;let u=s?.constructionLine?.meta?.aabb;if(u||(u=new nn,u.expandsByPoint(d),s.constructionLine.meta.aabb=u),!e.aabb.intersects(u))continue;const h=s?.constructionLine?.meta?.isClosed,m=t.splitFaceByPolyLine(l,d,h,!0);m?.lines?.length>0&&m?.intersectionCount>=2&&n.push(s)}o=n},r=e,c=n/10;if(e.area>c){let t=100,n=new nn;for(n.expand(e.center);!o.length&&n.area<c&&n.area<e.area;){n.expandByValue(t),o=Zl.linesIntersectingAABB(n),t+=50,s();for(let e of o)a.add(e.constructionLine.id)}}if(o.length||(o=Zl.getLinesIntersectingFace(r,!1),s()),o.length>0){i={face:e,intersecting:o},t.dispose();break}}if(!i)break;let{face:r,intersecting:h}=i,m=new Map;Object.values(be).forEach((e=>{"string"!=typeof e&&0!=Fe[e]&&m.set(e,h.filter((t=>{let n=t.constructionLine.meta;return n.lineCategory===e&&!(n.unableToSplitFaces&&n.unableToSplitFaces.has(r.id))})))}));let p=[];if(m.forEach(((e,t)=>{if(!e.length)return;let n=Ml(t,r.aabb.center,Fe[t]);if(n>0)if(e.some((e=>e.constructionLine.meta?.lineSubCategory))){let n=new Map;e.map((e=>{let t=e.constructionLine.meta.lineSubCategory;n.has(t)?n.get(t).push(e):n.set(t,[e])}));for(let[e,i]of n){let n=Ml(t,r.aabb.center,Fe[t],e);p.push([n,i.reduce(((e,t)=>{let n=fn(r.aabb.center.toArray(),t.constructionLine.line);return n<e.distance-b?{distance:n,line:t}:e}),{distance:1/0,line:null}).line])}}else p.push([n,e.reduce(((e,t)=>{let n=fn(r.aabb.center.toArray(),t.constructionLine.line);return n<e.distance-b?{distance:n,line:t}:e}),{distance:1/0,line:null}).line])})),Ee>0){let e=h.filter((e=>e.constructionLine?.meta?.used&&!e.constructionLine?.meta?.unableToSplitFaces?.has(r.id)&&e.constructionLine.meta.lineCategory==be.objects)).reduce(((e,t)=>{let n=fn(r.aabb.center.toArray(),t.constructionLine.line);return n<e.distance?{distance:n,line:t}:e}),{distance:1/0,line:null}).line;e&&p.push([Ml(be.used,r.aabb.center,Ee),e])}if(p=p.filter((e=>e[1])),0==p.length){Kl.add(r.id);continue}let g=J.weightedChoice(...p),f=fl.splitFaceByPolyLine(r,g.constructionLine.line,g.constructionLine.meta.isClosed,!1,J.bool(Qe.longestSplitOnlyChance));if(f&&(g.constructionLine.meta.used=!0),!f&&(d.set(r.id,(d.get(r.id)||0)+1),e--,!g.constructionLine.meta.unableToSplitFaces&&(g.constructionLine.meta.unableToSplitFaces=new Set),g.constructionLine.meta.unableToSplitFaces.add(r.id),d.get(r.id)>5)){let e=fl.faces.find((e=>e.id==r.id));for(let t of e.hedges.filter((t=>t.face==e)))fl.removeEdge(t.origin.x,t.origin.y,t.twin.origin.x,t.twin.origin.y);fl.cleanupTrailingEdges()}yield{showUpdate:!0,message:"Composing",isPercent:!0,value:t(100*(u=e/je,1-a(1-u,3)))}}var u}],[function*(){Cl.sort(((e,t)=>e.faces.reduce(((e,t)=>e+zn(t.vertices.map((e=>new zt(...e))))),0)-t.faces.reduce(((e,t)=>e+zn(t.vertices.map((e=>new zt(...e))))),0))),Cl=En(Cl.slice(t(Cl.length/4),n(Cl.length/4*2)));for(let e=0;e<Cl.length;e++){if(J.bool(100-Te.forceInsertObjectsChance))continue;let t=Cl[e];for(let e of t.faces)J.bool(50)||(fl.insertPolygon(e.vertices,!0),J.bool(50)&&fl.removeEdgesInsidePolygon(e.vertices))}let e=vl.filter((e=>e.meta.lineCategory==be.curves)).sort(((e,t)=>{let n=zn(e.line.map((e=>new zt(...e))));return zn(t.line.map((e=>new zt(...e))))-n}));for(let n=0;n<e.length;n++){if(J.bool(100-Te.forceInsertCurvesChance))continue;let i=e[n];n<t(e.length/10)&&(fl.insertPolygon(i.line,!0),fl.removeEdgesInsidePolygon(i.line,10))}}],[function*(){let e=fl.internalFaces().filter((e=>e.area>1)),n=e.length*Ae;for(let i=0;i<n&&!(e.length<10);i++){let l=J.choice(e.sort(((e,t)=>{const n=e.area-t.area;return Math.abs(n)<b?e.id-t.id:n})).slice(0,100));if(!l)continue;let a=l.hedges.filter((e=>e.twin&&e.face!==e.twin.face&&e.twin.face.area>0&&e.face.area>0)),s=J.choice(a);s&&fl.removeEdge(s.origin.x,s.origin.y,s.twin.origin.x,s.twin.origin.y),fl.cleanupTrailingEdges(),e=fl.internalFaces().filter((e=>e.area>1)),yield{showUpdate:!0,message:"Deconstructing",isPercent:!0,value:t(i/n*100)}}}],[function*(){fl.insertPolygon(Gl,!0)}],[function*(){let e=new Di(fl,.4).findDominantPaths();for(let t of e)Ll.push(t),yield{showUpdate:!0,message:"Walking Paths",isPercent:!1,value:Ll.length}}],[function*(){xl=new Ln(Gl,[[0,1],[1,2],[2,3],[3,0]]);let e=Me.meshDensity,t=xl.internalFaces()[0].area;xl.dispose();let n=P/15,i=[J.num(Y/2,Y/2),J.num(P/2-n,P/2+n)],l=Ll.sort(((e,t)=>fn(i,e.vertices.map((e=>e.toArray())))-fn(i,t.vertices.map((e=>e.toArray()))))).slice(0,Ll.length),a=[],s=0;for(;s<e&&l.length>0;){let n=l.shift();xl.insertPolygon(n.vertices.map((e=>[e.x,e.y])),!1),a.push(n),s=xl.internalFaces().reduce(((e,t)=>e+t.area),0)/t*100,yield{showUpdate:!0,message:"Defining subject",isPercent:!0,value:s/e*100}}xl.cleanupTrailingEdges();let o=xl.vertices.filter((e=>e.y<.75*P&&Cn(e.toArray(),Gl)));for(let e of o)for(let t of e.hedgelist){let e=[t.origin.x,t.origin.y],n=[t.twin.origin.x,t.twin.origin.y];if(Cn(e,Gl)&&Cn(n,Gl)){if(t.origin.distanceTo(t.twin.origin)<10)continue;xl.removeEdge(e[0],e[1],n[0],n[1])}}xl.cleanupTrailingEdges(),Sl.push(...a.sort(((e,t)=>t.length-e.length)))}],[function*(){let e=Ll.filter((e=>{let t=(Be.cropToMargin?Be.margin:He.margin)*Me.dominantLineInsetMultiplier;return!e.vertices.some((e=>e.x<=t||e.x>=Y-t||e.y<=t||e.y>=P-t))}));"none"!==Me.lineFilter&&(e=e.filter((e=>{let t=e.curviness>.01;return"curves"==Me.lineFilter?t:!t})));let n=[];for(let i of e){let e=t(i.vertices.length/2),l=!1;for(let t of n){let n=0;for(let a of i.vertices){for(let i of t.vertices)if(a.isEqualTo(i)&&(n++,n>=e)){l=!0;break}if(l)break}if(l)break}l||n.push(i)}e=n,Me.cropToDominantShape&&(e=e.filter((e=>xl.getFacesAtPoint(e.vertices[0].toArray()).length>0&&xl.getFacesAtPoint(e.vertices[e.vertices.length-1].toArray()).length>0)));let a=t(e.length/100*Me.skipLongest),s=e.sort(((e,t)=>t.length-e.length)).slice(a,e.length/100*Me.percentage+a),o=ve.bg[0][0]>.5?ve.line[0]:[...ve.line,...ve.base,...ve.accent].filter((e=>e[1]<.05)).reduce(((e,t)=>t[0]>e[0]?t:e),ve.line[0]),r=[...ve.line,...ve.base,...ve.accent].filter((e=>e[1]<.05)).reduce(((e,t)=>t[0]>e[0]?t:e),ve.line[0]);for(let e of s){if(J.bool(50)){let t=e.vertices.reduce(((t,n,i)=>0===i?0:t+n.distanceTo(e.vertices[i-1])),0)/J.num(10,15),n=e.vertices[1].angleTo(e.vertices[0]),a=new zt(e.vertices[0].x+l(n)*t,e.vertices[0].y+i(n)*t),s=e.vertices[e.vertices.length-2].angleTo(e.vertices[e.vertices.length-1]),o=new zt(e.vertices[e.vertices.length-1].x+l(s)*t,e.vertices[e.vertices.length-1].y+i(s)*t);e.vertices=[a,...e.vertices,o]}let t=new nn;t.expands(e.vertices),t.expandByValue(Me.thickness.max+3);let n={polygon:t.vertexList,faceRef:null,category:sn.walker,readyForRender:!0,detailObject:[{lines:[e.vertices.map((e=>e.toArray()))],noiseOffset:[J.num(-1,1),J.num(-1,1)],closedPolyOrLine:!1,materialHardness:J.num(Me.materialHardness.min,Me.materialHardness.max),linePressure:J.num(Me.linePressure.min,Me.linePressure.max),canWarp:!0,lineTapering:Pi(Me.lineTapering,J),lineWeight:J.num(Me.thickness.min,Me.thickness.max),lineColor:Me.backgroundColor?r:Me.colors?J.choice([...ve.accent,...ve.base,...ve.line]):o}]};Wl.push(n)}}],[function*(){let e=Re.count;for(let t=0;t<e;t++){let e=new Di(fl),t=Ui(fl);if(!t)break;e.walk(t,J.int(Re.length.min,Re.length.max),!0),e.AABB.expandByValue(10);let n=Re.isLineColor?ve.line[0]:Re.colors?J.weightedChoice([1,J.choice(ve.accent)],[0,J.choice(ve.line)],[1,J.choice(ve.base)]):J.choice(ve.bg),{fade:i,scale:l}=Re.lineTapering,a={polygon:e.AABB.vertexList,faceRef:null,category:sn.walker,readyForRender:!0,detailObject:[{lines:[e.pathVerts.map((e=>e.toArray()))],closedPolyOrLine:!1,noiseOffset:[J.num(-1,1),J.num(-1,1)],lineTapering:{fade:{in:{enabled:J.bool(i.in.enabledChance),length:J.num(i.in.min,i.in.max)},out:{enabled:J.bool(i.out.enabledChance),length:J.num(i.out.min,i.out.max)}},scale:{in:{enabled:J.bool(l.in.enabledChance),length:J.num(l.in.min,l.in.max)},out:{enabled:J.bool(l.out.enabledChance),length:J.num(l.out.min,l.out.max)}}},linePressure:J.num(Re.hardness.min,Re.hardness.max),canWarp:J.bool(Re.warpChance),lineWeight:J.num(Re.thickness.min,Re.thickness.max),lineColor:n}]};Wl.push(a)}}],[function*(){let e=fl.internalFaces().filter((e=>e.area>1)),n=new nn;n.expandsByPoint(Gl),e=e.filter((e=>n.containsPoint(e.center))),Be.cropToMargin&&(e=e.filter((e=>e.center.x>Be.margin&&e.center.x<Y-Be.margin&&e.center.y>Be.margin&&e.center.y<P-Be.margin)));let i=Zl.getAllLines().filter((e=>e.meta.lineCategory==be.curves&&e.meta.used)),l=e=>{let n=e.aabb;for(let l of i){let i=l.line.map((e=>new zt(...e)));if(l.meta?.aabb||(l.meta.aabb=new nn,l.meta.aabb.expands(i)),l.meta.aabb.intersects(n)){let n=t(.9*e.vertexlist.length),a=0;for(let t=0;t<e.vertexlist.length;t++){if(a>=n)return l;let s=e.vertexlist[t],o=!1;for(let e of i)if(s.isEqualTo(e)){a++,o=!0;break}!o&&Tn(i,s)&&a++}}}},a=e=>Xl.getPolygonsAtPoint(e.center.toArray()).sort(((e,t)=>e.meta.meta.totalArea-t.meta.meta.totalArea)),s=e=>{const t=xl.getFacesIntersectingPoly(e.vertexlist.map((e=>[e.x,e.y])));return e.vertexlist.every((e=>t.some((t=>Cn(e.toArray(),t.face.vertexlist.map((e=>e.toArray())))||Tn(t.face.vertexlist,e)))))?t:[]};for(let n=0;n<e.length;n++){let i=e[n],o=n,r=a(i),c=l(i),d=s(i),u=r.length?r[0].meta.meta.lightingIntensity:Ke.default,h={polygon:i.vertexlist,faceRef:i,lightingIntensity:u,category:sn.foreground,isInCurve:c,detailObjectProps:{inObject:r,inDominantShapes:d}};Wl.push(h),yield{showUpdate:!0,message:"Determining Layout",isPercent:!0,value:t(o/e.length*100)}}const o=[...Wl.filter((e=>e.category==sn.foreground&&e.lightingIntensity)).map((e=>e.lightingIntensity))].sort(((e,t)=>e-t));for(let e of Wl){const t=(r=e.lightingIntensity,(o.indexOf(r)+o.lastIndexOf(r))/2/(o.length-1));e.lightingIntensity=wt(Kt(ti(t),0,1,Ke.min,Ke.max),e.lightingIntensity,.9)}var r}],[function*(){let{freqMultiplier:e}=Oe,t=e,n=500*e;Zl.getAllLines().filter((e=>e.meta.lineCategory==be.objects&&e.meta.used)).forEach((e=>{yi.add(e.meta.id)}));let i=Wl.filter((e=>e.category==sn.foreground)),{base:l,accent:a,line:s,bg:o}=ve,r=En([...l,...a,...s,...o]),c=J.int(0,r.length-1);li=function(e,t,n="right"){let i=e.slice();for(let e=0;e<t;e++)i=_n(i,n);return i}(r,c),li.length>Oe.maxAccents&&(li=li.slice(0,Oe.maxAccents));let d=Oe.mutation;if("none"!==d){let e=e=>{let t,n=ci;switch(d){case"offsetUp":t=n;break;case"offsetDown":t=-30}return J.choice(gi(e,si,t,Oe.samplesForPaletteOffset))},t=[];for(let n=1;n<li.length;n++){let i=li[n],l=li[n-1],a=J.bool(50);if(l&&a){let n=e(l);t.push(n)}else t.push(i)}li=t}ai=ai.map((e=>[e[0],e[1],e[2]])),fi=ii(t,li.length,0,di,i.filter((e=>e.detailObjectProps?.inDominantShapes?.length>0)).map((e=>e.faceRef.center))),xi=ii(n,ai.length,0,di,i.filter((e=>!e.detailObjectProps?.inDominantShapes?.length)).map((e=>e.faceRef.center))),ai=pi(xi,ai),li=pi(fi,li)}],[function*(){let e=Wl.filter((e=>e.category==sn.foreground&&e.detailObjectProps?.inDominantShapes?.length>0)),t=new zt(Y/2,P/2),n=e.map((e=>e.faceRef.hedges.reduce(((e,n)=>e.origin?n.origin?t.distanceTo(e.origin)<t.distanceTo(n.origin)?e:n:e:n),e.faceRef.hedges[0])));for(let e=0;e<Je.count;e++){let e=Rt(J.num(ze.scale*Je.size.min,ze.scale*Je.size.max),ze.scale),t=n.map((e=>{let t=e.origin.lerp(e.twin.origin,.5);return{distance:fn(t.toArray(),Gl,!0),edge:e,point:t}})).filter((t=>t.distance>1.25*e)),i=2.5*e;t.sort(((e,t)=>Math.abs(e.distance-i)-Math.abs(t.distance-i)));let l=t[0];n.splice(n.indexOf(l.edge),1);let a=l.point,s=J.num(0,360),o=On({center:a.toArray(),radius:e,startAngle:s,endAngle:s+359.5}),r=new Qi([o],{x:J.num(-15,15),y:J.num(-15,15),z:J.num(-15,15)},1200,0,{x:yl[0],y:yl[1]}).getLineSegments(),c={polygon:r[0].map((e=>new zt(...e))),faceRef:null,category:sn.overlay,readyForRender:!1,detailObjectProps:{}};if(Wl.push(c),Je.outline){let e=r[0],t=new nn;t.expandsByPoint(e),t.expandByValue(2*Me.thickness.max);let n={polygon:t.vertexList,faceRef:null,category:sn.overlayOutline,readyForRender:!0,detailObject:[{lines:[e],noiseOffset:[J.num(-1,1),J.num(-1,1)],closedPolyOrLine:!1,materialHardness:J.num(Me.materialHardness.min,Me.materialHardness.max),linePressure:J.num(Me.linePressure.min,Me.linePressure.max),canWarp:!1,lineTapering:Pi(Me.lineTapering,J),lineWeight:J.num(Me.thickness.min,Me.thickness.max),lineColor:Me.backgroundColor?ve.bg[0]:Me.colors?J.choice([...ve.accent,...ve.base,...ve.line]):ve.line[0]}]};Wl.push(n)}}}],[function*(){let{enabled:e,linePressure:t,materialHardness:n,lineWeight:i,percentage:l,lineTapering:a}=Ie;if(!e)return;let s=vl.filter((e=>e.meta.used)).filter((()=>J.bool(l))),o=new nn;o.expands([new zt(0,0),new zt(Y,P)]);let r={polygon:o.vertexList,faceRef:null,category:sn.constructionLine,readyForRender:!0,detailObject:[{lines:s.map((e=>e.line)),closedPolyOrLine:!1,noiseOffset:[J.num(-1,1),J.num(-1,1)],linePressure:J.num(t.min,t.max),materialHardness:J.num(n.min,n.max),ca
(e,t){const n=e-t;return Math.abs(n)<this.epsilon||n<0?-1:1}insertRec(e,t,n){return e?((0===e.axis?this.compareCoord(t.point.x,e.point.point.x):this.compareCoord(t.point.y,e.point.point.y))<0?e.left=this.insertRec(e.left,t,n+1):e.right=this.insertRec(e.right,t,n+1),e):{point:t,axis:n%2,left:null,right:null}}remove(e){this.wasRemoved=!1,this.root=this.removeRec(this.root,e,0),this.wasRemoved&&this.count--}removeRec(e,t,n){if(!e)return null;const i=e.axis;if(this.equals(e.point,t)){if(this.wasRemoved=!0,e.right){const t=this.findMin(e.right,i,n+1);e.point=t.point,e.right=this.removeRec(e.right,t.point,n+1)}else{if(!e.left)return null;{const t=this.findMin(e.left,i,n+1);e.point=t.point,e.right=this.removeRec(e.left,t.point,n+1),e.left=null}}return e}{let l;l=0===i?this.compareCoord(t.point.x,e.point.point.x):this.compareCoord(t.point.y,e.point.point.y),l<0?e.left=this.removeRec(e.left,t,n+1):e.right=this.removeRec(e.right,t,n+1)}return e}findMin(e,t,n){if(!e)throw Error("Empty subtree when finding min.");if(e.axis===t)return e.left?this.findMin(e.left,t,n+1):e;const i=e.left?this.findMin(e.left,t,n+1):e,l=e.right?this.findMin(e.right,t,n+1):e;let a=e;return this.compareAxis(i.point,a.point,t)<0&&(a=i),this.compareAxis(l.point,a.point,t)<0&&(a=l),a}findNearest(e){return this.root?this.findNearestRec(this.root,e,this.root.point,0):null}findNearestRec(e,t,n,i){if(!e)return n;let l=n;this.distanceSq(e.point,t)<this.distanceSq(l,t)&&(l=e.point);const a=0===e.axis?t.point.x-e.point.point.x:t.point.y-e.point.point.y;let s,o;return a<-this.epsilon?(s=e.left,o=e.right):a>this.epsilon?(s=e.right,o=e.left):(s=e.left,o=e.right),l=this.findNearestRec(s,t,l,i+1),a**2<this.distanceSq(l,t)&&(l=this.findNearestRec(o,t,l,i+1)),l}findKNearest(e,t){if(!this.root)return[];const n=new Oi(t,(e=>e.dist));return this.findKNearestRec(this.root,e,t,n),n.toArray().map((e=>e.point))}getTotalNodes(){return this.count}*pointsWithinDistanceGenerator(e,t){const n=t*t;yield*this.pointsWithinDistanceRecGen(this.root,e,n)}*pointsWithinDistanceRecGen(e,t,n,i=0){if(!e)return;this.distanceSq(e.point,t)<=n&&(yield e.point);const l=0===e.axis?t.point.x-e.point.point.x:t.point.y-e.point.point.y;let a,s;l<-this.epsilon?(a=e.left,s=e.right):(a=e.right,s=e.left),yield*this.pointsWithinDistanceRecGen(a,t,n,i+1),l**2<=n&&(yield*this.pointsWithinDistanceRecGen(s,t,n,i+1))}findKNearestRec(e,t,n,i,l=0){if(!e)return;const a=e.axis,s=this.distanceSq(e.point,t);if(i.size()<n)i.push({dist:s,point:e.point});else{const t=i.peek();t&&s<t.dist&&i.replaceTop({dist:s,point:e.point})}const o=0===a?t.point.x-e.point.point.x:t.point.y-e.point.point.y;let r,c;o<-this.epsilon?(r=e.left,c=e.right):o>this.epsilon?(r=e.right,c=e.left):(r=e.left,c=e.right),this.findKNearestRec(r,t,n,i,l+1);const d=i.peek();d&&o**2<d.dist&&this.findKNearestRec(c,t,n,i,l+1)}distanceSq(e,t){const n=e.point.x-t.point.x,i=e.point.y-t.point.y;return n*n+i*i}compareAxis(e,t,n){const i=0===n?e.point.x-t.point.x:e.point.y-t.point.y;return Math.abs(i)<this.epsilon?0:i}equals(e,t){const n=e.point.x-t.point.x,i=e.point.y-t.point.y;return n*n+i*i<this.epsilon*this.epsilon}}class ul{opts;kTree=new dl;activeList=[];random;epsilon=b;maxDist;constructor(e){this.opts=e,this.random=e.random||J,this.maxDist=e.maxDist||1}*generate(){const{bounds:e,noiseField:t,initialCount:n=1,k:i=50}=this.opts;if(this.opts.seedPoints&&this.opts.seedPoints.length>0)for(let e of this.opts.seedPoints){const n={point:e,minDist:t(e.x,e.y)};this.placePoint(n),this.activeList.push(n),yield n}else for(let i=0;i<n;i++){const n=this.random.num(e.topLeft[0],e.bottomRight[0]),i=this.random.num(e.topLeft[1],e.bottomRight[1]),l=t(n,i),a={point:new zt(n,i),minDist:l};this.placePoint(a),this.activeList.push(a),yield a}for(;this.activeList.length>0;){const n=0,l=this.activeList[n];let a=!1;for(let n=1;n<i;n++){const s=l.minDist*(.5+i/n),o=this.random.dec()*Math.PI*2,r=l.point.x+Math.cos(o)*s,c=l.point.y+Math.sin(o)*s;if(r<e.topLeft[0]||r>e.bottomRight[0]||c<e.topLeft[1]||c>e.bottomRight[1])continue;const d=t(r,c),u={point:new zt(r,c),minDist:d};if(this.canPlace(u)){this.placePoint(u),this.activeList.push(u),yield u,a=!0;break}}a||this.activeList.splice(n,1)}}canPlace(e){for(let t of this.kTree.pointsWithinDistanceGenerator(e,this.maxDist+b))if(t.point.distanceTo(e.point)+this.epsilon<Math.max(t.minDist,e.minDist))return!1;return!0}placePoint(e){this.kTree.insert(e)}}const hl=function(e,t,n){const i=1/t,l=1/n;return Math.min(4,((3-i)*i**2*e+l**3)/(i**3*e+(3-l)*l**2))},ml=(e,t,n,i,l)=>Math.min(4,(2+Math.sqrt(2)*(e-n/16)*(n-e/16)*(t-i))/(1.5*l*(2+(Math.sqrt(5)-1)*t+(3-Math.sqrt(5))*i))),pl=(e,t)=>{const n=Math.sin(e.theta),i=Math.cos(e.theta),l=Math.sin(t.phi),a=Math.cos(t.phi),s=t.leftY,o=e.rightY,r=ml(n,i,l,a,s),c=ml(l,a,n,i,o);e.rightX=e.x+(e.deltaX*i-e.deltaY*n)*r,e.rightY=e.y+(e.deltaY*i+e.deltaX*n)*r,t.leftX=t.x-(e.deltaX*a+e.deltaY*l)*c,t.leftY=t.y-(e.deltaY*a-e.deltaX*l)*c},gl=(e,{tension:t=1,cyclic:n=!1}={})=>{const i=((e,t=1,n=!1)=>{const i=e.map((({x:e,y:n})=>((e,t,n)=>({x:e,y:t,leftY:n,rightY:n,leftX:n,rightX:n,deltaX:0,deltaY:0,delta:0,theta:0,phi:0,psi:0}))(e,n,t))),l=i[0],a=i[i.length-1];for(let e=0;e<i.length;e++)i[e].next=i[e+1]??l,i[e].prev=i[e-1]??a;if(((e,t)=>{const n=t?e.length:e.length-1;for(let t=0;t<n;t++){const n=e[t],i=e[t+1]??e[0];n.deltaX=i.x-n.x,n.deltaY=i.y-n.y,n.delta=Math.hypot(n.deltaX,n.deltaY)}})(i,n),2===e.length&&!n)return((e,t)=>{let n=1/(3*e.rightY);e.rightX=e.x+e.deltaX*n,e.rightY=e.y+e.deltaY*n,n=1/(3*t.leftY),t.leftX=t.x-e.deltaX*n,t.leftY=t.y-e.deltaY*n})(l,a),i;((e,t)=>{const[n,i]=t?[0,e.length]:[1,e.length-1];for(let t=n;t<i;t++){const n=e[t],i=n.prev,l=i.deltaY/i.delta,a=i.deltaX/i.delta;n.psi=Math.atan2(n.deltaY*a-n.deltaX*l,n.deltaX*a+n.deltaY*l)}})(i,n),function(e,t){const n=[],i=[],l=[],a=e[0],s=e[1],o=e[e.length-1],r=t?e.length+1:e.length;if(t)n[0]=0,l[0]=0,i[0]=1;else{const e=a.next,t=a.rightX,o=Math.abs(e.leftY),r=Math.abs(a.rightY);n[0]=hl(t,r,o),l[0]=-s.psi*n[0],i[0]=0}for(let s=1;s<r;s++){const c=e[s]??a,d=c.next,u=c.prev,h=s===r-1;if(!t&&h){const e=c.leftX,t=Math.abs(c.leftY),i=Math.abs(u.rightY),a=hl(e,t,i);o.theta=-l[r-2]*a/(1-a*n[r-2]);break}{let e=1/(3*Math.abs(u.rightY)-1),o=c.delta*(3-1/Math.abs(u.rightY)),m=1/(3*Math.abs(d.leftY)-1),p=u.delta*(3-1/Math.abs(d.leftY));const g=1-n[s-1]*e;o*=g;const b=Math.abs(c.leftY),f=Math.abs(c.rightY);b<f?o*=(b/f)**2:p*=(f/b)**2;let x=p/(p+o);n[s]=x*m;let Z=-d.psi*n[s];if(x=(1-x)/g,Z-=c.psi*x,x*=e,l[s]=Z-l[s-1]*x,i[s]=-i[s-1]*x,t&&h){let e=0,t=1;for(let a=s-1;a>=0;a--){const s=0===a?r-1:a;e=l[s]-e*n[s],t=i[s]-t*n[s]}e/=1-t,a.theta=e,l[0]=e;for(let t=1;t<r-1;t++)l[t]=l[t]+e*i[t];break}}}for(let t=r-2;t>=0;t-=1)e[t].theta=l[t]-e[t].next.theta*n[t]}(i,n),(e=>{for(let t=0;t<e.length;t++){const n=e[t];n.phi=-n.psi-n.theta}})(i);const s=n?i.length:i.length-1;for(let e=0;e<s;e++)pl(i[e],i[e].next);return i})(e,t,n),l=[],a=n?i.length:i.length-1;for(let e=0;e<a;e++){const t=i[e];l.push({startControl:{x:t.rightX,y:t.rightY},endControl:{x:t.next.leftX,y:t.next.leftY},point:{x:t.next.x,y:t.next.y}})}return l};function bl(e,t,n=!1,i=.01){const l=[],a=e.length;if(a<2)return l;const s=n?a:a-1;let o=null;for(let n=1;n<=s;n++){const s=n%a,r=e[(n-1)%a].point,c=e[s].startControl,d=e[s].endControl,u=e[s].point;let h=0;for(;h<=1;){const e=1-h,n={x:e**3*r.x+3*e**2*h*c.x+3*e*h**2*d.x+h**3*u.x,y:e**3*r.y+3*e**2*h*c.y+3*e*h**2*d.y+h**3*u.y};if(o){const e=n.x-o.x,i=n.y-o.y;e*e+i*i>=t*t&&(l.push(n),o=n)}else l.push(n),o=n;h+=i}const m={x:u.x,y:u.y};!o||o.x===m.x&&o.y===m.y||(l.push(m),o=m)}if(!n){const t=e[a-1].point,n=l[l.length-1];n.x===t.x&&n.y===t.y||l.push(t)}return l}let fl,xl,Zl,yl,Gl,Wl=[],vl=[],Ll=[],Sl=[],Xl=new class{cells=new Map;polygons=new Map;polygonMeta=new Map;nextPolygonId=0;cellSize;constructor(e,t){this.cellSize=e,t&&this.addPolygons(t)}getCellIndex(e,t){return`${f(e)},${f(t)}`}clear(){this.cells.clear(),this.polygons.clear(),this.polygonMeta.clear()}getCellTestVertices(e,t){let{cellSize:n}=this;return[new zt(e*n,t*n),new zt((e+1)*n,t*n),new zt((e+1)*n,(t+1)*n),new zt(e*n,(t+1)*n)]}addPolygons(e){e.forEach((e=>this.addPolygon(e.verts,e.meta)))}getPolygonsAtPoint(e){let{cellSize:t}=this,n=f(e[0]/t),i=f(e[1]/t);const l=this.getCellIndex(n,i);let a=new Set;return this.cells.has(l)&&Array.from(this.cells.get(l)).map((t=>{Tn(this.polygons.get(t).map((e=>(new zt).fromArray(e))),new zt(e[0],e[1]))&&a.add(t)})),Array.from(a).map((e=>({verts:this.polygons.get(e),meta:this.polygonMeta.get(e)})))}addPolygon(e,t){let{cellSize:n}=this;const i=this.nextPolygonId++;this.polygons.set(i,e),this.polygonMeta.set(i,t);let l=e.map((e=>(new zt).fromArray(e))),a=new nn;a.expands(l);const s=f(a.minX/n),o=x(a.maxX/n)-1,r=f(a.minY/n),c=x(a.maxY/n)-1;for(let e=s;e<=o;e++)for(let t=r;t<=c;t++){const n=this.getCellIndex(e,t),a=this.getCellTestVertices(e,t);if(a.some((e=>Tn(l,e))))this.cells.has(n)||this.cells.set(n,new Set),this.cells.get(n).add(i);else for(let e=0;e<a.length;e++)if(Hn([a[e],a[(e+1)%a.length]],l)){this.cells.has(n)||this.cells.set(n,new Set),this.cells.get(n).add(i);break}}return i}checkIntersections(e){let{cellSize:t}=this,n=e.map((e=>(new zt).fromArray(e))),i=new nn;i.expands(n);const l=f(i.minX/t),a=x(i.maxX/t)-1,s=f(i.minY/t),o=x(i.maxY/t)-1;let r=new Set;for(let e=l;e<=a;e++)for(let t=s;t<=o;t++){const i=this.getCellIndex(e,t),l=this.getCellTestVertices(e,t);this.cells.has(i)&&this.cells.get(i).forEach((e=>{if(l.some((e=>Tn(n,e))))r.add(e);else for(let t=0;t<l.length;t++)if(Hn([l[t],l[(t+1)%l.length]],n)){r.add(e);break}}))}return Array.from(r).map((e=>({verts:this.polygons.get(e),meta:this.polygonMeta.get(e)})))}getAllPolygons(){return Array.from(this.polygons).map((([e,t])=>({verts:t,meta:this.polygonMeta.get(e)})))}}(10),Cl=[],Vl=[[function*(){hn()}],[function*(){let e=ve.bg[0][0]>=.5,t=e?1:1.008,n=e?1:1.02;si=si.length?si:he.filter((e=>e!==ve)).map((e=>[...e.accent,...e.base,...e.line])).flat().map((e=>(e[0]*=n,e[1]*=t,e))),[...ve.accent,...ve.base,...ve.line].forEach((e=>{e[0]*=n,e[1]*=t}));let i=[...ve.accent,...ve.base,...ve.line];li=i,ai=[...ve.base].sort(((e,t)=>t[0]-e[0])),li=[...li].sort(((e,t)=>t[2]-e[2])),An([...li]),An([...ai])}],[function*(){let t=w?e.LinearFilter:e.NearestFilter,n={anisotropy:V,colorSpace:e.LinearDisplayP3ColorSpace,minFilter:t,magFilter:t,type:e.FloatType};Xt=new St(B,Q,{stencilBuffer:!1,depthBuffer:!1}),Ct={paperTexture:{target:new e.WebGLRenderTarget(B,Q,{...n,format:e.RedFormat,internalFormat:"R32F"}),pass:()=>{let t=new e.ShaderMaterial({uniforms:{resolution:{value:new e.Vector2(B,Q)},noiseOffset:{value:new e.Vector2(We[0],We[1])},...ce()},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:ie,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform highp sampler2D tTex;\n uniform vec2 resolution;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n uniform vec3 backgroundColor;\n uniform vec3 lineColor;\n uniform vec2 noiseOffset;\n\n ${ee}\n ${te}\n\n varying vec2 vUv;\n out vec4 outColor;\n\n #include <packing>\n\n ${ne}\n\n vec4 render(vec2 uv) {\n\n float noiseTex1 = fbm(uv - noiseOffset, 5, 300., 0.9) - 0.5;\n float noiseTex2 = fbm(uv - noiseOffset, 3, 400., 0.9) - 0.5;\n float texCombined = step(0.001, -(noiseTex1 * noiseTex2)) * .05;\n\n float noiseTexDark1 = fbm(uv + noiseOffset + 1., 5, 280., 0.9) - 0.5;\n float noiseTexDark2 = fbm(uv + noiseOffset + 1., 3, 300., 0.9) - 0.5;\n float texDarkCombined = step(0.0001, -(noiseTexDark1 * noiseTexDark2)) * .05;\n\n float smoothNoise1 = smoothstep(0., 0.6, fbm(uv, 3, 420., 0.9)) * 0.03;\n\n // vec3 lchColor = vec3(0., 0.5, 0.5);\n float result;\n result += texCombined;\n result -= texDarkCombined;\n result += smoothNoise1;\n \n // vec3 colorRGB = OKLCHtoP3LRGB(lchColor);\n // float canvasTexture = fbm(uv, 6, 120., 0.7);\n return vec4(vec3(result), 1.);\n }\n\n \n\n void main() {\n // A pseudo-random distribution for multi-sample\n const vec2 H2 = vec2(0.56984029, 0.75487766);\n // We do sub-pixel offsets relative to tile size, \n // because each tile is scaled to fill the entire local canvas\n vec2 px = 1.0 / resolution.xy;\n px *= 1.25;\n\n // We'll accumulate color across multiple samples\n const float samples = 6.0;\n vec4 sumColour = vec4(0.0);\n \n // Vary the random offset per pixel\n vec2 d0 = vec2(randomNonDet(vUv), randomNonDet(vUv + 1.0));\n\n for (float i = 0.0; i < samples; i++) {\n vec2 d = fract(i * H2 + d0) - 0.5;\n // localCoord in [0..1] in the local canvas\n vec2 sampleCoord = vUv + d * px;\n\n // Now map that to the large “full” coordinate space \n // subregion given by uTileOffset..uTileOffset+uTileSize\n vec2 screenCoord = uTileOffset + sampleCoord * uTileSize;\n\n // Next convert to [0..1] over the entire original geometry\n vec2 globalUV = screenCoord / resolution;\n\n vec4 sampleColor = render(globalUV);\n sumColour += sampleColor;\n }\n\n vec4 finalColor = clamp(sumColour / samples, 0.0, 1.0);\n outColor = finalColor;\n }\n `});re(t),Vt.material=t,X.setRenderTarget(Ct.paperTexture.target),Vt.render(X)}},displacementMap:{target:new e.WebGLRenderTarget(B,Q,{...n,format:e.RGFormat,internalFormat:"RG32F"}),pass:()=>{let e=ft();re(e),Vt.material=e,X.setRenderTarget(Ct.displacementMap.target),Vt.render(X)}},displacementMapWarped:{target:new e.WebGLRenderTarget(B,Q,{...n,format:e.RGFormat,internalFormat:"RG32F"}),pass:()=>{let e=ft();re(e),e.uniforms.uWarpEnabled.value=!0,Vt.material=e,X.setRenderTarget(Ct.displacementMapWarped.target),Vt.render(X)}},polyEdgeDistance:{target:new e.WebGLRenderTarget(B,Q,{...n,format:e.RedFormat,internalFormat:"R32F"}),skipSetup:!0}};let i=function*(){for(let e of Object.keys(Ct)){const t=Ct[e];t.skipSetup||t.pass&&t.pass()}return X.shadowMap.enabled=!0,void X.setRenderTarget(null)}();for(;!i.next().done;)yield}],[function*(){let e=yt();Vt.material=e;for(let t of Object.keys(Ct)){if(!Ct[t].debug)continue;let n=Ct[t].target.texture;e.uniforms.tTex.value=n,X.setRenderTarget(null),Vt.render(X),ta(),yield}}],[function*(){let t=(n=Ct.paperTexture.target.texture,new e.ShaderMaterial({uniforms:{grid:{value:{...ze}},...ce(),tWarpTex:{value:Ct.displacementMap.target.texture},resolution:{value:new e.Vector2(B,Q)},coordsResolution:{value:new e.Vector2(Y,P)},noiseOffset:{value:new e.Vector2(0,0)},tPaperTexture:{value:n},backgroundColor:{value:new e.Vector3(0,0,0)},lineColor:{value:new e.Vector3(0,0,0)},uGridStrength:{value:.3}},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:ie,fragmentShader:`\n precision highp float;\n\t\t\tprecision highp int;\n \n // uniform highp sampler2D tTex;\n uniform vec2 resolution;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n uniform vec2 coordsResolution;\n uniform vec3 backgroundColor;\n uniform vec3 lineColor;\n uniform vec2 noiseOffset;\n uniform float uGridStrength;\n uniform highp sampler2D tPaperTexture;\n uniform highp sampler2D tWarpTex;\n\n struct Grid {\n float countX;\n float countY;\n float marginX;\n float marginY;\n float w;\n float h;\n float scale;\n };\n uniform Grid grid;\n\n ${ee}\n ${Dt}\n ${te}\n \n float drawGridLines(vec2 uv, float lineWeight, float gridScale) {\n vec2 scale = resolution / coordsResolution;\n // This should be the desired line width in pixels\n float lineWeightNoise = snoise2D(uv * 200.f) * .09f;\n float gridLineWeight = (lineWeight + lineWeightNoise) * scale.y; // Width of the grid lines in pixels\n\n vec2 offset = vec2(grid.marginX, grid.marginY) * scale; // Applying scale to margins\n\n // Compute UVs for grid lines based on actual screen resolution and grid scaling\n vec2 gridUV = (uv * resolution - offset);\n\n // Convert grid dimensions from whatever space they are in to pixel space directly\n float gridWidthInPixelsX = grid.w * (resolution.x / coordsResolution.x) * 1.;\n float gridWidthInPixelsY = grid.h * (resolution.y / coordsResolution.y) * 1.;\n\n // Calculate the distance to the nearest grid line in pixels\n float lineDistX = min(mod(gridUV.x, gridWidthInPixelsX / gridScale), gridWidthInPixelsX - mod(gridUV.x, gridWidthInPixelsX / gridScale));\n float lineDistY = min(mod(gridUV.y, gridWidthInPixelsY / gridScale), gridWidthInPixelsY - mod(gridUV.y, gridWidthInPixelsY / gridScale));\n float lineDist = min(lineDistX, lineDistY);\n\n // Use smoothstep to create anti-aliased lines with a specified pixel width\n float lineFactor = 1.0 - smoothstep(gridLineWeight - 0.1, gridLineWeight + 0.1, lineDist);\n\n return lineFactor;\n }\n\n float drawGridBlocks(vec2 uv, float gridScale ) {\n vec2 scale = resolution / coordsResolution;\n vec2 offset = vec2(grid.marginX, grid.marginY) * scale; // Applying scale to margins\n vec2 gridUV = (uv * resolution - offset); // Apply resolution scaling to UV, then subtract offset\n\n float tileX = floor(gridUV.x / (grid.w * scale.x));\n float tileY = floor(gridUV.y / (grid.h * scale.y));\n\n vec2 centerUV = (vec2(tileX, tileY)) * vec2(grid.w, grid.h) / resolution;\n\n float noiseValue = clamp(fbm(centerUV, 3, 300., 0.5) + .5, 0.0, 1.); // Adjust for correct scaling if necessary\n\n return noiseValue;\n\n // float checker = mod(tileX + tileY, 2.0);\n \n // return checker == 0.0;\n }\n\n ${gt}\n\n varying vec2 vUv;\n out vec4 outColor;\n\n #include <packing>\n\n ${ne}\n ${Ut}\n\n vec4 render(vec2 uv, vec2 texUv, vec2 msaaOffset) {\n\n // vec2 uvOffset = lookupWarpSample(uv).xy;\n\n // vec2 offsetUV = uv + uvOffset;\n vec2 offsetUV = uv;\n\n float gridNoise = fbm(uv, 3, 10., 0.9);\n float gridNoise2 = fbm(uv + 2., 3, 600., 0.9);\n\n float tileScaleFactor = resolution.x / uTileSize.x;\n\n // float gridFactor = clamp(0., .12, drawGridLines(uv, 38.));\n float aspectRatio = resolution.x / resolution.y;\n vec2 uvNormalised = offsetUV * vec2(aspectRatio, 1.);\n\n const float gridDarkness = 0.3;\n\n float gridDivisor = 1.;\n float edgeFactor = smoothstep(0.2f, 1.f, screenEdgeDist(uvNormalised, 0.22 - (gridNoise * .06)));\n \n float gridFactor = clamp(0., gridDarkness, drawGridLines(offsetUV, .3 , 5.) * edgeFactor);\n float gridFactor2 = clamp(0., gridDarkness + 0.025, drawGridLines(offsetUV, .5 , 1.) * edgeFactor);\n \n vec3 lineCol = lineColor;\n \n lineCol.x += (step(0.6, gridNoise - gridNoise2) * 0.4);\n \n float gridTextureNoise = fbm(uv + noiseOffset, 6, 700., 0.7) * 0.5;\n vec3 lchColor = mix(backgroundColor, lineCol, clamp((gridFactor2 - gridTextureNoise) * uGridStrength, 0., 1.));\n \n float smoothNoise1 = texture(tPaperTexture, texUv + msaaOffset).x * 0.8;\n\n float colourNoise = fbm(uv + noiseOffset, 12, 5., 0.7) * 0.001;\n float colourNoise2 = fbm(uv - noiseOffset + 1., 12, 3., 0.7) * 0.001;\n\n lchColor.x += smoothNoise1 - colourNoise + colourNoise2;\n\n float edgeFactorVignette = smoothstep(0.2f, 1.f, screenEdgeDist(uvNormalised, 0.5));\n lchColor.x -= (1. - edgeFactorVignette) * 0.005;\n lchColor.y += (1. - edgeFactorVignette) * 0.005;\n // lchColor.y *= colourNoise;\n \n\n // lchColor = vec3(lchColor.x, lchColor.y, lchColor.z);\n\n vec3 colorRGB = OKLCHtoP3LRGB(lchColor);\n\n vec3 lightDir = normalize(vec3(.6f, 1.6f, 1.6f));\n vec3 lightColor = vec3(1.0f) * 1.7f;\n\n vec3 paperTextureNormals = calculateNormals(texUv + msaaOffset, 0.0002 * tileScaleFactor, 2.);\n vec3 diffuse = calculateDiffuse(paperTextureNormals, lightDir, lightColor);\n\n colorRGB *= diffuse;\n \n // float canvasTexture = fbm(uv, 6, 120., 0.7);\n return vec4(colorRGB, 1.);\n }\n\n \n\n void main() {\n // A pseudo-random distribution for multi-sample\n const vec2 H2 = vec2(0.56984029, 0.75487766);\n // We do sub-pixel offsets relative to tile size, \n // because each tile is scaled to fill the entire local canvas\n vec2 px = 1.0 / resolution.xy;\n px *= 1.25;\n\n // We'll accumulate color across multiple samples\n const float samples = 16.0;\n vec4 sumColour = vec4(0.0);\n \n // Vary the random offset per pixel\n vec2 d0 = vec2(randomNonDet(vUv), randomNonDet(vUv + 1.0));\n\n for (float i = 0.0; i < samples; i++) {\n vec2 d = fract(i * H2 + d0) - 0.5;\n // localCoord in [0..1] in the local canvas\n vec2 sampleCoord = vUv + d * px;\n\n // Now map that to the large “full” coordinate space \n // subregion given by uTileOffset..uTileOffset+uTileSize\n vec2 screenCoord = uTileOffset + sampleCoord * uTileSize;\n\n // Next convert to [0..1] over the entire original geometry\n vec2 globalUV = screenCoord / resolution;\n\n vec4 sampleColor = render(globalUV, vUv, d * px);\n sumColour += sampleColor;\n }\n\n vec4 finalColor = clamp(sumColour / samples, 0.0, 1.0);\n outColor = finalColor;\n }\n `}));var n;Vt.material=t,re(t);let i=Ht(J.choice(ve.bg)),l=Ht(J.choice(ve.line));t.uniforms.backgroundColor.value=(new e.Vector3).fromArray(i),t.uniforms.lineColor.value=(new e.Vector3).fromArray(l),t.uniforms.noiseOffset.value=new e.Vector2(We[0],We[1]),t.uniforms.uGridStrength.value=.2,X.setRenderTarget(Xt.getWriteBuffer()),Vt.render(X),Xt.copyAndSwapBuffers(),Xt.copyBufferToScreen()}],[function*(){let e=He.margin+ze.marginX,n=He.margin+ze.marginY,i=new zt(e,n),l=new zt(Y-e,P-n);(function(e,t,n=0){let i=[],l=[],a=J.weightedChoice([0,J.easedNum(ti,He.HVariance.min,He.HVariance.max)]),s=J.weightedChoice([0,J.easedNum(ti,He.VVariance.min,He.VVariance.max)]);for(let l=e.y;l<t.y;l+=ze.scale/2)J.gaussianBool(He.HVariance.threshold,He.HVariance.mean,He.HVariance.stdDev)||i.push({id:Nn(),meta:{lineCategory:be.horizontal},line:[[e.x-ze.scale*n,l+J.num(-ze.scale*a,ze.scale*a)],[t.x+ze.scale*n,l+J.num(-ze.scale*a,ze.scale*a)]]
xlbm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WUoZSxyKSkpLmZpbHRlcigoZT0+ZS5sZW5ndGg+PTIpKSx1LnB1c2goLi4uZSkscCgpfWVsc2UgdS5wdXNoKGkpLHAoKX1pZigib3V0bGluZSIhPT10JiZyLmFkZE91dGxpbmUmJiFyLmluc2V0RnJvbUdlb21ldHJ5JiZyLmJvdW5kaW5nR2VvbWV0cnkpe2xldCBlPXdlKHIpO3UucHVzaChlKX1wKCEwKX1jYXRjaChlKXtwb3N0TWVzc2FnZSh7cmVzdWx0Om51bGwsZXJyb3I6ZS5tZXNzYWdlLHdvcmtlcklkOmR9KX19fSgpOwovLyMgc291cmNlTWFwcGluZ1VSTD1zdHJlYW1saW5lcy53b3JrZXIuanMubWFwCgo=");const Li=navigator.hardwareConcurrency||4,Si=[],Xi={},Ci={},Vi=[],wi={};for(let e=0;e<Li;e++){const t=new vi;Si.push(t),wi[e]=!0,Ci[e]=[],t.onmessage=function(e){const{result:t,done:n,error:i,workerId:l}=e.data;if(t?.length>0&&Ci[l].push(...t),n||i){const e=Xi[l];if(i?e.reject(i):e.resolve(Ci[l]),delete Xi[l],wi[l]=!0,Ci[l]=[],Vi.length>0){const e=Vi.shift();e.data.workerId=l,Ki(l,e)}}}}function Ki(e,t){const n=Si[e];wi[e]=!1,Xi[e]=t,n.postMessage(t.data)}async function Ri(e){return new Promise(((t,n)=>{const i={data:e,resolve:t,reject:n};Vi.push(i),function(){for(let e=0;e<Si.length&&0!==Vi.length;e++)if(wi[e]){const t=Vi.shift();t.data.workerId=e,Ki(e,t)}}()}))}let ki=[],Ti=(e,{isInDominantPoly:t,normal:n,isOverlay:i=!1,isInCurveOrObject:l=!1})=>{const a=[{condition:i,key:Ge.overlay},{condition:!0,key:Ge.override},{condition:t,key:Ge.dominant},{condition:!t,key:Ge.nonDominant},{condition:n>Ke.default,key:Ge.normalHigh},{condition:n<Ke.default,key:Ge.normalLow},{condition:l,key:Ge.inCurveOrObject},{condition:!l,key:Ge.notInCurveOrObject}].filter((({key:t})=>e.spatialOverride?.[t]));for(const{condition:t,key:n}of a)if(t&&e.spatialOverride[n])return ge(e,e.spatialOverride[n]);return e},Mi=(e,t)=>e?.layerOverride?.[t]?ge(e,e.layerOverride[t]):e,zi=({random:e,type:t="noise",direction:n=e.num(0,360),objAABB:i,addOutline:l=!1,boundingGeometry:a,insetFromGeometry:s,insetFromGeometryDistance:c={min:2,max:4},lineWeight:d,scribble:u=!1,scribbleStrength:h=0,maxLength:m=1e10,minDistance:p=r(.2,.75*d),minLength:g=2*p,wobbleAmplitude:b=e.easedNum($n,.5,2),wobbleFreq:f=e.easedNum($n,10*d,20*d),streamLineProps:x})=>{const Z={stepSize:o(p/2,1),maxLength:m,minLength:g,insetFromGeometry:s,addOutline:l,insetFromGeometryDistance:c,minDistance:p,bounds:{topLeft:[i.minX,i.minY],bottomRight:[i.maxX,i.maxY]},postProcessingArgs:{directional:!0,scribbleStrength:u?h:0,wobbleFreq:f,wobbleAmplitude:d*b}};switch(t){case"noise":case"bnnoise":return{...Z,vectorFieldType:t,boundingGeometry:a,vectorFieldNoiseProps:{...x,wobbleDetail:e.num(1,2)}};case"outline":return{...Z,vectorFieldType:t,boundingGeometry:a};case"directional":return{...Z,vectorFieldType:t,boundingGeometry:a,vectorFieldDirectionalProps:{direction:n}};case"wobbles":return{...Z,vectorFieldType:"wobbles",boundingGeometry:a,blueNoiseProps:{warpStrength:1e3,minDist:1*p,maxDist:1.5*p},wobbleProps:{tension:{min:.5,max:3},maxPointUse:1,maxDivergence:4,maxLinePoints:30}};case"bluenoise":return{...Z,vectorFieldType:t,boundingGeometry:a,vectorFieldNoiseProps:{...x,wobbleDetail:1},blueNoiseProps:{warpStrength:100,minDist:p+d,maxDist:4*(p+d)}};case"edgefill":return{...Z,vectorFieldType:t,boundingGeometry:a,blueNoiseProps:{warpStrength:100,minDist:2*(p+d),maxDist:2.2*(p+d)}}}},Yi=(e,t,n=[],i)=>{if(n.length){let e=n[0],t=i.int(0,e.verts.length-1),l=(t+1)%e.verts.length;return new zt(...e.verts[t]).angleTo(new zt(...e.verts[l]))}let l=Zl.getLinesIntersectingFace(e,!1),a=e.center,s=new Set([...t].map((e=>e.meta.lineCategory))),o=[be.horizontal,be.vertical,be.perspective,be.objects].filter((e=>!s.has(e))),r=l.filter((e=>!t.has(e.constructionLine)&&o.some((t=>t==e.constructionLine.meta.lineCategory))));if(r.length){let e=r.reduce(((e,t)=>fn(a.toArray(),e.constructionLine.line)<fn(a.toArray(),t.constructionLine.line)?e:t),r[0]);t.add(e.constructionLine);let n=e.constructionLine.line.map((e=>new zt(...e)));return n[0].angleTo(n[n.length-1])}},Pi=(e,t)=>{let{fade:n,scale:i}=e;return{fade:{in:{enabled:t.bool(n.in.enabledChance),length:t.num(n.in.min,n.in.max)},out:{enabled:t.bool(n.out.enabledChance),length:t.num(n.out.min,n.out.max)}},scale:{in:{enabled:t.bool(i.in.enabledChance),length:t.num(i.in.min,i.in.max)},out:{enabled:t.bool(i.out.enabledChance),length:t.num(i.out.min,i.out.max)}}}};async function Ii(e,t){let{colorOverride:n}=e?.detailObjectProps||{};const i=new A(e?.detailObjectProps?.noiseSeedOverride||t),l=new nn;l.expands(e.polygon),l.expandByValue(10);const a=e.faceRef?.center||l.center,s=e?.detailObjectProps?.inDominantShapes||[],o=e?.detailObjectProps?.inObject||[],d=s.length>0,u=!!e?.isInCurve,h=!!e?.detailObjectProps?.inObject?.length,m=e?.detailObjectProps?.isFineDetail,p=Rt(e.lightingIntensity||Ke.default,Ke.clamp),{skipFill:g,skipDetails:b}=e.detailObjectProps||{};let f=Ti(Pe,{isInDominantPoly:m||d,normal:p,isOverlay:e.category==sn.overlay,isInCurveOrObject:h||u}),x=Ti(Ye,{isInDominantPoly:m||d,normal:p,isOverlay:e.category==sn.overlay,isInCurveOrObject:h||u});const Z=!g&&i.bool(f.fillChance),y=!b&&i.bool(x.fillChance),G=i.bool(f.insetChance),W=i.bool(x.insetChance),v=Z?i.weightedChoice(...f.layerCountChances):0,L=u?0:y?i.weightedChoice(...x.layerCountChances):0;let S=new Set,X=new Set,C=new Set,V=[],w=[],K=!1;function R(t,i,c){const h=[];for(let g=0;g<c;g++){const c=Mi("fill"===i?f:x,g);let b,Z=t.num(c.lineWeight.min,c.lineWeight.max),y=t.num(c.linePressure.min,c.linePressure.max);b=r(.4,Z*t.num(c.minDistanceMult.min,c.minDistanceMult.max)),m&&"detail"===i&&(Z*=.75,b*=.25);const v="fill"===i?ki.filter((e=>!S.has(e))):ki.filter((e=>!X.has(e)));let L,R=t.choice(v);v.length||("fill"===i?S.clear():X.clear(),R=t.choice(ki)),"fill"===i?S.add(R):X.add(R),d&&("fill"===i&&G||"detail"===i&&W)&&(L=u?e.isInCurve.line:s[0].face.vertexlist.map((e=>e.toArray())));let k=c.colorMap[g]||c.colorMap[0],T=t.weightedChoice(...k),M=hi(t,T,a,p,c.colorPalette,"fill"==i?V:w),z=null;if(t.bool(c.fadeAtLineSegmentChance)){let n,i,a=t.int(0,l.vertexList.length-1),s=[l.vertexList[a],l.vertexList[(a+1)%l.vertexList.length]],o=s[0].lerp(s[1],t.num(.01,.99));for(let t=0;t<e.polygon.length;t++){let n=[e.polygon[t],e.polygon[(t+1)%e.polygon.length]],l=xn(o.toArray(),n[0].toArray(),n[1].toArray());(!i||l<i.dist)&&(i={seg:n,dist:l})}n=i.seg;const{fadeAtLineSegmentDistanceMult:r,fadeAtLineSegmentStrengthMult:d}=c;let u=l.center.distanceTo(n[0].lerp(n[1],.5));z={segment:n,distance:2*u*t.num(r.min,r.max),strength:t.num(d.min,d.max)}}let Y=t.weightedChoice(...c.styleChances),P=0;"directional"===Y&&(P=Yi(e.faceRef,C,o,t));let I,H,F="fill"==i&&u&&(K||0==g&&t.bool(Ue.renderLightChance));K=F,"fill"===i?(n?M=n:F&&(M=hi(t,ye.lightestOrDarkestBasedOnBg,a,p,c.colorPalette,V)),V.push(M)):"detail"==i&&w.push(M);const N=t.bool(c.ignoreLightingChance);I=!(u&&Ue.ignoreLighting||N),H=!!(u&&Ue.ignoreLighting||N),h.push({paintLineObj:{colorLayerType:T,lineBrightness:I?Tt(p,Ke.min,Ke.max,wt(Ke.default,Ke.min,Ke.influencesBrightnessMult),wt(Ke.default,Ke.max,Ke.influencesBrightnessMult)):Ke.default,type:i,lines:[],closedPolyOrLine:!1,noiseOffset:[t.num(-1,1),t.num(-1,1)],canBulge:!0,isShading:!0,canWarp:!0,fadeAtLineSegment:z,lineTapering:Pi("bluenoise"==Y&&"detail"==i?{fade:{in:{enabledChance:0,min:1,max:1},out:{enabledChance:0,min:4,max:6}},scale:{in:{enabledChance:100,min:.5,max:.8},out:{enabledChance:100,min:.5,max:.8}}}:c.lineTapering,t),disableSaturationShift:H,linePressure:y*Tt(p,Ke.max,Ke.min,Tt(Ke.influencesPressureMult,1,0,.5,1),1),edgeSharpness:t.num(c.edgeSharpness.min,c.edgeSharpness.max),accumulationStrength:t.num(c.accumulationStrength.min,c.accumulationStrength.max),materialHardness:t.num(c.materialHardness.min,c.materialHardness.max),lineWeight:.8*Z,lineColor:M},workerData:{streamlineWorkerProps:zi({type:Y,direction:P,addOutline:"edgefill"==Y,scribble:d?!u&&t.bool(c.scribbleChance):t.bool(c.scribbleChance),scribbleStrength:t.num(c.scribbleStrength.min,c.scribbleStrength.max),random:t,insetFromGeometry:L,insetFromGeometryDistance:{min:c.insetDistance.min,max:c.insetDistance.max},objAABB:l,boundingGeometry:e.polygon.map((e=>e.toArray())),lineWeight:Z,minDistance:"bluenoise"==Y&&"detail"==i?.4*b:r(.4,"fill"==i?b*Kt(p,Ke.max,Ke.min,Kt(Ke.influencesMinDistanceMult,1,0,1,1),Kt(Ke.influencesMinDistanceMult,0,1,1,.5)):b),maxLength:c.maxLength?t.num(c.maxLength.min,c.maxLength.max):1e10,wobbleAmplitude:t.easedNum($n,c.wobbleAmplitude.min,c.wobbleAmplitude.max),wobbleFreq:t.easedNum($n,c.wobbleFreq.min,c.wobbleFreq.max),streamLineProps:{...R,wobbleDetail:t.int(1,2)}}),noiseSeed:un,randomSeed:E(t)}})}return h}const k=[...R(i,"fill",v),...R(i,"detail",L)],T=k.map((e=>Ri(e.workerData))),M=await Promise.all(T);e.allowExtraDetails=!1,k.filter((e=>"detail"==e.paintLineObj.type)).length>=2&&k.filter((e=>"detail"==e.paintLineObj.type)).every((e=>"directional"==e.workerData.streamlineWorkerProps.vectorFieldType))&&(e.allowExtraDetails=!0);for(let t=0;t<M.length;t++){const n=[],i=M[t],l=k[t].paintLineObj;"detail"==l.type&&"bluenoise"==k[t].workerData.streamlineWorkerProps.vectorFieldType&&(l.lineWeight*=1.5);for(let e of i){const t=e;t.length&&n.push(t)}n.length<1||(l.lines=n,e.detailObject=e.detailObject||[],e.detailObject.push(l))}if(e?.detailObject?.length){let t=[];for(let n=e.detailObject.length-1;n>0;n--){let i=e.detailObject[n-1],l=e.detailObject[n];l.colorLayerType===ye.previous&&i?.lines?.length&&l?.lines?.length&&(i.lines=[...i.lines,...l.lines],t.push(l))}t.length>0&&(e.detailObject=e.detailObject.filter((e=>!t.includes(e))))}e.allowExtraDetails&&e?.detailObject?.length&&!m&&i.bool(d?80:40)&&async function(e,t){let n=[...Wl,...an].filter((e=>e.category==sn.overlay));for(let t of n){let n=new nn;if(n.expands(t.polygon),e.faceRef.aabb.intersects(n))return}let i=e.detailObject.filter((e=>"detail"==e.type));const l=new nn;l.expands(e.polygon),l.expandByValue(10);const a=e.faceRef?.center||l.center;let s=new Ln([],[]);s.insertPolygon(e.polygon.map((e=>e.toArray())),!0);for(let e=0;e<i.length;e++){let t=i[e];for(let e of t.lines)s.insertPolygon(e,!1),await new Promise((e=>setTimeout(e,0)))}s.cleanupTrailingEdges();let o=s.internalFaces(),r=c(mn(a.x,a.y,100,5,40,100)),d=mn(a.x,a.y,600,0,100)>60;if(o.length>2)for(let n of o.filter((e=>e.area>100)))if(n.hedges.every((e=>e.face&&e.twin.face&&e.face!==e.twin.face))&&t.bool(r)){let i=t.num(.35,.45),l=n.vertexlist.map((e=>e.addPolar(e.angleTo(n.center),e.distanceTo(n.center)*i))),a={category:sn.detail,faceRef:n,polygon:l,detailObject:[],detailObjectProps:{isFineDetail:!0,skipDetails:!d,skipFill:!!d,inObject:e.detailObjectProps?.inObject,inDominantShapes:e.detailObjectProps?.inDominantShapes,noiseSeedOverride:E(t)}};Wl.push(a)}}(e,i),e.readyForRender=!0}let Hi,Fi,Ni=new Set;function Ui(e){let t,n=0;for(;!t&&n++<200;){let n=J.choice(e.internalFaces()),i=J.choice(n.vertexlist);Ni.has(i)||(t=i)}return t}class Di{dcel;maxAngle;pathVerts=[];AABB=new nn;constructor(e,t=.3){this.dcel=e,this.maxAngle=t}*findDominantPaths(e=!1){let t=new Set(this.dcel.hedges.filter((e=>e.face&&e.face.area>0&&e.twin.face&&e.twin.face.area>0&&e.origin!==e.twin.origin&&e.face!==e.twin.face)));for(;t.size>0;){let n=t.values().next().value;t.delete(n),t.delete(n.twin);let i=[n.twin.origin],l=[n.origin],a=new Set;a.add(n.origin),a.add(n.twin.origin);let o=0;for(let r of[n,n.twin]){let c=r.twin.origin,d=r===n?i:l,u=r.origin,h=u.angleTo(c);for(;;){const n=c.hedgelist.filter((t=>(!e||t.twin.face&&t.twin.face.area>0)&&t.face&&t.face.area>0&&!a.has(t.twin.origin)&&s(c.angleTo(t.twin.origin)-h)<this.maxAngle)).sort(((e,t)=>s(c.angleTo(e.twin.origin)-h)-s(c.angleTo(t.twin.origin)-h)));if(!n.length)break;let i=n[0];o+=s(c.angleTo(i.twin.origin)-h),t.delete(i),t.delete(i.twin),u=c,c=i.twin.origin,d.push(c),a.add(c),h=u.angleTo(c)}}l.reverse();let r=l.concat(i),c=r.reduce(((e,t,n)=>0===n?0:e+t.distanceTo(r[n-1])),0);yield{vertices:r,length:c,curviness:o/r.length}}}walk(e,t,n=!0){let i=e;if(!i)return;let l=0,a=0;this.AABB.expand(i);let s=new Set;for(s.add(i),Ni.add(i);l<=t&&a++<400;){const e=i.hedgelist.filter((e=>!s.has(e.twin.origin)&&!Ni.has(e.twin.origin)));if(e.sort(((e,t)=>{let n=e.twin.origin,i=t.twin.origin,l=this.AABB.center.distanceTo(n);return this.AABB.center.distanceTo(i)-l})),0===e.length)break;let a=e[0].twin.origin;if(l+=i.distanceTo(a),n&&l>t){let e=(o=i,r=a,c=1-(l-t)/i.distanceTo(a),new zt(wt(o.x,r.x,c),wt(o.y,r.y,c)));s.add(e),this.AABB.expand(e);break}s.add(a),Ni.add(a),this.AABB.expand(a),i=a}var o,r,c;this.pathVerts.push(...Array.from(s))}}class Oi{heap;maxSize;valueFunction;epsilon=b;constructor(e,t){this.valueFunction=t,this.heap=[],this.maxSize=e}size(){return this.heap.length}push(e){this.heap.push(e),this.siftUp(this.heap.length-1),this.heap.length>this.maxSize&&this.heap.pop()}clear(){this.heap=[]}peek(){return this.heap[0]}remove(e){const t=this.heap.findIndex((t=>t===e));-1!==t&&(this.heap[t]=this.heap[this.heap.length-1],this.heap.pop(),t<this.heap.length&&this.siftDown(t))}replaceTop(e){this.heap[0]=e,this.siftDown(0)}toArray(){return[...this.heap]}siftUp(e){for(;e>0;){const t=Math.floor((e-1)/2),n=this.valueFunction(this.heap[e])-this.valueFunction(this.heap[t]);if(n<this.epsilon&&n>-this.epsilon)break;if(n<=0)break;[this.heap[e],this.heap[t]]=[this.heap[t],this.heap[e]],e=t}}siftDown(e){const t=this.heap.length;for(;;){let n=e;const i=2*e+1,l=2*e+2,a=this.valueFunction(this.heap[n]);if(i<t&&this.valueFunction(this.heap[i])-a>this.epsilon&&(n=i),l<t){const e=this.valueFunction(this.heap[n]);this.valueFunction(this.heap[l])-e>this.epsilon&&(n=l)}if(n===e)break;[this.heap[e],this.heap[n]]=[this.heap[n],this.heap[e]],e=n}}}class Bi{position;rotation;dimensions;numSides;cameraPos;fov;aspect;near;far;lights;cullBackfaces;localVertices=[];worldVertices=[];screenVertices=[];constructor(e,t,n,i,l,a=90,s=Y/P,o=.1,r=1e4,c=[],d=!1){this.position=e,this.rotation=t,this.dimensions=n,this.numSides=i,this.cameraPos=l,this.fov=a,this.aspect=s,this.near=o,this.far=r,this.lights=c,this.cullBackfaces=d,this._buildLocalGeometry()}_buildLocalGeometry(){const{width:e,height:t,depth:n}=this.dimensions,i=e/2,l=t/2,a=n/2,s=2*Math.PI/this.numSides,o=this.numSides%2==0?-Math.PI/this.numSides:-Math.PI/2;if(0===n)for(let e=0;e<this.numSides;e++){const t=o+s*e,n=Math.cos(t)*i,a=Math.sin(t)*l;this.localVertices.push({x:n,y:a,z:0})}else for(let e=0;e<this.numSides;e++){const t=o+s*e,n=Math.cos(t),r=Math.sin(t);this.localVertices.push({x:n*i,y:r*l,z:+a}),this.localVertices.push({x:n*i,y:r*l,z:-a})}}getFaces2D(){const e=function(e,t,n,i,l,a){const s=Ji(e*Math.PI/180),o=ji(t*Math.PI/180),r=Ai(n*Math.PI/180),c=Ei(i,l,a),d=_i(r,_i(o,s));return _i(c,d)}(this.rotation.x,this.rotation.y,this.rotation.z,this.position.x,this.position.y,this.position.z),t=Ei(-this.cameraPos.x,-this.cameraPos.y,-this.cameraPos.z),n=_i(function(e,t,n,i){const l=1/Math.tan(e*Math.PI/180/2),a=1/(n-i);return[[l/t,0,0,0],[0,l,0,0],[0,0,(n+i)*a,n*i*a*2],[0,0,-1,0]]}(this.fov,this.aspect,this.near,this.far),_i(t,e));this.worldVertices=[],this.screenVertices=[];for(const t of this.localVertices){const i=qi(e,[t.x,t.y,t.z,1]);this.worldVertices.push({x:i[0],y:i[1],z:i[2]});const l=qi(n,[t.x,t.y,t.z,1]);0!==l[3]&&(l[0]/=l[3],l[1]/=l[3],l[2]/=l[3]);const a=(.5*l[0]+.5)*Y,s=(1-(.5*l[1]+.5))*P;this.screenVertices.push([a,s])}const i=this._buildFaces(),l=this.cameraPos.x,a=this.cameraPos.y,s=this.cameraPos.z,o=[];for(let e of i){const t=e.indices.map((e=>this.worldVertices[e])),n=e.indices.map((e=>this.screenVertices[e])),i=$i(t),r=el(t),c=tl(i,r,this.lights);if(this.cullBackfaces){const e={x:r.x-l,y:r.y-a,z:r.z-s};i[0]*e.x+i[1]*e.y+i[2]*e.z<0&&o.push({vertices:n,normal:i,lighting:c})}else o.push({vertices:n,normal:i,lighting:c})}return o}_buildFaces(){const e=[],t=this.numSides;if(0!==this.dimensions.depth){const n=[];for(let e=0;e<t;e++)n.push(2*e);e.push({indices:n});const i=[];for(let e=t-1;e>=0;e--)i.push(2*e+1);e.push({indices:i});for(let n=0;n<t;n++){const i=(n+1)%t,l=[2*n,2*n+1,2*i+1,2*i];e.push({indices:l})}}else e.push({indices:Array.from({length:t},((e,t)=>t))});return e}}class Qi{vertices;rotation;perspective;zShift;transformOrigin;projectedVertices;vertices3D;constructor(e,t,n=800,i=-50,l={x:Y/2,y:P/2}){this.vertices=e,this.rotation=t,this.perspective=n,this.zShift=i,this.transformOrigin=l}getLineSegments(){let e=new nn;for(let t of this.vertices)e.expands(t.map((e=>new zt(...e))));const{x:t,y:n,z:i}={...e.center,z:this.zShift},{x:l,y:a,z:s}=this.rotation,o=this.perspective,r=e.center,c=this.vertices.map((e=>e.map((e=>new zt(...e).subtract(r)))));this.vertices3D=[];for(let e=0;e<c.length;e++){this.vertices3D.push([]);for(const t of c[e])this.vertices3D[e].push({x:t.x,y:t.y,z:0})}const d=function(e,t,n,i,l,a){const s=t*Math.PI/180,o=n*Math.PI/180,r=Ji(e*Math.PI/180),c=ji(s);let d=_i(Ai(o),_i(c,r));return _i(Ei(i,l,a),d)}(l,a,s,t,n,i),u=this.vertices3D.map((e=>e.map((e=>{const t=[e.x,e.y,e.z,1],n=qi(d,t);return{x:n[0],y:n[1],z:n[2]}}))));return this.projectedVertices=u.map((e=>e.map((e=>function(e,t,n={x:Y/2,y:P/2}){const{x:i,y:l,z:a}=e,s=i-n.x,o=(l-n.y)*t/(t+a);return t+a<=0?null:[s*t/(t+a)+n.x,o+n.y]}(e,o,this.transformOrigin))).filter((e=>null!==e)))).map((e=>e.filter((e=>e[0]>=-100&&e[0]<=Y+100&&e[1]>=-100&&e[1]<=P+100)))).filter((e=>e.length>0)),this.projectedVertices}}function Ji(e){const t=Math.cos(e),n=Math.sin(e);return[[1,0,0,0],[0,t,-n,0],[0,n,t,0],[0,0,0,1]]}function ji(e){const t=Math.cos(e),n=Math.sin(e);return[[t,0,n,0],[0,1,0,0],[-n,0,t,0],[0,0,0,1]]}function Ai(e){const t=Math.cos(e),n=Math.sin(e);return[[t,-n,0,0],[n,t,0,0],[0,0,1,0],[0,0,0,1]]}function Ei(e,t,n=0){return[[1,0,0,e],[0,1,0,t],[0,0,1,n],[0,0,0,1]]}function _i(e,t){const n=Array.from(Array(e.length),(()=>Array(t[0].length).fill(0)));for(let i=0;i<e.length;i++)for(let l=0;l<t[0].length;l++)for(let a=0;a<e[0].length;a++)n[i][l]+=e[i][a]*t[a][l];return n}function qi(e,t){const n=[];for(let i=0;i<e.length;i++){let l=0;for(let n=0;n<t.length;n++)l+=e[i][n]*t[n];n.push(l)}return n}function $i(e){const t=e[0],n=e[1],i=e[2],l=[n.x-t.x,n.y-t.y,n.z-t.z],a=[i.x-t.x,i.y-t.y,i.z-t.z],s=[l[1]*a[2]-l[2]*a[1],l[2]*a[0]-l[0]*a[2],l[0]*a[1]-l[1]*a[0]],o=Math.sqrt(s[0]**2+s[1]**2+s[2]**2);return s.map((e=>e/o))}function el(e){const t=e.reduce(((e,t)=>(e.x+=t.x,e.y+=t.y,e.z+=t.z,e)),{x:0,y:0,z:0}),n=e.length;return{x:t.x/n,y:t.y/n,z:t.z/n}}function tl(e,t,n){let i=0;for(const l of n){const n={x:l.position.x-t.x,y:l.position.y-t.y,z:l.position.z-t.z},a=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z);if(0===a)continue;const s=n.x/a,o=n.y/a,r=n.z/a;i+=(e[0]*s+e[1]*o+e[2]*r)*l.brightness}return i}let nl=!1,il=0,ll=0;T();let al=T();const sl=()=>{if(!Vl[il])return void rl();const e=Vl[il][0](),t=Vl[il][1]||!1;let n,i=!1;const l=()=>{n=e.next(),$l?i=!1:(i=!0,n?.done||function(e){nl||(Hi=K.getParameter(K.MAX_CLIENT_WAIT_TIMEOUT_WEBGL),Fi=K.SYNC_FLUSH_COMMANDS_BIT,nl=!0);const t=K.fenceSync(K.SYNC_GPU_COMMANDS_COMPLETE,0);!function n(){const i=K.clientWaitSync(t,Fi,Hi);i===K.ALREADY_SIGNALED||i===K.CONDITION_SATISFIED||$l?(clearTimeout(void 0),K.deleteSync(t),e()):setTimeout(n,0)}()}(l))},a=()=>{const s=T();if(t)!i&&!$l&&l();else for(;T()-s<1e3/30&&!$l&&!n?.done;)n=e.next();ll++,n?.done?(ol("Step took"),Xt?.copyBufferToScreen(),i=!1,n=null,il++,sl()):(v(n.value||{showUpdate:!1}),setTimeout(a,0))};a()};function ol(e="",t=!1){T(),al=T()}const rl=()=>{document.complete=!0,An(mi([...oi][0],[...oi],oi.size)),ol("Total render time",!0),function(){for(let e=0;e<Si.length;e++){const t=Si[e];t&&t.terminate()}}()};function cl(e,t,n=4){const i=t/2,l=[];for(let t=0;t<e.length-1;t++){const[n,i]=e[t],[a,s]=e[t+1],o=a-n,r=s-i,c=Math.hypot(o,r);if(0===c){l.push([0,0]);continue}const d=-r/c,u=o/c;l.push([d,u])}const a=[],s=[];for(let t=0;t<e.length;t++){const[o,r]=e[t];if(0===t){const[e,t]=l[0],n=e*i,c=t*i;a.push([o+n,r+c]),s.push([o-n,r-c])}else if(t===e.length-1){const[e,t]=l[l.length-1],n=e*i,c=t*i;a.push([o+n,r+c]),s.push([o-n,r-c])}else{const[e,c]=l[t-1],[d,u]=l[t],h=Math.sqrt((e*d+c*u+1)/2);if(0===h){const t=e*i,n=c*i;a.push([o+t,r+n]),s.push([o-t,r-n]);continue}const m=i/h;if(m>n*i){const[t,n]=[e*i,c*i],[l,h]=[d*i,u*i];a.push([o+t,r+n]),a.push([o+l,r+h]),s.push([o-t,r-n]),s.push([o-l,r-h])}else{const[t,n]=[e+d,c+u],l=Math.hypot(t,n);if(0===l){const t=e*i,n=c*i;a.push([o+t,r+n]),s.push([o-t,r-n])}else{const[e,i]=[t/l,n/l],c=e*m,d=i*m;a.push([o+c,r+d]),s.push([o-c,r-d])}}}}return[...a.reverse(),...s]}class dl{root=null;epsilon=b;count=0;wasRemoved=!1;insert(e){this.root=this.insertRec(this.root,e,0),this.count++}compareCoord
l7bGV0IGE9ZSxjPTAsZD0wO2Zvcig7YzxuOyl7Y29uc3QgZT10KGEpO2lmKGVbMF0qZVswXStlWzFdKmVbMV08cCpwKWJyZWFrO2NvbnN0IG49W2FbMF0raCppKmVbMF0sYVsxXStoKmkqZVsxXV07aWYoIXJlKG4sbCl8fCFzLmlzVmFsaWRJbnNlcnRpb25Qb2ludChuKXx8cy5pc05lYXJPdGhlclN0cmVhbWxpbmVzKG4scixvKSlicmVhaztjb25zdCBnPXtzdGFydDphLGVuZDpuLHN0cmVhbWxpbmVJZDpyLHNlZ21lbnRJbmRleDpkfTtzLmFkZFNlZ21lbnQoZyksYT1uLGMrPWksZCsrLHlpZWxke3BvaW50OmEsZGlyZWN0aW9uOmh9fX1mdW5jdGlvbipsZShlLHQsaSl7Y29uc3Qgbj1lW3RdLFtzLHJdPWZ1bmN0aW9uKGUsdCxpPXApe2lmKHQ+MCYmdDxlLmxlbmd0aC0xKXtjb25zdCBuPWVbdC0xXSxzPWVbdCsxXSxyPXNbMF0tblswXSxvPXNbMV0tblsxXSxsPU1hdGguaHlwb3QocixvKTtpZihsPGkpcmV0dXJuW1swLDBdLFswLDBdXTtjb25zdCBoPVstby9sLHIvbF0sYT1bby9sLC1yL2xdLGM9aFswXSpoWzBdK2hbMV0qaFsxXSxkPWFbMF0qYVswXSthWzFdKmFbMV07cmV0dXJuIGM8aSppJiYoaFswXT0wLGhbMV09MCksZDxpKmkmJihhWzBdPTAsYVsxXT0wKSxbaCxhXX1yZXR1cm5bWzAsMF0sWzAsMF1dfShlLHQscCk7aWYoMD09PXNbMF0mJjA9PT1zWzFdfHwwPT09clswXSYmMD09PXJbMV0pcmV0dX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uYm90dG9tUmlnaHRbMF0rcCYmZVsxXT49dC50b3BMZWZ0WzFdLXAmJmVbMV08PXQuYm90dG9tUmlnaHRbMV0rcH1mdW5jdGlvbipvZShlLHQsaSxuLHMscixvLGwsaC
ex,cellIndices:n}),n}doesLineFullyIntersectFace(e,t){const n=this.lines.get(e),i=this.lineMeta.get(e);if(!n||!i)return!1;const l=t.hedges.map((e=>{let t=new nn;return t.expands([e.origin,e.nexthedge.origin]),{aabb:t,edge:e}})),a=[],s=i.isClosed?n.length:n.length-1;for(let e=0;e<s;e++){const t=new zt(...n[e]),i=new zt(...n[(e+1)%n.length]),s=i.x-t.x,o=i.y-t.y,r=s*s+o*o;let c=new nn;c.expands([t,i]);for(const{aabb:n,edge:d}of l){if(!n.intersects(c))continue;const l=d.intersectWithLineSegment([t,i]);if(l?.type===gn.intersecting&&l.point){const n=((l.point.x-t.x)*s+(l.point.y-t.y)*o)/r;a.push(e+n)}}}a.sort(((e,t)=>e-t));const o=a.filter(((e,t)=>0===t||Math.abs(e-a[t-1])>b));if(o.length<2)return!1;const r=new zt(...n[0]);let c=t.containsPoint(r)&&!t.isPointOnBoundary(r);for(let e=0;e<o.length-1;e++){c=!c;const i=o[e],l=o[e+1];if(i<b||l>s-b)continue;if(!c)continue;const a=(i+l)/2,r=Math.floor(a)%n.length,d=a-Math.floor(a),u=new zt(...n[r]),h=new zt(...n[(r+1)%n.length]),m=new zt(u.x+(h.x-u.x)*d,u.y+(h.y-u.y)*d);if(t.containsPoint(m)&&!t.isPointOnBoundary(m))return!0}return!1}linesIntersectingAABB(e){const t=this.aabbLineIntersectionCache.get(e);if(t)return t;const n=new Set,i=f(e.minX/this.cellSize),l=f(e.maxX/this.cellSize),a=f(e.minY/this.cellSize),s=f(e.maxY/this.cellSize);for(let e=i;e<=l;e++)for(let t=a;t<=s;t++){const i=this.getCellIndex(e,t);this.cells.has(i)&&this.cells.get(i).forEach((e=>n.add(e)))}const o=[...n].map((e=>({constructionLine:{id:e,line:this.lines.get(e),meta:this.lineMeta.get(e)},intersectionType:Qn.intersecting})));return this.aabbLineIntersectionCache.set(e,o),o}getLinesIntersectingFace(e,t=!0){const n=this.getCellsIntersectedByFace(e),i=new Set;for(const e of n){const t=this.cells.get(e);if(t)for(const e of t)i.add(e)}let l=Array.from(i);return t&&(l=l.filter((t=>this.doesLineFullyIntersectFace(t,e)))),l.map((e=>({constructionLine:{id:e,line:this.lines.get(e),meta:this.lineMeta.get(e)},intersectionType:Qn.intersecting})))}getGridDistanceField(e=0,t=0){let{cellSize:n}=this;const i=new Set,l=new Set,a=[];let s=f(t/n),o=f((Y-2*t)/n),r=f(t/n),c=f((P-2*t)/n);for(let t=s;t<=o;t++)for(let n=r;n<=c;n++){const l=this.getCellIndex(t,n);(!this.cells.has(l)||this.cells.get(l)?.size<=e)&&i.add(l)}const d=(e,t)=>{const n=[e];for(;n.length>0;){const e=n.pop();if(!e||l.has(e)||!i.has(e))continue;l.add(e);const[a,s]=this.getCellXYfromIndex(e);t.indices.push(e);const o=[this.getCellIndex(a-1,s),this.getCellIndex(a+1,s),this.getCellIndex(a,s-1),this.getCellIndex(a,s+1)];for(const e of o)!l.has(e)&&i.has(e)&&n.push(e)}};i.forEach((e=>{if(!l.has(e)){const t={vertices:[],indices:[]};d(e,t),t.indices.length>1&&a.push(t)}}));let u=this.distanceCalculator||new Bn(s,r,o,c);return u.initializeWithEmptyCells(i,this.getCellXYfromIndex.bind(this)),a.map((e=>{const t=new nn;let n=[];e.indices.forEach((e=>{const[t,i]=this.getCellXYfromIndex(e),l=u.getDistance(t,i);n.push([l,this.getCellVertexFromIndex(e)])}));let i=n.reduce(((e,t)=>e[0]>t[0]?e:t));return t.expands(n.map((([,e])=>e))),{aabb:t,cellCount:e.indices.length,maxDistance:i[0],cellsByDistance:n,indices:e.indices.map((e=>this.getCellVertexFromIndex(e)))}}))}}function jn(e){const[t,n,i]=e;return`oklch(${(100*(t||0)).toFixed(2)}% ${(n||0).toFixed(2)} ${(i||0).toFixed(2)})`}function An(e){e.forEach((e=>{const[t,n,i]=e;jn(e)}))}function En(e){const n=e.slice();for(let e=n.length-1;e>0;e--){const i=t(J.dec()*(e+1));[n[e],n[i]]=[n[i],n[e]]}return n}function _n(e,t="right"){const n=e.slice();if("right"===t){const e=n.pop();void 0!==e&&n.unshift(e)}else if("left"===t){const e=n.shift();void 0!==e&&n.push(e)}return n}const qn=e=>e,$n=e=>1-l(e*g/2),ei=e=>-(l(g*e)-1)/2,ti=e=>e<.5?(1-d(1-a(2*e,2)))/2:(d(1-a(-2*e+2,2))+1)/2;let ni={};const ii=(e,t=5,n=0,i=qn,l=[])=>{const a=`${e}-${n}-${t}`;if(ni[a]?.min)return ni[a];let s=0,o=-1/0,r=1/0,c=0,d=[],u=(t,l)=>{let a=i(mn(t,l,n,e));s+=a,c+=1,a>o&&(o=a),a<r&&(r=a),d.push(a)};if(l.length)for(let e of l)u(e.x,e.y);else for(let e=0;e<20*ze.countX;e+=ze.w/20)for(let t=0;t<20*ze.countY;t+=ze.h/20)u(e,t);let h={max:o,min:r,mean:s/c,indexValues:[],mostCommonIndex:0,leastCommonIndex:0};return d.map((e=>{let n=f(Tt(e,h.min,h.max,0,t-1));h.indexValues[n]=h.indexValues[n]?h.indexValues[n]+1:1})),h.mostCommonIndex=h.indexValues.reduce(((e,t,n)=>t>h.indexValues[e]?n:e),0),h.leastCommonIndex=h.indexValues.reduce(((e,t,n)=>t<h.indexValues[e]?n:e),0),ni[a]=h,h};let li=[],ai=[],si=[],oi=new Set,ri={L:1,C:1,H:2/Math.PI},ci=30,di=ei;function ui(e,t,n=ri){e=Nt(e),t=Nt(t);const{L:i,C:l,H:a}=n,s=e[0]-t[0],o=e[1]-t[1];let r=e[2]-t[2];r=(r+180)%360-180;const c=r*Math.PI/180;return Math.sqrt(s*s*i+o*o*l+c*c*a)}function hi(e,t,n,i=1,l="fg",a=[]){let s,o=t,r=ve.bg[0][0]>=.5,c=a?.[0];if(o==ye.previous)return c;if(o==ye.brightnessBasedShadowOrHighlight){let t,a=c||Gi(e,n,i,null,l),s=i>=wt(Ke.max,Ke.min,.5),o=.2;if(a[0]>.75&&!s&&(o=.02),s){let e=bi(a,si,o);t=[wt(a[0]+o,e[0],.5),e[1],e[2]]}else{let e=bi(a,si,-o);t=[wt(a[0]+-o,e[0],.5),e[1],e[2]]}return Nt(t)}ye.lightestOrDarkestBasedOnBg==o&&(o=r?ye.lightest:ye.darkest);let d=c||Gi(e,n,i,null,l),u=d[0]>.7&&d[1]<.05;switch(o){case ye.color:s=Gi(e,n,i,null,l);break;case ye.randomAccent:s=e.choice(li);break;case ye.base:s=ve.base[0];break;case ye.line:s=ve.line.reduce(((e,t)=>r?e[0]<t[0]?e:t:e[0]>t[0]?e:t),ve.line[0]);break;case ye.shadow:let t=c||Gi(e,n,i,null,l);s=gi([.3*t[0],t[1],t[2]],si,0)[0];break;case ye.highlight:let a=c||Gi(e,n,i,null,l);s=gi([kt(0,1,1.5*a[0]),a[1],a[2]],si,0)[0];break;case ye.offset:s=u?d:gi(c||d,si,ci*e.choice([-1,1]),1)[0];break;case ye.offsetUp:s=u?d:gi(c||d,si,ci,1)[0];break;case ye.palettecomplement:s=gi(c||d,li,180)[0];break;case ye.offsetDown:s=u?d:gi(c||d,si,ci,-1)[0];break;case ye.darkest:s=li.reduce(((e,t)=>e[0]<t[0]?e:t),li[0]);break;case ye.lightest:s=li.reduce(((e,t)=>e[0]>t[0]?e:t),li[0])}return oi.add(s),s}function mi(e,t,n=0){if(0===t.length)throw Error("Palette is empty.");const i=t.map((t=>({color:t,dist:ui(e,t)})));return i.sort(((e,t)=>e.dist-t.dist)),i.slice(0,n).map((e=>e.color))}function pi(e,t){let n=e.leastCommonIndex,i=e.mostCommonIndex,l=t.reduce(((e,t)=>e[0]<t[0]?e:t),t[0]),a=t.reduce(((e,t)=>e[0]>t[0]?e:t),t[0]);const s=(t.indexOf(l)-n+t.length)%t.length;let o=t.slice(s).concat(t.slice(0,s));if(o.indexOf(a)===i){const e=[];for(let t=0;t<o.length;t++)t!==i&&t!==n&&e.push(t);if(e.length>0){const t=J.choice(e);[o[i],o[t]]=[o[t],o[i]]}}return o}function gi(e,t,n=20,i=1){return mi([e[0],e[1],Ft(e[2]+n)],t.filter((e=>e)),i)}function bi(e,t,n=1){const i=[kt(0,1,e[0]+n),e[1],e[2]];let l;for(let e of t){let t=ui(i,e,ri);(!l||t<l.dist)&&(l={color:e,dist:t})}return l.color}let fi,xi,Zi=new Map,yi=new Set;function Gi(e,t,n=1,i=null,l="fg",a=null){let{freqMultiplier:o,singleAccent:r,usePolyIDColorOffset:d}=Oe,u=0,h="fg"==l?li:ai,m="fg"==l?fi:xi,p="fg"==l?o:500*o,g="bg"==l?Tt(t.y,0,P,0,h.length-1):Tt(di(mn(t.x,t.y,0,p,0,1)),m.min,m.max,0,h.length-1);if(d){let n=Xl.getPolygonsAtPoint(t.toArray()).filter((e=>yi.has(e.meta.meta.id))).sort(((e,t)=>e.meta.meta.totalArea-t.meta.meta.totalArea)),i=n?.[0];if(i){let t=i.meta.meta.id;Zi.has(t)||Zi.set(t,e.int(1,h.length-1)),u+=Zi.get(t)}}if(null!==i){let t=gi(a||h[c(s(g+u))%h.length],si,ci*i,Oe.samplesForComplimentary);return e.choice(t)}return h[c(s(g+u))%h.length]}function Wi(e,t,n){var i;return function(t){return i=i||function(e){var t=function(e){return atob(e)}(e),n=t.indexOf("\n",10)+1,i=t.substring(n)+"",l=new Blob([i],{type:"application/javascript"});return URL.createObjectURL(l)}(e),new Worker(i,t)}}var vi=Wi("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y29uc3R7Zmxvb3I6ZSxjZWlsOnQsc2luOmksY29zOm4scG93OnMsYWJzOnIsbWluOm8sbWF4OmwsaHlwb3Q6aCxyb3VuZDphLHNxcnQ6YyxhY29zOmQsc2lnbjpnLGxvZzpmLFBJOnV9PU1hdGgscD0xZS03O2Z1bm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sLm9yaWdpbi5oZWRnZWxpc3Quc3BsaWNlKGQsMSksbC5vcmlnaW4uaGVkZ2VsaXN0Lmxlbmd0aD4wKXtsZXQgZSx0OzA9PT1kPyhlPWwub3JpZ2luLmhlZGdlbGlzdFtsLm9yaWdpbi5oZWRnZWxpc3QubGVuZ3RoLTFdLHQ9bC5vcmlnaW4uaGVkZ2VsaXN0W2RdKTooZT1sLm9yaWdpbi5oZWRnZWxpc3RbZC0xXSx0PWwub3JpZ2luLmhlZGdlbGlzdFtkJWwub3JpZ2luLmhlZGdlbGlzdC5sZW5ndGhdKSx0LnByZXZoZWRnZT1lLnR3aW4sZS50d2luLm5leHRoZWRnZT10fWVsc2UgdGhpcy5kZWxldGVWZXJ0ZXgobC5vcmlnaW4pLGY9ITE7aWYoZD1oLm9yaWdpbi5oZWRnZWxpc3QuaW5kZXhPZihoKSxoLm9yaWdpbi5oZWRnZWxpc3Quc3BsaWNlKGQsMSksaC5vcmlnaW4uaGVkZ2VsaXN0Lmxlbmd0aD4wKXtsZXQgZSx0OzA9PT1kPyhlPWgub3JpZ2luLmhlZGdlbGlzdFtoLm9yaWdpbi5oZWRnZWxpc3QubGVuZ3RoLTFdLHQ9aC5vcmlnaW4uaGVkZ2VsaXN0W2RdKTooZT1oLm9yaWdpbi5oZWRnZWxpc3RbZC0xXSx0PWgub3JpZ2luLmhlZGdlbGlzdFtkJWgub3JpZ2luLmhlZGdlbGlzdC5sZW5ndGhdKSx0LnByZXZoZWRnZT1lLnR3aW4sZS50d2luLm5leHRoZWRnZT10fWVsc2UgdGhpcy
prevhedge=m,m.nexthedge=h;else{const e=d.hedgelist.indexOf(h);let t,n;0===e?(t=d.hedgelist[d.hedgelist.length-1],n=d.hedgelist[(e+1)%d.hedgelist.length]):(t=d.hedgelist[e-1],n=d.hedgelist[(e+1)%d.hedgelist.length]),h.prevhedge=t.twin,t.twin.nexthedge=h,m.nexthedge=n,n.prevhedge=m}if(r)m.prevhedge=h,h.nexthedge=m;else{const e=u.hedgelist.indexOf(m);let t,n;0===e?(t=u.hedgelist[u.hedgelist.length-1],n=u.hedgelist[(e+1)%u.hedgelist.length]):(t=u.hedgelist[e-1],n=u.hedgelist[(e+1)%u.hedgelist.length]),m.prevhedge=t.twin,t.twin.nexthedge=m,h.nexthedge=n,n.prevhedge=h}const p=h.nexthedge,g=m.nexthedge;if(p.face){const e=s.indexOf(p.face);e>-1&&s.splice(e,1),p.face.dispose(),p.face.area<=this.tolerance&&(c=!0)}if(g.face){const e=s.indexOf(g.face);e>-1&&s.splice(e,1),g.face.dispose(),g.face.area<=this.tolerance&&(c=!0)}const b=new Rn(this);b.wedge=p;let f=new Rn(this);if(f.wedge=g,b.equals(f)&&(f.dispose(),f=null),b){let e=b.wedge;for(e.face=b;e.nexthedge!==b.wedge;)e=e.nexthedge,e.face=b;b.area<=this.tolerance&&(c=!0),s.push(b)}if(f){let e=f.wedge;for(e.face=f;e.nexthedge!==f.wedge;)e=e.nexthedge,e.face=f;f.area<=this.tolerance&&(c=!0),s.push(f)}if(c)for(let e=0,t=s.length;e<t;e++)s[e]._holesDirty=!0}removeEdge(e,t,n,i){const{vertices:l,hedges:a,faces:s}=this,o=this.findHedge(e,t,n,i);if(!o)return;const r=o.twin,c=o.nexthedge,d=r.nexthedge;let u,h=!0,m=!0,p=!1;if(u=a.indexOf(o),a.splice(u,1),u=a.indexOf(r),a.splice(u,1),u=s.indexOf(o.face),u>-1&&s.splice(u,1),o.face.dispose(),o.face.area<=this.tolerance&&(p=!0),u=s.indexOf(r.face),u>-1&&s.splice(u,1),r.face.dispose(),r.face.area<=this.tolerance&&(p=!0),u=o.origin.hedgelist.indexOf(o),o.origin.hedgelist.splice(u,1),o.origin.hedgelist.length>0){let e,t;0===u?(e=o.origin.hedgelist[o.origin.hedgelist.length-1],t=o.origin.hedgelist[u]):(e=o.origin.hedgelist[u-1],t=o.origin.hedgelist[u%o.origin.hedgelist.length]),t.prevhedge=e.twin,e.twin.nexthedge=t}else this.deleteVertex(o.origin),m=!1;if(u=r.origin.hedgelist.indexOf(r),r.origin.hedgelist.splice(u,1),r.origin.hedgelist.length>0){let e,t;0===u?(e=r.origin.hedgelist[r.origin.hedgelist.length-1],t=r.origin.hedgelist[u]):(e=r.origin.hedgelist[u-1],t=r.origin.hedgelist[u%r.origin.hedgelist.length]),t.prevhedge=e.twin,e.twin.nexthedge=t}else this.deleteVertex(r.origin),h=!1;o.dispose(),r.dispose();const g=h?new Rn(this):null;g&&(g.wedge=c);let b=m?new Rn(this):null;if(b&&(b.wedge=d),g&&b)try{g.equals(b)&&(b.dispose(),b=null)}catch{b=null}if(g){let e=g.wedge;for(e.face=g;e.nexthedge!==g.wedge;){if(e=e.nexthedge,!e.face)return;e.face=g}g.area<=this.tolerance&&(p=!0),s.push(g)}if(b){let e=b.wedge;for(e.face=b;e.nexthedge!==b.wedge;)e=e.nexthedge,e.face=b;b.area<=this.tolerance&&(p=!0),s.push(b)}if(p)for(let e=0,t=s.length;e<t;e++)s[e]._holesDirty=!0}splitEdge(e,t,n,i,l,a){const{vertices:s,hedges:o}=this;let r=this.findVertex(l,a),c=this.findHedge(e,t,n,i);if(!c)return!1;if(r)return!0;const d=c.twin;let u;const h=this.addVertex(l,a),m=new Gn(h,c.origin),p=new Gn(d.origin,h);o.push(m),o.push(p);const g=new Gn(h,d.origin),b=new Gn(c.origin,h);return o.push(g),o.push(b),c.face.wedge===c&&(c.face.wedge=m),c.face._vertexlistDirty=!0,m.face=c.face,p.face=c.face,d.face.wedge===d&&(d.face.wedge=g),d.face._vertexlistDirty=!0,g.face=d.face,b.face=d.face,m.nexthedge=p,p.prevhedge=m,g.nexthedge=b,b.prevhedge=g,m.prevhedge=c.prevhedge!==d?c.prevhedge:b,m.prevhedge.nexthedge=m,p.nexthedge=c.nexthedge!==d?c.nexthedge:g,p.nexthedge.prevhedge=p,g.prevhedge=d.prevhedge!==c?d.prevhedge:p,g.prevhedge.nexthedge=g,b.nexthedge=d.nexthedge!==c?d.nexthedge:m,b.nexthedge.prevhedge=b,m.twin=b,p.twin=g,g.twin=p,b.twin=m,h.hedgelist.push(p,b),u=c.origin.hedgelist.indexOf(c),c.origin.hedgelist.splice(u,1,m),u=d.origin.hedgelist.indexOf(d),d.origin.hedgelist.splice(u,1,g),c.dispose(),d.dispose(),u=o.indexOf(c),o.splice(u,1),u=o.indexOf(d),o.splice(u,1),{h1:m,h2:p}}intersectFaceWithPolyLine(e,t,n=!1,i=!1){let l=[],a=i?t.length:t.length-1;for(let i=0;i<a;i++){let a=[t[i],t[(i+1)%t.length]];if(l.push(...e.intersectWithLineSeg(a.map((e=>(new zt).fromArray(e))))),n&&l.length>=2)break}return l}getFacesAtPoint(e){let t=[],n=new zt(...e);for(let e of this.faces)e.aabb.containsPoint(n)&&e.containsPoint(n)&&t.push(e);return t}getFacesIntersectingPoly(e){let t=e.map((e=>(new zt).fromArray(e))),n=new nn;n.expands(t);let i=[];for(let l of this.faces)if(!(l.area<=this.tolerance)&&n.intersects(l.aabb)){if(Mn(t,l.vertexlist)){i.push({face:l,intersections:[],isContained:!0});continue}let n=[];for(let i=0;i<e.length;i++){let a=[t[i],t[(i+1)%e.length]];n.push(...l.intersectWithLineSeg(a))}n.length>0&&i.push({face:l,intersections:n,isContained:!1})}return i}}class Ln extends vn{tolerance;constructor(e,t,n=Wn){super(e,t,n),this.tolerance=n}isPolyLineSegmentOnEdge(e,t){for(let n=0;n<t.length-1;n++){let i=[t[n],t[n+1]];if(this.isLineSegmentOnEdgeOfFace(e,i),this.tolerance)return!0}}isLineSegmentOnEdgeOfFace(e,t,n=b){for(let i=0;i<e.vertexlist.length;i++)if(Sn([e.vertexlist[i].toArray(),e.vertexlist[(i+1)%e.vertexlist.length].toArray()],t),n)return!0;return!1}getFacesIntersectingAABB(e){let t=[];for(let n of this.faces.filter((e=>e.area>0)))e.intersects(n.aabb,this.tolerance)&&t.push(n);return t}removeEdgesInsidePolygon(e,t=100){let n=new nn;n.expands(e.map((e=>(new zt).fromArray(e))));let i=e.map((e=>(new zt).fromArray(e))),l=this.getFacesIntersectingAABB(n),a=[];for(let t of l){let n=t.vertexlist;for(let t=0;t<n.length;t++){let l=n[t],s=n[(t+1)%n.length];if(!Tn(i,l,this.tolerance)||!Tn(i,s,this.tolerance))continue;let o=0;[l,s].forEach((t=>{Cn(t.toArray(),e,this.tolerance)&&o++})),o>1||a.push([l,s])}}for(let e of a)J.bool(t)&&this.removeEdge(e[0].x,e[0].y,e[1].x,e[1].y);this.cleanupTrailingEdges()}insertPolygon(e,t=!0){let n=[],i=new nn;i.expands(e.map((e=>(new zt).fromArray(e)))),i.expandByValue(this.tolerance);let l=this.getFacesIntersectingAABB(i),a=new Set;for(let e of l){let t=e.vertexlist;for(let e=0;e<t.length;e++){let n=t[e],i=t[(e+1)%t.length],l=this.findHedge(n.x,n.y,i.x,i.y);a.has(l.twin)||a.add(l)}}for(let t of e)n.push({type:"addVertex",data:{x:t[0],y:t[1]}});for(let i of a){let l=[];e:for(let a=0;a<(t?e.length:e.length-1);a++){let t=[new zt(...e[a]),new zt(...e[(a+1)%e.length])],s=i.intersectWithLineSegment(t);if(s.type==gn.intersecting){for(let e of l)if(e.isEqualTo(s.point))continue e;n.push({type:"addVertex",data:{x:s.point.x,y:s.point.y}})}}}for(let i=0;i<(t?e.length:e.length-1);i++){let t=[e[i],e[(i+1)%e.length]];n.push({type:"addEdge",data:{from:{x:t[0][0],y:t[0][1]},to:{x:t[1][0],y:t[1][1]}}})}this.executeAddOperations(n)}splitFaceByPolyLine(e,t,n=!1,i=!1,l=!1){const a=(e,t,n,i)=>{const l=[.5,.25,.75];for(let a of l){let l=e.lerp(t,a);if(n.containsPoint(l)&&!n.isPointOnBoundary(l,i))return!0}return!1},s=(e,t,n,i)=>{let l=[.25,.5,.75],a=0;for(let s of l){let l=e.lerp(t,s);if(n.isPointOnBoundary(l,i)&&(a++,a>=2))return!0}return a>=2};let o=[],r=[],c=!1,d=0;if(n){let n=t.findIndex((t=>!e.containsPoint(new zt(...t))||e.isPointOnBoundary(new zt(...t),this.tolerance)));if(!(n>=0))return!1;t=t.slice(n).concat(t.slice(0,n))}const u=n?t.length:t.length-1;for(let n=0;n<u;n++){let i=new zt(...t[n]),l=new zt(...t[(n+1)%t.length]),u=[i,l],h=e.intersectWithLineSeg(u);d+=h.length;let m=[i,...h.map((e=>e.point)),l];m=Xn(i,l,m,!0,this.tolerance);for(let t=0;t<m.length-1;t++){let n=m[t],i=m[t+1];a(n,i,e,this.tolerance)&&!s(n,i,e,this.tolerance)?(c||(r=[n],c=!0),r.push(i)):c&&(o.push(r),r=[],c=!1)}}if(!n&&c&&r.length>1&&o.push(r),i||(o=o.filter((t=>{let n=t[Math.floor(t.length/2)].lerp(t[Math.ceil(t.length/2)],.5);return e.containsPoint(n)}))),o.length>1&&l){let e=null;for(let t of o){let i=0;for(let e=0;e<(n?t.length:t.length-1);e++)i+=t[e].distanceTo(t[(e+1)%t.length]);(!e||i>e.length)&&(e={length:i,line:t})}if(!e)return!1;o=[e.line]}if(0===o.length)return!1;if(i)return{lines:o,intersectionCount:d};let h=[];for(let e of o)for(let t of e)h.push({type:"addVertex",data:{x:t.x,y:t.y}});for(let e of o)for(let t=0;t<e.length-1;t++)h.push({type:"addEdge",data:{from:{x:e[t].x,y:e[t].y},to:{x:e[t+1].x,y:e[t+1].y}}});return this.executeAddOperations(h),!0}executeAddOperations(e){const t=e.filter((e=>"addVertex"===e.type)),n=e.filter((e=>"addEdge"===e.type));let i=[];for(const e of n){let t=new nn,n=new zt(e.data.from.x,e.data.from.y),l=new zt(e.data.to.x,e.data.to.y);t.expands([n,l]),t.expandByValue(this.tolerance);let a=new Set;for(let e of this.hedges){let i=e.getAABB();if(i.expandByValue(this.tolerance),i.intersects(t)){let t=e.intersectWithLineSegment([n,l]);t.type==gn.intersecting&&(a.add(t.point),this.findVertex(t.point.x,t.point.y)||this.splitEdge(e.origin.x,e.origin.y,e.twin.origin.x,e.twin.origin.y,t.point.x,t.point.y))}}if(a.size>1){let e=Xn(n,l,[n,...a,l],!0,this.tolerance);for(let t=0;t<e.length-1;t++)i.push({type:"addEdge",data:{from:{x:e[t].x,y:e[t].y},to:{x:e[t+1].x,y:e[t+1].y}}})}else i.push(e)}for(const e of t){let{x:t,y:n}=e.data;if(!this.findVertex(t,n)){let e=!1;for(let i of this.hedges){let l=i.getAABB();l.expandByValue(this.tolerance),l.containsPoint(new zt(t,n))&&!this.findVertex(t,n)&&Vn([t,n],[i.origin.toArray(),i.twin.origin.toArray()])&&(e=!1!==this.splitEdge(i.origin.x,i.origin.y,i.twin.origin.x,i.twin.origin.y,t,n))}!e&&this.addVertex(t,n)}}for(const e of i.filter((e=>"addEdge"===e.type))){let{from:t,to:n}=e.data,i=this.findVertex(t.x,t.y),l=this.findVertex(n.x,n.y);if(i&&l){let e=new Set;e.add(i);let t=new nn;t.expands([i,l]),t.expandByValue(this.tolerance);for(let n of this.verticesInBB(t))Vn(n.toArray(),[i.toArray(),l.toArray()])&&e.add(n);e.add(l);let n=Xn(i,l,Array.from(e),!0);for(let e=0;e<n.length-1;e++)this.findHedge(n[e].x,n[e].y,n[e+1].x,n[e+1].y)||this.addEdge(n[e].x,n[e].y,n[e+1].x,n[e+1].y)}}}cleanupDegenerateHoles(){let e=new Set;this.faces.forEach((t=>{for(let n of this.faces)t!=n&&t.aabb.containsBB(n.aabb)&&t.vertexlist.every((e=>n.containsPoint(e)))&&n.hedges.forEach((t=>{t.face==n&&e.add(t)}))})),this.faces.filter((e=>e.area>0)).forEach((t=>{t.holes.forEach((n=>{n.hedges.forEach((n=>{n.face==t&&e.add(n)}))}))}));for(const t of e)t.origin&&t.twin.origin&&this.removeEdge(t.origin.x,t.origin.y,t.twin.origin.x,t.twin.origin.y)}cleanupTrailingEdges(){this.hedges.forEach((e=>{e.face==e.twin.face&&this.removeEdge(e.origin.x,e.origin.y,e.twin.origin.x,e.twin.origin.y)}))}}function Sn(e,t,n=b){let[i,l]=e,[a,o]=t;const r=l[0]-i[0],c=l[1]-i[1],u=o[0]-a[0],h=o[1]-a[1];if(s(r*h-c*u)>n)return!1;const m=s(r*(i[1]-a[1])-(i[0]-a[0])*c),p=d(r*r+c*c);return!(p<n)&&m/p<n}function Xn(e,t,n,i=!1,l=b){const a=t.x-e.x,s=t.y-e.y;let o=a*a+s*s;if(o<l)return n;const r=1/o,c=n.map((t=>{const n=((t.x-e.x)*a+(t.y-e.y)*s)*r;return{point:t,t:Math.max(0,Math.min(1,n))}}));c.sort(((t,n)=>{const i=t.t-n.t;return Math.abs(i)>l?i:(t.point.x-e.x)**2+(t.point.y-e.y)**2-((n.point.x-e.x)**2+(n.point.y-e.y)**2)}));let d=c.map((e=>e.point));return i&&(d=function(e,t){const n=[],i=new Map;for(const l of e){const e=`${Math.round(l.x/t)},${Math.round(l.y/t)}`;i.has(e)||(i.set(e,!0),n.push(l))}return n}(d,l)),d}function Cn(e,t,n=b){for(let i=0;i<t.length;i++){const l=t[i],a=t[(i+1)%t.length],s=o(l[0],a[0])-n,c=r(l[0],a[0])+n,d=o(l[1],a[1])+-n,u=r(l[1],a[1])+n;if(e[0]>=s&&e[0]<=c&&e[1]>=d&&e[1]<=u&&wn(e,l,a)<=n*n)return!0}return!1}function Vn(e,t,n=b){const[i,l]=t,a=(e[1]-i[1])*(l[0]-i[0])-(e[0]-i[0])*(l[1]-i[1]);if(Math.abs(a)>n)return!1;const s=(e[0]-i[0])*(l[0]-i[0])+(e[1]-i[1])*(l[1]-i[1]);return!(s<-n||s-((l[0]-i[0])*(l[0]-i[0])+(l[1]-i[1])*(l[1]-i[1]))>n)}function wn(e,t,n){const i=n[0]-t[0],l=n[1]-t[1],a=i*i+l*l;if(a<1e-14){const n=e[0]-t[0],i=e[1]-t[1];return n*n+i*i}let s=((e[0]-t[0])*i+(e[1]-t[1])*l)/a;s=Math.max(0,Math.min(1,s));const o=t[0]+s*i,r=t[1]+s*l,c=e[0]-o,d=e[1]-r;return c*c+d*d}let Kn=0;class Rn{_dcel;id=Kn++;changeIndex=0;wedge=null;_area=0;_areaDirty=!0;_vertexlist=[];_vertexlistDirty=!0;_centerDirty=!0;_hedges=[];_hedgesDirty=!0;_center=null;_hasInsertedIntoPQ=!1;_holes=[];_holesDirty=!0;_aabb=null;_aabbDirty=!0;constructor(e){this._dcel=e}get area(){return this._areaDirty&&(this._area=zn(this.vertexlist),this._areaDirty=!1),this._area}get areaExceptHoles(){const e=this.holes;let t=this.area;for(let n=0,i=e.length;n<i;n++)t+=e[n].area;return t}get internal(){return this.area>Wn}get external(){return this.area<=Wn}get hedges(){if(this._hedgesDirty){const e=[];let t=this.wedge,n=0;const i=1e6;for(e.push(t);t.nexthedge!==this.wedge&&n<i;)t=t.nexthedge,e.push(t),n++;if(n>=i)throw Error("Face vertex list is too long");this._hedges=e,this._hedgesDirty=!1}return this._hedges}get center(){if(this._centerDirty){const e=this.vertexlist;let t=0,n=0,i=0;for(let l=0;l<e.length;l++){const a=e[l].x,s=e[l].y,o=e[(l+1)%e.length].x,r=e[(l+1)%e.length].y,c=a*r-s*o;t+=c,n+=(a+o)*c,i+=(s+r)*c}t*=.5,n/=6*t,i/=6*t,this._center=new zt(n,i),this._centerDirty=!1}return this._center}get vertexlist(){return this._vertexlistDirty&&this.cleanVertexList(),this._vertexlist}cleanVertexList(){if(!this._vertexlistDirty)return;let e=this.wedge;const t=this._vertexlist;t.length=0;let n=0;const i=1e6;for(t.push(e.origin);e.nexthedge!==this.wedge&&n<i;)e=e.nexthedge,t.push(e.origin),n++;if(n>=i)throw Error("Face vertex list is too long");this._vertexlistDirty=!1}get holes(){if(this._holesDirty&&(this._holesDirty=!1,this._holes.length=0,this.internal)){const e=this._dcel.faces;for(let t=0,n=e.length;t<n;t++)this._tryAddHole(e[t])}return this._holes}get aabb(){return this._aabb||(this._aabb=new nn),this._aabbDirty&&(this._aabb.reset(),this._aabb.expands(this.vertexlist),this._aabbDirty=!1),this._aabb}equals(e){const t=this.vertexlist,n=e.vertexlist;if(t.length!==n.length)return!1;const i=t.length;for(let e=0;e<i;e++)for(let l=0;l<i&&t[l]===n[(e+l)%i];l++)if(l===i-1)return!0;return!1}findNearestEdge(e){return function(e,t){const n=Yn(e);let i=[e[0],e[1]],l=1e10,a=-1/0,s=null;for(let o=0;o<e.length;o++){const r=[e[o],e[(o+1)%e.length]],{distance:c,projection:d}=Pn(t,r[0],r[1]),u={x:r[1].x-r[0].x,y:r[1].y-r[0].y};let h={x:-u.y,y:u.x},m={x:(r[0].x+r[1].x)/2-n.x,y:(r[0].y+r[1].y)/2-n.y};h.x*m.x+h.y*m.y<0&&(h={x:u.y,y:-u.x});const p={x:t.x-(r[0].x+r[1].x)/2,y:t.y-(r[0].y+r[1].y)/2},g=h.x*p.x+h.y*p.y;(c<l||c===l&&g>a)&&g>0&&(l=c,i=r,a=g,s=d)}return{edge:i,distance:l,edgePoint:s}}(this.vertexlist,e)}containsPoint(e){return!(!this.aabb.containsPoint(e)||!Tn(this.vertexlist,e))}isPointOnBoundary(e,t=Wn){let n=this.vertexlist.map((e=>e.toArray()));return!!Cn(e.toArray(),n,t)}intersectWithPolyLine(e,t=!1){let n=[];const i=t?e.length:e.length-1;for(let l=0;l<i;l++){const i=t?(l+1)%e.length:l+1,a=[e[l],e[i]];n.push(...this.intersectWithLineSeg(a))}return n}intersectWithLineSeg(e){const t=[],n=this.hedges.filter((e=>e.face==this)),i=(new nn).expands(e);for(let l of n){if(!l.getAABB().intersects(i))continue;const n=l.intersectWithLineSegment(e);n.type===gn.intersecting&&t.push({point:n.point,edge:[l.origin,l.twin.origin]})}return t}dirty(){this._areaDirty=!0,this._hedgesDirty=!0,this._centerDirty=!0,this._vertexlistDirty=!0,this._holesDirty=!0,this._aabbDirty=!0,this.changeIndex++}dispose(){this.wedge=null,this._vertexlist.length=0,this._holes.length=0,this._aabb=null,this._dcel=null}_tryAddHole(e){this._holesDirty||e.external&&this.area-Math.abs(e.area)>Wn&&this.aabb.containsPoints(e.vertexlist)&&Mn(this.vertexlist,e.vertexlist,Wn)&&this._holes.push(e)}}function kn(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}function Tn(e,t,n=Wn){if(Cn([t.x,t.y],e.map((e=>e.toArray())),n))return!0;let i=0;for(let n=0;n<e.length;n++){const l=e[n],a=e[(n+1)%e.length];l.y<=t.y?a.y>t.y&&kn(l,a,t)>0&&i++:a.y<=t.y&&kn(l,a,t)<0&&i--}return 0!==i}function Mn(e,t,n=Wn){for(let i=0,l=t.length;i<l;i++)if(!Tn(e,t[i],n))return!1;return!0}function zn(e){if(e.length<3)return 0;let t=0;for(let n=0;n<e.length;n++){const i=(n+1)%e.length;t+=e[n].x*e[i].y-e[n].y*e[i].x}return.5*t}function Yn(e){let t=0,n=0;for(let i=0;i<e.length;i++)t+=e[i].x,n+=e[i].y;return new zt(t/e.length,n/e.length)}function Pn(e,t,n,i=Wn){const l=(n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y);if(l<i)return{distance:e.distanceTo(t),projection:t};let a=((e.x-t.x)*(n.x-t.x)+(e.y-t.y)*(n.y-t.y))/l;a<-i?a=0:a>1+i&&(a=1);const s=new zt(t.x+a*(n.x-t.x),t.y+a*(n.y-t.y));return{distance:e.distanceTo(s),projection:s}}function In(e,t,n=b){const[{x:i,y:l},{x:a,y:s}]=e,[{x:o,y:r},{x:c,y:d}]=t,u=(i-a)*(r-d)-(l-s)*(o-c);if(Math.abs(u)<n)return null;const h=((i-o)*(r-d)-(l-r)*(o-c))/u,m=((a-i)*(l-r)-(s-l)*(i-o))/u;return h>=-n&&h<=1+n&&m>=-n&&m<=1+n?new zt(i+h*(a-i),l+h*(s-l)):null}function Hn(e,t){const n=[];for(let i=0;i<t.length;i++){const l=[t[i],t[(i+1)%t.length]],a=In(e,l);a&&n.push({point:a,edge:l})}return n}let Fn=0;function Nn(){return Fn++,Fn}function Un(e){let{boxCenter:t,perspectiveCenter:n,centerBoxMaskDimensions:i=[0,0],width:l,height:a,gThreshold:s=2.5,gMean:o=1,gStdDev:r=1.5}=e;n||(n=t);const[c,d]=t;let[u,h]=n;u=Pt(new zt(u,h)).x,h=Pt(new zt(u,h)).y;let m=[i[0]*ze.scale,i[1]*ze.scale];l=Rt(l,ze.scale),a=Rt(a,ze.scale);let p=[];const g=2*(l+a),b=g/ze.scale,f=g/b;let x=[[u-m[0],h-m[1]],[u+m[0],h-m[1]],[u+m[0],h+m[1]],[u-m[0],h+m[1]]],Z=0,y=0,G=0;for(let e=0;e<b;e++){if(G<l?(Z=c-l/2+G,y=d-a/2):G<l+a?(Z=c+l/2,y=d-a/2+(G-l)):G<2*l+a?(Z=c+l/2-(G-(l+a)),y=d+a/2):(Z=c-l/2,y=d+a/2-(G-(2*l+a))),J.gaussianBool(s,o,r)){let e=Hn([[u,h],[Z,y]].map((e=>new zt(...e))),x.map((e=>new zt(...e))));if(!e[0])continue;let t=[e[0].point.toArray(),[Z,y]];if(p.push(t),J.bool(0)){let e=J.int(1,3)*ze.scale;J.bool(50)&&(e*=-1);let n=[[t[0][0]+e,t[0][1]],[t[1][0]+e,t[1][1]]];p.push(n)}}G+=f}return p}function Dn({center:e,width:t,height:n,angle:a=0}){let[s,o]=e,r=t/2,c=n/2,d=[[s-r,o-c],[s+r,o-c],[s+r,o+c],[s-r,o+c]];return 0!==a&&(d=function(e,t,n){const a=n||function(e){const t=e.reduce(((e,t)=>[e[0]+t[0],e[1]+t[1]]),[0,0]);return[t[0]/e.length,t[1]/e.length]}(e),s=t*g/180;return e.map((e=>{const t=[e[0]-a[0],e[1]-a[1]],n=[t[0]*l(s)-t[1]*i(s),t[0]*i(s)+t[1]*l(s)];return[n[0]+a[0],n[1]+a[1]]}))}(d,a,e)),d}function On(e){let{center:n,radius:i,startAngle:l=0,endAngle:a=180}=e,s=[],[o,r]=n;l=me(l),a=me(a);let c=t(i*Math.abs(a-l)*.125);for(let e=0;e<=c;e++){let t=l+e/c*(a-l),n=o+i*Math.cos(t),d=r+i*Math.sin(t);s.push([n,d])}let d=function(e){let t=0,n=0;for(let i=0;i<e.length;i++)t+=e[i][0],n+=e[i][1];return[t/e.length,n/e.length]}(s),u=[o-d[0],r-d[1]];return s=s.map((e=>[e[0]+u[0],e[1]+u[1]])),s}class Bn{startX;startY;endX;endY;distances;constructor(e,t,n,i){this.startX=e,this.startY=t,this.endX=n,this.endY=i;const l=n-e+1,a=i-t+1;this.distances=Array(a).fill(null).map((()=>Array(l).fill(1/0)))}initializeWithEmptyCells(e,t){for(let e=0;e<this.distances.length;e++)for(let t=0;t<this.distances[0].length;t++)this.distances[e][t]=0;e.forEach((e=>{const[n,i]=t(e),l=n-this.startX,a=i-this.startY;l>=0&&a>=0&&l<this.distances[0].length&&a<this.distances.length&&(this.distances[a][l]=1/0)}));for(let e=0;e<this.distances.length;e++)this.distances[e][0]=0,this.distances[e][this.distances[0].length-1]=0;for(let e=0;e<this.distances[0].length;e++)this.distances[0][e]=0,this.distances[this.distances.length-1][e]=0;this.performJFA()}performJFA(){const e=this.distances.length,t=this.distances[0].length;let n=[];for(let i=0;i<e;i++)for(let e=0;e<t;e++)0===this.distances[i][e]&&n.push([e,i]);for(;n.length>0;){let e=n.length;for(let t=0;t<e;t++){const[e,t]=n.shift();this.checkAndUpdate(e,t,n)}}}checkAndUpdate(e,t,n){const i=[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]];for(const[l,a]of i){const i=e+l,s=t+a;i>=0&&i<this.distances[0].length&&s>=0&&s<this.distances.length&&this.distances[s][i]>this.distances[t][e]+1&&(this.distances[s][i]=this.distances[t][e]+1,n.push([i,s]))}}getDistance(e,t){const n=e-this.startX,i=t-this.startY;return n>=0&&i>=0&&n<this.distances[0].length&&i<this.distances.length?this.distances[i][n]:1/0}}var Qn;!function(e){e.intersecting="INTERSECTING",e.contained="CONTAINED"}(Qn||(Qn={}));class Jn{cells=new Map;lines=new Map;lineMeta=new Map;distanceCalculator;nextLineId=0;cellSize;faceCellIndicesCache=new Map;aabbLineIntersectionCache=new Map;constructor(e,t){this.cellSize=e,t&&this.addLines(t)}getCellBounds(){let e=0,t=0,n=0,i=0;return this.cells.forEach(((l,a)=>{const[s,o]=this.getCellXYfromIndex(a);e=Math.min(e,s),t=Math.min(t,o),n=Math.max(n,s),i=Math.max(i,o)})),{width:n-e,height:i-t,minX:e,minY:t,maxX:n,maxY:i}}getCellIndex(e,t){return`${f(e)},${f(t)}`}getCellXYfromIndex(e){return e.split(",").map(Number)}getCellVertexFromIndex(e){let[t,n]=this.getCellXYfromIndex(e);return new zt(t*this.cellSize,n*this.cellSize)}clear(){this.cells.clear(),this.lines.clear(),this.lineMeta.clear(),this.faceCellIndicesCache.clear(),this.aabbLineIntersectionCache.clear()}addLines(e){e.forEach((e=>this.addLine(e.line,e.meta)))}addLine(e,t){const n=this.nextLineId++;this.lines.set(n,e),this.lineMeta.set(n,t);let i=t.isClosed?e.length:e.length-1;for(let t=0;t<i;t++)this.addSegment(e[t],e[(t+1)%e.length],n);return this.aabbLineIntersectionCache.clear(),n}removeLineById(e){if(this.lines.get(e)){for(let t of this.cells.values())t.delete(e);this.lines.delete(e),this.lineMeta.delete(e),this.aabbLineIntersectionCache.clear()}}addSegment(e,t,n){let i,[l,a]=e,[o,r]=t,c=f(l/this.cellSize),d=f(a/this.cellSize),u=f(o/this.cellSize),h=f(r/this.cellSize),m=s(u-c),p=-s(h-d),g=c<u?1:-1,b=d<h?1:-1,x=m+p;for(;;){const e=this.getCellIndex(c,d);if(this.cells.has(e)||this.cells.set(e,new Set),this.cells.get(e).add(n),c===u&&d===h)break;i=2*x,i>=p&&(x+=p,c+=g),i<=m&&(x+=m,d+=b)}}getLinesIntersectingOrContainedWithinAABB(e){let t=new Set,n=f(e.minX/this.cellSize),i=f(e.maxX/this.cellSize),l=f(e.minY/this.cellSize),a=f(e.maxY/this.cellSize);for(let e=n;e<=i;e++)for(let n=l;n<=a;n++){const i=this.getCellIndex(e,n);this.cells.has(i)&&this.cells.get(i).forEach((e=>t.add(e)))}return Array.from(t).map((e=>({id:Nn(),line:this.lines.get(e),meta:this.lineMeta.get(e)})))}getAllLines(){return Array.from(this.lines).map((([e,t])=>({id:e,line:t,meta:this.lineMeta.get(e)})))}getCellsIntersectedByFace(e){const t=this.faceCellIndicesCache.get(e.id);if(t&&t.changeIndex===e.changeIndex)return t.cellIndices;const n=new Set,i=e.aabb,l=f(i.minX/this.cellSize),a=f(i.maxX/this.cellSize),s=f(i.minY/this.cellSize),o=f(i.maxY/this.cellSize);for(let t=l;t<=a;t++)for(let i=s;i<=o;i++){const l=new nn;l.expands([new zt(t*this.cellSize,i*this.cellSize),new zt((t+1)*this.cellSize,(i+1)*this.cellSize)]);for(let a of l.vertexList)if(e.containsPoint(a)){n.add(this.getCellIndex(t,i));break}}return this.faceCellIndicesCache.set(e.id,{changeIndex:e.changeInd
3, 8., 0.6) * (lineDistanceMax / (uIsShading ? 2. : 2.));\n \n float lineWeightEdgeNoise = fbm(uv + uNoiseOffset + currentLineNoiseOffset, 3, 300., 0.54) * (lineDistanceMax / 10.);\n\n float lineDistance = (lineSDF + lineWeightWobble + lineWeightEdgeNoise); \n \n \n float lineFineNoise = clamp(\n smoothstep(0., 0.9, fbm(uv + currentLineNoiseOffset, 2, 700., 0.9) - 0.1) + remap(lineHardness, 1., 0., 1. - uMaterialHardness, 0.5),\n 0., 1.);\n\n float lineFineNoise2 = clamp(\n smoothstep(0., 0.9, fbm(uv, 1, 900., 0.9)) + remap(lineHardness, 1., 0., 0.01, 0.5),\n 0., (1. - uMaterialHardness) + .1);\n \n\n float alphaWobblePerLine = fbm(uNoiseOffset + currentLineNoiseOffset, 1, 300., 0.9) * 0.015;\n\n float lineColorWobble = 0.008;\n \n float lightnessWobblePerLine = ((fbm(uNoiseOffset + (currentLineNoiseOffset / 1.), 1, 1000., 0.9) + .5) / 2. ) * lineColorWobble;\n localColor.x += lightnessWobblePerLine;\n\n float saturationWobblePerLine = ((fbm(uNoiseOffset + (currentLineNoiseOffset / 1.1), 1, 1100., 0.9) + .5) / 2. ) * (lineColorWobble * 0.4);\n localColor.y += saturationWobblePerLine;\n \n float maxLineHardness = clamp(smoothstep(0., 1., lineHardness - alphaWobblePerLine), 0., 1.);\n\n float lineRolloff = 0.0001;\n float alphaHardLineSpread = lineDistanceMax * 1.;\n float hardLineSS = smoothstep(alphaHardLineSpread + lineRolloff, alphaHardLineSpread - lineRolloff, lineDistance);\n\n float alphaHardLine = clamp(\n (hardLineSS * (1. - lineFineNoise) * (1. - lineFineNoise2)) * maxLineHardness,\n 0., 1.);\n\n float alphaSoftLine = 0.;\n\n if(!uIsShading) {\n float alphaSoftLineNoise = clamp((fbm(uv + currentLineNoiseOffset, 1, 800., 0.9) - 0.3), 0., 1.);\n\n\n float alphaSoftLineSpread = lineDistanceMax * 1.5;\n float softLineSS = smoothstep(alphaSoftLineSpread + lineRolloff, alphaSoftLineSpread - lineRolloff, lineDistance);\n\n alphaSoftLine = clamp(\n (step(lineDistance, alphaSoftLineSpread) * alphaSoftLineNoise) * maxLineHardness,\n 0., .7);\n }\n \n\n float lineAlpha = max(alphaSoftLine, alphaHardLine) * segmentDistanceAlphaMult;\n \n \n\n \n // if(alphaHardLine > alpha) {\n // if(alpha == 0.) {\n // alpha = lineAlpha;\n // }\n // if(uIsShading) {\n // // 0 is always the closest line, so use this as our based for subsequent accumulation\n // if(i == 0) {\n // alpha = lineAlpha * 0.7;\n // } else {\n // alpha = clamp(alpha + (1.0 - alpha) * lineAlpha * alphaIncrement, 0., 1.);\n // }\n // } else {\n // alpha = max(alpha, lineAlpha);\n // }\n \n // clamp(alpha, 0., 1.);\n accumulationValue = clamp(accumulationValue + (1.0 - accumulationValue) * lineAlpha * 0.1, 0., 5.);\n // alpha = clamp(alpha + (1.0 - alpha) * lineAlpha * alphaIncrement, 0., 1.);\n // alpha = clamp(alpha, 0., 1.);\n\n // if(alphaHardLine > alpha) {\n alpha = clamp(1.0 - (1.0 - alpha) * (1.0 - lineAlpha * alphaIncrement), 0., 1.);\n color.x = clamp(\n 1.0 - (1.0 - localColor.x) * (1.0 - lineAlpha * lightnessIncrement), \n originalColor.x - accumulationClamp.x, \n originalColor.x + accumulationClamp.x\n );\n if(!uDisableSaturationShift) {\n color.y = clamp(1.0 - (1.0 - localColor.y) * (1.0 - lineAlpha * chromaIncrement), \n originalColor.y - accumulationClamp.y, \n originalColor.y + accumulationClamp.y\n );\n }\n \n \n }\n\n if(alpha <= 0.) {\n return vec4(frameBuffer, 1.);\n }\n\n // accumulationValue *= (smoothstep(.08, .0, sdf) + .5);\n \n // if(uIsShading) {\n // float chromaIncrement = 0.07 * uAccumulationStrength; // adjust for subtlety\n // float lightnessIncrement = -0.07 * uAccumulationStrength;\n\n // // if(uIsShading) {\n // // accumulationValue = clamp(accumulationValue, 0., .1);\n // color.x += accumulationValue * lightnessIncrement;\n // color.y += accumulationValue * chromaIncrement;\n\n // color.x += 0.08;\n // color.y -= (chromaIncrement * 0.4);\n // }\n\n // alpha = clamp(alpha, 0., 1.);\n float brightnessNoiseInfluence = smoothstep(-1., 1., fbm(uv + uNoiseOffset, 2, 50., 0.9)) + 0.4;\n float brightnessNoise = smoothstep(0.1, 0.31, fbm(uv + uNoiseOffset, 2, 1800., 0.5)) * brightnessNoiseInfluence * 0.002;\n color.x += brightnessNoise;\n\n float alphaNoise2 = smoothstep(-1., 1., fbm(uv, 1, 1000., 0.1)) * 0.02;\n float alphaNoise = smoothstep(-0.6, 1., fbm(uv, 2, 1200., 0.1)) * 0.12;\n alpha -= (alphaNoise + alphaNoise2);\n alpha = clamp(alpha, 0., 1.);\n\n // float colourShift = (smoothstep(0.1, 0.4, fbm(uv + uNoiseOffset, 2, 5., 0.6)) - 0.5) * 0.0001;\n // color.x += colourShift;\n\n \n \n float colorBrightWobble = fbm(uv + uNoiseOffset, 2, 20., 0.9) * 0.001;\n float colorEase = (\n easeOut(smoothstep(.02, .0, sdf + colorBrightWobble), 1.) \n * (0.01 + (accumulationValue * 0.02))\n );\n\n float colorBrightNoise = smoothstep(-0.4, 0.4, fbm(uv + uNoiseOffset, 2, 700., 0.9));\n float darkenEdge = easeOut(smoothstep(.0035, .0, sdf - (colorBrightWobble * 4.)), 1.) \n * (0.06 + (accumulationValue * 0.02)) * colorBrightNoise;\n\n colorEase += darkenEdge;\n \n color.x -= colorEase;\n color.y += (colorEase * 0.4);\n\n // color.x += 0.005;\n // color.y -= 0.005;\n\n // color.x -= 0.01;\n // color.y -= 0.02;\n\n // LINE SDF\n \n // LINE BRIGHTNESS\n \n color.x = clamp(color.x, 0., .84);\n color.y = clamp(color.y, 0., .4); \n // float satWeight = 0.05;\n // color.y *= remap(uBrightness, 0., 2., 1. + satWeight + 0.3, 1. - satWeight);\n\n \n\n // LIGHTING\n vec3 lightDir = normalize(vec3(.6f, 1.6f, 1.6f));\n vec3 lightColor = vec3(1.0f) * 1.7f;\n \n vec3 paperTextureNormals = calculateNormals(screenSpaceUV + msaaOffset, 0.0002 * tileScaleFactor.x, 4.);\n vec3 diffuse = calculateDiffuse(paperTextureNormals, lightDir, lightColor);\n\n vec3 colorRGB = OKLCHtoP3LRGB(color) * diffuse;\n vec3 colorMult = (frameBuffer * colorRGB) * diffuse;\n\n colorRGB = mix(frameBuffer, mix(colorMult, colorRGB * diffuse, clamp(0.9, 1., alpha + 0.3)), alpha);\n // colorRGB\n\n // colorRGB = mix(frameBuffer, colorRGB, alpha);\n\n // if(uEnableFadeAtLineSegment) {\n // colorRGB = vec3(segmentDistanceAlphaMult);\n // }\n\n return vec4(colorRGB, 1.0);\n }\n\n void main() {\n const vec2 H2 = vec2(0.5698402909980532f, 0.7548776662466927f);\n vec2 px = 1.f / resolution;\n px *= 1.25;\n vec2 uv = vUv;\n\n \n // Check if this fragment is within the SDF\n vec2 uvOffset = lookupWarpSample(uv).xy;\n float texCheck = (texture(tPolyEdgeDistance, uv + uvOffset).r - 0.5) * 2.0;\n if(texCheck < -0.1) {\n discard;\n }\n\n vec3 frameBuffer = texture(tScreenBuffer, vUv).rgb;\n\n\n const float samples = 4.f;\n \n vec4 sumColour;\n vec2 d0 = vec2(randomNonDet(uv), randomNonDet(uv + 1.f));\n\n \n for(float i = 0.f; i < samples; i++) {\n vec2 d = (fract(i * H2 + d0) - .5f);\n\n vec2 localCoord = vUv + d * px; /* changed */\n vec2 screenCoord = uTileOffset + localCoord * uTileSize; /* changed */\n vec2 globalUV = screenCoord / resolution; /* changed */\n\n // vec4 sampleColor = render(globalUV, vUv, d * px);\n vec4 sampleColor = render(globalUV, vUv, d * px, frameBuffer);\n // sampleColor.rgb *= sampleColor.a; // Convert to premultiplied alpha\n sumColour += sampleColor;\n }\n \n vec4 averageColor = clamp(sumColour / samples, 0., 1.);\n \n outColor = averageColor;\n }\n `});let n=t.isShading?At:Et;n.updatePolylines(t.lines,t.closedPolyOrLine);let i=jt.uniforms;re(jt),Vt.material=jt,i.tScreenBuffer.value=Xt.getReadBuffer().texture;let l=t.lineColor;if(i.uLineColor.value=Ht(l),i.uDisableSaturationShift.value=t.disableSaturationShift||!1,i.uLineWeight.value=t.lineWeight,i.uLineHardness.value=t.linePressure,i.uMaterialHardness.value=t.materialHardness||1,i.uIsShading.value=t.isShading||!1,i.tWarpTex.value=t.canWarp?Ct.displacementMapWarped.target.texture:Ct.displacementMap.target.texture,i.uNoiseOffset.value=new le(...t.noiseOffset),i.uFaceIndex.value=_t++,i.uLineWeight.value=t.lineWeight,i.uTaperingFadeIn.value=t.lineTapering.fade.in.enabled?t.lineTapering.fade.in.length:0,i.uTaperingFadeOut.value=t.lineTapering.fade.out.enabled?t.lineTapering.fade.out.length:0,i.uTaperingScaleIn.value=t.lineTapering.scale.in.enabled?t.lineTapering.scale.in.length:0,i.uTaperingScaleOut.value=t.lineTapering.scale.out.enabled?t.lineTapering.scale.out.length:0,i.uBrightness.value=t.lineBrightness||1,i.uEdgeSharpness.value=t.edgeSharpness||1,i.uAccumulationStrength.value=t.accumulationStrength||1,t?.fadeAtLineSegment){let e=Ot(t.fadeAtLineSegment.segment);const n=i.uFadeAtLineSegmentVertices.value;n[0]=e[0][0],n[1]=e[0][1],n[2]=e[1][0],n[3]=e[1][1],i.uFadeAtLineSegmentDistance.value=t.fadeAtLineSegment.distance,i.uFadeAtLineSegmentStrength.value=t.fadeAtLineSegment.strength,i.uEnableFadeAtLineSegment.value=!0,jt.needsUpdate=!0}else i.uEnableFadeAtLineSegment.value=!1;if(!qt||$t!==n){const{cellsWide:e,cellsHigh:t,cellSize:l}=n,{segmentDataTexture:a,segmentMetaDataTexture:s,segmentIndexTexture:o}=n.getTextures();i.uSegmentDataTex.value=a,i.uSegmentMetaDataTex.value=s,i.uSegmentIndexTex.value=o,i.tPolyLineGrid.value={width:e*l,height:t*l,cellSize:l},qt=!0}i.uIsClosedPoly.value=t.closedPolyOrLine,X.setRenderTarget(Xt.getWriteBuffer()),Vt.render(),Xt.copyAndSwapBuffers(),$t=n}let tn=new e.Vector4;class nn{minX=1/0;minY=1/0;maxX=-1/0;maxY=-1/0;constructor(){}get width(){return this.maxX-this.minX}get height(){return this.maxY-this.minY}get center(){return new zt((this.minX+this.maxX)/2,(this.minY+this.maxY)/2)}get vertexList(){return[new zt(this.minX,this.minY),new zt(this.maxX,this.minY),new zt(this.maxX,this.maxY),new zt(this.minX,this.maxY)]}get area(){return this.width*this.height}reset(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0}expand(e){this.minX=Math.min(e.x,this.minX),this.minY=Math.min(e.y,this.minY),this.maxX=Math.max(e.x,this.maxX),this.maxY=Math.max(e.y,this.maxY)}expands(e){for(let t=0,n=e.length;t<n;t++)this.expand(e[t]);return this}expandByPoint(e){return this.minX=Math.min(e[0],this.minX),this.minY=Math.min(e[1],this.minY),this.maxX=Math.max(e[0],this.maxX),this.maxY=Math.max(e[1],this.maxY),this}expandsByPoint(e){for(let t=0,n=e.length;t<n;t++)this.expandByPoint(e[t])}intersects(e,t=b){return!(e.maxX<this.minX-t||e.minX>this.maxX+t||e.maxY<this.minY-t||e.minY>this.maxY+t)}expandByValue(e){return this.minX-=e,this.minY-=e,this.maxX+=e,this.maxY+=e,this}containsPoint(e){return e.x<=this.maxX+b&&e.x>=this.minX-b&&e.y<=this.maxY+b&&e.y>=this.minY-b}distanceToPoint(e){const t=r(this.minX-e.x,0,e.x-this.maxX),n=r(this.minY-e.y,0,e.y-this.maxY);return d(t*t+n*n)}containsBB(e){return e.minX>=this.minX-b&&e.maxX<=this.maxX+b&&e.minY>=this.minY-b&&e.maxY<=this.maxY+b}containsPoints(e){for(let t=0,n=e.length;t<n;t++)if(!this.containsPoint(e[t]))return!1;return!0}size(){return{width:this.maxX-this.minX,height:this.maxY-this.minY}}}let ln,an=[];var sn,on;function rn(i){ln=ln||new e.ShaderMaterial({uniforms:{resolution:{value:new e.Vector2(B,Q)},tPositions:{value:new e.DataTexture},uPositionsCount:{value:0},...ce()},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:ie,fragmentShader:`\n precision highp float;\n\t\t\tprecision highp int;\n \n uniform highp sampler2D tPositions;\n uniform vec2 resolution;\n uniform int uPositionsCount;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n \n varying vec2 vUv;\n out vec4 outColor;\n\n ${ne}\n\n float pointLineSegSDF(vec2 p, vec2 a, vec2 b) {\n vec2 pa = p - a;\n vec2 ba = b - a;\n float t = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);\n return length(pa - ba * t);\n }\n \n bool isIntersecting(vec2 point, vec2 p1, vec2 p2) {\n if(p1.y == p2.y) {\n return false;\n }\n \n if(p1.y > point.y && p2.y > point.y) {\n return false;\n }\n \n if(p1.y < point.y && p2.y < point.y) {\n return false;\n }\n \n float intersectionX = p1.x + (point.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y);\n return intersectionX > point.x;\n }\n\n vec2 fetchVertex(int vertexIndex) {\n int textureWidth = textureSize(tPositions, 0).x;\n int x = vertexIndex % textureWidth;\n int y = vertexIndex / textureWidth;\n return texelFetch(tPositions, ivec2(x, y), 0).rg;\n }\n \n float polyDistanceSDF(vec2 uv) {\n float minDist = 1e20;\n int intersections = 0;\n \n for(int i = 0; i < uPositionsCount; i++) {\n vec2 vertex1 = fetchVertex(i) / resolution.xy;\n vec2 vertex2 = fetchVertex((i + 1) % uPositionsCount) / resolution.xy;\n \n minDist = min(minDist, pointLineSegSDF(uv, vertex1, vertex2));\n \n if(isIntersecting(uv, vertex1, vertex2)) {\n intersections++;\n }\n }\n return float(intersections % 2 == 1 ? minDist : -minDist);\n // return float(intersections % 2 == 1 ? minDist : 1.5);\n }\n \n vec4 render(vec2 uv) {\n float dist = polyDistanceSDF(uv);\n return vec4(dist) * 0.5 + .5;\n }\n \n\n void main() {\n // A pseudo-random distribution for multi-sample\n const vec2 H2 = vec2(0.56984029, 0.75487766);\n // We do sub-pixel offsets relative to tile size, \n // because each tile is scaled to fill the entire local canvas\n vec2 px = 1.0 / resolution.xy;\n px *= 1.25;\n\n // We'll accumulate color across multiple samples\n const float samples = 4.0;\n vec4 sumColour = vec4(0.0);\n \n // Vary the random offset per pixel\n vec2 d0 = vec2(randomNonDet(vUv), randomNonDet(vUv + 1.0));\n\n for (float i = 0.0; i < samples; i++) {\n vec2 d = fract(i * H2 + d0) - 0.5;\n // localCoord in [0..1] in the local canvas\n vec2 sampleCoord = vUv + d * px;\n\n // Now map that to the large “full” coordinate space \n // subregion given by uTileOffset..uTileOffset+uTileSize\n vec2 screenCoord = uTileOffset + sampleCoord * uTileSize;\n\n // Next convert to [0..1] over the entire original geometry\n vec2 globalUV = screenCoord / resolution;\n\n vec4 sampleColor = render(globalUV);\n sumColour += sampleColor;\n }\n\n vec4 finalColor = clamp(sumColour / samples, 0.0, 1.0);\n outColor = finalColor;\n }\n `});let l=Ot(i.polygon);ln.uniforms.uPositionsCount.value=l.length;let a=function(t){const i=t.flat(),l=i.length/2,a=o(C,l),s=n(l/C),r=new Float32Array(a*s*2);for(let e=0;e<l;e++){const t=2*e;r[t]=i[t]||0,r[t+1]=i[t+1]||0}let c=new e.DataTexture(r,a,s,e.RGFormat,e.FloatType);return c.needsUpdate=!0,{texture:c,width:a,height:s}}(l);ln.uniforms.tPositions.value=a.texture,re(ln),Vt.material=ln,X.setRenderTarget(Ct.polyEdgeDistance.target),X.setClearColor(1,0),X.clear();let s=oe();var c;((e,i=5)=>{i/=U,X.setScissorTest(!0),X.setScissor(((e,i=5)=>{let l=i*U,a=o(...e.map((e=>e.x)))-l,s=r(...e.map((e=>e.x)))+l,c=o(...e.map((e=>e.y)))-l,d=r(...e.map((e=>e.y)))+l,u=s-a,h=d-c;return tn.set(kt(t(a),0,B),kt(t(Q-d),0,Q),n(o(u,B)),n(o(h,Q))).divideScalar(N).round()})(e,i))})((c=i.polygon.map((e=>new le(e.x,e.y))),c.map((e=>e.clone().multiplyScalar(U)))).map((e=>(e.x=t((e.x-s.xOff)*(B/s.width)),e.y=n((e.y-s.yOff)*(Q/s.height)),e))),n(10*U*(B/s.width))),Vt.render(),X.setScissorTest(!1)}!function(e){e[e.constructionLine=0]="constructionLine",e[e.detail=1]="detail",e[e.foreground=2]="foreground",e[e.background=3]="background",e[e.shadow=4]="shadow",e[e.walker=5]="walker",e[e.overlay=6]="overlay",e[e.overlayOutline=7]="overlayOutline"}(sn||(sn={})),function(e){e[e.regular=0]="regular",e[e.warped=1]="warped"}(on||(on={}));const cn=4095,dn=e=>.5*(1-l(e*g));let un;function hn(e){un=new Float32Array(4096);for(let e=0;e<4096;e++)un[e]=J.dec()}let mn=(e,n,i=0,l=5,a=0,s=1)=>Kt(function(e,n=0,i=0){un||hn(),e<0&&(e=-e),n<0&&(n=-n),i<0&&(i=-i);let l,a,s,o,r,c=t(e),d=t(n),u=t(i),h=e-c,m=n-d,p=i-u,g=0,b=.5;for(let e=0;e<3;e++){let e=c+(d<<4)+(u<<8);l=dn(h),a=dn(m),s=un[e&cn],s+=l*(un[e+1&cn]-s),o=un[e+16&cn],o+=l*(un[e+16+1&cn]-o),s+=a*(o-s),e+=256,o=un[e&cn],o+=l*(un[e+1&cn]-o),r=un[e+16&cn],r+=l*(un[e+16+1&cn]-r),o+=a*(r-o),s+=dn(p)*(o-s),g+=s*b,b*=.8,c<<=1,h*=2,d<<=1,m*=2,u<<=1,p*=2,h>=1&&(c++,h--),m>=1&&(d++,m--),p>=1&&(u++,p--)}return g}((e+100)/l,(n+100)/l,(i+100)/l),0,1,a,s);const pn=b;var gn;function bn(e,t,n=!1){if(0===t.length)return e;if(1===t.length)return t[0];let i,l=1/0,a=n?t.length:t.length-1;for(let n=0;n<a;n++){const a=t[n],s=t[(n+1)%t.length],o=xn(e,a,s);o<l&&(l=o,i=[a,s])}return i?function(e,t,n){const[i,l]=t,[a,s]=n,[o,r]=e,c=a-i,d=s-l,u=c*c+d*d;if(u<pn)return[i,l];let h=((o-i)*c+(r-l)*d)/u;return h<-1e-7?h=0:h>1+pn&&(h=1),[i+h*c,l+h*d]}(e,...i):e}function fn(e,t,n=!1){let i=1/0;const l=t.length,a=n?l:l-1;for(let n=0;n<a;n++){const a=Zn(e,t[n],n===l-1?t[0]:t[n+1]);if(a<pn)return 0;i=Math.min(i,a)}return Math.sqrt(i)}function xn(e,t,n){return d(Zn(e,t,n))}function Zn(e,t,n){const[i,l]=t,[a,s]=n,[o,r]=e,c=a-i,d=s-l,u=c*c+d*d;if(u<pn){const e=o-i,t=r-l;return e*e+t*t}let h=((o-i)*c+(r-l)*d)/u;h<-1e-7?h=0:h>1+pn&&(h=1);const m=o-(i+h*c),p=r-(l+h*d);return m*m+p*p}!function(e){e[e.intersecting=0]="intersecting",e[e.colinear=1]="colinear",e[e.parallel=2]="parallel"}(gn||(gn={}));let yn=0;class Gn{v1;v2;id=yn++;origin;angle;length;twin=null;nexthedge=null;prevhedge=null;face=null;constructor(e,t){this.v1=e,this.v2=t,this.id=yn++,this.origin=t,this.angle=function(e,t){let n=t.x-e.x,i=t.y-e.y;const l=d(n*n+i*i);return i>0?u(n/l):2*g-u(n/l)}(e,t),this.length=d(a(t.x-e.x,2)+a(t.y-e.y,2))}dispose(){this.origin=null,this.twin=null,this.nexthedge=null,this.prevhedge=null,this.face=null}getAABB(){let e=new nn;return e.expands([this.origin,this.twin.origin]),e}intersectWithLineSegment([e,t]){return function(e,t,n,i){const{x:l,y:a}=e,{x:s,y:o}=t,{x:r,y:c}=n,{x:d,y:u}=i,h=(u-c)*(s-l)-(d-r)*(o-a),m=(d-r)*(a-c)-(u-c)*(l-r),p=(s-l)*(a-c)-(o-a)*(l-r);if(Math.abs(h)<pn)return Math.abs(m)<pn&&Math.abs(p)<pn?{type:gn.colinear,point:null,ua:0,ub:0}:{type:gn.parallel,point:null,ua:0,ub:0};const g=m/h,b=p/h;return g>=-1e-7&&g<=1+pn&&b>=-1e-7&&b<=1+pn?{type:gn.intersecting,point:new zt(l+g*(s-l),a+g*(o-a)),ua:g,ub:b}:{type:null,point:null,ua:g,ub:b}}(this.origin,this.twin.origin,e,t)}}const Wn=b;class vn{tolerance;vertices=[];hedges=[];faces=[];vertexMap=new Map;constructor(e,t,n=Wn){this.tolerance=n,e&&t&&this.setDatas(e,t)}getVertexKey(e,t){const n=e/this.tolerance,i=t/this.tolerance;return`${Z(n,this.tolerance)},${Z(i,this.tolerance)}`}addVertex(e,t){const n=this.getVertexKey(e,t);let i=this.vertexMap.get(n);i||(i=[],this.vertexMap.set(n,i));for(const n of i)if(this.isClose(n.x,e)&&this.isClose(n.y,t))return n;const l=new zt(e,t);return this.vertices.push(l),i.push(l),l}deleteVertex(e){const t=this.getVertexKey(e.x,e.y),n=this.vertexMap.get(t);if(n){const i=n.indexOf(e);i>-1&&(n.splice(i,1),0===n.length&&this.vertexMap.delete(t))}const i=this.vertices.indexOf(e);i>-1&&this.vertices.splice(i,1),e.dispose()}findVertex(e,t){const n=this.getVertexKey(e,t),i=this.vertexMap.get(n);if(i)for(const n of i)if(this.isClose(n.x,e)&&this.isClose(n.y,t))return n;return null}verticesInPoly(e){let t=e.map((e=>(new zt).fromArray(e))),n=new nn;n.expands(t);let i=[],l=this.verticesInBB(n);for(let e of l)Tn(t,e)&&i.push(e);return i}verticesInBB(e){const t=[];for(let n of this.vertices)e.containsPoint(n)&&t.push(n);return t}setDatas(e,t){const{vertices:n,hedges:i,faces:l}=this;for(let t=0,n=e.length;t<n;t++){const n=e[t];this.addVertex(n[0],n[1])}for(let e=0,l=t.length;e<l;e++){const l=t[e],a=new Gn(n[l[0]],n[l[1]]),s=new Gn(n[l[1]],n[l[0]]);a.twin=s,s.twin=a,n[l[1]].hedgelist.push(a),n[l[0]].hedgelist.push(s),i.push(s),i.push(a)}for(let e=0,t=n.length;e<t;e++){const t=n[e];t.sortincident();const i=t.hedgelist.length;if(0!=i)if(i<2)t.hedgelist[0].prevhedge=t.hedgelist[0].twin,t.hedgelist[0].twin.nexthedge=t.hedgelist[0];else{for(let e=0;e<i-1;e++)t.hedgelist[e].twin.nexthedge=t.hedgelist[e+1],t.hedgelist[e+1].prevhedge=t.hedgelist[e].twin;t.hedgelist[i-1].twin.nexthedge=t.hedgelist[0],t.hedgelist[0].prevhedge=t.hedgelist[i-1].twin}}const a=i.slice(0);let s=i.length;for(;s>0;){let e=a.pop();if(s-=1,null==e.face){const t=new Rn(this);for(t.wedge=e,t.wedge.face=t;e.nexthedge!==t.wedge;)e=e.nexthedge,e.face=t;l.push(t)}}}internalFaces(){const e=[],t=this.faces;for(let n=0,i=t.length;n<i;n++){const i=t[n];i.internal&&e.push(i)}return e}externalFaces(){const e=[],t=this.faces;for(let n=0,i=t.length;n<i;n++){const i=t[n];i.external&&e.push(i)}return e}dispose(){const{vertices:e,hedges:t,faces:n}=this;for(let t=0,n=e.length;t<n;t++)e[t].dispose();for(let e=0,n=t.length;e<n;e++)t[e].dispose();for(let e=0,t=n.length;e<t;e++)n[e].dispose();e.length=0,t.length=0,n.length=0}isClose=(e,t)=>s(e-t)<this.tolerance;findHedge(e,t,n,i){const{isClose:l}=this,a=this.findVertex(e,t);if(a)for(const e of a.hedgelist){const t=e.twin.origin;if(l(t.x,n)&&l(t.y,i))return e}const s=this.findVertex(n,i);if(s)for(const n of s.hedgelist){const i=n.twin.origin;if(l(i.x,e)&&l(i.y,t))return n}return null}addEdge(e,t,n,i){const{vertices:l,hedges:a,faces:s}=this;let o=!1,r=!1,c=!1,d=this.findVertex(e,t);d||(d=this.addVertex(e,t),o=!0);let u=this.findVertex(n,i);u||(u=this.addVertex(n,i),r=!0);const h=new Gn(u,d);a.push(h),d.hedgelist.push(h),d.sortincident();const m=new Gn(d,u);if(a.push(m),u.hedgelist.push(m),u.sortincident(),h.twin=m,m.twin=h,o)h.
const{cellsWide:i,cellsHigh:l}=this;this.segmentMetaDataTexture={texture:new e.DataTexture(new Float32Array(i*l*2),i,l,e.RGFormat,e.FloatType),width:i,height:l},this.segmentMetaDataTexture.texture.needsUpdate=!0,this.segmentIndexTexture={texture:new Bt(n,n,e.RedFormat,e.FloatType,new Float32Array(n*n)),width:n,height:n},this.segmentIndexTexture.texture.setRenderer(X)}updatePolylines(e,t=!1){this.isClosed=t,this.polyLines=e,this.texturesInitialised||(this.initializeTextures(),this.texturesInitialised=!0),this.buildSegmentRecords(),this.buildSegmentCellIndex(),this.buildSegmentDataTextures()}buildSegmentRecords(){const e=this.polyLines.reduce(((e,t)=>{const n=this.isClosed?t.length:t.length-1;return n>0?e+n:e}),0);this._segmentRecords=new Float32Array(8*e);let t=0;this.polyLines.forEach(((e,n)=>{let i=0;for(let t=0;t<e.length-1;t++)i+=Qt(e[t],e[t+1]);this.isClosed&&e.length>1&&(i+=Qt(e[e.length-1],e[0]));let l=0;const a=this.isClosed?e.length:e.length-1;for(let s=0;s<a;s++){const a=e[s],o=e[(s+1)%e.length],r=Qt(a,o);this._segmentRecords[t++]=a[0],this._segmentRecords[t++]=a[1],this._segmentRecords[t++]=o[0],this._segmentRecords[t++]=o[1],this._segmentRecords[t++]=n,this._segmentRecords[t++]=l,this._segmentRecords[t++]=l+r,this._segmentRecords[t++]=i,l+=r}}))}buildSegmentCellIndex(){const e=this.cellsWide*this.cellsHigh;this._cellCounts=new Float32Array(e),this._cellOffsets=new Float32Array(e);const n=this._segmentRecords.length/8;let i=0;for(let e=0;e<n;e++){const e=this._segmentRecords[i+0],n=this._segmentRecords[i+1],l=this._segmentRecords[i+2],a=this._segmentRecords[i+3];i+=8;const o=t(e/this.cellSize),r=t(n/this.cellSize),c=t(l/this.cellSize),d=t(a/this.cellSize);let u=s(c-o),h=s(d-r),m=o,p=r,g=1+u+h;const b=c>o?1:-1,f=d>r?1:-1;let x=u-h;for(u*=2,h*=2;g--;){if(m>=0&&m<this.cellsWide&&p>=0&&p<this.cellsHigh){const e=p*this.cellsWide+m;this._cellCounts[e]++}if(x>0)m+=b,x-=h;else if(x<0)p+=f,x+=u;else{if(m+=b,p+=f,x+=u-h,g--,g<0)break;if(m>=0&&m<this.cellsWide&&p>=0&&p<this.cellsHigh){const e=p*this.cellsWide+m;this._cellCounts[e]++}}}}let l=0;for(let t=0;t<e;t++){const e=this._cellCounts[t];this._cellOffsets[t]=l,l+=e}this._indexData=new Float32Array(l),i=0;for(let e=0;e<n;e++){const n=this._segmentRecords[i+0],l=this._segmentRecords[i+1],a=this._segmentRecords[i+2],o=this._segmentRecords[i+3];i+=8;const r=t(n/this.cellSize),c=t(l/this.cellSize),d=t(a/this.cellSize),u=t(o/this.cellSize);let h=s(d-r),m=s(u-c),p=r,g=c,b=1+h+m;const f=d>r?1:-1,x=u>c?1:-1;let Z=h-m;for(h*=2,m*=2;b--;){if(p>=0&&p<this.cellsWide&&g>=0&&g<this.cellsHigh){const t=g*this.cellsWide+p,n=this._cellOffsets[t];this._indexData[n]=e,this._cellOffsets[t]=n+1}if(Z>0)p+=f,Z-=m;else if(Z<0)g+=x,Z+=h;else{if(p+=f,g+=x,Z+=h-m,b--,b<0)break;if(p>=0&&p<this.cellsWide&&g>=0&&g<this.cellsHigh){const t=g*this.cellsWide+p,n=this._cellOffsets[t];this._indexData[n]=e,this._cellOffsets[t]=n+1}}}}}buildSegmentDataTextures(){const e=this.segmentDataTexture.texture.texture.image.data,t=this.segmentDataTexture.width,n=this.segmentDataTexture.height,i=this._segmentRecords.length/8,l=o(2*i,t*n);let a=0,s=0;for(let t=0;t<i&&!(2*t+1>=l);t++){const n=2*t*4,i=4*(2*t+1),l=this._segmentRecords[a+0],o=this._segmentRecords[a+1],r=this._segmentRecords[a+2],c=this._segmentRecords[a+3],d=this._segmentRecords[a+4],u=this._segmentRecords[a+5],h=this._segmentRecords[a+6],m=this._segmentRecords[a+7];e[n+0]=l,e[n+1]=o,e[n+2]=r,e[n+3]=c,e[i+0]=d,e[i+1]=u,e[i+2]=h,e[i+3]=m,a+=8,s+=8}this.segmentDataTexture.texture.uploadSubData(s);const r=this.segmentMetaDataTexture.texture.image.data,c=this.segmentMetaDataTexture.width*this.segmentMetaDataTexture.height;for(let e=0;e<c;e++){const t=this._cellCounts[e],n=this._cellOffsets[e]-t,i=2*e;r[i+0]=n,r[i+1]=t}this.segmentMetaDataTexture.texture.needsUpdate=!0;const d=this.segmentIndexTexture.texture.texture.image.data,u=d.length,h=Math.min(this._indexData.length,u);d.set(this._indexData.subarray(0,h)),this.segmentIndexTexture.texture.uploadSubData(this._indexData.length)}getTextures(){return{segmentMetaDataTexture:this.segmentMetaDataTexture.texture,segmentDataTexture:this.segmentDataTexture.texture.texture,segmentIndexTexture:this.segmentIndexTexture.texture.texture}}reset(){this._segmentRecords=new Float32Array(0),this._cellCounts=new Float32Array(0),this._cellOffsets=new Float32Array(0),this._indexData=new Float32Array(0)}dispose(){this.segmentDataTexture.texture.texture.dispose(),this.segmentMetaDataTexture.texture.dispose(),this.segmentIndexTexture.texture.texture.dispose()}}let jt,At=new Jt(4),Et=new Jt(20),_t=0,qt=!1,$t=null;function en(t){if(0===t.lines.length)return;jt=jt||new e.ShaderMaterial({uniforms:{resolution:{value:new e.Vector2(B,Q)},uInternalResolution:{value:new e.Vector2(Y,P)},uFaceIndex:{value:0},tPaperTexture:{value:Ct.paperTexture.target.texture},uSegmentDataTex:{value:null},uSegmentIndexTex:{value:null},uSegmentMetaDataTex:{value:null},uBrightness:{value:1},...ce(),uAccumulationStrength:{value:1},uEdgeSharpness:{value:1},uTaperingFadeIn:{value:0},uTaperingFadeOut:{value:0},uTaperingScaleIn:{value:0},uTaperingScaleOut:{value:0},uFadeAtLineSegmentVertices:{value:new Float32Array([0,0,0,0])},uFadeAtLineSegmentDistance:{value:0},uFadeAtLineSegmentStrength:{value:1},uEnableFadeAtLineSegment:{value:!1},uIsShading:{value:!0},uDisableSaturationShift:{value:!1},uIsClosedPoly:{value:!1},tScreenBuffer:{value:Xt.getReadBuffer().texture},tPolyEdgeDistance:{value:Ct.polyEdgeDistance.target.texture},uNoiseOffset:{value:new le(0,0)},tWarpTex:{value:Ct.displacementMap.target.texture},uLineColor:{value:new e.Vector3(1,0,0)},uLineHardness:{value:1},uLineWeight:{value:1},uMaterialHardness:{value:1},uLighting:{value:{center:Ke.default,min:wt(Ke.default,Ke.min,Ke.influencesBrightnessMult),max:wt(Ke.default,Ke.max,Ke.influencesBrightnessMult)}},tPolyLineGrid:{value:{width:0,height:0,cellSize:0}}},vertexShader:ie,glslVersion:e.GLSL3,fragmentShader:`\n precision highp float;\n precision highp int;\n\n uniform highp sampler2D tWarpTex;\n uniform highp sampler2D tScreenBuffer;\n uniform highp sampler2D tPaperTexture;\n uniform highp sampler2D tPolyEdgeDistance;\n\n uniform highp sampler2D uSegmentDataTex;\n uniform highp sampler2D uSegmentMetaDataTex;\n uniform highp sampler2D uSegmentIndexTex;\n\n struct TPolyLineGrid {\n float width;\n float height;\n float cellSize;\n };\n\n uniform TPolyLineGrid tPolyLineGrid;\n\n\n struct Lighting {\n float center;\n float min;\n float max;\n };\n\n uniform Lighting uLighting;\n \n // uniform int uPositionsCount;\n uniform bool uIsClosedPoly;\n \n uniform vec2 resolution;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n\n uniform vec2 uInternalResolution;\n uniform vec2 uNoiseOffset;\n uniform bool uIsShading;\n // uniform bool uBulge;\n\n uniform float uTaperingFadeIn;\n uniform float uTaperingFadeOut;\n uniform float uTaperingScaleIn;\n uniform float uTaperingScaleOut;\n\n uniform bool uEnableFadeAtLineSegment;\n uniform vec2 uFadeAtLineSegmentVertices[2];\n uniform float uFadeAtLineSegmentDistance;\n uniform float uFadeAtLineSegmentStrength;\n\n uniform float uBrightness;\n uniform float uEdgeSharpness;\n uniform float uAccumulationStrength;\n uniform float uMaterialHardness;\n uniform vec3 uLineColor;\n uniform float uLineHardness;\n uniform float uLineWeight;\n uniform float uFaceIndex;\n uniform bool uDisableSaturationShift;\n\n // Max number of lines to consider for this fragment\n const int MAX_LINE_COUNT = 64;\n\n in vec2 vUv;\n out vec4 outColor;\n\n ${Dt}\n ${te}\n ${bt}\n ${gt}\n ${ee}\n ${ne}\n ${Ut}\n\n //-----------------------------------------\n \n\n vec2 pointLineSDFInfinite(vec2 p, vec2 a, vec2 b) {\n vec2 pa = p - a;\n vec2 ba = b - a;\n float t = dot(pa, ba) / dot(ba, ba);\n float dist = length(pa - ba * t);\n return vec2(dist, t);\n }\n\n // 1) Helper to fetch offset+count from segmentMetaDataTexture\n vec2 getSegmentMeta(ivec2 cellCoords) {\n // each pixel stores (offset, count)\n return texelFetch(uSegmentMetaDataTex, cellCoords, 0).rg;\n }\n \n ivec2 getCellCounts() {\n return ivec2(\n int(tPolyLineGrid.width / tPolyLineGrid.cellSize),\n int(tPolyLineGrid.height / tPolyLineGrid.cellSize)\n );\n }\n\n ivec2 getGridCoords(vec2 uv) {\n ivec2 cellCount = getCellCounts();\n \n // Flip Y so top-left is (0,0)\n float flippedY = 1.0 - uv.y;\n \n int x = int(floor(uv.x * float(cellCount.x)));\n int y = int(floor(flippedY * float(cellCount.y)));\n \n return ivec2(x, y);\n }\n\n\n // 2) Helper to read the segment ID from segmentIndexTexture\n int getSegmentID(int globalIndex) {\n ivec2 size = textureSize(uSegmentIndexTex, 0);\n // clamp the fetch\n globalIndex = clamp(globalIndex, 0, size.x*size.y - 1);\n int x = globalIndex % size.x;\n int y = globalIndex / size.x;\n return int(texelFetch(uSegmentIndexTex, ivec2(x,y), 0).r);\n }\n\n // 3) Helper to read the 2 texels for the given segment\n struct SegmentData {\n vec2 a; // x1,y1\n vec2 b; // x2,y2\n float lineIndex; \n float segStart;\n float segEnd;\n float totalLen;\n };\n\n SegmentData getSegmentData(int segmentID) {\n SegmentData seg;\n // float scaleFactor = (1. / uInternalResolution.x);\n\n // each segment uses 2 RGBA texels = 8 floats\n // texel1 => (x1, y1, x2, y2)\n // texel2 => (lineIndex, segStartLen, segEndLen, totalLineLen)\n int texelIndex1 = segmentID * 2;\n int texelIndex2 = segmentID * 2 + 1;\n\n ivec2 size = textureSize(uSegmentDataTex, 0);\n\n // clamp fetch\n int maxTexels = size.x * size.y;\n texelIndex1 = clamp(texelIndex1, 0, maxTexels-1);\n texelIndex2 = clamp(texelIndex2, 0, maxTexels-1);\n\n // decode coordinates\n int x1 = texelIndex1 % size.x;\n int y1 = texelIndex1 / size.x;\n int x2 = texelIndex2 % size.x;\n int y2 = texelIndex2 / size.x;\n\n vec4 d1 = texelFetch(uSegmentDataTex, ivec2(x1,y1), 0);\n vec4 d2 = texelFetch(uSegmentDataTex, ivec2(x2,y2), 0);\n\n seg.a = d1.xy / uInternalResolution;\n seg.b = d1.zw / uInternalResolution;\n\n seg.a = vec2(seg.a.x, 1.0 - seg.a.y);\n seg.b = vec2(seg.b.x, 1.0 - seg.b.y);\n\n seg.lineIndex = d2.x;\n seg.segEnd = d2.z / uInternalResolution.x;\n seg.segStart = d2.y / uInternalResolution.x;\n seg.totalLen = d2.w / uInternalResolution.x; // scale to pixel space\n\n return seg;\n }\n\n vec2 pointLineSegSDF(vec2 p, vec2 a, vec2 b) {\n vec2 pa = p - a;\n vec2 ba = b - a;\n float t = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);\n float dist = length(pa - ba * t);\n return vec2(dist, t);\n }\n\n\n // This struct can store the final line-based result\n struct LineDistanceResult {\n float dist; // nearest distance for this line\n float lineT; // fraction along the entire line\n float lineIndex; // which line\n };\n \n const ivec2 offsets[9] = ivec2[](\n ivec2(-1,-1), ivec2(0,-1), ivec2(1,-1),\n ivec2(-1, 0), ivec2(0, 0), ivec2(1, 0),\n ivec2(-1, 1), ivec2(0, 1), ivec2(1, 1)\n );\n\n // This function will find the closest lines to the given uv coordinate\n void lineDistanceSDFSegments(\n vec2 uv,\n float distanceThreshold,\n out LineDistanceResult linesWithin[MAX_LINE_COUNT],\n out int linesCount\n ){\n linesCount = 0;\n \n // We'll keep track of each line's nearest distance in arrays,\n float lineDistances[MAX_LINE_COUNT];\n float lineTvalues[MAX_LINE_COUNT];\n int lineIDs[MAX_LINE_COUNT];\n \n // Initialize with defaults\n for (int i = 0; i < MAX_LINE_COUNT; i++) {\n lineDistances[i] = 1e20;\n lineTvalues[i] = 0.0;\n lineIDs[i] = -1;\n }\n \n // Figure out the base cell coords from uv\n ivec2 baseCellCoords = getGridCoords(uv);\n ivec2 cellCount = getCellCounts();\n \n // For each of the 9 offsets, gather segments from neighboring cells.\n for (int c = 0; c < 9; c++) {\n ivec2 cellCoords = baseCellCoords + offsets[c];\n \n // clamp cellCoords to grid boundaries\n if(cellCoords.x < 0 || cellCoords.x >= cellCount.x) continue;\n if(cellCoords.y < 0 || cellCoords.y >= cellCount.y) continue;\n \n // 1) fetch offset+count from the segmentMetaDataTexture\n vec2 meta = getSegmentMeta(cellCoords);\n int segOffset = int(meta.r);\n int segCount = int(meta.g);\n \n // 2) read each segment\n // same logic as before, but unify them into lineDistances\n for (int i = 0; i < 1024; i++) {\n if (i >= segCount) break;\n \n int segID = getSegmentID(segOffset + i);\n SegmentData seg = getSegmentData(segID);\n \n // compute distance to this segment\n vec2 dt = pointLineSegSDF(uv, seg.a, seg.b);\n float dist = dt.x;\n float localT = dt.y;\n \n float segLen = seg.segEnd - seg.segStart;\n float absoluteDistanceAlongLine = seg.segStart + localT * segLen;\n float fraction = (seg.totalLen > 0.0) ? (absoluteDistanceAlongLine / seg.totalLen) : 0.0;\n \n // if within threshold\n if (dist <= distanceThreshold) {\n int lineID = int(seg.lineIndex);\n \n // check if we already have that line\n int foundIndex = -1;\n for (int j = 0; j < MAX_LINE_COUNT; j++) {\n if (lineIDs[j] == lineID) {\n foundIndex = j;\n break;\n }\n }\n \n if (foundIndex == -1) {\n // new line\n for (int j = 0; j < MAX_LINE_COUNT; j++) {\n if (lineIDs[j] < 0) {\n lineIDs[j] = lineID;\n lineDistances[j] = dist;\n lineTvalues[j] = fraction;\n break;\n }\n }\n } else {\n // line already exists => keep closer distance\n if (dist < lineDistances[foundIndex]) {\n lineDistances[foundIndex] = dist;\n lineTvalues[foundIndex] = fraction;\n }\n }\n }\n }\n }\n \n // Final pass: gather valid lines into linesWithin\n int validCount = 0;\n for (int i = 0; i < MAX_LINE_COUNT; i++) {\n if (lineIDs[i] >= 0) {\n linesWithin[validCount].dist = lineDistances[i];\n linesWithin[validCount].lineT = lineTvalues[i];\n linesWithin[validCount].lineIndex = float(lineIDs[i]);\n validCount++;\n if (validCount >= MAX_LINE_COUNT) break;\n }\n }\n\n // Now 'validCount' lines are in linesWithin[0..validCount-1].\n // Sort them by dist ascending.\n for (int i = 0; i < MAX_LINE_COUNT - 1; i++) {\n // If 'i' >= validCount - 1, break\n if (i >= validCount - 1) break;\n\n for (int j = i + 1; j < MAX_LINE_COUNT; j++) {\n // If 'j' >= validCount, break\n if (j >= validCount) break;\n\n if (linesWithin[j].dist < linesWithin[i].dist) {\n // Swap\n LineDistanceResult tmp = linesWithin[i];\n linesWithin[i] = linesWithin[j];\n linesWithin[j] = tmp;\n }\n }\n }\n \n linesCount = validCount;\n }\n\n\n float easeOut(float t, float strength) {\n return 1.0 - pow(1.0 - t, strength);\n }\n\n // UV - Scene UV\n // screenSpaceUV - screen space UV\n // MSAA Offset - offset for the current sample\n vec4 render(vec2 uv, vec2 screenSpaceUV, vec2 msaaOffset, vec3 frameBuffer) {\n\n float scaleFactor = (1. / uInternalResolution.x);\n vec2 tileScaleFactor = resolution / uTileSize;\n \n \n vec2 uvWarp = lookupWarpSample(screenSpaceUV + msaaOffset).xy;\n vec2 ssLookupWarp = uvWarp * tileScaleFactor;\n\n uv += uvWarp;\n\n float sdf = (texture(tPolyEdgeDistance, screenSpaceUV + ssLookupWarp + msaaOffset).r - 0.5) * 2.0;\n\n // float flippedY = 1.0 - uv.y;\n vec3 color = uLineColor;\n\n // float shift = 0.02;\n // color.x += shift;\n // color.y -= shift * 0.4;\n\n float rampStart = 0.7; // Where ramping begins\n float rampEnd = 1.0; // Where ramping hits its max\n float lowValue = 0.015; // AccumulationIncrement below threshold\n float highValue = 0.06; // AccumulationIncrement if color.x approaches rampEnd\n\n // ‘t’ goes from 0.0 to 1.0 as color.x moves from rampStart to rampEnd\n float t = clamp((color.x - rampStart) / (rampEnd - rampStart), 0.0, 1.0);\n // float accumulationIncrement = mix(lowValue, highValue, t);\n \n float accumulationClampMax = 0.15;\n float accumulationIncrement = mix(lowValue, highValue, smoothstep(rampStart, rampEnd, color.x));\n vec2 accumulationClamp = vec2(accumulationClampMax, accumulationClampMax * 0.4);\n float chromaIncrement = (accumulationIncrement * 0.4) * uAccumulationStrength; // adjust for subtlety\n float lightnessIncrement = (-accumulationIncrement) * uAccumulationStrength; // adjust for subtlety\n float alphaIncrement = uIsShading ? .95 : 1.5; // adjust for subtlety\n \n // float brightnessRemap = remap(uBrightness, 0., 1., 0., 0.95);\n if(uIsShading) {\n float colorShift = uBrightness - uLighting.center;\n // Only scale down if colorShift is above 0\n float shiftFactor = (colorShift > 0. && color.x > 0.6) ? (1.0 - clamp(color.x / 0.82, 0., 1.)) : 1.0;\n float newMult = ((colorShift * 1.5 * shiftFactor) + 1.0);\n \n color.x *= newMult;\n \n // color.y = remap(\n // clamp(colorShift, 0., 1.),\n // 0.,\n // uLighting.max - uLighting.center,\n // color.y,\n // color.y - .02\n // );\n \n \n color.x -= 0.0;\n color.y -= 0.025;\n \n color.x = clamp(color.x, 0., 0.82);\n }\n // float satRemap = remap(uBrightness, 0.8, 1.2, 0.04, -0.02);\n // color.y -= (colorShift * 0.4);\n // }\n\n\n\n color.x = clamp(color.x, 0., .81);\n color.y = clamp(color.y, 0., .4);\n \n \n // float satShift = 1.0 - remap(uBrightness, 0.9, 1., 1.005, 1.);\n // color.y = clamp(color.y - satShift, 0., 1.);\n \n vec3 originalColor = color;\n // color.y = clamp(color.y - colourShift * 0.1, 0., 1.);\n // color.x *= uBrightness;\n // float satRemapAtHighBrightness = clamp(remap(uBrightness, 1., 1.2, 1., 0.8), 0.8, 1.);\n // color.y *= satRemapAtHighBrightness;\n\n \n\n\n \n\n // SHAPE SDF\n \n float alpha = 0.0;\n \n float segmentDistanceAlphaMult = 1.;\n\n if(uEnableFadeAtLineSegment) {\n vec2 fadeStartVert = uFadeAtLineSegmentVertices[0] / resolution.xy;\n vec2 fadeEndVert = uFadeAtLineSegmentVertices[1] / resolution.xy;\n float fadeDistance = uFadeAtLineSegmentDistance * scaleFactor;\n float fadeAlpha = pointLineSDFInfinite(uv, fadeStartVert, fadeEndVert).x;\n float fadeLerp = smoothstep(0., fadeDistance, fadeAlpha);\n fadeLerp = clamp(remap(fadeLerp, 0., 1., 1. - uFadeAtLineSegmentStrength, 1.), 0., 1.);\n segmentDistanceAlphaMult = fadeLerp;\n }\n\n float edgeSharpness = remap(uEdgeSharpness, 0., 1., -0.1, -0.0015);\n\n segmentDistanceAlphaMult *= smoothstep(edgeSharpness, -0.0, sdf);\n\n if(segmentDistanceAlphaMult <= 0.) {\n return vec4(frameBuffer, 1.);\n }\n\n\n float accumulationValue = 0.0;\n\n // Loop Setup\n // int linesInRangeCount;\n // vec3 linesInRange[MAX_LINE_COUNT];\n float lineSampleDistanceMax = scaleFactor * (uLineWeight * 2.);\n // lineDistanceSDF(uv + uvOffset, lineSampleDistanceMax, linesInRange, linesInRangeCount);\n\n LineDistanceResult linesWithin[MAX_LINE_COUNT];\n int linesCount;\n lineDistanceSDFSegments(uv, lineSampleDistanceMax, linesWithin, linesCount);\n\n // for(int i = MAX_LINE_COUNT; i >= 0; i--) {\n for(int i = 0; i < linesCount; i++) {\n vec3 localColor = color;\n // if(i >= linesInRangeCount) continue;\n // vec3 lineDistanceProps = linesInRange[i];\n\n float lineSDF = linesWithin[i].dist;\n float lineT = linesWithin[i].lineT;\n float lineIndex = linesWithin[i].lineIndex;\n\n float currentLineNoiseOffset = float(lineIndex) * 10.;\n\n // Line Tapering and Fade\n float fadeLineCap = 1.;\n float scaleLineCap = 1.;\n \n if(uTaperingFadeIn > 0. || uTaperingFadeOut > 0.) {\n float fadeWarp = abs(fbm(uv + uNoiseOffset + currentLineNoiseOffset, 1, 10., 0.9)) * 0.05;\n \n if(uTaperingFadeIn > 0.) {\n fadeLineCap = easeOut(smoothstep(0.0, (uTaperingFadeIn / 2.) - fadeWarp, lineT), 10.);\n }\n\n if(uTaperingFadeOut > 0.) {\n fadeLineCap *= easeOut(smoothstep(1., 1. - (uTaperingFadeOut / 2.) - fadeWarp, lineT), 10.);\n }\n }\n\n if(uTaperingScaleIn > 0. || uTaperingScaleOut > 0.) {\n float scaleWarp = abs(fbm(uv + uNoiseOffset + currentLineNoiseOffset, 1, 10., 0.9)) * 0.05;\n if(uTaperingScaleIn > 0.) {\n scaleLineCap = easeOut(smoothstep(0.0, (uTaperingScaleIn / 2.), lineT + scaleWarp), 1.);\n }\n\n if(uTaperingScaleOut > 0.) {\n scaleLineCap *= easeOut(smoothstep(1., 1. - (uTaperingScaleOut / 2.), lineT + scaleWarp), 1.);\n }\n }\n\n float lineHardness = uLineHardness * fadeLineCap;\n // float lineHardness = uLineHardness;\n\n // float lineWeight = uLineWeight + (fbm(uNoiseOffset + (lineIndex / 2.), 1, 10., 0.9) / 4.);\n float lineWeight = uLineWeight;\n \n float lineDistanceMax = (scaleFactor * lineWeight) * scaleLineCap;\n float lineWeightWobble = fbm(uv + currentLineNoiseOffset,
1,max:.2},out:{enabledChance:10,min:.1,max:.2}}},insetChance:0,styleChances:[[1,"outline"]],colorMap:[[[1,ye.line]]],spatialOverride:{[Ge.dominant]:{fillChance:100}}})},ut=new e.OrthographicCamera(-1,1,1,-1,0,1);class ht extends e.BufferGeometry{constructor(){super(),this.setAttribute("position",new e.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new e.Float32BufferAttribute([0,2,0,0,2,0],2))}}const mt=new ht;class pt{_mesh;constructor(t){this._mesh=new e.Mesh(mt,t)}dispose(){this._mesh.geometry.dispose()}render(e=X){e.render(this._mesh,ut)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}let gt="\n vec2 lookupWarpSample(const vec2 uv) {\n\n // vec2 offset = vec2(0.2);\n return ((texture(tWarpTex, uv).xy - 0.5) * 2.);\n }\n",bt="\n float remap(float t, float a1, float b1, float a2, float b2) {\n return a2 + (b2 - a2) * ((t - a1) / (b1 - a1));\n }\n";function ft(){return new e.ShaderMaterial({uniforms:{resolution:{value:new e.Vector2(B,Q)},noiseOffset:{value:new e.Vector2(We[0],We[1])},...ce(),wave:{value:{...De}},uWarpEnabled:{value:!1},grid:{value:{...ze}}},depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:ie,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform vec2 resolution;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n uniform vec2 noiseOffset;\n uniform bool uWarpEnabled;\n\n struct Wave {\n bool warpX;\n bool warpY;\n\n bool offAxisY;\n bool offAxisX;\n\n float warpXMult;\n float warpYMult;\n\n float displacementStrength;\n \n bool noiseMapEnabled;\n };\n \n uniform Wave wave;\n\n struct Grid {\n float countX;\n float countY;\n float marginX;\n float marginY;\n float w;\n float h;\n float scale;\n };\n\n uniform Grid grid;\n\n varying vec2 vUv;\n out vec4 outColor;\n\n // const float scale = 10.;\n\n #include <packing>\n\n ${ee}\n ${bt}\n ${te}\n \n // Third compomnent is the intersection\n // const float PI2 = acos(-1.);\n \n float noiseLookup(vec2 uv, float freq) {\n float influence = fbm(uv + noiseOffset, 2, freq + 0.2, 0.8);\n return smoothstep(0., 1., abs(fbm(uv - influence, 2, freq, 0.5)));\n }\n\n// vec2 warpTextureSampleUv(const vec2 uv) {\n// // Center of the drop\n// vec2 center = vec2(0.5, 0.5);\n// // Spacing between each ripple (distance in UV space)\n// float ringSpacing = 0.1;\n\n// // Thickness of each ripple peak\n// float ringThickness = 0.01;\n\n// // Overall ripple strength\n// float amplitude = 0.05;\n\n// // Distance from UV to the center\n// float dist = distance(uv, center);\n\n// // We compute the ripple shape by creating rings around the center at multiples of ringSpacing\n// // - sector is how far dist is from the last multiple of ringSpacing\n// // - ringDist is how far we are from the center of that ring\n// float sector = mod(dist, ringSpacing);\n// float ringDist = abs(sector - (ringSpacing * 0.5));\n\n// // Create a peak shape at the ring center\n// // wave is 1.0 near the ring center and 0.0 outside\n// float wave = 1.0 - smoothstep(0.0, ringThickness, ringDist);\n\n// // Convert wave to displacement strength\n// float offsetStrength = wave * amplitude;\n\n// // Direction outward from the center\n// vec2 direction = normalize(uv - center);\n\n// return direction * offsetStrength;\n// }\n \n vec2 warpTextureSampleUv(const vec2 uv) {\n\n float PI = acos(-1.);\n float gridSize = grid.w / 1000.;\n float strength = gridSize * .2;\n float edgeFalloff = 1.;\n\n // strength *= 50.; \n\n vec2 warpSpread = vec2(1.) * .1;\n\n float aspectRatio = resolution.x / resolution.y;\n\n vec2 offsetUV = uv + (noiseOffset * 2.);\n\n offsetUV.x *= 1.;\n offsetUV.y *= 1.2;\n\n // float noiseMask = snoise2D(offsetUV / .2) ;\n // float noiseMask2 = snoise2D(offsetUV / .18);\n // float noiseWarped = snoise2D(vec2((offsetUV.x + 1.) / .1 * noiseMask2, uv.y / 1.2 * noiseMask));\n // float noiseWarped2 = snoise2D(vec2((offsetUV.x + .8) / .25 * noiseMask2, uv.y / 1.2 * noiseMask));\n \n float freq = 10.1;\n float warpedDivisor = .5;\n\n float noiseMaskMask = smoothstep(0.95, 1., fbm(offsetUV, 1, freq * 3., 0.5));\n float noiseMask = (fbm(offsetUV, 1, freq + 0.001, 0.5) + 0.01) - fbm(offsetUV, 1, freq, 0.5);\n noiseMask *= 50.;\n noiseMask *= clamp(abs(noiseMaskMask), .5, 1e6);\n // float direction = smoothstep(-1., 1., fbm(offsetUV, 2, freq * .1, 0.5));\n\n // float noiseY = fbm(offsetUV * .5, 2, freq, 0.1);\n // float noiseX = fbm(offsetUV * .5, 3, freq/2., 0.2);\n\n float epsilon = 0.01;\n\n\n\n\n float noiseWarpedCenter = noiseLookup(offsetUV , warpedDivisor);\n float noiseWarpedY = noiseLookup(offsetUV + vec2(epsilon, 0.), warpedDivisor);\n float noiseWarpedX = noiseLookup(offsetUV + vec2(0., epsilon), warpedDivisor);\n\n // float dFdx = (noiseWarpedX - noiseWarpedCenter) / epsilon;\n // float dFdy = (noiseWarpedY - noiseWarpedCenter) / epsilon;\n\n // vec2 gradient = vec2(dFdx, dFdy);\n // gradient = vec2(-gradient.y, gradient.x);\n \n // gradient = normalize(gradient);\n\n // float projection = dot(uv, gradient);\n // float wave = sin(projection * .1); \n // gradient = vec2(-gradient.y, gradient.x);\n // float noiseWarped2 = fbm(offsetUV + vec2(freq/2.) * vec2(1.) * warpedUV, 1, freq * .5, 0.1);\n \n\n // float nNoise = snoise2D(offsetUV * .5);\n // float result = ((noiseWarped * 1.f) * (noiseWarped2 * 1.f)) * noiseMask;\n // float noiseSwirl = noiseMask;\n // float result = noiseWarped1 * 2. * PI - (PI * .5);\n\n vec2 divergence = vec2(0.);\n // divergence += vec2(cos(result), sin(result));\n // divergence += (result * strength) * noiseMask;\n divergence += noiseWarpedCenter * strength * noiseMask;\n // divergence *= screenEdgeDist(uv, edgeFalloff);\n \n // float simpleWarp = fbm(offsetUV, 6, 600.6, .9);\n\n // divergence += simpleWarp * .0003;\n\n return vec2(divergence); \n }\n\n\n const float PI = acos(-1.);\n\n const float waveWarpDivisor = 1.;\n // const int waveNoiseMapEnabled = 0;\n\n \n\n vec2 waveUv(vec2 uv) {\n\n vec2 margins = vec2(grid.marginX / resolution.x, grid.marginY / resolution.y);\n float width = grid.w / resolution.x;\n\n float lookupRemap = noiseOffset.x;\n \n // float influence = clamp(snoise2D((uv + lookupRemap)), 0.f, 1.f);\n float influence = grid.countX * wave.displacementStrength;\n \n // if(wave.noiseMapEnabled == 1)\n // influence = .9f + (influence / 10.f);\n \n float strength = (width / (waveWarpDivisor * PI) - 2.f) * (width / grid.countX) * influence;\n float sinX = sin(wave.warpXMult * PI * ((uv.x / width) + margins.x) - PI /2.) * strength;\n float sinY = sin(wave.warpYMult * PI * ((uv.y / width) + margins.y) - PI /2.) * strength;\n \n vec2 result = vec2(0.);\n \n if(wave.warpX)\n result.x += sinX;\n \n if(wave.warpY)\n result.y += sinY;\n \n if(wave.offAxisY)\n result.y += sinX;\n \n if(wave.offAxisX)\n result.x += sinY;\n \n // result.y = sin(waveWarpXMult * PI * ((uv.x + margins.y) / width)) * strength;\n // result.x = sin(waveWarpYMult * PI * ((uv.x + margins.x) / width)) * strength;\n\n return result;\n }\n\n // vec2 calculatePerspectiveOffset(vec2 uv) {\n // // Store the original UV coordinates\n // vec2 originalUv = uv;\n \n // // Define perspective depth factors\n // float perspectiveStrength = .0; // Controls the overall perspective effect\n // float tiltX = -0.3; // Controls the leftward skew\n // float tiltY = 0.2; // Controls the backward tilt\n \n // // Shift UVs to the center of the texture\n // uv -= 0.5;\n \n // // Apply perspective transformation\n // float depth = 1.0 - perspectiveStrength * (tiltX * uv.x + tiltY * uv.y);\n // uv /= depth;\n \n // // Calculate the min and max bounds of the transformed UVs\n // vec2 minBounds = vec2(-0.5) / (1.0 - perspectiveStrength * vec2(-tiltX, -tiltY));\n // vec2 maxBounds = vec2(0.5) / (1.0 - perspectiveStrength * vec2(tiltX, tiltY));\n \n // // Normalize the UV coordinates to the [0, 1] range\n // uv = (uv - minBounds) / (maxBounds - minBounds);\n \n // // Apply scaling to fill the scene\n // uv = uv * (maxBounds - minBounds);\n \n // // Calculate the offset by subtracting the original UV from the transformed and normalized UV\n // vec2 offset = uv - originalUv;\n \n // return offset;\n // }\n\n vec4 render(vec2 uv, vec2 screenSpaceUV, vec2 msaaOffset) {\n vec2 offset = uWarpEnabled ? warpTextureSampleUv(uv) : vec2(0.);\n vec2 warpedUv = waveUv(uv);\n offset += warpedUv;\n // offset += calculatePerspectiveOffset(uv);\n return(vec4(offset * 0.5 + 0.5, 0., 1.0));\n }\n\n float randomNonDet(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n }\n\n void main() {\n const vec2 H2 = vec2(0.5698402909980532f, 0.7548776662466927f);\n vec2 px = 1.f / resolution;\n px *= 1.25;\n vec2 uv = vUv;\n\n \n // Check if this fragment is within the SDF\n // vec2 uvOffset = lookupWarpSample(uv).xy;\n // float texCheck = (texture(tPolyEdgeDistance, uv + uvOffset).r - 0.5) * 2.0;\n // if(texCheck < -0.1) {\n // discard;\n // }\n\n\n const float samples = 6.f;\n \n vec4 sumColour;\n vec2 d0 = vec2(randomNonDet(uv), randomNonDet(uv + 1.f));\n\n \n for(float i = 0.f; i < samples; i++) {\n vec2 d = (fract(i * H2 + d0) - .5f);\n\n vec2 localCoord = vUv + d * px; /* changed */\n vec2 screenCoord = uTileOffset + localCoord * uTileSize; /* changed */\n vec2 globalUV = screenCoord / resolution; /* changed */\n\n // vec4 sampleColor = render(globalUV, vUv, d * px);\n vec4 sampleColor = render(globalUV, vUv, d * px);\n // sampleColor.rgb *= sampleColor.a; // Convert to premultiplied alpha\n sumColour += sampleColor;\n }\n \n vec4 averageColor = clamp(sumColour / samples, 0., 1.);\n \n outColor = averageColor;\n }\n `})}let xt="\n\n vec3 sCurve(vec3 c, float contrast, float midpoint) {\n // c in [0, 1], midpoint could be 0.5 or 0.18\n // contrast is how steep the curve is\n // A simple logistic-based S-curve\n return 1.0 / (1.2 + exp(-(c - midpoint) * contrast)) ;\n }\n\n vec4 adjustContrast(vec4 color, float factor) {\n float midpoint = 0.3; // 0.18\n // Factor is effectively the steepness of the slope\n vec3 curved = sCurve(color.rgb, factor, midpoint);\n return vec4(curved, color.a);\n }\n",Zt="\n const float l2p3alpha = 1.055;\n const float l2p3beta = 0.00304;\n const float l2p3gamma = 2.4;\n const float l2p3delta = 0.055;\n\n vec3 linear2P3(vec3 linearRgb) {\n vec3 a = l2p3alpha * pow(linearRgb, vec3(1.0 / l2p3gamma)) - l2p3delta;\n vec3 b = linearRgb / 12.92;\n vec3 mask = step(vec3(l2p3beta), linearRgb);\n\n return mix(b, a, mask);\n }\n";function yt(){return new e.ShaderMaterial({uniforms:{tTex:{value:null}},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:ie,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform highp sampler2D tTex;\n in vec2 vUv;\n out vec4 outColor;\n\n ${Zt}\n ${xt}\n\n // vec4 desaturateRGBA(vec4 color, float factor) {\n // float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));\n // vec3 desaturatedColor = mix(color.rgb, vec3(gray), factor);\n // return vec4(desaturatedColor, color.a);\n // }\n\n void main() {\n vec4 color = vec4(texture2D(tTex, vUv).rgb, 1.);\n // vec4 contrasty = adjustContrast(color, 12.);\n // color = mix(color, contrasty, 0.05);\n // color = adjustBrightness(color, 1.001);\n // color *= 0.95;\n // color = desaturateRGBA(color, 0.001);\n outColor = vec4(linear2P3(vec3(color)), 1.);\n }\n `})}const Gt=yt(),Wt=new e.ShaderMaterial({uniforms:{tTex:{value:null},uChannel:{value:0}},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:ie,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform highp sampler2D tTex;\n uniform int uChannel;\n\n in vec2 vUv;\n out vec4 outColor;\n\n // ${Zt}\n // ${xt}\n\n void main() {\n vec4 color = vec4(texture2D(tTex, vUv).rgba);\n if(uChannel == -1) {\n outColor = color;\n return;\n }\n float channelColor = color[ int(uChannel) ];\n outColor = vec4(vec3(channelColor), 1.0);\n }\n `}),vt=new pt(Gt);function Lt(e,t){vt.material=Gt,Gt.uniforms.tTex.value=e,X.setRenderTarget(t||null),vt.render(X)}class St{width;height;bufferIdx=0;textureCount=1;renderBuffers=[];renderBufferProps;maskEnabled=!1;constructor(t=B,n=Q,i){this.width=t,this.height=n;let l=w?e.LinearFilter:e.NearestFilter;this.renderBufferProps={anisotropy:V,minFilter:l,magFilter:l,stencilBuffer:!1,premultipliedAlpha:!0,alpha:!0,depthBuffer:!1,colorSpace:e.LinearDisplayP3ColorSpace,generateMipmaps:!1,format:e.RGBAFormat,type:e.FloatType,internalFormat:"RGBA32F",...i},this.setupFrameBuffers(),this.clearFrameBuffers(),X.autoClear=!1}setupFrameBuffers(){for(let t=0;t<2;t++)this.renderBuffers.push(new e.WebGLRenderTarget(this.width,this.height,this.renderBufferProps))}clearFrameBuffers(e=!0,t=!0,n=!0){X.setClearColor(16777215,0);const{stencil:i,color:l,depth:a}=X.state.buffers;this.renderBuffers.forEach((s=>{X.setRenderTarget(s),e&&l.setLocked(!1),t&&a.setLocked(!1),n&&i.setLocked(!1),X.clear(e,t,n)}))}enableMask(e=1){this.maskEnabled=!0;const{stencil:t}=X.state.buffers,n=X.getContext();t.setLocked(!1),t.setTest(!0),t.setFunc(n.EQUAL,e,4294967295),t.setOp(n.KEEP,n.KEEP,n.KEEP),t.setLocked(!0)}disableMask(){this.maskEnabled=!1;const{stencil:e}=X.state.buffers;e.setLocked(!1),e.setTest(!1),e.setLocked(!0)}renderMaterialAsMask(e,t=1){if(!this.renderBufferProps.stencilBuffer)throw Error("Stencil buffer not enabled in render buffer properties");const n=X.getContext(),{color:i,depth:l,stencil:a}=X.state.buffers;l.setMask(!1),l.setLocked(!0),i.setMask(!1),i.setLocked(!0),a.setLocked(!1),a.setTest(!0),a.setOp(n.KEEP,n.KEEP,n.REPLACE),a.setFunc(n.ALWAYS,t,4294967295),a.setClear(0),a.setLocked(!0),vt.material=e,X.setRenderTarget(this.getReadBuffer()),vt.render(),X.setRenderTarget(this.getWriteBuffer()),vt.render(),i.setLocked(!1),i.setMask(!0),l.setLocked(!1),l.setMask(!0)}getWriteBuffer(){return this.renderBuffers[(this.bufferIdx+1)%2]}getReadBuffer(){return this.renderBuffers[this.bufferIdx%2]}copyBufferChannelToScreen(e=0,t=this.getReadBuffer()){let n=this.maskEnabled;n&&this.disableMask(),X.setRenderTarget(null),vt.material=Wt,Wt.uniforms.tTex.value=t.texture,Wt.uniforms.uChannel.value=e,vt.render(),n&&this.enableMask()}copyBufferToBuffer(e){let t=this.maskEnabled;t&&this.disableMask(),X.setRenderTarget(e),X.copyFramebufferToTexture(this.getReadBuffer().texture),t&&this.enableMask()}copyAndSwapBuffers(){this.copyBufferToBuffer(this.getWriteBuffer()),this.bufferIdx++}copyBufferToScreen(e=this.getReadBuffer()){let t=this.maskEnabled;t&&this.disableMask(),Lt(e.texture),t&&this.enableMask()}}let Xt,Ct={},Vt=new pt(null);const wt=(e,t,n)=>(t-e)*n+e,Kt=(e,t,n,i,l)=>wt(i,l,((e,t,n)=>(n-e)/(t-e))(t,n,e));function Rt(e,t,n=b){if(0===t)return e;const i=n*Math.sign(e);return Math.round((e+i)/t)*t}function kt(e,t,n){return o(r(e,t),n)}const Tt=(e,t,n,i,l)=>kt(Kt(e,t,n,i,l),i,l);let Mt=0;class zt{x;y;id=Mt++;hedgelist=[];constructor(e=0,t=0){this.x=e,this.y=t}sortincident(){this.hedgelist&&this.hedgelist.sort(Yt)}subtract(e){return new zt(this.x-e.x,this.y-e.y)}addPolar(e,t){return new zt(this.x+t*l(e),this.y+t*i(e))}normalize(e=b){const t=d(this.x*this.x+this.y*this.y);return t<e?new zt(0,0):new zt(this.x/t,this.y/t)}multiply(e){return new zt(this.x*e,this.y*e)}add(e){return new zt(this.x+e.x,this.y+e.y)}toArray(){return[this.x,this.y]}fromArray(e){return this.x=e[0],this.y=e[1],this}distanceTo(e){return d(a(e.x-this.x,2)+a(e.y-this.y,2))}angleTo(e){return Math.atan2(e.y-this.y,e.x-this.x)}lerp(e,t){return new zt(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t)}translate(e,t){this.x+=t*l(e),this.y+=t*i(e)}clone(){return new zt(this.x,this.y)}isEqualTo(e,t=b){const n=e.x-this.x,i=e.y-this.y;return n*n+i*i<=t*t}isCloseTo(e,t=b){return this.distanceTo(e)<t}dispose(){this.hedgelist.length=0}}function Yt(e,t){return t.angle-e.angle}function Pt(e,t=1){if(0===t)return e;let n=ze.w/t,i=ze.h/t,l=Rt(e.x,n),a=Rt(e.y,i);return new zt(l,a)}function It(e,t=1){return function(e){return new zt(e.x+ze.marginX,e.y+ze.marginY)}(Pt(new zt(e.x,e.y),t))}function Ht(e){return[e[0],e[1],e[2]*Math.PI/180]}function Ft(e){return(e%360+360)%360}function Nt(e){return[kt(e[0],0,1),kt(e[1],0,1),Ft(e[2])]}let Ut="\n float getPaperTexture( const vec2 screenPosition ) {\n return texture(tPaperTexture, screenPosition).x;\n }\n\n vec3 calculateNormals(vec2 uv, float offsetScale, float scale) {\n // float offsetScale = .5;\n vec2 offset = vec2(offsetScale, offsetScale);\n // float scale = 1.;\n\n float left = getPaperTexture(vec2(uv.x + offset.x, uv.y));\n float right = getPaperTexture(vec2(uv.x - offset.x, uv.y));\n float up = getPaperTexture(vec2(uv.x, uv.y + offset.y));\n float down = getPaperTexture(vec2(uv.x, uv.y - offset.y));\n\n vec3 dx = vec3(1.0, 0.0, (left - right) * scale);\n vec3 dy = vec3(0.0, 1.0, (up - down) * scale);\n\n vec3 normal = normalize(cross(dy, dx));\n\n return -normal;\n }\n\n vec3 calculateDiffuse(vec3 normal, vec3 lightDir, vec3 lightColor) {\n // Calculate the diffuse component\n float diff = max(dot(normal, lightDir), 0.0);\n float angleAttenuation = pow(diff, 1.);\n return angleAttenuation * lightColor;\n }\n",Dt="\n // Partially adapted from - https://github.com/yum-food/HLSL_OKLAB/blob/main/oklab.cginc\n const mat3 m1i = mat3(vec3(1.22700842, -0.5576564, 0.28111404), vec3(-0.04047048, 1.11219073, -0.07157255), vec3(-0.07643651, -0.42138367, 1.58625265));\n const mat3 m2i = mat3(vec3(1.00003964, 0.39638005, 0.21589049), vec3(0.99998945, -0.10553958, -0.06374665), vec3(0.99999105, -0.08946276, -1.291495));\n // XYZ -> linear RGB (p3) from colorjs.io - https://github.com/color-js/color.js/blob/main/src/spaces/p3-linear.js\n const mat3 xyz_to_rgb_p3 = mat3(vec3(2.493496911941425, -0.9313836179191239, -0.40271078445071684), vec3(-0.8294889695615747, 1.7626640603183463, 0.023624685841943577), vec3(0.03584583024378447, -0.07617238926804182, 0.9568845240076872));\n\n // Functions for matrix multiplication and power, as GLSL doesn't have built-in matrix multiplication for 3x3 matrices\n vec3 mat3_mul_vec3(mat3 m, vec3 v) {\n return vec3(dot(m[0], v), dot(m[1], v), dot(m[2], v));\n }\n\n vec3 vec3_pow(vec3 v, float p) {\n return vec3(pow(v.x, p), pow(v.y, p), pow(v.z, p));\n }\n\n // Converts OKLCH color to XYZ color space\n vec3 OKLCHtoXYZ(vec3 c) {\n // Convert OKLCH to OKLAB\n float a = c.y * cos(c.z);\n float b = c.y * sin(c.z);\n vec3 oklab = vec3(c.x, a, b);\n\n // Convert OKLAB to XYZ\n oklab = mat3_mul_vec3(m2i, oklab);\n oklab = vec3_pow(oklab, 3.0);\n return mat3_mul_vec3(m1i, oklab);\n }\n\n // Converts XYZ color to linear RGB color space (p3)\n vec3 XYZtoP3LRGB(vec3 c) {\n return mat3_mul_vec3(xyz_to_rgb_p3, c);\n }\n\n // Main function to convert OKLCH to Linear RGB\n vec3 OKLCHtoP3LRGB(vec3 oklchColor) {\n vec3 xyzColor = OKLCHtoXYZ(oklchColor);\n vec3 lrgbColor = XYZtoP3LRGB(xyzColor);\n return lrgbColor;\n }\n";const Ot=e=>e.map((({x:e,y:t})=>[e*U,Q-t*U]));class Bt{width;height;format;type;channels;texture;gl;_glFormat;_glType;_glTexture;renderer;constructor(t,n,i,l,a){if(this.width=t,this.height=n,this.format=i,this.type=l,i===e.RGBAFormat)this.channels=4;else if(i===e.RGFormat)this.channels=2;else{if(i!==e.RedFormat)throw Error("Unsupported format for PartialDataTexture.");this.channels=1}const s=t*n*this.channels,o=a||new Float32Array(s);if(o.length!==s)throw Error("Initial data length does not match texture dimensions.");this.texture=new e.DataTexture(o,t,n,i,l),this.texture.needsUpdate=!0,this.gl=null,this._glFormat=null,this._glType=null,this._glTexture=null}setRenderer(t){this.renderer=t;const n=t.getContext();if(this.gl=n,this.format===e.RGBAFormat)this._glFormat=n.RGBA;else if(this.format===e.RGFormat)this._glFormat=n.RG;else{if(this.format!==e.RedFormat)throw Error("Unsupported format for PartialDataTexture.");this._glFormat=n.RED}if(this.type!==e.FloatType)throw Error("PartialDataTexture currently only supports Float32 data type.");this._glType=n.FLOAT,t.initTexture(this.texture);const i=t.properties.get(this.texture);this._glTexture=i.__webglTexture}uploadSubData(e){if(!this.gl||!this._glTexture)throw Error("Renderer not set or texture not initialized. Call setRenderer() before updating.");const t=this.gl,n=Math.floor(e/this.channels);if(n<=0)return;const i=this.width*this.height,l=Math.min(n,i),a=Math.floor(l/this.width),s=l%this.width,o=this.texture.image.data,r=t.getParameter(t.TEXTURE_BINDING_2D);if(t.bindTexture(t.TEXTURE_2D,this._glTexture),a>0){const e=o.subarray(0,a*this.width*this.channels);t.texSubImage2D(t.TEXTURE_2D,0,0,0,this.width,a,this._glFormat,this._glType,e)}if(s>0){const e=a*this.width*this.channels,n=o.subarray(e,e+s*this.channels);t.texSubImage2D(t.TEXTURE_2D,0,0,a,s,1,this._glFormat,this._glType,n)}t.bindTexture(t.TEXTURE_2D,r)}}function Qt(e,t){const n=t[0]-e[0],i=t[1]-e[1];return d(n*n+i*i)}class Jt{polyLines=[];isClosed;cellSize;cellsWide;cellsHigh;_segmentRecords;_cellCounts;_cellOffsets;_indexData;segmentDataTexture;segmentIndexTexture;segmentMetaDataTexture;texturesInitialised=!1;constructor(e=1){this.cellSize=e}initializeTextures(){const n=o(C,1024);this.segmentDataTexture={texture:new Bt(n,n,e.RGBAFormat,e.FloatType,new Float32Array(n*n*4)),width:n,height:n},this.segmentDataTexture.texture.setRenderer(X),this.cellsWide=t(Y/this.cellSize),this.cellsHigh=t(P/this.cellSize);
tdDev:1},VVariance:{min:0,max:10,threshold:2,mean:1,stdDev:1},rects:{insetRectEnabled:!0,spiralRectsEnabled:!0},circles:{count:0,minRadius:2,maxRadius:30},wobble:{enabled:!1,count:1e10,layers:2,multiLayers:1,minLength:5,gridDivisions:1,warpFreq:{min:600,max:800},offsetMultiplier:1},perspectiveBox:{enabled:!0,threshold:2,mean:1,stdDev:1,count:1,firstFull:!0}},Fe=Xe,Ne=Ce,Ue={layers:1,renderLightChance:0,ignoreLighting:!0,renderAccentChance:0,insetMult:2,maxWidth:80,spread:4,widthRange:.3,maxDivergence:2,tension:{min:.9,max:1.2},maxPointUse:1,pointsToConsider:30,maxLinePoints:30},De={warpX:!0,warpY:!1,offAxisX:!0,offAxisY:!1,warpXMult:.05,warpYMult:.05,displacementStrength:.05,noiseMapEnabled:!0},Oe={maxAccents:4,mutation:"none",dominantIsAccentChance:50,useNoiseLookup:!0,samplesForComplimentary:3,samplesForPaletteOffset:2,addBGContrast:!1,freqMultiplier:10,usePolyIDColorOffset:!0,singleAccent:!1,darksOnly:!1},Be={cropToMargin:!0,cropBGShapesAtMargin:!0,cropToMarginFillDark:!1,margin:30},Qe={count:100,lineRemoveStrength:.1,polyOverfitting:.75,noiseOverfittingSpread:0,noiseOverfitFreq:100,excludeWeakSplits:!1,longestSplitOnlyChance:50,noiseFieldCategoryInfluence:1e3},Je=Ve,je=100,Ae=.1,Ee=0,_e="";const qe=(e,t)=>{ze.scale=J.int(e,t);const n=Y/ze.scale,i=P/ze.scale;ze.countX=Math.ceil(n),ze.countY=Math.ceil(i);const l=ze.countX*ze.scale,a=ze.countY*ze.scale;ze.marginX=(Y-l)/2,ze.marginY=(P-a)/2,ze.w=ze.scale,ze.h=ze.scale};var $e,et,tt,nt,it;function lt(e,t){return function(e){return void 0!==e[t]?e[t]:e.default}}!function(e){e.xs="xsmall",e.sm="small",e.md="medium",e.lg="large",e.xl="xlarge"}($e||($e={})),function(e){e.none="none",e.sparse="sparse",e.light="light",e.dense="dense",e.filled="filled",e.detailOnly="detailOnly"}(et||(et={})),function(e){e.light="light",e.medium="medium",e.heavy="heavy"}(tt||(tt={})),function(e){e.color="color",e.dark="dark",e.light="light"}(nt||(nt={})),function(e){e.objects="objects",e.curves="curves",e.angles="angles",e.grid="grid",e.mesh="mesh",e.all="all",e.random="random"}(it||(it={}));const at=()=>({[it.objects]:{splits:{[be.horizontal]:1,[be.vertical]:2,[be.perspective]:0,[be.circle]:2,[be.wobbles]:3,[be.objects]:15,[be.curves]:5,[be.rects]:1,[be.borderRect]:1},meta:{forceSplit:{forceInsertCurvesChance:J.choice([10,0]),forceInsertObjectsChance:J.choice([30,0])}}},[it.grid]:{splits:{[be.horizontal]:2,[be.vertical]:4,[be.perspective]:0,[be.circle]:4,[be.wobbles]:1,[be.objects]:10,[be.curves]:0,[be.rects]:0,[be.borderRect]:0},meta:{forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:0}}},[it.curves]:{splits:{[be.horizontal]:1,[be.vertical]:2,[be.perspective]:0,[be.circle]:10,[be.wobbles]:10,[be.objects]:J.choice([10,1]),[be.curves]:10,[be.rects]:0,[be.borderRect]:1},meta:{usedLineReplayChance:10,forceSplit:{forceInsertCurvesChance:J.choice([0,20]),forceInsertObjectsChance:J.choice([0,20])}}},[it.angles]:{splits:{[be.horizontal]:2,[be.vertical]:3,[be.perspective]:3,[be.circle]:0,[be.wobbles]:0,[be.objects]:3,[be.curves]:2,[be.rects]:0,[be.borderRect]:1},meta:{forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:0}}},[it.mesh]:{splits:{[be.horizontal]:1,[be.vertical]:1,[be.perspective]:1,[be.circle]:1,[be.wobbles]:0,[be.objects]:1,[be.curves]:0,[be.rects]:0,[be.borderRect]:0},meta:{objectProps:{forceYUp:!0},forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:50}}},[it.all]:{splits:{[be.horizontal]:2,[be.vertical]:2,[be.perspective]:2,[be.circle]:2,[be.wobbles]:2,[be.objects]:4,[be.curves]:2,[be.rects]:1,[be.borderRect]:2},meta:{forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:0}}}});let st,ot;const rt=()=>{let e=at();_e="Pencils",qe(20,20),ot=J.weightedChoice([15,$e.sm],[15,$e.md],[10,$e.lg]);let n=lt(0,ot);st=J.weightedChoice([n({[$e.sm]:1,default:1}),et.light],[n({[$e.sm]:0,default:1}),et.dense],[n({[$e.sm]:2,[$e.md]:2,default:1}),et.filled],[1,et.detailOnly]);let i=lt(0,st),l=lt(0,J.weightedChoice([n({[$e.sm]:i({[et.none]:0,[et.sparse]:0,default:0}),default:0}),tt.light],[1,tt.medium],[1,tt.heavy])),a=J.weightedChoice([n({[$e.sm]:i({[et.filled]:5,default:1}),default:1}),it.objects],[n({[$e.sm]:0,default:2}),it.curves],[n({[$e.sm]:0,default:1}),it.angles],[n({[$e.sm]:0,default:1}),it.grid]),s=e[a];Fe=ge(Fe,s.splits),Te=ge(Te,s.meta.forceSplit),Qe=ge(Qe,{noiseOverfittingSpread:n({[$e.sm]:J.num(0,1),default:J.num(0,1)}),noiseOverfitFreq:1200,polyOverfitting:J.choice([1,J.num(.5,1.5)]),longestSplitOnlyChance:n({[$e.sm]:J.choice([0,50,100]),default:J.choice([50,100])}),noiseFieldCategoryInfluence:J.choice([1,4])}),Ee=n({default:s.meta?.usedLineReplayChance||4}),je=t(n({[$e.sm]:i({[et.filled]:J.int(190,180),[et.none]:J.int(190,230),[et.detailOnly]:J.int(200,230),default:J.int(190,230)}),[$e.md]:J.int(250,350),[$e.lg]:J.int(350,800)})),Ae=i({[et.filled]:n({[$e.lg]:J.num(0,.3),[$e.md]:J.num(0,.2),[$e.sm]:J.num(0,.01),default:J.num(0,.1)}),default:n({[$e.sm]:J.num(0,.01),[$e.md]:J.num(0,.1),[$e.lg]:J.num(0,.3)})});let o=J.weightedChoice([1,!1],[1,!0]);Oe={...Oe,mutation:J.weightedChoice([0,"offsetUp"],[0,"offsetDown"],[3,"none"]),addBGContrast:i({[et.detailOnly]:!1,default:!0}),useNoiseLookup:!0,samplesForComplimentary:J.int(1,3),samplesForPaletteOffset:1,singleAccent:!1,freqMultiplier:n({default:o?J.num(300,600):J.num(300,400)}),usePolyIDColorOffset:o,maxAccents:n({default:J.weightedChoice([1,4],[1,6],[2,100])}),darksOnly:!1};let r=lt(0,J.weightedChoice([10,nt.color],[n({[$e.lg]:1,default:0}),nt.dark],[n({[$e.lg]:1,default:0}),nt.light]));Je={...Je,size:n({[$e.lg]:{min:4,max:5},[$e.md]:{min:5,max:6},[$e.sm]:{min:6,max:8}})},Ne=[be.horizontal,be.vertical],Ke={...Ke,default:1,clamp:.05,min:.6,max:1,influencesPressureMult:0,influencesBrightnessMult:1,influencesMinDistanceMult:.2},st!=et.filled||ot!=$e.lg&&ot!=$e.md||!J.bool(10)||(Ke={...Ke,default:1,clamp:.05,min:.5,max:.55,influencesPressureMult:0,influencesBrightnessMult:1,influencesMinDistanceMult:0});let c=J.bool(40);Ue={...Ue,ignoreLighting:J.bool(50),maxWidth:.75*n({[$e.sm]:J.int(40,50),[$e.md]:J.int(40,50),default:J.num(35,45)}),renderLightChance:J.weightedChoice([1,0],[1,J.int(0,10)]),maxPointUse:1,maxDivergence:2,pointsToConsider:10};let d=J.num(.75,1.5);ke=ge({...ke,layers:2,layerScaleMult:2.5,zDepthMaxMult:J.int(1,2),cropTo:n({default:J.choice([xe.scene,xe.border,xe.none])}),forceYUp:a==it.grid||J.bool(30),clampVertsToGrid:n({[$e.sm]:!1,default:!1}),...n({[$e.sm]:{maxDist:200*d,minDist:130*d},[$e.md]:{maxDist:150*d,minDist:100*d},[$e.lg]:J.weightedChoice([5,{maxDist:130*d,minDist:80*d}])}),bnFreq:J.num(10,1e3),fieldFreq:n({[$e.lg]:J.int(4e3,1e4),[$e.sm]:J.int(1e3,2e3),default:J.choice([J.int(1e3,4e3),J.int(4e3,1e4)])}),clampRotationTo:J.weightedChoice([1,22.5],[4,1],[1,11.25]),minSizeMult:1,maxSizeMult:n({default:.75}),maxSides:5,minSides:3,perspective:2e4},s.meta?.objectProps||{});let u={edgeSharpness:{min:.8,max:1},fillChance:100,insetChance:J.choice([8,5,0]),wobbleFreq:{min:40,max:80},wobbleAmplitude:{min:1,max:3},accumulationStrength:{min:1,max:1},materialHardness:i({[et.light]:{min:.9,max:.97},default:{min:.93,max:.99}}),linePressure:i({default:{min:.65,max:.7}}),minDistanceMult:n({[$e.lg]:{min:.7,max:.8},[$e.sm]:{min:.7,max:.8},default:{min:.7,max:.8}}),lineTapering:{fade:{in:{enabledChance:0,min:0,max:0},out:{enabledChance:0,min:0,max:0}},scale:{in:{enabledChance:0,min:0,max:0},out:{enabledChance:0,min:0,max:0}}},layerCountChances:l({[tt.light]:[[1,2]],[tt.medium]:[[1,4]],[tt.heavy]:[[1,6]]}),lineWeight:n({[$e.sm]:{min:1.5,max:1.6},[$e.md]:{min:1.4,max:1.5},default:{min:1.4,max:1.5}}),layerOverride:[{fadeAtLineSegmentChance:0,lineTapering:{fade:{out:{enabledChance:n({[$e.sm]:50,[$e.md]:10,[$e.lg]:0,default:0}),min:1,max:2}}},wobbleAmplitude:{min:5,max:6},wobbleFreq:{min:50,max:70},styleChances:[[1,"bnnoise"]],colorMap:"none"===Oe.mutation&&J.bool(30)?[[[100,J.choice([ye.offsetDown,ye.offset,ye.offsetUp])],[J.weightedChoice([2,0],[1,J.int(0,15)]),ye.color]]]:[[[100,ye.color],[J.weightedChoice([2,0],[1,J.int(0,15)]),ye.offsetUp]]]},{fadeAtLineSegmentChance:0,styleChances:[[1,"edgefill"]],colorMap:[[[1,ye.previous]]],wobbleAmplitude:{min:5,max:6},wobbleFreq:{min:40,max:100}},J.weightedChoice([0,{scribbleChance:100,scribbleStrength:{min:.2,max:.4},colorMap:[[[1,ye.offset]]],styleChances:[[1,"bnnoise"]],linePressure:{min:.9,max:.95},lineTapering:{scale:{out:{enabledChance:100,min:0,max:.2},in:{enabledChance:100,min:0,max:.2}}}}],[2,{scribbleChance:0,colorMap:[[[1,ye.offsetUp]]],wobbleAmplitude:{min:1,max:1},styleChances:[[1,"bnnoise"]],fadeAtLineSegmentChance:100,fadeAtLineSegmentDistanceMult:{min:.6,max:1},fadeAtLineSegmentStrengthMult:{min:1,max:1.1},linePressure:{min:1.2,max:1.25},materialHardness:{min:.9,max:.95},lineTapering:{fade:{in:{enabledChance:0,min:1,max:1},out:{enabledChance:100,min:3,max:8}}}}]),{styleChances:[[1,"directional"],[1,"bnnoise"]],colorMap:[[[1,ye.previous]]],wobbleAmplitude:{min:4,max:8},wobbleFreq:{min:40,max:60}},{colorMap:[[[1,ye.brightnessBasedShadowOrHighlight]]],fadeAtLineSegmentChance:100,fadeAtLineSegmentDistanceMult:{min:1.5,max:1.5},fadeAtLineSegmentStrengthMult:{min:1,max:1},materialHardness:{min:.7,max:.8},linePressure:{min:1.3,max:1.4},minDistanceMult:{min:.5,max:.6},wobbleAmplitude:{min:1,max:2},wobbleFreq:{min:50,max:100},styleChances:[[1,"bnnoise"],[0,"directional"],[0,"wobbles"],[0,"bluenoise"],[0,"edgefill"]],lineTapering:{fade:{in:{enabledChance:0,min:.1,max:.2},out:{enabledChance:100,min:2,max:4}}}},{styleChances:[[1,"bnnoise"]],colorMap:[[[1,ye.previous]]],wobbleAmplitude:{min:5,max:6},wobbleFreq:{min:80,max:200}}]};Pe=ge(Pe,{ignoreLightingChance:0,wobbleAmplitude:{min:2,max:2},wobbleFreq:{min:35,max:45},materialHardness:i({default:{min:.8,max:.85}}),linePressure:{min:.7,max:.9},minDistanceMult:i({[et.sparse]:{min:2.7,max:3.8},default:{min:1.4,max:1.5}}),spatialOverride:{[Ge.notInCurveOrObject]:{fillChance:100,colorMap:[[[1,ye.offset]]],colorPalette:"fg",ignoreLightingChance:100,insetChance:100,scribbleChance:0,insetDistance:{min:10,max:20},minDistanceMult:{min:2.5,max:5},linePressure:{min:.8,max:.9},lineWeight:{min:.8,max:1.6},fadeAtLineSegmentChance:0},[Ge.nonDominant]:i({[et.light]:ge(u,{colorPalette:"bg",fillChance:100,layerCountChances:[[1,2]],minDistanceMult:{min:1,max:1.3},lineWeight:{min:1.1,max:1.2},layerOverride:[ge(u.layerOverride[0],{colorPalette:"bg",colorMap:[[[1,ye.color]]],linePressure:{min:.15,max:.2},styleChances:[[1,"bnnoise"]]}),ge(u.layerOverride[1],{linePressure:{min:.5,max:.6},colorMap:[[[1,ye.previous]]],styleChances:[[1,"edgefill"]]})]}),[et.detailOnly]:{fillChance:0},default:u}),[Ge.overlay]:{lineWeight:{min:1.6,max:1.7},materialHardness:{min:.6,max:.75},minDistanceMult:{min:1,max:1},layerCountChances:[[1,2]],linePressure:{min:.99,max:.99},layerOverride:{0:{styleChances:[[1,"bnnoise"]],colorMap:[[[1,ye.lightest]]],fadeAtLineSegmentChance:0,scribbleChance:0},1:{fadeAtLineSegmentChance:0,styleChances:[[1,"edgefill"]],colorMap:[[[1,ye.brightnessBasedShadowOrHighlight]]],wobbleAmplitude:{min:6,max:8},wobbleFreq:{min:60,max:90}}}},[i({default:n({[$e.lg]:c?Ge.inCurveOrObject:Ge.dominant,[$e.md]:c?Ge.inCurveOrObject:Ge.dominant,default:Ge.dominant})})]:ge(u,{fillChance:100,insetDistance:{min:6,max:12}})}}),Ye=ge(Ye,{insetChance:50,detailMinScaleDivisor:10,insetDistance:{min:4,max:12},wobbleAmplitude:{min:2,max:4},wobbleFreq:{min:55,max:200},fadeAtLineSegmentChance:0,fillChance:0,layerCountChances:[[1,2],[1,1]],colorMap:i({[et.detailOnly]:[[[1,ye.color]],[[1,ye.previous]]],default:[[[1,ye.line]]]}),lineTapering:{fade:{out:{enabledChance:0,min:1,max:2}},scale:{in:{enabledChance:100,min:.01,max:.2},out:{enabledChance:100,min:.01,max:.2}}},linePressure:{min:.9,max:.95},materialHardness:{min:.9,max:.95},lineWeight:{min:.6,max:1.5},minDistanceMult:{min:3,max:5},spatialOverride:{[Ge.nonDominant]:{scribbleChance:0,lineWeight:{min:1,max:1.5},colorMap:[J.choice([[[100,ye.line]]])],colorPalette:J.choice(["bg","fg"]),insetChance:100,insetDistance:{min:7,max:12},fillChance:i({[et.detailOnly]:100,default:0}),linePressure:i({[et.light]:{min:.5,max:.6},default:{min:.5,max:.6}}),minDistanceMult:n({[$e.sm]:{min:5,max:7},default:{min:4,max:6}}),styleChances:J.weightedChoice([1,[[1,"directional"]]],[1,[[1,"bnnoise"]]],[1,[[2,"bnnoise"],[2,"directional"],[0,"wobbles"],[0,"bluenoise"]]],[1,[[1,"bluenoise"]]])},[Ge.dominant]:{ignoreLightingChance:100,fillChance:n({[$e.sm]:i({[et.detailOnly]:J.int(30,40),default:J.int(40,50)}),default:J.weightedChoice([1,30],[3,J.num(40,70)])}),layerCountChances:[[2,2],[1,1]],linePressure:{min:.7,max:.9},styleChances:[[5,"bnnoise"],[5,"directional"],[1,"wobbles"],[4,"bluenoise"]],materialHardness:{min:.8,max:.9},colorMap:[[[100,ye.randomAccent]],[[100,ye.previous]]],minDistanceMult:{min:6,max:15},lineWeight:n({[$e.lg]:{min:1,max:1.25},default:{min:1,max:1.25}})}}}),Re=ge(Re,{count:10,warpChance:100,length:{min:100,max:200},thickness:{min:1,max:1.5}});let h=n({[$e.sm]:J.int(95,100),[$e.lg]:i({[et.light]:J.weightedChoice([2,J.int(55,70)],[1,J.int(65,90)]),[et.detailOnly]:J.weightedChoice([2,J.int(55,70)],[1,J.int(65,90)]),default:J.int(80,90)}),default:J.int(70,100)}),m=J.num(.75,1.25);Me=ge(Me,{meshInsetMuliplier:0,lineFilter:h<80?"none":J.weightedChoice([1,"curves"],[1,"straight"],[3,"none"]),meshDensity:h,skipLongest:n({[$e.lg]:J.int(0,10),default:0}),percentage:n({[$e.lg]:i({[et.filled]:J.weightedChoice([1,J.int(0,1)],[1,J.int(50,80)]),default:h>70?J.weightedChoice([1,J.int(40,70)],[1,J.int(0,0)]):J.int(40,70)}),[$e.md]:i({[et.filled]:J.weightedChoice([1,J.int(0,0)],[1,J.int(50,80)]),default:h>70?J.weightedChoice([1,J.int(40,70)],[1,J.int(0,5)]):J.int(40,70)}),[$e.sm]:i({[et.filled]:J.weightedChoice([1,J.int(0,0)],[1,J.int(50,80)]),default:J.int(40,70)}),default:J.int(50,80)}),cropToDominantShape:!1,colors:r({[nt.color]:!0,default:!1}),backgroundColor:r({[nt.light]:!(st!==et.filled&&h<80),default:!1}),materialHardness:{min:.9,max:.96},linePressure:{min:.9,max:.95},thickness:n({[$e.lg]:{min:2.85*m,max:3*m},[$e.md]:{min:2.25*m,max:3.65*m},default:{min:2.25*m,max:4.25*m}})});let p=J.weightedChoice([1,J.int(0,1)],[1,J.int(2,10)]),g=n({[$e.sm]:J.int(4,4),[$e.md]:J.int(4,4),[$e.lg]:J.int(4,4),default:2});He=ge(He,{margin:g*ze.scale,HVariance:{min:-p,max:p,threshold:1,mean:1,stdDev:1},VVariance:{min:-p,max:p,threshold:1,mean:1,stdDev:1},circles:{count:5,minRadius:5,maxRadius:18},wobble:{enabled:!0,count:1e10,minLength:2,layers:4,multiLayers:1,gridDivisions:1,warpFreq:{min:800,max:2e3},offsetMultiplier:.6},perspectiveBox:{enabled:!0,threshold:4,mean:2,stdDev:8,firstFull:!0,count:1}}),Be={...Be,cropToMargin:!1,margin:6*ze.scale}},ct=()=>{_e="Sparse",qe(20,20);let e=lt(0,J.weightedChoice([1,$e.sm],[1,$e.md],[1,$e.lg]));J.weightedChoice([1,tt.heavy]);let t=J.weightedChoice([e({[$e.sm]:1,default:1}),it.objects],[e({[$e.sm]:0,default:2}),it.curves],[e({[$e.sm]:0,default:1}),it.angles],[e({[$e.sm]:0,default:1}),it.grid]),n=at()[t];n.splits[be.circle]=3,Fe=ge(Fe,n.splits),Te=ge(Te,n.meta.forceSplit),Qe=ge(Qe,{noiseOverfittingSpread:e({[$e.sm]:J.num(0,1),default:J.num(0,1)}),noiseOverfitFreq:1200,polyOverfitting:J.num(.5,1.5)}),Ee=e({default:n.meta?.usedLineReplayChance||4}),je=J.int(200,800),Ae=.1;let i=J.weightedChoice([1,!1],[1,!0]);Oe={...Oe,mutation:J.weightedChoice([0,"offsetUp"],[0,"offsetDown"],[3,"none"]),useNoiseLookup:!0,samplesForComplimentary:J.int(1,2),samplesForPaletteOffset:1,singleAccent:!1,freqMultiplier:e({default:i?J.num(600,1e3):J.num(100,200)}),usePolyIDColorOffset:i,maxAccents:e({default:J.weightedChoice([0,4],[1,6],[2,100])}),darksOnly:!1};let l=lt(0,J.weightedChoice([e({[$e.lg]:1,default:1}),nt.dark]));Je={...Je,count:0},Ne=[be.horizontal,be.vertical],Ke={...Ke,default:1,clamp:.05,min:.9,max:1.1,influencesBrightnessMult:1,influencesMinDistanceMult:0,influencesPressureMult:0},Ue={...Ue,maxWidth:.75*e({[$e.sm]:J.int(40,50),[$e.md]:J.int(40,50),default:J.num(35,45)}),renderLightChance:100,maxPointUse:J.int(1,2),maxDivergence:J.int(2,4),pointsToConsider:10};let a=J.num(.75,1.5);ke=ge({...ke,layers:2,layerScaleMult:2.5,zDepthMaxMult:J.int(1,2),cropTo:e({default:J.choice([xe.scene,xe.border,xe.none])}),forceYUp:!0,clampVertsToGrid:e({[$e.sm]:!1,default:!1}),...e({[$e.sm]:{maxDist:200*a,minDist:130*a},[$e.md]:{maxDist:150*a,minDist:100*a},[$e.lg]:J.weightedChoice([5,{maxDist:150*a,minDist:100*a}])}),bnFreq:J.num(10,1e3),fieldFreq:e({[$e.lg]:J.int(4e3,1e4),[$e.sm]:J.int(1e3,2e3),default:J.choice([J.int(1e3,4e3),J.int(4e3,1e4)])}),clampRotationTo:J.weightedChoice([1,22.5],[4,1],[1,11.25]),minSizeMult:1,maxSizeMult:e({default:.75}),maxSides:5,minSides:3,perspective:2e4},n.meta?.objectProps||{}),Ie=ge(Ie,{});let s={edgeSharpness:{min:0,max:0},fillChance:90,insetChance:10,wobbleFreq:{min:30,max:60},wobbleAmplitude:{min:3,max:8},accumulationStrength:{min:10,max:10},materialHardness:{min:.4,max:.45},linePressure:{min:1.3,max:1.3},lineWeight:je<300?{min:1.9,max:2}:{min:1.6,max:1.7},minDistanceMult:{min:.45,max:.5},lineTapering:{scale:{in:{enabledChance:0,min:.1,max:.2},out:{enabledChance:0,min:1.5,max:2}},fade:{in:{enabledChance:0,min:0,max:0},out:{enabledChance:100,min:3,max:8}}},layerCountChances:[[1,3]],layerOverride:[{fadeAtLineSegmentChance:0,scribbleChance:10,scribbleStrength:{min:.2,max:.4},styleChances:[[1,"bnnoise"],[1,"directional"],[0,"edgefill"],[1,"bluenoise"]],colorMap:"none"===Oe.mutation&&J.bool(50)?[[[100,ye.offsetUp],[1,ye.color]]]:[[[100,ye.color],[1,ye.offsetUp]]]},{fadeAtLineSegmentChance:0,styleChances:[[2,"bnnoise"],[2,"directional"],[0,"edgefill"],[1,"bluenoise"]],colorMap:[[[100,ye.previous]]]},{styleChances:[[1,"bnnoise"]],colorMap:[[[1,ye.brightnessBasedShadowOrHighlight]]]}]};Pe=ge(Pe,{ignoreLightingChance:0,spatialOverride:{[Ge.nonDominant]:s,[Ge.overlay]:{lineWeight:{min:1.6,max:1.7},materialHardness:{min:.6,max:.75},minDistanceMult:{min:1,max:1},layerCountChances:[[1,2]],linePressure:{min:.99,max:.99},layerOverride:[{styleChances:[[1,"bnnoise"]],colorMap:[[[1,ye.lightest]]],fadeAtLineSegmentChance:0,scribbleChance:0},{fadeAtLineSegmentChance:0,styleChances:[[1,"bnnoise"]],colorMap:[[[1,ye.lightest],[1,ye.darkest]]],wobbleAmplitude:{min:6,max:8},wobbleFreq:{min:60,max:90}}]},[Ge.dominant]:ge(s,{fillChance:100,lineTapering:{fade:{in:{enabledChance:0,min:1,max:1},out:{enabledChance:50,min:6,max:8}}},insetChance:20,insetDistance:{min:6,max:12}})}}),Ye=ge(Ye,{insetChance:50,fillChance:50,detailMinScaleDivisor:10,insetDistance:{min:4,max:12},wobbleAmplitude:{min:2,max:4},wobbleFreq:{min:55,max:200},fadeAtLineSegmentChance:0,layerCountChances:[[1,2],[1,1]],colorMap:[[[1,ye.line]]],lineTapering:{fade:{out:{enabledChance:50,min:1,max:2}},scale:{in:{enabledChance:100,min:.01,max:.2},out:{enabledChance:100,min:.01,max:.2}}},linePressure:{min:.8,max:1},materialHardness:{min:.65,max:.82},lineWeight:{min:1.25,max:1.5},ignoreLightingChance:100,styleChances:[[6,"bnnoise"],[6,"directional"],[1,"wobbles"],[1,"bluenoise"]],minDistanceMult:{min:4,max:8}}),Re=ge(Re,{count:0,warpChance:100,length:{min:100,max:200},thickness:{min:1,max:1.5}});let o=e({[$e.sm]:J.int(95,100),[$e.lg]:J.int(65,90),default:J.int(70,100)});Me=ge(Me,{meshInsetMuliplier:0,lineFilter:"none",meshDensity:o,skipLongest:0,percentage:100,cropToDominantShape:!1,colors:l({default:!1}),backgroundColor:l({default:!1}),linePressure:{min:1.1,max:1.4},materialHardness:{min:.75,max:.82},lineTapering:{fade:{in:{enabledChance:0,min:0,max:1},out:{enabledChance:0,min:1,max:2}},scale:{in:{enabledChance:100,min:.1,max:.5},out:{enabledChance:100,min:.1,max:.5}}},thickness:e({default:je<600?{min:2,max:2.5}:{min:1.5,max:2}})});let r=J.weightedChoice([1,J.int(0,1)],[1,J.int(2,10)]),c=e({[$e.sm]:J.int(4,4),[$e.md]:J.int(4,4),[$e.lg]:J.int(4,4),default:2});He=ge(He,{margin:c*ze.scale,HVariance:{min:-r,max:r,threshold:1,mean:1,stdDev:1},VVariance:{min:-r,max:r,threshold:1,mean:1,stdDev:1},circles:{count:5,minRadius:5,maxRadius:18},wobble:{enabled:!0,count:1e10,minLength:2,layers:4,multiLayers:1,gridDivisions:1,warpFreq:{min:800,max:2e3},offsetMultiplier:.6},perspectiveBox:{enabled:!0,threshold:4,mean:2,stdDev:8,firstFull:!0,count:1}}),Be={...Be,cropToMargin:!1,margin:6*ze.scale}},dt=()=>{qe(20,20),_e="Outlines";let e=at();Fe={[be.horizontal]:3,[be.vertical]:4,[be.perspective]:5,[be.circle]:1,[be.wobbles]:3,[be.objects]:1,[be.curves]:0,[be.rects]:0,[be.borderRect]:0};let t=e[J.weightedChoice([1,it.objects],[1,it.curves],[1,it.angles],[1,it.grid])];J.bool(50)&&(Fe=ge(Fe,t.splits)),Fe[be.curves]=0,Ee=1,je=J.int(2e3,6e3),Qe=ge(Qe,{noiseOverfittingSpread:J.num(0,5),noiseOverfitFreq:J.int(200,1200),polyOverfitting:J.num(.5,2),longestSplitOnlyChance:0}),Ae=0,He=ge(He,{margin:4*ze.scale}),Be={...Be,cropToMargin:!1,margin:4*ze.scale},Re=ge(Re,{count:0,isLineColor:!0}),Ue={...Ue,layers:1,renderLightChance:0,renderAccentChance:0,insetMult:2,maxWidth:80,spread:4,widthRange:.3,maxDivergence:2,tension:{min:.9,max:1.2},maxPointUse:1,pointsToConsider:30,maxLinePoints:30},ke={...ke,layers:1,clampVertsToGrid:!0,maxDist:100,minDist:50,bnFreq:100,clampRotationTo:1,minSizeMult:1,maxSizeMult:1.25,maxSides:5,minSides:3,perspective:1900},Je={...Je,count:0},Ke={...Ke,default:1,clamp:.05,min:.99,max:1},Oe={...Oe,samplesForComplimentary:1,singleAccent:!1,freqMultiplier:1,usePolyIDColorOffset:!0,maxAccents:100,darksOnly:!1};let n=J.bool(50),i=!n&&J.bool(50);Ue={...Ue,maxWidth:J.num(30,40),renderLightChance:J.weightedChoice([1,0],[1,J.int(10,30)]),maxPointUse:J.int(2,3),maxDivergence:J.int(2,3),pointsToConsider:J.int(5,10)};let l=J.num(.75,.85),a=J.num(.75,1);Me=ge(Me,{meshDensity:J.int(60,90),percentage:J.int(40,60),cropToDominantShape:!1,skipLongest:1,colors:!1,backgroundColor:!1,linePressure:{min:l,max:l+.1},materialHardness:{min:1.05,max:1.2},thickness:{min:1*a,max:2*a}}),Ye=ge(Ye,{fillChance:J.int(40,60),fadeAtLineSegmentChance:0,colorMap:[[[1,ye.line]]],minDistanceMult:{min:2,max:4},styleChances:[[1,"bnnoise"],[1,"directional"],[0,"wobbles"],[0,"bluenoise"]],spatialOverride:{[Ge.dominant]:{linePressure:{min:l-.1,max:l-.05}},[Ge.nonDominant]:{fillChance:n?50:100,linePressure:n?{min:l-.1,max:l-.05}:{min:.4,max:.5},minDistanceMult:i?{min:.5,max:1}:{min:2,max:4},styleChances:i?[[0,"bnnoise"],[0,"directional"],[0,"wobbles"],[1,"bluenoise"]]:[[1,"bnnoise"],[1,"directional"],[0,"wobbles"],[0,"bluenoise"]]}}}),Pe=ge(Pe,{fillChance:n?100:0,linePressure:{min:l,max:l+.1},fadeAtLineSegmentChance:0,ignoreLightingChance:100,lineWeight:{min:1.3,max:1.3},lineTapering:{fade:{in:{enabledChance:0,min:0,max:1},out:{enabledChance:0,min:1,max:2}},scale:{in:{enabledChance:10,min:.
import*as e from"three";const{floor:t,ceil:n,sin:i,cos:l,pow:a,abs:s,min:o,max:r,round:c,sqrt:d,acos:u,sign:h,log:m,random:p,PI:g}=Math,b=1e-7;function f(e,n=b){return t(e+n)}function x(e,t=b){return n(e-t)}function Z(e,t=b){const n=t*h(e);return c(e+n)}let y,G,W="#fff";const v=e=>{e.showUpdate?(!G&&(()=>{y=document.createElement("div"),y.id="loading";const e=y.style;e.position="absolute",e.fontSize="1vmax",e.top=e.left="0",e.width="100%",e.height="100%",e.zIndex="1000",G=document.createElement("div");const t=G.style;t.textTransform="uppercase",t.position="fixed",t.lineHeight="0",t.top=t.left="0",t.width="100vw",t.height="100vh",t.height="fill-available",t.display="flex",t.justifyContent=t.alignItems="center",t.flexDirection="column",t.color=W,t.fontFamily="system-ui",t.fontWeight="500",y.appendChild(G),document.body.appendChild(y)})(),G.innerHTML=(e=>{const{message:t="",value:n=0,isPercent:i=!1}=e;let l=`<p>${t}</p>`,a="";return a=i?`<div style="max-width: 15vmin; margin-top: 1.25em; width: 100%; border: .5px solid ${W}"><div style="width: ${e.value||0}%; height: .75vmin; background-color: ${W}; overflow: hidden;"></div>`:`<p style="margin-top: 1.5em">${n}</p>`,""+(l+a)})(e)):G&&L()},L=()=>{let e=document.getElementById("loading");e&&document.body.removeChild(e),G=null};let S,X,C,V,w,K,R=()=>{S.style.display="none"},k=()=>{S.style.display="block"};const T=performance.now.bind(performance);let M,z,Y,P,I=null,H=()=>{M.style.display="none"},F=.72;const N=r(window.devicePixelRatio,2);let U,D,O,B,Q,J,j=0;class A{useA;prngA;prngB;hash;constructor(e){this.useA=!1,this.hash=e;const t=globalThis.parseInt;let n=function(e){let n=t(e.substring(0,8),16),i=t(e.substring(8,16),16),l=t(e.substring(16,24),16),a=t(e.substring(24,32),16);return function(){n|=0,i|=0,l|=0,a|=0;let e=(n+i|0)+a|0;return a=a+1|0,n=i^i>>>9,i=l+(l<<3)|0,l=l<<21|l>>>11,l=l+e|0,(e>>>0)/4294967296}};this.prngA=n(this.hash.substring(2,34)),this.prngB=n(this.hash.substring(34,66))}dec(){return this.useA=!this.useA,this.useA?this.prngA():this.prngB()}num(e,t){return e+(t-e)*this.dec()}int(e,n){return t(this.num(e,n+1))}bool(e=50){return this.dec()<e/100}choice(e){return e[this.int(0,e.length-1)]}easedDec(e){return e(this.dec())}easedInt(e,n,i){return t(this.easedNum(e,n,i))}easedNum(e,t,n){return t+(n-t)*this.easedDec(e)}weightedChoice(...e){const t=e.reduce(((e,[t])=>e+t),0);let n=this.dec()*t;for(const[t,i]of e)if((n-=t)<0)return i;return e[e.length-1][1]}gaussian(e=0,t=1){let n=0,i=0;for(;0===n;)n=this.dec();for(;0===i;)i=this.dec();return d(-2*m(n))*l(2*g*i)*t+e}gaussianBool(e=0,t=0,n=1){return this.gaussian(t,n)>=e}}function E(e=J){let t="0x";for(let n=0;n<64;n++)t+=Math.floor(16*e.dec()).toString(16);return t}let _,q=["0x79e4e7366d15206ce9f686aad9342df4022aae566689ccdd2616fef8eadf24fd","0xabb30680bfbc30d14af1884dc0078b201e00b9e56d79cf689a9b6c2466c9e7ce","0x6bfa2a5aa8879e7141f848ea3d18a43e5f808593890558a7ef5ee2c3f1f11047","0x2b6c8f8e2d35251cc72888786ac8592ab90c42ac4267c8c425326d87017bc345","0x9a74fc0b090bc985b238194988b07f5d14a866009c28f307703e20a1615f46fd","0xd50240d082091aa1290ff47dc8017677d42a5c42662d80c422745c1765598511","0x5f24d9d9c800b6e19b8ea9115514e59de6d0223b59bd7761e0abb28c1ddcf33f","0xfdad5657593d5aa53e307ea3fa4ca0b4b583a4819c11237e774a797788769d6b","0x25235c1d1ca4a672b1b5cefbd5bb734b27c66588fd5b9d891f4b8168a4661508","0x35cbb692c9572a3f83652fc351c11fd47a4bf86a39a3b5c1f66eb9548786f40f","0x62bacaa70cb1fd2f33f82cd56d14f5d59acb484d95d472a8c9ef051ca64a3dc6","0x7e555c7adee354f7998152001f3acb422219bf668bf185437da21cd5a30afb64"];function $(){let e="0x";for(var n=0;n<64;n++)e+=t(16*p()).toString(16);if("undefined"!=typeof tokenData&&tokenData?.tokenId){let e=tokenData.tokenId.slice(-3),t=parseInt(e,10);if(void 0!==q[t])return q[t]}return new URLSearchParams(globalThis.location.search).get("hash")||("undefined"!=typeof tokenData&&tokenData?.hash?tokenData.hash:e)}_=$();let ee="\n vec3 mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n }\n\n vec2 mod289(vec2 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n }\n\n vec3 permute(vec3 x) {\n return mod289(((x * 34.0) + 10.0) * x);\n }\n\n // Noise\n float snoise2D(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n\n // Permutations\n i = mod289(i);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));\n\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n float fbm(const vec2 v, const int octaves, float frequency, float amplitude) {\n float total = 0.0;\n float maxAmplitude = 0.0;\n for(int i = 0; i < octaves; i++) {\n total += snoise2D(v * frequency) * amplitude;\n maxAmplitude += amplitude;\n frequency *= 2.0;\n amplitude *= 0.5;\n }\n return total / maxAmplitude;\n }\n\n",te="\n float screenEdgeDist(vec2 uv, const float falloff) {\n vec2 normalizedCoords = gl_FragCoord.xy / resolution;\n\n // Calculate distances to the nearest edges\n float distanceToLeftEdge = normalizedCoords.x;\n float distanceToRightEdge = 1.0 - normalizedCoords.x;\n float distanceToBottomEdge = normalizedCoords.y;\n float distanceToTopEdge = 1.0 - normalizedCoords.y;\n\n // Find the minimum distance to any edge\n float minDistanceToEdge = min(min(distanceToLeftEdge, distanceToRightEdge), min(distanceToBottomEdge, distanceToTopEdge));\n\n float scaledDistance = 1.0 - abs(2.0 * minDistanceToEdge - 1.0);\n\n // Apply customizable falloff\n float falloffEffect = pow(scaledDistance, falloff);\n\n return falloffEffect;\n }\n",ne="\n float randomNonDet(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n }\n",ie="\n out vec2 vUv;\n\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n";const le=e.Vector2;let ae=!1,se={countX:1,countY:1,index:{x:0,y:0}},oe=(e=!1)=>{let t=e?P:Q,i=n((e?Y:B)/se.countX),l=n(t/se.countY);return{width:i,height:l,xOff:se.index.x*i,yOff:se.index.y*l,yOffFlippedY:(se.countY-1-se.index.y)*l}},re=t=>{let n=t.uniforms,{width:i,height:l,xOff:a,yOffFlippedY:s}=oe();n.uTileOffset.value=new e.Vector2(a,s),n.uTileSize.value=new e.Vector2(i,l)},ce=()=>(!ae&&(()=>{ae=!0;let e=new URL(window.location.href),t=e.searchParams.get("tileCount"),n=e.searchParams.get("index");if(t){let e=parseInt(t);se.countX=e,se.countY=e}if(n){let[e,t]=n.split(",").map((e=>parseInt(e)));se.index.x=o(e,se.countX-1),se.index.y=o(t,se.countY-1)}})(),{uTileOffset:{value:new e.Vector2(0,0)},uTileSize:{value:new e.Vector2(B,Q)}});var de=[{name:"Faces",bg:[[.7409,.0057,69.9871]],line:[[.12,0,68]],base:[[.7995,.0104,53.9144]],accent:[[.55,.092,133],[.37,.1,8],[.47,.124,28],[.7,.112,90],[.48,.088,247],[.59,.048,197],[.78,.012,56.581],[.12,0,68],[.52,.12,342],[.71,.068,44],[.44,.04,299],[.21,.004,329],[.7883,.0264,44]],commonPool:!0,solo:!1},{name:"Chalks",bg:[[.6919,.0323,69.9871]],line:[[.1285578041548887,4.7918630361524376e-9,null]],stroke:[[.9104718532196331,.02929501882422003,89.58052190776175]],base:[[.7968,.033,55.4365]],accent:[[.4391005470961144,.053143667197297274,179.45284673806202],[.7430751481851373,.0929,39.83760570859084],[.7703,.0895,64.56344067218811],[.6641410434441858,.15689118437280108,37.13690468980104],[.7559,.0178,222.564179724743]],disabled:!1,commonPool:!0,solo:!1},{name:"Beach",bg:[[.6835,.03883960001602766,67.25848906440592]],stroke:[[.9372288972261885,.020696467664658196,67.57155893750883]],line:[[.23356138751632896,.02729114952576314,246.90070685897228]],base:[[.8371,.0215,57.0279]],accent:[[.2774185198607467,.04318925551193144,167.75274001919718],[.42064998654759594,.03120177133138129,171.32246538045877],[.4311384415174281,.02336516751567073,241.2330314983908],[.6176019379584577,.1270253885540799,74.1805651416355],[.7260022319511451,.09724578337934522,55.06470317899317],[.7582608113288266,.02549172589125699,166.85185191796654],[.8204,.023,61.9891]],commonPool:!0,solo:!1},{name:"Morning Sun In A Dusty Room",bg:[[.25615282357231434,.011591200093299888,338.1519820725431]],line:[[.14287287327771095,.004143654188326715,345.4391631242127],[.8348,.02687,98.479]],stroke:[[.9136637420289497,.02687443532425364,80.24542314462997]],base:[[.7783871111844314,.042589978975680454,25.529877185969667]],accent:[[.2152,.011591200093299888,338.1519820725431],[.4974379254425503,.08269393625659356,333.938678657093],[.6377751669772775,.16624575588870555,29.858240404234152],[.7303722440997971,.14878423535567212,65.78690162717032],[.525648519572251,.044624199378743616,227.89564437801943],[.8348,.02687443532425364,98.4785]],commonPool:!0,solo:!1},{name:"Jazz",stroke:[[.2866006793419412,.021957785534446477,88.03909075711272]],bg:[[.7399,.0328,69.58004864146267]],base:[[.8051,.0372,74.6117]],line:[[.1285578041548887,4.7918630361524376e-9,null]],accent:[[.6315375414148215,.1752,34.478822707810366],[.5221231161993111,.109,231.97797627692054],[.7332,.1701,64.69716240181685],[.6904,.1463,32.65581391676761],[.8075,.0269,54.0471]],disabled:!1,commonPool:!0,solo:!1},{name:"Beige Box",bg:[[.2169,.004109954650405697,264.48855986171543]],line:[[.1921,.004109954650405697,264.48855986171543],[.7094,.004109954650405697,264.48855986171543]],base:[[.7044,.0027,264.3],[.2582,0,264.15]],stroke:[[.6451555150878627,.1324103074498338,351.3679204443482]],accent:[[.2944,0,264.1525],[.6471384357175027,.0950806296946004,146.09535186981566],[.6248985136009452,.08343861458985488,258.09336743754636],[.6419604611344321,.1604756929950665,39.9727943299859],[.6451555150878627,.1324103074498338,351.3679204443482],[.8436835998771347,.14145685075787068,96.14554462682747],[.71866,.13925,63.701],[.6861,.007,63.701]],commonPool:!0,solo:!1},{name:"Master",bg:[[.6936,.0211,82.40092539697929]],line:[[.2507780863015607,.009572580032197206,67.3680640985574]],base:[[.7269,.0162,157.61886984444504]],stroke:[[.9060102804608031,.012170144621286422,23.7150415636807]],accent:[[.6295566765037485,.1211519827044528,67.32018448430034],[.7605,.0195,238.616994352628],[.6174604546514465,.05042117055871639,256.5164449583005],[.4181072443550769,.072,173.90831954879036],[.6627,.1667,37.60803793025025],[.8234,.0071,74.2545],[.7783,.073,8.0298]],commonPool:!0,solo:!1},{name:"New York Autumn",bg:[[.7037,.0281,65.28937708039064]],stroke:[[.8626142182586253,.08537649420452362,82.03909126824601]],line:[[.19548782481388519,.00430705323020645,264.468763979492]],base:[[.7661,.0329,58.25082050504636]],accent:[[.45478156079252346,.039285338382841796,179.22836606186138],[.7553531036330657,.08130837219892006,99.24794847558877],[.5594780208031984,.07916054354499198,245.43994841186026],[.42899728927916636,.04922887943462986,76.52219098535193],[.8309661998821414,.04281039028933322,48.183040275461394],[.7850648916204185,.1273241170717795,79.558262732039],[.8022,.1082,91.79312487991842],[.5727044802833001,.1271825150640351,18.826326398068147],[.5371544884294275,.13634924860871195,21.160585432853736]],commonPool:!0,solo:!1},{name:"The Coast",bg:[[.6974,.0085,76.58691599832048]],stroke:[[.8444869430616695,.08523591444134622,87.01376484878972]],line:[[.22755957415683586,.0015428045966122382,17.270340681712298]],base:[[.7669770002469423,.0030391208463875215,84.56153889362372]],accent:[[.3779357986919375,.0535,176.4086979076003],[.6184542058002529,.0765,130.0878133972343],[.8444869430616695,.0863,87.01376484878972],[.8204404719119529,.0562,13.36293462743373],[.6466292227896673,.1007,248.2503623167608],[.6773,.0488,194.3393064675039],[.6163,.1335,21.160585432853736],[.7968000000000001,.01676,79.345]],commonPool:!0,solo:!1},{name:"Aged",bg:[[.7084,.0396,87.75614537114114]],stroke:[[.94095456060748,.015612821171329101,86.4264441546818]],line:[[.2703834919362128,.003498268640239951,48.59454667339406]],base:[[.7841,.021041287596747362,75.5028]],accent:[[.6599008372479219,.14410614712594896,43.767864491957255],[.5406041428443183,.0810794492722289,156.20612626175443],[.5030711080692698,.15264841257121137,26.608155858968416],[.7691417851736347,.1353050284474489,77.87710240074239],[.7874426063872318,.04659921665479499,51.68182155996902],[.467824859321765,.056096190272488924,217.56676918001241]],commonPool:!0,solo:!1},{name:"Ink & Colour",bg:[[.7601,.014,255.4795978283716]],stroke:[[.9553483843727791,.002877617626355211,84.55913178523588]],line:[[.23724829442832204,.009300030023333045,159.3038618360598]],base:[[.5326,.0294,169.58],[.5352,.1055,153.65],[.7482,.0675,265.537],[.5786,.1009,265.537]],accent:[[.3475,.065,169.58],[.4333,.08067410261737115,292.88016945552295],[.8007868908561364,.0333,7.942656494991638],[.6086666969575215,.1634,28.003190670134757],[.3195,.034575073883449464,254.02069392111645],[.6738,.1201,79.6718],[.8711,.00292,264.54],[.6613,.0632,169.58],[.5352,.1055,153.6549],[.6531,.1061,265.54]],disabled:!1,commonPool:!0,solo:!1},{name:"Oranges",bg:[[.705,.0354,65.1718]],stroke:[[.9912189562526743,.006931254927170287,88.6413010074412]],base:[[.7842,.0305,86.3684]],line:[[.18797280274608968,.026745997001574016,159.25756384014687]],accent:[[.35508002090426666,.043787467826530785,211.52484726500788],[.5510005837793092,.08755866639046411,103.27386758796968],[.691,.1582,47.266522185041936],[.7373,.1324,67.62887023877073],[.7999,.0316,88.72052641225343],[.7631,.0647,19.8072]],commonPool:!0,solo:!1},{name:"Henri",bg:[[.7213,.0319,80.6824944352112]],stroke:[[.7121124312829297,.09603422725607345,34.15613531599104]],line:[[.24303319779115856,.004923290798673418,355.16568727574077]],base:[[.8256,.0305,76.17859369988122]],accent:[[.4159,.0591,191.39940656052516],[.7920378039704564,.1352,73.45878915862028],[.7593,.0165,220.7288245953125],[.4637,.0738,237.7123227684075]],disabled:!1,commonPool:!0,solo:!1},{name:"Rand-ey",bg:[[.7426,.0171,87.52315695161104]],line:[[.19419793765469762,.0219,297.0814230776026]],stroke:[[.9076072420048279,.019870599528847212,87.51855970858247]],base:[[.595,.0433,247.9],[.7126,.0966,68.946],[.7791,0,64.059],[.5968,.1097,151.59]],accent:[[.575943267748716,.1486,29.4685],[.5129975835116938,.0741,305.527422000483],[.7538026010313094,.139,68.94572099685297],[.6147,.1332,247.9],[.8423,0,64.0592],[.53766,.1084,167.07]],disabled:!0,commonPool:!0,solo:!1},{name:"Olivetti",bg:[[.2222,.004109954650405697,264.48855986171543]],line:[[.234784254171478,.004109954650405697,264.48855986171543]],stroke:[[.7186588335782654,.1392507657144271,63.7012930132442]],base:[[.2551,0,34.30274488067005]],accent:[[.7186588335782654,.1392507657144271,63.7012930132442],[.6471384357175027,.0950806296946004,146.09535186981566],[.6248985136009452,.08343861458985488,258.09336743754636],[.6419604611344321,.1604756929950665,39.9727943299859],[.6451555150878627,.1324103074498338,351.3679204443482],[.8373623117765204,.15785248852128372,95.6270196002983],[.2582,.0037,275.8924],[.5803,.0037,275.8924]],disabled:!0,commonPool:!0,solo:!1},{name:"Toddler",bg:[[.7421,.0212,48.4352]],line:[[.18797280274608968,.026745997001574016,159.25756384014687]],stroke:[[.18797280274608968,.026745997001574016,159.25756384014687]],base:[[.6859848282821445,.008266766434931419,61.396302349703944],[.9349265127013049,.01153735356888476,84.57925253447382],[.7688,.0216,61.396302349703944]],accent:[[.3500879126177943,.0865,264.1433132212142],[.4453610930960556,.02928835497819446,336.8043193096847],[.569281111283594,.1860449489679648,25.02687693308303],[.5558543866168449,.054963958871380815,108.06205545681729],[.7052281079548163,.16337391917830385,43.93536507302679],[.8036,.1343,80.58696151433355],[.6763,.0745,108.06205545681729],[.7615,.0782,25.02687693308303]],disabled:!1,commonPool:!0,solo:!1}];let ue=(de.some((e=>e.solo))?de.filter((e=>e.solo)):de.filter((e=>!e.disabled))).map((e=>({name:e.name,disabled:e.disabled,commonPool:e.commonPool,base:e.base,bg:e.bg,line:e.line,accent:e.accent}))),he=de.filter((e=>e.commonPool)).map((e=>({name:e.name,disabled:e.disabled,commonPool:e.commonPool,base:e.base,bg:e.bg,line:e.line,accent:e.accent})));function me(e){return e*g/180}function pe(e){return function(e){return null!==e&&"object"==typeof e}(e)&&!Array.isArray(e)}function ge(...e){const t={};for(const n of e)if(n)for(const e of Object.keys(n)){const i=n[e];if(Array.isArray(i))t[e]=[...i];else if(pe(i)){const n=t[e];pe(n)?t[e]=ge(n,i):t[e]=ge({},i)}else t[e]=i}return t}var be,fe,xe;!function(e){e[e.horizontal=0]="horizontal",e[e.vertical=1]="vertical",e[e.perspective=2]="perspective",e[e.circle=3]="circle",e[e.wobbles=4]="wobbles",e[e.curves=5]="curves",e[e.rects=6]="rects",e[e.borderRect=7]="borderRect",e[e.triangle=8]="triangle",e[e.objects=9]="objects",e[e.used=10]="used"}(be||(be={})),function(e){e[e.front=0]="front",e[e.up=1]="up",e[e.right=2]="right",e[e.down=3]="down",e[e.left=4]="left"}(fe||(fe={})),function(e){e.border="border",e.scene="scene",e.none="none"}(xe||(xe={}));let Ze={layers:2,layerScaleMult:2.5,zDepthMaxMult:1,cropTo:xe.none,forceYUp:!0,clampVertsToGrid:!0,maxDist:200,minDist:130,bnFreq:500,fieldFreq:1500,clampRotationTo:1,minSizeMult:1,maxSizeMult:.75,maxSides:5,minSides:3,perspective:2e4};var ye,Ge;!function(e){e[e.color=0]="color",e[e.line=1]="line",e[e.palettecomplement=2]="palettecomplement",e[e.previous=3]="previous",e[e.base=4]="base",e[e.paletteOffset=5]="paletteOffset",e[e.shadow=6]="shadow",e[e.highlight=7]="highlight",e[e.randomAccent=8]="randomAccent",e[e.offset=9]="offset",e[e.offsetUp=10]="offsetUp",e[e.lightestOrDarkestBasedOnBg=11]="lightestOrDarkestBasedOnBg",e[e.brightnessBasedShadowOrHighlight=12]="brightnessBasedShadowOrHighlight",e[e.offsetDown=13]="offsetDown",e[e.darkest=14]="darkest",e[e.lightest=15]="lightest"}(ye||(ye={})),function(e){e.override="override",e.dominant="dominant",e.inCurveOrObject="inCurveOrObject",e.notInCurveOrObject="notInCurveOrObject",e.nonDominant="nonDominant",e.normalHigh="normalHigh",e.normalLow="normalLow",e.overlay="overlay",e.noop="noop"}(Ge||(Ge={}));let We,ve,Le={scribbleChance:0,edgeSharpness:{min:.2,max:.2},scribbleStrength:{min:.5,max:.5},accumulationStrength:{min:1,max:1},materialHardness:{min:1,max:1},fillChance:100,fadeAtLineSegmentDistanceMult:{min:.5,max:1.5},fadeAtLineSegmentStrengthMult:{min:1,max:1},minDistanceMult:{min:5,max:5},linePressure:{min:.8,max:.9},brightnessHighLowThreshold:.75,fadeAtLineSegmentChance:0,detailMinScaleDivisor:30,ignoreLightingChance:0,colorMap:[[[1,ye.color]],[[1,ye.color]]],dominantMeshWeight:100,insetChance:0,insetDistance:{min:2,max:4},wobbleAmplitude:{min:.5,max:1},wobbleFreq:{min:.5,max:1},layerCountChances:[[0,0],[1,1],[2,2]],styleChances:[[3,"noise"],[4,"directional"],[1,"wobbles"],[3,"bluenoise"]],lineTapering:{scale:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:1,max:1}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},lineWeight:{min:1.1,max:1.1},spatialOverride:{[Ge.overlay]:{fillChance:0}}},Se={scribbleChance:0,edgeSharpness:{min:.5,max:.5},scribbleStrength:{min:.3,max:.3},fillChance:100,accumulationStrength:{min:1,max:1},fadeAtLineSegmentDistanceMult:{min:.5,max:1.5},fadeAtLineSegmentStrengthMult:{min:1,max:1},colorMap:[[[1,ye.color]]],fadeAtLineSegmentChance:100,brightnessHighLowThreshold:.75,ignoreLightingChance:0,detailMinScaleDivisor:30,minDistanceMult:{min:.75,max:.75},dominantMeshWeight:100,insetChance:0,insetDistance:{min:2,max:4},wobbleAmplitude:{min:2,max:3},wobbleFreq:{min:20,max:40},layerCountChances:[[1,1]],styleChances:[[1,"noise"],[0,"directional"],[0,"wobbles"],[0,"bluenoise"]],lineTapering:{scale:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:1,max:1}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},linePressure:{min:1,max:1},materialHardness:{min:1,max:1},lineWeight:{min:1.1,max:1.1},spatialOverride:{[Ge.overlay]:{fillChance:100,lineWeight:{min:2.5,max:2.5},fadeAtLineSegmentChance:0,insetChance:0,ignoreLightingChance:100,styleChances:[[1,"noise"],[0,"directional"],[0,"wobbles"],[0,"bluenoise"]],minDistanceMult:{min:.75,max:.75},lineTapering:{scale:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:1,max:1}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},layerCountChances:[[1,2]]}}},Xe={[be.horizontal]:0,[be.vertical]:10,[be.perspective]:0,[be.circle]:10,[be.wobbles]:0,[be.objects]:8,[be.curves]:10,[be.rects]:5,[be.borderRect]:10},Ce=[be.horizontal,be.vertical,be.perspective],Ve={count:1,outline:!0,colors:[[0,ye.color],[0,ye.offset],[0,ye.base],[0,ye.line],[0,ye.darkest],[1,ye.lightest]],colorOffsets:!1,size:{min:4,max:9}},we=[],Ke={default:1,min:.45,max:1.12,clamp:.001,influencesPressureMult:0,influencesBrightnessMult:1,influencesMinDistanceMult:.3,position:{x:-10005.5,y:-1e4,z:-12e3}},Re={colors:!1,isLineColor:!1,count:50,warpChance:100,lineTapering:{scale:{in:{enabledChance:100,min:.5,max:.8},out:{enabledChance:100,min:.5,max:.8}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},length:{min:20,max:100},hardness:{min:1,max:1},thickness:{min:.5,max:5}},ke=Ze,Te={forceInsertCurvesChance:0,forceInsertObjectsChance:0},Me={meshDensity:80,lineFilter:"none",meshInsetMuliplier:1,dominantLineInsetMultiplier:1,percentage:50,skipLongest:3,cropToDominantShape:!1,materialHardness:{min:.9,max:.95},colors:!1,backgroundColor:!1,lineTapering:{scale:{in:{enabledChance:100,min:.3,max:.6},out:{enabledChance:100,min:.3,max:.6}},fade:{in:{enabledChance:50,min:.1,max:.2},out:{enabledChance:50,min:.1,max:.2}}},linePressure:{min:.9,max:.95},thickness:{min:.5,max:3}},ze={countX:0,countY:0,marginX:0,marginY:0,w:0,h:0,scale:0},Ye=Le,Pe=Se,Ie={enabled:!0,percentage:60,materialHardness:{min:.4,max:.4},lineTapering:{scale:{in:{enabledChance:100,min:.01,max:.1},out:{enabledChance:100,min:.01,max:.1}},fade:{in:{enabledChance:100,min:.01,max:.1},out:{enabledChance:100,min:.01,max:.1}}},linePressure:{min:.5,max:.5},lineWeight:{min:.6,max:.6}},He={margin:0,HVariance:{min:0,max:10,threshold:2,mean:1,s
tdDev:1},VVariance:{min:0,max:10,threshold:2,mean:1,stdDev:1},rects:{insetRectEnabled:!0,spiralRectsEnabled:!0},circles:{count:0,minRadius:2,maxRadius:30},wobble:{enabled:!1,count:1e10,layers:2,multiLayers:1,minLength:5,gridDivisions:1,warpFreq:{min:600,max:800},offsetMultiplier:1},perspectiveBox:{enabled:!0,threshold:2,mean:1,stdDev:1,count:1,firstFull:!0}},Fe=Xe,Ne=Ce,Ue={layers:1,renderLightChance:0,ignoreLighting:!0,renderAccentChance:0,insetMult:2,maxWidth:80,spread:4,widthRange:.3,maxDivergence:2,tension:{min:.9,max:1.2},maxPointUse:1,pointsToConsider:30,maxLinePoints:30},De={warpX:!0,warpY:!1,offAxisX:!0,offAxisY:!1,warpXMult:.05,warpYMult:.05,displacementStrength:.05,noiseMapEnabled:!0},Oe={maxAccents:4,mutation:"none",dominantIsAccentChance:50,useNoiseLookup:!0,samplesForComplimentary:3,samplesForPaletteOffset:2,addBGContrast:!1,freqMultiplier:10,usePolyIDColorOffset:!0,singleAccent:!1,darksOnly:!1},Be={cropToMargin:!0,cropBGShapesAtMargin:!0,cropToMarginFillDark:!1,margin:30},Qe={count:100,lineRemoveStrength:.1,polyOverfitting:.75,noiseOverfittingSpread:0,noiseOverfitFreq:100,excludeWeakSplits:!1,longestSplitOnlyChance:50,noiseFieldCategoryInfluence:1e3},Je=Ve,je=100,Ae=.1,Ee=0,_e="";const qe=(e,t)=>{ze.scale=J.int(e,t);const n=Y/ze.scale,i=P/ze.scale;ze.countX=Math.ceil(n),ze.countY=Math.ceil(i);const l=ze.countX*ze.scale,a=ze.countY*ze.scale;ze.marginX=(Y-l)/2,ze.marginY=(P-a)/2,ze.w=ze.scale,ze.h=ze.scale};var $e,et,tt,nt,it;function lt(e,t){return function(e){return void 0!==e[t]?e[t]:e.default}}!function(e){e.xs="xsmall",e.sm="small",e.md="medium",e.lg="large",e.xl="xlarge"}($e||($e={})),function(e){e.none="none",e.sparse="sparse",e.light="light",e.dense="dense",e.filled="filled",e.detailOnly="detailOnly"}(et||(et={})),function(e){e.light="light",e.medium="medium",e.heavy="heavy"}(tt||(tt={})),function(e){e.color="color",e.dark="dark",e.light="light"}(nt||(nt={})),function(e){e.objects="objects",e.curves="curves",e.angles="angles",e.grid="grid",e.mesh="mesh",e.all="all",e.random="random"}(it||(it={}));const at=()=>({[it.objects]:{splits:{[be.horizontal]:1,[be.vertical]:2,[be.perspective]:0,[be.circle]:2,[be.wobbles]:3,[be.objects]:15,[be.curves]:5,[be.rects]:1,[be.borderRect]:1},meta:{forceSplit:{forceInsertCurvesChance:J.choice([10,0]),forceInsertObjectsChance:J.choice([30,0])}}},[it.grid]:{splits:{[be.horizontal]:2,[be.vertical]:4,[be.perspective]:0,[be.circle]:4,[be.wobbles]:1,[be.objects]:10,[be.curves]:0,[be.rects]:0,[be.borderRect]:0},meta:{forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:0}}},[it.curves]:{splits:{[be.horizontal]:1,[be.vertical]:2,[be.perspective]:0,[be.circle]:10,[be.wobbles]:10,[be.objects]:J.choice([10,1]),[be.curves]:10,[be.rects]:0,[be.borderRect]:1},meta:{usedLineReplayChance:10,forceSplit:{forceInsertCurvesChance:J.choice([0,20]),forceInsertObjectsChance:J.choice([0,20])}}},[it.angles]:{splits:{[be.horizontal]:2,[be.vertical]:3,[be.perspective]:3,[be.circle]:0,[be.wobbles]:0,[be.objects]:3,[be.curves]:2,[be.rects]:0,[be.borderRect]:1},meta:{forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:0}}},[it.mesh]:{splits:{[be.horizontal]:1,[be.vertical]:1,[be.perspective]:1,[be.circle]:1,[be.wobbles]:0,[be.objects]:1,[be.curves]:0,[be.rects]:0,[be.borderRect]:0},meta:{objectProps:{forceYUp:!0},forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:50}}},[it.all]:{splits:{[be.horizontal]:2,[be.vertical]:2,[be.perspective]:2,[be.circle]:2,[be.wobbles]:2,[be.objects]:4,[be.curves]:2,[be.rects]:1,[be.borderRect]:2},meta:{forceSplit:{forceInsertCurvesChance:0,forceInsertObjectsChance:0}}}});let st,ot;const rt=()=>{let e=at();_e="Pencils",qe(20,20),ot=J.weightedChoice([15,$e.sm],[15,$e.md],[10,$e.lg]);let n=lt(0,ot);st=J.weightedChoice([n({[$e.sm]:1,default:1}),et.light],[n({[$e.sm]:0,default:1}),et.dense],[n({[$e.sm]:2,[$e.md]:2,default:1}),et.filled],[1,et.detailOnly]);let i=lt(0,st),l=lt(0,J.weightedChoice([n({[$e.sm]:i({[et.none]:0,[et.sparse]:0,default:0}),default:0}),tt.light],[1,tt.medium],[1,tt.heavy])),a=J.weightedChoice([n({[$e.sm]:i({[et.filled]:5,default:1}),default:1}),it.objects],[n({[$e.sm]:0,default:2}),it.curves],[n({[$e.sm]:0,default:1}),it.angles],[n({[$e.sm]:0,default:1}),it.grid]),s=e[a];Fe=ge(Fe,s.splits),Te=ge(Te,s.meta.forceSplit),Qe=ge(Qe,{noiseOverfittingSpread:n({[$e.sm]:J.num(0,1),default:J.num(0,1)}),noiseOverfitFreq:1200,polyOverfitting:J.choice([1,J.num(.5,1.5)]),longestSplitOnlyChance:n({[$e.sm]:J.choice([0,50,100]),default:J.choice([50,100])}),noiseFieldCategoryInfluence:J.choice([1,4])}),Ee=n({default:s.meta?.usedLineReplayChance||4}),je=t(n({[$e.sm]:i({[et.filled]:J.int(190,180),[et.none]:J.int(190,230),[et.detailOnly]:J.int(200,230),default:J.int(190,230)}),[$e.md]:J.int(250,350),[$e.lg]:J.int(350,800)})),Ae=i({[et.filled]:n({[$e.lg]:J.num(0,.3),[$e.md]:J.num(0,.2),[$e.sm]:J.num(0,.01),default:J.num(0,.1)}),default:n({[$e.sm]:J.num(0,.01),[$e.md]:J.num(0,.1),[$e.lg]:J.num(0,.3)})});let o=J.weightedChoice([1,!1],[1,!0]);Oe={...Oe,mutation:J.weightedChoice([0,"offsetUp"],[0,"offsetDown"],[3,"none"]),addBGContrast:i({[et.detailOnly]:!1,default:!0}),useNoiseLookup:!0,samplesForComplimentary:J.int(1,3),samplesForPaletteOffset:1,singleAccent:!1,freqMultiplier:n({default:o?J.num(300,600):J.num(300,400)}),usePolyIDColorOffset:o,maxAccents:n({default:J.weightedChoice([1,4],[1,6],[2,100])}),darksOnly:!1};let r=lt(0,J.weightedChoice([10,nt.color],[n({[$e.lg]:1,default:0}),nt.dark],[n({[$e.lg]:1,default:0}),nt.light]));Je={...Je,size:n({[$e.lg]:{min:4,max:5},[$e.md]:{min:5,max:6},[$e.sm]:{min:6,max:8}})},Ne=[be.horizontal,be.vertical],Ke={...Ke,default:1,clamp:.05,min:.6,max:1,influencesPressureMult:0,influencesBrightnessMult:1,influencesMinDistanceMult:.2},st!=et.filled||ot!=$e.lg&&ot!=$e.md||!J.bool(10)||(Ke={...Ke,default:1,clamp:.05,min:.5,max:.55,influencesPressureMult:0,influencesBrightnessMult:1,influencesMinDistanceMult:0});let c=J.bool(40);Ue={...Ue,ignoreLighting:J.bool(50),maxWidth:.75*n({[$e.sm]:J.int(40,50),[$e.md]:J.int(40,50),default:J.num(35,45)}),renderLightChance:J.weightedChoice([1,0],[1,J.int(0,10)]),maxPointUse:1,maxDivergence:2,pointsToConsider:10};let d=J.num(.75,1.5);ke=ge({...ke,layers:2,layerScaleMult:2.5,zDepthMaxMult:J.int(1,2),cropTo:n({default:J.choice([xe.scene,xe.border,xe.none])}),forceYUp:a==it.grid||J.bool(30),clampVertsToGrid:n({[$e.sm]:!1,default:!1}),...n({[$e.sm]:{maxDist:200*d,minDist:130*d},[$e.md]:{maxDist:150*d,minDist:100*d},[$e.lg]:J.weightedChoice([5,{maxDist:130*d,minDist:80*d}])}),bnFreq:J.num(10,1e3),fieldFreq:n({[$e.lg]:J.int(4e3,1e4),[$e.sm]:J.int(1e3,2e3),default:J.choice([J.int(1e3,4e3),J.int(4e3,1e4)])}),clampRotationTo:J.weightedChoice([1,22.5],[4,1],[1,11.25]),minSizeMult:1,maxSizeMult:n({default:.75}),maxSides:5,minSides:3,perspective:2e4},s.meta?.objectProps||{});let u={edgeSharpness:{min:.8,max:1},fillChance:100,insetChance:J.choice([8,5,0]),wobbleFreq:{min:40,max:80},wobbleAmplitude:{min:1,max:3},accumulationStrength:{min:1,max:1},materialHardness:i({[et.light]:{min:.9,max:.97},default:{min:.93,max:.99}}),linePressure:i({default:{min:.65,max:.7}}),minDistanceMult:n({[$e.lg]:{min:.7,max:.8},[$e.sm]:{min:.7,max:.8},default:{min:.7,max:.8}}),lineTapering:{fade:{in:{enabledChance:0,min:0,max:0},out:{enabledChance:0,min:0,max:0}},scale:{in:{enabledChance:0,min:0,max:0},out:{enabledChance:0,min:0,max:0}}},layerCountChances:l({[tt.light]:[[1,2]],[tt.medium]:[[1,4]],[tt.heavy]:[[1,6]]}),lineWeight:n({[$e.sm]:{min:1.5,max:1.6},[$e.md]:{min:1.4,max:1.5},default:{min:1.4,max:1.5}}),layerOverride:[{fadeAtLineSegmentChance:0,lineTapering:{fade:{out:{enabledChance:n({[$e.sm]:50,[$e.md]:10,[$e.lg]:0,default:0}),min:1,max:2}}},wobbleAmplitude:{min:5,max:6},wobbleFreq:{min:50,max:70},styleChances:[[1,"bnnoise"]],colorMap:"none"===Oe.mutation&&J.bool(30)?[[[100,J.choice([ye.offsetDown,ye.offset,ye.offsetUp])],[J.weightedChoice([2,0],[1,J.int(0,15)]),ye.color]]]:[[[100,ye.color],[J.weightedChoice([2,0],[1,J.int(0,15)]),ye.offsetUp]]]},{fadeAtLineSegmentChance:0,styleChances:[[1,"edgefill"]],colorMap:[[[1,ye.previous]]],wobbleAmplitude:{min:5,max:6},wobbleFreq:{min:40,max:100}},J.weightedChoice([0,{scribbleChance:100,scribbleStrength:{min:.2,max:.4},colorMap:[[[1,ye.offset]]],styleChances:[[1,"bnnoise"]],linePressure:{min:.9,max:.95},lineTapering:{scale:{out:{enabledChance:100,min:0,max:.2},in:{enabledChance:100,min:0,max:.2}}}}],[2,{scribbleChance:0,colorMap:[[[1,ye.offsetUp]]],wobbleAmplitude:{min:1,max:1},styleChances:[[1,"bnnoise"]],fadeAtLineSegmentChance:100,fadeAtLineSegmentDistanceMult:{min:.6,max:1},fadeAtLineSegmentStrengthMult:{min:1,max:1.1},linePressure:{min:1.2,max:1.25},materialHardness:{min:.9,max:.95},lineTapering:{fade:{in:{enabledChance:0,min:1,max:1},out:{enabledChance:100,min:3,max:8}}}}]),{styleChances:[[1,"directional"],[1,"bnnoise"]],colorMap:[[[1,ye.previous]]],wobbleAmplitude:{min:4,max:8},wobbleFreq:{min:40,max:60}},{colorMap:[[[1,ye.brightnessBasedShadowOrHighlight]]],fadeAtLineSegmentChance:100,fadeAtLineSegmentDistanceMult:{min:1.5,max:1.5},fadeAtLineSegmentStrengthMult:{min:1,max:1},materialHardness:{min:.7,max:.8},linePressure:{min:1.3,max:1.4},minDistanceMult:{min:.5,max:.6},wobbleAmplitude:{min:1,max:2},wobbleFreq:{min:50,max:100},styleChances:[[1,"bnnoise"],[0,"directional"],[0,"wobbles"],[0,"bluenoise"],[0,"edgefill"]],lineTapering:{fade:{in:{enabledChance:0,min:.1,max:.2},out:{enabledChance:100,min:2,max:4}}}},{styleChances:[[1,"bnnoise"]],colorMap:[[[1,ye.previous]]],wobbleAmplitude:{min:5,max:6},wobbleFreq:{min:80,max:200}}]};Pe=ge(Pe,{ignoreLightingChance:0,wobbleAmplitude:{min:2,max:2},wobbleFreq:{min:35,max:45},materialHardness:i({default:{min:.8,max:.85}}),linePressure:{min:.7,max:.9},minDistanceMult:i({[et.sparse]:{min:2.7,max:3.8},default:{min:1.4,max:1.5}}),spatialOverride:{[Ge.notInCurveOrObject]:{fillChance:100,colorMap:[[[1,ye.offset]]],colorPalette:"fg",ignoreLightingChance:100,insetChance:100,scribbleChance:0,insetDistance:{min:10,max:20},minDistanceMult:{min:2.5,max:5},linePressure:{min:.8,max:.9},lineWeight:{min:.8,max:1.6},fadeAtLineSegmentChance:0},[Ge.nonDominant]:i({[et.light]:ge(u,{colorPalette:"bg",fillChance:100,layerCountChances:[[1,2]],minDistanceMult:{min:1,max:1.3},lineWeight:{min:1.1,max:1.2},layerOverride:[ge(u.layerOverride[0],{colorPalette:"bg",colorMap:[[[1,ye.color]]],linePressure:{min:.15,max:.2},styleChances:[[1,"bnnoise"]]}),ge(u.layerOverride[1],{linePressure:{min:.5,max:.6},colorMap:[[[1,ye.previous]]],styleChances:[[1,"edgefill"]]})]}),[et.detailOnly]:{fillChance:0},default:u}),[Ge.overlay]:{lineWeight:{min:1.6,max:1.7},materialHardness:{min:.6,max:.75},minDistanceMult:{min:1,max:1},layerCountChances:[[1,2]],linePressure:{min:.99,max:.99},layerOverride:{0:{styleChances:[[1,"bnnoise"]],colorMap:[[[1,ye.lightest]]],fadeAtLineSegmentChance:0,scribbleChance:0},1:{fadeAtLineSegmentChance:0,styleChances:[[1,"edgefill"]],colorMap:[[[1,ye.brightnessBasedShadowOrHighlight]]],wobbleAmplitude:{min:6,max:8},wobbleFreq:{min:60,max:90}}}},[i({default:n({[$e.lg]:c?Ge.inCurveOrObject:Ge.dominant,[$e.md]:c?Ge.inCurveOrObject:Ge.dominant,default:Ge.dominant})})]:ge(u,{fillChance:100,insetDistance:{min:6,max:12}})}}),Ye=ge(Ye,{insetChance:50,detailMinScaleDivisor:10,insetDistance:{min:4,max:12},wobbleAmplitude:{min:2,max:4},wobbleFreq:{min:55,max:200},fadeAtLineSegmentChance:0,fillChance:0,layerCountChances:[[1,2],[1,1]],colorMap:i({[et.detailOnly]:[[[1,ye.color]],[[1,ye.previous]]],default:[[[1,ye.line]]]}),lineTapering:{fade:{out:{enabledChance:0,min:1,max:2}},scale:{in:{enabledChance:100,min:.01,max:.2},out:{enabledChance:100,min:.01,max:.2}}},linePressure:{min:.9,max:.95},materialHardness:{min:.9,max:.95},lineWeight:{min:.6,max:1.5},minDistanceMult:{min:3,max:5},spatialOverride:{[Ge.nonDominant]:{scribbleChance:0,lineWeight:{min:1,max:1.5},colorMap:[J.choice([[[100,ye.line]]])],colorPalette:J.choice(["bg","fg"]),insetChance:100,insetDistance:{min:7,max:12},fillChance:i({[et.detailOnly]:100,default:0}),linePressure:i({[et.light]:{min:.5,max:.6},default:{min:.5,max:.6}}),minDistanceMult:n({[$e.sm]:{min:5,max:7},default:{min:4,max:6}}),styleChances:J.weightedChoice([1,[[1,"directional"]]],[1,[[1,"bnnoise"]]],[1,[[2,"bnnoise"],[2,"directional"],[0,"wobbles"],[0,"bluenoise"]]],[1,[[1,"bluenoise"]]])},[Ge.dominant]:{ignoreLightingChance:100,fillChance:n({[$e.sm]:i({[et.detailOnly]:J.int(30,40),default:J.int(40,50)}),default:J.weightedChoice([1,30],[3,J.num(40,70)])}),layerCountChances:[[2,2],[1,1]],linePressure:{min:.7,max:.9},styleChances:[[5,"bnnoise"],[5,"directional"],[1,"wobbles"],[4,"bluenoise"]],materialHardness:{min:.8,max:.9},colorMap:[[[100,ye.randomAccent]],[[100,ye.previous]]],minDistanceMult:{min:6,max:15},lineWeight:n({[$e.lg]:{min:1,max:1.25},default:{min:1,max:1.25}})}}}),Re=ge(Re,{count:10,warpChance:100,length:{min:100,max:200},thickness:{min:1,max:1.5}});let h=n({[$e.sm]:J.int(95,100),[$e.lg]:i({[et.light]:J.weightedChoice([2,J.int(55,70)],[1,J.int(65,90)]),[et.detailOnly]:J.weightedChoice([2,J.int(55,70)],[1,J.int(65,90)]),default:J.int(80,90)}),default:J.int(70,100)}),m=J.num(.75,1.25);Me=ge(Me,{meshInsetMuliplier:0,lineFilter:h<80?"none":J.weightedChoice([1,"curves"],[1,"straight"],[3,"none"]),meshDensity:h,skipLongest:n({[$e.lg]:J.int(0,10),default:0}),percentage:n({[$e.lg]:i({[et.filled]:J.weightedChoice([1,J.int(0,1)],[1,J.int(50,80)]),default:h>70?J.weightedChoice([1,J.int(40,70)],[1,J.int(0,0)]):J.int(40,70)}),[$e.md]:i({[et.filled]:J.weightedChoice([1,J.int(0,0)],[1,J.int(50,80)]),default:h>70?J.weightedChoice([1,J.int(40,70)],[1,J.int(0,5)]):J.int(40,70)}),[$e.sm]:i({[et.filled]:J.weightedChoice([1,J.int(0,0)],[1,J.int(50,80)]),default:J.int(40,70)}),default:J.int(50,80)}),cropToDominantShape:!1,colors:r({[nt.color]:!0,default:!1}),backgroundColor:r({[nt.light]:!(st!==et.filled&&h<80),default:!1}),materialHardness:{min:.9,max:.96},linePressure:{min:.9,max:.95},thickness:n({[$e.lg]:{min:2.85*m,max:3*m},[$e.md]:{min:2.25*m,max:3.65*m},default:{min:2.25*m,max:4.25*m}})});let p=J.weightedChoice([1,J.int(0,1)],[1,J.int(2,10)]),g=n({[$e.sm]:J.int(4,4),[$e.md]:J.int(4,4),[$e.lg]:J.int(4,4),default:2});He=ge(He,{margin:g*ze.scale,HVariance:{min:-p,max:p,threshold:1,mean:1,stdDev:1},VVariance:{min:-p,max:p,threshold:1,mean:1,stdDev:1},circles:{count:5,minRadius:5,maxRadius:18},wobble:{enabled:!0,count:1e10,minLength:2,layers:4,multiLayers:1,gridDivisions:1,warpFreq:{min:800,max:2e3},offsetMultiplier:.6},perspectiveBox:{enabled:!0,threshold:4,mean:2,stdDev:8,firstFull:!0,count:1}}),Be={...Be,cropToMargin:!1,margin:6*ze.scale}},ct=()=>{_e="Sparse",qe(20,20);let e=lt(0,J.weightedChoice([1,$e.sm],[1,$e.md],[1,$e.lg]));J.weightedChoice([1,tt.heavy]);let t=J.weightedChoice([e({[$e.sm]:1,default:1}),it.objects],[e({[$e.sm]:0,default:2}),it.curves],[e({[$e.sm]:0,default:1}),it.angles],[e({[$e.sm]:0,default:1}),it.grid]),n=at()[t];n.splits[be.circle]=3,Fe=ge(Fe,n.splits),Te=ge(Te,n.meta.forceSplit),Qe=ge(Qe,{noiseOverfittingSpread:e({[$e.sm]:J.num(0,1),default:J.num(0,1)}),noiseOverfitFreq:1200,polyOverfitting:J.num(.5,1.5)}),Ee=e({default:n.meta?.usedLineReplayChance||4}),je=J.int(200,800),Ae=.1;let i=J.weightedChoice([1,!1],[1,!0]);Oe={...Oe,mutation:J.weightedChoice([0,"offsetUp"],[0,"offsetDown"],[3,"none"]),useNoiseLookup:!0,samplesForComplimentary:J.int(1,2),samplesForPaletteOffset:1,singleAccent:!1,freqMultiplier:e({default:i?J.num(600,1e3):J.num(100,200)}),usePolyIDColorOffset:i,maxAccents:e({default:J.weightedChoice([0,4],[1,6],[2,100])}),darksOnly:!1};let l=lt(0,J.weightedChoice([e({[$e.lg]:1,default:1}),nt.dark]));Je={...Je,count:0},Ne=[be.horizontal,be.vertical],Ke={...Ke,default:1,clamp:.05,min:.9,max:1.1,influencesBrightnessMult:1,influencesMinDistanceMult:0,influencesPressureMult:0},Ue={...Ue,maxWidth:.75*e({[$e.sm]:J.int(40,50),[$e.md]:J.int(40,50),default:J.num(35,45)}),renderLightChance:100,maxPointUse:J.int(1,2),maxDivergence:J.int(2,4),pointsToConsider:10};let a=J.num(.75,1.5);ke=ge({...ke,layers:2,layerScaleMult:2.5,zDepthMaxMult:J.int(1,2),cropTo:e({default:J.choice([xe.scene,xe.border,xe.none])}),forceYUp:!0,clampVertsToGrid:e({[$e.sm]:!1,default:!1}),...e({[$e.sm]:{maxDist:200*a,minDist:130*a},[$e.md]:{maxDist:150*a,minDist:100*a},[$e.lg]:J.weightedChoice([5,{maxDist:150*a,minDist:100*a}])}),bnFreq:J.num(10,1e3),fieldFreq:e({[$e.lg]:J.int(4e3,1e4),[$e.sm]:J.int(1e3,2e3),default:J.choice([J.int(1e3,4e3),J.int(4e3,1e4)])}),clampRotationTo:J.weightedChoice([1,22.5],[4,1],[1,11.25]),minSizeMult:1,maxSizeMult:e({default:.75}),maxSides:5,minSides:3,perspective:2e4},n.meta?.objectProps||{}),Ie=ge(Ie,{});let s={edgeSharpness:{min:0,max:0},fillChance:90,insetChance:10,wobbleFreq:{min:30,max:60},wobbleAmplitude:{min:3,max:8},accumulationStrength:{min:10,max:10},materialHardness:{min:.4,max:.45},linePressure:{min:1.3,max:1.3},lineWeight:je<300?{min:1.9,max:2}:{min:1.6,max:1.7},minDistanceMult:{min:.45,max:.5},lineTapering:{scale:{in:{enabledChance:0,min:.1,max:.2},out:{enabledChance:0,min:1.5,max:2}},fade:{in:{enabledChance:0,min:0,max:0},out:{enabledChance:100,min:3,max:8}}},layerCountChances:[[1,3]],layerOverride:[{fadeAtLineSegmentChance:0,scribbleChance:10,scribbleStrength:{min:.2,max:.4},styleChances:[[1,"bnnoise"],[1,"directional"],[0,"edgefill"],[1,"bluenoise"]],colorMap:"none"===Oe.mutation&&J.bool(50)?[[[100,ye.offsetUp],[1,ye.color]]]:[[[100,ye.color],[1,ye.offsetUp]]]},{fadeAtLineSegmentChance:0,styleChances:[[2,"bnnoise"],[2,"directional"],[0,"edgefill"],[1,"bluenoise"]],colorMap:[[[100,ye.previous]]]},{styleChances:[[1,"bnnoise"]],colorMap:[[[1,ye.brightnessBasedShadowOrHighlight]]]}]};Pe=ge(Pe,{ignoreLightingChance:0,spatialOverride:{[Ge.nonDominant]:s,[Ge.overlay]:{lineWeight:{min:1.6,max:1.7},materialHardness:{min:.6,max:.75},minDistanceMult:{min:1,max:1},layerCountChances:[[1,2]],linePressure:{min:.99,max:.99},layerOverride:[{styleChances:[[1,"bnnoise"]],colorMap:[[[1,ye.lightest]]],fadeAtLineSegmentChance:0,scribbleChance:0},{fadeAtLineSegmentChance:0,styleChances:[[1,"bnnoise"]],colorMap:[[[1,ye.lightest],[1,ye.darkest]]],wobbleAmplitude:{min:6,max:8},wobbleFreq:{min:60,max:90}}]},[Ge.dominant]:ge(s,{fillChance:100,lineTapering:{fade:{in:{enabledChance:0,min:1,max:1},out:{enabledChance:50,min:6,max:8}}},insetChance:20,insetDistance:{min:6,max:12}})}}),Ye=ge(Ye,{insetChance:50,fillChance:50,detailMinScaleDivisor:10,insetDistance:{min:4,max:12},wobbleAmplitude:{min:2,max:4},wobbleFreq:{min:55,max:200},fadeAtLineSegmentChance:0,layerCountChances:[[1,2],[1,1]],colorMap:[[[1,ye.line]]],lineTapering:{fade:{out:{enabledChance:50,min:1,max:2}},scale:{in:{enabledChance:100,min:.01,max:.2},out:{enabledChance:100,min:.01,max:.2}}},linePressure:{min:.8,max:1},materialHardness:{min:.65,max:.82},lineWeight:{min:1.25,max:1.5},ignoreLightingChance:100,styleChances:[[6,"bnnoise"],[6,"directional"],[1,"wobbles"],[1,"bluenoise"]],minDistanceMult:{min:4,max:8}}),Re=ge(Re,{count:0,warpChance:100,length:{min:100,max:200},thickness:{min:1,max:1.5}});let o=e({[$e.sm]:J.int(95,100),[$e.lg]:J.int(65,90),default:J.int(70,100)});Me=ge(Me,{meshInsetMuliplier:0,lineFilter:"none",meshDensity:o,skipLongest:0,percentage:100,cropToDominantShape:!1,colors:l({default:!1}),backgroundColor:l({default:!1}),linePressure:{min:1.1,max:1.4},materialHardness:{min:.75,max:.82},lineTapering:{fade:{in:{enabledChance:0,min:0,max:1},out:{enabledChance:0,min:1,max:2}},scale:{in:{enabledChance:100,min:.1,max:.5},out:{enabledChance:100,min:.1,max:.5}}},thickness:e({default:je<600?{min:2,max:2.5}:{min:1.5,max:2}})});let r=J.weightedChoice([1,J.int(0,1)],[1,J.int(2,10)]),c=e({[$e.sm]:J.int(4,4),[$e.md]:J.int(4,4),[$e.lg]:J.int(4,4),default:2});He=ge(He,{margin:c*ze.scale,HVariance:{min:-r,max:r,threshold:1,mean:1,stdDev:1},VVariance:{min:-r,max:r,threshold:1,mean:1,stdDev:1},circles:{count:5,minRadius:5,maxRadius:18},wobble:{enabled:!0,count:1e10,minLength:2,layers:4,multiLayers:1,gridDivisions:1,warpFreq:{min:800,max:2e3},offsetMultiplier:.6},perspectiveBox:{enabled:!0,threshold:4,mean:2,stdDev:8,firstFull:!0,count:1}}),Be={...Be,cropToMargin:!1,margin:6*ze.scale}},dt=()=>{qe(20,20),_e="Outlines";let e=at();Fe={[be.horizontal]:3,[be.vertical]:4,[be.perspective]:5,[be.circle]:1,[be.wobbles]:3,[be.objects]:1,[be.curves]:0,[be.rects]:0,[be.borderRect]:0};let t=e[J.weightedChoice([1,it.objects],[1,it.curves],[1,it.angles],[1,it.grid])];J.bool(50)&&(Fe=ge(Fe,t.splits)),Fe[be.curves]=0,Ee=1,je=J.int(2e3,6e3),Qe=ge(Qe,{noiseOverfittingSpread:J.num(0,5),noiseOverfitFreq:J.int(200,1200),polyOverfitting:J.num(.5,2),longestSplitOnlyChance:0}),Ae=0,He=ge(He,{margin:4*ze.scale}),Be={...Be,cropToMargin:!1,margin:4*ze.scale},Re=ge(Re,{count:0,isLineColor:!0}),Ue={...Ue,layers:1,renderLightChance:0,renderAccentChance:0,insetMult:2,maxWidth:80,spread:4,widthRange:.3,maxDivergence:2,tension:{min:.9,max:1.2},maxPointUse:1,pointsToConsider:30,maxLinePoints:30},ke={...ke,layers:1,clampVertsToGrid:!0,maxDist:100,minDist:50,bnFreq:100,clampRotationTo:1,minSizeMult:1,maxSizeMult:1.25,maxSides:5,minSides:3,perspective:1900},Je={...Je,count:0},Ke={...Ke,default:1,clamp:.05,min:.99,max:1},Oe={...Oe,samplesForComplimentary:1,singleAccent:!1,freqMultiplier:1,usePolyIDColorOffset:!0,maxAccents:100,darksOnly:!1};let n=J.bool(50),i=!n&&J.bool(50);Ue={...Ue,maxWidth:J.num(30,40),renderLightChance:J.weightedChoice([1,0],[1,J.int(10,30)]),maxPointUse:J.int(2,3),maxDivergence:J.int(2,3),pointsToConsider:J.int(5,10)};let l=J.num(.75,.85),a=J.num(.75,1);Me=ge(Me,{meshDensity:J.int(60,90),percentage:J.int(40,60),cropToDominantShape:!1,skipLongest:1,colors:!1,backgroundColor:!1,linePressure:{min:l,max:l+.1},materialHardness:{min:1.05,max:1.2},thickness:{min:1*a,max:2*a}}),Ye=ge(Ye,{fillChance:J.int(40,60),fadeAtLineSegmentChance:0,colorMap:[[[1,ye.line]]],minDistanceMult:{min:2,max:4},styleChances:[[1,"bnnoise"],[1,"directional"],[0,"wobbles"],[0,"bluenoise"]],spatialOverride:{[Ge.dominant]:{linePressure:{min:l-.1,max:l-.05}},[Ge.nonDominant]:{fillChance:n?50:100,linePressure:n?{min:l-.1,max:l-.05}:{min:.4,max:.5},minDistanceMult:i?{min:.5,max:1}:{min:2,max:4},styleChances:i?[[0,"bnnoise"],[0,"directional"],[0,"wobbles"],[1,"bluenoise"]]:[[1,"bnnoise"],[1,"directional"],[0,"wobbles"],[0,"bluenoise"]]}}}),Pe=ge(Pe,{fillChance:n?100:0,linePressure:{min:l,max:l+.1},fadeAtLineSegmentChance:0,ignoreLightingChance:100,lineWeight:{min:1.3,max:1.3},lineTapering:{fade:{in:{enabledChance:0,min:0,max:1},out:{enabledChance:0,min:1,max:2}},scale:{in:{enabledChance:10,min:.
import*as e from"three";const{floor:t,ceil:n,sin:i,cos:l,pow:a,abs:s,min:o,max:r,round:c,sqrt:d,acos:u,sign:h,log:m,random:p,PI:g}=Math,b=1e-7;function f(e,n=b){return t(e+n)}function x(e,t=b){return n(e-t)}function Z(e,t=b){const n=t*h(e);return c(e+n)}let y,G,W="#fff";const v=e=>{e.showUpdate?(!G&&(()=>{y=document.createElement("div"),y.id="loading";const e=y.style;e.position="absolute",e.fontSize="1vmax",e.top=e.left="0",e.width="100%",e.height="100%",e.zIndex="1000",G=document.createElement("div");const t=G.style;t.textTransform="uppercase",t.position="fixed",t.lineHeight="0",t.top=t.left="0",t.width="100vw",t.height="100vh",t.height="fill-available",t.display="flex",t.justifyContent=t.alignItems="center",t.flexDirection="column",t.color=W,t.fontFamily="system-ui",t.fontWeight="500",y.appendChild(G),document.body.appendChild(y)})(),G.innerHTML=(e=>{const{message:t="",value:n=0,isPercent:i=!1}=e;let l=`<p>${t}</p>`,a="";return a=i?`<div style="max-width: 15vmin; margin-top: 1.25em; width: 100%; border: .5px solid ${W}"><div style="width: ${e.value||0}%; height: .75vmin; background-color: ${W}; overflow: hidden;"></div>`:`<p style="margin-top: 1.5em">${n}</p>`,""+(l+a)})(e)):G&&L()},L=()=>{let e=document.getElementById("loading");e&&document.body.removeChild(e),G=null};let S,X,C,V,w,K,R=()=>{S.style.display="none"},k=()=>{S.style.display="block"};const T=performance.now.bind(performance);let M,z,Y,P,I=null,H=()=>{M.style.display="none"},F=.72;const N=r(window.devicePixelRatio,2);let U,D,O,B,Q,J,j=0;class A{useA;prngA;prngB;hash;constructor(e){this.useA=!1,this.hash=e;const t=globalThis.parseInt;let n=function(e){let n=t(e.substring(0,8),16),i=t(e.substring(8,16),16),l=t(e.substring(16,24),16),a=t(e.substring(24,32),16);return function(){n|=0,i|=0,l|=0,a|=0;let e=(n+i|0)+a|0;return a=a+1|0,n=i^i>>>9,i=l+(l<<3)|0,l=l<<21|l>>>11,l=l+e|0,(e>>>0)/4294967296}};this.prngA=n(this.hash.substring(2,34)),this.prngB=n(this.hash.substring(34,66))}dec(){return this.useA=!this.useA,this.useA?this.prngA():this.prngB()}num(e,t){return e+(t-e)*this.dec()}int(e,n){return t(this.num(e,n+1))}bool(e=50){return this.dec()<e/100}choice(e){return e[this.int(0,e.length-1)]}easedDec(e){return e(this.dec())}easedInt(e,n,i){return t(this.easedNum(e,n,i))}easedNum(e,t,n){return t+(n-t)*this.easedDec(e)}weightedChoice(...e){const t=e.reduce(((e,[t])=>e+t),0);let n=this.dec()*t;for(const[t,i]of e)if((n-=t)<0)return i;return e[e.length-1][1]}gaussian(e=0,t=1){let n=0,i=0;for(;0===n;)n=this.dec();for(;0===i;)i=this.dec();return d(-2*m(n))*l(2*g*i)*t+e}gaussianBool(e=0,t=0,n=1){return this.gaussian(t,n)>=e}}function E(e=J){let t="0x";for(let n=0;n<64;n++)t+=Math.floor(16*e.dec()).toString(16);return t}let _,q=["0x79e4e7366d15206ce9f686aad9342df4022aae566689ccdd2616fef8eadf24fd","0xabb30680bfbc30d14af1884dc0078b201e00b9e56d79cf689a9b6c2466c9e7ce","0x6bfa2a5aa8879e7141f848ea3d18a43e5f808593890558a7ef5ee2c3f1f11047","0x2b6c8f8e2d35251cc72888786ac8592ab90c42ac4267c8c425326d87017bc345","0x9a74fc0b090bc985b238194988b07f5d14a866009c28f307703e20a1615f46fd","0xd50240d082091aa1290ff47dc8017677d42a5c42662d80c422745c1765598511","0x5f24d9d9c800b6e19b8ea9115514e59de6d0223b59bd7761e0abb28c1ddcf33f","0xfdad5657593d5aa53e307ea3fa4ca0b4b583a4819c11237e774a797788769d6b","0x25235c1d1ca4a672b1b5cefbd5bb734b27c66588fd5b9d891f4b8168a4661508","0x35cbb692c9572a3f83652fc351c11fd47a4bf86a39a3b5c1f66eb9548786f40f","0x62bacaa70cb1fd2f33f82cd56d14f5d59acb484d95d472a8c9ef051ca64a3dc6","0x7e555c7adee354f7998152001f3acb422219bf668bf185437da21cd5a30afb64"];function $(){let e="0x";for(var n=0;n<64;n++)e+=t(16*p()).toString(16);if("undefined"!=typeof tokenData&&tokenData?.tokenId){let e=tokenData.tokenId.slice(-3),t=parseInt(e,10);if(void 0!==q[t])return q[t]}return new URLSearchParams(globalThis.location.search).get("hash")||("undefined"!=typeof tokenData&&tokenData?.hash?tokenData.hash:e)}_=$();let ee="\n vec3 mod289(vec3 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n }\n\n vec2 mod289(vec2 x) {\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n }\n\n vec3 permute(vec3 x) {\n return mod289(((x * 34.0) + 10.0) * x);\n }\n\n // Noise\n float snoise2D(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n\n // Permutations\n i = mod289(i);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));\n\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n float fbm(const vec2 v, const int octaves, float frequency, float amplitude) {\n float total = 0.0;\n float maxAmplitude = 0.0;\n for(int i = 0; i < octaves; i++) {\n total += snoise2D(v * frequency) * amplitude;\n maxAmplitude += amplitude;\n frequency *= 2.0;\n amplitude *= 0.5;\n }\n return total / maxAmplitude;\n }\n\n",te="\n float screenEdgeDist(vec2 uv, const float falloff) {\n vec2 normalizedCoords = gl_FragCoord.xy / resolution;\n\n // Calculate distances to the nearest edges\n float distanceToLeftEdge = normalizedCoords.x;\n float distanceToRightEdge = 1.0 - normalizedCoords.x;\n float distanceToBottomEdge = normalizedCoords.y;\n float distanceToTopEdge = 1.0 - normalizedCoords.y;\n\n // Find the minimum distance to any edge\n float minDistanceToEdge = min(min(distanceToLeftEdge, distanceToRightEdge), min(distanceToBottomEdge, distanceToTopEdge));\n\n float scaledDistance = 1.0 - abs(2.0 * minDistanceToEdge - 1.0);\n\n // Apply customizable falloff\n float falloffEffect = pow(scaledDistance, falloff);\n\n return falloffEffect;\n }\n",ne="\n float randomNonDet(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n }\n",ie="\n out vec2 vUv;\n\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n";const le=e.Vector2;let ae=!1,se={countX:1,countY:1,index:{x:0,y:0}},oe=(e=!1)=>{let t=e?P:Q,i=n((e?Y:B)/se.countX),l=n(t/se.countY);return{width:i,height:l,xOff:se.index.x*i,yOff:se.index.y*l,yOffFlippedY:(se.countY-1-se.index.y)*l}},re=t=>{let n=t.uniforms,{width:i,height:l,xOff:a,yOffFlippedY:s}=oe();n.uTileOffset.value=new e.Vector2(a,s),n.uTileSize.value=new e.Vector2(i,l)},ce=()=>(!ae&&(()=>{ae=!0;let e=new URL(window.location.href),t=e.searchParams.get("tileCount"),n=e.searchParams.get("index");if(t){let e=parseInt(t);se.countX=e,se.countY=e}if(n){let[e,t]=n.split(",").map((e=>parseInt(e)));se.index.x=o(e,se.countX-1),se.index.y=o(t,se.countY-1)}})(),{uTileOffset:{value:new e.Vector2(0,0)},uTileSize:{value:new e.Vector2(B,Q)}});var de=[{name:"Faces",bg:[[.7409,.0057,69.9871]],line:[[.12,0,68]],base:[[.7995,.0104,53.9144]],accent:[[.55,.092,133],[.37,.1,8],[.47,.124,28],[.7,.112,90],[.48,.088,247],[.59,.048,197],[.78,.012,56.581],[.12,0,68],[.52,.12,342],[.71,.068,44],[.44,.04,299],[.21,.004,329],[.7883,.0264,44]],commonPool:!0,solo:!1},{name:"Chalks",bg:[[.6919,.0323,69.9871]],line:[[.1285578041548887,4.7918630361524376e-9,null]],stroke:[[.9104718532196331,.02929501882422003,89.58052190776175]],base:[[.7968,.033,55.4365]],accent:[[.4391005470961144,.053143667197297274,179.45284673806202],[.7430751481851373,.0929,39.83760570859084],[.7703,.0895,64.56344067218811],[.6641410434441858,.15689118437280108,37.13690468980104],[.7559,.0178,222.564179724743]],disabled:!1,commonPool:!0,solo:!1},{name:"Beach",bg:[[.6835,.03883960001602766,67.25848906440592]],stroke:[[.9372288972261885,.020696467664658196,67.57155893750883]],line:[[.23356138751632896,.02729114952576314,246.90070685897228]],base:[[.8371,.0215,57.0279]],accent:[[.2774185198607467,.04318925551193144,167.75274001919718],[.42064998654759594,.03120177133138129,171.32246538045877],[.4311384415174281,.02336516751567073,241.2330314983908],[.6176019379584577,.1270253885540799,74.1805651416355],[.7260022319511451,.09724578337934522,55.06470317899317],[.7582608113288266,.02549172589125699,166.85185191796654],[.8204,.023,61.9891]],commonPool:!0,solo:!1},{name:"Morning Sun In A Dusty Room",bg:[[.25615282357231434,.011591200093299888,338.1519820725431]],line:[[.14287287327771095,.004143654188326715,345.4391631242127],[.8348,.02687,98.479]],stroke:[[.9136637420289497,.02687443532425364,80.24542314462997]],base:[[.7783871111844314,.042589978975680454,25.529877185969667]],accent:[[.2152,.011591200093299888,338.1519820725431],[.4974379254425503,.08269393625659356,333.938678657093],[.6377751669772775,.16624575588870555,29.858240404234152],[.7303722440997971,.14878423535567212,65.78690162717032],[.525648519572251,.044624199378743616,227.89564437801943],[.8348,.02687443532425364,98.4785]],commonPool:!0,solo:!1},{name:"Jazz",stroke:[[.2866006793419412,.021957785534446477,88.03909075711272]],bg:[[.7399,.0328,69.58004864146267]],base:[[.8051,.0372,74.6117]],line:[[.1285578041548887,4.7918630361524376e-9,null]],accent:[[.6315375414148215,.1752,34.478822707810366],[.5221231161993111,.109,231.97797627692054],[.7332,.1701,64.69716240181685],[.6904,.1463,32.65581391676761],[.8075,.0269,54.0471]],disabled:!1,commonPool:!0,solo:!1},{name:"Beige Box",bg:[[.2169,.004109954650405697,264.48855986171543]],line:[[.1921,.004109954650405697,264.48855986171543],[.7094,.004109954650405697,264.48855986171543]],base:[[.7044,.0027,264.3],[.2582,0,264.15]],stroke:[[.6451555150878627,.1324103074498338,351.3679204443482]],accent:[[.2944,0,264.1525],[.6471384357175027,.0950806296946004,146.09535186981566],[.6248985136009452,.08343861458985488,258.09336743754636],[.6419604611344321,.1604756929950665,39.9727943299859],[.6451555150878627,.1324103074498338,351.3679204443482],[.8436835998771347,.14145685075787068,96.14554462682747],[.71866,.13925,63.701],[.6861,.007,63.701]],commonPool:!0,solo:!1},{name:"Master",bg:[[.6936,.0211,82.40092539697929]],line:[[.2507780863015607,.009572580032197206,67.3680640985574]],base:[[.7269,.0162,157.61886984444504]],stroke:[[.9060102804608031,.012170144621286422,23.7150415636807]],accent:[[.6295566765037485,.1211519827044528,67.32018448430034],[.7605,.0195,238.616994352628],[.6174604546514465,.05042117055871639,256.5164449583005],[.4181072443550769,.072,173.90831954879036],[.6627,.1667,37.60803793025025],[.8234,.0071,74.2545],[.7783,.073,8.0298]],commonPool:!0,solo:!1},{name:"New York Autumn",bg:[[.7037,.0281,65.28937708039064]],stroke:[[.8626142182586253,.08537649420452362,82.03909126824601]],line:[[.19548782481388519,.00430705323020645,264.468763979492]],base:[[.7661,.0329,58.25082050504636]],accent:[[.45478156079252346,.039285338382841796,179.22836606186138],[.7553531036330657,.08130837219892006,99.24794847558877],[.5594780208031984,.07916054354499198,245.43994841186026],[.42899728927916636,.04922887943462986,76.52219098535193],[.8309661998821414,.04281039028933322,48.183040275461394],[.7850648916204185,.1273241170717795,79.558262732039],[.8022,.1082,91.79312487991842],[.5727044802833001,.1271825150640351,18.826326398068147],[.5371544884294275,.13634924860871195,21.160585432853736]],commonPool:!0,solo:!1},{name:"The Coast",bg:[[.6974,.0085,76.58691599832048]],stroke:[[.8444869430616695,.08523591444134622,87.01376484878972]],line:[[.22755957415683586,.0015428045966122382,17.270340681712298]],base:[[.7669770002469423,.0030391208463875215,84.56153889362372]],accent:[[.3779357986919375,.0535,176.4086979076003],[.6184542058002529,.0765,130.0878133972343],[.8444869430616695,.0863,87.01376484878972],[.8204404719119529,.0562,13.36293462743373],[.6466292227896673,.1007,248.2503623167608],[.6773,.0488,194.3393064675039],[.6163,.1335,21.160585432853736],[.7968000000000001,.01676,79.345]],commonPool:!0,solo:!1},{name:"Aged",bg:[[.7084,.0396,87.75614537114114]],stroke:[[.94095456060748,.015612821171329101,86.4264441546818]],line:[[.2703834919362128,.003498268640239951,48.59454667339406]],base:[[.7841,.021041287596747362,75.5028]],accent:[[.6599008372479219,.14410614712594896,43.767864491957255],[.5406041428443183,.0810794492722289,156.20612626175443],[.5030711080692698,.15264841257121137,26.608155858968416],[.7691417851736347,.1353050284474489,77.87710240074239],[.7874426063872318,.04659921665479499,51.68182155996902],[.467824859321765,.056096190272488924,217.56676918001241]],commonPool:!0,solo:!1},{name:"Ink & Colour",bg:[[.7601,.014,255.4795978283716]],stroke:[[.9553483843727791,.002877617626355211,84.55913178523588]],line:[[.23724829442832204,.009300030023333045,159.3038618360598]],base:[[.5326,.0294,169.58],[.5352,.1055,153.65],[.7482,.0675,265.537],[.5786,.1009,265.537]],accent:[[.3475,.065,169.58],[.4333,.08067410261737115,292.88016945552295],[.8007868908561364,.0333,7.942656494991638],[.6086666969575215,.1634,28.003190670134757],[.3195,.034575073883449464,254.02069392111645],[.6738,.1201,79.6718],[.8711,.00292,264.54],[.6613,.0632,169.58],[.5352,.1055,153.6549],[.6531,.1061,265.54]],disabled:!1,commonPool:!0,solo:!1},{name:"Oranges",bg:[[.705,.0354,65.1718]],stroke:[[.9912189562526743,.006931254927170287,88.6413010074412]],base:[[.7842,.0305,86.3684]],line:[[.18797280274608968,.026745997001574016,159.25756384014687]],accent:[[.35508002090426666,.043787467826530785,211.52484726500788],[.5510005837793092,.08755866639046411,103.27386758796968],[.691,.1582,47.266522185041936],[.7373,.1324,67.62887023877073],[.7999,.0316,88.72052641225343],[.7631,.0647,19.8072]],commonPool:!0,solo:!1},{name:"Henri",bg:[[.7213,.0319,80.6824944352112]],stroke:[[.7121124312829297,.09603422725607345,34.15613531599104]],line:[[.24303319779115856,.004923290798673418,355.16568727574077]],base:[[.8256,.0305,76.17859369988122]],accent:[[.4159,.0591,191.39940656052516],[.7920378039704564,.1352,73.45878915862028],[.7593,.0165,220.7288245953125],[.4637,.0738,237.7123227684075]],disabled:!1,commonPool:!0,solo:!1},{name:"Rand-ey",bg:[[.7426,.0171,87.52315695161104]],line:[[.19419793765469762,.0219,297.0814230776026]],stroke:[[.9076072420048279,.019870599528847212,87.51855970858247]],base:[[.595,.0433,247.9],[.7126,.0966,68.946],[.7791,0,64.059],[.5968,.1097,151.59]],accent:[[.575943267748716,.1486,29.4685],[.5129975835116938,.0741,305.527422000483],[.7538026010313094,.139,68.94572099685297],[.6147,.1332,247.9],[.8423,0,64.0592],[.53766,.1084,167.07]],disabled:!0,commonPool:!0,solo:!1},{name:"Olivetti",bg:[[.2222,.004109954650405697,264.48855986171543]],line:[[.234784254171478,.004109954650405697,264.48855986171543]],stroke:[[.7186588335782654,.1392507657144271,63.7012930132442]],base:[[.2551,0,34.30274488067005]],accent:[[.7186588335782654,.1392507657144271,63.7012930132442],[.6471384357175027,.0950806296946004,146.09535186981566],[.6248985136009452,.08343861458985488,258.09336743754636],[.6419604611344321,.1604756929950665,39.9727943299859],[.6451555150878627,.1324103074498338,351.3679204443482],[.8373623117765204,.15785248852128372,95.6270196002983],[.2582,.0037,275.8924],[.5803,.0037,275.8924]],disabled:!0,commonPool:!0,solo:!1},{name:"Toddler",bg:[[.7421,.0212,48.4352]],line:[[.18797280274608968,.026745997001574016,159.25756384014687]],stroke:[[.18797280274608968,.026745997001574016,159.25756384014687]],base:[[.6859848282821445,.008266766434931419,61.396302349703944],[.9349265127013049,.01153735356888476,84.57925253447382],[.7688,.0216,61.396302349703944]],accent:[[.3500879126177943,.0865,264.1433132212142],[.4453610930960556,.02928835497819446,336.8043193096847],[.569281111283594,.1860449489679648,25.02687693308303],[.5558543866168449,.054963958871380815,108.06205545681729],[.7052281079548163,.16337391917830385,43.93536507302679],[.8036,.1343,80.58696151433355],[.6763,.0745,108.06205545681729],[.7615,.0782,25.02687693308303]],disabled:!1,commonPool:!0,solo:!1}];let ue=(de.some((e=>e.solo))?de.filter((e=>e.solo)):de.filter((e=>!e.disabled))).map((e=>({name:e.name,disabled:e.disabled,commonPool:e.commonPool,base:e.base,bg:e.bg,line:e.line,accent:e.accent}))),he=de.filter((e=>e.commonPool)).map((e=>({name:e.name,disabled:e.disabled,commonPool:e.commonPool,base:e.base,bg:e.bg,line:e.line,accent:e.accent})));function me(e){return e*g/180}function pe(e){return function(e){return null!==e&&"object"==typeof e}(e)&&!Array.isArray(e)}function ge(...e){const t={};for(const n of e)if(n)for(const e of Object.keys(n)){const i=n[e];if(Array.isArray(i))t[e]=[...i];else if(pe(i)){const n=t[e];pe(n)?t[e]=ge(n,i):t[e]=ge({},i)}else t[e]=i}return t}var be,fe,xe;!function(e){e[e.horizontal=0]="horizontal",e[e.vertical=1]="vertical",e[e.perspective=2]="perspective",e[e.circle=3]="circle",e[e.wobbles=4]="wobbles",e[e.curves=5]="curves",e[e.rects=6]="rects",e[e.borderRect=7]="borderRect",e[e.triangle=8]="triangle",e[e.objects=9]="objects",e[e.used=10]="used"}(be||(be={})),function(e){e[e.front=0]="front",e[e.up=1]="up",e[e.right=2]="right",e[e.down=3]="down",e[e.left=4]="left"}(fe||(fe={})),function(e){e.border="border",e.scene="scene",e.none="none"}(xe||(xe={}));let Ze={layers:2,layerScaleMult:2.5,zDepthMaxMult:1,cropTo:xe.none,forceYUp:!0,clampVertsToGrid:!0,maxDist:200,minDist:130,bnFreq:500,fieldFreq:1500,clampRotationTo:1,minSizeMult:1,maxSizeMult:.75,maxSides:5,minSides:3,perspective:2e4};var ye,Ge;!function(e){e[e.color=0]="color",e[e.line=1]="line",e[e.palettecomplement=2]="palettecomplement",e[e.previous=3]="previous",e[e.base=4]="base",e[e.paletteOffset=5]="paletteOffset",e[e.shadow=6]="shadow",e[e.highlight=7]="highlight",e[e.randomAccent=8]="randomAccent",e[e.offset=9]="offset",e[e.offsetUp=10]="offsetUp",e[e.lightestOrDarkestBasedOnBg=11]="lightestOrDarkestBasedOnBg",e[e.brightnessBasedShadowOrHighlight=12]="brightnessBasedShadowOrHighlight",e[e.offsetDown=13]="offsetDown",e[e.darkest=14]="darkest",e[e.lightest=15]="lightest"}(ye||(ye={})),function(e){e.override="override",e.dominant="dominant",e.inCurveOrObject="inCurveOrObject",e.notInCurveOrObject="notInCurveOrObject",e.nonDominant="nonDominant",e.normalHigh="normalHigh",e.normalLow="normalLow",e.overlay="overlay",e.noop="noop"}(Ge||(Ge={}));let We,ve,Le={scribbleChance:0,edgeSharpness:{min:.2,max:.2},scribbleStrength:{min:.5,max:.5},accumulationStrength:{min:1,max:1},materialHardness:{min:1,max:1},fillChance:100,fadeAtLineSegmentDistanceMult:{min:.5,max:1.5},fadeAtLineSegmentStrengthMult:{min:1,max:1},minDistanceMult:{min:5,max:5},linePressure:{min:.8,max:.9},brightnessHighLowThreshold:.75,fadeAtLineSegmentChance:0,detailMinScaleDivisor:30,ignoreLightingChance:0,colorMap:[[[1,ye.color]],[[1,ye.color]]],dominantMeshWeight:100,insetChance:0,insetDistance:{min:2,max:4},wobbleAmplitude:{min:.5,max:1},wobbleFreq:{min:.5,max:1},layerCountChances:[[0,0],[1,1],[2,2]],styleChances:[[3,"noise"],[4,"directional"],[1,"wobbles"],[3,"bluenoise"]],lineTapering:{scale:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:1,max:1}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},lineWeight:{min:1.1,max:1.1},spatialOverride:{[Ge.overlay]:{fillChance:0}}},Se={scribbleChance:0,edgeSharpness:{min:.5,max:.5},scribbleStrength:{min:.3,max:.3},fillChance:100,accumulationStrength:{min:1,max:1},fadeAtLineSegmentDistanceMult:{min:.5,max:1.5},fadeAtLineSegmentStrengthMult:{min:1,max:1},colorMap:[[[1,ye.color]]],fadeAtLineSegmentChance:100,brightnessHighLowThreshold:.75,ignoreLightingChance:0,detailMinScaleDivisor:30,minDistanceMult:{min:.75,max:.75},dominantMeshWeight:100,insetChance:0,insetDistance:{min:2,max:4},wobbleAmplitude:{min:2,max:3},wobbleFreq:{min:20,max:40},layerCountChances:[[1,1]],styleChances:[[1,"noise"],[0,"directional"],[0,"wobbles"],[0,"bluenoise"]],lineTapering:{scale:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:1,max:1}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},linePressure:{min:1,max:1},materialHardness:{min:1,max:1},lineWeight:{min:1.1,max:1.1},spatialOverride:{[Ge.overlay]:{fillChance:100,lineWeight:{min:2.5,max:2.5},fadeAtLineSegmentChance:0,insetChance:0,ignoreLightingChance:100,styleChances:[[1,"noise"],[0,"directional"],[0,"wobbles"],[0,"bluenoise"]],minDistanceMult:{min:.75,max:.75},lineTapering:{scale:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:1,max:1}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},layerCountChances:[[1,2]]}}},Xe={[be.horizontal]:0,[be.vertical]:10,[be.perspective]:0,[be.circle]:10,[be.wobbles]:0,[be.objects]:8,[be.curves]:10,[be.rects]:5,[be.borderRect]:10},Ce=[be.horizontal,be.vertical,be.perspective],Ve={count:1,outline:!0,colors:[[0,ye.color],[0,ye.offset],[0,ye.base],[0,ye.line],[0,ye.darkest],[1,ye.lightest]],colorOffsets:!1,size:{min:4,max:9}},we=[],Ke={default:1,min:.45,max:1.12,clamp:.001,influencesPressureMult:0,influencesBrightnessMult:1,influencesMinDistanceMult:.3,position:{x:-10005.5,y:-1e4,z:-12e3}},Re={colors:!1,isLineColor:!1,count:50,warpChance:100,lineTapering:{scale:{in:{enabledChance:100,min:.5,max:.8},out:{enabledChance:100,min:.5,max:.8}},fade:{in:{enabledChance:0,min:.5,max:.8},out:{enabledChance:0,min:.5,max:.8}}},length:{min:20,max:100},hardness:{min:1,max:1},thickness:{min:.5,max:5}},ke=Ze,Te={forceInsertCurvesChance:0,forceInsertObjectsChance:0},Me={meshDensity:80,lineFilter:"none",meshInsetMuliplier:1,dominantLineInsetMultiplier:1,percentage:50,skipLongest:3,cropToDominantShape:!1,materialHardness:{min:.9,max:.95},colors:!1,backgroundColor:!1,lineTapering:{scale:{in:{enabledChance:100,min:.3,max:.6},out:{enabledChance:100,min:.3,max:.6}},fade:{in:{enabledChance:50,min:.1,max:.2},out:{enabledChance:50,min:.1,max:.2}}},linePressure:{min:.9,max:.95},thickness:{min:.5,max:3}},ze={countX:0,countY:0,marginX:0,marginY:0,w:0,h:0,scale:0},Ye=Le,Pe=Se,Ie={enabled:!0,percentage:60,materialHardness:{min:.4,max:.4},lineTapering:{scale:{in:{enabledChance:100,min:.01,max:.1},out:{enabledChance:100,min:.01,max:.1}},fade:{in:{enabledChance:100,min:.01,max:.1},out:{enabledChance:100,min:.01,max:.1}}},linePressure:{min:.5,max:.5},lineWeight:{min:.6,max:.6}},He={margin:0,HVariance:{min:0,max:10,threshold:2,mean:1,s
Materialistic is a generative series of 92 works exploring surface, texture, and the boundaries of digital materiality. The project draws a parallel between Cubism and early computer graphics, as both use simplified forms and structured systems to reinterpret reality. Deconstruction and reconstruction are at the core of this project. Each composition begins with precise construction lines and multiple viewpoints, then is reassembled algorithmically into geometric structures and fragmented planes. The interplay of movement, surface, and texture is directly created through the code. This contract represents the 12 artist curated edition mints from the release. The associated physicals can be claimed via The Disruptive Gallery.
Materialistic is a generative series of 92 works exploring surface, texture, and the boundaries of digital materiality. The project draws a parallel between Cubism and early computer graphics, as both use simplified forms and structured systems to reinterpret reality. Deconstruction and reconstruction are at the core of this project. Each composition begins with precise construction lines and multiple viewpoints, then is reassembled algorithmically into geometric structures and fragmented planes. The interplay of movement, surface, and texture is directly created through the code. This contract represents the 80 long-form digital edition mints from the release.
,bt);z("Lavender",Mt);z("GreenInThe trees",Lt);z("bleuets1new",St);z("Blue Autumn 2",yt);z("Summer classic b",mt);z("Spring classic2",At);z("redBlueDark4b",vt);z("Impressionnist4b2",xt);z("pinkSakuraEtcB",Pt);z("Pink2",Tt);z("Autumn new pale",_t);z("Autumn gold 2c",pt);z("blueblue2",wt);z("garden2",Ct);z("bleuetsnew",Dt);const fe={skipPattern:!1,color:"hsl( 125, 50%, 50% )",countLines:1e6,alpha:.4,lengthA:20,rotationType:0};class Sa{constructor(){this._isFirst=!0,this.isNewHash=!1}generate(){if(console.log(`[${a.id}] Generating params...`),this._idx=-1,this.isNewHash||this._isFirst){const e=[2,2,4,8];let t=e[a.rand()*e.length>>0];c.compositionsData.divider=t;const s=a.rand()*ye.length>>0;c.paletteData.palette=s,a.palettes=[s];const i=Array.from({length:ye.length},(n,l)=>l).filter(n=>n!==s);for(let n=0;n<3;n++){const l=Math.floor(a.rand()*i.length);a.palettes.push(i[l]),i.splice(l,1)}a.idxPalette=0,t<8&&(c.gridPatternData.linesGridAlpha=.7),this.isBroken=!0,this.isBrokenVerticaly=!0,this.isExtraBrokenVerticaly=!1,t<=4?t==4?(this.isBroken=a.rand()<.5,this.isBrokenVerticaly=a.rand()<.25):t==2&&(this.isBroken=a.rand()<.5,this.isBrokenVerticaly=a.rand()<.25):(this.isBroken=a.rand()<.8,this.isBrokenVerticaly=a.rand()<.5,this.isExtraBrokenVerticaly=a.rand()<.25,!this.isBroken&&this.isBrokenVerticaly&&this.isExtraBrokenVerticaly&&(this.isBroken=!0)),this.isSmallTrees=!1}(this._isFirst||this.divider!==c.compositionsData.divider)&&(this.divider=c.compositionsData.divider,this.divider==4?(c.gridData.divisions.chance=.96,c.gridData.divisions.friction=.93,c.gridData.divisions.maxDivisions=6):this.divider==2?(c.gridData.divisions.chance=.98,c.gridData.divisions.friction=.95,c.gridData.divisions.maxDivisions=7):this.divider==8&&(c.gridData.divisions.chance=.83,c.gridData.divisions.friction=.89,c.gridData.divisions.maxDivisions=5),this.isBroken=a.rand()<.5,this.isBroken=!0),this._isFirst=!1,this.isNewHash=!1,this.refreshLayers()}refreshLayers(){this.layers=[];const e=c.compositionsData.layers;this.layers.push(this._createLayer(e.background));for(let s=0;s<5;s++)this.layers.push(this._createLayer(e[`greenLayer${s+1}`]));const t=this._createTreesLayer();c.compositionsData.putTreesBefore?this.layers.splice(this.layers.length-1,0,t):this.layers.push(t),this.layers.push(this._createLayer(e.windLayer));for(let s=0;s<4;s++)s==2&&this.layers.push(this._createFlowersLayer()),this.layers.push(this._createLayer(e[`flowerLayer${s+1}`]));this.layers.push(this._createLayer(e.blueWindLayer)),this.layers.push(this._createLayer(e.greenFlowerLayer)),this.layers.push(this._createLayer(e.bonusLayer))}_createLayer(e){let t={};for(const s in e.params)t[s]=e.params[s].value;if(t.type="vege",t.id=++this._idx,t.patternId="classic",t={...fe,...t},e.noise){t.noise={};for(const s in e.noise.params)t.noise[s]=e.noise.params[s].value}return t}_createTreesLayer(){let e={};return e.id=++this._idx,e={...fe,...e},e.patternId="tree",e.skipPattern=!1,e}_createFlowersLayer(){let e={};return e.id=++this._idx,e={...fe,...e},e.patternId="flowers",e.skipPattern=!1,e}_createGridLayer(){let e={};return e.id=++this._idx,e={...fe,...e},e.patternId="grid",e.skipPattern=!1,e}}function Da(){const r=document.createElement("div");r.className="ryokans-menu",r.style.display="none";const e=document.createElement("style");e.innerHTML=` .ryokans-menu-action-button { width: 60px; height: 60px; border: 1px solid #fff; color: #fff; background: transparent; display: flex; align-items: center; justify-content: center; font-size: 0.5em; cursor: pointer; margin: 5px; transition: background 0.2s, color 0.2s; text-align: center; opacity: .35; background: rgba(0,0,0,0.8); } .ryokans-menu-action-button:hover { background: rgba(255,255,255,0.1); } `,document.head.appendChild(e);const t=new URLSearchParams(window.location.search),s=t.get("fullscreen")==="true",i=t.get("dpr")||"0.5",n=[s?{label:"Centered",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fullscreen","false"),window.location.href=u.toString()}}:{label:"Fullscreen",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fullscreen","true"),window.location.href=u.toString()}},i==="1"?{label:"LD",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("dpr","0.5"),window.location.href=u.toString()}}:{label:"HD",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("dpr","1"),window.location.href=u.toString()}},t.get("fixed")==="true"?{label:"Animated",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fixed","false"),window.location.href=u.toString()}}:{label:"Fixed",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fixed","true"),window.location.href=u.toString()}}];n.push({label:"Save",onClick:()=>{zt(a.gl.canvas)}}),document.body.appendChild(r),n.forEach(({label:u,onClick:f})=>{const g=document.createElement("button");g.className="ryokans-menu-action-button",g.innerText=u,g.onclick=f,r.appendChild(g)});let l=null;function o(){r.style.display="flex",r.style.justifyContent="center",r.style.alignItems="center",r.style.position="fixed",r.style.left="0",r.style.right="0",r.style.bottom="10px",r.style.top="",r.style.zIndex="1000",l&&clearTimeout(l),l=setTimeout(h,2e3)}function h(){r.style.display="none"}function d(){o()}window.addEventListener("mousemove",d),window.addEventListener("touchstart",d),h()}function Ca(){const r=a.sketch,e=a.generator,t=a.artwork;document.body.style.backgroundColor="#17140b",a.renderStartTime=performance.now(),t.init().then(async function(){r.setBgColor(c.backgroundData.globalBackgroundColor),r.clear(),ht.resetHash(),e.generate(),console.warn("First rand: ",a.rand()),console.warn("First rand 2: ",a.rand2()),c.isDirty=!0,a.seed=a.rand()*1e3,await t.generate(),await t.prerenderAnimated(),a.loader?.update(),Da(),await t.renderMoments(),r.artwork=t.texture,r.renderWebGL({options:c.postprocessData,displayArtwork:t!=null}),a.onRender.dispatch();let s=0;const i=async()=>{await t.regenerateAndRenderGrids(),await t.reRenderAnimated(),s=0,Be.add(n)},n=()=>{s+=1,s%1400===0&&(Be.remove(n),i())};!a.isRender&&!a.isFixed&&Be.add(n)}),Gt.add(()=>{t.renderAnimated(),r.artwork=t.textureAnimated,r.renderWebGL({options:c.postprocessData,displayArtwork:t!=null})})}class Aa{constructor(e,t={}){this.options={color:"#fff",width:"30%",...t},this.steps=7,this.step=1/this.steps,this.progress=0,this.progressRender=.001,this.progressRenderLocal=.001,this._isVisible=!1,this.element=document.createElement("div"),this.element.className="ryokan-loader",this.element.style.width="30%",this.element.style.zIndex="9999",this.element.style.position="absolute",this.element.style.bottom=0,this.element.style.left="50%",this.element.style.transform="translate(-50%, -50%)",this.element.style.backgroundColor="#17140B",this.element.style.padding="20px",this.element.style.border="1px solid #fff",this.barContainer=document.createElement("div"),this.barContainer.className="ryokan-loader-bar-container",this.barContainer.style.height="4px",this.barContainer.style.backgroundColor="#000",this.barContainer.style.opacity=.8,this.barContainer.style.overflow="hidden",this.barContainer.style.position="relative",this.bar=document.createElement("div"),this.bar.className="ryokan-loader-bar",this.bar.style.height="100%",this.bar.style.width="0%",this.bar.style.backgroundColor="#fff",this.bar.style.transition="width 0.3s ease-in-out",this.bar.style.position="absolute",this.bar.style.left="0",this.bar.style.top="0",this.barContainer.appendChild(this.bar),this.element.appendChild(this.barContainer),e&&(typeof e=="string"?document.querySelector(e).appendChild(this.element):e.appendChild(this.element)),this.setProgress(0)}update(){return this.progress+=this.step,this.setProgress(this.progress),this}setProgress(e){const t=Math.max(0,Math.min(1,e));return this.bar.style.width=`${t*100>>0}%`,this}setProgressRender(e){this.progressRender=e}setProgressRenderLocal(e){this.progressRenderLocal=e}getElement(){return this.element}show(){this._isVisible=!0,this.setProgress(0),this.element.style.display="block"}hide(){this._isVisible&&(this._isVisible=!1,this.element.style.display="none")}}ht.start(ls);ft.init(Oe);c.registerGUI(ft);a.data=c;c.init();new Gi(c);const qe=new kr(a.size.width,a.size.height);qe.initWebGL();qe.setBgColor(c.backgroundData.globalBackgroundColor);a.sketch=qe;const Pa=new La;a.artwork=Pa;const Ta=new Sa;a.generator=Ta;function za(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}if(za()){const r=document.createElement("div");r.innerText="Please open this page on a desktop for the full experience.",r.style.position="fixed",r.style.top="50%",r.style.left="50%",r.style.transform="translate(-50%, -50%)",r.style.backgroundColor="rgba(0,0,0,0.85)",r.style.color="#fff",r.style.padding="24px 32px",r.style.fontSize="12px",r.style.textAlign="center",r.style.maxWidth="90vw",document.body.appendChild(r)}else{const r=new Aa(document.body,{color:"#000",height:"10px"});a.loader=r,a.loader.show(),Ca()}
,bt);z("Lavender",Mt);z("GreenInThe trees",Lt);z("bleuets1new",St);z("Blue Autumn 2",yt);z("Summer classic b",mt);z("Spring classic2",At);z("redBlueDark4b",vt);z("Impressionnist4b2",xt);z("pinkSakuraEtcB",Pt);z("Pink2",Tt);z("Autumn new pale",_t);z("Autumn gold 2c",pt);z("blueblue2",wt);z("garden2",Ct);z("bleuetsnew",Dt);const fe={skipPattern:!1,color:"hsl( 125, 50%, 50% )",countLines:1e6,alpha:.4,lengthA:20,rotationType:0};class Sa{constructor(){this._isFirst=!0,this.isNewHash=!1}generate(){if(console.log(`[${a.id}] Generating params...`),this._idx=-1,this.isNewHash||this._isFirst){const e=[2,2,4,8];let t=e[a.rand()*e.length>>0];c.compositionsData.divider=t;const s=a.rand()*ye.length>>0;c.paletteData.palette=s,a.palettes=[s];const i=Array.from({length:ye.length},(n,l)=>l+1).filter(n=>n!==s);for(let n=0;n<3;n++){const l=Math.floor(a.rand()*i.length);a.palettes.push(i[l]),i.splice(l,1)}a.idxPalette=0,t<8&&(c.gridPatternData.linesGridAlpha=.7),this.isBroken=!0,this.isBrokenVerticaly=!0,this.isExtraBrokenVerticaly=!1,t<=4?t==4?(this.isBroken=a.rand()<.5,this.isBrokenVerticaly=a.rand()<.25):t==2&&(this.isBroken=a.rand()<.5,this.isBrokenVerticaly=a.rand()<.25):(this.isBroken=a.rand()<.8,this.isBrokenVerticaly=a.rand()<.5,this.isExtraBrokenVerticaly=a.rand()<.25,!this.isBroken&&this.isBrokenVerticaly&&this.isExtraBrokenVerticaly&&(this.isBroken=!0)),this.isSmallTrees=!1}(this._isFirst||this.divider!==c.compositionsData.divider)&&(this.divider=c.compositionsData.divider,this.divider==4?(c.gridData.divisions.chance=.96,c.gridData.divisions.friction=.93,c.gridData.divisions.maxDivisions=6):this.divider==2?(c.gridData.divisions.chance=.98,c.gridData.divisions.friction=.95,c.gridData.divisions.maxDivisions=7):this.divider==8&&(c.gridData.divisions.chance=.83,c.gridData.divisions.friction=.89,c.gridData.divisions.maxDivisions=5),this.isBroken=a.rand()<.5,this.isBroken=!0),this._isFirst=!1,this.isNewHash=!1,this.refreshLayers()}refreshLayers(){this.layers=[];const e=c.compositionsData.layers;this.layers.push(this._createLayer(e.background));for(let s=0;s<5;s++)this.layers.push(this._createLayer(e[`greenLayer${s+1}`]));const t=this._createTreesLayer();c.compositionsData.putTreesBefore?this.layers.splice(this.layers.length-1,0,t):this.layers.push(t),this.layers.push(this._createLayer(e.windLayer));for(let s=0;s<4;s++)s==2&&this.layers.push(this._createFlowersLayer()),this.layers.push(this._createLayer(e[`flowerLayer${s+1}`]));this.layers.push(this._createLayer(e.blueWindLayer)),this.layers.push(this._createLayer(e.greenFlowerLayer)),this.layers.push(this._createLayer(e.bonusLayer))}_createLayer(e){let t={};for(const s in e.params)t[s]=e.params[s].value;if(t.type="vege",t.id=++this._idx,t.patternId="classic",t={...fe,...t},e.noise){t.noise={};for(const s in e.noise.params)t.noise[s]=e.noise.params[s].value}return t}_createTreesLayer(){let e={};return e.id=++this._idx,e={...fe,...e},e.patternId="tree",e.skipPattern=!1,e}_createFlowersLayer(){let e={};return e.id=++this._idx,e={...fe,...e},e.patternId="flowers",e.skipPattern=!1,e}_createGridLayer(){let e={};return e.id=++this._idx,e={...fe,...e},e.patternId="grid",e.skipPattern=!1,e}}function Da(){const r=document.createElement("div");r.className="ryokans-menu",r.style.display="none";const e=document.createElement("style");e.innerHTML=` .ryokans-menu-action-button { width: 60px; height: 60px; border: 1px solid #fff; color: #fff; background: transparent; display: flex; align-items: center; justify-content: center; font-size: 0.5em; cursor: pointer; margin: 5px; transition: background 0.2s, color 0.2s; text-align: center; opacity: .35; background: rgba(0,0,0,0.8); } .ryokans-menu-action-button:hover { background: rgba(255,255,255,0.1); } `,document.head.appendChild(e);const t=new URLSearchParams(window.location.search),s=t.get("fullscreen")==="true",i=t.get("dpr")||"0.5",n=[s?{label:"Centered",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fullscreen","false"),window.location.href=u.toString()}}:{label:"Fullscreen",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fullscreen","true"),window.location.href=u.toString()}},i==="1"?{label:"LD",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("dpr","0.5"),window.location.href=u.toString()}}:{label:"HD",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("dpr","1"),window.location.href=u.toString()}},t.get("fixed")==="true"?{label:"Animated",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fixed","false"),window.location.href=u.toString()}}:{label:"Fixed",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fixed","true"),window.location.href=u.toString()}}];n.push({label:"Save",onClick:()=>{zt(a.gl.canvas)}}),document.body.appendChild(r),n.forEach(({label:u,onClick:f})=>{const g=document.createElement("button");g.className="ryokans-menu-action-button",g.innerText=u,g.onclick=f,r.appendChild(g)});let l=null;function o(){r.style.display="flex",r.style.justifyContent="center",r.style.alignItems="center",r.style.position="fixed",r.style.left="0",r.style.right="0",r.style.bottom="10px",r.style.top="",r.style.zIndex="1000",l&&clearTimeout(l),l=setTimeout(h,2e3)}function h(){r.style.display="none"}function d(){o()}window.addEventListener("mousemove",d),window.addEventListener("touchstart",d),h()}function Ca(){const r=a.sketch,e=a.generator,t=a.artwork;document.body.style.backgroundColor="#17140b",a.renderStartTime=performance.now(),t.init().then(async function(){r.setBgColor(c.backgroundData.globalBackgroundColor),r.clear(),ht.resetHash(),e.generate(),console.warn("First rand: ",a.rand()),console.warn("First rand 2: ",a.rand2()),c.isDirty=!0,a.seed=a.rand()*1e3,await t.generate(),await t.prerenderAnimated(),a.loader?.update(),Da(),await t.renderMoments(),r.artwork=t.texture,r.renderWebGL({options:c.postprocessData,displayArtwork:t!=null}),a.onRender.dispatch();let s=0;const i=async()=>{await t.regenerateAndRenderGrids(),await t.reRenderAnimated(),s=0,Be.add(n)},n=()=>{s+=1,s%1400===0&&(Be.remove(n),i())};!a.isRender&&!a.isFixed&&Be.add(n)}),Gt.add(()=>{t.renderAnimated(),r.artwork=t.textureAnimated,r.renderWebGL({options:c.postprocessData,displayArtwork:t!=null})})}class Aa{constructor(e,t={}){this.options={color:"#fff",width:"30%",...t},this.steps=7,this.step=1/this.steps,this.progress=0,this.progressRender=.001,this.progressRenderLocal=.001,this._isVisible=!1,this.element=document.createElement("div"),this.element.className="ryokan-loader",this.element.style.width="30%",this.element.style.zIndex="9999",this.element.style.position="absolute",this.element.style.bottom=0,this.element.style.left="50%",this.element.style.transform="translate(-50%, -50%)",this.element.style.backgroundColor="#17140B",this.element.style.padding="20px",this.element.style.border="1px solid #fff",this.barContainer=document.createElement("div"),this.barContainer.className="ryokan-loader-bar-container",this.barContainer.style.height="4px",this.barContainer.style.backgroundColor="#000",this.barContainer.style.opacity=.8,this.barContainer.style.overflow="hidden",this.barContainer.style.position="relative",this.bar=document.createElement("div"),this.bar.className="ryokan-loader-bar",this.bar.style.height="100%",this.bar.style.width="0%",this.bar.style.backgroundColor="#fff",this.bar.style.transition="width 0.3s ease-in-out",this.bar.style.position="absolute",this.bar.style.left="0",this.bar.style.top="0",this.barContainer.appendChild(this.bar),this.element.appendChild(this.barContainer),e&&(typeof e=="string"?document.querySelector(e).appendChild(this.element):e.appendChild(this.element)),this.setProgress(0)}update(){return this.progress+=this.step,this.setProgress(this.progress),this}setProgress(e){const t=Math.max(0,Math.min(1,e));return this.bar.style.width=`${t*100>>0}%`,this}setProgressRender(e){this.progressRender=e}setProgressRenderLocal(e){this.progressRenderLocal=e}getElement(){return this.element}show(){this._isVisible=!0,this.setProgress(0),this.element.style.display="block"}hide(){this._isVisible&&(this._isVisible=!1,this.element.style.display="none")}}ht.start(ls);ft.init(Oe);c.registerGUI(ft);a.data=c;c.init();new Gi(c);const qe=new kr(a.size.width,a.size.height);qe.initWebGL();qe.setBgColor(c.backgroundData.globalBackgroundColor);a.sketch=qe;const Pa=new La;a.artwork=Pa;const Ta=new Sa;a.generator=Ta;function za(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}if(za()){const r=document.createElement("div");r.innerText="Please open this page on a desktop for the full experience.",r.style.position="fixed",r.style.top="50%",r.style.left="50%",r.style.transform="translate(-50%, -50%)",r.style.backgroundColor="rgba(0,0,0,0.85)",r.style.color="#fff",r.style.padding="24px 32px",r.style.fontSize="12px",r.style.textAlign="center",r.style.maxWidth="90vw",document.body.appendChild(r)}else{const r=new Aa(document.body,{color:"#000",height:"10px"});a.loader=r,a.loader.show(),Ca()}
,bt);z("Lavender",Mt);z("GreenInThe trees",Lt);z("bleuets1new",St);z("Blue Autumn 2",yt);z("Summer classic b",mt);z("Spring classic2",At);z("redBlueDark4b",vt);z("Impressionnist4b2",xt);z("pinkSakuraEtcB",Pt);z("Pink2",Tt);z("Autumn new pale",_t);z("Autumn gold 2c",pt);z("blueblue2",wt);z("garden2",Ct);z("bleuetsnew",Dt);const fe={skipPattern:!1,color:"hsl( 125, 50%, 50% )",countLines:1e6,alpha:.4,lengthA:20,rotationType:0};class Sa{constructor(){this._isFirst=!0,this.isNewHash=!1}generate(){if(console.log(`[${a.id}] Generating params...`),this._idx=-1,this.isNewHash||this._isFirst){const e=[2,4,8];let t=e[a.rand()*e.length>>0];c.compositionsData.divider=t;const s=a.rand()*ye.length>>0;c.paletteData.palette=s,a.palettes=[s];const i=Array.from({length:ye.length},(n,l)=>l+1).filter(n=>n!==s);for(let n=0;n<3;n++){const l=Math.floor(a.rand()*i.length);a.palettes.push(i[l]),i.splice(l,1)}a.idxPalette=0,t<8&&(c.gridPatternData.linesGridAlpha=.7),this.isBroken=!0,this.isBrokenVerticaly=!0,this.isExtraBrokenVerticaly=!1,t<=4?t==4?(this.isBroken=a.rand()<.5,this.isBrokenVerticaly=a.rand()<.25):t==2&&(this.isBroken=a.rand()<.5,this.isBrokenVerticaly=a.rand()<.25):(this.isBroken=a.rand()<.8,this.isBrokenVerticaly=a.rand()<.5,this.isExtraBrokenVerticaly=a.rand()<.25,!this.isBroken&&this.isBrokenVerticaly&&this.isExtraBrokenVerticaly&&(this.isBroken=!0)),this.isSmallTrees=!1}(this._isFirst||this.divider!==c.compositionsData.divider)&&(this.divider=c.compositionsData.divider,this.divider==4?(c.gridData.divisions.chance=.96,c.gridData.divisions.friction=.93,c.gridData.divisions.maxDivisions=6):this.divider==2?(c.gridData.divisions.chance=.98,c.gridData.divisions.friction=.95,c.gridData.divisions.maxDivisions=7):this.divider==8&&(c.gridData.divisions.chance=.83,c.gridData.divisions.friction=.89,c.gridData.divisions.maxDivisions=5),this.isBroken=a.rand()<.5,this.isBroken=!0),this._isFirst=!1,this.isNewHash=!1,this.refreshLayers()}refreshLayers(){this.layers=[];const e=c.compositionsData.layers;this.layers.push(this._createLayer(e.background));for(let s=0;s<5;s++)this.layers.push(this._createLayer(e[`greenLayer${s+1}`]));const t=this._createTreesLayer();c.compositionsData.putTreesBefore?this.layers.splice(this.layers.length-1,0,t):this.layers.push(t),this.layers.push(this._createLayer(e.windLayer));for(let s=0;s<4;s++)s==2&&this.layers.push(this._createFlowersLayer()),this.layers.push(this._createLayer(e[`flowerLayer${s+1}`]));this.layers.push(this._createLayer(e.blueWindLayer)),this.layers.push(this._createLayer(e.greenFlowerLayer)),this.layers.push(this._createLayer(e.bonusLayer))}_createLayer(e){let t={};for(const s in e.params)t[s]=e.params[s].value;if(t.type="vege",t.id=++this._idx,t.patternId="classic",t={...fe,...t},e.noise){t.noise={};for(const s in e.noise.params)t.noise[s]=e.noise.params[s].value}return t}_createTreesLayer(){let e={};return e.id=++this._idx,e={...fe,...e},e.patternId="tree",e.skipPattern=!1,e}_createFlowersLayer(){let e={};return e.id=++this._idx,e={...fe,...e},e.patternId="flowers",e.skipPattern=!1,e}_createGridLayer(){let e={};return e.id=++this._idx,e={...fe,...e},e.patternId="grid",e.skipPattern=!1,e}}function Da(){const r=document.createElement("div");r.className="ryokans-menu",r.style.display="none";const e=document.createElement("style");e.innerHTML=` .ryokans-menu-action-button { width: 60px; height: 60px; border: 1px solid #fff; color: #fff; background: transparent; display: flex; align-items: center; justify-content: center; font-size: 0.5em; cursor: pointer; margin: 5px; transition: background 0.2s, color 0.2s; text-align: center; opacity: .35; background: rgba(0,0,0,0.8); } .ryokans-menu-action-button:hover { background: rgba(255,255,255,0.1); } `,document.head.appendChild(e);const t=new URLSearchParams(window.location.search),s=t.get("fullscreen")==="true",i=t.get("dpr")||"0.5",n=[s?{label:"Centered",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fullscreen","false"),window.location.href=u.toString()}}:{label:"Fullscreen",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fullscreen","true"),window.location.href=u.toString()}},i==="1"?{label:"LD",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("dpr","0.5"),window.location.href=u.toString()}}:{label:"HD",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("dpr","1"),window.location.href=u.toString()}},t.get("fixed")==="true"?{label:"Animated",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fixed","false"),window.location.href=u.toString()}}:{label:"Fixed",onClick:()=>{const u=new URL(window.location.href);u.searchParams.set("fixed","true"),window.location.href=u.toString()}}];n.push({label:"Save",onClick:()=>{zt(a.gl.canvas)}}),document.body.appendChild(r),n.forEach(({label:u,onClick:f})=>{const g=document.createElement("button");g.className="ryokans-menu-action-button",g.innerText=u,g.onclick=f,r.appendChild(g)});let l=null;function o(){r.style.display="flex",r.style.justifyContent="center",r.style.alignItems="center",r.style.position="fixed",r.style.left="0",r.style.right="0",r.style.bottom="10px",r.style.top="",r.style.zIndex="1000",l&&clearTimeout(l),l=setTimeout(h,2e3)}function h(){r.style.display="none"}function d(){o()}window.addEventListener("mousemove",d),window.addEventListener("touchstart",d),h()}function Ca(){const r=a.sketch,e=a.generator,t=a.artwork;document.body.style.backgroundColor="#17140b",a.renderStartTime=performance.now(),t.init().then(async function(){r.setBgColor(c.backgroundData.globalBackgroundColor),r.clear(),ht.resetHash(),e.generate(),console.warn("First rand: ",a.rand()),console.warn("First rand 2: ",a.rand2()),c.isDirty=!0,a.seed=a.rand()*1e3,await t.generate(),await t.prerenderAnimated(),a.loader?.update(),Da(),await t.renderMoments(),r.artwork=t.texture,r.renderWebGL({options:c.postprocessData,displayArtwork:t!=null}),a.onRender.dispatch();let s=0;const i=async()=>{await t.regenerateAndRenderGrids(),await t.reRenderAnimated(),s=0,Be.add(n)},n=()=>{s+=1,s%1400===0&&(Be.remove(n),i())};!a.isRender&&!a.isFixed&&Be.add(n)}),Gt.add(()=>{t.renderAnimated(),r.artwork=t.textureAnimated,r.renderWebGL({options:c.postprocessData,displayArtwork:t!=null})})}class Aa{constructor(e,t={}){this.options={color:"#fff",width:"30%",...t},this.steps=7,this.step=1/this.steps,this.progress=0,this.progressRender=.001,this.progressRenderLocal=.001,this._isVisible=!1,this.element=document.createElement("div"),this.element.className="ryokan-loader",this.element.style.width="30%",this.element.style.zIndex="9999",this.element.style.position="absolute",this.element.style.bottom=0,this.element.style.left="50%",this.element.style.transform="translate(-50%, -50%)",this.element.style.backgroundColor="#17140B",this.element.style.padding="20px",this.element.style.border="1px solid #fff",this.barContainer=document.createElement("div"),this.barContainer.className="ryokan-loader-bar-container",this.barContainer.style.height="4px",this.barContainer.style.backgroundColor="#000",this.barContainer.style.opacity=.8,this.barContainer.style.overflow="hidden",this.barContainer.style.position="relative",this.bar=document.createElement("div"),this.bar.className="ryokan-loader-bar",this.bar.style.height="100%",this.bar.style.width="0%",this.bar.style.backgroundColor="#fff",this.bar.style.transition="width 0.3s ease-in-out",this.bar.style.position="absolute",this.bar.style.left="0",this.bar.style.top="0",this.barContainer.appendChild(this.bar),this.element.appendChild(this.barContainer),e&&(typeof e=="string"?document.querySelector(e).appendChild(this.element):e.appendChild(this.element)),this.setProgress(0)}update(){return this.progress+=this.step,this.setProgress(this.progress),this}setProgress(e){const t=Math.max(0,Math.min(1,e));return this.bar.style.width=`${t*100>>0}%`,this}setProgressRender(e){this.progressRender=e}setProgressRenderLocal(e){this.progressRenderLocal=e}getElement(){return this.element}show(){this._isVisible=!0,this.setProgress(0),this.element.style.display="block"}hide(){this._isVisible&&(this._isVisible=!1,this.element.style.display="none")}}ht.start(ls);ft.init(Oe);c.registerGUI(ft);a.data=c;c.init();new Gi(c);const qe=new kr(a.size.width,a.size.height);qe.initWebGL();qe.setBgColor(c.backgroundData.globalBackgroundColor);a.sketch=qe;const Pa=new La;a.artwork=Pa;const Ta=new Sa;a.generator=Ta;function za(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}if(za()){const r=document.createElement("div");r.innerText="Please open this page on a desktop for the full experience.",r.style.position="fixed",r.style.top="50%",r.style.left="50%",r.style.transform="translate(-50%, -50%)",r.style.backgroundColor="rgba(0,0,0,0.85)",r.style.color="#fff",r.style.padding="24px 32px",r.style.fontSize="12px",r.style.textAlign="center",r.style.maxWidth="90vw",document.body.appendChild(r)}else{const r=new Aa(document.body,{color:"#000",height:"10px"});a.loader=r,a.loader.show(),Ca()}
sk.value=t.skipMask||this._skipMask,e>.7&&(n.uSkipMask.value=t.skipMask||this._skipMask)):n.uSkipMask.value=!0,n.uPercentGrid.value=e,n.uIsFlower.value=!0}update(e,t,s,i=1){const n=this.u;n.tPattern.value=e,n.uPercentGrid.value=s-.1,n.uSkipMask.value=t.skipMask,s>.7&&(n.uSkipMask.value=t.skipMask||this._skipMask),n.uThM.value*=2,n.uThA.value=(c.vegeLinesData.lines.thA+s*.1)*2,n.uDontUsePattern.value=t.skipPattern,n.uCountLines.value=t.countLines,n.uLineColor.value=new E(t.color),n.uLengthA.value=t.lengthA*2,n.uRotType.value=t.rotationType,n.uAlpha.value.x=t.alpha*i,n.uAlpha.value.y=t.alpha*i+.01,n.ugenhash.value=a.seed+t.id*1234,n.uIsFlower.value=!1}setPattern(e){this.u.tPattern.value=e}}var ua=`#define M_PI 3.1415926535897932384626433832795 #i_ noiseUtils #i_ snoise2d #i_ snoise3d #injectUniforms _u _f uSeed;_u bool hasMask;_u _s2 tMask;in _v2 vUv;out _v4 outColor0;_vm_f z=uTime+uSeed;_v2 uv=vUv;uv-=.5;uv*=uScale;uv+=.5;if(uMode==0){_f noise=sn3d(_v3(uv,z))*uStr;outColor0=_v4(_v3(noise),1.0);}else{_v3 p=_v3(uv,z);_v3 curl=curlNoise(p);_f noise=atan(curl.y,curl.x)/M_PI*2.;outColor0=_v4(_v3(noise*uStr),1.0);}if(hasMask){_v4 mask=texture(tMask,vUv);outColor0*=mask;}}`;class da extends j{constructor({textures:e={},cellSize:t=1024}={}){const s=a.gl,n=a.size.width/t/a.size.width;super(1,{type:s.FLOAT,internalFormat:s.renderer.isWebgl2?s.RGBA32F:s.RGBA,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE,generateMipmaps:!1,minFilter:s.NEAREST,magFilter:s.NEAREST},{ratio:n}),this.init({uniforms:{uSeed:{value:0}},textures:e,fs:ua,dataFroms:[c.patternNoiseData,c.gridData]}),this._mask=new G({ratio:.1}),this.uniforms.hasMask={value:!1},this.uniforms.tMask={value:this._mask.texture}}generate(e){this.uniforms.uSeed.value=a.seed}render(e=1,t,s=!1,i=null){this._programLinker?.update(),s&&(i?this.uniforms.tMask.value=i:(this._drawMask(),this.uniforms.tMask.value=this._mask.texture)),this.uniforms.hasMask.value=s,t?(this.uniforms.uScale.value=c.patternNoiseData.scale+t.scaleMax,this.uniforms.uTime.value=t.time,this.uniforms.uMode.value=t.mode):(this.uniforms.uScale.value=c.patternNoiseData.scale+e*c.patternNoiseData.scaleMax,this.uniforms.uTime.value+=.1),super.render({hasToUpdateUniforms:!1})}_drawMask(){this._mask.clear();const e=a.size.width,t=a.size.height;this._mask.ctx.fillStyle="#fff";const s=this._mask.ratio;this._mask.ctx.beginPath(),this._mask.ctx.moveTo(0,0),this._mask.ctx.lineTo(e*.5*s,0),this._mask.ctx.lineTo(0,t*.5*s),this._mask.ctx.fill(),this._mask.ctx.closePath(),this._mask.ctx.beginPath(),this._mask.ctx.moveTo(e*.5*s,0),this._mask.ctx.lineTo(e*s,0),this._mask.ctx.lineTo(e*s,t*.5*s),this._mask.ctx.fill(),this._mask.ctx.closePath(),this._mask.ctx.beginPath(),this._mask.ctx.moveTo(0,t*.5*s),this._mask.ctx.lineTo(e*.5*s,t*s),this._mask.ctx.lineTo(0,t*s),this._mask.ctx.fill(),this._mask.ctx.closePath(),this._mask.ctx.beginPath(),this._mask.ctx.moveTo(e*.5*s,t*s),this._mask.ctx.lineTo(e*s,t*s),this._mask.ctx.lineTo(e*s,t*.5*s),this._mask.ctx.fill(),this._mask.ctx.closePath(),this._mask.texture.needsUpdate=!0}}function ca(r){const e=r>>16&255,t=r>>8&255,s=r&255;return{r:e/255,g:t/255,b:s/255}}function fa(r,e,t,s="array"){var i=Math.max(r,e,t),n=Math.min(r,e,t),l,o,h=(i+n)/2;if(i==n)l=o=0;else{var d=i-n;switch(o=h>.5?d/(2-i-n):d/(i+n),i){case r:l=(e-t)/d+(e<t?6:0);break;case e:l=(t-r)/d+2;break;case t:l=(r-e)/d+4;break}l/=6}return s==="array"?[l,o,h]:s==="rgb"?{r:l,g:o,b:h}:{h:l,s:o,l:h}}function ga(r,e=!0){const t=ca(r),s=fa(t.r,t.g,t.b);return e?(s[0]*=360,s[1]*=100,s[2]*=100,`hsl( ${s[0]}, ${s[1]}%, ${s[2]}% )`):s}const tt=function(r){const e=ga(r,!1);return{h:e[0]*360,s:e[1]*100,l:e[2]*100}};class st{constructor({x:e,y:t,a:s,length:i=220,color:n,maxDepth:l=15,branchAngle:o=.99,type:h="tree"}={}){this.x=e,this.y=t,this.a=s,this.length=i,this.color=n,this.maxDepth=l,this.branchAngle=o,this.type=h,this._boundaryDepthRatio=12,this.branches=[],this.flowers=[],this.flowersSpecial=[]}async generate(){this._countSplit=0,this.branches.push({x:this.x,y:this.y,z:0,a:this.a,length:this.length,color:this.color}),await this._split(this.x+Math.cos(this.a)*this.length,this.y+Math.sin(this.a)*this.length,this.a,this.length,0,this.color)}async _split(e,t,s,i,n=0,l={h:a.rand()*360,s:100,l:50},o=0){const h=c.treebstractData;let d=h.splitCountMin+h.splitCountAdd*a.rand()>>0;n>8?d=Math.min(2,d):n>12&&(d=Math.min(1,d));const u=this.maxDepth*.4;let f;this.maxDepth<=this._boundaryDepthRatio?f=ie(n,0,this.maxDepth,1,1.2):f=ie(n,0,u,1,1.4)+ie(n,u,this.maxDepth,0,.2);let g=s;d>1&&(g-=this.branchAngle*.5*f);let _=i*.9;_=Math.max(h.minLength,_);const m=this.maxDepth>this._boundaryDepthRatio;this._countSplit++,this._countSplit%250===0&&await P();for(let p=0;p<d;p++){const w=p>=3&&p<5&&m?10:1,v=a.rand()*this.branchAngle*f*w,x=g+v,y={x:e,y:t,z:o,a:x,length:_,color:l,type:"branch"};n>4&&a.rand3()<.4&&this.branches.push(y);const M=n+1,k=ie(M,0,this.maxDepth,.9,.3);if(M<3||M<this.maxDepth&&a.rand()<k){l={...l},l.h=a.rand()<.3?l.h+a.rand()*20-10:l.h;const S=e+Math.cos(x)*_,U=t+Math.sin(x)*_,C=o+a.rand()*4-2;if(S<-300||U<-300||S>a.size.width+300||U>a.size.height+300)continue;this._split(S,U,x,_,n+1,l,C)}else{this.flowers.push({x:e+Math.cos(x)*_,y:t+Math.sin(x)*_,z:o+4,a:x,color:l,type:"flower"});const S=1+a.rand()*3>>0,U=Math.PI*.6/S;let L=x-Math.PI*.3;for(let D=0;D<S;D++){const A=-20+a.rand()*60,I=a.rand()<.15?"radial":"tangent",q=e+Math.cos(L)*(_+A),H=t+Math.sin(L)*(_+A);if(q<0||H<0||q>a.size.width||H>a.size.height)continue;const Y={x:q,y:H,z:o+4,dir:L,color:l,size:a.rand2()*40+4,type:"flower",typeOrientation:I};this.flowers.length<600&&this.flowers.push(Y),I=="radial"&&this.flowersSpecial.push(Y),L+=U}}}}prepareRendering(){this.elementsByZ=this.branches.concat(this.flowers)}async render(e,t,s){let i=16,n=36*2;e.fillStyle="#fff";let l=0;for(const o of this.elementsByZ){const h=Math.cos(o.a)*.5+.5,d=Math.sin(o.a)*.5+.5;if(o.type=="flower"){const u=o.x,f=o.y,g=n;e.fillRect((u-g*.5)*s,(f-g*.5)*s,g*s,g*s)}else{const u=o.x,f=o.y,g=o.x+Math.cos(o.a)*o.length,_=o.y+Math.sin(o.a)*o.length;t.beginPath(),t.strokeStyle=`rgb(${h*255}, ${d*255}, 255)`,t.lineWidth=i*s,t.moveTo(u*s,f*s),t.lineTo(g*s,_*s),t.stroke(),t.closePath()}l++,l%300===0&&await P()}}}class _a{constructor(){this.position={x:a.size.width*.5,y:0},this._ratio=.1;const e={flipY:!1};this.canvasBranch=new G({renderTargetOpts:e,ratio:this._ratio}),this.canvasElements=new G({renderTargetOpts:e,ratio:this._ratio})}generate(){this._trees=[];const e=1+a.rand()*12>>0,t=a.size.width/(e+1);for(let i=0;i<e;i++){const n=t*(i+1)+a.rand()*a.size.width*.2-a.size.width*.1;this._generateForestTree(n)}let s=0;e==1?s=a.rand()<.5?0:2:s=a.rand()*3>>0,this._generateForegroundTree(s)}async generateForest(e){this.color=e,this._trees=[];const t=3+a.rand()*5>>0,s=a.size.width/(t+1);for(let i=0;i<t;i++){const n=s*(i+1)+a.rand()*a.size.width*.2-a.size.width*.1;a.renderingMode!=="editor"?(await this._generateForestTree(n),P()):this._generateForestTree(n)}}generateForeground(e){this.color=e,this._trees=[],this._generateForegroundTree(a.rand()*3>>0)}async _generateForegroundTree(e=-1){e==-1&&(e=a.rand()*3>>0);let t=0;e==0?t=.25+a.rand()*.15-.075:e==1?t=.4+a.rand()*.2:t=.6+a.rand()*.15;const s=a.size.width*t,i=0;let n=(a.size.width<a.size.height?200:0)+500;n*=2;const l=this._getColor(),o=new st({x:s,y:i,a:Math.PI*.45+a.rand()*Math.PI*.1,length:n,color:l,maxDepth:12,branchAngle:1.503,type:"foreground"});a.renderingMode!=="editor"?await o.generate():o.generate(),this._trees.push(o)}async _generateForestTree(e){const t=e,s=a.rand()*-600,i=Math.PI*.45+a.rand()*Math.PI*.1,n=11+a.rand()*5>>0;let l=(a.size.width<a.size.height?200:-130*a.rand())+300+a.rand()*ie(n,11,16,150+a.rand()*150,100)>>0;l*=2;const o=.85+a.rand()*.3,h=this._getColor(),d=new st({x:t,y:s,a:i,length:l,color:h,maxDepth:n,branchAngle:o,type:"forest"});a.renderingMode!=="editor"?await d.generate():d.generate(),this._trees.push(d)}_getColor(){if(this.color){let e;return typeof this.color=="string"?e=tt(parseInt(this.color.replace("#",""),16)):e=tt(this.color),e.h=(e.h+a.rand()*150)%360,e}return{h:2.68392420373857+a.rand()*150,s:100,l:50}}getFlowerSpecial(){const e=[];for(const t of this._trees)for(const s of t.flowersSpecial)e.push(s);return e}get trees(){return this._trees}get flowersSpecial(){return this._trees.reduce((e,t)=>e.concat(t.flowersSpecial),[])}get texture(){return this.canvasElements.texture}get textureOrientation(){return this.texture}get textureBranch(){return this.canvasBranch.texture}get textureBranchOrientation(){return this.canvasBranch.texture}}class le{constructor(e,t,s,i,n){this._layer=e,this._sceneDeformer=t,this._patternsRenderer=s,this._vegeLines=i,this._elements=n,this._percentRender=0}setLayer(e){this._layer=e}async generate(){}_getPattern(e){return this._sceneDeformer.render(this._patternsRenderer.texture,e),this._sceneDeformer.texture}async renderScene(e,t,s=1){const i=this._layer.isSingleDir?[new F(1,1)]:[new F(1,0),new F(0,1)],n=i.length,l=1/a.size.width*2;for(let o=0;o<n;o++){const h=i[o];let d=this._getPattern(h);this._vegeLines.updateProgramLinker(),this._vegeLines.uniforms.uIsNormal.value=o==0;const u=o==0?0:l;this._vegeLines.uniforms.uOffset.value.x=h.x*u,this._vegeLines.uniforms.uOffset.value.y=h.y*u,this._vegeLines.update(d,this._layer,t),a.renderingMode!=="editor"?await this.renderVegeLines(s/n):this.renderVegeLines(s/n),this._vegeLines.uniforms.hasToCheckColor.value=!1}}async renderVegeLines(e=1,t=a.linesPerGeometry){const s=Math.ceil(a.linesTotal/t),i=e/s;this._vegeLines.uniforms.uIDAdd.value=0;for(let n=0;n<s;n++)this._vegeLines.render({hasToClear:!1,hasToUpdateUniforms:!1}),this._vegeLines.uniforms.uIDAdd.value+=t,this._percentRender+=i,a.loader.setProgressRender(a.loader.progressRenderLocal+this._percentRender),a.renderingMode!=="editor"&&await Nt()}get patternId(){return this._layer.patternId}}class pa extends le{constructor(e,t,s,i,n){super(e,t,s,i,n),this._treebstract=new _a}async generate(){a.renderingMode!=="editor"?this._layer.maskType==1?await this._treebstract.generateForest(this._layer.color):await this._treebstract.generateForeground(this._layer.color):this._layer.maskType==1?this._treebstract.generateForest(this._layer.color):this._treebstract.generateForeground(this._layer.color)}_getPattern(){return this._elements.treebstractRenderer.texture}async render(e,t,s){this._percentRender=0;const i=s/3,n=this._elements.treebstractRenderer;await n.render(this._treebstract.trees);const l=this._elements.flowersRenderer,o=this._treebstract.getFlowerSpecial();l.renderFlowers(o),this._vegeLines.updateProgramLinker(),this._vegeLines.uniforms.tTrees.value=n.textureBranch,this._vegeLines.uniforms.tTreesOrientation.value=n.textureBranchOrientation,this._vegeLines.updateForTrees(t,!0),await this.renderVegeLines(i),this._vegeLines.updateProgramLinker(),this._vegeLines.uniforms.tTrees.value=l.texture,this._vegeLines.uniforms.tTreesOrientation.value=l.textureOrientation,this._vegeLines.updateForFlowers(t,this._layer,null,!1),await this.renderVegeLines(i),await this.renderScene(e,t,i)}}class ma extends le{constructor(e,t,s,i,n){super(e,t,s,i,n)}async render(e,t,s){this._percentRender=0,this._patternsRenderer.render(e,this._layer.noise,this._layer.hasMask),await this.renderScene(e,t,s)}}class xa{constructor(){}prepare(e){this._ryokanCellSize=e}async generate(){const e=a.size.width/this._ryokanCellSize,t=a.size.height/this._ryokanCellSize;this._noise=new je(a.rand2),this._branches=[],this._dir=Math.PI*.1+Math.PI*a.rand2()*.8;const s=10+a.rand2()*10>>0;for(let i=0;i<s;i++){const n=Math.floor(6+a.rand2()*(e-3))*this._ryokanCellSize,l=Math.floor(6+a.rand2()*(t-3))*this._ryokanCellSize;this._branches.push(this._generateFromNewOrigin(n,l,i)),await P()}}_generateFromNewOrigin(e,t,s){this._leavesData=[];const i=this._generateTrunk(e,t,this._dir,5+a.rand2()*15>>0,s),n=this._generateLeaves();return{trunk:i,leaves:n}}_generateTrunk(e,t,s,i,n=0,l=!0){const o=c.treesData.flowers,h=[];h.push({x:e,y:t});const d=[];let u=e,f=t;for(let _=0;_<i;_++){s+=this._noise.noise3D(u*o.trunkNoiseScale,f*o.trunkNoiseScale,n)*(o.trunkNoiseStr*(l?1:.5)),u+=Math.cos(s)*o.trunkStep,f+=Math.sin(s)*o.trunkStep;const m=_/i;if(m>.3&&a.rand2()<o.leavesChance&&this._leavesData.push({x:u,y:f,a:s}),l&&m>.4&&a.rand2()<o.trunkBranchChance){const p=a.rand2()<.5?2:4;d.push(this._generateTrunk(u,f,s+Math.PI*.5*(a.rand2()<.5?-1:1),i/p>>0,n,!1))}h.push({x:u,y:f,a:s})}const g=[h];for(const _ of d)g.push(_);return l?g:h}_generateLeaves(){const e=[];for(const t of this._leavesData){const s=a.rand2()*12+1>>0;for(let i=0;i<s;i++){const n=t.a+Math.PI*a.rand2()-Math.PI*.5,l=a.rand2()*200,o=t.x+Math.cos(n)*l,h=t.y+Math.sin(n)*l,d={x:o,y:h,size:a.rand2()*50+4,a:n};e.push(d)}}return e}get branches(){return this._branches}}class va extends le{constructor(e,t,s,i,n){super(e,t,s,i,n),this._flowers=new xa}async generate(e){this._flowers.prepare(e),a.renderingMode!=="editor"?await this._flowers.generate():this._flowers.generate()}async render(e,t,s){this._percentRender=0;const i=this._elements.flowersRenderer,n=this._flowers.branches;i.render(n),this._vegeLines.updateProgramLinker(),this._vegeLines.uniforms.tTrees.value=i.texture,this._vegeLines.uniforms.tTreesOrientation.value=i.textureOrientation,this._vegeLines.updateForFlowers(t,this._layer,c.treesData.flowers.color2,!1),await this.renderVegeLines(s)}}class ya extends le{constructor(e,t,s,i,n){super(e,t,s,i,n)}async render(e,t,s){const i=this._elements.trees;this._vegeLines.updateProgramLinker(),this._vegeLines.uniforms.tTrees.value=i.texture,this._vegeLines.uniforms.tTreesOrientation.value=i.textureOrientation,this._vegeLines.updateForTrees(t,!0,!0),await this.renderVegeLines(1*s)}}class it extends le{constructor(e,t,s,i,n){super(e,t,s,i,n)}async render(){const e=this._elements.gridPattern;e.render({hasToClear:!1}),this._vegeLines.addChild(e.mesh),this._vegeLines.removeChild(this._vegeLines._mesh),this._vegeLines.render({hasToClear:!1,hasToUpdateUniforms:!1}),this._vegeLines.addChild(this._vegeLines._mesh),this._vegeLines.removeChild(e.mesh)}}class wa{constructor(e,t=512,s=!1,i=null,n){e=e,this._flowers=i.flowers,this._flowersRenderer=i.flowersRenderer,this._gridPattern=i.gridPattern,this._treebstract=i.treebstract,this._treebstractRenderer=i.treebstractRenderer,this._elements=i,this._vegeLines=i.vegeLines,this._texturesDeformer={...e},this._texturesVegeLines={...e},this._cellSize=t,this._idx=n,this._patternsRenderer=new da({cellSize:t}),this._sceneDeformer=new sa(this._texturesDeformer)}async generate(e,t=-1){this._idxPalette=t,this._patternsRenderer.generate(e),this._layers=[];const s=a.generator.layers,i=s.length;for(let n=0;n<i;n++){const l=s[n];let o=null;switch(l.patternId){case"classic":l.maskType!==0?o=pa:o=ma;break;case"flowers":o=va;break;case"tree":o=ya;break;case"grid":o=it;break}const h=new o(l,this._sceneDeformer,this._patternsRenderer,this._vegeLines,this._elements);a.renderingMode!=="editor"?await h.generate(e):h.generate(e),this._layers.push(h)}this._sceneLayerGrid=new it(null,this._sceneDeformer,this._patternsRenderer,this._vegeLines,this._elements)}refreshLayers(){const e=a.generator.layers;for(let t=0;t<e.length;t++){const s=e[t];this._layers[t].setLayer(s)}}async render(){this._vegeLines.clear();let e=c.compositionsData.layers.totalDivider;const t=.34*this._idx;a.isOver||a.loader.setProgressRenderLocal(t);const s=this._layers.length,i=1/s;for(let n=0;n<s;n++){const l=this._layers[n],o=n/s,h=Math.floor(o*e)/e;n===c.gridPatternData.index&&this._sceneLayerGrid.render(),await l.render(o,h,i/3),a.isOver||(a.loader.setProgressRenderLocal(t+o/3),a.loader.setProgressRender(t+o/3))}}get texture(){return this._vegeLines.texture}}class ba{constructor(e,t){this._textures=e,this._elements=t,this._vegeLines=new ha(e,!1),this._elements.vegeLines=this._vegeLines;const s=1;this._sceneBuilder0=this._createSceneBuilder(512*s,0),this._sceneBuilder1=this._createSceneBuilder(128*s,1),this._sceneBuilder2=this._createSceneBuilder(32*s,2),this._assembler=new ea({tGrid:t.deformerGridScene.texture,tFlow:t.flow.texture}),this._assemblerAnimated=new Zr({tAssembler:this._assembler.texture,tVegeLines:this._vegeLines.texture,tGrid:t.deformerGrid.texture,tGridScene:t.deformerGridScene.texture,tGridLines:t.gridLines.texture,tFlow:t.flow.texture})}_createSceneBuilder(e,t){return new wa(this._textures,e,!1,this._elements,t)}async generate(e){await this._vegeLines?.generate(),a.loader?.update(),a.renderingMode!=="editor"?(await this._sceneBuilder0?.generate(e,3),a.loader?.update(),await this._sceneBuilder1?.generate(e,5),a.loader?.update(),await this._sceneBuilder2?.generate(e,4),a.loader?.update()):(await this._sceneBuilder0?.generate(e,3),await this._sceneBuilder1?.generate(e,5),await this._sceneBuilder2?.generate(e,4))}async render(){if(a.loader?.setProgress(1),a.gl.renderer.autoClear=!0,this._assemblerAnimated.render({hasToClear:!0,clearBG:!0}),a.gl.renderer.autoClear=!1,this._step=0,await this._sceneBuilder0?.render(),a.gl.renderer.autoClear=!0,this._assembler.render({hasToClear:!0,texture:this._sceneBuilder0.texture,min:0,max:.2499}),a.gl.renderer.autoClear=!1,this._step=1,await this._sceneBuilder1?.render(),this._assembler.render({hasToClear:!1,texture:this._sceneBuilder1.texture,min:.25,max:.4999}),this._assembler.render({hasToClear:!1,texture:this._sceneBuilder1.texture,min:.75,max:1}),this._step=2,await this._sceneBuilder2?.render(),this._assembler.render({hasToClear:!1,texture:this._sceneBuilder2.texture,min:.5,max:.7499}),a.renderingMode==="animated"&&!a.isOver){let e=1-a.loader.progressRender;const t=10;let s=e/t;for(let i=0;i<t;i++)a.loader.setProgressRender(a.loader.progressRender+s),await Nt();await P()}if(a.infoDiv){const e=document.createElement("p");e.innerHTML=`<strong>Render Time:</strong> ${renderTime}ms`,a.infoDiv.appendChild(e)}this._assemblerAnimated.setPercent(2),a.isOver=!0}renderAnimated(){let e=0,t=.25,s=!1,i=0,n=1;this._step==1?(e=.25,t=.4999,i=.75,n=1,s=!0):this._step==2&&(e=.5,t=.7499),this._assemblerAnimated.render({hasToClear:!1,min1:e,max1:t,minMax2Activated:s,min2:i,max2:n})}async reRenderAnimated(){this._step=0,this._sceneBuilder0?.refreshLayers(),await this._sceneBuilder0?.render(),this._assembler.render({hasToClear:!1,texture:this._sceneBuilder0.texture,min:0,max:.2499}),this._step=1,this._sceneBuilder1?.refreshLayers(),await this._sceneBuilder1?.render(),this._assembler.render({hasToClear:!1,texture:this._sceneBuilder1.texture,min:.25,max:.4999}),this._assembler.render({hasToClear:!1,texture:this._sceneBuilder1.texture,min:.75,max:1}),this._step=2,this._sceneBuilder2?.refreshLayers(),await this._sceneBuilder2?.render(),this._assembler.render({hasToClear:!1,texture:this._sceneBuilder2.texture,min:.5,max:.7499}),this._assemblerAnimated.setPercent(2)}get texture(){return this._assembler.texture}get textureAnimated(){return this._assemblerAnimated.texture}}class Ma{constructor(){this._ratio=.1;const e={flipY:!1};this.canvasBranch=new G({renderTargetOpts:e,ratio:this._ratio}),this.canvasElements=new G({renderTargetOpts:e,ratio:this._ratio})}async render(e){this.canvasElements.clear(),this.canvasBranch.clear();for(const t of e)t.prepareRendering();for(const t of e)await t.render(this.canvasElements.ctx,this.canvasBranch.ctx,this._ratio);this.canvasElements.texture.needsUpdate=!0,this.canvasBranch.texture.needsUpdate=!0}get texture(){return this.canvasElements.texture}get textureOrientation(){return this.texture}get textureBranch(){return this.canvasBranch.texture}get textureBranchOrientation(){return this.canvasBranch.texture}}class La extends Fr{constructor(){super()}async init(){this._grid=new jr,this.add(this._grid,[c.gridData,c.compositionsData,c.gridPatternData]),this._flow=new Gr,this.add(this._flow,c.flowData),this._deformerGrid=new Ue({tToDeform:this._grid.texture}),this.add(this._deformerGrid),this._deformerGridScene=new Ue({tToDeform:this._grid.textureScene}),this.add(this._deformerGridScene),this._deformerGridLines=new Ue({tToDeform:this._grid.textureLines},1),this.add(this._deformerGridLines),this._trees=new Xr,this.add(this._trees,c.treesData),this._treebstractRenderer=new Ma,this._flowersRenderer=new qr,this._gridPattern=new Yr({tGridPattern:this._deformerGridLines.texture}),this._texturesScenes={tFlow:this._flow.texture,tGrid:this._deformerGrid.texture,tTrees:this._trees.texture,tTreesOrientation:this._trees.textureOrientation,tPattern:new oe(a.gl,{})},this._momentsRenderer=new ba(this._texturesScenes,{trees:this._trees,flowersRenderer:this._flowersRenderer,gridPattern:this._gridPattern,gridLines:this._deformerGridLines,treebstractRenderer:this._treebstractRenderer,deformerGrid:this._deformerGrid,deformerGridScene:this._deformerGridScene,flow:this._flow}),this.add(this._momentsRenderer,[c.treesData,c.treebstractData,c.patternNoiseData,c.vegeLinesData,c.compositionsData,c.gridPatternData,c.composerData])}async generate(){const e=c.gridData.isDirty,t=c.gridRyokanData.isDirty,s=c.compositionsData.isDirty||c.compositionsData.layers.isDirty;if(!this._gridRyokanCellSize||e||t||s){let i=Or.getNewRandomCellSize(128);i=1024/c.compositionsData.divider,await this._grid.generate(i),a.loader?.update();const l=[32,64,128];this._gridRyokanCellSize=l[l.length*a.rand2()>>0],a.renderingMode!=="editor"?await this._grid.seasonize():this._grid.seasonize(),a.loader?.update(),this._trees?.prepare(i)}this._trees?.generate(this._gridRyokanCellSize),await this._momentsRenderer.generate(this._gridRyokanCellSize)}async prerenderAnimated(){await this._grid.render(),this._flow.render(),await P(),this._deformerGrid.render(),this._deformerGridScene.render(),this._deformerGridLines.render(),this._trees.render(),await P()}async renderMoments(){await this._momentsRenderer.render()}async regenerateAndRenderGrids(){a.idxPalette+=1,c.paletteData.palette=a.palettes[a.idxPalette%4],a.generator.refreshLayers(),await this._grid.render(),await P(),this._flow.render(),await P(),this._deformerGrid.render(),await P(),this._deformerGridScene.render(),await P(),this._deformerGridLines.render(),await P()}renderAnimated(){a.loader.hide(),this._momentsRenderer.renderAnimated()}async reRenderAnimated(){await this._momentsRenderer.reRenderAnimated()}get texture(){return c.displayData.showExtra?c.displayData.getSelectedExtraTexture():c.displayData.getSelectedCoreTexture()}get textureAnimated(){return this._momentsRenderer.textureAnimated}}const ye=[];function z(r,e){ye.push({text:r,value:ye.length,data:e})}z("Autumn classic 3",gt);z("Green spring pluie"
peration="lighter",s.fillStyle=n,this._fillRect(s,t.x-t.size,t.y-t.size,t.size*2,t.size*2),s.restore()}}renderFlowers(e){this.clear(),this._renderFlowers(e),this.texture.needsUpdate=!0}_renderFlowers(e){const t=this.ctx;for(const s of e){const i=s.size,n=this._createLinearGradient(t,s.x-i,s.y,s.x+i,s.y);n.addColorStop(0,"rgba(0,0,255,1)"),n.addColorStop(1,"rgba(255,0,255,1)");const l=this._createLinearGradient(t,s.x,s.y-i,s.x,s.y+i);l.addColorStop(0,"rgba(0,0,255,1)"),l.addColorStop(1,"rgba(0,255,255,1)"),t.save(),t.beginPath(),this._rect(t,s.x-i,s.y-i,i*2,i*2),t.clip(),t.fillStyle=n,this._fillRect(t,s.x-i,s.y-i,i*2,i*2),t.globalCompositeOperation="lighter",t.fillStyle=l,this._fillRect(t,s.x-i,s.y-i,i*2,i*2),t.restore()}}_createLinearGradient(e,t,s,i,n){return e.createLinearGradient(t*this._ratio,s*this._ratio,i*this._ratio,n*this._ratio)}_fillRect(e,t,s,i,n){e.fillRect(t*this._ratio,s*this._ratio,i*this._ratio,n*this._ratio)}_rect(e,t,s,i,n){e.rect(t*this._ratio,s*this._ratio,i*this._ratio,n*this._ratio)}get textureOrientation(){return this.texture}get textureTrees(){return this._canvasTrees.texture}}var Hr=`#i_ noiseUtils #i_ snoise2d #injectUniforms _u _f uDecal;in _v2 vUv;out _v4 outColor0;void main(){_f a=snoise2d(vUv*10.+uDecal);_v2 uv=vUv+_v2(cos(a),sin(a))*.002*uDecal;outColor0=texture(tToDeform,uv);}`;class Ue extends j{constructor(e={},t=1,s={}){super(1,s,{ratio:.25}),this.init({textures:e,fs:Hr}),this.uniforms.uDecal={value:t}}}var Wr=`#injectUniforms in vec2 vUv;out vec4 outColor0;void main(){vec4 gridPattern=texture(tGridPattern,vUv);float alphagrid=gridPattern.r;outColor0=vec4(uLinesGridColor,alphagrid*uLinesGridAlpha);}`;class Yr extends j{constructor(e={},t={}){super(1,t,{ratio:.5}),this.init({textures:e,fs:Wr,dataFroms:[c.gridPatternData]})}}class Xr extends G{constructor(){const e={flipY:!1};super({renderTargetOpts:e,ratio:.05})}prepare(e){this._ryokanCellSize=e}generate(){let e=2+a.rand2()*3>>0;a.generator.isSmallTrees&&(e*=4),this._trees=[];for(let t=0;t<e;t++){const s=this._generateStraight(t);s&&this._trees.push(s)}this._generateOrientationsData()}_generateStraight(e=0){let t=this._findStartingX();if(t==-1)return null;let s=-Math.PI*.6+a.rand2()*Math.PI*.3,i=-200,n=!1;const l=[{x:t,y:i}];let o=100,h=.1,d=1.075,u=.5,f=0;for(;this._isStillIn(t,i,n);){const g=50+a.rand2()*50,_=t+Math.cos(s)*g,m=i+g;if(l.push({x:_,y:m}),t=_,i=m,f%6==0&&(s+=(a.rand()*Math.PI*.2-Math.PI*.1)*h),h*=d,h=Math.min(h,u),i>0&&(n=!0),f++,o--<0)break}return l.push({x:t+Math.cos(s)*200,y:i+200}),{path:l}}_findStartingX(){let e=0;return this._trees.length==0?e=this._getFirstX():e=this._getNewX(),e}_getFirstX(){const e=[.25,.382,.5,.618,.75],t=e.length*a.rand2()>>0;return a.size.width*e[t]}_getNewX(){let e=a.rand()*a.size.width;const t=c.treesData.treeThickness*(this._trees.length>2?3.5:5);let s=10;for(;this._isTooCloseFromOtherTrees(e,t);)if(e=a.rand()*a.size.width,s--<0)return-1;return e}_isTooCloseFromOtherTrees(e,t){for(const s of this._trees){const n=s.path[0].x;if(Math.abs(n-e)<t)return!0}return!1}_isStillIn(e,t,s=!1){return!(e<0||e>a.size.width||t>a.size.height||s&&t<0)}_generateOrientationsData(){for(const e of this._trees){const t=e.path,s=[],i=c.treesData.treeThickness,n=t[0];let l={x:n.x+i,y:n.y},o={x:n.x-i,y:n.y};const h=[],d=[],u=t.length;for(let f=1;f<u;f++){const g=t[f],_=t[f-1],m=g.x-_.x,p=g.y-_.y,w=Math.atan2(p,m);let v=i*1.4-i*.4*(f/u);a.generator.isSmallTrees&&(v*=.25);const x={x:g.x+Math.cos(w-Math.PI*.5)*v,y:g.y+Math.sin(w-Math.PI*.5)*v},y={x:g.x+Math.cos(w+Math.PI*.5)*v,y:g.y+Math.sin(w+Math.PI*.5)*v};h.push(x),d.push(y);const M=(Math.cos(w)*.5+.5)*255>>0,k=(Math.sin(w)*.5+.5)*255>>0,S=255;s.push({color:`rgb(${M}, ${k}, ${S})`,coords:[{...l},{...o},{...y},{...x}]}),l=x,o=y}e.blocks=s,e.pointsLeft=h,e.pointsRight=d}}render(){this.clear();for(const e of this._trees)this._renderTree(e);this.texture.needsUpdate=!0}_renderTree(e){const t=e.blocks;for(let s=0;s<t.length;s++){const i=t[s];this.ctx.fillStyle=i.color,this.ctx.beginPath(),this.ctx.moveTo(i.coords[0].x*this._ratio,i.coords[0].y*this._ratio);for(let n=1;n<i.coords.length;n++)this.ctx.lineTo(i.coords[n].x*this._ratio,i.coords[n].y*this._ratio);this.ctx.fill()}}get textureOrientation(){return this.texture}}let Ee=performance.now(),ce=0;const Kr=a.isRender?240:60,ve=1e3/Kr,me=[];function It(r){let e=r-Ee;if(e>ve*100?(e=0,ce=0,Ee=r):(ce+=e,Ee=r),ce>=ve){for(const t of me)t(e);ce=0}requestAnimationFrame(It)}requestAnimationFrame(It);const Be={add:r=>{me.push(r)},remove:r=>{const e=me.indexOf(r);e!==-1&&me.splice(e,1)},useDeltaTime:r=>{useDeltaTime=r},resume:()=>{},pause:()=>{}},Gt=new V,Nt=()=>new Promise(r=>{let e=performance.now(),t=0;function s(i){let n=i-e;n>ve*100?(n=0,t=0,e=i):(t+=n,e=i),t>=ve?(Gt.dispatch(),r()):requestAnimationFrame(s)}requestAnimationFrame(s)});var Jr=`#i_ blendmodes #injectUniforms _u _f uMin1;_u _f uMax1;_u bool uMinMax2Activated;_u _f uMin2;_u _f uMax2;_u _v3 uColor;_u bool uClearBG;_u _f uPercent;in _v2 vUv;out _v4 outColor0;_vm_v4 gridLines=_t(tGridLines,vUv);_v4 grid=_t(tGrid,vUv);_v4 result=_v4(uColor,1.);result.rgb=blendMode(2,result.rgb,_v3(grid.r),.5);result.rgb=blendMode(2,result.rgb,uLinesGridColor,gridLines.r*2.);if(uClearBG==true){outColor0=result;return;}_v4 gridScene=_t(tGridScene,vUv);_v4 vegeLines=_t(tVegeLines,vUv);_v4 assembler=_t(tAssembler,vUv);_f gridVal=gridScene.g;_v4 sb=assembler;bool isVegelinesOk=false;if(gridVal>=uMin1&&gridVal<=uMax1){sb.rgb=vegeLines.rgb;sb.a=1.;isVegelinesOk=true;}if(uMinMax2Activated==true){if(gridVal>=uMin2&&gridVal<=uMax2){sb.rgb=vegeLines.rgb;sb.a=1.;isVegelinesOk=true;}}_f vegeLinesLuminance=dot(vegeLines.rgb,_v3(0.299,0.587,0.114));result.rgb=mix(result.rgb,_v3(vegeLinesLuminance),(0.15+(0.35*(1.-uPercent)))*(1.-grid.b));if(uPercent<1.){outColor0=grid.b<uPercent ? sb : result;outColor0.rgb=blendMode(2,outColor0.rgb,uLinesGridColor,gridLines.r*2.*(1.-uPercent));}else{outColor0=sb;}}`;class Zr extends j{constructor(e){super(),this.init({fs:Jr,textures:e,dataFroms:[c.gridPatternData]}),this.uniforms.uMin1={value:1e-4},this.uniforms.uMax1={value:1.0001},this.uniforms.uMinMax2Activated={value:!1},this.uniforms.uMin2={value:1e-4},this.uniforms.uMax2={value:1.0001},this.uniforms.uColor={value:new E(16711935)},this.uniforms.uClearBG={value:!1},this.uniforms.uPercent={value:0}}render({hasToClear:e=!0,min1:t=0,max1:s=1,minMax2Activated:i=!1,min2:n=0,max2:l=1,clearBG:o=!1}={}){this.uniforms.uMin1.value=t,this.uniforms.uMax1.value=s,this.uniforms.uMinMax2Activated.value=i,this.uniforms.uMin2.value=n,this.uniforms.uMax2.value=l,this.uniforms.uColor.value.set(c.backgroundData.globalBackgroundColor),this.uniforms.uClearBG.value=o,this.uniforms.uPercent.value=a.loader.progressRender,super.render({hasToClear:e})}setPercent(e){this.uniforms.uPercent.value=e}}var Qr=`#injectUniforms _u _s2 tMoment;_u _f uMin;_u _f uMax;_u _v2 uScreenRatioV2;in _v2 vUv;out _v4 outColor0;_vm_v4 flow=_t(tFlow,vUv);_v4 grid=_t(tGrid,vUv);_v4 moment=_t(tMoment,vUv);_v4 sb=_v4(0.);if(grid.g>=uMin&&grid.g<=uMax){sb.rgb=moment.rgb;sb.a=1.;}outColor0=sb;}`;class ea extends j{constructor(e){super(),this.init({fs:Qr,textures:e,dataFroms:[c.composerData]}),this.uniforms.tMoment={value:null},this.uniforms.uMin={value:1e-4},this.uniforms.uMax={value:1.0001}}render({hasToClear:e=!0,texture:t=null,min:s=0,max:i=1,color:n=null}={}){this.uniforms.tMoment.value=t,this.uniforms.uMin.value=s,this.uniforms.uMax.value=i,super.render({hasToClear:e})}}a.rand;function ie(r,e,t,s,i){return s+(r-e)*(i-s)/(t-e)}var ta=`#injectUniforms _u _v2 uDirMultiplier;in _v2 vUv;out _v4 outColor0;_vm_v2 uvGrid=vUv;float percent=texture(tGrid,uvGrid).r*2.-1.;_v2 offset=_v2(uDispX,uDispY)*uDirMultiplier*uStrength;offset*=percent;_v4 pattern=texture(tPattern,mod(vUv+offset,1.));outColor0=pattern;}`;class sa extends j{constructor(e={},t={}){super(1,t,{ratio:.25});const s=.25;this._grid=new G({ratio:.25}),e.tGrid=this._grid.texture,this._grid.clear();const i=4,n=4;for(let l=0;l<a.size.width;l+=i)for(let o=0;o<a.size.height;o+=n){const h=a.rand2()*255>>0;this._grid.ctx.fillStyle=`rgba( ${h}, ${h}, ${h}, 1 )`,this._grid.ctx.fillRect(l*s,o*s,i*s,n*s)}this._grid.texture.needsUpdate=!0,this.init({textures:e,fs:ta,dataFroms:[a.data.compositionsData.deformer,a.data.gridData]}),this.uniforms.uDirMultiplier={value:new F(1,1)}}render(e,t){this.uniforms.tPattern.value=e,this.uniforms.uDirMultiplier.value=t,super.render()}get textureGrid(){return this._grid.texture}}class ia{constructor(e,t){this.reset(e,t)}reset(e,t){this.width=e,this.height=t,this.count=this.width*this.height>>0,this.count4=this.count<<2,this.data=new Float32Array(this.count4);const s=a.gl;this.textureMain=new oe(s,{image:this.data,width:this.width,height:this.height,type:s.FLOAT,generateMipmaps:!1,target:s.TEXTURE_2D,format:s.RGBA,internalFormat:s.renderer.isWebgl2?s.RGBA32F:s.RGBA,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE,minFilter:s.NEAREST,magFilter:s.NEAREST,flipY:!1});for(let i=0;i<this.count4;i+=4)this.textureMain.image[i+0]=0,this.textureMain.image[i+1]=0,this.textureMain.image[i+2]=0,this.textureMain.image[i+3]=1;this.textureMain.needsUpdate=!0}init(){this.uniforms={tData:{value:this.textureMain}}}setX(e,t){this.textureMain.image[t*4+0]=e,this.textureMain.needsUpdate=!0}setY(e,t){this.textureMain.image[t*4+1]=e,this.textureMain.needsUpdate=!0}setZ(e,t){this.textureMain.image[t*4+2]=e,this.textureMain.needsUpdate=!0}setW(e,t){this.textureMain.image[t*4+3]=e,this.textureMain.needsUpdate=!0}}class ra extends be{constructor(e){e=e;const t=a.linesPerGeometry,s=t<<1,i=t<<2;let n=0,l=0,o=0,h=0,d=0;const u=new Float32Array(i);for(let y=0;y<i;y++){const M=y;for(let k=0;k<4;k++)u[n]=M,n+=1,l+=2;d+=1,d>e.width-1&&(d=0)}n=0,l=0;let f=1,g=1;const _=new Float32Array(i*2),m=new Float32Array(i*2);for(let y=0;y<s;y++)_[h+0]=-1*f,_[h+1]=-1*g,m[h+0]=0,m[h+1]=0,_[h+2]=-1*f,_[h+3]=1*g,m[h+2]=0,m[h+3]=1,_[h+4]=1*f,_[h+5]=-1*g,m[h+4]=1,m[h+5]=0,_[h+6]=1*f,_[h+7]=1*g,m[h+6]=1,m[h+7]=1,h+=8;const p=new Float32Array(i);let w=0;for(let y=0;y<s;y++){const M=y;p[w]=M,p[w+1]=M,p[w+2]=M,p[w+3]=M,w+=4}l=0;const v=new Uint32Array(i*3);for(let y=0;y<t;y++)v[o+0]=l,v[o+1]=v[o+4]=l+1,v[o+2]=v[o+3]=l+2,v[o+5]=l+3,l+=4,o+=12;const x={uid:{data:u},side:{size:2,data:_},uv:{size:2,data:m},index:{data:v},zs:{size:1,data:p}};super(a.gl,x),this.count=t}generate(){const e=this.attributes.zs.data;for(let t=0;t<this.count;t++){const s=a.rand(),i=t*4;e[i]=s,e[i+1]=s,e[i+2]=s,e[i+3]=s}this.attributes.zs.needsUpdate=!0}}class aa{constructor(e,t,s){this.idx=e,this.data=t,this.dataColors=s,this._x=0,this._y=0}reset(){this.x=0,this.y=0,this.alpha=0}setRGB(e,t=-1){this.dataColors.setRGB(e,this.idx),t!=-1&&this.dataColors.setAlpha(t,this.idx)}set x(e){this._x=e,this.data.setX(this._x,this.idx)}get x(){return this._x}set y(e){this._y=e,this.data.setY(this._y,this.idx)}get y(){return this._y}set z(e){this._z=e,this.data.setZ(this._z,this.idx)}get z(){return this._z}set w(e){this._w=e,this.data.setW(this._w,this.idx)}get w(){return this._w}}class na extends Le{constructor(e,t){const s=new ra(e);super(a.gl,{geometry:s,program:t}),this.lines=[];for(let i=0;i<e.count;i++)this.lines.push(new aa(i,e));this.idxLine=0}generate(){this.geometry.generate()}get(){if(!this.helpers)throw new Error("Property 'helpers' set to false. Switch to true to be able to target lines through objects.");if(this.lines.length<=0)throw new Error("No more line available.");return this.lines.pop()}}var oa=`#define M_PI 3.1415 #define HALF_PI 1.5707 _u _f ugenhash; #injectUniforms _u _v2 uResolution;_u _f uScreenRatio;_u _v2 uScreenRatioV2;_u _v2 uOffset;_u _f uPercentGrid;_u bool uSkipMask;_u _v3 uLineColor;_u bool uIsFlower;_u _s2 tColor;_u bool hasToCheckColor;_u _f uIDAdd;_u _f uMarg;in _f uid;in _v2 side;in _v2 uv;in _f zs;out _v2 vUv;out _v3 vColor;out _f isVisible;out _f isVisibles[4];out _f vUid;out _f vModColor1;out _f vModColor2;out _f vAlpha;out _v3 vLineColor; #i_ noiseUtils #i_ snoise2d #i_ rgb2hsl #i_ hsl2rgb #i_ cubic _f _getUID(){return uid+uIDAdd;}_f vhash(_v3 p){p=fract(p*0.3183099+.1);p*=17.0;return fract(p.x*p.y*p.z*(p.x+p.y+p.z));}_f vnoise(in _v3 x){_v3 i=floor(x);_v3 f=fract(x);f=f*f*(3.0-2.0*f);return mix(mix(mix(vhash(i+_v3(0,0,0)),vhash(i+_v3(1,0,0)),f.x),mix(vhash(i+_v3(0,1,0)),vhash(i+_v3(1,1,0)),f.x),f.y),mix(mix(vhash(i+_v3(0,0,1)),vhash(i+_v3(1,0,1)),f.x),mix(vhash(i+_v3(0,1,1)),vhash(i+_v3(1,1,1)),f.x),f.y),f.z);}_f hash12(_v2 p){_v3 p3=fract(_v3(p.xyx)*.1031);p3+=dot(p3,p3.yzx+33.33);return fract((p3.x+p3.y)*p3.z);}_f cbv(_v3 p1,_v3 p2,_v3 rgbToCompare){_f dx=p2.x-p1.x;_f dy=p2.y-p1.y;_f a=atan(dy,dx);_f dist=sqrt(dx*dx+dy*dy);_f acc=dist/2.;_f x=p1.x;_f y=p1.y;for(int i=0;i<2;i++){_v3 p=_t(tPattern,_v2(x,y)).rgb;_f diff=abs(p.z-rgbToCompare.z);if(diff>uVisibleThreshold){return 0.;}x+=cos(a)*acc;y+=sin(a)*acc;}return 1.;}_f mapToPower(_f value,_f minValue,_f maxValue,_f power){_f valueSign=sign(value);value=(value-minValue)/(maxValue-minValue);value=valueSign>0. ? value : value-1.;value=pow(value*valueSign,abs(power));value=valueSign>0. ? value : 1.-value;return value*(maxValue-minValue)+minValue;}_f rbp(_f minValue,_f maxValue,_f power){if(minValue==maxValue){return minValue;}_f value=hash12(_v2(_getUID(),ugenhash))*(maxValue-minValue)+minValue;return mapToPower(value,minValue,maxValue,power);}_v3 iqhash3(_v2 p){_v3 q=_v3(dot(p,_v2(127.1,311.7)),dot(p,_v2(269.5,183.3)),dot(p,_v2(419.2,371.9)));return fract(sin(q)*43758.5453);}_f iqnoise(in _v3 P,_f u,_f v){_v2 x=P.xy;_v2 p=floor(x);_v2 f=fract(x);_f k=1.0+63.0*pow(1.0-v,4.0);_f va=0.0;_f wt=0.0;for(int j=-2;j<=2;j++)for(int i=-2;i<=2;i++){_v2 g=_v2(_f(i),_f(j));_v3 o=iqhash3(p+g)*_v3(u,u,1.0);o=0.5+0.5*sin(P.z+6.2831*o);_v2 r=g-f+o.xy;_f d=dot(r,r);_f ww=pow(1.0-smoothstep(0.0,1.414,sqrt(d)),k);va+=o.z*ww;wt+=ww;}return va/wt;}_f fxrand(){return hash12(_v2(_getUID(),ugenhash));}_f _fxrandInc=0.;_f fxrandInc(){_fxrandInc+=.1;return hash12(_v2(_getUID()+_fxrandInc,ugenhash+_fxrandInc));}out _v3 vDebug;void main(){vUv=uv;_f id=_getUID();_f width=1000.0;_f height=1000.0;_f x=mod(id,width);_f y=floor(id/width);_v2 uvDataTexture=_v2((x+0.5)/width,(y+0.5)/height);vec4 dataMain=_t(tDataMain,uvDataTexture);vec4 dataMain2=dataMain.xyzw;dataMain2.x=mod(dataMain2.x+uOffset.x,1.);dataMain2.y=mod(dataMain2.y+uOffset.y,1.);_f mrgo=uMarg;dataMain2.x=(dataMain2.x*1.-.5)*(2.-mrgo*uScreenRatioV2.x);dataMain2.y=(dataMain2.y*1.-.5)*(2.-mrgo*uScreenRatioV2.y);_v2 uvFlow=dataMain2.xy*.5+.5;vec4 colorValue=_t(tPattern,dataMain2.xy);vec4 flow=_t(tFlow,uvFlow);_f valueFlow=(flow.r+flow.g)*0.5*uValueFlowAdjust;_f angleFlow=atan(flow.y,flow.x);_f rt=0.;_f canAdd=0.;_f rotationType=uRotType;\${rotation}_f segmentLength=uLengthM+rbp(0.,uLengthA,uLengthP);_f segmentTh=uThM+rbp(0.,uThA,uThP);_v3 posBase=_v3(0.);posBase.x+=side.x*(segmentLength/uResolution.x);posBase.y+=side.y*(segmentTh/uResolution.y)*(2.*1./uScreenRatio);_f sinRot=sin(rt);_f cosRot=cos(rt);_v3 p1=_v3(0.);p1.x=-1.*(segmentLength/uResolution.x);p1.x=0.;_f p1x=p1.x;_f p1y=p1.y;p1.x=cosRot*p1x-sinRot*p1y;p1.y=sinRot*p1x+cosRot*p1y;p1.y*=uScreenRatio;p1+=(dataMain2.xyz*.5+.5);_v3 p2=_v3(0.);p2.x=1.*(segmentLength/uResolution.x);_f p2x=p2.x;_f p2y=p2.y;p2.x=cosRot*p2x-sinRot*p2y;p2.y=sinRot*p2x+cosRot*p2y;p2.y*=uScreenRatio;p2+=(dataMain2.xyz*.5+.5);if(uDontUsePattern==true){isVisible=1.;isVisibles[3]=1.;}else{isVisibles[3]=cbv(p1,p2,_v3(1.,1.,1.));_f isVisibleSum=isVisibles[3];isVisible=isVisibleSum>0. ? 1. : 0.;}vec4 valueGrid=_t(tGrid,p1.xy);if(uSkipMask==false){isVisibles[3]*=valueGrid.r<uPercentGrid ? 0. : 1.;}_f posBasex=posBase.x;_f posBasey=posBase.y;posBase.x=cosRot*posBasex-sinRot*posBasey;posBase.y=sinRot*posBasex+cosRot*posBasey;posBase.y*=uScreenRatio;_v2 pUV=posBase.xy;pUV+=(dataMain2.xy*.5+.5);_f hue=rbp(-.03,.06,1.);_f saturation=rbp(-.05,.05,1.);_f luminosity=rbp(-.1,.1,1.);vAlpha=rbp(uAlpha.x,uAlpha.y,4.);vColor=_v3(hue,saturation,luminosity);vLineColor=uLineColor;posBase+=_v3(dataMain2.x,dataMain2.y,0.);_v4 pos=_v4(posBase,1.);vModColor1=vnoise(_v3((dataMain2.x)*uCaScale,(dataMain2.y)*uCaScale,0.))*uCaValue;vModColor2=vnoise(_v3((dataMain2.x)*uCaScale,(dataMain2.y)*uCaScale,0.))*uCaValue;_f percentModColor=snoise2d(_v2((dataMain2.x)*uCaScale2,(dataMain2.y)*uCaScale2));_f baseValue2=1.-uCaValue2;vModColor1*=(baseValue2+percentModColor*uCaValue2);vModColor2*=(baseValue2+percentModColor*uCaValue2);if(valueGrid.r<.9){_f rx=1.-mrgo*(.5-mrgo)*uScreenRatioV2.x;_f ry=1.-mrgo*(.5-mrgo)*uScreenRatioV2.y;pos.x=max(-rx,min(pos.x,rx));pos.y=max(-ry,min(pos.y,ry));}else{_f rx=1.-mrgo*.5*(.5-mrgo*.5)*uScreenRatioV2.x;_f ry=1.-mrgo*.5*(.5-mrgo*.5)*uScreenRatioV2.y;pos.x=max(-rx,min(pos.x,rx));pos.y=max(-ry,min(pos.y,ry));}gl_Position=pos;vUid=_getUID();}`,la=`#ifndef PI #define PI 3.141592653589793 #endif #injectUniforms _u _v3 uLineColor;_u bool uIsNormal;in _v2 vUv;in _v3 vColor;in _f isVisible;in _f isVisibles[4];in _f vUid;in _f vModColor1;in _f vModColor2;in _f vAlpha;in _f vBrush; #i_ rgb2hsl #i_ hsl2rgb #i_ cubic #i_ exponential layout(location=0)out vec4 outColor0;_v3 applyMod(_v3 color,_v3 mod){_f hue=color.r+mod.r;_f sat=color.g+mod.g;_f lum=color.b+mod.b;color=hsl2rgb(hue,sat,lum);return color;}in _v3 vDebug;in _v3 vLineColor;void main(){if(vUid>uCountLines){discard;}_v3 color=rgb2hsl(vLineColor);_f hue=color.r+vColor.r;_f sat=color.g+vColor.g-vModColor1*.2+uCaSat*exponentialOut(vUv.y);_f lum=color.b+vColor.b-vModColor2*.4-uCaLum*cubicIn(vUv.y);color=hsl2rgb(hue,sat,lum);_f a=1.;outColor0=vec4(color,vAlpha)*isVisibles[3];if(uDontUsePattern==true){outColor0=vec4(color,vAlpha);}outColor0.a*=a;}`;const Qe={0:` rt = fxrandInc() * M_PI * 2.; canAdd = 1.; `,1:` if( fxrandInc() < .75 ) { rt = fxrandInc() * M_PI * 2.; canAdd = 1.; } else { if( fxrandInc() < .5 ) { rt = 0.; } else { rt = M_PI * .5; } } `,2:` if( fxrandInc() < .3 ) { rt = fxrandInc() * M_PI * 2.; canAdd = 1.; } else { if( fxrandInc() < .5 ) { rt = 0.; } else { rt = M_PI * .5; } } `,3:` rt = vnoise( vec3( ( dataMain.x + ugenhash * .001 ) * uRotNoise.x, ( dataMain.y + ugenhash * .001 ) * uRotNoise.y, 0. ) ); rt *= M_PI * 2.; rt += mix( angleFlow * uAngleFlowBoost, fxrandInc() * M_PI * 2., valueFlow * .1 ); `,4:` if( fxrandInc() < .675 ) { rt = iqnoise( vec3( ( dataMain.x + ugenhash * .001 ) * uRotNoise.x, ( dataMain.y + ugenhash * .001 ) * uRotNoise.y, 0. ), .2, .0 ) * M_PI * 2.; } else { if( fxrandInc() < .5 ) { rt = 0.; } else { rt = M_PI * .5; } } `,6:` rt = mix( angleFlow * uAngleFlowBoost, fxrandInc() * M_PI * 2., valueFlow * .1 ); rt += mix( angleFlow * uAngleFlowBoost, fxrandInc() * M_PI * 2., valueFlow * .1 ); `,7:` vec2 treesOrientations = texture( tTreesOrientation, uvFlow ).rg; treesOrientations.rg -= .5; rt = atan( treesOrientations.y, treesOrientations.x ); rt += mix( angleFlow * uAngleFlowBoost * .1, fxrandInc() * M_PI * 2., valueFlow * .1 ); `,8:` vec2 treesOrientations = texture( tTreesOrientation, uvFlow ).rg; treesOrientations.rg -= .5; rt = atan( treesOrientations.y, treesOrientations.x ) + M_PI * .5; rt += mix( angleFlow * uAngleFlowBoost, fxrandInc() * M_PI * 2., valueFlow * .1 ); `},et=new E(1,1,1);class ha extends j{constructor(e={},t=!1){super(1),this._skipMask=t;const s=1e3;this._texData=new ia(s,s),e.tDataMain=this._texData.textureMain,this._programLinker=new Bt,this._programLinker.init({uniforms:{ugenhash:{value:0},sizePlanes:{value:10}},vs:oa,fs:la,textures:e,dataFroms:c.vegeLinesData});const i=this.u;i.uLineColor={value:et},i.uOffset={value:new F(0,0)},i.uPercentGrid={value:1},i.uSkipMask={value:!1},i.uIsNormal={value:!0},i.uIsFlower={value:!1},i.tBrushes={value:a.textureBrushes},i.tColor={value:a.textureBrushes},i.hasToCheckColor={value:!1},i.uIDAdd={value:0},i.uMarg={value:a.isPrint?.017:0},this._programs={};for(const n in Qe){const l=Qe[n],o=this._programLinker.vs.replace("${rotation}",l);this._programs[n]=new ae(a.gl,{vertex:o,fragment:this._programLinker.fs,uniforms:this._programLinker.uniforms,transparent:!0,cullFace:a.gl.FRONT,depthWrite:!1})}this._program=this._programs[0]||new ae(a.gl,{vertex:this._programLinker.vs,fragment:this._programLinker.fs,uniforms:this._programLinker.uniforms,transparent:!0,cullFace:a.gl.FRONT,depthWrite:!1}),this._mesh=new na(this._texData,this._program),this.addChild(this._mesh),this._hasLineBeenGenerated=!1}async generate(){if(!this._hasLineBeenGenerated){let e=0;const t=this._mesh.lines;for(const s of t)s.x=a.rand(),s.y=a.rand(),s.z=a.rand(),s.w=a.rand(),e++,e%25e3===0&&await P();this._hasLineBeenGenerated=!0}this._mesh.generate()}render({hasToClear:e=!0,hasToUpdateUniforms:t=!0}={}){e||(a.gl.renderer.autoClear=!1,a.gl.clearColor(0,0,0,0));const s=this._programs[this.u.uRotType.value]||this._program;this._mesh.program=s,super.render({hasToClear:e,hasToUpdateUniforms:t})}clear(){a.gl.clearColor(a.bgColor.r,a.bgColor.g,a.bgColor.b,0),a.gl.renderer.autoClear=!0,this._render(this,this._renderTarget,!0),a.gl.renderer.autoClear=!1}prepare({uDontUsePattern:e=!1,uRotType:t=0,uLengthA:s=100,uCountLines:i=1e6,uLineColor:n=et,uAlpha:l=null,uOffset:o=new F(0,0)}){const h=this.u;l&&(h.uAlpha.value.x=l.min,h.uAlpha.value.y=l.max),h.uLengthA.value=s,h.uRotType.value=t,h.uCountLines.value=i,h.uDontUsePattern.value=e,h.uLineColor.value=n,h.uOffset.value=o}updateForTrees(e,t=!0,s=!1){const i=this.u;i.tPattern.value=i.tTrees.value,i.uDontUsePattern.value=!1,i.uLengthM.value=c.treesData.lengthM+(s?20:-10),i.uLengthA.value=c.treesData.lengthA,i.uLengthP.value=c.treesData.lengthP,i.uThM.value=c.treesData.thM+(s?.1:-.1),i.uThA.value=c.treesData.thA,i.uThP.value=c.treesData.thP,i.uRotType.value=7,i.uAlpha.value.x=c.treesData.alpha,i.uAlpha.value.y=c.treesData.alpha+.01,i.ugenhash.value=a.seed+1234,i.uLineColor.value=new E(c.treesData.color),i.uCountLines.value=c.treesData.countLines,i.uSkipMask.value=t,i.uPercentGrid.value=e,i.uIsFlower.value=!1}updateForFlowers(e,t,s=null,i=!0){const n=this.u,l=c.treesData.flowers;n.tPattern.value=n.tTrees.value,n.uDontUsePattern.value=!1,n.uLengthM.value=l.lengthM,n.uLengthA.value=l.lengthA,n.uLengthP.value=l.lengthP,n.uThM.value=l.thM,n.uThA.value=l.thA,n.uThP.value=l.thP,n.uRotType.value=8,n.uAlpha.value.x=l.alpha,n.uAlpha.value.y=l.alpha+.01,n.ugenhash.value=a.seed+1234,n.uLineColor.value=new E(s||l.color),n.uCountLines.value=l.countLines,n.uAngleFlowBoost.value=l.angleFlowBoost,i?(n.uSkipMa
ogramLinker=new Bt({width:this._width,height:this._height}),this._programLinker.init({uniforms:e,textures:t,vs:s,fs:i,dataFroms:l}),this.mesh=Br({uniforms:this._programLinker.uniforms,vertex:this._programLinker.vs,fragment:this._programLinker.fs,width:2,height:2}),this.addChild(this.mesh)),this._onInit()}_onInit(){}refreshTextures(e){this._programLinker.refreshTextures(e)}_createRT(e,t){const s={width:this._width,height:this._height,minFilter:a.gl.LINEAR,magFilter:a.gl.NEAREST,wrapS:a.gl.CLAMP_TO_EDGE,wrapT:a.gl.CLAMP_TO_EDGE,color:e,depth:!1},i=Object.assign({},s,t);return new Ie(a.gl,i)}generate(){}updateProgramLinker(){this._programLinker?.update()}render({hasToClear:e=!0,hasToUpdateUniforms:t=!0}={}){t&&this._programLinker?.update(),this._render(this,this._renderTarget,e)}_setClear(e=-1,t=1){e>=0&&(e=e instanceof E?e:new E(e),a.gl.clearColor(e.r,e.g,e.b,t))}_render(e,t,s=!0){a.renderer.render({scene:e,camera:this._camera,target:t,sort:!1,update:!1,clear:s})}clear(){a.gl.clearColor(a.bgColor.r,a.bgColor.g,a.bgColor.b,0),a.gl.renderer.autoClear=!0,this._render(this,this._renderTarget,!0),a.gl.renderer.autoClear=!1}get uniforms(){return this._programLinker.uniforms}get u(){return this.uniforms}get texture(){return this._renderTarget.texture}get textures(){return this._renderTarget.textures}get renderTarget(){return this._renderTarget}get camera(){return this._camera}}var Ir=`#define M_PI 3.1415926535897932384626433832795 #i_ noiseUtils #i_ snoise2d _v4 pperm(_v4 x){return mod(((x*34.0)+1.0)*x,289.0);}_v4 ptisq(_v4 r){return 1.79-0.85*r;}_v3 pfade(_v3 t){return t*t*t*(t*(t*6.0-15.0)+10.0);}_f pnoise(_v3 P){_v3 Pi0=floor(P);_v3 Pi1=Pi0+_v3(1.0);Pi0=mod(Pi0,289.0);Pi1=mod(Pi1,289.0);_v3 Pf0=fract(P);_v3 Pf1=Pf0-_v3(1.0);_v4 ix=_v4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);_v4 iy=_v4(Pi0.yy,Pi1.yy);_v4 iz0=Pi0.zzzz;_v4 iz1=Pi1.zzzz;_v4 ixy=pperm(pperm(ix)+iy);_v4 ixy0=pperm(ixy+iz0);_v4 ixy1=pperm(ixy+iz1);_v4 gx0=ixy0/7.0;_v4 gy0=fract(floor(gx0)/7.0)-0.5;gx0=fract(gx0);_v4 gz0=_v4(0.5)-abs(gx0)-abs(gy0);_v4 sz0=step(gz0,_v4(0.0));gx0-=sz0*(step(0.0,gx0)-0.5);gy0-=sz0*(step(0.0,gy0)-0.5);_v4 gx1=ixy1/7.0;_v4 gy1=fract(floor(gx1)/7.0)-0.5;gx1=fract(gx1);_v4 gz1=_v4(0.5)-abs(gx1)-abs(gy1);_v4 sz1=step(gz1,_v4(0.0));gx1-=sz1*(step(0.0,gx1)-0.5);gy1-=sz1*(step(0.0,gy1)-0.5);_v3 g000=_v3(gx0.x,gy0.x,gz0.x);_v3 g100=_v3(gx0.y,gy0.y,gz0.y);_v3 g010=_v3(gx0.z,gy0.z,gz0.z);_v3 g110=_v3(gx0.w,gy0.w,gz0.w);_v3 g001=_v3(gx1.x,gy1.x,gz1.x);_v3 g101=_v3(gx1.y,gy1.y,gz1.y);_v3 g011=_v3(gx1.z,gy1.z,gz1.z);_v3 g111=_v3(gx1.w,gy1.w,gz1.w);_v4 norm0=ptisq(_v4(dot(g000,g000),dot(g010,g010),dot(g100,g100),dot(g110,g110)));g000*=norm0.x;g010*=norm0.y;g100*=norm0.z;g110*=norm0.w;_v4 norm1=ptisq(_v4(dot(g001,g001),dot(g011,g011),dot(g101,g101),dot(g111,g111)));g001*=norm1.x;g011*=norm1.y;g101*=norm1.z;g111*=norm1.w;_f n000=dot(g000,Pf0);_f n100=dot(g100,_v3(Pf1.x,Pf0.yz));_f n010=dot(g010,_v3(Pf0.x,Pf1.y,Pf0.z));_f n110=dot(g110,_v3(Pf1.xy,Pf0.z));_f n001=dot(g001,_v3(Pf0.xy,Pf1.z));_f n101=dot(g101,_v3(Pf1.x,Pf0.y,Pf1.z));_f n011=dot(g011,_v3(Pf0.x,Pf1.yz));_f n111=dot(g111,Pf1);_v3 fade_xyz=pfade(Pf0);_v4 n_z=mix(_v4(n000,n100,n010,n110),_v4(n001,n101,n011,n111),fade_xyz.z);vec2 n_yz=mix(n_z.xy,n_z.zw,fade_xyz.y);_f n_xyz=mix(n_yz.x,n_yz.y,fade_xyz.x);return 2.2*n_xyz;} #injectUniforms _f sn3m(_v3 v,_f nb){const _v2 C=_v2(1.0/6.0,1.0/3.0);const _v4 D=_v4(0.0,0.5,1.0,2.0);_v3 i=floor(v+dot(v,C.yyy));_v3 x0=v-i+dot(i,C.xxx);_v3 g=step(x0.yzx,x0.xyz);_v3 l=1.0-g;_v3 i1=min(g.xyz,l.zxy);_v3 i2=max(g.xyz,l.zxy);_v3 x1=x0-i1+C.xxx;_v3 x2=x0-i2+C.yyy;_v3 x3=x0-D.yyy;i=mod289(i);_v4 p=permute(permute(permute(i.z+_v4(0.0,i1.z,i2.z,1.0))+i.y+_v4(0.0,i1.y,i2.y,1.0))+i.x+_v4(0.0,i1.x,i2.x,1.0));_f n_=0.1428;_v3 ns=n_*D.wyz-D.xzx;_v4 j=p-49.0*floor(p*ns.z*ns.z);_v4 x_=floor(j*ns.z);_v4 y_=floor(j-7.0*x_);_v4 x=x_*ns.x+ns.yyyy;_v4 y=y_*ns.x+ns.yyyy;_v4 h=1.0-abs(x)-abs(y);_v4 b0=_v4(x.xy,y.xy);_v4 b1=_v4(x.zw,y.zw);_v4 s0=floor(b0)*2.0+1.0;_v4 s1=floor(b1)*2.0+1.0;_v4 sh=-step(h,_v4(0.));_v4 a0=b0.xzyw+s0.xzyw*sh.xxyy;_v4 a1=b1.xzyw+s1.xzyw*sh.zzww;_v3 p0=_v3(a0.xy,h.x);_v3 p1=_v3(a0.zw,h.y);_v3 p2=_v3(a1.xy,h.z);_v3 p3=_v3(a1.zw,h.w);if(uModMax2==true){p0=max(p0,_v3(0.));p1=max(p1,_v3(0.));p2=max(p2,_v3(0.));p3=max(p3,_v3(0.));}_v4 norm=taylorInvSqrt(_v4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;_f m0=dot(x0,x0);_f m1=dot(x1,x1);_f m2=dot(x2,x2);_f m3=dot(x3,x3);_v4 m=_v4(0.);if(uModMax==true){m=max(nb-_v4(m0,m1,m2,m3),0.);}else{m=nb-_v4(m0,m1,m2,m3);};m=m*m;m=m*m*m*m*m;_f noise=42.*dot(m,_v4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3)));return noise;}_v3 snv3m(_v3 x,_f noiseBase){_f s=sn3m(_v3(x),noiseBase);_f s1=sn3m(_v3(x.y-19.1,x.z+33.4,x.x+47.2),noiseBase);_f s2=sn3m(_v3(x.z+74.2,x.x-124.5,x.y+99.4),noiseBase);_v3 c=_v3(s,s1,s2);return c;}_v3 cnm(_v3 p,_f nb){const _f e=.1;_v3 dx=_v3(e,0.0,0.0);_v3 dy=_v3(0.0,e,0.0);_v3 dz=_v3(0.0,0.0,e);_v3 p_x0=snv3m(p-dx,nb);_v3 p_x1=snv3m(p+dx,nb);_v3 p_y0=snv3m(p-dy,nb);_v3 p_y1=snv3m(p+dy,nb);_v3 p_z0=snv3m(p-dz,nb);_v3 p_z1=snv3m(p+dz,nb);_f x=p_y1.z-p_y0.z-p_z1.y+p_z0.y;_f y=p_z1.x-p_z0.x-p_x1.z+p_x0.z;_f z=p_x1.y-p_x0.y-p_y1.x+p_y0.x;const _f divisor=1.0/(2.0*e);return normalize(_v3(x,y,z)*divisor);}_u _f uSeed;_u _v2 uResolution;_u _f uScreenRatio;in _v2 vUv;_lay 0)out _v4 outColor0;_vm_v2 uv=vUv*_v2(uScreenRatio,1.);uv.x+=uOffset;_v2 uvOrigin=uv;_v3 curl=_v3(0.);_v2 zeroUV=_v2(0.);_v2 valueTest=_v2(0.);_f cum=uCUvMult;_f cra=uCRatioAccu;_v2 ucu=cum*_v2(uCUvMultX,uCUvMultY);_f crx=uCRatioX*cra;_f cry=uCRatioY*cra;curl=cnm(_v3((uv+zeroUV)*ucu,uSeed*uCSeedMult),uModBase);curl*=uCStr;uv.x+=curl.x*crx;uv.y+=curl.y*cry;valueTest.x+=curl.x*crx;valueTest.y+=curl.y*cry;for(int i=0;i<uCLoop;i++){curl=cnm(_v3((uv+zeroUV)*ucu,uSeed*uCSeedMult),uModBase);curl*=uCStr;uv.x+=curl.x*crx;uv.y+=curl.y*cry;valueTest.x+=curl.x*crx;valueTest.y+=curl.y*cry;}_v2 valueTest2=_v2(0.);_v2 uv2=uvOrigin;_v2 suv=_v2(uSnUvMultX,uSnUvMultY);_f cvalue=snoise2d(_v2(uv2*uSnUvMult*suv+uSeed*uSnSeedMult))*M_PI;cvalue*=uSnStr;_f srx=uSnRatioX*uSnRatioAccu;_f sry=uSnRatioY*uSnRatioAccu;uv2.x+=cos(cvalue)*srx;uv2.y+=sin(cvalue)*sry;valueTest2.x+=cos(cvalue)*srx;valueTest2.y+=sin(cvalue)*sry;for(int i=0;i<uSnLoop;i++){cvalue=snoise2d(_v2(uv2*uSnUvMult*suv+uSeed*uSnSeedMult))*M_PI;cvalue*=uSnStr;uv2.x+=cos(cvalue)*srx;uv2.y+=sin(cvalue)*sry;valueTest2.x+=cos(cvalue)*srx;valueTest2.y+=sin(cvalue)*sry;}_f pvalue=pnoise(_v3(uvOrigin*uPNoiseUvMult,uSeed*uPNoiseSeedMult))*uPNoiseStr;_v2 uvMix=mix(uv,uv2,uMixRatio);_v2 uvFinal=mix(uv,uvMix,pvalue);_v2 uvTestMix=mix(valueTest,valueTest2,uMixRatio*pvalue);_v2 uvTestFinal=mix(valueTest,uvTestMix,pvalue);outColor0=_v4(normalize(uvTestMix.xy),0.,1.);}`;class Gr extends j{constructor(e){const t=a.gl;super(.15,{type:t.FLOAT,internalFormat:t.renderer.isWebgl2?t.RGBA32F:t.RGBA,wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,generateMipmaps:!1,minFilter:t.NEAREST,magFilter:t.NEAREST}),this.init({fs:Ir,textures:e,dataFroms:[c.flowData]})}render(){this.uniforms.uSeed.value=a.seed,this.uniforms.uOffset.value=a.rand()*100-50,super.render({hasToUpdateUniforms:a.renderingMode=="animated"?!a.isOver:!0})}}class Nr{constructor(){this.possibleCols=[];let e=2048;for(;e>4;)this.possibleCols.push(e),e>>=1;this.possibleLines=[];let t=1024;for(;t>4;)this.possibleLines.push(t),t>>=1}getNewRandomCellSize(e=1024){const t=[];let s=e;for(;s>4;)t.push(s),s>>=1;return s=t[a.rand2()*t.length>>0],a.size.height/s}getNextPowerOfTwo(e){const t=[];let s=e;for(;s>=2;)s&s-1||t.push(s),s>>=1;const i=a.rand2()*t.length>>0;return t[i]}getPowerOfTwoBetween(e,t){const s=[];let i=t;for(;i>=e;)i&i-1||s.push(i),i>>=1;const n=a.rand2()*s.length>>0;return s[n]}}const Or=new Nr;class G{constructor({width:e=a.size.width,height:t=a.size.height,ratio:s=1,hasToCreateDebugMesh:i=!1,renderTargetOpts:n={},willReadFrequently:l=!1}={}){this._width=e*s,this._height=t*s,this._ratio=s,this._willReadFrequently=l,this._initEngine(n),i&&this._createDebugMesh()}_initEngine(e){this.canvas=document.createElement("canvas"),this.canvas.width=this._width,this.canvas.height=this._height,this.canvas.classList.add("patterns"),this.ctx=this.canvas.getContext("2d",{willReadFrequently:this._willReadFrequently});const t={image:this.canvas,minFilter:a.gl.NEAREST,magFilter:a.gl.NEAREST,generateMipmaps:!1},s=Object.assign({},t,e);this._texture=new oe(a.gl,s)}_createDebugMesh(){this._uniforms={uTexture:{value:this._texture},uOpacity:{value:.2}},this.mesh=new Le(a.gl,{geometry:new Ve(a.gl,{width:1,height:1}),program:new ae(a.gl,{vertex:` attribute vec2 uv; attribute vec3 position; varying vec2 vUv; void main() { vUv = uv; gl_Position = vec4( position * 2., 1.0 ); } `,fragment:` precision highp float; uniform sampler2D uTexture; uniform float uOpacity; varying vec2 vUv; void main() { gl_FragColor = texture2D( uTexture, vUv ) * uOpacity; } `,uniforms:this._uniforms,transparent:!0})})}createDebugView({ratioSize:e=.05,marginTop:t=10}={}){this.canvas.style.zIndex=1001,this.canvas.style.width=this._width*e+"px",this.canvas.style.height=this._height*e+"px",this.canvas.style.top=idx*this._height*e+t+"px",this.canvas.style.left="5px",this.canvas.style.transform="translate( 0, 0 )",this.canvas.style.border="2px solid #444",this.canvas.classList.add("debug"+idx),document.body.appendChild(this.canvas)}clear({clearColor:e="#000"}={}){this.ctx.fillStyle=e,this.ctx.fillRect(0,0,this._width,this._height)}draw(){}render(){}_refreshDebugMesh(){this._uniforms.uOpacity.value=.1}resize(e,t){this._width=e*this._ratio,this._height=t*this._ratio,this.canvas.width=this._width,this.canvas.height=this._height,this.canvas.style.width=this._width+"px",this.canvas.style.height=this._height+"px",this._texture.needsUpdate=!0}dispose(){this.canvas.width=0,this.canvas.height=0,this.canvas=null,this._texture.dispose()}get texture(){return this._texture}get width(){return this._width}get height(){return this._height}get ratio(){return this._ratio}}const P=()=>new Promise(requestAnimationFrame);function je(r){this.p=new Uint8Array(256),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(var e=0;256>e;e++)this.p[e]=256*a.rand();for(e=0;512>e;e++)this.perm[e]=this.p[255&e],this.permMod12[e]=this.perm[e]%12}var Vr=1/3,N=1/6;je.prototype={grad3:new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),noise3D:function(r,e,t){var s,i,n,l,o,h,d,u,f,g,_=this.permMod12,m=this.perm,p=this.grad3,w=(r+e+t)*Vr,v=Math.floor(r+w),x=Math.floor(e+w),y=Math.floor(t+w),M=(v+x+y)*N,k=v-M,S=x-M,U=y-M,C=r-k,L=e-S,D=t-U;C>=L?L>=D?(o=1,h=0,d=0,u=1,f=1,g=0):C>=D?(o=1,h=0,d=0,u=1,f=0,g=1):(o=0,h=0,d=1,u=1,f=0,g=1):D>L?(o=0,h=0,d=1,u=0,f=1,g=1):D>C?(o=0,h=1,d=0,u=0,f=1,g=1):(o=0,h=1,d=0,u=1,f=1,g=0);var A=C-o+N,I=L-h+N,q=D-d+N,H=C-u+2*N,Y=L-f+2*N,Se=D-g+2*N,De=C-1+3*N,Ce=L-1+3*N,Ae=D-1+3*N,he=255&v,ue=255&x,de=255&y,Q=.6-C*C-L*L-D*D;if(0>Q)s=0;else{var Pe=3*_[he+m[ue+m[de]]];Q*=Q,s=Q*Q*(p[Pe]*C+p[Pe+1]*L+p[Pe+2]*D)}var ee=.6-A*A-I*I-q*q;if(0>ee)i=0;else{var Te=3*_[he+o+m[ue+h+m[de+d]]];ee*=ee,i=ee*ee*(p[Te]*A+p[Te+1]*I+p[Te+2]*q)}var te=.6-H*H-Y*Y-Se*Se;if(0>te)n=0;else{var ze=3*_[he+u+m[ue+f+m[de+g]]];te*=te,n=te*te*(p[ze]*H+p[ze+1]*Y+p[ze+2]*Se)}var se=.6-De*De-Ce*Ce-Ae*Ae;if(0>se)l=0;else{var ke=3*_[he+1+m[ue+1+m[de+1]]];se*=se,l=se*se*(p[ke]*De+p[ke+1]*Ce+p[ke+2]*Ae)}return 32*(s+i+n+l)}};class K{constructor(e,t,s,i){this.x=e,this.y=t,this.width=s,this.height=i,this._lines=[],this._data=c.gridData.divisions,this._isFinal=!1,this._isEmpty=!1}divide(e=0,t=1){this._idxDivision=e,this._chanceDivision=t;const s=this.x,i=this.y;this._idxDivision<this._data.linesDivisions&&(this._lines.push({xFrom:s,yFrom:i,xTo:s+this.width,yTo:i}),this._lines.push({xFrom:s,yFrom:i,xTo:s,yTo:i+this.height}),this._lines.push({xFrom:s+this.width,yFrom:i,xTo:s+this.width,yTo:i+this.height}),this._lines.push({xFrom:s,yFrom:i+this.height,xTo:s+this.width,yTo:i+this.height}));const n=this._divide(this.x,this.y,this.width,this.height),l=a.rand2(),o=this._data.activateChanceFilling?l<this._data.chanceFilling:!0;n||(o?this._isFinal=!0:this._isEmpty=!0)}_divide(e,t,s,i){const n=a.rand2(),l=a.rand2();if(this._idxDivision>=this._data.maxDivisions||n>this._chanceDivision)return!1;c.gridData.divisionsType;let o=c.gridData.margin;const h=s/2-o*.5,d=i/2-o*.5;this._cells=[],l<.95&&(this._cells.push(new K(e,t,h,d)),this._cells.push(new K(e+h+o,t,h,d)),this._cells.push(new K(e,t+d+o,h,d)),this._cells.push(new K(e+h+o,t+d+o,h,d)));for(let u of this._cells)u.divide(this._idxDivision+1,this._chanceDivision*this._data.friction);return!0}seasonize(e,t){if(!this._isFinal){for(let o of this._cells)o.seasonize();return}let s=e.noise3D(this.x/c.gridData.divisions.noiseScale,this.y/c.gridData.divisions.noiseScale,0+a.seed),i=e.noise3D(this.x/c.gridData.divisions.noiseScale,this.y/c.gridData.divisions.noiseScale,1e3+a.seed);if(s=(s+1)/2,i=(s+1)/2,c.gridData.divisions.useMacroScale){const o=c.gridData.divisions.noiseScale*c.gridData.divisions.macroScale;let h=e.noise3D(this.x/o,this.y/o,0+a.seed);s+=h*.5}const n=c.compositionsData.layers.totalDivider,l=c.compositionsData.layers.totalDivider2;this.value=Math.floor(s*n)/(n-1),this.value3=s,this.value2=Math.floor(i*l)/l}draw=(e,t,s=1)=>{if(!this._isFinal)return;const i=this.value*255>>0,n=this.value3*255>>0,l=this.value2*255>>0,o=this.x*s,h=this.y*s,d=this.width*s,u=this.height*s;e.fillStyle="rgb("+i+","+i+","+n+")",t.fillStyle="rgb("+l+","+l+","+l+")",e.fillRect(o,h,d,u),t.fillRect(o,h,d,u)};drawLines=e=>{if(!this._isFinal)return;const t=2,s=t>>1;e.save(),e.strokeStyle="#fff",e.lineWidth=t,e.translate(this.x,this.y),e.strokeRect(-s,-s,this.width+s,this.height+s),e.restore()};drawEmpty=e=>{this._isEmpty&&(e.save(),e.fillStyle="#fff",e.translate(this.x,this.y),e.fillRect(0,0,this.width,this.height),e.restore())};collectFinalCells(e){if(this._isFinal){e.push(this);return}if(this._cells)for(const t of this._cells)t.collectFinalCells(e)}collectFinalLines(e){if(this._lines)for(let t=0;t<this._lines.length;t++)e.push(this._lines[t]);if(this._cells)for(const t of this._cells)t.collectFinalLines(e)}get finalCells(){if(this._isFinal)return[this];if(!this._cells)return[];const e=[];for(const t of this._cells){const s=t.finalCells;for(let i=0;i<s.length;i++)e.push(s[i])}return e}get lines(){let e=[...this._lines||[]];if(this._cells)for(const t of this._cells)e=e.concat(t.lines);return e}get emptyCells(){if(this._isEmpty)return[this];{let e=[];if(this._cells)for(let t of this._cells)e=e.concat(t.emptyCells);return e}}}class $r{constructor(e){this._ratio=e}generate(e=null,t,s){e==null&&this.clear(),this._ctx=e||this.ctx,this._ctx.willReadFrequently=!0,s.willReadFrequently=!0;let i=100+a.rand()*200>>0;const n=[{x:0,y:1},{x:1,y:0},{x:-1,y:0},{x:0,y:-1}];let l=[2,1];t==512&&(l=[4,2]),i=a.rand()*50+150>>0;for(let o=0;o<i;o++){const h=t/l[a.rand()*l.length>>0],d=a.size.width/h,u=a.size.height/h,f=a.rand()*d>>0,g=u*.5+a.rand()*u*.5>>0;let _=a.rand()*255>>0,m=_,p=_,w=0;if(e&&a.rand()<.5){p=0;for(let v of n){const x=(f+v.x)*h,y=(g+v.y)*h;if(x>=0&&x<a.size.width&&y>=0&&y<a.size.height){let M=this._getImageData(this._ctx,x,y,1,1);p+=M,M=this._getImageData(s,x,y,1,1),w++}}w>0&&(p=p/w>>0,_=p>127?Math.max(0,p-100):Math.min(255,p+100),m=p>127?Math.max(0,p-100):Math.min(255,p+100))}this._ctx.fillStyle=`rgba( ${_}, ${_}, ${_}, .5 )`,this._fillRect(this._ctx,f*h,g*h,h,h),a.rand()<.8&&(s.fillStyle=`rgba( ${m}, ${m}, ${m}, .5 )`,this._fillRect(s,f*h,g*h,h,h))}e==null&&(this.texture.needsUpdate=!0)}generateVertLines(e=null,t,s){this._ctx=e;let i=30+a.rand()*40>>0,n=1;switch(t){case 512:n=4;break;case 256:n=2;break;case 128:n=2;break}for(let l=0;l<i;l++){const o=t/n,h=a.size.height/o,d=a.size.width/o,u=a.rand()*d>>0,f=1+a.rand()*h*.5>>0,g=a.size.height/o;let _=(a.rand()*(g-Math.ceil(f/o))>>0)*o,m=a.rand()*75>>0;m=0;let p=m+75+a.rand()*100>>0;if(p=255,_<a.size.height*.5){let x=m;m=p,p=x}const w=_/o,v=f/w>>0;_-=o;for(let x=0;x<w;x++){const y=u*o,M=_+x*o*v;let k=0,S=0,U=0,C=0;y>0&&(k=this._getImageData(this._ctx,y-o,M),S=this._getImageData(s,y-o,M)),y+o<a.size.width&&(U=this._getImageData(this._ctx,y+o,M),C=this._getImageData(s,y+o,M));let L=m+(p-m)*x/w>>0,D=L;const A=(k+U)/2;Math.abs(L-A)<50&&(L=A>127?Math.max(0,A-100):Math.min(255,A+100));const I=(S+C)/2;Math.abs(D-I)<50&&(D=I>127?Math.max(0,I-100):Math.min(255,I+100)),this._ctx.fillStyle=`rgba(${L}, ${L}, ${L}, .85)`,this._fillRect(this._ctx,y,M,o,o*v),s.fillStyle=`rgba(${D}, ${D}, ${D}, .85)`,this._fillRect(s,y,M,o,o*v)}}}generateVertLines2(e=null,t,s){this._ctx=e,this._ctx.willReadFrequently=!0,s.willReadFrequently=!0;let i=30+a.rand()*40>>0,n=1;switch(t){case 512:n=4;break;case 256:n=2;break;case 128:n=2;break}for(let l=0;l<i;l++){const o=t/n,h=a.size.height/o,d=a.size.width/o,u=a.rand()*d>>0,f=1+a.rand()*h*.5>>0,g=a.size.height/o,_=a.size.height-(a.rand()*(g-Math.ceil(f/o))>>0)*o-o*f;let m=a.rand()*75>>0;m=0;let p=m+75+a.rand()*100>>0;if(p=255,_>a.size.height*.5){let v=m;m=p,p=v}const w=f;for(let v=0;v<w;v++){const x=u*o,y=_+v*o;let M=0,k=0,S=0,U=0;x>0&&(M=this._getImageData(this._ctx,x-o,y),k=this._getImageData(s,x-o,y)),x+o<a.size.width&&(S=this._getImageData(this._ctx,x+o,y),U=this._getImageData(s,x+o,y));let C=m+(p-m)*v/w>>0,L=C;const D=(M+S)/2;Math.abs(C-D)<50&&(C=D>127?Math.max(0,D-100):Math.min(255,D+100));const A=(k+U)/2;Math.abs(L-A)<50&&(L=A>127?Math.max(0,A-100):Math.min(255,A+100)),this._ctx.fillStyle=`rgba(${C}, ${C}, ${C}, .85)`,this._fillRect(this._ctx,x,y,o,o),s.fillStyle=`rgba(${L}, ${L}, ${L}, .85)`,this._fillRect(s,x,y,o,o)}}}_fillRect(e,t,s,i,n){e.fillRect(t*this._ratio,s*this._ratio,i*this._ratio,n*this._ratio)}_getImageData(e,t,s){return e.getImageData(t*this._ratio,s*this._ratio,1,1).data[0]}}class jr extends G{constructor(){const t={flipY:!1};super({renderTargetOpts:t,ratio:.25,willReadFrequently:!0}),this._textures=[],this._gridLines=new G({renderTargetOpts:t}),this._gridScene=new G({renderTargetOpts:t,ratio:.25,willReadFrequently:!0}),this._gridCustom=new $r(.25),this._noise=new je(a.rand2)}getNoiseValues(e,t){const s=Math.floor(e/this._cellSizeMin),i=Math.floor(t/this._cellSizeMin);return this._noiseCompiled[i][s]}async generate(e){this._cellSize=e,this._cells=[],this._finalCells=null;const t=c.gridData,s=t.margin,i=a.size.width/e,n=a.size.height/e,l=(a.size.width-s*(i+1))/i,o=(a.size.height-s*(n+1))/n;let h=s,d=s;for(let u=0;u<n;u++){for(let f=0;f<i;f++){const g=new K(h,d,l,o);g.divide(0,t.divisions.chance),this._cells.push(g),h+=l+s}h=s,d+=o+s,await P()}this._finalCells=[],this._finalLines=[],this._finalLines.push({xFrom:s,yFrom:s,xTo:a.size.width-s,yTo:s}),this._finalLines.push({xFrom:s,yFrom:s,xTo:s,yTo:a.size.height-s}),this._finalLines.push({xFrom:a.size.width-s,yFrom:s,xTo:a.size.width-s,yTo:a.size.height-s}),this._finalLines.push({xFrom:s,yFrom:a.size.height-s,xTo:a.size.width-s,yTo:a.size.height-s});for(const u of this._cells)u.collectFinalCells(this._finalCells),u.collectFinalLines(this._finalLines)}async seasonize(){let e=0;for(let t of this.finalCells)t.seasonize(this._noise,this),e++,e%1e3===0&&await P()}async render(){this.clear({clearColor:"#000"}),this._gridLines.clear(),this._gridScene.clear();let e=0;for(let t of this._finalCells)t.draw(this.ctx,this._gridScene.ctx,this._ratio),e%1e3==0&&await P(),e+=1;a.generator.isBroken&&(this._customizeGrid(),this._gridCustom.generate(this._gridScene.ctx,this._cellSize,this.ctx),a.generator.isBrokenVerticaly&&this._gridCustom.generateVertLines(this._gridScene.ctx,this._cellSize,this.ctx),a.generator.isExtraBrokenVerticaly&&this._gridCustom.generateVertLines2(this._gridScene.ctx,this._cellSize,this.ctx)),await P(),this.texture.needsUpdate=!0,this._gridScene.texture.needsUpdate=!0,this._gridLines.ctx.strokeStyle="rgba(255, 255, 255, 0.8)",this._gridLines.ctx.lineCap="square";for(let t of this.finalLines){if(!t||a.rand()>c.gridData.divisions.chanceDrawLine)continue;const s=t.xFrom===t.xTo,i=1+a.rand3()*6>>0;for(let n=0;n<i;n++)this._gridLines.ctx.beginPath(),this._gridLines.ctx.lineWidth=c.gridPatternData.width,s?(this._gridLines.ctx.moveTo(t.xFrom+a.rand()*8-4,t.yFrom+a.rand()*4-2),this._gridLines.ctx.lineTo(t.xTo+a.rand()*8-4,t.yTo+a.rand()*4-2)):(this._gridLines.ctx.moveTo(t.xFrom+a.rand()*4-2,t.yFrom+a.rand()*8-4),this._gridLines.ctx.lineTo(t.xTo+a.rand()*4-2,t.yTo+a.rand()*8-4)),this._gridLines.ctx.stroke(),this._gridLines.ctx.closePath()}await P(),this._gridLines.texture.needsUpdate=!0}_customizeGrid(){this._cellSize=this._cellSize;const e=a.size.width/this._cellSize,t=a.size.height/this._cellSize;if(Math.floor(a.size.width/this._cellSize),Math.floor(a.size.height/this._cellSize),a.generator.isBroken)for(let s=0;s<e;s++){let i=-1;const n=a.rand3();if(n<.33?i=a.rand3()*255:n<.66?i=a.rand3()*125:n<.75&&(i=-2),i!=-1)for(let l=0;l<t;l++){i==-2&&(i=l%2===0?25:150,s%4===0?i=l%2===0?25:150:s%4===1?i=l%2===0?125:10:s%4===2?i=200:s%4===3&&(i=l%2===0?25:225));const o=s*this._cellSize,h=l*this._cellSize;this._gridScene.ctx.fillStyle=`rgba(${i}, ${i}, ${i}, 0.5)`,this._gridScene.ctx.fillRect(o*this._ratio,h*this._ratio,this._cellSize*this._ratio,this._cellSize*this._ratio)}}for(let s=0;s<10;s++)for(let i=0;i<e;i++){if(a.rand()<.25)return;const n=i*this._cellSize,l=s*this._cellSize;this.ctx.fillStyle=`rgba(${10}, ${10}, ${10}, 0.25)`,this.ctx.fillRect(n*this._ratio,l*this._ratio,this._cellSize*this._ratio,this._cellSize*this._ratio)}}get finalCells(){return this._finalCells}get finalLines(){return this._finalLines}get textures(){return this._textures}get textureLines(){return this._gridLines.texture}get textureUV(){return this._gridUV.texture}get textureEmpty(){return this._gridEmpty.texture}get textureScene(){return this._gridScene.texture}}class qr extends G{constructor(){const e={flipY:!1};super({renderTargetOpts:e,ratio:.1})}render(e){this.clear();for(const t of e)this._renderBranch(t);this.texture.needsUpdate=!0}_renderBranch(e){this._renderLeaves(e)}_renderLeaves(e){for(const t of e.leaves){const s=this.ctx,i=this._createLinearGradient(s,t.x-t.size,t.y,t.x+t.size,t.y);i.addColorStop(0,"rgba(0,0,255,1)"),i.addColorStop(1,"rgba(255,0,255,1)");const n=this._createLinearGradient(s,t.x,t.y-t.size,t.x,t.y+t.size);n.addColorStop(0,"rgba(0,0,255,1)"),n.addColorStop(1,"rgba(0,255,255,1)"),s.save(),s.beginPath(),this._rect(s,t.x-t.size,t.y-t.size,t.size*2,t.size*2),s.clip(),s.fillStyle=i,this._fillRect(s,t.x-t.size,t.y-t.size,t.size*2,t.size*2),s.globalCompositeO
rr(r){return r=parseInt(r),[(r>>16&255)/255,(r>>8&255)/255,(r&255)/255]}function Je(r){return r===void 0?[0,0,0]:arguments.length===3?arguments:isNaN(r)?r[0]==="#"?Ke(r):Xe[r.toLowerCase()]?Ke(Xe[r.toLowerCase()]):[0,0,0]:rr(r)}class E extends Array{constructor(e){return Array.isArray(e)?super(...e):super(...Je(...arguments))}get r(){return this[0]}get g(){return this[1]}get b(){return this[2]}set r(e){this[0]=e}set g(e){this[1]=e}set b(e){this[2]=e}set(e){return Array.isArray(e)?this.copy(e):this.copy(Je(...arguments))}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this}}function ar(r,e){return r[0]=e[0],r[1]=e[1],r}function nr(r,e,t){return r[0]=e,r[1]=t,r}class F extends Array{constructor(e=0,t=e){return super(e,t),this}get x(){return this[0]}get y(){return this[1]}set x(e){this[0]=e}set y(e){this[1]=e}set(e,t=e){return e.length?this.copy(e):(nr(this,e,t),this)}copy(e){return ar(this,e),this}}class Ve extends be{constructor(e,{width:t=1,height:s=1,widthSegments:i=1,heightSegments:n=1,attributes:l={}}={}){const o=i,h=n,d=(o+1)*(h+1),u=o*h*6,f=new Float32Array(d*3),g=new Float32Array(d*3),_=new Float32Array(d*2),m=u>65536?new Uint32Array(u):new Uint16Array(u);Ve.buildPlane(f,g,_,m,t,s,0,o,h),Object.assign(l,{position:{size:3,data:f},normal:{size:3,data:g},uv:{size:2,data:_},index:{data:m}}),super(e,l)}static buildPlane(e,t,s,i,n,l,o,h,d,u=0,f=1,g=2,_=1,m=-1,p=0,w=0){const v=p,x=n/h,y=l/d;for(let M=0;M<=d;M++){let k=M*y-l/2;for(let S=0;S<=h;S++,p++){let U=S*x-n/2;if(e[p*3+u]=U*_,e[p*3+f]=k*m,e[p*3+g]=o/2,t[p*3+u]=0,t[p*3+f]=0,t[p*3+g]=o>=0?1:-1,s[p*2]=S/h,s[p*2+1]=1-M/d,M===d||S===h)continue;let C=v+S+M*(h+1),L=v+S+(M+1)*(h+1),D=v+S+(M+1)*(h+1)+1,A=v+S+M*(h+1)+1;i[w*6]=C,i[w*6+1]=L,i[w*6+2]=A,i[w*6+3]=L,i[w*6+4]=D,i[w*6+5]=A,w++}}}}class or extends be{constructor(e,{attributes:t={}}={}){Object.assign(t,{position:{size:2,data:new Float32Array([-1,-1,3,-1,-1,3])},uv:{size:2,data:new Float32Array([0,0,2,0,0,2])}}),super(e,t)}}class lr{constructor(e,{width:t,height:s,dpr:i,wrapS:n=e.CLAMP_TO_EDGE,wrapT:l=e.CLAMP_TO_EDGE,minFilter:o=e.LINEAR,magFilter:h=e.LINEAR,geometry:d=new or(e),targetOnly:u=null}={}){this.gl=e,this.options={wrapS:n,wrapT:l,minFilter:o,magFilter:h},this.passes=[],this.geometry=d,this.uniform={value:null},this.targetOnly=u;const f=this.fbo={read:null,write:null,swap:()=>{let g=f.read;f.read=f.write,f.write=g}};this.resize({width:t,height:s,dpr:i})}addPass({vertex:e="",fragment:t="",uniforms:s={},textureUniform:i="tMap",enabled:n=!0}={}){s[i]={value:this.fbo.read.texture};const l=new ae(this.gl,{vertex:e,fragment:t,uniforms:s}),h={mesh:new Le(this.gl,{geometry:this.geometry,program:l}),program:l,uniforms:s,enabled:n,textureUniform:i};return this.passes.push(h),h}resize({width:e,height:t,dpr:s}={}){s&&(this.dpr=s),e&&(this.width=e,this.height=t||e),s=this.dpr||this.gl.renderer.dpr,e=Math.floor((this.width||this.gl.renderer.width)*s),t=Math.floor((this.height||this.gl.renderer.height)*s),this.options.width=e,this.options.height=t,this.fbo.read=new Ie(this.gl,this.options),this.fbo.write=new Ie(this.gl,this.options)}render({scene:e,camera:t,texture:s,target:i=null,update:n=!0,sort:l=!0,frustumCull:o=!0,beforePostCallbacks:h}){const d=this.passes.filter(u=>u.enabled);s||(this.gl.renderer.render({scene:e,camera:t,target:d.length||!i&&this.targetOnly?this.fbo.write:i,update:n,sort:l,frustumCull:o}),this.fbo.swap(),h&&h.forEach(u=>u&&u())),d.forEach((u,f)=>{u.mesh.program.uniforms[u.textureUniform].value=!f&&s?s:this.fbo.read.texture,this.gl.renderer.render({scene:u.mesh,target:f===d.length-1&&(i||!this.targetOnly)?i:this.fbo.write,clear:!0}),this.fbo.swap()}),this.uniform.value=this.fbo.read.texture}}var hr="_m4 bmx(_f b){return _m4(1,0,0,0,0,1,0,0,0,0,1,0,b,b,b,1);}_v3 brn(_v3 c,_f v){return c+v;}",ur="_m4 contrastMatrix(_f contrast){_f t=(1.0-contrast)/2.0;return _m4(contrast,0,0,0,0,contrast,0,0,0,0,contrast,0,t,t,t,1);}_v3 contrast(_v3 color,_f value){return 0.5+value*(color-0.5);}",dr="_v3 hueshift(_v3 color,_f hue){const _v3 k=_v3(0.57735,0.57735,0.57735);_f cosAngle=cos(hue);return _v3(color*cosAngle+cross(k,color)*sin(hue)+k*dot(k,color)*(1.0-cosAngle));}_v3 hueshift2(_v3 color,_f shift){_v3 P=_v3(0.55735)*dot(_v3(0.55735),color);_v3 U=color-P;_v3 V=cross(_v3(0.55735),U);color=U*cos(shift*6.2832)+V*sin(shift*6.2832)+P;return color;}",cr="_v3 saturation(_v3 rgb,_f adjustment){const _v3 W=_v3(0.2125,0.7154,0.0721);_v3 intensity=_v3(dot(rgb,W));return mix(intensity,rgb,adjustment);}_v3 saturation2(_v3 rgb,_f adjustment){const _v3 W=_v3(0.2125,0.7154,0.0721);_v3 intensity=_v3(dot(rgb,W));return mix(rgb,intensity,adjustment);}",fr="vec3 blAverage(vec3 base,vec3 bl){return(base+bl)/2.0;}vec3 blAverage(vec3 base,vec3 bl,float opacity){return(blAverage(base,bl)*opacity+base*(1.0-opacity));}_v3 blmd(_i mode,_v3 base,_v3 bl,_f opacity){if(mode==2){return blAverage(base,bl,opacity);}}_v3 blendMode(_i mode,_v3 base,_v3 bl,_f opacity){return blmd(mode,base,bl,opacity);}",gr="_v4 sharpen(in _s2 tex,in _v2 coords,in _v2 renderSize){_f dx=1.0/renderSize.x;_f dy=1.0/renderSize.y;_v4 sum=_v4(0.0);sum+=-1.*_t(tex,coords+_v2(-1.0*dx,0.0*dy));sum+=-1.*_t(tex,coords+_v2(0.0*dx,-1.0*dy));sum+=5.*_t(tex,coords+_v2(0.0*dx,0.0*dy));sum+=-1.*_t(tex,coords+_v2(0.0*dx,1.0*dy));sum+=-1.*_t(tex,coords+_v2(1.0*dx,0.0*dy));return sum;}",_r="vec3 exposure(vec3 color,float value){return(1.0+value)*color;}_f Lum(_v3 c){return 0.299*c.r+0.587*c.g+0.114*c.b;}_v3 ClipColor(_v3 c){_f l=Lum(c);_f n=min(min(c.r,c.g),c.b);_f x=max(max(c.r,c.g),c.b);if(n<0.0)c=max((c-l)*l/(l-n)+l,0.0);if(x>1.0)c=min((c-l)*(1.0-l)/(x-l)+l,1.0);return c;}_v3 SetLum(_v3 c,_f l){c+=l-Lum(c);return ClipColor(c);}_f Sat(_v3 c){_f n=min(min(c.r,c.g),c.b);_f x=max(max(c.r,c.g),c.b);return x-n;}_v3 SetSat(_v3 c,_f s){_f cmin=min(min(c.r,c.g),c.b);_f cmax=max(max(c.r,c.g),c.b);_v3 res=_v3(0.0);if(cmax>cmin){if(c.r==cmin&&c.b==cmax){res.r=0.0;res.g=((c.g-cmin)*s)/(cmax-cmin);res.b=s;}else if(c.r==cmin&&c.g==cmax){res.r=0.0;res.b=((c.b-cmin)*s)/(cmax-cmin);res.g=s;}else if(c.g==cmin&&c.b==cmax){res.g=0.0;res.r=((c.r-cmin)*s)/(cmax-cmin);res.b=s;}else if(c.g==cmin&&c.r==cmax){res.g=0.0;res.b=((c.b-cmin)*s)/(cmax-cmin);res.r=s;}else if(c.b==cmin&&c.r==cmax){res.b=0.0;res.g=((c.g-cmin)*s)/(cmax-cmin);res.r=s;}else{res.b=0.0;res.r=((c.r-cmin)*s)/(cmax-cmin);res.g=s;}}return res;}vec3 autoExposure(_v4 artwork,_f highlights,_f shadows,bool autoExposure){_f amt=mix(highlights,shadows,Lum(artwork.rgb))*artwork.a;if(amt<0.0)amt*=2.0;_v3 res=mix(artwork.rgb,_v3(1.0),amt);if(autoExposure==true){_v3 blend=mix(_v3(1.0),pow(artwork.rgb,_v3(1.0/0.7)),amt);res=max(1.0-((1.0-res)/blend),0.0);res=SetLum(SetSat(artwork.rgb,Sat(res)),Lum(res));}return res;}vec3 autoExposure(_v4 artwork,_f highlights,_f shadows){return autoExposure(artwork,highlights,shadows,true);}",pr="_f hue2rgb(_f f1,_f f2,_f hue){if(hue<0.0)hue+=1.0;else if(hue>1.0)hue-=1.0;_f res;if((6.0*hue)<1.0)res=f1+(f2-f1)*6.0*hue;else if((2.0*hue)<1.0)res=f2;else if((3.0*hue)<2.0)res=f1+(f2-f1)*((2.0/3.0)-hue)*6.0;else res=f1;return res;}_v3 hsl2rgb(_v3 hsl){_v3 rgb;if(hsl.y==0.0){rgb=_v3(hsl.z);}else{_f f2;if(hsl.z<0.5)f2=hsl.z*(1.0+hsl.y);else f2=hsl.z+hsl.y-hsl.y*hsl.z;_f f1=2.0*hsl.z-f2;rgb.r=hue2rgb(f1,f2,hsl.x+(1.0/3.0));rgb.g=hue2rgb(f1,f2,hsl.x);rgb.b=hue2rgb(f1,f2,hsl.x-(1.0/3.0));}return rgb;}_v3 hsl2rgb(_f h,_f s,_f l){return hsl2rgb(_v3(h,s,l));}",mr="vec3 rgb2hsl(vec3 c){float cMin=min(min(c.r,c.g),c.b),cMax=max(max(c.r,c.g),c.b),delta=cMax-cMin;vec3 hsl=vec3(0.,0.,(cMax+cMin)/2.);if(delta!=0.0){if(hsl.z<.5){hsl.y=delta/(cMax+cMin);}else{hsl.y=delta/(2.-cMax-cMin);}float deltaR=(((cMax-c.r)/6.)+(delta/2.))/delta,deltaG=(((cMax-c.g)/6.)+(delta/2.))/delta,deltaB=(((cMax-c.b)/6.)+(delta/2.))/delta;if(c.r==cMax){hsl.x=deltaB-deltaG;}else if(c.g==cMax){hsl.x=(1./3.)+deltaR-deltaB;}else{hsl.x=(2./3.)+deltaG-deltaR;}hsl.x=fract(hsl.x);}return hsl;}",xr="const _v4 C=_v4(0.21,0.36,-0.57,0.02);_f snoise2d(_v2 v){_v2 i=floor(v+dot(v,C.yy));_v2 x0=v-i+dot(i,C.xx);_v2 i1;i1=(x0.x>x0.y)? _v2(1.0,0.0): _v2(0.0,1.0);_v4 x12=x0.xyxy+C.xxzz;x12.xy-=i1;i=mod(i,289.0);_v3 p=permute(permute(i.y+_v3(0.0,i1.y,1.0))+i.x+_v3(0.0,i1.x,1.0));_v3 m=max(0.5-_v3(dot(x0,x0),dot(x12.xy,x12.xy),dot(x12.zw,x12.zw)),0.0);m=m*m;m=m*m;_v3 x=2.0*fract(p*C.www)-1.0;_v3 h=abs(x)-0.5;_v3 ox=floor(x+0.5);_v3 a0=x-ox;m*=1.792-0.853*(a0*a0+h*h);_v3 g;g.x=a0.x*x0.x+h.x*x0.y;g.yz=a0.yz*x12.xz+h.yz*x12.yw;return 130.0*dot(m,g);}",vr=`const float PI=3.14;const float PI2=PI*2.;_f sn3d(_v3 v){ #i_ snoise3dpart _v4 norm=taylorInvSqrt(_v4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;_v4 m=max(0.6-_v4(dot(x0,x0),dot(x1,x1),dot(x2,x2),dot(x3,x3)),0.0);m=m*m*m;return 42.0*dot(m,_v4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3)));}_v3 snv3(_v3 x){_f s=sn3d(_v3(x));_f s1=sn3d(_v3(x.y-9.07,x.z+31.2,x.x+23.12));_f s2=sn3d(_v3(x.z+74.2,x.x-130.2,x.y+99.4));_v3 c=_v3(s,s1,s2);return c;}_v3 curlNoise(_v3 p){const _f e=.1;_v3 dx=_v3(e,0.0,0.0);_v3 dy=_v3(0.0,e,0.0);_v3 dz=_v3(0.0,0.0,e);_v3 p_x0=snv3(p-dx);_v3 p_x1=snv3(p+dx);_v3 p_y0=snv3(p-dy);_v3 p_y1=snv3(p+dy);_v3 p_z0=snv3(p-dz);_v3 p_z1=snv3(p+dz);_f x=p_y1.z-p_y0.z-p_z1.y+p_z0.y;_f y=p_z1.x-p_z0.x-p_x1.z+p_x0.z;_f z=p_x1.y-p_x0.y-p_y1.x+p_y0.x;const _f divisor=1.0/(2.0*e);return normalize(_v3(x,y,z)*divisor);}`,yr="const _v2 C=_v2(1.0/6.0,1.0/3.0);const _v4 D=_v4(0.0,0.5,1.0,2.0);_v3 i=floor(v+dot(v,C.yyy));_v3 x0=v-i+dot(i,C.xxx);_v3 g=step(x0.yzx,x0.xyz);_v3 l=1.0-g;_v3 i1=min(g.xyz,l.zxy);_v3 i2=max(g.xyz,l.zxy);_v3 x1=x0-i1+C.xxx;_v3 x2=x0-i2+C.yyy;_v3 x3=x0-D.yyy;i=mod289(i);_v4 p=permute(permute(permute(i.z+_v4(0.0,i1.z,i2.z,1.0))+i.y+_v4(0.0,i1.y,i2.y,1.0))+i.x+_v4(0.0,i1.x,i2.x,1.0));_v3 ns=0.1428*D.wyz-D.xzx;_v4 j=p-49.0*floor(p*ns.z*ns.z);_v4 x_=floor(j*ns.z);_v4 y_=floor(j-7.0*x_);_v4 x=x_*ns.x+ns.yyyy;_v4 y=y_*ns.x+ns.yyyy;_v4 h=1.0-abs(x)-abs(y);_v4 b0=_v4(x.xy,y.xy);_v4 b1=_v4(x.zw,y.zw);_v4 s0=floor(b0)*2.0+1.0;_v4 s1=floor(b1)*2.0+1.0;_v4 sh=-step(h,_v4(0.));_v4 a0=b0.xzyw+s0.xzyw*sh.xxyy;_v4 a1=b1.xzyw+s1.xzyw*sh.zzww;_v3 p0=_v3(a0.xy,h.x);_v3 p1=_v3(a0.zw,h.y);_v3 p2=_v3(a1.xy,h.z);_v3 p3=_v3(a1.zw,h.w);",wr="vec2 mod289(vec2 x){return x-floor(x*(1.0/289.0))*289.0;}vec3 mod289(vec3 x){return x-floor(x*(1.0/289.0))*289.0;}vec4 mod289(vec4 x){return x-floor(x*(1.0/289.0))*289.0;}vec3 mod7(vec3 x){return x-floor(x*(1.0/7.0))*7.0;}vec3 permute(vec3 x){return mod289(((x*34.0)+10.0)*x);}vec4 permute(vec4 x){return mod289(((x*34.0)+1.0)*x);}vec4 taylorInvSqrt(vec4 r){return 1.792-0.853*r;}vec3 fade(vec3 t){return t*t*t*(t*(t*6.0-15.0)+10.0);}",br="_f grain(_v2 texCoord,_v2 resolution,_f frame,_f multiplier){_v2 mult=texCoord*resolution;_f offset=snoise3d(vec3(mult/multiplier,frame));_f n1=pnoise3D(vec3(mult,offset),vec3(1.0/texCoord*resolution,1.0));return n1/2.0+0.5;}_f grain(_v2 texCoord,_v2 resolution,_f frame){return grain(texCoord,resolution,frame,2.5);}_f grain(_v2 texCoord,_v2 resolution){return grain(texCoord,resolution,0.0);}",Mr="float cubicIn(float t){return t*t*t;}float cubicOut(float t){float f=t-1.0;return f*f*f+1.0;}",Lr="float exponentialOut(float t){return t==1.0 ? t : 1.0-pow(2.0,-10.0*t);}float exponentialIn(float t){return t==0.0 ? t : pow(2.0,10.0*(t-1.0));}";const Ze=/(#i_ .*)/gi,Rt={snoise3dpart:R(yr),brightness:R(hr),contrast:R(ur),hueShift:R(dr),saturation:R(cr),blendmodes:R(fr),sharpen:R(gr),hsl2rgb:R(pr),rgb2hsl:mr,snoise2d:R(xr),noiseUtils:R(wr),grain:R(br),exposure:R(_r),cubic:R(Mr),exponential:R(Lr)};Rt.snoise3d=R(Ft(vr));function ne(r){return r=Ft(r),r=R(r),r=`#version 300 es precision highp float; `+r,r}function R(r){return r=r.replace(/_i/g,"int"),r=r.replace(/_f/g,"float"),r=r.replace(/_v2/g,"vec2"),r=r.replace(/_v3/g,"vec3"),r=r.replace(/_v4/g,"vec4"),r=r.replace(/_m2/g,"mat2"),r=r.replace(/_m3/g,"mat3"),r=r.replace(/_m4/g,"mat4"),r=r.replace(/_4/g,"mat4"),r=r.replace(/_s2/g,"sampler2D"),r=r.replace(/_t/g,"texture"),r=r.replace(/_u/g,"uniform"),r=r.replace(/_gte/g,"greaterThanEqual"),r=r.replace(/_lte/g,"lessThanEqual"),r=r.replace(/_smst/g,"smoothstep"),r=r.replace(/_lay/g,"layout(location = "),r=r.replace(/_vm/g,"void main() {"),r}function Ft(r){const e=Sr(r);for(const t of e){const s=Dr(t);let i=Rt[s];i=i.replace("#define GLSLIFY 1",""),r=r.replace(t,i)}return r}function Sr(r){Ze.lastIndex=0;let e=null,t=0;const s=[];for(;(e=Ze.exec(r))&&t<100;)s.push(e[0]);return s}function Dr(r){return r.replace("#i_","").replace(/ /g,"")}var Cr=`_u _v2 uArtworkSize;_u sampler2D tArtwork;_u _v3 uBgColor;_u _f uBrightness;_u _f uContrast;_u _f uSaturation;_u _f uHighlights;_u _f uShadows;_u _f uHueAdjust;_u _f uSharpenBlur;_u _f uSharpenSize;_u _i uSharpenBlend;_u _f uNormalStr;_u _v2 uLightPos;_u _f uLightStr;in _v2 vUv;out _v4 fragColor; #i_ contrast #i_ brightness #i_ sharpen #i_ exposure _v2 stdNormalMap(_f height){return-_v2(dFdx(height),dFdy(height));}_v3 applyHue(_v3 col,_f hueAdjust){_v3 k=_v3(0.57735,0.57735,0.57735);_f cosAngle=cos(hueAdjust);return col*cosAngle+cross(k,col)*sin(hueAdjust)+k*dot(k,col)*(1.0-cosAngle);}_vm_v2 uv=vUv;_v4 artwork=_t(tArtwork,uv).rgba;_v2 areaSize=uSharpenSize/uArtworkSize;_v4 c1=texture(tArtwork,mod(uv-areaSize,1.));_v4 c2=texture(tArtwork,mod(_v2(uv.x,uv.y-areaSize.y),1.));_v4 c3=texture(tArtwork,mod(_v2(uv.x+areaSize.x,uv.y-areaSize.y),1.));_v4 c4=texture(tArtwork,mod(_v2(uv.x-areaSize.x,uv.y),1.));_v4 c5=texture(tArtwork,mod(_v2(uv.x+areaSize.x,uv.y),1.));_v4 c6=texture(tArtwork,mod(_v2(uv.x-areaSize.x,uv.y+areaSize.y),1.));_v4 c7=texture(tArtwork,mod(_v2(uv.x,uv.y+areaSize.y),1.));_v4 c8=texture(tArtwork,mod(uv+areaSize,1.));_v4 blur=(c1+c3+c6+c8+2.*(c2+c4+c5+c7)+4.*artwork)/16.;artwork=(1.+uSharpenBlur)*artwork-uSharpenBlur*blur;artwork=bmx(uBrightness)*contrastMatrix(uContrast)*artwork;_v3 res=autoExposure(artwork,uHighlights,uShadows);res=applyHue(res,uHueAdjust);const _v3 W=_v3(0.2125,0.7154,0.0721);_v3 intensity=_v3(dot(res,W));res=mix(intensity,res,uSaturation);artwork.rgb=res;_f height=(artwork.r+artwork.g+artwork.b)/3.;_v2 normal=stdNormalMap(height);normal*=uNormalStr;normal+=.5;_f lighting=dot(normal,normalize(uLightPos));artwork.rgb+=lighting*uLightStr*.5;fragColor=artwork;}`,Ar=`#version 300 es precision highp float;in vec2 position;in vec2 uv;out vec2 vUv;void main(){gl_Position=vec4(position,0.,1.);vUv=uv;}`;const pe=[];function $e(){a.screen.width=window.innerWidth,a.screen.height=window.innerHeight;for(const r of pe)r()}window.addEventListener("resize",$e,!1);window.addEventListener("orientationchange",$e,!1);$e();const Pr={add:r=>{pe.push(r)},remove:r=>{const e=pe.indexOf(r);e!==-1&&pe.splice(e,1)}};function Tr(r,e="center"){if(r.style.boxShadow="0 0 10px rgba(0,0,0,0.5)",r.style.position="absolute",a.isRender){r.style.top="0",r.style.left="0",r.style.width="100%",r.style.height="100%";return}function t(){let{width:s,height:i}=a.screen;const n=a.isFullScreen?0:100,l=a.isFullScreen?a.dpr:.25;s=s-n,i=i-n,s=Math.min(a.size.width*l,s),i=Math.min(a.size.height*l,i);let o=r.width,h=r.height;if(a.screen.height<r.height){let u=o/h;h=i,o=i*u,o>s&&(u=h/o,o=s,h=s*u)}else{let u=h/o;o=s,h=s*u,h>i&&(u=o/h,h=i,o=i*u)}r.style.height=h+"px",r.style.width=o+"px";const d=0;if(a.renderingMode!="animated"||location.href.indexOf("localhost")>-1)switch(e){case"center":r.style.left=(a.screen.width-o)*.5+d+"px",r.style.top=(a.screen.height-h)*.5+"px";break}}Pr.add(t),t()}const zr=ne(Cr);class kr{constructor(e,t){this.width=e,this.height=t,this.setBgColor(16777215),this.setClearAlpha(1),this._isFirstRender=!0}initWebGL(){this._initEngine(),this._scene=new Me(this._gl),this._camera=new kt(this._gl,{fov:35,near:.1,far:1e3,aspect:this.width/this.height}),this._camera.position.set(0,0,7),this._camera.lookAt([0,0,0]),a.resolution=new F(a.size.width*a.dpr,a.size.height*a.dpr),a.resolutionNoDPR=new F(a.size.width,a.size.height),this._initArtwork(),this._postComposite=new lr(this._gl,{width:this.width,height:this.height,dpr:a.dpr||1}),this._renderPass=this._postComposite.addPass({fragment:zr,vertex:Ar,uniforms:this._uniforms})}_initArtwork(){this._uniforms={uArtworkSize:{value:a.resolution},uBgColor:{value:new E},tArtwork:{value:new oe(a.gl,{image:new Uint8Array([191,25,54,255,96,18,54,255,96,18,54,255,37,13,53,255]),width:2,height:2,magFilter:a.gl.NEAREST})},uDAT:{value:1},uBrightness:{value:1},uContrast:{value:1},uSaturation:{value:1},uHighlights:{value:1},uShadows:{value:1},uHueAdjust:{value:0},uSharpenBlur:{value:0},uSharpenSize:{value:1},uSharpenBlend:{value:2},uNormalStr:{value:10},uLightPos:{value:new F(-.3,.8)},uLightStr:{value:.1}}}_initEngine(){this._renderer=new Xi({width:this.width,height:this.height,dpr:a.dpr||1,antialias:!1,preserveDrawingBuffer:!0}),this._gl=this._renderer.gl,a.gl=this._gl,this._gl.canvas.style.zIndex=1e3,this._gl.canvas.style.display="none",this._gl.autoClear=!1,Tr(this._gl.canvas),document.body.appendChild(this._gl.canvas),a.renderer=this._renderer}clear(){this._gl.clearColor(this._bgColor.r,this._bgColor.g,this._bgColor.b,this._clearAlpha)}renderWebGL=({options:e,skipComposer:t=!1,scene:s=null,displayArtwork:i=!0}={})=>{this._uniforms.uBgColor.value=this._bgColor,e&&(this._uniforms.uBrightness.value=e.brightness,this._uniforms.uContrast.value=e.contrast,this._uniforms.uSaturation.value=e.saturation,this._uniforms.uHighlights.value=e.highlights,this._uniforms.uShadows.value=e.shadows,this._uniforms.uHueAdjust.value=e.hue,this._uniforms.uSharpenBlur.value=Math.max(.2,e.sharpen.sharpenBlur),this._uniforms.uSharpenSize.value=e.sharpen.sharpenSize,this._uniforms.uSharpenBlend.value=e.sharpen.sharpenBlend,this._uniforms.uNormalStr.value=e.normal.normalStr-3.5,this._uniforms.uLightPos.value.x=e.light.lightPosX,this._uniforms.uLightPos.value.y=e.light.lightPosY,this._uniforms.uLightStr.value=e.light.lightStr),this._uniforms.uDAT.value=i?1:0,t||!i?this._renderer.render({scene:s||this._scene,camera:this._camera}):(this._renderPass.enabled=!0,this._postComposite.targetOnly=!1,this._postComposite.render({scene:this._scene})),this._isFirstRender&&(this._gl.canvas.style.display="block",this._isFirstRender=!1)};setBgColor(e){e instanceof E||(this._bgColor instanceof E?this._bgColor.set(e):this._bgColor=new E(e)),a.bgColor=this._bgColor}setClearAlpha(e){this._clearAlpha=e}get artwork(){return this._uniforms.tArtwork.value}set artwork(e){this._uniforms.tArtwork.value=e}get scene(){return this._scene}get renderer(){return this._renderer}get camera(){return this._camera}}function Rr(r,e){a.data&&a.data.displayData&&a.data.displayData.addCoreDisplay(r,e)}class Fr{constructor(){this._orders=[]}add(e,t){this._orders.push({renderable:e,data:t});const s=e.constructor.name;Rr(s,e.texture)}generate(){for(let e of this._orders)e.renderable.generate&&e.renderable.generate()}async render(e=!1){let t=!1;for(let s of this._orders){if(!s.data){(t||e)&&(await s.renderable?.render(),t=!0);continue}const i=Array.isArray(s.data)?s.data.some(n=>n.isDirty):s.data.isDirty;(e||i||t)&&(await s.renderable.render(),t=!0)}return t}get texture(){return this._orders[this._orders.length-1].renderable.texture}}var Ut="in _v2 uv;in _v2 position;out _v2 vUv;_vmvUv=uv;gl_Position=_v4(_v3(position,0.),1.0);}",Et="in _v2 vUv;_lay 0)out _v4 outColor0;_vmoutColor0=vec4(vUv,0.,1.);}";const Ur=ne(Ut),Er=ne(Et);function Br({uniforms:r={},vertex:e=Ur,fragment:t=Er,width:s=1,height:i=1}={}){return new Le(a.gl,{geometry:new be(a.gl,{position:{size:2,data:new Float32Array([-1,-1,3,-1,-1,3])},uv:{size:2,data:new Float32Array([0,0,2,0,0,2])}}),program:new ae(a.gl,{vertex:e,fragment:t,uniforms:r,transparent:!0,depthWrite:!1})})}class Bt{constructor({width:e=a.size.width,height:t=a.size.height}={}){this.vs=null,this.fs=null,this._width=e,this._height=t,this._uniformsInjected=[],this._uniforms={}}init({uniforms:e=this._uniforms,textures:t={},vs:s=null,fs:i=null,dataFroms:n=null,hasToAddSystemData:l=!0}={}){Object.entries(t).forEach(([h,d])=>{d!==null&&(e[h]={value:d})});const o=a.size.width/a.size.height;if(this._uniforms=Object.assign({uSeed:{value:0},uResolution:{value:a.resolutionNoDPR},uResolutionRatio:{value:o>1?1/a.resolutionNoDPR.x:1/a.resolutionNoDPR.y},uResolutionInv:{value:o>1?new F(1/a.resolutionNoDPR.x,1/a.resolutionNoDPR.y):new F(1/a.resolutionNoDPR.y,1/a.resolutionNoDPR.x)},uScreenRatio:{value:o},uScreenRatioV2:{value:o>1?new F(1,o):new F(1/o,1)},uArtworkSize:{value:new F(this._width,this._height)}},e),s||i){n=n?n.length?n:[n]:[],l&&a.data&&a.data.backgroundData&&n.push(a.data.backgroundData);const{vs:h,fs:d}=this.gatherUniformsFromData(n,{vs:s,fs:i,uniformsToFeed:this._uniforms,textures:t,hasToResolveShader:!0});this.vs=h,this.fs=d}}refreshTextures(e){Object.entries(e).forEach(([t,s])=>{s!==null&&(this._uniforms[t].value=s)})}gatherUniformsFromData(e,{vs:t=null,fs:s=null,uniformsToFeed:i=this._uniforms,hasToResolveShader:n=!0,textures:l=null}={}){let o="";e=e.length?e:[e];for(const h of e){o=this._gatherUniformsFromParams(i,h.params,o);for(let d in h.dataLayers){let u=h.dataLayers[d];o=this._gatherUniformsFromParams(i,u.params,o)}}for(let h in l)i[h].value!==null&&(o+=`uniform sampler2D ${h}; `);return t&&(n&&(t=ne(t)),t=t.replace("#injectUniforms",o),this.vs=t),s&&(n&&(s=ne(s)),s=s.replace("#injectUniforms",o),this.fs=s),{vs:t,fs:s}}_gatherUniformsFromParams(e,t,s){for(let i in t){let n=t[i];if(n.isUniform){let l="u"+i.charAt(0).toUpperCase()+i.slice(1),o="float";typeof n.value=="boolean"&&(o="bool");let h=n.value;n.type==="color"?(h=new E(h),o="vec3"):typeof h=="object"&&("min"in h||"max"in h)?(h=new F(h.min,h.max),o="vec2"):typeof h=="object"&&("x"in h||"y"in h)?(h=new F(h.x,h.y),o="vec2"):n.type==="int"&&(o="int"),e[l]={value:h},s+=`uniform ${o} ${l}; `,this._uniformsInjected.push({name:l,type:o,from:t,nameParam:i})}}return s}update(){this._updateInjectedUniforms(this._uniforms)}_updateInjectedUniforms(e){for(let t of this._uniformsInjected){let s=t.from[t.nameParam].value;const i=t.type;i==="vec3"?e[t.name].value.set(new E(s)):i==="vec2"?"min"in s||"max"in s?e[t.name].value.set(s.min,s.max):e[t.name].value.set(s.x,s.y):e[t.name].value=s}}get uniforms(){return this._uniforms}}class j extends Me{constructor(e=1,t={},{width:s=a.size.width,height:i=a.size.height,ratio:n=1}={}){super(),this._width=s*n,this._height=i*n,this._camera=new kt(this._gl,{fov:50,near:.1,far:1e3,aspect:this._width/this._height}),this._camera.position.set(0,0,5),this._camera.lookAt([0,0,0]),this._renderTarget=this._createRT(e,t)}init({uniforms:e={},textures:t={},vs:s=Ut,fs:i=Et,createMesh:n=!0,dataFroms:l=null}={}){n&&(this._pr
ttributes(e)}bindAttributes(e){e.attributeLocations.forEach((t,{name:s,type:i})=>{if(!this.attributes[s]){console.warn(`active attribute ${s} not being supplied`);return}const n=this.attributes[s];this.gl.bindBuffer(n.target,n.buffer),this.glState.boundBuffer=n.buffer;let l=1;i===35674&&(l=2),i===35675&&(l=3),i===35676&&(l=4);const o=n.size/l,h=l===1?0:l*l*4,d=l===1?0:l*4;for(let u=0;u<l;u++)this.gl.vertexAttribPointer(t+u,o,n.type,n.normalized,n.stride+h,n.offset+u*d),this.gl.enableVertexAttribArray(t+u),this.gl.renderer.vertexAttribDivisor(t+u,n.divisor)}),this.attributes.index&&this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.attributes.index.buffer)}draw({program:e,mode:t=this.gl.TRIANGLES}){this.gl.renderer.currentGeometry!==`${this.id}_${e.attributeOrder}`&&(this.VAOs[e.attributeOrder]||this.createVAO(e),this.gl.renderer.bindVertexArray(this.VAOs[e.attributeOrder]),this.gl.renderer.currentGeometry=`${this.id}_${e.attributeOrder}`),e.attributeLocations.forEach((i,{name:n})=>{const l=this.attributes[n];l.needsUpdate&&this.updateAttribute(l)});let s=2;this.attributes.index?.type===this.gl.UNSIGNED_INT&&(s=4),this.attributes.index?this.gl.drawElements(t,this.drawRange.count,this.attributes.index.type,this.attributes.index.offset+this.drawRange.start*s):this.gl.drawArrays(t,this.drawRange.start,this.drawRange.count)}getPosition(){const e=this.attributes.position;if(e.data)return e;if(!He)return He=!0}remove(){for(let e in this.VAOs)this.gl.renderer.deleteVertexArray(this.VAOs[e]),delete this.VAOs[e];for(let e in this.attributes)this.gl.deleteBuffer(this.attributes[e].buffer),delete this.attributes[e]}}let ji=1;const We={};class ae{constructor(e,{vertex:t,fragment:s,uniforms:i={},transparent:n=!1,cullFace:l=e.BACK,frontFace:o=e.CCW,depthTest:h=!0,depthWrite:d=!0,depthFunc:u=e.LESS}={}){e.canvas||console.error("gl not passed as first argument to Program"),this.gl=e,this.uniforms=i,this.id=ji++,t||console.warn("vertex shader not supplied"),s||console.warn("fragment shader not supplied"),this.transparent=n,this.cullFace=l,this.frontFace=o,this.depthTest=h,this.depthWrite=d,this.depthFunc=u,this.blendFunc={},this.blendEquation={},this.transparent&&!this.blendFunc.src&&(this.gl.renderer.premultipliedAlpha?this.setBlendFunc(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.setBlendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA));const f=e.createShader(e.VERTEX_SHADER);e.shaderSource(f,t),e.compileShader(f),e.getShaderInfoLog(f)!==""&&console.warn(`${e.getShaderInfoLog(f)} Vertex Shader ${Ye(t)}`);const g=e.createShader(e.FRAGMENT_SHADER);if(e.shaderSource(g,s),e.compileShader(g),e.getShaderInfoLog(g)!==""&&console.warn(`${e.getShaderInfoLog(g)} Fragment Shader ${Ye(s)}`),this.program=e.createProgram(),e.attachShader(this.program,f),e.attachShader(this.program,g),e.linkProgram(this.program),!e.getProgramParameter(this.program,e.LINK_STATUS))return console.warn(e.getProgramInfoLog(this.program));e.deleteShader(f),e.deleteShader(g),this.uniformLocations=new Map;let _=e.getProgramParameter(this.program,e.ACTIVE_UNIFORMS);for(let w=0;w<_;w++){let v=e.getActiveUniform(this.program,w);this.uniformLocations.set(v,e.getUniformLocation(this.program,v.name));const x=v.name.match(/(\w+)/g);v.uniformName=x[0],x.length===3?(v.isStructArray=!0,v.structIndex=Number(x[1]),v.structProperty=x[2]):x.length===2&&isNaN(Number(x[1]))&&(v.isStruct=!0,v.structProperty=x[1])}this.attributeLocations=new Map;const m=[],p=e.getProgramParameter(this.program,e.ACTIVE_ATTRIBUTES);for(let w=0;w<p;w++){const v=e.getActiveAttrib(this.program,w),x=e.getAttribLocation(this.program,v.name);x!==-1&&(m[x]=v.name,this.attributeLocations.set(v,x))}this.attributeOrder=m.join("")}setBlendFunc(e,t,s,i){this.blendFunc.src=e,this.blendFunc.dst=t,this.blendFunc.srcAlpha=s,this.blendFunc.dstAlpha=i,e&&(this.transparent=!0)}setBlendEquation(e,t){this.blendEquation.modeRGB=e,this.blendEquation.modeAlpha=t}applyState(){this.depthTest?this.gl.renderer.enable(this.gl.DEPTH_TEST):this.gl.renderer.disable(this.gl.DEPTH_TEST),this.cullFace?this.gl.renderer.enable(this.gl.CULL_FACE):this.gl.renderer.disable(this.gl.CULL_FACE),this.blendFunc.src?this.gl.renderer.enable(this.gl.BLEND):this.gl.renderer.disable(this.gl.BLEND),this.cullFace&&this.gl.renderer.setCullFace(this.cullFace),this.gl.renderer.setFrontFace(this.frontFace),this.gl.renderer.setDepthMask(this.depthWrite),this.gl.renderer.setDepthFunc(this.depthFunc),this.blendFunc.src&&this.gl.renderer.setBlendFunc(this.blendFunc.src,this.blendFunc.dst,this.blendFunc.srcAlpha,this.blendFunc.dstAlpha),this.gl.renderer.setBlendEquation(this.blendEquation.modeRGB,this.blendEquation.modeAlpha)}use({flipFaces:e=!1}={}){let t=-1;this.gl.renderer.state.currentProgram===this.id||(this.gl.useProgram(this.program),this.gl.renderer.state.currentProgram=this.id),this.uniformLocations.forEach((i,n)=>{let l=n.uniformName,o=this.uniforms[l];if(o.value.texture)return t=t+1,o.value.update(t),Fe(this.gl,n.type,i,t);if(o.value.length&&o.value[0].texture){const h=[];return o.value.forEach(d=>{t=t+1,d.update(t),h.push(t)}),Fe(this.gl,n.type,i,h)}Fe(this.gl,n.type,i,o.value)}),this.applyState(),e&&this.gl.renderer.setFrontFace(this.frontFace===this.gl.CCW?this.gl.CW:this.gl.CCW)}remove(){this.gl.deleteProgram(this.program)}}function Fe(r,e,t,s){s=s.length?qi(s):s;const i=r.renderer.state.uniformLocations.get(t);if(s.length)if(i===void 0||i.length!==s.length)r.renderer.state.uniformLocations.set(t,s.slice(0));else{if(Hi(i,s))return;i.set?i.set(s):Wi(i,s),r.renderer.state.uniformLocations.set(t,i)}else{if(i===s)return;r.renderer.state.uniformLocations.set(t,s)}switch(e){case 5126:return s.length?r.uniform1fv(t,s):r.uniform1f(t,s);case 35664:return r.uniform2fv(t,s);case 35665:return r.uniform3fv(t,s);case 35666:return r.uniform4fv(t,s);case 35670:case 5124:case 35678:case 35680:return s.length?r.uniform1iv(t,s):r.uniform1i(t,s);case 35671:case 35667:return r.uniform2iv(t,s);case 35672:case 35668:return r.uniform3iv(t,s);case 35673:case 35669:return r.uniform4iv(t,s);case 35674:return r.uniformMatrix2fv(t,!1,s);case 35675:return r.uniformMatrix3fv(t,!1,s);case 35676:return r.uniformMatrix4fv(t,!1,s)}}function Ye(r){let e=r.split(` `);for(let t=0;t<e.length;t++)e[t]=t+1+": "+e[t];return e.join(` `)}function qi(r){const e=r.length,t=r[0].length;if(t===void 0)return r;const s=e*t;let i=We[s];i||(We[s]=i=new Float32Array(s));for(let n=0;n<e;n++)i.set(r[n],n*t);return i}function Hi(r,e){if(r.length!==e.length)return!1;for(let t=0,s=r.length;t<s;t++)if(r[t]!==e[t])return!1;return!0}function Wi(r,e){for(let t=0,s=r.length;t<s;t++)r[t]=e[t]}new Z;let Yi=1;class Xi{constructor({canvas:e=document.createElement("canvas"),width:t=300,height:s=150,dpr:i=1,alpha:n=!1,depth:l=!0,stencil:o=!1,antialias:h=!1,premultipliedAlpha:d=!1,preserveDrawingBuffer:u=!1,powerPreference:f="default",autoClear:g=!0,webgl:_=2}={}){const m={alpha:n,depth:l,stencil:o,antialias:h,premultipliedAlpha:d,preserveDrawingBuffer:u,powerPreference:f};this.dpr=i,this.alpha=n,this.color=!0,this.depth=l,this.stencil=o,this.premultipliedAlpha=d,this.autoClear=g,this.id=Yi++,_===2&&(this.gl=e.getContext("webgl2",m)),this.isWebgl2=!!this.gl,this.gl||(this.gl=e.getContext("webgl",m)),this.gl||console.error("unable to create webgl context"),this.gl.renderer=this,this.setSize(t,s),this.state={},this.state.blendFunc={src:this.gl.ONE,dst:this.gl.ZERO},this.state.blendEquation={modeRGB:this.gl.FUNC_ADD},this.state.cullFace=null,this.state.frontFace=this.gl.CCW,this.state.depthMask=!0,this.state.depthFunc=this.gl.LESS,this.state.premultiplyAlpha=!1,this.state.flipY=!1,this.state.unpackAlignment=4,this.state.framebuffer=null,this.state.viewport={x:0,y:0,width:null,height:null},this.state.textureUnits=[],this.state.activeTextureUnit=0,this.state.boundBuffer=null,this.state.uniformLocations=new Map,this.state.currentProgram=null,this.extensions={},this.isWebgl2&&(this.getExtension("EXT_color_buffer_float"),this.getExtension("OES_texture_float_linear")),this.vertexAttribDivisor=this.getExtension("ANGLE_instanced_arrays","vertexAttribDivisor","vertexAttribDivisorANGLE"),this.drawArraysInstanced=this.getExtension("ANGLE_instanced_arrays","drawArraysInstanced","drawArraysInstancedANGLE"),this.drawElementsInstanced=this.getExtension("ANGLE_instanced_arrays","drawElementsInstanced","drawElementsInstancedANGLE"),this.createVertexArray=this.getExtension("OES_vertex_array_object","createVertexArray","createVertexArrayOES"),this.bindVertexArray=this.getExtension("OES_vertex_array_object","bindVertexArray","bindVertexArrayOES"),this.deleteVertexArray=this.getExtension("OES_vertex_array_object","deleteVertexArray","deleteVertexArrayOES"),this.drawBuffers=this.getExtension("WEBGL_draw_buffers","drawBuffers","drawBuffersWEBGL"),this.parameters={},this.parameters.maxTextureUnits=this.gl.getParameter(this.gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS),this.parameters.maxAnisotropy=this.getExtension("EXT_texture_filter_anisotropic")?this.gl.getParameter(this.getExtension("EXT_texture_filter_anisotropic").MAX_TEXTURE_MAX_ANISOTROPY_EXT):0}setSize(e,t){this.width=e,this.height=t,this.gl.canvas.width=e*this.dpr,this.gl.canvas.height=t*this.dpr,this.gl.canvas.style&&Object.assign(this.gl.canvas.style,{width:e+"px",height:t+"px"})}setViewport(e,t,s=0,i=0){this.state.viewport.width===e&&this.state.viewport.height===t||(this.state.viewport.width=e,this.state.viewport.height=t,this.state.viewport.x=s,this.state.viewport.y=i,this.gl.viewport(s,i,e,t))}setScissor(e,t,s=0,i=0){this.gl.scissor(s,i,e,t)}enable(e){this.state[e]!==!0&&(this.gl.enable(e),this.state[e]=!0)}disable(e){this.state[e]!==!1&&(this.gl.disable(e),this.state[e]=!1)}setBlendFunc(e,t,s,i){this.state.blendFunc.src===e&&this.state.blendFunc.dst===t&&this.state.blendFunc.srcAlpha===s&&this.state.blendFunc.dstAlpha===i||(this.state.blendFunc.src=e,this.state.blendFunc.dst=t,this.state.blendFunc.srcAlpha=s,this.state.blendFunc.dstAlpha=i,s!==void 0?this.gl.blendFuncSeparate(e,t,s,i):this.gl.blendFunc(e,t))}setBlendEquation(e,t){e=e||this.gl.FUNC_ADD,!(this.state.blendEquation.modeRGB===e&&this.state.blendEquation.modeAlpha===t)&&(this.state.blendEquation.modeRGB=e,this.state.blendEquation.modeAlpha=t,t!==void 0?this.gl.blendEquationSeparate(e,t):this.gl.blendEquation(e))}setCullFace(e){this.state.cullFace!==e&&(this.state.cullFace=e,this.gl.cullFace(e))}setFrontFace(e){this.state.frontFace!==e&&(this.state.frontFace=e,this.gl.frontFace(e))}setDepthMask(e){this.state.depthMask!==e&&(this.state.depthMask=e,this.gl.depthMask(e))}setDepthFunc(e){this.state.depthFunc!==e&&(this.state.depthFunc=e,this.gl.depthFunc(e))}activeTexture(e){this.state.activeTextureUnit!==e&&(this.state.activeTextureUnit=e,this.gl.activeTexture(this.gl.TEXTURE0+e))}bindFramebuffer({target:e=this.gl.FRAMEBUFFER,buffer:t=null}={}){this.state.framebuffer!==t&&(this.state.framebuffer=t,this.gl.bindFramebuffer(e,t))}getExtension(e,t,s){return t&&this.gl[t]?this.gl[t].bind(this.gl):(this.extensions[e]||(this.extensions[e]=this.gl.getExtension(e)),t?this.extensions[e]?this.extensions[e][s].bind(this.extensions[e]):null:this.extensions[e])}getRenderList({scene:e,camera:t,frustumCull:s,sort:i}){let n=[];return e.traverse(l=>{if(!l.visible)return!0;l.draw&&n.push(l)}),n}render({scene:e,camera:t,target:s=null,update:i=!0,sort:n=!0,frustumCull:l=!0,clear:o}){s===null?(this.bindFramebuffer(),this.setViewport(this.width*this.dpr,this.height*this.dpr)):(this.bindFramebuffer(s),this.setViewport(s.width,s.height)),(o||this.autoClear&&o!==!1)&&(this.depth&&(!s||s.depth)&&(this.enable(this.gl.DEPTH_TEST),this.setDepthMask(!0)),this.gl.clear((this.color?this.gl.COLOR_BUFFER_BIT:0)|(this.depth?this.gl.DEPTH_BUFFER_BIT:0)|(this.stencil?this.gl.STENCIL_BUFFER_BIT:0))),i&&e.updateMatrixWorld(),t&&t.updateMatrixWorld(),this.getRenderList({scene:e,camera:t,frustumCull:l,sort:n}).forEach(d=>{d.draw({camera:t})})}}class Ki extends Array{constructor(e=0,t=0,s=0,i=1){return super(e,t,s,i),this.onChange=()=>{},this}get x(){return this[0]}get y(){return this[1]}get z(){return this[2]}get w(){return this[3]}set x(e){this[0]=e,this.onChange()}set y(e){this[1]=e,this.onChange()}set z(e){this[2]=e,this.onChange()}set w(e){this[3]=e,this.onChange()}}function Ji(r,e,t,s,i){let n=1/Math.tan(e/2),l=1/(s-i);return r[0]=n/t,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=n,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=(i+s)*l,r[11]=-1,r[12]=0,r[13]=0,r[14]=2*i*s*l,r[15]=0,r}class $ extends Array{constructor(e=1,t=0,s=0,i=0,n=0,l=1,o=0,h=0,d=0,u=0,f=1,g=0,_=0,m=0,p=0,w=1){return super(e,t,s,i,n,l,o,h,d,u,f,g,_,m,p,w),this}get x(){return this[12]}get y(){return this[13]}get z(){return this[14]}get w(){return this[15]}set x(e){this[12]=e}set y(e){this[13]=e}set z(e){this[14]=e}set w(e){this[15]=e}multiply(e,t){return this}identity(){}copy(e){return this}fromPerspective({fov:e,aspect:t,near:s,far:i}={}){return Ji(this,e,t,s,i),this}setPosition(e){return this.x=e[0],this.y=e[1],this.z=e[2],this}compose(e,t,s){return this}getRotation(e){return this}getTranslation(e){return this}getScaling(e){return this}}new $;class Zi extends Array{constructor(e=0,t=e,s=e,i="YXZ"){return super(e,t,s),this.order=i,this.onChange=()=>{},this}get x(){return this[0]}get y(){return this[1]}get z(){return this[2]}set x(e){this[0]=e,this.onChange()}set y(e){this[1]=e,this.onChange()}set z(e){this[2]=e,this.onChange()}set(e,t=e,s=e){return e.length?this.copy(e):(this[0]=e,this[1]=t,this[2]=s,this.onChange(),this)}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this.onChange(),this}reorder(e){}fromRotationMatrix(e,t=this.order){}fromQuaternion(e,t=this.order){}fromArray(e,t=0){}toArray(e=[],t=0){}}class Me{constructor(){this.parent=null,this.children=[],this.visible=!0,this.matrix=new $,this.worldMatrix=new $,this.matrixAutoUpdate=!0,this.position=new Z,this.quaternion=new Ki,this.scale=new Z(1),this.rotation=new Zi,this.up=new Z(0,1,0),this.rotation.onChange=()=>this.quaternion.fromEuler(this.rotation),this.quaternion.onChange=()=>this.rotation.fromQuaternion(this.quaternion)}setParent(e,t=!0){this.parent&&e!==this.parent&&this.parent.removeChild(this,!1),this.parent=e,t&&e&&e.addChild(this,!1)}addChild(e,t=!0){~this.children.indexOf(e)||this.children.push(e),t&&e.setParent(this,!1)}removeChild(e,t=!0){~this.children.indexOf(e)&&this.children.splice(this.children.indexOf(e),1),t&&e.setParent(null,!1)}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.worldMatrixNeedsUpdate||e)&&(this.parent===null?this.worldMatrix.copy(this.matrix):this.worldMatrix.multiply(this.parent.worldMatrix,this.matrix),this.worldMatrixNeedsUpdate=!1,e=!0);for(let t=0,s=this.children.length;t<s;t++)this.children[t].updateMatrixWorld(e)}updateMatrix(){this.matrix.compose(this.quaternion,this.position,this.scale),this.worldMatrixNeedsUpdate=!0}traverse(e){if(!e(this))for(let t=0,s=this.children.length;t<s;t++)this.children[t].traverse(e)}lookAt(e,t=!1){this.matrix.getRotation(this.quaternion),this.rotation.fromQuaternion(this.quaternion)}}const Qi=new $;class kt extends Me{constructor(e,{near:t=.1,far:s=100,fov:i=45,aspect:n=1,left:l,right:o,bottom:h,top:d,zoom:u=1}={}){super(),Object.assign(this,{near:t,far:s,fov:i,aspect:n,left:l,right:o,bottom:h,top:d,zoom:u}),this.projectionMatrix=new $,this.viewMatrix=new $,this.projectionViewMatrix=new $,this.worldPosition=new Z,this.type="perspective",this.perspective()}perspective({near:e=this.near,far:t=this.far,fov:s=this.fov,aspect:i=this.aspect}={}){return Object.assign(this,{near:e,far:t,fov:s,aspect:i}),this.projectionMatrix.fromPerspective({fov:s*(Math.PI/180),aspect:i,near:e,far:t}),this.type="perspective",this}updateMatrixWorld(){return super.updateMatrixWorld(),this.worldMatrix.getTranslation(this.worldPosition),this.projectionViewMatrix.multiply(this.projectionMatrix,this.viewMatrix),this}lookAt(e){return super.lookAt(e,!0),this}project(e){return e.applyMatrix4(this.viewMatrix),e.applyMatrix4(this.projectionMatrix),this}unproject(e){return e.applyMatrix4(Qi.inverse(this.projectionMatrix)),e.applyMatrix4(this.worldMatrix),this}}class er extends Array{constructor(e=1,t=0,s=0,i=0,n=1,l=0,o=0,h=0,d=1){return super(e,t,s,i,n,l,o,h,d),this}set(e,t,s,i,n,l,o,h,d){return e.length?this.copy(e):this}translate(e,t=this){return this}rotate(e,t=this){return this}scale(e,t=this){return this}multiply(e,t){return this}identity(){return this}copy(e){return this}fromMatrix4(e){return this}fromQuaternion(e){return this}fromBasis(e,t,s){return this}inverse(e=this){return this}getNormalMatrix(e){return this}}let tr=0;class Le extends Me{constructor(e,{geometry:t,program:s,mode:i=e.TRIANGLES,frustumCulled:n=!0,renderOrder:l=0}={}){super(),e.canvas||console.error("gl not passed as first argument to Mesh"),this.gl=e,this.id=tr++,this.geometry=t,this.program=s,this.mode=i,this.frustumCulled=n,this.renderOrder=l,this.modelViewMatrix=new $,this.normalMatrix=new er}draw({camera:e}={}){e&&(this.program.uniforms.modelMatrix||Object.assign(this.program.uniforms,{modelMatrix:{value:null},viewMatrix:{value:null},modelViewMatrix:{value:null},normalMatrix:{value:null},projectionMatrix:{value:null},cameraPosition:{value:null}}),this.program.uniforms.projectionMatrix.value=e.projectionMatrix,this.program.uniforms.cameraPosition.value=e.worldPosition,this.program.uniforms.viewMatrix.value=e.viewMatrix,this.modelViewMatrix.multiply(e.viewMatrix,this.worldMatrix),this.normalMatrix.getNormalMatrix(this.modelViewMatrix),this.program.uniforms.modelMatrix.value=this.worldMatrix,this.program.uniforms.modelViewMatrix.value=this.modelViewMatrix,this.program.uniforms.normalMatrix.value=this.normalMatrix),this.program.use(),this.geometry.draw({mode:this.mode,program:this.program})}}const sr=new Uint8Array(4);let ir=1;class oe{constructor(e,{image:t,target:s=e.TEXTURE_2D,type:i=e.UNSIGNED_BYTE,format:n=e.RGBA,internalFormat:l=n,wrapS:o=e.CLAMP_TO_EDGE,wrapT:h=e.CLAMP_TO_EDGE,generateMipmaps:d=!0,minFilter:u=d?e.NEAREST_MIPMAP_LINEAR:e.LINEAR,magFilter:f=e.LINEAR,premultiplyAlpha:g=!1,unpackAlignment:_=4,flipY:m=s==e.TEXTURE_2D,anisotropy:p=0,level:w=0,width:v,height:x=v}={}){this.gl=e,this.id=ir++,this.image=t,this.target=s,this.type=i,this.format=n,this.internalFormat=l,this.minFilter=u,this.magFilter=f,this.wrapS=o,this.wrapT=h,this.generateMipmaps=d,this.premultiplyAlpha=g,this.unpackAlignment=_,this.flipY=m,this.anisotropy=Math.min(p,this.gl.renderer.parameters.maxAnisotropy),this.level=w,this.width=v,this.height=x,this.texture=this.gl.createTexture(),this.store={image:null},this.glState=this.gl.renderer.state,this.state={},this.state.minFilter=this.gl.NEAREST_MIPMAP_LINEAR,this.state.magFilter=this.gl.LINEAR,this.state.wrapS=this.gl.REPEAT,this.state.wrapT=this.gl.REPEAT,this.state.anisotropy=0}bind(){this.glState.textureUnits[this.glState.activeTextureUnit]!==this.id&&(this.gl.bindTexture(this.target,this.texture),this.glState.textureUnits[this.glState.activeTextureUnit]=this.id)}update(e=0){const t=!(this.image===this.store.image&&!this.needsUpdate);(t||this.glState.textureUnits[e]!==this.id)&&(this.gl.renderer.activeTexture(e),this.bind()),t&&(this.needsUpdate=!1,this.flipY!==this.glState.flipY&&(this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,this.flipY),this.glState.flipY=this.flipY),this.premultiplyAlpha!==this.glState.premultiplyAlpha&&(this.gl.pixelStorei(this.gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),this.glState.premultiplyAlpha=this.premultiplyAlpha),this.unpackAlignment!==this.glState.unpackAlignment&&(this.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT,this.unpackAlignment),this.glState.unpackAlignment=this.unpackAlignment),this.minFilter!==this.state.minFilter&&(this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,this.minFilter),this.state.minFilter=this.minFilter),this.magFilter!==this.state.magFilter&&(this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,this.magFilter),this.state.magFilter=this.magFilter),this.wrapS!==this.state.wrapS&&(this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,this.wrapS),this.state.wrapS=this.wrapS),this.wrapT!==this.state.wrapT&&(this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,this.wrapT),this.state.wrapT=this.wrapT),this.image?(this.image.width&&(this.width=this.image.width,this.height=this.image.height),ArrayBuffer.isView(this.image)?this.gl.texImage2D(this.target,this.level,this.internalFormat,this.width,this.height,0,this.format,this.type,this.image):this.gl.texImage2D(this.target,this.level,this.internalFormat,this.format,this.type,this.image),this.onUpdate&&this.onUpdate()):this.width?this.gl.texImage2D(this.target,this.level,this.internalFormat,this.width,this.height,0,this.format,this.type,null):this.gl.texImage2D(this.target,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,sr),this.store.image=this.image)}}class Ie{constructor(e,{width:t=e.canvas.width,height:s=e.canvas.height,target:i=e.FRAMEBUFFER,color:n=1,depth:l=!0,stencil:o=!1,depthTexture:h=!1,wrapS:d=e.CLAMP_TO_EDGE,wrapT:u=e.CLAMP_TO_EDGE,minFilter:f=e.LINEAR,magFilter:g=f,type:_=e.UNSIGNED_BYTE,format:m=e.RGBA,internalFormat:p=m,unpackAlignment:w,premultiplyAlpha:v}={}){this.gl=e,this.width=t,this.height=s,this.depth=l,this.buffer=this.gl.createFramebuffer(),this.target=i,this.gl.renderer.bindFramebuffer(this),this.textures=[];const x=[];for(let y=0;y<n;y++)this.textures.push(new oe(e,{width:t,height:s,wrapS:d,wrapT:u,minFilter:f,magFilter:g,type:_,format:m,internalFormat:p,unpackAlignment:w,premultiplyAlpha:v,flipY:!1,generateMipmaps:!1})),this.textures[y].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+y,this.gl.TEXTURE_2D,this.textures[y].texture,0),x.push(this.gl.COLOR_ATTACHMENT0+y);x.length>1&&this.gl.renderer.drawBuffers(x),this.texture=this.textures[0],this.gl.renderer.bindFramebuffer({target:this.target})}setSize(e,t){if(!(this.width===e&&this.height===t)){this.width=e,this.height=t,this.gl.renderer.bindFramebuffer(this);for(let s=0;s<this.textures.length;s++)this.textures[s].width=e,this.textures[s].height=t,this.textures[s].needsUpdate=!0,this.textures[s].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+s,this.gl.TEXTURE_2D,this.textures[s].texture,0);this.gl.renderer.bindFramebuffer({target:this.target})}}}const Xe={black:"#000000",white:"#ffffff"};function Ke(r){r.length===4&&(r=r[0]+r[1]+r[1]+r[2]+r[2]+r[3]+r[3]);const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(r);return[parseInt(e[1],16)/255,parseInt(e[2],16)/255,parseInt(e[3],16)/255]}function
6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#eba60f",n:569547,a:.21,d:196,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#e8cd34",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#6f7059",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#c3b968",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#eadfdf",n:550188,a:.21,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},ks={o:"#3f3838",a:.13,f:{o:"#c17f08",o2:"#e0dcce",b:.1,a:.43}},Rs={u:{m:6.96,q:.01}},Fs={c2:"#9f9f75",p:.36},pt={c:zs,t:ks,w:Rs,g:Fs},Us={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#7d94a3",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#49b1c7",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#c3b5aa",n:999547,a:.17,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#bbc35a",n:853547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#21230f",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#25341e",n:608418,a:.48,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#1e2a16",n:999547,a:.17,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#56534f",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#90a268",n:569547,a:.21,d:147,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#f8ee63",n:246547,a:.32,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#687059",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#d2c76f",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#b00909",n:550188,a:.21,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},Es={o:"#3f3838",a:.5,f:{o:"#f71a1a",o2:"#f71a1a",b:.1,a:.34}},Bs={u:{m:6.96,q:.01}},Is={c2:"#959558",p:.48},mt={c:Us,t:Es,w:Bs,g:Is},Gs={l:{bg:{o:"#fde4c9",n:999547,a:.63,d:82,r:0,s:!1},g1:{o:"#333e2f",n:911547,a:.29,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#133d5a",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#b09a7f",n:999547,a:.17,d:1239,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#484b4e",n:853547,a:.16,d:750,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#0dc0d7",n:902547,a:.3,d:1076,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#cabb3f",n:608418,a:.14,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#333e2f",n:999547,a:.21,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#f8f6d6",n:794547,a:.3,d:130,r:3,s:!0,x:75,e:0,i:9.24},f3:{o:"#e72d22",n:667547,a:.26,d:375,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#9d3112",n:246547,a:.29,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#7a8772",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#c3b968",n:550188,a:.42,d:25,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#f6e187",n:550188,a:.34,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},Ns={o:"#383739",a:.16,f:{o:"#eb6c14",o2:"#e44b2f",b:.1,a:.5}},Os={u:{m:6.96,q:.01}},Vs={c2:"#c5bd95",p:.7},xt={c:Gs,t:Ns,w:Os,g:Vs},$s={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#015c97",n:686547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#70e5fd",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#1e85d3",n:999547,a:.22,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#d8e714",n:853547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#1a1b0c",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#37342d",n:608418,a:.48,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#102c34",n:999547,a:.17,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#9a8857",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#ed4d36",n:569547,a:.21,d:130,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#d74c39",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#85906f",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#e0d390",n:550188,a:.28,d:0,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#0e0d0d",n:550188,a:.24,d:1141,r:4,s:!0,x:32.17,e:0,i:9.38}}},js={o:"#3f3838",a:.5,f:{o:"#e72615",o2:"#ed2210",b:.1,a:.34}},qs={u:{m:6.96,q:.01}},Hs={c2:"#8c8c63",p:.55},vt={c:$s,t:js,w:qs,g:Hs},Ws={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#74bae7",n:686547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#49b1c7",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#8fb9d7",n:999547,a:.17,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#bbc35a",n:853547,a:.14,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#35434a",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#bd8374",n:608418,a:.39,d:0,r:3,s:!0,x:73.91,e:1,i:8.7},f1:{o:"#252227",n:999547,a:.17,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#ede0cf",n:784547,a:.11,d:293,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#dd6b2a",n:569547,a:.21,d:147,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#e85434",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#ea362e",n:989825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#c3b692",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#b00909",n:550188,a:.21,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},Ys={o:"#2f160f",a:.5,f:{o:"#e72615",o2:"#94271d",b:.1}},Xs={u:{m:6.96,q:.01}},Ks={p:.35},yt={c:Ws,t:Ys,w:Xs,g:Ks},Js={l:{bg:{o:"#fde4c9",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#37a3ea",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#c6fd90",n:745547,a:.26,d:799,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#445126",n:999547,a:.17,d:880,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#aff02f",n:853547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#142627",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#8c9a70",n:941418,a:.24,d:0,r:3,s:!1,x:8.7,e:1,i:.38},f1:{o:"#3e2b20",n:872547,a:.17,d:65,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#258ee3",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#49ade7",n:569547,a:.21,d:130,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#52a4e7",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#7b90d7",n:158825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#e3d776",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#7cb5c3",n:550188,a:.34,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},Zs={o:"#3f3838",a:.5,f:{o:"#f4f3f0",o2:"#f0d6a1",b:.1,a:.43}},Qs={u:{m:6.96,q:.01}},ei={c2:"#a8a87a",p:.45},wt={c:Js,t:Zs,w:Qs,g:ei},ti={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#84cbfa",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#18b1d0",n:686547,a:.42,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#949145",n:999547,a:.21,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#ddc5b2",n:823547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#272912",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#41361b",n:608418,a:.48,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#271e16",n:999547,a:.33,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#615e3f",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#a1ad86",n:403547,a:.21,d:0,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#faf7f2",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#817c58",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#a4a472",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#e9eadf",n:550188,a:.21,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},si={o:"#3f3838",a:.13,f:{o:"#faf9cd",o2:"#ffd33c",b:.1,a:.29}},ii={u:{m:6.96,q:.01}},ri={c2:"#4f4f3d",p:0},bt={c:ti,t:si,w:ii,g:ri},ai={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#ede07f",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#49b1c7",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#c3b5aa",n:999547,a:.17,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#8cd9fa",n:853547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#272912",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#271d06",n:608418,a:.48,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#271e16",n:999547,a:.17,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#d083bb",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#7d875a",n:569547,a:.21,d:82,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#e8e334",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#6f7059",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#c3b968",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#08b08d",n:550188,a:.21,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},ni={o:"#3f3838",a:.13,f:{o:"#f4e178",o2:"#e0dcce",b:.1,a:.43}},oi={u:{m:6.96,q:.01}},li={c2:"#afaf88",p:0},Mt={c:ai,t:ni,w:oi,g:li},hi={l:{bg:{o:"#f3f3f3",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#c2dced",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#81e2f6",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#c3f7fa",n:999547,a:.17,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#5aa9c3",n:853547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#272912",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#413b2e",n:608418,a:.48,d:571,r:4,s:!1,x:3.04,e:1,i:.38},f1:{o:"#0a2706",n:999547,a:.17,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#4b543e",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#86a759",n:569547,a:.21,d:130,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#bfdd78",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#9baa7e",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#c3b968",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#b0a408",n:550188,a:.21,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},ui={o:"#393522",a:.5,f:{o:"#f7fad7",o2:"#f4ffe3",b:.1,a:.34}},di={u:{m:6.96,q:.01}},ci={c2:"#bfbc8a",p:.46},Lt={c:hi,t:ui,w:di,g:ci},fi={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#a3977d",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#b9ebf5",n:960547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#d1edf2",n:999547,a:.17,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#3a643c",n:853547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#081609",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#999f71",n:677418,a:.24,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#201a04",n:804547,a:.17,d:1125,r:2,s:!1,x:36.52,e:1,i:3.38},f2:{o:"#6b9bf5",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#84a9cd",n:569547,a:.21,d:130,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#da9336",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#687059",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#cdc564",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#adb008",n:550188,a:.21,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},gi={o:"#3c2d20",a:.5,f:{o:"#fff3eb",o2:"#edcf4e",b:.1,a:.34}},_i={u:{m:6.96,q:0}},pi={c2:"#cfe8aa",p:.32},St={c:fi,t:gi,w:_i,g:pi},mi={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#7d94a3",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#beeaf3",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#d1edf2",n:999547,a:.39,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#5c643a",n:853547,a:.46,d:620,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#272912",n:999547,a:.22,d:668,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#444931",n:647418,a:.17,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#0a112c",n:872547,a:.17,d:1125,r:2,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#5e7fbd",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#81b1df",n:569547,a:.21,d:130,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#f5b56e",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#9ba28f",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#bfb54e",n:550188,a:.33,d:30,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#e9ed9f",n:550188,a:.21,d:49,r:1,s:!0,x:32.17,e:0,i:9.38}}},xi={o:"#3c2d20",a:.5,f:{o:"#f3f7f1",o2:"#42577e",b:.1,a:.34}},vi={u:{m:6.96,q:0}},yi={c2:"#afad73",p:.52},Dt={c:mi,t:xi,w:vi,g:yi},wi={l:{bg:{o:"#b89875",n:999547,a:.65,d:82,r:0,s:!1},g1:{o:"#80c7f5",n:833547,a:.33,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#493d72",n:686547,a:.25,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#3dd0ef",n:999547,a:.48,d:1207,r:2,s:!1,x:24,e:1,i:2.38},g4:{o:"#f8e071",n:823547,a:.14,d:1484,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#272249",n:999547,a:.33,d:750,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#413b1b",n:608418,a:.48,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#222716",n:999547,a:.33,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#566344",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#94ad86",n:403547,a:.21,d:0,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#f8f7f7",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#4d764a",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#cddc96",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#f8ecc2",n:922188,a:.21,d:293,r:4,s:!0,x:32.17,e:0,i:9.38}}},bi={o:"#3f3838",a:.13,f:{o:"#fff57d",o2:"#eb3608",b:.1,a:.29}},Mi={u:{m:6.96,q:0}},Li={c2:"#ccc56b",p:.5},Ct={c:wi,t:bi,w:Mi,g:Li},Si={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#7d94a3",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#49b1c7",n:960547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#c3b5aa",n:999547,a:.17,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#bbc35a",n:853547,a:.12,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#272912",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#37342d",n:608418,a:.48,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#0f2b34",n:999547,a:.17,d:734,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#56534f",n:784547,a:.11,d:1304,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#aab7a1",n:569547,a:.21,d:260,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#aab7a1",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#687059",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#c3b968",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#5dd6ed",n:550188,a:.21,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},Di={o:"#3f3838",a:.5,f:{o:"#f36cd0",o2:"#f4aae0",b:.1,a:.34}},Ci={u:{m:6.96,q:0}},Ai={c2:"#4f4f3d",p:.74},At={c:Si,t:Di,w:Ci,g:Ai},Pi={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#7d94a3",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#ff7e06",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#bde7f8",n:999547,a:.17,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#3a643c",n:853547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#151602",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#363426",n:608418,a:.48,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#4a4e08",n:412547,a:.17,d:424,r:2,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#a796bd",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#845dd2",n:569547,a:.21,d:130,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#372089",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#84926b",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#ecde71",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#adb008",n:550188,a:.21,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},Ti={o:"#3f2917",a:.5,f:{o:"#f9f7fa",o2:"#f3dcf6",b:.1,a:.34}},zi={u:{m:6.96,q:0}},ki={c2:"#87b269",p:.46},Pt={c:Pi,t:Ti,w:zi,g:ki},Ri={l:{bg:{o:"#fde4c9",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#37a3ea",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#fddf90",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#25b0bd",n:951547,a:.21,d:163,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#567719",n:853547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#1e373a",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#e7da6d",n:608418,a:.14,d:0,r:3,s:!1,x:8.7,e:1,i:.38},f1:{o:"#3a322d",n:999547,a:.17,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#d925e3",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#e74b4b",n:569547,a:.21,d:130,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#e37bdc",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#d77bd7",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#c3b968",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#25b0bd",n:843188,a:.34,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},Fi={o:"#3f3838",a:.5,f:{o:"#f0d6a1",o2:"#f0d6a1",b:.1,a:.5}},Ui={u:{m:6.96,q:.01}},Ei={c2:"#60b1f2",p:.18},Tt={c:Ri,t:Fi,w:Ui,g:Ei},_e=[];function T(r){_e.push({text:_e.length+"",value:_e.length,data:r})}T(gt);T(bt);T(Mt);T(Lt);T(St);T(yt);T(mt);T(At);T(vt);T(xt);T(Pt);T(Tt);T(_t);T(pt);T(wt);T(Ct);T(Dt);class X extends b{constructor(e=null){super(e),this.ap("palette",-1,{onChange:this._onPaletteSelected})}_saveNewPalette=()=>{const e=this._serializePalette(),t=this.minifyPaletteData(e),s=JSON.stringify(t,null,2),i=new Blob([s],{type:"application/json"}),n=URL.createObjectURL(i),l=document.createElement("a");l.href=n,l.download="palette.json",document.body.appendChild(l),l.click(),setTimeout(()=>{document.body.removeChild(l),URL.revokeObjectURL(n)},100)};_onPaletteSelected=(e=-1)=>{e=e!==-1?e:this.palette;const t=_e.find(n=>n.value===e),s=t?t.data:null;if(!s)return;const i=this._unminifyPaletteData(s);if(i.compositionsData&&i.compositionsData.layers)for(const n in i.compositionsData.layers){const l=i.compositionsData.layers[n],o=c.compositionsData.layers.dataLayers[n];o&&(l.color&&(o.color=l.color),l.countLines!==void 0&&(o.countLines=l.countLines),l.alpha!==void 0&&(o.alpha=l.alpha),l.lengthA!==void 0&&(o.lengthA=l.lengthA),l.rotationType!==void 0&&(o.rotationType=l.rotationType),l.isSingleDir!==void 0&&(o.isSingleDir=l.isSingleDir),l.noiseScaleMax!==void 0&&(o.noise.scaleMax=l.noiseScaleMax),l.noiseMode!==void 0&&(o.noise.mode=l.noiseMode),l.noiseTime!==void 0&&(o.noise.time=l.noiseTime))}i.treesData&&(i.treesData.color&&(c.treesData.color=i.treesData.color),i.treesData.alpha&&(c.treesData.alpha=i.treesData.alpha),i.treesData.flowers&&(i.treesData.flowers.color&&(c.treesData.flowers.color=i.treesData.flowers.color),i.treesData.flowers.color2&&(c.treesData.flowers.color2=i.treesData.flowers.color2),i.treesData.flowers.alpha&&(c.treesData.flowers.alpha=i.treesData.flowers.alpha),i.treesData.flowers.angleFlowBoost!==void 0&&(c.treesData.flowers.angleFlowBoost=i.treesData.flowers.angleFlowBoost))),i.flowData&&i.flowData.curl&&(i.flowData.curl.curlUvMult!==void 0&&(c.flowData.curl.curlUvMult=i.flowData.curl.curlUvMult),i.flowData.curl.curlRatioAccum!==void 0&&(c.flowData.curl.curlRatioAccum=i.flowData.curl.curlRatioAccum)),i.gridPatternData&&(i.gridPatternData.linesGridColor!==void 0&&(c.gridPatternData.linesGridColor=i.gridPatternData.linesGridColor),i.gridPatternData.linesGridAlpha!==void 0&&(c.gridPatternData.linesGridAlpha=i.gridPatternData.linesGridAlpha))};static get KEY_MAPPINGS(){return{compositionsData:"c",layers:"l",color:"o",color2:"o2",countLines:"n",alpha:"a",lengthA:"d",rotationType:"r",treesData:"t",flowers:"f",angleFlowBoost:"b",flowData:"w",curl:"u",curlUvMult:"m",curlRatioAccum:"q",isSingleDir:"s",noiseScaleMax:"x",noiseMode:"e",noiseTime:"i",gridPatternData:"g",linesGridAlpha:"p",linesGridColor:"c2"}}static get LAYER_MAPPINGS(){return{background:"bg",greenLayer1:"g1",greenLayer2:"g2",greenLayer3:"g3",greenLayer4:"g4",greenLayer5:"g5",windLayer:"wl",flowerLayer1:"f1",flowerLayer2:"f2",flowerLayer3:"f3",flowerLayer4:"f4",blueWindLayer:"bw",greenFlowerLayer:"gf",bonusLayer:"bn"}}static getReverseMapping(e){const t={};for(const[s,i]of Object.entries(e))t[i]=s;return t}_unminifyPaletteData(e){const t=X.getReverseMapping(X.KEY_MAPPINGS),s=X.getReverseMapping(X.LAYER_MAPPINGS),i=o=>{if(o.length===4){const h=o[1],d=o[2],u=o[3];return`#${h}${h}${d}${d}${u}${u}`}return o},n=(o,h=[])=>{if(typeof o!="object"||o===null)return typeof o=="string"&&o.startsWith("#")?i(o):o;if(Array.isArray(o))return o.map(u=>n(u,h));const d={};for(const[u,f]of Object.entries(o)){let g=t[u]||u;h.length===1&&h[0]==="layers"&&s[u]&&(g=s[u]);let _=[...h];g==="layers"&&_.push("layers"),d[g]=n(f,_)}return d};return n(e,[])}}class Bi extends b{constructor(e=null){super(e),this.ap("branchLength",220),this.ap("minLength",45),this.ap("splitCountMin",2),this.ap("splitCountAdd",2),this.ap("maxDepth",15),this.ap("branchAngle",.99)}}class Ii extends fs{constructor(){super()}_initCustoms(){this.paletteData=new X(this.guiSystem?.addFolder("Palettes")),this.addDataLayer(gs,{name:"gridRyokan"}),this.gridRyokanData.gui.mainFolder.expanded=!1,this.addDataLayer(Bi,{name:"treebstract",style:{top:"290px"}}),this.treebstractData.gui.mainFolder.expanded=!1;let e=270;this.addDataLayer(xs,{name:"grid",style:{right:`${e}px`}}),this.gridData.gui.mainFolder.expanded=!1,this.addDataLayer(vs,{name:"compositions",style:{right:`${e}px`,top:"40px"}}),this.compositionsData.gui.mainFolder.expanded=!1,e+=264,this.addDataLayer(_s,{name:"flow",style:{right:`${e}px`}}),this.flowData.gui.mainFolder.expanded=!1,e+=264,this.addDataLayer(ws,{name:"trees",style:{right:`${e}px`}}),this.treesData.gui.mainFolder.expanded=!1,e+=264,this.addDataLayer(ys,{name:"patternNoise",style:{right:`${e}px`}}),this.patternNoiseData.gui.mainFolder.expanded=!1,e+=264,this.addDataLayer(bs,{name:"gridPattern",style:{right:`${e}px`}}),e+=264,this.addDataLayer(ms,{name:"vegeLines",style:{right:`${e}px`}}),e+=264,this.addDataLayer(ps,{name:"composer",style:{right:`${e}px`}})}}const c=new Ii;function zt(r,{prefix:e="",postfix:t=""}={}){const s=document.createElement("a");s.setAttribute("download",(e?e+"_":"")+a.id+"-"+tokenData.hash+(t?"_"+t:"")+".jpg"),s.setAttribute("href",r.toDataURL("image/jpg",1)),s.click()}class Gi{constructor(){window.addEventListener("keydown",e=>{if(console.log(e.key),e.key.toLowerCase()==="s"&&zt(a.gl.canvas),e.key.toLowerCase()==="f"){const t=new URL(window.location.href);t.searchParams.set("fullscreen","true"),window.location.href=t.toString()}if(e.key==="1"){const t=new URL(window.location.href);t.searchParams.set("dpr","1"),window.location.href=t.toString()}})}}function Ni(r,e){return r[0]=e[0],r[1]=e[1],r[2]=e[2],r}function Oi(r,e,t,s){return r[0]=e,r[1]=t,r[2]=s,r}class Z extends Array{constructor(e=0,t=e,s=e){return super(e,t,s),this}get x(){return this[0]}get y(){return this[1]}get z(){return this[2]}set x(e){this[0]=e}set y(e){this[1]=e}set z(e){this[2]=e}set(e,t=e,s=e){return e.length?this.copy(e):(Oi(this,e,t,s),this)}copy(e){return Ni(this,e),this}}new Z;let Vi=1,$i=1,He=!1;class be{constructor(e,t={}){e.canvas||console.error("gl not passed as first argument to Geometry"),this.gl=e,this.attributes=t,this.id=Vi++,this.VAOs={},this.drawRange={start:0,count:0},this.instancedCount=0,this.gl.renderer.bindVertexArray(null),this.gl.renderer.currentGeometry=null,this.glState=this.gl.renderer.state;for(let s in t)this.addAttribute(s,t[s])}addAttribute(e,t){this.attributes[e]=t,t.id=$i++,t.size=t.size||1,t.type=t.type||(t.data.constructor===Float32Array?this.gl.FLOAT:t.data.constructor===Uint16Array?this.gl.UNSIGNED_SHORT:this.gl.UNSIGNED_INT),t.target=e==="index"?this.gl.ELEMENT_ARRAY_BUFFER:this.gl.ARRAY_BUFFER,t.normalized=t.normalized||!1,t.stride=t.stride||0,t.offset=t.offset||0,t.count=t.count||(t.stride?t.data.byteLength/t.stride:t.data.length/t.size),t.divisor=t.instanced||0,t.needsUpdate=!1,t.usage=t.usage||this.gl.STATIC_DRAW,t.buffer||this.updateAttribute(t),this.drawRange.count=Math.max(this.drawRange.count,t.count)}updateAttribute(e){const t=!e.buffer;t&&(e.buffer=this.gl.createBuffer()),this.glState.boundBuffer!==e.buffer&&(this.gl.bindBuffer(e.target,e.buffer),this.glState.boundBuffer=e.buffer),t?this.gl.bufferData(e.target,e.data,e.usage):this.gl.bufferSubData(e.target,0,e.data),e.needsUpdate=!1}setIndex(e){this.addAttribute("index",e)}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}setInstancedCount(e){this.instancedCount=e}createVAO(e){this.VAOs[e.attributeOrder]=this.gl.renderer.createVertexArray(),this.gl.renderer.bindVertexArray(this.VAOs[e.attributeOrder]),this.bindA
class V{constructor(){this._entities=[]}add(e){if(typeof e!="function")throw new Error("Entity must be a function");this._entities.push(e)}remove(e){const t=this._entities.indexOf(e);t!==-1&&this._entities.splice(t,1)}dispatch(...e){for(const t of this._entities)typeof t=="function"?t(...e):console.error("Event: dispatch: entity is not a function")}clear(){this._entities=[]}dispose(){this._entities=null}}let xe=.5,rt="animated";const B=new URLSearchParams(window.location.search),Ot=B.has("render")&&B.get("render")==="true",Vt=B.has("fullscreen")&&B.get("fullscreen")==="true",$t=B.has("print")&&B.get("print")==="true",jt=B.has("fixed")&&B.get("fixed")==="true";B.has("r")&&(rt=B.get("r"));if(B.has("dpr")){const r=parseFloat(B.get("dpr"));!isNaN(r)&&r>0&&(xe=r)}xe=Math.min(xe,1);const a={id:"mmts",screen:{width:0,height:0},isFullScreen:Vt,isPrint:$t,isFixed:jt,size:{width:4096*2,height:2048*2},dpr:xe,linesSize:512,linesPerGeometry:1e5,linesTotal:1e6,onRender:new V,rand:Math.random,useGUI:!0,renderingMode:rt,isRender:Ot,isOver:!1},O={metaKey:!1,shiftKey:!1,altKey:!1,ctrlKey:!1},at=new V,nt=new V;window&&(window?.addEventListener("keydown",r=>{O.metaKey=r.metaKey,O.shiftKey=r.shiftKey,O.altKey=r.altKey,O.ctrlKey=r.ctrlKey,at.dispatch(r.key)}),window?.addEventListener("keyup",r=>{O.metaKey=r.metaKey,O.shiftKey=r.shiftKey,O.altKey=r.altKey,O.ctrlKey=r.ctrlKey,nt.dispatch(r.key)}));const qt={enter:13,space:32,q:81,w:87,e:69,r:82,t:84,y:89,u:85,i:73,o:79,p:80,a:65,s:83,d:68,f:70,g:71,h:72,j:74,k:75,l:76,z:90,x:88,c:67,v:86,b:66,n:78,m:77,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57,0:48,"[":219,"]":221,"\\":220,";":186,"'":222,",":188,".":190,"/":191,down:40,up:38,left:37,right:39,esc:27};function Ht(r){r.preventDefault(),r.stopPropagation(),r.stopImmediatePropagation()}const Re={prevent:Ht,special:O,onDown:at,onUp:nt,touches:qt},Wt=5;function Ge(r){const e=JSON.parse(localStorage.getItem("hashes-history"))||[];e.includes(r)||(e.length==Wt&&e.shift(),e.push(r),localStorage.setItem("hashes-history",JSON.stringify(e)))}function re(r){return`${global.id}-${r}`}function Yt(r,e){const t=JSON.parse(localStorage.getItem(re(r)))||[];t.includes(e)||(t.push(e),localStorage.setItem(re(r),JSON.stringify(t)))}function Xt(r){return JSON.parse(localStorage.getItem(re(r)))||[]}function Kt(r){const e=Xt(r),t=document.createElement("a"),s=new Blob([JSON.stringify(e)],{type:"application/json"});t.href=URL.createObjectURL(s),t.download=re(r)+".json",t.click()}function Jt(r){localStorage.removeItem(re(r))}let J=null;const ot=new V,Ne=new V,we=new V;function lt(){return tokenData.hash}function Zt(r,e=null){J=r,J.init(e),J.createPrerand()}function Qt(r=!0,e=!0){J.reset(e),r&&(ot.dispatch(),we.dispatch())}function es(r){J.setHash(r),Ne.dispatch(),we.dispatch()}function ts(){J.generateNewHash(),Ne.dispatch(),we.dispatch()}function ss(r){Re.onDown.add(e=>{if(Re.special.shiftKey){if(Re.special.ctrlKey){switch(console.log("here"),e){case"H":Jt(r),console.log('... hashes clear for project "',r,'"');break}return}switch(e){case"S":Yt(r,lt()),console.log('... hash saved for project "',r,'"');break;case"E":Kt(r),console.log('... export hashes for project "',r,'"');break}}})}const W={load:Zt,reset:Qt,setHash:es,generateNewHash:ts,getHash:lt,activateKeyboard:ss,onReset:ot,onChangeHash:Ne,onResetOrChangeHash:we};class is{constructor(){this.onChangeHash=W.onChangeHash}start(e,t=null){console.log("Engine: start"),W.load(e,t),W.activateKeyboard(a.id)}resetHash({andDispatch:e=!0,andLog:t=!0}={}){W.reset(e,t)}generateNewHash(){W.generateNewHash()}setHash(e){W.setHash(e)}get hash(){return W.getHash()}}const ht=new is;class ge{constructor(e){this.S=new Uint32Array(4),this.initializeFromHash(e.hash)}initializeFromHash(e){for(let t=0;t<4;t++)this.S[t]=parseInt(e.substr(t*16+2,16),16);for(let t=0;t<12;t++)this.R()}R(e=1){e*=this.S[3],this.S[3]=this.S[2],this.S[2]=this.S[1];let t=this.S[3];return t^=t<<11,this.S[0]^=t^t>>>8^(this.S[1]=this.S[0])>>>19,this.S[0]/2**32}random_dec=()=>this.R();random_num=(e,t)=>e+this.R()*(t-e);random_int=(e,t)=>Math.floor(e+this.R()*(t-e+1));random_bool=e=>this.R()<e;random_choice=e=>e[Math.floor(this.R()*e.length)]}function ut(){console.log(`%c Change seed: %c`+tokenData.hash,"color: white; background-color:green","color: green; background-color:yellow")}function rs(r=null){window.genTokenData||(window.genTokenData=function(t){let s={},i="0x";for(var n=0;n<64;n++)i+=Math.floor(Math.random()*16).toString(16);return s.hash=i,s.tokenId=(t*1e6+Math.floor(Math.random()*1e3)).toString(),s},window.tokenData=genTokenData(123),r?tokenData.hash=r:Ge(tokenData.hash),ut(),ct())}function as(){const r=genTokenData(3122021);r.hash="0xs03122021m13021990z";const e=new ge(r);a.prerand=e.random_dec}function dt(r=!0){ct(),r&&console.log("%c Reset hash ","color: white; background-color: gray")}function ct(){const r=new ge(tokenData);a.rand=r.random_dec;const e=new ge(tokenData);a.rand2=e.random_dec;const t=new ge(tokenData);a.rand3=t.random_dec}function ns(r){tokenData.hash=r,Ge(tokenData.hash),dt(!1),console.log("%c Set hash %c","color: white; background-color:red","color: red; background-color:yellow")}function os(){tokenData=genTokenData(123),Ge(tokenData.hash),ut()}const ls={init:rs,reset:dt,setHash:ns,generateNewHash:os,createPrerand:as};class hs{constructor(){this._guis=new Map}init(e=null){this.guiClass=e}get(e,t={}){return this.guiClass?(this._guis.has(e)||this._guis.set(e,new this.guiClass(e,t)),this._guis.get(e)):null}}const ft=new hs;class Oe{constructor(){this._folder={expanded:!1}}addFolder(){return new Oe}addBlade(){return{on:()=>this}}addButton(){return{on:()=>this}}addBinding(){return{on:()=>this}}apply(){}refresh(){}open(){}close(){}get mainFolder(){return this._folder}}class b{constructor(e=null,t=null){this._gui=e,this._params={},this._dataLayers={},this.canDispatch=!0,this._isDirty=!1,this.onChange=t||new V}reset(){for(let e in this._params)this[e]=this._params[e].value}serialize(){const e={};for(let t in this._params){const s=this._params[t];e[t]=s.serializeMethod?s.serializeMethod(s.value):s.value}for(let t in this._dataLayers)e[t]=this._dataLayers[t].serialize();return e}setParams(e){for(let t in e){const s=this._params[t];if(s)s.isLocked||(this[t]=s.setMethod?s.setMethod(e[t]):e[t]);else{const i=this._dataLayers[t];i&&i.setParams(e[t])}}}ap(...e){this.addParam(...e)}addParam(e,t,{serializeMethod:s=null,setMethod:i=null,onChange:n=null,isUniform:l=!1,type:o=null,isLocked:h=!1}={}){if(this._params[e]!==void 0)throw new Error(`DataLayer: addParam: name already exists: ${e}`);return this._params[e]={value:t,defaultValue:t,serializeMethod:s,setMethod:i,isUniform:l,type:o,isLocked:h},Object.defineProperty(this,e,{get:function(){return this._params[e].value},set:function(d){d!==this._params[e].value&&(this._params[e].value=d,this._isDirty=!0,this.onChange.dispatch(),n&&this.canDispatch&&n(d),this._gui&&this._gui.refresh())}}),this._gui?{gui:(d,u)=>{this._gui&&(typeof t=="object"&&("min"in t&&"max"in t||"x"in t&&"y"in t)&&(u=this._dispatch),this._gui.apply(this,e,d,u))}}:{gui:()=>{}}}updateGUIParam(e,t,s=null){this._gui&&this._gui.apply(this,e,t,s)}addParamU(e,t,{serializeMethod:s=null,setMethod:i=null,onChange:n=null,isUniform:l=!0,type:o=null,isLocked:h=!1}={}){return this.addParam(e,t,{serializeMethod:s,setMethod:i,onChange:n,isUniform:l,type:o,isLocked:h})}addParamUI(e,t,{serializeMethod:s=null,setMethod:i=null,onChange:n=null,isUniform:l=!0,type:o="int",isLocked:h=!1}={}){return this.addParam(e,t,{serializeMethod:s,setMethod:i,onChange:n,isUniform:l,type:o,isLocked:h})}addParamUC(e,t,{serializeMethod:s=null,setMethod:i=null,onChange:n=null,isUniform:l=!0,type:o="color",isLocked:h=!1}={}){return this.addParam(e,t,{serializeMethod:s,setMethod:i,onChange:n,isUniform:l,type:o,isLocked:h})}addParamU2(e,t,{serializeMethod:s=null,setMethod:i=null,onChange:n=null,isUniform:l=!0,type:o="vec2",isLocked:h=!1}={}){return this.addParam(e,t,{serializeMethod:s,setMethod:i,onChange:n,isUniform:l,type:o,isLocked:h})}addParamU3(e,t,{serializeMethod:s=null,setMethod:i=null,onChange:n=null,isUniform:l=!0,type:o="vec3",isLocked:h=!1}={}){return this.addParam(e,t,{serializeMethod:s,setMethod:i,onChange:n,isUniform:l,type:o,isLocked:h})}addParamUB(e,t,{serializeMethod:s=null,setMethod:i=null,onChange:n=null,isUniform:l=!0,type:o="bool",isLocked:h=!1}={}){return this.addParam(e,t,{serializeMethod:s,setMethod:i,onChange:n,isUniform:l,type:o,isLocked:h})}apU(...e){return this.addParamU(...e)}apUI(...e){return this.addParamUI(...e)}apUC(...e){return this.addParamUC(...e)}apU2(...e){return this.addParamU2(...e)}apU3(...e){return this.addParamU3(...e)}apUB(...e){return this.addParamUB(...e)}resetParam(e){this[e]=this._params[e].defaultValue}addDataLayer(e,t){if(this._dataLayers[e]!==void 0)throw new Error(`DataLayer: addDataLayer: name already exists: ${e}`);t.onChange||(t.onChange=this.onChange),this._dataLayers[e]=t,Object.defineProperty(this,e,{get:function(){return this._dataLayers[e]}})}adl(...e){this.addDataLayer(...e)}_dispatch=()=>{this._isDirty=!0,this.onChange.dispatch()};get dataLayers(){return this._dataLayers}get params(){return this._params}get gui(){return this._gui}set isDirty(e){for(let t in this._dataLayers)this._dataLayers[t].isDirty=e;this._isDirty=e}get isDirty(){for(let e in this._dataLayers)if(this._dataLayers[e].isDirty)return!0;return this._isDirty}}class us extends b{constructor(e){super(e),this.apUC("globalBackgroundColor",15526362)}}class ds extends b{constructor(e){super(e),this._optionsCore=[],this._idxCore=0,this.ap("core",0),this._hasExtra=!1,this._optionsExtra=[],this._idxExtra=0}addCoreDisplay(e,t){this._optionsCore.push({text:e,value:this._idxCore,texture:t}),this.canDispatch=!1,this.core=this._idxCore,this.canDispatch=!0,this._idxCore++}addExtraDisplay(e,t){}getSelectedCoreTexture(){return this._optionsCore[this.core].texture}getSelectedExtraTexture(){return this._optionsExtra[this.extra].texture}}class cs extends b{constructor(e){super(e),this.ap("brightness",0),this.ap("contrast",.98),this.ap("saturation",1.1),this.ap("highlights",.1),this.ap("shadows",1.05),this.ap("hue",0);let t=.2;a.dpr==1?t=.2:a.dpr==2?t=.4:a.dpr>2&&(t=.6),this.addDataLayer("sharpen",new b),this.sharpen.ap("sharpenBlur",t),this.sharpen.ap("sharpenSize",1),this.sharpen.ap("sharpenBlend",2),this.addDataLayer("normal",new b),this.normal.ap("normalStr",10),this.addDataLayer("light",new b),this.light.ap("lightPosX",.75),this.light.ap("lightPosY",-.57),this.light.ap("lightStr",.09)}}class fs{constructor(){this.onChange=new V,this._dataLayers=[],this._isDirty=!0,this.canDispatch=!0}init(){this._initSystem(),this._initCustoms()}_initSystem(){this.hasBackgroundChange=!1,this.backgroundData=new us(this.guiSystem),this.backgroundData.onChange.add(()=>{this.hasBackgroundChange=!0,this._dispatch()}),this._dataLayers.push(this.backgroundData),this.hasPostProcessChange=!1,this.postprocessData=new cs(this.guiSystem?.addFolder("Postprocess")),this.postprocessData.onChange.add(()=>{console.log(">>> post process change"),this.hasPostProcessChange=!0,this._dispatch()}),this._dataLayers.push(this.postprocessData),this.hasDisplayChange=!1,this.displayData=new ds(this.guiSystem?.addFolder("Display")),this.displayData.onChange.add(()=>{this.hasDisplayChange=!0,this._dispatch()}),this._dataLayers.push(this.displayData)}_initCustoms(){}_dispatch=()=>{this.canDispatch&&this.onChange.dispatch()};registerGUI(e){this._gui=e}addDataLayer(e,{style:t={},onChange:s=null,name:i=null,closeGUI:n=!1}={}){i=i||e.prototype.constructor.name.replace("Data","");const l=i.charAt(0).toUpperCase()+i.slice(1),o=i.charAt(0).toLowerCase()+i.slice(1)+"Data",h=this._gui?.get(l,{style:t}),d=new e(h);this[o]=d,d.onChange.add(()=>{s&&s(),this._dispatch()}),this._dataLayers.push(d),n&&(h._folder.expanded=!1)}resetChangesStatus(){this.hasBackgroundChange=!1,this.hasPostProcessChange=!1,this.hasDisplayChange=!1}set isDirty(e){for(let t of this._dataLayers)t.isDirty=e;this._isDirty=e}get isDirty(){for(let e of this._dataLayers)if(e.isDirty)return!0;return this._isDirty}get isDirtyExceptDisplay(){for(let e of this._dataLayers)if(e.isDirty&&e!==this.displayData)return!0;return!1}}class gs extends b{constructor(e=null){super(e),this.ap("lineWidth",4),this.ap("linesBigWidth",18),this.adl("divisions",new b),this.divisions.ap("chance",.83)}}class _s extends b{constructor(e=null){super(e),this.apU("offset",0),this.adl("curl",new b),this.curl.apUI("cLoop",8),this.curl.apU("cUvMult",6.96),this.curl.apU("cUvMultX",1),this.curl.apU("cUvMultY",1),this.curl.apU("cSeedMult",1),this.curl.apU("cStr",1.09),this.curl.apU("cRatioX",.22),this.curl.apU("cRatioY",.26),this.curl.apU("cRatioAccu",.01),this.adl("cm",new b);const t=this.cm;t.apU("modBase",1.022),t.apUI("modMaths",10),t.apU("modMax",!1),t.apU("modMax2",!0),this.adl("sn",new b);const s=this.sn;s.apUI("snLoop",1),s.apU("snUvMult",2.07),s.apU("snUvMultX",1),s.apU("snUvMultY",.22),s.apU("snSeedMult",1),s.apU("snStr",.87),s.apU("snRatioX",.22),s.apU("snRatioY",.23),s.apU("snRatioAccu",.017),this.adl("pnoise",new b);const i=this.pnoise;i.apU("pNoiseUvMult",2.826),i.apU("pNoiseSeedMult",1.63),i.apU("pNoiseStr",3.261),this.adl("mix",new b),this.mix.apU("mixRatio",1)}}class ps extends b{constructor(e=null){super(e),this.adl("lines",new b),this.lines.apU("linesGridAlpha",.489),this.lines.apUI("linesGridBlendmode",3),this.lines.apUC("linesGridColor",13156797),this.lines.apUB("linesGridInvert",!1)}}class ms extends b{constructor(e=null){super(e);const t=1,s=.3,i=8,n=50;this.adl("lines",new b),this.lines.apU("countLines",1e6),this.lines.apU("thM",t),this.lines.apU("thA",s),this.lines.apU("thP",i),this.lines.apU("lengthM",n),this.lines.apU("lengthA",157),this.lines.apU("lengthP",50),this.lines.apU("rotType",6),this.lines.apU2("rotNoise",{x:4.36,y:7.69}),this.lines.apU("valueFlowAdjust",.06),this.lines.apU("angleFlowBoost",.435),this.lines.apU("visibleThreshold",.859),this.lines.apU("dontUsePattern",!1),this.adl("colors",new b),this.colors.apU2("alpha",{min:.14,max:.774}),this.colors.apUB("applyAlpha",!0),this.adl("ca",new b),this.ca.apU("caValue",.761),this.ca.apU("caSat",.261),this.ca.apU("caLum",0),this.ca.apU("caScale",782),this.ca.apU("caValue2",.359),this.ca.apU("caScale2",1e3)}}class xs extends b{constructor(e=null){super(e),this.ap("margin",0),this.ap("lineWidth",4),this.adl("divisions",new b),this.divisions.ap("chance",.83),this.divisions.ap("friction",.89),this.divisions.ap("maxDivisions",4),this.divisions.ap("activateChanceFilling",!0),this.divisions.ap("chanceFilling",.99),this.divisions.ap("chanceDrawLine",1),this.divisions.ap("noiseScale",30),this.divisions.ap("macroScale",20),this.divisions.ap("useMacroScale",!1),this.divisions.ap("linesDivisions",2),this.divisions.ap("chanceLinesDivisions",.65)}}class vs extends b{constructor(e=null){super(e),this.ap("divider",8),this.ap("putTreesBefore",!1),this.adl("deformer",new b),this.deformer.apU("dispX",.39),this.deformer.apU("dispY",.39),this.deformer.apU("strength",.152),this.adl("layers",new b),this.layers.ap("totalDivider",13),this.layers.ap("totalDivider2",3),this.layers.adl("background",new b),this._setupLayer(this.layers.background,{color:"#b89875",countLines:999547,alpha:.36,lengthA:82,rotationType:0,skipPattern:!0}),this.layers.adl("greenLayer1",new b),this._setupLayer(this.layers.greenLayer1,{color:"#7d94a3",countLines:276547,alpha:.14,lengthA:1500,rotationType:6,noise:{scaleMax:27.3,mode:1,time:.38}}),this.layers.adl("greenLayer2",new b),this._setupLayer(this.layers.greenLayer2,{color:"#49b1c7",countLines:686547,alpha:.26,lengthA:1500,rotationType:2,noise:{scaleMax:31.3,mode:1,time:1.38}}),this.layers.adl("greenLayer3",new b),this._setupLayer(this.layers.greenLayer3,{color:"#c3b5aa",countLines:999547,alpha:.17,lengthA:1500,rotationType:2,noise:{scaleMax:34.78,mode:1,time:2.38}}),this.layers.adl("greenLayer4",new b),this._setupLayer(this.layers.greenLayer4,{color:"#bbc35a",countLines:853547,alpha:.09,lengthA:1500,rotationType:2,noise:{scaleMax:34.78,mode:1,time:3.38}}),this.layers.adl("greenLayer5",new b),this._setupLayer(this.layers.greenLayer5,{color:"#272912",countLines:999547,alpha:.33,lengthA:1500,rotationType:4,noise:{scaleMax:34.35,mode:1,time:4.38}}),this.layers.adl("windLayer",new b),this._setupLayer(this.layers.windLayer,{color:"#37342d",colorSummer:"#25341e",countLines:608418,alpha:.48,lengthA:0,rotationType:3,skipMask:!1,isSingleDir:!1,noise:{scaleMax:3.04,mode:1,time:.38}}),this.layers.adl("flowerLayer1",new b),this._setupLayer(this.layers.flowerLayer1,{color:"#102b34",colorSummer:"#1e2a16",countLines:999547,alpha:.17,lengthA:424,rotationType:6,noise:{scaleMax:3.04,mode:1,time:3.38}}),this.layers.adl("flowerLayer2",new b),this._setupLayer(this.layers.flowerLayer2,{color:"#56534f",countLines:784547,alpha:.11,lengthA:717,rotationType:6,maskType:1,noise:{scaleMax:9.57,mode:1,time:4.38}}),this.layers.adl("flowerLayer3",new b),this._setupLayer(this.layers.flowerLayer3,{color:"#eb5f0f",colorWinter:"#dfe7ec",colorSpring:"#aab7a1",colorAutumn:"#eb5f0f",colorSummer:"#8d9d68",countLines:569547,alpha:.21,lengthA:130,rotationType:6,maskType:1,noise:{scaleMax:3.48,mode:1,time:7.38}}),this.layers.adl("flowerLayer4",new b),this._setupLayer(this.layers.flowerLayer4,{color:"#e85434",colorWinter:"#68757d",colorSpring:"#aab7a1",colorAutumn:"#e85434",colorSummer:"#dad159",countLines:246547,alpha:.41,lengthA:0,rotationType:6,maskType:2,noise:{scaleMax:3.48,mode:0,time:6.38}}),this.layers.adl("blueWindLayer",new b),this._setupLayer(this.layers.blueWindLayer,{color:"#687059",colorWinter:"#dfe7ec",countLines:999825,alpha:.28,lengthA:293,rotationType:6,noise:{scaleMax:34.78,mode:1,time:6.38}}),this.layers.adl("greenFlowerLayer",new b),this._setupLayer(this.layers.greenFlowerLayer,{color:"#c3b968",colorWinter:"#a4bdcd",countLines:550188,alpha:.33,lengthA:130,rotationType:6,noise:{scaleMax:16.09,mode:0,time:8.38}}),this.layers.adl("bonusLayer",new b),this._setupLayer(this.layers.bonusLayer,{color:"#b00909",colorWinter:"#0f93ec",countLines:550188,alpha:.21,lengthA:668,rotationType:4,hasMask:!0,noise:{scaleMax:32.17,mode:0,time:9.38}})}_setupLayer(e,t){e.ap("color",t.color),e.apU("countLines",t.countLines),e.apU("alpha",t.alpha),e.ap("skipMask",t.skipMask||!1),e.apU("lengthA",t.lengthA),e.apU("rotationType",t.rotationType),e.apU("isSingleDir",t.hasMask||!1),e.apU("hasMask",t.hasMask||!1),e.ap("maskType",t.maskType||0),e.apU("skip",t.skip||!1),e.apU("skipPattern",t.skipPattern||!1),t.noise&&(e.adl("noise",new b),e.noise.ap("scaleMax",t.noise.scaleMax),e.noise.ap("mode",t.noise.mode),e.noise.ap("time",t.noise.time))}}class ys extends b{constructor(e=null){super(e),this.apU("scale",.543),this.ap("scaleMax",26.1),this.apU("str",.35),this.apU("time",.38),this.apUI("mode",0)}}class ws extends b{constructor(e){super(e),this.ap("color","#3f3838"),this.ap("treeThickness",280),this.ap("countLines",15e4),this.ap("thM",2),this.ap("thA",2),this.ap("thP",8),this.ap("lengthM",47*2),this.ap("lengthA",184*2),this.ap("lengthP",50),this.ap("alpha",.5),this.ap("angleFlowBoost",.1),this.adl("flowers",new b),this.flowers.ap("color","#e72615"),this.flowers.ap("color2","#e44b2f"),this.flowers.ap("trunkStep",50),this.flowers.ap("trunkNoiseScale",.3587),this.flowers.ap("trunkNoiseStr",.7513),this.flowers.ap("trunkBranchChance",.3),this.flowers.ap("leavesChance",.6),this.flowers.ap("countLines",804348),this.flowers.ap("thM",1.9),this.flowers.ap("thA",.4),this.flowers.ap("thP",8),this.flowers.ap("lengthM",30),this.flowers.ap("lengthA",146),this.flowers.ap("lengthP",50),this.flowers.ap("alpha",.337),this.flowers.ap("angleFlowBoost",.1)}}class bs extends b{constructor(e=null){super(e),this.ap("index",10),this.ap("width",.25),this.apU("linesGridAlpha",.5),this.apUI("linesGridBlendmode",3),this.apUC("linesGridColor","#4f4f3d"),this.apUB("linesGridInvert",!1)}}const Ms={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#7d94a3",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#39cded",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#c3b5aa",n:999547,a:.17,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#bbc35a",n:853547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#272912",n:999547,a:.33,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#37342d",n:608418,a:.48,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#102b34",n:999547,a:.17,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#56534f",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#fa640f",n:569547,a:.26,d:130,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#e85434",n:246547,a:.41,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#687059",n:999825,a:.28,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#c3b968",n:550188,a:.33,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#b00909",n:550188,a:.21,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},Ls={o:"#3f3838",a:.5,f:{o:"#e72615",o2:"#e44b2f",b:.1}},Ss={u:{m:6.96,q:.01}},Ds={c2:"#9c9677",p:.46},gt={c:Ms,t:Ls,w:Ss,g:Ds},Cs={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#7d94a3",n:941547,a:.22,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#3e95e7",n:951547,a:.36,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#c3b5aa",n:999547,a:.17,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#bbc35a",n:960547,a:.21,d:750,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#272912",n:960547,a:.12,d:1500,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#37342d",n:980418,a:.13,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#102b34",n:999547,a:.17,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#56534f",n:784547,a:.11,d:717,r:6,s:!1,x:9.57,e:1,i:4.38},f3:{o:"#fa9220",n:794547,a:.11,d:130,r:6,s:!1,x:3.48,e:1,i:7.38},f4:{o:"#e85434",n:951547,a:.14,d:0,r:6,s:!1,x:3.48,e:0,i:6.38},bw:{o:"#687059",n:999825,a:.12,d:293,r:6,s:!1,x:34.78,e:1,i:6.38},gf:{o:"#e0d36c",n:970188,a:.16,d:130,r:6,s:!1,x:16.09,e:0,i:8.38},bn:{o:"#b00909",n:550188,a:.12,d:668,r:4,s:!0,x:32.17,e:0,i:9.38}}},As={o:"#3f3838",a:.3,f:{o:"#fa5f2d",o2:"#e44b2f",b:.1,a:.21}},Ps={u:{m:6.96,q:.01}},Ts={c2:"#9f9f6f",p:.46},_t={c:Cs,t:As,w:Ps,g:Ts},zs={l:{bg:{o:"#b89875",n:999547,a:.36,d:82,r:0,s:!1},g1:{o:"#7d94a3",n:276547,a:.14,d:1500,r:6,s:!1,x:27.3,e:1,i:.38},g2:{o:"#2bcef0",n:686547,a:.26,d:1500,r:2,s:!1,x:31.3,e:1,i:1.38},g3:{o:"#49b1c7",n:999547,a:.17,d:1500,r:2,s:!1,x:34.78,e:1,i:2.38},g4:{o:"#ddc5b2",n:853547,a:.09,d:1500,r:2,s:!1,x:34.78,e:1,i:3.38},g5:{o:"#272912",n:999547,a:.33,d:832,r:4,s:!1,x:34.35,e:1,i:4.38},wl:{o:"#37342d",n:608418,a:.48,d:0,r:3,s:!1,x:3.04,e:1,i:.38},f1:{o:"#271e16",n:999547,a:.17,d:424,r:6,s:!1,x:3.04,e:1,i:3.38},f2:{o:"#56534f",n:784547,a:.11,d:717,r:
**Moments** is an exploration of memory and nostalgia, with nature and architecture as its subjects, inspired by my peaceful experiences in traditional Japanese ryokans. Some kind of memories reconstructed while souvenirs are fading as time passes. ## **The Digital Collection** The Digital Collection is a long form series and an animated piece that will loop through 4 different palettes for each NFT, emulating the time passing through seasons. My inspiration for this collection comes from serene and dear memories of my time in Japan. For me, traveling there means experiencing relaxing, inspiring moments in traditional ryokans—far away from the city, surrounded by nature (sometimes literally in the middle of the forest), where you can genuinely focus on self-care. You spend time in an onsen, enjoy beautifully curated and prepared meals, and return to your room with an incredible view of the outdoors. These places have a unique kind of architecture: minimalistic yet carefully constructed. Last year, I read a book called In Praise of Shadows by Junichiro Tanizaki, which helped me connect more deeply with the evolution of Japanese culture, linking a past I didn't know with the present day. Everything suddenly made sense to me. In a way, because of this book, I started seeing the Japan I knew differently (I noticed many many details), but also I started to have a look at my life and surroundings differently. Today, whenever I’m faced with complicated moments or need to figure out a solution, I mentally revisit my time in those ryokans. It’s become a kind of escape for me, a place where I find peace. It also brings up a lot of nostalgia from my experiences there. Earlier, I mentioned the architecture—I've decided to use that as the foundation for Moments. My starting point was the Japanese Shoji doors, constructed from wooden frames and washi paper. They became the structural basis for my artwork, where each block acts as a window into a memory, a window into a particular moment or passage of time. Nature appears either clearly through a seasonal color palette or more subtly suggested by organic elements and movements. The geometric structure is blending with more organic elements. This approach reflects the idea of ephemerality—representing nostalgia, memories that were once clear but have since been reconstructed again and again, ultimately transforming into something uniquely ours, reshaped through multiple layers of reflection.
class Loader{constructor(t,e={}){this.options={color:"#fff",width:"30%",...e},this.steps=7,this.step=1/this.steps,this.progress=0,this.progressRender=.001,this.progressRenderLocal=.001,this._isVisible=!1,this.element=document.createElement("div"),this.element.className="ryokan-loader",this.element.style.width="30%",this.element.style.zIndex="9999",this.element.style.position="absolute",this.element.style.bottom=0,this.element.style.left="50%",this.element.style.transform="translate(-50%, -50%)",this.element.style.backgroundColor="#17140B",this.element.style.padding="20px",this.element.style.border="1px solid #fff",this.barContainer=document.createElement("div"),this.barContainer.className="ryokan-loader-bar-container",this.barContainer.style.height="4px",this.barContainer.style.backgroundColor="#000",this.barContainer.style.opacity=.8,this.barContainer.style.overflow="hidden",this.barContainer.style.position="relative",this.bar=document.createElement("div"),this.bar.className="ryokan-loader-bar",this.bar.style.height="100%",this.bar.style.width="0%",this.bar.style.backgroundColor="#fff",this.bar.style.transition="width 0.3s ease-in-out",this.bar.style.position="absolute",this.bar.style.left="0",this.bar.style.top="0",this.barContainer.appendChild(this.bar),this.element.appendChild(this.barContainer),t&&("string"==typeof t?document.querySelector(t).appendChild(this.element):t.appendChild(this.element)),this.setProgress(0)}update(t){return this.progress+=this.step,this.setProgress(this.progress),this}setProgress(t){const e=Math.max(0,Math.min(1,t));return this.bar.style.width=`${e*100>>0}%`,this}setProgressRender(t){this.progressRender=t}setProgressRenderLocal(t){this.progressRenderLocal=t}getElement(){return this.element}show(){this._isVisible=!0,this.setProgress(0),this.element.style.display="block"}hide(){this._isVisible&&(this._isVisible=!1,this.element.style.display="none")}}let loader;const urlParams=new URLSearchParams(window.location.search),isRender=urlParams.has("render")&&"true"===urlParams.get("render");document.body.style.backgroundColor="#17140b";const canvas=document.querySelector("canvas")||document.createElement("canvas");canvas.id="defaultCanvas0",canvas.parentNode||document.body.appendChild(canvas);const cid=tokenData.externalAssetDependencies[0].cid,preferredGateway=tokenData.preferredIPFSGateway,tokenId=tokenData.tokenId.slice(-1);function createUrl(t,e,r){return`${t}${e}/moments-${r}.jpg`}async function loadImage(){const t=canvas.getContext("2d");loader=new Loader(document.body),loader.show(),loader.setProgress(.1);const e=createUrl(preferredGateway,cid,tokenId);console.log("Trying URL:",e),loader.update();try{const r=await loadImageFromUrl(e);loader.update(),displayImage(r,canvas,t),loader.hide()}catch(r){console.log("Failed to load from preferred gateway, trying fallback..."),loader.update();const a=createUrl("https://ipfs.io/ipfs/",cid,tokenId);console.log("Trying fallback URL:",a);try{const e=await loadImageFromUrl(a);loader.update(),displayImage(e,canvas,t),loader.hide()}catch(e){console.log("Failed to load from ipfs.io, trying florianzumbrunn.com fallback..."),loader.update();const r=`https://florianzumbrunn.com/fallbacks/moments/moments-${tokenId}.jpg`;console.log("Trying final fallback URL:",r);try{const e=await loadImageFromUrl(r);loader.update(),displayImage(e,canvas,t),loader.hide()}catch(e){console.error("Failed to load image from all sources",e),loader.setProgress(1),setTimeout(()=>loader.hide(),1500),t.fillStyle="red",t.font="20px Arial",t.fillText("Error loading image",50,100)}}}}function loadImageFromUrl(t){return new Promise((e,r)=>{const a=new Image;a.crossOrigin="Anonymous",a.onload=()=>{loader.setProgress(.9),e(a)},a.onerror=t=>r(t),a.src=t,loader.setProgress(.5)})}function displayImage(t,e,r){const a=isRender?.25:1;console.log("displaying image",t.width,t.height,isRender),e.width=t.width*a,e.height=t.height*a,e.style.width=e.width+"px",e.style.height=e.height+"px",r.drawImage(t,0,0,t.width*a,t.height*a),applyResponsiveStyling(e,t.width,t.height),loader&&(loader.setProgress(1),setTimeout(()=>loader.hide(),500))}function applyResponsiveStyling(t,e,r){t.style.maxWidth="100%",t.style.maxHeight="100vh",t.style.width="auto",t.style.height="auto";const a=t.parentElement||document.body;a.style.display="flex",a.style.justifyContent="center",a.style.alignItems="center",a.style.height="100vh",a.style.margin="0",a.style.padding="0"}window.addEventListener("resize",()=>{canvas.width>0&&canvas.height>0&&applyResponsiveStyling(canvas,canvas.width,canvas.height)}),document.addEventListener("DOMContentLoaded",()=>{document.body.style.margin="0",document.body.style.padding="0",document.body.style.overflow="hidden",loadImage()});
**Moments** is an exploration of memory and nostalgia, with nature and architecture as its subjects, inspired by my peaceful experiences in traditional Japanese ryokans. Each artwork uses a structural grid inspired by *shoji* doors, acting as windows into fragmented yet familiar landscapes. Some kind of memories reconstructed while souvenirs are fading as time pass. ## **The Curated Collection** The Curated Collection is a special selection of 10 distinct pieces, handpicked at different times over four months of experimentation and refinement. Each artwork captures a unique moment, showcasing variations in composition, palette, and mood. They narrate the evolution of my algorithm, from initial explorations to sophisticated states closer to its final form. Printed on **Canson watercolor paper 310g** and elegantly framed in **white aluminum**, each piece is individually **enhanced by hand with dry and wet pastel pencils and oil pastel**— adding depth, texture, and tangibility. Adding a new layer of "human hand" that will add the final stroke to the artwork. The NFT contains the original digital piece, before any hand intervention. These pieces invite viewers to slow down and fully immerse themselves in their subtle details and evocative atmospheres. Observing them from afar reveals their harmonious structure and contemplative movement; moving closer uncovers all its details, textures and subtile layers of colors that live on top of each others. My intention is for each viewer to experience a sense of calm surprise, encouraging curiosity and introspection, and ultimately feeling transported into their own serene "moment."
1-50 of 89