@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.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Rt=Object.defineProperty;var Do=Object.getOwnPropertyDescriptor;var Oo=Object.getOwnPropertyNames;var Io=Object.prototype.hasOwnProperty;var Ho=(e,n)=>{for(var t in n)Rt(e,t,{get:n[t],enumerable:!0})},Vo=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Oo(n))!Io.call(e,r)&&r!==t&&Rt(e,r,{get:()=>n[r],enumerable:!(o=Do(n,r))||o.enumerable});return e};var zo=e=>Vo(Rt({},"__esModule",{value:!0}),e);var Li={};Ho(Li,{PolyAxesHelperElement:()=>je,PolyDirectionalLightHelperElement:()=>Ze,PolyMapControlsElement:()=>Ke,PolyMeshElement:()=>Oe,PolyOrbitControlsElement:()=>Qe,PolyOrthographicCameraElement:()=>et,PolyPerspectiveCameraElement:()=>Je,PolyPolygonElement:()=>We,PolySceneElement:()=>xe,PolySelectElement:()=>ot,PolyTransformControlsElement:()=>nt});module.exports=zo(Li);var ee=require("@layoutit/polycss-core");var zt=require("@layoutit/polycss-core"),Ft=50,Bt=[.4,-.7,.59],Nt="#ffffff",$t=1,Xt="#ffffff",Yt=.4,Ve=4096,mn=1,Fo=.1,Bo=1,Sn=Ve*Ve,No=Sn*3,Ot=2048,$o=4*1024*1024,Xo=16*1024*1024,Yo=.995,Uo=12,Ie=new Map,It=new WeakMap,oe=.001,ce=1e-9,Go=1e-4,Wo=.1,pn=.01,jo=.75,Zo=1,qo=250,fn=1.5,Qo=.75,Ko=3,Jo=2,er=4,Ht=64,Le=64,Ee=64,tr=128,hn=50,gn=1e-7,yn=16,kt=.9,nr=.05,or=Number.POSITIVE_INFINITY,rr=.6;function sr(e){let n=Ie.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),Ie.set(e,n),n.then(()=>{Ie.get(e)===n&&Ie.delete(e)},()=>{Ie.get(e)===n&&Ie.delete(e)})),n}function ct(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Bo,Math.max(Fo,n))}function Ut(e,n){let t=e.toFixed(n).replace(/\.?0+$/,"");return Object.is(Number(t),-0)?"0":t}function ze(e,n=er){let t=Ut(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function Ce(e,n=Ko){return e.map(t=>Ut(t,n)).join(",")}function wn(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=ce)return!1;let l=Math.sign(i);if(n===0)n=l;else if(l!==n)return!1}return!0}function ir(e){let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-o[1]*r[0]}return n/2}function ar(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],l=o[1]-t[1],a=r*l-s*i;if(Math.abs(a)<=ce)return null;let u=t[0]-e[0],m=t[1]-e[1],d=(u*l-m*i)/a;return[e[0]+d*r,e[1]+d*s]}function Gt(e,n){if(e.length<6||e.length%2!==0||n<=0)return e;let t=[];for(let a=0;a<e.length;a+=2)t.push([e[a],e[a+1]]);if(!wn(t))return Xe(e,n);let o=ir(t);if(Math.abs(o)<=ce)return Xe(e,n);let r=o>0?1:-1,s=[];for(let a=0;a<t.length;a++){let u=t[a],m=t[(a+1)%t.length],d=m[0]-u[0],f=m[1]-u[1],g=Math.hypot(d,f);if(g<=ce)return Xe(e,n);let p=r*(f/g)*n,h=r*(-d/g)*n;s.push({a:[u[0]+p,u[1]+h],b:[m[0]+p,m[1]+h]})}let i=[],l=Math.max(2,n*4);for(let a=0;a<t.length;a++){let u=s[(a+t.length-1)%t.length],m=s[a],d=ar(u.a,u.b,m.a,m.b);if(!d)return Xe(e,n);let f=t[a],g=d[0]-f[0],p=d[1]-f[1],h=Math.hypot(g,p);h>l?i.push(f[0]+g/h*l,f[1]+p/h*l):i.push(d[0],d[1])}return i}function bn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function Wt(e){let t=e?.defaultView?.__polycssProjectiveQuadGuards,o=t?.maxWeightRatio,r=Math.max(0,bn(t?.denomEps,nr)),s=typeof o=="number"&&Number.isFinite(o)&&o>0?Math.max(1,o):or,i=Math.max(0,bn(t?.bleed,rr));return{denomEps:r,maxWeightRatio:s,bleed:i,disableGuards:t?.disableGuards===!0}}function xn(e,n){if(e.length!==4||!wn(e))return null;let[t,o,r,s]=e,i=t[0]-o[0]+r[0]-s[0],l=t[1]-o[1]+r[1]-s[1],a=o[0]-r[0],u=s[0]-r[0],m=o[1]-r[1],d=s[1]-r[1],f=a*d-m*u;if(Math.abs(f)<=ce)return null;let g=(i*d-l*u)/f,p=(a*l-m*i)/f,h=[1,1+g,1+g+p,1+p];if(h.some(A=>!Number.isFinite(A)))return null;let b=Math.min(...h),x=Math.max(...h);return!n.disableGuards&&(b<=n.denomEps||x/b>n.maxWeightRatio)?null:{g,h:p,w1:1+g,w3:1+p}}function lr(e,n,t,o,r,s,i,l){if(e.length!==8)return null;let a=[[e[0],e[1]],[e[2],e[3]],[e[4],e[5]],[e[6],e[7]]];if(!xn(a,l))return null;let u=Gt(e,l.bleed),m=[[u[0],u[1]],[u[2],u[3]],[u[4],u[5]],[u[6],u[7]]],d=xn(m,l);if(!d)return null;let{g:f,h:g,w1:p,w3:h}=d,[b,x,,A]=m,M=[r+b[0]*n[0]+b[1]*t[0],s+b[0]*n[1]+b[1]*t[1],i+b[0]*n[2]+b[1]*t[2]],P=([k,C],v)=>[(v-1)*r+(v*k-b[0])*n[0]+(v*C-b[1])*t[0],(v-1)*s+(v*k-b[0])*n[1]+(v*C-b[1])*t[1],(v-1)*i+(v*k-b[0])*n[2]+(v*C-b[1])*t[2]],E=[...P(x,p),f,...P(A,h),g,o[0],o[1],o[2],0,M[0],M[1],M[2],1];for(let k=0;k<8;k+=1)E[k]/=Ht;return Ce(E,6)}function st(e,n=Jo){let t=Ut(e,n);return Number(t)===0?"0":`${t}%`}function cr(e,n,t,o,r,s){let i=(e-t)*(s-o)-(n-o)*(r-t);return Math.abs(i)>gn?!1:(e-t)*(e-r)+(n-o)*(n-s)<=gn}function ur(e,n=hn,t=hn){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,l]=e[r],[a,u]=e[s];if(cr(n,t,i,l,a,u))return!0;l>t!=u>t&&n<(a-i)*(t-l)/(u-l)+i&&(o=!o)}return o}function Tn(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function dr(e,n){let t=Tn(e);if(t<=0)return 1;let o=Math.max(1,...e.map(i=>Math.max(i.width,i.height))),r=Ot/o,s=Math.sqrt(n/(t*4));return ct(Math.min(r,s))}function mr(e,n){let t=Tn(e),o=.5;return t<=Sn?o=1:t<=No&&(o=.75),ct(Math.min(o,dr(e,n)))}function pr(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function fr(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function hr(e,n,t){let o=pr(e,n),r=fr(e,n),s=o>Ot?Ot/o:1,i=r>t?Math.sqrt(t/r):1;return Math.min(s,i)}function gr(e,n,t){let o=mr(n.pages,t),r=o===1?n:at(e,o);for(let s=0;s<4;s++){let i=hr(r.pages,o,t);if(i>=1)break;let l=ct(o*i*Yo);if(l>=o)break;o=l,r=at(e,o)}return{packed:r,atlasScale:o}}function yr(e){return Ln(e)?$o:Xo}function Ln(e){if(!e)return!1;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return t?t("(pointer: coarse)").matches||t("(hover: none)").matches:!1}function br(e,n){return e!==void 0&&e!=="auto"||Ln(n)?Ee:tr}function xr(e,n){let t=e.matrix.split(",").map(o=>Number(o));return t.length!==16||t.some(o=>!Number.isFinite(o))?e.canonicalMatrix:(t[0]*=e.canvasW/n,t[1]*=e.canvasW/n,t[2]*=e.canvasW/n,t[4]*=e.canvasH/n,t[5]*=e.canvasH/n,t[6]*=e.canvasH/n,Ce(t))}function vn(e,n){for(let t of e.entries)t&&(t.atlasCanonicalSize=n,t.atlasMatrix=xr(t,n));return e}function Me(e){return e.atlasCanonicalSize??Ee}function _n(e,n,t){let o=br(n,t);if(n!==void 0&&n!=="auto"){let i=ct(n);return{packed:vn(at(e,i),o),atlasScale:i,atlasCanonicalSize:o}}let r=at(e,1),s=gr(e,r,yr(t));return{packed:vn(s.packed,o),atlasScale:s.atlasScale,atlasCanonicalSize:o}}function vr(e){return Math.max(mn,Math.ceil(mn/e))}function Pe(e,n,t=1,o=0,r=0,s=1,i=0,l=0){e.setTransform(t*n,o*n,r*n,s*n,i*n,l*n)}function Se(e){let n=(0,zt.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function jt({r:e,g:n,b:t}){return`${e},${n},${t}`}function Pr(e){return(0,zt.parsePureColor)(e)?.alpha??1}function Er({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function J(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,s=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`(^|;)\\s*${s}\\s*:[^;]*`,"i"),l=i.test(o)?o.replace(i,(a,u)=>`${u}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;l!==o&&e.setAttribute("style",l)}function pe(e,n){let t=e.getAttribute("style")??"";if(!t)return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`^\\s*${o}\\s*:`,"i"),s=t.split(";").map(i=>i.trim()).filter(i=>i&&!r.test(i)).join(";");s?e.setAttribute("style",s):e.removeAttribute("style")}function Rn(e,n,t,o,r){let s=Se(e),i=Se(t),l=Se(o),a=l.r/255*r+i.r/255*n,u=l.g/255*r+i.g/255*n,m=l.b/255*r+i.b/255*n,d=Math.max(0,Math.min(255,Math.round(s.r*a))),f=Math.max(0,Math.min(255,Math.round(s.g*u))),g=Math.max(0,Math.min(255,Math.round(s.b*m))),p=Pr(e);return p<1?`rgba(${d}, ${f}, ${g}, ${p})`:Er({r:d,g:f,b:g})}function kn(e,n,t,o){let r=Se(n),s=Se(t);return{r:s.r/255*o+r.r/255*e,g:s.g/255*o+r.g/255*e,b:s.b/255*o+r.b/255*e}}function Ar({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(1,r))*255);return`rgb(${o(e)} ${o(n)} ${o(t)})`}function Mr(e,n,t,o,r,s,i){Math.abs(s.r-1)<.001&&Math.abs(s.g-1)<.001&&Math.abs(s.b-1)<.001||(e.save(),Pe(e,i),e.globalCompositeOperation="multiply",e.fillStyle=Ar(s),e.fillRect(n,t,o,r),e.restore())}function Cr(e,n,t,o,r,s,i){let l=n.naturalWidth||n.width||1,a=n.naturalHeight||n.height||1,u=Math.max(r/l,s/a),m=l*u,d=a*u;Pe(e,i),e.drawImage(n,t+(r-m)/2,o+(s-d)/2,m,d)}function it(e){return`${e[0]},${e[1]},${e[2]}`}function Sr(e,n){let t=it(e),o=it(n);return t<o?`${t}|${o}`:`${o}|${t}`}function Dn(e,n){return it(e)<it(n)?[n[0]-e[0],n[1]-e[1],n[2]-e[2]]:[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function wr(e){return!e.texture}function Ue(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function ut(e){if(e.length<3)return null;let n=e[0],t=0,o=0,r=0;for(let i=1;i+1<e.length;i++){let l=e[i],a=e[i+1],u=[l[0]-n[0],l[1]-n[1],l[2]-n[2]],m=[a[0]-n[0],a[1]-n[1],a[2]-n[2]];t-=u[1]*m[2]-u[2]*m[1],o-=u[2]*m[0]-u[0]*m[2],r-=u[0]*m[1]-u[1]*m[0]}let s=Math.hypot(t,o,r);return s<=ce?null:(t/=s,o/=s,r/=s,[t,o,r])}function Fe(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function Tr(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Lr(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=Ue(e.vertices,n,t),r=ut(o);return r?{pts:o,normal:r,planeD:Fe(r,o[0]),optimizable:wr(e)}:null}function _r(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:On(e,n)}function On(e,n){return!e||!n||Fe(e.normal,n.normal)<1-Go?!1:Math.abs(e.planeD-n.planeD)<=Wo}function Pn(e,n){if(!e)return null;let t=n.directionalLight,o=n.ambientLight,r=t?.direction??Bt,s=t?.color??Nt,i=Math.max(0,t?.intensity??$t),l=o?.color??Xt,a=Math.max(0,o?.intensity??Yt),u=Math.hypot(r[0],r[1],r[2])||1,m=r[0]/u,d=r[1]/u,f=r[2]/u,g=i*Math.max(0,e.normal[0]*m+e.normal[1]*d+e.normal[2]*f),p=kn(g,s,l,a);return p.r*.2126+p.g*.7152+p.b*.0722}function Rr(e){let n=[...e],t=Math.abs(n[0])>ce?0:Math.abs(n[1])>ce?1:2;return n[t]<0&&(n[0]*=-1,n[1]*=-1,n[2]*=-1),`${n[0].toFixed(6)},${n[1].toFixed(6)},${n[2].toFixed(6)}`}function Ye(e,n,t,o,r={}){let s=Fe(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],l=Math.hypot(i[0],i[1],i[2]);if(l<=ce)return null;let a=[i[0]/l,i[1]/l,i[2]/l],u=[t[1]*a[2]-t[2]*a[1],t[2]*a[0]-t[0]*a[2],t[0]*a[1]-t[1]*a[0]],m=Math.hypot(u[0],u[1],u[2]);if(m<=ce)return null;let d=[u[0]/m,u[1]/m,u[2]/m],f=e.map(w=>{let O=w[0]-n[0],H=w[1]-n[1],V=w[2]-n[2];return[O*a[0]+H*a[1]+V*a[2],O*d[0]+H*d[1]+V*d[2]]}),g=r.boundsOrigin??n,p=n[0]-g[0],h=n[1]-g[1],b=n[2]-g[2],x=p*a[0]+h*a[1]+b*a[2],A=p*d[0]+h*d[1]+b*d[2],M=1/0,P=1/0,E=-1/0,k=-1/0;for(let[w,O]of f){let H=w+x,V=O+A;H<M&&(M=H),H>E&&(E=H),V<P&&(P=V),V>k&&(k=V)}let C=E-M,v=k-P;if(!Number.isFinite(C)||!Number.isFinite(v))return null;let B=r.snapBounds?Math.floor(M+oe):M,N=r.snapBounds?Math.floor(P+oe):P,Y=r.snapBounds?Math.ceil(E-oe):E,ne=r.snapBounds?Math.ceil(k-oe):k,S=Math.max(1,r.snapBounds?Y-B:Math.ceil(C)),$=Math.max(1,r.snapBounds?ne-N:Math.ceil(v));return{xAxis:a,yAxis:d,local2D:f,shiftX:x-B,shiftY:A-N,canvasW:S,canvasH:$,pixelArea:S*$,rawArea:C*v}}function kr(e,n,t,o){let r=0,s=0;for(let i of e){let l=n[i];if(!l)return null;let a=Ye(l.pts,l.pts[0],l.normal,t,{boundsOrigin:o,snapBounds:!0});if(!a)return null;r+=a.pixelArea,s+=a.rawArea}return{pixelArea:r,rawArea:s}}function Dr(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,s=new Set;for(let i of e){let l=n[i];if(!l)continue;let a=[l.pts[1][0]-l.pts[0][0],l.pts[1][1]-l.pts[0][1],l.pts[1][2]-l.pts[0][2]],u=Ye(l.pts,l.pts[0],l.normal,a);o&&u?(o.pixelArea+=u.pixelArea,o.rawArea+=u.rawArea):o=null;for(let m=0;m<l.pts.length;m++){let d=Dn(l.pts[m],l.pts[(m+1)%l.pts.length]),f=Ye(l.pts,l.pts[0],l.normal,d);if(!f)continue;let g=Rr(f.xAxis);if(s.has(g))continue;s.add(g);let p=kr(e,n,f.xAxis,t);p&&(!r||p.pixelArea<r.pixelArea||p.pixelArea===r.pixelArea&&p.rawArea<r.rawArea-oe)&&(r={xAxis:f.xAxis,...p})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+oe)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function Zt(e,n){let t=n.tileSize??Ft,o=n.layerElevation??t,r=e.map(d=>Lr(d,t,o)),s=new Map,i=e.map(()=>new Set),l=e.map(()=>new Set);for(let d=0;d<e.length;d++){let f=e[d].vertices;if(!(!f||f.length<3))for(let g=0;g<f.length;g++){let p=Sr(f[g],f[(g+1)%f.length]),h=s.get(p),b={polygon:d,edge:g};h?h.push(b):s.set(p,[b])}}let a=e.map(()=>new Set);for(let d of s.values())if(!(d.length<2))for(let f=0;f<d.length;f++)for(let g=f+1;g<d.length;g++){let p=d[f],h=d[g],b=p.polygon,x=h.polygon;if(e[b].texture&&e[x].texture&&(l[p.polygon].add(p.edge),l[h.polygon].add(h.edge)),On(r[b],r[x]))i[p.polygon].add(p.edge),i[h.polygon].add(h.edge);else{let A=Pn(r[b],n),M=Pn(r[x],n);A!==null&&M!==null&&(A<=M+pn&&i[p.polygon].add(p.edge),M<=A+pn&&i[h.polygon].add(h.edge))}_r(r[b],r[x])&&(a[b].add(x),a[x].add(b))}let u=Array(e.length).fill(void 0),m=new Set;for(let d=0;d<e.length;d++){if(m.has(d)||!r[d]?.optimizable)continue;let f=[],g=[d];for(m.add(d);g.length>0;){let h=g.pop();f.push(h);for(let b of a[h])m.has(b)||(m.add(b),g.push(b))}if(f.length<2)continue;let p=Dr(f,r);if(p)for(let h of f)u[h]={xAxis:p.xAxis,boundsOrigin:p.boundsOrigin,seamEdges:i[h],textureEdgeRepairEdges:l[h]}}for(let d=0;d<e.length;d++)!u[d]&&(i[d].size>0||l[d].size>0)&&(u[d]={seamEdges:i[d],textureEdgeRepairEdges:l[d]});return u}function Or(e){if(typeof e.toBlob=="function")return new Promise(n=>{e.toBlob(t=>{n(t?URL.createObjectURL(t):null)},"image/png")});try{return Promise.resolve(e.toDataURL("image/png"))}catch{return Promise.resolve(null)}}function En(e,n,t,o){if(o.optimize&&o.fixedXAxis)return Ye(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,s=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,i=s??(o.optimize?e.map((l,a)=>a):[0]);for(let l of i){let a=(l+1)%e.length,u=s?Dn(e[l],e[a]):[e[a][0]-e[l][0],e[a][1]-e[l][1],e[a][2]-e[l][2]],m=Ye(e,n,t,u,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});m&&(!r||m.pixelArea<r.pixelArea||m.pixelArea===r.pixelArea&&m.rawArea<r.rawArea-oe)&&(r=m)}return r}function Ir(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=oe)return;r.push(s)};for(let[r,s]of e.local2D)o(n,r+e.shiftX),o(t,s+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>oe||Math.abs(t[0])>oe||n[1]-n[0]<=oe||t[1]-t[0]<=oe))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,l=s+e.shiftY,a=Math.abs(i-n[0])<=oe||Math.abs(i-n[1])<=oe,u=Math.abs(l-t[0])<=oe||Math.abs(l-t[1])<=oe;if(!a||!u)return!1}return!0}function In(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,l]=n,a=t[0],u=t[1],m=o[0],d=o[1],f=r[0],g=r[1],p=s[0],h=1-s[1],b=i[0],x=1-i[1],A=l[0],M=1-l[1],P=b-p,E=x-h,k=A-p,C=M-h,v=P*C-k*E;if(Math.abs(v)<=1e-9)return null;let B=m-a,N=f-a,Y=d-u,ne=g-u,S={a:(B*C-N*E)/v,b:(P*N-k*B)/v,c:(Y*C-ne*E)/v,d:(P*ne-k*Y)/v,e:0,f:0};return S.e=a-S.a*p-S.b*h,S.f=u-S.c*p-S.d*h,S}function Hn(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let s of e){let i=s[0],l=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(l))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,l),r=Math.max(r,l)}return{minU:n,minV:t,maxU:o,maxV:r}}function Hr(e,n,t,o,r,s,i,l){let u=Ue(e.vertices,n,t).map(f=>{let g=f[0]-o[0],p=f[1]-o[1],h=f[2]-o[2];return[g*r[0]+p*r[1]+h*r[2]+i,g*s[0]+p*s[1]+h*s[2]+l]}),m=In(u,e.uvs),d=Hn(e.uvs);return!m&&!d?null:{screenPts:u.flatMap(([f,g])=>[f,g]),uvAffine:m,uvSampleRect:d}}function Xe(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],o+=e[i+1];t/=r,o/=r;let s=e.slice();for(let i=0;i<s.length;i+=2){let l=s[i]-t,a=s[i+1]-o,u=Math.hypot(l,a);u<=oe||(s[i]+=l/u*n,s[i+1]+=a/u*n)}return s}function Vt(e,n,t,o){for(let r=0;r<o.length;r+=2){let s=n+o[r],i=t+o[r+1];r===0?e.moveTo(s,i):e.lineTo(s,i)}e.closePath()}function qt(e,n,t,o,r){let{vertices:s,texture:i,uvs:l}=e;if(!s||s.length<3)return null;let a=t.tileSize??Ft,u=t.layerElevation??a,m=Ue(s,a,u),d=m[0],f=m[1],g=[f[0]-d[0],f[1]-d[1],f[2]-d[2]];if(Math.hypot(g[0],g[1],g[2])===0)return null;let h=ut(m);if(!h)return null;let b=En(m,d,h,{optimize:!1}),x=i||b&&Ir(b)?b:En(m,d,h,{optimize:!0,fixedXAxis:r?.xAxis,boundsOrigin:r?.boundsOrigin,snapBounds:!!r,seamEdges:r?.seamEdges});if(!x)return null;let{xAxis:A,yAxis:M,local2D:P}=x,E=i&&r?.textureEdgeRepairEdges?.size?r.textureEdgeRepairEdges:null,k=!!(i&&E),C=x.shiftX,v=x.shiftY,B=x.canvasW,N=x.canvasH,Y=[];for(let[I,D]of P)Y.push(I+C,D+v);let ne=d[0]-C*A[0]-v*M[0],S=d[1]-C*A[1]-v*M[1],$=d[2]-C*A[2]-v*M[2],w=Ce([A[0],A[1],A[2],0,M[0],M[1],M[2],0,h[0],h[1],h[2],0,ne,S,$,1]),O=Ce([A[0]*B,A[1]*B,A[2]*B,0,M[0]*N,M[1]*N,M[2]*N,0,h[0],h[1],h[2],0,ne,S,$,1]),H=Ce([A[0]*B/Ee,A[1]*B/Ee,A[2]*B/Ee,0,M[0]*N/Ee,M[1]*N/Ee,M[2]*N/Ee,0,h[0],h[1],h[2],0,ne,S,$,1]),V=!i&&s.length===4?lr(Y,A,M,h,ne,S,$,o):null,j=t.directionalLight,le=t.ambientLight,_=j?.direction??Bt,X=j?.color??Nt,U=Math.max(0,j?.intensity??$t),re=le?.color??Xt,se=Math.max(0,le?.intensity??Yt),ue=Math.hypot(_[0],_[1],_[2])||1,he=_[0]/ue,de=_[1]/ue,me=_[2]/ue,ge=U*Math.max(0,h[0]*he+h[1]*de+h[2]*me),be=kn(ge,X,re,se),c=Rn(e.color??"#cccccc",ge,X,re,se),y=null,R=null;i&&l&&l.length>=3&&l.length===s.length&&(R=Hn(l),y=In(P.map(([I,D])=>[I+C,D+v]),l));let T=i&&e.textureTriangles?.length?e.textureTriangles.map(I=>Hr(I,a,u,d,A,M,C,v)).filter(I=>!!I):null;return{index:n,polygon:e,texture:i,tileSize:a,layerElevation:u,matrix:w,canonicalMatrix:O,atlasMatrix:H,projectiveMatrix:V,canvasW:B,canvasH:N,screenPts:Y,uvAffine:y,uvSampleRect:R,textureTriangles:T,textureEdgeRepairEdges:E,textureEdgeRepair:k,normal:h,textureTint:be,shadedColor:c}}function dt(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??Ft,r=t.layerElevation??o,s=Ue(e.vertices,o,r),i=ut(s);if(!i)return null;let l=[{a:0,b:1,c:2},{a:1,b:2,c:0},{a:2,b:0,c:1}].map(Z=>{let F=s[Z.a],K=s[Z.b];return{...Z,length:Math.hypot(K[0]-F[0],K[1]-F[1],K[2]-F[2])}}).sort((Z,F)=>F.length-Z.length),a=l[0].a,u=l[0].b,m=l[0].c,d=s[a],f=s[u],g=s[m],p=l[0].length;if(p<=ce)return null;let h=[(f[0]-d[0])/p,(f[1]-d[1])/p,(f[2]-d[2])/p],b=[g[0]-d[0],g[1]-d[1],g[2]-d[2]],x=Fe(b,h),A=[d[0]+h[0]*x,d[1]+h[1]*x,d[2]+h[2]*x],M=[A[0]-g[0],A[1]-g[1],A[2]-g[2]],P=Math.hypot(M[0],M[1],M[2]);if(P<=ce)return null;let E=[M[0]/P,M[1]/P,M[2]/P];if(Fe(Tr(h,E),i)<0){let Z=u;if(u=a,a=Z,d=s[a],f=s[u],p=Math.hypot(f[0]-d[0],f[1]-d[1],f[2]-d[2]),p<=ce)return null;h=[(f[0]-d[0])/p,(f[1]-d[1])/p,(f[2]-d[2])/p];let F=[g[0]-d[0],g[1]-d[1],g[2]-d[2]];x=Fe(F,h),A=[d[0]+h[0]*x,d[1]+h[1]*x,d[2]+h[2]*x],M=[A[0]-g[0],A[1]-g[1],A[2]-g[2]];let K=Math.hypot(M[0],M[1],M[2]);if(K<=ce)return null;E=[M[0]/K,M[1]/K,M[2]/K]}let k=Math.max(0,Math.min(p,x)),C=Math.max(0,p-k),v=Gt([k,0,0,P,k+C,P],Qo),B=[v[0],v[1]],N=[v[2],v[3]],Y=[v[4],v[5]],ne=(N[1]+Y[1])/2,S=B[0]-N[0],$=Y[0]-B[0],w=ne-B[1];if(S<=ce||$<=ce||w<=ce||!Number.isFinite(S+$+w))return null;let O=t.directionalLight,H=t.ambientLight,V=O?.direction??Bt,j=O?.color??Nt,le=Math.max(0,O?.intensity??$t),_=H?.color??Xt,X=Math.max(0,H?.intensity??Yt),U=Math.hypot(V[0],V[1],V[2])||1,re=V[0]/U,se=V[1]/U,ue=V[2]/U,he=le*Math.max(0,i[0]*re+i[1]*se+i[2]*ue),de=Rn(e.color??"#cccccc",he,j,_,X),me=t.textureLighting??"baked",ge=Se(e.color??"#cccccc"),be=de===t.solidPaintDefaults?.paintColor,c=me==="dynamic"&&jt(ge)===t.solidPaintDefaults?.dynamicColorKey,y=me==="dynamic"||be?"":`color:${de};`,R=me==="dynamic"?`--pnx:${i[0].toFixed(4)};--pny:${i[1].toFixed(4)};--pnz:${i[2].toFixed(4)};`+(c?"":`--psr:${(ge.r/255).toFixed(4)};--psg:${(ge.g/255).toFixed(4)};--psb:${(ge.b/255).toFixed(4)};`):"",T=([Z,F])=>[g[0]+(Z-k)*h[0]+F*E[0],g[1]+(Z-k)*h[1]+F*E[1],g[2]+(Z-k)*h[2]+F*E[2]],I=T(B),D=T([N[0],ne]),z=T([Y[0],ne]),G=Le/2,te=[(z[0]-D[0])/Le,(z[1]-D[1])/Le,(z[2]-D[2])/Le],q=[I[0]-te[0]*G,I[1]-te[1]*G,I[2]-te[2]*G],Q=[(D[0]-q[0])/Le,(D[1]-q[1])/Le,(D[2]-q[2])/Le],L=`transform:matrix3d(${Ce([te[0],te[1],te[2],0,Q[0],Q[1],Q[2],0,i[0],i[1],i[2],0,q[0],q[1],q[2],1])});`+y+R;return{index:n,polygon:e,styleText:L}}function at(e,n=1){let t=Array(e.length).fill(null),o=[],r=vr(n),s=e.filter(a=>!!a).sort((a,u)=>u.canvasH-a.canvasH||u.canvasW-a.canvasW||a.index-u.index),i=()=>({width:r,height:r,entries:[],shelves:[]}),l=(a,u,m)=>{if(a.sealed)return null;for(let g of a.shelves)if(u.canvasH<=g.height&&g.x+u.canvasW+r<=Ve){let p={...u,pageIndex:m,x:g.x,y:g.y};return g.x+=u.canvasW+r*2,a.entries.push(p),a.width=Math.max(a.width,p.x+u.canvasW+r),p}let d=a.shelves.length===0?r:a.height+r;if(d+u.canvasH+r>Ve)return null;let f={...u,pageIndex:m,x:r,y:d};return a.shelves.push({x:r+u.canvasW+r*2,y:d,height:u.canvasH}),a.entries.push(f),a.width=Math.max(a.width,f.x+u.canvasW+r),a.height=Math.max(a.height,d+u.canvasH+r),f};for(let a of s){if(a.canvasW+r*2>Ve||a.canvasH+r*2>Ve){let d=o.length,f={...a,pageIndex:d,x:r,y:r};t[a.index]=f,o.push({width:a.canvasW+r*2,height:a.canvasH+r*2,entries:[f],shelves:[],sealed:!0});continue}let m=null;for(let d=0;d<o.length&&(m=l(o[d],a,d),!m);d++);if(!m){let d=i(),f=o.length;o.push(d),m=l(d,a,f)}m&&(t[a.index]=m)}return{entries:t,pages:o.map(({width:a,height:u,entries:m})=>({width:a,height:u,entries:m}))}}function Vr(e,n,t,o){Pe(e,o),e.beginPath(),Vt(e,n.x,n.y,n.screenPts),e.clip(),Pe(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function He(e,n){return Math.max(0,Math.min(n,e))}function An(e,n,t,o,r,s,i,l){let a=n.naturalWidth||n.width||1,u=n.naturalHeight||n.height||1,m=He(Math.min(t.minU,t.maxU)*a,a),d=He(Math.max(t.minU,t.maxU)*a,a),f=He(Math.min(t.minV,t.maxV)*u,u),g=He(Math.max(t.minV,t.maxV)*u,u),p=Math.floor(m),h=Math.floor(f),b=Math.ceil(d)-p,x=Math.ceil(g)-h;b<1&&(p=Math.floor(He((t.minU+t.maxU)/2*a,a-1)),b=1),x<1&&(h=Math.floor(He((t.minV+t.maxV)/2*u,u-1)),x=1),p=Math.max(0,Math.min(a-1,p)),h=Math.max(0,Math.min(u-1,h)),b=Math.max(1,Math.min(a-p,b)),x=Math.max(1,Math.min(u-h,x)),Pe(e,l),e.drawImage(n,p,h,b,x,o,r,s,i)}function zr(e,n,t,o,r,s){for(let i=0;i<o.length;i+=2){let l=n+o[i]+r,a=t+o[i+1]+s;i===0?e.moveTo(l,a):e.lineTo(l,a)}e.closePath()}function Fr(e,n,t,o,r=0,s=0){if(n.textureTriangles?.length){let i=t.naturalWidth||t.width||1,l=t.naturalHeight||t.height||1;for(let a of n.textureTriangles){let u=Xe(a.screenPts,jo);e.save(),Pe(e,o),e.beginPath(),zr(e,n.x,n.y,u,r,s),e.clip(),a.uvAffine?(Pe(e,o,a.uvAffine.a/i,a.uvAffine.c/i,a.uvAffine.b/l,a.uvAffine.d/l,n.x+a.uvAffine.e+r,n.y+a.uvAffine.f+s),e.drawImage(t,0,0)):a.uvSampleRect&&An(e,t,a.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let i=t.naturalWidth||t.width||1,l=t.naturalHeight||t.height||1;Pe(e,o,n.uvAffine.a/i,n.uvAffine.c/i,n.uvAffine.b/l,n.uvAffine.d/l,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+s),e.drawImage(t,0,0)}else n.uvSampleRect?An(e,t,n.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o):Cr(e,t,n.x+r,n.y+s,n.canvasW,n.canvasH,o)}function Br(e,n,t,o,r,s){let i=r-t,l=s-o,a=i*i+l*l;if(a<=ce)return Math.hypot(e-t,n-o);let u=Math.max(0,Math.min(1,((e-t)*i+(n-o)*l)/a));return Math.hypot(e-(t+i*u),n-(o+l*u))}function Nr(e,n,t,o){let r=1/0,s=t.length/2;for(let i of o){if(i<0||i>=s)continue;let l=i*2,a=(i+1)%s*2;r=Math.min(r,Br(e,n,t[l],t[l+1],t[a],t[a+1]))}return r}function $r(e,n,t,o,r,s){let i=Math.max(0,o-s),l=Math.min(n-1,o+s),a=Math.max(0,r-s),u=Math.min(t-1,r+s),m=null,d=1/0;for(let f=a;f<=u;f++)for(let g=i;g<=l;g++){if(g===o&&f===r)continue;let p=g-o,h=f-r,b=p*p+h*h;if(b>s*s||b>=d)continue;let x=(f*n+g)*4;e[x+3]<qo||(m=x,d=b)}return m}function Xr(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),s=Math.max(0,Math.floor(n.y*t)),i=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),l=Math.max(1,Math.min(o.height-s,Math.ceil(n.canvasH*t)));if(i<=0||l<=0)return;let a;try{a=e.getImageData(r,s,i,l)}catch{return}let u=a.data,m=new Uint8ClampedArray(u),d=Math.max(fn,fn/t),f=Math.max(2,Math.ceil(d*t)+1),g=!1;for(let p=0;p<l;p++)for(let h=0;h<i;h++){let b=(p*i+h)*4,x=u[b+3];if(x<Zo||x===255)continue;let A=(r+h+.5)/t-n.x,M=(s+p+.5)/t-n.y;if(Nr(A,M,n.screenPts,n.textureEdgeRepairEdges)>d)continue;let P=$r(m,i,l,h,p,f);P!==null&&(u[b]=m[P],u[b+1]=m[P+1],u[b+2]=m[P+2],u[b+3]=255,g=!0)}g&&e.putImageData(a,r,s)}async function Yr(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=e.entries.some(m=>m.textureEdgeRepair&&m.texture&&m.textureEdgeRepairEdges&&m.textureEdgeRepairEdges.size>0),i=r.getContext("2d",s?{willReadFrequently:!0}:void 0);if(!i)return{width:e.width,height:e.height,url:null};let l=Array.from(new Set(e.entries.flatMap(m=>m.texture?[m.texture]:[]))),a=new Map;await Promise.all(l.map(async m=>{a.set(m,await sr(m))}));for(let m of e.entries){let d=m.texture?a.get(m.texture):null;if(!m.texture){i.save(),Vr(i,m,n,o),i.restore();continue}d&&(i.save(),Pe(i,o),i.beginPath(),Vt(i,m.x,m.y,m.screenPts),i.clip(),Fr(i,m,d,o),i.restore()),m.texture&&n==="baked"&&(i.save(),Pe(i,o),i.beginPath(),Vt(i,m.x,m.y,m.screenPts),i.clip(),Mr(i,m.x,m.y,m.canvasW,m.canvasH,m.textureTint,o),i.restore()),Xr(i,m,o)}let u=await Or(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:u}}async function Vn(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await Yr(i,n,t,o))}return s}function zn(e,n,t,o){if(!n.url)return;let r=`url(${n.url})`,s=o.canvasW||1,i=o.canvasH||1,l=Me(o),a=`${ze(-o.x/s*l)} ${ze(-o.y/i*l)}`,u=`${ze(n.width/s*l)} ${ze(n.height/i*l)}`;t==="dynamic"?(J(e,"background-image",r),J(e,"background-position",a),J(e,"background-size",u)):J(e,"background",`${r} ${a} / ${u} no-repeat`),t==="dynamic"?(J(e,"mask-image",r),J(e,"mask-mode","alpha"),J(e,"mask-position",a),J(e,"mask-size",u),J(e,"mask-repeat","no-repeat"),J(e,"-webkit-mask-image",r),J(e,"-webkit-mask-position",a),J(e,"-webkit-mask-size",u),J(e,"-webkit-mask-repeat","no-repeat")):(pe(e,"mask-image"),pe(e,"mask-mode"),pe(e,"mask-position"),pe(e,"mask-size"),pe(e,"mask-repeat"),pe(e,"-webkit-mask-image"),pe(e,"-webkit-mask-position"),pe(e,"-webkit-mask-size"),pe(e,"-webkit-mask-repeat"))}function Re(e,n){let t=It.get(e);if(t)for(let r of t)e.removeAttribute(`data-${r}`);let o=[];if(n.data)for(let[r,s]of Object.entries(n.data))e.setAttribute(`data-${r}`,String(s)),o.push(r);It.set(e,o)}function Fn(e,n,t,o=0,r=0){let s=e.matrix.split(",").map(f=>Number(f));if(s.length!==16||s.some(f=>!Number.isFinite(f)))return e.matrix;let i=s[0],l=s[1],a=s[2],u=s[4],m=s[5],d=s[6];return s[0]*=n,s[1]*=n,s[2]*=n,s[4]*=t,s[5]*=t,s[6]*=t,s[12]+=o*i+r*u,s[13]+=o*l+r*m,s[14]+=o*a+r*d,Ce(s)}function Ur(e,n){return Fn(e,n.width/yn,n.height/yn,n.minX,n.minY)}function Gr(e){return Fn(e,(e.canvasW||1)/Ht,(e.canvasH||1)/Ht)}function Wr(e){let n=Xn(e);return[`transform:matrix3d(${Ur(e,n.bounds)})`,`border-shape:${Yn(n.points)}`].join(";")}function jr(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,o=e.layerElevation,r=Ue(n.vertices,t,o),s=ut(r);if(!s)return null;let i=e.screenPts[0],l=e.screenPts[1],a=e.screenPts[2],u=e.screenPts[3],m=e.screenPts[4],d=e.screenPts[5],f=a-i,g=u-l,p=m-i,h=d-l,b=f*h-g*p;if(Math.abs(b)<=ce)return null;let x=r[0],A=r[1],M=r[2],P=[A[0]-x[0],A[1]-x[1],A[2]-x[2]],E=[M[0]-x[0],M[1]-x[1],M[2]-x[2]],k=[(P[0]*h-g*E[0])/b,(P[1]*h-g*E[1])/b,(P[2]*h-g*E[2])/b],C=[(f*E[0]-P[0]*p)/b,(f*E[1]-P[1]*p)/b,(f*E[2]-P[2]*p)/b],v=x[0]-k[0]*i-C[0]*l,B=x[1]-k[1]*i-C[1]*l,N=x[2]-k[2]*i-C[2]*l;return{normal:s,matrix:Ce([k[0]*e.canvasW/Me(e),k[1]*e.canvasW/Me(e),k[2]*e.canvasW/Me(e),0,C[0]*e.canvasH/Me(e),C[1]*e.canvasH/Me(e),C[2]*e.canvasH/Me(e),0,s[0],s[1],s[2],0,v,B,N,1])}}function Zr(e,n,t,o){if(!n.texture||!t.texture||n.texture!==t.texture)return!1;let r=jr(n,t);return r?(J(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(J(e,"--pnx",r.normal[0].toFixed(4)),J(e,"--pny",r.normal[1].toFixed(4)),J(e,"--pnz",r.normal[2].toFixed(4))),Re(e,t),!0):!1}function Bn(e,n){J(e,"--pnx",n.normal[0].toFixed(4)),J(e,"--pny",n.normal[1].toFixed(4)),J(e,"--pnz",n.normal[2].toFixed(4))}function qr(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=oe)return;r.push(s)};for(let r=0;r<e.screenPts.length;r+=2)o(n,e.screenPts[r]),o(t,e.screenPts[r+1]);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>oe||Math.abs(t[0])>oe||n[1]-n[0]<=oe||t[1]-t[0]<=oe))return null;for(let r=0;r<e.screenPts.length;r+=2){let s=e.screenPts[r],i=e.screenPts[r+1],l=Math.abs(s-n[0])<=oe||Math.abs(s-n[1])<=oe,a=Math.abs(i-t[0])<=oe||Math.abs(i-t[1])<=oe;if(!l||!a)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function _e(e){return!!qr(e)}function lt(e){return!e.texture&&e.polygon.vertices.length===3}function Be(e){return!e.texture&&!!e.projectiveMatrix&&!_e(e)}function Qt(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function mt(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";if(!t)return!0;let o=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(t);return!/\bVersion\/[\d.]+.*\bSafari\//.test(t)||o}function Mn(e,n){e.set(n,(e.get(n)??0)+1)}function Cn(e){let n,t=1;for(let[o,r]of e)r>t&&(n=o,t=r);return n}function Nn(e,n,t,o){let r=new Map,s=new Map,i=new Map,l=!o.has("b"),a=l,u=!o.has("u")&&mt(t),m=!o.has("i")&&Qt(t);for(let g of e)if(!(!g||g.texture)){if(n==="dynamic"){if(!(u&<(g))&&!(l&&_e(g))&&!(a&&Be(g))&&!m)continue;let p=Se(g.polygon.color??"#cccccc"),h=jt(p);Mn(s,h),i.has(h)||i.set(h,p);continue}!(u&<(g))&&!(l&&_e(g))&&!(a&&Be(g))&&!m||Mn(r,g.shadedColor)}let d=Cn(r),f=Cn(s);return{paintColor:d,dynamicColorKey:f,dynamicColor:f?i.get(f):void 0}}function $n(){return new Promise(e=>setTimeout(e,0))}async function Dt(e){return performance.now()-e<Uo?e:(await $n(),performance.now())}function pt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=new Set(n.strategies?.disable??[]),r=Zt(e,n),s=Wt(t),i=e.map((l,a)=>qt(l,a,n,s,r[a]));return Nn(i,n.textureLighting??"baked",t,o)}function Qr(e,n,t){let o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(let u=0;u<e.length;u+=2){let m=e[u],d=e[u+1];!Number.isFinite(m)||!Number.isFinite(d)||(o=Math.min(o,m),r=Math.min(r,d),s=Math.max(s,m),i=Math.max(i,d))}let l=s-o,a=i-r;return!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(l)||!Number.isFinite(a)||l<=ce||a<=ce?{minX:0,minY:0,width:n,height:t}:{minX:o,minY:r,width:l,height:a}}function Xn(e){let n=e.canvasW||1,t=e.canvasH||1,o=kt>0?Gt(e.screenPts,kt):e.screenPts,r=kt>0?Qr(o,n,t):{minX:0,minY:0,width:n,height:t},s=[];for(let i=0;i<o.length;i+=2){let l=Math.max(0,Math.min(100,(o[i]-r.minX)/r.width*100)),a=Math.max(0,Math.min(100,(o[i+1]-r.minY)/r.height*100));s.push([l,a])}return{bounds:r,points:s}}function Kr([e,n]){return`${st(e)} ${st(n)}`}function Jr(e){return`polygon(${e.map(Kr).join(",")})`}function es(e){if(ur(e))return"circle(0)";let n=0,t=0,o=Math.max(1,e.length);for(let[i,l]of e)n+=i,t+=l;let r=st(Math.max(0,Math.min(100,n/o))),s=st(Math.max(0,Math.min(100,t/o)));return`circle(0 at ${r} ${s})`}function Yn(e){return`${Jr(e)} ${es(e)}`}function Un(e){return Yn(Xn(e).points)}function Kt(e,n,t,o){if(t==="dynamic"){pe(e,"color"),pe(e,"background"),Bn(e,n);let r=Se(n.polygon.color??"#cccccc");jt(r)===o?.dynamicColorKey?(pe(e,"--psr"),pe(e,"--psg"),pe(e,"--psb")):(J(e,"--psr",(r.r/255).toFixed(4)),J(e,"--psg",(r.g/255).toFixed(4)),J(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(pe(e,"background"),J(e,"color",n.shadedColor)):(pe(e,"background"),pe(e,"color"))}function Gn(e,n,t,o){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${Gr(e)})`),Re(r,e.polygon),Kt(r,e,n,o),r}function Wn(e,n,t,o){let r=t.createElement("i");return r.setAttribute("style",Wr(e)),Re(r,e.polygon),Kt(r,e,n,o),r}function jn(e,n,t,o){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`),Re(r,e.polygon),Kt(r,e,n,o),r}function Zn(e,n,t){let o=t.createElement("s");o.setAttribute("style",`transform:matrix3d(${e.atlasMatrix})`),Re(o,e.polygon);let r=e.canvasW||1,s=e.canvasH||1,i=Me(e);return J(o,"--polycss-atlas-size",`${i}px`),J(o,"background-position",`${ze(-e.x/r*i)} ${ze(-e.y/s*i)}`),J(o,"opacity","0"),n==="dynamic"&&Bn(o,e),o}function qn(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=new Set(n.strategies?.disable??[]),s=!r.has("b"),i=s,l=!r.has("u")&&mt(t),a=!r.has("i")&&Qt(t),u=Zt(e,n),m=Wt(t),d=e.map((P,E)=>qt(P,E,n,m,u[E])),f=d.map(P=>P&&l&<(P)?dt(P.polygon,P.index,n):null),g=d.map((P,E)=>P&&(P.texture||!(s&&_e(P))&&!f[E]&&!(i&&Be(P))&&!a?P:null)),{packed:p,atlasScale:h}=_n(g,n.textureQuality,t),b=new Map,x=[],A=!1,M=[];for(let P=0;P<e.length;P++){let E=d[P],k=f[P];if(!E)continue;let C=p.entries[P];if(C){let v=Zn(C,o,t);b.set(P,v),x.push({polygonIndex:P,element:v,kind:"atlas",plan:C,dispose:()=>{}})}else if(!E.texture&&s&&_e(E)){let v=Gn(E,o,t,n.solidPaintDefaults);x.push({polygonIndex:P,element:v,kind:"solid",plan:E,dispose:()=>{}})}else if(!E.texture&&k){let v=Jt(k,t);x.push({polygonIndex:P,element:v,kind:"triangle",plan:E,dispose:()=>{}})}else if(!E.texture&&i&&Be(E)){let v=jn(E,o,t,n.solidPaintDefaults);x.push({polygonIndex:P,element:v,kind:"solid",plan:E,dispose:()=>{}})}else if(!E.texture&&a){let v=Wn(E,o,t,n.solidPaintDefaults);x.push({polygonIndex:P,element:v,kind:"border",plan:E,dispose:()=>{}})}}return x.sort((P,E)=>P.polygonIndex-E.polygonIndex),Vn(p.pages,o,t,h,()=>A).then(P=>{if(A){for(let E of P)E.url?.startsWith("blob:")&&URL.revokeObjectURL(E.url);return}M=P.flatMap(E=>E.url?.startsWith("blob:")?[E.url]:[]);for(let E=0;E<p.pages.length;E++){let k=p.pages[E],C=P[E];if(C)for(let v of k.entries){let B=b.get(v.index);!B||!C.url||(zn(B,C,o,v),pe(B,"opacity"))}}}).catch(()=>{if(!A)for(let P of b.values())J(P,"opacity","0.5"),J(P,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:x,dispose(){A=!0;for(let P of M)URL.revokeObjectURL(P);M=[]}}}async function Qn(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let r=n.textureLighting??"baked",s=new Set(n.strategies?.disable??[]),i=!s.has("b"),l=i,a=!s.has("u")&&mt(o),u=!s.has("i")&&Qt(o);if(await $n(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let m=Zt(e,n),d=Wt(o),f=performance.now(),g=new Array(e.length);for(let C=0;C<e.length;C++)if(g[C]=qt(e[C],C,n,d,m[C]),f=await Dt(f),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let p=n.solidPaintDefaults??Nn(g,r,o,s),h=new Array(g.length),b=new Array(g.length);for(let C=0;C<g.length;C++){let v=g[C],B=v&&a&<(v)?dt(v.polygon,v.index,{...n,solidPaintDefaults:p}):null;if(h[C]=B,b[C]=v&&(v.texture||!(i&&_e(v))&&!B&&!(l&&Be(v))&&!u?v:null),f=await Dt(f),t())return{rendered:[],solidPaintDefaults:p,dispose:()=>{}}}let{packed:x,atlasScale:A}=_n(b,n.textureQuality,o),M=new Map,P=[],E=!1,k=[];for(let C=0;C<e.length;C++){let v=g[C],B=h[C];if(!v)continue;let N=x.entries[C];if(N){let Y=Zn(N,r,o);M.set(C,Y),P.push({polygonIndex:C,element:Y,kind:"atlas",plan:N,dispose:()=>{}})}else if(!v.texture&&i&&_e(v)){let Y=Gn(v,r,o,p);P.push({polygonIndex:C,element:Y,kind:"solid",plan:v,dispose:()=>{}})}else if(!v.texture&&B){let Y=Jt(B,o);P.push({polygonIndex:C,element:Y,kind:"triangle",plan:v,dispose:()=>{}})}else if(!v.texture&&l&&Be(v)){let Y=jn(v,r,o,p);P.push({polygonIndex:C,element:Y,kind:"solid",plan:v,dispose:()=>{}})}else if(!v.texture&&u){let Y=Wn(v,r,o,p);P.push({polygonIndex:C,element:Y,kind:"border",plan:v,dispose:()=>{}})}if(f=await Dt(f),t()){for(let Y of P)Y.dispose();return{rendered:[],solidPaintDefaults:p,dispose:()=>{}}}}return P.sort((C,v)=>C.polygonIndex-v.polygonIndex),Vn(x.pages,r,o,A,()=>E||t()).then(C=>{if(E||t()){for(let v of C)v.url?.startsWith("blob:")&&URL.revokeObjectURL(v.url);return}k=C.flatMap(v=>v.url?.startsWith("blob:")?[v.url]:[]);for(let v=0;v<x.pages.length;v++){let B=x.pages[v],N=C[v];if(N)for(let Y of B.entries){let ne=M.get(Y.index);!ne||!N.url||(zn(ne,N,r,Y),pe(ne,"opacity"))}}}).catch(()=>{if(!(E||t()))for(let C of M.values())J(C,"opacity","0.5"),J(C,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:P,solidPaintDefaults:p,dispose(){E=!0;for(let C of k)URL.revokeObjectURL(C);k=[]}}}function ts(e,n){let t=e.map((o,r)=>dt(o,r,n));return t.some(o=>!o)?null:t}function ns(e){e.style.backgroundImage="",e.style.backgroundPosition="",e.style.backgroundSize="",e.style.maskImage="",e.style.maskMode="",e.style.maskPosition="",e.style.maskSize="",e.style.maskRepeat="",e.style.removeProperty("-webkit-mask-image"),e.style.removeProperty("-webkit-mask-position"),e.style.removeProperty("-webkit-mask-size"),e.style.removeProperty("-webkit-mask-repeat")}function Kn(e,n){e.setAttribute("style",n.styleText),(n.polygon.data||It.get(e)?.length)&&Re(e,n.polygon)}function Jt(e,n){let t=n.createElement("u");return ns(t),Kn(t,e),Re(t,e.polygon),t}function en(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};if(!mt(t))return null;let o=ts(e,n);if(!o)return null;let r=[];for(let s of o){let i=Jt(s,t);r.push({polygonIndex:s.index,element:i,kind:"triangle",dispose:()=>{}})}return r.sort((s,i)=>s.polygonIndex-i.polygonIndex),{rendered:r,dispose(){}}}function Jn(e,n,t={}){if(e.length!==n.length)return!1;let o=t.textureLighting??"baked",r=[];for(let s=0;s<e.length;s++){let i=e[s];if(i.polygonIndex!==s)return!1;let l=n[s];if(!l)return!1;if(i.kind==="atlas"){if(!i.plan||!Zr(i.element,i.plan,l,o))return!1;continue}if(i.kind==="triangle"){let a=dt(l,s,t);if(!a)return!1;r[s]=a;continue}return!1}for(let s=0;s<e.length;s++){let i=e[s];if(i.kind==="triangle"){let l=r[s];if(!l)return!1;Kn(i.element,l)}}return!0}var ae=require("@layoutit/polycss-core"),os=[.4,-.7,.59],rs="#ffffff",ss=1,is="#ffffff",as=.4,to={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},ls=["t","b","bl","br","fr","fl"],cs=new Map([["0,0,1","t"],["0,0,-1","b"],["0,1,0","fl"],["0,-1,0","br"],["1,0,0","fr"],["-1,0,0","bl"]]);function eo(e){let n=[];for(let t of ls)(0,ae.normalFacesCamera)(to[t],e)&&n.push(t);return n.join("|")}function us(e,n,t){let o=e.__polycssVoxelBrushState??(e.__polycssVoxelBrushState={});o.color!==n&&(e.style.color=n,o.color=n),o.transform!==t&&(e.style.transform=t,o.transform=t)}function ds(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let l=1;l+1<n.length;l+=1){let a=n[l],u=n[l+1],m=a[1]-t[1],d=a[0]-t[0],f=a[2]-t[2],g=u[1]-t[1],p=u[0]-t[0],h=u[2]-t[2];o-=d*h-f*p,r-=f*g-m*h,s-=m*p-d*g}let i=Math.hypot(o,r,s);return i<=1e-9?null:[Math.round(o/i),Math.round(r/i),Math.round(s/i)]}function ms(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=ds(e),t=n?cs.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,s=1/0,i=-1/0,l=-1/0,a=-1/0;for(let d of e.vertices)o=Math.min(o,d[0]),r=Math.min(r,d[1]),s=Math.min(s,d[2]),i=Math.max(i,d[0]),l=Math.max(l,d[1]),a=Math.max(a,d[2]);let u=1e-6,m=e.color||"#cccccc";return Math.abs(a-s)<=u?{axis:"z",face:t,left:r*ae.BASE_TILE,top:o*ae.BASE_TILE,width:Math.max(0,(l-r)*ae.BASE_TILE),height:Math.max(0,(i-o)*ae.BASE_TILE),z:s*ae.BASE_TILE,baseColor:m}:Math.abs(i-o)<=u?{axis:"x",face:t,left:r*ae.BASE_TILE,top:s*ae.BASE_TILE,width:Math.max(0,(l-r)*ae.BASE_TILE),height:Math.max(0,(a-s)*ae.BASE_TILE),z:-o*ae.BASE_TILE,baseColor:m}:Math.abs(l-r)<=u?{axis:"y",face:t,left:s*ae.BASE_TILE,top:o*ae.BASE_TILE,width:Math.max(0,(a-s)*ae.BASE_TILE),height:Math.max(0,(i-o)*ae.BASE_TILE),z:-r*ae.BASE_TILE,baseColor:m}:null}function tn(e){let n=(0,ae.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha}:{r:255,g:255,b:255,alpha:1}}function ps({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function nn(e){return Math.round(Math.max(0,Math.min(255,e)))}function fs(e,n,t,o){let r=tn(n),s=tn(t?.color??rs),i=tn(o?.color??is),l=t?.direction??os,a=Math.hypot(l[0],l[1],l[2])||1,u=l[0]/a,m=l[1]/a,d=l[2]/a,f=Math.max(0,t?.intensity??ss)*Math.max(0,e[0]*u+e[1]*m+e[2]*d),g=Math.max(0,o?.intensity??as),p=i.r/255*g+s.r/255*f,h=i.g/255*g+s.g/255*f,b=i.b/255*g+s.b/255*f,x={r:r.r*p,g:r.g*h,b:r.b*b,alpha:r.alpha};return x.alpha<1?`rgba(${nn(x.r)}, ${nn(x.g)}, ${nn(x.b)}, ${x.alpha})`:ps(x)}function hs(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=ms(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return n}function gs(e,n,t,o,r,s){return`matrix3d(${(e==="x"?[o,0,0,0,0,0,r,0,0,-1,0,0,n,-s,t,1]:e==="y"?[0,0,o,0,0,r,0,0,-1,0,0,0,-s,t,n,1]:[o,0,0,0,0,r,0,0,0,0,1,0,n,t,s,1]).map(l=>Number(l.toFixed(6))).join(",")})`}function ys(e){return e.axis==="x"?[e.left+e.width/2,-e.z,e.top+e.height/2]:e.axis==="y"?[-e.z,e.top+e.height/2,e.left+e.width/2]:[e.left+e.width/2,e.top+e.height/2,e.z]}function bs(e,n){let t=ys(e),o=n.meshRotation;o&&(t=(0,ae.rotateVec3)(t,o[0]??0,o[1]??0,o[2]??0));let[r,s]=(0,ae.rotateVec3)(t,n.rotX,0,n.rotY);return{x:r,y:s}}function xs(e,n,t){let o=e.filter(f=>n.has(f.face)).map(f=>({item:f,...bs(f,t)}));if(o.length===0)return[];let r=1/0,s=-1/0,i=1/0,l=-1/0;for(let f of o)r=Math.min(r,f.x),s=Math.max(s,f.x),i=Math.min(i,f.y),l=Math.max(l,f.y);let a=4,u=Math.max(1e-6,s-r),m=Math.max(1e-6,l-i),d=new Map;for(let f of o){let g=Math.min(a-1,Math.max(0,Math.floor((f.x-r)/u*a))),p=Math.min(a-1,Math.max(0,Math.floor((f.y-i)/m*a))),h=`${g}:${p}`,b=d.get(h);b||(b={tx:g,ty:p,sourceIndex:f.item.sourceIndex,items:[]},d.set(h,b)),b.items.push(f.item),b.sourceIndex=Math.min(b.sourceIndex,f.item.sourceIndex)}return Array.from(d.values()).sort((f,g)=>f.ty-g.ty||f.tx-g.tx||f.sourceIndex-g.sourceIndex).flatMap(f=>f.items)}function no(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:s}=e,i=hs(o);if(i.length===0)return null;t.classList.add("polycss-voxel-mesh");let l=new Map,a=(p,h)=>{let b=`${p}|${h}`,x=l.get(b);if(x)return x;let A=fs(to[p],h,r,s);return l.set(b,A),A},u=[],m="",d=0,f=p=>{let h=u[p];return h||(h=n.createElement("b"),u[p]=h),h.parentElement!==t&&t.appendChild(h),h},g=(p,h)=>{let b=new Set(p.split("|").filter(Boolean)),x=xs(i,b,h);d=0;for(let A of x){let M=f(d);us(M,a(A.face,A.baseColor),gs(A.axis,A.left,A.top,A.width,A.height,A.z)),d+=1}for(let A=d;A<u.length;A+=1)u[A]?.remove()};return{element:t,get brushCount(){return d},render(p){m=eo(p),g(m,p)},syncCamera(p){let h=eo(p);h!==m&&(m=h,g(h,p))},dispose(){for(let p of u)p.remove();t.classList.remove("polycss-voxel-mesh"),u.length=0,d=0,m=""}}}var oo="polycss-styles";function ro(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(oo))return;let t=n.createElement("style");t.id=oo,t.textContent=vs,n.head.appendChild(t)}var vs=`
|
|
1
|
+
"use strict";var yo=Object.defineProperty;var as=Object.getOwnPropertyDescriptor;var ls=Object.getOwnPropertyNames;var cs=Object.prototype.hasOwnProperty;var ds=(e,n)=>{for(var t in n)yo(e,t,{get:n[t],enumerable:!0})},us=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of ls(n))!cs.call(e,r)&&r!==t&&yo(e,r,{get:()=>n[r],enumerable:!(o=as(n,r))||o.enumerable});return e};var ps=e=>us(yo({},"__esModule",{value:!0}),e);var Bl={};ds(Bl,{PolyAxesHelperElement:()=>dn,PolyBoxElement:()=>xn,PolyCameraElement:()=>yn,PolyConeElement:()=>Ln,PolyCylinderElement:()=>wn,PolyDirectionalLightHelperElement:()=>un,PolyDodecahedronElement:()=>An,PolyFirstPersonControlsElement:()=>hn,PolyIcosahedronElement:()=>Tn,PolyIframeElement:()=>ln,PolyMapControlsElement:()=>fn,PolyMeshElement:()=>xt,PolyOctahedronElement:()=>Cn,PolyOrbitControlsElement:()=>mn,PolyOrthographicCameraElement:()=>Pt,PolyPerspectiveCameraElement:()=>gn,PolyPlaneElement:()=>Pn,PolyPolygonElement:()=>cn,PolyRingElement:()=>Sn,PolySceneElement:()=>_e,PolySelectElement:()=>vn,PolySphereElement:()=>Mn,PolyTetrahedronElement:()=>En,PolyTorusElement:()=>_n,PolyTransformControlsElement:()=>bn});module.exports=ps(Bl);var ne=require("@layoutit/polycss-core");var or=require("@layoutit/polycss-core");function ms(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 Qt(e,n,t){return(0,or.packTextureAtlasPlansWithScaleCore)(e,n,ms(t))}var It=require("@layoutit/polycss-core");var rt=require("@layoutit/polycss-core"),cr=require("@layoutit/polycss-core"),dr=require("@layoutit/polycss-core"),Tt=new Map;function fs(e){let n=Tt.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}),Tt.set(e,n),n.then(()=>{Tt.get(e)===n&&Tt.delete(e)},()=>{Tt.get(e)===n&&Tt.delete(e)})),n}function Ie(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 bo(e){let n=e/255;return n<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function vo(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 hs(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]=vo(bo(f[v])*b),f[v+1]=vo(bo(f[v+1])*y),f[v+2]=vo(bo(f[v+2])*P));e.putImageData(x,c,l)}function gs(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;Ie(e,s),e.drawImage(n,t+(r-g)/2,o+(i-x)/2,g,x)}function At(e,n){return Math.max(0,Math.min(n,e))}function rr(e,n,t,o,r,i,s,c){let l=n.naturalWidth||n.width||1,p=n.naturalHeight||n.height||1,g=At(Math.min(t.minU,t.maxU)*l,l),x=At(Math.max(t.minU,t.maxU)*l,l),f=At(Math.min(t.minV,t.maxV)*p,p),b=At(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(At((t.minU+t.maxU)/2*l,l-1)),v=1),C<1&&(P=Math.floor(At((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)),Ie(e,c),e.drawImage(n,y,P,v,C,o,r,i,s)}function ur(e){return e==="repeat"||e==="mirrored-repeat"}function ir(e,n){return ur(e)?Math.floor(n):0}function sr(e,n){return ur(e)?Math.ceil(n)-1:0}function ar(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function lr(e,n,t,o,r,i,s){let c=r?ir(i,r.minU):0,l=r?sr(i,r.maxU):0,p=r?ir(s,r.minV):0,g=r?sr(s,r.maxV):0;for(let x=c;x<=l;x++)for(let f=p;f<=g;f++){let b=ar(i,x),y=ar(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 xo(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 Dn(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 ys(e,n,t,o){Ie(e,o),e.beginPath(),xo(e,n.x,n.y,n.screenPts),e.clip(),Ie(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function On(e,n,t,o,r){n.polygon.textureAlphaMode==="opaque"&&(Ie(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+r,n.canvasW,n.canvasH))}function bs(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=(0,cr.expandClipPoints)(l.screenPts,rt.TEXTURE_TRIANGLE_BLEED*(n.bleedRatio??1));e.save(),Ie(e,o),e.beginPath(),Dn(e,n.x,n.y,p,r,i),e.clip(),On(e,n,o,r,i),l.uvAffine?(Ie(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),lr(e,t,s,c,l.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t)):l.uvSampleRect&&rr(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(),Ie(e,o),e.beginPath(),Dn(e,n.x,n.y,n.screenPts,r,i),e.clip(),On(e,n,o,r,i)),Ie(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),lr(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(),Ie(e,o),e.beginPath(),Dn(e,n.x,n.y,n.screenPts,r,i),e.clip(),On(e,n,o,r,i)),rr(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(),Ie(e,o),e.beginPath(),Dn(e,n.x,n.y,n.screenPts,r,i),e.clip(),On(e,n,o,r,i)),gs(e,t,n.x+r,n.y+i,n.canvasW,n.canvasH,o),s&&e.restore()}}function vs(e,n,t,o,r,i){let s=r-t,c=i-o,l=s*s+c*c;if(l<=dr.BASIS_EPS)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 xs(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,vs(e,n,t[c],t[c+1],t[l],t[l+1]))}return r}function Ps(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]<rt.TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN||(g=C,x=v)}return g}function Ss(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(rt.TEXTURE_EDGE_REPAIR_RADIUS,rt.TEXTURE_EDGE_REPAIR_RADIUS/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<rt.TEXTURE_EDGE_REPAIR_ALPHA_MIN||C===255)continue;let F=(r+P+.5)/t-n.x,k=(i+y+.5)/t-n.y;if(xs(F,k,n.screenPts,n.textureEdgeRepairEdges)>x)continue;let z=Ps(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 Cs(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 Es(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 fs(g))}));for(let g of e.entries){let x=g.texture?l.get(g.texture):null;if(!g.texture){s.save(),ys(s,g,n,o),s.restore();continue}x&&(s.save(),Ie(s,o),s.beginPath(),xo(s,g.x,g.y,g.screenPts),s.clip(),bs(s,g,x,o),s.restore()),g.texture&&n==="baked"&&(s.save(),Ie(s,o),s.beginPath(),xo(s,g.x,g.y,g.screenPts),s.clip(),hs(s,g.x,g.y,g.canvasW,g.canvasH,g.textureTint,o),s.restore()),Ss(s,g,o)}let p=await Cs(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:p}}async function qt(e,n,t,o,r){let i=[];for(let s of e){if(r())break;i.push(await Es(s,n,t,o))}return i}var J=require("@layoutit/polycss-core"),Hn=require("@layoutit/polycss-core"),mr=require("@layoutit/polycss-core");var pr=require("@layoutit/polycss-core");function Mt(e,n){let o=e?.defaultView?.__polycssProjectiveQuadGuards,r=n&&o?{...n,...o}:o??n;return(0,pr.resolveProjectiveQuadGuards)(r)}function Kt(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 fr(e){if(hr(e))return!0;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,J.safariCssProjectiveUnsupported)(t):!0}function Jt(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 hr(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 Ts(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function Je(e,n){return n?.disable?.includes("u")?null:hr(e)?"corner-bevel":fr(e)?Ts(e)?"border-large":"border":null}function en(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,J.safariCssProjectiveUnsupported)(t):!0}function In(e,n,t,o,r){let i=new Set(o?.disable??[]);return(0,J.getSolidPaintDefaultsForPlansCore)(e,n,i,{solidTriangleSupported:fr(t),projectiveQuadSupported:en(t),cornerShapeSupported:Jt(t),borderShapeSupported:Kt(t)},Hn.parseHex,Hn.rgbKey,r)}var Te=require("@layoutit/polycss-core"),Ue=require("@layoutit/polycss-core");var Dt=require("@layoutit/polycss-core");var st=require("@layoutit/polycss-core"),gr=require("@layoutit/polycss-core");var wt=require("@layoutit/polycss-core");function Ee(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 ct(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 tn(e,n,t,o=!1){if(n==="dynamic"){let r=(0,wt.parseHex)(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(0,wt.rgbKey)(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 As(e,n){Ee(e,"--pnx",n.normal[0].toFixed(4)),Ee(e,"--pny",n.normal[1].toFixed(4)),Ee(e,"--pnz",n.normal[2].toFixed(4))}function Lt(e,n,t,o){if(t==="dynamic"){ct(e,"color"),ct(e,"background"),As(e,n);let r=(0,wt.parseHex)(n.polygon.color??"#cccccc");(0,wt.rgbKey)(r)===o?.dynamicColorKey?(ct(e,"--psr"),ct(e,"--psg"),ct(e,"--psb")):(Ee(e,"--psr",(r.r/255).toFixed(4)),Ee(e,"--psg",(r.g/255).toFixed(4)),Ee(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(ct(e,"background"),Ee(e,"color",n.shadedColor)):(ct(e,"background"),ct(e,"color"))}var _t=require("@layoutit/polycss-core"),it=require("@layoutit/polycss-core"),Fn=require("@layoutit/polycss-core"),ot=require("@layoutit/polycss-core"),yr="polycss-corner-shape-solid",Po=new WeakMap,So=new WeakMap;function Pe(e,n,t){let o=Po.get(e),r=So.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?Po.set(e,c):Po.delete(e),s.size>0?So.set(e,s):So.delete(e),e.__polycssHasDataAttrs=c.length>0}function Rt(e){return e.__polycssHasDataAttrs===!0}function Co(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=(0,it.atlasCanonicalSizeForEntry)(o),p=`${(0,st.formatCssLength)(-o.x/s*l)} ${(0,st.formatCssLength)(-o.y/c*l)}`,g=`${(0,st.formatCssLength)(n.width/s*l)} ${(0,st.formatCssLength)(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 br(e,n,t,o){if(n.texture){if(!t.texture||n.texture!==t.texture)return!1}else if(t.texture)return!1;let r=vr(n,t);return r?(e.style.visibility="",Ee(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(Ee(e,"--pnx",r.normal[0].toFixed(4)),Ee(e,"--pny",r.normal[1].toFixed(4)),Ee(e,"--pnz",r.normal[2].toFixed(4))),Pe(e,t,n.index),!0):(e.style.visibility="hidden",Pe(e,t,n.index),!0)}function Eo(e,n,t,o,r){if(o!=="baked")return{...e,polygon:n,normal:t};let i=r.directionalLight,s=r.ambientLight,c=i?.direction??ot.DEFAULT_LIGHT_DIR,l=i?.color??ot.DEFAULT_LIGHT_COLOR,p=Math.max(0,i?.intensity??ot.DEFAULT_LIGHT_INTENSITY),g=s?.color??ot.DEFAULT_AMBIENT_COLOR,x=Math.max(0,s?.intensity??ot.DEFAULT_AMBIENT_INTENSITY),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:(0,gr.shadePolygon)(n.color??"#cccccc",C,l,g,x)}}function vr(e,n){let t=xr(e,n);if(!t)return null;let{normal:o,xAxis:r,yAxis:i,tx:s,ty:c,tz:l}=t;return{normal:o,matrix:(0,st.formatMatrix3dValues)([r[0]*e.canvasW/(0,it.atlasCanonicalSizeForEntry)(e),r[1]*e.canvasW/(0,it.atlasCanonicalSizeForEntry)(e),r[2]*e.canvasW/(0,it.atlasCanonicalSizeForEntry)(e),0,i[0]*e.canvasH/(0,it.atlasCanonicalSizeForEntry)(e),i[1]*e.canvasH/(0,it.atlasCanonicalSizeForEntry)(e),i[2]*e.canvasH/(0,it.atlasCanonicalSizeForEntry)(e),0,o[0],o[1],o[2],0,s,c,l,1])}}var xr=Fn.stableBasisFromPlan;function Ms(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=xr(e,n);if(!o)return null;let r=(0,Fn.computeProjectiveQuadMatrix)(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return r?{matrix:r,normal:o.normal}:null}function To(e,n,t,o,r=!1){let i=t.createElement("b");return i.setAttribute("style",`transform:matrix3d(${(0,st.formatSolidQuadMatrix)(e)})`+tn(e,n,o,r)),Pe(i,e.polygon,e.index),i}function Ao(e,n,t,o,r=!1){let i=t.createElement("i");return i.setAttribute("style",(0,_t.formatBorderShapeElementStyle)(e)+tn(e,n,o,r)),Pe(i,e.polygon,e.index),i}function Mo(e,n,t,o,r,i=!1){let s=o.createElement("u");return s.className=yr,s.setAttribute("style",(0,_t.formatCornerShapeElementStyle)(e,n)+tn(e,t,r,i)),Pe(s,e.polygon,e.index),s}function wo(e,n,t,o,r=!1){let i=t.createElement("b");return i.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+tn(e,n,o,r)),Pe(i,e.polygon,e.index),i}function Pr(e,n,t,o,r,i,s){let c=n.projectiveMatrix?Ms(n,t,i):vr(n,t);if(!c)return!1;let l=Eo(n,t,c.normal,o,r);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,Lt(e,l,o,s),Pe(e,l.polygon,l.index),!0}function Sr(e,n,t,o){e.style.visibility="",e.setAttribute("style",(0,_t.formatBorderShapeElementStyle)(n)),Lt(e,n,t,o),Pe(e,n.polygon,n.index)}function Cr(e,n,t,o,r){e.style.visibility="",e.className=yr,e.setAttribute("style",(0,_t.formatCornerShapeElementStyle)(n,t)),Lt(e,n,o,r),Ee(e,"background","currentColor"),Pe(e,n.polygon,n.index)}function Lo(e,n,t,o=!1){let r=t.createElement("s"),i=(0,it.atlasCanonicalSizeForEntry)(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),Pe(r,e.polygon,e.index),r}var Rr=require("@layoutit/polycss-core");var Vn=require("@layoutit/polycss-core");function gt(e,n,t,o={}){let r=o.primitive!=null?void 0:(()=>{let i=t.doc??(typeof document<"u"?document:null);return i?Je(i,t.strategies)??"border":"border"})();return(0,Vn.computeSolidTrianglePlan)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??r})}function _o(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?Je(y,t.strategies)??"border":"border"})();return(0,Vn.computeSolidTrianglePlanFromCssPoints)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??b},r,i,s,c,l,p,g,x,f)}var yt=require("@layoutit/polycss-core"),dt=require("@layoutit/polycss-core"),Er=require("@layoutit/polycss-core");var Ro=require("@layoutit/polycss-core");var ws="0 48px 96px 48px";function Tr(e,n){return(0,yt.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function Ar(e,n,t){let o=(0,yt.resolveBleedRatio)(t.seamBleed),r=yt.DEFAULT_SEAM_BLEED*o,i={...t,bleedRatio:o};return n&&r>0?{...i,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:i}function ko(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 Mr(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function kt(e,n,t,o,r,i){return t?i.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:r==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:Mr(n,i):!0}function Do(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"?ws:""),t.__polycssSolidTrianglePrimitive=n)}function Oo(e){let n=e;n.__polycssSolidTriangleHidden&&(e.style.visibility="",n.__polycssSolidTriangleHidden=!1)}function nn(e){let n=e;n.__polycssSolidTriangleHidden||(e.style.visibility="hidden",n.__polycssSolidTriangleHidden=!0)}function Bn(e,n){e.setAttribute("style",n.styleText),Do(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||Rt(e))&&Pe(e,n.polygon)}function wr(e,n,t,o){if(!n.colorComputed){(n.polygon.data||Rt(e))&&Pe(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??Mr(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=(0,dt.stepRgbToward)(p,s,t.maxStep);b=y,f=(0,dt.rgbToCss)(y,c)}(f!==l||!(0,dt.rgbEqual)(b,p))&&(e.style.color=f),r.__polycssSolidTriangleColor=f,r.__polycssSolidTriangleColorRgb=b,r.__polycssSolidTriangleColorAlpha=c,r.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||Rt(e))&&Pe(e,n.polygon)}function zn(e,n,t,o){let r=e;Do(e,n.primitive),r.__polycssSolidTriangleBasis!==n.basis&&(r.__polycssSolidTriangleBasis=n.basis),Oo(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||Rt(e))&&wr(e,n,t,o)}function Ho(e,n,t,o){Oo(e),wr(e,n,t,o)}function Nn(e,n){let t=e;Do(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),Oo(e),e.style.transform=n.transformText,(n.polygon.data||Rt(e))&&Pe(e,n.polygon)}function Ls(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 Lr(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=Ls(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=(0,dt.colorErrorScore)(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 Gn(e,n){let t=n.createElement("u");return Bn(t,e),Pe(t,e.polygon,e.index),t}function _s(e,n,t){let o=t.createElement("u");return nn(o),Pe(o,e,n),o}function _r(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=(0,Ro.stableTriangleMatrixDecimals)(s.stableTriangleMatrixDecimals),g=t.doc??(typeof document<"u"?document:null),x=g?Je(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=Tr(n,t);for(let b=0;b<e.length;b++){let y=e[b].element,P=n[b];if(l){if(kt(y,b,o,c,s.stableTriangleColorPolicy,i)){let C=(0,Er.computeSolidTriangleColorPlan)(P,b,t);if(!C)continue;Ho(y,C,i)}continue}let v=gt(P,b,Ar(b,f,t),{basis:y.__polycssSolidTriangleBasis,matrixDecimals:p,primitive:x,includeColor:r!=="plan-only"&&r!=="transform-only"&&kt(y,b,o,c,s.stableTriangleColorPolicy,i)});if(!v){nn(y);continue}o&&r==="plan-only"||(o&&r==="transform-only"?Nn(y,v):o?zn(y,v,i):Bn(y,v))}return!0}function on(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=Je(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let r=(0,Ro.stableTriangleMatrixDecimals)(n.stableTriangleMatrixDecimals),i=[],s=Tr(e,n);for(let c=0;c<e.length;c+=1){let l=e[c],p=gt(l,c,Ar(c,s,n),{matrixDecimals:r,primitive:o}),g=p?Gn(p,t):_s(l,c,t);i.push({polygonIndex:c,element:g,kind:"triangle",dispose:()=>{}})}return{rendered:i,dispose(){}}}var Fo=require("@layoutit/polycss-core");function kr(){return new Promise(e=>setTimeout(e,0))}async function Io(e){return performance.now()-e<Te.ASYNC_RENDER_BUDGET_MS?e:(await kr(),performance.now())}function Dr(e,n){let t=(0,Te.resolveBleedRatio)(n.seamBleed),o=Te.DEFAULT_SEAM_BLEED*t,r={...n,bleedRatio:t};return e.seamBleedEdges?.size&&o>0?{...r,seamBleed:o,seamEdges:e.seamBleedEdges}:{...r,seamBleed:void 0,seamEdges:void 0}}function Or(e,n){return(0,Ue.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function Hr(e,n,t){let o=(0,Te.resolveBleedRatio)(t.seamBleed),r=Te.DEFAULT_SEAM_BLEED*o,i={...t,bleedRatio:o};return n&&r>0?{...i,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:i}function Ot(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=(0,Ue.buildBasisHints)(e,n),r=Mt(t),i=e.map((s,c)=>(0,Ue.computeTextureAtlasPlan)(s,c,n,r,o[c]));return In(i,n.textureLighting??"baked",t,n.strategies)}function Ht(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&&en(t),p=Je(t,n.strategies),g=p!==null,x=!s.has("i")&&Jt(t),f=!s.has("i")&&Kt(t),b=(0,Ue.buildBasisHints)(e,n),y=Mt(t),P=Or(e,n),v=e.map((u,d)=>(0,Ue.computeTextureAtlasPlan)(u,d,Hr(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?In(v,o,t,n.strategies):void 0),F=C?{...n,solidPaintDefaults:C}:n,k=v.map(u=>u&&g&&(0,J.isSolidTrianglePlan)(u)?gt(u.polygon,u.index,Dr(u,F),{primitive:p??void 0}):null),z=v.map(u=>u&&x&&!(0,J.isSolidTrianglePlan)(u)&&!(c&&(0,J.isFullRectSolid)(u))&&!(l&&(0,J.isProjectiveQuadPlan)(u))?(0,Dt.cornerShapeGeometryForPlan)(u):null),O=v.map((u,d)=>u&&(u.texture||!(c&&(0,J.isFullRectSolid)(u))&&!k[d]&&!(l&&(0,J.isProjectiveQuadPlan)(u))&&!z[d]&&!f?u:null)),{packed:Z,atlasScale:q}=Qt(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=Lo(R,o,t,i);D.set(u,L),H.push({polygonIndex:u,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!d.texture&&c&&(0,J.isFullRectSolid)(d)){let L=To(d,o,t,C,i);H.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&T){let L=Gn(T,t);H.push({polygonIndex:u,element:L,kind:"triangle",plan:d,dispose:()=>{}})}else if(!d.texture&&l&&(0,J.isProjectiveQuadPlan)(d)){let L=wo(d,o,t,C,i);H.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&w){let L=Mo(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=qt(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||Co(L,w,o,R,!0)}}}).catch(()=>{if(!V)for(let u of D.values())Ee(u,"opacity","0.5"),Ee(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 $n(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&&en(o),g=Je(o,n.strategies),x=g!==null,f=!c.has("i")&&Jt(o),b=!c.has("i")&&Kt(o);if(await kr(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let y=(0,Ue.buildBasisHints)(e,n),P=Mt(o),v=Or(e,n),C=performance.now(),F=new Array(e.length);for(let u=0;u<e.length;u++)if(F[u]=(0,Ue.computeTextureAtlasPlan)(e[u],u,Hr(u,v,n),P,y[u]),C=await Io(C),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let k=n.solidPaintDefaults??In(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&&(0,J.isSolidTrianglePlan)(d)?gt(d.polygon,d.index,Dr(d,{...n,solidPaintDefaults:k}),{primitive:g??void 0}):null;z[u]=T;let w=d&&f&&!(0,J.isSolidTrianglePlan)(d)&&!(l&&(0,J.isFullRectSolid)(d))&&!(p&&(0,J.isProjectiveQuadPlan)(d))?(0,Dt.cornerShapeGeometryForPlan)(d):null;if(O[u]=w,Z[u]=d&&(d.texture||!(l&&(0,J.isFullRectSolid)(d))&&!T&&!(p&&(0,J.isProjectiveQuadPlan)(d))&&!w&&!b?d:null),C=await Io(C),t())return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}let{packed:q,atlasScale:D}=Qt(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=Lo(R,r,o,s);H.set(u,L),V.push({polygonIndex:u,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!d.texture&&l&&(0,J.isFullRectSolid)(d)){let L=To(d,r,o,k,s);V.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&T){let L=Gn(T,o);V.push({polygonIndex:u,element:L,kind:"triangle",plan:d,dispose:()=>{}})}else if(!d.texture&&p&&(0,J.isProjectiveQuadPlan)(d)){let L=wo(d,r,o,k,s);V.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&w){let L=Mo(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 Io(C),t()){for(let L of V)L.dispose();return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}}V.sort((u,d)=>u.polygonIndex-d.polygonIndex);let h=qt(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||Co(L,w,r,R,!0)}}}).catch(()=>{if(!(G||t()))for(let u of H.values())Ee(u,"opacity","0.5"),Ee(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 Un(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=(0,Fo.stableTriangleMatrixDecimals)(i.stableTriangleMatrixDecimals),g=ko(i),x=o.tileSize??Te.DEFAULT_TILE,f=o.layerElevation??x,b=o.doc??(typeof document<"u"?document:null),y=b?Je(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=_o(F,v,o,{basis:C.__polycssSolidTriangleBasis,matrixDecimals:p,primitive:y,color:t.colors?.[v],includeColor:l!=="plan-only"&&l!=="transform-only"&&kt(C,v,s,c,i.stableTriangleColorPolicy,g)},z,O,Z,q,D,H,V,G,A);if(!h){nn(C);continue}l!=="plan-only"&&(l==="transform-only"?Nn(C,h):zn(C,h,g))}return!0}function jn(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&&en(r),p=!!r&&!s.has("i")&&Jt(r),g=!!r&&!s.has("i")&&Kt(r),x=(0,Te.resolveBleedRatio)(o.seamBleed),f=r?Mt(r,{bleed:Te.PROJECTIVE_QUAD_BLEED*x}):{denomEps:Te.PROJECTIVE_QUAD_DENOM_EPS,maxWeightRatio:Te.PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,bleed:Te.PROJECTIVE_QUAD_BLEED*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=ko(o),F=(0,Fo.stableTriangleMatrixDecimals)(o.stableTriangleMatrixDecimals),k=r?Je(r,t.strategies)??"border":"border";if(_r(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||!br(H.element,H.plan,V,i))return!1;continue}if(H.kind==="triangle"){let G=H.element;if(v){let h=o.stableTriangleColorPolicy==="adaptive"||kt(G,D,b,y,o.stableTriangleColorPolicy,C);O[D]=h?(0,Rr.computeSolidTriangleColorPlan)(V,D,t):null;continue}let A=gt(V,D,t,{basis:G.__polycssSolidTriangleBasis,matrixDecimals:F,primitive:k,includeColor:P!=="plan-only"&&P!=="transform-only"&&kt(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=(0,Ue.computeTextureAtlasPlan)(V,D,t,f);if(!G||G.texture||!g||c&&(0,J.isFullRectSolid)(G)||l&&(0,J.isProjectiveQuadPlan)(G)||p&&(0,Dt.cornerShapeGeometryForPlan)(G))return!1;Z[D]=G;continue}if(H.kind==="corner"){let G=(0,Ue.computeTextureAtlasPlan)(V,D,t,f);if(!G||G.texture||!p||(0,J.isSolidTrianglePlan)(G)||c&&(0,J.isFullRectSolid)(G)||l&&(0,J.isProjectiveQuadPlan)(G)||!(0,Dt.cornerShapeGeometryForPlan)(G))return!1;Z[D]=G;continue}return!1}let q=b&&P!=="plan-only"&&P!=="transform-only"?Lr(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&&Ho(H.element,G,C,q?.has(D));continue}let V=z[D];if(!V){nn(H.element);continue}if(b&&P==="plan-only")continue;b&&P==="transform-only"?Nn(H.element,V):b?zn(H.element,V,C,q?.has(D)):Bn(H.element,V)}else if(H.kind==="solid"){let V=Z[D];if(!V||!Pr(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?(0,Dt.cornerShapeGeometryForPlan)(V):null;if(!V||!G)return!1;Cr(H.element,V,G,i,o.solidPaintDefaults)}}return!0}var Ir=require("@layoutit/polycss-core"),Ft=require("@layoutit/polycss-core"),Wn=require("@layoutit/polycss-core");var ee=require("@layoutit/polycss-core"),Is=[.4,-.7,.59],Fs="#ffffff",Vs=1,Bs="#ffffff",zs=.4,Gr=1,Ns=8,Gs=ee.PROJECTIVE_QUAD_BLEED,at=1e-6,$s=(0,ee.resolveProjectiveQuadGuards)({bleed:0}),$r={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},zo=["t","b","bl","br","fr","fl"],Us=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 Fr(e){let n=[];for(let t of zo)(0,ee.normalFacesCamera)($r[t],e)&&n.push(t);return n.join("|")}function js(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 Ws(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 Ys(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=Ws(e),t=n?Us.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=ea(e.color);return Math.abs(l-i)<=p?{axis:"z",face:t,left:r*ee.BASE_TILE,top:o*ee.BASE_TILE,width:Math.max(0,(c-r)*ee.BASE_TILE),height:Math.max(0,(s-o)*ee.BASE_TILE),z:i*ee.BASE_TILE,baseColor:g,bleed:Vo()}:Math.abs(s-o)<=p?{axis:"x",face:t,left:r*ee.BASE_TILE,top:i*ee.BASE_TILE,width:Math.max(0,(c-r)*ee.BASE_TILE),height:Math.max(0,(l-i)*ee.BASE_TILE),z:-o*ee.BASE_TILE,baseColor:g,bleed:Vo()}:Math.abs(c-r)<=p?{axis:"y",face:t,left:i*ee.BASE_TILE,top:o*ee.BASE_TILE,width:Math.max(0,(l-i)*ee.BASE_TILE),height:Math.max(0,(s-o)*ee.BASE_TILE),z:-r*ee.BASE_TILE,baseColor:g,bleed:Vo()}:null}function Vo(){return{left:0,right:0,top:0,bottom:0}}function Xs(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 Vr(e){return[e[1]*ee.BASE_TILE,e[0]*ee.BASE_TILE,e[2]*ee.BASE_TILE]}function Br(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function Zs(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])<=at){if(Math.abs(n[0]-o)<=at)return"left";if(Math.abs(n[0]-r)<=at)return"right"}if(Math.abs(n[1]-t[1])<=at){if(Math.abs(n[1]-i)<=at)return"top";if(Math.abs(n[1]-s)<=at)return"bottom"}return null}function Qs(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=at)){if(t!==null)return null;t=o}return t}function qs(e,n,t){let o=n.vertices,r=Vr(o[t]),i=Vr(o[(t+1)%o.length]),s=Zs(e,Br(e,r),Br(e,i));if(!s)return null;let c=Qs(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>at?{item:e,side:s,variableAxis:c,fixed:r,start:l,end:p}:null}function zr(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],Gs)}function Ks(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=qs(o,r,i);if(!s)continue;let c=Xs(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+at);for(let s of r)s.item.sourceIndex!==i.item.sourceIndex&&(zr(s),zr(i));r.push(i)}}}function Js(e){let n=(0,ee.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha}:{r:255,g:255,b:255,alpha:1}}function ea(e){if(!e)return"#cccccc";let n=(0,ee.parsePureColor)(e);if(!n)return e;let t={r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha};if(t.alpha<1){let o=Math.round(Math.max(0,t.alpha)*1e3)/1e3;return`rgba(${Bo(t.r)}, ${Bo(t.g)}, ${Bo(t.b)}, ${o})`}return ta(t)}function ta({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 Bo(e){return Math.round(Math.max(0,Math.min(255,e)))}function na(e,n,t,o){let r=t?.direction??Is,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??Vs)*Math.max(0,e[0]*s+e[1]*c+e[2]*l),g=Math.max(0,o?.intensity??zs),x=t?.color??Fs,f=o?.color??Bs,b=(0,ee.shadePolygon)(n,p,x,f,g),y=Js(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 oa(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=Ys(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return Ks(e,n),n}function ra(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 ia(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 sa(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function aa(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(r=>!Number.isFinite(r)))return null;let o=ee.SOLID_QUAD_CANONICAL_SIZE/n;for(let r=0;r<8;r+=1)t[r]*=o;return`matrix3d(${t.map(r=>Number(r.toFixed(6))).join(",")})`}function Nr(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 la(e,n){let{xAxis:t,yAxis:o,normal:r,tx:i,ty:s,tz:c}=ra(e),l=(0,ee.computeProjectiveQuadMatrix)(ia(e),t,o,r,i,s,c,$s,sa(e));return l?aa(l,n)??Nr(e,n):Nr(e,n)}function ca(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function da(e){return ca(e)?Ns:Gr}function ua(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 pa(e,n){let t=ua(e),o=n.meshRotation;o&&(t=(0,ee.rotateVec3InWrapperCssFrame)(t,o));let[r,i]=(0,ee.rotateVec3)(t,n.rotX,0,n.rotY);return{x:r,y:i}}function ma(e,n,t){let o=e.filter(f=>n.has(f.face)).map(f=>({item:f,...pa(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 Ur(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:i}=e,s=oa(o);if(s.length===0)return null;let c=new Set(s.map(h=>h.face));t.classList.add("polycss-voxel-mesh");let l=da(n);l!==Gr&&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=na($r[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),js(u,g(h.face,h.baseColor),la(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 zo)c.has(h)&&O(h,y.get(h)??[])},q=h=>new Set(h.split("|").filter(Boolean)),D=h=>{let u=q(h);return zo.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 re=T+1;re<h.length;re+=1){let _=f.get(h[re]);if(_?.parentNode===t){L=_;break}}t.insertBefore(R,L??z())}C=d},A=(h,u,d)=>{if(!d){let re=D(h);G(re,!1),v=H(re);return}let T=new Set(h.split("|").filter(Boolean)),w=ma(s,T,u),{orderedFaces:R,itemsByFace:L}=V(w);for(let re of R)O(re,L.get(re)??[]);G(R,!0),v=w.length};return Z(),{get brushCount(){return v},render(h){P=Fr(h),A(P,h,!0)},syncCamera(h){let u=Fr(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 jr="polycss-styles";function Wr(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(jr))return;let t=n.createElement("style");t.id=jr,t.textContent=fa,n.head.appendChild(t)}var fa=`
|
|
2
2
|
/* \u2500\u2500 Scene container \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
3
3
|
|
|
4
4
|
.polycss-scene,
|
|
@@ -8,6 +8,18 @@
|
|
|
8
8
|
box-sizing: border-box;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/* Camera wrapper (mounted by createPolyCamera / PolyPerspectiveCamera /
|
|
12
|
+
PolyOrthographicCamera). Fills its parent so the scene inside has a
|
|
13
|
+
positioned, sized layout context for its top: 50% / left: 50% pin to
|
|
14
|
+
resolve against. Inline styles win on specificity if the user sizes
|
|
15
|
+
the camera explicitly. */
|
|
16
|
+
.polycss-camera {
|
|
17
|
+
position: relative;
|
|
18
|
+
display: block;
|
|
19
|
+
width: 100%;
|
|
20
|
+
height: 100%;
|
|
21
|
+
}
|
|
22
|
+
|
|
11
23
|
.polycss-scene {
|
|
12
24
|
position: absolute;
|
|
13
25
|
top: 50%;
|
|
@@ -15,7 +27,6 @@
|
|
|
15
27
|
width: 0;
|
|
16
28
|
height: 0;
|
|
17
29
|
transform-style: preserve-3d;
|
|
18
|
-
perspective: 8000px;
|
|
19
30
|
/* Pin the scene as a composited layer. Without this, mobile Chrome
|
|
20
31
|
re-rasterizes every descendant tile when the scene transform changes
|
|
21
32
|
each animation frame, which overruns the raster budget on textured
|
|
@@ -26,8 +37,8 @@
|
|
|
26
37
|
|
|
27
38
|
/* \u2500\u2500 First-person controls perspective context \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
28
39
|
|
|
29
|
-
/* PolyFirstPersonControls toggles this class on
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 Ps=750,Es=8e3;var ft=65,ht=45,As=1,ke=ee.BASE_TILE;function Ms(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let r of t)if(!o.includes(r))return!1;return!0}function so(e){let n=[];return e.position&&n.push(`translate3d(${e.position[0]}px, ${e.position[1]}px, ${e.position[2]}px)`),e.scale!==void 0&&(typeof e.scale=="number"?e.scale!==1&&n.push(`scale3d(${e.scale}, ${e.scale}, ${e.scale})`):n.push(`scale3d(${e.scale[0]}, ${e.scale[1]}, ${e.scale[2]})`)),e.rotation&&(e.rotation[0]&&n.push(`rotateX(${e.rotation[0]}deg)`),e.rotation[1]&&n.push(`rotateY(${e.rotation[1]}deg)`),e.rotation[2]&&n.push(`rotateZ(${e.rotation[2]}deg)`)),n.length>0?n.join(" "):void 0}function Cs(e,n=[0,0,0],t=1){let o=e.rotX??ft,r=e.rotY??ht,s=(e.zoom??As)*t,i=(e.distance??0)*t,l=e.target??[0,0,0],a=l[0]+n[0],u=l[1]+n[1],m=l[2]+n[2],d=u*ke,f=a*ke,g=m*ke;return`${i!==0?`translateZ(${-i}px) `:""}scale(${s}) rotateX(${o}deg) rotate(${r}deg) translate3d(${-d}px, ${-f}px, ${-g}px)`}function Ss(e){let n=e.trim();if(!n||n==="normal")return 1;let t=n.endsWith("%")?Number(n.slice(0,-1))/100:Number(n);return Number.isFinite(t)&&t>0?t:1}function ws(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=Ss(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function on(e,n){return n===1?e:e*n}function Ts(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}var Ls=.1;function _s(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let d=1;d+1<e.vertices.length;d++){let f=e.vertices[d],g=e.vertices[d+1],p=f[1]-n[1],h=f[0]-n[0],b=f[2]-n[2],x=g[1]-n[1],A=g[0]-n[0],M=g[2]-n[2];t-=h*M-b*A,o-=b*x-p*M,r-=p*A-h*x}let s=Math.hypot(t,o,r);if(s<1e-9)return null;t/=s,o/=s,r/=s;let i=1/Ls,l=Math.round(t*i)/i,a=Math.round(o*i)/i,u=Math.round(r*i)/i,m=Math.hypot(l,a,u);return m<1e-9?null:{key:l+","+a+","+u,vec:[l/m,a/m,u/m]}}function io(e,n={}){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");e.ownerDocument&&ro(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let t={...n},o=ws(e),r=[0,0,0],s=e.ownerDocument??document,i=s.createElement("div");i.className="polycss-scene",i.setAttribute("aria-hidden","true"),a(i,t),e.appendChild(i);let l=new Set;function a(c,y){Ts(c,o),c.style.transform=Cs(y,r,o),typeof y.perspective=="number"?c.style.perspective=`${on(y.perspective,o)}px`:y.perspective===!1?c.style.perspective=`${on(1e6,o)}px`:Math.abs(o-1)<1e-6?c.style.removeProperty("perspective"):c.style.perspective=`${on(Es,o)}px`,u(c,y)}function u(c,y){let R=y.textureLighting==="dynamic";c.dataset.polycssLighting=y.textureLighting??"baked";let T=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"];if(!R){for(let fe of T)c.style.removeProperty(fe);return}let I=y.directionalLight?.direction??[.4,-.7,.59],D=Math.hypot(I[0],I[1],I[2])||1,z=I[0]/D,G=I[1]/D,te=I[2]/D,q=(0,ee.parseHexColor)(y.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],Q=(0,ee.parseHexColor)(y.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],W=y.directionalLight?.intensity??1,L=y.ambientLight?.intensity??.4,Z=fe=>(fe/255).toFixed(4);c.style.setProperty("--plx",z.toFixed(4)),c.style.setProperty("--ply",G.toFixed(4)),c.style.setProperty("--plz",te.toFixed(4)),c.style.setProperty("--plr",Z(q[0])),c.style.setProperty("--plg",Z(q[1])),c.style.setProperty("--plb",Z(q[2])),c.style.setProperty("--pli",W.toFixed(4)),c.style.setProperty("--par",Z(Q[0])),c.style.setProperty("--pag",Z(Q[1])),c.style.setProperty("--pab",Z(Q[2])),c.style.setProperty("--pai",L.toFixed(4));let F=te,K=Math.sign(F||1)*Math.max(Math.abs(F),.01);c.style.setProperty("--clx",z.toFixed(4)),c.style.setProperty("--cly",G.toFixed(4)),c.style.setProperty("--clz",K.toFixed(4))}function m(c){c.voxelRenderer?.dispose(),c.voxelRenderer=void 0,h(c.rendered,c.disposeAtlas),c.disposeAtlas=void 0,c.rendered.length=0,c.cameraCullGroups.length=0,c.cameraCullSignature="",p(c);for(let y of Array.from(c.wrapper.children))y instanceof HTMLElement&&y.classList.contains("polycss-bucket")&&y.remove()}function d(c){for(let y of Array.from(c.wrapper.childNodes)){if(!(y instanceof HTMLElement))return y;if(y.classList.contains("polycss-bucket")||y.classList.contains("polycss-shadow"))continue;let R=y.tagName.toLowerCase();if(!(R==="b"||R==="i"||R==="s"||R==="u"||R==="q"))return y}return null}function f(c,y,R){R?.parentNode===c.wrapper?c.wrapper.insertBefore(y,R):c.wrapper.appendChild(y)}function g(c){return Array.from(c.children).some(y=>y instanceof HTMLElement&&y.classList.contains("polycss-bucket"))}function p(c){for(let y of c.shadowRendered)y.parentNode&&y.parentNode.removeChild(y);c.shadowRendered.length=0}function h(c,y){y?.();for(let R of c){try{R.dispose()}catch{}R.element.parentNode&&R.element.parentNode.removeChild(R.element)}}function b(c){for(let y of Array.from(c.wrapper.children))y instanceof HTMLElement&&y.classList.contains("polycss-bucket")&&y.remove();for(let y of c.rendered)y.element.parentNode&&y.element.parentNode.removeChild(y.element)}function x(c,y){let R=c.polygons[y.polygonIndex];return c.stableDom&&R?(0,ee.polygonCssSurfaceNormal)(R):y.plan?.normal??(R?(0,ee.polygonCssSurfaceNormal)(R):null)}function A(c){if(!C(c))return c.rendered;let y=M(c);return c.rendered.filter(R=>P(c,R,ee.CAMERA_BACKFACE_CULL_EPS,y))}function M(c){return{rotX:t.rotX??ft,rotY:t.rotY??ht,meshRotation:c.handle.transform.rotation}}function P(c,y,R=ee.CAMERA_BACKFACE_CULL_EPS,T=M(c)){let I=x(c,y);return I===null||(0,ee.normalFacesCamera)(I,T,R)}function E(c){c.cameraCullGroups=(0,ee.cameraCullNormalGroups)(c.rendered.map(y=>x(c,y)))}function k(c){return C(c)?(0,ee.cameraCullVisibleSignature)(c.cameraCullGroups,M(c)):"all"}function C(c){return!c.excludeFromAutoCenter&&(0,ee.isVoxelCameraCullableNormalGroups)(c.cameraCullGroups)}function v(c){c.cameraCullSignature=C(c)?k(c):"all"}function B(c,y){let R=new Array(c.rendered.length),T=!1,I=M(c);for(let W=0;W<c.rendered.length;W+=1){let L=c.rendered[W],Z=P(c,L,y,I);R[W]=Z}let D=null,z=null,G=()=>{if(!(!D||!z)){if(D===z)D.remove();else{let W=s.createRange();W.setStartBefore(D),W.setEndAfter(z),W.deleteContents(),W.detach()}D=null,z=null,T=!0}};for(let W=0;W<c.rendered.length;W+=1){let L=c.rendered[W];!R[W]&&L.element.parentNode===c.wrapper?(z&&z.nextSibling===L.element||(G(),D=L.element),z=L.element):G()}G();let te=W=>{for(let L=W;L<c.rendered.length;L+=1){let Z=c.rendered[L].element;if(Z.parentNode===c.wrapper)return Z}return d(c)},q=-1,Q=W=>{if(q<0)return;let L=s.createDocumentFragment();for(let Z=q;Z<W;Z+=1){let F=c.rendered[Z];S(c,F),L.appendChild(F.element)}f(c,L,te(W)),q=-1,T=!0};for(let W=0;W<c.rendered.length;W+=1){let L=c.rendered[W];R[W]&&L.element.parentNode!==c.wrapper?q<0&&(q=W):Q(W)}return Q(c.rendered.length),T}function N(c,y=!1){if(c.voxelRenderer){c.voxelRenderer.syncCamera(M(c)),c.cameraCullSignature="voxel-direct";return}if(!C(c)){let I=c.cameraCullSignature!=="all";c.cameraCullSignature="all",I&&le(c);return}if(g(c.wrapper)){Y(c,y);return}let R=k(c);if(!y&&R===c.cameraCullSignature)return;let T=B(c,ee.CAMERA_BACKFACE_CULL_EPS);c.cameraCullSignature=R,T&&j(c)}function Y(c,y=!1){let R=C(c)?k(c):"all";!y&&R===c.cameraCullSignature||le(c)}function ne(c,y){return x(c,y)}function S(c,y){if(t.textureLighting!=="dynamic")return;let R=ne(c,y);R&&(y.element.style.setProperty("--pnx",R[0].toFixed(4)),y.element.style.setProperty("--pny",R[1].toFixed(4)),y.element.style.setProperty("--pnz",R[2].toFixed(4)))}function $(c){b(c);let y=s.createDocumentFragment(),R=t.textureLighting==="dynamic"&&!c.stableDom,T=new Map,I=[];for(let D of A(c)){let z=c.polygons[D.polygonIndex],G=R&&z?_s(z):null;if(!G){I.push(D);continue}let te=G.key+"|"+(z.color??""),q=T.get(te);q||(q={vec:G.vec,items:[]},T.set(te,q)),q.items.push(D)}for(let D of I)S(c,D),y.appendChild(D.element);for(let D of T.values()){if(D.items.length<2){for(let G of D.items)S(c,G),y.appendChild(G.element);continue}let z=s.createElement("div");z.className="polycss-bucket",z.style.setProperty("--pnx",String(D.vec[0])),z.style.setProperty("--pny",String(D.vec[1])),z.style.setProperty("--pnz",String(D.vec[2]));for(let G of D.items)z.appendChild(G.element),G.element.style.removeProperty("--pnx"),G.element.style.removeProperty("--pny"),G.element.style.removeProperty("--pnz");y.appendChild(z)}f(c,y,d(c)),v(c)}function w(){return new Promise(c=>setTimeout(c,0))}async function O(c,y){if(t.textureLighting==="dynamic"&&!c.stableDom)return $(c),!y();b(c);let T=s.createDocumentFragment(),I=d(c),D=0;for(let z of A(c)){if(y())return!1;S(c,z),T.appendChild(z.element),D++,D%Ps===0&&(f(c,T,I),T=s.createDocumentFragment(),await w())}return T.childNodes.length>0&&f(c,T,I),v(c),!y()}function H(c,y){let R=t.textureLighting==="dynamic",T=t.directionalLight?.direction,I=y&&(y[0]!==0||y[1]!==0||y[2]!==0);if(!R||!I||!T){if(c.lightOverrideSignature==="clear")return;c.wrapper.style.removeProperty("--plx"),c.wrapper.style.removeProperty("--ply"),c.wrapper.style.removeProperty("--plz"),c.lightOverrideSignature="clear";return}let D=(0,ee.inverseRotateVec3)(T,y),z=Math.hypot(D[0],D[1],D[2])||1,G=(D[0]/z).toFixed(4),te=(D[1]/z).toFixed(4),q=(D[2]/z).toFixed(4),Q=`${G}|${te}|${q}`;c.lightOverrideSignature!==Q&&(c.wrapper.style.setProperty("--plx",G),c.wrapper.style.setProperty("--ply",te),c.wrapper.style.setProperty("--plz",q),c.lightOverrideSignature=Q)}function V(c,y){y.paintColor?c.style.setProperty("--polycss-paint",y.paintColor):c.style.removeProperty("--polycss-paint"),y.dynamicColor?(c.style.setProperty("--psr",(y.dynamicColor.r/255).toFixed(4)),c.style.setProperty("--psg",(y.dynamicColor.g/255).toFixed(4)),c.style.setProperty("--psb",(y.dynamicColor.b/255).toFixed(4))):(c.style.removeProperty("--psr"),c.style.removeProperty("--psg"),c.style.removeProperty("--psb"))}function j(c){if(p(c),!c.castShadow||t.textureLighting!=="dynamic")return;let y=t.shadow?.color??"#000000",R=t.shadow?.opacity??.25,T=(0,ee.parseHexColor)(y)?.rgb??[0,0,0],I=T[0],D=T[1],z=T[2],G=`rgba(${I},${D},${z},${R})`,te=(0,ee.findOverlappingPolygonDuplicates)(c.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.4}),q=s.createDocumentFragment();for(let W of A(c)){if(te.has(W.polygonIndex))continue;let L=W.plan;if(!L)continue;let Z=`matrix3d(${L.matrix})`,F=s.createElement("q");F.className="polycss-shadow",F.style.transform=`var(--shadow-proj) ${Z}`,F.style.color=G,F.style.width=`${L.canvasW}px`,F.style.height=`${L.canvasH}px`,F.style.setProperty("border-shape",Un(L)),F.style.setProperty("--pnx",L.normal[0].toFixed(4)),F.style.setProperty("--pny",L.normal[1].toFixed(4)),F.style.setProperty("--pnz",L.normal[2].toFixed(4)),q.appendChild(F),c.shadowRendered.push(F)}let Q=c.wrapper.firstChild;Q?c.wrapper.insertBefore(q,Q):c.wrapper.appendChild(q)}function le(c){if(c.voxelRenderer){c.voxelRenderer.render(M(c)),c.cameraCullSignature="voxel-direct";return}p(c),$(c),j(c)}function _(c){return!!c.voxelSource&&t.textureLighting!=="dynamic"&&!c.stableDom&&!c.castShadow}function X(c,y){m(c);let R=t.directionalLight,T=y?{...R,direction:y}:R;if(_(c)){let te=no({doc:s,wrapper:c.wrapper,polygons:c.parseResult.polygons,directionalLight:T,ambientLight:t.ambientLight});if(te){c.voxelRenderer=te,te.render(M(c)),c.cameraCullSignature="voxel-direct";return}}let I={doc:s,directionalLight:T,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality,strategies:t.strategies},D=pt(c.polygons,I);V(c.wrapper,D);let z={...I,solidPaintDefaults:D},G=(c.stableDom?en(c.polygons,z):null)??qn(c.polygons,z);c.rendered=G.rendered,c.disposeAtlas=G.dispose,E(c),$(c),j(c)}function U(){if(t.textureLighting!=="dynamic"){i.style.removeProperty("--shadow-ground-cssz");return}let c=1/0;for(let T of l)if(!T.disposed&&T.castShadow)for(let I of T.polygons)for(let D of I.vertices)D[2]<c&&(c=D[2]);if(!Number.isFinite(c)){i.style.removeProperty("--shadow-ground-cssz");return}let y=t.shadow?.lift??.05,R=(c+y)*ke;i.style.setProperty("--shadow-ground-cssz",R.toFixed(3))}async function re(c,y){m(c);let R={doc:s,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality,strategies:t.strategies},T=c.stableDom?en(c.polygons,R):null;if(T){let z=pt(c.polygons,R);return V(c.wrapper,z),c.rendered=T.rendered,c.disposeAtlas=T.dispose,E(c),$(c),j(c),!y()}let I=await Qn(c.polygons,R,y);if(y())return I.dispose(),!1;V(c.wrapper,I.solidPaintDefaults),c.rendered=I.rendered,c.disposeAtlas=I.dispose,E(c);let D=await O(c,y);return D&&j(c),D}function se(){let c=r,y=[0,0,0];if(t.autoCenter){let R=[];for(let T of l)!T.disposed&&!T.excludeFromAutoCenter&&R.push(...T.polygons);if(R.length>0){let T=(0,ee.computeSceneBbox)(R);y=[(T.min[0]+T.max[0])/2,(T.min[1]+T.max[1])/2,(T.min[2]+T.max[2])/2]}}c[0]===y[0]&&c[1]===y[1]&&c[2]===y[2]||(r=y,a(i,t))}function ue(c,y={}){let T=(i.ownerDocument??document).createElement("div");T.className="polycss-mesh",y.id&&T.setAttribute("data-poly-mesh-id",y.id);let I={...y},D=y.merge!==!1,z=!!y.stableDom,G=0,te=so(I);te&&(T.style.transform=te);let q=(F,K)=>K?(0,ee.mergePolygons)(F):F,Q=q(c.polygons,D);function W(F){if(F.length===0){T.style.removeProperty("--origin");return}let K=1/0,fe=1/0,Ae=1/0,Te=-1/0,rt=-1/0,_t=-1/0;for(let ko of F)for(let ve of ko.vertices)ve[0]<K&&(K=ve[0]),ve[0]>Te&&(Te=ve[0]),ve[1]<fe&&(fe=ve[1]),ve[1]>rt&&(rt=ve[1]),ve[2]<Ae&&(Ae=ve[2]),ve[2]>_t&&(_t=ve[2]);if(!Number.isFinite(K)){T.style.removeProperty("--origin");return}let Lo=(fe+rt)/2*ke,_o=(K+Te)/2*ke,Ro=(Ae+_t)/2*ke;T.style.setProperty("--origin",`${Lo}px ${_o}px ${Ro}px`)}W(Q),i.appendChild(T);let L={handle:void 0,wrapper:T,parseResult:c,rendered:[],shadowRendered:[],polygons:Q,voxelSource:c.voxelSource,disposed:!1,stableDom:z,excludeFromAutoCenter:!!y.excludeFromAutoCenter,castShadow:!!y.castShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",bakedRotation:y.rotation?[...y.rotation]:[0,0,0]},Z={polygons:Q,element:T,id:y.id,get transform(){return I},remove(){G++,T.parentNode&&T.parentNode.removeChild(T),m(L),l.delete(L),se(),U()},setPolygons(F,K){G++,D=K?.merge??D,z=K?.stableDom??z,L.stableDom=z,L.voxelSource=void 0,L.polygons=q(F,D),Z.polygons=L.polygons,W(L.polygons);let fe=K?.recomputeAutoCenter??!0;if(L.stableDom&&!g(L.wrapper)){let Ae={doc:s,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality},Te=pt(L.polygons,Ae);if(V(L.wrapper,Te),Jn(L.rendered,L.polygons,{...Ae,solidPaintDefaults:Te})){E(L),N(L,!0),fe&&se();return}}X(L),fe&&se()},updatePolygon(F,K){let fe=typeof F=="number"?F:L.polygons.indexOf(F);fe<0||fe>=L.polygons.length||(L.voxelSource=void 0,Object.assign(L.polygons[fe],K),X(L))},async setPolygonsChunked(F,K){let fe=++G;D=K?.merge??D,z=K?.stableDom??z,L.stableDom=z,L.voxelSource=void 0,L.polygons=q(F,D),Z.polygons=L.polygons,W(L.polygons);let Ae=K?.recomputeAutoCenter??!0;if(!await re(L,()=>L.disposed||fe!==G)){m(L);return}Ae&&se()},setTransform(F){let K=L.castShadow;F.castShadow!==void 0&&(L.castShadow=!!F.castShadow),I={...I,...F};let fe=so(I);T.style.transform=fe??"",H(L,I.rotation),F.rotation!==void 0&&N(L),L.castShadow!==K&&(j(L),U())},dispose(){if(!L.disposed){L.disposed=!0,G++,T.parentNode&&T.parentNode.removeChild(T),m(L);try{c.dispose()}catch{}l.delete(L),se(),U()}},rebakeAtlas(){L.bakedRotation=I.rotation?[...I.rotation]:[0,0,0];let F=t.directionalLight?.direction??[.4,-.7,.59],K=(0,ee.inverseRotateVec3)(F,L.bakedRotation);X(L,K)},getPosition(){return I.position},getRotation(){return I.rotation},getScale(){return I.scale},getPolygons(){return Z.polygons}};return L.handle=Z,l.add(L),X(L),H(L,I.rotation),se(),U(),Z}function he(c){let y=!!t.autoCenter,R=t.strategies,T=t.textureLighting,I=t.rotX??ft,D=t.rotY??ht;t={...t,...c},a(i,t);let z=!!t.autoCenter;for(let Q of l)H(Q,Q.handle.transform.rotation);let G=c.strategies!==void 0&&!Ms(c.strategies,R);if(G)for(let Q of l)X(Q);let te=c.rotX!==void 0&&(t.rotX??ft)!==I||c.rotY!==void 0&&(t.rotY??ht)!==D;if(!G&&te)for(let Q of l)N(Q);if(y!==z&&se(),c.textureLighting!==void 0&&T!==t.textureLighting){for(let Q of l)!G&&(Q.voxelSource||Q.voxelRenderer)?X(Q):j(Q);U()}}function de(){return t}function me(){let c=[];for(let y of l)c.push(y.handle);return c}function ge(c){let y=c;for(;y;){if(y instanceof HTMLElement&&y.classList.contains("polycss-mesh")){for(let R of l)if(R.wrapper===y)return R.handle;return null}y=y.parentElement}return null}function be(){let c=Array.from(l);for(let y of c)try{y.handle.dispose()}catch{}i.parentNode&&i.parentNode.removeChild(i)}return{add:ue,setOptions:he,destroy:be,host:e,getOptions:de,meshes:me,findMeshByElement:ge}}var Rs=typeof HTMLElement<"u"?HTMLElement:class{},ks=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function De(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Ds(e){return e==="false"?!1:De(e)}function Os(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Is(e){if(e==="baked"||e==="dynamic")return e}function Hs(e){return e==="auto"?"auto":De(e)}var xe=class extends Rs{constructor(){super(...arguments);this._scene=null}static get observedAttributes(){return[...ks]}getScene(){return this._scene}_readOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={},s=Ds(this.getAttribute("perspective"));s!==void 0&&(r.perspective=s);let i=De(this.getAttribute("rot-x"));i!==void 0&&(r.rotX=i);let l=De(this.getAttribute("rot-y"));l!==void 0&&(r.rotY=l);let a=De(this.getAttribute("zoom"));a!==void 0&&(r.zoom=a),r.textureLighting=Is(this.getAttribute("texture-lighting"))??"baked";let u=Hs(this.getAttribute("texture-quality"));return u!==void 0&&(r.textureQuality=u),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=Os(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=De(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let s={direction:t??[.4,-.7,.59]};return o&&(s.color=o),r!==void 0&&(s.intensity=r),s}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=De(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){this._scene||(this._scene=io(this,this._readOptions()),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1})))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null)}attributeChangedCallback(t,o,r){o!==r&&this._scene&&this._scene.setOptions(this._readOptions())}};var gt=require("@layoutit/polycss-core"),Vs=typeof HTMLElement<"u"?HTMLElement:class{},zs=["src","mtl","position","scale","rotation","auto-center"];function Ge(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function ao(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Ge(e)}}function Fs(e){return e.closest("poly-scene")??null}function Bs(e){if(e.length===0)return e;let n=(0,gt.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s),...i.textureTriangles?.length?{textureTriangles:i.textureTriangles.map(l=>({...l,vertices:l.vertices.map(s)}))}:null}))}var Oe=class extends Vs{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...zs]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:Ge(this.getAttribute("position")),scale:ao(this.getAttribute("scale")),rotation:Ge(this.getAttribute("rotation"))})}}_tearDown(){if(this._loadToken+=1,this._handle){try{this._handle.dispose()}catch{}this._handle=null}this._parseResult=null}async _maybeLoad(){let t=this.getAttribute("src");if(!t)return;let o=Fs(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,i;try{i=await(0,gt.loadMesh)(t,s?{mtlUrl:s}:void 0)}catch(u){this.dispatchEvent(new CustomEvent("polycss:error",{detail:u,bubbles:!0}));return}if(r!==this._loadToken){try{i.dispose()}catch{}return}let l=o.getScene();if(!l){try{i.dispose()}catch{}return}this.hasAttribute("auto-center")&&(i={...i,polygons:Bs(i.polygons)}),this._parseResult=i,this._handle=l.add(i,{position:Ge(this.getAttribute("position")),scale:ao(this.getAttribute("scale")),rotation:Ge(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var Ns=typeof HTMLElement<"u"?HTMLElement:class{},$s=["vertices","color","texture","uvs","position","scale","rotation"];function lo(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function rn(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Xs(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return rn(e)}}function Ys(e){return e.closest("poly-scene")??null}var We=class extends Ns{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...$s]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=Ys(this);if(!t)return;let o=t.getScene();if(!o)return;let r=lo(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let s=this.getAttribute("color")||void 0,i=this.getAttribute("texture")||void 0,l=lo(this.getAttribute("uvs"))??void 0,a={};for(let d of Array.from(this.attributes))d.name.startsWith("data-")&&(a[d.name.slice(5)]=d.value);let m={polygons:[{vertices:r,...s!==void 0?{color:s}:{},...i!==void 0?{texture:i}:{},...l!==void 0?{uvs:l}:{},...Object.keys(a).length>0?{data:a}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(m,{position:rn(this.getAttribute("position")),scale:Xs(this.getAttribute("scale")),rotation:rn(this.getAttribute("rotation"))})}};var uo=require("@layoutit/polycss-core"),Us=typeof HTMLElement<"u"?HTMLElement:class{},Gs=["size","thickness","negative","x-color","y-color","z-color"];function Ws(e){return e.closest("poly-scene")??null}function co(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var je=class extends Us{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Gs]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&this._handle&&this._remount()}_polygons(){return(0,uo.axesHelperPolygons)({size:co(this.getAttribute("size")),thickness:co(this.getAttribute("thickness")),negative:this.hasAttribute("negative"),xColor:this.getAttribute("x-color")??void 0,yColor:this.getAttribute("y-color")??void 0,zColor:this.getAttribute("z-color")??void 0})}_mount(){let t=Ws(this);if(!t)return;let o=t.getScene();if(!o)return;let r={polygons:this._polygons(),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(r,{excludeFromAutoCenter:!0})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var fo=require("@layoutit/polycss-core"),js=typeof HTMLElement<"u"?HTMLElement:class{},Zs=["direction","target","distance","size","color"],sn=50,qs=5,Qs=.35,Ks="#ffd54a";function Js(e){return e.closest("poly-scene")??null}function mo(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function po(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var Ze=class extends js{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Zs]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="size"||t==="color"){this._remount();return}this._handle.setTransform({position:this._meshPosition()})}}_meshPosition(){let t=mo(this.getAttribute("direction"));if(!t)return;let o=mo(this.getAttribute("target"))??[0,0,0],r=po(this.getAttribute("distance"),qs),s=t[0],i=t[1],l=t[2],a=Math.hypot(s,i,l)||1,u=o[0]+i/a*r,m=o[1]+s/a*r,d=o[2]+l/a*r;return[m*sn,u*sn,d*sn]}_mount(){let t=Js(this);if(!t)return;let o=t.getScene();if(!o)return;let r=po(this.getAttribute("size"),Qs),s=this.getAttribute("color")??Ks,i={polygons:(0,fo.octahedronPolygons)({center:[0,0,0],size:r,color:s}),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(i,{position:this._meshPosition(),excludeFromAutoCenter:!0})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var ho=require("@layoutit/polycss-core");var yt={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Ne(e,n){let t;return n.animate===!1?t=!1:n.animate?t={speed:n.animate.speed??.3,axis:n.animate.axis??"y",pauseOnInteraction:n.animate.pauseOnInteraction??!0}:t=e.animate,{drag:n.drag??e.drag,wheel:n.wheel??e.wheel,dolly:n.dolly??e.dolly,invert:n.invert??e.invert,minZoom:n.minZoom??e.minZoom,maxZoom:n.maxZoom??e.maxZoom,minDistance:n.minDistance??e.minDistance,maxDistance:n.maxDistance??e.maxDistance,animate:t}}function qe(e){return e===!0?-1:e===!1?1:e}function bt(){let e=[],n=[],t=[];function o(i){return i==="change"?e:i==="start"?n:t}function r(i){if(e.length===0)return;let l={type:"change",camera:i()},a=e.slice();for(let u of a)try{u(l)}catch(m){console.error("[polycss] controls 'change' listener threw:",m)}}function s(i,l){let a=i==="start"?n:t;if(a.length===0)return;let u={type:i,camera:l()},m=a.slice();for(let d of m)try{d(u)}catch(f){console.error(`[polycss] controls '${i}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function xt(e){return()=>{let n=e.getOptions(),t=n.target??[0,0,0];return{rotX:n.rotX??0,rotY:n.rotY??0,zoom:n.zoom??1,target:[t[0],t[1],t[2]],distance:n.distance??0}}}function vt(e,n,t,o,r,s){let i=!1,l=null;return{onWheel:m=>{let d=n();if(!d.wheel||t())return;m.preventDefault();let f=m.deltaMode===1?16:m.deltaMode===2?100:1,g=m.deltaY*f;m.ctrlKey?g*=10:g*=3;let p=e.getOptions();if(d.dolly){let h=p.distance??0,b=Math.max(d.minDistance,Math.min(d.maxDistance,h+g*.05));e.setOptions({distance:b})}else{let h=Math.exp(-g*513e-6),b=p.zoom??1,x=Math.max(d.minZoom,Math.min(d.maxZoom,b*h));e.setOptions({zoom:x})}i||(i=!0,s("start",o)),r(o),l!==null&&clearTimeout(l),l=setTimeout(()=>{l=null,i=!1,s("end",o)},150)},teardown:()=>{l!==null&&(clearTimeout(l),l=null),i=!1}}}function Pt(e,n,t,o,r,s,i){let l=null,a=0,u=g=>{if(l===null||o())return;let p=t();if(!p.animate){l=null;return}if(r())a=g;else{let h=Math.min(50,a?g-a:16.67);a=g;let b=p.animate.speed*(h/16.67),x=n.getOptions();if(p.animate.axis==="x"){let A=(((x.rotX??65)+b)%360+360)%360;n.setOptions({rotX:A})}else{let A=(((x.rotY??45)+b)%360+360)%360;n.setOptions({rotY:A})}i(s)}l=e.requestAnimationFrame(u)};return{start:()=>{l!==null||!t().animate||o()||(a=0,l=e.requestAnimationFrame(u))},stop:()=>{l!==null&&(e.cancelAnimationFrame(l),l=null)},isRunning:()=>l!==null}}function go(e,n={}){let t=Ne(yt,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},l=!1,a=!1,u=bt(),m=xt(e),{changeListeners:d,startListeners:f,endListeners:g,listenerArray:p,emitChange:h,emitInteraction:b}=u,x=Pt(r,e,()=>t,()=>a,()=>l,m,h),A=w=>{if(!(!t.drag||a)&&s===null&&w.isPrimary!==!1){w.preventDefault(),s=w.pointerId,i={x:w.clientX,y:w.clientY},o.style.cursor="grabbing";try{w.target.setPointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!0),b("start",m)}},M=w=>{if(s===null||w.pointerId!==s||!t.drag||a)return;w.preventDefault();let O=w.clientX-i.x,H=w.clientY-i.y;i={x:w.clientX,y:w.clientY};let V=qe(t.invert),j=O/4*V,le=H/4*V,_=e.getOptions();if(w.shiftKey){let X=_.rotX??65,U=_.rotY??45,re=Math.max(.01,_.zoom??1),se=Math.cos(X*Math.PI/180),ue=se>=0?Math.max(.1,se):Math.min(-.1,se),he=Math.cos(U*Math.PI/180),de=Math.sin(U*Math.PI/180),me=re*ho.BASE_TILE,ge=(O*de-H*he/ue)/me,be=-(O*he+H*de/ue)/me,c=_.target??[0,0,0];e.setOptions({target:[c[0]+ge,c[1]+be,c[2]]})}else{let X=Math.max(0,Math.min(100,(_.rotX??65)-le)),U=(((_.rotY??45)-j)%360+360)%360;e.setOptions({rotX:X,rotY:U})}h(m)},P=w=>{if(s===w.pointerId){s=null,o.style.cursor=t.drag&&!a?"grab":"";try{w.target.releasePointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!1),b("end",m)}},E=vt(e,()=>t,()=>a,m,h,b);function k(){o.addEventListener("pointerdown",A),o.addEventListener("pointermove",M),o.addEventListener("pointerup",P),o.addEventListener("pointercancel",P),o.addEventListener("wheel",E.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function C(){o.removeEventListener("pointerdown",A),o.removeEventListener("pointermove",M),o.removeEventListener("pointerup",P),o.removeEventListener("pointercancel",P),o.removeEventListener("wheel",E.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",E.teardown()}k(),x.start();function v(w){let O=!!t.animate;t=Ne(t,w),!a&&s===null&&(o.style.cursor=t.drag?"grab":"");let H=!!t.animate;O&&!H?x.stop():!O&&H&&x.start()}function B(){a&&(a=!1,k(),x.start())}function N(){a||(a=!0,C(),x.stop(),s=null,l=!1,E.teardown())}function Y(){N(),d.length=0,f.length=0,g.length=0}function ne(w,O){let H=p(w);H.includes(O)||H.push(O)}function S(w,O){let H=p(w),V=H.indexOf(O);V>=0&&H.splice(V,1)}function $(w,O){return p(w).includes(O)}return{update:v,resume:B,pause:N,destroy:Y,addEventListener:ne,removeEventListener:S,hasEventListener:$}}function ie(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Et(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function we(e){if(e!==null)return!(e==="false"||e==="0")}function At(e){if(e===null)return;if(e==="true")return!0;if(e==="false")return!1;let n=parseFloat(e);return Number.isFinite(n)?n:!0}function Mt(e){if(e==="x"||e==="y")return e}var ei=typeof HTMLElement<"u"?HTMLElement:class{},ti=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Qe=class extends ei{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...ti]}_readAnimate(){let t=ie(this.getAttribute("animate-speed")),o=Mt(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:we(r)}:{}}}_readOptions(){let t={},o=we(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=we(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ie(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ie(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let l=At(this.getAttribute("invert"));l!==void 0&&(t.invert=l);let a=ie(this.getAttribute("zoom-min")),u=ie(this.getAttribute("zoom-max"));return a!==void 0&&(t.minZoom=a),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof xe)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=go(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var yo=require("@layoutit/polycss-core");function bo(e,n={}){let t=Ne(yt,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},l=!1,a=!1,u=!1,m={x:0,y:0},d=bt(),f=xt(e),{changeListeners:g,startListeners:p,endListeners:h,listenerArray:b,emitChange:x,emitInteraction:A}=d,M=Pt(r,e,()=>t,()=>a,()=>l,f,x),P=_=>{if(!(!t.drag||a)&&s===null&&_.isPrimary!==!1){_.preventDefault(),s=_.pointerId,i={x:_.clientX,y:_.clientY},o.style.cursor="grabbing";try{_.target.setPointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!0),A("start",f)}},E=_=>{if(s===null||_.pointerId!==s||!t.drag||a)return;_.preventDefault();let X=_.clientX-i.x,U=_.clientY-i.y;i={x:_.clientX,y:_.clientY};let re=e.getOptions();if(_.shiftKey){let se=qe(t.invert),ue=X/4*se,he=U/4*se,de=Math.max(0,Math.min(100,(re.rotX??65)-he)),me=(((re.rotY??45)-ue)%360+360)%360;e.setOptions({rotX:de,rotY:me})}else{let se=re.rotX??65,ue=re.rotY??45,he=Math.max(.01,re.zoom??1),de=Math.cos(se*Math.PI/180),me=de>=0?Math.max(.1,de):Math.min(-.1,de),ge=Math.cos(ue*Math.PI/180),be=Math.sin(ue*Math.PI/180),c=he*yo.BASE_TILE,y=(X*be-U*ge/me)/c,R=-(X*ge+U*be/me)/c,T=re.target??[0,0,0];e.setOptions({target:[T[0]+y,T[1]+R,T[2]]})}x(f)},k=_=>{if(s===_.pointerId){s=null,o.style.cursor=t.drag&&!a?"grab":"";try{_.target.releasePointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(l=!1),A("end",f)}},C=_=>{_.preventDefault()},v=_=>{_.button===2&&(u=!0,m={x:_.clientX,y:_.clientY},t.animate&&t.animate.pauseOnInteraction&&(l=!0),A("start",f))},B=_=>{if(!u||!t.drag)return;let X=_.clientX-m.x,U=_.clientY-m.y;m={x:_.clientX,y:_.clientY};let re=qe(t.invert),se=X/4*re,ue=U/4*re,he=e.getOptions(),de=Math.max(0,Math.min(100,(he.rotX??65)-ue)),me=(((he.rotY??45)-se)%360+360)%360;e.setOptions({rotX:de,rotY:me}),x(f)},N=_=>{_.button===2&&u&&(u=!1,A("end",f))},Y=vt(e,()=>t,()=>a,f,x,A);function ne(){o.addEventListener("pointerdown",P),o.addEventListener("pointermove",E),o.addEventListener("pointerup",k),o.addEventListener("pointercancel",k),o.addEventListener("wheel",Y.onWheel,{passive:!1}),o.addEventListener("contextmenu",C),o.addEventListener("mousedown",v),o.addEventListener("mousemove",B),o.addEventListener("mouseup",N),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function S(){o.removeEventListener("pointerdown",P),o.removeEventListener("pointermove",E),o.removeEventListener("pointerup",k),o.removeEventListener("pointercancel",k),o.removeEventListener("wheel",Y.onWheel),o.removeEventListener("contextmenu",C),o.removeEventListener("mousedown",v),o.removeEventListener("mousemove",B),o.removeEventListener("mouseup",N),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",Y.teardown()}ne(),M.start();function $(_){let X=!!t.animate;t=Ne(t,_),!a&&s===null&&(o.style.cursor=t.drag?"grab":"");let U=!!t.animate;X&&!U?M.stop():!X&&U&&M.start()}function w(){a&&(a=!1,ne(),M.start())}function O(){a||(a=!0,S(),M.stop(),s=null,l=!1,u=!1,Y.teardown())}function H(){O(),g.length=0,p.length=0,h.length=0}function V(_,X){let U=b(_);U.includes(X)||U.push(X)}function j(_,X){let U=b(_),re=U.indexOf(X);re>=0&&U.splice(re,1)}function le(_,X){return b(_).includes(X)}return{update:$,resume:w,pause:O,destroy:H,addEventListener:V,removeEventListener:j,hasEventListener:le}}var ni=typeof HTMLElement<"u"?HTMLElement:class{},oi=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Ke=class extends ni{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...oi]}_readAnimate(){let t=ie(this.getAttribute("animate-speed")),o=Mt(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:we(r)}:{}}}_readOptions(){let t={},o=we(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=we(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ie(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ie(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let l=At(this.getAttribute("invert"));l!==void 0&&(t.invert=l);let a=ie(this.getAttribute("zoom-min")),u=ie(this.getAttribute("zoom-max"));return a!==void 0&&(t.minZoom=a),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof xe)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=bo(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var an=require("@layoutit/polycss-core"),ri=8e3;function ln(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,an.createIsometricCamera)(n),o=`${e.perspective??ri}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function xo(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,an.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var si=typeof HTMLElement<"u"?HTMLElement:class{},ii=["perspective","zoom","rot-x","rot-y","target","distance"],Je=class extends si{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...ii]}getCamera(){return this._camera}_readOptions(){return{perspective:ie(this.getAttribute("perspective")),zoom:ie(this.getAttribute("zoom")),rotX:ie(this.getAttribute("rot-x")),rotY:ie(this.getAttribute("rot-y")),target:Et(this.getAttribute("target")),distance:ie(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=ln(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let s=this._readOptions();this._camera=ln(s),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var ai=typeof HTMLElement<"u"?HTMLElement:class{},li=["zoom","rot-x","rot-y","target","distance"],et=class extends ai{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...li]}getCamera(){return this._camera}_readOptions(){return{zoom:ie(this.getAttribute("zoom")),rotX:ie(this.getAttribute("rot-x")),rotY:ie(this.getAttribute("rot-y")),target:Et(this.getAttribute("target")),distance:ie(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=xo(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let s=this._readOptions();s.zoom!==void 0&&this._camera.update({zoom:s.zoom}),s.rotX!==void 0&&this._camera.update({rotX:s.rotX}),s.rotY!==void 0&&this._camera.update({rotY:s.rotY}),s.target!==void 0&&this._camera.update({target:s.target}),s.distance!==void 0&&this._camera.update({distance:s.distance})}};var ye=require("@layoutit/polycss-core"),St="#ff3653",wt="#8adb00",Tt="#2c8fff",$e=50,vo=60,ci=.6,ui=.0125,di=.15,mi=.04,pi=1,Po=.02,cn=1.04,fi=.1,hi=.25,Co=1e-4,gi=.6,yi=.8,bi=1,tt={0:1,1:0,2:2},Eo=[{cssAxis:0,sign:1,key:"x",color:St},{cssAxis:0,sign:-1,key:"-x",color:St},{cssAxis:1,sign:1,key:"y",color:wt},{cssAxis:1,sign:-1,key:"-y",color:wt},{cssAxis:2,sign:1,key:"z",color:Tt},{cssAxis:2,sign:-1,key:"-z",color:Tt}],Ao=[{cssAxis:0,key:"x",color:St},{cssAxis:1,key:"y",color:wt},{cssAxis:2,key:"z",color:Tt}],Mo=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:Tt},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:wt},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:St}];function un(e,n,t,o){let r=t*Math.PI/180,s=o*Math.PI/180,i=[0,0,0];i[e]=n;let l=i[0]*Math.cos(s)-i[1]*Math.sin(s),a=i[0]*Math.sin(s)+i[1]*Math.cos(s),u=i[2];return a*Math.sin(r)+u*Math.cos(r)<0}function xi(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),s=parseInt(t[3],16);return`rgba(${o}, ${r}, ${s}, ${n})`}function Lt(e,n){return!n||n<=0?e:Math.round(e/n)*n}function vi(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let a of l.vertices)a[0]<n&&(n=a[0]),a[0]>r&&(r=a[0]),a[1]<t&&(t=a[1]),a[1]>s&&(s=a[1]),a[2]<o&&(o=a[2]),a[2]>i&&(i=a[2]);return Number.isFinite(n)?[(t+s)/2*$e,(n+r)/2*$e,(o+i)/2*$e]:[0,0,0]}function dn(e){if(e.length===0)return vo;let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let a of e)for(let u of a.vertices)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*$e*ci:vo}function Ct(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function Pi(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:l,translationSnap:a,onAxisDelta:u,onMouseDown:m,onMouseUp:d,onDraggingChanged:f}=e,g=o,p=[0,0,0];p[n]=t;let h=r.ownerDocument.createElement("div");h.style.position="absolute",h.style.left="0",h.style.top="0",h.style.width="0",h.style.height="0",h.style.transform=`translate3d(${p[0]*g}px, ${p[1]*g}px, ${p[2]*g}px)`,r.appendChild(h);let b=r.getBoundingClientRect(),x=h.getBoundingClientRect();r.removeChild(h);let A=(x.left-b.left)/g,M=(x.top-b.top)/g,P=A*A+M*M;if(P<Co)return;m?.(),f?.(!0);let E=C=>{let v=C.clientX-i,B=C.clientY-l,N=(v*A+B*M)/P;N=Lt(N,a),u(N,p)},k=()=>{window.removeEventListener("pointermove",E),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k);let C=v=>{v.stopPropagation(),v.stopImmediatePropagation()};window.addEventListener("click",C,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",C,!0),0),d?.(),f?.(!1)};window.addEventListener("pointermove",E),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)}function Ei(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:s,startClientY:i,translationSnap:l,onPlaneDelta:a,onMouseDown:u,onMouseUp:m,onDraggingChanged:d}=e,f=[0,0,0];f[n]=1;let g=[0,0,0];g[t]=1;function p(P){let E=r.ownerDocument.createElement("div");E.style.position="absolute",E.style.left="0",E.style.top="0",E.style.width="0",E.style.height="0",E.style.transform=`translate3d(${P[0]*o}px, ${P[1]*o}px, ${P[2]*o}px)`,r.appendChild(E);let k=r.getBoundingClientRect(),C=E.getBoundingClientRect();return r.removeChild(E),{x:(C.left-k.left)/o,y:(C.top-k.top)/o}}let h=p(f),b=p(g),x=h.x*b.y-b.x*h.y;if(Math.abs(x)<Co)return;u?.(),d?.(!0);let A=P=>{let E=P.clientX-s,k=P.clientY-i,C=(b.y*E-b.x*k)/x,v=(-h.y*E+h.x*k)/x;C=Lt(C,l),v=Lt(v,l),a(C,v,f,g)},M=()=>{window.removeEventListener("pointermove",A),window.removeEventListener("pointerup",M),window.removeEventListener("pointercancel",M);let P=E=>{E.stopPropagation(),E.stopImmediatePropagation()};window.addEventListener("click",P,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",P,!0),0),m?.(),d?.(!1)};window.addEventListener("pointermove",A),window.addEventListener("pointerup",M),window.addEventListener("pointercancel",M)}function Ai(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:l,onMouseDown:a,onMouseUp:u,onDraggingChanged:m}=e,d=t.getBoundingClientRect(),f=d.left,g=d.top,p=Math.atan2(s-g,r-f),h=0;a?.(),m?.(!0);let b=A=>{let M=Math.atan2(A.clientY-g,A.clientX-f),P=M-p;P>Math.PI?P-=2*Math.PI:P<-Math.PI&&(P+=2*Math.PI),h+=P,p=M;let E=h*180/Math.PI;E=Lt(E,i),l(E)},x=()=>{window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x);let A=M=>{M.stopPropagation(),M.stopImmediatePropagation()};window.addEventListener("click",A,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",A,!0),0),u?.(),m?.(!1)};window.addEventListener("pointermove",b),window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x)}function So(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,l=null,a=null,u=[0,0,0];function m(){if(!t)return[0,0,0];let S=t.transform.position??[0,0,0];return[S[0]+u[0],S[1]+u[1],S[2]+u[2]]}function d(S){return a===S?bi:l===S?yi:gi}function f(){for(let[S,$]of i){let w=g($.spec,d(S));$.handle.setPolygons(w,{recomputeAutoCenter:!1})}}function g(S,$){let O=dn(t?.polygons??[])*r,H=O/$e,V=xi(S.color,$);if(S.kind==="arrow"){let _=e.getOptions(),X=un(S.cssAxis,S.sign,_.rotX??65,_.rotY??45);return(0,ye.arrowPolygons)({axis:tt[S.cssAxis],sign:S.sign,shaftLength:H,shaftHalfThickness:H*ui,headLength:H*di,headHalfThickness:H*mi,color:V,shaft:!X})}if(S.kind==="plane"){let _=e.getOptions(),X=_.rotX??65,U=_.rotY??45,re=tt[S.perpAxis],se=(re+1)%3,ue=(re+2)%3,he=tt[se],de=tt[ue],me=un(he,1,X,U)?-1:1,ge=un(de,1,X,U)?-1:1,be=H*hi;return(0,ye.planePolygons)({axis:re,size:H*fi,offset:[me*be,ge*be],color:V})}let le=O*pi/$e*cn;return(0,ye.ringQuadPolygons)({axis:tt[S.cssAxis],outerRadius:le,color:V})}function p(S){return S.kind==="arrow"?"polycss-transform-arrow":S.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function h(){if(o==="translate"){let S=Eo.map(w=>({kind:"arrow",key:w.key,cssAxis:w.cssAxis,sign:w.sign,color:w.color})),$=Mo.map(w=>({kind:"plane",key:w.key,perpAxis:w.perpAxis,axisA:w.axisA,axisB:w.axisB,color:w.color}));return[...S,...$]}return o==="rotate"?Ao.map(S=>({kind:"ring",key:S.key,cssAxis:S.cssAxis,color:S.color})):[]}function b(){if(x(),!t)return;let S={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};function $(O){if(O.kind==="arrow"){let j=O.key.replace("-","")[0];return S[j]}if(O.kind==="ring")return S[O.key];let H=["x","y","z"][O.axisA],V=["x","y","z"][O.axisB];return S[H]&&S[V]}let w=m();for(let O of h()){if(!$(O))continue;let H=g(O,d(O.key)),V=e.add({polygons:H,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${O.key}`,position:w}),j=p(O);if(V.element.classList.add("polycss-transform-gizmo",j,`${j}--${O.key}`),O.kind==="ring"){let le=(1-Po)/cn,_=(1+Po)/cn;V.element.style.setProperty("--ring-inner-ratio",`${le}`),V.element.style.setProperty("--ring-outer-ratio",`${_}`)}i.set(O.key,{handle:V,spec:O})}}function x(){for(let{handle:S}of i.values())S.remove();i.clear(),l=null,a=null}function A(){if(!t)return;let S=m();for(let{handle:$}of i.values())$.setTransform({position:S})}function M(){t&&(i.size===0?b():A())}function P(S){if(t=S,!S){u=[0,0,0],x();return}u=vi(S.polygons),x(),b()}function E(){P(null)}function k(S){S!==o&&(o=S,t&&(x(),b()))}function C(S,$,w){if(!t||!v)return;let O=[v[0]+$*w[0],v[1]+$*w[1],v[2]+$*w[2]];t.setTransform({position:O}),A(),s.onObjectChange?.({object:t,position:O}),s.onChange?.()}let v=null,B=null,N=S=>{if(!t||s.enabled===!1)return;let $={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate"){for(let w of Mo){let O=["x","y","z"][w.axisA],H=["x","y","z"][w.axisB];if(!$[O]||!$[H])continue;let V=i.get(w.key);if(V&&Ct(V.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),a=w.key,f(),v=(t.transform.position??[0,0,0]).slice(),Ei({axisA:w.axisA,axisB:w.axisB,probeDistanceCss:dn(t.polygons)*r,wrapper:V.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,translationSnap:s.translationSnap??null,onPlaneDelta:(j,le,_,X)=>{if(!t||!v)return;let U=[v[0]+j*_[0]+le*X[0],v[1]+j*_[1]+le*X[1],v[2]+j*_[2]+le*X[2]];t.setTransform({position:U}),A(),s.onObjectChange?.({object:t,position:U}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:j=>{j||(a=null,v=null,f()),s.onDraggingChanged?.(j)}});return}}for(let w of Eo){let O=w.key.replace("-","")[0];if(!$[O])continue;let H=i.get(w.key);if(H&&Ct(H.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),a=w.key,f(),v=(t.transform.position??[0,0,0]).slice(),Pi({cssAxis:w.cssAxis,sign:w.sign,shaftLengthCss:dn(t.polygons)*r,wrapper:H.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(V,j)=>C(w,V,j),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:V=>{V||(a=null,v=null,f()),s.onDraggingChanged?.(V)}});return}}}else if(o==="rotate")for(let w of Ao){if(!$[w.key])continue;let O=i.get(w.key);if(O&&Ct(O.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),a=w.key,f(),B=(t.transform.rotation??[0,0,0]).slice(),Ai({cssAxis:w.cssAxis,wrapper:O.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:H=>{if(!t||!B)return;let V=w.cssAxis===0?-1:1,j=[0,0,0];j[w.cssAxis]=1;let le=H*V*Math.PI/180,_=(0,ye.quatFromEulerXYZ)(B),X=(0,ye.quatFromAxisAngle)(j,le),U=(0,ye.eulerXYZFromQuat)((0,ye.quatMultiply)(X,_));t.setTransform({rotation:U}),s.onObjectChange?.({object:t,rotation:U}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:H=>{H||(a=null,B=null,f(),t?.rebakeAtlas()),s.onDraggingChanged?.(H)}});return}}};e.host.addEventListener("pointerdown",N,{capture:!0});let Y=S=>{if(!t||a||s.enabled===!1)return;let $=null;for(let[w,O]of i)if(Ct(O.handle.element,S.clientX,S.clientY)){$=w;break}$!==l&&(l=$,f())};e.host.addEventListener("pointermove",Y);function ne(){e.host.removeEventListener("pointerdown",N,{capture:!0}),e.host.removeEventListener("pointermove",Y),x()}return{attach:P,detach:E,setMode:k,update:M,destroy:ne}}var Mi=typeof HTMLElement<"u"?HTMLElement:class{},Ci=["mode","target","size","enabled"];function wo(e){if(e==="translate"||e==="rotate")return e}var nt=class extends Mi{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Ci]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof xe)return t;t=t.parentNode}return null}_findTargetMesh(){let t=this.getAttribute("target");if(!t)return null;let o=this._findScene();if(!o)return null;let r=null;try{r=o.querySelector(`#${t}`)??o.querySelector(t)}catch{r=o.querySelector(`[id="${t}"]`)}return r instanceof Oe?r:null}_readOptions(){let t={},o=wo(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=ie(this.getAttribute("size"));r!==void 0&&(t.size=r);let s=this.getAttribute("enabled");return s!==null&&(t.enabled=s!=="false"&&s!=="0"),t.onObjectChange=i=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:i.position,rotation:i.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let s=()=>{t.removeEventListener("polycss:scene-ready",s),this._attach()};t.addEventListener("polycss:scene-ready",s)}return}this._tc=So(o,this._readOptions());let r=this._findTargetMesh();if(r){let s=r.getMeshHandle();s&&this._tc.attach(s)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,r){if(o!==r&&this._tc){if(t==="mode"){let s=wo(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};function Si(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function To(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let h of o)try{h(t)}catch(b){console.error("[polycss/createSelect] onChange threw:",b)}}function s(p){t=p,r()}function i(p){n.multiple?t.includes(p)||(t=[...t,p]):t=[p],r()}function l(p){t.includes(p)&&(t=t.filter(h=>h!==p),r())}function a(p){t.includes(p)?t=t.filter(h=>h!==p):n.multiple?t=[...t,p]:t=[p],r()}function u(){t.length!==0&&(t=[],r())}function m(p){return t.includes(p)}function d(p,h){for(let b of e.meshes())if(!b.element.classList.contains("polycss-transform-gizmo")&&Si(b.element,p,h))return b;return null}let f=p=>{let h=p.target;if(h?.closest(".polycss-transform-gizmo"))return;let b=e.findMeshByElement(h)??d(p.clientX,p.clientY);if(!b){n.onPointerMissed&&n.onPointerMissed(p),n.clearOnMiss!==!1&&u();return}n.multiple&&(p.shiftKey||p.metaKey||p.ctrlKey)?a(b):t.length===1&&t[0]===b?u():s([b])};e.host.addEventListener("click",f);function g(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:s,add:i,remove:l,toggle:a,clear:u,has:m,destroy:g}}var wi=typeof HTMLElement<"u"?HTMLElement:class{},Ti=["multiple","clear-on-miss"],ot=class extends wi{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Ti]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof xe)return t;t=t.parentNode}return null}_readOptions(){return{multiple:this.hasAttribute("multiple"),clearOnMiss:!this.hasAttribute("clear-on-miss")||this.getAttribute("clear-on-miss")!=="false",onChange:t=>{this.dispatchEvent(new CustomEvent("polycss:select",{bubbles:!0,detail:{selected:t}}))}}}_attach(){if(this._selection)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._selection=To(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};typeof customElements<"u"&&(customElements.get("poly-scene")||customElements.define("poly-scene",xe),customElements.get("poly-mesh")||customElements.define("poly-mesh",Oe),customElements.get("poly-polygon")||customElements.define("poly-polygon",We),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",je),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",Ze),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",Qe),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",Ke),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",Je),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",et),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",nt),customElements.get("poly-select")||customElements.define("poly-select",ot));0&&(module.exports={PolyAxesHelperElement,PolyDirectionalLightHelperElement,PolyMapControlsElement,PolyMeshElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPolygonElement,PolySceneElement,PolySelectElement,PolyTransformControlsElement});
|
|
519
|
+
`;var Yr=require("@layoutit/polycss-core"),ha=1,je=Yr.BASE_TILE,ga=.1;function ya(e){return[e[1]*je,e[0]*je,e[2]*je]}function Vt(e){return[e[1],e[0],e[2]]}function ut(e){return e?.direction?{...e,direction:Vt(e.direction)}:e}function Yn(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?ya(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 No(e,n=[0,0,0],t=1){let o=e.state,r=o.rotX,i=o.rotY,c=(o.zoom??ha)/je*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*je,y=g*je,P=f*je;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${r}deg) rotate(${i}deg) translate3d(${-b}px, ${-y}px, ${-P}px)`}function ba(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 Xr(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=ba(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function Zr(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}function Qr(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/ga,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 qr(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 Kr(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Jr(e,n){return e===n?!0:(e?.color??"#000000")===(n?.color??"#000000")&&(e?.opacity??.25)===(n?.opacity??.25)&&(e?.lift??.05)===(n?.lift??.05)&&(e?.maxExtend??2e3)===(n?.maxExtend??2e3)}var pt=require("@layoutit/polycss-core");var va=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"],Bt="--polycss-light-preview-active",ei=`var(${Bt}, 0)`,xa="max(0, calc(var(--pnx, 0) * var(--plx, 0) + var(--pny, 0) * var(--ply, 0) + var(--pnz, 1) * var(--plz, 1)))",Go=(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))`,Pa=Go("--psr","--par","--plr"),Sa=Go("--psg","--pag","--plg"),Ca=Go("--psb","--pab","--plb");function me(e,n,t){return e.style.getPropertyValue(n)===t?!1:(e.style.setProperty(n,t),!0)}function bt(e){for(let n of va)e.style.getPropertyValue(n)&&e.style.removeProperty(n)}function Xn(e,n){let t=n.directionalLight?.direction??[.4,-.7,.59],o=Vt(t),r=Math.hypot(o[0],o[1],o[2])||1,i=o[0]/r,s=o[1]/r,c=o[2]/r,l=(0,pt.parseHexColor)(n.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],p=(0,pt.parseHexColor)(n.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],g=n.directionalLight?.intensity??1,x=n.ambientLight?.intensity??.4,f=P=>(P/255).toFixed(4);me(e,"--plx",i.toFixed(2)),me(e,"--ply",s.toFixed(2)),me(e,"--plz",c.toFixed(2)),me(e,"--plr",f(l[0])),me(e,"--plg",f(l[1])),me(e,"--plb",f(l[2])),me(e,"--pli",g.toFixed(4)),me(e,"--par",f(p[0])),me(e,"--pag",f(p[1])),me(e,"--pab",f(p[2])),me(e,"--pai",x.toFixed(4));let b=c,y=Math.sign(b||1)*Math.max(Math.abs(b),.01);me(e,"--clx",i.toFixed(2)),me(e,"--cly",s.toFixed(2)),me(e,"--clz",y.toFixed(2))}function ti(e,n){let t=n.textureLighting==="dynamic";if(e.dataset.polycssLighting=n.textureLighting??"baked",!t){bt(e);return}Xn(e,n)}function vt(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 ni(e,n){let t=(0,pt.parseHex)(n??"#cccccc");e.style.setProperty("--psr",(t.r/255).toFixed(4)),e.style.setProperty("--psg",(t.g/255).toFixed(4)),e.style.setProperty("--psb",(t.b/255).toFixed(4))}function $o(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=t.textureLighting??"baked",r={directionalLight:ut(t.directionalLight),ambientLight:t.ambientLight,textureLighting:o,textureQuality:t.textureQuality,seamBleed:t.seamBleed,strategies:t.strategies},i=Eo(e.plan,n,e.plan.normal,o,r);return Lt(e.element,i,o),o==="baked"&&Ta(e.element),!0}function Ea(e){let n=(0,pt.parsePureColor)(e)??{rgb:[255,255,255],alpha:1},[t,o,r]=n.rgb,i=(c,l)=>`calc(${c} * (1 - ${ei}) + var(${l}, ${c}) * ${ei})`,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 oi(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=e.element,r=e.plan.normal,i=(0,pt.parseHex)(n.color??"#cccccc"),s=!1;return s=me(o,"--pnx",r[0].toFixed(4))||s,s=me(o,"--pny",r[1].toFixed(4))||s,s=me(o,"--pnz",r[2].toFixed(4))||s,s=me(o,"--psr",(i.r/255).toFixed(4))||s,s=me(o,"--psg",(i.g/255).toFixed(4))||s,s=me(o,"--psb",(i.b/255).toFixed(4))||s,s=me(o,"--plam",xa)||s,s=me(o,"--polycss-preview-r",Pa)||s,s=me(o,"--polycss-preview-g",Sa)||s,s=me(o,"--polycss-preview-b",Ca)||s,s=me(o,"--polycss-paint",Ea(t))||s,o.style.getPropertyValue("color")&&(o.style.removeProperty("color"),s=!0),s}function Ta(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 Aa="http://www.w3.org/2000/svg",Zn=class{constructor(){this.groundSvg=null;this.groundVisible=!1;this.currentGroundCssZ=null;this.shadowRoot=null}};function ri(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 ii(e){e.groundSvg?.parentNode&&e.groundSvg.parentNode.removeChild(e.groundSvg),e.groundSvg=null,e.groundVisible=!1}function si(e){e.groundSvg&&e.groundVisible&&(e.groundSvg.style.display="none",e.groundVisible=!1)}function ai(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(Aa,"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 li(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 Zn,receiverShadowCache:new Map,receiverShadowCacheKey:new Map,casterItemsCache:new Map,casterItemsCacheKey:new Map}}var Fe=require("@layoutit/polycss-core");function ci(e){for(let n of e)n.svg&&n.svg.parentNode&&n.svg.parentNode.removeChild(n.svg),n.svg=null}function di(e,n){if(n){let t=e.receiverShadowCache.get(n);t&&ci(t),e.receiverShadowCache.delete(n),e.receiverShadowCacheKey.delete(n)}else{for(let t of e.receiverShadowCache.values())ci(t);e.receiverShadowCache.clear(),e.receiverShadowCacheKey.clear()}}function ui(e,n){n?(e.casterItemsCache.delete(n),e.casterItemsCacheKey.delete(n)):(e.casterItemsCache.clear(),e.casterItemsCacheKey.clear())}function pi(e){ii(e.shadowSvgState),mi(e)}function Uo(e){return e.handle.id??e.autoMeshId}var Ma="http://www.w3.org/2000/svg",Qn=new WeakMap,fi=new WeakMap,hi=new WeakMap,gi=new WeakMap,yi=new WeakMap;function bi(e){let n=Qn.get(e);return n||(n=new Map,Qn.set(e,n)),n}function jo(e){let n=Qn.get(e);if(n){for(let t of n.values())t.svg&&t.svg.parentNode&&t.svg.parentNode.removeChild(t.svg);n.clear(),Qn.delete(e)}}function mi(e){for(let n of e.meshes)jo(n)}function vi(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=(0,Fe.meshScaleVec3)(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=(0,Fe.prepareReceiverFacePlanes)(o.polygons,P,o.handle.transform.scale,r,z,v),x.set(o,Z),f.set(o,O);let A=bi(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=(0,Fe.meshScaleVec3)(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=(0,Fe.prepareCasterPolyItems)(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 _=fi.get(A);(_===void 0||hi.get(A)!==A.polygons)&&(_=(0,Fe.buildSharedEdgeMap)(A.polygons),fi.set(A,_),hi.set(A,A.polygons)),L=_}let re;if(A!==o&&A.polygons.length>=40){let _=gi.get(A);(_===void 0||yi.get(A)!==w)&&(_=(0,Fe.prepareCasterEdgeOwners)(A.polygons,h,A.handle.transform.scale,u),gi.set(A,_),yi.set(A,w)),re=_}q.push({id:A,items:R,selfShadowEdgeMap:L,edgeOwners:re,casterPolygonCount:A.polygons.length})}let D={rotX:e.camera.state.rotX,rotY:e.camera.state.rotY,meshRotation:o.handle.transform.rotation},H=(0,Fe.computeReceiverShadowFaces)({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=bi(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(Ma,"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",Uo(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}`),ri(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=ai(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 re=A.paths[L],_=R?Uo(re.casterId):"";R&&w.push(_);let j=d[L];if(j.setAttribute("d",re.d),j.getAttribute("fill")!==A.fill&&j.setAttribute("fill",A.fill),j.getAttribute("stroke")!==A.fill&&j.setAttribute("stroke",A.fill),j.getAttribute("opacity")!==T&&j.setAttribute("opacity",T),R){j.getAttribute("data-poly-shadow-caster")!==_&&j.setAttribute("data-poly-shadow-caster",_);let Q=JSON.stringify(re.casterPolygonIndices);j.getAttribute("data-poly-shadow-caster-polys")!==Q&&j.setAttribute("data-poly-shadow-caster-polys",Q)}}if(R){let L=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 xi=Symbol.for("polycss.animation.triangleFrameTarget");var wa=750;function Pi(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:ne.DEFAULT_SEAM_BLEED}}var La={key:"non-cullable",normal:[1,1,0]};function Si(){return[La]}function Ci(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&&Wr(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...r}=n,i=Pi({seamBleed:ne.DEFAULT_SEAM_BLEED,...r}),s=Xr(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=li({host:e,doc:l,cameraEl:p,sceneEl:g,camera:t,layoutScale:s,options:i}),f=x.meshes,b=new WeakMap,y=x.shadowSvgState,P=()=>si(y),v=()=>pi(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=>di(x,a),O=a=>ui(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){Zr(a,s),a.style.transform=No(t,c,s),ti(a,m)}function D(a){a.style.transform=No(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?(0,ne.polygonCssSurfaceNormal)(S):m.plan?.normal??(S?(0,ne.polygonCssSurfaceNormal)(S):null)}function R(a){if(!Q(a))return a.rendered;let m=L(a);return a.rendered.filter(S=>re(a,S,ne.CAMERA_BACKFACE_CULL_EPS,m))}function L(a){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:a.handle.transform.rotation}}function re(a,m,S=ne.CAMERA_BACKFACE_CULL_EPS,E=L(a)){let W=w(a,m);return W===null||(0,ne.normalFacesCamera)(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(!(0,ne.isAxisAlignedSurfaceNormal)(E)){a.cameraCullGroups=Si();return}let W=(0,ne.cameraCullNormalKey)(E);if(!m.has(W)&&(m.set(W,E),m.size>ne.VOXEL_CAMERA_CULL_NORMAL_LIMIT)){a.cameraCullGroups=Si();return}}a.cameraCullGroups=Array.from(m,([S,E])=>({key:S,normal:E}))}function j(a){return Q(a)?(0,ne.cameraCullVisibleSignature)(a.cameraCullGroups,L(a)):"all"}function Q(a){return!a.excludeFromAutoCenter&&(0,ne.isVoxelCameraCullableNormalGroups)(a.cameraCullGroups)}function ae(a){a.cameraCullSignature=Q(a)?j(a):"all"}function be(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 se=a.rendered[K],te=re(a,se,m,W);S[K]=te}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 se=a.rendered[K];!S[K]&&se.element.parentNode===a.wrapper?(I&&I.nextSibling===se.element||(U(),B=se.element),I=se.element):U()}U();let Y=K=>{for(let se=K;se<a.rendered.length;se+=1){let te=a.rendered[se].element;if(te.parentNode===a.wrapper)return te}return V(a)},de=-1,ie=K=>{if(de<0)return;let se=l.createDocumentFragment();for(let te=de;te<K;te+=1){let Ne=a.rendered[te];Se(a,Ne),se.appendChild(Ne.element)}G(a,se,Y(K)),de=-1,E=!0};for(let K=0;K<a.rendered.length;K+=1){let se=a.rendered[K];S[K]&&se.element.parentNode!==a.wrapper?de<0&&(de=K):ie(K)}return ie(a.rendered.length),E}function fe(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&&Ce(a);return}if(a.hasBuckets){ge(a,m);return}let S=j(a);if(!m&&S===a.cameraCullSignature)return;let E=be(a,ne.CAMERA_BACKFACE_CULL_EPS);a.cameraCullSignature=S,E&&Xe(a)}function ge(a,m=!1){let S=Q(a)?j(a):"all";!m&&S===a.cameraCullSignature||Ce(a)}function we(a,m){return w(a,m)}function Se(a,m){if(i.textureLighting!=="dynamic")return;let S=we(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 ke(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?Qr(U):null;if(!Y){B.push(I);continue}let de=Y.key+"|"+(U.color??""),ie=W.get(de);ie||(ie={vec:Y.vec,items:[]},W.set(de,ie)),ie.items.push(I)}for(let I of B)Se(a,I),S.appendChild(I.element);for(let I of W.values()){if(I.items.length<2){for(let Y of I.items)Se(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)),ae(a)}function Ye(){return new Promise(a=>setTimeout(a,0))}async function tt(a,m){if(i.textureLighting==="dynamic"&&!a.stableDom)return ke(a),!m();T(a);let E=l.createDocumentFragment(),W=V(a),B=0;for(let I of R(a)){if(m())return!1;Se(a,I),E.appendChild(I.element),B++,B%wa===0&&(G(a,E,W),E=l.createDocumentFragment(),await Ye())}return E.childNodes.length>0&&G(a,E,W),ae(a),!m()}function mt(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=(0,ne.inverseRotateVec3)(E,m),I=Vt(B),U=Math.hypot(I[0],I[1],I[2])||1,Y=(I[0]/U).toFixed(2),de=(I[1]/U).toFixed(2),ie=(I[2]/U).toFixed(2),K=`${Y}|${de}|${ie}`;a.lightOverrideSignature!==K&&(a.wrapper.style.setProperty("--plx",Y),a.wrapper.style.setProperty("--ply",de),a.wrapper.style.setProperty("--plz",ie),a.lightOverrideSignature=K)}function Ct(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=$o(S,E,i)||m)}return a.solidLightingPreviewPrepared=!1,a.solidLightingPreviewActive=!1,m}function ft(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&&(oi(S,E,S.plan.shadedColor),m=!0)}return a.solidLightingPreviewPrepared=m,m}function lo(a){return(i.textureLighting??"baked")!=="baked"||!a.solidLightingPreviewPrepared&&!ft(a)?!1:(a.solidLightingPreviewActive=!0,!0)}function co(a){return a.kind==="atlas"||!!a.plan?.texture}function uo(){if((i.textureLighting??"baked")!=="baked")return!1;let a=!1;for(let m of f)a=Ct(m)||a,m.rendered.some(co)&&(Yt(m),a=!0);g.style.removeProperty(Bt);for(let m of f)bt(m.wrapper),m.solidLightingPreviewActive=!1;return bt(g),a}function po(){g.style.removeProperty(Bt);for(let a of f)a.solidLightingPreviewActive&&(Ct(a),bt(a.wrapper));(i.textureLighting??"baked")!=="dynamic"&&(bt(g),k(),Le())}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){bt(a.wrapper);return}let B=(0,ne.inverseRotateVec3)(E,S);Xn(a.wrapper,{...i,...m,directionalLight:{...i.directionalLight,...m.directionalLight,direction:B}})}function le(a){if((i.textureLighting??"baked")!=="baked")return!1;Xn(g,{...i,...a}),!a.skipShadows&&a.directionalLight?.direction&&Le(a.directionalLight.direction);let m=!1;for(let S of f)$(S,a),m=lo(S)||m;return m?me(g,Bt,"1"):g.style.removeProperty(Bt),m}function ce(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"?(ni(W.element,S),!0):B==="baked"?$o(W,E,i):!1}function De(a,m){let S=a.polygons[m];if(!S)return!1;let E=d(a,m);return E?(Pe(E.element,S,m),!0):!1}function Wt(a,m,S){return!(S.length===0||!S.every(E=>E==="color"||E==="data")||S.includes("color")&&!ce(a,m,a.polygons[m]?.color)||S.includes("data")&&!De(a,m))}function Xe(a){k(),Le()}function Le(a){let m=[];for(let te of f)!te.disposed&&te.castShadow&&m.push(te);if(m.length===0){v(),C=null;return}let S=i.shadow?.color??"#000000",E=i.shadow?.opacity??.25,W=(0,ne.parseHexColor)(S)?.rgb??[0,0,0],B=W[0],I=W[1],U=W[2],Y=a??i.directionalLight?.direction??[.4,-.7,.59],de=Vt(Y),ie=F(de);if(ie!==null&&ie===C)return;let K=new Map;for(let te of m)K.set(te,(0,ne.findOverlappingPolygonDuplicates)(te.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.95,preserveDoubleSidedBackfaces:!1}));let se=new Map;for(let te of f)te.disposed||!te.receiveShadow||se.set(te,new Set);P();for(let te of f)te.disposed||!te.receiveShadow||vi(x,m,K,te,se.get(te)??new Set,de,B,I,U,E);C=ie}function Ce(a){if(a.voxelRenderer){a.voxelRenderer.render(L(a)),a.cameraCullSignature="voxel-direct";return}A(a),ke(a),Xe(a)}function Be(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 de=Y&&Y.polygons===a.polygons?Y.dedupDropped:(0,ne.findOverlappingPolygonDuplicates)(a.polygons,{normalTolerance:.1,distanceTolerance:.12,overlapFraction:.98,preserveDoubleSidedBackfaces:!1}),ie=(0,ne.computeLightVisibility)(a.polygons,[E,W,B],de);return a.lightOcclusionCache={polygons:a.polygons,lightDirKey:U,occluded:ie,dedupDropped:de},ie}function ze(a){return!!a.voxelSource&&i.textureLighting!=="dynamic"&&!a.stableDom&&!a.castShadow}function Me(a,m){H(a);let S=i.directionalLight,E=m?{...S,direction:m}:S,W=ut(E),B=void 0;if(ze(a)){let Y=Ur({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=Ot(a.polygons,I);return vt(a.wrapper,Y),on(a.polygons,{...I,solidPaintDefaults:Y})??Ht(a.polygons,{...I,solidPaintDefaults:Y})})():Ht(a.polygons,{...I,computeSolidPaintDefaults:!0,skipDynamicNormalVars:i.textureLighting==="dynamic"});a.stableDom||vt(a.wrapper,U.solidPaintDefaults??{}),u(a,U.rendered,U.dispose),a.skipBucketNormalCleanupOnce=i.textureLighting==="dynamic"&&!a.stableDom,_(a),ke(a),Xe(a)}function Yt(a,m){if(a.rendered.length===0||a.voxelRenderer||a.stableDom||ze(a)){Me(a,m);return}if(a.rendered[0]?.element.parentNode===null){Me(a,m);return}let S=i.directionalLight,E=m?{...S,direction:m}:S,W=ut(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=Ht(a.polygons,B),U=()=>{a.rebakeInFlight=!1;let ie=a.rebakeQueuedLightDir;ie!==null&&(a.rebakeQueuedLightDir=null,Yt(a,ie))},Y=()=>{if(a.disposed){I.dispose(),U();return}if(I.rendered.length!==a.rendered.length){I.dispose(),Me(a,m),U();return}for(let se of I.rendered){let te=a.renderedByPolygonIndex[se.polygonIndex];if(!te)continue;let Ne=se.element.getAttribute("style");Ne!==null&&te.element.setAttribute("style",Ne)}let ie=I.solidPaintDefaults;ie&&vt(a.wrapper,ie);let K=a.disposeAtlas;a.disposeAtlas=I.dispose,K&&(typeof requestAnimationFrame=="function"?te=>{requestAnimationFrame(te)}:te=>{setTimeout(te,0)})(K),Xe(a),U()},de=I.pagesReady;de&&typeof de.then=="function"?de.then(()=>fo(I.rendered)).then(ho).then(Y,()=>{I.dispose(),a.disposed||Me(a,m),U()}):Y()}function mo(a,m){if(a.rebakeInFlight){a.rebakeQueuedLightDir=m;return}a.rebakeInFlight=!0,Yt(a,m)}function fo(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 ho(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 nt(){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 de of Y.vertices){let ie=de[2]+U;ie<a&&(a=ie)}}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)*je,W=y.currentGroundCssZ;y.currentGroundCssZ=E,W!==E&&(k(),Le())}async function Rn(a,m){H(a);let S=ut(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?on(a.polygons,E):null;if(W){let U=Ot(a.polygons,E);return vt(a.wrapper,U),u(a,W.rendered,W.dispose),_(a),ke(a),Xe(a),!m()}let B=await $n(a.polygons,{...E,skipDynamicNormalVars:i.textureLighting==="dynamic"},m);if(m())return B.dispose(),!1;vt(a.wrapper,B.solidPaintDefaults),u(a,B.rendered,B.dispose),a.skipBucketNormalCleanupOnce=i.textureLighting==="dynamic"&&!a.stableDom,_(a);let I=await tt(a,m);return I&&Xe(a),I}function ht(){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=(0,ne.computeSceneBbox)(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 es(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,de=Yn(B);de&&(E.style.transform=de);let ie=(N,X)=>a.voxelSource?N:X?(0,ne.optimizeMeshPolygons)(N,{meshResolution:m.meshResolution}):(U||m.excludeFromAutoCenter,N),K=ie(a.polygons,I),se=null;function te(){let N=Yn(B);E.style.transform=N??""}function Ne(N){if(N.length===0){se=null,Ze&&(Ze.bboxCenterCss=null),te();return}let X=1/0,ue=1/0,ye=1/0,Oe=-1/0,pe=-1/0,xe=-1/0;for(let Ke of N)for(let $e of Ke.vertices)$e[0]<X&&(X=$e[0]),$e[0]>Oe&&(Oe=$e[0]),$e[1]<ue&&(ue=$e[1]),$e[1]>pe&&(pe=$e[1]),$e[2]<ye&&(ye=$e[2]),$e[2]>xe&&(xe=$e[2]);if(!Number.isFinite(X)){se=null,Ze&&(Ze.bboxCenterCss=null),te();return}let Ge=(ue+pe)/2*je,qe=(X+Oe)/2*je,He=(ye+xe)/2*je;se=[Ge,qe,He],Ze&&(Ze.bboxCenterCss=se),te()}let Ze=null;Ne(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:se,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},Qe=null,go=0,kn=-1,Xt=null;function Zt(){Qe=null,Xt=null,kn=-1}function tr(){let N=Qe;if(!N||N.polygonCount!==M.polygons.length)return M.polygons;if(Xt&&kn===go)return Xt;let X=N.vertices,ue=new Array(N.polygonCount);for(let ye=0;ye<N.polygonCount;ye++){let Oe=M.polygons[ye],pe=ye*9;ue[ye]={...Oe,color:N.colors?.[ye]??Oe.color,vertices:[[X[pe],X[pe+1],X[pe+2]],[X[pe+3],X[pe+4],X[pe+5]],[X[pe+6],X[pe+7],X[pe+8]]]}}return Xt=ue,kn=go,ue}function nr(N,X){let ue=N?.stableTriangleUpdateMode==="color-only";M.stableTriangleColorFrame++;let ye=M.stableDom&&!X;if(ye||Ne(M.polygons),M.stableDom&&!M.hasBuckets){let Oe={doc:l,directionalLight:ut(i.directionalLight),ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed},pe=M.rendered.length===M.polygons.length&&M.rendered.every(He=>He.kind==="triangle"),xe=M.stableDom&&!X,Ge=pe||xe?{}:Ot(M.polygons,Oe);pe||vt(M.wrapper,Ge);let qe={...Oe,solidPaintDefaults:Ge,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(jn(M.rendered,M.polygons,qe))return ue||(_(M),fe(M,!0),X&&ht()),!0}return ye&&Ne(M.polygons),!1}let Et={get polygons(){return tr()},set polygons(N){Zt(),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),ht(),nt()},setPolygons(N,X){Y++,I=X?.merge??I,U=X?.stableDom??U,M.stableDom=U,M.voxelSource=void 0,M.polygons=ie(N,I),O(M),z(M),Zt(),Et.polygons=M.polygons;let ue=X?.recomputeAutoCenter??!0;nr(X,ue)||(Me(M),ue&&ht())},[xi](N,X){let ue=X?.merge??I,ye=X?.stableDom??U;if(!N.solidTriangles||!ye||ue||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 xe=0;xe<M.rendered.length;xe++){let Ge=M.rendered[xe],qe=M.polygons[xe];if(Ge?.kind!=="triangle"||Ge.polygonIndex!==xe||!qe||qe.vertices.length!==3||qe.texture||qe.material?.texture)return!1}let Oe=X?.recomputeAutoCenter??!0;if(!Oe){let xe=M.stableTriangleColorFrame+1,Ge={doc:l,directionalLight:ut(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:xe};if(Un(M.rendered,M.polygons,N,Ge))return Y++,I=ue,U=ye,M.stableDom=U,M.voxelSource=void 0,M.stableTriangleColorFrame=xe,Qe=N,go++,Xt=null,kn=-1,Q(M)?(_(M),fe(M,!0)):ae(M),!0}Y++,I=ue,U=ye,M.stableDom=U,M.voxelSource=void 0;let pe=N.vertices;for(let xe=0;xe<N.polygonCount;xe++){let Ge=M.polygons[xe],qe=N.colors?.[xe];qe&&(Ge.color=qe);let He=Ge.vertices,Ke=xe*9;He[0][0]=pe[Ke],He[0][1]=pe[Ke+1],He[0][2]=pe[Ke+2],He[1][0]=pe[Ke+3],He[1][1]=pe[Ke+4],He[1][2]=pe[Ke+5],He[2][0]=pe[Ke+6],He[2][1]=pe[Ke+7],He[2][2]=pe[Ke+8]}return Zt(),Et.polygons=M.polygons,nr(X,Oe)},updatePolygon(N,X){let ue=typeof N=="number"?N:M.polygons.indexOf(N);if(ue<0&&typeof N!="number"&&Qe&&(ue=tr().indexOf(N)),ue<0||ue>=M.polygons.length)return;Zt(),M.voxelSource=void 0,Object.assign(M.polygons[ue],X);let ye=Object.keys(X);Wt(M,ue,ye)||Me(M)},async setPolygonsChunked(N,X){let ue=++Y;I=X?.merge??I,U=X?.stableDom??U,M.stableDom=U,M.voxelSource=void 0,M.polygons=ie(N,I),Zt(),Et.polygons=M.polygons,Ne(M.polygons);let ye=X?.recomputeAutoCenter??!0;if(!await Rn(M,()=>M.disposed||ue!==Y)){H(M);return}ye&&ht()},setTransform(N){let X=M.castShadow,ue=M.receiveShadow;N.castShadow!==void 0&&(M.castShadow=!!N.castShadow),N.receiveShadow!==void 0&&(M.receiveShadow=!!N.receiveShadow),B={...B,...N};let ye=Yn(B);E.style.transform=ye??"",mt(M,B.rotation),N.rotation!==void 0&&fe(M,!0),M.castShadow!==X&&(M.voxelSource&&Me(M),Xe(M),nt()),M.receiveShadow!==ue&&(M.receiveShadow||jo(M),k(),Le()),(N.position!==void 0||N.scale!==void 0)&&(M.castShadow||M.receiveShadow)&&(nt(),k(),Le())},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),ht(),nt()}},rebakeAtlas(){M.bakedRotation=B.rotation?[...B.rotation]:[0,0,0];let N=i.directionalLight?.direction??[.4,-.7,.59],X=(0,ne.inverseRotateVec3)(N,M.bakedRotation);mo(M,X)},getPosition(){return B.position},getRotation(){return B.rotation},getScale(){return B.scale},getPolygons(){return Et.polygons}};return M.handle=Et,Ze=M,b.set(E,M),f.add(M),Me(M),mt(M,B.rotation),ht(),nt(),M.receiveShadow&&(k(),Le()),Et}function ts(a){let m=!!i.autoCenter,S=i.strategies,E=i.seamBleed,W=i.textureLighting,B=i.directionalLight?.direction,I=i.shadow,U=Pi(a);i={...i,...U},x.options.current=i,q(g,i);let Y=!!i.autoCenter;for(let Qe of f)mt(Qe,Qe.handle.transform.rotation);let de=a.strategies!==void 0&&!qr(a.strategies,S),ie=Object.prototype.hasOwnProperty.call(a,"seamBleed")&&U.seamBleed!==E;if(de||ie)for(let Qe of f)Me(Qe);m!==Y&&ht();let K=a.textureLighting!==void 0&&W!==i.textureLighting,se=i.directionalLight?.direction,te=a.directionalLight!==void 0&&!Kr(B,se),Ne=i.shadow,Ze=a.shadow!==void 0&&!Jr(I,Ne),M=te||Ze;if(K){if(!de&&!ie)for(let Qe of f)Me(Qe);nt(),k(),Le()}else M&&(Ze&&k(),Le());Ze&&a.shadow?.lift!==I?.lift&&nt()}function ns(){return i}function os(){D(g);for(let a of f)fe(a)}function rs(){let a=[];for(let m of f)a.push(m.handle);return a}function is(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 ss(){let a=Array.from(f);for(let m of a)try{m.handle.dispose()}catch{}p.parentNode&&p.parentNode.removeChild(p)}return{add:es,setOptions:ts,destroy:ss,host:e,camera:t,cameraEl:p,applyCamera:os,getOptions:ns,meshes:rs,findMeshByElement:is,previewBakedSolidLighting:le,commitBakedSolidLighting:uo,clearBakedSolidLightingPreview:po}}var Wo=require("@layoutit/polycss-core"),_a=32e3;function rn(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,Wo.createIsometricCamera)(n),o=`${e.perspective??_a}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function sn(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,Wo.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var Ra=typeof HTMLElement<"u"?HTMLElement:class{},ka=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function We(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Da(e){return e==="false"?!1:We(e)}function Yo(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 Oa(e){if(e==="baked"||e==="dynamic")return e}function Ha(e){return e==="auto"?"auto":We(e)}function Ia(e){return typeof e.getCamera=="function"}var _e=class extends Ra{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...ka]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(Ia(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=Da(this.getAttribute("perspective")),o=We(this.getAttribute("rot-x")),r=We(this.getAttribute("rot-y")),i=We(this.getAttribute("zoom")),s=We(this.getAttribute("distance")),c=Yo(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?sn(l):t!==void 0?rn({...l,perspective:t}):sn(l)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={};r.textureLighting=Oa(this.getAttribute("texture-lighting"))??"baked";let i=Ha(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=Yo(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=We(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=We(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=Ci(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=We(this.getAttribute("rot-x")),c=We(this.getAttribute("rot-y")),l=We(this.getAttribute("zoom")),p=We(this.getAttribute("distance")),g=Yo(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())}}};var qn=require("@layoutit/polycss-core"),Fa=typeof HTMLElement<"u"?HTMLElement:class{},Va=["src","mtl","mesh-resolution","position","scale","rotation","auto-center","cast-shadow","receive-shadow","target-size","default-color","palette","include-objects","exclude-objects"];function an(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 Ei(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return an(e)}}function Xo(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 Ba(e){let n=e.getAttribute("target-size"),t=e.getAttribute("default-color"),o=Xo(e.getAttribute("palette")),r=Xo(e.getAttribute("include-objects")),i=Xo(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 za(e){return e.closest("poly-scene")??null}function Na(e){if(e.length===0)return e;let n=(0,qn.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let 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 xt=class extends Fa{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Va]}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:an(this.getAttribute("position")),scale:Ei(this.getAttribute("scale")),rotation:an(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=za(this);if(!o)return;let r=++this._loadToken,i=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,l=Ba(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(0,qn.loadMesh)(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:Na(p.polygons)}),this._parseResult=p,this._handle=g.add(p,{position:an(this.getAttribute("position")),scale:Ei(this.getAttribute("scale")),rotation:an(this.getAttribute("rotation")),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var zt=require("@layoutit/polycss-core"),Ga=typeof HTMLElement<"u"?HTMLElement:class{},$a=["src","width","height","position","rotation","scale","allow","loading","referrerpolicy","sandbox","title"];function Zo(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 Ua(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Zo(e)}}function Ti(e,n){if(e===null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}function ja(e){let n=e.closest("poly-scene");return n?n.querySelector(".polycss-scene"):null}function Wa(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)*zt.BASE_TILE,x=(e?.[0]??0)*zt.BASE_TILE,f=(e?.[2]??0)*zt.BASE_TILE,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 ln=class extends Ga{constructor(){super(...arguments);this._wrapper=null;this._iframe=null}static get observedAttributes(){return[...$a]}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=ja(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=Ti(this.getAttribute("width"),16),o=Ti(this.getAttribute("height"),9),r=t*zt.BASE_TILE,i=o*zt.BASE_TILE;this._iframe.style.width=`${r}px`,this._iframe.style.height=`${i}px`;let s=Zo(this.getAttribute("position")),c=Zo(this.getAttribute("rotation")),l=Ua(this.getAttribute("scale"));this._wrapper.style.transform=Wa(s,c,l,r,i)}_teardown(){this._wrapper?.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null,this._iframe=null}};var Ya=typeof HTMLElement<"u"?HTMLElement:class{},Xa=["vertices","color","texture","uvs","position","scale","rotation"];function Ai(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Qo(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 Za(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Qo(e)}}function Qa(e){return e.closest("poly-scene")??null}var cn=class extends Ya{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Xa]}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=Qa(this);if(!t)return;let o=t.getScene();if(!o)return;let r=Ai(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=Ai(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:Qo(this.getAttribute("position")),scale:Za(this.getAttribute("scale")),rotation:Qo(this.getAttribute("rotation"))})}};var wi=require("@layoutit/polycss-core"),qa=typeof HTMLElement<"u"?HTMLElement:class{},Ka=["size","thickness","negative","x-color","y-color","z-color"];function Ja(e){return e.closest("poly-scene")??null}function Mi(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var dn=class extends qa{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Ka]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&this._handle&&this._remount()}_polygons(){return(0,wi.axesHelperPolygons)({size:Mi(this.getAttribute("size")),thickness:Mi(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=Ja(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}}};var Ri=require("@layoutit/polycss-core"),el=typeof HTMLElement<"u"?HTMLElement:class{},tl=["direction","target","distance","size","color"],nl=5,ol=.35,rl="#ffd54a";function il(e){return e.closest("poly-scene")??null}function Li(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 _i(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var un=class extends el{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...tl]}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=Li(this.getAttribute("direction"));if(!t)return;let o=Li(this.getAttribute("target"))??[0,0,0],r=_i(this.getAttribute("distance"),nl),[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=il(this);if(!t)return;let o=t.getScene();if(!o)return;let r=_i(this.getAttribute("size"),ol),i=this.getAttribute("color")??rl,s={polygons:(0,Ri.octahedronPolygons)({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}}};var ki=require("@layoutit/polycss-core");var Kn={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Nt(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 pn(e){return e===!0?-1:e===!1?1:e}function Gt(){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 $t(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 Jn(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 eo(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 Di(e,n={}){let t=Nt(Kn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,i=null,s={x:0,y:0},c=!1,l=!1,p=Gt(),g=$t(e),{changeListeners:x,startListeners:f,endListeners:b,listenerArray:y,emitChange:P,emitInteraction:v}=p,C=eo(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=pn(t.invert),L=T/4*R,re=w/4*R,_=e.camera.state;if(d.shiftKey){let j=_.rotX??65,Q=_.rotY??45,ae=Math.max(.01,_.zoom??1),be=Math.cos(j*Math.PI/180),fe=be>=0?Math.max(.1,be):Math.min(-.1,be),ge=Math.cos(Q*Math.PI/180),we=Math.sin(Q*Math.PI/180),Se=ae*ki.BASE_TILE,ke=(T*we-w*ge/fe)/Se,Ye=-(T*ge+w*we/fe)/Se,tt=_.target??[0,0,0];e.camera.update({target:[tt[0]+ke,tt[1]+Ye,tt[2]]})}else{let j=Math.max(0,Math.min(89,(_.rotX??65)-re)),Q=(((_.rotY??45)-L)%360+360)%360;e.camera.update({rotX:j,rotY:Q})}e.applyCamera(),P(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=Jn(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=Nt(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 oe(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function to(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 Re(e){if(e!==null)return!(e==="false"||e==="0")}function no(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 oo(e){if(e==="x"||e==="y")return e}var sl=typeof HTMLElement<"u"?HTMLElement:class{},al=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],mn=class extends sl{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...al]}getControls(){return this._controls}_readAnimate(){let t=oe(this.getAttribute("animate-speed")),o=oo(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:Re(r)}:{}}}_readOptions(){let t={},o=Re(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Re(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let i=oe(this.getAttribute("min-distance"));i!==void 0&&(t.minDistance=i);let s=oe(this.getAttribute("max-distance"));s!==void 0&&(t.maxDistance=s);let c=no(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=oe(this.getAttribute("zoom-min")),p=oe(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 _e)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=Di(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 Oi=require("@layoutit/polycss-core");function Hi(e,n={}){let t=Nt(Kn,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=Gt(),f=$t(e),{changeListeners:b,startListeners:y,endListeners:P,listenerArray:v,emitChange:C,emitInteraction:F}=x,k=eo(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 ae=e.camera.state;if(_.shiftKey){let be=pn(t.invert),fe=j/4*be,ge=Q/4*be,we=(ae.rotX??65)-ge,Se=(((ae.rotY??45)-fe)%360+360)%360;e.camera.update({rotX:we,rotY:Se})}else{let be=ae.rotX??65,fe=ae.rotY??45,ge=Math.max(.01,ae.zoom??1),we=Math.cos(be*Math.PI/180),Se=we>=0?Math.max(.1,we):Math.min(-.1,we),ke=Math.cos(fe*Math.PI/180),Ye=Math.sin(fe*Math.PI/180),tt=ge*Oi.BASE_TILE,mt=(j*Ye-Q*ke/Se)/tt,Ct=-(j*ke+Q*Ye/Se)/tt,ft=ae.target??[0,0,0];e.camera.update({target:[ft[0]+mt,ft[1]+Ct,ft[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 ae=pn(t.invert),be=j/4*ae,fe=Q/4*ae,ge=e.camera.state,we=(ge.rotX??65)-fe,Se=(((ge.rotY??45)-be)%360+360)%360;e.camera.update({rotX:we,rotY:Se}),e.applyCamera(),C(f)},V=_=>{_.button===2&&p&&(p=!1,F("end",f))},G=Jn(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=Nt(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(_),ae=Q.indexOf(j);ae>=0&&Q.splice(ae,1)}function re(_,j){return v(_).includes(j)}return{update:u,resume:d,pause:T,destroy:w,addEventListener:R,removeEventListener:L,hasEventListener:re}}var ll=typeof HTMLElement<"u"?HTMLElement:class{},cl=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],fn=class extends ll{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...cl]}_readAnimate(){let t=oe(this.getAttribute("animate-speed")),o=oo(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:Re(r)}:{}}}_readOptions(){let t={},o=Re(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Re(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let i=oe(this.getAttribute("min-distance"));i!==void 0&&(t.minDistance=i);let s=oe(this.getAttribute("max-distance"));s!==void 0&&(t.maxDistance=s);let c=no(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=oe(this.getAttribute("zoom-min")),p=oe(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 _e)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=Hi(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Gi=require("@layoutit/polycss-core");var dl={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 Ii(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 Fi=new Set(["KeyW","ArrowUp"]),Vi=new Set(["KeyS","ArrowDown"]),Bi=new Set(["KeyA","ArrowLeft"]),zi=new Set(["KeyD","ArrowRight"]),Ni=new Set(["Space"]),qo=new Set(["ControlLeft","ControlRight"]);function $i(e,n={}){let t=Ii(dl,n),o=e.host,r=e.cameraEl,i=o.ownerDocument??document,s=i.defaultView??globalThis,c=Gt(),l=$t(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($,le){let ce=$*Math.PI/180,De=le*Math.PI/180;return[-Math.sin(ce)*Math.cos(De),-Math.sin(ce)*Math.sin(De),-Math.cos(ce)]}function q(){let $=e.camera.perspectiveStyle,le=$==="none"?0:parseFloat($);return(Number.isFinite(le)&&le>0?le:2e3)/Gi.BASE_TILE}function D(){let $=e.camera.state,le=Z($.rotX??90,$.rotY??0),ce=q();return[O[0]+le[0]*ce,O[1]+le[1]*ce,O[2]+le[2]*ce]}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 le=$.movementX??0,ce=$.movementY??0;if(le===0&&ce===0)return;let De=e.camera.state,Wt=t.lookSensitivity,Xe=t.invertY?-1:1,Le=(((De.rotY??0)-le*Wt)%360+360)%360,Ce=(De.rotX??90)-ce*Wt*Xe;Ce<t.minPitch?Ce=t.minPitch:Ce>t.maxPitch&&(Ce=t.maxPitch);let Be=Z(Ce,Le),ze=q(),Me=[O[0]+Be[0]*ze,O[1]+Be[1]*ze,O[2]+Be[2]*ze];e.camera.update({rotX:Ce,rotY:Le,target:Me}),e.applyCamera(),b(l)},u=$=>Fi.has($)||Vi.has($)||Bi.has($)||zi.has($)||Ni.has($)||qo.has($),d=$=>{if(!(!t.enabled||C)&&u($.code)&&!(!v&&!t.moveEnabled)){if(Ni.has($.code)){if(!t.jumpEnabled)return;$.preventDefault(),!P.has($.code)&&F===0&&k===0&&(F=t.jumpVelocity),P.add($.code);return}qo.has($.code)&&!t.crouchEnabled||!t.moveEnabled&&!qo.has($.code)||($.preventDefault(),P.add($.code))}},T=$=>{u($.code)&&P.delete($.code)},w=()=>{P.clear()},R=null,L=0,re=.05,_=$=>{if(R===null||C)return;let le=Math.min(re,L?($-L)/1e3:.0167);if(L=$,t.enabled){let ce=!1,De=e.camera.state;if(t.moveEnabled){let Ce=0,Be=0;for(let ze of P)Fi.has(ze)?Ce+=1:Vi.has(ze)?Ce-=1:zi.has(ze)?Be+=1:Bi.has(ze)&&(Be-=1);if(Ce!==0||Be!==0){let Me=(De.rotY??0)*Math.PI/180,Yt=-Math.cos(Me),mo=-Math.sin(Me),fo=-Math.sin(Me),ho=Math.cos(Me),nt=Math.hypot(Ce,Be)||1,Rn=t.moveSpeed*le;O[0]+=(Yt*Ce+fo*Be)/nt*Rn,O[1]+=(mo*Ce+ho*Be)/nt*Rn,ce=!0}}let Xe=t.crouchEnabled&&(P.has("ControlLeft")||P.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(F!==0||k>0)?(F-=t.gravity*le,k+=F*le,k<=0&&(k=0,F=0)):t.jumpEnabled||(k=0,F=0);let Le=t.groundZ+Xe+k;if(Math.abs(O[2]-Le)>1e-4&&(O[2]=Le,ce=!0),ce){let Ce=D();e.camera.update({target:Ce}),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 ae(){let le=r.ownerDocument?.defaultView?.getComputedStyle(r).perspective??"",ce=parseFloat(le),De=Number.isFinite(ce)&&ce>0?ce:2e3;r.style.setProperty("--polycss-fpv-perspective",`${De}px`),r.classList.add("polycss-fpv-host")}function be(){r.classList.remove("polycss-fpv-host"),r.style.removeProperty("--polycss-fpv-perspective")}function fe(){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":"",ae()}function ge(){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{}be()}V(),fe(),j();function we($){let le=t.eyeHeight,ce=t.groundZ;t=Ii(t,$),C||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==le||t.groundZ!==ce)&&(O[2]=t.groundZ+t.eyeHeight,H(),b(l))}function Se(){C&&(C=!1,fe(),j())}function ke(){C||(C=!0,ge(),Q(),z&&(z=!1,y("end",l)))}function Ye(){ke(),p.length=0,g.length=0,x.length=0}function tt(){if(!(!t.enabled||!t.lookEnabled||C))try{o.requestPointerLock()}catch{}}function mt(){if(v)try{i.exitPointerLock()}catch{}}function Ct(){return v}function ft($,le){let ce=f($);ce.includes(le)||ce.push(le)}function lo($,le){let ce=f($),De=ce.indexOf(le);De>=0&&ce.splice(De,1)}function co($,le){return f($).includes(le)}function uo(){return[O[0],O[1],O[2]]}function po($){O[0]=$[0],O[1]=$[1],O[2]=$[2],H(),b(l)}return{update:we,resume:Se,pause:ke,destroy:Ye,lock:tt,unlock:mt,isLocked:Ct,getOrigin:uo,setOrigin:po,addEventListener:ft,removeEventListener:lo,hasEventListener:co}}var ul=typeof HTMLElement<"u"?HTMLElement:class{},pl=["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"],hn=class extends ul{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...pl]}_readOptions(){let t={},o=Re(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let r=Re(this.getAttribute("look-enabled"));r!==void 0&&(t.lookEnabled=r);let i=Re(this.getAttribute("move-enabled"));i!==void 0&&(t.moveEnabled=i);let s=Re(this.getAttribute("jump-enabled"));s!==void 0&&(t.jumpEnabled=s);let c=Re(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let l=oe(this.getAttribute("look-sensitivity"));if(l!==void 0&&(t.lookSensitivity=l),this.hasAttribute("invert-y")){let C=Re(this.getAttribute("invert-y"));C!==void 0&&(t.invertY=C)}let p=oe(this.getAttribute("move-speed"));p!==void 0&&(t.moveSpeed=p);let g=oe(this.getAttribute("jump-velocity"));g!==void 0&&(t.jumpVelocity=g);let x=oe(this.getAttribute("gravity"));x!==void 0&&(t.gravity=x);let f=oe(this.getAttribute("eye-height"));f!==void 0&&(t.eyeHeight=f);let b=oe(this.getAttribute("crouch-height"));b!==void 0&&(t.crouchHeight=b);let y=oe(this.getAttribute("ground-z"));y!==void 0&&(t.groundZ=y);let P=oe(this.getAttribute("min-pitch"));P!==void 0&&(t.minPitch=P);let v=oe(this.getAttribute("max-pitch"));return v!==void 0&&(t.maxPitch=v),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof _e)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 ml=typeof HTMLElement<"u"?HTMLElement:class{},fl=["perspective","zoom","rot-x","rot-y","target","distance"],gn=class extends ml{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...fl]}getCamera(){return this._camera}_readOptions(){return{perspective:oe(this.getAttribute("perspective")),zoom:oe(this.getAttribute("zoom")),rotX:oe(this.getAttribute("rot-x")),rotY:oe(this.getAttribute("rot-y")),target:to(this.getAttribute("target")),distance:oe(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=rn(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=rn(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 hl=typeof HTMLElement<"u"?HTMLElement:class{},gl=["zoom","rot-x","rot-y","target","distance"],Pt=class extends hl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...gl]}getCamera(){return this._camera}_readOptions(){return{zoom:oe(this.getAttribute("zoom")),rotX:oe(this.getAttribute("rot-x")),rotY:oe(this.getAttribute("rot-y")),target:to(this.getAttribute("target")),distance:oe(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=sn(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 yn=class extends Pt{};var Ae=require("@layoutit/polycss-core");function Ut(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 Ui(e,n,t,o){for(let r of e)if(!(o&&!o(r))&&Ut(r.element,n,t))return r;return null}var ro="#ff3653",io="#8adb00",so="#2c8fff",jt=50,ji=60,yl=.6,bl=.0125,vl=.15,xl=.04,Pl=1,Wi=.02,Ko=1.04,Sl=.1,Cl=.25,Qi=1e-4,El=.6,Tl=.8,Al=1,lt={0:1,1:0,2:2},Yi=[{cssAxis:0,sign:1,key:"x",color:ro},{cssAxis:0,sign:-1,key:"-x",color:ro},{cssAxis:1,sign:1,key:"y",color:io},{cssAxis:1,sign:-1,key:"-y",color:io},{cssAxis:2,sign:1,key:"z",color:so},{cssAxis:2,sign:-1,key:"-z",color:so}],Xi=[{cssAxis:0,key:"x",color:ro},{cssAxis:1,key:"y",color:io},{cssAxis:2,key:"z",color:so}],Zi=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:so},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:io},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:ro}];function Jo(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 Ml(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 ao(e,n){return!n||n<=0?e:Math.round(e/n)*n}function wl(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 er(e){if(e.length===0)return ji;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)*jt*yl:ji}function Ll(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<Qi)return;g?.(),f?.(!0);let O=q=>{let D=q.clientX-s,H=q.clientY-c,V=(D*F+H*k)/z;V=ao(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 _l(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)<Qi)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=ao(q,c),D=ao(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 Rl(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=ao(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 qi(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=(0,Ae.rotateVec3)(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?Al:c===h?Tl:El}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=er(t?.polygons??[])*r,w=T/jt,R=Ml(h.color,u);if(h.kind==="arrow"){let _=e.camera.state,j=Jo(h.cssAxis,h.sign,_.rotX??65,_.rotY??45);return(0,Ae.arrowPolygons)({axis:lt[h.cssAxis],sign:h.sign,shaftLength:w,shaftHalfThickness:w*bl,headLength:w*vl,headHalfThickness:w*xl,color:R,shaft:!j})}if(h.kind==="plane"){let _=e.camera.state,j=_.rotX??65,Q=_.rotY??45,ae=lt[h.perpAxis],be=(ae+1)%3,fe=(ae+2)%3,ge=lt[be],we=lt[fe],Se=Jo(ge,1,j,Q)?-1:1,ke=Jo(we,1,j,Q)?-1:1,Ye=w*Cl;return(0,Ae.planePolygons)({axis:ae,size:w*Sl,offset:[Se*Ye,ke*Ye],color:R})}let re=T*Pl/jt*Ko;return(0,Ae.ringQuadPolygons)({axis:lt[h.cssAxis],outerRadius:re,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=Yi.map(d=>({kind:"arrow",key:d.key,cssAxis:d.cssAxis,sign:d.sign,color:d.color})),u=Zi.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"?Xi.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 re=(1-Wi)/Ko,_=(1+Wi)/Ko;R.element.style.setProperty("--ring-inner-ratio",`${re}`),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=wl(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=lt[h.cssAxis],R=u*T/jt,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 Zi){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&&Ut(R.handle.element,h.clientX,h.clientY)){h.preventDefault(),h.stopPropagation(),l=d.key,f(),D=(t.transform.position??[0,0,0]).slice(),_l({axisA:d.axisA,axisB:d.axisB,probeDistanceCss:er(t.polygons)*r,wrapper:R.handle.element,target:t,startClientX:h.clientX,startClientY:h.clientY,translationSnap:i.translationSnap??null,onPlaneDelta:(L,re,_,j)=>{if(!t||!D)return;let Q=_[d.axisA],ae=j[d.axisB],be=lt[d.axisA],fe=lt[d.axisB],ge=D.slice();ge[be]+=L*Q/jt,ge[fe]+=re*ae/jt,t.setTransform({position:ge}),F(),i.onObjectChange?.({object:t,position:ge}),i.onChange?.()},onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:L=>{L||(l=null,D=null,f()),i.onDraggingChanged?.(L)}});return}}for(let d of Yi){let T=d.key.replace("-","")[0];if(!u[T])continue;let w=s.get(d.key);if(w&&Ut(w.handle.element,h.clientX,h.clientY)){h.preventDefault(),h.stopPropagation(),l=d.key,f(),D=(t.transform.position??[0,0,0]).slice(),Ll({cssAxis:d.cssAxis,sign:d.sign,shaftLengthCss:er(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 Xi){if(!u[d.key])continue;let T=s.get(d.key);if(T&&Ut(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(),Rl({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=lt[d.cssAxis],L=[0,0,0];L[R]=1;let re=-w*Math.PI/180,_=(0,Ae.quatFromEulerXYZ)(H),j=(0,Ae.quatFromAxisAngle)(L,re),Q=(0,Ae.eulerXYZFromQuat)((0,Ae.quatMultiply)(j,_)),ae=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,be=(0,Ae.rotateVec3)(p,H[0],H[1],H[2]),fe=(0,Ae.rotateVec3)(p,Q[0],Q[1],Q[2]),ge=[D[0]+ae*(be[0]-fe[0]),D[1]+ae*(be[1]-fe[1]),D[2]+ae*(be[2]-fe[2])];t.setTransform({rotation:Q,position:ge}),F(),i.onObjectChange?.({object:t,rotation:Q,position:ge}),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(Ut(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 kl=typeof HTMLElement<"u"?HTMLElement:class{},Dl=["mode","target","size","enabled"];function Ki(e){if(e==="translate"||e==="rotate")return e}var bn=class extends kl{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Dl]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof _e)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 xt?r:null}_readOptions(){let t={},o=Ki(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=oe(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=qi(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=Ki(r);i&&this._tc.setMode(i)}else if(t==="target"){let i=this._findTargetMesh();this._tc.attach(i?i.getMeshHandle()??null:null)}}}};function Ji(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 Ui(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 Ol=typeof HTMLElement<"u"?HTMLElement:class{},Hl=["multiple","clear-on-miss"],vn=class extends Ol{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Hl]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof _e)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=Ji(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};var he=require("@layoutit/polycss-core"),Il=typeof HTMLElement<"u"?HTMLElement:class{};function Fl(e){return e.closest("poly-scene")??null}function ve(e,n,t){let o=e.getAttribute(n);if(!o)return t;let r=parseFloat(o);return Number.isFinite(r)?r:t}function et(e,n,t){return e.getAttribute(n)??t}function St(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 Vl(e){if(e.length===0)return e;let n=(0,he.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let i=s=>[s[0]-t,s[1]-o,s[2]-r];return e.map(s=>({...s,vertices:s.vertices.map(i)}))}var Ve=class extends Il{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:St(this,"position"),scale:(()=>{let i=this.getAttribute("scale");if(!i)return;if(i.includes(","))return St(this,"scale");let s=parseFloat(i);return Number.isFinite(s)?s:void 0})(),rotation:St(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=Fl(this);if(!t)return;let o=t.getScene?.();if(!o)return;let r=this.buildPolygons();this.hasAttribute("auto-center")&&(r=Vl(r));let i={polygons:r,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(i,{position:St(this,"position"),scale:(()=>{let s=this.getAttribute("scale");if(!s)return;if(s.includes(","))return St(this,"scale");let c=parseFloat(s);return Number.isFinite(c)?c:void 0})(),rotation:St(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow"),excludeFromAutoCenter:this.hasAttribute("exclude-from-auto-center"),merge:!1})}},xn=class extends Ve{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("size"),t=n?parseFloat(n):void 0;return(0,he.boxPolygons)({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:et(this,"color")})}},Pn=class extends Ve{static get observedAttributes(){return["axis","size","offset","color","auto-center","position","scale","rotation","cast-shadow","receive-shadow"]}buildPolygons(){let n=ve(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("offset"),r=o===null?0:parseFloat(o);return(0,he.planePolygons)({axis:t,size:ve(this,"size",.4),offset:Number.isFinite(r)?r:0,color:et(this,"color")})}},Sn=class extends Ve{static get observedAttributes(){return["axis","radius","segments","half-thickness","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=ve(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("half-thickness");return(0,he.ringPolygons)({axis:t,radius:ve(this,"radius",50),segments:ve(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:et(this,"color")})}},Cn=class extends Ve{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.octahedronPolygons)({center:St(this,"center")??[0,0,0],size:ve(this,"size",50),color:et(this,"color")})}},En=class extends Ve{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.tetrahedronPolygons)({size:ve(this,"size",100),color:et(this,"color")})}},Tn=class extends Ve{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.icosahedronPolygons)({size:ve(this,"size",100),color:et(this,"color")})}},An=class extends Ve{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.dodecahedronPolygons)({size:ve(this,"size",100),color:et(this,"color")})}},Mn=class extends Ve{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.spherePolygons)({radius:ve(this,"radius",50),subdivisions:ve(this,"subdivisions",1),color:et(this,"color")})}},wn=class extends Ve{static get observedAttributes(){return["radius","radius-top","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("radius-top");return(0,he.cylinderPolygons)({radius:ve(this,"radius",50),radiusTop:n?parseFloat(n):void 0,height:ve(this,"height",100),radialSegments:ve(this,"radial-segments",12),color:et(this,"color")})}},Ln=class extends Ve{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.conePolygons)({radius:ve(this,"radius",50),height:ve(this,"height",100),radialSegments:ve(this,"radial-segments",12),color:et(this,"color")})}},_n=class extends Ve{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.torusPolygons)({radius:ve(this,"radius",50),tube:ve(this,"tube",15),radialSegments:ve(this,"radial-segments",12),tubularSegments:ve(this,"tubular-segments",16),color:et(this,"color")})}};typeof customElements<"u"&&(customElements.get("poly-scene")||customElements.define("poly-scene",_e),customElements.get("poly-mesh")||customElements.define("poly-mesh",xt),customElements.get("poly-iframe")||customElements.define("poly-iframe",ln),customElements.get("poly-polygon")||customElements.define("poly-polygon",cn),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",dn),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",un),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",mn),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",fn),customElements.get("poly-first-person-controls")||customElements.define("poly-first-person-controls",hn),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",gn),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",Pt),customElements.get("poly-camera")||customElements.define("poly-camera",yn),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",bn),customElements.get("poly-select")||customElements.define("poly-select",vn),customElements.get("poly-box")||customElements.define("poly-box",xn),customElements.get("poly-plane")||customElements.define("poly-plane",Pn),customElements.get("poly-ring")||customElements.define("poly-ring",Sn),customElements.get("poly-octahedron")||customElements.define("poly-octahedron",Cn),customElements.get("poly-tetrahedron")||customElements.define("poly-tetrahedron",En),customElements.get("poly-sphere")||customElements.define("poly-sphere",Mn),customElements.get("poly-icosahedron")||customElements.define("poly-icosahedron",Tn),customElements.get("poly-dodecahedron")||customElements.define("poly-dodecahedron",An),customElements.get("poly-cylinder")||customElements.define("poly-cylinder",wn),customElements.get("poly-cone")||customElements.define("poly-cone",Ln),customElements.get("poly-torus")||customElements.define("poly-torus",_n));0&&(module.exports={PolyAxesHelperElement,PolyBoxElement,PolyCameraElement,PolyConeElement,PolyCylinderElement,PolyDirectionalLightHelperElement,PolyDodecahedronElement,PolyFirstPersonControlsElement,PolyIcosahedronElement,PolyIframeElement,PolyMapControlsElement,PolyMeshElement,PolyOctahedronElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPlaneElement,PolyPolygonElement,PolyRingElement,PolySceneElement,PolySelectElement,PolySphereElement,PolyTetrahedronElement,PolyTorusElement,PolyTransformControlsElement});
|