@layoutit/polycss 0.2.6 → 0.2.7

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 Eo=Object.defineProperty;var gs=Object.getOwnPropertyDescriptor;var hs=Object.getOwnPropertyNames;var ys=Object.prototype.hasOwnProperty;var bs=(e,n)=>{for(var t in n)Eo(e,t,{get:n[t],enumerable:!0})},xs=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of hs(n))!ys.call(e,i)&&i!==t&&Eo(e,i,{get:()=>n[i],enumerable:!(o=gs(n,i))||o.enumerable});return e};var vs=e=>xs(Eo({},"__esModule",{value:!0}),e);var Zl={};bs(Zl,{PolyAxesHelperElement:()=>gn,PolyBoxElement:()=>Tn,PolyCameraElement:()=>Sn,PolyConeElement:()=>On,PolyCylinderElement:()=>Dn,PolyDirectionalLightHelperElement:()=>hn,PolyDodecahedronElement:()=>Rn,PolyFirstPersonControlsElement:()=>vn,PolyIcosahedronElement:()=>_n,PolyIframeElement:()=>mn,PolyMapControlsElement:()=>xn,PolyMeshElement:()=>St,PolyOctahedronElement:()=>Mn,PolyOrbitControlsElement:()=>bn,PolyOrthographicCameraElement:()=>Ct,PolyPerspectiveCameraElement:()=>Pn,PolyPlaneElement:()=>An,PolyPolygonElement:()=>fn,PolyRingElement:()=>wn,PolySceneElement:()=>ke,PolySelectElement:()=>En,PolySphereElement:()=>kn,PolyTetrahedronElement:()=>Ln,PolyTorusElement:()=>In,PolyTransformControlsElement:()=>Cn});module.exports=vs(Zl);var te=require("@layoutit/polycss-core");var ur=require("@layoutit/polycss-core");function Ps(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,o){return(0,ur.packTextureAtlasPlansWithScaleCore)(e,n,Ps(t),o)}var Vt=require("@layoutit/polycss-core");var rt=require("@layoutit/polycss-core"),hr=require("@layoutit/polycss-core"),yr=require("@layoutit/polycss-core"),Lt=new Map;function Ss(e){let n=Lt.get(e);return n||(n=new Promise((t,o)=>{let i=new Image;i.decoding="async",i.crossOrigin="anonymous",i.onload=()=>t(i),i.onerror=()=>o(new Error(`texture load failed: ${e}`)),i.src=e}),Lt.set(e,n),n.then(()=>{Lt.get(e)===n&&Lt.delete(e)},()=>{Lt.get(e)===n&&Lt.delete(e)})),n}function ze(e,n,t=1,o=0,i=0,r=1,s=0,c=0){e.setTransform(t*n,o*n,i*n,r*n,s*n,c*n)}function To(e){let n=e/255;return n<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function Ao(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 Cs(e,n,t,o,i,r,s){let c=Math.round(n*s),l=Math.round(t*s),d=Math.max(1,Math.round(o*s)),h=Math.max(1,Math.round(i*s)),v=e.getImageData(c,l,d,h),f=v.data,b=r.r,y=r.g,P=r.b;for(let x=0;x<f.length;x+=4)f[x+3]!==0&&(f[x]=Ao(To(f[x])*b),f[x+1]=Ao(To(f[x+1])*y),f[x+2]=Ao(To(f[x+2])*P));e.putImageData(v,c,l)}function Es(e,n,t,o,i,r,s){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,d=Math.max(i/c,r/l),h=c*d,v=l*d;ze(e,s),e.drawImage(n,t+(i-h)/2,o+(r-v)/2,h,v)}function _t(e,n){return Math.max(0,Math.min(n,e))}function dr(e,n,t,o,i,r,s,c){let l=n.naturalWidth||n.width||1,d=n.naturalHeight||n.height||1,h=_t(Math.min(t.minU,t.maxU)*l,l),v=_t(Math.max(t.minU,t.maxU)*l,l),f=_t(Math.min(t.minV,t.maxV)*d,d),b=_t(Math.max(t.minV,t.maxV)*d,d),y=Math.floor(h),P=Math.floor(f),x=Math.ceil(v)-y,E=Math.ceil(b)-P;x<1&&(y=Math.floor(_t((t.minU+t.maxU)/2*l,l-1)),x=1),E<1&&(P=Math.floor(_t((t.minV+t.maxV)/2*d,d-1)),E=1),y=Math.max(0,Math.min(l-1,y)),P=Math.max(0,Math.min(d-1,P)),x=Math.max(1,Math.min(l-y,x)),E=Math.max(1,Math.min(d-P,E)),ze(e,c),e.drawImage(n,y,P,x,E,o,i,r,s)}function br(e){return e==="repeat"||e==="mirrored-repeat"}function pr(e,n){return br(e)?Math.floor(n):0}function mr(e,n){return br(e)?Math.ceil(n)-1:0}function fr(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function gr(e,n,t,o,i,r,s){let c=i?pr(r,i.minU):0,l=i?mr(r,i.maxU):0,d=i?pr(s,i.minV):0,h=i?mr(s,i.maxV):0;for(let v=c;v<=l;v++)for(let f=d;f<=h;f++){let b=fr(r,v),y=fr(s,f);if(!b&&!y){e.drawImage(n,v*t,f*o);continue}e.save(),e.translate((b?v+1:v)*t,(y?f+1:f)*o),e.scale(b?-1:1,y?-1:1),e.drawImage(n,0,0),e.restore()}}function wo(e,n,t,o){for(let i=0;i<o.length;i+=2){let r=n+o[i],s=t+o[i+1];i===0?e.moveTo(r,s):e.lineTo(r,s)}e.closePath()}function Bn(e,n,t,o,i,r){for(let s=0;s<o.length;s+=2){let c=n+o[s]+i,l=t+o[s+1]+r;s===0?e.moveTo(c,l):e.lineTo(c,l)}e.closePath()}function Ts(e,n,t,o){ze(e,o),e.beginPath(),wo(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 zn(e,n,t,o,i){n.polygon.textureAlphaMode==="opaque"&&(ze(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+i,n.canvasW,n.canvasH))}function As(e,n,t,o,i=0,r=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 d=(0,hr.expandClipPoints)(l.screenPts,rt.TEXTURE_TRIANGLE_BLEED*(n.bleedRatio??1));e.save(),ze(e,o),e.beginPath(),Bn(e,n.x,n.y,d,i,r),e.clip(),zn(e,n,o,i,r),l.uvAffine?(ze(e,o,l.uvAffine.a/s,l.uvAffine.c/s,l.uvAffine.b/c,l.uvAffine.d/c,n.x+l.uvAffine.e+i,n.y+l.uvAffine.f+r),gr(e,t,s,c,l.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t)):l.uvSampleRect&&dr(e,t,l.uvSampleRect,n.x+i,n.y+r,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(),ze(e,o),e.beginPath(),Bn(e,n.x,n.y,n.screenPts,i,r),e.clip(),zn(e,n,o,i,r)),ze(e,o,n.uvAffine.a/s,n.uvAffine.c/s,n.uvAffine.b/c,n.uvAffine.d/c,n.x+n.uvAffine.e+i,n.y+n.uvAffine.f+r),gr(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(),ze(e,o),e.beginPath(),Bn(e,n.x,n.y,n.screenPts,i,r),e.clip(),zn(e,n,o,i,r)),dr(e,t,n.uvSampleRect,n.x+i,n.y+r,n.canvasW,n.canvasH,o),s&&e.restore()}else{let s=n.polygon.textureAlphaMode==="opaque";s&&(e.save(),ze(e,o),e.beginPath(),Bn(e,n.x,n.y,n.screenPts,i,r),e.clip(),zn(e,n,o,i,r)),Es(e,t,n.x+i,n.y+r,n.canvasW,n.canvasH,o),s&&e.restore()}}function ws(e,n,t,o,i,r){let s=i-t,c=r-o,l=s*s+c*c;if(l<=yr.BASIS_EPS)return Math.hypot(e-t,n-o);let d=Math.max(0,Math.min(1,((e-t)*s+(n-o)*c)/l));return Math.hypot(e-(t+s*d),n-(o+c*d))}function Ms(e,n,t,o){let i=1/0,r=t.length/2;for(let s of o){if(s<0||s>=r)continue;let c=s*2,l=(s+1)%r*2;i=Math.min(i,ws(e,n,t[c],t[c+1],t[l],t[l+1]))}return i}function Ls(e,n,t,o,i,r){let s=Math.max(0,o-r),c=Math.min(n-1,o+r),l=Math.max(0,i-r),d=Math.min(t-1,i+r),h=null,v=1/0;for(let f=l;f<=d;f++)for(let b=s;b<=c;b++){if(b===o&&f===i)continue;let y=b-o,P=f-i,x=y*y+P*P;if(x>r*r||x>=v)continue;let E=(f*n+b)*4;e[E+3]<rt.TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN||(h=E,v=x)}return h}function _s(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let i=Math.max(0,Math.floor(n.x*t)),r=Math.max(0,Math.floor(n.y*t)),s=Math.max(1,Math.min(o.width-i,Math.ceil(n.canvasW*t))),c=Math.max(1,Math.min(o.height-r,Math.ceil(n.canvasH*t)));if(s<=0||c<=0)return;let l;try{l=e.getImageData(i,r,s,c)}catch{return}let d=l.data,h=new Uint8ClampedArray(d),v=Math.max(rt.TEXTURE_EDGE_REPAIR_RADIUS,rt.TEXTURE_EDGE_REPAIR_RADIUS/t),f=Math.max(2,Math.ceil(v*t)+1),b=!1;for(let y=0;y<c;y++)for(let P=0;P<s;P++){let x=(y*s+P)*4,E=d[x+3];if(E<rt.TEXTURE_EDGE_REPAIR_ALPHA_MIN||E===255)continue;let O=(i+P+.5)/t-n.x,R=(r+y+.5)/t-n.y;if(Ms(O,R,n.screenPts,n.textureEdgeRepairEdges)>v)continue;let j=Ls(h,s,c,P,y,f);j!==null&&(d[x]=h[j],d[x+1]=h[j+1],d[x+2]=h[j+2],d[x+3]=255,b=!0)}b&&e.putImageData(l,i,r)}function Rs(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 ks(e,n,t,o){let i=t.createElement("canvas");i.width=Math.max(1,Math.ceil(e.width*o)),i.height=Math.max(1,Math.ceil(e.height*o));let r=e.entries.some(h=>h.textureEdgeRepair&&h.texture&&h.textureEdgeRepairEdges&&h.textureEdgeRepairEdges.size>0),s=i.getContext("2d",r?{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 Ss(h))}));for(let h of e.entries){let v=h.texture?l.get(h.texture):null;if(!h.texture){s.save(),Ts(s,h,n,o),s.restore();continue}v&&(s.save(),ze(s,o),s.beginPath(),wo(s,h.x,h.y,h.screenPts),s.clip(),As(s,h,v,o),s.restore()),h.texture&&n==="baked"&&(s.save(),ze(s,o),s.beginPath(),wo(s,h.x,h.y,h.screenPts),s.clip(),Cs(s,h.x,h.y,h.canvasW,h.canvasH,h.textureTint,o),s.restore()),_s(s,h,o)}let d=await Rs(i);return i.width=1,i.height=1,{width:e.width,height:e.height,url:d}}async function Kt(e,n,t,o,i){let r=[];for(let s of e){if(i())break;r.push(await ks(s,n,t,o))}return r}var ee=require("@layoutit/polycss-core"),Vn=require("@layoutit/polycss-core"),vr=require("@layoutit/polycss-core");var xr=require("@layoutit/polycss-core");function Rt(e,n){let o=e?.defaultView?.__polycssProjectiveQuadGuards,i=n&&o?{...n,...o}:o??n;return(0,xr.resolveProjectiveQuadGuards)(i)}function Jt(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 i=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return i?i("(pointer: fine)").matches&&i("(hover: hover)").matches:!0}function Pr(e){if(Sr(e))return!0;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,ee.safariCssProjectiveUnsupported)(t):!0}function en(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 Sr(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 Ds(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function qe(e,n){return n?.disable?.includes("u")?null:Sr(e)?"corner-bevel":Pr(e)?Ds(e)?"border-large":"border":null}function tn(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,ee.safariCssProjectiveUnsupported)(t):!0}function Nn(e,n,t,o,i){let r=new Set(o?.disable??[]);return(0,ee.getSolidPaintDefaultsForPlansCore)(e,n,r,{solidTriangleSupported:Pr(t),projectiveQuadSupported:tn(t),cornerShapeSupported:en(t),borderShapeSupported:Jt(t)},Vn.parseHex,Vn.rgbKey,i)}var Ae=require("@layoutit/polycss-core"),Re=require("@layoutit/polycss-core");var Ft=require("@layoutit/polycss-core");var xe=require("@layoutit/polycss-core"),Cr=require("@layoutit/polycss-core");var kt=require("@layoutit/polycss-core");function Te(e,n,t){let o=e.getAttribute("style")??"",i=`${n}:${t}`,r=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(`(^|;)\\s*${r}\\s*:[^;]*`,"i"),c=s.test(o)?o.replace(s,(l,d)=>`${d}${i}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${i}`;c!==o&&e.setAttribute("style",c)}function lt(e,n){let t=e.getAttribute("style")??"";if(!t||!t.toLowerCase().includes(n.toLowerCase()))return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`^\\s*${o}\\s*:`,"i"),r=t.split(";").map(s=>s.trim()).filter(s=>s&&!i.test(s)).join(";");r?e.setAttribute("style",r):e.removeAttribute("style")}function nn(e,n,t,o=!1){if(n==="dynamic"){let i=(0,kt.parseHex)(e.polygon.color??"#cccccc"),r=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return(0,kt.rgbKey)(i)!==t?.dynamicColorKey&&(r+=`;--psr:${(i.r/255).toFixed(4)};--psg:${(i.g/255).toFixed(4)};--psb:${(i.b/255).toFixed(4)}`),r}return e.shadedColor?`;color:${e.shadedColor}`:""}function Os(e,n){Te(e,"--pnx",n.normal[0].toFixed(4)),Te(e,"--pny",n.normal[1].toFixed(4)),Te(e,"--pnz",n.normal[2].toFixed(4))}function Dt(e,n,t,o){if(t==="dynamic"){lt(e,"color"),lt(e,"background"),Os(e,n);let i=(0,kt.parseHex)(n.polygon.color??"#cccccc");(0,kt.rgbKey)(i)===o?.dynamicColorKey?(lt(e,"--psr"),lt(e,"--psg"),lt(e,"--psb")):(Te(e,"--psr",(i.r/255).toFixed(4)),Te(e,"--psg",(i.g/255).toFixed(4)),Te(e,"--psb",(i.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(lt(e,"background"),Te(e,"color",n.shadedColor)):(lt(e,"background"),lt(e,"color"))}var Ot=require("@layoutit/polycss-core"),sn=require("@layoutit/polycss-core"),Gn=require("@layoutit/polycss-core"),ot=require("@layoutit/polycss-core"),Er="polycss-corner-shape-solid";function on(e){return e.atlasLeafWidth??(0,sn.atlasCanonicalSizeForEntry)(e)}function rn(e){return e.atlasLeafHeight??(0,sn.atlasCanonicalSizeForEntry)(e)}function Tr(e,n){return(0,xe.resolvePolyTextureImageRendering)(e.polygon,n)}function jn(e){return e==="pixelated"?";image-rendering:pixelated":""}function _o(e,n,t,o,i,r,s,c,l){e.setAttribute("data-polycss-leaf","polygon"),e.setAttribute("data-polycss-texture-backend",n),e.setAttribute("data-polycss-texture-ready",t?"true":"false"),e.setAttribute("data-polycss-texture-image-rendering",o),i?e.setAttribute("data-polycss-texture-leaf-sizing",i):e.removeAttribute("data-polycss-texture-leaf-sizing"),r?e.setAttribute("data-polycss-texture-projection",r):e.removeAttribute("data-polycss-texture-projection"),s?e.setAttribute("data-polycss-texture-lighting",s):e.removeAttribute("data-polycss-texture-lighting"),typeof c=="number"?e.setAttribute("data-polycss-texture-leaf-width",String(c)):e.removeAttribute("data-polycss-texture-leaf-width"),typeof l=="number"?e.setAttribute("data-polycss-texture-leaf-height",String(l)):e.removeAttribute("data-polycss-texture-leaf-height")}var Mo=new WeakMap,Lo=new WeakMap;function Se(e,n,t){let o=Mo.get(e),i=Lo.get(e),r=typeof t=="number";if(!n.data&&!r&&(!o||o.length===0)){e.__polycssHasDataAttrs=!1;return}let s=new Map;if(n.data)for(let[l,d]of Object.entries(n.data))s.set(l,String(d));if(n.doubleSided===!0&&s.set("polycss-double-sided","true"),r&&s.set("poly-index",String(t)),o)for(let l of o)s.has(l)||e.removeAttribute(`data-${l}`);for(let[l,d]of s)i?.get(l)!==d&&e.setAttribute(`data-${l}`,d);let c=Array.from(s.keys());c.length>0?Mo.set(e,c):Mo.delete(e),s.size>0?Lo.set(e,s):Lo.delete(e),e.__polycssHasDataAttrs=c.length>0}function It(e){return e.__polycssHasDataAttrs===!0}function Ro(e,n,t,o,i=t==="dynamic",r){if(!n.url)return;let s=Tr(o,r),c=`url(${n.url})`,l=o.canvasW||1,d=o.canvasH||1,h=(0,sn.atlasCanonicalSizeForEntry)(o),v=on(o),f=rn(o),b=`${(0,xe.formatCssLength)(-o.x/l*v)} ${(0,xe.formatCssLength)(-o.y/d*f)}`,y=`${(0,xe.formatCssLength)(n.width/l*v)} ${(0,xe.formatCssLength)(n.height/d*f)}`,P=`transform:matrix3d(${o.atlasMatrix});--polycss-atlas-size:${h}px;--polycss-atlas-width:${(0,xe.formatCssLength)(v)};--polycss-atlas-height:${(0,xe.formatCssLength)(f)};--polycss-atlas-leaf-sizing:${o.atlasLeafSizing??"canonical"}`,x=`${P};--polycss-atlas-position:${b};--polycss-atlas-image-size:${y}`;if(t==="dynamic"){let E=i?`;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`:"";e.setAttribute("style",x+`;--polycss-atlas-url:${c}`+E+jn(s))}else e.setAttribute("style",P+`;background-image:${c};background-position:${b};background-size:${y};background-repeat:no-repeat;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`+jn(s));_o(e,"atlas",!0,s,o.atlasLeafSizing??"canonical","affine",t,v,f)}function Ar(e,n,t,o){if(n.texture){if(!t.texture||n.texture!==t.texture)return!1}else if(t.texture)return!1;let i=wr(n,t);return i?(e.style.visibility="",Te(e,"transform",`matrix3d(${i.matrix})`),o==="dynamic"&&(Te(e,"--pnx",i.normal[0].toFixed(4)),Te(e,"--pny",i.normal[1].toFixed(4)),Te(e,"--pnz",i.normal[2].toFixed(4))),Se(e,t,n.index),!0):(e.style.visibility="hidden",Se(e,t,n.index),!0)}function ko(e,n,t,o,i){if(o!=="baked")return{...e,polygon:n,normal:t};let r=i.directionalLight,s=i.ambientLight,c=r?.direction??ot.DEFAULT_LIGHT_DIR,l=r?.color??ot.DEFAULT_LIGHT_COLOR,d=Math.max(0,r?.intensity??ot.DEFAULT_LIGHT_INTENSITY),h=s?.color??ot.DEFAULT_AMBIENT_COLOR,v=Math.max(0,s?.intensity??ot.DEFAULT_AMBIENT_INTENSITY),f=Math.hypot(c[0],c[1],c[2])||1,b=c[0]/f,y=c[1]/f,P=c[2]/f,E=i.lightOccludedPolyIndices?.has(e.index)??!1?0:d*Math.max(0,t[0]*b+t[1]*y+t[2]*P);return{...e,polygon:n,normal:t,shadedColor:(0,Cr.shadePolygon)(n.color??"#cccccc",E,l,h,v)}}function wr(e,n){let t=Mr(e,n);if(!t)return null;let{normal:o,xAxis:i,yAxis:r,tx:s,ty:c,tz:l}=t;return{normal:o,matrix:(0,xe.formatMatrix3dValues)([i[0]*e.canvasW/on(e),i[1]*e.canvasW/on(e),i[2]*e.canvasW/on(e),0,r[0]*e.canvasH/rn(e),r[1]*e.canvasH/rn(e),r[2]*e.canvasH/rn(e),0,o[0],o[1],o[2],0,s,c,l,1])}}var Mr=Gn.stableBasisFromPlan;function Is(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=Mr(e,n);if(!o)return null;let i=(0,Gn.computeProjectiveQuadMatrix)(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return i?{matrix:i,normal:o.normal}:null}function Do(e,n,t,o,i=!1){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${(0,xe.formatSolidQuadMatrix)(e)})`+nn(e,n,o,i)),Se(r,e.polygon,e.index),r}function Oo(e,n,t,o,i=!1){let r=t.createElement("i");return r.setAttribute("style",(0,Ot.formatBorderShapeElementStyle)(e)+nn(e,n,o,i)),Se(r,e.polygon,e.index),r}function Io(e,n,t,o,i,r=!1){let s=o.createElement("u");return s.className=Er,s.setAttribute("style",(0,Ot.formatCornerShapeElementStyle)(e,n)+nn(e,t,i,r)),Se(s,e.polygon,e.index),s}function Ho(e,n,t,o,i=!1){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+nn(e,n,o,i)),Se(r,e.polygon,e.index),r}function Lr(e,n,t,o,i,r,s){let c=n.projectiveMatrix?Is(n,t,r):wr(n,t);if(!c)return!1;let l=ko(n,t,c.normal,o,i);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,Dt(e,l,o,s),Se(e,l.polygon,l.index),!0}function _r(e,n,t,o){e.style.visibility="",e.setAttribute("style",(0,Ot.formatBorderShapeElementStyle)(n)),Dt(e,n,t,o),Se(e,n.polygon,n.index)}function Rr(e,n,t,o,i){e.style.visibility="",e.className=Er,e.setAttribute("style",(0,Ot.formatCornerShapeElementStyle)(n,t)),Dt(e,n,o,i),Te(e,"background","currentColor"),Se(e,n.polygon,n.index)}function Fo(e,n,t,o=!1,i){let r=t.createElement("s"),s=Tr(e,i),c=(0,sn.atlasCanonicalSizeForEntry)(e),l=on(e),d=rn(e),h=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:${c}px;--polycss-atlas-width:${(0,xe.formatCssLength)(l)};--polycss-atlas-height:${(0,xe.formatCssLength)(d)};--polycss-atlas-leaf-sizing:${e.atlasLeafSizing??"canonical"};opacity:0`+h+jn(s)),_o(r,"atlas",!1,s,e.atlasLeafSizing??"canonical","affine",n,l,d),Se(r,e.polygon,e.index),r}function Bo(e,n,t,o=!1){let i=t.createElement("s"),r=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return i.setAttribute("style",`transform:matrix3d(${n.matrix});--polycss-atlas-width:${(0,xe.formatCssLength)(n.leafWidth)};--polycss-atlas-height:${(0,xe.formatCssLength)(n.leafHeight)};--polycss-atlas-leaf-sizing:image;background-image:url(${n.url});background-position:${(0,xe.formatCssLength)(n.backgroundPosition[0])} ${(0,xe.formatCssLength)(n.backgroundPosition[1])};background-size:${(0,xe.formatCssLength)(n.backgroundSize[0])} ${(0,xe.formatCssLength)(n.backgroundSize[1])};background-repeat:no-repeat;background-blend-mode:normal;mask-image:none;-webkit-mask-image:none`+r+jn(n.imageRendering)),_o(i,"image",!0,n.imageRendering,"image",n.projection,n.lighting,n.leafWidth,n.leafHeight),i.setAttribute("data-polycss-texture-source-x",String(n.sourceRect.x)),i.setAttribute("data-polycss-texture-source-y",String(n.sourceRect.y)),i.setAttribute("data-polycss-texture-source-width",String(n.sourceRect.width)),i.setAttribute("data-polycss-texture-source-height",String(n.sourceRect.height)),Se(i,e.polygon,e.index),i}var zr=require("@layoutit/polycss-core");var $n=require("@layoutit/polycss-core");function bt(e,n,t,o={}){let i=o.primitive!=null?void 0:(()=>{let r=t.doc??(typeof document<"u"?document:null);return r?qe(r,t.strategies)??"border":"border"})();return(0,$n.computeSolidTrianglePlan)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??i})}function zo(e,n,t,o,i,r,s,c,l,d,h,v,f){let b=o.primitive!=null?void 0:(()=>{let y=t.doc??(typeof document<"u"?document:null);return y?qe(y,t.strategies)??"border":"border"})();return(0,$n.computeSolidTrianglePlanFromCssPoints)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??b},i,r,s,c,l,d,h,v,f)}var xt=require("@layoutit/polycss-core"),ct=require("@layoutit/polycss-core"),kr=require("@layoutit/polycss-core");var Vo=require("@layoutit/polycss-core");var Hs="0 48px 96px 48px";function Dr(e,n){return(0,xt.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function Or(e,n,t){let o=(0,xt.resolveBleedRatio)(t.seamBleed),i=xt.DEFAULT_SEAM_BLEED*o,r={...t,bleedRatio:o};return n&&i>0?{...r,seamBleed:n.has(e)?i:void 0,seamEdges:n.get(e)}:r}function No(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 Ir(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function Ht(e,n,t,o,i,r){return t?r.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:i==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:Ir(n,r):!0}function jo(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"?Hs:""),t.__polycssSolidTrianglePrimitive=n)}function Go(e){let n=e;n.__polycssSolidTriangleHidden&&(e.style.visibility="",n.__polycssSolidTriangleHidden=!1)}function an(e){let n=e;n.__polycssSolidTriangleHidden||(e.style.visibility="hidden",n.__polycssSolidTriangleHidden=!0)}function Un(e,n){e.setAttribute("style",n.styleText),jo(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||It(e))&&Se(e,n.polygon)}function Hr(e,n,t,o){if(!n.colorComputed){(n.polygon.data||It(e))&&Se(e,n.polygon);return}let i=e,r=n.bakedColor??"",s=n.bakedRgb,c=n.bakedAlpha??1,l=i.__polycssSolidTriangleColor,d=i.__polycssSolidTriangleColorRgb,h=i.__polycssSolidTriangleColorAlpha??1,v=o??Ir(n.index,t);if(!t.updatesDisabled&&l!==r&&(l===void 0||v)){let f=r,b=s;if(t.maxStep>0&&d&&s&&h===c){let y=(0,ct.stepRgbToward)(d,s,t.maxStep);b=y,f=(0,ct.rgbToCss)(y,c)}(f!==l||!(0,ct.rgbEqual)(b,d))&&(e.style.color=f),i.__polycssSolidTriangleColor=f,i.__polycssSolidTriangleColorRgb=b,i.__polycssSolidTriangleColorAlpha=c,i.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||It(e))&&Se(e,n.polygon)}function Wn(e,n,t,o){let i=e;jo(e,n.primitive),i.__polycssSolidTriangleBasis!==n.basis&&(i.__polycssSolidTriangleBasis=n.basis),Go(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||It(e))&&Hr(e,n,t,o)}function $o(e,n,t,o){Go(e),Hr(e,n,t,o)}function Yn(e,n){let t=e;jo(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),Go(e),e.style.transform=n.transformText,(n.polygon.data||It(e))&&Se(e,n.polygon)}function Fs(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 Fr(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)),i=Math.max(1,Math.floor(t.stableTriangleColorFreezeFrames??1));if(i<=1&&!Number.isFinite(t.stableTriangleColorBudget))return null;let r=Fs(e.length,t),s=Math.max(1,Math.floor(t.stableTriangleColorMaxAge??Math.max(2,i*2))),c=[];for(let l=0;l<e.length;l++){let d=e[l],h=n[l];if(d.kind!=="triangle"||!h)continue;let v=d.element,f=v.__polycssSolidTriangleColor,b=h.bakedColor??"";if(f===b)continue;let y=v.__polycssSolidTriangleColorFrame??0,P=Math.max(0,o-y),x=(0,ct.colorErrorScore)(f,b);c.push({index:l,score:(P>=s?1e6:0)+x*1e4+P})}return c.length===0?new Set:(c.sort((l,d)=>d.score-l.score),new Set(c.slice(0,r).map(l=>l.index)))}function Xn(e,n){let t=n.createElement("u");return Un(t,e),Se(t,e.polygon,e.index),t}function Bs(e,n,t){let o=t.createElement("u");return an(o),Se(o,e,n),o}function Br(e,n,t,o,i,r){let s=t,c=s.stableTriangleDebug,l=o&&i==="color-only";if(s.stableTriangleColorPolicy==="adaptive"||e.length!==n.length)return!1;let d=(0,Vo.stableTriangleMatrixDecimals)(s.stableTriangleMatrixDecimals),h=t.doc??(typeof document<"u"?document:null),v=h?qe(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=Dr(n,t);for(let b=0;b<e.length;b++){let y=e[b].element,P=n[b];if(l){if(Ht(y,b,o,c,s.stableTriangleColorPolicy,r)){let E=(0,kr.computeSolidTriangleColorPlan)(P,b,t);if(!E)continue;$o(y,E,r)}continue}let x=bt(P,b,Or(b,f,t),{basis:y.__polycssSolidTriangleBasis,matrixDecimals:d,primitive:v,includeColor:i!=="plan-only"&&i!=="transform-only"&&Ht(y,b,o,c,s.stableTriangleColorPolicy,r)});if(!x){an(y);continue}o&&i==="plan-only"||(o&&i==="transform-only"?Yn(y,x):o?Wn(y,x,r):Un(y,x))}return!0}function ln(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=qe(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let i=(0,Vo.stableTriangleMatrixDecimals)(n.stableTriangleMatrixDecimals),r=[],s=Dr(e,n);for(let c=0;c<e.length;c+=1){let l=e[c],d=bt(l,c,Or(c,s,n),{matrixDecimals:i,primitive:o}),h=d?Xn(d,t):Bs(l,c,t);r.push({polygonIndex:c,element:h,kind:"triangle",dispose:()=>{}})}return{rendered:r,dispose(){}}}var Wo=require("@layoutit/polycss-core");function Vr(){return new Promise(e=>setTimeout(e,0))}async function Uo(e){return performance.now()-e<Ae.ASYNC_RENDER_BUDGET_MS?e:(await Vr(),performance.now())}function Nr(e,n){let t=(0,Ae.resolveBleedRatio)(n.seamBleed),o=Ae.DEFAULT_SEAM_BLEED*t,i={...n,bleedRatio:t};return e.seamBleedEdges?.size&&o>0?{...i,seamBleed:o,seamEdges:e.seamBleedEdges}:{...i,seamBleed:void 0,seamEdges:void 0}}function jr(e,n){return(0,Re.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function Gr(e,n,t){let o=(0,Ae.resolveBleedRatio)(t.seamBleed),i=Ae.DEFAULT_SEAM_BLEED*o,r={...t,bleedRatio:o};return n&&i>0?{...r,seamBleed:n.has(e)?i:void 0,seamEdges:n.get(e)}:r}function Bt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=(0,Re.buildBasisHints)(e,n),i=Rt(t),r=e.map((s,c)=>(0,Re.computeTextureAtlasPlan)(s,c,n,i,o[c]));return Nn(r,n.textureLighting??"baked",t,n.strategies)}function zt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",i=n,r=o==="dynamic"&&i.skipDynamicNormalVars===!0,s=new Set(n.strategies?.disable??[]),c=!s.has("b"),l=c&&tn(t),d=qe(t,n.strategies),h=d!==null,v=!s.has("i")&&en(t),f=!s.has("i")&&Jt(t),b=(0,Re.buildBasisHints)(e,n),y=Rt(t),P=jr(e,n),x=e.map((u,m)=>(0,Re.computeTextureAtlasPlan)(u,m,Gr(m,P,n),y,b[m])),E=n.solidPaintDefaults??(i.computeSolidPaintDefaults?Nn(x,o,t,n.strategies):void 0),O=E?{...n,solidPaintDefaults:E}:n,R=x.map(u=>u&&h&&(0,ee.isSolidTrianglePlan)(u)?bt(u.polygon,u.index,Nr(u,O),{primitive:d??void 0}):null),j=x.map(u=>u&&v&&!(0,ee.isSolidTrianglePlan)(u)&&!(c&&(0,ee.isFullRectSolid)(u))&&!(l&&(0,ee.isProjectiveQuadPlan)(u))?(0,Ft.cornerShapeGeometryForPlan)(u):null),D=x.map(u=>u?(0,Re.resolvePolyTextureLeafGeometry)(u,{imageRendering:n.textureImageRendering,backend:n.textureBackend,projection:n.textureProjection,allowProjective:l,projectiveQuadGuards:y}):null),Q=x.map((u,m)=>D[m]?null:u&&(u.texture||!(c&&(0,ee.isFullRectSolid)(u))&&!R[m]&&!(l&&(0,ee.isProjectiveQuadPlan)(u))&&!j[m]&&!f?u:null)),{packed:J,atlasScale:k}=qt(Q,n.textureQuality,t,n.textureLeafSizing),V=new Map,z=[],B=!1,A=[];for(let u=0;u<e.length;u++){let m=x[u],L=R[u],_=j[u],H=D[u];if(!m)continue;let q=J.entries[u];if(q){let C=Fo(q,o,t,r,n.textureImageRendering);V.set(u,C),z.push({polygonIndex:u,element:C,kind:"atlas",plan:q,dispose:()=>{}})}else if(H){let C=Bo(m,H,t,r);z.push({polygonIndex:u,element:C,kind:"image",plan:m,dispose:()=>{}})}else if(!m.texture&&c&&(0,ee.isFullRectSolid)(m)){let C=Do(m,o,t,E,r);z.push({polygonIndex:u,element:C,kind:"solid",plan:m,dispose:()=>{}})}else if(!m.texture&&L){let C=Xn(L,t);z.push({polygonIndex:u,element:C,kind:"triangle",plan:m,dispose:()=>{}})}else if(!m.texture&&l&&(0,ee.isProjectiveQuadPlan)(m)){let C=Ho(m,o,t,E,r);z.push({polygonIndex:u,element:C,kind:"solid",plan:m,dispose:()=>{}})}else if(!m.texture&&_){let C=Io(m,_,o,t,E,r);z.push({polygonIndex:u,element:C,kind:"corner",plan:m,dispose:()=>{}})}else if(!m.texture&&f){let C=Oo(m,o,t,E,r);z.push({polygonIndex:u,element:C,kind:"border",plan:m,dispose:()=>{}})}}z.sort((u,m)=>u.polygonIndex-m.polygonIndex);let g=Kt(J.pages,o,t,k,()=>B).then(u=>{if(B){for(let m of u)m.url?.startsWith("blob:")&&URL.revokeObjectURL(m.url);return}A=u.flatMap(m=>m.url?.startsWith("blob:")?[m.url]:[]);for(let m=0;m<J.pages.length;m++){let L=J.pages[m],_=u[m];if(_)for(let H of L.entries){let q=V.get(H.index);!q||!_.url||Ro(q,_,o,H,!0,n.textureImageRendering)}}}).catch(()=>{if(!B)for(let u of V.values())Te(u,"opacity","0.5"),Te(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:z,solidPaintDefaults:E??{},pagesReady:g,dispose(){B=!0;for(let u of A)URL.revokeObjectURL(u);A=[]}}}async function Zn(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let i=n.textureLighting??"baked",s=i==="dynamic"&&n.skipDynamicNormalVars===!0,c=new Set(n.strategies?.disable??[]),l=!c.has("b"),d=l&&tn(o),h=qe(o,n.strategies),v=h!==null,f=!c.has("i")&&en(o),b=!c.has("i")&&Jt(o);if(await Vr(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let y=(0,Re.buildBasisHints)(e,n),P=Rt(o),x=jr(e,n),E=performance.now(),O=new Array(e.length);for(let u=0;u<e.length;u++)if(O[u]=(0,Re.computeTextureAtlasPlan)(e[u],u,Gr(u,x,n),P,y[u]),E=await Uo(E),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let R=n.solidPaintDefaults??Nn(O,i,o,n.strategies),j=new Array(O.length),D=new Array(O.length),Q=new Array(O.length),J=new Array(O.length);for(let u=0;u<O.length;u++){let m=O[u],L=m&&v&&(0,ee.isSolidTrianglePlan)(m)?bt(m.polygon,m.index,Nr(m,{...n,solidPaintDefaults:R}),{primitive:h??void 0}):null;j[u]=L;let _=m&&f&&!(0,ee.isSolidTrianglePlan)(m)&&!(l&&(0,ee.isFullRectSolid)(m))&&!(d&&(0,ee.isProjectiveQuadPlan)(m))?(0,Ft.cornerShapeGeometryForPlan)(m):null;D[u]=_;let H=m?(0,Re.resolvePolyTextureLeafGeometry)(m,{imageRendering:n.textureImageRendering,backend:n.textureBackend,projection:n.textureProjection,allowProjective:d,projectiveQuadGuards:P}):null;if(Q[u]=H,J[u]=H?null:m&&(m.texture||!(l&&(0,ee.isFullRectSolid)(m))&&!L&&!(d&&(0,ee.isProjectiveQuadPlan)(m))&&!_&&!b?m:null),E=await Uo(E),t())return{rendered:[],solidPaintDefaults:R,dispose:()=>{}}}let{packed:k,atlasScale:V}=qt(J,n.textureQuality,o,n.textureLeafSizing),z=new Map,B=[],A=!1,g=[];for(let u=0;u<e.length;u++){let m=O[u],L=j[u],_=D[u],H=Q[u];if(!m)continue;let q=k.entries[u];if(q){let C=Fo(q,i,o,s,n.textureImageRendering);z.set(u,C),B.push({polygonIndex:u,element:C,kind:"atlas",plan:q,dispose:()=>{}})}else if(H){let C=Bo(m,H,o,s);B.push({polygonIndex:u,element:C,kind:"image",plan:m,dispose:()=>{}})}else if(!m.texture&&l&&(0,ee.isFullRectSolid)(m)){let C=Do(m,i,o,R,s);B.push({polygonIndex:u,element:C,kind:"solid",plan:m,dispose:()=>{}})}else if(!m.texture&&L){let C=Xn(L,o);B.push({polygonIndex:u,element:C,kind:"triangle",plan:m,dispose:()=>{}})}else if(!m.texture&&d&&(0,ee.isProjectiveQuadPlan)(m)){let C=Ho(m,i,o,R,s);B.push({polygonIndex:u,element:C,kind:"solid",plan:m,dispose:()=>{}})}else if(!m.texture&&_){let C=Io(m,_,i,o,R,s);B.push({polygonIndex:u,element:C,kind:"corner",plan:m,dispose:()=>{}})}else if(!m.texture&&b){let C=Oo(m,i,o,R,s);B.push({polygonIndex:u,element:C,kind:"border",plan:m,dispose:()=>{}})}if(E=await Uo(E),t()){for(let C of B)C.dispose();return{rendered:[],solidPaintDefaults:R,dispose:()=>{}}}}B.sort((u,m)=>u.polygonIndex-m.polygonIndex);let T=Kt(k.pages,i,o,V,()=>A||t()).then(u=>{if(A||t()){for(let m of u)m.url?.startsWith("blob:")&&URL.revokeObjectURL(m.url);return}g=u.flatMap(m=>m.url?.startsWith("blob:")?[m.url]:[]);for(let m=0;m<k.pages.length;m++){let L=k.pages[m],_=u[m];if(_)for(let H of L.entries){let q=z.get(H.index);!q||!_.url||Ro(q,_,i,H,!0,n.textureImageRendering)}}}).catch(()=>{if(!(A||t()))for(let u of z.values())Te(u,"opacity","0.5"),Te(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:B,solidPaintDefaults:R,pagesReady:T,dispose(){A=!0;for(let u of g)URL.revokeObjectURL(u);g=[]}}}function Qn(e,n,t,o={}){let i=o.textureLighting??"baked",r=o,s=r.optimizeStableTriangleStyle===!0&&i==="baked";if(!s||r.stableTriangleColorPolicy==="adaptive"||e.length!==t.polygonCount||n.length!==t.polygonCount||t.vertices.length<t.polygonCount*9)return!1;let c=r.stableTriangleDebug,l=r.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full");if(l==="color-only")return!1;let d=(0,Wo.stableTriangleMatrixDecimals)(r.stableTriangleMatrixDecimals),h=No(r),v=o.tileSize??Ae.DEFAULT_TILE,f=o.layerElevation??v,b=o.doc??(typeof document<"u"?document:null),y=b?qe(b,o.strategies)??"border":"border";for(let x=0;x<e.length;x++){let E=e[x],O=n[x];if(E.kind!=="triangle"||E.polygonIndex!==x||!O||O.vertices.length!==3||O.texture||O.material?.texture)return!1}let P=t.vertices;for(let x=0;x<e.length;x++){let E=e[x].element,O=n[x],R=x*9,j=P[R+1]*v,D=P[R]*v,Q=P[R+2]*f,J=P[R+4]*v,k=P[R+3]*v,V=P[R+5]*f,z=P[R+7]*v,B=P[R+6]*v,A=P[R+8]*f,g=zo(O,x,o,{basis:E.__polycssSolidTriangleBasis,matrixDecimals:d,primitive:y,color:t.colors?.[x],includeColor:l!=="plan-only"&&l!=="transform-only"&&Ht(E,x,s,c,r.stableTriangleColorPolicy,h)},j,D,Q,J,k,V,z,B,A);if(!g){an(E);continue}l!=="plan-only"&&(l==="transform-only"?Yn(E,g):Wn(E,g,h))}return!0}function qn(e,n,t={}){if(e.length!==n.length)return!1;let o=t,i=t.doc??(typeof document<"u"?document:null),r=t.textureLighting??"baked",s=new Set(t.strategies?.disable??[]),c=!s.has("b"),l=!!i&&c&&tn(i),d=!!i&&!s.has("i")&&en(i),h=!!i&&!s.has("i")&&Jt(i),v=(0,Ae.resolveBleedRatio)(o.seamBleed),f=i?Rt(i,{bleed:Ae.PROJECTIVE_QUAD_BLEED*v}):{denomEps:Ae.PROJECTIVE_QUAD_DENOM_EPS,maxWeightRatio:Ae.PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,bleed:Ae.PROJECTIVE_QUAD_BLEED*v,disableGuards:!1},b=o.optimizeStableTriangleStyle===!0&&r==="baked",y=o.stableTriangleDebug,P=o.stableTriangleUpdateMode??(y==="plan-only"||y==="transform-only"?y:"full"),x=b&&P==="color-only",E=No(o),O=(0,Wo.stableTriangleMatrixDecimals)(o.stableTriangleMatrixDecimals),R=i?qe(i,t.strategies)??"border":"border";if(Br(e,n,t,b,P,E))return!0;let j=[],D=[],Q=[];for(let k=0;k<e.length;k++){let V=e[k];if(V.polygonIndex!==k)return!1;let z=n[k];if(!z||x&&V.kind!=="triangle")return!1;if(V.kind==="atlas"){if(!V.plan||!Ar(V.element,V.plan,z,r))return!1;continue}if(V.kind==="triangle"){let B=V.element;if(x){let g=o.stableTriangleColorPolicy==="adaptive"||Ht(B,k,b,y,o.stableTriangleColorPolicy,E);D[k]=g?(0,zr.computeSolidTriangleColorPlan)(z,k,t):null;continue}let A=bt(z,k,t,{basis:B.__polycssSolidTriangleBasis,matrixDecimals:O,primitive:R,includeColor:P!=="plan-only"&&P!=="transform-only"&&Ht(B,k,b,y,o.stableTriangleColorPolicy,E)});if(!A){j[k]=null;continue}j[k]=A;continue}if(V.kind==="solid"){if(!V.plan||z.texture||z.vertices.length!==V.plan.polygon.vertices.length)return!1;Q[k]=V.plan;continue}if(V.kind==="border"){let B=(0,Re.computeTextureAtlasPlan)(z,k,t,f);if(!B||B.texture||!h||c&&(0,ee.isFullRectSolid)(B)||l&&(0,ee.isProjectiveQuadPlan)(B)||d&&(0,Ft.cornerShapeGeometryForPlan)(B))return!1;Q[k]=B;continue}if(V.kind==="corner"){let B=(0,Re.computeTextureAtlasPlan)(z,k,t,f);if(!B||B.texture||!d||(0,ee.isSolidTrianglePlan)(B)||c&&(0,ee.isFullRectSolid)(B)||l&&(0,ee.isProjectiveQuadPlan)(B)||!(0,Ft.cornerShapeGeometryForPlan)(B))return!1;Q[k]=B;continue}return!1}let J=b&&P!=="plan-only"&&P!=="transform-only"?Fr(e,x?D:j,o):null;for(let k=0;k<e.length;k++){let V=e[k];if(V.kind==="triangle"){if(x){let B=D[k];B&&$o(V.element,B,E,J?.has(k));continue}let z=j[k];if(!z){an(V.element);continue}if(b&&P==="plan-only")continue;b&&P==="transform-only"?Yn(V.element,z):b?Wn(V.element,z,E,J?.has(k)):Un(V.element,z)}else if(V.kind==="solid"){let z=Q[k];if(!z||!Lr(V.element,z,n[k],r,t,f,o.solidPaintDefaults))return!1}else if(V.kind==="border"){let z=Q[k];if(!z)return!1;_r(V.element,z,r,o.solidPaintDefaults)}else if(V.kind==="corner"){let z=Q[k],B=z?(0,Ft.cornerShapeGeometryForPlan)(z):null;if(!z||!B)return!1;Rr(V.element,z,B,r,o.solidPaintDefaults)}}return!0}var $r=require("@layoutit/polycss-core"),Nt=require("@layoutit/polycss-core"),Kn=require("@layoutit/polycss-core");var oe=require("@layoutit/polycss-core"),$s=[.4,-.7,.59],Us="#ffffff",Ws=1,Ys="#ffffff",Xs=.4,Qr=1,Zs=8,Qs=oe.PROJECTIVE_QUAD_BLEED,it=1e-6,qs=(0,oe.resolveProjectiveQuadGuards)({bleed:0}),qr={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},Zo=["t","b","bl","br","fr","fl"],Ks=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 Ur(e){let n=[];for(let t of Zo)(0,oe.normalFacesCamera)(qr[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 ea(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,i=0,r=0;for(let c=1;c+1<n.length;c+=1){let l=n[c],d=n[c+1],h=l[1]-t[1],v=l[0]-t[0],f=l[2]-t[2],b=d[1]-t[1],y=d[0]-t[0],P=d[2]-t[2];o-=v*P-f*y,i-=f*b-h*P,r-=h*y-v*b}let s=Math.hypot(o,i,r);return s<=1e-9?null:[Math.round(o/s),Math.round(i/s),Math.round(r/s)]}function ta(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=ea(e),t=n?Ks.get(n.join(",")):void 0;if(!t)return null;let o=1/0,i=1/0,r=1/0,s=-1/0,c=-1/0,l=-1/0;for(let v of e.vertices)o=Math.min(o,v[0]),i=Math.min(i,v[1]),r=Math.min(r,v[2]),s=Math.max(s,v[0]),c=Math.max(c,v[1]),l=Math.max(l,v[2]);let d=1e-6,h=la(e.color);return Math.abs(l-r)<=d?{axis:"z",face:t,left:i*oe.BASE_TILE,top:o*oe.BASE_TILE,width:Math.max(0,(c-i)*oe.BASE_TILE),height:Math.max(0,(s-o)*oe.BASE_TILE),z:r*oe.BASE_TILE,baseColor:h,bleed:Yo()}:Math.abs(s-o)<=d?{axis:"x",face:t,left:i*oe.BASE_TILE,top:r*oe.BASE_TILE,width:Math.max(0,(c-i)*oe.BASE_TILE),height:Math.max(0,(l-r)*oe.BASE_TILE),z:-o*oe.BASE_TILE,baseColor:h,bleed:Yo()}:Math.abs(c-i)<=d?{axis:"y",face:t,left:r*oe.BASE_TILE,top:o*oe.BASE_TILE,width:Math.max(0,(l-r)*oe.BASE_TILE),height:Math.max(0,(s-o)*oe.BASE_TILE),z:-i*oe.BASE_TILE,baseColor:h,bleed:Yo()}:null}function Yo(){return{left:0,right:0,top:0,bottom:0}}function na(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 Wr(e){return[e[1]*oe.BASE_TILE,e[0]*oe.BASE_TILE,e[2]*oe.BASE_TILE]}function Yr(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function oa(e,n,t){let o=e.left,i=e.left+e.width,r=e.top,s=e.top+e.height;if(Math.abs(n[0]-t[0])<=it){if(Math.abs(n[0]-o)<=it)return"left";if(Math.abs(n[0]-i)<=it)return"right"}if(Math.abs(n[1]-t[1])<=it){if(Math.abs(n[1]-r)<=it)return"top";if(Math.abs(n[1]-s)<=it)return"bottom"}return null}function ra(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=it)){if(t!==null)return null;t=o}return t}function ia(e,n,t){let o=n.vertices,i=Wr(o[t]),r=Wr(o[(t+1)%o.length]),s=oa(e,Yr(e,i),Yr(e,r));if(!s)return null;let c=ra(i,r);if(c===null)return null;let l=Math.min(i[c],r[c]),d=Math.max(i[c],r[c]);return d-l>it?{item:e,side:s,variableAxis:c,fixed:i,start:l,end:d}:null}function Xr(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],Qs)}function sa(e,n){let t=new Map;for(let o of n){let i=e[o.sourceIndex];if(i)for(let r=0;r<i.vertices.length;r+=1){let s=ia(o,i,r);if(!s)continue;let c=na(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((r,s)=>r.start-s.start||r.end-s.end);let i=[];for(let r of o){i=i.filter(s=>s.end>r.start+it);for(let s of i)s.item.sourceIndex!==r.item.sourceIndex&&(Xr(s),Xr(r));i.push(r)}}}function aa(e){let n=(0,oe.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 la(e){if(!e)return"#cccccc";let n=(0,oe.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(${Xo(t.r)}, ${Xo(t.g)}, ${Xo(t.b)}, ${o})`}return ca(t)}function ca({r:e,g:n,b:t}){let o=i=>Math.round(Math.max(0,Math.min(255,i))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function Xo(e){return Math.round(Math.max(0,Math.min(255,e)))}function ua(e,n,t,o){let i=t?.direction??$s,r=Math.hypot(i[0],i[1],i[2])||1,s=i[0]/r,c=i[1]/r,l=i[2]/r,d=Math.max(0,t?.intensity??Ws)*Math.max(0,e[0]*s+e[1]*c+e[2]*l),h=Math.max(0,o?.intensity??Xs),v=t?.color??Us,f=o?.color??Ys,b=(0,oe.shadePolygon)(n,d,v,f,h),y=aa(n);if(y.alpha>=1)return b;let P=parseInt(b.slice(1,3),16),x=parseInt(b.slice(3,5),16),E=parseInt(b.slice(5,7),16);return`rgba(${P}, ${x}, ${E}, ${y.alpha})`}function da(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],i=ta(o);if(!i||i.width<=0||i.height<=0)return[];n.push({...i,sourceIndex:t})}return sa(e,n),n}function pa(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 ma(e){let n=e.left,t=e.top,o=e.left+e.width,i=e.top+e.height;return[n,t,o,t,o,i,n,i]}function fa(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function ga(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(i=>!Number.isFinite(i)))return null;let o=oe.SOLID_QUAD_CANONICAL_SIZE/n;for(let i=0;i<8;i+=1)t[i]*=o;return`matrix3d(${t.map(i=>Number(i.toFixed(6))).join(",")})`}function Zr(e,n){let t=e.left-e.bleed.left,o=e.top-e.bleed.top,i=e.width+e.bleed.left+e.bleed.right,r=e.height+e.bleed.top+e.bleed.bottom,s=e.z,c=i/n,l=r/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 ha(e,n){let{xAxis:t,yAxis:o,normal:i,tx:r,ty:s,tz:c}=pa(e),l=(0,oe.computeProjectiveQuadMatrix)(ma(e),t,o,i,r,s,c,qs,fa(e));return l?ga(l,n)??Zr(e,n):Zr(e,n)}function ya(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function ba(e){return ya(e)?Zs:Qr}function xa(e){return e.axis==="x"?[e.left+e.width/2,-e.z,e.top+e.height/2]:e.axis==="y"?[-e.z,e.top+e.height/2,e.left+e.width/2]:[e.left+e.width/2,e.top+e.height/2,e.z]}function va(e,n){let t=xa(e),o=n.meshRotation;o&&(t=(0,oe.rotateVec3InWrapperCssFrame)(t,o));let[i,r]=(0,oe.rotateVec3)(t,n.rotX,0,n.rotY);return{x:i,y:r}}function Pa(e,n,t){let o=e.filter(f=>n.has(f.face)).map(f=>({item:f,...va(f,t)}));if(o.length===0)return[];let i=1/0,r=-1/0,s=1/0,c=-1/0;for(let f of o)i=Math.min(i,f.x),r=Math.max(r,f.x),s=Math.min(s,f.y),c=Math.max(c,f.y);let l=4,d=Math.max(1e-6,r-i),h=Math.max(1e-6,c-s),v=new Map;for(let f of o){let b=Math.min(l-1,Math.max(0,Math.floor((f.x-i)/d*l))),y=Math.min(l-1,Math.max(0,Math.floor((f.y-s)/h*l))),P=`${b}:${y}`,x=v.get(P);x||(x={tx:b,ty:y,sourceIndex:f.item.sourceIndex,items:[]},v.set(P,x)),x.items.push(f.item),x.sourceIndex=Math.min(x.sourceIndex,f.item.sourceIndex)}return Array.from(v.values()).sort((f,b)=>f.ty-b.ty||f.tx-b.tx||f.sourceIndex-b.sourceIndex).flatMap(f=>f.items)}function Kr(e){let{doc:n,wrapper:t,polygons:o,directionalLight:i,ambientLight:r}=e,s=da(o);if(s.length===0)return null;let c=new Set(s.map(g=>g.face));t.classList.add("polycss-voxel-mesh");let l=ba(n);l!==Qr&&t.style.setProperty("--polycss-voxel-primitive",`${l}px`);let d=new Map,h=(g,T)=>{let u=`${g}|${T}`,m=d.get(u);if(m)return m;let L=ua(qr[g],T,i,r);return d.set(u,L),L},v=new Map,f=new Map,b=new Map,y=new Map;for(let g of s){let T=y.get(g.face);T||(T=[],y.set(g.face,T)),T.push(g)}let P="",x=0,E=new Set,O=g=>{let T=v.get(g.sourceIndex);return T||(T=n.createElement("b"),v.set(g.sourceIndex,T),Js(T,h(g.face,g.baseColor),ha(g,l))),T},R=g=>{let T=f.get(g);return T||(T=n.createElement("span"),T.className=`polycss-voxel-face polycss-voxel-face-${g}`,T.dataset.polycssVoxelFace=g,T.__polycssVoxelFaceHost=!0,f.set(g,T)),T},j=()=>{for(let g of Array.from(t.childNodes))if(!g.__polycssVoxelFaceHost)return g;return null},D=(g,T)=>{let u=T.map(_=>_.sourceIndex).join(",");if(b.get(g)===u)return;let m=R(g),L=n.createDocumentFragment();for(let _ of T)L.appendChild(O(_));m.replaceChildren(L),b.set(g,u)},Q=()=>{for(let g of Zo)c.has(g)&&D(g,y.get(g)??[])},J=g=>new Set(g.split("|").filter(Boolean)),k=g=>{let T=J(g);return Zo.filter(u=>T.has(u)&&c.has(u))},V=g=>{let T=0;for(let u of g)T+=y.get(u)?.length??0;return T},z=g=>{let T=new Set,u=[],m=new Map;for(let L of g){T.has(L.face)||(T.add(L.face),u.push(L.face));let _=m.get(L.face);_||(_=[],m.set(L.face,_)),_.push(L)}return{orderedFaces:u,itemsByFace:m}},B=(g,T)=>{let u=new Set(g);for(let m of E){if(u.has(m))continue;let L=f.get(m);L?.parentNode===t&&t.removeChild(L)}if(T){let m=n.createDocumentFragment();for(let L of g)m.appendChild(R(L));t.insertBefore(m,j()),E=u;return}for(let m=0;m<g.length;m+=1){let L=g[m],_=R(L);if(_.parentNode===t)continue;let H=null;for(let q=m+1;q<g.length;q+=1){let C=f.get(g[q]);if(C?.parentNode===t){H=C;break}}t.insertBefore(_,H??j())}E=u},A=(g,T,u)=>{if(!u){let q=k(g);B(q,!1),x=V(q);return}let m=new Set(g.split("|").filter(Boolean)),L=Pa(s,m,T),{orderedFaces:_,itemsByFace:H}=z(L);for(let q of _)D(q,H.get(q)??[]);B(_,!0),x=L.length};return Q(),{get brushCount(){return x},render(g){P=Ur(g),A(P,g,!0)},syncCamera(g){let T=Ur(g);T!==P&&(P=T,A(T,g,!1))},dispose(){for(let g of f.values())g.remove();t.classList.remove("polycss-voxel-mesh"),t.style.removeProperty("--polycss-voxel-primitive"),v.clear(),f.clear(),b.clear(),x=0,E=new Set,P=""}}}var Jr="polycss-styles";function ei(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(Jr))return;let t=n.createElement("style");t.id=Jr,t.textContent=Sa,n.head.appendChild(t)}var Sa=`
1
+ "use strict";var Ao=Object.defineProperty;var Cs=Object.getOwnPropertyDescriptor;var Es=Object.getOwnPropertyNames;var Ts=Object.prototype.hasOwnProperty;var As=(e,n)=>{for(var t in n)Ao(e,t,{get:n[t],enumerable:!0})},ws=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Es(n))!Ts.call(e,i)&&i!==t&&Ao(e,i,{get:()=>n[i],enumerable:!(o=Cs(n,i))||o.enumerable});return e};var Ms=e=>ws(Ao({},"__esModule",{value:!0}),e);var oc={};As(oc,{PolyAxesHelperElement:()=>xn,PolyBoxElement:()=>Ln,PolyCameraElement:()=>An,PolyConeElement:()=>Bn,PolyCylinderElement:()=>Fn,PolyDirectionalLightHelperElement:()=>vn,PolyDodecahedronElement:()=>In,PolyFirstPersonControlsElement:()=>En,PolyIcosahedronElement:()=>On,PolyIframeElement:()=>yn,PolyMapControlsElement:()=>Cn,PolyMeshElement:()=>wt,PolyOctahedronElement:()=>kn,PolyOrbitControlsElement:()=>Sn,PolyOrthographicCameraElement:()=>Mt,PolyPerspectiveCameraElement:()=>Tn,PolyPlaneElement:()=>_n,PolyPolygonElement:()=>bn,PolyRingElement:()=>Rn,PolySceneElement:()=>Oe,PolySelectElement:()=>Mn,PolySphereElement:()=>Hn,PolyTetrahedronElement:()=>Dn,PolyTorusElement:()=>Vn,PolyTransformControlsElement:()=>wn});module.exports=Ms(oc);var J=require("@layoutit/polycss-core");var dr=require("@layoutit/polycss-core");function Ls(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 tn(e,n,t,o){return(0,dr.packTextureAtlasPlansWithScaleCore)(e,n,Ls(t),o)}var jt=require("@layoutit/polycss-core");var ut=require("@layoutit/polycss-core"),yr=require("@layoutit/polycss-core"),br=require("@layoutit/polycss-core"),Rt=new Map;function _s(e){let n=Rt.get(e);return n||(n=new Promise((t,o)=>{let i=new Image;i.decoding="async",i.crossOrigin="anonymous",i.onload=()=>t(i),i.onerror=()=>o(new Error(`texture load failed: ${e}`)),i.src=e}),Rt.set(e,n),n.then(()=>{Rt.get(e)===n&&Rt.delete(e)},()=>{Rt.get(e)===n&&Rt.delete(e)})),n}function je(e,n,t=1,o=0,i=0,r=1,a=0,c=0){e.setTransform(t*n,o*n,i*n,r*n,a*n,c*n)}function wo(e){let n=e/255;return n<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function Mo(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 Rs(e,n,t,o,i,r,a){let c=Math.round(n*a),l=Math.round(t*a),m=Math.max(1,Math.round(o*a)),g=Math.max(1,Math.round(i*a)),x=e.getImageData(c,l,m,g),f=x.data,b=r.r,h=r.g,S=r.b;for(let v=0;v<f.length;v+=4)f[v+3]!==0&&(f[v]=Mo(wo(f[v])*b),f[v+1]=Mo(wo(f[v+1])*h),f[v+2]=Mo(wo(f[v+2])*S));e.putImageData(x,c,l)}function ks(e,n,t,o,i,r,a){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,m=Math.max(i/c,r/l),g=c*m,x=l*m;je(e,a),e.drawImage(n,t+(i-g)/2,o+(r-x)/2,g,x)}function kt(e,n){return Math.max(0,Math.min(n,e))}function pr(e,n,t,o,i,r,a,c){let l=n.naturalWidth||n.width||1,m=n.naturalHeight||n.height||1,g=kt(Math.min(t.minU,t.maxU)*l,l),x=kt(Math.max(t.minU,t.maxU)*l,l),f=kt(Math.min(t.minV,t.maxV)*m,m),b=kt(Math.max(t.minV,t.maxV)*m,m),h=Math.floor(g),S=Math.floor(f),v=Math.ceil(x)-h,C=Math.ceil(b)-S;v<1&&(h=Math.floor(kt((t.minU+t.maxU)/2*l,l-1)),v=1),C<1&&(S=Math.floor(kt((t.minV+t.maxV)/2*m,m-1)),C=1),h=Math.max(0,Math.min(l-1,h)),S=Math.max(0,Math.min(m-1,S)),v=Math.max(1,Math.min(l-h,v)),C=Math.max(1,Math.min(m-S,C)),je(e,c),e.drawImage(n,h,S,v,C,o,i,r,a)}function xr(e){return e==="repeat"||e==="mirrored-repeat"}function mr(e,n){return xr(e)?Math.floor(n):0}function fr(e,n){return xr(e)?Math.ceil(n)-1:0}function gr(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function hr(e,n,t,o,i,r,a){let c=i?mr(r,i.minU):0,l=i?fr(r,i.maxU):0,m=i?mr(a,i.minV):0,g=i?fr(a,i.maxV):0;for(let x=c;x<=l;x++)for(let f=m;f<=g;f++){let b=gr(r,x),h=gr(a,f);if(!b&&!h){e.drawImage(n,x*t,f*o);continue}e.save(),e.translate((b?x+1:x)*t,(h?f+1:f)*o),e.scale(b?-1:1,h?-1:1),e.drawImage(n,0,0),e.restore()}}function Lo(e,n,t,o){for(let i=0;i<o.length;i+=2){let r=n+o[i],a=t+o[i+1];i===0?e.moveTo(r,a):e.lineTo(r,a)}e.closePath()}function $n(e,n,t,o,i,r){for(let a=0;a<o.length;a+=2){let c=n+o[a]+i,l=t+o[a+1]+r;a===0?e.moveTo(c,l):e.lineTo(c,l)}e.closePath()}function Ds(e,n,t,o){je(e,o),e.beginPath(),Lo(e,n.x,n.y,n.screenPts),e.clip(),je(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function Gn(e,n,t,o,i){n.polygon.textureAlphaMode==="opaque"&&(je(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+i,n.canvasW,n.canvasH))}function Os(e,n,t,o,i=0,r=0){if(n.textureTriangles?.length){let a=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1;for(let l of n.textureTriangles){let m=(0,yr.expandClipPoints)(l.screenPts,ut.TEXTURE_TRIANGLE_BLEED*(n.bleedRatio??1));e.save(),je(e,o),e.beginPath(),$n(e,n.x,n.y,m,i,r),e.clip(),Gn(e,n,o,i,r),l.uvAffine?(je(e,o,l.uvAffine.a/a,l.uvAffine.c/a,l.uvAffine.b/c,l.uvAffine.d/c,n.x+l.uvAffine.e+i,n.y+l.uvAffine.f+r),hr(e,t,a,c,l.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t)):l.uvSampleRect&&pr(e,t,l.uvSampleRect,n.x+i,n.y+r,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let a=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1,l=n.polygon.textureAlphaMode==="opaque";l&&(e.save(),je(e,o),e.beginPath(),$n(e,n.x,n.y,n.screenPts,i,r),e.clip(),Gn(e,n,o,i,r)),je(e,o,n.uvAffine.a/a,n.uvAffine.c/a,n.uvAffine.b/c,n.uvAffine.d/c,n.x+n.uvAffine.e+i,n.y+n.uvAffine.f+r),hr(e,t,a,c,n.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t),l&&e.restore()}else if(n.uvSampleRect){let a=n.polygon.textureAlphaMode==="opaque";a&&(e.save(),je(e,o),e.beginPath(),$n(e,n.x,n.y,n.screenPts,i,r),e.clip(),Gn(e,n,o,i,r)),pr(e,t,n.uvSampleRect,n.x+i,n.y+r,n.canvasW,n.canvasH,o),a&&e.restore()}else{let a=n.polygon.textureAlphaMode==="opaque";a&&(e.save(),je(e,o),e.beginPath(),$n(e,n.x,n.y,n.screenPts,i,r),e.clip(),Gn(e,n,o,i,r)),ks(e,t,n.x+i,n.y+r,n.canvasW,n.canvasH,o),a&&e.restore()}}function Is(e,n,t,o,i,r){let a=i-t,c=r-o,l=a*a+c*c;if(l<=br.BASIS_EPS)return Math.hypot(e-t,n-o);let m=Math.max(0,Math.min(1,((e-t)*a+(n-o)*c)/l));return Math.hypot(e-(t+a*m),n-(o+c*m))}function Hs(e,n,t,o){let i=1/0,r=t.length/2;for(let a of o){if(a<0||a>=r)continue;let c=a*2,l=(a+1)%r*2;i=Math.min(i,Is(e,n,t[c],t[c+1],t[l],t[l+1]))}return i}function Fs(e,n,t,o,i,r){let a=Math.max(0,o-r),c=Math.min(n-1,o+r),l=Math.max(0,i-r),m=Math.min(t-1,i+r),g=null,x=1/0;for(let f=l;f<=m;f++)for(let b=a;b<=c;b++){if(b===o&&f===i)continue;let h=b-o,S=f-i,v=h*h+S*S;if(v>r*r||v>=x)continue;let C=(f*n+b)*4;e[C+3]<ut.TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN||(g=C,x=v)}return g}function Bs(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let i=Math.max(0,Math.floor(n.x*t)),r=Math.max(0,Math.floor(n.y*t)),a=Math.max(1,Math.min(o.width-i,Math.ceil(n.canvasW*t))),c=Math.max(1,Math.min(o.height-r,Math.ceil(n.canvasH*t)));if(a<=0||c<=0)return;let l;try{l=e.getImageData(i,r,a,c)}catch{return}let m=l.data,g=new Uint8ClampedArray(m),x=Math.max(ut.TEXTURE_EDGE_REPAIR_RADIUS,ut.TEXTURE_EDGE_REPAIR_RADIUS/t),f=Math.max(2,Math.ceil(x*t)+1),b=!1;for(let h=0;h<c;h++)for(let S=0;S<a;S++){let v=(h*a+S)*4,C=m[v+3];if(C<ut.TEXTURE_EDGE_REPAIR_ALPHA_MIN||C===255)continue;let R=(i+S+.5)/t-n.x,I=(r+h+.5)/t-n.y;if(Hs(R,I,n.screenPts,n.textureEdgeRepairEdges)>x)continue;let B=Fs(g,a,c,S,h,f);B!==null&&(m[v]=g[B],m[v+1]=g[B+1],m[v+2]=g[B+2],m[v+3]=255,b=!0)}b&&e.putImageData(l,i,r)}function Vs(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 zs(e,n,t,o){let i=t.createElement("canvas");i.width=Math.max(1,Math.ceil(e.width*o)),i.height=Math.max(1,Math.ceil(e.height*o));let r=e.entries.some(g=>g.textureEdgeRepair&&g.texture&&g.textureEdgeRepairEdges&&g.textureEdgeRepairEdges.size>0),a=i.getContext("2d",r?{willReadFrequently:!0}:void 0);if(!a)return{width:e.width,height:e.height,url:null};let c=Array.from(new Set(e.entries.flatMap(g=>g.texture?[g.texture]:[]))),l=new Map;await Promise.all(c.map(async g=>{l.set(g,await _s(g))}));for(let g of e.entries){let x=g.texture?l.get(g.texture):null;if(!g.texture){a.save(),Ds(a,g,n,o),a.restore();continue}x&&(a.save(),je(a,o),a.beginPath(),Lo(a,g.x,g.y,g.screenPts),a.clip(),Os(a,g,x,o),a.restore()),g.texture&&n==="baked"&&(a.save(),je(a,o),a.beginPath(),Lo(a,g.x,g.y,g.screenPts),a.clip(),Rs(a,g.x,g.y,g.canvasW,g.canvasH,g.textureTint,o),a.restore()),Bs(a,g,o)}let m=await Vs(i);return i.width=1,i.height=1,{width:e.width,height:e.height,url:m}}async function nn(e,n,t,o,i){let r=[];for(let a of e){if(i())break;r.push(await zs(a,n,t,o))}return r}var Q=require("@layoutit/polycss-core"),Un=require("@layoutit/polycss-core"),Pr=require("@layoutit/polycss-core");var vr=require("@layoutit/polycss-core");function Dt(e,n){let o=e?.defaultView?.__polycssProjectiveQuadGuards,i=n&&o?{...n,...o}:o??n;return(0,vr.resolveProjectiveQuadGuards)(i)}function on(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 i=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return i?i("(pointer: fine)").matches&&i("(hover: hover)").matches:!0}function Sr(e){if(Cr(e))return!0;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,Q.safariCssProjectiveUnsupported)(t):!0}function rn(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 Cr(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 Ns(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function nt(e,n){return n?.disable?.includes("u")?null:Cr(e)?"corner-bevel":Sr(e)?Ns(e)?"border-large":"border":null}function sn(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,Q.safariCssProjectiveUnsupported)(t):!0}function Wn(e,n,t,o,i){let r=new Set(o?.disable??[]);return(0,Q.getSolidPaintDefaultsForPlansCore)(e,n,r,{solidTriangleSupported:Sr(t),projectiveQuadSupported:sn(t),cornerShapeSupported:rn(t),borderShapeSupported:on(t)},Un.parseHex,Un.rgbKey,i)}var Me=require("@layoutit/polycss-core"),ke=require("@layoutit/polycss-core");var Vt=require("@layoutit/polycss-core");var Ce=require("@layoutit/polycss-core"),Er=require("@layoutit/polycss-core");var Ot=require("@layoutit/polycss-core");function we(e,n,t){let o=e.getAttribute("style")??"",i=`${n}:${t}`,r=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(`(^|;)\\s*${r}\\s*:[^;]*`,"i"),c=a.test(o)?o.replace(a,(l,m)=>`${m}${i}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${i}`;c!==o&&e.setAttribute("style",c)}function ht(e,n){let t=e.getAttribute("style")??"";if(!t||!t.toLowerCase().includes(n.toLowerCase()))return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`^\\s*${o}\\s*:`,"i"),r=t.split(";").map(a=>a.trim()).filter(a=>a&&!i.test(a)).join(";");r?e.setAttribute("style",r):e.removeAttribute("style")}function an(e,n,t,o=!1){if(n==="dynamic"){let i=(0,Ot.parseHex)(e.polygon.color??"#cccccc"),r=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return(0,Ot.rgbKey)(i)!==t?.dynamicColorKey&&(r+=`;--psr:${(i.r/255).toFixed(4)};--psg:${(i.g/255).toFixed(4)};--psb:${(i.b/255).toFixed(4)}`),r}return e.shadedColor?`;color:${e.shadedColor}`:""}function js(e,n){we(e,"--pnx",n.normal[0].toFixed(4)),we(e,"--pny",n.normal[1].toFixed(4)),we(e,"--pnz",n.normal[2].toFixed(4))}function It(e,n,t,o){if(t==="dynamic"){ht(e,"color"),ht(e,"background"),js(e,n);let i=(0,Ot.parseHex)(n.polygon.color??"#cccccc");(0,Ot.rgbKey)(i)===o?.dynamicColorKey?(ht(e,"--psr"),ht(e,"--psg"),ht(e,"--psb")):(we(e,"--psr",(i.r/255).toFixed(4)),we(e,"--psg",(i.g/255).toFixed(4)),we(e,"--psb",(i.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(ht(e,"background"),we(e,"color",n.shadedColor)):(ht(e,"background"),ht(e,"color"))}var Ht=require("@layoutit/polycss-core"),un=require("@layoutit/polycss-core"),Xn=require("@layoutit/polycss-core"),lt=require("@layoutit/polycss-core"),Tr="polycss-corner-shape-solid";function ln(e){return e.atlasLeafWidth??(0,un.atlasCanonicalSizeForEntry)(e)}function cn(e){return e.atlasLeafHeight??(0,un.atlasCanonicalSizeForEntry)(e)}function Ar(e,n){return(0,Ce.resolvePolyTextureImageRendering)(e.polygon,n)}function Yn(e){return e==="pixelated"?";image-rendering:pixelated":""}function ko(e,n,t,o,i,r,a,c,l){e.setAttribute("data-polycss-leaf","polygon"),e.setAttribute("data-polycss-texture-backend",n),e.setAttribute("data-polycss-texture-ready",t?"true":"false"),e.setAttribute("data-polycss-texture-image-rendering",o),i?e.setAttribute("data-polycss-texture-leaf-sizing",i):e.removeAttribute("data-polycss-texture-leaf-sizing"),r?e.setAttribute("data-polycss-texture-projection",r):e.removeAttribute("data-polycss-texture-projection"),a?e.setAttribute("data-polycss-texture-lighting",a):e.removeAttribute("data-polycss-texture-lighting"),typeof c=="number"?e.setAttribute("data-polycss-texture-leaf-width",String(c)):e.removeAttribute("data-polycss-texture-leaf-width"),typeof l=="number"?e.setAttribute("data-polycss-texture-leaf-height",String(l)):e.removeAttribute("data-polycss-texture-leaf-height")}var _o=new WeakMap,Ro=new WeakMap;function Ae(e,n,t){let o=_o.get(e),i=Ro.get(e),r=typeof t=="number";if(!n.data&&!r&&(!o||o.length===0)){e.__polycssHasDataAttrs=!1;return}let a=new Map;if(n.data)for(let[l,m]of Object.entries(n.data))a.set(l,String(m));if(n.doubleSided===!0&&a.set("polycss-double-sided","true"),r&&a.set("poly-index",String(t)),o)for(let l of o)a.has(l)||e.removeAttribute(`data-${l}`);for(let[l,m]of a)i?.get(l)!==m&&e.setAttribute(`data-${l}`,m);let c=Array.from(a.keys());c.length>0?_o.set(e,c):_o.delete(e),a.size>0?Ro.set(e,a):Ro.delete(e),e.__polycssHasDataAttrs=c.length>0}function Ft(e){return e.__polycssHasDataAttrs===!0}function Do(e,n,t,o,i=t==="dynamic",r){if(!n.url)return;let a=Ar(o,r),c=`url(${n.url})`,l=o.canvasW||1,m=o.canvasH||1,g=(0,un.atlasCanonicalSizeForEntry)(o),x=ln(o),f=cn(o),b=`${(0,Ce.formatCssLength)(-o.x/l*x)} ${(0,Ce.formatCssLength)(-o.y/m*f)}`,h=`${(0,Ce.formatCssLength)(n.width/l*x)} ${(0,Ce.formatCssLength)(n.height/m*f)}`,S=`transform:matrix3d(${o.atlasMatrix});--polycss-atlas-size:${g}px;--polycss-atlas-width:${(0,Ce.formatCssLength)(x)};--polycss-atlas-height:${(0,Ce.formatCssLength)(f)};--polycss-atlas-leaf-sizing:${o.atlasLeafSizing??"canonical"}`,v=`${S};--polycss-atlas-position:${b};--polycss-atlas-image-size:${h}`;if(t==="dynamic"){let C=i?`;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`:"";e.setAttribute("style",v+`;--polycss-atlas-url:${c}`+C+Yn(a))}else e.setAttribute("style",S+`;background-image:${c};background-position:${b};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)}`+Yn(a));ko(e,"atlas",!0,a,o.atlasLeafSizing??"canonical","affine",t,x,f)}function wr(e,n,t,o){if(n.texture){if(!t.texture||n.texture!==t.texture)return!1}else if(t.texture)return!1;let i=Mr(n,t);return i?(e.style.visibility="",we(e,"transform",`matrix3d(${i.matrix})`),o==="dynamic"&&(we(e,"--pnx",i.normal[0].toFixed(4)),we(e,"--pny",i.normal[1].toFixed(4)),we(e,"--pnz",i.normal[2].toFixed(4))),Ae(e,t,n.index),!0):(e.style.visibility="hidden",Ae(e,t,n.index),!0)}function Oo(e,n,t,o,i){if(o!=="baked")return{...e,polygon:n,normal:t};let r=i.directionalLight,a=i.ambientLight,c=r?.direction??lt.DEFAULT_LIGHT_DIR,l=r?.color??lt.DEFAULT_LIGHT_COLOR,m=Math.max(0,r?.intensity??lt.DEFAULT_LIGHT_INTENSITY),g=a?.color??lt.DEFAULT_AMBIENT_COLOR,x=Math.max(0,a?.intensity??lt.DEFAULT_AMBIENT_INTENSITY),f=Math.hypot(c[0],c[1],c[2])||1,b=c[0]/f,h=c[1]/f,S=c[2]/f,C=i.lightOccludedPolyIndices?.has(e.index)??!1?0:m*Math.max(0,t[0]*b+t[1]*h+t[2]*S);return{...e,polygon:n,normal:t,shadedColor:(0,Er.shadePolygon)(n.color??"#cccccc",C,l,g,x)}}function Mr(e,n){let t=Lr(e,n);if(!t)return null;let{normal:o,xAxis:i,yAxis:r,tx:a,ty:c,tz:l}=t;return{normal:o,matrix:(0,Ce.formatMatrix3dValues)([i[0]*e.canvasW/ln(e),i[1]*e.canvasW/ln(e),i[2]*e.canvasW/ln(e),0,r[0]*e.canvasH/cn(e),r[1]*e.canvasH/cn(e),r[2]*e.canvasH/cn(e),0,o[0],o[1],o[2],0,a,c,l,1])}}var Lr=Xn.stableBasisFromPlan;function $s(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=Lr(e,n);if(!o)return null;let i=(0,Xn.computeProjectiveQuadMatrix)(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return i?{matrix:i,normal:o.normal}:null}function Io(e,n,t,o,i=!1){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${(0,Ce.formatSolidQuadMatrix)(e)})`+an(e,n,o,i)),Ae(r,e.polygon,e.index),r}function Ho(e,n,t,o,i=!1){let r=t.createElement("i");return r.setAttribute("style",(0,Ht.formatBorderShapeElementStyle)(e)+an(e,n,o,i)),Ae(r,e.polygon,e.index),r}function Fo(e,n,t,o,i,r=!1){let a=o.createElement("u");return a.className=Tr,a.setAttribute("style",(0,Ht.formatCornerShapeElementStyle)(e,n)+an(e,t,i,r)),Ae(a,e.polygon,e.index),a}function Bo(e,n,t,o,i=!1){let r=t.createElement("b");return r.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+an(e,n,o,i)),Ae(r,e.polygon,e.index),r}function _r(e,n,t,o,i,r,a){let c=n.projectiveMatrix?$s(n,t,r):Mr(n,t);if(!c)return!1;let l=Oo(n,t,c.normal,o,i);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,It(e,l,o,a),Ae(e,l.polygon,l.index),!0}function Rr(e,n,t,o){e.style.visibility="",e.setAttribute("style",(0,Ht.formatBorderShapeElementStyle)(n)),It(e,n,t,o),Ae(e,n.polygon,n.index)}function kr(e,n,t,o,i){e.style.visibility="",e.className=Tr,e.setAttribute("style",(0,Ht.formatCornerShapeElementStyle)(n,t)),It(e,n,o,i),we(e,"background","currentColor"),Ae(e,n.polygon,n.index)}function Vo(e,n,t,o=!1,i){let r=t.createElement("s"),a=Ar(e,i),c=(0,un.atlasCanonicalSizeForEntry)(e),l=ln(e),m=cn(e),g=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:${c}px;--polycss-atlas-width:${(0,Ce.formatCssLength)(l)};--polycss-atlas-height:${(0,Ce.formatCssLength)(m)};--polycss-atlas-leaf-sizing:${e.atlasLeafSizing??"canonical"};opacity:0`+g+Yn(a)),ko(r,"atlas",!1,a,e.atlasLeafSizing??"canonical","affine",n,l,m),Ae(r,e.polygon,e.index),r}function zo(e,n,t,o=!1){let i=t.createElement("s"),r=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return i.setAttribute("style",`transform:matrix3d(${n.matrix});--polycss-atlas-width:${(0,Ce.formatCssLength)(n.leafWidth)};--polycss-atlas-height:${(0,Ce.formatCssLength)(n.leafHeight)};--polycss-atlas-leaf-sizing:image;background-image:url(${n.url});background-position:${(0,Ce.formatCssLength)(n.backgroundPosition[0])} ${(0,Ce.formatCssLength)(n.backgroundPosition[1])};background-size:${(0,Ce.formatCssLength)(n.backgroundSize[0])} ${(0,Ce.formatCssLength)(n.backgroundSize[1])};background-repeat:no-repeat;background-blend-mode:normal;mask-image:none;-webkit-mask-image:none`+r+Yn(n.imageRendering)),ko(i,"image",!0,n.imageRendering,"image",n.projection,n.lighting,n.leafWidth,n.leafHeight),i.setAttribute("data-polycss-texture-source-x",String(n.sourceRect.x)),i.setAttribute("data-polycss-texture-source-y",String(n.sourceRect.y)),i.setAttribute("data-polycss-texture-source-width",String(n.sourceRect.width)),i.setAttribute("data-polycss-texture-source-height",String(n.sourceRect.height)),Ae(i,e.polygon,e.index),i}var zr=require("@layoutit/polycss-core");var Zn=require("@layoutit/polycss-core");function Ct(e,n,t,o={}){let i=o.primitive!=null?void 0:(()=>{let r=t.doc??(typeof document<"u"?document:null);return r?nt(r,t.strategies)??"border":"border"})();return(0,Zn.computeSolidTrianglePlan)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??i})}function No(e,n,t,o,i,r,a,c,l,m,g,x,f){let b=o.primitive!=null?void 0:(()=>{let h=t.doc??(typeof document<"u"?document:null);return h?nt(h,t.strategies)??"border":"border"})();return(0,Zn.computeSolidTrianglePlanFromCssPoints)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??b},i,r,a,c,l,m,g,x,f)}var Et=require("@layoutit/polycss-core"),yt=require("@layoutit/polycss-core"),Dr=require("@layoutit/polycss-core");var jo=require("@layoutit/polycss-core");var Gs="0 48px 96px 48px";function Or(e,n){return(0,Et.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function Ir(e,n,t){let o=(0,Et.resolveBleedRatio)(t.seamBleed),i=Et.DEFAULT_SEAM_BLEED*o,r={...t,bleedRatio:o};return n&&i>0?{...r,seamBleed:n.has(e)?i:void 0,seamEdges:n.get(e)}:r}function $o(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 Hr(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function Bt(e,n,t,o,i,r){return t?r.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:i==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:Hr(n,r):!0}function Go(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"?Gs:""),t.__polycssSolidTrianglePrimitive=n)}function Uo(e){let n=e;n.__polycssSolidTriangleHidden&&(e.style.visibility="",n.__polycssSolidTriangleHidden=!1)}function dn(e){let n=e;n.__polycssSolidTriangleHidden||(e.style.visibility="hidden",n.__polycssSolidTriangleHidden=!0)}function Qn(e,n){e.setAttribute("style",n.styleText),Go(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||Ft(e))&&Ae(e,n.polygon)}function Fr(e,n,t,o){if(!n.colorComputed){(n.polygon.data||Ft(e))&&Ae(e,n.polygon);return}let i=e,r=n.bakedColor??"",a=n.bakedRgb,c=n.bakedAlpha??1,l=i.__polycssSolidTriangleColor,m=i.__polycssSolidTriangleColorRgb,g=i.__polycssSolidTriangleColorAlpha??1,x=o??Hr(n.index,t);if(!t.updatesDisabled&&l!==r&&(l===void 0||x)){let f=r,b=a;if(t.maxStep>0&&m&&a&&g===c){let h=(0,yt.stepRgbToward)(m,a,t.maxStep);b=h,f=(0,yt.rgbToCss)(h,c)}(f!==l||!(0,yt.rgbEqual)(b,m))&&(e.style.color=f),i.__polycssSolidTriangleColor=f,i.__polycssSolidTriangleColorRgb=b,i.__polycssSolidTriangleColorAlpha=c,i.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||Ft(e))&&Ae(e,n.polygon)}function qn(e,n,t,o){let i=e;Go(e,n.primitive),i.__polycssSolidTriangleBasis!==n.basis&&(i.__polycssSolidTriangleBasis=n.basis),Uo(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||Ft(e))&&Fr(e,n,t,o)}function Wo(e,n,t,o){Uo(e),Fr(e,n,t,o)}function Kn(e,n){let t=e;Go(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),Uo(e),e.style.transform=n.transformText,(n.polygon.data||Ft(e))&&Ae(e,n.polygon)}function Us(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 Br(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)),i=Math.max(1,Math.floor(t.stableTriangleColorFreezeFrames??1));if(i<=1&&!Number.isFinite(t.stableTriangleColorBudget))return null;let r=Us(e.length,t),a=Math.max(1,Math.floor(t.stableTriangleColorMaxAge??Math.max(2,i*2))),c=[];for(let l=0;l<e.length;l++){let m=e[l],g=n[l];if(m.kind!=="triangle"||!g)continue;let x=m.element,f=x.__polycssSolidTriangleColor,b=g.bakedColor??"";if(f===b)continue;let h=x.__polycssSolidTriangleColorFrame??0,S=Math.max(0,o-h),v=(0,yt.colorErrorScore)(f,b);c.push({index:l,score:(S>=a?1e6:0)+v*1e4+S})}return c.length===0?new Set:(c.sort((l,m)=>m.score-l.score),new Set(c.slice(0,r).map(l=>l.index)))}function Jn(e,n){let t=n.createElement("u");return Qn(t,e),Ae(t,e.polygon,e.index),t}function Ws(e,n,t){let o=t.createElement("u");return dn(o),Ae(o,e,n),o}function Vr(e,n,t,o,i,r){let a=t,c=a.stableTriangleDebug,l=o&&i==="color-only";if(a.stableTriangleColorPolicy==="adaptive"||e.length!==n.length)return!1;let m=(0,jo.stableTriangleMatrixDecimals)(a.stableTriangleMatrixDecimals),g=t.doc??(typeof document<"u"?document:null),x=g?nt(g,t.strategies)??"border":"border";for(let b=0;b<e.length;b++){let h=e[b];if(h.kind!=="triangle"||h.polygonIndex!==b||!n[b])return!1}let f=Or(n,t);for(let b=0;b<e.length;b++){let h=e[b].element,S=n[b];if(l){if(Bt(h,b,o,c,a.stableTriangleColorPolicy,r)){let C=(0,Dr.computeSolidTriangleColorPlan)(S,b,t);if(!C)continue;Wo(h,C,r)}continue}let v=Ct(S,b,Ir(b,f,t),{basis:h.__polycssSolidTriangleBasis,matrixDecimals:m,primitive:x,includeColor:i!=="plan-only"&&i!=="transform-only"&&Bt(h,b,o,c,a.stableTriangleColorPolicy,r)});if(!v){dn(h);continue}o&&i==="plan-only"||(o&&i==="transform-only"?Kn(h,v):o?qn(h,v,r):Qn(h,v))}return!0}function pn(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=nt(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let i=(0,jo.stableTriangleMatrixDecimals)(n.stableTriangleMatrixDecimals),r=[],a=Or(e,n);for(let c=0;c<e.length;c+=1){let l=e[c],m=Ct(l,c,Ir(c,a,n),{matrixDecimals:i,primitive:o}),g=m?Jn(m,t):Ws(l,c,t);r.push({polygonIndex:c,element:g,kind:"triangle",dispose:()=>{}})}return{rendered:r,dispose(){}}}var Xo=require("@layoutit/polycss-core");function Nr(){return new Promise(e=>setTimeout(e,0))}async function Yo(e){return performance.now()-e<Me.ASYNC_RENDER_BUDGET_MS?e:(await Nr(),performance.now())}function jr(e,n){let t=(0,Me.resolveBleedRatio)(n.seamBleed),o=Me.DEFAULT_SEAM_BLEED*t,i={...n,bleedRatio:t};return e.seamBleedEdges?.size&&o>0?{...i,seamBleed:o,seamEdges:e.seamBleedEdges}:{...i,seamBleed:void 0,seamEdges:void 0}}function $r(e,n){return(0,ke.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function Gr(e,n,t){let o=(0,Me.resolveBleedRatio)(t.seamBleed),i=Me.DEFAULT_SEAM_BLEED*o,r={...t,bleedRatio:o};return n&&i>0?{...r,seamBleed:n.has(e)?i:void 0,seamEdges:n.get(e)}:r}function zt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=(0,ke.buildBasisHints)(e,n),i=Dt(t),r=e.map((a,c)=>(0,ke.computeTextureAtlasPlan)(a,c,n,i,o[c]));return Wn(r,n.textureLighting??"baked",t,n.strategies)}function Nt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",i=n,r=o==="dynamic"&&i.skipDynamicNormalVars===!0,a=new Set(n.strategies?.disable??[]),c=!a.has("b"),l=c&&sn(t),m=nt(t,n.strategies),g=m!==null,x=!a.has("i")&&rn(t),f=!a.has("i")&&on(t),b=(0,ke.buildBasisHints)(e,n),h=Dt(t),S=$r(e,n),v=e.map((u,d)=>(0,ke.computeTextureAtlasPlan)(u,d,Gr(d,S,n),h,b[d])),C=n.solidPaintDefaults??(i.computeSolidPaintDefaults?Wn(v,o,t,n.strategies):void 0),R=C?{...n,solidPaintDefaults:C}:n,I=v.map(u=>u&&g&&(0,Q.isSolidTrianglePlan)(u)?Ct(u.polygon,u.index,jr(u,R),{primitive:m??void 0}):null),B=v.map(u=>u&&x&&!(0,Q.isSolidTrianglePlan)(u)&&!(c&&(0,Q.isFullRectSolid)(u))&&!(l&&(0,Q.isProjectiveQuadPlan)(u))?(0,Vt.cornerShapeGeometryForPlan)(u):null),O=v.map(u=>u?(0,ke.resolvePolyTextureLeafGeometry)(u,{imageRendering:n.textureImageRendering,backend:n.textureBackend,projection:n.textureProjection,allowProjective:l,projectiveQuadGuards:h}):null),X=v.map((u,d)=>O[d]?null:u&&(u.texture||!(c&&(0,Q.isFullRectSolid)(u))&&!I[d]&&!(l&&(0,Q.isProjectiveQuadPlan)(u))&&!B[d]&&!f?u:null)),{packed:Z,atlasScale:M}=tn(X,n.textureQuality,t,n.textureLeafSizing),z=new Map,V=[],F=!1,ae=[];for(let u=0;u<e.length;u++){let d=v[u],A=I[u],_=B[u],N=O[u];if(!d)continue;let Y=Z.entries[u];if(Y){let w=Vo(Y,o,t,r,n.textureImageRendering);z.set(u,w),V.push({polygonIndex:u,element:w,kind:"atlas",plan:Y,dispose:()=>{}})}else if(N){let w=zo(d,N,t,r);V.push({polygonIndex:u,element:w,kind:"image",plan:d,dispose:()=>{}})}else if(!d.texture&&c&&(0,Q.isFullRectSolid)(d)){let w=Io(d,o,t,C,r);V.push({polygonIndex:u,element:w,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&A){let w=Jn(A,t);V.push({polygonIndex:u,element:w,kind:"triangle",plan:d,dispose:()=>{}})}else if(!d.texture&&l&&(0,Q.isProjectiveQuadPlan)(d)){let w=Bo(d,o,t,C,r);V.push({polygonIndex:u,element:w,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&_){let w=Fo(d,_,o,t,C,r);V.push({polygonIndex:u,element:w,kind:"corner",plan:d,dispose:()=>{}})}else if(!d.texture&&f){let w=Ho(d,o,t,C,r);V.push({polygonIndex:u,element:w,kind:"border",plan:d,dispose:()=>{}})}}V.sort((u,d)=>u.polygonIndex-d.polygonIndex);let y=nn(Z.pages,o,t,M,()=>F).then(u=>{if(F){for(let d of u)d.url?.startsWith("blob:")&&URL.revokeObjectURL(d.url);return}ae=u.flatMap(d=>d.url?.startsWith("blob:")?[d.url]:[]);for(let d=0;d<Z.pages.length;d++){let A=Z.pages[d],_=u[d];if(_)for(let N of A.entries){let Y=z.get(N.index);!Y||!_.url||Do(Y,_,o,N,!0,n.textureImageRendering)}}}).catch(()=>{if(!F)for(let u of z.values())we(u,"opacity","0.5"),we(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:V,solidPaintDefaults:C??{},pagesReady:y,dispose(){F=!0;for(let u of ae)URL.revokeObjectURL(u);ae=[]}}}async function eo(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let i=n.textureLighting??"baked",a=i==="dynamic"&&n.skipDynamicNormalVars===!0,c=new Set(n.strategies?.disable??[]),l=!c.has("b"),m=l&&sn(o),g=nt(o,n.strategies),x=g!==null,f=!c.has("i")&&rn(o),b=!c.has("i")&&on(o);if(await Nr(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let h=(0,ke.buildBasisHints)(e,n),S=Dt(o),v=$r(e,n),C=performance.now(),R=new Array(e.length);for(let u=0;u<e.length;u++)if(R[u]=(0,ke.computeTextureAtlasPlan)(e[u],u,Gr(u,v,n),S,h[u]),C=await Yo(C),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let I=n.solidPaintDefaults??Wn(R,i,o,n.strategies),B=new Array(R.length),O=new Array(R.length),X=new Array(R.length),Z=new Array(R.length);for(let u=0;u<R.length;u++){let d=R[u],A=d&&x&&(0,Q.isSolidTrianglePlan)(d)?Ct(d.polygon,d.index,jr(d,{...n,solidPaintDefaults:I}),{primitive:g??void 0}):null;B[u]=A;let _=d&&f&&!(0,Q.isSolidTrianglePlan)(d)&&!(l&&(0,Q.isFullRectSolid)(d))&&!(m&&(0,Q.isProjectiveQuadPlan)(d))?(0,Vt.cornerShapeGeometryForPlan)(d):null;O[u]=_;let N=d?(0,ke.resolvePolyTextureLeafGeometry)(d,{imageRendering:n.textureImageRendering,backend:n.textureBackend,projection:n.textureProjection,allowProjective:m,projectiveQuadGuards:S}):null;if(X[u]=N,Z[u]=N?null:d&&(d.texture||!(l&&(0,Q.isFullRectSolid)(d))&&!A&&!(m&&(0,Q.isProjectiveQuadPlan)(d))&&!_&&!b?d:null),C=await Yo(C),t())return{rendered:[],solidPaintDefaults:I,dispose:()=>{}}}let{packed:M,atlasScale:z}=tn(Z,n.textureQuality,o,n.textureLeafSizing),V=new Map,F=[],ae=!1,y=[];for(let u=0;u<e.length;u++){let d=R[u],A=B[u],_=O[u],N=X[u];if(!d)continue;let Y=M.entries[u];if(Y){let w=Vo(Y,i,o,a,n.textureImageRendering);V.set(u,w),F.push({polygonIndex:u,element:w,kind:"atlas",plan:Y,dispose:()=>{}})}else if(N){let w=zo(d,N,o,a);F.push({polygonIndex:u,element:w,kind:"image",plan:d,dispose:()=>{}})}else if(!d.texture&&l&&(0,Q.isFullRectSolid)(d)){let w=Io(d,i,o,I,a);F.push({polygonIndex:u,element:w,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&A){let w=Jn(A,o);F.push({polygonIndex:u,element:w,kind:"triangle",plan:d,dispose:()=>{}})}else if(!d.texture&&m&&(0,Q.isProjectiveQuadPlan)(d)){let w=Bo(d,i,o,I,a);F.push({polygonIndex:u,element:w,kind:"solid",plan:d,dispose:()=>{}})}else if(!d.texture&&_){let w=Fo(d,_,i,o,I,a);F.push({polygonIndex:u,element:w,kind:"corner",plan:d,dispose:()=>{}})}else if(!d.texture&&b){let w=Ho(d,i,o,I,a);F.push({polygonIndex:u,element:w,kind:"border",plan:d,dispose:()=>{}})}if(C=await Yo(C),t()){for(let w of F)w.dispose();return{rendered:[],solidPaintDefaults:I,dispose:()=>{}}}}F.sort((u,d)=>u.polygonIndex-d.polygonIndex);let L=nn(M.pages,i,o,z,()=>ae||t()).then(u=>{if(ae||t()){for(let d of u)d.url?.startsWith("blob:")&&URL.revokeObjectURL(d.url);return}y=u.flatMap(d=>d.url?.startsWith("blob:")?[d.url]:[]);for(let d=0;d<M.pages.length;d++){let A=M.pages[d],_=u[d];if(_)for(let N of A.entries){let Y=V.get(N.index);!Y||!_.url||Do(Y,_,i,N,!0,n.textureImageRendering)}}}).catch(()=>{if(!(ae||t()))for(let u of V.values())we(u,"opacity","0.5"),we(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:F,solidPaintDefaults:I,pagesReady:L,dispose(){ae=!0;for(let u of y)URL.revokeObjectURL(u);y=[]}}}function to(e,n,t,o={}){let i=o.textureLighting??"baked",r=o,a=r.optimizeStableTriangleStyle===!0&&i==="baked";if(!a||r.stableTriangleColorPolicy==="adaptive"||e.length!==t.polygonCount||n.length!==t.polygonCount||t.vertices.length<t.polygonCount*9)return!1;let c=r.stableTriangleDebug,l=r.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full");if(l==="color-only")return!1;let m=(0,Xo.stableTriangleMatrixDecimals)(r.stableTriangleMatrixDecimals),g=$o(r),x=o.tileSize??Me.DEFAULT_TILE,f=o.layerElevation??x,b=o.doc??(typeof document<"u"?document:null),h=b?nt(b,o.strategies)??"border":"border";for(let v=0;v<e.length;v++){let C=e[v],R=n[v];if(C.kind!=="triangle"||C.polygonIndex!==v||!R||R.vertices.length!==3||R.texture||R.material?.texture)return!1}let S=t.vertices;for(let v=0;v<e.length;v++){let C=e[v].element,R=n[v],I=v*9,B=S[I+1]*x,O=S[I]*x,X=S[I+2]*f,Z=S[I+4]*x,M=S[I+3]*x,z=S[I+5]*f,V=S[I+7]*x,F=S[I+6]*x,ae=S[I+8]*f,y=No(R,v,o,{basis:C.__polycssSolidTriangleBasis,matrixDecimals:m,primitive:h,color:t.colors?.[v],includeColor:l!=="plan-only"&&l!=="transform-only"&&Bt(C,v,a,c,r.stableTriangleColorPolicy,g)},B,O,X,Z,M,z,V,F,ae);if(!y){dn(C);continue}l!=="plan-only"&&(l==="transform-only"?Kn(C,y):qn(C,y,g))}return!0}function no(e,n,t={}){if(e.length!==n.length)return!1;let o=t,i=t.doc??(typeof document<"u"?document:null),r=t.textureLighting??"baked",a=new Set(t.strategies?.disable??[]),c=!a.has("b"),l=!!i&&c&&sn(i),m=!!i&&!a.has("i")&&rn(i),g=!!i&&!a.has("i")&&on(i),x=(0,Me.resolveBleedRatio)(o.seamBleed),f=i?Dt(i,{bleed:Me.PROJECTIVE_QUAD_BLEED*x}):{denomEps:Me.PROJECTIVE_QUAD_DENOM_EPS,maxWeightRatio:Me.PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,bleed:Me.PROJECTIVE_QUAD_BLEED*x,disableGuards:!1},b=o.optimizeStableTriangleStyle===!0&&r==="baked",h=o.stableTriangleDebug,S=o.stableTriangleUpdateMode??(h==="plan-only"||h==="transform-only"?h:"full"),v=b&&S==="color-only",C=$o(o),R=(0,Xo.stableTriangleMatrixDecimals)(o.stableTriangleMatrixDecimals),I=i?nt(i,t.strategies)??"border":"border";if(Vr(e,n,t,b,S,C))return!0;let B=[],O=[],X=[];for(let M=0;M<e.length;M++){let z=e[M];if(z.polygonIndex!==M)return!1;let V=n[M];if(!V||v&&z.kind!=="triangle")return!1;if(z.kind==="atlas"){if(!z.plan||!wr(z.element,z.plan,V,r))return!1;continue}if(z.kind==="triangle"){let F=z.element;if(v){let y=o.stableTriangleColorPolicy==="adaptive"||Bt(F,M,b,h,o.stableTriangleColorPolicy,C);O[M]=y?(0,zr.computeSolidTriangleColorPlan)(V,M,t):null;continue}let ae=Ct(V,M,t,{basis:F.__polycssSolidTriangleBasis,matrixDecimals:R,primitive:I,includeColor:S!=="plan-only"&&S!=="transform-only"&&Bt(F,M,b,h,o.stableTriangleColorPolicy,C)});if(!ae){B[M]=null;continue}B[M]=ae;continue}if(z.kind==="solid"){if(!z.plan||V.texture||V.vertices.length!==z.plan.polygon.vertices.length)return!1;X[M]=z.plan;continue}if(z.kind==="border"){let F=(0,ke.computeTextureAtlasPlan)(V,M,t,f);if(!F||F.texture||!g||c&&(0,Q.isFullRectSolid)(F)||l&&(0,Q.isProjectiveQuadPlan)(F)||m&&(0,Vt.cornerShapeGeometryForPlan)(F))return!1;X[M]=F;continue}if(z.kind==="corner"){let F=(0,ke.computeTextureAtlasPlan)(V,M,t,f);if(!F||F.texture||!m||(0,Q.isSolidTrianglePlan)(F)||c&&(0,Q.isFullRectSolid)(F)||l&&(0,Q.isProjectiveQuadPlan)(F)||!(0,Vt.cornerShapeGeometryForPlan)(F))return!1;X[M]=F;continue}return!1}let Z=b&&S!=="plan-only"&&S!=="transform-only"?Br(e,v?O:B,o):null;for(let M=0;M<e.length;M++){let z=e[M];if(z.kind==="triangle"){if(v){let F=O[M];F&&Wo(z.element,F,C,Z?.has(M));continue}let V=B[M];if(!V){dn(z.element);continue}if(b&&S==="plan-only")continue;b&&S==="transform-only"?Kn(z.element,V):b?qn(z.element,V,C,Z?.has(M)):Qn(z.element,V)}else if(z.kind==="solid"){let V=X[M];if(!V||!_r(z.element,V,n[M],r,t,f,o.solidPaintDefaults))return!1}else if(z.kind==="border"){let V=X[M];if(!V)return!1;Rr(z.element,V,r,o.solidPaintDefaults)}else if(z.kind==="corner"){let V=X[M],F=V?(0,Vt.cornerShapeGeometryForPlan)(V):null;if(!V||!F)return!1;kr(z.element,V,F,r,o.solidPaintDefaults)}}return!0}var Ur=require("@layoutit/polycss-core"),$t=require("@layoutit/polycss-core"),oo=require("@layoutit/polycss-core");var re=require("@layoutit/polycss-core"),Ks=[.4,-.7,.59],Js="#ffffff",ea=1,ta="#ffffff",na=.4,qr=1,oa=8,ra=re.PROJECTIVE_QUAD_BLEED,dt=1e-6,ia=(0,re.resolveProjectiveQuadGuards)({bleed:0}),Kr={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},qo=["t","b","bl","br","fr","fl"],sa=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 Wr(e){let n=[];for(let t of qo)(0,re.normalFacesCamera)(Kr[t],e)&&n.push(t);return n.join("|")}function aa(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 la(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,i=0,r=0;for(let c=1;c+1<n.length;c+=1){let l=n[c],m=n[c+1],g=l[1]-t[1],x=l[0]-t[0],f=l[2]-t[2],b=m[1]-t[1],h=m[0]-t[0],S=m[2]-t[2];o-=x*S-f*h,i-=f*b-g*S,r-=g*h-x*b}let a=Math.hypot(o,i,r);return a<=1e-9?null:[Math.round(o/a),Math.round(i/a),Math.round(r/a)]}function ca(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=la(e),t=n?sa.get(n.join(",")):void 0;if(!t)return null;let o=1/0,i=1/0,r=1/0,a=-1/0,c=-1/0,l=-1/0;for(let x of e.vertices)o=Math.min(o,x[0]),i=Math.min(i,x[1]),r=Math.min(r,x[2]),a=Math.max(a,x[0]),c=Math.max(c,x[1]),l=Math.max(l,x[2]);let m=1e-6,g=ha(e.color);return Math.abs(l-r)<=m?{axis:"z",face:t,left:i*re.BASE_TILE,top:o*re.BASE_TILE,width:Math.max(0,(c-i)*re.BASE_TILE),height:Math.max(0,(a-o)*re.BASE_TILE),z:r*re.BASE_TILE,baseColor:g,bleed:Zo()}:Math.abs(a-o)<=m?{axis:"x",face:t,left:i*re.BASE_TILE,top:r*re.BASE_TILE,width:Math.max(0,(c-i)*re.BASE_TILE),height:Math.max(0,(l-r)*re.BASE_TILE),z:-o*re.BASE_TILE,baseColor:g,bleed:Zo()}:Math.abs(c-i)<=m?{axis:"y",face:t,left:r*re.BASE_TILE,top:o*re.BASE_TILE,width:Math.max(0,(l-r)*re.BASE_TILE),height:Math.max(0,(a-o)*re.BASE_TILE),z:-i*re.BASE_TILE,baseColor:g,bleed:Zo()}:null}function Zo(){return{left:0,right:0,top:0,bottom:0}}function ua(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 Yr(e){return[e[1]*re.BASE_TILE,e[0]*re.BASE_TILE,e[2]*re.BASE_TILE]}function Xr(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function da(e,n,t){let o=e.left,i=e.left+e.width,r=e.top,a=e.top+e.height;if(Math.abs(n[0]-t[0])<=dt){if(Math.abs(n[0]-o)<=dt)return"left";if(Math.abs(n[0]-i)<=dt)return"right"}if(Math.abs(n[1]-t[1])<=dt){if(Math.abs(n[1]-r)<=dt)return"top";if(Math.abs(n[1]-a)<=dt)return"bottom"}return null}function pa(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=dt)){if(t!==null)return null;t=o}return t}function ma(e,n,t){let o=n.vertices,i=Yr(o[t]),r=Yr(o[(t+1)%o.length]),a=da(e,Xr(e,i),Xr(e,r));if(!a)return null;let c=pa(i,r);if(c===null)return null;let l=Math.min(i[c],r[c]),m=Math.max(i[c],r[c]);return m-l>dt?{item:e,side:a,variableAxis:c,fixed:i,start:l,end:m}:null}function Zr(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],ra)}function fa(e,n){let t=new Map;for(let o of n){let i=e[o.sourceIndex];if(i)for(let r=0;r<i.vertices.length;r+=1){let a=ma(o,i,r);if(!a)continue;let c=ua(a),l=t.get(c);l?l.push(a):t.set(c,[a])}}for(let o of t.values()){if(o.length<2)continue;o.sort((r,a)=>r.start-a.start||r.end-a.end);let i=[];for(let r of o){i=i.filter(a=>a.end>r.start+dt);for(let a of i)a.item.sourceIndex!==r.item.sourceIndex&&(Zr(a),Zr(r));i.push(r)}}}function ga(e){let n=(0,re.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 ha(e){if(!e)return"#cccccc";let n=(0,re.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(${Qo(t.r)}, ${Qo(t.g)}, ${Qo(t.b)}, ${o})`}return ya(t)}function ya({r:e,g:n,b:t}){let o=i=>Math.round(Math.max(0,Math.min(255,i))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function Qo(e){return Math.round(Math.max(0,Math.min(255,e)))}function ba(e,n,t,o){let i=t?.direction??Ks,r=Math.hypot(i[0],i[1],i[2])||1,a=i[0]/r,c=i[1]/r,l=i[2]/r,m=Math.max(0,t?.intensity??ea)*Math.max(0,e[0]*a+e[1]*c+e[2]*l),g=Math.max(0,o?.intensity??na),x=t?.color??Js,f=o?.color??ta,b=(0,re.shadePolygon)(n,m,x,f,g),h=ga(n);if(h.alpha>=1)return b;let S=parseInt(b.slice(1,3),16),v=parseInt(b.slice(3,5),16),C=parseInt(b.slice(5,7),16);return`rgba(${S}, ${v}, ${C}, ${h.alpha})`}function xa(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],i=ca(o);if(!i||i.width<=0||i.height<=0)return[];n.push({...i,sourceIndex:t})}return fa(e,n),n}function va(e){return e.axis==="x"?{xAxis:[1,0,0],yAxis:[0,0,1],normal:[0,-1,0],tx:0,ty:-e.z,tz:0}:e.axis==="y"?{xAxis:[0,0,1],yAxis:[0,1,0],normal:[-1,0,0],tx:-e.z,ty:0,tz:0}:{xAxis:[1,0,0],yAxis:[0,1,0],normal:[0,0,1],tx:0,ty:0,tz:e.z}}function Pa(e){let n=e.left,t=e.top,o=e.left+e.width,i=e.top+e.height;return[n,t,o,t,o,i,n,i]}function Sa(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function Ca(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(i=>!Number.isFinite(i)))return null;let o=re.SOLID_QUAD_CANONICAL_SIZE/n;for(let i=0;i<8;i+=1)t[i]*=o;return`matrix3d(${t.map(i=>Number(i.toFixed(6))).join(",")})`}function Qr(e,n){let t=e.left-e.bleed.left,o=e.top-e.bleed.top,i=e.width+e.bleed.left+e.bleed.right,r=e.height+e.bleed.top+e.bleed.bottom,a=e.z,c=i/n,l=r/n;return`matrix3d(${(e.axis==="x"?[c,0,0,0,0,0,l,0,0,-1,0,0,t,-a,o,1]:e.axis==="y"?[0,0,c,0,0,l,0,0,-1,0,0,0,-a,o,t,1]:[c,0,0,0,0,l,0,0,0,0,1,0,t,o,a,1]).map(g=>Number(g.toFixed(6))).join(",")})`}function Ea(e,n){let{xAxis:t,yAxis:o,normal:i,tx:r,ty:a,tz:c}=va(e),l=(0,re.computeProjectiveQuadMatrix)(Pa(e),t,o,i,r,a,c,ia,Sa(e));return l?Ca(l,n)??Qr(e,n):Qr(e,n)}function Ta(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function Aa(e){return Ta(e)?oa:qr}function wa(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 Ma(e,n){let t=wa(e),o=n.meshRotation;o&&(t=(0,re.rotateVec3InWrapperCssFrame)(t,o));let[i,r]=(0,re.rotateVec3)(t,n.rotX,0,n.rotY);return{x:i,y:r}}function La(e,n,t){let o=e.filter(f=>n.has(f.face)).map(f=>({item:f,...Ma(f,t)}));if(o.length===0)return[];let i=1/0,r=-1/0,a=1/0,c=-1/0;for(let f of o)i=Math.min(i,f.x),r=Math.max(r,f.x),a=Math.min(a,f.y),c=Math.max(c,f.y);let l=4,m=Math.max(1e-6,r-i),g=Math.max(1e-6,c-a),x=new Map;for(let f of o){let b=Math.min(l-1,Math.max(0,Math.floor((f.x-i)/m*l))),h=Math.min(l-1,Math.max(0,Math.floor((f.y-a)/g*l))),S=`${b}:${h}`,v=x.get(S);v||(v={tx:b,ty:h,sourceIndex:f.item.sourceIndex,items:[]},x.set(S,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:i,ambientLight:r}=e,a=xa(o);if(a.length===0)return null;let c=new Set(a.map(y=>y.face));t.classList.add("polycss-voxel-mesh");let l=Aa(n);l!==qr&&t.style.setProperty("--polycss-voxel-primitive",`${l}px`);let m=new Map,g=(y,L)=>{let u=`${y}|${L}`,d=m.get(u);if(d)return d;let A=ba(Kr[y],L,i,r);return m.set(u,A),A},x=new Map,f=new Map,b=new Map,h=new Map;for(let y of a){let L=h.get(y.face);L||(L=[],h.set(y.face,L)),L.push(y)}let S="",v=0,C=new Set,R=y=>{let L=x.get(y.sourceIndex);return L||(L=n.createElement("b"),x.set(y.sourceIndex,L),aa(L,g(y.face,y.baseColor),Ea(y,l))),L},I=y=>{let L=f.get(y);return L||(L=n.createElement("span"),L.className=`polycss-voxel-face polycss-voxel-face-${y}`,L.dataset.polycssVoxelFace=y,L.__polycssVoxelFaceHost=!0,f.set(y,L)),L},B=()=>{for(let y of Array.from(t.childNodes))if(!y.__polycssVoxelFaceHost)return y;return null},O=(y,L)=>{let u=L.map(_=>_.sourceIndex).join(",");if(b.get(y)===u)return;let d=I(y),A=n.createDocumentFragment();for(let _ of L)A.appendChild(R(_));d.replaceChildren(A),b.set(y,u)},X=()=>{for(let y of qo)c.has(y)&&O(y,h.get(y)??[])},Z=y=>new Set(y.split("|").filter(Boolean)),M=y=>{let L=Z(y);return qo.filter(u=>L.has(u)&&c.has(u))},z=y=>{let L=0;for(let u of y)L+=h.get(u)?.length??0;return L},V=y=>{let L=new Set,u=[],d=new Map;for(let A of y){L.has(A.face)||(L.add(A.face),u.push(A.face));let _=d.get(A.face);_||(_=[],d.set(A.face,_)),_.push(A)}return{orderedFaces:u,itemsByFace:d}},F=(y,L)=>{let u=new Set(y);for(let d of C){if(u.has(d))continue;let A=f.get(d);A?.parentNode===t&&t.removeChild(A)}if(L){let d=n.createDocumentFragment();for(let A of y)d.appendChild(I(A));t.insertBefore(d,B()),C=u;return}for(let d=0;d<y.length;d+=1){let A=y[d],_=I(A);if(_.parentNode===t)continue;let N=null;for(let Y=d+1;Y<y.length;Y+=1){let w=f.get(y[Y]);if(w?.parentNode===t){N=w;break}}t.insertBefore(_,N??B())}C=u},ae=(y,L,u)=>{if(!u){let Y=M(y);F(Y,!1),v=z(Y);return}let d=new Set(y.split("|").filter(Boolean)),A=La(a,d,L),{orderedFaces:_,itemsByFace:N}=V(A);for(let Y of _)O(Y,N.get(Y)??[]);F(_,!0),v=A.length};return X(),{get brushCount(){return v},render(y){S=Wr(y),ae(S,y,!0)},syncCamera(y){let L=Wr(y);L!==S&&(S=L,ae(L,y,!1))},dispose(){for(let y of f.values())y.remove();t.classList.remove("polycss-voxel-mesh"),t.style.removeProperty("--polycss-voxel-primitive"),x.clear(),f.clear(),b.clear(),v=0,C=new Set,S=""}}}var ei="polycss-styles";function ti(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(ei))return;let t=n.createElement("style");t.id=ei,t.textContent=_a,n.head.appendChild(t)}var _a=`
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,
@@ -516,4 +516,4 @@
516
516
  .polycss-scene[data-polycss-lighting="dynamic"] q {
517
517
  opacity: clamp(0, calc((var(--pnx) * var(--clx) + var(--pny) * var(--cly) + var(--pnz) * var(--clz)) * 10), 1);
518
518
  }
519
- `;var Ke=require("@layoutit/polycss-core");var cn=Ke.BASE_TILE,Ca=.1;function un(e){return(0,Ke.worldDirectionToCss)(e)}function ut(e){return(0,Ke.worldDirectionalLightToCss)(e)}function Jn(e){return(0,Ke.buildPolyMeshTransform)(e)}function Qo(e,n=[0,0,0],t=1){return(0,Ke.buildPolyCameraSceneTransform)(e.state,{autoCenterOffset:n,layoutScale:t})}function Ea(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 ti(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=Ea(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function ni(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}function oi(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,i=0;for(let v=1;v+1<e.vertices.length;v++){let f=e.vertices[v],b=e.vertices[v+1],y=f[1]-n[1],P=f[0]-n[0],x=f[2]-n[2],E=b[1]-n[1],O=b[0]-n[0],R=b[2]-n[2];t-=P*R-x*O,o-=x*E-y*R,i-=y*O-P*E}let r=Math.hypot(t,o,i);if(r<1e-9)return null;t/=r,o/=r,i/=r;let s=1/Ca,c=Math.round(t*s)/s,l=Math.round(o*s)/s,d=Math.round(i*s)/s,h=Math.hypot(c,l,d);return h<1e-9?null:{key:c+","+l+","+d,vec:[c/h,l/h,d/h]}}function ri(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let i of t)if(!o.includes(i))return!1;return!0}function ii(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function si(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 dt=require("@layoutit/polycss-core");var Ta=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"],jt="--polycss-light-preview-active",ai=`var(${jt}, 0)`,Aa="max(0, calc(var(--pnx, 0) * var(--plx, 0) + var(--pny, 0) * var(--ply, 0) + var(--pnz, 1) * var(--plz, 1)))",qo=(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))`,wa=qo("--psr","--par","--plr"),Ma=qo("--psg","--pag","--plg"),La=qo("--psb","--pab","--plb");function me(e,n,t){return e.style.getPropertyValue(n)===t?!1:(e.style.setProperty(n,t),!0)}function vt(e){for(let n of Ta)e.style.getPropertyValue(n)&&e.style.removeProperty(n)}function eo(e,n){let t=n.directionalLight?.direction??[.4,-.7,.59],o=un(t),i=Math.hypot(o[0],o[1],o[2])||1,r=o[0]/i,s=o[1]/i,c=o[2]/i,l=(0,dt.parseHexColor)(n.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],d=(0,dt.parseHexColor)(n.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],h=n.directionalLight?.intensity??1,v=n.ambientLight?.intensity??.4,f=P=>(P/255).toFixed(4);me(e,"--plx",r.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(d[0])),me(e,"--pag",f(d[1])),me(e,"--pab",f(d[2])),me(e,"--pai",v.toFixed(4));let b=c,y=Math.sign(b||1)*Math.max(Math.abs(b),.01);me(e,"--clx",r.toFixed(2)),me(e,"--cly",s.toFixed(2)),me(e,"--clz",y.toFixed(2))}function li(e,n){let t=n.textureLighting==="dynamic";if(e.dataset.polycssLighting=n.textureLighting??"baked",!t){vt(e);return}eo(e,n)}function Pt(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 ci(e,n){let t=(0,dt.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 Ko(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=t.textureLighting??"baked",i={directionalLight:ut(t.directionalLight),ambientLight:t.ambientLight,textureLighting:o,textureQuality:t.textureQuality,seamBleed:t.seamBleed,strategies:t.strategies},r=ko(e.plan,n,e.plan.normal,o,i);return Dt(e.element,r,o),o==="baked"&&Ra(e.element),!0}function _a(e){let n=(0,dt.parsePureColor)(e)??{rgb:[255,255,255],alpha:1},[t,o,i]=n.rgb,r=(c,l)=>`calc(${c} * (1 - ${ai}) + var(${l}, ${c}) * ${ai})`,s=n.alpha<1?` / ${n.alpha}`:"";return`rgb(${r(t,"--polycss-preview-r")} ${r(o,"--polycss-preview-g")} ${r(i,"--polycss-preview-b")}${s})`}function ui(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=e.element,i=e.plan.normal,r=(0,dt.parseHex)(n.color??"#cccccc"),s=!1;return s=me(o,"--pnx",i[0].toFixed(4))||s,s=me(o,"--pny",i[1].toFixed(4))||s,s=me(o,"--pnz",i[2].toFixed(4))||s,s=me(o,"--psr",(r.r/255).toFixed(4))||s,s=me(o,"--psg",(r.g/255).toFixed(4))||s,s=me(o,"--psb",(r.b/255).toFixed(4))||s,s=me(o,"--plam",Aa)||s,s=me(o,"--polycss-preview-r",wa)||s,s=me(o,"--polycss-preview-g",Ma)||s,s=me(o,"--polycss-preview-b",La)||s,s=me(o,"--polycss-paint",_a(t))||s,o.style.getPropertyValue("color")&&(o.style.removeProperty("color"),s=!0),s}function Ra(e){e.style.removeProperty("--pnx"),e.style.removeProperty("--pny"),e.style.removeProperty("--pnz"),e.style.removeProperty("--psr"),e.style.removeProperty("--psg"),e.style.removeProperty("--psb"),e.style.removeProperty("--plam"),e.style.removeProperty("--polycss-preview-r"),e.style.removeProperty("--polycss-preview-g"),e.style.removeProperty("--polycss-preview-b"),e.style.removeProperty("--polycss-paint")}var ka="http://www.w3.org/2000/svg",to=class{constructor(){this.groundSvg=null;this.groundVisible=!1;this.currentGroundCssZ=null;this.shadowRoot=null}};function di(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 i=t.firstChild;i?t.insertBefore(o,i):t.appendChild(o)}return o}function pi(e){e.groundSvg?.parentNode&&e.groundSvg.parentNode.removeChild(e.groundSvg),e.groundSvg=null,e.groundVisible=!1}function mi(e){e.groundSvg&&e.groundVisible&&(e.groundSvg.style.display="none",e.groundVisible=!1)}function fi(e,n,t,o){let i=[],r=e.firstChild;for(let s=0;s<t;s++){let c=r;c&&c.tagName==="path"?r=c.nextSibling:(c=n.createElementNS(ka,"path"),c.setAttribute("fill-rule","nonzero"),o&&(c.setAttribute("stroke-width","0.5"),c.setAttribute("stroke-linejoin","round")),e.insertBefore(c,r)),i.push(c)}for(;r;){let s=r.nextSibling;e.removeChild(r),r=s}return i}function gi(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 to,receiverShadowCache:new Map,receiverShadowCacheKey:new Map,casterItemsCache:new Map,casterItemsCacheKey:new Map}}var Ve=require("@layoutit/polycss-core");function hi(e){for(let n of e)n.svg&&n.svg.parentNode&&n.svg.parentNode.removeChild(n.svg),n.svg=null}function yi(e,n){if(n){let t=e.receiverShadowCache.get(n);t&&hi(t),e.receiverShadowCache.delete(n),e.receiverShadowCacheKey.delete(n)}else{for(let t of e.receiverShadowCache.values())hi(t);e.receiverShadowCache.clear(),e.receiverShadowCacheKey.clear()}}function bi(e,n){n?(e.casterItemsCache.delete(n),e.casterItemsCacheKey.delete(n)):(e.casterItemsCache.clear(),e.casterItemsCacheKey.clear())}function xi(e){pi(e.shadowSvgState),vi(e)}function Jo(e){return e.handle.id??e.autoMeshId}var Da="http://www.w3.org/2000/svg",no=new WeakMap,Pi=new WeakMap,Si=new WeakMap,Ci=new WeakMap,Ei=new WeakMap;function Ti(e){let n=no.get(e);return n||(n=new Map,no.set(e,n)),n}function er(e){let n=no.get(e);if(n){for(let t of n.values())t.svg&&t.svg.parentNode&&t.svg.parentNode.removeChild(t.svg);n.clear(),no.delete(e)}}function vi(e){for(let n of e.meshes)er(n)}function Ai(e,n,t,o,i,r,s,c,l,d){let h=e.options.current,{receiverShadowCache:v,receiverShadowCacheKey:f,casterItemsCache:b,casterItemsCacheKey:y}=e,P=o.handle.transform.position??[0,0,0],x=o.handle.transform.rotation??[0,0,0],E=o.polygons.some(A=>A.texture!==void 0),O=(0,Ve.meshScaleVec3)(o.handle.transform.scale),R=o.bboxCenterCss,j=h.shadow?.lift??.001,D=`${o.polygons.length}|${i.size}|${P.join(",")}|${x.join(",")}|${O.join(",")}|${R?R.join(","):"n"}|${j}`,Q=v.get(o);if(Q===void 0||f.get(o)!==D){Q=(0,Ve.prepareReceiverFacePlanes)(o.polygons,P,o.handle.transform.scale,i,j,x),v.set(o,Q),f.set(o,D);let A=Ti(o);for(let g of A.values())g.svg&&g.svg.parentNode&&g.svg.parentNode.removeChild(g.svg);A.clear()}let J=[];for(let A of n){let g=A.handle.transform.position??[0,0,0],T=A.handle.transform.rotation??[0,0,0],u=(0,Ve.meshScaleVec3)(A.handle.transform.scale),m=A.bboxCenterCss,L=`${A.polygons.length}|${g.join(",")}|${T.join(",")}|${u.join(",")}|${m?m.join(","):"n"}`,_=b.get(A);if(_===void 0||y.get(A)!==L){let C=t.get(A),W=new Set;for(let Z of A.rendered)Z.plan&&!C.has(Z.polygonIndex)&&W.add(Z.polygonIndex);_=(0,Ve.prepareCasterPolyItems)(A.polygons,g,A.handle.transform.scale,Z=>W.has(Z),T),b.set(A,_),y.set(A,L)}let H;if(A===o){let C=Pi.get(A);(C===void 0||Si.get(A)!==A.polygons)&&(C=(0,Ve.buildSharedEdgeMap)(A.polygons),Pi.set(A,C),Si.set(A,A.polygons)),H=C}let q;if(A!==o&&A.polygons.length>=40){let C=Ci.get(A);(C===void 0||Ei.get(A)!==L)&&(C=(0,Ve.prepareCasterEdgeOwners)(A.polygons,g,A.handle.transform.scale,T),Ci.set(A,C),Ei.set(A,L)),q=C}J.push({id:A,items:_,selfShadowEdgeMap:H,edgeOwners:q,casterPolygonCount:A.polygons.length})}let k={rotX:e.camera.state.rotX,rotY:e.camera.state.rotY,meshRotation:o.handle.transform.rotation},V=(0,Ve.computeReceiverShadowFaces)({receiverPlanes:Q,receiverPolygons:o.polygons,receiverHasTexture:E,casters:J,lightDir:r,cameraRot:k,ambientLight:h.ambientLight,directionalLight:h.directionalLight,shadow:{color:h.shadow?.color,opacity:d,maxExtend:h.shadow?.maxExtend}}),z=Ti(o),B=new Set;for(let A of V){B.add(A.faceIndex);let g=z.get(A.faceIndex);g||(g={svg:null,visible:!1,width:-1,height:-1,matrixCss:""},z.set(A.faceIndex,g));let T=g.svg;T?(g.visible||(T.style.display="block"),(g.width!==A.width||g.height!==A.height)&&(T.setAttribute("width",String(A.width)),T.setAttribute("height",String(A.height)),T.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),g.width=A.width,g.height=A.height),g.matrixCss!==A.matrixCss&&(T.style.transform=A.matrixCss,g.matrixCss=A.matrixCss)):(T=e.doc.createElementNS(Da,"svg"),T.setAttribute("class","polycss-shadow polycss-shadow-svg polycss-shadow-receiver"),h.debugShadowAttrs&&(T.setAttribute("data-poly-shadow-type","receiver"),T.setAttribute("data-poly-shadow-receiver",Jo(o)),T.setAttribute("data-poly-shadow-receiver-face",String(A.faceIndex)),T.setAttribute("data-poly-shadow-receiver-polys",JSON.stringify(A.memberPolyIndices))),T.setAttribute("width",String(A.width)),T.setAttribute("height",String(A.height)),T.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),T.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}`),di(e.shadowSvgState,e.doc,e.sceneEl).appendChild(T),g.svg=T,g.width=A.width,g.height=A.height,g.matrixCss=A.matrixCss),g.visible=!0;let u=fi(T,e.doc,A.paths.length,!0),m=A.opacity.toFixed(4),L=[],_=!!h.debugShadowAttrs;for(let H=0;H<A.paths.length;H++){let q=A.paths[H],C=_?Jo(q.casterId):"";_&&L.push(C);let W=u[H];if(W.setAttribute("d",q.d),W.getAttribute("fill")!==A.fill&&W.setAttribute("fill",A.fill),W.getAttribute("stroke")!==A.fill&&W.setAttribute("stroke",A.fill),W.getAttribute("opacity")!==m&&W.setAttribute("opacity",m),_){W.getAttribute("data-poly-shadow-caster")!==C&&W.setAttribute("data-poly-shadow-caster",C);let Z=JSON.stringify(q.casterPolygonIndices);W.getAttribute("data-poly-shadow-caster-polys")!==Z&&W.setAttribute("data-poly-shadow-caster-polys",Z)}}if(_){let H=L.join(" ");T.getAttribute("data-poly-shadow-casters")!==H&&T.setAttribute("data-poly-shadow-casters",H)}}for(let[A,g]of z)B.has(A)||g.svg&&g.visible&&(g.svg.style.display="none",g.visible=!1)}var wi=Symbol.for("polycss.animation.triangleFrameTarget");var Oa=750;var oo=Promise.resolve();function Mi(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:te.DEFAULT_SEAM_BLEED}}var Ia={key:"non-cullable",normal:[1,1,0]};function Li(){return[Ia]}function _i(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&&ei(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...i}=n,r=Mi({seamBleed:te.DEFAULT_SEAM_BLEED,...i}),s=ti(e),c=[0,0,0],l=e.ownerDocument??document,d=l.createElement("div");d.className="polycss-camera",Q(d,r),e.appendChild(d);let h=l.createElement("div");h.className="polycss-scene",h.setAttribute("aria-hidden","true"),J(h,r),d.appendChild(h);let v=gi({host:e,doc:l,cameraEl:d,sceneEl:h,camera:t,layoutScale:s,options:r}),f=v.meshes,b=new WeakMap,y=v.shadowSvgState,P=()=>mi(y),x=()=>xi(v),E=null;function O(a){if(!a)return null;let p=Math.hypot(a[0],a[1],a[2]);if(!Number.isFinite(p)||p<=0)return null;let S=Math.round(a[0]/p*100)/100,w=Math.round(a[1]/p*100)/100,$=Math.round(a[2]/p*100)/100;return`${S}|${w}|${$}`}function R(){E=null}let j=a=>yi(v,a),D=a=>bi(v,a);function Q(a,p){let S=(0,te.capturePolyCameraSnapshot)(t);a.style.perspective=S.appliedPerspectiveStyle,a.dataset.polycssCameraProjection=S.projection,a.dataset.polycssCameraPerspective=S.perspectiveStyle,a.dataset.polycssCameraAppliedPerspective=S.appliedPerspectiveStyle,a.dataset.polycssCameraZoom=String(S.state.zoom),a.dataset.polycssCameraDistance=String(S.state.distance),a.dataset.polycssCameraRotX=String(S.state.rotX),a.dataset.polycssCameraRotY=String(S.state.rotY),a.dataset.polycssCameraTarget=S.state.target.join(",")}function J(a,p){ni(a,s),a.style.transform=Qo(t,c,s),li(a,p)}function k(a){a.style.transform=Qo(t,c,s)}function V(a){a.textureReadyPromise=oo,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 p of Array.from(a.wrapper.children))p instanceof HTMLElement&&p.classList.contains("polycss-bucket")&&p.remove();a.hasBuckets=!1}function z(a){for(let p of Array.from(a.wrapper.childNodes)){if(!(p instanceof HTMLElement))return p;if(p.classList.contains("polycss-bucket")||p.classList.contains("polycss-shadow"))continue;let S=p.tagName.toLowerCase();if(!(S==="b"||S==="i"||S==="s"||S==="u"||S==="q"))return p}return null}function B(a,p,S){S?.parentNode===a.wrapper?a.wrapper.insertBefore(p,S):a.wrapper.appendChild(p)}function A(a){for(let p of a.shadowRendered)p.parentNode&&p.parentNode.removeChild(p);a.shadowRendered.length=0,x()}function g(a,p){p?.();for(let S of a){try{S.dispose()}catch{}S.element.parentNode&&S.element.parentNode.removeChild(S.element)}}function T(a,p,S,w){a.rendered=p,a.renderedByPolygonIndex=[];for(let $ of p)a.renderedByPolygonIndex[$.polygonIndex]=$;a.disposeAtlas=S,a.textureReadyPromise=w?w.catch(()=>{}):oo,a.solidLightingPreviewPrepared=!1}function u(a,p){let S=a.renderedByPolygonIndex[p];return S?.polygonIndex===p?S:void 0}function m(a){for(let p of Array.from(a.wrapper.children))p instanceof HTMLElement&&p.classList.contains("polycss-bucket")&&p.remove();a.hasBuckets=!1;for(let p of a.rendered)p.element.parentNode&&p.element.parentNode.removeChild(p.element)}function L(a,p){let S=a.polygons[p.polygonIndex];return a.stableDom&&S?(0,te.polygonCssSurfaceNormal)(S):p.plan?.normal??(S?(0,te.polygonCssSurfaceNormal)(S):null)}function _(a){if(!Z(a))return a.rendered;let p=H(a);return a.rendered.filter(S=>q(a,S,te.CAMERA_BACKFACE_CULL_EPS,p))}function H(a){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:a.handle.transform.rotation}}function q(a,p,S=te.CAMERA_BACKFACE_CULL_EPS,w=H(a)){let $=L(a,p);return $===null||(0,te.normalFacesCamera)($,w,S)}function C(a){if(a.excludeFromAutoCenter){a.cameraCullGroups=[];return}let p=new Map;for(let S of a.rendered){let w=L(a,S);if(!w)continue;if(!(0,te.isAxisAlignedSurfaceNormal)(w)){a.cameraCullGroups=Li();return}let $=(0,te.cameraCullNormalKey)(w);if(!p.has($)&&(p.set($,w),p.size>te.VOXEL_CAMERA_CULL_NORMAL_LIMIT)){a.cameraCullGroups=Li();return}}a.cameraCullGroups=Array.from(p,([S,w])=>({key:S,normal:w}))}function W(a){return Z(a)?(0,te.cameraCullVisibleSignature)(a.cameraCullGroups,H(a)):"all"}function Z(a){return!a.excludeFromAutoCenter&&(0,te.isVoxelCameraCullableNormalGroups)(a.cameraCullGroups)}function ae(a){a.cameraCullSignature=Z(a)?W(a):"all"}function be(a,p){let S=new Array(a.rendered.length),w=!1,$=H(a);for(let K=0;K<a.rendered.length;K+=1){let se=a.rendered[K],ne=q(a,se,p,$);S[K]=ne}let N=null,I=null,U=()=>{if(!(!N||!I)){if(N===I)N.remove();else{let K=l.createRange();K.setStartBefore(N),K.setEndAfter(I),K.deleteContents(),K.detach()}N=null,I=null,w=!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(),N=se.element),I=se.element):U()}U();let Y=K=>{for(let se=K;se<a.rendered.length;se+=1){let ne=a.rendered[se].element;if(ne.parentNode===a.wrapper)return ne}return z(a)},ue=-1,ie=K=>{if(ue<0)return;let se=l.createDocumentFragment();for(let ne=ue;ne<K;ne+=1){let He=a.rendered[ne];Ce(a,He),se.appendChild(He.element)}B(a,se,Y(K)),ue=-1,w=!0};for(let K=0;K<a.rendered.length;K+=1){let se=a.rendered[K];S[K]&&se.element.parentNode!==a.wrapper?ue<0&&(ue=K):ie(K)}return ie(a.rendered.length),w}function fe(a,p=!1){if(a.voxelRenderer){p?a.voxelRenderer.render(H(a)):a.voxelRenderer.syncCamera(H(a)),a.cameraCullSignature="voxel-direct";return}if(!Z(a)){let $=a.cameraCullSignature!=="all";a.cameraCullSignature="all",$&&Ee(a);return}if(a.hasBuckets){he(a,p);return}let S=W(a);if(!p&&S===a.cameraCullSignature)return;let w=be(a,te.CAMERA_BACKFACE_CULL_EPS);a.cameraCullSignature=S,w&&Xe(a)}function he(a,p=!1){let S=Z(a)?W(a):"all";!p&&S===a.cameraCullSignature||Ee(a)}function Le(a,p){return L(a,p)}function Ce(a,p){if(r.textureLighting!=="dynamic")return;let S=Le(a,p);S&&(p.element.style.setProperty("--pnx",S[0].toFixed(4)),p.element.style.setProperty("--pny",S[1].toFixed(4)),p.element.style.setProperty("--pnz",S[2].toFixed(4)))}function Oe(a){m(a),a.hasBuckets=!1;let p=a.skipBucketNormalCleanupOnce;a.skipBucketNormalCleanupOnce=!1;let S=l.createDocumentFragment(),w=r.textureLighting==="dynamic"&&!a.stableDom,$=new Map,N=[];for(let I of _(a)){let U=a.polygons[I.polygonIndex],Y=w&&U?oi(U):null;if(!Y){N.push(I);continue}let ue=Y.key+"|"+(U.color??""),ie=$.get(ue);ie||(ie={vec:Y.vec,items:[]},$.set(ue,ie)),ie.items.push(I)}for(let I of N)Ce(a,I),S.appendChild(I.element);for(let I of $.values()){if(I.items.length<2){for(let Y of I.items)Ce(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),(!p||Y.kind==="triangle")&&(Y.element.style.removeProperty("--pnx"),Y.element.style.removeProperty("--pny"),Y.element.style.removeProperty("--pnz"));S.appendChild(U)}B(a,S,z(a)),ae(a)}function Ye(){return new Promise(a=>setTimeout(a,0))}async function et(a,p){if(r.textureLighting==="dynamic"&&!a.stableDom)return Oe(a),!p();m(a);let w=l.createDocumentFragment(),$=z(a),N=0;for(let I of _(a)){if(p())return!1;Ce(a,I),w.appendChild(I.element),N++,N%Oa===0&&(B(a,w,$),w=l.createDocumentFragment(),await Ye())}return w.childNodes.length>0&&B(a,w,$),ae(a),!p()}function pt(a,p){let S=r.textureLighting==="dynamic",w=r.directionalLight?.direction,$=p&&(p[0]!==0||p[1]!==0||p[2]!==0);if(!S||!$||!w){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 N=(0,te.inverseRotateVec3)(w,p),I=un(N),U=Math.hypot(I[0],I[1],I[2])||1,Y=(I[0]/U).toFixed(2),ue=(I[1]/U).toFixed(2),ie=(I[2]/U).toFixed(2),K=`${Y}|${ue}|${ie}`;a.lightOverrideSignature!==K&&(a.wrapper.style.setProperty("--plx",Y),a.wrapper.style.setProperty("--ply",ue),a.wrapper.style.setProperty("--plz",ie),a.lightOverrideSignature=K)}function Tt(a){let p=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let w=a.polygons[S.polygonIndex];w&&(p=Ko(S,w,r)||p)}return a.solidLightingPreviewPrepared=!1,a.solidLightingPreviewActive=!1,p}function mt(a){if((r.textureLighting??"baked")!=="baked")return!1;let p=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let w=a.polygons[S.polygonIndex];w&&(ui(S,w,S.plan.shadedColor),p=!0)}return a.solidLightingPreviewPrepared=p,p}function yo(a){return(r.textureLighting??"baked")!=="baked"||!a.solidLightingPreviewPrepared&&!mt(a)?!1:(a.solidLightingPreviewActive=!0,!0)}function bo(a){return a.kind==="atlas"||!!a.plan?.texture}function xo(){if((r.textureLighting??"baked")!=="baked")return!1;let a=!1;for(let p of f)a=Tt(p)||a,p.rendered.some(bo)&&(Qt(p),a=!0);h.style.removeProperty(jt);for(let p of f)vt(p.wrapper),p.solidLightingPreviewActive=!1;return vt(h),a}function vo(){h.style.removeProperty(jt);for(let a of f)a.solidLightingPreviewActive&&(Tt(a),vt(a.wrapper));(r.textureLighting??"baked")!=="dynamic"&&(vt(h),R(),_e())}function G(a,p){let S=a.handle.transform.rotation,w=p.directionalLight?.direction??r.directionalLight?.direction;if(!(S&&(S[0]!==0||S[1]!==0||S[2]!==0))||!w){vt(a.wrapper);return}let N=(0,te.inverseRotateVec3)(w,S);eo(a.wrapper,{...r,...p,directionalLight:{...r.directionalLight,...p.directionalLight,direction:N}})}function le(a){if((r.textureLighting??"baked")!=="baked")return!1;eo(h,{...r,...a}),!a.skipShadows&&a.directionalLight?.direction&&_e(a.directionalLight.direction);let p=!1;for(let S of f)G(S,a),p=yo(S)||p;return p?me(h,jt,"1"):h.style.removeProperty(jt),p}function ce(a,p,S){let w=a.polygons[p];if(!w)return!1;let $=u(a,p);if(!$)return!1;let N=r.textureLighting??"baked";return N==="dynamic"?(ci($.element,S),!0):N==="baked"?Ko($,w,r):!1}function Ie(a,p){let S=a.polygons[p];if(!S)return!1;let w=u(a,p);return w?(Se(w.element,S,p),!0):!1}function Zt(a,p,S){return!(S.length===0||!S.every(w=>w==="color"||w==="data")||S.includes("color")&&!ce(a,p,a.polygons[p]?.color)||S.includes("data")&&!Ie(a,p))}function Xe(a){R(),_e()}function _e(a){let p=[];for(let ne of f)!ne.disposed&&ne.castShadow&&p.push(ne);if(p.length===0){x(),E=null;return}let S=r.shadow?.color??"#000000",w=r.shadow?.opacity??.25,$=(0,te.parseHexColor)(S)?.rgb??[0,0,0],N=$[0],I=$[1],U=$[2],Y=a??r.directionalLight?.direction??[.4,-.7,.59],ue=un(Y),ie=O(ue);if(ie!==null&&ie===E)return;let K=new Map;for(let ne of p)K.set(ne,(0,te.findOverlappingPolygonDuplicates)(ne.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.95,preserveDoubleSidedBackfaces:!1}));let se=new Map;for(let ne of f)ne.disposed||!ne.receiveShadow||se.set(ne,new Set);P();for(let ne of f)ne.disposed||!ne.receiveShadow||Ai(v,p,K,ne,se.get(ne)??new Set,ue,N,I,U,w);E=ie}function Ee(a){if(a.voxelRenderer){a.voxelRenderer.render(H(a)),a.cameraCullSignature="voxel-direct";return}A(a),Oe(a),Xe(a)}function je(a,p){if(!p||!a.polygons||a.polygons.length<2)return;let S=Math.hypot(p[0],p[1],p[2]);if(!Number.isFinite(S)||S<=0)return;let w=p[0]/S,$=p[1]/S,N=p[2]/S,I=K=>Math.round(K*1e3)/1e3,U=`${I(w)},${I($)},${I(N)}`,Y=a.lightOcclusionCache;if(Y&&Y.polygons===a.polygons&&Y.lightDirKey===U)return Y.occluded;let ue=Y&&Y.polygons===a.polygons?Y.dedupDropped:(0,te.findOverlappingPolygonDuplicates)(a.polygons,{normalTolerance:.1,distanceTolerance:.12,overlapFraction:.98,preserveDoubleSidedBackfaces:!1}),ie=(0,te.computeLightVisibility)(a.polygons,[w,$,N],ue);return a.lightOcclusionCache={polygons:a.polygons,lightDirKey:U,occluded:ie,dedupDropped:ue},ie}function Ge(a){return!!a.voxelSource&&r.textureLighting!=="dynamic"&&!a.stableDom&&!a.castShadow}function Me(a,p){V(a);let S=r.directionalLight,w=p?{...S,direction:p}:S,$=ut(w),N=void 0;if(Ge(a)){let Y=Kr({doc:l,wrapper:a.wrapper,polygons:a.parseResult.polygons,directionalLight:$,ambientLight:r.ambientLight});if(Y){a.voxelRenderer=Y,Y.render(H(a)),a.cameraCullSignature="voxel-direct",a.textureReadyPromise=oo;return}}let I={doc:l,directionalLight:$,ambientLight:r.ambientLight,textureLighting:r.textureLighting,textureQuality:r.textureQuality,textureLeafSizing:r.textureLeafSizing,textureImageRendering:r.textureImageRendering,textureBackend:r.textureBackend,textureProjection:r.textureProjection,seamBleed:r.seamBleed,strategies:r.strategies,lightOccludedPolyIndices:N},U=a.stableDom?(()=>{let Y=Bt(a.polygons,I);return Pt(a.wrapper,Y),ln(a.polygons,{...I,solidPaintDefaults:Y})??zt(a.polygons,{...I,solidPaintDefaults:Y})})():zt(a.polygons,{...I,computeSolidPaintDefaults:!0,skipDynamicNormalVars:r.textureLighting==="dynamic"});a.stableDom||Pt(a.wrapper,U.solidPaintDefaults??{}),T(a,U.rendered,U.dispose,U.pagesReady),a.skipBucketNormalCleanupOnce=r.textureLighting==="dynamic"&&!a.stableDom,C(a),Oe(a),Xe(a)}function Qt(a,p){if(a.rendered.length===0||a.voxelRenderer||a.stableDom||Ge(a)){Me(a,p);return}if(a.rendered[0]?.element.parentNode===null){Me(a,p);return}let S=r.directionalLight,w=p?{...S,direction:p}:S,$=ut(w),N={doc:l,directionalLight:$,ambientLight:r.ambientLight,textureLighting:r.textureLighting,textureQuality:r.textureQuality,textureLeafSizing:r.textureLeafSizing,textureImageRendering:r.textureImageRendering,textureBackend:r.textureBackend,textureProjection:r.textureProjection,seamBleed:r.seamBleed,strategies:r.strategies,computeSolidPaintDefaults:!0,skipDynamicNormalVars:r.textureLighting==="dynamic"},I=zt(a.polygons,N),U=()=>{a.rebakeInFlight=!1;let ie=a.rebakeQueuedLightDir;ie!==null&&(a.rebakeQueuedLightDir=null,Qt(a,ie))},Y=()=>{if(a.disposed){I.dispose(),U();return}if(I.rendered.length!==a.rendered.length){I.dispose(),Me(a,p),U();return}for(let se of I.rendered){let ne=a.renderedByPolygonIndex[se.polygonIndex];if(!ne)continue;let He=se.element.getAttribute("style");He!==null&&ne.element.setAttribute("style",He)}let ie=I.solidPaintDefaults;ie&&Pt(a.wrapper,ie);let K=a.disposeAtlas;a.disposeAtlas=I.dispose,K&&(typeof requestAnimationFrame=="function"?ne=>{requestAnimationFrame(ne)}:ne=>{setTimeout(ne,0)})(K),Xe(a),U()},ue=I.pagesReady;ue&&typeof ue.then=="function"?(a.textureReadyPromise=ue.catch(()=>{}),ue.then(()=>So(I.rendered)).then(Co).then(Y,()=>{I.dispose(),a.disposed||Me(a,p),U()})):Y()}function Po(a,p){if(a.rebakeInFlight){a.rebakeQueuedLightDir=p;return}a.rebakeInFlight=!0,Qt(a,p)}function So(a){let p=new Set;for(let S of a){let w=S.element.getAttribute("style")??"",$=/url\((blob:[^)]+)\)/g,N;for(;(N=$.exec(w))!==null;)p.add(N[1])}return Array.from(p)}function Co(a){return a.length===0||typeof Image>"u"?Promise.resolve():Promise.all(a.map(p=>{let S=new Image;S.src=p;let w=S.decode?.();return w?w.catch(()=>{}):Promise.resolve()})).then(()=>{})}function tt(){let a=1/0,p=!1;for(let N of f)if(!N.disposed&&N.receiveShadow){p=!0;break}for(let N of f){if(N.disposed||!(p?N.receiveShadow:N.castShadow))continue;let U=N.handle.transform.position?.[2]??0;for(let Y of N.polygons)for(let ue of Y.vertices){let ie=ue[2]+U;ie<a&&(a=ie)}}if(!Number.isFinite(a)){let N=y.currentGroundCssZ!==null;y.currentGroundCssZ=null,N&&(x(),R());return}let S=r.shadow?.lift??.05,w=(a+S)*cn,$=y.currentGroundCssZ;y.currentGroundCssZ=w,$!==w&&(R(),_e())}async function Hn(a,p){V(a);let S=ut(r.directionalLight),w={doc:l,directionalLight:S,ambientLight:r.ambientLight,textureLighting:r.textureLighting,textureQuality:r.textureQuality,textureLeafSizing:r.textureLeafSizing,textureImageRendering:r.textureImageRendering,textureBackend:r.textureBackend,textureProjection:r.textureProjection,seamBleed:r.seamBleed,strategies:r.strategies,lightOccludedPolyIndices:void 0},$=a.stableDom?ln(a.polygons,w):null;if($){let U=Bt(a.polygons,w);return Pt(a.wrapper,U),T(a,$.rendered,$.dispose,$.pagesReady),C(a),Oe(a),Xe(a),!p()}let N=await Zn(a.polygons,{...w,skipDynamicNormalVars:r.textureLighting==="dynamic"},p);if(p())return N.dispose(),!1;Pt(a.wrapper,N.solidPaintDefaults),T(a,N.rendered,N.dispose,N.pagesReady),a.skipBucketNormalCleanupOnce=r.textureLighting==="dynamic"&&!a.stableDom,C(a);let I=await et(a,p);return I&&Xe(a),I}function ft(){let a=c,p=[0,0,0];if(r.autoCenter){let S=[];for(let w of f)!w.disposed&&!w.excludeFromAutoCenter&&S.push(...w.polygons);if(S.length>0){let w=(0,te.computeSceneBbox)(S);p=[(w.min[0]+w.max[0])/2,(w.min[1]+w.max[1])/2,(w.min[2]+w.max[2])/2]}}a[0]===p[0]&&a[1]===p[1]&&a[2]===p[2]||(c=p,v.autoCenter.offset=p,J(h,r))}function as(a,p={}){let w=(h.ownerDocument??document).createElement("div");w.className="polycss-mesh",p.id&&w.setAttribute("data-poly-mesh-id",p.id);let $=`polycss-mesh-${v.meshAutoCounter.next++}`;w.setAttribute("data-poly-mesh-index",$);let N={...p},I=p.merge!==!1,U=!!p.stableDom,Y=0,ue=Jn(N);ue&&(w.style.transform=ue);let ie=(F,X)=>a.voxelSource?F:X?(0,te.optimizeMeshPolygons)(F,{meshResolution:p.meshResolution}):(U||p.excludeFromAutoCenter,F),K=ie(a.polygons,I),se=null;function ne(){let F=Jn(N);w.style.transform=F??""}function He(F){if(F.length===0){se=null,nt&&(nt.bboxCenterCss=null),ne();return}let X=1/0,de=1/0,ye=1/0,Fe=-1/0,pe=-1/0,Pe=-1/0;for(let Qe of F)for(let Ue of Qe.vertices)Ue[0]<X&&(X=Ue[0]),Ue[0]>Fe&&(Fe=Ue[0]),Ue[1]<de&&(de=Ue[1]),Ue[1]>pe&&(pe=Ue[1]),Ue[2]<ye&&(ye=Ue[2]),Ue[2]>Pe&&(Pe=Ue[2]);if(!Number.isFinite(X)){se=null,nt&&(nt.bboxCenterCss=null),ne();return}let $e=(de+pe)/2*cn,Ze=(X+Fe)/2*cn,Be=(ye+Pe)/2*cn;se=[$e,Ze,Be],nt&&(nt.bboxCenterCss=se),ne()}let nt=null;He(K),h.appendChild(w);let M={handle:void 0,wrapper:w,parseResult:a,rendered:[],renderedByPolygonIndex:[],shadowRendered:[],polygons:K,voxelSource:a.voxelSource,disposed:!1,stableDom:U,hasBuckets:!1,skipBucketNormalCleanupOnce:!1,excludeFromAutoCenter:!!p.excludeFromAutoCenter,castShadow:!!p.castShadow,bboxCenterCss:se,receiveShadow:!!p.receiveShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",stableTriangleColorFrame:0,solidLightingPreviewPrepared:!1,solidLightingPreviewActive:!1,bakedRotation:p.rotation?[...p.rotation]:[0,0,0],autoMeshId:$,rebakeInFlight:!1,rebakeQueuedLightDir:null,textureReadyPromise:oo},gt=null,At=0,wt=-1,ht=null;function yt(){gt=null,ht=null,wt=-1}function Fn(){let F=gt;if(!F||F.polygonCount!==M.polygons.length)return M.polygons;if(ht&&wt===At)return ht;let X=F.vertices,de=new Array(F.polygonCount);for(let ye=0;ye<F.polygonCount;ye++){let Fe=M.polygons[ye],pe=ye*9;de[ye]={...Fe,color:F.colors?.[ye]??Fe.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 ht=de,wt=At,de}function Mt(F,X){let de=F?.stableTriangleUpdateMode==="color-only";M.stableTriangleColorFrame++;let ye=M.stableDom&&!X;if(ye||He(M.polygons),M.stableDom&&!M.hasBuckets){let Fe={doc:l,directionalLight:ut(r.directionalLight),ambientLight:r.ambientLight,textureLighting:r.textureLighting,textureQuality:r.textureQuality,textureLeafSizing:r.textureLeafSizing,textureImageRendering:r.textureImageRendering,textureBackend:r.textureBackend,textureProjection:r.textureProjection,seamBleed:r.seamBleed},pe=M.rendered.length===M.polygons.length&&M.rendered.every(Be=>Be.kind==="triangle"),Pe=M.stableDom&&!X,$e=pe||Pe?{}:Bt(M.polygons,Fe);pe||Pt(M.wrapper,$e);let Ze={...Fe,solidPaintDefaults:$e,optimizeStableTriangleStyle:!0,stableTriangleDebug:F?.stableTriangleDebug,stableTriangleUpdateMode:F?.stableTriangleUpdateMode,stableTriangleColorPolicy:F?.stableTriangleColorPolicy,stableTriangleColorSteps:F?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:F?.stableTriangleColorFreezeFrames,stableTriangleColorBudget:F?.stableTriangleColorBudget,stableTriangleColorMaxAge:F?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:F?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:F?.stableTriangleMatrixDecimals,stableTriangleColorFrame:M.stableTriangleColorFrame};if(qn(M.rendered,M.polygons,Ze))return de||(C(M),fe(M,!0),X&&ft()),!0}return ye&&He(M.polygons),!1}let at={get polygons(){return Fn()},set polygons(F){yt(),M.polygons=F},element:w,id:p.id,get transform(){return N},remove(){Y++,w.parentNode&&w.parentNode.removeChild(w),V(M),f.delete(M),b.delete(w),j(M),D(M),ft(),tt()},setPolygons(F,X){Y++,I=X?.merge??I,U=X?.stableDom??U,M.stableDom=U,M.voxelSource=void 0,M.polygons=ie(F,I),D(M),j(M),yt(),at.polygons=M.polygons;let de=X?.recomputeAutoCenter??!0;Mt(X,de)||(Me(M),de&&ft())},[wi](F,X){let de=X?.merge??I,ye=X?.stableDom??U;if(!F.solidTriangles||!ye||de||p.meshResolution!==void 0||M.hasBuckets||F.polygonCount!==M.polygons.length||F.vertices.length<F.polygonCount*9||M.rendered.length!==F.polygonCount)return!1;for(let Pe=0;Pe<M.rendered.length;Pe++){let $e=M.rendered[Pe],Ze=M.polygons[Pe];if($e?.kind!=="triangle"||$e.polygonIndex!==Pe||!Ze||Ze.vertices.length!==3||Ze.texture||Ze.material?.texture)return!1}let Fe=X?.recomputeAutoCenter??!0;if(!Fe){let Pe=M.stableTriangleColorFrame+1,$e={doc:l,directionalLight:ut(r.directionalLight),ambientLight:r.ambientLight,textureLighting:r.textureLighting,textureQuality:r.textureQuality,textureLeafSizing:r.textureLeafSizing,textureImageRendering:r.textureImageRendering,textureBackend:r.textureBackend,textureProjection:r.textureProjection,seamBleed:r.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:Pe};if(Qn(M.rendered,M.polygons,F,$e))return Y++,I=de,U=ye,M.stableDom=U,M.voxelSource=void 0,M.stableTriangleColorFrame=Pe,gt=F,At++,ht=null,wt=-1,Z(M)?(C(M),fe(M,!0)):ae(M),!0}Y++,I=de,U=ye,M.stableDom=U,M.voxelSource=void 0;let pe=F.vertices;for(let Pe=0;Pe<F.polygonCount;Pe++){let $e=M.polygons[Pe],Ze=F.colors?.[Pe];Ze&&($e.color=Ze);let Be=$e.vertices,Qe=Pe*9;Be[0][0]=pe[Qe],Be[0][1]=pe[Qe+1],Be[0][2]=pe[Qe+2],Be[1][0]=pe[Qe+3],Be[1][1]=pe[Qe+4],Be[1][2]=pe[Qe+5],Be[2][0]=pe[Qe+6],Be[2][1]=pe[Qe+7],Be[2][2]=pe[Qe+8]}return yt(),at.polygons=M.polygons,Mt(X,Fe)},updatePolygon(F,X){let de=typeof F=="number"?F:M.polygons.indexOf(F);if(de<0&&typeof F!="number"&&gt&&(de=Fn().indexOf(F)),de<0||de>=M.polygons.length)return;yt(),M.voxelSource=void 0,Object.assign(M.polygons[de],X);let ye=Object.keys(X);Zt(M,de,ye)||Me(M)},async setPolygonsChunked(F,X){let de=++Y;I=X?.merge??I,U=X?.stableDom??U,M.stableDom=U,M.voxelSource=void 0,M.polygons=ie(F,I),yt(),at.polygons=M.polygons,He(M.polygons);let ye=X?.recomputeAutoCenter??!0;if(!await Hn(M,()=>M.disposed||de!==Y)){V(M);return}ye&&ft()},setTransform(F){let X=M.castShadow,de=M.receiveShadow;F.castShadow!==void 0&&(M.castShadow=!!F.castShadow),F.receiveShadow!==void 0&&(M.receiveShadow=!!F.receiveShadow),N={...N,...F};let ye=Jn(N);w.style.transform=ye??"",pt(M,N.rotation),F.rotation!==void 0&&fe(M,!0),M.castShadow!==X&&(M.voxelSource&&Me(M),Xe(M),tt()),M.receiveShadow!==de&&(M.receiveShadow||er(M),R(),_e()),(F.position!==void 0||F.scale!==void 0)&&(M.castShadow||M.receiveShadow)&&(tt(),R(),_e())},dispose(){if(!M.disposed){M.disposed=!0,Y++,w.parentNode&&w.parentNode.removeChild(w),V(M);try{a.dispose()}catch{}f.delete(M),b.delete(w),ft(),tt()}},rebakeAtlas(){M.bakedRotation=N.rotation?[...N.rotation]:[0,0,0];let F=r.directionalLight?.direction??[.4,-.7,.59],X=(0,te.inverseRotateVec3)(F,M.bakedRotation);Po(M,X)},whenTexturesReady(){return M.textureReadyPromise},getPosition(){return N.position},getRotation(){return N.rotation},getScale(){return N.scale},getPolygons(){return at.polygons}};return M.handle=at,nt=M,b.set(w,M),f.add(M),Me(M),pt(M,N.rotation),ft(),tt(),M.receiveShadow&&(R(),_e()),at}function ls(a){let p=!!r.autoCenter,S=r.strategies,w=r.seamBleed,$=r.textureLeafSizing,N=r.textureImageRendering,I=r.textureBackend,U=r.textureProjection,Y=r.textureLighting,ue=r.directionalLight?.direction,ie=r.shadow,K=Mi(a);r={...r,...K},v.options.current=r,J(h,r);let se=!!r.autoCenter;for(let F of f)pt(F,F.handle.transform.rotation);let ne=a.strategies!==void 0&&!ri(a.strategies,S),He=Object.prototype.hasOwnProperty.call(a,"seamBleed")&&K.seamBleed!==w,nt=Object.prototype.hasOwnProperty.call(a,"textureLeafSizing")&&K.textureLeafSizing!==$,M=Object.prototype.hasOwnProperty.call(a,"textureImageRendering")&&K.textureImageRendering!==N,gt=Object.prototype.hasOwnProperty.call(a,"textureBackend")&&K.textureBackend!==I,At=Object.prototype.hasOwnProperty.call(a,"textureProjection")&&K.textureProjection!==U;if(ne||He||nt||M||gt||At)for(let F of f)Me(F);p!==se&&ft();let wt=a.textureLighting!==void 0&&Y!==r.textureLighting,ht=r.directionalLight?.direction,yt=a.directionalLight!==void 0&&!ii(ue,ht),Fn=r.shadow,Mt=a.shadow!==void 0&&!si(ie,Fn),at=yt||Mt;if(wt){if(!ne&&!He&&!nt&&!M&&!gt&&!At)for(let F of f)Me(F);tt(),R(),_e()}else at&&(Mt&&R(),_e());Mt&&a.shadow?.lift!==ie?.lift&&tt()}function cs(){return r}function us(){Q(d,r),k(h);for(let a of f)fe(a)}function ds(){let a=[];for(let p of f)a.push(p.handle);return a}function ps(){return Promise.all(Array.from(f,a=>a.handle.whenTexturesReady())).then(()=>{})}function ms(a){let p=a;for(;p;){if(p instanceof HTMLElement){let S=b.get(p);if(S&&!S.disposed)return S.handle;if(p.classList.contains("polycss-mesh"))return null}p=p.parentElement}return null}function fs(){let a=Array.from(f);for(let p of a)try{p.handle.dispose()}catch{}d.parentNode&&d.parentNode.removeChild(d)}return{add:as,setOptions:ls,destroy:fs,host:e,camera:t,cameraEl:d,sceneElement:h,applyCamera:us,getOptions:cs,meshes:ds,whenTexturesReady:ps,findMeshByElement:ms,previewBakedSolidLighting:le,commitBakedSolidLighting:xo,clearBakedSolidLightingPreview:vo}}var tr=require("@layoutit/polycss-core"),Ha=32e3;function ro(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,tr.createIsometricCamera)(n),o=`${e.perspective??Ha}px`;return{get state(){return t.state},update(i){t.update(i)},getStyle(i){return t.getStyle(i)},type:"perspective",perspectiveStyle:o}}function dn(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,tr.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var Fa=typeof HTMLElement<"u"?HTMLElement:class{},Ba=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","texture-leaf-sizing","texture-image-rendering","texture-backend","texture-projection","auto-center"];function We(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function za(e){return e==="false"?!1:We(e)}function nr(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 Va(e){if(e==="baked"||e==="dynamic")return e}function Na(e){return e==="auto"?"auto":We(e)}function ja(e){if(e==="canonical"||e==="local"||e==="raster")return e}function Ga(e){if(e==="auto"||e==="pixelated")return e}function $a(e){if(e==="auto"||e==="atlas"||e==="image")return e}function Ua(e){if(e==="affine"||e==="projective")return e}function Wa(e){return typeof e.getCamera=="function"}var ke=class extends Fa{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...Ba]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(Wa(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=za(this.getAttribute("perspective")),o=We(this.getAttribute("rot-x")),i=We(this.getAttribute("rot-y")),r=We(this.getAttribute("zoom")),s=We(this.getAttribute("distance")),c=nr(this.getAttribute("target")),l={...o!==void 0?{rotX:o}:{},...i!==void 0?{rotY:i}:{},...r!==void 0?{zoom:r}:{},...s!==void 0?{distance:s}:{},...c!==void 0?{target:c}:{}};return t===!1?dn(l):t!==void 0?ro({...l,perspective:t}):dn(l)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),i={};i.textureLighting=Va(this.getAttribute("texture-lighting"))??"baked";let r=Na(this.getAttribute("texture-quality"));r!==void 0&&(i.textureQuality=r),i.textureLeafSizing=ja(this.getAttribute("texture-leaf-sizing"))??"canonical";let s=Ga(this.getAttribute("texture-image-rendering"));s!==void 0&&(i.textureImageRendering=s);let c=$a(this.getAttribute("texture-backend"));c!==void 0&&(i.textureBackend=c);let l=Ua(this.getAttribute("texture-projection"));return l!==void 0&&(i.textureProjection=l),i.autoCenter=this.hasAttribute("auto-center"),t&&(i.directionalLight=t),o&&(i.ambientLight=o),i}_readDirectionalLight(){let t=nr(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,i=We(this.getAttribute("directional-intensity"));if(!t&&!o&&i===void 0)return;let r={direction:t??[.4,-.7,.59]};return o&&(r.color=o),i!==void 0&&(r.intensity=i),r}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=We(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let i={};return t&&(i.color=t),o!==void 0&&(i.intensity=o),i}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=_i(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,i){if(o!==i&&this._scene){if(this._implicitCamera&&["rot-x","rot-y","zoom","distance","target"].includes(t)){let s=We(this.getAttribute("rot-x")),c=We(this.getAttribute("rot-y")),l=We(this.getAttribute("zoom")),d=We(this.getAttribute("distance")),h=nr(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}),d!==void 0&&this._implicitCamera.update({distance:d}),h!==void 0&&this._implicitCamera.update({target:h}),this._scene.applyCamera();return}this._scene.setOptions(this._readNonCameraOptions())}}};var io=require("@layoutit/polycss-core"),Ya=typeof HTMLElement<"u"?HTMLElement:class{},Xa=["src","mtl","mesh-resolution","position","scale","rotation","auto-center","cast-shadow","receive-shadow","target-size","default-color","palette","include-objects","exclude-objects"];function pn(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 Ri(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return pn(e)}}function or(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 Za(e){let n=e.getAttribute("target-size"),t=e.getAttribute("default-color"),o=or(e.getAttribute("palette")),i=or(e.getAttribute("include-objects")),r=or(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),i&&(c.includeObjects=i),r&&(c.excludeObjects=r),Object.keys(c).length>0?c:void 0}function Qa(e){return e.closest("poly-scene")??null}function qa(e){if(e.length===0)return e;let n=(0,io.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,i=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&i===0)return e;let r=s=>[s[0]-t,s[1]-o,s[2]-i];return e.map(s=>({...s,vertices:s.vertices.map(r),...s.textureTriangles?.length?{textureTriangles:s.textureTriangles.map(c=>({...c,vertices:c.vertices.map(r)}))}:null}))}var St=class extends Ya{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Xa]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,i){if(o!==i){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:pn(this.getAttribute("position")),scale:Ri(this.getAttribute("scale")),rotation:pn(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=Qa(this);if(!o)return;let i=++this._loadToken,r=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,l=Za(this),d;try{let f=r||c!==void 0||l?{...r?{mtlUrl:r}:{},...c!==void 0?{meshResolution:c}:{},...l?{objOptions:l}:{}}:void 0;d=await(0,io.loadMesh)(t,f)}catch(f){this.dispatchEvent(new CustomEvent("polycss:error",{detail:f,bubbles:!0}));return}if(i!==this._loadToken){try{d.dispose()}catch{}return}let h=o.getScene();if(!h){try{d.dispose()}catch{}return}this.hasAttribute("auto-center")&&(d={...d,polygons:qa(d.polygons)}),this._parseResult=d,this._handle=h.add(d,{position:pn(this.getAttribute("position")),scale:Ri(this.getAttribute("scale")),rotation:pn(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 Gt=require("@layoutit/polycss-core"),Ka=typeof HTMLElement<"u"?HTMLElement:class{},Ja=["src","width","height","position","rotation","scale","allow","loading","referrerpolicy","sandbox","title"];function rr(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 el(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return rr(e)}}function ki(e,n){if(e===null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}function tl(e){let n=e.closest("poly-scene");return n?n.querySelector(".polycss-scene"):null}function nl(e,n,t,o,i){let r=typeof t=="number"?t:t?.[0]??1,s=typeof t=="number"?t:t?.[1]??1,c=typeof t=="number"?t:t?.[2]??1,l=r!==1||s!==1||c!==1,d=!!n&&(!!n[0]||!!n[1]||!!n[2]),h=(e?.[1]??0)*Gt.BASE_TILE,v=(e?.[0]??0)*Gt.BASE_TILE,f=(e?.[2]??0)*Gt.BASE_TILE,b=[];return b.push(`translate3d(${h}px, ${v}px, ${f}px)`),d&&(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(${r}, ${s}, ${c})`),b.push(`translate(${-o/2}px, ${-i/2}px)`),b.join(" ")}var mn=class extends Ka{constructor(){super(...arguments);this._wrapper=null;this._iframe=null}static get observedAttributes(){return[...Ja]}getIframeElement(){return this._iframe}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,i){if(o!==i&&!(!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 r=this.getAttribute(t);r===null?this._iframe.removeAttribute(t):this._iframe.setAttribute(t,r);return}this._applyGeometry()}}_mount(){let t=tl(this);if(!t)return;let o=this.ownerDocument;if(!o)return;let i=o.createElement("div");i.className="polycss-iframe",i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.transformOrigin="0 0",i.style.transformStyle="preserve-3d";let r=o.createElement("iframe");r.style.display="block",r.style.border="0",r.style.background="#000";let s=this.getAttribute("src");s&&(r.src=s);let c=this.getAttribute("allow");c&&r.setAttribute("allow",c);for(let l of["loading","referrerpolicy","sandbox","title"]){let d=this.getAttribute(l);d!==null&&r.setAttribute(l,d)}i.appendChild(r),t.appendChild(i),this._wrapper=i,this._iframe=r,this._applyGeometry()}_applyGeometry(){if(!this._wrapper||!this._iframe)return;let t=ki(this.getAttribute("width"),16),o=ki(this.getAttribute("height"),9),i=t*Gt.BASE_TILE,r=o*Gt.BASE_TILE;this._iframe.style.width=`${i}px`,this._iframe.style.height=`${r}px`;let s=rr(this.getAttribute("position")),c=rr(this.getAttribute("rotation")),l=el(this.getAttribute("scale"));this._wrapper.style.transform=nl(s,c,l,i,r)}_teardown(){this._wrapper?.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null,this._iframe=null}};var ol=typeof HTMLElement<"u"?HTMLElement:class{},rl=["vertices","color","texture","uvs","position","scale","rotation"];function Di(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function ir(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 il(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return ir(e)}}function sl(e){return e.closest("poly-scene")??null}var fn=class extends ol{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...rl]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,i){o!==i&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=sl(this);if(!t)return;let o=t.getScene();if(!o)return;let i=Di(this.getAttribute("vertices"));if(!i||!Array.isArray(i)||i.length<3)return;let r=this.getAttribute("color")||void 0,s=this.getAttribute("texture")||void 0,c=Di(this.getAttribute("uvs"))??void 0,l={};for(let v of Array.from(this.attributes))v.name.startsWith("data-")&&(l[v.name.slice(5)]=v.value);let h={polygons:[{vertices:i,...r!==void 0?{color:r}:{},...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:ir(this.getAttribute("position")),scale:il(this.getAttribute("scale")),rotation:ir(this.getAttribute("rotation"))})}};var Ii=require("@layoutit/polycss-core"),al=typeof HTMLElement<"u"?HTMLElement:class{},ll=["size","thickness","negative","x-color","y-color","z-color"];function cl(e){return e.closest("poly-scene")??null}function Oi(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var gn=class extends al{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...ll]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,i){o!==i&&this._handle&&this._remount()}_polygons(){return(0,Ii.axesHelperPolygons)({size:Oi(this.getAttribute("size")),thickness:Oi(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=cl(this);if(!t)return;let o=t.getScene();if(!o)return;let i={polygons:this._polygons(),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(i,{excludeFromAutoCenter:!0,merge:!1})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var Bi=require("@layoutit/polycss-core"),ul=typeof HTMLElement<"u"?HTMLElement:class{},dl=["direction","target","distance","size","color"],pl=5,ml=.35,fl="#ffd54a";function gl(e){return e.closest("poly-scene")??null}function Hi(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 Fi(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var hn=class extends ul{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...dl]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,i){if(o!==i&&this._handle){if(t==="size"||t==="color"){this._remount();return}this._handle.setTransform({position:this._meshPosition()})}}_meshPosition(){let t=Hi(this.getAttribute("direction"));if(!t)return;let o=Hi(this.getAttribute("target"))??[0,0,0],i=Fi(this.getAttribute("distance"),pl),[r,s,c]=t,l=Math.hypot(r,s,c)||1;return[o[0]+r/l*i,o[1]+s/l*i,o[2]+c/l*i]}_mount(){let t=gl(this);if(!t)return;let o=t.getScene();if(!o)return;let i=Fi(this.getAttribute("size"),ml),r=this.getAttribute("color")??fl,s={polygons:(0,Bi.octahedronPolygons)({center:[0,0,0],size:i,color:r}),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 zi=require("@layoutit/polycss-core");var so={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function $t(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 yn(e){return e===!0?-1:e===!1?1:e}function Ut(){let e=[],n=[],t=[];function o(s){return s==="change"?e:s==="start"?n:t}function i(s){if(e.length===0)return;let c={type:"change",camera:s()},l=e.slice();for(let d of l)try{d(c)}catch(h){console.error("[polycss] controls 'change' listener threw:",h)}}function r(s,c){let l=s==="start"?n:t;if(l.length===0)return;let d={type:s,camera:c()},h=l.slice();for(let v of h)try{v(d)}catch(f){console.error(`[polycss] controls '${s}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:i,emitInteraction:r}}function Wt(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 ao(e,n,t,o,i,r){let s=!1,c=null;return{onWheel:h=>{let v=n();if(!v.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(v.dolly){let P=y.distance??0,x=Math.max(v.minDistance,Math.min(v.maxDistance,P+b*.05));e.camera.update({distance:x})}else{let P=Math.exp(-b*513e-6),x=y.zoom??1,E=Math.max(v.minZoom,Math.min(v.maxZoom,x*P));e.camera.update({zoom:E})}e.applyCamera(),s||(s=!0,r("start",o)),i(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,s=!1,r("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),s=!1}}}function lo(e,n,t,o,i,r,s){let c=null,l=0,d=b=>{if(c===null||o())return;let y=t();if(!y.animate){c=null;return}if(i())l=b;else{let P=Math.min(50,l?b-l:16.67);l=b;let x=y.animate.speed*(P/16.67),E=n.camera.state;if(y.animate.axis==="x"){let O=(((E.rotX??65)+x)%360+360)%360;n.camera.update({rotX:O})}else{let O=(((E.rotY??45)+x)%360+360)%360;n.camera.update({rotY:O})}n.applyCamera(),s(r)}c=e.requestAnimationFrame(d)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(d))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function Vi(e,n={}){let t=$t(so,n),o=e.host,i=o.ownerDocument?.defaultView??globalThis,r=null,s={x:0,y:0},c=!1,l=!1,d=Ut(),h=Wt(e),{changeListeners:v,startListeners:f,endListeners:b,listenerArray:y,emitChange:P,emitInteraction:x}=d,E=lo(i,e,()=>t,()=>l,()=>c,h,P),O=u=>{if(!(!t.drag||l)&&r===null&&u.isPrimary!==!1){u.preventDefault(),r=u.pointerId,s={x:u.clientX,y:u.clientY},o.style.cursor="grabbing";try{u.target.setPointerCapture(u.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),x("start",h)}},R=u=>{if(r===null||u.pointerId!==r||!t.drag||l)return;u.preventDefault();let m=u.clientX-s.x,L=u.clientY-s.y;s={x:u.clientX,y:u.clientY};let _=yn(t.invert),H=m/4*_,q=L/4*_,C=e.camera.state;if(u.shiftKey){let W=C.rotX??65,Z=C.rotY??45,ae=Math.max(.01,C.zoom??1),be=Math.cos(W*Math.PI/180),fe=be>=0?Math.max(.1,be):Math.min(-.1,be),he=Math.cos(Z*Math.PI/180),Le=Math.sin(Z*Math.PI/180),Ce=ae*zi.BASE_TILE,Oe=(m*Le-L*he/fe)/Ce,Ye=-(m*he+L*Le/fe)/Ce,et=C.target??[0,0,0];e.camera.update({target:[et[0]+Oe,et[1]+Ye,et[2]]})}else{let W=Math.max(0,Math.min(89,(C.rotX??65)-q)),Z=(((C.rotY??45)-H)%360+360)%360;e.camera.update({rotX:W,rotY:Z})}e.applyCamera(),P(h)},j=u=>{if(r===u.pointerId){r=null,o.style.cursor=t.drag&&!l?"grab":"";try{u.target.releasePointerCapture(u.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),x("end",h)}},D=ao(e,()=>t,()=>l,h,P,x);function Q(){o.addEventListener("pointerdown",O),o.addEventListener("pointermove",R),o.addEventListener("pointerup",j),o.addEventListener("pointercancel",j),o.addEventListener("wheel",D.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function J(){o.removeEventListener("pointerdown",O),o.removeEventListener("pointermove",R),o.removeEventListener("pointerup",j),o.removeEventListener("pointercancel",j),o.removeEventListener("wheel",D.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",D.teardown()}Q(),E.start();function k(u){let m=!!t.animate;t=$t(t,u),!l&&r===null&&(o.style.cursor=t.drag?"grab":"");let L=!!t.animate;m&&!L?E.stop():!m&&L&&E.start()}function V(){l&&(l=!1,Q(),E.start())}function z(){l||(l=!0,J(),E.stop(),r=null,c=!1,D.teardown())}function B(){z(),v.length=0,f.length=0,b.length=0}function A(u,m){let L=y(u);L.includes(m)||L.push(m)}function g(u,m){let L=y(u),_=L.indexOf(m);_>=0&&L.splice(_,1)}function T(u,m){return y(u).includes(m)}return{update:k,resume:V,pause:z,destroy:B,addEventListener:A,removeEventListener:g,hasEventListener:T}}function re(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function co(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 De(e){if(e!==null)return!(e==="false"||e==="0")}function uo(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 po(e){if(e==="x"||e==="y")return e}var hl=typeof HTMLElement<"u"?HTMLElement:class{},yl=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],bn=class extends hl{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...yl]}getControls(){return this._controls}_readAnimate(){let t=re(this.getAttribute("animate-speed")),o=po(this.getAttribute("animate-axis")),i=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}:{},...i!==null?{pauseOnInteraction:De(i)}:{}}}_readOptions(){let t={},o=De(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let i=De(this.getAttribute("wheel"));i!==void 0&&(t.wheel=i),this.hasAttribute("dolly")&&(t.dolly=!0);let r=re(this.getAttribute("min-distance"));r!==void 0&&(t.minDistance=r);let s=re(this.getAttribute("max-distance"));s!==void 0&&(t.maxDistance=s);let c=uo(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=re(this.getAttribute("zoom-min")),d=re(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),d!==void 0&&(t.maxZoom=d),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof ke)return t;t=t.parentNode}return null}_attach(){if(this._controls)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._controls=Vi(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,i){o!==i&&this._controls&&this._controls.update(this._readOptions())}};var Ni=require("@layoutit/polycss-core");function ji(e,n={}){let t=$t(so,n),o=e.host,i=o.ownerDocument?.defaultView??globalThis,r=null,s={x:0,y:0},c=!1,l=!1,d=!1,h={x:0,y:0},v=Ut(),f=Wt(e),{changeListeners:b,startListeners:y,endListeners:P,listenerArray:x,emitChange:E,emitInteraction:O}=v,R=lo(i,e,()=>t,()=>l,()=>c,f,E),j=C=>{if(!(!t.drag||l)&&r===null&&C.isPrimary!==!1){C.preventDefault(),r=C.pointerId,s={x:C.clientX,y:C.clientY},o.style.cursor="grabbing";try{C.target.setPointerCapture(C.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),O("start",f)}},D=C=>{if(r===null||C.pointerId!==r||!t.drag||l)return;C.preventDefault();let W=C.clientX-s.x,Z=C.clientY-s.y;s={x:C.clientX,y:C.clientY};let ae=e.camera.state;if(C.shiftKey){let be=yn(t.invert),fe=W/4*be,he=Z/4*be,Le=(ae.rotX??65)-he,Ce=(((ae.rotY??45)-fe)%360+360)%360;e.camera.update({rotX:Le,rotY:Ce})}else{let be=ae.rotX??65,fe=ae.rotY??45,he=Math.max(.01,ae.zoom??1),Le=Math.cos(be*Math.PI/180),Ce=Le>=0?Math.max(.1,Le):Math.min(-.1,Le),Oe=Math.cos(fe*Math.PI/180),Ye=Math.sin(fe*Math.PI/180),et=he*Ni.BASE_TILE,pt=(W*Ye-Z*Oe/Ce)/et,Tt=-(W*Oe+Z*Ye/Ce)/et,mt=ae.target??[0,0,0];e.camera.update({target:[mt[0]+pt,mt[1]+Tt,mt[2]]})}e.applyCamera(),E(f)},Q=C=>{if(r===C.pointerId){r=null,o.style.cursor=t.drag&&!l?"grab":"";try{C.target.releasePointerCapture(C.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),O("end",f)}},J=C=>{C.preventDefault()},k=C=>{C.button===2&&(d=!0,h={x:C.clientX,y:C.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),O("start",f))},V=C=>{if(!d||!t.drag)return;let W=C.clientX-h.x,Z=C.clientY-h.y;h={x:C.clientX,y:C.clientY};let ae=yn(t.invert),be=W/4*ae,fe=Z/4*ae,he=e.camera.state,Le=(he.rotX??65)-fe,Ce=(((he.rotY??45)-be)%360+360)%360;e.camera.update({rotX:Le,rotY:Ce}),e.applyCamera(),E(f)},z=C=>{C.button===2&&d&&(d=!1,O("end",f))},B=ao(e,()=>t,()=>l,f,E,O);function A(){o.addEventListener("pointerdown",j),o.addEventListener("pointermove",D),o.addEventListener("pointerup",Q),o.addEventListener("pointercancel",Q),o.addEventListener("wheel",B.onWheel,{passive:!1}),o.addEventListener("contextmenu",J),o.addEventListener("mousedown",k),o.addEventListener("mousemove",V),o.addEventListener("mouseup",z),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function g(){o.removeEventListener("pointerdown",j),o.removeEventListener("pointermove",D),o.removeEventListener("pointerup",Q),o.removeEventListener("pointercancel",Q),o.removeEventListener("wheel",B.onWheel),o.removeEventListener("contextmenu",J),o.removeEventListener("mousedown",k),o.removeEventListener("mousemove",V),o.removeEventListener("mouseup",z),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",B.teardown()}A(),R.start();function T(C){let W=!!t.animate;t=$t(t,C),!l&&r===null&&(o.style.cursor=t.drag?"grab":"");let Z=!!t.animate;W&&!Z?R.stop():!W&&Z&&R.start()}function u(){l&&(l=!1,A(),R.start())}function m(){l||(l=!0,g(),R.stop(),r=null,c=!1,d=!1,B.teardown())}function L(){m(),b.length=0,y.length=0,P.length=0}function _(C,W){let Z=x(C);Z.includes(W)||Z.push(W)}function H(C,W){let Z=x(C),ae=Z.indexOf(W);ae>=0&&Z.splice(ae,1)}function q(C,W){return x(C).includes(W)}return{update:T,resume:u,pause:m,destroy:L,addEventListener:_,removeEventListener:H,hasEventListener:q}}var bl=typeof HTMLElement<"u"?HTMLElement:class{},xl=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],xn=class extends bl{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...xl]}_readAnimate(){let t=re(this.getAttribute("animate-speed")),o=po(this.getAttribute("animate-axis")),i=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}:{},...i!==null?{pauseOnInteraction:De(i)}:{}}}_readOptions(){let t={},o=De(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let i=De(this.getAttribute("wheel"));i!==void 0&&(t.wheel=i),this.hasAttribute("dolly")&&(t.dolly=!0);let r=re(this.getAttribute("min-distance"));r!==void 0&&(t.minDistance=r);let s=re(this.getAttribute("max-distance"));s!==void 0&&(t.maxDistance=s);let c=uo(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=re(this.getAttribute("zoom-min")),d=re(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),d!==void 0&&(t.maxZoom=d),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof ke)return t;t=t.parentNode}return null}_attach(){if(this._controls)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._controls=ji(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,i){o!==i&&this._controls&&this._controls.update(this._readOptions())}};var Zi=require("@layoutit/polycss-core");var vl={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 Gi(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 $i=new Set(["KeyW","ArrowUp"]),Ui=new Set(["KeyS","ArrowDown"]),Wi=new Set(["KeyA","ArrowLeft"]),Yi=new Set(["KeyD","ArrowRight"]),Xi=new Set(["Space"]),sr=new Set(["ControlLeft","ControlRight"]);function Qi(e,n={}){let t=Gi(vl,n),o=e.host,i=e.cameraEl,r=o.ownerDocument??document,s=r.defaultView??globalThis,c=Ut(),l=Wt(e),{changeListeners:d,startListeners:h,endListeners:v,listenerArray:f,emitChange:b,emitInteraction:y}=c,P=new Set,x=!1,E=!1,O=0,R=0,j=!1,D=[0,0,t.groundZ+t.eyeHeight];function Q(G,le){let ce=G*Math.PI/180,Ie=le*Math.PI/180;return[-Math.sin(ce)*Math.cos(Ie),-Math.sin(ce)*Math.sin(Ie),-Math.cos(ce)]}function J(){let G=e.camera.perspectiveStyle,le=G==="none"?0:parseFloat(G);return(Number.isFinite(le)&&le>0?le:2e3)/Zi.BASE_TILE}function k(){let G=e.camera.state,le=Q(G.rotX??90,G.rotY??0),ce=J();return[D[0]+le[0]*ce,D[1]+le[1]*ce,D[2]+le[2]*ce]}function V(){let G=k();e.camera.update({target:G}),e.applyCamera()}function z(){let G=e.camera.state.target??[0,0,0];D=[G[0],G[1],t.groundZ+t.eyeHeight],V()}let B=()=>{if(!(!t.enabled||!t.lookEnabled||E||x))try{o.requestPointerLock()}catch{}},A=()=>{let G=r.pointerLockElement===o;G!==x&&(x=G,x?(j=!0,y("start",l)):j&&(j=!1,y("end",l)))},g=G=>{if(!x||!t.enabled||!t.lookEnabled||E)return;let le=G.movementX??0,ce=G.movementY??0;if(le===0&&ce===0)return;let Ie=e.camera.state,Zt=t.lookSensitivity,Xe=t.invertY?-1:1,_e=(((Ie.rotY??0)-le*Zt)%360+360)%360,Ee=(Ie.rotX??90)-ce*Zt*Xe;Ee<t.minPitch?Ee=t.minPitch:Ee>t.maxPitch&&(Ee=t.maxPitch);let je=Q(Ee,_e),Ge=J(),Me=[D[0]+je[0]*Ge,D[1]+je[1]*Ge,D[2]+je[2]*Ge];e.camera.update({rotX:Ee,rotY:_e,target:Me}),e.applyCamera(),b(l)},T=G=>$i.has(G)||Ui.has(G)||Wi.has(G)||Yi.has(G)||Xi.has(G)||sr.has(G),u=G=>{if(!(!t.enabled||E)&&T(G.code)&&!(!x&&!t.moveEnabled)){if(Xi.has(G.code)){if(!t.jumpEnabled)return;G.preventDefault(),!P.has(G.code)&&O===0&&R===0&&(O=t.jumpVelocity),P.add(G.code);return}sr.has(G.code)&&!t.crouchEnabled||!t.moveEnabled&&!sr.has(G.code)||(G.preventDefault(),P.add(G.code))}},m=G=>{T(G.code)&&P.delete(G.code)},L=()=>{P.clear()},_=null,H=0,q=.05,C=G=>{if(_===null||E)return;let le=Math.min(q,H?(G-H)/1e3:.0167);if(H=G,t.enabled){let ce=!1,Ie=e.camera.state;if(t.moveEnabled){let Ee=0,je=0;for(let Ge of P)$i.has(Ge)?Ee+=1:Ui.has(Ge)?Ee-=1:Yi.has(Ge)?je+=1:Wi.has(Ge)&&(je-=1);if(Ee!==0||je!==0){let Me=(Ie.rotY??0)*Math.PI/180,Qt=-Math.cos(Me),Po=-Math.sin(Me),So=-Math.sin(Me),Co=Math.cos(Me),tt=Math.hypot(Ee,je)||1,Hn=t.moveSpeed*le;D[0]+=(Qt*Ee+So*je)/tt*Hn,D[1]+=(Po*Ee+Co*je)/tt*Hn,ce=!0}}let Xe=t.crouchEnabled&&(P.has("ControlLeft")||P.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(O!==0||R>0)?(O-=t.gravity*le,R+=O*le,R<=0&&(R=0,O=0)):t.jumpEnabled||(R=0,O=0);let _e=t.groundZ+Xe+R;if(Math.abs(D[2]-_e)>1e-4&&(D[2]=_e,ce=!0),ce){let Ee=k();e.camera.update({target:Ee}),e.applyCamera(),b(l)}}_=s.requestAnimationFrame(C)};function W(){_!==null||E||(H=0,_=s.requestAnimationFrame(C))}function Z(){_!==null&&(s.cancelAnimationFrame(_),_=null)}function ae(){let le=i.ownerDocument?.defaultView?.getComputedStyle(i).perspective??"",ce=parseFloat(le),Ie=Number.isFinite(ce)&&ce>0?ce:2e3;i.style.setProperty("--polycss-fpv-perspective",`${Ie}px`),i.classList.add("polycss-fpv-host")}function be(){i.classList.remove("polycss-fpv-host"),i.style.removeProperty("--polycss-fpv-perspective")}function fe(){o.addEventListener("click",B),r.addEventListener("pointerlockchange",A),r.addEventListener("mousemove",g),s.addEventListener("keydown",u),s.addEventListener("keyup",m),s.addEventListener("blur",L),o.style.cursor=t.lookEnabled?"crosshair":"",ae()}function he(){if(o.removeEventListener("click",B),r.removeEventListener("pointerlockchange",A),r.removeEventListener("mousemove",g),s.removeEventListener("keydown",u),s.removeEventListener("keyup",m),s.removeEventListener("blur",L),o.style.cursor="",P.clear(),x)try{r.exitPointerLock()}catch{}be()}z(),fe(),W();function Le(G){let le=t.eyeHeight,ce=t.groundZ;t=Gi(t,G),E||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==le||t.groundZ!==ce)&&(D[2]=t.groundZ+t.eyeHeight,V(),b(l))}function Ce(){E&&(E=!1,fe(),W())}function Oe(){E||(E=!0,he(),Z(),j&&(j=!1,y("end",l)))}function Ye(){Oe(),d.length=0,h.length=0,v.length=0}function et(){if(!(!t.enabled||!t.lookEnabled||E))try{o.requestPointerLock()}catch{}}function pt(){if(x)try{r.exitPointerLock()}catch{}}function Tt(){return x}function mt(G,le){let ce=f(G);ce.includes(le)||ce.push(le)}function yo(G,le){let ce=f(G),Ie=ce.indexOf(le);Ie>=0&&ce.splice(Ie,1)}function bo(G,le){return f(G).includes(le)}function xo(){return[D[0],D[1],D[2]]}function vo(G){D[0]=G[0],D[1]=G[1],D[2]=G[2],V(),b(l)}return{update:Le,resume:Ce,pause:Oe,destroy:Ye,lock:et,unlock:pt,isLocked:Tt,getOrigin:xo,setOrigin:vo,addEventListener:mt,removeEventListener:yo,hasEventListener:bo}}var Pl=typeof HTMLElement<"u"?HTMLElement:class{},Sl=["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"],vn=class extends Pl{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Sl]}_readOptions(){let t={},o=De(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let i=De(this.getAttribute("look-enabled"));i!==void 0&&(t.lookEnabled=i);let r=De(this.getAttribute("move-enabled"));r!==void 0&&(t.moveEnabled=r);let s=De(this.getAttribute("jump-enabled"));s!==void 0&&(t.jumpEnabled=s);let c=De(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let l=re(this.getAttribute("look-sensitivity"));if(l!==void 0&&(t.lookSensitivity=l),this.hasAttribute("invert-y")){let E=De(this.getAttribute("invert-y"));E!==void 0&&(t.invertY=E)}let d=re(this.getAttribute("move-speed"));d!==void 0&&(t.moveSpeed=d);let h=re(this.getAttribute("jump-velocity"));h!==void 0&&(t.jumpVelocity=h);let v=re(this.getAttribute("gravity"));v!==void 0&&(t.gravity=v);let f=re(this.getAttribute("eye-height"));f!==void 0&&(t.eyeHeight=f);let b=re(this.getAttribute("crouch-height"));b!==void 0&&(t.crouchHeight=b);let y=re(this.getAttribute("ground-z"));y!==void 0&&(t.groundZ=y);let P=re(this.getAttribute("min-pitch"));P!==void 0&&(t.minPitch=P);let x=re(this.getAttribute("max-pitch"));return x!==void 0&&(t.maxPitch=x),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof ke)return t;t=t.parentNode}return null}_attach(){if(this._controls)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._controls=Qi(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,i){o!==i&&this._controls&&this._controls.update(this._readOptions())}};var Cl=typeof HTMLElement<"u"?HTMLElement:class{},El=["perspective","zoom","rot-x","rot-y","target","distance"],Pn=class extends Cl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...El]}getCamera(){return this._camera}_readOptions(){return{perspective:re(this.getAttribute("perspective")),zoom:re(this.getAttribute("zoom")),rotX:re(this.getAttribute("rot-x")),rotY:re(this.getAttribute("rot-y")),target:co(this.getAttribute("target")),distance:re(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=ro(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,i){if(o===i||!this._camera||!this._wrapper)return;let r=this._readOptions();if(t==="perspective"){let l=r.perspective!==void 0?`${r.perspective}px`:"32000px";this._wrapper.style.perspective=l;return}this._camera.update({rotX:r.rotX,rotY:r.rotY,zoom:r.zoom,target:r.target,distance:r.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var Tl=typeof HTMLElement<"u"?HTMLElement:class{},Al=["zoom","rot-x","rot-y","target","distance"],Ct=class extends Tl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Al]}getCamera(){return this._camera}_readOptions(){return{zoom:re(this.getAttribute("zoom")),rotX:re(this.getAttribute("rot-x")),rotY:re(this.getAttribute("rot-y")),target:co(this.getAttribute("target")),distance:re(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=dn(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,i){if(o===i||!this._camera)return;let r=this._readOptions();r.zoom!==void 0&&this._camera.update({zoom:r.zoom}),r.rotX!==void 0&&this._camera.update({rotX:r.rotX}),r.rotY!==void 0&&this._camera.update({rotY:r.rotY}),r.target!==void 0&&this._camera.update({target:r.target}),r.distance!==void 0&&this._camera.update({distance:r.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var Sn=class extends Ct{};var we=require("@layoutit/polycss-core");function Yt(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let i of o){let r=i.getBoundingClientRect();if(!(r.width<=0||r.height<=0)&&n>=r.left&&n<=r.right&&t>=r.top&&t<=r.bottom)return!0}return!1}function qi(e,n,t,o){for(let i of e)if(!(o&&!o(i))&&Yt(i.element,n,t))return i;return null}var mo="#ff3653",fo="#8adb00",go="#2c8fff",Xt=50,Ki=60,wl=.6,Ml=.0125,Ll=.15,_l=.04,Rl=1,Ji=.02,ar=1.04,kl=.1,Dl=.25,os=1e-4,Ol=.6,Il=.8,Hl=1,st={0:1,1:0,2:2},es=[{cssAxis:0,sign:1,key:"x",color:mo},{cssAxis:0,sign:-1,key:"-x",color:mo},{cssAxis:1,sign:1,key:"y",color:fo},{cssAxis:1,sign:-1,key:"-y",color:fo},{cssAxis:2,sign:1,key:"z",color:go},{cssAxis:2,sign:-1,key:"-z",color:go}],ts=[{cssAxis:0,key:"x",color:mo},{cssAxis:1,key:"y",color:fo},{cssAxis:2,key:"z",color:go}],ns=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:go},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:fo},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:mo}];function lr(e,n,t,o){let i=t*Math.PI/180,r=o*Math.PI/180,s=[0,0,0];s[e]=n;let c=s[0]*Math.cos(r)-s[1]*Math.sin(r),l=s[0]*Math.sin(r)+s[1]*Math.cos(r),d=s[2];return l*Math.sin(i)+d*Math.cos(i)<0}function Fl(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),i=parseInt(t[2],16),r=parseInt(t[3],16);return`rgba(${o}, ${i}, ${r}, ${n})`}function ho(e,n){return!n||n<=0?e:Math.round(e/n)*n}function Bl(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,i=-1/0,r=-1/0,s=-1/0;for(let c of e)for(let l of c.vertices)l[0]<n&&(n=l[0]),l[0]>i&&(i=l[0]),l[1]<t&&(t=l[1]),l[1]>r&&(r=l[1]),l[2]<o&&(o=l[2]),l[2]>s&&(s=l[2]);return Number.isFinite(n)?[(n+i)/2,(t+r)/2,(o+s)/2]:[0,0,0]}function cr(e){if(e.length===0)return Ki;let n=1/0,t=1/0,o=1/0,i=-1/0,r=-1/0,s=-1/0;for(let l of e)for(let d of l.vertices)d[0]<n&&(n=d[0]),d[0]>i&&(i=d[0]),d[1]<t&&(t=d[1]),d[1]>r&&(r=d[1]),d[2]<o&&(o=d[2]),d[2]>s&&(s=d[2]);return Number.isFinite(n)?Math.max(i-n,r-t,s-o)*Xt*wl:Ki}function zl(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:i,target:r,startClientX:s,startClientY:c,translationSnap:l,onAxisDelta:d,onMouseDown:h,onMouseUp:v,onDraggingChanged:f}=e,b=o,y=[0,0,0];y[n]=t;let P=i.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)`,i.appendChild(P);let x=i.getBoundingClientRect(),E=P.getBoundingClientRect();i.removeChild(P);let O=(E.left-x.left)/b,R=(E.top-x.top)/b,j=O*O+R*R;if(j<os)return;h?.(),f?.(!0);let D=J=>{let k=J.clientX-s,V=J.clientY-c,z=(k*O+V*R)/j;z=ho(z,l),d(z,y)},Q=()=>{window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",Q),window.removeEventListener("pointercancel",Q);let J=k=>{k.stopPropagation(),k.stopImmediatePropagation()};window.addEventListener("click",J,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",J,!0),0),v?.(),f?.(!1)};window.addEventListener("pointermove",D),window.addEventListener("pointerup",Q),window.addEventListener("pointercancel",Q)}function Vl(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:i,startClientX:r,startClientY:s,translationSnap:c,onPlaneDelta:l,onMouseDown:d,onMouseUp:h,onDraggingChanged:v}=e,f=[0,0,0];f[n]=1;let b=[0,0,0];b[t]=1;function y(j){let D=i.ownerDocument.createElement("div");D.style.position="absolute",D.style.left="0",D.style.top="0",D.style.width="0",D.style.height="0",D.style.transform=`translate3d(${j[0]*o}px, ${j[1]*o}px, ${j[2]*o}px)`,i.appendChild(D);let Q=i.getBoundingClientRect(),J=D.getBoundingClientRect();return i.removeChild(D),{x:(J.left-Q.left)/o,y:(J.top-Q.top)/o}}let P=y(f),x=y(b),E=P.x*x.y-x.x*P.y;if(Math.abs(E)<os)return;d?.(),v?.(!0);let O=j=>{let D=j.clientX-r,Q=j.clientY-s,J=(x.y*D-x.x*Q)/E,k=(-P.y*D+P.x*Q)/E;J=ho(J,c),k=ho(k,c),l(J,k,f,b)},R=()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",R),window.removeEventListener("pointercancel",R);let j=D=>{D.stopPropagation(),D.stopImmediatePropagation()};window.addEventListener("click",j,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",j,!0),0),h?.(),v?.(!1)};window.addEventListener("pointermove",O),window.addEventListener("pointerup",R),window.addEventListener("pointercancel",R)}function Nl(e){let{cssAxis:n,wrapper:t,target:o,startClientX:i,startClientY:r,rotationSnap:s,onAngleDelta:c,onMouseDown:l,onMouseUp:d,onDraggingChanged:h}=e,v=t.getBoundingClientRect(),f=v.left,b=v.top,y=Math.atan2(r-b,i-f),P=0;l?.(),h?.(!0);let x=O=>{let R=Math.atan2(O.clientY-b,O.clientX-f),j=R-y;j>Math.PI?j-=2*Math.PI:j<-Math.PI&&(j+=2*Math.PI),P+=j,y=R;let D=P*180/Math.PI;D=ho(D,s),c(D)},E=()=>{window.removeEventListener("pointermove",x),window.removeEventListener("pointerup",E),window.removeEventListener("pointercancel",E);let O=R=>{R.stopPropagation(),R.stopImmediatePropagation()};window.addEventListener("click",O,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",O,!0),0),d?.(),h?.(!1)};window.addEventListener("pointermove",x),window.addEventListener("pointerup",E),window.addEventListener("pointercancel",E)}function rs(e,n={}){let t=null,o=n.mode??"translate",i=n.size??1,r={...n},s=new Map,c=null,l=null,d=[0,0,0];function h(){if(!t)return[0,0,0];let g=t.transform.position??[0,0,0],T=t.transform.rotation??[0,0,0],u=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,m=(0,we.rotateVec3)(d,T[0],T[1],T[2]);return[g[0]+u*m[0],g[1]+u*m[1],g[2]+u*m[2]]}function v(g){return l===g?Hl:c===g?Il:Ol}function f(){for(let[g,T]of s){let u=b(T.spec,v(g));T.handle.setPolygons(u,{recomputeAutoCenter:!1})}}function b(g,T){let m=cr(t?.polygons??[])*i,L=m/Xt,_=Fl(g.color,T);if(g.kind==="arrow"){let C=e.camera.state,W=lr(g.cssAxis,g.sign,C.rotX??65,C.rotY??45);return(0,we.arrowPolygons)({axis:st[g.cssAxis],sign:g.sign,shaftLength:L,shaftHalfThickness:L*Ml,headLength:L*Ll,headHalfThickness:L*_l,color:_,shaft:!W})}if(g.kind==="plane"){let C=e.camera.state,W=C.rotX??65,Z=C.rotY??45,ae=st[g.perpAxis],be=(ae+1)%3,fe=(ae+2)%3,he=st[be],Le=st[fe],Ce=lr(he,1,W,Z)?-1:1,Oe=lr(Le,1,W,Z)?-1:1,Ye=L*Dl;return(0,we.planePolygons)({axis:ae,size:L*kl,offset:[Ce*Ye,Oe*Ye],color:_})}let q=m*Rl/Xt*ar;return(0,we.ringQuadPolygons)({axis:st[g.cssAxis],outerRadius:q,color:_})}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=es.map(u=>({kind:"arrow",key:u.key,cssAxis:u.cssAxis,sign:u.sign,color:u.color})),T=ns.map(u=>({kind:"plane",key:u.key,perpAxis:u.perpAxis,axisA:u.axisA,axisB:u.axisB,color:u.color}));return[...g,...T]}return o==="rotate"?ts.map(g=>({kind:"ring",key:g.key,cssAxis:g.cssAxis,color:g.color})):[]}function x(){if(E(),!t)return;let g={x:r.showX!==!1,y:r.showY!==!1,z:r.showZ!==!1};function T(m){if(m.kind==="arrow"){let H=m.key.replace("-","")[0];return g[H]}if(m.kind==="ring")return g[m.key];let L=["x","y","z"][m.axisA],_=["x","y","z"][m.axisB];return g[L]&&g[_]}let u=h();for(let m of P()){if(!T(m))continue;let L=b(m,v(m.key)),_=e.add({polygons:L,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${m.key}`,position:u}),H=y(m);if(_.element.classList.add("polycss-transform-gizmo",H,`${H}--${m.key}`),m.kind==="ring"){let q=(1-Ji)/ar,C=(1+Ji)/ar;_.element.style.setProperty("--ring-inner-ratio",`${q}`),_.element.style.setProperty("--ring-outer-ratio",`${C}`)}s.set(m.key,{handle:_,spec:m})}}function E(){for(let{handle:g}of s.values())g.remove();s.clear(),c=null,l=null}function O(){if(!t)return;let g=h();for(let{handle:T}of s.values())T.setTransform({position:g})}function R(){t&&(s.size===0?x():O())}function j(g){if(t=g,!g){d=[0,0,0],E();return}d=Bl(g.polygons),E(),x()}function D(){j(null)}function Q(g){g!==o&&(o=g,t&&(E(),x()))}function J(g,T,u){if(!t||!k)return;let m=u[g.cssAxis],L=st[g.cssAxis],_=T*m/Xt,H=k.slice();H[L]=k[L]+_,t.setTransform({position:H}),O(),r.onObjectChange?.({object:t,position:H}),r.onChange?.()}let k=null,V=null,z=g=>{if(!t||r.enabled===!1)return;let T={x:r.showX!==!1,y:r.showY!==!1,z:r.showZ!==!1};if(o==="translate"){for(let u of ns){let m=["x","y","z"][u.axisA],L=["x","y","z"][u.axisB];if(!T[m]||!T[L])continue;let _=s.get(u.key);if(_&&Yt(_.handle.element,g.clientX,g.clientY)){g.preventDefault(),g.stopPropagation(),l=u.key,f(),k=(t.transform.position??[0,0,0]).slice(),Vl({axisA:u.axisA,axisB:u.axisB,probeDistanceCss:cr(t.polygons)*i,wrapper:_.handle.element,target:t,startClientX:g.clientX,startClientY:g.clientY,translationSnap:r.translationSnap??null,onPlaneDelta:(H,q,C,W)=>{if(!t||!k)return;let Z=C[u.axisA],ae=W[u.axisB],be=st[u.axisA],fe=st[u.axisB],he=k.slice();he[be]+=H*Z/Xt,he[fe]+=q*ae/Xt,t.setTransform({position:he}),O(),r.onObjectChange?.({object:t,position:he}),r.onChange?.()},onMouseDown:r.onMouseDown,onMouseUp:r.onMouseUp,onDraggingChanged:H=>{H||(l=null,k=null,f()),r.onDraggingChanged?.(H)}});return}}for(let u of es){let m=u.key.replace("-","")[0];if(!T[m])continue;let L=s.get(u.key);if(L&&Yt(L.handle.element,g.clientX,g.clientY)){g.preventDefault(),g.stopPropagation(),l=u.key,f(),k=(t.transform.position??[0,0,0]).slice(),zl({cssAxis:u.cssAxis,sign:u.sign,shaftLengthCss:cr(t.polygons)*i,wrapper:L.handle.element,target:t,startClientX:g.clientX,startClientY:g.clientY,translationSnap:r.translationSnap??null,onAxisDelta:(_,H)=>J(u,_,H),onMouseDown:r.onMouseDown,onMouseUp:r.onMouseUp,onDraggingChanged:_=>{_||(l=null,k=null,f()),r.onDraggingChanged?.(_)}});return}}}else if(o==="rotate")for(let u of ts){if(!T[u.key])continue;let m=s.get(u.key);if(m&&Yt(m.handle.element,g.clientX,g.clientY)){g.preventDefault(),g.stopPropagation(),l=u.key,f(),V=(t.transform.rotation??[0,0,0]).slice(),k=(t.transform.position??[0,0,0]).slice(),Nl({cssAxis:u.cssAxis,wrapper:m.handle.element,target:t,startClientX:g.clientX,startClientY:g.clientY,rotationSnap:r.rotationSnap??null,onAngleDelta:L=>{if(!t||!V||!k)return;let _=st[u.cssAxis],H=[0,0,0];H[_]=1;let q=-L*Math.PI/180,C=(0,we.quatFromEulerXYZ)(V),W=(0,we.quatFromAxisAngle)(H,q),Z=(0,we.eulerXYZFromQuat)((0,we.quatMultiply)(W,C)),ae=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,be=(0,we.rotateVec3)(d,V[0],V[1],V[2]),fe=(0,we.rotateVec3)(d,Z[0],Z[1],Z[2]),he=[k[0]+ae*(be[0]-fe[0]),k[1]+ae*(be[1]-fe[1]),k[2]+ae*(be[2]-fe[2])];t.setTransform({rotation:Z,position:he}),O(),r.onObjectChange?.({object:t,rotation:Z,position:he}),r.onChange?.()},onMouseDown:r.onMouseDown,onMouseUp:r.onMouseUp,onDraggingChanged:L=>{L||(l=null,V=null,k=null,f(),t?.rebakeAtlas()),r.onDraggingChanged?.(L)}});return}}};e.host.addEventListener("pointerdown",z,{capture:!0});let B=g=>{if(!t||l||r.enabled===!1)return;let T=null;for(let[u,m]of s)if(Yt(m.handle.element,g.clientX,g.clientY)){T=u;break}T!==c&&(c=T,f())};e.host.addEventListener("pointermove",B);function A(){e.host.removeEventListener("pointerdown",z,{capture:!0}),e.host.removeEventListener("pointermove",B),E()}return{attach:j,detach:D,setMode:Q,update:R,destroy:A}}var jl=typeof HTMLElement<"u"?HTMLElement:class{},Gl=["mode","target","size","enabled"];function is(e){if(e==="translate"||e==="rotate")return e}var Cn=class extends jl{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Gl]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof ke)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 i=null;try{i=o.querySelector(`#${t}`)??o.querySelector(t)}catch{i=o.querySelector(`[id="${t}"]`)}return i instanceof St?i:null}_readOptions(){let t={},o=is(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let i=re(this.getAttribute("size"));i!==void 0&&(t.size=i);let r=this.getAttribute("enabled");return r!==null&&(t.enabled=r!=="false"&&r!=="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 r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._tc=rs(o,this._readOptions());let i=this._findTargetMesh();if(i){let r=i.getMeshHandle();r&&this._tc.attach(r)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,i){if(o!==i&&this._tc){if(t==="mode"){let r=is(i);r&&this._tc.setMode(r)}else if(t==="target"){let r=this._findTargetMesh();this._tc.attach(r?r.getMeshHandle()??null:null)}}}};function ss(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function i(){t=n.filter?n.filter(t):t;for(let P of o)try{P(t)}catch(x){console.error("[polycss/createSelect] onChange threw:",x)}}function r(y){t=y,i()}function s(y){n.multiple?t.includes(y)||(t=[...t,y]):t=[y],i()}function c(y){t.includes(y)&&(t=t.filter(P=>P!==y),i())}function l(y){t.includes(y)?t=t.filter(P=>P!==y):n.multiple?t=[...t,y]:t=[y],i()}function d(){t.length!==0&&(t=[],i())}function h(y){return t.includes(y)}function v(y,P){return qi(e.meshes(),y,P,x=>!x.element.classList.contains("polycss-transform-gizmo"))}let f=y=>{let P=y.target;if(P?.closest(".polycss-transform-gizmo"))return;let x=e.findMeshByElement(P)??v(y.clientX,y.clientY);if(!x){n.onPointerMissed&&n.onPointerMissed(y),n.clearOnMiss!==!1&&d();return}n.multiple&&(y.shiftKey||y.metaKey||y.ctrlKey)?l(x):t.length===1&&t[0]===x?d():r([x])};e.host.addEventListener("click",f);function b(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:r,add:s,remove:c,toggle:l,clear:d,has:h,destroy:b}}var $l=typeof HTMLElement<"u"?HTMLElement:class{},Ul=["multiple","clear-on-miss"],En=class extends $l{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Ul]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof ke)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 i=()=>{t.removeEventListener("polycss:scene-ready",i),this._attach()};t.addEventListener("polycss:scene-ready",i)}return}this._selection=ss(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,i){o!==i&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};var ge=require("@layoutit/polycss-core"),Wl=typeof HTMLElement<"u"?HTMLElement:class{};function Yl(e){return e.closest("poly-scene")??null}function ve(e,n,t){let o=e.getAttribute(n);if(!o)return t;let i=parseFloat(o);return Number.isFinite(i)?i:t}function Je(e,n,t){return e.getAttribute(n)??t}function Et(e,n){let t=e.getAttribute(n);if(!t)return;let o=t.split(",").map(i=>parseFloat(i.trim()));if(!(o.length!==3||o.some(i=>!Number.isFinite(i))))return[o[0],o[1],o[2]]}function Xl(e){if(e.length===0)return e;let n=(0,ge.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,i=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&i===0)return e;let r=s=>[s[0]-t,s[1]-o,s[2]-i];return e.map(s=>({...s,vertices:s.vertices.map(r)}))}var Ne=class extends Wl{constructor(){super(...arguments);this._handle=null}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,i){if(o!==i&&this._handle){if(t==="position"||t==="scale"||t==="rotation"||t==="cast-shadow"||t==="receive-shadow"){this._handle.setTransform({position:Et(this,"position"),scale:(()=>{let r=this.getAttribute("scale");if(!r)return;if(r.includes(","))return Et(this,"scale");let s=parseFloat(r);return Number.isFinite(s)?s:void 0})(),rotation:Et(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=Yl(this);if(!t)return;let o=t.getScene?.();if(!o)return;let i=this.buildPolygons();this.hasAttribute("auto-center")&&(i=Xl(i));let r={polygons:i,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(r,{position:Et(this,"position"),scale:(()=>{let s=this.getAttribute("scale");if(!s)return;if(s.includes(","))return Et(this,"scale");let c=parseFloat(s);return Number.isFinite(c)?c:void 0})(),rotation:Et(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow"),excludeFromAutoCenter:this.hasAttribute("exclude-from-auto-center"),merge:!1})}},Tn=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("size"),t=n?parseFloat(n):void 0;return(0,ge.boxPolygons)({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:Je(this,"color")})}},An=class extends Ne{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"),i=o===null?0:parseFloat(o);return(0,ge.planePolygons)({axis:t,size:ve(this,"size",.4),offset:Number.isFinite(i)?i:0,color:Je(this,"color")})}},wn=class extends Ne{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,ge.ringPolygons)({axis:t,radius:ve(this,"radius",50),segments:ve(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:Je(this,"color")})}},Mn=class extends Ne{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ge.octahedronPolygons)({center:Et(this,"center")??[0,0,0],size:ve(this,"size",50),color:Je(this,"color")})}},Ln=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ge.tetrahedronPolygons)({size:ve(this,"size",100),color:Je(this,"color")})}},_n=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ge.icosahedronPolygons)({size:ve(this,"size",100),color:Je(this,"color")})}},Rn=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ge.dodecahedronPolygons)({size:ve(this,"size",100),color:Je(this,"color")})}},kn=class extends Ne{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ge.spherePolygons)({radius:ve(this,"radius",50),subdivisions:ve(this,"subdivisions",1),color:Je(this,"color")})}},Dn=class extends Ne{static get observedAttributes(){return["radius","radius-top","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("radius-top");return(0,ge.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")})}},On=class extends Ne{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ge.conePolygons)({radius:ve(this,"radius",50),height:ve(this,"height",100),radialSegments:ve(this,"radial-segments",12),color:Je(this,"color")})}},In=class extends Ne{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ge.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",ke),customElements.get("poly-mesh")||customElements.define("poly-mesh",St),customElements.get("poly-iframe")||customElements.define("poly-iframe",mn),customElements.get("poly-polygon")||customElements.define("poly-polygon",fn),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",gn),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",hn),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",bn),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",xn),customElements.get("poly-first-person-controls")||customElements.define("poly-first-person-controls",vn),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",Pn),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",Ct),customElements.get("poly-camera")||customElements.define("poly-camera",Sn),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",Cn),customElements.get("poly-select")||customElements.define("poly-select",En),customElements.get("poly-box")||customElements.define("poly-box",Tn),customElements.get("poly-plane")||customElements.define("poly-plane",An),customElements.get("poly-ring")||customElements.define("poly-ring",wn),customElements.get("poly-octahedron")||customElements.define("poly-octahedron",Mn),customElements.get("poly-tetrahedron")||customElements.define("poly-tetrahedron",Ln),customElements.get("poly-sphere")||customElements.define("poly-sphere",kn),customElements.get("poly-icosahedron")||customElements.define("poly-icosahedron",_n),customElements.get("poly-dodecahedron")||customElements.define("poly-dodecahedron",Rn),customElements.get("poly-cylinder")||customElements.define("poly-cylinder",Dn),customElements.get("poly-cone")||customElements.define("poly-cone",On),customElements.get("poly-torus")||customElements.define("poly-torus",In));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});
519
+ `;var Ze=require("@layoutit/polycss-core");var mn=Ze.BASE_TILE,Ra=.1;function ni(e){return(0,Ze.worldPositionToCss)(e)}function fn(e){return(0,Ze.worldDirectionToCss)(e)}function bt(e){return(0,Ze.worldDirectionalLightToCss)(e)}function ro(e){return(0,Ze.buildPolyMeshTransform)(e)}function Ko(e,n=[0,0,0],t=1){return(0,Ze.buildPolyCameraSceneTransform)(e.state,{autoCenterOffset:n,layoutScale:t})}function ka(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 oi(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=ka(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function ri(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}function ii(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,i=0;for(let x=1;x+1<e.vertices.length;x++){let f=e.vertices[x],b=e.vertices[x+1],h=f[1]-n[1],S=f[0]-n[0],v=f[2]-n[2],C=b[1]-n[1],R=b[0]-n[0],I=b[2]-n[2];t-=S*I-v*R,o-=v*C-h*I,i-=h*R-S*C}let r=Math.hypot(t,o,i);if(r<1e-9)return null;t/=r,o/=r,i/=r;let a=1/Ra,c=Math.round(t*a)/a,l=Math.round(o*a)/a,m=Math.round(i*a)/a,g=Math.hypot(c,l,m);return g<1e-9?null:{key:c+","+l+","+m,vec:[c/g,l/g,m/g]}}function si(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let i of t)if(!o.includes(i))return!1;return!0}function ai(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function li(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)&&(e?.parametric??!1)===(n?.parametric??!1)&&(e?.definition??16)===(n?.definition??16)&&(e?.dragDefinition??-1)===(n?.dragDefinition??-1)&&(e?.style??"vector")===(n?.style??"vector")&&(e?.followAnimation??!1)===(n?.followAnimation??!1)}var xt=require("@layoutit/polycss-core");var Da=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"],Gt="--polycss-light-preview-active",ci=`var(${Gt}, 0)`,Oa="max(0, calc(var(--pnx, 0) * var(--plx, 0) + var(--pny, 0) * var(--ply, 0) + var(--pnz, 1) * var(--plz, 1)))",Jo=(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))`,Ia=Jo("--psr","--par","--plr"),Ha=Jo("--psg","--pag","--plg"),Fa=Jo("--psb","--pab","--plb");function he(e,n,t){return e.style.getPropertyValue(n)===t?!1:(e.style.setProperty(n,t),!0)}function Tt(e){for(let n of Da)e.style.getPropertyValue(n)&&e.style.removeProperty(n)}function io(e,n){let t=n.directionalLight?.direction??[.4,-.7,.59],o=fn(t),i=Math.hypot(o[0],o[1],o[2])||1,r=o[0]/i,a=o[1]/i,c=o[2]/i,l=(0,xt.parseHexColor)(n.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],m=(0,xt.parseHexColor)(n.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],g=n.directionalLight?.intensity??1,x=n.ambientLight?.intensity??.4,f=S=>(S/255).toFixed(4);he(e,"--plx",r.toFixed(2)),he(e,"--ply",a.toFixed(2)),he(e,"--plz",c.toFixed(2)),he(e,"--plr",f(l[0])),he(e,"--plg",f(l[1])),he(e,"--plb",f(l[2])),he(e,"--pli",g.toFixed(4)),he(e,"--par",f(m[0])),he(e,"--pag",f(m[1])),he(e,"--pab",f(m[2])),he(e,"--pai",x.toFixed(4));let b=c,h=Math.sign(b||1)*Math.max(Math.abs(b),.01);he(e,"--clx",r.toFixed(2)),he(e,"--cly",a.toFixed(2)),he(e,"--clz",h.toFixed(2))}function ui(e,n){let t=n.textureLighting==="dynamic";if(e.dataset.polycssLighting=n.textureLighting??"baked",!t){Tt(e);return}io(e,n)}function At(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 di(e,n){let t=(0,xt.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 er(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=t.textureLighting??"baked",i={directionalLight:bt(t.directionalLight),ambientLight:t.ambientLight,textureLighting:o,textureQuality:t.textureQuality,seamBleed:t.seamBleed,strategies:t.strategies},r=Oo(e.plan,n,e.plan.normal,o,i);return It(e.element,r,o),o==="baked"&&Va(e.element),!0}function Ba(e){let n=(0,xt.parsePureColor)(e)??{rgb:[255,255,255],alpha:1},[t,o,i]=n.rgb,r=(c,l)=>`calc(${c} * (1 - ${ci}) + var(${l}, ${c}) * ${ci})`,a=n.alpha<1?` / ${n.alpha}`:"";return`rgb(${r(t,"--polycss-preview-r")} ${r(o,"--polycss-preview-g")} ${r(i,"--polycss-preview-b")}${a})`}function pi(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=e.element,i=e.plan.normal,r=(0,xt.parseHex)(n.color??"#cccccc"),a=!1;return a=he(o,"--pnx",i[0].toFixed(4))||a,a=he(o,"--pny",i[1].toFixed(4))||a,a=he(o,"--pnz",i[2].toFixed(4))||a,a=he(o,"--psr",(r.r/255).toFixed(4))||a,a=he(o,"--psg",(r.g/255).toFixed(4))||a,a=he(o,"--psb",(r.b/255).toFixed(4))||a,a=he(o,"--plam",Oa)||a,a=he(o,"--polycss-preview-r",Ia)||a,a=he(o,"--polycss-preview-g",Ha)||a,a=he(o,"--polycss-preview-b",Fa)||a,a=he(o,"--polycss-paint",Ba(t))||a,o.style.getPropertyValue("color")&&(o.style.removeProperty("color"),a=!0),a}function Va(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 so=class{constructor(){this.groundSvg=null;this.groundVisible=!1;this.currentGroundCssZ=null;this.shadowRoot=null}};function mi(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 i=t.firstChild;i?t.insertBefore(o,i):t.appendChild(o)}return o}function fi(e){e.groundSvg?.parentNode&&e.groundSvg.parentNode.removeChild(e.groundSvg),e.groundSvg=null,e.groundVisible=!1}function gi(e){e.groundSvg&&e.groundVisible&&(e.groundSvg.style.display="none",e.groundVisible=!1)}function hi(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 so,receiverShadowCache:new Map,receiverShadowCacheKey:new Map,casterItemsCache:new Map,casterItemsCacheKey:new Map,shadowDragActive:!1}}var De=require("@layoutit/polycss-core");function yi(e){for(let n of e)n.svg&&n.svg.parentNode&&n.svg.parentNode.removeChild(n.svg),n.svg=null}function bi(e,n){if(n){let t=e.receiverShadowCache.get(n);t&&yi(t),e.receiverShadowCache.delete(n),e.receiverShadowCacheKey.delete(n)}else{for(let t of e.receiverShadowCache.values())yi(t);e.receiverShadowCache.clear(),e.receiverShadowCacheKey.clear()}}function xi(e,n){n?(e.casterItemsCache.delete(n),e.casterItemsCacheKey.delete(n)):(e.casterItemsCache.clear(),e.casterItemsCacheKey.clear())}function vi(e){fi(e.shadowSvgState),Si(e)}function Pi(e){return e.handle.id??e.autoMeshId}var Mi="http://www.w3.org/2000/svg",ao=new WeakMap,Ci=new WeakMap,Ei=new WeakMap,Ti=new WeakMap,Ai=new WeakMap;function za(e){let n=ao.get(e);return n||(n=new Map,ao.set(e,n)),n}function Na(e,n){let t=za(e),o=t.get(n);return o||(o=new Map,t.set(n,o)),o}function Li(e){let n=ao.get(e);if(n){for(let t of n.values()){for(let o of t.values())o.svg&&o.svg.parentNode&&o.svg.parentNode.removeChild(o.svg);t.clear()}n.clear()}}function tr(e){Li(e),ao.delete(e)}function Si(e){for(let n of e.meshes)tr(n)}function _i(e,n,t,o,i,r,a,c,l,m,g){let x=e.options.current,{receiverShadowCache:f,receiverShadowCacheKey:b,casterItemsCache:h,casterItemsCacheKey:S}=e,v=o.handle.transform.position??[0,0,0],C=o.handle.transform.rotation??[0,0,0],R=o.polygons.some(u=>u.texture!==void 0),I=(0,De.meshScaleVec3)(o.handle.transform.scale),B=o.bboxCenterCss,O=x.shadow?.lift??.001,X=`${o.polygons.length}|${i.size}|${v.join(",")}|${C.join(",")}|${I.join(",")}|${B?B.join(","):"n"}|${O}`,Z=f.get(o);(Z===void 0||b.get(o)!==X)&&(Z=(0,De.prepareReceiverFacePlanes)(o.polygons,v,o.handle.transform.scale,i,O,C),f.set(o,Z),b.set(o,X),Li(o));let M=[];for(let u of n){let d=u.handle.transform.position??[0,0,0],A=u.handle.transform.rotation??[0,0,0],_=(0,De.meshScaleVec3)(u.handle.transform.scale),N=u.bboxCenterCss,Y=`${u.polygons.length}|${d.join(",")}|${A.join(",")}|${_.join(",")}|${N?N.join(","):"n"}`,w=h.get(u);(w===void 0||S.get(u)!==Y)&&(w=(0,De.prepareCasterPolyItems)(u.polygons,d,u.handle.transform.scale,()=>!0,A),h.set(u,w),S.set(u,Y));let ee;if(u===o){let K=Ci.get(u);(K===void 0||Ei.get(u)!==u.polygons)&&(K=(0,De.buildSharedEdgeMap)(u.polygons),Ci.set(u,K),Ei.set(u,u.polygons)),ee=K}let te;if(u!==o&&(u.polygons.length>=40||g.points.length>0)){let K=Ti.get(u);(K===void 0||Ai.get(u)!==Y)&&(K=(0,De.prepareCasterEdgeOwners)(u.polygons,d,u.handle.transform.scale,A),Ti.set(u,K),Ai.set(u,Y)),te=K}let ne,ye;if(x.shadow?.parametric){let K=u.shadowDefinition??x.shadow.definition??16,ge=e.shadowDragActive?Math.min(K,x.shadow.dragDefinition??K):K,xe=(0,De.buildParametricCasterOverride)({polysWorldVerts:w.map(Se=>Se.wv),lightDir:r,definition:ge,isSelf:u===o,style:x.shadow.style,pointLights:g.points.map(Se=>({position:Se.lightPos,index:Se.index}))});ne=xe.overrideSilhouette,ye=xe.overridePointSilhouettes}M.push({id:u,items:w,selfShadowEdgeMap:ee,edgeOwners:te,casterPolygonCount:u.polygons.length,overrideSilhouette:ne,overridePointSilhouettes:ye})}let z={rotX:e.camera.state.rotX,rotY:e.camera.state.rotY,meshRotation:o.handle.transform.rotation},V=(0,De.computeMergedReceiverShadows)({receiverPlanes:Z,receiverPolygons:o.polygons,receiverHasTexture:R,casters:M,lightDir:r,runDirectional:g.runDirectional,pointPasses:g.points,allPointLights:g.allPointLights,cameraRot:z,ambientLight:x.ambientLight,directionalLight:x.directionalLight,shadow:{color:x.shadow?.color,opacity:m,maxExtend:x.shadow?.maxExtend}}),F=Na(o,"m"),ae=new Set,y=!!x.debugShadowAttrs,L=mi(e.shadowSvgState,e.doc,e.sceneEl);for(let u of V){ae.add(u.faceIndex);let d=F.get(u.faceIndex);d||(d={svg:null,visible:!1,width:-1,height:-1,matrixCss:""},F.set(u.faceIndex,d));let A=d.svg;A||(A=e.doc.createElementNS(Mi,"svg"),A.setAttribute("class","polycss-shadow polycss-shadow-svg polycss-shadow-receiver"),L.appendChild(A),d.svg=A),d.visible||(A.style.display="block"),d.visible=!0,(d.width!==u.width||d.height!==u.height)&&(A.setAttribute("width",String(u.width)),A.setAttribute("height",String(u.height)),A.setAttribute("viewBox",`0 0 ${u.width} ${u.height}`),d.width=u.width,d.height=u.height);let _=`position:absolute;top:0;left:0;display:block;overflow:hidden;transform-origin:0 0;pointer-events:none;will-change:transform;opacity:${u.svgOpacity.toFixed(4)};transform:${u.matrixCss}`;for(d.matrixCss!==_&&(A.setAttribute("style",_),d.matrixCss=_),y&&(A.setAttribute("data-poly-shadow-type","receiver"),A.setAttribute("data-poly-shadow-receiver",Pi(o)),A.setAttribute("data-poly-shadow-receiver-face",String(u.faceIndex)),A.setAttribute("data-poly-shadow-receiver-polys",JSON.stringify(u.memberPolyIndices)),A.setAttribute("data-poly-shadow-layers",String(u.layers.length)));A.firstChild;)A.removeChild(A.firstChild);u.baseFill&&u.baseD&&A.appendChild(wi(e.doc,u.baseD,u.baseFill,!1,1));for(let N of u.layers)A.appendChild(wi(e.doc,N.d,N.fill,N.multiply,N.opacity))}for(let[u,d]of F)ae.has(u)||d.svg&&d.visible&&(d.svg.style.display="none",d.visible=!1)}function wi(e,n,t,o,i){let r=e.createElementNS(Mi,"path");return r.setAttribute("d",n),r.setAttribute("fill",t),r.setAttribute("fill-rule","nonzero"),i!==1&&r.setAttribute("opacity",i.toFixed(4)),o&&(r.style.mixBlendMode="multiply"),r}var Ri=Symbol.for("polycss.animation.triangleFrameTarget");var ja=750;var lo=Promise.resolve();function ki(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:J.DEFAULT_SEAM_BLEED}}var $a={key:"non-cullable",normal:[1,1,0]};function Di(){return[$a]}function Oi(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&&ti(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...i}=n,r=ki({seamBleed:J.DEFAULT_SEAM_BLEED,...i}),a=oi(e),c=[0,0,0],l=e.ownerDocument??document,m=l.createElement("div");m.className="polycss-camera",F(m,r),e.appendChild(m);let g=l.createElement("div");g.className="polycss-scene",g.setAttribute("aria-hidden","true"),ae(g,r),m.appendChild(g);let x=hi({host:e,doc:l,cameraEl:m,sceneEl:g,camera:t,layoutScale:a,options:r}),f=x.meshes,b=new WeakMap,h=x.shadowSvgState,S=()=>gi(h),v=()=>vi(x),C=null,R=null,I=140,B=0,O=80;function X(s){if(!r.shadow?.followAnimation||!s.castShadow&&!s.receiveShadow)return;let p=typeof performance<"u"?performance.now():Date.now();p-B<O||(B=p,M(),Ve())}function Z(s){if(!s)return null;let p=Math.hypot(s[0],s[1],s[2]);if(!Number.isFinite(p)||p<=0)return null;let P=Math.round(s[0]/p*100)/100,T=Math.round(s[1]/p*100)/100,j=Math.round(s[2]/p*100)/100;return`${P}|${T}|${j}`}function M(){C=null}let z=s=>bi(x,s),V=s=>xi(x,s);function F(s,p){let P=(0,J.capturePolyCameraSnapshot)(t);s.style.perspective=P.appliedPerspectiveStyle,s.dataset.polycssCameraProjection=P.projection,s.dataset.polycssCameraPerspective=P.perspectiveStyle,s.dataset.polycssCameraAppliedPerspective=P.appliedPerspectiveStyle,s.dataset.polycssCameraZoom=String(P.state.zoom),s.dataset.polycssCameraDistance=String(P.state.distance),s.dataset.polycssCameraRotX=String(P.state.rotX),s.dataset.polycssCameraRotY=String(P.state.rotY),s.dataset.polycssCameraTarget=P.state.target.join(",")}function ae(s,p){ri(s,a),s.style.transform=Ko(t,c,a),ui(s,p)}function y(s){s.style.transform=Ko(t,c,a)}function L(s){s.textureReadyPromise=lo,s.voxelRenderer?.dispose(),s.voxelRenderer=void 0,_(s.rendered,s.disposeAtlas),s.disposeAtlas=void 0,s.rendered.length=0,s.renderedByPolygonIndex=[],s.cameraCullGroups=[],s.cameraCullSignature="",s.solidLightingPreviewPrepared=!1,s.solidLightingPreviewActive=!1,A(s);for(let p of Array.from(s.wrapper.children))p instanceof HTMLElement&&p.classList.contains("polycss-bucket")&&p.remove();s.hasBuckets=!1}function u(s){for(let p of Array.from(s.wrapper.childNodes)){if(!(p instanceof HTMLElement))return p;if(p.classList.contains("polycss-bucket")||p.classList.contains("polycss-shadow"))continue;let P=p.tagName.toLowerCase();if(!(P==="b"||P==="i"||P==="s"||P==="u"||P==="q"))return p}return null}function d(s,p,P){P?.parentNode===s.wrapper?s.wrapper.insertBefore(p,P):s.wrapper.appendChild(p)}function A(s){for(let p of s.shadowRendered)p.parentNode&&p.parentNode.removeChild(p);s.shadowRendered.length=0,v()}function _(s,p){p?.();for(let P of s){try{P.dispose()}catch{}P.element.parentNode&&P.element.parentNode.removeChild(P.element)}}function N(s,p,P,T){s.rendered=p,s.renderedByPolygonIndex=[];for(let j of p)s.renderedByPolygonIndex[j.polygonIndex]=j;s.disposeAtlas=P,s.textureReadyPromise=T?T.catch(()=>{}):lo,s.solidLightingPreviewPrepared=!1}function Y(s,p){let P=s.renderedByPolygonIndex[p];return P?.polygonIndex===p?P:void 0}function w(s){for(let p of Array.from(s.wrapper.children))p instanceof HTMLElement&&p.classList.contains("polycss-bucket")&&p.remove();s.hasBuckets=!1;for(let p of s.rendered)p.element.parentNode&&p.element.parentNode.removeChild(p.element)}function ee(s,p){let P=s.polygons[p.polygonIndex];return s.stableDom&&P?(0,J.polygonCssSurfaceNormal)(P):p.plan?.normal??(P?(0,J.polygonCssSurfaceNormal)(P):null)}function te(s){if(!xe(s))return s.rendered;let p=ne(s);return s.rendered.filter(P=>ye(s,P,J.CAMERA_BACKFACE_CULL_EPS,p))}function ne(s){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:s.handle.transform.rotation}}function ye(s,p,P=J.CAMERA_BACKFACE_CULL_EPS,T=ne(s)){let j=ee(s,p);return j===null||(0,J.normalFacesCamera)(j,T,P)}function K(s){if(s.excludeFromAutoCenter){s.cameraCullGroups=[];return}let p=new Map;for(let P of s.rendered){let T=ee(s,P);if(!T)continue;if(!(0,J.isAxisAlignedSurfaceNormal)(T)){s.cameraCullGroups=Di();return}let j=(0,J.cameraCullNormalKey)(T);if(!p.has(j)&&(p.set(j,T),p.size>J.VOXEL_CAMERA_CULL_NORMAL_LIMIT)){s.cameraCullGroups=Di();return}}s.cameraCullGroups=Array.from(p,([P,T])=>({key:P,normal:T}))}function ge(s){return xe(s)?(0,J.cameraCullVisibleSignature)(s.cameraCullGroups,ne(s)):"all"}function xe(s){return!s.excludeFromAutoCenter&&(0,J.isVoxelCameraCullableNormalGroups)(s.cameraCullGroups)}function Se(s){s.cameraCullSignature=xe(s)?ge(s):"all"}function qe(s,p){let P=new Array(s.rendered.length),T=!1,j=ne(s);for(let q=0;q<s.rendered.length;q+=1){let le=s.rendered[q],ve=ye(s,le,p,j);P[q]=ve}let H=null,k=null,$=()=>{if(!(!H||!k)){if(H===k)H.remove();else{let q=l.createRange();q.setStartBefore(H),q.setEndAfter(k),q.deleteContents(),q.detach()}H=null,k=null,T=!0}};for(let q=0;q<s.rendered.length;q+=1){let le=s.rendered[q];!P[q]&&le.element.parentNode===s.wrapper?(k&&k.nextSibling===le.element||($(),H=le.element),k=le.element):$()}$();let W=q=>{for(let le=q;le<s.rendered.length;le+=1){let ve=s.rendered[le].element;if(ve.parentNode===s.wrapper)return ve}return u(s)},me=-1,ue=q=>{if(me<0)return;let le=l.createDocumentFragment();for(let ve=me;ve<q;ve+=1){let Te=s.rendered[ve];mt(s,Te),le.appendChild(Te.element)}d(s,le,W(q)),me=-1,T=!0};for(let q=0;q<s.rendered.length;q+=1){let le=s.rendered[q];P[q]&&le.element.parentNode!==s.wrapper?me<0&&(me=q):ue(q)}return ue(s.rendered.length),T}function He(s,p=!1){if(s.voxelRenderer){p?s.voxelRenderer.render(ne(s)):s.voxelRenderer.syncCamera(ne(s)),s.cameraCullSignature="voxel-direct";return}if(!xe(s)){let j=s.cameraCullSignature!=="all";s.cameraCullSignature="all",j&&Nn(s);return}if(s.hasBuckets){rt(s,p);return}let P=ge(s);if(!p&&P===s.cameraCullSignature)return;let T=qe(s,J.CAMERA_BACKFACE_CULL_EPS);s.cameraCullSignature=P,T&&Be(s)}function rt(s,p=!1){let P=xe(s)?ge(s):"all";!p&&P===s.cameraCullSignature||Nn(s)}function qt(s,p){return ee(s,p)}function mt(s,p){if(r.textureLighting!=="dynamic")return;let P=qt(s,p);P&&(p.element.style.setProperty("--pnx",P[0].toFixed(4)),p.element.style.setProperty("--pny",P[1].toFixed(4)),p.element.style.setProperty("--pnz",P[2].toFixed(4)))}function it(s){w(s),s.hasBuckets=!1;let p=s.skipBucketNormalCleanupOnce;s.skipBucketNormalCleanupOnce=!1;let P=l.createDocumentFragment(),T=r.textureLighting==="dynamic"&&!s.stableDom,j=new Map,H=[];for(let k of te(s)){let $=s.polygons[k.polygonIndex],W=T&&$?ii($):null;if(!W){H.push(k);continue}let me=W.key+"|"+($.color??""),ue=j.get(me);ue||(ue={vec:W.vec,items:[]},j.set(me,ue)),ue.items.push(k)}for(let k of H)mt(s,k),P.appendChild(k.element);for(let k of j.values()){if(k.items.length<2){for(let W of k.items)mt(s,W),P.appendChild(W.element);continue}let $=l.createElement("div");$.className="polycss-bucket",s.hasBuckets=!0,$.style.setProperty("--pnx",String(k.vec[0])),$.style.setProperty("--pny",String(k.vec[1])),$.style.setProperty("--pnz",String(k.vec[2]));for(let W of k.items)$.appendChild(W.element),(!p||W.kind==="triangle")&&(W.element.style.removeProperty("--pnx"),W.element.style.removeProperty("--pny"),W.element.style.removeProperty("--pnz"));P.appendChild($)}d(s,P,u(s)),Se(s)}function So(){return new Promise(s=>setTimeout(s,0))}async function Co(s,p){if(r.textureLighting==="dynamic"&&!s.stableDom)return it(s),!p();w(s);let T=l.createDocumentFragment(),j=u(s),H=0;for(let k of te(s)){if(p())return!1;mt(s,k),T.appendChild(k.element),H++,H%ja===0&&(d(s,T,j),T=l.createDocumentFragment(),await So())}return T.childNodes.length>0&&d(s,T,j),Se(s),!p()}function Kt(s,p){let P=r.textureLighting==="dynamic",T=r.directionalLight?.direction,j=p&&(p[0]!==0||p[1]!==0||p[2]!==0);if(!P||!j||!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 H=(0,J.inverseRotateVec3)(T,p),k=fn(H),$=Math.hypot(k[0],k[1],k[2])||1,W=(k[0]/$).toFixed(2),me=(k[1]/$).toFixed(2),ue=(k[2]/$).toFixed(2),q=`${W}|${me}|${ue}`;s.lightOverrideSignature!==q&&(s.wrapper.style.setProperty("--plx",W),s.wrapper.style.setProperty("--ply",me),s.wrapper.style.setProperty("--plz",ue),s.lightOverrideSignature=q)}function zn(s){let p=!1;for(let P of s.rendered){if(!P.plan||P.kind==="atlas"||P.plan.texture)continue;let T=s.polygons[P.polygonIndex];T&&(p=er(P,T,r)||p)}return s.solidLightingPreviewPrepared=!1,s.solidLightingPreviewActive=!1,p}function G(s){if((r.textureLighting??"baked")!=="baked")return!1;let p=!1;for(let P of s.rendered){if(!P.plan||P.kind==="atlas"||P.plan.texture)continue;let T=s.polygons[P.polygonIndex];T&&(pi(P,T,P.plan.shadedColor),p=!0)}return s.solidLightingPreviewPrepared=p,p}function de(s){return(r.textureLighting??"baked")!=="baked"||!s.solidLightingPreviewPrepared&&!G(s)?!1:(s.solidLightingPreviewActive=!0,!0)}function pe(s){return s.kind==="atlas"||!!s.plan?.texture}function Fe(){if((r.textureLighting??"baked")!=="baked")return!1;let s=!1;for(let p of f)s=zn(p)||s,p.rendered.some(pe)&&(To(p),s=!0);g.style.removeProperty(Gt);for(let p of f)Tt(p.wrapper),p.solidLightingPreviewActive=!1;return Tt(g),s}function Jt(){g.style.removeProperty(Gt);for(let s of f)s.solidLightingPreviewActive&&(zn(s),Tt(s.wrapper));(r.textureLighting??"baked")!=="dynamic"&&(Tt(g),M(),Ve())}function en(s,p){let P=s.handle.transform.rotation,T=p.directionalLight?.direction??r.directionalLight?.direction;if(!(P&&(P[0]!==0||P[1]!==0||P[2]!==0))||!T){Tt(s.wrapper);return}let H=(0,J.inverseRotateVec3)(T,P);io(s.wrapper,{...r,...p,directionalLight:{...r.directionalLight,...p.directionalLight,direction:H}})}function vt(s){if((r.textureLighting??"baked")!=="baked")return!1;io(g,{...r,...s}),!s.skipShadows&&s.directionalLight?.direction&&Ve(s.directionalLight.direction,{progressive:!0});let p=!1;for(let P of f)en(P,s),p=de(P)||p;return p?he(g,Gt,"1"):g.style.removeProperty(Gt),p}function _e(s,p,P){let T=s.polygons[p];if(!T)return!1;let j=Y(s,p);if(!j)return!1;let H=r.textureLighting??"baked";return H==="dynamic"?(di(j.element,P),!0):H==="baked"?er(j,T,r):!1}function Ge(s,p){let P=s.polygons[p];if(!P)return!1;let T=Y(s,p);return T?(Ae(T.element,P,p),!0):!1}function Ke(s,p,P){return!(P.length===0||!P.every(T=>T==="color"||T==="data")||P.includes("color")&&!_e(s,p,s.polygons[p]?.color)||P.includes("data")&&!Ge(s,p))}function Be(s){M(),Ve()}function Ve(s,p){let P=r.shadow,T=!!p?.progressive&&!!P?.parametric&&P?.dragDefinition!=null&&P.dragDefinition<(P.definition??16);x.shadowDragActive=T,T&&(R&&clearTimeout(R),R=setTimeout(()=>{R=null,x.shadowDragActive=!1,M(),Ve()},I));let j=[];for(let oe of f)!oe.disposed&&oe.castShadow&&j.push(oe);if(j.length===0){v(),C=null;return}let H=r.shadow?.color??"#000000",k=r.shadow?.opacity??.25,$=(0,J.parseHexColor)(H)?.rgb??[0,0,0],W=$[0],me=$[1],ue=$[2],q=s??r.directionalLight?.direction??[.4,-.7,.59],le=fn(q),ve=r.textureLighting==="dynamic"?[]:r.pointLights??[],Te=ve.map(oe=>({position:ni(oe.position),color:oe.color,intensity:oe.intensity})),Ue=ve.map((oe,D)=>oe.castShadow?D:-1).filter(oe=>oe>=0),E=Ue.map(oe=>Te[oe].position),st=r.directionalLight,ft=!!st?.direction&&(st.intensity??1)>0,at=Z(le),Je=E.map(oe=>`${Math.round(oe[0])},${Math.round(oe[1])},${Math.round(oe[2])}`).join(";"),We=at===null&&Je===""?null:`${at??""}|${Je}`;if(We!==null&&We===C)return;let gt=new Map;for(let oe of j)gt.set(oe,(0,J.findOverlappingPolygonDuplicates)(oe.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.95,preserveDoubleSidedBackfaces:!1}));let ct=new Map;for(let oe of f)oe.disposed||!oe.receiveShadow||ct.set(oe,new Set);S();for(let oe of f){if(oe.disposed||!oe.receiveShadow)continue;let D=ct.get(oe)??new Set;_i(x,j,gt,oe,D,le,W,me,ue,k,{runDirectional:ft,points:E.map((U,ce)=>({lightPos:U,index:Ue[ce]})),allPointLights:Te})}C=We}function Nn(s){if(s.voxelRenderer){s.voxelRenderer.render(ne(s)),s.cameraCullSignature="voxel-direct";return}A(s),it(s),Be(s)}function Eo(s,p){if(!p||!s.polygons||s.polygons.length<2)return;let P=Math.hypot(p[0],p[1],p[2]);if(!Number.isFinite(P)||P<=0)return;let T=p[0]/P,j=p[1]/P,H=p[2]/P,k=q=>Math.round(q*1e3)/1e3,$=`${k(T)},${k(j)},${k(H)}`,W=s.lightOcclusionCache;if(W&&W.polygons===s.polygons&&W.lightDirKey===$)return W.occluded;let me=W&&W.polygons===s.polygons?W.dedupDropped:(0,J.findOverlappingPolygonDuplicates)(s.polygons,{normalTolerance:.1,distanceTolerance:.12,overlapFraction:.98,preserveDoubleSidedBackfaces:!1}),ue=(0,J.computeLightVisibility)(s.polygons,[T,j,H],me);return s.lightOcclusionCache={polygons:s.polygons,lightDirKey:$,occluded:ue,dedupDropped:me},ue}function jn(s){return!!s.voxelSource&&r.textureLighting!=="dynamic"&&!s.stableDom&&!s.castShadow}function _t(s){let p=r.pointLights;if(!p||p.length===0)return;let P=s.handle.transform.position??[0,0,0],T=s.handle.transform.rotation??[0,0,0],j=T[0]!==0||T[1]!==0||T[2]!==0;return p.map(H=>{let k=[H.position[0]-P[0],H.position[1]-P[1],H.position[2]-P[2]],$=j?(0,J.inverseRotateVec3)(k,T):k;return{...H,position:$}})}function ze(s,p){L(s);let P=r.directionalLight,T=p?{...P,direction:p}:P,j=bt(T),H=void 0;if(jn(s)){let W=Jr({doc:l,wrapper:s.wrapper,polygons:s.parseResult.polygons,directionalLight:j,ambientLight:r.ambientLight});if(W){s.voxelRenderer=W,W.render(ne(s)),s.cameraCullSignature="voxel-direct",s.textureReadyPromise=lo;return}}let k={doc:l,directionalLight:j,pointLights:_t(s),ambientLight:r.ambientLight,textureLighting:r.textureLighting,textureQuality:r.textureQuality,textureLeafSizing:r.textureLeafSizing,textureImageRendering:r.textureImageRendering,textureBackend:r.textureBackend,textureProjection:r.textureProjection,seamBleed:r.seamBleed,strategies:r.strategies,lightOccludedPolyIndices:H},$=s.stableDom?(()=>{let W=zt(s.polygons,k);return At(s.wrapper,W),pn(s.polygons,{...k,solidPaintDefaults:W})??Nt(s.polygons,{...k,solidPaintDefaults:W})})():Nt(s.polygons,{...k,computeSolidPaintDefaults:!0,skipDynamicNormalVars:r.textureLighting==="dynamic"});s.stableDom||At(s.wrapper,$.solidPaintDefaults??{}),N(s,$.rendered,$.dispose,$.pagesReady),s.skipBucketNormalCleanupOnce=r.textureLighting==="dynamic"&&!s.stableDom,K(s),it(s),Be(s)}function To(s,p){if(s.rendered.length===0||s.voxelRenderer||s.stableDom||jn(s)){ze(s,p);return}if(s.rendered[0]?.element.parentNode===null){ze(s,p);return}let P=r.directionalLight,T=p?{...P,direction:p}:P,j=bt(T),H={doc:l,directionalLight:j,pointLights:_t(s),ambientLight:r.ambientLight,textureLighting:r.textureLighting,textureQuality:r.textureQuality,textureLeafSizing:r.textureLeafSizing,textureImageRendering:r.textureImageRendering,textureBackend:r.textureBackend,textureProjection:r.textureProjection,seamBleed:r.seamBleed,strategies:r.strategies,computeSolidPaintDefaults:!0,skipDynamicNormalVars:r.textureLighting==="dynamic"},k=Nt(s.polygons,H),$=()=>{s.rebakeInFlight=!1;let ue=s.rebakeQueuedLightDir;ue!==null&&(s.rebakeQueuedLightDir=null,To(s,ue))},W=()=>{if(s.disposed){k.dispose(),$();return}if(k.rendered.length!==s.rendered.length){k.dispose(),ze(s,p),$();return}for(let le of k.rendered){let ve=s.renderedByPolygonIndex[le.polygonIndex];if(!ve)continue;let Te=le.element.getAttribute("style");Te!==null&&ve.element.setAttribute("style",Te)}let ue=k.solidPaintDefaults;ue&&At(s.wrapper,ue);let q=s.disposeAtlas;s.disposeAtlas=k.dispose,q&&(typeof requestAnimationFrame=="function"?ve=>{requestAnimationFrame(ve)}:ve=>{setTimeout(ve,0)})(q),Be(s),$()},me=k.pagesReady;me&&typeof me.then=="function"?(s.textureReadyPromise=me.catch(()=>{}),me.then(()=>ps(k.rendered)).then(ms).then(W,()=>{k.dispose(),s.disposed||ze(s,p),$()})):W()}function ds(s,p){if(s.rebakeInFlight){s.rebakeQueuedLightDir=p;return}s.rebakeInFlight=!0,To(s,p)}function ps(s){let p=new Set;for(let P of s){let T=P.element.getAttribute("style")??"",j=/url\((blob:[^)]+)\)/g,H;for(;(H=j.exec(T))!==null;)p.add(H[1])}return Array.from(p)}function ms(s){return s.length===0||typeof Image>"u"?Promise.resolve():Promise.all(s.map(p=>{let P=new Image;P.src=p;let T=P.decode?.();return T?T.catch(()=>{}):Promise.resolve()})).then(()=>{})}function Pt(){let s=1/0,p=!1;for(let H of f)if(!H.disposed&&H.receiveShadow){p=!0;break}for(let H of f){if(H.disposed||!(p?H.receiveShadow:H.castShadow))continue;let $=H.handle.transform.position?.[2]??0;for(let W of H.polygons)for(let me of W.vertices){let ue=me[2]+$;ue<s&&(s=ue)}}if(!Number.isFinite(s)){let H=h.currentGroundCssZ!==null;h.currentGroundCssZ=null,H&&(v(),M());return}let P=r.shadow?.lift??.05,T=(s+P)*mn,j=h.currentGroundCssZ;h.currentGroundCssZ=T,j!==T&&(M(),Ve())}async function fs(s,p){L(s);let P=bt(r.directionalLight),T={doc:l,directionalLight:P,pointLights:_t(s),ambientLight:r.ambientLight,textureLighting:r.textureLighting,textureQuality:r.textureQuality,textureLeafSizing:r.textureLeafSizing,textureImageRendering:r.textureImageRendering,textureBackend:r.textureBackend,textureProjection:r.textureProjection,seamBleed:r.seamBleed,strategies:r.strategies,lightOccludedPolyIndices:void 0},j=s.stableDom?pn(s.polygons,T):null;if(j){let $=zt(s.polygons,T);return At(s.wrapper,$),N(s,j.rendered,j.dispose,j.pagesReady),K(s),it(s),Be(s),!p()}let H=await eo(s.polygons,{...T,skipDynamicNormalVars:r.textureLighting==="dynamic"},p);if(p())return H.dispose(),!1;At(s.wrapper,H.solidPaintDefaults),N(s,H.rendered,H.dispose,H.pagesReady),s.skipBucketNormalCleanupOnce=r.textureLighting==="dynamic"&&!s.stableDom,K(s);let k=await Co(s,p);return k&&Be(s),k}function St(){let s=c,p=[0,0,0];if(r.autoCenter){let P=[];for(let T of f)!T.disposed&&!T.excludeFromAutoCenter&&P.push(...T.polygons);if(P.length>0){let T=(0,J.computeSceneBbox)(P);p=[(T.min[0]+T.max[0])/2,(T.min[1]+T.max[1])/2,(T.min[2]+T.max[2])/2]}}s[0]===p[0]&&s[1]===p[1]&&s[2]===p[2]||(c=p,x.autoCenter.offset=p,ae(g,r))}function gs(s,p={}){let T=(g.ownerDocument??document).createElement("div");T.className="polycss-mesh",p.id&&T.setAttribute("data-poly-mesh-id",p.id);let j=`polycss-mesh-${x.meshAutoCounter.next++}`;T.setAttribute("data-poly-mesh-index",j);let H={...p},k=p.merge!==!1,$=!!p.stableDom,W=0,me=ro(H);me&&(T.style.transform=me);let ue=(D,U)=>s.voxelSource?D:U?(0,J.optimizeMeshPolygons)(D,{meshResolution:p.meshResolution}):($||p.excludeFromAutoCenter,D),q=ue(s.polygons,k),le=null;function ve(){let D=ro(H);T.style.transform=D??""}function Te(D){if(D.length===0){le=null,Ue&&(Ue.bboxCenterCss=null),ve();return}let U=1/0,ce=1/0,fe=1/0,Re=-1/0,ie=-1/0,be=-1/0;for(let tt of D)for(let Xe of tt.vertices)Xe[0]<U&&(U=Xe[0]),Xe[0]>Re&&(Re=Xe[0]),Xe[1]<ce&&(ce=Xe[1]),Xe[1]>ie&&(ie=Xe[1]),Xe[2]<fe&&(fe=Xe[2]),Xe[2]>be&&(be=Xe[2]);if(!Number.isFinite(U)){le=null,Ue&&(Ue.bboxCenterCss=null),ve();return}let Ye=(ce+ie)/2*mn,et=(U+Re)/2*mn,Ne=(fe+be)/2*mn;le=[Ye,et,Ne],Ue&&(Ue.bboxCenterCss=le),ve()}let Ue=null;Te(q),g.appendChild(T);let E={handle:void 0,wrapper:T,parseResult:s,rendered:[],renderedByPolygonIndex:[],shadowRendered:[],polygons:q,voxelSource:s.voxelSource,disposed:!1,stableDom:$,hasBuckets:!1,skipBucketNormalCleanupOnce:!1,excludeFromAutoCenter:!!p.excludeFromAutoCenter,castShadow:!!p.castShadow,bboxCenterCss:le,receiveShadow:!!p.receiveShadow,shadowDefinition:p.shadowDefinition,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",stableTriangleColorFrame:0,solidLightingPreviewPrepared:!1,solidLightingPreviewActive:!1,bakedRotation:p.rotation?[...p.rotation]:[0,0,0],autoMeshId:j,rebakeInFlight:!1,rebakeQueuedLightDir:null,textureReadyPromise:lo},st=null,ft=0,at=-1,Je=null;function We(){st=null,Je=null,at=-1}function gt(){let D=st;if(!D||D.polygonCount!==E.polygons.length)return E.polygons;if(Je&&at===ft)return Je;let U=D.vertices,ce=new Array(D.polygonCount);for(let fe=0;fe<D.polygonCount;fe++){let Re=E.polygons[fe],ie=fe*9;ce[fe]={...Re,color:D.colors?.[fe]??Re.color,vertices:[[U[ie],U[ie+1],U[ie+2]],[U[ie+3],U[ie+4],U[ie+5]],[U[ie+6],U[ie+7],U[ie+8]]]}}return Je=ce,at=ft,ce}function ct(D,U){let ce=D?.stableTriangleUpdateMode==="color-only";E.stableTriangleColorFrame++;let fe=E.stableDom&&!U;if(fe||Te(E.polygons),E.stableDom&&!E.hasBuckets){let Re={doc:l,directionalLight:bt(r.directionalLight),ambientLight:r.ambientLight,textureLighting:r.textureLighting,textureQuality:r.textureQuality,textureLeafSizing:r.textureLeafSizing,textureImageRendering:r.textureImageRendering,textureBackend:r.textureBackend,textureProjection:r.textureProjection,seamBleed:r.seamBleed},ie=E.rendered.length===E.polygons.length&&E.rendered.every(Ne=>Ne.kind==="triangle"),be=E.stableDom&&!U,Ye=ie||be?{}:zt(E.polygons,Re);ie||At(E.wrapper,Ye);let et={...Re,solidPaintDefaults:Ye,optimizeStableTriangleStyle:!0,stableTriangleDebug:D?.stableTriangleDebug,stableTriangleUpdateMode:D?.stableTriangleUpdateMode,stableTriangleColorPolicy:D?.stableTriangleColorPolicy,stableTriangleColorSteps:D?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:D?.stableTriangleColorFreezeFrames,stableTriangleColorBudget:D?.stableTriangleColorBudget,stableTriangleColorMaxAge:D?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:D?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:D?.stableTriangleMatrixDecimals,stableTriangleColorFrame:E.stableTriangleColorFrame};if(no(E.rendered,E.polygons,et))return ce||(K(E),He(E,!0),U&&St()),!0}return fe&&Te(E.polygons),!1}let oe={get polygons(){return gt()},set polygons(D){We(),E.polygons=D},element:T,id:p.id,get transform(){return H},remove(){W++,T.parentNode&&T.parentNode.removeChild(T),L(E),f.delete(E),b.delete(T),z(E),V(E),St(),Pt()},setPolygons(D,U){W++,k=U?.merge??k,$=U?.stableDom??$,E.stableDom=$,E.voxelSource=void 0,E.polygons=ue(D,k),V(E),z(E),We(),oe.polygons=E.polygons;let ce=U?.recomputeAutoCenter??!0;X(E),!ct(U,ce)&&(ze(E),ce&&St())},[Ri](D,U){let ce=U?.merge??k,fe=U?.stableDom??$;if(!D.solidTriangles||!fe||ce||p.meshResolution!==void 0||E.hasBuckets||D.polygonCount!==E.polygons.length||D.vertices.length<D.polygonCount*9||E.rendered.length!==D.polygonCount)return!1;for(let be=0;be<E.rendered.length;be++){let Ye=E.rendered[be],et=E.polygons[be];if(Ye?.kind!=="triangle"||Ye.polygonIndex!==be||!et||et.vertices.length!==3||et.texture||et.material?.texture)return!1}let Re=U?.recomputeAutoCenter??!0;if(!Re){let be=E.stableTriangleColorFrame+1,Ye={doc:l,directionalLight:bt(r.directionalLight),ambientLight:r.ambientLight,textureLighting:r.textureLighting,textureQuality:r.textureQuality,textureLeafSizing:r.textureLeafSizing,textureImageRendering:r.textureImageRendering,textureBackend:r.textureBackend,textureProjection:r.textureProjection,seamBleed:r.seamBleed,solidPaintDefaults:{},optimizeStableTriangleStyle:!0,stableTriangleDebug:U?.stableTriangleDebug,stableTriangleUpdateMode:U?.stableTriangleUpdateMode,stableTriangleColorPolicy:U?.stableTriangleColorPolicy,stableTriangleColorSteps:U?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:U?.stableTriangleColorFreezeFrames??0,stableTriangleColorBudget:U?.stableTriangleColorBudget,stableTriangleColorMaxAge:U?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:U?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:U?.stableTriangleMatrixDecimals,stableTriangleColorFrame:be};if(to(E.rendered,E.polygons,D,Ye))return W++,k=ce,$=fe,E.stableDom=$,E.voxelSource=void 0,E.stableTriangleColorFrame=be,st=D,ft++,Je=null,at=-1,xe(E)?(K(E),He(E,!0)):Se(E),!0}W++,k=ce,$=fe,E.stableDom=$,E.voxelSource=void 0;let ie=D.vertices;for(let be=0;be<D.polygonCount;be++){let Ye=E.polygons[be],et=D.colors?.[be];et&&(Ye.color=et);let Ne=Ye.vertices,tt=be*9;Ne[0][0]=ie[tt],Ne[0][1]=ie[tt+1],Ne[0][2]=ie[tt+2],Ne[1][0]=ie[tt+3],Ne[1][1]=ie[tt+4],Ne[1][2]=ie[tt+5],Ne[2][0]=ie[tt+6],Ne[2][1]=ie[tt+7],Ne[2][2]=ie[tt+8]}return We(),oe.polygons=E.polygons,ct(U,Re)},updatePolygon(D,U){let ce=typeof D=="number"?D:E.polygons.indexOf(D);if(ce<0&&typeof D!="number"&&st&&(ce=gt().indexOf(D)),ce<0||ce>=E.polygons.length)return;We(),E.voxelSource=void 0,Object.assign(E.polygons[ce],U);let fe=Object.keys(U);Ke(E,ce,fe)||ze(E)},async setPolygonsChunked(D,U){let ce=++W;k=U?.merge??k,$=U?.stableDom??$,E.stableDom=$,E.voxelSource=void 0,E.polygons=ue(D,k),We(),oe.polygons=E.polygons,Te(E.polygons);let fe=U?.recomputeAutoCenter??!0;if(!await fs(E,()=>E.disposed||ce!==W)){L(E);return}fe&&St()},setTransform(D){let U=E.castShadow,ce=E.receiveShadow,fe=E.shadowDefinition;D.castShadow!==void 0&&(E.castShadow=!!D.castShadow),D.receiveShadow!==void 0&&(E.receiveShadow=!!D.receiveShadow),D.shadowDefinition!==void 0&&(E.shadowDefinition=D.shadowDefinition),H={...H,...D};let Re=ro(H);T.style.transform=Re??"",Kt(E,H.rotation),D.rotation!==void 0&&He(E,!0),E.castShadow!==U&&(E.voxelSource&&ze(E),Be(E),Pt()),E.receiveShadow!==ce&&(E.receiveShadow||tr(E),M(),Ve()),(D.position!==void 0||D.scale!==void 0)&&(E.castShadow||E.receiveShadow)&&(Pt(),M(),Ve()),E.shadowDefinition!==fe&&(E.castShadow||E.receiveShadow)&&(M(),Ve())},dispose(){if(!E.disposed){E.disposed=!0,W++,T.parentNode&&T.parentNode.removeChild(T),L(E);try{s.dispose()}catch{}f.delete(E),b.delete(T),St(),Pt()}},rebakeAtlas(){E.bakedRotation=H.rotation?[...H.rotation]:[0,0,0];let D=r.directionalLight?.direction??[.4,-.7,.59],U=(0,J.inverseRotateVec3)(D,E.bakedRotation);ds(E,U)},whenTexturesReady(){return E.textureReadyPromise},getPosition(){return H.position},getRotation(){return H.rotation},getScale(){return H.scale},getPolygons(){return oe.polygons}};return E.handle=oe,Ue=E,b.set(T,E),f.add(E),ze(E),Kt(E,H.rotation),St(),Pt(),E.receiveShadow&&(M(),Ve()),oe}function hs(s){let p=!!r.autoCenter,P=r.strategies,T=r.seamBleed,j=r.textureLeafSizing,H=r.textureImageRendering,k=r.textureBackend,$=r.textureProjection,W=r.textureLighting,me=r.directionalLight?.direction,ue=r.directionalLight?.intensity,q=r.directionalLight?.color,le=r.shadow,ve=r.pointLights,Te=ki(s);r={...r,...Te},x.options.current=r,ae(g,r);let Ue=!!r.autoCenter;for(let ie of f)Kt(ie,ie.handle.transform.rotation);let E=s.strategies!==void 0&&!si(s.strategies,P),st=Object.prototype.hasOwnProperty.call(s,"seamBleed")&&Te.seamBleed!==T,ft=Object.prototype.hasOwnProperty.call(s,"textureLeafSizing")&&Te.textureLeafSizing!==j,at=Object.prototype.hasOwnProperty.call(s,"textureImageRendering")&&Te.textureImageRendering!==H,Je=Object.prototype.hasOwnProperty.call(s,"textureBackend")&&Te.textureBackend!==k,We=Object.prototype.hasOwnProperty.call(s,"textureProjection")&&Te.textureProjection!==$,gt=ie=>(ie??[]).map(be=>`${be.position.join(",")}|${be.color??""}|${be.intensity??1}|${be.castShadow?1:0}`).join(";"),ct=Object.prototype.hasOwnProperty.call(s,"pointLights")&&gt(r.pointLights)!==gt(ve);if(E||st||ft||at||Je||We||ct)for(let ie of f)ze(ie);p!==Ue&&St();let oe=s.textureLighting!==void 0&&W!==r.textureLighting,D=r.directionalLight,U=s.directionalLight!==void 0&&(!ai(me,D?.direction)||(ue??1)!==(D?.intensity??1)||(q??"#ffffff")!==(D?.color??"#ffffff")),ce=r.shadow,fe=s.shadow!==void 0&&!li(le,ce),Re=U||fe||ct;if(oe){if(!E&&!st&&!ft&&!at&&!Je&&!We)for(let ie of f)ze(ie);Pt(),M(),Ve()}else Re&&((fe||U)&&M(),Ve(void 0,{progressive:(U||ct)&&!fe}));fe&&s.shadow?.lift!==le?.lift&&Pt()}function ys(){return r}function bs(){F(m,r),y(g);for(let s of f)He(s)}function xs(){let s=[];for(let p of f)s.push(p.handle);return s}function vs(){return Promise.all(Array.from(f,s=>s.handle.whenTexturesReady())).then(()=>{})}function Ps(s){let p=s;for(;p;){if(p instanceof HTMLElement){let P=b.get(p);if(P&&!P.disposed)return P.handle;if(p.classList.contains("polycss-mesh"))return null}p=p.parentElement}return null}function Ss(){R&&(clearTimeout(R),R=null);let s=Array.from(f);for(let p of s)try{p.handle.dispose()}catch{}m.parentNode&&m.parentNode.removeChild(m)}return{add:gs,setOptions:hs,destroy:Ss,host:e,camera:t,cameraEl:m,sceneElement:g,applyCamera:bs,getOptions:ys,meshes:xs,whenTexturesReady:vs,findMeshByElement:Ps,previewBakedSolidLighting:vt,commitBakedSolidLighting:Fe,clearBakedSolidLightingPreview:Jt}}var nr=require("@layoutit/polycss-core"),Ga=32e3;function co(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,nr.createIsometricCamera)(n),o=`${e.perspective??Ga}px`;return{get state(){return t.state},update(i){t.update(i)},getStyle(i){return t.getStyle(i)},type:"perspective",perspectiveStyle:o}}function gn(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,nr.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var Ua=typeof HTMLElement<"u"?HTMLElement:class{},Wa=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","texture-leaf-sizing","texture-image-rendering","texture-backend","texture-projection","auto-center"];function Qe(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Ya(e){return e==="false"?!1:Qe(e)}function or(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==="baked"||e==="dynamic")return e}function Za(e){return e==="auto"?"auto":Qe(e)}function Qa(e){if(e==="canonical"||e==="local"||e==="raster")return e}function qa(e){if(e==="auto"||e==="pixelated")return e}function Ka(e){if(e==="auto"||e==="atlas"||e==="image")return e}function Ja(e){if(e==="affine"||e==="projective")return e}function el(e){return typeof e.getCamera=="function"}var Oe=class extends Ua{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...Wa]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(el(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=Ya(this.getAttribute("perspective")),o=Qe(this.getAttribute("rot-x")),i=Qe(this.getAttribute("rot-y")),r=Qe(this.getAttribute("zoom")),a=Qe(this.getAttribute("distance")),c=or(this.getAttribute("target")),l={...o!==void 0?{rotX:o}:{},...i!==void 0?{rotY:i}:{},...r!==void 0?{zoom:r}:{},...a!==void 0?{distance:a}:{},...c!==void 0?{target:c}:{}};return t===!1?gn(l):t!==void 0?co({...l,perspective:t}):gn(l)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),i={};i.textureLighting=Xa(this.getAttribute("texture-lighting"))??"baked";let r=Za(this.getAttribute("texture-quality"));r!==void 0&&(i.textureQuality=r),i.textureLeafSizing=Qa(this.getAttribute("texture-leaf-sizing"))??"canonical";let a=qa(this.getAttribute("texture-image-rendering"));a!==void 0&&(i.textureImageRendering=a);let c=Ka(this.getAttribute("texture-backend"));c!==void 0&&(i.textureBackend=c);let l=Ja(this.getAttribute("texture-projection"));return l!==void 0&&(i.textureProjection=l),i.autoCenter=this.hasAttribute("auto-center"),t&&(i.directionalLight=t),o&&(i.ambientLight=o),i}_readDirectionalLight(){let t=or(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,i=Qe(this.getAttribute("directional-intensity"));if(!t&&!o&&i===void 0)return;let r={direction:t??[.4,-.7,.59]};return o&&(r.color=o),i!==void 0&&(r.intensity=i),r}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=Qe(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let i={};return t&&(i.color=t),o!==void 0&&(i.intensity=o),i}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=Oi(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,i){if(o!==i&&this._scene){if(this._implicitCamera&&["rot-x","rot-y","zoom","distance","target"].includes(t)){let a=Qe(this.getAttribute("rot-x")),c=Qe(this.getAttribute("rot-y")),l=Qe(this.getAttribute("zoom")),m=Qe(this.getAttribute("distance")),g=or(this.getAttribute("target"));a!==void 0&&this._implicitCamera.update({rotX:a}),c!==void 0&&this._implicitCamera.update({rotY:c}),l!==void 0&&this._implicitCamera.update({zoom:l}),m!==void 0&&this._implicitCamera.update({distance:m}),g!==void 0&&this._implicitCamera.update({target:g}),this._scene.applyCamera();return}this._scene.setOptions(this._readNonCameraOptions())}}};var uo=require("@layoutit/polycss-core"),tl=typeof HTMLElement<"u"?HTMLElement:class{},nl=["src","mtl","mesh-resolution","position","scale","rotation","auto-center","cast-shadow","receive-shadow","target-size","default-color","palette","include-objects","exclude-objects"];function hn(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 Ii(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return hn(e)}}function rr(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 ol(e){let n=e.getAttribute("target-size"),t=e.getAttribute("default-color"),o=rr(e.getAttribute("palette")),i=rr(e.getAttribute("include-objects")),r=rr(e.getAttribute("exclude-objects")),a=n!==null?parseFloat(n):NaN,c={};return Number.isFinite(a)&&(c.targetSize=a),t&&(c.defaultColor=t),o&&(c.palette=o),i&&(c.includeObjects=i),r&&(c.excludeObjects=r),Object.keys(c).length>0?c:void 0}function rl(e){return e.closest("poly-scene")??null}function il(e){if(e.length===0)return e;let n=(0,uo.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,i=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&i===0)return e;let r=a=>[a[0]-t,a[1]-o,a[2]-i];return e.map(a=>({...a,vertices:a.vertices.map(r),...a.textureTriangles?.length?{textureTriangles:a.textureTriangles.map(c=>({...c,vertices:c.vertices.map(r)}))}:null}))}var wt=class extends tl{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...nl]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,i){if(o!==i){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:hn(this.getAttribute("position")),scale:Ii(this.getAttribute("scale")),rotation:hn(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=rl(this);if(!o)return;let i=++this._loadToken,r=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,l=ol(this),m;try{let f=r||c!==void 0||l?{...r?{mtlUrl:r}:{},...c!==void 0?{meshResolution:c}:{},...l?{objOptions:l}:{}}:void 0;m=await(0,uo.loadMesh)(t,f)}catch(f){this.dispatchEvent(new CustomEvent("polycss:error",{detail:f,bubbles:!0}));return}if(i!==this._loadToken){try{m.dispose()}catch{}return}let g=o.getScene();if(!g){try{m.dispose()}catch{}return}this.hasAttribute("auto-center")&&(m={...m,polygons:il(m.polygons)}),this._parseResult=m,this._handle=g.add(m,{position:hn(this.getAttribute("position")),scale:Ii(this.getAttribute("scale")),rotation:hn(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 Ut=require("@layoutit/polycss-core"),sl=typeof HTMLElement<"u"?HTMLElement:class{},al=["src","width","height","position","rotation","scale","allow","loading","referrerpolicy","sandbox","title"];function ir(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 ll(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return ir(e)}}function Hi(e,n){if(e===null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}function cl(e){let n=e.closest("poly-scene");return n?n.querySelector(".polycss-scene"):null}function ul(e,n,t,o,i){let r=typeof t=="number"?t:t?.[0]??1,a=typeof t=="number"?t:t?.[1]??1,c=typeof t=="number"?t:t?.[2]??1,l=r!==1||a!==1||c!==1,m=!!n&&(!!n[0]||!!n[1]||!!n[2]),g=(e?.[1]??0)*Ut.BASE_TILE,x=(e?.[0]??0)*Ut.BASE_TILE,f=(e?.[2]??0)*Ut.BASE_TILE,b=[];return b.push(`translate3d(${g}px, ${x}px, ${f}px)`),m&&(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(${r}, ${a}, ${c})`),b.push(`translate(${-o/2}px, ${-i/2}px)`),b.join(" ")}var yn=class extends sl{constructor(){super(...arguments);this._wrapper=null;this._iframe=null}static get observedAttributes(){return[...al]}getIframeElement(){return this._iframe}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,i){if(o!==i&&!(!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 r=this.getAttribute(t);r===null?this._iframe.removeAttribute(t):this._iframe.setAttribute(t,r);return}this._applyGeometry()}}_mount(){let t=cl(this);if(!t)return;let o=this.ownerDocument;if(!o)return;let i=o.createElement("div");i.className="polycss-iframe",i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.transformOrigin="0 0",i.style.transformStyle="preserve-3d";let r=o.createElement("iframe");r.style.display="block",r.style.border="0",r.style.background="#000";let a=this.getAttribute("src");a&&(r.src=a);let c=this.getAttribute("allow");c&&r.setAttribute("allow",c);for(let l of["loading","referrerpolicy","sandbox","title"]){let m=this.getAttribute(l);m!==null&&r.setAttribute(l,m)}i.appendChild(r),t.appendChild(i),this._wrapper=i,this._iframe=r,this._applyGeometry()}_applyGeometry(){if(!this._wrapper||!this._iframe)return;let t=Hi(this.getAttribute("width"),16),o=Hi(this.getAttribute("height"),9),i=t*Ut.BASE_TILE,r=o*Ut.BASE_TILE;this._iframe.style.width=`${i}px`,this._iframe.style.height=`${r}px`;let a=ir(this.getAttribute("position")),c=ir(this.getAttribute("rotation")),l=ll(this.getAttribute("scale"));this._wrapper.style.transform=ul(a,c,l,i,r)}_teardown(){this._wrapper?.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null,this._iframe=null}};var dl=typeof HTMLElement<"u"?HTMLElement:class{},pl=["vertices","color","texture","uvs","position","scale","rotation"];function Fi(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function sr(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 ml(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return sr(e)}}function fl(e){return e.closest("poly-scene")??null}var bn=class extends dl{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...pl]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,i){o!==i&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=fl(this);if(!t)return;let o=t.getScene();if(!o)return;let i=Fi(this.getAttribute("vertices"));if(!i||!Array.isArray(i)||i.length<3)return;let r=this.getAttribute("color")||void 0,a=this.getAttribute("texture")||void 0,c=Fi(this.getAttribute("uvs"))??void 0,l={};for(let x of Array.from(this.attributes))x.name.startsWith("data-")&&(l[x.name.slice(5)]=x.value);let g={polygons:[{vertices:i,...r!==void 0?{color:r}:{},...a!==void 0?{texture:a}:{},...c!==void 0?{uvs:c}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(g,{position:sr(this.getAttribute("position")),scale:ml(this.getAttribute("scale")),rotation:sr(this.getAttribute("rotation"))})}};var Vi=require("@layoutit/polycss-core"),gl=typeof HTMLElement<"u"?HTMLElement:class{},hl=["size","thickness","negative","x-color","y-color","z-color"];function yl(e){return e.closest("poly-scene")??null}function Bi(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}var xn=class extends gl{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...hl]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,i){o!==i&&this._handle&&this._remount()}_polygons(){return(0,Vi.axesHelperPolygons)({size:Bi(this.getAttribute("size")),thickness:Bi(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=yl(this);if(!t)return;let o=t.getScene();if(!o)return;let i={polygons:this._polygons(),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(i,{excludeFromAutoCenter:!0,merge:!1})}_remount(){this._tearDown(),this._mount()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}};var ji=require("@layoutit/polycss-core"),bl=typeof HTMLElement<"u"?HTMLElement:class{},xl=["direction","target","distance","size","color"],vl=5,Pl=.35,Sl="#ffd54a";function Cl(e){return e.closest("poly-scene")??null}function zi(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Ni(e,n){if(e==null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}var vn=class extends bl{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...xl]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,i){if(o!==i&&this._handle){if(t==="size"||t==="color"){this._remount();return}this._handle.setTransform({position:this._meshPosition()})}}_meshPosition(){let t=zi(this.getAttribute("direction"));if(!t)return;let o=zi(this.getAttribute("target"))??[0,0,0],i=Ni(this.getAttribute("distance"),vl),[r,a,c]=t,l=Math.hypot(r,a,c)||1;return[o[0]+r/l*i,o[1]+a/l*i,o[2]+c/l*i]}_mount(){let t=Cl(this);if(!t)return;let o=t.getScene();if(!o)return;let i=Ni(this.getAttribute("size"),Pl),r=this.getAttribute("color")??Sl,a={polygons:(0,ji.octahedronPolygons)({center:[0,0,0],size:i,color:r}),objectUrls:[],dispose:()=>{},warnings:[]};this._handle=o.add(a,{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 $i=require("@layoutit/polycss-core");var po={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Wt(e,n){let t;return n.animate===!1?t=!1:n.animate?t={speed:n.animate.speed??.3,axis:n.animate.axis??"y",pauseOnInteraction:n.animate.pauseOnInteraction??!0}:t=e.animate,{drag:n.drag??e.drag,wheel:n.wheel??e.wheel,dolly:n.dolly??e.dolly,invert:n.invert??e.invert,minZoom:n.minZoom??e.minZoom,maxZoom:n.maxZoom??e.maxZoom,minDistance:n.minDistance??e.minDistance,maxDistance:n.maxDistance??e.maxDistance,animate:t}}function Pn(e){return e===!0?-1:e===!1?1:e}function Yt(){let e=[],n=[],t=[];function o(a){return a==="change"?e:a==="start"?n:t}function i(a){if(e.length===0)return;let c={type:"change",camera:a()},l=e.slice();for(let m of l)try{m(c)}catch(g){console.error("[polycss] controls 'change' listener threw:",g)}}function r(a,c){let l=a==="start"?n:t;if(l.length===0)return;let m={type:a,camera:c()},g=l.slice();for(let x of g)try{x(m)}catch(f){console.error(`[polycss] controls '${a}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:i,emitInteraction:r}}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 mo(e,n,t,o,i,r){let a=!1,c=null;return{onWheel:g=>{let x=n();if(!x.wheel||t())return;g.preventDefault();let f=g.deltaMode===1?16:g.deltaMode===2?100:1,b=g.deltaY*f;g.ctrlKey?b*=10:b*=3;let h=e.camera.state;if(x.dolly){let S=h.distance??0,v=Math.max(x.minDistance,Math.min(x.maxDistance,S+b*.05));e.camera.update({distance:v})}else{let S=Math.exp(-b*513e-6),v=h.zoom??1,C=Math.max(x.minZoom,Math.min(x.maxZoom,v*S));e.camera.update({zoom:C})}e.applyCamera(),a||(a=!0,r("start",o)),i(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,a=!1,r("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),a=!1}}}function fo(e,n,t,o,i,r,a){let c=null,l=0,m=b=>{if(c===null||o())return;let h=t();if(!h.animate){c=null;return}if(i())l=b;else{let S=Math.min(50,l?b-l:16.67);l=b;let v=h.animate.speed*(S/16.67),C=n.camera.state;if(h.animate.axis==="x"){let R=(((C.rotX??65)+v)%360+360)%360;n.camera.update({rotX:R})}else{let R=(((C.rotY??45)+v)%360+360)%360;n.camera.update({rotY:R})}n.applyCamera(),a(r)}c=e.requestAnimationFrame(m)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(m))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function Gi(e,n={}){let t=Wt(po,n),o=e.host,i=o.ownerDocument?.defaultView??globalThis,r=null,a={x:0,y:0},c=!1,l=!1,m=Yt(),g=Xt(e),{changeListeners:x,startListeners:f,endListeners:b,listenerArray:h,emitChange:S,emitInteraction:v}=m,C=fo(i,e,()=>t,()=>l,()=>c,g,S),R=u=>{if(!(!t.drag||l)&&r===null&&u.isPrimary!==!1){u.preventDefault(),r=u.pointerId,a={x:u.clientX,y:u.clientY},o.style.cursor="grabbing";try{u.target.setPointerCapture(u.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),v("start",g)}},I=u=>{if(r===null||u.pointerId!==r||!t.drag||l)return;u.preventDefault();let d=u.clientX-a.x,A=u.clientY-a.y;a={x:u.clientX,y:u.clientY};let _=Pn(t.invert),N=d/4*_,Y=A/4*_,w=e.camera.state;if(u.shiftKey){let ee=w.rotX??65,te=w.rotY??45,ne=Math.max(.01,w.zoom??1),ye=Math.cos(ee*Math.PI/180),K=ye>=0?Math.max(.1,ye):Math.min(-.1,ye),ge=Math.cos(te*Math.PI/180),xe=Math.sin(te*Math.PI/180),Se=ne*$i.BASE_TILE,qe=(d*xe-A*ge/K)/Se,He=-(d*ge+A*xe/K)/Se,rt=w.target??[0,0,0];e.camera.update({target:[rt[0]+qe,rt[1]+He,rt[2]]})}else{let ee=Math.max(0,Math.min(89,(w.rotX??65)-Y)),te=(((w.rotY??45)-N)%360+360)%360;e.camera.update({rotX:ee,rotY:te})}e.applyCamera(),S(g)},B=u=>{if(r===u.pointerId){r=null,o.style.cursor=t.drag&&!l?"grab":"";try{u.target.releasePointerCapture(u.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),v("end",g)}},O=mo(e,()=>t,()=>l,g,S,v);function X(){o.addEventListener("pointerdown",R),o.addEventListener("pointermove",I),o.addEventListener("pointerup",B),o.addEventListener("pointercancel",B),o.addEventListener("wheel",O.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function Z(){o.removeEventListener("pointerdown",R),o.removeEventListener("pointermove",I),o.removeEventListener("pointerup",B),o.removeEventListener("pointercancel",B),o.removeEventListener("wheel",O.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",O.teardown()}X(),C.start();function M(u){let d=!!t.animate;t=Wt(t,u),!l&&r===null&&(o.style.cursor=t.drag?"grab":"");let A=!!t.animate;d&&!A?C.stop():!d&&A&&C.start()}function z(){l&&(l=!1,X(),C.start())}function V(){l||(l=!0,Z(),C.stop(),r=null,c=!1,O.teardown())}function F(){V(),x.length=0,f.length=0,b.length=0}function ae(u,d){let A=h(u);A.includes(d)||A.push(d)}function y(u,d){let A=h(u),_=A.indexOf(d);_>=0&&A.splice(_,1)}function L(u,d){return h(u).includes(d)}return{update:M,resume:z,pause:V,destroy:F,addEventListener:ae,removeEventListener:y,hasEventListener:L}}function se(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function go(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 Ie(e){if(e!==null)return!(e==="false"||e==="0")}function ho(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 yo(e){if(e==="x"||e==="y")return e}var El=typeof HTMLElement<"u"?HTMLElement:class{},Tl=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Sn=class extends El{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Tl]}getControls(){return this._controls}_readAnimate(){let t=se(this.getAttribute("animate-speed")),o=yo(this.getAttribute("animate-axis")),i=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}:{},...i!==null?{pauseOnInteraction:Ie(i)}:{}}}_readOptions(){let t={},o=Ie(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let i=Ie(this.getAttribute("wheel"));i!==void 0&&(t.wheel=i),this.hasAttribute("dolly")&&(t.dolly=!0);let r=se(this.getAttribute("min-distance"));r!==void 0&&(t.minDistance=r);let a=se(this.getAttribute("max-distance"));a!==void 0&&(t.maxDistance=a);let c=ho(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=se(this.getAttribute("zoom-min")),m=se(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),m!==void 0&&(t.maxZoom=m),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Oe)return t;t=t.parentNode}return null}_attach(){if(this._controls)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._controls=Gi(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,i){o!==i&&this._controls&&this._controls.update(this._readOptions())}};var Ui=require("@layoutit/polycss-core");function Wi(e,n={}){let t=Wt(po,n),o=e.host,i=o.ownerDocument?.defaultView??globalThis,r=null,a={x:0,y:0},c=!1,l=!1,m=!1,g={x:0,y:0},x=Yt(),f=Xt(e),{changeListeners:b,startListeners:h,endListeners:S,listenerArray:v,emitChange:C,emitInteraction:R}=x,I=fo(i,e,()=>t,()=>l,()=>c,f,C),B=w=>{if(!(!t.drag||l)&&r===null&&w.isPrimary!==!1){w.preventDefault(),r=w.pointerId,a={x:w.clientX,y:w.clientY},o.style.cursor="grabbing";try{w.target.setPointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),R("start",f)}},O=w=>{if(r===null||w.pointerId!==r||!t.drag||l)return;w.preventDefault();let ee=w.clientX-a.x,te=w.clientY-a.y;a={x:w.clientX,y:w.clientY};let ne=e.camera.state;if(w.shiftKey){let ye=Pn(t.invert),K=ee/4*ye,ge=te/4*ye,xe=(ne.rotX??65)-ge,Se=(((ne.rotY??45)-K)%360+360)%360;e.camera.update({rotX:xe,rotY:Se})}else{let ye=ne.rotX??65,K=ne.rotY??45,ge=Math.max(.01,ne.zoom??1),xe=Math.cos(ye*Math.PI/180),Se=xe>=0?Math.max(.1,xe):Math.min(-.1,xe),qe=Math.cos(K*Math.PI/180),He=Math.sin(K*Math.PI/180),rt=ge*Ui.BASE_TILE,qt=(ee*He-te*qe/Se)/rt,mt=-(ee*qe+te*He/Se)/rt,it=ne.target??[0,0,0];e.camera.update({target:[it[0]+qt,it[1]+mt,it[2]]})}e.applyCamera(),C(f)},X=w=>{if(r===w.pointerId){r=null,o.style.cursor=t.drag&&!l?"grab":"";try{w.target.releasePointerCapture(w.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),R("end",f)}},Z=w=>{w.preventDefault()},M=w=>{w.button===2&&(m=!0,g={x:w.clientX,y:w.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),R("start",f))},z=w=>{if(!m||!t.drag)return;let ee=w.clientX-g.x,te=w.clientY-g.y;g={x:w.clientX,y:w.clientY};let ne=Pn(t.invert),ye=ee/4*ne,K=te/4*ne,ge=e.camera.state,xe=(ge.rotX??65)-K,Se=(((ge.rotY??45)-ye)%360+360)%360;e.camera.update({rotX:xe,rotY:Se}),e.applyCamera(),C(f)},V=w=>{w.button===2&&m&&(m=!1,R("end",f))},F=mo(e,()=>t,()=>l,f,C,R);function ae(){o.addEventListener("pointerdown",B),o.addEventListener("pointermove",O),o.addEventListener("pointerup",X),o.addEventListener("pointercancel",X),o.addEventListener("wheel",F.onWheel,{passive:!1}),o.addEventListener("contextmenu",Z),o.addEventListener("mousedown",M),o.addEventListener("mousemove",z),o.addEventListener("mouseup",V),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function y(){o.removeEventListener("pointerdown",B),o.removeEventListener("pointermove",O),o.removeEventListener("pointerup",X),o.removeEventListener("pointercancel",X),o.removeEventListener("wheel",F.onWheel),o.removeEventListener("contextmenu",Z),o.removeEventListener("mousedown",M),o.removeEventListener("mousemove",z),o.removeEventListener("mouseup",V),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",F.teardown()}ae(),I.start();function L(w){let ee=!!t.animate;t=Wt(t,w),!l&&r===null&&(o.style.cursor=t.drag?"grab":"");let te=!!t.animate;ee&&!te?I.stop():!ee&&te&&I.start()}function u(){l&&(l=!1,ae(),I.start())}function d(){l||(l=!0,y(),I.stop(),r=null,c=!1,m=!1,F.teardown())}function A(){d(),b.length=0,h.length=0,S.length=0}function _(w,ee){let te=v(w);te.includes(ee)||te.push(ee)}function N(w,ee){let te=v(w),ne=te.indexOf(ee);ne>=0&&te.splice(ne,1)}function Y(w,ee){return v(w).includes(ee)}return{update:L,resume:u,pause:d,destroy:A,addEventListener:_,removeEventListener:N,hasEventListener:Y}}var Al=typeof HTMLElement<"u"?HTMLElement:class{},wl=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Cn=class extends Al{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...wl]}_readAnimate(){let t=se(this.getAttribute("animate-speed")),o=yo(this.getAttribute("animate-axis")),i=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}:{},...i!==null?{pauseOnInteraction:Ie(i)}:{}}}_readOptions(){let t={},o=Ie(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let i=Ie(this.getAttribute("wheel"));i!==void 0&&(t.wheel=i),this.hasAttribute("dolly")&&(t.dolly=!0);let r=se(this.getAttribute("min-distance"));r!==void 0&&(t.minDistance=r);let a=se(this.getAttribute("max-distance"));a!==void 0&&(t.maxDistance=a);let c=ho(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=se(this.getAttribute("zoom-min")),m=se(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),m!==void 0&&(t.maxZoom=m),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Oe)return t;t=t.parentNode}return null}_attach(){if(this._controls)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._controls=Wi(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,i){o!==i&&this._controls&&this._controls.update(this._readOptions())}};var Ji=require("@layoutit/polycss-core");var Ml={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 Yi(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 Xi=new Set(["KeyW","ArrowUp"]),Zi=new Set(["KeyS","ArrowDown"]),Qi=new Set(["KeyA","ArrowLeft"]),qi=new Set(["KeyD","ArrowRight"]),Ki=new Set(["Space"]),ar=new Set(["ControlLeft","ControlRight"]);function es(e,n={}){let t=Yi(Ml,n),o=e.host,i=e.cameraEl,r=o.ownerDocument??document,a=r.defaultView??globalThis,c=Yt(),l=Xt(e),{changeListeners:m,startListeners:g,endListeners:x,listenerArray:f,emitChange:b,emitInteraction:h}=c,S=new Set,v=!1,C=!1,R=0,I=0,B=!1,O=[0,0,t.groundZ+t.eyeHeight];function X(G,de){let pe=G*Math.PI/180,Fe=de*Math.PI/180;return[-Math.sin(pe)*Math.cos(Fe),-Math.sin(pe)*Math.sin(Fe),-Math.cos(pe)]}function Z(){let G=e.camera.perspectiveStyle,de=G==="none"?0:parseFloat(G);return(Number.isFinite(de)&&de>0?de:2e3)/Ji.BASE_TILE}function M(){let G=e.camera.state,de=X(G.rotX??90,G.rotY??0),pe=Z();return[O[0]+de[0]*pe,O[1]+de[1]*pe,O[2]+de[2]*pe]}function z(){let G=M();e.camera.update({target:G}),e.applyCamera()}function V(){let G=e.camera.state.target??[0,0,0];O=[G[0],G[1],t.groundZ+t.eyeHeight],z()}let F=()=>{if(!(!t.enabled||!t.lookEnabled||C||v))try{o.requestPointerLock()}catch{}},ae=()=>{let G=r.pointerLockElement===o;G!==v&&(v=G,v?(B=!0,h("start",l)):B&&(B=!1,h("end",l)))},y=G=>{if(!v||!t.enabled||!t.lookEnabled||C)return;let de=G.movementX??0,pe=G.movementY??0;if(de===0&&pe===0)return;let Fe=e.camera.state,Jt=t.lookSensitivity,en=t.invertY?-1:1,vt=(((Fe.rotY??0)-de*Jt)%360+360)%360,_e=(Fe.rotX??90)-pe*Jt*en;_e<t.minPitch?_e=t.minPitch:_e>t.maxPitch&&(_e=t.maxPitch);let Ge=X(_e,vt),Ke=Z(),Be=[O[0]+Ge[0]*Ke,O[1]+Ge[1]*Ke,O[2]+Ge[2]*Ke];e.camera.update({rotX:_e,rotY:vt,target:Be}),e.applyCamera(),b(l)},L=G=>Xi.has(G)||Zi.has(G)||Qi.has(G)||qi.has(G)||Ki.has(G)||ar.has(G),u=G=>{if(!(!t.enabled||C)&&L(G.code)&&!(!v&&!t.moveEnabled)){if(Ki.has(G.code)){if(!t.jumpEnabled)return;G.preventDefault(),!S.has(G.code)&&R===0&&I===0&&(R=t.jumpVelocity),S.add(G.code);return}ar.has(G.code)&&!t.crouchEnabled||!t.moveEnabled&&!ar.has(G.code)||(G.preventDefault(),S.add(G.code))}},d=G=>{L(G.code)&&S.delete(G.code)},A=()=>{S.clear()},_=null,N=0,Y=.05,w=G=>{if(_===null||C)return;let de=Math.min(Y,N?(G-N)/1e3:.0167);if(N=G,t.enabled){let pe=!1,Fe=e.camera.state;if(t.moveEnabled){let _e=0,Ge=0;for(let Ke of S)Xi.has(Ke)?_e+=1:Zi.has(Ke)?_e-=1:qi.has(Ke)?Ge+=1:Qi.has(Ke)&&(Ge-=1);if(_e!==0||Ge!==0){let Be=(Fe.rotY??0)*Math.PI/180,Ve=-Math.cos(Be),Nn=-Math.sin(Be),Eo=-Math.sin(Be),jn=Math.cos(Be),_t=Math.hypot(_e,Ge)||1,ze=t.moveSpeed*de;O[0]+=(Ve*_e+Eo*Ge)/_t*ze,O[1]+=(Nn*_e+jn*Ge)/_t*ze,pe=!0}}let en=t.crouchEnabled&&(S.has("ControlLeft")||S.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(R!==0||I>0)?(R-=t.gravity*de,I+=R*de,I<=0&&(I=0,R=0)):t.jumpEnabled||(I=0,R=0);let vt=t.groundZ+en+I;if(Math.abs(O[2]-vt)>1e-4&&(O[2]=vt,pe=!0),pe){let _e=M();e.camera.update({target:_e}),e.applyCamera(),b(l)}}_=a.requestAnimationFrame(w)};function ee(){_!==null||C||(N=0,_=a.requestAnimationFrame(w))}function te(){_!==null&&(a.cancelAnimationFrame(_),_=null)}function ne(){let de=i.ownerDocument?.defaultView?.getComputedStyle(i).perspective??"",pe=parseFloat(de),Fe=Number.isFinite(pe)&&pe>0?pe:2e3;i.style.setProperty("--polycss-fpv-perspective",`${Fe}px`),i.classList.add("polycss-fpv-host")}function ye(){i.classList.remove("polycss-fpv-host"),i.style.removeProperty("--polycss-fpv-perspective")}function K(){o.addEventListener("click",F),r.addEventListener("pointerlockchange",ae),r.addEventListener("mousemove",y),a.addEventListener("keydown",u),a.addEventListener("keyup",d),a.addEventListener("blur",A),o.style.cursor=t.lookEnabled?"crosshair":"",ne()}function ge(){if(o.removeEventListener("click",F),r.removeEventListener("pointerlockchange",ae),r.removeEventListener("mousemove",y),a.removeEventListener("keydown",u),a.removeEventListener("keyup",d),a.removeEventListener("blur",A),o.style.cursor="",S.clear(),v)try{r.exitPointerLock()}catch{}ye()}V(),K(),ee();function xe(G){let de=t.eyeHeight,pe=t.groundZ;t=Yi(t,G),C||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==de||t.groundZ!==pe)&&(O[2]=t.groundZ+t.eyeHeight,z(),b(l))}function Se(){C&&(C=!1,K(),ee())}function qe(){C||(C=!0,ge(),te(),B&&(B=!1,h("end",l)))}function He(){qe(),m.length=0,g.length=0,x.length=0}function rt(){if(!(!t.enabled||!t.lookEnabled||C))try{o.requestPointerLock()}catch{}}function qt(){if(v)try{r.exitPointerLock()}catch{}}function mt(){return v}function it(G,de){let pe=f(G);pe.includes(de)||pe.push(de)}function So(G,de){let pe=f(G),Fe=pe.indexOf(de);Fe>=0&&pe.splice(Fe,1)}function Co(G,de){return f(G).includes(de)}function Kt(){return[O[0],O[1],O[2]]}function zn(G){O[0]=G[0],O[1]=G[1],O[2]=G[2],z(),b(l)}return{update:xe,resume:Se,pause:qe,destroy:He,lock:rt,unlock:qt,isLocked:mt,getOrigin:Kt,setOrigin:zn,addEventListener:it,removeEventListener:So,hasEventListener:Co}}var Ll=typeof HTMLElement<"u"?HTMLElement:class{},_l=["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"],En=class extends Ll{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[..._l]}_readOptions(){let t={},o=Ie(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let i=Ie(this.getAttribute("look-enabled"));i!==void 0&&(t.lookEnabled=i);let r=Ie(this.getAttribute("move-enabled"));r!==void 0&&(t.moveEnabled=r);let a=Ie(this.getAttribute("jump-enabled"));a!==void 0&&(t.jumpEnabled=a);let c=Ie(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let l=se(this.getAttribute("look-sensitivity"));if(l!==void 0&&(t.lookSensitivity=l),this.hasAttribute("invert-y")){let C=Ie(this.getAttribute("invert-y"));C!==void 0&&(t.invertY=C)}let m=se(this.getAttribute("move-speed"));m!==void 0&&(t.moveSpeed=m);let g=se(this.getAttribute("jump-velocity"));g!==void 0&&(t.jumpVelocity=g);let x=se(this.getAttribute("gravity"));x!==void 0&&(t.gravity=x);let f=se(this.getAttribute("eye-height"));f!==void 0&&(t.eyeHeight=f);let b=se(this.getAttribute("crouch-height"));b!==void 0&&(t.crouchHeight=b);let h=se(this.getAttribute("ground-z"));h!==void 0&&(t.groundZ=h);let S=se(this.getAttribute("min-pitch"));S!==void 0&&(t.minPitch=S);let v=se(this.getAttribute("max-pitch"));return v!==void 0&&(t.maxPitch=v),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Oe)return t;t=t.parentNode}return null}_attach(){if(this._controls)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._controls=es(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,i){o!==i&&this._controls&&this._controls.update(this._readOptions())}};var Rl=typeof HTMLElement<"u"?HTMLElement:class{},kl=["perspective","zoom","rot-x","rot-y","target","distance"],Tn=class extends Rl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...kl]}getCamera(){return this._camera}_readOptions(){return{perspective:se(this.getAttribute("perspective")),zoom:se(this.getAttribute("zoom")),rotX:se(this.getAttribute("rot-x")),rotY:se(this.getAttribute("rot-y")),target:go(this.getAttribute("target")),distance:se(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=co(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,i){if(o===i||!this._camera||!this._wrapper)return;let r=this._readOptions();if(t==="perspective"){let l=r.perspective!==void 0?`${r.perspective}px`:"32000px";this._wrapper.style.perspective=l;return}this._camera.update({rotX:r.rotX,rotY:r.rotY,zoom:r.zoom,target:r.target,distance:r.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var Dl=typeof HTMLElement<"u"?HTMLElement:class{},Ol=["zoom","rot-x","rot-y","target","distance"],Mt=class extends Dl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Ol]}getCamera(){return this._camera}_readOptions(){return{zoom:se(this.getAttribute("zoom")),rotX:se(this.getAttribute("rot-x")),rotY:se(this.getAttribute("rot-y")),target:go(this.getAttribute("target")),distance:se(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=gn(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,i){if(o===i||!this._camera)return;let r=this._readOptions();r.zoom!==void 0&&this._camera.update({zoom:r.zoom}),r.rotX!==void 0&&this._camera.update({rotX:r.rotX}),r.rotY!==void 0&&this._camera.update({rotY:r.rotY}),r.target!==void 0&&this._camera.update({target:r.target}),r.distance!==void 0&&this._camera.update({distance:r.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var An=class extends Mt{};var Le=require("@layoutit/polycss-core");function Zt(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let i of o){let r=i.getBoundingClientRect();if(!(r.width<=0||r.height<=0)&&n>=r.left&&n<=r.right&&t>=r.top&&t<=r.bottom)return!0}return!1}function ts(e,n,t,o){for(let i of e)if(!(o&&!o(i))&&Zt(i.element,n,t))return i;return null}var bo="#ff3653",xo="#8adb00",vo="#2c8fff",Qt=50,ns=60,Il=.6,Hl=.0125,Fl=.15,Bl=.04,Vl=1,os=.02,lr=1.04,zl=.1,Nl=.25,as=1e-4,jl=.6,$l=.8,Gl=1,pt={0:1,1:0,2:2},rs=[{cssAxis:0,sign:1,key:"x",color:bo},{cssAxis:0,sign:-1,key:"-x",color:bo},{cssAxis:1,sign:1,key:"y",color:xo},{cssAxis:1,sign:-1,key:"-y",color:xo},{cssAxis:2,sign:1,key:"z",color:vo},{cssAxis:2,sign:-1,key:"-z",color:vo}],is=[{cssAxis:0,key:"x",color:bo},{cssAxis:1,key:"y",color:xo},{cssAxis:2,key:"z",color:vo}],ss=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:vo},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:xo},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:bo}];function cr(e,n,t,o){let i=t*Math.PI/180,r=o*Math.PI/180,a=[0,0,0];a[e]=n;let c=a[0]*Math.cos(r)-a[1]*Math.sin(r),l=a[0]*Math.sin(r)+a[1]*Math.cos(r),m=a[2];return l*Math.sin(i)+m*Math.cos(i)<0}function Ul(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),i=parseInt(t[2],16),r=parseInt(t[3],16);return`rgba(${o}, ${i}, ${r}, ${n})`}function Po(e,n){return!n||n<=0?e:Math.round(e/n)*n}function Wl(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,i=-1/0,r=-1/0,a=-1/0;for(let c of e)for(let l of c.vertices)l[0]<n&&(n=l[0]),l[0]>i&&(i=l[0]),l[1]<t&&(t=l[1]),l[1]>r&&(r=l[1]),l[2]<o&&(o=l[2]),l[2]>a&&(a=l[2]);return Number.isFinite(n)?[(n+i)/2,(t+r)/2,(o+a)/2]:[0,0,0]}function ur(e){if(e.length===0)return ns;let n=1/0,t=1/0,o=1/0,i=-1/0,r=-1/0,a=-1/0;for(let l of e)for(let m of l.vertices)m[0]<n&&(n=m[0]),m[0]>i&&(i=m[0]),m[1]<t&&(t=m[1]),m[1]>r&&(r=m[1]),m[2]<o&&(o=m[2]),m[2]>a&&(a=m[2]);return Number.isFinite(n)?Math.max(i-n,r-t,a-o)*Qt*Il:ns}function Yl(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:i,target:r,startClientX:a,startClientY:c,translationSnap:l,onAxisDelta:m,onMouseDown:g,onMouseUp:x,onDraggingChanged:f}=e,b=o,h=[0,0,0];h[n]=t;let S=i.ownerDocument.createElement("div");S.style.position="absolute",S.style.left="0",S.style.top="0",S.style.width="0",S.style.height="0",S.style.transform=`translate3d(${h[0]*b}px, ${h[1]*b}px, ${h[2]*b}px)`,i.appendChild(S);let v=i.getBoundingClientRect(),C=S.getBoundingClientRect();i.removeChild(S);let R=(C.left-v.left)/b,I=(C.top-v.top)/b,B=R*R+I*I;if(B<as)return;g?.(),f?.(!0);let O=Z=>{let M=Z.clientX-a,z=Z.clientY-c,V=(M*R+z*I)/B;V=Po(V,l),m(V,h)},X=()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",X),window.removeEventListener("pointercancel",X);let Z=M=>{M.stopPropagation(),M.stopImmediatePropagation()};window.addEventListener("click",Z,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",Z,!0),0),x?.(),f?.(!1)};window.addEventListener("pointermove",O),window.addEventListener("pointerup",X),window.addEventListener("pointercancel",X)}function Xl(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:i,startClientX:r,startClientY:a,translationSnap:c,onPlaneDelta:l,onMouseDown:m,onMouseUp:g,onDraggingChanged:x}=e,f=[0,0,0];f[n]=1;let b=[0,0,0];b[t]=1;function h(B){let O=i.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(${B[0]*o}px, ${B[1]*o}px, ${B[2]*o}px)`,i.appendChild(O);let X=i.getBoundingClientRect(),Z=O.getBoundingClientRect();return i.removeChild(O),{x:(Z.left-X.left)/o,y:(Z.top-X.top)/o}}let S=h(f),v=h(b),C=S.x*v.y-v.x*S.y;if(Math.abs(C)<as)return;m?.(),x?.(!0);let R=B=>{let O=B.clientX-r,X=B.clientY-a,Z=(v.y*O-v.x*X)/C,M=(-S.y*O+S.x*X)/C;Z=Po(Z,c),M=Po(M,c),l(Z,M,f,b)},I=()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",I),window.removeEventListener("pointercancel",I);let B=O=>{O.stopPropagation(),O.stopImmediatePropagation()};window.addEventListener("click",B,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",B,!0),0),g?.(),x?.(!1)};window.addEventListener("pointermove",R),window.addEventListener("pointerup",I),window.addEventListener("pointercancel",I)}function Zl(e){let{cssAxis:n,wrapper:t,target:o,startClientX:i,startClientY:r,rotationSnap:a,onAngleDelta:c,onMouseDown:l,onMouseUp:m,onDraggingChanged:g}=e,x=t.getBoundingClientRect(),f=x.left,b=x.top,h=Math.atan2(r-b,i-f),S=0;l?.(),g?.(!0);let v=R=>{let I=Math.atan2(R.clientY-b,R.clientX-f),B=I-h;B>Math.PI?B-=2*Math.PI:B<-Math.PI&&(B+=2*Math.PI),S+=B,h=I;let O=S*180/Math.PI;O=Po(O,a),c(O)},C=()=>{window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",C),window.removeEventListener("pointercancel",C);let R=I=>{I.stopPropagation(),I.stopImmediatePropagation()};window.addEventListener("click",R,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",R,!0),0),m?.(),g?.(!1)};window.addEventListener("pointermove",v),window.addEventListener("pointerup",C),window.addEventListener("pointercancel",C)}function ls(e,n={}){let t=null,o=n.mode??"translate",i=n.size??1,r={...n},a=new Map,c=null,l=null,m=[0,0,0];function g(){if(!t)return[0,0,0];let y=t.transform.position??[0,0,0],L=t.transform.rotation??[0,0,0],u=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,d=(0,Le.rotateVec3)(m,L[0],L[1],L[2]);return[y[0]+u*d[0],y[1]+u*d[1],y[2]+u*d[2]]}function x(y){return l===y?Gl:c===y?$l:jl}function f(){for(let[y,L]of a){let u=b(L.spec,x(y));L.handle.setPolygons(u,{recomputeAutoCenter:!1})}}function b(y,L){let d=ur(t?.polygons??[])*i,A=d/Qt,_=Ul(y.color,L);if(y.kind==="arrow"){let w=e.camera.state,ee=cr(y.cssAxis,y.sign,w.rotX??65,w.rotY??45);return(0,Le.arrowPolygons)({axis:pt[y.cssAxis],sign:y.sign,shaftLength:A,shaftHalfThickness:A*Hl,headLength:A*Fl,headHalfThickness:A*Bl,color:_,shaft:!ee})}if(y.kind==="plane"){let w=e.camera.state,ee=w.rotX??65,te=w.rotY??45,ne=pt[y.perpAxis],ye=(ne+1)%3,K=(ne+2)%3,ge=pt[ye],xe=pt[K],Se=cr(ge,1,ee,te)?-1:1,qe=cr(xe,1,ee,te)?-1:1,He=A*Nl;return(0,Le.planePolygons)({axis:ne,size:A*zl,offset:[Se*He,qe*He],color:_})}let Y=d*Vl/Qt*lr;return(0,Le.ringQuadPolygons)({axis:pt[y.cssAxis],outerRadius:Y,color:_})}function h(y){return y.kind==="arrow"?"polycss-transform-arrow":y.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function S(){if(o==="translate"){let y=rs.map(u=>({kind:"arrow",key:u.key,cssAxis:u.cssAxis,sign:u.sign,color:u.color})),L=ss.map(u=>({kind:"plane",key:u.key,perpAxis:u.perpAxis,axisA:u.axisA,axisB:u.axisB,color:u.color}));return[...y,...L]}return o==="rotate"?is.map(y=>({kind:"ring",key:y.key,cssAxis:y.cssAxis,color:y.color})):[]}function v(){if(C(),!t)return;let y={x:r.showX!==!1,y:r.showY!==!1,z:r.showZ!==!1};function L(d){if(d.kind==="arrow"){let N=d.key.replace("-","")[0];return y[N]}if(d.kind==="ring")return y[d.key];let A=["x","y","z"][d.axisA],_=["x","y","z"][d.axisB];return y[A]&&y[_]}let u=g();for(let d of S()){if(!L(d))continue;let A=b(d,x(d.key)),_=e.add({polygons:A,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${d.key}`,position:u}),N=h(d);if(_.element.classList.add("polycss-transform-gizmo",N,`${N}--${d.key}`),d.kind==="ring"){let Y=(1-os)/lr,w=(1+os)/lr;_.element.style.setProperty("--ring-inner-ratio",`${Y}`),_.element.style.setProperty("--ring-outer-ratio",`${w}`)}a.set(d.key,{handle:_,spec:d})}}function C(){for(let{handle:y}of a.values())y.remove();a.clear(),c=null,l=null}function R(){if(!t)return;let y=g();for(let{handle:L}of a.values())L.setTransform({position:y})}function I(){t&&(a.size===0?v():R())}function B(y){if(t=y,!y){m=[0,0,0],C();return}m=Wl(y.polygons),C(),v()}function O(){B(null)}function X(y){y!==o&&(o=y,t&&(C(),v()))}function Z(y,L,u){if(!t||!M)return;let d=u[y.cssAxis],A=pt[y.cssAxis],_=L*d/Qt,N=M.slice();N[A]=M[A]+_,t.setTransform({position:N}),R(),r.onObjectChange?.({object:t,position:N}),r.onChange?.()}let M=null,z=null,V=y=>{if(!t||r.enabled===!1)return;let L={x:r.showX!==!1,y:r.showY!==!1,z:r.showZ!==!1};if(o==="translate"){for(let u of ss){let d=["x","y","z"][u.axisA],A=["x","y","z"][u.axisB];if(!L[d]||!L[A])continue;let _=a.get(u.key);if(_&&Zt(_.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=u.key,f(),M=(t.transform.position??[0,0,0]).slice(),Xl({axisA:u.axisA,axisB:u.axisB,probeDistanceCss:ur(t.polygons)*i,wrapper:_.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,translationSnap:r.translationSnap??null,onPlaneDelta:(N,Y,w,ee)=>{if(!t||!M)return;let te=w[u.axisA],ne=ee[u.axisB],ye=pt[u.axisA],K=pt[u.axisB],ge=M.slice();ge[ye]+=N*te/Qt,ge[K]+=Y*ne/Qt,t.setTransform({position:ge}),R(),r.onObjectChange?.({object:t,position:ge}),r.onChange?.()},onMouseDown:r.onMouseDown,onMouseUp:r.onMouseUp,onDraggingChanged:N=>{N||(l=null,M=null,f()),r.onDraggingChanged?.(N)}});return}}for(let u of rs){let d=u.key.replace("-","")[0];if(!L[d])continue;let A=a.get(u.key);if(A&&Zt(A.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=u.key,f(),M=(t.transform.position??[0,0,0]).slice(),Yl({cssAxis:u.cssAxis,sign:u.sign,shaftLengthCss:ur(t.polygons)*i,wrapper:A.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,translationSnap:r.translationSnap??null,onAxisDelta:(_,N)=>Z(u,_,N),onMouseDown:r.onMouseDown,onMouseUp:r.onMouseUp,onDraggingChanged:_=>{_||(l=null,M=null,f()),r.onDraggingChanged?.(_)}});return}}}else if(o==="rotate")for(let u of is){if(!L[u.key])continue;let d=a.get(u.key);if(d&&Zt(d.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=u.key,f(),z=(t.transform.rotation??[0,0,0]).slice(),M=(t.transform.position??[0,0,0]).slice(),Zl({cssAxis:u.cssAxis,wrapper:d.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,rotationSnap:r.rotationSnap??null,onAngleDelta:A=>{if(!t||!z||!M)return;let _=pt[u.cssAxis],N=[0,0,0];N[_]=1;let Y=-A*Math.PI/180,w=(0,Le.quatFromEulerXYZ)(z),ee=(0,Le.quatFromAxisAngle)(N,Y),te=(0,Le.eulerXYZFromQuat)((0,Le.quatMultiply)(ee,w)),ne=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,ye=(0,Le.rotateVec3)(m,z[0],z[1],z[2]),K=(0,Le.rotateVec3)(m,te[0],te[1],te[2]),ge=[M[0]+ne*(ye[0]-K[0]),M[1]+ne*(ye[1]-K[1]),M[2]+ne*(ye[2]-K[2])];t.setTransform({rotation:te,position:ge}),R(),r.onObjectChange?.({object:t,rotation:te,position:ge}),r.onChange?.()},onMouseDown:r.onMouseDown,onMouseUp:r.onMouseUp,onDraggingChanged:A=>{A||(l=null,z=null,M=null,f(),t?.rebakeAtlas()),r.onDraggingChanged?.(A)}});return}}};e.host.addEventListener("pointerdown",V,{capture:!0});let F=y=>{if(!t||l||r.enabled===!1)return;let L=null;for(let[u,d]of a)if(Zt(d.handle.element,y.clientX,y.clientY)){L=u;break}L!==c&&(c=L,f())};e.host.addEventListener("pointermove",F);function ae(){e.host.removeEventListener("pointerdown",V,{capture:!0}),e.host.removeEventListener("pointermove",F),C()}return{attach:B,detach:O,setMode:X,update:I,destroy:ae}}var Ql=typeof HTMLElement<"u"?HTMLElement:class{},ql=["mode","target","size","enabled"];function cs(e){if(e==="translate"||e==="rotate")return e}var wn=class extends Ql{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...ql]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Oe)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 i=null;try{i=o.querySelector(`#${t}`)??o.querySelector(t)}catch{i=o.querySelector(`[id="${t}"]`)}return i instanceof wt?i:null}_readOptions(){let t={},o=cs(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let i=se(this.getAttribute("size"));i!==void 0&&(t.size=i);let r=this.getAttribute("enabled");return r!==null&&(t.enabled=r!=="false"&&r!=="0"),t.onObjectChange=a=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:a.position,rotation:a.rotation}}))},t}_attach(){if(this._tc)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._tc=ls(o,this._readOptions());let i=this._findTargetMesh();if(i){let r=i.getMeshHandle();r&&this._tc.attach(r)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,i){if(o!==i&&this._tc){if(t==="mode"){let r=cs(i);r&&this._tc.setMode(r)}else if(t==="target"){let r=this._findTargetMesh();this._tc.attach(r?r.getMeshHandle()??null:null)}}}};function us(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function i(){t=n.filter?n.filter(t):t;for(let S of o)try{S(t)}catch(v){console.error("[polycss/createSelect] onChange threw:",v)}}function r(h){t=h,i()}function a(h){n.multiple?t.includes(h)||(t=[...t,h]):t=[h],i()}function c(h){t.includes(h)&&(t=t.filter(S=>S!==h),i())}function l(h){t.includes(h)?t=t.filter(S=>S!==h):n.multiple?t=[...t,h]:t=[h],i()}function m(){t.length!==0&&(t=[],i())}function g(h){return t.includes(h)}function x(h,S){return ts(e.meshes(),h,S,v=>!v.element.classList.contains("polycss-transform-gizmo"))}let f=h=>{let S=h.target;if(S?.closest(".polycss-transform-gizmo"))return;let v=e.findMeshByElement(S)??x(h.clientX,h.clientY);if(!v){n.onPointerMissed&&n.onPointerMissed(h),n.clearOnMiss!==!1&&m();return}n.multiple&&(h.shiftKey||h.metaKey||h.ctrlKey)?l(v):t.length===1&&t[0]===v?m():r([v])};e.host.addEventListener("click",f);function b(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:r,add:a,remove:c,toggle:l,clear:m,has:g,destroy:b}}var Kl=typeof HTMLElement<"u"?HTMLElement:class{},Jl=["multiple","clear-on-miss"],Mn=class extends Kl{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Jl]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Oe)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 i=()=>{t.removeEventListener("polycss:scene-ready",i),this._attach()};t.addEventListener("polycss:scene-ready",i)}return}this._selection=us(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,i){o!==i&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};var Pe=require("@layoutit/polycss-core"),ec=typeof HTMLElement<"u"?HTMLElement:class{};function tc(e){return e.closest("poly-scene")??null}function Ee(e,n,t){let o=e.getAttribute(n);if(!o)return t;let i=parseFloat(o);return Number.isFinite(i)?i:t}function ot(e,n,t){return e.getAttribute(n)??t}function Lt(e,n){let t=e.getAttribute(n);if(!t)return;let o=t.split(",").map(i=>parseFloat(i.trim()));if(!(o.length!==3||o.some(i=>!Number.isFinite(i))))return[o[0],o[1],o[2]]}function nc(e){if(e.length===0)return e;let n=(0,Pe.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,i=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&i===0)return e;let r=a=>[a[0]-t,a[1]-o,a[2]-i];return e.map(a=>({...a,vertices:a.vertices.map(r)}))}var $e=class extends ec{constructor(){super(...arguments);this._handle=null}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,i){if(o!==i&&this._handle){if(t==="position"||t==="scale"||t==="rotation"||t==="cast-shadow"||t==="receive-shadow"){this._handle.setTransform({position:Lt(this,"position"),scale:(()=>{let r=this.getAttribute("scale");if(!r)return;if(r.includes(","))return Lt(this,"scale");let a=parseFloat(r);return Number.isFinite(a)?a:void 0})(),rotation:Lt(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=tc(this);if(!t)return;let o=t.getScene?.();if(!o)return;let i=this.buildPolygons();this.hasAttribute("auto-center")&&(i=nc(i));let r={polygons:i,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(r,{position:Lt(this,"position"),scale:(()=>{let a=this.getAttribute("scale");if(!a)return;if(a.includes(","))return Lt(this,"scale");let c=parseFloat(a);return Number.isFinite(c)?c:void 0})(),rotation:Lt(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow"),excludeFromAutoCenter:this.hasAttribute("exclude-from-auto-center"),merge:!1})}},Ln=class extends $e{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,Pe.boxPolygons)({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:ot(this,"color")})}},_n=class extends $e{static get observedAttributes(){return["axis","size","offset","color","auto-center","position","scale","rotation","cast-shadow","receive-shadow"]}buildPolygons(){let n=Ee(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("offset"),i=o===null?0:parseFloat(o);return(0,Pe.planePolygons)({axis:t,size:Ee(this,"size",.4),offset:Number.isFinite(i)?i:0,color:ot(this,"color")})}},Rn=class extends $e{static get observedAttributes(){return["axis","radius","segments","half-thickness","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=Ee(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("half-thickness");return(0,Pe.ringPolygons)({axis:t,radius:Ee(this,"radius",50),segments:Ee(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:ot(this,"color")})}},kn=class extends $e{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Pe.octahedronPolygons)({center:Lt(this,"center")??[0,0,0],size:Ee(this,"size",50),color:ot(this,"color")})}},Dn=class extends $e{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Pe.tetrahedronPolygons)({size:Ee(this,"size",100),color:ot(this,"color")})}},On=class extends $e{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Pe.icosahedronPolygons)({size:Ee(this,"size",100),color:ot(this,"color")})}},In=class extends $e{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Pe.dodecahedronPolygons)({size:Ee(this,"size",100),color:ot(this,"color")})}},Hn=class extends $e{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Pe.spherePolygons)({radius:Ee(this,"radius",50),subdivisions:Ee(this,"subdivisions",1),color:ot(this,"color")})}},Fn=class extends $e{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,Pe.cylinderPolygons)({radius:Ee(this,"radius",50),radiusTop:n?parseFloat(n):void 0,height:Ee(this,"height",100),radialSegments:Ee(this,"radial-segments",12),color:ot(this,"color")})}},Bn=class extends $e{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Pe.conePolygons)({radius:Ee(this,"radius",50),height:Ee(this,"height",100),radialSegments:Ee(this,"radial-segments",12),color:ot(this,"color")})}},Vn=class extends $e{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,Pe.torusPolygons)({radius:Ee(this,"radius",50),tube:Ee(this,"tube",15),radialSegments:Ee(this,"radial-segments",12),tubularSegments:Ee(this,"tubular-segments",16),color:ot(this,"color")})}};typeof customElements<"u"&&(customElements.get("poly-scene")||customElements.define("poly-scene",Oe),customElements.get("poly-mesh")||customElements.define("poly-mesh",wt),customElements.get("poly-iframe")||customElements.define("poly-iframe",yn),customElements.get("poly-polygon")||customElements.define("poly-polygon",bn),customElements.get("poly-axes-helper")||customElements.define("poly-axes-helper",xn),customElements.get("poly-directional-light-helper")||customElements.define("poly-directional-light-helper",vn),customElements.get("poly-orbit-controls")||customElements.define("poly-orbit-controls",Sn),customElements.get("poly-map-controls")||customElements.define("poly-map-controls",Cn),customElements.get("poly-first-person-controls")||customElements.define("poly-first-person-controls",En),customElements.get("poly-perspective-camera")||customElements.define("poly-perspective-camera",Tn),customElements.get("poly-orthographic-camera")||customElements.define("poly-orthographic-camera",Mt),customElements.get("poly-camera")||customElements.define("poly-camera",An),customElements.get("poly-transform-controls")||customElements.define("poly-transform-controls",wn),customElements.get("poly-select")||customElements.define("poly-select",Mn),customElements.get("poly-box")||customElements.define("poly-box",Ln),customElements.get("poly-plane")||customElements.define("poly-plane",_n),customElements.get("poly-ring")||customElements.define("poly-ring",Rn),customElements.get("poly-octahedron")||customElements.define("poly-octahedron",kn),customElements.get("poly-tetrahedron")||customElements.define("poly-tetrahedron",Dn),customElements.get("poly-sphere")||customElements.define("poly-sphere",Hn),customElements.get("poly-icosahedron")||customElements.define("poly-icosahedron",On),customElements.get("poly-dodecahedron")||customElements.define("poly-dodecahedron",In),customElements.get("poly-cylinder")||customElements.define("poly-cylinder",Fn),customElements.get("poly-cone")||customElements.define("poly-cone",Bn),customElements.get("poly-torus")||customElements.define("poly-torus",Vn));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});