@layoutit/polycss 0.0.1 → 0.2.0
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 +3 -2
- package/dist/{PolySelectElement-DCuYJb5J.d.cts → PolySelectElement-Tvsmhx2m.d.cts} +60 -8
- package/dist/{PolySelectElement-DCuYJb5J.d.ts → PolySelectElement-Tvsmhx2m.d.ts} +60 -8
- package/dist/elements.cjs +192 -38
- package/dist/elements.d.cts +1 -1
- package/dist/elements.d.ts +1 -1
- package/dist/elements.js +192 -38
- package/dist/index.cjs +192 -38
- package/dist/index.d.cts +83 -3
- package/dist/index.d.ts +83 -3
- package/dist/index.js +192 -38
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Je=Object.defineProperty;var Jt=Object.getOwnPropertyDescriptor;var Qt=Object.getOwnPropertyNames;var en=Object.prototype.hasOwnProperty;var tn=(e,n)=>{for(var t in n)Je(e,t,{get:n[t],enumerable:!0})},Ke=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Qt(n))!en.call(e,r)&&r!==t&&Je(e,r,{get:()=>n[r],enumerable:!(o=Jt(n,r))||o.enumerable});return e},U=(e,n,t)=>(Ke(e,n,"default"),t&&Ke(t,n,"default"));var nn=e=>Ke(Je({},"__esModule",{value:!0}),e);var $={};tn($,{PolyMapControlsElement:()=>Ue,PolyMeshElement:()=>ye,PolyOrbitControlsElement:()=>$e,PolyOrthographicCameraElement:()=>Ze,PolyPerspectiveCameraElement:()=>We,PolyPolygonElement:()=>Fe,PolySceneElement:()=>K,PolySelectElement:()=>je,PolyTransformControlsElement:()=>Ge,createPolyMapControls:()=>Re,createPolyOrbitControls:()=>De,createPolyOrthographicCamera:()=>Se,createPolyPerspectiveCamera:()=>be,createPolyScene:()=>Le,createSelect:()=>Ie,createTransformControls:()=>ze,injectPolyBaseStyles:()=>Te});module.exports=nn($);var q=require("@layoutit/polycss-core");var nt=require("@layoutit/polycss-core"),ot=50,bt=[.4,-.7,.59],vt="#ffffff",xt=1,Pt="#ffffff",At=.4,pe=4096,ft=1,on=.1,rn=1,Et=pe*pe,sn=Et*3,Qe=2048,et=16*1024*1024,an=.995,ue=new Map,tt=new WeakMap,B=.001,ee=1e-9,ln=1e-4,cn=.1,un=.75,dn=0,pn=.45,mn=3,fn=2;function hn(e){let n=ue.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),ue.set(e,n),n.then(()=>{ue.get(e)===n&&ue.delete(e)},()=>{ue.get(e)===n&&ue.delete(e)})),n}function Ce(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(rn,Math.max(on,n))}function Ct(e,n){let t=e.toFixed(n).replace(/\.?0+$/,"");return Object.is(Number(t),-0)?"0":t}function Mt(e,n=mn){return e.map(t=>Ct(t,n)).join(",")}function Pe(e,n=fn){return`${Ct(e,n)}%`}function Tt(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function yn(e){let n=Tt(e);if(n<=0)return 1;let t=Math.max(1,...e.map(s=>Math.max(s.width,s.height))),o=Qe/t,r=Math.sqrt(et/(n*4));return Ce(Math.min(o,r))}function gn(e){let n=Tt(e),t=.5;return n<=Et?t=1:n<=sn&&(t=.75),Ce(Math.min(t,yn(e)))}function bn(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function vn(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function xn(e,n){let t=bn(e,n),o=vn(e,n),r=t>Qe?Qe/t:1,s=o>et?Math.sqrt(et/o):1;return Math.min(r,s)}function Pn(e,n){let t=gn(n.pages),o=t===1?n:Ee(e,t);for(let r=0;r<4;r++){let s=xn(o.pages,t);if(s>=1)break;let i=Ce(t*s*an);if(i>=t)break;t=i,o=Ee(e,t)}return{packed:o,atlasScale:t}}function An(e,n){if(n!==void 0&&n!=="auto"){let o=Ce(n);return{packed:Ee(e,o),atlasScale:o}}let t=Ee(e,1);return Pn(e,t)}function En(e){return Math.max(ft,Math.ceil(ft/e))}function te(e,n,t=1,o=0,r=0,s=1,i=0,c=0){e.setTransform(t*n,o*n,r*n,s*n,i*n,c*n)}function ie(e){let n=(0,nt.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function Cn(e){return(0,nt.parsePureColor)(e)?.alpha??1}function Mn({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function Lt(e,n,t,o,r){let s=ie(e),i=ie(t),c=ie(o),l=c.r/255*r+i.r/255*n,a=c.g/255*r+i.g/255*n,d=c.b/255*r+i.b/255*n,m=Math.max(0,Math.min(255,Math.round(s.r*l))),f=Math.max(0,Math.min(255,Math.round(s.g*a))),h=Math.max(0,Math.min(255,Math.round(s.b*d))),u=Cn(e);return u<1?`rgba(${m}, ${f}, ${h}, ${u})`:Mn({r:m,g:f,b:h})}function Tn(e,n,t,o){let r=ie(n),s=ie(t);return{r:s.r/255*o+r.r/255*e,g:s.g/255*o+r.g/255*e,b:s.b/255*o+r.b/255*e}}function Ln({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(1,r))*255);return`rgb(${o(e)} ${o(n)} ${o(t)})`}function Sn(e,n,t,o,r,s,i){Math.abs(s.r-1)<.001&&Math.abs(s.g-1)<.001&&Math.abs(s.b-1)<.001||(e.save(),te(e,i),e.globalCompositeOperation="multiply",e.fillStyle=Ln(s),e.fillRect(n,t,o,r),e.restore())}function _n(e,n,t,o,r,s,i){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,a=Math.max(r/c,s/l),d=c*a,m=l*a;te(e,i),e.drawImage(n,t+(r-d)/2,o+(s-m)/2,d,m)}function Ae(e){return`${e[0]},${e[1]},${e[2]}`}function wn(e,n){let t=Ae(e),o=Ae(n);return t<o?`${t}|${o}`:`${o}|${t}`}function St(e,n){return Ae(e)<Ae(n)?[n[0]-e[0],n[1]-e[1],n[2]-e[2]]:[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function On(e){return!e.texture}function Me(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function rt(e){if(e.length<3)return null;let n=e[0],t=e[1],o=e[2],r=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],s=[o[0]-n[0],o[1]-n[1],o[2]-n[2]],i=-(r[1]*s[2]-r[2]*s[1]),c=-(r[2]*s[0]-r[0]*s[2]),l=-(r[0]*s[1]-r[1]*s[0]),a=Math.hypot(i,c,l);return a<=ee?null:(i/=a,c/=a,l/=a,[i,c,l])}function me(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function kn(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Hn(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=Me(e.vertices,n,t),r=rt(o);return r?{pts:o,normal:r,planeD:me(r,o[0]),optimizable:On(e)}:null}function Dn(e,n){return!e||!n||!e.optimizable||!n.optimizable||me(e.normal,n.normal)<1-ln?!1:Math.abs(e.planeD-n.planeD)<=cn}function Rn(e){let n=[...e],t=Math.abs(n[0])>ee?0:Math.abs(n[1])>ee?1:2;return n[t]<0&&(n[0]*=-1,n[1]*=-1,n[2]*=-1),`${n[0].toFixed(6)},${n[1].toFixed(6)},${n[2].toFixed(6)}`}function ge(e,n,t,o,r={}){let s=me(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],c=Math.hypot(i[0],i[1],i[2]);if(c<=ee)return null;let l=[i[0]/c,i[1]/c,i[2]/c],a=[t[1]*l[2]-t[2]*l[1],t[2]*l[0]-t[0]*l[2],t[0]*l[1]-t[1]*l[0]],d=Math.hypot(a[0],a[1],a[2]);if(d<=ee)return null;let m=[a[0]/d,a[1]/d,a[2]/d],f=e.map(A=>{let P=A[0]-n[0],D=A[1]-n[1],k=A[2]-n[2];return[P*l[0]+D*l[1]+k*l[2],P*m[0]+D*m[1]+k*m[2]]}),h=r.boundsOrigin??n,u=n[0]-h[0],p=n[1]-h[1],b=n[2]-h[2],x=u*l[0]+p*l[1]+b*l[2],C=u*m[0]+p*m[1]+b*m[2],M=1/0,H=1/0,y=-1/0,g=-1/0;for(let[A,P]of f){let D=A+x,k=P+C;D<M&&(M=D),D>y&&(y=D),k<H&&(H=k),k>g&&(g=k)}let _=y-M,E=g-H;if(!Number.isFinite(_)||!Number.isFinite(E))return null;let w=r.snapBounds?Math.floor(M+B):M,S=r.snapBounds?Math.floor(H+B):H,v=r.snapBounds?Math.ceil(y-B):y,O=r.snapBounds?Math.ceil(g-B):g,T=Math.max(1,r.snapBounds?v-w:Math.ceil(_)),R=Math.max(1,r.snapBounds?O-S:Math.ceil(E));return{xAxis:l,yAxis:m,local2D:f,shiftX:x-w,shiftY:C-S,canvasW:T,canvasH:R,pixelArea:T*R,rawArea:_*E}}function In(e,n,t,o){let r=0,s=0;for(let i of e){let c=n[i];if(!c)return null;let l=ge(c.pts,c.pts[0],c.normal,t,{boundsOrigin:o,snapBounds:!0});if(!l)return null;r+=l.pixelArea,s+=l.rawArea}return{pixelArea:r,rawArea:s}}function Vn(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,s=new Set;for(let i of e){let c=n[i];if(!c)continue;let l=[c.pts[1][0]-c.pts[0][0],c.pts[1][1]-c.pts[0][1],c.pts[1][2]-c.pts[0][2]],a=ge(c.pts,c.pts[0],c.normal,l);o&&a?(o.pixelArea+=a.pixelArea,o.rawArea+=a.rawArea):o=null;for(let d=0;d<c.pts.length;d++){let m=St(c.pts[d],c.pts[(d+1)%c.pts.length]),f=ge(c.pts,c.pts[0],c.normal,m);if(!f)continue;let h=Rn(f.xAxis);if(s.has(h))continue;s.add(h);let u=In(e,n,f.xAxis,t);u&&(!r||u.pixelArea<r.pixelArea||u.pixelArea===r.pixelArea&&u.rawArea<r.rawArea-B)&&(r={xAxis:f.xAxis,...u})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+B)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function zn(e,n){let t=n.tileSize??ot,o=n.layerElevation??t,r=e.map(d=>Hn(d,t,o)),s=new Map,i=e.map(()=>new Set);for(let d=0;d<e.length;d++){let m=e[d].vertices;if(!(!m||m.length<3))for(let f=0;f<m.length;f++){let h=wn(m[f],m[(f+1)%m.length]),u=s.get(h),p={polygon:d,edge:f};u?u.push(p):s.set(h,[p])}}let c=e.map(()=>new Set);for(let d of s.values())if(!(d.length<2)){for(let m of d)i[m.polygon].add(m.edge);for(let m=0;m<d.length;m++)for(let f=m+1;f<d.length;f++){let h=d[m].polygon,u=d[f].polygon;Dn(r[h],r[u])&&(c[h].add(u),c[u].add(h))}}let l=Array(e.length).fill(void 0),a=new Set;for(let d=0;d<e.length;d++){if(a.has(d)||!r[d]?.optimizable)continue;let m=[],f=[d];for(a.add(d);f.length>0;){let u=f.pop();m.push(u);for(let p of c[u])a.has(p)||(a.add(p),f.push(p))}if(m.length<2)continue;let h=Vn(m,r);if(h)for(let u of m)l[u]={xAxis:h.xAxis,boundsOrigin:h.boundsOrigin,seamEdges:i[u]}}for(let d=0;d<e.length;d++)!l[d]&&i[d].size>0&&(l[d]={seamEdges:i[d]});return l}function Bn(e){if(typeof e.toBlob=="function")return new Promise(n=>{e.toBlob(t=>{n(t?URL.createObjectURL(t):null)},"image/png")});try{return Promise.resolve(e.toDataURL("image/png"))}catch{return Promise.resolve(null)}}function ht(e,n,t,o){if(o.optimize&&o.fixedXAxis)return ge(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,s=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,i=s??(o.optimize?e.map((c,l)=>l):[0]);for(let c of i){let l=(c+1)%e.length,a=s?St(e[c],e[l]):[e[l][0]-e[c][0],e[l][1]-e[c][1],e[l][2]-e[c][2]],d=ge(e,n,t,a,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});d&&(!r||d.pixelArea<r.pixelArea||d.pixelArea===r.pixelArea&&d.rawArea<r.rawArea-B)&&(r=d)}return r}function Fn(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=B)return;r.push(s)};for(let[r,s]of e.local2D)o(n,r+e.shiftX),o(t,s+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>B||Math.abs(t[0])>B||n[1]-n[0]<=B||t[1]-t[0]<=B))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,c=s+e.shiftY,l=Math.abs(i-n[0])<=B||Math.abs(i-n[1])<=B,a=Math.abs(c-t[0])<=B||Math.abs(c-t[1])<=B;if(!l||!a)return!1}return!0}function _t(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,c]=n,l=t[0],a=t[1],d=o[0],m=o[1],f=r[0],h=r[1],u=s[0],p=1-s[1],b=i[0],x=1-i[1],C=c[0],M=1-c[1],H=b-u,y=x-p,g=C-u,_=M-p,E=H*_-g*y;if(Math.abs(E)<=1e-9)return null;let w=d-l,S=f-l,v=m-a,O=h-a,T={a:(w*_-S*y)/E,b:(H*S-g*w)/E,c:(v*_-O*y)/E,d:(H*O-g*v)/E,e:0,f:0};return T.e=l-T.a*u-T.b*p,T.f=a-T.c*u-T.d*p,T}function wt(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let s of e){let i=s[0],c=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(c))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,c),r=Math.max(r,c)}return{minU:n,minV:t,maxU:o,maxV:r}}function Nn(e,n,t,o,r,s,i,c){let a=Me(e.vertices,n,t).map(f=>{let h=f[0]-o[0],u=f[1]-o[1],p=f[2]-o[2];return[h*r[0]+u*r[1]+p*r[2]+i,h*s[0]+u*s[1]+p*s[2]+c]}),d=_t(a,e.uvs),m=wt(e.uvs);return!d&&!m?null:{screenPts:a.flatMap(([f,h])=>[f,h]),uvAffine:d,uvSampleRect:m}}function Xn(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],o+=e[i+1];t/=r,o/=r;let s=e.slice();for(let i=0;i<s.length;i+=2){let c=s[i]-t,l=s[i+1]-o,a=Math.hypot(c,l);a<=B||(s[i]+=c/a*n,s[i+1]+=l/a*n)}return s}function Yn(e){let n=0;for(let t=0;t<e.length;t+=2){let o=(t+2)%e.length;n+=e[t]*e[o+1]-e[o]*e[t+1]}return n/2}function st(e,n,t,o){for(let r=0;r<o.length;r+=2){let s=n+o[r],i=t+o[r+1];r===0?e.moveTo(s,i):e.lineTo(s,i)}e.closePath()}function $n(e,n,t,o,r,s){if(st(e,n,t,o),!r||r.size===0||s<=0)return;let i=o.length/2,c=Yn(o);for(let l of r){let a=l*2,d=(l+1)%i*2,m=o[a],f=o[a+1],h=o[d],u=o[d+1],p=h-m,b=u-f,x=Math.hypot(p,b);if(x<=B)continue;let C=c>=0?b/x:-b/x,M=c>=0?-p/x:p/x;e.moveTo(n+m,t+f),e.lineTo(n+h,t+u),e.lineTo(n+h+C*s,t+u+M*s),e.lineTo(n+m+C*s,t+f+M*s),e.closePath()}}function Un(e,n,t,o){let{vertices:r,texture:s,uvs:i}=e;if(!r||r.length<3)return null;let c=t.tileSize??ot,l=t.layerElevation??c,a=Me(r,c,l),d=a[0],m=a[1],f=[m[0]-d[0],m[1]-d[1],m[2]-d[2]];if(Math.hypot(f[0],f[1],f[2])===0)return null;let u=rt(a);if(!u)return null;let p=ht(a,d,u,{optimize:!1}),b=s||p&&Fn(p)?p:ht(a,d,u,{optimize:!0,fixedXAxis:o?.xAxis,boundsOrigin:o?.boundsOrigin,snapBounds:!!o,seamEdges:o?.seamEdges});if(!b)return null;let{xAxis:x,yAxis:C,local2D:M,shiftX:H,shiftY:y}=b,g=[];for(let[Y,z]of M)g.push(Y+H,z+y);let _=d[0]-H*x[0]-y*C[0],E=d[1]-H*x[1]-y*C[1],w=d[2]-H*x[2]-y*C[2],S=Mt([x[0],x[1],x[2],0,C[0],C[1],C[2],0,u[0],u[1],u[2],0,_,E,w,1]),v=t.directionalLight,O=t.ambientLight,T=v?.direction??bt,R=v?.color??vt,A=Math.max(0,v?.intensity??xt),P=O?.color??Pt,D=Math.max(0,O?.intensity??At),k=Math.hypot(T[0],T[1],T[2])||1,F=T[0]/k,j=T[1]/k,L=T[2]/k,I=A*Math.max(0,u[0]*F+u[1]*j+u[2]*L),V=Tn(I,R,P,D),X=Lt(e.color??"#cccccc",I,R,P,D),W=null,Z=null;s&&i&&i.length>=3&&i.length===r.length&&(Z=wt(i),W=_t(M.map(([Y,z])=>[Y+H,z+y]),i));let G=s&&e.textureTriangles?.length?e.textureTriangles.map(Y=>Nn(Y,c,l,d,x,C,H,y)).filter(Y=>!!Y):null;return{index:n,polygon:e,texture:s,tileSize:c,layerElevation:l,matrix:S,canvasW:b.canvasW,canvasH:b.canvasH,screenPts:g,uvAffine:W,uvSampleRect:Z,textureTriangles:G,seamEdges:o?.seamEdges.size?o.seamEdges:null,normal:u,textureTint:V,shadedColor:X}}function Ot(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??ot,r=t.layerElevation??o,s=Me(e.vertices,o,r),i=rt(s);if(!i)return null;let c=[{a:0,b:1,c:2},{a:1,b:2,c:0},{a:2,b:0,c:1}].map(Q=>{let J=s[Q.a],re=s[Q.b];return{...Q,length:Math.hypot(re[0]-J[0],re[1]-J[1],re[2]-J[2])}}).sort((Q,J)=>J.length-Q.length),l=c[0].a,a=c[0].b,d=c[0].c,m=s[l],f=s[a],h=s[d],u=c[0].length;if(u<=ee)return null;let p=[(f[0]-m[0])/u,(f[1]-m[1])/u,(f[2]-m[2])/u],b=[h[0]-m[0],h[1]-m[1],h[2]-m[2]],x=me(b,p),C=[m[0]+p[0]*x,m[1]+p[1]*x,m[2]+p[2]*x],M=[C[0]-h[0],C[1]-h[1],C[2]-h[2]],H=Math.hypot(M[0],M[1],M[2]);if(H<=ee)return null;let y=[M[0]/H,M[1]/H,M[2]/H];if(me(kn(p,y),i)<0){let Q=a;if(a=l,l=Q,m=s[l],f=s[a],u=Math.hypot(f[0]-m[0],f[1]-m[1],f[2]-m[2]),u<=ee)return null;p=[(f[0]-m[0])/u,(f[1]-m[1])/u,(f[2]-m[2])/u];let J=[h[0]-m[0],h[1]-m[1],h[2]-m[2]];x=me(J,p),C=[m[0]+p[0]*x,m[1]+p[1]*x,m[2]+p[2]*x],M=[C[0]-h[0],C[1]-h[1],C[2]-h[2]];let re=Math.hypot(M[0],M[1],M[2]);if(re<=ee)return null;y=[M[0]/re,M[1]/re,M[2]/re]}let g=Math.max(0,Math.min(u,x)),_=Math.max(0,u-g),E=pn,w=g+E,S=_+E,v=H+E*2,O=h[0]-w*p[0]-E*y[0],T=h[1]-w*p[1]-E*y[1],R=h[2]-w*p[2]-E*y[2],A=Mt([p[0],p[1],p[2],0,y[0],y[1],y[2],0,i[0],i[1],i[2],0,O,T,R,1]),P=t.directionalLight,D=t.ambientLight,k=P?.direction??bt,F=P?.color??vt,j=Math.max(0,P?.intensity??xt),L=D?.color??Pt,I=Math.max(0,D?.intensity??At),V=Math.hypot(k[0],k[1],k[2])||1,X=k[0]/V,W=k[1]/V,Z=k[2]/V,G=j*Math.max(0,i[0]*X+i[1]*W+i[2]*Z),Y=Lt(e.color??"#cccccc",G,F,L,I),z=t.textureLighting??"baked",ne=ie(e.color??"#cccccc"),ce=z==="dynamic"?"":`border-bottom-color:${Y};`,oe=z==="dynamic"?`--pnx:${i[0].toFixed(4)};--pny:${i[1].toFixed(4)};--pnz:${i[2].toFixed(4)};--psr:${(ne.r/255).toFixed(4)};--psg:${(ne.g/255).toFixed(4)};--psb:${(ne.b/255).toFixed(4)};`:"",qe=`transform:matrix3d(${A});border-width:0 ${S}px ${v}px ${w}px;`+ce+oe;return{index:n,polygon:e,styleText:qe}}function Ee(e,n=1){let t=Array(e.length).fill(null),o=[],r=En(n),s=e.filter(l=>!!l).sort((l,a)=>a.canvasH-l.canvasH||a.canvasW-l.canvasW||l.index-a.index),i=()=>({width:r,height:r,entries:[],shelves:[]}),c=(l,a,d)=>{if(l.sealed)return null;for(let h of l.shelves)if(a.canvasH<=h.height&&h.x+a.canvasW+r<=pe){let u={...a,pageIndex:d,x:h.x,y:h.y};return h.x+=a.canvasW+r*2,l.entries.push(u),l.width=Math.max(l.width,u.x+a.canvasW+r),u}let m=l.shelves.length===0?r:l.height+r;if(m+a.canvasH+r>pe)return null;let f={...a,pageIndex:d,x:r,y:m};return l.shelves.push({x:r+a.canvasW+r*2,y:m,height:a.canvasH}),l.entries.push(f),l.width=Math.max(l.width,f.x+a.canvasW+r),l.height=Math.max(l.height,m+a.canvasH+r),f};for(let l of s){if(l.canvasW+r*2>pe||l.canvasH+r*2>pe){let m=o.length,f={...l,pageIndex:m,x:r,y:r};t[l.index]=f,o.push({width:l.canvasW+r*2,height:l.canvasH+r*2,entries:[f],shelves:[],sealed:!0});continue}let d=null;for(let m=0;m<o.length&&(d=c(o[m],l,m),!d);m++);if(!d){let m=i(),f=o.length;o.push(m),d=c(m,l,f)}d&&(t[l.index]=d)}return{entries:t,pages:o.map(({width:l,height:a,entries:d})=>({width:l,height:a,entries:d}))}}function Wn(e,n,t,o){te(e,o),e.beginPath(),st(e,n.x,n.y,n.screenPts),e.clip(),te(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function de(e,n){return Math.max(0,Math.min(n,e))}function yt(e,n,t,o,r,s,i,c){let l=n.naturalWidth||n.width||1,a=n.naturalHeight||n.height||1,d=de(Math.min(t.minU,t.maxU)*l,l),m=de(Math.max(t.minU,t.maxU)*l,l),f=de(Math.min(t.minV,t.maxV)*a,a),h=de(Math.max(t.minV,t.maxV)*a,a),u=Math.floor(d),p=Math.floor(f),b=Math.ceil(m)-u,x=Math.ceil(h)-p;b<1&&(u=Math.floor(de((t.minU+t.maxU)/2*l,l-1)),b=1),x<1&&(p=Math.floor(de((t.minV+t.maxV)/2*a,a-1)),x=1),u=Math.max(0,Math.min(l-1,u)),p=Math.max(0,Math.min(a-1,p)),b=Math.max(1,Math.min(l-u,b)),x=Math.max(1,Math.min(a-p,x)),te(e,c),e.drawImage(n,u,p,b,x,o,r,s,i)}async function Zn(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=r.getContext("2d");if(!s)return{width:e.width,height:e.height,url:null};let i=Array.from(new Set(e.entries.flatMap(a=>a.texture?[a.texture]:[]))),c=new Map;await Promise.all(i.map(async a=>{c.set(a,await hn(a))}));for(let a of e.entries){let d=a.texture?c.get(a.texture):null;if(s.save(),te(s,o),s.beginPath(),a.texture?$n(s,a.x,a.y,a.screenPts,a.seamEdges,dn):st(s,a.x,a.y,a.screenPts),s.clip(),!a.texture)Wn(s,a,n,o);else if(d&&a.textureTriangles?.length){let m=d.naturalWidth||d.width||1,f=d.naturalHeight||d.height||1;for(let h of a.textureTriangles){let u=Xn(h.screenPts,un);s.save(),te(s,o),s.beginPath();for(let p=0;p<u.length;p+=2){let b=a.x+u[p],x=a.y+u[p+1];p===0?s.moveTo(b,x):s.lineTo(b,x)}s.closePath(),s.clip(),h.uvAffine?(te(s,o,h.uvAffine.a/m,h.uvAffine.c/m,h.uvAffine.b/f,h.uvAffine.d/f,a.x+h.uvAffine.e,a.y+h.uvAffine.f),s.drawImage(d,0,0)):h.uvSampleRect&&yt(s,d,h.uvSampleRect,a.x,a.y,a.canvasW,a.canvasH,o),s.restore()}}else if(d&&a.uvAffine){let m=d.naturalWidth||d.width||1,f=d.naturalHeight||d.height||1;te(s,o,a.uvAffine.a/m,a.uvAffine.c/m,a.uvAffine.b/f,a.uvAffine.d/f,a.x+a.uvAffine.e,a.y+a.uvAffine.f),s.drawImage(d,0,0)}else d&&a.uvSampleRect?yt(s,d,a.uvSampleRect,a.x,a.y,a.canvasW,a.canvasH,o):d&&_n(s,d,a.x,a.y,a.canvasW,a.canvasH,o);a.texture&&n==="baked"&&Sn(s,a.x,a.y,a.canvasW,a.canvasH,a.textureTint,o),s.restore()}let l=await Bn(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:l}}async function Gn(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await Zn(i,n,t,o))}return s}function jn(e,n,t,o){if(!n.url)return;let r=`url(${n.url})`,s=`-${o.x}px -${o.y}px`,i=`${n.width}px ${n.height}px`;t==="dynamic"?(e.style.backgroundImage=r,e.style.backgroundPosition=s,e.style.backgroundSize=i):e.style.background=`${r} ${s} / ${i} no-repeat`,t==="dynamic"?(e.style.maskImage=r,e.style.maskMode="alpha",e.style.maskPosition=s,e.style.maskSize=i,e.style.maskRepeat="no-repeat",e.style.setProperty("-webkit-mask-image",r),e.style.setProperty("-webkit-mask-position",s),e.style.setProperty("-webkit-mask-size",i),e.style.setProperty("-webkit-mask-repeat","no-repeat")):(e.style.maskImage="",e.style.maskMode="",e.style.maskPosition="",e.style.maskSize="",e.style.maskRepeat="",e.style.removeProperty("-webkit-mask-image"),e.style.removeProperty("-webkit-mask-position"),e.style.removeProperty("-webkit-mask-size"),e.style.removeProperty("-webkit-mask-repeat"))}function it(e,n){let t=tt.get(e);if(t)for(let r of t)e.removeAttribute(`data-${r}`);let o=[];if(n.data)for(let[r,s]of Object.entries(n.data))e.setAttribute(`data-${r}`,String(s)),o.push(r);tt.set(e,o)}function at(e,n){e.style.width=`${n.canvasW}px`,e.style.height=`${n.canvasH}px`,e.style.transform=`matrix3d(${n.matrix})`,it(e,n.polygon)}function kt(e,n){e.style.setProperty("--pnx",n.normal[0].toFixed(4)),e.style.setProperty("--pny",n.normal[1].toFixed(4)),e.style.setProperty("--pnz",n.normal[2].toFixed(4))}function qn(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=B)return;r.push(s)};for(let r=0;r<e.screenPts.length;r+=2)o(n,e.screenPts[r]),o(t,e.screenPts[r+1]);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>B||Math.abs(t[0])>B||n[1]-n[0]<=B||t[1]-t[0]<=B))return null;for(let r=0;r<e.screenPts.length;r+=2){let s=e.screenPts[r],i=e.screenPts[r+1],c=Math.abs(s-n[0])<=B||Math.abs(s-n[1])<=B,l=Math.abs(i-t[0])<=B||Math.abs(i-t[1])<=B;if(!c||!l)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function gt(e){return!!qn(e)}function Kn(e){return!e.texture&&e.polygon.vertices.length===3}function Jn(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) polygon(50% 50%, 50% 50%, 50% 50%)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function Qn(e){let n=[],t=e.canvasW||1,o=e.canvasH||1;for(let r=0;r<e.screenPts.length;r+=2){let s=Math.max(0,Math.min(100,e.screenPts[r]/t*100)),i=Math.max(0,Math.min(100,e.screenPts[r+1]/o*100));n.push(`${Pe(s)} ${Pe(i)}`)}return`polygon(${n.join(", ")})`}function eo(e){let n=0,t=0,o=Math.max(1,e.screenPts.length/2);for(let l=0;l<e.screenPts.length;l+=2)n+=e.screenPts[l],t+=e.screenPts[l+1];let r=e.canvasW||1,s=e.canvasH||1,i=Pe(Math.max(0,Math.min(100,n/o/r*100))),c=Pe(Math.max(0,Math.min(100,t/o/s*100)));return`polygon(${Array.from({length:o},()=>`${i} ${c}`).join(", ")})`}function to(e){return`${Qn(e)} ${eo(e)}`}function no(e,n,t){if(t==="dynamic"){kt(e,n);let o=ie(n.polygon.color??"#cccccc");e.style.setProperty("--psr",(o.r/255).toFixed(4)),e.style.setProperty("--psg",(o.g/255).toFixed(4)),e.style.setProperty("--psb",(o.b/255).toFixed(4))}else e.style.background=n.shadedColor}function oo(e,n,t){let o=t.createElement("b");return at(o,e),no(o,e,n),o}function ro(e,n){let t=n.createElement("i");return at(t,e),t.style.color=e.shadedColor,t.style.setProperty("border-shape",to(e)),t}function so(e,n,t){let o=t.createElement("s");return at(o,e),o.style.backgroundPosition=`-${e.x}px -${e.y}px`,o.style.opacity="0",n==="dynamic"&&kt(o,e),o}function Ht(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=o!=="dynamic"&&Jn(t),s=zn(e,n),i=e.map((p,b)=>Un(p,b,n,s[b])),c=i.map(p=>p&&Kn(p)?Ot(p.polygon,p.index,n):null),l=i.map((p,b)=>p&&(p.texture||!gt(p)&&!c[b]&&!r?p:null)),{packed:a,atlasScale:d}=An(l,n.atlasScale),m=new Map,f=[],h=!1,u=[];for(let p=0;p<e.length;p++){let b=i[p],x=c[p];if(!b)continue;let C=a.entries[p];if(C){let M=so(C,o,t);m.set(p,M),f.push({polygonIndex:p,element:M,kind:"atlas",dispose:()=>{}})}else if(!b.texture&>(b)){let M=oo(b,o,t);f.push({polygonIndex:p,element:M,kind:"solid",dispose:()=>{}})}else if(!b.texture&&x){let M=It(x,t);f.push({polygonIndex:p,element:M,kind:"triangle",dispose:()=>{}})}else if(!b.texture&&r){let M=ro(b,t);f.push({polygonIndex:p,element:M,kind:"border",dispose:()=>{}})}}return f.sort((p,b)=>p.polygonIndex-b.polygonIndex),Gn(a.pages,o,t,d,()=>h).then(p=>{if(h){for(let b of p)b.url?.startsWith("blob:")&&URL.revokeObjectURL(b.url);return}u=p.flatMap(b=>b.url?.startsWith("blob:")?[b.url]:[]);for(let b=0;b<a.pages.length;b++){let x=a.pages[b],C=p[b];if(C)for(let M of x.entries){let H=m.get(M.index);!H||!C.url||(jn(H,C,o,M),H.style.opacity="")}}}).catch(()=>{if(!h)for(let p of m.values())p.style.opacity="0.5",p.style.outline="1px dashed rgba(255, 0, 0, 0.6)"}),{rendered:f,dispose(){h=!0;for(let p of u)URL.revokeObjectURL(p);u=[]}}}function Dt(e,n){let t=e.map((o,r)=>Ot(o,r,n));return t.some(o=>!o)?null:t}function io(e){e.style.backgroundImage="",e.style.backgroundPosition="",e.style.backgroundSize="",e.style.maskImage="",e.style.maskMode="",e.style.maskPosition="",e.style.maskSize="",e.style.maskRepeat="",e.style.removeProperty("-webkit-mask-image"),e.style.removeProperty("-webkit-mask-position"),e.style.removeProperty("-webkit-mask-size"),e.style.removeProperty("-webkit-mask-repeat")}function Rt(e,n){e.style.cssText=n.styleText,(n.polygon.data||tt.get(e)?.length)&&it(e,n.polygon)}function It(e,n){let t=n.createElement("u");return io(t),Rt(t,e),it(t,e.polygon),t}function Vt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=Dt(e,n);if(!o)return null;let r=[];for(let s of o){let i=It(s,t);r.push({polygonIndex:s.index,element:i,kind:"triangle",dispose:()=>{}})}return r.sort((s,i)=>s.polygonIndex-i.polygonIndex),{rendered:r,dispose(){}}}function zt(e,n,t={}){if(!(t.doc??(typeof document<"u"?document:null)))return{rendered:e,dispose:()=>{}};if(e.some(s=>s.kind!=="triangle"))return null;let r=Dt(n,t);if(!r||r.length!==e.length)return null;for(let s=0;s<e.length;s++)if(e[s].polygonIndex!==r[s].index)return null;for(let s=0;s<e.length;s++)Rt(e[s].element,r[s]);return{rendered:e,dispose(){}}}var Bt="polycss-styles";function Te(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(Bt))return;let t=n.createElement("style");t.id=Bt,t.textContent=ao,n.head.appendChild(t)}var ao=`
|
|
1
|
+
"use strict";var Xt=Object.defineProperty;var Vo=Object.getOwnPropertyDescriptor;var Fo=Object.getOwnPropertyNames;var zo=Object.prototype.hasOwnProperty;var Bo=(e,n)=>{for(var t in n)Xt(e,t,{get:n[t],enumerable:!0})},Yt=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Fo(n))!zo.call(e,r)&&r!==t&&Xt(e,r,{get:()=>n[r],enumerable:!(o=Vo(n,r))||o.enumerable});return e},he=(e,n,t)=>(Yt(e,n,"default"),t&&Yt(t,n,"default"));var No=e=>Yt(Xt({},"__esModule",{value:!0}),e);var fe={};Bo(fe,{PolyMapControlsElement:()=>It,PolyMeshElement:()=>je,PolyOrbitControlsElement:()=>Ht,PolyOrthographicCameraElement:()=>Ft,PolyPerspectiveCameraElement:()=>Vt,PolyPolygonElement:()=>kt,PolySceneElement:()=>Ce,PolySelectElement:()=>Bt,PolyTransformControlsElement:()=>zt,createPolyFirstPersonControls:()=>So,createPolyMapControls:()=>Et,createPolyOrbitControls:()=>Pt,createPolyOrthographicCamera:()=>yt,createPolyPerspectiveCamera:()=>Ke,createPolyScene:()=>gt,createSelect:()=>Ct,createTransformControls:()=>Tt,injectPolyBaseStyles:()=>pt});module.exports=No(fe);var te=require("@layoutit/polycss-core");var qt=require("@layoutit/polycss-core"),Qt=50,Kt=[.4,-.7,.59],Jt="#ffffff",en=1,tn="#ffffff",nn=.4,ze=4096,Cn=1,Yo=.1,Xo=1,Vn=ze*ze,$o=Vn*3,Gt=2048,Uo=4*1024*1024,Go=16*1024*1024,jo=.995,Wo=12,Ve=new Map,jt=new WeakMap,ie=.001,pe=1e-9,Zo=1e-4,qo=.1,An=.01,Qo=.75,Ko=1,Jo=250,Mn=1.5,er=.75,tr=3,nr=2,or=4,Wt=64,ke=64,Se=64,rr=128,Sn=50,Ln=1e-7,wn=16,$t=.9,sr=.05,ir=Number.POSITIVE_INFINITY,ar=.6;function lr(e){let n=Ve.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),Ve.set(e,n),n.then(()=>{Ve.get(e)===n&&Ve.delete(e)},()=>{Ve.get(e)===n&&Ve.delete(e)})),n}function lt(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Xo,Math.max(Yo,n))}function on(e,n){let t=e.toFixed(n).replace(/\.?0+$/,"");return Object.is(Number(t),-0)?"0":t}function Be(e,n=or){let t=on(e,n);return Number(t)===0||Object.is(Number(t),-0)?"0":`${t}px`}function we(e,n=tr){return e.map(t=>on(t,n)).join(",")}function Fn(e){if(e.length<3)return!1;let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length],s=e[(t+2)%e.length],i=(r[0]-o[0])*(s[1]-r[1])-(r[1]-o[1])*(s[0]-r[0]);if(Math.abs(i)<=pe)return!1;let a=Math.sign(i);if(n===0)n=a;else if(a!==n)return!1}return!0}function cr(e){let n=0;for(let t=0;t<e.length;t++){let o=e[t],r=e[(t+1)%e.length];n+=o[0]*r[1]-o[1]*r[0]}return n/2}function ur(e,n,t,o){let r=n[0]-e[0],s=n[1]-e[1],i=o[0]-t[0],a=o[1]-t[1],l=r*a-s*i;if(Math.abs(l)<=pe)return null;let u=t[0]-e[0],p=t[1]-e[1],d=(u*a-p*i)/l;return[e[0]+d*r,e[1]+d*s]}function rn(e,n){if(e.length<6||e.length%2!==0||n<=0)return e;let t=[];for(let l=0;l<e.length;l+=2)t.push([e[l],e[l+1]]);if(!Fn(t))return Ze(e,n);let o=cr(t);if(Math.abs(o)<=pe)return Ze(e,n);let r=o>0?1:-1,s=[];for(let l=0;l<t.length;l++){let u=t[l],p=t[(l+1)%t.length],d=p[0]-u[0],f=p[1]-u[1],g=Math.hypot(d,f);if(g<=pe)return Ze(e,n);let m=r*(f/g)*n,h=r*(-d/g)*n;s.push({a:[u[0]+m,u[1]+h],b:[p[0]+m,p[1]+h]})}let i=[],a=Math.max(2,n*4);for(let l=0;l<t.length;l++){let u=s[(l+t.length-1)%t.length],p=s[l],d=ur(u.a,u.b,p.a,p.b);if(!d)return Ze(e,n);let f=t[l],g=d[0]-f[0],m=d[1]-f[1],h=Math.hypot(g,m);h>a?i.push(f[0]+g/h*a,f[1]+m/h*a):i.push(d[0],d[1])}return i}function Tn(e,n){return typeof e=="number"&&Number.isFinite(e)?e:n}function sn(e){let t=e?.defaultView?.__polycssProjectiveQuadGuards,o=t?.maxWeightRatio,r=Math.max(0,Tn(t?.denomEps,sr)),s=typeof o=="number"&&Number.isFinite(o)&&o>0?Math.max(1,o):ir,i=Math.max(0,Tn(t?.bleed,ar));return{denomEps:r,maxWeightRatio:s,bleed:i,disableGuards:t?.disableGuards===!0}}function _n(e,n){if(e.length!==4||!Fn(e))return null;let[t,o,r,s]=e,i=t[0]-o[0]+r[0]-s[0],a=t[1]-o[1]+r[1]-s[1],l=o[0]-r[0],u=s[0]-r[0],p=o[1]-r[1],d=s[1]-r[1],f=l*d-p*u;if(Math.abs(f)<=pe)return null;let g=(i*d-a*u)/f,m=(l*a-p*i)/f,h=[1,1+g,1+g+m,1+m];if(h.some(E=>!Number.isFinite(E)))return null;let y=Math.min(...h),v=Math.max(...h);return!n.disableGuards&&(y<=n.denomEps||v/y>n.maxWeightRatio)?null:{g,h:m,w1:1+g,w3:1+m}}function dr(e,n,t,o,r,s,i,a){if(e.length!==8)return null;let l=[[e[0],e[1]],[e[2],e[3]],[e[4],e[5]],[e[6],e[7]]];if(!_n(l,a))return null;let u=rn(e,a.bleed),p=[[u[0],u[1]],[u[2],u[3]],[u[4],u[5]],[u[6],u[7]]],d=_n(p,a);if(!d)return null;let{g:f,h:g,w1:m,w3:h}=d,[y,v,,E]=p,A=[r+y[0]*n[0]+y[1]*t[0],s+y[0]*n[1]+y[1]*t[1],i+y[0]*n[2]+y[1]*t[2]],x=([O,M],P)=>[(P-1)*r+(P*O-y[0])*n[0]+(P*M-y[1])*t[0],(P-1)*s+(P*O-y[0])*n[1]+(P*M-y[1])*t[1],(P-1)*i+(P*O-y[0])*n[2]+(P*M-y[1])*t[2]],C=[...x(v,m),f,...x(E,h),g,o[0],o[1],o[2],0,A[0],A[1],A[2],1];for(let O=0;O<8;O+=1)C[O]/=Wt;return we(C,6)}function rt(e,n=nr){let t=on(e,n);return Number(t)===0?"0":`${t}%`}function mr(e,n,t,o,r,s){let i=(e-t)*(s-o)-(n-o)*(r-t);return Math.abs(i)>Ln?!1:(e-t)*(e-r)+(n-o)*(n-s)<=Ln}function pr(e,n=Sn,t=Sn){let o=!1;for(let r=0,s=e.length-1;r<e.length;s=r++){let[i,a]=e[r],[l,u]=e[s];if(mr(n,t,i,a,l,u))return!0;a>t!=u>t&&n<(l-i)*(t-a)/(u-a)+i&&(o=!o)}return o}function zn(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function fr(e,n){let t=zn(e);if(t<=0)return 1;let o=Math.max(1,...e.map(i=>Math.max(i.width,i.height))),r=Gt/o,s=Math.sqrt(n/(t*4));return lt(Math.min(r,s))}function hr(e,n){let t=zn(e),o=.5;return t<=Vn?o=1:t<=$o&&(o=.75),lt(Math.min(o,fr(e,n)))}function gr(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function yr(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function br(e,n,t){let o=gr(e,n),r=yr(e,n),s=o>Gt?Gt/o:1,i=r>t?Math.sqrt(t/r):1;return Math.min(s,i)}function xr(e,n,t){let o=hr(n.pages,t),r=o===1?n:it(e,o);for(let s=0;s<4;s++){let i=br(r.pages,o,t);if(i>=1)break;let a=lt(o*i*jo);if(a>=o)break;o=a,r=it(e,o)}return{packed:r,atlasScale:o}}function vr(e){return Bn(e)?Uo:Go}function Bn(e){if(!e)return!1;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return t?t("(pointer: coarse)").matches||t("(hover: none)").matches:!1}function Pr(e,n){return e!==void 0&&e!=="auto"||Bn(n)?Se:rr}function Er(e,n){let t=e.matrix.split(",").map(o=>Number(o));return t.length!==16||t.some(o=>!Number.isFinite(o))?e.canonicalMatrix:(t[0]*=e.canvasW/n,t[1]*=e.canvasW/n,t[2]*=e.canvasW/n,t[4]*=e.canvasH/n,t[5]*=e.canvasH/n,t[6]*=e.canvasH/n,we(t))}function kn(e,n){for(let t of e.entries)t&&(t.atlasCanonicalSize=n,t.atlasMatrix=Er(t,n));return e}function Le(e){return e.atlasCanonicalSize??Se}function Nn(e,n,t){let o=Pr(n,t);if(n!==void 0&&n!=="auto"){let i=lt(n);return{packed:kn(it(e,i),o),atlasScale:i,atlasCanonicalSize:o}}let r=it(e,1),s=xr(e,r,vr(t));return{packed:kn(s.packed,o),atlasScale:s.atlasScale,atlasCanonicalSize:o}}function Cr(e){return Math.max(Cn,Math.ceil(Cn/e))}function Ae(e,n,t=1,o=0,r=0,s=1,i=0,a=0){e.setTransform(t*n,o*n,r*n,s*n,i*n,a*n)}function Te(e){let n=(0,qt.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function an({r:e,g:n,b:t}){return`${e},${n},${t}`}function Ar(e){return(0,qt.parsePureColor)(e)?.alpha??1}function Mr({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function ee(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,s=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`(^|;)\\s*${s}\\s*:[^;]*`,"i"),a=i.test(o)?o.replace(i,(l,u)=>`${u}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;a!==o&&e.setAttribute("style",a)}function ye(e,n){let t=e.getAttribute("style")??"";if(!t)return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`^\\s*${o}\\s*:`,"i"),s=t.split(";").map(i=>i.trim()).filter(i=>i&&!r.test(i)).join(";");s?e.setAttribute("style",s):e.removeAttribute("style")}function Yn(e,n,t,o,r){let s=Te(e),i=Te(t),a=Te(o),l=a.r/255*r+i.r/255*n,u=a.g/255*r+i.g/255*n,p=a.b/255*r+i.b/255*n,d=Math.max(0,Math.min(255,Math.round(s.r*l))),f=Math.max(0,Math.min(255,Math.round(s.g*u))),g=Math.max(0,Math.min(255,Math.round(s.b*p))),m=Ar(e);return m<1?`rgba(${d}, ${f}, ${g}, ${m})`:Mr({r:d,g:f,b:g})}function Xn(e,n,t,o){let r=Te(n),s=Te(t);return{r:s.r/255*o+r.r/255*e,g:s.g/255*o+r.g/255*e,b:s.b/255*o+r.b/255*e}}function Sr({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(1,r))*255);return`rgb(${o(e)} ${o(n)} ${o(t)})`}function Lr(e,n,t,o,r,s,i){Math.abs(s.r-1)<.001&&Math.abs(s.g-1)<.001&&Math.abs(s.b-1)<.001||(e.save(),Ae(e,i),e.globalCompositeOperation="multiply",e.fillStyle=Sr(s),e.fillRect(n,t,o,r),e.restore())}function wr(e,n,t,o,r,s,i){let a=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,u=Math.max(r/a,s/l),p=a*u,d=l*u;Ae(e,i),e.drawImage(n,t+(r-p)/2,o+(s-d)/2,p,d)}function st(e){return`${e[0]},${e[1]},${e[2]}`}function Tr(e,n){let t=st(e),o=st(n);return t<o?`${t}|${o}`:`${o}|${t}`}function $n(e,n){return st(e)<st(n)?[n[0]-e[0],n[1]-e[1],n[2]-e[2]]:[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function _r(e){return!e.texture}function Qe(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function ct(e){if(e.length<3)return null;let n=e[0],t=0,o=0,r=0;for(let i=1;i+1<e.length;i++){let a=e[i],l=e[i+1],u=[a[0]-n[0],a[1]-n[1],a[2]-n[2]],p=[l[0]-n[0],l[1]-n[1],l[2]-n[2]];t-=u[1]*p[2]-u[2]*p[1],o-=u[2]*p[0]-u[0]*p[2],r-=u[0]*p[1]-u[1]*p[0]}let s=Math.hypot(t,o,r);return s<=pe?null:(t/=s,o/=s,r/=s,[t,o,r])}function Ne(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function kr(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Rr(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=Qe(e.vertices,n,t),r=ct(o);return r?{pts:o,normal:r,planeD:Ne(r,o[0]),optimizable:_r(e)}:null}function Or(e,n){return!e||!n||!e.optimizable||!n.optimizable?!1:Un(e,n)}function Un(e,n){return!e||!n||Ne(e.normal,n.normal)<1-Zo?!1:Math.abs(e.planeD-n.planeD)<=qo}function Rn(e,n){if(!e)return null;let t=n.directionalLight,o=n.ambientLight,r=t?.direction??Kt,s=t?.color??Jt,i=Math.max(0,t?.intensity??en),a=o?.color??tn,l=Math.max(0,o?.intensity??nn),u=Math.hypot(r[0],r[1],r[2])||1,p=r[0]/u,d=r[1]/u,f=r[2]/u,g=i*Math.max(0,e.normal[0]*p+e.normal[1]*d+e.normal[2]*f),m=Xn(g,s,a,l);return m.r*.2126+m.g*.7152+m.b*.0722}function Dr(e){let n=[...e],t=Math.abs(n[0])>pe?0:Math.abs(n[1])>pe?1:2;return n[t]<0&&(n[0]*=-1,n[1]*=-1,n[2]*=-1),`${n[0].toFixed(6)},${n[1].toFixed(6)},${n[2].toFixed(6)}`}function qe(e,n,t,o,r={}){let s=Ne(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],a=Math.hypot(i[0],i[1],i[2]);if(a<=pe)return null;let l=[i[0]/a,i[1]/a,i[2]/a],u=[t[1]*l[2]-t[2]*l[1],t[2]*l[0]-t[0]*l[2],t[0]*l[1]-t[1]*l[0]],p=Math.hypot(u[0],u[1],u[2]);if(p<=pe)return null;let d=[u[0]/p,u[1]/p,u[2]/p],f=e.map(w=>{let I=w[0]-n[0],F=w[1]-n[1],B=w[2]-n[2];return[I*l[0]+F*l[1]+B*l[2],I*d[0]+F*d[1]+B*d[2]]}),g=r.boundsOrigin??n,m=n[0]-g[0],h=n[1]-g[1],y=n[2]-g[2],v=m*l[0]+h*l[1]+y*l[2],E=m*d[0]+h*d[1]+y*d[2],A=1/0,x=1/0,C=-1/0,O=-1/0;for(let[w,I]of f){let F=w+v,B=I+E;F<A&&(A=F),F>C&&(C=F),B<x&&(x=B),B>O&&(O=B)}let M=C-A,P=O-x;if(!Number.isFinite(M)||!Number.isFinite(P))return null;let X=r.snapBounds?Math.floor(A+ie):A,$=r.snapBounds?Math.floor(x+ie):x,W=r.snapBounds?Math.ceil(C-ie):C,ne=r.snapBounds?Math.ceil(O-ie):O,S=Math.max(1,r.snapBounds?W-X:Math.ceil(M)),U=Math.max(1,r.snapBounds?ne-$:Math.ceil(P));return{xAxis:l,yAxis:d,local2D:f,shiftX:v-X,shiftY:E-$,canvasW:S,canvasH:U,pixelArea:S*U,rawArea:M*P}}function Hr(e,n,t,o){let r=0,s=0;for(let i of e){let a=n[i];if(!a)return null;let l=qe(a.pts,a.pts[0],a.normal,t,{boundsOrigin:o,snapBounds:!0});if(!l)return null;r+=l.pixelArea,s+=l.rawArea}return{pixelArea:r,rawArea:s}}function Ir(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,s=new Set;for(let i of e){let a=n[i];if(!a)continue;let l=[a.pts[1][0]-a.pts[0][0],a.pts[1][1]-a.pts[0][1],a.pts[1][2]-a.pts[0][2]],u=qe(a.pts,a.pts[0],a.normal,l);o&&u?(o.pixelArea+=u.pixelArea,o.rawArea+=u.rawArea):o=null;for(let p=0;p<a.pts.length;p++){let d=$n(a.pts[p],a.pts[(p+1)%a.pts.length]),f=qe(a.pts,a.pts[0],a.normal,d);if(!f)continue;let g=Dr(f.xAxis);if(s.has(g))continue;s.add(g);let m=Hr(e,n,f.xAxis,t);m&&(!r||m.pixelArea<r.pixelArea||m.pixelArea===r.pixelArea&&m.rawArea<r.rawArea-ie)&&(r={xAxis:f.xAxis,...m})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+ie)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function ln(e,n){let t=n.tileSize??Qt,o=n.layerElevation??t,r=e.map(d=>Rr(d,t,o)),s=new Map,i=e.map(()=>new Set),a=e.map(()=>new Set);for(let d=0;d<e.length;d++){let f=e[d].vertices;if(!(!f||f.length<3))for(let g=0;g<f.length;g++){let m=Tr(f[g],f[(g+1)%f.length]),h=s.get(m),y={polygon:d,edge:g};h?h.push(y):s.set(m,[y])}}let l=e.map(()=>new Set);for(let d of s.values())if(!(d.length<2))for(let f=0;f<d.length;f++)for(let g=f+1;g<d.length;g++){let m=d[f],h=d[g],y=m.polygon,v=h.polygon;if(e[y].texture&&e[v].texture&&(a[m.polygon].add(m.edge),a[h.polygon].add(h.edge)),Un(r[y],r[v]))i[m.polygon].add(m.edge),i[h.polygon].add(h.edge);else{let E=Rn(r[y],n),A=Rn(r[v],n);E!==null&&A!==null&&(E<=A+An&&i[m.polygon].add(m.edge),A<=E+An&&i[h.polygon].add(h.edge))}Or(r[y],r[v])&&(l[y].add(v),l[v].add(y))}let u=Array(e.length).fill(void 0),p=new Set;for(let d=0;d<e.length;d++){if(p.has(d)||!r[d]?.optimizable)continue;let f=[],g=[d];for(p.add(d);g.length>0;){let h=g.pop();f.push(h);for(let y of l[h])p.has(y)||(p.add(y),g.push(y))}if(f.length<2)continue;let m=Ir(f,r);if(m)for(let h of f)u[h]={xAxis:m.xAxis,boundsOrigin:m.boundsOrigin,seamEdges:i[h],textureEdgeRepairEdges:a[h]}}for(let d=0;d<e.length;d++)!u[d]&&(i[d].size>0||a[d].size>0)&&(u[d]={seamEdges:i[d],textureEdgeRepairEdges:a[d]});return u}function Vr(e){if(typeof e.toBlob=="function")return new Promise(n=>{e.toBlob(t=>{n(t?URL.createObjectURL(t):null)},"image/png")});try{return Promise.resolve(e.toDataURL("image/png"))}catch{return Promise.resolve(null)}}function On(e,n,t,o){if(o.optimize&&o.fixedXAxis)return qe(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,s=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,i=s??(o.optimize?e.map((a,l)=>l):[0]);for(let a of i){let l=(a+1)%e.length,u=s?$n(e[a],e[l]):[e[l][0]-e[a][0],e[l][1]-e[a][1],e[l][2]-e[a][2]],p=qe(e,n,t,u,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});p&&(!r||p.pixelArea<r.pixelArea||p.pixelArea===r.pixelArea&&p.rawArea<r.rawArea-ie)&&(r=p)}return r}function Fr(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=ie)return;r.push(s)};for(let[r,s]of e.local2D)o(n,r+e.shiftX),o(t,s+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>ie||Math.abs(t[0])>ie||n[1]-n[0]<=ie||t[1]-t[0]<=ie))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,a=s+e.shiftY,l=Math.abs(i-n[0])<=ie||Math.abs(i-n[1])<=ie,u=Math.abs(a-t[0])<=ie||Math.abs(a-t[1])<=ie;if(!l||!u)return!1}return!0}function Gn(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,a]=n,l=t[0],u=t[1],p=o[0],d=o[1],f=r[0],g=r[1],m=s[0],h=1-s[1],y=i[0],v=1-i[1],E=a[0],A=1-a[1],x=y-m,C=v-h,O=E-m,M=A-h,P=x*M-O*C;if(Math.abs(P)<=1e-9)return null;let X=p-l,$=f-l,W=d-u,ne=g-u,S={a:(X*M-$*C)/P,b:(x*$-O*X)/P,c:(W*M-ne*C)/P,d:(x*ne-O*W)/P,e:0,f:0};return S.e=l-S.a*m-S.b*h,S.f=u-S.c*m-S.d*h,S}function jn(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let s of e){let i=s[0],a=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(a))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,a),r=Math.max(r,a)}return{minU:n,minV:t,maxU:o,maxV:r}}function zr(e,n,t,o,r,s,i,a){let u=Qe(e.vertices,n,t).map(f=>{let g=f[0]-o[0],m=f[1]-o[1],h=f[2]-o[2];return[g*r[0]+m*r[1]+h*r[2]+i,g*s[0]+m*s[1]+h*s[2]+a]}),p=Gn(u,e.uvs),d=jn(e.uvs);return!p&&!d?null:{screenPts:u.flatMap(([f,g])=>[f,g]),uvAffine:p,uvSampleRect:d}}function Ze(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],o+=e[i+1];t/=r,o/=r;let s=e.slice();for(let i=0;i<s.length;i+=2){let a=s[i]-t,l=s[i+1]-o,u=Math.hypot(a,l);u<=ie||(s[i]+=a/u*n,s[i+1]+=l/u*n)}return s}function Zt(e,n,t,o){for(let r=0;r<o.length;r+=2){let s=n+o[r],i=t+o[r+1];r===0?e.moveTo(s,i):e.lineTo(s,i)}e.closePath()}function cn(e,n,t,o,r){let{vertices:s,texture:i,uvs:a}=e;if(!s||s.length<3)return null;let l=t.tileSize??Qt,u=t.layerElevation??l,p=Qe(s,l,u),d=p[0],f=p[1],g=[f[0]-d[0],f[1]-d[1],f[2]-d[2]];if(Math.hypot(g[0],g[1],g[2])===0)return null;let h=ct(p);if(!h)return null;let y=On(p,d,h,{optimize:!1}),v=i||y&&Fr(y)?y:On(p,d,h,{optimize:!0,fixedXAxis:r?.xAxis,boundsOrigin:r?.boundsOrigin,snapBounds:!!r,seamEdges:r?.seamEdges});if(!v)return null;let{xAxis:E,yAxis:A,local2D:x}=v,C=i&&r?.textureEdgeRepairEdges?.size?r.textureEdgeRepairEdges:null,O=!!(i&&C),M=v.shiftX,P=v.shiftY,X=v.canvasW,$=v.canvasH,W=[];for(let[V,D]of x)W.push(V+M,D+P);let ne=d[0]-M*E[0]-P*A[0],S=d[1]-M*E[1]-P*A[1],U=d[2]-M*E[2]-P*A[2],w=we([E[0],E[1],E[2],0,A[0],A[1],A[2],0,h[0],h[1],h[2],0,ne,S,U,1]),I=we([E[0]*X,E[1]*X,E[2]*X,0,A[0]*$,A[1]*$,A[2]*$,0,h[0],h[1],h[2],0,ne,S,U,1]),F=we([E[0]*X/Se,E[1]*X/Se,E[2]*X/Se,0,A[0]*$/Se,A[1]*$/Se,A[2]*$/Se,0,h[0],h[1],h[2],0,ne,S,U,1]),B=!i&&s.length===4?dr(W,E,A,h,ne,S,U,o):null,J=t.directionalLight,le=t.ambientLight,k=J?.direction??Kt,j=J?.color??Jt,Z=Math.max(0,J?.intensity??en),se=le?.color??tn,oe=Math.max(0,le?.intensity??nn),de=Math.hypot(k[0],k[1],k[2])||1,ge=k[0]/de,me=k[1]/de,ue=k[2]/de,be=Z*Math.max(0,h[0]*ge+h[1]*me+h[2]*ue),xe=Xn(be,j,se,oe),c=Yn(e.color??"#cccccc",be,j,se,oe),b=null,R=null;i&&a&&a.length>=3&&a.length===s.length&&(R=jn(a),b=Gn(x.map(([V,D])=>[V+M,D+P]),a));let _=i&&e.textureTriangles?.length?e.textureTriangles.map(V=>zr(V,l,u,d,E,A,M,P)).filter(V=>!!V):null;return{index:n,polygon:e,texture:i,tileSize:l,layerElevation:u,matrix:w,canonicalMatrix:I,atlasMatrix:F,projectiveMatrix:B,canvasW:X,canvasH:$,screenPts:W,uvAffine:b,uvSampleRect:R,textureTriangles:_,textureEdgeRepairEdges:C,textureEdgeRepair:O,normal:h,textureTint:xe,shadedColor:c}}function ut(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??Qt,r=t.layerElevation??o,s=Qe(e.vertices,o,r),i=ct(s);if(!i)return null;let a=[{a:0,b:1,c:2},{a:1,b:2,c:0},{a:2,b:0,c:1}].map(Q=>{let H=s[Q.a],q=s[Q.b];return{...Q,length:Math.hypot(q[0]-H[0],q[1]-H[1],q[2]-H[2])}}).sort((Q,H)=>H.length-Q.length),l=a[0].a,u=a[0].b,p=a[0].c,d=s[l],f=s[u],g=s[p],m=a[0].length;if(m<=pe)return null;let h=[(f[0]-d[0])/m,(f[1]-d[1])/m,(f[2]-d[2])/m],y=[g[0]-d[0],g[1]-d[1],g[2]-d[2]],v=Ne(y,h),E=[d[0]+h[0]*v,d[1]+h[1]*v,d[2]+h[2]*v],A=[E[0]-g[0],E[1]-g[1],E[2]-g[2]],x=Math.hypot(A[0],A[1],A[2]);if(x<=pe)return null;let C=[A[0]/x,A[1]/x,A[2]/x];if(Ne(kr(h,C),i)<0){let Q=u;if(u=l,l=Q,d=s[l],f=s[u],m=Math.hypot(f[0]-d[0],f[1]-d[1],f[2]-d[2]),m<=pe)return null;h=[(f[0]-d[0])/m,(f[1]-d[1])/m,(f[2]-d[2])/m];let H=[g[0]-d[0],g[1]-d[1],g[2]-d[2]];v=Ne(H,h),E=[d[0]+h[0]*v,d[1]+h[1]*v,d[2]+h[2]*v],A=[E[0]-g[0],E[1]-g[1],E[2]-g[2]];let q=Math.hypot(A[0],A[1],A[2]);if(q<=pe)return null;C=[A[0]/q,A[1]/q,A[2]/q]}let O=Math.max(0,Math.min(m,v)),M=Math.max(0,m-O),P=rn([O,0,0,x,O+M,x],er),X=[P[0],P[1]],$=[P[2],P[3]],W=[P[4],P[5]],ne=($[1]+W[1])/2,S=X[0]-$[0],U=W[0]-X[0],w=ne-X[1];if(S<=pe||U<=pe||w<=pe||!Number.isFinite(S+U+w))return null;let I=t.directionalLight,F=t.ambientLight,B=I?.direction??Kt,J=I?.color??Jt,le=Math.max(0,I?.intensity??en),k=F?.color??tn,j=Math.max(0,F?.intensity??nn),Z=Math.hypot(B[0],B[1],B[2])||1,se=B[0]/Z,oe=B[1]/Z,de=B[2]/Z,ge=le*Math.max(0,i[0]*se+i[1]*oe+i[2]*de),me=Yn(e.color??"#cccccc",ge,J,k,j),ue=t.textureLighting??"baked",be=Te(e.color??"#cccccc"),xe=me===t.solidPaintDefaults?.paintColor,c=ue==="dynamic"&&an(be)===t.solidPaintDefaults?.dynamicColorKey,b=ue==="dynamic"||xe?"":`color:${me};`,R=ue==="dynamic"?`--pnx:${i[0].toFixed(4)};--pny:${i[1].toFixed(4)};--pnz:${i[2].toFixed(4)};`+(c?"":`--psr:${(be.r/255).toFixed(4)};--psg:${(be.g/255).toFixed(4)};--psb:${(be.b/255).toFixed(4)};`):"",_=([Q,H])=>[g[0]+(Q-O)*h[0]+H*C[0],g[1]+(Q-O)*h[1]+H*C[1],g[2]+(Q-O)*h[2]+H*C[2]],V=_(X),D=_([$[0],ne]),Y=_([W[0],ne]),L=ke/2,N=[(Y[0]-D[0])/ke,(Y[1]-D[1])/ke,(Y[2]-D[2])/ke],z=[V[0]-N[0]*L,V[1]-N[1]*L,V[2]-N[2]*L],G=[(D[0]-z[0])/ke,(D[1]-z[1])/ke,(D[2]-z[2])/ke],T=`transform:matrix3d(${we([N[0],N[1],N[2],0,G[0],G[1],G[2],0,i[0],i[1],i[2],0,z[0],z[1],z[2],1])});`+b+R;return{index:n,polygon:e,styleText:T}}function it(e,n=1){let t=Array(e.length).fill(null),o=[],r=Cr(n),s=e.filter(l=>!!l).sort((l,u)=>u.canvasH-l.canvasH||u.canvasW-l.canvasW||l.index-u.index),i=()=>({width:r,height:r,entries:[],shelves:[]}),a=(l,u,p)=>{if(l.sealed)return null;for(let g of l.shelves)if(u.canvasH<=g.height&&g.x+u.canvasW+r<=ze){let m={...u,pageIndex:p,x:g.x,y:g.y};return g.x+=u.canvasW+r*2,l.entries.push(m),l.width=Math.max(l.width,m.x+u.canvasW+r),m}let d=l.shelves.length===0?r:l.height+r;if(d+u.canvasH+r>ze)return null;let f={...u,pageIndex:p,x:r,y:d};return l.shelves.push({x:r+u.canvasW+r*2,y:d,height:u.canvasH}),l.entries.push(f),l.width=Math.max(l.width,f.x+u.canvasW+r),l.height=Math.max(l.height,d+u.canvasH+r),f};for(let l of s){if(l.canvasW+r*2>ze||l.canvasH+r*2>ze){let d=o.length,f={...l,pageIndex:d,x:r,y:r};t[l.index]=f,o.push({width:l.canvasW+r*2,height:l.canvasH+r*2,entries:[f],shelves:[],sealed:!0});continue}let p=null;for(let d=0;d<o.length&&(p=a(o[d],l,d),!p);d++);if(!p){let d=i(),f=o.length;o.push(d),p=a(d,l,f)}p&&(t[l.index]=p)}return{entries:t,pages:o.map(({width:l,height:u,entries:p})=>({width:l,height:u,entries:p}))}}function Br(e,n,t,o){Ae(e,o),e.beginPath(),Zt(e,n.x,n.y,n.screenPts),e.clip(),Ae(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function Fe(e,n){return Math.max(0,Math.min(n,e))}function Dn(e,n,t,o,r,s,i,a){let l=n.naturalWidth||n.width||1,u=n.naturalHeight||n.height||1,p=Fe(Math.min(t.minU,t.maxU)*l,l),d=Fe(Math.max(t.minU,t.maxU)*l,l),f=Fe(Math.min(t.minV,t.maxV)*u,u),g=Fe(Math.max(t.minV,t.maxV)*u,u),m=Math.floor(p),h=Math.floor(f),y=Math.ceil(d)-m,v=Math.ceil(g)-h;y<1&&(m=Math.floor(Fe((t.minU+t.maxU)/2*l,l-1)),y=1),v<1&&(h=Math.floor(Fe((t.minV+t.maxV)/2*u,u-1)),v=1),m=Math.max(0,Math.min(l-1,m)),h=Math.max(0,Math.min(u-1,h)),y=Math.max(1,Math.min(l-m,y)),v=Math.max(1,Math.min(u-h,v)),Ae(e,a),e.drawImage(n,m,h,y,v,o,r,s,i)}function Nr(e,n,t,o,r,s){for(let i=0;i<o.length;i+=2){let a=n+o[i]+r,l=t+o[i+1]+s;i===0?e.moveTo(a,l):e.lineTo(a,l)}e.closePath()}function Yr(e,n,t,o,r=0,s=0){if(n.textureTriangles?.length){let i=t.naturalWidth||t.width||1,a=t.naturalHeight||t.height||1;for(let l of n.textureTriangles){let u=Ze(l.screenPts,Qo);e.save(),Ae(e,o),e.beginPath(),Nr(e,n.x,n.y,u,r,s),e.clip(),l.uvAffine?(Ae(e,o,l.uvAffine.a/i,l.uvAffine.c/i,l.uvAffine.b/a,l.uvAffine.d/a,n.x+l.uvAffine.e+r,n.y+l.uvAffine.f+s),e.drawImage(t,0,0)):l.uvSampleRect&&Dn(e,t,l.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let i=t.naturalWidth||t.width||1,a=t.naturalHeight||t.height||1;Ae(e,o,n.uvAffine.a/i,n.uvAffine.c/i,n.uvAffine.b/a,n.uvAffine.d/a,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+s),e.drawImage(t,0,0)}else n.uvSampleRect?Dn(e,t,n.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o):wr(e,t,n.x+r,n.y+s,n.canvasW,n.canvasH,o)}function Xr(e,n,t,o,r,s){let i=r-t,a=s-o,l=i*i+a*a;if(l<=pe)return Math.hypot(e-t,n-o);let u=Math.max(0,Math.min(1,((e-t)*i+(n-o)*a)/l));return Math.hypot(e-(t+i*u),n-(o+a*u))}function $r(e,n,t,o){let r=1/0,s=t.length/2;for(let i of o){if(i<0||i>=s)continue;let a=i*2,l=(i+1)%s*2;r=Math.min(r,Xr(e,n,t[a],t[a+1],t[l],t[l+1]))}return r}function Ur(e,n,t,o,r,s){let i=Math.max(0,o-s),a=Math.min(n-1,o+s),l=Math.max(0,r-s),u=Math.min(t-1,r+s),p=null,d=1/0;for(let f=l;f<=u;f++)for(let g=i;g<=a;g++){if(g===o&&f===r)continue;let m=g-o,h=f-r,y=m*m+h*h;if(y>s*s||y>=d)continue;let v=(f*n+g)*4;e[v+3]<Jo||(p=v,d=y)}return p}function Gr(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),s=Math.max(0,Math.floor(n.y*t)),i=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),a=Math.max(1,Math.min(o.height-s,Math.ceil(n.canvasH*t)));if(i<=0||a<=0)return;let l;try{l=e.getImageData(r,s,i,a)}catch{return}let u=l.data,p=new Uint8ClampedArray(u),d=Math.max(Mn,Mn/t),f=Math.max(2,Math.ceil(d*t)+1),g=!1;for(let m=0;m<a;m++)for(let h=0;h<i;h++){let y=(m*i+h)*4,v=u[y+3];if(v<Ko||v===255)continue;let E=(r+h+.5)/t-n.x,A=(s+m+.5)/t-n.y;if($r(E,A,n.screenPts,n.textureEdgeRepairEdges)>d)continue;let x=Ur(p,i,a,h,m,f);x!==null&&(u[y]=p[x],u[y+1]=p[x+1],u[y+2]=p[x+2],u[y+3]=255,g=!0)}g&&e.putImageData(l,r,s)}async function jr(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=e.entries.some(p=>p.textureEdgeRepair&&p.texture&&p.textureEdgeRepairEdges&&p.textureEdgeRepairEdges.size>0),i=r.getContext("2d",s?{willReadFrequently:!0}:void 0);if(!i)return{width:e.width,height:e.height,url:null};let a=Array.from(new Set(e.entries.flatMap(p=>p.texture?[p.texture]:[]))),l=new Map;await Promise.all(a.map(async p=>{l.set(p,await lr(p))}));for(let p of e.entries){let d=p.texture?l.get(p.texture):null;if(!p.texture){i.save(),Br(i,p,n,o),i.restore();continue}d&&(i.save(),Ae(i,o),i.beginPath(),Zt(i,p.x,p.y,p.screenPts),i.clip(),Yr(i,p,d,o),i.restore()),p.texture&&n==="baked"&&(i.save(),Ae(i,o),i.beginPath(),Zt(i,p.x,p.y,p.screenPts),i.clip(),Lr(i,p.x,p.y,p.canvasW,p.canvasH,p.textureTint,o),i.restore()),Gr(i,p,o)}let u=await Vr(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:u}}async function Wn(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await jr(i,n,t,o))}return s}function Zn(e,n,t,o){if(!n.url)return;let r=`url(${n.url})`,s=o.canvasW||1,i=o.canvasH||1,a=Le(o),l=`${Be(-o.x/s*a)} ${Be(-o.y/i*a)}`,u=`${Be(n.width/s*a)} ${Be(n.height/i*a)}`;t==="dynamic"?(ee(e,"background-image",r),ee(e,"background-position",l),ee(e,"background-size",u)):ee(e,"background",`${r} ${l} / ${u} no-repeat`),t==="dynamic"?(ee(e,"mask-image",r),ee(e,"mask-mode","alpha"),ee(e,"mask-position",l),ee(e,"mask-size",u),ee(e,"mask-repeat","no-repeat"),ee(e,"-webkit-mask-image",r),ee(e,"-webkit-mask-position",l),ee(e,"-webkit-mask-size",u),ee(e,"-webkit-mask-repeat","no-repeat")):(ye(e,"mask-image"),ye(e,"mask-mode"),ye(e,"mask-position"),ye(e,"mask-size"),ye(e,"mask-repeat"),ye(e,"-webkit-mask-image"),ye(e,"-webkit-mask-position"),ye(e,"-webkit-mask-size"),ye(e,"-webkit-mask-repeat"))}function Oe(e,n){let t=jt.get(e);if(t)for(let r of t)e.removeAttribute(`data-${r}`);let o=[];if(n.data)for(let[r,s]of Object.entries(n.data))e.setAttribute(`data-${r}`,String(s)),o.push(r);jt.set(e,o)}function qn(e,n,t,o=0,r=0){let s=e.matrix.split(",").map(f=>Number(f));if(s.length!==16||s.some(f=>!Number.isFinite(f)))return e.matrix;let i=s[0],a=s[1],l=s[2],u=s[4],p=s[5],d=s[6];return s[0]*=n,s[1]*=n,s[2]*=n,s[4]*=t,s[5]*=t,s[6]*=t,s[12]+=o*i+r*u,s[13]+=o*a+r*p,s[14]+=o*l+r*d,we(s)}function Wr(e,n){return qn(e,n.width/wn,n.height/wn,n.minX,n.minY)}function Zr(e){return qn(e,(e.canvasW||1)/Wt,(e.canvasH||1)/Wt)}function qr(e){let n=eo(e);return[`transform:matrix3d(${Wr(e,n.bounds)})`,`border-shape:${to(n.points)}`].join(";")}function Qr(e,n){if(e.screenPts.length<6||n.vertices.length<3)return null;let t=e.tileSize,o=e.layerElevation,r=Qe(n.vertices,t,o),s=ct(r);if(!s)return null;let i=e.screenPts[0],a=e.screenPts[1],l=e.screenPts[2],u=e.screenPts[3],p=e.screenPts[4],d=e.screenPts[5],f=l-i,g=u-a,m=p-i,h=d-a,y=f*h-g*m;if(Math.abs(y)<=pe)return null;let v=r[0],E=r[1],A=r[2],x=[E[0]-v[0],E[1]-v[1],E[2]-v[2]],C=[A[0]-v[0],A[1]-v[1],A[2]-v[2]],O=[(x[0]*h-g*C[0])/y,(x[1]*h-g*C[1])/y,(x[2]*h-g*C[2])/y],M=[(f*C[0]-x[0]*m)/y,(f*C[1]-x[1]*m)/y,(f*C[2]-x[2]*m)/y],P=v[0]-O[0]*i-M[0]*a,X=v[1]-O[1]*i-M[1]*a,$=v[2]-O[2]*i-M[2]*a;return{normal:s,matrix:we([O[0]*e.canvasW/Le(e),O[1]*e.canvasW/Le(e),O[2]*e.canvasW/Le(e),0,M[0]*e.canvasH/Le(e),M[1]*e.canvasH/Le(e),M[2]*e.canvasH/Le(e),0,s[0],s[1],s[2],0,P,X,$,1])}}function Kr(e,n,t,o){if(!n.texture||!t.texture||n.texture!==t.texture)return!1;let r=Qr(n,t);return r?(ee(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(ee(e,"--pnx",r.normal[0].toFixed(4)),ee(e,"--pny",r.normal[1].toFixed(4)),ee(e,"--pnz",r.normal[2].toFixed(4))),Oe(e,t),!0):!1}function Qn(e,n){ee(e,"--pnx",n.normal[0].toFixed(4)),ee(e,"--pny",n.normal[1].toFixed(4)),ee(e,"--pnz",n.normal[2].toFixed(4))}function Jr(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=ie)return;r.push(s)};for(let r=0;r<e.screenPts.length;r+=2)o(n,e.screenPts[r]),o(t,e.screenPts[r+1]);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>ie||Math.abs(t[0])>ie||n[1]-n[0]<=ie||t[1]-t[0]<=ie))return null;for(let r=0;r<e.screenPts.length;r+=2){let s=e.screenPts[r],i=e.screenPts[r+1],a=Math.abs(s-n[0])<=ie||Math.abs(s-n[1])<=ie,l=Math.abs(i-t[0])<=ie||Math.abs(i-t[1])<=ie;if(!a||!l)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function Re(e){return!!Jr(e)}function at(e){return!e.texture&&e.polygon.vertices.length===3}function Ye(e){return!e.texture&&!!e.projectiveMatrix&&!Re(e)}function un(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function dt(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";if(!t)return!0;let o=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(t);return!/\bVersion\/[\d.]+.*\bSafari\//.test(t)||o}function Hn(e,n){e.set(n,(e.get(n)??0)+1)}function In(e){let n,t=1;for(let[o,r]of e)r>t&&(n=o,t=r);return n}function Kn(e,n,t,o){let r=new Map,s=new Map,i=new Map,a=!o.has("b"),l=a,u=!o.has("u")&&dt(t),p=!o.has("i")&&un(t);for(let g of e)if(!(!g||g.texture)){if(n==="dynamic"){if(!(u&&at(g))&&!(a&&Re(g))&&!(l&&Ye(g))&&!p)continue;let m=Te(g.polygon.color??"#cccccc"),h=an(m);Hn(s,h),i.has(h)||i.set(h,m);continue}!(u&&at(g))&&!(a&&Re(g))&&!(l&&Ye(g))&&!p||Hn(r,g.shadedColor)}let d=In(r),f=In(s);return{paintColor:d,dynamicColorKey:f,dynamicColor:f?i.get(f):void 0}}function Jn(){return new Promise(e=>setTimeout(e,0))}async function Ut(e){return performance.now()-e<Wo?e:(await Jn(),performance.now())}function mt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=new Set(n.strategies?.disable??[]),r=ln(e,n),s=sn(t),i=e.map((a,l)=>cn(a,l,n,s,r[l]));return Kn(i,n.textureLighting??"baked",t,o)}function es(e,n,t){let o=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(let u=0;u<e.length;u+=2){let p=e[u],d=e[u+1];!Number.isFinite(p)||!Number.isFinite(d)||(o=Math.min(o,p),r=Math.min(r,d),s=Math.max(s,p),i=Math.max(i,d))}let a=s-o,l=i-r;return!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(a)||!Number.isFinite(l)||a<=pe||l<=pe?{minX:0,minY:0,width:n,height:t}:{minX:o,minY:r,width:a,height:l}}function eo(e){let n=e.canvasW||1,t=e.canvasH||1,o=$t>0?rn(e.screenPts,$t):e.screenPts,r=$t>0?es(o,n,t):{minX:0,minY:0,width:n,height:t},s=[];for(let i=0;i<o.length;i+=2){let a=Math.max(0,Math.min(100,(o[i]-r.minX)/r.width*100)),l=Math.max(0,Math.min(100,(o[i+1]-r.minY)/r.height*100));s.push([a,l])}return{bounds:r,points:s}}function ts([e,n]){return`${rt(e)} ${rt(n)}`}function ns(e){return`polygon(${e.map(ts).join(",")})`}function os(e){if(pr(e))return"circle(0)";let n=0,t=0,o=Math.max(1,e.length);for(let[i,a]of e)n+=i,t+=a;let r=rt(Math.max(0,Math.min(100,n/o))),s=rt(Math.max(0,Math.min(100,t/o)));return`circle(0 at ${r} ${s})`}function to(e){return`${ns(e)} ${os(e)}`}function no(e){return to(eo(e).points)}function dn(e,n,t,o){if(t==="dynamic"){ye(e,"color"),ye(e,"background"),Qn(e,n);let r=Te(n.polygon.color??"#cccccc");an(r)===o?.dynamicColorKey?(ye(e,"--psr"),ye(e,"--psg"),ye(e,"--psb")):(ee(e,"--psr",(r.r/255).toFixed(4)),ee(e,"--psg",(r.g/255).toFixed(4)),ee(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(ye(e,"background"),ee(e,"color",n.shadedColor)):(ye(e,"background"),ye(e,"color"))}function oo(e,n,t,o){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${Zr(e)})`),Oe(r,e.polygon),dn(r,e,n,o),r}function ro(e,n,t,o){let r=t.createElement("i");return r.setAttribute("style",qr(e)),Oe(r,e.polygon),dn(r,e,n,o),r}function so(e,n,t,o){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`),Oe(r,e.polygon),dn(r,e,n,o),r}function io(e,n,t){let o=t.createElement("s");o.setAttribute("style",`transform:matrix3d(${e.atlasMatrix})`),Oe(o,e.polygon);let r=e.canvasW||1,s=e.canvasH||1,i=Le(e);return ee(o,"--polycss-atlas-size",`${i}px`),ee(o,"background-position",`${Be(-e.x/r*i)} ${Be(-e.y/s*i)}`),ee(o,"opacity","0"),n==="dynamic"&&Qn(o,e),o}function ao(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=new Set(n.strategies?.disable??[]),s=!r.has("b"),i=s,a=!r.has("u")&&dt(t),l=!r.has("i")&&un(t),u=ln(e,n),p=sn(t),d=e.map((x,C)=>cn(x,C,n,p,u[C])),f=d.map(x=>x&&a&&at(x)?ut(x.polygon,x.index,n):null),g=d.map((x,C)=>x&&(x.texture||!(s&&Re(x))&&!f[C]&&!(i&&Ye(x))&&!l?x:null)),{packed:m,atlasScale:h}=Nn(g,n.textureQuality,t),y=new Map,v=[],E=!1,A=[];for(let x=0;x<e.length;x++){let C=d[x],O=f[x];if(!C)continue;let M=m.entries[x];if(M){let P=io(M,o,t);y.set(x,P),v.push({polygonIndex:x,element:P,kind:"atlas",plan:M,dispose:()=>{}})}else if(!C.texture&&s&&Re(C)){let P=oo(C,o,t,n.solidPaintDefaults);v.push({polygonIndex:x,element:P,kind:"solid",plan:C,dispose:()=>{}})}else if(!C.texture&&O){let P=mn(O,t);v.push({polygonIndex:x,element:P,kind:"triangle",plan:C,dispose:()=>{}})}else if(!C.texture&&i&&Ye(C)){let P=so(C,o,t,n.solidPaintDefaults);v.push({polygonIndex:x,element:P,kind:"solid",plan:C,dispose:()=>{}})}else if(!C.texture&&l){let P=ro(C,o,t,n.solidPaintDefaults);v.push({polygonIndex:x,element:P,kind:"border",plan:C,dispose:()=>{}})}}return v.sort((x,C)=>x.polygonIndex-C.polygonIndex),Wn(m.pages,o,t,h,()=>E).then(x=>{if(E){for(let C of x)C.url?.startsWith("blob:")&&URL.revokeObjectURL(C.url);return}A=x.flatMap(C=>C.url?.startsWith("blob:")?[C.url]:[]);for(let C=0;C<m.pages.length;C++){let O=m.pages[C],M=x[C];if(M)for(let P of O.entries){let X=y.get(P.index);!X||!M.url||(Zn(X,M,o,P),ye(X,"opacity"))}}}).catch(()=>{if(!E)for(let x of y.values())ee(x,"opacity","0.5"),ee(x,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:v,dispose(){E=!0;for(let x of A)URL.revokeObjectURL(x);A=[]}}}async function lo(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let r=n.textureLighting??"baked",s=new Set(n.strategies?.disable??[]),i=!s.has("b"),a=i,l=!s.has("u")&&dt(o),u=!s.has("i")&&un(o);if(await Jn(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let p=ln(e,n),d=sn(o),f=performance.now(),g=new Array(e.length);for(let M=0;M<e.length;M++)if(g[M]=cn(e[M],M,n,d,p[M]),f=await Ut(f),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let m=n.solidPaintDefaults??Kn(g,r,o,s),h=new Array(g.length),y=new Array(g.length);for(let M=0;M<g.length;M++){let P=g[M],X=P&&l&&at(P)?ut(P.polygon,P.index,{...n,solidPaintDefaults:m}):null;if(h[M]=X,y[M]=P&&(P.texture||!(i&&Re(P))&&!X&&!(a&&Ye(P))&&!u?P:null),f=await Ut(f),t())return{rendered:[],solidPaintDefaults:m,dispose:()=>{}}}let{packed:v,atlasScale:E}=Nn(y,n.textureQuality,o),A=new Map,x=[],C=!1,O=[];for(let M=0;M<e.length;M++){let P=g[M],X=h[M];if(!P)continue;let $=v.entries[M];if($){let W=io($,r,o);A.set(M,W),x.push({polygonIndex:M,element:W,kind:"atlas",plan:$,dispose:()=>{}})}else if(!P.texture&&i&&Re(P)){let W=oo(P,r,o,m);x.push({polygonIndex:M,element:W,kind:"solid",plan:P,dispose:()=>{}})}else if(!P.texture&&X){let W=mn(X,o);x.push({polygonIndex:M,element:W,kind:"triangle",plan:P,dispose:()=>{}})}else if(!P.texture&&a&&Ye(P)){let W=so(P,r,o,m);x.push({polygonIndex:M,element:W,kind:"solid",plan:P,dispose:()=>{}})}else if(!P.texture&&u){let W=ro(P,r,o,m);x.push({polygonIndex:M,element:W,kind:"border",plan:P,dispose:()=>{}})}if(f=await Ut(f),t()){for(let W of x)W.dispose();return{rendered:[],solidPaintDefaults:m,dispose:()=>{}}}}return x.sort((M,P)=>M.polygonIndex-P.polygonIndex),Wn(v.pages,r,o,E,()=>C||t()).then(M=>{if(C||t()){for(let P of M)P.url?.startsWith("blob:")&&URL.revokeObjectURL(P.url);return}O=M.flatMap(P=>P.url?.startsWith("blob:")?[P.url]:[]);for(let P=0;P<v.pages.length;P++){let X=v.pages[P],$=M[P];if($)for(let W of X.entries){let ne=A.get(W.index);!ne||!$.url||(Zn(ne,$,r,W),ye(ne,"opacity"))}}}).catch(()=>{if(!(C||t()))for(let M of A.values())ee(M,"opacity","0.5"),ee(M,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:x,solidPaintDefaults:m,dispose(){C=!0;for(let M of O)URL.revokeObjectURL(M);O=[]}}}function rs(e,n){let t=e.map((o,r)=>ut(o,r,n));return t.some(o=>!o)?null:t}function ss(e){e.style.backgroundImage="",e.style.backgroundPosition="",e.style.backgroundSize="",e.style.maskImage="",e.style.maskMode="",e.style.maskPosition="",e.style.maskSize="",e.style.maskRepeat="",e.style.removeProperty("-webkit-mask-image"),e.style.removeProperty("-webkit-mask-position"),e.style.removeProperty("-webkit-mask-size"),e.style.removeProperty("-webkit-mask-repeat")}function co(e,n){e.setAttribute("style",n.styleText),(n.polygon.data||jt.get(e)?.length)&&Oe(e,n.polygon)}function mn(e,n){let t=n.createElement("u");return ss(t),co(t,e),Oe(t,e.polygon),t}function pn(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};if(!dt(t))return null;let o=rs(e,n);if(!o)return null;let r=[];for(let s of o){let i=mn(s,t);r.push({polygonIndex:s.index,element:i,kind:"triangle",dispose:()=>{}})}return r.sort((s,i)=>s.polygonIndex-i.polygonIndex),{rendered:r,dispose(){}}}function uo(e,n,t={}){if(e.length!==n.length)return!1;let o=t.textureLighting??"baked",r=[];for(let s=0;s<e.length;s++){let i=e[s];if(i.polygonIndex!==s)return!1;let a=n[s];if(!a)return!1;if(i.kind==="atlas"){if(!i.plan||!Kr(i.element,i.plan,a,o))return!1;continue}if(i.kind==="triangle"){let l=ut(a,s,t);if(!l)return!1;r[s]=l;continue}return!1}for(let s=0;s<e.length;s++){let i=e[s];if(i.kind==="triangle"){let a=r[s];if(!a)return!1;co(i.element,a)}}return!0}var ce=require("@layoutit/polycss-core"),is=[.4,-.7,.59],as="#ffffff",ls=1,cs="#ffffff",us=.4,po={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},ds=["t","b","bl","br","fr","fl"],ms=new Map([["0,0,1","t"],["0,0,-1","b"],["0,1,0","fl"],["0,-1,0","br"],["1,0,0","fr"],["-1,0,0","bl"]]);function mo(e){let n=[];for(let t of ds)(0,ce.normalFacesCamera)(po[t],e)&&n.push(t);return n.join("|")}function ps(e,n,t){let o=e.__polycssVoxelBrushState??(e.__polycssVoxelBrushState={});o.color!==n&&(e.style.color=n,o.color=n),o.transform!==t&&(e.style.transform=t,o.transform=t)}function fs(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let a=1;a+1<n.length;a+=1){let l=n[a],u=n[a+1],p=l[1]-t[1],d=l[0]-t[0],f=l[2]-t[2],g=u[1]-t[1],m=u[0]-t[0],h=u[2]-t[2];o-=d*h-f*m,r-=f*g-p*h,s-=p*m-d*g}let i=Math.hypot(o,r,s);return i<=1e-9?null:[Math.round(o/i),Math.round(r/i),Math.round(s/i)]}function hs(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=fs(e),t=n?ms.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,s=1/0,i=-1/0,a=-1/0,l=-1/0;for(let d of e.vertices)o=Math.min(o,d[0]),r=Math.min(r,d[1]),s=Math.min(s,d[2]),i=Math.max(i,d[0]),a=Math.max(a,d[1]),l=Math.max(l,d[2]);let u=1e-6,p=e.color||"#cccccc";return Math.abs(l-s)<=u?{axis:"z",face:t,left:r*ce.BASE_TILE,top:o*ce.BASE_TILE,width:Math.max(0,(a-r)*ce.BASE_TILE),height:Math.max(0,(i-o)*ce.BASE_TILE),z:s*ce.BASE_TILE,baseColor:p}:Math.abs(i-o)<=u?{axis:"x",face:t,left:r*ce.BASE_TILE,top:s*ce.BASE_TILE,width:Math.max(0,(a-r)*ce.BASE_TILE),height:Math.max(0,(l-s)*ce.BASE_TILE),z:-o*ce.BASE_TILE,baseColor:p}:Math.abs(a-r)<=u?{axis:"y",face:t,left:s*ce.BASE_TILE,top:o*ce.BASE_TILE,width:Math.max(0,(l-s)*ce.BASE_TILE),height:Math.max(0,(i-o)*ce.BASE_TILE),z:-r*ce.BASE_TILE,baseColor:p}:null}function fn(e){let n=(0,ce.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha}:{r:255,g:255,b:255,alpha:1}}function gs({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function hn(e){return Math.round(Math.max(0,Math.min(255,e)))}function ys(e,n,t,o){let r=fn(n),s=fn(t?.color??as),i=fn(o?.color??cs),a=t?.direction??is,l=Math.hypot(a[0],a[1],a[2])||1,u=a[0]/l,p=a[1]/l,d=a[2]/l,f=Math.max(0,t?.intensity??ls)*Math.max(0,e[0]*u+e[1]*p+e[2]*d),g=Math.max(0,o?.intensity??us),m=i.r/255*g+s.r/255*f,h=i.g/255*g+s.g/255*f,y=i.b/255*g+s.b/255*f,v={r:r.r*m,g:r.g*h,b:r.b*y,alpha:r.alpha};return v.alpha<1?`rgba(${hn(v.r)}, ${hn(v.g)}, ${hn(v.b)}, ${v.alpha})`:gs(v)}function bs(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=hs(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return n}function xs(e,n,t,o,r,s){return`matrix3d(${(e==="x"?[o,0,0,0,0,0,r,0,0,-1,0,0,n,-s,t,1]:e==="y"?[0,0,o,0,0,r,0,0,-1,0,0,0,-s,t,n,1]:[o,0,0,0,0,r,0,0,0,0,1,0,n,t,s,1]).map(a=>Number(a.toFixed(6))).join(",")})`}function vs(e){return e.axis==="x"?[e.left+e.width/2,-e.z,e.top+e.height/2]:e.axis==="y"?[-e.z,e.top+e.height/2,e.left+e.width/2]:[e.left+e.width/2,e.top+e.height/2,e.z]}function Ps(e,n){let t=vs(e),o=n.meshRotation;o&&(t=(0,ce.rotateVec3)(t,o[0]??0,o[1]??0,o[2]??0));let[r,s]=(0,ce.rotateVec3)(t,n.rotX,0,n.rotY);return{x:r,y:s}}function Es(e,n,t){let o=e.filter(f=>n.has(f.face)).map(f=>({item:f,...Ps(f,t)}));if(o.length===0)return[];let r=1/0,s=-1/0,i=1/0,a=-1/0;for(let f of o)r=Math.min(r,f.x),s=Math.max(s,f.x),i=Math.min(i,f.y),a=Math.max(a,f.y);let l=4,u=Math.max(1e-6,s-r),p=Math.max(1e-6,a-i),d=new Map;for(let f of o){let g=Math.min(l-1,Math.max(0,Math.floor((f.x-r)/u*l))),m=Math.min(l-1,Math.max(0,Math.floor((f.y-i)/p*l))),h=`${g}:${m}`,y=d.get(h);y||(y={tx:g,ty:m,sourceIndex:f.item.sourceIndex,items:[]},d.set(h,y)),y.items.push(f.item),y.sourceIndex=Math.min(y.sourceIndex,f.item.sourceIndex)}return Array.from(d.values()).sort((f,g)=>f.ty-g.ty||f.tx-g.tx||f.sourceIndex-g.sourceIndex).flatMap(f=>f.items)}function fo(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:s}=e,i=bs(o);if(i.length===0)return null;t.classList.add("polycss-voxel-mesh");let a=new Map,l=(m,h)=>{let y=`${m}|${h}`,v=a.get(y);if(v)return v;let E=ys(po[m],h,r,s);return a.set(y,E),E},u=[],p="",d=0,f=m=>{let h=u[m];return h||(h=n.createElement("b"),u[m]=h),h.parentElement!==t&&t.appendChild(h),h},g=(m,h)=>{let y=new Set(m.split("|").filter(Boolean)),v=Es(i,y,h);d=0;for(let E of v){let A=f(d);ps(A,l(E.face,E.baseColor),xs(E.axis,E.left,E.top,E.width,E.height,E.z)),d+=1}for(let E=d;E<u.length;E+=1)u[E]?.remove()};return{element:t,get brushCount(){return d},render(m){p=mo(m),g(p,m)},syncCamera(m){let h=mo(m);h!==p&&(p=h,g(h,m))},dispose(){for(let m of u)m.remove();t.classList.remove("polycss-voxel-mesh"),u.length=0,d=0,p=""}}}var ho="polycss-styles";function pt(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(ho))return;let t=n.createElement("style");t.id=ho,t.textContent=Cs,n.head.appendChild(t)}var Cs=`
|
|
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,
|
|
@@ -15,13 +15,29 @@
|
|
|
15
15
|
width: 0;
|
|
16
16
|
height: 0;
|
|
17
17
|
transform-style: preserve-3d;
|
|
18
|
-
perspective:
|
|
19
|
-
|
|
18
|
+
perspective: 8000px;
|
|
19
|
+
/* Pin the scene as a composited layer. Without this, mobile Chrome
|
|
20
|
+
re-rasterizes every descendant tile when the scene transform changes
|
|
21
|
+
each animation frame, which overruns the raster budget on textured
|
|
22
|
+
meshes (faces drop, fragments float). With will-change, the GPU
|
|
23
|
+
reuses the cached layer pixels and only re-composites. */
|
|
24
|
+
will-change: transform;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
/* \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
|
+
|
|
29
|
+
/* PolyFirstPersonControls toggles this class on its host element (vanilla:
|
|
30
|
+
scene.host; react/vue: the camera wrapper). FPV needs a real perspective
|
|
31
|
+
context so scene Z translation produces visible depth motion - without
|
|
32
|
+
it, walking forward looks like a planar pan. The class wins over inline
|
|
33
|
+
perspective styles (e.g. PolyOrthographicCamera's perspective: none)
|
|
34
|
+
via !important. The actual perspective value is set inline by the
|
|
35
|
+
controls as the --polycss-fpv-perspective custom property; the default
|
|
36
|
+
of 2000px matches the controls' lookOffset fallback so the FPV math and
|
|
37
|
+
visual perspective stay in sync. */
|
|
38
|
+
.polycss-fpv-host {
|
|
39
|
+
perspective: var(--polycss-fpv-perspective, 2000px) !important;
|
|
40
|
+
transform-style: preserve-3d !important;
|
|
25
41
|
}
|
|
26
42
|
|
|
27
43
|
/* \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 */
|
|
@@ -53,22 +69,77 @@
|
|
|
53
69
|
background-repeat: no-repeat;
|
|
54
70
|
}
|
|
55
71
|
|
|
72
|
+
.polycss-scene b,
|
|
73
|
+
.polycss-scene i,
|
|
74
|
+
.polycss-scene u {
|
|
75
|
+
color: var(--polycss-paint, currentColor);
|
|
76
|
+
}
|
|
77
|
+
|
|
56
78
|
.polycss-scene b {
|
|
79
|
+
background: currentColor;
|
|
80
|
+
width: 64px;
|
|
81
|
+
height: 64px;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.polycss-mesh.polycss-voxel-mesh > b {
|
|
85
|
+
top: 0;
|
|
86
|
+
left: 0;
|
|
87
|
+
width: 1px;
|
|
88
|
+
height: 1px;
|
|
89
|
+
backface-visibility: visible;
|
|
90
|
+
pointer-events: none;
|
|
57
91
|
}
|
|
58
92
|
|
|
59
93
|
.polycss-scene i {
|
|
94
|
+
width: 16px;
|
|
95
|
+
height: 16px;
|
|
60
96
|
border-color: currentColor;
|
|
61
97
|
}
|
|
62
98
|
|
|
63
99
|
.polycss-scene s {
|
|
100
|
+
width: var(--polycss-atlas-size, 64px);
|
|
101
|
+
height: var(--polycss-atlas-size, 64px);
|
|
64
102
|
}
|
|
65
103
|
|
|
66
104
|
.polycss-scene u {
|
|
67
|
-
width:
|
|
68
|
-
height:
|
|
105
|
+
width: 0;
|
|
106
|
+
height: 0;
|
|
69
107
|
background: transparent;
|
|
70
108
|
box-sizing: content-box;
|
|
71
109
|
border: 0 solid transparent;
|
|
110
|
+
border-color: transparent transparent currentColor transparent;
|
|
111
|
+
border-width: 0 32px 64px 32px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* <q> \u2014 dedicated shadow leaf. Same border-shape rendering trick as <i>
|
|
115
|
+
(border-color: currentColor fills the polygon outline) but with its
|
|
116
|
+
own tag so we don't have to thread :not(.polycss-shadow) exclusions
|
|
117
|
+
through every dynamic-mode color rule. backface-visibility must be
|
|
118
|
+
visible because the projection matrix is near-rank-deficient and the
|
|
119
|
+
resulting plane's normal can read as back-facing under some camera
|
|
120
|
+
angles; the leaf is intentionally always painted. Strip the UA's
|
|
121
|
+
default ::before/::after open-/close-quote so the element is just a
|
|
122
|
+
styled box. */
|
|
123
|
+
.polycss-scene q {
|
|
124
|
+
position: absolute;
|
|
125
|
+
display: block;
|
|
126
|
+
transform-origin: 0 0;
|
|
127
|
+
transform-style: preserve-3d;
|
|
128
|
+
margin: 0;
|
|
129
|
+
padding: 0;
|
|
130
|
+
font: inherit;
|
|
131
|
+
font-weight: normal;
|
|
132
|
+
font-style: normal;
|
|
133
|
+
line-height: 0;
|
|
134
|
+
text-decoration: none;
|
|
135
|
+
backface-visibility: visible;
|
|
136
|
+
border-color: currentColor;
|
|
137
|
+
pointer-events: none;
|
|
138
|
+
will-change: transform;
|
|
139
|
+
}
|
|
140
|
+
.polycss-scene q::before,
|
|
141
|
+
.polycss-scene q::after {
|
|
142
|
+
content: none;
|
|
72
143
|
}
|
|
73
144
|
|
|
74
145
|
/* \u2500\u2500 Gizmo override (createTransformControls) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
@@ -78,15 +149,42 @@
|
|
|
78
149
|
* pipeline as user content but the gizmo is a UI affordance \u2014 both
|
|
79
150
|
* faces of every polygon should remain visible regardless of camera
|
|
80
151
|
* orientation, otherwise the cuboid shafts and pyramid heads end up
|
|
81
|
-
* half-culled. Transitions on border-color and background-color
|
|
82
|
-
* the idle / hover / drag alpha changes.
|
|
152
|
+
* half-culled. Transitions on color, border-color, and background-color
|
|
153
|
+
* smooth the idle / hover / drag alpha changes.
|
|
83
154
|
*/
|
|
84
155
|
.polycss-mesh.polycss-transform-gizmo i,
|
|
85
156
|
.polycss-mesh.polycss-transform-gizmo b,
|
|
86
157
|
.polycss-mesh.polycss-transform-gizmo s,
|
|
87
158
|
.polycss-mesh.polycss-transform-gizmo u {
|
|
88
159
|
backface-visibility: visible;
|
|
89
|
-
transition: border-color 150ms ease-out, background-color 150ms ease-out;
|
|
160
|
+
transition: color 150ms ease-out, border-color 150ms ease-out, background-color 150ms ease-out;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/*
|
|
164
|
+
* Rotate rings are rendered as a single square quad per ring, then masked
|
|
165
|
+
* to a donut via a radial-gradient. The --ring-inner-ratio CSS var is set
|
|
166
|
+
* inline by createTransformControls (= innerR / outerR, where outerR maps
|
|
167
|
+
* to the quad's edge at 50%). Hit-testing has to use the donut shape too.
|
|
168
|
+
* Single DOM node per ring instead of N segment quads.
|
|
169
|
+
*/
|
|
170
|
+
.polycss-mesh.polycss-transform-ring i,
|
|
171
|
+
.polycss-mesh.polycss-transform-ring b,
|
|
172
|
+
.polycss-mesh.polycss-transform-ring s,
|
|
173
|
+
.polycss-mesh.polycss-transform-ring u {
|
|
174
|
+
--ring-inner-r: calc(var(--ring-inner-ratio, 0.92) * 50%);
|
|
175
|
+
--ring-outer-r: calc(var(--ring-outer-ratio, 1) * 50%);
|
|
176
|
+
-webkit-mask: radial-gradient(circle at 50% 50%,
|
|
177
|
+
transparent 0%,
|
|
178
|
+
transparent var(--ring-inner-r),
|
|
179
|
+
black var(--ring-inner-r),
|
|
180
|
+
black var(--ring-outer-r),
|
|
181
|
+
transparent var(--ring-outer-r));
|
|
182
|
+
mask: radial-gradient(circle at 50% 50%,
|
|
183
|
+
transparent 0%,
|
|
184
|
+
transparent var(--ring-inner-r),
|
|
185
|
+
black var(--ring-inner-r),
|
|
186
|
+
black var(--ring-outer-r),
|
|
187
|
+
transparent var(--ring-outer-r));
|
|
90
188
|
}
|
|
91
189
|
|
|
92
190
|
/* \u2500\u2500 Dynamic lighting cascade vars (scene root \u2192 polygons) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
@@ -106,6 +204,20 @@
|
|
|
106
204
|
@property --plx { syntax: "<number>"; inherits: true; initial-value: 0; }
|
|
107
205
|
@property --ply { syntax: "<number>"; inherits: true; initial-value: 0; }
|
|
108
206
|
@property --plz { syntax: "<number>"; inherits: true; initial-value: 1; }
|
|
207
|
+
|
|
208
|
+
/* CSS-space light components (world-Y\u2192cssX, world-X\u2192cssY, world-Z\u2192cssZ).
|
|
209
|
+
Used by the shadow projection matrix. --clx is clamped away from 0 in JS
|
|
210
|
+
to avoid divide-by-zero when the light is near-horizontal. */
|
|
211
|
+
@property --clx { syntax: "<number>"; inherits: true; initial-value: 0.01; }
|
|
212
|
+
@property --cly { syntax: "<number>"; inherits: true; initial-value: 0; }
|
|
213
|
+
@property --clz { syntax: "<number>"; inherits: true; initial-value: 1; }
|
|
214
|
+
|
|
215
|
+
/* Ground-plane position in CSS pixels along the CSS-Z axis (= world-Z, the
|
|
216
|
+
up axis in polycss's world convention). Stored as a <number> so it can be
|
|
217
|
+
used directly inside matrix3d() calc() expressions (matrix3d requires
|
|
218
|
+
dimensionless entries \u2014 no px units).
|
|
219
|
+
Set by recomputeShadowGround() from the min world-Z of casting meshes. */
|
|
220
|
+
@property --shadow-ground-cssz { syntax: "<number>"; inherits: true; initial-value: 0; }
|
|
109
221
|
@property --plr { syntax: "<number>"; inherits: true; initial-value: 1; }
|
|
110
222
|
@property --plg { syntax: "<number>"; inherits: true; initial-value: 1; }
|
|
111
223
|
@property --plb { syntax: "<number>"; inherits: true; initial-value: 1; }
|
|
@@ -123,9 +235,9 @@
|
|
|
123
235
|
@property --pnx { syntax: "<number>"; inherits: true; initial-value: 0; }
|
|
124
236
|
@property --pny { syntax: "<number>"; inherits: true; initial-value: 0; }
|
|
125
237
|
@property --pnz { syntax: "<number>"; inherits: true; initial-value: 1; }
|
|
126
|
-
@property --psr { syntax: "<number>"; inherits:
|
|
127
|
-
@property --psg { syntax: "<number>"; inherits:
|
|
128
|
-
@property --psb { syntax: "<number>"; inherits:
|
|
238
|
+
@property --psr { syntax: "<number>"; inherits: true; initial-value: 1; }
|
|
239
|
+
@property --psg { syntax: "<number>"; inherits: true; initial-value: 1; }
|
|
240
|
+
@property --psb { syntax: "<number>"; inherits: true; initial-value: 1; }
|
|
129
241
|
|
|
130
242
|
/* Hoisted Lambert dot product \u2014 computed once per element it's set on.
|
|
131
243
|
inherits:true so a bucket wrapper computes lambert ONCE for its whole
|
|
@@ -171,6 +283,7 @@
|
|
|
171
283
|
leaf). */
|
|
172
284
|
.polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > i,
|
|
173
285
|
.polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > b,
|
|
286
|
+
.polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > s,
|
|
174
287
|
.polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > u {
|
|
175
288
|
--plam: max(0, calc(
|
|
176
289
|
var(--pnx) * var(--plx) +
|
|
@@ -179,7 +292,7 @@
|
|
|
179
292
|
));
|
|
180
293
|
}
|
|
181
294
|
|
|
182
|
-
/*
|
|
295
|
+
/* Atlas polys: containment + background-color from lambert (inherited or
|
|
183
296
|
own) and the scene-level light vars. Splitting this from the lambert
|
|
184
297
|
calc above lets bucketed polys skip the dot-product entirely. */
|
|
185
298
|
.polycss-scene[data-polycss-lighting="dynamic"] s {
|
|
@@ -200,29 +313,10 @@
|
|
|
200
313
|
background-blend-mode: multiply;
|
|
201
314
|
}
|
|
202
315
|
|
|
203
|
-
.polycss-scene[data-polycss-lighting="dynamic"] b
|
|
204
|
-
|
|
205
|
-
calc(255 * var(--psr) * (var(--par) * var(--pai)
|
|
206
|
-
+ var(--plr) * var(--pli) * max(0,
|
|
207
|
-
var(--pnx) * var(--plx) +
|
|
208
|
-
var(--pny) * var(--ply) +
|
|
209
|
-
var(--pnz) * var(--plz))))
|
|
210
|
-
calc(255 * var(--psg) * (var(--pag) * var(--pai)
|
|
211
|
-
+ var(--plg) * var(--pli) * max(0,
|
|
212
|
-
var(--pnx) * var(--plx) +
|
|
213
|
-
var(--pny) * var(--ply) +
|
|
214
|
-
var(--pnz) * var(--plz))))
|
|
215
|
-
calc(255 * var(--psb) * (var(--pab) * var(--pai)
|
|
216
|
-
+ var(--plb) * var(--pli) * max(0,
|
|
217
|
-
var(--pnx) * var(--plx) +
|
|
218
|
-
var(--pny) * var(--ply) +
|
|
219
|
-
var(--pnz) * var(--plz))))
|
|
220
|
-
);
|
|
221
|
-
background-blend-mode: normal;
|
|
222
|
-
}
|
|
223
|
-
|
|
316
|
+
.polycss-scene[data-polycss-lighting="dynamic"] b,
|
|
317
|
+
.polycss-scene[data-polycss-lighting="dynamic"] i,
|
|
224
318
|
.polycss-scene[data-polycss-lighting="dynamic"] u {
|
|
225
|
-
|
|
319
|
+
color: rgb(
|
|
226
320
|
calc(255 * var(--psr) * (var(--par) * var(--pai)
|
|
227
321
|
+ var(--plr) * var(--pli) * var(--plam)))
|
|
228
322
|
calc(255 * var(--psg) * (var(--pag) * var(--pai)
|
|
@@ -231,4 +325,64 @@
|
|
|
231
325
|
+ var(--plb) * var(--pli) * var(--plam)))
|
|
232
326
|
);
|
|
233
327
|
}
|
|
234
|
-
`;var lo=65,co=45,uo=1,ae=q.BASE_TILE;function Ft(e){let n=[];return e.position&&n.push(`translate3d(${e.position[0]}px, ${e.position[1]}px, ${e.position[2]}px)`),e.scale!==void 0&&(typeof e.scale=="number"?e.scale!==1&&n.push(`scale3d(${e.scale}, ${e.scale}, ${e.scale})`):n.push(`scale3d(${e.scale[0]}, ${e.scale[1]}, ${e.scale[2]})`)),e.rotation&&(e.rotation[0]&&n.push(`rotateX(${e.rotation[0]}deg)`),e.rotation[1]&&n.push(`rotateY(${e.rotation[1]}deg)`),e.rotation[2]&&n.push(`rotateZ(${e.rotation[2]}deg)`)),n.length>0?n.join(" "):void 0}function po(e){let n=e.rotX??lo,t=e.rotY??co,o=e.zoom??uo,r=e.distance??0,s=e.target??[0,0,0],i=s[1]*ae,c=s[0]*ae,l=s[2]*ae;return`${r!==0?`translateZ(${-r}px) `:""}scale(${o}) rotateX(${n}deg) rotate(${t}deg) translate3d(${-i}px, ${-c}px, ${-l}px)`}var mo=.1;function fo(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=e.vertices[1],o=e.vertices[2],r=t[1]-n[1],s=t[0]-n[0],i=t[2]-n[2],c=o[1]-n[1],l=o[0]-n[0],a=o[2]-n[2],d=-(s*a-i*l),m=-(i*c-r*a),f=-(r*l-s*c),h=Math.hypot(d,m,f);if(h<1e-9)return null;d/=h,m/=h,f/=h;let u=1/mo,p=Math.round(d*u)/u,b=Math.round(m*u)/u,x=Math.round(f*u)/u,C=Math.hypot(p,b,x);return C<1e-9?null:{key:p+","+b+","+x,vec:[p/C,b/C,x/C]}}function Le(e,n={}){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");e.ownerDocument&&Te(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let t={...n},o=e.ownerDocument??document,r=o.createElement("div");r.className="polycss-scene",r.setAttribute("aria-hidden","true"),c(r,t);let s=o.createElement("div");s.className="polycss-offset",r.appendChild(s),e.appendChild(r);let i=new Set;function c(y,g){y.style.setProperty("--scene-transform",po(g)),l(y,g)}function l(y,g){let _=g.textureLighting==="dynamic";y.dataset.polycssLighting=g.textureLighting??"baked";let E=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai"];if(!_){for(let F of E)y.style.removeProperty(F);return}let w=g.directionalLight?.direction??[.4,-.7,.59],S=Math.hypot(w[0],w[1],w[2])||1,v=w[0]/S,O=w[1]/S,T=w[2]/S,R=(0,q.parseHexColor)(g.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],A=(0,q.parseHexColor)(g.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],P=g.directionalLight?.intensity??1,D=g.ambientLight?.intensity??.4,k=F=>(F/255).toFixed(4);y.style.setProperty("--plx",v.toFixed(4)),y.style.setProperty("--ply",O.toFixed(4)),y.style.setProperty("--plz",T.toFixed(4)),y.style.setProperty("--plr",k(R[0])),y.style.setProperty("--plg",k(R[1])),y.style.setProperty("--plb",k(R[2])),y.style.setProperty("--pli",P.toFixed(4)),y.style.setProperty("--par",k(A[0])),y.style.setProperty("--pag",k(A[1])),y.style.setProperty("--pab",k(A[2])),y.style.setProperty("--pai",D.toFixed(4))}function a(y){for(d(y.rendered,y.disposeAtlas),y.disposeAtlas=void 0,y.rendered.length=0;y.wrapper.firstChild;)y.wrapper.removeChild(y.wrapper.firstChild)}function d(y,g){g?.();for(let _ of y){try{_.dispose()}catch{}_.element.parentNode&&_.element.parentNode.removeChild(_.element)}}function m(y){let g=o.createDocumentFragment(),_=t.textureLighting==="dynamic"&&!y.stableDom,E=new Map,w=[];for(let S of y.rendered){let v=y.polygons[S.polygonIndex],O=_&&v?fo(v):null;if(!O){w.push(S);continue}let T=O.key+"|"+(v.color??""),R=E.get(T);R||(R={vec:O.vec,items:[]},E.set(T,R)),R.items.push(S)}for(let S of w)g.appendChild(S.element);for(let S of E.values()){if(S.items.length<2){for(let O of S.items)g.appendChild(O.element);continue}let v=o.createElement("div");v.className="polycss-bucket",v.style.setProperty("--pnx",String(S.vec[0])),v.style.setProperty("--pny",String(S.vec[1])),v.style.setProperty("--pnz",String(S.vec[2]));for(let O of S.items)v.appendChild(O.element),O.element.style.removeProperty("--pnx"),O.element.style.removeProperty("--pny"),O.element.style.removeProperty("--pnz");g.appendChild(v)}y.wrapper.appendChild(g)}function f(y,g){let _=t.textureLighting==="dynamic",E=t.directionalLight?.direction,w=g&&(g[0]!==0||g[1]!==0||g[2]!==0);if(!_||!w||!E){y.style.removeProperty("--plx"),y.style.removeProperty("--ply"),y.style.removeProperty("--plz");return}let S=(0,q.inverseRotateVec3)(E,g),v=Math.hypot(S[0],S[1],S[2])||1;y.style.setProperty("--plx",(S[0]/v).toFixed(4)),y.style.setProperty("--ply",(S[1]/v).toFixed(4)),y.style.setProperty("--plz",(S[2]/v).toFixed(4))}function h(y,g){a(y);let _=t.directionalLight,E=g?{..._,direction:g}:_,w={doc:o,directionalLight:E,ambientLight:t.ambientLight,textureLighting:t.textureLighting,atlasScale:t.atlasScale},S=(y.stableDom?Vt(y.polygons,w):null)??Ht(y.polygons,w);y.rendered=S.rendered,y.disposeAtlas=S.dispose,m(y)}function u(){if(!t.autoCenter){s.style.removeProperty("--offset-transform");return}let y=[];for(let v of i)!v.disposed&&!v.excludeFromAutoCenter&&y.push(...v.polygons);if(y.length===0){s.style.removeProperty("--offset-transform");return}let g=(0,q.computeSceneBbox)(y),_=ae,E=(g.min[1]+g.max[1])/2*_,w=(g.min[0]+g.max[0])/2*_,S=(g.min[2]+g.max[2])/2*_;s.style.setProperty("--offset-transform",`translate3d(${-E}px, ${-w}px, ${-S}px)`)}function p(y,g={}){let E=(r.ownerDocument??document).createElement("div");E.className="polycss-mesh",g.id&&E.setAttribute("data-poly-mesh-id",g.id);let w={...g},S=g.merge!==!1,v=!!g.stableDom,O=Ft(w);O&&(E.style.transform=O);let T=(k,F)=>F?(0,q.mergePolygons)(k):k,R=T(y.polygons,S);function A(k){if(k.length===0){E.style.removeProperty("--origin");return}let F=1/0,j=1/0,L=1/0,I=-1/0,V=-1/0,X=-1/0;for(let Y of k)for(let z of Y.vertices)z[0]<F&&(F=z[0]),z[0]>I&&(I=z[0]),z[1]<j&&(j=z[1]),z[1]>V&&(V=z[1]),z[2]<L&&(L=z[2]),z[2]>X&&(X=z[2]);if(!Number.isFinite(F)){E.style.removeProperty("--origin");return}let W=(j+V)/2*ae,Z=(F+I)/2*ae,G=(L+X)/2*ae;E.style.setProperty("--origin",`${W}px ${Z}px ${G}px`)}A(R),s.appendChild(E);let P={handle:void 0,wrapper:E,parseResult:y,rendered:[],polygons:R,disposed:!1,stableDom:v,excludeFromAutoCenter:!!g.excludeFromAutoCenter,bakedRotation:g.rotation?[...g.rotation]:[0,0,0]},D={polygons:R,element:E,id:g.id,get transform(){return w},remove(){E.parentNode&&E.parentNode.removeChild(E),a(P),i.delete(P),u()},setPolygons(k,F){S=F?.merge??S,v=F?.stableDom??v,P.stableDom=v,P.polygons=T(k,S),D.polygons=P.polygons,A(P.polygons);let j=F?.recomputeAutoCenter??!0;if(P.stableDom&&!P.wrapper.querySelector(".polycss-bucket")){let L={doc:o,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,atlasScale:t.atlasScale},I=zt(P.rendered,P.polygons,L);if(I){P.disposeAtlas?.(),P.rendered=I.rendered,P.disposeAtlas=I.dispose,j&&u();return}}h(P),j&&u()},setTransform(k){w={...w,...k};let F=Ft(w);E.style.transform=F??"",f(E,w.rotation)},dispose(){if(!P.disposed){P.disposed=!0,E.parentNode&&E.parentNode.removeChild(E),a(P);try{y.dispose()}catch{}i.delete(P),u()}},rebakeAtlas(){P.bakedRotation=w.rotation?[...w.rotation]:[0,0,0];let k=t.directionalLight?.direction??[.4,-.7,.59],F=(0,q.inverseRotateVec3)(k,P.bakedRotation);h(P,F)},getPosition(){return w.position},getRotation(){return w.rotation},getScale(){return w.scale},getPolygons(){return D.polygons}};return P.handle=D,i.add(P),h(P),f(E,w.rotation),u(),D}function b(y){let g=!!t.autoCenter;t={...t,...y},c(r,t);let _=!!t.autoCenter;for(let E of i)f(E.wrapper,E.handle.transform.rotation);g!==_&&u()}function x(){return t}function C(){let y=[];for(let g of i)y.push(g.handle);return y}function M(y){let g=y;for(;g;){if(g instanceof HTMLElement&&g.classList.contains("polycss-mesh")){for(let _ of i)if(_.wrapper===g)return _.handle;return null}g=g.parentElement}return null}function H(){let y=Array.from(i);for(let g of y)try{g.handle.dispose()}catch{}r.parentNode&&r.parentNode.removeChild(r)}return{add:p,setOptions:b,destroy:H,host:e,getOptions:x,meshes:C,findMeshByElement:M}}var lt=require("@layoutit/polycss-core"),ho=8e3;function be(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,lt.createIsometricCamera)(n),o=`${e.perspective??ho}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function Se(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,lt.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var Nt=require("@layoutit/polycss-core");var _e={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function fe(e,n){let t;return n.animate===!1?t=!1:n.animate?t={speed:n.animate.speed??.3,axis:n.animate.axis??"y",pauseOnInteraction:n.animate.pauseOnInteraction??!0}:t=e.animate,{drag:n.drag??e.drag,wheel:n.wheel??e.wheel,dolly:n.dolly??e.dolly,invert:n.invert??e.invert,minZoom:n.minZoom??e.minZoom,maxZoom:n.maxZoom??e.maxZoom,minDistance:n.minDistance??e.minDistance,maxDistance:n.maxDistance??e.maxDistance,animate:t}}function ve(e){return e===!0?-1:e===!1?1:e}function we(){let e=[],n=[],t=[];function o(i){return i==="change"?e:i==="start"?n:t}function r(i){if(e.length===0)return;let c={type:"change",camera:i()},l=e.slice();for(let a of l)try{a(c)}catch(d){console.error("[polycss] controls 'change' listener threw:",d)}}function s(i,c){let l=i==="start"?n:t;if(l.length===0)return;let a={type:i,camera:c()},d=l.slice();for(let m of d)try{m(a)}catch(f){console.error(`[polycss] controls '${i}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function Oe(e){return()=>{let n=e.getOptions(),t=n.target??[0,0,0];return{rotX:n.rotX??0,rotY:n.rotY??0,zoom:n.zoom??1,target:[t[0],t[1],t[2]],distance:n.distance??0}}}function ke(e,n,t,o,r,s){let i=!1,c=null;return{onWheel:d=>{let m=n();if(!m.wheel||t())return;d.preventDefault();let f=d.deltaMode===1?16:d.deltaMode===2?100:1,h=d.deltaY*f;d.ctrlKey?h*=10:h*=3;let u=e.getOptions();if(m.dolly){let p=u.distance??0,b=Math.max(m.minDistance,Math.min(m.maxDistance,p+h*.05));e.setOptions({distance:b})}else{let p=Math.exp(-h*513e-6),b=u.zoom??1,x=Math.max(m.minZoom,Math.min(m.maxZoom,b*p));e.setOptions({zoom:x})}i||(i=!0,s("start",o)),r(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,i=!1,s("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),i=!1}}}function He(e,n,t,o,r,s,i){let c=null,l=0,a=h=>{if(c===null||o())return;let u=t();if(!u.animate){c=null;return}if(r())l=h;else{let p=Math.min(50,l?h-l:16.67);l=h;let b=u.animate.speed*(p/16.67),x=n.getOptions();if(u.animate.axis==="x"){let C=(((x.rotX??65)+b)%360+360)%360;n.setOptions({rotX:C})}else{let C=(((x.rotY??45)+b)%360+360)%360;n.setOptions({rotY:C})}i(s)}c=e.requestAnimationFrame(a)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(a))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function De(e,n={}){let t=fe(_e,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,a=we(),d=Oe(e),{changeListeners:m,startListeners:f,endListeners:h,listenerArray:u,emitChange:p,emitInteraction:b}=a,x=He(r,e,()=>t,()=>l,()=>c,d,p),C=A=>{if(!(!t.drag||l)&&s===null&&A.isPrimary!==!1){A.preventDefault(),s=A.pointerId,i={x:A.clientX,y:A.clientY},o.style.cursor="grabbing";try{A.target.setPointerCapture(A.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),b("start",d)}},M=A=>{if(s===null||A.pointerId!==s||!t.drag||l)return;A.preventDefault();let P=A.clientX-i.x,D=A.clientY-i.y;i={x:A.clientX,y:A.clientY};let k=ve(t.invert),F=P/4*k,j=D/4*k,L=e.getOptions();if(A.shiftKey){let I=L.rotX??65,V=L.rotY??45,X=Math.max(.01,L.zoom??1),W=Math.cos(I*Math.PI/180),Z=W>=0?Math.max(.1,W):Math.min(-.1,W),G=Math.cos(V*Math.PI/180),Y=Math.sin(V*Math.PI/180),z=X*Nt.BASE_TILE,ne=(P*Y-D*G/Z)/z,ce=-(P*G+D*Y/Z)/z,oe=L.target??[0,0,0];e.setOptions({target:[oe[0]+ne,oe[1]+ce,oe[2]]})}else{let I=Math.max(0,Math.min(100,(L.rotX??65)-j)),V=(((L.rotY??45)-F)%360+360)%360;e.setOptions({rotX:I,rotY:V})}p(d)},H=A=>{if(s===A.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{A.target.releasePointerCapture(A.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),b("end",d)}},y=ke(e,()=>t,()=>l,d,p,b);function g(){o.addEventListener("pointerdown",C),o.addEventListener("pointermove",M),o.addEventListener("pointerup",H),o.addEventListener("pointercancel",H),o.addEventListener("wheel",y.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function _(){o.removeEventListener("pointerdown",C),o.removeEventListener("pointermove",M),o.removeEventListener("pointerup",H),o.removeEventListener("pointercancel",H),o.removeEventListener("wheel",y.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",y.teardown()}g(),x.start();function E(A){let P=!!t.animate;t=fe(t,A),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let D=!!t.animate;P&&!D?x.stop():!P&&D&&x.start()}function w(){l&&(l=!1,g(),x.start())}function S(){l||(l=!0,_(),x.stop(),s=null,c=!1,y.teardown())}function v(){S(),m.length=0,f.length=0,h.length=0}function O(A,P){let D=u(A);D.includes(P)||D.push(P)}function T(A,P){let D=u(A),k=D.indexOf(P);k>=0&&D.splice(k,1)}function R(A,P){return u(A).includes(P)}return{update:E,resume:w,pause:S,destroy:v,addEventListener:O,removeEventListener:T,hasEventListener:R}}var Xt=require("@layoutit/polycss-core");function Re(e,n={}){let t=fe(_e,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,a=!1,d={x:0,y:0},m=we(),f=Oe(e),{changeListeners:h,startListeners:u,endListeners:p,listenerArray:b,emitChange:x,emitInteraction:C}=m,M=He(r,e,()=>t,()=>l,()=>c,f,x),H=L=>{if(!(!t.drag||l)&&s===null&&L.isPrimary!==!1){L.preventDefault(),s=L.pointerId,i={x:L.clientX,y:L.clientY},o.style.cursor="grabbing";try{L.target.setPointerCapture(L.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),C("start",f)}},y=L=>{if(s===null||L.pointerId!==s||!t.drag||l)return;L.preventDefault();let I=L.clientX-i.x,V=L.clientY-i.y;i={x:L.clientX,y:L.clientY};let X=e.getOptions();if(L.shiftKey){let W=ve(t.invert),Z=I/4*W,G=V/4*W,Y=Math.max(0,Math.min(100,(X.rotX??65)-G)),z=(((X.rotY??45)-Z)%360+360)%360;e.setOptions({rotX:Y,rotY:z})}else{let W=X.rotX??65,Z=X.rotY??45,G=Math.max(.01,X.zoom??1),Y=Math.cos(W*Math.PI/180),z=Y>=0?Math.max(.1,Y):Math.min(-.1,Y),ne=Math.cos(Z*Math.PI/180),ce=Math.sin(Z*Math.PI/180),oe=G*Xt.BASE_TILE,qe=(I*ce-V*ne/z)/oe,Q=-(I*ne+V*ce/z)/oe,J=X.target??[0,0,0];e.setOptions({target:[J[0]+qe,J[1]+Q,J[2]]})}x(f)},g=L=>{if(s===L.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{L.target.releasePointerCapture(L.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),C("end",f)}},_=L=>{L.preventDefault()},E=L=>{L.button===2&&(a=!0,d={x:L.clientX,y:L.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),C("start",f))},w=L=>{if(!a||!t.drag)return;let I=L.clientX-d.x,V=L.clientY-d.y;d={x:L.clientX,y:L.clientY};let X=ve(t.invert),W=I/4*X,Z=V/4*X,G=e.getOptions(),Y=Math.max(0,Math.min(100,(G.rotX??65)-Z)),z=(((G.rotY??45)-W)%360+360)%360;e.setOptions({rotX:Y,rotY:z}),x(f)},S=L=>{L.button===2&&a&&(a=!1,C("end",f))},v=ke(e,()=>t,()=>l,f,x,C);function O(){o.addEventListener("pointerdown",H),o.addEventListener("pointermove",y),o.addEventListener("pointerup",g),o.addEventListener("pointercancel",g),o.addEventListener("wheel",v.onWheel,{passive:!1}),o.addEventListener("contextmenu",_),o.addEventListener("mousedown",E),o.addEventListener("mousemove",w),o.addEventListener("mouseup",S),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function T(){o.removeEventListener("pointerdown",H),o.removeEventListener("pointermove",y),o.removeEventListener("pointerup",g),o.removeEventListener("pointercancel",g),o.removeEventListener("wheel",v.onWheel),o.removeEventListener("contextmenu",_),o.removeEventListener("mousedown",E),o.removeEventListener("mousemove",w),o.removeEventListener("mouseup",S),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",v.teardown()}O(),M.start();function R(L){let I=!!t.animate;t=fe(t,L),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let V=!!t.animate;I&&!V?M.stop():!I&&V&&M.start()}function A(){l&&(l=!1,O(),M.start())}function P(){l||(l=!0,T(),M.stop(),s=null,c=!1,a=!1,v.teardown())}function D(){P(),h.length=0,u.length=0,p.length=0}function k(L,I){let V=b(L);V.includes(I)||V.push(I)}function F(L,I){let V=b(L),X=V.indexOf(I);X>=0&&V.splice(X,1)}function j(L,I){return b(L).includes(I)}return{update:R,resume:A,pause:P,destroy:D,addEventListener:k,removeEventListener:F,hasEventListener:j}}function yo(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function Ie(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let p of o)try{p(t)}catch(b){console.error("[polycss/createSelect] onChange threw:",b)}}function s(u){t=u,r()}function i(u){n.multiple?t.includes(u)||(t=[...t,u]):t=[u],r()}function c(u){t.includes(u)&&(t=t.filter(p=>p!==u),r())}function l(u){t.includes(u)?t=t.filter(p=>p!==u):n.multiple?t=[...t,u]:t=[u],r()}function a(){t.length!==0&&(t=[],r())}function d(u){return t.includes(u)}function m(u,p){for(let b of e.meshes())if(!b.element.classList.contains("polycss-transform-gizmo")&&yo(b.element,u,p))return b;return null}let f=u=>{let p=u.target;if(p?.closest(".polycss-transform-gizmo"))return;let b=e.findMeshByElement(p)??m(u.clientX,u.clientY);if(!b){n.onPointerMissed&&n.onPointerMissed(u),n.clearOnMiss!==!1&&a();return}n.multiple&&(u.shiftKey||u.metaKey||u.ctrlKey)?l(b):t.length===1&&t[0]===b?a():s([b])};e.host.addEventListener("click",f);function h(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:s,add:i,remove:c,toggle:l,clear:a,has:d,destroy:h}}var Ve=require("@layoutit/polycss-core"),ut="#ff3653",dt="#8adb00",pt="#2c8fff",he=50,Yt=60,go=.6,bo=.0125,vo=.15,xo=.04,Po=1,Ao=.012,Eo=64,Co=1e-4,Mo=.6,To=.8,Lo=1,$t={0:1,1:0,2:2},Ut=[{cssAxis:0,sign:1,key:"x",color:ut},{cssAxis:0,sign:-1,key:"-x",color:ut},{cssAxis:1,sign:1,key:"y",color:dt},{cssAxis:1,sign:-1,key:"-y",color:dt},{cssAxis:2,sign:1,key:"z",color:pt},{cssAxis:2,sign:-1,key:"-z",color:pt}],Wt=[{cssAxis:0,key:"x",color:ut},{cssAxis:1,key:"y",color:dt},{cssAxis:2,key:"z",color:pt}];function So(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),s=parseInt(t[3],16);return`rgba(${o}, ${r}, ${s}, ${n})`}function Gt(e,n){return!n||n<=0?e:Math.round(e/n)*n}function _o(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let l of c.vertices)l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>s&&(s=l[1]),l[2]<o&&(o=l[2]),l[2]>i&&(i=l[2]);return Number.isFinite(n)?[(t+s)/2*he,(n+r)/2*he,(o+i)/2*he]:[0,0,0]}function Zt(e){if(e.length===0)return Yt;let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let a of l.vertices)a[0]<n&&(n=a[0]),a[0]>r&&(r=a[0]),a[1]<t&&(t=a[1]),a[1]>s&&(s=a[1]),a[2]<o&&(o=a[2]),a[2]>i&&(i=a[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*he*go:Yt}function ct(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function wo(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:c,translationSnap:l,onAxisDelta:a,onMouseDown:d,onMouseUp:m,onDraggingChanged:f}=e,h=o,u=[0,0,0];u[n]=t;let p=r.ownerDocument.createElement("div");p.style.position="absolute",p.style.left="0",p.style.top="0",p.style.width="0",p.style.height="0",p.style.transform=`translate3d(${u[0]*h}px, ${u[1]*h}px, ${u[2]*h}px)`,r.appendChild(p);let b=r.getBoundingClientRect(),x=p.getBoundingClientRect();r.removeChild(p);let C=(x.left-b.left)/h,M=(x.top-b.top)/h,H=C*C+M*M;if(H<Co)return;d?.(),f?.(!0);let y=_=>{let E=_.clientX-i,w=_.clientY-c,S=(E*C+w*M)/H;S=Gt(S,l),a(S,u)},g=()=>{window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g);let _=E=>{E.stopPropagation(),E.stopImmediatePropagation()};window.addEventListener("click",_,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",_,!0),0),m?.(),f?.(!1)};window.addEventListener("pointermove",y),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g)}function Oo(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:c,onMouseDown:l,onMouseUp:a,onDraggingChanged:d}=e,m=t.getBoundingClientRect(),f=m.left,h=m.top,u=Math.atan2(s-h,r-f),p=0;l?.(),d?.(!0);let b=C=>{let M=Math.atan2(C.clientY-h,C.clientX-f),H=M-u;H>Math.PI?H-=2*Math.PI:H<-Math.PI&&(H+=2*Math.PI),p+=H,u=M;let y=p*180/Math.PI;y=Gt(y,i),c(y)},x=()=>{window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x);let C=M=>{M.stopPropagation(),M.stopImmediatePropagation()};window.addEventListener("click",C,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",C,!0),0),a?.(),d?.(!1)};window.addEventListener("pointermove",b),window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x)}function ze(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,c=null,l=null,a=[0,0,0];function d(){if(!t)return[0,0,0];let v=t.transform.position??[0,0,0];return[v[0]+a[0],v[1]+a[1],v[2]+a[2]]}function m(v){return l===v?Lo:c===v?To:Mo}function f(){for(let[v,O]of i){let T=h(O.spec,m(v));O.handle.setPolygons(T,{recomputeAutoCenter:!1})}}function h(v,O){let R=Zt(t?.polygons??[])*r,A=R/he,P=So(v.color,O);if(o==="translate")return(0,Ve.arrowPolygons)({axis:$t[v.cssAxis],sign:v.sign??1,shaftLength:A,shaftHalfThickness:A*bo,headLength:A*vo,headHalfThickness:A*xo,color:P});let D=R*Po/he;return(0,Ve.ringPolygons)({axis:$t[v.cssAxis],radius:D,halfThickness:D*Ao,segments:Eo,color:P})}function u(){if(p(),!t)return;let v={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1},O=o==="translate"?Ut:o==="rotate"?Wt:[],T=o==="translate"?"polycss-transform-arrow":"polycss-transform-ring",R=d();for(let A of O){let P=A.key.replace("-","")[0];if(!v[P])continue;let D=h(A,m(A.key)),k=e.add({polygons:D,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${A.key}`,position:R});k.element.classList.add("polycss-transform-gizmo",T,`${T}--${A.key}`),i.set(A.key,{handle:k,spec:A})}}function p(){for(let{handle:v}of i.values())v.remove();i.clear(),c=null,l=null}function b(){if(!t)return;let v=d();for(let{handle:O}of i.values())O.setTransform({position:v})}function x(){t&&(i.size===0?u():b())}function C(v){if(t=v,!v){a=[0,0,0],p();return}a=_o(v.polygons),p(),u()}function M(){C(null)}function H(v){v!==o&&(o=v,t&&(p(),u()))}function y(v,O,T){if(!t||!g)return;let R=[g[0]+O*T[0],g[1]+O*T[1],g[2]+O*T[2]];t.setTransform({position:R}),b(),s.onObjectChange?.({object:t,position:R}),s.onChange?.()}let g=null,_=null,E=v=>{if(!t||s.enabled===!1)return;let O={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate")for(let T of Ut){let R=T.key.replace("-","")[0];if(!O[R])continue;let A=i.get(T.key);if(A&&ct(A.handle.element,v.clientX,v.clientY)){v.preventDefault(),v.stopPropagation(),l=T.key,f(),g=(t.transform.position??[0,0,0]).slice(),wo({cssAxis:T.cssAxis,sign:T.sign,shaftLengthCss:Zt(t.polygons)*r,wrapper:A.handle.element,target:t,startClientX:v.clientX,startClientY:v.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(P,D)=>y(T,P,D),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:P=>{P||(l=null,g=null,f()),s.onDraggingChanged?.(P)}});return}}else if(o==="rotate")for(let T of Wt){if(!O[T.key])continue;let R=i.get(T.key);if(R&&ct(R.handle.element,v.clientX,v.clientY)){v.preventDefault(),v.stopPropagation(),l=T.key,f(),_=(t.transform.rotation??[0,0,0]).slice(),Oo({cssAxis:T.cssAxis,wrapper:R.handle.element,target:t,startClientX:v.clientX,startClientY:v.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:A=>{if(!t||!_)return;let P=[_[0],_[1],_[2]],D=T.cssAxis===0?-1:1;P[T.cssAxis]=_[T.cssAxis]+A*D,t.setTransform({rotation:P}),s.onObjectChange?.({object:t,rotation:P}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:A=>{A||(l=null,_=null,f(),t?.rebakeAtlas()),s.onDraggingChanged?.(A)}});return}}};e.host.addEventListener("pointerdown",E,{capture:!0});let w=v=>{if(!t||l||s.enabled===!1)return;let O=null;for(let[T,R]of i)if(ct(R.handle.element,v.clientX,v.clientY)){O=T;break}O!==c&&(c=O,f())};e.host.addEventListener("pointermove",w);function S(){e.host.removeEventListener("pointerdown",E,{capture:!0}),e.host.removeEventListener("pointermove",w),p()}return{attach:C,detach:M,setMode:H,update:x,destroy:S}}var ko=typeof HTMLElement<"u"?HTMLElement:class{},Ho=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","atlas-scale","auto-center"];function le(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Do(e){return e==="false"?!1:le(e)}function Ro(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Io(e){if(e==="baked"||e==="dynamic")return e}function Vo(e){return e==="auto"?"auto":le(e)}var K=class extends ko{constructor(){super(...arguments);this._scene=null}static get observedAttributes(){return[...Ho]}getScene(){return this._scene}_readOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={},s=Do(this.getAttribute("perspective"));s!==void 0&&(r.perspective=s);let i=le(this.getAttribute("rot-x"));i!==void 0&&(r.rotX=i);let c=le(this.getAttribute("rot-y"));c!==void 0&&(r.rotY=c);let l=le(this.getAttribute("zoom"));l!==void 0&&(r.zoom=l),r.textureLighting=Io(this.getAttribute("texture-lighting"))??"baked";let a=Vo(this.getAttribute("atlas-scale"));return a!==void 0&&(r.atlasScale=a),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=Ro(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=le(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let s={direction:t??[.4,-.7,.59]};return o&&(s.color=o),r!==void 0&&(s.intensity=r),s}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=le(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){this._scene||(this._scene=Le(this,this._readOptions()),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1})))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null)}attributeChangedCallback(t,o,r){o!==r&&this._scene&&this._scene.setOptions(this._readOptions())}};var Be=require("@layoutit/polycss-core"),zo=typeof HTMLElement<"u"?HTMLElement:class{},Bo=["src","mtl","position","scale","rotation","auto-center"];function xe(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function jt(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return xe(e)}}function Fo(e){return e.closest("poly-scene")??null}function No(e){if(e.length===0)return e;let n=(0,Be.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s),...i.textureTriangles?.length?{textureTriangles:i.textureTriangles.map(c=>({...c,vertices:c.vertices.map(s)}))}:null}))}var ye=class extends zo{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Bo]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:xe(this.getAttribute("position")),scale:jt(this.getAttribute("scale")),rotation:xe(this.getAttribute("rotation"))})}}_tearDown(){if(this._loadToken+=1,this._handle){try{this._handle.dispose()}catch{}this._handle=null}this._parseResult=null}async _maybeLoad(){let t=this.getAttribute("src");if(!t)return;let o=Fo(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,i;try{i=await(0,Be.loadMesh)(t,s?{mtlUrl:s}:void 0)}catch(a){this.dispatchEvent(new CustomEvent("polycss:error",{detail:a,bubbles:!0}));return}if(r!==this._loadToken){try{i.dispose()}catch{}return}let c=o.getScene();if(!c){try{i.dispose()}catch{}return}this.hasAttribute("auto-center")&&(i={...i,polygons:No(i.polygons)}),this._parseResult=i,this._handle=c.add(i,{position:xe(this.getAttribute("position")),scale:jt(this.getAttribute("scale")),rotation:xe(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var Xo=typeof HTMLElement<"u"?HTMLElement:class{},Yo=["vertices","color","texture","uvs","position","scale","rotation"];function qt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function mt(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function $o(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return mt(e)}}function Uo(e){return e.closest("poly-scene")??null}var Fe=class extends Xo{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Yo]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=Uo(this);if(!t)return;let o=t.getScene();if(!o)return;let r=qt(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let s=this.getAttribute("color")||void 0,i=this.getAttribute("texture")||void 0,c=qt(this.getAttribute("uvs"))??void 0,l={};for(let m of Array.from(this.attributes))m.name.startsWith("data-")&&(l[m.name.slice(5)]=m.value);let d={polygons:[{vertices:r,...s!==void 0?{color:s}:{},...i!==void 0?{texture:i}:{},...c!==void 0?{uvs:c}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(d,{position:mt(this.getAttribute("position")),scale:$o(this.getAttribute("scale")),rotation:mt(this.getAttribute("rotation"))})}};function N(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Ne(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function se(e){if(e!==null)return!(e==="false"||e==="0")}function Xe(e){if(e===null)return;if(e==="true")return!0;if(e==="false")return!1;let n=parseFloat(e);return Number.isFinite(n)?n:!0}function Ye(e){if(e==="x"||e==="y")return e}var Wo=typeof HTMLElement<"u"?HTMLElement:class{},Zo=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],$e=class extends Wo{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Zo]}_readAnimate(){let t=N(this.getAttribute("animate-speed")),o=Ye(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:se(r)}:{}}}_readOptions(){let t={},o=se(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=se(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=N(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=N(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=Xe(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=N(this.getAttribute("zoom-min")),a=N(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),a!==void 0&&(t.maxZoom=a),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof K)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=De(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Go=typeof HTMLElement<"u"?HTMLElement:class{},jo=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Ue=class extends Go{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...jo]}_readAnimate(){let t=N(this.getAttribute("animate-speed")),o=Ye(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:se(r)}:{}}}_readOptions(){let t={},o=se(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=se(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=N(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=N(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=Xe(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=N(this.getAttribute("zoom-min")),a=N(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),a!==void 0&&(t.maxZoom=a),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof K)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=Re(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var qo=typeof HTMLElement<"u"?HTMLElement:class{},Ko=["perspective","zoom","rot-x","rot-y","target","distance"],We=class extends qo{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Ko]}getCamera(){return this._camera}_readOptions(){return{perspective:N(this.getAttribute("perspective")),zoom:N(this.getAttribute("zoom")),rotX:N(this.getAttribute("rot-x")),rotY:N(this.getAttribute("rot-y")),target:Ne(this.getAttribute("target")),distance:N(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=be(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let s=this._readOptions();this._camera=be(s),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var Jo=typeof HTMLElement<"u"?HTMLElement:class{},Qo=["zoom","rot-x","rot-y","target","distance"],Ze=class extends Jo{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Qo]}getCamera(){return this._camera}_readOptions(){return{zoom:N(this.getAttribute("zoom")),rotX:N(this.getAttribute("rot-x")),rotY:N(this.getAttribute("rot-y")),target:Ne(this.getAttribute("target")),distance:N(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Se(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let s=this._readOptions();s.zoom!==void 0&&this._camera.update({zoom:s.zoom}),s.rotX!==void 0&&this._camera.update({rotX:s.rotX}),s.rotY!==void 0&&this._camera.update({rotY:s.rotY}),s.target!==void 0&&this._camera.update({target:s.target}),s.distance!==void 0&&this._camera.update({distance:s.distance})}};var er=typeof HTMLElement<"u"?HTMLElement:class{},tr=["mode","target","size","enabled"];function Kt(e){if(e==="translate"||e==="rotate")return e}var Ge=class extends er{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...tr]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof K)return t;t=t.parentNode}return null}_findTargetMesh(){let t=this.getAttribute("target");if(!t)return null;let o=this._findScene();if(!o)return null;let r=null;try{r=o.querySelector(`#${t}`)??o.querySelector(t)}catch{r=o.querySelector(`[id="${t}"]`)}return r instanceof ye?r:null}_readOptions(){let t={},o=Kt(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=N(this.getAttribute("size"));r!==void 0&&(t.size=r);let s=this.getAttribute("enabled");return s!==null&&(t.enabled=s!=="false"&&s!=="0"),t.onObjectChange=i=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:i.position,rotation:i.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let s=()=>{t.removeEventListener("polycss:scene-ready",s),this._attach()};t.addEventListener("polycss:scene-ready",s)}return}this._tc=ze(o,this._readOptions());let r=this._findTargetMesh();if(r){let s=r.getMeshHandle();s&&this._tc.attach(s)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,r){if(o!==r&&this._tc){if(t==="mode"){let s=Kt(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};var nr=typeof HTMLElement<"u"?HTMLElement:class{},or=["multiple","clear-on-miss"],je=class extends nr{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...or]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof K)return t;t=t.parentNode}return null}_readOptions(){return{multiple:this.hasAttribute("multiple"),clearOnMiss:!this.hasAttribute("clear-on-miss")||this.getAttribute("clear-on-miss")!=="false",onChange:t=>{this.dispatchEvent(new CustomEvent("polycss:select",{bubbles:!0,detail:{selected:t}}))}}}_attach(){if(this._selection)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._selection=Ie(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};U($,require("@layoutit/polycss-core"),module.exports);0&&(module.exports={PolyMapControlsElement,PolyMeshElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPolygonElement,PolySceneElement,PolySelectElement,PolyTransformControlsElement,createPolyMapControls,createPolyOrbitControls,createPolyOrthographicCamera,createPolyPerspectiveCamera,createPolyScene,createSelect,createTransformControls,injectPolyBaseStyles,...require("@layoutit/polycss-core")});
|
|
328
|
+
|
|
329
|
+
/* \u2500\u2500 Cast shadows (dynamic mode only) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
330
|
+
|
|
331
|
+
/*
|
|
332
|
+
* Shadow projection matrix. Projects any 3D point P onto the horizontal
|
|
333
|
+
* ground plane (cssZ \u2248 G) along the CSS-space light direction (--clx/y/z).
|
|
334
|
+
*
|
|
335
|
+
* In polycss's world convention world Z is up (red-green plane is the
|
|
336
|
+
* floor in the axes helper). After the world\u2192CSS swap (Y\u2194X), world Z stays
|
|
337
|
+
* as CSS Z, so the ground plane normal in CSS space is +cssZ.
|
|
338
|
+
*
|
|
339
|
+
* The strict projection formula would set m22=0 (output.z is a constant G,
|
|
340
|
+
* the polygon is exactly flat). But Chromium SKIPS rendering elements
|
|
341
|
+
* whose composed transform matrix is non-invertible (singular). m22=0
|
|
342
|
+
* makes the matrix singular, so the shadow paints nothing even though it
|
|
343
|
+
* has a valid layout box. The fix: collapse along z by a near-zero
|
|
344
|
+
* scale (Z_SQUASH = 0.01) instead of exactly zero \u2014 output.z is then
|
|
345
|
+
* approximately G with ~1% drift from the input, full-rank and renderable.
|
|
346
|
+
* The shadow still looks flat to the eye (the drift is sub-pixel for
|
|
347
|
+
* any realistic scene size).
|
|
348
|
+
*
|
|
349
|
+
* out.cssX = P.cssX - (--clx/--clz) * (P.cssZ - G)
|
|
350
|
+
* out.cssY = P.cssY - (--cly/--clz) * (P.cssZ - G)
|
|
351
|
+
* out.cssZ = Z_SQUASH * P.cssZ + (1 - Z_SQUASH) * G
|
|
352
|
+
*
|
|
353
|
+
* As column-major 4\xD74 (CSS matrix3d order):
|
|
354
|
+
* col1: [1, 0, 0, 0]
|
|
355
|
+
* col2: [0, 1, 0, 0]
|
|
356
|
+
* col3: [-(--clx/--clz), -(--cly/--clz), Z_SQUASH, 0]
|
|
357
|
+
* col4: [G*(--clx/--clz), G*(--cly/--clz), G*(1-Z_SQUASH), 1]
|
|
358
|
+
*/
|
|
359
|
+
.polycss-scene[data-polycss-lighting="dynamic"] {
|
|
360
|
+
--shadow-proj: matrix3d(
|
|
361
|
+
1, 0, 0, 0,
|
|
362
|
+
0, 1, 0, 0,
|
|
363
|
+
calc(-1 * var(--clx) / var(--clz)),
|
|
364
|
+
calc(-1 * var(--cly) / var(--clz)),
|
|
365
|
+
0.01,
|
|
366
|
+
0,
|
|
367
|
+
calc(var(--shadow-ground-cssz) * var(--clx) / var(--clz)),
|
|
368
|
+
calc(var(--shadow-ground-cssz) * var(--cly) / var(--clz)),
|
|
369
|
+
calc(var(--shadow-ground-cssz) * 0.99),
|
|
370
|
+
1
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/* <q> shadow leaf \u2014 Lambert-gated opacity. Polygons facing the light cast
|
|
375
|
+
full shadow; polygons facing away cast zero shadow (their projection
|
|
376
|
+
would stack inside the silhouette and produce ugly overdraw). The
|
|
377
|
+
* 10 multiplier sharpens the cutoff so small positive Lambert values
|
|
378
|
+
jump quickly to 1, giving a near-binary visibility decision with a
|
|
379
|
+
smooth edge transition. Pure CSS calc \u2014 no JS at light-change time.
|
|
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 {
|
|
386
|
+
opacity: clamp(0, calc((var(--pnx) * var(--clx) + var(--pny) * var(--cly) + var(--pnz) * var(--clz)) * 10), 1);
|
|
387
|
+
}
|
|
388
|
+
`;var As=750,Ms=8e3;var ft=65,ht=45,Ss=1,De=te.BASE_TILE;function Ls(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let r of t)if(!o.includes(r))return!1;return!0}function go(e){let n=[];return e.position&&n.push(`translate3d(${e.position[0]}px, ${e.position[1]}px, ${e.position[2]}px)`),e.scale!==void 0&&(typeof e.scale=="number"?e.scale!==1&&n.push(`scale3d(${e.scale}, ${e.scale}, ${e.scale})`):n.push(`scale3d(${e.scale[0]}, ${e.scale[1]}, ${e.scale[2]})`)),e.rotation&&(e.rotation[0]&&n.push(`rotateX(${e.rotation[0]}deg)`),e.rotation[1]&&n.push(`rotateY(${e.rotation[1]}deg)`),e.rotation[2]&&n.push(`rotateZ(${e.rotation[2]}deg)`)),n.length>0?n.join(" "):void 0}function ws(e,n=[0,0,0],t=1){let o=e.rotX??ft,r=e.rotY??ht,s=(e.zoom??Ss)*t,i=(e.distance??0)*t,a=e.target??[0,0,0],l=a[0]+n[0],u=a[1]+n[1],p=a[2]+n[2],d=u*De,f=l*De,g=p*De;return`${i!==0?`translateZ(${-i}px) `:""}scale(${s}) rotateX(${o}deg) rotate(${r}deg) translate3d(${-d}px, ${-f}px, ${-g}px)`}function Ts(e){let n=e.trim();if(!n||n==="normal")return 1;let t=n.endsWith("%")?Number(n.slice(0,-1))/100:Number(n);return Number.isFinite(t)&&t>0?t:1}function _s(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=Ts(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function gn(e,n){return n===1?e:e*n}function ks(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}var Rs=.1;function Os(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let d=1;d+1<e.vertices.length;d++){let f=e.vertices[d],g=e.vertices[d+1],m=f[1]-n[1],h=f[0]-n[0],y=f[2]-n[2],v=g[1]-n[1],E=g[0]-n[0],A=g[2]-n[2];t-=h*A-y*E,o-=y*v-m*A,r-=m*E-h*v}let s=Math.hypot(t,o,r);if(s<1e-9)return null;t/=s,o/=s,r/=s;let i=1/Rs,a=Math.round(t*i)/i,l=Math.round(o*i)/i,u=Math.round(r*i)/i,p=Math.hypot(a,l,u);return p<1e-9?null:{key:a+","+l+","+u,vec:[a/p,l/p,u/p]}}function gt(e,n={}){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");e.ownerDocument&&pt(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let t={...n},o=_s(e),r=[0,0,0],s=e.ownerDocument??document,i=s.createElement("div");i.className="polycss-scene",i.setAttribute("aria-hidden","true"),l(i,t),e.appendChild(i);let a=new Set;function l(c,b){ks(c,o),c.style.transform=ws(b,r,o),typeof b.perspective=="number"?c.style.perspective=`${gn(b.perspective,o)}px`:b.perspective===!1?c.style.perspective=`${gn(1e6,o)}px`:Math.abs(o-1)<1e-6?c.style.removeProperty("perspective"):c.style.perspective=`${gn(Ms,o)}px`,u(c,b)}function u(c,b){let R=b.textureLighting==="dynamic";c.dataset.polycssLighting=b.textureLighting??"baked";let _=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"];if(!R){for(let re of _)c.style.removeProperty(re);return}let V=b.directionalLight?.direction??[.4,-.7,.59],D=Math.hypot(V[0],V[1],V[2])||1,Y=V[0]/D,L=V[1]/D,N=V[2]/D,z=(0,te.parseHexColor)(b.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],G=(0,te.parseHexColor)(b.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],K=b.directionalLight?.intensity??1,T=b.ambientLight?.intensity??.4,Q=re=>(re/255).toFixed(4);c.style.setProperty("--plx",Y.toFixed(4)),c.style.setProperty("--ply",L.toFixed(4)),c.style.setProperty("--plz",N.toFixed(4)),c.style.setProperty("--plr",Q(z[0])),c.style.setProperty("--plg",Q(z[1])),c.style.setProperty("--plb",Q(z[2])),c.style.setProperty("--pli",K.toFixed(4)),c.style.setProperty("--par",Q(G[0])),c.style.setProperty("--pag",Q(G[1])),c.style.setProperty("--pab",Q(G[2])),c.style.setProperty("--pai",T.toFixed(4));let H=N,q=Math.sign(H||1)*Math.max(Math.abs(H),.01);c.style.setProperty("--clx",Y.toFixed(4)),c.style.setProperty("--cly",L.toFixed(4)),c.style.setProperty("--clz",q.toFixed(4))}function p(c){c.voxelRenderer?.dispose(),c.voxelRenderer=void 0,h(c.rendered,c.disposeAtlas),c.disposeAtlas=void 0,c.rendered.length=0,c.cameraCullGroups.length=0,c.cameraCullSignature="",m(c);for(let b of Array.from(c.wrapper.children))b instanceof HTMLElement&&b.classList.contains("polycss-bucket")&&b.remove()}function d(c){for(let b of Array.from(c.wrapper.childNodes)){if(!(b instanceof HTMLElement))return b;if(b.classList.contains("polycss-bucket")||b.classList.contains("polycss-shadow"))continue;let R=b.tagName.toLowerCase();if(!(R==="b"||R==="i"||R==="s"||R==="u"||R==="q"))return b}return null}function f(c,b,R){R?.parentNode===c.wrapper?c.wrapper.insertBefore(b,R):c.wrapper.appendChild(b)}function g(c){return Array.from(c.children).some(b=>b instanceof HTMLElement&&b.classList.contains("polycss-bucket"))}function m(c){for(let b of c.shadowRendered)b.parentNode&&b.parentNode.removeChild(b);c.shadowRendered.length=0}function h(c,b){b?.();for(let R of c){try{R.dispose()}catch{}R.element.parentNode&&R.element.parentNode.removeChild(R.element)}}function y(c){for(let b of Array.from(c.wrapper.children))b instanceof HTMLElement&&b.classList.contains("polycss-bucket")&&b.remove();for(let b of c.rendered)b.element.parentNode&&b.element.parentNode.removeChild(b.element)}function v(c,b){let R=c.polygons[b.polygonIndex];return c.stableDom&&R?(0,te.polygonCssSurfaceNormal)(R):b.plan?.normal??(R?(0,te.polygonCssSurfaceNormal)(R):null)}function E(c){if(!M(c))return c.rendered;let b=A(c);return c.rendered.filter(R=>x(c,R,te.CAMERA_BACKFACE_CULL_EPS,b))}function A(c){return{rotX:t.rotX??ft,rotY:t.rotY??ht,meshRotation:c.handle.transform.rotation}}function x(c,b,R=te.CAMERA_BACKFACE_CULL_EPS,_=A(c)){let V=v(c,b);return V===null||(0,te.normalFacesCamera)(V,_,R)}function C(c){c.cameraCullGroups=(0,te.cameraCullNormalGroups)(c.rendered.map(b=>v(c,b)))}function O(c){return M(c)?(0,te.cameraCullVisibleSignature)(c.cameraCullGroups,A(c)):"all"}function M(c){return!c.excludeFromAutoCenter&&(0,te.isVoxelCameraCullableNormalGroups)(c.cameraCullGroups)}function P(c){c.cameraCullSignature=M(c)?O(c):"all"}function X(c,b){let R=new Array(c.rendered.length),_=!1,V=A(c);for(let K=0;K<c.rendered.length;K+=1){let T=c.rendered[K],Q=x(c,T,b,V);R[K]=Q}let D=null,Y=null,L=()=>{if(!(!D||!Y)){if(D===Y)D.remove();else{let K=s.createRange();K.setStartBefore(D),K.setEndAfter(Y),K.deleteContents(),K.detach()}D=null,Y=null,_=!0}};for(let K=0;K<c.rendered.length;K+=1){let T=c.rendered[K];!R[K]&&T.element.parentNode===c.wrapper?(Y&&Y.nextSibling===T.element||(L(),D=T.element),Y=T.element):L()}L();let N=K=>{for(let T=K;T<c.rendered.length;T+=1){let Q=c.rendered[T].element;if(Q.parentNode===c.wrapper)return Q}return d(c)},z=-1,G=K=>{if(z<0)return;let T=s.createDocumentFragment();for(let Q=z;Q<K;Q+=1){let H=c.rendered[Q];S(c,H),T.appendChild(H.element)}f(c,T,N(K)),z=-1,_=!0};for(let K=0;K<c.rendered.length;K+=1){let T=c.rendered[K];R[K]&&T.element.parentNode!==c.wrapper?z<0&&(z=K):G(K)}return G(c.rendered.length),_}function $(c,b=!1){if(c.voxelRenderer){c.voxelRenderer.syncCamera(A(c)),c.cameraCullSignature="voxel-direct";return}if(!M(c)){let V=c.cameraCullSignature!=="all";c.cameraCullSignature="all",V&&le(c);return}if(g(c.wrapper)){W(c,b);return}let R=O(c);if(!b&&R===c.cameraCullSignature)return;let _=X(c,te.CAMERA_BACKFACE_CULL_EPS);c.cameraCullSignature=R,_&&J(c)}function W(c,b=!1){let R=M(c)?O(c):"all";!b&&R===c.cameraCullSignature||le(c)}function ne(c,b){return v(c,b)}function S(c,b){if(t.textureLighting!=="dynamic")return;let R=ne(c,b);R&&(b.element.style.setProperty("--pnx",R[0].toFixed(4)),b.element.style.setProperty("--pny",R[1].toFixed(4)),b.element.style.setProperty("--pnz",R[2].toFixed(4)))}function U(c){y(c);let b=s.createDocumentFragment(),R=t.textureLighting==="dynamic"&&!c.stableDom,_=new Map,V=[];for(let D of E(c)){let Y=c.polygons[D.polygonIndex],L=R&&Y?Os(Y):null;if(!L){V.push(D);continue}let N=L.key+"|"+(Y.color??""),z=_.get(N);z||(z={vec:L.vec,items:[]},_.set(N,z)),z.items.push(D)}for(let D of V)S(c,D),b.appendChild(D.element);for(let D of _.values()){if(D.items.length<2){for(let L of D.items)S(c,L),b.appendChild(L.element);continue}let Y=s.createElement("div");Y.className="polycss-bucket",Y.style.setProperty("--pnx",String(D.vec[0])),Y.style.setProperty("--pny",String(D.vec[1])),Y.style.setProperty("--pnz",String(D.vec[2]));for(let L of D.items)Y.appendChild(L.element),L.element.style.removeProperty("--pnx"),L.element.style.removeProperty("--pny"),L.element.style.removeProperty("--pnz");b.appendChild(Y)}f(c,b,d(c)),P(c)}function w(){return new Promise(c=>setTimeout(c,0))}async function I(c,b){if(t.textureLighting==="dynamic"&&!c.stableDom)return U(c),!b();y(c);let _=s.createDocumentFragment(),V=d(c),D=0;for(let Y of E(c)){if(b())return!1;S(c,Y),_.appendChild(Y.element),D++,D%As===0&&(f(c,_,V),_=s.createDocumentFragment(),await w())}return _.childNodes.length>0&&f(c,_,V),P(c),!b()}function F(c,b){let R=t.textureLighting==="dynamic",_=t.directionalLight?.direction,V=b&&(b[0]!==0||b[1]!==0||b[2]!==0);if(!R||!V||!_){if(c.lightOverrideSignature==="clear")return;c.wrapper.style.removeProperty("--plx"),c.wrapper.style.removeProperty("--ply"),c.wrapper.style.removeProperty("--plz"),c.lightOverrideSignature="clear";return}let D=(0,te.inverseRotateVec3)(_,b),Y=Math.hypot(D[0],D[1],D[2])||1,L=(D[0]/Y).toFixed(4),N=(D[1]/Y).toFixed(4),z=(D[2]/Y).toFixed(4),G=`${L}|${N}|${z}`;c.lightOverrideSignature!==G&&(c.wrapper.style.setProperty("--plx",L),c.wrapper.style.setProperty("--ply",N),c.wrapper.style.setProperty("--plz",z),c.lightOverrideSignature=G)}function B(c,b){b.paintColor?c.style.setProperty("--polycss-paint",b.paintColor):c.style.removeProperty("--polycss-paint"),b.dynamicColor?(c.style.setProperty("--psr",(b.dynamicColor.r/255).toFixed(4)),c.style.setProperty("--psg",(b.dynamicColor.g/255).toFixed(4)),c.style.setProperty("--psb",(b.dynamicColor.b/255).toFixed(4))):(c.style.removeProperty("--psr"),c.style.removeProperty("--psg"),c.style.removeProperty("--psb"))}function J(c){if(m(c),!c.castShadow||t.textureLighting!=="dynamic")return;let b=t.shadow?.color??"#000000",R=t.shadow?.opacity??.25,_=(0,te.parseHexColor)(b)?.rgb??[0,0,0],V=_[0],D=_[1],Y=_[2],L=`rgba(${V},${D},${Y},${R})`,N=(0,te.findOverlappingPolygonDuplicates)(c.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.4}),z=s.createDocumentFragment();for(let K of E(c)){if(N.has(K.polygonIndex))continue;let T=K.plan;if(!T)continue;let Q=`matrix3d(${T.matrix})`,H=s.createElement("q");H.className="polycss-shadow",H.style.transform=`var(--shadow-proj) ${Q}`,H.style.color=L,H.style.width=`${T.canvasW}px`,H.style.height=`${T.canvasH}px`,H.style.setProperty("border-shape",no(T)),H.style.setProperty("--pnx",T.normal[0].toFixed(4)),H.style.setProperty("--pny",T.normal[1].toFixed(4)),H.style.setProperty("--pnz",T.normal[2].toFixed(4)),z.appendChild(H),c.shadowRendered.push(H)}let G=c.wrapper.firstChild;G?c.wrapper.insertBefore(z,G):c.wrapper.appendChild(z)}function le(c){if(c.voxelRenderer){c.voxelRenderer.render(A(c)),c.cameraCullSignature="voxel-direct";return}m(c),U(c),J(c)}function k(c){return!!c.voxelSource&&t.textureLighting!=="dynamic"&&!c.stableDom&&!c.castShadow}function j(c,b){p(c);let R=t.directionalLight,_=b?{...R,direction:b}:R;if(k(c)){let N=fo({doc:s,wrapper:c.wrapper,polygons:c.parseResult.polygons,directionalLight:_,ambientLight:t.ambientLight});if(N){c.voxelRenderer=N,N.render(A(c)),c.cameraCullSignature="voxel-direct";return}}let V={doc:s,directionalLight:_,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality,strategies:t.strategies},D=mt(c.polygons,V);B(c.wrapper,D);let Y={...V,solidPaintDefaults:D},L=(c.stableDom?pn(c.polygons,Y):null)??ao(c.polygons,Y);c.rendered=L.rendered,c.disposeAtlas=L.dispose,C(c),U(c),J(c)}function Z(){if(t.textureLighting!=="dynamic"){i.style.removeProperty("--shadow-ground-cssz");return}let c=1/0;for(let _ of a)if(!_.disposed&&_.castShadow)for(let V of _.polygons)for(let D of V.vertices)D[2]<c&&(c=D[2]);if(!Number.isFinite(c)){i.style.removeProperty("--shadow-ground-cssz");return}let b=t.shadow?.lift??.05,R=(c+b)*De;i.style.setProperty("--shadow-ground-cssz",R.toFixed(3))}async function se(c,b){p(c);let R={doc:s,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality,strategies:t.strategies},_=c.stableDom?pn(c.polygons,R):null;if(_){let Y=mt(c.polygons,R);return B(c.wrapper,Y),c.rendered=_.rendered,c.disposeAtlas=_.dispose,C(c),U(c),J(c),!b()}let V=await lo(c.polygons,R,b);if(b())return V.dispose(),!1;B(c.wrapper,V.solidPaintDefaults),c.rendered=V.rendered,c.disposeAtlas=V.dispose,C(c);let D=await I(c,b);return D&&J(c),D}function oe(){let c=r,b=[0,0,0];if(t.autoCenter){let R=[];for(let _ of a)!_.disposed&&!_.excludeFromAutoCenter&&R.push(..._.polygons);if(R.length>0){let _=(0,te.computeSceneBbox)(R);b=[(_.min[0]+_.max[0])/2,(_.min[1]+_.max[1])/2,(_.min[2]+_.max[2])/2]}}c[0]===b[0]&&c[1]===b[1]&&c[2]===b[2]||(r=b,l(i,t))}function de(c,b={}){let _=(i.ownerDocument??document).createElement("div");_.className="polycss-mesh",b.id&&_.setAttribute("data-poly-mesh-id",b.id);let V={...b},D=b.merge!==!1,Y=!!b.stableDom,L=0,N=go(V);N&&(_.style.transform=N);let z=(H,q)=>q?(0,te.mergePolygons)(H):H,G=z(c.polygons,D);function K(H){if(H.length===0){_.style.removeProperty("--origin");return}let q=1/0,re=1/0,ve=1/0,Me=-1/0,Ie=-1/0,We=-1/0;for(let Io of H)for(let Ee of Io.vertices)Ee[0]<q&&(q=Ee[0]),Ee[0]>Me&&(Me=Ee[0]),Ee[1]<re&&(re=Ee[1]),Ee[1]>Ie&&(Ie=Ee[1]),Ee[2]<ve&&(ve=Ee[2]),Ee[2]>We&&(We=Ee[2]);if(!Number.isFinite(q)){_.style.removeProperty("--origin");return}let Nt=(re+Ie)/2*De,nt=(q+Me)/2*De,ot=(ve+We)/2*De;_.style.setProperty("--origin",`${Nt}px ${nt}px ${ot}px`)}K(G),i.appendChild(_);let T={handle:void 0,wrapper:_,parseResult:c,rendered:[],shadowRendered:[],polygons:G,voxelSource:c.voxelSource,disposed:!1,stableDom:Y,excludeFromAutoCenter:!!b.excludeFromAutoCenter,castShadow:!!b.castShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",bakedRotation:b.rotation?[...b.rotation]:[0,0,0]},Q={polygons:G,element:_,id:b.id,get transform(){return V},remove(){L++,_.parentNode&&_.parentNode.removeChild(_),p(T),a.delete(T),oe(),Z()},setPolygons(H,q){L++,D=q?.merge??D,Y=q?.stableDom??Y,T.stableDom=Y,T.voxelSource=void 0,T.polygons=z(H,D),Q.polygons=T.polygons,K(T.polygons);let re=q?.recomputeAutoCenter??!0;if(T.stableDom&&!g(T.wrapper)){let ve={doc:s,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,textureQuality:t.textureQuality},Me=mt(T.polygons,ve);if(B(T.wrapper,Me),uo(T.rendered,T.polygons,{...ve,solidPaintDefaults:Me})){C(T),$(T,!0),re&&oe();return}}j(T),re&&oe()},updatePolygon(H,q){let re=typeof H=="number"?H:T.polygons.indexOf(H);re<0||re>=T.polygons.length||(T.voxelSource=void 0,Object.assign(T.polygons[re],q),j(T))},async setPolygonsChunked(H,q){let re=++L;D=q?.merge??D,Y=q?.stableDom??Y,T.stableDom=Y,T.voxelSource=void 0,T.polygons=z(H,D),Q.polygons=T.polygons,K(T.polygons);let ve=q?.recomputeAutoCenter??!0;if(!await se(T,()=>T.disposed||re!==L)){p(T);return}ve&&oe()},setTransform(H){let q=T.castShadow;H.castShadow!==void 0&&(T.castShadow=!!H.castShadow),V={...V,...H};let re=go(V);_.style.transform=re??"",F(T,V.rotation),H.rotation!==void 0&&$(T),T.castShadow!==q&&(J(T),Z())},dispose(){if(!T.disposed){T.disposed=!0,L++,_.parentNode&&_.parentNode.removeChild(_),p(T);try{c.dispose()}catch{}a.delete(T),oe(),Z()}},rebakeAtlas(){T.bakedRotation=V.rotation?[...V.rotation]:[0,0,0];let H=t.directionalLight?.direction??[.4,-.7,.59],q=(0,te.inverseRotateVec3)(H,T.bakedRotation);j(T,q)},getPosition(){return V.position},getRotation(){return V.rotation},getScale(){return V.scale},getPolygons(){return Q.polygons}};return T.handle=Q,a.add(T),j(T),F(T,V.rotation),oe(),Z(),Q}function ge(c){let b=!!t.autoCenter,R=t.strategies,_=t.textureLighting,V=t.rotX??ft,D=t.rotY??ht;t={...t,...c},l(i,t);let Y=!!t.autoCenter;for(let G of a)F(G,G.handle.transform.rotation);let L=c.strategies!==void 0&&!Ls(c.strategies,R);if(L)for(let G of a)j(G);let N=c.rotX!==void 0&&(t.rotX??ft)!==V||c.rotY!==void 0&&(t.rotY??ht)!==D;if(!L&&N)for(let G of a)$(G);if(b!==Y&&oe(),c.textureLighting!==void 0&&_!==t.textureLighting){for(let G of a)!L&&(G.voxelSource||G.voxelRenderer)?j(G):J(G);Z()}}function me(){return t}function ue(){let c=[];for(let b of a)c.push(b.handle);return c}function be(c){let b=c;for(;b;){if(b instanceof HTMLElement&&b.classList.contains("polycss-mesh")){for(let R of a)if(R.wrapper===b)return R.handle;return null}b=b.parentElement}return null}function xe(){let c=Array.from(a);for(let b of c)try{b.handle.dispose()}catch{}i.parentNode&&i.parentNode.removeChild(i)}return{add:de,setOptions:ge,destroy:xe,host:e,getOptions:me,meshes:ue,findMeshByElement:be}}var yn=require("@layoutit/polycss-core"),Ds=8e3;function Ke(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,yn.createIsometricCamera)(n),o=`${e.perspective??Ds}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function yt(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,yn.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var yo=require("@layoutit/polycss-core");var bt={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Xe(e,n){let t;return n.animate===!1?t=!1:n.animate?t={speed:n.animate.speed??.3,axis:n.animate.axis??"y",pauseOnInteraction:n.animate.pauseOnInteraction??!0}:t=e.animate,{drag:n.drag??e.drag,wheel:n.wheel??e.wheel,dolly:n.dolly??e.dolly,invert:n.invert??e.invert,minZoom:n.minZoom??e.minZoom,maxZoom:n.maxZoom??e.maxZoom,minDistance:n.minDistance??e.minDistance,maxDistance:n.maxDistance??e.maxDistance,animate:t}}function Je(e){return e===!0?-1:e===!1?1:e}function $e(){let e=[],n=[],t=[];function o(i){return i==="change"?e:i==="start"?n:t}function r(i){if(e.length===0)return;let a={type:"change",camera:i()},l=e.slice();for(let u of l)try{u(a)}catch(p){console.error("[polycss] controls 'change' listener threw:",p)}}function s(i,a){let l=i==="start"?n:t;if(l.length===0)return;let u={type:i,camera:a()},p=l.slice();for(let d of p)try{d(u)}catch(f){console.error(`[polycss] controls '${i}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function Ue(e){return()=>{let n=e.getOptions(),t=n.target??[0,0,0];return{rotX:n.rotX??0,rotY:n.rotY??0,zoom:n.zoom??1,target:[t[0],t[1],t[2]],distance:n.distance??0}}}function xt(e,n,t,o,r,s){let i=!1,a=null;return{onWheel:p=>{let d=n();if(!d.wheel||t())return;p.preventDefault();let f=p.deltaMode===1?16:p.deltaMode===2?100:1,g=p.deltaY*f;p.ctrlKey?g*=10:g*=3;let m=e.getOptions();if(d.dolly){let h=m.distance??0,y=Math.max(d.minDistance,Math.min(d.maxDistance,h+g*.05));e.setOptions({distance:y})}else{let h=Math.exp(-g*513e-6),y=m.zoom??1,v=Math.max(d.minZoom,Math.min(d.maxZoom,y*h));e.setOptions({zoom:v})}i||(i=!0,s("start",o)),r(o),a!==null&&clearTimeout(a),a=setTimeout(()=>{a=null,i=!1,s("end",o)},150)},teardown:()=>{a!==null&&(clearTimeout(a),a=null),i=!1}}}function vt(e,n,t,o,r,s,i){let a=null,l=0,u=g=>{if(a===null||o())return;let m=t();if(!m.animate){a=null;return}if(r())l=g;else{let h=Math.min(50,l?g-l:16.67);l=g;let y=m.animate.speed*(h/16.67),v=n.getOptions();if(m.animate.axis==="x"){let E=(((v.rotX??65)+y)%360+360)%360;n.setOptions({rotX:E})}else{let E=(((v.rotY??45)+y)%360+360)%360;n.setOptions({rotY:E})}i(s)}a=e.requestAnimationFrame(u)};return{start:()=>{a!==null||!t().animate||o()||(l=0,a=e.requestAnimationFrame(u))},stop:()=>{a!==null&&(e.cancelAnimationFrame(a),a=null)},isRunning:()=>a!==null}}function Pt(e,n={}){let t=Xe(bt,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},a=!1,l=!1,u=$e(),p=Ue(e),{changeListeners:d,startListeners:f,endListeners:g,listenerArray:m,emitChange:h,emitInteraction:y}=u,v=vt(r,e,()=>t,()=>l,()=>a,p,h),E=w=>{if(!(!t.drag||l)&&s===null&&w.isPrimary!==!1){w.preventDefault(),s=w.pointerId,i={x:w.clientX,y:w.clientY},o.style.cursor="grabbing";try{w.target.setPointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(a=!0),y("start",p)}},A=w=>{if(s===null||w.pointerId!==s||!t.drag||l)return;w.preventDefault();let I=w.clientX-i.x,F=w.clientY-i.y;i={x:w.clientX,y:w.clientY};let B=Je(t.invert),J=I/4*B,le=F/4*B,k=e.getOptions();if(w.shiftKey){let j=k.rotX??65,Z=k.rotY??45,se=Math.max(.01,k.zoom??1),oe=Math.cos(j*Math.PI/180),de=oe>=0?Math.max(.1,oe):Math.min(-.1,oe),ge=Math.cos(Z*Math.PI/180),me=Math.sin(Z*Math.PI/180),ue=se*yo.BASE_TILE,be=(I*me-F*ge/de)/ue,xe=-(I*ge+F*me/de)/ue,c=k.target??[0,0,0];e.setOptions({target:[c[0]+be,c[1]+xe,c[2]]})}else{let j=Math.max(0,Math.min(100,(k.rotX??65)-le)),Z=(((k.rotY??45)-J)%360+360)%360;e.setOptions({rotX:j,rotY:Z})}h(p)},x=w=>{if(s===w.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{w.target.releasePointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(a=!1),y("end",p)}},C=xt(e,()=>t,()=>l,p,h,y);function O(){o.addEventListener("pointerdown",E),o.addEventListener("pointermove",A),o.addEventListener("pointerup",x),o.addEventListener("pointercancel",x),o.addEventListener("wheel",C.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function M(){o.removeEventListener("pointerdown",E),o.removeEventListener("pointermove",A),o.removeEventListener("pointerup",x),o.removeEventListener("pointercancel",x),o.removeEventListener("wheel",C.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",C.teardown()}O(),v.start();function P(w){let I=!!t.animate;t=Xe(t,w),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let F=!!t.animate;I&&!F?v.stop():!I&&F&&v.start()}function X(){l&&(l=!1,O(),v.start())}function $(){l||(l=!0,M(),v.stop(),s=null,a=!1,C.teardown())}function W(){$(),d.length=0,f.length=0,g.length=0}function ne(w,I){let F=m(w);F.includes(I)||F.push(I)}function S(w,I){let F=m(w),B=F.indexOf(I);B>=0&&F.splice(B,1)}function U(w,I){return m(w).includes(I)}return{update:P,resume:X,pause:$,destroy:W,addEventListener:ne,removeEventListener:S,hasEventListener:U}}var bo=require("@layoutit/polycss-core");function Et(e,n={}){let t=Xe(bt,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},a=!1,l=!1,u=!1,p={x:0,y:0},d=$e(),f=Ue(e),{changeListeners:g,startListeners:m,endListeners:h,listenerArray:y,emitChange:v,emitInteraction:E}=d,A=vt(r,e,()=>t,()=>l,()=>a,f,v),x=k=>{if(!(!t.drag||l)&&s===null&&k.isPrimary!==!1){k.preventDefault(),s=k.pointerId,i={x:k.clientX,y:k.clientY},o.style.cursor="grabbing";try{k.target.setPointerCapture(k.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(a=!0),E("start",f)}},C=k=>{if(s===null||k.pointerId!==s||!t.drag||l)return;k.preventDefault();let j=k.clientX-i.x,Z=k.clientY-i.y;i={x:k.clientX,y:k.clientY};let se=e.getOptions();if(k.shiftKey){let oe=Je(t.invert),de=j/4*oe,ge=Z/4*oe,me=Math.max(0,Math.min(100,(se.rotX??65)-ge)),ue=(((se.rotY??45)-de)%360+360)%360;e.setOptions({rotX:me,rotY:ue})}else{let oe=se.rotX??65,de=se.rotY??45,ge=Math.max(.01,se.zoom??1),me=Math.cos(oe*Math.PI/180),ue=me>=0?Math.max(.1,me):Math.min(-.1,me),be=Math.cos(de*Math.PI/180),xe=Math.sin(de*Math.PI/180),c=ge*bo.BASE_TILE,b=(j*xe-Z*be/ue)/c,R=-(j*be+Z*xe/ue)/c,_=se.target??[0,0,0];e.setOptions({target:[_[0]+b,_[1]+R,_[2]]})}v(f)},O=k=>{if(s===k.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{k.target.releasePointerCapture(k.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(a=!1),E("end",f)}},M=k=>{k.preventDefault()},P=k=>{k.button===2&&(u=!0,p={x:k.clientX,y:k.clientY},t.animate&&t.animate.pauseOnInteraction&&(a=!0),E("start",f))},X=k=>{if(!u||!t.drag)return;let j=k.clientX-p.x,Z=k.clientY-p.y;p={x:k.clientX,y:k.clientY};let se=Je(t.invert),oe=j/4*se,de=Z/4*se,ge=e.getOptions(),me=Math.max(0,Math.min(100,(ge.rotX??65)-de)),ue=(((ge.rotY??45)-oe)%360+360)%360;e.setOptions({rotX:me,rotY:ue}),v(f)},$=k=>{k.button===2&&u&&(u=!1,E("end",f))},W=xt(e,()=>t,()=>l,f,v,E);function ne(){o.addEventListener("pointerdown",x),o.addEventListener("pointermove",C),o.addEventListener("pointerup",O),o.addEventListener("pointercancel",O),o.addEventListener("wheel",W.onWheel,{passive:!1}),o.addEventListener("contextmenu",M),o.addEventListener("mousedown",P),o.addEventListener("mousemove",X),o.addEventListener("mouseup",$),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function S(){o.removeEventListener("pointerdown",x),o.removeEventListener("pointermove",C),o.removeEventListener("pointerup",O),o.removeEventListener("pointercancel",O),o.removeEventListener("wheel",W.onWheel),o.removeEventListener("contextmenu",M),o.removeEventListener("mousedown",P),o.removeEventListener("mousemove",X),o.removeEventListener("mouseup",$),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",W.teardown()}ne(),A.start();function U(k){let j=!!t.animate;t=Xe(t,k),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let Z=!!t.animate;j&&!Z?A.stop():!j&&Z&&A.start()}function w(){l&&(l=!1,ne(),A.start())}function I(){l||(l=!0,S(),A.stop(),s=null,a=!1,u=!1,W.teardown())}function F(){I(),g.length=0,m.length=0,h.length=0}function B(k,j){let Z=y(k);Z.includes(j)||Z.push(j)}function J(k,j){let Z=y(k),se=Z.indexOf(j);se>=0&&Z.splice(se,1)}function le(k,j){return y(k).includes(j)}return{update:U,resume:w,pause:I,destroy:F,addEventListener:B,removeEventListener:J,hasEventListener:le}}var Mo=require("@layoutit/polycss-core");var Hs={enabled:!0,lookEnabled:!0,moveEnabled:!0,jumpEnabled:!0,crouchEnabled:!0,lookSensitivity:.15,invertY:!1,moveSpeed:5,jumpVelocity:7,gravity:18,eyeHeight:1.7,crouchHeight:1,groundZ:0,minPitch:5,maxPitch:175};function xo(e,n){return{enabled:n.enabled??e.enabled,lookEnabled:n.lookEnabled??e.lookEnabled,moveEnabled:n.moveEnabled??e.moveEnabled,jumpEnabled:n.jumpEnabled??e.jumpEnabled,crouchEnabled:n.crouchEnabled??e.crouchEnabled,lookSensitivity:n.lookSensitivity??e.lookSensitivity,invertY:n.invertY??e.invertY,moveSpeed:n.moveSpeed??e.moveSpeed,jumpVelocity:n.jumpVelocity??e.jumpVelocity,gravity:n.gravity??e.gravity,eyeHeight:n.eyeHeight??e.eyeHeight,crouchHeight:n.crouchHeight??e.crouchHeight,groundZ:n.groundZ??e.groundZ,minPitch:n.minPitch??e.minPitch,maxPitch:n.maxPitch??e.maxPitch}}var vo=new Set(["KeyW","ArrowUp"]),Po=new Set(["KeyS","ArrowDown"]),Eo=new Set(["KeyA","ArrowLeft"]),Co=new Set(["KeyD","ArrowRight"]),Ao=new Set(["Space"]),bn=new Set(["ControlLeft","ControlRight"]);function So(e,n={}){let t=xo(Hs,n),o=e.host,r=o.ownerDocument??document,s=r.defaultView??globalThis,i=$e(),a=Ue(e),{changeListeners:l,startListeners:u,endListeners:p,listenerArray:d,emitChange:f,emitInteraction:g}=i,m=new Set,h=!1,y=!1,v=0,E=0,A=!1,x=[0,0,t.groundZ+t.eyeHeight];function C(L,N){let z=L*Math.PI/180,G=N*Math.PI/180;return[-Math.sin(z)*Math.cos(G),-Math.sin(z)*Math.sin(G),-Math.cos(z)]}function O(){let L=e.getOptions().perspective;return(typeof L=="number"&&L>0?L:2e3)/Mo.BASE_TILE}function M(){let L=e.getOptions(),N=C(L.rotX??90,L.rotY??0),z=O();return[x[0]+N[0]*z,x[1]+N[1]*z,x[2]+N[2]*z]}function P(){let L=M();e.setOptions({target:L})}function X(){let N=e.getOptions().target??[0,0,0];x=[N[0],N[1],t.groundZ+t.eyeHeight],P()}let $=()=>{if(!(!t.enabled||!t.lookEnabled||y||h))try{o.requestPointerLock()}catch{}},W=()=>{let L=r.pointerLockElement===o;L!==h&&(h=L,h?(A=!0,g("start",a)):A&&(A=!1,g("end",a)))},ne=L=>{if(!h||!t.enabled||!t.lookEnabled||y)return;let N=L.movementX??0,z=L.movementY??0;if(N===0&&z===0)return;let G=e.getOptions(),K=t.lookSensitivity,T=t.invertY?-1:1,Q=(((G.rotY??0)-N*K)%360+360)%360,H=(G.rotX??90)-z*K*T;H<t.minPitch?H=t.minPitch:H>t.maxPitch&&(H=t.maxPitch);let q=C(H,Q),re=O(),ve=[x[0]+q[0]*re,x[1]+q[1]*re,x[2]+q[2]*re];e.setOptions({rotX:H,rotY:Q,target:ve}),f(a)},S=L=>vo.has(L)||Po.has(L)||Eo.has(L)||Co.has(L)||Ao.has(L)||bn.has(L),U=L=>{if(!(!t.enabled||y)&&S(L.code)&&!(!h&&!t.moveEnabled)){if(Ao.has(L.code)){if(!t.jumpEnabled)return;L.preventDefault(),!m.has(L.code)&&v===0&&E===0&&(v=t.jumpVelocity),m.add(L.code);return}bn.has(L.code)&&!t.crouchEnabled||!t.moveEnabled&&!bn.has(L.code)||(L.preventDefault(),m.add(L.code))}},w=L=>{S(L.code)&&m.delete(L.code)},I=()=>{m.clear()},F=null,B=0,J=.05,le=L=>{if(F===null||y)return;let N=Math.min(J,B?(L-B)/1e3:.0167);if(B=L,t.enabled){let z=!1,G=e.getOptions();if(t.moveEnabled){let H=0,q=0;for(let re of m)vo.has(re)?H+=1:Po.has(re)?H-=1:Co.has(re)?q+=1:Eo.has(re)&&(q-=1);if(H!==0||q!==0){let ve=(G.rotY??0)*Math.PI/180,Me=-Math.cos(ve),Ie=-Math.sin(ve),We=-Math.sin(ve),Nt=Math.cos(ve),nt=Math.hypot(H,q)||1,ot=t.moveSpeed*N;x[0]+=(Me*H+We*q)/nt*ot,x[1]+=(Ie*H+Nt*q)/nt*ot,z=!0}}let T=t.crouchEnabled&&(m.has("ControlLeft")||m.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(v!==0||E>0)?(v-=t.gravity*N,E+=v*N,E<=0&&(E=0,v=0)):t.jumpEnabled||(E=0,v=0);let Q=t.groundZ+T+E;if(Math.abs(x[2]-Q)>1e-4&&(x[2]=Q,z=!0),z){let H=M();e.setOptions({target:H}),f(a)}}F=s.requestAnimationFrame(le)};function k(){F!==null||y||(B=0,F=s.requestAnimationFrame(le))}function j(){F!==null&&(s.cancelAnimationFrame(F),F=null)}function Z(){let N=o.ownerDocument?.defaultView?.getComputedStyle(o).perspective??"",z=parseFloat(N),G=Number.isFinite(z)&&z>0?z:2e3;o.style.setProperty("--polycss-fpv-perspective",`${G}px`),o.classList.add("polycss-fpv-host")}function se(){o.classList.remove("polycss-fpv-host"),o.style.removeProperty("--polycss-fpv-perspective")}function oe(){o.addEventListener("click",$),r.addEventListener("pointerlockchange",W),r.addEventListener("mousemove",ne),s.addEventListener("keydown",U),s.addEventListener("keyup",w),s.addEventListener("blur",I),o.style.cursor=t.lookEnabled?"crosshair":"",Z()}function de(){if(o.removeEventListener("click",$),r.removeEventListener("pointerlockchange",W),r.removeEventListener("mousemove",ne),s.removeEventListener("keydown",U),s.removeEventListener("keyup",w),s.removeEventListener("blur",I),o.style.cursor="",m.clear(),h)try{r.exitPointerLock()}catch{}se()}X(),oe(),k();function ge(L){let N=t.eyeHeight,z=t.groundZ;t=xo(t,L),y||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==N||t.groundZ!==z)&&(x[2]=t.groundZ+t.eyeHeight,P(),f(a))}function me(){y&&(y=!1,oe(),k())}function ue(){y||(y=!0,de(),j(),A&&(A=!1,g("end",a)))}function be(){ue(),l.length=0,u.length=0,p.length=0}function xe(){if(!(!t.enabled||!t.lookEnabled||y))try{o.requestPointerLock()}catch{}}function c(){if(h)try{r.exitPointerLock()}catch{}}function b(){return h}function R(L,N){let z=d(L);z.includes(N)||z.push(N)}function _(L,N){let z=d(L),G=z.indexOf(N);G>=0&&z.splice(G,1)}function V(L,N){return d(L).includes(N)}function D(){return[x[0],x[1],x[2]]}function Y(L){x[0]=L[0],x[1]=L[1],x[2]=L[2],P(),f(a)}return{update:ge,resume:me,pause:ue,destroy:be,lock:xe,unlock:c,isLocked:b,getOrigin:D,setOrigin:Y,addEventListener:R,removeEventListener:_,hasEventListener:V}}function Is(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function Ct(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let h of o)try{h(t)}catch(y){console.error("[polycss/createSelect] onChange threw:",y)}}function s(m){t=m,r()}function i(m){n.multiple?t.includes(m)||(t=[...t,m]):t=[m],r()}function a(m){t.includes(m)&&(t=t.filter(h=>h!==m),r())}function l(m){t.includes(m)?t=t.filter(h=>h!==m):n.multiple?t=[...t,m]:t=[m],r()}function u(){t.length!==0&&(t=[],r())}function p(m){return t.includes(m)}function d(m,h){for(let y of e.meshes())if(!y.element.classList.contains("polycss-transform-gizmo")&&Is(y.element,m,h))return y;return null}let f=m=>{let h=m.target;if(h?.closest(".polycss-transform-gizmo"))return;let y=e.findMeshByElement(h)??d(m.clientX,m.clientY);if(!y){n.onPointerMissed&&n.onPointerMissed(m),n.clearOnMiss!==!1&&u();return}n.multiple&&(m.shiftKey||m.metaKey||m.ctrlKey)?l(y):t.length===1&&t[0]===y?u():s([y])};e.host.addEventListener("click",f);function g(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:s,add:i,remove:a,toggle:l,clear:u,has:p,destroy:g}}var Pe=require("@layoutit/polycss-core"),Mt="#ff3653",St="#8adb00",Lt="#2c8fff",Ge=50,Lo=60,Vs=.6,Fs=.0125,zs=.15,Bs=.04,Ns=1,wo=.02,xn=1.04,Ys=.1,Xs=.25,Ro=1e-4,$s=.6,Us=.8,Gs=1,et={0:1,1:0,2:2},To=[{cssAxis:0,sign:1,key:"x",color:Mt},{cssAxis:0,sign:-1,key:"-x",color:Mt},{cssAxis:1,sign:1,key:"y",color:St},{cssAxis:1,sign:-1,key:"-y",color:St},{cssAxis:2,sign:1,key:"z",color:Lt},{cssAxis:2,sign:-1,key:"-z",color:Lt}],_o=[{cssAxis:0,key:"x",color:Mt},{cssAxis:1,key:"y",color:St},{cssAxis:2,key:"z",color:Lt}],ko=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:Lt},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:St},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:Mt}];function vn(e,n,t,o){let r=t*Math.PI/180,s=o*Math.PI/180,i=[0,0,0];i[e]=n;let a=i[0]*Math.cos(s)-i[1]*Math.sin(s),l=i[0]*Math.sin(s)+i[1]*Math.cos(s),u=i[2];return l*Math.sin(r)+u*Math.cos(r)<0}function js(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),s=parseInt(t[3],16);return`rgba(${o}, ${r}, ${s}, ${n})`}function wt(e,n){return!n||n<=0?e:Math.round(e/n)*n}function Ws(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let a of e)for(let l of a.vertices)l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>s&&(s=l[1]),l[2]<o&&(o=l[2]),l[2]>i&&(i=l[2]);return Number.isFinite(n)?[(t+s)/2*Ge,(n+r)/2*Ge,(o+i)/2*Ge]:[0,0,0]}function Pn(e){if(e.length===0)return Lo;let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let u of l.vertices)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*Ge*Vs:Lo}function At(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function Zs(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:a,translationSnap:l,onAxisDelta:u,onMouseDown:p,onMouseUp:d,onDraggingChanged:f}=e,g=o,m=[0,0,0];m[n]=t;let h=r.ownerDocument.createElement("div");h.style.position="absolute",h.style.left="0",h.style.top="0",h.style.width="0",h.style.height="0",h.style.transform=`translate3d(${m[0]*g}px, ${m[1]*g}px, ${m[2]*g}px)`,r.appendChild(h);let y=r.getBoundingClientRect(),v=h.getBoundingClientRect();r.removeChild(h);let E=(v.left-y.left)/g,A=(v.top-y.top)/g,x=E*E+A*A;if(x<Ro)return;p?.(),f?.(!0);let C=M=>{let P=M.clientX-i,X=M.clientY-a,$=(P*E+X*A)/x;$=wt($,l),u($,m)},O=()=>{window.removeEventListener("pointermove",C),window.removeEventListener("pointerup",O),window.removeEventListener("pointercancel",O);let M=P=>{P.stopPropagation(),P.stopImmediatePropagation()};window.addEventListener("click",M,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",M,!0),0),d?.(),f?.(!1)};window.addEventListener("pointermove",C),window.addEventListener("pointerup",O),window.addEventListener("pointercancel",O)}function qs(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:s,startClientY:i,translationSnap:a,onPlaneDelta:l,onMouseDown:u,onMouseUp:p,onDraggingChanged:d}=e,f=[0,0,0];f[n]=1;let g=[0,0,0];g[t]=1;function m(x){let C=r.ownerDocument.createElement("div");C.style.position="absolute",C.style.left="0",C.style.top="0",C.style.width="0",C.style.height="0",C.style.transform=`translate3d(${x[0]*o}px, ${x[1]*o}px, ${x[2]*o}px)`,r.appendChild(C);let O=r.getBoundingClientRect(),M=C.getBoundingClientRect();return r.removeChild(C),{x:(M.left-O.left)/o,y:(M.top-O.top)/o}}let h=m(f),y=m(g),v=h.x*y.y-y.x*h.y;if(Math.abs(v)<Ro)return;u?.(),d?.(!0);let E=x=>{let C=x.clientX-s,O=x.clientY-i,M=(y.y*C-y.x*O)/v,P=(-h.y*C+h.x*O)/v;M=wt(M,a),P=wt(P,a),l(M,P,f,g)},A=()=>{window.removeEventListener("pointermove",E),window.removeEventListener("pointerup",A),window.removeEventListener("pointercancel",A);let x=C=>{C.stopPropagation(),C.stopImmediatePropagation()};window.addEventListener("click",x,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",x,!0),0),p?.(),d?.(!1)};window.addEventListener("pointermove",E),window.addEventListener("pointerup",A),window.addEventListener("pointercancel",A)}function Qs(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:a,onMouseDown:l,onMouseUp:u,onDraggingChanged:p}=e,d=t.getBoundingClientRect(),f=d.left,g=d.top,m=Math.atan2(s-g,r-f),h=0;l?.(),p?.(!0);let y=E=>{let A=Math.atan2(E.clientY-g,E.clientX-f),x=A-m;x>Math.PI?x-=2*Math.PI:x<-Math.PI&&(x+=2*Math.PI),h+=x,m=A;let C=h*180/Math.PI;C=wt(C,i),a(C)},v=()=>{window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",v),window.removeEventListener("pointercancel",v);let E=A=>{A.stopPropagation(),A.stopImmediatePropagation()};window.addEventListener("click",E,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",E,!0),0),u?.(),p?.(!1)};window.addEventListener("pointermove",y),window.addEventListener("pointerup",v),window.addEventListener("pointercancel",v)}function Tt(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,a=null,l=null,u=[0,0,0];function p(){if(!t)return[0,0,0];let S=t.transform.position??[0,0,0];return[S[0]+u[0],S[1]+u[1],S[2]+u[2]]}function d(S){return l===S?Gs:a===S?Us:$s}function f(){for(let[S,U]of i){let w=g(U.spec,d(S));U.handle.setPolygons(w,{recomputeAutoCenter:!1})}}function g(S,U){let I=Pn(t?.polygons??[])*r,F=I/Ge,B=js(S.color,U);if(S.kind==="arrow"){let k=e.getOptions(),j=vn(S.cssAxis,S.sign,k.rotX??65,k.rotY??45);return(0,Pe.arrowPolygons)({axis:et[S.cssAxis],sign:S.sign,shaftLength:F,shaftHalfThickness:F*Fs,headLength:F*zs,headHalfThickness:F*Bs,color:B,shaft:!j})}if(S.kind==="plane"){let k=e.getOptions(),j=k.rotX??65,Z=k.rotY??45,se=et[S.perpAxis],oe=(se+1)%3,de=(se+2)%3,ge=et[oe],me=et[de],ue=vn(ge,1,j,Z)?-1:1,be=vn(me,1,j,Z)?-1:1,xe=F*Xs;return(0,Pe.planePolygons)({axis:se,size:F*Ys,offset:[ue*xe,be*xe],color:B})}let le=I*Ns/Ge*xn;return(0,Pe.ringQuadPolygons)({axis:et[S.cssAxis],outerRadius:le,color:B})}function m(S){return S.kind==="arrow"?"polycss-transform-arrow":S.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function h(){if(o==="translate"){let S=To.map(w=>({kind:"arrow",key:w.key,cssAxis:w.cssAxis,sign:w.sign,color:w.color})),U=ko.map(w=>({kind:"plane",key:w.key,perpAxis:w.perpAxis,axisA:w.axisA,axisB:w.axisB,color:w.color}));return[...S,...U]}return o==="rotate"?_o.map(S=>({kind:"ring",key:S.key,cssAxis:S.cssAxis,color:S.color})):[]}function y(){if(v(),!t)return;let S={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};function U(I){if(I.kind==="arrow"){let J=I.key.replace("-","")[0];return S[J]}if(I.kind==="ring")return S[I.key];let F=["x","y","z"][I.axisA],B=["x","y","z"][I.axisB];return S[F]&&S[B]}let w=p();for(let I of h()){if(!U(I))continue;let F=g(I,d(I.key)),B=e.add({polygons:F,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${I.key}`,position:w}),J=m(I);if(B.element.classList.add("polycss-transform-gizmo",J,`${J}--${I.key}`),I.kind==="ring"){let le=(1-wo)/xn,k=(1+wo)/xn;B.element.style.setProperty("--ring-inner-ratio",`${le}`),B.element.style.setProperty("--ring-outer-ratio",`${k}`)}i.set(I.key,{handle:B,spec:I})}}function v(){for(let{handle:S}of i.values())S.remove();i.clear(),a=null,l=null}function E(){if(!t)return;let S=p();for(let{handle:U}of i.values())U.setTransform({position:S})}function A(){t&&(i.size===0?y():E())}function x(S){if(t=S,!S){u=[0,0,0],v();return}u=Ws(S.polygons),v(),y()}function C(){x(null)}function O(S){S!==o&&(o=S,t&&(v(),y()))}function M(S,U,w){if(!t||!P)return;let I=[P[0]+U*w[0],P[1]+U*w[1],P[2]+U*w[2]];t.setTransform({position:I}),E(),s.onObjectChange?.({object:t,position:I}),s.onChange?.()}let P=null,X=null,$=S=>{if(!t||s.enabled===!1)return;let U={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate"){for(let w of ko){let I=["x","y","z"][w.axisA],F=["x","y","z"][w.axisB];if(!U[I]||!U[F])continue;let B=i.get(w.key);if(B&&At(B.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),l=w.key,f(),P=(t.transform.position??[0,0,0]).slice(),qs({axisA:w.axisA,axisB:w.axisB,probeDistanceCss:Pn(t.polygons)*r,wrapper:B.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,translationSnap:s.translationSnap??null,onPlaneDelta:(J,le,k,j)=>{if(!t||!P)return;let Z=[P[0]+J*k[0]+le*j[0],P[1]+J*k[1]+le*j[1],P[2]+J*k[2]+le*j[2]];t.setTransform({position:Z}),E(),s.onObjectChange?.({object:t,position:Z}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:J=>{J||(l=null,P=null,f()),s.onDraggingChanged?.(J)}});return}}for(let w of To){let I=w.key.replace("-","")[0];if(!U[I])continue;let F=i.get(w.key);if(F&&At(F.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),l=w.key,f(),P=(t.transform.position??[0,0,0]).slice(),Zs({cssAxis:w.cssAxis,sign:w.sign,shaftLengthCss:Pn(t.polygons)*r,wrapper:F.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(B,J)=>M(w,B,J),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:B=>{B||(l=null,P=null,f()),s.onDraggingChanged?.(B)}});return}}}else if(o==="rotate")for(let w of _o){if(!U[w.key])continue;let I=i.get(w.key);if(I&&At(I.handle.element,S.clientX,S.clientY)){S.preventDefault(),S.stopPropagation(),l=w.key,f(),X=(t.transform.rotation??[0,0,0]).slice(),Qs({cssAxis:w.cssAxis,wrapper:I.handle.element,target:t,startClientX:S.clientX,startClientY:S.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:F=>{if(!t||!X)return;let B=w.cssAxis===0?-1:1,J=[0,0,0];J[w.cssAxis]=1;let le=F*B*Math.PI/180,k=(0,Pe.quatFromEulerXYZ)(X),j=(0,Pe.quatFromAxisAngle)(J,le),Z=(0,Pe.eulerXYZFromQuat)((0,Pe.quatMultiply)(j,k));t.setTransform({rotation:Z}),s.onObjectChange?.({object:t,rotation:Z}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:F=>{F||(l=null,X=null,f(),t?.rebakeAtlas()),s.onDraggingChanged?.(F)}});return}}};e.host.addEventListener("pointerdown",$,{capture:!0});let W=S=>{if(!t||l||s.enabled===!1)return;let U=null;for(let[w,I]of i)if(At(I.handle.element,S.clientX,S.clientY)){U=w;break}U!==a&&(a=U,f())};e.host.addEventListener("pointermove",W);function ne(){e.host.removeEventListener("pointerdown",$,{capture:!0}),e.host.removeEventListener("pointermove",W),v()}return{attach:x,detach:C,setMode:O,update:A,destroy:ne}}var Ks=typeof HTMLElement<"u"?HTMLElement:class{},Js=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function He(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function ei(e){return e==="false"?!1:He(e)}function ti(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function ni(e){if(e==="baked"||e==="dynamic")return e}function oi(e){return e==="auto"?"auto":He(e)}var Ce=class extends Ks{constructor(){super(...arguments);this._scene=null}static get observedAttributes(){return[...Js]}getScene(){return this._scene}_readOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={},s=ei(this.getAttribute("perspective"));s!==void 0&&(r.perspective=s);let i=He(this.getAttribute("rot-x"));i!==void 0&&(r.rotX=i);let a=He(this.getAttribute("rot-y"));a!==void 0&&(r.rotY=a);let l=He(this.getAttribute("zoom"));l!==void 0&&(r.zoom=l),r.textureLighting=ni(this.getAttribute("texture-lighting"))??"baked";let u=oi(this.getAttribute("texture-quality"));return u!==void 0&&(r.textureQuality=u),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=ti(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=He(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let s={direction:t??[.4,-.7,.59]};return o&&(s.color=o),r!==void 0&&(s.intensity=r),s}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=He(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){this._scene||(this._scene=gt(this,this._readOptions()),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1})))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null)}attributeChangedCallback(t,o,r){o!==r&&this._scene&&this._scene.setOptions(this._readOptions())}};var _t=require("@layoutit/polycss-core"),ri=typeof HTMLElement<"u"?HTMLElement:class{},si=["src","mtl","position","scale","rotation","auto-center"];function tt(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Oo(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return tt(e)}}function ii(e){return e.closest("poly-scene")??null}function ai(e){if(e.length===0)return e;let n=(0,_t.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s),...i.textureTriangles?.length?{textureTriangles:i.textureTriangles.map(a=>({...a,vertices:a.vertices.map(s)}))}:null}))}var je=class extends ri{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...si]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:tt(this.getAttribute("position")),scale:Oo(this.getAttribute("scale")),rotation:tt(this.getAttribute("rotation"))})}}_tearDown(){if(this._loadToken+=1,this._handle){try{this._handle.dispose()}catch{}this._handle=null}this._parseResult=null}async _maybeLoad(){let t=this.getAttribute("src");if(!t)return;let o=ii(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,i;try{i=await(0,_t.loadMesh)(t,s?{mtlUrl:s}:void 0)}catch(u){this.dispatchEvent(new CustomEvent("polycss:error",{detail:u,bubbles:!0}));return}if(r!==this._loadToken){try{i.dispose()}catch{}return}let a=o.getScene();if(!a){try{i.dispose()}catch{}return}this.hasAttribute("auto-center")&&(i={...i,polygons:ai(i.polygons)}),this._parseResult=i,this._handle=a.add(i,{position:tt(this.getAttribute("position")),scale:Oo(this.getAttribute("scale")),rotation:tt(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var li=typeof HTMLElement<"u"?HTMLElement:class{},ci=["vertices","color","texture","uvs","position","scale","rotation"];function Do(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function En(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function ui(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return En(e)}}function di(e){return e.closest("poly-scene")??null}var kt=class extends li{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...ci]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=di(this);if(!t)return;let o=t.getScene();if(!o)return;let r=Do(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let s=this.getAttribute("color")||void 0,i=this.getAttribute("texture")||void 0,a=Do(this.getAttribute("uvs"))??void 0,l={};for(let d of Array.from(this.attributes))d.name.startsWith("data-")&&(l[d.name.slice(5)]=d.value);let p={polygons:[{vertices:r,...s!==void 0?{color:s}:{},...i!==void 0?{texture:i}:{},...a!==void 0?{uvs:a}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(p,{position:En(this.getAttribute("position")),scale:ui(this.getAttribute("scale")),rotation:En(this.getAttribute("rotation"))})}};function ae(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Rt(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function _e(e){if(e!==null)return!(e==="false"||e==="0")}function Ot(e){if(e===null)return;if(e==="true")return!0;if(e==="false")return!1;let n=parseFloat(e);return Number.isFinite(n)?n:!0}function Dt(e){if(e==="x"||e==="y")return e}var mi=typeof HTMLElement<"u"?HTMLElement:class{},pi=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Ht=class extends mi{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...pi]}_readAnimate(){let t=ae(this.getAttribute("animate-speed")),o=Dt(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:_e(r)}:{}}}_readOptions(){let t={},o=_e(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=_e(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ae(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ae(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let a=Ot(this.getAttribute("invert"));a!==void 0&&(t.invert=a);let l=ae(this.getAttribute("zoom-min")),u=ae(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ce)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=Pt(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var fi=typeof HTMLElement<"u"?HTMLElement:class{},hi=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],It=class extends fi{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...hi]}_readAnimate(){let t=ae(this.getAttribute("animate-speed")),o=Dt(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:_e(r)}:{}}}_readOptions(){let t={},o=_e(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=_e(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ae(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ae(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let a=Ot(this.getAttribute("invert"));a!==void 0&&(t.invert=a);let l=ae(this.getAttribute("zoom-min")),u=ae(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ce)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=Et(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var gi=typeof HTMLElement<"u"?HTMLElement:class{},yi=["perspective","zoom","rot-x","rot-y","target","distance"],Vt=class extends gi{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...yi]}getCamera(){return this._camera}_readOptions(){return{perspective:ae(this.getAttribute("perspective")),zoom:ae(this.getAttribute("zoom")),rotX:ae(this.getAttribute("rot-x")),rotY:ae(this.getAttribute("rot-y")),target:Rt(this.getAttribute("target")),distance:ae(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Ke(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let s=this._readOptions();this._camera=Ke(s),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var bi=typeof HTMLElement<"u"?HTMLElement:class{},xi=["zoom","rot-x","rot-y","target","distance"],Ft=class extends bi{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...xi]}getCamera(){return this._camera}_readOptions(){return{zoom:ae(this.getAttribute("zoom")),rotX:ae(this.getAttribute("rot-x")),rotY:ae(this.getAttribute("rot-y")),target:Rt(this.getAttribute("target")),distance:ae(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=yt(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let s=this._readOptions();s.zoom!==void 0&&this._camera.update({zoom:s.zoom}),s.rotX!==void 0&&this._camera.update({rotX:s.rotX}),s.rotY!==void 0&&this._camera.update({rotY:s.rotY}),s.target!==void 0&&this._camera.update({target:s.target}),s.distance!==void 0&&this._camera.update({distance:s.distance})}};var vi=typeof HTMLElement<"u"?HTMLElement:class{},Pi=["mode","target","size","enabled"];function Ho(e){if(e==="translate"||e==="rotate")return e}var zt=class extends vi{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Pi]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ce)return t;t=t.parentNode}return null}_findTargetMesh(){let t=this.getAttribute("target");if(!t)return null;let o=this._findScene();if(!o)return null;let r=null;try{r=o.querySelector(`#${t}`)??o.querySelector(t)}catch{r=o.querySelector(`[id="${t}"]`)}return r instanceof je?r:null}_readOptions(){let t={},o=Ho(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=ae(this.getAttribute("size"));r!==void 0&&(t.size=r);let s=this.getAttribute("enabled");return s!==null&&(t.enabled=s!=="false"&&s!=="0"),t.onObjectChange=i=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:i.position,rotation:i.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let s=()=>{t.removeEventListener("polycss:scene-ready",s),this._attach()};t.addEventListener("polycss:scene-ready",s)}return}this._tc=Tt(o,this._readOptions());let r=this._findTargetMesh();if(r){let s=r.getMeshHandle();s&&this._tc.attach(s)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,r){if(o!==r&&this._tc){if(t==="mode"){let s=Ho(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};var Ei=typeof HTMLElement<"u"?HTMLElement:class{},Ci=["multiple","clear-on-miss"],Bt=class extends Ei{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Ci]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ce)return t;t=t.parentNode}return null}_readOptions(){return{multiple:this.hasAttribute("multiple"),clearOnMiss:!this.hasAttribute("clear-on-miss")||this.getAttribute("clear-on-miss")!=="false",onChange:t=>{this.dispatchEvent(new CustomEvent("polycss:select",{bubbles:!0,detail:{selected:t}}))}}}_attach(){if(this._selection)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._selection=Ct(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};he(fe,require("@layoutit/polycss-core"),module.exports);0&&(module.exports={PolyMapControlsElement,PolyMeshElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPolygonElement,PolySceneElement,PolySelectElement,PolyTransformControlsElement,createPolyFirstPersonControls,createPolyMapControls,createPolyOrbitControls,createPolyOrthographicCamera,createPolyPerspectiveCamera,createPolyScene,createSelect,createTransformControls,injectPolyBaseStyles,...require("@layoutit/polycss-core")});
|