@layoutit/polycss 0.2.0 → 0.2.2

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 CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Xt=Object.defineProperty;var Vo=Object.getOwnPropertyDescriptor;var Fo=Object.getOwnPropertyNames;var zo=Object.prototype.hasOwnProperty;var Bo=(e,n)=>{for(var t in n)Xt(e,t,{get:n[t],enumerable:!0})},Yt=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Fo(n))!zo.call(e,r)&&r!==t&&Xt(e,r,{get:()=>n[r],enumerable:!(o=Vo(n,r))||o.enumerable});return e},he=(e,n,t)=>(Yt(e,n,"default"),t&&Yt(t,n,"default"));var No=e=>Yt(Xt({},"__esModule",{value:!0}),e);var fe={};Bo(fe,{PolyMapControlsElement:()=>It,PolyMeshElement:()=>je,PolyOrbitControlsElement:()=>Ht,PolyOrthographicCameraElement:()=>Ft,PolyPerspectiveCameraElement:()=>Vt,PolyPolygonElement:()=>kt,PolySceneElement:()=>Ce,PolySelectElement:()=>Bt,PolyTransformControlsElement:()=>zt,createPolyFirstPersonControls:()=>So,createPolyMapControls:()=>Et,createPolyOrbitControls:()=>Pt,createPolyOrthographicCamera:()=>yt,createPolyPerspectiveCamera:()=>Ke,createPolyScene:()=>gt,createSelect:()=>Ct,createTransformControls:()=>Tt,injectPolyBaseStyles:()=>pt});module.exports=No(fe);var te=require("@layoutit/polycss-core");var qt=require("@layoutit/polycss-core"),Qt=50,Kt=[.4,-.7,.59],Jt="#ffffff",en=1,tn="#ffffff",nn=.4,ze=4096,Cn=1,Yo=.1,Xo=1,Vn=ze*ze,$o=Vn*3,Gt=2048,Uo=4*1024*1024,Go=16*1024*1024,jo=.995,Wo=12,Ve=new Map,jt=new WeakMap,ie=.001,pe=1e-9,Zo=1e-4,qo=.1,An=.01,Qo=.75,Ko=1,Jo=250,Mn=1.5,er=.75,tr=3,nr=2,or=4,Wt=64,ke=64,Se=64,rr=128,Sn=50,Ln=1e-7,wn=16,$t=.9,sr=.05,ir=Number.POSITIVE_INFINITY,ar=.6;function lr(e){let n=Ve.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}),Ve.set(e,n),n.then(()=>{Ve.get(e)===n&&Ve.delete(e)},()=>{Ve.get(e)===n&&Ve.delete(e)})),n}function lt(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Xo,Math.max(Yo,n))}function on(e,n){let t=e.toFixed(n).replace(/\.?0+$/,"");return Object.is(Number(t),-0)?"0":t}function Be(e,n=or){let t=on(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function we(e,n=tr){return e.map(t=>on(t,n)).join(",")}function Fn(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=pe)return!1;let a=Math.sign(i);if(n===0)n=a;else if(a!==n)return!1}return!0}function cr(e){let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-o[1]*r[0]}return n/2}function ur(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],a=o[1]-t[1],l=r*a-s*i;if(Math.abs(l)<=pe)return null;let u=t[0]-e[0],p=t[1]-e[1],d=(u*a-p*i)/l;return[e[0]+d*r,e[1]+d*s]}function rn(e,n){if(e.length<6||e.length%2!==0||n<=0)return e;let t=[];for(let l=0;l<e.length;l+=2)t.push([e[l],e[l+1]]);if(!Fn(t))return Ze(e,n);let o=cr(t);if(Math.abs(o)<=pe)return Ze(e,n);let r=o>0?1:-1,s=[];for(let l=0;l<t.length;l++){let u=t[l],p=t[(l+1)%t.length],d=p[0]-u[0],f=p[1]-u[1],g=Math.hypot(d,f);if(g<=pe)return Ze(e,n);let m=r*(f/g)*n,h=r*(-d/g)*n;s.push({a:[u[0]+m,u[1]+h],b:[p[0]+m,p[1]+h]})}let i=[],a=Math.max(2,n*4);for(let l=0;l<t.length;l++){let u=s[(l+t.length-1)%t.length],p=s[l],d=ur(u.a,u.b,p.a,p.b);if(!d)return Ze(e,n);let f=t[l],g=d[0]-f[0],m=d[1]-f[1],h=Math.hypot(g,m);h>a?i.push(f[0]+g/h*a,f[1]+m/h*a):i.push(d[0],d[1])}return i}function Tn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function sn(e){let t=e?.defaultView?.__polycssProjectiveQuadGuards,o=t?.maxWeightRatio,r=Math.max(0,Tn(t?.denomEps,sr)),s=typeof o=="number"&&Number.isFinite(o)&&o>0?Math.max(1,o):ir,i=Math.max(0,Tn(t?.bleed,ar));return{denomEps:r,maxWeightRatio:s,bleed:i,disableGuards:t?.disableGuards===!0}}function _n(e,n){if(e.length!==4||!Fn(e))return null;let[t,o,r,s]=e,i=t[0]-o[0]+r[0]-s[0],a=t[1]-o[1]+r[1]-s[1],l=o[0]-r[0],u=s[0]-r[0],p=o[1]-r[1],d=s[1]-r[1],f=l*d-p*u;if(Math.abs(f)<=pe)return null;let g=(i*d-a*u)/f,m=(l*a-p*i)/f,h=[1,1+g,1+g+m,1+m];if(h.some(E=>!Number.isFinite(E)))return null;let y=Math.min(...h),v=Math.max(...h);return!n.disableGuards&&(y<=n.denomEps||v/y>n.maxWeightRatio)?null:{g,h:m,w1:1+g,w3:1+m}}function dr(e,n,t,o,r,s,i,a){if(e.length!==8)return null;let l=[[e[0],e[1]],[e[2],e[3]],[e[4],e[5]],[e[6],e[7]]];if(!_n(l,a))return null;let u=rn(e,a.bleed),p=[[u[0],u[1]],[u[2],u[3]],[u[4],u[5]],[u[6],u[7]]],d=_n(p,a);if(!d)return null;let{g:f,h:g,w1:m,w3:h}=d,[y,v,,E]=p,A=[r+y[0]*n[0]+y[1]*t[0],s+y[0]*n[1]+y[1]*t[1],i+y[0]*n[2]+y[1]*t[2]],x=([O,M],P)=>[(P-1)*r+(P*O-y[0])*n[0]+(P*M-y[1])*t[0],(P-1)*s+(P*O-y[0])*n[1]+(P*M-y[1])*t[1],(P-1)*i+(P*O-y[0])*n[2]+(P*M-y[1])*t[2]],C=[...x(v,m),f,...x(E,h),g,o[0],o[1],o[2],0,A[0],A[1],A[2],1];for(let O=0;O<8;O+=1)C[O]/=Wt;return we(C,6)}function rt(e,n=nr){let t=on(e,n);return Number(t)===0?"0":`${t}%`}function mr(e,n,t,o,r,s){let i=(e-t)*(s-o)-(n-o)*(r-t);return Math.abs(i)>Ln?!1:(e-t)*(e-r)+(n-o)*(n-s)<=Ln}function pr(e,n=Sn,t=Sn){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,a]=e[r],[l,u]=e[s];if(mr(n,t,i,a,l,u))return!0;a>t!=u>t&&n<(l-i)*(t-a)/(u-a)+i&&(o=!o)}return o}function zn(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function fr(e,n){let t=zn(e);if(t<=0)return 1;let o=Math.max(1,...e.map(i=>Math.max(i.width,i.height))),r=Gt/o,s=Math.sqrt(n/(t*4));return lt(Math.min(r,s))}function hr(e,n){let t=zn(e),o=.5;return t<=Vn?o=1:t<=$o&&(o=.75),lt(Math.min(o,fr(e,n)))}function gr(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function yr(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function br(e,n,t){let o=gr(e,n),r=yr(e,n),s=o>Gt?Gt/o:1,i=r>t?Math.sqrt(t/r):1;return Math.min(s,i)}function xr(e,n,t){let o=hr(n.pages,t),r=o===1?n:it(e,o);for(let s=0;s<4;s++){let i=br(r.pages,o,t);if(i>=1)break;let a=lt(o*i*jo);if(a>=o)break;o=a,r=it(e,o)}return{packed:r,atlasScale:o}}function vr(e){return Bn(e)?Uo:Go}function Bn(e){if(!e)return!1;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return t?t("(pointer: coarse)").matches||t("(hover: none)").matches:!1}function Pr(e,n){return e!==void 0&&e!=="auto"||Bn(n)?Se:rr}function Er(e,n){let t=e.matrix.split(",").map(o=>Number(o));return t.length!==16||t.some(o=>!Number.isFinite(o))?e.canonicalMatrix:(t[0]*=e.canvasW/n,t[1]*=e.canvasW/n,t[2]*=e.canvasW/n,t[4]*=e.canvasH/n,t[5]*=e.canvasH/n,t[6]*=e.canvasH/n,we(t))}function kn(e,n){for(let t of e.entries)t&&(t.atlasCanonicalSize=n,t.atlasMatrix=Er(t,n));return e}function Le(e){return e.atlasCanonicalSize??Se}function Nn(e,n,t){let o=Pr(n,t);if(n!==void 0&&n!=="auto"){let i=lt(n);return{packed:kn(it(e,i),o),atlasScale:i,atlasCanonicalSize:o}}let r=it(e,1),s=xr(e,r,vr(t));return{packed:kn(s.packed,o),atlasScale:s.atlasScale,atlasCanonicalSize:o}}function Cr(e){return Math.max(Cn,Math.ceil(Cn/e))}function Ae(e,n,t=1,o=0,r=0,s=1,i=0,a=0){e.setTransform(t*n,o*n,r*n,s*n,i*n,a*n)}function Te(e){let n=(0,qt.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function an({r:e,g:n,b:t}){return`${e},${n},${t}`}function Ar(e){return(0,qt.parsePureColor)(e)?.alpha??1}function Mr({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 ee(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,s=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`(^|;)\\s*${s}\\s*:[^;]*`,"i"),a=i.test(o)?o.replace(i,(l,u)=>`${u}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;a!==o&&e.setAttribute("style",a)}function ye(e,n){let t=e.getAttribute("style")??"";if(!t)return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`^\\s*${o}\\s*:`,"i"),s=t.split(";").map(i=>i.trim()).filter(i=>i&&!r.test(i)).join(";");s?e.setAttribute("style",s):e.removeAttribute("style")}function Yn(e,n,t,o,r){let s=Te(e),i=Te(t),a=Te(o),l=a.r/255*r+i.r/255*n,u=a.g/255*r+i.g/255*n,p=a.b/255*r+i.b/255*n,d=Math.max(0,Math.min(255,Math.round(s.r*l))),f=Math.max(0,Math.min(255,Math.round(s.g*u))),g=Math.max(0,Math.min(255,Math.round(s.b*p))),m=Ar(e);return m<1?`rgba(${d}, ${f}, ${g}, ${m})`:Mr({r:d,g:f,b:g})}function Xn(e,n,t,o){let r=Te(n),s=Te(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 Sr({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 Lr(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(),Ae(e,i),e.globalCompositeOperation="multiply",e.fillStyle=Sr(s),e.fillRect(n,t,o,r),e.restore())}function wr(e,n,t,o,r,s,i){let a=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,u=Math.max(r/a,s/l),p=a*u,d=l*u;Ae(e,i),e.drawImage(n,t+(r-p)/2,o+(s-d)/2,p,d)}function st(e){return`${e[0]},${e[1]},${e[2]}`}function Tr(e,n){let t=st(e),o=st(n);return t<o?`${t}|${o}`:`${o}|${t}`}function $n(e,n){return st(e)<st(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 _r(e){return!e.texture}function Qe(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function ct(e){if(e.length<3)return null;let n=e[0],t=0,o=0,r=0;for(let i=1;i+1<e.length;i++){let a=e[i],l=e[i+1],u=[a[0]-n[0],a[1]-n[1],a[2]-n[2]],p=[l[0]-n[0],l[1]-n[1],l[2]-n[2]];t-=u[1]*p[2]-u[2]*p[1],o-=u[2]*p[0]-u[0]*p[2],r-=u[0]*p[1]-u[1]*p[0]}let s=Math.hypot(t,o,r);return s<=pe?null:(t/=s,o/=s,r/=s,[t,o,r])}function Ne(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function kr(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 Rr(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=Qe(e.vertices,n,t),r=ct(o);return r?{pts:o,normal:r,planeD:Ne(r,o[0]),optimizable:_r(e)}:null}function Or(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:Un(e,n)}function Un(e,n){return!e||!n||Ne(e.normal,n.normal)<1-Zo?!1:Math.abs(e.planeD-n.planeD)<=qo}function Rn(e,n){if(!e)return null;let t=n.directionalLight,o=n.ambientLight,r=t?.direction??Kt,s=t?.color??Jt,i=Math.max(0,t?.intensity??en),a=o?.color??tn,l=Math.max(0,o?.intensity??nn),u=Math.hypot(r[0],r[1],r[2])||1,p=r[0]/u,d=r[1]/u,f=r[2]/u,g=i*Math.max(0,e.normal[0]*p+e.normal[1]*d+e.normal[2]*f),m=Xn(g,s,a,l);return m.r*.2126+m.g*.7152+m.b*.0722}function Dr(e){let n=[...e],t=Math.abs(n[0])>pe?0:Math.abs(n[1])>pe?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 qe(e,n,t,o,r={}){let s=Ne(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],a=Math.hypot(i[0],i[1],i[2]);if(a<=pe)return null;let l=[i[0]/a,i[1]/a,i[2]/a],u=[t[1]*l[2]-t[2]*l[1],t[2]*l[0]-t[0]*l[2],t[0]*l[1]-t[1]*l[0]],p=Math.hypot(u[0],u[1],u[2]);if(p<=pe)return null;let d=[u[0]/p,u[1]/p,u[2]/p],f=e.map(w=>{let I=w[0]-n[0],F=w[1]-n[1],B=w[2]-n[2];return[I*l[0]+F*l[1]+B*l[2],I*d[0]+F*d[1]+B*d[2]]}),g=r.boundsOrigin??n,m=n[0]-g[0],h=n[1]-g[1],y=n[2]-g[2],v=m*l[0]+h*l[1]+y*l[2],E=m*d[0]+h*d[1]+y*d[2],A=1/0,x=1/0,C=-1/0,O=-1/0;for(let[w,I]of f){let F=w+v,B=I+E;F<A&&(A=F),F>C&&(C=F),B<x&&(x=B),B>O&&(O=B)}let M=C-A,P=O-x;if(!Number.isFinite(M)||!Number.isFinite(P))return null;let X=r.snapBounds?Math.floor(A+ie):A,$=r.snapBounds?Math.floor(x+ie):x,W=r.snapBounds?Math.ceil(C-ie):C,ne=r.snapBounds?Math.ceil(O-ie):O,S=Math.max(1,r.snapBounds?W-X:Math.ceil(M)),U=Math.max(1,r.snapBounds?ne-$:Math.ceil(P));return{xAxis:l,yAxis:d,local2D:f,shiftX:v-X,shiftY:E-$,canvasW:S,canvasH:U,pixelArea:S*U,rawArea:M*P}}function Hr(e,n,t,o){let r=0,s=0;for(let i of e){let a=n[i];if(!a)return null;let l=qe(a.pts,a.pts[0],a.normal,t,{boundsOrigin:o,snapBounds:!0});if(!l)return null;r+=l.pixelArea,s+=l.rawArea}return{pixelArea:r,rawArea:s}}function Ir(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 a=n[i];if(!a)continue;let l=[a.pts[1][0]-a.pts[0][0],a.pts[1][1]-a.pts[0][1],a.pts[1][2]-a.pts[0][2]],u=qe(a.pts,a.pts[0],a.normal,l);o&&u?(o.pixelArea+=u.pixelArea,o.rawArea+=u.rawArea):o=null;for(let p=0;p<a.pts.length;p++){let d=$n(a.pts[p],a.pts[(p+1)%a.pts.length]),f=qe(a.pts,a.pts[0],a.normal,d);if(!f)continue;let g=Dr(f.xAxis);if(s.has(g))continue;s.add(g);let m=Hr(e,n,f.xAxis,t);m&&(!r||m.pixelArea<r.pixelArea||m.pixelArea===r.pixelArea&&m.rawArea<r.rawArea-ie)&&(r={xAxis:f.xAxis,...m})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+ie)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function ln(e,n){let t=n.tileSize??Qt,o=n.layerElevation??t,r=e.map(d=>Rr(d,t,o)),s=new Map,i=e.map(()=>new Set),a=e.map(()=>new Set);for(let d=0;d<e.length;d++){let f=e[d].vertices;if(!(!f||f.length<3))for(let g=0;g<f.length;g++){let m=Tr(f[g],f[(g+1)%f.length]),h=s.get(m),y={polygon:d,edge:g};h?h.push(y):s.set(m,[y])}}let l=e.map(()=>new Set);for(let d of s.values())if(!(d.length<2))for(let f=0;f<d.length;f++)for(let g=f+1;g<d.length;g++){let m=d[f],h=d[g],y=m.polygon,v=h.polygon;if(e[y].texture&&e[v].texture&&(a[m.polygon].add(m.edge),a[h.polygon].add(h.edge)),Un(r[y],r[v]))i[m.polygon].add(m.edge),i[h.polygon].add(h.edge);else{let E=Rn(r[y],n),A=Rn(r[v],n);E!==null&&A!==null&&(E<=A+An&&i[m.polygon].add(m.edge),A<=E+An&&i[h.polygon].add(h.edge))}Or(r[y],r[v])&&(l[y].add(v),l[v].add(y))}let u=Array(e.length).fill(void 0),p=new Set;for(let d=0;d<e.length;d++){if(p.has(d)||!r[d]?.optimizable)continue;let f=[],g=[d];for(p.add(d);g.length>0;){let h=g.pop();f.push(h);for(let y of l[h])p.has(y)||(p.add(y),g.push(y))}if(f.length<2)continue;let m=Ir(f,r);if(m)for(let h of f)u[h]={xAxis:m.xAxis,boundsOrigin:m.boundsOrigin,seamEdges:i[h],textureEdgeRepairEdges:a[h]}}for(let d=0;d<e.length;d++)!u[d]&&(i[d].size>0||a[d].size>0)&&(u[d]={seamEdges:i[d],textureEdgeRepairEdges:a[d]});return u}function Vr(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 On(e,n,t,o){if(o.optimize&&o.fixedXAxis)return qe(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((a,l)=>l):[0]);for(let a of i){let l=(a+1)%e.length,u=s?$n(e[a],e[l]):[e[l][0]-e[a][0],e[l][1]-e[a][1],e[l][2]-e[a][2]],p=qe(e,n,t,u,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});p&&(!r||p.pixelArea<r.pixelArea||p.pixelArea===r.pixelArea&&p.rawArea<r.rawArea-ie)&&(r=p)}return r}function Fr(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=ie)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])>ie||Math.abs(t[0])>ie||n[1]-n[0]<=ie||t[1]-t[0]<=ie))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,a=s+e.shiftY,l=Math.abs(i-n[0])<=ie||Math.abs(i-n[1])<=ie,u=Math.abs(a-t[0])<=ie||Math.abs(a-t[1])<=ie;if(!l||!u)return!1}return!0}function Gn(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,a]=n,l=t[0],u=t[1],p=o[0],d=o[1],f=r[0],g=r[1],m=s[0],h=1-s[1],y=i[0],v=1-i[1],E=a[0],A=1-a[1],x=y-m,C=v-h,O=E-m,M=A-h,P=x*M-O*C;if(Math.abs(P)<=1e-9)return null;let X=p-l,$=f-l,W=d-u,ne=g-u,S={a:(X*M-$*C)/P,b:(x*$-O*X)/P,c:(W*M-ne*C)/P,d:(x*ne-O*W)/P,e:0,f:0};return S.e=l-S.a*m-S.b*h,S.f=u-S.c*m-S.d*h,S}function jn(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],a=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(a))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,a),r=Math.max(r,a)}return{minU:n,minV:t,maxU:o,maxV:r}}function zr(e,n,t,o,r,s,i,a){let u=Qe(e.vertices,n,t).map(f=>{let g=f[0]-o[0],m=f[1]-o[1],h=f[2]-o[2];return[g*r[0]+m*r[1]+h*r[2]+i,g*s[0]+m*s[1]+h*s[2]+a]}),p=Gn(u,e.uvs),d=jn(e.uvs);return!p&&!d?null:{screenPts:u.flatMap(([f,g])=>[f,g]),uvAffine:p,uvSampleRect:d}}function Ze(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 a=s[i]-t,l=s[i+1]-o,u=Math.hypot(a,l);u<=ie||(s[i]+=a/u*n,s[i+1]+=l/u*n)}return s}function Zt(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 cn(e,n,t,o,r){let{vertices:s,texture:i,uvs:a}=e;if(!s||s.length<3)return null;let l=t.tileSize??Qt,u=t.layerElevation??l,p=Qe(s,l,u),d=p[0],f=p[1],g=[f[0]-d[0],f[1]-d[1],f[2]-d[2]];if(Math.hypot(g[0],g[1],g[2])===0)return null;let h=ct(p);if(!h)return null;let y=On(p,d,h,{optimize:!1}),v=i||y&&Fr(y)?y:On(p,d,h,{optimize:!0,fixedXAxis:r?.xAxis,boundsOrigin:r?.boundsOrigin,snapBounds:!!r,seamEdges:r?.seamEdges});if(!v)return null;let{xAxis:E,yAxis:A,local2D:x}=v,C=i&&r?.textureEdgeRepairEdges?.size?r.textureEdgeRepairEdges:null,O=!!(i&&C),M=v.shiftX,P=v.shiftY,X=v.canvasW,$=v.canvasH,W=[];for(let[V,D]of x)W.push(V+M,D+P);let ne=d[0]-M*E[0]-P*A[0],S=d[1]-M*E[1]-P*A[1],U=d[2]-M*E[2]-P*A[2],w=we([E[0],E[1],E[2],0,A[0],A[1],A[2],0,h[0],h[1],h[2],0,ne,S,U,1]),I=we([E[0]*X,E[1]*X,E[2]*X,0,A[0]*$,A[1]*$,A[2]*$,0,h[0],h[1],h[2],0,ne,S,U,1]),F=we([E[0]*X/Se,E[1]*X/Se,E[2]*X/Se,0,A[0]*$/Se,A[1]*$/Se,A[2]*$/Se,0,h[0],h[1],h[2],0,ne,S,U,1]),B=!i&&s.length===4?dr(W,E,A,h,ne,S,U,o):null,J=t.directionalLight,le=t.ambientLight,k=J?.direction??Kt,j=J?.color??Jt,Z=Math.max(0,J?.intensity??en),se=le?.color??tn,oe=Math.max(0,le?.intensity??nn),de=Math.hypot(k[0],k[1],k[2])||1,ge=k[0]/de,me=k[1]/de,ue=k[2]/de,be=Z*Math.max(0,h[0]*ge+h[1]*me+h[2]*ue),xe=Xn(be,j,se,oe),c=Yn(e.color??"#cccccc",be,j,se,oe),b=null,R=null;i&&a&&a.length>=3&&a.length===s.length&&(R=jn(a),b=Gn(x.map(([V,D])=>[V+M,D+P]),a));let _=i&&e.textureTriangles?.length?e.textureTriangles.map(V=>zr(V,l,u,d,E,A,M,P)).filter(V=>!!V):null;return{index:n,polygon:e,texture:i,tileSize:l,layerElevation:u,matrix:w,canonicalMatrix:I,atlasMatrix:F,projectiveMatrix:B,canvasW:X,canvasH:$,screenPts:W,uvAffine:b,uvSampleRect:R,textureTriangles:_,textureEdgeRepairEdges:C,textureEdgeRepair:O,normal:h,textureTint:xe,shadedColor:c}}function ut(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??Qt,r=t.layerElevation??o,s=Qe(e.vertices,o,r),i=ct(s);if(!i)return null;let a=[{a:0,b:1,c:2},{a:1,b:2,c:0},{a:2,b:0,c:1}].map(Q=>{let H=s[Q.a],q=s[Q.b];return{...Q,length:Math.hypot(q[0]-H[0],q[1]-H[1],q[2]-H[2])}}).sort((Q,H)=>H.length-Q.length),l=a[0].a,u=a[0].b,p=a[0].c,d=s[l],f=s[u],g=s[p],m=a[0].length;if(m<=pe)return null;let h=[(f[0]-d[0])/m,(f[1]-d[1])/m,(f[2]-d[2])/m],y=[g[0]-d[0],g[1]-d[1],g[2]-d[2]],v=Ne(y,h),E=[d[0]+h[0]*v,d[1]+h[1]*v,d[2]+h[2]*v],A=[E[0]-g[0],E[1]-g[1],E[2]-g[2]],x=Math.hypot(A[0],A[1],A[2]);if(x<=pe)return null;let C=[A[0]/x,A[1]/x,A[2]/x];if(Ne(kr(h,C),i)<0){let Q=u;if(u=l,l=Q,d=s[l],f=s[u],m=Math.hypot(f[0]-d[0],f[1]-d[1],f[2]-d[2]),m<=pe)return null;h=[(f[0]-d[0])/m,(f[1]-d[1])/m,(f[2]-d[2])/m];let H=[g[0]-d[0],g[1]-d[1],g[2]-d[2]];v=Ne(H,h),E=[d[0]+h[0]*v,d[1]+h[1]*v,d[2]+h[2]*v],A=[E[0]-g[0],E[1]-g[1],E[2]-g[2]];let q=Math.hypot(A[0],A[1],A[2]);if(q<=pe)return null;C=[A[0]/q,A[1]/q,A[2]/q]}let O=Math.max(0,Math.min(m,v)),M=Math.max(0,m-O),P=rn([O,0,0,x,O+M,x],er),X=[P[0],P[1]],$=[P[2],P[3]],W=[P[4],P[5]],ne=($[1]+W[1])/2,S=X[0]-$[0],U=W[0]-X[0],w=ne-X[1];if(S<=pe||U<=pe||w<=pe||!Number.isFinite(S+U+w))return null;let I=t.directionalLight,F=t.ambientLight,B=I?.direction??Kt,J=I?.color??Jt,le=Math.max(0,I?.intensity??en),k=F?.color??tn,j=Math.max(0,F?.intensity??nn),Z=Math.hypot(B[0],B[1],B[2])||1,se=B[0]/Z,oe=B[1]/Z,de=B[2]/Z,ge=le*Math.max(0,i[0]*se+i[1]*oe+i[2]*de),me=Yn(e.color??"#cccccc",ge,J,k,j),ue=t.textureLighting??"baked",be=Te(e.color??"#cccccc"),xe=me===t.solidPaintDefaults?.paintColor,c=ue==="dynamic"&&an(be)===t.solidPaintDefaults?.dynamicColorKey,b=ue==="dynamic"||xe?"":`color:${me};`,R=ue==="dynamic"?`--pnx:${i[0].toFixed(4)};--pny:${i[1].toFixed(4)};--pnz:${i[2].toFixed(4)};`+(c?"":`--psr:${(be.r/255).toFixed(4)};--psg:${(be.g/255).toFixed(4)};--psb:${(be.b/255).toFixed(4)};`):"",_=([Q,H])=>[g[0]+(Q-O)*h[0]+H*C[0],g[1]+(Q-O)*h[1]+H*C[1],g[2]+(Q-O)*h[2]+H*C[2]],V=_(X),D=_([$[0],ne]),Y=_([W[0],ne]),L=ke/2,N=[(Y[0]-D[0])/ke,(Y[1]-D[1])/ke,(Y[2]-D[2])/ke],z=[V[0]-N[0]*L,V[1]-N[1]*L,V[2]-N[2]*L],G=[(D[0]-z[0])/ke,(D[1]-z[1])/ke,(D[2]-z[2])/ke],T=`transform:matrix3d(${we([N[0],N[1],N[2],0,G[0],G[1],G[2],0,i[0],i[1],i[2],0,z[0],z[1],z[2],1])});`+b+R;return{index:n,polygon:e,styleText:T}}function it(e,n=1){let t=Array(e.length).fill(null),o=[],r=Cr(n),s=e.filter(l=>!!l).sort((l,u)=>u.canvasH-l.canvasH||u.canvasW-l.canvasW||l.index-u.index),i=()=>({width:r,height:r,entries:[],shelves:[]}),a=(l,u,p)=>{if(l.sealed)return null;for(let g of l.shelves)if(u.canvasH<=g.height&&g.x+u.canvasW+r<=ze){let m={...u,pageIndex:p,x:g.x,y:g.y};return g.x+=u.canvasW+r*2,l.entries.push(m),l.width=Math.max(l.width,m.x+u.canvasW+r),m}let d=l.shelves.length===0?r:l.height+r;if(d+u.canvasH+r>ze)return null;let f={...u,pageIndex:p,x:r,y:d};return l.shelves.push({x:r+u.canvasW+r*2,y:d,height:u.canvasH}),l.entries.push(f),l.width=Math.max(l.width,f.x+u.canvasW+r),l.height=Math.max(l.height,d+u.canvasH+r),f};for(let l of s){if(l.canvasW+r*2>ze||l.canvasH+r*2>ze){let d=o.length,f={...l,pageIndex:d,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 p=null;for(let d=0;d<o.length&&(p=a(o[d],l,d),!p);d++);if(!p){let d=i(),f=o.length;o.push(d),p=a(d,l,f)}p&&(t[l.index]=p)}return{entries:t,pages:o.map(({width:l,height:u,entries:p})=>({width:l,height:u,entries:p}))}}function Br(e,n,t,o){Ae(e,o),e.beginPath(),Zt(e,n.x,n.y,n.screenPts),e.clip(),Ae(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function Fe(e,n){return Math.max(0,Math.min(n,e))}function Dn(e,n,t,o,r,s,i,a){let l=n.naturalWidth||n.width||1,u=n.naturalHeight||n.height||1,p=Fe(Math.min(t.minU,t.maxU)*l,l),d=Fe(Math.max(t.minU,t.maxU)*l,l),f=Fe(Math.min(t.minV,t.maxV)*u,u),g=Fe(Math.max(t.minV,t.maxV)*u,u),m=Math.floor(p),h=Math.floor(f),y=Math.ceil(d)-m,v=Math.ceil(g)-h;y<1&&(m=Math.floor(Fe((t.minU+t.maxU)/2*l,l-1)),y=1),v<1&&(h=Math.floor(Fe((t.minV+t.maxV)/2*u,u-1)),v=1),m=Math.max(0,Math.min(l-1,m)),h=Math.max(0,Math.min(u-1,h)),y=Math.max(1,Math.min(l-m,y)),v=Math.max(1,Math.min(u-h,v)),Ae(e,a),e.drawImage(n,m,h,y,v,o,r,s,i)}function Nr(e,n,t,o,r,s){for(let i=0;i<o.length;i+=2){let a=n+o[i]+r,l=t+o[i+1]+s;i===0?e.moveTo(a,l):e.lineTo(a,l)}e.closePath()}function Yr(e,n,t,o,r=0,s=0){if(n.textureTriangles?.length){let i=t.naturalWidth||t.width||1,a=t.naturalHeight||t.height||1;for(let l of n.textureTriangles){let u=Ze(l.screenPts,Qo);e.save(),Ae(e,o),e.beginPath(),Nr(e,n.x,n.y,u,r,s),e.clip(),l.uvAffine?(Ae(e,o,l.uvAffine.a/i,l.uvAffine.c/i,l.uvAffine.b/a,l.uvAffine.d/a,n.x+l.uvAffine.e+r,n.y+l.uvAffine.f+s),e.drawImage(t,0,0)):l.uvSampleRect&&Dn(e,t,l.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let i=t.naturalWidth||t.width||1,a=t.naturalHeight||t.height||1;Ae(e,o,n.uvAffine.a/i,n.uvAffine.c/i,n.uvAffine.b/a,n.uvAffine.d/a,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+s),e.drawImage(t,0,0)}else n.uvSampleRect?Dn(e,t,n.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o):wr(e,t,n.x+r,n.y+s,n.canvasW,n.canvasH,o)}function Xr(e,n,t,o,r,s){let i=r-t,a=s-o,l=i*i+a*a;if(l<=pe)return Math.hypot(e-t,n-o);let u=Math.max(0,Math.min(1,((e-t)*i+(n-o)*a)/l));return Math.hypot(e-(t+i*u),n-(o+a*u))}function $r(e,n,t,o){let r=1/0,s=t.length/2;for(let i of o){if(i<0||i>=s)continue;let a=i*2,l=(i+1)%s*2;r=Math.min(r,Xr(e,n,t[a],t[a+1],t[l],t[l+1]))}return r}function Ur(e,n,t,o,r,s){let i=Math.max(0,o-s),a=Math.min(n-1,o+s),l=Math.max(0,r-s),u=Math.min(t-1,r+s),p=null,d=1/0;for(let f=l;f<=u;f++)for(let g=i;g<=a;g++){if(g===o&&f===r)continue;let m=g-o,h=f-r,y=m*m+h*h;if(y>s*s||y>=d)continue;let v=(f*n+g)*4;e[v+3]<Jo||(p=v,d=y)}return p}function Gr(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),s=Math.max(0,Math.floor(n.y*t)),i=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),a=Math.max(1,Math.min(o.height-s,Math.ceil(n.canvasH*t)));if(i<=0||a<=0)return;let l;try{l=e.getImageData(r,s,i,a)}catch{return}let u=l.data,p=new Uint8ClampedArray(u),d=Math.max(Mn,Mn/t),f=Math.max(2,Math.ceil(d*t)+1),g=!1;for(let m=0;m<a;m++)for(let h=0;h<i;h++){let y=(m*i+h)*4,v=u[y+3];if(v<Ko||v===255)continue;let E=(r+h+.5)/t-n.x,A=(s+m+.5)/t-n.y;if($r(E,A,n.screenPts,n.textureEdgeRepairEdges)>d)continue;let x=Ur(p,i,a,h,m,f);x!==null&&(u[y]=p[x],u[y+1]=p[x+1],u[y+2]=p[x+2],u[y+3]=255,g=!0)}g&&e.putImageData(l,r,s)}async function jr(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=e.entries.some(p=>p.textureEdgeRepair&&p.texture&&p.textureEdgeRepairEdges&&p.textureEdgeRepairEdges.size>0),i=r.getContext("2d",s?{willReadFrequently:!0}:void 0);if(!i)return{width:e.width,height:e.height,url:null};let a=Array.from(new Set(e.entries.flatMap(p=>p.texture?[p.texture]:[]))),l=new Map;await Promise.all(a.map(async p=>{l.set(p,await lr(p))}));for(let p of e.entries){let d=p.texture?l.get(p.texture):null;if(!p.texture){i.save(),Br(i,p,n,o),i.restore();continue}d&&(i.save(),Ae(i,o),i.beginPath(),Zt(i,p.x,p.y,p.screenPts),i.clip(),Yr(i,p,d,o),i.restore()),p.texture&&n==="baked"&&(i.save(),Ae(i,o),i.beginPath(),Zt(i,p.x,p.y,p.screenPts),i.clip(),Lr(i,p.x,p.y,p.canvasW,p.canvasH,p.textureTint,o),i.restore()),Gr(i,p,o)}let u=await Vr(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:u}}async function Wn(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await jr(i,n,t,o))}return s}function Zn(e,n,t,o){if(!n.url)return;let r=`url(${n.url})`,s=o.canvasW||1,i=o.canvasH||1,a=Le(o),l=`${Be(-o.x/s*a)} ${Be(-o.y/i*a)}`,u=`${Be(n.width/s*a)} ${Be(n.height/i*a)}`;t==="dynamic"?(ee(e,"background-image",r),ee(e,"background-position",l),ee(e,"background-size",u)):ee(e,"background",`${r} ${l} / ${u} no-repeat`),t==="dynamic"?(ee(e,"mask-image",r),ee(e,"mask-mode","alpha"),ee(e,"mask-position",l),ee(e,"mask-size",u),ee(e,"mask-repeat","no-repeat"),ee(e,"-webkit-mask-image",r),ee(e,"-webkit-mask-position",l),ee(e,"-webkit-mask-size",u),ee(e,"-webkit-mask-repeat","no-repeat")):(ye(e,"mask-image"),ye(e,"mask-mode"),ye(e,"mask-position"),ye(e,"mask-size"),ye(e,"mask-repeat"),ye(e,"-webkit-mask-image"),ye(e,"-webkit-mask-position"),ye(e,"-webkit-mask-size"),ye(e,"-webkit-mask-repeat"))}function Oe(e,n){let t=jt.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);jt.set(e,o)}function qn(e,n,t,o=0,r=0){let s=e.matrix.split(",").map(f=>Number(f));if(s.length!==16||s.some(f=>!Number.isFinite(f)))return e.matrix;let i=s[0],a=s[1],l=s[2],u=s[4],p=s[5],d=s[6];return s[0]*=n,s[1]*=n,s[2]*=n,s[4]*=t,s[5]*=t,s[6]*=t,s[12]+=o*i+r*u,s[13]+=o*a+r*p,s[14]+=o*l+r*d,we(s)}function Wr(e,n){return qn(e,n.width/wn,n.height/wn,n.minX,n.minY)}function Zr(e){return qn(e,(e.canvasW||1)/Wt,(e.canvasH||1)/Wt)}function qr(e){let n=eo(e);return[`transform:matrix3d(${Wr(e,n.bounds)})`,`border-shape:${to(n.points)}`].join(";")}function Qr(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,o=e.layerElevation,r=Qe(n.vertices,t,o),s=ct(r);if(!s)return null;let i=e.screenPts[0],a=e.screenPts[1],l=e.screenPts[2],u=e.screenPts[3],p=e.screenPts[4],d=e.screenPts[5],f=l-i,g=u-a,m=p-i,h=d-a,y=f*h-g*m;if(Math.abs(y)<=pe)return null;let v=r[0],E=r[1],A=r[2],x=[E[0]-v[0],E[1]-v[1],E[2]-v[2]],C=[A[0]-v[0],A[1]-v[1],A[2]-v[2]],O=[(x[0]*h-g*C[0])/y,(x[1]*h-g*C[1])/y,(x[2]*h-g*C[2])/y],M=[(f*C[0]-x[0]*m)/y,(f*C[1]-x[1]*m)/y,(f*C[2]-x[2]*m)/y],P=v[0]-O[0]*i-M[0]*a,X=v[1]-O[1]*i-M[1]*a,$=v[2]-O[2]*i-M[2]*a;return{normal:s,matrix:we([O[0]*e.canvasW/Le(e),O[1]*e.canvasW/Le(e),O[2]*e.canvasW/Le(e),0,M[0]*e.canvasH/Le(e),M[1]*e.canvasH/Le(e),M[2]*e.canvasH/Le(e),0,s[0],s[1],s[2],0,P,X,$,1])}}function Kr(e,n,t,o){if(!n.texture||!t.texture||n.texture!==t.texture)return!1;let r=Qr(n,t);return r?(ee(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(ee(e,"--pnx",r.normal[0].toFixed(4)),ee(e,"--pny",r.normal[1].toFixed(4)),ee(e,"--pnz",r.normal[2].toFixed(4))),Oe(e,t),!0):!1}function Qn(e,n){ee(e,"--pnx",n.normal[0].toFixed(4)),ee(e,"--pny",n.normal[1].toFixed(4)),ee(e,"--pnz",n.normal[2].toFixed(4))}function Jr(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=ie)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])>ie||Math.abs(t[0])>ie||n[1]-n[0]<=ie||t[1]-t[0]<=ie))return null;for(let r=0;r<e.screenPts.length;r+=2){let s=e.screenPts[r],i=e.screenPts[r+1],a=Math.abs(s-n[0])<=ie||Math.abs(s-n[1])<=ie,l=Math.abs(i-t[0])<=ie||Math.abs(i-t[1])<=ie;if(!a||!l)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function Re(e){return!!Jr(e)}function at(e){return!e.texture&&e.polygon.vertices.length===3}function Ye(e){return!e.texture&&!!e.projectiveMatrix&&!Re(e)}function un(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function dt(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";if(!t)return!0;let o=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(t);return!/\bVersion\/[\d.]+.*\bSafari\//.test(t)||o}function Hn(e,n){e.set(n,(e.get(n)??0)+1)}function In(e){let n,t=1;for(let[o,r]of e)r>t&&(n=o,t=r);return n}function Kn(e,n,t,o){let r=new Map,s=new Map,i=new Map,a=!o.has("b"),l=a,u=!o.has("u")&&dt(t),p=!o.has("i")&&un(t);for(let g of e)if(!(!g||g.texture)){if(n==="dynamic"){if(!(u&&at(g))&&!(a&&Re(g))&&!(l&&Ye(g))&&!p)continue;let m=Te(g.polygon.color??"#cccccc"),h=an(m);Hn(s,h),i.has(h)||i.set(h,m);continue}!(u&&at(g))&&!(a&&Re(g))&&!(l&&Ye(g))&&!p||Hn(r,g.shadedColor)}let d=In(r),f=In(s);return{paintColor:d,dynamicColorKey:f,dynamicColor:f?i.get(f):void 0}}function Jn(){return new Promise(e=>setTimeout(e,0))}async function Ut(e){return performance.now()-e<Wo?e:(await Jn(),performance.now())}function mt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=new Set(n.strategies?.disable??[]),r=ln(e,n),s=sn(t),i=e.map((a,l)=>cn(a,l,n,s,r[l]));return Kn(i,n.textureLighting??"baked",t,o)}function es(e,n,t){let o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(let u=0;u<e.length;u+=2){let p=e[u],d=e[u+1];!Number.isFinite(p)||!Number.isFinite(d)||(o=Math.min(o,p),r=Math.min(r,d),s=Math.max(s,p),i=Math.max(i,d))}let a=s-o,l=i-r;return!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(a)||!Number.isFinite(l)||a<=pe||l<=pe?{minX:0,minY:0,width:n,height:t}:{minX:o,minY:r,width:a,height:l}}function eo(e){let n=e.canvasW||1,t=e.canvasH||1,o=$t>0?rn(e.screenPts,$t):e.screenPts,r=$t>0?es(o,n,t):{minX:0,minY:0,width:n,height:t},s=[];for(let i=0;i<o.length;i+=2){let a=Math.max(0,Math.min(100,(o[i]-r.minX)/r.width*100)),l=Math.max(0,Math.min(100,(o[i+1]-r.minY)/r.height*100));s.push([a,l])}return{bounds:r,points:s}}function ts([e,n]){return`${rt(e)} ${rt(n)}`}function ns(e){return`polygon(${e.map(ts).join(",")})`}function os(e){if(pr(e))return"circle(0)";let n=0,t=0,o=Math.max(1,e.length);for(let[i,a]of e)n+=i,t+=a;let r=rt(Math.max(0,Math.min(100,n/o))),s=rt(Math.max(0,Math.min(100,t/o)));return`circle(0 at ${r} ${s})`}function to(e){return`${ns(e)} ${os(e)}`}function no(e){return to(eo(e).points)}function dn(e,n,t,o){if(t==="dynamic"){ye(e,"color"),ye(e,"background"),Qn(e,n);let r=Te(n.polygon.color??"#cccccc");an(r)===o?.dynamicColorKey?(ye(e,"--psr"),ye(e,"--psg"),ye(e,"--psb")):(ee(e,"--psr",(r.r/255).toFixed(4)),ee(e,"--psg",(r.g/255).toFixed(4)),ee(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(ye(e,"background"),ee(e,"color",n.shadedColor)):(ye(e,"background"),ye(e,"color"))}function oo(e,n,t,o){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${Zr(e)})`),Oe(r,e.polygon),dn(r,e,n,o),r}function ro(e,n,t,o){let r=t.createElement("i");return r.setAttribute("style",qr(e)),Oe(r,e.polygon),dn(r,e,n,o),r}function so(e,n,t,o){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`),Oe(r,e.polygon),dn(r,e,n,o),r}function io(e,n,t){let o=t.createElement("s");o.setAttribute("style",`transform:matrix3d(${e.atlasMatrix})`),Oe(o,e.polygon);let r=e.canvasW||1,s=e.canvasH||1,i=Le(e);return ee(o,"--polycss-atlas-size",`${i}px`),ee(o,"background-position",`${Be(-e.x/r*i)} ${Be(-e.y/s*i)}`),ee(o,"opacity","0"),n==="dynamic"&&Qn(o,e),o}function ao(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=new Set(n.strategies?.disable??[]),s=!r.has("b"),i=s,a=!r.has("u")&&dt(t),l=!r.has("i")&&un(t),u=ln(e,n),p=sn(t),d=e.map((x,C)=>cn(x,C,n,p,u[C])),f=d.map(x=>x&&a&&at(x)?ut(x.polygon,x.index,n):null),g=d.map((x,C)=>x&&(x.texture||!(s&&Re(x))&&!f[C]&&!(i&&Ye(x))&&!l?x:null)),{packed:m,atlasScale:h}=Nn(g,n.textureQuality,t),y=new Map,v=[],E=!1,A=[];for(let x=0;x<e.length;x++){let C=d[x],O=f[x];if(!C)continue;let M=m.entries[x];if(M){let P=io(M,o,t);y.set(x,P),v.push({polygonIndex:x,element:P,kind:"atlas",plan:M,dispose:()=>{}})}else if(!C.texture&&s&&Re(C)){let P=oo(C,o,t,n.solidPaintDefaults);v.push({polygonIndex:x,element:P,kind:"solid",plan:C,dispose:()=>{}})}else if(!C.texture&&O){let P=mn(O,t);v.push({polygonIndex:x,element:P,kind:"triangle",plan:C,dispose:()=>{}})}else if(!C.texture&&i&&Ye(C)){let P=so(C,o,t,n.solidPaintDefaults);v.push({polygonIndex:x,element:P,kind:"solid",plan:C,dispose:()=>{}})}else if(!C.texture&&l){let P=ro(C,o,t,n.solidPaintDefaults);v.push({polygonIndex:x,element:P,kind:"border",plan:C,dispose:()=>{}})}}return v.sort((x,C)=>x.polygonIndex-C.polygonIndex),Wn(m.pages,o,t,h,()=>E).then(x=>{if(E){for(let C of x)C.url?.startsWith("blob:")&&URL.revokeObjectURL(C.url);return}A=x.flatMap(C=>C.url?.startsWith("blob:")?[C.url]:[]);for(let C=0;C<m.pages.length;C++){let O=m.pages[C],M=x[C];if(M)for(let P of O.entries){let X=y.get(P.index);!X||!M.url||(Zn(X,M,o,P),ye(X,"opacity"))}}}).catch(()=>{if(!E)for(let x of y.values())ee(x,"opacity","0.5"),ee(x,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:v,dispose(){E=!0;for(let x of A)URL.revokeObjectURL(x);A=[]}}}async function lo(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let r=n.textureLighting??"baked",s=new Set(n.strategies?.disable??[]),i=!s.has("b"),a=i,l=!s.has("u")&&dt(o),u=!s.has("i")&&un(o);if(await Jn(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let p=ln(e,n),d=sn(o),f=performance.now(),g=new Array(e.length);for(let M=0;M<e.length;M++)if(g[M]=cn(e[M],M,n,d,p[M]),f=await Ut(f),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let m=n.solidPaintDefaults??Kn(g,r,o,s),h=new Array(g.length),y=new Array(g.length);for(let M=0;M<g.length;M++){let P=g[M],X=P&&l&&at(P)?ut(P.polygon,P.index,{...n,solidPaintDefaults:m}):null;if(h[M]=X,y[M]=P&&(P.texture||!(i&&Re(P))&&!X&&!(a&&Ye(P))&&!u?P:null),f=await Ut(f),t())return{rendered:[],solidPaintDefaults:m,dispose:()=>{}}}let{packed:v,atlasScale:E}=Nn(y,n.textureQuality,o),A=new Map,x=[],C=!1,O=[];for(let M=0;M<e.length;M++){let P=g[M],X=h[M];if(!P)continue;let $=v.entries[M];if($){let W=io($,r,o);A.set(M,W),x.push({polygonIndex:M,element:W,kind:"atlas",plan:$,dispose:()=>{}})}else if(!P.texture&&i&&Re(P)){let W=oo(P,r,o,m);x.push({polygonIndex:M,element:W,kind:"solid",plan:P,dispose:()=>{}})}else if(!P.texture&&X){let W=mn(X,o);x.push({polygonIndex:M,element:W,kind:"triangle",plan:P,dispose:()=>{}})}else if(!P.texture&&a&&Ye(P)){let W=so(P,r,o,m);x.push({polygonIndex:M,element:W,kind:"solid",plan:P,dispose:()=>{}})}else if(!P.texture&&u){let W=ro(P,r,o,m);x.push({polygonIndex:M,element:W,kind:"border",plan:P,dispose:()=>{}})}if(f=await Ut(f),t()){for(let W of x)W.dispose();return{rendered:[],solidPaintDefaults:m,dispose:()=>{}}}}return x.sort((M,P)=>M.polygonIndex-P.polygonIndex),Wn(v.pages,r,o,E,()=>C||t()).then(M=>{if(C||t()){for(let P of M)P.url?.startsWith("blob:")&&URL.revokeObjectURL(P.url);return}O=M.flatMap(P=>P.url?.startsWith("blob:")?[P.url]:[]);for(let P=0;P<v.pages.length;P++){let X=v.pages[P],$=M[P];if($)for(let W of X.entries){let ne=A.get(W.index);!ne||!$.url||(Zn(ne,$,r,W),ye(ne,"opacity"))}}}).catch(()=>{if(!(C||t()))for(let M of A.values())ee(M,"opacity","0.5"),ee(M,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:x,solidPaintDefaults:m,dispose(){C=!0;for(let M of O)URL.revokeObjectURL(M);O=[]}}}function rs(e,n){let t=e.map((o,r)=>ut(o,r,n));return t.some(o=>!o)?null:t}function ss(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 co(e,n){e.setAttribute("style",n.styleText),(n.polygon.data||jt.get(e)?.length)&&Oe(e,n.polygon)}function mn(e,n){let t=n.createElement("u");return ss(t),co(t,e),Oe(t,e.polygon),t}function pn(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};if(!dt(t))return null;let o=rs(e,n);if(!o)return null;let r=[];for(let s of o){let i=mn(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 uo(e,n,t={}){if(e.length!==n.length)return!1;let o=t.textureLighting??"baked",r=[];for(let s=0;s<e.length;s++){let i=e[s];if(i.polygonIndex!==s)return!1;let a=n[s];if(!a)return!1;if(i.kind==="atlas"){if(!i.plan||!Kr(i.element,i.plan,a,o))return!1;continue}if(i.kind==="triangle"){let l=ut(a,s,t);if(!l)return!1;r[s]=l;continue}return!1}for(let s=0;s<e.length;s++){let i=e[s];if(i.kind==="triangle"){let a=r[s];if(!a)return!1;co(i.element,a)}}return!0}var ce=require("@layoutit/polycss-core"),is=[.4,-.7,.59],as="#ffffff",ls=1,cs="#ffffff",us=.4,po={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},ds=["t","b","bl","br","fr","fl"],ms=new Map([["0,0,1","t"],["0,0,-1","b"],["0,1,0","fl"],["0,-1,0","br"],["1,0,0","fr"],["-1,0,0","bl"]]);function mo(e){let n=[];for(let t of ds)(0,ce.normalFacesCamera)(po[t],e)&&n.push(t);return n.join("|")}function ps(e,n,t){let o=e.__polycssVoxelBrushState??(e.__polycssVoxelBrushState={});o.color!==n&&(e.style.color=n,o.color=n),o.transform!==t&&(e.style.transform=t,o.transform=t)}function fs(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let a=1;a+1<n.length;a+=1){let l=n[a],u=n[a+1],p=l[1]-t[1],d=l[0]-t[0],f=l[2]-t[2],g=u[1]-t[1],m=u[0]-t[0],h=u[2]-t[2];o-=d*h-f*m,r-=f*g-p*h,s-=p*m-d*g}let i=Math.hypot(o,r,s);return i<=1e-9?null:[Math.round(o/i),Math.round(r/i),Math.round(s/i)]}function hs(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=fs(e),t=n?ms.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,s=1/0,i=-1/0,a=-1/0,l=-1/0;for(let d of e.vertices)o=Math.min(o,d[0]),r=Math.min(r,d[1]),s=Math.min(s,d[2]),i=Math.max(i,d[0]),a=Math.max(a,d[1]),l=Math.max(l,d[2]);let u=1e-6,p=e.color||"#cccccc";return Math.abs(l-s)<=u?{axis:"z",face:t,left:r*ce.BASE_TILE,top:o*ce.BASE_TILE,width:Math.max(0,(a-r)*ce.BASE_TILE),height:Math.max(0,(i-o)*ce.BASE_TILE),z:s*ce.BASE_TILE,baseColor:p}:Math.abs(i-o)<=u?{axis:"x",face:t,left:r*ce.BASE_TILE,top:s*ce.BASE_TILE,width:Math.max(0,(a-r)*ce.BASE_TILE),height:Math.max(0,(l-s)*ce.BASE_TILE),z:-o*ce.BASE_TILE,baseColor:p}:Math.abs(a-r)<=u?{axis:"y",face:t,left:s*ce.BASE_TILE,top:o*ce.BASE_TILE,width:Math.max(0,(l-s)*ce.BASE_TILE),height:Math.max(0,(i-o)*ce.BASE_TILE),z:-r*ce.BASE_TILE,baseColor:p}:null}function fn(e){let n=(0,ce.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha}:{r:255,g:255,b:255,alpha:1}}function gs({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 hn(e){return Math.round(Math.max(0,Math.min(255,e)))}function ys(e,n,t,o){let r=fn(n),s=fn(t?.color??as),i=fn(o?.color??cs),a=t?.direction??is,l=Math.hypot(a[0],a[1],a[2])||1,u=a[0]/l,p=a[1]/l,d=a[2]/l,f=Math.max(0,t?.intensity??ls)*Math.max(0,e[0]*u+e[1]*p+e[2]*d),g=Math.max(0,o?.intensity??us),m=i.r/255*g+s.r/255*f,h=i.g/255*g+s.g/255*f,y=i.b/255*g+s.b/255*f,v={r:r.r*m,g:r.g*h,b:r.b*y,alpha:r.alpha};return v.alpha<1?`rgba(${hn(v.r)}, ${hn(v.g)}, ${hn(v.b)}, ${v.alpha})`:gs(v)}function bs(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=hs(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return n}function xs(e,n,t,o,r,s){return`matrix3d(${(e==="x"?[o,0,0,0,0,0,r,0,0,-1,0,0,n,-s,t,1]:e==="y"?[0,0,o,0,0,r,0,0,-1,0,0,0,-s,t,n,1]:[o,0,0,0,0,r,0,0,0,0,1,0,n,t,s,1]).map(a=>Number(a.toFixed(6))).join(",")})`}function vs(e){return e.axis==="x"?[e.left+e.width/2,-e.z,e.top+e.height/2]:e.axis==="y"?[-e.z,e.top+e.height/2,e.left+e.width/2]:[e.left+e.width/2,e.top+e.height/2,e.z]}function Ps(e,n){let t=vs(e),o=n.meshRotation;o&&(t=(0,ce.rotateVec3)(t,o[0]??0,o[1]??0,o[2]??0));let[r,s]=(0,ce.rotateVec3)(t,n.rotX,0,n.rotY);return{x:r,y:s}}function Es(e,n,t){let o=e.filter(f=>n.has(f.face)).map(f=>({item:f,...Ps(f,t)}));if(o.length===0)return[];let r=1/0,s=-1/0,i=1/0,a=-1/0;for(let f of o)r=Math.min(r,f.x),s=Math.max(s,f.x),i=Math.min(i,f.y),a=Math.max(a,f.y);let l=4,u=Math.max(1e-6,s-r),p=Math.max(1e-6,a-i),d=new Map;for(let f of o){let g=Math.min(l-1,Math.max(0,Math.floor((f.x-r)/u*l))),m=Math.min(l-1,Math.max(0,Math.floor((f.y-i)/p*l))),h=`${g}:${m}`,y=d.get(h);y||(y={tx:g,ty:m,sourceIndex:f.item.sourceIndex,items:[]},d.set(h,y)),y.items.push(f.item),y.sourceIndex=Math.min(y.sourceIndex,f.item.sourceIndex)}return Array.from(d.values()).sort((f,g)=>f.ty-g.ty||f.tx-g.tx||f.sourceIndex-g.sourceIndex).flatMap(f=>f.items)}function fo(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:s}=e,i=bs(o);if(i.length===0)return null;t.classList.add("polycss-voxel-mesh");let a=new Map,l=(m,h)=>{let y=`${m}|${h}`,v=a.get(y);if(v)return v;let E=ys(po[m],h,r,s);return a.set(y,E),E},u=[],p="",d=0,f=m=>{let h=u[m];return h||(h=n.createElement("b"),u[m]=h),h.parentElement!==t&&t.appendChild(h),h},g=(m,h)=>{let y=new Set(m.split("|").filter(Boolean)),v=Es(i,y,h);d=0;for(let E of v){let A=f(d);ps(A,l(E.face,E.baseColor),xs(E.axis,E.left,E.top,E.width,E.height,E.z)),d+=1}for(let E=d;E<u.length;E+=1)u[E]?.remove()};return{element:t,get brushCount(){return d},render(m){p=mo(m),g(p,m)},syncCamera(m){let h=mo(m);h!==p&&(p=h,g(h,m))},dispose(){for(let m of u)m.remove();t.classList.remove("polycss-voxel-mesh"),u.length=0,d=0,p=""}}}var ho="polycss-styles";function pt(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(ho))return;let t=n.createElement("style");t.id=ho,t.textContent=Cs,n.head.appendChild(t)}var Cs=`
1
+ "use strict";var No=Object.defineProperty;var Bi=Object.getOwnPropertyDescriptor;var zi=Object.getOwnPropertyNames;var Ni=Object.prototype.hasOwnProperty;var $i=(e,n)=>{for(var t in n)No(e,t,{get:n[t],enumerable:!0})},zo=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of zi(n))!Ni.call(e,r)&&r!==t&&No(e,r,{get:()=>n[r],enumerable:!(o=Bi(n,r))||o.enumerable});return e},pe=(e,n,t)=>(zo(e,n,"default"),t&&zo(t,n,"default"));var Ui=e=>zo(No({},"__esModule",{value:!0}),e);var de={};$i(de,{PolyBoxElement:()=>Po,PolyCameraElement:()=>bo,PolyConeElement:()=>_o,PolyCylinderElement:()=>Lo,PolyDodecahedronElement:()=>wo,PolyFirstPersonControlsElement:()=>go,PolyIcosahedronElement:()=>Ao,PolyIframeElement:()=>lo,PolyMapControlsElement:()=>ho,PolyMeshElement:()=>ln,PolyOctahedronElement:()=>Eo,PolyOrbitControlsElement:()=>fo,PolyOrthographicCameraElement:()=>un,PolyPerspectiveCameraElement:()=>yo,PolyPlaneElement:()=>So,PolyPolygonElement:()=>co,PolyRingElement:()=>Co,PolySceneElement:()=>He,PolySceneSnapshotError:()=>At,PolySelectElement:()=>xo,PolySphereElement:()=>Mo,PolyTetrahedronElement:()=>To,PolyTorusElement:()=>Ro,PolyTransformControlsElement:()=>vo,buildAtlasPages:()=>Rt,buildTextureEdgeRepairSets:()=>Pt.buildTextureEdgeRepairSets,collectPolyRenderStats:()=>mi,computeTextureAtlasPlanPublic:()=>$n.computeTextureAtlasPlanPublic,createPolyBox:()=>Pi,createPolyCamera:()=>Ws,createPolyCone:()=>_i,createPolyCylinder:()=>Li,createPolyDodecahedron:()=>Mi,createPolyFirstPersonControls:()=>eo,createPolyIcosahedron:()=>wi,createPolyMapControls:()=>Jn,createPolyOctahedron:()=>Ei,createPolyOrbitControls:()=>Kn,createPolyOrthographicCamera:()=>Tt,createPolyPerspectiveCamera:()=>Ht,createPolyPlane:()=>Si,createPolyRing:()=>Ci,createPolyScene:()=>Xn,createPolySphere:()=>Ti,createPolyTetrahedron:()=>Ai,createPolyTorus:()=>Ri,createSelect:()=>to,createTransformControls:()=>io,cssBorderShapeForPlan:()=>St.cssBorderShapeForPlan,exportPolySceneSnapshot:()=>xi,filterAtlasPlans:()=>Dn,formatBorderShapeEntryMatrix:()=>St.formatBorderShapeEntryMatrix,formatCssLengthPx:()=>Ze.formatCssLengthPx,formatMatrix3d:()=>Ze.formatMatrix3d,formatSolidQuadEntryMatrix:()=>Ze.formatSolidQuadEntryMatrix,getSolidPaintDefaults:()=>vt,getSolidPaintDefaultsFromPlans:()=>On,injectPolyBaseStyles:()=>Un,isBorderShapeSupported:()=>bn,isFullRectSolid:()=>q.isFullRectSolid,isProjectiveQuadPlan:()=>q.isProjectiveQuadPlan,isSolidTrianglePlan:()=>q.isSolidTrianglePlan,isSolidTriangleSupported:()=>vn,packTextureAtlasPlansWithScale:()=>_t,renderPolygonsWithStableTriangles:()=>Ot,renderPolygonsWithTextureAtlas:()=>xt,renderPolygonsWithTextureAtlasAsync:()=>Qt,updatePolygonsWithStableTopology:()=>Jt,updatePolygonsWithStableTriangles:()=>Nn,updateStableTriangleFrame:()=>Kt});module.exports=Ui(de);var ne=require("@layoutit/polycss-core");var Dr=require("@layoutit/polycss-core");function Gi(e){if(!e)return!1;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return t?t("(pointer: coarse)").matches||t("(hover: none)").matches:!1}function _t(e,n,t){return(0,Dr.packTextureAtlasPlansWithScaleCore)(e,n,Gi(t))}var Pt=require("@layoutit/polycss-core");var ct=require("@layoutit/polycss-core"),zr=require("@layoutit/polycss-core"),Nr=require("@layoutit/polycss-core"),zt=new Map;function ji(e){let n=zt.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.crossOrigin="anonymous",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),zt.set(e,n),n.then(()=>{zt.get(e)===n&&zt.delete(e)},()=>{zt.get(e)===n&&zt.delete(e)})),n}function Be(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 $o(e){let n=e/255;return n<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function Uo(e){let n=e<=.0031308?e*12.92:1.055*Math.pow(e,.4166666666666667)-.055;return Math.max(0,Math.min(255,Math.round(n*255)))}function Wi(e,n,t,o,r,s,i){let c=Math.round(n*i),l=Math.round(t*i),u=Math.max(1,Math.round(o*i)),d=Math.max(1,Math.round(r*i)),x=e.getImageData(c,l,u,d),h=x.data,b=s.r,v=s.g,P=s.b;for(let g=0;g<h.length;g+=4)h[g+3]!==0&&(h[g]=Uo($o(h[g])*b),h[g+1]=Uo($o(h[g+1])*v),h[g+2]=Uo($o(h[g+2])*P));e.putImageData(x,c,l)}function Yi(e,n,t,o,r,s,i){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,u=Math.max(r/c,s/l),d=c*u,x=l*u;Be(e,i),e.drawImage(n,t+(r-d)/2,o+(s-x)/2,d,x)}function Nt(e,n){return Math.max(0,Math.min(n,e))}function Ir(e,n,t,o,r,s,i,c){let l=n.naturalWidth||n.width||1,u=n.naturalHeight||n.height||1,d=Nt(Math.min(t.minU,t.maxU)*l,l),x=Nt(Math.max(t.minU,t.maxU)*l,l),h=Nt(Math.min(t.minV,t.maxV)*u,u),b=Nt(Math.max(t.minV,t.maxV)*u,u),v=Math.floor(d),P=Math.floor(h),g=Math.ceil(x)-v,C=Math.ceil(b)-P;g<1&&(v=Math.floor(Nt((t.minU+t.maxU)/2*l,l-1)),g=1),C<1&&(P=Math.floor(Nt((t.minV+t.maxV)/2*u,u-1)),C=1),v=Math.max(0,Math.min(l-1,v)),P=Math.max(0,Math.min(u-1,P)),g=Math.max(1,Math.min(l-v,g)),C=Math.max(1,Math.min(u-P,C)),Be(e,c),e.drawImage(n,v,P,g,C,o,r,s,i)}function $r(e){return e==="repeat"||e==="mirrored-repeat"}function Hr(e,n){return $r(e)?Math.floor(n):0}function Fr(e,n){return $r(e)?Math.ceil(n)-1:0}function Vr(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function Br(e,n,t,o,r,s,i){let c=r?Hr(s,r.minU):0,l=r?Fr(s,r.maxU):0,u=r?Hr(i,r.minV):0,d=r?Fr(i,r.maxV):0;for(let x=c;x<=l;x++)for(let h=u;h<=d;h++){let b=Vr(s,x),v=Vr(i,h);if(!b&&!v){e.drawImage(n,x*t,h*o);continue}e.save(),e.translate((b?x+1:x)*t,(v?h+1:h)*o),e.scale(b?-1:1,v?-1:1),e.drawImage(n,0,0),e.restore()}}function Go(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){for(let i=0;i<o.length;i+=2){let c=n+o[i]+r,l=t+o[i+1]+s;i===0?e.moveTo(c,l):e.lineTo(c,l)}e.closePath()}function Xi(e,n,t,o){Be(e,o),e.beginPath(),Go(e,n.x,n.y,n.screenPts),e.clip(),Be(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function Rn(e,n,t,o,r){n.polygon.textureAlphaMode==="opaque"&&(Be(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+r,n.canvasW,n.canvasH))}function Zi(e,n,t,o,r=0,s=0){if(n.textureTriangles?.length){let i=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1;for(let l of n.textureTriangles){let u=(0,zr.expandClipPoints)(l.screenPts,ct.TEXTURE_TRIANGLE_BLEED*(n.bleedRatio??1));e.save(),Be(e,o),e.beginPath(),_n(e,n.x,n.y,u,r,s),e.clip(),Rn(e,n,o,r,s),l.uvAffine?(Be(e,o,l.uvAffine.a/i,l.uvAffine.c/i,l.uvAffine.b/c,l.uvAffine.d/c,n.x+l.uvAffine.e+r,n.y+l.uvAffine.f+s),Br(e,t,i,c,l.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t)):l.uvSampleRect&&Ir(e,t,l.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let i=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1,l=n.polygon.textureAlphaMode==="opaque";l&&(e.save(),Be(e,o),e.beginPath(),_n(e,n.x,n.y,n.screenPts,r,s),e.clip(),Rn(e,n,o,r,s)),Be(e,o,n.uvAffine.a/i,n.uvAffine.c/i,n.uvAffine.b/c,n.uvAffine.d/c,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+s),Br(e,t,i,c,n.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t),l&&e.restore()}else if(n.uvSampleRect){let i=n.polygon.textureAlphaMode==="opaque";i&&(e.save(),Be(e,o),e.beginPath(),_n(e,n.x,n.y,n.screenPts,r,s),e.clip(),Rn(e,n,o,r,s)),Ir(e,t,n.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),i&&e.restore()}else{let i=n.polygon.textureAlphaMode==="opaque";i&&(e.save(),Be(e,o),e.beginPath(),_n(e,n.x,n.y,n.screenPts,r,s),e.clip(),Rn(e,n,o,r,s)),Yi(e,t,n.x+r,n.y+s,n.canvasW,n.canvasH,o),i&&e.restore()}}function qi(e,n,t,o,r,s){let i=r-t,c=s-o,l=i*i+c*c;if(l<=Nr.BASIS_EPS)return Math.hypot(e-t,n-o);let u=Math.max(0,Math.min(1,((e-t)*i+(n-o)*c)/l));return Math.hypot(e-(t+i*u),n-(o+c*u))}function Qi(e,n,t,o){let r=1/0,s=t.length/2;for(let i of o){if(i<0||i>=s)continue;let c=i*2,l=(i+1)%s*2;r=Math.min(r,qi(e,n,t[c],t[c+1],t[l],t[l+1]))}return r}function Ki(e,n,t,o,r,s){let i=Math.max(0,o-s),c=Math.min(n-1,o+s),l=Math.max(0,r-s),u=Math.min(t-1,r+s),d=null,x=1/0;for(let h=l;h<=u;h++)for(let b=i;b<=c;b++){if(b===o&&h===r)continue;let v=b-o,P=h-r,g=v*v+P*P;if(g>s*s||g>=x)continue;let C=(h*n+b)*4;e[C+3]<ct.TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN||(d=C,x=g)}return d}function Ji(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),s=Math.max(0,Math.floor(n.y*t)),i=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),c=Math.max(1,Math.min(o.height-s,Math.ceil(n.canvasH*t)));if(i<=0||c<=0)return;let l;try{l=e.getImageData(r,s,i,c)}catch{return}let u=l.data,d=new Uint8ClampedArray(u),x=Math.max(ct.TEXTURE_EDGE_REPAIR_RADIUS,ct.TEXTURE_EDGE_REPAIR_RADIUS/t),h=Math.max(2,Math.ceil(x*t)+1),b=!1;for(let v=0;v<c;v++)for(let P=0;P<i;P++){let g=(v*i+P)*4,C=u[g+3];if(C<ct.TEXTURE_EDGE_REPAIR_ALPHA_MIN||C===255)continue;let D=(r+P+.5)/t-n.x,k=(s+v+.5)/t-n.y;if(Qi(D,k,n.screenPts,n.textureEdgeRepairEdges)>x)continue;let z=Ki(d,i,c,P,v,h);z!==null&&(u[g]=d[z],u[g+1]=d[z+1],u[g+2]=d[z+2],u[g+3]=255,b=!0)}b&&e.putImageData(l,r,s)}function ea(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)}}async function ta(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=e.entries.some(d=>d.textureEdgeRepair&&d.texture&&d.textureEdgeRepairEdges&&d.textureEdgeRepairEdges.size>0),i=r.getContext("2d",s?{willReadFrequently:!0}:void 0);if(!i)return{width:e.width,height:e.height,url:null};let c=Array.from(new Set(e.entries.flatMap(d=>d.texture?[d.texture]:[]))),l=new Map;await Promise.all(c.map(async d=>{l.set(d,await ji(d))}));for(let d of e.entries){let x=d.texture?l.get(d.texture):null;if(!d.texture){i.save(),Xi(i,d,n,o),i.restore();continue}x&&(i.save(),Be(i,o),i.beginPath(),Go(i,d.x,d.y,d.screenPts),i.clip(),Zi(i,d,x,o),i.restore()),d.texture&&n==="baked"&&(i.save(),Be(i,o),i.beginPath(),Go(i,d.x,d.y,d.screenPts),i.clip(),Wi(i,d.x,d.y,d.canvasW,d.canvasH,d.textureTint,o),i.restore()),Ji(i,d,o)}let u=await ea(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:u}}async function Rt(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await ta(i,n,t,o))}return s}var q=require("@layoutit/polycss-core"),kn=require("@layoutit/polycss-core"),Gr=require("@layoutit/polycss-core");var Ur=require("@layoutit/polycss-core");function $t(e,n){let o=e?.defaultView?.__polycssProjectiveQuadGuards,r=n&&o?{...n,...o}:o??n;return(0,Ur.resolveProjectiveQuadGuards)(r)}function Ut(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function jo(e){if(jr(e))return!0;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,q.safariCssProjectiveUnsupported)(t):!0}function gn(e){let n=e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0);return!!n?.supports?.("corner-top-left-shape","bevel")&&!!n.supports("corner-top-right-shape","bevel")&&!!n.supports("corner-bottom-right-shape","bevel")&&!!n.supports("corner-bottom-left-shape","bevel")}function jr(e){let n=e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0);return!!n?.supports?.("corner-top-left-shape","bevel")&&!!n.supports("corner-top-right-shape","bevel")}function na(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function Ye(e,n){return n?.disable?.includes("u")?null:jr(e)?"corner-bevel":jo(e)?na(e)?"border-large":"border":null}function Gt(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,q.safariCssProjectiveUnsupported)(t):!0}function yn(e,n,t,o,r){let s=new Set(o?.disable??[]);return(0,q.getSolidPaintDefaultsForPlansCore)(e,n,s,{solidTriangleSupported:jo(t),projectiveQuadSupported:Gt(t),cornerShapeSupported:gn(t),borderShapeSupported:Ut(t)},kn.parseHex,kn.rgbKey,r)}function On(e,n,t=new Set,o){let r=o??(typeof document<"u"?document:null);if(!r)return{};let s=t.size>0?{disable:Array.from(t)}:void 0;return yn(e,n,r,s)}function bn(e){let n=e??(typeof document<"u"?document:null);if(!n){if(!!!(typeof CSS<"u"?CSS:void 0)?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=typeof matchMedia<"u"?matchMedia:void 0;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}return Ut(n)}function vn(e){let n=e??(typeof document<"u"?document:null);if(!n){let t=typeof CSS<"u"?CSS:void 0;if(t?.supports?.("corner-top-left-shape","bevel")&&t.supports("corner-top-right-shape","bevel"))return!0;let o=(typeof navigator<"u"?navigator:globalThis.navigator)?.userAgent??"";if(!o)return!0;let r=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(o);return!/\bVersion\/[\d.]+.*\bSafari\//.test(o)||r}return jo(n)}function Dn(e,n,t,o){let r=o??(typeof document<"u"?document:null);return(0,q.filterAtlasPlans)(e,n,t,{solidTriangleSupported:vn(o),projectiveQuadSupported:r?Gt(r):!0,borderShapeSupported:bn(o)})}var Me=require("@layoutit/polycss-core"),Xe=require("@layoutit/polycss-core");var qt=require("@layoutit/polycss-core");var dt=require("@layoutit/polycss-core"),Wr=require("@layoutit/polycss-core");var jt=require("@layoutit/polycss-core");function we(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,s=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`(^|;)\\s*${s}\\s*:[^;]*`,"i"),c=i.test(o)?o.replace(i,(l,u)=>`${u}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;c!==o&&e.setAttribute("style",c)}function ht(e,n){let t=e.getAttribute("style")??"";if(!t||!t.toLowerCase().includes(n.toLowerCase()))return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`^\\s*${o}\\s*:`,"i"),s=t.split(";").map(i=>i.trim()).filter(i=>i&&!r.test(i)).join(";");s?e.setAttribute("style",s):e.removeAttribute("style")}function xn(e,n,t,o=!1){if(n==="dynamic"){let r=(0,jt.parseHex)(e.polygon.color??"#cccccc"),s=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return(0,jt.rgbKey)(r)!==t?.dynamicColorKey&&(s+=`;--psr:${(r.r/255).toFixed(4)};--psg:${(r.g/255).toFixed(4)};--psb:${(r.b/255).toFixed(4)}`),s}return e.shadedColor?`;color:${e.shadedColor}`:""}function oa(e,n){we(e,"--pnx",n.normal[0].toFixed(4)),we(e,"--pny",n.normal[1].toFixed(4)),we(e,"--pnz",n.normal[2].toFixed(4))}function Wt(e,n,t,o){if(t==="dynamic"){ht(e,"color"),ht(e,"background"),oa(e,n);let r=(0,jt.parseHex)(n.polygon.color??"#cccccc");(0,jt.rgbKey)(r)===o?.dynamicColorKey?(ht(e,"--psr"),ht(e,"--psg"),ht(e,"--psb")):(we(e,"--psr",(r.r/255).toFixed(4)),we(e,"--psg",(r.g/255).toFixed(4)),we(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(ht(e,"background"),we(e,"color",n.shadedColor)):(ht(e,"background"),ht(e,"color"))}var Yt=require("@layoutit/polycss-core"),ut=require("@layoutit/polycss-core"),In=require("@layoutit/polycss-core"),lt=require("@layoutit/polycss-core"),Yr="polycss-corner-shape-solid",Wo=new WeakMap,Yo=new WeakMap;function Ee(e,n,t){let o=Wo.get(e),r=Yo.get(e),s=typeof t=="number";if(!n.data&&!s&&(!o||o.length===0)){e.__polycssHasDataAttrs=!1;return}let i=new Map;if(n.data)for(let[l,u]of Object.entries(n.data))i.set(l,String(u));if(s&&i.set("poly-index",String(t)),o)for(let l of o)i.has(l)||e.removeAttribute(`data-${l}`);for(let[l,u]of i)r?.get(l)!==u&&e.setAttribute(`data-${l}`,u);let c=Array.from(i.keys());c.length>0?Wo.set(e,c):Wo.delete(e),i.size>0?Yo.set(e,i):Yo.delete(e),e.__polycssHasDataAttrs=c.length>0}function Xt(e){return e.__polycssHasDataAttrs===!0}function Xo(e,n,t,o,r=t==="dynamic"){if(!n.url)return;let s=`url(${n.url})`,i=o.canvasW||1,c=o.canvasH||1,l=(0,ut.atlasCanonicalSizeForEntry)(o),u=`${(0,dt.formatCssLength)(-o.x/i*l)} ${(0,dt.formatCssLength)(-o.y/c*l)}`,d=`${(0,dt.formatCssLength)(n.width/i*l)} ${(0,dt.formatCssLength)(n.height/c*l)}`,x=`transform:matrix3d(${o.atlasMatrix});--polycss-atlas-size:${l}px`,h=`${x};--polycss-atlas-position:${u};--polycss-atlas-image-size:${d}`;if(t==="dynamic"){let b=r?`;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`:"";e.setAttribute("style",h+`;--polycss-atlas-url:${s}`+b)}else e.setAttribute("style",x+`;background-image:${s};background-position:${u};background-size:${d};background-repeat:no-repeat;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`)}function Xr(e,n,t,o){if(n.texture){if(!t.texture||n.texture!==t.texture)return!1}else if(t.texture)return!1;let r=Zr(n,t);return r?(e.style.visibility="",we(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(we(e,"--pnx",r.normal[0].toFixed(4)),we(e,"--pny",r.normal[1].toFixed(4)),we(e,"--pnz",r.normal[2].toFixed(4))),Ee(e,t,n.index),!0):(e.style.visibility="hidden",Ee(e,t,n.index),!0)}function Zo(e,n,t,o,r){if(o!=="baked")return{...e,polygon:n,normal:t};let s=r.directionalLight,i=r.ambientLight,c=s?.direction??lt.DEFAULT_LIGHT_DIR,l=s?.color??lt.DEFAULT_LIGHT_COLOR,u=Math.max(0,s?.intensity??lt.DEFAULT_LIGHT_INTENSITY),d=i?.color??lt.DEFAULT_AMBIENT_COLOR,x=Math.max(0,i?.intensity??lt.DEFAULT_AMBIENT_INTENSITY),h=Math.hypot(c[0],c[1],c[2])||1,b=c[0]/h,v=c[1]/h,P=c[2]/h,C=r.lightOccludedPolyIndices?.has(e.index)??!1?0:u*Math.max(0,t[0]*b+t[1]*v+t[2]*P);return{...e,polygon:n,normal:t,shadedColor:(0,Wr.shadePolygon)(n.color??"#cccccc",C,l,d,x)}}function Zr(e,n){let t=qr(e,n);if(!t)return null;let{normal:o,xAxis:r,yAxis:s,tx:i,ty:c,tz:l}=t;return{normal:o,matrix:(0,dt.formatMatrix3dValues)([r[0]*e.canvasW/(0,ut.atlasCanonicalSizeForEntry)(e),r[1]*e.canvasW/(0,ut.atlasCanonicalSizeForEntry)(e),r[2]*e.canvasW/(0,ut.atlasCanonicalSizeForEntry)(e),0,s[0]*e.canvasH/(0,ut.atlasCanonicalSizeForEntry)(e),s[1]*e.canvasH/(0,ut.atlasCanonicalSizeForEntry)(e),s[2]*e.canvasH/(0,ut.atlasCanonicalSizeForEntry)(e),0,o[0],o[1],o[2],0,i,c,l,1])}}var qr=In.stableBasisFromPlan;function ra(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=qr(e,n);if(!o)return null;let r=(0,In.computeProjectiveQuadMatrix)(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return r?{matrix:r,normal:o.normal}:null}function qo(e,n,t,o,r=!1){let s=t.createElement("b");return s.setAttribute("style",`transform:matrix3d(${(0,dt.formatSolidQuadMatrix)(e)})`+xn(e,n,o,r)),Ee(s,e.polygon,e.index),s}function Qo(e,n,t,o,r=!1){let s=t.createElement("i");return s.setAttribute("style",(0,Yt.formatBorderShapeElementStyle)(e)+xn(e,n,o,r)),Ee(s,e.polygon,e.index),s}function Ko(e,n,t,o,r,s=!1){let i=o.createElement("u");return i.className=Yr,i.setAttribute("style",(0,Yt.formatCornerShapeElementStyle)(e,n)+xn(e,t,r,s)),Ee(i,e.polygon,e.index),i}function Jo(e,n,t,o,r=!1){let s=t.createElement("b");return s.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+xn(e,n,o,r)),Ee(s,e.polygon,e.index),s}function Qr(e,n,t,o,r,s,i){let c=n.projectiveMatrix?ra(n,t,s):Zr(n,t);if(!c)return!1;let l=Zo(n,t,c.normal,o,r);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,Wt(e,l,o,i),Ee(e,l.polygon,l.index),!0}function Kr(e,n,t,o){e.style.visibility="",e.setAttribute("style",(0,Yt.formatBorderShapeElementStyle)(n)),Wt(e,n,t,o),Ee(e,n.polygon,n.index)}function Jr(e,n,t,o,r){e.style.visibility="",e.className=Yr,e.setAttribute("style",(0,Yt.formatCornerShapeElementStyle)(n,t)),Wt(e,n,o,r),we(e,"background","currentColor"),Ee(e,n.polygon,n.index)}function er(e,n,t,o=!1){let r=t.createElement("s"),s=(0,ut.atlasCanonicalSizeForEntry)(e),i=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return r.setAttribute("style",`transform:matrix3d(${e.atlasMatrix});--polycss-atlas-size:${s}px;opacity:0`+i),Ee(r,e.polygon,e.index),r}var ns=require("@layoutit/polycss-core");var Hn=require("@layoutit/polycss-core");function gt(e,n,t,o={}){let r=o.primitive!=null?void 0:(()=>{let s=t.doc??(typeof document<"u"?document:null);return s?Ye(s,t.strategies)??"border":"border"})();return(0,Hn.computeSolidTrianglePlan)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??r})}function tr(e,n,t,o,r,s,i,c,l,u,d,x,h){let b=o.primitive!=null?void 0:(()=>{let v=t.doc??(typeof document<"u"?document:null);return v?Ye(v,t.strategies)??"border":"border"})();return(0,Hn.computeSolidTrianglePlanFromCssPoints)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??b},r,s,i,c,l,u,d,x,h)}var kt=require("@layoutit/polycss-core"),bt=require("@layoutit/polycss-core"),nr=require("@layoutit/polycss-core");var Fn=require("@layoutit/polycss-core");var sa="0 48px 96px 48px";function or(e,n){return(0,kt.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function rr(e,n,t){let o=(0,kt.resolveBleedRatio)(t.seamBleed),r=kt.DEFAULT_SEAM_BLEED*o,s={...t,bleedRatio:o};return n&&r>0?{...s,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:s}function Vn(e){return{updatesDisabled:e.stableTriangleColorFreezeFrames===0,freezeFrames:Math.max(1,Math.floor(e.stableTriangleColorFreezeFrames??1)),colorFrame:Math.max(0,Math.floor(e.stableTriangleColorFrame??0)),maxStep:Math.max(0,Math.floor(e.stableTriangleColorMaxStep??0))}}function es(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function yt(e,n,t,o,r,s){return t?s.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:r==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:es(n,s):!0}function sr(e,n){let t=e;t.__polycssSolidTrianglePrimitive!==n&&(n==="corner-bevel"?(e.style.width="",e.style.height="",e.style.backgroundColor="",e.style.borderWidth="",e.style.borderTopLeftRadius="",e.style.borderTopRightRadius="",e.style.removeProperty("corner-top-left-shape"),e.style.removeProperty("corner-top-right-shape")):(e.style.width="",e.style.height="",e.style.backgroundColor="",e.style.borderTopLeftRadius="",e.style.borderTopRightRadius="",e.style.removeProperty("corner-top-left-shape"),e.style.removeProperty("corner-top-right-shape"),e.style.borderWidth=n==="border-large"?sa:""),t.__polycssSolidTrianglePrimitive=n)}function ir(e){let n=e;n.__polycssSolidTriangleHidden&&(e.style.visibility="",n.__polycssSolidTriangleHidden=!1)}function Zt(e){let n=e;n.__polycssSolidTriangleHidden||(e.style.visibility="hidden",n.__polycssSolidTriangleHidden=!0)}function Pn(e,n){e.setAttribute("style",n.styleText),sr(e,n.primitive);let t=e;t.__polycssSolidTriangleBasis=n.basis,t.__polycssSolidTriangleHidden=!1,n.colorComputed&&(t.__polycssSolidTriangleColor=n.bakedColor??"",t.__polycssSolidTriangleColorRgb=n.bakedRgb,t.__polycssSolidTriangleColorAlpha=n.bakedAlpha),t.__polycssSolidTriangleColorFrame=void 0,(n.polygon.data||Xt(e))&&Ee(e,n.polygon)}function ts(e,n,t,o){if(!n.colorComputed){(n.polygon.data||Xt(e))&&Ee(e,n.polygon);return}let r=e,s=n.bakedColor??"",i=n.bakedRgb,c=n.bakedAlpha??1,l=r.__polycssSolidTriangleColor,u=r.__polycssSolidTriangleColorRgb,d=r.__polycssSolidTriangleColorAlpha??1,x=o??es(n.index,t);if(!t.updatesDisabled&&l!==s&&(l===void 0||x)){let h=s,b=i;if(t.maxStep>0&&u&&i&&d===c){let v=(0,bt.stepRgbToward)(u,i,t.maxStep);b=v,h=(0,bt.rgbToCss)(v,c)}(h!==l||!(0,bt.rgbEqual)(b,u))&&(e.style.color=h),r.__polycssSolidTriangleColor=h,r.__polycssSolidTriangleColorRgb=b,r.__polycssSolidTriangleColorAlpha=c,r.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||Xt(e))&&Ee(e,n.polygon)}function Sn(e,n,t,o){let r=e;sr(e,n.primitive),r.__polycssSolidTriangleBasis!==n.basis&&(r.__polycssSolidTriangleBasis=n.basis),ir(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||Xt(e))&&ts(e,n,t,o)}function Bn(e,n,t,o){ir(e),ts(e,n,t,o)}function Cn(e,n){let t=e;sr(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),ir(e),e.style.transform=n.transformText,(n.polygon.data||Xt(e))&&Ee(e,n.polygon)}function ia(e,n){let t=n.stableTriangleColorBudget;if(typeof t=="number"&&Number.isFinite(t)&&t>0)return t<=1?Math.max(1,Math.ceil(e*t)):Math.max(1,Math.floor(t));let o=Math.max(1,Math.floor(n.stableTriangleColorFreezeFrames??1));return Math.max(1,Math.ceil(e/o))}function ar(e,n,t){if(t.stableTriangleColorPolicy!=="adaptive")return null;if(t.stableTriangleColorFreezeFrames===0)return new Set;let o=Math.max(0,Math.floor(t.stableTriangleColorFrame??0)),r=Math.max(1,Math.floor(t.stableTriangleColorFreezeFrames??1));if(r<=1&&!Number.isFinite(t.stableTriangleColorBudget))return null;let s=ia(e.length,t),i=Math.max(1,Math.floor(t.stableTriangleColorMaxAge??Math.max(2,r*2))),c=[];for(let l=0;l<e.length;l++){let u=e[l],d=n[l];if(u.kind!=="triangle"||!d)continue;let x=u.element,h=x.__polycssSolidTriangleColor,b=d.bakedColor??"";if(h===b)continue;let v=x.__polycssSolidTriangleColorFrame??0,P=Math.max(0,o-v),g=(0,bt.colorErrorScore)(h,b);c.push({index:l,score:(P>=i?1e6:0)+g*1e4+P})}return c.length===0?new Set:(c.sort((l,u)=>u.score-l.score),new Set(c.slice(0,s).map(l=>l.index)))}function zn(e,n){let t=n.createElement("u");return Pn(t,e),Ee(t,e.polygon,e.index),t}function aa(e,n,t){let o=t.createElement("u");return Zt(o),Ee(o,e,n),o}function lr(e,n,t,o,r,s){let i=t,c=i.stableTriangleDebug,l=o&&r==="color-only";if(i.stableTriangleColorPolicy==="adaptive"||e.length!==n.length)return!1;let u=(0,Fn.stableTriangleMatrixDecimals)(i.stableTriangleMatrixDecimals),d=t.doc??(typeof document<"u"?document:null),x=d?Ye(d,t.strategies)??"border":"border";for(let b=0;b<e.length;b++){let v=e[b];if(v.kind!=="triangle"||v.polygonIndex!==b||!n[b])return!1}let h=or(n,t);for(let b=0;b<e.length;b++){let v=e[b].element,P=n[b];if(l){if(yt(v,b,o,c,i.stableTriangleColorPolicy,s)){let C=(0,nr.computeSolidTriangleColorPlan)(P,b,t);if(!C)continue;Bn(v,C,s)}continue}let g=gt(P,b,rr(b,h,t),{basis:v.__polycssSolidTriangleBasis,matrixDecimals:u,primitive:x,includeColor:r!=="plan-only"&&r!=="transform-only"&&yt(v,b,o,c,i.stableTriangleColorPolicy,s)});if(!g){Zt(v);continue}o&&r==="plan-only"||(o&&r==="transform-only"?Cn(v,g):o?Sn(v,g,s):Pn(v,g))}return!0}function Ot(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=Ye(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let r=(0,Fn.stableTriangleMatrixDecimals)(n.stableTriangleMatrixDecimals),s=[],i=or(e,n);for(let c=0;c<e.length;c+=1){let l=e[c],u=gt(l,c,rr(c,i,n),{matrixDecimals:r,primitive:o}),d=u?zn(u,t):aa(l,c,t);s.push({polygonIndex:c,element:d,kind:"triangle",dispose:()=>{}})}return{rendered:s,dispose(){}}}function Nn(e,n,t={}){let o=t.doc??(typeof document<"u"?document:null);if(!o)return{rendered:e,dispose:()=>{}};let r=Ye(o,t.strategies);if(!r||e.some(g=>g.kind!=="triangle")||n.length!==e.length)return null;for(let g=0;g<e.length;g++)if(e[g].polygonIndex!==g)return null;let s=t.optimizeStableTriangleStyle===!0&&(t.textureLighting??"baked")==="baked",i=t,c=i.stableTriangleDebug,l=i.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full"),u=s&&l==="color-only",d=Vn(i),x=(0,Fn.stableTriangleMatrixDecimals)(i.stableTriangleMatrixDecimals);if(lr(e,n,t,s,l,d))return{rendered:e,dispose(){}};let h=new Array(e.length),b=new Array(e.length),v=or(n,t);for(let g=0;g<e.length;g++){let C=e[g].element;if(u){let D=i.stableTriangleColorPolicy==="adaptive"||yt(C,g,s,c,i.stableTriangleColorPolicy,d);b[g]=D?(0,nr.computeSolidTriangleColorPlan)(n[g],g,t):null;continue}h[g]=gt(n[g],g,rr(g,v,t),{basis:C.__polycssSolidTriangleBasis,matrixDecimals:x,primitive:r,includeColor:l!=="plan-only"&&l!=="transform-only"&&yt(C,g,s,c,i.stableTriangleColorPolicy,d)})}let P=s&&l!=="plan-only"&&l!=="transform-only"?ar(e,u?b:h,i):null;for(let g=0;g<e.length;g++){if(u){let D=b[g];D&&Bn(e[g].element,D,d,P?.has(g));continue}let C=h[g];if(!C){Zt(e[g].element);continue}s&&l==="plan-only"||(s&&l==="transform-only"?Cn(e[g].element,C):s?Sn(e[g].element,C,d,P?.has(g)):Pn(e[g].element,C))}return{rendered:e,dispose(){}}}var ur=require("@layoutit/polycss-core");function os(){return new Promise(e=>setTimeout(e,0))}async function cr(e){return performance.now()-e<Me.ASYNC_RENDER_BUDGET_MS?e:(await os(),performance.now())}function rs(e,n){let t=(0,Me.resolveBleedRatio)(n.seamBleed),o=Me.DEFAULT_SEAM_BLEED*t,r={...n,bleedRatio:t};return e.seamBleedEdges?.size&&o>0?{...r,seamBleed:o,seamEdges:e.seamBleedEdges}:{...r,seamBleed:void 0,seamEdges:void 0}}function ss(e,n){return(0,Xe.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function is(e,n,t){let o=(0,Me.resolveBleedRatio)(t.seamBleed),r=Me.DEFAULT_SEAM_BLEED*o,s={...t,bleedRatio:o};return n&&r>0?{...s,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:s}function vt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=(0,Xe.buildBasisHints)(e,n),r=$t(t),s=e.map((i,c)=>(0,Xe.computeTextureAtlasPlan)(i,c,n,r,o[c]));return yn(s,n.textureLighting??"baked",t,n.strategies)}function xt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=n,s=o==="dynamic"&&r.skipDynamicNormalVars===!0,i=new Set(n.strategies?.disable??[]),c=!i.has("b"),l=c&&Gt(t),u=Ye(t,n.strategies),d=u!==null,x=!i.has("i")&&gn(t),h=!i.has("i")&&Ut(t),b=(0,Xe.buildBasisHints)(e,n),v=$t(t),P=ss(e,n),g=e.map((m,p)=>(0,Xe.computeTextureAtlasPlan)(m,p,is(p,P,n),v,b[p]));if(typeof window<"u"){let m=window,p=g[1];m.__vanillaPlan1={matrix:p?.matrix,canvasW:p?.canvasW,canvasH:p?.canvasH,vertexCount:e[1]?.vertices.length}}let C=n.solidPaintDefaults??(r.computeSolidPaintDefaults?yn(g,o,t,n.strategies):void 0),D=C?{...n,solidPaintDefaults:C}:n,k=g.map(m=>m&&d&&(0,q.isSolidTrianglePlan)(m)?gt(m.polygon,m.index,rs(m,D),{primitive:u??void 0}):null),z=g.map(m=>m&&x&&!(0,q.isSolidTrianglePlan)(m)&&!(c&&(0,q.isFullRectSolid)(m))&&!(l&&(0,q.isProjectiveQuadPlan)(m))?(0,qt.cornerShapeGeometryForPlan)(m):null),I=g.map((m,p)=>m&&(m.texture||!(c&&(0,q.isFullRectSolid)(m))&&!k[p]&&!(l&&(0,q.isProjectiveQuadPlan)(m))&&!z[p]&&!h?m:null)),{packed:Z,atlasScale:K}=_t(I,n.textureQuality,t),O=new Map,H=[],V=!1,$=[];for(let m=0;m<e.length;m++){let p=g[m],T=k[m],M=z[m];if(!p)continue;let R=Z.entries[m];if(R){let L=er(R,o,t,s);O.set(m,L),H.push({polygonIndex:m,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!p.texture&&c&&(0,q.isFullRectSolid)(p)){let L=qo(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&T){let L=zn(T,t);H.push({polygonIndex:m,element:L,kind:"triangle",plan:p,dispose:()=>{}})}else if(!p.texture&&l&&(0,q.isProjectiveQuadPlan)(p)){let L=Jo(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&M){let L=Ko(p,M,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"corner",plan:p,dispose:()=>{}})}else if(!p.texture&&h){let L=Qo(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"border",plan:p,dispose:()=>{}})}}H.sort((m,p)=>m.polygonIndex-p.polygonIndex);let A=Rt(Z.pages,o,t,K,()=>V).then(m=>{if(V){for(let p of m)p.url?.startsWith("blob:")&&URL.revokeObjectURL(p.url);return}$=m.flatMap(p=>p.url?.startsWith("blob:")?[p.url]:[]);for(let p=0;p<Z.pages.length;p++){let T=Z.pages[p],M=m[p];if(M)for(let R of T.entries){let L=O.get(R.index);!L||!M.url||Xo(L,M,o,R,!0)}}}).catch(()=>{if(!V)for(let m of O.values())we(m,"opacity","0.5"),we(m,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:H,solidPaintDefaults:C??{},pagesReady:A,dispose(){V=!0;for(let m of $)URL.revokeObjectURL(m);$=[]}}}async function Qt(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let r=n.textureLighting??"baked",i=r==="dynamic"&&n.skipDynamicNormalVars===!0,c=new Set(n.strategies?.disable??[]),l=!c.has("b"),u=l&&Gt(o),d=Ye(o,n.strategies),x=d!==null,h=!c.has("i")&&gn(o),b=!c.has("i")&&Ut(o);if(await os(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let v=(0,Xe.buildBasisHints)(e,n),P=$t(o),g=ss(e,n),C=performance.now(),D=new Array(e.length);for(let m=0;m<e.length;m++)if(D[m]=(0,Xe.computeTextureAtlasPlan)(e[m],m,is(m,g,n),P,v[m]),C=await cr(C),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let k=n.solidPaintDefaults??yn(D,r,o,n.strategies),z=new Array(D.length),I=new Array(D.length),Z=new Array(D.length);for(let m=0;m<D.length;m++){let p=D[m],T=p&&x&&(0,q.isSolidTrianglePlan)(p)?gt(p.polygon,p.index,rs(p,{...n,solidPaintDefaults:k}),{primitive:d??void 0}):null;z[m]=T;let M=p&&h&&!(0,q.isSolidTrianglePlan)(p)&&!(l&&(0,q.isFullRectSolid)(p))&&!(u&&(0,q.isProjectiveQuadPlan)(p))?(0,qt.cornerShapeGeometryForPlan)(p):null;if(I[m]=M,Z[m]=p&&(p.texture||!(l&&(0,q.isFullRectSolid)(p))&&!T&&!(u&&(0,q.isProjectiveQuadPlan)(p))&&!M&&!b?p:null),C=await cr(C),t())return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}let{packed:K,atlasScale:O}=_t(Z,n.textureQuality,o),H=new Map,V=[],$=!1,A=[];for(let m=0;m<e.length;m++){let p=D[m],T=z[m],M=I[m];if(!p)continue;let R=K.entries[m];if(R){let L=er(R,r,o,i);H.set(m,L),V.push({polygonIndex:m,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!p.texture&&l&&(0,q.isFullRectSolid)(p)){let L=qo(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&T){let L=zn(T,o);V.push({polygonIndex:m,element:L,kind:"triangle",plan:p,dispose:()=>{}})}else if(!p.texture&&u&&(0,q.isProjectiveQuadPlan)(p)){let L=Jo(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&M){let L=Ko(p,M,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"corner",plan:p,dispose:()=>{}})}else if(!p.texture&&b){let L=Qo(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"border",plan:p,dispose:()=>{}})}if(C=await cr(C),t()){for(let L of V)L.dispose();return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}}V.sort((m,p)=>m.polygonIndex-p.polygonIndex);let y=Rt(K.pages,r,o,O,()=>$||t()).then(m=>{if($||t()){for(let p of m)p.url?.startsWith("blob:")&&URL.revokeObjectURL(p.url);return}A=m.flatMap(p=>p.url?.startsWith("blob:")?[p.url]:[]);for(let p=0;p<K.pages.length;p++){let T=K.pages[p],M=m[p];if(M)for(let R of T.entries){let L=H.get(R.index);!L||!M.url||Xo(L,M,r,R,!0)}}}).catch(()=>{if(!($||t()))for(let m of H.values())we(m,"opacity","0.5"),we(m,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:V,solidPaintDefaults:k,pagesReady:y,dispose(){$=!0;for(let m of A)URL.revokeObjectURL(m);A=[]}}}function Kt(e,n,t,o={}){let r=o.textureLighting??"baked",s=o,i=s.optimizeStableTriangleStyle===!0&&r==="baked";if(!i||s.stableTriangleColorPolicy==="adaptive"||e.length!==t.polygonCount||n.length!==t.polygonCount||t.vertices.length<t.polygonCount*9)return!1;let c=s.stableTriangleDebug,l=s.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full");if(l==="color-only")return!1;let u=(0,ur.stableTriangleMatrixDecimals)(s.stableTriangleMatrixDecimals),d=Vn(s),x=o.tileSize??Me.DEFAULT_TILE,h=o.layerElevation??x,b=o.doc??(typeof document<"u"?document:null),v=b?Ye(b,o.strategies)??"border":"border";for(let g=0;g<e.length;g++){let C=e[g],D=n[g];if(C.kind!=="triangle"||C.polygonIndex!==g||!D||D.vertices.length!==3||D.texture||D.material?.texture)return!1}let P=t.vertices;for(let g=0;g<e.length;g++){let C=e[g].element,D=n[g],k=g*9,z=P[k+1]*x,I=P[k]*x,Z=P[k+2]*h,K=P[k+4]*x,O=P[k+3]*x,H=P[k+5]*h,V=P[k+7]*x,$=P[k+6]*x,A=P[k+8]*h,y=tr(D,g,o,{basis:C.__polycssSolidTriangleBasis,matrixDecimals:u,primitive:v,color:t.colors?.[g],includeColor:l!=="plan-only"&&l!=="transform-only"&&yt(C,g,i,c,s.stableTriangleColorPolicy,d)},z,I,Z,K,O,H,V,$,A);if(!y){Zt(C);continue}l!=="plan-only"&&(l==="transform-only"?Cn(C,y):Sn(C,y,d))}return!0}function Jt(e,n,t={}){if(e.length!==n.length)return!1;let o=t,r=t.doc??(typeof document<"u"?document:null),s=t.textureLighting??"baked",i=new Set(t.strategies?.disable??[]),c=!i.has("b"),l=!!r&&c&&Gt(r),u=!!r&&!i.has("i")&&gn(r),d=!!r&&!i.has("i")&&Ut(r),x=(0,Me.resolveBleedRatio)(o.seamBleed),h=r?$t(r,{bleed:Me.PROJECTIVE_QUAD_BLEED*x}):{denomEps:Me.PROJECTIVE_QUAD_DENOM_EPS,maxWeightRatio:Me.PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,bleed:Me.PROJECTIVE_QUAD_BLEED*x,disableGuards:!1},b=o.optimizeStableTriangleStyle===!0&&s==="baked",v=o.stableTriangleDebug,P=o.stableTriangleUpdateMode??(v==="plan-only"||v==="transform-only"?v:"full"),g=b&&P==="color-only",C=Vn(o),D=(0,ur.stableTriangleMatrixDecimals)(o.stableTriangleMatrixDecimals),k=r?Ye(r,t.strategies)??"border":"border";if(lr(e,n,t,b,P,C))return!0;let z=[],I=[],Z=[];for(let O=0;O<e.length;O++){let H=e[O];if(H.polygonIndex!==O)return!1;let V=n[O];if(!V||g&&H.kind!=="triangle")return!1;if(H.kind==="atlas"){if(!H.plan||!Xr(H.element,H.plan,V,s))return!1;continue}if(H.kind==="triangle"){let $=H.element;if(g){let y=o.stableTriangleColorPolicy==="adaptive"||yt($,O,b,v,o.stableTriangleColorPolicy,C);I[O]=y?(0,ns.computeSolidTriangleColorPlan)(V,O,t):null;continue}let A=gt(V,O,t,{basis:$.__polycssSolidTriangleBasis,matrixDecimals:D,primitive:k,includeColor:P!=="plan-only"&&P!=="transform-only"&&yt($,O,b,v,o.stableTriangleColorPolicy,C)});if(!A){z[O]=null;continue}z[O]=A;continue}if(H.kind==="solid"){if(!H.plan||V.texture||V.vertices.length!==H.plan.polygon.vertices.length)return!1;Z[O]=H.plan;continue}if(H.kind==="border"){let $=(0,Xe.computeTextureAtlasPlan)(V,O,t,h);if(!$||$.texture||!d||c&&(0,q.isFullRectSolid)($)||l&&(0,q.isProjectiveQuadPlan)($)||u&&(0,qt.cornerShapeGeometryForPlan)($))return!1;Z[O]=$;continue}if(H.kind==="corner"){let $=(0,Xe.computeTextureAtlasPlan)(V,O,t,h);if(!$||$.texture||!u||(0,q.isSolidTrianglePlan)($)||c&&(0,q.isFullRectSolid)($)||l&&(0,q.isProjectiveQuadPlan)($)||!(0,qt.cornerShapeGeometryForPlan)($))return!1;Z[O]=$;continue}return!1}let K=b&&P!=="plan-only"&&P!=="transform-only"?ar(e,g?I:z,o):null;for(let O=0;O<e.length;O++){let H=e[O];if(H.kind==="triangle"){if(g){let $=I[O];$&&Bn(H.element,$,C,K?.has(O));continue}let V=z[O];if(!V){Zt(H.element);continue}if(b&&P==="plan-only")continue;b&&P==="transform-only"?Cn(H.element,V):b?Sn(H.element,V,C,K?.has(O)):Pn(H.element,V)}else if(H.kind==="solid"){let V=Z[O];if(!V||!Qr(H.element,V,n[O],s,t,h,o.solidPaintDefaults))return!1}else if(H.kind==="border"){let V=Z[O];if(!V)return!1;Kr(H.element,V,s,o.solidPaintDefaults)}else if(H.kind==="corner"){let V=Z[O],$=V?(0,qt.cornerShapeGeometryForPlan)(V):null;if(!V||!$)return!1;Jr(H.element,V,$,s,o.solidPaintDefaults)}}return!0}var $n=require("@layoutit/polycss-core"),Ze=require("@layoutit/polycss-core"),St=require("@layoutit/polycss-core");var ee=require("@layoutit/polycss-core"),la=[.4,-.7,.59],ca="#ffffff",ua=1,da="#ffffff",pa=.4,ps=1,ma=8,fa=ee.PROJECTIVE_QUAD_BLEED,pt=1e-6,ha=(0,ee.resolveProjectiveQuadGuards)({bleed:0}),ms={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},mr=["t","b","bl","br","fr","fl"],ga=new Map([["0,0,1","t"],["0,0,-1","b"],["0,1,0","fl"],["0,-1,0","br"],["1,0,0","fr"],["-1,0,0","bl"]]);function as(e){let n=[];for(let t of mr)(0,ee.normalFacesCamera)(ms[t],e)&&n.push(t);return n.join("|")}function ya(e,n,t){let o=e.__polycssVoxelBrushState??(e.__polycssVoxelBrushState={});o.color!==n&&(e.style.color=n,o.color=n),o.transform!==t&&(e.style.transform=t,o.transform=t)}function ba(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let c=1;c+1<n.length;c+=1){let l=n[c],u=n[c+1],d=l[1]-t[1],x=l[0]-t[0],h=l[2]-t[2],b=u[1]-t[1],v=u[0]-t[0],P=u[2]-t[2];o-=x*P-h*v,r-=h*b-d*P,s-=d*v-x*b}let i=Math.hypot(o,r,s);return i<=1e-9?null:[Math.round(o/i),Math.round(r/i),Math.round(s/i)]}function va(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=ba(e),t=n?ga.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,s=1/0,i=-1/0,c=-1/0,l=-1/0;for(let x of e.vertices)o=Math.min(o,x[0]),r=Math.min(r,x[1]),s=Math.min(s,x[2]),i=Math.max(i,x[0]),c=Math.max(c,x[1]),l=Math.max(l,x[2]);let u=1e-6,d=Aa(e.color);return Math.abs(l-s)<=u?{axis:"z",face:t,left:r*ee.BASE_TILE,top:o*ee.BASE_TILE,width:Math.max(0,(c-r)*ee.BASE_TILE),height:Math.max(0,(i-o)*ee.BASE_TILE),z:s*ee.BASE_TILE,baseColor:d,bleed:dr()}:Math.abs(i-o)<=u?{axis:"x",face:t,left:r*ee.BASE_TILE,top:s*ee.BASE_TILE,width:Math.max(0,(c-r)*ee.BASE_TILE),height:Math.max(0,(l-s)*ee.BASE_TILE),z:-o*ee.BASE_TILE,baseColor:d,bleed:dr()}:Math.abs(c-r)<=u?{axis:"y",face:t,left:s*ee.BASE_TILE,top:o*ee.BASE_TILE,width:Math.max(0,(l-s)*ee.BASE_TILE),height:Math.max(0,(i-o)*ee.BASE_TILE),z:-r*ee.BASE_TILE,baseColor:d,bleed:dr()}:null}function dr(){return{left:0,right:0,top:0,bottom:0}}function xa(e){let n=o=>String(Number(o.toFixed(6))),t=`${e.item.baseColor}|${e.variableAxis}`;for(let o=0;o<3;o+=1)o!==e.variableAxis&&(t+=`|${o}:${n(e.fixed[o])}`);return t}function ls(e){return[e[1]*ee.BASE_TILE,e[0]*ee.BASE_TILE,e[2]*ee.BASE_TILE]}function cs(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function Pa(e,n,t){let o=e.left,r=e.left+e.width,s=e.top,i=e.top+e.height;if(Math.abs(n[0]-t[0])<=pt){if(Math.abs(n[0]-o)<=pt)return"left";if(Math.abs(n[0]-r)<=pt)return"right"}if(Math.abs(n[1]-t[1])<=pt){if(Math.abs(n[1]-s)<=pt)return"top";if(Math.abs(n[1]-i)<=pt)return"bottom"}return null}function Sa(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=pt)){if(t!==null)return null;t=o}return t}function Ca(e,n,t){let o=n.vertices,r=ls(o[t]),s=ls(o[(t+1)%o.length]),i=Pa(e,cs(e,r),cs(e,s));if(!i)return null;let c=Sa(r,s);if(c===null)return null;let l=Math.min(r[c],s[c]),u=Math.max(r[c],s[c]);return u-l>pt?{item:e,side:i,variableAxis:c,fixed:r,start:l,end:u}:null}function us(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],fa)}function Ea(e,n){let t=new Map;for(let o of n){let r=e[o.sourceIndex];if(r)for(let s=0;s<r.vertices.length;s+=1){let i=Ca(o,r,s);if(!i)continue;let c=xa(i),l=t.get(c);l?l.push(i):t.set(c,[i])}}for(let o of t.values()){if(o.length<2)continue;o.sort((s,i)=>s.start-i.start||s.end-i.end);let r=[];for(let s of o){r=r.filter(i=>i.end>s.start+pt);for(let i of r)i.item.sourceIndex!==s.item.sourceIndex&&(us(i),us(s));r.push(s)}}}function Ta(e){let n=(0,ee.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha}:{r:255,g:255,b:255,alpha:1}}function Aa(e){if(!e)return"#cccccc";let n=(0,ee.parsePureColor)(e);if(!n)return e;let t={r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha};if(t.alpha<1){let o=Math.round(Math.max(0,t.alpha)*1e3)/1e3;return`rgba(${pr(t.r)}, ${pr(t.g)}, ${pr(t.b)}, ${o})`}return wa(t)}function wa({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 pr(e){return Math.round(Math.max(0,Math.min(255,e)))}function Ma(e,n,t,o){let r=t?.direction??la,s=Math.hypot(r[0],r[1],r[2])||1,i=r[0]/s,c=r[1]/s,l=r[2]/s,u=Math.max(0,t?.intensity??ua)*Math.max(0,e[0]*i+e[1]*c+e[2]*l),d=Math.max(0,o?.intensity??pa),x=t?.color??ca,h=o?.color??da,b=(0,ee.shadePolygon)(n,u,x,h,d),v=Ta(n);if(v.alpha>=1)return b;let P=parseInt(b.slice(1,3),16),g=parseInt(b.slice(3,5),16),C=parseInt(b.slice(5,7),16);return`rgba(${P}, ${g}, ${C}, ${v.alpha})`}function La(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=va(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return Ea(e,n),n}function _a(e){return e.axis==="x"?{xAxis:[1,0,0],yAxis:[0,0,1],normal:[0,-1,0],tx:0,ty:-e.z,tz:0}:e.axis==="y"?{xAxis:[0,0,1],yAxis:[0,1,0],normal:[-1,0,0],tx:-e.z,ty:0,tz:0}:{xAxis:[1,0,0],yAxis:[0,1,0],normal:[0,0,1],tx:0,ty:0,tz:e.z}}function Ra(e){let n=e.left,t=e.top,o=e.left+e.width,r=e.top+e.height;return[n,t,o,t,o,r,n,r]}function ka(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function Oa(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(r=>!Number.isFinite(r)))return null;let o=ee.SOLID_QUAD_CANONICAL_SIZE/n;for(let r=0;r<8;r+=1)t[r]*=o;return`matrix3d(${t.map(r=>Number(r.toFixed(6))).join(",")})`}function ds(e,n){let t=e.left-e.bleed.left,o=e.top-e.bleed.top,r=e.width+e.bleed.left+e.bleed.right,s=e.height+e.bleed.top+e.bleed.bottom,i=e.z,c=r/n,l=s/n;return`matrix3d(${(e.axis==="x"?[c,0,0,0,0,0,l,0,0,-1,0,0,t,-i,o,1]:e.axis==="y"?[0,0,c,0,0,l,0,0,-1,0,0,0,-i,o,t,1]:[c,0,0,0,0,l,0,0,0,0,1,0,t,o,i,1]).map(d=>Number(d.toFixed(6))).join(",")})`}function Da(e,n){let{xAxis:t,yAxis:o,normal:r,tx:s,ty:i,tz:c}=_a(e),l=(0,ee.computeProjectiveQuadMatrix)(Ra(e),t,o,r,s,i,c,ha,ka(e));return l?Oa(l,n)??ds(e,n):ds(e,n)}function Ia(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function Ha(e){return Ia(e)?ma:ps}function Fa(e){return e.axis==="x"?[e.left+e.width/2,-e.z,e.top+e.height/2]:e.axis==="y"?[-e.z,e.top+e.height/2,e.left+e.width/2]:[e.left+e.width/2,e.top+e.height/2,e.z]}function Va(e,n){let t=Fa(e),o=n.meshRotation;o&&(t=(0,ee.rotateVec3InWrapperCssFrame)(t,o));let[r,s]=(0,ee.rotateVec3)(t,n.rotX,0,n.rotY);return{x:r,y:s}}function Ba(e,n,t){let o=e.filter(h=>n.has(h.face)).map(h=>({item:h,...Va(h,t)}));if(o.length===0)return[];let r=1/0,s=-1/0,i=1/0,c=-1/0;for(let h of o)r=Math.min(r,h.x),s=Math.max(s,h.x),i=Math.min(i,h.y),c=Math.max(c,h.y);let l=4,u=Math.max(1e-6,s-r),d=Math.max(1e-6,c-i),x=new Map;for(let h of o){let b=Math.min(l-1,Math.max(0,Math.floor((h.x-r)/u*l))),v=Math.min(l-1,Math.max(0,Math.floor((h.y-i)/d*l))),P=`${b}:${v}`,g=x.get(P);g||(g={tx:b,ty:v,sourceIndex:h.item.sourceIndex,items:[]},x.set(P,g)),g.items.push(h.item),g.sourceIndex=Math.min(g.sourceIndex,h.item.sourceIndex)}return Array.from(x.values()).sort((h,b)=>h.ty-b.ty||h.tx-b.tx||h.sourceIndex-b.sourceIndex).flatMap(h=>h.items)}function fs(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:s}=e,i=La(o);if(i.length===0)return null;let c=new Set(i.map(y=>y.face));t.classList.add("polycss-voxel-mesh");let l=Ha(n);l!==ps&&t.style.setProperty("--polycss-voxel-primitive",`${l}px`);let u=new Map,d=(y,m)=>{let p=`${y}|${m}`,T=u.get(p);if(T)return T;let M=Ma(ms[y],m,r,s);return u.set(p,M),M},x=new Map,h=new Map,b=new Map,v=new Map;for(let y of i){let m=v.get(y.face);m||(m=[],v.set(y.face,m)),m.push(y)}let P="",g=0,C=new Set,D=y=>{let m=x.get(y.sourceIndex);return m||(m=n.createElement("b"),x.set(y.sourceIndex,m),ya(m,d(y.face,y.baseColor),Da(y,l))),m},k=y=>{let m=h.get(y);return m||(m=n.createElement("span"),m.className=`polycss-voxel-face polycss-voxel-face-${y}`,m.dataset.polycssVoxelFace=y,m.__polycssVoxelFaceHost=!0,h.set(y,m)),m},z=()=>{for(let y of Array.from(t.childNodes))if(!y.__polycssVoxelFaceHost)return y;return null},I=(y,m)=>{let p=m.map(R=>R.sourceIndex).join(",");if(b.get(y)===p)return;let T=k(y),M=n.createDocumentFragment();for(let R of m)M.appendChild(D(R));T.replaceChildren(M),b.set(y,p)},Z=()=>{for(let y of mr)c.has(y)&&I(y,v.get(y)??[])},K=y=>new Set(y.split("|").filter(Boolean)),O=y=>{let m=K(y);return mr.filter(p=>m.has(p)&&c.has(p))},H=y=>{let m=0;for(let p of y)m+=v.get(p)?.length??0;return m},V=y=>{let m=new Set,p=[],T=new Map;for(let M of y){m.has(M.face)||(m.add(M.face),p.push(M.face));let R=T.get(M.face);R||(R=[],T.set(M.face,R)),R.push(M)}return{orderedFaces:p,itemsByFace:T}},$=(y,m)=>{let p=new Set(y);for(let T of C){if(p.has(T))continue;let M=h.get(T);M?.parentNode===t&&t.removeChild(M)}if(m){let T=n.createDocumentFragment();for(let M of y)T.appendChild(k(M));t.insertBefore(T,z()),C=p;return}for(let T=0;T<y.length;T+=1){let M=y[T],R=k(M);if(R.parentNode===t)continue;let L=null;for(let re=T+1;re<y.length;re+=1){let _=h.get(y[re]);if(_?.parentNode===t){L=_;break}}t.insertBefore(R,L??z())}C=p},A=(y,m,p)=>{if(!p){let re=O(y);$(re,!1),g=H(re);return}let T=new Set(y.split("|").filter(Boolean)),M=Ba(i,T,m),{orderedFaces:R,itemsByFace:L}=V(M);for(let re of R)I(re,L.get(re)??[]);$(R,!0),g=M.length};return Z(),{get brushCount(){return g},render(y){P=as(y),A(P,y,!0)},syncCamera(y){let m=as(y);m!==P&&(P=m,A(m,y,!1))},dispose(){for(let y of h.values())y.remove();t.classList.remove("polycss-voxel-mesh"),t.style.removeProperty("--polycss-voxel-primitive"),x.clear(),h.clear(),b.clear(),g=0,C=new Set,P=""}}}var hs="polycss-styles";function Un(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(hs))return;let t=n.createElement("style");t.id=hs,t.textContent=za,n.head.appendChild(t)}var za=`
2
2
  /* \u2500\u2500 Scene container \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
3
3
 
4
4
  .polycss-scene,
@@ -8,6 +8,18 @@
8
8
  box-sizing: border-box;
9
9
  }
10
10
 
11
+ /* Camera wrapper (mounted by createPolyCamera / PolyPerspectiveCamera /
12
+ PolyOrthographicCamera). Fills its parent so the scene inside has a
13
+ positioned, sized layout context for its top: 50% / left: 50% pin to
14
+ resolve against. Inline styles win on specificity if the user sizes
15
+ the camera explicitly. */
16
+ .polycss-camera {
17
+ position: relative;
18
+ display: block;
19
+ width: 100%;
20
+ height: 100%;
21
+ }
22
+
11
23
  .polycss-scene {
12
24
  position: absolute;
13
25
  top: 50%;
@@ -15,7 +27,6 @@
15
27
  width: 0;
16
28
  height: 0;
17
29
  transform-style: preserve-3d;
18
- perspective: 8000px;
19
30
  /* Pin the scene as a composited layer. Without this, mobile Chrome
20
31
  re-rasterizes every descendant tile when the scene transform changes
21
32
  each animation frame, which overruns the raster budget on textured
@@ -26,8 +37,8 @@
26
37
 
27
38
  /* \u2500\u2500 First-person controls perspective context \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
28
39
 
29
- /* PolyFirstPersonControls toggles this class on its host element (vanilla:
30
- scene.host; react/vue: the camera wrapper). FPV needs a real perspective
40
+ /* PolyFirstPersonControls toggles this class on the camera wrapper
41
+ (scene.cameraEl in vanilla; the camera wrapper div in react/vue). FPV needs a real perspective
31
42
  context so scene Z translation produces visible depth motion - without
32
43
  it, walking forward looks like a planar pan. The class wins over inline
33
44
  perspective styles (e.g. PolyOrthographicCamera's perspective: none)
@@ -40,12 +51,32 @@
40
51
  transform-style: preserve-3d !important;
41
52
  }
42
53
 
54
+ /* \u2500\u2500 Shadow root 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 */
55
+
56
+ /* Single 0\xD70 preserve-3d container that owns every shadow SVG (ground +
57
+ per-face receiver). Children composite via their own absolute matrix3d
58
+ transforms exactly as if mounted on .polycss-scene directly. The wrapper
59
+ exists so the DOM has one obvious "shadows live here" node and so
60
+ future toggles (clip-region, hide-all-shadows) flip a single ancestor. */
61
+ .polycss-shadows {
62
+ position: absolute;
63
+ top: 0;
64
+ left: 0;
65
+ width: 0;
66
+ height: 0;
67
+ transform-style: preserve-3d;
68
+ pointer-events: none;
69
+ }
70
+
43
71
  /* \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 */
44
72
 
45
73
  .polycss-mesh {
46
74
  position: absolute;
47
75
  transform-style: preserve-3d;
48
- transform-origin: var(--origin);
76
+ /* Pivot at wrapper local (0,0,0) for three.js mesh.position/rotation/scale
77
+ parity. Geometry is positioned by the parser (bbox-min-at-origin by
78
+ default, or pre-centered via parseGltf/parseObj { center: true }). */
79
+ transform-origin: 0 0 0;
49
80
  }
50
81
 
51
82
  /* \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 */
@@ -81,11 +112,27 @@
81
112
  height: 64px;
82
113
  }
83
114
 
84
- .polycss-mesh.polycss-voxel-mesh > b {
115
+ .polycss-mesh.polycss-voxel-mesh > .polycss-voxel-face {
116
+ position: absolute;
117
+ display: block;
85
118
  top: 0;
86
119
  left: 0;
87
- width: 1px;
88
- height: 1px;
120
+ width: 0;
121
+ height: 0;
122
+ transform-style: preserve-3d;
123
+ transform-origin: 0 0;
124
+ margin: 0;
125
+ padding: 0;
126
+ font: inherit;
127
+ line-height: 0;
128
+ pointer-events: none;
129
+ }
130
+
131
+ .polycss-mesh.polycss-voxel-mesh > .polycss-voxel-face > b {
132
+ top: 0;
133
+ left: 0;
134
+ width: var(--polycss-voxel-primitive, 1px);
135
+ height: var(--polycss-voxel-primitive, 1px);
89
136
  backface-visibility: visible;
90
137
  pointer-events: none;
91
138
  }
@@ -108,18 +155,42 @@
108
155
  box-sizing: content-box;
109
156
  border: 0 solid transparent;
110
157
  border-color: transparent transparent currentColor transparent;
111
- border-width: 0 32px 64px 32px;
112
- }
113
-
114
- /* <q> \u2014 dedicated shadow leaf. Same border-shape rendering trick as <i>
115
- (border-color: currentColor fills the polygon outline) but with its
116
- own tag so we don't have to thread :not(.polycss-shadow) exclusions
117
- through every dynamic-mode color rule. backface-visibility must be
118
- visible because the projection matrix is near-rank-deficient and the
119
- resulting plane's normal can read as back-facing under some camera
120
- angles; the leaf is intentionally always painted. Strip the UA's
121
- default ::before/::after open-/close-quote so the element is just a
122
- styled box. */
158
+ border-width: 0 16px 32px 16px;
159
+ }
160
+
161
+ @supports (corner-top-left-shape: bevel) and (corner-top-right-shape: bevel) {
162
+ .polycss-scene > u,
163
+ .polycss-mesh > u,
164
+ .polycss-bucket > u {
165
+ border-width: 0;
166
+ width: 32px;
167
+ height: 32px;
168
+ background-color: currentColor;
169
+ border-top-left-radius: 50% 100%;
170
+ border-top-right-radius: 50% 100%;
171
+ corner-top-left-shape: bevel;
172
+ corner-top-right-shape: bevel;
173
+ }
174
+
175
+ .polycss-scene > u.polycss-corner-shape-solid,
176
+ .polycss-mesh > u.polycss-corner-shape-solid,
177
+ .polycss-bucket > u.polycss-corner-shape-solid {
178
+ width: 16px;
179
+ height: 16px;
180
+ box-sizing: border-box;
181
+ border: 0;
182
+ background: currentColor;
183
+ border-radius: 0;
184
+ corner-top-left-shape: initial;
185
+ corner-top-right-shape: initial;
186
+ corner-bottom-right-shape: initial;
187
+ corner-bottom-left-shape: initial;
188
+ }
189
+ }
190
+
191
+ /* Reserved internal <q> shadow element rules. Current shadow emission uses SVG
192
+ surfaces; these rules keep any retained <q> markup styled as a plain
193
+ border-shape leaf instead of inheriting UA quote styling. */
123
194
  .polycss-scene q {
124
195
  position: absolute;
125
196
  display: block;
@@ -213,7 +284,7 @@
213
284
  @property --clz { syntax: "<number>"; inherits: true; initial-value: 1; }
214
285
 
215
286
  /* Ground-plane position in CSS pixels along the CSS-Z axis (= world-Z, the
216
- up axis in polycss's world convention). Stored as a <number> so it can be
287
+ up axis in PolyCSS's world convention). Stored as a <number> so it can be
217
288
  used directly inside matrix3d() calc() expressions (matrix3d requires
218
289
  dimensionless entries \u2014 no px units).
219
290
  Set by recomputeShadowGround() from the min world-Z of casting meshes. */
@@ -302,37 +373,105 @@
302
373
  leaves, so there's nothing inside a leaf that needs to participate
303
374
  in 3D compositing across the contain boundary. */
304
375
  contain: strict;
376
+ /*
377
+ * Three.js MeshLambertMaterial parity for textured surfaces:
378
+ *
379
+ * target = sRGB_encode(albedo_linear \xD7 irradiance_linear / \u03C0)
380
+ *
381
+ * background-blend-mode: multiply produces (bitmap \xD7 tint) in sRGB
382
+ * \u2014 approximately sRGB(albedo_linear \xD7 tint_linear) when bitmap \u2248
383
+ * sRGB(albedo_linear). So we want tint = sRGB_encode(irradiance /\u03C0).
384
+ *
385
+ * Each light/ambient colour channel is sRGB-to-linearised
386
+ * via pow((c + 0.055) / 1.055, 2.4) before the dot product so the
387
+ * irradiance accumulates in linear space; final encode is
388
+ * 1.055 \xD7 pow(c, 1/2.4) - 0.055. min(1, \u2026) clamps inside the encode
389
+ * domain. Matches the solid <b>/<i>/<u> pipeline below.
390
+ */
305
391
  background-color: rgb(
306
- calc(255 * (var(--par) * var(--pai)
307
- + var(--plr) * var(--pli) * var(--plam)))
308
- calc(255 * (var(--pag) * var(--pai)
309
- + var(--plg) * var(--pli) * var(--plam)))
310
- calc(255 * (var(--pab) * var(--pai)
311
- + var(--plb) * var(--pli) * var(--plam)))
392
+ calc(255 * max(0, 1.055 * pow(min(1, (
393
+ pow((var(--par) + 0.055) / 1.055, 2.4) * var(--pai) +
394
+ pow((var(--plr) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
395
+ ) / 3.14159265), 0.4167) - 0.055))
396
+ calc(255 * max(0, 1.055 * pow(min(1, (
397
+ pow((var(--pag) + 0.055) / 1.055, 2.4) * var(--pai) +
398
+ pow((var(--plg) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
399
+ ) / 3.14159265), 0.4167) - 0.055))
400
+ calc(255 * max(0, 1.055 * pow(min(1, (
401
+ pow((var(--pab) + 0.055) / 1.055, 2.4) * var(--pai) +
402
+ pow((var(--plb) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
403
+ ) / 3.14159265), 0.4167) - 0.055))
312
404
  );
313
405
  background-blend-mode: multiply;
406
+ background-image: var(--polycss-atlas-url);
407
+ background-position: var(--polycss-atlas-position);
408
+ background-repeat: no-repeat;
409
+ background-size: var(--polycss-atlas-image-size);
410
+ mask-image: var(--polycss-atlas-url);
411
+ mask-mode: alpha;
412
+ mask-position: var(--polycss-atlas-position);
413
+ mask-repeat: no-repeat;
414
+ mask-size: var(--polycss-atlas-image-size);
415
+ -webkit-mask-image: var(--polycss-atlas-url);
416
+ -webkit-mask-position: var(--polycss-atlas-position);
417
+ -webkit-mask-repeat: no-repeat;
418
+ -webkit-mask-size: var(--polycss-atlas-image-size);
314
419
  }
315
420
 
316
421
  .polycss-scene[data-polycss-lighting="dynamic"] b,
317
422
  .polycss-scene[data-polycss-lighting="dynamic"] i,
318
423
  .polycss-scene[data-polycss-lighting="dynamic"] u {
424
+ /*
425
+ * Three.js MeshLambertMaterial parity (default useLegacyLights=false,
426
+ * physically-correct pipeline):
427
+ *
428
+ * lit_linear = albedo_linear \xD7 (lightColor_linear \xD7 intensity \xD7 lambert
429
+ * + ambient_linear \xD7 ambientIntensity) / \u03C0
430
+ * output = 255 \xD7 sRGB_encode(min(1, lit_linear))
431
+ *
432
+ * sRGB\u2192linear: pow((c + 0.055) / 1.055, 2.4) for c > 0.04045
433
+ * 12.92 \xD7 c otherwise (skipped \u2014 tiny)
434
+ * linear\u2192sRGB: 1.055 \xD7 pow(c, 1/2.4) - 0.055 for c > 0.0031308
435
+ * 12.92 \xD7 c otherwise (skipped \u2014 tiny)
436
+ *
437
+ * The naive pow(c, 2.4) shortcut undershoots by ~2x for small c
438
+ * (dark channels of a saturated colour) \u2014 the +0.055/1.055 offset
439
+ * is load-bearing for the G/B drift on saturated fixtures.
440
+ *
441
+ * Verified against per-pixel screenshots in bench/three-parity.html
442
+ * (cube #dc2626 top face): drift <3 per channel across i=0.5..3,
443
+ * ambient=0..0.3, lambert=0..1.
444
+ */
319
445
  color: rgb(
320
- calc(255 * var(--psr) * (var(--par) * var(--pai)
321
- + var(--plr) * var(--pli) * var(--plam)))
322
- calc(255 * var(--psg) * (var(--pag) * var(--pai)
323
- + var(--plg) * var(--pli) * var(--plam)))
324
- calc(255 * var(--psb) * (var(--pab) * var(--pai)
325
- + var(--plb) * var(--pli) * var(--plam)))
446
+ calc(255 * max(0, 1.055 * pow(min(1,
447
+ pow((var(--psr) + 0.055) / 1.055, 2.4) * (
448
+ pow((var(--par) + 0.055) / 1.055, 2.4) * var(--pai) +
449
+ pow((var(--plr) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
450
+ ) / 3.14159265
451
+ ), 0.4167) - 0.055))
452
+ calc(255 * max(0, 1.055 * pow(min(1,
453
+ pow((var(--psg) + 0.055) / 1.055, 2.4) * (
454
+ pow((var(--pag) + 0.055) / 1.055, 2.4) * var(--pai) +
455
+ pow((var(--plg) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
456
+ ) / 3.14159265
457
+ ), 0.4167) - 0.055))
458
+ calc(255 * max(0, 1.055 * pow(min(1,
459
+ pow((var(--psb) + 0.055) / 1.055, 2.4) * (
460
+ pow((var(--pab) + 0.055) / 1.055, 2.4) * var(--pai) +
461
+ pow((var(--plb) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
462
+ ) / 3.14159265
463
+ ), 0.4167) - 0.055))
326
464
  );
327
465
  }
328
466
 
329
- /* \u2500\u2500 Cast shadows (dynamic mode only) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
467
+ /* \u2500\u2500 Retained <q> shadow projection (dynamic-mode CSS path) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
330
468
 
331
469
  /*
332
- * Shadow projection matrix. Projects any 3D point P onto the horizontal
333
- * ground plane (cssZ \u2248 G) along the CSS-space light direction (--clx/y/z).
470
+ * Projection matrix for retained internal <q> shadow leaves. Projects any
471
+ * 3D point P onto the horizontal ground plane (cssZ \u2248 G) along the CSS-space
472
+ * light direction (--clx/y/z).
334
473
  *
335
- * In polycss's world convention world Z is up (red-green plane is the
474
+ * In PolyCSS's world convention world Z is up (red-green plane is the
336
475
  * floor in the axes helper). After the world\u2192CSS swap (Y\u2194X), world Z stays
337
476
  * as CSS Z, so the ground plane normal in CSS space is +cssZ.
338
477
  *
@@ -343,7 +482,7 @@
343
482
  * has a valid layout box. The fix: collapse along z by a near-zero
344
483
  * scale (Z_SQUASH = 0.01) instead of exactly zero \u2014 output.z is then
345
484
  * approximately G with ~1% drift from the input, full-rank and renderable.
346
- * The shadow still looks flat to the eye (the drift is sub-pixel for
485
+ * The result still looks flat to the eye (the drift is sub-pixel for
347
486
  * any realistic scene size).
348
487
  *
349
488
  * out.cssX = P.cssX - (--clx/--clz) * (P.cssZ - G)
@@ -371,18 +510,290 @@
371
510
  );
372
511
  }
373
512
 
374
- /* <q> shadow leaf \u2014 Lambert-gated opacity. Polygons facing the light cast
375
- full shadow; polygons facing away cast zero shadow (their projection
376
- would stack inside the silhouette and produce ugly overdraw). The
377
- * 10 multiplier sharpens the cutoff so small positive Lambert values
378
- jump quickly to 1, giving a near-binary visibility decision with a
379
- smooth edge transition. Pure CSS calc \u2014 no JS at light-change time.
513
+ /* Retained <q> opacity gate. Polygons facing the light cast full shadow;
514
+ polygons facing away cast zero shadow. The * 10 multiplier sharpens the
515
+ cutoff so small positive Lambert values jump quickly to 1. */
516
+ .polycss-scene[data-polycss-lighting="dynamic"] q {
517
+ opacity: clamp(0, calc((var(--pnx) * var(--clx) + var(--pny) * var(--cly) + var(--pnz) * var(--clz)) * 10), 1);
518
+ }
519
+ `;var gs=require("@layoutit/polycss-core"),Na=1,qe=gs.BASE_TILE,$a=.1;function Ua(e){return[e[1]*qe,e[0]*qe,e[2]*qe]}function en(e){return[e[1],e[0],e[2]]}function Ct(e){return e?.direction?{...e,direction:en(e.direction)}:e}function Gn(e){let n=typeof e.scale=="number"?e.scale:e.scale?.[0]??1,t=typeof e.scale=="number"?e.scale:e.scale?.[1]??1,o=typeof e.scale=="number"?e.scale:e.scale?.[2]??1,r=n!==1||t!==1||o!==1,s=!!e.rotation&&(!!e.rotation[0]||!!e.rotation[1]||!!e.rotation[2]),i=e.position?Ua(e.position):[0,0,0],c=[];return(i[0]!==0||i[1]!==0||i[2]!==0)&&c.push(`translate3d(${i[0]}px, ${i[1]}px, ${i[2]}px)`),s&&(e.rotation[0]&&c.push(`rotateY(${-e.rotation[0]}deg)`),e.rotation[1]&&c.push(`rotateX(${-e.rotation[1]}deg)`),e.rotation[2]&&c.push(`rotateZ(${-e.rotation[2]}deg)`)),r&&c.push(`scale3d(${n}, ${t}, ${o})`),c.length>0?c.join(" "):void 0}function fr(e,n=[0,0,0],t=1){let o=e.state,r=o.rotX,s=o.rotY,c=(o.zoom??Na)/qe*t,l=(o.distance??0)*t,u=o.target??[0,0,0],d=u[0]+n[0],x=u[1]+n[1],h=u[2]+n[2],b=x*qe,v=d*qe,P=h*qe;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${r}deg) rotate(${s}deg) translate3d(${-b}px, ${-v}px, ${-P}px)`}function Ga(e){let n=e.trim();if(!n||n==="normal")return 1;let t=n.endsWith("%")?Number(n.slice(0,-1))/100:Number(n);return Number.isFinite(t)&&t>0?t:1}function ys(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=Ga(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function bs(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}function vs(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let x=1;x+1<e.vertices.length;x++){let h=e.vertices[x],b=e.vertices[x+1],v=h[1]-n[1],P=h[0]-n[0],g=h[2]-n[2],C=b[1]-n[1],D=b[0]-n[0],k=b[2]-n[2];t-=P*k-g*D,o-=g*C-v*k,r-=v*D-P*C}let s=Math.hypot(t,o,r);if(s<1e-9)return null;t/=s,o/=s,r/=s;let i=1/$a,c=Math.round(t*i)/i,l=Math.round(o*i)/i,u=Math.round(r*i)/i,d=Math.hypot(c,l,u);return d<1e-9?null:{key:c+","+l+","+u,vec:[c/d,l/d,u/d]}}function xs(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let r of t)if(!o.includes(r))return!1;return!0}function Ps(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Ss(e,n){return e===n?!0:(e?.color??"#000000")===(n?.color??"#000000")&&(e?.opacity??.25)===(n?.opacity??.25)&&(e?.lift??.05)===(n?.lift??.05)&&(e?.maxExtend??2e3)===(n?.maxExtend??2e3)}var Et=require("@layoutit/polycss-core");var ja=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"],tn="--polycss-light-preview-active",Cs=`var(${tn}, 0)`,Wa="max(0, calc(var(--pnx, 0) * var(--plx, 0) + var(--pny, 0) * var(--ply, 0) + var(--pnz, 1) * var(--plz, 1)))",hr=(e,n,t)=>`calc(255 * max(0, 1.055 * pow(min(1, pow((var(${e}, 1) + 0.055) / 1.055, 2.4) * (pow((var(${n}, 1) + 0.055) / 1.055, 2.4) * var(--pai, 0.4) + pow((var(${t}, 1) + 0.055) / 1.055, 2.4) * var(--pli, 1) * var(--plam, 0)) / 3.14159265), 0.4167) - 0.055))`,Ya=hr("--psr","--par","--plr"),Xa=hr("--psg","--pag","--plg"),Za=hr("--psb","--pab","--plb");function he(e,n,t){return e.style.getPropertyValue(n)===t?!1:(e.style.setProperty(n,t),!0)}function Dt(e){for(let n of ja)e.style.getPropertyValue(n)&&e.style.removeProperty(n)}function jn(e,n){let t=n.directionalLight?.direction??[.4,-.7,.59],o=en(t),r=Math.hypot(o[0],o[1],o[2])||1,s=o[0]/r,i=o[1]/r,c=o[2]/r,l=(0,Et.parseHexColor)(n.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],u=(0,Et.parseHexColor)(n.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],d=n.directionalLight?.intensity??1,x=n.ambientLight?.intensity??.4,h=P=>(P/255).toFixed(4);he(e,"--plx",s.toFixed(2)),he(e,"--ply",i.toFixed(2)),he(e,"--plz",c.toFixed(2)),he(e,"--plr",h(l[0])),he(e,"--plg",h(l[1])),he(e,"--plb",h(l[2])),he(e,"--pli",d.toFixed(4)),he(e,"--par",h(u[0])),he(e,"--pag",h(u[1])),he(e,"--pab",h(u[2])),he(e,"--pai",x.toFixed(4));let b=c,v=Math.sign(b||1)*Math.max(Math.abs(b),.01);he(e,"--clx",s.toFixed(2)),he(e,"--cly",i.toFixed(2)),he(e,"--clz",v.toFixed(2))}function Es(e,n){let t=n.textureLighting==="dynamic";if(e.dataset.polycssLighting=n.textureLighting??"baked",!t){Dt(e);return}jn(e,n)}function It(e,n){n.paintColor?e.style.setProperty("--polycss-paint",n.paintColor):e.style.getPropertyValue("--polycss-paint")&&e.style.removeProperty("--polycss-paint"),n.dynamicColor?(e.style.setProperty("--psr",(n.dynamicColor.r/255).toFixed(4)),e.style.setProperty("--psg",(n.dynamicColor.g/255).toFixed(4)),e.style.setProperty("--psb",(n.dynamicColor.b/255).toFixed(4))):(e.style.getPropertyValue("--psr")||e.style.getPropertyValue("--psg")||e.style.getPropertyValue("--psb"))&&(e.style.removeProperty("--psr"),e.style.removeProperty("--psg"),e.style.removeProperty("--psb"))}function Ts(e,n){let t=(0,Et.parseHex)(n??"#cccccc");e.style.setProperty("--psr",(t.r/255).toFixed(4)),e.style.setProperty("--psg",(t.g/255).toFixed(4)),e.style.setProperty("--psb",(t.b/255).toFixed(4))}function gr(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=t.textureLighting??"baked",r={directionalLight:Ct(t.directionalLight),ambientLight:t.ambientLight,textureLighting:o,textureQuality:t.textureQuality,seamBleed:t.seamBleed,strategies:t.strategies},s=Zo(e.plan,n,e.plan.normal,o,r);return Wt(e.element,s,o),o==="baked"&&Qa(e.element),!0}function qa(e){let n=(0,Et.parsePureColor)(e)??{rgb:[255,255,255],alpha:1},[t,o,r]=n.rgb,s=(c,l)=>`calc(${c} * (1 - ${Cs}) + var(${l}, ${c}) * ${Cs})`,i=n.alpha<1?` / ${n.alpha}`:"";return`rgb(${s(t,"--polycss-preview-r")} ${s(o,"--polycss-preview-g")} ${s(r,"--polycss-preview-b")}${i})`}function As(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=e.element,r=e.plan.normal,s=(0,Et.parseHex)(n.color??"#cccccc"),i=!1;return i=he(o,"--pnx",r[0].toFixed(4))||i,i=he(o,"--pny",r[1].toFixed(4))||i,i=he(o,"--pnz",r[2].toFixed(4))||i,i=he(o,"--psr",(s.r/255).toFixed(4))||i,i=he(o,"--psg",(s.g/255).toFixed(4))||i,i=he(o,"--psb",(s.b/255).toFixed(4))||i,i=he(o,"--plam",Wa)||i,i=he(o,"--polycss-preview-r",Ya)||i,i=he(o,"--polycss-preview-g",Xa)||i,i=he(o,"--polycss-preview-b",Za)||i,i=he(o,"--polycss-paint",qa(t))||i,o.style.getPropertyValue("color")&&(o.style.removeProperty("color"),i=!0),i}function Qa(e){e.style.removeProperty("--pnx"),e.style.removeProperty("--pny"),e.style.removeProperty("--pnz"),e.style.removeProperty("--psr"),e.style.removeProperty("--psg"),e.style.removeProperty("--psb"),e.style.removeProperty("--plam"),e.style.removeProperty("--polycss-preview-r"),e.style.removeProperty("--polycss-preview-g"),e.style.removeProperty("--polycss-preview-b"),e.style.removeProperty("--polycss-paint")}var Ka="http://www.w3.org/2000/svg",Wn=class{constructor(){this.groundSvg=null;this.groundVisible=!1;this.currentGroundCssZ=null;this.shadowRoot=null}};function ws(e,n,t){let o=e.shadowRoot;if(o||(o=n.createElement("div"),o.setAttribute("class","polycss-shadows"),o.style.position="absolute",o.style.top="0",o.style.left="0",o.style.width="0",o.style.height="0",o.style.transformStyle="preserve-3d",o.style.pointerEvents="none",e.shadowRoot=o),o.parentNode!==t){let r=t.firstChild;r?t.insertBefore(o,r):t.appendChild(o)}return o}function Ms(e){e.groundSvg?.parentNode&&e.groundSvg.parentNode.removeChild(e.groundSvg),e.groundSvg=null,e.groundVisible=!1}function Ls(e){e.groundSvg&&e.groundVisible&&(e.groundSvg.style.display="none",e.groundVisible=!1)}function _s(e,n,t,o){let r=[],s=e.firstChild;for(let i=0;i<t;i++){let c=s;c&&c.tagName==="path"?s=c.nextSibling:(c=n.createElementNS(Ka,"path"),c.setAttribute("fill-rule","nonzero"),o&&(c.setAttribute("stroke-width","0.5"),c.setAttribute("stroke-linejoin","round")),e.insertBefore(c,s)),r.push(c)}for(;s;){let i=s.nextSibling;e.removeChild(s),s=i}return r}function Rs(e){return{host:e.host,doc:e.doc,cameraEl:e.cameraEl,sceneEl:e.sceneEl,camera:e.camera,layoutScale:e.layoutScale,options:{current:e.options},meshes:new Set,meshAutoCounter:{next:0},autoCenter:{offset:[0,0,0]},bboxCenterCssCache:{value:null},shadowSvgState:new Wn,receiverShadowCache:new Map,receiverShadowCacheKey:new Map,casterItemsCache:new Map,casterItemsCacheKey:new Map}}var ze=require("@layoutit/polycss-core");function ks(e){for(let n of e)n.svg&&n.svg.parentNode&&n.svg.parentNode.removeChild(n.svg),n.svg=null}function Os(e,n){if(n){let t=e.receiverShadowCache.get(n);t&&ks(t),e.receiverShadowCache.delete(n),e.receiverShadowCacheKey.delete(n)}else{for(let t of e.receiverShadowCache.values())ks(t);e.receiverShadowCache.clear(),e.receiverShadowCacheKey.clear()}}function Ds(e,n){n?(e.casterItemsCache.delete(n),e.casterItemsCacheKey.delete(n)):(e.casterItemsCache.clear(),e.casterItemsCacheKey.clear())}function Is(e){Ms(e.shadowSvgState),Hs(e)}function yr(e){return e.handle.id??e.autoMeshId}var Ja="http://www.w3.org/2000/svg",Yn=new WeakMap,Fs=new WeakMap,Vs=new WeakMap,Bs=new WeakMap,zs=new WeakMap;function Ns(e){let n=Yn.get(e);return n||(n=new Map,Yn.set(e,n)),n}function br(e){let n=Yn.get(e);if(n){for(let t of n.values())t.svg&&t.svg.parentNode&&t.svg.parentNode.removeChild(t.svg);n.clear(),Yn.delete(e)}}function Hs(e){for(let n of e.meshes)br(n)}function $s(e,n,t,o,r,s,i,c,l,u){let d=e.options.current,{receiverShadowCache:x,receiverShadowCacheKey:h,casterItemsCache:b,casterItemsCacheKey:v}=e,P=o.handle.transform.position??[0,0,0],g=o.handle.transform.rotation??[0,0,0],C=o.polygons.some(A=>A.texture!==void 0),D=(0,ze.meshScaleVec3)(o.handle.transform.scale),k=o.bboxCenterCss,z=d.shadow?.lift??.001,I=`${o.polygons.length}|${r.size}|${P.join(",")}|${g.join(",")}|${D.join(",")}|${k?k.join(","):"n"}|${z}`,Z=x.get(o);if(Z===void 0||h.get(o)!==I){Z=(0,ze.prepareReceiverFacePlanes)(o.polygons,P,o.handle.transform.scale,r,z,g),x.set(o,Z),h.set(o,I);let A=Ns(o);for(let y of A.values())y.svg&&y.svg.parentNode&&y.svg.parentNode.removeChild(y.svg);A.clear()}let K=[];for(let A of n){let y=A.handle.transform.position??[0,0,0],m=A.handle.transform.rotation??[0,0,0],p=(0,ze.meshScaleVec3)(A.handle.transform.scale),T=A.bboxCenterCss,M=`${A.polygons.length}|${y.join(",")}|${m.join(",")}|${p.join(",")}|${T?T.join(","):"n"}`,R=b.get(A);if(R===void 0||v.get(A)!==M){let _=t.get(A),j=new Set;for(let Q of A.rendered)Q.plan&&!_.has(Q.polygonIndex)&&j.add(Q.polygonIndex);R=(0,ze.prepareCasterPolyItems)(A.polygons,y,A.handle.transform.scale,Q=>j.has(Q),m),b.set(A,R),v.set(A,M)}let L;if(A===o){let _=Fs.get(A);(_===void 0||Vs.get(A)!==A.polygons)&&(_=(0,ze.buildSharedEdgeMap)(A.polygons),Fs.set(A,_),Vs.set(A,A.polygons)),L=_}let re;if(A!==o&&A.polygons.length>=40){let _=Bs.get(A);(_===void 0||zs.get(A)!==M)&&(_=(0,ze.prepareCasterEdgeOwners)(A.polygons,y,A.handle.transform.scale,m),Bs.set(A,_),zs.set(A,M)),re=_}K.push({id:A,items:R,selfShadowEdgeMap:L,edgeOwners:re,casterPolygonCount:A.polygons.length})}let O={rotX:e.camera.state.rotX,rotY:e.camera.state.rotY,meshRotation:o.handle.transform.rotation},H=(0,ze.computeReceiverShadowFaces)({receiverPlanes:Z,receiverPolygons:o.polygons,receiverHasTexture:C,casters:K,lightDir:s,cameraRot:O,ambientLight:d.ambientLight,directionalLight:d.directionalLight,shadow:{color:d.shadow?.color,opacity:u,maxExtend:d.shadow?.maxExtend}}),V=Ns(o),$=new Set;for(let A of H){$.add(A.faceIndex);let y=V.get(A.faceIndex);y||(y={svg:null,visible:!1,width:-1,height:-1,matrixCss:""},V.set(A.faceIndex,y));let m=y.svg;m?(y.visible||(m.style.display="block"),(y.width!==A.width||y.height!==A.height)&&(m.setAttribute("width",String(A.width)),m.setAttribute("height",String(A.height)),m.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),y.width=A.width,y.height=A.height),y.matrixCss!==A.matrixCss&&(m.style.transform=A.matrixCss,y.matrixCss=A.matrixCss)):(m=e.doc.createElementNS(Ja,"svg"),m.setAttribute("class","polycss-shadow polycss-shadow-svg polycss-shadow-receiver"),d.debugShadowAttrs&&(m.setAttribute("data-poly-shadow-type","receiver"),m.setAttribute("data-poly-shadow-receiver",yr(o)),m.setAttribute("data-poly-shadow-receiver-face",String(A.faceIndex)),m.setAttribute("data-poly-shadow-receiver-polys",JSON.stringify(A.memberPolyIndices))),m.setAttribute("width",String(A.width)),m.setAttribute("height",String(A.height)),m.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),m.setAttribute("style",`position:absolute;top:0;left:0;display:block;overflow:hidden;transform-origin:0 0;pointer-events:none;will-change:transform;transform:${A.matrixCss}`),ws(e.shadowSvgState,e.doc,e.sceneEl).appendChild(m),y.svg=m,y.width=A.width,y.height=A.height,y.matrixCss=A.matrixCss),y.visible=!0;let p=_s(m,e.doc,A.paths.length,!0),T=A.opacity.toFixed(4),M=[],R=!!d.debugShadowAttrs;for(let L=0;L<A.paths.length;L++){let re=A.paths[L],_=R?yr(re.casterId):"";R&&M.push(_);let j=p[L];if(j.setAttribute("d",re.d),j.getAttribute("fill")!==A.fill&&j.setAttribute("fill",A.fill),j.getAttribute("stroke")!==A.fill&&j.setAttribute("stroke",A.fill),j.getAttribute("opacity")!==T&&j.setAttribute("opacity",T),R){j.getAttribute("data-poly-shadow-caster")!==_&&j.setAttribute("data-poly-shadow-caster",_);let Q=JSON.stringify(re.casterPolygonIndices);j.getAttribute("data-poly-shadow-caster-polys")!==Q&&j.setAttribute("data-poly-shadow-caster-polys",Q)}}if(R){let L=M.join(" ");m.getAttribute("data-poly-shadow-casters")!==L&&m.setAttribute("data-poly-shadow-casters",L)}}for(let[A,y]of V)$.has(A)||y.svg&&y.visible&&(y.svg.style.display="none",y.visible=!1)}var Us=Symbol.for("polycss.animation.triangleFrameTarget");var el=750;function Gs(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:ne.DEFAULT_SEAM_BLEED}}var tl={key:"non-cullable",normal:[1,1,0]};function js(){return[tl]}function Xn(e,n){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");if(!n?.camera)throw new Error("createPolyScene: a camera handle is required. Use createPolyCamera({...}) or createPolyPerspectiveCamera({...}) and pass as { camera }.");let t=n.camera;e.ownerDocument&&Un(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...r}=n,s=Gs({seamBleed:ne.DEFAULT_SEAM_BLEED,...r}),i=ys(e),c=[0,0,0],l=e.ownerDocument??document,u=l.createElement("div");u.className="polycss-camera",Z(u,s),e.appendChild(u);let d=l.createElement("div");d.className="polycss-scene",d.setAttribute("aria-hidden","true"),K(d,s),u.appendChild(d);let x=Rs({host:e,doc:l,cameraEl:u,sceneEl:d,camera:t,layoutScale:i,options:s}),h=x.meshes,b=new WeakMap,v=x.shadowSvgState,P=()=>Ls(v),g=()=>Is(x),C=null;function D(a){if(!a)return null;let f=Math.hypot(a[0],a[1],a[2]);if(!Number.isFinite(f)||f<=0)return null;let S=Math.round(a[0]/f*100)/100,E=Math.round(a[1]/f*100)/100,W=Math.round(a[2]/f*100)/100;return`${S}|${E}|${W}`}function k(){C=null}let z=a=>Os(x,a),I=a=>Ds(x,a);function Z(a,f){let S=t.perspectiveStyle;if(S==="none")a.style.perspective="1000000px";else{let E=parseFloat(S);Number.isFinite(E)&&(a.style.perspective=`${E}px`)}}function K(a,f){bs(a,i),a.style.transform=fr(t,c,i),Es(a,f)}function O(a){a.style.transform=fr(t,c,i)}function H(a){a.voxelRenderer?.dispose(),a.voxelRenderer=void 0,y(a.rendered,a.disposeAtlas),a.disposeAtlas=void 0,a.rendered.length=0,a.renderedByPolygonIndex=[],a.cameraCullGroups=[],a.cameraCullSignature="",a.solidLightingPreviewPrepared=!1,a.solidLightingPreviewActive=!1,A(a);for(let f of Array.from(a.wrapper.children))f instanceof HTMLElement&&f.classList.contains("polycss-bucket")&&f.remove();a.hasBuckets=!1}function V(a){for(let f of Array.from(a.wrapper.childNodes)){if(!(f instanceof HTMLElement))return f;if(f.classList.contains("polycss-bucket")||f.classList.contains("polycss-shadow"))continue;let S=f.tagName.toLowerCase();if(!(S==="b"||S==="i"||S==="s"||S==="u"||S==="q"))return f}return null}function $(a,f,S){S?.parentNode===a.wrapper?a.wrapper.insertBefore(f,S):a.wrapper.appendChild(f)}function A(a){for(let f of a.shadowRendered)f.parentNode&&f.parentNode.removeChild(f);a.shadowRendered.length=0,g()}function y(a,f){f?.();for(let S of a){try{S.dispose()}catch{}S.element.parentNode&&S.element.parentNode.removeChild(S.element)}}function m(a,f,S){a.rendered=f,a.renderedByPolygonIndex=[];for(let E of f)a.renderedByPolygonIndex[E.polygonIndex]=E;a.disposeAtlas=S,a.solidLightingPreviewPrepared=!1}function p(a,f){let S=a.renderedByPolygonIndex[f];return S?.polygonIndex===f?S:void 0}function T(a){for(let f of Array.from(a.wrapper.children))f instanceof HTMLElement&&f.classList.contains("polycss-bucket")&&f.remove();a.hasBuckets=!1;for(let f of a.rendered)f.element.parentNode&&f.element.parentNode.removeChild(f.element)}function M(a,f){let S=a.polygons[f.polygonIndex];return a.stableDom&&S?(0,ne.polygonCssSurfaceNormal)(S):f.plan?.normal??(S?(0,ne.polygonCssSurfaceNormal)(S):null)}function R(a){if(!Q(a))return a.rendered;let f=L(a);return a.rendered.filter(S=>re(a,S,ne.CAMERA_BACKFACE_CULL_EPS,f))}function L(a){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:a.handle.transform.rotation}}function re(a,f,S=ne.CAMERA_BACKFACE_CULL_EPS,E=L(a)){let W=M(a,f);return W===null||(0,ne.normalFacesCamera)(W,E,S)}function _(a){if(a.excludeFromAutoCenter){a.cameraCullGroups=[];return}let f=new Map;for(let S of a.rendered){let E=M(a,S);if(!E)continue;if(!(0,ne.isAxisAlignedSurfaceNormal)(E)){a.cameraCullGroups=js();return}let W=(0,ne.cameraCullNormalKey)(E);if(!f.has(W)&&(f.set(W,E),f.size>ne.VOXEL_CAMERA_CULL_NORMAL_LIMIT)){a.cameraCullGroups=js();return}}a.cameraCullGroups=Array.from(f,([S,E])=>({key:S,normal:E}))}function j(a){return Q(a)?(0,ne.cameraCullVisibleSignature)(a.cameraCullGroups,L(a)):"all"}function Q(a){return!a.excludeFromAutoCenter&&(0,ne.isVoxelCameraCullableNormalGroups)(a.cameraCullGroups)}function ae(a){a.cameraCullSignature=Q(a)?j(a):"all"}function xe(a,f){let S=new Array(a.rendered.length),E=!1,W=L(a);for(let J=0;J<a.rendered.length;J+=1){let ie=a.rendered[J],te=re(a,ie,f,W);S[J]=te}let B=null,F=null,G=()=>{if(!(!B||!F)){if(B===F)B.remove();else{let J=l.createRange();J.setStartBefore(B),J.setEndAfter(F),J.deleteContents(),J.detach()}B=null,F=null,E=!0}};for(let J=0;J<a.rendered.length;J+=1){let ie=a.rendered[J];!S[J]&&ie.element.parentNode===a.wrapper?(F&&F.nextSibling===ie.element||(G(),B=ie.element),F=ie.element):G()}G();let Y=J=>{for(let ie=J;ie<a.rendered.length;ie+=1){let te=a.rendered[ie].element;if(te.parentNode===a.wrapper)return te}return V(a)},ue=-1,se=J=>{if(ue<0)return;let ie=l.createDocumentFragment();for(let te=ue;te<J;te+=1){let Ge=a.rendered[te];Te(a,Ge),ie.appendChild(Ge.element)}$(a,ie,Y(J)),ue=-1,E=!0};for(let J=0;J<a.rendered.length;J+=1){let ie=a.rendered[J];S[J]&&ie.element.parentNode!==a.wrapper?ue<0&&(ue=J):se(J)}return se(a.rendered.length),E}function ge(a,f=!1){if(a.voxelRenderer){f?a.voxelRenderer.render(L(a)):a.voxelRenderer.syncCamera(L(a)),a.cameraCullSignature="voxel-direct";return}if(!Q(a)){let W=a.cameraCullSignature!=="all";a.cameraCullSignature="all",W&&Ae(a);return}if(a.hasBuckets){be(a,f);return}let S=j(a);if(!f&&S===a.cameraCullSignature)return;let E=xe(a,ne.CAMERA_BACKFACE_CULL_EPS);a.cameraCullSignature=S,E&&Je(a)}function be(a,f=!1){let S=Q(a)?j(a):"all";!f&&S===a.cameraCullSignature||Ae(a)}function Re(a,f){return M(a,f)}function Te(a,f){if(s.textureLighting!=="dynamic")return;let S=Re(a,f);S&&(f.element.style.setProperty("--pnx",S[0].toFixed(4)),f.element.style.setProperty("--pny",S[1].toFixed(4)),f.element.style.setProperty("--pnz",S[2].toFixed(4)))}function De(a){T(a),a.hasBuckets=!1;let f=a.skipBucketNormalCleanupOnce;a.skipBucketNormalCleanupOnce=!1;let S=l.createDocumentFragment(),E=s.textureLighting==="dynamic"&&!a.stableDom,W=new Map,B=[];for(let F of R(a)){let G=a.polygons[F.polygonIndex],Y=E&&G?vs(G):null;if(!Y){B.push(F);continue}let ue=Y.key+"|"+(G.color??""),se=W.get(ue);se||(se={vec:Y.vec,items:[]},W.set(ue,se)),se.items.push(F)}for(let F of B)Te(a,F),S.appendChild(F.element);for(let F of W.values()){if(F.items.length<2){for(let Y of F.items)Te(a,Y),S.appendChild(Y.element);continue}let G=l.createElement("div");G.className="polycss-bucket",a.hasBuckets=!0,G.style.setProperty("--pnx",String(F.vec[0])),G.style.setProperty("--pny",String(F.vec[1])),G.style.setProperty("--pnz",String(F.vec[2]));for(let Y of F.items)G.appendChild(Y.element),(!f||Y.kind==="triangle")&&(Y.element.style.removeProperty("--pnx"),Y.element.style.removeProperty("--pny"),Y.element.style.removeProperty("--pnz"));S.appendChild(G)}$(a,S,V(a)),ae(a)}function Ke(){return new Promise(a=>setTimeout(a,0))}async function it(a,f){if(s.textureLighting==="dynamic"&&!a.stableDom)return De(a),!f();T(a);let E=l.createDocumentFragment(),W=V(a),B=0;for(let F of R(a)){if(f())return!1;Te(a,F),E.appendChild(F.element),B++,B%el===0&&($(a,E,W),E=l.createDocumentFragment(),await Ke())}return E.childNodes.length>0&&$(a,E,W),ae(a),!f()}function wt(a,f){let S=s.textureLighting==="dynamic",E=s.directionalLight?.direction,W=f&&(f[0]!==0||f[1]!==0||f[2]!==0);if(!S||!W||!E){if(a.lightOverrideSignature==="clear")return;a.wrapper.style.removeProperty("--plx"),a.wrapper.style.removeProperty("--ply"),a.wrapper.style.removeProperty("--plz"),a.lightOverrideSignature="clear";return}let B=(0,ne.inverseRotateVec3)(E,f),F=en(B),G=Math.hypot(F[0],F[1],F[2])||1,Y=(F[0]/G).toFixed(2),ue=(F[1]/G).toFixed(2),se=(F[2]/G).toFixed(2),J=`${Y}|${ue}|${se}`;a.lightOverrideSignature!==J&&(a.wrapper.style.setProperty("--plx",Y),a.wrapper.style.setProperty("--ply",ue),a.wrapper.style.setProperty("--plz",se),a.lightOverrideSignature=J)}function Vt(a){let f=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let E=a.polygons[S.polygonIndex];E&&(f=gr(S,E,s)||f)}return a.solidLightingPreviewPrepared=!1,a.solidLightingPreviewActive=!1,f}function Mt(a){if((s.textureLighting??"baked")!=="baked")return!1;let f=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let E=a.polygons[S.polygonIndex];E&&(As(S,E,S.plan.shadedColor),f=!0)}return a.solidLightingPreviewPrepared=f,f}function ko(a){return(s.textureLighting??"baked")!=="baked"||!a.solidLightingPreviewPrepared&&!Mt(a)?!1:(a.solidLightingPreviewActive=!0,!0)}function Oo(a){return a.kind==="atlas"||!!a.plan?.texture}function Do(){if((s.textureLighting??"baked")!=="baked")return!1;let a=!1;for(let f of h)a=Vt(f)||a,f.rendered.some(Oo)&&(mn(f),a=!0);d.style.removeProperty(tn);for(let f of h)Dt(f.wrapper),f.solidLightingPreviewActive=!1;return Dt(d),a}function Io(){d.style.removeProperty(tn);for(let a of h)a.solidLightingPreviewActive&&(Vt(a),Dt(a.wrapper));(s.textureLighting??"baked")!=="dynamic"&&(Dt(d),k(),ke())}function U(a,f){let S=a.handle.transform.rotation,E=f.directionalLight?.direction??s.directionalLight?.direction;if(!(S&&(S[0]!==0||S[1]!==0||S[2]!==0))||!E){Dt(a.wrapper);return}let B=(0,ne.inverseRotateVec3)(E,S);jn(a.wrapper,{...s,...f,directionalLight:{...s.directionalLight,...f.directionalLight,direction:B}})}function le(a){if((s.textureLighting??"baked")!=="baked")return!1;jn(d,{...s,...a}),!a.skipShadows&&a.directionalLight?.direction&&ke(a.directionalLight.direction);let f=!1;for(let S of h)U(S,a),f=ko(S)||f;return f?he(d,tn,"1"):d.style.removeProperty(tn),f}function ce(a,f,S){let E=a.polygons[f];if(!E)return!1;let W=p(a,f);if(!W)return!1;let B=s.textureLighting??"baked";return B==="dynamic"?(Ts(W.element,S),!0):B==="baked"?gr(W,E,s):!1}function Ie(a,f){let S=a.polygons[f];if(!S)return!1;let E=p(a,f);return E?(Ee(E.element,S,f),!0):!1}function pn(a,f,S){return!(S.length===0||!S.every(E=>E==="color"||E==="data")||S.includes("color")&&!ce(a,f,a.polygons[f]?.color)||S.includes("data")&&!Ie(a,f))}function Je(a){k(),ke()}function ke(a){let f=[];for(let te of h)!te.disposed&&te.castShadow&&f.push(te);if(f.length===0){g(),C=null;return}let S=s.shadow?.color??"#000000",E=s.shadow?.opacity??.25,W=(0,ne.parseHexColor)(S)?.rgb??[0,0,0],B=W[0],F=W[1],G=W[2],Y=a??s.directionalLight?.direction??[.4,-.7,.59],ue=en(Y),se=D(ue);if(se!==null&&se===C)return;let J=new Map;for(let te of f)J.set(te,(0,ne.findOverlappingPolygonDuplicates)(te.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.95,preserveDoubleSidedBackfaces:!1}));let ie=new Map;for(let te of h)te.disposed||!te.receiveShadow||ie.set(te,new Set);P();for(let te of h)te.disposed||!te.receiveShadow||$s(x,f,J,te,ie.get(te)??new Set,ue,B,F,G,E);C=se}function Ae(a){if(a.voxelRenderer){a.voxelRenderer.render(L(a)),a.cameraCullSignature="voxel-direct";return}A(a),De(a),Je(a)}function $e(a,f){if(!f||!a.polygons||a.polygons.length<2)return;let S=Math.hypot(f[0],f[1],f[2]);if(!Number.isFinite(S)||S<=0)return;let E=f[0]/S,W=f[1]/S,B=f[2]/S,F=J=>Math.round(J*1e3)/1e3,G=`${F(E)},${F(W)},${F(B)}`,Y=a.lightOcclusionCache;if(Y&&Y.polygons===a.polygons&&Y.lightDirKey===G)return Y.occluded;let ue=Y&&Y.polygons===a.polygons?Y.dedupDropped:(0,ne.findOverlappingPolygonDuplicates)(a.polygons,{normalTolerance:.1,distanceTolerance:.12,overlapFraction:.98,preserveDoubleSidedBackfaces:!1}),se=(0,ne.computeLightVisibility)(a.polygons,[E,W,B],ue);return a.lightOcclusionCache={polygons:a.polygons,lightDirKey:G,occluded:se,dedupDropped:ue},se}function Ue(a){return!!a.voxelSource&&s.textureLighting!=="dynamic"&&!a.stableDom&&!a.castShadow}function _e(a,f){H(a);let S=s.directionalLight,E=f?{...S,direction:f}:S,W=Ct(E),B=void 0;if(Ue(a)){let Y=fs({doc:l,wrapper:a.wrapper,polygons:a.parseResult.polygons,directionalLight:W,ambientLight:s.ambientLight});if(Y){a.voxelRenderer=Y,Y.render(L(a)),a.cameraCullSignature="voxel-direct";return}}let F={doc:l,directionalLight:W,ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,strategies:s.strategies,lightOccludedPolyIndices:B},G=a.stableDom?(()=>{let Y=vt(a.polygons,F);return It(a.wrapper,Y),Ot(a.polygons,{...F,solidPaintDefaults:Y})??xt(a.polygons,{...F,solidPaintDefaults:Y})})():xt(a.polygons,{...F,computeSolidPaintDefaults:!0,skipDynamicNormalVars:s.textureLighting==="dynamic"});a.stableDom||It(a.wrapper,G.solidPaintDefaults??{}),m(a,G.rendered,G.dispose),a.skipBucketNormalCleanupOnce=s.textureLighting==="dynamic"&&!a.stableDom,_(a),De(a),Je(a)}function mn(a,f){if(a.rendered.length===0||a.voxelRenderer||a.stableDom||Ue(a)){_e(a,f);return}if(a.rendered[0]?.element.parentNode===null){_e(a,f);return}let S=s.directionalLight,E=f?{...S,direction:f}:S,W=Ct(E),B={doc:l,directionalLight:W,ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,strategies:s.strategies,computeSolidPaintDefaults:!0,skipDynamicNormalVars:s.textureLighting==="dynamic"},F=xt(a.polygons,B),G=()=>{a.rebakeInFlight=!1;let se=a.rebakeQueuedLightDir;se!==null&&(a.rebakeQueuedLightDir=null,mn(a,se))},Y=()=>{if(a.disposed){F.dispose(),G();return}if(F.rendered.length!==a.rendered.length){F.dispose(),_e(a,f),G();return}for(let ie of F.rendered){let te=a.renderedByPolygonIndex[ie.polygonIndex];if(!te)continue;let Ge=ie.element.getAttribute("style");Ge!==null&&te.element.setAttribute("style",Ge)}let se=F.solidPaintDefaults;se&&It(a.wrapper,se);let J=a.disposeAtlas;a.disposeAtlas=F.dispose,J&&(typeof requestAnimationFrame=="function"?te=>{requestAnimationFrame(te)}:te=>{setTimeout(te,0)})(J),Je(a),G()},ue=F.pagesReady;ue&&typeof ue.then=="function"?ue.then(()=>Fo(F.rendered)).then(Vo).then(Y,()=>{F.dispose(),a.disposed||_e(a,f),G()}):Y()}function Ho(a,f){if(a.rebakeInFlight){a.rebakeQueuedLightDir=f;return}a.rebakeInFlight=!0,mn(a,f)}function Fo(a){let f=new Set;for(let S of a){let E=S.element.getAttribute("style")??"",W=/url\((blob:[^)]+)\)/g,B;for(;(B=W.exec(E))!==null;)f.add(B[1])}return Array.from(f)}function Vo(a){return a.length===0||typeof Image>"u"?Promise.resolve():Promise.all(a.map(f=>{let S=new Image;S.src=f;let E=S.decode?.();return E?E.catch(()=>{}):Promise.resolve()})).then(()=>{})}function at(){let a=1/0,f=!1;for(let B of h)if(!B.disposed&&B.receiveShadow){f=!0;break}for(let B of h){if(B.disposed||!(f?B.receiveShadow:B.castShadow))continue;let G=B.handle.transform.position?.[2]??0;for(let Y of B.polygons)for(let ue of Y.vertices){let se=ue[2]+G;se<a&&(a=se)}}if(!Number.isFinite(a)){let B=v.currentGroundCssZ!==null;v.currentGroundCssZ=null,B&&(g(),k());return}let S=s.shadow?.lift??.05,E=(a+S)*qe,W=v.currentGroundCssZ;v.currentGroundCssZ=E,W!==E&&(k(),ke())}async function Mn(a,f){H(a);let S=Ct(s.directionalLight),E={doc:l,directionalLight:S,ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,strategies:s.strategies,lightOccludedPolyIndices:void 0},W=a.stableDom?Ot(a.polygons,E):null;if(W){let G=vt(a.polygons,E);return It(a.wrapper,G),m(a,W.rendered,W.dispose),_(a),De(a),Je(a),!f()}let B=await Qt(a.polygons,{...E,skipDynamicNormalVars:s.textureLighting==="dynamic"},f);if(f())return B.dispose(),!1;It(a.wrapper,B.solidPaintDefaults),m(a,B.rendered,B.dispose),a.skipBucketNormalCleanupOnce=s.textureLighting==="dynamic"&&!a.stableDom,_(a);let F=await it(a,f);return F&&Je(a),F}function Lt(){let a=c,f=[0,0,0];if(s.autoCenter){let S=[];for(let E of h)!E.disposed&&!E.excludeFromAutoCenter&&S.push(...E.polygons);if(S.length>0){let E=(0,ne.computeSceneBbox)(S);f=[(E.min[0]+E.max[0])/2,(E.min[1]+E.max[1])/2,(E.min[2]+E.max[2])/2]}}a[0]===f[0]&&a[1]===f[1]&&a[2]===f[2]||(c=f,x.autoCenter.offset=f,K(d,s))}function ki(a,f={}){let E=(d.ownerDocument??document).createElement("div");E.className="polycss-mesh",f.id&&E.setAttribute("data-poly-mesh-id",f.id);let W=`polycss-mesh-${x.meshAutoCounter.next++}`;E.setAttribute("data-poly-mesh-index",W);let B={...f},F=f.merge!==!1,G=!!f.stableDom,Y=0,ue=Gn(B);ue&&(E.style.transform=ue);let se=(N,X)=>a.voxelSource?N:X?(0,ne.optimizeMeshPolygons)(N,{meshResolution:f.meshResolution}):(G||f.excludeFromAutoCenter,N),J=se(a.polygons,F),ie=null;function te(){let N=Gn(B);E.style.transform=N??""}function Ge(N){if(N.length===0){ie=null,et&&(et.bboxCenterCss=null),te();return}let X=1/0,me=1/0,ve=1/0,Fe=-1/0,fe=-1/0,Ce=-1/0;for(let ot of N)for(let We of ot.vertices)We[0]<X&&(X=We[0]),We[0]>Fe&&(Fe=We[0]),We[1]<me&&(me=We[1]),We[1]>fe&&(fe=We[1]),We[2]<ve&&(ve=We[2]),We[2]>Ce&&(Ce=We[2]);if(!Number.isFinite(X)){ie=null,et&&(et.bboxCenterCss=null),te();return}let je=(me+fe)/2*qe,nt=(X+Fe)/2*qe,Ve=(ve+Ce)/2*qe;ie=[je,nt,Ve],et&&(et.bboxCenterCss=ie),te()}let et=null;Ge(J),d.appendChild(E);let w={handle:void 0,wrapper:E,parseResult:a,rendered:[],renderedByPolygonIndex:[],shadowRendered:[],polygons:J,voxelSource:a.voxelSource,disposed:!1,stableDom:G,hasBuckets:!1,skipBucketNormalCleanupOnce:!1,excludeFromAutoCenter:!!f.excludeFromAutoCenter,castShadow:!!f.castShadow,bboxCenterCss:ie,receiveShadow:!!f.receiveShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",stableTriangleColorFrame:0,solidLightingPreviewPrepared:!1,solidLightingPreviewActive:!1,bakedRotation:f.rotation?[...f.rotation]:[0,0,0],autoMeshId:W,rebakeInFlight:!1,rebakeQueuedLightDir:null},tt=null,Bo=0,Ln=-1,fn=null;function hn(){tt=null,fn=null,Ln=-1}function kr(){let N=tt;if(!N||N.polygonCount!==w.polygons.length)return w.polygons;if(fn&&Ln===Bo)return fn;let X=N.vertices,me=new Array(N.polygonCount);for(let ve=0;ve<N.polygonCount;ve++){let Fe=w.polygons[ve],fe=ve*9;me[ve]={...Fe,color:N.colors?.[ve]??Fe.color,vertices:[[X[fe],X[fe+1],X[fe+2]],[X[fe+3],X[fe+4],X[fe+5]],[X[fe+6],X[fe+7],X[fe+8]]]}}return fn=me,Ln=Bo,me}function Or(N,X){let me=N?.stableTriangleUpdateMode==="color-only";w.stableTriangleColorFrame++;let ve=w.stableDom&&!X;if(ve||Ge(w.polygons),w.stableDom&&!w.hasBuckets){let Fe={doc:l,directionalLight:Ct(s.directionalLight),ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed},fe=w.rendered.length===w.polygons.length&&w.rendered.every(Ve=>Ve.kind==="triangle"),Ce=w.stableDom&&!X,je=fe||Ce?{}:vt(w.polygons,Fe);fe||It(w.wrapper,je);let nt={...Fe,solidPaintDefaults:je,optimizeStableTriangleStyle:!0,stableTriangleDebug:N?.stableTriangleDebug,stableTriangleUpdateMode:N?.stableTriangleUpdateMode,stableTriangleColorPolicy:N?.stableTriangleColorPolicy,stableTriangleColorSteps:N?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:N?.stableTriangleColorFreezeFrames,stableTriangleColorBudget:N?.stableTriangleColorBudget,stableTriangleColorMaxAge:N?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:N?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:N?.stableTriangleMatrixDecimals,stableTriangleColorFrame:w.stableTriangleColorFrame};if(Jt(w.rendered,w.polygons,nt))return me||(_(w),ge(w,!0),X&&Lt()),!0}return ve&&Ge(w.polygons),!1}let Bt={get polygons(){return kr()},set polygons(N){hn(),w.polygons=N},element:E,id:f.id,get transform(){return B},remove(){Y++,E.parentNode&&E.parentNode.removeChild(E),H(w),h.delete(w),b.delete(E),z(w),I(w),Lt(),at()},setPolygons(N,X){Y++,F=X?.merge??F,G=X?.stableDom??G,w.stableDom=G,w.voxelSource=void 0,w.polygons=se(N,F),I(w),z(w),hn(),Bt.polygons=w.polygons;let me=X?.recomputeAutoCenter??!0;Or(X,me)||(_e(w),me&&Lt())},[Us](N,X){let me=X?.merge??F,ve=X?.stableDom??G;if(!N.solidTriangles||!ve||me||f.meshResolution!==void 0||w.hasBuckets||N.polygonCount!==w.polygons.length||N.vertices.length<N.polygonCount*9||w.rendered.length!==N.polygonCount)return!1;for(let Ce=0;Ce<w.rendered.length;Ce++){let je=w.rendered[Ce],nt=w.polygons[Ce];if(je?.kind!=="triangle"||je.polygonIndex!==Ce||!nt||nt.vertices.length!==3||nt.texture||nt.material?.texture)return!1}let Fe=X?.recomputeAutoCenter??!0;if(!Fe){let Ce=w.stableTriangleColorFrame+1,je={doc:l,directionalLight:Ct(s.directionalLight),ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,solidPaintDefaults:{},optimizeStableTriangleStyle:!0,stableTriangleDebug:X?.stableTriangleDebug,stableTriangleUpdateMode:X?.stableTriangleUpdateMode,stableTriangleColorPolicy:X?.stableTriangleColorPolicy,stableTriangleColorSteps:X?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:X?.stableTriangleColorFreezeFrames??0,stableTriangleColorBudget:X?.stableTriangleColorBudget,stableTriangleColorMaxAge:X?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:X?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:X?.stableTriangleMatrixDecimals,stableTriangleColorFrame:Ce};if(Kt(w.rendered,w.polygons,N,je))return Y++,F=me,G=ve,w.stableDom=G,w.voxelSource=void 0,w.stableTriangleColorFrame=Ce,tt=N,Bo++,fn=null,Ln=-1,Q(w)?(_(w),ge(w,!0)):ae(w),!0}Y++,F=me,G=ve,w.stableDom=G,w.voxelSource=void 0;let fe=N.vertices;for(let Ce=0;Ce<N.polygonCount;Ce++){let je=w.polygons[Ce],nt=N.colors?.[Ce];nt&&(je.color=nt);let Ve=je.vertices,ot=Ce*9;Ve[0][0]=fe[ot],Ve[0][1]=fe[ot+1],Ve[0][2]=fe[ot+2],Ve[1][0]=fe[ot+3],Ve[1][1]=fe[ot+4],Ve[1][2]=fe[ot+5],Ve[2][0]=fe[ot+6],Ve[2][1]=fe[ot+7],Ve[2][2]=fe[ot+8]}return hn(),Bt.polygons=w.polygons,Or(X,Fe)},updatePolygon(N,X){let me=typeof N=="number"?N:w.polygons.indexOf(N);if(me<0&&typeof N!="number"&&tt&&(me=kr().indexOf(N)),me<0||me>=w.polygons.length)return;hn(),w.voxelSource=void 0,Object.assign(w.polygons[me],X);let ve=Object.keys(X);pn(w,me,ve)||_e(w)},async setPolygonsChunked(N,X){let me=++Y;F=X?.merge??F,G=X?.stableDom??G,w.stableDom=G,w.voxelSource=void 0,w.polygons=se(N,F),hn(),Bt.polygons=w.polygons,Ge(w.polygons);let ve=X?.recomputeAutoCenter??!0;if(!await Mn(w,()=>w.disposed||me!==Y)){H(w);return}ve&&Lt()},setTransform(N){let X=w.castShadow,me=w.receiveShadow;N.castShadow!==void 0&&(w.castShadow=!!N.castShadow),N.receiveShadow!==void 0&&(w.receiveShadow=!!N.receiveShadow),B={...B,...N};let ve=Gn(B);E.style.transform=ve??"",wt(w,B.rotation),N.rotation!==void 0&&ge(w,!0),w.castShadow!==X&&(w.voxelSource&&_e(w),Je(w),at()),w.receiveShadow!==me&&(w.receiveShadow||br(w),k(),ke()),(N.position!==void 0||N.scale!==void 0)&&(w.castShadow||w.receiveShadow)&&(at(),k(),ke())},dispose(){if(!w.disposed){w.disposed=!0,Y++,E.parentNode&&E.parentNode.removeChild(E),H(w);try{a.dispose()}catch{}h.delete(w),b.delete(E),Lt(),at()}},rebakeAtlas(){w.bakedRotation=B.rotation?[...B.rotation]:[0,0,0];let N=s.directionalLight?.direction??[.4,-.7,.59],X=(0,ne.inverseRotateVec3)(N,w.bakedRotation);Ho(w,X)},getPosition(){return B.position},getRotation(){return B.rotation},getScale(){return B.scale},getPolygons(){return Bt.polygons}};return w.handle=Bt,et=w,b.set(E,w),h.add(w),_e(w),wt(w,B.rotation),Lt(),at(),w.receiveShadow&&(k(),ke()),Bt}function Oi(a){let f=!!s.autoCenter,S=s.strategies,E=s.seamBleed,W=s.textureLighting,B=s.directionalLight?.direction,F=s.shadow,G=Gs(a);s={...s,...G},x.options.current=s,K(d,s);let Y=!!s.autoCenter;for(let tt of h)wt(tt,tt.handle.transform.rotation);let ue=a.strategies!==void 0&&!xs(a.strategies,S),se=Object.prototype.hasOwnProperty.call(a,"seamBleed")&&G.seamBleed!==E;if(ue||se)for(let tt of h)_e(tt);f!==Y&&Lt();let J=a.textureLighting!==void 0&&W!==s.textureLighting,ie=s.directionalLight?.direction,te=a.directionalLight!==void 0&&!Ps(B,ie),Ge=s.shadow,et=a.shadow!==void 0&&!Ss(F,Ge),w=te||et;if(J){if(!ue&&!se)for(let tt of h)_e(tt);at(),k(),ke()}else w&&(et&&k(),ke());et&&a.shadow?.lift!==F?.lift&&at()}function Di(){return s}function Ii(){O(d);for(let a of h)ge(a)}function Hi(){let a=[];for(let f of h)a.push(f.handle);return a}function Fi(a){let f=a;for(;f;){if(f instanceof HTMLElement){let S=b.get(f);if(S&&!S.disposed)return S.handle;if(f.classList.contains("polycss-mesh"))return null}f=f.parentElement}return null}function Vi(){let a=Array.from(h);for(let f of a)try{f.handle.dispose()}catch{}u.parentNode&&u.parentNode.removeChild(u)}return{add:ki,setOptions:Oi,destroy:Vi,host:e,camera:t,cameraEl:u,applyCamera:Ii,getOptions:Di,meshes:Hi,findMeshByElement:Fi,previewBakedSolidLighting:le,commitBakedSolidLighting:Do,clearBakedSolidLightingPreview:Io}}var vr=require("@layoutit/polycss-core"),nl=32e3;function Ht(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,vr.createIsometricCamera)(n),o=`${e.perspective??nl}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function Tt(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,vr.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var Ws=Tt;var Ys=require("@layoutit/polycss-core");var Zn={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function nn(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 En(e){return e===!0?-1:e===!1?1:e}function on(){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 u of l)try{u(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 u={type:i,camera:c()},d=l.slice();for(let x of d)try{x(u)}catch(h){console.error(`[polycss] controls '${i}' listener threw:`,h)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function rn(e){return()=>{let n=e.camera.state,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 qn(e,n,t,o,r,s){let i=!1,c=null;return{onWheel:d=>{let x=n();if(!x.wheel||t())return;d.preventDefault();let h=d.deltaMode===1?16:d.deltaMode===2?100:1,b=d.deltaY*h;d.ctrlKey?b*=10:b*=3;let v=e.camera.state;if(x.dolly){let P=v.distance??0,g=Math.max(x.minDistance,Math.min(x.maxDistance,P+b*.05));e.camera.update({distance:g})}else{let P=Math.exp(-b*513e-6),g=v.zoom??1,C=Math.max(x.minZoom,Math.min(x.maxZoom,g*P));e.camera.update({zoom:C})}e.applyCamera(),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 Qn(e,n,t,o,r,s,i){let c=null,l=0,u=b=>{if(c===null||o())return;let v=t();if(!v.animate){c=null;return}if(r())l=b;else{let P=Math.min(50,l?b-l:16.67);l=b;let g=v.animate.speed*(P/16.67),C=n.camera.state;if(v.animate.axis==="x"){let D=(((C.rotX??65)+g)%360+360)%360;n.camera.update({rotX:D})}else{let D=(((C.rotY??45)+g)%360+360)%360;n.camera.update({rotY:D})}n.applyCamera(),i(s)}c=e.requestAnimationFrame(u)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(u))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function Kn(e,n={}){let t=nn(Zn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,u=on(),d=rn(e),{changeListeners:x,startListeners:h,endListeners:b,listenerArray:v,emitChange:P,emitInteraction:g}=u,C=Qn(r,e,()=>t,()=>l,()=>c,d,P),D=p=>{if(!(!t.drag||l)&&s===null&&p.isPrimary!==!1){p.preventDefault(),s=p.pointerId,i={x:p.clientX,y:p.clientY},o.style.cursor="grabbing";try{p.target.setPointerCapture(p.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),g("start",d)}},k=p=>{if(s===null||p.pointerId!==s||!t.drag||l)return;p.preventDefault();let T=p.clientX-i.x,M=p.clientY-i.y;i={x:p.clientX,y:p.clientY};let R=En(t.invert),L=T/4*R,re=M/4*R,_=e.camera.state;if(p.shiftKey){let j=_.rotX??65,Q=_.rotY??45,ae=Math.max(.01,_.zoom??1),xe=Math.cos(j*Math.PI/180),ge=xe>=0?Math.max(.1,xe):Math.min(-.1,xe),be=Math.cos(Q*Math.PI/180),Re=Math.sin(Q*Math.PI/180),Te=ae*Ys.BASE_TILE,De=(T*Re-M*be/ge)/Te,Ke=-(T*be+M*Re/ge)/Te,it=_.target??[0,0,0];e.camera.update({target:[it[0]+De,it[1]+Ke,it[2]]})}else{let j=Math.max(0,Math.min(89,(_.rotX??65)-re)),Q=(((_.rotY??45)-L)%360+360)%360;e.camera.update({rotX:j,rotY:Q})}e.applyCamera(),P(d)},z=p=>{if(s===p.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{p.target.releasePointerCapture(p.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),g("end",d)}},I=qn(e,()=>t,()=>l,d,P,g);function Z(){o.addEventListener("pointerdown",D),o.addEventListener("pointermove",k),o.addEventListener("pointerup",z),o.addEventListener("pointercancel",z),o.addEventListener("wheel",I.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function K(){o.removeEventListener("pointerdown",D),o.removeEventListener("pointermove",k),o.removeEventListener("pointerup",z),o.removeEventListener("pointercancel",z),o.removeEventListener("wheel",I.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",I.teardown()}Z(),C.start();function O(p){let T=!!t.animate;t=nn(t,p),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let M=!!t.animate;T&&!M?C.stop():!T&&M&&C.start()}function H(){l&&(l=!1,Z(),C.start())}function V(){l||(l=!0,K(),C.stop(),s=null,c=!1,I.teardown())}function $(){V(),x.length=0,h.length=0,b.length=0}function A(p,T){let M=v(p);M.includes(T)||M.push(T)}function y(p,T){let M=v(p),R=M.indexOf(T);R>=0&&M.splice(R,1)}function m(p,T){return v(p).includes(T)}return{update:O,resume:H,pause:V,destroy:$,addEventListener:A,removeEventListener:y,hasEventListener:m}}var Xs=require("@layoutit/polycss-core");function Jn(e,n={}){let t=nn(Zn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,u=!1,d={x:0,y:0},x=on(),h=rn(e),{changeListeners:b,startListeners:v,endListeners:P,listenerArray:g,emitChange:C,emitInteraction:D}=x,k=Qn(r,e,()=>t,()=>l,()=>c,h,C),z=_=>{if(!(!t.drag||l)&&s===null&&_.isPrimary!==!1){_.preventDefault(),s=_.pointerId,i={x:_.clientX,y:_.clientY},o.style.cursor="grabbing";try{_.target.setPointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),D("start",h)}},I=_=>{if(s===null||_.pointerId!==s||!t.drag||l)return;_.preventDefault();let j=_.clientX-i.x,Q=_.clientY-i.y;i={x:_.clientX,y:_.clientY};let ae=e.camera.state;if(_.shiftKey){let xe=En(t.invert),ge=j/4*xe,be=Q/4*xe,Re=(ae.rotX??65)-be,Te=(((ae.rotY??45)-ge)%360+360)%360;e.camera.update({rotX:Re,rotY:Te})}else{let xe=ae.rotX??65,ge=ae.rotY??45,be=Math.max(.01,ae.zoom??1),Re=Math.cos(xe*Math.PI/180),Te=Re>=0?Math.max(.1,Re):Math.min(-.1,Re),De=Math.cos(ge*Math.PI/180),Ke=Math.sin(ge*Math.PI/180),it=be*Xs.BASE_TILE,wt=(j*Ke-Q*De/Te)/it,Vt=-(j*De+Q*Ke/Te)/it,Mt=ae.target??[0,0,0];e.camera.update({target:[Mt[0]+wt,Mt[1]+Vt,Mt[2]]})}e.applyCamera(),C(h)},Z=_=>{if(s===_.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{_.target.releasePointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),D("end",h)}},K=_=>{_.preventDefault()},O=_=>{_.button===2&&(u=!0,d={x:_.clientX,y:_.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),D("start",h))},H=_=>{if(!u||!t.drag)return;let j=_.clientX-d.x,Q=_.clientY-d.y;d={x:_.clientX,y:_.clientY};let ae=En(t.invert),xe=j/4*ae,ge=Q/4*ae,be=e.camera.state,Re=(be.rotX??65)-ge,Te=(((be.rotY??45)-xe)%360+360)%360;e.camera.update({rotX:Re,rotY:Te}),e.applyCamera(),C(h)},V=_=>{_.button===2&&u&&(u=!1,D("end",h))},$=qn(e,()=>t,()=>l,h,C,D);function A(){o.addEventListener("pointerdown",z),o.addEventListener("pointermove",I),o.addEventListener("pointerup",Z),o.addEventListener("pointercancel",Z),o.addEventListener("wheel",$.onWheel,{passive:!1}),o.addEventListener("contextmenu",K),o.addEventListener("mousedown",O),o.addEventListener("mousemove",H),o.addEventListener("mouseup",V),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function y(){o.removeEventListener("pointerdown",z),o.removeEventListener("pointermove",I),o.removeEventListener("pointerup",Z),o.removeEventListener("pointercancel",Z),o.removeEventListener("wheel",$.onWheel),o.removeEventListener("contextmenu",K),o.removeEventListener("mousedown",O),o.removeEventListener("mousemove",H),o.removeEventListener("mouseup",V),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",$.teardown()}A(),k.start();function m(_){let j=!!t.animate;t=nn(t,_),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let Q=!!t.animate;j&&!Q?k.stop():!j&&Q&&k.start()}function p(){l&&(l=!1,A(),k.start())}function T(){l||(l=!0,y(),k.stop(),s=null,c=!1,u=!1,$.teardown())}function M(){T(),b.length=0,v.length=0,P.length=0}function R(_,j){let Q=g(_);Q.includes(j)||Q.push(j)}function L(_,j){let Q=g(_),ae=Q.indexOf(j);ae>=0&&Q.splice(ae,1)}function re(_,j){return g(_).includes(j)}return{update:m,resume:p,pause:T,destroy:M,addEventListener:R,removeEventListener:L,hasEventListener:re}}var ti=require("@layoutit/polycss-core");var ol={enabled:!0,lookEnabled:!0,moveEnabled:!0,jumpEnabled:!0,crouchEnabled:!0,lookSensitivity:.15,invertY:!1,moveSpeed:5,jumpVelocity:7,gravity:18,eyeHeight:1.7,crouchHeight:1,groundZ:0,minPitch:5,maxPitch:175};function Zs(e,n){return{enabled:n.enabled??e.enabled,lookEnabled:n.lookEnabled??e.lookEnabled,moveEnabled:n.moveEnabled??e.moveEnabled,jumpEnabled:n.jumpEnabled??e.jumpEnabled,crouchEnabled:n.crouchEnabled??e.crouchEnabled,lookSensitivity:n.lookSensitivity??e.lookSensitivity,invertY:n.invertY??e.invertY,moveSpeed:n.moveSpeed??e.moveSpeed,jumpVelocity:n.jumpVelocity??e.jumpVelocity,gravity:n.gravity??e.gravity,eyeHeight:n.eyeHeight??e.eyeHeight,crouchHeight:n.crouchHeight??e.crouchHeight,groundZ:n.groundZ??e.groundZ,minPitch:n.minPitch??e.minPitch,maxPitch:n.maxPitch??e.maxPitch}}var qs=new Set(["KeyW","ArrowUp"]),Qs=new Set(["KeyS","ArrowDown"]),Ks=new Set(["KeyA","ArrowLeft"]),Js=new Set(["KeyD","ArrowRight"]),ei=new Set(["Space"]),xr=new Set(["ControlLeft","ControlRight"]);function eo(e,n={}){let t=Zs(ol,n),o=e.host,r=e.cameraEl,s=o.ownerDocument??document,i=s.defaultView??globalThis,c=on(),l=rn(e),{changeListeners:u,startListeners:d,endListeners:x,listenerArray:h,emitChange:b,emitInteraction:v}=c,P=new Set,g=!1,C=!1,D=0,k=0,z=!1,I=[0,0,t.groundZ+t.eyeHeight];function Z(U,le){let ce=U*Math.PI/180,Ie=le*Math.PI/180;return[-Math.sin(ce)*Math.cos(Ie),-Math.sin(ce)*Math.sin(Ie),-Math.cos(ce)]}function K(){let U=e.camera.perspectiveStyle,le=U==="none"?0:parseFloat(U);return(Number.isFinite(le)&&le>0?le:2e3)/ti.BASE_TILE}function O(){let U=e.camera.state,le=Z(U.rotX??90,U.rotY??0),ce=K();return[I[0]+le[0]*ce,I[1]+le[1]*ce,I[2]+le[2]*ce]}function H(){let U=O();e.camera.update({target:U}),e.applyCamera()}function V(){let U=e.camera.state.target??[0,0,0];I=[U[0],U[1],t.groundZ+t.eyeHeight],H()}let $=()=>{if(!(!t.enabled||!t.lookEnabled||C||g))try{o.requestPointerLock()}catch{}},A=()=>{let U=s.pointerLockElement===o;U!==g&&(g=U,g?(z=!0,v("start",l)):z&&(z=!1,v("end",l)))},y=U=>{if(!g||!t.enabled||!t.lookEnabled||C)return;let le=U.movementX??0,ce=U.movementY??0;if(le===0&&ce===0)return;let Ie=e.camera.state,pn=t.lookSensitivity,Je=t.invertY?-1:1,ke=(((Ie.rotY??0)-le*pn)%360+360)%360,Ae=(Ie.rotX??90)-ce*pn*Je;Ae<t.minPitch?Ae=t.minPitch:Ae>t.maxPitch&&(Ae=t.maxPitch);let $e=Z(Ae,ke),Ue=K(),_e=[I[0]+$e[0]*Ue,I[1]+$e[1]*Ue,I[2]+$e[2]*Ue];e.camera.update({rotX:Ae,rotY:ke,target:_e}),e.applyCamera(),b(l)},m=U=>qs.has(U)||Qs.has(U)||Ks.has(U)||Js.has(U)||ei.has(U)||xr.has(U),p=U=>{if(!(!t.enabled||C)&&m(U.code)&&!(!g&&!t.moveEnabled)){if(ei.has(U.code)){if(!t.jumpEnabled)return;U.preventDefault(),!P.has(U.code)&&D===0&&k===0&&(D=t.jumpVelocity),P.add(U.code);return}xr.has(U.code)&&!t.crouchEnabled||!t.moveEnabled&&!xr.has(U.code)||(U.preventDefault(),P.add(U.code))}},T=U=>{m(U.code)&&P.delete(U.code)},M=()=>{P.clear()},R=null,L=0,re=.05,_=U=>{if(R===null||C)return;let le=Math.min(re,L?(U-L)/1e3:.0167);if(L=U,t.enabled){let ce=!1,Ie=e.camera.state;if(t.moveEnabled){let Ae=0,$e=0;for(let Ue of P)qs.has(Ue)?Ae+=1:Qs.has(Ue)?Ae-=1:Js.has(Ue)?$e+=1:Ks.has(Ue)&&($e-=1);if(Ae!==0||$e!==0){let _e=(Ie.rotY??0)*Math.PI/180,mn=-Math.cos(_e),Ho=-Math.sin(_e),Fo=-Math.sin(_e),Vo=Math.cos(_e),at=Math.hypot(Ae,$e)||1,Mn=t.moveSpeed*le;I[0]+=(mn*Ae+Fo*$e)/at*Mn,I[1]+=(Ho*Ae+Vo*$e)/at*Mn,ce=!0}}let Je=t.crouchEnabled&&(P.has("ControlLeft")||P.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(D!==0||k>0)?(D-=t.gravity*le,k+=D*le,k<=0&&(k=0,D=0)):t.jumpEnabled||(k=0,D=0);let ke=t.groundZ+Je+k;if(Math.abs(I[2]-ke)>1e-4&&(I[2]=ke,ce=!0),ce){let Ae=O();e.camera.update({target:Ae}),e.applyCamera(),b(l)}}R=i.requestAnimationFrame(_)};function j(){R!==null||C||(L=0,R=i.requestAnimationFrame(_))}function Q(){R!==null&&(i.cancelAnimationFrame(R),R=null)}function ae(){let le=r.ownerDocument?.defaultView?.getComputedStyle(r).perspective??"",ce=parseFloat(le),Ie=Number.isFinite(ce)&&ce>0?ce:2e3;r.style.setProperty("--polycss-fpv-perspective",`${Ie}px`),r.classList.add("polycss-fpv-host")}function xe(){r.classList.remove("polycss-fpv-host"),r.style.removeProperty("--polycss-fpv-perspective")}function ge(){o.addEventListener("click",$),s.addEventListener("pointerlockchange",A),s.addEventListener("mousemove",y),i.addEventListener("keydown",p),i.addEventListener("keyup",T),i.addEventListener("blur",M),o.style.cursor=t.lookEnabled?"crosshair":"",ae()}function be(){if(o.removeEventListener("click",$),s.removeEventListener("pointerlockchange",A),s.removeEventListener("mousemove",y),i.removeEventListener("keydown",p),i.removeEventListener("keyup",T),i.removeEventListener("blur",M),o.style.cursor="",P.clear(),g)try{s.exitPointerLock()}catch{}xe()}V(),ge(),j();function Re(U){let le=t.eyeHeight,ce=t.groundZ;t=Zs(t,U),C||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==le||t.groundZ!==ce)&&(I[2]=t.groundZ+t.eyeHeight,H(),b(l))}function Te(){C&&(C=!1,ge(),j())}function De(){C||(C=!0,be(),Q(),z&&(z=!1,v("end",l)))}function Ke(){De(),u.length=0,d.length=0,x.length=0}function it(){if(!(!t.enabled||!t.lookEnabled||C))try{o.requestPointerLock()}catch{}}function wt(){if(g)try{s.exitPointerLock()}catch{}}function Vt(){return g}function Mt(U,le){let ce=h(U);ce.includes(le)||ce.push(le)}function ko(U,le){let ce=h(U),Ie=ce.indexOf(le);Ie>=0&&ce.splice(Ie,1)}function Oo(U,le){return h(U).includes(le)}function Do(){return[I[0],I[1],I[2]]}function Io(U){I[0]=U[0],I[1]=U[1],I[2]=U[2],H(),b(l)}return{update:Re,resume:Te,pause:De,destroy:Ke,lock:it,unlock:wt,isLocked:Vt,getOrigin:Do,setOrigin:Io,addEventListener:Mt,removeEventListener:ko,hasEventListener:Oo}}function sn(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 ni(e,n,t,o){for(let r of e)if(!(o&&!o(r))&&sn(r.element,n,t))return r;return null}function to(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let P of o)try{P(t)}catch(g){console.error("[polycss/createSelect] onChange threw:",g)}}function s(v){t=v,r()}function i(v){n.multiple?t.includes(v)||(t=[...t,v]):t=[v],r()}function c(v){t.includes(v)&&(t=t.filter(P=>P!==v),r())}function l(v){t.includes(v)?t=t.filter(P=>P!==v):n.multiple?t=[...t,v]:t=[v],r()}function u(){t.length!==0&&(t=[],r())}function d(v){return t.includes(v)}function x(v,P){return ni(e.meshes(),v,P,g=>!g.element.classList.contains("polycss-transform-gizmo"))}let h=v=>{let P=v.target;if(P?.closest(".polycss-transform-gizmo"))return;let g=e.findMeshByElement(P)??x(v.clientX,v.clientY);if(!g){n.onPointerMissed&&n.onPointerMissed(v),n.clearOnMiss!==!1&&u();return}n.multiple&&(v.shiftKey||v.metaKey||v.ctrlKey)?l(g):t.length===1&&t[0]===g?u():s([g])};e.host.addEventListener("click",h);function b(){e.host.removeEventListener("click",h),o.clear()}return{get selected(){return t},set:s,add:i,remove:c,toggle:l,clear:u,has:d,destroy:b}}var Le=require("@layoutit/polycss-core");var no="#ff3653",oo="#8adb00",ro="#2c8fff",an=50,oi=60,rl=.6,sl=.0125,il=.15,al=.04,ll=1,ri=.02,Pr=1.04,cl=.1,ul=.25,li=1e-4,dl=.6,pl=.8,ml=1,mt={0:1,1:0,2:2},si=[{cssAxis:0,sign:1,key:"x",color:no},{cssAxis:0,sign:-1,key:"-x",color:no},{cssAxis:1,sign:1,key:"y",color:oo},{cssAxis:1,sign:-1,key:"-y",color:oo},{cssAxis:2,sign:1,key:"z",color:ro},{cssAxis:2,sign:-1,key:"-z",color:ro}],ii=[{cssAxis:0,key:"x",color:no},{cssAxis:1,key:"y",color:oo},{cssAxis:2,key:"z",color:ro}],ai=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:ro},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:oo},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:no}];function Sr(e,n,t,o){let r=t*Math.PI/180,s=o*Math.PI/180,i=[0,0,0];i[e]=n;let c=i[0]*Math.cos(s)-i[1]*Math.sin(s),l=i[0]*Math.sin(s)+i[1]*Math.cos(s),u=i[2];return l*Math.sin(r)+u*Math.cos(r)<0}function fl(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 so(e,n){return!n||n<=0?e:Math.round(e/n)*n}function hl(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)?[(n+r)/2,(t+s)/2,(o+i)/2]:[0,0,0]}function Cr(e){if(e.length===0)return oi;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 u of l.vertices)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*an*rl:oi}function gl(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:c,translationSnap:l,onAxisDelta:u,onMouseDown:d,onMouseUp:x,onDraggingChanged:h}=e,b=o,v=[0,0,0];v[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(${v[0]*b}px, ${v[1]*b}px, ${v[2]*b}px)`,r.appendChild(P);let g=r.getBoundingClientRect(),C=P.getBoundingClientRect();r.removeChild(P);let D=(C.left-g.left)/b,k=(C.top-g.top)/b,z=D*D+k*k;if(z<li)return;d?.(),h?.(!0);let I=K=>{let O=K.clientX-i,H=K.clientY-c,V=(O*D+H*k)/z;V=so(V,l),u(V,v)},Z=()=>{window.removeEventListener("pointermove",I),window.removeEventListener("pointerup",Z),window.removeEventListener("pointercancel",Z);let K=O=>{O.stopPropagation(),O.stopImmediatePropagation()};window.addEventListener("click",K,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",K,!0),0),x?.(),h?.(!1)};window.addEventListener("pointermove",I),window.addEventListener("pointerup",Z),window.addEventListener("pointercancel",Z)}function yl(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:s,startClientY:i,translationSnap:c,onPlaneDelta:l,onMouseDown:u,onMouseUp:d,onDraggingChanged:x}=e,h=[0,0,0];h[n]=1;let b=[0,0,0];b[t]=1;function v(z){let I=r.ownerDocument.createElement("div");I.style.position="absolute",I.style.left="0",I.style.top="0",I.style.width="0",I.style.height="0",I.style.transform=`translate3d(${z[0]*o}px, ${z[1]*o}px, ${z[2]*o}px)`,r.appendChild(I);let Z=r.getBoundingClientRect(),K=I.getBoundingClientRect();return r.removeChild(I),{x:(K.left-Z.left)/o,y:(K.top-Z.top)/o}}let P=v(h),g=v(b),C=P.x*g.y-g.x*P.y;if(Math.abs(C)<li)return;u?.(),x?.(!0);let D=z=>{let I=z.clientX-s,Z=z.clientY-i,K=(g.y*I-g.x*Z)/C,O=(-P.y*I+P.x*Z)/C;K=so(K,c),O=so(O,c),l(K,O,h,b)},k=()=>{window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k);let z=I=>{I.stopPropagation(),I.stopImmediatePropagation()};window.addEventListener("click",z,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",z,!0),0),d?.(),x?.(!1)};window.addEventListener("pointermove",D),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)}function bl(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:c,onMouseDown:l,onMouseUp:u,onDraggingChanged:d}=e,x=t.getBoundingClientRect(),h=x.left,b=x.top,v=Math.atan2(s-b,r-h),P=0;l?.(),d?.(!0);let g=D=>{let k=Math.atan2(D.clientY-b,D.clientX-h),z=k-v;z>Math.PI?z-=2*Math.PI:z<-Math.PI&&(z+=2*Math.PI),P+=z,v=k;let I=P*180/Math.PI;I=so(I,i),c(I)},C=()=>{window.removeEventListener("pointermove",g),window.removeEventListener("pointerup",C),window.removeEventListener("pointercancel",C);let D=k=>{k.stopPropagation(),k.stopImmediatePropagation()};window.addEventListener("click",D,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",D,!0),0),u?.(),d?.(!1)};window.addEventListener("pointermove",g),window.addEventListener("pointerup",C),window.addEventListener("pointercancel",C)}function io(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,c=null,l=null,u=[0,0,0];function d(){if(!t)return[0,0,0];let y=t.transform.position??[0,0,0],m=t.transform.rotation??[0,0,0],p=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,T=(0,Le.rotateVec3)(u,m[0],m[1],m[2]);return[y[0]+p*T[0],y[1]+p*T[1],y[2]+p*T[2]]}function x(y){return l===y?ml:c===y?pl:dl}function h(){for(let[y,m]of i){let p=b(m.spec,x(y));m.handle.setPolygons(p,{recomputeAutoCenter:!1})}}function b(y,m){let T=Cr(t?.polygons??[])*r,M=T/an,R=fl(y.color,m);if(y.kind==="arrow"){let _=e.camera.state,j=Sr(y.cssAxis,y.sign,_.rotX??65,_.rotY??45);return(0,Le.arrowPolygons)({axis:mt[y.cssAxis],sign:y.sign,shaftLength:M,shaftHalfThickness:M*sl,headLength:M*il,headHalfThickness:M*al,color:R,shaft:!j})}if(y.kind==="plane"){let _=e.camera.state,j=_.rotX??65,Q=_.rotY??45,ae=mt[y.perpAxis],xe=(ae+1)%3,ge=(ae+2)%3,be=mt[xe],Re=mt[ge],Te=Sr(be,1,j,Q)?-1:1,De=Sr(Re,1,j,Q)?-1:1,Ke=M*ul;return(0,Le.planePolygons)({axis:ae,size:M*cl,offset:[Te*Ke,De*Ke],color:R})}let re=T*ll/an*Pr;return(0,Le.ringQuadPolygons)({axis:mt[y.cssAxis],outerRadius:re,color:R})}function v(y){return y.kind==="arrow"?"polycss-transform-arrow":y.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function P(){if(o==="translate"){let y=si.map(p=>({kind:"arrow",key:p.key,cssAxis:p.cssAxis,sign:p.sign,color:p.color})),m=ai.map(p=>({kind:"plane",key:p.key,perpAxis:p.perpAxis,axisA:p.axisA,axisB:p.axisB,color:p.color}));return[...y,...m]}return o==="rotate"?ii.map(y=>({kind:"ring",key:y.key,cssAxis:y.cssAxis,color:y.color})):[]}function g(){if(C(),!t)return;let y={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};function m(T){if(T.kind==="arrow"){let L=T.key.replace("-","")[0];return y[L]}if(T.kind==="ring")return y[T.key];let M=["x","y","z"][T.axisA],R=["x","y","z"][T.axisB];return y[M]&&y[R]}let p=d();for(let T of P()){if(!m(T))continue;let M=b(T,x(T.key)),R=e.add({polygons:M,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${T.key}`,position:p}),L=v(T);if(R.element.classList.add("polycss-transform-gizmo",L,`${L}--${T.key}`),T.kind==="ring"){let re=(1-ri)/Pr,_=(1+ri)/Pr;R.element.style.setProperty("--ring-inner-ratio",`${re}`),R.element.style.setProperty("--ring-outer-ratio",`${_}`)}i.set(T.key,{handle:R,spec:T})}}function C(){for(let{handle:y}of i.values())y.remove();i.clear(),c=null,l=null}function D(){if(!t)return;let y=d();for(let{handle:m}of i.values())m.setTransform({position:y})}function k(){t&&(i.size===0?g():D())}function z(y){if(t=y,!y){u=[0,0,0],C();return}u=hl(y.polygons),C(),g()}function I(){z(null)}function Z(y){y!==o&&(o=y,t&&(C(),g()))}function K(y,m,p){if(!t||!O)return;let T=p[y.cssAxis],M=mt[y.cssAxis],R=m*T/an,L=O.slice();L[M]=O[M]+R,t.setTransform({position:L}),D(),s.onObjectChange?.({object:t,position:L}),s.onChange?.()}let O=null,H=null,V=y=>{if(!t||s.enabled===!1)return;let m={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate"){for(let p of ai){let T=["x","y","z"][p.axisA],M=["x","y","z"][p.axisB];if(!m[T]||!m[M])continue;let R=i.get(p.key);if(R&&sn(R.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),O=(t.transform.position??[0,0,0]).slice(),yl({axisA:p.axisA,axisB:p.axisB,probeDistanceCss:Cr(t.polygons)*r,wrapper:R.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,translationSnap:s.translationSnap??null,onPlaneDelta:(L,re,_,j)=>{if(!t||!O)return;let Q=_[p.axisA],ae=j[p.axisB],xe=mt[p.axisA],ge=mt[p.axisB],be=O.slice();be[xe]+=L*Q/an,be[ge]+=re*ae/an,t.setTransform({position:be}),D(),s.onObjectChange?.({object:t,position:be}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:L=>{L||(l=null,O=null,h()),s.onDraggingChanged?.(L)}});return}}for(let p of si){let T=p.key.replace("-","")[0];if(!m[T])continue;let M=i.get(p.key);if(M&&sn(M.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),O=(t.transform.position??[0,0,0]).slice(),gl({cssAxis:p.cssAxis,sign:p.sign,shaftLengthCss:Cr(t.polygons)*r,wrapper:M.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(R,L)=>K(p,R,L),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:R=>{R||(l=null,O=null,h()),s.onDraggingChanged?.(R)}});return}}}else if(o==="rotate")for(let p of ii){if(!m[p.key])continue;let T=i.get(p.key);if(T&&sn(T.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),H=(t.transform.rotation??[0,0,0]).slice(),O=(t.transform.position??[0,0,0]).slice(),bl({cssAxis:p.cssAxis,wrapper:T.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:M=>{if(!t||!H||!O)return;let R=mt[p.cssAxis],L=[0,0,0];L[R]=1;let re=-M*Math.PI/180,_=(0,Le.quatFromEulerXYZ)(H),j=(0,Le.quatFromAxisAngle)(L,re),Q=(0,Le.eulerXYZFromQuat)((0,Le.quatMultiply)(j,_)),ae=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,xe=(0,Le.rotateVec3)(u,H[0],H[1],H[2]),ge=(0,Le.rotateVec3)(u,Q[0],Q[1],Q[2]),be=[O[0]+ae*(xe[0]-ge[0]),O[1]+ae*(xe[1]-ge[1]),O[2]+ae*(xe[2]-ge[2])];t.setTransform({rotation:Q,position:be}),D(),s.onObjectChange?.({object:t,rotation:Q,position:be}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:M=>{M||(l=null,H=null,O=null,h(),t?.rebakeAtlas()),s.onDraggingChanged?.(M)}});return}}};e.host.addEventListener("pointerdown",V,{capture:!0});let $=y=>{if(!t||l||s.enabled===!1)return;let m=null;for(let[p,T]of i)if(sn(T.handle.element,y.clientX,y.clientY)){m=p;break}m!==c&&(c=m,h())};e.host.addEventListener("pointermove",$);function A(){e.host.removeEventListener("pointerdown",V,{capture:!0}),e.host.removeEventListener("pointermove",$),C()}return{attach:z,detach:I,setMode:Z,update:k,destroy:A}}var vl=typeof HTMLElement<"u"?HTMLElement:class{},xl=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function Qe(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Pl(e){return e==="false"?!1:Qe(e)}function Er(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 Sl(e){if(e==="baked"||e==="dynamic")return e}function Cl(e){return e==="auto"?"auto":Qe(e)}function El(e){return typeof e.getCamera=="function"}var He=class extends vl{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...xl]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(El(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=Pl(this.getAttribute("perspective")),o=Qe(this.getAttribute("rot-x")),r=Qe(this.getAttribute("rot-y")),s=Qe(this.getAttribute("zoom")),i=Qe(this.getAttribute("distance")),c=Er(this.getAttribute("target")),l={...o!==void 0?{rotX:o}:{},...r!==void 0?{rotY:r}:{},...s!==void 0?{zoom:s}:{},...i!==void 0?{distance:i}:{},...c!==void 0?{target:c}:{}};return t===!1?Tt(l):t!==void 0?Ht({...l,perspective:t}):Tt(l)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={};r.textureLighting=Sl(this.getAttribute("texture-lighting"))??"baked";let s=Cl(this.getAttribute("texture-quality"));return s!==void 0&&(r.textureQuality=s),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=Er(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=Qe(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=Qe(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(){if(this._scene)return;let t=this._findAncestorCamera(),o;t?(o=t,this._implicitCamera=null):(this._implicitCamera=this._buildImplicitCamera(),o=this._implicitCamera),this._scene=Xn(this,{camera:o,...this._readNonCameraOptions()}),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1}))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null),this._implicitCamera=null}attributeChangedCallback(t,o,r){if(o!==r&&this._scene){if(this._implicitCamera&&["rot-x","rot-y","zoom","distance","target"].includes(t)){let i=Qe(this.getAttribute("rot-x")),c=Qe(this.getAttribute("rot-y")),l=Qe(this.getAttribute("zoom")),u=Qe(this.getAttribute("distance")),d=Er(this.getAttribute("target"));i!==void 0&&this._implicitCamera.update({rotX:i}),c!==void 0&&this._implicitCamera.update({rotY:c}),l!==void 0&&this._implicitCamera.update({zoom:l}),u!==void 0&&this._implicitCamera.update({distance:u}),d!==void 0&&this._implicitCamera.update({target:d}),this._scene.applyCamera();return}this._scene.setOptions(this._readNonCameraOptions())}}};var ao=require("@layoutit/polycss-core"),Tl=typeof HTMLElement<"u"?HTMLElement:class{},Al=["src","mtl","mesh-resolution","position","scale","rotation","auto-center","cast-shadow","receive-shadow","target-size","default-color","palette","include-objects","exclude-objects"];function Tn(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 ci(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Tn(e)}}function Tr(e){if(!e)return;let n=e.split(",").map(t=>t.trim()).filter(t=>t.length>0);return n.length>0?n:void 0}function wl(e){let n=e.getAttribute("target-size"),t=e.getAttribute("default-color"),o=Tr(e.getAttribute("palette")),r=Tr(e.getAttribute("include-objects")),s=Tr(e.getAttribute("exclude-objects")),i=n!==null?parseFloat(n):NaN,c={};return Number.isFinite(i)&&(c.targetSize=i),t&&(c.defaultColor=t),o&&(c.palette=o),r&&(c.includeObjects=r),s&&(c.excludeObjects=s),Object.keys(c).length>0?c:void 0}function Ml(e){return e.closest("poly-scene")??null}function Ll(e){if(e.length===0)return e;let n=(0,ao.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 ln=class extends Tl{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Al]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"||t==="mesh-resolution"||t==="target-size"||t==="default-color"||t==="palette"||t==="include-objects"||t==="exclude-objects"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:Tn(this.getAttribute("position")),scale:ci(this.getAttribute("scale")),rotation:Tn(this.getAttribute("rotation")),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")})}}_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=Ml(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,l=wl(this),u;try{let h=s||c!==void 0||l?{...s?{mtlUrl:s}:{},...c!==void 0?{meshResolution:c}:{},...l?{objOptions:l}:{}}:void 0;u=await(0,ao.loadMesh)(t,h)}catch(h){this.dispatchEvent(new CustomEvent("polycss:error",{detail:h,bubbles:!0}));return}if(r!==this._loadToken){try{u.dispose()}catch{}return}let d=o.getScene();if(!d){try{u.dispose()}catch{}return}this.hasAttribute("auto-center")&&(u={...u,polygons:Ll(u.polygons)}),this._parseResult=u,this._handle=d.add(u,{position:Tn(this.getAttribute("position")),scale:ci(this.getAttribute("scale")),rotation:Tn(this.getAttribute("rotation")),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var cn=require("@layoutit/polycss-core"),_l=typeof HTMLElement<"u"?HTMLElement:class{},Rl=["src","width","height","position","rotation","scale","allow","loading","referrerpolicy","sandbox","title"];function Ar(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 kl(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Ar(e)}}function ui(e,n){if(e===null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}function Ol(e){let n=e.closest("poly-scene");return n?n.querySelector(".polycss-scene"):null}function Dl(e,n,t,o,r){let s=typeof t=="number"?t:t?.[0]??1,i=typeof t=="number"?t:t?.[1]??1,c=typeof t=="number"?t:t?.[2]??1,l=s!==1||i!==1||c!==1,u=!!n&&(!!n[0]||!!n[1]||!!n[2]),d=(e?.[1]??0)*cn.BASE_TILE,x=(e?.[0]??0)*cn.BASE_TILE,h=(e?.[2]??0)*cn.BASE_TILE,b=[];return b.push(`translate3d(${d}px, ${x}px, ${h}px)`),u&&(n[0]&&b.push(`rotateY(${-n[0]}deg)`),n[1]&&b.push(`rotateX(${-n[1]}deg)`),n[2]&&b.push(`rotateZ(${-n[2]}deg)`)),l&&b.push(`scale3d(${s}, ${i}, ${c})`),b.push(`translate(${-o/2}px, ${-r/2}px)`),b.join(" ")}var lo=class extends _l{constructor(){super(...arguments);this._wrapper=null;this._iframe=null}static get observedAttributes(){return[...Rl]}getIframeElement(){return this._iframe}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o!==r&&!(!this._wrapper||!this._iframe)){if(t==="src"){this._iframe.src=this.getAttribute("src")??"";return}if(t==="allow"||t==="loading"||t==="referrerpolicy"||t==="sandbox"||t==="title"){let s=this.getAttribute(t);s===null?this._iframe.removeAttribute(t):this._iframe.setAttribute(t,s);return}this._applyGeometry()}}_mount(){let t=Ol(this);if(!t)return;let o=this.ownerDocument;if(!o)return;let r=o.createElement("div");r.className="polycss-iframe",r.style.position="absolute",r.style.left="0",r.style.top="0",r.style.transformOrigin="0 0",r.style.transformStyle="preserve-3d";let s=o.createElement("iframe");s.style.display="block",s.style.border="0",s.style.background="#000";let i=this.getAttribute("src");i&&(s.src=i);let c=this.getAttribute("allow");c&&s.setAttribute("allow",c);for(let l of["loading","referrerpolicy","sandbox","title"]){let u=this.getAttribute(l);u!==null&&s.setAttribute(l,u)}r.appendChild(s),t.appendChild(r),this._wrapper=r,this._iframe=s,this._applyGeometry()}_applyGeometry(){if(!this._wrapper||!this._iframe)return;let t=ui(this.getAttribute("width"),16),o=ui(this.getAttribute("height"),9),r=t*cn.BASE_TILE,s=o*cn.BASE_TILE;this._iframe.style.width=`${r}px`,this._iframe.style.height=`${s}px`;let i=Ar(this.getAttribute("position")),c=Ar(this.getAttribute("rotation")),l=kl(this.getAttribute("scale"));this._wrapper.style.transform=Dl(i,c,l,r,s)}_teardown(){this._wrapper?.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null,this._iframe=null}};var Il=typeof HTMLElement<"u"?HTMLElement:class{},Hl=["vertices","color","texture","uvs","position","scale","rotation"];function di(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function wr(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 Fl(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return wr(e)}}function Vl(e){return e.closest("poly-scene")??null}var co=class extends Il{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Hl]}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=Vl(this);if(!t)return;let o=t.getScene();if(!o)return;let r=di(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=di(this.getAttribute("uvs"))??void 0,l={};for(let x of Array.from(this.attributes))x.name.startsWith("data-")&&(l[x.name.slice(5)]=x.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:wr(this.getAttribute("position")),scale:Fl(this.getAttribute("scale")),rotation:wr(this.getAttribute("rotation"))})}};function oe(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function uo(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Oe(e){if(e!==null)return!(e==="false"||e==="0")}function po(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 mo(e){if(e==="x"||e==="y")return e}var Bl=typeof HTMLElement<"u"?HTMLElement:class{},zl=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],fo=class extends Bl{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...zl]}getControls(){return this._controls}_readAnimate(){let t=oe(this.getAttribute("animate-speed")),o=mo(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:Oe(r)}:{}}}_readOptions(){let t={},o=Oe(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Oe(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=oe(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=oe(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=po(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=oe(this.getAttribute("zoom-min")),u=oe(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof He)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=Kn(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 Nl=typeof HTMLElement<"u"?HTMLElement:class{},$l=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],ho=class extends Nl{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...$l]}_readAnimate(){let t=oe(this.getAttribute("animate-speed")),o=mo(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:Oe(r)}:{}}}_readOptions(){let t={},o=Oe(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Oe(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=oe(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=oe(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=po(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=oe(this.getAttribute("zoom-min")),u=oe(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof He)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=Jn(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 Ul=typeof HTMLElement<"u"?HTMLElement:class{},Gl=["enabled","look-enabled","move-enabled","jump-enabled","crouch-enabled","look-sensitivity","invert-y","move-speed","jump-velocity","gravity","eye-height","crouch-height","ground-z","min-pitch","max-pitch"],go=class extends Ul{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Gl]}_readOptions(){let t={},o=Oe(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let r=Oe(this.getAttribute("look-enabled"));r!==void 0&&(t.lookEnabled=r);let s=Oe(this.getAttribute("move-enabled"));s!==void 0&&(t.moveEnabled=s);let i=Oe(this.getAttribute("jump-enabled"));i!==void 0&&(t.jumpEnabled=i);let c=Oe(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let l=oe(this.getAttribute("look-sensitivity"));if(l!==void 0&&(t.lookSensitivity=l),this.hasAttribute("invert-y")){let C=Oe(this.getAttribute("invert-y"));C!==void 0&&(t.invertY=C)}let u=oe(this.getAttribute("move-speed"));u!==void 0&&(t.moveSpeed=u);let d=oe(this.getAttribute("jump-velocity"));d!==void 0&&(t.jumpVelocity=d);let x=oe(this.getAttribute("gravity"));x!==void 0&&(t.gravity=x);let h=oe(this.getAttribute("eye-height"));h!==void 0&&(t.eyeHeight=h);let b=oe(this.getAttribute("crouch-height"));b!==void 0&&(t.crouchHeight=b);let v=oe(this.getAttribute("ground-z"));v!==void 0&&(t.groundZ=v);let P=oe(this.getAttribute("min-pitch"));P!==void 0&&(t.minPitch=P);let g=oe(this.getAttribute("max-pitch"));return g!==void 0&&(t.maxPitch=g),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof He)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=eo(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 jl=typeof HTMLElement<"u"?HTMLElement:class{},Wl=["perspective","zoom","rot-x","rot-y","target","distance"],yo=class extends jl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Wl]}getCamera(){return this._camera}_readOptions(){return{perspective:oe(this.getAttribute("perspective")),zoom:oe(this.getAttribute("zoom")),rotX:oe(this.getAttribute("rot-x")),rotY:oe(this.getAttribute("rot-y")),target:uo(this.getAttribute("target")),distance:oe(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Ht(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();if(t==="perspective"){this._camera=Ht(s),this._wrapper.style.perspective=this._camera.perspectiveStyle;return}this._camera.update({rotX:s.rotX,rotY:s.rotY,zoom:s.zoom,target:s.target,distance:s.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var Yl=typeof HTMLElement<"u"?HTMLElement:class{},Xl=["zoom","rot-x","rot-y","target","distance"],un=class extends Yl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Xl]}getCamera(){return this._camera}_readOptions(){return{zoom:oe(this.getAttribute("zoom")),rotX:oe(this.getAttribute("rot-x")),rotY:oe(this.getAttribute("rot-y")),target:uo(this.getAttribute("target")),distance:oe(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Tt(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}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var bo=class extends un{};var Zl=typeof HTMLElement<"u"?HTMLElement:class{},ql=["mode","target","size","enabled"];function pi(e){if(e==="translate"||e==="rotate")return e}var vo=class extends Zl{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...ql]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof He)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 ln?r:null}_readOptions(){let t={},o=pi(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=oe(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=io(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=pi(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};var Ql=typeof HTMLElement<"u"?HTMLElement:class{},Kl=["multiple","clear-on-miss"],xo=class extends Ql{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Kl]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof He)return t;t=t.parentNode}return null}_readOptions(){return{multiple:this.hasAttribute("multiple"),clearOnMiss:!this.hasAttribute("clear-on-miss")||this.getAttribute("clear-on-miss")!=="false",onChange:t=>{this.dispatchEvent(new CustomEvent("polycss:select",{bubbles:!0,detail:{selected:t}}))}}}_attach(){if(this._selection)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._selection=to(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};var Mr={quad:0,clippedSolid:0,atlas:0,stableTriangle:0},Jl={polygonCount:0,mountedPolygonLeafCount:0,shadowLeafCount:0,surfaceLeafCounts:Mr,bucketCount:0};function ec(e){return typeof e=="number"?{polygonCount:e}:e??{}}function dn(e,n){return e.querySelectorAll(n).length}function tc(e,n){let t=e;return typeof t.matches=="function"&&t.matches(n)}function nc(e,n){if(!n)return[e];let t=[];return tc(e,n)&&t.push(e),t.push(...Array.from(e.querySelectorAll(n))),t}function mi(e,n){let t=ec(n);if(!e)return{...Jl,surfaceLeafCounts:{...Mr},polygonCount:t.polygonCount??0};let o=nc(e,t.scopeSelector),r={...Mr},s=0,i=0;for(let l of o)r.quad+=dn(l,"b"),r.clippedSolid+=dn(l,"i"),r.atlas+=dn(l,"s"),r.stableTriangle+=dn(l,"u"),s+=dn(l,"q, .polycss-shadow-svg"),i+=dn(l,".polycss-bucket");let c=r.quad+r.clippedSolid+r.atlas+r.stableTriangle;return{polygonCount:t.polygonCount??c,mountedPolygonLeafCount:c,shadowLeafCount:s,surfaceLeafCounts:r,bucketCount:i}}var At=class extends Error{constructor(n,t,o){super(t),this.name="PolySceneSnapshotError",this.code=n,this.url=o,Object.setPrototypeOf(this,new.target.prototype)}},oc=`
520
+ html,
521
+ body {
522
+ width: 100%;
523
+ height: 100%;
524
+ margin: 0;
525
+ }
380
526
 
381
- The base layout / positioning / pseudo-element-strip rules for <q>
382
- live in the polygon-leaf section above. This rule only adds the
383
- dynamic-light Lambert gating, separated so it's easy to disable the
384
- gate for debugging by commenting out a single block. */
385
- .polycss-scene q {
527
+ body {
528
+ position: relative;
529
+ overflow: hidden;
530
+ }
531
+ `,Lr=["b","i","s","u"],rc=["b","i","u"],sc=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--pnx","--pny","--pnz","--psr","--psg","--psb","--plam","--polycss-light-preview-active","--polycss-preview-r","--polycss-preview-g","--polycss-preview-b"],ic=["--clx","--cly","--clz","--shadow-ground-cssz"],ac=["--polycss-atlas-size","--polycss-atlas-url","--polycss-atlas-position","--polycss-atlas-image-size"];function lc(e){return!!e&&typeof e.querySelector=="function"&&typeof e.cloneNode=="function"}function cc(e){let n=e.closest(".polycss-camera");if(n)return n;let t=e.closest(".polycss-scene");return t?t.closest(".polycss-camera")??t:e.querySelector(".polycss-camera")??e.querySelector(".polycss-scene")}function wn(e){return[e,...Array.from(e.querySelectorAll("*"))]}function ft(e,n){return e.matches(n)||!!e.querySelector(n)}function fi(e,n){return e.tagName.toLowerCase()===n||!!e.querySelector(n)}function uc(e){let n=Lr.filter(o=>fi(e,o)),t=rc.filter(o=>n.includes(o));return{hasCamera:ft(e,".polycss-camera"),hasScene:ft(e,".polycss-scene"),hasMesh:ft(e,".polycss-mesh"),hasFpvHost:ft(e,".polycss-fpv-host"),hasBucket:ft(e,".polycss-bucket"),hasVoxelMesh:ft(e,".polycss-voxel-mesh"),hasTransformGizmo:ft(e,".polycss-transform-gizmo"),hasTransformRing:ft(e,".polycss-transform-ring"),hasDynamicLighting:ft(e,'.polycss-scene[data-polycss-lighting="dynamic"]'),hasQ:fi(e,"q"),leafTags:n,solidLeafTags:t}}function An(e,n=".polycss-scene "){return e.map(t=>`${n}${t}`).join(`,
532
+ `)}function dc(e){return e.map(n=>`.polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > ${n}`).join(`,
533
+ `)}function pc(e){let n=['@property --plx { syntax: "<number>"; inherits: true; initial-value: 0; }','@property --ply { syntax: "<number>"; inherits: true; initial-value: 0; }','@property --plz { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --plr { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --plg { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --plb { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --pli { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --par { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --pag { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --pab { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --pai { syntax: "<number>"; inherits: true; initial-value: 0.4; }','@property --pnx { syntax: "<number>"; inherits: true; initial-value: 0; }','@property --pny { syntax: "<number>"; inherits: true; initial-value: 0; }','@property --pnz { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --psr { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --psg { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --psb { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --plam { syntax: "<number>"; inherits: true; initial-value: 0; }'];return e&&n.push('@property --clx { syntax: "<number>"; inherits: true; initial-value: 0.01; }','@property --cly { syntax: "<number>"; inherits: true; initial-value: 0; }','@property --clz { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --shadow-ground-cssz { syntax: "<number>"; inherits: true; initial-value: 0; }'),n.join(`
534
+ `)}function mc(e){let n=[pc(e.hasQ)];return e.hasBucket&&n.push(`
535
+ .polycss-scene[data-polycss-lighting="dynamic"] .polycss-bucket {
536
+ --plam: max(0, calc(
537
+ var(--pnx) * var(--plx) +
538
+ var(--pny) * var(--ply) +
539
+ var(--pnz) * var(--plz)
540
+ ));
541
+ }
542
+ `),e.leafTags.length>0&&n.push(`
543
+ ${dc(e.leafTags)} {
544
+ --plam: max(0, calc(
545
+ var(--pnx) * var(--plx) +
546
+ var(--pny) * var(--ply) +
547
+ var(--pnz) * var(--plz)
548
+ ));
549
+ }
550
+ `),e.leafTags.includes("s")&&n.push(`
551
+ .polycss-scene[data-polycss-lighting="dynamic"] s {
552
+ contain: strict;
553
+ background-color: rgb(
554
+ calc(255 * (var(--par) * var(--pai)
555
+ + var(--plr) * var(--pli) * var(--plam)))
556
+ calc(255 * (var(--pag) * var(--pai)
557
+ + var(--plg) * var(--pli) * var(--plam)))
558
+ calc(255 * (var(--pab) * var(--pai)
559
+ + var(--plb) * var(--pli) * var(--plam)))
560
+ );
561
+ background-blend-mode: multiply;
562
+ background-image: var(--polycss-atlas-url);
563
+ background-position: var(--polycss-atlas-position);
564
+ background-repeat: no-repeat;
565
+ background-size: var(--polycss-atlas-image-size);
566
+ mask-image: var(--polycss-atlas-url);
567
+ mask-mode: alpha;
568
+ mask-position: var(--polycss-atlas-position);
569
+ mask-repeat: no-repeat;
570
+ mask-size: var(--polycss-atlas-image-size);
571
+ -webkit-mask-image: var(--polycss-atlas-url);
572
+ -webkit-mask-position: var(--polycss-atlas-position);
573
+ -webkit-mask-repeat: no-repeat;
574
+ -webkit-mask-size: var(--polycss-atlas-image-size);
575
+ }
576
+ `),e.solidLeafTags.length>0&&n.push(`
577
+ ${An(e.solidLeafTags)} {
578
+ color: rgb(
579
+ calc(255 * var(--psr) * (var(--par) * var(--pai)
580
+ + var(--plr) * var(--pli) * var(--plam)))
581
+ calc(255 * var(--psg) * (var(--pag) * var(--pai)
582
+ + var(--plg) * var(--pli) * var(--plam)))
583
+ calc(255 * var(--psb) * (var(--pab) * var(--pai)
584
+ + var(--plb) * var(--pli) * var(--plam)))
585
+ );
586
+ }
587
+ `),e.hasQ&&n.push(`
588
+ .polycss-scene[data-polycss-lighting="dynamic"] {
589
+ --shadow-proj: matrix3d(
590
+ 1, 0, 0, 0,
591
+ 0, 1, 0, 0,
592
+ calc(-1 * var(--clx) / var(--clz)),
593
+ calc(-1 * var(--cly) / var(--clz)),
594
+ 0.01,
595
+ 0,
596
+ calc(var(--shadow-ground-cssz) * var(--clx) / var(--clz)),
597
+ calc(var(--shadow-ground-cssz) * var(--cly) / var(--clz)),
598
+ calc(var(--shadow-ground-cssz) * 0.99),
599
+ 1
600
+ );
601
+ }
602
+
603
+ .polycss-scene[data-polycss-lighting="dynamic"] q {
386
604
  opacity: clamp(0, calc((var(--pnx) * var(--clx) + var(--pny) * var(--cly) + var(--pnz) * var(--clz)) * 10), 1);
387
605
  }
388
- `;var As=750,Ms=8e3;var ft=65,ht=45,Ss=1,De=te.BASE_TILE;function Ls(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let r of t)if(!o.includes(r))return!1;return!0}function go(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 ws(e,n=[0,0,0],t=1){let o=e.rotX??ft,r=e.rotY??ht,s=(e.zoom??Ss)*t,i=(e.distance??0)*t,a=e.target??[0,0,0],l=a[0]+n[0],u=a[1]+n[1],p=a[2]+n[2],d=u*De,f=l*De,g=p*De;return`${i!==0?`translateZ(${-i}px) `:""}scale(${s}) rotateX(${o}deg) rotate(${r}deg) translate3d(${-d}px, ${-f}px, ${-g}px)`}function Ts(e){let n=e.trim();if(!n||n==="normal")return 1;let t=n.endsWith("%")?Number(n.slice(0,-1))/100:Number(n);return Number.isFinite(t)&&t>0?t:1}function _s(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=Ts(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function gn(e,n){return n===1?e:e*n}function ks(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}var Rs=.1;function Os(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let d=1;d+1<e.vertices.length;d++){let f=e.vertices[d],g=e.vertices[d+1],m=f[1]-n[1],h=f[0]-n[0],y=f[2]-n[2],v=g[1]-n[1],E=g[0]-n[0],A=g[2]-n[2];t-=h*A-y*E,o-=y*v-m*A,r-=m*E-h*v}let s=Math.hypot(t,o,r);if(s<1e-9)return null;t/=s,o/=s,r/=s;let i=1/Rs,a=Math.round(t*i)/i,l=Math.round(o*i)/i,u=Math.round(r*i)/i,p=Math.hypot(a,l,u);return p<1e-9?null:{key:a+","+l+","+u,vec:[a/p,l/p,u/p]}}function gt(e,n={}){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");e.ownerDocument&&pt(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let t={...n},o=_s(e),r=[0,0,0],s=e.ownerDocument??document,i=s.createElement("div");i.className="polycss-scene",i.setAttribute("aria-hidden","true"),l(i,t),e.appendChild(i);let a=new Set;function l(c,b){ks(c,o),c.style.transform=ws(b,r,o),typeof b.perspective=="number"?c.style.perspective=`${gn(b.perspective,o)}px`:b.perspective===!1?c.style.perspective=`${gn(1e6,o)}px`:Math.abs(o-1)<1e-6?c.style.removeProperty("perspective"):c.style.perspective=`${gn(Ms,o)}px`,u(c,b)}function u(c,b){let R=b.textureLighting==="dynamic";c.dataset.polycssLighting=b.textureLighting??"baked";let _=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"];if(!R){for(let re of _)c.style.removeProperty(re);return}let V=b.directionalLight?.direction??[.4,-.7,.59],D=Math.hypot(V[0],V[1],V[2])||1,Y=V[0]/D,L=V[1]/D,N=V[2]/D,z=(0,te.parseHexColor)(b.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],G=(0,te.parseHexColor)(b.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],K=b.directionalLight?.intensity??1,T=b.ambientLight?.intensity??.4,Q=re=>(re/255).toFixed(4);c.style.setProperty("--plx",Y.toFixed(4)),c.style.setProperty("--ply",L.toFixed(4)),c.style.setProperty("--plz",N.toFixed(4)),c.style.setProperty("--plr",Q(z[0])),c.style.setProperty("--plg",Q(z[1])),c.style.setProperty("--plb",Q(z[2])),c.style.setProperty("--pli",K.toFixed(4)),c.style.setProperty("--par",Q(G[0])),c.style.setProperty("--pag",Q(G[1])),c.style.setProperty("--pab",Q(G[2])),c.style.setProperty("--pai",T.toFixed(4));let H=N,q=Math.sign(H||1)*Math.max(Math.abs(H),.01);c.style.setProperty("--clx",Y.toFixed(4)),c.style.setProperty("--cly",L.toFixed(4)),c.style.setProperty("--clz",q.toFixed(4))}function p(c){c.voxelRenderer?.dispose(),c.voxelRenderer=void 0,h(c.rendered,c.disposeAtlas),c.disposeAtlas=void 0,c.rendered.length=0,c.cameraCullGroups.length=0,c.cameraCullSignature="",m(c);for(let b of Array.from(c.wrapper.children))b instanceof HTMLElement&&b.classList.contains("polycss-bucket")&&b.remove()}function d(c){for(let b of Array.from(c.wrapper.childNodes)){if(!(b instanceof HTMLElement))return b;if(b.classList.contains("polycss-bucket")||b.classList.contains("polycss-shadow"))continue;let R=b.tagName.toLowerCase();if(!(R==="b"||R==="i"||R==="s"||R==="u"||R==="q"))return b}return null}function f(c,b,R){R?.parentNode===c.wrapper?c.wrapper.insertBefore(b,R):c.wrapper.appendChild(b)}function g(c){return Array.from(c.children).some(b=>b instanceof HTMLElement&&b.classList.contains("polycss-bucket"))}function m(c){for(let b of c.shadowRendered)b.parentNode&&b.parentNode.removeChild(b);c.shadowRendered.length=0}function h(c,b){b?.();for(let R of c){try{R.dispose()}catch{}R.element.parentNode&&R.element.parentNode.removeChild(R.element)}}function y(c){for(let b of Array.from(c.wrapper.children))b instanceof HTMLElement&&b.classList.contains("polycss-bucket")&&b.remove();for(let b of c.rendered)b.element.parentNode&&b.element.parentNode.removeChild(b.element)}function v(c,b){let R=c.polygons[b.polygonIndex];return c.stableDom&&R?(0,te.polygonCssSurfaceNormal)(R):b.plan?.normal??(R?(0,te.polygonCssSurfaceNormal)(R):null)}function E(c){if(!M(c))return c.rendered;let b=A(c);return c.rendered.filter(R=>x(c,R,te.CAMERA_BACKFACE_CULL_EPS,b))}function A(c){return{rotX:t.rotX??ft,rotY:t.rotY??ht,meshRotation:c.handle.transform.rotation}}function x(c,b,R=te.CAMERA_BACKFACE_CULL_EPS,_=A(c)){let V=v(c,b);return V===null||(0,te.normalFacesCamera)(V,_,R)}function C(c){c.cameraCullGroups=(0,te.cameraCullNormalGroups)(c.rendered.map(b=>v(c,b)))}function O(c){return M(c)?(0,te.cameraCullVisibleSignature)(c.cameraCullGroups,A(c)):"all"}function M(c){return!c.excludeFromAutoCenter&&(0,te.isVoxelCameraCullableNormalGroups)(c.cameraCullGroups)}function P(c){c.cameraCullSignature=M(c)?O(c):"all"}function X(c,b){let R=new Array(c.rendered.length),_=!1,V=A(c);for(let K=0;K<c.rendered.length;K+=1){let T=c.rendered[K],Q=x(c,T,b,V);R[K]=Q}let D=null,Y=null,L=()=>{if(!(!D||!Y)){if(D===Y)D.remove();else{let K=s.createRange();K.setStartBefore(D),K.setEndAfter(Y),K.deleteContents(),K.detach()}D=null,Y=null,_=!0}};for(let K=0;K<c.rendered.length;K+=1){let T=c.rendered[K];!R[K]&&T.element.parentNode===c.wrapper?(Y&&Y.nextSibling===T.element||(L(),D=T.element),Y=T.element):L()}L();let N=K=>{for(let T=K;T<c.rendered.length;T+=1){let Q=c.rendered[T].element;if(Q.parentNode===c.wrapper)return Q}return d(c)},z=-1,G=K=>{if(z<0)return;let T=s.createDocumentFragment();for(let Q=z;Q<K;Q+=1){let H=c.rendered[Q];S(c,H),T.appendChild(H.element)}f(c,T,N(K)),z=-1,_=!0};for(let K=0;K<c.rendered.length;K+=1){let T=c.rendered[K];R[K]&&T.element.parentNode!==c.wrapper?z<0&&(z=K):G(K)}return G(c.rendered.length),_}function $(c,b=!1){if(c.voxelRenderer){c.voxelRenderer.syncCamera(A(c)),c.cameraCullSignature="voxel-direct";return}if(!M(c)){let V=c.cameraCullSignature!=="all";c.cameraCullSignature="all",V&&le(c);return}if(g(c.wrapper)){W(c,b);return}let R=O(c);if(!b&&R===c.cameraCullSignature)return;let _=X(c,te.CAMERA_BACKFACE_CULL_EPS);c.cameraCullSignature=R,_&&J(c)}function W(c,b=!1){let R=M(c)?O(c):"all";!b&&R===c.cameraCullSignature||le(c)}function ne(c,b){return v(c,b)}function S(c,b){if(t.textureLighting!=="dynamic")return;let R=ne(c,b);R&&(b.element.style.setProperty("--pnx",R[0].toFixed(4)),b.element.style.setProperty("--pny",R[1].toFixed(4)),b.element.style.setProperty("--pnz",R[2].toFixed(4)))}function U(c){y(c);let b=s.createDocumentFragment(),R=t.textureLighting==="dynamic"&&!c.stableDom,_=new Map,V=[];for(let D of E(c)){let Y=c.polygons[D.polygonIndex],L=R&&Y?Os(Y):null;if(!L){V.push(D);continue}let N=L.key+"|"+(Y.color??""),z=_.get(N);z||(z={vec:L.vec,items:[]},_.set(N,z)),z.items.push(D)}for(let D of V)S(c,D),b.appendChild(D.element);for(let D of _.values()){if(D.items.length<2){for(let L of D.items)S(c,L),b.appendChild(L.element);continue}let Y=s.createElement("div");Y.className="polycss-bucket",Y.style.setProperty("--pnx",String(D.vec[0])),Y.style.setProperty("--pny",String(D.vec[1])),Y.style.setProperty("--pnz",String(D.vec[2]));for(let L of D.items)Y.appendChild(L.element),L.element.style.removeProperty("--pnx"),L.element.style.removeProperty("--pny"),L.element.style.removeProperty("--pnz");b.appendChild(Y)}f(c,b,d(c)),P(c)}function w(){return new Promise(c=>setTimeout(c,0))}async function I(c,b){if(t.textureLighting==="dynamic"&&!c.stableDom)return U(c),!b();y(c);let _=s.createDocumentFragment(),V=d(c),D=0;for(let Y of E(c)){if(b())return!1;S(c,Y),_.appendChild(Y.element),D++,D%As===0&&(f(c,_,V),_=s.createDocumentFragment(),await w())}return _.childNodes.length>0&&f(c,_,V),P(c),!b()}function F(c,b){let R=t.textureLighting==="dynamic",_=t.directionalLight?.direction,V=b&&(b[0]!==0||b[1]!==0||b[2]!==0);if(!R||!V||!_){if(c.lightOverrideSignature==="clear")return;c.wrapper.style.removeProperty("--plx"),c.wrapper.style.removeProperty("--ply"),c.wrapper.style.removeProperty("--plz"),c.lightOverrideSignature="clear";return}let D=(0,te.inverseRotateVec3)(_,b),Y=Math.hypot(D[0],D[1],D[2])||1,L=(D[0]/Y).toFixed(4),N=(D[1]/Y).toFixed(4),z=(D[2]/Y).toFixed(4),G=`${L}|${N}|${z}`;c.lightOverrideSignature!==G&&(c.wrapper.style.setProperty("--plx",L),c.wrapper.style.setProperty("--ply",N),c.wrapper.style.setProperty("--plz",z),c.lightOverrideSignature=G)}function B(c,b){b.paintColor?c.style.setProperty("--polycss-paint",b.paintColor):c.style.removeProperty("--polycss-paint"),b.dynamicColor?(c.style.setProperty("--psr",(b.dynamicColor.r/255).toFixed(4)),c.style.setProperty("--psg",(b.dynamicColor.g/255).toFixed(4)),c.style.setProperty("--psb",(b.dynamicColor.b/255).toFixed(4))):(c.style.removeProperty("--psr"),c.style.removeProperty("--psg"),c.style.removeProperty("--psb"))}function J(c){if(m(c),!c.castShadow||t.textureLighting!=="dynamic")return;let b=t.shadow?.color??"#000000",R=t.shadow?.opacity??.25,_=(0,te.parseHexColor)(b)?.rgb??[0,0,0],V=_[0],D=_[1],Y=_[2],L=`rgba(${V},${D},${Y},${R})`,N=(0,te.findOverlappingPolygonDuplicates)(c.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.4}),z=s.createDocumentFragment();for(let K of E(c)){if(N.has(K.polygonIndex))continue;let T=K.plan;if(!T)continue;let Q=`matrix3d(${T.matrix})`,H=s.createElement("q");H.className="polycss-shadow",H.style.transform=`var(--shadow-proj) ${Q}`,H.style.color=L,H.style.width=`${T.canvasW}px`,H.style.height=`${T.canvasH}px`,H.style.setProperty("border-shape",no(T)),H.style.setProperty("--pnx",T.normal[0].toFixed(4)),H.style.setProperty("--pny",T.normal[1].toFixed(4)),H.style.setProperty("--pnz",T.normal[2].toFixed(4)),z.appendChild(H),c.shadowRendered.push(H)}let G=c.wrapper.firstChild;G?c.wrapper.insertBefore(z,G):c.wrapper.appendChild(z)}function le(c){if(c.voxelRenderer){c.voxelRenderer.render(A(c)),c.cameraCullSignature="voxel-direct";return}m(c),U(c),J(c)}function k(c){return!!c.voxelSource&&t.textureLighting!=="dynamic"&&!c.stableDom&&!c.castShadow}function j(c,b){p(c);let R=t.directionalLight,_=b?{...R,direction:b}:R;if(k(c)){let N=fo({doc:s,wrapper:c.wrapper,polygons:c.parseResult.polygons,directionalLight:_,ambientLight:t.ambientLight});if(N){c.voxelRenderer=N,N.render(A(c)),c.cameraCullSignature="voxel-direct";return}}let V={doc:s,directionalLight:_,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality,strategies:t.strategies},D=mt(c.polygons,V);B(c.wrapper,D);let Y={...V,solidPaintDefaults:D},L=(c.stableDom?pn(c.polygons,Y):null)??ao(c.polygons,Y);c.rendered=L.rendered,c.disposeAtlas=L.dispose,C(c),U(c),J(c)}function Z(){if(t.textureLighting!=="dynamic"){i.style.removeProperty("--shadow-ground-cssz");return}let c=1/0;for(let _ of a)if(!_.disposed&&_.castShadow)for(let V of _.polygons)for(let D of V.vertices)D[2]<c&&(c=D[2]);if(!Number.isFinite(c)){i.style.removeProperty("--shadow-ground-cssz");return}let b=t.shadow?.lift??.05,R=(c+b)*De;i.style.setProperty("--shadow-ground-cssz",R.toFixed(3))}async function se(c,b){p(c);let R={doc:s,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality,strategies:t.strategies},_=c.stableDom?pn(c.polygons,R):null;if(_){let Y=mt(c.polygons,R);return B(c.wrapper,Y),c.rendered=_.rendered,c.disposeAtlas=_.dispose,C(c),U(c),J(c),!b()}let V=await lo(c.polygons,R,b);if(b())return V.dispose(),!1;B(c.wrapper,V.solidPaintDefaults),c.rendered=V.rendered,c.disposeAtlas=V.dispose,C(c);let D=await I(c,b);return D&&J(c),D}function oe(){let c=r,b=[0,0,0];if(t.autoCenter){let R=[];for(let _ of a)!_.disposed&&!_.excludeFromAutoCenter&&R.push(..._.polygons);if(R.length>0){let _=(0,te.computeSceneBbox)(R);b=[(_.min[0]+_.max[0])/2,(_.min[1]+_.max[1])/2,(_.min[2]+_.max[2])/2]}}c[0]===b[0]&&c[1]===b[1]&&c[2]===b[2]||(r=b,l(i,t))}function de(c,b={}){let _=(i.ownerDocument??document).createElement("div");_.className="polycss-mesh",b.id&&_.setAttribute("data-poly-mesh-id",b.id);let V={...b},D=b.merge!==!1,Y=!!b.stableDom,L=0,N=go(V);N&&(_.style.transform=N);let z=(H,q)=>q?(0,te.mergePolygons)(H):H,G=z(c.polygons,D);function K(H){if(H.length===0){_.style.removeProperty("--origin");return}let q=1/0,re=1/0,ve=1/0,Me=-1/0,Ie=-1/0,We=-1/0;for(let Io of H)for(let Ee of Io.vertices)Ee[0]<q&&(q=Ee[0]),Ee[0]>Me&&(Me=Ee[0]),Ee[1]<re&&(re=Ee[1]),Ee[1]>Ie&&(Ie=Ee[1]),Ee[2]<ve&&(ve=Ee[2]),Ee[2]>We&&(We=Ee[2]);if(!Number.isFinite(q)){_.style.removeProperty("--origin");return}let Nt=(re+Ie)/2*De,nt=(q+Me)/2*De,ot=(ve+We)/2*De;_.style.setProperty("--origin",`${Nt}px ${nt}px ${ot}px`)}K(G),i.appendChild(_);let T={handle:void 0,wrapper:_,parseResult:c,rendered:[],shadowRendered:[],polygons:G,voxelSource:c.voxelSource,disposed:!1,stableDom:Y,excludeFromAutoCenter:!!b.excludeFromAutoCenter,castShadow:!!b.castShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",bakedRotation:b.rotation?[...b.rotation]:[0,0,0]},Q={polygons:G,element:_,id:b.id,get transform(){return V},remove(){L++,_.parentNode&&_.parentNode.removeChild(_),p(T),a.delete(T),oe(),Z()},setPolygons(H,q){L++,D=q?.merge??D,Y=q?.stableDom??Y,T.stableDom=Y,T.voxelSource=void 0,T.polygons=z(H,D),Q.polygons=T.polygons,K(T.polygons);let re=q?.recomputeAutoCenter??!0;if(T.stableDom&&!g(T.wrapper)){let ve={doc:s,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality},Me=mt(T.polygons,ve);if(B(T.wrapper,Me),uo(T.rendered,T.polygons,{...ve,solidPaintDefaults:Me})){C(T),$(T,!0),re&&oe();return}}j(T),re&&oe()},updatePolygon(H,q){let re=typeof H=="number"?H:T.polygons.indexOf(H);re<0||re>=T.polygons.length||(T.voxelSource=void 0,Object.assign(T.polygons[re],q),j(T))},async setPolygonsChunked(H,q){let re=++L;D=q?.merge??D,Y=q?.stableDom??Y,T.stableDom=Y,T.voxelSource=void 0,T.polygons=z(H,D),Q.polygons=T.polygons,K(T.polygons);let ve=q?.recomputeAutoCenter??!0;if(!await se(T,()=>T.disposed||re!==L)){p(T);return}ve&&oe()},setTransform(H){let q=T.castShadow;H.castShadow!==void 0&&(T.castShadow=!!H.castShadow),V={...V,...H};let re=go(V);_.style.transform=re??"",F(T,V.rotation),H.rotation!==void 0&&$(T),T.castShadow!==q&&(J(T),Z())},dispose(){if(!T.disposed){T.disposed=!0,L++,_.parentNode&&_.parentNode.removeChild(_),p(T);try{c.dispose()}catch{}a.delete(T),oe(),Z()}},rebakeAtlas(){T.bakedRotation=V.rotation?[...V.rotation]:[0,0,0];let H=t.directionalLight?.direction??[.4,-.7,.59],q=(0,te.inverseRotateVec3)(H,T.bakedRotation);j(T,q)},getPosition(){return V.position},getRotation(){return V.rotation},getScale(){return V.scale},getPolygons(){return Q.polygons}};return T.handle=Q,a.add(T),j(T),F(T,V.rotation),oe(),Z(),Q}function ge(c){let b=!!t.autoCenter,R=t.strategies,_=t.textureLighting,V=t.rotX??ft,D=t.rotY??ht;t={...t,...c},l(i,t);let Y=!!t.autoCenter;for(let G of a)F(G,G.handle.transform.rotation);let L=c.strategies!==void 0&&!Ls(c.strategies,R);if(L)for(let G of a)j(G);let N=c.rotX!==void 0&&(t.rotX??ft)!==V||c.rotY!==void 0&&(t.rotY??ht)!==D;if(!L&&N)for(let G of a)$(G);if(b!==Y&&oe(),c.textureLighting!==void 0&&_!==t.textureLighting){for(let G of a)!L&&(G.voxelSource||G.voxelRenderer)?j(G):J(G);Z()}}function me(){return t}function ue(){let c=[];for(let b of a)c.push(b.handle);return c}function be(c){let b=c;for(;b;){if(b instanceof HTMLElement&&b.classList.contains("polycss-mesh")){for(let R of a)if(R.wrapper===b)return R.handle;return null}b=b.parentElement}return null}function xe(){let c=Array.from(a);for(let b of c)try{b.handle.dispose()}catch{}i.parentNode&&i.parentNode.removeChild(i)}return{add:de,setOptions:ge,destroy:xe,host:e,getOptions:me,meshes:ue,findMeshByElement:be}}var yn=require("@layoutit/polycss-core"),Ds=8e3;function Ke(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,yn.createIsometricCamera)(n),o=`${e.perspective??Ds}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function yt(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,yn.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var yo=require("@layoutit/polycss-core");var bt={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Xe(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 Je(e){return e===!0?-1:e===!1?1:e}function $e(){let e=[],n=[],t=[];function o(i){return i==="change"?e:i==="start"?n:t}function r(i){if(e.length===0)return;let a={type:"change",camera:i()},l=e.slice();for(let u of l)try{u(a)}catch(p){console.error("[polycss] controls 'change' listener threw:",p)}}function s(i,a){let l=i==="start"?n:t;if(l.length===0)return;let u={type:i,camera:a()},p=l.slice();for(let d of p)try{d(u)}catch(f){console.error(`[polycss] controls '${i}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function Ue(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 xt(e,n,t,o,r,s){let i=!1,a=null;return{onWheel:p=>{let d=n();if(!d.wheel||t())return;p.preventDefault();let f=p.deltaMode===1?16:p.deltaMode===2?100:1,g=p.deltaY*f;p.ctrlKey?g*=10:g*=3;let m=e.getOptions();if(d.dolly){let h=m.distance??0,y=Math.max(d.minDistance,Math.min(d.maxDistance,h+g*.05));e.setOptions({distance:y})}else{let h=Math.exp(-g*513e-6),y=m.zoom??1,v=Math.max(d.minZoom,Math.min(d.maxZoom,y*h));e.setOptions({zoom:v})}i||(i=!0,s("start",o)),r(o),a!==null&&clearTimeout(a),a=setTimeout(()=>{a=null,i=!1,s("end",o)},150)},teardown:()=>{a!==null&&(clearTimeout(a),a=null),i=!1}}}function vt(e,n,t,o,r,s,i){let a=null,l=0,u=g=>{if(a===null||o())return;let m=t();if(!m.animate){a=null;return}if(r())l=g;else{let h=Math.min(50,l?g-l:16.67);l=g;let y=m.animate.speed*(h/16.67),v=n.getOptions();if(m.animate.axis==="x"){let E=(((v.rotX??65)+y)%360+360)%360;n.setOptions({rotX:E})}else{let E=(((v.rotY??45)+y)%360+360)%360;n.setOptions({rotY:E})}i(s)}a=e.requestAnimationFrame(u)};return{start:()=>{a!==null||!t().animate||o()||(l=0,a=e.requestAnimationFrame(u))},stop:()=>{a!==null&&(e.cancelAnimationFrame(a),a=null)},isRunning:()=>a!==null}}function Pt(e,n={}){let t=Xe(bt,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},a=!1,l=!1,u=$e(),p=Ue(e),{changeListeners:d,startListeners:f,endListeners:g,listenerArray:m,emitChange:h,emitInteraction:y}=u,v=vt(r,e,()=>t,()=>l,()=>a,p,h),E=w=>{if(!(!t.drag||l)&&s===null&&w.isPrimary!==!1){w.preventDefault(),s=w.pointerId,i={x:w.clientX,y:w.clientY},o.style.cursor="grabbing";try{w.target.setPointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(a=!0),y("start",p)}},A=w=>{if(s===null||w.pointerId!==s||!t.drag||l)return;w.preventDefault();let I=w.clientX-i.x,F=w.clientY-i.y;i={x:w.clientX,y:w.clientY};let B=Je(t.invert),J=I/4*B,le=F/4*B,k=e.getOptions();if(w.shiftKey){let j=k.rotX??65,Z=k.rotY??45,se=Math.max(.01,k.zoom??1),oe=Math.cos(j*Math.PI/180),de=oe>=0?Math.max(.1,oe):Math.min(-.1,oe),ge=Math.cos(Z*Math.PI/180),me=Math.sin(Z*Math.PI/180),ue=se*yo.BASE_TILE,be=(I*me-F*ge/de)/ue,xe=-(I*ge+F*me/de)/ue,c=k.target??[0,0,0];e.setOptions({target:[c[0]+be,c[1]+xe,c[2]]})}else{let j=Math.max(0,Math.min(100,(k.rotX??65)-le)),Z=(((k.rotY??45)-J)%360+360)%360;e.setOptions({rotX:j,rotY:Z})}h(p)},x=w=>{if(s===w.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{w.target.releasePointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(a=!1),y("end",p)}},C=xt(e,()=>t,()=>l,p,h,y);function O(){o.addEventListener("pointerdown",E),o.addEventListener("pointermove",A),o.addEventListener("pointerup",x),o.addEventListener("pointercancel",x),o.addEventListener("wheel",C.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function M(){o.removeEventListener("pointerdown",E),o.removeEventListener("pointermove",A),o.removeEventListener("pointerup",x),o.removeEventListener("pointercancel",x),o.removeEventListener("wheel",C.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",C.teardown()}O(),v.start();function P(w){let I=!!t.animate;t=Xe(t,w),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let F=!!t.animate;I&&!F?v.stop():!I&&F&&v.start()}function X(){l&&(l=!1,O(),v.start())}function $(){l||(l=!0,M(),v.stop(),s=null,a=!1,C.teardown())}function W(){$(),d.length=0,f.length=0,g.length=0}function ne(w,I){let F=m(w);F.includes(I)||F.push(I)}function S(w,I){let F=m(w),B=F.indexOf(I);B>=0&&F.splice(B,1)}function U(w,I){return m(w).includes(I)}return{update:P,resume:X,pause:$,destroy:W,addEventListener:ne,removeEventListener:S,hasEventListener:U}}var bo=require("@layoutit/polycss-core");function Et(e,n={}){let t=Xe(bt,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},a=!1,l=!1,u=!1,p={x:0,y:0},d=$e(),f=Ue(e),{changeListeners:g,startListeners:m,endListeners:h,listenerArray:y,emitChange:v,emitInteraction:E}=d,A=vt(r,e,()=>t,()=>l,()=>a,f,v),x=k=>{if(!(!t.drag||l)&&s===null&&k.isPrimary!==!1){k.preventDefault(),s=k.pointerId,i={x:k.clientX,y:k.clientY},o.style.cursor="grabbing";try{k.target.setPointerCapture(k.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(a=!0),E("start",f)}},C=k=>{if(s===null||k.pointerId!==s||!t.drag||l)return;k.preventDefault();let j=k.clientX-i.x,Z=k.clientY-i.y;i={x:k.clientX,y:k.clientY};let se=e.getOptions();if(k.shiftKey){let oe=Je(t.invert),de=j/4*oe,ge=Z/4*oe,me=Math.max(0,Math.min(100,(se.rotX??65)-ge)),ue=(((se.rotY??45)-de)%360+360)%360;e.setOptions({rotX:me,rotY:ue})}else{let oe=se.rotX??65,de=se.rotY??45,ge=Math.max(.01,se.zoom??1),me=Math.cos(oe*Math.PI/180),ue=me>=0?Math.max(.1,me):Math.min(-.1,me),be=Math.cos(de*Math.PI/180),xe=Math.sin(de*Math.PI/180),c=ge*bo.BASE_TILE,b=(j*xe-Z*be/ue)/c,R=-(j*be+Z*xe/ue)/c,_=se.target??[0,0,0];e.setOptions({target:[_[0]+b,_[1]+R,_[2]]})}v(f)},O=k=>{if(s===k.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{k.target.releasePointerCapture(k.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(a=!1),E("end",f)}},M=k=>{k.preventDefault()},P=k=>{k.button===2&&(u=!0,p={x:k.clientX,y:k.clientY},t.animate&&t.animate.pauseOnInteraction&&(a=!0),E("start",f))},X=k=>{if(!u||!t.drag)return;let j=k.clientX-p.x,Z=k.clientY-p.y;p={x:k.clientX,y:k.clientY};let se=Je(t.invert),oe=j/4*se,de=Z/4*se,ge=e.getOptions(),me=Math.max(0,Math.min(100,(ge.rotX??65)-de)),ue=(((ge.rotY??45)-oe)%360+360)%360;e.setOptions({rotX:me,rotY:ue}),v(f)},$=k=>{k.button===2&&u&&(u=!1,E("end",f))},W=xt(e,()=>t,()=>l,f,v,E);function ne(){o.addEventListener("pointerdown",x),o.addEventListener("pointermove",C),o.addEventListener("pointerup",O),o.addEventListener("pointercancel",O),o.addEventListener("wheel",W.onWheel,{passive:!1}),o.addEventListener("contextmenu",M),o.addEventListener("mousedown",P),o.addEventListener("mousemove",X),o.addEventListener("mouseup",$),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function S(){o.removeEventListener("pointerdown",x),o.removeEventListener("pointermove",C),o.removeEventListener("pointerup",O),o.removeEventListener("pointercancel",O),o.removeEventListener("wheel",W.onWheel),o.removeEventListener("contextmenu",M),o.removeEventListener("mousedown",P),o.removeEventListener("mousemove",X),o.removeEventListener("mouseup",$),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",W.teardown()}ne(),A.start();function U(k){let j=!!t.animate;t=Xe(t,k),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let Z=!!t.animate;j&&!Z?A.stop():!j&&Z&&A.start()}function w(){l&&(l=!1,ne(),A.start())}function I(){l||(l=!0,S(),A.stop(),s=null,a=!1,u=!1,W.teardown())}function F(){I(),g.length=0,m.length=0,h.length=0}function B(k,j){let Z=y(k);Z.includes(j)||Z.push(j)}function J(k,j){let Z=y(k),se=Z.indexOf(j);se>=0&&Z.splice(se,1)}function le(k,j){return y(k).includes(j)}return{update:U,resume:w,pause:I,destroy:F,addEventListener:B,removeEventListener:J,hasEventListener:le}}var Mo=require("@layoutit/polycss-core");var Hs={enabled:!0,lookEnabled:!0,moveEnabled:!0,jumpEnabled:!0,crouchEnabled:!0,lookSensitivity:.15,invertY:!1,moveSpeed:5,jumpVelocity:7,gravity:18,eyeHeight:1.7,crouchHeight:1,groundZ:0,minPitch:5,maxPitch:175};function xo(e,n){return{enabled:n.enabled??e.enabled,lookEnabled:n.lookEnabled??e.lookEnabled,moveEnabled:n.moveEnabled??e.moveEnabled,jumpEnabled:n.jumpEnabled??e.jumpEnabled,crouchEnabled:n.crouchEnabled??e.crouchEnabled,lookSensitivity:n.lookSensitivity??e.lookSensitivity,invertY:n.invertY??e.invertY,moveSpeed:n.moveSpeed??e.moveSpeed,jumpVelocity:n.jumpVelocity??e.jumpVelocity,gravity:n.gravity??e.gravity,eyeHeight:n.eyeHeight??e.eyeHeight,crouchHeight:n.crouchHeight??e.crouchHeight,groundZ:n.groundZ??e.groundZ,minPitch:n.minPitch??e.minPitch,maxPitch:n.maxPitch??e.maxPitch}}var vo=new Set(["KeyW","ArrowUp"]),Po=new Set(["KeyS","ArrowDown"]),Eo=new Set(["KeyA","ArrowLeft"]),Co=new Set(["KeyD","ArrowRight"]),Ao=new Set(["Space"]),bn=new Set(["ControlLeft","ControlRight"]);function So(e,n={}){let t=xo(Hs,n),o=e.host,r=o.ownerDocument??document,s=r.defaultView??globalThis,i=$e(),a=Ue(e),{changeListeners:l,startListeners:u,endListeners:p,listenerArray:d,emitChange:f,emitInteraction:g}=i,m=new Set,h=!1,y=!1,v=0,E=0,A=!1,x=[0,0,t.groundZ+t.eyeHeight];function C(L,N){let z=L*Math.PI/180,G=N*Math.PI/180;return[-Math.sin(z)*Math.cos(G),-Math.sin(z)*Math.sin(G),-Math.cos(z)]}function O(){let L=e.getOptions().perspective;return(typeof L=="number"&&L>0?L:2e3)/Mo.BASE_TILE}function M(){let L=e.getOptions(),N=C(L.rotX??90,L.rotY??0),z=O();return[x[0]+N[0]*z,x[1]+N[1]*z,x[2]+N[2]*z]}function P(){let L=M();e.setOptions({target:L})}function X(){let N=e.getOptions().target??[0,0,0];x=[N[0],N[1],t.groundZ+t.eyeHeight],P()}let $=()=>{if(!(!t.enabled||!t.lookEnabled||y||h))try{o.requestPointerLock()}catch{}},W=()=>{let L=r.pointerLockElement===o;L!==h&&(h=L,h?(A=!0,g("start",a)):A&&(A=!1,g("end",a)))},ne=L=>{if(!h||!t.enabled||!t.lookEnabled||y)return;let N=L.movementX??0,z=L.movementY??0;if(N===0&&z===0)return;let G=e.getOptions(),K=t.lookSensitivity,T=t.invertY?-1:1,Q=(((G.rotY??0)-N*K)%360+360)%360,H=(G.rotX??90)-z*K*T;H<t.minPitch?H=t.minPitch:H>t.maxPitch&&(H=t.maxPitch);let q=C(H,Q),re=O(),ve=[x[0]+q[0]*re,x[1]+q[1]*re,x[2]+q[2]*re];e.setOptions({rotX:H,rotY:Q,target:ve}),f(a)},S=L=>vo.has(L)||Po.has(L)||Eo.has(L)||Co.has(L)||Ao.has(L)||bn.has(L),U=L=>{if(!(!t.enabled||y)&&S(L.code)&&!(!h&&!t.moveEnabled)){if(Ao.has(L.code)){if(!t.jumpEnabled)return;L.preventDefault(),!m.has(L.code)&&v===0&&E===0&&(v=t.jumpVelocity),m.add(L.code);return}bn.has(L.code)&&!t.crouchEnabled||!t.moveEnabled&&!bn.has(L.code)||(L.preventDefault(),m.add(L.code))}},w=L=>{S(L.code)&&m.delete(L.code)},I=()=>{m.clear()},F=null,B=0,J=.05,le=L=>{if(F===null||y)return;let N=Math.min(J,B?(L-B)/1e3:.0167);if(B=L,t.enabled){let z=!1,G=e.getOptions();if(t.moveEnabled){let H=0,q=0;for(let re of m)vo.has(re)?H+=1:Po.has(re)?H-=1:Co.has(re)?q+=1:Eo.has(re)&&(q-=1);if(H!==0||q!==0){let ve=(G.rotY??0)*Math.PI/180,Me=-Math.cos(ve),Ie=-Math.sin(ve),We=-Math.sin(ve),Nt=Math.cos(ve),nt=Math.hypot(H,q)||1,ot=t.moveSpeed*N;x[0]+=(Me*H+We*q)/nt*ot,x[1]+=(Ie*H+Nt*q)/nt*ot,z=!0}}let T=t.crouchEnabled&&(m.has("ControlLeft")||m.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(v!==0||E>0)?(v-=t.gravity*N,E+=v*N,E<=0&&(E=0,v=0)):t.jumpEnabled||(E=0,v=0);let Q=t.groundZ+T+E;if(Math.abs(x[2]-Q)>1e-4&&(x[2]=Q,z=!0),z){let H=M();e.setOptions({target:H}),f(a)}}F=s.requestAnimationFrame(le)};function k(){F!==null||y||(B=0,F=s.requestAnimationFrame(le))}function j(){F!==null&&(s.cancelAnimationFrame(F),F=null)}function Z(){let N=o.ownerDocument?.defaultView?.getComputedStyle(o).perspective??"",z=parseFloat(N),G=Number.isFinite(z)&&z>0?z:2e3;o.style.setProperty("--polycss-fpv-perspective",`${G}px`),o.classList.add("polycss-fpv-host")}function se(){o.classList.remove("polycss-fpv-host"),o.style.removeProperty("--polycss-fpv-perspective")}function oe(){o.addEventListener("click",$),r.addEventListener("pointerlockchange",W),r.addEventListener("mousemove",ne),s.addEventListener("keydown",U),s.addEventListener("keyup",w),s.addEventListener("blur",I),o.style.cursor=t.lookEnabled?"crosshair":"",Z()}function de(){if(o.removeEventListener("click",$),r.removeEventListener("pointerlockchange",W),r.removeEventListener("mousemove",ne),s.removeEventListener("keydown",U),s.removeEventListener("keyup",w),s.removeEventListener("blur",I),o.style.cursor="",m.clear(),h)try{r.exitPointerLock()}catch{}se()}X(),oe(),k();function ge(L){let N=t.eyeHeight,z=t.groundZ;t=xo(t,L),y||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==N||t.groundZ!==z)&&(x[2]=t.groundZ+t.eyeHeight,P(),f(a))}function me(){y&&(y=!1,oe(),k())}function ue(){y||(y=!0,de(),j(),A&&(A=!1,g("end",a)))}function be(){ue(),l.length=0,u.length=0,p.length=0}function xe(){if(!(!t.enabled||!t.lookEnabled||y))try{o.requestPointerLock()}catch{}}function c(){if(h)try{r.exitPointerLock()}catch{}}function b(){return h}function R(L,N){let z=d(L);z.includes(N)||z.push(N)}function _(L,N){let z=d(L),G=z.indexOf(N);G>=0&&z.splice(G,1)}function V(L,N){return d(L).includes(N)}function D(){return[x[0],x[1],x[2]]}function Y(L){x[0]=L[0],x[1]=L[1],x[2]=L[2],P(),f(a)}return{update:ge,resume:me,pause:ue,destroy:be,lock:xe,unlock:c,isLocked:b,getOrigin:D,setOrigin:Y,addEventListener:R,removeEventListener:_,hasEventListener:V}}function Is(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 Ct(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let h of o)try{h(t)}catch(y){console.error("[polycss/createSelect] onChange threw:",y)}}function s(m){t=m,r()}function i(m){n.multiple?t.includes(m)||(t=[...t,m]):t=[m],r()}function a(m){t.includes(m)&&(t=t.filter(h=>h!==m),r())}function l(m){t.includes(m)?t=t.filter(h=>h!==m):n.multiple?t=[...t,m]:t=[m],r()}function u(){t.length!==0&&(t=[],r())}function p(m){return t.includes(m)}function d(m,h){for(let y of e.meshes())if(!y.element.classList.contains("polycss-transform-gizmo")&&Is(y.element,m,h))return y;return null}let f=m=>{let h=m.target;if(h?.closest(".polycss-transform-gizmo"))return;let y=e.findMeshByElement(h)??d(m.clientX,m.clientY);if(!y){n.onPointerMissed&&n.onPointerMissed(m),n.clearOnMiss!==!1&&u();return}n.multiple&&(m.shiftKey||m.metaKey||m.ctrlKey)?l(y):t.length===1&&t[0]===y?u():s([y])};e.host.addEventListener("click",f);function g(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:s,add:i,remove:a,toggle:l,clear:u,has:p,destroy:g}}var Pe=require("@layoutit/polycss-core"),Mt="#ff3653",St="#8adb00",Lt="#2c8fff",Ge=50,Lo=60,Vs=.6,Fs=.0125,zs=.15,Bs=.04,Ns=1,wo=.02,xn=1.04,Ys=.1,Xs=.25,Ro=1e-4,$s=.6,Us=.8,Gs=1,et={0:1,1:0,2:2},To=[{cssAxis:0,sign:1,key:"x",color:Mt},{cssAxis:0,sign:-1,key:"-x",color:Mt},{cssAxis:1,sign:1,key:"y",color:St},{cssAxis:1,sign:-1,key:"-y",color:St},{cssAxis:2,sign:1,key:"z",color:Lt},{cssAxis:2,sign:-1,key:"-z",color:Lt}],_o=[{cssAxis:0,key:"x",color:Mt},{cssAxis:1,key:"y",color:St},{cssAxis:2,key:"z",color:Lt}],ko=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:Lt},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:St},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:Mt}];function vn(e,n,t,o){let r=t*Math.PI/180,s=o*Math.PI/180,i=[0,0,0];i[e]=n;let a=i[0]*Math.cos(s)-i[1]*Math.sin(s),l=i[0]*Math.sin(s)+i[1]*Math.cos(s),u=i[2];return l*Math.sin(r)+u*Math.cos(r)<0}function js(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 wt(e,n){return!n||n<=0?e:Math.round(e/n)*n}function Ws(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 a of e)for(let l of a.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*Ge,(n+r)/2*Ge,(o+i)/2*Ge]:[0,0,0]}function Pn(e){if(e.length===0)return Lo;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 u of l.vertices)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*Ge*Vs:Lo}function At(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 Zs(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:a,translationSnap:l,onAxisDelta:u,onMouseDown:p,onMouseUp:d,onDraggingChanged:f}=e,g=o,m=[0,0,0];m[n]=t;let h=r.ownerDocument.createElement("div");h.style.position="absolute",h.style.left="0",h.style.top="0",h.style.width="0",h.style.height="0",h.style.transform=`translate3d(${m[0]*g}px, ${m[1]*g}px, ${m[2]*g}px)`,r.appendChild(h);let y=r.getBoundingClientRect(),v=h.getBoundingClientRect();r.removeChild(h);let E=(v.left-y.left)/g,A=(v.top-y.top)/g,x=E*E+A*A;if(x<Ro)return;p?.(),f?.(!0);let C=M=>{let P=M.clientX-i,X=M.clientY-a,$=(P*E+X*A)/x;$=wt($,l),u($,m)},O=()=>{window.removeEventListener("pointermove",C),window.removeEventListener("pointerup",O),window.removeEventListener("pointercancel",O);let M=P=>{P.stopPropagation(),P.stopImmediatePropagation()};window.addEventListener("click",M,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",M,!0),0),d?.(),f?.(!1)};window.addEventListener("pointermove",C),window.addEventListener("pointerup",O),window.addEventListener("pointercancel",O)}function qs(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:s,startClientY:i,translationSnap:a,onPlaneDelta:l,onMouseDown:u,onMouseUp:p,onDraggingChanged:d}=e,f=[0,0,0];f[n]=1;let g=[0,0,0];g[t]=1;function m(x){let C=r.ownerDocument.createElement("div");C.style.position="absolute",C.style.left="0",C.style.top="0",C.style.width="0",C.style.height="0",C.style.transform=`translate3d(${x[0]*o}px, ${x[1]*o}px, ${x[2]*o}px)`,r.appendChild(C);let O=r.getBoundingClientRect(),M=C.getBoundingClientRect();return r.removeChild(C),{x:(M.left-O.left)/o,y:(M.top-O.top)/o}}let h=m(f),y=m(g),v=h.x*y.y-y.x*h.y;if(Math.abs(v)<Ro)return;u?.(),d?.(!0);let E=x=>{let C=x.clientX-s,O=x.clientY-i,M=(y.y*C-y.x*O)/v,P=(-h.y*C+h.x*O)/v;M=wt(M,a),P=wt(P,a),l(M,P,f,g)},A=()=>{window.removeEventListener("pointermove",E),window.removeEventListener("pointerup",A),window.removeEventListener("pointercancel",A);let x=C=>{C.stopPropagation(),C.stopImmediatePropagation()};window.addEventListener("click",x,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",x,!0),0),p?.(),d?.(!1)};window.addEventListener("pointermove",E),window.addEventListener("pointerup",A),window.addEventListener("pointercancel",A)}function Qs(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:a,onMouseDown:l,onMouseUp:u,onDraggingChanged:p}=e,d=t.getBoundingClientRect(),f=d.left,g=d.top,m=Math.atan2(s-g,r-f),h=0;l?.(),p?.(!0);let y=E=>{let A=Math.atan2(E.clientY-g,E.clientX-f),x=A-m;x>Math.PI?x-=2*Math.PI:x<-Math.PI&&(x+=2*Math.PI),h+=x,m=A;let C=h*180/Math.PI;C=wt(C,i),a(C)},v=()=>{window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",v),window.removeEventListener("pointercancel",v);let E=A=>{A.stopPropagation(),A.stopImmediatePropagation()};window.addEventListener("click",E,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",E,!0),0),u?.(),p?.(!1)};window.addEventListener("pointermove",y),window.addEventListener("pointerup",v),window.addEventListener("pointercancel",v)}function Tt(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,a=null,l=null,u=[0,0,0];function p(){if(!t)return[0,0,0];let S=t.transform.position??[0,0,0];return[S[0]+u[0],S[1]+u[1],S[2]+u[2]]}function d(S){return l===S?Gs:a===S?Us:$s}function f(){for(let[S,U]of i){let w=g(U.spec,d(S));U.handle.setPolygons(w,{recomputeAutoCenter:!1})}}function g(S,U){let I=Pn(t?.polygons??[])*r,F=I/Ge,B=js(S.color,U);if(S.kind==="arrow"){let k=e.getOptions(),j=vn(S.cssAxis,S.sign,k.rotX??65,k.rotY??45);return(0,Pe.arrowPolygons)({axis:et[S.cssAxis],sign:S.sign,shaftLength:F,shaftHalfThickness:F*Fs,headLength:F*zs,headHalfThickness:F*Bs,color:B,shaft:!j})}if(S.kind==="plane"){let k=e.getOptions(),j=k.rotX??65,Z=k.rotY??45,se=et[S.perpAxis],oe=(se+1)%3,de=(se+2)%3,ge=et[oe],me=et[de],ue=vn(ge,1,j,Z)?-1:1,be=vn(me,1,j,Z)?-1:1,xe=F*Xs;return(0,Pe.planePolygons)({axis:se,size:F*Ys,offset:[ue*xe,be*xe],color:B})}let le=I*Ns/Ge*xn;return(0,Pe.ringQuadPolygons)({axis:et[S.cssAxis],outerRadius:le,color:B})}function m(S){return S.kind==="arrow"?"polycss-transform-arrow":S.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function h(){if(o==="translate"){let S=To.map(w=>({kind:"arrow",key:w.key,cssAxis:w.cssAxis,sign:w.sign,color:w.color})),U=ko.map(w=>({kind:"plane",key:w.key,perpAxis:w.perpAxis,axisA:w.axisA,axisB:w.axisB,color:w.color}));return[...S,...U]}return o==="rotate"?_o.map(S=>({kind:"ring",key:S.key,cssAxis:S.cssAxis,color:S.color})):[]}function y(){if(v(),!t)return;let S={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};function U(I){if(I.kind==="arrow"){let J=I.key.replace("-","")[0];return S[J]}if(I.kind==="ring")return S[I.key];let F=["x","y","z"][I.axisA],B=["x","y","z"][I.axisB];return S[F]&&S[B]}let w=p();for(let I of h()){if(!U(I))continue;let F=g(I,d(I.key)),B=e.add({polygons:F,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${I.key}`,position:w}),J=m(I);if(B.element.classList.add("polycss-transform-gizmo",J,`${J}--${I.key}`),I.kind==="ring"){let le=(1-wo)/xn,k=(1+wo)/xn;B.element.style.setProperty("--ring-inner-ratio",`${le}`),B.element.style.setProperty("--ring-outer-ratio",`${k}`)}i.set(I.key,{handle:B,spec:I})}}function v(){for(let{handle:S}of i.values())S.remove();i.clear(),a=null,l=null}function E(){if(!t)return;let S=p();for(let{handle:U}of i.values())U.setTransform({position:S})}function A(){t&&(i.size===0?y():E())}function x(S){if(t=S,!S){u=[0,0,0],v();return}u=Ws(S.polygons),v(),y()}function C(){x(null)}function O(S){S!==o&&(o=S,t&&(v(),y()))}function M(S,U,w){if(!t||!P)return;let I=[P[0]+U*w[0],P[1]+U*w[1],P[2]+U*w[2]];t.setTransform({position:I}),E(),s.onObjectChange?.({object:t,position:I}),s.onChange?.()}let P=null,X=null,$=S=>{if(!t||s.enabled===!1)return;let U={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate"){for(let w of ko){let I=["x","y","z"][w.axisA],F=["x","y","z"][w.axisB];if(!U[I]||!U[F])continue;let B=i.get(w.key);if(B&&At(B.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),l=w.key,f(),P=(t.transform.position??[0,0,0]).slice(),qs({axisA:w.axisA,axisB:w.axisB,probeDistanceCss:Pn(t.polygons)*r,wrapper:B.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,translationSnap:s.translationSnap??null,onPlaneDelta:(J,le,k,j)=>{if(!t||!P)return;let Z=[P[0]+J*k[0]+le*j[0],P[1]+J*k[1]+le*j[1],P[2]+J*k[2]+le*j[2]];t.setTransform({position:Z}),E(),s.onObjectChange?.({object:t,position:Z}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:J=>{J||(l=null,P=null,f()),s.onDraggingChanged?.(J)}});return}}for(let w of To){let I=w.key.replace("-","")[0];if(!U[I])continue;let F=i.get(w.key);if(F&&At(F.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),l=w.key,f(),P=(t.transform.position??[0,0,0]).slice(),Zs({cssAxis:w.cssAxis,sign:w.sign,shaftLengthCss:Pn(t.polygons)*r,wrapper:F.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(B,J)=>M(w,B,J),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:B=>{B||(l=null,P=null,f()),s.onDraggingChanged?.(B)}});return}}}else if(o==="rotate")for(let w of _o){if(!U[w.key])continue;let I=i.get(w.key);if(I&&At(I.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),l=w.key,f(),X=(t.transform.rotation??[0,0,0]).slice(),Qs({cssAxis:w.cssAxis,wrapper:I.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:F=>{if(!t||!X)return;let B=w.cssAxis===0?-1:1,J=[0,0,0];J[w.cssAxis]=1;let le=F*B*Math.PI/180,k=(0,Pe.quatFromEulerXYZ)(X),j=(0,Pe.quatFromAxisAngle)(J,le),Z=(0,Pe.eulerXYZFromQuat)((0,Pe.quatMultiply)(j,k));t.setTransform({rotation:Z}),s.onObjectChange?.({object:t,rotation:Z}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:F=>{F||(l=null,X=null,f(),t?.rebakeAtlas()),s.onDraggingChanged?.(F)}});return}}};e.host.addEventListener("pointerdown",$,{capture:!0});let W=S=>{if(!t||l||s.enabled===!1)return;let U=null;for(let[w,I]of i)if(At(I.handle.element,S.clientX,S.clientY)){U=w;break}U!==a&&(a=U,f())};e.host.addEventListener("pointermove",W);function ne(){e.host.removeEventListener("pointerdown",$,{capture:!0}),e.host.removeEventListener("pointermove",W),v()}return{attach:x,detach:C,setMode:O,update:A,destroy:ne}}var Ks=typeof HTMLElement<"u"?HTMLElement:class{},Js=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function He(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function ei(e){return e==="false"?!1:He(e)}function ti(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 ni(e){if(e==="baked"||e==="dynamic")return e}function oi(e){return e==="auto"?"auto":He(e)}var Ce=class extends Ks{constructor(){super(...arguments);this._scene=null}static get observedAttributes(){return[...Js]}getScene(){return this._scene}_readOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={},s=ei(this.getAttribute("perspective"));s!==void 0&&(r.perspective=s);let i=He(this.getAttribute("rot-x"));i!==void 0&&(r.rotX=i);let a=He(this.getAttribute("rot-y"));a!==void 0&&(r.rotY=a);let l=He(this.getAttribute("zoom"));l!==void 0&&(r.zoom=l),r.textureLighting=ni(this.getAttribute("texture-lighting"))??"baked";let u=oi(this.getAttribute("texture-quality"));return u!==void 0&&(r.textureQuality=u),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=ti(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=He(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=He(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=gt(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 _t=require("@layoutit/polycss-core"),ri=typeof HTMLElement<"u"?HTMLElement:class{},si=["src","mtl","position","scale","rotation","auto-center"];function tt(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 Oo(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return tt(e)}}function ii(e){return e.closest("poly-scene")??null}function ai(e){if(e.length===0)return e;let n=(0,_t.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(a=>({...a,vertices:a.vertices.map(s)}))}:null}))}var je=class extends ri{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...si]}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:tt(this.getAttribute("position")),scale:Oo(this.getAttribute("scale")),rotation:tt(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=ii(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,i;try{i=await(0,_t.loadMesh)(t,s?{mtlUrl:s}:void 0)}catch(u){this.dispatchEvent(new CustomEvent("polycss:error",{detail:u,bubbles:!0}));return}if(r!==this._loadToken){try{i.dispose()}catch{}return}let a=o.getScene();if(!a){try{i.dispose()}catch{}return}this.hasAttribute("auto-center")&&(i={...i,polygons:ai(i.polygons)}),this._parseResult=i,this._handle=a.add(i,{position:tt(this.getAttribute("position")),scale:Oo(this.getAttribute("scale")),rotation:tt(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var li=typeof HTMLElement<"u"?HTMLElement:class{},ci=["vertices","color","texture","uvs","position","scale","rotation"];function Do(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function En(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 ui(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return En(e)}}function di(e){return e.closest("poly-scene")??null}var kt=class extends li{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...ci]}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=di(this);if(!t)return;let o=t.getScene();if(!o)return;let r=Do(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,a=Do(this.getAttribute("uvs"))??void 0,l={};for(let d of Array.from(this.attributes))d.name.startsWith("data-")&&(l[d.name.slice(5)]=d.value);let p={polygons:[{vertices:r,...s!==void 0?{color:s}:{},...i!==void 0?{texture:i}:{},...a!==void 0?{uvs:a}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(p,{position:En(this.getAttribute("position")),scale:ui(this.getAttribute("scale")),rotation:En(this.getAttribute("rotation"))})}};function ae(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Rt(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 _e(e){if(e!==null)return!(e==="false"||e==="0")}function Ot(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 Dt(e){if(e==="x"||e==="y")return e}var mi=typeof HTMLElement<"u"?HTMLElement:class{},pi=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Ht=class extends mi{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...pi]}_readAnimate(){let t=ae(this.getAttribute("animate-speed")),o=Dt(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:_e(r)}:{}}}_readOptions(){let t={},o=_e(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=_e(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ae(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ae(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let a=Ot(this.getAttribute("invert"));a!==void 0&&(t.invert=a);let l=ae(this.getAttribute("zoom-min")),u=ae(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ce)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=Pt(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 fi=typeof HTMLElement<"u"?HTMLElement:class{},hi=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],It=class extends fi{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...hi]}_readAnimate(){let t=ae(this.getAttribute("animate-speed")),o=Dt(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:_e(r)}:{}}}_readOptions(){let t={},o=_e(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=_e(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ae(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ae(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let a=Ot(this.getAttribute("invert"));a!==void 0&&(t.invert=a);let l=ae(this.getAttribute("zoom-min")),u=ae(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ce)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=Et(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 gi=typeof HTMLElement<"u"?HTMLElement:class{},yi=["perspective","zoom","rot-x","rot-y","target","distance"],Vt=class extends gi{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...yi]}getCamera(){return this._camera}_readOptions(){return{perspective:ae(this.getAttribute("perspective")),zoom:ae(this.getAttribute("zoom")),rotX:ae(this.getAttribute("rot-x")),rotY:ae(this.getAttribute("rot-y")),target:Rt(this.getAttribute("target")),distance:ae(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Ke(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=Ke(s),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var bi=typeof HTMLElement<"u"?HTMLElement:class{},xi=["zoom","rot-x","rot-y","target","distance"],Ft=class extends bi{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...xi]}getCamera(){return this._camera}_readOptions(){return{zoom:ae(this.getAttribute("zoom")),rotX:ae(this.getAttribute("rot-x")),rotY:ae(this.getAttribute("rot-y")),target:Rt(this.getAttribute("target")),distance:ae(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=yt(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 vi=typeof HTMLElement<"u"?HTMLElement:class{},Pi=["mode","target","size","enabled"];function Ho(e){if(e==="translate"||e==="rotate")return e}var zt=class extends vi{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Pi]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ce)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 je?r:null}_readOptions(){let t={},o=Ho(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=ae(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=Tt(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=Ho(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};var Ei=typeof HTMLElement<"u"?HTMLElement:class{},Ci=["multiple","clear-on-miss"],Bt=class extends Ei{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Ci]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ce)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=Ct(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())}};he(fe,require("@layoutit/polycss-core"),module.exports);0&&(module.exports={PolyMapControlsElement,PolyMeshElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPolygonElement,PolySceneElement,PolySelectElement,PolyTransformControlsElement,createPolyFirstPersonControls,createPolyMapControls,createPolyOrbitControls,createPolyOrthographicCamera,createPolyPerspectiveCamera,createPolyScene,createSelect,createTransformControls,injectPolyBaseStyles,...require("@layoutit/polycss-core")});
606
+ `),n.join(`
607
+ `)}function fc(e){let n=[oc];if(e.hasScene&&n.push(`
608
+ .polycss-scene,
609
+ .polycss-scene *,
610
+ .polycss-scene *::before,
611
+ .polycss-scene *::after {
612
+ box-sizing: border-box;
613
+ }
614
+
615
+ .polycss-scene {
616
+ position: absolute;
617
+ top: 50%;
618
+ left: 50%;
619
+ width: 0;
620
+ height: 0;
621
+ transform-style: preserve-3d;
622
+ }
623
+ `),e.hasCamera&&n.push(`
624
+ .polycss-camera {
625
+ position: relative;
626
+ display: block;
627
+ width: 100%;
628
+ height: 100%;
629
+ }
630
+ `),e.hasFpvHost&&n.push(`
631
+ .polycss-fpv-host {
632
+ perspective: var(--polycss-fpv-perspective, 2000px) !important;
633
+ transform-style: preserve-3d !important;
634
+ }
635
+ `),e.hasMesh&&n.push(`
636
+ .polycss-mesh {
637
+ position: absolute;
638
+ transform-style: preserve-3d;
639
+ }
640
+ `),e.hasBucket&&n.push(`
641
+ .polycss-bucket {
642
+ position: absolute;
643
+ transform-style: preserve-3d;
644
+ }
645
+ `),e.leafTags.length>0&&n.push(`
646
+ ${An(e.leafTags)} {
647
+ position: absolute;
648
+ display: block;
649
+ transform-origin: 0 0;
650
+ transform-style: preserve-3d;
651
+ margin: 0;
652
+ padding: 0;
653
+ font: inherit;
654
+ font-weight: normal;
655
+ font-style: normal;
656
+ line-height: 0;
657
+ text-decoration: none;
658
+ backface-visibility: hidden;
659
+ background-repeat: no-repeat;
660
+ }
661
+ `),e.solidLeafTags.length>0&&!e.hasDynamicLighting&&n.push(`
662
+ ${An(e.solidLeafTags)} {
663
+ color: currentColor;
664
+ }
665
+ `),e.leafTags.includes("b")&&n.push(`
666
+ .polycss-scene b {
667
+ background: currentColor;
668
+ width: 64px;
669
+ height: 64px;
670
+ }
671
+ `),e.hasVoxelMesh&&n.push(`
672
+ .polycss-mesh.polycss-voxel-mesh > .polycss-voxel-face {
673
+ position: absolute;
674
+ display: block;
675
+ top: 0;
676
+ left: 0;
677
+ width: 0;
678
+ height: 0;
679
+ transform-style: preserve-3d;
680
+ transform-origin: 0 0;
681
+ margin: 0;
682
+ padding: 0;
683
+ font: inherit;
684
+ line-height: 0;
685
+ pointer-events: none;
686
+ }
687
+
688
+ .polycss-mesh.polycss-voxel-mesh > .polycss-voxel-face > b {
689
+ top: 0;
690
+ left: 0;
691
+ width: var(--polycss-voxel-primitive, 1px);
692
+ height: var(--polycss-voxel-primitive, 1px);
693
+ backface-visibility: visible;
694
+ pointer-events: none;
695
+ }
696
+ `),e.leafTags.includes("i")&&n.push(`
697
+ .polycss-scene i {
698
+ width: 16px;
699
+ height: 16px;
700
+ border-color: currentColor;
701
+ }
702
+ `),e.leafTags.includes("s")&&n.push(`
703
+ .polycss-scene s {
704
+ width: 64px;
705
+ height: 64px;
706
+ }
707
+ `),e.leafTags.includes("u")&&n.push(`
708
+ .polycss-scene u {
709
+ width: 0;
710
+ height: 0;
711
+ background: transparent;
712
+ box-sizing: content-box;
713
+ border: 0 solid transparent;
714
+ border-color: transparent transparent currentColor transparent;
715
+ border-width: 0 16px 32px 16px;
716
+ }
717
+
718
+ @supports (corner-top-left-shape: bevel) and (corner-top-right-shape: bevel) {
719
+ .polycss-scene > u,
720
+ .polycss-mesh > u,
721
+ .polycss-bucket > u {
722
+ border-width: 0;
723
+ width: 32px;
724
+ height: 32px;
725
+ background-color: currentColor;
726
+ border-top-left-radius: 50% 100%;
727
+ border-top-right-radius: 50% 100%;
728
+ corner-top-left-shape: bevel;
729
+ corner-top-right-shape: bevel;
730
+ }
731
+
732
+ .polycss-scene > u.polycss-corner-shape-solid,
733
+ .polycss-mesh > u.polycss-corner-shape-solid,
734
+ .polycss-bucket > u.polycss-corner-shape-solid {
735
+ width: 16px;
736
+ height: 16px;
737
+ box-sizing: border-box;
738
+ border: 0;
739
+ background: currentColor;
740
+ border-radius: 0;
741
+ corner-top-left-shape: initial;
742
+ corner-top-right-shape: initial;
743
+ corner-bottom-right-shape: initial;
744
+ corner-bottom-left-shape: initial;
745
+ }
746
+ }
747
+ `),e.hasQ&&n.push(`
748
+ .polycss-scene q {
749
+ position: absolute;
750
+ display: block;
751
+ transform-origin: 0 0;
752
+ transform-style: preserve-3d;
753
+ margin: 0;
754
+ padding: 0;
755
+ font: inherit;
756
+ font-weight: normal;
757
+ font-style: normal;
758
+ line-height: 0;
759
+ text-decoration: none;
760
+ backface-visibility: visible;
761
+ border-color: currentColor;
762
+ pointer-events: none;
763
+ }
764
+
765
+ .polycss-scene q::before,
766
+ .polycss-scene q::after {
767
+ content: none;
768
+ }
769
+ `),e.hasTransformGizmo){let t=e.leafTags.length>0?e.leafTags:Lr;n.push(`
770
+ ${An(t,".polycss-mesh.polycss-transform-gizmo ")} {
771
+ backface-visibility: visible;
772
+ transition: color 150ms ease-out, border-color 150ms ease-out, background-color 150ms ease-out;
773
+ }
774
+ `)}if(e.hasTransformRing){let t=e.leafTags.length>0?e.leafTags:Lr;n.push(`
775
+ ${An(t,".polycss-mesh.polycss-transform-ring ")} {
776
+ --ring-inner-r: calc(var(--ring-inner-ratio, 0.92) * 50%);
777
+ --ring-outer-r: calc(var(--ring-outer-ratio, 1) * 50%);
778
+ -webkit-mask: radial-gradient(circle at 50% 50%,
779
+ transparent 0%,
780
+ transparent var(--ring-inner-r),
781
+ black var(--ring-inner-r),
782
+ black var(--ring-outer-r),
783
+ transparent var(--ring-outer-r));
784
+ mask: radial-gradient(circle at 50% 50%,
785
+ transparent 0%,
786
+ transparent var(--ring-inner-r),
787
+ black var(--ring-inner-r),
788
+ black var(--ring-outer-r),
789
+ transparent var(--ring-outer-r));
790
+ }
791
+ `)}return e.hasDynamicLighting&&n.push(mc(e)),n.map(t=>t.trim()).filter(Boolean).join(`
792
+
793
+ `)}function Rr(e){let n=e.style;return n&&typeof n.getPropertyValue=="function"?n:null}function gi(e){let n=e.getAttribute("style");n!==null&&n.trim()===""&&e.removeAttribute("style")}function hc(e,n){let t=e;for(;t;){let o=Rr(t)?.getPropertyValue(n).trim();if(o)return o;t=t.parentElement}return""}function gc(e,n,t){let o=wn(e),r=wn(n);for(let s=0;s<r.length;s++){let i=o[s],c=r[s];if(!i||!c)continue;let l=Rr(c);if(!l)continue;if(c.classList.contains("polycss-mesh")){let d=l.getPropertyValue("--origin").trim();d&&(l.setProperty("transform-origin",d),l.removeProperty("--origin"))}let u=c.tagName.toLowerCase();if(u==="s"){let d=l.getPropertyValue("--polycss-atlas-size").trim();if(d&&(l.setProperty("width",d),l.setProperty("height",d)),t.hasDynamicLighting)l.removeProperty("--polycss-atlas-size");else for(let x of ac)l.removeProperty(x)}else if(u==="b"||u==="i"||u==="u"){let d=hc(i,"--polycss-paint"),x=t.hasDynamicLighting?"":i.ownerDocument.defaultView?.getComputedStyle(i).color;x?l.setProperty("color",x):d&&!l.getPropertyValue("color")&&l.setProperty("color",d)}if(!t.hasDynamicLighting)for(let d of sc)l.removeProperty(d);if(!t.hasQ)for(let d of ic)l.removeProperty(d);l.removeProperty("will-change"),l.removeProperty("--polycss-paint"),gi(c)}}function yc(e){for(let n of Array.from(e.querySelectorAll("script")))n.remove();for(let n of wn(e))for(let t of Array.from(n.attributes))t.name.toLowerCase().startsWith("on")&&n.removeAttribute(t.name)}function yi(e){let n=e.trim();return n===""||n.startsWith("#")||/^data:/i.test(n)}function bc(e,n){return/^data:/i.test(e.trim())?e.trim():bi(e,n.baseUrl)}function hi(e){let n=/url\(\s*(?:(["'])(.*?)\1|([^)]*?))\s*\)/i.exec(e);return(n?.[2]??n?.[3]??"").trim()||null}function vc(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\a ")}function bi(e,n){try{return new URL(e,n).href}catch{throw new At("ASSET_INLINE_FAILED",`exportPolySceneSnapshot: could not resolve asset URL "${e}".`,e)}}function xc(e){let n=(()=>{try{return new URL(e).pathname.toLowerCase()}catch{return e.toLowerCase()}})();return n.endsWith(".jpg")||n.endsWith(".jpeg")?"image/jpeg":n.endsWith(".png")?"image/png":n.endsWith(".webp")?"image/webp":n.endsWith(".gif")?"image/gif":n.endsWith(".svg")?"image/svg+xml":n.endsWith(".avif")?"image/avif":"application/octet-stream"}function Pc(e){let n=new Uint8Array(e),t=32768,o="";for(let r=0;r<n.length;r+=t){let s=n.subarray(r,r+t);o+=String.fromCharCode(...s)}return btoa(o)}function Sc(e){return/^(blob|filesystem):/i.test(e.trim())}function Cc(e){return new Promise((n,t)=>{let o=new XMLHttpRequest;o.open("GET",e,!0),o.responseType="blob",o.onload=()=>{o.status===0||o.status>=200&&o.status<300?n(o.response):t(new Error(`XHR ${o.status}`))},o.onerror=()=>t(new Error("XHR request failed")),o.send()})}async function Ec(e){let n=Sc(e);try{if(typeof fetch!="function")throw new Error("fetch is not available");let t=await fetch(e,n?void 0:{credentials:"same-origin"});if(!t.ok)throw new Error(`HTTP ${t.status}`);return await t.blob()}catch(t){if(n&&typeof XMLHttpRequest=="function")return Cc(e);throw t}}async function vi(e,n){if(yi(e))return e;let t=bi(e,n.baseUrl),o=n.cache.get(t);if(o)return o;let r=(async()=>{try{let s=await Ec(t),i=s.type||xc(t),c=Pc(await s.arrayBuffer());return`data:${i};base64,${c}`}catch{throw new At("ASSET_INLINE_FAILED",`exportPolySceneSnapshot: could not inline asset "${t}".`,t)}})();return n.cache.set(t,r),r}async function _r(e,n){let t=/url\(\s*(?:(["'])(.*?)\1|([^)]*?))\s*\)/gi,o="",r=0,s;for(;(s=t.exec(e))!==null;){o+=e.slice(r,s.index);let i=(s[2]??s[3]??"").trim(),c=await vi(i,n);o+=yi(i)?s[0]:`url("${c}")`,r=t.lastIndex}return o+e.slice(r)}async function Tc(e,n){for(let t of wn(e)){let o=t.getAttribute("style");o&&t.setAttribute("style",await _r(o,n))}for(let t of Array.from(e.querySelectorAll("style")))t.textContent=await _r(t.textContent??"",n)}function Ac(e){return{position:e.getPropertyValue("background-position").trim(),size:e.getPropertyValue("background-size").trim(),repeat:e.getPropertyValue("background-repeat").trim()}}function wc(e,n){n.position&&e.setProperty("background-position",n.position),n.size&&e.setProperty("background-size",n.size),n.repeat&&e.setProperty("background-repeat",n.repeat)}async function Mc(e,n){let t=[],o=new Map,r=new Map,s=async l=>{let u=bc(l,n),d=o.get(u);if(d)return d;let x=`a${o.size}`;return o.set(u,x),r.set(u,await vi(l,n)),x},i=l=>{for(let[u,d]of o)if(d===l)return r.get(u)??"";return""};for(let l of wn(e)){let u=Rr(l);if(!u||l.tagName.toLowerCase()!=="s")continue;let d=hi(u.getPropertyValue("--polycss-atlas-url"));if(d&&!d.startsWith("#")){let P=await s(d),g="data-polycss-snapshot-atlas";l.setAttribute(g,P),u.removeProperty("--polycss-atlas-url"),t.push({attr:g,value:P,property:"--polycss-atlas-url",dataUrl:i(P)})}let x=hi(u.getPropertyValue("background-image"));if(!x||x.startsWith("#"))continue;let h=await s(x),b="data-polycss-snapshot-bg",v=Ac(u);l.setAttribute(b,h),u.removeProperty("background"),u.removeProperty("background-image"),wc(u,v),t.push({attr:b,value:h,property:"background-image",dataUrl:i(h)}),gi(l)}let c=new Set;return t.filter(l=>{let u=`${l.attr}|${l.value}|${l.property}`;return c.has(u)?!1:(c.add(u),!0)}).map(l=>`.polycss-scene [${l.attr}="${l.value}"] {
794
+ ${l.property}: url("${vc(l.dataUrl)}");
795
+ }`).join(`
796
+
797
+ `)}function Lc(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function _c(e){return e.replace(/<\/style/gi,"<\\/style")}function Rc(e){return e.baseURI||e.URL||e.defaultView?.location.href||"http://localhost/"}async function xi(e){if(!lc(e))throw new At("INVALID_TARGET","exportPolySceneSnapshot: target must be an Element.");let n=cc(e);if(!n)throw new At("SCENE_NOT_FOUND","exportPolySceneSnapshot: target is not inside and does not contain a rendered PolyCSS scene.");let t=e.ownerDocument,o={baseUrl:Rc(t),cache:new Map},r=n.cloneNode(!0),s=uc(r);gc(n,r,s),yc(r);let i=await Mc(r,o);await Tc(r,o);let c=await _r([fc(s),i].filter(Boolean).join(`
798
+
799
+ `),o);return["<!doctype html>","<html>","<head>",'<meta charset="utf-8">',t.title?`<title>${Lc(t.title)}</title>`:"",`<style>${_c(c)}</style>`,"</head>","<body>",r.outerHTML,"</body>","</html>"].filter(Boolean).join("")}var Pe=require("@layoutit/polycss-core");function rt(e){return{polygons:e,objectUrls:[],warnings:[],dispose:()=>{}}}function Pi(e={}){return rt((0,Pe.boxPolygons)(e))}function Si(e){return rt((0,Pe.planePolygons)(e))}function Ci(e){return rt((0,Pe.ringPolygons)(e))}function Ei(e){return rt((0,Pe.octahedronPolygons)(e))}function Ti(e={}){return rt((0,Pe.spherePolygons)(e))}function Ai(e={}){return rt((0,Pe.tetrahedronPolygons)(e))}function wi(e={}){return rt((0,Pe.icosahedronPolygons)(e))}function Mi(e={}){return rt((0,Pe.dodecahedronPolygons)(e))}function Li(e={}){return rt((0,Pe.cylinderPolygons)(e))}function _i(e={}){return rt((0,Pe.conePolygons)(e))}function Ri(e={}){return rt((0,Pe.torusPolygons)(e))}var ye=require("@layoutit/polycss-core"),kc=typeof HTMLElement<"u"?HTMLElement:class{};function Oc(e){return e.closest("poly-scene")??null}function Se(e,n,t){let o=e.getAttribute(n);if(!o)return t;let r=parseFloat(o);return Number.isFinite(r)?r:t}function st(e,n,t){return e.getAttribute(n)??t}function Ft(e,n){let t=e.getAttribute(n);if(!t)return;let o=t.split(",").map(r=>parseFloat(r.trim()));if(!(o.length!==3||o.some(r=>!Number.isFinite(r))))return[o[0],o[1],o[2]]}function Dc(e){if(e.length===0)return e;let n=(0,ye.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)}))}var Ne=class extends kc{constructor(){super(...arguments);this._handle=null}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="position"||t==="scale"||t==="rotation"||t==="cast-shadow"||t==="receive-shadow"){this._handle.setTransform({position:Ft(this,"position"),scale:(()=>{let s=this.getAttribute("scale");if(!s)return;if(s.includes(","))return Ft(this,"scale");let i=parseFloat(s);return Number.isFinite(i)?i:void 0})(),rotation:Ft(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")});return}this._tearDown(),this._mount()}}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=Oc(this);if(!t)return;let o=t.getScene?.();if(!o)return;let r=this.buildPolygons();this.hasAttribute("auto-center")&&(r=Dc(r));let s={polygons:r,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(s,{position:Ft(this,"position"),scale:(()=>{let i=this.getAttribute("scale");if(!i)return;if(i.includes(","))return Ft(this,"scale");let c=parseFloat(i);return Number.isFinite(c)?c:void 0})(),rotation:Ft(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow"),excludeFromAutoCenter:this.hasAttribute("exclude-from-auto-center"),merge:!1})}},Po=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("size"),t=n?parseFloat(n):void 0;return(0,ye.boxPolygons)({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:st(this,"color")})}},So=class extends Ne{static get observedAttributes(){return["axis","size","offset","color","auto-center","position","scale","rotation","cast-shadow","receive-shadow"]}buildPolygons(){let n=Se(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("offset"),r=o===null?0:parseFloat(o);return(0,ye.planePolygons)({axis:t,size:Se(this,"size",.4),offset:Number.isFinite(r)?r:0,color:st(this,"color")})}},Co=class extends Ne{static get observedAttributes(){return["axis","radius","segments","half-thickness","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=Se(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("half-thickness");return(0,ye.ringPolygons)({axis:t,radius:Se(this,"radius",50),segments:Se(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:st(this,"color")})}},Eo=class extends Ne{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.octahedronPolygons)({center:Ft(this,"center")??[0,0,0],size:Se(this,"size",50),color:st(this,"color")})}},To=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.tetrahedronPolygons)({size:Se(this,"size",100),color:st(this,"color")})}},Ao=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.icosahedronPolygons)({size:Se(this,"size",100),color:st(this,"color")})}},wo=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.dodecahedronPolygons)({size:Se(this,"size",100),color:st(this,"color")})}},Mo=class extends Ne{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.spherePolygons)({radius:Se(this,"radius",50),subdivisions:Se(this,"subdivisions",1),color:st(this,"color")})}},Lo=class extends Ne{static get observedAttributes(){return["radius","radius-top","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("radius-top");return(0,ye.cylinderPolygons)({radius:Se(this,"radius",50),radiusTop:n?parseFloat(n):void 0,height:Se(this,"height",100),radialSegments:Se(this,"radial-segments",12),color:st(this,"color")})}},_o=class extends Ne{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.conePolygons)({radius:Se(this,"radius",50),height:Se(this,"height",100),radialSegments:Se(this,"radial-segments",12),color:st(this,"color")})}},Ro=class extends Ne{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.torusPolygons)({radius:Se(this,"radius",50),tube:Se(this,"tube",15),radialSegments:Se(this,"radial-segments",12),tubularSegments:Se(this,"tubular-segments",16),color:st(this,"color")})}};pe(de,require("@layoutit/polycss-core"),module.exports);0&&(module.exports={PolyBoxElement,PolyCameraElement,PolyConeElement,PolyCylinderElement,PolyDodecahedronElement,PolyFirstPersonControlsElement,PolyIcosahedronElement,PolyIframeElement,PolyMapControlsElement,PolyMeshElement,PolyOctahedronElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPlaneElement,PolyPolygonElement,PolyRingElement,PolySceneElement,PolySceneSnapshotError,PolySelectElement,PolySphereElement,PolyTetrahedronElement,PolyTorusElement,PolyTransformControlsElement,buildAtlasPages,buildTextureEdgeRepairSets,collectPolyRenderStats,computeTextureAtlasPlanPublic,createPolyBox,createPolyCamera,createPolyCone,createPolyCylinder,createPolyDodecahedron,createPolyFirstPersonControls,createPolyIcosahedron,createPolyMapControls,createPolyOctahedron,createPolyOrbitControls,createPolyOrthographicCamera,createPolyPerspectiveCamera,createPolyPlane,createPolyRing,createPolyScene,createPolySphere,createPolyTetrahedron,createPolyTorus,createSelect,createTransformControls,cssBorderShapeForPlan,exportPolySceneSnapshot,filterAtlasPlans,formatBorderShapeEntryMatrix,formatCssLengthPx,formatMatrix3d,formatSolidQuadEntryMatrix,getSolidPaintDefaults,getSolidPaintDefaultsFromPlans,injectPolyBaseStyles,isBorderShapeSupported,isFullRectSolid,isProjectiveQuadPlan,isSolidTrianglePlan,isSolidTriangleSupported,packTextureAtlasPlansWithScale,renderPolygonsWithStableTriangles,renderPolygonsWithTextureAtlas,renderPolygonsWithTextureAtlasAsync,updatePolygonsWithStableTopology,updatePolygonsWithStableTriangles,updateStableTriangleFrame,...require("@layoutit/polycss-core")});