@layoutit/polycss 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/elements.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Co=Object.defineProperty;var Bi=Object.getOwnPropertyDescriptor;var Ni=Object.getOwnPropertyNames;var Ui=Object.prototype.hasOwnProperty;var $i=(e,n)=>{for(var t in n)Co(e,t,{get:n[t],enumerable:!0})},Gi=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Ni(n))!Ui.call(e,r)&&r!==t&&Co(e,r,{get:()=>n[r],enumerable:!(o=Bi(n,r))||o.enumerable});return e};var Yi=e=>Gi(Co({},"__esModule",{value:!0}),e);var ca={};$i(ca,{PolyAxesHelperElement:()=>hn,PolyBoxElement:()=>Mn,PolyCameraElement:()=>Cn,PolyConeElement:()=>Hn,PolyCylinderElement:()=>Fn,PolyDirectionalLightHelperElement:()=>yn,PolyDodecahedronElement:()=>kn,PolyFirstPersonControlsElement:()=>Pn,PolyIcosahedronElement:()=>Dn,PolyMapControlsElement:()=>xn,PolyMeshElement:()=>Lt,PolyOctahedronElement:()=>_n,PolyOrbitControlsElement:()=>vn,PolyOrthographicCameraElement:()=>_t,PolyPerspectiveCameraElement:()=>Sn,PolyPlaneElement:()=>wn,PolyPolygonElement:()=>gn,PolyRingElement:()=>Ln,PolySceneElement:()=>Ge,PolySelectElement:()=>An,PolySphereElement:()=>On,PolyTetrahedronElement:()=>Rn,PolyTorusElement:()=>In,PolyTransformControlsElement:()=>Tn});module.exports=Yi(ca);var W=require("@layoutit/polycss-core");var sr=require("@layoutit/polycss-core");function ji(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 nn(e,n,t){return(0,sr.packTextureAtlasPlansWithScaleCore)(e,n,ji(t))}var Ut=require("@layoutit/polycss-core");var ft=require("@layoutit/polycss-core"),mr=require("@layoutit/polycss-core"),pr=require("@layoutit/polycss-core"),fr=require("@layoutit/polycss-core"),Dt=new Map;function Xi(e){let n=Dt.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.crossOrigin="anonymous",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),Dt.set(e,n),n.then(()=>{Dt.get(e)===n&&Dt.delete(e)},()=>{Dt.get(e)===n&&Dt.delete(e)})),n}function Ze(e,n,t=1,o=0,r=0,i=1,l=0,c=0){e.setTransform(t*n,o*n,r*n,i*n,l*n,c*n)}function Wi(e,n,t,o,r,i,l){Math.abs(i.r-1)<.001&&Math.abs(i.g-1)<.001&&Math.abs(i.b-1)<.001||(e.save(),Ze(e,l),e.globalCompositeOperation="multiply",e.fillStyle=(0,mr.tintToCss)(i),e.fillRect(n,t,o,r),e.restore())}function Zi(e,n,t,o,r,i,l){let c=n.naturalWidth||n.width||1,a=n.naturalHeight||n.height||1,m=Math.max(r/c,i/a),f=c*m,h=a*m;Ze(e,l),e.drawImage(n,t+(r-f)/2,o+(i-h)/2,f,h)}function kt(e,n){return Math.max(0,Math.min(n,e))}function lr(e,n,t,o,r,i,l,c){let a=n.naturalWidth||n.width||1,m=n.naturalHeight||n.height||1,f=kt(Math.min(t.minU,t.maxU)*a,a),h=kt(Math.max(t.minU,t.maxU)*a,a),g=kt(Math.min(t.minV,t.maxV)*m,m),x=kt(Math.max(t.minV,t.maxV)*m,m),y=Math.floor(f),P=Math.floor(g),v=Math.ceil(h)-y,E=Math.ceil(x)-P;v<1&&(y=Math.floor(kt((t.minU+t.maxU)/2*a,a-1)),v=1),E<1&&(P=Math.floor(kt((t.minV+t.maxV)/2*m,m-1)),E=1),y=Math.max(0,Math.min(a-1,y)),P=Math.max(0,Math.min(m-1,P)),v=Math.max(1,Math.min(a-y,v)),E=Math.max(1,Math.min(m-P,E)),Ze(e,c),e.drawImage(n,y,P,v,E,o,r,i,l)}function gr(e){return e==="repeat"||e==="mirrored-repeat"}function ar(e,n){return gr(e)?Math.floor(n):0}function cr(e,n){return gr(e)?Math.ceil(n)-1:0}function ur(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function dr(e,n,t,o,r,i,l){let c=r?ar(i,r.minU):0,a=r?cr(i,r.maxU):0,m=r?ar(l,r.minV):0,f=r?cr(l,r.maxV):0;for(let h=c;h<=a;h++)for(let g=m;g<=f;g++){let x=ur(i,h),y=ur(l,g);if(!x&&!y){e.drawImage(n,h*t,g*o);continue}e.save(),e.translate((x?h+1:h)*t,(y?g+1:g)*o),e.scale(x?-1:1,y?-1:1),e.drawImage(n,0,0),e.restore()}}function Eo(e,n,t,o){for(let r=0;r<o.length;r+=2){let i=n+o[r],l=t+o[r+1];r===0?e.moveTo(i,l):e.lineTo(i,l)}e.closePath()}function Un(e,n,t,o,r,i){for(let l=0;l<o.length;l+=2){let c=n+o[l]+r,a=t+o[l+1]+i;l===0?e.moveTo(c,a):e.lineTo(c,a)}e.closePath()}function Qi(e,n,t,o){Ze(e,o),e.beginPath(),Eo(e,n.x,n.y,n.screenPts),e.clip(),Ze(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function $n(e,n,t,o,r){n.polygon.textureAlphaMode==="opaque"&&(Ze(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+r,n.canvasW,n.canvasH))}function qi(e,n,t,o,r=0,i=0){if(n.textureTriangles?.length){let l=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1;for(let a of n.textureTriangles){let m=(0,pr.expandClipPoints)(a.screenPts,ft.TEXTURE_TRIANGLE_BLEED);e.save(),Ze(e,o),e.beginPath(),Un(e,n.x,n.y,m,r,i),e.clip(),$n(e,n,o,r,i),a.uvAffine?(Ze(e,o,a.uvAffine.a/l,a.uvAffine.c/l,a.uvAffine.b/c,a.uvAffine.d/c,n.x+a.uvAffine.e+r,n.y+a.uvAffine.f+i),dr(e,t,l,c,a.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t)):a.uvSampleRect&&lr(e,t,a.uvSampleRect,n.x+r,n.y+i,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let l=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1,a=n.polygon.textureAlphaMode==="opaque";a&&(e.save(),Ze(e,o),e.beginPath(),Un(e,n.x,n.y,n.screenPts,r,i),e.clip(),$n(e,n,o,r,i)),Ze(e,o,n.uvAffine.a/l,n.uvAffine.c/l,n.uvAffine.b/c,n.uvAffine.d/c,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+i),dr(e,t,l,c,n.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t),a&&e.restore()}else if(n.uvSampleRect){let l=n.polygon.textureAlphaMode==="opaque";l&&(e.save(),Ze(e,o),e.beginPath(),Un(e,n.x,n.y,n.screenPts,r,i),e.clip(),$n(e,n,o,r,i)),lr(e,t,n.uvSampleRect,n.x+r,n.y+i,n.canvasW,n.canvasH,o),l&&e.restore()}else{let l=n.polygon.textureAlphaMode==="opaque";l&&(e.save(),Ze(e,o),e.beginPath(),Un(e,n.x,n.y,n.screenPts,r,i),e.clip(),$n(e,n,o,r,i)),Zi(e,t,n.x+r,n.y+i,n.canvasW,n.canvasH,o),l&&e.restore()}}function Ki(e,n,t,o,r,i){let l=r-t,c=i-o,a=l*l+c*c;if(a<=fr.BASIS_EPS)return Math.hypot(e-t,n-o);let m=Math.max(0,Math.min(1,((e-t)*l+(n-o)*c)/a));return Math.hypot(e-(t+l*m),n-(o+c*m))}function Ji(e,n,t,o){let r=1/0,i=t.length/2;for(let l of o){if(l<0||l>=i)continue;let c=l*2,a=(l+1)%i*2;r=Math.min(r,Ki(e,n,t[c],t[c+1],t[a],t[a+1]))}return r}function es(e,n,t,o,r,i){let l=Math.max(0,o-i),c=Math.min(n-1,o+i),a=Math.max(0,r-i),m=Math.min(t-1,r+i),f=null,h=1/0;for(let g=a;g<=m;g++)for(let x=l;x<=c;x++){if(x===o&&g===r)continue;let y=x-o,P=g-r,v=y*y+P*P;if(v>i*i||v>=h)continue;let E=(g*n+x)*4;e[E+3]<ft.TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN||(f=E,h=v)}return f}function ts(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),i=Math.max(0,Math.floor(n.y*t)),l=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),c=Math.max(1,Math.min(o.height-i,Math.ceil(n.canvasH*t)));if(l<=0||c<=0)return;let a;try{a=e.getImageData(r,i,l,c)}catch{return}let m=a.data,f=new Uint8ClampedArray(m),h=Math.max(ft.TEXTURE_EDGE_REPAIR_RADIUS,ft.TEXTURE_EDGE_REPAIR_RADIUS/t),g=Math.max(2,Math.ceil(h*t)+1),x=!1;for(let y=0;y<c;y++)for(let P=0;P<l;P++){let v=(y*l+P)*4,E=m[v+3];if(E<ft.TEXTURE_EDGE_REPAIR_ALPHA_MIN||E===255)continue;let H=(r+P+.5)/t-n.x,k=(i+y+.5)/t-n.y;if(Ji(H,k,n.screenPts,n.textureEdgeRepairEdges)>h)continue;let N=es(f,l,c,P,y,g);N!==null&&(m[v]=f[N],m[v+1]=f[N+1],m[v+2]=f[N+2],m[v+3]=255,x=!0)}x&&e.putImageData(a,r,i)}function ns(e){if(typeof e.toBlob=="function")return new Promise(n=>{e.toBlob(t=>{n(t?URL.createObjectURL(t):null)},"image/png")});try{return Promise.resolve(e.toDataURL("image/png"))}catch{return Promise.resolve(null)}}async function os(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let i=e.entries.some(f=>f.textureEdgeRepair&&f.texture&&f.textureEdgeRepairEdges&&f.textureEdgeRepairEdges.size>0),l=r.getContext("2d",i?{willReadFrequently:!0}:void 0);if(!l)return{width:e.width,height:e.height,url:null};let c=Array.from(new Set(e.entries.flatMap(f=>f.texture?[f.texture]:[]))),a=new Map;await Promise.all(c.map(async f=>{a.set(f,await Xi(f))}));for(let f of e.entries){let h=f.texture?a.get(f.texture):null;if(!f.texture){l.save(),Qi(l,f,n,o),l.restore();continue}h&&(l.save(),Ze(l,o),l.beginPath(),Eo(l,f.x,f.y,f.screenPts),l.clip(),qi(l,f,h,o),l.restore()),f.texture&&n==="baked"&&(l.save(),Ze(l,o),l.beginPath(),Eo(l,f.x,f.y,f.screenPts),l.clip(),Wi(l,f.x,f.y,f.canvasW,f.canvasH,f.textureTint,o),l.restore()),ts(l,f,o)}let m=await ns(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:m}}async function on(e,n,t,o,r){let i=[];for(let l of e){if(r())break;i.push(await os(l,n,t,o))}return i}var J=require("@layoutit/polycss-core"),Gn=require("@layoutit/polycss-core"),yr=require("@layoutit/polycss-core");var hr=require("@layoutit/polycss-core");function Ot(e){let t=e?.defaultView?.__polycssProjectiveQuadGuards;return(0,hr.resolveProjectiveQuadGuards)(t)}function rn(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 br(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,J.safariCssProjectiveUnsupported)(t):!0}function sn(e){let n=e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0);return!!n?.supports?.("corner-top-left-shape","bevel")&&!!n.supports("corner-top-right-shape","bevel")&&!!n.supports("corner-bottom-right-shape","bevel")&&!!n.supports("corner-bottom-left-shape","bevel")}function rs(e){let n=e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0);return!!n?.supports?.("corner-top-left-shape","bevel")&&!!n.supports("corner-top-right-shape","bevel")}function is(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function at(e,n){return n?.disable?.includes("u")?null:rs(e)?"corner-bevel":br(e)?is(e)?"border-large":"border":null}function ln(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,J.safariCssProjectiveUnsupported)(t):!0}function Yn(e,n,t,o,r){let i=new Set(o?.disable??[]);return(0,J.getSolidPaintDefaultsForPlansCore)(e,n,i,{solidTriangleSupported:br(t),projectiveQuadSupported:ln(t),cornerShapeSupported:sn(t),borderShapeSupported:rn(t)},Gn.parseHex,Gn.rgbKey,r)}var dt=require("@layoutit/polycss-core"),nt=require("@layoutit/polycss-core");var Bt=require("@layoutit/polycss-core");var ht=require("@layoutit/polycss-core"),vr=require("@layoutit/polycss-core");var Ft=require("@layoutit/polycss-core");function Ve(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=new RegExp(`(^|;)\\s*${i}\\s*:[^;]*`,"i"),c=l.test(o)?o.replace(l,(a,m)=>`${m}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;c!==o&&e.setAttribute("style",c)}function Pt(e,n){let t=e.getAttribute("style")??"";if(!t||!t.toLowerCase().includes(n.toLowerCase()))return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`^\\s*${o}\\s*:`,"i"),i=t.split(";").map(l=>l.trim()).filter(l=>l&&!r.test(l)).join(";");i?e.setAttribute("style",i):e.removeAttribute("style")}function an(e,n,t,o=!1){if(n==="dynamic"){let r=(0,Ft.parseHex)(e.polygon.color??"#cccccc"),i=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return(0,Ft.rgbKey)(r)!==t?.dynamicColorKey&&(i+=`;--psr:${(r.r/255).toFixed(4)};--psg:${(r.g/255).toFixed(4)};--psb:${(r.b/255).toFixed(4)}`),i}return e.shadedColor&&e.shadedColor!==t?.paintColor?`;color:${e.shadedColor}`:""}function ss(e,n){Ve(e,"--pnx",n.normal[0].toFixed(4)),Ve(e,"--pny",n.normal[1].toFixed(4)),Ve(e,"--pnz",n.normal[2].toFixed(4))}function Ht(e,n,t,o){if(t==="dynamic"){Pt(e,"color"),Pt(e,"background"),ss(e,n);let r=(0,Ft.parseHex)(n.polygon.color??"#cccccc");(0,Ft.rgbKey)(r)===o?.dynamicColorKey?(Pt(e,"--psr"),Pt(e,"--psg"),Pt(e,"--psb")):(Ve(e,"--psr",(r.r/255).toFixed(4)),Ve(e,"--psg",(r.g/255).toFixed(4)),Ve(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(Pt(e,"background"),Ve(e,"color",n.shadedColor)):(Pt(e,"background"),Pt(e,"color"))}var It=require("@layoutit/polycss-core"),gt=require("@layoutit/polycss-core"),jn=require("@layoutit/polycss-core"),ut=require("@layoutit/polycss-core"),To=new WeakMap,Ao=new WeakMap;function ze(e,n){let t=To.get(e),o=Ao.get(e);if(!n.data&&(!t||t.length===0)){e.__polycssHasDataAttrs=!1;return}let r=new Map;if(n.data)for(let[l,c]of Object.entries(n.data))r.set(l,String(c));if(t)for(let l of t)r.has(l)||e.removeAttribute(`data-${l}`);for(let[l,c]of r)o?.get(l)!==c&&e.setAttribute(`data-${l}`,c);let i=Array.from(r.keys());i.length>0?To.set(e,i):To.delete(e),r.size>0?Ao.set(e,r):Ao.delete(e),e.__polycssHasDataAttrs=i.length>0}function Vt(e){return e.__polycssHasDataAttrs===!0}function Mo(e,n,t,o,r=t==="dynamic"){if(!n.url)return;let i=`url(${n.url})`,l=o.canvasW||1,c=o.canvasH||1,a=(0,gt.atlasCanonicalSizeForEntry)(o),m=`${(0,ht.formatCssLength)(-o.x/l*a)} ${(0,ht.formatCssLength)(-o.y/c*a)}`,f=`${(0,ht.formatCssLength)(n.width/l*a)} ${(0,ht.formatCssLength)(n.height/c*a)}`,h=`transform:matrix3d(${o.atlasMatrix});--polycss-atlas-size:${a}px`,g=`${h};--polycss-atlas-position:${m};--polycss-atlas-image-size:${f}`;if(t==="dynamic"){let x=r?`;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`:"";e.setAttribute("style",g+`;--polycss-atlas-url:${i}`+x)}else e.setAttribute("style",h+`;background:${i} ${m} / ${f} no-repeat`)}function xr(e,n,t,o){if(n.texture){if(!t.texture||n.texture!==t.texture)return!1}else if(t.texture)return!1;let r=Pr(n,t);return r?(e.style.visibility="",Ve(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(Ve(e,"--pnx",r.normal[0].toFixed(4)),Ve(e,"--pny",r.normal[1].toFixed(4)),Ve(e,"--pnz",r.normal[2].toFixed(4))),ze(e,t),!0):(e.style.visibility="hidden",ze(e,t),!0)}function wo(e,n,t,o,r){if(o!=="baked")return{...e,polygon:n,normal:t};let i=r.directionalLight,l=r.ambientLight,c=i?.direction??ut.DEFAULT_LIGHT_DIR,a=i?.color??ut.DEFAULT_LIGHT_COLOR,m=Math.max(0,i?.intensity??ut.DEFAULT_LIGHT_INTENSITY),f=l?.color??ut.DEFAULT_AMBIENT_COLOR,h=Math.max(0,l?.intensity??ut.DEFAULT_AMBIENT_INTENSITY),g=Math.hypot(c[0],c[1],c[2])||1,x=c[0]/g,y=c[1]/g,P=c[2]/g,v=m*Math.max(0,t[0]*x+t[1]*y+t[2]*P);return{...e,polygon:n,normal:t,shadedColor:(0,vr.shadePolygon)(n.color??"#cccccc",v,a,f,h)}}function Pr(e,n){let t=Sr(e,n);if(!t)return null;let{normal:o,xAxis:r,yAxis:i,tx:l,ty:c,tz:a}=t;return{normal:o,matrix:(0,ht.formatMatrix3dValues)([r[0]*e.canvasW/(0,gt.atlasCanonicalSizeForEntry)(e),r[1]*e.canvasW/(0,gt.atlasCanonicalSizeForEntry)(e),r[2]*e.canvasW/(0,gt.atlasCanonicalSizeForEntry)(e),0,i[0]*e.canvasH/(0,gt.atlasCanonicalSizeForEntry)(e),i[1]*e.canvasH/(0,gt.atlasCanonicalSizeForEntry)(e),i[2]*e.canvasH/(0,gt.atlasCanonicalSizeForEntry)(e),0,o[0],o[1],o[2],0,l,c,a,1])}}var Sr=jn.stableBasisFromPlan;function ls(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=Sr(e,n);if(!o)return null;let r=(0,jn.computeProjectiveQuadMatrix)(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return r?{matrix:r,normal:o.normal}:null}function Lo(e,n,t,o,r=!1){let i=t.createElement("b");return i.setAttribute("style",`transform:matrix3d(${(0,ht.formatSolidQuadMatrix)(e)})`+an(e,n,o,r)),ze(i,e.polygon),i}function _o(e,n,t,o,r=!1){let i=t.createElement("i");return i.setAttribute("style",(0,It.formatBorderShapeElementStyle)(e)+an(e,n,o,r)),ze(i,e.polygon),i}function Ro(e,n,t,o,r,i=!1){let l=o.createElement("u");return l.setAttribute("style",(0,It.formatCornerShapeElementStyle)(e,n)+an(e,t,r,i)),ze(l,e.polygon),l}function Do(e,n,t,o,r=!1){let i=t.createElement("b");return i.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+an(e,n,o,r)),ze(i,e.polygon),i}function Cr(e,n,t,o,r,i,l){let c=n.projectiveMatrix?ls(n,t,i):Pr(n,t);if(!c)return!1;let a=wo(n,t,c.normal,o,r);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,Ht(e,a,o,l),ze(e,a.polygon),!0}function Er(e,n,t,o){e.style.visibility="",e.setAttribute("style",(0,It.formatBorderShapeElementStyle)(n)),Ht(e,n,t,o),ze(e,n.polygon)}function Tr(e,n,t,o,r){e.style.visibility="",e.setAttribute("style",(0,It.formatCornerShapeElementStyle)(n,t)),Ht(e,n,o,r),Ve(e,"background","currentColor"),ze(e,n.polygon)}function ko(e,n,t,o=!1){let r=t.createElement("s"),i=(0,gt.atlasCanonicalSizeForEntry)(e),l=n==="dynamic"&&!o?`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`:"";return r.setAttribute("style",`transform:matrix3d(${e.atlasMatrix});--polycss-atlas-size:${i}px;opacity:0`+l),ze(r,e.polygon),r}var kr=require("@layoutit/polycss-core");var Xn=require("@layoutit/polycss-core");function Mt(e,n,t,o={}){let r=o.primitive!=null?void 0:(()=>{let i=t.doc??(typeof document<"u"?document:null);return i?at(i,t.strategies)??"border":"border"})();return(0,Xn.computeSolidTrianglePlan)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??r})}function Oo(e,n,t,o,r,i,l,c,a,m,f,h,g){let x=o.primitive!=null?void 0:(()=>{let y=t.doc??(typeof document<"u"?document:null);return y?at(y,t.strategies)??"border":"border"})();return(0,Xn.computeSolidTrianglePlanFromCssPoints)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??x},r,i,l,c,a,m,f,h,g)}var wt=require("@layoutit/polycss-core"),St=require("@layoutit/polycss-core"),Ar=require("@layoutit/polycss-core");var Fo=require("@layoutit/polycss-core");var as=1.5;function Mr(e,n){return(0,wt.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function wr(e,n,t){return n?{...t,seamBleed:n.has(e)?as:void 0,seamEdges:n.get(e)}:t}function Ho(e){return{updatesDisabled:e.stableTriangleColorFreezeFrames===0,freezeFrames:Math.max(1,Math.floor(e.stableTriangleColorFreezeFrames??1)),colorFrame:Math.max(0,Math.floor(e.stableTriangleColorFrame??0)),maxStep:Math.max(0,Math.floor(e.stableTriangleColorMaxStep??0))}}function Lr(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function zt(e,n,t,o,r,i){return t?i.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:r==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:Lr(n,i):!0}function Io(e,n){let t=e;t.__polycssSolidTrianglePrimitive!==n&&(e.classList.toggle(wt.SOLID_TRIANGLE_CORNER_CLASS,n==="corner-bevel"),e.classList.toggle(wt.SOLID_TRIANGLE_LARGE_BORDER_CLASS,n==="border-large"),t.__polycssSolidTrianglePrimitive=n)}function Vo(e){let n=e;n.__polycssSolidTriangleHidden&&(e.style.visibility="",n.__polycssSolidTriangleHidden=!1)}function cn(e){let n=e;n.__polycssSolidTriangleHidden||(e.style.visibility="hidden",n.__polycssSolidTriangleHidden=!0)}function Wn(e,n){e.setAttribute("style",n.styleText),Io(e,n.primitive);let t=e;t.__polycssSolidTriangleBasis=n.basis,t.__polycssSolidTriangleHidden=!1,n.colorComputed&&(t.__polycssSolidTriangleColor=n.bakedColor??"",t.__polycssSolidTriangleColorRgb=n.bakedRgb,t.__polycssSolidTriangleColorAlpha=n.bakedAlpha),t.__polycssSolidTriangleColorFrame=void 0,(n.polygon.data||Vt(e))&&ze(e,n.polygon)}function _r(e,n,t,o){if(!n.colorComputed){(n.polygon.data||Vt(e))&&ze(e,n.polygon);return}let r=e,i=n.bakedColor??"",l=n.bakedRgb,c=n.bakedAlpha??1,a=r.__polycssSolidTriangleColor,m=r.__polycssSolidTriangleColorRgb,f=r.__polycssSolidTriangleColorAlpha??1,h=o??Lr(n.index,t);if(!t.updatesDisabled&&a!==i&&(a===void 0||h)){let g=i,x=l;if(t.maxStep>0&&m&&l&&f===c){let y=(0,St.stepRgbToward)(m,l,t.maxStep);x=y,g=(0,St.rgbToCss)(y,c)}(g!==a||!(0,St.rgbEqual)(x,m))&&(e.style.color=g),r.__polycssSolidTriangleColor=g,r.__polycssSolidTriangleColorRgb=x,r.__polycssSolidTriangleColorAlpha=c,r.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||Vt(e))&&ze(e,n.polygon)}function Zn(e,n,t,o){let r=e;Io(e,n.primitive),r.__polycssSolidTriangleBasis!==n.basis&&(r.__polycssSolidTriangleBasis=n.basis),Vo(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||Vt(e))&&_r(e,n,t,o)}function zo(e,n,t,o){Vo(e),_r(e,n,t,o)}function Qn(e,n){let t=e;Io(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),Vo(e),e.style.transform=n.transformText,(n.polygon.data||Vt(e))&&ze(e,n.polygon)}function cs(e,n){let t=n.stableTriangleColorBudget;if(typeof t=="number"&&Number.isFinite(t)&&t>0)return t<=1?Math.max(1,Math.ceil(e*t)):Math.max(1,Math.floor(t));let o=Math.max(1,Math.floor(n.stableTriangleColorFreezeFrames??1));return Math.max(1,Math.ceil(e/o))}function Rr(e,n,t){if(t.stableTriangleColorPolicy!=="adaptive")return null;if(t.stableTriangleColorFreezeFrames===0)return new Set;let o=Math.max(0,Math.floor(t.stableTriangleColorFrame??0)),r=Math.max(1,Math.floor(t.stableTriangleColorFreezeFrames??1));if(r<=1&&!Number.isFinite(t.stableTriangleColorBudget))return null;let i=cs(e.length,t),l=Math.max(1,Math.floor(t.stableTriangleColorMaxAge??Math.max(2,r*2))),c=[];for(let a=0;a<e.length;a++){let m=e[a],f=n[a];if(m.kind!=="triangle"||!f)continue;let h=m.element,g=h.__polycssSolidTriangleColor,x=f.bakedColor??"";if(g===x)continue;let y=h.__polycssSolidTriangleColorFrame??0,P=Math.max(0,o-y),v=(0,St.colorErrorScore)(g,x);c.push({index:a,score:(P>=l?1e6:0)+v*1e4+P})}return c.length===0?new Set:(c.sort((a,m)=>m.score-a.score),new Set(c.slice(0,i).map(a=>a.index)))}function qn(e,n){let t=n.createElement("u");return Wn(t,e),t}function us(e,n){let t=n.createElement("u");return cn(t),e.data&&ze(t,e),t}function Dr(e,n,t,o,r,i){let l=t,c=l.stableTriangleDebug,a=o&&r==="color-only";if(l.stableTriangleColorPolicy==="adaptive"||e.length!==n.length)return!1;let m=(0,Fo.stableTriangleMatrixDecimals)(l.stableTriangleMatrixDecimals),f=t.doc??(typeof document<"u"?document:null),h=f?at(f,t.strategies)??"border":"border";for(let x=0;x<e.length;x++){let y=e[x];if(y.kind!=="triangle"||y.polygonIndex!==x||!n[x])return!1}let g=Mr(n,t);for(let x=0;x<e.length;x++){let y=e[x].element,P=n[x];if(a){if(zt(y,x,o,c,l.stableTriangleColorPolicy,i)){let E=(0,Ar.computeSolidTriangleColorPlan)(P,x,t);if(!E)continue;zo(y,E,i)}continue}let v=Mt(P,x,wr(x,g,t),{basis:y.__polycssSolidTriangleBasis,matrixDecimals:m,primitive:h,includeColor:r!=="plan-only"&&r!=="transform-only"&&zt(y,x,o,c,l.stableTriangleColorPolicy,i)});if(!v){cn(y);continue}o&&r==="plan-only"||(o&&r==="transform-only"?Qn(y,v):o?Zn(y,v,i):Wn(y,v))}return!0}function un(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=at(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let r=(0,Fo.stableTriangleMatrixDecimals)(n.stableTriangleMatrixDecimals),i=[],l=Mr(e,n);for(let c=0;c<e.length;c+=1){let a=e[c],m=Mt(a,c,wr(c,l,n),{matrixDecimals:r,primitive:o}),f=m?qn(m,t):us(a,t);i.push({polygonIndex:c,element:f,kind:"triangle",dispose:()=>{}})}return{rendered:i,dispose(){}}}var No=require("@layoutit/polycss-core"),Or=1.5;function Fr(){return new Promise(e=>setTimeout(e,0))}async function Bo(e){return performance.now()-e<dt.ASYNC_RENDER_BUDGET_MS?e:(await Fr(),performance.now())}function Hr(e,n){return e.seamBleedEdges?.size?{...n,seamBleed:Or,seamEdges:e.seamBleedEdges}:{...n,seamBleed:void 0,seamEdges:void 0}}function Ir(e,n){return(0,nt.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function Vr(e,n,t){return n?{...t,seamBleed:n.has(e)?Or:void 0,seamEdges:n.get(e)}:t}function Nt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=(0,nt.buildBasisHints)(e,n),r=Ot(t),i=e.map((l,c)=>(0,nt.computeTextureAtlasPlan)(l,c,n,r,o[c]));return Yn(i,n.textureLighting??"baked",t,n.strategies)}function dn(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=n,i=o==="dynamic"&&r.skipDynamicNormalVars===!0,l=new Set(n.strategies?.disable??[]),c=!l.has("b"),a=c&&ln(t),m=at(t,n.strategies),f=m!==null,h=!l.has("i")&&sn(t),g=!l.has("i")&&rn(t),x=(0,nt.buildBasisHints)(e,n),y=Ot(t),P=Ir(e,n),v=e.map((u,p)=>(0,nt.computeTextureAtlasPlan)(u,p,Vr(p,P,n),y,x[p])),E=n.solidPaintDefaults??(r.computeSolidPaintDefaults?Yn(v,o,t,n.strategies):void 0),H=E?{...n,solidPaintDefaults:E}:n,k=v.map(u=>u&&f&&(0,J.isSolidTrianglePlan)(u)?Mt(u.polygon,u.index,Hr(u,H),{primitive:m??void 0}):null),N=v.map(u=>u&&h&&!(0,J.isSolidTrianglePlan)(u)&&!(c&&(0,J.isFullRectSolid)(u))&&!(a&&(0,J.isProjectiveQuadPlan)(u))?(0,Bt.cornerShapeGeometryForPlan)(u):null),R=v.map((u,p)=>u&&(u.texture||!(c&&(0,J.isFullRectSolid)(u))&&!k[p]&&!(a&&(0,J.isProjectiveQuadPlan)(u))&&!N[p]&&!g?u:null)),{packed:ee,atlasScale:z}=nn(R,n.textureQuality,t),O=new Map,$=[],U=!1,le=[];for(let u=0;u<e.length;u++){let p=v[u],C=k[u],A=N[u];if(!p)continue;let w=ee.entries[u];if(w){let M=ko(w,o,t,i);O.set(u,M),$.push({polygonIndex:u,element:M,kind:"atlas",plan:w,dispose:()=>{}})}else if(!p.texture&&c&&(0,J.isFullRectSolid)(p)){let M=Lo(p,o,t,E,i);$.push({polygonIndex:u,element:M,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&C){let M=qn(C,t);$.push({polygonIndex:u,element:M,kind:"triangle",plan:p,dispose:()=>{}})}else if(!p.texture&&a&&(0,J.isProjectiveQuadPlan)(p)){let M=Do(p,o,t,E,i);$.push({polygonIndex:u,element:M,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&A){let M=Ro(p,A,o,t,E,i);$.push({polygonIndex:u,element:M,kind:"corner",plan:p,dispose:()=>{}})}else if(!p.texture&&g){let M=_o(p,o,t,E,i);$.push({polygonIndex:u,element:M,kind:"border",plan:p,dispose:()=>{}})}}return $.sort((u,p)=>u.polygonIndex-p.polygonIndex),on(ee.pages,o,t,z,()=>U).then(u=>{if(U){for(let p of u)p.url?.startsWith("blob:")&&URL.revokeObjectURL(p.url);return}le=u.flatMap(p=>p.url?.startsWith("blob:")?[p.url]:[]);for(let p=0;p<ee.pages.length;p++){let C=ee.pages[p],A=u[p];if(A)for(let w of C.entries){let M=O.get(w.index);!M||!A.url||Mo(M,A,o,w,!i)}}}).catch(()=>{if(!U)for(let u of O.values())Ve(u,"opacity","0.5"),Ve(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:$,solidPaintDefaults:E??{},dispose(){U=!0;for(let u of le)URL.revokeObjectURL(u);le=[]}}}async function Kn(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",l=r==="dynamic"&&n.skipDynamicNormalVars===!0,c=new Set(n.strategies?.disable??[]),a=!c.has("b"),m=a&&ln(o),f=at(o,n.strategies),h=f!==null,g=!c.has("i")&&sn(o),x=!c.has("i")&&rn(o);if(await Fr(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let y=(0,nt.buildBasisHints)(e,n),P=Ot(o),v=Ir(e,n),E=performance.now(),H=new Array(e.length);for(let u=0;u<e.length;u++)if(H[u]=(0,nt.computeTextureAtlasPlan)(e[u],u,Vr(u,v,n),P,y[u]),E=await Bo(E),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let k=n.solidPaintDefaults??Yn(H,r,o,n.strategies),N=new Array(H.length),R=new Array(H.length),ee=new Array(H.length);for(let u=0;u<H.length;u++){let p=H[u],C=p&&h&&(0,J.isSolidTrianglePlan)(p)?Mt(p.polygon,p.index,Hr(p,{...n,solidPaintDefaults:k}),{primitive:f??void 0}):null;N[u]=C;let A=p&&g&&!(0,J.isSolidTrianglePlan)(p)&&!(a&&(0,J.isFullRectSolid)(p))&&!(m&&(0,J.isProjectiveQuadPlan)(p))?(0,Bt.cornerShapeGeometryForPlan)(p):null;if(R[u]=A,ee[u]=p&&(p.texture||!(a&&(0,J.isFullRectSolid)(p))&&!C&&!(m&&(0,J.isProjectiveQuadPlan)(p))&&!A&&!x?p:null),E=await Bo(E),t())return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}let{packed:z,atlasScale:O}=nn(ee,n.textureQuality,o),$=new Map,U=[],le=!1,Ce=[];for(let u=0;u<e.length;u++){let p=H[u],C=N[u],A=R[u];if(!p)continue;let w=z.entries[u];if(w){let M=ko(w,r,o,l);$.set(u,M),U.push({polygonIndex:u,element:M,kind:"atlas",plan:w,dispose:()=>{}})}else if(!p.texture&&a&&(0,J.isFullRectSolid)(p)){let M=Lo(p,r,o,k,l);U.push({polygonIndex:u,element:M,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&C){let M=qn(C,o);U.push({polygonIndex:u,element:M,kind:"triangle",plan:p,dispose:()=>{}})}else if(!p.texture&&m&&(0,J.isProjectiveQuadPlan)(p)){let M=Do(p,r,o,k,l);U.push({polygonIndex:u,element:M,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&A){let M=Ro(p,A,r,o,k,l);U.push({polygonIndex:u,element:M,kind:"corner",plan:p,dispose:()=>{}})}else if(!p.texture&&x){let M=_o(p,r,o,k,l);U.push({polygonIndex:u,element:M,kind:"border",plan:p,dispose:()=>{}})}if(E=await Bo(E),t()){for(let M of U)M.dispose();return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}}return U.sort((u,p)=>u.polygonIndex-p.polygonIndex),on(z.pages,r,o,O,()=>le||t()).then(u=>{if(le||t()){for(let p of u)p.url?.startsWith("blob:")&&URL.revokeObjectURL(p.url);return}Ce=u.flatMap(p=>p.url?.startsWith("blob:")?[p.url]:[]);for(let p=0;p<z.pages.length;p++){let C=z.pages[p],A=u[p];if(A)for(let w of C.entries){let M=$.get(w.index);!M||!A.url||Mo(M,A,r,w,!l)}}}).catch(()=>{if(!(le||t()))for(let u of $.values())Ve(u,"opacity","0.5"),Ve(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:U,solidPaintDefaults:k,dispose(){le=!0;for(let u of Ce)URL.revokeObjectURL(u);Ce=[]}}}function Jn(e,n,t,o={}){let r=o.textureLighting??"baked",i=o,l=i.optimizeStableTriangleStyle===!0&&r==="baked";if(!l||i.stableTriangleColorPolicy==="adaptive"||e.length!==t.polygonCount||n.length!==t.polygonCount||t.vertices.length<t.polygonCount*9)return!1;let c=i.stableTriangleDebug,a=i.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full");if(a==="color-only")return!1;let m=(0,No.stableTriangleMatrixDecimals)(i.stableTriangleMatrixDecimals),f=Ho(i),h=o.tileSize??dt.DEFAULT_TILE,g=o.layerElevation??h,x=o.doc??(typeof document<"u"?document:null),y=x?at(x,o.strategies)??"border":"border";for(let v=0;v<e.length;v++){let E=e[v],H=n[v];if(E.kind!=="triangle"||E.polygonIndex!==v||!H||H.vertices.length!==3||H.texture||H.material?.texture)return!1}let P=t.vertices;for(let v=0;v<e.length;v++){let E=e[v].element,H=n[v],k=v*9,N=P[k+1]*h,R=P[k]*h,ee=P[k+2]*g,z=P[k+4]*h,O=P[k+3]*h,$=P[k+5]*g,U=P[k+7]*h,le=P[k+6]*h,Ce=P[k+8]*g,u=Oo(H,v,o,{basis:E.__polycssSolidTriangleBasis,matrixDecimals:m,primitive:y,color:t.colors?.[v],includeColor:a!=="plan-only"&&a!=="transform-only"&&zt(E,v,l,c,i.stableTriangleColorPolicy,f)},N,R,ee,z,O,$,U,le,Ce);if(!u){cn(E);continue}a!=="plan-only"&&(a==="transform-only"?Qn(E,u):Zn(E,u,f))}return!0}function eo(e,n,t={}){if(e.length!==n.length)return!1;let o=t.doc??(typeof document<"u"?document:null),r=t.textureLighting??"baked",i=new Set(t.strategies?.disable??[]),l=!i.has("b"),c=!!o&&l&&ln(o),a=!!o&&!i.has("i")&&sn(o),m=!!o&&!i.has("i")&&rn(o),f=o?Ot(o):{denomEps:dt.PROJECTIVE_QUAD_DENOM_EPS,maxWeightRatio:dt.PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,bleed:dt.PROJECTIVE_QUAD_BLEED,disableGuards:!1},h=t.optimizeStableTriangleStyle===!0&&r==="baked",g=t,x=g.stableTriangleDebug,y=g.stableTriangleUpdateMode??(x==="plan-only"||x==="transform-only"?x:"full"),P=h&&y==="color-only",v=Ho(g),E=(0,No.stableTriangleMatrixDecimals)(g.stableTriangleMatrixDecimals),H=o?at(o,t.strategies)??"border":"border";if(Dr(e,n,t,h,y,v))return!0;let k=[],N=[],R=[];for(let z=0;z<e.length;z++){let O=e[z];if(O.polygonIndex!==z)return!1;let $=n[z];if(!$||P&&O.kind!=="triangle")return!1;if(O.kind==="atlas"){if(!O.plan||!xr(O.element,O.plan,$,r))return!1;continue}if(O.kind==="triangle"){let U=O.element;if(P){let Ce=g.stableTriangleColorPolicy==="adaptive"||zt(U,z,h,x,g.stableTriangleColorPolicy,v);N[z]=Ce?(0,kr.computeSolidTriangleColorPlan)($,z,t):null;continue}let le=Mt($,z,t,{basis:U.__polycssSolidTriangleBasis,matrixDecimals:E,primitive:H,includeColor:y!=="plan-only"&&y!=="transform-only"&&zt(U,z,h,x,g.stableTriangleColorPolicy,v)});if(!le){k[z]=null;continue}k[z]=le;continue}if(O.kind==="solid"){if(!O.plan||$.texture||$.vertices.length!==O.plan.polygon.vertices.length)return!1;R[z]=O.plan;continue}if(O.kind==="border"){let U=(0,nt.computeTextureAtlasPlan)($,z,t,f);if(!U||U.texture||!m||l&&(0,J.isFullRectSolid)(U)||c&&(0,J.isProjectiveQuadPlan)(U)||a&&(0,Bt.cornerShapeGeometryForPlan)(U))return!1;R[z]=U;continue}if(O.kind==="corner"){let U=(0,nt.computeTextureAtlasPlan)($,z,t,f);if(!U||U.texture||!a||(0,J.isSolidTrianglePlan)(U)||l&&(0,J.isFullRectSolid)(U)||c&&(0,J.isProjectiveQuadPlan)(U)||!(0,Bt.cornerShapeGeometryForPlan)(U))return!1;R[z]=U;continue}return!1}let ee=h&&y!=="plan-only"&&y!=="transform-only"?Rr(e,P?N:k,g):null;for(let z=0;z<e.length;z++){let O=e[z];if(O.kind==="triangle"){if(P){let U=N[z];U&&zo(O.element,U,v,ee?.has(z));continue}let $=k[z];if(!$){cn(O.element);continue}if(h&&y==="plan-only")continue;h&&y==="transform-only"?Qn(O.element,$):h?Zn(O.element,$,v,ee?.has(z)):Wn(O.element,$)}else if(O.kind==="solid"){let $=R[z];if(!$||!Cr(O.element,$,n[z],r,t,f,g.solidPaintDefaults))return!1}else if(O.kind==="border"){let $=R[z];if(!$)return!1;Er(O.element,$,r,g.solidPaintDefaults)}else if(O.kind==="corner"){let $=R[z],U=$?(0,Bt.cornerShapeGeometryForPlan)($):null;if(!$||!U)return!1;Tr(O.element,$,U,r,g.solidPaintDefaults)}}return!0}var zr=require("@layoutit/polycss-core"),$t=require("@layoutit/polycss-core"),to=require("@layoutit/polycss-core");var ce=require("@layoutit/polycss-core"),hs=[.4,-.7,.59],ys="#ffffff",bs=1,vs="#ffffff",xs=.4,Yr=1,Ps=8,Ss=ce.PROJECTIVE_QUAD_BLEED,yt=1e-6,Cs=(0,ce.resolveProjectiveQuadGuards)({bleed:0}),jr={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},Go=["t","b","bl","br","fr","fl"],Es=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 Br(e){let n=[];for(let t of Go)(0,ce.normalFacesCamera)(jr[t],e)&&n.push(t);return n.join("|")}function Ts(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 As(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,i=0;for(let c=1;c+1<n.length;c+=1){let a=n[c],m=n[c+1],f=a[1]-t[1],h=a[0]-t[0],g=a[2]-t[2],x=m[1]-t[1],y=m[0]-t[0],P=m[2]-t[2];o-=h*P-g*y,r-=g*x-f*P,i-=f*y-h*x}let l=Math.hypot(o,r,i);return l<=1e-9?null:[Math.round(o/l),Math.round(r/l),Math.round(i/l)]}function Ms(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=As(e),t=n?Es.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,i=1/0,l=-1/0,c=-1/0,a=-1/0;for(let h of e.vertices)o=Math.min(o,h[0]),r=Math.min(r,h[1]),i=Math.min(i,h[2]),l=Math.max(l,h[0]),c=Math.max(c,h[1]),a=Math.max(a,h[2]);let m=1e-6,f=ks(e.color);return Math.abs(a-i)<=m?{axis:"z",face:t,left:r*ce.BASE_TILE,top:o*ce.BASE_TILE,width:Math.max(0,(c-r)*ce.BASE_TILE),height:Math.max(0,(l-o)*ce.BASE_TILE),z:i*ce.BASE_TILE,baseColor:f,bleed:Uo()}:Math.abs(l-o)<=m?{axis:"x",face:t,left:r*ce.BASE_TILE,top:i*ce.BASE_TILE,width:Math.max(0,(c-r)*ce.BASE_TILE),height:Math.max(0,(a-i)*ce.BASE_TILE),z:-o*ce.BASE_TILE,baseColor:f,bleed:Uo()}:Math.abs(c-r)<=m?{axis:"y",face:t,left:i*ce.BASE_TILE,top:o*ce.BASE_TILE,width:Math.max(0,(a-i)*ce.BASE_TILE),height:Math.max(0,(l-o)*ce.BASE_TILE),z:-r*ce.BASE_TILE,baseColor:f,bleed:Uo()}:null}function Uo(){return{left:0,right:0,top:0,bottom:0}}function ws(e){let n=o=>String(Number(o.toFixed(6))),t=`${e.item.baseColor}|${e.variableAxis}`;for(let o=0;o<3;o+=1)o!==e.variableAxis&&(t+=`|${o}:${n(e.fixed[o])}`);return t}function Nr(e){return[e[1]*ce.BASE_TILE,e[0]*ce.BASE_TILE,e[2]*ce.BASE_TILE]}function Ur(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function Ls(e,n,t){let o=e.left,r=e.left+e.width,i=e.top,l=e.top+e.height;if(Math.abs(n[0]-t[0])<=yt){if(Math.abs(n[0]-o)<=yt)return"left";if(Math.abs(n[0]-r)<=yt)return"right"}if(Math.abs(n[1]-t[1])<=yt){if(Math.abs(n[1]-i)<=yt)return"top";if(Math.abs(n[1]-l)<=yt)return"bottom"}return null}function _s(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=yt)){if(t!==null)return null;t=o}return t}function Rs(e,n,t){let o=n.vertices,r=Nr(o[t]),i=Nr(o[(t+1)%o.length]),l=Ls(e,Ur(e,r),Ur(e,i));if(!l)return null;let c=_s(r,i);if(c===null)return null;let a=Math.min(r[c],i[c]),m=Math.max(r[c],i[c]);return m-a>yt?{item:e,side:l,variableAxis:c,fixed:r,start:a,end:m}:null}function $r(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],Ss)}function Ds(e,n){let t=new Map;for(let o of n){let r=e[o.sourceIndex];if(r)for(let i=0;i<r.vertices.length;i+=1){let l=Rs(o,r,i);if(!l)continue;let c=ws(l),a=t.get(c);a?a.push(l):t.set(c,[l])}}for(let o of t.values()){if(o.length<2)continue;o.sort((i,l)=>i.start-l.start||i.end-l.end);let r=[];for(let i of o){r=r.filter(l=>l.end>i.start+yt);for(let l of r)l.item.sourceIndex!==i.item.sourceIndex&&($r(l),$r(i));r.push(i)}}}function $o(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 ks(e){if(!e)return"#cccccc";let n=(0,ce.parsePureColor)(e);if(!n)return e;let t={r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha};if(t.alpha<1){let o=Math.round(Math.max(0,t.alpha)*1e3)/1e3;return`rgba(${Gt(t.r)}, ${Gt(t.g)}, ${Gt(t.b)}, ${o})`}return Xr(t)}function Xr({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 Gt(e){return Math.round(Math.max(0,Math.min(255,e)))}function Os(e,n,t,o){let r=$o(n),i=$o(t?.color??ys),l=$o(o?.color??vs),c=t?.direction??hs,a=Math.hypot(c[0],c[1],c[2])||1,m=c[0]/a,f=c[1]/a,h=c[2]/a,g=Math.max(0,t?.intensity??bs)*Math.max(0,e[0]*m+e[1]*f+e[2]*h),x=Math.max(0,o?.intensity??xs),y=l.r/255*x+i.r/255*g,P=l.g/255*x+i.g/255*g,v=l.b/255*x+i.b/255*g,E={r:r.r*y,g:r.g*P,b:r.b*v,alpha:r.alpha};return E.alpha<1?`rgba(${Gt(E.r)}, ${Gt(E.g)}, ${Gt(E.b)}, ${E.alpha})`:Xr(E)}function Fs(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=Ms(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return Ds(e,n),n}function Hs(e){return e.axis==="x"?{xAxis:[1,0,0],yAxis:[0,0,1],normal:[0,-1,0],tx:0,ty:-e.z,tz:0}:e.axis==="y"?{xAxis:[0,0,1],yAxis:[0,1,0],normal:[-1,0,0],tx:-e.z,ty:0,tz:0}:{xAxis:[1,0,0],yAxis:[0,1,0],normal:[0,0,1],tx:0,ty:0,tz:e.z}}function Is(e){let n=e.left,t=e.top,o=e.left+e.width,r=e.top+e.height;return[n,t,o,t,o,r,n,r]}function Vs(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function zs(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(r=>!Number.isFinite(r)))return null;let o=ce.SOLID_QUAD_CANONICAL_SIZE/n;for(let r=0;r<8;r+=1)t[r]*=o;return`matrix3d(${t.map(r=>Number(r.toFixed(6))).join(",")})`}function Gr(e,n){let t=e.left-e.bleed.left,o=e.top-e.bleed.top,r=e.width+e.bleed.left+e.bleed.right,i=e.height+e.bleed.top+e.bleed.bottom,l=e.z,c=r/n,a=i/n;return`matrix3d(${(e.axis==="x"?[c,0,0,0,0,0,a,0,0,-1,0,0,t,-l,o,1]:e.axis==="y"?[0,0,c,0,0,a,0,0,-1,0,0,0,-l,o,t,1]:[c,0,0,0,0,a,0,0,0,0,1,0,t,o,l,1]).map(f=>Number(f.toFixed(6))).join(",")})`}function Bs(e,n){let{xAxis:t,yAxis:o,normal:r,tx:i,ty:l,tz:c}=Hs(e),a=(0,ce.computeProjectiveQuadMatrix)(Is(e),t,o,r,i,l,c,Cs,Vs(e));return a?zs(a,n)??Gr(e,n):Gr(e,n)}function Ns(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function Us(e){return Ns(e)?Ps:Yr}function $s(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 Gs(e,n){let t=$s(e),o=n.meshRotation;o&&(t=(0,ce.rotateVec3)(t,o[0]??0,o[1]??0,o[2]??0));let[r,i]=(0,ce.rotateVec3)(t,n.rotX,0,n.rotY);return{x:r,y:i}}function Ys(e,n,t){let o=e.filter(g=>n.has(g.face)).map(g=>({item:g,...Gs(g,t)}));if(o.length===0)return[];let r=1/0,i=-1/0,l=1/0,c=-1/0;for(let g of o)r=Math.min(r,g.x),i=Math.max(i,g.x),l=Math.min(l,g.y),c=Math.max(c,g.y);let a=4,m=Math.max(1e-6,i-r),f=Math.max(1e-6,c-l),h=new Map;for(let g of o){let x=Math.min(a-1,Math.max(0,Math.floor((g.x-r)/m*a))),y=Math.min(a-1,Math.max(0,Math.floor((g.y-l)/f*a))),P=`${x}:${y}`,v=h.get(P);v||(v={tx:x,ty:y,sourceIndex:g.item.sourceIndex,items:[]},h.set(P,v)),v.items.push(g.item),v.sourceIndex=Math.min(v.sourceIndex,g.item.sourceIndex)}return Array.from(h.values()).sort((g,x)=>g.ty-x.ty||g.tx-x.tx||g.sourceIndex-x.sourceIndex).flatMap(g=>g.items)}function Wr(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:i}=e,l=Fs(o);if(l.length===0)return null;let c=new Set(l.map(u=>u.face));t.classList.add("polycss-voxel-mesh");let a=Us(n);a!==Yr&&t.style.setProperty("--polycss-voxel-primitive",`${a}px`);let m=new Map,f=(u,p)=>{let C=`${u}|${p}`,A=m.get(C);if(A)return A;let w=Os(jr[u],p,r,i);return m.set(C,w),w},h=new Map,g=new Map,x=new Map,y=new Map;for(let u of l){let p=y.get(u.face);p||(p=[],y.set(u.face,p)),p.push(u)}let P="",v=0,E=new Set,H=u=>{let p=h.get(u.sourceIndex);return p||(p=n.createElement("b"),h.set(u.sourceIndex,p),Ts(p,f(u.face,u.baseColor),Bs(u,a))),p},k=u=>{let p=g.get(u);return p||(p=n.createElement("span"),p.className=`polycss-voxel-face polycss-voxel-face-${u}`,p.dataset.polycssVoxelFace=u,p.__polycssVoxelFaceHost=!0,g.set(u,p)),p},N=()=>{for(let u of Array.from(t.childNodes))if(!u.__polycssVoxelFaceHost)return u;return null},R=(u,p)=>{let C=p.map(M=>M.sourceIndex).join(",");if(x.get(u)===C)return;let A=k(u),w=n.createDocumentFragment();for(let M of p)w.appendChild(H(M));A.replaceChildren(w),x.set(u,C)},ee=()=>{for(let u of Go)c.has(u)&&R(u,y.get(u)??[])},z=u=>new Set(u.split("|").filter(Boolean)),O=u=>{let p=z(u);return Go.filter(C=>p.has(C)&&c.has(C))},$=u=>{let p=0;for(let C of u)p+=y.get(C)?.length??0;return p},U=u=>{let p=new Set,C=[],A=new Map;for(let w of u){p.has(w.face)||(p.add(w.face),C.push(w.face));let M=A.get(w.face);M||(M=[],A.set(w.face,M)),M.push(w)}return{orderedFaces:C,itemsByFace:A}},le=(u,p)=>{let C=new Set(u);for(let A of E){if(C.has(A))continue;let w=g.get(A);w?.parentNode===t&&t.removeChild(w)}if(p){let A=n.createDocumentFragment();for(let w of u)A.appendChild(k(w));t.insertBefore(A,N()),E=C;return}for(let A=0;A<u.length;A+=1){let w=u[A],M=k(w);if(M.parentNode===t)continue;let ae=null;for(let ve=A+1;ve<u.length;ve+=1){let _=g.get(u[ve]);if(_?.parentNode===t){ae=_;break}}t.insertBefore(M,ae??N())}E=C},Ce=(u,p,C)=>{if(!C){let ve=O(u);le(ve,!1),v=$(ve);return}let A=new Set(u.split("|").filter(Boolean)),w=Ys(l,A,p),{orderedFaces:M,itemsByFace:ae}=U(w);for(let ve of M)R(ve,ae.get(ve)??[]);le(M,!0),v=w.length};return ee(),{get brushCount(){return v},render(u){P=Br(u),Ce(P,u,!0)},syncCamera(u){let p=Br(u);p!==P&&(P=p,Ce(p,u,!1))},dispose(){for(let u of g.values())u.remove();t.classList.remove("polycss-voxel-mesh"),t.style.removeProperty("--polycss-voxel-primitive"),h.clear(),g.clear(),x.clear(),v=0,E=new Set,P=""}}}var Zr="polycss-styles";function Qr(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(Zr))return;let t=n.createElement("style");t.id=Zr,t.textContent=js,n.head.appendChild(t)}var js=`
1
+ "use strict";var bo=Object.defineProperty;var as=Object.getOwnPropertyDescriptor;var ls=Object.getOwnPropertyNames;var cs=Object.prototype.hasOwnProperty;var ds=(e,n)=>{for(var t in n)bo(e,t,{get:n[t],enumerable:!0})},us=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of ls(n))!cs.call(e,r)&&r!==t&&bo(e,r,{get:()=>n[r],enumerable:!(o=as(n,r))||o.enumerable});return e};var ps=e=>us(bo({},"__esModule",{value:!0}),e);var Vl={};ds(Vl,{PolyAxesHelperElement:()=>cn,PolyBoxElement:()=>vn,PolyCameraElement:()=>gn,PolyConeElement:()=>wn,PolyCylinderElement:()=>Mn,PolyDirectionalLightHelperElement:()=>dn,PolyDodecahedronElement:()=>Tn,PolyFirstPersonControlsElement:()=>fn,PolyIcosahedronElement:()=>En,PolyIframeElement:()=>an,PolyMapControlsElement:()=>mn,PolyMeshElement:()=>xt,PolyOctahedronElement:()=>Sn,PolyOrbitControlsElement:()=>pn,PolyOrthographicCameraElement:()=>Pt,PolyPerspectiveCameraElement:()=>hn,PolyPlaneElement:()=>xn,PolyPolygonElement:()=>ln,PolyRingElement:()=>Pn,PolySceneElement:()=>_e,PolySelectElement:()=>bn,PolySphereElement:()=>An,PolyTetrahedronElement:()=>Cn,PolyTorusElement:()=>Ln,PolyTransformControlsElement:()=>yn});module.exports=ps(Vl);var ne=require("@layoutit/polycss-core");var rr=require("@layoutit/polycss-core");function ms(e){if(!e)return!1;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return t?t("(pointer: coarse)").matches||t("(hover: none)").matches:!1}function Qt(e,n,t){return(0,rr.packTextureAtlasPlansWithScaleCore)(e,n,ms(t))}var It=require("@layoutit/polycss-core");var ot=require("@layoutit/polycss-core"),dr=require("@layoutit/polycss-core"),ur=require("@layoutit/polycss-core"),Tt=new Map;function fs(e){let n=Tt.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.crossOrigin="anonymous",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),Tt.set(e,n),n.then(()=>{Tt.get(e)===n&&Tt.delete(e)},()=>{Tt.get(e)===n&&Tt.delete(e)})),n}function Ie(e,n,t=1,o=0,r=0,i=1,s=0,c=0){e.setTransform(t*n,o*n,r*n,i*n,s*n,c*n)}function vo(e){let n=e/255;return n<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function xo(e){let n=e<=.0031308?e*12.92:1.055*Math.pow(e,.4166666666666667)-.055;return Math.max(0,Math.min(255,Math.round(n*255)))}function hs(e,n,t,o,r,i,s){let c=Math.round(n*s),l=Math.round(t*s),p=Math.max(1,Math.round(o*s)),h=Math.max(1,Math.round(r*s)),x=e.getImageData(c,l,p,h),f=x.data,b=i.r,y=i.g,P=i.b;for(let v=0;v<f.length;v+=4)f[v+3]!==0&&(f[v]=xo(vo(f[v])*b),f[v+1]=xo(vo(f[v+1])*y),f[v+2]=xo(vo(f[v+2])*P));e.putImageData(x,c,l)}function gs(e,n,t,o,r,i,s){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,p=Math.max(r/c,i/l),h=c*p,x=l*p;Ie(e,s),e.drawImage(n,t+(r-h)/2,o+(i-x)/2,h,x)}function At(e,n){return Math.max(0,Math.min(n,e))}function ir(e,n,t,o,r,i,s,c){let l=n.naturalWidth||n.width||1,p=n.naturalHeight||n.height||1,h=At(Math.min(t.minU,t.maxU)*l,l),x=At(Math.max(t.minU,t.maxU)*l,l),f=At(Math.min(t.minV,t.maxV)*p,p),b=At(Math.max(t.minV,t.maxV)*p,p),y=Math.floor(h),P=Math.floor(f),v=Math.ceil(x)-y,C=Math.ceil(b)-P;v<1&&(y=Math.floor(At((t.minU+t.maxU)/2*l,l-1)),v=1),C<1&&(P=Math.floor(At((t.minV+t.maxV)/2*p,p-1)),C=1),y=Math.max(0,Math.min(l-1,y)),P=Math.max(0,Math.min(p-1,P)),v=Math.max(1,Math.min(l-y,v)),C=Math.max(1,Math.min(p-P,C)),Ie(e,c),e.drawImage(n,y,P,v,C,o,r,i,s)}function pr(e){return e==="repeat"||e==="mirrored-repeat"}function sr(e,n){return pr(e)?Math.floor(n):0}function ar(e,n){return pr(e)?Math.ceil(n)-1:0}function lr(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function cr(e,n,t,o,r,i,s){let c=r?sr(i,r.minU):0,l=r?ar(i,r.maxU):0,p=r?sr(s,r.minV):0,h=r?ar(s,r.maxV):0;for(let x=c;x<=l;x++)for(let f=p;f<=h;f++){let b=lr(i,x),y=lr(s,f);if(!b&&!y){e.drawImage(n,x*t,f*o);continue}e.save(),e.translate((b?x+1:x)*t,(y?f+1:f)*o),e.scale(b?-1:1,y?-1:1),e.drawImage(n,0,0),e.restore()}}function Po(e,n,t,o){for(let r=0;r<o.length;r+=2){let i=n+o[r],s=t+o[r+1];r===0?e.moveTo(i,s):e.lineTo(i,s)}e.closePath()}function kn(e,n,t,o,r,i){for(let s=0;s<o.length;s+=2){let c=n+o[s]+r,l=t+o[s+1]+i;s===0?e.moveTo(c,l):e.lineTo(c,l)}e.closePath()}function ys(e,n,t,o){Ie(e,o),e.beginPath(),Po(e,n.x,n.y,n.screenPts),e.clip(),Ie(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function Dn(e,n,t,o,r){n.polygon.textureAlphaMode==="opaque"&&(Ie(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+r,n.canvasW,n.canvasH))}function bs(e,n,t,o,r=0,i=0){if(n.textureTriangles?.length){let s=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1;for(let l of n.textureTriangles){let p=(0,dr.expandClipPoints)(l.screenPts,ot.TEXTURE_TRIANGLE_BLEED*(n.bleedRatio??1));e.save(),Ie(e,o),e.beginPath(),kn(e,n.x,n.y,p,r,i),e.clip(),Dn(e,n,o,r,i),l.uvAffine?(Ie(e,o,l.uvAffine.a/s,l.uvAffine.c/s,l.uvAffine.b/c,l.uvAffine.d/c,n.x+l.uvAffine.e+r,n.y+l.uvAffine.f+i),cr(e,t,s,c,l.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t)):l.uvSampleRect&&ir(e,t,l.uvSampleRect,n.x+r,n.y+i,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let s=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1,l=n.polygon.textureAlphaMode==="opaque";l&&(e.save(),Ie(e,o),e.beginPath(),kn(e,n.x,n.y,n.screenPts,r,i),e.clip(),Dn(e,n,o,r,i)),Ie(e,o,n.uvAffine.a/s,n.uvAffine.c/s,n.uvAffine.b/c,n.uvAffine.d/c,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+i),cr(e,t,s,c,n.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t),l&&e.restore()}else if(n.uvSampleRect){let s=n.polygon.textureAlphaMode==="opaque";s&&(e.save(),Ie(e,o),e.beginPath(),kn(e,n.x,n.y,n.screenPts,r,i),e.clip(),Dn(e,n,o,r,i)),ir(e,t,n.uvSampleRect,n.x+r,n.y+i,n.canvasW,n.canvasH,o),s&&e.restore()}else{let s=n.polygon.textureAlphaMode==="opaque";s&&(e.save(),Ie(e,o),e.beginPath(),kn(e,n.x,n.y,n.screenPts,r,i),e.clip(),Dn(e,n,o,r,i)),gs(e,t,n.x+r,n.y+i,n.canvasW,n.canvasH,o),s&&e.restore()}}function vs(e,n,t,o,r,i){let s=r-t,c=i-o,l=s*s+c*c;if(l<=ur.BASIS_EPS)return Math.hypot(e-t,n-o);let p=Math.max(0,Math.min(1,((e-t)*s+(n-o)*c)/l));return Math.hypot(e-(t+s*p),n-(o+c*p))}function xs(e,n,t,o){let r=1/0,i=t.length/2;for(let s of o){if(s<0||s>=i)continue;let c=s*2,l=(s+1)%i*2;r=Math.min(r,vs(e,n,t[c],t[c+1],t[l],t[l+1]))}return r}function Ps(e,n,t,o,r,i){let s=Math.max(0,o-i),c=Math.min(n-1,o+i),l=Math.max(0,r-i),p=Math.min(t-1,r+i),h=null,x=1/0;for(let f=l;f<=p;f++)for(let b=s;b<=c;b++){if(b===o&&f===r)continue;let y=b-o,P=f-r,v=y*y+P*P;if(v>i*i||v>=x)continue;let C=(f*n+b)*4;e[C+3]<ot.TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN||(h=C,x=v)}return h}function Ss(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),i=Math.max(0,Math.floor(n.y*t)),s=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),c=Math.max(1,Math.min(o.height-i,Math.ceil(n.canvasH*t)));if(s<=0||c<=0)return;let l;try{l=e.getImageData(r,i,s,c)}catch{return}let p=l.data,h=new Uint8ClampedArray(p),x=Math.max(ot.TEXTURE_EDGE_REPAIR_RADIUS,ot.TEXTURE_EDGE_REPAIR_RADIUS/t),f=Math.max(2,Math.ceil(x*t)+1),b=!1;for(let y=0;y<c;y++)for(let P=0;P<s;P++){let v=(y*s+P)*4,C=p[v+3];if(C<ot.TEXTURE_EDGE_REPAIR_ALPHA_MIN||C===255)continue;let F=(r+P+.5)/t-n.x,k=(i+y+.5)/t-n.y;if(xs(F,k,n.screenPts,n.textureEdgeRepairEdges)>x)continue;let z=Ps(h,s,c,P,y,f);z!==null&&(p[v]=h[z],p[v+1]=h[z+1],p[v+2]=h[z+2],p[v+3]=255,b=!0)}b&&e.putImageData(l,r,i)}function Cs(e){if(typeof e.toBlob=="function")return new Promise(n=>{e.toBlob(t=>{n(t?URL.createObjectURL(t):null)},"image/png")});try{return Promise.resolve(e.toDataURL("image/png"))}catch{return Promise.resolve(null)}}async function Es(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let i=e.entries.some(h=>h.textureEdgeRepair&&h.texture&&h.textureEdgeRepairEdges&&h.textureEdgeRepairEdges.size>0),s=r.getContext("2d",i?{willReadFrequently:!0}:void 0);if(!s)return{width:e.width,height:e.height,url:null};let c=Array.from(new Set(e.entries.flatMap(h=>h.texture?[h.texture]:[]))),l=new Map;await Promise.all(c.map(async h=>{l.set(h,await fs(h))}));for(let h of e.entries){let x=h.texture?l.get(h.texture):null;if(!h.texture){s.save(),ys(s,h,n,o),s.restore();continue}x&&(s.save(),Ie(s,o),s.beginPath(),Po(s,h.x,h.y,h.screenPts),s.clip(),bs(s,h,x,o),s.restore()),h.texture&&n==="baked"&&(s.save(),Ie(s,o),s.beginPath(),Po(s,h.x,h.y,h.screenPts),s.clip(),hs(s,h.x,h.y,h.canvasW,h.canvasH,h.textureTint,o),s.restore()),Ss(s,h,o)}let p=await Cs(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:p}}async function qt(e,n,t,o,r){let i=[];for(let s of e){if(r())break;i.push(await Es(s,n,t,o))}return i}var J=require("@layoutit/polycss-core"),On=require("@layoutit/polycss-core"),fr=require("@layoutit/polycss-core");var mr=require("@layoutit/polycss-core");function Mt(e,n){let o=e?.defaultView?.__polycssProjectiveQuadGuards,r=n&&o?{...n,...o}:o??n;return(0,mr.resolveProjectiveQuadGuards)(r)}function Kt(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function hr(e){if(gr(e))return!0;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,J.safariCssProjectiveUnsupported)(t):!0}function Jt(e){let n=e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0);return!!n?.supports?.("corner-top-left-shape","bevel")&&!!n.supports("corner-top-right-shape","bevel")&&!!n.supports("corner-bottom-right-shape","bevel")&&!!n.supports("corner-bottom-left-shape","bevel")}function gr(e){let n=e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0);return!!n?.supports?.("corner-top-left-shape","bevel")&&!!n.supports("corner-top-right-shape","bevel")}function Ts(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function Ke(e,n){return n?.disable?.includes("u")?null:gr(e)?"corner-bevel":hr(e)?Ts(e)?"border-large":"border":null}function en(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,J.safariCssProjectiveUnsupported)(t):!0}function Hn(e,n,t,o,r){let i=new Set(o?.disable??[]);return(0,J.getSolidPaintDefaultsForPlansCore)(e,n,i,{solidTriangleSupported:hr(t),projectiveQuadSupported:en(t),cornerShapeSupported:Jt(t),borderShapeSupported:Kt(t)},On.parseHex,On.rgbKey,r)}var Te=require("@layoutit/polycss-core"),Ue=require("@layoutit/polycss-core");var Dt=require("@layoutit/polycss-core");var it=require("@layoutit/polycss-core"),yr=require("@layoutit/polycss-core");var wt=require("@layoutit/polycss-core");function Ee(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(`(^|;)\\s*${i}\\s*:[^;]*`,"i"),c=s.test(o)?o.replace(s,(l,p)=>`${p}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;c!==o&&e.setAttribute("style",c)}function ct(e,n){let t=e.getAttribute("style")??"";if(!t||!t.toLowerCase().includes(n.toLowerCase()))return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`^\\s*${o}\\s*:`,"i"),i=t.split(";").map(s=>s.trim()).filter(s=>s&&!r.test(s)).join(";");i?e.setAttribute("style",i):e.removeAttribute("style")}function tn(e,n,t,o=!1){if(n==="dynamic"){let r=(0,wt.parseHex)(e.polygon.color??"#cccccc"),i=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return(0,wt.rgbKey)(r)!==t?.dynamicColorKey&&(i+=`;--psr:${(r.r/255).toFixed(4)};--psg:${(r.g/255).toFixed(4)};--psb:${(r.b/255).toFixed(4)}`),i}return e.shadedColor?`;color:${e.shadedColor}`:""}function As(e,n){Ee(e,"--pnx",n.normal[0].toFixed(4)),Ee(e,"--pny",n.normal[1].toFixed(4)),Ee(e,"--pnz",n.normal[2].toFixed(4))}function Lt(e,n,t,o){if(t==="dynamic"){ct(e,"color"),ct(e,"background"),As(e,n);let r=(0,wt.parseHex)(n.polygon.color??"#cccccc");(0,wt.rgbKey)(r)===o?.dynamicColorKey?(ct(e,"--psr"),ct(e,"--psg"),ct(e,"--psb")):(Ee(e,"--psr",(r.r/255).toFixed(4)),Ee(e,"--psg",(r.g/255).toFixed(4)),Ee(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(ct(e,"background"),Ee(e,"color",n.shadedColor)):(ct(e,"background"),ct(e,"color"))}var _t=require("@layoutit/polycss-core"),rt=require("@layoutit/polycss-core"),In=require("@layoutit/polycss-core"),nt=require("@layoutit/polycss-core"),br="polycss-corner-shape-solid",So=new WeakMap,Co=new WeakMap;function Pe(e,n,t){let o=So.get(e),r=Co.get(e),i=typeof t=="number";if(!n.data&&!i&&(!o||o.length===0)){e.__polycssHasDataAttrs=!1;return}let s=new Map;if(n.data)for(let[l,p]of Object.entries(n.data))s.set(l,String(p));if(i&&s.set("poly-index",String(t)),o)for(let l of o)s.has(l)||e.removeAttribute(`data-${l}`);for(let[l,p]of s)r?.get(l)!==p&&e.setAttribute(`data-${l}`,p);let c=Array.from(s.keys());c.length>0?So.set(e,c):So.delete(e),s.size>0?Co.set(e,s):Co.delete(e),e.__polycssHasDataAttrs=c.length>0}function Rt(e){return e.__polycssHasDataAttrs===!0}function Eo(e,n,t,o,r=t==="dynamic"){if(!n.url)return;let i=`url(${n.url})`,s=o.canvasW||1,c=o.canvasH||1,l=(0,rt.atlasCanonicalSizeForEntry)(o),p=`${(0,it.formatCssLength)(-o.x/s*l)} ${(0,it.formatCssLength)(-o.y/c*l)}`,h=`${(0,it.formatCssLength)(n.width/s*l)} ${(0,it.formatCssLength)(n.height/c*l)}`,x=`transform:matrix3d(${o.atlasMatrix});--polycss-atlas-size:${l}px`,f=`${x};--polycss-atlas-position:${p};--polycss-atlas-image-size:${h}`;if(t==="dynamic"){let b=r?`;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`:"";e.setAttribute("style",f+`;--polycss-atlas-url:${i}`+b)}else e.setAttribute("style",x+`;background-image:${i};background-position:${p};background-size:${h};background-repeat:no-repeat;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`)}function vr(e,n,t,o){if(n.texture){if(!t.texture||n.texture!==t.texture)return!1}else if(t.texture)return!1;let r=xr(n,t);return r?(e.style.visibility="",Ee(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(Ee(e,"--pnx",r.normal[0].toFixed(4)),Ee(e,"--pny",r.normal[1].toFixed(4)),Ee(e,"--pnz",r.normal[2].toFixed(4))),Pe(e,t,n.index),!0):(e.style.visibility="hidden",Pe(e,t,n.index),!0)}function To(e,n,t,o,r){if(o!=="baked")return{...e,polygon:n,normal:t};let i=r.directionalLight,s=r.ambientLight,c=i?.direction??nt.DEFAULT_LIGHT_DIR,l=i?.color??nt.DEFAULT_LIGHT_COLOR,p=Math.max(0,i?.intensity??nt.DEFAULT_LIGHT_INTENSITY),h=s?.color??nt.DEFAULT_AMBIENT_COLOR,x=Math.max(0,s?.intensity??nt.DEFAULT_AMBIENT_INTENSITY),f=Math.hypot(c[0],c[1],c[2])||1,b=c[0]/f,y=c[1]/f,P=c[2]/f,C=r.lightOccludedPolyIndices?.has(e.index)??!1?0:p*Math.max(0,t[0]*b+t[1]*y+t[2]*P);return{...e,polygon:n,normal:t,shadedColor:(0,yr.shadePolygon)(n.color??"#cccccc",C,l,h,x)}}function xr(e,n){let t=Pr(e,n);if(!t)return null;let{normal:o,xAxis:r,yAxis:i,tx:s,ty:c,tz:l}=t;return{normal:o,matrix:(0,it.formatMatrix3dValues)([r[0]*e.canvasW/(0,rt.atlasCanonicalSizeForEntry)(e),r[1]*e.canvasW/(0,rt.atlasCanonicalSizeForEntry)(e),r[2]*e.canvasW/(0,rt.atlasCanonicalSizeForEntry)(e),0,i[0]*e.canvasH/(0,rt.atlasCanonicalSizeForEntry)(e),i[1]*e.canvasH/(0,rt.atlasCanonicalSizeForEntry)(e),i[2]*e.canvasH/(0,rt.atlasCanonicalSizeForEntry)(e),0,o[0],o[1],o[2],0,s,c,l,1])}}var Pr=In.stableBasisFromPlan;function Ms(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=Pr(e,n);if(!o)return null;let r=(0,In.computeProjectiveQuadMatrix)(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return r?{matrix:r,normal:o.normal}:null}function Ao(e,n,t,o,r=!1){let i=t.createElement("b");return i.setAttribute("style",`transform:matrix3d(${(0,it.formatSolidQuadMatrix)(e)})`+tn(e,n,o,r)),Pe(i,e.polygon,e.index),i}function Mo(e,n,t,o,r=!1){let i=t.createElement("i");return i.setAttribute("style",(0,_t.formatBorderShapeElementStyle)(e)+tn(e,n,o,r)),Pe(i,e.polygon,e.index),i}function wo(e,n,t,o,r,i=!1){let s=o.createElement("u");return s.className=br,s.setAttribute("style",(0,_t.formatCornerShapeElementStyle)(e,n)+tn(e,t,r,i)),Pe(s,e.polygon,e.index),s}function Lo(e,n,t,o,r=!1){let i=t.createElement("b");return i.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+tn(e,n,o,r)),Pe(i,e.polygon,e.index),i}function Sr(e,n,t,o,r,i,s){let c=n.projectiveMatrix?Ms(n,t,i):xr(n,t);if(!c)return!1;let l=To(n,t,c.normal,o,r);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,Lt(e,l,o,s),Pe(e,l.polygon,l.index),!0}function Cr(e,n,t,o){e.style.visibility="",e.setAttribute("style",(0,_t.formatBorderShapeElementStyle)(n)),Lt(e,n,t,o),Pe(e,n.polygon,n.index)}function Er(e,n,t,o,r){e.style.visibility="",e.className=br,e.setAttribute("style",(0,_t.formatCornerShapeElementStyle)(n,t)),Lt(e,n,o,r),Ee(e,"background","currentColor"),Pe(e,n.polygon,n.index)}function _o(e,n,t,o=!1){let r=t.createElement("s"),i=(0,rt.atlasCanonicalSizeForEntry)(e),s=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return r.setAttribute("style",`transform:matrix3d(${e.atlasMatrix});--polycss-atlas-size:${i}px;opacity:0`+s),Pe(r,e.polygon,e.index),r}var kr=require("@layoutit/polycss-core");var Fn=require("@layoutit/polycss-core");function gt(e,n,t,o={}){let r=o.primitive!=null?void 0:(()=>{let i=t.doc??(typeof document<"u"?document:null);return i?Ke(i,t.strategies)??"border":"border"})();return(0,Fn.computeSolidTrianglePlan)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??r})}function Ro(e,n,t,o,r,i,s,c,l,p,h,x,f){let b=o.primitive!=null?void 0:(()=>{let y=t.doc??(typeof document<"u"?document:null);return y?Ke(y,t.strategies)??"border":"border"})();return(0,Fn.computeSolidTrianglePlanFromCssPoints)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??b},r,i,s,c,l,p,h,x,f)}var yt=require("@layoutit/polycss-core"),dt=require("@layoutit/polycss-core"),Tr=require("@layoutit/polycss-core");var ko=require("@layoutit/polycss-core");var ws="0 48px 96px 48px";function Ar(e,n){return(0,yt.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function Mr(e,n,t){let o=(0,yt.resolveBleedRatio)(t.seamBleed),r=yt.DEFAULT_SEAM_BLEED*o,i={...t,bleedRatio:o};return n&&r>0?{...i,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:i}function Do(e){return{updatesDisabled:e.stableTriangleColorFreezeFrames===0,freezeFrames:Math.max(1,Math.floor(e.stableTriangleColorFreezeFrames??1)),colorFrame:Math.max(0,Math.floor(e.stableTriangleColorFrame??0)),maxStep:Math.max(0,Math.floor(e.stableTriangleColorMaxStep??0))}}function wr(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function kt(e,n,t,o,r,i){return t?i.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:r==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:wr(n,i):!0}function Oo(e,n){let t=e;t.__polycssSolidTrianglePrimitive!==n&&(n==="corner-bevel"?(e.style.width="",e.style.height="",e.style.backgroundColor="",e.style.borderWidth="",e.style.borderTopLeftRadius="",e.style.borderTopRightRadius="",e.style.removeProperty("corner-top-left-shape"),e.style.removeProperty("corner-top-right-shape")):(e.style.width="",e.style.height="",e.style.backgroundColor="",e.style.borderTopLeftRadius="",e.style.borderTopRightRadius="",e.style.removeProperty("corner-top-left-shape"),e.style.removeProperty("corner-top-right-shape"),e.style.borderWidth=n==="border-large"?ws:""),t.__polycssSolidTrianglePrimitive=n)}function Ho(e){let n=e;n.__polycssSolidTriangleHidden&&(e.style.visibility="",n.__polycssSolidTriangleHidden=!1)}function nn(e){let n=e;n.__polycssSolidTriangleHidden||(e.style.visibility="hidden",n.__polycssSolidTriangleHidden=!0)}function Vn(e,n){e.setAttribute("style",n.styleText),Oo(e,n.primitive);let t=e;t.__polycssSolidTriangleBasis=n.basis,t.__polycssSolidTriangleHidden=!1,n.colorComputed&&(t.__polycssSolidTriangleColor=n.bakedColor??"",t.__polycssSolidTriangleColorRgb=n.bakedRgb,t.__polycssSolidTriangleColorAlpha=n.bakedAlpha),t.__polycssSolidTriangleColorFrame=void 0,(n.polygon.data||Rt(e))&&Pe(e,n.polygon)}function Lr(e,n,t,o){if(!n.colorComputed){(n.polygon.data||Rt(e))&&Pe(e,n.polygon);return}let r=e,i=n.bakedColor??"",s=n.bakedRgb,c=n.bakedAlpha??1,l=r.__polycssSolidTriangleColor,p=r.__polycssSolidTriangleColorRgb,h=r.__polycssSolidTriangleColorAlpha??1,x=o??wr(n.index,t);if(!t.updatesDisabled&&l!==i&&(l===void 0||x)){let f=i,b=s;if(t.maxStep>0&&p&&s&&h===c){let y=(0,dt.stepRgbToward)(p,s,t.maxStep);b=y,f=(0,dt.rgbToCss)(y,c)}(f!==l||!(0,dt.rgbEqual)(b,p))&&(e.style.color=f),r.__polycssSolidTriangleColor=f,r.__polycssSolidTriangleColorRgb=b,r.__polycssSolidTriangleColorAlpha=c,r.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||Rt(e))&&Pe(e,n.polygon)}function Bn(e,n,t,o){let r=e;Oo(e,n.primitive),r.__polycssSolidTriangleBasis!==n.basis&&(r.__polycssSolidTriangleBasis=n.basis),Ho(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||Rt(e))&&Lr(e,n,t,o)}function Io(e,n,t,o){Ho(e),Lr(e,n,t,o)}function zn(e,n){let t=e;Oo(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),Ho(e),e.style.transform=n.transformText,(n.polygon.data||Rt(e))&&Pe(e,n.polygon)}function Ls(e,n){let t=n.stableTriangleColorBudget;if(typeof t=="number"&&Number.isFinite(t)&&t>0)return t<=1?Math.max(1,Math.ceil(e*t)):Math.max(1,Math.floor(t));let o=Math.max(1,Math.floor(n.stableTriangleColorFreezeFrames??1));return Math.max(1,Math.ceil(e/o))}function _r(e,n,t){if(t.stableTriangleColorPolicy!=="adaptive")return null;if(t.stableTriangleColorFreezeFrames===0)return new Set;let o=Math.max(0,Math.floor(t.stableTriangleColorFrame??0)),r=Math.max(1,Math.floor(t.stableTriangleColorFreezeFrames??1));if(r<=1&&!Number.isFinite(t.stableTriangleColorBudget))return null;let i=Ls(e.length,t),s=Math.max(1,Math.floor(t.stableTriangleColorMaxAge??Math.max(2,r*2))),c=[];for(let l=0;l<e.length;l++){let p=e[l],h=n[l];if(p.kind!=="triangle"||!h)continue;let x=p.element,f=x.__polycssSolidTriangleColor,b=h.bakedColor??"";if(f===b)continue;let y=x.__polycssSolidTriangleColorFrame??0,P=Math.max(0,o-y),v=(0,dt.colorErrorScore)(f,b);c.push({index:l,score:(P>=s?1e6:0)+v*1e4+P})}return c.length===0?new Set:(c.sort((l,p)=>p.score-l.score),new Set(c.slice(0,i).map(l=>l.index)))}function Nn(e,n){let t=n.createElement("u");return Vn(t,e),Pe(t,e.polygon,e.index),t}function _s(e,n,t){let o=t.createElement("u");return nn(o),Pe(o,e,n),o}function Rr(e,n,t,o,r,i){let s=t,c=s.stableTriangleDebug,l=o&&r==="color-only";if(s.stableTriangleColorPolicy==="adaptive"||e.length!==n.length)return!1;let p=(0,ko.stableTriangleMatrixDecimals)(s.stableTriangleMatrixDecimals),h=t.doc??(typeof document<"u"?document:null),x=h?Ke(h,t.strategies)??"border":"border";for(let b=0;b<e.length;b++){let y=e[b];if(y.kind!=="triangle"||y.polygonIndex!==b||!n[b])return!1}let f=Ar(n,t);for(let b=0;b<e.length;b++){let y=e[b].element,P=n[b];if(l){if(kt(y,b,o,c,s.stableTriangleColorPolicy,i)){let C=(0,Tr.computeSolidTriangleColorPlan)(P,b,t);if(!C)continue;Io(y,C,i)}continue}let v=gt(P,b,Mr(b,f,t),{basis:y.__polycssSolidTriangleBasis,matrixDecimals:p,primitive:x,includeColor:r!=="plan-only"&&r!=="transform-only"&&kt(y,b,o,c,s.stableTriangleColorPolicy,i)});if(!v){nn(y);continue}o&&r==="plan-only"||(o&&r==="transform-only"?zn(y,v):o?Bn(y,v,i):Vn(y,v))}return!0}function on(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=Ke(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let r=(0,ko.stableTriangleMatrixDecimals)(n.stableTriangleMatrixDecimals),i=[],s=Ar(e,n);for(let c=0;c<e.length;c+=1){let l=e[c],p=gt(l,c,Mr(c,s,n),{matrixDecimals:r,primitive:o}),h=p?Nn(p,t):_s(l,c,t);i.push({polygonIndex:c,element:h,kind:"triangle",dispose:()=>{}})}return{rendered:i,dispose(){}}}var Vo=require("@layoutit/polycss-core");function Dr(){return new Promise(e=>setTimeout(e,0))}async function Fo(e){return performance.now()-e<Te.ASYNC_RENDER_BUDGET_MS?e:(await Dr(),performance.now())}function Or(e,n){let t=(0,Te.resolveBleedRatio)(n.seamBleed),o=Te.DEFAULT_SEAM_BLEED*t,r={...n,bleedRatio:t};return e.seamBleedEdges?.size&&o>0?{...r,seamBleed:o,seamEdges:e.seamBleedEdges}:{...r,seamBleed:void 0,seamEdges:void 0}}function Hr(e,n){return(0,Ue.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function Ir(e,n,t){let o=(0,Te.resolveBleedRatio)(t.seamBleed),r=Te.DEFAULT_SEAM_BLEED*o,i={...t,bleedRatio:o};return n&&r>0?{...i,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:i}function Ot(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=(0,Ue.buildBasisHints)(e,n),r=Mt(t),i=e.map((s,c)=>(0,Ue.computeTextureAtlasPlan)(s,c,n,r,o[c]));return Hn(i,n.textureLighting??"baked",t,n.strategies)}function Ht(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=n,i=o==="dynamic"&&r.skipDynamicNormalVars===!0,s=new Set(n.strategies?.disable??[]),c=!s.has("b"),l=c&&en(t),p=Ke(t,n.strategies),h=p!==null,x=!s.has("i")&&Jt(t),f=!s.has("i")&&Kt(t),b=(0,Ue.buildBasisHints)(e,n),y=Mt(t),P=Hr(e,n),v=e.map((u,d)=>(0,Ue.computeTextureAtlasPlan)(u,d,Ir(d,P,n),y,b[d]));if(typeof window<"u"){let u=window,d=v[1];u.__vanillaPlan1={matrix:d?.matrix,canvasW:d?.canvasW,canvasH:d?.canvasH,vertexCount:e[1]?.vertices.length}}let C=n.solidPaintDefaults??(r.computeSolidPaintDefaults?Hn(v,o,t,n.strategies):void 0),F=C?{...n,solidPaintDefaults:C}:n,k=v.map(u=>u&&h&&(0,J.isSolidTrianglePlan)(u)?gt(u.polygon,u.index,Or(u,F),{primitive:p??void 0}):null),z=v.map(u=>u&&x&&!(0,J.isSolidTrianglePlan)(u)&&!(c&&(0,J.isFullRectSolid)(u))&&!(l&&(0,J.isProjectiveQuadPlan)(u))?(0,Dt.cornerShapeGeometryForPlan)(u):null),O=v.map((u,d)=>u&&(u.texture||!(c&&(0,J.isFullRectSolid)(u))&&!k[d]&&!(l&&(0,J.isProjectiveQuadPlan)(u))&&!z[d]&&!f?u:null)),{packed:Z,atlasScale:q}=Qt(O,n.textureQuality,t),D=new Map,H=[],V=!1,G=[];for(let u=0;u<e.length;u++){let d=v[u],T=k[u],w=z[u];if(!d)continue;let R=Z.entries[u];if(R){let L=_o(R,o,t,i);D.set(u,L),H.push({polygonIndex:u,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!d.texture&&c&&(0,J.isFullRectSolid)(d)){let L=Ao(d,o,t,C,i);H.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&T){let L=Nn(T,t);H.push({polygonIndex:u,element:L,kind:"triangle",plan:d,dispose:()=>{}})}else if(!d.texture&&l&&(0,J.isProjectiveQuadPlan)(d)){let L=Lo(d,o,t,C,i);H.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&w){let L=wo(d,w,o,t,C,i);H.push({polygonIndex:u,element:L,kind:"corner",plan:d,dispose:()=>{}})}else if(!d.texture&&f){let L=Mo(d,o,t,C,i);H.push({polygonIndex:u,element:L,kind:"border",plan:d,dispose:()=>{}})}}H.sort((u,d)=>u.polygonIndex-d.polygonIndex);let A=qt(Z.pages,o,t,q,()=>V).then(u=>{if(V){for(let d of u)d.url?.startsWith("blob:")&&URL.revokeObjectURL(d.url);return}G=u.flatMap(d=>d.url?.startsWith("blob:")?[d.url]:[]);for(let d=0;d<Z.pages.length;d++){let T=Z.pages[d],w=u[d];if(w)for(let R of T.entries){let L=D.get(R.index);!L||!w.url||Eo(L,w,o,R,!0)}}}).catch(()=>{if(!V)for(let u of D.values())Ee(u,"opacity","0.5"),Ee(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:H,solidPaintDefaults:C??{},pagesReady:A,dispose(){V=!0;for(let u of G)URL.revokeObjectURL(u);G=[]}}}async function Gn(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let r=n.textureLighting??"baked",s=r==="dynamic"&&n.skipDynamicNormalVars===!0,c=new Set(n.strategies?.disable??[]),l=!c.has("b"),p=l&&en(o),h=Ke(o,n.strategies),x=h!==null,f=!c.has("i")&&Jt(o),b=!c.has("i")&&Kt(o);if(await Dr(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let y=(0,Ue.buildBasisHints)(e,n),P=Mt(o),v=Hr(e,n),C=performance.now(),F=new Array(e.length);for(let u=0;u<e.length;u++)if(F[u]=(0,Ue.computeTextureAtlasPlan)(e[u],u,Ir(u,v,n),P,y[u]),C=await Fo(C),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let k=n.solidPaintDefaults??Hn(F,r,o,n.strategies),z=new Array(F.length),O=new Array(F.length),Z=new Array(F.length);for(let u=0;u<F.length;u++){let d=F[u],T=d&&x&&(0,J.isSolidTrianglePlan)(d)?gt(d.polygon,d.index,Or(d,{...n,solidPaintDefaults:k}),{primitive:h??void 0}):null;z[u]=T;let w=d&&f&&!(0,J.isSolidTrianglePlan)(d)&&!(l&&(0,J.isFullRectSolid)(d))&&!(p&&(0,J.isProjectiveQuadPlan)(d))?(0,Dt.cornerShapeGeometryForPlan)(d):null;if(O[u]=w,Z[u]=d&&(d.texture||!(l&&(0,J.isFullRectSolid)(d))&&!T&&!(p&&(0,J.isProjectiveQuadPlan)(d))&&!w&&!b?d:null),C=await Fo(C),t())return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}let{packed:q,atlasScale:D}=Qt(Z,n.textureQuality,o),H=new Map,V=[],G=!1,A=[];for(let u=0;u<e.length;u++){let d=F[u],T=z[u],w=O[u];if(!d)continue;let R=q.entries[u];if(R){let L=_o(R,r,o,s);H.set(u,L),V.push({polygonIndex:u,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!d.texture&&l&&(0,J.isFullRectSolid)(d)){let L=Ao(d,r,o,k,s);V.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&T){let L=Nn(T,o);V.push({polygonIndex:u,element:L,kind:"triangle",plan:d,dispose:()=>{}})}else if(!d.texture&&p&&(0,J.isProjectiveQuadPlan)(d)){let L=Lo(d,r,o,k,s);V.push({polygonIndex:u,element:L,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&w){let L=wo(d,w,r,o,k,s);V.push({polygonIndex:u,element:L,kind:"corner",plan:d,dispose:()=>{}})}else if(!d.texture&&b){let L=Mo(d,r,o,k,s);V.push({polygonIndex:u,element:L,kind:"border",plan:d,dispose:()=>{}})}if(C=await Fo(C),t()){for(let L of V)L.dispose();return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}}V.sort((u,d)=>u.polygonIndex-d.polygonIndex);let g=qt(q.pages,r,o,D,()=>G||t()).then(u=>{if(G||t()){for(let d of u)d.url?.startsWith("blob:")&&URL.revokeObjectURL(d.url);return}A=u.flatMap(d=>d.url?.startsWith("blob:")?[d.url]:[]);for(let d=0;d<q.pages.length;d++){let T=q.pages[d],w=u[d];if(w)for(let R of T.entries){let L=H.get(R.index);!L||!w.url||Eo(L,w,r,R,!0)}}}).catch(()=>{if(!(G||t()))for(let u of H.values())Ee(u,"opacity","0.5"),Ee(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:V,solidPaintDefaults:k,pagesReady:g,dispose(){G=!0;for(let u of A)URL.revokeObjectURL(u);A=[]}}}function $n(e,n,t,o={}){let r=o.textureLighting??"baked",i=o,s=i.optimizeStableTriangleStyle===!0&&r==="baked";if(!s||i.stableTriangleColorPolicy==="adaptive"||e.length!==t.polygonCount||n.length!==t.polygonCount||t.vertices.length<t.polygonCount*9)return!1;let c=i.stableTriangleDebug,l=i.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full");if(l==="color-only")return!1;let p=(0,Vo.stableTriangleMatrixDecimals)(i.stableTriangleMatrixDecimals),h=Do(i),x=o.tileSize??Te.DEFAULT_TILE,f=o.layerElevation??x,b=o.doc??(typeof document<"u"?document:null),y=b?Ke(b,o.strategies)??"border":"border";for(let v=0;v<e.length;v++){let C=e[v],F=n[v];if(C.kind!=="triangle"||C.polygonIndex!==v||!F||F.vertices.length!==3||F.texture||F.material?.texture)return!1}let P=t.vertices;for(let v=0;v<e.length;v++){let C=e[v].element,F=n[v],k=v*9,z=P[k+1]*x,O=P[k]*x,Z=P[k+2]*f,q=P[k+4]*x,D=P[k+3]*x,H=P[k+5]*f,V=P[k+7]*x,G=P[k+6]*x,A=P[k+8]*f,g=Ro(F,v,o,{basis:C.__polycssSolidTriangleBasis,matrixDecimals:p,primitive:y,color:t.colors?.[v],includeColor:l!=="plan-only"&&l!=="transform-only"&&kt(C,v,s,c,i.stableTriangleColorPolicy,h)},z,O,Z,q,D,H,V,G,A);if(!g){nn(C);continue}l!=="plan-only"&&(l==="transform-only"?zn(C,g):Bn(C,g,h))}return!0}function Un(e,n,t={}){if(e.length!==n.length)return!1;let o=t,r=t.doc??(typeof document<"u"?document:null),i=t.textureLighting??"baked",s=new Set(t.strategies?.disable??[]),c=!s.has("b"),l=!!r&&c&&en(r),p=!!r&&!s.has("i")&&Jt(r),h=!!r&&!s.has("i")&&Kt(r),x=(0,Te.resolveBleedRatio)(o.seamBleed),f=r?Mt(r,{bleed:Te.PROJECTIVE_QUAD_BLEED*x}):{denomEps:Te.PROJECTIVE_QUAD_DENOM_EPS,maxWeightRatio:Te.PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,bleed:Te.PROJECTIVE_QUAD_BLEED*x,disableGuards:!1},b=o.optimizeStableTriangleStyle===!0&&i==="baked",y=o.stableTriangleDebug,P=o.stableTriangleUpdateMode??(y==="plan-only"||y==="transform-only"?y:"full"),v=b&&P==="color-only",C=Do(o),F=(0,Vo.stableTriangleMatrixDecimals)(o.stableTriangleMatrixDecimals),k=r?Ke(r,t.strategies)??"border":"border";if(Rr(e,n,t,b,P,C))return!0;let z=[],O=[],Z=[];for(let D=0;D<e.length;D++){let H=e[D];if(H.polygonIndex!==D)return!1;let V=n[D];if(!V||v&&H.kind!=="triangle")return!1;if(H.kind==="atlas"){if(!H.plan||!vr(H.element,H.plan,V,i))return!1;continue}if(H.kind==="triangle"){let G=H.element;if(v){let g=o.stableTriangleColorPolicy==="adaptive"||kt(G,D,b,y,o.stableTriangleColorPolicy,C);O[D]=g?(0,kr.computeSolidTriangleColorPlan)(V,D,t):null;continue}let A=gt(V,D,t,{basis:G.__polycssSolidTriangleBasis,matrixDecimals:F,primitive:k,includeColor:P!=="plan-only"&&P!=="transform-only"&&kt(G,D,b,y,o.stableTriangleColorPolicy,C)});if(!A){z[D]=null;continue}z[D]=A;continue}if(H.kind==="solid"){if(!H.plan||V.texture||V.vertices.length!==H.plan.polygon.vertices.length)return!1;Z[D]=H.plan;continue}if(H.kind==="border"){let G=(0,Ue.computeTextureAtlasPlan)(V,D,t,f);if(!G||G.texture||!h||c&&(0,J.isFullRectSolid)(G)||l&&(0,J.isProjectiveQuadPlan)(G)||p&&(0,Dt.cornerShapeGeometryForPlan)(G))return!1;Z[D]=G;continue}if(H.kind==="corner"){let G=(0,Ue.computeTextureAtlasPlan)(V,D,t,f);if(!G||G.texture||!p||(0,J.isSolidTrianglePlan)(G)||c&&(0,J.isFullRectSolid)(G)||l&&(0,J.isProjectiveQuadPlan)(G)||!(0,Dt.cornerShapeGeometryForPlan)(G))return!1;Z[D]=G;continue}return!1}let q=b&&P!=="plan-only"&&P!=="transform-only"?_r(e,v?O:z,o):null;for(let D=0;D<e.length;D++){let H=e[D];if(H.kind==="triangle"){if(v){let G=O[D];G&&Io(H.element,G,C,q?.has(D));continue}let V=z[D];if(!V){nn(H.element);continue}if(b&&P==="plan-only")continue;b&&P==="transform-only"?zn(H.element,V):b?Bn(H.element,V,C,q?.has(D)):Vn(H.element,V)}else if(H.kind==="solid"){let V=Z[D];if(!V||!Sr(H.element,V,n[D],i,t,f,o.solidPaintDefaults))return!1}else if(H.kind==="border"){let V=Z[D];if(!V)return!1;Cr(H.element,V,i,o.solidPaintDefaults)}else if(H.kind==="corner"){let V=Z[D],G=V?(0,Dt.cornerShapeGeometryForPlan)(V):null;if(!V||!G)return!1;Er(H.element,V,G,i,o.solidPaintDefaults)}}return!0}var Fr=require("@layoutit/polycss-core"),Ft=require("@layoutit/polycss-core"),jn=require("@layoutit/polycss-core");var ee=require("@layoutit/polycss-core"),Is=[.4,-.7,.59],Fs="#ffffff",Vs=1,Bs="#ffffff",zs=.4,$r=1,Ns=8,Gs=ee.PROJECTIVE_QUAD_BLEED,st=1e-6,$s=(0,ee.resolveProjectiveQuadGuards)({bleed:0}),Ur={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},No=["t","b","bl","br","fr","fl"],Us=new Map([["0,0,1","t"],["0,0,-1","b"],["0,1,0","fl"],["0,-1,0","br"],["1,0,0","fr"],["-1,0,0","bl"]]);function Vr(e){let n=[];for(let t of No)(0,ee.normalFacesCamera)(Ur[t],e)&&n.push(t);return n.join("|")}function js(e,n,t){let o=e.__polycssVoxelBrushState??(e.__polycssVoxelBrushState={});o.color!==n&&(e.style.color=n,o.color=n),o.transform!==t&&(e.style.transform=t,o.transform=t)}function Ws(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,i=0;for(let c=1;c+1<n.length;c+=1){let l=n[c],p=n[c+1],h=l[1]-t[1],x=l[0]-t[0],f=l[2]-t[2],b=p[1]-t[1],y=p[0]-t[0],P=p[2]-t[2];o-=x*P-f*y,r-=f*b-h*P,i-=h*y-x*b}let s=Math.hypot(o,r,i);return s<=1e-9?null:[Math.round(o/s),Math.round(r/s),Math.round(i/s)]}function Ys(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=Ws(e),t=n?Us.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,i=1/0,s=-1/0,c=-1/0,l=-1/0;for(let x of e.vertices)o=Math.min(o,x[0]),r=Math.min(r,x[1]),i=Math.min(i,x[2]),s=Math.max(s,x[0]),c=Math.max(c,x[1]),l=Math.max(l,x[2]);let p=1e-6,h=ea(e.color);return Math.abs(l-i)<=p?{axis:"z",face:t,left:r*ee.BASE_TILE,top:o*ee.BASE_TILE,width:Math.max(0,(c-r)*ee.BASE_TILE),height:Math.max(0,(s-o)*ee.BASE_TILE),z:i*ee.BASE_TILE,baseColor:h,bleed:Bo()}:Math.abs(s-o)<=p?{axis:"x",face:t,left:r*ee.BASE_TILE,top:i*ee.BASE_TILE,width:Math.max(0,(c-r)*ee.BASE_TILE),height:Math.max(0,(l-i)*ee.BASE_TILE),z:-o*ee.BASE_TILE,baseColor:h,bleed:Bo()}:Math.abs(c-r)<=p?{axis:"y",face:t,left:i*ee.BASE_TILE,top:o*ee.BASE_TILE,width:Math.max(0,(l-i)*ee.BASE_TILE),height:Math.max(0,(s-o)*ee.BASE_TILE),z:-r*ee.BASE_TILE,baseColor:h,bleed:Bo()}:null}function Bo(){return{left:0,right:0,top:0,bottom:0}}function Xs(e){let n=o=>String(Number(o.toFixed(6))),t=`${e.item.baseColor}|${e.variableAxis}`;for(let o=0;o<3;o+=1)o!==e.variableAxis&&(t+=`|${o}:${n(e.fixed[o])}`);return t}function Br(e){return[e[1]*ee.BASE_TILE,e[0]*ee.BASE_TILE,e[2]*ee.BASE_TILE]}function zr(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function Zs(e,n,t){let o=e.left,r=e.left+e.width,i=e.top,s=e.top+e.height;if(Math.abs(n[0]-t[0])<=st){if(Math.abs(n[0]-o)<=st)return"left";if(Math.abs(n[0]-r)<=st)return"right"}if(Math.abs(n[1]-t[1])<=st){if(Math.abs(n[1]-i)<=st)return"top";if(Math.abs(n[1]-s)<=st)return"bottom"}return null}function Qs(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=st)){if(t!==null)return null;t=o}return t}function qs(e,n,t){let o=n.vertices,r=Br(o[t]),i=Br(o[(t+1)%o.length]),s=Zs(e,zr(e,r),zr(e,i));if(!s)return null;let c=Qs(r,i);if(c===null)return null;let l=Math.min(r[c],i[c]),p=Math.max(r[c],i[c]);return p-l>st?{item:e,side:s,variableAxis:c,fixed:r,start:l,end:p}:null}function Nr(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],Gs)}function Ks(e,n){let t=new Map;for(let o of n){let r=e[o.sourceIndex];if(r)for(let i=0;i<r.vertices.length;i+=1){let s=qs(o,r,i);if(!s)continue;let c=Xs(s),l=t.get(c);l?l.push(s):t.set(c,[s])}}for(let o of t.values()){if(o.length<2)continue;o.sort((i,s)=>i.start-s.start||i.end-s.end);let r=[];for(let i of o){r=r.filter(s=>s.end>i.start+st);for(let s of r)s.item.sourceIndex!==i.item.sourceIndex&&(Nr(s),Nr(i));r.push(i)}}}function Js(e){let n=(0,ee.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha}:{r:255,g:255,b:255,alpha:1}}function ea(e){if(!e)return"#cccccc";let n=(0,ee.parsePureColor)(e);if(!n)return e;let t={r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha};if(t.alpha<1){let o=Math.round(Math.max(0,t.alpha)*1e3)/1e3;return`rgba(${zo(t.r)}, ${zo(t.g)}, ${zo(t.b)}, ${o})`}return ta(t)}function ta({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function zo(e){return Math.round(Math.max(0,Math.min(255,e)))}function na(e,n,t,o){let r=t?.direction??Is,i=Math.hypot(r[0],r[1],r[2])||1,s=r[0]/i,c=r[1]/i,l=r[2]/i,p=Math.max(0,t?.intensity??Vs)*Math.max(0,e[0]*s+e[1]*c+e[2]*l),h=Math.max(0,o?.intensity??zs),x=t?.color??Fs,f=o?.color??Bs,b=(0,ee.shadePolygon)(n,p,x,f,h),y=Js(n);if(y.alpha>=1)return b;let P=parseInt(b.slice(1,3),16),v=parseInt(b.slice(3,5),16),C=parseInt(b.slice(5,7),16);return`rgba(${P}, ${v}, ${C}, ${y.alpha})`}function oa(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=Ys(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return Ks(e,n),n}function ra(e){return e.axis==="x"?{xAxis:[1,0,0],yAxis:[0,0,1],normal:[0,-1,0],tx:0,ty:-e.z,tz:0}:e.axis==="y"?{xAxis:[0,0,1],yAxis:[0,1,0],normal:[-1,0,0],tx:-e.z,ty:0,tz:0}:{xAxis:[1,0,0],yAxis:[0,1,0],normal:[0,0,1],tx:0,ty:0,tz:e.z}}function ia(e){let n=e.left,t=e.top,o=e.left+e.width,r=e.top+e.height;return[n,t,o,t,o,r,n,r]}function sa(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function aa(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(r=>!Number.isFinite(r)))return null;let o=ee.SOLID_QUAD_CANONICAL_SIZE/n;for(let r=0;r<8;r+=1)t[r]*=o;return`matrix3d(${t.map(r=>Number(r.toFixed(6))).join(",")})`}function Gr(e,n){let t=e.left-e.bleed.left,o=e.top-e.bleed.top,r=e.width+e.bleed.left+e.bleed.right,i=e.height+e.bleed.top+e.bleed.bottom,s=e.z,c=r/n,l=i/n;return`matrix3d(${(e.axis==="x"?[c,0,0,0,0,0,l,0,0,-1,0,0,t,-s,o,1]:e.axis==="y"?[0,0,c,0,0,l,0,0,-1,0,0,0,-s,o,t,1]:[c,0,0,0,0,l,0,0,0,0,1,0,t,o,s,1]).map(h=>Number(h.toFixed(6))).join(",")})`}function la(e,n){let{xAxis:t,yAxis:o,normal:r,tx:i,ty:s,tz:c}=ra(e),l=(0,ee.computeProjectiveQuadMatrix)(ia(e),t,o,r,i,s,c,$s,sa(e));return l?aa(l,n)??Gr(e,n):Gr(e,n)}function ca(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function da(e){return ca(e)?Ns:$r}function ua(e){return e.axis==="x"?[e.left+e.width/2,-e.z,e.top+e.height/2]:e.axis==="y"?[-e.z,e.top+e.height/2,e.left+e.width/2]:[e.left+e.width/2,e.top+e.height/2,e.z]}function pa(e,n){let t=ua(e),o=n.meshRotation;o&&(t=(0,ee.rotateVec3InWrapperCssFrame)(t,o));let[r,i]=(0,ee.rotateVec3)(t,n.rotX,0,n.rotY);return{x:r,y:i}}function ma(e,n,t){let o=e.filter(f=>n.has(f.face)).map(f=>({item:f,...pa(f,t)}));if(o.length===0)return[];let r=1/0,i=-1/0,s=1/0,c=-1/0;for(let f of o)r=Math.min(r,f.x),i=Math.max(i,f.x),s=Math.min(s,f.y),c=Math.max(c,f.y);let l=4,p=Math.max(1e-6,i-r),h=Math.max(1e-6,c-s),x=new Map;for(let f of o){let b=Math.min(l-1,Math.max(0,Math.floor((f.x-r)/p*l))),y=Math.min(l-1,Math.max(0,Math.floor((f.y-s)/h*l))),P=`${b}:${y}`,v=x.get(P);v||(v={tx:b,ty:y,sourceIndex:f.item.sourceIndex,items:[]},x.set(P,v)),v.items.push(f.item),v.sourceIndex=Math.min(v.sourceIndex,f.item.sourceIndex)}return Array.from(x.values()).sort((f,b)=>f.ty-b.ty||f.tx-b.tx||f.sourceIndex-b.sourceIndex).flatMap(f=>f.items)}function jr(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:i}=e,s=oa(o);if(s.length===0)return null;let c=new Set(s.map(g=>g.face));t.classList.add("polycss-voxel-mesh");let l=da(n);l!==$r&&t.style.setProperty("--polycss-voxel-primitive",`${l}px`);let p=new Map,h=(g,u)=>{let d=`${g}|${u}`,T=p.get(d);if(T)return T;let w=na(Ur[g],u,r,i);return p.set(d,w),w},x=new Map,f=new Map,b=new Map,y=new Map;for(let g of s){let u=y.get(g.face);u||(u=[],y.set(g.face,u)),u.push(g)}let P="",v=0,C=new Set,F=g=>{let u=x.get(g.sourceIndex);return u||(u=n.createElement("b"),x.set(g.sourceIndex,u),js(u,h(g.face,g.baseColor),la(g,l))),u},k=g=>{let u=f.get(g);return u||(u=n.createElement("span"),u.className=`polycss-voxel-face polycss-voxel-face-${g}`,u.dataset.polycssVoxelFace=g,u.__polycssVoxelFaceHost=!0,f.set(g,u)),u},z=()=>{for(let g of Array.from(t.childNodes))if(!g.__polycssVoxelFaceHost)return g;return null},O=(g,u)=>{let d=u.map(R=>R.sourceIndex).join(",");if(b.get(g)===d)return;let T=k(g),w=n.createDocumentFragment();for(let R of u)w.appendChild(F(R));T.replaceChildren(w),b.set(g,d)},Z=()=>{for(let g of No)c.has(g)&&O(g,y.get(g)??[])},q=g=>new Set(g.split("|").filter(Boolean)),D=g=>{let u=q(g);return No.filter(d=>u.has(d)&&c.has(d))},H=g=>{let u=0;for(let d of g)u+=y.get(d)?.length??0;return u},V=g=>{let u=new Set,d=[],T=new Map;for(let w of g){u.has(w.face)||(u.add(w.face),d.push(w.face));let R=T.get(w.face);R||(R=[],T.set(w.face,R)),R.push(w)}return{orderedFaces:d,itemsByFace:T}},G=(g,u)=>{let d=new Set(g);for(let T of C){if(d.has(T))continue;let w=f.get(T);w?.parentNode===t&&t.removeChild(w)}if(u){let T=n.createDocumentFragment();for(let w of g)T.appendChild(k(w));t.insertBefore(T,z()),C=d;return}for(let T=0;T<g.length;T+=1){let w=g[T],R=k(w);if(R.parentNode===t)continue;let L=null;for(let re=T+1;re<g.length;re+=1){let _=f.get(g[re]);if(_?.parentNode===t){L=_;break}}t.insertBefore(R,L??z())}C=d},A=(g,u,d)=>{if(!d){let re=D(g);G(re,!1),v=H(re);return}let T=new Set(g.split("|").filter(Boolean)),w=ma(s,T,u),{orderedFaces:R,itemsByFace:L}=V(w);for(let re of R)O(re,L.get(re)??[]);G(R,!0),v=w.length};return Z(),{get brushCount(){return v},render(g){P=Vr(g),A(P,g,!0)},syncCamera(g){let u=Vr(g);u!==P&&(P=u,A(u,g,!1))},dispose(){for(let g of f.values())g.remove();t.classList.remove("polycss-voxel-mesh"),t.style.removeProperty("--polycss-voxel-primitive"),x.clear(),f.clear(),b.clear(),v=0,C=new Set,P=""}}}var Wr="polycss-styles";function Yr(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(Wr))return;let t=n.createElement("style");t.id=Wr,t.textContent=fa,n.head.appendChild(t)}var fa=`
2
2
  /* \u2500\u2500 Scene container \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
3
3
 
4
4
  .polycss-scene,
@@ -51,12 +51,32 @@
51
51
  transform-style: preserve-3d !important;
52
52
  }
53
53
 
54
+ /* \u2500\u2500 Shadow root wrapper \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
55
+
56
+ /* Single 0\xD70 preserve-3d container that owns every shadow SVG (ground +
57
+ per-face receiver). Children composite via their own absolute matrix3d
58
+ transforms exactly as if mounted on .polycss-scene directly. The wrapper
59
+ exists so the DOM has one obvious "shadows live here" node and so
60
+ future toggles (clip-region, hide-all-shadows) flip a single ancestor. */
61
+ .polycss-shadows {
62
+ position: absolute;
63
+ top: 0;
64
+ left: 0;
65
+ width: 0;
66
+ height: 0;
67
+ transform-style: preserve-3d;
68
+ pointer-events: none;
69
+ }
70
+
54
71
  /* \u2500\u2500 Mesh wrapper \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
55
72
 
56
73
  .polycss-mesh {
57
74
  position: absolute;
58
75
  transform-style: preserve-3d;
59
- transform-origin: var(--origin);
76
+ /* Pivot at wrapper local (0,0,0) for three.js mesh.position/rotation/scale
77
+ parity. Geometry is positioned by the parser (bbox-min-at-origin by
78
+ default, or pre-centered via parseGltf/parseObj { center: true }). */
79
+ transform-origin: 0 0 0;
60
80
  }
61
81
 
62
82
  /* \u2500\u2500 Polygon leaf element \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
@@ -138,30 +158,39 @@
138
158
  border-width: 0 16px 32px 16px;
139
159
  }
140
160
 
141
- .polycss-scene u.polycss-large-border-triangle {
142
- border-width: 0 48px 96px 48px;
143
- }
144
-
145
- .polycss-scene u.polycss-corner-triangle {
146
- width: 32px;
147
- height: 32px;
148
- background: currentColor;
149
- border: 0;
150
- border-top-left-radius: 50% 100%;
151
- border-top-right-radius: 50% 100%;
152
- corner-top-left-shape: bevel;
153
- corner-top-right-shape: bevel;
161
+ @supports (corner-top-left-shape: bevel) and (corner-top-right-shape: bevel) {
162
+ .polycss-scene > u,
163
+ .polycss-mesh > u,
164
+ .polycss-bucket > u {
165
+ border-width: 0;
166
+ width: 32px;
167
+ height: 32px;
168
+ background-color: currentColor;
169
+ border-top-left-radius: 50% 100%;
170
+ border-top-right-radius: 50% 100%;
171
+ corner-top-left-shape: bevel;
172
+ corner-top-right-shape: bevel;
173
+ }
174
+
175
+ .polycss-scene > u.polycss-corner-shape-solid,
176
+ .polycss-mesh > u.polycss-corner-shape-solid,
177
+ .polycss-bucket > u.polycss-corner-shape-solid {
178
+ width: 16px;
179
+ height: 16px;
180
+ box-sizing: border-box;
181
+ border: 0;
182
+ background: currentColor;
183
+ border-radius: 0;
184
+ corner-top-left-shape: initial;
185
+ corner-top-right-shape: initial;
186
+ corner-bottom-right-shape: initial;
187
+ corner-bottom-left-shape: initial;
188
+ }
154
189
  }
155
190
 
156
- /* <q> \u2014 dedicated shadow leaf. Same border-shape rendering trick as <i>
157
- (border-color: currentColor fills the polygon outline) but with its
158
- own tag so we don't have to thread :not(.polycss-shadow) exclusions
159
- through every dynamic-mode color rule. backface-visibility must be
160
- visible because the projection matrix is near-rank-deficient and the
161
- resulting plane's normal can read as back-facing under some camera
162
- angles; the leaf is intentionally always painted. Strip the UA's
163
- default ::before/::after open-/close-quote so the element is just a
164
- styled box. */
191
+ /* Reserved internal <q> shadow element rules. Current shadow emission uses SVG
192
+ surfaces; these rules keep any retained <q> markup styled as a plain
193
+ border-shape leaf instead of inheriting UA quote styling. */
165
194
  .polycss-scene q {
166
195
  position: absolute;
167
196
  display: block;
@@ -344,13 +373,34 @@
344
373
  leaves, so there's nothing inside a leaf that needs to participate
345
374
  in 3D compositing across the contain boundary. */
346
375
  contain: strict;
376
+ /*
377
+ * Three.js MeshLambertMaterial parity for textured surfaces:
378
+ *
379
+ * target = sRGB_encode(albedo_linear \xD7 irradiance_linear / \u03C0)
380
+ *
381
+ * background-blend-mode: multiply produces (bitmap \xD7 tint) in sRGB
382
+ * \u2014 approximately sRGB(albedo_linear \xD7 tint_linear) when bitmap \u2248
383
+ * sRGB(albedo_linear). So we want tint = sRGB_encode(irradiance /\u03C0).
384
+ *
385
+ * Each light/ambient colour channel is sRGB-to-linearised
386
+ * via pow((c + 0.055) / 1.055, 2.4) before the dot product so the
387
+ * irradiance accumulates in linear space; final encode is
388
+ * 1.055 \xD7 pow(c, 1/2.4) - 0.055. min(1, \u2026) clamps inside the encode
389
+ * domain. Matches the solid <b>/<i>/<u> pipeline below.
390
+ */
347
391
  background-color: rgb(
348
- calc(255 * (var(--par) * var(--pai)
349
- + var(--plr) * var(--pli) * var(--plam)))
350
- calc(255 * (var(--pag) * var(--pai)
351
- + var(--plg) * var(--pli) * var(--plam)))
352
- calc(255 * (var(--pab) * var(--pai)
353
- + var(--plb) * var(--pli) * var(--plam)))
392
+ calc(255 * max(0, 1.055 * pow(min(1, (
393
+ pow((var(--par) + 0.055) / 1.055, 2.4) * var(--pai) +
394
+ pow((var(--plr) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
395
+ ) / 3.14159265), 0.4167) - 0.055))
396
+ calc(255 * max(0, 1.055 * pow(min(1, (
397
+ pow((var(--pag) + 0.055) / 1.055, 2.4) * var(--pai) +
398
+ pow((var(--plg) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
399
+ ) / 3.14159265), 0.4167) - 0.055))
400
+ calc(255 * max(0, 1.055 * pow(min(1, (
401
+ pow((var(--pab) + 0.055) / 1.055, 2.4) * var(--pai) +
402
+ pow((var(--plb) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
403
+ ) / 3.14159265), 0.4167) - 0.055))
354
404
  );
355
405
  background-blend-mode: multiply;
356
406
  background-image: var(--polycss-atlas-url);
@@ -371,21 +421,55 @@
371
421
  .polycss-scene[data-polycss-lighting="dynamic"] b,
372
422
  .polycss-scene[data-polycss-lighting="dynamic"] i,
373
423
  .polycss-scene[data-polycss-lighting="dynamic"] u {
424
+ /*
425
+ * Three.js MeshLambertMaterial parity (default useLegacyLights=false,
426
+ * physically-correct pipeline):
427
+ *
428
+ * lit_linear = albedo_linear \xD7 (lightColor_linear \xD7 intensity \xD7 lambert
429
+ * + ambient_linear \xD7 ambientIntensity) / \u03C0
430
+ * output = 255 \xD7 sRGB_encode(min(1, lit_linear))
431
+ *
432
+ * sRGB\u2192linear: pow((c + 0.055) / 1.055, 2.4) for c > 0.04045
433
+ * 12.92 \xD7 c otherwise (skipped \u2014 tiny)
434
+ * linear\u2192sRGB: 1.055 \xD7 pow(c, 1/2.4) - 0.055 for c > 0.0031308
435
+ * 12.92 \xD7 c otherwise (skipped \u2014 tiny)
436
+ *
437
+ * The naive pow(c, 2.4) shortcut undershoots by ~2x for small c
438
+ * (dark channels of a saturated colour) \u2014 the +0.055/1.055 offset
439
+ * is load-bearing for the G/B drift on saturated fixtures.
440
+ *
441
+ * Verified against per-pixel screenshots in bench/three-parity.html
442
+ * (cube #dc2626 top face): drift <3 per channel across i=0.5..3,
443
+ * ambient=0..0.3, lambert=0..1.
444
+ */
374
445
  color: rgb(
375
- calc(255 * var(--psr) * (var(--par) * var(--pai)
376
- + var(--plr) * var(--pli) * var(--plam)))
377
- calc(255 * var(--psg) * (var(--pag) * var(--pai)
378
- + var(--plg) * var(--pli) * var(--plam)))
379
- calc(255 * var(--psb) * (var(--pab) * var(--pai)
380
- + var(--plb) * var(--pli) * var(--plam)))
446
+ calc(255 * max(0, 1.055 * pow(min(1,
447
+ pow((var(--psr) + 0.055) / 1.055, 2.4) * (
448
+ pow((var(--par) + 0.055) / 1.055, 2.4) * var(--pai) +
449
+ pow((var(--plr) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
450
+ ) / 3.14159265
451
+ ), 0.4167) - 0.055))
452
+ calc(255 * max(0, 1.055 * pow(min(1,
453
+ pow((var(--psg) + 0.055) / 1.055, 2.4) * (
454
+ pow((var(--pag) + 0.055) / 1.055, 2.4) * var(--pai) +
455
+ pow((var(--plg) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
456
+ ) / 3.14159265
457
+ ), 0.4167) - 0.055))
458
+ calc(255 * max(0, 1.055 * pow(min(1,
459
+ pow((var(--psb) + 0.055) / 1.055, 2.4) * (
460
+ pow((var(--pab) + 0.055) / 1.055, 2.4) * var(--pai) +
461
+ pow((var(--plb) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
462
+ ) / 3.14159265
463
+ ), 0.4167) - 0.055))
381
464
  );
382
465
  }
383
466
 
384
- /* \u2500\u2500 Cast shadow projection (dynamic-mode CSS path) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
467
+ /* \u2500\u2500 Retained <q> shadow projection (dynamic-mode CSS path) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
385
468
 
386
469
  /*
387
- * Shadow projection matrix. Projects any 3D point P onto the horizontal
388
- * ground plane (cssZ \u2248 G) along the CSS-space light direction (--clx/y/z).
470
+ * Projection matrix for retained internal <q> shadow leaves. Projects any
471
+ * 3D point P onto the horizontal ground plane (cssZ \u2248 G) along the CSS-space
472
+ * light direction (--clx/y/z).
389
473
  *
390
474
  * In PolyCSS's world convention world Z is up (red-green plane is the
391
475
  * floor in the axes helper). After the world\u2192CSS swap (Y\u2194X), world Z stays
@@ -398,7 +482,7 @@
398
482
  * has a valid layout box. The fix: collapse along z by a near-zero
399
483
  * scale (Z_SQUASH = 0.01) instead of exactly zero \u2014 output.z is then
400
484
  * approximately G with ~1% drift from the input, full-rank and renderable.
401
- * The shadow still looks flat to the eye (the drift is sub-pixel for
485
+ * The result still looks flat to the eye (the drift is sub-pixel for
402
486
  * any realistic scene size).
403
487
  *
404
488
  * out.cssX = P.cssX - (--clx/--clz) * (P.cssZ - G)
@@ -426,19 +510,10 @@
426
510
  );
427
511
  }
428
512
 
429
- /* <q> shadow leaf \u2014 Lambert-gated opacity. Polygons facing the light cast
430
- full shadow; polygons facing away cast zero shadow (their projection
431
- would stack inside the silhouette and produce ugly overdraw). The
432
- * 10 multiplier sharpens the cutoff so small positive Lambert values
433
- jump quickly to 1, giving a near-binary visibility decision with a
434
- smooth edge transition. Pure CSS calc \u2014 no JS at light-change time.
435
-
436
- Scoped to dynamic mode: baked-mode shadow leaves are dropped from the
437
- DOM up-front by isBakedShadowCaster() and don't carry --pnx/--pny/--pnz,
438
- so an unscoped gate would silently zero them via the @property
439
- initial values. The base layout / positioning / pseudo-element-strip
440
- rules for <q> live in the polygon-leaf section above. */
513
+ /* Retained <q> opacity gate. Polygons facing the light cast full shadow;
514
+ polygons facing away cast zero shadow. The * 10 multiplier sharpens the
515
+ cutoff so small positive Lambert values jump quickly to 1. */
441
516
  .polycss-scene[data-polycss-lighting="dynamic"] q {
442
517
  opacity: clamp(0, calc((var(--pnx) * var(--clx) + var(--pny) * var(--cly) + var(--pnz) * var(--clz)) * 10), 1);
443
518
  }
444
- `;var Xs=750;function qr(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:W.DEFAULT_SEAM_BLEED}}var Ws=1,Ke=W.BASE_TILE,Zs=Symbol.for("polycss.animation.triangleFrameTarget"),Qs={key:"non-cullable",normal:[1,1,0]};function Kr(){return[Qs]}function qs(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 Ks(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Js(e,n){return e===n?!0:(e?.color??"#000000")===(n?.color??"#000000")&&(e?.opacity??.25)===(n?.opacity??.25)&&(e?.lift??.05)===(n?.lift??.05)&&(e?.maxExtend??2e3)===(n?.maxExtend??2e3)}function Jr(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 ei(e,n=[0,0,0],t=1){let o=e.state,r=o.rotX,i=o.rotY,l=(o.zoom??Ws)*t,c=(o.distance??0)*t,a=o.target??[0,0,0],m=a[0]+n[0],f=a[1]+n[1],h=a[2]+n[2],g=f*Ke,x=m*Ke,y=h*Ke;return`${c!==0?`translateZ(${-c}px) `:""}scale(${l}) rotateX(${r}deg) rotate(${i}deg) translate3d(${-g}px, ${-x}px, ${-y}px)`}function el(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 tl(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=el(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function ti(e,n){return n===1?e:e*n}function nl(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}var ol=.1;function rl(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let h=1;h+1<e.vertices.length;h++){let g=e.vertices[h],x=e.vertices[h+1],y=g[1]-n[1],P=g[0]-n[0],v=g[2]-n[2],E=x[1]-n[1],H=x[0]-n[0],k=x[2]-n[2];t-=P*k-v*H,o-=v*E-y*k,r-=y*H-P*E}let i=Math.hypot(t,o,r);if(i<1e-9)return null;t/=i,o/=i,r/=i;let l=1/ol,c=Math.round(t*l)/l,a=Math.round(o*l)/l,m=Math.round(r*l)/l,f=Math.hypot(c,a,m);return f<1e-9?null:{key:c+","+a+","+m,vec:[c/f,a/f,m/f]}}function ni(e,n){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");if(!n?.camera)throw new Error("createPolyScene: a camera handle is required. Use createPolyCamera({...}) or createPolyPerspectiveCamera({...}) and pass as { camera }.");let t=n.camera;e.ownerDocument&&Qr(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...r}=n,i=qr({seamBleed:W.DEFAULT_SEAM_BLEED,...r}),l=tl(e),c=[0,0,0],a=e.ownerDocument??document,m=a.createElement("div");m.className="polycss-camera",z(m,i),e.appendChild(m);let f=a.createElement("div");f.className="polycss-scene",f.setAttribute("aria-hidden","true"),O(f,i),m.appendChild(f);let h=new Set,g=null,x=[];function y(){for(let s of x)s.parentNode&&s.parentNode.removeChild(s);x.length=0,k()}let P=new Map,v=new Map;function E(s){for(let d of s)d.svg&&d.svg.parentNode&&d.svg.parentNode.removeChild(d.svg),d.svg=null,d.path=null}function H(s){if(s){let d=P.get(s);d&&E(d),P.delete(s),v.delete(s)}else{for(let d of P.values())E(d);P.clear(),v.clear()}}function k(){for(let s of P.values())for(let d of s)d.svg&&d.visible&&(d.svg.style.display="none",d.visible=!1)}let N=new Map,R=new Map;function ee(s){s?(N.delete(s),R.delete(s)):(N.clear(),R.clear())}function z(s,d){let S=t.perspectiveStyle;if(S==="none")s.style.perspective=`${ti(1e6,l)}px`;else{let T=parseFloat(S);Number.isFinite(T)&&(s.style.perspective=`${ti(T,l)}px`)}}function O(s,d){nl(s,l),s.style.transform=ei(t,c,l),U(s,d)}function $(s){s.style.transform=ei(t,c,l)}function U(s,d){let S=d.textureLighting==="dynamic";s.dataset.polycssLighting=d.textureLighting??"baked";let T=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"];if(!S){for(let Ee of T)s.style.removeProperty(Ee);return}let I=d.directionalLight?.direction??[.4,-.7,.59],V=Math.hypot(I[0],I[1],I[2])||1,F=I[0]/V,K=I[1]/V,Y=I[2]/V,B=(0,W.parseHexColor)(d.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],ne=(0,W.parseHexColor)(d.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],j=d.directionalLight?.intensity??1,b=d.ambientLight?.intensity??.4,te=Ee=>(Ee/255).toFixed(4);s.style.setProperty("--plx",F.toFixed(4)),s.style.setProperty("--ply",K.toFixed(4)),s.style.setProperty("--plz",Y.toFixed(4)),s.style.setProperty("--plr",te(B[0])),s.style.setProperty("--plg",te(B[1])),s.style.setProperty("--plb",te(B[2])),s.style.setProperty("--pli",j.toFixed(4)),s.style.setProperty("--par",te(ne[0])),s.style.setProperty("--pag",te(ne[1])),s.style.setProperty("--pab",te(ne[2])),s.style.setProperty("--pai",b.toFixed(4));let Ae=Y,Le=Math.sign(Ae||1)*Math.max(Math.abs(Ae),.01);s.style.setProperty("--clx",F.toFixed(4)),s.style.setProperty("--cly",K.toFixed(4)),s.style.setProperty("--clz",Le.toFixed(4))}function le(s){s.voxelRenderer?.dispose(),s.voxelRenderer=void 0,C(s.rendered,s.disposeAtlas),s.disposeAtlas=void 0,s.rendered.length=0,s.renderedByPolygonIndex=[],s.cameraCullGroups=[],s.cameraCullSignature="",p(s);for(let d of Array.from(s.wrapper.children))d instanceof HTMLElement&&d.classList.contains("polycss-bucket")&&d.remove();s.hasBuckets=!1}function Ce(s){for(let d of Array.from(s.wrapper.childNodes)){if(!(d instanceof HTMLElement))return d;if(d.classList.contains("polycss-bucket")||d.classList.contains("polycss-shadow"))continue;let S=d.tagName.toLowerCase();if(!(S==="b"||S==="i"||S==="s"||S==="u"||S==="q"))return d}return null}function u(s,d,S){S?.parentNode===s.wrapper?s.wrapper.insertBefore(d,S):s.wrapper.appendChild(d)}function p(s){for(let d of s.shadowRendered)d.parentNode&&d.parentNode.removeChild(d);s.shadowRendered.length=0,y()}function C(s,d){d?.();for(let S of s){try{S.dispose()}catch{}S.element.parentNode&&S.element.parentNode.removeChild(S.element)}}function A(s,d,S){s.rendered=d,s.renderedByPolygonIndex=[];for(let T of d)s.renderedByPolygonIndex[T.polygonIndex]=T;s.disposeAtlas=S}function w(s,d){let S=s.renderedByPolygonIndex[d];return S?.polygonIndex===d?S:void 0}function M(s){for(let d of Array.from(s.wrapper.children))d instanceof HTMLElement&&d.classList.contains("polycss-bucket")&&d.remove();s.hasBuckets=!1;for(let d of s.rendered)d.element.parentNode&&d.element.parentNode.removeChild(d.element)}function ae(s,d){let S=s.polygons[d.polygonIndex];return s.stableDom&&S?(0,W.polygonCssSurfaceNormal)(S):d.plan?.normal??(S?(0,W.polygonCssSurfaceNormal)(S):null)}function ve(s){if(!we(s))return s.rendered;let d=_(s);return s.rendered.filter(S=>re(s,S,W.CAMERA_BACKFACE_CULL_EPS,d))}function _(s){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:s.handle.transform.rotation}}function re(s,d,S=W.CAMERA_BACKFACE_CULL_EPS,T=_(s)){let I=ae(s,d);return I===null||(0,W.normalFacesCamera)(I,T,S)}function ie(s){if(s.excludeFromAutoCenter){s.cameraCullGroups=[];return}let d=new Map;for(let S of s.rendered){let T=ae(s,S);if(!T)continue;if(!(0,W.isAxisAlignedSurfaceNormal)(T)){s.cameraCullGroups=Kr();return}let I=(0,W.cameraCullNormalKey)(T);if(!d.has(I)&&(d.set(I,T),d.size>W.VOXEL_CAMERA_CULL_NORMAL_LIMIT)){s.cameraCullGroups=Kr();return}}s.cameraCullGroups=Array.from(d,([S,T])=>({key:S,normal:T}))}function Te(s){return we(s)?(0,W.cameraCullVisibleSignature)(s.cameraCullGroups,_(s)):"all"}function we(s){return!s.excludeFromAutoCenter&&(0,W.isVoxelCameraCullableNormalGroups)(s.cameraCullGroups)}function He(s){s.cameraCullSignature=we(s)?Te(s):"all"}function Ne(s,d){let S=new Array(s.rendered.length),T=!1,I=_(s);for(let j=0;j<s.rendered.length;j+=1){let b=s.rendered[j],te=re(s,b,d,I);S[j]=te}let V=null,F=null,K=()=>{if(!(!V||!F)){if(V===F)V.remove();else{let j=a.createRange();j.setStartBefore(V),j.setEndAfter(F),j.deleteContents(),j.detach()}V=null,F=null,T=!0}};for(let j=0;j<s.rendered.length;j+=1){let b=s.rendered[j];!S[j]&&b.element.parentNode===s.wrapper?(F&&F.nextSibling===b.element||(K(),V=b.element),F=b.element):K()}K();let Y=j=>{for(let b=j;b<s.rendered.length;b+=1){let te=s.rendered[b].element;if(te.parentNode===s.wrapper)return te}return Ce(s)},B=-1,ne=j=>{if(B<0)return;let b=a.createDocumentFragment();for(let te=B;te<j;te+=1){let Ae=s.rendered[te];je(s,Ae),b.appendChild(Ae.element)}u(s,b,Y(j)),B=-1,T=!0};for(let j=0;j<s.rendered.length;j+=1){let b=s.rendered[j];S[j]&&b.element.parentNode!==s.wrapper?B<0&&(B=j):ne(j)}return ne(s.rendered.length),T}function Oe(s,d=!1){if(s.voxelRenderer){d?s.voxelRenderer.render(_(s)):s.voxelRenderer.syncCamera(_(s)),s.cameraCullSignature="voxel-direct";return}if(!we(s)){let I=s.cameraCullSignature!=="all";s.cameraCullSignature="all",I&&Ie(s);return}if(s.hasBuckets){Ue(s,d);return}let S=Te(s);if(!d&&S===s.cameraCullSignature)return;let T=Ne(s,W.CAMERA_BACKFACE_CULL_EPS);s.cameraCullSignature=S,T&&de(s)}function Ue(s,d=!1){let S=we(s)?Te(s):"all";!d&&S===s.cameraCullSignature||Ie(s)}function rt(s,d){return ae(s,d)}function je(s,d){if(i.textureLighting!=="dynamic")return;let S=rt(s,d);S&&(d.element.style.setProperty("--pnx",S[0].toFixed(4)),d.element.style.setProperty("--pny",S[1].toFixed(4)),d.element.style.setProperty("--pnz",S[2].toFixed(4)))}function qe(s){M(s),s.hasBuckets=!1;let d=s.skipBucketNormalCleanupOnce;s.skipBucketNormalCleanupOnce=!1;let S=a.createDocumentFragment(),T=i.textureLighting==="dynamic"&&!s.stableDom,I=new Map,V=[];for(let F of ve(s)){let K=s.polygons[F.polygonIndex],Y=T&&K?rl(K):null;if(!Y){V.push(F);continue}let B=Y.key+"|"+(K.color??""),ne=I.get(B);ne||(ne={vec:Y.vec,items:[]},I.set(B,ne)),ne.items.push(F)}for(let F of V)je(s,F),S.appendChild(F.element);for(let F of I.values()){if(F.items.length<2){for(let Y of F.items)je(s,Y),S.appendChild(Y.element);continue}let K=a.createElement("div");K.className="polycss-bucket",s.hasBuckets=!0,K.style.setProperty("--pnx",String(F.vec[0])),K.style.setProperty("--pny",String(F.vec[1])),K.style.setProperty("--pnz",String(F.vec[2]));for(let Y of F.items)K.appendChild(Y.element),(!d||Y.kind==="triangle")&&(Y.element.style.removeProperty("--pnx"),Y.element.style.removeProperty("--pny"),Y.element.style.removeProperty("--pnz"));S.appendChild(K)}u(s,S,Ce(s)),He(s)}function Zt(){return new Promise(s=>setTimeout(s,0))}async function Qt(s,d){if(i.textureLighting==="dynamic"&&!s.stableDom)return qe(s),!d();M(s);let T=a.createDocumentFragment(),I=Ce(s),V=0;for(let F of ve(s)){if(d())return!1;je(s,F),T.appendChild(F.element),V++,V%Xs===0&&(u(s,T,I),T=a.createDocumentFragment(),await Zt())}return T.childNodes.length>0&&u(s,T,I),He(s),!d()}function mt(s,d){let S=i.textureLighting==="dynamic",T=i.directionalLight?.direction,I=d&&(d[0]!==0||d[1]!==0||d[2]!==0);if(!S||!I||!T){if(s.lightOverrideSignature==="clear")return;s.wrapper.style.removeProperty("--plx"),s.wrapper.style.removeProperty("--ply"),s.wrapper.style.removeProperty("--plz"),s.lightOverrideSignature="clear";return}let V=(0,W.inverseRotateVec3)(T,d),F=Math.hypot(V[0],V[1],V[2])||1,K=(V[0]/F).toFixed(4),Y=(V[1]/F).toFixed(4),B=(V[2]/F).toFixed(4),ne=`${K}|${Y}|${B}`;s.lightOverrideSignature!==ne&&(s.wrapper.style.setProperty("--plx",K),s.wrapper.style.setProperty("--ply",Y),s.wrapper.style.setProperty("--plz",B),s.lightOverrideSignature=ne)}function Ct(s,d){d.paintColor?s.style.setProperty("--polycss-paint",d.paintColor):s.style.getPropertyValue("--polycss-paint")&&s.style.removeProperty("--polycss-paint"),d.dynamicColor?(s.style.setProperty("--psr",(d.dynamicColor.r/255).toFixed(4)),s.style.setProperty("--psg",(d.dynamicColor.g/255).toFixed(4)),s.style.setProperty("--psb",(d.dynamicColor.b/255).toFixed(4))):(s.style.getPropertyValue("--psr")||s.style.getPropertyValue("--psg")||s.style.getPropertyValue("--psb"))&&(s.style.removeProperty("--psr"),s.style.removeProperty("--psg"),s.style.removeProperty("--psb"))}function ho(s,d){let S=(0,W.parseHex)(d??"#cccccc");s.style.setProperty("--psr",(S.r/255).toFixed(4)),s.style.setProperty("--psg",(S.g/255).toFixed(4)),s.style.setProperty("--psb",(S.b/255).toFixed(4))}function yo(s,d){if(!s.plan||s.kind==="atlas"||s.plan.texture)return!1;let S=i.textureLighting??"baked",T={directionalLight:i.directionalLight,ambientLight:i.ambientLight,textureLighting:S,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies},I=wo(s.plan,d,s.plan.normal,S,T);return Ht(s.element,I,S),!0}function bo(s,d,S){let T=s.polygons[d];if(!T)return!1;let I=w(s,d);if(!I)return!1;let V=i.textureLighting??"baked";return V==="dynamic"?(ho(I.element,S),!0):V==="baked"?yo(I,T):!1}function G(s,d){let S=s.polygons[d];if(!S)return!1;let T=w(s,d);return T?(ze(T.element,S),!0):!1}function be(s,d,S){return!(S.length===0||!S.every(T=>T==="color"||T==="data")||S.includes("color")&&!bo(s,d,s.polygons[d]?.color)||S.includes("data")&&!G(s,d))}function de(s){De()}function De(){y();let s=[];for(let B of h)!B.disposed&&B.castShadow&&s.push(B);if(s.length===0)return;let d=i.shadow?.color??"#000000",S=i.shadow?.opacity??.25,T=(0,W.parseHexColor)(d)?.rgb??[0,0,0],I=T[0],V=T[1],F=T[2],K=i.directionalLight?.direction??[.4,-.7,.59],Y=new Map;for(let B of s)Y.set(B,(0,W.findOverlappingPolygonDuplicates)(B.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.4,preserveDoubleSidedBackfaces:!1}));g!==null&&qt(s,Y,K,g,I,V,F,S);for(let B of h)B.disposed||!B.receiveShadow||Et(s,Y,B,K,I,V,F,S)}function qt(s,d,S,T,I,V,F,K){let Y=[],B=1/0,ne=1/0,j=-1/0,b=-1/0,te=1/0,Ae=1/0,Le=-1/0,Ee=-1/0;for(let pe of s){let fe=pe.handle.transform.position??[0,0,0],ye=d.get(pe);for(let it of pe.rendered){if(ye.has(it.polygonIndex)||!it.plan)continue;let Jt=pe.polygons[it.polygonIndex];if(!Jt)continue;let bt=[];for(let vt of Jt.vertices){let _e=[vt[1]*Ke+fe[0],vt[0]*Ke+fe[1],vt[2]*Ke+fe[2]];_e[0]<te&&(te=_e[0]),_e[1]<Ae&&(Ae=_e[1]),_e[0]>Le&&(Le=_e[0]),_e[1]>Ee&&(Ee=_e[1]);let ke=(0,W.projectCssVertexToGround)(_e,S,T);bt.push(ke),ke[0]<B&&(B=ke[0]),ke[1]<ne&&(ne=ke[1]),ke[0]>j&&(j=ke[0]),ke[1]>b&&(b=ke[1])}let $e=bt.length>3?(0,W.convexHull2D)(bt):bt;$e.length>=3&&Y.push($e)}}if(Y.length===0)return;let ge=i.shadow?.maxExtend??2e3,Z=Math.max(B,te-ge),me=Math.max(ne,Ae-ge),oe=Math.min(j,Le+ge),L=Math.min(b,Ee+ge),D=oe-Z,Q=L-me;if(!(D>0)||!(Q>0))return;let se="";for(let pe of Y){let fe=(0,W.ensureCcw2D)(pe);se+=`M${(fe[0][0]-Z).toFixed(3)},${(fe[0][1]-me).toFixed(3)}`;for(let ye=1;ye<fe.length;ye++)se+=`L${(fe[ye][0]-Z).toFixed(3)},${(fe[ye][1]-me).toFixed(3)}`;se+="Z"}let he="http://www.w3.org/2000/svg",X=a.createElementNS(he,"svg");X.setAttribute("class","polycss-shadow polycss-shadow-svg"),X.setAttribute("width",String(D)),X.setAttribute("height",String(Q)),X.setAttribute("viewBox",`0 0 ${D} ${Q}`),X.setAttribute("style",`position:absolute;top:0;left:0;display:block;overflow:hidden;transform-origin:0 0;pointer-events:none;will-change:transform;transform:translate3d(${Z.toFixed(3)}px,${me.toFixed(3)}px,${T.toFixed(3)}px)`);let q=a.createElementNS(he,"path");q.setAttribute("d",se);let xe=`rgb(${I},${V},${F})`;q.setAttribute("fill",xe),q.setAttribute("fill-rule","nonzero"),q.setAttribute("stroke",xe),q.setAttribute("stroke-width","2"),q.setAttribute("stroke-linejoin","round"),q.setAttribute("opacity",K.toFixed(4)),X.appendChild(q),x.push(X);let Pe=f.firstChild;Pe?f.insertBefore(X,Pe):f.appendChild(X)}function Kt(s,d,S){let T=[];for(let Y of s.polygons){if(Y.vertices.length<3)continue;let B=S(Y.vertices[0],d),ne=S(Y.vertices[1],d),j=S(Y.vertices[2],d),b=[ne[0]-B[0],ne[1]-B[1],ne[2]-B[2]],te=[j[0]-B[0],j[1]-B[1],j[2]-B[2]],Ae=te[1]*b[2]-te[2]*b[1],Le=te[2]*b[0]-te[0]*b[2],Ee=te[0]*b[1]-te[1]*b[0],ge=Math.hypot(Ae,Le,Ee);if(ge<1e-9)continue;let Z=[Ae/ge,Le/ge,Ee/ge],me=Math.hypot(b[0],b[1],b[2]);if(me<1e-9)continue;let oe=[b[0]/me,b[1]/me,b[2]/me],L=[Z[1]*oe[2]-Z[2]*oe[1],Z[2]*oe[0]-Z[0]*oe[2],Z[0]*oe[1]-Z[1]*oe[0]],D=Z[0]*B[0]+Z[1]*B[1]+Z[2]*B[2];T.push({face:Y,O:B,n:Z,u:oe,v:L,offset:D})}let I=.001,V=.5,F=[];for(let Y of T){let B=!1;for(let ne of F){let j=ne.rep;if(!(1-(Y.n[0]*j.n[0]+Y.n[1]*j.n[1]+Y.n[2]*j.n[2])>I)&&!(Math.abs(Y.offset-j.offset)>V)){ne.faces.push(Y),B=!0;break}}B||F.push({rep:Y,faces:[Y]})}let K=[];for(let Y of F){let{O:B,n:ne,u:j,v:b}=Y.rep,te=[];for(let Le of Y.faces)for(let Ee of Le.face.vertices){let ge=S(Ee,d),Z=ge[0]-B[0],me=ge[1]-B[1],oe=ge[2]-B[2];te.push([Z*j[0]+me*j[1]+oe*j[2],Z*b[0]+me*b[1]+oe*b[2]])}if(te.length<3)continue;let Ae=(0,W.convexHull2D)(te);Ae.length<3||K.push({O:B,n:ne,u:j,v:b,outlineUv:(0,W.ensureCcw2D)(Ae)})}return K}function Et(s,d,S,T,I,V,F,K){let Y=Math.hypot(T[0],T[1],T[2])||1,B=T[0]/Y,ne=T[1]/Y,j=T[2]/Y,b="http://www.w3.org/2000/svg",te=S.handle.transform.position??[0,0,0],Ae=(Z,me)=>[Z[1]*Ke+me[0],Z[0]*Ke+me[1],Z[2]*Ke+me[2]],Le=`${S.polygons.length}|${te.join(",")}`,Ee=P.get(S);(Ee===void 0||v.get(S)!==Le)&&(Ee=Kt(S,te,Ae).map(me=>{let{O:oe,n:L,u:D,v:Q,outlineUv:se}=me,he=1/0,X=1/0,q=-1/0,xe=-1/0;for(let $e of se)$e[0]<he&&(he=$e[0]),$e[1]<X&&(X=$e[1]),$e[0]>q&&(q=$e[0]),$e[1]>xe&&(xe=$e[1]);let Pe=q-he,pe=xe-X,fe=5,ye=oe[0]+he*D[0]+X*Q[0]+fe*L[0],it=oe[1]+he*D[1]+X*Q[1]+fe*L[1],Fe=oe[2]+he*D[2]+X*Q[2]+fe*L[2],bt=`matrix3d(${[D[0],D[1],D[2],0,Q[0],Q[1],Q[2],0,L[0],L[1],L[2],0,ye,it,Fe,1].map($e=>$e.toFixed(4)).join(",")})`;return{O:oe,n:L,u:D,v:Q,outlineUv:se,minU:he,minV:X,width:Pe,height:pe,matrixCss:bt,svg:null,path:null,visible:!1}}),P.set(S,Ee),v.set(S,Le));let ge=[];for(let Z of s){if(Z===S)continue;let me=Z.handle.transform.position??[0,0,0],oe=`${Z.polygons.length}|${me.join(",")}`,L=N.get(Z);if(L===void 0||R.get(Z)!==oe){let D=d.get(Z);L=[];for(let Q of Z.rendered){if(D.has(Q.polygonIndex)||!Q.plan)continue;let he=Z.polygons[Q.polygonIndex];if(!he)continue;let X=he.vertices.map(Fe=>Ae(Fe,me)),q=1/0,xe=1/0,Pe=1/0,pe=-1/0,fe=-1/0,ye=-1/0;for(let Fe of X)Fe[0]<q&&(q=Fe[0]),Fe[0]>pe&&(pe=Fe[0]),Fe[1]<xe&&(xe=Fe[1]),Fe[1]>fe&&(fe=Fe[1]),Fe[2]<Pe&&(Pe=Fe[2]),Fe[2]>ye&&(ye=Fe[2]);let it=[[q,xe,Pe],[pe,xe,Pe],[q,fe,Pe],[pe,fe,Pe],[q,xe,ye],[pe,xe,ye],[q,fe,ye],[pe,fe,ye]];L.push({wv:X,bboxCorners:it})}N.set(Z,L),R.set(Z,oe)}for(let D of L)ge.push(D)}for(let Z of Ee){let{O:me,n:oe,u:L,v:D,outlineUv:Q,minU:se,minV:he,width:X,height:q,matrixCss:xe}=Z,Pe=B*oe[0]+ne*oe[1]+j*oe[2];if(Pe<=1e-6)continue;let pe=Se=>(Se[0]-me[0])*oe[0]+(Se[1]-me[1])*oe[1]+(Se[2]-me[2])*oe[2],fe=(Se,tt,Tt,At)=>{let st=Tt/(Tt-At);return[Se[0]+st*(tt[0]-Se[0]),Se[1]+st*(tt[1]-Se[1]),Se[2]+st*(tt[2]-Se[2])]},ye=Se=>{let tt=Se[0]-me[0],Tt=Se[1]-me[1],At=Se[2]-me[2],st=(tt*oe[0]+Tt*oe[1]+At*oe[2])/Pe,en=Se[0]-st*B,tn=Se[1]-st*ne,Rt=Se[2]-st*j,lt=en-me[0],xt=tn-me[1],We=Rt-me[2];return[lt*L[0]+xt*L[1]+We*L[2],lt*D[0]+xt*D[1]+We*D[2]]},it=[],Fe=se,Jt=he,bt=Z.minU+X,$e=Z.minV+q;for(let Se of ge){let tt=Se.bboxCorners,Tt=!1,At=1/0,st=1/0,en=-1/0,tn=-1/0;for(let lt=0;lt<8;lt++){let xt=tt[lt];pe(xt)>=0&&(Tt=!0);let We=ye(xt);We[0]<At&&(At=We[0]),We[0]>en&&(en=We[0]),We[1]<st&&(st=We[1]),We[1]>tn&&(tn=We[1])}if(!Tt||en<Fe||At>bt||tn<Jt||st>$e)continue;let Rt=Se.wv;for(let lt=1;lt<Rt.length-1;lt++){let xt=Rt[0],We=Rt[lt],tr=Rt[lt+1],Oi=pe(xt),Fi=pe(We),Hi=pe(tr),Bn=[],nr=[[xt,Oi],[We,Fi],[tr,Hi]];for(let Nn=0;Nn<3;Nn++){let[rr,So]=nr[Nn],[zi,ir]=nr[(Nn+1)%3];So>=0&&Bn.push(rr),So>=0!=ir>=0&&Bn.push(fe(rr,zi,So,ir))}if(Bn.length<3)continue;let Ii=Bn.map(ye),Vi=(0,W.ensureCcw2D)(Ii),or=(0,W.clipPolygonToConvex2D)(Vi,Q);or.length<3||it.push(or)}}if(it.length===0||!(X>0)||!(q>0))continue;let vt="";for(let Se of it){vt+=`M${(Se[0][0]-se).toFixed(1)},${(Se[0][1]-he).toFixed(1)}`;for(let tt=1;tt<Se.length;tt++)vt+=`L${(Se[tt][0]-se).toFixed(1)},${(Se[tt][1]-he).toFixed(1)}`;vt+="Z"}let _e=Z.svg,ke=Z.path;!_e||!ke?(_e=a.createElementNS(b,"svg"),_e.setAttribute("class","polycss-shadow polycss-shadow-svg polycss-shadow-receiver"),_e.setAttribute("width",String(X)),_e.setAttribute("height",String(q)),_e.setAttribute("viewBox",`0 0 ${X} ${q}`),_e.setAttribute("style",`position:absolute;top:0;left:0;display:block;overflow:hidden;transform-origin:0 0;pointer-events:none;will-change:transform;transform:${xe}`),ke=a.createElementNS(b,"path"),ke.setAttribute("fill-rule","nonzero"),_e.appendChild(ke),f.insertBefore(_e,f.firstChild),Z.svg=_e,Z.path=ke):Z.visible||(_e.style.display="block"),Z.visible=!0,ke.setAttribute("d",vt);let Jo=`rgb(${I},${V},${F})`;ke.getAttribute("fill")!==Jo&&ke.setAttribute("fill",Jo);let er=K.toFixed(4);ke.getAttribute("opacity")!==er&&ke.setAttribute("opacity",er)}}function Ie(s){if(s.voxelRenderer){s.voxelRenderer.render(_(s)),s.cameraCullSignature="voxel-direct";return}p(s),qe(s),de(s)}function et(s){return!!s.voxelSource&&i.textureLighting!=="dynamic"&&!s.stableDom&&!s.castShadow}function Be(s,d){le(s);let S=i.directionalLight,T=d?{...S,direction:d}:S;if(et(s)){let F=Wr({doc:a,wrapper:s.wrapper,polygons:s.parseResult.polygons,directionalLight:T,ambientLight:i.ambientLight});if(F){s.voxelRenderer=F,F.render(_(s)),s.cameraCullSignature="voxel-direct";return}}let I={doc:a,directionalLight:T,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies},V=s.stableDom?(()=>{let F=Nt(s.polygons,I);return Ct(s.wrapper,F),un(s.polygons,{...I,solidPaintDefaults:F})??dn(s.polygons,{...I,solidPaintDefaults:F})})():dn(s.polygons,{...I,computeSolidPaintDefaults:!0,skipDynamicNormalVars:i.textureLighting==="dynamic"});s.stableDom||Ct(s.wrapper,V.solidPaintDefaults??{}),A(s,V.rendered,V.dispose),s.skipBucketNormalCleanupOnce=i.textureLighting==="dynamic"&&!s.stableDom,ie(s),qe(s),de(s)}function Xe(){let s=1/0,d=!1;for(let V of h)if(!V.disposed&&V.receiveShadow){d=!0;break}for(let V of h){if(V.disposed||!(d?V.receiveShadow:V.castShadow))continue;let K=V.handle.transform.position?.[2]??0;for(let Y of V.polygons)for(let B of Y.vertices){let ne=B[2]+K;ne<s&&(s=ne)}}if(!Number.isFinite(s)){let V=g!==null;g=null,V&&y();return}let S=i.shadow?.lift??.05,T=(s+S)*Ke,I=g;g=T,I!==T&&De()}async function vo(s,d){le(s);let S={doc:a,directionalLight:i.directionalLight,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies},T=s.stableDom?un(s.polygons,S):null;if(T){let F=Nt(s.polygons,S);return Ct(s.wrapper,F),A(s,T.rendered,T.dispose),ie(s),qe(s),de(s),!d()}let I=await Kn(s.polygons,{...S,skipDynamicNormalVars:i.textureLighting==="dynamic"},d);if(d())return I.dispose(),!1;Ct(s.wrapper,I.solidPaintDefaults),A(s,I.rendered,I.dispose),s.skipBucketNormalCleanupOnce=i.textureLighting==="dynamic"&&!s.stableDom,ie(s);let V=await Qt(s,d);return V&&de(s),V}function pt(){let s=c,d=[0,0,0];if(i.autoCenter){let S=[];for(let T of h)!T.disposed&&!T.excludeFromAutoCenter&&S.push(...T.polygons);if(S.length>0){let T=(0,W.computeSceneBbox)(S);d=[(T.min[0]+T.max[0])/2,(T.min[1]+T.max[1])/2,(T.min[2]+T.max[2])/2]}}s[0]===d[0]&&s[1]===d[1]&&s[2]===d[2]||(c=d,O(f,i))}function xo(s,d={}){let T=(f.ownerDocument??document).createElement("div");T.className="polycss-mesh",d.id&&T.setAttribute("data-poly-mesh-id",d.id);let I={...d},V=d.merge!==!1,F=!!d.stableDom,K=0,Y=Jr(I);Y&&(T.style.transform=Y);let B=(L,D)=>s.voxelSource||!D?L:(0,W.optimizeMeshPolygons)(L,{meshResolution:d.meshResolution}),ne=B(s.polygons,V);function j(L){if(L.length===0){T.style.removeProperty("--origin");return}let D=1/0,Q=1/0,se=1/0,he=-1/0,X=-1/0,q=-1/0;for(let fe of L)for(let ye of fe.vertices)ye[0]<D&&(D=ye[0]),ye[0]>he&&(he=ye[0]),ye[1]<Q&&(Q=ye[1]),ye[1]>X&&(X=ye[1]),ye[2]<se&&(se=ye[2]),ye[2]>q&&(q=ye[2]);if(!Number.isFinite(D)){T.style.removeProperty("--origin");return}let xe=(Q+X)/2*Ke,Pe=(D+he)/2*Ke,pe=(se+q)/2*Ke;T.style.setProperty("--origin",`${xe}px ${Pe}px ${pe}px`)}j(ne),f.appendChild(T);let b={handle:void 0,wrapper:T,parseResult:s,rendered:[],renderedByPolygonIndex:[],shadowRendered:[],polygons:ne,voxelSource:s.voxelSource,disposed:!1,stableDom:F,hasBuckets:!1,skipBucketNormalCleanupOnce:!1,excludeFromAutoCenter:!!d.excludeFromAutoCenter,castShadow:!!d.castShadow,receiveShadow:!!d.receiveShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",stableTriangleColorFrame:0,bakedRotation:d.rotation?[...d.rotation]:[0,0,0]},te=null,Ae=0,Le=-1,Ee=null;function ge(){te=null,Ee=null,Le=-1}function Z(){let L=te;if(!L||L.polygonCount!==b.polygons.length)return b.polygons;if(Ee&&Le===Ae)return Ee;let D=L.vertices,Q=new Array(L.polygonCount);for(let se=0;se<L.polygonCount;se++){let he=b.polygons[se],X=se*9;Q[se]={...he,color:L.colors?.[se]??he.color,vertices:[[D[X],D[X+1],D[X+2]],[D[X+3],D[X+4],D[X+5]],[D[X+6],D[X+7],D[X+8]]]}}return Ee=Q,Le=Ae,Q}function me(L,D){let Q=L?.stableTriangleUpdateMode==="color-only";b.stableTriangleColorFrame++;let se=b.stableDom&&!D;if(se||j(b.polygons),b.stableDom&&!b.hasBuckets){let he={doc:a,directionalLight:i.directionalLight,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed},X=b.rendered.length===b.polygons.length&&b.rendered.every(pe=>pe.kind==="triangle"),q=b.stableDom&&!D,xe=X||q?{}:Nt(b.polygons,he);X||Ct(b.wrapper,xe);let Pe={...he,solidPaintDefaults:xe,optimizeStableTriangleStyle:!0,stableTriangleDebug:L?.stableTriangleDebug,stableTriangleUpdateMode:L?.stableTriangleUpdateMode,stableTriangleColorPolicy:L?.stableTriangleColorPolicy,stableTriangleColorSteps:L?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:L?.stableTriangleColorFreezeFrames,stableTriangleColorBudget:L?.stableTriangleColorBudget,stableTriangleColorMaxAge:L?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:L?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:L?.stableTriangleMatrixDecimals,stableTriangleColorFrame:b.stableTriangleColorFrame};if(eo(b.rendered,b.polygons,Pe))return Q||(ie(b),Oe(b,!0),D&&pt()),!0}return se&&j(b.polygons),!1}let oe={get polygons(){return Z()},set polygons(L){ge(),b.polygons=L},element:T,id:d.id,get transform(){return I},remove(){K++,T.parentNode&&T.parentNode.removeChild(T),le(b),h.delete(b),H(b),ee(b),pt(),Xe()},setPolygons(L,D){K++,V=D?.merge??V,F=D?.stableDom??F,b.stableDom=F,b.voxelSource=void 0,b.polygons=B(L,V),ee(b),H(b),ge(),oe.polygons=b.polygons;let Q=D?.recomputeAutoCenter??!0;me(D,Q)||(Be(b),Q&&pt())},[Zs](L,D){let Q=D?.merge??V,se=D?.stableDom??F;if(!L.solidTriangles||!se||Q||d.meshResolution!==void 0||b.hasBuckets||L.polygonCount!==b.polygons.length||L.vertices.length<L.polygonCount*9||b.rendered.length!==L.polygonCount)return!1;for(let q=0;q<b.rendered.length;q++){let xe=b.rendered[q],Pe=b.polygons[q];if(xe?.kind!=="triangle"||xe.polygonIndex!==q||!Pe||Pe.vertices.length!==3||Pe.texture||Pe.material?.texture)return!1}let he=D?.recomputeAutoCenter??!0;if(!he){let q=b.stableTriangleColorFrame+1,xe={doc:a,directionalLight:i.directionalLight,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,solidPaintDefaults:{},optimizeStableTriangleStyle:!0,stableTriangleDebug:D?.stableTriangleDebug,stableTriangleUpdateMode:D?.stableTriangleUpdateMode,stableTriangleColorPolicy:D?.stableTriangleColorPolicy,stableTriangleColorSteps:D?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:D?.stableTriangleColorFreezeFrames??0,stableTriangleColorBudget:D?.stableTriangleColorBudget,stableTriangleColorMaxAge:D?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:D?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:D?.stableTriangleMatrixDecimals,stableTriangleColorFrame:q};if(Jn(b.rendered,b.polygons,L,xe))return K++,V=Q,F=se,b.stableDom=F,b.voxelSource=void 0,b.stableTriangleColorFrame=q,te=L,Ae++,Ee=null,Le=-1,we(b)?(ie(b),Oe(b,!0)):He(b),!0}K++,V=Q,F=se,b.stableDom=F,b.voxelSource=void 0;let X=L.vertices;for(let q=0;q<L.polygonCount;q++){let xe=b.polygons[q],Pe=L.colors?.[q];Pe&&(xe.color=Pe);let pe=xe.vertices,fe=q*9;pe[0][0]=X[fe],pe[0][1]=X[fe+1],pe[0][2]=X[fe+2],pe[1][0]=X[fe+3],pe[1][1]=X[fe+4],pe[1][2]=X[fe+5],pe[2][0]=X[fe+6],pe[2][1]=X[fe+7],pe[2][2]=X[fe+8]}return ge(),oe.polygons=b.polygons,me(D,he)},updatePolygon(L,D){let Q=typeof L=="number"?L:b.polygons.indexOf(L);if(Q<0&&typeof L!="number"&&te&&(Q=Z().indexOf(L)),Q<0||Q>=b.polygons.length)return;ge(),b.voxelSource=void 0,Object.assign(b.polygons[Q],D);let se=Object.keys(D);be(b,Q,se)||Be(b)},async setPolygonsChunked(L,D){let Q=++K;V=D?.merge??V,F=D?.stableDom??F,b.stableDom=F,b.voxelSource=void 0,b.polygons=B(L,V),ge(),oe.polygons=b.polygons,j(b.polygons);let se=D?.recomputeAutoCenter??!0;if(!await vo(b,()=>b.disposed||Q!==K)){le(b);return}se&&pt()},setTransform(L){let D=b.castShadow,Q=b.receiveShadow;L.castShadow!==void 0&&(b.castShadow=!!L.castShadow),L.receiveShadow!==void 0&&(b.receiveShadow=!!L.receiveShadow),I={...I,...L};let se=Jr(I);T.style.transform=se??"",mt(b,I.rotation),L.rotation!==void 0&&Oe(b,!0),b.castShadow!==D&&(de(b),Xe()),b.receiveShadow!==Q&&De(),L.position!==void 0&&(Xe(),De())},dispose(){if(!b.disposed){b.disposed=!0,K++,T.parentNode&&T.parentNode.removeChild(T),le(b);try{s.dispose()}catch{}h.delete(b),pt(),Xe()}},rebakeAtlas(){b.bakedRotation=I.rotation?[...I.rotation]:[0,0,0];let L=i.directionalLight?.direction??[.4,-.7,.59],D=(0,W.inverseRotateVec3)(L,b.bakedRotation);Be(b,D)},getPosition(){return I.position},getRotation(){return I.rotation},getScale(){return I.scale},getPolygons(){return oe.polygons}};return b.handle=oe,h.add(b),Be(b),mt(b,I.rotation),pt(),Xe(),b.receiveShadow&&De(),oe}function Po(s){let d=!!i.autoCenter,S=i.strategies,T=i.seamBleed,I=i.textureLighting,V=i.directionalLight?.direction,F=i.shadow,K=qr(s);i={...i,...K},O(f,i);let Y=!!i.autoCenter;for(let ge of h)mt(ge,ge.handle.transform.rotation);let B=s.strategies!==void 0&&!qs(s.strategies,S),ne=Object.prototype.hasOwnProperty.call(s,"seamBleed")&&K.seamBleed!==T;if(B||ne)for(let ge of h)Be(ge);d!==Y&&pt();let j=s.textureLighting!==void 0&&I!==i.textureLighting,b=i.directionalLight?.direction,te=s.directionalLight!==void 0&&!Ks(V,b),Ae=i.shadow,Le=s.shadow!==void 0&&!Js(F,Ae),Ee=te||Le;if(j){for(let ge of h)!B&&!ne&&(ge.voxelSource||ge.voxelRenderer)&&Be(ge);Xe(),De()}else Ee&&De();Le&&s.shadow?.lift!==F?.lift&&Xe()}function Vn(){return i}function zn(){$(f);for(let s of h)Oe(s)}function Ri(){let s=[];for(let d of h)s.push(d.handle);return s}function Di(s){let d=s;for(;d;){if(d instanceof HTMLElement&&d.classList.contains("polycss-mesh")){for(let S of h)if(S.wrapper===d)return S.handle;return null}d=d.parentElement}return null}function ki(){let s=Array.from(h);for(let d of s)try{d.handle.dispose()}catch{}m.parentNode&&m.parentNode.removeChild(m)}return{add:xo,setOptions:Po,destroy:ki,host:e,camera:t,cameraEl:m,applyCamera:zn,getOptions:Vn,meshes:Ri,findMeshByElement:Di}}var Yo=require("@layoutit/polycss-core"),il=8e3;function mn(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,Yo.createIsometricCamera)(n),o=`${e.perspective??il}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function pn(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,Yo.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var sl=typeof HTMLElement<"u"?HTMLElement:class{},ll=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function ot(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function al(e){return e==="false"?!1:ot(e)}function jo(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 cl(e){if(e==="baked"||e==="dynamic")return e}function ul(e){return e==="auto"?"auto":ot(e)}function dl(e){return typeof e.getCamera=="function"}var Ge=class extends sl{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...ll]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(dl(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=al(this.getAttribute("perspective")),o=ot(this.getAttribute("rot-x")),r=ot(this.getAttribute("rot-y")),i=ot(this.getAttribute("zoom")),l=ot(this.getAttribute("distance")),c=jo(this.getAttribute("target")),a={...o!==void 0?{rotX:o}:{},...r!==void 0?{rotY:r}:{},...i!==void 0?{zoom:i}:{},...l!==void 0?{distance:l}:{},...c!==void 0?{target:c}:{}};return t===!1?pn(a):t!==void 0?mn({...a,perspective:t}):pn(a)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={};r.textureLighting=cl(this.getAttribute("texture-lighting"))??"baked";let i=ul(this.getAttribute("texture-quality"));return i!==void 0&&(r.textureQuality=i),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=jo(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=ot(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let i={direction:t??[.4,-.7,.59]};return o&&(i.color=o),r!==void 0&&(i.intensity=r),i}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=ot(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){if(this._scene)return;let t=this._findAncestorCamera(),o;t?(o=t,this._implicitCamera=null):(this._implicitCamera=this._buildImplicitCamera(),o=this._implicitCamera),this._scene=ni(this,{camera:o,...this._readNonCameraOptions()}),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1}))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null),this._implicitCamera=null}attributeChangedCallback(t,o,r){if(o!==r&&this._scene){if(this._implicitCamera&&["rot-x","rot-y","zoom","distance","target"].includes(t)){let l=ot(this.getAttribute("rot-x")),c=ot(this.getAttribute("rot-y")),a=ot(this.getAttribute("zoom")),m=ot(this.getAttribute("distance")),f=jo(this.getAttribute("target"));l!==void 0&&this._implicitCamera.update({rotX:l}),c!==void 0&&this._implicitCamera.update({rotY:c}),a!==void 0&&this._implicitCamera.update({zoom:a}),m!==void 0&&this._implicitCamera.update({distance:m}),f!==void 0&&this._implicitCamera.update({target:f}),this._scene.applyCamera();return}this._scene.setOptions(this._readNonCameraOptions())}}};var no=require("@layoutit/polycss-core"),ml=typeof HTMLElement<"u"?HTMLElement:class{},pl=["src","mtl","mesh-resolution","position","scale","rotation","auto-center"];function fn(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 oi(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return fn(e)}}function fl(e){return e.closest("poly-scene")??null}function gl(e){if(e.length===0)return e;let n=(0,no.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let i=l=>[l[0]-t,l[1]-o,l[2]-r];return e.map(l=>({...l,vertices:l.vertices.map(i),...l.textureTriangles?.length?{textureTriangles:l.textureTriangles.map(c=>({...c,vertices:c.vertices.map(i)}))}:null}))}var Lt=class extends ml{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...pl]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"||t==="mesh-resolution"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:fn(this.getAttribute("position")),scale:oi(this.getAttribute("scale")),rotation:fn(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=fl(this);if(!o)return;let r=++this._loadToken,i=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,a;try{let h=i||c!==void 0?{...i?{mtlUrl:i}:{},...c!==void 0?{meshResolution:c}:{}}:void 0;a=await(0,no.loadMesh)(t,h)}catch(h){this.dispatchEvent(new CustomEvent("polycss:error",{detail:h,bubbles:!0}));return}if(r!==this._loadToken){try{a.dispose()}catch{}return}let m=o.getScene();if(!m){try{a.dispose()}catch{}return}this.hasAttribute("auto-center")&&(a={...a,polygons:gl(a.polygons)}),this._parseResult=a,this._handle=m.add(a,{position:fn(this.getAttribute("position")),scale:oi(this.getAttribute("scale")),rotation:fn(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var hl=typeof HTMLElement<"u"?HTMLElement:class{},yl=["vertices","color","texture","uvs","position","scale","rotation"];function ri(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Xo(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 bl(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Xo(e)}}function vl(e){return e.closest("poly-scene")??null}var gn=class extends hl{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...yl]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=vl(this);if(!t)return;let o=t.getScene();if(!o)return;let r=ri(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let i=this.getAttribute("color")||void 0,l=this.getAttribute("texture")||void 0,c=ri(this.getAttribute("uvs"))??void 0,a={};for(let h of Array.from(this.attributes))h.name.startsWith("data-")&&(a[h.name.slice(5)]=h.value);let f={polygons:[{vertices:r,...i!==void 0?{color:i}:{},...l!==void 0?{texture:l}:{},...c!==void 0?{uvs:c}:{},...Object.keys(a).length>0?{data:a}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(f,{position:Xo(this.getAttribute("position")),scale:bl(this.getAttribute("scale")),rotation:Xo(this.getAttribute("rotation"))})}};var si=require("@layoutit/polycss-core"),xl=typeof HTMLElement<"u"?HTMLElement:class{},Pl=["size","thickness","negative","x-color","y-color","z-color"];function Sl(e){return e.closest("poly-scene")??null}function ii(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var hn=class extends xl{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Pl]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&this._handle&&this._remount()}_polygons(){return(0,si.axesHelperPolygons)({size:ii(this.getAttribute("size")),thickness:ii(this.getAttribute("thickness")),negative:this.hasAttribute("negative"),xColor:this.getAttribute("x-color")??void 0,yColor:this.getAttribute("y-color")??void 0,zColor:this.getAttribute("z-color")??void 0})}_mount(){let t=Sl(this);if(!t)return;let o=t.getScene();if(!o)return;let r={polygons:this._polygons(),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(r,{excludeFromAutoCenter:!0,merge:!1})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var ci=require("@layoutit/polycss-core"),Cl=typeof HTMLElement<"u"?HTMLElement:class{},El=["direction","target","distance","size","color"],Wo=50,Tl=5,Al=.35,Ml="#ffd54a";function wl(e){return e.closest("poly-scene")??null}function li(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function ai(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var yn=class extends Cl{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...El]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="size"||t==="color"){this._remount();return}this._handle.setTransform({position:this._meshPosition()})}}_meshPosition(){let t=li(this.getAttribute("direction"));if(!t)return;let o=li(this.getAttribute("target"))??[0,0,0],r=ai(this.getAttribute("distance"),Tl),i=t[0],l=t[1],c=t[2],a=Math.hypot(i,l,c)||1,m=o[0]+l/a*r,f=o[1]+i/a*r,h=o[2]+c/a*r;return[f*Wo,m*Wo,h*Wo]}_mount(){let t=wl(this);if(!t)return;let o=t.getScene();if(!o)return;let r=ai(this.getAttribute("size"),Al),i=this.getAttribute("color")??Ml,l={polygons:(0,ci.octahedronPolygons)({center:[0,0,0],size:r,color:i}),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(l,{position:this._meshPosition(),excludeFromAutoCenter:!0,merge:!1})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var ui=require("@layoutit/polycss-core");var oo={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Yt(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 bn(e){return e===!0?-1:e===!1?1:e}function jt(){let e=[],n=[],t=[];function o(l){return l==="change"?e:l==="start"?n:t}function r(l){if(e.length===0)return;let c={type:"change",camera:l()},a=e.slice();for(let m of a)try{m(c)}catch(f){console.error("[polycss] controls 'change' listener threw:",f)}}function i(l,c){let a=l==="start"?n:t;if(a.length===0)return;let m={type:l,camera:c()},f=a.slice();for(let h of f)try{h(m)}catch(g){console.error(`[polycss] controls '${l}' listener threw:`,g)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:i}}function Xt(e){return()=>{let n=e.camera.state,t=n.target??[0,0,0];return{rotX:n.rotX??0,rotY:n.rotY??0,zoom:n.zoom??1,target:[t[0],t[1],t[2]],distance:n.distance??0}}}function ro(e,n,t,o,r,i){let l=!1,c=null;return{onWheel:f=>{let h=n();if(!h.wheel||t())return;f.preventDefault();let g=f.deltaMode===1?16:f.deltaMode===2?100:1,x=f.deltaY*g;f.ctrlKey?x*=10:x*=3;let y=e.camera.state;if(h.dolly){let P=y.distance??0,v=Math.max(h.minDistance,Math.min(h.maxDistance,P+x*.05));e.camera.update({distance:v})}else{let P=Math.exp(-x*513e-6),v=y.zoom??1,E=Math.max(h.minZoom,Math.min(h.maxZoom,v*P));e.camera.update({zoom:E})}e.applyCamera(),l||(l=!0,i("start",o)),r(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,l=!1,i("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),l=!1}}}function io(e,n,t,o,r,i,l){let c=null,a=0,m=x=>{if(c===null||o())return;let y=t();if(!y.animate){c=null;return}if(r())a=x;else{let P=Math.min(50,a?x-a:16.67);a=x;let v=y.animate.speed*(P/16.67),E=n.camera.state;if(y.animate.axis==="x"){let H=(((E.rotX??65)+v)%360+360)%360;n.camera.update({rotX:H})}else{let H=(((E.rotY??45)+v)%360+360)%360;n.camera.update({rotY:H})}n.applyCamera(),l(i)}c=e.requestAnimationFrame(m)};return{start:()=>{c!==null||!t().animate||o()||(a=0,c=e.requestAnimationFrame(m))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function di(e,n={}){let t=Yt(oo,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,i=null,l={x:0,y:0},c=!1,a=!1,m=jt(),f=Xt(e),{changeListeners:h,startListeners:g,endListeners:x,listenerArray:y,emitChange:P,emitInteraction:v}=m,E=io(r,e,()=>t,()=>a,()=>c,f,P),H=C=>{if(!(!t.drag||a)&&i===null&&C.isPrimary!==!1){C.preventDefault(),i=C.pointerId,l={x:C.clientX,y:C.clientY},o.style.cursor="grabbing";try{C.target.setPointerCapture(C.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),v("start",f)}},k=C=>{if(i===null||C.pointerId!==i||!t.drag||a)return;C.preventDefault();let A=C.clientX-l.x,w=C.clientY-l.y;l={x:C.clientX,y:C.clientY};let M=bn(t.invert),ae=A/4*M,ve=w/4*M,_=e.camera.state;if(C.shiftKey){let re=_.rotX??65,ie=_.rotY??45,Te=Math.max(.01,_.zoom??1),we=Math.cos(re*Math.PI/180),He=we>=0?Math.max(.1,we):Math.min(-.1,we),Ne=Math.cos(ie*Math.PI/180),Oe=Math.sin(ie*Math.PI/180),Ue=Te*ui.BASE_TILE,rt=(A*Oe-w*Ne/He)/Ue,je=-(A*Ne+w*Oe/He)/Ue,qe=_.target??[0,0,0];e.camera.update({target:[qe[0]+rt,qe[1]+je,qe[2]]})}else{let re=Math.max(0,Math.min(100,(_.rotX??65)-ve)),ie=(((_.rotY??45)-ae)%360+360)%360;e.camera.update({rotX:re,rotY:ie})}e.applyCamera(),P(f)},N=C=>{if(i===C.pointerId){i=null,o.style.cursor=t.drag&&!a?"grab":"";try{C.target.releasePointerCapture(C.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),v("end",f)}},R=ro(e,()=>t,()=>a,f,P,v);function ee(){o.addEventListener("pointerdown",H),o.addEventListener("pointermove",k),o.addEventListener("pointerup",N),o.addEventListener("pointercancel",N),o.addEventListener("wheel",R.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function z(){o.removeEventListener("pointerdown",H),o.removeEventListener("pointermove",k),o.removeEventListener("pointerup",N),o.removeEventListener("pointercancel",N),o.removeEventListener("wheel",R.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",R.teardown()}ee(),E.start();function O(C){let A=!!t.animate;t=Yt(t,C),!a&&i===null&&(o.style.cursor=t.drag?"grab":"");let w=!!t.animate;A&&!w?E.stop():!A&&w&&E.start()}function $(){a&&(a=!1,ee(),E.start())}function U(){a||(a=!0,z(),E.stop(),i=null,c=!1,R.teardown())}function le(){U(),h.length=0,g.length=0,x.length=0}function Ce(C,A){let w=y(C);w.includes(A)||w.push(A)}function u(C,A){let w=y(C),M=w.indexOf(A);M>=0&&w.splice(M,1)}function p(C,A){return y(C).includes(A)}return{update:O,resume:$,pause:U,destroy:le,addEventListener:Ce,removeEventListener:u,hasEventListener:p}}function ue(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function so(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 Ye(e){if(e!==null)return!(e==="false"||e==="0")}function lo(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 ao(e){if(e==="x"||e==="y")return e}var Ll=typeof HTMLElement<"u"?HTMLElement:class{},_l=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],vn=class extends Ll{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[..._l]}_readAnimate(){let t=ue(this.getAttribute("animate-speed")),o=ao(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:Ye(r)}:{}}}_readOptions(){let t={},o=Ye(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Ye(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let i=ue(this.getAttribute("min-distance"));i!==void 0&&(t.minDistance=i);let l=ue(this.getAttribute("max-distance"));l!==void 0&&(t.maxDistance=l);let c=lo(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let a=ue(this.getAttribute("zoom-min")),m=ue(this.getAttribute("zoom-max"));return a!==void 0&&(t.minZoom=a),m!==void 0&&(t.maxZoom=m),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ge)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=di(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var mi=require("@layoutit/polycss-core");function pi(e,n={}){let t=Yt(oo,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,i=null,l={x:0,y:0},c=!1,a=!1,m=!1,f={x:0,y:0},h=jt(),g=Xt(e),{changeListeners:x,startListeners:y,endListeners:P,listenerArray:v,emitChange:E,emitInteraction:H}=h,k=io(r,e,()=>t,()=>a,()=>c,g,E),N=_=>{if(!(!t.drag||a)&&i===null&&_.isPrimary!==!1){_.preventDefault(),i=_.pointerId,l={x:_.clientX,y:_.clientY},o.style.cursor="grabbing";try{_.target.setPointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),H("start",g)}},R=_=>{if(i===null||_.pointerId!==i||!t.drag||a)return;_.preventDefault();let re=_.clientX-l.x,ie=_.clientY-l.y;l={x:_.clientX,y:_.clientY};let Te=e.camera.state;if(_.shiftKey){let we=bn(t.invert),He=re/4*we,Ne=ie/4*we,Oe=Math.max(0,Math.min(100,(Te.rotX??65)-Ne)),Ue=(((Te.rotY??45)-He)%360+360)%360;e.camera.update({rotX:Oe,rotY:Ue})}else{let we=Te.rotX??65,He=Te.rotY??45,Ne=Math.max(.01,Te.zoom??1),Oe=Math.cos(we*Math.PI/180),Ue=Oe>=0?Math.max(.1,Oe):Math.min(-.1,Oe),rt=Math.cos(He*Math.PI/180),je=Math.sin(He*Math.PI/180),qe=Ne*mi.BASE_TILE,Zt=(re*je-ie*rt/Ue)/qe,Qt=-(re*rt+ie*je/Ue)/qe,mt=Te.target??[0,0,0];e.camera.update({target:[mt[0]+Zt,mt[1]+Qt,mt[2]]})}e.applyCamera(),E(g)},ee=_=>{if(i===_.pointerId){i=null,o.style.cursor=t.drag&&!a?"grab":"";try{_.target.releasePointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),H("end",g)}},z=_=>{_.preventDefault()},O=_=>{_.button===2&&(m=!0,f={x:_.clientX,y:_.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),H("start",g))},$=_=>{if(!m||!t.drag)return;let re=_.clientX-f.x,ie=_.clientY-f.y;f={x:_.clientX,y:_.clientY};let Te=bn(t.invert),we=re/4*Te,He=ie/4*Te,Ne=e.camera.state,Oe=Math.max(0,Math.min(100,(Ne.rotX??65)-He)),Ue=(((Ne.rotY??45)-we)%360+360)%360;e.camera.update({rotX:Oe,rotY:Ue}),e.applyCamera(),E(g)},U=_=>{_.button===2&&m&&(m=!1,H("end",g))},le=ro(e,()=>t,()=>a,g,E,H);function Ce(){o.addEventListener("pointerdown",N),o.addEventListener("pointermove",R),o.addEventListener("pointerup",ee),o.addEventListener("pointercancel",ee),o.addEventListener("wheel",le.onWheel,{passive:!1}),o.addEventListener("contextmenu",z),o.addEventListener("mousedown",O),o.addEventListener("mousemove",$),o.addEventListener("mouseup",U),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function u(){o.removeEventListener("pointerdown",N),o.removeEventListener("pointermove",R),o.removeEventListener("pointerup",ee),o.removeEventListener("pointercancel",ee),o.removeEventListener("wheel",le.onWheel),o.removeEventListener("contextmenu",z),o.removeEventListener("mousedown",O),o.removeEventListener("mousemove",$),o.removeEventListener("mouseup",U),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",le.teardown()}Ce(),k.start();function p(_){let re=!!t.animate;t=Yt(t,_),!a&&i===null&&(o.style.cursor=t.drag?"grab":"");let ie=!!t.animate;re&&!ie?k.stop():!re&&ie&&k.start()}function C(){a&&(a=!1,Ce(),k.start())}function A(){a||(a=!0,u(),k.stop(),i=null,c=!1,m=!1,le.teardown())}function w(){A(),x.length=0,y.length=0,P.length=0}function M(_,re){let ie=v(_);ie.includes(re)||ie.push(re)}function ae(_,re){let ie=v(_),Te=ie.indexOf(re);Te>=0&&ie.splice(Te,1)}function ve(_,re){return v(_).includes(re)}return{update:p,resume:C,pause:A,destroy:w,addEventListener:M,removeEventListener:ae,hasEventListener:ve}}var Rl=typeof HTMLElement<"u"?HTMLElement:class{},Dl=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],xn=class extends Rl{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Dl]}_readAnimate(){let t=ue(this.getAttribute("animate-speed")),o=ao(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:Ye(r)}:{}}}_readOptions(){let t={},o=Ye(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Ye(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let i=ue(this.getAttribute("min-distance"));i!==void 0&&(t.minDistance=i);let l=ue(this.getAttribute("max-distance"));l!==void 0&&(t.maxDistance=l);let c=lo(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let a=ue(this.getAttribute("zoom-min")),m=ue(this.getAttribute("zoom-max"));return a!==void 0&&(t.minZoom=a),m!==void 0&&(t.maxZoom=m),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ge)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=pi(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 xi=require("@layoutit/polycss-core");var kl={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 fi(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 gi=new Set(["KeyW","ArrowUp"]),hi=new Set(["KeyS","ArrowDown"]),yi=new Set(["KeyA","ArrowLeft"]),bi=new Set(["KeyD","ArrowRight"]),vi=new Set(["Space"]),Zo=new Set(["ControlLeft","ControlRight"]);function Pi(e,n={}){let t=fi(kl,n),o=e.host,r=e.cameraEl,i=o.ownerDocument??document,l=i.defaultView??globalThis,c=jt(),a=Xt(e),{changeListeners:m,startListeners:f,endListeners:h,listenerArray:g,emitChange:x,emitInteraction:y}=c,P=new Set,v=!1,E=!1,H=0,k=0,N=!1,R=[0,0,t.groundZ+t.eyeHeight];function ee(G,be){let de=G*Math.PI/180,De=be*Math.PI/180;return[-Math.sin(de)*Math.cos(De),-Math.sin(de)*Math.sin(De),-Math.cos(de)]}function z(){let G=e.camera.perspectiveStyle,be=G==="none"?0:parseFloat(G);return(Number.isFinite(be)&&be>0?be:2e3)/xi.BASE_TILE}function O(){let G=e.camera.state,be=ee(G.rotX??90,G.rotY??0),de=z();return[R[0]+be[0]*de,R[1]+be[1]*de,R[2]+be[2]*de]}function $(){let G=O();e.camera.update({target:G}),e.applyCamera()}function U(){let G=e.camera.state.target??[0,0,0];R=[G[0],G[1],t.groundZ+t.eyeHeight],$()}let le=()=>{if(!(!t.enabled||!t.lookEnabled||E||v))try{o.requestPointerLock()}catch{}},Ce=()=>{let G=i.pointerLockElement===o;G!==v&&(v=G,v?(N=!0,y("start",a)):N&&(N=!1,y("end",a)))},u=G=>{if(!v||!t.enabled||!t.lookEnabled||E)return;let be=G.movementX??0,de=G.movementY??0;if(be===0&&de===0)return;let De=e.camera.state,qt=t.lookSensitivity,Kt=t.invertY?-1:1,Et=(((De.rotY??0)-be*qt)%360+360)%360,Ie=(De.rotX??90)-de*qt*Kt;Ie<t.minPitch?Ie=t.minPitch:Ie>t.maxPitch&&(Ie=t.maxPitch);let et=ee(Ie,Et),Be=z(),Xe=[R[0]+et[0]*Be,R[1]+et[1]*Be,R[2]+et[2]*Be];e.camera.update({rotX:Ie,rotY:Et,target:Xe}),e.applyCamera(),x(a)},p=G=>gi.has(G)||hi.has(G)||yi.has(G)||bi.has(G)||vi.has(G)||Zo.has(G),C=G=>{if(!(!t.enabled||E)&&p(G.code)&&!(!v&&!t.moveEnabled)){if(vi.has(G.code)){if(!t.jumpEnabled)return;G.preventDefault(),!P.has(G.code)&&H===0&&k===0&&(H=t.jumpVelocity),P.add(G.code);return}Zo.has(G.code)&&!t.crouchEnabled||!t.moveEnabled&&!Zo.has(G.code)||(G.preventDefault(),P.add(G.code))}},A=G=>{p(G.code)&&P.delete(G.code)},w=()=>{P.clear()},M=null,ae=0,ve=.05,_=G=>{if(M===null||E)return;let be=Math.min(ve,ae?(G-ae)/1e3:.0167);if(ae=G,t.enabled){let de=!1,De=e.camera.state;if(t.moveEnabled){let Ie=0,et=0;for(let Be of P)gi.has(Be)?Ie+=1:hi.has(Be)?Ie-=1:bi.has(Be)?et+=1:yi.has(Be)&&(et-=1);if(Ie!==0||et!==0){let Xe=(De.rotY??0)*Math.PI/180,vo=-Math.cos(Xe),pt=-Math.sin(Xe),xo=-Math.sin(Xe),Po=Math.cos(Xe),Vn=Math.hypot(Ie,et)||1,zn=t.moveSpeed*be;R[0]+=(vo*Ie+xo*et)/Vn*zn,R[1]+=(pt*Ie+Po*et)/Vn*zn,de=!0}}let Kt=t.crouchEnabled&&(P.has("ControlLeft")||P.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(H!==0||k>0)?(H-=t.gravity*be,k+=H*be,k<=0&&(k=0,H=0)):t.jumpEnabled||(k=0,H=0);let Et=t.groundZ+Kt+k;if(Math.abs(R[2]-Et)>1e-4&&(R[2]=Et,de=!0),de){let Ie=O();e.camera.update({target:Ie}),e.applyCamera(),x(a)}}M=l.requestAnimationFrame(_)};function re(){M!==null||E||(ae=0,M=l.requestAnimationFrame(_))}function ie(){M!==null&&(l.cancelAnimationFrame(M),M=null)}function Te(){let be=r.ownerDocument?.defaultView?.getComputedStyle(r).perspective??"",de=parseFloat(be),De=Number.isFinite(de)&&de>0?de:2e3;r.style.setProperty("--polycss-fpv-perspective",`${De}px`),r.classList.add("polycss-fpv-host")}function we(){r.classList.remove("polycss-fpv-host"),r.style.removeProperty("--polycss-fpv-perspective")}function He(){o.addEventListener("click",le),i.addEventListener("pointerlockchange",Ce),i.addEventListener("mousemove",u),l.addEventListener("keydown",C),l.addEventListener("keyup",A),l.addEventListener("blur",w),o.style.cursor=t.lookEnabled?"crosshair":"",Te()}function Ne(){if(o.removeEventListener("click",le),i.removeEventListener("pointerlockchange",Ce),i.removeEventListener("mousemove",u),l.removeEventListener("keydown",C),l.removeEventListener("keyup",A),l.removeEventListener("blur",w),o.style.cursor="",P.clear(),v)try{i.exitPointerLock()}catch{}we()}U(),He(),re();function Oe(G){let be=t.eyeHeight,de=t.groundZ;t=fi(t,G),E||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==be||t.groundZ!==de)&&(R[2]=t.groundZ+t.eyeHeight,$(),x(a))}function Ue(){E&&(E=!1,He(),re())}function rt(){E||(E=!0,Ne(),ie(),N&&(N=!1,y("end",a)))}function je(){rt(),m.length=0,f.length=0,h.length=0}function qe(){if(!(!t.enabled||!t.lookEnabled||E))try{o.requestPointerLock()}catch{}}function Zt(){if(v)try{i.exitPointerLock()}catch{}}function Qt(){return v}function mt(G,be){let de=g(G);de.includes(be)||de.push(be)}function Ct(G,be){let de=g(G),De=de.indexOf(be);De>=0&&de.splice(De,1)}function ho(G,be){return g(G).includes(be)}function yo(){return[R[0],R[1],R[2]]}function bo(G){R[0]=G[0],R[1]=G[1],R[2]=G[2],$(),x(a)}return{update:Oe,resume:Ue,pause:rt,destroy:je,lock:qe,unlock:Zt,isLocked:Qt,getOrigin:yo,setOrigin:bo,addEventListener:mt,removeEventListener:Ct,hasEventListener:ho}}var Ol=typeof HTMLElement<"u"?HTMLElement:class{},Fl=["enabled","look-enabled","move-enabled","jump-enabled","crouch-enabled","look-sensitivity","invert-y","move-speed","jump-velocity","gravity","eye-height","crouch-height","ground-z","min-pitch","max-pitch"],Pn=class extends Ol{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Fl]}_readOptions(){let t={},o=Ye(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let r=Ye(this.getAttribute("look-enabled"));r!==void 0&&(t.lookEnabled=r);let i=Ye(this.getAttribute("move-enabled"));i!==void 0&&(t.moveEnabled=i);let l=Ye(this.getAttribute("jump-enabled"));l!==void 0&&(t.jumpEnabled=l);let c=Ye(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let a=ue(this.getAttribute("look-sensitivity"));if(a!==void 0&&(t.lookSensitivity=a),this.hasAttribute("invert-y")){let E=Ye(this.getAttribute("invert-y"));E!==void 0&&(t.invertY=E)}let m=ue(this.getAttribute("move-speed"));m!==void 0&&(t.moveSpeed=m);let f=ue(this.getAttribute("jump-velocity"));f!==void 0&&(t.jumpVelocity=f);let h=ue(this.getAttribute("gravity"));h!==void 0&&(t.gravity=h);let g=ue(this.getAttribute("eye-height"));g!==void 0&&(t.eyeHeight=g);let x=ue(this.getAttribute("crouch-height"));x!==void 0&&(t.crouchHeight=x);let y=ue(this.getAttribute("ground-z"));y!==void 0&&(t.groundZ=y);let P=ue(this.getAttribute("min-pitch"));P!==void 0&&(t.minPitch=P);let v=ue(this.getAttribute("max-pitch"));return v!==void 0&&(t.maxPitch=v),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ge)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=Pi(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 Hl=typeof HTMLElement<"u"?HTMLElement:class{},Il=["perspective","zoom","rot-x","rot-y","target","distance"],Sn=class extends Hl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Il]}getCamera(){return this._camera}_readOptions(){return{perspective:ue(this.getAttribute("perspective")),zoom:ue(this.getAttribute("zoom")),rotX:ue(this.getAttribute("rot-x")),rotY:ue(this.getAttribute("rot-y")),target:so(this.getAttribute("target")),distance:ue(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=mn(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let i=this._readOptions();this._camera=mn(i),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var Vl=typeof HTMLElement<"u"?HTMLElement:class{},zl=["zoom","rot-x","rot-y","target","distance"],_t=class extends Vl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...zl]}getCamera(){return this._camera}_readOptions(){return{zoom:ue(this.getAttribute("zoom")),rotX:ue(this.getAttribute("rot-x")),rotY:ue(this.getAttribute("rot-y")),target:so(this.getAttribute("target")),distance:ue(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=pn(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let i=this._readOptions();i.zoom!==void 0&&this._camera.update({zoom:i.zoom}),i.rotX!==void 0&&this._camera.update({rotX:i.rotX}),i.rotY!==void 0&&this._camera.update({rotY:i.rotY}),i.target!==void 0&&this._camera.update({target:i.target}),i.distance!==void 0&&this._camera.update({distance:i.distance})}};var Cn=class extends _t{};var Qe=require("@layoutit/polycss-core"),uo="#ff3653",mo="#8adb00",po="#2c8fff",Wt=50,Si=60,Bl=.6,Nl=.0125,Ul=.15,$l=.04,Gl=1,Ci=.02,Qo=1.04,Yl=.1,jl=.25,Mi=1e-4,Xl=.6,Wl=.8,Zl=1,En={0:1,1:0,2:2},Ei=[{cssAxis:0,sign:1,key:"x",color:uo},{cssAxis:0,sign:-1,key:"-x",color:uo},{cssAxis:1,sign:1,key:"y",color:mo},{cssAxis:1,sign:-1,key:"-y",color:mo},{cssAxis:2,sign:1,key:"z",color:po},{cssAxis:2,sign:-1,key:"-z",color:po}],Ti=[{cssAxis:0,key:"x",color:uo},{cssAxis:1,key:"y",color:mo},{cssAxis:2,key:"z",color:po}],Ai=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:po},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:mo},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:uo}];function qo(e,n,t,o){let r=t*Math.PI/180,i=o*Math.PI/180,l=[0,0,0];l[e]=n;let c=l[0]*Math.cos(i)-l[1]*Math.sin(i),a=l[0]*Math.sin(i)+l[1]*Math.cos(i),m=l[2];return a*Math.sin(r)+m*Math.cos(r)<0}function Ql(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),i=parseInt(t[3],16);return`rgba(${o}, ${r}, ${i}, ${n})`}function fo(e,n){return!n||n<=0?e:Math.round(e/n)*n}function ql(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,l=-1/0;for(let c of e)for(let a of c.vertices)a[0]<n&&(n=a[0]),a[0]>r&&(r=a[0]),a[1]<t&&(t=a[1]),a[1]>i&&(i=a[1]),a[2]<o&&(o=a[2]),a[2]>l&&(l=a[2]);return Number.isFinite(n)?[(t+i)/2*Wt,(n+r)/2*Wt,(o+l)/2*Wt]:[0,0,0]}function Ko(e){if(e.length===0)return Si;let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,l=-1/0;for(let a of e)for(let m of a.vertices)m[0]<n&&(n=m[0]),m[0]>r&&(r=m[0]),m[1]<t&&(t=m[1]),m[1]>i&&(i=m[1]),m[2]<o&&(o=m[2]),m[2]>l&&(l=m[2]);return Number.isFinite(n)?Math.max(r-n,i-t,l-o)*Wt*Bl:Si}function co(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let i=r.getBoundingClientRect();if(!(i.width<=0||i.height<=0)&&n>=i.left&&n<=i.right&&t>=i.top&&t<=i.bottom)return!0}return!1}function Kl(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:i,startClientX:l,startClientY:c,translationSnap:a,onAxisDelta:m,onMouseDown:f,onMouseUp:h,onDraggingChanged:g}=e,x=o,y=[0,0,0];y[n]=t;let P=r.ownerDocument.createElement("div");P.style.position="absolute",P.style.left="0",P.style.top="0",P.style.width="0",P.style.height="0",P.style.transform=`translate3d(${y[0]*x}px, ${y[1]*x}px, ${y[2]*x}px)`,r.appendChild(P);let v=r.getBoundingClientRect(),E=P.getBoundingClientRect();r.removeChild(P);let H=(E.left-v.left)/x,k=(E.top-v.top)/x,N=H*H+k*k;if(N<Mi)return;f?.(),g?.(!0);let R=z=>{let O=z.clientX-l,$=z.clientY-c,U=(O*H+$*k)/N;U=fo(U,a),m(U,y)},ee=()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",ee),window.removeEventListener("pointercancel",ee);let z=O=>{O.stopPropagation(),O.stopImmediatePropagation()};window.addEventListener("click",z,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",z,!0),0),h?.(),g?.(!1)};window.addEventListener("pointermove",R),window.addEventListener("pointerup",ee),window.addEventListener("pointercancel",ee)}function Jl(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:i,startClientY:l,translationSnap:c,onPlaneDelta:a,onMouseDown:m,onMouseUp:f,onDraggingChanged:h}=e,g=[0,0,0];g[n]=1;let x=[0,0,0];x[t]=1;function y(N){let R=r.ownerDocument.createElement("div");R.style.position="absolute",R.style.left="0",R.style.top="0",R.style.width="0",R.style.height="0",R.style.transform=`translate3d(${N[0]*o}px, ${N[1]*o}px, ${N[2]*o}px)`,r.appendChild(R);let ee=r.getBoundingClientRect(),z=R.getBoundingClientRect();return r.removeChild(R),{x:(z.left-ee.left)/o,y:(z.top-ee.top)/o}}let P=y(g),v=y(x),E=P.x*v.y-v.x*P.y;if(Math.abs(E)<Mi)return;m?.(),h?.(!0);let H=N=>{let R=N.clientX-i,ee=N.clientY-l,z=(v.y*R-v.x*ee)/E,O=(-P.y*R+P.x*ee)/E;z=fo(z,c),O=fo(O,c),a(z,O,g,x)},k=()=>{window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k);let N=R=>{R.stopPropagation(),R.stopImmediatePropagation()};window.addEventListener("click",N,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",N,!0),0),f?.(),h?.(!1)};window.addEventListener("pointermove",H),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)}function ea(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:i,rotationSnap:l,onAngleDelta:c,onMouseDown:a,onMouseUp:m,onDraggingChanged:f}=e,h=t.getBoundingClientRect(),g=h.left,x=h.top,y=Math.atan2(i-x,r-g),P=0;a?.(),f?.(!0);let v=H=>{let k=Math.atan2(H.clientY-x,H.clientX-g),N=k-y;N>Math.PI?N-=2*Math.PI:N<-Math.PI&&(N+=2*Math.PI),P+=N,y=k;let R=P*180/Math.PI;R=fo(R,l),c(R)},E=()=>{window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",E),window.removeEventListener("pointercancel",E);let H=k=>{k.stopPropagation(),k.stopImmediatePropagation()};window.addEventListener("click",H,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",H,!0),0),m?.(),f?.(!1)};window.addEventListener("pointermove",v),window.addEventListener("pointerup",E),window.addEventListener("pointercancel",E)}function wi(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,i={...n},l=new Map,c=null,a=null,m=[0,0,0];function f(){if(!t)return[0,0,0];let u=t.transform.position??[0,0,0];return[u[0]+m[0],u[1]+m[1],u[2]+m[2]]}function h(u){return a===u?Zl:c===u?Wl:Xl}function g(){for(let[u,p]of l){let C=x(p.spec,h(u));p.handle.setPolygons(C,{recomputeAutoCenter:!1})}}function x(u,p){let A=Ko(t?.polygons??[])*r,w=A/Wt,M=Ql(u.color,p);if(u.kind==="arrow"){let _=e.camera.state,re=qo(u.cssAxis,u.sign,_.rotX??65,_.rotY??45);return(0,Qe.arrowPolygons)({axis:En[u.cssAxis],sign:u.sign,shaftLength:w,shaftHalfThickness:w*Nl,headLength:w*Ul,headHalfThickness:w*$l,color:M,shaft:!re})}if(u.kind==="plane"){let _=e.camera.state,re=_.rotX??65,ie=_.rotY??45,Te=En[u.perpAxis],we=(Te+1)%3,He=(Te+2)%3,Ne=En[we],Oe=En[He],Ue=qo(Ne,1,re,ie)?-1:1,rt=qo(Oe,1,re,ie)?-1:1,je=w*jl;return(0,Qe.planePolygons)({axis:Te,size:w*Yl,offset:[Ue*je,rt*je],color:M})}let ve=A*Gl/Wt*Qo;return(0,Qe.ringQuadPolygons)({axis:En[u.cssAxis],outerRadius:ve,color:M})}function y(u){return u.kind==="arrow"?"polycss-transform-arrow":u.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function P(){if(o==="translate"){let u=Ei.map(C=>({kind:"arrow",key:C.key,cssAxis:C.cssAxis,sign:C.sign,color:C.color})),p=Ai.map(C=>({kind:"plane",key:C.key,perpAxis:C.perpAxis,axisA:C.axisA,axisB:C.axisB,color:C.color}));return[...u,...p]}return o==="rotate"?Ti.map(u=>({kind:"ring",key:u.key,cssAxis:u.cssAxis,color:u.color})):[]}function v(){if(E(),!t)return;let u={x:i.showX!==!1,y:i.showY!==!1,z:i.showZ!==!1};function p(A){if(A.kind==="arrow"){let ae=A.key.replace("-","")[0];return u[ae]}if(A.kind==="ring")return u[A.key];let w=["x","y","z"][A.axisA],M=["x","y","z"][A.axisB];return u[w]&&u[M]}let C=f();for(let A of P()){if(!p(A))continue;let w=x(A,h(A.key)),M=e.add({polygons:w,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${A.key}`,position:C}),ae=y(A);if(M.element.classList.add("polycss-transform-gizmo",ae,`${ae}--${A.key}`),A.kind==="ring"){let ve=(1-Ci)/Qo,_=(1+Ci)/Qo;M.element.style.setProperty("--ring-inner-ratio",`${ve}`),M.element.style.setProperty("--ring-outer-ratio",`${_}`)}l.set(A.key,{handle:M,spec:A})}}function E(){for(let{handle:u}of l.values())u.remove();l.clear(),c=null,a=null}function H(){if(!t)return;let u=f();for(let{handle:p}of l.values())p.setTransform({position:u})}function k(){t&&(l.size===0?v():H())}function N(u){if(t=u,!u){m=[0,0,0],E();return}m=ql(u.polygons),E(),v()}function R(){N(null)}function ee(u){u!==o&&(o=u,t&&(E(),v()))}function z(u,p,C){if(!t||!O)return;let A=[O[0]+p*C[0],O[1]+p*C[1],O[2]+p*C[2]];t.setTransform({position:A}),H(),i.onObjectChange?.({object:t,position:A}),i.onChange?.()}let O=null,$=null,U=u=>{if(!t||i.enabled===!1)return;let p={x:i.showX!==!1,y:i.showY!==!1,z:i.showZ!==!1};if(o==="translate"){for(let C of Ai){let A=["x","y","z"][C.axisA],w=["x","y","z"][C.axisB];if(!p[A]||!p[w])continue;let M=l.get(C.key);if(M&&co(M.handle.element,u.clientX,u.clientY)){u.preventDefault(),u.stopPropagation(),a=C.key,g(),O=(t.transform.position??[0,0,0]).slice(),Jl({axisA:C.axisA,axisB:C.axisB,probeDistanceCss:Ko(t.polygons)*r,wrapper:M.handle.element,target:t,startClientX:u.clientX,startClientY:u.clientY,translationSnap:i.translationSnap??null,onPlaneDelta:(ae,ve,_,re)=>{if(!t||!O)return;let ie=[O[0]+ae*_[0]+ve*re[0],O[1]+ae*_[1]+ve*re[1],O[2]+ae*_[2]+ve*re[2]];t.setTransform({position:ie}),H(),i.onObjectChange?.({object:t,position:ie}),i.onChange?.()},onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:ae=>{ae||(a=null,O=null,g()),i.onDraggingChanged?.(ae)}});return}}for(let C of Ei){let A=C.key.replace("-","")[0];if(!p[A])continue;let w=l.get(C.key);if(w&&co(w.handle.element,u.clientX,u.clientY)){u.preventDefault(),u.stopPropagation(),a=C.key,g(),O=(t.transform.position??[0,0,0]).slice(),Kl({cssAxis:C.cssAxis,sign:C.sign,shaftLengthCss:Ko(t.polygons)*r,wrapper:w.handle.element,target:t,startClientX:u.clientX,startClientY:u.clientY,translationSnap:i.translationSnap??null,onAxisDelta:(M,ae)=>z(C,M,ae),onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:M=>{M||(a=null,O=null,g()),i.onDraggingChanged?.(M)}});return}}}else if(o==="rotate")for(let C of Ti){if(!p[C.key])continue;let A=l.get(C.key);if(A&&co(A.handle.element,u.clientX,u.clientY)){u.preventDefault(),u.stopPropagation(),a=C.key,g(),$=(t.transform.rotation??[0,0,0]).slice(),ea({cssAxis:C.cssAxis,wrapper:A.handle.element,target:t,startClientX:u.clientX,startClientY:u.clientY,rotationSnap:i.rotationSnap??null,onAngleDelta:w=>{if(!t||!$)return;let M=C.cssAxis===0?-1:1,ae=[0,0,0];ae[C.cssAxis]=1;let ve=w*M*Math.PI/180,_=(0,Qe.quatFromEulerXYZ)($),re=(0,Qe.quatFromAxisAngle)(ae,ve),ie=(0,Qe.eulerXYZFromQuat)((0,Qe.quatMultiply)(re,_));t.setTransform({rotation:ie}),i.onObjectChange?.({object:t,rotation:ie}),i.onChange?.()},onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:w=>{w||(a=null,$=null,g(),t?.rebakeAtlas()),i.onDraggingChanged?.(w)}});return}}};e.host.addEventListener("pointerdown",U,{capture:!0});let le=u=>{if(!t||a||i.enabled===!1)return;let p=null;for(let[C,A]of l)if(co(A.handle.element,u.clientX,u.clientY)){p=C;break}p!==c&&(c=p,g())};e.host.addEventListener("pointermove",le);function Ce(){e.host.removeEventListener("pointerdown",U,{capture:!0}),e.host.removeEventListener("pointermove",le),E()}return{attach:N,detach:R,setMode:ee,update:k,destroy:Ce}}var ta=typeof HTMLElement<"u"?HTMLElement:class{},na=["mode","target","size","enabled"];function Li(e){if(e==="translate"||e==="rotate")return e}var Tn=class extends ta{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...na]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ge)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 Lt?r:null}_readOptions(){let t={},o=Li(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=ue(this.getAttribute("size"));r!==void 0&&(t.size=r);let i=this.getAttribute("enabled");return i!==null&&(t.enabled=i!=="false"&&i!=="0"),t.onObjectChange=l=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:l.position,rotation:l.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let i=()=>{t.removeEventListener("polycss:scene-ready",i),this._attach()};t.addEventListener("polycss:scene-ready",i)}return}this._tc=wi(o,this._readOptions());let r=this._findTargetMesh();if(r){let i=r.getMeshHandle();i&&this._tc.attach(i)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,r){if(o!==r&&this._tc){if(t==="mode"){let i=Li(r);i&&this._tc.setMode(i)}else if(t==="target"){let i=this._findTargetMesh();this._tc.attach(i?i.getMeshHandle()??null:null)}}}};function oa(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let i=r.getBoundingClientRect();if(!(i.width<=0||i.height<=0)&&n>=i.left&&n<=i.right&&t>=i.top&&t<=i.bottom)return!0}return!1}function _i(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let P of o)try{P(t)}catch(v){console.error("[polycss/createSelect] onChange threw:",v)}}function i(y){t=y,r()}function l(y){n.multiple?t.includes(y)||(t=[...t,y]):t=[y],r()}function c(y){t.includes(y)&&(t=t.filter(P=>P!==y),r())}function a(y){t.includes(y)?t=t.filter(P=>P!==y):n.multiple?t=[...t,y]:t=[y],r()}function m(){t.length!==0&&(t=[],r())}function f(y){return t.includes(y)}function h(y,P){for(let v of e.meshes())if(!v.element.classList.contains("polycss-transform-gizmo")&&oa(v.element,y,P))return v;return null}let g=y=>{let P=y.target;if(P?.closest(".polycss-transform-gizmo"))return;let v=e.findMeshByElement(P)??h(y.clientX,y.clientY);if(!v){n.onPointerMissed&&n.onPointerMissed(y),n.clearOnMiss!==!1&&m();return}n.multiple&&(y.shiftKey||y.metaKey||y.ctrlKey)?a(v):t.length===1&&t[0]===v?m():i([v])};e.host.addEventListener("click",g);function x(){e.host.removeEventListener("click",g),o.clear()}return{get selected(){return t},set:i,add:l,remove:c,toggle:a,clear:m,has:f,destroy:x}}var ra=typeof HTMLElement<"u"?HTMLElement:class{},ia=["multiple","clear-on-miss"],An=class extends ra{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...ia]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Ge)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=_i(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};var Me=require("@layoutit/polycss-core"),sa=typeof HTMLElement<"u"?HTMLElement:class{};function la(e){return e.closest("poly-scene")??null}function Re(e,n,t){let o=e.getAttribute(n);if(!o)return t;let r=parseFloat(o);return Number.isFinite(r)?r:t}function ct(e,n,t){return e.getAttribute(n)??t}function go(e,n){let t=e.getAttribute(n);if(!t)return;let o=t.split(",").map(r=>parseFloat(r.trim()));if(!(o.length!==3||o.some(r=>!Number.isFinite(r))))return[o[0],o[1],o[2]]}function aa(e){if(e.length===0)return e;let n=(0,Me.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let i=l=>[l[0]-t,l[1]-o,l[2]-r];return e.map(l=>({...l,vertices:l.vertices.map(i)}))}var Je=class extends sa{constructor(){super(...arguments);this._handle=null}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=la(this);if(!t)return;let o=t.getScene?.();if(!o)return;let r=this.buildPolygons();this.hasAttribute("auto-center")&&(r=aa(r));let i={polygons:r,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(i,{position:go(this,"position"),scale:(()=>{let l=this.getAttribute("scale");if(!l)return;if(l.includes(","))return go(this,"scale");let c=parseFloat(l);return Number.isFinite(c)?c:void 0})(),rotation:go(this,"rotation"),merge:!1})}},Mn=class extends Je{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("size"),t=n?parseFloat(n):void 0;return(0,Me.boxPolygons)({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:ct(this,"color")})}},wn=class extends Je{static get observedAttributes(){return["axis","size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=Re(this,"axis",2);return(0,Me.planePolygons)({axis:n===0||n===1||n===2?n:2,size:Re(this,"size",.4),color:ct(this,"color")})}},Ln=class extends Je{static get observedAttributes(){return["axis","radius","segments","half-thickness","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=Re(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("half-thickness");return(0,Me.ringPolygons)({axis:t,radius:Re(this,"radius",50),segments:Re(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:ct(this,"color")})}},_n=class extends Je{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Me.octahedronPolygons)({center:go(this,"center")??[0,0,0],size:Re(this,"size",50),color:ct(this,"color")})}},Rn=class extends Je{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Me.tetrahedronPolygons)({size:Re(this,"size",100),color:ct(this,"color")})}},Dn=class extends Je{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Me.icosahedronPolygons)({size:Re(this,"size",100),color:ct(this,"color")})}},kn=class extends Je{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Me.dodecahedronPolygons)({size:Re(this,"size",100),color:ct(this,"color")})}},On=class extends Je{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Me.spherePolygons)({radius:Re(this,"radius",50),subdivisions:Re(this,"subdivisions",1),color:ct(this,"color")})}},Fn=class extends Je{static get observedAttributes(){return["radius","radius-top","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("radius-top");return(0,Me.cylinderPolygons)({radius:Re(this,"radius",50),radiusTop:n?parseFloat(n):void 0,height:Re(this,"height",100),radialSegments:Re(this,"radial-segments",12),color:ct(this,"color")})}},Hn=class extends Je{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Me.conePolygons)({radius:Re(this,"radius",50),height:Re(this,"height",100),radialSegments:Re(this,"radial-segments",12),color:ct(this,"color")})}},In=class extends Je{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Me.torusPolygons)({radius:Re(this,"radius",50),tube:Re(this,"tube",15),radialSegments:Re(this,"radial-segments",12),tubularSegments:Re(this,"tubular-segments",16),color:ct(this,"color")})}};typeof customElements<"u"&&(customElements.get("poly-scene")||customElements.define("poly-scene",Ge),customElements.get("poly-mesh")||customElements.define("poly-mesh",Lt),customElements.get("poly-polygon")||customElements.define("poly-polygon",gn),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",hn),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",yn),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",vn),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",xn),customElements.get("poly-first-person-controls")||customElements.define("poly-first-person-controls",Pn),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",Sn),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",_t),customElements.get("poly-camera")||customElements.define("poly-camera",Cn),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",Tn),customElements.get("poly-select")||customElements.define("poly-select",An),customElements.get("poly-box")||customElements.define("poly-box",Mn),customElements.get("poly-plane")||customElements.define("poly-plane",wn),customElements.get("poly-ring")||customElements.define("poly-ring",Ln),customElements.get("poly-octahedron")||customElements.define("poly-octahedron",_n),customElements.get("poly-tetrahedron")||customElements.define("poly-tetrahedron",Rn),customElements.get("poly-sphere")||customElements.define("poly-sphere",On),customElements.get("poly-icosahedron")||customElements.define("poly-icosahedron",Dn),customElements.get("poly-dodecahedron")||customElements.define("poly-dodecahedron",kn),customElements.get("poly-cylinder")||customElements.define("poly-cylinder",Fn),customElements.get("poly-cone")||customElements.define("poly-cone",Hn),customElements.get("poly-torus")||customElements.define("poly-torus",In));0&&(module.exports={PolyAxesHelperElement,PolyBoxElement,PolyCameraElement,PolyConeElement,PolyCylinderElement,PolyDirectionalLightHelperElement,PolyDodecahedronElement,PolyFirstPersonControlsElement,PolyIcosahedronElement,PolyMapControlsElement,PolyMeshElement,PolyOctahedronElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPlaneElement,PolyPolygonElement,PolyRingElement,PolySceneElement,PolySelectElement,PolySphereElement,PolyTetrahedronElement,PolyTorusElement,PolyTransformControlsElement});
519
+ `;var Wn=require("@layoutit/polycss-core"),ha=1,at=Wn.BASE_TILE,ga=.1;function Vt(e){return[e[1],e[0],e[2]]}function ut(e){return e?.direction?{...e,direction:Vt(e.direction)}:e}function Yn(e){return(0,Wn.buildPolyMeshTransform)(e)}function Go(e,n=[0,0,0],t=1){let o=e.state,r=o.rotX,i=o.rotY,c=(o.zoom??ha)/at*t,l=(o.distance??0)*t,p=o.target??[0,0,0],h=p[0]+n[0],x=p[1]+n[1],f=p[2]+n[2],b=x*at,y=h*at,P=f*at;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${r}deg) rotate(${i}deg) translate3d(${-b}px, ${-y}px, ${-P}px)`}function ya(e){let n=e.trim();if(!n||n==="normal")return 1;let t=n.endsWith("%")?Number(n.slice(0,-1))/100:Number(n);return Number.isFinite(t)&&t>0?t:1}function Xr(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=ya(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function Zr(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}function Qr(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let x=1;x+1<e.vertices.length;x++){let f=e.vertices[x],b=e.vertices[x+1],y=f[1]-n[1],P=f[0]-n[0],v=f[2]-n[2],C=b[1]-n[1],F=b[0]-n[0],k=b[2]-n[2];t-=P*k-v*F,o-=v*C-y*k,r-=y*F-P*C}let i=Math.hypot(t,o,r);if(i<1e-9)return null;t/=i,o/=i,r/=i;let s=1/ga,c=Math.round(t*s)/s,l=Math.round(o*s)/s,p=Math.round(r*s)/s,h=Math.hypot(c,l,p);return h<1e-9?null:{key:c+","+l+","+p,vec:[c/h,l/h,p/h]}}function qr(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let r of t)if(!o.includes(r))return!1;return!0}function Kr(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Jr(e,n){return e===n?!0:(e?.color??"#000000")===(n?.color??"#000000")&&(e?.opacity??.25)===(n?.opacity??.25)&&(e?.lift??.05)===(n?.lift??.05)&&(e?.maxExtend??2e3)===(n?.maxExtend??2e3)}var pt=require("@layoutit/polycss-core");var ba=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"],Bt="--polycss-light-preview-active",ei=`var(${Bt}, 0)`,va="max(0, calc(var(--pnx, 0) * var(--plx, 0) + var(--pny, 0) * var(--ply, 0) + var(--pnz, 1) * var(--plz, 1)))",$o=(e,n,t)=>`calc(255 * max(0, 1.055 * pow(min(1, pow((var(${e}, 1) + 0.055) / 1.055, 2.4) * (pow((var(${n}, 1) + 0.055) / 1.055, 2.4) * var(--pai, 0.4) + pow((var(${t}, 1) + 0.055) / 1.055, 2.4) * var(--pli, 1) * var(--plam, 0)) / 3.14159265), 0.4167) - 0.055))`,xa=$o("--psr","--par","--plr"),Pa=$o("--psg","--pag","--plg"),Sa=$o("--psb","--pab","--plb");function me(e,n,t){return e.style.getPropertyValue(n)===t?!1:(e.style.setProperty(n,t),!0)}function bt(e){for(let n of ba)e.style.getPropertyValue(n)&&e.style.removeProperty(n)}function Xn(e,n){let t=n.directionalLight?.direction??[.4,-.7,.59],o=Vt(t),r=Math.hypot(o[0],o[1],o[2])||1,i=o[0]/r,s=o[1]/r,c=o[2]/r,l=(0,pt.parseHexColor)(n.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],p=(0,pt.parseHexColor)(n.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],h=n.directionalLight?.intensity??1,x=n.ambientLight?.intensity??.4,f=P=>(P/255).toFixed(4);me(e,"--plx",i.toFixed(2)),me(e,"--ply",s.toFixed(2)),me(e,"--plz",c.toFixed(2)),me(e,"--plr",f(l[0])),me(e,"--plg",f(l[1])),me(e,"--plb",f(l[2])),me(e,"--pli",h.toFixed(4)),me(e,"--par",f(p[0])),me(e,"--pag",f(p[1])),me(e,"--pab",f(p[2])),me(e,"--pai",x.toFixed(4));let b=c,y=Math.sign(b||1)*Math.max(Math.abs(b),.01);me(e,"--clx",i.toFixed(2)),me(e,"--cly",s.toFixed(2)),me(e,"--clz",y.toFixed(2))}function ti(e,n){let t=n.textureLighting==="dynamic";if(e.dataset.polycssLighting=n.textureLighting??"baked",!t){bt(e);return}Xn(e,n)}function vt(e,n){n.paintColor?e.style.setProperty("--polycss-paint",n.paintColor):e.style.getPropertyValue("--polycss-paint")&&e.style.removeProperty("--polycss-paint"),n.dynamicColor?(e.style.setProperty("--psr",(n.dynamicColor.r/255).toFixed(4)),e.style.setProperty("--psg",(n.dynamicColor.g/255).toFixed(4)),e.style.setProperty("--psb",(n.dynamicColor.b/255).toFixed(4))):(e.style.getPropertyValue("--psr")||e.style.getPropertyValue("--psg")||e.style.getPropertyValue("--psb"))&&(e.style.removeProperty("--psr"),e.style.removeProperty("--psg"),e.style.removeProperty("--psb"))}function ni(e,n){let t=(0,pt.parseHex)(n??"#cccccc");e.style.setProperty("--psr",(t.r/255).toFixed(4)),e.style.setProperty("--psg",(t.g/255).toFixed(4)),e.style.setProperty("--psb",(t.b/255).toFixed(4))}function Uo(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=t.textureLighting??"baked",r={directionalLight:ut(t.directionalLight),ambientLight:t.ambientLight,textureLighting:o,textureQuality:t.textureQuality,seamBleed:t.seamBleed,strategies:t.strategies},i=To(e.plan,n,e.plan.normal,o,r);return Lt(e.element,i,o),o==="baked"&&Ea(e.element),!0}function Ca(e){let n=(0,pt.parsePureColor)(e)??{rgb:[255,255,255],alpha:1},[t,o,r]=n.rgb,i=(c,l)=>`calc(${c} * (1 - ${ei}) + var(${l}, ${c}) * ${ei})`,s=n.alpha<1?` / ${n.alpha}`:"";return`rgb(${i(t,"--polycss-preview-r")} ${i(o,"--polycss-preview-g")} ${i(r,"--polycss-preview-b")}${s})`}function oi(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=e.element,r=e.plan.normal,i=(0,pt.parseHex)(n.color??"#cccccc"),s=!1;return s=me(o,"--pnx",r[0].toFixed(4))||s,s=me(o,"--pny",r[1].toFixed(4))||s,s=me(o,"--pnz",r[2].toFixed(4))||s,s=me(o,"--psr",(i.r/255).toFixed(4))||s,s=me(o,"--psg",(i.g/255).toFixed(4))||s,s=me(o,"--psb",(i.b/255).toFixed(4))||s,s=me(o,"--plam",va)||s,s=me(o,"--polycss-preview-r",xa)||s,s=me(o,"--polycss-preview-g",Pa)||s,s=me(o,"--polycss-preview-b",Sa)||s,s=me(o,"--polycss-paint",Ca(t))||s,o.style.getPropertyValue("color")&&(o.style.removeProperty("color"),s=!0),s}function Ea(e){e.style.removeProperty("--pnx"),e.style.removeProperty("--pny"),e.style.removeProperty("--pnz"),e.style.removeProperty("--psr"),e.style.removeProperty("--psg"),e.style.removeProperty("--psb"),e.style.removeProperty("--plam"),e.style.removeProperty("--polycss-preview-r"),e.style.removeProperty("--polycss-preview-g"),e.style.removeProperty("--polycss-preview-b"),e.style.removeProperty("--polycss-paint")}var Ta="http://www.w3.org/2000/svg",Zn=class{constructor(){this.groundSvg=null;this.groundVisible=!1;this.currentGroundCssZ=null;this.shadowRoot=null}};function ri(e,n,t){let o=e.shadowRoot;if(o||(o=n.createElement("div"),o.setAttribute("class","polycss-shadows"),o.style.position="absolute",o.style.top="0",o.style.left="0",o.style.width="0",o.style.height="0",o.style.transformStyle="preserve-3d",o.style.pointerEvents="none",e.shadowRoot=o),o.parentNode!==t){let r=t.firstChild;r?t.insertBefore(o,r):t.appendChild(o)}return o}function ii(e){e.groundSvg?.parentNode&&e.groundSvg.parentNode.removeChild(e.groundSvg),e.groundSvg=null,e.groundVisible=!1}function si(e){e.groundSvg&&e.groundVisible&&(e.groundSvg.style.display="none",e.groundVisible=!1)}function ai(e,n,t,o){let r=[],i=e.firstChild;for(let s=0;s<t;s++){let c=i;c&&c.tagName==="path"?i=c.nextSibling:(c=n.createElementNS(Ta,"path"),c.setAttribute("fill-rule","nonzero"),o&&(c.setAttribute("stroke-width","0.5"),c.setAttribute("stroke-linejoin","round")),e.insertBefore(c,i)),r.push(c)}for(;i;){let s=i.nextSibling;e.removeChild(i),i=s}return r}function li(e){return{host:e.host,doc:e.doc,cameraEl:e.cameraEl,sceneEl:e.sceneEl,camera:e.camera,layoutScale:e.layoutScale,options:{current:e.options},meshes:new Set,meshAutoCounter:{next:0},autoCenter:{offset:[0,0,0]},bboxCenterCssCache:{value:null},shadowSvgState:new Zn,receiverShadowCache:new Map,receiverShadowCacheKey:new Map,casterItemsCache:new Map,casterItemsCacheKey:new Map}}var Fe=require("@layoutit/polycss-core");function ci(e){for(let n of e)n.svg&&n.svg.parentNode&&n.svg.parentNode.removeChild(n.svg),n.svg=null}function di(e,n){if(n){let t=e.receiverShadowCache.get(n);t&&ci(t),e.receiverShadowCache.delete(n),e.receiverShadowCacheKey.delete(n)}else{for(let t of e.receiverShadowCache.values())ci(t);e.receiverShadowCache.clear(),e.receiverShadowCacheKey.clear()}}function ui(e,n){n?(e.casterItemsCache.delete(n),e.casterItemsCacheKey.delete(n)):(e.casterItemsCache.clear(),e.casterItemsCacheKey.clear())}function pi(e){ii(e.shadowSvgState),mi(e)}function jo(e){return e.handle.id??e.autoMeshId}var Aa="http://www.w3.org/2000/svg",Qn=new WeakMap,fi=new WeakMap,hi=new WeakMap,gi=new WeakMap,yi=new WeakMap;function bi(e){let n=Qn.get(e);return n||(n=new Map,Qn.set(e,n)),n}function Wo(e){let n=Qn.get(e);if(n){for(let t of n.values())t.svg&&t.svg.parentNode&&t.svg.parentNode.removeChild(t.svg);n.clear(),Qn.delete(e)}}function mi(e){for(let n of e.meshes)Wo(n)}function vi(e,n,t,o,r,i,s,c,l,p){let h=e.options.current,{receiverShadowCache:x,receiverShadowCacheKey:f,casterItemsCache:b,casterItemsCacheKey:y}=e,P=o.handle.transform.position??[0,0,0],v=o.handle.transform.rotation??[0,0,0],C=o.polygons.some(A=>A.texture!==void 0),F=(0,Fe.meshScaleVec3)(o.handle.transform.scale),k=o.bboxCenterCss,z=h.shadow?.lift??.001,O=`${o.polygons.length}|${r.size}|${P.join(",")}|${v.join(",")}|${F.join(",")}|${k?k.join(","):"n"}|${z}`,Z=x.get(o);if(Z===void 0||f.get(o)!==O){Z=(0,Fe.prepareReceiverFacePlanes)(o.polygons,P,o.handle.transform.scale,r,z,v),x.set(o,Z),f.set(o,O);let A=bi(o);for(let g of A.values())g.svg&&g.svg.parentNode&&g.svg.parentNode.removeChild(g.svg);A.clear()}let q=[];for(let A of n){let g=A.handle.transform.position??[0,0,0],u=A.handle.transform.rotation??[0,0,0],d=(0,Fe.meshScaleVec3)(A.handle.transform.scale),T=A.bboxCenterCss,w=`${A.polygons.length}|${g.join(",")}|${u.join(",")}|${d.join(",")}|${T?T.join(","):"n"}`,R=b.get(A);if(R===void 0||y.get(A)!==w){let _=t.get(A),j=new Set;for(let Q of A.rendered)Q.plan&&!_.has(Q.polygonIndex)&&j.add(Q.polygonIndex);R=(0,Fe.prepareCasterPolyItems)(A.polygons,g,A.handle.transform.scale,Q=>j.has(Q),u),b.set(A,R),y.set(A,w)}let L;if(A===o){let _=fi.get(A);(_===void 0||hi.get(A)!==A.polygons)&&(_=(0,Fe.buildSharedEdgeMap)(A.polygons),fi.set(A,_),hi.set(A,A.polygons)),L=_}let re;if(A!==o&&A.polygons.length>=40){let _=gi.get(A);(_===void 0||yi.get(A)!==w)&&(_=(0,Fe.prepareCasterEdgeOwners)(A.polygons,g,A.handle.transform.scale,u),gi.set(A,_),yi.set(A,w)),re=_}q.push({id:A,items:R,selfShadowEdgeMap:L,edgeOwners:re,casterPolygonCount:A.polygons.length})}let D={rotX:e.camera.state.rotX,rotY:e.camera.state.rotY,meshRotation:o.handle.transform.rotation},H=(0,Fe.computeReceiverShadowFaces)({receiverPlanes:Z,receiverPolygons:o.polygons,receiverHasTexture:C,casters:q,lightDir:i,cameraRot:D,ambientLight:h.ambientLight,directionalLight:h.directionalLight,shadow:{color:h.shadow?.color,opacity:p,maxExtend:h.shadow?.maxExtend}}),V=bi(o),G=new Set;for(let A of H){G.add(A.faceIndex);let g=V.get(A.faceIndex);g||(g={svg:null,visible:!1,width:-1,height:-1,matrixCss:""},V.set(A.faceIndex,g));let u=g.svg;u?(g.visible||(u.style.display="block"),(g.width!==A.width||g.height!==A.height)&&(u.setAttribute("width",String(A.width)),u.setAttribute("height",String(A.height)),u.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),g.width=A.width,g.height=A.height),g.matrixCss!==A.matrixCss&&(u.style.transform=A.matrixCss,g.matrixCss=A.matrixCss)):(u=e.doc.createElementNS(Aa,"svg"),u.setAttribute("class","polycss-shadow polycss-shadow-svg polycss-shadow-receiver"),h.debugShadowAttrs&&(u.setAttribute("data-poly-shadow-type","receiver"),u.setAttribute("data-poly-shadow-receiver",jo(o)),u.setAttribute("data-poly-shadow-receiver-face",String(A.faceIndex)),u.setAttribute("data-poly-shadow-receiver-polys",JSON.stringify(A.memberPolyIndices))),u.setAttribute("width",String(A.width)),u.setAttribute("height",String(A.height)),u.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),u.setAttribute("style",`position:absolute;top:0;left:0;display:block;overflow:hidden;transform-origin:0 0;pointer-events:none;will-change:transform;transform:${A.matrixCss}`),ri(e.shadowSvgState,e.doc,e.sceneEl).appendChild(u),g.svg=u,g.width=A.width,g.height=A.height,g.matrixCss=A.matrixCss),g.visible=!0;let d=ai(u,e.doc,A.paths.length,!0),T=A.opacity.toFixed(4),w=[],R=!!h.debugShadowAttrs;for(let L=0;L<A.paths.length;L++){let re=A.paths[L],_=R?jo(re.casterId):"";R&&w.push(_);let j=d[L];if(j.setAttribute("d",re.d),j.getAttribute("fill")!==A.fill&&j.setAttribute("fill",A.fill),j.getAttribute("stroke")!==A.fill&&j.setAttribute("stroke",A.fill),j.getAttribute("opacity")!==T&&j.setAttribute("opacity",T),R){j.getAttribute("data-poly-shadow-caster")!==_&&j.setAttribute("data-poly-shadow-caster",_);let Q=JSON.stringify(re.casterPolygonIndices);j.getAttribute("data-poly-shadow-caster-polys")!==Q&&j.setAttribute("data-poly-shadow-caster-polys",Q)}}if(R){let L=w.join(" ");u.getAttribute("data-poly-shadow-casters")!==L&&u.setAttribute("data-poly-shadow-casters",L)}}for(let[A,g]of V)G.has(A)||g.svg&&g.visible&&(g.svg.style.display="none",g.visible=!1)}var xi=Symbol.for("polycss.animation.triangleFrameTarget");var Ma=750;function Pi(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:ne.DEFAULT_SEAM_BLEED}}var wa={key:"non-cullable",normal:[1,1,0]};function Si(){return[wa]}function Ci(e,n){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");if(!n?.camera)throw new Error("createPolyScene: a camera handle is required. Use createPolyCamera({...}) or createPolyPerspectiveCamera({...}) and pass as { camera }.");let t=n.camera;e.ownerDocument&&Yr(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...r}=n,i=Pi({seamBleed:ne.DEFAULT_SEAM_BLEED,...r}),s=Xr(e),c=[0,0,0],l=e.ownerDocument??document,p=l.createElement("div");p.className="polycss-camera",Z(p,i),e.appendChild(p);let h=l.createElement("div");h.className="polycss-scene",h.setAttribute("aria-hidden","true"),q(h,i),p.appendChild(h);let x=li({host:e,doc:l,cameraEl:p,sceneEl:h,camera:t,layoutScale:s,options:i}),f=x.meshes,b=new WeakMap,y=x.shadowSvgState,P=()=>si(y),v=()=>pi(x),C=null;function F(a){if(!a)return null;let m=Math.hypot(a[0],a[1],a[2]);if(!Number.isFinite(m)||m<=0)return null;let S=Math.round(a[0]/m*100)/100,E=Math.round(a[1]/m*100)/100,W=Math.round(a[2]/m*100)/100;return`${S}|${E}|${W}`}function k(){C=null}let z=a=>di(x,a),O=a=>ui(x,a);function Z(a,m){let S=t.perspectiveStyle;if(S==="none")a.style.perspective="1000000px";else{let E=parseFloat(S);Number.isFinite(E)&&(a.style.perspective=`${E}px`)}}function q(a,m){Zr(a,s),a.style.transform=Go(t,c,s),ti(a,m)}function D(a){a.style.transform=Go(t,c,s)}function H(a){a.voxelRenderer?.dispose(),a.voxelRenderer=void 0,g(a.rendered,a.disposeAtlas),a.disposeAtlas=void 0,a.rendered.length=0,a.renderedByPolygonIndex=[],a.cameraCullGroups=[],a.cameraCullSignature="",a.solidLightingPreviewPrepared=!1,a.solidLightingPreviewActive=!1,A(a);for(let m of Array.from(a.wrapper.children))m instanceof HTMLElement&&m.classList.contains("polycss-bucket")&&m.remove();a.hasBuckets=!1}function V(a){for(let m of Array.from(a.wrapper.childNodes)){if(!(m instanceof HTMLElement))return m;if(m.classList.contains("polycss-bucket")||m.classList.contains("polycss-shadow"))continue;let S=m.tagName.toLowerCase();if(!(S==="b"||S==="i"||S==="s"||S==="u"||S==="q"))return m}return null}function G(a,m,S){S?.parentNode===a.wrapper?a.wrapper.insertBefore(m,S):a.wrapper.appendChild(m)}function A(a){for(let m of a.shadowRendered)m.parentNode&&m.parentNode.removeChild(m);a.shadowRendered.length=0,v()}function g(a,m){m?.();for(let S of a){try{S.dispose()}catch{}S.element.parentNode&&S.element.parentNode.removeChild(S.element)}}function u(a,m,S){a.rendered=m,a.renderedByPolygonIndex=[];for(let E of m)a.renderedByPolygonIndex[E.polygonIndex]=E;a.disposeAtlas=S,a.solidLightingPreviewPrepared=!1}function d(a,m){let S=a.renderedByPolygonIndex[m];return S?.polygonIndex===m?S:void 0}function T(a){for(let m of Array.from(a.wrapper.children))m instanceof HTMLElement&&m.classList.contains("polycss-bucket")&&m.remove();a.hasBuckets=!1;for(let m of a.rendered)m.element.parentNode&&m.element.parentNode.removeChild(m.element)}function w(a,m){let S=a.polygons[m.polygonIndex];return a.stableDom&&S?(0,ne.polygonCssSurfaceNormal)(S):m.plan?.normal??(S?(0,ne.polygonCssSurfaceNormal)(S):null)}function R(a){if(!Q(a))return a.rendered;let m=L(a);return a.rendered.filter(S=>re(a,S,ne.CAMERA_BACKFACE_CULL_EPS,m))}function L(a){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:a.handle.transform.rotation}}function re(a,m,S=ne.CAMERA_BACKFACE_CULL_EPS,E=L(a)){let W=w(a,m);return W===null||(0,ne.normalFacesCamera)(W,E,S)}function _(a){if(a.excludeFromAutoCenter){a.cameraCullGroups=[];return}let m=new Map;for(let S of a.rendered){let E=w(a,S);if(!E)continue;if(!(0,ne.isAxisAlignedSurfaceNormal)(E)){a.cameraCullGroups=Si();return}let W=(0,ne.cameraCullNormalKey)(E);if(!m.has(W)&&(m.set(W,E),m.size>ne.VOXEL_CAMERA_CULL_NORMAL_LIMIT)){a.cameraCullGroups=Si();return}}a.cameraCullGroups=Array.from(m,([S,E])=>({key:S,normal:E}))}function j(a){return Q(a)?(0,ne.cameraCullVisibleSignature)(a.cameraCullGroups,L(a)):"all"}function Q(a){return!a.excludeFromAutoCenter&&(0,ne.isVoxelCameraCullableNormalGroups)(a.cameraCullGroups)}function ae(a){a.cameraCullSignature=Q(a)?j(a):"all"}function be(a,m){let S=new Array(a.rendered.length),E=!1,W=L(a);for(let K=0;K<a.rendered.length;K+=1){let se=a.rendered[K],te=re(a,se,m,W);S[K]=te}let B=null,I=null,U=()=>{if(!(!B||!I)){if(B===I)B.remove();else{let K=l.createRange();K.setStartBefore(B),K.setEndAfter(I),K.deleteContents(),K.detach()}B=null,I=null,E=!0}};for(let K=0;K<a.rendered.length;K+=1){let se=a.rendered[K];!S[K]&&se.element.parentNode===a.wrapper?(I&&I.nextSibling===se.element||(U(),B=se.element),I=se.element):U()}U();let Y=K=>{for(let se=K;se<a.rendered.length;se+=1){let te=a.rendered[se].element;if(te.parentNode===a.wrapper)return te}return V(a)},de=-1,ie=K=>{if(de<0)return;let se=l.createDocumentFragment();for(let te=de;te<K;te+=1){let Ne=a.rendered[te];Se(a,Ne),se.appendChild(Ne.element)}G(a,se,Y(K)),de=-1,E=!0};for(let K=0;K<a.rendered.length;K+=1){let se=a.rendered[K];S[K]&&se.element.parentNode!==a.wrapper?de<0&&(de=K):ie(K)}return ie(a.rendered.length),E}function fe(a,m=!1){if(a.voxelRenderer){m?a.voxelRenderer.render(L(a)):a.voxelRenderer.syncCamera(L(a)),a.cameraCullSignature="voxel-direct";return}if(!Q(a)){let W=a.cameraCullSignature!=="all";a.cameraCullSignature="all",W&&Ce(a);return}if(a.hasBuckets){ge(a,m);return}let S=j(a);if(!m&&S===a.cameraCullSignature)return;let E=be(a,ne.CAMERA_BACKFACE_CULL_EPS);a.cameraCullSignature=S,E&&Ye(a)}function ge(a,m=!1){let S=Q(a)?j(a):"all";!m&&S===a.cameraCullSignature||Ce(a)}function we(a,m){return w(a,m)}function Se(a,m){if(i.textureLighting!=="dynamic")return;let S=we(a,m);S&&(m.element.style.setProperty("--pnx",S[0].toFixed(4)),m.element.style.setProperty("--pny",S[1].toFixed(4)),m.element.style.setProperty("--pnz",S[2].toFixed(4)))}function ke(a){T(a),a.hasBuckets=!1;let m=a.skipBucketNormalCleanupOnce;a.skipBucketNormalCleanupOnce=!1;let S=l.createDocumentFragment(),E=i.textureLighting==="dynamic"&&!a.stableDom,W=new Map,B=[];for(let I of R(a)){let U=a.polygons[I.polygonIndex],Y=E&&U?Qr(U):null;if(!Y){B.push(I);continue}let de=Y.key+"|"+(U.color??""),ie=W.get(de);ie||(ie={vec:Y.vec,items:[]},W.set(de,ie)),ie.items.push(I)}for(let I of B)Se(a,I),S.appendChild(I.element);for(let I of W.values()){if(I.items.length<2){for(let Y of I.items)Se(a,Y),S.appendChild(Y.element);continue}let U=l.createElement("div");U.className="polycss-bucket",a.hasBuckets=!0,U.style.setProperty("--pnx",String(I.vec[0])),U.style.setProperty("--pny",String(I.vec[1])),U.style.setProperty("--pnz",String(I.vec[2]));for(let Y of I.items)U.appendChild(Y.element),(!m||Y.kind==="triangle")&&(Y.element.style.removeProperty("--pnx"),Y.element.style.removeProperty("--pny"),Y.element.style.removeProperty("--pnz"));S.appendChild(U)}G(a,S,V(a)),ae(a)}function We(){return new Promise(a=>setTimeout(a,0))}async function et(a,m){if(i.textureLighting==="dynamic"&&!a.stableDom)return ke(a),!m();T(a);let E=l.createDocumentFragment(),W=V(a),B=0;for(let I of R(a)){if(m())return!1;Se(a,I),E.appendChild(I.element),B++,B%Ma===0&&(G(a,E,W),E=l.createDocumentFragment(),await We())}return E.childNodes.length>0&&G(a,E,W),ae(a),!m()}function mt(a,m){let S=i.textureLighting==="dynamic",E=i.directionalLight?.direction,W=m&&(m[0]!==0||m[1]!==0||m[2]!==0);if(!S||!W||!E){if(a.lightOverrideSignature==="clear")return;a.wrapper.style.removeProperty("--plx"),a.wrapper.style.removeProperty("--ply"),a.wrapper.style.removeProperty("--plz"),a.lightOverrideSignature="clear";return}let B=(0,ne.inverseRotateVec3)(E,m),I=Vt(B),U=Math.hypot(I[0],I[1],I[2])||1,Y=(I[0]/U).toFixed(2),de=(I[1]/U).toFixed(2),ie=(I[2]/U).toFixed(2),K=`${Y}|${de}|${ie}`;a.lightOverrideSignature!==K&&(a.wrapper.style.setProperty("--plx",Y),a.wrapper.style.setProperty("--ply",de),a.wrapper.style.setProperty("--plz",ie),a.lightOverrideSignature=K)}function Ct(a){let m=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let E=a.polygons[S.polygonIndex];E&&(m=Uo(S,E,i)||m)}return a.solidLightingPreviewPrepared=!1,a.solidLightingPreviewActive=!1,m}function ft(a){if((i.textureLighting??"baked")!=="baked")return!1;let m=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let E=a.polygons[S.polygonIndex];E&&(oi(S,E,S.plan.shadedColor),m=!0)}return a.solidLightingPreviewPrepared=m,m}function co(a){return(i.textureLighting??"baked")!=="baked"||!a.solidLightingPreviewPrepared&&!ft(a)?!1:(a.solidLightingPreviewActive=!0,!0)}function uo(a){return a.kind==="atlas"||!!a.plan?.texture}function po(){if((i.textureLighting??"baked")!=="baked")return!1;let a=!1;for(let m of f)a=Ct(m)||a,m.rendered.some(uo)&&(Yt(m),a=!0);h.style.removeProperty(Bt);for(let m of f)bt(m.wrapper),m.solidLightingPreviewActive=!1;return bt(h),a}function mo(){h.style.removeProperty(Bt);for(let a of f)a.solidLightingPreviewActive&&(Ct(a),bt(a.wrapper));(i.textureLighting??"baked")!=="dynamic"&&(bt(h),k(),Le())}function $(a,m){let S=a.handle.transform.rotation,E=m.directionalLight?.direction??i.directionalLight?.direction;if(!(S&&(S[0]!==0||S[1]!==0||S[2]!==0))||!E){bt(a.wrapper);return}let B=(0,ne.inverseRotateVec3)(E,S);Xn(a.wrapper,{...i,...m,directionalLight:{...i.directionalLight,...m.directionalLight,direction:B}})}function le(a){if((i.textureLighting??"baked")!=="baked")return!1;Xn(h,{...i,...a}),!a.skipShadows&&a.directionalLight?.direction&&Le(a.directionalLight.direction);let m=!1;for(let S of f)$(S,a),m=co(S)||m;return m?me(h,Bt,"1"):h.style.removeProperty(Bt),m}function ce(a,m,S){let E=a.polygons[m];if(!E)return!1;let W=d(a,m);if(!W)return!1;let B=i.textureLighting??"baked";return B==="dynamic"?(ni(W.element,S),!0):B==="baked"?Uo(W,E,i):!1}function De(a,m){let S=a.polygons[m];if(!S)return!1;let E=d(a,m);return E?(Pe(E.element,S,m),!0):!1}function Wt(a,m,S){return!(S.length===0||!S.every(E=>E==="color"||E==="data")||S.includes("color")&&!ce(a,m,a.polygons[m]?.color)||S.includes("data")&&!De(a,m))}function Ye(a){k(),Le()}function Le(a){let m=[];for(let te of f)!te.disposed&&te.castShadow&&m.push(te);if(m.length===0){v(),C=null;return}let S=i.shadow?.color??"#000000",E=i.shadow?.opacity??.25,W=(0,ne.parseHexColor)(S)?.rgb??[0,0,0],B=W[0],I=W[1],U=W[2],Y=a??i.directionalLight?.direction??[.4,-.7,.59],de=Vt(Y),ie=F(de);if(ie!==null&&ie===C)return;let K=new Map;for(let te of m)K.set(te,(0,ne.findOverlappingPolygonDuplicates)(te.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.95,preserveDoubleSidedBackfaces:!1}));let se=new Map;for(let te of f)te.disposed||!te.receiveShadow||se.set(te,new Set);P();for(let te of f)te.disposed||!te.receiveShadow||vi(x,m,K,te,se.get(te)??new Set,de,B,I,U,E);C=ie}function Ce(a){if(a.voxelRenderer){a.voxelRenderer.render(L(a)),a.cameraCullSignature="voxel-direct";return}A(a),ke(a),Ye(a)}function Be(a,m){if(!m||!a.polygons||a.polygons.length<2)return;let S=Math.hypot(m[0],m[1],m[2]);if(!Number.isFinite(S)||S<=0)return;let E=m[0]/S,W=m[1]/S,B=m[2]/S,I=K=>Math.round(K*1e3)/1e3,U=`${I(E)},${I(W)},${I(B)}`,Y=a.lightOcclusionCache;if(Y&&Y.polygons===a.polygons&&Y.lightDirKey===U)return Y.occluded;let de=Y&&Y.polygons===a.polygons?Y.dedupDropped:(0,ne.findOverlappingPolygonDuplicates)(a.polygons,{normalTolerance:.1,distanceTolerance:.12,overlapFraction:.98,preserveDoubleSidedBackfaces:!1}),ie=(0,ne.computeLightVisibility)(a.polygons,[E,W,B],de);return a.lightOcclusionCache={polygons:a.polygons,lightDirKey:U,occluded:ie,dedupDropped:de},ie}function ze(a){return!!a.voxelSource&&i.textureLighting!=="dynamic"&&!a.stableDom&&!a.castShadow}function Me(a,m){H(a);let S=i.directionalLight,E=m?{...S,direction:m}:S,W=ut(E),B=void 0;if(ze(a)){let Y=jr({doc:l,wrapper:a.wrapper,polygons:a.parseResult.polygons,directionalLight:W,ambientLight:i.ambientLight});if(Y){a.voxelRenderer=Y,Y.render(L(a)),a.cameraCullSignature="voxel-direct";return}}let I={doc:l,directionalLight:W,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies,lightOccludedPolyIndices:B},U=a.stableDom?(()=>{let Y=Ot(a.polygons,I);return vt(a.wrapper,Y),on(a.polygons,{...I,solidPaintDefaults:Y})??Ht(a.polygons,{...I,solidPaintDefaults:Y})})():Ht(a.polygons,{...I,computeSolidPaintDefaults:!0,skipDynamicNormalVars:i.textureLighting==="dynamic"});a.stableDom||vt(a.wrapper,U.solidPaintDefaults??{}),u(a,U.rendered,U.dispose),a.skipBucketNormalCleanupOnce=i.textureLighting==="dynamic"&&!a.stableDom,_(a),ke(a),Ye(a)}function Yt(a,m){if(a.rendered.length===0||a.voxelRenderer||a.stableDom||ze(a)){Me(a,m);return}if(a.rendered[0]?.element.parentNode===null){Me(a,m);return}let S=i.directionalLight,E=m?{...S,direction:m}:S,W=ut(E),B={doc:l,directionalLight:W,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies,computeSolidPaintDefaults:!0,skipDynamicNormalVars:i.textureLighting==="dynamic"},I=Ht(a.polygons,B),U=()=>{a.rebakeInFlight=!1;let ie=a.rebakeQueuedLightDir;ie!==null&&(a.rebakeQueuedLightDir=null,Yt(a,ie))},Y=()=>{if(a.disposed){I.dispose(),U();return}if(I.rendered.length!==a.rendered.length){I.dispose(),Me(a,m),U();return}for(let se of I.rendered){let te=a.renderedByPolygonIndex[se.polygonIndex];if(!te)continue;let Ne=se.element.getAttribute("style");Ne!==null&&te.element.setAttribute("style",Ne)}let ie=I.solidPaintDefaults;ie&&vt(a.wrapper,ie);let K=a.disposeAtlas;a.disposeAtlas=I.dispose,K&&(typeof requestAnimationFrame=="function"?te=>{requestAnimationFrame(te)}:te=>{setTimeout(te,0)})(K),Ye(a),U()},de=I.pagesReady;de&&typeof de.then=="function"?de.then(()=>ho(I.rendered)).then(go).then(Y,()=>{I.dispose(),a.disposed||Me(a,m),U()}):Y()}function fo(a,m){if(a.rebakeInFlight){a.rebakeQueuedLightDir=m;return}a.rebakeInFlight=!0,Yt(a,m)}function ho(a){let m=new Set;for(let S of a){let E=S.element.getAttribute("style")??"",W=/url\((blob:[^)]+)\)/g,B;for(;(B=W.exec(E))!==null;)m.add(B[1])}return Array.from(m)}function go(a){return a.length===0||typeof Image>"u"?Promise.resolve():Promise.all(a.map(m=>{let S=new Image;S.src=m;let E=S.decode?.();return E?E.catch(()=>{}):Promise.resolve()})).then(()=>{})}function tt(){let a=1/0,m=!1;for(let B of f)if(!B.disposed&&B.receiveShadow){m=!0;break}for(let B of f){if(B.disposed||!(m?B.receiveShadow:B.castShadow))continue;let U=B.handle.transform.position?.[2]??0;for(let Y of B.polygons)for(let de of Y.vertices){let ie=de[2]+U;ie<a&&(a=ie)}}if(!Number.isFinite(a)){let B=y.currentGroundCssZ!==null;y.currentGroundCssZ=null,B&&(v(),k());return}let S=i.shadow?.lift??.05,E=(a+S)*at,W=y.currentGroundCssZ;y.currentGroundCssZ=E,W!==E&&(k(),Le())}async function _n(a,m){H(a);let S=ut(i.directionalLight),E={doc:l,directionalLight:S,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies,lightOccludedPolyIndices:void 0},W=a.stableDom?on(a.polygons,E):null;if(W){let U=Ot(a.polygons,E);return vt(a.wrapper,U),u(a,W.rendered,W.dispose),_(a),ke(a),Ye(a),!m()}let B=await Gn(a.polygons,{...E,skipDynamicNormalVars:i.textureLighting==="dynamic"},m);if(m())return B.dispose(),!1;vt(a.wrapper,B.solidPaintDefaults),u(a,B.rendered,B.dispose),a.skipBucketNormalCleanupOnce=i.textureLighting==="dynamic"&&!a.stableDom,_(a);let I=await et(a,m);return I&&Ye(a),I}function ht(){let a=c,m=[0,0,0];if(i.autoCenter){let S=[];for(let E of f)!E.disposed&&!E.excludeFromAutoCenter&&S.push(...E.polygons);if(S.length>0){let E=(0,ne.computeSceneBbox)(S);m=[(E.min[0]+E.max[0])/2,(E.min[1]+E.max[1])/2,(E.min[2]+E.max[2])/2]}}a[0]===m[0]&&a[1]===m[1]&&a[2]===m[2]||(c=m,x.autoCenter.offset=m,q(h,i))}function es(a,m={}){let E=(h.ownerDocument??document).createElement("div");E.className="polycss-mesh",m.id&&E.setAttribute("data-poly-mesh-id",m.id);let W=`polycss-mesh-${x.meshAutoCounter.next++}`;E.setAttribute("data-poly-mesh-index",W);let B={...m},I=m.merge!==!1,U=!!m.stableDom,Y=0,de=Yn(B);de&&(E.style.transform=de);let ie=(N,X)=>a.voxelSource?N:X?(0,ne.optimizeMeshPolygons)(N,{meshResolution:m.meshResolution}):(U||m.excludeFromAutoCenter,N),K=ie(a.polygons,I),se=null;function te(){let N=Yn(B);E.style.transform=N??""}function Ne(N){if(N.length===0){se=null,Xe&&(Xe.bboxCenterCss=null),te();return}let X=1/0,ue=1/0,ye=1/0,Oe=-1/0,pe=-1/0,xe=-1/0;for(let qe of N)for(let $e of qe.vertices)$e[0]<X&&(X=$e[0]),$e[0]>Oe&&(Oe=$e[0]),$e[1]<ue&&(ue=$e[1]),$e[1]>pe&&(pe=$e[1]),$e[2]<ye&&(ye=$e[2]),$e[2]>xe&&(xe=$e[2]);if(!Number.isFinite(X)){se=null,Xe&&(Xe.bboxCenterCss=null),te();return}let Ge=(ue+pe)/2*at,Qe=(X+Oe)/2*at,He=(ye+xe)/2*at;se=[Ge,Qe,He],Xe&&(Xe.bboxCenterCss=se),te()}let Xe=null;Ne(K),h.appendChild(E);let M={handle:void 0,wrapper:E,parseResult:a,rendered:[],renderedByPolygonIndex:[],shadowRendered:[],polygons:K,voxelSource:a.voxelSource,disposed:!1,stableDom:U,hasBuckets:!1,skipBucketNormalCleanupOnce:!1,excludeFromAutoCenter:!!m.excludeFromAutoCenter,castShadow:!!m.castShadow,bboxCenterCss:se,receiveShadow:!!m.receiveShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",stableTriangleColorFrame:0,solidLightingPreviewPrepared:!1,solidLightingPreviewActive:!1,bakedRotation:m.rotation?[...m.rotation]:[0,0,0],autoMeshId:W,rebakeInFlight:!1,rebakeQueuedLightDir:null},Ze=null,yo=0,Rn=-1,Xt=null;function Zt(){Ze=null,Xt=null,Rn=-1}function nr(){let N=Ze;if(!N||N.polygonCount!==M.polygons.length)return M.polygons;if(Xt&&Rn===yo)return Xt;let X=N.vertices,ue=new Array(N.polygonCount);for(let ye=0;ye<N.polygonCount;ye++){let Oe=M.polygons[ye],pe=ye*9;ue[ye]={...Oe,color:N.colors?.[ye]??Oe.color,vertices:[[X[pe],X[pe+1],X[pe+2]],[X[pe+3],X[pe+4],X[pe+5]],[X[pe+6],X[pe+7],X[pe+8]]]}}return Xt=ue,Rn=yo,ue}function or(N,X){let ue=N?.stableTriangleUpdateMode==="color-only";M.stableTriangleColorFrame++;let ye=M.stableDom&&!X;if(ye||Ne(M.polygons),M.stableDom&&!M.hasBuckets){let Oe={doc:l,directionalLight:ut(i.directionalLight),ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed},pe=M.rendered.length===M.polygons.length&&M.rendered.every(He=>He.kind==="triangle"),xe=M.stableDom&&!X,Ge=pe||xe?{}:Ot(M.polygons,Oe);pe||vt(M.wrapper,Ge);let Qe={...Oe,solidPaintDefaults:Ge,optimizeStableTriangleStyle:!0,stableTriangleDebug:N?.stableTriangleDebug,stableTriangleUpdateMode:N?.stableTriangleUpdateMode,stableTriangleColorPolicy:N?.stableTriangleColorPolicy,stableTriangleColorSteps:N?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:N?.stableTriangleColorFreezeFrames,stableTriangleColorBudget:N?.stableTriangleColorBudget,stableTriangleColorMaxAge:N?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:N?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:N?.stableTriangleMatrixDecimals,stableTriangleColorFrame:M.stableTriangleColorFrame};if(Un(M.rendered,M.polygons,Qe))return ue||(_(M),fe(M,!0),X&&ht()),!0}return ye&&Ne(M.polygons),!1}let Et={get polygons(){return nr()},set polygons(N){Zt(),M.polygons=N},element:E,id:m.id,get transform(){return B},remove(){Y++,E.parentNode&&E.parentNode.removeChild(E),H(M),f.delete(M),b.delete(E),z(M),O(M),ht(),tt()},setPolygons(N,X){Y++,I=X?.merge??I,U=X?.stableDom??U,M.stableDom=U,M.voxelSource=void 0,M.polygons=ie(N,I),O(M),z(M),Zt(),Et.polygons=M.polygons;let ue=X?.recomputeAutoCenter??!0;or(X,ue)||(Me(M),ue&&ht())},[xi](N,X){let ue=X?.merge??I,ye=X?.stableDom??U;if(!N.solidTriangles||!ye||ue||m.meshResolution!==void 0||M.hasBuckets||N.polygonCount!==M.polygons.length||N.vertices.length<N.polygonCount*9||M.rendered.length!==N.polygonCount)return!1;for(let xe=0;xe<M.rendered.length;xe++){let Ge=M.rendered[xe],Qe=M.polygons[xe];if(Ge?.kind!=="triangle"||Ge.polygonIndex!==xe||!Qe||Qe.vertices.length!==3||Qe.texture||Qe.material?.texture)return!1}let Oe=X?.recomputeAutoCenter??!0;if(!Oe){let xe=M.stableTriangleColorFrame+1,Ge={doc:l,directionalLight:ut(i.directionalLight),ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,solidPaintDefaults:{},optimizeStableTriangleStyle:!0,stableTriangleDebug:X?.stableTriangleDebug,stableTriangleUpdateMode:X?.stableTriangleUpdateMode,stableTriangleColorPolicy:X?.stableTriangleColorPolicy,stableTriangleColorSteps:X?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:X?.stableTriangleColorFreezeFrames??0,stableTriangleColorBudget:X?.stableTriangleColorBudget,stableTriangleColorMaxAge:X?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:X?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:X?.stableTriangleMatrixDecimals,stableTriangleColorFrame:xe};if($n(M.rendered,M.polygons,N,Ge))return Y++,I=ue,U=ye,M.stableDom=U,M.voxelSource=void 0,M.stableTriangleColorFrame=xe,Ze=N,yo++,Xt=null,Rn=-1,Q(M)?(_(M),fe(M,!0)):ae(M),!0}Y++,I=ue,U=ye,M.stableDom=U,M.voxelSource=void 0;let pe=N.vertices;for(let xe=0;xe<N.polygonCount;xe++){let Ge=M.polygons[xe],Qe=N.colors?.[xe];Qe&&(Ge.color=Qe);let He=Ge.vertices,qe=xe*9;He[0][0]=pe[qe],He[0][1]=pe[qe+1],He[0][2]=pe[qe+2],He[1][0]=pe[qe+3],He[1][1]=pe[qe+4],He[1][2]=pe[qe+5],He[2][0]=pe[qe+6],He[2][1]=pe[qe+7],He[2][2]=pe[qe+8]}return Zt(),Et.polygons=M.polygons,or(X,Oe)},updatePolygon(N,X){let ue=typeof N=="number"?N:M.polygons.indexOf(N);if(ue<0&&typeof N!="number"&&Ze&&(ue=nr().indexOf(N)),ue<0||ue>=M.polygons.length)return;Zt(),M.voxelSource=void 0,Object.assign(M.polygons[ue],X);let ye=Object.keys(X);Wt(M,ue,ye)||Me(M)},async setPolygonsChunked(N,X){let ue=++Y;I=X?.merge??I,U=X?.stableDom??U,M.stableDom=U,M.voxelSource=void 0,M.polygons=ie(N,I),Zt(),Et.polygons=M.polygons,Ne(M.polygons);let ye=X?.recomputeAutoCenter??!0;if(!await _n(M,()=>M.disposed||ue!==Y)){H(M);return}ye&&ht()},setTransform(N){let X=M.castShadow,ue=M.receiveShadow;N.castShadow!==void 0&&(M.castShadow=!!N.castShadow),N.receiveShadow!==void 0&&(M.receiveShadow=!!N.receiveShadow),B={...B,...N};let ye=Yn(B);E.style.transform=ye??"",mt(M,B.rotation),N.rotation!==void 0&&fe(M,!0),M.castShadow!==X&&(M.voxelSource&&Me(M),Ye(M),tt()),M.receiveShadow!==ue&&(M.receiveShadow||Wo(M),k(),Le()),(N.position!==void 0||N.scale!==void 0)&&(M.castShadow||M.receiveShadow)&&(tt(),k(),Le())},dispose(){if(!M.disposed){M.disposed=!0,Y++,E.parentNode&&E.parentNode.removeChild(E),H(M);try{a.dispose()}catch{}f.delete(M),b.delete(E),ht(),tt()}},rebakeAtlas(){M.bakedRotation=B.rotation?[...B.rotation]:[0,0,0];let N=i.directionalLight?.direction??[.4,-.7,.59],X=(0,ne.inverseRotateVec3)(N,M.bakedRotation);fo(M,X)},getPosition(){return B.position},getRotation(){return B.rotation},getScale(){return B.scale},getPolygons(){return Et.polygons}};return M.handle=Et,Xe=M,b.set(E,M),f.add(M),Me(M),mt(M,B.rotation),ht(),tt(),M.receiveShadow&&(k(),Le()),Et}function ts(a){let m=!!i.autoCenter,S=i.strategies,E=i.seamBleed,W=i.textureLighting,B=i.directionalLight?.direction,I=i.shadow,U=Pi(a);i={...i,...U},x.options.current=i,q(h,i);let Y=!!i.autoCenter;for(let Ze of f)mt(Ze,Ze.handle.transform.rotation);let de=a.strategies!==void 0&&!qr(a.strategies,S),ie=Object.prototype.hasOwnProperty.call(a,"seamBleed")&&U.seamBleed!==E;if(de||ie)for(let Ze of f)Me(Ze);m!==Y&&ht();let K=a.textureLighting!==void 0&&W!==i.textureLighting,se=i.directionalLight?.direction,te=a.directionalLight!==void 0&&!Kr(B,se),Ne=i.shadow,Xe=a.shadow!==void 0&&!Jr(I,Ne),M=te||Xe;if(K){if(!de&&!ie)for(let Ze of f)Me(Ze);tt(),k(),Le()}else M&&(Xe&&k(),Le());Xe&&a.shadow?.lift!==I?.lift&&tt()}function ns(){return i}function os(){D(h);for(let a of f)fe(a)}function rs(){let a=[];for(let m of f)a.push(m.handle);return a}function is(a){let m=a;for(;m;){if(m instanceof HTMLElement){let S=b.get(m);if(S&&!S.disposed)return S.handle;if(m.classList.contains("polycss-mesh"))return null}m=m.parentElement}return null}function ss(){let a=Array.from(f);for(let m of a)try{m.handle.dispose()}catch{}p.parentNode&&p.parentNode.removeChild(p)}return{add:es,setOptions:ts,destroy:ss,host:e,camera:t,cameraEl:p,sceneElement:h,applyCamera:os,getOptions:ns,meshes:rs,findMeshByElement:is,previewBakedSolidLighting:le,commitBakedSolidLighting:po,clearBakedSolidLightingPreview:mo}}var Yo=require("@layoutit/polycss-core"),La=32e3;function qn(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,Yo.createIsometricCamera)(n),o=`${e.perspective??La}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function rn(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,Yo.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var _a=typeof HTMLElement<"u"?HTMLElement:class{},Ra=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function je(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function ka(e){return e==="false"?!1:je(e)}function Xo(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 Da(e){if(e==="baked"||e==="dynamic")return e}function Oa(e){return e==="auto"?"auto":je(e)}function Ha(e){return typeof e.getCamera=="function"}var _e=class extends _a{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...Ra]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(Ha(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=ka(this.getAttribute("perspective")),o=je(this.getAttribute("rot-x")),r=je(this.getAttribute("rot-y")),i=je(this.getAttribute("zoom")),s=je(this.getAttribute("distance")),c=Xo(this.getAttribute("target")),l={...o!==void 0?{rotX:o}:{},...r!==void 0?{rotY:r}:{},...i!==void 0?{zoom:i}:{},...s!==void 0?{distance:s}:{},...c!==void 0?{target:c}:{}};return t===!1?rn(l):t!==void 0?qn({...l,perspective:t}):rn(l)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={};r.textureLighting=Da(this.getAttribute("texture-lighting"))??"baked";let i=Oa(this.getAttribute("texture-quality"));return i!==void 0&&(r.textureQuality=i),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=Xo(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=je(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let i={direction:t??[.4,-.7,.59]};return o&&(i.color=o),r!==void 0&&(i.intensity=r),i}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=je(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){if(this._scene)return;let t=this._findAncestorCamera(),o;t?(o=t,this._implicitCamera=null):(this._implicitCamera=this._buildImplicitCamera(),o=this._implicitCamera),this._scene=Ci(this,{camera:o,...this._readNonCameraOptions()}),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1}))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null),this._implicitCamera=null}attributeChangedCallback(t,o,r){if(o!==r&&this._scene){if(this._implicitCamera&&["rot-x","rot-y","zoom","distance","target"].includes(t)){let s=je(this.getAttribute("rot-x")),c=je(this.getAttribute("rot-y")),l=je(this.getAttribute("zoom")),p=je(this.getAttribute("distance")),h=Xo(this.getAttribute("target"));s!==void 0&&this._implicitCamera.update({rotX:s}),c!==void 0&&this._implicitCamera.update({rotY:c}),l!==void 0&&this._implicitCamera.update({zoom:l}),p!==void 0&&this._implicitCamera.update({distance:p}),h!==void 0&&this._implicitCamera.update({target:h}),this._scene.applyCamera();return}this._scene.setOptions(this._readNonCameraOptions())}}};var Kn=require("@layoutit/polycss-core"),Ia=typeof HTMLElement<"u"?HTMLElement:class{},Fa=["src","mtl","mesh-resolution","position","scale","rotation","auto-center","cast-shadow","receive-shadow","target-size","default-color","palette","include-objects","exclude-objects"];function sn(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Ei(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return sn(e)}}function Zo(e){if(!e)return;let n=e.split(",").map(t=>t.trim()).filter(t=>t.length>0);return n.length>0?n:void 0}function Va(e){let n=e.getAttribute("target-size"),t=e.getAttribute("default-color"),o=Zo(e.getAttribute("palette")),r=Zo(e.getAttribute("include-objects")),i=Zo(e.getAttribute("exclude-objects")),s=n!==null?parseFloat(n):NaN,c={};return Number.isFinite(s)&&(c.targetSize=s),t&&(c.defaultColor=t),o&&(c.palette=o),r&&(c.includeObjects=r),i&&(c.excludeObjects=i),Object.keys(c).length>0?c:void 0}function Ba(e){return e.closest("poly-scene")??null}function za(e){if(e.length===0)return e;let n=(0,Kn.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let i=s=>[s[0]-t,s[1]-o,s[2]-r];return e.map(s=>({...s,vertices:s.vertices.map(i),...s.textureTriangles?.length?{textureTriangles:s.textureTriangles.map(c=>({...c,vertices:c.vertices.map(i)}))}:null}))}var xt=class extends Ia{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Fa]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"||t==="mesh-resolution"||t==="target-size"||t==="default-color"||t==="palette"||t==="include-objects"||t==="exclude-objects"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:sn(this.getAttribute("position")),scale:Ei(this.getAttribute("scale")),rotation:sn(this.getAttribute("rotation")),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")})}}_tearDown(){if(this._loadToken+=1,this._handle){try{this._handle.dispose()}catch{}this._handle=null}this._parseResult=null}async _maybeLoad(){let t=this.getAttribute("src");if(!t)return;let o=Ba(this);if(!o)return;let r=++this._loadToken,i=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,l=Va(this),p;try{let f=i||c!==void 0||l?{...i?{mtlUrl:i}:{},...c!==void 0?{meshResolution:c}:{},...l?{objOptions:l}:{}}:void 0;p=await(0,Kn.loadMesh)(t,f)}catch(f){this.dispatchEvent(new CustomEvent("polycss:error",{detail:f,bubbles:!0}));return}if(r!==this._loadToken){try{p.dispose()}catch{}return}let h=o.getScene();if(!h){try{p.dispose()}catch{}return}this.hasAttribute("auto-center")&&(p={...p,polygons:za(p.polygons)}),this._parseResult=p,this._handle=h.add(p,{position:sn(this.getAttribute("position")),scale:Ei(this.getAttribute("scale")),rotation:sn(this.getAttribute("rotation")),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var zt=require("@layoutit/polycss-core"),Na=typeof HTMLElement<"u"?HTMLElement:class{},Ga=["src","width","height","position","rotation","scale","allow","loading","referrerpolicy","sandbox","title"];function Qo(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function $a(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Qo(e)}}function Ti(e,n){if(e===null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}function Ua(e){let n=e.closest("poly-scene");return n?n.querySelector(".polycss-scene"):null}function ja(e,n,t,o,r){let i=typeof t=="number"?t:t?.[0]??1,s=typeof t=="number"?t:t?.[1]??1,c=typeof t=="number"?t:t?.[2]??1,l=i!==1||s!==1||c!==1,p=!!n&&(!!n[0]||!!n[1]||!!n[2]),h=(e?.[1]??0)*zt.BASE_TILE,x=(e?.[0]??0)*zt.BASE_TILE,f=(e?.[2]??0)*zt.BASE_TILE,b=[];return b.push(`translate3d(${h}px, ${x}px, ${f}px)`),p&&(n[0]&&b.push(`rotateY(${-n[0]}deg)`),n[1]&&b.push(`rotateX(${-n[1]}deg)`),n[2]&&b.push(`rotateZ(${-n[2]}deg)`)),l&&b.push(`scale3d(${i}, ${s}, ${c})`),b.push(`translate(${-o/2}px, ${-r/2}px)`),b.join(" ")}var an=class extends Na{constructor(){super(...arguments);this._wrapper=null;this._iframe=null}static get observedAttributes(){return[...Ga]}getIframeElement(){return this._iframe}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o!==r&&!(!this._wrapper||!this._iframe)){if(t==="src"){this._iframe.src=this.getAttribute("src")??"";return}if(t==="allow"||t==="loading"||t==="referrerpolicy"||t==="sandbox"||t==="title"){let i=this.getAttribute(t);i===null?this._iframe.removeAttribute(t):this._iframe.setAttribute(t,i);return}this._applyGeometry()}}_mount(){let t=Ua(this);if(!t)return;let o=this.ownerDocument;if(!o)return;let r=o.createElement("div");r.className="polycss-iframe",r.style.position="absolute",r.style.left="0",r.style.top="0",r.style.transformOrigin="0 0",r.style.transformStyle="preserve-3d";let i=o.createElement("iframe");i.style.display="block",i.style.border="0",i.style.background="#000";let s=this.getAttribute("src");s&&(i.src=s);let c=this.getAttribute("allow");c&&i.setAttribute("allow",c);for(let l of["loading","referrerpolicy","sandbox","title"]){let p=this.getAttribute(l);p!==null&&i.setAttribute(l,p)}r.appendChild(i),t.appendChild(r),this._wrapper=r,this._iframe=i,this._applyGeometry()}_applyGeometry(){if(!this._wrapper||!this._iframe)return;let t=Ti(this.getAttribute("width"),16),o=Ti(this.getAttribute("height"),9),r=t*zt.BASE_TILE,i=o*zt.BASE_TILE;this._iframe.style.width=`${r}px`,this._iframe.style.height=`${i}px`;let s=Qo(this.getAttribute("position")),c=Qo(this.getAttribute("rotation")),l=$a(this.getAttribute("scale"));this._wrapper.style.transform=ja(s,c,l,r,i)}_teardown(){this._wrapper?.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null,this._iframe=null}};var Wa=typeof HTMLElement<"u"?HTMLElement:class{},Ya=["vertices","color","texture","uvs","position","scale","rotation"];function Ai(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function qo(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Xa(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return qo(e)}}function Za(e){return e.closest("poly-scene")??null}var ln=class extends Wa{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Ya]}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=Za(this);if(!t)return;let o=t.getScene();if(!o)return;let r=Ai(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let i=this.getAttribute("color")||void 0,s=this.getAttribute("texture")||void 0,c=Ai(this.getAttribute("uvs"))??void 0,l={};for(let x of Array.from(this.attributes))x.name.startsWith("data-")&&(l[x.name.slice(5)]=x.value);let h={polygons:[{vertices:r,...i!==void 0?{color:i}:{},...s!==void 0?{texture:s}:{},...c!==void 0?{uvs:c}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(h,{position:qo(this.getAttribute("position")),scale:Xa(this.getAttribute("scale")),rotation:qo(this.getAttribute("rotation"))})}};var wi=require("@layoutit/polycss-core"),Qa=typeof HTMLElement<"u"?HTMLElement:class{},qa=["size","thickness","negative","x-color","y-color","z-color"];function Ka(e){return e.closest("poly-scene")??null}function Mi(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var cn=class extends Qa{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...qa]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&this._handle&&this._remount()}_polygons(){return(0,wi.axesHelperPolygons)({size:Mi(this.getAttribute("size")),thickness:Mi(this.getAttribute("thickness")),negative:this.hasAttribute("negative"),xColor:this.getAttribute("x-color")??void 0,yColor:this.getAttribute("y-color")??void 0,zColor:this.getAttribute("z-color")??void 0})}_mount(){let t=Ka(this);if(!t)return;let o=t.getScene();if(!o)return;let r={polygons:this._polygons(),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(r,{excludeFromAutoCenter:!0,merge:!1})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var Ri=require("@layoutit/polycss-core"),Ja=typeof HTMLElement<"u"?HTMLElement:class{},el=["direction","target","distance","size","color"],tl=5,nl=.35,ol="#ffd54a";function rl(e){return e.closest("poly-scene")??null}function Li(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function _i(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var dn=class extends Ja{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...el]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="size"||t==="color"){this._remount();return}this._handle.setTransform({position:this._meshPosition()})}}_meshPosition(){let t=Li(this.getAttribute("direction"));if(!t)return;let o=Li(this.getAttribute("target"))??[0,0,0],r=_i(this.getAttribute("distance"),tl),[i,s,c]=t,l=Math.hypot(i,s,c)||1;return[o[0]+i/l*r,o[1]+s/l*r,o[2]+c/l*r]}_mount(){let t=rl(this);if(!t)return;let o=t.getScene();if(!o)return;let r=_i(this.getAttribute("size"),nl),i=this.getAttribute("color")??ol,s={polygons:(0,Ri.octahedronPolygons)({center:[0,0,0],size:r,color:i}),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(s,{position:this._meshPosition(),excludeFromAutoCenter:!0,merge:!1})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var ki=require("@layoutit/polycss-core");var Jn={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Nt(e,n){let t;return n.animate===!1?t=!1:n.animate?t={speed:n.animate.speed??.3,axis:n.animate.axis??"y",pauseOnInteraction:n.animate.pauseOnInteraction??!0}:t=e.animate,{drag:n.drag??e.drag,wheel:n.wheel??e.wheel,dolly:n.dolly??e.dolly,invert:n.invert??e.invert,minZoom:n.minZoom??e.minZoom,maxZoom:n.maxZoom??e.maxZoom,minDistance:n.minDistance??e.minDistance,maxDistance:n.maxDistance??e.maxDistance,animate:t}}function un(e){return e===!0?-1:e===!1?1:e}function Gt(){let e=[],n=[],t=[];function o(s){return s==="change"?e:s==="start"?n:t}function r(s){if(e.length===0)return;let c={type:"change",camera:s()},l=e.slice();for(let p of l)try{p(c)}catch(h){console.error("[polycss] controls 'change' listener threw:",h)}}function i(s,c){let l=s==="start"?n:t;if(l.length===0)return;let p={type:s,camera:c()},h=l.slice();for(let x of h)try{x(p)}catch(f){console.error(`[polycss] controls '${s}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:i}}function $t(e){return()=>{let n=e.camera.state,t=n.target??[0,0,0];return{rotX:n.rotX??0,rotY:n.rotY??0,zoom:n.zoom??1,target:[t[0],t[1],t[2]],distance:n.distance??0}}}function eo(e,n,t,o,r,i){let s=!1,c=null;return{onWheel:h=>{let x=n();if(!x.wheel||t())return;h.preventDefault();let f=h.deltaMode===1?16:h.deltaMode===2?100:1,b=h.deltaY*f;h.ctrlKey?b*=10:b*=3;let y=e.camera.state;if(x.dolly){let P=y.distance??0,v=Math.max(x.minDistance,Math.min(x.maxDistance,P+b*.05));e.camera.update({distance:v})}else{let P=Math.exp(-b*513e-6),v=y.zoom??1,C=Math.max(x.minZoom,Math.min(x.maxZoom,v*P));e.camera.update({zoom:C})}e.applyCamera(),s||(s=!0,i("start",o)),r(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,s=!1,i("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),s=!1}}}function to(e,n,t,o,r,i,s){let c=null,l=0,p=b=>{if(c===null||o())return;let y=t();if(!y.animate){c=null;return}if(r())l=b;else{let P=Math.min(50,l?b-l:16.67);l=b;let v=y.animate.speed*(P/16.67),C=n.camera.state;if(y.animate.axis==="x"){let F=(((C.rotX??65)+v)%360+360)%360;n.camera.update({rotX:F})}else{let F=(((C.rotY??45)+v)%360+360)%360;n.camera.update({rotY:F})}n.applyCamera(),s(i)}c=e.requestAnimationFrame(p)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(p))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function Di(e,n={}){let t=Nt(Jn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,i=null,s={x:0,y:0},c=!1,l=!1,p=Gt(),h=$t(e),{changeListeners:x,startListeners:f,endListeners:b,listenerArray:y,emitChange:P,emitInteraction:v}=p,C=to(r,e,()=>t,()=>l,()=>c,h,P),F=d=>{if(!(!t.drag||l)&&i===null&&d.isPrimary!==!1){d.preventDefault(),i=d.pointerId,s={x:d.clientX,y:d.clientY},o.style.cursor="grabbing";try{d.target.setPointerCapture(d.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),v("start",h)}},k=d=>{if(i===null||d.pointerId!==i||!t.drag||l)return;d.preventDefault();let T=d.clientX-s.x,w=d.clientY-s.y;s={x:d.clientX,y:d.clientY};let R=un(t.invert),L=T/4*R,re=w/4*R,_=e.camera.state;if(d.shiftKey){let j=_.rotX??65,Q=_.rotY??45,ae=Math.max(.01,_.zoom??1),be=Math.cos(j*Math.PI/180),fe=be>=0?Math.max(.1,be):Math.min(-.1,be),ge=Math.cos(Q*Math.PI/180),we=Math.sin(Q*Math.PI/180),Se=ae*ki.BASE_TILE,ke=(T*we-w*ge/fe)/Se,We=-(T*ge+w*we/fe)/Se,et=_.target??[0,0,0];e.camera.update({target:[et[0]+ke,et[1]+We,et[2]]})}else{let j=Math.max(0,Math.min(89,(_.rotX??65)-re)),Q=(((_.rotY??45)-L)%360+360)%360;e.camera.update({rotX:j,rotY:Q})}e.applyCamera(),P(h)},z=d=>{if(i===d.pointerId){i=null,o.style.cursor=t.drag&&!l?"grab":"";try{d.target.releasePointerCapture(d.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),v("end",h)}},O=eo(e,()=>t,()=>l,h,P,v);function Z(){o.addEventListener("pointerdown",F),o.addEventListener("pointermove",k),o.addEventListener("pointerup",z),o.addEventListener("pointercancel",z),o.addEventListener("wheel",O.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function q(){o.removeEventListener("pointerdown",F),o.removeEventListener("pointermove",k),o.removeEventListener("pointerup",z),o.removeEventListener("pointercancel",z),o.removeEventListener("wheel",O.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",O.teardown()}Z(),C.start();function D(d){let T=!!t.animate;t=Nt(t,d),!l&&i===null&&(o.style.cursor=t.drag?"grab":"");let w=!!t.animate;T&&!w?C.stop():!T&&w&&C.start()}function H(){l&&(l=!1,Z(),C.start())}function V(){l||(l=!0,q(),C.stop(),i=null,c=!1,O.teardown())}function G(){V(),x.length=0,f.length=0,b.length=0}function A(d,T){let w=y(d);w.includes(T)||w.push(T)}function g(d,T){let w=y(d),R=w.indexOf(T);R>=0&&w.splice(R,1)}function u(d,T){return y(d).includes(T)}return{update:D,resume:H,pause:V,destroy:G,addEventListener:A,removeEventListener:g,hasEventListener:u}}function oe(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function no(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Re(e){if(e!==null)return!(e==="false"||e==="0")}function oo(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 ro(e){if(e==="x"||e==="y")return e}var il=typeof HTMLElement<"u"?HTMLElement:class{},sl=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],pn=class extends il{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...sl]}getControls(){return this._controls}_readAnimate(){let t=oe(this.getAttribute("animate-speed")),o=ro(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:Re(r)}:{}}}_readOptions(){let t={},o=Re(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Re(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let i=oe(this.getAttribute("min-distance"));i!==void 0&&(t.minDistance=i);let s=oe(this.getAttribute("max-distance"));s!==void 0&&(t.maxDistance=s);let c=oo(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=oe(this.getAttribute("zoom-min")),p=oe(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),p!==void 0&&(t.maxZoom=p),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof _e)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=Di(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Oi=require("@layoutit/polycss-core");function Hi(e,n={}){let t=Nt(Jn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,i=null,s={x:0,y:0},c=!1,l=!1,p=!1,h={x:0,y:0},x=Gt(),f=$t(e),{changeListeners:b,startListeners:y,endListeners:P,listenerArray:v,emitChange:C,emitInteraction:F}=x,k=to(r,e,()=>t,()=>l,()=>c,f,C),z=_=>{if(!(!t.drag||l)&&i===null&&_.isPrimary!==!1){_.preventDefault(),i=_.pointerId,s={x:_.clientX,y:_.clientY},o.style.cursor="grabbing";try{_.target.setPointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),F("start",f)}},O=_=>{if(i===null||_.pointerId!==i||!t.drag||l)return;_.preventDefault();let j=_.clientX-s.x,Q=_.clientY-s.y;s={x:_.clientX,y:_.clientY};let ae=e.camera.state;if(_.shiftKey){let be=un(t.invert),fe=j/4*be,ge=Q/4*be,we=(ae.rotX??65)-ge,Se=(((ae.rotY??45)-fe)%360+360)%360;e.camera.update({rotX:we,rotY:Se})}else{let be=ae.rotX??65,fe=ae.rotY??45,ge=Math.max(.01,ae.zoom??1),we=Math.cos(be*Math.PI/180),Se=we>=0?Math.max(.1,we):Math.min(-.1,we),ke=Math.cos(fe*Math.PI/180),We=Math.sin(fe*Math.PI/180),et=ge*Oi.BASE_TILE,mt=(j*We-Q*ke/Se)/et,Ct=-(j*ke+Q*We/Se)/et,ft=ae.target??[0,0,0];e.camera.update({target:[ft[0]+mt,ft[1]+Ct,ft[2]]})}e.applyCamera(),C(f)},Z=_=>{if(i===_.pointerId){i=null,o.style.cursor=t.drag&&!l?"grab":"";try{_.target.releasePointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),F("end",f)}},q=_=>{_.preventDefault()},D=_=>{_.button===2&&(p=!0,h={x:_.clientX,y:_.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),F("start",f))},H=_=>{if(!p||!t.drag)return;let j=_.clientX-h.x,Q=_.clientY-h.y;h={x:_.clientX,y:_.clientY};let ae=un(t.invert),be=j/4*ae,fe=Q/4*ae,ge=e.camera.state,we=(ge.rotX??65)-fe,Se=(((ge.rotY??45)-be)%360+360)%360;e.camera.update({rotX:we,rotY:Se}),e.applyCamera(),C(f)},V=_=>{_.button===2&&p&&(p=!1,F("end",f))},G=eo(e,()=>t,()=>l,f,C,F);function A(){o.addEventListener("pointerdown",z),o.addEventListener("pointermove",O),o.addEventListener("pointerup",Z),o.addEventListener("pointercancel",Z),o.addEventListener("wheel",G.onWheel,{passive:!1}),o.addEventListener("contextmenu",q),o.addEventListener("mousedown",D),o.addEventListener("mousemove",H),o.addEventListener("mouseup",V),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function g(){o.removeEventListener("pointerdown",z),o.removeEventListener("pointermove",O),o.removeEventListener("pointerup",Z),o.removeEventListener("pointercancel",Z),o.removeEventListener("wheel",G.onWheel),o.removeEventListener("contextmenu",q),o.removeEventListener("mousedown",D),o.removeEventListener("mousemove",H),o.removeEventListener("mouseup",V),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",G.teardown()}A(),k.start();function u(_){let j=!!t.animate;t=Nt(t,_),!l&&i===null&&(o.style.cursor=t.drag?"grab":"");let Q=!!t.animate;j&&!Q?k.stop():!j&&Q&&k.start()}function d(){l&&(l=!1,A(),k.start())}function T(){l||(l=!0,g(),k.stop(),i=null,c=!1,p=!1,G.teardown())}function w(){T(),b.length=0,y.length=0,P.length=0}function R(_,j){let Q=v(_);Q.includes(j)||Q.push(j)}function L(_,j){let Q=v(_),ae=Q.indexOf(j);ae>=0&&Q.splice(ae,1)}function re(_,j){return v(_).includes(j)}return{update:u,resume:d,pause:T,destroy:w,addEventListener:R,removeEventListener:L,hasEventListener:re}}var al=typeof HTMLElement<"u"?HTMLElement:class{},ll=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],mn=class extends al{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...ll]}_readAnimate(){let t=oe(this.getAttribute("animate-speed")),o=ro(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:Re(r)}:{}}}_readOptions(){let t={},o=Re(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Re(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let i=oe(this.getAttribute("min-distance"));i!==void 0&&(t.minDistance=i);let s=oe(this.getAttribute("max-distance"));s!==void 0&&(t.maxDistance=s);let c=oo(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=oe(this.getAttribute("zoom-min")),p=oe(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),p!==void 0&&(t.maxZoom=p),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof _e)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=Hi(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Gi=require("@layoutit/polycss-core");var cl={enabled:!0,lookEnabled:!0,moveEnabled:!0,jumpEnabled:!0,crouchEnabled:!0,lookSensitivity:.15,invertY:!1,moveSpeed:5,jumpVelocity:7,gravity:18,eyeHeight:1.7,crouchHeight:1,groundZ:0,minPitch:5,maxPitch:175};function Ii(e,n){return{enabled:n.enabled??e.enabled,lookEnabled:n.lookEnabled??e.lookEnabled,moveEnabled:n.moveEnabled??e.moveEnabled,jumpEnabled:n.jumpEnabled??e.jumpEnabled,crouchEnabled:n.crouchEnabled??e.crouchEnabled,lookSensitivity:n.lookSensitivity??e.lookSensitivity,invertY:n.invertY??e.invertY,moveSpeed:n.moveSpeed??e.moveSpeed,jumpVelocity:n.jumpVelocity??e.jumpVelocity,gravity:n.gravity??e.gravity,eyeHeight:n.eyeHeight??e.eyeHeight,crouchHeight:n.crouchHeight??e.crouchHeight,groundZ:n.groundZ??e.groundZ,minPitch:n.minPitch??e.minPitch,maxPitch:n.maxPitch??e.maxPitch}}var Fi=new Set(["KeyW","ArrowUp"]),Vi=new Set(["KeyS","ArrowDown"]),Bi=new Set(["KeyA","ArrowLeft"]),zi=new Set(["KeyD","ArrowRight"]),Ni=new Set(["Space"]),Ko=new Set(["ControlLeft","ControlRight"]);function $i(e,n={}){let t=Ii(cl,n),o=e.host,r=e.cameraEl,i=o.ownerDocument??document,s=i.defaultView??globalThis,c=Gt(),l=$t(e),{changeListeners:p,startListeners:h,endListeners:x,listenerArray:f,emitChange:b,emitInteraction:y}=c,P=new Set,v=!1,C=!1,F=0,k=0,z=!1,O=[0,0,t.groundZ+t.eyeHeight];function Z($,le){let ce=$*Math.PI/180,De=le*Math.PI/180;return[-Math.sin(ce)*Math.cos(De),-Math.sin(ce)*Math.sin(De),-Math.cos(ce)]}function q(){let $=e.camera.perspectiveStyle,le=$==="none"?0:parseFloat($);return(Number.isFinite(le)&&le>0?le:2e3)/Gi.BASE_TILE}function D(){let $=e.camera.state,le=Z($.rotX??90,$.rotY??0),ce=q();return[O[0]+le[0]*ce,O[1]+le[1]*ce,O[2]+le[2]*ce]}function H(){let $=D();e.camera.update({target:$}),e.applyCamera()}function V(){let $=e.camera.state.target??[0,0,0];O=[$[0],$[1],t.groundZ+t.eyeHeight],H()}let G=()=>{if(!(!t.enabled||!t.lookEnabled||C||v))try{o.requestPointerLock()}catch{}},A=()=>{let $=i.pointerLockElement===o;$!==v&&(v=$,v?(z=!0,y("start",l)):z&&(z=!1,y("end",l)))},g=$=>{if(!v||!t.enabled||!t.lookEnabled||C)return;let le=$.movementX??0,ce=$.movementY??0;if(le===0&&ce===0)return;let De=e.camera.state,Wt=t.lookSensitivity,Ye=t.invertY?-1:1,Le=(((De.rotY??0)-le*Wt)%360+360)%360,Ce=(De.rotX??90)-ce*Wt*Ye;Ce<t.minPitch?Ce=t.minPitch:Ce>t.maxPitch&&(Ce=t.maxPitch);let Be=Z(Ce,Le),ze=q(),Me=[O[0]+Be[0]*ze,O[1]+Be[1]*ze,O[2]+Be[2]*ze];e.camera.update({rotX:Ce,rotY:Le,target:Me}),e.applyCamera(),b(l)},u=$=>Fi.has($)||Vi.has($)||Bi.has($)||zi.has($)||Ni.has($)||Ko.has($),d=$=>{if(!(!t.enabled||C)&&u($.code)&&!(!v&&!t.moveEnabled)){if(Ni.has($.code)){if(!t.jumpEnabled)return;$.preventDefault(),!P.has($.code)&&F===0&&k===0&&(F=t.jumpVelocity),P.add($.code);return}Ko.has($.code)&&!t.crouchEnabled||!t.moveEnabled&&!Ko.has($.code)||($.preventDefault(),P.add($.code))}},T=$=>{u($.code)&&P.delete($.code)},w=()=>{P.clear()},R=null,L=0,re=.05,_=$=>{if(R===null||C)return;let le=Math.min(re,L?($-L)/1e3:.0167);if(L=$,t.enabled){let ce=!1,De=e.camera.state;if(t.moveEnabled){let Ce=0,Be=0;for(let ze of P)Fi.has(ze)?Ce+=1:Vi.has(ze)?Ce-=1:zi.has(ze)?Be+=1:Bi.has(ze)&&(Be-=1);if(Ce!==0||Be!==0){let Me=(De.rotY??0)*Math.PI/180,Yt=-Math.cos(Me),fo=-Math.sin(Me),ho=-Math.sin(Me),go=Math.cos(Me),tt=Math.hypot(Ce,Be)||1,_n=t.moveSpeed*le;O[0]+=(Yt*Ce+ho*Be)/tt*_n,O[1]+=(fo*Ce+go*Be)/tt*_n,ce=!0}}let Ye=t.crouchEnabled&&(P.has("ControlLeft")||P.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(F!==0||k>0)?(F-=t.gravity*le,k+=F*le,k<=0&&(k=0,F=0)):t.jumpEnabled||(k=0,F=0);let Le=t.groundZ+Ye+k;if(Math.abs(O[2]-Le)>1e-4&&(O[2]=Le,ce=!0),ce){let Ce=D();e.camera.update({target:Ce}),e.applyCamera(),b(l)}}R=s.requestAnimationFrame(_)};function j(){R!==null||C||(L=0,R=s.requestAnimationFrame(_))}function Q(){R!==null&&(s.cancelAnimationFrame(R),R=null)}function ae(){let le=r.ownerDocument?.defaultView?.getComputedStyle(r).perspective??"",ce=parseFloat(le),De=Number.isFinite(ce)&&ce>0?ce:2e3;r.style.setProperty("--polycss-fpv-perspective",`${De}px`),r.classList.add("polycss-fpv-host")}function be(){r.classList.remove("polycss-fpv-host"),r.style.removeProperty("--polycss-fpv-perspective")}function fe(){o.addEventListener("click",G),i.addEventListener("pointerlockchange",A),i.addEventListener("mousemove",g),s.addEventListener("keydown",d),s.addEventListener("keyup",T),s.addEventListener("blur",w),o.style.cursor=t.lookEnabled?"crosshair":"",ae()}function ge(){if(o.removeEventListener("click",G),i.removeEventListener("pointerlockchange",A),i.removeEventListener("mousemove",g),s.removeEventListener("keydown",d),s.removeEventListener("keyup",T),s.removeEventListener("blur",w),o.style.cursor="",P.clear(),v)try{i.exitPointerLock()}catch{}be()}V(),fe(),j();function we($){let le=t.eyeHeight,ce=t.groundZ;t=Ii(t,$),C||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==le||t.groundZ!==ce)&&(O[2]=t.groundZ+t.eyeHeight,H(),b(l))}function Se(){C&&(C=!1,fe(),j())}function ke(){C||(C=!0,ge(),Q(),z&&(z=!1,y("end",l)))}function We(){ke(),p.length=0,h.length=0,x.length=0}function et(){if(!(!t.enabled||!t.lookEnabled||C))try{o.requestPointerLock()}catch{}}function mt(){if(v)try{i.exitPointerLock()}catch{}}function Ct(){return v}function ft($,le){let ce=f($);ce.includes(le)||ce.push(le)}function co($,le){let ce=f($),De=ce.indexOf(le);De>=0&&ce.splice(De,1)}function uo($,le){return f($).includes(le)}function po(){return[O[0],O[1],O[2]]}function mo($){O[0]=$[0],O[1]=$[1],O[2]=$[2],H(),b(l)}return{update:we,resume:Se,pause:ke,destroy:We,lock:et,unlock:mt,isLocked:Ct,getOrigin:po,setOrigin:mo,addEventListener:ft,removeEventListener:co,hasEventListener:uo}}var dl=typeof HTMLElement<"u"?HTMLElement:class{},ul=["enabled","look-enabled","move-enabled","jump-enabled","crouch-enabled","look-sensitivity","invert-y","move-speed","jump-velocity","gravity","eye-height","crouch-height","ground-z","min-pitch","max-pitch"],fn=class extends dl{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...ul]}_readOptions(){let t={},o=Re(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let r=Re(this.getAttribute("look-enabled"));r!==void 0&&(t.lookEnabled=r);let i=Re(this.getAttribute("move-enabled"));i!==void 0&&(t.moveEnabled=i);let s=Re(this.getAttribute("jump-enabled"));s!==void 0&&(t.jumpEnabled=s);let c=Re(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let l=oe(this.getAttribute("look-sensitivity"));if(l!==void 0&&(t.lookSensitivity=l),this.hasAttribute("invert-y")){let C=Re(this.getAttribute("invert-y"));C!==void 0&&(t.invertY=C)}let p=oe(this.getAttribute("move-speed"));p!==void 0&&(t.moveSpeed=p);let h=oe(this.getAttribute("jump-velocity"));h!==void 0&&(t.jumpVelocity=h);let x=oe(this.getAttribute("gravity"));x!==void 0&&(t.gravity=x);let f=oe(this.getAttribute("eye-height"));f!==void 0&&(t.eyeHeight=f);let b=oe(this.getAttribute("crouch-height"));b!==void 0&&(t.crouchHeight=b);let y=oe(this.getAttribute("ground-z"));y!==void 0&&(t.groundZ=y);let P=oe(this.getAttribute("min-pitch"));P!==void 0&&(t.minPitch=P);let v=oe(this.getAttribute("max-pitch"));return v!==void 0&&(t.maxPitch=v),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof _e)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=$i(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var pl=typeof HTMLElement<"u"?HTMLElement:class{},ml=["perspective","zoom","rot-x","rot-y","target","distance"],hn=class extends pl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...ml]}getCamera(){return this._camera}_readOptions(){return{perspective:oe(this.getAttribute("perspective")),zoom:oe(this.getAttribute("zoom")),rotX:oe(this.getAttribute("rot-x")),rotY:oe(this.getAttribute("rot-y")),target:no(this.getAttribute("target")),distance:oe(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=qn(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let i=this._readOptions();if(t==="perspective"){let l=i.perspective!==void 0?`${i.perspective}px`:"32000px";this._wrapper.style.perspective=l;return}this._camera.update({rotX:i.rotX,rotY:i.rotY,zoom:i.zoom,target:i.target,distance:i.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var fl=typeof HTMLElement<"u"?HTMLElement:class{},hl=["zoom","rot-x","rot-y","target","distance"],Pt=class extends fl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...hl]}getCamera(){return this._camera}_readOptions(){return{zoom:oe(this.getAttribute("zoom")),rotX:oe(this.getAttribute("rot-x")),rotY:oe(this.getAttribute("rot-y")),target:no(this.getAttribute("target")),distance:oe(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=rn(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let i=this._readOptions();i.zoom!==void 0&&this._camera.update({zoom:i.zoom}),i.rotX!==void 0&&this._camera.update({rotX:i.rotX}),i.rotY!==void 0&&this._camera.update({rotY:i.rotY}),i.target!==void 0&&this._camera.update({target:i.target}),i.distance!==void 0&&this._camera.update({distance:i.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var gn=class extends Pt{};var Ae=require("@layoutit/polycss-core");function Ut(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let i=r.getBoundingClientRect();if(!(i.width<=0||i.height<=0)&&n>=i.left&&n<=i.right&&t>=i.top&&t<=i.bottom)return!0}return!1}function Ui(e,n,t,o){for(let r of e)if(!(o&&!o(r))&&Ut(r.element,n,t))return r;return null}var io="#ff3653",so="#8adb00",ao="#2c8fff",jt=50,ji=60,gl=.6,yl=.0125,bl=.15,vl=.04,xl=1,Wi=.02,Jo=1.04,Pl=.1,Sl=.25,Qi=1e-4,Cl=.6,El=.8,Tl=1,lt={0:1,1:0,2:2},Yi=[{cssAxis:0,sign:1,key:"x",color:io},{cssAxis:0,sign:-1,key:"-x",color:io},{cssAxis:1,sign:1,key:"y",color:so},{cssAxis:1,sign:-1,key:"-y",color:so},{cssAxis:2,sign:1,key:"z",color:ao},{cssAxis:2,sign:-1,key:"-z",color:ao}],Xi=[{cssAxis:0,key:"x",color:io},{cssAxis:1,key:"y",color:so},{cssAxis:2,key:"z",color:ao}],Zi=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:ao},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:so},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:io}];function er(e,n,t,o){let r=t*Math.PI/180,i=o*Math.PI/180,s=[0,0,0];s[e]=n;let c=s[0]*Math.cos(i)-s[1]*Math.sin(i),l=s[0]*Math.sin(i)+s[1]*Math.cos(i),p=s[2];return l*Math.sin(r)+p*Math.cos(r)<0}function Al(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),i=parseInt(t[3],16);return`rgba(${o}, ${r}, ${i}, ${n})`}function lo(e,n){return!n||n<=0?e:Math.round(e/n)*n}function Ml(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let c of e)for(let l of c.vertices)l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>i&&(i=l[1]),l[2]<o&&(o=l[2]),l[2]>s&&(s=l[2]);return Number.isFinite(n)?[(n+r)/2,(t+i)/2,(o+s)/2]:[0,0,0]}function tr(e){if(e.length===0)return ji;let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let l of e)for(let p of l.vertices)p[0]<n&&(n=p[0]),p[0]>r&&(r=p[0]),p[1]<t&&(t=p[1]),p[1]>i&&(i=p[1]),p[2]<o&&(o=p[2]),p[2]>s&&(s=p[2]);return Number.isFinite(n)?Math.max(r-n,i-t,s-o)*jt*gl:ji}function wl(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:i,startClientX:s,startClientY:c,translationSnap:l,onAxisDelta:p,onMouseDown:h,onMouseUp:x,onDraggingChanged:f}=e,b=o,y=[0,0,0];y[n]=t;let P=r.ownerDocument.createElement("div");P.style.position="absolute",P.style.left="0",P.style.top="0",P.style.width="0",P.style.height="0",P.style.transform=`translate3d(${y[0]*b}px, ${y[1]*b}px, ${y[2]*b}px)`,r.appendChild(P);let v=r.getBoundingClientRect(),C=P.getBoundingClientRect();r.removeChild(P);let F=(C.left-v.left)/b,k=(C.top-v.top)/b,z=F*F+k*k;if(z<Qi)return;h?.(),f?.(!0);let O=q=>{let D=q.clientX-s,H=q.clientY-c,V=(D*F+H*k)/z;V=lo(V,l),p(V,y)},Z=()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",Z),window.removeEventListener("pointercancel",Z);let q=D=>{D.stopPropagation(),D.stopImmediatePropagation()};window.addEventListener("click",q,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",q,!0),0),x?.(),f?.(!1)};window.addEventListener("pointermove",O),window.addEventListener("pointerup",Z),window.addEventListener("pointercancel",Z)}function Ll(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:i,startClientY:s,translationSnap:c,onPlaneDelta:l,onMouseDown:p,onMouseUp:h,onDraggingChanged:x}=e,f=[0,0,0];f[n]=1;let b=[0,0,0];b[t]=1;function y(z){let O=r.ownerDocument.createElement("div");O.style.position="absolute",O.style.left="0",O.style.top="0",O.style.width="0",O.style.height="0",O.style.transform=`translate3d(${z[0]*o}px, ${z[1]*o}px, ${z[2]*o}px)`,r.appendChild(O);let Z=r.getBoundingClientRect(),q=O.getBoundingClientRect();return r.removeChild(O),{x:(q.left-Z.left)/o,y:(q.top-Z.top)/o}}let P=y(f),v=y(b),C=P.x*v.y-v.x*P.y;if(Math.abs(C)<Qi)return;p?.(),x?.(!0);let F=z=>{let O=z.clientX-i,Z=z.clientY-s,q=(v.y*O-v.x*Z)/C,D=(-P.y*O+P.x*Z)/C;q=lo(q,c),D=lo(D,c),l(q,D,f,b)},k=()=>{window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k);let z=O=>{O.stopPropagation(),O.stopImmediatePropagation()};window.addEventListener("click",z,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",z,!0),0),h?.(),x?.(!1)};window.addEventListener("pointermove",F),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)}function _l(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:i,rotationSnap:s,onAngleDelta:c,onMouseDown:l,onMouseUp:p,onDraggingChanged:h}=e,x=t.getBoundingClientRect(),f=x.left,b=x.top,y=Math.atan2(i-b,r-f),P=0;l?.(),h?.(!0);let v=F=>{let k=Math.atan2(F.clientY-b,F.clientX-f),z=k-y;z>Math.PI?z-=2*Math.PI:z<-Math.PI&&(z+=2*Math.PI),P+=z,y=k;let O=P*180/Math.PI;O=lo(O,s),c(O)},C=()=>{window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",C),window.removeEventListener("pointercancel",C);let F=k=>{k.stopPropagation(),k.stopImmediatePropagation()};window.addEventListener("click",F,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",F,!0),0),p?.(),h?.(!1)};window.addEventListener("pointermove",v),window.addEventListener("pointerup",C),window.addEventListener("pointercancel",C)}function qi(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,i={...n},s=new Map,c=null,l=null,p=[0,0,0];function h(){if(!t)return[0,0,0];let g=t.transform.position??[0,0,0],u=t.transform.rotation??[0,0,0],d=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,T=(0,Ae.rotateVec3)(p,u[0],u[1],u[2]);return[g[0]+d*T[0],g[1]+d*T[1],g[2]+d*T[2]]}function x(g){return l===g?Tl:c===g?El:Cl}function f(){for(let[g,u]of s){let d=b(u.spec,x(g));u.handle.setPolygons(d,{recomputeAutoCenter:!1})}}function b(g,u){let T=tr(t?.polygons??[])*r,w=T/jt,R=Al(g.color,u);if(g.kind==="arrow"){let _=e.camera.state,j=er(g.cssAxis,g.sign,_.rotX??65,_.rotY??45);return(0,Ae.arrowPolygons)({axis:lt[g.cssAxis],sign:g.sign,shaftLength:w,shaftHalfThickness:w*yl,headLength:w*bl,headHalfThickness:w*vl,color:R,shaft:!j})}if(g.kind==="plane"){let _=e.camera.state,j=_.rotX??65,Q=_.rotY??45,ae=lt[g.perpAxis],be=(ae+1)%3,fe=(ae+2)%3,ge=lt[be],we=lt[fe],Se=er(ge,1,j,Q)?-1:1,ke=er(we,1,j,Q)?-1:1,We=w*Sl;return(0,Ae.planePolygons)({axis:ae,size:w*Pl,offset:[Se*We,ke*We],color:R})}let re=T*xl/jt*Jo;return(0,Ae.ringQuadPolygons)({axis:lt[g.cssAxis],outerRadius:re,color:R})}function y(g){return g.kind==="arrow"?"polycss-transform-arrow":g.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function P(){if(o==="translate"){let g=Yi.map(d=>({kind:"arrow",key:d.key,cssAxis:d.cssAxis,sign:d.sign,color:d.color})),u=Zi.map(d=>({kind:"plane",key:d.key,perpAxis:d.perpAxis,axisA:d.axisA,axisB:d.axisB,color:d.color}));return[...g,...u]}return o==="rotate"?Xi.map(g=>({kind:"ring",key:g.key,cssAxis:g.cssAxis,color:g.color})):[]}function v(){if(C(),!t)return;let g={x:i.showX!==!1,y:i.showY!==!1,z:i.showZ!==!1};function u(T){if(T.kind==="arrow"){let L=T.key.replace("-","")[0];return g[L]}if(T.kind==="ring")return g[T.key];let w=["x","y","z"][T.axisA],R=["x","y","z"][T.axisB];return g[w]&&g[R]}let d=h();for(let T of P()){if(!u(T))continue;let w=b(T,x(T.key)),R=e.add({polygons:w,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${T.key}`,position:d}),L=y(T);if(R.element.classList.add("polycss-transform-gizmo",L,`${L}--${T.key}`),T.kind==="ring"){let re=(1-Wi)/Jo,_=(1+Wi)/Jo;R.element.style.setProperty("--ring-inner-ratio",`${re}`),R.element.style.setProperty("--ring-outer-ratio",`${_}`)}s.set(T.key,{handle:R,spec:T})}}function C(){for(let{handle:g}of s.values())g.remove();s.clear(),c=null,l=null}function F(){if(!t)return;let g=h();for(let{handle:u}of s.values())u.setTransform({position:g})}function k(){t&&(s.size===0?v():F())}function z(g){if(t=g,!g){p=[0,0,0],C();return}p=Ml(g.polygons),C(),v()}function O(){z(null)}function Z(g){g!==o&&(o=g,t&&(C(),v()))}function q(g,u,d){if(!t||!D)return;let T=d[g.cssAxis],w=lt[g.cssAxis],R=u*T/jt,L=D.slice();L[w]=D[w]+R,t.setTransform({position:L}),F(),i.onObjectChange?.({object:t,position:L}),i.onChange?.()}let D=null,H=null,V=g=>{if(!t||i.enabled===!1)return;let u={x:i.showX!==!1,y:i.showY!==!1,z:i.showZ!==!1};if(o==="translate"){for(let d of Zi){let T=["x","y","z"][d.axisA],w=["x","y","z"][d.axisB];if(!u[T]||!u[w])continue;let R=s.get(d.key);if(R&&Ut(R.handle.element,g.clientX,g.clientY)){g.preventDefault(),g.stopPropagation(),l=d.key,f(),D=(t.transform.position??[0,0,0]).slice(),Ll({axisA:d.axisA,axisB:d.axisB,probeDistanceCss:tr(t.polygons)*r,wrapper:R.handle.element,target:t,startClientX:g.clientX,startClientY:g.clientY,translationSnap:i.translationSnap??null,onPlaneDelta:(L,re,_,j)=>{if(!t||!D)return;let Q=_[d.axisA],ae=j[d.axisB],be=lt[d.axisA],fe=lt[d.axisB],ge=D.slice();ge[be]+=L*Q/jt,ge[fe]+=re*ae/jt,t.setTransform({position:ge}),F(),i.onObjectChange?.({object:t,position:ge}),i.onChange?.()},onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:L=>{L||(l=null,D=null,f()),i.onDraggingChanged?.(L)}});return}}for(let d of Yi){let T=d.key.replace("-","")[0];if(!u[T])continue;let w=s.get(d.key);if(w&&Ut(w.handle.element,g.clientX,g.clientY)){g.preventDefault(),g.stopPropagation(),l=d.key,f(),D=(t.transform.position??[0,0,0]).slice(),wl({cssAxis:d.cssAxis,sign:d.sign,shaftLengthCss:tr(t.polygons)*r,wrapper:w.handle.element,target:t,startClientX:g.clientX,startClientY:g.clientY,translationSnap:i.translationSnap??null,onAxisDelta:(R,L)=>q(d,R,L),onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:R=>{R||(l=null,D=null,f()),i.onDraggingChanged?.(R)}});return}}}else if(o==="rotate")for(let d of Xi){if(!u[d.key])continue;let T=s.get(d.key);if(T&&Ut(T.handle.element,g.clientX,g.clientY)){g.preventDefault(),g.stopPropagation(),l=d.key,f(),H=(t.transform.rotation??[0,0,0]).slice(),D=(t.transform.position??[0,0,0]).slice(),_l({cssAxis:d.cssAxis,wrapper:T.handle.element,target:t,startClientX:g.clientX,startClientY:g.clientY,rotationSnap:i.rotationSnap??null,onAngleDelta:w=>{if(!t||!H||!D)return;let R=lt[d.cssAxis],L=[0,0,0];L[R]=1;let re=-w*Math.PI/180,_=(0,Ae.quatFromEulerXYZ)(H),j=(0,Ae.quatFromAxisAngle)(L,re),Q=(0,Ae.eulerXYZFromQuat)((0,Ae.quatMultiply)(j,_)),ae=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,be=(0,Ae.rotateVec3)(p,H[0],H[1],H[2]),fe=(0,Ae.rotateVec3)(p,Q[0],Q[1],Q[2]),ge=[D[0]+ae*(be[0]-fe[0]),D[1]+ae*(be[1]-fe[1]),D[2]+ae*(be[2]-fe[2])];t.setTransform({rotation:Q,position:ge}),F(),i.onObjectChange?.({object:t,rotation:Q,position:ge}),i.onChange?.()},onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:w=>{w||(l=null,H=null,D=null,f(),t?.rebakeAtlas()),i.onDraggingChanged?.(w)}});return}}};e.host.addEventListener("pointerdown",V,{capture:!0});let G=g=>{if(!t||l||i.enabled===!1)return;let u=null;for(let[d,T]of s)if(Ut(T.handle.element,g.clientX,g.clientY)){u=d;break}u!==c&&(c=u,f())};e.host.addEventListener("pointermove",G);function A(){e.host.removeEventListener("pointerdown",V,{capture:!0}),e.host.removeEventListener("pointermove",G),C()}return{attach:z,detach:O,setMode:Z,update:k,destroy:A}}var Rl=typeof HTMLElement<"u"?HTMLElement:class{},kl=["mode","target","size","enabled"];function Ki(e){if(e==="translate"||e==="rotate")return e}var yn=class extends Rl{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...kl]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof _e)return t;t=t.parentNode}return null}_findTargetMesh(){let t=this.getAttribute("target");if(!t)return null;let o=this._findScene();if(!o)return null;let r=null;try{r=o.querySelector(`#${t}`)??o.querySelector(t)}catch{r=o.querySelector(`[id="${t}"]`)}return r instanceof xt?r:null}_readOptions(){let t={},o=Ki(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=oe(this.getAttribute("size"));r!==void 0&&(t.size=r);let i=this.getAttribute("enabled");return i!==null&&(t.enabled=i!=="false"&&i!=="0"),t.onObjectChange=s=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:s.position,rotation:s.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let i=()=>{t.removeEventListener("polycss:scene-ready",i),this._attach()};t.addEventListener("polycss:scene-ready",i)}return}this._tc=qi(o,this._readOptions());let r=this._findTargetMesh();if(r){let i=r.getMeshHandle();i&&this._tc.attach(i)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,r){if(o!==r&&this._tc){if(t==="mode"){let i=Ki(r);i&&this._tc.setMode(i)}else if(t==="target"){let i=this._findTargetMesh();this._tc.attach(i?i.getMeshHandle()??null:null)}}}};function Ji(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let P of o)try{P(t)}catch(v){console.error("[polycss/createSelect] onChange threw:",v)}}function i(y){t=y,r()}function s(y){n.multiple?t.includes(y)||(t=[...t,y]):t=[y],r()}function c(y){t.includes(y)&&(t=t.filter(P=>P!==y),r())}function l(y){t.includes(y)?t=t.filter(P=>P!==y):n.multiple?t=[...t,y]:t=[y],r()}function p(){t.length!==0&&(t=[],r())}function h(y){return t.includes(y)}function x(y,P){return Ui(e.meshes(),y,P,v=>!v.element.classList.contains("polycss-transform-gizmo"))}let f=y=>{let P=y.target;if(P?.closest(".polycss-transform-gizmo"))return;let v=e.findMeshByElement(P)??x(y.clientX,y.clientY);if(!v){n.onPointerMissed&&n.onPointerMissed(y),n.clearOnMiss!==!1&&p();return}n.multiple&&(y.shiftKey||y.metaKey||y.ctrlKey)?l(v):t.length===1&&t[0]===v?p():i([v])};e.host.addEventListener("click",f);function b(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:i,add:s,remove:c,toggle:l,clear:p,has:h,destroy:b}}var Dl=typeof HTMLElement<"u"?HTMLElement:class{},Ol=["multiple","clear-on-miss"],bn=class extends Dl{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Ol]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof _e)return t;t=t.parentNode}return null}_readOptions(){return{multiple:this.hasAttribute("multiple"),clearOnMiss:!this.hasAttribute("clear-on-miss")||this.getAttribute("clear-on-miss")!=="false",onChange:t=>{this.dispatchEvent(new CustomEvent("polycss:select",{bubbles:!0,detail:{selected:t}}))}}}_attach(){if(this._selection)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._selection=Ji(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};var he=require("@layoutit/polycss-core"),Hl=typeof HTMLElement<"u"?HTMLElement:class{};function Il(e){return e.closest("poly-scene")??null}function ve(e,n,t){let o=e.getAttribute(n);if(!o)return t;let r=parseFloat(o);return Number.isFinite(r)?r:t}function Je(e,n,t){return e.getAttribute(n)??t}function St(e,n){let t=e.getAttribute(n);if(!t)return;let o=t.split(",").map(r=>parseFloat(r.trim()));if(!(o.length!==3||o.some(r=>!Number.isFinite(r))))return[o[0],o[1],o[2]]}function Fl(e){if(e.length===0)return e;let n=(0,he.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let i=s=>[s[0]-t,s[1]-o,s[2]-r];return e.map(s=>({...s,vertices:s.vertices.map(i)}))}var Ve=class extends Hl{constructor(){super(...arguments);this._handle=null}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="position"||t==="scale"||t==="rotation"||t==="cast-shadow"||t==="receive-shadow"){this._handle.setTransform({position:St(this,"position"),scale:(()=>{let i=this.getAttribute("scale");if(!i)return;if(i.includes(","))return St(this,"scale");let s=parseFloat(i);return Number.isFinite(s)?s:void 0})(),rotation:St(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")});return}this._tearDown(),this._mount()}}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=Il(this);if(!t)return;let o=t.getScene?.();if(!o)return;let r=this.buildPolygons();this.hasAttribute("auto-center")&&(r=Fl(r));let i={polygons:r,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(i,{position:St(this,"position"),scale:(()=>{let s=this.getAttribute("scale");if(!s)return;if(s.includes(","))return St(this,"scale");let c=parseFloat(s);return Number.isFinite(c)?c:void 0})(),rotation:St(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow"),excludeFromAutoCenter:this.hasAttribute("exclude-from-auto-center"),merge:!1})}},vn=class extends Ve{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("size"),t=n?parseFloat(n):void 0;return(0,he.boxPolygons)({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:Je(this,"color")})}},xn=class extends Ve{static get observedAttributes(){return["axis","size","offset","color","auto-center","position","scale","rotation","cast-shadow","receive-shadow"]}buildPolygons(){let n=ve(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("offset"),r=o===null?0:parseFloat(o);return(0,he.planePolygons)({axis:t,size:ve(this,"size",.4),offset:Number.isFinite(r)?r:0,color:Je(this,"color")})}},Pn=class extends Ve{static get observedAttributes(){return["axis","radius","segments","half-thickness","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=ve(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("half-thickness");return(0,he.ringPolygons)({axis:t,radius:ve(this,"radius",50),segments:ve(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:Je(this,"color")})}},Sn=class extends Ve{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.octahedronPolygons)({center:St(this,"center")??[0,0,0],size:ve(this,"size",50),color:Je(this,"color")})}},Cn=class extends Ve{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.tetrahedronPolygons)({size:ve(this,"size",100),color:Je(this,"color")})}},En=class extends Ve{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.icosahedronPolygons)({size:ve(this,"size",100),color:Je(this,"color")})}},Tn=class extends Ve{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.dodecahedronPolygons)({size:ve(this,"size",100),color:Je(this,"color")})}},An=class extends Ve{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.spherePolygons)({radius:ve(this,"radius",50),subdivisions:ve(this,"subdivisions",1),color:Je(this,"color")})}},Mn=class extends Ve{static get observedAttributes(){return["radius","radius-top","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("radius-top");return(0,he.cylinderPolygons)({radius:ve(this,"radius",50),radiusTop:n?parseFloat(n):void 0,height:ve(this,"height",100),radialSegments:ve(this,"radial-segments",12),color:Je(this,"color")})}},wn=class extends Ve{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.conePolygons)({radius:ve(this,"radius",50),height:ve(this,"height",100),radialSegments:ve(this,"radial-segments",12),color:Je(this,"color")})}},Ln=class extends Ve{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,he.torusPolygons)({radius:ve(this,"radius",50),tube:ve(this,"tube",15),radialSegments:ve(this,"radial-segments",12),tubularSegments:ve(this,"tubular-segments",16),color:Je(this,"color")})}};typeof customElements<"u"&&(customElements.get("poly-scene")||customElements.define("poly-scene",_e),customElements.get("poly-mesh")||customElements.define("poly-mesh",xt),customElements.get("poly-iframe")||customElements.define("poly-iframe",an),customElements.get("poly-polygon")||customElements.define("poly-polygon",ln),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",cn),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",dn),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",pn),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",mn),customElements.get("poly-first-person-controls")||customElements.define("poly-first-person-controls",fn),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",hn),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",Pt),customElements.get("poly-camera")||customElements.define("poly-camera",gn),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",yn),customElements.get("poly-select")||customElements.define("poly-select",bn),customElements.get("poly-box")||customElements.define("poly-box",vn),customElements.get("poly-plane")||customElements.define("poly-plane",xn),customElements.get("poly-ring")||customElements.define("poly-ring",Pn),customElements.get("poly-octahedron")||customElements.define("poly-octahedron",Sn),customElements.get("poly-tetrahedron")||customElements.define("poly-tetrahedron",Cn),customElements.get("poly-sphere")||customElements.define("poly-sphere",An),customElements.get("poly-icosahedron")||customElements.define("poly-icosahedron",En),customElements.get("poly-dodecahedron")||customElements.define("poly-dodecahedron",Tn),customElements.get("poly-cylinder")||customElements.define("poly-cylinder",Mn),customElements.get("poly-cone")||customElements.define("poly-cone",wn),customElements.get("poly-torus")||customElements.define("poly-torus",Ln));0&&(module.exports={PolyAxesHelperElement,PolyBoxElement,PolyCameraElement,PolyConeElement,PolyCylinderElement,PolyDirectionalLightHelperElement,PolyDodecahedronElement,PolyFirstPersonControlsElement,PolyIcosahedronElement,PolyIframeElement,PolyMapControlsElement,PolyMeshElement,PolyOctahedronElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPlaneElement,PolyPolygonElement,PolyRingElement,PolySceneElement,PolySelectElement,PolySphereElement,PolyTetrahedronElement,PolyTorusElement,PolyTransformControlsElement});