@layoutit/polycss 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/elements.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Ye=Object.defineProperty;var on=Object.getOwnPropertyDescriptor;var rn=Object.getOwnPropertyNames;var sn=Object.prototype.hasOwnProperty;var an=(e,n)=>{for(var t in n)Ye(e,t,{get:n[t],enumerable:!0})},ln=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of rn(n))!sn.call(e,r)&&r!==t&&Ye(e,r,{get:()=>n[r],enumerable:!(o=on(n,r))||o.enumerable});return e};var cn=e=>ln(Ye({},"__esModule",{value:!0}),e);var vr={};an(vr,{PolyAxesHelperElement:()=>be,PolyDirectionalLightHelperElement:()=>ve,PolyMapControlsElement:()=>Ee,PolyMeshElement:()=>ae,PolyOrbitControlsElement:()=>Pe,PolyOrthographicCameraElement:()=>Me,PolyPerspectiveCameraElement:()=>Ae,PolyPolygonElement:()=>ge,PolySceneElement:()=>G,PolySelectElement:()=>Te,PolyTransformControlsElement:()=>Ce});module.exports=cn(vr);var j=require("@layoutit/polycss-core");var Ze=require("@layoutit/polycss-core"),Ge=50,dt=[.4,-.7,.59],pt="#ffffff",mt=1,ft="#ffffff",ht=.4,de=4096,at=1,un=.1,dn=1,yt=de*de,pn=yt*3,$e=2048,Ue=16*1024*1024,mn=.995,ce=new Map,We=new WeakMap,B=.001,J=1e-9,fn=1e-4,hn=.1,yn=.75,gn=0,bn=.45,vn=3,xn=2;function Pn(e){let n=ce.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),ce.set(e,n),n.then(()=>{ce.get(e)===n&&ce.delete(e)},()=>{ce.get(e)===n&&ce.delete(e)})),n}function we(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(dn,Math.max(un,n))}function gt(e,n){let t=e.toFixed(n).replace(/\.?0+$/,"");return Object.is(Number(t),-0)?"0":t}function bt(e,n=vn){return e.map(t=>gt(t,n)).join(",")}function Le(e,n=xn){return`${gt(e,n)}%`}function vt(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function En(e){let n=vt(e);if(n<=0)return 1;let t=Math.max(1,...e.map(s=>Math.max(s.width,s.height))),o=$e/t,r=Math.sqrt(Ue/(n*4));return we(Math.min(o,r))}function An(e){let n=vt(e),t=.5;return n<=yt?t=1:n<=pn&&(t=.75),we(Math.min(t,En(e)))}function Mn(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function Cn(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function Tn(e,n){let t=Mn(e,n),o=Cn(e,n),r=t>$e?$e/t:1,s=o>Ue?Math.sqrt(Ue/o):1;return Math.min(r,s)}function Ln(e,n){let t=An(n.pages),o=t===1?n:Se(e,t);for(let r=0;r<4;r++){let s=Tn(o.pages,t);if(s>=1)break;let i=we(t*s*mn);if(i>=t)break;t=i,o=Se(e,t)}return{packed:o,atlasScale:t}}function _n(e,n){if(n!==void 0&&n!=="auto"){let o=we(n);return{packed:Se(e,o),atlasScale:o}}let t=Se(e,1);return Ln(e,t)}function Sn(e){return Math.max(at,Math.ceil(at/e))}function Q(e,n,t=1,o=0,r=0,s=1,i=0,c=0){e.setTransform(t*n,o*n,r*n,s*n,i*n,c*n)}function re(e){let n=(0,Ze.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function wn(e){return(0,Ze.parsePureColor)(e)?.alpha??1}function kn({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function xt(e,n,t,o,r){let s=re(e),i=re(t),c=re(o),l=c.r/255*r+i.r/255*n,a=c.g/255*r+i.g/255*n,d=c.b/255*r+i.b/255*n,m=Math.max(0,Math.min(255,Math.round(s.r*l))),f=Math.max(0,Math.min(255,Math.round(s.g*a))),h=Math.max(0,Math.min(255,Math.round(s.b*d))),u=wn(e);return u<1?`rgba(${m}, ${f}, ${h}, ${u})`:kn({r:m,g:f,b:h})}function On(e,n,t,o){let r=re(n),s=re(t);return{r:s.r/255*o+r.r/255*e,g:s.g/255*o+r.g/255*e,b:s.b/255*o+r.b/255*e}}function Hn({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(1,r))*255);return`rgb(${o(e)} ${o(n)} ${o(t)})`}function Dn(e,n,t,o,r,s,i){Math.abs(s.r-1)<.001&&Math.abs(s.g-1)<.001&&Math.abs(s.b-1)<.001||(e.save(),Q(e,i),e.globalCompositeOperation="multiply",e.fillStyle=Hn(s),e.fillRect(n,t,o,r),e.restore())}function Rn(e,n,t,o,r,s,i){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,a=Math.max(r/c,s/l),d=c*a,m=l*a;Q(e,i),e.drawImage(n,t+(r-d)/2,o+(s-m)/2,d,m)}function _e(e){return`${e[0]},${e[1]},${e[2]}`}function In(e,n){let t=_e(e),o=_e(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Pt(e,n){return _e(e)<_e(n)?[n[0]-e[0],n[1]-e[1],n[2]-e[2]]:[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function Vn(e){return!e.texture}function ke(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function je(e){if(e.length<3)return null;let n=e[0],t=e[1],o=e[2],r=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],s=[o[0]-n[0],o[1]-n[1],o[2]-n[2]],i=-(r[1]*s[2]-r[2]*s[1]),c=-(r[2]*s[0]-r[0]*s[2]),l=-(r[0]*s[1]-r[1]*s[0]),a=Math.hypot(i,c,l);return a<=J?null:(i/=a,c/=a,l/=a,[i,c,l])}function pe(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function zn(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Bn(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=ke(e.vertices,n,t),r=je(o);return r?{pts:o,normal:r,planeD:pe(r,o[0]),optimizable:Vn(e)}:null}function Fn(e,n){return!e||!n||!e.optimizable||!n.optimizable||pe(e.normal,n.normal)<1-fn?!1:Math.abs(e.planeD-n.planeD)<=hn}function Nn(e){let n=[...e],t=Math.abs(n[0])>J?0:Math.abs(n[1])>J?1:2;return n[t]<0&&(n[0]*=-1,n[1]*=-1,n[2]*=-1),`${n[0].toFixed(6)},${n[1].toFixed(6)},${n[2].toFixed(6)}`}function he(e,n,t,o,r={}){let s=pe(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],c=Math.hypot(i[0],i[1],i[2]);if(c<=J)return null;let l=[i[0]/c,i[1]/c,i[2]/c],a=[t[1]*l[2]-t[2]*l[1],t[2]*l[0]-t[0]*l[2],t[0]*l[1]-t[1]*l[0]],d=Math.hypot(a[0],a[1],a[2]);if(d<=J)return null;let m=[a[0]/d,a[1]/d,a[2]/d],f=e.map(E=>{let P=E[0]-n[0],D=E[1]-n[1],O=E[2]-n[2];return[P*l[0]+D*l[1]+O*l[2],P*m[0]+D*m[1]+O*m[2]]}),h=r.boundsOrigin??n,u=n[0]-h[0],p=n[1]-h[1],b=n[2]-h[2],x=u*l[0]+p*l[1]+b*l[2],M=u*m[0]+p*m[1]+b*m[2],C=1/0,H=1/0,y=-1/0,g=-1/0;for(let[E,P]of f){let D=E+x,O=P+M;D<C&&(C=D),D>y&&(y=D),O<H&&(H=O),O>g&&(g=O)}let S=y-C,A=g-H;if(!Number.isFinite(S)||!Number.isFinite(A))return null;let w=r.snapBounds?Math.floor(C+B):C,_=r.snapBounds?Math.floor(H+B):H,v=r.snapBounds?Math.ceil(y-B):y,k=r.snapBounds?Math.ceil(g-B):g,T=Math.max(1,r.snapBounds?v-w:Math.ceil(S)),R=Math.max(1,r.snapBounds?k-_:Math.ceil(A));return{xAxis:l,yAxis:m,local2D:f,shiftX:x-w,shiftY:M-_,canvasW:T,canvasH:R,pixelArea:T*R,rawArea:S*A}}function Xn(e,n,t,o){let r=0,s=0;for(let i of e){let c=n[i];if(!c)return null;let l=he(c.pts,c.pts[0],c.normal,t,{boundsOrigin:o,snapBounds:!0});if(!l)return null;r+=l.pixelArea,s+=l.rawArea}return{pixelArea:r,rawArea:s}}function Yn(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,s=new Set;for(let i of e){let c=n[i];if(!c)continue;let l=[c.pts[1][0]-c.pts[0][0],c.pts[1][1]-c.pts[0][1],c.pts[1][2]-c.pts[0][2]],a=he(c.pts,c.pts[0],c.normal,l);o&&a?(o.pixelArea+=a.pixelArea,o.rawArea+=a.rawArea):o=null;for(let d=0;d<c.pts.length;d++){let m=Pt(c.pts[d],c.pts[(d+1)%c.pts.length]),f=he(c.pts,c.pts[0],c.normal,m);if(!f)continue;let h=Nn(f.xAxis);if(s.has(h))continue;s.add(h);let u=Xn(e,n,f.xAxis,t);u&&(!r||u.pixelArea<r.pixelArea||u.pixelArea===r.pixelArea&&u.rawArea<r.rawArea-B)&&(r={xAxis:f.xAxis,...u})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+B)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function $n(e,n){let t=n.tileSize??Ge,o=n.layerElevation??t,r=e.map(d=>Bn(d,t,o)),s=new Map,i=e.map(()=>new Set);for(let d=0;d<e.length;d++){let m=e[d].vertices;if(!(!m||m.length<3))for(let f=0;f<m.length;f++){let h=In(m[f],m[(f+1)%m.length]),u=s.get(h),p={polygon:d,edge:f};u?u.push(p):s.set(h,[p])}}let c=e.map(()=>new Set);for(let d of s.values())if(!(d.length<2)){for(let m of d)i[m.polygon].add(m.edge);for(let m=0;m<d.length;m++)for(let f=m+1;f<d.length;f++){let h=d[m].polygon,u=d[f].polygon;Fn(r[h],r[u])&&(c[h].add(u),c[u].add(h))}}let l=Array(e.length).fill(void 0),a=new Set;for(let d=0;d<e.length;d++){if(a.has(d)||!r[d]?.optimizable)continue;let m=[],f=[d];for(a.add(d);f.length>0;){let u=f.pop();m.push(u);for(let p of c[u])a.has(p)||(a.add(p),f.push(p))}if(m.length<2)continue;let h=Yn(m,r);if(h)for(let u of m)l[u]={xAxis:h.xAxis,boundsOrigin:h.boundsOrigin,seamEdges:i[u]}}for(let d=0;d<e.length;d++)!l[d]&&i[d].size>0&&(l[d]={seamEdges:i[d]});return l}function Un(e){if(typeof e.toBlob=="function")return new Promise(n=>{e.toBlob(t=>{n(t?URL.createObjectURL(t):null)},"image/png")});try{return Promise.resolve(e.toDataURL("image/png"))}catch{return Promise.resolve(null)}}function lt(e,n,t,o){if(o.optimize&&o.fixedXAxis)return he(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,s=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,i=s??(o.optimize?e.map((c,l)=>l):[0]);for(let c of i){let l=(c+1)%e.length,a=s?Pt(e[c],e[l]):[e[l][0]-e[c][0],e[l][1]-e[c][1],e[l][2]-e[c][2]],d=he(e,n,t,a,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});d&&(!r||d.pixelArea<r.pixelArea||d.pixelArea===r.pixelArea&&d.rawArea<r.rawArea-B)&&(r=d)}return r}function Wn(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=B)return;r.push(s)};for(let[r,s]of e.local2D)o(n,r+e.shiftX),o(t,s+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>B||Math.abs(t[0])>B||n[1]-n[0]<=B||t[1]-t[0]<=B))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,c=s+e.shiftY,l=Math.abs(i-n[0])<=B||Math.abs(i-n[1])<=B,a=Math.abs(c-t[0])<=B||Math.abs(c-t[1])<=B;if(!l||!a)return!1}return!0}function Et(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,c]=n,l=t[0],a=t[1],d=o[0],m=o[1],f=r[0],h=r[1],u=s[0],p=1-s[1],b=i[0],x=1-i[1],M=c[0],C=1-c[1],H=b-u,y=x-p,g=M-u,S=C-p,A=H*S-g*y;if(Math.abs(A)<=1e-9)return null;let w=d-l,_=f-l,v=m-a,k=h-a,T={a:(w*S-_*y)/A,b:(H*_-g*w)/A,c:(v*S-k*y)/A,d:(H*k-g*v)/A,e:0,f:0};return T.e=l-T.a*u-T.b*p,T.f=a-T.c*u-T.d*p,T}function At(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let s of e){let i=s[0],c=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(c))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,c),r=Math.max(r,c)}return{minU:n,minV:t,maxU:o,maxV:r}}function Zn(e,n,t,o,r,s,i,c){let a=ke(e.vertices,n,t).map(f=>{let h=f[0]-o[0],u=f[1]-o[1],p=f[2]-o[2];return[h*r[0]+u*r[1]+p*r[2]+i,h*s[0]+u*s[1]+p*s[2]+c]}),d=Et(a,e.uvs),m=At(e.uvs);return!d&&!m?null:{screenPts:a.flatMap(([f,h])=>[f,h]),uvAffine:d,uvSampleRect:m}}function Gn(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],o+=e[i+1];t/=r,o/=r;let s=e.slice();for(let i=0;i<s.length;i+=2){let c=s[i]-t,l=s[i+1]-o,a=Math.hypot(c,l);a<=B||(s[i]+=c/a*n,s[i+1]+=l/a*n)}return s}function jn(e){let n=0;for(let t=0;t<e.length;t+=2){let o=(t+2)%e.length;n+=e[t]*e[o+1]-e[o]*e[t+1]}return n/2}function qe(e,n,t,o){for(let r=0;r<o.length;r+=2){let s=n+o[r],i=t+o[r+1];r===0?e.moveTo(s,i):e.lineTo(s,i)}e.closePath()}function qn(e,n,t,o,r,s){if(qe(e,n,t,o),!r||r.size===0||s<=0)return;let i=o.length/2,c=jn(o);for(let l of r){let a=l*2,d=(l+1)%i*2,m=o[a],f=o[a+1],h=o[d],u=o[d+1],p=h-m,b=u-f,x=Math.hypot(p,b);if(x<=B)continue;let M=c>=0?b/x:-b/x,C=c>=0?-p/x:p/x;e.moveTo(n+m,t+f),e.lineTo(n+h,t+u),e.lineTo(n+h+M*s,t+u+C*s),e.lineTo(n+m+M*s,t+f+C*s),e.closePath()}}function Kn(e,n,t,o){let{vertices:r,texture:s,uvs:i}=e;if(!r||r.length<3)return null;let c=t.tileSize??Ge,l=t.layerElevation??c,a=ke(r,c,l),d=a[0],m=a[1],f=[m[0]-d[0],m[1]-d[1],m[2]-d[2]];if(Math.hypot(f[0],f[1],f[2])===0)return null;let u=je(a);if(!u)return null;let p=lt(a,d,u,{optimize:!1}),b=s||p&&Wn(p)?p:lt(a,d,u,{optimize:!0,fixedXAxis:o?.xAxis,boundsOrigin:o?.boundsOrigin,snapBounds:!!o,seamEdges:o?.seamEdges});if(!b)return null;let{xAxis:x,yAxis:M,local2D:C,shiftX:H,shiftY:y}=b,g=[];for(let[Y,z]of C)g.push(Y+H,z+y);let S=d[0]-H*x[0]-y*M[0],A=d[1]-H*x[1]-y*M[1],w=d[2]-H*x[2]-y*M[2],_=bt([x[0],x[1],x[2],0,M[0],M[1],M[2],0,u[0],u[1],u[2],0,S,A,w,1]),v=t.directionalLight,k=t.ambientLight,T=v?.direction??dt,R=v?.color??pt,E=Math.max(0,v?.intensity??mt),P=k?.color??ft,D=Math.max(0,k?.intensity??ht),O=Math.hypot(T[0],T[1],T[2])||1,F=T[0]/O,Z=T[1]/O,L=T[2]/O,I=E*Math.max(0,u[0]*F+u[1]*Z+u[2]*L),V=On(I,R,P,D),X=xt(e.color??"#cccccc",I,R,P,D),$=null,U=null;s&&i&&i.length>=3&&i.length===r.length&&(U=At(i),$=Et(C.map(([Y,z])=>[Y+H,z+y]),i));let W=s&&e.textureTriangles?.length?e.textureTriangles.map(Y=>Zn(Y,c,l,d,x,M,H,y)).filter(Y=>!!Y):null;return{index:n,polygon:e,texture:s,tileSize:c,layerElevation:l,matrix:_,canvasW:b.canvasW,canvasH:b.canvasH,screenPts:g,uvAffine:$,uvSampleRect:U,textureTriangles:W,seamEdges:o?.seamEdges.size?o.seamEdges:null,normal:u,textureTint:V,shadedColor:X}}function Mt(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??Ge,r=t.layerElevation??o,s=ke(e.vertices,o,r),i=je(s);if(!i)return null;let c=[{a:0,b:1,c:2},{a:1,b:2,c:0},{a:2,b:0,c:1}].map(K=>{let q=s[K.a],ne=s[K.b];return{...K,length:Math.hypot(ne[0]-q[0],ne[1]-q[1],ne[2]-q[2])}}).sort((K,q)=>q.length-K.length),l=c[0].a,a=c[0].b,d=c[0].c,m=s[l],f=s[a],h=s[d],u=c[0].length;if(u<=J)return null;let p=[(f[0]-m[0])/u,(f[1]-m[1])/u,(f[2]-m[2])/u],b=[h[0]-m[0],h[1]-m[1],h[2]-m[2]],x=pe(b,p),M=[m[0]+p[0]*x,m[1]+p[1]*x,m[2]+p[2]*x],C=[M[0]-h[0],M[1]-h[1],M[2]-h[2]],H=Math.hypot(C[0],C[1],C[2]);if(H<=J)return null;let y=[C[0]/H,C[1]/H,C[2]/H];if(pe(zn(p,y),i)<0){let K=a;if(a=l,l=K,m=s[l],f=s[a],u=Math.hypot(f[0]-m[0],f[1]-m[1],f[2]-m[2]),u<=J)return null;p=[(f[0]-m[0])/u,(f[1]-m[1])/u,(f[2]-m[2])/u];let q=[h[0]-m[0],h[1]-m[1],h[2]-m[2]];x=pe(q,p),M=[m[0]+p[0]*x,m[1]+p[1]*x,m[2]+p[2]*x],C=[M[0]-h[0],M[1]-h[1],M[2]-h[2]];let ne=Math.hypot(C[0],C[1],C[2]);if(ne<=J)return null;y=[C[0]/ne,C[1]/ne,C[2]/ne]}let g=Math.max(0,Math.min(u,x)),S=Math.max(0,u-g),A=bn,w=g+A,_=S+A,v=H+A*2,k=h[0]-w*p[0]-A*y[0],T=h[1]-w*p[1]-A*y[1],R=h[2]-w*p[2]-A*y[2],E=bt([p[0],p[1],p[2],0,y[0],y[1],y[2],0,i[0],i[1],i[2],0,k,T,R,1]),P=t.directionalLight,D=t.ambientLight,O=P?.direction??dt,F=P?.color??pt,Z=Math.max(0,P?.intensity??mt),L=D?.color??ft,I=Math.max(0,D?.intensity??ht),V=Math.hypot(O[0],O[1],O[2])||1,X=O[0]/V,$=O[1]/V,U=O[2]/V,W=Z*Math.max(0,i[0]*X+i[1]*$+i[2]*U),Y=xt(e.color??"#cccccc",W,F,L,I),z=t.textureLighting??"baked",ee=re(e.color??"#cccccc"),le=z==="dynamic"?"":`border-bottom-color:${Y};`,te=z==="dynamic"?`--pnx:${i[0].toFixed(4)};--pny:${i[1].toFixed(4)};--pnz:${i[2].toFixed(4)};--psr:${(ee.r/255).toFixed(4)};--psg:${(ee.g/255).toFixed(4)};--psb:${(ee.b/255).toFixed(4)};`:"",Xe=`transform:matrix3d(${E});border-width:0 ${_}px ${v}px ${w}px;`+le+te;return{index:n,polygon:e,styleText:Xe}}function Se(e,n=1){let t=Array(e.length).fill(null),o=[],r=Sn(n),s=e.filter(l=>!!l).sort((l,a)=>a.canvasH-l.canvasH||a.canvasW-l.canvasW||l.index-a.index),i=()=>({width:r,height:r,entries:[],shelves:[]}),c=(l,a,d)=>{if(l.sealed)return null;for(let h of l.shelves)if(a.canvasH<=h.height&&h.x+a.canvasW+r<=de){let u={...a,pageIndex:d,x:h.x,y:h.y};return h.x+=a.canvasW+r*2,l.entries.push(u),l.width=Math.max(l.width,u.x+a.canvasW+r),u}let m=l.shelves.length===0?r:l.height+r;if(m+a.canvasH+r>de)return null;let f={...a,pageIndex:d,x:r,y:m};return l.shelves.push({x:r+a.canvasW+r*2,y:m,height:a.canvasH}),l.entries.push(f),l.width=Math.max(l.width,f.x+a.canvasW+r),l.height=Math.max(l.height,m+a.canvasH+r),f};for(let l of s){if(l.canvasW+r*2>de||l.canvasH+r*2>de){let m=o.length,f={...l,pageIndex:m,x:r,y:r};t[l.index]=f,o.push({width:l.canvasW+r*2,height:l.canvasH+r*2,entries:[f],shelves:[],sealed:!0});continue}let d=null;for(let m=0;m<o.length&&(d=c(o[m],l,m),!d);m++);if(!d){let m=i(),f=o.length;o.push(m),d=c(m,l,f)}d&&(t[l.index]=d)}return{entries:t,pages:o.map(({width:l,height:a,entries:d})=>({width:l,height:a,entries:d}))}}function Jn(e,n,t,o){Q(e,o),e.beginPath(),qe(e,n.x,n.y,n.screenPts),e.clip(),Q(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function ue(e,n){return Math.max(0,Math.min(n,e))}function ct(e,n,t,o,r,s,i,c){let l=n.naturalWidth||n.width||1,a=n.naturalHeight||n.height||1,d=ue(Math.min(t.minU,t.maxU)*l,l),m=ue(Math.max(t.minU,t.maxU)*l,l),f=ue(Math.min(t.minV,t.maxV)*a,a),h=ue(Math.max(t.minV,t.maxV)*a,a),u=Math.floor(d),p=Math.floor(f),b=Math.ceil(m)-u,x=Math.ceil(h)-p;b<1&&(u=Math.floor(ue((t.minU+t.maxU)/2*l,l-1)),b=1),x<1&&(p=Math.floor(ue((t.minV+t.maxV)/2*a,a-1)),x=1),u=Math.max(0,Math.min(l-1,u)),p=Math.max(0,Math.min(a-1,p)),b=Math.max(1,Math.min(l-u,b)),x=Math.max(1,Math.min(a-p,x)),Q(e,c),e.drawImage(n,u,p,b,x,o,r,s,i)}async function Qn(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=r.getContext("2d");if(!s)return{width:e.width,height:e.height,url:null};let i=Array.from(new Set(e.entries.flatMap(a=>a.texture?[a.texture]:[]))),c=new Map;await Promise.all(i.map(async a=>{c.set(a,await Pn(a))}));for(let a of e.entries){let d=a.texture?c.get(a.texture):null;if(s.save(),Q(s,o),s.beginPath(),a.texture?qn(s,a.x,a.y,a.screenPts,a.seamEdges,gn):qe(s,a.x,a.y,a.screenPts),s.clip(),!a.texture)Jn(s,a,n,o);else if(d&&a.textureTriangles?.length){let m=d.naturalWidth||d.width||1,f=d.naturalHeight||d.height||1;for(let h of a.textureTriangles){let u=Gn(h.screenPts,yn);s.save(),Q(s,o),s.beginPath();for(let p=0;p<u.length;p+=2){let b=a.x+u[p],x=a.y+u[p+1];p===0?s.moveTo(b,x):s.lineTo(b,x)}s.closePath(),s.clip(),h.uvAffine?(Q(s,o,h.uvAffine.a/m,h.uvAffine.c/m,h.uvAffine.b/f,h.uvAffine.d/f,a.x+h.uvAffine.e,a.y+h.uvAffine.f),s.drawImage(d,0,0)):h.uvSampleRect&&ct(s,d,h.uvSampleRect,a.x,a.y,a.canvasW,a.canvasH,o),s.restore()}}else if(d&&a.uvAffine){let m=d.naturalWidth||d.width||1,f=d.naturalHeight||d.height||1;Q(s,o,a.uvAffine.a/m,a.uvAffine.c/m,a.uvAffine.b/f,a.uvAffine.d/f,a.x+a.uvAffine.e,a.y+a.uvAffine.f),s.drawImage(d,0,0)}else d&&a.uvSampleRect?ct(s,d,a.uvSampleRect,a.x,a.y,a.canvasW,a.canvasH,o):d&&Rn(s,d,a.x,a.y,a.canvasW,a.canvasH,o);a.texture&&n==="baked"&&Dn(s,a.x,a.y,a.canvasW,a.canvasH,a.textureTint,o),s.restore()}let l=await Un(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:l}}async function eo(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await Qn(i,n,t,o))}return s}function to(e,n,t,o){if(!n.url)return;let r=`url(${n.url})`,s=`-${o.x}px -${o.y}px`,i=`${n.width}px ${n.height}px`;t==="dynamic"?(e.style.backgroundImage=r,e.style.backgroundPosition=s,e.style.backgroundSize=i):e.style.background=`${r} ${s} / ${i} no-repeat`,t==="dynamic"?(e.style.maskImage=r,e.style.maskMode="alpha",e.style.maskPosition=s,e.style.maskSize=i,e.style.maskRepeat="no-repeat",e.style.setProperty("-webkit-mask-image",r),e.style.setProperty("-webkit-mask-position",s),e.style.setProperty("-webkit-mask-size",i),e.style.setProperty("-webkit-mask-repeat","no-repeat")):(e.style.maskImage="",e.style.maskMode="",e.style.maskPosition="",e.style.maskSize="",e.style.maskRepeat="",e.style.removeProperty("-webkit-mask-image"),e.style.removeProperty("-webkit-mask-position"),e.style.removeProperty("-webkit-mask-size"),e.style.removeProperty("-webkit-mask-repeat"))}function Ke(e,n){let t=We.get(e);if(t)for(let r of t)e.removeAttribute(`data-${r}`);let o=[];if(n.data)for(let[r,s]of Object.entries(n.data))e.setAttribute(`data-${r}`,String(s)),o.push(r);We.set(e,o)}function Je(e,n){e.style.width=`${n.canvasW}px`,e.style.height=`${n.canvasH}px`,e.style.transform=`matrix3d(${n.matrix})`,Ke(e,n.polygon)}function Ct(e,n){e.style.setProperty("--pnx",n.normal[0].toFixed(4)),e.style.setProperty("--pny",n.normal[1].toFixed(4)),e.style.setProperty("--pnz",n.normal[2].toFixed(4))}function no(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=B)return;r.push(s)};for(let r=0;r<e.screenPts.length;r+=2)o(n,e.screenPts[r]),o(t,e.screenPts[r+1]);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>B||Math.abs(t[0])>B||n[1]-n[0]<=B||t[1]-t[0]<=B))return null;for(let r=0;r<e.screenPts.length;r+=2){let s=e.screenPts[r],i=e.screenPts[r+1],c=Math.abs(s-n[0])<=B||Math.abs(s-n[1])<=B,l=Math.abs(i-t[0])<=B||Math.abs(i-t[1])<=B;if(!c||!l)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function ut(e){return!!no(e)}function oo(e){return!e.texture&&e.polygon.vertices.length===3}function ro(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) polygon(50% 50%, 50% 50%, 50% 50%)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function so(e){let n=[],t=e.canvasW||1,o=e.canvasH||1;for(let r=0;r<e.screenPts.length;r+=2){let s=Math.max(0,Math.min(100,e.screenPts[r]/t*100)),i=Math.max(0,Math.min(100,e.screenPts[r+1]/o*100));n.push(`${Le(s)} ${Le(i)}`)}return`polygon(${n.join(", ")})`}function io(e){let n=0,t=0,o=Math.max(1,e.screenPts.length/2);for(let l=0;l<e.screenPts.length;l+=2)n+=e.screenPts[l],t+=e.screenPts[l+1];let r=e.canvasW||1,s=e.canvasH||1,i=Le(Math.max(0,Math.min(100,n/o/r*100))),c=Le(Math.max(0,Math.min(100,t/o/s*100)));return`polygon(${Array.from({length:o},()=>`${i} ${c}`).join(", ")})`}function ao(e){return`${so(e)} ${io(e)}`}function lo(e,n,t){if(t==="dynamic"){Ct(e,n);let o=re(n.polygon.color??"#cccccc");e.style.setProperty("--psr",(o.r/255).toFixed(4)),e.style.setProperty("--psg",(o.g/255).toFixed(4)),e.style.setProperty("--psb",(o.b/255).toFixed(4))}else e.style.background=n.shadedColor}function co(e,n,t){let o=t.createElement("b");return Je(o,e),lo(o,e,n),o}function uo(e,n){let t=n.createElement("i");return Je(t,e),t.style.color=e.shadedColor,t.style.setProperty("border-shape",ao(e)),t}function po(e,n,t){let o=t.createElement("s");return Je(o,e),o.style.backgroundPosition=`-${e.x}px -${e.y}px`,o.style.opacity="0",n==="dynamic"&&Ct(o,e),o}function Tt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=o!=="dynamic"&&ro(t),s=$n(e,n),i=e.map((p,b)=>Kn(p,b,n,s[b])),c=i.map(p=>p&&oo(p)?Mt(p.polygon,p.index,n):null),l=i.map((p,b)=>p&&(p.texture||!ut(p)&&!c[b]&&!r?p:null)),{packed:a,atlasScale:d}=_n(l,n.atlasScale),m=new Map,f=[],h=!1,u=[];for(let p=0;p<e.length;p++){let b=i[p],x=c[p];if(!b)continue;let M=a.entries[p];if(M){let C=po(M,o,t);m.set(p,C),f.push({polygonIndex:p,element:C,kind:"atlas",dispose:()=>{}})}else if(!b.texture&&ut(b)){let C=co(b,o,t);f.push({polygonIndex:p,element:C,kind:"solid",dispose:()=>{}})}else if(!b.texture&&x){let C=St(x,t);f.push({polygonIndex:p,element:C,kind:"triangle",dispose:()=>{}})}else if(!b.texture&&r){let C=uo(b,t);f.push({polygonIndex:p,element:C,kind:"border",dispose:()=>{}})}}return f.sort((p,b)=>p.polygonIndex-b.polygonIndex),eo(a.pages,o,t,d,()=>h).then(p=>{if(h){for(let b of p)b.url?.startsWith("blob:")&&URL.revokeObjectURL(b.url);return}u=p.flatMap(b=>b.url?.startsWith("blob:")?[b.url]:[]);for(let b=0;b<a.pages.length;b++){let x=a.pages[b],M=p[b];if(M)for(let C of x.entries){let H=m.get(C.index);!H||!M.url||(to(H,M,o,C),H.style.opacity="")}}}).catch(()=>{if(!h)for(let p of m.values())p.style.opacity="0.5",p.style.outline="1px dashed rgba(255, 0, 0, 0.6)"}),{rendered:f,dispose(){h=!0;for(let p of u)URL.revokeObjectURL(p);u=[]}}}function Lt(e,n){let t=e.map((o,r)=>Mt(o,r,n));return t.some(o=>!o)?null:t}function mo(e){e.style.backgroundImage="",e.style.backgroundPosition="",e.style.backgroundSize="",e.style.maskImage="",e.style.maskMode="",e.style.maskPosition="",e.style.maskSize="",e.style.maskRepeat="",e.style.removeProperty("-webkit-mask-image"),e.style.removeProperty("-webkit-mask-position"),e.style.removeProperty("-webkit-mask-size"),e.style.removeProperty("-webkit-mask-repeat")}function _t(e,n){e.style.cssText=n.styleText,(n.polygon.data||We.get(e)?.length)&&Ke(e,n.polygon)}function St(e,n){let t=n.createElement("u");return mo(t),_t(t,e),Ke(t,e.polygon),t}function wt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=Lt(e,n);if(!o)return null;let r=[];for(let s of o){let i=St(s,t);r.push({polygonIndex:s.index,element:i,kind:"triangle",dispose:()=>{}})}return r.sort((s,i)=>s.polygonIndex-i.polygonIndex),{rendered:r,dispose(){}}}function kt(e,n,t={}){if(!(t.doc??(typeof document<"u"?document:null)))return{rendered:e,dispose:()=>{}};if(e.some(s=>s.kind!=="triangle"))return null;let r=Lt(n,t);if(!r||r.length!==e.length)return null;for(let s=0;s<e.length;s++)if(e[s].polygonIndex!==r[s].index)return null;for(let s=0;s<e.length;s++)_t(e[s].element,r[s]);return{rendered:e,dispose(){}}}var Ot="polycss-styles";function Ht(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(Ot))return;let t=n.createElement("style");t.id=Ot,t.textContent=fo,n.head.appendChild(t)}var fo=`
1
+ "use strict";var Rt=Object.defineProperty;var Do=Object.getOwnPropertyDescriptor;var Oo=Object.getOwnPropertyNames;var Io=Object.prototype.hasOwnProperty;var Ho=(e,n)=>{for(var t in n)Rt(e,t,{get:n[t],enumerable:!0})},Vo=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Oo(n))!Io.call(e,r)&&r!==t&&Rt(e,r,{get:()=>n[r],enumerable:!(o=Do(n,r))||o.enumerable});return e};var zo=e=>Vo(Rt({},"__esModule",{value:!0}),e);var Li={};Ho(Li,{PolyAxesHelperElement:()=>je,PolyDirectionalLightHelperElement:()=>Ze,PolyMapControlsElement:()=>Ke,PolyMeshElement:()=>Oe,PolyOrbitControlsElement:()=>Qe,PolyOrthographicCameraElement:()=>et,PolyPerspectiveCameraElement:()=>Je,PolyPolygonElement:()=>We,PolySceneElement:()=>xe,PolySelectElement:()=>ot,PolyTransformControlsElement:()=>nt});module.exports=zo(Li);var ee=require("@layoutit/polycss-core");var zt=require("@layoutit/polycss-core"),Ft=50,Bt=[.4,-.7,.59],Nt="#ffffff",$t=1,Xt="#ffffff",Yt=.4,Ve=4096,mn=1,Fo=.1,Bo=1,Sn=Ve*Ve,No=Sn*3,Ot=2048,$o=4*1024*1024,Xo=16*1024*1024,Yo=.995,Uo=12,Ie=new Map,It=new WeakMap,oe=.001,ce=1e-9,Go=1e-4,Wo=.1,pn=.01,jo=.75,Zo=1,qo=250,fn=1.5,Qo=.75,Ko=3,Jo=2,er=4,Ht=64,Le=64,Ee=64,tr=128,hn=50,gn=1e-7,yn=16,kt=.9,nr=.05,or=Number.POSITIVE_INFINITY,rr=.6;function sr(e){let n=Ie.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),Ie.set(e,n),n.then(()=>{Ie.get(e)===n&&Ie.delete(e)},()=>{Ie.get(e)===n&&Ie.delete(e)})),n}function ct(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Bo,Math.max(Fo,n))}function Ut(e,n){let t=e.toFixed(n).replace(/\.?0+$/,"");return Object.is(Number(t),-0)?"0":t}function ze(e,n=er){let t=Ut(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function Ce(e,n=Ko){return e.map(t=>Ut(t,n)).join(",")}function wn(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=ce)return!1;let l=Math.sign(i);if(n===0)n=l;else if(l!==n)return!1}return!0}function ir(e){let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-o[1]*r[0]}return n/2}function ar(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],l=o[1]-t[1],a=r*l-s*i;if(Math.abs(a)<=ce)return null;let u=t[0]-e[0],m=t[1]-e[1],d=(u*l-m*i)/a;return[e[0]+d*r,e[1]+d*s]}function Gt(e,n){if(e.length<6||e.length%2!==0||n<=0)return e;let t=[];for(let a=0;a<e.length;a+=2)t.push([e[a],e[a+1]]);if(!wn(t))return Xe(e,n);let o=ir(t);if(Math.abs(o)<=ce)return Xe(e,n);let r=o>0?1:-1,s=[];for(let a=0;a<t.length;a++){let u=t[a],m=t[(a+1)%t.length],d=m[0]-u[0],f=m[1]-u[1],g=Math.hypot(d,f);if(g<=ce)return Xe(e,n);let p=r*(f/g)*n,h=r*(-d/g)*n;s.push({a:[u[0]+p,u[1]+h],b:[m[0]+p,m[1]+h]})}let i=[],l=Math.max(2,n*4);for(let a=0;a<t.length;a++){let u=s[(a+t.length-1)%t.length],m=s[a],d=ar(u.a,u.b,m.a,m.b);if(!d)return Xe(e,n);let f=t[a],g=d[0]-f[0],p=d[1]-f[1],h=Math.hypot(g,p);h>l?i.push(f[0]+g/h*l,f[1]+p/h*l):i.push(d[0],d[1])}return i}function bn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function Wt(e){let t=e?.defaultView?.__polycssProjectiveQuadGuards,o=t?.maxWeightRatio,r=Math.max(0,bn(t?.denomEps,nr)),s=typeof o=="number"&&Number.isFinite(o)&&o>0?Math.max(1,o):or,i=Math.max(0,bn(t?.bleed,rr));return{denomEps:r,maxWeightRatio:s,bleed:i,disableGuards:t?.disableGuards===!0}}function xn(e,n){if(e.length!==4||!wn(e))return null;let[t,o,r,s]=e,i=t[0]-o[0]+r[0]-s[0],l=t[1]-o[1]+r[1]-s[1],a=o[0]-r[0],u=s[0]-r[0],m=o[1]-r[1],d=s[1]-r[1],f=a*d-m*u;if(Math.abs(f)<=ce)return null;let g=(i*d-l*u)/f,p=(a*l-m*i)/f,h=[1,1+g,1+g+p,1+p];if(h.some(A=>!Number.isFinite(A)))return null;let b=Math.min(...h),x=Math.max(...h);return!n.disableGuards&&(b<=n.denomEps||x/b>n.maxWeightRatio)?null:{g,h:p,w1:1+g,w3:1+p}}function lr(e,n,t,o,r,s,i,l){if(e.length!==8)return null;let a=[[e[0],e[1]],[e[2],e[3]],[e[4],e[5]],[e[6],e[7]]];if(!xn(a,l))return null;let u=Gt(e,l.bleed),m=[[u[0],u[1]],[u[2],u[3]],[u[4],u[5]],[u[6],u[7]]],d=xn(m,l);if(!d)return null;let{g:f,h:g,w1:p,w3:h}=d,[b,x,,A]=m,M=[r+b[0]*n[0]+b[1]*t[0],s+b[0]*n[1]+b[1]*t[1],i+b[0]*n[2]+b[1]*t[2]],P=([k,C],v)=>[(v-1)*r+(v*k-b[0])*n[0]+(v*C-b[1])*t[0],(v-1)*s+(v*k-b[0])*n[1]+(v*C-b[1])*t[1],(v-1)*i+(v*k-b[0])*n[2]+(v*C-b[1])*t[2]],E=[...P(x,p),f,...P(A,h),g,o[0],o[1],o[2],0,M[0],M[1],M[2],1];for(let k=0;k<8;k+=1)E[k]/=Ht;return Ce(E,6)}function st(e,n=Jo){let t=Ut(e,n);return Number(t)===0?"0":`${t}%`}function cr(e,n,t,o,r,s){let i=(e-t)*(s-o)-(n-o)*(r-t);return Math.abs(i)>gn?!1:(e-t)*(e-r)+(n-o)*(n-s)<=gn}function ur(e,n=hn,t=hn){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,l]=e[r],[a,u]=e[s];if(cr(n,t,i,l,a,u))return!0;l>t!=u>t&&n<(a-i)*(t-l)/(u-l)+i&&(o=!o)}return o}function Tn(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function dr(e,n){let t=Tn(e);if(t<=0)return 1;let o=Math.max(1,...e.map(i=>Math.max(i.width,i.height))),r=Ot/o,s=Math.sqrt(n/(t*4));return ct(Math.min(r,s))}function mr(e,n){let t=Tn(e),o=.5;return t<=Sn?o=1:t<=No&&(o=.75),ct(Math.min(o,dr(e,n)))}function pr(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function fr(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function hr(e,n,t){let o=pr(e,n),r=fr(e,n),s=o>Ot?Ot/o:1,i=r>t?Math.sqrt(t/r):1;return Math.min(s,i)}function gr(e,n,t){let o=mr(n.pages,t),r=o===1?n:at(e,o);for(let s=0;s<4;s++){let i=hr(r.pages,o,t);if(i>=1)break;let l=ct(o*i*Yo);if(l>=o)break;o=l,r=at(e,o)}return{packed:r,atlasScale:o}}function yr(e){return Ln(e)?$o:Xo}function Ln(e){if(!e)return!1;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return t?t("(pointer: coarse)").matches||t("(hover: none)").matches:!1}function br(e,n){return e!==void 0&&e!=="auto"||Ln(n)?Ee:tr}function xr(e,n){let t=e.matrix.split(",").map(o=>Number(o));return t.length!==16||t.some(o=>!Number.isFinite(o))?e.canonicalMatrix:(t[0]*=e.canvasW/n,t[1]*=e.canvasW/n,t[2]*=e.canvasW/n,t[4]*=e.canvasH/n,t[5]*=e.canvasH/n,t[6]*=e.canvasH/n,Ce(t))}function vn(e,n){for(let t of e.entries)t&&(t.atlasCanonicalSize=n,t.atlasMatrix=xr(t,n));return e}function Me(e){return e.atlasCanonicalSize??Ee}function _n(e,n,t){let o=br(n,t);if(n!==void 0&&n!=="auto"){let i=ct(n);return{packed:vn(at(e,i),o),atlasScale:i,atlasCanonicalSize:o}}let r=at(e,1),s=gr(e,r,yr(t));return{packed:vn(s.packed,o),atlasScale:s.atlasScale,atlasCanonicalSize:o}}function vr(e){return Math.max(mn,Math.ceil(mn/e))}function Pe(e,n,t=1,o=0,r=0,s=1,i=0,l=0){e.setTransform(t*n,o*n,r*n,s*n,i*n,l*n)}function Se(e){let n=(0,zt.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function jt({r:e,g:n,b:t}){return`${e},${n},${t}`}function Pr(e){return(0,zt.parsePureColor)(e)?.alpha??1}function Er({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function J(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,s=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`(^|;)\\s*${s}\\s*:[^;]*`,"i"),l=i.test(o)?o.replace(i,(a,u)=>`${u}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;l!==o&&e.setAttribute("style",l)}function pe(e,n){let t=e.getAttribute("style")??"";if(!t)return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`^\\s*${o}\\s*:`,"i"),s=t.split(";").map(i=>i.trim()).filter(i=>i&&!r.test(i)).join(";");s?e.setAttribute("style",s):e.removeAttribute("style")}function Rn(e,n,t,o,r){let s=Se(e),i=Se(t),l=Se(o),a=l.r/255*r+i.r/255*n,u=l.g/255*r+i.g/255*n,m=l.b/255*r+i.b/255*n,d=Math.max(0,Math.min(255,Math.round(s.r*a))),f=Math.max(0,Math.min(255,Math.round(s.g*u))),g=Math.max(0,Math.min(255,Math.round(s.b*m))),p=Pr(e);return p<1?`rgba(${d}, ${f}, ${g}, ${p})`:Er({r:d,g:f,b:g})}function kn(e,n,t,o){let r=Se(n),s=Se(t);return{r:s.r/255*o+r.r/255*e,g:s.g/255*o+r.g/255*e,b:s.b/255*o+r.b/255*e}}function Ar({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(1,r))*255);return`rgb(${o(e)} ${o(n)} ${o(t)})`}function Mr(e,n,t,o,r,s,i){Math.abs(s.r-1)<.001&&Math.abs(s.g-1)<.001&&Math.abs(s.b-1)<.001||(e.save(),Pe(e,i),e.globalCompositeOperation="multiply",e.fillStyle=Ar(s),e.fillRect(n,t,o,r),e.restore())}function Cr(e,n,t,o,r,s,i){let l=n.naturalWidth||n.width||1,a=n.naturalHeight||n.height||1,u=Math.max(r/l,s/a),m=l*u,d=a*u;Pe(e,i),e.drawImage(n,t+(r-m)/2,o+(s-d)/2,m,d)}function it(e){return`${e[0]},${e[1]},${e[2]}`}function Sr(e,n){let t=it(e),o=it(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Dn(e,n){return it(e)<it(n)?[n[0]-e[0],n[1]-e[1],n[2]-e[2]]:[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function wr(e){return!e.texture}function Ue(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function ut(e){if(e.length<3)return null;let n=e[0],t=0,o=0,r=0;for(let i=1;i+1<e.length;i++){let l=e[i],a=e[i+1],u=[l[0]-n[0],l[1]-n[1],l[2]-n[2]],m=[a[0]-n[0],a[1]-n[1],a[2]-n[2]];t-=u[1]*m[2]-u[2]*m[1],o-=u[2]*m[0]-u[0]*m[2],r-=u[0]*m[1]-u[1]*m[0]}let s=Math.hypot(t,o,r);return s<=ce?null:(t/=s,o/=s,r/=s,[t,o,r])}function Fe(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Tr(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Lr(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=Ue(e.vertices,n,t),r=ut(o);return r?{pts:o,normal:r,planeD:Fe(r,o[0]),optimizable:wr(e)}:null}function _r(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:On(e,n)}function On(e,n){return!e||!n||Fe(e.normal,n.normal)<1-Go?!1:Math.abs(e.planeD-n.planeD)<=Wo}function Pn(e,n){if(!e)return null;let t=n.directionalLight,o=n.ambientLight,r=t?.direction??Bt,s=t?.color??Nt,i=Math.max(0,t?.intensity??$t),l=o?.color??Xt,a=Math.max(0,o?.intensity??Yt),u=Math.hypot(r[0],r[1],r[2])||1,m=r[0]/u,d=r[1]/u,f=r[2]/u,g=i*Math.max(0,e.normal[0]*m+e.normal[1]*d+e.normal[2]*f),p=kn(g,s,l,a);return p.r*.2126+p.g*.7152+p.b*.0722}function Rr(e){let n=[...e],t=Math.abs(n[0])>ce?0:Math.abs(n[1])>ce?1:2;return n[t]<0&&(n[0]*=-1,n[1]*=-1,n[2]*=-1),`${n[0].toFixed(6)},${n[1].toFixed(6)},${n[2].toFixed(6)}`}function Ye(e,n,t,o,r={}){let s=Fe(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],l=Math.hypot(i[0],i[1],i[2]);if(l<=ce)return null;let a=[i[0]/l,i[1]/l,i[2]/l],u=[t[1]*a[2]-t[2]*a[1],t[2]*a[0]-t[0]*a[2],t[0]*a[1]-t[1]*a[0]],m=Math.hypot(u[0],u[1],u[2]);if(m<=ce)return null;let d=[u[0]/m,u[1]/m,u[2]/m],f=e.map(w=>{let O=w[0]-n[0],H=w[1]-n[1],V=w[2]-n[2];return[O*a[0]+H*a[1]+V*a[2],O*d[0]+H*d[1]+V*d[2]]}),g=r.boundsOrigin??n,p=n[0]-g[0],h=n[1]-g[1],b=n[2]-g[2],x=p*a[0]+h*a[1]+b*a[2],A=p*d[0]+h*d[1]+b*d[2],M=1/0,P=1/0,E=-1/0,k=-1/0;for(let[w,O]of f){let H=w+x,V=O+A;H<M&&(M=H),H>E&&(E=H),V<P&&(P=V),V>k&&(k=V)}let C=E-M,v=k-P;if(!Number.isFinite(C)||!Number.isFinite(v))return null;let B=r.snapBounds?Math.floor(M+oe):M,N=r.snapBounds?Math.floor(P+oe):P,Y=r.snapBounds?Math.ceil(E-oe):E,ne=r.snapBounds?Math.ceil(k-oe):k,S=Math.max(1,r.snapBounds?Y-B:Math.ceil(C)),$=Math.max(1,r.snapBounds?ne-N:Math.ceil(v));return{xAxis:a,yAxis:d,local2D:f,shiftX:x-B,shiftY:A-N,canvasW:S,canvasH:$,pixelArea:S*$,rawArea:C*v}}function kr(e,n,t,o){let r=0,s=0;for(let i of e){let l=n[i];if(!l)return null;let a=Ye(l.pts,l.pts[0],l.normal,t,{boundsOrigin:o,snapBounds:!0});if(!a)return null;r+=a.pixelArea,s+=a.rawArea}return{pixelArea:r,rawArea:s}}function Dr(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,s=new Set;for(let i of e){let l=n[i];if(!l)continue;let a=[l.pts[1][0]-l.pts[0][0],l.pts[1][1]-l.pts[0][1],l.pts[1][2]-l.pts[0][2]],u=Ye(l.pts,l.pts[0],l.normal,a);o&&u?(o.pixelArea+=u.pixelArea,o.rawArea+=u.rawArea):o=null;for(let m=0;m<l.pts.length;m++){let d=Dn(l.pts[m],l.pts[(m+1)%l.pts.length]),f=Ye(l.pts,l.pts[0],l.normal,d);if(!f)continue;let g=Rr(f.xAxis);if(s.has(g))continue;s.add(g);let p=kr(e,n,f.xAxis,t);p&&(!r||p.pixelArea<r.pixelArea||p.pixelArea===r.pixelArea&&p.rawArea<r.rawArea-oe)&&(r={xAxis:f.xAxis,...p})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+oe)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function Zt(e,n){let t=n.tileSize??Ft,o=n.layerElevation??t,r=e.map(d=>Lr(d,t,o)),s=new Map,i=e.map(()=>new Set),l=e.map(()=>new Set);for(let d=0;d<e.length;d++){let f=e[d].vertices;if(!(!f||f.length<3))for(let g=0;g<f.length;g++){let p=Sr(f[g],f[(g+1)%f.length]),h=s.get(p),b={polygon:d,edge:g};h?h.push(b):s.set(p,[b])}}let a=e.map(()=>new Set);for(let d of s.values())if(!(d.length<2))for(let f=0;f<d.length;f++)for(let g=f+1;g<d.length;g++){let p=d[f],h=d[g],b=p.polygon,x=h.polygon;if(e[b].texture&&e[x].texture&&(l[p.polygon].add(p.edge),l[h.polygon].add(h.edge)),On(r[b],r[x]))i[p.polygon].add(p.edge),i[h.polygon].add(h.edge);else{let A=Pn(r[b],n),M=Pn(r[x],n);A!==null&&M!==null&&(A<=M+pn&&i[p.polygon].add(p.edge),M<=A+pn&&i[h.polygon].add(h.edge))}_r(r[b],r[x])&&(a[b].add(x),a[x].add(b))}let u=Array(e.length).fill(void 0),m=new Set;for(let d=0;d<e.length;d++){if(m.has(d)||!r[d]?.optimizable)continue;let f=[],g=[d];for(m.add(d);g.length>0;){let h=g.pop();f.push(h);for(let b of a[h])m.has(b)||(m.add(b),g.push(b))}if(f.length<2)continue;let p=Dr(f,r);if(p)for(let h of f)u[h]={xAxis:p.xAxis,boundsOrigin:p.boundsOrigin,seamEdges:i[h],textureEdgeRepairEdges:l[h]}}for(let d=0;d<e.length;d++)!u[d]&&(i[d].size>0||l[d].size>0)&&(u[d]={seamEdges:i[d],textureEdgeRepairEdges:l[d]});return u}function Or(e){if(typeof e.toBlob=="function")return new Promise(n=>{e.toBlob(t=>{n(t?URL.createObjectURL(t):null)},"image/png")});try{return Promise.resolve(e.toDataURL("image/png"))}catch{return Promise.resolve(null)}}function En(e,n,t,o){if(o.optimize&&o.fixedXAxis)return Ye(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,s=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,i=s??(o.optimize?e.map((l,a)=>a):[0]);for(let l of i){let a=(l+1)%e.length,u=s?Dn(e[l],e[a]):[e[a][0]-e[l][0],e[a][1]-e[l][1],e[a][2]-e[l][2]],m=Ye(e,n,t,u,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});m&&(!r||m.pixelArea<r.pixelArea||m.pixelArea===r.pixelArea&&m.rawArea<r.rawArea-oe)&&(r=m)}return r}function Ir(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=oe)return;r.push(s)};for(let[r,s]of e.local2D)o(n,r+e.shiftX),o(t,s+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>oe||Math.abs(t[0])>oe||n[1]-n[0]<=oe||t[1]-t[0]<=oe))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,l=s+e.shiftY,a=Math.abs(i-n[0])<=oe||Math.abs(i-n[1])<=oe,u=Math.abs(l-t[0])<=oe||Math.abs(l-t[1])<=oe;if(!a||!u)return!1}return!0}function In(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,l]=n,a=t[0],u=t[1],m=o[0],d=o[1],f=r[0],g=r[1],p=s[0],h=1-s[1],b=i[0],x=1-i[1],A=l[0],M=1-l[1],P=b-p,E=x-h,k=A-p,C=M-h,v=P*C-k*E;if(Math.abs(v)<=1e-9)return null;let B=m-a,N=f-a,Y=d-u,ne=g-u,S={a:(B*C-N*E)/v,b:(P*N-k*B)/v,c:(Y*C-ne*E)/v,d:(P*ne-k*Y)/v,e:0,f:0};return S.e=a-S.a*p-S.b*h,S.f=u-S.c*p-S.d*h,S}function Hn(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let s of e){let i=s[0],l=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(l))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,l),r=Math.max(r,l)}return{minU:n,minV:t,maxU:o,maxV:r}}function Hr(e,n,t,o,r,s,i,l){let u=Ue(e.vertices,n,t).map(f=>{let g=f[0]-o[0],p=f[1]-o[1],h=f[2]-o[2];return[g*r[0]+p*r[1]+h*r[2]+i,g*s[0]+p*s[1]+h*s[2]+l]}),m=In(u,e.uvs),d=Hn(e.uvs);return!m&&!d?null:{screenPts:u.flatMap(([f,g])=>[f,g]),uvAffine:m,uvSampleRect:d}}function Xe(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],o+=e[i+1];t/=r,o/=r;let s=e.slice();for(let i=0;i<s.length;i+=2){let l=s[i]-t,a=s[i+1]-o,u=Math.hypot(l,a);u<=oe||(s[i]+=l/u*n,s[i+1]+=a/u*n)}return s}function Vt(e,n,t,o){for(let r=0;r<o.length;r+=2){let s=n+o[r],i=t+o[r+1];r===0?e.moveTo(s,i):e.lineTo(s,i)}e.closePath()}function qt(e,n,t,o,r){let{vertices:s,texture:i,uvs:l}=e;if(!s||s.length<3)return null;let a=t.tileSize??Ft,u=t.layerElevation??a,m=Ue(s,a,u),d=m[0],f=m[1],g=[f[0]-d[0],f[1]-d[1],f[2]-d[2]];if(Math.hypot(g[0],g[1],g[2])===0)return null;let h=ut(m);if(!h)return null;let b=En(m,d,h,{optimize:!1}),x=i||b&&Ir(b)?b:En(m,d,h,{optimize:!0,fixedXAxis:r?.xAxis,boundsOrigin:r?.boundsOrigin,snapBounds:!!r,seamEdges:r?.seamEdges});if(!x)return null;let{xAxis:A,yAxis:M,local2D:P}=x,E=i&&r?.textureEdgeRepairEdges?.size?r.textureEdgeRepairEdges:null,k=!!(i&&E),C=x.shiftX,v=x.shiftY,B=x.canvasW,N=x.canvasH,Y=[];for(let[I,D]of P)Y.push(I+C,D+v);let ne=d[0]-C*A[0]-v*M[0],S=d[1]-C*A[1]-v*M[1],$=d[2]-C*A[2]-v*M[2],w=Ce([A[0],A[1],A[2],0,M[0],M[1],M[2],0,h[0],h[1],h[2],0,ne,S,$,1]),O=Ce([A[0]*B,A[1]*B,A[2]*B,0,M[0]*N,M[1]*N,M[2]*N,0,h[0],h[1],h[2],0,ne,S,$,1]),H=Ce([A[0]*B/Ee,A[1]*B/Ee,A[2]*B/Ee,0,M[0]*N/Ee,M[1]*N/Ee,M[2]*N/Ee,0,h[0],h[1],h[2],0,ne,S,$,1]),V=!i&&s.length===4?lr(Y,A,M,h,ne,S,$,o):null,j=t.directionalLight,le=t.ambientLight,_=j?.direction??Bt,X=j?.color??Nt,U=Math.max(0,j?.intensity??$t),re=le?.color??Xt,se=Math.max(0,le?.intensity??Yt),ue=Math.hypot(_[0],_[1],_[2])||1,he=_[0]/ue,de=_[1]/ue,me=_[2]/ue,ge=U*Math.max(0,h[0]*he+h[1]*de+h[2]*me),be=kn(ge,X,re,se),c=Rn(e.color??"#cccccc",ge,X,re,se),y=null,R=null;i&&l&&l.length>=3&&l.length===s.length&&(R=Hn(l),y=In(P.map(([I,D])=>[I+C,D+v]),l));let T=i&&e.textureTriangles?.length?e.textureTriangles.map(I=>Hr(I,a,u,d,A,M,C,v)).filter(I=>!!I):null;return{index:n,polygon:e,texture:i,tileSize:a,layerElevation:u,matrix:w,canonicalMatrix:O,atlasMatrix:H,projectiveMatrix:V,canvasW:B,canvasH:N,screenPts:Y,uvAffine:y,uvSampleRect:R,textureTriangles:T,textureEdgeRepairEdges:E,textureEdgeRepair:k,normal:h,textureTint:be,shadedColor:c}}function dt(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??Ft,r=t.layerElevation??o,s=Ue(e.vertices,o,r),i=ut(s);if(!i)return null;let l=[{a:0,b:1,c:2},{a:1,b:2,c:0},{a:2,b:0,c:1}].map(Z=>{let F=s[Z.a],K=s[Z.b];return{...Z,length:Math.hypot(K[0]-F[0],K[1]-F[1],K[2]-F[2])}}).sort((Z,F)=>F.length-Z.length),a=l[0].a,u=l[0].b,m=l[0].c,d=s[a],f=s[u],g=s[m],p=l[0].length;if(p<=ce)return null;let h=[(f[0]-d[0])/p,(f[1]-d[1])/p,(f[2]-d[2])/p],b=[g[0]-d[0],g[1]-d[1],g[2]-d[2]],x=Fe(b,h),A=[d[0]+h[0]*x,d[1]+h[1]*x,d[2]+h[2]*x],M=[A[0]-g[0],A[1]-g[1],A[2]-g[2]],P=Math.hypot(M[0],M[1],M[2]);if(P<=ce)return null;let E=[M[0]/P,M[1]/P,M[2]/P];if(Fe(Tr(h,E),i)<0){let Z=u;if(u=a,a=Z,d=s[a],f=s[u],p=Math.hypot(f[0]-d[0],f[1]-d[1],f[2]-d[2]),p<=ce)return null;h=[(f[0]-d[0])/p,(f[1]-d[1])/p,(f[2]-d[2])/p];let F=[g[0]-d[0],g[1]-d[1],g[2]-d[2]];x=Fe(F,h),A=[d[0]+h[0]*x,d[1]+h[1]*x,d[2]+h[2]*x],M=[A[0]-g[0],A[1]-g[1],A[2]-g[2]];let K=Math.hypot(M[0],M[1],M[2]);if(K<=ce)return null;E=[M[0]/K,M[1]/K,M[2]/K]}let k=Math.max(0,Math.min(p,x)),C=Math.max(0,p-k),v=Gt([k,0,0,P,k+C,P],Qo),B=[v[0],v[1]],N=[v[2],v[3]],Y=[v[4],v[5]],ne=(N[1]+Y[1])/2,S=B[0]-N[0],$=Y[0]-B[0],w=ne-B[1];if(S<=ce||$<=ce||w<=ce||!Number.isFinite(S+$+w))return null;let O=t.directionalLight,H=t.ambientLight,V=O?.direction??Bt,j=O?.color??Nt,le=Math.max(0,O?.intensity??$t),_=H?.color??Xt,X=Math.max(0,H?.intensity??Yt),U=Math.hypot(V[0],V[1],V[2])||1,re=V[0]/U,se=V[1]/U,ue=V[2]/U,he=le*Math.max(0,i[0]*re+i[1]*se+i[2]*ue),de=Rn(e.color??"#cccccc",he,j,_,X),me=t.textureLighting??"baked",ge=Se(e.color??"#cccccc"),be=de===t.solidPaintDefaults?.paintColor,c=me==="dynamic"&&jt(ge)===t.solidPaintDefaults?.dynamicColorKey,y=me==="dynamic"||be?"":`color:${de};`,R=me==="dynamic"?`--pnx:${i[0].toFixed(4)};--pny:${i[1].toFixed(4)};--pnz:${i[2].toFixed(4)};`+(c?"":`--psr:${(ge.r/255).toFixed(4)};--psg:${(ge.g/255).toFixed(4)};--psb:${(ge.b/255).toFixed(4)};`):"",T=([Z,F])=>[g[0]+(Z-k)*h[0]+F*E[0],g[1]+(Z-k)*h[1]+F*E[1],g[2]+(Z-k)*h[2]+F*E[2]],I=T(B),D=T([N[0],ne]),z=T([Y[0],ne]),G=Le/2,te=[(z[0]-D[0])/Le,(z[1]-D[1])/Le,(z[2]-D[2])/Le],q=[I[0]-te[0]*G,I[1]-te[1]*G,I[2]-te[2]*G],Q=[(D[0]-q[0])/Le,(D[1]-q[1])/Le,(D[2]-q[2])/Le],L=`transform:matrix3d(${Ce([te[0],te[1],te[2],0,Q[0],Q[1],Q[2],0,i[0],i[1],i[2],0,q[0],q[1],q[2],1])});`+y+R;return{index:n,polygon:e,styleText:L}}function at(e,n=1){let t=Array(e.length).fill(null),o=[],r=vr(n),s=e.filter(a=>!!a).sort((a,u)=>u.canvasH-a.canvasH||u.canvasW-a.canvasW||a.index-u.index),i=()=>({width:r,height:r,entries:[],shelves:[]}),l=(a,u,m)=>{if(a.sealed)return null;for(let g of a.shelves)if(u.canvasH<=g.height&&g.x+u.canvasW+r<=Ve){let p={...u,pageIndex:m,x:g.x,y:g.y};return g.x+=u.canvasW+r*2,a.entries.push(p),a.width=Math.max(a.width,p.x+u.canvasW+r),p}let d=a.shelves.length===0?r:a.height+r;if(d+u.canvasH+r>Ve)return null;let f={...u,pageIndex:m,x:r,y:d};return a.shelves.push({x:r+u.canvasW+r*2,y:d,height:u.canvasH}),a.entries.push(f),a.width=Math.max(a.width,f.x+u.canvasW+r),a.height=Math.max(a.height,d+u.canvasH+r),f};for(let a of s){if(a.canvasW+r*2>Ve||a.canvasH+r*2>Ve){let d=o.length,f={...a,pageIndex:d,x:r,y:r};t[a.index]=f,o.push({width:a.canvasW+r*2,height:a.canvasH+r*2,entries:[f],shelves:[],sealed:!0});continue}let m=null;for(let d=0;d<o.length&&(m=l(o[d],a,d),!m);d++);if(!m){let d=i(),f=o.length;o.push(d),m=l(d,a,f)}m&&(t[a.index]=m)}return{entries:t,pages:o.map(({width:a,height:u,entries:m})=>({width:a,height:u,entries:m}))}}function Vr(e,n,t,o){Pe(e,o),e.beginPath(),Vt(e,n.x,n.y,n.screenPts),e.clip(),Pe(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function He(e,n){return Math.max(0,Math.min(n,e))}function An(e,n,t,o,r,s,i,l){let a=n.naturalWidth||n.width||1,u=n.naturalHeight||n.height||1,m=He(Math.min(t.minU,t.maxU)*a,a),d=He(Math.max(t.minU,t.maxU)*a,a),f=He(Math.min(t.minV,t.maxV)*u,u),g=He(Math.max(t.minV,t.maxV)*u,u),p=Math.floor(m),h=Math.floor(f),b=Math.ceil(d)-p,x=Math.ceil(g)-h;b<1&&(p=Math.floor(He((t.minU+t.maxU)/2*a,a-1)),b=1),x<1&&(h=Math.floor(He((t.minV+t.maxV)/2*u,u-1)),x=1),p=Math.max(0,Math.min(a-1,p)),h=Math.max(0,Math.min(u-1,h)),b=Math.max(1,Math.min(a-p,b)),x=Math.max(1,Math.min(u-h,x)),Pe(e,l),e.drawImage(n,p,h,b,x,o,r,s,i)}function zr(e,n,t,o,r,s){for(let i=0;i<o.length;i+=2){let l=n+o[i]+r,a=t+o[i+1]+s;i===0?e.moveTo(l,a):e.lineTo(l,a)}e.closePath()}function Fr(e,n,t,o,r=0,s=0){if(n.textureTriangles?.length){let i=t.naturalWidth||t.width||1,l=t.naturalHeight||t.height||1;for(let a of n.textureTriangles){let u=Xe(a.screenPts,jo);e.save(),Pe(e,o),e.beginPath(),zr(e,n.x,n.y,u,r,s),e.clip(),a.uvAffine?(Pe(e,o,a.uvAffine.a/i,a.uvAffine.c/i,a.uvAffine.b/l,a.uvAffine.d/l,n.x+a.uvAffine.e+r,n.y+a.uvAffine.f+s),e.drawImage(t,0,0)):a.uvSampleRect&&An(e,t,a.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let i=t.naturalWidth||t.width||1,l=t.naturalHeight||t.height||1;Pe(e,o,n.uvAffine.a/i,n.uvAffine.c/i,n.uvAffine.b/l,n.uvAffine.d/l,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+s),e.drawImage(t,0,0)}else n.uvSampleRect?An(e,t,n.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o):Cr(e,t,n.x+r,n.y+s,n.canvasW,n.canvasH,o)}function Br(e,n,t,o,r,s){let i=r-t,l=s-o,a=i*i+l*l;if(a<=ce)return Math.hypot(e-t,n-o);let u=Math.max(0,Math.min(1,((e-t)*i+(n-o)*l)/a));return Math.hypot(e-(t+i*u),n-(o+l*u))}function Nr(e,n,t,o){let r=1/0,s=t.length/2;for(let i of o){if(i<0||i>=s)continue;let l=i*2,a=(i+1)%s*2;r=Math.min(r,Br(e,n,t[l],t[l+1],t[a],t[a+1]))}return r}function $r(e,n,t,o,r,s){let i=Math.max(0,o-s),l=Math.min(n-1,o+s),a=Math.max(0,r-s),u=Math.min(t-1,r+s),m=null,d=1/0;for(let f=a;f<=u;f++)for(let g=i;g<=l;g++){if(g===o&&f===r)continue;let p=g-o,h=f-r,b=p*p+h*h;if(b>s*s||b>=d)continue;let x=(f*n+g)*4;e[x+3]<qo||(m=x,d=b)}return m}function Xr(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),s=Math.max(0,Math.floor(n.y*t)),i=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),l=Math.max(1,Math.min(o.height-s,Math.ceil(n.canvasH*t)));if(i<=0||l<=0)return;let a;try{a=e.getImageData(r,s,i,l)}catch{return}let u=a.data,m=new Uint8ClampedArray(u),d=Math.max(fn,fn/t),f=Math.max(2,Math.ceil(d*t)+1),g=!1;for(let p=0;p<l;p++)for(let h=0;h<i;h++){let b=(p*i+h)*4,x=u[b+3];if(x<Zo||x===255)continue;let A=(r+h+.5)/t-n.x,M=(s+p+.5)/t-n.y;if(Nr(A,M,n.screenPts,n.textureEdgeRepairEdges)>d)continue;let P=$r(m,i,l,h,p,f);P!==null&&(u[b]=m[P],u[b+1]=m[P+1],u[b+2]=m[P+2],u[b+3]=255,g=!0)}g&&e.putImageData(a,r,s)}async function Yr(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=e.entries.some(m=>m.textureEdgeRepair&&m.texture&&m.textureEdgeRepairEdges&&m.textureEdgeRepairEdges.size>0),i=r.getContext("2d",s?{willReadFrequently:!0}:void 0);if(!i)return{width:e.width,height:e.height,url:null};let l=Array.from(new Set(e.entries.flatMap(m=>m.texture?[m.texture]:[]))),a=new Map;await Promise.all(l.map(async m=>{a.set(m,await sr(m))}));for(let m of e.entries){let d=m.texture?a.get(m.texture):null;if(!m.texture){i.save(),Vr(i,m,n,o),i.restore();continue}d&&(i.save(),Pe(i,o),i.beginPath(),Vt(i,m.x,m.y,m.screenPts),i.clip(),Fr(i,m,d,o),i.restore()),m.texture&&n==="baked"&&(i.save(),Pe(i,o),i.beginPath(),Vt(i,m.x,m.y,m.screenPts),i.clip(),Mr(i,m.x,m.y,m.canvasW,m.canvasH,m.textureTint,o),i.restore()),Xr(i,m,o)}let u=await Or(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:u}}async function Vn(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await Yr(i,n,t,o))}return s}function zn(e,n,t,o){if(!n.url)return;let r=`url(${n.url})`,s=o.canvasW||1,i=o.canvasH||1,l=Me(o),a=`${ze(-o.x/s*l)} ${ze(-o.y/i*l)}`,u=`${ze(n.width/s*l)} ${ze(n.height/i*l)}`;t==="dynamic"?(J(e,"background-image",r),J(e,"background-position",a),J(e,"background-size",u)):J(e,"background",`${r} ${a} / ${u} no-repeat`),t==="dynamic"?(J(e,"mask-image",r),J(e,"mask-mode","alpha"),J(e,"mask-position",a),J(e,"mask-size",u),J(e,"mask-repeat","no-repeat"),J(e,"-webkit-mask-image",r),J(e,"-webkit-mask-position",a),J(e,"-webkit-mask-size",u),J(e,"-webkit-mask-repeat","no-repeat")):(pe(e,"mask-image"),pe(e,"mask-mode"),pe(e,"mask-position"),pe(e,"mask-size"),pe(e,"mask-repeat"),pe(e,"-webkit-mask-image"),pe(e,"-webkit-mask-position"),pe(e,"-webkit-mask-size"),pe(e,"-webkit-mask-repeat"))}function Re(e,n){let t=It.get(e);if(t)for(let r of t)e.removeAttribute(`data-${r}`);let o=[];if(n.data)for(let[r,s]of Object.entries(n.data))e.setAttribute(`data-${r}`,String(s)),o.push(r);It.set(e,o)}function Fn(e,n,t,o=0,r=0){let s=e.matrix.split(",").map(f=>Number(f));if(s.length!==16||s.some(f=>!Number.isFinite(f)))return e.matrix;let i=s[0],l=s[1],a=s[2],u=s[4],m=s[5],d=s[6];return s[0]*=n,s[1]*=n,s[2]*=n,s[4]*=t,s[5]*=t,s[6]*=t,s[12]+=o*i+r*u,s[13]+=o*l+r*m,s[14]+=o*a+r*d,Ce(s)}function Ur(e,n){return Fn(e,n.width/yn,n.height/yn,n.minX,n.minY)}function Gr(e){return Fn(e,(e.canvasW||1)/Ht,(e.canvasH||1)/Ht)}function Wr(e){let n=Xn(e);return[`transform:matrix3d(${Ur(e,n.bounds)})`,`border-shape:${Yn(n.points)}`].join(";")}function jr(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,o=e.layerElevation,r=Ue(n.vertices,t,o),s=ut(r);if(!s)return null;let i=e.screenPts[0],l=e.screenPts[1],a=e.screenPts[2],u=e.screenPts[3],m=e.screenPts[4],d=e.screenPts[5],f=a-i,g=u-l,p=m-i,h=d-l,b=f*h-g*p;if(Math.abs(b)<=ce)return null;let x=r[0],A=r[1],M=r[2],P=[A[0]-x[0],A[1]-x[1],A[2]-x[2]],E=[M[0]-x[0],M[1]-x[1],M[2]-x[2]],k=[(P[0]*h-g*E[0])/b,(P[1]*h-g*E[1])/b,(P[2]*h-g*E[2])/b],C=[(f*E[0]-P[0]*p)/b,(f*E[1]-P[1]*p)/b,(f*E[2]-P[2]*p)/b],v=x[0]-k[0]*i-C[0]*l,B=x[1]-k[1]*i-C[1]*l,N=x[2]-k[2]*i-C[2]*l;return{normal:s,matrix:Ce([k[0]*e.canvasW/Me(e),k[1]*e.canvasW/Me(e),k[2]*e.canvasW/Me(e),0,C[0]*e.canvasH/Me(e),C[1]*e.canvasH/Me(e),C[2]*e.canvasH/Me(e),0,s[0],s[1],s[2],0,v,B,N,1])}}function Zr(e,n,t,o){if(!n.texture||!t.texture||n.texture!==t.texture)return!1;let r=jr(n,t);return r?(J(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(J(e,"--pnx",r.normal[0].toFixed(4)),J(e,"--pny",r.normal[1].toFixed(4)),J(e,"--pnz",r.normal[2].toFixed(4))),Re(e,t),!0):!1}function Bn(e,n){J(e,"--pnx",n.normal[0].toFixed(4)),J(e,"--pny",n.normal[1].toFixed(4)),J(e,"--pnz",n.normal[2].toFixed(4))}function qr(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=oe)return;r.push(s)};for(let r=0;r<e.screenPts.length;r+=2)o(n,e.screenPts[r]),o(t,e.screenPts[r+1]);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>oe||Math.abs(t[0])>oe||n[1]-n[0]<=oe||t[1]-t[0]<=oe))return null;for(let r=0;r<e.screenPts.length;r+=2){let s=e.screenPts[r],i=e.screenPts[r+1],l=Math.abs(s-n[0])<=oe||Math.abs(s-n[1])<=oe,a=Math.abs(i-t[0])<=oe||Math.abs(i-t[1])<=oe;if(!l||!a)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function _e(e){return!!qr(e)}function lt(e){return!e.texture&&e.polygon.vertices.length===3}function Be(e){return!e.texture&&!!e.projectiveMatrix&&!_e(e)}function Qt(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function mt(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";if(!t)return!0;let o=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(t);return!/\bVersion\/[\d.]+.*\bSafari\//.test(t)||o}function Mn(e,n){e.set(n,(e.get(n)??0)+1)}function Cn(e){let n,t=1;for(let[o,r]of e)r>t&&(n=o,t=r);return n}function Nn(e,n,t,o){let r=new Map,s=new Map,i=new Map,l=!o.has("b"),a=l,u=!o.has("u")&&mt(t),m=!o.has("i")&&Qt(t);for(let g of e)if(!(!g||g.texture)){if(n==="dynamic"){if(!(u&&lt(g))&&!(l&&_e(g))&&!(a&&Be(g))&&!m)continue;let p=Se(g.polygon.color??"#cccccc"),h=jt(p);Mn(s,h),i.has(h)||i.set(h,p);continue}!(u&&lt(g))&&!(l&&_e(g))&&!(a&&Be(g))&&!m||Mn(r,g.shadedColor)}let d=Cn(r),f=Cn(s);return{paintColor:d,dynamicColorKey:f,dynamicColor:f?i.get(f):void 0}}function $n(){return new Promise(e=>setTimeout(e,0))}async function Dt(e){return performance.now()-e<Uo?e:(await $n(),performance.now())}function pt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=new Set(n.strategies?.disable??[]),r=Zt(e,n),s=Wt(t),i=e.map((l,a)=>qt(l,a,n,s,r[a]));return Nn(i,n.textureLighting??"baked",t,o)}function Qr(e,n,t){let o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(let u=0;u<e.length;u+=2){let m=e[u],d=e[u+1];!Number.isFinite(m)||!Number.isFinite(d)||(o=Math.min(o,m),r=Math.min(r,d),s=Math.max(s,m),i=Math.max(i,d))}let l=s-o,a=i-r;return!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(l)||!Number.isFinite(a)||l<=ce||a<=ce?{minX:0,minY:0,width:n,height:t}:{minX:o,minY:r,width:l,height:a}}function Xn(e){let n=e.canvasW||1,t=e.canvasH||1,o=kt>0?Gt(e.screenPts,kt):e.screenPts,r=kt>0?Qr(o,n,t):{minX:0,minY:0,width:n,height:t},s=[];for(let i=0;i<o.length;i+=2){let l=Math.max(0,Math.min(100,(o[i]-r.minX)/r.width*100)),a=Math.max(0,Math.min(100,(o[i+1]-r.minY)/r.height*100));s.push([l,a])}return{bounds:r,points:s}}function Kr([e,n]){return`${st(e)} ${st(n)}`}function Jr(e){return`polygon(${e.map(Kr).join(",")})`}function es(e){if(ur(e))return"circle(0)";let n=0,t=0,o=Math.max(1,e.length);for(let[i,l]of e)n+=i,t+=l;let r=st(Math.max(0,Math.min(100,n/o))),s=st(Math.max(0,Math.min(100,t/o)));return`circle(0 at ${r} ${s})`}function Yn(e){return`${Jr(e)} ${es(e)}`}function Un(e){return Yn(Xn(e).points)}function Kt(e,n,t,o){if(t==="dynamic"){pe(e,"color"),pe(e,"background"),Bn(e,n);let r=Se(n.polygon.color??"#cccccc");jt(r)===o?.dynamicColorKey?(pe(e,"--psr"),pe(e,"--psg"),pe(e,"--psb")):(J(e,"--psr",(r.r/255).toFixed(4)),J(e,"--psg",(r.g/255).toFixed(4)),J(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(pe(e,"background"),J(e,"color",n.shadedColor)):(pe(e,"background"),pe(e,"color"))}function Gn(e,n,t,o){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${Gr(e)})`),Re(r,e.polygon),Kt(r,e,n,o),r}function Wn(e,n,t,o){let r=t.createElement("i");return r.setAttribute("style",Wr(e)),Re(r,e.polygon),Kt(r,e,n,o),r}function jn(e,n,t,o){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`),Re(r,e.polygon),Kt(r,e,n,o),r}function Zn(e,n,t){let o=t.createElement("s");o.setAttribute("style",`transform:matrix3d(${e.atlasMatrix})`),Re(o,e.polygon);let r=e.canvasW||1,s=e.canvasH||1,i=Me(e);return J(o,"--polycss-atlas-size",`${i}px`),J(o,"background-position",`${ze(-e.x/r*i)} ${ze(-e.y/s*i)}`),J(o,"opacity","0"),n==="dynamic"&&Bn(o,e),o}function qn(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=new Set(n.strategies?.disable??[]),s=!r.has("b"),i=s,l=!r.has("u")&&mt(t),a=!r.has("i")&&Qt(t),u=Zt(e,n),m=Wt(t),d=e.map((P,E)=>qt(P,E,n,m,u[E])),f=d.map(P=>P&&l&&lt(P)?dt(P.polygon,P.index,n):null),g=d.map((P,E)=>P&&(P.texture||!(s&&_e(P))&&!f[E]&&!(i&&Be(P))&&!a?P:null)),{packed:p,atlasScale:h}=_n(g,n.textureQuality,t),b=new Map,x=[],A=!1,M=[];for(let P=0;P<e.length;P++){let E=d[P],k=f[P];if(!E)continue;let C=p.entries[P];if(C){let v=Zn(C,o,t);b.set(P,v),x.push({polygonIndex:P,element:v,kind:"atlas",plan:C,dispose:()=>{}})}else if(!E.texture&&s&&_e(E)){let v=Gn(E,o,t,n.solidPaintDefaults);x.push({polygonIndex:P,element:v,kind:"solid",plan:E,dispose:()=>{}})}else if(!E.texture&&k){let v=Jt(k,t);x.push({polygonIndex:P,element:v,kind:"triangle",plan:E,dispose:()=>{}})}else if(!E.texture&&i&&Be(E)){let v=jn(E,o,t,n.solidPaintDefaults);x.push({polygonIndex:P,element:v,kind:"solid",plan:E,dispose:()=>{}})}else if(!E.texture&&a){let v=Wn(E,o,t,n.solidPaintDefaults);x.push({polygonIndex:P,element:v,kind:"border",plan:E,dispose:()=>{}})}}return x.sort((P,E)=>P.polygonIndex-E.polygonIndex),Vn(p.pages,o,t,h,()=>A).then(P=>{if(A){for(let E of P)E.url?.startsWith("blob:")&&URL.revokeObjectURL(E.url);return}M=P.flatMap(E=>E.url?.startsWith("blob:")?[E.url]:[]);for(let E=0;E<p.pages.length;E++){let k=p.pages[E],C=P[E];if(C)for(let v of k.entries){let B=b.get(v.index);!B||!C.url||(zn(B,C,o,v),pe(B,"opacity"))}}}).catch(()=>{if(!A)for(let P of b.values())J(P,"opacity","0.5"),J(P,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:x,dispose(){A=!0;for(let P of M)URL.revokeObjectURL(P);M=[]}}}async function Qn(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let r=n.textureLighting??"baked",s=new Set(n.strategies?.disable??[]),i=!s.has("b"),l=i,a=!s.has("u")&&mt(o),u=!s.has("i")&&Qt(o);if(await $n(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let m=Zt(e,n),d=Wt(o),f=performance.now(),g=new Array(e.length);for(let C=0;C<e.length;C++)if(g[C]=qt(e[C],C,n,d,m[C]),f=await Dt(f),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let p=n.solidPaintDefaults??Nn(g,r,o,s),h=new Array(g.length),b=new Array(g.length);for(let C=0;C<g.length;C++){let v=g[C],B=v&&a&&lt(v)?dt(v.polygon,v.index,{...n,solidPaintDefaults:p}):null;if(h[C]=B,b[C]=v&&(v.texture||!(i&&_e(v))&&!B&&!(l&&Be(v))&&!u?v:null),f=await Dt(f),t())return{rendered:[],solidPaintDefaults:p,dispose:()=>{}}}let{packed:x,atlasScale:A}=_n(b,n.textureQuality,o),M=new Map,P=[],E=!1,k=[];for(let C=0;C<e.length;C++){let v=g[C],B=h[C];if(!v)continue;let N=x.entries[C];if(N){let Y=Zn(N,r,o);M.set(C,Y),P.push({polygonIndex:C,element:Y,kind:"atlas",plan:N,dispose:()=>{}})}else if(!v.texture&&i&&_e(v)){let Y=Gn(v,r,o,p);P.push({polygonIndex:C,element:Y,kind:"solid",plan:v,dispose:()=>{}})}else if(!v.texture&&B){let Y=Jt(B,o);P.push({polygonIndex:C,element:Y,kind:"triangle",plan:v,dispose:()=>{}})}else if(!v.texture&&l&&Be(v)){let Y=jn(v,r,o,p);P.push({polygonIndex:C,element:Y,kind:"solid",plan:v,dispose:()=>{}})}else if(!v.texture&&u){let Y=Wn(v,r,o,p);P.push({polygonIndex:C,element:Y,kind:"border",plan:v,dispose:()=>{}})}if(f=await Dt(f),t()){for(let Y of P)Y.dispose();return{rendered:[],solidPaintDefaults:p,dispose:()=>{}}}}return P.sort((C,v)=>C.polygonIndex-v.polygonIndex),Vn(x.pages,r,o,A,()=>E||t()).then(C=>{if(E||t()){for(let v of C)v.url?.startsWith("blob:")&&URL.revokeObjectURL(v.url);return}k=C.flatMap(v=>v.url?.startsWith("blob:")?[v.url]:[]);for(let v=0;v<x.pages.length;v++){let B=x.pages[v],N=C[v];if(N)for(let Y of B.entries){let ne=M.get(Y.index);!ne||!N.url||(zn(ne,N,r,Y),pe(ne,"opacity"))}}}).catch(()=>{if(!(E||t()))for(let C of M.values())J(C,"opacity","0.5"),J(C,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:P,solidPaintDefaults:p,dispose(){E=!0;for(let C of k)URL.revokeObjectURL(C);k=[]}}}function ts(e,n){let t=e.map((o,r)=>dt(o,r,n));return t.some(o=>!o)?null:t}function ns(e){e.style.backgroundImage="",e.style.backgroundPosition="",e.style.backgroundSize="",e.style.maskImage="",e.style.maskMode="",e.style.maskPosition="",e.style.maskSize="",e.style.maskRepeat="",e.style.removeProperty("-webkit-mask-image"),e.style.removeProperty("-webkit-mask-position"),e.style.removeProperty("-webkit-mask-size"),e.style.removeProperty("-webkit-mask-repeat")}function Kn(e,n){e.setAttribute("style",n.styleText),(n.polygon.data||It.get(e)?.length)&&Re(e,n.polygon)}function Jt(e,n){let t=n.createElement("u");return ns(t),Kn(t,e),Re(t,e.polygon),t}function en(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};if(!mt(t))return null;let o=ts(e,n);if(!o)return null;let r=[];for(let s of o){let i=Jt(s,t);r.push({polygonIndex:s.index,element:i,kind:"triangle",dispose:()=>{}})}return r.sort((s,i)=>s.polygonIndex-i.polygonIndex),{rendered:r,dispose(){}}}function Jn(e,n,t={}){if(e.length!==n.length)return!1;let o=t.textureLighting??"baked",r=[];for(let s=0;s<e.length;s++){let i=e[s];if(i.polygonIndex!==s)return!1;let l=n[s];if(!l)return!1;if(i.kind==="atlas"){if(!i.plan||!Zr(i.element,i.plan,l,o))return!1;continue}if(i.kind==="triangle"){let a=dt(l,s,t);if(!a)return!1;r[s]=a;continue}return!1}for(let s=0;s<e.length;s++){let i=e[s];if(i.kind==="triangle"){let l=r[s];if(!l)return!1;Kn(i.element,l)}}return!0}var ae=require("@layoutit/polycss-core"),os=[.4,-.7,.59],rs="#ffffff",ss=1,is="#ffffff",as=.4,to={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},ls=["t","b","bl","br","fr","fl"],cs=new Map([["0,0,1","t"],["0,0,-1","b"],["0,1,0","fl"],["0,-1,0","br"],["1,0,0","fr"],["-1,0,0","bl"]]);function eo(e){let n=[];for(let t of ls)(0,ae.normalFacesCamera)(to[t],e)&&n.push(t);return n.join("|")}function us(e,n,t){let o=e.__polycssVoxelBrushState??(e.__polycssVoxelBrushState={});o.color!==n&&(e.style.color=n,o.color=n),o.transform!==t&&(e.style.transform=t,o.transform=t)}function ds(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let l=1;l+1<n.length;l+=1){let a=n[l],u=n[l+1],m=a[1]-t[1],d=a[0]-t[0],f=a[2]-t[2],g=u[1]-t[1],p=u[0]-t[0],h=u[2]-t[2];o-=d*h-f*p,r-=f*g-m*h,s-=m*p-d*g}let i=Math.hypot(o,r,s);return i<=1e-9?null:[Math.round(o/i),Math.round(r/i),Math.round(s/i)]}function ms(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=ds(e),t=n?cs.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,s=1/0,i=-1/0,l=-1/0,a=-1/0;for(let d of e.vertices)o=Math.min(o,d[0]),r=Math.min(r,d[1]),s=Math.min(s,d[2]),i=Math.max(i,d[0]),l=Math.max(l,d[1]),a=Math.max(a,d[2]);let u=1e-6,m=e.color||"#cccccc";return Math.abs(a-s)<=u?{axis:"z",face:t,left:r*ae.BASE_TILE,top:o*ae.BASE_TILE,width:Math.max(0,(l-r)*ae.BASE_TILE),height:Math.max(0,(i-o)*ae.BASE_TILE),z:s*ae.BASE_TILE,baseColor:m}:Math.abs(i-o)<=u?{axis:"x",face:t,left:r*ae.BASE_TILE,top:s*ae.BASE_TILE,width:Math.max(0,(l-r)*ae.BASE_TILE),height:Math.max(0,(a-s)*ae.BASE_TILE),z:-o*ae.BASE_TILE,baseColor:m}:Math.abs(l-r)<=u?{axis:"y",face:t,left:s*ae.BASE_TILE,top:o*ae.BASE_TILE,width:Math.max(0,(a-s)*ae.BASE_TILE),height:Math.max(0,(i-o)*ae.BASE_TILE),z:-r*ae.BASE_TILE,baseColor:m}:null}function tn(e){let n=(0,ae.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha}:{r:255,g:255,b:255,alpha:1}}function ps({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function nn(e){return Math.round(Math.max(0,Math.min(255,e)))}function fs(e,n,t,o){let r=tn(n),s=tn(t?.color??rs),i=tn(o?.color??is),l=t?.direction??os,a=Math.hypot(l[0],l[1],l[2])||1,u=l[0]/a,m=l[1]/a,d=l[2]/a,f=Math.max(0,t?.intensity??ss)*Math.max(0,e[0]*u+e[1]*m+e[2]*d),g=Math.max(0,o?.intensity??as),p=i.r/255*g+s.r/255*f,h=i.g/255*g+s.g/255*f,b=i.b/255*g+s.b/255*f,x={r:r.r*p,g:r.g*h,b:r.b*b,alpha:r.alpha};return x.alpha<1?`rgba(${nn(x.r)}, ${nn(x.g)}, ${nn(x.b)}, ${x.alpha})`:ps(x)}function hs(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=ms(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return n}function gs(e,n,t,o,r,s){return`matrix3d(${(e==="x"?[o,0,0,0,0,0,r,0,0,-1,0,0,n,-s,t,1]:e==="y"?[0,0,o,0,0,r,0,0,-1,0,0,0,-s,t,n,1]:[o,0,0,0,0,r,0,0,0,0,1,0,n,t,s,1]).map(l=>Number(l.toFixed(6))).join(",")})`}function ys(e){return e.axis==="x"?[e.left+e.width/2,-e.z,e.top+e.height/2]:e.axis==="y"?[-e.z,e.top+e.height/2,e.left+e.width/2]:[e.left+e.width/2,e.top+e.height/2,e.z]}function bs(e,n){let t=ys(e),o=n.meshRotation;o&&(t=(0,ae.rotateVec3)(t,o[0]??0,o[1]??0,o[2]??0));let[r,s]=(0,ae.rotateVec3)(t,n.rotX,0,n.rotY);return{x:r,y:s}}function xs(e,n,t){let o=e.filter(f=>n.has(f.face)).map(f=>({item:f,...bs(f,t)}));if(o.length===0)return[];let r=1/0,s=-1/0,i=1/0,l=-1/0;for(let f of o)r=Math.min(r,f.x),s=Math.max(s,f.x),i=Math.min(i,f.y),l=Math.max(l,f.y);let a=4,u=Math.max(1e-6,s-r),m=Math.max(1e-6,l-i),d=new Map;for(let f of o){let g=Math.min(a-1,Math.max(0,Math.floor((f.x-r)/u*a))),p=Math.min(a-1,Math.max(0,Math.floor((f.y-i)/m*a))),h=`${g}:${p}`,b=d.get(h);b||(b={tx:g,ty:p,sourceIndex:f.item.sourceIndex,items:[]},d.set(h,b)),b.items.push(f.item),b.sourceIndex=Math.min(b.sourceIndex,f.item.sourceIndex)}return Array.from(d.values()).sort((f,g)=>f.ty-g.ty||f.tx-g.tx||f.sourceIndex-g.sourceIndex).flatMap(f=>f.items)}function no(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:s}=e,i=hs(o);if(i.length===0)return null;t.classList.add("polycss-voxel-mesh");let l=new Map,a=(p,h)=>{let b=`${p}|${h}`,x=l.get(b);if(x)return x;let A=fs(to[p],h,r,s);return l.set(b,A),A},u=[],m="",d=0,f=p=>{let h=u[p];return h||(h=n.createElement("b"),u[p]=h),h.parentElement!==t&&t.appendChild(h),h},g=(p,h)=>{let b=new Set(p.split("|").filter(Boolean)),x=xs(i,b,h);d=0;for(let A of x){let M=f(d);us(M,a(A.face,A.baseColor),gs(A.axis,A.left,A.top,A.width,A.height,A.z)),d+=1}for(let A=d;A<u.length;A+=1)u[A]?.remove()};return{element:t,get brushCount(){return d},render(p){m=eo(p),g(m,p)},syncCamera(p){let h=eo(p);h!==m&&(m=h,g(h,p))},dispose(){for(let p of u)p.remove();t.classList.remove("polycss-voxel-mesh"),u.length=0,d=0,m=""}}}var oo="polycss-styles";function ro(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(oo))return;let t=n.createElement("style");t.id=oo,t.textContent=vs,n.head.appendChild(t)}var vs=`
2
2
  /* \u2500\u2500 Scene container \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
3
3
 
4
4
  .polycss-scene,
@@ -15,13 +15,29 @@
15
15
  width: 0;
16
16
  height: 0;
17
17
  transform-style: preserve-3d;
18
- perspective: none;
19
- transform: var(--scene-transform);
18
+ perspective: 8000px;
19
+ /* Pin the scene as a composited layer. Without this, mobile Chrome
20
+ re-rasterizes every descendant tile when the scene transform changes
21
+ each animation frame, which overruns the raster budget on textured
22
+ meshes (faces drop, fragments float). With will-change, the GPU
23
+ reuses the cached layer pixels and only re-composites. */
24
+ will-change: transform;
20
25
  }
21
26
 
22
- .polycss-offset {
23
- transform-style: preserve-3d;
24
- transform: var(--offset-transform);
27
+ /* \u2500\u2500 First-person controls perspective context \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
28
+
29
+ /* PolyFirstPersonControls toggles this class on its host element (vanilla:
30
+ scene.host; react/vue: the camera wrapper). FPV needs a real perspective
31
+ context so scene Z translation produces visible depth motion - without
32
+ it, walking forward looks like a planar pan. The class wins over inline
33
+ perspective styles (e.g. PolyOrthographicCamera's perspective: none)
34
+ via !important. The actual perspective value is set inline by the
35
+ controls as the --polycss-fpv-perspective custom property; the default
36
+ of 2000px matches the controls' lookOffset fallback so the FPV math and
37
+ visual perspective stay in sync. */
38
+ .polycss-fpv-host {
39
+ perspective: var(--polycss-fpv-perspective, 2000px) !important;
40
+ transform-style: preserve-3d !important;
25
41
  }
26
42
 
27
43
  /* \u2500\u2500 Mesh wrapper \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
@@ -53,22 +69,77 @@
53
69
  background-repeat: no-repeat;
54
70
  }
55
71
 
72
+ .polycss-scene b,
73
+ .polycss-scene i,
74
+ .polycss-scene u {
75
+ color: var(--polycss-paint, currentColor);
76
+ }
77
+
56
78
  .polycss-scene b {
79
+ background: currentColor;
80
+ width: 64px;
81
+ height: 64px;
82
+ }
83
+
84
+ .polycss-mesh.polycss-voxel-mesh > b {
85
+ top: 0;
86
+ left: 0;
87
+ width: 1px;
88
+ height: 1px;
89
+ backface-visibility: visible;
90
+ pointer-events: none;
57
91
  }
58
92
 
59
93
  .polycss-scene i {
94
+ width: 16px;
95
+ height: 16px;
60
96
  border-color: currentColor;
61
97
  }
62
98
 
63
99
  .polycss-scene s {
100
+ width: var(--polycss-atlas-size, 64px);
101
+ height: var(--polycss-atlas-size, 64px);
64
102
  }
65
103
 
66
104
  .polycss-scene u {
67
- width: 0px;
68
- height: 0px;
105
+ width: 0;
106
+ height: 0;
69
107
  background: transparent;
70
108
  box-sizing: content-box;
71
109
  border: 0 solid transparent;
110
+ border-color: transparent transparent currentColor transparent;
111
+ border-width: 0 32px 64px 32px;
112
+ }
113
+
114
+ /* <q> \u2014 dedicated shadow leaf. Same border-shape rendering trick as <i>
115
+ (border-color: currentColor fills the polygon outline) but with its
116
+ own tag so we don't have to thread :not(.polycss-shadow) exclusions
117
+ through every dynamic-mode color rule. backface-visibility must be
118
+ visible because the projection matrix is near-rank-deficient and the
119
+ resulting plane's normal can read as back-facing under some camera
120
+ angles; the leaf is intentionally always painted. Strip the UA's
121
+ default ::before/::after open-/close-quote so the element is just a
122
+ styled box. */
123
+ .polycss-scene q {
124
+ position: absolute;
125
+ display: block;
126
+ transform-origin: 0 0;
127
+ transform-style: preserve-3d;
128
+ margin: 0;
129
+ padding: 0;
130
+ font: inherit;
131
+ font-weight: normal;
132
+ font-style: normal;
133
+ line-height: 0;
134
+ text-decoration: none;
135
+ backface-visibility: visible;
136
+ border-color: currentColor;
137
+ pointer-events: none;
138
+ will-change: transform;
139
+ }
140
+ .polycss-scene q::before,
141
+ .polycss-scene q::after {
142
+ content: none;
72
143
  }
73
144
 
74
145
  /* \u2500\u2500 Gizmo override (createTransformControls) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
@@ -78,15 +149,42 @@
78
149
  * pipeline as user content but the gizmo is a UI affordance \u2014 both
79
150
  * faces of every polygon should remain visible regardless of camera
80
151
  * orientation, otherwise the cuboid shafts and pyramid heads end up
81
- * half-culled. Transitions on border-color and background-color smooth
82
- * the idle / hover / drag alpha changes.
152
+ * half-culled. Transitions on color, border-color, and background-color
153
+ * smooth the idle / hover / drag alpha changes.
83
154
  */
84
155
  .polycss-mesh.polycss-transform-gizmo i,
85
156
  .polycss-mesh.polycss-transform-gizmo b,
86
157
  .polycss-mesh.polycss-transform-gizmo s,
87
158
  .polycss-mesh.polycss-transform-gizmo u {
88
159
  backface-visibility: visible;
89
- transition: border-color 150ms ease-out, background-color 150ms ease-out;
160
+ transition: color 150ms ease-out, border-color 150ms ease-out, background-color 150ms ease-out;
161
+ }
162
+
163
+ /*
164
+ * Rotate rings are rendered as a single square quad per ring, then masked
165
+ * to a donut via a radial-gradient. The --ring-inner-ratio CSS var is set
166
+ * inline by createTransformControls (= innerR / outerR, where outerR maps
167
+ * to the quad's edge at 50%). Hit-testing has to use the donut shape too.
168
+ * Single DOM node per ring instead of N segment quads.
169
+ */
170
+ .polycss-mesh.polycss-transform-ring i,
171
+ .polycss-mesh.polycss-transform-ring b,
172
+ .polycss-mesh.polycss-transform-ring s,
173
+ .polycss-mesh.polycss-transform-ring u {
174
+ --ring-inner-r: calc(var(--ring-inner-ratio, 0.92) * 50%);
175
+ --ring-outer-r: calc(var(--ring-outer-ratio, 1) * 50%);
176
+ -webkit-mask: radial-gradient(circle at 50% 50%,
177
+ transparent 0%,
178
+ transparent var(--ring-inner-r),
179
+ black var(--ring-inner-r),
180
+ black var(--ring-outer-r),
181
+ transparent var(--ring-outer-r));
182
+ mask: radial-gradient(circle at 50% 50%,
183
+ transparent 0%,
184
+ transparent var(--ring-inner-r),
185
+ black var(--ring-inner-r),
186
+ black var(--ring-outer-r),
187
+ transparent var(--ring-outer-r));
90
188
  }
91
189
 
92
190
  /* \u2500\u2500 Dynamic lighting cascade vars (scene root \u2192 polygons) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
@@ -106,6 +204,20 @@
106
204
  @property --plx { syntax: "<number>"; inherits: true; initial-value: 0; }
107
205
  @property --ply { syntax: "<number>"; inherits: true; initial-value: 0; }
108
206
  @property --plz { syntax: "<number>"; inherits: true; initial-value: 1; }
207
+
208
+ /* CSS-space light components (world-Y\u2192cssX, world-X\u2192cssY, world-Z\u2192cssZ).
209
+ Used by the shadow projection matrix. --clx is clamped away from 0 in JS
210
+ to avoid divide-by-zero when the light is near-horizontal. */
211
+ @property --clx { syntax: "<number>"; inherits: true; initial-value: 0.01; }
212
+ @property --cly { syntax: "<number>"; inherits: true; initial-value: 0; }
213
+ @property --clz { syntax: "<number>"; inherits: true; initial-value: 1; }
214
+
215
+ /* Ground-plane position in CSS pixels along the CSS-Z axis (= world-Z, the
216
+ up axis in polycss's world convention). Stored as a <number> so it can be
217
+ used directly inside matrix3d() calc() expressions (matrix3d requires
218
+ dimensionless entries \u2014 no px units).
219
+ Set by recomputeShadowGround() from the min world-Z of casting meshes. */
220
+ @property --shadow-ground-cssz { syntax: "<number>"; inherits: true; initial-value: 0; }
109
221
  @property --plr { syntax: "<number>"; inherits: true; initial-value: 1; }
110
222
  @property --plg { syntax: "<number>"; inherits: true; initial-value: 1; }
111
223
  @property --plb { syntax: "<number>"; inherits: true; initial-value: 1; }
@@ -123,9 +235,9 @@
123
235
  @property --pnx { syntax: "<number>"; inherits: true; initial-value: 0; }
124
236
  @property --pny { syntax: "<number>"; inherits: true; initial-value: 0; }
125
237
  @property --pnz { syntax: "<number>"; inherits: true; initial-value: 1; }
126
- @property --psr { syntax: "<number>"; inherits: false; initial-value: 1; }
127
- @property --psg { syntax: "<number>"; inherits: false; initial-value: 1; }
128
- @property --psb { syntax: "<number>"; inherits: false; initial-value: 1; }
238
+ @property --psr { syntax: "<number>"; inherits: true; initial-value: 1; }
239
+ @property --psg { syntax: "<number>"; inherits: true; initial-value: 1; }
240
+ @property --psb { syntax: "<number>"; inherits: true; initial-value: 1; }
129
241
 
130
242
  /* Hoisted Lambert dot product \u2014 computed once per element it's set on.
131
243
  inherits:true so a bucket wrapper computes lambert ONCE for its whole
@@ -171,6 +283,7 @@
171
283
  leaf). */
172
284
  .polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > i,
173
285
  .polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > b,
286
+ .polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > s,
174
287
  .polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > u {
175
288
  --plam: max(0, calc(
176
289
  var(--pnx) * var(--plx) +
@@ -179,7 +292,7 @@
179
292
  ));
180
293
  }
181
294
 
182
- /* All polys: containment + background-color from lambert (inherited or
295
+ /* Atlas polys: containment + background-color from lambert (inherited or
183
296
  own) and the scene-level light vars. Splitting this from the lambert
184
297
  calc above lets bucketed polys skip the dot-product entirely. */
185
298
  .polycss-scene[data-polycss-lighting="dynamic"] s {
@@ -200,29 +313,10 @@
200
313
  background-blend-mode: multiply;
201
314
  }
202
315
 
203
- .polycss-scene[data-polycss-lighting="dynamic"] b {
204
- background-color: rgb(
205
- calc(255 * var(--psr) * (var(--par) * var(--pai)
206
- + var(--plr) * var(--pli) * max(0,
207
- var(--pnx) * var(--plx) +
208
- var(--pny) * var(--ply) +
209
- var(--pnz) * var(--plz))))
210
- calc(255 * var(--psg) * (var(--pag) * var(--pai)
211
- + var(--plg) * var(--pli) * max(0,
212
- var(--pnx) * var(--plx) +
213
- var(--pny) * var(--ply) +
214
- var(--pnz) * var(--plz))))
215
- calc(255 * var(--psb) * (var(--pab) * var(--pai)
216
- + var(--plb) * var(--pli) * max(0,
217
- var(--pnx) * var(--plx) +
218
- var(--pny) * var(--ply) +
219
- var(--pnz) * var(--plz))))
220
- );
221
- background-blend-mode: normal;
222
- }
223
-
316
+ .polycss-scene[data-polycss-lighting="dynamic"] b,
317
+ .polycss-scene[data-polycss-lighting="dynamic"] i,
224
318
  .polycss-scene[data-polycss-lighting="dynamic"] u {
225
- border-bottom-color: rgb(
319
+ color: rgb(
226
320
  calc(255 * var(--psr) * (var(--par) * var(--pai)
227
321
  + var(--plr) * var(--pli) * var(--plam)))
228
322
  calc(255 * var(--psg) * (var(--pag) * var(--pai)
@@ -231,4 +325,64 @@
231
325
  + var(--plb) * var(--pli) * var(--plam)))
232
326
  );
233
327
  }
234
- `;var ho=65,yo=45,go=1,se=j.BASE_TILE;function Dt(e){let n=[];return e.position&&n.push(`translate3d(${e.position[0]}px, ${e.position[1]}px, ${e.position[2]}px)`),e.scale!==void 0&&(typeof e.scale=="number"?e.scale!==1&&n.push(`scale3d(${e.scale}, ${e.scale}, ${e.scale})`):n.push(`scale3d(${e.scale[0]}, ${e.scale[1]}, ${e.scale[2]})`)),e.rotation&&(e.rotation[0]&&n.push(`rotateX(${e.rotation[0]}deg)`),e.rotation[1]&&n.push(`rotateY(${e.rotation[1]}deg)`),e.rotation[2]&&n.push(`rotateZ(${e.rotation[2]}deg)`)),n.length>0?n.join(" "):void 0}function bo(e){let n=e.rotX??ho,t=e.rotY??yo,o=e.zoom??go,r=e.distance??0,s=e.target??[0,0,0],i=s[1]*se,c=s[0]*se,l=s[2]*se;return`${r!==0?`translateZ(${-r}px) `:""}scale(${o}) rotateX(${n}deg) rotate(${t}deg) translate3d(${-i}px, ${-c}px, ${-l}px)`}var vo=.1;function xo(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=e.vertices[1],o=e.vertices[2],r=t[1]-n[1],s=t[0]-n[0],i=t[2]-n[2],c=o[1]-n[1],l=o[0]-n[0],a=o[2]-n[2],d=-(s*a-i*l),m=-(i*c-r*a),f=-(r*l-s*c),h=Math.hypot(d,m,f);if(h<1e-9)return null;d/=h,m/=h,f/=h;let u=1/vo,p=Math.round(d*u)/u,b=Math.round(m*u)/u,x=Math.round(f*u)/u,M=Math.hypot(p,b,x);return M<1e-9?null:{key:p+","+b+","+x,vec:[p/M,b/M,x/M]}}function Rt(e,n={}){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");e.ownerDocument&&Ht(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let t={...n},o=e.ownerDocument??document,r=o.createElement("div");r.className="polycss-scene",r.setAttribute("aria-hidden","true"),c(r,t);let s=o.createElement("div");s.className="polycss-offset",r.appendChild(s),e.appendChild(r);let i=new Set;function c(y,g){y.style.setProperty("--scene-transform",bo(g)),l(y,g)}function l(y,g){let S=g.textureLighting==="dynamic";y.dataset.polycssLighting=g.textureLighting??"baked";let A=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai"];if(!S){for(let F of A)y.style.removeProperty(F);return}let w=g.directionalLight?.direction??[.4,-.7,.59],_=Math.hypot(w[0],w[1],w[2])||1,v=w[0]/_,k=w[1]/_,T=w[2]/_,R=(0,j.parseHexColor)(g.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],E=(0,j.parseHexColor)(g.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],P=g.directionalLight?.intensity??1,D=g.ambientLight?.intensity??.4,O=F=>(F/255).toFixed(4);y.style.setProperty("--plx",v.toFixed(4)),y.style.setProperty("--ply",k.toFixed(4)),y.style.setProperty("--plz",T.toFixed(4)),y.style.setProperty("--plr",O(R[0])),y.style.setProperty("--plg",O(R[1])),y.style.setProperty("--plb",O(R[2])),y.style.setProperty("--pli",P.toFixed(4)),y.style.setProperty("--par",O(E[0])),y.style.setProperty("--pag",O(E[1])),y.style.setProperty("--pab",O(E[2])),y.style.setProperty("--pai",D.toFixed(4))}function a(y){for(d(y.rendered,y.disposeAtlas),y.disposeAtlas=void 0,y.rendered.length=0;y.wrapper.firstChild;)y.wrapper.removeChild(y.wrapper.firstChild)}function d(y,g){g?.();for(let S of y){try{S.dispose()}catch{}S.element.parentNode&&S.element.parentNode.removeChild(S.element)}}function m(y){let g=o.createDocumentFragment(),S=t.textureLighting==="dynamic"&&!y.stableDom,A=new Map,w=[];for(let _ of y.rendered){let v=y.polygons[_.polygonIndex],k=S&&v?xo(v):null;if(!k){w.push(_);continue}let T=k.key+"|"+(v.color??""),R=A.get(T);R||(R={vec:k.vec,items:[]},A.set(T,R)),R.items.push(_)}for(let _ of w)g.appendChild(_.element);for(let _ of A.values()){if(_.items.length<2){for(let k of _.items)g.appendChild(k.element);continue}let v=o.createElement("div");v.className="polycss-bucket",v.style.setProperty("--pnx",String(_.vec[0])),v.style.setProperty("--pny",String(_.vec[1])),v.style.setProperty("--pnz",String(_.vec[2]));for(let k of _.items)v.appendChild(k.element),k.element.style.removeProperty("--pnx"),k.element.style.removeProperty("--pny"),k.element.style.removeProperty("--pnz");g.appendChild(v)}y.wrapper.appendChild(g)}function f(y,g){let S=t.textureLighting==="dynamic",A=t.directionalLight?.direction,w=g&&(g[0]!==0||g[1]!==0||g[2]!==0);if(!S||!w||!A){y.style.removeProperty("--plx"),y.style.removeProperty("--ply"),y.style.removeProperty("--plz");return}let _=(0,j.inverseRotateVec3)(A,g),v=Math.hypot(_[0],_[1],_[2])||1;y.style.setProperty("--plx",(_[0]/v).toFixed(4)),y.style.setProperty("--ply",(_[1]/v).toFixed(4)),y.style.setProperty("--plz",(_[2]/v).toFixed(4))}function h(y,g){a(y);let S=t.directionalLight,A=g?{...S,direction:g}:S,w={doc:o,directionalLight:A,ambientLight:t.ambientLight,textureLighting:t.textureLighting,atlasScale:t.atlasScale},_=(y.stableDom?wt(y.polygons,w):null)??Tt(y.polygons,w);y.rendered=_.rendered,y.disposeAtlas=_.dispose,m(y)}function u(){if(!t.autoCenter){s.style.removeProperty("--offset-transform");return}let y=[];for(let v of i)!v.disposed&&!v.excludeFromAutoCenter&&y.push(...v.polygons);if(y.length===0){s.style.removeProperty("--offset-transform");return}let g=(0,j.computeSceneBbox)(y),S=se,A=(g.min[1]+g.max[1])/2*S,w=(g.min[0]+g.max[0])/2*S,_=(g.min[2]+g.max[2])/2*S;s.style.setProperty("--offset-transform",`translate3d(${-A}px, ${-w}px, ${-_}px)`)}function p(y,g={}){let A=(r.ownerDocument??document).createElement("div");A.className="polycss-mesh",g.id&&A.setAttribute("data-poly-mesh-id",g.id);let w={...g},_=g.merge!==!1,v=!!g.stableDom,k=Dt(w);k&&(A.style.transform=k);let T=(O,F)=>F?(0,j.mergePolygons)(O):O,R=T(y.polygons,_);function E(O){if(O.length===0){A.style.removeProperty("--origin");return}let F=1/0,Z=1/0,L=1/0,I=-1/0,V=-1/0,X=-1/0;for(let Y of O)for(let z of Y.vertices)z[0]<F&&(F=z[0]),z[0]>I&&(I=z[0]),z[1]<Z&&(Z=z[1]),z[1]>V&&(V=z[1]),z[2]<L&&(L=z[2]),z[2]>X&&(X=z[2]);if(!Number.isFinite(F)){A.style.removeProperty("--origin");return}let $=(Z+V)/2*se,U=(F+I)/2*se,W=(L+X)/2*se;A.style.setProperty("--origin",`${$}px ${U}px ${W}px`)}E(R),s.appendChild(A);let P={handle:void 0,wrapper:A,parseResult:y,rendered:[],polygons:R,disposed:!1,stableDom:v,excludeFromAutoCenter:!!g.excludeFromAutoCenter,bakedRotation:g.rotation?[...g.rotation]:[0,0,0]},D={polygons:R,element:A,id:g.id,get transform(){return w},remove(){A.parentNode&&A.parentNode.removeChild(A),a(P),i.delete(P),u()},setPolygons(O,F){_=F?.merge??_,v=F?.stableDom??v,P.stableDom=v,P.polygons=T(O,_),D.polygons=P.polygons,E(P.polygons);let Z=F?.recomputeAutoCenter??!0;if(P.stableDom&&!P.wrapper.querySelector(".polycss-bucket")){let L={doc:o,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,atlasScale:t.atlasScale},I=kt(P.rendered,P.polygons,L);if(I){P.disposeAtlas?.(),P.rendered=I.rendered,P.disposeAtlas=I.dispose,Z&&u();return}}h(P),Z&&u()},setTransform(O){w={...w,...O};let F=Dt(w);A.style.transform=F??"",f(A,w.rotation)},dispose(){if(!P.disposed){P.disposed=!0,A.parentNode&&A.parentNode.removeChild(A),a(P);try{y.dispose()}catch{}i.delete(P),u()}},rebakeAtlas(){P.bakedRotation=w.rotation?[...w.rotation]:[0,0,0];let O=t.directionalLight?.direction??[.4,-.7,.59],F=(0,j.inverseRotateVec3)(O,P.bakedRotation);h(P,F)},getPosition(){return w.position},getRotation(){return w.rotation},getScale(){return w.scale},getPolygons(){return D.polygons}};return P.handle=D,i.add(P),h(P),f(A,w.rotation),u(),D}function b(y){let g=!!t.autoCenter;t={...t,...y},c(r,t);let S=!!t.autoCenter;for(let A of i)f(A.wrapper,A.handle.transform.rotation);g!==S&&u()}function x(){return t}function M(){let y=[];for(let g of i)y.push(g.handle);return y}function C(y){let g=y;for(;g;){if(g instanceof HTMLElement&&g.classList.contains("polycss-mesh")){for(let S of i)if(S.wrapper===g)return S.handle;return null}g=g.parentElement}return null}function H(){let y=Array.from(i);for(let g of y)try{g.handle.dispose()}catch{}r.parentNode&&r.parentNode.removeChild(r)}return{add:p,setOptions:b,destroy:H,host:e,getOptions:x,meshes:M,findMeshByElement:C}}var Po=typeof HTMLElement<"u"?HTMLElement:class{},Eo=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","atlas-scale","auto-center"];function ie(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Ao(e){return e==="false"?!1:ie(e)}function Mo(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Co(e){if(e==="baked"||e==="dynamic")return e}function To(e){return e==="auto"?"auto":ie(e)}var G=class extends Po{constructor(){super(...arguments);this._scene=null}static get observedAttributes(){return[...Eo]}getScene(){return this._scene}_readOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={},s=Ao(this.getAttribute("perspective"));s!==void 0&&(r.perspective=s);let i=ie(this.getAttribute("rot-x"));i!==void 0&&(r.rotX=i);let c=ie(this.getAttribute("rot-y"));c!==void 0&&(r.rotY=c);let l=ie(this.getAttribute("zoom"));l!==void 0&&(r.zoom=l),r.textureLighting=Co(this.getAttribute("texture-lighting"))??"baked";let a=To(this.getAttribute("atlas-scale"));return a!==void 0&&(r.atlasScale=a),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=Mo(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=ie(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let s={direction:t??[.4,-.7,.59]};return o&&(s.color=o),r!==void 0&&(s.intensity=r),s}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=ie(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){this._scene||(this._scene=Rt(this,this._readOptions()),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1})))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null)}attributeChangedCallback(t,o,r){o!==r&&this._scene&&this._scene.setOptions(this._readOptions())}};var Oe=require("@layoutit/polycss-core"),Lo=typeof HTMLElement<"u"?HTMLElement:class{},_o=["src","mtl","position","scale","rotation","auto-center"];function ye(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function It(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return ye(e)}}function So(e){return e.closest("poly-scene")??null}function wo(e){if(e.length===0)return e;let n=(0,Oe.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s),...i.textureTriangles?.length?{textureTriangles:i.textureTriangles.map(c=>({...c,vertices:c.vertices.map(s)}))}:null}))}var ae=class extends Lo{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[..._o]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:ye(this.getAttribute("position")),scale:It(this.getAttribute("scale")),rotation:ye(this.getAttribute("rotation"))})}}_tearDown(){if(this._loadToken+=1,this._handle){try{this._handle.dispose()}catch{}this._handle=null}this._parseResult=null}async _maybeLoad(){let t=this.getAttribute("src");if(!t)return;let o=So(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,i;try{i=await(0,Oe.loadMesh)(t,s?{mtlUrl:s}:void 0)}catch(a){this.dispatchEvent(new CustomEvent("polycss:error",{detail:a,bubbles:!0}));return}if(r!==this._loadToken){try{i.dispose()}catch{}return}let c=o.getScene();if(!c){try{i.dispose()}catch{}return}this.hasAttribute("auto-center")&&(i={...i,polygons:wo(i.polygons)}),this._parseResult=i,this._handle=c.add(i,{position:ye(this.getAttribute("position")),scale:It(this.getAttribute("scale")),rotation:ye(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var ko=typeof HTMLElement<"u"?HTMLElement:class{},Oo=["vertices","color","texture","uvs","position","scale","rotation"];function Vt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Qe(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Ho(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Qe(e)}}function Do(e){return e.closest("poly-scene")??null}var ge=class extends ko{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Oo]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=Do(this);if(!t)return;let o=t.getScene();if(!o)return;let r=Vt(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let s=this.getAttribute("color")||void 0,i=this.getAttribute("texture")||void 0,c=Vt(this.getAttribute("uvs"))??void 0,l={};for(let m of Array.from(this.attributes))m.name.startsWith("data-")&&(l[m.name.slice(5)]=m.value);let d={polygons:[{vertices:r,...s!==void 0?{color:s}:{},...i!==void 0?{texture:i}:{},...c!==void 0?{uvs:c}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(d,{position:Qe(this.getAttribute("position")),scale:Ho(this.getAttribute("scale")),rotation:Qe(this.getAttribute("rotation"))})}};var Bt=require("@layoutit/polycss-core"),Ro=typeof HTMLElement<"u"?HTMLElement:class{},Io=["size","thickness","negative","x-color","y-color","z-color"];function Vo(e){return e.closest("poly-scene")??null}function zt(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var be=class extends Ro{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Io]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&this._handle&&this._remount()}_polygons(){return(0,Bt.axesHelperPolygons)({size:zt(this.getAttribute("size")),thickness:zt(this.getAttribute("thickness")),negative:this.hasAttribute("negative"),xColor:this.getAttribute("x-color")??void 0,yColor:this.getAttribute("y-color")??void 0,zColor:this.getAttribute("z-color")??void 0})}_mount(){let t=Vo(this);if(!t)return;let o=t.getScene();if(!o)return;let r={polygons:this._polygons(),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(r,{excludeFromAutoCenter:!0})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var Xt=require("@layoutit/polycss-core"),zo=typeof HTMLElement<"u"?HTMLElement:class{},Bo=["direction","target","distance","size","color"],et=50,Fo=5,No=.35,Xo="#ffd54a";function Yo(e){return e.closest("poly-scene")??null}function Ft(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Nt(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var ve=class extends zo{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Bo]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="size"||t==="color"){this._remount();return}this._handle.setTransform({position:this._meshPosition()})}}_meshPosition(){let t=Ft(this.getAttribute("direction"));if(!t)return;let o=Ft(this.getAttribute("target"))??[0,0,0],r=Nt(this.getAttribute("distance"),Fo),s=t[0],i=t[1],c=t[2],l=Math.hypot(s,i,c)||1,a=o[0]+i/l*r,d=o[1]+s/l*r,m=o[2]+c/l*r;return[d*et,a*et,m*et]}_mount(){let t=Yo(this);if(!t)return;let o=t.getScene();if(!o)return;let r=Nt(this.getAttribute("size"),No),s=this.getAttribute("color")??Xo,i={polygons:(0,Xt.octahedronPolygons)({center:[0,0,0],size:r,color:s}),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(i,{position:this._meshPosition(),excludeFromAutoCenter:!0})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var Yt=require("@layoutit/polycss-core");var He={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function me(e,n){let t;return n.animate===!1?t=!1:n.animate?t={speed:n.animate.speed??.3,axis:n.animate.axis??"y",pauseOnInteraction:n.animate.pauseOnInteraction??!0}:t=e.animate,{drag:n.drag??e.drag,wheel:n.wheel??e.wheel,dolly:n.dolly??e.dolly,invert:n.invert??e.invert,minZoom:n.minZoom??e.minZoom,maxZoom:n.maxZoom??e.maxZoom,minDistance:n.minDistance??e.minDistance,maxDistance:n.maxDistance??e.maxDistance,animate:t}}function xe(e){return e===!0?-1:e===!1?1:e}function De(){let e=[],n=[],t=[];function o(i){return i==="change"?e:i==="start"?n:t}function r(i){if(e.length===0)return;let c={type:"change",camera:i()},l=e.slice();for(let a of l)try{a(c)}catch(d){console.error("[polycss] controls 'change' listener threw:",d)}}function s(i,c){let l=i==="start"?n:t;if(l.length===0)return;let a={type:i,camera:c()},d=l.slice();for(let m of d)try{m(a)}catch(f){console.error(`[polycss] controls '${i}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function Re(e){return()=>{let n=e.getOptions(),t=n.target??[0,0,0];return{rotX:n.rotX??0,rotY:n.rotY??0,zoom:n.zoom??1,target:[t[0],t[1],t[2]],distance:n.distance??0}}}function Ie(e,n,t,o,r,s){let i=!1,c=null;return{onWheel:d=>{let m=n();if(!m.wheel||t())return;d.preventDefault();let f=d.deltaMode===1?16:d.deltaMode===2?100:1,h=d.deltaY*f;d.ctrlKey?h*=10:h*=3;let u=e.getOptions();if(m.dolly){let p=u.distance??0,b=Math.max(m.minDistance,Math.min(m.maxDistance,p+h*.05));e.setOptions({distance:b})}else{let p=Math.exp(-h*513e-6),b=u.zoom??1,x=Math.max(m.minZoom,Math.min(m.maxZoom,b*p));e.setOptions({zoom:x})}i||(i=!0,s("start",o)),r(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,i=!1,s("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),i=!1}}}function Ve(e,n,t,o,r,s,i){let c=null,l=0,a=h=>{if(c===null||o())return;let u=t();if(!u.animate){c=null;return}if(r())l=h;else{let p=Math.min(50,l?h-l:16.67);l=h;let b=u.animate.speed*(p/16.67),x=n.getOptions();if(u.animate.axis==="x"){let M=(((x.rotX??65)+b)%360+360)%360;n.setOptions({rotX:M})}else{let M=(((x.rotY??45)+b)%360+360)%360;n.setOptions({rotY:M})}i(s)}c=e.requestAnimationFrame(a)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(a))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function $t(e,n={}){let t=me(He,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,a=De(),d=Re(e),{changeListeners:m,startListeners:f,endListeners:h,listenerArray:u,emitChange:p,emitInteraction:b}=a,x=Ve(r,e,()=>t,()=>l,()=>c,d,p),M=E=>{if(!(!t.drag||l)&&s===null&&E.isPrimary!==!1){E.preventDefault(),s=E.pointerId,i={x:E.clientX,y:E.clientY},o.style.cursor="grabbing";try{E.target.setPointerCapture(E.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),b("start",d)}},C=E=>{if(s===null||E.pointerId!==s||!t.drag||l)return;E.preventDefault();let P=E.clientX-i.x,D=E.clientY-i.y;i={x:E.clientX,y:E.clientY};let O=xe(t.invert),F=P/4*O,Z=D/4*O,L=e.getOptions();if(E.shiftKey){let I=L.rotX??65,V=L.rotY??45,X=Math.max(.01,L.zoom??1),$=Math.cos(I*Math.PI/180),U=$>=0?Math.max(.1,$):Math.min(-.1,$),W=Math.cos(V*Math.PI/180),Y=Math.sin(V*Math.PI/180),z=X*Yt.BASE_TILE,ee=(P*Y-D*W/U)/z,le=-(P*W+D*Y/U)/z,te=L.target??[0,0,0];e.setOptions({target:[te[0]+ee,te[1]+le,te[2]]})}else{let I=Math.max(0,Math.min(100,(L.rotX??65)-Z)),V=(((L.rotY??45)-F)%360+360)%360;e.setOptions({rotX:I,rotY:V})}p(d)},H=E=>{if(s===E.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{E.target.releasePointerCapture(E.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),b("end",d)}},y=Ie(e,()=>t,()=>l,d,p,b);function g(){o.addEventListener("pointerdown",M),o.addEventListener("pointermove",C),o.addEventListener("pointerup",H),o.addEventListener("pointercancel",H),o.addEventListener("wheel",y.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function S(){o.removeEventListener("pointerdown",M),o.removeEventListener("pointermove",C),o.removeEventListener("pointerup",H),o.removeEventListener("pointercancel",H),o.removeEventListener("wheel",y.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",y.teardown()}g(),x.start();function A(E){let P=!!t.animate;t=me(t,E),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let D=!!t.animate;P&&!D?x.stop():!P&&D&&x.start()}function w(){l&&(l=!1,g(),x.start())}function _(){l||(l=!0,S(),x.stop(),s=null,c=!1,y.teardown())}function v(){_(),m.length=0,f.length=0,h.length=0}function k(E,P){let D=u(E);D.includes(P)||D.push(P)}function T(E,P){let D=u(E),O=D.indexOf(P);O>=0&&D.splice(O,1)}function R(E,P){return u(E).includes(P)}return{update:A,resume:w,pause:_,destroy:v,addEventListener:k,removeEventListener:T,hasEventListener:R}}function N(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function ze(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function oe(e){if(e!==null)return!(e==="false"||e==="0")}function Be(e){if(e===null)return;if(e==="true")return!0;if(e==="false")return!1;let n=parseFloat(e);return Number.isFinite(n)?n:!0}function Fe(e){if(e==="x"||e==="y")return e}var $o=typeof HTMLElement<"u"?HTMLElement:class{},Uo=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Pe=class extends $o{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Uo]}_readAnimate(){let t=N(this.getAttribute("animate-speed")),o=Fe(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:oe(r)}:{}}}_readOptions(){let t={},o=oe(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=oe(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=N(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=N(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=Be(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=N(this.getAttribute("zoom-min")),a=N(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),a!==void 0&&(t.maxZoom=a),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof G)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=$t(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Ut=require("@layoutit/polycss-core");function Wt(e,n={}){let t=me(He,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,a=!1,d={x:0,y:0},m=De(),f=Re(e),{changeListeners:h,startListeners:u,endListeners:p,listenerArray:b,emitChange:x,emitInteraction:M}=m,C=Ve(r,e,()=>t,()=>l,()=>c,f,x),H=L=>{if(!(!t.drag||l)&&s===null&&L.isPrimary!==!1){L.preventDefault(),s=L.pointerId,i={x:L.clientX,y:L.clientY},o.style.cursor="grabbing";try{L.target.setPointerCapture(L.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),M("start",f)}},y=L=>{if(s===null||L.pointerId!==s||!t.drag||l)return;L.preventDefault();let I=L.clientX-i.x,V=L.clientY-i.y;i={x:L.clientX,y:L.clientY};let X=e.getOptions();if(L.shiftKey){let $=xe(t.invert),U=I/4*$,W=V/4*$,Y=Math.max(0,Math.min(100,(X.rotX??65)-W)),z=(((X.rotY??45)-U)%360+360)%360;e.setOptions({rotX:Y,rotY:z})}else{let $=X.rotX??65,U=X.rotY??45,W=Math.max(.01,X.zoom??1),Y=Math.cos($*Math.PI/180),z=Y>=0?Math.max(.1,Y):Math.min(-.1,Y),ee=Math.cos(U*Math.PI/180),le=Math.sin(U*Math.PI/180),te=W*Ut.BASE_TILE,Xe=(I*le-V*ee/z)/te,K=-(I*ee+V*le/z)/te,q=X.target??[0,0,0];e.setOptions({target:[q[0]+Xe,q[1]+K,q[2]]})}x(f)},g=L=>{if(s===L.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{L.target.releasePointerCapture(L.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),M("end",f)}},S=L=>{L.preventDefault()},A=L=>{L.button===2&&(a=!0,d={x:L.clientX,y:L.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),M("start",f))},w=L=>{if(!a||!t.drag)return;let I=L.clientX-d.x,V=L.clientY-d.y;d={x:L.clientX,y:L.clientY};let X=xe(t.invert),$=I/4*X,U=V/4*X,W=e.getOptions(),Y=Math.max(0,Math.min(100,(W.rotX??65)-U)),z=(((W.rotY??45)-$)%360+360)%360;e.setOptions({rotX:Y,rotY:z}),x(f)},_=L=>{L.button===2&&a&&(a=!1,M("end",f))},v=Ie(e,()=>t,()=>l,f,x,M);function k(){o.addEventListener("pointerdown",H),o.addEventListener("pointermove",y),o.addEventListener("pointerup",g),o.addEventListener("pointercancel",g),o.addEventListener("wheel",v.onWheel,{passive:!1}),o.addEventListener("contextmenu",S),o.addEventListener("mousedown",A),o.addEventListener("mousemove",w),o.addEventListener("mouseup",_),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function T(){o.removeEventListener("pointerdown",H),o.removeEventListener("pointermove",y),o.removeEventListener("pointerup",g),o.removeEventListener("pointercancel",g),o.removeEventListener("wheel",v.onWheel),o.removeEventListener("contextmenu",S),o.removeEventListener("mousedown",A),o.removeEventListener("mousemove",w),o.removeEventListener("mouseup",_),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",v.teardown()}k(),C.start();function R(L){let I=!!t.animate;t=me(t,L),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let V=!!t.animate;I&&!V?C.stop():!I&&V&&C.start()}function E(){l&&(l=!1,k(),C.start())}function P(){l||(l=!0,T(),C.stop(),s=null,c=!1,a=!1,v.teardown())}function D(){P(),h.length=0,u.length=0,p.length=0}function O(L,I){let V=b(L);V.includes(I)||V.push(I)}function F(L,I){let V=b(L),X=V.indexOf(I);X>=0&&V.splice(X,1)}function Z(L,I){return b(L).includes(I)}return{update:R,resume:E,pause:P,destroy:D,addEventListener:O,removeEventListener:F,hasEventListener:Z}}var Wo=typeof HTMLElement<"u"?HTMLElement:class{},Zo=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Ee=class extends Wo{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Zo]}_readAnimate(){let t=N(this.getAttribute("animate-speed")),o=Fe(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:oe(r)}:{}}}_readOptions(){let t={},o=oe(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=oe(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=N(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=N(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=Be(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=N(this.getAttribute("zoom-min")),a=N(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),a!==void 0&&(t.maxZoom=a),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof G)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=Wt(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var tt=require("@layoutit/polycss-core"),Go=8e3;function nt(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,tt.createIsometricCamera)(n),o=`${e.perspective??Go}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function Zt(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,tt.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var jo=typeof HTMLElement<"u"?HTMLElement:class{},qo=["perspective","zoom","rot-x","rot-y","target","distance"],Ae=class extends jo{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...qo]}getCamera(){return this._camera}_readOptions(){return{perspective:N(this.getAttribute("perspective")),zoom:N(this.getAttribute("zoom")),rotX:N(this.getAttribute("rot-x")),rotY:N(this.getAttribute("rot-y")),target:ze(this.getAttribute("target")),distance:N(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=nt(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let s=this._readOptions();this._camera=nt(s),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var Ko=typeof HTMLElement<"u"?HTMLElement:class{},Jo=["zoom","rot-x","rot-y","target","distance"],Me=class extends Ko{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Jo]}getCamera(){return this._camera}_readOptions(){return{zoom:N(this.getAttribute("zoom")),rotX:N(this.getAttribute("rot-x")),rotY:N(this.getAttribute("rot-y")),target:ze(this.getAttribute("target")),distance:N(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Zt(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let s=this._readOptions();s.zoom!==void 0&&this._camera.update({zoom:s.zoom}),s.rotX!==void 0&&this._camera.update({rotX:s.rotX}),s.rotY!==void 0&&this._camera.update({rotY:s.rotY}),s.target!==void 0&&this._camera.update({target:s.target}),s.distance!==void 0&&this._camera.update({distance:s.distance})}};var Ne=require("@layoutit/polycss-core"),rt="#ff3653",st="#8adb00",it="#2c8fff",fe=50,Gt=60,Qo=.6,er=.0125,tr=.15,nr=.04,or=1,rr=.012,sr=64,ir=1e-4,ar=.6,lr=.8,cr=1,jt={0:1,1:0,2:2},qt=[{cssAxis:0,sign:1,key:"x",color:rt},{cssAxis:0,sign:-1,key:"-x",color:rt},{cssAxis:1,sign:1,key:"y",color:st},{cssAxis:1,sign:-1,key:"-y",color:st},{cssAxis:2,sign:1,key:"z",color:it},{cssAxis:2,sign:-1,key:"-z",color:it}],Kt=[{cssAxis:0,key:"x",color:rt},{cssAxis:1,key:"y",color:st},{cssAxis:2,key:"z",color:it}];function ur(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),s=parseInt(t[3],16);return`rgba(${o}, ${r}, ${s}, ${n})`}function Qt(e,n){return!n||n<=0?e:Math.round(e/n)*n}function dr(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let l of c.vertices)l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>s&&(s=l[1]),l[2]<o&&(o=l[2]),l[2]>i&&(i=l[2]);return Number.isFinite(n)?[(t+s)/2*fe,(n+r)/2*fe,(o+i)/2*fe]:[0,0,0]}function Jt(e){if(e.length===0)return Gt;let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let a of l.vertices)a[0]<n&&(n=a[0]),a[0]>r&&(r=a[0]),a[1]<t&&(t=a[1]),a[1]>s&&(s=a[1]),a[2]<o&&(o=a[2]),a[2]>i&&(i=a[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*fe*Qo:Gt}function ot(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function pr(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:c,translationSnap:l,onAxisDelta:a,onMouseDown:d,onMouseUp:m,onDraggingChanged:f}=e,h=o,u=[0,0,0];u[n]=t;let p=r.ownerDocument.createElement("div");p.style.position="absolute",p.style.left="0",p.style.top="0",p.style.width="0",p.style.height="0",p.style.transform=`translate3d(${u[0]*h}px, ${u[1]*h}px, ${u[2]*h}px)`,r.appendChild(p);let b=r.getBoundingClientRect(),x=p.getBoundingClientRect();r.removeChild(p);let M=(x.left-b.left)/h,C=(x.top-b.top)/h,H=M*M+C*C;if(H<ir)return;d?.(),f?.(!0);let y=S=>{let A=S.clientX-i,w=S.clientY-c,_=(A*M+w*C)/H;_=Qt(_,l),a(_,u)},g=()=>{window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g);let S=A=>{A.stopPropagation(),A.stopImmediatePropagation()};window.addEventListener("click",S,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",S,!0),0),m?.(),f?.(!1)};window.addEventListener("pointermove",y),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g)}function mr(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:c,onMouseDown:l,onMouseUp:a,onDraggingChanged:d}=e,m=t.getBoundingClientRect(),f=m.left,h=m.top,u=Math.atan2(s-h,r-f),p=0;l?.(),d?.(!0);let b=M=>{let C=Math.atan2(M.clientY-h,M.clientX-f),H=C-u;H>Math.PI?H-=2*Math.PI:H<-Math.PI&&(H+=2*Math.PI),p+=H,u=C;let y=p*180/Math.PI;y=Qt(y,i),c(y)},x=()=>{window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x);let M=C=>{C.stopPropagation(),C.stopImmediatePropagation()};window.addEventListener("click",M,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",M,!0),0),a?.(),d?.(!1)};window.addEventListener("pointermove",b),window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x)}function en(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,c=null,l=null,a=[0,0,0];function d(){if(!t)return[0,0,0];let v=t.transform.position??[0,0,0];return[v[0]+a[0],v[1]+a[1],v[2]+a[2]]}function m(v){return l===v?cr:c===v?lr:ar}function f(){for(let[v,k]of i){let T=h(k.spec,m(v));k.handle.setPolygons(T,{recomputeAutoCenter:!1})}}function h(v,k){let R=Jt(t?.polygons??[])*r,E=R/fe,P=ur(v.color,k);if(o==="translate")return(0,Ne.arrowPolygons)({axis:jt[v.cssAxis],sign:v.sign??1,shaftLength:E,shaftHalfThickness:E*er,headLength:E*tr,headHalfThickness:E*nr,color:P});let D=R*or/fe;return(0,Ne.ringPolygons)({axis:jt[v.cssAxis],radius:D,halfThickness:D*rr,segments:sr,color:P})}function u(){if(p(),!t)return;let v={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1},k=o==="translate"?qt:o==="rotate"?Kt:[],T=o==="translate"?"polycss-transform-arrow":"polycss-transform-ring",R=d();for(let E of k){let P=E.key.replace("-","")[0];if(!v[P])continue;let D=h(E,m(E.key)),O=e.add({polygons:D,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${E.key}`,position:R});O.element.classList.add("polycss-transform-gizmo",T,`${T}--${E.key}`),i.set(E.key,{handle:O,spec:E})}}function p(){for(let{handle:v}of i.values())v.remove();i.clear(),c=null,l=null}function b(){if(!t)return;let v=d();for(let{handle:k}of i.values())k.setTransform({position:v})}function x(){t&&(i.size===0?u():b())}function M(v){if(t=v,!v){a=[0,0,0],p();return}a=dr(v.polygons),p(),u()}function C(){M(null)}function H(v){v!==o&&(o=v,t&&(p(),u()))}function y(v,k,T){if(!t||!g)return;let R=[g[0]+k*T[0],g[1]+k*T[1],g[2]+k*T[2]];t.setTransform({position:R}),b(),s.onObjectChange?.({object:t,position:R}),s.onChange?.()}let g=null,S=null,A=v=>{if(!t||s.enabled===!1)return;let k={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate")for(let T of qt){let R=T.key.replace("-","")[0];if(!k[R])continue;let E=i.get(T.key);if(E&&ot(E.handle.element,v.clientX,v.clientY)){v.preventDefault(),v.stopPropagation(),l=T.key,f(),g=(t.transform.position??[0,0,0]).slice(),pr({cssAxis:T.cssAxis,sign:T.sign,shaftLengthCss:Jt(t.polygons)*r,wrapper:E.handle.element,target:t,startClientX:v.clientX,startClientY:v.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(P,D)=>y(T,P,D),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:P=>{P||(l=null,g=null,f()),s.onDraggingChanged?.(P)}});return}}else if(o==="rotate")for(let T of Kt){if(!k[T.key])continue;let R=i.get(T.key);if(R&&ot(R.handle.element,v.clientX,v.clientY)){v.preventDefault(),v.stopPropagation(),l=T.key,f(),S=(t.transform.rotation??[0,0,0]).slice(),mr({cssAxis:T.cssAxis,wrapper:R.handle.element,target:t,startClientX:v.clientX,startClientY:v.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:E=>{if(!t||!S)return;let P=[S[0],S[1],S[2]],D=T.cssAxis===0?-1:1;P[T.cssAxis]=S[T.cssAxis]+E*D,t.setTransform({rotation:P}),s.onObjectChange?.({object:t,rotation:P}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:E=>{E||(l=null,S=null,f(),t?.rebakeAtlas()),s.onDraggingChanged?.(E)}});return}}};e.host.addEventListener("pointerdown",A,{capture:!0});let w=v=>{if(!t||l||s.enabled===!1)return;let k=null;for(let[T,R]of i)if(ot(R.handle.element,v.clientX,v.clientY)){k=T;break}k!==c&&(c=k,f())};e.host.addEventListener("pointermove",w);function _(){e.host.removeEventListener("pointerdown",A,{capture:!0}),e.host.removeEventListener("pointermove",w),p()}return{attach:M,detach:C,setMode:H,update:x,destroy:_}}var fr=typeof HTMLElement<"u"?HTMLElement:class{},hr=["mode","target","size","enabled"];function tn(e){if(e==="translate"||e==="rotate")return e}var Ce=class extends fr{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...hr]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof G)return t;t=t.parentNode}return null}_findTargetMesh(){let t=this.getAttribute("target");if(!t)return null;let o=this._findScene();if(!o)return null;let r=null;try{r=o.querySelector(`#${t}`)??o.querySelector(t)}catch{r=o.querySelector(`[id="${t}"]`)}return r instanceof ae?r:null}_readOptions(){let t={},o=tn(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=N(this.getAttribute("size"));r!==void 0&&(t.size=r);let s=this.getAttribute("enabled");return s!==null&&(t.enabled=s!=="false"&&s!=="0"),t.onObjectChange=i=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:i.position,rotation:i.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let s=()=>{t.removeEventListener("polycss:scene-ready",s),this._attach()};t.addEventListener("polycss:scene-ready",s)}return}this._tc=en(o,this._readOptions());let r=this._findTargetMesh();if(r){let s=r.getMeshHandle();s&&this._tc.attach(s)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,r){if(o!==r&&this._tc){if(t==="mode"){let s=tn(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};function yr(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function nn(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let p of o)try{p(t)}catch(b){console.error("[polycss/createSelect] onChange threw:",b)}}function s(u){t=u,r()}function i(u){n.multiple?t.includes(u)||(t=[...t,u]):t=[u],r()}function c(u){t.includes(u)&&(t=t.filter(p=>p!==u),r())}function l(u){t.includes(u)?t=t.filter(p=>p!==u):n.multiple?t=[...t,u]:t=[u],r()}function a(){t.length!==0&&(t=[],r())}function d(u){return t.includes(u)}function m(u,p){for(let b of e.meshes())if(!b.element.classList.contains("polycss-transform-gizmo")&&yr(b.element,u,p))return b;return null}let f=u=>{let p=u.target;if(p?.closest(".polycss-transform-gizmo"))return;let b=e.findMeshByElement(p)??m(u.clientX,u.clientY);if(!b){n.onPointerMissed&&n.onPointerMissed(u),n.clearOnMiss!==!1&&a();return}n.multiple&&(u.shiftKey||u.metaKey||u.ctrlKey)?l(b):t.length===1&&t[0]===b?a():s([b])};e.host.addEventListener("click",f);function h(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:s,add:i,remove:c,toggle:l,clear:a,has:d,destroy:h}}var gr=typeof HTMLElement<"u"?HTMLElement:class{},br=["multiple","clear-on-miss"],Te=class extends gr{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...br]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof G)return t;t=t.parentNode}return null}_readOptions(){return{multiple:this.hasAttribute("multiple"),clearOnMiss:!this.hasAttribute("clear-on-miss")||this.getAttribute("clear-on-miss")!=="false",onChange:t=>{this.dispatchEvent(new CustomEvent("polycss:select",{bubbles:!0,detail:{selected:t}}))}}}_attach(){if(this._selection)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._selection=nn(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};typeof customElements<"u"&&(customElements.get("poly-scene")||customElements.define("poly-scene",G),customElements.get("poly-mesh")||customElements.define("poly-mesh",ae),customElements.get("poly-polygon")||customElements.define("poly-polygon",ge),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",be),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",ve),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",Pe),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",Ee),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",Ae),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",Me),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",Ce),customElements.get("poly-select")||customElements.define("poly-select",Te));0&&(module.exports={PolyAxesHelperElement,PolyDirectionalLightHelperElement,PolyMapControlsElement,PolyMeshElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPolygonElement,PolySceneElement,PolySelectElement,PolyTransformControlsElement});
328
+
329
+ /* \u2500\u2500 Cast shadows (dynamic mode only) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
330
+
331
+ /*
332
+ * Shadow projection matrix. Projects any 3D point P onto the horizontal
333
+ * ground plane (cssZ \u2248 G) along the CSS-space light direction (--clx/y/z).
334
+ *
335
+ * In polycss's world convention world Z is up (red-green plane is the
336
+ * floor in the axes helper). After the world\u2192CSS swap (Y\u2194X), world Z stays
337
+ * as CSS Z, so the ground plane normal in CSS space is +cssZ.
338
+ *
339
+ * The strict projection formula would set m22=0 (output.z is a constant G,
340
+ * the polygon is exactly flat). But Chromium SKIPS rendering elements
341
+ * whose composed transform matrix is non-invertible (singular). m22=0
342
+ * makes the matrix singular, so the shadow paints nothing even though it
343
+ * has a valid layout box. The fix: collapse along z by a near-zero
344
+ * scale (Z_SQUASH = 0.01) instead of exactly zero \u2014 output.z is then
345
+ * approximately G with ~1% drift from the input, full-rank and renderable.
346
+ * The shadow still looks flat to the eye (the drift is sub-pixel for
347
+ * any realistic scene size).
348
+ *
349
+ * out.cssX = P.cssX - (--clx/--clz) * (P.cssZ - G)
350
+ * out.cssY = P.cssY - (--cly/--clz) * (P.cssZ - G)
351
+ * out.cssZ = Z_SQUASH * P.cssZ + (1 - Z_SQUASH) * G
352
+ *
353
+ * As column-major 4\xD74 (CSS matrix3d order):
354
+ * col1: [1, 0, 0, 0]
355
+ * col2: [0, 1, 0, 0]
356
+ * col3: [-(--clx/--clz), -(--cly/--clz), Z_SQUASH, 0]
357
+ * col4: [G*(--clx/--clz), G*(--cly/--clz), G*(1-Z_SQUASH), 1]
358
+ */
359
+ .polycss-scene[data-polycss-lighting="dynamic"] {
360
+ --shadow-proj: matrix3d(
361
+ 1, 0, 0, 0,
362
+ 0, 1, 0, 0,
363
+ calc(-1 * var(--clx) / var(--clz)),
364
+ calc(-1 * var(--cly) / var(--clz)),
365
+ 0.01,
366
+ 0,
367
+ calc(var(--shadow-ground-cssz) * var(--clx) / var(--clz)),
368
+ calc(var(--shadow-ground-cssz) * var(--cly) / var(--clz)),
369
+ calc(var(--shadow-ground-cssz) * 0.99),
370
+ 1
371
+ );
372
+ }
373
+
374
+ /* <q> shadow leaf \u2014 Lambert-gated opacity. Polygons facing the light cast
375
+ full shadow; polygons facing away cast zero shadow (their projection
376
+ would stack inside the silhouette and produce ugly overdraw). The
377
+ * 10 multiplier sharpens the cutoff so small positive Lambert values
378
+ jump quickly to 1, giving a near-binary visibility decision with a
379
+ smooth edge transition. Pure CSS calc \u2014 no JS at light-change time.
380
+
381
+ The base layout / positioning / pseudo-element-strip rules for <q>
382
+ live in the polygon-leaf section above. This rule only adds the
383
+ dynamic-light Lambert gating, separated so it's easy to disable the
384
+ gate for debugging by commenting out a single block. */
385
+ .polycss-scene q {
386
+ opacity: clamp(0, calc((var(--pnx) * var(--clx) + var(--pny) * var(--cly) + var(--pnz) * var(--clz)) * 10), 1);
387
+ }
388
+ `;var Ps=750,Es=8e3;var ft=65,ht=45,As=1,ke=ee.BASE_TILE;function Ms(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let r of t)if(!o.includes(r))return!1;return!0}function so(e){let n=[];return e.position&&n.push(`translate3d(${e.position[0]}px, ${e.position[1]}px, ${e.position[2]}px)`),e.scale!==void 0&&(typeof e.scale=="number"?e.scale!==1&&n.push(`scale3d(${e.scale}, ${e.scale}, ${e.scale})`):n.push(`scale3d(${e.scale[0]}, ${e.scale[1]}, ${e.scale[2]})`)),e.rotation&&(e.rotation[0]&&n.push(`rotateX(${e.rotation[0]}deg)`),e.rotation[1]&&n.push(`rotateY(${e.rotation[1]}deg)`),e.rotation[2]&&n.push(`rotateZ(${e.rotation[2]}deg)`)),n.length>0?n.join(" "):void 0}function Cs(e,n=[0,0,0],t=1){let o=e.rotX??ft,r=e.rotY??ht,s=(e.zoom??As)*t,i=(e.distance??0)*t,l=e.target??[0,0,0],a=l[0]+n[0],u=l[1]+n[1],m=l[2]+n[2],d=u*ke,f=a*ke,g=m*ke;return`${i!==0?`translateZ(${-i}px) `:""}scale(${s}) rotateX(${o}deg) rotate(${r}deg) translate3d(${-d}px, ${-f}px, ${-g}px)`}function Ss(e){let n=e.trim();if(!n||n==="normal")return 1;let t=n.endsWith("%")?Number(n.slice(0,-1))/100:Number(n);return Number.isFinite(t)&&t>0?t:1}function ws(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=Ss(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function on(e,n){return n===1?e:e*n}function Ts(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}var Ls=.1;function _s(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let d=1;d+1<e.vertices.length;d++){let f=e.vertices[d],g=e.vertices[d+1],p=f[1]-n[1],h=f[0]-n[0],b=f[2]-n[2],x=g[1]-n[1],A=g[0]-n[0],M=g[2]-n[2];t-=h*M-b*A,o-=b*x-p*M,r-=p*A-h*x}let s=Math.hypot(t,o,r);if(s<1e-9)return null;t/=s,o/=s,r/=s;let i=1/Ls,l=Math.round(t*i)/i,a=Math.round(o*i)/i,u=Math.round(r*i)/i,m=Math.hypot(l,a,u);return m<1e-9?null:{key:l+","+a+","+u,vec:[l/m,a/m,u/m]}}function io(e,n={}){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");e.ownerDocument&&ro(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let t={...n},o=ws(e),r=[0,0,0],s=e.ownerDocument??document,i=s.createElement("div");i.className="polycss-scene",i.setAttribute("aria-hidden","true"),a(i,t),e.appendChild(i);let l=new Set;function a(c,y){Ts(c,o),c.style.transform=Cs(y,r,o),typeof y.perspective=="number"?c.style.perspective=`${on(y.perspective,o)}px`:y.perspective===!1?c.style.perspective=`${on(1e6,o)}px`:Math.abs(o-1)<1e-6?c.style.removeProperty("perspective"):c.style.perspective=`${on(Es,o)}px`,u(c,y)}function u(c,y){let R=y.textureLighting==="dynamic";c.dataset.polycssLighting=y.textureLighting??"baked";let T=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"];if(!R){for(let fe of T)c.style.removeProperty(fe);return}let I=y.directionalLight?.direction??[.4,-.7,.59],D=Math.hypot(I[0],I[1],I[2])||1,z=I[0]/D,G=I[1]/D,te=I[2]/D,q=(0,ee.parseHexColor)(y.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],Q=(0,ee.parseHexColor)(y.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],W=y.directionalLight?.intensity??1,L=y.ambientLight?.intensity??.4,Z=fe=>(fe/255).toFixed(4);c.style.setProperty("--plx",z.toFixed(4)),c.style.setProperty("--ply",G.toFixed(4)),c.style.setProperty("--plz",te.toFixed(4)),c.style.setProperty("--plr",Z(q[0])),c.style.setProperty("--plg",Z(q[1])),c.style.setProperty("--plb",Z(q[2])),c.style.setProperty("--pli",W.toFixed(4)),c.style.setProperty("--par",Z(Q[0])),c.style.setProperty("--pag",Z(Q[1])),c.style.setProperty("--pab",Z(Q[2])),c.style.setProperty("--pai",L.toFixed(4));let F=te,K=Math.sign(F||1)*Math.max(Math.abs(F),.01);c.style.setProperty("--clx",z.toFixed(4)),c.style.setProperty("--cly",G.toFixed(4)),c.style.setProperty("--clz",K.toFixed(4))}function m(c){c.voxelRenderer?.dispose(),c.voxelRenderer=void 0,h(c.rendered,c.disposeAtlas),c.disposeAtlas=void 0,c.rendered.length=0,c.cameraCullGroups.length=0,c.cameraCullSignature="",p(c);for(let y of Array.from(c.wrapper.children))y instanceof HTMLElement&&y.classList.contains("polycss-bucket")&&y.remove()}function d(c){for(let y of Array.from(c.wrapper.childNodes)){if(!(y instanceof HTMLElement))return y;if(y.classList.contains("polycss-bucket")||y.classList.contains("polycss-shadow"))continue;let R=y.tagName.toLowerCase();if(!(R==="b"||R==="i"||R==="s"||R==="u"||R==="q"))return y}return null}function f(c,y,R){R?.parentNode===c.wrapper?c.wrapper.insertBefore(y,R):c.wrapper.appendChild(y)}function g(c){return Array.from(c.children).some(y=>y instanceof HTMLElement&&y.classList.contains("polycss-bucket"))}function p(c){for(let y of c.shadowRendered)y.parentNode&&y.parentNode.removeChild(y);c.shadowRendered.length=0}function h(c,y){y?.();for(let R of c){try{R.dispose()}catch{}R.element.parentNode&&R.element.parentNode.removeChild(R.element)}}function b(c){for(let y of Array.from(c.wrapper.children))y instanceof HTMLElement&&y.classList.contains("polycss-bucket")&&y.remove();for(let y of c.rendered)y.element.parentNode&&y.element.parentNode.removeChild(y.element)}function x(c,y){let R=c.polygons[y.polygonIndex];return c.stableDom&&R?(0,ee.polygonCssSurfaceNormal)(R):y.plan?.normal??(R?(0,ee.polygonCssSurfaceNormal)(R):null)}function A(c){if(!C(c))return c.rendered;let y=M(c);return c.rendered.filter(R=>P(c,R,ee.CAMERA_BACKFACE_CULL_EPS,y))}function M(c){return{rotX:t.rotX??ft,rotY:t.rotY??ht,meshRotation:c.handle.transform.rotation}}function P(c,y,R=ee.CAMERA_BACKFACE_CULL_EPS,T=M(c)){let I=x(c,y);return I===null||(0,ee.normalFacesCamera)(I,T,R)}function E(c){c.cameraCullGroups=(0,ee.cameraCullNormalGroups)(c.rendered.map(y=>x(c,y)))}function k(c){return C(c)?(0,ee.cameraCullVisibleSignature)(c.cameraCullGroups,M(c)):"all"}function C(c){return!c.excludeFromAutoCenter&&(0,ee.isVoxelCameraCullableNormalGroups)(c.cameraCullGroups)}function v(c){c.cameraCullSignature=C(c)?k(c):"all"}function B(c,y){let R=new Array(c.rendered.length),T=!1,I=M(c);for(let W=0;W<c.rendered.length;W+=1){let L=c.rendered[W],Z=P(c,L,y,I);R[W]=Z}let D=null,z=null,G=()=>{if(!(!D||!z)){if(D===z)D.remove();else{let W=s.createRange();W.setStartBefore(D),W.setEndAfter(z),W.deleteContents(),W.detach()}D=null,z=null,T=!0}};for(let W=0;W<c.rendered.length;W+=1){let L=c.rendered[W];!R[W]&&L.element.parentNode===c.wrapper?(z&&z.nextSibling===L.element||(G(),D=L.element),z=L.element):G()}G();let te=W=>{for(let L=W;L<c.rendered.length;L+=1){let Z=c.rendered[L].element;if(Z.parentNode===c.wrapper)return Z}return d(c)},q=-1,Q=W=>{if(q<0)return;let L=s.createDocumentFragment();for(let Z=q;Z<W;Z+=1){let F=c.rendered[Z];S(c,F),L.appendChild(F.element)}f(c,L,te(W)),q=-1,T=!0};for(let W=0;W<c.rendered.length;W+=1){let L=c.rendered[W];R[W]&&L.element.parentNode!==c.wrapper?q<0&&(q=W):Q(W)}return Q(c.rendered.length),T}function N(c,y=!1){if(c.voxelRenderer){c.voxelRenderer.syncCamera(M(c)),c.cameraCullSignature="voxel-direct";return}if(!C(c)){let I=c.cameraCullSignature!=="all";c.cameraCullSignature="all",I&&le(c);return}if(g(c.wrapper)){Y(c,y);return}let R=k(c);if(!y&&R===c.cameraCullSignature)return;let T=B(c,ee.CAMERA_BACKFACE_CULL_EPS);c.cameraCullSignature=R,T&&j(c)}function Y(c,y=!1){let R=C(c)?k(c):"all";!y&&R===c.cameraCullSignature||le(c)}function ne(c,y){return x(c,y)}function S(c,y){if(t.textureLighting!=="dynamic")return;let R=ne(c,y);R&&(y.element.style.setProperty("--pnx",R[0].toFixed(4)),y.element.style.setProperty("--pny",R[1].toFixed(4)),y.element.style.setProperty("--pnz",R[2].toFixed(4)))}function $(c){b(c);let y=s.createDocumentFragment(),R=t.textureLighting==="dynamic"&&!c.stableDom,T=new Map,I=[];for(let D of A(c)){let z=c.polygons[D.polygonIndex],G=R&&z?_s(z):null;if(!G){I.push(D);continue}let te=G.key+"|"+(z.color??""),q=T.get(te);q||(q={vec:G.vec,items:[]},T.set(te,q)),q.items.push(D)}for(let D of I)S(c,D),y.appendChild(D.element);for(let D of T.values()){if(D.items.length<2){for(let G of D.items)S(c,G),y.appendChild(G.element);continue}let z=s.createElement("div");z.className="polycss-bucket",z.style.setProperty("--pnx",String(D.vec[0])),z.style.setProperty("--pny",String(D.vec[1])),z.style.setProperty("--pnz",String(D.vec[2]));for(let G of D.items)z.appendChild(G.element),G.element.style.removeProperty("--pnx"),G.element.style.removeProperty("--pny"),G.element.style.removeProperty("--pnz");y.appendChild(z)}f(c,y,d(c)),v(c)}function w(){return new Promise(c=>setTimeout(c,0))}async function O(c,y){if(t.textureLighting==="dynamic"&&!c.stableDom)return $(c),!y();b(c);let T=s.createDocumentFragment(),I=d(c),D=0;for(let z of A(c)){if(y())return!1;S(c,z),T.appendChild(z.element),D++,D%Ps===0&&(f(c,T,I),T=s.createDocumentFragment(),await w())}return T.childNodes.length>0&&f(c,T,I),v(c),!y()}function H(c,y){let R=t.textureLighting==="dynamic",T=t.directionalLight?.direction,I=y&&(y[0]!==0||y[1]!==0||y[2]!==0);if(!R||!I||!T){if(c.lightOverrideSignature==="clear")return;c.wrapper.style.removeProperty("--plx"),c.wrapper.style.removeProperty("--ply"),c.wrapper.style.removeProperty("--plz"),c.lightOverrideSignature="clear";return}let D=(0,ee.inverseRotateVec3)(T,y),z=Math.hypot(D[0],D[1],D[2])||1,G=(D[0]/z).toFixed(4),te=(D[1]/z).toFixed(4),q=(D[2]/z).toFixed(4),Q=`${G}|${te}|${q}`;c.lightOverrideSignature!==Q&&(c.wrapper.style.setProperty("--plx",G),c.wrapper.style.setProperty("--ply",te),c.wrapper.style.setProperty("--plz",q),c.lightOverrideSignature=Q)}function V(c,y){y.paintColor?c.style.setProperty("--polycss-paint",y.paintColor):c.style.removeProperty("--polycss-paint"),y.dynamicColor?(c.style.setProperty("--psr",(y.dynamicColor.r/255).toFixed(4)),c.style.setProperty("--psg",(y.dynamicColor.g/255).toFixed(4)),c.style.setProperty("--psb",(y.dynamicColor.b/255).toFixed(4))):(c.style.removeProperty("--psr"),c.style.removeProperty("--psg"),c.style.removeProperty("--psb"))}function j(c){if(p(c),!c.castShadow||t.textureLighting!=="dynamic")return;let y=t.shadow?.color??"#000000",R=t.shadow?.opacity??.25,T=(0,ee.parseHexColor)(y)?.rgb??[0,0,0],I=T[0],D=T[1],z=T[2],G=`rgba(${I},${D},${z},${R})`,te=(0,ee.findOverlappingPolygonDuplicates)(c.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.4}),q=s.createDocumentFragment();for(let W of A(c)){if(te.has(W.polygonIndex))continue;let L=W.plan;if(!L)continue;let Z=`matrix3d(${L.matrix})`,F=s.createElement("q");F.className="polycss-shadow",F.style.transform=`var(--shadow-proj) ${Z}`,F.style.color=G,F.style.width=`${L.canvasW}px`,F.style.height=`${L.canvasH}px`,F.style.setProperty("border-shape",Un(L)),F.style.setProperty("--pnx",L.normal[0].toFixed(4)),F.style.setProperty("--pny",L.normal[1].toFixed(4)),F.style.setProperty("--pnz",L.normal[2].toFixed(4)),q.appendChild(F),c.shadowRendered.push(F)}let Q=c.wrapper.firstChild;Q?c.wrapper.insertBefore(q,Q):c.wrapper.appendChild(q)}function le(c){if(c.voxelRenderer){c.voxelRenderer.render(M(c)),c.cameraCullSignature="voxel-direct";return}p(c),$(c),j(c)}function _(c){return!!c.voxelSource&&t.textureLighting!=="dynamic"&&!c.stableDom&&!c.castShadow}function X(c,y){m(c);let R=t.directionalLight,T=y?{...R,direction:y}:R;if(_(c)){let te=no({doc:s,wrapper:c.wrapper,polygons:c.parseResult.polygons,directionalLight:T,ambientLight:t.ambientLight});if(te){c.voxelRenderer=te,te.render(M(c)),c.cameraCullSignature="voxel-direct";return}}let I={doc:s,directionalLight:T,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality,strategies:t.strategies},D=pt(c.polygons,I);V(c.wrapper,D);let z={...I,solidPaintDefaults:D},G=(c.stableDom?en(c.polygons,z):null)??qn(c.polygons,z);c.rendered=G.rendered,c.disposeAtlas=G.dispose,E(c),$(c),j(c)}function U(){if(t.textureLighting!=="dynamic"){i.style.removeProperty("--shadow-ground-cssz");return}let c=1/0;for(let T of l)if(!T.disposed&&T.castShadow)for(let I of T.polygons)for(let D of I.vertices)D[2]<c&&(c=D[2]);if(!Number.isFinite(c)){i.style.removeProperty("--shadow-ground-cssz");return}let y=t.shadow?.lift??.05,R=(c+y)*ke;i.style.setProperty("--shadow-ground-cssz",R.toFixed(3))}async function re(c,y){m(c);let R={doc:s,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality,strategies:t.strategies},T=c.stableDom?en(c.polygons,R):null;if(T){let z=pt(c.polygons,R);return V(c.wrapper,z),c.rendered=T.rendered,c.disposeAtlas=T.dispose,E(c),$(c),j(c),!y()}let I=await Qn(c.polygons,R,y);if(y())return I.dispose(),!1;V(c.wrapper,I.solidPaintDefaults),c.rendered=I.rendered,c.disposeAtlas=I.dispose,E(c);let D=await O(c,y);return D&&j(c),D}function se(){let c=r,y=[0,0,0];if(t.autoCenter){let R=[];for(let T of l)!T.disposed&&!T.excludeFromAutoCenter&&R.push(...T.polygons);if(R.length>0){let T=(0,ee.computeSceneBbox)(R);y=[(T.min[0]+T.max[0])/2,(T.min[1]+T.max[1])/2,(T.min[2]+T.max[2])/2]}}c[0]===y[0]&&c[1]===y[1]&&c[2]===y[2]||(r=y,a(i,t))}function ue(c,y={}){let T=(i.ownerDocument??document).createElement("div");T.className="polycss-mesh",y.id&&T.setAttribute("data-poly-mesh-id",y.id);let I={...y},D=y.merge!==!1,z=!!y.stableDom,G=0,te=so(I);te&&(T.style.transform=te);let q=(F,K)=>K?(0,ee.mergePolygons)(F):F,Q=q(c.polygons,D);function W(F){if(F.length===0){T.style.removeProperty("--origin");return}let K=1/0,fe=1/0,Ae=1/0,Te=-1/0,rt=-1/0,_t=-1/0;for(let ko of F)for(let ve of ko.vertices)ve[0]<K&&(K=ve[0]),ve[0]>Te&&(Te=ve[0]),ve[1]<fe&&(fe=ve[1]),ve[1]>rt&&(rt=ve[1]),ve[2]<Ae&&(Ae=ve[2]),ve[2]>_t&&(_t=ve[2]);if(!Number.isFinite(K)){T.style.removeProperty("--origin");return}let Lo=(fe+rt)/2*ke,_o=(K+Te)/2*ke,Ro=(Ae+_t)/2*ke;T.style.setProperty("--origin",`${Lo}px ${_o}px ${Ro}px`)}W(Q),i.appendChild(T);let L={handle:void 0,wrapper:T,parseResult:c,rendered:[],shadowRendered:[],polygons:Q,voxelSource:c.voxelSource,disposed:!1,stableDom:z,excludeFromAutoCenter:!!y.excludeFromAutoCenter,castShadow:!!y.castShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",bakedRotation:y.rotation?[...y.rotation]:[0,0,0]},Z={polygons:Q,element:T,id:y.id,get transform(){return I},remove(){G++,T.parentNode&&T.parentNode.removeChild(T),m(L),l.delete(L),se(),U()},setPolygons(F,K){G++,D=K?.merge??D,z=K?.stableDom??z,L.stableDom=z,L.voxelSource=void 0,L.polygons=q(F,D),Z.polygons=L.polygons,W(L.polygons);let fe=K?.recomputeAutoCenter??!0;if(L.stableDom&&!g(L.wrapper)){let Ae={doc:s,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality},Te=pt(L.polygons,Ae);if(V(L.wrapper,Te),Jn(L.rendered,L.polygons,{...Ae,solidPaintDefaults:Te})){E(L),N(L,!0),fe&&se();return}}X(L),fe&&se()},updatePolygon(F,K){let fe=typeof F=="number"?F:L.polygons.indexOf(F);fe<0||fe>=L.polygons.length||(L.voxelSource=void 0,Object.assign(L.polygons[fe],K),X(L))},async setPolygonsChunked(F,K){let fe=++G;D=K?.merge??D,z=K?.stableDom??z,L.stableDom=z,L.voxelSource=void 0,L.polygons=q(F,D),Z.polygons=L.polygons,W(L.polygons);let Ae=K?.recomputeAutoCenter??!0;if(!await re(L,()=>L.disposed||fe!==G)){m(L);return}Ae&&se()},setTransform(F){let K=L.castShadow;F.castShadow!==void 0&&(L.castShadow=!!F.castShadow),I={...I,...F};let fe=so(I);T.style.transform=fe??"",H(L,I.rotation),F.rotation!==void 0&&N(L),L.castShadow!==K&&(j(L),U())},dispose(){if(!L.disposed){L.disposed=!0,G++,T.parentNode&&T.parentNode.removeChild(T),m(L);try{c.dispose()}catch{}l.delete(L),se(),U()}},rebakeAtlas(){L.bakedRotation=I.rotation?[...I.rotation]:[0,0,0];let F=t.directionalLight?.direction??[.4,-.7,.59],K=(0,ee.inverseRotateVec3)(F,L.bakedRotation);X(L,K)},getPosition(){return I.position},getRotation(){return I.rotation},getScale(){return I.scale},getPolygons(){return Z.polygons}};return L.handle=Z,l.add(L),X(L),H(L,I.rotation),se(),U(),Z}function he(c){let y=!!t.autoCenter,R=t.strategies,T=t.textureLighting,I=t.rotX??ft,D=t.rotY??ht;t={...t,...c},a(i,t);let z=!!t.autoCenter;for(let Q of l)H(Q,Q.handle.transform.rotation);let G=c.strategies!==void 0&&!Ms(c.strategies,R);if(G)for(let Q of l)X(Q);let te=c.rotX!==void 0&&(t.rotX??ft)!==I||c.rotY!==void 0&&(t.rotY??ht)!==D;if(!G&&te)for(let Q of l)N(Q);if(y!==z&&se(),c.textureLighting!==void 0&&T!==t.textureLighting){for(let Q of l)!G&&(Q.voxelSource||Q.voxelRenderer)?X(Q):j(Q);U()}}function de(){return t}function me(){let c=[];for(let y of l)c.push(y.handle);return c}function ge(c){let y=c;for(;y;){if(y instanceof HTMLElement&&y.classList.contains("polycss-mesh")){for(let R of l)if(R.wrapper===y)return R.handle;return null}y=y.parentElement}return null}function be(){let c=Array.from(l);for(let y of c)try{y.handle.dispose()}catch{}i.parentNode&&i.parentNode.removeChild(i)}return{add:ue,setOptions:he,destroy:be,host:e,getOptions:de,meshes:me,findMeshByElement:ge}}var Rs=typeof HTMLElement<"u"?HTMLElement:class{},ks=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function De(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Ds(e){return e==="false"?!1:De(e)}function Os(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Is(e){if(e==="baked"||e==="dynamic")return e}function Hs(e){return e==="auto"?"auto":De(e)}var xe=class extends Rs{constructor(){super(...arguments);this._scene=null}static get observedAttributes(){return[...ks]}getScene(){return this._scene}_readOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={},s=Ds(this.getAttribute("perspective"));s!==void 0&&(r.perspective=s);let i=De(this.getAttribute("rot-x"));i!==void 0&&(r.rotX=i);let l=De(this.getAttribute("rot-y"));l!==void 0&&(r.rotY=l);let a=De(this.getAttribute("zoom"));a!==void 0&&(r.zoom=a),r.textureLighting=Is(this.getAttribute("texture-lighting"))??"baked";let u=Hs(this.getAttribute("texture-quality"));return u!==void 0&&(r.textureQuality=u),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=Os(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=De(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let s={direction:t??[.4,-.7,.59]};return o&&(s.color=o),r!==void 0&&(s.intensity=r),s}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=De(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){this._scene||(this._scene=io(this,this._readOptions()),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1})))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null)}attributeChangedCallback(t,o,r){o!==r&&this._scene&&this._scene.setOptions(this._readOptions())}};var gt=require("@layoutit/polycss-core"),Vs=typeof HTMLElement<"u"?HTMLElement:class{},zs=["src","mtl","position","scale","rotation","auto-center"];function Ge(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function ao(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Ge(e)}}function Fs(e){return e.closest("poly-scene")??null}function Bs(e){if(e.length===0)return e;let n=(0,gt.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s),...i.textureTriangles?.length?{textureTriangles:i.textureTriangles.map(l=>({...l,vertices:l.vertices.map(s)}))}:null}))}var Oe=class extends Vs{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...zs]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:Ge(this.getAttribute("position")),scale:ao(this.getAttribute("scale")),rotation:Ge(this.getAttribute("rotation"))})}}_tearDown(){if(this._loadToken+=1,this._handle){try{this._handle.dispose()}catch{}this._handle=null}this._parseResult=null}async _maybeLoad(){let t=this.getAttribute("src");if(!t)return;let o=Fs(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,i;try{i=await(0,gt.loadMesh)(t,s?{mtlUrl:s}:void 0)}catch(u){this.dispatchEvent(new CustomEvent("polycss:error",{detail:u,bubbles:!0}));return}if(r!==this._loadToken){try{i.dispose()}catch{}return}let l=o.getScene();if(!l){try{i.dispose()}catch{}return}this.hasAttribute("auto-center")&&(i={...i,polygons:Bs(i.polygons)}),this._parseResult=i,this._handle=l.add(i,{position:Ge(this.getAttribute("position")),scale:ao(this.getAttribute("scale")),rotation:Ge(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var Ns=typeof HTMLElement<"u"?HTMLElement:class{},$s=["vertices","color","texture","uvs","position","scale","rotation"];function lo(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function rn(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Xs(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return rn(e)}}function Ys(e){return e.closest("poly-scene")??null}var We=class extends Ns{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...$s]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=Ys(this);if(!t)return;let o=t.getScene();if(!o)return;let r=lo(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let s=this.getAttribute("color")||void 0,i=this.getAttribute("texture")||void 0,l=lo(this.getAttribute("uvs"))??void 0,a={};for(let d of Array.from(this.attributes))d.name.startsWith("data-")&&(a[d.name.slice(5)]=d.value);let m={polygons:[{vertices:r,...s!==void 0?{color:s}:{},...i!==void 0?{texture:i}:{},...l!==void 0?{uvs:l}:{},...Object.keys(a).length>0?{data:a}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(m,{position:rn(this.getAttribute("position")),scale:Xs(this.getAttribute("scale")),rotation:rn(this.getAttribute("rotation"))})}};var uo=require("@layoutit/polycss-core"),Us=typeof HTMLElement<"u"?HTMLElement:class{},Gs=["size","thickness","negative","x-color","y-color","z-color"];function Ws(e){return e.closest("poly-scene")??null}function co(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var je=class extends Us{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Gs]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&this._handle&&this._remount()}_polygons(){return(0,uo.axesHelperPolygons)({size:co(this.getAttribute("size")),thickness:co(this.getAttribute("thickness")),negative:this.hasAttribute("negative"),xColor:this.getAttribute("x-color")??void 0,yColor:this.getAttribute("y-color")??void 0,zColor:this.getAttribute("z-color")??void 0})}_mount(){let t=Ws(this);if(!t)return;let o=t.getScene();if(!o)return;let r={polygons:this._polygons(),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(r,{excludeFromAutoCenter:!0})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var fo=require("@layoutit/polycss-core"),js=typeof HTMLElement<"u"?HTMLElement:class{},Zs=["direction","target","distance","size","color"],sn=50,qs=5,Qs=.35,Ks="#ffd54a";function Js(e){return e.closest("poly-scene")??null}function mo(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function po(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var Ze=class extends js{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Zs]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="size"||t==="color"){this._remount();return}this._handle.setTransform({position:this._meshPosition()})}}_meshPosition(){let t=mo(this.getAttribute("direction"));if(!t)return;let o=mo(this.getAttribute("target"))??[0,0,0],r=po(this.getAttribute("distance"),qs),s=t[0],i=t[1],l=t[2],a=Math.hypot(s,i,l)||1,u=o[0]+i/a*r,m=o[1]+s/a*r,d=o[2]+l/a*r;return[m*sn,u*sn,d*sn]}_mount(){let t=Js(this);if(!t)return;let o=t.getScene();if(!o)return;let r=po(this.getAttribute("size"),Qs),s=this.getAttribute("color")??Ks,i={polygons:(0,fo.octahedronPolygons)({center:[0,0,0],size:r,color:s}),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(i,{position:this._meshPosition(),excludeFromAutoCenter:!0})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var ho=require("@layoutit/polycss-core");var yt={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Ne(e,n){let t;return n.animate===!1?t=!1:n.animate?t={speed:n.animate.speed??.3,axis:n.animate.axis??"y",pauseOnInteraction:n.animate.pauseOnInteraction??!0}:t=e.animate,{drag:n.drag??e.drag,wheel:n.wheel??e.wheel,dolly:n.dolly??e.dolly,invert:n.invert??e.invert,minZoom:n.minZoom??e.minZoom,maxZoom:n.maxZoom??e.maxZoom,minDistance:n.minDistance??e.minDistance,maxDistance:n.maxDistance??e.maxDistance,animate:t}}function qe(e){return e===!0?-1:e===!1?1:e}function bt(){let e=[],n=[],t=[];function o(i){return i==="change"?e:i==="start"?n:t}function r(i){if(e.length===0)return;let l={type:"change",camera:i()},a=e.slice();for(let u of a)try{u(l)}catch(m){console.error("[polycss] controls 'change' listener threw:",m)}}function s(i,l){let a=i==="start"?n:t;if(a.length===0)return;let u={type:i,camera:l()},m=a.slice();for(let d of m)try{d(u)}catch(f){console.error(`[polycss] controls '${i}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function xt(e){return()=>{let n=e.getOptions(),t=n.target??[0,0,0];return{rotX:n.rotX??0,rotY:n.rotY??0,zoom:n.zoom??1,target:[t[0],t[1],t[2]],distance:n.distance??0}}}function vt(e,n,t,o,r,s){let i=!1,l=null;return{onWheel:m=>{let d=n();if(!d.wheel||t())return;m.preventDefault();let f=m.deltaMode===1?16:m.deltaMode===2?100:1,g=m.deltaY*f;m.ctrlKey?g*=10:g*=3;let p=e.getOptions();if(d.dolly){let h=p.distance??0,b=Math.max(d.minDistance,Math.min(d.maxDistance,h+g*.05));e.setOptions({distance:b})}else{let h=Math.exp(-g*513e-6),b=p.zoom??1,x=Math.max(d.minZoom,Math.min(d.maxZoom,b*h));e.setOptions({zoom:x})}i||(i=!0,s("start",o)),r(o),l!==null&&clearTimeout(l),l=setTimeout(()=>{l=null,i=!1,s("end",o)},150)},teardown:()=>{l!==null&&(clearTimeout(l),l=null),i=!1}}}function Pt(e,n,t,o,r,s,i){let l=null,a=0,u=g=>{if(l===null||o())return;let p=t();if(!p.animate){l=null;return}if(r())a=g;else{let h=Math.min(50,a?g-a:16.67);a=g;let b=p.animate.speed*(h/16.67),x=n.getOptions();if(p.animate.axis==="x"){let A=(((x.rotX??65)+b)%360+360)%360;n.setOptions({rotX:A})}else{let A=(((x.rotY??45)+b)%360+360)%360;n.setOptions({rotY:A})}i(s)}l=e.requestAnimationFrame(u)};return{start:()=>{l!==null||!t().animate||o()||(a=0,l=e.requestAnimationFrame(u))},stop:()=>{l!==null&&(e.cancelAnimationFrame(l),l=null)},isRunning:()=>l!==null}}function go(e,n={}){let t=Ne(yt,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},l=!1,a=!1,u=bt(),m=xt(e),{changeListeners:d,startListeners:f,endListeners:g,listenerArray:p,emitChange:h,emitInteraction:b}=u,x=Pt(r,e,()=>t,()=>a,()=>l,m,h),A=w=>{if(!(!t.drag||a)&&s===null&&w.isPrimary!==!1){w.preventDefault(),s=w.pointerId,i={x:w.clientX,y:w.clientY},o.style.cursor="grabbing";try{w.target.setPointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!0),b("start",m)}},M=w=>{if(s===null||w.pointerId!==s||!t.drag||a)return;w.preventDefault();let O=w.clientX-i.x,H=w.clientY-i.y;i={x:w.clientX,y:w.clientY};let V=qe(t.invert),j=O/4*V,le=H/4*V,_=e.getOptions();if(w.shiftKey){let X=_.rotX??65,U=_.rotY??45,re=Math.max(.01,_.zoom??1),se=Math.cos(X*Math.PI/180),ue=se>=0?Math.max(.1,se):Math.min(-.1,se),he=Math.cos(U*Math.PI/180),de=Math.sin(U*Math.PI/180),me=re*ho.BASE_TILE,ge=(O*de-H*he/ue)/me,be=-(O*he+H*de/ue)/me,c=_.target??[0,0,0];e.setOptions({target:[c[0]+ge,c[1]+be,c[2]]})}else{let X=Math.max(0,Math.min(100,(_.rotX??65)-le)),U=(((_.rotY??45)-j)%360+360)%360;e.setOptions({rotX:X,rotY:U})}h(m)},P=w=>{if(s===w.pointerId){s=null,o.style.cursor=t.drag&&!a?"grab":"";try{w.target.releasePointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!1),b("end",m)}},E=vt(e,()=>t,()=>a,m,h,b);function k(){o.addEventListener("pointerdown",A),o.addEventListener("pointermove",M),o.addEventListener("pointerup",P),o.addEventListener("pointercancel",P),o.addEventListener("wheel",E.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function C(){o.removeEventListener("pointerdown",A),o.removeEventListener("pointermove",M),o.removeEventListener("pointerup",P),o.removeEventListener("pointercancel",P),o.removeEventListener("wheel",E.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",E.teardown()}k(),x.start();function v(w){let O=!!t.animate;t=Ne(t,w),!a&&s===null&&(o.style.cursor=t.drag?"grab":"");let H=!!t.animate;O&&!H?x.stop():!O&&H&&x.start()}function B(){a&&(a=!1,k(),x.start())}function N(){a||(a=!0,C(),x.stop(),s=null,l=!1,E.teardown())}function Y(){N(),d.length=0,f.length=0,g.length=0}function ne(w,O){let H=p(w);H.includes(O)||H.push(O)}function S(w,O){let H=p(w),V=H.indexOf(O);V>=0&&H.splice(V,1)}function $(w,O){return p(w).includes(O)}return{update:v,resume:B,pause:N,destroy:Y,addEventListener:ne,removeEventListener:S,hasEventListener:$}}function ie(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Et(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function we(e){if(e!==null)return!(e==="false"||e==="0")}function At(e){if(e===null)return;if(e==="true")return!0;if(e==="false")return!1;let n=parseFloat(e);return Number.isFinite(n)?n:!0}function Mt(e){if(e==="x"||e==="y")return e}var ei=typeof HTMLElement<"u"?HTMLElement:class{},ti=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Qe=class extends ei{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...ti]}_readAnimate(){let t=ie(this.getAttribute("animate-speed")),o=Mt(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:we(r)}:{}}}_readOptions(){let t={},o=we(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=we(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ie(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ie(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let l=At(this.getAttribute("invert"));l!==void 0&&(t.invert=l);let a=ie(this.getAttribute("zoom-min")),u=ie(this.getAttribute("zoom-max"));return a!==void 0&&(t.minZoom=a),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof xe)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=go(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var yo=require("@layoutit/polycss-core");function bo(e,n={}){let t=Ne(yt,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},l=!1,a=!1,u=!1,m={x:0,y:0},d=bt(),f=xt(e),{changeListeners:g,startListeners:p,endListeners:h,listenerArray:b,emitChange:x,emitInteraction:A}=d,M=Pt(r,e,()=>t,()=>a,()=>l,f,x),P=_=>{if(!(!t.drag||a)&&s===null&&_.isPrimary!==!1){_.preventDefault(),s=_.pointerId,i={x:_.clientX,y:_.clientY},o.style.cursor="grabbing";try{_.target.setPointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!0),A("start",f)}},E=_=>{if(s===null||_.pointerId!==s||!t.drag||a)return;_.preventDefault();let X=_.clientX-i.x,U=_.clientY-i.y;i={x:_.clientX,y:_.clientY};let re=e.getOptions();if(_.shiftKey){let se=qe(t.invert),ue=X/4*se,he=U/4*se,de=Math.max(0,Math.min(100,(re.rotX??65)-he)),me=(((re.rotY??45)-ue)%360+360)%360;e.setOptions({rotX:de,rotY:me})}else{let se=re.rotX??65,ue=re.rotY??45,he=Math.max(.01,re.zoom??1),de=Math.cos(se*Math.PI/180),me=de>=0?Math.max(.1,de):Math.min(-.1,de),ge=Math.cos(ue*Math.PI/180),be=Math.sin(ue*Math.PI/180),c=he*yo.BASE_TILE,y=(X*be-U*ge/me)/c,R=-(X*ge+U*be/me)/c,T=re.target??[0,0,0];e.setOptions({target:[T[0]+y,T[1]+R,T[2]]})}x(f)},k=_=>{if(s===_.pointerId){s=null,o.style.cursor=t.drag&&!a?"grab":"";try{_.target.releasePointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!1),A("end",f)}},C=_=>{_.preventDefault()},v=_=>{_.button===2&&(u=!0,m={x:_.clientX,y:_.clientY},t.animate&&t.animate.pauseOnInteraction&&(l=!0),A("start",f))},B=_=>{if(!u||!t.drag)return;let X=_.clientX-m.x,U=_.clientY-m.y;m={x:_.clientX,y:_.clientY};let re=qe(t.invert),se=X/4*re,ue=U/4*re,he=e.getOptions(),de=Math.max(0,Math.min(100,(he.rotX??65)-ue)),me=(((he.rotY??45)-se)%360+360)%360;e.setOptions({rotX:de,rotY:me}),x(f)},N=_=>{_.button===2&&u&&(u=!1,A("end",f))},Y=vt(e,()=>t,()=>a,f,x,A);function ne(){o.addEventListener("pointerdown",P),o.addEventListener("pointermove",E),o.addEventListener("pointerup",k),o.addEventListener("pointercancel",k),o.addEventListener("wheel",Y.onWheel,{passive:!1}),o.addEventListener("contextmenu",C),o.addEventListener("mousedown",v),o.addEventListener("mousemove",B),o.addEventListener("mouseup",N),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function S(){o.removeEventListener("pointerdown",P),o.removeEventListener("pointermove",E),o.removeEventListener("pointerup",k),o.removeEventListener("pointercancel",k),o.removeEventListener("wheel",Y.onWheel),o.removeEventListener("contextmenu",C),o.removeEventListener("mousedown",v),o.removeEventListener("mousemove",B),o.removeEventListener("mouseup",N),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",Y.teardown()}ne(),M.start();function $(_){let X=!!t.animate;t=Ne(t,_),!a&&s===null&&(o.style.cursor=t.drag?"grab":"");let U=!!t.animate;X&&!U?M.stop():!X&&U&&M.start()}function w(){a&&(a=!1,ne(),M.start())}function O(){a||(a=!0,S(),M.stop(),s=null,l=!1,u=!1,Y.teardown())}function H(){O(),g.length=0,p.length=0,h.length=0}function V(_,X){let U=b(_);U.includes(X)||U.push(X)}function j(_,X){let U=b(_),re=U.indexOf(X);re>=0&&U.splice(re,1)}function le(_,X){return b(_).includes(X)}return{update:$,resume:w,pause:O,destroy:H,addEventListener:V,removeEventListener:j,hasEventListener:le}}var ni=typeof HTMLElement<"u"?HTMLElement:class{},oi=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Ke=class extends ni{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...oi]}_readAnimate(){let t=ie(this.getAttribute("animate-speed")),o=Mt(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:we(r)}:{}}}_readOptions(){let t={},o=we(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=we(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ie(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ie(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let l=At(this.getAttribute("invert"));l!==void 0&&(t.invert=l);let a=ie(this.getAttribute("zoom-min")),u=ie(this.getAttribute("zoom-max"));return a!==void 0&&(t.minZoom=a),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof xe)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=bo(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var an=require("@layoutit/polycss-core"),ri=8e3;function ln(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,an.createIsometricCamera)(n),o=`${e.perspective??ri}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function xo(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,an.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var si=typeof HTMLElement<"u"?HTMLElement:class{},ii=["perspective","zoom","rot-x","rot-y","target","distance"],Je=class extends si{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...ii]}getCamera(){return this._camera}_readOptions(){return{perspective:ie(this.getAttribute("perspective")),zoom:ie(this.getAttribute("zoom")),rotX:ie(this.getAttribute("rot-x")),rotY:ie(this.getAttribute("rot-y")),target:Et(this.getAttribute("target")),distance:ie(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=ln(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let s=this._readOptions();this._camera=ln(s),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var ai=typeof HTMLElement<"u"?HTMLElement:class{},li=["zoom","rot-x","rot-y","target","distance"],et=class extends ai{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...li]}getCamera(){return this._camera}_readOptions(){return{zoom:ie(this.getAttribute("zoom")),rotX:ie(this.getAttribute("rot-x")),rotY:ie(this.getAttribute("rot-y")),target:Et(this.getAttribute("target")),distance:ie(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=xo(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let s=this._readOptions();s.zoom!==void 0&&this._camera.update({zoom:s.zoom}),s.rotX!==void 0&&this._camera.update({rotX:s.rotX}),s.rotY!==void 0&&this._camera.update({rotY:s.rotY}),s.target!==void 0&&this._camera.update({target:s.target}),s.distance!==void 0&&this._camera.update({distance:s.distance})}};var ye=require("@layoutit/polycss-core"),St="#ff3653",wt="#8adb00",Tt="#2c8fff",$e=50,vo=60,ci=.6,ui=.0125,di=.15,mi=.04,pi=1,Po=.02,cn=1.04,fi=.1,hi=.25,Co=1e-4,gi=.6,yi=.8,bi=1,tt={0:1,1:0,2:2},Eo=[{cssAxis:0,sign:1,key:"x",color:St},{cssAxis:0,sign:-1,key:"-x",color:St},{cssAxis:1,sign:1,key:"y",color:wt},{cssAxis:1,sign:-1,key:"-y",color:wt},{cssAxis:2,sign:1,key:"z",color:Tt},{cssAxis:2,sign:-1,key:"-z",color:Tt}],Ao=[{cssAxis:0,key:"x",color:St},{cssAxis:1,key:"y",color:wt},{cssAxis:2,key:"z",color:Tt}],Mo=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:Tt},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:wt},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:St}];function un(e,n,t,o){let r=t*Math.PI/180,s=o*Math.PI/180,i=[0,0,0];i[e]=n;let l=i[0]*Math.cos(s)-i[1]*Math.sin(s),a=i[0]*Math.sin(s)+i[1]*Math.cos(s),u=i[2];return a*Math.sin(r)+u*Math.cos(r)<0}function xi(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),s=parseInt(t[3],16);return`rgba(${o}, ${r}, ${s}, ${n})`}function Lt(e,n){return!n||n<=0?e:Math.round(e/n)*n}function vi(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let a of l.vertices)a[0]<n&&(n=a[0]),a[0]>r&&(r=a[0]),a[1]<t&&(t=a[1]),a[1]>s&&(s=a[1]),a[2]<o&&(o=a[2]),a[2]>i&&(i=a[2]);return Number.isFinite(n)?[(t+s)/2*$e,(n+r)/2*$e,(o+i)/2*$e]:[0,0,0]}function dn(e){if(e.length===0)return vo;let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let a of e)for(let u of a.vertices)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*$e*ci:vo}function Ct(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function Pi(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:l,translationSnap:a,onAxisDelta:u,onMouseDown:m,onMouseUp:d,onDraggingChanged:f}=e,g=o,p=[0,0,0];p[n]=t;let h=r.ownerDocument.createElement("div");h.style.position="absolute",h.style.left="0",h.style.top="0",h.style.width="0",h.style.height="0",h.style.transform=`translate3d(${p[0]*g}px, ${p[1]*g}px, ${p[2]*g}px)`,r.appendChild(h);let b=r.getBoundingClientRect(),x=h.getBoundingClientRect();r.removeChild(h);let A=(x.left-b.left)/g,M=(x.top-b.top)/g,P=A*A+M*M;if(P<Co)return;m?.(),f?.(!0);let E=C=>{let v=C.clientX-i,B=C.clientY-l,N=(v*A+B*M)/P;N=Lt(N,a),u(N,p)},k=()=>{window.removeEventListener("pointermove",E),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k);let C=v=>{v.stopPropagation(),v.stopImmediatePropagation()};window.addEventListener("click",C,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",C,!0),0),d?.(),f?.(!1)};window.addEventListener("pointermove",E),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)}function Ei(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:s,startClientY:i,translationSnap:l,onPlaneDelta:a,onMouseDown:u,onMouseUp:m,onDraggingChanged:d}=e,f=[0,0,0];f[n]=1;let g=[0,0,0];g[t]=1;function p(P){let E=r.ownerDocument.createElement("div");E.style.position="absolute",E.style.left="0",E.style.top="0",E.style.width="0",E.style.height="0",E.style.transform=`translate3d(${P[0]*o}px, ${P[1]*o}px, ${P[2]*o}px)`,r.appendChild(E);let k=r.getBoundingClientRect(),C=E.getBoundingClientRect();return r.removeChild(E),{x:(C.left-k.left)/o,y:(C.top-k.top)/o}}let h=p(f),b=p(g),x=h.x*b.y-b.x*h.y;if(Math.abs(x)<Co)return;u?.(),d?.(!0);let A=P=>{let E=P.clientX-s,k=P.clientY-i,C=(b.y*E-b.x*k)/x,v=(-h.y*E+h.x*k)/x;C=Lt(C,l),v=Lt(v,l),a(C,v,f,g)},M=()=>{window.removeEventListener("pointermove",A),window.removeEventListener("pointerup",M),window.removeEventListener("pointercancel",M);let P=E=>{E.stopPropagation(),E.stopImmediatePropagation()};window.addEventListener("click",P,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",P,!0),0),m?.(),d?.(!1)};window.addEventListener("pointermove",A),window.addEventListener("pointerup",M),window.addEventListener("pointercancel",M)}function Ai(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:l,onMouseDown:a,onMouseUp:u,onDraggingChanged:m}=e,d=t.getBoundingClientRect(),f=d.left,g=d.top,p=Math.atan2(s-g,r-f),h=0;a?.(),m?.(!0);let b=A=>{let M=Math.atan2(A.clientY-g,A.clientX-f),P=M-p;P>Math.PI?P-=2*Math.PI:P<-Math.PI&&(P+=2*Math.PI),h+=P,p=M;let E=h*180/Math.PI;E=Lt(E,i),l(E)},x=()=>{window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x);let A=M=>{M.stopPropagation(),M.stopImmediatePropagation()};window.addEventListener("click",A,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",A,!0),0),u?.(),m?.(!1)};window.addEventListener("pointermove",b),window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x)}function So(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,l=null,a=null,u=[0,0,0];function m(){if(!t)return[0,0,0];let S=t.transform.position??[0,0,0];return[S[0]+u[0],S[1]+u[1],S[2]+u[2]]}function d(S){return a===S?bi:l===S?yi:gi}function f(){for(let[S,$]of i){let w=g($.spec,d(S));$.handle.setPolygons(w,{recomputeAutoCenter:!1})}}function g(S,$){let O=dn(t?.polygons??[])*r,H=O/$e,V=xi(S.color,$);if(S.kind==="arrow"){let _=e.getOptions(),X=un(S.cssAxis,S.sign,_.rotX??65,_.rotY??45);return(0,ye.arrowPolygons)({axis:tt[S.cssAxis],sign:S.sign,shaftLength:H,shaftHalfThickness:H*ui,headLength:H*di,headHalfThickness:H*mi,color:V,shaft:!X})}if(S.kind==="plane"){let _=e.getOptions(),X=_.rotX??65,U=_.rotY??45,re=tt[S.perpAxis],se=(re+1)%3,ue=(re+2)%3,he=tt[se],de=tt[ue],me=un(he,1,X,U)?-1:1,ge=un(de,1,X,U)?-1:1,be=H*hi;return(0,ye.planePolygons)({axis:re,size:H*fi,offset:[me*be,ge*be],color:V})}let le=O*pi/$e*cn;return(0,ye.ringQuadPolygons)({axis:tt[S.cssAxis],outerRadius:le,color:V})}function p(S){return S.kind==="arrow"?"polycss-transform-arrow":S.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function h(){if(o==="translate"){let S=Eo.map(w=>({kind:"arrow",key:w.key,cssAxis:w.cssAxis,sign:w.sign,color:w.color})),$=Mo.map(w=>({kind:"plane",key:w.key,perpAxis:w.perpAxis,axisA:w.axisA,axisB:w.axisB,color:w.color}));return[...S,...$]}return o==="rotate"?Ao.map(S=>({kind:"ring",key:S.key,cssAxis:S.cssAxis,color:S.color})):[]}function b(){if(x(),!t)return;let S={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};function $(O){if(O.kind==="arrow"){let j=O.key.replace("-","")[0];return S[j]}if(O.kind==="ring")return S[O.key];let H=["x","y","z"][O.axisA],V=["x","y","z"][O.axisB];return S[H]&&S[V]}let w=m();for(let O of h()){if(!$(O))continue;let H=g(O,d(O.key)),V=e.add({polygons:H,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${O.key}`,position:w}),j=p(O);if(V.element.classList.add("polycss-transform-gizmo",j,`${j}--${O.key}`),O.kind==="ring"){let le=(1-Po)/cn,_=(1+Po)/cn;V.element.style.setProperty("--ring-inner-ratio",`${le}`),V.element.style.setProperty("--ring-outer-ratio",`${_}`)}i.set(O.key,{handle:V,spec:O})}}function x(){for(let{handle:S}of i.values())S.remove();i.clear(),l=null,a=null}function A(){if(!t)return;let S=m();for(let{handle:$}of i.values())$.setTransform({position:S})}function M(){t&&(i.size===0?b():A())}function P(S){if(t=S,!S){u=[0,0,0],x();return}u=vi(S.polygons),x(),b()}function E(){P(null)}function k(S){S!==o&&(o=S,t&&(x(),b()))}function C(S,$,w){if(!t||!v)return;let O=[v[0]+$*w[0],v[1]+$*w[1],v[2]+$*w[2]];t.setTransform({position:O}),A(),s.onObjectChange?.({object:t,position:O}),s.onChange?.()}let v=null,B=null,N=S=>{if(!t||s.enabled===!1)return;let $={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate"){for(let w of Mo){let O=["x","y","z"][w.axisA],H=["x","y","z"][w.axisB];if(!$[O]||!$[H])continue;let V=i.get(w.key);if(V&&Ct(V.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),a=w.key,f(),v=(t.transform.position??[0,0,0]).slice(),Ei({axisA:w.axisA,axisB:w.axisB,probeDistanceCss:dn(t.polygons)*r,wrapper:V.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,translationSnap:s.translationSnap??null,onPlaneDelta:(j,le,_,X)=>{if(!t||!v)return;let U=[v[0]+j*_[0]+le*X[0],v[1]+j*_[1]+le*X[1],v[2]+j*_[2]+le*X[2]];t.setTransform({position:U}),A(),s.onObjectChange?.({object:t,position:U}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:j=>{j||(a=null,v=null,f()),s.onDraggingChanged?.(j)}});return}}for(let w of Eo){let O=w.key.replace("-","")[0];if(!$[O])continue;let H=i.get(w.key);if(H&&Ct(H.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),a=w.key,f(),v=(t.transform.position??[0,0,0]).slice(),Pi({cssAxis:w.cssAxis,sign:w.sign,shaftLengthCss:dn(t.polygons)*r,wrapper:H.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(V,j)=>C(w,V,j),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:V=>{V||(a=null,v=null,f()),s.onDraggingChanged?.(V)}});return}}}else if(o==="rotate")for(let w of Ao){if(!$[w.key])continue;let O=i.get(w.key);if(O&&Ct(O.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),a=w.key,f(),B=(t.transform.rotation??[0,0,0]).slice(),Ai({cssAxis:w.cssAxis,wrapper:O.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:H=>{if(!t||!B)return;let V=w.cssAxis===0?-1:1,j=[0,0,0];j[w.cssAxis]=1;let le=H*V*Math.PI/180,_=(0,ye.quatFromEulerXYZ)(B),X=(0,ye.quatFromAxisAngle)(j,le),U=(0,ye.eulerXYZFromQuat)((0,ye.quatMultiply)(X,_));t.setTransform({rotation:U}),s.onObjectChange?.({object:t,rotation:U}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:H=>{H||(a=null,B=null,f(),t?.rebakeAtlas()),s.onDraggingChanged?.(H)}});return}}};e.host.addEventListener("pointerdown",N,{capture:!0});let Y=S=>{if(!t||a||s.enabled===!1)return;let $=null;for(let[w,O]of i)if(Ct(O.handle.element,S.clientX,S.clientY)){$=w;break}$!==l&&(l=$,f())};e.host.addEventListener("pointermove",Y);function ne(){e.host.removeEventListener("pointerdown",N,{capture:!0}),e.host.removeEventListener("pointermove",Y),x()}return{attach:P,detach:E,setMode:k,update:M,destroy:ne}}var Mi=typeof HTMLElement<"u"?HTMLElement:class{},Ci=["mode","target","size","enabled"];function wo(e){if(e==="translate"||e==="rotate")return e}var nt=class extends Mi{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Ci]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof xe)return t;t=t.parentNode}return null}_findTargetMesh(){let t=this.getAttribute("target");if(!t)return null;let o=this._findScene();if(!o)return null;let r=null;try{r=o.querySelector(`#${t}`)??o.querySelector(t)}catch{r=o.querySelector(`[id="${t}"]`)}return r instanceof Oe?r:null}_readOptions(){let t={},o=wo(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=ie(this.getAttribute("size"));r!==void 0&&(t.size=r);let s=this.getAttribute("enabled");return s!==null&&(t.enabled=s!=="false"&&s!=="0"),t.onObjectChange=i=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:i.position,rotation:i.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let s=()=>{t.removeEventListener("polycss:scene-ready",s),this._attach()};t.addEventListener("polycss:scene-ready",s)}return}this._tc=So(o,this._readOptions());let r=this._findTargetMesh();if(r){let s=r.getMeshHandle();s&&this._tc.attach(s)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,r){if(o!==r&&this._tc){if(t==="mode"){let s=wo(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};function Si(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function To(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let h of o)try{h(t)}catch(b){console.error("[polycss/createSelect] onChange threw:",b)}}function s(p){t=p,r()}function i(p){n.multiple?t.includes(p)||(t=[...t,p]):t=[p],r()}function l(p){t.includes(p)&&(t=t.filter(h=>h!==p),r())}function a(p){t.includes(p)?t=t.filter(h=>h!==p):n.multiple?t=[...t,p]:t=[p],r()}function u(){t.length!==0&&(t=[],r())}function m(p){return t.includes(p)}function d(p,h){for(let b of e.meshes())if(!b.element.classList.contains("polycss-transform-gizmo")&&Si(b.element,p,h))return b;return null}let f=p=>{let h=p.target;if(h?.closest(".polycss-transform-gizmo"))return;let b=e.findMeshByElement(h)??d(p.clientX,p.clientY);if(!b){n.onPointerMissed&&n.onPointerMissed(p),n.clearOnMiss!==!1&&u();return}n.multiple&&(p.shiftKey||p.metaKey||p.ctrlKey)?a(b):t.length===1&&t[0]===b?u():s([b])};e.host.addEventListener("click",f);function g(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:s,add:i,remove:l,toggle:a,clear:u,has:m,destroy:g}}var wi=typeof HTMLElement<"u"?HTMLElement:class{},Ti=["multiple","clear-on-miss"],ot=class extends wi{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Ti]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof xe)return t;t=t.parentNode}return null}_readOptions(){return{multiple:this.hasAttribute("multiple"),clearOnMiss:!this.hasAttribute("clear-on-miss")||this.getAttribute("clear-on-miss")!=="false",onChange:t=>{this.dispatchEvent(new CustomEvent("polycss:select",{bubbles:!0,detail:{selected:t}}))}}}_attach(){if(this._selection)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._selection=To(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};typeof customElements<"u"&&(customElements.get("poly-scene")||customElements.define("poly-scene",xe),customElements.get("poly-mesh")||customElements.define("poly-mesh",Oe),customElements.get("poly-polygon")||customElements.define("poly-polygon",We),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",je),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",Ze),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",Qe),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",Ke),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",Je),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",et),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",nt),customElements.get("poly-select")||customElements.define("poly-select",ot));0&&(module.exports={PolyAxesHelperElement,PolyDirectionalLightHelperElement,PolyMapControlsElement,PolyMeshElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPolygonElement,PolySceneElement,PolySelectElement,PolyTransformControlsElement});