@layoutit/polycss 0.0.1

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.
@@ -0,0 +1,234 @@
1
+ import{BASE_TILE as no,computeSceneBbox as oo,inverseRotateVec3 as St,mergePolygons as ro,parseHexColor as wt}from"@layoutit/polycss-core";import{parsePureColor as st}from"@layoutit/polycss-core";var Ye=50,it=[.4,-.7,.59],at="#ffffff",lt=1,ct="#ffffff",ut=.4,ce=4096,tt=1,Kt=.1,Jt=1,dt=ce*ce,Qt=dt*3,Fe=2048,Ne=16*1024*1024,en=.995,ae=new Map,Xe=new WeakMap,B=.001,K=1e-9,tn=1e-4,nn=.1,on=.75,rn=0,sn=.45,an=3,ln=2;function cn(e){let n=ae.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}),ae.set(e,n),n.then(()=>{ae.get(e)===n&&ae.delete(e)},()=>{ae.get(e)===n&&ae.delete(e)})),n}function xe(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Jt,Math.max(Kt,n))}function pt(e,n){let t=e.toFixed(n).replace(/\.?0+$/,"");return Object.is(Number(t),-0)?"0":t}function mt(e,n=an){return e.map(t=>pt(t,n)).join(",")}function ge(e,n=ln){return`${pt(e,n)}%`}function ft(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function un(e){let n=ft(e);if(n<=0)return 1;let t=Math.max(1,...e.map(s=>Math.max(s.width,s.height))),o=Fe/t,r=Math.sqrt(Ne/(n*4));return xe(Math.min(o,r))}function dn(e){let n=ft(e),t=.5;return n<=dt?t=1:n<=Qt&&(t=.75),xe(Math.min(t,un(e)))}function pn(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function mn(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function fn(e,n){let t=pn(e,n),o=mn(e,n),r=t>Fe?Fe/t:1,s=o>Ne?Math.sqrt(Ne/o):1;return Math.min(r,s)}function hn(e,n){let t=dn(n.pages),o=t===1?n:ve(e,t);for(let r=0;r<4;r++){let s=fn(o.pages,t);if(s>=1)break;let i=xe(t*s*en);if(i>=t)break;t=i,o=ve(e,t)}return{packed:o,atlasScale:t}}function yn(e,n){if(n!==void 0&&n!=="auto"){let o=xe(n);return{packed:ve(e,o),atlasScale:o}}let t=ve(e,1);return hn(e,t)}function gn(e){return Math.max(tt,Math.ceil(tt/e))}function J(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 oe(e){let n=st(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function bn(e){return st(e)?.alpha??1}function vn({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 ht(e,n,t,o,r){let s=oe(e),i=oe(t),c=oe(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=bn(e);return u<1?`rgba(${m}, ${f}, ${h}, ${u})`:vn({r:m,g:f,b:h})}function xn(e,n,t,o){let r=oe(n),s=oe(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 Pn({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 En(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(),J(e,i),e.globalCompositeOperation="multiply",e.fillStyle=Pn(s),e.fillRect(n,t,o,r),e.restore())}function An(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;J(e,i),e.drawImage(n,t+(r-d)/2,o+(s-m)/2,d,m)}function be(e){return`${e[0]},${e[1]},${e[2]}`}function Mn(e,n){let t=be(e),o=be(n);return t<o?`${t}|${o}`:`${o}|${t}`}function yt(e,n){return be(e)<be(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 Cn(e){return!e.texture}function Pe(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function $e(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<=K?null:(i/=a,c/=a,l/=a,[i,c,l])}function ue(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Tn(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 Ln(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=Pe(e.vertices,n,t),r=$e(o);return r?{pts:o,normal:r,planeD:ue(r,o[0]),optimizable:Cn(e)}:null}function _n(e,n){return!e||!n||!e.optimizable||!n.optimizable||ue(e.normal,n.normal)<1-tn?!1:Math.abs(e.planeD-n.planeD)<=nn}function Sn(e){let n=[...e],t=Math.abs(n[0])>K?0:Math.abs(n[1])>K?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 fe(e,n,t,o,r={}){let s=ue(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<=K)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<=K)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 wn(e,n,t,o){let r=0,s=0;for(let i of e){let c=n[i];if(!c)return null;let l=fe(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 kn(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=fe(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=yt(c.pts[d],c.pts[(d+1)%c.pts.length]),f=fe(c.pts,c.pts[0],c.normal,m);if(!f)continue;let h=Sn(f.xAxis);if(s.has(h))continue;s.add(h);let u=wn(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 On(e,n){let t=n.tileSize??Ye,o=n.layerElevation??t,r=e.map(d=>Ln(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=Mn(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;_n(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=kn(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 Hn(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 nt(e,n,t,o){if(o.optimize&&o.fixedXAxis)return fe(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?yt(e[c],e[l]):[e[l][0]-e[c][0],e[l][1]-e[c][1],e[l][2]-e[c][2]],d=fe(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 Dn(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 gt(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 bt(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 Rn(e,n,t,o,r,s,i,c){let a=Pe(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=gt(a,e.uvs),m=bt(e.uvs);return!d&&!m?null:{screenPts:a.flatMap(([f,h])=>[f,h]),uvAffine:d,uvSampleRect:m}}function In(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 Vn(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 Ue(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 zn(e,n,t,o,r,s){if(Ue(e,n,t,o),!r||r.size===0||s<=0)return;let i=o.length/2,c=Vn(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 Bn(e,n,t,o){let{vertices:r,texture:s,uvs:i}=e;if(!r||r.length<3)return null;let c=t.tileSize??Ye,l=t.layerElevation??c,a=Pe(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=$e(a);if(!u)return null;let p=nt(a,d,u,{optimize:!1}),b=s||p&&Dn(p)?p:nt(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],_=mt([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??it,R=v?.color??at,E=Math.max(0,v?.intensity??lt),P=k?.color??ct,D=Math.max(0,k?.intensity??ut),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=xn(I,R,P,D),X=ht(e.color??"#cccccc",I,R,P,D),$=null,U=null;s&&i&&i.length>=3&&i.length===r.length&&(U=bt(i),$=gt(C.map(([Y,z])=>[Y+H,z+y]),i));let W=s&&e.textureTriangles?.length?e.textureTriangles.map(Y=>Rn(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 vt(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??Ye,r=t.layerElevation??o,s=Pe(e.vertices,o,r),i=$e(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(q=>{let j=s[q.a],te=s[q.b];return{...q,length:Math.hypot(te[0]-j[0],te[1]-j[1],te[2]-j[2])}}).sort((q,j)=>j.length-q.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<=K)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=ue(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<=K)return null;let y=[C[0]/H,C[1]/H,C[2]/H];if(ue(Tn(p,y),i)<0){let q=a;if(a=l,l=q,m=s[l],f=s[a],u=Math.hypot(f[0]-m[0],f[1]-m[1],f[2]-m[2]),u<=K)return null;p=[(f[0]-m[0])/u,(f[1]-m[1])/u,(f[2]-m[2])/u];let j=[h[0]-m[0],h[1]-m[1],h[2]-m[2]];x=ue(j,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 te=Math.hypot(C[0],C[1],C[2]);if(te<=K)return null;y=[C[0]/te,C[1]/te,C[2]/te]}let g=Math.max(0,Math.min(u,x)),S=Math.max(0,u-g),A=sn,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=mt([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??it,F=P?.color??at,Z=Math.max(0,P?.intensity??lt),L=D?.color??ct,I=Math.max(0,D?.intensity??ut),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=ht(e.color??"#cccccc",W,F,L,I),z=t.textureLighting??"baked",Q=oe(e.color??"#cccccc"),ie=z==="dynamic"?"":`border-bottom-color:${Y};`,ee=z==="dynamic"?`--pnx:${i[0].toFixed(4)};--pny:${i[1].toFixed(4)};--pnz:${i[2].toFixed(4)};--psr:${(Q.r/255).toFixed(4)};--psg:${(Q.g/255).toFixed(4)};--psb:${(Q.b/255).toFixed(4)};`:"",Be=`transform:matrix3d(${E});border-width:0 ${_}px ${v}px ${w}px;`+ie+ee;return{index:n,polygon:e,styleText:Be}}function ve(e,n=1){let t=Array(e.length).fill(null),o=[],r=gn(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<=ce){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>ce)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>ce||l.canvasH+r*2>ce){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 Fn(e,n,t,o){J(e,o),e.beginPath(),Ue(e,n.x,n.y,n.screenPts),e.clip(),J(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function le(e,n){return Math.max(0,Math.min(n,e))}function ot(e,n,t,o,r,s,i,c){let l=n.naturalWidth||n.width||1,a=n.naturalHeight||n.height||1,d=le(Math.min(t.minU,t.maxU)*l,l),m=le(Math.max(t.minU,t.maxU)*l,l),f=le(Math.min(t.minV,t.maxV)*a,a),h=le(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(le((t.minU+t.maxU)/2*l,l-1)),b=1),x<1&&(p=Math.floor(le((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)),J(e,c),e.drawImage(n,u,p,b,x,o,r,s,i)}async function Nn(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 cn(a))}));for(let a of e.entries){let d=a.texture?c.get(a.texture):null;if(s.save(),J(s,o),s.beginPath(),a.texture?zn(s,a.x,a.y,a.screenPts,a.seamEdges,rn):Ue(s,a.x,a.y,a.screenPts),s.clip(),!a.texture)Fn(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=In(h.screenPts,on);s.save(),J(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?(J(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&&ot(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;J(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?ot(s,d,a.uvSampleRect,a.x,a.y,a.canvasW,a.canvasH,o):d&&An(s,d,a.x,a.y,a.canvasW,a.canvasH,o);a.texture&&n==="baked"&&En(s,a.x,a.y,a.canvasW,a.canvasH,a.textureTint,o),s.restore()}let l=await Hn(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:l}}async function Xn(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await Nn(i,n,t,o))}return s}function Yn(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 We(e,n){let t=Xe.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);Xe.set(e,o)}function Ze(e,n){e.style.width=`${n.canvasW}px`,e.style.height=`${n.canvasH}px`,e.style.transform=`matrix3d(${n.matrix})`,We(e,n.polygon)}function xt(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 $n(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 rt(e){return!!$n(e)}function Un(e){return!e.texture&&e.polygon.vertices.length===3}function Wn(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 Zn(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(`${ge(s)} ${ge(i)}`)}return`polygon(${n.join(", ")})`}function Gn(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=ge(Math.max(0,Math.min(100,n/o/r*100))),c=ge(Math.max(0,Math.min(100,t/o/s*100)));return`polygon(${Array.from({length:o},()=>`${i} ${c}`).join(", ")})`}function jn(e){return`${Zn(e)} ${Gn(e)}`}function qn(e,n,t){if(t==="dynamic"){xt(e,n);let o=oe(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 Kn(e,n,t){let o=t.createElement("b");return Ze(o,e),qn(o,e,n),o}function Jn(e,n){let t=n.createElement("i");return Ze(t,e),t.style.color=e.shadedColor,t.style.setProperty("border-shape",jn(e)),t}function Qn(e,n,t){let o=t.createElement("s");return Ze(o,e),o.style.backgroundPosition=`-${e.x}px -${e.y}px`,o.style.opacity="0",n==="dynamic"&&xt(o,e),o}function Pt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=o!=="dynamic"&&Wn(t),s=On(e,n),i=e.map((p,b)=>Bn(p,b,n,s[b])),c=i.map(p=>p&&Un(p)?vt(p.polygon,p.index,n):null),l=i.map((p,b)=>p&&(p.texture||!rt(p)&&!c[b]&&!r?p:null)),{packed:a,atlasScale:d}=yn(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=Qn(M,o,t);m.set(p,C),f.push({polygonIndex:p,element:C,kind:"atlas",dispose:()=>{}})}else if(!b.texture&&rt(b)){let C=Kn(b,o,t);f.push({polygonIndex:p,element:C,kind:"solid",dispose:()=>{}})}else if(!b.texture&&x){let C=Mt(x,t);f.push({polygonIndex:p,element:C,kind:"triangle",dispose:()=>{}})}else if(!b.texture&&r){let C=Jn(b,t);f.push({polygonIndex:p,element:C,kind:"border",dispose:()=>{}})}}return f.sort((p,b)=>p.polygonIndex-b.polygonIndex),Xn(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||(Yn(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 Et(e,n){let t=e.map((o,r)=>vt(o,r,n));return t.some(o=>!o)?null:t}function eo(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 At(e,n){e.style.cssText=n.styleText,(n.polygon.data||Xe.get(e)?.length)&&We(e,n.polygon)}function Mt(e,n){let t=n.createElement("u");return eo(t),At(t,e),We(t,e.polygon),t}function Ct(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=Et(e,n);if(!o)return null;let r=[];for(let s of o){let i=Mt(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 Tt(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=Et(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++)At(e[s].element,r[s]);return{rendered:e,dispose(){}}}var Lt="polycss-styles";function _t(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(Lt))return;let t=n.createElement("style");t.id=Lt,t.textContent=to,n.head.appendChild(t)}var to=`
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
+
4
+ .polycss-scene,
5
+ .polycss-scene *,
6
+ .polycss-scene *::before,
7
+ .polycss-scene *::after {
8
+ box-sizing: border-box;
9
+ }
10
+
11
+ .polycss-scene {
12
+ position: absolute;
13
+ top: 50%;
14
+ left: 50%;
15
+ width: 0;
16
+ height: 0;
17
+ transform-style: preserve-3d;
18
+ perspective: none;
19
+ transform: var(--scene-transform);
20
+ }
21
+
22
+ .polycss-offset {
23
+ transform-style: preserve-3d;
24
+ transform: var(--offset-transform);
25
+ }
26
+
27
+ /* \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 */
28
+
29
+ .polycss-mesh {
30
+ position: absolute;
31
+ transform-style: preserve-3d;
32
+ transform-origin: var(--origin);
33
+ }
34
+
35
+ /* \u2500\u2500 Polygon leaf element \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 */
36
+
37
+ .polycss-scene b,
38
+ .polycss-scene i,
39
+ .polycss-scene s,
40
+ .polycss-scene u {
41
+ position: absolute;
42
+ display: block;
43
+ transform-origin: 0 0;
44
+ transform-style: preserve-3d;
45
+ margin: 0;
46
+ padding: 0;
47
+ font: inherit;
48
+ font-weight: normal;
49
+ font-style: normal;
50
+ line-height: 0;
51
+ text-decoration: none;
52
+ backface-visibility: hidden;
53
+ background-repeat: no-repeat;
54
+ }
55
+
56
+ .polycss-scene b {
57
+ }
58
+
59
+ .polycss-scene i {
60
+ border-color: currentColor;
61
+ }
62
+
63
+ .polycss-scene s {
64
+ }
65
+
66
+ .polycss-scene u {
67
+ width: 0px;
68
+ height: 0px;
69
+ background: transparent;
70
+ box-sizing: content-box;
71
+ border: 0 solid transparent;
72
+ }
73
+
74
+ /* \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 */
75
+
76
+ /*
77
+ * Translate arrows + rotate rings render through the same polygon
78
+ * pipeline as user content but the gizmo is a UI affordance \u2014 both
79
+ * faces of every polygon should remain visible regardless of camera
80
+ * 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.
83
+ */
84
+ .polycss-mesh.polycss-transform-gizmo i,
85
+ .polycss-mesh.polycss-transform-gizmo b,
86
+ .polycss-mesh.polycss-transform-gizmo s,
87
+ .polycss-mesh.polycss-transform-gizmo u {
88
+ backface-visibility: visible;
89
+ transition: border-color 150ms ease-out, background-color 150ms ease-out;
90
+ }
91
+
92
+ /* \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 */
93
+
94
+ /*
95
+ * Dynamic mode: the scene root carries the directional + ambient light
96
+ * setup as custom properties. Each polygon leaf bakes its own normal
97
+ * directly into an inline calc() that reads these vars to resolve the
98
+ * Lambert dot product and per-channel tint. Sliding the light only
99
+ * writes these scene-root vars \u2014 no JS, no atlas redraw.
100
+ *
101
+ * Registering with @property forces the browser to parse the values as
102
+ * <number>s instead of opaque token streams; that makes the polygon-level
103
+ * calc() expressions resolve reliably across engines.
104
+ */
105
+
106
+ @property --plx { syntax: "<number>"; inherits: true; initial-value: 0; }
107
+ @property --ply { syntax: "<number>"; inherits: true; initial-value: 0; }
108
+ @property --plz { syntax: "<number>"; inherits: true; initial-value: 1; }
109
+ @property --plr { syntax: "<number>"; inherits: true; initial-value: 1; }
110
+ @property --plg { syntax: "<number>"; inherits: true; initial-value: 1; }
111
+ @property --plb { syntax: "<number>"; inherits: true; initial-value: 1; }
112
+ @property --pli { syntax: "<number>"; inherits: true; initial-value: 1; }
113
+ @property --par { syntax: "<number>"; inherits: true; initial-value: 1; }
114
+ @property --pag { syntax: "<number>"; inherits: true; initial-value: 1; }
115
+ @property --pab { syntax: "<number>"; inherits: true; initial-value: 1; }
116
+ @property --pai { syntax: "<number>"; inherits: true; initial-value: 0.4; }
117
+
118
+ /* Per-polygon surface normal \u2014 set inline by the renderer per leaf, OR by
119
+ a .polycss-bucket wrapper that groups axis-aligned polys sharing the
120
+ same face direction. inherits:true so polys inside a bucket pick up
121
+ the wrapper's normal automatically; polys outside any bucket still
122
+ override it inline. */
123
+ @property --pnx { syntax: "<number>"; inherits: true; initial-value: 0; }
124
+ @property --pny { syntax: "<number>"; inherits: true; initial-value: 0; }
125
+ @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; }
129
+
130
+ /* Hoisted Lambert dot product \u2014 computed once per element it's set on.
131
+ inherits:true so a bucket wrapper computes lambert ONCE for its whole
132
+ group (one calc per bucket, not per polygon). Solo polys still set it
133
+ themselves via the per-poly rule below. */
134
+ @property --plam { syntax: "<number>"; inherits: true; initial-value: 0; }
135
+
136
+ /* Calc-driven Lambert + tint, scoped to dynamic-lighting scenes. Lives
137
+ here (not inline per polygon) so each leaf only carries its tiny normal
138
+ declarations \u2014 ~12\xD7 smaller per-polygon style payload on big meshes.
139
+ --plam is computed once and reused 3\xD7 (one per channel),
140
+ cutting the dot-product calc count from 3 \u2192 1 per polygon per frame. */
141
+ /* Lambert-bucket wrapper: createPolyScene groups axis-aligned polys
142
+ sharing one face direction inside a .polycss-bucket div with the
143
+ bucket's normal as inline CSS vars. Lambert is computed ONCE per
144
+ bucket (inherits:true on --plam propagates the value to
145
+ every leaf child). For voxel meshes this collapses thousands of
146
+ per-frame dot products into a few dozen. */
147
+ .polycss-bucket {
148
+ position: absolute;
149
+ transform-style: preserve-3d;
150
+ }
151
+
152
+ /* Per-bucket lambert calc \u2014 runs once per bucket per frame. */
153
+ .polycss-scene[data-polycss-lighting="dynamic"] .polycss-bucket {
154
+ --plam: max(0, calc(
155
+ var(--pnx) * var(--plx) +
156
+ var(--pny) * var(--ply) +
157
+ var(--pnz) * var(--plz)
158
+ ));
159
+ }
160
+
161
+ /* Per-poly lambert calc \u2014 applies to any leaf whose direct parent is NOT
162
+ a .polycss-bucket. Covers:
163
+ - vanilla createPolyScene polys not inside a bucket (e.g. off-axis
164
+ curved polys that didn't make a bucket group)
165
+ - React <PolyScene polygons> path (leaves are direct children of
166
+ .polycss-scene; no <PolyMesh> wrapper)
167
+ - React <PolyScene><PolyMesh polygons></PolyMesh> path (leaves are
168
+ direct children of .polycss-mesh)
169
+ Bucketed leaves are skipped \u2014 their parent IS .polycss-bucket so they
170
+ inherit the bucket's hoisted lambert (one calc per bucket, not per
171
+ leaf). */
172
+ .polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > i,
173
+ .polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > b,
174
+ .polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > u {
175
+ --plam: max(0, calc(
176
+ var(--pnx) * var(--plx) +
177
+ var(--pny) * var(--ply) +
178
+ var(--pnz) * var(--plz)
179
+ ));
180
+ }
181
+
182
+ /* All polys: containment + background-color from lambert (inherited or
183
+ own) and the scene-level light vars. Splitting this from the lambert
184
+ calc above lets bucketed polys skip the dot-product entirely. */
185
+ .polycss-scene[data-polycss-lighting="dynamic"] s {
186
+ /* Isolate each leaf's layout/style/paint walks from siblings. Works
187
+ because the leaf transform-style:preserve-3d was dropped above \u2014
188
+ the 3D context lives on .polycss-scene / .polycss-mesh, not the
189
+ leaves, so there's nothing inside a leaf that needs to participate
190
+ in 3D compositing across the contain boundary. */
191
+ contain: strict;
192
+ background-color: rgb(
193
+ calc(255 * (var(--par) * var(--pai)
194
+ + var(--plr) * var(--pli) * var(--plam)))
195
+ calc(255 * (var(--pag) * var(--pai)
196
+ + var(--plg) * var(--pli) * var(--plam)))
197
+ calc(255 * (var(--pab) * var(--pai)
198
+ + var(--plb) * var(--pli) * var(--plam)))
199
+ );
200
+ background-blend-mode: multiply;
201
+ }
202
+
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
+
224
+ .polycss-scene[data-polycss-lighting="dynamic"] u {
225
+ border-bottom-color: rgb(
226
+ calc(255 * var(--psr) * (var(--par) * var(--pai)
227
+ + var(--plr) * var(--pli) * var(--plam)))
228
+ calc(255 * var(--psg) * (var(--pag) * var(--pai)
229
+ + var(--plg) * var(--pli) * var(--plam)))
230
+ calc(255 * var(--psb) * (var(--pab) * var(--pai)
231
+ + var(--plb) * var(--pli) * var(--plam)))
232
+ );
233
+ }
234
+ `;var so=65,io=45,ao=1,re=no;function kt(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 lo(e){let n=e.rotX??so,t=e.rotY??io,o=e.zoom??ao,r=e.distance??0,s=e.target??[0,0,0],i=s[1]*re,c=s[0]*re,l=s[2]*re;return`${r!==0?`translateZ(${-r}px) `:""}scale(${o}) rotateX(${n}deg) rotate(${t}deg) translate3d(${-i}px, ${-c}px, ${-l}px)`}var co=.1;function uo(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/co,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 Ot(e,n={}){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");e.ownerDocument&&_t(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",lo(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=wt(g.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],E=wt(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?uo(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 _=St(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?Ct(y.polygons,w):null)??Pt(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=oo(y),S=re,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=kt(w);k&&(A.style.transform=k);let T=(O,F)=>F?ro(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*re,U=(F+I)/2*re,W=(L+X)/2*re;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=Tt(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=kt(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=St(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{},mo=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","atlas-scale","auto-center"];function se(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function fo(e){return e==="false"?!1:se(e)}function ho(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 yo(e){if(e==="baked"||e==="dynamic")return e}function go(e){return e==="auto"?"auto":se(e)}var G=class extends po{constructor(){super(...arguments);this._scene=null}static get observedAttributes(){return[...mo]}getScene(){return this._scene}_readOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={},s=fo(this.getAttribute("perspective"));s!==void 0&&(r.perspective=s);let i=se(this.getAttribute("rot-x"));i!==void 0&&(r.rotX=i);let c=se(this.getAttribute("rot-y"));c!==void 0&&(r.rotY=c);let l=se(this.getAttribute("zoom"));l!==void 0&&(r.zoom=l),r.textureLighting=yo(this.getAttribute("texture-lighting"))??"baked";let a=go(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=ho(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=se(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=se(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=Ot(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())}};import{computeSceneBbox as bo,loadMesh as vo}from"@layoutit/polycss-core";var xo=typeof HTMLElement<"u"?HTMLElement:class{},Po=["src","mtl","position","scale","rotation","auto-center"];function he(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 Ht(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return he(e)}}function Eo(e){return e.closest("poly-scene")??null}function Ao(e){if(e.length===0)return e;let n=bo(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 de=class extends xo{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Po]}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:he(this.getAttribute("position")),scale:Ht(this.getAttribute("scale")),rotation:he(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=Eo(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,i;try{i=await vo(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:Ao(i.polygons)}),this._parseResult=i,this._handle=c.add(i,{position:he(this.getAttribute("position")),scale:Ht(this.getAttribute("scale")),rotation:he(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var Mo=typeof HTMLElement<"u"?HTMLElement:class{},Co=["vertices","color","texture","uvs","position","scale","rotation"];function Dt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}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 To(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Ge(e)}}function Lo(e){return e.closest("poly-scene")??null}var Ee=class extends Mo{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Co]}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=Lo(this);if(!t)return;let o=t.getScene();if(!o)return;let r=Dt(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=Dt(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:Ge(this.getAttribute("position")),scale:To(this.getAttribute("scale")),rotation:Ge(this.getAttribute("rotation"))})}};import{axesHelperPolygons as _o}from"@layoutit/polycss-core";var So=typeof HTMLElement<"u"?HTMLElement:class{},wo=["size","thickness","negative","x-color","y-color","z-color"];function ko(e){return e.closest("poly-scene")??null}function Rt(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var Ae=class extends So{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...wo]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&this._handle&&this._remount()}_polygons(){return _o({size:Rt(this.getAttribute("size")),thickness:Rt(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=ko(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}}};import{octahedronPolygons as Oo}from"@layoutit/polycss-core";var Ho=typeof HTMLElement<"u"?HTMLElement:class{},Do=["direction","target","distance","size","color"],je=50,Ro=5,Io=.35,Vo="#ffd54a";function zo(e){return e.closest("poly-scene")??null}function It(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 Vt(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var Me=class extends Ho{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Do]}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=It(this.getAttribute("direction"));if(!t)return;let o=It(this.getAttribute("target"))??[0,0,0],r=Vt(this.getAttribute("distance"),Ro),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*je,a*je,m*je]}_mount(){let t=zo(this);if(!t)return;let o=t.getScene();if(!o)return;let r=Vt(this.getAttribute("size"),Io),s=this.getAttribute("color")??Vo,i={polygons:Oo({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}}};import{BASE_TILE as Bo}from"@layoutit/polycss-core";var Ce={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function pe(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 ye(e){return e===!0?-1:e===!1?1:e}function Te(){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 Le(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 _e(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 Se(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 zt(e,n={}){let t=pe(Ce,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,a=Te(),d=Le(e),{changeListeners:m,startListeners:f,endListeners:h,listenerArray:u,emitChange:p,emitInteraction:b}=a,x=Se(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=ye(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*Bo,Q=(P*Y-D*W/U)/z,ie=-(P*W+D*Y/U)/z,ee=L.target??[0,0,0];e.setOptions({target:[ee[0]+Q,ee[1]+ie,ee[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=_e(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=pe(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 we(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 ne(e){if(e!==null)return!(e==="false"||e==="0")}function ke(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 Oe(e){if(e==="x"||e==="y")return e}var Fo=typeof HTMLElement<"u"?HTMLElement:class{},No=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],He=class extends Fo{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...No]}_readAnimate(){let t=N(this.getAttribute("animate-speed")),o=Oe(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:ne(r)}:{}}}_readOptions(){let t={},o=ne(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=ne(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=ke(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=zt(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())}};import{BASE_TILE as Xo}from"@layoutit/polycss-core";function Bt(e,n={}){let t=pe(Ce,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=Te(),f=Le(e),{changeListeners:h,startListeners:u,endListeners:p,listenerArray:b,emitChange:x,emitInteraction:M}=m,C=Se(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 $=ye(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),Q=Math.cos(U*Math.PI/180),ie=Math.sin(U*Math.PI/180),ee=W*Xo,Be=(I*ie-V*Q/z)/ee,q=-(I*Q+V*ie/z)/ee,j=X.target??[0,0,0];e.setOptions({target:[j[0]+Be,j[1]+q,j[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=ye(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=_e(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=pe(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 Yo=typeof HTMLElement<"u"?HTMLElement:class{},$o=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],De=class extends Yo{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...$o]}_readAnimate(){let t=N(this.getAttribute("animate-speed")),o=Oe(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:ne(r)}:{}}}_readOptions(){let t={},o=ne(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=ne(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=ke(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=Bt(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())}};import{createIsometricCamera as Ft}from"@layoutit/polycss-core";var Uo=8e3;function qe(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=Ft(n),o=`${e.perspective??Uo}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}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=Ft(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var Wo=typeof HTMLElement<"u"?HTMLElement:class{},Zo=["perspective","zoom","rot-x","rot-y","target","distance"],Re=class extends Wo{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Zo]}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:we(this.getAttribute("target")),distance:N(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=qe(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=qe(s),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var Go=typeof HTMLElement<"u"?HTMLElement:class{},jo=["zoom","rot-x","rot-y","target","distance"],Ie=class extends Go{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:we(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)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})}};import{arrowPolygons as qo,ringPolygons as Ko}from"@layoutit/polycss-core";var Je="#ff3653",Qe="#8adb00",et="#2c8fff",me=50,Xt=60,Jo=.6,Qo=.0125,er=.15,tr=.04,nr=1,or=.012,rr=64,sr=1e-4,ir=.6,ar=.8,lr=1,Yt={0:1,1:0,2:2},$t=[{cssAxis:0,sign:1,key:"x",color:Je},{cssAxis:0,sign:-1,key:"-x",color:Je},{cssAxis:1,sign:1,key:"y",color:Qe},{cssAxis:1,sign:-1,key:"-y",color:Qe},{cssAxis:2,sign:1,key:"z",color:et},{cssAxis:2,sign:-1,key:"-z",color:et}],Ut=[{cssAxis:0,key:"x",color:Je},{cssAxis:1,key:"y",color:Qe},{cssAxis:2,key:"z",color:et}];function cr(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 Zt(e,n){return!n||n<=0?e:Math.round(e/n)*n}function ur(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*me,(n+r)/2*me,(o+i)/2*me]:[0,0,0]}function Wt(e){if(e.length===0)return Xt;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)*me*Jo:Xt}function Ke(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 dr(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<sr)return;d?.(),f?.(!0);let y=S=>{let A=S.clientX-i,w=S.clientY-c,_=(A*M+w*C)/H;_=Zt(_,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 pr(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=Zt(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 Gt(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?lr:c===v?ar:ir}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=Wt(t?.polygons??[])*r,E=R/me,P=cr(v.color,k);if(o==="translate")return qo({axis:Yt[v.cssAxis],sign:v.sign??1,shaftLength:E,shaftHalfThickness:E*Qo,headLength:E*er,headHalfThickness:E*tr,color:P});let D=R*nr/me;return Ko({axis:Yt[v.cssAxis],radius:D,halfThickness:D*or,segments:rr,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"?$t:o==="rotate"?Ut:[],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=ur(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 $t){let R=T.key.replace("-","")[0];if(!k[R])continue;let E=i.get(T.key);if(E&&Ke(E.handle.element,v.clientX,v.clientY)){v.preventDefault(),v.stopPropagation(),l=T.key,f(),g=(t.transform.position??[0,0,0]).slice(),dr({cssAxis:T.cssAxis,sign:T.sign,shaftLengthCss:Wt(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 Ut){if(!k[T.key])continue;let R=i.get(T.key);if(R&&Ke(R.handle.element,v.clientX,v.clientY)){v.preventDefault(),v.stopPropagation(),l=T.key,f(),S=(t.transform.rotation??[0,0,0]).slice(),pr({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(Ke(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 mr=typeof HTMLElement<"u"?HTMLElement:class{},fr=["mode","target","size","enabled"];function jt(e){if(e==="translate"||e==="rotate")return e}var Ve=class extends mr{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...fr]}_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 de?r:null}_readOptions(){let t={},o=jt(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=Gt(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=jt(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};function hr(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 qt(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")&&hr(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 yr=typeof HTMLElement<"u"?HTMLElement:class{},gr=["multiple","clear-on-miss"],ze=class extends yr{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...gr]}_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=qt(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",de),customElements.get("poly-polygon")||customElements.define("poly-polygon",Ee),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",Ae),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",Me),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",He),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",De),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",Re),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",Ie),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",Ve),customElements.get("poly-select")||customElements.define("poly-select",ze));export{Ae as PolyAxesHelperElement,Me as PolyDirectionalLightHelperElement,De as PolyMapControlsElement,de as PolyMeshElement,He as PolyOrbitControlsElement,Ie as PolyOrthographicCameraElement,Re as PolyPerspectiveCameraElement,Ee as PolyPolygonElement,G as PolySceneElement,ze as PolySelectElement,Ve as PolyTransformControlsElement};