@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.
package/dist/index.cjs ADDED
@@ -0,0 +1,234 @@
1
+ "use strict";var Je=Object.defineProperty;var Jt=Object.getOwnPropertyDescriptor;var Qt=Object.getOwnPropertyNames;var en=Object.prototype.hasOwnProperty;var tn=(e,n)=>{for(var t in n)Je(e,t,{get:n[t],enumerable:!0})},Ke=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Qt(n))!en.call(e,r)&&r!==t&&Je(e,r,{get:()=>n[r],enumerable:!(o=Jt(n,r))||o.enumerable});return e},U=(e,n,t)=>(Ke(e,n,"default"),t&&Ke(t,n,"default"));var nn=e=>Ke(Je({},"__esModule",{value:!0}),e);var $={};tn($,{PolyMapControlsElement:()=>Ue,PolyMeshElement:()=>ye,PolyOrbitControlsElement:()=>$e,PolyOrthographicCameraElement:()=>Ze,PolyPerspectiveCameraElement:()=>We,PolyPolygonElement:()=>Fe,PolySceneElement:()=>K,PolySelectElement:()=>je,PolyTransformControlsElement:()=>Ge,createPolyMapControls:()=>Re,createPolyOrbitControls:()=>De,createPolyOrthographicCamera:()=>Se,createPolyPerspectiveCamera:()=>be,createPolyScene:()=>Le,createSelect:()=>Ie,createTransformControls:()=>ze,injectPolyBaseStyles:()=>Te});module.exports=nn($);var q=require("@layoutit/polycss-core");var nt=require("@layoutit/polycss-core"),ot=50,bt=[.4,-.7,.59],vt="#ffffff",xt=1,Pt="#ffffff",At=.4,pe=4096,ft=1,on=.1,rn=1,Et=pe*pe,sn=Et*3,Qe=2048,et=16*1024*1024,an=.995,ue=new Map,tt=new WeakMap,B=.001,ee=1e-9,ln=1e-4,cn=.1,un=.75,dn=0,pn=.45,mn=3,fn=2;function hn(e){let n=ue.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}),ue.set(e,n),n.then(()=>{ue.get(e)===n&&ue.delete(e)},()=>{ue.get(e)===n&&ue.delete(e)})),n}function Ce(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(rn,Math.max(on,n))}function Ct(e,n){let t=e.toFixed(n).replace(/\.?0+$/,"");return Object.is(Number(t),-0)?"0":t}function Mt(e,n=mn){return e.map(t=>Ct(t,n)).join(",")}function Pe(e,n=fn){return`${Ct(e,n)}%`}function Tt(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function yn(e){let n=Tt(e);if(n<=0)return 1;let t=Math.max(1,...e.map(s=>Math.max(s.width,s.height))),o=Qe/t,r=Math.sqrt(et/(n*4));return Ce(Math.min(o,r))}function gn(e){let n=Tt(e),t=.5;return n<=Et?t=1:n<=sn&&(t=.75),Ce(Math.min(t,yn(e)))}function bn(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function vn(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function xn(e,n){let t=bn(e,n),o=vn(e,n),r=t>Qe?Qe/t:1,s=o>et?Math.sqrt(et/o):1;return Math.min(r,s)}function Pn(e,n){let t=gn(n.pages),o=t===1?n:Ee(e,t);for(let r=0;r<4;r++){let s=xn(o.pages,t);if(s>=1)break;let i=Ce(t*s*an);if(i>=t)break;t=i,o=Ee(e,t)}return{packed:o,atlasScale:t}}function An(e,n){if(n!==void 0&&n!=="auto"){let o=Ce(n);return{packed:Ee(e,o),atlasScale:o}}let t=Ee(e,1);return Pn(e,t)}function En(e){return Math.max(ft,Math.ceil(ft/e))}function te(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 ie(e){let n=(0,nt.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function Cn(e){return(0,nt.parsePureColor)(e)?.alpha??1}function Mn({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 Lt(e,n,t,o,r){let s=ie(e),i=ie(t),c=ie(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=Cn(e);return u<1?`rgba(${m}, ${f}, ${h}, ${u})`:Mn({r:m,g:f,b:h})}function Tn(e,n,t,o){let r=ie(n),s=ie(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 Ln({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 Sn(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(),te(e,i),e.globalCompositeOperation="multiply",e.fillStyle=Ln(s),e.fillRect(n,t,o,r),e.restore())}function _n(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;te(e,i),e.drawImage(n,t+(r-d)/2,o+(s-m)/2,d,m)}function Ae(e){return`${e[0]},${e[1]},${e[2]}`}function wn(e,n){let t=Ae(e),o=Ae(n);return t<o?`${t}|${o}`:`${o}|${t}`}function St(e,n){return Ae(e)<Ae(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 On(e){return!e.texture}function Me(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function rt(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<=ee?null:(i/=a,c/=a,l/=a,[i,c,l])}function me(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function kn(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 Hn(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=Me(e.vertices,n,t),r=rt(o);return r?{pts:o,normal:r,planeD:me(r,o[0]),optimizable:On(e)}:null}function Dn(e,n){return!e||!n||!e.optimizable||!n.optimizable||me(e.normal,n.normal)<1-ln?!1:Math.abs(e.planeD-n.planeD)<=cn}function Rn(e){let n=[...e],t=Math.abs(n[0])>ee?0:Math.abs(n[1])>ee?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 ge(e,n,t,o,r={}){let s=me(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<=ee)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<=ee)return null;let m=[a[0]/d,a[1]/d,a[2]/d],f=e.map(A=>{let P=A[0]-n[0],D=A[1]-n[1],k=A[2]-n[2];return[P*l[0]+D*l[1]+k*l[2],P*m[0]+D*m[1]+k*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],C=u*m[0]+p*m[1]+b*m[2],M=1/0,H=1/0,y=-1/0,g=-1/0;for(let[A,P]of f){let D=A+x,k=P+C;D<M&&(M=D),D>y&&(y=D),k<H&&(H=k),k>g&&(g=k)}let _=y-M,E=g-H;if(!Number.isFinite(_)||!Number.isFinite(E))return null;let w=r.snapBounds?Math.floor(M+B):M,S=r.snapBounds?Math.floor(H+B):H,v=r.snapBounds?Math.ceil(y-B):y,O=r.snapBounds?Math.ceil(g-B):g,T=Math.max(1,r.snapBounds?v-w:Math.ceil(_)),R=Math.max(1,r.snapBounds?O-S:Math.ceil(E));return{xAxis:l,yAxis:m,local2D:f,shiftX:x-w,shiftY:C-S,canvasW:T,canvasH:R,pixelArea:T*R,rawArea:_*E}}function In(e,n,t,o){let r=0,s=0;for(let i of e){let c=n[i];if(!c)return null;let l=ge(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 Vn(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=ge(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=St(c.pts[d],c.pts[(d+1)%c.pts.length]),f=ge(c.pts,c.pts[0],c.normal,m);if(!f)continue;let h=Rn(f.xAxis);if(s.has(h))continue;s.add(h);let u=In(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 zn(e,n){let t=n.tileSize??ot,o=n.layerElevation??t,r=e.map(d=>Hn(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=wn(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;Dn(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=Vn(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 Bn(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 ht(e,n,t,o){if(o.optimize&&o.fixedXAxis)return ge(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?St(e[c],e[l]):[e[l][0]-e[c][0],e[l][1]-e[c][1],e[l][2]-e[c][2]],d=ge(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 Fn(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 _t(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],C=c[0],M=1-c[1],H=b-u,y=x-p,g=C-u,_=M-p,E=H*_-g*y;if(Math.abs(E)<=1e-9)return null;let w=d-l,S=f-l,v=m-a,O=h-a,T={a:(w*_-S*y)/E,b:(H*S-g*w)/E,c:(v*_-O*y)/E,d:(H*O-g*v)/E,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 wt(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 Nn(e,n,t,o,r,s,i,c){let a=Me(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=_t(a,e.uvs),m=wt(e.uvs);return!d&&!m?null:{screenPts:a.flatMap(([f,h])=>[f,h]),uvAffine:d,uvSampleRect:m}}function Xn(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 Yn(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 st(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 $n(e,n,t,o,r,s){if(st(e,n,t,o),!r||r.size===0||s<=0)return;let i=o.length/2,c=Yn(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 C=c>=0?b/x:-b/x,M=c>=0?-p/x:p/x;e.moveTo(n+m,t+f),e.lineTo(n+h,t+u),e.lineTo(n+h+C*s,t+u+M*s),e.lineTo(n+m+C*s,t+f+M*s),e.closePath()}}function Un(e,n,t,o){let{vertices:r,texture:s,uvs:i}=e;if(!r||r.length<3)return null;let c=t.tileSize??ot,l=t.layerElevation??c,a=Me(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=rt(a);if(!u)return null;let p=ht(a,d,u,{optimize:!1}),b=s||p&&Fn(p)?p:ht(a,d,u,{optimize:!0,fixedXAxis:o?.xAxis,boundsOrigin:o?.boundsOrigin,snapBounds:!!o,seamEdges:o?.seamEdges});if(!b)return null;let{xAxis:x,yAxis:C,local2D:M,shiftX:H,shiftY:y}=b,g=[];for(let[Y,z]of M)g.push(Y+H,z+y);let _=d[0]-H*x[0]-y*C[0],E=d[1]-H*x[1]-y*C[1],w=d[2]-H*x[2]-y*C[2],S=Mt([x[0],x[1],x[2],0,C[0],C[1],C[2],0,u[0],u[1],u[2],0,_,E,w,1]),v=t.directionalLight,O=t.ambientLight,T=v?.direction??bt,R=v?.color??vt,A=Math.max(0,v?.intensity??xt),P=O?.color??Pt,D=Math.max(0,O?.intensity??At),k=Math.hypot(T[0],T[1],T[2])||1,F=T[0]/k,j=T[1]/k,L=T[2]/k,I=A*Math.max(0,u[0]*F+u[1]*j+u[2]*L),V=Tn(I,R,P,D),X=Lt(e.color??"#cccccc",I,R,P,D),W=null,Z=null;s&&i&&i.length>=3&&i.length===r.length&&(Z=wt(i),W=_t(M.map(([Y,z])=>[Y+H,z+y]),i));let G=s&&e.textureTriangles?.length?e.textureTriangles.map(Y=>Nn(Y,c,l,d,x,C,H,y)).filter(Y=>!!Y):null;return{index:n,polygon:e,texture:s,tileSize:c,layerElevation:l,matrix:S,canvasW:b.canvasW,canvasH:b.canvasH,screenPts:g,uvAffine:W,uvSampleRect:Z,textureTriangles:G,seamEdges:o?.seamEdges.size?o.seamEdges:null,normal:u,textureTint:V,shadedColor:X}}function Ot(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??ot,r=t.layerElevation??o,s=Me(e.vertices,o,r),i=rt(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],re=s[Q.b];return{...Q,length:Math.hypot(re[0]-J[0],re[1]-J[1],re[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<=ee)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=me(b,p),C=[m[0]+p[0]*x,m[1]+p[1]*x,m[2]+p[2]*x],M=[C[0]-h[0],C[1]-h[1],C[2]-h[2]],H=Math.hypot(M[0],M[1],M[2]);if(H<=ee)return null;let y=[M[0]/H,M[1]/H,M[2]/H];if(me(kn(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<=ee)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=me(J,p),C=[m[0]+p[0]*x,m[1]+p[1]*x,m[2]+p[2]*x],M=[C[0]-h[0],C[1]-h[1],C[2]-h[2]];let re=Math.hypot(M[0],M[1],M[2]);if(re<=ee)return null;y=[M[0]/re,M[1]/re,M[2]/re]}let g=Math.max(0,Math.min(u,x)),_=Math.max(0,u-g),E=pn,w=g+E,S=_+E,v=H+E*2,O=h[0]-w*p[0]-E*y[0],T=h[1]-w*p[1]-E*y[1],R=h[2]-w*p[2]-E*y[2],A=Mt([p[0],p[1],p[2],0,y[0],y[1],y[2],0,i[0],i[1],i[2],0,O,T,R,1]),P=t.directionalLight,D=t.ambientLight,k=P?.direction??bt,F=P?.color??vt,j=Math.max(0,P?.intensity??xt),L=D?.color??Pt,I=Math.max(0,D?.intensity??At),V=Math.hypot(k[0],k[1],k[2])||1,X=k[0]/V,W=k[1]/V,Z=k[2]/V,G=j*Math.max(0,i[0]*X+i[1]*W+i[2]*Z),Y=Lt(e.color??"#cccccc",G,F,L,I),z=t.textureLighting??"baked",ne=ie(e.color??"#cccccc"),ce=z==="dynamic"?"":`border-bottom-color:${Y};`,oe=z==="dynamic"?`--pnx:${i[0].toFixed(4)};--pny:${i[1].toFixed(4)};--pnz:${i[2].toFixed(4)};--psr:${(ne.r/255).toFixed(4)};--psg:${(ne.g/255).toFixed(4)};--psb:${(ne.b/255).toFixed(4)};`:"",qe=`transform:matrix3d(${A});border-width:0 ${S}px ${v}px ${w}px;`+ce+oe;return{index:n,polygon:e,styleText:qe}}function Ee(e,n=1){let t=Array(e.length).fill(null),o=[],r=En(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<=pe){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>pe)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>pe||l.canvasH+r*2>pe){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 Wn(e,n,t,o){te(e,o),e.beginPath(),st(e,n.x,n.y,n.screenPts),e.clip(),te(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function de(e,n){return Math.max(0,Math.min(n,e))}function yt(e,n,t,o,r,s,i,c){let l=n.naturalWidth||n.width||1,a=n.naturalHeight||n.height||1,d=de(Math.min(t.minU,t.maxU)*l,l),m=de(Math.max(t.minU,t.maxU)*l,l),f=de(Math.min(t.minV,t.maxV)*a,a),h=de(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(de((t.minU+t.maxU)/2*l,l-1)),b=1),x<1&&(p=Math.floor(de((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)),te(e,c),e.drawImage(n,u,p,b,x,o,r,s,i)}async function Zn(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 hn(a))}));for(let a of e.entries){let d=a.texture?c.get(a.texture):null;if(s.save(),te(s,o),s.beginPath(),a.texture?$n(s,a.x,a.y,a.screenPts,a.seamEdges,dn):st(s,a.x,a.y,a.screenPts),s.clip(),!a.texture)Wn(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=Xn(h.screenPts,un);s.save(),te(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?(te(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&&yt(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;te(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?yt(s,d,a.uvSampleRect,a.x,a.y,a.canvasW,a.canvasH,o):d&&_n(s,d,a.x,a.y,a.canvasW,a.canvasH,o);a.texture&&n==="baked"&&Sn(s,a.x,a.y,a.canvasW,a.canvasH,a.textureTint,o),s.restore()}let l=await Bn(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:l}}async function Gn(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await Zn(i,n,t,o))}return s}function jn(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 it(e,n){let t=tt.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);tt.set(e,o)}function at(e,n){e.style.width=`${n.canvasW}px`,e.style.height=`${n.canvasH}px`,e.style.transform=`matrix3d(${n.matrix})`,it(e,n.polygon)}function kt(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 qn(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 gt(e){return!!qn(e)}function Kn(e){return!e.texture&&e.polygon.vertices.length===3}function Jn(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 Qn(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(`${Pe(s)} ${Pe(i)}`)}return`polygon(${n.join(", ")})`}function eo(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=Pe(Math.max(0,Math.min(100,n/o/r*100))),c=Pe(Math.max(0,Math.min(100,t/o/s*100)));return`polygon(${Array.from({length:o},()=>`${i} ${c}`).join(", ")})`}function to(e){return`${Qn(e)} ${eo(e)}`}function no(e,n,t){if(t==="dynamic"){kt(e,n);let o=ie(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 oo(e,n,t){let o=t.createElement("b");return at(o,e),no(o,e,n),o}function ro(e,n){let t=n.createElement("i");return at(t,e),t.style.color=e.shadedColor,t.style.setProperty("border-shape",to(e)),t}function so(e,n,t){let o=t.createElement("s");return at(o,e),o.style.backgroundPosition=`-${e.x}px -${e.y}px`,o.style.opacity="0",n==="dynamic"&&kt(o,e),o}function Ht(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=o!=="dynamic"&&Jn(t),s=zn(e,n),i=e.map((p,b)=>Un(p,b,n,s[b])),c=i.map(p=>p&&Kn(p)?Ot(p.polygon,p.index,n):null),l=i.map((p,b)=>p&&(p.texture||!gt(p)&&!c[b]&&!r?p:null)),{packed:a,atlasScale:d}=An(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 C=a.entries[p];if(C){let M=so(C,o,t);m.set(p,M),f.push({polygonIndex:p,element:M,kind:"atlas",dispose:()=>{}})}else if(!b.texture&&gt(b)){let M=oo(b,o,t);f.push({polygonIndex:p,element:M,kind:"solid",dispose:()=>{}})}else if(!b.texture&&x){let M=It(x,t);f.push({polygonIndex:p,element:M,kind:"triangle",dispose:()=>{}})}else if(!b.texture&&r){let M=ro(b,t);f.push({polygonIndex:p,element:M,kind:"border",dispose:()=>{}})}}return f.sort((p,b)=>p.polygonIndex-b.polygonIndex),Gn(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],C=p[b];if(C)for(let M of x.entries){let H=m.get(M.index);!H||!C.url||(jn(H,C,o,M),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 Dt(e,n){let t=e.map((o,r)=>Ot(o,r,n));return t.some(o=>!o)?null:t}function io(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 Rt(e,n){e.style.cssText=n.styleText,(n.polygon.data||tt.get(e)?.length)&&it(e,n.polygon)}function It(e,n){let t=n.createElement("u");return io(t),Rt(t,e),it(t,e.polygon),t}function Vt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=Dt(e,n);if(!o)return null;let r=[];for(let s of o){let i=It(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 zt(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=Dt(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++)Rt(e[s].element,r[s]);return{rendered:e,dispose(){}}}var Bt="polycss-styles";function Te(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(Bt))return;let t=n.createElement("style");t.id=Bt,t.textContent=ao,n.head.appendChild(t)}var ao=`
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 lo=65,co=45,uo=1,ae=q.BASE_TILE;function Ft(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 po(e){let n=e.rotX??lo,t=e.rotY??co,o=e.zoom??uo,r=e.distance??0,s=e.target??[0,0,0],i=s[1]*ae,c=s[0]*ae,l=s[2]*ae;return`${r!==0?`translateZ(${-r}px) `:""}scale(${o}) rotateX(${n}deg) rotate(${t}deg) translate3d(${-i}px, ${-c}px, ${-l}px)`}var mo=.1;function fo(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/mo,p=Math.round(d*u)/u,b=Math.round(m*u)/u,x=Math.round(f*u)/u,C=Math.hypot(p,b,x);return C<1e-9?null:{key:p+","+b+","+x,vec:[p/C,b/C,x/C]}}function Le(e,n={}){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");e.ownerDocument&&Te(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",po(g)),l(y,g)}function l(y,g){let _=g.textureLighting==="dynamic";y.dataset.polycssLighting=g.textureLighting??"baked";let E=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai"];if(!_){for(let F of E)y.style.removeProperty(F);return}let w=g.directionalLight?.direction??[.4,-.7,.59],S=Math.hypot(w[0],w[1],w[2])||1,v=w[0]/S,O=w[1]/S,T=w[2]/S,R=(0,q.parseHexColor)(g.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],A=(0,q.parseHexColor)(g.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],P=g.directionalLight?.intensity??1,D=g.ambientLight?.intensity??.4,k=F=>(F/255).toFixed(4);y.style.setProperty("--plx",v.toFixed(4)),y.style.setProperty("--ply",O.toFixed(4)),y.style.setProperty("--plz",T.toFixed(4)),y.style.setProperty("--plr",k(R[0])),y.style.setProperty("--plg",k(R[1])),y.style.setProperty("--plb",k(R[2])),y.style.setProperty("--pli",P.toFixed(4)),y.style.setProperty("--par",k(A[0])),y.style.setProperty("--pag",k(A[1])),y.style.setProperty("--pab",k(A[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 _ of y){try{_.dispose()}catch{}_.element.parentNode&&_.element.parentNode.removeChild(_.element)}}function m(y){let g=o.createDocumentFragment(),_=t.textureLighting==="dynamic"&&!y.stableDom,E=new Map,w=[];for(let S of y.rendered){let v=y.polygons[S.polygonIndex],O=_&&v?fo(v):null;if(!O){w.push(S);continue}let T=O.key+"|"+(v.color??""),R=E.get(T);R||(R={vec:O.vec,items:[]},E.set(T,R)),R.items.push(S)}for(let S of w)g.appendChild(S.element);for(let S of E.values()){if(S.items.length<2){for(let O of S.items)g.appendChild(O.element);continue}let v=o.createElement("div");v.className="polycss-bucket",v.style.setProperty("--pnx",String(S.vec[0])),v.style.setProperty("--pny",String(S.vec[1])),v.style.setProperty("--pnz",String(S.vec[2]));for(let O of S.items)v.appendChild(O.element),O.element.style.removeProperty("--pnx"),O.element.style.removeProperty("--pny"),O.element.style.removeProperty("--pnz");g.appendChild(v)}y.wrapper.appendChild(g)}function f(y,g){let _=t.textureLighting==="dynamic",E=t.directionalLight?.direction,w=g&&(g[0]!==0||g[1]!==0||g[2]!==0);if(!_||!w||!E){y.style.removeProperty("--plx"),y.style.removeProperty("--ply"),y.style.removeProperty("--plz");return}let S=(0,q.inverseRotateVec3)(E,g),v=Math.hypot(S[0],S[1],S[2])||1;y.style.setProperty("--plx",(S[0]/v).toFixed(4)),y.style.setProperty("--ply",(S[1]/v).toFixed(4)),y.style.setProperty("--plz",(S[2]/v).toFixed(4))}function h(y,g){a(y);let _=t.directionalLight,E=g?{..._,direction:g}:_,w={doc:o,directionalLight:E,ambientLight:t.ambientLight,textureLighting:t.textureLighting,atlasScale:t.atlasScale},S=(y.stableDom?Vt(y.polygons,w):null)??Ht(y.polygons,w);y.rendered=S.rendered,y.disposeAtlas=S.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,q.computeSceneBbox)(y),_=ae,E=(g.min[1]+g.max[1])/2*_,w=(g.min[0]+g.max[0])/2*_,S=(g.min[2]+g.max[2])/2*_;s.style.setProperty("--offset-transform",`translate3d(${-E}px, ${-w}px, ${-S}px)`)}function p(y,g={}){let E=(r.ownerDocument??document).createElement("div");E.className="polycss-mesh",g.id&&E.setAttribute("data-poly-mesh-id",g.id);let w={...g},S=g.merge!==!1,v=!!g.stableDom,O=Ft(w);O&&(E.style.transform=O);let T=(k,F)=>F?(0,q.mergePolygons)(k):k,R=T(y.polygons,S);function A(k){if(k.length===0){E.style.removeProperty("--origin");return}let F=1/0,j=1/0,L=1/0,I=-1/0,V=-1/0,X=-1/0;for(let Y of k)for(let z of Y.vertices)z[0]<F&&(F=z[0]),z[0]>I&&(I=z[0]),z[1]<j&&(j=z[1]),z[1]>V&&(V=z[1]),z[2]<L&&(L=z[2]),z[2]>X&&(X=z[2]);if(!Number.isFinite(F)){E.style.removeProperty("--origin");return}let W=(j+V)/2*ae,Z=(F+I)/2*ae,G=(L+X)/2*ae;E.style.setProperty("--origin",`${W}px ${Z}px ${G}px`)}A(R),s.appendChild(E);let P={handle:void 0,wrapper:E,parseResult:y,rendered:[],polygons:R,disposed:!1,stableDom:v,excludeFromAutoCenter:!!g.excludeFromAutoCenter,bakedRotation:g.rotation?[...g.rotation]:[0,0,0]},D={polygons:R,element:E,id:g.id,get transform(){return w},remove(){E.parentNode&&E.parentNode.removeChild(E),a(P),i.delete(P),u()},setPolygons(k,F){S=F?.merge??S,v=F?.stableDom??v,P.stableDom=v,P.polygons=T(k,S),D.polygons=P.polygons,A(P.polygons);let j=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=zt(P.rendered,P.polygons,L);if(I){P.disposeAtlas?.(),P.rendered=I.rendered,P.disposeAtlas=I.dispose,j&&u();return}}h(P),j&&u()},setTransform(k){w={...w,...k};let F=Ft(w);E.style.transform=F??"",f(E,w.rotation)},dispose(){if(!P.disposed){P.disposed=!0,E.parentNode&&E.parentNode.removeChild(E),a(P);try{y.dispose()}catch{}i.delete(P),u()}},rebakeAtlas(){P.bakedRotation=w.rotation?[...w.rotation]:[0,0,0];let k=t.directionalLight?.direction??[.4,-.7,.59],F=(0,q.inverseRotateVec3)(k,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(E,w.rotation),u(),D}function b(y){let g=!!t.autoCenter;t={...t,...y},c(r,t);let _=!!t.autoCenter;for(let E of i)f(E.wrapper,E.handle.transform.rotation);g!==_&&u()}function x(){return t}function C(){let y=[];for(let g of i)y.push(g.handle);return y}function M(y){let g=y;for(;g;){if(g instanceof HTMLElement&&g.classList.contains("polycss-mesh")){for(let _ of i)if(_.wrapper===g)return _.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:C,findMeshByElement:M}}var lt=require("@layoutit/polycss-core"),ho=8e3;function be(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,lt.createIsometricCamera)(n),o=`${e.perspective??ho}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function Se(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,lt.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var Nt=require("@layoutit/polycss-core");var _e={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function fe(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 ve(e){return e===!0?-1:e===!1?1:e}function we(){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 Oe(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 ke(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 He(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 C=(((x.rotX??65)+b)%360+360)%360;n.setOptions({rotX:C})}else{let C=(((x.rotY??45)+b)%360+360)%360;n.setOptions({rotY:C})}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 De(e,n={}){let t=fe(_e,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,a=we(),d=Oe(e),{changeListeners:m,startListeners:f,endListeners:h,listenerArray:u,emitChange:p,emitInteraction:b}=a,x=He(r,e,()=>t,()=>l,()=>c,d,p),C=A=>{if(!(!t.drag||l)&&s===null&&A.isPrimary!==!1){A.preventDefault(),s=A.pointerId,i={x:A.clientX,y:A.clientY},o.style.cursor="grabbing";try{A.target.setPointerCapture(A.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),b("start",d)}},M=A=>{if(s===null||A.pointerId!==s||!t.drag||l)return;A.preventDefault();let P=A.clientX-i.x,D=A.clientY-i.y;i={x:A.clientX,y:A.clientY};let k=ve(t.invert),F=P/4*k,j=D/4*k,L=e.getOptions();if(A.shiftKey){let I=L.rotX??65,V=L.rotY??45,X=Math.max(.01,L.zoom??1),W=Math.cos(I*Math.PI/180),Z=W>=0?Math.max(.1,W):Math.min(-.1,W),G=Math.cos(V*Math.PI/180),Y=Math.sin(V*Math.PI/180),z=X*Nt.BASE_TILE,ne=(P*Y-D*G/Z)/z,ce=-(P*G+D*Y/Z)/z,oe=L.target??[0,0,0];e.setOptions({target:[oe[0]+ne,oe[1]+ce,oe[2]]})}else{let I=Math.max(0,Math.min(100,(L.rotX??65)-j)),V=(((L.rotY??45)-F)%360+360)%360;e.setOptions({rotX:I,rotY:V})}p(d)},H=A=>{if(s===A.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{A.target.releasePointerCapture(A.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),b("end",d)}},y=ke(e,()=>t,()=>l,d,p,b);function g(){o.addEventListener("pointerdown",C),o.addEventListener("pointermove",M),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 _(){o.removeEventListener("pointerdown",C),o.removeEventListener("pointermove",M),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 E(A){let P=!!t.animate;t=fe(t,A),!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 S(){l||(l=!0,_(),x.stop(),s=null,c=!1,y.teardown())}function v(){S(),m.length=0,f.length=0,h.length=0}function O(A,P){let D=u(A);D.includes(P)||D.push(P)}function T(A,P){let D=u(A),k=D.indexOf(P);k>=0&&D.splice(k,1)}function R(A,P){return u(A).includes(P)}return{update:E,resume:w,pause:S,destroy:v,addEventListener:O,removeEventListener:T,hasEventListener:R}}var Xt=require("@layoutit/polycss-core");function Re(e,n={}){let t=fe(_e,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=we(),f=Oe(e),{changeListeners:h,startListeners:u,endListeners:p,listenerArray:b,emitChange:x,emitInteraction:C}=m,M=He(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),C("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 W=ve(t.invert),Z=I/4*W,G=V/4*W,Y=Math.max(0,Math.min(100,(X.rotX??65)-G)),z=(((X.rotY??45)-Z)%360+360)%360;e.setOptions({rotX:Y,rotY:z})}else{let W=X.rotX??65,Z=X.rotY??45,G=Math.max(.01,X.zoom??1),Y=Math.cos(W*Math.PI/180),z=Y>=0?Math.max(.1,Y):Math.min(-.1,Y),ne=Math.cos(Z*Math.PI/180),ce=Math.sin(Z*Math.PI/180),oe=G*Xt.BASE_TILE,qe=(I*ce-V*ne/z)/oe,Q=-(I*ne+V*ce/z)/oe,J=X.target??[0,0,0];e.setOptions({target:[J[0]+qe,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),C("end",f)}},_=L=>{L.preventDefault()},E=L=>{L.button===2&&(a=!0,d={x:L.clientX,y:L.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),C("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=ve(t.invert),W=I/4*X,Z=V/4*X,G=e.getOptions(),Y=Math.max(0,Math.min(100,(G.rotX??65)-Z)),z=(((G.rotY??45)-W)%360+360)%360;e.setOptions({rotX:Y,rotY:z}),x(f)},S=L=>{L.button===2&&a&&(a=!1,C("end",f))},v=ke(e,()=>t,()=>l,f,x,C);function O(){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",_),o.addEventListener("mousedown",E),o.addEventListener("mousemove",w),o.addEventListener("mouseup",S),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",_),o.removeEventListener("mousedown",E),o.removeEventListener("mousemove",w),o.removeEventListener("mouseup",S),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",v.teardown()}O(),M.start();function R(L){let I=!!t.animate;t=fe(t,L),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let V=!!t.animate;I&&!V?M.stop():!I&&V&&M.start()}function A(){l&&(l=!1,O(),M.start())}function P(){l||(l=!0,T(),M.stop(),s=null,c=!1,a=!1,v.teardown())}function D(){P(),h.length=0,u.length=0,p.length=0}function k(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 j(L,I){return b(L).includes(I)}return{update:R,resume:A,pause:P,destroy:D,addEventListener:k,removeEventListener:F,hasEventListener:j}}function yo(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 Ie(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")&&yo(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 Ve=require("@layoutit/polycss-core"),ut="#ff3653",dt="#8adb00",pt="#2c8fff",he=50,Yt=60,go=.6,bo=.0125,vo=.15,xo=.04,Po=1,Ao=.012,Eo=64,Co=1e-4,Mo=.6,To=.8,Lo=1,$t={0:1,1:0,2:2},Ut=[{cssAxis:0,sign:1,key:"x",color:ut},{cssAxis:0,sign:-1,key:"-x",color:ut},{cssAxis:1,sign:1,key:"y",color:dt},{cssAxis:1,sign:-1,key:"-y",color:dt},{cssAxis:2,sign:1,key:"z",color:pt},{cssAxis:2,sign:-1,key:"-z",color:pt}],Wt=[{cssAxis:0,key:"x",color:ut},{cssAxis:1,key:"y",color:dt},{cssAxis:2,key:"z",color:pt}];function So(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 Gt(e,n){return!n||n<=0?e:Math.round(e/n)*n}function _o(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*he,(n+r)/2*he,(o+i)/2*he]:[0,0,0]}function Zt(e){if(e.length===0)return Yt;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)*he*go:Yt}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 wo(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 C=(x.left-b.left)/h,M=(x.top-b.top)/h,H=C*C+M*M;if(H<Co)return;d?.(),f?.(!0);let y=_=>{let E=_.clientX-i,w=_.clientY-c,S=(E*C+w*M)/H;S=Gt(S,l),a(S,u)},g=()=>{window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g);let _=E=>{E.stopPropagation(),E.stopImmediatePropagation()};window.addEventListener("click",_,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",_,!0),0),m?.(),f?.(!1)};window.addEventListener("pointermove",y),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g)}function Oo(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=C=>{let M=Math.atan2(C.clientY-h,C.clientX-f),H=M-u;H>Math.PI?H-=2*Math.PI:H<-Math.PI&&(H+=2*Math.PI),p+=H,u=M;let y=p*180/Math.PI;y=Gt(y,i),c(y)},x=()=>{window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x);let C=M=>{M.stopPropagation(),M.stopImmediatePropagation()};window.addEventListener("click",C,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",C,!0),0),a?.(),d?.(!1)};window.addEventListener("pointermove",b),window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x)}function ze(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?Lo:c===v?To:Mo}function f(){for(let[v,O]of i){let T=h(O.spec,m(v));O.handle.setPolygons(T,{recomputeAutoCenter:!1})}}function h(v,O){let R=Zt(t?.polygons??[])*r,A=R/he,P=So(v.color,O);if(o==="translate")return(0,Ve.arrowPolygons)({axis:$t[v.cssAxis],sign:v.sign??1,shaftLength:A,shaftHalfThickness:A*bo,headLength:A*vo,headHalfThickness:A*xo,color:P});let D=R*Po/he;return(0,Ve.ringPolygons)({axis:$t[v.cssAxis],radius:D,halfThickness:D*Ao,segments:Eo,color:P})}function u(){if(p(),!t)return;let v={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1},O=o==="translate"?Ut:o==="rotate"?Wt:[],T=o==="translate"?"polycss-transform-arrow":"polycss-transform-ring",R=d();for(let A of O){let P=A.key.replace("-","")[0];if(!v[P])continue;let D=h(A,m(A.key)),k=e.add({polygons:D,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${A.key}`,position:R});k.element.classList.add("polycss-transform-gizmo",T,`${T}--${A.key}`),i.set(A.key,{handle:k,spec:A})}}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:O}of i.values())O.setTransform({position:v})}function x(){t&&(i.size===0?u():b())}function C(v){if(t=v,!v){a=[0,0,0],p();return}a=_o(v.polygons),p(),u()}function M(){C(null)}function H(v){v!==o&&(o=v,t&&(p(),u()))}function y(v,O,T){if(!t||!g)return;let R=[g[0]+O*T[0],g[1]+O*T[1],g[2]+O*T[2]];t.setTransform({position:R}),b(),s.onObjectChange?.({object:t,position:R}),s.onChange?.()}let g=null,_=null,E=v=>{if(!t||s.enabled===!1)return;let O={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate")for(let T of Ut){let R=T.key.replace("-","")[0];if(!O[R])continue;let A=i.get(T.key);if(A&&ct(A.handle.element,v.clientX,v.clientY)){v.preventDefault(),v.stopPropagation(),l=T.key,f(),g=(t.transform.position??[0,0,0]).slice(),wo({cssAxis:T.cssAxis,sign:T.sign,shaftLengthCss:Zt(t.polygons)*r,wrapper:A.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 Wt){if(!O[T.key])continue;let R=i.get(T.key);if(R&&ct(R.handle.element,v.clientX,v.clientY)){v.preventDefault(),v.stopPropagation(),l=T.key,f(),_=(t.transform.rotation??[0,0,0]).slice(),Oo({cssAxis:T.cssAxis,wrapper:R.handle.element,target:t,startClientX:v.clientX,startClientY:v.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:A=>{if(!t||!_)return;let P=[_[0],_[1],_[2]],D=T.cssAxis===0?-1:1;P[T.cssAxis]=_[T.cssAxis]+A*D,t.setTransform({rotation:P}),s.onObjectChange?.({object:t,rotation:P}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:A=>{A||(l=null,_=null,f(),t?.rebakeAtlas()),s.onDraggingChanged?.(A)}});return}}};e.host.addEventListener("pointerdown",E,{capture:!0});let w=v=>{if(!t||l||s.enabled===!1)return;let O=null;for(let[T,R]of i)if(ct(R.handle.element,v.clientX,v.clientY)){O=T;break}O!==c&&(c=O,f())};e.host.addEventListener("pointermove",w);function S(){e.host.removeEventListener("pointerdown",E,{capture:!0}),e.host.removeEventListener("pointermove",w),p()}return{attach:C,detach:M,setMode:H,update:x,destroy:S}}var ko=typeof HTMLElement<"u"?HTMLElement:class{},Ho=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","atlas-scale","auto-center"];function le(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Do(e){return e==="false"?!1:le(e)}function Ro(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 Io(e){if(e==="baked"||e==="dynamic")return e}function Vo(e){return e==="auto"?"auto":le(e)}var K=class extends ko{constructor(){super(...arguments);this._scene=null}static get observedAttributes(){return[...Ho]}getScene(){return this._scene}_readOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={},s=Do(this.getAttribute("perspective"));s!==void 0&&(r.perspective=s);let i=le(this.getAttribute("rot-x"));i!==void 0&&(r.rotX=i);let c=le(this.getAttribute("rot-y"));c!==void 0&&(r.rotY=c);let l=le(this.getAttribute("zoom"));l!==void 0&&(r.zoom=l),r.textureLighting=Io(this.getAttribute("texture-lighting"))??"baked";let a=Vo(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=Ro(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=le(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=le(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=Le(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 Be=require("@layoutit/polycss-core"),zo=typeof HTMLElement<"u"?HTMLElement:class{},Bo=["src","mtl","position","scale","rotation","auto-center"];function xe(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 jt(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return xe(e)}}function Fo(e){return e.closest("poly-scene")??null}function No(e){if(e.length===0)return e;let n=(0,Be.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 ye=class extends zo{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Bo]}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:xe(this.getAttribute("position")),scale:jt(this.getAttribute("scale")),rotation:xe(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=Fo(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,i;try{i=await(0,Be.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:No(i.polygons)}),this._parseResult=i,this._handle=c.add(i,{position:xe(this.getAttribute("position")),scale:jt(this.getAttribute("scale")),rotation:xe(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var Xo=typeof HTMLElement<"u"?HTMLElement:class{},Yo=["vertices","color","texture","uvs","position","scale","rotation"];function qt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function mt(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 $o(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return mt(e)}}function Uo(e){return e.closest("poly-scene")??null}var Fe=class extends Xo{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Yo]}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=Uo(this);if(!t)return;let o=t.getScene();if(!o)return;let r=qt(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=qt(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:mt(this.getAttribute("position")),scale:$o(this.getAttribute("scale")),rotation:mt(this.getAttribute("rotation"))})}};function N(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Ne(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 se(e){if(e!==null)return!(e==="false"||e==="0")}function Xe(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 Ye(e){if(e==="x"||e==="y")return e}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"],$e=class extends Wo{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Zo]}_readAnimate(){let t=N(this.getAttribute("animate-speed")),o=Ye(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:se(r)}:{}}}_readOptions(){let t={},o=se(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=se(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=Xe(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 K)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=De(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 Go=typeof HTMLElement<"u"?HTMLElement:class{},jo=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Ue=class extends Go{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...jo]}_readAnimate(){let t=N(this.getAttribute("animate-speed")),o=Ye(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:se(r)}:{}}}_readOptions(){let t={},o=se(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=se(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=Xe(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 K)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=Re(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 qo=typeof HTMLElement<"u"?HTMLElement:class{},Ko=["perspective","zoom","rot-x","rot-y","target","distance"],We=class extends qo{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Ko]}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:Ne(this.getAttribute("target")),distance:N(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=be(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=be(s),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var Jo=typeof HTMLElement<"u"?HTMLElement:class{},Qo=["zoom","rot-x","rot-y","target","distance"],Ze=class extends Jo{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Qo]}getCamera(){return this._camera}_readOptions(){return{zoom:N(this.getAttribute("zoom")),rotX:N(this.getAttribute("rot-x")),rotY:N(this.getAttribute("rot-y")),target:Ne(this.getAttribute("target")),distance:N(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Se(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 er=typeof HTMLElement<"u"?HTMLElement:class{},tr=["mode","target","size","enabled"];function Kt(e){if(e==="translate"||e==="rotate")return e}var Ge=class extends er{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...tr]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof K)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 ye?r:null}_readOptions(){let t={},o=Kt(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=ze(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=Kt(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};var nr=typeof HTMLElement<"u"?HTMLElement:class{},or=["multiple","clear-on-miss"],je=class extends nr{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...or]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof K)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=Ie(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())}};U($,require("@layoutit/polycss-core"),module.exports);0&&(module.exports={PolyMapControlsElement,PolyMeshElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPolygonElement,PolySceneElement,PolySelectElement,PolyTransformControlsElement,createPolyMapControls,createPolyOrbitControls,createPolyOrthographicCamera,createPolyPerspectiveCamera,createPolyScene,createSelect,createTransformControls,injectPolyBaseStyles,...require("@layoutit/polycss-core")});
@@ -0,0 +1,220 @@
1
+ import { P as PolySceneHandle, a as PolyMeshHandle } from './PolySelectElement-DCuYJb5J.cjs';
2
+ export { b as PolyCameraOptions, c as PolyMapControlsElement, d as PolyMeshElement, e as PolyMeshTransform, f as PolyOrbitControlsElement, g as PolyOrthographicCameraElement, h as PolyOrthographicCameraHandle, i as PolyOrthographicCameraOptions, j as PolyPerspectiveCameraElement, k as PolyPerspectiveCameraHandle, l as PolyPerspectiveCameraOptions, m as PolyPolygonElement, n as PolySceneElement, o as PolySceneOptions, p as PolySelectElement, q as PolyTransformControlsElement, r as createPolyOrthographicCamera, s as createPolyPerspectiveCamera, t as createPolyScene } from './PolySelectElement-DCuYJb5J.cjs';
3
+ import { Vec3 } from '@layoutit/polycss-core';
4
+ export * from '@layoutit/polycss-core';
5
+
6
+ /**
7
+ * Shared types, constants, and utilities for orbit/map controls factories.
8
+ * Not part of the public API surface — use createPolyOrbitControls or
9
+ * createPolyMapControls.
10
+ */
11
+
12
+ interface PolyControlsAnimateOptions {
13
+ /**
14
+ * Rotation rate in degrees per 60 Hz-equivalent frame. The tick is
15
+ * dt-clamped so 0.3 deg/frame ≈ 18 deg/sec on every refresh rate.
16
+ * Default: 0.3.
17
+ */
18
+ speed?: number;
19
+ /** Rotation axis. Default: "y" (yaw, rotates around vertical world Z). */
20
+ axis?: "x" | "y";
21
+ /** Halt the loop while a pointer drag is in progress. Default: true. */
22
+ pauseOnInteraction?: boolean;
23
+ }
24
+ interface PolyControlsBaseOptions {
25
+ /** Pointer-drag. Default: true. */
26
+ drag?: boolean;
27
+ /** Wheel / pinch zoom. Default: true. */
28
+ wheel?: boolean;
29
+ /**
30
+ * When `true`, wheel events change `distance` (camera pull-back in CSS px)
31
+ * instead of `zoom`. Mirrors Three.js OrbitControls dolly behaviour.
32
+ * Default: false (zoom mode).
33
+ */
34
+ dolly?: boolean;
35
+ /**
36
+ * Drag-direction inversion. `false` = natural, `true` = invert (×-1),
37
+ * a number multiplies sensitivity (negative inverts). Default: false.
38
+ */
39
+ invert?: boolean | number;
40
+ /** Minimum CSS zoom. Default: 0.1. */
41
+ minZoom?: number;
42
+ /** Maximum CSS zoom. Default: 10. */
43
+ maxZoom?: number;
44
+ /** Minimum dolly distance in CSS pixels. Default: 0. Only used when `dolly: true`. */
45
+ minDistance?: number;
46
+ /** Maximum dolly distance in CSS pixels. Default: Infinity. Only used when `dolly: true`. */
47
+ maxDistance?: number;
48
+ /** Auto-rotate. Pass false (or omit) to disable. */
49
+ animate?: false | PolyControlsAnimateOptions;
50
+ }
51
+ interface PolyControlsCamera {
52
+ rotX: number;
53
+ rotY: number;
54
+ zoom: number;
55
+ target: Vec3;
56
+ distance: number;
57
+ }
58
+ interface PolyControlsChangeEvent {
59
+ type: "change";
60
+ camera: PolyControlsCamera;
61
+ }
62
+ interface PolyControlsInteractionEvent {
63
+ type: "start" | "end";
64
+ camera: PolyControlsCamera;
65
+ }
66
+ type PolyControlsEvent = PolyControlsChangeEvent | PolyControlsInteractionEvent;
67
+ type PolyControlsListener<E extends PolyControlsEvent = PolyControlsEvent> = (event: E) => void;
68
+ interface PolyControlsHandle {
69
+ update(partial: PolyControlsBaseOptions): void;
70
+ resume(): void;
71
+ pause(): void;
72
+ destroy(): void;
73
+ addEventListener<T extends PolyControlsEvent["type"]>(type: T, listener: PolyControlsListener<Extract<PolyControlsEvent, {
74
+ type: T;
75
+ }>>): void;
76
+ removeEventListener<T extends PolyControlsEvent["type"]>(type: T, listener: PolyControlsListener<Extract<PolyControlsEvent, {
77
+ type: T;
78
+ }>>): void;
79
+ hasEventListener<T extends PolyControlsEvent["type"]>(type: T, listener: PolyControlsListener<Extract<PolyControlsEvent, {
80
+ type: T;
81
+ }>>): boolean;
82
+ }
83
+
84
+ /**
85
+ * createPolyOrbitControls — orbit-mode camera input for a PolyScene.
86
+ *
87
+ * Left-drag rotates rotX / rotY around the target (orbit). Wheel zooms or
88
+ * dollies. Mirrors Three.js OrbitControls semantics.
89
+ *
90
+ * For map/pan semantics (left-drag pans, right-drag orbits) use
91
+ * `createPolyMapControls` instead.
92
+ */
93
+
94
+ type PolyOrbitControlsOptions = PolyControlsBaseOptions;
95
+ type PolyOrbitControlsHandle = PolyControlsHandle;
96
+ declare function createPolyOrbitControls(scene: PolySceneHandle, options?: PolyOrbitControlsOptions): PolyOrbitControlsHandle;
97
+
98
+ /**
99
+ * createPolyMapControls — map/pan-mode camera input for a PolyScene.
100
+ *
101
+ * Left-drag pans the target (slippy-map semantics — terrain follows pointer).
102
+ * Right-drag or Shift+left-drag orbits. Wheel zooms or dollies.
103
+ * Mirrors Three.js MapControls semantics.
104
+ *
105
+ * For orbit-only semantics (left-drag orbits) use `createPolyOrbitControls`
106
+ * instead.
107
+ */
108
+
109
+ type PolyMapControlsOptions = PolyControlsBaseOptions;
110
+ type PolyMapControlsHandle = PolyControlsHandle;
111
+ declare function createPolyMapControls(scene: PolySceneHandle, options?: PolyMapControlsOptions): PolyMapControlsHandle;
112
+
113
+ /**
114
+ * createSelect — additive selection layer for vanilla polycss scenes.
115
+ * Mirrors the React `<Select>` API: tracks one or more selected
116
+ * meshes, fires `onChange` whenever the set changes, supports
117
+ * single-click toggle (re-clicking the selected mesh deselects it),
118
+ * shift/meta/ctrl + click for multi-select extension, and a JS bbox
119
+ * hit-test fallback for clicks that fall through native polygon
120
+ * hit-testing (e.g. CSS `border-shape` clipping).
121
+ *
122
+ * Usage:
123
+ * const select = createSelect(scene, { onChange: (meshes) => ... });
124
+ * select.set([handle]); // imperative selection
125
+ * select.toggle(handle);
126
+ * select.clear();
127
+ * select.destroy(); // remove listeners
128
+ */
129
+
130
+ interface PolySelectOptions {
131
+ /** Allow multiple meshes selected at once. Default false. */
132
+ multiple?: boolean;
133
+ /** When true (default), clicking the background clears selection.
134
+ * Set false to keep the current selection on background clicks. */
135
+ clearOnMiss?: boolean;
136
+ /** Optional filter applied to every selection change — return the
137
+ * array that should become the new selection (drop / reorder). */
138
+ filter?: (meshes: PolyMeshHandle[]) => PolyMeshHandle[];
139
+ /** Fires after every selection change with the new array. */
140
+ onChange?: (meshes: PolyMeshHandle[]) => void;
141
+ /** Fires when a click resolves to no mesh (background click). */
142
+ onPointerMissed?: (event: MouseEvent) => void;
143
+ }
144
+ interface PolySelectionHandle {
145
+ /** Current selection. Reference is stable until selection changes. */
146
+ readonly selected: ReadonlyArray<PolyMeshHandle>;
147
+ /** Replace selection wholesale. */
148
+ set(next: PolyMeshHandle[]): void;
149
+ /** Add to selection (or replace, when `multiple` is false). */
150
+ add(mesh: PolyMeshHandle): void;
151
+ /** Remove from selection. No-op if not present. */
152
+ remove(mesh: PolyMeshHandle): void;
153
+ /** Toggle membership. With single-mode, toggling a non-selected
154
+ * mesh replaces selection; toggling the selected mesh clears. */
155
+ toggle(mesh: PolyMeshHandle): void;
156
+ /** Clear selection. */
157
+ clear(): void;
158
+ /** Membership test. */
159
+ has(mesh: PolyMeshHandle): boolean;
160
+ /** Remove the host listener. Idempotent. */
161
+ destroy(): void;
162
+ }
163
+ declare function createSelect(scene: PolySceneHandle, options?: PolySelectOptions): PolySelectionHandle;
164
+
165
+ type Mode = "translate" | "rotate";
166
+ interface PolyTransformControlsObjectChangeEvent {
167
+ object: PolyMeshHandle;
168
+ position?: Vec3;
169
+ rotation?: Vec3;
170
+ }
171
+ interface PolyTransformControlsOptions {
172
+ /** Drag mode. "translate" → axial arrows, "rotate" → axial rings. */
173
+ mode?: Mode;
174
+ /** Multiplier on gizmo size (shaft length / ring radius). Default 1. */
175
+ size?: number;
176
+ /** Snap step (CSS pixels) for translate-mode. */
177
+ translationSnap?: number | null;
178
+ /** Snap step (degrees) for rotate-mode. */
179
+ rotationSnap?: number | null;
180
+ /** Show / hide axis pairs. Default true for all. */
181
+ showX?: boolean;
182
+ showY?: boolean;
183
+ showZ?: boolean;
184
+ /** Disable interaction without unmounting. Default true. */
185
+ enabled?: boolean;
186
+ /** Fires for any transform change. Argument-less, mirrors three.js. */
187
+ onChange?: () => void;
188
+ /** Fires with the new transform during drag. The gizmo also calls
189
+ * `target.setTransform` internally; this callback lets parent code
190
+ * mirror the change into its own state. */
191
+ onObjectChange?: (event: PolyTransformControlsObjectChangeEvent) => void;
192
+ /** Fires once on drag start. */
193
+ onMouseDown?: () => void;
194
+ /** Fires once on drag end. */
195
+ onMouseUp?: () => void;
196
+ /** Fires with `true` on drag start, `false` on drag end. */
197
+ onDraggingChanged?: (dragging: boolean) => void;
198
+ }
199
+ interface PolyTransformControlsHandle {
200
+ /** Bind to a mesh — gizmo follows the mesh's transform. Pass `null`
201
+ * to detach. Calling `attach` again with a new target swaps the
202
+ * binding without rebuilding the gizmo geometry. */
203
+ attach(mesh: PolyMeshHandle | null): void;
204
+ /** Equivalent to `attach(null)`. */
205
+ detach(): void;
206
+ /** Switch between translate and rotate. Tears down the old gizmo
207
+ * and rebuilds the new one. */
208
+ setMode(mode: Mode): void;
209
+ /** Re-read the target's transform and reposition the gizmo. Call
210
+ * after mutating `target.setTransform` externally if you want the
211
+ * gizmo to follow. */
212
+ update(): void;
213
+ /** Remove all listeners + gizmo meshes from the scene. Idempotent. */
214
+ destroy(): void;
215
+ }
216
+ declare function createTransformControls(scene: PolySceneHandle, options?: PolyTransformControlsOptions): PolyTransformControlsHandle;
217
+
218
+ declare function injectPolyBaseStyles(doc?: Document): void;
219
+
220
+ export { type PolyControlsAnimateOptions, type PolyControlsBaseOptions, type PolyControlsCamera, type PolyControlsChangeEvent, type PolyControlsEvent, type PolyControlsHandle, type PolyControlsInteractionEvent, type PolyControlsListener, type PolyMapControlsHandle, type PolyMapControlsOptions, PolyMeshHandle, type PolyOrbitControlsHandle, type PolyOrbitControlsOptions, PolySceneHandle, type PolySelectOptions, type PolySelectionHandle, type PolyTransformControlsHandle, type PolyTransformControlsObjectChangeEvent, type PolyTransformControlsOptions, createPolyMapControls, createPolyOrbitControls, createSelect, createTransformControls, injectPolyBaseStyles };