@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/README.md +151 -149
- package/dist/PolyShapeElements-BNHvErQF.d.cts +654 -0
- package/dist/PolyShapeElements-BNHvErQF.d.ts +654 -0
- package/dist/elements.cjs +180 -49
- package/dist/elements.d.cts +1 -1
- package/dist/elements.d.ts +1 -1
- package/dist/elements.js +180 -49
- package/dist/index.cjs +461 -50
- package/dist/index.d.cts +144 -83
- package/dist/index.d.ts +144 -83
- package/dist/index.js +461 -50
- package/package.json +3 -3
- package/dist/PolySelectElement-Tvsmhx2m.d.cts +0 -419
- package/dist/PolySelectElement-Tvsmhx2m.d.ts +0 -419
package/dist/elements.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as hs,cameraCullVisibleSignature as gs,computeSceneBbox as ys,findOverlappingPolygonDuplicates as bs,inverseRotateVec3 as oo,isVoxelCameraCullableNormalGroups as xs,mergePolygons as vs,normalFacesCamera as Ps,parseHexColor as Jt,polygonCssSurfaceNormal as ro}from"@layoutit/polycss-core";import{parsePureColor as En}from"@layoutit/polycss-core";var Ot=50,It=[.4,-.7,.59],Ht="#ffffff",Vt=1,zt="#ffffff",Ft=.4,Oe=4096,ln=1,_o=.1,Ro=1,An=Oe*Oe,ko=An*3,_t=2048,Do=4*1024*1024,Oo=16*1024*1024,Io=.995,Ho=12,ke=new Map,Rt=new WeakMap,ne=.001,ae=1e-9,Vo=1e-4,zo=.1,cn=.01,Fo=.75,Bo=1,No=250,un=1.5,$o=.75,Xo=3,Yo=2,Uo=4,kt=64,we=64,ve=64,Go=128,dn=50,mn=1e-7,pn=16,Tt=.9,Wo=.05,jo=Number.POSITIVE_INFINITY,Zo=.6;function qo(e){let n=ke.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}),ke.set(e,n),n.then(()=>{ke.get(e)===n&&ke.delete(e)},()=>{ke.get(e)===n&&ke.delete(e)})),n}function Ke(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Ro,Math.max(_o,n))}function Bt(e,n){let t=e.toFixed(n).replace(/\.?0+$/,"");return Object.is(Number(t),-0)?"0":t}function Ie(e,n=Uo){let t=Bt(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function Ae(e,n=Xo){return e.map(t=>Bt(t,n)).join(",")}function Mn(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)<=ae)return!1;let l=Math.sign(i);if(n===0)n=l;else if(l!==n)return!1}return!0}function Qo(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 Ko(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],l=o[1]-t[1],a=r*l-s*i;if(Math.abs(a)<=ae)return null;let u=t[0]-e[0],m=t[1]-e[1],d=(u*l-m*i)/a;return[e[0]+d*r,e[1]+d*s]}function Nt(e,n){if(e.length<6||e.length%2!==0||n<=0)return e;let t=[];for(let a=0;a<e.length;a+=2)t.push([e[a],e[a+1]]);if(!Mn(t))return Ne(e,n);let o=Qo(t);if(Math.abs(o)<=ae)return Ne(e,n);let r=o>0?1:-1,s=[];for(let a=0;a<t.length;a++){let u=t[a],m=t[(a+1)%t.length],d=m[0]-u[0],f=m[1]-u[1],g=Math.hypot(d,f);if(g<=ae)return Ne(e,n);let p=r*(f/g)*n,h=r*(-d/g)*n;s.push({a:[u[0]+p,u[1]+h],b:[m[0]+p,m[1]+h]})}let i=[],l=Math.max(2,n*4);for(let a=0;a<t.length;a++){let u=s[(a+t.length-1)%t.length],m=s[a],d=Ko(u.a,u.b,m.a,m.b);if(!d)return Ne(e,n);let f=t[a],g=d[0]-f[0],p=d[1]-f[1],h=Math.hypot(g,p);h>l?i.push(f[0]+g/h*l,f[1]+p/h*l):i.push(d[0],d[1])}return i}function fn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function $t(e){let t=e?.defaultView?.__polycssProjectiveQuadGuards,o=t?.maxWeightRatio,r=Math.max(0,fn(t?.denomEps,Wo)),s=typeof o=="number"&&Number.isFinite(o)&&o>0?Math.max(1,o):jo,i=Math.max(0,fn(t?.bleed,Zo));return{denomEps:r,maxWeightRatio:s,bleed:i,disableGuards:t?.disableGuards===!0}}function hn(e,n){if(e.length!==4||!Mn(e))return null;let[t,o,r,s]=e,i=t[0]-o[0]+r[0]-s[0],l=t[1]-o[1]+r[1]-s[1],a=o[0]-r[0],u=s[0]-r[0],m=o[1]-r[1],d=s[1]-r[1],f=a*d-m*u;if(Math.abs(f)<=ae)return null;let g=(i*d-l*u)/f,p=(a*l-m*i)/f,h=[1,1+g,1+g+p,1+p];if(h.some(A=>!Number.isFinite(A)))return null;let b=Math.min(...h),x=Math.max(...h);return!n.disableGuards&&(b<=n.denomEps||x/b>n.maxWeightRatio)?null:{g,h:p,w1:1+g,w3:1+p}}function Jo(e,n,t,o,r,s,i,l){if(e.length!==8)return null;let a=[[e[0],e[1]],[e[2],e[3]],[e[4],e[5]],[e[6],e[7]]];if(!hn(a,l))return null;let u=Nt(e,l.bleed),m=[[u[0],u[1]],[u[2],u[3]],[u[4],u[5]],[u[6],u[7]]],d=hn(m,l);if(!d)return null;let{g:f,h:g,w1:p,w3:h}=d,[b,x,,A]=m,M=[r+b[0]*n[0]+b[1]*t[0],s+b[0]*n[1]+b[1]*t[1],i+b[0]*n[2]+b[1]*t[2]],P=([k,C],v)=>[(v-1)*r+(v*k-b[0])*n[0]+(v*C-b[1])*t[0],(v-1)*s+(v*k-b[0])*n[1]+(v*C-b[1])*t[1],(v-1)*i+(v*k-b[0])*n[2]+(v*C-b[1])*t[2]],E=[...P(x,p),f,...P(A,h),g,o[0],o[1],o[2],0,M[0],M[1],M[2],1];for(let k=0;k<8;k+=1)E[k]/=kt;return Ae(E,6)}function je(e,n=Yo){let t=Bt(e,n);return Number(t)===0?"0":`${t}%`}function er(e,n,t,o,r,s){let i=(e-t)*(s-o)-(n-o)*(r-t);return Math.abs(i)>mn?!1:(e-t)*(e-r)+(n-o)*(n-s)<=mn}function tr(e,n=dn,t=dn){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,l]=e[r],[a,u]=e[s];if(er(n,t,i,l,a,u))return!0;l>t!=u>t&&n<(a-i)*(t-l)/(u-l)+i&&(o=!o)}return o}function Cn(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function nr(e,n){let t=Cn(e);if(t<=0)return 1;let o=Math.max(1,...e.map(i=>Math.max(i.width,i.height))),r=_t/o,s=Math.sqrt(n/(t*4));return Ke(Math.min(r,s))}function or(e,n){let t=Cn(e),o=.5;return t<=An?o=1:t<=ko&&(o=.75),Ke(Math.min(o,nr(e,n)))}function rr(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function sr(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function ir(e,n,t){let o=rr(e,n),r=sr(e,n),s=o>_t?_t/o:1,i=r>t?Math.sqrt(t/r):1;return Math.min(s,i)}function ar(e,n,t){let o=or(n.pages,t),r=o===1?n:qe(e,o);for(let s=0;s<4;s++){let i=ir(r.pages,o,t);if(i>=1)break;let l=Ke(o*i*Io);if(l>=o)break;o=l,r=qe(e,o)}return{packed:r,atlasScale:o}}function lr(e){return Sn(e)?Do:Oo}function Sn(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 cr(e,n){return e!==void 0&&e!=="auto"||Sn(n)?ve:Go}function ur(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,Ae(t))}function gn(e,n){for(let t of e.entries)t&&(t.atlasCanonicalSize=n,t.atlasMatrix=ur(t,n));return e}function Ee(e){return e.atlasCanonicalSize??ve}function wn(e,n,t){let o=cr(n,t);if(n!==void 0&&n!=="auto"){let i=Ke(n);return{packed:gn(qe(e,i),o),atlasScale:i,atlasCanonicalSize:o}}let r=qe(e,1),s=ar(e,r,lr(t));return{packed:gn(s.packed,o),atlasScale:s.atlasScale,atlasCanonicalSize:o}}function dr(e){return Math.max(ln,Math.ceil(ln/e))}function xe(e,n,t=1,o=0,r=0,s=1,i=0,l=0){e.setTransform(t*n,o*n,r*n,s*n,i*n,l*n)}function Me(e){let n=En(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function Xt({r:e,g:n,b:t}){return`${e},${n},${t}`}function mr(e){return En(e)?.alpha??1}function pr({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function J(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,s=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`(^|;)\\s*${s}\\s*:[^;]*`,"i"),l=i.test(o)?o.replace(i,(a,u)=>`${u}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;l!==o&&e.setAttribute("style",l)}function de(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 Tn(e,n,t,o,r){let s=Me(e),i=Me(t),l=Me(o),a=l.r/255*r+i.r/255*n,u=l.g/255*r+i.g/255*n,m=l.b/255*r+i.b/255*n,d=Math.max(0,Math.min(255,Math.round(s.r*a))),f=Math.max(0,Math.min(255,Math.round(s.g*u))),g=Math.max(0,Math.min(255,Math.round(s.b*m))),p=mr(e);return p<1?`rgba(${d}, ${f}, ${g}, ${p})`:pr({r:d,g:f,b:g})}function Ln(e,n,t,o){let r=Me(n),s=Me(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 fr({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 hr(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(),xe(e,i),e.globalCompositeOperation="multiply",e.fillStyle=fr(s),e.fillRect(n,t,o,r),e.restore())}function gr(e,n,t,o,r,s,i){let l=n.naturalWidth||n.width||1,a=n.naturalHeight||n.height||1,u=Math.max(r/l,s/a),m=l*u,d=a*u;xe(e,i),e.drawImage(n,t+(r-m)/2,o+(s-d)/2,m,d)}function Ze(e){return`${e[0]},${e[1]},${e[2]}`}function yr(e,n){let t=Ze(e),o=Ze(n);return t<o?`${t}|${o}`:`${o}|${t}`}function _n(e,n){return Ze(e)<Ze(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 br(e){return!e.texture}function Xe(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function Je(e){if(e.length<3)return null;let n=e[0],t=0,o=0,r=0;for(let i=1;i+1<e.length;i++){let l=e[i],a=e[i+1],u=[l[0]-n[0],l[1]-n[1],l[2]-n[2]],m=[a[0]-n[0],a[1]-n[1],a[2]-n[2]];t-=u[1]*m[2]-u[2]*m[1],o-=u[2]*m[0]-u[0]*m[2],r-=u[0]*m[1]-u[1]*m[0]}let s=Math.hypot(t,o,r);return s<=ae?null:(t/=s,o/=s,r/=s,[t,o,r])}function He(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function xr(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 vr(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=Xe(e.vertices,n,t),r=Je(o);return r?{pts:o,normal:r,planeD:He(r,o[0]),optimizable:br(e)}:null}function Pr(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:Rn(e,n)}function Rn(e,n){return!e||!n||He(e.normal,n.normal)<1-Vo?!1:Math.abs(e.planeD-n.planeD)<=zo}function yn(e,n){if(!e)return null;let t=n.directionalLight,o=n.ambientLight,r=t?.direction??It,s=t?.color??Ht,i=Math.max(0,t?.intensity??Vt),l=o?.color??zt,a=Math.max(0,o?.intensity??Ft),u=Math.hypot(r[0],r[1],r[2])||1,m=r[0]/u,d=r[1]/u,f=r[2]/u,g=i*Math.max(0,e.normal[0]*m+e.normal[1]*d+e.normal[2]*f),p=Ln(g,s,l,a);return p.r*.2126+p.g*.7152+p.b*.0722}function Er(e){let n=[...e],t=Math.abs(n[0])>ae?0:Math.abs(n[1])>ae?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 $e(e,n,t,o,r={}){let s=He(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],l=Math.hypot(i[0],i[1],i[2]);if(l<=ae)return null;let a=[i[0]/l,i[1]/l,i[2]/l],u=[t[1]*a[2]-t[2]*a[1],t[2]*a[0]-t[0]*a[2],t[0]*a[1]-t[1]*a[0]],m=Math.hypot(u[0],u[1],u[2]);if(m<=ae)return null;let d=[u[0]/m,u[1]/m,u[2]/m],f=e.map(w=>{let O=w[0]-n[0],H=w[1]-n[1],V=w[2]-n[2];return[O*a[0]+H*a[1]+V*a[2],O*d[0]+H*d[1]+V*d[2]]}),g=r.boundsOrigin??n,p=n[0]-g[0],h=n[1]-g[1],b=n[2]-g[2],x=p*a[0]+h*a[1]+b*a[2],A=p*d[0]+h*d[1]+b*d[2],M=1/0,P=1/0,E=-1/0,k=-1/0;for(let[w,O]of f){let H=w+x,V=O+A;H<M&&(M=H),H>E&&(E=H),V<P&&(P=V),V>k&&(k=V)}let C=E-M,v=k-P;if(!Number.isFinite(C)||!Number.isFinite(v))return null;let B=r.snapBounds?Math.floor(M+ne):M,N=r.snapBounds?Math.floor(P+ne):P,Y=r.snapBounds?Math.ceil(E-ne):E,te=r.snapBounds?Math.ceil(k-ne):k,S=Math.max(1,r.snapBounds?Y-B:Math.ceil(C)),$=Math.max(1,r.snapBounds?te-N:Math.ceil(v));return{xAxis:a,yAxis:d,local2D:f,shiftX:x-B,shiftY:A-N,canvasW:S,canvasH:$,pixelArea:S*$,rawArea:C*v}}function Ar(e,n,t,o){let r=0,s=0;for(let i of e){let l=n[i];if(!l)return null;let a=$e(l.pts,l.pts[0],l.normal,t,{boundsOrigin:o,snapBounds:!0});if(!a)return null;r+=a.pixelArea,s+=a.rawArea}return{pixelArea:r,rawArea:s}}function Mr(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,s=new Set;for(let i of e){let l=n[i];if(!l)continue;let a=[l.pts[1][0]-l.pts[0][0],l.pts[1][1]-l.pts[0][1],l.pts[1][2]-l.pts[0][2]],u=$e(l.pts,l.pts[0],l.normal,a);o&&u?(o.pixelArea+=u.pixelArea,o.rawArea+=u.rawArea):o=null;for(let m=0;m<l.pts.length;m++){let d=_n(l.pts[m],l.pts[(m+1)%l.pts.length]),f=$e(l.pts,l.pts[0],l.normal,d);if(!f)continue;let g=Er(f.xAxis);if(s.has(g))continue;s.add(g);let p=Ar(e,n,f.xAxis,t);p&&(!r||p.pixelArea<r.pixelArea||p.pixelArea===r.pixelArea&&p.rawArea<r.rawArea-ne)&&(r={xAxis:f.xAxis,...p})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+ne)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function Yt(e,n){let t=n.tileSize??Ot,o=n.layerElevation??t,r=e.map(d=>vr(d,t,o)),s=new Map,i=e.map(()=>new Set),l=e.map(()=>new Set);for(let d=0;d<e.length;d++){let f=e[d].vertices;if(!(!f||f.length<3))for(let g=0;g<f.length;g++){let p=yr(f[g],f[(g+1)%f.length]),h=s.get(p),b={polygon:d,edge:g};h?h.push(b):s.set(p,[b])}}let a=e.map(()=>new Set);for(let d of s.values())if(!(d.length<2))for(let f=0;f<d.length;f++)for(let g=f+1;g<d.length;g++){let p=d[f],h=d[g],b=p.polygon,x=h.polygon;if(e[b].texture&&e[x].texture&&(l[p.polygon].add(p.edge),l[h.polygon].add(h.edge)),Rn(r[b],r[x]))i[p.polygon].add(p.edge),i[h.polygon].add(h.edge);else{let A=yn(r[b],n),M=yn(r[x],n);A!==null&&M!==null&&(A<=M+cn&&i[p.polygon].add(p.edge),M<=A+cn&&i[h.polygon].add(h.edge))}Pr(r[b],r[x])&&(a[b].add(x),a[x].add(b))}let u=Array(e.length).fill(void 0),m=new Set;for(let d=0;d<e.length;d++){if(m.has(d)||!r[d]?.optimizable)continue;let f=[],g=[d];for(m.add(d);g.length>0;){let h=g.pop();f.push(h);for(let b of a[h])m.has(b)||(m.add(b),g.push(b))}if(f.length<2)continue;let p=Mr(f,r);if(p)for(let h of f)u[h]={xAxis:p.xAxis,boundsOrigin:p.boundsOrigin,seamEdges:i[h],textureEdgeRepairEdges:l[h]}}for(let d=0;d<e.length;d++)!u[d]&&(i[d].size>0||l[d].size>0)&&(u[d]={seamEdges:i[d],textureEdgeRepairEdges:l[d]});return u}function Cr(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 bn(e,n,t,o){if(o.optimize&&o.fixedXAxis)return $e(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,s=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,i=s??(o.optimize?e.map((l,a)=>a):[0]);for(let l of i){let a=(l+1)%e.length,u=s?_n(e[l],e[a]):[e[a][0]-e[l][0],e[a][1]-e[l][1],e[a][2]-e[l][2]],m=$e(e,n,t,u,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});m&&(!r||m.pixelArea<r.pixelArea||m.pixelArea===r.pixelArea&&m.rawArea<r.rawArea-ne)&&(r=m)}return r}function Sr(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=ne)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])>ne||Math.abs(t[0])>ne||n[1]-n[0]<=ne||t[1]-t[0]<=ne))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,l=s+e.shiftY,a=Math.abs(i-n[0])<=ne||Math.abs(i-n[1])<=ne,u=Math.abs(l-t[0])<=ne||Math.abs(l-t[1])<=ne;if(!a||!u)return!1}return!0}function kn(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,l]=n,a=t[0],u=t[1],m=o[0],d=o[1],f=r[0],g=r[1],p=s[0],h=1-s[1],b=i[0],x=1-i[1],A=l[0],M=1-l[1],P=b-p,E=x-h,k=A-p,C=M-h,v=P*C-k*E;if(Math.abs(v)<=1e-9)return null;let B=m-a,N=f-a,Y=d-u,te=g-u,S={a:(B*C-N*E)/v,b:(P*N-k*B)/v,c:(Y*C-te*E)/v,d:(P*te-k*Y)/v,e:0,f:0};return S.e=a-S.a*p-S.b*h,S.f=u-S.c*p-S.d*h,S}function Dn(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let s of e){let i=s[0],l=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(l))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,l),r=Math.max(r,l)}return{minU:n,minV:t,maxU:o,maxV:r}}function wr(e,n,t,o,r,s,i,l){let u=Xe(e.vertices,n,t).map(f=>{let g=f[0]-o[0],p=f[1]-o[1],h=f[2]-o[2];return[g*r[0]+p*r[1]+h*r[2]+i,g*s[0]+p*s[1]+h*s[2]+l]}),m=kn(u,e.uvs),d=Dn(e.uvs);return!m&&!d?null:{screenPts:u.flatMap(([f,g])=>[f,g]),uvAffine:m,uvSampleRect:d}}function Ne(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],o+=e[i+1];t/=r,o/=r;let s=e.slice();for(let i=0;i<s.length;i+=2){let l=s[i]-t,a=s[i+1]-o,u=Math.hypot(l,a);u<=ne||(s[i]+=l/u*n,s[i+1]+=a/u*n)}return s}function Dt(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 Ut(e,n,t,o,r){let{vertices:s,texture:i,uvs:l}=e;if(!s||s.length<3)return null;let a=t.tileSize??Ot,u=t.layerElevation??a,m=Xe(s,a,u),d=m[0],f=m[1],g=[f[0]-d[0],f[1]-d[1],f[2]-d[2]];if(Math.hypot(g[0],g[1],g[2])===0)return null;let h=Je(m);if(!h)return null;let b=bn(m,d,h,{optimize:!1}),x=i||b&&Sr(b)?b:bn(m,d,h,{optimize:!0,fixedXAxis:r?.xAxis,boundsOrigin:r?.boundsOrigin,snapBounds:!!r,seamEdges:r?.seamEdges});if(!x)return null;let{xAxis:A,yAxis:M,local2D:P}=x,E=i&&r?.textureEdgeRepairEdges?.size?r.textureEdgeRepairEdges:null,k=!!(i&&E),C=x.shiftX,v=x.shiftY,B=x.canvasW,N=x.canvasH,Y=[];for(let[I,D]of P)Y.push(I+C,D+v);let te=d[0]-C*A[0]-v*M[0],S=d[1]-C*A[1]-v*M[1],$=d[2]-C*A[2]-v*M[2],w=Ae([A[0],A[1],A[2],0,M[0],M[1],M[2],0,h[0],h[1],h[2],0,te,S,$,1]),O=Ae([A[0]*B,A[1]*B,A[2]*B,0,M[0]*N,M[1]*N,M[2]*N,0,h[0],h[1],h[2],0,te,S,$,1]),H=Ae([A[0]*B/ve,A[1]*B/ve,A[2]*B/ve,0,M[0]*N/ve,M[1]*N/ve,M[2]*N/ve,0,h[0],h[1],h[2],0,te,S,$,1]),V=!i&&s.length===4?Jo(Y,A,M,h,te,S,$,o):null,j=t.directionalLight,ie=t.ambientLight,_=j?.direction??It,X=j?.color??Ht,U=Math.max(0,j?.intensity??Vt),oe=ie?.color??zt,re=Math.max(0,ie?.intensity??Ft),le=Math.hypot(_[0],_[1],_[2])||1,pe=_[0]/le,ce=_[1]/le,ue=_[2]/le,fe=U*Math.max(0,h[0]*pe+h[1]*ce+h[2]*ue),ge=Ln(fe,X,oe,re),c=Tn(e.color??"#cccccc",fe,X,oe,re),y=null,R=null;i&&l&&l.length>=3&&l.length===s.length&&(R=Dn(l),y=kn(P.map(([I,D])=>[I+C,D+v]),l));let T=i&&e.textureTriangles?.length?e.textureTriangles.map(I=>wr(I,a,u,d,A,M,C,v)).filter(I=>!!I):null;return{index:n,polygon:e,texture:i,tileSize:a,layerElevation:u,matrix:w,canonicalMatrix:O,atlasMatrix:H,projectiveMatrix:V,canvasW:B,canvasH:N,screenPts:Y,uvAffine:y,uvSampleRect:R,textureTriangles:T,textureEdgeRepairEdges:E,textureEdgeRepair:k,normal:h,textureTint:ge,shadedColor:c}}function et(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??Ot,r=t.layerElevation??o,s=Xe(e.vertices,o,r),i=Je(s);if(!i)return null;let l=[{a:0,b:1,c:2},{a:1,b:2,c:0},{a:2,b:0,c:1}].map(Z=>{let F=s[Z.a],K=s[Z.b];return{...Z,length:Math.hypot(K[0]-F[0],K[1]-F[1],K[2]-F[2])}}).sort((Z,F)=>F.length-Z.length),a=l[0].a,u=l[0].b,m=l[0].c,d=s[a],f=s[u],g=s[m],p=l[0].length;if(p<=ae)return null;let h=[(f[0]-d[0])/p,(f[1]-d[1])/p,(f[2]-d[2])/p],b=[g[0]-d[0],g[1]-d[1],g[2]-d[2]],x=He(b,h),A=[d[0]+h[0]*x,d[1]+h[1]*x,d[2]+h[2]*x],M=[A[0]-g[0],A[1]-g[1],A[2]-g[2]],P=Math.hypot(M[0],M[1],M[2]);if(P<=ae)return null;let E=[M[0]/P,M[1]/P,M[2]/P];if(He(xr(h,E),i)<0){let Z=u;if(u=a,a=Z,d=s[a],f=s[u],p=Math.hypot(f[0]-d[0],f[1]-d[1],f[2]-d[2]),p<=ae)return null;h=[(f[0]-d[0])/p,(f[1]-d[1])/p,(f[2]-d[2])/p];let F=[g[0]-d[0],g[1]-d[1],g[2]-d[2]];x=He(F,h),A=[d[0]+h[0]*x,d[1]+h[1]*x,d[2]+h[2]*x],M=[A[0]-g[0],A[1]-g[1],A[2]-g[2]];let K=Math.hypot(M[0],M[1],M[2]);if(K<=ae)return null;E=[M[0]/K,M[1]/K,M[2]/K]}let k=Math.max(0,Math.min(p,x)),C=Math.max(0,p-k),v=Nt([k,0,0,P,k+C,P],$o),B=[v[0],v[1]],N=[v[2],v[3]],Y=[v[4],v[5]],te=(N[1]+Y[1])/2,S=B[0]-N[0],$=Y[0]-B[0],w=te-B[1];if(S<=ae||$<=ae||w<=ae||!Number.isFinite(S+$+w))return null;let O=t.directionalLight,H=t.ambientLight,V=O?.direction??It,j=O?.color??Ht,ie=Math.max(0,O?.intensity??Vt),_=H?.color??zt,X=Math.max(0,H?.intensity??Ft),U=Math.hypot(V[0],V[1],V[2])||1,oe=V[0]/U,re=V[1]/U,le=V[2]/U,pe=ie*Math.max(0,i[0]*oe+i[1]*re+i[2]*le),ce=Tn(e.color??"#cccccc",pe,j,_,X),ue=t.textureLighting??"baked",fe=Me(e.color??"#cccccc"),ge=ce===t.solidPaintDefaults?.paintColor,c=ue==="dynamic"&&Xt(fe)===t.solidPaintDefaults?.dynamicColorKey,y=ue==="dynamic"||ge?"":`color:${ce};`,R=ue==="dynamic"?`--pnx:${i[0].toFixed(4)};--pny:${i[1].toFixed(4)};--pnz:${i[2].toFixed(4)};`+(c?"":`--psr:${(fe.r/255).toFixed(4)};--psg:${(fe.g/255).toFixed(4)};--psb:${(fe.b/255).toFixed(4)};`):"",T=([Z,F])=>[g[0]+(Z-k)*h[0]+F*E[0],g[1]+(Z-k)*h[1]+F*E[1],g[2]+(Z-k)*h[2]+F*E[2]],I=T(B),D=T([N[0],te]),z=T([Y[0],te]),G=we/2,ee=[(z[0]-D[0])/we,(z[1]-D[1])/we,(z[2]-D[2])/we],q=[I[0]-ee[0]*G,I[1]-ee[1]*G,I[2]-ee[2]*G],Q=[(D[0]-q[0])/we,(D[1]-q[1])/we,(D[2]-q[2])/we],L=`transform:matrix3d(${Ae([ee[0],ee[1],ee[2],0,Q[0],Q[1],Q[2],0,i[0],i[1],i[2],0,q[0],q[1],q[2],1])});`+y+R;return{index:n,polygon:e,styleText:L}}function qe(e,n=1){let t=Array(e.length).fill(null),o=[],r=dr(n),s=e.filter(a=>!!a).sort((a,u)=>u.canvasH-a.canvasH||u.canvasW-a.canvasW||a.index-u.index),i=()=>({width:r,height:r,entries:[],shelves:[]}),l=(a,u,m)=>{if(a.sealed)return null;for(let g of a.shelves)if(u.canvasH<=g.height&&g.x+u.canvasW+r<=Oe){let p={...u,pageIndex:m,x:g.x,y:g.y};return g.x+=u.canvasW+r*2,a.entries.push(p),a.width=Math.max(a.width,p.x+u.canvasW+r),p}let d=a.shelves.length===0?r:a.height+r;if(d+u.canvasH+r>Oe)return null;let f={...u,pageIndex:m,x:r,y:d};return a.shelves.push({x:r+u.canvasW+r*2,y:d,height:u.canvasH}),a.entries.push(f),a.width=Math.max(a.width,f.x+u.canvasW+r),a.height=Math.max(a.height,d+u.canvasH+r),f};for(let a of s){if(a.canvasW+r*2>Oe||a.canvasH+r*2>Oe){let d=o.length,f={...a,pageIndex:d,x:r,y:r};t[a.index]=f,o.push({width:a.canvasW+r*2,height:a.canvasH+r*2,entries:[f],shelves:[],sealed:!0});continue}let m=null;for(let d=0;d<o.length&&(m=l(o[d],a,d),!m);d++);if(!m){let d=i(),f=o.length;o.push(d),m=l(d,a,f)}m&&(t[a.index]=m)}return{entries:t,pages:o.map(({width:a,height:u,entries:m})=>({width:a,height:u,entries:m}))}}function Tr(e,n,t,o){xe(e,o),e.beginPath(),Dt(e,n.x,n.y,n.screenPts),e.clip(),xe(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function De(e,n){return Math.max(0,Math.min(n,e))}function xn(e,n,t,o,r,s,i,l){let a=n.naturalWidth||n.width||1,u=n.naturalHeight||n.height||1,m=De(Math.min(t.minU,t.maxU)*a,a),d=De(Math.max(t.minU,t.maxU)*a,a),f=De(Math.min(t.minV,t.maxV)*u,u),g=De(Math.max(t.minV,t.maxV)*u,u),p=Math.floor(m),h=Math.floor(f),b=Math.ceil(d)-p,x=Math.ceil(g)-h;b<1&&(p=Math.floor(De((t.minU+t.maxU)/2*a,a-1)),b=1),x<1&&(h=Math.floor(De((t.minV+t.maxV)/2*u,u-1)),x=1),p=Math.max(0,Math.min(a-1,p)),h=Math.max(0,Math.min(u-1,h)),b=Math.max(1,Math.min(a-p,b)),x=Math.max(1,Math.min(u-h,x)),xe(e,l),e.drawImage(n,p,h,b,x,o,r,s,i)}function Lr(e,n,t,o,r,s){for(let i=0;i<o.length;i+=2){let l=n+o[i]+r,a=t+o[i+1]+s;i===0?e.moveTo(l,a):e.lineTo(l,a)}e.closePath()}function _r(e,n,t,o,r=0,s=0){if(n.textureTriangles?.length){let i=t.naturalWidth||t.width||1,l=t.naturalHeight||t.height||1;for(let a of n.textureTriangles){let u=Ne(a.screenPts,Fo);e.save(),xe(e,o),e.beginPath(),Lr(e,n.x,n.y,u,r,s),e.clip(),a.uvAffine?(xe(e,o,a.uvAffine.a/i,a.uvAffine.c/i,a.uvAffine.b/l,a.uvAffine.d/l,n.x+a.uvAffine.e+r,n.y+a.uvAffine.f+s),e.drawImage(t,0,0)):a.uvSampleRect&&xn(e,t,a.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let i=t.naturalWidth||t.width||1,l=t.naturalHeight||t.height||1;xe(e,o,n.uvAffine.a/i,n.uvAffine.c/i,n.uvAffine.b/l,n.uvAffine.d/l,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+s),e.drawImage(t,0,0)}else n.uvSampleRect?xn(e,t,n.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o):gr(e,t,n.x+r,n.y+s,n.canvasW,n.canvasH,o)}function Rr(e,n,t,o,r,s){let i=r-t,l=s-o,a=i*i+l*l;if(a<=ae)return Math.hypot(e-t,n-o);let u=Math.max(0,Math.min(1,((e-t)*i+(n-o)*l)/a));return Math.hypot(e-(t+i*u),n-(o+l*u))}function kr(e,n,t,o){let r=1/0,s=t.length/2;for(let i of o){if(i<0||i>=s)continue;let l=i*2,a=(i+1)%s*2;r=Math.min(r,Rr(e,n,t[l],t[l+1],t[a],t[a+1]))}return r}function Dr(e,n,t,o,r,s){let i=Math.max(0,o-s),l=Math.min(n-1,o+s),a=Math.max(0,r-s),u=Math.min(t-1,r+s),m=null,d=1/0;for(let f=a;f<=u;f++)for(let g=i;g<=l;g++){if(g===o&&f===r)continue;let p=g-o,h=f-r,b=p*p+h*h;if(b>s*s||b>=d)continue;let x=(f*n+g)*4;e[x+3]<No||(m=x,d=b)}return m}function Or(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),s=Math.max(0,Math.floor(n.y*t)),i=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),l=Math.max(1,Math.min(o.height-s,Math.ceil(n.canvasH*t)));if(i<=0||l<=0)return;let a;try{a=e.getImageData(r,s,i,l)}catch{return}let u=a.data,m=new Uint8ClampedArray(u),d=Math.max(un,un/t),f=Math.max(2,Math.ceil(d*t)+1),g=!1;for(let p=0;p<l;p++)for(let h=0;h<i;h++){let b=(p*i+h)*4,x=u[b+3];if(x<Bo||x===255)continue;let A=(r+h+.5)/t-n.x,M=(s+p+.5)/t-n.y;if(kr(A,M,n.screenPts,n.textureEdgeRepairEdges)>d)continue;let P=Dr(m,i,l,h,p,f);P!==null&&(u[b]=m[P],u[b+1]=m[P+1],u[b+2]=m[P+2],u[b+3]=255,g=!0)}g&&e.putImageData(a,r,s)}async function Ir(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=e.entries.some(m=>m.textureEdgeRepair&&m.texture&&m.textureEdgeRepairEdges&&m.textureEdgeRepairEdges.size>0),i=r.getContext("2d",s?{willReadFrequently:!0}:void 0);if(!i)return{width:e.width,height:e.height,url:null};let l=Array.from(new Set(e.entries.flatMap(m=>m.texture?[m.texture]:[]))),a=new Map;await Promise.all(l.map(async m=>{a.set(m,await qo(m))}));for(let m of e.entries){let d=m.texture?a.get(m.texture):null;if(!m.texture){i.save(),Tr(i,m,n,o),i.restore();continue}d&&(i.save(),xe(i,o),i.beginPath(),Dt(i,m.x,m.y,m.screenPts),i.clip(),_r(i,m,d,o),i.restore()),m.texture&&n==="baked"&&(i.save(),xe(i,o),i.beginPath(),Dt(i,m.x,m.y,m.screenPts),i.clip(),hr(i,m.x,m.y,m.canvasW,m.canvasH,m.textureTint,o),i.restore()),Or(i,m,o)}let u=await Cr(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:u}}async function On(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await Ir(i,n,t,o))}return s}function In(e,n,t,o){if(!n.url)return;let r=`url(${n.url})`,s=o.canvasW||1,i=o.canvasH||1,l=Ee(o),a=`${Ie(-o.x/s*l)} ${Ie(-o.y/i*l)}`,u=`${Ie(n.width/s*l)} ${Ie(n.height/i*l)}`;t==="dynamic"?(J(e,"background-image",r),J(e,"background-position",a),J(e,"background-size",u)):J(e,"background",`${r} ${a} / ${u} no-repeat`),t==="dynamic"?(J(e,"mask-image",r),J(e,"mask-mode","alpha"),J(e,"mask-position",a),J(e,"mask-size",u),J(e,"mask-repeat","no-repeat"),J(e,"-webkit-mask-image",r),J(e,"-webkit-mask-position",a),J(e,"-webkit-mask-size",u),J(e,"-webkit-mask-repeat","no-repeat")):(de(e,"mask-image"),de(e,"mask-mode"),de(e,"mask-position"),de(e,"mask-size"),de(e,"mask-repeat"),de(e,"-webkit-mask-image"),de(e,"-webkit-mask-position"),de(e,"-webkit-mask-size"),de(e,"-webkit-mask-repeat"))}function Le(e,n){let t=Rt.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);Rt.set(e,o)}function Hn(e,n,t,o=0,r=0){let s=e.matrix.split(",").map(f=>Number(f));if(s.length!==16||s.some(f=>!Number.isFinite(f)))return e.matrix;let i=s[0],l=s[1],a=s[2],u=s[4],m=s[5],d=s[6];return s[0]*=n,s[1]*=n,s[2]*=n,s[4]*=t,s[5]*=t,s[6]*=t,s[12]+=o*i+r*u,s[13]+=o*l+r*m,s[14]+=o*a+r*d,Ae(s)}function Hr(e,n){return Hn(e,n.width/pn,n.height/pn,n.minX,n.minY)}function Vr(e){return Hn(e,(e.canvasW||1)/kt,(e.canvasH||1)/kt)}function zr(e){let n=Bn(e);return[`transform:matrix3d(${Hr(e,n.bounds)})`,`border-shape:${Nn(n.points)}`].join(";")}function Fr(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,o=e.layerElevation,r=Xe(n.vertices,t,o),s=Je(r);if(!s)return null;let i=e.screenPts[0],l=e.screenPts[1],a=e.screenPts[2],u=e.screenPts[3],m=e.screenPts[4],d=e.screenPts[5],f=a-i,g=u-l,p=m-i,h=d-l,b=f*h-g*p;if(Math.abs(b)<=ae)return null;let x=r[0],A=r[1],M=r[2],P=[A[0]-x[0],A[1]-x[1],A[2]-x[2]],E=[M[0]-x[0],M[1]-x[1],M[2]-x[2]],k=[(P[0]*h-g*E[0])/b,(P[1]*h-g*E[1])/b,(P[2]*h-g*E[2])/b],C=[(f*E[0]-P[0]*p)/b,(f*E[1]-P[1]*p)/b,(f*E[2]-P[2]*p)/b],v=x[0]-k[0]*i-C[0]*l,B=x[1]-k[1]*i-C[1]*l,N=x[2]-k[2]*i-C[2]*l;return{normal:s,matrix:Ae([k[0]*e.canvasW/Ee(e),k[1]*e.canvasW/Ee(e),k[2]*e.canvasW/Ee(e),0,C[0]*e.canvasH/Ee(e),C[1]*e.canvasH/Ee(e),C[2]*e.canvasH/Ee(e),0,s[0],s[1],s[2],0,v,B,N,1])}}function Br(e,n,t,o){if(!n.texture||!t.texture||n.texture!==t.texture)return!1;let r=Fr(n,t);return r?(J(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(J(e,"--pnx",r.normal[0].toFixed(4)),J(e,"--pny",r.normal[1].toFixed(4)),J(e,"--pnz",r.normal[2].toFixed(4))),Le(e,t),!0):!1}function Vn(e,n){J(e,"--pnx",n.normal[0].toFixed(4)),J(e,"--pny",n.normal[1].toFixed(4)),J(e,"--pnz",n.normal[2].toFixed(4))}function Nr(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=ne)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])>ne||Math.abs(t[0])>ne||n[1]-n[0]<=ne||t[1]-t[0]<=ne))return null;for(let r=0;r<e.screenPts.length;r+=2){let s=e.screenPts[r],i=e.screenPts[r+1],l=Math.abs(s-n[0])<=ne||Math.abs(s-n[1])<=ne,a=Math.abs(i-t[0])<=ne||Math.abs(i-t[1])<=ne;if(!l||!a)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function Te(e){return!!Nr(e)}function Qe(e){return!e.texture&&e.polygon.vertices.length===3}function Ve(e){return!e.texture&&!!e.projectiveMatrix&&!Te(e)}function Gt(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 tt(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 vn(e,n){e.set(n,(e.get(n)??0)+1)}function Pn(e){let n,t=1;for(let[o,r]of e)r>t&&(n=o,t=r);return n}function zn(e,n,t,o){let r=new Map,s=new Map,i=new Map,l=!o.has("b"),a=l,u=!o.has("u")&&tt(t),m=!o.has("i")&&Gt(t);for(let g of e)if(!(!g||g.texture)){if(n==="dynamic"){if(!(u&&Qe(g))&&!(l&&Te(g))&&!(a&&Ve(g))&&!m)continue;let p=Me(g.polygon.color??"#cccccc"),h=Xt(p);vn(s,h),i.has(h)||i.set(h,p);continue}!(u&&Qe(g))&&!(l&&Te(g))&&!(a&&Ve(g))&&!m||vn(r,g.shadedColor)}let d=Pn(r),f=Pn(s);return{paintColor:d,dynamicColorKey:f,dynamicColor:f?i.get(f):void 0}}function Fn(){return new Promise(e=>setTimeout(e,0))}async function Lt(e){return performance.now()-e<Ho?e:(await Fn(),performance.now())}function nt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=new Set(n.strategies?.disable??[]),r=Yt(e,n),s=$t(t),i=e.map((l,a)=>Ut(l,a,n,s,r[a]));return zn(i,n.textureLighting??"baked",t,o)}function $r(e,n,t){let o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(let u=0;u<e.length;u+=2){let m=e[u],d=e[u+1];!Number.isFinite(m)||!Number.isFinite(d)||(o=Math.min(o,m),r=Math.min(r,d),s=Math.max(s,m),i=Math.max(i,d))}let l=s-o,a=i-r;return!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(l)||!Number.isFinite(a)||l<=ae||a<=ae?{minX:0,minY:0,width:n,height:t}:{minX:o,minY:r,width:l,height:a}}function Bn(e){let n=e.canvasW||1,t=e.canvasH||1,o=Tt>0?Nt(e.screenPts,Tt):e.screenPts,r=Tt>0?$r(o,n,t):{minX:0,minY:0,width:n,height:t},s=[];for(let i=0;i<o.length;i+=2){let l=Math.max(0,Math.min(100,(o[i]-r.minX)/r.width*100)),a=Math.max(0,Math.min(100,(o[i+1]-r.minY)/r.height*100));s.push([l,a])}return{bounds:r,points:s}}function Xr([e,n]){return`${je(e)} ${je(n)}`}function Yr(e){return`polygon(${e.map(Xr).join(",")})`}function Ur(e){if(tr(e))return"circle(0)";let n=0,t=0,o=Math.max(1,e.length);for(let[i,l]of e)n+=i,t+=l;let r=je(Math.max(0,Math.min(100,n/o))),s=je(Math.max(0,Math.min(100,t/o)));return`circle(0 at ${r} ${s})`}function Nn(e){return`${Yr(e)} ${Ur(e)}`}function $n(e){return Nn(Bn(e).points)}function Wt(e,n,t,o){if(t==="dynamic"){de(e,"color"),de(e,"background"),Vn(e,n);let r=Me(n.polygon.color??"#cccccc");Xt(r)===o?.dynamicColorKey?(de(e,"--psr"),de(e,"--psg"),de(e,"--psb")):(J(e,"--psr",(r.r/255).toFixed(4)),J(e,"--psg",(r.g/255).toFixed(4)),J(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(de(e,"background"),J(e,"color",n.shadedColor)):(de(e,"background"),de(e,"color"))}function Xn(e,n,t,o){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${Vr(e)})`),Le(r,e.polygon),Wt(r,e,n,o),r}function Yn(e,n,t,o){let r=t.createElement("i");return r.setAttribute("style",zr(e)),Le(r,e.polygon),Wt(r,e,n,o),r}function Un(e,n,t,o){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`),Le(r,e.polygon),Wt(r,e,n,o),r}function Gn(e,n,t){let o=t.createElement("s");o.setAttribute("style",`transform:matrix3d(${e.atlasMatrix})`),Le(o,e.polygon);let r=e.canvasW||1,s=e.canvasH||1,i=Ee(e);return J(o,"--polycss-atlas-size",`${i}px`),J(o,"background-position",`${Ie(-e.x/r*i)} ${Ie(-e.y/s*i)}`),J(o,"opacity","0"),n==="dynamic"&&Vn(o,e),o}function Wn(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=new Set(n.strategies?.disable??[]),s=!r.has("b"),i=s,l=!r.has("u")&&tt(t),a=!r.has("i")&&Gt(t),u=Yt(e,n),m=$t(t),d=e.map((P,E)=>Ut(P,E,n,m,u[E])),f=d.map(P=>P&&l&&Qe(P)?et(P.polygon,P.index,n):null),g=d.map((P,E)=>P&&(P.texture||!(s&&Te(P))&&!f[E]&&!(i&&Ve(P))&&!a?P:null)),{packed:p,atlasScale:h}=wn(g,n.textureQuality,t),b=new Map,x=[],A=!1,M=[];for(let P=0;P<e.length;P++){let E=d[P],k=f[P];if(!E)continue;let C=p.entries[P];if(C){let v=Gn(C,o,t);b.set(P,v),x.push({polygonIndex:P,element:v,kind:"atlas",plan:C,dispose:()=>{}})}else if(!E.texture&&s&&Te(E)){let v=Xn(E,o,t,n.solidPaintDefaults);x.push({polygonIndex:P,element:v,kind:"solid",plan:E,dispose:()=>{}})}else if(!E.texture&&k){let v=jt(k,t);x.push({polygonIndex:P,element:v,kind:"triangle",plan:E,dispose:()=>{}})}else if(!E.texture&&i&&Ve(E)){let v=Un(E,o,t,n.solidPaintDefaults);x.push({polygonIndex:P,element:v,kind:"solid",plan:E,dispose:()=>{}})}else if(!E.texture&&a){let v=Yn(E,o,t,n.solidPaintDefaults);x.push({polygonIndex:P,element:v,kind:"border",plan:E,dispose:()=>{}})}}return x.sort((P,E)=>P.polygonIndex-E.polygonIndex),On(p.pages,o,t,h,()=>A).then(P=>{if(A){for(let E of P)E.url?.startsWith("blob:")&&URL.revokeObjectURL(E.url);return}M=P.flatMap(E=>E.url?.startsWith("blob:")?[E.url]:[]);for(let E=0;E<p.pages.length;E++){let k=p.pages[E],C=P[E];if(C)for(let v of k.entries){let B=b.get(v.index);!B||!C.url||(In(B,C,o,v),de(B,"opacity"))}}}).catch(()=>{if(!A)for(let P of b.values())J(P,"opacity","0.5"),J(P,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:x,dispose(){A=!0;for(let P of M)URL.revokeObjectURL(P);M=[]}}}async function jn(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let r=n.textureLighting??"baked",s=new Set(n.strategies?.disable??[]),i=!s.has("b"),l=i,a=!s.has("u")&&tt(o),u=!s.has("i")&&Gt(o);if(await Fn(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let m=Yt(e,n),d=$t(o),f=performance.now(),g=new Array(e.length);for(let C=0;C<e.length;C++)if(g[C]=Ut(e[C],C,n,d,m[C]),f=await Lt(f),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let p=n.solidPaintDefaults??zn(g,r,o,s),h=new Array(g.length),b=new Array(g.length);for(let C=0;C<g.length;C++){let v=g[C],B=v&&a&&Qe(v)?et(v.polygon,v.index,{...n,solidPaintDefaults:p}):null;if(h[C]=B,b[C]=v&&(v.texture||!(i&&Te(v))&&!B&&!(l&&Ve(v))&&!u?v:null),f=await Lt(f),t())return{rendered:[],solidPaintDefaults:p,dispose:()=>{}}}let{packed:x,atlasScale:A}=wn(b,n.textureQuality,o),M=new Map,P=[],E=!1,k=[];for(let C=0;C<e.length;C++){let v=g[C],B=h[C];if(!v)continue;let N=x.entries[C];if(N){let Y=Gn(N,r,o);M.set(C,Y),P.push({polygonIndex:C,element:Y,kind:"atlas",plan:N,dispose:()=>{}})}else if(!v.texture&&i&&Te(v)){let Y=Xn(v,r,o,p);P.push({polygonIndex:C,element:Y,kind:"solid",plan:v,dispose:()=>{}})}else if(!v.texture&&B){let Y=jt(B,o);P.push({polygonIndex:C,element:Y,kind:"triangle",plan:v,dispose:()=>{}})}else if(!v.texture&&l&&Ve(v)){let Y=Un(v,r,o,p);P.push({polygonIndex:C,element:Y,kind:"solid",plan:v,dispose:()=>{}})}else if(!v.texture&&u){let Y=Yn(v,r,o,p);P.push({polygonIndex:C,element:Y,kind:"border",plan:v,dispose:()=>{}})}if(f=await Lt(f),t()){for(let Y of P)Y.dispose();return{rendered:[],solidPaintDefaults:p,dispose:()=>{}}}}return P.sort((C,v)=>C.polygonIndex-v.polygonIndex),On(x.pages,r,o,A,()=>E||t()).then(C=>{if(E||t()){for(let v of C)v.url?.startsWith("blob:")&&URL.revokeObjectURL(v.url);return}k=C.flatMap(v=>v.url?.startsWith("blob:")?[v.url]:[]);for(let v=0;v<x.pages.length;v++){let B=x.pages[v],N=C[v];if(N)for(let Y of B.entries){let te=M.get(Y.index);!te||!N.url||(In(te,N,r,Y),de(te,"opacity"))}}}).catch(()=>{if(!(E||t()))for(let C of M.values())J(C,"opacity","0.5"),J(C,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:P,solidPaintDefaults:p,dispose(){E=!0;for(let C of k)URL.revokeObjectURL(C);k=[]}}}function Gr(e,n){let t=e.map((o,r)=>et(o,r,n));return t.some(o=>!o)?null:t}function Wr(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 Zn(e,n){e.setAttribute("style",n.styleText),(n.polygon.data||Rt.get(e)?.length)&&Le(e,n.polygon)}function jt(e,n){let t=n.createElement("u");return Wr(t),Zn(t,e),Le(t,e.polygon),t}function Zt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};if(!tt(t))return null;let o=Gr(e,n);if(!o)return null;let r=[];for(let s of o){let i=jt(s,t);r.push({polygonIndex:s.index,element:i,kind:"triangle",dispose:()=>{}})}return r.sort((s,i)=>s.polygonIndex-i.polygonIndex),{rendered:r,dispose(){}}}function qn(e,n,t={}){if(e.length!==n.length)return!1;let o=t.textureLighting??"baked",r=[];for(let s=0;s<e.length;s++){let i=e[s];if(i.polygonIndex!==s)return!1;let l=n[s];if(!l)return!1;if(i.kind==="atlas"){if(!i.plan||!Br(i.element,i.plan,l,o))return!1;continue}if(i.kind==="triangle"){let a=et(l,s,t);if(!a)return!1;r[s]=a;continue}return!1}for(let s=0;s<e.length;s++){let i=e[s];if(i.kind==="triangle"){let l=r[s];if(!l)return!1;Zn(i.element,l)}}return!0}import{BASE_TILE as he,normalFacesCamera as jr,parsePureColor as Zr,rotateVec3 as Qn}from"@layoutit/polycss-core";var qr=[.4,-.7,.59],Qr="#ffffff",Kr=1,Jr="#ffffff",es=.4,Jn={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},ts=["t","b","bl","br","fr","fl"],ns=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 Kn(e){let n=[];for(let t of ts)jr(Jn[t],e)&&n.push(t);return n.join("|")}function os(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 rs(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let l=1;l+1<n.length;l+=1){let a=n[l],u=n[l+1],m=a[1]-t[1],d=a[0]-t[0],f=a[2]-t[2],g=u[1]-t[1],p=u[0]-t[0],h=u[2]-t[2];o-=d*h-f*p,r-=f*g-m*h,s-=m*p-d*g}let i=Math.hypot(o,r,s);return i<=1e-9?null:[Math.round(o/i),Math.round(r/i),Math.round(s/i)]}function ss(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=rs(e),t=n?ns.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,s=1/0,i=-1/0,l=-1/0,a=-1/0;for(let d of e.vertices)o=Math.min(o,d[0]),r=Math.min(r,d[1]),s=Math.min(s,d[2]),i=Math.max(i,d[0]),l=Math.max(l,d[1]),a=Math.max(a,d[2]);let u=1e-6,m=e.color||"#cccccc";return Math.abs(a-s)<=u?{axis:"z",face:t,left:r*he,top:o*he,width:Math.max(0,(l-r)*he),height:Math.max(0,(i-o)*he),z:s*he,baseColor:m}:Math.abs(i-o)<=u?{axis:"x",face:t,left:r*he,top:s*he,width:Math.max(0,(l-r)*he),height:Math.max(0,(a-s)*he),z:-o*he,baseColor:m}:Math.abs(l-r)<=u?{axis:"y",face:t,left:s*he,top:o*he,width:Math.max(0,(a-s)*he),height:Math.max(0,(i-o)*he),z:-r*he,baseColor:m}:null}function qt(e){let n=Zr(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 is({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 Qt(e){return Math.round(Math.max(0,Math.min(255,e)))}function as(e,n,t,o){let r=qt(n),s=qt(t?.color??Qr),i=qt(o?.color??Jr),l=t?.direction??qr,a=Math.hypot(l[0],l[1],l[2])||1,u=l[0]/a,m=l[1]/a,d=l[2]/a,f=Math.max(0,t?.intensity??Kr)*Math.max(0,e[0]*u+e[1]*m+e[2]*d),g=Math.max(0,o?.intensity??es),p=i.r/255*g+s.r/255*f,h=i.g/255*g+s.g/255*f,b=i.b/255*g+s.b/255*f,x={r:r.r*p,g:r.g*h,b:r.b*b,alpha:r.alpha};return x.alpha<1?`rgba(${Qt(x.r)}, ${Qt(x.g)}, ${Qt(x.b)}, ${x.alpha})`:is(x)}function ls(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=ss(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return n}function cs(e,n,t,o,r,s){return`matrix3d(${(e==="x"?[o,0,0,0,0,0,r,0,0,-1,0,0,n,-s,t,1]:e==="y"?[0,0,o,0,0,r,0,0,-1,0,0,0,-s,t,n,1]:[o,0,0,0,0,r,0,0,0,0,1,0,n,t,s,1]).map(l=>Number(l.toFixed(6))).join(",")})`}function us(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 ds(e,n){let t=us(e),o=n.meshRotation;o&&(t=Qn(t,o[0]??0,o[1]??0,o[2]??0));let[r,s]=Qn(t,n.rotX,0,n.rotY);return{x:r,y:s}}function ms(e,n,t){let o=e.filter(f=>n.has(f.face)).map(f=>({item:f,...ds(f,t)}));if(o.length===0)return[];let r=1/0,s=-1/0,i=1/0,l=-1/0;for(let f of o)r=Math.min(r,f.x),s=Math.max(s,f.x),i=Math.min(i,f.y),l=Math.max(l,f.y);let a=4,u=Math.max(1e-6,s-r),m=Math.max(1e-6,l-i),d=new Map;for(let f of o){let g=Math.min(a-1,Math.max(0,Math.floor((f.x-r)/u*a))),p=Math.min(a-1,Math.max(0,Math.floor((f.y-i)/m*a))),h=`${g}:${p}`,b=d.get(h);b||(b={tx:g,ty:p,sourceIndex:f.item.sourceIndex,items:[]},d.set(h,b)),b.items.push(f.item),b.sourceIndex=Math.min(b.sourceIndex,f.item.sourceIndex)}return Array.from(d.values()).sort((f,g)=>f.ty-g.ty||f.tx-g.tx||f.sourceIndex-g.sourceIndex).flatMap(f=>f.items)}function eo(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:s}=e,i=ls(o);if(i.length===0)return null;t.classList.add("polycss-voxel-mesh");let l=new Map,a=(p,h)=>{let b=`${p}|${h}`,x=l.get(b);if(x)return x;let A=as(Jn[p],h,r,s);return l.set(b,A),A},u=[],m="",d=0,f=p=>{let h=u[p];return h||(h=n.createElement("b"),u[p]=h),h.parentElement!==t&&t.appendChild(h),h},g=(p,h)=>{let b=new Set(p.split("|").filter(Boolean)),x=ms(i,b,h);d=0;for(let A of x){let M=f(d);os(M,a(A.face,A.baseColor),cs(A.axis,A.left,A.top,A.width,A.height,A.z)),d+=1}for(let A=d;A<u.length;A+=1)u[A]?.remove()};return{element:t,get brushCount(){return d},render(p){m=Kn(p),g(m,p)},syncCamera(p){let h=Kn(p);h!==m&&(m=h,g(h,p))},dispose(){for(let p of u)p.remove();t.classList.remove("polycss-voxel-mesh"),u.length=0,d=0,m=""}}}var to="polycss-styles";function no(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(to))return;let t=n.createElement("style");t.id=to,t.textContent=ps,n.head.appendChild(t)}var ps=`
|
|
1
|
+
import{CAMERA_BACKFACE_CULL_EPS as wo,DEFAULT_SEAM_BLEED as mi,VOXEL_CAMERA_CULL_NORMAL_LIMIT as hl,cameraCullNormalKey as gl,cameraCullVisibleSignature as yl,computeSceneBbox as bl,computeLightVisibility as vl,findOverlappingPolygonDuplicates as ci,inverseRotateVec3 as Lo,isAxisAlignedSurfaceNormal as xl,isVoxelCameraCullableNormalGroups as Pl,normalFacesCamera as Sl,optimizeMeshPolygons as Cl,parseHexColor as El,polygonCssSurfaceNormal as di}from"@layoutit/polycss-core";import{packTextureAtlasPlansWithScaleCore as Xi}from"@layoutit/polycss-core";function Zi(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 Ot(e,n,t){return Xi(e,n,Zi(t))}import{buildTextureEdgeRepairSets as Js,buildSeamBleedPolygonEdges as ea,buildSeamBleedPolygonSet as ta}from"@layoutit/polycss-core";import{TEXTURE_TRIANGLE_BLEED as Qi,TEXTURE_EDGE_REPAIR_ALPHA_MIN as qi,TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN as Ki,TEXTURE_EDGE_REPAIR_RADIUS as No}from"@layoutit/polycss-core";import{expandClipPoints as Ji}from"@layoutit/polycss-core";import{BASIS_EPS as es}from"@layoutit/polycss-core";var mt=new Map;function ts(e){let n=mt.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}),mt.set(e,n),n.then(()=>{mt.get(e)===n&&mt.delete(e)},()=>{mt.get(e)===n&&mt.delete(e)})),n}function Re(e,n,t=1,o=0,r=0,i=1,s=0,c=0){e.setTransform(t*n,o*n,r*n,i*n,s*n,c*n)}function Jn(e){let n=e/255;return n<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function eo(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 ns(e,n,t,o,r,i,s){let c=Math.round(n*s),l=Math.round(t*s),p=Math.max(1,Math.round(o*s)),g=Math.max(1,Math.round(r*s)),x=e.getImageData(c,l,p,g),f=x.data,b=i.r,y=i.g,P=i.b;for(let v=0;v<f.length;v+=4)f[v+3]!==0&&(f[v]=eo(Jn(f[v])*b),f[v+1]=eo(Jn(f[v+1])*y),f[v+2]=eo(Jn(f[v+2])*P));e.putImageData(x,c,l)}function os(e,n,t,o,r,i,s){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,p=Math.max(r/c,i/l),g=c*p,x=l*p;Re(e,s),e.drawImage(n,t+(r-g)/2,o+(i-x)/2,g,x)}function ft(e,n){return Math.max(0,Math.min(n,e))}function Go(e,n,t,o,r,i,s,c){let l=n.naturalWidth||n.width||1,p=n.naturalHeight||n.height||1,g=ft(Math.min(t.minU,t.maxU)*l,l),x=ft(Math.max(t.minU,t.maxU)*l,l),f=ft(Math.min(t.minV,t.maxV)*p,p),b=ft(Math.max(t.minV,t.maxV)*p,p),y=Math.floor(g),P=Math.floor(f),v=Math.ceil(x)-y,C=Math.ceil(b)-P;v<1&&(y=Math.floor(ft((t.minU+t.maxU)/2*l,l-1)),v=1),C<1&&(P=Math.floor(ft((t.minV+t.maxV)/2*p,p-1)),C=1),y=Math.max(0,Math.min(l-1,y)),P=Math.max(0,Math.min(p-1,P)),v=Math.max(1,Math.min(l-y,v)),C=Math.max(1,Math.min(p-P,C)),Re(e,c),e.drawImage(n,y,P,v,C,o,r,i,s)}function Yo(e){return e==="repeat"||e==="mirrored-repeat"}function $o(e,n){return Yo(e)?Math.floor(n):0}function Uo(e,n){return Yo(e)?Math.ceil(n)-1:0}function jo(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function Wo(e,n,t,o,r,i,s){let c=r?$o(i,r.minU):0,l=r?Uo(i,r.maxU):0,p=r?$o(s,r.minV):0,g=r?Uo(s,r.maxV):0;for(let x=c;x<=l;x++)for(let f=p;f<=g;f++){let b=jo(i,x),y=jo(s,f);if(!b&&!y){e.drawImage(n,x*t,f*o);continue}e.save(),e.translate((b?x+1:x)*t,(y?f+1:f)*o),e.scale(b?-1:1,y?-1:1),e.drawImage(n,0,0),e.restore()}}function to(e,n,t,o){for(let r=0;r<o.length;r+=2){let i=n+o[r],s=t+o[r+1];r===0?e.moveTo(i,s):e.lineTo(i,s)}e.closePath()}function qt(e,n,t,o,r,i){for(let s=0;s<o.length;s+=2){let c=n+o[s]+r,l=t+o[s+1]+i;s===0?e.moveTo(c,l):e.lineTo(c,l)}e.closePath()}function rs(e,n,t,o){Re(e,o),e.beginPath(),to(e,n.x,n.y,n.screenPts),e.clip(),Re(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function Kt(e,n,t,o,r){n.polygon.textureAlphaMode==="opaque"&&(Re(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+r,n.canvasW,n.canvasH))}function is(e,n,t,o,r=0,i=0){if(n.textureTriangles?.length){let s=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1;for(let l of n.textureTriangles){let p=Ji(l.screenPts,Qi*(n.bleedRatio??1));e.save(),Re(e,o),e.beginPath(),qt(e,n.x,n.y,p,r,i),e.clip(),Kt(e,n,o,r,i),l.uvAffine?(Re(e,o,l.uvAffine.a/s,l.uvAffine.c/s,l.uvAffine.b/c,l.uvAffine.d/c,n.x+l.uvAffine.e+r,n.y+l.uvAffine.f+i),Wo(e,t,s,c,l.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t)):l.uvSampleRect&&Go(e,t,l.uvSampleRect,n.x+r,n.y+i,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let s=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1,l=n.polygon.textureAlphaMode==="opaque";l&&(e.save(),Re(e,o),e.beginPath(),qt(e,n.x,n.y,n.screenPts,r,i),e.clip(),Kt(e,n,o,r,i)),Re(e,o,n.uvAffine.a/s,n.uvAffine.c/s,n.uvAffine.b/c,n.uvAffine.d/c,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+i),Wo(e,t,s,c,n.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t),l&&e.restore()}else if(n.uvSampleRect){let s=n.polygon.textureAlphaMode==="opaque";s&&(e.save(),Re(e,o),e.beginPath(),qt(e,n.x,n.y,n.screenPts,r,i),e.clip(),Kt(e,n,o,r,i)),Go(e,t,n.uvSampleRect,n.x+r,n.y+i,n.canvasW,n.canvasH,o),s&&e.restore()}else{let s=n.polygon.textureAlphaMode==="opaque";s&&(e.save(),Re(e,o),e.beginPath(),qt(e,n.x,n.y,n.screenPts,r,i),e.clip(),Kt(e,n,o,r,i)),os(e,t,n.x+r,n.y+i,n.canvasW,n.canvasH,o),s&&e.restore()}}function ss(e,n,t,o,r,i){let s=r-t,c=i-o,l=s*s+c*c;if(l<=es)return Math.hypot(e-t,n-o);let p=Math.max(0,Math.min(1,((e-t)*s+(n-o)*c)/l));return Math.hypot(e-(t+s*p),n-(o+c*p))}function as(e,n,t,o){let r=1/0,i=t.length/2;for(let s of o){if(s<0||s>=i)continue;let c=s*2,l=(s+1)%i*2;r=Math.min(r,ss(e,n,t[c],t[c+1],t[l],t[l+1]))}return r}function ls(e,n,t,o,r,i){let s=Math.max(0,o-i),c=Math.min(n-1,o+i),l=Math.max(0,r-i),p=Math.min(t-1,r+i),g=null,x=1/0;for(let f=l;f<=p;f++)for(let b=s;b<=c;b++){if(b===o&&f===r)continue;let y=b-o,P=f-r,v=y*y+P*P;if(v>i*i||v>=x)continue;let C=(f*n+b)*4;e[C+3]<Ki||(g=C,x=v)}return g}function cs(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)),i=Math.max(0,Math.floor(n.y*t)),s=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),c=Math.max(1,Math.min(o.height-i,Math.ceil(n.canvasH*t)));if(s<=0||c<=0)return;let l;try{l=e.getImageData(r,i,s,c)}catch{return}let p=l.data,g=new Uint8ClampedArray(p),x=Math.max(No,No/t),f=Math.max(2,Math.ceil(x*t)+1),b=!1;for(let y=0;y<c;y++)for(let P=0;P<s;P++){let v=(y*s+P)*4,C=p[v+3];if(C<qi||C===255)continue;let F=(r+P+.5)/t-n.x,k=(i+y+.5)/t-n.y;if(as(F,k,n.screenPts,n.textureEdgeRepairEdges)>x)continue;let z=ls(g,s,c,P,y,f);z!==null&&(p[v]=g[z],p[v+1]=g[z+1],p[v+2]=g[z+2],p[v+3]=255,b=!0)}b&&e.putImageData(l,r,i)}function ds(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 us(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 i=e.entries.some(g=>g.textureEdgeRepair&&g.texture&&g.textureEdgeRepairEdges&&g.textureEdgeRepairEdges.size>0),s=r.getContext("2d",i?{willReadFrequently:!0}:void 0);if(!s)return{width:e.width,height:e.height,url:null};let c=Array.from(new Set(e.entries.flatMap(g=>g.texture?[g.texture]:[]))),l=new Map;await Promise.all(c.map(async g=>{l.set(g,await ts(g))}));for(let g of e.entries){let x=g.texture?l.get(g.texture):null;if(!g.texture){s.save(),rs(s,g,n,o),s.restore();continue}x&&(s.save(),Re(s,o),s.beginPath(),to(s,g.x,g.y,g.screenPts),s.clip(),is(s,g,x,o),s.restore()),g.texture&&n==="baked"&&(s.save(),Re(s,o),s.beginPath(),to(s,g.x,g.y,g.screenPts),s.clip(),ns(s,g.x,g.y,g.canvasW,g.canvasH,g.textureTint,o),s.restore()),cs(s,g,o)}let p=await ds(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:p}}async function Ht(e,n,t,o,r){let i=[];for(let s of e){if(r())break;i.push(await us(s,n,t,o))}return i}import{isFullRectSolid as We,isSolidTrianglePlan as et,isProjectiveQuadPlan as Ye,fullRectBounds as bd,safariCssProjectiveUnsupported as Xo,incrementCount as vd,dominantCountKey as xd,filterAtlasPlans as Pd,getSolidPaintDefaultsForPlansCore as ms}from"@layoutit/polycss-core";import{parseHex as fs,rgbKey as hs}from"@layoutit/polycss-core";import{computeTextureAtlasPlan as Td,buildBasisHints as Ad}from"@layoutit/polycss-core";import{resolveProjectiveQuadGuards as ps}from"@layoutit/polycss-core";function ht(e,n){let o=e?.defaultView?.__polycssProjectiveQuadGuards,r=n&&o?{...n,...o}:o??n;return ps(r)}function It(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 Zo(e){if(Qo(e))return!0;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!Xo(t):!0}function Ft(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 Qo(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 gs(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function Xe(e,n){return n?.disable?.includes("u")?null:Qo(e)?"corner-bevel":Zo(e)?gs(e)?"border-large":"border":null}function Vt(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!Xo(t):!0}function Jt(e,n,t,o,r){let i=new Set(o?.disable??[]);return ms(e,n,i,{solidTriangleSupported:Zo(t),projectiveQuadSupported:Vt(t),cornerShapeSupported:Ft(t),borderShapeSupported:It(t)},fs,hs,r)}import{ASYNC_RENDER_BUDGET_MS as Gs,DEFAULT_SEAM_BLEED as gr,DEFAULT_TILE as $s,PROJECTIVE_QUAD_DENOM_EPS as Us,PROJECTIVE_QUAD_MAX_WEIGHT_RATIO as js,PROJECTIVE_QUAD_BLEED as hr,resolveBleedRatio as bo}from"@layoutit/polycss-core";import{buildBasisHints as vo,buildSeamBleedPolygonEdges as Ws,computeTextureAtlasPlan as $t}from"@layoutit/polycss-core";import{cornerShapeGeometryForPlan as Gt}from"@layoutit/polycss-core";import{formatCssLength as en,formatMatrix3dValues as bs,formatSolidQuadMatrix as vs}from"@layoutit/polycss-core";import{shadePolygon as xs}from"@layoutit/polycss-core";import{parseHex as qo,rgbKey as Ko}from"@layoutit/polycss-core";function xe(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(`(^|;)\\s*${i}\\s*:[^;]*`,"i"),c=s.test(o)?o.replace(s,(l,p)=>`${p}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;c!==o&&e.setAttribute("style",c)}function tt(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"),i=t.split(";").map(s=>s.trim()).filter(s=>s&&!r.test(s)).join(";");i?e.setAttribute("style",i):e.removeAttribute("style")}function Bt(e,n,t,o=!1){if(n==="dynamic"){let r=qo(e.polygon.color??"#cccccc"),i=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return Ko(r)!==t?.dynamicColorKey&&(i+=`;--psr:${(r.r/255).toFixed(4)};--psg:${(r.g/255).toFixed(4)};--psb:${(r.b/255).toFixed(4)}`),i}return e.shadedColor?`;color:${e.shadedColor}`:""}function ys(e,n){xe(e,"--pnx",n.normal[0].toFixed(4)),xe(e,"--pny",n.normal[1].toFixed(4)),xe(e,"--pnz",n.normal[2].toFixed(4))}function gt(e,n,t,o){if(t==="dynamic"){tt(e,"color"),tt(e,"background"),ys(e,n);let r=qo(n.polygon.color??"#cccccc");Ko(r)===o?.dynamicColorKey?(tt(e,"--psr"),tt(e,"--psg"),tt(e,"--psb")):(xe(e,"--psr",(r.r/255).toFixed(4)),xe(e,"--psg",(r.g/255).toFixed(4)),xe(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(tt(e,"background"),xe(e,"color",n.shadedColor)):(tt(e,"background"),tt(e,"color"))}import{formatBorderShapeElementStyle as Jo,formatCornerShapeElementStyle as er}from"@layoutit/polycss-core";import{atlasCanonicalSizeForEntry as nt}from"@layoutit/polycss-core";import{computeProjectiveQuadMatrix as Ps,stableBasisFromPlan as Ss}from"@layoutit/polycss-core";import{DEFAULT_LIGHT_DIR as Cs,DEFAULT_LIGHT_COLOR as Es,DEFAULT_LIGHT_INTENSITY as Ts,DEFAULT_AMBIENT_COLOR as As,DEFAULT_AMBIENT_INTENSITY as Ms}from"@layoutit/polycss-core";var tr="polycss-corner-shape-solid",no=new WeakMap,oo=new WeakMap;function ye(e,n,t){let o=no.get(e),r=oo.get(e),i=typeof t=="number";if(!n.data&&!i&&(!o||o.length===0)){e.__polycssHasDataAttrs=!1;return}let s=new Map;if(n.data)for(let[l,p]of Object.entries(n.data))s.set(l,String(p));if(i&&s.set("poly-index",String(t)),o)for(let l of o)s.has(l)||e.removeAttribute(`data-${l}`);for(let[l,p]of s)r?.get(l)!==p&&e.setAttribute(`data-${l}`,p);let c=Array.from(s.keys());c.length>0?no.set(e,c):no.delete(e),s.size>0?oo.set(e,s):oo.delete(e),e.__polycssHasDataAttrs=c.length>0}function yt(e){return e.__polycssHasDataAttrs===!0}function ro(e,n,t,o,r=t==="dynamic"){if(!n.url)return;let i=`url(${n.url})`,s=o.canvasW||1,c=o.canvasH||1,l=nt(o),p=`${en(-o.x/s*l)} ${en(-o.y/c*l)}`,g=`${en(n.width/s*l)} ${en(n.height/c*l)}`,x=`transform:matrix3d(${o.atlasMatrix});--polycss-atlas-size:${l}px`,f=`${x};--polycss-atlas-position:${p};--polycss-atlas-image-size:${g}`;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",f+`;--polycss-atlas-url:${i}`+b)}else e.setAttribute("style",x+`;background-image:${i};background-position:${p};background-size:${g};background-repeat:no-repeat;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`)}function nr(e,n,t,o){if(n.texture){if(!t.texture||n.texture!==t.texture)return!1}else if(t.texture)return!1;let r=or(n,t);return r?(e.style.visibility="",xe(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(xe(e,"--pnx",r.normal[0].toFixed(4)),xe(e,"--pny",r.normal[1].toFixed(4)),xe(e,"--pnz",r.normal[2].toFixed(4))),ye(e,t,n.index),!0):(e.style.visibility="hidden",ye(e,t,n.index),!0)}function io(e,n,t,o,r){if(o!=="baked")return{...e,polygon:n,normal:t};let i=r.directionalLight,s=r.ambientLight,c=i?.direction??Cs,l=i?.color??Es,p=Math.max(0,i?.intensity??Ts),g=s?.color??As,x=Math.max(0,s?.intensity??Ms),f=Math.hypot(c[0],c[1],c[2])||1,b=c[0]/f,y=c[1]/f,P=c[2]/f,C=r.lightOccludedPolyIndices?.has(e.index)??!1?0:p*Math.max(0,t[0]*b+t[1]*y+t[2]*P);return{...e,polygon:n,normal:t,shadedColor:xs(n.color??"#cccccc",C,l,g,x)}}function or(e,n){let t=rr(e,n);if(!t)return null;let{normal:o,xAxis:r,yAxis:i,tx:s,ty:c,tz:l}=t;return{normal:o,matrix:bs([r[0]*e.canvasW/nt(e),r[1]*e.canvasW/nt(e),r[2]*e.canvasW/nt(e),0,i[0]*e.canvasH/nt(e),i[1]*e.canvasH/nt(e),i[2]*e.canvasH/nt(e),0,o[0],o[1],o[2],0,s,c,l,1])}}var rr=Ss;function ws(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=rr(e,n);if(!o)return null;let r=Ps(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return r?{matrix:r,normal:o.normal}:null}function so(e,n,t,o,r=!1){let i=t.createElement("b");return i.setAttribute("style",`transform:matrix3d(${vs(e)})`+Bt(e,n,o,r)),ye(i,e.polygon,e.index),i}function ao(e,n,t,o,r=!1){let i=t.createElement("i");return i.setAttribute("style",Jo(e)+Bt(e,n,o,r)),ye(i,e.polygon,e.index),i}function lo(e,n,t,o,r,i=!1){let s=o.createElement("u");return s.className=tr,s.setAttribute("style",er(e,n)+Bt(e,t,r,i)),ye(s,e.polygon,e.index),s}function co(e,n,t,o,r=!1){let i=t.createElement("b");return i.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+Bt(e,n,o,r)),ye(i,e.polygon,e.index),i}function ir(e,n,t,o,r,i,s){let c=n.projectiveMatrix?ws(n,t,i):or(n,t);if(!c)return!1;let l=io(n,t,c.normal,o,r);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,gt(e,l,o,s),ye(e,l.polygon,l.index),!0}function sr(e,n,t,o){e.style.visibility="",e.setAttribute("style",Jo(n)),gt(e,n,t,o),ye(e,n.polygon,n.index)}function ar(e,n,t,o,r){e.style.visibility="",e.className=tr,e.setAttribute("style",er(n,t)),gt(e,n,o,r),xe(e,"background","currentColor"),ye(e,n.polygon,n.index)}function uo(e,n,t,o=!1){let r=t.createElement("s"),i=nt(e),s=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:${i}px;opacity:0`+s),ye(r,e.polygon,e.index),r}import{computeSolidTriangleColorPlan as Ys}from"@layoutit/polycss-core";import{computeSolidTrianglePlanFromCssPoints as Ls,computeSolidTrianglePlan as _s}from"@layoutit/polycss-core";function at(e,n,t,o={}){let r=o.primitive!=null?void 0:(()=>{let i=t.doc??(typeof document<"u"?document:null);return i?Xe(i,t.strategies)??"border":"border"})();return _s(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??r})}function po(e,n,t,o,r,i,s,c,l,p,g,x,f){let b=o.primitive!=null?void 0:(()=>{let y=t.doc??(typeof document<"u"?document:null);return y?Xe(y,t.strategies)??"border":"border"})();return Ls(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??b},r,i,s,c,l,p,g,x,f)}import{buildSeamBleedPolygonEdges as Rs,DEFAULT_SEAM_BLEED as ks,DEFAULT_TILE as $d,resolveBleedRatio as Ds}from"@layoutit/polycss-core";import{rgbEqual as Os,stepRgbToward as Hs,rgbToCss as Is,colorErrorScore as Fs}from"@layoutit/polycss-core";import{computeSolidTriangleColorPlan as Vs}from"@layoutit/polycss-core";import{stableTriangleMatrixDecimals as lr}from"@layoutit/polycss-core";var Bs="0 48px 96px 48px";function cr(e,n){return Rs(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function dr(e,n,t){let o=Ds(t.seamBleed),r=ks*o,i={...t,bleedRatio:o};return n&&r>0?{...i,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:i}function mo(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 ur(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function bt(e,n,t,o,r,i){return t?i.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:r==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:ur(n,i):!0}function fo(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"?Bs:""),t.__polycssSolidTrianglePrimitive=n)}function ho(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 tn(e,n){e.setAttribute("style",n.styleText),fo(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||yt(e))&&ye(e,n.polygon)}function pr(e,n,t,o){if(!n.colorComputed){(n.polygon.data||yt(e))&&ye(e,n.polygon);return}let r=e,i=n.bakedColor??"",s=n.bakedRgb,c=n.bakedAlpha??1,l=r.__polycssSolidTriangleColor,p=r.__polycssSolidTriangleColorRgb,g=r.__polycssSolidTriangleColorAlpha??1,x=o??ur(n.index,t);if(!t.updatesDisabled&&l!==i&&(l===void 0||x)){let f=i,b=s;if(t.maxStep>0&&p&&s&&g===c){let y=Hs(p,s,t.maxStep);b=y,f=Is(y,c)}(f!==l||!Os(b,p))&&(e.style.color=f),r.__polycssSolidTriangleColor=f,r.__polycssSolidTriangleColorRgb=b,r.__polycssSolidTriangleColorAlpha=c,r.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||yt(e))&&ye(e,n.polygon)}function nn(e,n,t,o){let r=e;fo(e,n.primitive),r.__polycssSolidTriangleBasis!==n.basis&&(r.__polycssSolidTriangleBasis=n.basis),ho(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||yt(e))&&pr(e,n,t,o)}function go(e,n,t,o){ho(e),pr(e,n,t,o)}function on(e,n){let t=e;fo(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),ho(e),e.style.transform=n.transformText,(n.polygon.data||yt(e))&&ye(e,n.polygon)}function zs(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 mr(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 i=zs(e.length,t),s=Math.max(1,Math.floor(t.stableTriangleColorMaxAge??Math.max(2,r*2))),c=[];for(let l=0;l<e.length;l++){let p=e[l],g=n[l];if(p.kind!=="triangle"||!g)continue;let x=p.element,f=x.__polycssSolidTriangleColor,b=g.bakedColor??"";if(f===b)continue;let y=x.__polycssSolidTriangleColorFrame??0,P=Math.max(0,o-y),v=Fs(f,b);c.push({index:l,score:(P>=s?1e6:0)+v*1e4+P})}return c.length===0?new Set:(c.sort((l,p)=>p.score-l.score),new Set(c.slice(0,i).map(l=>l.index)))}function rn(e,n){let t=n.createElement("u");return tn(t,e),ye(t,e.polygon,e.index),t}function Ns(e,n,t){let o=t.createElement("u");return zt(o),ye(o,e,n),o}function fr(e,n,t,o,r,i){let s=t,c=s.stableTriangleDebug,l=o&&r==="color-only";if(s.stableTriangleColorPolicy==="adaptive"||e.length!==n.length)return!1;let p=lr(s.stableTriangleMatrixDecimals),g=t.doc??(typeof document<"u"?document:null),x=g?Xe(g,t.strategies)??"border":"border";for(let b=0;b<e.length;b++){let y=e[b];if(y.kind!=="triangle"||y.polygonIndex!==b||!n[b])return!1}let f=cr(n,t);for(let b=0;b<e.length;b++){let y=e[b].element,P=n[b];if(l){if(bt(y,b,o,c,s.stableTriangleColorPolicy,i)){let C=Vs(P,b,t);if(!C)continue;go(y,C,i)}continue}let v=at(P,b,dr(b,f,t),{basis:y.__polycssSolidTriangleBasis,matrixDecimals:p,primitive:x,includeColor:r!=="plan-only"&&r!=="transform-only"&&bt(y,b,o,c,s.stableTriangleColorPolicy,i)});if(!v){zt(y);continue}o&&r==="plan-only"||(o&&r==="transform-only"?on(y,v):o?nn(y,v,i):tn(y,v))}return!0}function Nt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=Xe(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let r=lr(n.stableTriangleMatrixDecimals),i=[],s=cr(e,n);for(let c=0;c<e.length;c+=1){let l=e[c],p=at(l,c,dr(c,s,n),{matrixDecimals:r,primitive:o}),g=p?rn(p,t):Ns(l,c,t);i.push({polygonIndex:c,element:g,kind:"triangle",dispose:()=>{}})}return{rendered:i,dispose(){}}}import{stableTriangleMatrixDecimals as yr}from"@layoutit/polycss-core";function br(){return new Promise(e=>setTimeout(e,0))}async function yo(e){return performance.now()-e<Gs?e:(await br(),performance.now())}function vr(e,n){let t=bo(n.seamBleed),o=gr*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 xr(e,n){return Ws(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function Pr(e,n,t){let o=bo(t.seamBleed),r=gr*o,i={...t,bleedRatio:o};return n&&r>0?{...i,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:i}function vt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=vo(e,n),r=ht(t),i=e.map((s,c)=>$t(s,c,n,r,o[c]));return Jt(i,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,i=o==="dynamic"&&r.skipDynamicNormalVars===!0,s=new Set(n.strategies?.disable??[]),c=!s.has("b"),l=c&&Vt(t),p=Xe(t,n.strategies),g=p!==null,x=!s.has("i")&&Ft(t),f=!s.has("i")&&It(t),b=vo(e,n),y=ht(t),P=xr(e,n),v=e.map((u,d)=>$t(u,d,Pr(d,P,n),y,b[d]));if(typeof window<"u"){let u=window,d=v[1];u.__vanillaPlan1={matrix:d?.matrix,canvasW:d?.canvasW,canvasH:d?.canvasH,vertexCount:e[1]?.vertices.length}}let C=n.solidPaintDefaults??(r.computeSolidPaintDefaults?Jt(v,o,t,n.strategies):void 0),F=C?{...n,solidPaintDefaults:C}:n,k=v.map(u=>u&&g&&et(u)?at(u.polygon,u.index,vr(u,F),{primitive:p??void 0}):null),z=v.map(u=>u&&x&&!et(u)&&!(c&&We(u))&&!(l&&Ye(u))?Gt(u):null),O=v.map((u,d)=>u&&(u.texture||!(c&&We(u))&&!k[d]&&!(l&&Ye(u))&&!z[d]&&!f?u:null)),{packed:Z,atlasScale:q}=Ot(O,n.textureQuality,t),D=new Map,H=[],V=!1,G=[];for(let u=0;u<e.length;u++){let d=v[u],T=k[u],w=z[u];if(!d)continue;let R=Z.entries[u];if(R){let L=uo(R,o,t,i);D.set(u,L),H.push({polygonIndex:u,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!d.texture&&c&&We(d)){let L=so(d,o,t,C,i);H.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&T){let L=rn(T,t);H.push({polygonIndex:u,element:L,kind:"triangle",plan:d,dispose:()=>{}})}else if(!d.texture&&l&&Ye(d)){let L=co(d,o,t,C,i);H.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&w){let L=lo(d,w,o,t,C,i);H.push({polygonIndex:u,element:L,kind:"corner",plan:d,dispose:()=>{}})}else if(!d.texture&&f){let L=ao(d,o,t,C,i);H.push({polygonIndex:u,element:L,kind:"border",plan:d,dispose:()=>{}})}}H.sort((u,d)=>u.polygonIndex-d.polygonIndex);let A=Ht(Z.pages,o,t,q,()=>V).then(u=>{if(V){for(let d of u)d.url?.startsWith("blob:")&&URL.revokeObjectURL(d.url);return}G=u.flatMap(d=>d.url?.startsWith("blob:")?[d.url]:[]);for(let d=0;d<Z.pages.length;d++){let T=Z.pages[d],w=u[d];if(w)for(let R of T.entries){let L=D.get(R.index);!L||!w.url||ro(L,w,o,R,!0)}}}).catch(()=>{if(!V)for(let u of D.values())xe(u,"opacity","0.5"),xe(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:H,solidPaintDefaults:C??{},pagesReady:A,dispose(){V=!0;for(let u of G)URL.revokeObjectURL(u);G=[]}}}async function sn(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=r==="dynamic"&&n.skipDynamicNormalVars===!0,c=new Set(n.strategies?.disable??[]),l=!c.has("b"),p=l&&Vt(o),g=Xe(o,n.strategies),x=g!==null,f=!c.has("i")&&Ft(o),b=!c.has("i")&&It(o);if(await br(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let y=vo(e,n),P=ht(o),v=xr(e,n),C=performance.now(),F=new Array(e.length);for(let u=0;u<e.length;u++)if(F[u]=$t(e[u],u,Pr(u,v,n),P,y[u]),C=await yo(C),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let k=n.solidPaintDefaults??Jt(F,r,o,n.strategies),z=new Array(F.length),O=new Array(F.length),Z=new Array(F.length);for(let u=0;u<F.length;u++){let d=F[u],T=d&&x&&et(d)?at(d.polygon,d.index,vr(d,{...n,solidPaintDefaults:k}),{primitive:g??void 0}):null;z[u]=T;let w=d&&f&&!et(d)&&!(l&&We(d))&&!(p&&Ye(d))?Gt(d):null;if(O[u]=w,Z[u]=d&&(d.texture||!(l&&We(d))&&!T&&!(p&&Ye(d))&&!w&&!b?d:null),C=await yo(C),t())return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}let{packed:q,atlasScale:D}=Ot(Z,n.textureQuality,o),H=new Map,V=[],G=!1,A=[];for(let u=0;u<e.length;u++){let d=F[u],T=z[u],w=O[u];if(!d)continue;let R=q.entries[u];if(R){let L=uo(R,r,o,s);H.set(u,L),V.push({polygonIndex:u,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!d.texture&&l&&We(d)){let L=so(d,r,o,k,s);V.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&T){let L=rn(T,o);V.push({polygonIndex:u,element:L,kind:"triangle",plan:d,dispose:()=>{}})}else if(!d.texture&&p&&Ye(d)){let L=co(d,r,o,k,s);V.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&w){let L=lo(d,w,r,o,k,s);V.push({polygonIndex:u,element:L,kind:"corner",plan:d,dispose:()=>{}})}else if(!d.texture&&b){let L=ao(d,r,o,k,s);V.push({polygonIndex:u,element:L,kind:"border",plan:d,dispose:()=>{}})}if(C=await yo(C),t()){for(let L of V)L.dispose();return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}}V.sort((u,d)=>u.polygonIndex-d.polygonIndex);let h=Ht(q.pages,r,o,D,()=>G||t()).then(u=>{if(G||t()){for(let d of u)d.url?.startsWith("blob:")&&URL.revokeObjectURL(d.url);return}A=u.flatMap(d=>d.url?.startsWith("blob:")?[d.url]:[]);for(let d=0;d<q.pages.length;d++){let T=q.pages[d],w=u[d];if(w)for(let R of T.entries){let L=H.get(R.index);!L||!w.url||ro(L,w,r,R,!0)}}}).catch(()=>{if(!(G||t()))for(let u of H.values())xe(u,"opacity","0.5"),xe(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:V,solidPaintDefaults:k,pagesReady:h,dispose(){G=!0;for(let u of A)URL.revokeObjectURL(u);A=[]}}}function an(e,n,t,o={}){let r=o.textureLighting??"baked",i=o,s=i.optimizeStableTriangleStyle===!0&&r==="baked";if(!s||i.stableTriangleColorPolicy==="adaptive"||e.length!==t.polygonCount||n.length!==t.polygonCount||t.vertices.length<t.polygonCount*9)return!1;let c=i.stableTriangleDebug,l=i.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full");if(l==="color-only")return!1;let p=yr(i.stableTriangleMatrixDecimals),g=mo(i),x=o.tileSize??$s,f=o.layerElevation??x,b=o.doc??(typeof document<"u"?document:null),y=b?Xe(b,o.strategies)??"border":"border";for(let v=0;v<e.length;v++){let C=e[v],F=n[v];if(C.kind!=="triangle"||C.polygonIndex!==v||!F||F.vertices.length!==3||F.texture||F.material?.texture)return!1}let P=t.vertices;for(let v=0;v<e.length;v++){let C=e[v].element,F=n[v],k=v*9,z=P[k+1]*x,O=P[k]*x,Z=P[k+2]*f,q=P[k+4]*x,D=P[k+3]*x,H=P[k+5]*f,V=P[k+7]*x,G=P[k+6]*x,A=P[k+8]*f,h=po(F,v,o,{basis:C.__polycssSolidTriangleBasis,matrixDecimals:p,primitive:y,color:t.colors?.[v],includeColor:l!=="plan-only"&&l!=="transform-only"&&bt(C,v,s,c,i.stableTriangleColorPolicy,g)},z,O,Z,q,D,H,V,G,A);if(!h){zt(C);continue}l!=="plan-only"&&(l==="transform-only"?on(C,h):nn(C,h,g))}return!0}function ln(e,n,t={}){if(e.length!==n.length)return!1;let o=t,r=t.doc??(typeof document<"u"?document:null),i=t.textureLighting??"baked",s=new Set(t.strategies?.disable??[]),c=!s.has("b"),l=!!r&&c&&Vt(r),p=!!r&&!s.has("i")&&Ft(r),g=!!r&&!s.has("i")&&It(r),x=bo(o.seamBleed),f=r?ht(r,{bleed:hr*x}):{denomEps:Us,maxWeightRatio:js,bleed:hr*x,disableGuards:!1},b=o.optimizeStableTriangleStyle===!0&&i==="baked",y=o.stableTriangleDebug,P=o.stableTriangleUpdateMode??(y==="plan-only"||y==="transform-only"?y:"full"),v=b&&P==="color-only",C=mo(o),F=yr(o.stableTriangleMatrixDecimals),k=r?Xe(r,t.strategies)??"border":"border";if(fr(e,n,t,b,P,C))return!0;let z=[],O=[],Z=[];for(let D=0;D<e.length;D++){let H=e[D];if(H.polygonIndex!==D)return!1;let V=n[D];if(!V||v&&H.kind!=="triangle")return!1;if(H.kind==="atlas"){if(!H.plan||!nr(H.element,H.plan,V,i))return!1;continue}if(H.kind==="triangle"){let G=H.element;if(v){let h=o.stableTriangleColorPolicy==="adaptive"||bt(G,D,b,y,o.stableTriangleColorPolicy,C);O[D]=h?Ys(V,D,t):null;continue}let A=at(V,D,t,{basis:G.__polycssSolidTriangleBasis,matrixDecimals:F,primitive:k,includeColor:P!=="plan-only"&&P!=="transform-only"&&bt(G,D,b,y,o.stableTriangleColorPolicy,C)});if(!A){z[D]=null;continue}z[D]=A;continue}if(H.kind==="solid"){if(!H.plan||V.texture||V.vertices.length!==H.plan.polygon.vertices.length)return!1;Z[D]=H.plan;continue}if(H.kind==="border"){let G=$t(V,D,t,f);if(!G||G.texture||!g||c&&We(G)||l&&Ye(G)||p&&Gt(G))return!1;Z[D]=G;continue}if(H.kind==="corner"){let G=$t(V,D,t,f);if(!G||G.texture||!p||et(G)||c&&We(G)||l&&Ye(G)||!Gt(G))return!1;Z[D]=G;continue}return!1}let q=b&&P!=="plan-only"&&P!=="transform-only"?mr(e,v?O:z,o):null;for(let D=0;D<e.length;D++){let H=e[D];if(H.kind==="triangle"){if(v){let G=O[D];G&&go(H.element,G,C,q?.has(D));continue}let V=z[D];if(!V){zt(H.element);continue}if(b&&P==="plan-only")continue;b&&P==="transform-only"?on(H.element,V):b?nn(H.element,V,C,q?.has(D)):tn(H.element,V)}else if(H.kind==="solid"){let V=Z[D];if(!V||!ir(H.element,V,n[D],i,t,f,o.solidPaintDefaults))return!1}else if(H.kind==="border"){let V=Z[D];if(!V)return!1;sr(H.element,V,i,o.solidPaintDefaults)}else if(H.kind==="corner"){let V=Z[D],G=V?Gt(V):null;if(!V||!G)return!1;ar(H.element,V,G,i,o.solidPaintDefaults)}}return!0}import{computeTextureAtlasPlanPublic as na}from"@layoutit/polycss-core";import{formatMatrix3d as oa,formatCssLengthPx as ra,formatSolidQuadEntryMatrix as ia}from"@layoutit/polycss-core";import{formatBorderShapeEntryMatrix as sa,cssBorderShapeForPlan as aa}from"@layoutit/polycss-core";import{BASE_TILE as Pe,computeProjectiveQuadMatrix as la,normalFacesCamera as ca,parsePureColor as Mr,PROJECTIVE_QUAD_BLEED as da,resolveProjectiveQuadGuards as ua,rotateVec3 as pa,rotateVec3InWrapperCssFrame as ma,shadePolygon as fa,SOLID_QUAD_CANONICAL_SIZE as ha}from"@layoutit/polycss-core";var ga=[.4,-.7,.59],ya="#ffffff",ba=1,va="#ffffff",xa=.4,wr=1,Pa=8,Sa=da,Ke=1e-6,Ca=ua({bleed:0}),Lr={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},So=["t","b","bl","br","fr","fl"],Ea=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 Sr(e){let n=[];for(let t of So)ca(Lr[t],e)&&n.push(t);return n.join("|")}function Ta(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 Aa(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,i=0;for(let c=1;c+1<n.length;c+=1){let l=n[c],p=n[c+1],g=l[1]-t[1],x=l[0]-t[0],f=l[2]-t[2],b=p[1]-t[1],y=p[0]-t[0],P=p[2]-t[2];o-=x*P-f*y,r-=f*b-g*P,i-=g*y-x*b}let s=Math.hypot(o,r,i);return s<=1e-9?null:[Math.round(o/s),Math.round(r/s),Math.round(i/s)]}function Ma(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=Aa(e),t=n?Ea.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,i=1/0,s=-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]),i=Math.min(i,x[2]),s=Math.max(s,x[0]),c=Math.max(c,x[1]),l=Math.max(l,x[2]);let p=1e-6,g=Oa(e.color);return Math.abs(l-i)<=p?{axis:"z",face:t,left:r*Pe,top:o*Pe,width:Math.max(0,(c-r)*Pe),height:Math.max(0,(s-o)*Pe),z:i*Pe,baseColor:g,bleed:xo()}:Math.abs(s-o)<=p?{axis:"x",face:t,left:r*Pe,top:i*Pe,width:Math.max(0,(c-r)*Pe),height:Math.max(0,(l-i)*Pe),z:-o*Pe,baseColor:g,bleed:xo()}:Math.abs(c-r)<=p?{axis:"y",face:t,left:i*Pe,top:o*Pe,width:Math.max(0,(l-i)*Pe),height:Math.max(0,(s-o)*Pe),z:-r*Pe,baseColor:g,bleed:xo()}:null}function xo(){return{left:0,right:0,top:0,bottom:0}}function wa(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 Cr(e){return[e[1]*Pe,e[0]*Pe,e[2]*Pe]}function Er(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function La(e,n,t){let o=e.left,r=e.left+e.width,i=e.top,s=e.top+e.height;if(Math.abs(n[0]-t[0])<=Ke){if(Math.abs(n[0]-o)<=Ke)return"left";if(Math.abs(n[0]-r)<=Ke)return"right"}if(Math.abs(n[1]-t[1])<=Ke){if(Math.abs(n[1]-i)<=Ke)return"top";if(Math.abs(n[1]-s)<=Ke)return"bottom"}return null}function _a(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=Ke)){if(t!==null)return null;t=o}return t}function Ra(e,n,t){let o=n.vertices,r=Cr(o[t]),i=Cr(o[(t+1)%o.length]),s=La(e,Er(e,r),Er(e,i));if(!s)return null;let c=_a(r,i);if(c===null)return null;let l=Math.min(r[c],i[c]),p=Math.max(r[c],i[c]);return p-l>Ke?{item:e,side:s,variableAxis:c,fixed:r,start:l,end:p}:null}function Tr(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],Sa)}function ka(e,n){let t=new Map;for(let o of n){let r=e[o.sourceIndex];if(r)for(let i=0;i<r.vertices.length;i+=1){let s=Ra(o,r,i);if(!s)continue;let c=wa(s),l=t.get(c);l?l.push(s):t.set(c,[s])}}for(let o of t.values()){if(o.length<2)continue;o.sort((i,s)=>i.start-s.start||i.end-s.end);let r=[];for(let i of o){r=r.filter(s=>s.end>i.start+Ke);for(let s of r)s.item.sourceIndex!==i.item.sourceIndex&&(Tr(s),Tr(i));r.push(i)}}}function Da(e){let n=Mr(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 Oa(e){if(!e)return"#cccccc";let n=Mr(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(${Po(t.r)}, ${Po(t.g)}, ${Po(t.b)}, ${o})`}return Ha(t)}function Ha({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 Po(e){return Math.round(Math.max(0,Math.min(255,e)))}function Ia(e,n,t,o){let r=t?.direction??ga,i=Math.hypot(r[0],r[1],r[2])||1,s=r[0]/i,c=r[1]/i,l=r[2]/i,p=Math.max(0,t?.intensity??ba)*Math.max(0,e[0]*s+e[1]*c+e[2]*l),g=Math.max(0,o?.intensity??xa),x=t?.color??ya,f=o?.color??va,b=fa(n,p,x,f,g),y=Da(n);if(y.alpha>=1)return b;let P=parseInt(b.slice(1,3),16),v=parseInt(b.slice(3,5),16),C=parseInt(b.slice(5,7),16);return`rgba(${P}, ${v}, ${C}, ${y.alpha})`}function Fa(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=Ma(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return ka(e,n),n}function Va(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 Ba(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 za(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function Na(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(r=>!Number.isFinite(r)))return null;let o=ha/n;for(let r=0;r<8;r+=1)t[r]*=o;return`matrix3d(${t.map(r=>Number(r.toFixed(6))).join(",")})`}function Ar(e,n){let t=e.left-e.bleed.left,o=e.top-e.bleed.top,r=e.width+e.bleed.left+e.bleed.right,i=e.height+e.bleed.top+e.bleed.bottom,s=e.z,c=r/n,l=i/n;return`matrix3d(${(e.axis==="x"?[c,0,0,0,0,0,l,0,0,-1,0,0,t,-s,o,1]:e.axis==="y"?[0,0,c,0,0,l,0,0,-1,0,0,0,-s,o,t,1]:[c,0,0,0,0,l,0,0,0,0,1,0,t,o,s,1]).map(g=>Number(g.toFixed(6))).join(",")})`}function Ga(e,n){let{xAxis:t,yAxis:o,normal:r,tx:i,ty:s,tz:c}=Va(e),l=la(Ba(e),t,o,r,i,s,c,Ca,za(e));return l?Na(l,n)??Ar(e,n):Ar(e,n)}function $a(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function Ua(e){return $a(e)?Pa:wr}function ja(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 Wa(e,n){let t=ja(e),o=n.meshRotation;o&&(t=ma(t,o));let[r,i]=pa(t,n.rotX,0,n.rotY);return{x:r,y:i}}function Ya(e,n,t){let o=e.filter(f=>n.has(f.face)).map(f=>({item:f,...Wa(f,t)}));if(o.length===0)return[];let r=1/0,i=-1/0,s=1/0,c=-1/0;for(let f of o)r=Math.min(r,f.x),i=Math.max(i,f.x),s=Math.min(s,f.y),c=Math.max(c,f.y);let l=4,p=Math.max(1e-6,i-r),g=Math.max(1e-6,c-s),x=new Map;for(let f of o){let b=Math.min(l-1,Math.max(0,Math.floor((f.x-r)/p*l))),y=Math.min(l-1,Math.max(0,Math.floor((f.y-s)/g*l))),P=`${b}:${y}`,v=x.get(P);v||(v={tx:b,ty:y,sourceIndex:f.item.sourceIndex,items:[]},x.set(P,v)),v.items.push(f.item),v.sourceIndex=Math.min(v.sourceIndex,f.item.sourceIndex)}return Array.from(x.values()).sort((f,b)=>f.ty-b.ty||f.tx-b.tx||f.sourceIndex-b.sourceIndex).flatMap(f=>f.items)}function _r(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:i}=e,s=Fa(o);if(s.length===0)return null;let c=new Set(s.map(h=>h.face));t.classList.add("polycss-voxel-mesh");let l=Ua(n);l!==wr&&t.style.setProperty("--polycss-voxel-primitive",`${l}px`);let p=new Map,g=(h,u)=>{let d=`${h}|${u}`,T=p.get(d);if(T)return T;let w=Ia(Lr[h],u,r,i);return p.set(d,w),w},x=new Map,f=new Map,b=new Map,y=new Map;for(let h of s){let u=y.get(h.face);u||(u=[],y.set(h.face,u)),u.push(h)}let P="",v=0,C=new Set,F=h=>{let u=x.get(h.sourceIndex);return u||(u=n.createElement("b"),x.set(h.sourceIndex,u),Ta(u,g(h.face,h.baseColor),Ga(h,l))),u},k=h=>{let u=f.get(h);return u||(u=n.createElement("span"),u.className=`polycss-voxel-face polycss-voxel-face-${h}`,u.dataset.polycssVoxelFace=h,u.__polycssVoxelFaceHost=!0,f.set(h,u)),u},z=()=>{for(let h of Array.from(t.childNodes))if(!h.__polycssVoxelFaceHost)return h;return null},O=(h,u)=>{let d=u.map(R=>R.sourceIndex).join(",");if(b.get(h)===d)return;let T=k(h),w=n.createDocumentFragment();for(let R of u)w.appendChild(F(R));T.replaceChildren(w),b.set(h,d)},Z=()=>{for(let h of So)c.has(h)&&O(h,y.get(h)??[])},q=h=>new Set(h.split("|").filter(Boolean)),D=h=>{let u=q(h);return So.filter(d=>u.has(d)&&c.has(d))},H=h=>{let u=0;for(let d of h)u+=y.get(d)?.length??0;return u},V=h=>{let u=new Set,d=[],T=new Map;for(let w of h){u.has(w.face)||(u.add(w.face),d.push(w.face));let R=T.get(w.face);R||(R=[],T.set(w.face,R)),R.push(w)}return{orderedFaces:d,itemsByFace:T}},G=(h,u)=>{let d=new Set(h);for(let T of C){if(d.has(T))continue;let w=f.get(T);w?.parentNode===t&&t.removeChild(w)}if(u){let T=n.createDocumentFragment();for(let w of h)T.appendChild(k(w));t.insertBefore(T,z()),C=d;return}for(let T=0;T<h.length;T+=1){let w=h[T],R=k(w);if(R.parentNode===t)continue;let L=null;for(let te=T+1;te<h.length;te+=1){let _=f.get(h[te]);if(_?.parentNode===t){L=_;break}}t.insertBefore(R,L??z())}C=d},A=(h,u,d)=>{if(!d){let te=D(h);G(te,!1),v=H(te);return}let T=new Set(h.split("|").filter(Boolean)),w=Ya(s,T,u),{orderedFaces:R,itemsByFace:L}=V(w);for(let te of R)O(te,L.get(te)??[]);G(R,!0),v=w.length};return Z(),{get brushCount(){return v},render(h){P=Sr(h),A(P,h,!0)},syncCamera(h){let u=Sr(h);u!==P&&(P=u,A(u,h,!1))},dispose(){for(let h of f.values())h.remove();t.classList.remove("polycss-voxel-mesh"),t.style.removeProperty("--polycss-voxel-primitive"),x.clear(),f.clear(),b.clear(),v=0,C=new Set,P=""}}}var Rr="polycss-styles";function kr(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(Rr))return;let t=n.createElement("style");t.id=Rr,t.textContent=Xa,n.head.appendChild(t)}var Xa=`
|
|
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 @@ import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as
|
|
|
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 @@ import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as
|
|
|
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 @@ import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as
|
|
|
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
|
|
30
|
-
scene.
|
|
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 @@ import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as
|
|
|
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
|
-
|
|
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 @@ import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as
|
|
|
81
112
|
height: 64px;
|
|
82
113
|
}
|
|
83
114
|
|
|
84
|
-
.polycss-mesh.polycss-voxel-mesh >
|
|
115
|
+
.polycss-mesh.polycss-voxel-mesh > .polycss-voxel-face {
|
|
116
|
+
position: absolute;
|
|
117
|
+
display: block;
|
|
118
|
+
top: 0;
|
|
119
|
+
left: 0;
|
|
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 {
|
|
85
132
|
top: 0;
|
|
86
133
|
left: 0;
|
|
87
|
-
width: 1px;
|
|
88
|
-
height: 1px;
|
|
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 @@ import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as
|
|
|
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
|
|
158
|
+
border-width: 0 16px 32px 16px;
|
|
112
159
|
}
|
|
113
160
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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 @@ import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as
|
|
|
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
|
|
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 @@ import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as
|
|
|
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 * (
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
calc(255 * (
|
|
311
|
-
|
|
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 *
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
|
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
|
-
*
|
|
333
|
-
* ground plane (cssZ \u2248 G) along the CSS-space
|
|
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
|
|
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 @@ import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as
|
|
|
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
|
|
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,10 @@ import{BASE_TILE as fs,CAMERA_BACKFACE_CULL_EPS as Kt,cameraCullNormalGroups as
|
|
|
371
510
|
);
|
|
372
511
|
}
|
|
373
512
|
|
|
374
|
-
/* <q>
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
jump quickly to 1, giving a near-binary visibility decision with a
|
|
379
|
-
smooth edge transition. Pure CSS calc \u2014 no JS at light-change time.
|
|
380
|
-
|
|
381
|
-
The base layout / positioning / pseudo-element-strip rules for <q>
|
|
382
|
-
live in the polygon-leaf section above. This rule only adds the
|
|
383
|
-
dynamic-light Lambert gating, separated so it's easy to disable the
|
|
384
|
-
gate for debugging by commenting out a single block. */
|
|
385
|
-
.polycss-scene q {
|
|
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 {
|
|
386
517
|
opacity: clamp(0, calc((var(--pnx) * var(--clx) + var(--pny) * var(--cly) + var(--pnz) * var(--clz)) * 10), 1);
|
|
387
518
|
}
|
|
388
|
-
`;var Es=750,As=8e3;var ot=65,rt=45,Ms=1,_e=fs;function Cs(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let r of t)if(!o.includes(r))return!1;return!0}function so(e){let n=[];return e.position&&n.push(`translate3d(${e.position[0]}px, ${e.position[1]}px, ${e.position[2]}px)`),e.scale!==void 0&&(typeof e.scale=="number"?e.scale!==1&&n.push(`scale3d(${e.scale}, ${e.scale}, ${e.scale})`):n.push(`scale3d(${e.scale[0]}, ${e.scale[1]}, ${e.scale[2]})`)),e.rotation&&(e.rotation[0]&&n.push(`rotateX(${e.rotation[0]}deg)`),e.rotation[1]&&n.push(`rotateY(${e.rotation[1]}deg)`),e.rotation[2]&&n.push(`rotateZ(${e.rotation[2]}deg)`)),n.length>0?n.join(" "):void 0}function Ss(e,n=[0,0,0],t=1){let o=e.rotX??ot,r=e.rotY??rt,s=(e.zoom??Ms)*t,i=(e.distance??0)*t,l=e.target??[0,0,0],a=l[0]+n[0],u=l[1]+n[1],m=l[2]+n[2],d=u*_e,f=a*_e,g=m*_e;return`${i!==0?`translateZ(${-i}px) `:""}scale(${s}) rotateX(${o}deg) rotate(${r}deg) translate3d(${-d}px, ${-f}px, ${-g}px)`}function ws(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 Ts(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=ws(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function en(e,n){return n===1?e:e*n}function Ls(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}var _s=.1;function Rs(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let d=1;d+1<e.vertices.length;d++){let f=e.vertices[d],g=e.vertices[d+1],p=f[1]-n[1],h=f[0]-n[0],b=f[2]-n[2],x=g[1]-n[1],A=g[0]-n[0],M=g[2]-n[2];t-=h*M-b*A,o-=b*x-p*M,r-=p*A-h*x}let s=Math.hypot(t,o,r);if(s<1e-9)return null;t/=s,o/=s,r/=s;let i=1/_s,l=Math.round(t*i)/i,a=Math.round(o*i)/i,u=Math.round(r*i)/i,m=Math.hypot(l,a,u);return m<1e-9?null:{key:l+","+a+","+u,vec:[l/m,a/m,u/m]}}function io(e,n={}){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");e.ownerDocument&&no(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let t={...n},o=Ts(e),r=[0,0,0],s=e.ownerDocument??document,i=s.createElement("div");i.className="polycss-scene",i.setAttribute("aria-hidden","true"),a(i,t),e.appendChild(i);let l=new Set;function a(c,y){Ls(c,o),c.style.transform=Ss(y,r,o),typeof y.perspective=="number"?c.style.perspective=`${en(y.perspective,o)}px`:y.perspective===!1?c.style.perspective=`${en(1e6,o)}px`:Math.abs(o-1)<1e-6?c.style.removeProperty("perspective"):c.style.perspective=`${en(As,o)}px`,u(c,y)}function u(c,y){let R=y.textureLighting==="dynamic";c.dataset.polycssLighting=y.textureLighting??"baked";let T=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"];if(!R){for(let me of T)c.style.removeProperty(me);return}let I=y.directionalLight?.direction??[.4,-.7,.59],D=Math.hypot(I[0],I[1],I[2])||1,z=I[0]/D,G=I[1]/D,ee=I[2]/D,q=Jt(y.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],Q=Jt(y.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],W=y.directionalLight?.intensity??1,L=y.ambientLight?.intensity??.4,Z=me=>(me/255).toFixed(4);c.style.setProperty("--plx",z.toFixed(4)),c.style.setProperty("--ply",G.toFixed(4)),c.style.setProperty("--plz",ee.toFixed(4)),c.style.setProperty("--plr",Z(q[0])),c.style.setProperty("--plg",Z(q[1])),c.style.setProperty("--plb",Z(q[2])),c.style.setProperty("--pli",W.toFixed(4)),c.style.setProperty("--par",Z(Q[0])),c.style.setProperty("--pag",Z(Q[1])),c.style.setProperty("--pab",Z(Q[2])),c.style.setProperty("--pai",L.toFixed(4));let F=ee,K=Math.sign(F||1)*Math.max(Math.abs(F),.01);c.style.setProperty("--clx",z.toFixed(4)),c.style.setProperty("--cly",G.toFixed(4)),c.style.setProperty("--clz",K.toFixed(4))}function m(c){c.voxelRenderer?.dispose(),c.voxelRenderer=void 0,h(c.rendered,c.disposeAtlas),c.disposeAtlas=void 0,c.rendered.length=0,c.cameraCullGroups.length=0,c.cameraCullSignature="",p(c);for(let y of Array.from(c.wrapper.children))y instanceof HTMLElement&&y.classList.contains("polycss-bucket")&&y.remove()}function d(c){for(let y of Array.from(c.wrapper.childNodes)){if(!(y instanceof HTMLElement))return y;if(y.classList.contains("polycss-bucket")||y.classList.contains("polycss-shadow"))continue;let R=y.tagName.toLowerCase();if(!(R==="b"||R==="i"||R==="s"||R==="u"||R==="q"))return y}return null}function f(c,y,R){R?.parentNode===c.wrapper?c.wrapper.insertBefore(y,R):c.wrapper.appendChild(y)}function g(c){return Array.from(c.children).some(y=>y instanceof HTMLElement&&y.classList.contains("polycss-bucket"))}function p(c){for(let y of c.shadowRendered)y.parentNode&&y.parentNode.removeChild(y);c.shadowRendered.length=0}function h(c,y){y?.();for(let R of c){try{R.dispose()}catch{}R.element.parentNode&&R.element.parentNode.removeChild(R.element)}}function b(c){for(let y of Array.from(c.wrapper.children))y instanceof HTMLElement&&y.classList.contains("polycss-bucket")&&y.remove();for(let y of c.rendered)y.element.parentNode&&y.element.parentNode.removeChild(y.element)}function x(c,y){let R=c.polygons[y.polygonIndex];return c.stableDom&&R?ro(R):y.plan?.normal??(R?ro(R):null)}function A(c){if(!C(c))return c.rendered;let y=M(c);return c.rendered.filter(R=>P(c,R,Kt,y))}function M(c){return{rotX:t.rotX??ot,rotY:t.rotY??rt,meshRotation:c.handle.transform.rotation}}function P(c,y,R=Kt,T=M(c)){let I=x(c,y);return I===null||Ps(I,T,R)}function E(c){c.cameraCullGroups=hs(c.rendered.map(y=>x(c,y)))}function k(c){return C(c)?gs(c.cameraCullGroups,M(c)):"all"}function C(c){return!c.excludeFromAutoCenter&&xs(c.cameraCullGroups)}function v(c){c.cameraCullSignature=C(c)?k(c):"all"}function B(c,y){let R=new Array(c.rendered.length),T=!1,I=M(c);for(let W=0;W<c.rendered.length;W+=1){let L=c.rendered[W],Z=P(c,L,y,I);R[W]=Z}let D=null,z=null,G=()=>{if(!(!D||!z)){if(D===z)D.remove();else{let W=s.createRange();W.setStartBefore(D),W.setEndAfter(z),W.deleteContents(),W.detach()}D=null,z=null,T=!0}};for(let W=0;W<c.rendered.length;W+=1){let L=c.rendered[W];!R[W]&&L.element.parentNode===c.wrapper?(z&&z.nextSibling===L.element||(G(),D=L.element),z=L.element):G()}G();let ee=W=>{for(let L=W;L<c.rendered.length;L+=1){let Z=c.rendered[L].element;if(Z.parentNode===c.wrapper)return Z}return d(c)},q=-1,Q=W=>{if(q<0)return;let L=s.createDocumentFragment();for(let Z=q;Z<W;Z+=1){let F=c.rendered[Z];S(c,F),L.appendChild(F.element)}f(c,L,ee(W)),q=-1,T=!0};for(let W=0;W<c.rendered.length;W+=1){let L=c.rendered[W];R[W]&&L.element.parentNode!==c.wrapper?q<0&&(q=W):Q(W)}return Q(c.rendered.length),T}function N(c,y=!1){if(c.voxelRenderer){c.voxelRenderer.syncCamera(M(c)),c.cameraCullSignature="voxel-direct";return}if(!C(c)){let I=c.cameraCullSignature!=="all";c.cameraCullSignature="all",I&&ie(c);return}if(g(c.wrapper)){Y(c,y);return}let R=k(c);if(!y&&R===c.cameraCullSignature)return;let T=B(c,Kt);c.cameraCullSignature=R,T&&j(c)}function Y(c,y=!1){let R=C(c)?k(c):"all";!y&&R===c.cameraCullSignature||ie(c)}function te(c,y){return x(c,y)}function S(c,y){if(t.textureLighting!=="dynamic")return;let R=te(c,y);R&&(y.element.style.setProperty("--pnx",R[0].toFixed(4)),y.element.style.setProperty("--pny",R[1].toFixed(4)),y.element.style.setProperty("--pnz",R[2].toFixed(4)))}function $(c){b(c);let y=s.createDocumentFragment(),R=t.textureLighting==="dynamic"&&!c.stableDom,T=new Map,I=[];for(let D of A(c)){let z=c.polygons[D.polygonIndex],G=R&&z?Rs(z):null;if(!G){I.push(D);continue}let ee=G.key+"|"+(z.color??""),q=T.get(ee);q||(q={vec:G.vec,items:[]},T.set(ee,q)),q.items.push(D)}for(let D of I)S(c,D),y.appendChild(D.element);for(let D of T.values()){if(D.items.length<2){for(let G of D.items)S(c,G),y.appendChild(G.element);continue}let z=s.createElement("div");z.className="polycss-bucket",z.style.setProperty("--pnx",String(D.vec[0])),z.style.setProperty("--pny",String(D.vec[1])),z.style.setProperty("--pnz",String(D.vec[2]));for(let G of D.items)z.appendChild(G.element),G.element.style.removeProperty("--pnx"),G.element.style.removeProperty("--pny"),G.element.style.removeProperty("--pnz");y.appendChild(z)}f(c,y,d(c)),v(c)}function w(){return new Promise(c=>setTimeout(c,0))}async function O(c,y){if(t.textureLighting==="dynamic"&&!c.stableDom)return $(c),!y();b(c);let T=s.createDocumentFragment(),I=d(c),D=0;for(let z of A(c)){if(y())return!1;S(c,z),T.appendChild(z.element),D++,D%Es===0&&(f(c,T,I),T=s.createDocumentFragment(),await w())}return T.childNodes.length>0&&f(c,T,I),v(c),!y()}function H(c,y){let R=t.textureLighting==="dynamic",T=t.directionalLight?.direction,I=y&&(y[0]!==0||y[1]!==0||y[2]!==0);if(!R||!I||!T){if(c.lightOverrideSignature==="clear")return;c.wrapper.style.removeProperty("--plx"),c.wrapper.style.removeProperty("--ply"),c.wrapper.style.removeProperty("--plz"),c.lightOverrideSignature="clear";return}let D=oo(T,y),z=Math.hypot(D[0],D[1],D[2])||1,G=(D[0]/z).toFixed(4),ee=(D[1]/z).toFixed(4),q=(D[2]/z).toFixed(4),Q=`${G}|${ee}|${q}`;c.lightOverrideSignature!==Q&&(c.wrapper.style.setProperty("--plx",G),c.wrapper.style.setProperty("--ply",ee),c.wrapper.style.setProperty("--plz",q),c.lightOverrideSignature=Q)}function V(c,y){y.paintColor?c.style.setProperty("--polycss-paint",y.paintColor):c.style.removeProperty("--polycss-paint"),y.dynamicColor?(c.style.setProperty("--psr",(y.dynamicColor.r/255).toFixed(4)),c.style.setProperty("--psg",(y.dynamicColor.g/255).toFixed(4)),c.style.setProperty("--psb",(y.dynamicColor.b/255).toFixed(4))):(c.style.removeProperty("--psr"),c.style.removeProperty("--psg"),c.style.removeProperty("--psb"))}function j(c){if(p(c),!c.castShadow||t.textureLighting!=="dynamic")return;let y=t.shadow?.color??"#000000",R=t.shadow?.opacity??.25,T=Jt(y)?.rgb??[0,0,0],I=T[0],D=T[1],z=T[2],G=`rgba(${I},${D},${z},${R})`,ee=bs(c.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.4}),q=s.createDocumentFragment();for(let W of A(c)){if(ee.has(W.polygonIndex))continue;let L=W.plan;if(!L)continue;let Z=`matrix3d(${L.matrix})`,F=s.createElement("q");F.className="polycss-shadow",F.style.transform=`var(--shadow-proj) ${Z}`,F.style.color=G,F.style.width=`${L.canvasW}px`,F.style.height=`${L.canvasH}px`,F.style.setProperty("border-shape",$n(L)),F.style.setProperty("--pnx",L.normal[0].toFixed(4)),F.style.setProperty("--pny",L.normal[1].toFixed(4)),F.style.setProperty("--pnz",L.normal[2].toFixed(4)),q.appendChild(F),c.shadowRendered.push(F)}let Q=c.wrapper.firstChild;Q?c.wrapper.insertBefore(q,Q):c.wrapper.appendChild(q)}function ie(c){if(c.voxelRenderer){c.voxelRenderer.render(M(c)),c.cameraCullSignature="voxel-direct";return}p(c),$(c),j(c)}function _(c){return!!c.voxelSource&&t.textureLighting!=="dynamic"&&!c.stableDom&&!c.castShadow}function X(c,y){m(c);let R=t.directionalLight,T=y?{...R,direction:y}:R;if(_(c)){let ee=eo({doc:s,wrapper:c.wrapper,polygons:c.parseResult.polygons,directionalLight:T,ambientLight:t.ambientLight});if(ee){c.voxelRenderer=ee,ee.render(M(c)),c.cameraCullSignature="voxel-direct";return}}let I={doc:s,directionalLight:T,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality,strategies:t.strategies},D=nt(c.polygons,I);V(c.wrapper,D);let z={...I,solidPaintDefaults:D},G=(c.stableDom?Zt(c.polygons,z):null)??Wn(c.polygons,z);c.rendered=G.rendered,c.disposeAtlas=G.dispose,E(c),$(c),j(c)}function U(){if(t.textureLighting!=="dynamic"){i.style.removeProperty("--shadow-ground-cssz");return}let c=1/0;for(let T of l)if(!T.disposed&&T.castShadow)for(let I of T.polygons)for(let D of I.vertices)D[2]<c&&(c=D[2]);if(!Number.isFinite(c)){i.style.removeProperty("--shadow-ground-cssz");return}let y=t.shadow?.lift??.05,R=(c+y)*_e;i.style.setProperty("--shadow-ground-cssz",R.toFixed(3))}async function oe(c,y){m(c);let R={doc:s,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality,strategies:t.strategies},T=c.stableDom?Zt(c.polygons,R):null;if(T){let z=nt(c.polygons,R);return V(c.wrapper,z),c.rendered=T.rendered,c.disposeAtlas=T.dispose,E(c),$(c),j(c),!y()}let I=await jn(c.polygons,R,y);if(y())return I.dispose(),!1;V(c.wrapper,I.solidPaintDefaults),c.rendered=I.rendered,c.disposeAtlas=I.dispose,E(c);let D=await O(c,y);return D&&j(c),D}function re(){let c=r,y=[0,0,0];if(t.autoCenter){let R=[];for(let T of l)!T.disposed&&!T.excludeFromAutoCenter&&R.push(...T.polygons);if(R.length>0){let T=ys(R);y=[(T.min[0]+T.max[0])/2,(T.min[1]+T.max[1])/2,(T.min[2]+T.max[2])/2]}}c[0]===y[0]&&c[1]===y[1]&&c[2]===y[2]||(r=y,a(i,t))}function le(c,y={}){let T=(i.ownerDocument??document).createElement("div");T.className="polycss-mesh",y.id&&T.setAttribute("data-poly-mesh-id",y.id);let I={...y},D=y.merge!==!1,z=!!y.stableDom,G=0,ee=so(I);ee&&(T.style.transform=ee);let q=(F,K)=>K?vs(F):F,Q=q(c.polygons,D);function W(F){if(F.length===0){T.style.removeProperty("--origin");return}let K=1/0,me=1/0,Pe=1/0,Se=-1/0,We=-1/0,wt=-1/0;for(let Lo of F)for(let ye of Lo.vertices)ye[0]<K&&(K=ye[0]),ye[0]>Se&&(Se=ye[0]),ye[1]<me&&(me=ye[1]),ye[1]>We&&(We=ye[1]),ye[2]<Pe&&(Pe=ye[2]),ye[2]>wt&&(wt=ye[2]);if(!Number.isFinite(K)){T.style.removeProperty("--origin");return}let So=(me+We)/2*_e,wo=(K+Se)/2*_e,To=(Pe+wt)/2*_e;T.style.setProperty("--origin",`${So}px ${wo}px ${To}px`)}W(Q),i.appendChild(T);let L={handle:void 0,wrapper:T,parseResult:c,rendered:[],shadowRendered:[],polygons:Q,voxelSource:c.voxelSource,disposed:!1,stableDom:z,excludeFromAutoCenter:!!y.excludeFromAutoCenter,castShadow:!!y.castShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",bakedRotation:y.rotation?[...y.rotation]:[0,0,0]},Z={polygons:Q,element:T,id:y.id,get transform(){return I},remove(){G++,T.parentNode&&T.parentNode.removeChild(T),m(L),l.delete(L),re(),U()},setPolygons(F,K){G++,D=K?.merge??D,z=K?.stableDom??z,L.stableDom=z,L.voxelSource=void 0,L.polygons=q(F,D),Z.polygons=L.polygons,W(L.polygons);let me=K?.recomputeAutoCenter??!0;if(L.stableDom&&!g(L.wrapper)){let Pe={doc:s,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality},Se=nt(L.polygons,Pe);if(V(L.wrapper,Se),qn(L.rendered,L.polygons,{...Pe,solidPaintDefaults:Se})){E(L),N(L,!0),me&&re();return}}X(L),me&&re()},updatePolygon(F,K){let me=typeof F=="number"?F:L.polygons.indexOf(F);me<0||me>=L.polygons.length||(L.voxelSource=void 0,Object.assign(L.polygons[me],K),X(L))},async setPolygonsChunked(F,K){let me=++G;D=K?.merge??D,z=K?.stableDom??z,L.stableDom=z,L.voxelSource=void 0,L.polygons=q(F,D),Z.polygons=L.polygons,W(L.polygons);let Pe=K?.recomputeAutoCenter??!0;if(!await oe(L,()=>L.disposed||me!==G)){m(L);return}Pe&&re()},setTransform(F){let K=L.castShadow;F.castShadow!==void 0&&(L.castShadow=!!F.castShadow),I={...I,...F};let me=so(I);T.style.transform=me??"",H(L,I.rotation),F.rotation!==void 0&&N(L),L.castShadow!==K&&(j(L),U())},dispose(){if(!L.disposed){L.disposed=!0,G++,T.parentNode&&T.parentNode.removeChild(T),m(L);try{c.dispose()}catch{}l.delete(L),re(),U()}},rebakeAtlas(){L.bakedRotation=I.rotation?[...I.rotation]:[0,0,0];let F=t.directionalLight?.direction??[.4,-.7,.59],K=oo(F,L.bakedRotation);X(L,K)},getPosition(){return I.position},getRotation(){return I.rotation},getScale(){return I.scale},getPolygons(){return Z.polygons}};return L.handle=Z,l.add(L),X(L),H(L,I.rotation),re(),U(),Z}function pe(c){let y=!!t.autoCenter,R=t.strategies,T=t.textureLighting,I=t.rotX??ot,D=t.rotY??rt;t={...t,...c},a(i,t);let z=!!t.autoCenter;for(let Q of l)H(Q,Q.handle.transform.rotation);let G=c.strategies!==void 0&&!Cs(c.strategies,R);if(G)for(let Q of l)X(Q);let ee=c.rotX!==void 0&&(t.rotX??ot)!==I||c.rotY!==void 0&&(t.rotY??rt)!==D;if(!G&&ee)for(let Q of l)N(Q);if(y!==z&&re(),c.textureLighting!==void 0&&T!==t.textureLighting){for(let Q of l)!G&&(Q.voxelSource||Q.voxelRenderer)?X(Q):j(Q);U()}}function ce(){return t}function ue(){let c=[];for(let y of l)c.push(y.handle);return c}function fe(c){let y=c;for(;y;){if(y instanceof HTMLElement&&y.classList.contains("polycss-mesh")){for(let R of l)if(R.wrapper===y)return R.handle;return null}y=y.parentElement}return null}function ge(){let c=Array.from(l);for(let y of c)try{y.handle.dispose()}catch{}i.parentNode&&i.parentNode.removeChild(i)}return{add:le,setOptions:pe,destroy:ge,host:e,getOptions:ce,meshes:ue,findMeshByElement:fe}}var ks=typeof HTMLElement<"u"?HTMLElement:class{},Ds=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function Re(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Os(e){return e==="false"?!1:Re(e)}function Is(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 Hs(e){if(e==="baked"||e==="dynamic")return e}function Vs(e){return e==="auto"?"auto":Re(e)}var be=class extends ks{constructor(){super(...arguments);this._scene=null}static get observedAttributes(){return[...Ds]}getScene(){return this._scene}_readOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={},s=Os(this.getAttribute("perspective"));s!==void 0&&(r.perspective=s);let i=Re(this.getAttribute("rot-x"));i!==void 0&&(r.rotX=i);let l=Re(this.getAttribute("rot-y"));l!==void 0&&(r.rotY=l);let a=Re(this.getAttribute("zoom"));a!==void 0&&(r.zoom=a),r.textureLighting=Hs(this.getAttribute("texture-lighting"))??"baked";let u=Vs(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=Is(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=Re(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=Re(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){this._scene||(this._scene=io(this,this._readOptions()),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1})))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null)}attributeChangedCallback(t,o,r){o!==r&&this._scene&&this._scene.setOptions(this._readOptions())}};import{computeSceneBbox as zs,loadMesh as Fs}from"@layoutit/polycss-core";var Bs=typeof HTMLElement<"u"?HTMLElement:class{},Ns=["src","mtl","position","scale","rotation","auto-center"];function Ye(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function ao(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Ye(e)}}function $s(e){return e.closest("poly-scene")??null}function Xs(e){if(e.length===0)return e;let n=zs(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s),...i.textureTriangles?.length?{textureTriangles:i.textureTriangles.map(l=>({...l,vertices:l.vertices.map(s)}))}:null}))}var ze=class extends Bs{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Ns]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:Ye(this.getAttribute("position")),scale:ao(this.getAttribute("scale")),rotation:Ye(this.getAttribute("rotation"))})}}_tearDown(){if(this._loadToken+=1,this._handle){try{this._handle.dispose()}catch{}this._handle=null}this._parseResult=null}async _maybeLoad(){let t=this.getAttribute("src");if(!t)return;let o=$s(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,i;try{i=await Fs(t,s?{mtlUrl:s}:void 0)}catch(u){this.dispatchEvent(new CustomEvent("polycss:error",{detail:u,bubbles:!0}));return}if(r!==this._loadToken){try{i.dispose()}catch{}return}let l=o.getScene();if(!l){try{i.dispose()}catch{}return}this.hasAttribute("auto-center")&&(i={...i,polygons:Xs(i.polygons)}),this._parseResult=i,this._handle=l.add(i,{position:Ye(this.getAttribute("position")),scale:ao(this.getAttribute("scale")),rotation:Ye(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var Ys=typeof HTMLElement<"u"?HTMLElement:class{},Us=["vertices","color","texture","uvs","position","scale","rotation"];function lo(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}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 Gs(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return tn(e)}}function Ws(e){return e.closest("poly-scene")??null}var st=class extends Ys{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Us]}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=Ws(this);if(!t)return;let o=t.getScene();if(!o)return;let r=lo(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let s=this.getAttribute("color")||void 0,i=this.getAttribute("texture")||void 0,l=lo(this.getAttribute("uvs"))??void 0,a={};for(let d of Array.from(this.attributes))d.name.startsWith("data-")&&(a[d.name.slice(5)]=d.value);let m={polygons:[{vertices:r,...s!==void 0?{color:s}:{},...i!==void 0?{texture:i}:{},...l!==void 0?{uvs:l}:{},...Object.keys(a).length>0?{data:a}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(m,{position:tn(this.getAttribute("position")),scale:Gs(this.getAttribute("scale")),rotation:tn(this.getAttribute("rotation"))})}};import{axesHelperPolygons as js}from"@layoutit/polycss-core";var Zs=typeof HTMLElement<"u"?HTMLElement:class{},qs=["size","thickness","negative","x-color","y-color","z-color"];function Qs(e){return e.closest("poly-scene")??null}function co(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var it=class extends Zs{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...qs]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&this._handle&&this._remount()}_polygons(){return js({size:co(this.getAttribute("size")),thickness:co(this.getAttribute("thickness")),negative:this.hasAttribute("negative"),xColor:this.getAttribute("x-color")??void 0,yColor:this.getAttribute("y-color")??void 0,zColor:this.getAttribute("z-color")??void 0})}_mount(){let t=Qs(this);if(!t)return;let o=t.getScene();if(!o)return;let r={polygons:this._polygons(),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(r,{excludeFromAutoCenter:!0})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};import{octahedronPolygons as Ks}from"@layoutit/polycss-core";var Js=typeof HTMLElement<"u"?HTMLElement:class{},ei=["direction","target","distance","size","color"],nn=50,ti=5,ni=.35,oi="#ffd54a";function ri(e){return e.closest("poly-scene")??null}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 mo(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var at=class extends Js{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...ei]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="size"||t==="color"){this._remount();return}this._handle.setTransform({position:this._meshPosition()})}}_meshPosition(){let t=uo(this.getAttribute("direction"));if(!t)return;let o=uo(this.getAttribute("target"))??[0,0,0],r=mo(this.getAttribute("distance"),ti),s=t[0],i=t[1],l=t[2],a=Math.hypot(s,i,l)||1,u=o[0]+i/a*r,m=o[1]+s/a*r,d=o[2]+l/a*r;return[m*nn,u*nn,d*nn]}_mount(){let t=ri(this);if(!t)return;let o=t.getScene();if(!o)return;let r=mo(this.getAttribute("size"),ni),s=this.getAttribute("color")??oi,i={polygons:Ks({center:[0,0,0],size:r,color:s}),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(i,{position:this._meshPosition(),excludeFromAutoCenter:!0})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};import{BASE_TILE as si}from"@layoutit/polycss-core";var lt={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Fe(e,n){let t;return n.animate===!1?t=!1:n.animate?t={speed:n.animate.speed??.3,axis:n.animate.axis??"y",pauseOnInteraction:n.animate.pauseOnInteraction??!0}:t=e.animate,{drag:n.drag??e.drag,wheel:n.wheel??e.wheel,dolly:n.dolly??e.dolly,invert:n.invert??e.invert,minZoom:n.minZoom??e.minZoom,maxZoom:n.maxZoom??e.maxZoom,minDistance:n.minDistance??e.minDistance,maxDistance:n.maxDistance??e.maxDistance,animate:t}}function Ue(e){return e===!0?-1:e===!1?1:e}function ct(){let e=[],n=[],t=[];function o(i){return i==="change"?e:i==="start"?n:t}function r(i){if(e.length===0)return;let l={type:"change",camera:i()},a=e.slice();for(let u of a)try{u(l)}catch(m){console.error("[polycss] controls 'change' listener threw:",m)}}function s(i,l){let a=i==="start"?n:t;if(a.length===0)return;let u={type:i,camera:l()},m=a.slice();for(let d of m)try{d(u)}catch(f){console.error(`[polycss] controls '${i}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function ut(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 dt(e,n,t,o,r,s){let i=!1,l=null;return{onWheel:m=>{let d=n();if(!d.wheel||t())return;m.preventDefault();let f=m.deltaMode===1?16:m.deltaMode===2?100:1,g=m.deltaY*f;m.ctrlKey?g*=10:g*=3;let p=e.getOptions();if(d.dolly){let h=p.distance??0,b=Math.max(d.minDistance,Math.min(d.maxDistance,h+g*.05));e.setOptions({distance:b})}else{let h=Math.exp(-g*513e-6),b=p.zoom??1,x=Math.max(d.minZoom,Math.min(d.maxZoom,b*h));e.setOptions({zoom:x})}i||(i=!0,s("start",o)),r(o),l!==null&&clearTimeout(l),l=setTimeout(()=>{l=null,i=!1,s("end",o)},150)},teardown:()=>{l!==null&&(clearTimeout(l),l=null),i=!1}}}function mt(e,n,t,o,r,s,i){let l=null,a=0,u=g=>{if(l===null||o())return;let p=t();if(!p.animate){l=null;return}if(r())a=g;else{let h=Math.min(50,a?g-a:16.67);a=g;let b=p.animate.speed*(h/16.67),x=n.getOptions();if(p.animate.axis==="x"){let A=(((x.rotX??65)+b)%360+360)%360;n.setOptions({rotX:A})}else{let A=(((x.rotY??45)+b)%360+360)%360;n.setOptions({rotY:A})}i(s)}l=e.requestAnimationFrame(u)};return{start:()=>{l!==null||!t().animate||o()||(a=0,l=e.requestAnimationFrame(u))},stop:()=>{l!==null&&(e.cancelAnimationFrame(l),l=null)},isRunning:()=>l!==null}}function po(e,n={}){let t=Fe(lt,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},l=!1,a=!1,u=ct(),m=ut(e),{changeListeners:d,startListeners:f,endListeners:g,listenerArray:p,emitChange:h,emitInteraction:b}=u,x=mt(r,e,()=>t,()=>a,()=>l,m,h),A=w=>{if(!(!t.drag||a)&&s===null&&w.isPrimary!==!1){w.preventDefault(),s=w.pointerId,i={x:w.clientX,y:w.clientY},o.style.cursor="grabbing";try{w.target.setPointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!0),b("start",m)}},M=w=>{if(s===null||w.pointerId!==s||!t.drag||a)return;w.preventDefault();let O=w.clientX-i.x,H=w.clientY-i.y;i={x:w.clientX,y:w.clientY};let V=Ue(t.invert),j=O/4*V,ie=H/4*V,_=e.getOptions();if(w.shiftKey){let X=_.rotX??65,U=_.rotY??45,oe=Math.max(.01,_.zoom??1),re=Math.cos(X*Math.PI/180),le=re>=0?Math.max(.1,re):Math.min(-.1,re),pe=Math.cos(U*Math.PI/180),ce=Math.sin(U*Math.PI/180),ue=oe*si,fe=(O*ce-H*pe/le)/ue,ge=-(O*pe+H*ce/le)/ue,c=_.target??[0,0,0];e.setOptions({target:[c[0]+fe,c[1]+ge,c[2]]})}else{let X=Math.max(0,Math.min(100,(_.rotX??65)-ie)),U=(((_.rotY??45)-j)%360+360)%360;e.setOptions({rotX:X,rotY:U})}h(m)},P=w=>{if(s===w.pointerId){s=null,o.style.cursor=t.drag&&!a?"grab":"";try{w.target.releasePointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!1),b("end",m)}},E=dt(e,()=>t,()=>a,m,h,b);function k(){o.addEventListener("pointerdown",A),o.addEventListener("pointermove",M),o.addEventListener("pointerup",P),o.addEventListener("pointercancel",P),o.addEventListener("wheel",E.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function C(){o.removeEventListener("pointerdown",A),o.removeEventListener("pointermove",M),o.removeEventListener("pointerup",P),o.removeEventListener("pointercancel",P),o.removeEventListener("wheel",E.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",E.teardown()}k(),x.start();function v(w){let O=!!t.animate;t=Fe(t,w),!a&&s===null&&(o.style.cursor=t.drag?"grab":"");let H=!!t.animate;O&&!H?x.stop():!O&&H&&x.start()}function B(){a&&(a=!1,k(),x.start())}function N(){a||(a=!0,C(),x.stop(),s=null,l=!1,E.teardown())}function Y(){N(),d.length=0,f.length=0,g.length=0}function te(w,O){let H=p(w);H.includes(O)||H.push(O)}function S(w,O){let H=p(w),V=H.indexOf(O);V>=0&&H.splice(V,1)}function $(w,O){return p(w).includes(O)}return{update:v,resume:B,pause:N,destroy:Y,addEventListener:te,removeEventListener:S,hasEventListener:$}}function se(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function pt(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 Ce(e){if(e!==null)return!(e==="false"||e==="0")}function ft(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 ht(e){if(e==="x"||e==="y")return e}var ii=typeof HTMLElement<"u"?HTMLElement:class{},ai=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],gt=class extends ii{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...ai]}_readAnimate(){let t=se(this.getAttribute("animate-speed")),o=ht(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:Ce(r)}:{}}}_readOptions(){let t={},o=Ce(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Ce(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=se(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=se(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let l=ft(this.getAttribute("invert"));l!==void 0&&(t.invert=l);let a=se(this.getAttribute("zoom-min")),u=se(this.getAttribute("zoom-max"));return a!==void 0&&(t.minZoom=a),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof be)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=po(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};import{BASE_TILE as li}from"@layoutit/polycss-core";function fo(e,n={}){let t=Fe(lt,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},l=!1,a=!1,u=!1,m={x:0,y:0},d=ct(),f=ut(e),{changeListeners:g,startListeners:p,endListeners:h,listenerArray:b,emitChange:x,emitInteraction:A}=d,M=mt(r,e,()=>t,()=>a,()=>l,f,x),P=_=>{if(!(!t.drag||a)&&s===null&&_.isPrimary!==!1){_.preventDefault(),s=_.pointerId,i={x:_.clientX,y:_.clientY},o.style.cursor="grabbing";try{_.target.setPointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!0),A("start",f)}},E=_=>{if(s===null||_.pointerId!==s||!t.drag||a)return;_.preventDefault();let X=_.clientX-i.x,U=_.clientY-i.y;i={x:_.clientX,y:_.clientY};let oe=e.getOptions();if(_.shiftKey){let re=Ue(t.invert),le=X/4*re,pe=U/4*re,ce=Math.max(0,Math.min(100,(oe.rotX??65)-pe)),ue=(((oe.rotY??45)-le)%360+360)%360;e.setOptions({rotX:ce,rotY:ue})}else{let re=oe.rotX??65,le=oe.rotY??45,pe=Math.max(.01,oe.zoom??1),ce=Math.cos(re*Math.PI/180),ue=ce>=0?Math.max(.1,ce):Math.min(-.1,ce),fe=Math.cos(le*Math.PI/180),ge=Math.sin(le*Math.PI/180),c=pe*li,y=(X*ge-U*fe/ue)/c,R=-(X*fe+U*ge/ue)/c,T=oe.target??[0,0,0];e.setOptions({target:[T[0]+y,T[1]+R,T[2]]})}x(f)},k=_=>{if(s===_.pointerId){s=null,o.style.cursor=t.drag&&!a?"grab":"";try{_.target.releasePointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!1),A("end",f)}},C=_=>{_.preventDefault()},v=_=>{_.button===2&&(u=!0,m={x:_.clientX,y:_.clientY},t.animate&&t.animate.pauseOnInteraction&&(l=!0),A("start",f))},B=_=>{if(!u||!t.drag)return;let X=_.clientX-m.x,U=_.clientY-m.y;m={x:_.clientX,y:_.clientY};let oe=Ue(t.invert),re=X/4*oe,le=U/4*oe,pe=e.getOptions(),ce=Math.max(0,Math.min(100,(pe.rotX??65)-le)),ue=(((pe.rotY??45)-re)%360+360)%360;e.setOptions({rotX:ce,rotY:ue}),x(f)},N=_=>{_.button===2&&u&&(u=!1,A("end",f))},Y=dt(e,()=>t,()=>a,f,x,A);function te(){o.addEventListener("pointerdown",P),o.addEventListener("pointermove",E),o.addEventListener("pointerup",k),o.addEventListener("pointercancel",k),o.addEventListener("wheel",Y.onWheel,{passive:!1}),o.addEventListener("contextmenu",C),o.addEventListener("mousedown",v),o.addEventListener("mousemove",B),o.addEventListener("mouseup",N),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function S(){o.removeEventListener("pointerdown",P),o.removeEventListener("pointermove",E),o.removeEventListener("pointerup",k),o.removeEventListener("pointercancel",k),o.removeEventListener("wheel",Y.onWheel),o.removeEventListener("contextmenu",C),o.removeEventListener("mousedown",v),o.removeEventListener("mousemove",B),o.removeEventListener("mouseup",N),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",Y.teardown()}te(),M.start();function $(_){let X=!!t.animate;t=Fe(t,_),!a&&s===null&&(o.style.cursor=t.drag?"grab":"");let U=!!t.animate;X&&!U?M.stop():!X&&U&&M.start()}function w(){a&&(a=!1,te(),M.start())}function O(){a||(a=!0,S(),M.stop(),s=null,l=!1,u=!1,Y.teardown())}function H(){O(),g.length=0,p.length=0,h.length=0}function V(_,X){let U=b(_);U.includes(X)||U.push(X)}function j(_,X){let U=b(_),oe=U.indexOf(X);oe>=0&&U.splice(oe,1)}function ie(_,X){return b(_).includes(X)}return{update:$,resume:w,pause:O,destroy:H,addEventListener:V,removeEventListener:j,hasEventListener:ie}}var ci=typeof HTMLElement<"u"?HTMLElement:class{},ui=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],yt=class extends ci{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...ui]}_readAnimate(){let t=se(this.getAttribute("animate-speed")),o=ht(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:Ce(r)}:{}}}_readOptions(){let t={},o=Ce(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Ce(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=se(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=se(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let l=ft(this.getAttribute("invert"));l!==void 0&&(t.invert=l);let a=se(this.getAttribute("zoom-min")),u=se(this.getAttribute("zoom-max"));return a!==void 0&&(t.minZoom=a),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof be)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=fo(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};import{createIsometricCamera as ho}from"@layoutit/polycss-core";var di=8e3;function on(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=ho(n),o=`${e.perspective??di}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function go(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=ho(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var mi=typeof HTMLElement<"u"?HTMLElement:class{},pi=["perspective","zoom","rot-x","rot-y","target","distance"],bt=class extends mi{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...pi]}getCamera(){return this._camera}_readOptions(){return{perspective:se(this.getAttribute("perspective")),zoom:se(this.getAttribute("zoom")),rotX:se(this.getAttribute("rot-x")),rotY:se(this.getAttribute("rot-y")),target:pt(this.getAttribute("target")),distance:se(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=on(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=on(s),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var fi=typeof HTMLElement<"u"?HTMLElement:class{},hi=["zoom","rot-x","rot-y","target","distance"],xt=class extends fi{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...hi]}getCamera(){return this._camera}_readOptions(){return{zoom:se(this.getAttribute("zoom")),rotX:se(this.getAttribute("rot-x")),rotY:se(this.getAttribute("rot-y")),target:pt(this.getAttribute("target")),distance:se(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=go(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let s=this._readOptions();s.zoom!==void 0&&this._camera.update({zoom:s.zoom}),s.rotX!==void 0&&this._camera.update({rotX:s.rotX}),s.rotY!==void 0&&this._camera.update({rotY:s.rotY}),s.target!==void 0&&this._camera.update({target:s.target}),s.distance!==void 0&&this._camera.update({distance:s.distance})}};import{arrowPolygons as gi,eulerXYZFromQuat as yi,planePolygons as bi,quatFromAxisAngle as xi,quatFromEulerXYZ as vi,quatMultiply as Pi,ringQuadPolygons as Ei}from"@layoutit/polycss-core";var Pt="#ff3653",Et="#8adb00",At="#2c8fff",Be=50,yo=60,Ai=.6,Mi=.0125,Ci=.15,Si=.04,wi=1,bo=.02,rn=1.04,Ti=.1,Li=.25,Eo=1e-4,_i=.6,Ri=.8,ki=1,Ge={0:1,1:0,2:2},xo=[{cssAxis:0,sign:1,key:"x",color:Pt},{cssAxis:0,sign:-1,key:"-x",color:Pt},{cssAxis:1,sign:1,key:"y",color:Et},{cssAxis:1,sign:-1,key:"-y",color:Et},{cssAxis:2,sign:1,key:"z",color:At},{cssAxis:2,sign:-1,key:"-z",color:At}],vo=[{cssAxis:0,key:"x",color:Pt},{cssAxis:1,key:"y",color:Et},{cssAxis:2,key:"z",color:At}],Po=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:At},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:Et},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:Pt}];function sn(e,n,t,o){let r=t*Math.PI/180,s=o*Math.PI/180,i=[0,0,0];i[e]=n;let l=i[0]*Math.cos(s)-i[1]*Math.sin(s),a=i[0]*Math.sin(s)+i[1]*Math.cos(s),u=i[2];return a*Math.sin(r)+u*Math.cos(r)<0}function Di(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 Mt(e,n){return!n||n<=0?e:Math.round(e/n)*n}function Oi(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let a of l.vertices)a[0]<n&&(n=a[0]),a[0]>r&&(r=a[0]),a[1]<t&&(t=a[1]),a[1]>s&&(s=a[1]),a[2]<o&&(o=a[2]),a[2]>i&&(i=a[2]);return Number.isFinite(n)?[(t+s)/2*Be,(n+r)/2*Be,(o+i)/2*Be]:[0,0,0]}function an(e){if(e.length===0)return yo;let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let a of e)for(let u of a.vertices)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*Be*Ai:yo}function vt(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 Ii(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:l,translationSnap:a,onAxisDelta:u,onMouseDown:m,onMouseUp:d,onDraggingChanged:f}=e,g=o,p=[0,0,0];p[n]=t;let h=r.ownerDocument.createElement("div");h.style.position="absolute",h.style.left="0",h.style.top="0",h.style.width="0",h.style.height="0",h.style.transform=`translate3d(${p[0]*g}px, ${p[1]*g}px, ${p[2]*g}px)`,r.appendChild(h);let b=r.getBoundingClientRect(),x=h.getBoundingClientRect();r.removeChild(h);let A=(x.left-b.left)/g,M=(x.top-b.top)/g,P=A*A+M*M;if(P<Eo)return;m?.(),f?.(!0);let E=C=>{let v=C.clientX-i,B=C.clientY-l,N=(v*A+B*M)/P;N=Mt(N,a),u(N,p)},k=()=>{window.removeEventListener("pointermove",E),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k);let C=v=>{v.stopPropagation(),v.stopImmediatePropagation()};window.addEventListener("click",C,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",C,!0),0),d?.(),f?.(!1)};window.addEventListener("pointermove",E),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)}function Hi(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:s,startClientY:i,translationSnap:l,onPlaneDelta:a,onMouseDown:u,onMouseUp:m,onDraggingChanged:d}=e,f=[0,0,0];f[n]=1;let g=[0,0,0];g[t]=1;function p(P){let E=r.ownerDocument.createElement("div");E.style.position="absolute",E.style.left="0",E.style.top="0",E.style.width="0",E.style.height="0",E.style.transform=`translate3d(${P[0]*o}px, ${P[1]*o}px, ${P[2]*o}px)`,r.appendChild(E);let k=r.getBoundingClientRect(),C=E.getBoundingClientRect();return r.removeChild(E),{x:(C.left-k.left)/o,y:(C.top-k.top)/o}}let h=p(f),b=p(g),x=h.x*b.y-b.x*h.y;if(Math.abs(x)<Eo)return;u?.(),d?.(!0);let A=P=>{let E=P.clientX-s,k=P.clientY-i,C=(b.y*E-b.x*k)/x,v=(-h.y*E+h.x*k)/x;C=Mt(C,l),v=Mt(v,l),a(C,v,f,g)},M=()=>{window.removeEventListener("pointermove",A),window.removeEventListener("pointerup",M),window.removeEventListener("pointercancel",M);let P=E=>{E.stopPropagation(),E.stopImmediatePropagation()};window.addEventListener("click",P,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",P,!0),0),m?.(),d?.(!1)};window.addEventListener("pointermove",A),window.addEventListener("pointerup",M),window.addEventListener("pointercancel",M)}function Vi(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:l,onMouseDown:a,onMouseUp:u,onDraggingChanged:m}=e,d=t.getBoundingClientRect(),f=d.left,g=d.top,p=Math.atan2(s-g,r-f),h=0;a?.(),m?.(!0);let b=A=>{let M=Math.atan2(A.clientY-g,A.clientX-f),P=M-p;P>Math.PI?P-=2*Math.PI:P<-Math.PI&&(P+=2*Math.PI),h+=P,p=M;let E=h*180/Math.PI;E=Mt(E,i),l(E)},x=()=>{window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x);let A=M=>{M.stopPropagation(),M.stopImmediatePropagation()};window.addEventListener("click",A,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",A,!0),0),u?.(),m?.(!1)};window.addEventListener("pointermove",b),window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x)}function Ao(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,l=null,a=null,u=[0,0,0];function m(){if(!t)return[0,0,0];let S=t.transform.position??[0,0,0];return[S[0]+u[0],S[1]+u[1],S[2]+u[2]]}function d(S){return a===S?ki:l===S?Ri:_i}function f(){for(let[S,$]of i){let w=g($.spec,d(S));$.handle.setPolygons(w,{recomputeAutoCenter:!1})}}function g(S,$){let O=an(t?.polygons??[])*r,H=O/Be,V=Di(S.color,$);if(S.kind==="arrow"){let _=e.getOptions(),X=sn(S.cssAxis,S.sign,_.rotX??65,_.rotY??45);return gi({axis:Ge[S.cssAxis],sign:S.sign,shaftLength:H,shaftHalfThickness:H*Mi,headLength:H*Ci,headHalfThickness:H*Si,color:V,shaft:!X})}if(S.kind==="plane"){let _=e.getOptions(),X=_.rotX??65,U=_.rotY??45,oe=Ge[S.perpAxis],re=(oe+1)%3,le=(oe+2)%3,pe=Ge[re],ce=Ge[le],ue=sn(pe,1,X,U)?-1:1,fe=sn(ce,1,X,U)?-1:1,ge=H*Li;return bi({axis:oe,size:H*Ti,offset:[ue*ge,fe*ge],color:V})}let ie=O*wi/Be*rn;return Ei({axis:Ge[S.cssAxis],outerRadius:ie,color:V})}function p(S){return S.kind==="arrow"?"polycss-transform-arrow":S.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function h(){if(o==="translate"){let S=xo.map(w=>({kind:"arrow",key:w.key,cssAxis:w.cssAxis,sign:w.sign,color:w.color})),$=Po.map(w=>({kind:"plane",key:w.key,perpAxis:w.perpAxis,axisA:w.axisA,axisB:w.axisB,color:w.color}));return[...S,...$]}return o==="rotate"?vo.map(S=>({kind:"ring",key:S.key,cssAxis:S.cssAxis,color:S.color})):[]}function b(){if(x(),!t)return;let S={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};function $(O){if(O.kind==="arrow"){let j=O.key.replace("-","")[0];return S[j]}if(O.kind==="ring")return S[O.key];let H=["x","y","z"][O.axisA],V=["x","y","z"][O.axisB];return S[H]&&S[V]}let w=m();for(let O of h()){if(!$(O))continue;let H=g(O,d(O.key)),V=e.add({polygons:H,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${O.key}`,position:w}),j=p(O);if(V.element.classList.add("polycss-transform-gizmo",j,`${j}--${O.key}`),O.kind==="ring"){let ie=(1-bo)/rn,_=(1+bo)/rn;V.element.style.setProperty("--ring-inner-ratio",`${ie}`),V.element.style.setProperty("--ring-outer-ratio",`${_}`)}i.set(O.key,{handle:V,spec:O})}}function x(){for(let{handle:S}of i.values())S.remove();i.clear(),l=null,a=null}function A(){if(!t)return;let S=m();for(let{handle:$}of i.values())$.setTransform({position:S})}function M(){t&&(i.size===0?b():A())}function P(S){if(t=S,!S){u=[0,0,0],x();return}u=Oi(S.polygons),x(),b()}function E(){P(null)}function k(S){S!==o&&(o=S,t&&(x(),b()))}function C(S,$,w){if(!t||!v)return;let O=[v[0]+$*w[0],v[1]+$*w[1],v[2]+$*w[2]];t.setTransform({position:O}),A(),s.onObjectChange?.({object:t,position:O}),s.onChange?.()}let v=null,B=null,N=S=>{if(!t||s.enabled===!1)return;let $={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate"){for(let w of Po){let O=["x","y","z"][w.axisA],H=["x","y","z"][w.axisB];if(!$[O]||!$[H])continue;let V=i.get(w.key);if(V&&vt(V.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),a=w.key,f(),v=(t.transform.position??[0,0,0]).slice(),Hi({axisA:w.axisA,axisB:w.axisB,probeDistanceCss:an(t.polygons)*r,wrapper:V.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,translationSnap:s.translationSnap??null,onPlaneDelta:(j,ie,_,X)=>{if(!t||!v)return;let U=[v[0]+j*_[0]+ie*X[0],v[1]+j*_[1]+ie*X[1],v[2]+j*_[2]+ie*X[2]];t.setTransform({position:U}),A(),s.onObjectChange?.({object:t,position:U}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:j=>{j||(a=null,v=null,f()),s.onDraggingChanged?.(j)}});return}}for(let w of xo){let O=w.key.replace("-","")[0];if(!$[O])continue;let H=i.get(w.key);if(H&&vt(H.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),a=w.key,f(),v=(t.transform.position??[0,0,0]).slice(),Ii({cssAxis:w.cssAxis,sign:w.sign,shaftLengthCss:an(t.polygons)*r,wrapper:H.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(V,j)=>C(w,V,j),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:V=>{V||(a=null,v=null,f()),s.onDraggingChanged?.(V)}});return}}}else if(o==="rotate")for(let w of vo){if(!$[w.key])continue;let O=i.get(w.key);if(O&&vt(O.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),a=w.key,f(),B=(t.transform.rotation??[0,0,0]).slice(),Vi({cssAxis:w.cssAxis,wrapper:O.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:H=>{if(!t||!B)return;let V=w.cssAxis===0?-1:1,j=[0,0,0];j[w.cssAxis]=1;let ie=H*V*Math.PI/180,_=vi(B),X=xi(j,ie),U=yi(Pi(X,_));t.setTransform({rotation:U}),s.onObjectChange?.({object:t,rotation:U}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:H=>{H||(a=null,B=null,f(),t?.rebakeAtlas()),s.onDraggingChanged?.(H)}});return}}};e.host.addEventListener("pointerdown",N,{capture:!0});let Y=S=>{if(!t||a||s.enabled===!1)return;let $=null;for(let[w,O]of i)if(vt(O.handle.element,S.clientX,S.clientY)){$=w;break}$!==l&&(l=$,f())};e.host.addEventListener("pointermove",Y);function te(){e.host.removeEventListener("pointerdown",N,{capture:!0}),e.host.removeEventListener("pointermove",Y),x()}return{attach:P,detach:E,setMode:k,update:M,destroy:te}}var zi=typeof HTMLElement<"u"?HTMLElement:class{},Fi=["mode","target","size","enabled"];function Mo(e){if(e==="translate"||e==="rotate")return e}var Ct=class extends zi{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Fi]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof be)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 ze?r:null}_readOptions(){let t={},o=Mo(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=se(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=Ao(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=Mo(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};function Bi(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 Co(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let h of o)try{h(t)}catch(b){console.error("[polycss/createSelect] onChange threw:",b)}}function s(p){t=p,r()}function i(p){n.multiple?t.includes(p)||(t=[...t,p]):t=[p],r()}function l(p){t.includes(p)&&(t=t.filter(h=>h!==p),r())}function a(p){t.includes(p)?t=t.filter(h=>h!==p):n.multiple?t=[...t,p]:t=[p],r()}function u(){t.length!==0&&(t=[],r())}function m(p){return t.includes(p)}function d(p,h){for(let b of e.meshes())if(!b.element.classList.contains("polycss-transform-gizmo")&&Bi(b.element,p,h))return b;return null}let f=p=>{let h=p.target;if(h?.closest(".polycss-transform-gizmo"))return;let b=e.findMeshByElement(h)??d(p.clientX,p.clientY);if(!b){n.onPointerMissed&&n.onPointerMissed(p),n.clearOnMiss!==!1&&u();return}n.multiple&&(p.shiftKey||p.metaKey||p.ctrlKey)?a(b):t.length===1&&t[0]===b?u():s([b])};e.host.addEventListener("click",f);function g(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:s,add:i,remove:l,toggle:a,clear:u,has:m,destroy:g}}var Ni=typeof HTMLElement<"u"?HTMLElement:class{},$i=["multiple","clear-on-miss"],St=class extends Ni{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...$i]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof be)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=Co(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};typeof customElements<"u"&&(customElements.get("poly-scene")||customElements.define("poly-scene",be),customElements.get("poly-mesh")||customElements.define("poly-mesh",ze),customElements.get("poly-polygon")||customElements.define("poly-polygon",st),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",it),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",at),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",gt),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",yt),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",bt),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",xt),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",Ct),customElements.get("poly-select")||customElements.define("poly-select",St));export{it as PolyAxesHelperElement,at as PolyDirectionalLightHelperElement,yt as PolyMapControlsElement,ze as PolyMeshElement,gt as PolyOrbitControlsElement,xt as PolyOrthographicCameraElement,bt as PolyPerspectiveCameraElement,st as PolyPolygonElement,be as PolySceneElement,St as PolySelectElement,Ct as PolyTransformControlsElement};
|
|
519
|
+
`;import{BASE_TILE as Za}from"@layoutit/polycss-core";var Qa=1,Ve=Za,qa=.1;function Ka(e){return[e[1]*Ve,e[0]*Ve,e[2]*Ve]}function Pt(e){return[e[1],e[0],e[2]]}function ot(e){return e?.direction?{...e,direction:Pt(e.direction)}:e}function cn(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,i=!!e.rotation&&(!!e.rotation[0]||!!e.rotation[1]||!!e.rotation[2]),s=e.position?Ka(e.position):[0,0,0],c=[];return(s[0]!==0||s[1]!==0||s[2]!==0)&&c.push(`translate3d(${s[0]}px, ${s[1]}px, ${s[2]}px)`),i&&(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 Co(e,n=[0,0,0],t=1){let o=e.state,r=o.rotX,i=o.rotY,c=(o.zoom??Qa)/Ve*t,l=(o.distance??0)*t,p=o.target??[0,0,0],g=p[0]+n[0],x=p[1]+n[1],f=p[2]+n[2],b=x*Ve,y=g*Ve,P=f*Ve;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${r}deg) rotate(${i}deg) translate3d(${-b}px, ${-y}px, ${-P}px)`}function Ja(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 Dr(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=Ja(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function Or(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}function Hr(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 f=e.vertices[x],b=e.vertices[x+1],y=f[1]-n[1],P=f[0]-n[0],v=f[2]-n[2],C=b[1]-n[1],F=b[0]-n[0],k=b[2]-n[2];t-=P*k-v*F,o-=v*C-y*k,r-=y*F-P*C}let i=Math.hypot(t,o,r);if(i<1e-9)return null;t/=i,o/=i,r/=i;let s=1/qa,c=Math.round(t*s)/s,l=Math.round(o*s)/s,p=Math.round(r*s)/s,g=Math.hypot(c,l,p);return g<1e-9?null:{key:c+","+l+","+p,vec:[c/g,l/g,p/g]}}function Ir(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 Fr(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Vr(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)}import{parseHex as Nr,parseHexColor as Br,parsePureColor as el}from"@layoutit/polycss-core";var tl=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"],St="--polycss-light-preview-active",zr=`var(${St}, 0)`,nl="max(0, calc(var(--pnx, 0) * var(--plx, 0) + var(--pny, 0) * var(--ply, 0) + var(--pnz, 1) * var(--plz, 1)))",Eo=(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))`,ol=Eo("--psr","--par","--plr"),rl=Eo("--psg","--pag","--plg"),il=Eo("--psb","--pab","--plb");function de(e,n,t){return e.style.getPropertyValue(n)===t?!1:(e.style.setProperty(n,t),!0)}function lt(e){for(let n of tl)e.style.getPropertyValue(n)&&e.style.removeProperty(n)}function dn(e,n){let t=n.directionalLight?.direction??[.4,-.7,.59],o=Pt(t),r=Math.hypot(o[0],o[1],o[2])||1,i=o[0]/r,s=o[1]/r,c=o[2]/r,l=Br(n.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],p=Br(n.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],g=n.directionalLight?.intensity??1,x=n.ambientLight?.intensity??.4,f=P=>(P/255).toFixed(4);de(e,"--plx",i.toFixed(2)),de(e,"--ply",s.toFixed(2)),de(e,"--plz",c.toFixed(2)),de(e,"--plr",f(l[0])),de(e,"--plg",f(l[1])),de(e,"--plb",f(l[2])),de(e,"--pli",g.toFixed(4)),de(e,"--par",f(p[0])),de(e,"--pag",f(p[1])),de(e,"--pab",f(p[2])),de(e,"--pai",x.toFixed(4));let b=c,y=Math.sign(b||1)*Math.max(Math.abs(b),.01);de(e,"--clx",i.toFixed(2)),de(e,"--cly",s.toFixed(2)),de(e,"--clz",y.toFixed(2))}function Gr(e,n){let t=n.textureLighting==="dynamic";if(e.dataset.polycssLighting=n.textureLighting??"baked",!t){lt(e);return}dn(e,n)}function ct(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 $r(e,n){let t=Nr(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 To(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=t.textureLighting??"baked",r={directionalLight:ot(t.directionalLight),ambientLight:t.ambientLight,textureLighting:o,textureQuality:t.textureQuality,seamBleed:t.seamBleed,strategies:t.strategies},i=io(e.plan,n,e.plan.normal,o,r);return gt(e.element,i,o),o==="baked"&&al(e.element),!0}function sl(e){let n=el(e)??{rgb:[255,255,255],alpha:1},[t,o,r]=n.rgb,i=(c,l)=>`calc(${c} * (1 - ${zr}) + var(${l}, ${c}) * ${zr})`,s=n.alpha<1?` / ${n.alpha}`:"";return`rgb(${i(t,"--polycss-preview-r")} ${i(o,"--polycss-preview-g")} ${i(r,"--polycss-preview-b")}${s})`}function Ur(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=e.element,r=e.plan.normal,i=Nr(n.color??"#cccccc"),s=!1;return s=de(o,"--pnx",r[0].toFixed(4))||s,s=de(o,"--pny",r[1].toFixed(4))||s,s=de(o,"--pnz",r[2].toFixed(4))||s,s=de(o,"--psr",(i.r/255).toFixed(4))||s,s=de(o,"--psg",(i.g/255).toFixed(4))||s,s=de(o,"--psb",(i.b/255).toFixed(4))||s,s=de(o,"--plam",nl)||s,s=de(o,"--polycss-preview-r",ol)||s,s=de(o,"--polycss-preview-g",rl)||s,s=de(o,"--polycss-preview-b",il)||s,s=de(o,"--polycss-paint",sl(t))||s,o.style.getPropertyValue("color")&&(o.style.removeProperty("color"),s=!0),s}function al(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 ll="http://www.w3.org/2000/svg",un=class{constructor(){this.groundSvg=null;this.groundVisible=!1;this.currentGroundCssZ=null;this.shadowRoot=null}};function jr(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 Wr(e){e.groundSvg?.parentNode&&e.groundSvg.parentNode.removeChild(e.groundSvg),e.groundSvg=null,e.groundVisible=!1}function Yr(e){e.groundSvg&&e.groundVisible&&(e.groundSvg.style.display="none",e.groundVisible=!1)}function Xr(e,n,t,o){let r=[],i=e.firstChild;for(let s=0;s<t;s++){let c=i;c&&c.tagName==="path"?i=c.nextSibling:(c=n.createElementNS(ll,"path"),c.setAttribute("fill-rule","nonzero"),o&&(c.setAttribute("stroke-width","0.5"),c.setAttribute("stroke-linejoin","round")),e.insertBefore(c,i)),r.push(c)}for(;i;){let s=i.nextSibling;e.removeChild(i),i=s}return r}function Zr(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 un,receiverShadowCache:new Map,receiverShadowCacheKey:new Map,casterItemsCache:new Map,casterItemsCacheKey:new Map}}import{buildSharedEdgeMap as cl,computeReceiverShadowFaces as dl,meshScaleVec3 as ti,prepareCasterEdgeOwners as ul,prepareCasterPolyItems as pl,prepareReceiverFacePlanes as ml}from"@layoutit/polycss-core";function Qr(e){for(let n of e)n.svg&&n.svg.parentNode&&n.svg.parentNode.removeChild(n.svg),n.svg=null}function qr(e,n){if(n){let t=e.receiverShadowCache.get(n);t&&Qr(t),e.receiverShadowCache.delete(n),e.receiverShadowCacheKey.delete(n)}else{for(let t of e.receiverShadowCache.values())Qr(t);e.receiverShadowCache.clear(),e.receiverShadowCacheKey.clear()}}function Kr(e,n){n?(e.casterItemsCache.delete(n),e.casterItemsCacheKey.delete(n)):(e.casterItemsCache.clear(),e.casterItemsCacheKey.clear())}function Jr(e){Wr(e.shadowSvgState),ei(e)}function Ao(e){return e.handle.id??e.autoMeshId}var fl="http://www.w3.org/2000/svg",pn=new WeakMap,ni=new WeakMap,oi=new WeakMap,ri=new WeakMap,ii=new WeakMap;function si(e){let n=pn.get(e);return n||(n=new Map,pn.set(e,n)),n}function Mo(e){let n=pn.get(e);if(n){for(let t of n.values())t.svg&&t.svg.parentNode&&t.svg.parentNode.removeChild(t.svg);n.clear(),pn.delete(e)}}function ei(e){for(let n of e.meshes)Mo(n)}function ai(e,n,t,o,r,i,s,c,l,p){let g=e.options.current,{receiverShadowCache:x,receiverShadowCacheKey:f,casterItemsCache:b,casterItemsCacheKey:y}=e,P=o.handle.transform.position??[0,0,0],v=o.handle.transform.rotation??[0,0,0],C=o.polygons.some(A=>A.texture!==void 0),F=ti(o.handle.transform.scale),k=o.bboxCenterCss,z=g.shadow?.lift??.001,O=`${o.polygons.length}|${r.size}|${P.join(",")}|${v.join(",")}|${F.join(",")}|${k?k.join(","):"n"}|${z}`,Z=x.get(o);if(Z===void 0||f.get(o)!==O){Z=ml(o.polygons,P,o.handle.transform.scale,r,z,v),x.set(o,Z),f.set(o,O);let A=si(o);for(let h of A.values())h.svg&&h.svg.parentNode&&h.svg.parentNode.removeChild(h.svg);A.clear()}let q=[];for(let A of n){let h=A.handle.transform.position??[0,0,0],u=A.handle.transform.rotation??[0,0,0],d=ti(A.handle.transform.scale),T=A.bboxCenterCss,w=`${A.polygons.length}|${h.join(",")}|${u.join(",")}|${d.join(",")}|${T?T.join(","):"n"}`,R=b.get(A);if(R===void 0||y.get(A)!==w){let _=t.get(A),j=new Set;for(let Q of A.rendered)Q.plan&&!_.has(Q.polygonIndex)&&j.add(Q.polygonIndex);R=pl(A.polygons,h,A.handle.transform.scale,Q=>j.has(Q),u),b.set(A,R),y.set(A,w)}let L;if(A===o){let _=ni.get(A);(_===void 0||oi.get(A)!==A.polygons)&&(_=cl(A.polygons),ni.set(A,_),oi.set(A,A.polygons)),L=_}let te;if(A!==o&&A.polygons.length>=40){let _=ri.get(A);(_===void 0||ii.get(A)!==w)&&(_=ul(A.polygons,h,A.handle.transform.scale,u),ri.set(A,_),ii.set(A,w)),te=_}q.push({id:A,items:R,selfShadowEdgeMap:L,edgeOwners:te,casterPolygonCount:A.polygons.length})}let D={rotX:e.camera.state.rotX,rotY:e.camera.state.rotY,meshRotation:o.handle.transform.rotation},H=dl({receiverPlanes:Z,receiverPolygons:o.polygons,receiverHasTexture:C,casters:q,lightDir:i,cameraRot:D,ambientLight:g.ambientLight,directionalLight:g.directionalLight,shadow:{color:g.shadow?.color,opacity:p,maxExtend:g.shadow?.maxExtend}}),V=si(o),G=new Set;for(let A of H){G.add(A.faceIndex);let h=V.get(A.faceIndex);h||(h={svg:null,visible:!1,width:-1,height:-1,matrixCss:""},V.set(A.faceIndex,h));let u=h.svg;u?(h.visible||(u.style.display="block"),(h.width!==A.width||h.height!==A.height)&&(u.setAttribute("width",String(A.width)),u.setAttribute("height",String(A.height)),u.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),h.width=A.width,h.height=A.height),h.matrixCss!==A.matrixCss&&(u.style.transform=A.matrixCss,h.matrixCss=A.matrixCss)):(u=e.doc.createElementNS(fl,"svg"),u.setAttribute("class","polycss-shadow polycss-shadow-svg polycss-shadow-receiver"),g.debugShadowAttrs&&(u.setAttribute("data-poly-shadow-type","receiver"),u.setAttribute("data-poly-shadow-receiver",Ao(o)),u.setAttribute("data-poly-shadow-receiver-face",String(A.faceIndex)),u.setAttribute("data-poly-shadow-receiver-polys",JSON.stringify(A.memberPolyIndices))),u.setAttribute("width",String(A.width)),u.setAttribute("height",String(A.height)),u.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),u.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}`),jr(e.shadowSvgState,e.doc,e.sceneEl).appendChild(u),h.svg=u,h.width=A.width,h.height=A.height,h.matrixCss=A.matrixCss),h.visible=!0;let d=Xr(u,e.doc,A.paths.length,!0),T=A.opacity.toFixed(4),w=[],R=!!g.debugShadowAttrs;for(let L=0;L<A.paths.length;L++){let te=A.paths[L],_=R?Ao(te.casterId):"";R&&w.push(_);let j=d[L];if(j.setAttribute("d",te.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(te.casterPolygonIndices);j.getAttribute("data-poly-shadow-caster-polys")!==Q&&j.setAttribute("data-poly-shadow-caster-polys",Q)}}if(R){let L=w.join(" ");u.getAttribute("data-poly-shadow-casters")!==L&&u.setAttribute("data-poly-shadow-casters",L)}}for(let[A,h]of V)G.has(A)||h.svg&&h.visible&&(h.svg.style.display="none",h.visible=!1)}var li=Symbol.for("polycss.animation.triangleFrameTarget");var Tl=750;function ui(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:mi}}var Al={key:"non-cullable",normal:[1,1,0]};function pi(){return[Al]}function fi(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&&kr(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...r}=n,i=ui({seamBleed:mi,...r}),s=Dr(e),c=[0,0,0],l=e.ownerDocument??document,p=l.createElement("div");p.className="polycss-camera",Z(p,i),e.appendChild(p);let g=l.createElement("div");g.className="polycss-scene",g.setAttribute("aria-hidden","true"),q(g,i),p.appendChild(g);let x=Zr({host:e,doc:l,cameraEl:p,sceneEl:g,camera:t,layoutScale:s,options:i}),f=x.meshes,b=new WeakMap,y=x.shadowSvgState,P=()=>Yr(y),v=()=>Jr(x),C=null;function F(a){if(!a)return null;let m=Math.hypot(a[0],a[1],a[2]);if(!Number.isFinite(m)||m<=0)return null;let S=Math.round(a[0]/m*100)/100,E=Math.round(a[1]/m*100)/100,W=Math.round(a[2]/m*100)/100;return`${S}|${E}|${W}`}function k(){C=null}let z=a=>qr(x,a),O=a=>Kr(x,a);function Z(a,m){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 q(a,m){Or(a,s),a.style.transform=Co(t,c,s),Gr(a,m)}function D(a){a.style.transform=Co(t,c,s)}function H(a){a.voxelRenderer?.dispose(),a.voxelRenderer=void 0,h(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 m of Array.from(a.wrapper.children))m instanceof HTMLElement&&m.classList.contains("polycss-bucket")&&m.remove();a.hasBuckets=!1}function V(a){for(let m of Array.from(a.wrapper.childNodes)){if(!(m instanceof HTMLElement))return m;if(m.classList.contains("polycss-bucket")||m.classList.contains("polycss-shadow"))continue;let S=m.tagName.toLowerCase();if(!(S==="b"||S==="i"||S==="s"||S==="u"||S==="q"))return m}return null}function G(a,m,S){S?.parentNode===a.wrapper?a.wrapper.insertBefore(m,S):a.wrapper.appendChild(m)}function A(a){for(let m of a.shadowRendered)m.parentNode&&m.parentNode.removeChild(m);a.shadowRendered.length=0,v()}function h(a,m){m?.();for(let S of a){try{S.dispose()}catch{}S.element.parentNode&&S.element.parentNode.removeChild(S.element)}}function u(a,m,S){a.rendered=m,a.renderedByPolygonIndex=[];for(let E of m)a.renderedByPolygonIndex[E.polygonIndex]=E;a.disposeAtlas=S,a.solidLightingPreviewPrepared=!1}function d(a,m){let S=a.renderedByPolygonIndex[m];return S?.polygonIndex===m?S:void 0}function T(a){for(let m of Array.from(a.wrapper.children))m instanceof HTMLElement&&m.classList.contains("polycss-bucket")&&m.remove();a.hasBuckets=!1;for(let m of a.rendered)m.element.parentNode&&m.element.parentNode.removeChild(m.element)}function w(a,m){let S=a.polygons[m.polygonIndex];return a.stableDom&&S?di(S):m.plan?.normal??(S?di(S):null)}function R(a){if(!Q(a))return a.rendered;let m=L(a);return a.rendered.filter(S=>te(a,S,wo,m))}function L(a){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:a.handle.transform.rotation}}function te(a,m,S=wo,E=L(a)){let W=w(a,m);return W===null||Sl(W,E,S)}function _(a){if(a.excludeFromAutoCenter){a.cameraCullGroups=[];return}let m=new Map;for(let S of a.rendered){let E=w(a,S);if(!E)continue;if(!xl(E)){a.cameraCullGroups=pi();return}let W=gl(E);if(!m.has(W)&&(m.set(W,E),m.size>hl)){a.cameraCullGroups=pi();return}}a.cameraCullGroups=Array.from(m,([S,E])=>({key:S,normal:E}))}function j(a){return Q(a)?yl(a.cameraCullGroups,L(a)):"all"}function Q(a){return!a.excludeFromAutoCenter&&Pl(a.cameraCullGroups)}function re(a){a.cameraCullSignature=Q(a)?j(a):"all"}function fe(a,m){let S=new Array(a.rendered.length),E=!1,W=L(a);for(let K=0;K<a.rendered.length;K+=1){let oe=a.rendered[K],J=te(a,oe,m,W);S[K]=J}let B=null,I=null,U=()=>{if(!(!B||!I)){if(B===I)B.remove();else{let K=l.createRange();K.setStartBefore(B),K.setEndAfter(I),K.deleteContents(),K.detach()}B=null,I=null,E=!0}};for(let K=0;K<a.rendered.length;K+=1){let oe=a.rendered[K];!S[K]&&oe.element.parentNode===a.wrapper?(I&&I.nextSibling===oe.element||(U(),B=oe.element),I=oe.element):U()}U();let Y=K=>{for(let oe=K;oe<a.rendered.length;oe+=1){let J=a.rendered[oe].element;if(J.parentNode===a.wrapper)return J}return V(a)},ae=-1,ne=K=>{if(ae<0)return;let oe=l.createDocumentFragment();for(let J=ae;J<K;J+=1){let He=a.rendered[J];be(a,He),oe.appendChild(He.element)}G(a,oe,Y(K)),ae=-1,E=!0};for(let K=0;K<a.rendered.length;K+=1){let oe=a.rendered[K];S[K]&&oe.element.parentNode!==a.wrapper?ae<0&&(ae=K):ne(K)}return ne(a.rendered.length),E}function ue(a,m=!1){if(a.voxelRenderer){m?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&&ve(a);return}if(a.hasBuckets){pe(a,m);return}let S=j(a);if(!m&&S===a.cameraCullSignature)return;let E=fe(a,wo);a.cameraCullSignature=S,E&&Ne(a)}function pe(a,m=!1){let S=Q(a)?j(a):"all";!m&&S===a.cameraCullSignature||ve(a)}function Ce(a,m){return w(a,m)}function be(a,m){if(i.textureLighting!=="dynamic")return;let S=Ce(a,m);S&&(m.element.style.setProperty("--pnx",S[0].toFixed(4)),m.element.style.setProperty("--pny",S[1].toFixed(4)),m.element.style.setProperty("--pnz",S[2].toFixed(4)))}function Ae(a){T(a),a.hasBuckets=!1;let m=a.skipBucketNormalCleanupOnce;a.skipBucketNormalCleanupOnce=!1;let S=l.createDocumentFragment(),E=i.textureLighting==="dynamic"&&!a.stableDom,W=new Map,B=[];for(let I of R(a)){let U=a.polygons[I.polygonIndex],Y=E&&U?Hr(U):null;if(!Y){B.push(I);continue}let ae=Y.key+"|"+(U.color??""),ne=W.get(ae);ne||(ne={vec:Y.vec,items:[]},W.set(ae,ne)),ne.items.push(I)}for(let I of B)be(a,I),S.appendChild(I.element);for(let I of W.values()){if(I.items.length<2){for(let Y of I.items)be(a,Y),S.appendChild(Y.element);continue}let U=l.createElement("div");U.className="polycss-bucket",a.hasBuckets=!0,U.style.setProperty("--pnx",String(I.vec[0])),U.style.setProperty("--pny",String(I.vec[1])),U.style.setProperty("--pnz",String(I.vec[2]));for(let Y of I.items)U.appendChild(Y.element),(!m||Y.kind==="triangle")&&(Y.element.style.removeProperty("--pnx"),Y.element.style.removeProperty("--pny"),Y.element.style.removeProperty("--pnz"));S.appendChild(U)}G(a,S,V(a)),re(a)}function ze(){return new Promise(a=>setTimeout(a,0))}async function Qe(a,m){if(i.textureLighting==="dynamic"&&!a.stableDom)return Ae(a),!m();T(a);let E=l.createDocumentFragment(),W=V(a),B=0;for(let I of R(a)){if(m())return!1;be(a,I),E.appendChild(I.element),B++,B%Tl===0&&(G(a,E,W),E=l.createDocumentFragment(),await ze())}return E.childNodes.length>0&&G(a,E,W),re(a),!m()}function rt(a,m){let S=i.textureLighting==="dynamic",E=i.directionalLight?.direction,W=m&&(m[0]!==0||m[1]!==0||m[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=Lo(E,m),I=Pt(B),U=Math.hypot(I[0],I[1],I[2])||1,Y=(I[0]/U).toFixed(2),ae=(I[1]/U).toFixed(2),ne=(I[2]/U).toFixed(2),K=`${Y}|${ae}|${ne}`;a.lightOverrideSignature!==K&&(a.wrapper.style.setProperty("--plx",Y),a.wrapper.style.setProperty("--ply",ae),a.wrapper.style.setProperty("--plz",ne),a.lightOverrideSignature=K)}function ut(a){let m=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let E=a.polygons[S.polygonIndex];E&&(m=To(S,E,i)||m)}return a.solidLightingPreviewPrepared=!1,a.solidLightingPreviewActive=!1,m}function it(a){if((i.textureLighting??"baked")!=="baked")return!1;let m=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let E=a.polygons[S.polygonIndex];E&&(Ur(S,E,S.plan.shadedColor),m=!0)}return a.solidLightingPreviewPrepared=m,m}function jn(a){return(i.textureLighting??"baked")!=="baked"||!a.solidLightingPreviewPrepared&&!it(a)?!1:(a.solidLightingPreviewActive=!0,!0)}function Wn(a){return a.kind==="atlas"||!!a.plan?.texture}function Yn(){if((i.textureLighting??"baked")!=="baked")return!1;let a=!1;for(let m of f)a=ut(m)||a,m.rendered.some(Wn)&&(Rt(m),a=!0);g.style.removeProperty(St);for(let m of f)lt(m.wrapper),m.solidLightingPreviewActive=!1;return lt(g),a}function Xn(){g.style.removeProperty(St);for(let a of f)a.solidLightingPreviewActive&&(ut(a),lt(a.wrapper));(i.textureLighting??"baked")!=="dynamic"&&(lt(g),k(),Ee())}function $(a,m){let S=a.handle.transform.rotation,E=m.directionalLight?.direction??i.directionalLight?.direction;if(!(S&&(S[0]!==0||S[1]!==0||S[2]!==0))||!E){lt(a.wrapper);return}let B=Lo(E,S);dn(a.wrapper,{...i,...m,directionalLight:{...i.directionalLight,...m.directionalLight,direction:B}})}function ie(a){if((i.textureLighting??"baked")!=="baked")return!1;dn(g,{...i,...a}),!a.skipShadows&&a.directionalLight?.direction&&Ee(a.directionalLight.direction);let m=!1;for(let S of f)$(S,a),m=jn(S)||m;return m?de(g,St,"1"):g.style.removeProperty(St),m}function se(a,m,S){let E=a.polygons[m];if(!E)return!1;let W=d(a,m);if(!W)return!1;let B=i.textureLighting??"baked";return B==="dynamic"?($r(W.element,S),!0):B==="baked"?To(W,E,i):!1}function Me(a,m){let S=a.polygons[m];if(!S)return!1;let E=d(a,m);return E?(ye(E.element,S,m),!0):!1}function _t(a,m,S){return!(S.length===0||!S.every(E=>E==="color"||E==="data")||S.includes("color")&&!se(a,m,a.polygons[m]?.color)||S.includes("data")&&!Me(a,m))}function Ne(a){k(),Ee()}function Ee(a){let m=[];for(let J of f)!J.disposed&&J.castShadow&&m.push(J);if(m.length===0){v(),C=null;return}let S=i.shadow?.color??"#000000",E=i.shadow?.opacity??.25,W=El(S)?.rgb??[0,0,0],B=W[0],I=W[1],U=W[2],Y=a??i.directionalLight?.direction??[.4,-.7,.59],ae=Pt(Y),ne=F(ae);if(ne!==null&&ne===C)return;let K=new Map;for(let J of m)K.set(J,ci(J.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.95,preserveDoubleSidedBackfaces:!1}));let oe=new Map;for(let J of f)J.disposed||!J.receiveShadow||oe.set(J,new Set);P();for(let J of f)J.disposed||!J.receiveShadow||ai(x,m,K,J,oe.get(J)??new Set,ae,B,I,U,E);C=ne}function ve(a){if(a.voxelRenderer){a.voxelRenderer.render(L(a)),a.cameraCullSignature="voxel-direct";return}A(a),Ae(a),Ne(a)}function De(a,m){if(!m||!a.polygons||a.polygons.length<2)return;let S=Math.hypot(m[0],m[1],m[2]);if(!Number.isFinite(S)||S<=0)return;let E=m[0]/S,W=m[1]/S,B=m[2]/S,I=K=>Math.round(K*1e3)/1e3,U=`${I(E)},${I(W)},${I(B)}`,Y=a.lightOcclusionCache;if(Y&&Y.polygons===a.polygons&&Y.lightDirKey===U)return Y.occluded;let ae=Y&&Y.polygons===a.polygons?Y.dedupDropped:ci(a.polygons,{normalTolerance:.1,distanceTolerance:.12,overlapFraction:.98,preserveDoubleSidedBackfaces:!1}),ne=vl(a.polygons,[E,W,B],ae);return a.lightOcclusionCache={polygons:a.polygons,lightDirKey:U,occluded:ne,dedupDropped:ae},ne}function Oe(a){return!!a.voxelSource&&i.textureLighting!=="dynamic"&&!a.stableDom&&!a.castShadow}function Se(a,m){H(a);let S=i.directionalLight,E=m?{...S,direction:m}:S,W=ot(E),B=void 0;if(Oe(a)){let Y=_r({doc:l,wrapper:a.wrapper,polygons:a.parseResult.polygons,directionalLight:W,ambientLight:i.ambientLight});if(Y){a.voxelRenderer=Y,Y.render(L(a)),a.cameraCullSignature="voxel-direct";return}}let I={doc:l,directionalLight:W,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies,lightOccludedPolyIndices:B},U=a.stableDom?(()=>{let Y=vt(a.polygons,I);return ct(a.wrapper,Y),Nt(a.polygons,{...I,solidPaintDefaults:Y})??xt(a.polygons,{...I,solidPaintDefaults:Y})})():xt(a.polygons,{...I,computeSolidPaintDefaults:!0,skipDynamicNormalVars:i.textureLighting==="dynamic"});a.stableDom||ct(a.wrapper,U.solidPaintDefaults??{}),u(a,U.rendered,U.dispose),a.skipBucketNormalCleanupOnce=i.textureLighting==="dynamic"&&!a.stableDom,_(a),Ae(a),Ne(a)}function Rt(a,m){if(a.rendered.length===0||a.voxelRenderer||a.stableDom||Oe(a)){Se(a,m);return}if(a.rendered[0]?.element.parentNode===null){Se(a,m);return}let S=i.directionalLight,E=m?{...S,direction:m}:S,W=ot(E),B={doc:l,directionalLight:W,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies,computeSolidPaintDefaults:!0,skipDynamicNormalVars:i.textureLighting==="dynamic"},I=xt(a.polygons,B),U=()=>{a.rebakeInFlight=!1;let ne=a.rebakeQueuedLightDir;ne!==null&&(a.rebakeQueuedLightDir=null,Rt(a,ne))},Y=()=>{if(a.disposed){I.dispose(),U();return}if(I.rendered.length!==a.rendered.length){I.dispose(),Se(a,m),U();return}for(let oe of I.rendered){let J=a.renderedByPolygonIndex[oe.polygonIndex];if(!J)continue;let He=oe.element.getAttribute("style");He!==null&&J.element.setAttribute("style",He)}let ne=I.solidPaintDefaults;ne&&ct(a.wrapper,ne);let K=a.disposeAtlas;a.disposeAtlas=I.dispose,K&&(typeof requestAnimationFrame=="function"?J=>{requestAnimationFrame(J)}:J=>{setTimeout(J,0)})(K),Ne(a),U()},ae=I.pagesReady;ae&&typeof ae.then=="function"?ae.then(()=>Qn(I.rendered)).then(qn).then(Y,()=>{I.dispose(),a.disposed||Se(a,m),U()}):Y()}function Zn(a,m){if(a.rebakeInFlight){a.rebakeQueuedLightDir=m;return}a.rebakeInFlight=!0,Rt(a,m)}function Qn(a){let m=new Set;for(let S of a){let E=S.element.getAttribute("style")??"",W=/url\((blob:[^)]+)\)/g,B;for(;(B=W.exec(E))!==null;)m.add(B[1])}return Array.from(m)}function qn(a){return a.length===0||typeof Image>"u"?Promise.resolve():Promise.all(a.map(m=>{let S=new Image;S.src=m;let E=S.decode?.();return E?E.catch(()=>{}):Promise.resolve()})).then(()=>{})}function qe(){let a=1/0,m=!1;for(let B of f)if(!B.disposed&&B.receiveShadow){m=!0;break}for(let B of f){if(B.disposed||!(m?B.receiveShadow:B.castShadow))continue;let U=B.handle.transform.position?.[2]??0;for(let Y of B.polygons)for(let ae of Y.vertices){let ne=ae[2]+U;ne<a&&(a=ne)}}if(!Number.isFinite(a)){let B=y.currentGroundCssZ!==null;y.currentGroundCssZ=null,B&&(v(),k());return}let S=i.shadow?.lift??.05,E=(a+S)*Ve,W=y.currentGroundCssZ;y.currentGroundCssZ=E,W!==E&&(k(),Ee())}async function Zt(a,m){H(a);let S=ot(i.directionalLight),E={doc:l,directionalLight:S,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies,lightOccludedPolyIndices:void 0},W=a.stableDom?Nt(a.polygons,E):null;if(W){let U=vt(a.polygons,E);return ct(a.wrapper,U),u(a,W.rendered,W.dispose),_(a),Ae(a),Ne(a),!m()}let B=await sn(a.polygons,{...E,skipDynamicNormalVars:i.textureLighting==="dynamic"},m);if(m())return B.dispose(),!1;ct(a.wrapper,B.solidPaintDefaults),u(a,B.rendered,B.dispose),a.skipBucketNormalCleanupOnce=i.textureLighting==="dynamic"&&!a.stableDom,_(a);let I=await Qe(a,m);return I&&Ne(a),I}function st(){let a=c,m=[0,0,0];if(i.autoCenter){let S=[];for(let E of f)!E.disposed&&!E.excludeFromAutoCenter&&S.push(...E.polygons);if(S.length>0){let E=bl(S);m=[(E.min[0]+E.max[0])/2,(E.min[1]+E.max[1])/2,(E.min[2]+E.max[2])/2]}}a[0]===m[0]&&a[1]===m[1]&&a[2]===m[2]||(c=m,x.autoCenter.offset=m,q(g,i))}function Ni(a,m={}){let E=(g.ownerDocument??document).createElement("div");E.className="polycss-mesh",m.id&&E.setAttribute("data-poly-mesh-id",m.id);let W=`polycss-mesh-${x.meshAutoCounter.next++}`;E.setAttribute("data-poly-mesh-index",W);let B={...m},I=m.merge!==!1,U=!!m.stableDom,Y=0,ae=cn(B);ae&&(E.style.transform=ae);let ne=(N,X)=>a.voxelSource?N:X?Cl(N,{meshResolution:m.meshResolution}):(U||m.excludeFromAutoCenter,N),K=ne(a.polygons,I),oe=null;function J(){let N=cn(B);E.style.transform=N??""}function He(N){if(N.length===0){oe=null,Ge&&(Ge.bboxCenterCss=null),J();return}let X=1/0,le=1/0,me=1/0,Le=-1/0,ce=-1/0,ge=-1/0;for(let je of N)for(let Fe of je.vertices)Fe[0]<X&&(X=Fe[0]),Fe[0]>Le&&(Le=Fe[0]),Fe[1]<le&&(le=Fe[1]),Fe[1]>ce&&(ce=Fe[1]),Fe[2]<me&&(me=Fe[2]),Fe[2]>ge&&(ge=Fe[2]);if(!Number.isFinite(X)){oe=null,Ge&&(Ge.bboxCenterCss=null),J();return}let Ie=(le+ce)/2*Ve,Ue=(X+Le)/2*Ve,_e=(me+ge)/2*Ve;oe=[Ie,Ue,_e],Ge&&(Ge.bboxCenterCss=oe),J()}let Ge=null;He(K),g.appendChild(E);let M={handle:void 0,wrapper:E,parseResult:a,rendered:[],renderedByPolygonIndex:[],shadowRendered:[],polygons:K,voxelSource:a.voxelSource,disposed:!1,stableDom:U,hasBuckets:!1,skipBucketNormalCleanupOnce:!1,excludeFromAutoCenter:!!m.excludeFromAutoCenter,castShadow:!!m.castShadow,bboxCenterCss:oe,receiveShadow:!!m.receiveShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",stableTriangleColorFrame:0,solidLightingPreviewPrepared:!1,solidLightingPreviewActive:!1,bakedRotation:m.rotation?[...m.rotation]:[0,0,0],autoMeshId:W,rebakeInFlight:!1,rebakeQueuedLightDir:null},$e=null,Kn=0,Qt=-1,kt=null;function Dt(){$e=null,kt=null,Qt=-1}function Bo(){let N=$e;if(!N||N.polygonCount!==M.polygons.length)return M.polygons;if(kt&&Qt===Kn)return kt;let X=N.vertices,le=new Array(N.polygonCount);for(let me=0;me<N.polygonCount;me++){let Le=M.polygons[me],ce=me*9;le[me]={...Le,color:N.colors?.[me]??Le.color,vertices:[[X[ce],X[ce+1],X[ce+2]],[X[ce+3],X[ce+4],X[ce+5]],[X[ce+6],X[ce+7],X[ce+8]]]}}return kt=le,Qt=Kn,le}function zo(N,X){let le=N?.stableTriangleUpdateMode==="color-only";M.stableTriangleColorFrame++;let me=M.stableDom&&!X;if(me||He(M.polygons),M.stableDom&&!M.hasBuckets){let Le={doc:l,directionalLight:ot(i.directionalLight),ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed},ce=M.rendered.length===M.polygons.length&&M.rendered.every(_e=>_e.kind==="triangle"),ge=M.stableDom&&!X,Ie=ce||ge?{}:vt(M.polygons,Le);ce||ct(M.wrapper,Ie);let Ue={...Le,solidPaintDefaults:Ie,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:M.stableTriangleColorFrame};if(ln(M.rendered,M.polygons,Ue))return le||(_(M),ue(M,!0),X&&st()),!0}return me&&He(M.polygons),!1}let pt={get polygons(){return Bo()},set polygons(N){Dt(),M.polygons=N},element:E,id:m.id,get transform(){return B},remove(){Y++,E.parentNode&&E.parentNode.removeChild(E),H(M),f.delete(M),b.delete(E),z(M),O(M),st(),qe()},setPolygons(N,X){Y++,I=X?.merge??I,U=X?.stableDom??U,M.stableDom=U,M.voxelSource=void 0,M.polygons=ne(N,I),O(M),z(M),Dt(),pt.polygons=M.polygons;let le=X?.recomputeAutoCenter??!0;zo(X,le)||(Se(M),le&&st())},[li](N,X){let le=X?.merge??I,me=X?.stableDom??U;if(!N.solidTriangles||!me||le||m.meshResolution!==void 0||M.hasBuckets||N.polygonCount!==M.polygons.length||N.vertices.length<N.polygonCount*9||M.rendered.length!==N.polygonCount)return!1;for(let ge=0;ge<M.rendered.length;ge++){let Ie=M.rendered[ge],Ue=M.polygons[ge];if(Ie?.kind!=="triangle"||Ie.polygonIndex!==ge||!Ue||Ue.vertices.length!==3||Ue.texture||Ue.material?.texture)return!1}let Le=X?.recomputeAutoCenter??!0;if(!Le){let ge=M.stableTriangleColorFrame+1,Ie={doc:l,directionalLight:ot(i.directionalLight),ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.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:ge};if(an(M.rendered,M.polygons,N,Ie))return Y++,I=le,U=me,M.stableDom=U,M.voxelSource=void 0,M.stableTriangleColorFrame=ge,$e=N,Kn++,kt=null,Qt=-1,Q(M)?(_(M),ue(M,!0)):re(M),!0}Y++,I=le,U=me,M.stableDom=U,M.voxelSource=void 0;let ce=N.vertices;for(let ge=0;ge<N.polygonCount;ge++){let Ie=M.polygons[ge],Ue=N.colors?.[ge];Ue&&(Ie.color=Ue);let _e=Ie.vertices,je=ge*9;_e[0][0]=ce[je],_e[0][1]=ce[je+1],_e[0][2]=ce[je+2],_e[1][0]=ce[je+3],_e[1][1]=ce[je+4],_e[1][2]=ce[je+5],_e[2][0]=ce[je+6],_e[2][1]=ce[je+7],_e[2][2]=ce[je+8]}return Dt(),pt.polygons=M.polygons,zo(X,Le)},updatePolygon(N,X){let le=typeof N=="number"?N:M.polygons.indexOf(N);if(le<0&&typeof N!="number"&&$e&&(le=Bo().indexOf(N)),le<0||le>=M.polygons.length)return;Dt(),M.voxelSource=void 0,Object.assign(M.polygons[le],X);let me=Object.keys(X);_t(M,le,me)||Se(M)},async setPolygonsChunked(N,X){let le=++Y;I=X?.merge??I,U=X?.stableDom??U,M.stableDom=U,M.voxelSource=void 0,M.polygons=ne(N,I),Dt(),pt.polygons=M.polygons,He(M.polygons);let me=X?.recomputeAutoCenter??!0;if(!await Zt(M,()=>M.disposed||le!==Y)){H(M);return}me&&st()},setTransform(N){let X=M.castShadow,le=M.receiveShadow;N.castShadow!==void 0&&(M.castShadow=!!N.castShadow),N.receiveShadow!==void 0&&(M.receiveShadow=!!N.receiveShadow),B={...B,...N};let me=cn(B);E.style.transform=me??"",rt(M,B.rotation),N.rotation!==void 0&&ue(M,!0),M.castShadow!==X&&(M.voxelSource&&Se(M),Ne(M),qe()),M.receiveShadow!==le&&(M.receiveShadow||Mo(M),k(),Ee()),(N.position!==void 0||N.scale!==void 0)&&(M.castShadow||M.receiveShadow)&&(qe(),k(),Ee())},dispose(){if(!M.disposed){M.disposed=!0,Y++,E.parentNode&&E.parentNode.removeChild(E),H(M);try{a.dispose()}catch{}f.delete(M),b.delete(E),st(),qe()}},rebakeAtlas(){M.bakedRotation=B.rotation?[...B.rotation]:[0,0,0];let N=i.directionalLight?.direction??[.4,-.7,.59],X=Lo(N,M.bakedRotation);Zn(M,X)},getPosition(){return B.position},getRotation(){return B.rotation},getScale(){return B.scale},getPolygons(){return pt.polygons}};return M.handle=pt,Ge=M,b.set(E,M),f.add(M),Se(M),rt(M,B.rotation),st(),qe(),M.receiveShadow&&(k(),Ee()),pt}function Gi(a){let m=!!i.autoCenter,S=i.strategies,E=i.seamBleed,W=i.textureLighting,B=i.directionalLight?.direction,I=i.shadow,U=ui(a);i={...i,...U},x.options.current=i,q(g,i);let Y=!!i.autoCenter;for(let $e of f)rt($e,$e.handle.transform.rotation);let ae=a.strategies!==void 0&&!Ir(a.strategies,S),ne=Object.prototype.hasOwnProperty.call(a,"seamBleed")&&U.seamBleed!==E;if(ae||ne)for(let $e of f)Se($e);m!==Y&&st();let K=a.textureLighting!==void 0&&W!==i.textureLighting,oe=i.directionalLight?.direction,J=a.directionalLight!==void 0&&!Fr(B,oe),He=i.shadow,Ge=a.shadow!==void 0&&!Vr(I,He),M=J||Ge;if(K){if(!ae&&!ne)for(let $e of f)Se($e);qe(),k(),Ee()}else M&&(Ge&&k(),Ee());Ge&&a.shadow?.lift!==I?.lift&&qe()}function $i(){return i}function Ui(){D(g);for(let a of f)ue(a)}function ji(){let a=[];for(let m of f)a.push(m.handle);return a}function Wi(a){let m=a;for(;m;){if(m instanceof HTMLElement){let S=b.get(m);if(S&&!S.disposed)return S.handle;if(m.classList.contains("polycss-mesh"))return null}m=m.parentElement}return null}function Yi(){let a=Array.from(f);for(let m of a)try{m.handle.dispose()}catch{}p.parentNode&&p.parentNode.removeChild(p)}return{add:Ni,setOptions:Gi,destroy:Yi,host:e,camera:t,cameraEl:p,applyCamera:Ui,getOptions:$i,meshes:ji,findMeshByElement:Wi,previewBakedSolidLighting:ie,commitBakedSolidLighting:Yn,clearBakedSolidLightingPreview:Xn}}import{createIsometricCamera as hi}from"@layoutit/polycss-core";var Ml=32e3;function Ut(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=hi(n),o=`${e.perspective??Ml}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function jt(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=hi(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var wl=typeof HTMLElement<"u"?HTMLElement:class{},Ll=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function Be(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function _l(e){return e==="false"?!1:Be(e)}function _o(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 Rl(e){if(e==="baked"||e==="dynamic")return e}function kl(e){return e==="auto"?"auto":Be(e)}function Dl(e){return typeof e.getCamera=="function"}var we=class extends wl{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...Ll]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(Dl(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=_l(this.getAttribute("perspective")),o=Be(this.getAttribute("rot-x")),r=Be(this.getAttribute("rot-y")),i=Be(this.getAttribute("zoom")),s=Be(this.getAttribute("distance")),c=_o(this.getAttribute("target")),l={...o!==void 0?{rotX:o}:{},...r!==void 0?{rotY:r}:{},...i!==void 0?{zoom:i}:{},...s!==void 0?{distance:s}:{},...c!==void 0?{target:c}:{}};return t===!1?jt(l):t!==void 0?Ut({...l,perspective:t}):jt(l)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={};r.textureLighting=Rl(this.getAttribute("texture-lighting"))??"baked";let i=kl(this.getAttribute("texture-quality"));return i!==void 0&&(r.textureQuality=i),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=_o(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=Be(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let i={direction:t??[.4,-.7,.59]};return o&&(i.color=o),r!==void 0&&(i.intensity=r),i}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=Be(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=fi(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 s=Be(this.getAttribute("rot-x")),c=Be(this.getAttribute("rot-y")),l=Be(this.getAttribute("zoom")),p=Be(this.getAttribute("distance")),g=_o(this.getAttribute("target"));s!==void 0&&this._implicitCamera.update({rotX:s}),c!==void 0&&this._implicitCamera.update({rotY:c}),l!==void 0&&this._implicitCamera.update({zoom:l}),p!==void 0&&this._implicitCamera.update({distance:p}),g!==void 0&&this._implicitCamera.update({target:g}),this._scene.applyCamera();return}this._scene.setOptions(this._readNonCameraOptions())}}};import{computeSceneBbox as Ol,loadMesh as Hl}from"@layoutit/polycss-core";var Il=typeof HTMLElement<"u"?HTMLElement:class{},Fl=["src","mtl","mesh-resolution","position","scale","rotation","auto-center","cast-shadow","receive-shadow","target-size","default-color","palette","include-objects","exclude-objects"];function Wt(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 gi(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Wt(e)}}function Ro(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 Vl(e){let n=e.getAttribute("target-size"),t=e.getAttribute("default-color"),o=Ro(e.getAttribute("palette")),r=Ro(e.getAttribute("include-objects")),i=Ro(e.getAttribute("exclude-objects")),s=n!==null?parseFloat(n):NaN,c={};return Number.isFinite(s)&&(c.targetSize=s),t&&(c.defaultColor=t),o&&(c.palette=o),r&&(c.includeObjects=r),i&&(c.excludeObjects=i),Object.keys(c).length>0?c:void 0}function Bl(e){return e.closest("poly-scene")??null}function zl(e){if(e.length===0)return e;let n=Ol(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 i=s=>[s[0]-t,s[1]-o,s[2]-r];return e.map(s=>({...s,vertices:s.vertices.map(i),...s.textureTriangles?.length?{textureTriangles:s.textureTriangles.map(c=>({...c,vertices:c.vertices.map(i)}))}:null}))}var Ct=class extends Il{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Fl]}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:Wt(this.getAttribute("position")),scale:gi(this.getAttribute("scale")),rotation:Wt(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=Bl(this);if(!o)return;let r=++this._loadToken,i=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,l=Vl(this),p;try{let f=i||c!==void 0||l?{...i?{mtlUrl:i}:{},...c!==void 0?{meshResolution:c}:{},...l?{objOptions:l}:{}}:void 0;p=await Hl(t,f)}catch(f){this.dispatchEvent(new CustomEvent("polycss:error",{detail:f,bubbles:!0}));return}if(r!==this._loadToken){try{p.dispose()}catch{}return}let g=o.getScene();if(!g){try{p.dispose()}catch{}return}this.hasAttribute("auto-center")&&(p={...p,polygons:zl(p.polygons)}),this._parseResult=p,this._handle=g.add(p,{position:Wt(this.getAttribute("position")),scale:gi(this.getAttribute("scale")),rotation:Wt(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}))}};import{BASE_TILE as Yt}from"@layoutit/polycss-core";var Nl=typeof HTMLElement<"u"?HTMLElement:class{},Gl=["src","width","height","position","rotation","scale","allow","loading","referrerpolicy","sandbox","title"];function ko(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 $l(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return ko(e)}}function yi(e,n){if(e===null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}function Ul(e){let n=e.closest("poly-scene");return n?n.querySelector(".polycss-scene"):null}function jl(e,n,t,o,r){let i=typeof t=="number"?t:t?.[0]??1,s=typeof t=="number"?t:t?.[1]??1,c=typeof t=="number"?t:t?.[2]??1,l=i!==1||s!==1||c!==1,p=!!n&&(!!n[0]||!!n[1]||!!n[2]),g=(e?.[1]??0)*Yt,x=(e?.[0]??0)*Yt,f=(e?.[2]??0)*Yt,b=[];return b.push(`translate3d(${g}px, ${x}px, ${f}px)`),p&&(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(${i}, ${s}, ${c})`),b.push(`translate(${-o/2}px, ${-r/2}px)`),b.join(" ")}var mn=class extends Nl{constructor(){super(...arguments);this._wrapper=null;this._iframe=null}static get observedAttributes(){return[...Gl]}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 i=this.getAttribute(t);i===null?this._iframe.removeAttribute(t):this._iframe.setAttribute(t,i);return}this._applyGeometry()}}_mount(){let t=Ul(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 i=o.createElement("iframe");i.style.display="block",i.style.border="0",i.style.background="#000";let s=this.getAttribute("src");s&&(i.src=s);let c=this.getAttribute("allow");c&&i.setAttribute("allow",c);for(let l of["loading","referrerpolicy","sandbox","title"]){let p=this.getAttribute(l);p!==null&&i.setAttribute(l,p)}r.appendChild(i),t.appendChild(r),this._wrapper=r,this._iframe=i,this._applyGeometry()}_applyGeometry(){if(!this._wrapper||!this._iframe)return;let t=yi(this.getAttribute("width"),16),o=yi(this.getAttribute("height"),9),r=t*Yt,i=o*Yt;this._iframe.style.width=`${r}px`,this._iframe.style.height=`${i}px`;let s=ko(this.getAttribute("position")),c=ko(this.getAttribute("rotation")),l=$l(this.getAttribute("scale"));this._wrapper.style.transform=jl(s,c,l,r,i)}_teardown(){this._wrapper?.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null,this._iframe=null}};var Wl=typeof HTMLElement<"u"?HTMLElement:class{},Yl=["vertices","color","texture","uvs","position","scale","rotation"];function bi(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Do(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 Xl(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Do(e)}}function Zl(e){return e.closest("poly-scene")??null}var fn=class extends Wl{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Yl]}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=Zl(this);if(!t)return;let o=t.getScene();if(!o)return;let r=bi(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let i=this.getAttribute("color")||void 0,s=this.getAttribute("texture")||void 0,c=bi(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 g={polygons:[{vertices:r,...i!==void 0?{color:i}:{},...s!==void 0?{texture:s}:{},...c!==void 0?{uvs:c}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(g,{position:Do(this.getAttribute("position")),scale:Xl(this.getAttribute("scale")),rotation:Do(this.getAttribute("rotation"))})}};import{axesHelperPolygons as Ql}from"@layoutit/polycss-core";var ql=typeof HTMLElement<"u"?HTMLElement:class{},Kl=["size","thickness","negative","x-color","y-color","z-color"];function Jl(e){return e.closest("poly-scene")??null}function vi(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var hn=class extends ql{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Kl]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&this._handle&&this._remount()}_polygons(){return Ql({size:vi(this.getAttribute("size")),thickness:vi(this.getAttribute("thickness")),negative:this.hasAttribute("negative"),xColor:this.getAttribute("x-color")??void 0,yColor:this.getAttribute("y-color")??void 0,zColor:this.getAttribute("z-color")??void 0})}_mount(){let t=Jl(this);if(!t)return;let o=t.getScene();if(!o)return;let r={polygons:this._polygons(),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(r,{excludeFromAutoCenter:!0,merge:!1})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};import{octahedronPolygons as ec}from"@layoutit/polycss-core";var tc=typeof HTMLElement<"u"?HTMLElement:class{},nc=["direction","target","distance","size","color"],oc=5,rc=.35,ic="#ffd54a";function sc(e){return e.closest("poly-scene")??null}function xi(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 Pi(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var gn=class extends tc{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...nc]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="size"||t==="color"){this._remount();return}this._handle.setTransform({position:this._meshPosition()})}}_meshPosition(){let t=xi(this.getAttribute("direction"));if(!t)return;let o=xi(this.getAttribute("target"))??[0,0,0],r=Pi(this.getAttribute("distance"),oc),[i,s,c]=t,l=Math.hypot(i,s,c)||1;return[o[0]+i/l*r,o[1]+s/l*r,o[2]+c/l*r]}_mount(){let t=sc(this);if(!t)return;let o=t.getScene();if(!o)return;let r=Pi(this.getAttribute("size"),rc),i=this.getAttribute("color")??ic,s={polygons:ec({center:[0,0,0],size:r,color:i}),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(s,{position:this._meshPosition(),excludeFromAutoCenter:!0,merge:!1})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};import{BASE_TILE as ac}from"@layoutit/polycss-core";var yn={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Et(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 Xt(e){return e===!0?-1:e===!1?1:e}function Tt(){let e=[],n=[],t=[];function o(s){return s==="change"?e:s==="start"?n:t}function r(s){if(e.length===0)return;let c={type:"change",camera:s()},l=e.slice();for(let p of l)try{p(c)}catch(g){console.error("[polycss] controls 'change' listener threw:",g)}}function i(s,c){let l=s==="start"?n:t;if(l.length===0)return;let p={type:s,camera:c()},g=l.slice();for(let x of g)try{x(p)}catch(f){console.error(`[polycss] controls '${s}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:i}}function At(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 bn(e,n,t,o,r,i){let s=!1,c=null;return{onWheel:g=>{let x=n();if(!x.wheel||t())return;g.preventDefault();let f=g.deltaMode===1?16:g.deltaMode===2?100:1,b=g.deltaY*f;g.ctrlKey?b*=10:b*=3;let y=e.camera.state;if(x.dolly){let P=y.distance??0,v=Math.max(x.minDistance,Math.min(x.maxDistance,P+b*.05));e.camera.update({distance:v})}else{let P=Math.exp(-b*513e-6),v=y.zoom??1,C=Math.max(x.minZoom,Math.min(x.maxZoom,v*P));e.camera.update({zoom:C})}e.applyCamera(),s||(s=!0,i("start",o)),r(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,s=!1,i("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),s=!1}}}function vn(e,n,t,o,r,i,s){let c=null,l=0,p=b=>{if(c===null||o())return;let y=t();if(!y.animate){c=null;return}if(r())l=b;else{let P=Math.min(50,l?b-l:16.67);l=b;let v=y.animate.speed*(P/16.67),C=n.camera.state;if(y.animate.axis==="x"){let F=(((C.rotX??65)+v)%360+360)%360;n.camera.update({rotX:F})}else{let F=(((C.rotY??45)+v)%360+360)%360;n.camera.update({rotY:F})}n.applyCamera(),s(i)}c=e.requestAnimationFrame(p)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(p))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function Si(e,n={}){let t=Et(yn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,i=null,s={x:0,y:0},c=!1,l=!1,p=Tt(),g=At(e),{changeListeners:x,startListeners:f,endListeners:b,listenerArray:y,emitChange:P,emitInteraction:v}=p,C=vn(r,e,()=>t,()=>l,()=>c,g,P),F=d=>{if(!(!t.drag||l)&&i===null&&d.isPrimary!==!1){d.preventDefault(),i=d.pointerId,s={x:d.clientX,y:d.clientY},o.style.cursor="grabbing";try{d.target.setPointerCapture(d.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),v("start",g)}},k=d=>{if(i===null||d.pointerId!==i||!t.drag||l)return;d.preventDefault();let T=d.clientX-s.x,w=d.clientY-s.y;s={x:d.clientX,y:d.clientY};let R=Xt(t.invert),L=T/4*R,te=w/4*R,_=e.camera.state;if(d.shiftKey){let j=_.rotX??65,Q=_.rotY??45,re=Math.max(.01,_.zoom??1),fe=Math.cos(j*Math.PI/180),ue=fe>=0?Math.max(.1,fe):Math.min(-.1,fe),pe=Math.cos(Q*Math.PI/180),Ce=Math.sin(Q*Math.PI/180),be=re*ac,Ae=(T*Ce-w*pe/ue)/be,ze=-(T*pe+w*Ce/ue)/be,Qe=_.target??[0,0,0];e.camera.update({target:[Qe[0]+Ae,Qe[1]+ze,Qe[2]]})}else{let j=Math.max(0,Math.min(89,(_.rotX??65)-te)),Q=(((_.rotY??45)-L)%360+360)%360;e.camera.update({rotX:j,rotY:Q})}e.applyCamera(),P(g)},z=d=>{if(i===d.pointerId){i=null,o.style.cursor=t.drag&&!l?"grab":"";try{d.target.releasePointerCapture(d.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),v("end",g)}},O=bn(e,()=>t,()=>l,g,P,v);function Z(){o.addEventListener("pointerdown",F),o.addEventListener("pointermove",k),o.addEventListener("pointerup",z),o.addEventListener("pointercancel",z),o.addEventListener("wheel",O.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function q(){o.removeEventListener("pointerdown",F),o.removeEventListener("pointermove",k),o.removeEventListener("pointerup",z),o.removeEventListener("pointercancel",z),o.removeEventListener("wheel",O.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",O.teardown()}Z(),C.start();function D(d){let T=!!t.animate;t=Et(t,d),!l&&i===null&&(o.style.cursor=t.drag?"grab":"");let w=!!t.animate;T&&!w?C.stop():!T&&w&&C.start()}function H(){l&&(l=!1,Z(),C.start())}function V(){l||(l=!0,q(),C.stop(),i=null,c=!1,O.teardown())}function G(){V(),x.length=0,f.length=0,b.length=0}function A(d,T){let w=y(d);w.includes(T)||w.push(T)}function h(d,T){let w=y(d),R=w.indexOf(T);R>=0&&w.splice(R,1)}function u(d,T){return y(d).includes(T)}return{update:D,resume:H,pause:V,destroy:G,addEventListener:A,removeEventListener:h,hasEventListener:u}}function ee(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function xn(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 Te(e){if(e!==null)return!(e==="false"||e==="0")}function Pn(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 Sn(e){if(e==="x"||e==="y")return e}var lc=typeof HTMLElement<"u"?HTMLElement:class{},cc=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Cn=class extends lc{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...cc]}getControls(){return this._controls}_readAnimate(){let t=ee(this.getAttribute("animate-speed")),o=Sn(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:Te(r)}:{}}}_readOptions(){let t={},o=Te(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Te(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let i=ee(this.getAttribute("min-distance"));i!==void 0&&(t.minDistance=i);let s=ee(this.getAttribute("max-distance"));s!==void 0&&(t.maxDistance=s);let c=Pn(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=ee(this.getAttribute("zoom-min")),p=ee(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),p!==void 0&&(t.maxZoom=p),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof we)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=Si(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};import{BASE_TILE as dc}from"@layoutit/polycss-core";function Ci(e,n={}){let t=Et(yn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,i=null,s={x:0,y:0},c=!1,l=!1,p=!1,g={x:0,y:0},x=Tt(),f=At(e),{changeListeners:b,startListeners:y,endListeners:P,listenerArray:v,emitChange:C,emitInteraction:F}=x,k=vn(r,e,()=>t,()=>l,()=>c,f,C),z=_=>{if(!(!t.drag||l)&&i===null&&_.isPrimary!==!1){_.preventDefault(),i=_.pointerId,s={x:_.clientX,y:_.clientY},o.style.cursor="grabbing";try{_.target.setPointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),F("start",f)}},O=_=>{if(i===null||_.pointerId!==i||!t.drag||l)return;_.preventDefault();let j=_.clientX-s.x,Q=_.clientY-s.y;s={x:_.clientX,y:_.clientY};let re=e.camera.state;if(_.shiftKey){let fe=Xt(t.invert),ue=j/4*fe,pe=Q/4*fe,Ce=(re.rotX??65)-pe,be=(((re.rotY??45)-ue)%360+360)%360;e.camera.update({rotX:Ce,rotY:be})}else{let fe=re.rotX??65,ue=re.rotY??45,pe=Math.max(.01,re.zoom??1),Ce=Math.cos(fe*Math.PI/180),be=Ce>=0?Math.max(.1,Ce):Math.min(-.1,Ce),Ae=Math.cos(ue*Math.PI/180),ze=Math.sin(ue*Math.PI/180),Qe=pe*dc,rt=(j*ze-Q*Ae/be)/Qe,ut=-(j*Ae+Q*ze/be)/Qe,it=re.target??[0,0,0];e.camera.update({target:[it[0]+rt,it[1]+ut,it[2]]})}e.applyCamera(),C(f)},Z=_=>{if(i===_.pointerId){i=null,o.style.cursor=t.drag&&!l?"grab":"";try{_.target.releasePointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),F("end",f)}},q=_=>{_.preventDefault()},D=_=>{_.button===2&&(p=!0,g={x:_.clientX,y:_.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),F("start",f))},H=_=>{if(!p||!t.drag)return;let j=_.clientX-g.x,Q=_.clientY-g.y;g={x:_.clientX,y:_.clientY};let re=Xt(t.invert),fe=j/4*re,ue=Q/4*re,pe=e.camera.state,Ce=(pe.rotX??65)-ue,be=(((pe.rotY??45)-fe)%360+360)%360;e.camera.update({rotX:Ce,rotY:be}),e.applyCamera(),C(f)},V=_=>{_.button===2&&p&&(p=!1,F("end",f))},G=bn(e,()=>t,()=>l,f,C,F);function A(){o.addEventListener("pointerdown",z),o.addEventListener("pointermove",O),o.addEventListener("pointerup",Z),o.addEventListener("pointercancel",Z),o.addEventListener("wheel",G.onWheel,{passive:!1}),o.addEventListener("contextmenu",q),o.addEventListener("mousedown",D),o.addEventListener("mousemove",H),o.addEventListener("mouseup",V),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function h(){o.removeEventListener("pointerdown",z),o.removeEventListener("pointermove",O),o.removeEventListener("pointerup",Z),o.removeEventListener("pointercancel",Z),o.removeEventListener("wheel",G.onWheel),o.removeEventListener("contextmenu",q),o.removeEventListener("mousedown",D),o.removeEventListener("mousemove",H),o.removeEventListener("mouseup",V),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",G.teardown()}A(),k.start();function u(_){let j=!!t.animate;t=Et(t,_),!l&&i===null&&(o.style.cursor=t.drag?"grab":"");let Q=!!t.animate;j&&!Q?k.stop():!j&&Q&&k.start()}function d(){l&&(l=!1,A(),k.start())}function T(){l||(l=!0,h(),k.stop(),i=null,c=!1,p=!1,G.teardown())}function w(){T(),b.length=0,y.length=0,P.length=0}function R(_,j){let Q=v(_);Q.includes(j)||Q.push(j)}function L(_,j){let Q=v(_),re=Q.indexOf(j);re>=0&&Q.splice(re,1)}function te(_,j){return v(_).includes(j)}return{update:u,resume:d,pause:T,destroy:w,addEventListener:R,removeEventListener:L,hasEventListener:te}}var uc=typeof HTMLElement<"u"?HTMLElement:class{},pc=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],En=class extends uc{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...pc]}_readAnimate(){let t=ee(this.getAttribute("animate-speed")),o=Sn(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:Te(r)}:{}}}_readOptions(){let t={},o=Te(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Te(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let i=ee(this.getAttribute("min-distance"));i!==void 0&&(t.minDistance=i);let s=ee(this.getAttribute("max-distance"));s!==void 0&&(t.maxDistance=s);let c=Pn(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=ee(this.getAttribute("zoom-min")),p=ee(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),p!==void 0&&(t.maxZoom=p),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof we)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=Ci(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};import{BASE_TILE as mc}from"@layoutit/polycss-core";var fc={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 Ei(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 Ti=new Set(["KeyW","ArrowUp"]),Ai=new Set(["KeyS","ArrowDown"]),Mi=new Set(["KeyA","ArrowLeft"]),wi=new Set(["KeyD","ArrowRight"]),Li=new Set(["Space"]),Oo=new Set(["ControlLeft","ControlRight"]);function _i(e,n={}){let t=Ei(fc,n),o=e.host,r=e.cameraEl,i=o.ownerDocument??document,s=i.defaultView??globalThis,c=Tt(),l=At(e),{changeListeners:p,startListeners:g,endListeners:x,listenerArray:f,emitChange:b,emitInteraction:y}=c,P=new Set,v=!1,C=!1,F=0,k=0,z=!1,O=[0,0,t.groundZ+t.eyeHeight];function Z($,ie){let se=$*Math.PI/180,Me=ie*Math.PI/180;return[-Math.sin(se)*Math.cos(Me),-Math.sin(se)*Math.sin(Me),-Math.cos(se)]}function q(){let $=e.camera.perspectiveStyle,ie=$==="none"?0:parseFloat($);return(Number.isFinite(ie)&&ie>0?ie:2e3)/mc}function D(){let $=e.camera.state,ie=Z($.rotX??90,$.rotY??0),se=q();return[O[0]+ie[0]*se,O[1]+ie[1]*se,O[2]+ie[2]*se]}function H(){let $=D();e.camera.update({target:$}),e.applyCamera()}function V(){let $=e.camera.state.target??[0,0,0];O=[$[0],$[1],t.groundZ+t.eyeHeight],H()}let G=()=>{if(!(!t.enabled||!t.lookEnabled||C||v))try{o.requestPointerLock()}catch{}},A=()=>{let $=i.pointerLockElement===o;$!==v&&(v=$,v?(z=!0,y("start",l)):z&&(z=!1,y("end",l)))},h=$=>{if(!v||!t.enabled||!t.lookEnabled||C)return;let ie=$.movementX??0,se=$.movementY??0;if(ie===0&&se===0)return;let Me=e.camera.state,_t=t.lookSensitivity,Ne=t.invertY?-1:1,Ee=(((Me.rotY??0)-ie*_t)%360+360)%360,ve=(Me.rotX??90)-se*_t*Ne;ve<t.minPitch?ve=t.minPitch:ve>t.maxPitch&&(ve=t.maxPitch);let De=Z(ve,Ee),Oe=q(),Se=[O[0]+De[0]*Oe,O[1]+De[1]*Oe,O[2]+De[2]*Oe];e.camera.update({rotX:ve,rotY:Ee,target:Se}),e.applyCamera(),b(l)},u=$=>Ti.has($)||Ai.has($)||Mi.has($)||wi.has($)||Li.has($)||Oo.has($),d=$=>{if(!(!t.enabled||C)&&u($.code)&&!(!v&&!t.moveEnabled)){if(Li.has($.code)){if(!t.jumpEnabled)return;$.preventDefault(),!P.has($.code)&&F===0&&k===0&&(F=t.jumpVelocity),P.add($.code);return}Oo.has($.code)&&!t.crouchEnabled||!t.moveEnabled&&!Oo.has($.code)||($.preventDefault(),P.add($.code))}},T=$=>{u($.code)&&P.delete($.code)},w=()=>{P.clear()},R=null,L=0,te=.05,_=$=>{if(R===null||C)return;let ie=Math.min(te,L?($-L)/1e3:.0167);if(L=$,t.enabled){let se=!1,Me=e.camera.state;if(t.moveEnabled){let ve=0,De=0;for(let Oe of P)Ti.has(Oe)?ve+=1:Ai.has(Oe)?ve-=1:wi.has(Oe)?De+=1:Mi.has(Oe)&&(De-=1);if(ve!==0||De!==0){let Se=(Me.rotY??0)*Math.PI/180,Rt=-Math.cos(Se),Zn=-Math.sin(Se),Qn=-Math.sin(Se),qn=Math.cos(Se),qe=Math.hypot(ve,De)||1,Zt=t.moveSpeed*ie;O[0]+=(Rt*ve+Qn*De)/qe*Zt,O[1]+=(Zn*ve+qn*De)/qe*Zt,se=!0}}let Ne=t.crouchEnabled&&(P.has("ControlLeft")||P.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(F!==0||k>0)?(F-=t.gravity*ie,k+=F*ie,k<=0&&(k=0,F=0)):t.jumpEnabled||(k=0,F=0);let Ee=t.groundZ+Ne+k;if(Math.abs(O[2]-Ee)>1e-4&&(O[2]=Ee,se=!0),se){let ve=D();e.camera.update({target:ve}),e.applyCamera(),b(l)}}R=s.requestAnimationFrame(_)};function j(){R!==null||C||(L=0,R=s.requestAnimationFrame(_))}function Q(){R!==null&&(s.cancelAnimationFrame(R),R=null)}function re(){let ie=r.ownerDocument?.defaultView?.getComputedStyle(r).perspective??"",se=parseFloat(ie),Me=Number.isFinite(se)&&se>0?se:2e3;r.style.setProperty("--polycss-fpv-perspective",`${Me}px`),r.classList.add("polycss-fpv-host")}function fe(){r.classList.remove("polycss-fpv-host"),r.style.removeProperty("--polycss-fpv-perspective")}function ue(){o.addEventListener("click",G),i.addEventListener("pointerlockchange",A),i.addEventListener("mousemove",h),s.addEventListener("keydown",d),s.addEventListener("keyup",T),s.addEventListener("blur",w),o.style.cursor=t.lookEnabled?"crosshair":"",re()}function pe(){if(o.removeEventListener("click",G),i.removeEventListener("pointerlockchange",A),i.removeEventListener("mousemove",h),s.removeEventListener("keydown",d),s.removeEventListener("keyup",T),s.removeEventListener("blur",w),o.style.cursor="",P.clear(),v)try{i.exitPointerLock()}catch{}fe()}V(),ue(),j();function Ce($){let ie=t.eyeHeight,se=t.groundZ;t=Ei(t,$),C||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==ie||t.groundZ!==se)&&(O[2]=t.groundZ+t.eyeHeight,H(),b(l))}function be(){C&&(C=!1,ue(),j())}function Ae(){C||(C=!0,pe(),Q(),z&&(z=!1,y("end",l)))}function ze(){Ae(),p.length=0,g.length=0,x.length=0}function Qe(){if(!(!t.enabled||!t.lookEnabled||C))try{o.requestPointerLock()}catch{}}function rt(){if(v)try{i.exitPointerLock()}catch{}}function ut(){return v}function it($,ie){let se=f($);se.includes(ie)||se.push(ie)}function jn($,ie){let se=f($),Me=se.indexOf(ie);Me>=0&&se.splice(Me,1)}function Wn($,ie){return f($).includes(ie)}function Yn(){return[O[0],O[1],O[2]]}function Xn($){O[0]=$[0],O[1]=$[1],O[2]=$[2],H(),b(l)}return{update:Ce,resume:be,pause:Ae,destroy:ze,lock:Qe,unlock:rt,isLocked:ut,getOrigin:Yn,setOrigin:Xn,addEventListener:it,removeEventListener:jn,hasEventListener:Wn}}var hc=typeof HTMLElement<"u"?HTMLElement:class{},gc=["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"],Tn=class extends hc{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...gc]}_readOptions(){let t={},o=Te(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let r=Te(this.getAttribute("look-enabled"));r!==void 0&&(t.lookEnabled=r);let i=Te(this.getAttribute("move-enabled"));i!==void 0&&(t.moveEnabled=i);let s=Te(this.getAttribute("jump-enabled"));s!==void 0&&(t.jumpEnabled=s);let c=Te(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let l=ee(this.getAttribute("look-sensitivity"));if(l!==void 0&&(t.lookSensitivity=l),this.hasAttribute("invert-y")){let C=Te(this.getAttribute("invert-y"));C!==void 0&&(t.invertY=C)}let p=ee(this.getAttribute("move-speed"));p!==void 0&&(t.moveSpeed=p);let g=ee(this.getAttribute("jump-velocity"));g!==void 0&&(t.jumpVelocity=g);let x=ee(this.getAttribute("gravity"));x!==void 0&&(t.gravity=x);let f=ee(this.getAttribute("eye-height"));f!==void 0&&(t.eyeHeight=f);let b=ee(this.getAttribute("crouch-height"));b!==void 0&&(t.crouchHeight=b);let y=ee(this.getAttribute("ground-z"));y!==void 0&&(t.groundZ=y);let P=ee(this.getAttribute("min-pitch"));P!==void 0&&(t.minPitch=P);let v=ee(this.getAttribute("max-pitch"));return v!==void 0&&(t.maxPitch=v),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof we)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=_i(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 yc=typeof HTMLElement<"u"?HTMLElement:class{},bc=["perspective","zoom","rot-x","rot-y","target","distance"],An=class extends yc{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...bc]}getCamera(){return this._camera}_readOptions(){return{perspective:ee(this.getAttribute("perspective")),zoom:ee(this.getAttribute("zoom")),rotX:ee(this.getAttribute("rot-x")),rotY:ee(this.getAttribute("rot-y")),target:xn(this.getAttribute("target")),distance:ee(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Ut(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 i=this._readOptions();if(t==="perspective"){this._camera=Ut(i),this._wrapper.style.perspective=this._camera.perspectiveStyle;return}this._camera.update({rotX:i.rotX,rotY:i.rotY,zoom:i.zoom,target:i.target,distance:i.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var vc=typeof HTMLElement<"u"?HTMLElement:class{},xc=["zoom","rot-x","rot-y","target","distance"],Mt=class extends vc{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...xc]}getCamera(){return this._camera}_readOptions(){return{zoom:ee(this.getAttribute("zoom")),rotX:ee(this.getAttribute("rot-x")),rotY:ee(this.getAttribute("rot-y")),target:xn(this.getAttribute("target")),distance:ee(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=jt(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 i=this._readOptions();i.zoom!==void 0&&this._camera.update({zoom:i.zoom}),i.rotX!==void 0&&this._camera.update({rotX:i.rotX}),i.rotY!==void 0&&this._camera.update({rotY:i.rotY}),i.target!==void 0&&this._camera.update({target:i.target}),i.distance!==void 0&&this._camera.update({distance:i.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var Mn=class extends Mt{};import{arrowPolygons as Pc,eulerXYZFromQuat as Sc,planePolygons as Cc,quatFromAxisAngle as Ec,quatFromEulerXYZ as Tc,quatMultiply as Ac,ringQuadPolygons as Mc,rotateVec3 as Ho}from"@layoutit/polycss-core";function wt(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let i=r.getBoundingClientRect();if(!(i.width<=0||i.height<=0)&&n>=i.left&&n<=i.right&&t>=i.top&&t<=i.bottom)return!0}return!1}function Ri(e,n,t,o){for(let r of e)if(!(o&&!o(r))&&wt(r.element,n,t))return r;return null}var wn="#ff3653",Ln="#8adb00",_n="#2c8fff",Lt=50,ki=60,wc=.6,Lc=.0125,_c=.15,Rc=.04,kc=1,Di=.02,Io=1.04,Dc=.1,Oc=.25,Fi=1e-4,Hc=.6,Ic=.8,Fc=1,Je={0:1,1:0,2:2},Oi=[{cssAxis:0,sign:1,key:"x",color:wn},{cssAxis:0,sign:-1,key:"-x",color:wn},{cssAxis:1,sign:1,key:"y",color:Ln},{cssAxis:1,sign:-1,key:"-y",color:Ln},{cssAxis:2,sign:1,key:"z",color:_n},{cssAxis:2,sign:-1,key:"-z",color:_n}],Hi=[{cssAxis:0,key:"x",color:wn},{cssAxis:1,key:"y",color:Ln},{cssAxis:2,key:"z",color:_n}],Ii=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:_n},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:Ln},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:wn}];function Fo(e,n,t,o){let r=t*Math.PI/180,i=o*Math.PI/180,s=[0,0,0];s[e]=n;let c=s[0]*Math.cos(i)-s[1]*Math.sin(i),l=s[0]*Math.sin(i)+s[1]*Math.cos(i),p=s[2];return l*Math.sin(r)+p*Math.cos(r)<0}function Vc(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),i=parseInt(t[3],16);return`rgba(${o}, ${r}, ${i}, ${n})`}function Rn(e,n){return!n||n<=0?e:Math.round(e/n)*n}function Bc(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-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]>i&&(i=l[1]),l[2]<o&&(o=l[2]),l[2]>s&&(s=l[2]);return Number.isFinite(n)?[(n+r)/2,(t+i)/2,(o+s)/2]:[0,0,0]}function Vo(e){if(e.length===0)return ki;let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let l of e)for(let p of l.vertices)p[0]<n&&(n=p[0]),p[0]>r&&(r=p[0]),p[1]<t&&(t=p[1]),p[1]>i&&(i=p[1]),p[2]<o&&(o=p[2]),p[2]>s&&(s=p[2]);return Number.isFinite(n)?Math.max(r-n,i-t,s-o)*Lt*wc:ki}function zc(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:i,startClientX:s,startClientY:c,translationSnap:l,onAxisDelta:p,onMouseDown:g,onMouseUp:x,onDraggingChanged:f}=e,b=o,y=[0,0,0];y[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(${y[0]*b}px, ${y[1]*b}px, ${y[2]*b}px)`,r.appendChild(P);let v=r.getBoundingClientRect(),C=P.getBoundingClientRect();r.removeChild(P);let F=(C.left-v.left)/b,k=(C.top-v.top)/b,z=F*F+k*k;if(z<Fi)return;g?.(),f?.(!0);let O=q=>{let D=q.clientX-s,H=q.clientY-c,V=(D*F+H*k)/z;V=Rn(V,l),p(V,y)},Z=()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",Z),window.removeEventListener("pointercancel",Z);let q=D=>{D.stopPropagation(),D.stopImmediatePropagation()};window.addEventListener("click",q,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",q,!0),0),x?.(),f?.(!1)};window.addEventListener("pointermove",O),window.addEventListener("pointerup",Z),window.addEventListener("pointercancel",Z)}function Nc(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:i,startClientY:s,translationSnap:c,onPlaneDelta:l,onMouseDown:p,onMouseUp:g,onDraggingChanged:x}=e,f=[0,0,0];f[n]=1;let b=[0,0,0];b[t]=1;function y(z){let O=r.ownerDocument.createElement("div");O.style.position="absolute",O.style.left="0",O.style.top="0",O.style.width="0",O.style.height="0",O.style.transform=`translate3d(${z[0]*o}px, ${z[1]*o}px, ${z[2]*o}px)`,r.appendChild(O);let Z=r.getBoundingClientRect(),q=O.getBoundingClientRect();return r.removeChild(O),{x:(q.left-Z.left)/o,y:(q.top-Z.top)/o}}let P=y(f),v=y(b),C=P.x*v.y-v.x*P.y;if(Math.abs(C)<Fi)return;p?.(),x?.(!0);let F=z=>{let O=z.clientX-i,Z=z.clientY-s,q=(v.y*O-v.x*Z)/C,D=(-P.y*O+P.x*Z)/C;q=Rn(q,c),D=Rn(D,c),l(q,D,f,b)},k=()=>{window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k);let z=O=>{O.stopPropagation(),O.stopImmediatePropagation()};window.addEventListener("click",z,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",z,!0),0),g?.(),x?.(!1)};window.addEventListener("pointermove",F),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)}function Gc(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:i,rotationSnap:s,onAngleDelta:c,onMouseDown:l,onMouseUp:p,onDraggingChanged:g}=e,x=t.getBoundingClientRect(),f=x.left,b=x.top,y=Math.atan2(i-b,r-f),P=0;l?.(),g?.(!0);let v=F=>{let k=Math.atan2(F.clientY-b,F.clientX-f),z=k-y;z>Math.PI?z-=2*Math.PI:z<-Math.PI&&(z+=2*Math.PI),P+=z,y=k;let O=P*180/Math.PI;O=Rn(O,s),c(O)},C=()=>{window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",C),window.removeEventListener("pointercancel",C);let F=k=>{k.stopPropagation(),k.stopImmediatePropagation()};window.addEventListener("click",F,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",F,!0),0),p?.(),g?.(!1)};window.addEventListener("pointermove",v),window.addEventListener("pointerup",C),window.addEventListener("pointercancel",C)}function Vi(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,i={...n},s=new Map,c=null,l=null,p=[0,0,0];function g(){if(!t)return[0,0,0];let h=t.transform.position??[0,0,0],u=t.transform.rotation??[0,0,0],d=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,T=Ho(p,u[0],u[1],u[2]);return[h[0]+d*T[0],h[1]+d*T[1],h[2]+d*T[2]]}function x(h){return l===h?Fc:c===h?Ic:Hc}function f(){for(let[h,u]of s){let d=b(u.spec,x(h));u.handle.setPolygons(d,{recomputeAutoCenter:!1})}}function b(h,u){let T=Vo(t?.polygons??[])*r,w=T/Lt,R=Vc(h.color,u);if(h.kind==="arrow"){let _=e.camera.state,j=Fo(h.cssAxis,h.sign,_.rotX??65,_.rotY??45);return Pc({axis:Je[h.cssAxis],sign:h.sign,shaftLength:w,shaftHalfThickness:w*Lc,headLength:w*_c,headHalfThickness:w*Rc,color:R,shaft:!j})}if(h.kind==="plane"){let _=e.camera.state,j=_.rotX??65,Q=_.rotY??45,re=Je[h.perpAxis],fe=(re+1)%3,ue=(re+2)%3,pe=Je[fe],Ce=Je[ue],be=Fo(pe,1,j,Q)?-1:1,Ae=Fo(Ce,1,j,Q)?-1:1,ze=w*Oc;return Cc({axis:re,size:w*Dc,offset:[be*ze,Ae*ze],color:R})}let te=T*kc/Lt*Io;return Mc({axis:Je[h.cssAxis],outerRadius:te,color:R})}function y(h){return h.kind==="arrow"?"polycss-transform-arrow":h.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function P(){if(o==="translate"){let h=Oi.map(d=>({kind:"arrow",key:d.key,cssAxis:d.cssAxis,sign:d.sign,color:d.color})),u=Ii.map(d=>({kind:"plane",key:d.key,perpAxis:d.perpAxis,axisA:d.axisA,axisB:d.axisB,color:d.color}));return[...h,...u]}return o==="rotate"?Hi.map(h=>({kind:"ring",key:h.key,cssAxis:h.cssAxis,color:h.color})):[]}function v(){if(C(),!t)return;let h={x:i.showX!==!1,y:i.showY!==!1,z:i.showZ!==!1};function u(T){if(T.kind==="arrow"){let L=T.key.replace("-","")[0];return h[L]}if(T.kind==="ring")return h[T.key];let w=["x","y","z"][T.axisA],R=["x","y","z"][T.axisB];return h[w]&&h[R]}let d=g();for(let T of P()){if(!u(T))continue;let w=b(T,x(T.key)),R=e.add({polygons:w,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${T.key}`,position:d}),L=y(T);if(R.element.classList.add("polycss-transform-gizmo",L,`${L}--${T.key}`),T.kind==="ring"){let te=(1-Di)/Io,_=(1+Di)/Io;R.element.style.setProperty("--ring-inner-ratio",`${te}`),R.element.style.setProperty("--ring-outer-ratio",`${_}`)}s.set(T.key,{handle:R,spec:T})}}function C(){for(let{handle:h}of s.values())h.remove();s.clear(),c=null,l=null}function F(){if(!t)return;let h=g();for(let{handle:u}of s.values())u.setTransform({position:h})}function k(){t&&(s.size===0?v():F())}function z(h){if(t=h,!h){p=[0,0,0],C();return}p=Bc(h.polygons),C(),v()}function O(){z(null)}function Z(h){h!==o&&(o=h,t&&(C(),v()))}function q(h,u,d){if(!t||!D)return;let T=d[h.cssAxis],w=Je[h.cssAxis],R=u*T/Lt,L=D.slice();L[w]=D[w]+R,t.setTransform({position:L}),F(),i.onObjectChange?.({object:t,position:L}),i.onChange?.()}let D=null,H=null,V=h=>{if(!t||i.enabled===!1)return;let u={x:i.showX!==!1,y:i.showY!==!1,z:i.showZ!==!1};if(o==="translate"){for(let d of Ii){let T=["x","y","z"][d.axisA],w=["x","y","z"][d.axisB];if(!u[T]||!u[w])continue;let R=s.get(d.key);if(R&&wt(R.handle.element,h.clientX,h.clientY)){h.preventDefault(),h.stopPropagation(),l=d.key,f(),D=(t.transform.position??[0,0,0]).slice(),Nc({axisA:d.axisA,axisB:d.axisB,probeDistanceCss:Vo(t.polygons)*r,wrapper:R.handle.element,target:t,startClientX:h.clientX,startClientY:h.clientY,translationSnap:i.translationSnap??null,onPlaneDelta:(L,te,_,j)=>{if(!t||!D)return;let Q=_[d.axisA],re=j[d.axisB],fe=Je[d.axisA],ue=Je[d.axisB],pe=D.slice();pe[fe]+=L*Q/Lt,pe[ue]+=te*re/Lt,t.setTransform({position:pe}),F(),i.onObjectChange?.({object:t,position:pe}),i.onChange?.()},onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:L=>{L||(l=null,D=null,f()),i.onDraggingChanged?.(L)}});return}}for(let d of Oi){let T=d.key.replace("-","")[0];if(!u[T])continue;let w=s.get(d.key);if(w&&wt(w.handle.element,h.clientX,h.clientY)){h.preventDefault(),h.stopPropagation(),l=d.key,f(),D=(t.transform.position??[0,0,0]).slice(),zc({cssAxis:d.cssAxis,sign:d.sign,shaftLengthCss:Vo(t.polygons)*r,wrapper:w.handle.element,target:t,startClientX:h.clientX,startClientY:h.clientY,translationSnap:i.translationSnap??null,onAxisDelta:(R,L)=>q(d,R,L),onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:R=>{R||(l=null,D=null,f()),i.onDraggingChanged?.(R)}});return}}}else if(o==="rotate")for(let d of Hi){if(!u[d.key])continue;let T=s.get(d.key);if(T&&wt(T.handle.element,h.clientX,h.clientY)){h.preventDefault(),h.stopPropagation(),l=d.key,f(),H=(t.transform.rotation??[0,0,0]).slice(),D=(t.transform.position??[0,0,0]).slice(),Gc({cssAxis:d.cssAxis,wrapper:T.handle.element,target:t,startClientX:h.clientX,startClientY:h.clientY,rotationSnap:i.rotationSnap??null,onAngleDelta:w=>{if(!t||!H||!D)return;let R=Je[d.cssAxis],L=[0,0,0];L[R]=1;let te=-w*Math.PI/180,_=Tc(H),j=Ec(L,te),Q=Sc(Ac(j,_)),re=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,fe=Ho(p,H[0],H[1],H[2]),ue=Ho(p,Q[0],Q[1],Q[2]),pe=[D[0]+re*(fe[0]-ue[0]),D[1]+re*(fe[1]-ue[1]),D[2]+re*(fe[2]-ue[2])];t.setTransform({rotation:Q,position:pe}),F(),i.onObjectChange?.({object:t,rotation:Q,position:pe}),i.onChange?.()},onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:w=>{w||(l=null,H=null,D=null,f(),t?.rebakeAtlas()),i.onDraggingChanged?.(w)}});return}}};e.host.addEventListener("pointerdown",V,{capture:!0});let G=h=>{if(!t||l||i.enabled===!1)return;let u=null;for(let[d,T]of s)if(wt(T.handle.element,h.clientX,h.clientY)){u=d;break}u!==c&&(c=u,f())};e.host.addEventListener("pointermove",G);function A(){e.host.removeEventListener("pointerdown",V,{capture:!0}),e.host.removeEventListener("pointermove",G),C()}return{attach:z,detach:O,setMode:Z,update:k,destroy:A}}var $c=typeof HTMLElement<"u"?HTMLElement:class{},Uc=["mode","target","size","enabled"];function Bi(e){if(e==="translate"||e==="rotate")return e}var kn=class extends $c{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Uc]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof we)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 Ct?r:null}_readOptions(){let t={},o=Bi(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=ee(this.getAttribute("size"));r!==void 0&&(t.size=r);let i=this.getAttribute("enabled");return i!==null&&(t.enabled=i!=="false"&&i!=="0"),t.onObjectChange=s=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:s.position,rotation:s.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let i=()=>{t.removeEventListener("polycss:scene-ready",i),this._attach()};t.addEventListener("polycss:scene-ready",i)}return}this._tc=Vi(o,this._readOptions());let r=this._findTargetMesh();if(r){let i=r.getMeshHandle();i&&this._tc.attach(i)}}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 i=Bi(r);i&&this._tc.setMode(i)}else if(t==="target"){let i=this._findTargetMesh();this._tc.attach(i?i.getMeshHandle()??null:null)}}}};function zi(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(v){console.error("[polycss/createSelect] onChange threw:",v)}}function i(y){t=y,r()}function s(y){n.multiple?t.includes(y)||(t=[...t,y]):t=[y],r()}function c(y){t.includes(y)&&(t=t.filter(P=>P!==y),r())}function l(y){t.includes(y)?t=t.filter(P=>P!==y):n.multiple?t=[...t,y]:t=[y],r()}function p(){t.length!==0&&(t=[],r())}function g(y){return t.includes(y)}function x(y,P){return Ri(e.meshes(),y,P,v=>!v.element.classList.contains("polycss-transform-gizmo"))}let f=y=>{let P=y.target;if(P?.closest(".polycss-transform-gizmo"))return;let v=e.findMeshByElement(P)??x(y.clientX,y.clientY);if(!v){n.onPointerMissed&&n.onPointerMissed(y),n.clearOnMiss!==!1&&p();return}n.multiple&&(y.shiftKey||y.metaKey||y.ctrlKey)?l(v):t.length===1&&t[0]===v?p():i([v])};e.host.addEventListener("click",f);function b(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:i,add:s,remove:c,toggle:l,clear:p,has:g,destroy:b}}var jc=typeof HTMLElement<"u"?HTMLElement:class{},Wc=["multiple","clear-on-miss"],Dn=class extends jc{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Wc]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof we)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=zi(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())}};import{boxPolygons as Yc,planePolygons as Xc,ringPolygons as Zc,octahedronPolygons as Qc,spherePolygons as qc,tetrahedronPolygons as Kc,icosahedronPolygons as Jc,dodecahedronPolygons as ed,cylinderPolygons as td,conePolygons as nd,torusPolygons as od,computeSceneBbox as rd}from"@layoutit/polycss-core";var id=typeof HTMLElement<"u"?HTMLElement:class{};function sd(e){return e.closest("poly-scene")??null}function he(e,n,t){let o=e.getAttribute(n);if(!o)return t;let r=parseFloat(o);return Number.isFinite(r)?r:t}function Ze(e,n,t){return e.getAttribute(n)??t}function dt(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 ad(e){if(e.length===0)return e;let n=rd(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 i=s=>[s[0]-t,s[1]-o,s[2]-r];return e.map(s=>({...s,vertices:s.vertices.map(i)}))}var ke=class extends id{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:dt(this,"position"),scale:(()=>{let i=this.getAttribute("scale");if(!i)return;if(i.includes(","))return dt(this,"scale");let s=parseFloat(i);return Number.isFinite(s)?s:void 0})(),rotation:dt(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=sd(this);if(!t)return;let o=t.getScene?.();if(!o)return;let r=this.buildPolygons();this.hasAttribute("auto-center")&&(r=ad(r));let i={polygons:r,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(i,{position:dt(this,"position"),scale:(()=>{let s=this.getAttribute("scale");if(!s)return;if(s.includes(","))return dt(this,"scale");let c=parseFloat(s);return Number.isFinite(c)?c:void 0})(),rotation:dt(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow"),excludeFromAutoCenter:this.hasAttribute("exclude-from-auto-center"),merge:!1})}},On=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("size"),t=n?parseFloat(n):void 0;return Yc({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:Ze(this,"color")})}},Hn=class extends ke{static get observedAttributes(){return["axis","size","offset","color","auto-center","position","scale","rotation","cast-shadow","receive-shadow"]}buildPolygons(){let n=he(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("offset"),r=o===null?0:parseFloat(o);return Xc({axis:t,size:he(this,"size",.4),offset:Number.isFinite(r)?r:0,color:Ze(this,"color")})}},In=class extends ke{static get observedAttributes(){return["axis","radius","segments","half-thickness","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=he(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("half-thickness");return Zc({axis:t,radius:he(this,"radius",50),segments:he(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:Ze(this,"color")})}},Fn=class extends ke{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return Qc({center:dt(this,"center")??[0,0,0],size:he(this,"size",50),color:Ze(this,"color")})}},Vn=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return Kc({size:he(this,"size",100),color:Ze(this,"color")})}},Bn=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return Jc({size:he(this,"size",100),color:Ze(this,"color")})}},zn=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return ed({size:he(this,"size",100),color:Ze(this,"color")})}},Nn=class extends ke{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return qc({radius:he(this,"radius",50),subdivisions:he(this,"subdivisions",1),color:Ze(this,"color")})}},Gn=class extends ke{static get observedAttributes(){return["radius","radius-top","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("radius-top");return td({radius:he(this,"radius",50),radiusTop:n?parseFloat(n):void 0,height:he(this,"height",100),radialSegments:he(this,"radial-segments",12),color:Ze(this,"color")})}},$n=class extends ke{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return nd({radius:he(this,"radius",50),height:he(this,"height",100),radialSegments:he(this,"radial-segments",12),color:Ze(this,"color")})}},Un=class extends ke{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return od({radius:he(this,"radius",50),tube:he(this,"tube",15),radialSegments:he(this,"radial-segments",12),tubularSegments:he(this,"tubular-segments",16),color:Ze(this,"color")})}};typeof customElements<"u"&&(customElements.get("poly-scene")||customElements.define("poly-scene",we),customElements.get("poly-mesh")||customElements.define("poly-mesh",Ct),customElements.get("poly-iframe")||customElements.define("poly-iframe",mn),customElements.get("poly-polygon")||customElements.define("poly-polygon",fn),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",hn),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",gn),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",Cn),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",En),customElements.get("poly-first-person-controls")||customElements.define("poly-first-person-controls",Tn),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",An),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",Mt),customElements.get("poly-camera")||customElements.define("poly-camera",Mn),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",kn),customElements.get("poly-select")||customElements.define("poly-select",Dn),customElements.get("poly-box")||customElements.define("poly-box",On),customElements.get("poly-plane")||customElements.define("poly-plane",Hn),customElements.get("poly-ring")||customElements.define("poly-ring",In),customElements.get("poly-octahedron")||customElements.define("poly-octahedron",Fn),customElements.get("poly-tetrahedron")||customElements.define("poly-tetrahedron",Vn),customElements.get("poly-sphere")||customElements.define("poly-sphere",Nn),customElements.get("poly-icosahedron")||customElements.define("poly-icosahedron",Bn),customElements.get("poly-dodecahedron")||customElements.define("poly-dodecahedron",zn),customElements.get("poly-cylinder")||customElements.define("poly-cylinder",Gn),customElements.get("poly-cone")||customElements.define("poly-cone",$n),customElements.get("poly-torus")||customElements.define("poly-torus",Un));export{hn as PolyAxesHelperElement,On as PolyBoxElement,Mn as PolyCameraElement,$n as PolyConeElement,Gn as PolyCylinderElement,gn as PolyDirectionalLightHelperElement,zn as PolyDodecahedronElement,Tn as PolyFirstPersonControlsElement,Bn as PolyIcosahedronElement,mn as PolyIframeElement,En as PolyMapControlsElement,Ct as PolyMeshElement,Fn as PolyOctahedronElement,Cn as PolyOrbitControlsElement,Mt as PolyOrthographicCameraElement,An as PolyPerspectiveCameraElement,Hn as PolyPlaneElement,fn as PolyPolygonElement,In as PolyRingElement,we as PolySceneElement,Dn as PolySelectElement,Nn as PolySphereElement,Vn as PolyTetrahedronElement,Un as PolyTorusElement,kn as PolyTransformControlsElement};
|