@layoutit/polycss 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{CAMERA_BACKFACE_CULL_EPS as Eo,DEFAULT_SEAM_BLEED as zs,VOXEL_CAMERA_CULL_NORMAL_LIMIT as wl,cameraCullNormalKey as Ml,cameraCullVisibleSignature as Ll,computeSceneBbox as _l,computeLightVisibility as Rl,findOverlappingPolygonDuplicates as Hs,inverseRotateVec3 as To,isAxisAlignedSurfaceNormal as kl,isVoxelCameraCullableNormalGroups as Ol,normalFacesCamera as Dl,optimizeMeshPolygons as Il,parseHexColor as Hl,polygonCssSurfaceNormal as Fs}from"@layoutit/polycss-core";import{packTextureAtlasPlansWithScaleCore as bi}from"@layoutit/polycss-core";function vi(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 xt(e,n,t){return bi(e,n,vi(t))}import{buildTextureEdgeRepairSets as Ur,buildSeamBleedPolygonEdges as ba,buildSeamBleedPolygonSet as va}from"@layoutit/polycss-core";import{TEXTURE_TRIANGLE_BLEED as xi,TEXTURE_EDGE_REPAIR_ALPHA_MIN as Pi,TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN as Si,TEXTURE_EDGE_REPAIR_RADIUS as mr}from"@layoutit/polycss-core";import{expandClipPoints as Ci}from"@layoutit/polycss-core";import{BASIS_EPS as Ei}from"@layoutit/polycss-core";var Pt=new Map;function Ti(e){let n=Pt.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.crossOrigin="anonymous",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),Pt.set(e,n),n.then(()=>{Pt.get(e)===n&&Pt.delete(e)},()=>{Pt.get(e)===n&&Pt.delete(e)})),n}function _e(e,n,t=1,o=0,r=0,s=1,i=0,c=0){e.setTransform(t*n,o*n,r*n,s*n,i*n,c*n)}function Nn(e){let n=e/255;return n<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function $n(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 Ai(e,n,t,o,r,s,i){let c=Math.round(n*i),l=Math.round(t*i),u=Math.max(1,Math.round(o*i)),d=Math.max(1,Math.round(r*i)),x=e.getImageData(c,l,u,d),h=x.data,b=s.r,v=s.g,P=s.b;for(let g=0;g<h.length;g+=4)h[g+3]!==0&&(h[g]=$n(Nn(h[g])*b),h[g+1]=$n(Nn(h[g+1])*v),h[g+2]=$n(Nn(h[g+2])*P));e.putImageData(x,c,l)}function wi(e,n,t,o,r,s,i){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,u=Math.max(r/c,s/l),d=c*u,x=l*u;_e(e,i),e.drawImage(n,t+(r-d)/2,o+(s-x)/2,d,x)}function St(e,n){return Math.max(0,Math.min(n,e))}function fr(e,n,t,o,r,s,i,c){let l=n.naturalWidth||n.width||1,u=n.naturalHeight||n.height||1,d=St(Math.min(t.minU,t.maxU)*l,l),x=St(Math.max(t.minU,t.maxU)*l,l),h=St(Math.min(t.minV,t.maxV)*u,u),b=St(Math.max(t.minV,t.maxV)*u,u),v=Math.floor(d),P=Math.floor(h),g=Math.ceil(x)-v,C=Math.ceil(b)-P;g<1&&(v=Math.floor(St((t.minU+t.maxU)/2*l,l-1)),g=1),C<1&&(P=Math.floor(St((t.minV+t.maxV)/2*u,u-1)),C=1),v=Math.max(0,Math.min(l-1,v)),P=Math.max(0,Math.min(u-1,P)),g=Math.max(1,Math.min(l-v,g)),C=Math.max(1,Math.min(u-P,C)),_e(e,c),e.drawImage(n,v,P,g,C,o,r,s,i)}function vr(e){return e==="repeat"||e==="mirrored-repeat"}function hr(e,n){return vr(e)?Math.floor(n):0}function gr(e,n){return vr(e)?Math.ceil(n)-1:0}function yr(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function br(e,n,t,o,r,s,i){let c=r?hr(s,r.minU):0,l=r?gr(s,r.maxU):0,u=r?hr(i,r.minV):0,d=r?gr(i,r.maxV):0;for(let x=c;x<=l;x++)for(let h=u;h<=d;h++){let b=yr(s,x),v=yr(i,h);if(!b&&!v){e.drawImage(n,x*t,h*o);continue}e.save(),e.translate((b?x+1:x)*t,(v?h+1:h)*o),e.scale(b?-1:1,v?-1:1),e.drawImage(n,0,0),e.restore()}}function Un(e,n,t,o){for(let r=0;r<o.length;r+=2){let s=n+o[r],i=t+o[r+1];r===0?e.moveTo(s,i):e.lineTo(s,i)}e.closePath()}function dn(e,n,t,o,r,s){for(let i=0;i<o.length;i+=2){let c=n+o[i]+r,l=t+o[i+1]+s;i===0?e.moveTo(c,l):e.lineTo(c,l)}e.closePath()}function Mi(e,n,t,o){_e(e,o),e.beginPath(),Un(e,n.x,n.y,n.screenPts),e.clip(),_e(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function pn(e,n,t,o,r){n.polygon.textureAlphaMode==="opaque"&&(_e(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+r,n.canvasW,n.canvasH))}function Li(e,n,t,o,r=0,s=0){if(n.textureTriangles?.length){let i=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1;for(let l of n.textureTriangles){let u=Ci(l.screenPts,xi*(n.bleedRatio??1));e.save(),_e(e,o),e.beginPath(),dn(e,n.x,n.y,u,r,s),e.clip(),pn(e,n,o,r,s),l.uvAffine?(_e(e,o,l.uvAffine.a/i,l.uvAffine.c/i,l.uvAffine.b/c,l.uvAffine.d/c,n.x+l.uvAffine.e+r,n.y+l.uvAffine.f+s),br(e,t,i,c,l.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t)):l.uvSampleRect&&fr(e,t,l.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let i=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1,l=n.polygon.textureAlphaMode==="opaque";l&&(e.save(),_e(e,o),e.beginPath(),dn(e,n.x,n.y,n.screenPts,r,s),e.clip(),pn(e,n,o,r,s)),_e(e,o,n.uvAffine.a/i,n.uvAffine.c/i,n.uvAffine.b/c,n.uvAffine.d/c,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+s),br(e,t,i,c,n.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t),l&&e.restore()}else if(n.uvSampleRect){let i=n.polygon.textureAlphaMode==="opaque";i&&(e.save(),_e(e,o),e.beginPath(),dn(e,n.x,n.y,n.screenPts,r,s),e.clip(),pn(e,n,o,r,s)),fr(e,t,n.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),i&&e.restore()}else{let i=n.polygon.textureAlphaMode==="opaque";i&&(e.save(),_e(e,o),e.beginPath(),dn(e,n.x,n.y,n.screenPts,r,s),e.clip(),pn(e,n,o,r,s)),wi(e,t,n.x+r,n.y+s,n.canvasW,n.canvasH,o),i&&e.restore()}}function _i(e,n,t,o,r,s){let i=r-t,c=s-o,l=i*i+c*c;if(l<=Ei)return Math.hypot(e-t,n-o);let u=Math.max(0,Math.min(1,((e-t)*i+(n-o)*c)/l));return Math.hypot(e-(t+i*u),n-(o+c*u))}function Ri(e,n,t,o){let r=1/0,s=t.length/2;for(let i of o){if(i<0||i>=s)continue;let c=i*2,l=(i+1)%s*2;r=Math.min(r,_i(e,n,t[c],t[c+1],t[l],t[l+1]))}return r}function ki(e,n,t,o,r,s){let i=Math.max(0,o-s),c=Math.min(n-1,o+s),l=Math.max(0,r-s),u=Math.min(t-1,r+s),d=null,x=1/0;for(let h=l;h<=u;h++)for(let b=i;b<=c;b++){if(b===o&&h===r)continue;let v=b-o,P=h-r,g=v*v+P*P;if(g>s*s||g>=x)continue;let C=(h*n+b)*4;e[C+3]<Si||(d=C,x=g)}return d}function Oi(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),s=Math.max(0,Math.floor(n.y*t)),i=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),c=Math.max(1,Math.min(o.height-s,Math.ceil(n.canvasH*t)));if(i<=0||c<=0)return;let l;try{l=e.getImageData(r,s,i,c)}catch{return}let u=l.data,d=new Uint8ClampedArray(u),x=Math.max(mr,mr/t),h=Math.max(2,Math.ceil(x*t)+1),b=!1;for(let v=0;v<c;v++)for(let P=0;P<i;P++){let g=(v*i+P)*4,C=u[g+3];if(C<Pi||C===255)continue;let D=(r+P+.5)/t-n.x,k=(s+v+.5)/t-n.y;if(Ri(D,k,n.screenPts,n.textureEdgeRepairEdges)>x)continue;let z=ki(d,i,c,P,v,h);z!==null&&(u[g]=d[z],u[g+1]=d[z+1],u[g+2]=d[z+2],u[g+3]=255,b=!0)}b&&e.putImageData(l,r,s)}function Di(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 Ii(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=e.entries.some(d=>d.textureEdgeRepair&&d.texture&&d.textureEdgeRepairEdges&&d.textureEdgeRepairEdges.size>0),i=r.getContext("2d",s?{willReadFrequently:!0}:void 0);if(!i)return{width:e.width,height:e.height,url:null};let c=Array.from(new Set(e.entries.flatMap(d=>d.texture?[d.texture]:[]))),l=new Map;await Promise.all(c.map(async d=>{l.set(d,await Ti(d))}));for(let d of e.entries){let x=d.texture?l.get(d.texture):null;if(!d.texture){i.save(),Mi(i,d,n,o),i.restore();continue}x&&(i.save(),_e(i,o),i.beginPath(),Un(i,d.x,d.y,d.screenPts),i.clip(),Li(i,d,x,o),i.restore()),d.texture&&n==="baked"&&(i.save(),_e(i,o),i.beginPath(),Un(i,d.x,d.y,d.screenPts),i.clip(),Ai(i,d.x,d.y,d.canvasW,d.canvasH,d.textureTint,o),i.restore()),Oi(i,d,o)}let u=await Di(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:u}}async function Ct(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await Ii(i,n,t,o))}return s}import{isFullRectSolid as Ve,isSolidTrianglePlan as Je,isProjectiveQuadPlan as Be,fullRectBounds as Cd,safariCssProjectiveUnsupported as xr,incrementCount as Ed,dominantCountKey as Td,filterAtlasPlans as Fi,getSolidPaintDefaultsForPlansCore as Vi}from"@layoutit/polycss-core";import{parseHex as Bi,rgbKey as zi}from"@layoutit/polycss-core";import{computeTextureAtlasPlan as Ld,buildBasisHints as _d}from"@layoutit/polycss-core";import{resolveProjectiveQuadGuards as Hi}from"@layoutit/polycss-core";function Et(e,n){let o=e?.defaultView?.__polycssProjectiveQuadGuards,r=n&&o?{...n,...o}:o??n;return Hi(r)}function Tt(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function Gn(e){if(Pr(e))return!0;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!xr(t):!0}function Gt(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 Pr(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 Ni(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function ze(e,n){return n?.disable?.includes("u")?null:Pr(e)?"corner-bevel":Gn(e)?Ni(e)?"border-large":"border":null}function At(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!xr(t):!0}function jt(e,n,t,o,r){let s=new Set(o?.disable??[]);return Vi(e,n,s,{solidTriangleSupported:Gn(t),projectiveQuadSupported:At(t),cornerShapeSupported:Gt(t),borderShapeSupported:Tt(t)},Bi,zi,r)}function jn(e,n,t=new Set,o){let r=o??(typeof document<"u"?document:null);if(!r)return{};let s=t.size>0?{disable:Array.from(t)}:void 0;return jt(e,n,r,s)}function mn(e){let n=e??(typeof document<"u"?document:null);if(!n){if(!!!(typeof CSS<"u"?CSS:void 0)?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=typeof matchMedia<"u"?matchMedia:void 0;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}return Tt(n)}function fn(e){let n=e??(typeof document<"u"?document:null);if(!n){let t=typeof CSS<"u"?CSS:void 0;if(t?.supports?.("corner-top-left-shape","bevel")&&t.supports("corner-top-right-shape","bevel"))return!0;let o=(typeof navigator<"u"?navigator:globalThis.navigator)?.userAgent??"";if(!o)return!0;let r=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(o);return!/\bVersion\/[\d.]+.*\bSafari\//.test(o)||r}return Gn(n)}function Wn(e,n,t,o){let r=o??(typeof document<"u"?document:null);return Fi(e,n,t,{solidTriangleSupported:fn(o),projectiveQuadSupported:r?At(r):!0,borderShapeSupported:mn(o)})}import{ASYNC_RENDER_BUDGET_MS as pa,DEFAULT_SEAM_BLEED as Fr,DEFAULT_TILE as ma,PROJECTIVE_QUAD_DENOM_EPS as fa,PROJECTIVE_QUAD_MAX_WEIGHT_RATIO as ha,PROJECTIVE_QUAD_BLEED as Hr,resolveBleedRatio as mo}from"@layoutit/polycss-core";import{buildBasisHints as fo,buildSeamBleedPolygonEdges as ga,computeTextureAtlasPlan as Qt}from"@layoutit/polycss-core";import{cornerShapeGeometryForPlan as qt}from"@layoutit/polycss-core";import{formatCssLength as hn,formatMatrix3dValues as Ui,formatSolidQuadMatrix as Gi}from"@layoutit/polycss-core";import{shadePolygon as ji}from"@layoutit/polycss-core";import{parseHex as Sr,rgbKey as Cr}from"@layoutit/polycss-core";function xe(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,s=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`(^|;)\\s*${s}\\s*:[^;]*`,"i"),c=i.test(o)?o.replace(i,(l,u)=>`${u}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;c!==o&&e.setAttribute("style",c)}function ot(e,n){let t=e.getAttribute("style")??"";if(!t||!t.toLowerCase().includes(n.toLowerCase()))return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`^\\s*${o}\\s*:`,"i"),s=t.split(";").map(i=>i.trim()).filter(i=>i&&!r.test(i)).join(";");s?e.setAttribute("style",s):e.removeAttribute("style")}function Wt(e,n,t,o=!1){if(n==="dynamic"){let r=Sr(e.polygon.color??"#cccccc"),s=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return Cr(r)!==t?.dynamicColorKey&&(s+=`;--psr:${(r.r/255).toFixed(4)};--psg:${(r.g/255).toFixed(4)};--psb:${(r.b/255).toFixed(4)}`),s}return e.shadedColor?`;color:${e.shadedColor}`:""}function $i(e,n){xe(e,"--pnx",n.normal[0].toFixed(4)),xe(e,"--pny",n.normal[1].toFixed(4)),xe(e,"--pnz",n.normal[2].toFixed(4))}function wt(e,n,t,o){if(t==="dynamic"){ot(e,"color"),ot(e,"background"),$i(e,n);let r=Sr(n.polygon.color??"#cccccc");Cr(r)===o?.dynamicColorKey?(ot(e,"--psr"),ot(e,"--psg"),ot(e,"--psb")):(xe(e,"--psr",(r.r/255).toFixed(4)),xe(e,"--psg",(r.g/255).toFixed(4)),xe(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(ot(e,"background"),xe(e,"color",n.shadedColor)):(ot(e,"background"),ot(e,"color"))}import{formatBorderShapeElementStyle as Er,formatCornerShapeElementStyle as Tr}from"@layoutit/polycss-core";import{atlasCanonicalSizeForEntry as rt}from"@layoutit/polycss-core";import{computeProjectiveQuadMatrix as Wi,stableBasisFromPlan as Yi}from"@layoutit/polycss-core";import{DEFAULT_LIGHT_DIR as Xi,DEFAULT_LIGHT_COLOR as Zi,DEFAULT_LIGHT_INTENSITY as qi,DEFAULT_AMBIENT_COLOR as Qi,DEFAULT_AMBIENT_INTENSITY as Ki}from"@layoutit/polycss-core";var Ar="polycss-corner-shape-solid",Yn=new WeakMap,Xn=new WeakMap;function ye(e,n,t){let o=Yn.get(e),r=Xn.get(e),s=typeof t=="number";if(!n.data&&!s&&(!o||o.length===0)){e.__polycssHasDataAttrs=!1;return}let i=new Map;if(n.data)for(let[l,u]of Object.entries(n.data))i.set(l,String(u));if(s&&i.set("poly-index",String(t)),o)for(let l of o)i.has(l)||e.removeAttribute(`data-${l}`);for(let[l,u]of i)r?.get(l)!==u&&e.setAttribute(`data-${l}`,u);let c=Array.from(i.keys());c.length>0?Yn.set(e,c):Yn.delete(e),i.size>0?Xn.set(e,i):Xn.delete(e),e.__polycssHasDataAttrs=c.length>0}function Mt(e){return e.__polycssHasDataAttrs===!0}function Zn(e,n,t,o,r=t==="dynamic"){if(!n.url)return;let s=`url(${n.url})`,i=o.canvasW||1,c=o.canvasH||1,l=rt(o),u=`${hn(-o.x/i*l)} ${hn(-o.y/c*l)}`,d=`${hn(n.width/i*l)} ${hn(n.height/c*l)}`,x=`transform:matrix3d(${o.atlasMatrix});--polycss-atlas-size:${l}px`,h=`${x};--polycss-atlas-position:${u};--polycss-atlas-image-size:${d}`;if(t==="dynamic"){let b=r?`;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`:"";e.setAttribute("style",h+`;--polycss-atlas-url:${s}`+b)}else e.setAttribute("style",x+`;background-image:${s};background-position:${u};background-size:${d};background-repeat:no-repeat;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`)}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 r=Mr(n,t);return r?(e.style.visibility="",xe(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(xe(e,"--pnx",r.normal[0].toFixed(4)),xe(e,"--pny",r.normal[1].toFixed(4)),xe(e,"--pnz",r.normal[2].toFixed(4))),ye(e,t,n.index),!0):(e.style.visibility="hidden",ye(e,t,n.index),!0)}function qn(e,n,t,o,r){if(o!=="baked")return{...e,polygon:n,normal:t};let s=r.directionalLight,i=r.ambientLight,c=s?.direction??Xi,l=s?.color??Zi,u=Math.max(0,s?.intensity??qi),d=i?.color??Qi,x=Math.max(0,i?.intensity??Ki),h=Math.hypot(c[0],c[1],c[2])||1,b=c[0]/h,v=c[1]/h,P=c[2]/h,C=r.lightOccludedPolyIndices?.has(e.index)??!1?0:u*Math.max(0,t[0]*b+t[1]*v+t[2]*P);return{...e,polygon:n,normal:t,shadedColor:ji(n.color??"#cccccc",C,l,d,x)}}function Mr(e,n){let t=Lr(e,n);if(!t)return null;let{normal:o,xAxis:r,yAxis:s,tx:i,ty:c,tz:l}=t;return{normal:o,matrix:Ui([r[0]*e.canvasW/rt(e),r[1]*e.canvasW/rt(e),r[2]*e.canvasW/rt(e),0,s[0]*e.canvasH/rt(e),s[1]*e.canvasH/rt(e),s[2]*e.canvasH/rt(e),0,o[0],o[1],o[2],0,i,c,l,1])}}var Lr=Yi;function Ji(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=Lr(e,n);if(!o)return null;let r=Wi(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return r?{matrix:r,normal:o.normal}:null}function Qn(e,n,t,o,r=!1){let s=t.createElement("b");return s.setAttribute("style",`transform:matrix3d(${Gi(e)})`+Wt(e,n,o,r)),ye(s,e.polygon,e.index),s}function Kn(e,n,t,o,r=!1){let s=t.createElement("i");return s.setAttribute("style",Er(e)+Wt(e,n,o,r)),ye(s,e.polygon,e.index),s}function Jn(e,n,t,o,r,s=!1){let i=o.createElement("u");return i.className=Ar,i.setAttribute("style",Tr(e,n)+Wt(e,t,r,s)),ye(i,e.polygon,e.index),i}function eo(e,n,t,o,r=!1){let s=t.createElement("b");return s.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+Wt(e,n,o,r)),ye(s,e.polygon,e.index),s}function _r(e,n,t,o,r,s,i){let c=n.projectiveMatrix?Ji(n,t,s):Mr(n,t);if(!c)return!1;let l=qn(n,t,c.normal,o,r);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,wt(e,l,o,i),ye(e,l.polygon,l.index),!0}function Rr(e,n,t,o){e.style.visibility="",e.setAttribute("style",Er(n)),wt(e,n,t,o),ye(e,n.polygon,n.index)}function kr(e,n,t,o,r){e.style.visibility="",e.className=Ar,e.setAttribute("style",Tr(n,t)),wt(e,n,o,r),xe(e,"background","currentColor"),ye(e,n.polygon,n.index)}function to(e,n,t,o=!1){let r=t.createElement("s"),s=rt(e),i=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:${s}px;opacity:0`+i),ye(r,e.polygon,e.index),r}import{computeSolidTriangleColorPlan as ya}from"@layoutit/polycss-core";import{computeSolidTrianglePlanFromCssPoints as ea,computeSolidTrianglePlan as ta}from"@layoutit/polycss-core";function st(e,n,t,o={}){let r=o.primitive!=null?void 0:(()=>{let s=t.doc??(typeof document<"u"?document:null);return s?ze(s,t.strategies)??"border":"border"})();return ta(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??r})}function no(e,n,t,o,r,s,i,c,l,u,d,x,h){let b=o.primitive!=null?void 0:(()=>{let v=t.doc??(typeof document<"u"?document:null);return v?ze(v,t.strategies)??"border":"border"})();return ea(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??b},r,s,i,c,l,u,d,x,h)}import{buildSeamBleedPolygonEdges as na,DEFAULT_SEAM_BLEED as oa,DEFAULT_TILE as Yd,resolveBleedRatio as ra}from"@layoutit/polycss-core";import{rgbEqual as sa,stepRgbToward as ia,rgbToCss as aa,colorErrorScore as la}from"@layoutit/polycss-core";import{computeSolidTriangleColorPlan as Or}from"@layoutit/polycss-core";import{stableTriangleMatrixDecimals as oo}from"@layoutit/polycss-core";var ca="0 48px 96px 48px";function ro(e,n){return na(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function so(e,n,t){let o=ra(t.seamBleed),r=oa*o,s={...t,bleedRatio:o};return n&&r>0?{...s,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:s}function gn(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 Dr(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function it(e,n,t,o,r,s){return t?s.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:r==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:Dr(n,s):!0}function io(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"?ca:""),t.__polycssSolidTrianglePrimitive=n)}function ao(e){let n=e;n.__polycssSolidTriangleHidden&&(e.style.visibility="",n.__polycssSolidTriangleHidden=!1)}function Lt(e){let n=e;n.__polycssSolidTriangleHidden||(e.style.visibility="hidden",n.__polycssSolidTriangleHidden=!0)}function Yt(e,n){e.setAttribute("style",n.styleText),io(e,n.primitive);let t=e;t.__polycssSolidTriangleBasis=n.basis,t.__polycssSolidTriangleHidden=!1,n.colorComputed&&(t.__polycssSolidTriangleColor=n.bakedColor??"",t.__polycssSolidTriangleColorRgb=n.bakedRgb,t.__polycssSolidTriangleColorAlpha=n.bakedAlpha),t.__polycssSolidTriangleColorFrame=void 0,(n.polygon.data||Mt(e))&&ye(e,n.polygon)}function Ir(e,n,t,o){if(!n.colorComputed){(n.polygon.data||Mt(e))&&ye(e,n.polygon);return}let r=e,s=n.bakedColor??"",i=n.bakedRgb,c=n.bakedAlpha??1,l=r.__polycssSolidTriangleColor,u=r.__polycssSolidTriangleColorRgb,d=r.__polycssSolidTriangleColorAlpha??1,x=o??Dr(n.index,t);if(!t.updatesDisabled&&l!==s&&(l===void 0||x)){let h=s,b=i;if(t.maxStep>0&&u&&i&&d===c){let v=ia(u,i,t.maxStep);b=v,h=aa(v,c)}(h!==l||!sa(b,u))&&(e.style.color=h),r.__polycssSolidTriangleColor=h,r.__polycssSolidTriangleColorRgb=b,r.__polycssSolidTriangleColorAlpha=c,r.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||Mt(e))&&ye(e,n.polygon)}function Xt(e,n,t,o){let r=e;io(e,n.primitive),r.__polycssSolidTriangleBasis!==n.basis&&(r.__polycssSolidTriangleBasis=n.basis),ao(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||Mt(e))&&Ir(e,n,t,o)}function yn(e,n,t,o){ao(e),Ir(e,n,t,o)}function Zt(e,n){let t=e;io(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),ao(e),e.style.transform=n.transformText,(n.polygon.data||Mt(e))&&ye(e,n.polygon)}function ua(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 lo(e,n,t){if(t.stableTriangleColorPolicy!=="adaptive")return null;if(t.stableTriangleColorFreezeFrames===0)return new Set;let o=Math.max(0,Math.floor(t.stableTriangleColorFrame??0)),r=Math.max(1,Math.floor(t.stableTriangleColorFreezeFrames??1));if(r<=1&&!Number.isFinite(t.stableTriangleColorBudget))return null;let s=ua(e.length,t),i=Math.max(1,Math.floor(t.stableTriangleColorMaxAge??Math.max(2,r*2))),c=[];for(let l=0;l<e.length;l++){let u=e[l],d=n[l];if(u.kind!=="triangle"||!d)continue;let x=u.element,h=x.__polycssSolidTriangleColor,b=d.bakedColor??"";if(h===b)continue;let v=x.__polycssSolidTriangleColorFrame??0,P=Math.max(0,o-v),g=la(h,b);c.push({index:l,score:(P>=i?1e6:0)+g*1e4+P})}return c.length===0?new Set:(c.sort((l,u)=>u.score-l.score),new Set(c.slice(0,s).map(l=>l.index)))}function bn(e,n){let t=n.createElement("u");return Yt(t,e),ye(t,e.polygon,e.index),t}function da(e,n,t){let o=t.createElement("u");return Lt(o),ye(o,e,n),o}function co(e,n,t,o,r,s){let i=t,c=i.stableTriangleDebug,l=o&&r==="color-only";if(i.stableTriangleColorPolicy==="adaptive"||e.length!==n.length)return!1;let u=oo(i.stableTriangleMatrixDecimals),d=t.doc??(typeof document<"u"?document:null),x=d?ze(d,t.strategies)??"border":"border";for(let b=0;b<e.length;b++){let v=e[b];if(v.kind!=="triangle"||v.polygonIndex!==b||!n[b])return!1}let h=ro(n,t);for(let b=0;b<e.length;b++){let v=e[b].element,P=n[b];if(l){if(it(v,b,o,c,i.stableTriangleColorPolicy,s)){let C=Or(P,b,t);if(!C)continue;yn(v,C,s)}continue}let g=st(P,b,so(b,h,t),{basis:v.__polycssSolidTriangleBasis,matrixDecimals:u,primitive:x,includeColor:r!=="plan-only"&&r!=="transform-only"&&it(v,b,o,c,i.stableTriangleColorPolicy,s)});if(!g){Lt(v);continue}o&&r==="plan-only"||(o&&r==="transform-only"?Zt(v,g):o?Xt(v,g,s):Yt(v,g))}return!0}function _t(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=ze(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let r=oo(n.stableTriangleMatrixDecimals),s=[],i=ro(e,n);for(let c=0;c<e.length;c+=1){let l=e[c],u=st(l,c,so(c,i,n),{matrixDecimals:r,primitive:o}),d=u?bn(u,t):da(l,c,t);s.push({polygonIndex:c,element:d,kind:"triangle",dispose:()=>{}})}return{rendered:s,dispose(){}}}function uo(e,n,t={}){let o=t.doc??(typeof document<"u"?document:null);if(!o)return{rendered:e,dispose:()=>{}};let r=ze(o,t.strategies);if(!r||e.some(g=>g.kind!=="triangle")||n.length!==e.length)return null;for(let g=0;g<e.length;g++)if(e[g].polygonIndex!==g)return null;let s=t.optimizeStableTriangleStyle===!0&&(t.textureLighting??"baked")==="baked",i=t,c=i.stableTriangleDebug,l=i.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full"),u=s&&l==="color-only",d=gn(i),x=oo(i.stableTriangleMatrixDecimals);if(co(e,n,t,s,l,d))return{rendered:e,dispose(){}};let h=new Array(e.length),b=new Array(e.length),v=ro(n,t);for(let g=0;g<e.length;g++){let C=e[g].element;if(u){let D=i.stableTriangleColorPolicy==="adaptive"||it(C,g,s,c,i.stableTriangleColorPolicy,d);b[g]=D?Or(n[g],g,t):null;continue}h[g]=st(n[g],g,so(g,v,t),{basis:C.__polycssSolidTriangleBasis,matrixDecimals:x,primitive:r,includeColor:l!=="plan-only"&&l!=="transform-only"&&it(C,g,s,c,i.stableTriangleColorPolicy,d)})}let P=s&&l!=="plan-only"&&l!=="transform-only"?lo(e,u?b:h,i):null;for(let g=0;g<e.length;g++){if(u){let D=b[g];D&&yn(e[g].element,D,d,P?.has(g));continue}let C=h[g];if(!C){Lt(e[g].element);continue}s&&l==="plan-only"||(s&&l==="transform-only"?Zt(e[g].element,C):s?Xt(e[g].element,C,d,P?.has(g)):Yt(e[g].element,C))}return{rendered:e,dispose(){}}}import{stableTriangleMatrixDecimals as Vr}from"@layoutit/polycss-core";function Br(){return new Promise(e=>setTimeout(e,0))}async function po(e){return performance.now()-e<pa?e:(await Br(),performance.now())}function zr(e,n){let t=mo(n.seamBleed),o=Fr*t,r={...n,bleedRatio:t};return e.seamBleedEdges?.size&&o>0?{...r,seamBleed:o,seamEdges:e.seamBleedEdges}:{...r,seamBleed:void 0,seamEdges:void 0}}function Nr(e,n){return ga(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function $r(e,n,t){let o=mo(t.seamBleed),r=Fr*o,s={...t,bleedRatio:o};return n&&r>0?{...s,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:s}function dt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=fo(e,n),r=Et(t),s=e.map((i,c)=>Qt(i,c,n,r,o[c]));return jt(s,n.textureLighting??"baked",t,n.strategies)}function pt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=n,s=o==="dynamic"&&r.skipDynamicNormalVars===!0,i=new Set(n.strategies?.disable??[]),c=!i.has("b"),l=c&&At(t),u=ze(t,n.strategies),d=u!==null,x=!i.has("i")&&Gt(t),h=!i.has("i")&&Tt(t),b=fo(e,n),v=Et(t),P=Nr(e,n),g=e.map((m,p)=>Qt(m,p,$r(p,P,n),v,b[p]));if(typeof window<"u"){let m=window,p=g[1];m.__vanillaPlan1={matrix:p?.matrix,canvasW:p?.canvasW,canvasH:p?.canvasH,vertexCount:e[1]?.vertices.length}}let C=n.solidPaintDefaults??(r.computeSolidPaintDefaults?jt(g,o,t,n.strategies):void 0),D=C?{...n,solidPaintDefaults:C}:n,k=g.map(m=>m&&d&&Je(m)?st(m.polygon,m.index,zr(m,D),{primitive:u??void 0}):null),z=g.map(m=>m&&x&&!Je(m)&&!(c&&Ve(m))&&!(l&&Be(m))?qt(m):null),I=g.map((m,p)=>m&&(m.texture||!(c&&Ve(m))&&!k[p]&&!(l&&Be(m))&&!z[p]&&!h?m:null)),{packed:Z,atlasScale:Q}=xt(I,n.textureQuality,t),O=new Map,H=[],V=!1,$=[];for(let m=0;m<e.length;m++){let p=g[m],T=k[m],M=z[m];if(!p)continue;let R=Z.entries[m];if(R){let L=to(R,o,t,s);O.set(m,L),H.push({polygonIndex:m,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!p.texture&&c&&Ve(p)){let L=Qn(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&T){let L=bn(T,t);H.push({polygonIndex:m,element:L,kind:"triangle",plan:p,dispose:()=>{}})}else if(!p.texture&&l&&Be(p)){let L=eo(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&M){let L=Jn(p,M,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"corner",plan:p,dispose:()=>{}})}else if(!p.texture&&h){let L=Kn(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"border",plan:p,dispose:()=>{}})}}H.sort((m,p)=>m.polygonIndex-p.polygonIndex);let A=Ct(Z.pages,o,t,Q,()=>V).then(m=>{if(V){for(let p of m)p.url?.startsWith("blob:")&&URL.revokeObjectURL(p.url);return}$=m.flatMap(p=>p.url?.startsWith("blob:")?[p.url]:[]);for(let p=0;p<Z.pages.length;p++){let T=Z.pages[p],M=m[p];if(M)for(let R of T.entries){let L=O.get(R.index);!L||!M.url||Zn(L,M,o,R,!0)}}}).catch(()=>{if(!V)for(let m of O.values())xe(m,"opacity","0.5"),xe(m,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:H,solidPaintDefaults:C??{},pagesReady:A,dispose(){V=!0;for(let m of $)URL.revokeObjectURL(m);$=[]}}}async function Kt(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let r=n.textureLighting??"baked",i=r==="dynamic"&&n.skipDynamicNormalVars===!0,c=new Set(n.strategies?.disable??[]),l=!c.has("b"),u=l&&At(o),d=ze(o,n.strategies),x=d!==null,h=!c.has("i")&&Gt(o),b=!c.has("i")&&Tt(o);if(await Br(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let v=fo(e,n),P=Et(o),g=Nr(e,n),C=performance.now(),D=new Array(e.length);for(let m=0;m<e.length;m++)if(D[m]=Qt(e[m],m,$r(m,g,n),P,v[m]),C=await po(C),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let k=n.solidPaintDefaults??jt(D,r,o,n.strategies),z=new Array(D.length),I=new Array(D.length),Z=new Array(D.length);for(let m=0;m<D.length;m++){let p=D[m],T=p&&x&&Je(p)?st(p.polygon,p.index,zr(p,{...n,solidPaintDefaults:k}),{primitive:d??void 0}):null;z[m]=T;let M=p&&h&&!Je(p)&&!(l&&Ve(p))&&!(u&&Be(p))?qt(p):null;if(I[m]=M,Z[m]=p&&(p.texture||!(l&&Ve(p))&&!T&&!(u&&Be(p))&&!M&&!b?p:null),C=await po(C),t())return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}let{packed:Q,atlasScale:O}=xt(Z,n.textureQuality,o),H=new Map,V=[],$=!1,A=[];for(let m=0;m<e.length;m++){let p=D[m],T=z[m],M=I[m];if(!p)continue;let R=Q.entries[m];if(R){let L=to(R,r,o,i);H.set(m,L),V.push({polygonIndex:m,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!p.texture&&l&&Ve(p)){let L=Qn(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&T){let L=bn(T,o);V.push({polygonIndex:m,element:L,kind:"triangle",plan:p,dispose:()=>{}})}else if(!p.texture&&u&&Be(p)){let L=eo(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&M){let L=Jn(p,M,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"corner",plan:p,dispose:()=>{}})}else if(!p.texture&&b){let L=Kn(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"border",plan:p,dispose:()=>{}})}if(C=await po(C),t()){for(let L of V)L.dispose();return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}}V.sort((m,p)=>m.polygonIndex-p.polygonIndex);let y=Ct(Q.pages,r,o,O,()=>$||t()).then(m=>{if($||t()){for(let p of m)p.url?.startsWith("blob:")&&URL.revokeObjectURL(p.url);return}A=m.flatMap(p=>p.url?.startsWith("blob:")?[p.url]:[]);for(let p=0;p<Q.pages.length;p++){let T=Q.pages[p],M=m[p];if(M)for(let R of T.entries){let L=H.get(R.index);!L||!M.url||Zn(L,M,r,R,!0)}}}).catch(()=>{if(!($||t()))for(let m of H.values())xe(m,"opacity","0.5"),xe(m,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:V,solidPaintDefaults:k,pagesReady:y,dispose(){$=!0;for(let m of A)URL.revokeObjectURL(m);A=[]}}}function Jt(e,n,t,o={}){let r=o.textureLighting??"baked",s=o,i=s.optimizeStableTriangleStyle===!0&&r==="baked";if(!i||s.stableTriangleColorPolicy==="adaptive"||e.length!==t.polygonCount||n.length!==t.polygonCount||t.vertices.length<t.polygonCount*9)return!1;let c=s.stableTriangleDebug,l=s.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full");if(l==="color-only")return!1;let u=Vr(s.stableTriangleMatrixDecimals),d=gn(s),x=o.tileSize??ma,h=o.layerElevation??x,b=o.doc??(typeof document<"u"?document:null),v=b?ze(b,o.strategies)??"border":"border";for(let g=0;g<e.length;g++){let C=e[g],D=n[g];if(C.kind!=="triangle"||C.polygonIndex!==g||!D||D.vertices.length!==3||D.texture||D.material?.texture)return!1}let P=t.vertices;for(let g=0;g<e.length;g++){let C=e[g].element,D=n[g],k=g*9,z=P[k+1]*x,I=P[k]*x,Z=P[k+2]*h,Q=P[k+4]*x,O=P[k+3]*x,H=P[k+5]*h,V=P[k+7]*x,$=P[k+6]*x,A=P[k+8]*h,y=no(D,g,o,{basis:C.__polycssSolidTriangleBasis,matrixDecimals:u,primitive:v,color:t.colors?.[g],includeColor:l!=="plan-only"&&l!=="transform-only"&&it(C,g,i,c,s.stableTriangleColorPolicy,d)},z,I,Z,Q,O,H,V,$,A);if(!y){Lt(C);continue}l!=="plan-only"&&(l==="transform-only"?Zt(C,y):Xt(C,y,d))}return!0}function en(e,n,t={}){if(e.length!==n.length)return!1;let o=t,r=t.doc??(typeof document<"u"?document:null),s=t.textureLighting??"baked",i=new Set(t.strategies?.disable??[]),c=!i.has("b"),l=!!r&&c&&At(r),u=!!r&&!i.has("i")&&Gt(r),d=!!r&&!i.has("i")&&Tt(r),x=mo(o.seamBleed),h=r?Et(r,{bleed:Hr*x}):{denomEps:fa,maxWeightRatio:ha,bleed:Hr*x,disableGuards:!1},b=o.optimizeStableTriangleStyle===!0&&s==="baked",v=o.stableTriangleDebug,P=o.stableTriangleUpdateMode??(v==="plan-only"||v==="transform-only"?v:"full"),g=b&&P==="color-only",C=gn(o),D=Vr(o.stableTriangleMatrixDecimals),k=r?ze(r,t.strategies)??"border":"border";if(co(e,n,t,b,P,C))return!0;let z=[],I=[],Z=[];for(let O=0;O<e.length;O++){let H=e[O];if(H.polygonIndex!==O)return!1;let V=n[O];if(!V||g&&H.kind!=="triangle")return!1;if(H.kind==="atlas"){if(!H.plan||!wr(H.element,H.plan,V,s))return!1;continue}if(H.kind==="triangle"){let $=H.element;if(g){let y=o.stableTriangleColorPolicy==="adaptive"||it($,O,b,v,o.stableTriangleColorPolicy,C);I[O]=y?ya(V,O,t):null;continue}let A=st(V,O,t,{basis:$.__polycssSolidTriangleBasis,matrixDecimals:D,primitive:k,includeColor:P!=="plan-only"&&P!=="transform-only"&&it($,O,b,v,o.stableTriangleColorPolicy,C)});if(!A){z[O]=null;continue}z[O]=A;continue}if(H.kind==="solid"){if(!H.plan||V.texture||V.vertices.length!==H.plan.polygon.vertices.length)return!1;Z[O]=H.plan;continue}if(H.kind==="border"){let $=Qt(V,O,t,h);if(!$||$.texture||!d||c&&Ve($)||l&&Be($)||u&&qt($))return!1;Z[O]=$;continue}if(H.kind==="corner"){let $=Qt(V,O,t,h);if(!$||$.texture||!u||Je($)||c&&Ve($)||l&&Be($)||!qt($))return!1;Z[O]=$;continue}return!1}let Q=b&&P!=="plan-only"&&P!=="transform-only"?lo(e,g?I:z,o):null;for(let O=0;O<e.length;O++){let H=e[O];if(H.kind==="triangle"){if(g){let $=I[O];$&&yn(H.element,$,C,Q?.has(O));continue}let V=z[O];if(!V){Lt(H.element);continue}if(b&&P==="plan-only")continue;b&&P==="transform-only"?Zt(H.element,V):b?Xt(H.element,V,C,Q?.has(O)):Yt(H.element,V)}else if(H.kind==="solid"){let V=Z[O];if(!V||!_r(H.element,V,n[O],s,t,h,o.solidPaintDefaults))return!1}else if(H.kind==="border"){let V=Z[O];if(!V)return!1;Rr(H.element,V,s,o.solidPaintDefaults)}else if(H.kind==="corner"){let V=Z[O],$=V?qt(V):null;if(!V||!$)return!1;kr(H.element,V,$,s,o.solidPaintDefaults)}}return!0}import{computeTextureAtlasPlanPublic as Gr}from"@layoutit/polycss-core";import{formatMatrix3d as jr,formatCssLengthPx as Wr,formatSolidQuadEntryMatrix as Yr}from"@layoutit/polycss-core";import{formatBorderShapeEntryMatrix as Xr,cssBorderShapeForPlan as Zr}from"@layoutit/polycss-core";import{BASE_TILE as Pe,computeProjectiveQuadMatrix as xa,normalFacesCamera as Pa,parsePureColor as ts,PROJECTIVE_QUAD_BLEED as Sa,resolveProjectiveQuadGuards as Ca,rotateVec3 as Ea,rotateVec3InWrapperCssFrame as Ta,shadePolygon as Aa,SOLID_QUAD_CANONICAL_SIZE as wa}from"@layoutit/polycss-core";var Ma=[.4,-.7,.59],La="#ffffff",_a=1,Ra="#ffffff",ka=.4,ns=1,Oa=8,Da=Sa,et=1e-6,Ia=Ca({bleed:0}),os={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},yo=["t","b","bl","br","fr","fl"],Ha=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 qr(e){let n=[];for(let t of yo)Pa(os[t],e)&&n.push(t);return n.join("|")}function Fa(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 Va(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let c=1;c+1<n.length;c+=1){let l=n[c],u=n[c+1],d=l[1]-t[1],x=l[0]-t[0],h=l[2]-t[2],b=u[1]-t[1],v=u[0]-t[0],P=u[2]-t[2];o-=x*P-h*v,r-=h*b-d*P,s-=d*v-x*b}let i=Math.hypot(o,r,s);return i<=1e-9?null:[Math.round(o/i),Math.round(r/i),Math.round(s/i)]}function Ba(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=Va(e),t=n?Ha.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,s=1/0,i=-1/0,c=-1/0,l=-1/0;for(let x of e.vertices)o=Math.min(o,x[0]),r=Math.min(r,x[1]),s=Math.min(s,x[2]),i=Math.max(i,x[0]),c=Math.max(c,x[1]),l=Math.max(l,x[2]);let u=1e-6,d=Wa(e.color);return Math.abs(l-s)<=u?{axis:"z",face:t,left:r*Pe,top:o*Pe,width:Math.max(0,(c-r)*Pe),height:Math.max(0,(i-o)*Pe),z:s*Pe,baseColor:d,bleed:ho()}:Math.abs(i-o)<=u?{axis:"x",face:t,left:r*Pe,top:s*Pe,width:Math.max(0,(c-r)*Pe),height:Math.max(0,(l-s)*Pe),z:-o*Pe,baseColor:d,bleed:ho()}:Math.abs(c-r)<=u?{axis:"y",face:t,left:s*Pe,top:o*Pe,width:Math.max(0,(l-s)*Pe),height:Math.max(0,(i-o)*Pe),z:-r*Pe,baseColor:d,bleed:ho()}:null}function ho(){return{left:0,right:0,top:0,bottom:0}}function za(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 Qr(e){return[e[1]*Pe,e[0]*Pe,e[2]*Pe]}function Kr(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function Na(e,n,t){let o=e.left,r=e.left+e.width,s=e.top,i=e.top+e.height;if(Math.abs(n[0]-t[0])<=et){if(Math.abs(n[0]-o)<=et)return"left";if(Math.abs(n[0]-r)<=et)return"right"}if(Math.abs(n[1]-t[1])<=et){if(Math.abs(n[1]-s)<=et)return"top";if(Math.abs(n[1]-i)<=et)return"bottom"}return null}function $a(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=et)){if(t!==null)return null;t=o}return t}function Ua(e,n,t){let o=n.vertices,r=Qr(o[t]),s=Qr(o[(t+1)%o.length]),i=Na(e,Kr(e,r),Kr(e,s));if(!i)return null;let c=$a(r,s);if(c===null)return null;let l=Math.min(r[c],s[c]),u=Math.max(r[c],s[c]);return u-l>et?{item:e,side:i,variableAxis:c,fixed:r,start:l,end:u}:null}function Jr(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],Da)}function Ga(e,n){let t=new Map;for(let o of n){let r=e[o.sourceIndex];if(r)for(let s=0;s<r.vertices.length;s+=1){let i=Ua(o,r,s);if(!i)continue;let c=za(i),l=t.get(c);l?l.push(i):t.set(c,[i])}}for(let o of t.values()){if(o.length<2)continue;o.sort((s,i)=>s.start-i.start||s.end-i.end);let r=[];for(let s of o){r=r.filter(i=>i.end>s.start+et);for(let i of r)i.item.sourceIndex!==s.item.sourceIndex&&(Jr(i),Jr(s));r.push(s)}}}function ja(e){let n=ts(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 Wa(e){if(!e)return"#cccccc";let n=ts(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(${go(t.r)}, ${go(t.g)}, ${go(t.b)}, ${o})`}return Ya(t)}function Ya({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function go(e){return Math.round(Math.max(0,Math.min(255,e)))}function Xa(e,n,t,o){let r=t?.direction??Ma,s=Math.hypot(r[0],r[1],r[2])||1,i=r[0]/s,c=r[1]/s,l=r[2]/s,u=Math.max(0,t?.intensity??_a)*Math.max(0,e[0]*i+e[1]*c+e[2]*l),d=Math.max(0,o?.intensity??ka),x=t?.color??La,h=o?.color??Ra,b=Aa(n,u,x,h,d),v=ja(n);if(v.alpha>=1)return b;let P=parseInt(b.slice(1,3),16),g=parseInt(b.slice(3,5),16),C=parseInt(b.slice(5,7),16);return`rgba(${P}, ${g}, ${C}, ${v.alpha})`}function Za(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=Ba(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return Ga(e,n),n}function qa(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 Qa(e){let n=e.left,t=e.top,o=e.left+e.width,r=e.top+e.height;return[n,t,o,t,o,r,n,r]}function Ka(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function Ja(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(r=>!Number.isFinite(r)))return null;let o=wa/n;for(let r=0;r<8;r+=1)t[r]*=o;return`matrix3d(${t.map(r=>Number(r.toFixed(6))).join(",")})`}function es(e,n){let t=e.left-e.bleed.left,o=e.top-e.bleed.top,r=e.width+e.bleed.left+e.bleed.right,s=e.height+e.bleed.top+e.bleed.bottom,i=e.z,c=r/n,l=s/n;return`matrix3d(${(e.axis==="x"?[c,0,0,0,0,0,l,0,0,-1,0,0,t,-i,o,1]:e.axis==="y"?[0,0,c,0,0,l,0,0,-1,0,0,0,-i,o,t,1]:[c,0,0,0,0,l,0,0,0,0,1,0,t,o,i,1]).map(d=>Number(d.toFixed(6))).join(",")})`}function el(e,n){let{xAxis:t,yAxis:o,normal:r,tx:s,ty:i,tz:c}=qa(e),l=xa(Qa(e),t,o,r,s,i,c,Ia,Ka(e));return l?Ja(l,n)??es(e,n):es(e,n)}function tl(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function nl(e){return tl(e)?Oa:ns}function ol(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 rl(e,n){let t=ol(e),o=n.meshRotation;o&&(t=Ta(t,o));let[r,s]=Ea(t,n.rotX,0,n.rotY);return{x:r,y:s}}function sl(e,n,t){let o=e.filter(h=>n.has(h.face)).map(h=>({item:h,...rl(h,t)}));if(o.length===0)return[];let r=1/0,s=-1/0,i=1/0,c=-1/0;for(let h of o)r=Math.min(r,h.x),s=Math.max(s,h.x),i=Math.min(i,h.y),c=Math.max(c,h.y);let l=4,u=Math.max(1e-6,s-r),d=Math.max(1e-6,c-i),x=new Map;for(let h of o){let b=Math.min(l-1,Math.max(0,Math.floor((h.x-r)/u*l))),v=Math.min(l-1,Math.max(0,Math.floor((h.y-i)/d*l))),P=`${b}:${v}`,g=x.get(P);g||(g={tx:b,ty:v,sourceIndex:h.item.sourceIndex,items:[]},x.set(P,g)),g.items.push(h.item),g.sourceIndex=Math.min(g.sourceIndex,h.item.sourceIndex)}return Array.from(x.values()).sort((h,b)=>h.ty-b.ty||h.tx-b.tx||h.sourceIndex-b.sourceIndex).flatMap(h=>h.items)}function rs(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:s}=e,i=Za(o);if(i.length===0)return null;let c=new Set(i.map(y=>y.face));t.classList.add("polycss-voxel-mesh");let l=nl(n);l!==ns&&t.style.setProperty("--polycss-voxel-primitive",`${l}px`);let u=new Map,d=(y,m)=>{let p=`${y}|${m}`,T=u.get(p);if(T)return T;let M=Xa(os[y],m,r,s);return u.set(p,M),M},x=new Map,h=new Map,b=new Map,v=new Map;for(let y of i){let m=v.get(y.face);m||(m=[],v.set(y.face,m)),m.push(y)}let P="",g=0,C=new Set,D=y=>{let m=x.get(y.sourceIndex);return m||(m=n.createElement("b"),x.set(y.sourceIndex,m),Fa(m,d(y.face,y.baseColor),el(y,l))),m},k=y=>{let m=h.get(y);return m||(m=n.createElement("span"),m.className=`polycss-voxel-face polycss-voxel-face-${y}`,m.dataset.polycssVoxelFace=y,m.__polycssVoxelFaceHost=!0,h.set(y,m)),m},z=()=>{for(let y of Array.from(t.childNodes))if(!y.__polycssVoxelFaceHost)return y;return null},I=(y,m)=>{let p=m.map(R=>R.sourceIndex).join(",");if(b.get(y)===p)return;let T=k(y),M=n.createDocumentFragment();for(let R of m)M.appendChild(D(R));T.replaceChildren(M),b.set(y,p)},Z=()=>{for(let y of yo)c.has(y)&&I(y,v.get(y)??[])},Q=y=>new Set(y.split("|").filter(Boolean)),O=y=>{let m=Q(y);return yo.filter(p=>m.has(p)&&c.has(p))},H=y=>{let m=0;for(let p of y)m+=v.get(p)?.length??0;return m},V=y=>{let m=new Set,p=[],T=new Map;for(let M of y){m.has(M.face)||(m.add(M.face),p.push(M.face));let R=T.get(M.face);R||(R=[],T.set(M.face,R)),R.push(M)}return{orderedFaces:p,itemsByFace:T}},$=(y,m)=>{let p=new Set(y);for(let T of C){if(p.has(T))continue;let M=h.get(T);M?.parentNode===t&&t.removeChild(M)}if(m){let T=n.createDocumentFragment();for(let M of y)T.appendChild(k(M));t.insertBefore(T,z()),C=p;return}for(let T=0;T<y.length;T+=1){let M=y[T],R=k(M);if(R.parentNode===t)continue;let L=null;for(let te=T+1;te<y.length;te+=1){let _=h.get(y[te]);if(_?.parentNode===t){L=_;break}}t.insertBefore(R,L??z())}C=p},A=(y,m,p)=>{if(!p){let te=O(y);$(te,!1),g=H(te);return}let T=new Set(y.split("|").filter(Boolean)),M=sl(i,T,m),{orderedFaces:R,itemsByFace:L}=V(M);for(let te of R)I(te,L.get(te)??[]);$(R,!0),g=M.length};return Z(),{get brushCount(){return g},render(y){P=qr(y),A(P,y,!0)},syncCamera(y){let m=qr(y);m!==P&&(P=m,A(m,y,!1))},dispose(){for(let y of h.values())y.remove();t.classList.remove("polycss-voxel-mesh"),t.style.removeProperty("--polycss-voxel-primitive"),x.clear(),h.clear(),b.clear(),g=0,C=new Set,P=""}}}var ss="polycss-styles";function bo(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(ss))return;let t=n.createElement("style");t.id=ss,t.textContent=il,n.head.appendChild(t)}var il=`
1
+ import{CAMERA_BACKFACE_CULL_EPS as Eo,DEFAULT_SEAM_BLEED as zs,VOXEL_CAMERA_CULL_NORMAL_LIMIT as wl,cameraCullNormalKey as Ml,cameraCullVisibleSignature as Ll,computeSceneBbox as _l,computeLightVisibility as Rl,findOverlappingPolygonDuplicates as Hs,inverseRotateVec3 as To,isAxisAlignedSurfaceNormal as kl,isVoxelCameraCullableNormalGroups as Ol,normalFacesCamera as Dl,optimizeMeshPolygons as Il,parseHexColor as Hl,polygonCssSurfaceNormal as Fs}from"@layoutit/polycss-core";import{packTextureAtlasPlansWithScaleCore as bi}from"@layoutit/polycss-core";function vi(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 xt(e,n,t){return bi(e,n,vi(t))}import{buildTextureEdgeRepairSets as Ur,buildSeamBleedPolygonEdges as ba,buildSeamBleedPolygonSet as va}from"@layoutit/polycss-core";import{TEXTURE_TRIANGLE_BLEED as xi,TEXTURE_EDGE_REPAIR_ALPHA_MIN as Pi,TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN as Si,TEXTURE_EDGE_REPAIR_RADIUS as mr}from"@layoutit/polycss-core";import{expandClipPoints as Ci}from"@layoutit/polycss-core";import{BASIS_EPS as Ei}from"@layoutit/polycss-core";var Pt=new Map;function Ti(e){let n=Pt.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.crossOrigin="anonymous",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),Pt.set(e,n),n.then(()=>{Pt.get(e)===n&&Pt.delete(e)},()=>{Pt.get(e)===n&&Pt.delete(e)})),n}function _e(e,n,t=1,o=0,r=0,s=1,i=0,c=0){e.setTransform(t*n,o*n,r*n,s*n,i*n,c*n)}function Nn(e){let n=e/255;return n<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function $n(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 Ai(e,n,t,o,r,s,i){let c=Math.round(n*i),l=Math.round(t*i),u=Math.max(1,Math.round(o*i)),d=Math.max(1,Math.round(r*i)),x=e.getImageData(c,l,u,d),h=x.data,b=s.r,v=s.g,P=s.b;for(let g=0;g<h.length;g+=4)h[g+3]!==0&&(h[g]=$n(Nn(h[g])*b),h[g+1]=$n(Nn(h[g+1])*v),h[g+2]=$n(Nn(h[g+2])*P));e.putImageData(x,c,l)}function wi(e,n,t,o,r,s,i){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,u=Math.max(r/c,s/l),d=c*u,x=l*u;_e(e,i),e.drawImage(n,t+(r-d)/2,o+(s-x)/2,d,x)}function St(e,n){return Math.max(0,Math.min(n,e))}function fr(e,n,t,o,r,s,i,c){let l=n.naturalWidth||n.width||1,u=n.naturalHeight||n.height||1,d=St(Math.min(t.minU,t.maxU)*l,l),x=St(Math.max(t.minU,t.maxU)*l,l),h=St(Math.min(t.minV,t.maxV)*u,u),b=St(Math.max(t.minV,t.maxV)*u,u),v=Math.floor(d),P=Math.floor(h),g=Math.ceil(x)-v,C=Math.ceil(b)-P;g<1&&(v=Math.floor(St((t.minU+t.maxU)/2*l,l-1)),g=1),C<1&&(P=Math.floor(St((t.minV+t.maxV)/2*u,u-1)),C=1),v=Math.max(0,Math.min(l-1,v)),P=Math.max(0,Math.min(u-1,P)),g=Math.max(1,Math.min(l-v,g)),C=Math.max(1,Math.min(u-P,C)),_e(e,c),e.drawImage(n,v,P,g,C,o,r,s,i)}function vr(e){return e==="repeat"||e==="mirrored-repeat"}function hr(e,n){return vr(e)?Math.floor(n):0}function gr(e,n){return vr(e)?Math.ceil(n)-1:0}function yr(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function br(e,n,t,o,r,s,i){let c=r?hr(s,r.minU):0,l=r?gr(s,r.maxU):0,u=r?hr(i,r.minV):0,d=r?gr(i,r.maxV):0;for(let x=c;x<=l;x++)for(let h=u;h<=d;h++){let b=yr(s,x),v=yr(i,h);if(!b&&!v){e.drawImage(n,x*t,h*o);continue}e.save(),e.translate((b?x+1:x)*t,(v?h+1:h)*o),e.scale(b?-1:1,v?-1:1),e.drawImage(n,0,0),e.restore()}}function Un(e,n,t,o){for(let r=0;r<o.length;r+=2){let s=n+o[r],i=t+o[r+1];r===0?e.moveTo(s,i):e.lineTo(s,i)}e.closePath()}function dn(e,n,t,o,r,s){for(let i=0;i<o.length;i+=2){let c=n+o[i]+r,l=t+o[i+1]+s;i===0?e.moveTo(c,l):e.lineTo(c,l)}e.closePath()}function Mi(e,n,t,o){_e(e,o),e.beginPath(),Un(e,n.x,n.y,n.screenPts),e.clip(),_e(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function pn(e,n,t,o,r){n.polygon.textureAlphaMode==="opaque"&&(_e(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+r,n.canvasW,n.canvasH))}function Li(e,n,t,o,r=0,s=0){if(n.textureTriangles?.length){let i=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1;for(let l of n.textureTriangles){let u=Ci(l.screenPts,xi*(n.bleedRatio??1));e.save(),_e(e,o),e.beginPath(),dn(e,n.x,n.y,u,r,s),e.clip(),pn(e,n,o,r,s),l.uvAffine?(_e(e,o,l.uvAffine.a/i,l.uvAffine.c/i,l.uvAffine.b/c,l.uvAffine.d/c,n.x+l.uvAffine.e+r,n.y+l.uvAffine.f+s),br(e,t,i,c,l.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t)):l.uvSampleRect&&fr(e,t,l.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let i=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1,l=n.polygon.textureAlphaMode==="opaque";l&&(e.save(),_e(e,o),e.beginPath(),dn(e,n.x,n.y,n.screenPts,r,s),e.clip(),pn(e,n,o,r,s)),_e(e,o,n.uvAffine.a/i,n.uvAffine.c/i,n.uvAffine.b/c,n.uvAffine.d/c,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+s),br(e,t,i,c,n.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t),l&&e.restore()}else if(n.uvSampleRect){let i=n.polygon.textureAlphaMode==="opaque";i&&(e.save(),_e(e,o),e.beginPath(),dn(e,n.x,n.y,n.screenPts,r,s),e.clip(),pn(e,n,o,r,s)),fr(e,t,n.uvSampleRect,n.x+r,n.y+s,n.canvasW,n.canvasH,o),i&&e.restore()}else{let i=n.polygon.textureAlphaMode==="opaque";i&&(e.save(),_e(e,o),e.beginPath(),dn(e,n.x,n.y,n.screenPts,r,s),e.clip(),pn(e,n,o,r,s)),wi(e,t,n.x+r,n.y+s,n.canvasW,n.canvasH,o),i&&e.restore()}}function _i(e,n,t,o,r,s){let i=r-t,c=s-o,l=i*i+c*c;if(l<=Ei)return Math.hypot(e-t,n-o);let u=Math.max(0,Math.min(1,((e-t)*i+(n-o)*c)/l));return Math.hypot(e-(t+i*u),n-(o+c*u))}function Ri(e,n,t,o){let r=1/0,s=t.length/2;for(let i of o){if(i<0||i>=s)continue;let c=i*2,l=(i+1)%s*2;r=Math.min(r,_i(e,n,t[c],t[c+1],t[l],t[l+1]))}return r}function ki(e,n,t,o,r,s){let i=Math.max(0,o-s),c=Math.min(n-1,o+s),l=Math.max(0,r-s),u=Math.min(t-1,r+s),d=null,x=1/0;for(let h=l;h<=u;h++)for(let b=i;b<=c;b++){if(b===o&&h===r)continue;let v=b-o,P=h-r,g=v*v+P*P;if(g>s*s||g>=x)continue;let C=(h*n+b)*4;e[C+3]<Si||(d=C,x=g)}return d}function Oi(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),s=Math.max(0,Math.floor(n.y*t)),i=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),c=Math.max(1,Math.min(o.height-s,Math.ceil(n.canvasH*t)));if(i<=0||c<=0)return;let l;try{l=e.getImageData(r,s,i,c)}catch{return}let u=l.data,d=new Uint8ClampedArray(u),x=Math.max(mr,mr/t),h=Math.max(2,Math.ceil(x*t)+1),b=!1;for(let v=0;v<c;v++)for(let P=0;P<i;P++){let g=(v*i+P)*4,C=u[g+3];if(C<Pi||C===255)continue;let D=(r+P+.5)/t-n.x,k=(s+v+.5)/t-n.y;if(Ri(D,k,n.screenPts,n.textureEdgeRepairEdges)>x)continue;let z=ki(d,i,c,P,v,h);z!==null&&(u[g]=d[z],u[g+1]=d[z+1],u[g+2]=d[z+2],u[g+3]=255,b=!0)}b&&e.putImageData(l,r,s)}function Di(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 Ii(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=e.entries.some(d=>d.textureEdgeRepair&&d.texture&&d.textureEdgeRepairEdges&&d.textureEdgeRepairEdges.size>0),i=r.getContext("2d",s?{willReadFrequently:!0}:void 0);if(!i)return{width:e.width,height:e.height,url:null};let c=Array.from(new Set(e.entries.flatMap(d=>d.texture?[d.texture]:[]))),l=new Map;await Promise.all(c.map(async d=>{l.set(d,await Ti(d))}));for(let d of e.entries){let x=d.texture?l.get(d.texture):null;if(!d.texture){i.save(),Mi(i,d,n,o),i.restore();continue}x&&(i.save(),_e(i,o),i.beginPath(),Un(i,d.x,d.y,d.screenPts),i.clip(),Li(i,d,x,o),i.restore()),d.texture&&n==="baked"&&(i.save(),_e(i,o),i.beginPath(),Un(i,d.x,d.y,d.screenPts),i.clip(),Ai(i,d.x,d.y,d.canvasW,d.canvasH,d.textureTint,o),i.restore()),Oi(i,d,o)}let u=await Di(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:u}}async function Ct(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await Ii(i,n,t,o))}return s}import{isFullRectSolid as Ve,isSolidTrianglePlan as Ke,isProjectiveQuadPlan as Be,fullRectBounds as Cd,safariCssProjectiveUnsupported as xr,incrementCount as Ed,dominantCountKey as Td,filterAtlasPlans as Fi,getSolidPaintDefaultsForPlansCore as Vi}from"@layoutit/polycss-core";import{parseHex as Bi,rgbKey as zi}from"@layoutit/polycss-core";import{computeTextureAtlasPlan as Ld,buildBasisHints as _d}from"@layoutit/polycss-core";import{resolveProjectiveQuadGuards as Hi}from"@layoutit/polycss-core";function Et(e,n){let o=e?.defaultView?.__polycssProjectiveQuadGuards,r=n&&o?{...n,...o}:o??n;return Hi(r)}function Tt(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function Gn(e){if(Pr(e))return!0;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!xr(t):!0}function Ut(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 Pr(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 Ni(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function ze(e,n){return n?.disable?.includes("u")?null:Pr(e)?"corner-bevel":Gn(e)?Ni(e)?"border-large":"border":null}function At(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!xr(t):!0}function Gt(e,n,t,o,r){let s=new Set(o?.disable??[]);return Vi(e,n,s,{solidTriangleSupported:Gn(t),projectiveQuadSupported:At(t),cornerShapeSupported:Ut(t),borderShapeSupported:Tt(t)},Bi,zi,r)}function jn(e,n,t=new Set,o){let r=o??(typeof document<"u"?document:null);if(!r)return{};let s=t.size>0?{disable:Array.from(t)}:void 0;return Gt(e,n,r,s)}function mn(e){let n=e??(typeof document<"u"?document:null);if(!n){if(!!!(typeof CSS<"u"?CSS:void 0)?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) circle(0)"))return!1;let r=typeof matchMedia<"u"?matchMedia:void 0;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}return Tt(n)}function fn(e){let n=e??(typeof document<"u"?document:null);if(!n){let t=typeof CSS<"u"?CSS:void 0;if(t?.supports?.("corner-top-left-shape","bevel")&&t.supports("corner-top-right-shape","bevel"))return!0;let o=(typeof navigator<"u"?navigator:globalThis.navigator)?.userAgent??"";if(!o)return!0;let r=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(o);return!/\bVersion\/[\d.]+.*\bSafari\//.test(o)||r}return Gn(n)}function Wn(e,n,t,o){let r=o??(typeof document<"u"?document:null);return Fi(e,n,t,{solidTriangleSupported:fn(o),projectiveQuadSupported:r?At(r):!0,borderShapeSupported:mn(o)})}import{ASYNC_RENDER_BUDGET_MS as pa,DEFAULT_SEAM_BLEED as Fr,DEFAULT_TILE as ma,PROJECTIVE_QUAD_DENOM_EPS as fa,PROJECTIVE_QUAD_MAX_WEIGHT_RATIO as ha,PROJECTIVE_QUAD_BLEED as Hr,resolveBleedRatio as mo}from"@layoutit/polycss-core";import{buildBasisHints as fo,buildSeamBleedPolygonEdges as ga,computeTextureAtlasPlan as qt}from"@layoutit/polycss-core";import{cornerShapeGeometryForPlan as Zt}from"@layoutit/polycss-core";import{formatCssLength as hn,formatMatrix3dValues as Ui,formatSolidQuadMatrix as Gi}from"@layoutit/polycss-core";import{shadePolygon as ji}from"@layoutit/polycss-core";import{parseHex as Sr,rgbKey as Cr}from"@layoutit/polycss-core";function xe(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,s=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`(^|;)\\s*${s}\\s*:[^;]*`,"i"),c=i.test(o)?o.replace(i,(l,u)=>`${u}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;c!==o&&e.setAttribute("style",c)}function ot(e,n){let t=e.getAttribute("style")??"";if(!t||!t.toLowerCase().includes(n.toLowerCase()))return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`^\\s*${o}\\s*:`,"i"),s=t.split(";").map(i=>i.trim()).filter(i=>i&&!r.test(i)).join(";");s?e.setAttribute("style",s):e.removeAttribute("style")}function jt(e,n,t,o=!1){if(n==="dynamic"){let r=Sr(e.polygon.color??"#cccccc"),s=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return Cr(r)!==t?.dynamicColorKey&&(s+=`;--psr:${(r.r/255).toFixed(4)};--psg:${(r.g/255).toFixed(4)};--psb:${(r.b/255).toFixed(4)}`),s}return e.shadedColor?`;color:${e.shadedColor}`:""}function $i(e,n){xe(e,"--pnx",n.normal[0].toFixed(4)),xe(e,"--pny",n.normal[1].toFixed(4)),xe(e,"--pnz",n.normal[2].toFixed(4))}function wt(e,n,t,o){if(t==="dynamic"){ot(e,"color"),ot(e,"background"),$i(e,n);let r=Sr(n.polygon.color??"#cccccc");Cr(r)===o?.dynamicColorKey?(ot(e,"--psr"),ot(e,"--psg"),ot(e,"--psb")):(xe(e,"--psr",(r.r/255).toFixed(4)),xe(e,"--psg",(r.g/255).toFixed(4)),xe(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(ot(e,"background"),xe(e,"color",n.shadedColor)):(ot(e,"background"),ot(e,"color"))}import{formatBorderShapeElementStyle as Er,formatCornerShapeElementStyle as Tr}from"@layoutit/polycss-core";import{atlasCanonicalSizeForEntry as rt}from"@layoutit/polycss-core";import{computeProjectiveQuadMatrix as Wi,stableBasisFromPlan as Yi}from"@layoutit/polycss-core";import{DEFAULT_LIGHT_DIR as Xi,DEFAULT_LIGHT_COLOR as Zi,DEFAULT_LIGHT_INTENSITY as qi,DEFAULT_AMBIENT_COLOR as Qi,DEFAULT_AMBIENT_INTENSITY as Ki}from"@layoutit/polycss-core";var Ar="polycss-corner-shape-solid",Yn=new WeakMap,Xn=new WeakMap;function ye(e,n,t){let o=Yn.get(e),r=Xn.get(e),s=typeof t=="number";if(!n.data&&!s&&(!o||o.length===0)){e.__polycssHasDataAttrs=!1;return}let i=new Map;if(n.data)for(let[l,u]of Object.entries(n.data))i.set(l,String(u));if(s&&i.set("poly-index",String(t)),o)for(let l of o)i.has(l)||e.removeAttribute(`data-${l}`);for(let[l,u]of i)r?.get(l)!==u&&e.setAttribute(`data-${l}`,u);let c=Array.from(i.keys());c.length>0?Yn.set(e,c):Yn.delete(e),i.size>0?Xn.set(e,i):Xn.delete(e),e.__polycssHasDataAttrs=c.length>0}function Mt(e){return e.__polycssHasDataAttrs===!0}function Zn(e,n,t,o,r=t==="dynamic"){if(!n.url)return;let s=`url(${n.url})`,i=o.canvasW||1,c=o.canvasH||1,l=rt(o),u=`${hn(-o.x/i*l)} ${hn(-o.y/c*l)}`,d=`${hn(n.width/i*l)} ${hn(n.height/c*l)}`,x=`transform:matrix3d(${o.atlasMatrix});--polycss-atlas-size:${l}px`,h=`${x};--polycss-atlas-position:${u};--polycss-atlas-image-size:${d}`;if(t==="dynamic"){let b=r?`;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`:"";e.setAttribute("style",h+`;--polycss-atlas-url:${s}`+b)}else e.setAttribute("style",x+`;background-image:${s};background-position:${u};background-size:${d};background-repeat:no-repeat;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`)}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 r=Mr(n,t);return r?(e.style.visibility="",xe(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(xe(e,"--pnx",r.normal[0].toFixed(4)),xe(e,"--pny",r.normal[1].toFixed(4)),xe(e,"--pnz",r.normal[2].toFixed(4))),ye(e,t,n.index),!0):(e.style.visibility="hidden",ye(e,t,n.index),!0)}function qn(e,n,t,o,r){if(o!=="baked")return{...e,polygon:n,normal:t};let s=r.directionalLight,i=r.ambientLight,c=s?.direction??Xi,l=s?.color??Zi,u=Math.max(0,s?.intensity??qi),d=i?.color??Qi,x=Math.max(0,i?.intensity??Ki),h=Math.hypot(c[0],c[1],c[2])||1,b=c[0]/h,v=c[1]/h,P=c[2]/h,C=r.lightOccludedPolyIndices?.has(e.index)??!1?0:u*Math.max(0,t[0]*b+t[1]*v+t[2]*P);return{...e,polygon:n,normal:t,shadedColor:ji(n.color??"#cccccc",C,l,d,x)}}function Mr(e,n){let t=Lr(e,n);if(!t)return null;let{normal:o,xAxis:r,yAxis:s,tx:i,ty:c,tz:l}=t;return{normal:o,matrix:Ui([r[0]*e.canvasW/rt(e),r[1]*e.canvasW/rt(e),r[2]*e.canvasW/rt(e),0,s[0]*e.canvasH/rt(e),s[1]*e.canvasH/rt(e),s[2]*e.canvasH/rt(e),0,o[0],o[1],o[2],0,i,c,l,1])}}var Lr=Yi;function Ji(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=Lr(e,n);if(!o)return null;let r=Wi(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return r?{matrix:r,normal:o.normal}:null}function Qn(e,n,t,o,r=!1){let s=t.createElement("b");return s.setAttribute("style",`transform:matrix3d(${Gi(e)})`+jt(e,n,o,r)),ye(s,e.polygon,e.index),s}function Kn(e,n,t,o,r=!1){let s=t.createElement("i");return s.setAttribute("style",Er(e)+jt(e,n,o,r)),ye(s,e.polygon,e.index),s}function Jn(e,n,t,o,r,s=!1){let i=o.createElement("u");return i.className=Ar,i.setAttribute("style",Tr(e,n)+jt(e,t,r,s)),ye(i,e.polygon,e.index),i}function eo(e,n,t,o,r=!1){let s=t.createElement("b");return s.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+jt(e,n,o,r)),ye(s,e.polygon,e.index),s}function _r(e,n,t,o,r,s,i){let c=n.projectiveMatrix?Ji(n,t,s):Mr(n,t);if(!c)return!1;let l=qn(n,t,c.normal,o,r);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,wt(e,l,o,i),ye(e,l.polygon,l.index),!0}function Rr(e,n,t,o){e.style.visibility="",e.setAttribute("style",Er(n)),wt(e,n,t,o),ye(e,n.polygon,n.index)}function kr(e,n,t,o,r){e.style.visibility="",e.className=Ar,e.setAttribute("style",Tr(n,t)),wt(e,n,o,r),xe(e,"background","currentColor"),ye(e,n.polygon,n.index)}function to(e,n,t,o=!1){let r=t.createElement("s"),s=rt(e),i=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:${s}px;opacity:0`+i),ye(r,e.polygon,e.index),r}import{computeSolidTriangleColorPlan as ya}from"@layoutit/polycss-core";import{computeSolidTrianglePlanFromCssPoints as ea,computeSolidTrianglePlan as ta}from"@layoutit/polycss-core";function st(e,n,t,o={}){let r=o.primitive!=null?void 0:(()=>{let s=t.doc??(typeof document<"u"?document:null);return s?ze(s,t.strategies)??"border":"border"})();return ta(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??r})}function no(e,n,t,o,r,s,i,c,l,u,d,x,h){let b=o.primitive!=null?void 0:(()=>{let v=t.doc??(typeof document<"u"?document:null);return v?ze(v,t.strategies)??"border":"border"})();return ea(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??b},r,s,i,c,l,u,d,x,h)}import{buildSeamBleedPolygonEdges as na,DEFAULT_SEAM_BLEED as oa,DEFAULT_TILE as Yd,resolveBleedRatio as ra}from"@layoutit/polycss-core";import{rgbEqual as sa,stepRgbToward as ia,rgbToCss as aa,colorErrorScore as la}from"@layoutit/polycss-core";import{computeSolidTriangleColorPlan as Or}from"@layoutit/polycss-core";import{stableTriangleMatrixDecimals as oo}from"@layoutit/polycss-core";var ca="0 48px 96px 48px";function ro(e,n){return na(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function so(e,n,t){let o=ra(t.seamBleed),r=oa*o,s={...t,bleedRatio:o};return n&&r>0?{...s,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:s}function gn(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 Dr(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function it(e,n,t,o,r,s){return t?s.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:r==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:Dr(n,s):!0}function io(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"?ca:""),t.__polycssSolidTrianglePrimitive=n)}function ao(e){let n=e;n.__polycssSolidTriangleHidden&&(e.style.visibility="",n.__polycssSolidTriangleHidden=!1)}function Lt(e){let n=e;n.__polycssSolidTriangleHidden||(e.style.visibility="hidden",n.__polycssSolidTriangleHidden=!0)}function Wt(e,n){e.setAttribute("style",n.styleText),io(e,n.primitive);let t=e;t.__polycssSolidTriangleBasis=n.basis,t.__polycssSolidTriangleHidden=!1,n.colorComputed&&(t.__polycssSolidTriangleColor=n.bakedColor??"",t.__polycssSolidTriangleColorRgb=n.bakedRgb,t.__polycssSolidTriangleColorAlpha=n.bakedAlpha),t.__polycssSolidTriangleColorFrame=void 0,(n.polygon.data||Mt(e))&&ye(e,n.polygon)}function Ir(e,n,t,o){if(!n.colorComputed){(n.polygon.data||Mt(e))&&ye(e,n.polygon);return}let r=e,s=n.bakedColor??"",i=n.bakedRgb,c=n.bakedAlpha??1,l=r.__polycssSolidTriangleColor,u=r.__polycssSolidTriangleColorRgb,d=r.__polycssSolidTriangleColorAlpha??1,x=o??Dr(n.index,t);if(!t.updatesDisabled&&l!==s&&(l===void 0||x)){let h=s,b=i;if(t.maxStep>0&&u&&i&&d===c){let v=ia(u,i,t.maxStep);b=v,h=aa(v,c)}(h!==l||!sa(b,u))&&(e.style.color=h),r.__polycssSolidTriangleColor=h,r.__polycssSolidTriangleColorRgb=b,r.__polycssSolidTriangleColorAlpha=c,r.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||Mt(e))&&ye(e,n.polygon)}function Yt(e,n,t,o){let r=e;io(e,n.primitive),r.__polycssSolidTriangleBasis!==n.basis&&(r.__polycssSolidTriangleBasis=n.basis),ao(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||Mt(e))&&Ir(e,n,t,o)}function yn(e,n,t,o){ao(e),Ir(e,n,t,o)}function Xt(e,n){let t=e;io(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),ao(e),e.style.transform=n.transformText,(n.polygon.data||Mt(e))&&ye(e,n.polygon)}function ua(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 lo(e,n,t){if(t.stableTriangleColorPolicy!=="adaptive")return null;if(t.stableTriangleColorFreezeFrames===0)return new Set;let o=Math.max(0,Math.floor(t.stableTriangleColorFrame??0)),r=Math.max(1,Math.floor(t.stableTriangleColorFreezeFrames??1));if(r<=1&&!Number.isFinite(t.stableTriangleColorBudget))return null;let s=ua(e.length,t),i=Math.max(1,Math.floor(t.stableTriangleColorMaxAge??Math.max(2,r*2))),c=[];for(let l=0;l<e.length;l++){let u=e[l],d=n[l];if(u.kind!=="triangle"||!d)continue;let x=u.element,h=x.__polycssSolidTriangleColor,b=d.bakedColor??"";if(h===b)continue;let v=x.__polycssSolidTriangleColorFrame??0,P=Math.max(0,o-v),g=la(h,b);c.push({index:l,score:(P>=i?1e6:0)+g*1e4+P})}return c.length===0?new Set:(c.sort((l,u)=>u.score-l.score),new Set(c.slice(0,s).map(l=>l.index)))}function bn(e,n){let t=n.createElement("u");return Wt(t,e),ye(t,e.polygon,e.index),t}function da(e,n,t){let o=t.createElement("u");return Lt(o),ye(o,e,n),o}function co(e,n,t,o,r,s){let i=t,c=i.stableTriangleDebug,l=o&&r==="color-only";if(i.stableTriangleColorPolicy==="adaptive"||e.length!==n.length)return!1;let u=oo(i.stableTriangleMatrixDecimals),d=t.doc??(typeof document<"u"?document:null),x=d?ze(d,t.strategies)??"border":"border";for(let b=0;b<e.length;b++){let v=e[b];if(v.kind!=="triangle"||v.polygonIndex!==b||!n[b])return!1}let h=ro(n,t);for(let b=0;b<e.length;b++){let v=e[b].element,P=n[b];if(l){if(it(v,b,o,c,i.stableTriangleColorPolicy,s)){let C=Or(P,b,t);if(!C)continue;yn(v,C,s)}continue}let g=st(P,b,so(b,h,t),{basis:v.__polycssSolidTriangleBasis,matrixDecimals:u,primitive:x,includeColor:r!=="plan-only"&&r!=="transform-only"&&it(v,b,o,c,i.stableTriangleColorPolicy,s)});if(!g){Lt(v);continue}o&&r==="plan-only"||(o&&r==="transform-only"?Xt(v,g):o?Yt(v,g,s):Wt(v,g))}return!0}function _t(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=ze(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let r=oo(n.stableTriangleMatrixDecimals),s=[],i=ro(e,n);for(let c=0;c<e.length;c+=1){let l=e[c],u=st(l,c,so(c,i,n),{matrixDecimals:r,primitive:o}),d=u?bn(u,t):da(l,c,t);s.push({polygonIndex:c,element:d,kind:"triangle",dispose:()=>{}})}return{rendered:s,dispose(){}}}function uo(e,n,t={}){let o=t.doc??(typeof document<"u"?document:null);if(!o)return{rendered:e,dispose:()=>{}};let r=ze(o,t.strategies);if(!r||e.some(g=>g.kind!=="triangle")||n.length!==e.length)return null;for(let g=0;g<e.length;g++)if(e[g].polygonIndex!==g)return null;let s=t.optimizeStableTriangleStyle===!0&&(t.textureLighting??"baked")==="baked",i=t,c=i.stableTriangleDebug,l=i.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full"),u=s&&l==="color-only",d=gn(i),x=oo(i.stableTriangleMatrixDecimals);if(co(e,n,t,s,l,d))return{rendered:e,dispose(){}};let h=new Array(e.length),b=new Array(e.length),v=ro(n,t);for(let g=0;g<e.length;g++){let C=e[g].element;if(u){let D=i.stableTriangleColorPolicy==="adaptive"||it(C,g,s,c,i.stableTriangleColorPolicy,d);b[g]=D?Or(n[g],g,t):null;continue}h[g]=st(n[g],g,so(g,v,t),{basis:C.__polycssSolidTriangleBasis,matrixDecimals:x,primitive:r,includeColor:l!=="plan-only"&&l!=="transform-only"&&it(C,g,s,c,i.stableTriangleColorPolicy,d)})}let P=s&&l!=="plan-only"&&l!=="transform-only"?lo(e,u?b:h,i):null;for(let g=0;g<e.length;g++){if(u){let D=b[g];D&&yn(e[g].element,D,d,P?.has(g));continue}let C=h[g];if(!C){Lt(e[g].element);continue}s&&l==="plan-only"||(s&&l==="transform-only"?Xt(e[g].element,C):s?Yt(e[g].element,C,d,P?.has(g)):Wt(e[g].element,C))}return{rendered:e,dispose(){}}}import{stableTriangleMatrixDecimals as Vr}from"@layoutit/polycss-core";function Br(){return new Promise(e=>setTimeout(e,0))}async function po(e){return performance.now()-e<pa?e:(await Br(),performance.now())}function zr(e,n){let t=mo(n.seamBleed),o=Fr*t,r={...n,bleedRatio:t};return e.seamBleedEdges?.size&&o>0?{...r,seamBleed:o,seamEdges:e.seamBleedEdges}:{...r,seamBleed:void 0,seamEdges:void 0}}function Nr(e,n){return ga(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function $r(e,n,t){let o=mo(t.seamBleed),r=Fr*o,s={...t,bleedRatio:o};return n&&r>0?{...s,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:s}function dt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=fo(e,n),r=Et(t),s=e.map((i,c)=>qt(i,c,n,r,o[c]));return Gt(s,n.textureLighting??"baked",t,n.strategies)}function pt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=n,s=o==="dynamic"&&r.skipDynamicNormalVars===!0,i=new Set(n.strategies?.disable??[]),c=!i.has("b"),l=c&&At(t),u=ze(t,n.strategies),d=u!==null,x=!i.has("i")&&Ut(t),h=!i.has("i")&&Tt(t),b=fo(e,n),v=Et(t),P=Nr(e,n),g=e.map((m,p)=>qt(m,p,$r(p,P,n),v,b[p]));if(typeof window<"u"){let m=window,p=g[1];m.__vanillaPlan1={matrix:p?.matrix,canvasW:p?.canvasW,canvasH:p?.canvasH,vertexCount:e[1]?.vertices.length}}let C=n.solidPaintDefaults??(r.computeSolidPaintDefaults?Gt(g,o,t,n.strategies):void 0),D=C?{...n,solidPaintDefaults:C}:n,k=g.map(m=>m&&d&&Ke(m)?st(m.polygon,m.index,zr(m,D),{primitive:u??void 0}):null),z=g.map(m=>m&&x&&!Ke(m)&&!(c&&Ve(m))&&!(l&&Be(m))?Zt(m):null),I=g.map((m,p)=>m&&(m.texture||!(c&&Ve(m))&&!k[p]&&!(l&&Be(m))&&!z[p]&&!h?m:null)),{packed:Z,atlasScale:Q}=xt(I,n.textureQuality,t),O=new Map,H=[],V=!1,$=[];for(let m=0;m<e.length;m++){let p=g[m],T=k[m],M=z[m];if(!p)continue;let R=Z.entries[m];if(R){let L=to(R,o,t,s);O.set(m,L),H.push({polygonIndex:m,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!p.texture&&c&&Ve(p)){let L=Qn(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&T){let L=bn(T,t);H.push({polygonIndex:m,element:L,kind:"triangle",plan:p,dispose:()=>{}})}else if(!p.texture&&l&&Be(p)){let L=eo(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&M){let L=Jn(p,M,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"corner",plan:p,dispose:()=>{}})}else if(!p.texture&&h){let L=Kn(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"border",plan:p,dispose:()=>{}})}}H.sort((m,p)=>m.polygonIndex-p.polygonIndex);let A=Ct(Z.pages,o,t,Q,()=>V).then(m=>{if(V){for(let p of m)p.url?.startsWith("blob:")&&URL.revokeObjectURL(p.url);return}$=m.flatMap(p=>p.url?.startsWith("blob:")?[p.url]:[]);for(let p=0;p<Z.pages.length;p++){let T=Z.pages[p],M=m[p];if(M)for(let R of T.entries){let L=O.get(R.index);!L||!M.url||Zn(L,M,o,R,!0)}}}).catch(()=>{if(!V)for(let m of O.values())xe(m,"opacity","0.5"),xe(m,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:H,solidPaintDefaults:C??{},pagesReady:A,dispose(){V=!0;for(let m of $)URL.revokeObjectURL(m);$=[]}}}async function Qt(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let r=n.textureLighting??"baked",i=r==="dynamic"&&n.skipDynamicNormalVars===!0,c=new Set(n.strategies?.disable??[]),l=!c.has("b"),u=l&&At(o),d=ze(o,n.strategies),x=d!==null,h=!c.has("i")&&Ut(o),b=!c.has("i")&&Tt(o);if(await Br(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let v=fo(e,n),P=Et(o),g=Nr(e,n),C=performance.now(),D=new Array(e.length);for(let m=0;m<e.length;m++)if(D[m]=qt(e[m],m,$r(m,g,n),P,v[m]),C=await po(C),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let k=n.solidPaintDefaults??Gt(D,r,o,n.strategies),z=new Array(D.length),I=new Array(D.length),Z=new Array(D.length);for(let m=0;m<D.length;m++){let p=D[m],T=p&&x&&Ke(p)?st(p.polygon,p.index,zr(p,{...n,solidPaintDefaults:k}),{primitive:d??void 0}):null;z[m]=T;let M=p&&h&&!Ke(p)&&!(l&&Ve(p))&&!(u&&Be(p))?Zt(p):null;if(I[m]=M,Z[m]=p&&(p.texture||!(l&&Ve(p))&&!T&&!(u&&Be(p))&&!M&&!b?p:null),C=await po(C),t())return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}let{packed:Q,atlasScale:O}=xt(Z,n.textureQuality,o),H=new Map,V=[],$=!1,A=[];for(let m=0;m<e.length;m++){let p=D[m],T=z[m],M=I[m];if(!p)continue;let R=Q.entries[m];if(R){let L=to(R,r,o,i);H.set(m,L),V.push({polygonIndex:m,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!p.texture&&l&&Ve(p)){let L=Qn(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&T){let L=bn(T,o);V.push({polygonIndex:m,element:L,kind:"triangle",plan:p,dispose:()=>{}})}else if(!p.texture&&u&&Be(p)){let L=eo(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&M){let L=Jn(p,M,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"corner",plan:p,dispose:()=>{}})}else if(!p.texture&&b){let L=Kn(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"border",plan:p,dispose:()=>{}})}if(C=await po(C),t()){for(let L of V)L.dispose();return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}}V.sort((m,p)=>m.polygonIndex-p.polygonIndex);let y=Ct(Q.pages,r,o,O,()=>$||t()).then(m=>{if($||t()){for(let p of m)p.url?.startsWith("blob:")&&URL.revokeObjectURL(p.url);return}A=m.flatMap(p=>p.url?.startsWith("blob:")?[p.url]:[]);for(let p=0;p<Q.pages.length;p++){let T=Q.pages[p],M=m[p];if(M)for(let R of T.entries){let L=H.get(R.index);!L||!M.url||Zn(L,M,r,R,!0)}}}).catch(()=>{if(!($||t()))for(let m of H.values())xe(m,"opacity","0.5"),xe(m,"outline","1px dashed rgba(255, 0, 0, 0.6)")});return{rendered:V,solidPaintDefaults:k,pagesReady:y,dispose(){$=!0;for(let m of A)URL.revokeObjectURL(m);A=[]}}}function Kt(e,n,t,o={}){let r=o.textureLighting??"baked",s=o,i=s.optimizeStableTriangleStyle===!0&&r==="baked";if(!i||s.stableTriangleColorPolicy==="adaptive"||e.length!==t.polygonCount||n.length!==t.polygonCount||t.vertices.length<t.polygonCount*9)return!1;let c=s.stableTriangleDebug,l=s.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full");if(l==="color-only")return!1;let u=Vr(s.stableTriangleMatrixDecimals),d=gn(s),x=o.tileSize??ma,h=o.layerElevation??x,b=o.doc??(typeof document<"u"?document:null),v=b?ze(b,o.strategies)??"border":"border";for(let g=0;g<e.length;g++){let C=e[g],D=n[g];if(C.kind!=="triangle"||C.polygonIndex!==g||!D||D.vertices.length!==3||D.texture||D.material?.texture)return!1}let P=t.vertices;for(let g=0;g<e.length;g++){let C=e[g].element,D=n[g],k=g*9,z=P[k+1]*x,I=P[k]*x,Z=P[k+2]*h,Q=P[k+4]*x,O=P[k+3]*x,H=P[k+5]*h,V=P[k+7]*x,$=P[k+6]*x,A=P[k+8]*h,y=no(D,g,o,{basis:C.__polycssSolidTriangleBasis,matrixDecimals:u,primitive:v,color:t.colors?.[g],includeColor:l!=="plan-only"&&l!=="transform-only"&&it(C,g,i,c,s.stableTriangleColorPolicy,d)},z,I,Z,Q,O,H,V,$,A);if(!y){Lt(C);continue}l!=="plan-only"&&(l==="transform-only"?Xt(C,y):Yt(C,y,d))}return!0}function Jt(e,n,t={}){if(e.length!==n.length)return!1;let o=t,r=t.doc??(typeof document<"u"?document:null),s=t.textureLighting??"baked",i=new Set(t.strategies?.disable??[]),c=!i.has("b"),l=!!r&&c&&At(r),u=!!r&&!i.has("i")&&Ut(r),d=!!r&&!i.has("i")&&Tt(r),x=mo(o.seamBleed),h=r?Et(r,{bleed:Hr*x}):{denomEps:fa,maxWeightRatio:ha,bleed:Hr*x,disableGuards:!1},b=o.optimizeStableTriangleStyle===!0&&s==="baked",v=o.stableTriangleDebug,P=o.stableTriangleUpdateMode??(v==="plan-only"||v==="transform-only"?v:"full"),g=b&&P==="color-only",C=gn(o),D=Vr(o.stableTriangleMatrixDecimals),k=r?ze(r,t.strategies)??"border":"border";if(co(e,n,t,b,P,C))return!0;let z=[],I=[],Z=[];for(let O=0;O<e.length;O++){let H=e[O];if(H.polygonIndex!==O)return!1;let V=n[O];if(!V||g&&H.kind!=="triangle")return!1;if(H.kind==="atlas"){if(!H.plan||!wr(H.element,H.plan,V,s))return!1;continue}if(H.kind==="triangle"){let $=H.element;if(g){let y=o.stableTriangleColorPolicy==="adaptive"||it($,O,b,v,o.stableTriangleColorPolicy,C);I[O]=y?ya(V,O,t):null;continue}let A=st(V,O,t,{basis:$.__polycssSolidTriangleBasis,matrixDecimals:D,primitive:k,includeColor:P!=="plan-only"&&P!=="transform-only"&&it($,O,b,v,o.stableTriangleColorPolicy,C)});if(!A){z[O]=null;continue}z[O]=A;continue}if(H.kind==="solid"){if(!H.plan||V.texture||V.vertices.length!==H.plan.polygon.vertices.length)return!1;Z[O]=H.plan;continue}if(H.kind==="border"){let $=qt(V,O,t,h);if(!$||$.texture||!d||c&&Ve($)||l&&Be($)||u&&Zt($))return!1;Z[O]=$;continue}if(H.kind==="corner"){let $=qt(V,O,t,h);if(!$||$.texture||!u||Ke($)||c&&Ve($)||l&&Be($)||!Zt($))return!1;Z[O]=$;continue}return!1}let Q=b&&P!=="plan-only"&&P!=="transform-only"?lo(e,g?I:z,o):null;for(let O=0;O<e.length;O++){let H=e[O];if(H.kind==="triangle"){if(g){let $=I[O];$&&yn(H.element,$,C,Q?.has(O));continue}let V=z[O];if(!V){Lt(H.element);continue}if(b&&P==="plan-only")continue;b&&P==="transform-only"?Xt(H.element,V):b?Yt(H.element,V,C,Q?.has(O)):Wt(H.element,V)}else if(H.kind==="solid"){let V=Z[O];if(!V||!_r(H.element,V,n[O],s,t,h,o.solidPaintDefaults))return!1}else if(H.kind==="border"){let V=Z[O];if(!V)return!1;Rr(H.element,V,s,o.solidPaintDefaults)}else if(H.kind==="corner"){let V=Z[O],$=V?Zt(V):null;if(!V||!$)return!1;kr(H.element,V,$,s,o.solidPaintDefaults)}}return!0}import{computeTextureAtlasPlanPublic as Gr}from"@layoutit/polycss-core";import{formatMatrix3d as jr,formatCssLengthPx as Wr,formatSolidQuadEntryMatrix as Yr}from"@layoutit/polycss-core";import{formatBorderShapeEntryMatrix as Xr,cssBorderShapeForPlan as Zr}from"@layoutit/polycss-core";import{BASE_TILE as Pe,computeProjectiveQuadMatrix as xa,normalFacesCamera as Pa,parsePureColor as ts,PROJECTIVE_QUAD_BLEED as Sa,resolveProjectiveQuadGuards as Ca,rotateVec3 as Ea,rotateVec3InWrapperCssFrame as Ta,shadePolygon as Aa,SOLID_QUAD_CANONICAL_SIZE as wa}from"@layoutit/polycss-core";var Ma=[.4,-.7,.59],La="#ffffff",_a=1,Ra="#ffffff",ka=.4,ns=1,Oa=8,Da=Sa,Je=1e-6,Ia=Ca({bleed:0}),os={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},yo=["t","b","bl","br","fr","fl"],Ha=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 qr(e){let n=[];for(let t of yo)Pa(os[t],e)&&n.push(t);return n.join("|")}function Fa(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 Va(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,s=0;for(let c=1;c+1<n.length;c+=1){let l=n[c],u=n[c+1],d=l[1]-t[1],x=l[0]-t[0],h=l[2]-t[2],b=u[1]-t[1],v=u[0]-t[0],P=u[2]-t[2];o-=x*P-h*v,r-=h*b-d*P,s-=d*v-x*b}let i=Math.hypot(o,r,s);return i<=1e-9?null:[Math.round(o/i),Math.round(r/i),Math.round(s/i)]}function Ba(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=Va(e),t=n?Ha.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,s=1/0,i=-1/0,c=-1/0,l=-1/0;for(let x of e.vertices)o=Math.min(o,x[0]),r=Math.min(r,x[1]),s=Math.min(s,x[2]),i=Math.max(i,x[0]),c=Math.max(c,x[1]),l=Math.max(l,x[2]);let u=1e-6,d=Wa(e.color);return Math.abs(l-s)<=u?{axis:"z",face:t,left:r*Pe,top:o*Pe,width:Math.max(0,(c-r)*Pe),height:Math.max(0,(i-o)*Pe),z:s*Pe,baseColor:d,bleed:ho()}:Math.abs(i-o)<=u?{axis:"x",face:t,left:r*Pe,top:s*Pe,width:Math.max(0,(c-r)*Pe),height:Math.max(0,(l-s)*Pe),z:-o*Pe,baseColor:d,bleed:ho()}:Math.abs(c-r)<=u?{axis:"y",face:t,left:s*Pe,top:o*Pe,width:Math.max(0,(l-s)*Pe),height:Math.max(0,(i-o)*Pe),z:-r*Pe,baseColor:d,bleed:ho()}:null}function ho(){return{left:0,right:0,top:0,bottom:0}}function za(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 Qr(e){return[e[1]*Pe,e[0]*Pe,e[2]*Pe]}function Kr(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function Na(e,n,t){let o=e.left,r=e.left+e.width,s=e.top,i=e.top+e.height;if(Math.abs(n[0]-t[0])<=Je){if(Math.abs(n[0]-o)<=Je)return"left";if(Math.abs(n[0]-r)<=Je)return"right"}if(Math.abs(n[1]-t[1])<=Je){if(Math.abs(n[1]-s)<=Je)return"top";if(Math.abs(n[1]-i)<=Je)return"bottom"}return null}function $a(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=Je)){if(t!==null)return null;t=o}return t}function Ua(e,n,t){let o=n.vertices,r=Qr(o[t]),s=Qr(o[(t+1)%o.length]),i=Na(e,Kr(e,r),Kr(e,s));if(!i)return null;let c=$a(r,s);if(c===null)return null;let l=Math.min(r[c],s[c]),u=Math.max(r[c],s[c]);return u-l>Je?{item:e,side:i,variableAxis:c,fixed:r,start:l,end:u}:null}function Jr(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],Da)}function Ga(e,n){let t=new Map;for(let o of n){let r=e[o.sourceIndex];if(r)for(let s=0;s<r.vertices.length;s+=1){let i=Ua(o,r,s);if(!i)continue;let c=za(i),l=t.get(c);l?l.push(i):t.set(c,[i])}}for(let o of t.values()){if(o.length<2)continue;o.sort((s,i)=>s.start-i.start||s.end-i.end);let r=[];for(let s of o){r=r.filter(i=>i.end>s.start+Je);for(let i of r)i.item.sourceIndex!==s.item.sourceIndex&&(Jr(i),Jr(s));r.push(s)}}}function ja(e){let n=ts(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 Wa(e){if(!e)return"#cccccc";let n=ts(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(${go(t.r)}, ${go(t.g)}, ${go(t.b)}, ${o})`}return Ya(t)}function Ya({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function go(e){return Math.round(Math.max(0,Math.min(255,e)))}function Xa(e,n,t,o){let r=t?.direction??Ma,s=Math.hypot(r[0],r[1],r[2])||1,i=r[0]/s,c=r[1]/s,l=r[2]/s,u=Math.max(0,t?.intensity??_a)*Math.max(0,e[0]*i+e[1]*c+e[2]*l),d=Math.max(0,o?.intensity??ka),x=t?.color??La,h=o?.color??Ra,b=Aa(n,u,x,h,d),v=ja(n);if(v.alpha>=1)return b;let P=parseInt(b.slice(1,3),16),g=parseInt(b.slice(3,5),16),C=parseInt(b.slice(5,7),16);return`rgba(${P}, ${g}, ${C}, ${v.alpha})`}function Za(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=Ba(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return Ga(e,n),n}function qa(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 Qa(e){let n=e.left,t=e.top,o=e.left+e.width,r=e.top+e.height;return[n,t,o,t,o,r,n,r]}function Ka(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function Ja(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(r=>!Number.isFinite(r)))return null;let o=wa/n;for(let r=0;r<8;r+=1)t[r]*=o;return`matrix3d(${t.map(r=>Number(r.toFixed(6))).join(",")})`}function es(e,n){let t=e.left-e.bleed.left,o=e.top-e.bleed.top,r=e.width+e.bleed.left+e.bleed.right,s=e.height+e.bleed.top+e.bleed.bottom,i=e.z,c=r/n,l=s/n;return`matrix3d(${(e.axis==="x"?[c,0,0,0,0,0,l,0,0,-1,0,0,t,-i,o,1]:e.axis==="y"?[0,0,c,0,0,l,0,0,-1,0,0,0,-i,o,t,1]:[c,0,0,0,0,l,0,0,0,0,1,0,t,o,i,1]).map(d=>Number(d.toFixed(6))).join(",")})`}function el(e,n){let{xAxis:t,yAxis:o,normal:r,tx:s,ty:i,tz:c}=qa(e),l=xa(Qa(e),t,o,r,s,i,c,Ia,Ka(e));return l?Ja(l,n)??es(e,n):es(e,n)}function tl(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function nl(e){return tl(e)?Oa:ns}function ol(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 rl(e,n){let t=ol(e),o=n.meshRotation;o&&(t=Ta(t,o));let[r,s]=Ea(t,n.rotX,0,n.rotY);return{x:r,y:s}}function sl(e,n,t){let o=e.filter(h=>n.has(h.face)).map(h=>({item:h,...rl(h,t)}));if(o.length===0)return[];let r=1/0,s=-1/0,i=1/0,c=-1/0;for(let h of o)r=Math.min(r,h.x),s=Math.max(s,h.x),i=Math.min(i,h.y),c=Math.max(c,h.y);let l=4,u=Math.max(1e-6,s-r),d=Math.max(1e-6,c-i),x=new Map;for(let h of o){let b=Math.min(l-1,Math.max(0,Math.floor((h.x-r)/u*l))),v=Math.min(l-1,Math.max(0,Math.floor((h.y-i)/d*l))),P=`${b}:${v}`,g=x.get(P);g||(g={tx:b,ty:v,sourceIndex:h.item.sourceIndex,items:[]},x.set(P,g)),g.items.push(h.item),g.sourceIndex=Math.min(g.sourceIndex,h.item.sourceIndex)}return Array.from(x.values()).sort((h,b)=>h.ty-b.ty||h.tx-b.tx||h.sourceIndex-b.sourceIndex).flatMap(h=>h.items)}function rs(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:s}=e,i=Za(o);if(i.length===0)return null;let c=new Set(i.map(y=>y.face));t.classList.add("polycss-voxel-mesh");let l=nl(n);l!==ns&&t.style.setProperty("--polycss-voxel-primitive",`${l}px`);let u=new Map,d=(y,m)=>{let p=`${y}|${m}`,T=u.get(p);if(T)return T;let M=Xa(os[y],m,r,s);return u.set(p,M),M},x=new Map,h=new Map,b=new Map,v=new Map;for(let y of i){let m=v.get(y.face);m||(m=[],v.set(y.face,m)),m.push(y)}let P="",g=0,C=new Set,D=y=>{let m=x.get(y.sourceIndex);return m||(m=n.createElement("b"),x.set(y.sourceIndex,m),Fa(m,d(y.face,y.baseColor),el(y,l))),m},k=y=>{let m=h.get(y);return m||(m=n.createElement("span"),m.className=`polycss-voxel-face polycss-voxel-face-${y}`,m.dataset.polycssVoxelFace=y,m.__polycssVoxelFaceHost=!0,h.set(y,m)),m},z=()=>{for(let y of Array.from(t.childNodes))if(!y.__polycssVoxelFaceHost)return y;return null},I=(y,m)=>{let p=m.map(R=>R.sourceIndex).join(",");if(b.get(y)===p)return;let T=k(y),M=n.createDocumentFragment();for(let R of m)M.appendChild(D(R));T.replaceChildren(M),b.set(y,p)},Z=()=>{for(let y of yo)c.has(y)&&I(y,v.get(y)??[])},Q=y=>new Set(y.split("|").filter(Boolean)),O=y=>{let m=Q(y);return yo.filter(p=>m.has(p)&&c.has(p))},H=y=>{let m=0;for(let p of y)m+=v.get(p)?.length??0;return m},V=y=>{let m=new Set,p=[],T=new Map;for(let M of y){m.has(M.face)||(m.add(M.face),p.push(M.face));let R=T.get(M.face);R||(R=[],T.set(M.face,R)),R.push(M)}return{orderedFaces:p,itemsByFace:T}},$=(y,m)=>{let p=new Set(y);for(let T of C){if(p.has(T))continue;let M=h.get(T);M?.parentNode===t&&t.removeChild(M)}if(m){let T=n.createDocumentFragment();for(let M of y)T.appendChild(k(M));t.insertBefore(T,z()),C=p;return}for(let T=0;T<y.length;T+=1){let M=y[T],R=k(M);if(R.parentNode===t)continue;let L=null;for(let te=T+1;te<y.length;te+=1){let _=h.get(y[te]);if(_?.parentNode===t){L=_;break}}t.insertBefore(R,L??z())}C=p},A=(y,m,p)=>{if(!p){let te=O(y);$(te,!1),g=H(te);return}let T=new Set(y.split("|").filter(Boolean)),M=sl(i,T,m),{orderedFaces:R,itemsByFace:L}=V(M);for(let te of R)I(te,L.get(te)??[]);$(R,!0),g=M.length};return Z(),{get brushCount(){return g},render(y){P=qr(y),A(P,y,!0)},syncCamera(y){let m=qr(y);m!==P&&(P=m,A(m,y,!1))},dispose(){for(let y of h.values())y.remove();t.classList.remove("polycss-voxel-mesh"),t.style.removeProperty("--polycss-voxel-primitive"),x.clear(),h.clear(),b.clear(),g=0,C=new Set,P=""}}}var ss="polycss-styles";function bo(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(ss))return;let t=n.createElement("style");t.id=ss,t.textContent=il,n.head.appendChild(t)}var il=`
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,7 +516,7 @@ import{CAMERA_BACKFACE_CULL_EPS as Eo,DEFAULT_SEAM_BLEED as zs,VOXEL_CAMERA_CULL
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
- `;import{BASE_TILE as al}from"@layoutit/polycss-core";var ll=1,Ne=al,cl=.1;function ul(e){return[e[1]*Ne,e[0]*Ne,e[2]*Ne]}function Rt(e){return[e[1],e[0],e[2]]}function at(e){return e?.direction?{...e,direction:Rt(e.direction)}:e}function vn(e){let n=typeof e.scale=="number"?e.scale:e.scale?.[0]??1,t=typeof e.scale=="number"?e.scale:e.scale?.[1]??1,o=typeof e.scale=="number"?e.scale:e.scale?.[2]??1,r=n!==1||t!==1||o!==1,s=!!e.rotation&&(!!e.rotation[0]||!!e.rotation[1]||!!e.rotation[2]),i=e.position?ul(e.position):[0,0,0],c=[];return(i[0]!==0||i[1]!==0||i[2]!==0)&&c.push(`translate3d(${i[0]}px, ${i[1]}px, ${i[2]}px)`),s&&(e.rotation[0]&&c.push(`rotateY(${-e.rotation[0]}deg)`),e.rotation[1]&&c.push(`rotateX(${-e.rotation[1]}deg)`),e.rotation[2]&&c.push(`rotateZ(${-e.rotation[2]}deg)`)),r&&c.push(`scale3d(${n}, ${t}, ${o})`),c.length>0?c.join(" "):void 0}function vo(e,n=[0,0,0],t=1){let o=e.state,r=o.rotX,s=o.rotY,c=(o.zoom??ll)/Ne*t,l=(o.distance??0)*t,u=o.target??[0,0,0],d=u[0]+n[0],x=u[1]+n[1],h=u[2]+n[2],b=x*Ne,v=d*Ne,P=h*Ne;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${r}deg) rotate(${s}deg) translate3d(${-b}px, ${-v}px, ${-P}px)`}function dl(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 is(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=dl(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function as(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}function ls(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let x=1;x+1<e.vertices.length;x++){let h=e.vertices[x],b=e.vertices[x+1],v=h[1]-n[1],P=h[0]-n[0],g=h[2]-n[2],C=b[1]-n[1],D=b[0]-n[0],k=b[2]-n[2];t-=P*k-g*D,o-=g*C-v*k,r-=v*D-P*C}let s=Math.hypot(t,o,r);if(s<1e-9)return null;t/=s,o/=s,r/=s;let i=1/cl,c=Math.round(t*i)/i,l=Math.round(o*i)/i,u=Math.round(r*i)/i,d=Math.hypot(c,l,u);return d<1e-9?null:{key:c+","+l+","+u,vec:[c/d,l/d,u/d]}}function cs(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let r of t)if(!o.includes(r))return!1;return!0}function us(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function ds(e,n){return e===n?!0:(e?.color??"#000000")===(n?.color??"#000000")&&(e?.opacity??.25)===(n?.opacity??.25)&&(e?.lift??.05)===(n?.lift??.05)&&(e?.maxExtend??2e3)===(n?.maxExtend??2e3)}import{parseHex as fs,parseHexColor as ps,parsePureColor as pl}from"@layoutit/polycss-core";var ml=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"],kt="--polycss-light-preview-active",ms=`var(${kt}, 0)`,fl="max(0, calc(var(--pnx, 0) * var(--plx, 0) + var(--pny, 0) * var(--ply, 0) + var(--pnz, 1) * var(--plz, 1)))",xo=(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))`,hl=xo("--psr","--par","--plr"),gl=xo("--psg","--pag","--plg"),yl=xo("--psb","--pab","--plb");function ue(e,n,t){return e.style.getPropertyValue(n)===t?!1:(e.style.setProperty(n,t),!0)}function mt(e){for(let n of ml)e.style.getPropertyValue(n)&&e.style.removeProperty(n)}function xn(e,n){let t=n.directionalLight?.direction??[.4,-.7,.59],o=Rt(t),r=Math.hypot(o[0],o[1],o[2])||1,s=o[0]/r,i=o[1]/r,c=o[2]/r,l=ps(n.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],u=ps(n.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],d=n.directionalLight?.intensity??1,x=n.ambientLight?.intensity??.4,h=P=>(P/255).toFixed(4);ue(e,"--plx",s.toFixed(2)),ue(e,"--ply",i.toFixed(2)),ue(e,"--plz",c.toFixed(2)),ue(e,"--plr",h(l[0])),ue(e,"--plg",h(l[1])),ue(e,"--plb",h(l[2])),ue(e,"--pli",d.toFixed(4)),ue(e,"--par",h(u[0])),ue(e,"--pag",h(u[1])),ue(e,"--pab",h(u[2])),ue(e,"--pai",x.toFixed(4));let b=c,v=Math.sign(b||1)*Math.max(Math.abs(b),.01);ue(e,"--clx",s.toFixed(2)),ue(e,"--cly",i.toFixed(2)),ue(e,"--clz",v.toFixed(2))}function hs(e,n){let t=n.textureLighting==="dynamic";if(e.dataset.polycssLighting=n.textureLighting??"baked",!t){mt(e);return}xn(e,n)}function ft(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 gs(e,n){let t=fs(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 Po(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=t.textureLighting??"baked",r={directionalLight:at(t.directionalLight),ambientLight:t.ambientLight,textureLighting:o,textureQuality:t.textureQuality,seamBleed:t.seamBleed,strategies:t.strategies},s=qn(e.plan,n,e.plan.normal,o,r);return wt(e.element,s,o),o==="baked"&&vl(e.element),!0}function bl(e){let n=pl(e)??{rgb:[255,255,255],alpha:1},[t,o,r]=n.rgb,s=(c,l)=>`calc(${c} * (1 - ${ms}) + var(${l}, ${c}) * ${ms})`,i=n.alpha<1?` / ${n.alpha}`:"";return`rgb(${s(t,"--polycss-preview-r")} ${s(o,"--polycss-preview-g")} ${s(r,"--polycss-preview-b")}${i})`}function ys(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=e.element,r=e.plan.normal,s=fs(n.color??"#cccccc"),i=!1;return i=ue(o,"--pnx",r[0].toFixed(4))||i,i=ue(o,"--pny",r[1].toFixed(4))||i,i=ue(o,"--pnz",r[2].toFixed(4))||i,i=ue(o,"--psr",(s.r/255).toFixed(4))||i,i=ue(o,"--psg",(s.g/255).toFixed(4))||i,i=ue(o,"--psb",(s.b/255).toFixed(4))||i,i=ue(o,"--plam",fl)||i,i=ue(o,"--polycss-preview-r",hl)||i,i=ue(o,"--polycss-preview-g",gl)||i,i=ue(o,"--polycss-preview-b",yl)||i,i=ue(o,"--polycss-paint",bl(t))||i,o.style.getPropertyValue("color")&&(o.style.removeProperty("color"),i=!0),i}function vl(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 xl="http://www.w3.org/2000/svg",Pn=class{constructor(){this.groundSvg=null;this.groundVisible=!1;this.currentGroundCssZ=null;this.shadowRoot=null}};function bs(e,n,t){let o=e.shadowRoot;if(o||(o=n.createElement("div"),o.setAttribute("class","polycss-shadows"),o.style.position="absolute",o.style.top="0",o.style.left="0",o.style.width="0",o.style.height="0",o.style.transformStyle="preserve-3d",o.style.pointerEvents="none",e.shadowRoot=o),o.parentNode!==t){let r=t.firstChild;r?t.insertBefore(o,r):t.appendChild(o)}return o}function vs(e){e.groundSvg?.parentNode&&e.groundSvg.parentNode.removeChild(e.groundSvg),e.groundSvg=null,e.groundVisible=!1}function xs(e){e.groundSvg&&e.groundVisible&&(e.groundSvg.style.display="none",e.groundVisible=!1)}function Ps(e,n,t,o){let r=[],s=e.firstChild;for(let i=0;i<t;i++){let c=s;c&&c.tagName==="path"?s=c.nextSibling:(c=n.createElementNS(xl,"path"),c.setAttribute("fill-rule","nonzero"),o&&(c.setAttribute("stroke-width","0.5"),c.setAttribute("stroke-linejoin","round")),e.insertBefore(c,s)),r.push(c)}for(;s;){let i=s.nextSibling;e.removeChild(s),s=i}return r}function Ss(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 Pn,receiverShadowCache:new Map,receiverShadowCacheKey:new Map,casterItemsCache:new Map,casterItemsCacheKey:new Map}}import{buildSharedEdgeMap as Pl,computeReceiverShadowFaces as Sl,meshScaleVec3 as Ms,prepareCasterEdgeOwners as Cl,prepareCasterPolyItems as El,prepareReceiverFacePlanes as Tl}from"@layoutit/polycss-core";function Cs(e){for(let n of e)n.svg&&n.svg.parentNode&&n.svg.parentNode.removeChild(n.svg),n.svg=null}function Es(e,n){if(n){let t=e.receiverShadowCache.get(n);t&&Cs(t),e.receiverShadowCache.delete(n),e.receiverShadowCacheKey.delete(n)}else{for(let t of e.receiverShadowCache.values())Cs(t);e.receiverShadowCache.clear(),e.receiverShadowCacheKey.clear()}}function Ts(e,n){n?(e.casterItemsCache.delete(n),e.casterItemsCacheKey.delete(n)):(e.casterItemsCache.clear(),e.casterItemsCacheKey.clear())}function As(e){vs(e.shadowSvgState),ws(e)}function So(e){return e.handle.id??e.autoMeshId}var Al="http://www.w3.org/2000/svg",Sn=new WeakMap,Ls=new WeakMap,_s=new WeakMap,Rs=new WeakMap,ks=new WeakMap;function Os(e){let n=Sn.get(e);return n||(n=new Map,Sn.set(e,n)),n}function Co(e){let n=Sn.get(e);if(n){for(let t of n.values())t.svg&&t.svg.parentNode&&t.svg.parentNode.removeChild(t.svg);n.clear(),Sn.delete(e)}}function ws(e){for(let n of e.meshes)Co(n)}function Ds(e,n,t,o,r,s,i,c,l,u){let d=e.options.current,{receiverShadowCache:x,receiverShadowCacheKey:h,casterItemsCache:b,casterItemsCacheKey:v}=e,P=o.handle.transform.position??[0,0,0],g=o.handle.transform.rotation??[0,0,0],C=o.polygons.some(A=>A.texture!==void 0),D=Ms(o.handle.transform.scale),k=o.bboxCenterCss,z=d.shadow?.lift??.001,I=`${o.polygons.length}|${r.size}|${P.join(",")}|${g.join(",")}|${D.join(",")}|${k?k.join(","):"n"}|${z}`,Z=x.get(o);if(Z===void 0||h.get(o)!==I){Z=Tl(o.polygons,P,o.handle.transform.scale,r,z,g),x.set(o,Z),h.set(o,I);let A=Os(o);for(let y of A.values())y.svg&&y.svg.parentNode&&y.svg.parentNode.removeChild(y.svg);A.clear()}let Q=[];for(let A of n){let y=A.handle.transform.position??[0,0,0],m=A.handle.transform.rotation??[0,0,0],p=Ms(A.handle.transform.scale),T=A.bboxCenterCss,M=`${A.polygons.length}|${y.join(",")}|${m.join(",")}|${p.join(",")}|${T?T.join(","):"n"}`,R=b.get(A);if(R===void 0||v.get(A)!==M){let _=t.get(A),j=new Set;for(let q of A.rendered)q.plan&&!_.has(q.polygonIndex)&&j.add(q.polygonIndex);R=El(A.polygons,y,A.handle.transform.scale,q=>j.has(q),m),b.set(A,R),v.set(A,M)}let L;if(A===o){let _=Ls.get(A);(_===void 0||_s.get(A)!==A.polygons)&&(_=Pl(A.polygons),Ls.set(A,_),_s.set(A,A.polygons)),L=_}let te;if(A!==o&&A.polygons.length>=40){let _=Rs.get(A);(_===void 0||ks.get(A)!==M)&&(_=Cl(A.polygons,y,A.handle.transform.scale,m),Rs.set(A,_),ks.set(A,M)),te=_}Q.push({id:A,items:R,selfShadowEdgeMap:L,edgeOwners:te,casterPolygonCount:A.polygons.length})}let O={rotX:e.camera.state.rotX,rotY:e.camera.state.rotY,meshRotation:o.handle.transform.rotation},H=Sl({receiverPlanes:Z,receiverPolygons:o.polygons,receiverHasTexture:C,casters:Q,lightDir:s,cameraRot:O,ambientLight:d.ambientLight,directionalLight:d.directionalLight,shadow:{color:d.shadow?.color,opacity:u,maxExtend:d.shadow?.maxExtend}}),V=Os(o),$=new Set;for(let A of H){$.add(A.faceIndex);let y=V.get(A.faceIndex);y||(y={svg:null,visible:!1,width:-1,height:-1,matrixCss:""},V.set(A.faceIndex,y));let m=y.svg;m?(y.visible||(m.style.display="block"),(y.width!==A.width||y.height!==A.height)&&(m.setAttribute("width",String(A.width)),m.setAttribute("height",String(A.height)),m.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),y.width=A.width,y.height=A.height),y.matrixCss!==A.matrixCss&&(m.style.transform=A.matrixCss,y.matrixCss=A.matrixCss)):(m=e.doc.createElementNS(Al,"svg"),m.setAttribute("class","polycss-shadow polycss-shadow-svg polycss-shadow-receiver"),d.debugShadowAttrs&&(m.setAttribute("data-poly-shadow-type","receiver"),m.setAttribute("data-poly-shadow-receiver",So(o)),m.setAttribute("data-poly-shadow-receiver-face",String(A.faceIndex)),m.setAttribute("data-poly-shadow-receiver-polys",JSON.stringify(A.memberPolyIndices))),m.setAttribute("width",String(A.width)),m.setAttribute("height",String(A.height)),m.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),m.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}`),bs(e.shadowSvgState,e.doc,e.sceneEl).appendChild(m),y.svg=m,y.width=A.width,y.height=A.height,y.matrixCss=A.matrixCss),y.visible=!0;let p=Ps(m,e.doc,A.paths.length,!0),T=A.opacity.toFixed(4),M=[],R=!!d.debugShadowAttrs;for(let L=0;L<A.paths.length;L++){let te=A.paths[L],_=R?So(te.casterId):"";R&&M.push(_);let j=p[L];if(j.setAttribute("d",te.d),j.getAttribute("fill")!==A.fill&&j.setAttribute("fill",A.fill),j.getAttribute("stroke")!==A.fill&&j.setAttribute("stroke",A.fill),j.getAttribute("opacity")!==T&&j.setAttribute("opacity",T),R){j.getAttribute("data-poly-shadow-caster")!==_&&j.setAttribute("data-poly-shadow-caster",_);let q=JSON.stringify(te.casterPolygonIndices);j.getAttribute("data-poly-shadow-caster-polys")!==q&&j.setAttribute("data-poly-shadow-caster-polys",q)}}if(R){let L=M.join(" ");m.getAttribute("data-poly-shadow-casters")!==L&&m.setAttribute("data-poly-shadow-casters",L)}}for(let[A,y]of V)$.has(A)||y.svg&&y.visible&&(y.svg.style.display="none",y.visible=!1)}var Is=Symbol.for("polycss.animation.triangleFrameTarget");var Fl=750;function Vs(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:zs}}var Vl={key:"non-cullable",normal:[1,1,0]};function Bs(){return[Vl]}function Ao(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&&bo(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...r}=n,s=Vs({seamBleed:zs,...r}),i=is(e),c=[0,0,0],l=e.ownerDocument??document,u=l.createElement("div");u.className="polycss-camera",Z(u,s),e.appendChild(u);let d=l.createElement("div");d.className="polycss-scene",d.setAttribute("aria-hidden","true"),Q(d,s),u.appendChild(d);let x=Ss({host:e,doc:l,cameraEl:u,sceneEl:d,camera:t,layoutScale:i,options:s}),h=x.meshes,b=new WeakMap,v=x.shadowSvgState,P=()=>xs(v),g=()=>As(x),C=null;function D(a){if(!a)return null;let f=Math.hypot(a[0],a[1],a[2]);if(!Number.isFinite(f)||f<=0)return null;let S=Math.round(a[0]/f*100)/100,E=Math.round(a[1]/f*100)/100,W=Math.round(a[2]/f*100)/100;return`${S}|${E}|${W}`}function k(){C=null}let z=a=>Es(x,a),I=a=>Ts(x,a);function Z(a,f){let S=t.perspectiveStyle;if(S==="none")a.style.perspective="1000000px";else{let E=parseFloat(S);Number.isFinite(E)&&(a.style.perspective=`${E}px`)}}function Q(a,f){as(a,i),a.style.transform=vo(t,c,i),hs(a,f)}function O(a){a.style.transform=vo(t,c,i)}function H(a){a.voxelRenderer?.dispose(),a.voxelRenderer=void 0,y(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 f of Array.from(a.wrapper.children))f instanceof HTMLElement&&f.classList.contains("polycss-bucket")&&f.remove();a.hasBuckets=!1}function V(a){for(let f of Array.from(a.wrapper.childNodes)){if(!(f instanceof HTMLElement))return f;if(f.classList.contains("polycss-bucket")||f.classList.contains("polycss-shadow"))continue;let S=f.tagName.toLowerCase();if(!(S==="b"||S==="i"||S==="s"||S==="u"||S==="q"))return f}return null}function $(a,f,S){S?.parentNode===a.wrapper?a.wrapper.insertBefore(f,S):a.wrapper.appendChild(f)}function A(a){for(let f of a.shadowRendered)f.parentNode&&f.parentNode.removeChild(f);a.shadowRendered.length=0,g()}function y(a,f){f?.();for(let S of a){try{S.dispose()}catch{}S.element.parentNode&&S.element.parentNode.removeChild(S.element)}}function m(a,f,S){a.rendered=f,a.renderedByPolygonIndex=[];for(let E of f)a.renderedByPolygonIndex[E.polygonIndex]=E;a.disposeAtlas=S,a.solidLightingPreviewPrepared=!1}function p(a,f){let S=a.renderedByPolygonIndex[f];return S?.polygonIndex===f?S:void 0}function T(a){for(let f of Array.from(a.wrapper.children))f instanceof HTMLElement&&f.classList.contains("polycss-bucket")&&f.remove();a.hasBuckets=!1;for(let f of a.rendered)f.element.parentNode&&f.element.parentNode.removeChild(f.element)}function M(a,f){let S=a.polygons[f.polygonIndex];return a.stableDom&&S?Fs(S):f.plan?.normal??(S?Fs(S):null)}function R(a){if(!q(a))return a.rendered;let f=L(a);return a.rendered.filter(S=>te(a,S,Eo,f))}function L(a){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:a.handle.transform.rotation}}function te(a,f,S=Eo,E=L(a)){let W=M(a,f);return W===null||Dl(W,E,S)}function _(a){if(a.excludeFromAutoCenter){a.cameraCullGroups=[];return}let f=new Map;for(let S of a.rendered){let E=M(a,S);if(!E)continue;if(!kl(E)){a.cameraCullGroups=Bs();return}let W=Ml(E);if(!f.has(W)&&(f.set(W,E),f.size>wl)){a.cameraCullGroups=Bs();return}}a.cameraCullGroups=Array.from(f,([S,E])=>({key:S,normal:E}))}function j(a){return q(a)?Ll(a.cameraCullGroups,L(a)):"all"}function q(a){return!a.excludeFromAutoCenter&&Ol(a.cameraCullGroups)}function re(a){a.cameraCullSignature=q(a)?j(a):"all"}function fe(a,f){let S=new Array(a.rendered.length),E=!1,W=L(a);for(let K=0;K<a.rendered.length;K+=1){let oe=a.rendered[K],J=te(a,oe,f,W);S[K]=J}let B=null,F=null,G=()=>{if(!(!B||!F)){if(B===F)B.remove();else{let K=l.createRange();K.setStartBefore(B),K.setEndAfter(F),K.deleteContents(),K.detach()}B=null,F=null,E=!0}};for(let K=0;K<a.rendered.length;K+=1){let oe=a.rendered[K];!S[K]&&oe.element.parentNode===a.wrapper?(F&&F.nextSibling===oe.element||(G(),B=oe.element),F=oe.element):G()}G();let Y=K=>{for(let oe=K;oe<a.rendered.length;oe+=1){let J=a.rendered[oe].element;if(J.parentNode===a.wrapper)return J}return V(a)},ae=-1,ne=K=>{if(ae<0)return;let oe=l.createDocumentFragment();for(let J=ae;J<K;J+=1){let Ie=a.rendered[J];be(a,Ie),oe.appendChild(Ie.element)}$(a,oe,Y(K)),ae=-1,E=!0};for(let K=0;K<a.rendered.length;K+=1){let oe=a.rendered[K];S[K]&&oe.element.parentNode!==a.wrapper?ae<0&&(ae=K):ne(K)}return ne(a.rendered.length),E}function de(a,f=!1){if(a.voxelRenderer){f?a.voxelRenderer.render(L(a)):a.voxelRenderer.syncCamera(L(a)),a.cameraCullSignature="voxel-direct";return}if(!q(a)){let W=a.cameraCullSignature!=="all";a.cameraCullSignature="all",W&&ve(a);return}if(a.hasBuckets){pe(a,f);return}let S=j(a);if(!f&&S===a.cameraCullSignature)return;let E=fe(a,Eo);a.cameraCullSignature=S,E&&Ge(a)}function pe(a,f=!1){let S=q(a)?j(a):"all";!f&&S===a.cameraCullSignature||ve(a)}function Ce(a,f){return M(a,f)}function be(a,f){if(s.textureLighting!=="dynamic")return;let S=Ce(a,f);S&&(f.element.style.setProperty("--pnx",S[0].toFixed(4)),f.element.style.setProperty("--pny",S[1].toFixed(4)),f.element.style.setProperty("--pnz",S[2].toFixed(4)))}function Ae(a){T(a),a.hasBuckets=!1;let f=a.skipBucketNormalCleanupOnce;a.skipBucketNormalCleanupOnce=!1;let S=l.createDocumentFragment(),E=s.textureLighting==="dynamic"&&!a.stableDom,W=new Map,B=[];for(let F of R(a)){let G=a.polygons[F.polygonIndex],Y=E&&G?ls(G):null;if(!Y){B.push(F);continue}let ae=Y.key+"|"+(G.color??""),ne=W.get(ae);ne||(ne={vec:Y.vec,items:[]},W.set(ae,ne)),ne.items.push(F)}for(let F of B)be(a,F),S.appendChild(F.element);for(let F of W.values()){if(F.items.length<2){for(let Y of F.items)be(a,Y),S.appendChild(Y.element);continue}let G=l.createElement("div");G.className="polycss-bucket",a.hasBuckets=!0,G.style.setProperty("--pnx",String(F.vec[0])),G.style.setProperty("--pny",String(F.vec[1])),G.style.setProperty("--pnz",String(F.vec[2]));for(let Y of F.items)G.appendChild(Y.element),(!f||Y.kind==="triangle")&&(Y.element.style.removeProperty("--pnx"),Y.element.style.removeProperty("--pny"),Y.element.style.removeProperty("--pnz"));S.appendChild(G)}$(a,S,V(a)),re(a)}function Ue(){return new Promise(a=>setTimeout(a,0))}async function Qe(a,f){if(s.textureLighting==="dynamic"&&!a.stableDom)return Ae(a),!f();T(a);let E=l.createDocumentFragment(),W=V(a),B=0;for(let F of R(a)){if(f())return!1;be(a,F),E.appendChild(F.element),B++,B%Fl===0&&($(a,E,W),E=l.createDocumentFragment(),await Ue())}return E.childNodes.length>0&&$(a,E,W),re(a),!f()}function lt(a,f){let S=s.textureLighting==="dynamic",E=s.directionalLight?.direction,W=f&&(f[0]!==0||f[1]!==0||f[2]!==0);if(!S||!W||!E){if(a.lightOverrideSignature==="clear")return;a.wrapper.style.removeProperty("--plx"),a.wrapper.style.removeProperty("--ply"),a.wrapper.style.removeProperty("--plz"),a.lightOverrideSignature="clear";return}let B=To(E,f),F=Rt(B),G=Math.hypot(F[0],F[1],F[2])||1,Y=(F[0]/G).toFixed(2),ae=(F[1]/G).toFixed(2),ne=(F[2]/G).toFixed(2),K=`${Y}|${ae}|${ne}`;a.lightOverrideSignature!==K&&(a.wrapper.style.setProperty("--plx",Y),a.wrapper.style.setProperty("--ply",ae),a.wrapper.style.setProperty("--plz",ne),a.lightOverrideSignature=K)}function bt(a){let f=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let E=a.polygons[S.polygonIndex];E&&(f=Po(S,E,s)||f)}return a.solidLightingPreviewPrepared=!1,a.solidLightingPreviewActive=!1,f}function ct(a){if((s.textureLighting??"baked")!=="baked")return!1;let f=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let E=a.polygons[S.polygonIndex];E&&(ys(S,E,S.plan.shadedColor),f=!0)}return a.solidLightingPreviewPrepared=f,f}function On(a){return(s.textureLighting??"baked")!=="baked"||!a.solidLightingPreviewPrepared&&!ct(a)?!1:(a.solidLightingPreviewActive=!0,!0)}function Dn(a){return a.kind==="atlas"||!!a.plan?.texture}function In(){if((s.textureLighting??"baked")!=="baked")return!1;let a=!1;for(let f of h)a=bt(f)||a,f.rendered.some(Dn)&&(Nt(f),a=!0);d.style.removeProperty(kt);for(let f of h)mt(f.wrapper),f.solidLightingPreviewActive=!1;return mt(d),a}function Hn(){d.style.removeProperty(kt);for(let a of h)a.solidLightingPreviewActive&&(bt(a),mt(a.wrapper));(s.textureLighting??"baked")!=="dynamic"&&(mt(d),k(),Ee())}function U(a,f){let S=a.handle.transform.rotation,E=f.directionalLight?.direction??s.directionalLight?.direction;if(!(S&&(S[0]!==0||S[1]!==0||S[2]!==0))||!E){mt(a.wrapper);return}let B=To(E,S);xn(a.wrapper,{...s,...f,directionalLight:{...s.directionalLight,...f.directionalLight,direction:B}})}function se(a){if((s.textureLighting??"baked")!=="baked")return!1;xn(d,{...s,...a}),!a.skipShadows&&a.directionalLight?.direction&&Ee(a.directionalLight.direction);let f=!1;for(let S of h)U(S,a),f=On(S)||f;return f?ue(d,kt,"1"):d.style.removeProperty(kt),f}function ie(a,f,S){let E=a.polygons[f];if(!E)return!1;let W=p(a,f);if(!W)return!1;let B=s.textureLighting??"baked";return B==="dynamic"?(gs(W.element,S),!0):B==="baked"?Po(W,E,s):!1}function we(a,f){let S=a.polygons[f];if(!S)return!1;let E=p(a,f);return E?(ye(E.element,S,f),!0):!1}function zt(a,f,S){return!(S.length===0||!S.every(E=>E==="color"||E==="data")||S.includes("color")&&!ie(a,f,a.polygons[f]?.color)||S.includes("data")&&!we(a,f))}function Ge(a){k(),Ee()}function Ee(a){let f=[];for(let J of h)!J.disposed&&J.castShadow&&f.push(J);if(f.length===0){g(),C=null;return}let S=s.shadow?.color??"#000000",E=s.shadow?.opacity??.25,W=Hl(S)?.rgb??[0,0,0],B=W[0],F=W[1],G=W[2],Y=a??s.directionalLight?.direction??[.4,-.7,.59],ae=Rt(Y),ne=D(ae);if(ne!==null&&ne===C)return;let K=new Map;for(let J of f)K.set(J,Hs(J.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.95,preserveDoubleSidedBackfaces:!1}));let oe=new Map;for(let J of h)J.disposed||!J.receiveShadow||oe.set(J,new Set);P();for(let J of h)J.disposed||!J.receiveShadow||Ds(x,f,K,J,oe.get(J)??new Set,ae,B,F,G,E);C=ne}function ve(a){if(a.voxelRenderer){a.voxelRenderer.render(L(a)),a.cameraCullSignature="voxel-direct";return}A(a),Ae(a),Ge(a)}function Oe(a,f){if(!f||!a.polygons||a.polygons.length<2)return;let S=Math.hypot(f[0],f[1],f[2]);if(!Number.isFinite(S)||S<=0)return;let E=f[0]/S,W=f[1]/S,B=f[2]/S,F=K=>Math.round(K*1e3)/1e3,G=`${F(E)},${F(W)},${F(B)}`,Y=a.lightOcclusionCache;if(Y&&Y.polygons===a.polygons&&Y.lightDirKey===G)return Y.occluded;let ae=Y&&Y.polygons===a.polygons?Y.dedupDropped:Hs(a.polygons,{normalTolerance:.1,distanceTolerance:.12,overlapFraction:.98,preserveDoubleSidedBackfaces:!1}),ne=Rl(a.polygons,[E,W,B],ae);return a.lightOcclusionCache={polygons:a.polygons,lightDirKey:G,occluded:ne,dedupDropped:ae},ne}function De(a){return!!a.voxelSource&&s.textureLighting!=="dynamic"&&!a.stableDom&&!a.castShadow}function Se(a,f){H(a);let S=s.directionalLight,E=f?{...S,direction:f}:S,W=at(E),B=void 0;if(De(a)){let Y=rs({doc:l,wrapper:a.wrapper,polygons:a.parseResult.polygons,directionalLight:W,ambientLight:s.ambientLight});if(Y){a.voxelRenderer=Y,Y.render(L(a)),a.cameraCullSignature="voxel-direct";return}}let F={doc:l,directionalLight:W,ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,strategies:s.strategies,lightOccludedPolyIndices:B},G=a.stableDom?(()=>{let Y=dt(a.polygons,F);return ft(a.wrapper,Y),_t(a.polygons,{...F,solidPaintDefaults:Y})??pt(a.polygons,{...F,solidPaintDefaults:Y})})():pt(a.polygons,{...F,computeSolidPaintDefaults:!0,skipDynamicNormalVars:s.textureLighting==="dynamic"});a.stableDom||ft(a.wrapper,G.solidPaintDefaults??{}),m(a,G.rendered,G.dispose),a.skipBucketNormalCleanupOnce=s.textureLighting==="dynamic"&&!a.stableDom,_(a),Ae(a),Ge(a)}function Nt(a,f){if(a.rendered.length===0||a.voxelRenderer||a.stableDom||De(a)){Se(a,f);return}if(a.rendered[0]?.element.parentNode===null){Se(a,f);return}let S=s.directionalLight,E=f?{...S,direction:f}:S,W=at(E),B={doc:l,directionalLight:W,ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,strategies:s.strategies,computeSolidPaintDefaults:!0,skipDynamicNormalVars:s.textureLighting==="dynamic"},F=pt(a.polygons,B),G=()=>{a.rebakeInFlight=!1;let ne=a.rebakeQueuedLightDir;ne!==null&&(a.rebakeQueuedLightDir=null,Nt(a,ne))},Y=()=>{if(a.disposed){F.dispose(),G();return}if(F.rendered.length!==a.rendered.length){F.dispose(),Se(a,f),G();return}for(let oe of F.rendered){let J=a.renderedByPolygonIndex[oe.polygonIndex];if(!J)continue;let Ie=oe.element.getAttribute("style");Ie!==null&&J.element.setAttribute("style",Ie)}let ne=F.solidPaintDefaults;ne&&ft(a.wrapper,ne);let K=a.disposeAtlas;a.disposeAtlas=F.dispose,K&&(typeof requestAnimationFrame=="function"?J=>{requestAnimationFrame(J)}:J=>{setTimeout(J,0)})(K),Ge(a),G()},ae=F.pagesReady;ae&&typeof ae.then=="function"?ae.then(()=>Vn(F.rendered)).then(Bn).then(Y,()=>{F.dispose(),a.disposed||Se(a,f),G()}):Y()}function Fn(a,f){if(a.rebakeInFlight){a.rebakeQueuedLightDir=f;return}a.rebakeInFlight=!0,Nt(a,f)}function Vn(a){let f=new Set;for(let S of a){let E=S.element.getAttribute("style")??"",W=/url\((blob:[^)]+)\)/g,B;for(;(B=W.exec(E))!==null;)f.add(B[1])}return Array.from(f)}function Bn(a){return a.length===0||typeof Image>"u"?Promise.resolve():Promise.all(a.map(f=>{let S=new Image;S.src=f;let E=S.decode?.();return E?E.catch(()=>{}):Promise.resolve()})).then(()=>{})}function Ke(){let a=1/0,f=!1;for(let B of h)if(!B.disposed&&B.receiveShadow){f=!0;break}for(let B of h){if(B.disposed||!(f?B.receiveShadow:B.castShadow))continue;let G=B.handle.transform.position?.[2]??0;for(let Y of B.polygons)for(let ae of Y.vertices){let ne=ae[2]+G;ne<a&&(a=ne)}}if(!Number.isFinite(a)){let B=v.currentGroundCssZ!==null;v.currentGroundCssZ=null,B&&(g(),k());return}let S=s.shadow?.lift??.05,E=(a+S)*Ne,W=v.currentGroundCssZ;v.currentGroundCssZ=E,W!==E&&(k(),Ee())}async function cn(a,f){H(a);let S=at(s.directionalLight),E={doc:l,directionalLight:S,ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,strategies:s.strategies,lightOccludedPolyIndices:void 0},W=a.stableDom?_t(a.polygons,E):null;if(W){let G=dt(a.polygons,E);return ft(a.wrapper,G),m(a,W.rendered,W.dispose),_(a),Ae(a),Ge(a),!f()}let B=await Kt(a.polygons,{...E,skipDynamicNormalVars:s.textureLighting==="dynamic"},f);if(f())return B.dispose(),!1;ft(a.wrapper,B.solidPaintDefaults),m(a,B.rendered,B.dispose),a.skipBucketNormalCleanupOnce=s.textureLighting==="dynamic"&&!a.stableDom,_(a);let F=await Qe(a,f);return F&&Ge(a),F}function ut(){let a=c,f=[0,0,0];if(s.autoCenter){let S=[];for(let E of h)!E.disposed&&!E.excludeFromAutoCenter&&S.push(...E.polygons);if(S.length>0){let E=_l(S);f=[(E.min[0]+E.max[0])/2,(E.min[1]+E.max[1])/2,(E.min[2]+E.max[2])/2]}}a[0]===f[0]&&a[1]===f[1]&&a[2]===f[2]||(c=f,x.autoCenter.offset=f,Q(d,s))}function di(a,f={}){let E=(d.ownerDocument??document).createElement("div");E.className="polycss-mesh",f.id&&E.setAttribute("data-poly-mesh-id",f.id);let W=`polycss-mesh-${x.meshAutoCounter.next++}`;E.setAttribute("data-poly-mesh-index",W);let B={...f},F=f.merge!==!1,G=!!f.stableDom,Y=0,ae=vn(B);ae&&(E.style.transform=ae);let ne=(N,X)=>a.voxelSource?N:X?Il(N,{meshResolution:f.meshResolution}):(G||f.excludeFromAutoCenter,N),K=ne(a.polygons,F),oe=null;function J(){let N=vn(B);E.style.transform=N??""}function Ie(N){if(N.length===0){oe=null,je&&(je.bboxCenterCss=null),J();return}let X=1/0,le=1/0,me=1/0,Me=-1/0,ce=-1/0,ge=-1/0;for(let Xe of N)for(let Fe of Xe.vertices)Fe[0]<X&&(X=Fe[0]),Fe[0]>Me&&(Me=Fe[0]),Fe[1]<le&&(le=Fe[1]),Fe[1]>ce&&(ce=Fe[1]),Fe[2]<me&&(me=Fe[2]),Fe[2]>ge&&(ge=Fe[2]);if(!Number.isFinite(X)){oe=null,je&&(je.bboxCenterCss=null),J();return}let He=(le+ce)/2*Ne,Ye=(X+Me)/2*Ne,Le=(me+ge)/2*Ne;oe=[He,Ye,Le],je&&(je.bboxCenterCss=oe),J()}let je=null;Ie(K),d.appendChild(E);let w={handle:void 0,wrapper:E,parseResult:a,rendered:[],renderedByPolygonIndex:[],shadowRendered:[],polygons:K,voxelSource:a.voxelSource,disposed:!1,stableDom:G,hasBuckets:!1,skipBucketNormalCleanupOnce:!1,excludeFromAutoCenter:!!f.excludeFromAutoCenter,castShadow:!!f.castShadow,bboxCenterCss:oe,receiveShadow:!!f.receiveShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",stableTriangleColorFrame:0,solidLightingPreviewPrepared:!1,solidLightingPreviewActive:!1,bakedRotation:f.rotation?[...f.rotation]:[0,0,0],autoMeshId:W,rebakeInFlight:!1,rebakeQueuedLightDir:null},We=null,zn=0,un=-1,$t=null;function Ut(){We=null,$t=null,un=-1}function dr(){let N=We;if(!N||N.polygonCount!==w.polygons.length)return w.polygons;if($t&&un===zn)return $t;let X=N.vertices,le=new Array(N.polygonCount);for(let me=0;me<N.polygonCount;me++){let Me=w.polygons[me],ce=me*9;le[me]={...Me,color:N.colors?.[me]??Me.color,vertices:[[X[ce],X[ce+1],X[ce+2]],[X[ce+3],X[ce+4],X[ce+5]],[X[ce+6],X[ce+7],X[ce+8]]]}}return $t=le,un=zn,le}function pr(N,X){let le=N?.stableTriangleUpdateMode==="color-only";w.stableTriangleColorFrame++;let me=w.stableDom&&!X;if(me||Ie(w.polygons),w.stableDom&&!w.hasBuckets){let Me={doc:l,directionalLight:at(s.directionalLight),ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed},ce=w.rendered.length===w.polygons.length&&w.rendered.every(Le=>Le.kind==="triangle"),ge=w.stableDom&&!X,He=ce||ge?{}:dt(w.polygons,Me);ce||ft(w.wrapper,He);let Ye={...Me,solidPaintDefaults:He,optimizeStableTriangleStyle:!0,stableTriangleDebug:N?.stableTriangleDebug,stableTriangleUpdateMode:N?.stableTriangleUpdateMode,stableTriangleColorPolicy:N?.stableTriangleColorPolicy,stableTriangleColorSteps:N?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:N?.stableTriangleColorFreezeFrames,stableTriangleColorBudget:N?.stableTriangleColorBudget,stableTriangleColorMaxAge:N?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:N?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:N?.stableTriangleMatrixDecimals,stableTriangleColorFrame:w.stableTriangleColorFrame};if(en(w.rendered,w.polygons,Ye))return le||(_(w),de(w,!0),X&&ut()),!0}return me&&Ie(w.polygons),!1}let vt={get polygons(){return dr()},set polygons(N){Ut(),w.polygons=N},element:E,id:f.id,get transform(){return B},remove(){Y++,E.parentNode&&E.parentNode.removeChild(E),H(w),h.delete(w),b.delete(E),z(w),I(w),ut(),Ke()},setPolygons(N,X){Y++,F=X?.merge??F,G=X?.stableDom??G,w.stableDom=G,w.voxelSource=void 0,w.polygons=ne(N,F),I(w),z(w),Ut(),vt.polygons=w.polygons;let le=X?.recomputeAutoCenter??!0;pr(X,le)||(Se(w),le&&ut())},[Is](N,X){let le=X?.merge??F,me=X?.stableDom??G;if(!N.solidTriangles||!me||le||f.meshResolution!==void 0||w.hasBuckets||N.polygonCount!==w.polygons.length||N.vertices.length<N.polygonCount*9||w.rendered.length!==N.polygonCount)return!1;for(let ge=0;ge<w.rendered.length;ge++){let He=w.rendered[ge],Ye=w.polygons[ge];if(He?.kind!=="triangle"||He.polygonIndex!==ge||!Ye||Ye.vertices.length!==3||Ye.texture||Ye.material?.texture)return!1}let Me=X?.recomputeAutoCenter??!0;if(!Me){let ge=w.stableTriangleColorFrame+1,He={doc:l,directionalLight:at(s.directionalLight),ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,solidPaintDefaults:{},optimizeStableTriangleStyle:!0,stableTriangleDebug:X?.stableTriangleDebug,stableTriangleUpdateMode:X?.stableTriangleUpdateMode,stableTriangleColorPolicy:X?.stableTriangleColorPolicy,stableTriangleColorSteps:X?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:X?.stableTriangleColorFreezeFrames??0,stableTriangleColorBudget:X?.stableTriangleColorBudget,stableTriangleColorMaxAge:X?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:X?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:X?.stableTriangleMatrixDecimals,stableTriangleColorFrame:ge};if(Jt(w.rendered,w.polygons,N,He))return Y++,F=le,G=me,w.stableDom=G,w.voxelSource=void 0,w.stableTriangleColorFrame=ge,We=N,zn++,$t=null,un=-1,q(w)?(_(w),de(w,!0)):re(w),!0}Y++,F=le,G=me,w.stableDom=G,w.voxelSource=void 0;let ce=N.vertices;for(let ge=0;ge<N.polygonCount;ge++){let He=w.polygons[ge],Ye=N.colors?.[ge];Ye&&(He.color=Ye);let Le=He.vertices,Xe=ge*9;Le[0][0]=ce[Xe],Le[0][1]=ce[Xe+1],Le[0][2]=ce[Xe+2],Le[1][0]=ce[Xe+3],Le[1][1]=ce[Xe+4],Le[1][2]=ce[Xe+5],Le[2][0]=ce[Xe+6],Le[2][1]=ce[Xe+7],Le[2][2]=ce[Xe+8]}return Ut(),vt.polygons=w.polygons,pr(X,Me)},updatePolygon(N,X){let le=typeof N=="number"?N:w.polygons.indexOf(N);if(le<0&&typeof N!="number"&&We&&(le=dr().indexOf(N)),le<0||le>=w.polygons.length)return;Ut(),w.voxelSource=void 0,Object.assign(w.polygons[le],X);let me=Object.keys(X);zt(w,le,me)||Se(w)},async setPolygonsChunked(N,X){let le=++Y;F=X?.merge??F,G=X?.stableDom??G,w.stableDom=G,w.voxelSource=void 0,w.polygons=ne(N,F),Ut(),vt.polygons=w.polygons,Ie(w.polygons);let me=X?.recomputeAutoCenter??!0;if(!await cn(w,()=>w.disposed||le!==Y)){H(w);return}me&&ut()},setTransform(N){let X=w.castShadow,le=w.receiveShadow;N.castShadow!==void 0&&(w.castShadow=!!N.castShadow),N.receiveShadow!==void 0&&(w.receiveShadow=!!N.receiveShadow),B={...B,...N};let me=vn(B);E.style.transform=me??"",lt(w,B.rotation),N.rotation!==void 0&&de(w,!0),w.castShadow!==X&&(w.voxelSource&&Se(w),Ge(w),Ke()),w.receiveShadow!==le&&(w.receiveShadow||Co(w),k(),Ee()),(N.position!==void 0||N.scale!==void 0)&&(w.castShadow||w.receiveShadow)&&(Ke(),k(),Ee())},dispose(){if(!w.disposed){w.disposed=!0,Y++,E.parentNode&&E.parentNode.removeChild(E),H(w);try{a.dispose()}catch{}h.delete(w),b.delete(E),ut(),Ke()}},rebakeAtlas(){w.bakedRotation=B.rotation?[...B.rotation]:[0,0,0];let N=s.directionalLight?.direction??[.4,-.7,.59],X=To(N,w.bakedRotation);Fn(w,X)},getPosition(){return B.position},getRotation(){return B.rotation},getScale(){return B.scale},getPolygons(){return vt.polygons}};return w.handle=vt,je=w,b.set(E,w),h.add(w),Se(w),lt(w,B.rotation),ut(),Ke(),w.receiveShadow&&(k(),Ee()),vt}function pi(a){let f=!!s.autoCenter,S=s.strategies,E=s.seamBleed,W=s.textureLighting,B=s.directionalLight?.direction,F=s.shadow,G=Vs(a);s={...s,...G},x.options.current=s,Q(d,s);let Y=!!s.autoCenter;for(let We of h)lt(We,We.handle.transform.rotation);let ae=a.strategies!==void 0&&!cs(a.strategies,S),ne=Object.prototype.hasOwnProperty.call(a,"seamBleed")&&G.seamBleed!==E;if(ae||ne)for(let We of h)Se(We);f!==Y&&ut();let K=a.textureLighting!==void 0&&W!==s.textureLighting,oe=s.directionalLight?.direction,J=a.directionalLight!==void 0&&!us(B,oe),Ie=s.shadow,je=a.shadow!==void 0&&!ds(F,Ie),w=J||je;if(K){if(!ae&&!ne)for(let We of h)Se(We);Ke(),k(),Ee()}else w&&(je&&k(),Ee());je&&a.shadow?.lift!==F?.lift&&Ke()}function mi(){return s}function fi(){O(d);for(let a of h)de(a)}function hi(){let a=[];for(let f of h)a.push(f.handle);return a}function gi(a){let f=a;for(;f;){if(f instanceof HTMLElement){let S=b.get(f);if(S&&!S.disposed)return S.handle;if(f.classList.contains("polycss-mesh"))return null}f=f.parentElement}return null}function yi(){let a=Array.from(h);for(let f of a)try{f.handle.dispose()}catch{}u.parentNode&&u.parentNode.removeChild(u)}return{add:di,setOptions:pi,destroy:yi,host:e,camera:t,cameraEl:u,applyCamera:fi,getOptions:mi,meshes:hi,findMeshByElement:gi,previewBakedSolidLighting:se,commitBakedSolidLighting:In,clearBakedSolidLightingPreview:Hn}}import{createIsometricCamera as Ns}from"@layoutit/polycss-core";var Bl=32e3;function Ot(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=Ns(n),o=`${e.perspective??Bl}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function ht(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=Ns(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var zl=ht;import{BASE_TILE as Nl}from"@layoutit/polycss-core";var Cn={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Dt(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 tn(e){return e===!0?-1:e===!1?1:e}function It(){let e=[],n=[],t=[];function o(i){return i==="change"?e:i==="start"?n:t}function r(i){if(e.length===0)return;let c={type:"change",camera:i()},l=e.slice();for(let u of l)try{u(c)}catch(d){console.error("[polycss] controls 'change' listener threw:",d)}}function s(i,c){let l=i==="start"?n:t;if(l.length===0)return;let u={type:i,camera:c()},d=l.slice();for(let x of d)try{x(u)}catch(h){console.error(`[polycss] controls '${i}' listener threw:`,h)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function Ht(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 En(e,n,t,o,r,s){let i=!1,c=null;return{onWheel:d=>{let x=n();if(!x.wheel||t())return;d.preventDefault();let h=d.deltaMode===1?16:d.deltaMode===2?100:1,b=d.deltaY*h;d.ctrlKey?b*=10:b*=3;let v=e.camera.state;if(x.dolly){let P=v.distance??0,g=Math.max(x.minDistance,Math.min(x.maxDistance,P+b*.05));e.camera.update({distance:g})}else{let P=Math.exp(-b*513e-6),g=v.zoom??1,C=Math.max(x.minZoom,Math.min(x.maxZoom,g*P));e.camera.update({zoom:C})}e.applyCamera(),i||(i=!0,s("start",o)),r(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,i=!1,s("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),i=!1}}}function Tn(e,n,t,o,r,s,i){let c=null,l=0,u=b=>{if(c===null||o())return;let v=t();if(!v.animate){c=null;return}if(r())l=b;else{let P=Math.min(50,l?b-l:16.67);l=b;let g=v.animate.speed*(P/16.67),C=n.camera.state;if(v.animate.axis==="x"){let D=(((C.rotX??65)+g)%360+360)%360;n.camera.update({rotX:D})}else{let D=(((C.rotY??45)+g)%360+360)%360;n.camera.update({rotY:D})}n.applyCamera(),i(s)}c=e.requestAnimationFrame(u)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(u))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function wo(e,n={}){let t=Dt(Cn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,u=It(),d=Ht(e),{changeListeners:x,startListeners:h,endListeners:b,listenerArray:v,emitChange:P,emitInteraction:g}=u,C=Tn(r,e,()=>t,()=>l,()=>c,d,P),D=p=>{if(!(!t.drag||l)&&s===null&&p.isPrimary!==!1){p.preventDefault(),s=p.pointerId,i={x:p.clientX,y:p.clientY},o.style.cursor="grabbing";try{p.target.setPointerCapture(p.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),g("start",d)}},k=p=>{if(s===null||p.pointerId!==s||!t.drag||l)return;p.preventDefault();let T=p.clientX-i.x,M=p.clientY-i.y;i={x:p.clientX,y:p.clientY};let R=tn(t.invert),L=T/4*R,te=M/4*R,_=e.camera.state;if(p.shiftKey){let j=_.rotX??65,q=_.rotY??45,re=Math.max(.01,_.zoom??1),fe=Math.cos(j*Math.PI/180),de=fe>=0?Math.max(.1,fe):Math.min(-.1,fe),pe=Math.cos(q*Math.PI/180),Ce=Math.sin(q*Math.PI/180),be=re*Nl,Ae=(T*Ce-M*pe/de)/be,Ue=-(T*pe+M*Ce/de)/be,Qe=_.target??[0,0,0];e.camera.update({target:[Qe[0]+Ae,Qe[1]+Ue,Qe[2]]})}else{let j=Math.max(0,Math.min(89,(_.rotX??65)-te)),q=(((_.rotY??45)-L)%360+360)%360;e.camera.update({rotX:j,rotY:q})}e.applyCamera(),P(d)},z=p=>{if(s===p.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{p.target.releasePointerCapture(p.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),g("end",d)}},I=En(e,()=>t,()=>l,d,P,g);function Z(){o.addEventListener("pointerdown",D),o.addEventListener("pointermove",k),o.addEventListener("pointerup",z),o.addEventListener("pointercancel",z),o.addEventListener("wheel",I.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function Q(){o.removeEventListener("pointerdown",D),o.removeEventListener("pointermove",k),o.removeEventListener("pointerup",z),o.removeEventListener("pointercancel",z),o.removeEventListener("wheel",I.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",I.teardown()}Z(),C.start();function O(p){let T=!!t.animate;t=Dt(t,p),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let M=!!t.animate;T&&!M?C.stop():!T&&M&&C.start()}function H(){l&&(l=!1,Z(),C.start())}function V(){l||(l=!0,Q(),C.stop(),s=null,c=!1,I.teardown())}function $(){V(),x.length=0,h.length=0,b.length=0}function A(p,T){let M=v(p);M.includes(T)||M.push(T)}function y(p,T){let M=v(p),R=M.indexOf(T);R>=0&&M.splice(R,1)}function m(p,T){return v(p).includes(T)}return{update:O,resume:H,pause:V,destroy:$,addEventListener:A,removeEventListener:y,hasEventListener:m}}import{BASE_TILE as $l}from"@layoutit/polycss-core";function Mo(e,n={}){let t=Dt(Cn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,u=!1,d={x:0,y:0},x=It(),h=Ht(e),{changeListeners:b,startListeners:v,endListeners:P,listenerArray:g,emitChange:C,emitInteraction:D}=x,k=Tn(r,e,()=>t,()=>l,()=>c,h,C),z=_=>{if(!(!t.drag||l)&&s===null&&_.isPrimary!==!1){_.preventDefault(),s=_.pointerId,i={x:_.clientX,y:_.clientY},o.style.cursor="grabbing";try{_.target.setPointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),D("start",h)}},I=_=>{if(s===null||_.pointerId!==s||!t.drag||l)return;_.preventDefault();let j=_.clientX-i.x,q=_.clientY-i.y;i={x:_.clientX,y:_.clientY};let re=e.camera.state;if(_.shiftKey){let fe=tn(t.invert),de=j/4*fe,pe=q/4*fe,Ce=(re.rotX??65)-pe,be=(((re.rotY??45)-de)%360+360)%360;e.camera.update({rotX:Ce,rotY:be})}else{let fe=re.rotX??65,de=re.rotY??45,pe=Math.max(.01,re.zoom??1),Ce=Math.cos(fe*Math.PI/180),be=Ce>=0?Math.max(.1,Ce):Math.min(-.1,Ce),Ae=Math.cos(de*Math.PI/180),Ue=Math.sin(de*Math.PI/180),Qe=pe*$l,lt=(j*Ue-q*Ae/be)/Qe,bt=-(j*Ae+q*Ue/be)/Qe,ct=re.target??[0,0,0];e.camera.update({target:[ct[0]+lt,ct[1]+bt,ct[2]]})}e.applyCamera(),C(h)},Z=_=>{if(s===_.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{_.target.releasePointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),D("end",h)}},Q=_=>{_.preventDefault()},O=_=>{_.button===2&&(u=!0,d={x:_.clientX,y:_.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),D("start",h))},H=_=>{if(!u||!t.drag)return;let j=_.clientX-d.x,q=_.clientY-d.y;d={x:_.clientX,y:_.clientY};let re=tn(t.invert),fe=j/4*re,de=q/4*re,pe=e.camera.state,Ce=(pe.rotX??65)-de,be=(((pe.rotY??45)-fe)%360+360)%360;e.camera.update({rotX:Ce,rotY:be}),e.applyCamera(),C(h)},V=_=>{_.button===2&&u&&(u=!1,D("end",h))},$=En(e,()=>t,()=>l,h,C,D);function A(){o.addEventListener("pointerdown",z),o.addEventListener("pointermove",I),o.addEventListener("pointerup",Z),o.addEventListener("pointercancel",Z),o.addEventListener("wheel",$.onWheel,{passive:!1}),o.addEventListener("contextmenu",Q),o.addEventListener("mousedown",O),o.addEventListener("mousemove",H),o.addEventListener("mouseup",V),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function y(){o.removeEventListener("pointerdown",z),o.removeEventListener("pointermove",I),o.removeEventListener("pointerup",Z),o.removeEventListener("pointercancel",Z),o.removeEventListener("wheel",$.onWheel),o.removeEventListener("contextmenu",Q),o.removeEventListener("mousedown",O),o.removeEventListener("mousemove",H),o.removeEventListener("mouseup",V),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",$.teardown()}A(),k.start();function m(_){let j=!!t.animate;t=Dt(t,_),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let q=!!t.animate;j&&!q?k.stop():!j&&q&&k.start()}function p(){l&&(l=!1,A(),k.start())}function T(){l||(l=!0,y(),k.stop(),s=null,c=!1,u=!1,$.teardown())}function M(){T(),b.length=0,v.length=0,P.length=0}function R(_,j){let q=g(_);q.includes(j)||q.push(j)}function L(_,j){let q=g(_),re=q.indexOf(j);re>=0&&q.splice(re,1)}function te(_,j){return g(_).includes(j)}return{update:m,resume:p,pause:T,destroy:M,addEventListener:R,removeEventListener:L,hasEventListener:te}}import{BASE_TILE as Ul}from"@layoutit/polycss-core";var Gl={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 $s(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 Us=new Set(["KeyW","ArrowUp"]),Gs=new Set(["KeyS","ArrowDown"]),js=new Set(["KeyA","ArrowLeft"]),Ws=new Set(["KeyD","ArrowRight"]),Ys=new Set(["Space"]),Lo=new Set(["ControlLeft","ControlRight"]);function _o(e,n={}){let t=$s(Gl,n),o=e.host,r=e.cameraEl,s=o.ownerDocument??document,i=s.defaultView??globalThis,c=It(),l=Ht(e),{changeListeners:u,startListeners:d,endListeners:x,listenerArray:h,emitChange:b,emitInteraction:v}=c,P=new Set,g=!1,C=!1,D=0,k=0,z=!1,I=[0,0,t.groundZ+t.eyeHeight];function Z(U,se){let ie=U*Math.PI/180,we=se*Math.PI/180;return[-Math.sin(ie)*Math.cos(we),-Math.sin(ie)*Math.sin(we),-Math.cos(ie)]}function Q(){let U=e.camera.perspectiveStyle,se=U==="none"?0:parseFloat(U);return(Number.isFinite(se)&&se>0?se:2e3)/Ul}function O(){let U=e.camera.state,se=Z(U.rotX??90,U.rotY??0),ie=Q();return[I[0]+se[0]*ie,I[1]+se[1]*ie,I[2]+se[2]*ie]}function H(){let U=O();e.camera.update({target:U}),e.applyCamera()}function V(){let U=e.camera.state.target??[0,0,0];I=[U[0],U[1],t.groundZ+t.eyeHeight],H()}let $=()=>{if(!(!t.enabled||!t.lookEnabled||C||g))try{o.requestPointerLock()}catch{}},A=()=>{let U=s.pointerLockElement===o;U!==g&&(g=U,g?(z=!0,v("start",l)):z&&(z=!1,v("end",l)))},y=U=>{if(!g||!t.enabled||!t.lookEnabled||C)return;let se=U.movementX??0,ie=U.movementY??0;if(se===0&&ie===0)return;let we=e.camera.state,zt=t.lookSensitivity,Ge=t.invertY?-1:1,Ee=(((we.rotY??0)-se*zt)%360+360)%360,ve=(we.rotX??90)-ie*zt*Ge;ve<t.minPitch?ve=t.minPitch:ve>t.maxPitch&&(ve=t.maxPitch);let Oe=Z(ve,Ee),De=Q(),Se=[I[0]+Oe[0]*De,I[1]+Oe[1]*De,I[2]+Oe[2]*De];e.camera.update({rotX:ve,rotY:Ee,target:Se}),e.applyCamera(),b(l)},m=U=>Us.has(U)||Gs.has(U)||js.has(U)||Ws.has(U)||Ys.has(U)||Lo.has(U),p=U=>{if(!(!t.enabled||C)&&m(U.code)&&!(!g&&!t.moveEnabled)){if(Ys.has(U.code)){if(!t.jumpEnabled)return;U.preventDefault(),!P.has(U.code)&&D===0&&k===0&&(D=t.jumpVelocity),P.add(U.code);return}Lo.has(U.code)&&!t.crouchEnabled||!t.moveEnabled&&!Lo.has(U.code)||(U.preventDefault(),P.add(U.code))}},T=U=>{m(U.code)&&P.delete(U.code)},M=()=>{P.clear()},R=null,L=0,te=.05,_=U=>{if(R===null||C)return;let se=Math.min(te,L?(U-L)/1e3:.0167);if(L=U,t.enabled){let ie=!1,we=e.camera.state;if(t.moveEnabled){let ve=0,Oe=0;for(let De of P)Us.has(De)?ve+=1:Gs.has(De)?ve-=1:Ws.has(De)?Oe+=1:js.has(De)&&(Oe-=1);if(ve!==0||Oe!==0){let Se=(we.rotY??0)*Math.PI/180,Nt=-Math.cos(Se),Fn=-Math.sin(Se),Vn=-Math.sin(Se),Bn=Math.cos(Se),Ke=Math.hypot(ve,Oe)||1,cn=t.moveSpeed*se;I[0]+=(Nt*ve+Vn*Oe)/Ke*cn,I[1]+=(Fn*ve+Bn*Oe)/Ke*cn,ie=!0}}let Ge=t.crouchEnabled&&(P.has("ControlLeft")||P.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(D!==0||k>0)?(D-=t.gravity*se,k+=D*se,k<=0&&(k=0,D=0)):t.jumpEnabled||(k=0,D=0);let Ee=t.groundZ+Ge+k;if(Math.abs(I[2]-Ee)>1e-4&&(I[2]=Ee,ie=!0),ie){let ve=O();e.camera.update({target:ve}),e.applyCamera(),b(l)}}R=i.requestAnimationFrame(_)};function j(){R!==null||C||(L=0,R=i.requestAnimationFrame(_))}function q(){R!==null&&(i.cancelAnimationFrame(R),R=null)}function re(){let se=r.ownerDocument?.defaultView?.getComputedStyle(r).perspective??"",ie=parseFloat(se),we=Number.isFinite(ie)&&ie>0?ie:2e3;r.style.setProperty("--polycss-fpv-perspective",`${we}px`),r.classList.add("polycss-fpv-host")}function fe(){r.classList.remove("polycss-fpv-host"),r.style.removeProperty("--polycss-fpv-perspective")}function de(){o.addEventListener("click",$),s.addEventListener("pointerlockchange",A),s.addEventListener("mousemove",y),i.addEventListener("keydown",p),i.addEventListener("keyup",T),i.addEventListener("blur",M),o.style.cursor=t.lookEnabled?"crosshair":"",re()}function pe(){if(o.removeEventListener("click",$),s.removeEventListener("pointerlockchange",A),s.removeEventListener("mousemove",y),i.removeEventListener("keydown",p),i.removeEventListener("keyup",T),i.removeEventListener("blur",M),o.style.cursor="",P.clear(),g)try{s.exitPointerLock()}catch{}fe()}V(),de(),j();function Ce(U){let se=t.eyeHeight,ie=t.groundZ;t=$s(t,U),C||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==se||t.groundZ!==ie)&&(I[2]=t.groundZ+t.eyeHeight,H(),b(l))}function be(){C&&(C=!1,de(),j())}function Ae(){C||(C=!0,pe(),q(),z&&(z=!1,v("end",l)))}function Ue(){Ae(),u.length=0,d.length=0,x.length=0}function Qe(){if(!(!t.enabled||!t.lookEnabled||C))try{o.requestPointerLock()}catch{}}function lt(){if(g)try{s.exitPointerLock()}catch{}}function bt(){return g}function ct(U,se){let ie=h(U);ie.includes(se)||ie.push(se)}function On(U,se){let ie=h(U),we=ie.indexOf(se);we>=0&&ie.splice(we,1)}function Dn(U,se){return h(U).includes(se)}function In(){return[I[0],I[1],I[2]]}function Hn(U){I[0]=U[0],I[1]=U[1],I[2]=U[2],H(),b(l)}return{update:Ce,resume:be,pause:Ae,destroy:Ue,lock:Qe,unlock:lt,isLocked:bt,getOrigin:In,setOrigin:Hn,addEventListener:ct,removeEventListener:On,hasEventListener:Dn}}function Ft(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function Xs(e,n,t,o){for(let r of e)if(!(o&&!o(r))&&Ft(r.element,n,t))return r;return null}function Ro(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let P of o)try{P(t)}catch(g){console.error("[polycss/createSelect] onChange threw:",g)}}function s(v){t=v,r()}function i(v){n.multiple?t.includes(v)||(t=[...t,v]):t=[v],r()}function c(v){t.includes(v)&&(t=t.filter(P=>P!==v),r())}function l(v){t.includes(v)?t=t.filter(P=>P!==v):n.multiple?t=[...t,v]:t=[v],r()}function u(){t.length!==0&&(t=[],r())}function d(v){return t.includes(v)}function x(v,P){return Xs(e.meshes(),v,P,g=>!g.element.classList.contains("polycss-transform-gizmo"))}let h=v=>{let P=v.target;if(P?.closest(".polycss-transform-gizmo"))return;let g=e.findMeshByElement(P)??x(v.clientX,v.clientY);if(!g){n.onPointerMissed&&n.onPointerMissed(v),n.clearOnMiss!==!1&&u();return}n.multiple&&(v.shiftKey||v.metaKey||v.ctrlKey)?l(g):t.length===1&&t[0]===g?u():s([g])};e.host.addEventListener("click",h);function b(){e.host.removeEventListener("click",h),o.clear()}return{get selected(){return t},set:s,add:i,remove:c,toggle:l,clear:u,has:d,destroy:b}}import{arrowPolygons as jl,eulerXYZFromQuat as Wl,planePolygons as Yl,quatFromAxisAngle as Xl,quatFromEulerXYZ as Zl,quatMultiply as ql,ringQuadPolygons as Ql,rotateVec3 as ko}from"@layoutit/polycss-core";var An="#ff3653",wn="#8adb00",Mn="#2c8fff",Vt=50,Zs=60,Kl=.6,Jl=.0125,ec=.15,tc=.04,nc=1,qs=.02,Oo=1.04,oc=.1,rc=.25,ei=1e-4,sc=.6,ic=.8,ac=1,tt={0:1,1:0,2:2},Qs=[{cssAxis:0,sign:1,key:"x",color:An},{cssAxis:0,sign:-1,key:"-x",color:An},{cssAxis:1,sign:1,key:"y",color:wn},{cssAxis:1,sign:-1,key:"-y",color:wn},{cssAxis:2,sign:1,key:"z",color:Mn},{cssAxis:2,sign:-1,key:"-z",color:Mn}],Ks=[{cssAxis:0,key:"x",color:An},{cssAxis:1,key:"y",color:wn},{cssAxis:2,key:"z",color:Mn}],Js=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:Mn},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:wn},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:An}];function Do(e,n,t,o){let r=t*Math.PI/180,s=o*Math.PI/180,i=[0,0,0];i[e]=n;let c=i[0]*Math.cos(s)-i[1]*Math.sin(s),l=i[0]*Math.sin(s)+i[1]*Math.cos(s),u=i[2];return l*Math.sin(r)+u*Math.cos(r)<0}function lc(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),s=parseInt(t[3],16);return`rgba(${o}, ${r}, ${s}, ${n})`}function Ln(e,n){return!n||n<=0?e:Math.round(e/n)*n}function cc(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let l of c.vertices)l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>s&&(s=l[1]),l[2]<o&&(o=l[2]),l[2]>i&&(i=l[2]);return Number.isFinite(n)?[(n+r)/2,(t+s)/2,(o+i)/2]:[0,0,0]}function Io(e){if(e.length===0)return Zs;let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let u of l.vertices)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*Vt*Kl:Zs}function uc(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:c,translationSnap:l,onAxisDelta:u,onMouseDown:d,onMouseUp:x,onDraggingChanged:h}=e,b=o,v=[0,0,0];v[n]=t;let P=r.ownerDocument.createElement("div");P.style.position="absolute",P.style.left="0",P.style.top="0",P.style.width="0",P.style.height="0",P.style.transform=`translate3d(${v[0]*b}px, ${v[1]*b}px, ${v[2]*b}px)`,r.appendChild(P);let g=r.getBoundingClientRect(),C=P.getBoundingClientRect();r.removeChild(P);let D=(C.left-g.left)/b,k=(C.top-g.top)/b,z=D*D+k*k;if(z<ei)return;d?.(),h?.(!0);let I=Q=>{let O=Q.clientX-i,H=Q.clientY-c,V=(O*D+H*k)/z;V=Ln(V,l),u(V,v)},Z=()=>{window.removeEventListener("pointermove",I),window.removeEventListener("pointerup",Z),window.removeEventListener("pointercancel",Z);let Q=O=>{O.stopPropagation(),O.stopImmediatePropagation()};window.addEventListener("click",Q,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",Q,!0),0),x?.(),h?.(!1)};window.addEventListener("pointermove",I),window.addEventListener("pointerup",Z),window.addEventListener("pointercancel",Z)}function dc(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:s,startClientY:i,translationSnap:c,onPlaneDelta:l,onMouseDown:u,onMouseUp:d,onDraggingChanged:x}=e,h=[0,0,0];h[n]=1;let b=[0,0,0];b[t]=1;function v(z){let I=r.ownerDocument.createElement("div");I.style.position="absolute",I.style.left="0",I.style.top="0",I.style.width="0",I.style.height="0",I.style.transform=`translate3d(${z[0]*o}px, ${z[1]*o}px, ${z[2]*o}px)`,r.appendChild(I);let Z=r.getBoundingClientRect(),Q=I.getBoundingClientRect();return r.removeChild(I),{x:(Q.left-Z.left)/o,y:(Q.top-Z.top)/o}}let P=v(h),g=v(b),C=P.x*g.y-g.x*P.y;if(Math.abs(C)<ei)return;u?.(),x?.(!0);let D=z=>{let I=z.clientX-s,Z=z.clientY-i,Q=(g.y*I-g.x*Z)/C,O=(-P.y*I+P.x*Z)/C;Q=Ln(Q,c),O=Ln(O,c),l(Q,O,h,b)},k=()=>{window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k);let z=I=>{I.stopPropagation(),I.stopImmediatePropagation()};window.addEventListener("click",z,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",z,!0),0),d?.(),x?.(!1)};window.addEventListener("pointermove",D),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)}function pc(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:c,onMouseDown:l,onMouseUp:u,onDraggingChanged:d}=e,x=t.getBoundingClientRect(),h=x.left,b=x.top,v=Math.atan2(s-b,r-h),P=0;l?.(),d?.(!0);let g=D=>{let k=Math.atan2(D.clientY-b,D.clientX-h),z=k-v;z>Math.PI?z-=2*Math.PI:z<-Math.PI&&(z+=2*Math.PI),P+=z,v=k;let I=P*180/Math.PI;I=Ln(I,i),c(I)},C=()=>{window.removeEventListener("pointermove",g),window.removeEventListener("pointerup",C),window.removeEventListener("pointercancel",C);let D=k=>{k.stopPropagation(),k.stopImmediatePropagation()};window.addEventListener("click",D,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",D,!0),0),u?.(),d?.(!1)};window.addEventListener("pointermove",g),window.addEventListener("pointerup",C),window.addEventListener("pointercancel",C)}function Ho(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,c=null,l=null,u=[0,0,0];function d(){if(!t)return[0,0,0];let y=t.transform.position??[0,0,0],m=t.transform.rotation??[0,0,0],p=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,T=ko(u,m[0],m[1],m[2]);return[y[0]+p*T[0],y[1]+p*T[1],y[2]+p*T[2]]}function x(y){return l===y?ac:c===y?ic:sc}function h(){for(let[y,m]of i){let p=b(m.spec,x(y));m.handle.setPolygons(p,{recomputeAutoCenter:!1})}}function b(y,m){let T=Io(t?.polygons??[])*r,M=T/Vt,R=lc(y.color,m);if(y.kind==="arrow"){let _=e.camera.state,j=Do(y.cssAxis,y.sign,_.rotX??65,_.rotY??45);return jl({axis:tt[y.cssAxis],sign:y.sign,shaftLength:M,shaftHalfThickness:M*Jl,headLength:M*ec,headHalfThickness:M*tc,color:R,shaft:!j})}if(y.kind==="plane"){let _=e.camera.state,j=_.rotX??65,q=_.rotY??45,re=tt[y.perpAxis],fe=(re+1)%3,de=(re+2)%3,pe=tt[fe],Ce=tt[de],be=Do(pe,1,j,q)?-1:1,Ae=Do(Ce,1,j,q)?-1:1,Ue=M*rc;return Yl({axis:re,size:M*oc,offset:[be*Ue,Ae*Ue],color:R})}let te=T*nc/Vt*Oo;return Ql({axis:tt[y.cssAxis],outerRadius:te,color:R})}function v(y){return y.kind==="arrow"?"polycss-transform-arrow":y.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function P(){if(o==="translate"){let y=Qs.map(p=>({kind:"arrow",key:p.key,cssAxis:p.cssAxis,sign:p.sign,color:p.color})),m=Js.map(p=>({kind:"plane",key:p.key,perpAxis:p.perpAxis,axisA:p.axisA,axisB:p.axisB,color:p.color}));return[...y,...m]}return o==="rotate"?Ks.map(y=>({kind:"ring",key:y.key,cssAxis:y.cssAxis,color:y.color})):[]}function g(){if(C(),!t)return;let y={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};function m(T){if(T.kind==="arrow"){let L=T.key.replace("-","")[0];return y[L]}if(T.kind==="ring")return y[T.key];let M=["x","y","z"][T.axisA],R=["x","y","z"][T.axisB];return y[M]&&y[R]}let p=d();for(let T of P()){if(!m(T))continue;let M=b(T,x(T.key)),R=e.add({polygons:M,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${T.key}`,position:p}),L=v(T);if(R.element.classList.add("polycss-transform-gizmo",L,`${L}--${T.key}`),T.kind==="ring"){let te=(1-qs)/Oo,_=(1+qs)/Oo;R.element.style.setProperty("--ring-inner-ratio",`${te}`),R.element.style.setProperty("--ring-outer-ratio",`${_}`)}i.set(T.key,{handle:R,spec:T})}}function C(){for(let{handle:y}of i.values())y.remove();i.clear(),c=null,l=null}function D(){if(!t)return;let y=d();for(let{handle:m}of i.values())m.setTransform({position:y})}function k(){t&&(i.size===0?g():D())}function z(y){if(t=y,!y){u=[0,0,0],C();return}u=cc(y.polygons),C(),g()}function I(){z(null)}function Z(y){y!==o&&(o=y,t&&(C(),g()))}function Q(y,m,p){if(!t||!O)return;let T=p[y.cssAxis],M=tt[y.cssAxis],R=m*T/Vt,L=O.slice();L[M]=O[M]+R,t.setTransform({position:L}),D(),s.onObjectChange?.({object:t,position:L}),s.onChange?.()}let O=null,H=null,V=y=>{if(!t||s.enabled===!1)return;let m={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate"){for(let p of Js){let T=["x","y","z"][p.axisA],M=["x","y","z"][p.axisB];if(!m[T]||!m[M])continue;let R=i.get(p.key);if(R&&Ft(R.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),O=(t.transform.position??[0,0,0]).slice(),dc({axisA:p.axisA,axisB:p.axisB,probeDistanceCss:Io(t.polygons)*r,wrapper:R.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,translationSnap:s.translationSnap??null,onPlaneDelta:(L,te,_,j)=>{if(!t||!O)return;let q=_[p.axisA],re=j[p.axisB],fe=tt[p.axisA],de=tt[p.axisB],pe=O.slice();pe[fe]+=L*q/Vt,pe[de]+=te*re/Vt,t.setTransform({position:pe}),D(),s.onObjectChange?.({object:t,position:pe}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:L=>{L||(l=null,O=null,h()),s.onDraggingChanged?.(L)}});return}}for(let p of Qs){let T=p.key.replace("-","")[0];if(!m[T])continue;let M=i.get(p.key);if(M&&Ft(M.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),O=(t.transform.position??[0,0,0]).slice(),uc({cssAxis:p.cssAxis,sign:p.sign,shaftLengthCss:Io(t.polygons)*r,wrapper:M.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(R,L)=>Q(p,R,L),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:R=>{R||(l=null,O=null,h()),s.onDraggingChanged?.(R)}});return}}}else if(o==="rotate")for(let p of Ks){if(!m[p.key])continue;let T=i.get(p.key);if(T&&Ft(T.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),H=(t.transform.rotation??[0,0,0]).slice(),O=(t.transform.position??[0,0,0]).slice(),pc({cssAxis:p.cssAxis,wrapper:T.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:M=>{if(!t||!H||!O)return;let R=tt[p.cssAxis],L=[0,0,0];L[R]=1;let te=-M*Math.PI/180,_=Zl(H),j=Xl(L,te),q=Wl(ql(j,_)),re=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,fe=ko(u,H[0],H[1],H[2]),de=ko(u,q[0],q[1],q[2]),pe=[O[0]+re*(fe[0]-de[0]),O[1]+re*(fe[1]-de[1]),O[2]+re*(fe[2]-de[2])];t.setTransform({rotation:q,position:pe}),D(),s.onObjectChange?.({object:t,rotation:q,position:pe}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:M=>{M||(l=null,H=null,O=null,h(),t?.rebakeAtlas()),s.onDraggingChanged?.(M)}});return}}};e.host.addEventListener("pointerdown",V,{capture:!0});let $=y=>{if(!t||l||s.enabled===!1)return;let m=null;for(let[p,T]of i)if(Ft(T.handle.element,y.clientX,y.clientY)){m=p;break}m!==c&&(c=m,h())};e.host.addEventListener("pointermove",$);function A(){e.host.removeEventListener("pointerdown",V,{capture:!0}),e.host.removeEventListener("pointermove",$),C()}return{attach:z,detach:I,setMode:Z,update:k,destroy:A}}var mc=typeof HTMLElement<"u"?HTMLElement:class{},fc=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function $e(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function hc(e){return e==="false"?!1:$e(e)}function Fo(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 gc(e){if(e==="baked"||e==="dynamic")return e}function yc(e){return e==="auto"?"auto":$e(e)}function bc(e){return typeof e.getCamera=="function"}var Re=class extends mc{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...fc]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(bc(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=hc(this.getAttribute("perspective")),o=$e(this.getAttribute("rot-x")),r=$e(this.getAttribute("rot-y")),s=$e(this.getAttribute("zoom")),i=$e(this.getAttribute("distance")),c=Fo(this.getAttribute("target")),l={...o!==void 0?{rotX:o}:{},...r!==void 0?{rotY:r}:{},...s!==void 0?{zoom:s}:{},...i!==void 0?{distance:i}:{},...c!==void 0?{target:c}:{}};return t===!1?ht(l):t!==void 0?Ot({...l,perspective:t}):ht(l)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={};r.textureLighting=gc(this.getAttribute("texture-lighting"))??"baked";let s=yc(this.getAttribute("texture-quality"));return s!==void 0&&(r.textureQuality=s),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=Fo(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=$e(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let s={direction:t??[.4,-.7,.59]};return o&&(s.color=o),r!==void 0&&(s.intensity=r),s}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=$e(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){if(this._scene)return;let t=this._findAncestorCamera(),o;t?(o=t,this._implicitCamera=null):(this._implicitCamera=this._buildImplicitCamera(),o=this._implicitCamera),this._scene=Ao(this,{camera:o,...this._readNonCameraOptions()}),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1}))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null),this._implicitCamera=null}attributeChangedCallback(t,o,r){if(o!==r&&this._scene){if(this._implicitCamera&&["rot-x","rot-y","zoom","distance","target"].includes(t)){let i=$e(this.getAttribute("rot-x")),c=$e(this.getAttribute("rot-y")),l=$e(this.getAttribute("zoom")),u=$e(this.getAttribute("distance")),d=Fo(this.getAttribute("target"));i!==void 0&&this._implicitCamera.update({rotX:i}),c!==void 0&&this._implicitCamera.update({rotY:c}),l!==void 0&&this._implicitCamera.update({zoom:l}),u!==void 0&&this._implicitCamera.update({distance:u}),d!==void 0&&this._implicitCamera.update({target:d}),this._scene.applyCamera();return}this._scene.setOptions(this._readNonCameraOptions())}}};import{computeSceneBbox as vc,loadMesh as xc}from"@layoutit/polycss-core";var Pc=typeof HTMLElement<"u"?HTMLElement:class{},Sc=["src","mtl","mesh-resolution","position","scale","rotation","auto-center","cast-shadow","receive-shadow","target-size","default-color","palette","include-objects","exclude-objects"];function nn(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 ti(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return nn(e)}}function Vo(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 Cc(e){let n=e.getAttribute("target-size"),t=e.getAttribute("default-color"),o=Vo(e.getAttribute("palette")),r=Vo(e.getAttribute("include-objects")),s=Vo(e.getAttribute("exclude-objects")),i=n!==null?parseFloat(n):NaN,c={};return Number.isFinite(i)&&(c.targetSize=i),t&&(c.defaultColor=t),o&&(c.palette=o),r&&(c.includeObjects=r),s&&(c.excludeObjects=s),Object.keys(c).length>0?c:void 0}function Ec(e){return e.closest("poly-scene")??null}function Tc(e){if(e.length===0)return e;let n=vc(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s),...i.textureTriangles?.length?{textureTriangles:i.textureTriangles.map(c=>({...c,vertices:c.vertices.map(s)}))}:null}))}var on=class extends Pc{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Sc]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"||t==="mesh-resolution"||t==="target-size"||t==="default-color"||t==="palette"||t==="include-objects"||t==="exclude-objects"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:nn(this.getAttribute("position")),scale:ti(this.getAttribute("scale")),rotation:nn(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=Ec(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,l=Cc(this),u;try{let h=s||c!==void 0||l?{...s?{mtlUrl:s}:{},...c!==void 0?{meshResolution:c}:{},...l?{objOptions:l}:{}}:void 0;u=await xc(t,h)}catch(h){this.dispatchEvent(new CustomEvent("polycss:error",{detail:h,bubbles:!0}));return}if(r!==this._loadToken){try{u.dispose()}catch{}return}let d=o.getScene();if(!d){try{u.dispose()}catch{}return}this.hasAttribute("auto-center")&&(u={...u,polygons:Tc(u.polygons)}),this._parseResult=u,this._handle=d.add(u,{position:nn(this.getAttribute("position")),scale:ti(this.getAttribute("scale")),rotation:nn(this.getAttribute("rotation")),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};import{BASE_TILE as rn}from"@layoutit/polycss-core";var Ac=typeof HTMLElement<"u"?HTMLElement:class{},wc=["src","width","height","position","rotation","scale","allow","loading","referrerpolicy","sandbox","title"];function Bo(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 Mc(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Bo(e)}}function ni(e,n){if(e===null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}function Lc(e){let n=e.closest("poly-scene");return n?n.querySelector(".polycss-scene"):null}function _c(e,n,t,o,r){let s=typeof t=="number"?t:t?.[0]??1,i=typeof t=="number"?t:t?.[1]??1,c=typeof t=="number"?t:t?.[2]??1,l=s!==1||i!==1||c!==1,u=!!n&&(!!n[0]||!!n[1]||!!n[2]),d=(e?.[1]??0)*rn,x=(e?.[0]??0)*rn,h=(e?.[2]??0)*rn,b=[];return b.push(`translate3d(${d}px, ${x}px, ${h}px)`),u&&(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(${s}, ${i}, ${c})`),b.push(`translate(${-o/2}px, ${-r/2}px)`),b.join(" ")}var zo=class extends Ac{constructor(){super(...arguments);this._wrapper=null;this._iframe=null}static get observedAttributes(){return[...wc]}getIframeElement(){return this._iframe}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o!==r&&!(!this._wrapper||!this._iframe)){if(t==="src"){this._iframe.src=this.getAttribute("src")??"";return}if(t==="allow"||t==="loading"||t==="referrerpolicy"||t==="sandbox"||t==="title"){let s=this.getAttribute(t);s===null?this._iframe.removeAttribute(t):this._iframe.setAttribute(t,s);return}this._applyGeometry()}}_mount(){let t=Lc(this);if(!t)return;let o=this.ownerDocument;if(!o)return;let r=o.createElement("div");r.className="polycss-iframe",r.style.position="absolute",r.style.left="0",r.style.top="0",r.style.transformOrigin="0 0",r.style.transformStyle="preserve-3d";let s=o.createElement("iframe");s.style.display="block",s.style.border="0",s.style.background="#000";let i=this.getAttribute("src");i&&(s.src=i);let c=this.getAttribute("allow");c&&s.setAttribute("allow",c);for(let l of["loading","referrerpolicy","sandbox","title"]){let u=this.getAttribute(l);u!==null&&s.setAttribute(l,u)}r.appendChild(s),t.appendChild(r),this._wrapper=r,this._iframe=s,this._applyGeometry()}_applyGeometry(){if(!this._wrapper||!this._iframe)return;let t=ni(this.getAttribute("width"),16),o=ni(this.getAttribute("height"),9),r=t*rn,s=o*rn;this._iframe.style.width=`${r}px`,this._iframe.style.height=`${s}px`;let i=Bo(this.getAttribute("position")),c=Bo(this.getAttribute("rotation")),l=Mc(this.getAttribute("scale"));this._wrapper.style.transform=_c(i,c,l,r,s)}_teardown(){this._wrapper?.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null,this._iframe=null}};var Rc=typeof HTMLElement<"u"?HTMLElement:class{},kc=["vertices","color","texture","uvs","position","scale","rotation"];function oi(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function No(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Oc(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return No(e)}}function Dc(e){return e.closest("poly-scene")??null}var $o=class extends Rc{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...kc]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=Dc(this);if(!t)return;let o=t.getScene();if(!o)return;let r=oi(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let s=this.getAttribute("color")||void 0,i=this.getAttribute("texture")||void 0,c=oi(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 d={polygons:[{vertices:r,...s!==void 0?{color:s}:{},...i!==void 0?{texture:i}:{},...c!==void 0?{uvs:c}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(d,{position:No(this.getAttribute("position")),scale:Oc(this.getAttribute("scale")),rotation:No(this.getAttribute("rotation"))})}};function ee(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function _n(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Te(e){if(e!==null)return!(e==="false"||e==="0")}function Rn(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 kn(e){if(e==="x"||e==="y")return e}var Ic=typeof HTMLElement<"u"?HTMLElement:class{},Hc=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Uo=class extends Ic{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Hc]}getControls(){return this._controls}_readAnimate(){let t=ee(this.getAttribute("animate-speed")),o=kn(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:Te(r)}:{}}}_readOptions(){let t={},o=Te(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Te(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ee(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ee(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=Rn(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=ee(this.getAttribute("zoom-min")),u=ee(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Re)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=wo(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Fc=typeof HTMLElement<"u"?HTMLElement:class{},Vc=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Go=class extends Fc{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Vc]}_readAnimate(){let t=ee(this.getAttribute("animate-speed")),o=kn(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:Te(r)}:{}}}_readOptions(){let t={},o=Te(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Te(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ee(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ee(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=Rn(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=ee(this.getAttribute("zoom-min")),u=ee(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Re)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=Mo(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Bc=typeof HTMLElement<"u"?HTMLElement:class{},zc=["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"],jo=class extends Bc{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...zc]}_readOptions(){let t={},o=Te(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let r=Te(this.getAttribute("look-enabled"));r!==void 0&&(t.lookEnabled=r);let s=Te(this.getAttribute("move-enabled"));s!==void 0&&(t.moveEnabled=s);let i=Te(this.getAttribute("jump-enabled"));i!==void 0&&(t.jumpEnabled=i);let c=Te(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let l=ee(this.getAttribute("look-sensitivity"));if(l!==void 0&&(t.lookSensitivity=l),this.hasAttribute("invert-y")){let C=Te(this.getAttribute("invert-y"));C!==void 0&&(t.invertY=C)}let u=ee(this.getAttribute("move-speed"));u!==void 0&&(t.moveSpeed=u);let d=ee(this.getAttribute("jump-velocity"));d!==void 0&&(t.jumpVelocity=d);let x=ee(this.getAttribute("gravity"));x!==void 0&&(t.gravity=x);let h=ee(this.getAttribute("eye-height"));h!==void 0&&(t.eyeHeight=h);let b=ee(this.getAttribute("crouch-height"));b!==void 0&&(t.crouchHeight=b);let v=ee(this.getAttribute("ground-z"));v!==void 0&&(t.groundZ=v);let P=ee(this.getAttribute("min-pitch"));P!==void 0&&(t.minPitch=P);let g=ee(this.getAttribute("max-pitch"));return g!==void 0&&(t.maxPitch=g),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Re)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=_o(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Nc=typeof HTMLElement<"u"?HTMLElement:class{},$c=["perspective","zoom","rot-x","rot-y","target","distance"],Wo=class extends Nc{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...$c]}getCamera(){return this._camera}_readOptions(){return{perspective:ee(this.getAttribute("perspective")),zoom:ee(this.getAttribute("zoom")),rotX:ee(this.getAttribute("rot-x")),rotY:ee(this.getAttribute("rot-y")),target:_n(this.getAttribute("target")),distance:ee(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Ot(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let s=this._readOptions();if(t==="perspective"){this._camera=Ot(s),this._wrapper.style.perspective=this._camera.perspectiveStyle;return}this._camera.update({rotX:s.rotX,rotY:s.rotY,zoom:s.zoom,target:s.target,distance:s.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var Uc=typeof HTMLElement<"u"?HTMLElement:class{},Gc=["zoom","rot-x","rot-y","target","distance"],sn=class extends Uc{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Gc]}getCamera(){return this._camera}_readOptions(){return{zoom:ee(this.getAttribute("zoom")),rotX:ee(this.getAttribute("rot-x")),rotY:ee(this.getAttribute("rot-y")),target:_n(this.getAttribute("target")),distance:ee(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=ht(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let s=this._readOptions();s.zoom!==void 0&&this._camera.update({zoom:s.zoom}),s.rotX!==void 0&&this._camera.update({rotX:s.rotX}),s.rotY!==void 0&&this._camera.update({rotY:s.rotY}),s.target!==void 0&&this._camera.update({target:s.target}),s.distance!==void 0&&this._camera.update({distance:s.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var Yo=class extends sn{};var jc=typeof HTMLElement<"u"?HTMLElement:class{},Wc=["mode","target","size","enabled"];function ri(e){if(e==="translate"||e==="rotate")return e}var Xo=class extends jc{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Wc]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Re)return t;t=t.parentNode}return null}_findTargetMesh(){let t=this.getAttribute("target");if(!t)return null;let o=this._findScene();if(!o)return null;let r=null;try{r=o.querySelector(`#${t}`)??o.querySelector(t)}catch{r=o.querySelector(`[id="${t}"]`)}return r instanceof on?r:null}_readOptions(){let t={},o=ri(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=ee(this.getAttribute("size"));r!==void 0&&(t.size=r);let s=this.getAttribute("enabled");return s!==null&&(t.enabled=s!=="false"&&s!=="0"),t.onObjectChange=i=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:i.position,rotation:i.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let s=()=>{t.removeEventListener("polycss:scene-ready",s),this._attach()};t.addEventListener("polycss:scene-ready",s)}return}this._tc=Ho(o,this._readOptions());let r=this._findTargetMesh();if(r){let s=r.getMeshHandle();s&&this._tc.attach(s)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,r){if(o!==r&&this._tc){if(t==="mode"){let s=ri(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};var Yc=typeof HTMLElement<"u"?HTMLElement:class{},Xc=["multiple","clear-on-miss"],Zo=class extends Yc{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Xc]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Re)return t;t=t.parentNode}return null}_readOptions(){return{multiple:this.hasAttribute("multiple"),clearOnMiss:!this.hasAttribute("clear-on-miss")||this.getAttribute("clear-on-miss")!=="false",onChange:t=>{this.dispatchEvent(new CustomEvent("polycss:select",{bubbles:!0,detail:{selected:t}}))}}}_attach(){if(this._selection)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._selection=Ro(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};var qo={quad:0,clippedSolid:0,atlas:0,stableTriangle:0},Zc={polygonCount:0,mountedPolygonLeafCount:0,shadowLeafCount:0,surfaceLeafCounts:qo,bucketCount:0};function qc(e){return typeof e=="number"?{polygonCount:e}:e??{}}function Bt(e,n){return e.querySelectorAll(n).length}function Qc(e,n){let t=e;return typeof t.matches=="function"&&t.matches(n)}function Kc(e,n){if(!n)return[e];let t=[];return Qc(e,n)&&t.push(e),t.push(...Array.from(e.querySelectorAll(n))),t}function Jc(e,n){let t=qc(n);if(!e)return{...Zc,surfaceLeafCounts:{...qo},polygonCount:t.polygonCount??0};let o=Kc(e,t.scopeSelector),r={...qo},s=0,i=0;for(let l of o)r.quad+=Bt(l,"b"),r.clippedSolid+=Bt(l,"i"),r.atlas+=Bt(l,"s"),r.stableTriangle+=Bt(l,"u"),s+=Bt(l,"q, .polycss-shadow-svg"),i+=Bt(l,".polycss-bucket");let c=r.quad+r.clippedSolid+r.atlas+r.stableTriangle;return{polygonCount:t.polygonCount??c,mountedPolygonLeafCount:c,shadowLeafCount:s,surfaceLeafCounts:r,bucketCount:i}}var gt=class extends Error{constructor(n,t,o){super(t),this.name="PolySceneSnapshotError",this.code=n,this.url=o,Object.setPrototypeOf(this,new.target.prototype)}},eu=`
519
+ `;import{BASE_TILE as al,buildPolyMeshTransform as ll}from"@layoutit/polycss-core";var cl=1,et=al,ul=.1;function Rt(e){return[e[1],e[0],e[2]]}function at(e){return e?.direction?{...e,direction:Rt(e.direction)}:e}function vn(e){return ll(e)}function vo(e,n=[0,0,0],t=1){let o=e.state,r=o.rotX,s=o.rotY,c=(o.zoom??cl)/et*t,l=(o.distance??0)*t,u=o.target??[0,0,0],d=u[0]+n[0],x=u[1]+n[1],h=u[2]+n[2],b=x*et,v=d*et,P=h*et;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${r}deg) rotate(${s}deg) translate3d(${-b}px, ${-v}px, ${-P}px)`}function dl(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 is(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=dl(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function as(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}function ls(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let x=1;x+1<e.vertices.length;x++){let h=e.vertices[x],b=e.vertices[x+1],v=h[1]-n[1],P=h[0]-n[0],g=h[2]-n[2],C=b[1]-n[1],D=b[0]-n[0],k=b[2]-n[2];t-=P*k-g*D,o-=g*C-v*k,r-=v*D-P*C}let s=Math.hypot(t,o,r);if(s<1e-9)return null;t/=s,o/=s,r/=s;let i=1/ul,c=Math.round(t*i)/i,l=Math.round(o*i)/i,u=Math.round(r*i)/i,d=Math.hypot(c,l,u);return d<1e-9?null:{key:c+","+l+","+u,vec:[c/d,l/d,u/d]}}function cs(e,n){let t=e?.disable??[],o=n?.disable??[];if(t.length!==o.length)return!1;for(let r of t)if(!o.includes(r))return!1;return!0}function us(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function ds(e,n){return e===n?!0:(e?.color??"#000000")===(n?.color??"#000000")&&(e?.opacity??.25)===(n?.opacity??.25)&&(e?.lift??.05)===(n?.lift??.05)&&(e?.maxExtend??2e3)===(n?.maxExtend??2e3)}import{parseHex as fs,parseHexColor as ps,parsePureColor as pl}from"@layoutit/polycss-core";var ml=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"],kt="--polycss-light-preview-active",ms=`var(${kt}, 0)`,fl="max(0, calc(var(--pnx, 0) * var(--plx, 0) + var(--pny, 0) * var(--ply, 0) + var(--pnz, 1) * var(--plz, 1)))",xo=(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))`,hl=xo("--psr","--par","--plr"),gl=xo("--psg","--pag","--plg"),yl=xo("--psb","--pab","--plb");function ue(e,n,t){return e.style.getPropertyValue(n)===t?!1:(e.style.setProperty(n,t),!0)}function mt(e){for(let n of ml)e.style.getPropertyValue(n)&&e.style.removeProperty(n)}function xn(e,n){let t=n.directionalLight?.direction??[.4,-.7,.59],o=Rt(t),r=Math.hypot(o[0],o[1],o[2])||1,s=o[0]/r,i=o[1]/r,c=o[2]/r,l=ps(n.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],u=ps(n.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],d=n.directionalLight?.intensity??1,x=n.ambientLight?.intensity??.4,h=P=>(P/255).toFixed(4);ue(e,"--plx",s.toFixed(2)),ue(e,"--ply",i.toFixed(2)),ue(e,"--plz",c.toFixed(2)),ue(e,"--plr",h(l[0])),ue(e,"--plg",h(l[1])),ue(e,"--plb",h(l[2])),ue(e,"--pli",d.toFixed(4)),ue(e,"--par",h(u[0])),ue(e,"--pag",h(u[1])),ue(e,"--pab",h(u[2])),ue(e,"--pai",x.toFixed(4));let b=c,v=Math.sign(b||1)*Math.max(Math.abs(b),.01);ue(e,"--clx",s.toFixed(2)),ue(e,"--cly",i.toFixed(2)),ue(e,"--clz",v.toFixed(2))}function hs(e,n){let t=n.textureLighting==="dynamic";if(e.dataset.polycssLighting=n.textureLighting??"baked",!t){mt(e);return}xn(e,n)}function ft(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 gs(e,n){let t=fs(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 Po(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=t.textureLighting??"baked",r={directionalLight:at(t.directionalLight),ambientLight:t.ambientLight,textureLighting:o,textureQuality:t.textureQuality,seamBleed:t.seamBleed,strategies:t.strategies},s=qn(e.plan,n,e.plan.normal,o,r);return wt(e.element,s,o),o==="baked"&&vl(e.element),!0}function bl(e){let n=pl(e)??{rgb:[255,255,255],alpha:1},[t,o,r]=n.rgb,s=(c,l)=>`calc(${c} * (1 - ${ms}) + var(${l}, ${c}) * ${ms})`,i=n.alpha<1?` / ${n.alpha}`:"";return`rgb(${s(t,"--polycss-preview-r")} ${s(o,"--polycss-preview-g")} ${s(r,"--polycss-preview-b")}${i})`}function ys(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=e.element,r=e.plan.normal,s=fs(n.color??"#cccccc"),i=!1;return i=ue(o,"--pnx",r[0].toFixed(4))||i,i=ue(o,"--pny",r[1].toFixed(4))||i,i=ue(o,"--pnz",r[2].toFixed(4))||i,i=ue(o,"--psr",(s.r/255).toFixed(4))||i,i=ue(o,"--psg",(s.g/255).toFixed(4))||i,i=ue(o,"--psb",(s.b/255).toFixed(4))||i,i=ue(o,"--plam",fl)||i,i=ue(o,"--polycss-preview-r",hl)||i,i=ue(o,"--polycss-preview-g",gl)||i,i=ue(o,"--polycss-preview-b",yl)||i,i=ue(o,"--polycss-paint",bl(t))||i,o.style.getPropertyValue("color")&&(o.style.removeProperty("color"),i=!0),i}function vl(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 xl="http://www.w3.org/2000/svg",Pn=class{constructor(){this.groundSvg=null;this.groundVisible=!1;this.currentGroundCssZ=null;this.shadowRoot=null}};function bs(e,n,t){let o=e.shadowRoot;if(o||(o=n.createElement("div"),o.setAttribute("class","polycss-shadows"),o.style.position="absolute",o.style.top="0",o.style.left="0",o.style.width="0",o.style.height="0",o.style.transformStyle="preserve-3d",o.style.pointerEvents="none",e.shadowRoot=o),o.parentNode!==t){let r=t.firstChild;r?t.insertBefore(o,r):t.appendChild(o)}return o}function vs(e){e.groundSvg?.parentNode&&e.groundSvg.parentNode.removeChild(e.groundSvg),e.groundSvg=null,e.groundVisible=!1}function xs(e){e.groundSvg&&e.groundVisible&&(e.groundSvg.style.display="none",e.groundVisible=!1)}function Ps(e,n,t,o){let r=[],s=e.firstChild;for(let i=0;i<t;i++){let c=s;c&&c.tagName==="path"?s=c.nextSibling:(c=n.createElementNS(xl,"path"),c.setAttribute("fill-rule","nonzero"),o&&(c.setAttribute("stroke-width","0.5"),c.setAttribute("stroke-linejoin","round")),e.insertBefore(c,s)),r.push(c)}for(;s;){let i=s.nextSibling;e.removeChild(s),s=i}return r}function Ss(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 Pn,receiverShadowCache:new Map,receiverShadowCacheKey:new Map,casterItemsCache:new Map,casterItemsCacheKey:new Map}}import{buildSharedEdgeMap as Pl,computeReceiverShadowFaces as Sl,meshScaleVec3 as Ms,prepareCasterEdgeOwners as Cl,prepareCasterPolyItems as El,prepareReceiverFacePlanes as Tl}from"@layoutit/polycss-core";function Cs(e){for(let n of e)n.svg&&n.svg.parentNode&&n.svg.parentNode.removeChild(n.svg),n.svg=null}function Es(e,n){if(n){let t=e.receiverShadowCache.get(n);t&&Cs(t),e.receiverShadowCache.delete(n),e.receiverShadowCacheKey.delete(n)}else{for(let t of e.receiverShadowCache.values())Cs(t);e.receiverShadowCache.clear(),e.receiverShadowCacheKey.clear()}}function Ts(e,n){n?(e.casterItemsCache.delete(n),e.casterItemsCacheKey.delete(n)):(e.casterItemsCache.clear(),e.casterItemsCacheKey.clear())}function As(e){vs(e.shadowSvgState),ws(e)}function So(e){return e.handle.id??e.autoMeshId}var Al="http://www.w3.org/2000/svg",Sn=new WeakMap,Ls=new WeakMap,_s=new WeakMap,Rs=new WeakMap,ks=new WeakMap;function Os(e){let n=Sn.get(e);return n||(n=new Map,Sn.set(e,n)),n}function Co(e){let n=Sn.get(e);if(n){for(let t of n.values())t.svg&&t.svg.parentNode&&t.svg.parentNode.removeChild(t.svg);n.clear(),Sn.delete(e)}}function ws(e){for(let n of e.meshes)Co(n)}function Ds(e,n,t,o,r,s,i,c,l,u){let d=e.options.current,{receiverShadowCache:x,receiverShadowCacheKey:h,casterItemsCache:b,casterItemsCacheKey:v}=e,P=o.handle.transform.position??[0,0,0],g=o.handle.transform.rotation??[0,0,0],C=o.polygons.some(A=>A.texture!==void 0),D=Ms(o.handle.transform.scale),k=o.bboxCenterCss,z=d.shadow?.lift??.001,I=`${o.polygons.length}|${r.size}|${P.join(",")}|${g.join(",")}|${D.join(",")}|${k?k.join(","):"n"}|${z}`,Z=x.get(o);if(Z===void 0||h.get(o)!==I){Z=Tl(o.polygons,P,o.handle.transform.scale,r,z,g),x.set(o,Z),h.set(o,I);let A=Os(o);for(let y of A.values())y.svg&&y.svg.parentNode&&y.svg.parentNode.removeChild(y.svg);A.clear()}let Q=[];for(let A of n){let y=A.handle.transform.position??[0,0,0],m=A.handle.transform.rotation??[0,0,0],p=Ms(A.handle.transform.scale),T=A.bboxCenterCss,M=`${A.polygons.length}|${y.join(",")}|${m.join(",")}|${p.join(",")}|${T?T.join(","):"n"}`,R=b.get(A);if(R===void 0||v.get(A)!==M){let _=t.get(A),j=new Set;for(let q of A.rendered)q.plan&&!_.has(q.polygonIndex)&&j.add(q.polygonIndex);R=El(A.polygons,y,A.handle.transform.scale,q=>j.has(q),m),b.set(A,R),v.set(A,M)}let L;if(A===o){let _=Ls.get(A);(_===void 0||_s.get(A)!==A.polygons)&&(_=Pl(A.polygons),Ls.set(A,_),_s.set(A,A.polygons)),L=_}let te;if(A!==o&&A.polygons.length>=40){let _=Rs.get(A);(_===void 0||ks.get(A)!==M)&&(_=Cl(A.polygons,y,A.handle.transform.scale,m),Rs.set(A,_),ks.set(A,M)),te=_}Q.push({id:A,items:R,selfShadowEdgeMap:L,edgeOwners:te,casterPolygonCount:A.polygons.length})}let O={rotX:e.camera.state.rotX,rotY:e.camera.state.rotY,meshRotation:o.handle.transform.rotation},H=Sl({receiverPlanes:Z,receiverPolygons:o.polygons,receiverHasTexture:C,casters:Q,lightDir:s,cameraRot:O,ambientLight:d.ambientLight,directionalLight:d.directionalLight,shadow:{color:d.shadow?.color,opacity:u,maxExtend:d.shadow?.maxExtend}}),V=Os(o),$=new Set;for(let A of H){$.add(A.faceIndex);let y=V.get(A.faceIndex);y||(y={svg:null,visible:!1,width:-1,height:-1,matrixCss:""},V.set(A.faceIndex,y));let m=y.svg;m?(y.visible||(m.style.display="block"),(y.width!==A.width||y.height!==A.height)&&(m.setAttribute("width",String(A.width)),m.setAttribute("height",String(A.height)),m.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),y.width=A.width,y.height=A.height),y.matrixCss!==A.matrixCss&&(m.style.transform=A.matrixCss,y.matrixCss=A.matrixCss)):(m=e.doc.createElementNS(Al,"svg"),m.setAttribute("class","polycss-shadow polycss-shadow-svg polycss-shadow-receiver"),d.debugShadowAttrs&&(m.setAttribute("data-poly-shadow-type","receiver"),m.setAttribute("data-poly-shadow-receiver",So(o)),m.setAttribute("data-poly-shadow-receiver-face",String(A.faceIndex)),m.setAttribute("data-poly-shadow-receiver-polys",JSON.stringify(A.memberPolyIndices))),m.setAttribute("width",String(A.width)),m.setAttribute("height",String(A.height)),m.setAttribute("viewBox",`0 0 ${A.width} ${A.height}`),m.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}`),bs(e.shadowSvgState,e.doc,e.sceneEl).appendChild(m),y.svg=m,y.width=A.width,y.height=A.height,y.matrixCss=A.matrixCss),y.visible=!0;let p=Ps(m,e.doc,A.paths.length,!0),T=A.opacity.toFixed(4),M=[],R=!!d.debugShadowAttrs;for(let L=0;L<A.paths.length;L++){let te=A.paths[L],_=R?So(te.casterId):"";R&&M.push(_);let j=p[L];if(j.setAttribute("d",te.d),j.getAttribute("fill")!==A.fill&&j.setAttribute("fill",A.fill),j.getAttribute("stroke")!==A.fill&&j.setAttribute("stroke",A.fill),j.getAttribute("opacity")!==T&&j.setAttribute("opacity",T),R){j.getAttribute("data-poly-shadow-caster")!==_&&j.setAttribute("data-poly-shadow-caster",_);let q=JSON.stringify(te.casterPolygonIndices);j.getAttribute("data-poly-shadow-caster-polys")!==q&&j.setAttribute("data-poly-shadow-caster-polys",q)}}if(R){let L=M.join(" ");m.getAttribute("data-poly-shadow-casters")!==L&&m.setAttribute("data-poly-shadow-casters",L)}}for(let[A,y]of V)$.has(A)||y.svg&&y.visible&&(y.svg.style.display="none",y.visible=!1)}var Is=Symbol.for("polycss.animation.triangleFrameTarget");var Fl=750;function Vs(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:zs}}var Vl={key:"non-cullable",normal:[1,1,0]};function Bs(){return[Vl]}function Ao(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&&bo(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...r}=n,s=Vs({seamBleed:zs,...r}),i=is(e),c=[0,0,0],l=e.ownerDocument??document,u=l.createElement("div");u.className="polycss-camera",Z(u,s),e.appendChild(u);let d=l.createElement("div");d.className="polycss-scene",d.setAttribute("aria-hidden","true"),Q(d,s),u.appendChild(d);let x=Ss({host:e,doc:l,cameraEl:u,sceneEl:d,camera:t,layoutScale:i,options:s}),h=x.meshes,b=new WeakMap,v=x.shadowSvgState,P=()=>xs(v),g=()=>As(x),C=null;function D(a){if(!a)return null;let f=Math.hypot(a[0],a[1],a[2]);if(!Number.isFinite(f)||f<=0)return null;let S=Math.round(a[0]/f*100)/100,E=Math.round(a[1]/f*100)/100,W=Math.round(a[2]/f*100)/100;return`${S}|${E}|${W}`}function k(){C=null}let z=a=>Es(x,a),I=a=>Ts(x,a);function Z(a,f){let S=t.perspectiveStyle;if(S==="none")a.style.perspective="1000000px";else{let E=parseFloat(S);Number.isFinite(E)&&(a.style.perspective=`${E}px`)}}function Q(a,f){as(a,i),a.style.transform=vo(t,c,i),hs(a,f)}function O(a){a.style.transform=vo(t,c,i)}function H(a){a.voxelRenderer?.dispose(),a.voxelRenderer=void 0,y(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 f of Array.from(a.wrapper.children))f instanceof HTMLElement&&f.classList.contains("polycss-bucket")&&f.remove();a.hasBuckets=!1}function V(a){for(let f of Array.from(a.wrapper.childNodes)){if(!(f instanceof HTMLElement))return f;if(f.classList.contains("polycss-bucket")||f.classList.contains("polycss-shadow"))continue;let S=f.tagName.toLowerCase();if(!(S==="b"||S==="i"||S==="s"||S==="u"||S==="q"))return f}return null}function $(a,f,S){S?.parentNode===a.wrapper?a.wrapper.insertBefore(f,S):a.wrapper.appendChild(f)}function A(a){for(let f of a.shadowRendered)f.parentNode&&f.parentNode.removeChild(f);a.shadowRendered.length=0,g()}function y(a,f){f?.();for(let S of a){try{S.dispose()}catch{}S.element.parentNode&&S.element.parentNode.removeChild(S.element)}}function m(a,f,S){a.rendered=f,a.renderedByPolygonIndex=[];for(let E of f)a.renderedByPolygonIndex[E.polygonIndex]=E;a.disposeAtlas=S,a.solidLightingPreviewPrepared=!1}function p(a,f){let S=a.renderedByPolygonIndex[f];return S?.polygonIndex===f?S:void 0}function T(a){for(let f of Array.from(a.wrapper.children))f instanceof HTMLElement&&f.classList.contains("polycss-bucket")&&f.remove();a.hasBuckets=!1;for(let f of a.rendered)f.element.parentNode&&f.element.parentNode.removeChild(f.element)}function M(a,f){let S=a.polygons[f.polygonIndex];return a.stableDom&&S?Fs(S):f.plan?.normal??(S?Fs(S):null)}function R(a){if(!q(a))return a.rendered;let f=L(a);return a.rendered.filter(S=>te(a,S,Eo,f))}function L(a){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:a.handle.transform.rotation}}function te(a,f,S=Eo,E=L(a)){let W=M(a,f);return W===null||Dl(W,E,S)}function _(a){if(a.excludeFromAutoCenter){a.cameraCullGroups=[];return}let f=new Map;for(let S of a.rendered){let E=M(a,S);if(!E)continue;if(!kl(E)){a.cameraCullGroups=Bs();return}let W=Ml(E);if(!f.has(W)&&(f.set(W,E),f.size>wl)){a.cameraCullGroups=Bs();return}}a.cameraCullGroups=Array.from(f,([S,E])=>({key:S,normal:E}))}function j(a){return q(a)?Ll(a.cameraCullGroups,L(a)):"all"}function q(a){return!a.excludeFromAutoCenter&&Ol(a.cameraCullGroups)}function re(a){a.cameraCullSignature=q(a)?j(a):"all"}function fe(a,f){let S=new Array(a.rendered.length),E=!1,W=L(a);for(let K=0;K<a.rendered.length;K+=1){let oe=a.rendered[K],J=te(a,oe,f,W);S[K]=J}let B=null,F=null,G=()=>{if(!(!B||!F)){if(B===F)B.remove();else{let K=l.createRange();K.setStartBefore(B),K.setEndAfter(F),K.deleteContents(),K.detach()}B=null,F=null,E=!0}};for(let K=0;K<a.rendered.length;K+=1){let oe=a.rendered[K];!S[K]&&oe.element.parentNode===a.wrapper?(F&&F.nextSibling===oe.element||(G(),B=oe.element),F=oe.element):G()}G();let Y=K=>{for(let oe=K;oe<a.rendered.length;oe+=1){let J=a.rendered[oe].element;if(J.parentNode===a.wrapper)return J}return V(a)},ae=-1,ne=K=>{if(ae<0)return;let oe=l.createDocumentFragment();for(let J=ae;J<K;J+=1){let Ie=a.rendered[J];be(a,Ie),oe.appendChild(Ie.element)}$(a,oe,Y(K)),ae=-1,E=!0};for(let K=0;K<a.rendered.length;K+=1){let oe=a.rendered[K];S[K]&&oe.element.parentNode!==a.wrapper?ae<0&&(ae=K):ne(K)}return ne(a.rendered.length),E}function de(a,f=!1){if(a.voxelRenderer){f?a.voxelRenderer.render(L(a)):a.voxelRenderer.syncCamera(L(a)),a.cameraCullSignature="voxel-direct";return}if(!q(a)){let W=a.cameraCullSignature!=="all";a.cameraCullSignature="all",W&&ve(a);return}if(a.hasBuckets){pe(a,f);return}let S=j(a);if(!f&&S===a.cameraCullSignature)return;let E=fe(a,Eo);a.cameraCullSignature=S,E&&Ue(a)}function pe(a,f=!1){let S=q(a)?j(a):"all";!f&&S===a.cameraCullSignature||ve(a)}function Ce(a,f){return M(a,f)}function be(a,f){if(s.textureLighting!=="dynamic")return;let S=Ce(a,f);S&&(f.element.style.setProperty("--pnx",S[0].toFixed(4)),f.element.style.setProperty("--pny",S[1].toFixed(4)),f.element.style.setProperty("--pnz",S[2].toFixed(4)))}function Ae(a){T(a),a.hasBuckets=!1;let f=a.skipBucketNormalCleanupOnce;a.skipBucketNormalCleanupOnce=!1;let S=l.createDocumentFragment(),E=s.textureLighting==="dynamic"&&!a.stableDom,W=new Map,B=[];for(let F of R(a)){let G=a.polygons[F.polygonIndex],Y=E&&G?ls(G):null;if(!Y){B.push(F);continue}let ae=Y.key+"|"+(G.color??""),ne=W.get(ae);ne||(ne={vec:Y.vec,items:[]},W.set(ae,ne)),ne.items.push(F)}for(let F of B)be(a,F),S.appendChild(F.element);for(let F of W.values()){if(F.items.length<2){for(let Y of F.items)be(a,Y),S.appendChild(Y.element);continue}let G=l.createElement("div");G.className="polycss-bucket",a.hasBuckets=!0,G.style.setProperty("--pnx",String(F.vec[0])),G.style.setProperty("--pny",String(F.vec[1])),G.style.setProperty("--pnz",String(F.vec[2]));for(let Y of F.items)G.appendChild(Y.element),(!f||Y.kind==="triangle")&&(Y.element.style.removeProperty("--pnx"),Y.element.style.removeProperty("--pny"),Y.element.style.removeProperty("--pnz"));S.appendChild(G)}$(a,S,V(a)),re(a)}function $e(){return new Promise(a=>setTimeout(a,0))}async function qe(a,f){if(s.textureLighting==="dynamic"&&!a.stableDom)return Ae(a),!f();T(a);let E=l.createDocumentFragment(),W=V(a),B=0;for(let F of R(a)){if(f())return!1;be(a,F),E.appendChild(F.element),B++,B%Fl===0&&($(a,E,W),E=l.createDocumentFragment(),await $e())}return E.childNodes.length>0&&$(a,E,W),re(a),!f()}function lt(a,f){let S=s.textureLighting==="dynamic",E=s.directionalLight?.direction,W=f&&(f[0]!==0||f[1]!==0||f[2]!==0);if(!S||!W||!E){if(a.lightOverrideSignature==="clear")return;a.wrapper.style.removeProperty("--plx"),a.wrapper.style.removeProperty("--ply"),a.wrapper.style.removeProperty("--plz"),a.lightOverrideSignature="clear";return}let B=To(E,f),F=Rt(B),G=Math.hypot(F[0],F[1],F[2])||1,Y=(F[0]/G).toFixed(2),ae=(F[1]/G).toFixed(2),ne=(F[2]/G).toFixed(2),K=`${Y}|${ae}|${ne}`;a.lightOverrideSignature!==K&&(a.wrapper.style.setProperty("--plx",Y),a.wrapper.style.setProperty("--ply",ae),a.wrapper.style.setProperty("--plz",ne),a.lightOverrideSignature=K)}function bt(a){let f=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let E=a.polygons[S.polygonIndex];E&&(f=Po(S,E,s)||f)}return a.solidLightingPreviewPrepared=!1,a.solidLightingPreviewActive=!1,f}function ct(a){if((s.textureLighting??"baked")!=="baked")return!1;let f=!1;for(let S of a.rendered){if(!S.plan||S.kind==="atlas"||S.plan.texture)continue;let E=a.polygons[S.polygonIndex];E&&(ys(S,E,S.plan.shadedColor),f=!0)}return a.solidLightingPreviewPrepared=f,f}function On(a){return(s.textureLighting??"baked")!=="baked"||!a.solidLightingPreviewPrepared&&!ct(a)?!1:(a.solidLightingPreviewActive=!0,!0)}function Dn(a){return a.kind==="atlas"||!!a.plan?.texture}function In(){if((s.textureLighting??"baked")!=="baked")return!1;let a=!1;for(let f of h)a=bt(f)||a,f.rendered.some(Dn)&&(zt(f),a=!0);d.style.removeProperty(kt);for(let f of h)mt(f.wrapper),f.solidLightingPreviewActive=!1;return mt(d),a}function Hn(){d.style.removeProperty(kt);for(let a of h)a.solidLightingPreviewActive&&(bt(a),mt(a.wrapper));(s.textureLighting??"baked")!=="dynamic"&&(mt(d),k(),Ee())}function U(a,f){let S=a.handle.transform.rotation,E=f.directionalLight?.direction??s.directionalLight?.direction;if(!(S&&(S[0]!==0||S[1]!==0||S[2]!==0))||!E){mt(a.wrapper);return}let B=To(E,S);xn(a.wrapper,{...s,...f,directionalLight:{...s.directionalLight,...f.directionalLight,direction:B}})}function se(a){if((s.textureLighting??"baked")!=="baked")return!1;xn(d,{...s,...a}),!a.skipShadows&&a.directionalLight?.direction&&Ee(a.directionalLight.direction);let f=!1;for(let S of h)U(S,a),f=On(S)||f;return f?ue(d,kt,"1"):d.style.removeProperty(kt),f}function ie(a,f,S){let E=a.polygons[f];if(!E)return!1;let W=p(a,f);if(!W)return!1;let B=s.textureLighting??"baked";return B==="dynamic"?(gs(W.element,S),!0):B==="baked"?Po(W,E,s):!1}function we(a,f){let S=a.polygons[f];if(!S)return!1;let E=p(a,f);return E?(ye(E.element,S,f),!0):!1}function Bt(a,f,S){return!(S.length===0||!S.every(E=>E==="color"||E==="data")||S.includes("color")&&!ie(a,f,a.polygons[f]?.color)||S.includes("data")&&!we(a,f))}function Ue(a){k(),Ee()}function Ee(a){let f=[];for(let J of h)!J.disposed&&J.castShadow&&f.push(J);if(f.length===0){g(),C=null;return}let S=s.shadow?.color??"#000000",E=s.shadow?.opacity??.25,W=Hl(S)?.rgb??[0,0,0],B=W[0],F=W[1],G=W[2],Y=a??s.directionalLight?.direction??[.4,-.7,.59],ae=Rt(Y),ne=D(ae);if(ne!==null&&ne===C)return;let K=new Map;for(let J of f)K.set(J,Hs(J.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.95,preserveDoubleSidedBackfaces:!1}));let oe=new Map;for(let J of h)J.disposed||!J.receiveShadow||oe.set(J,new Set);P();for(let J of h)J.disposed||!J.receiveShadow||Ds(x,f,K,J,oe.get(J)??new Set,ae,B,F,G,E);C=ne}function ve(a){if(a.voxelRenderer){a.voxelRenderer.render(L(a)),a.cameraCullSignature="voxel-direct";return}A(a),Ae(a),Ue(a)}function Oe(a,f){if(!f||!a.polygons||a.polygons.length<2)return;let S=Math.hypot(f[0],f[1],f[2]);if(!Number.isFinite(S)||S<=0)return;let E=f[0]/S,W=f[1]/S,B=f[2]/S,F=K=>Math.round(K*1e3)/1e3,G=`${F(E)},${F(W)},${F(B)}`,Y=a.lightOcclusionCache;if(Y&&Y.polygons===a.polygons&&Y.lightDirKey===G)return Y.occluded;let ae=Y&&Y.polygons===a.polygons?Y.dedupDropped:Hs(a.polygons,{normalTolerance:.1,distanceTolerance:.12,overlapFraction:.98,preserveDoubleSidedBackfaces:!1}),ne=Rl(a.polygons,[E,W,B],ae);return a.lightOcclusionCache={polygons:a.polygons,lightDirKey:G,occluded:ne,dedupDropped:ae},ne}function De(a){return!!a.voxelSource&&s.textureLighting!=="dynamic"&&!a.stableDom&&!a.castShadow}function Se(a,f){H(a);let S=s.directionalLight,E=f?{...S,direction:f}:S,W=at(E),B=void 0;if(De(a)){let Y=rs({doc:l,wrapper:a.wrapper,polygons:a.parseResult.polygons,directionalLight:W,ambientLight:s.ambientLight});if(Y){a.voxelRenderer=Y,Y.render(L(a)),a.cameraCullSignature="voxel-direct";return}}let F={doc:l,directionalLight:W,ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,strategies:s.strategies,lightOccludedPolyIndices:B},G=a.stableDom?(()=>{let Y=dt(a.polygons,F);return ft(a.wrapper,Y),_t(a.polygons,{...F,solidPaintDefaults:Y})??pt(a.polygons,{...F,solidPaintDefaults:Y})})():pt(a.polygons,{...F,computeSolidPaintDefaults:!0,skipDynamicNormalVars:s.textureLighting==="dynamic"});a.stableDom||ft(a.wrapper,G.solidPaintDefaults??{}),m(a,G.rendered,G.dispose),a.skipBucketNormalCleanupOnce=s.textureLighting==="dynamic"&&!a.stableDom,_(a),Ae(a),Ue(a)}function zt(a,f){if(a.rendered.length===0||a.voxelRenderer||a.stableDom||De(a)){Se(a,f);return}if(a.rendered[0]?.element.parentNode===null){Se(a,f);return}let S=s.directionalLight,E=f?{...S,direction:f}:S,W=at(E),B={doc:l,directionalLight:W,ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,strategies:s.strategies,computeSolidPaintDefaults:!0,skipDynamicNormalVars:s.textureLighting==="dynamic"},F=pt(a.polygons,B),G=()=>{a.rebakeInFlight=!1;let ne=a.rebakeQueuedLightDir;ne!==null&&(a.rebakeQueuedLightDir=null,zt(a,ne))},Y=()=>{if(a.disposed){F.dispose(),G();return}if(F.rendered.length!==a.rendered.length){F.dispose(),Se(a,f),G();return}for(let oe of F.rendered){let J=a.renderedByPolygonIndex[oe.polygonIndex];if(!J)continue;let Ie=oe.element.getAttribute("style");Ie!==null&&J.element.setAttribute("style",Ie)}let ne=F.solidPaintDefaults;ne&&ft(a.wrapper,ne);let K=a.disposeAtlas;a.disposeAtlas=F.dispose,K&&(typeof requestAnimationFrame=="function"?J=>{requestAnimationFrame(J)}:J=>{setTimeout(J,0)})(K),Ue(a),G()},ae=F.pagesReady;ae&&typeof ae.then=="function"?ae.then(()=>Vn(F.rendered)).then(Bn).then(Y,()=>{F.dispose(),a.disposed||Se(a,f),G()}):Y()}function Fn(a,f){if(a.rebakeInFlight){a.rebakeQueuedLightDir=f;return}a.rebakeInFlight=!0,zt(a,f)}function Vn(a){let f=new Set;for(let S of a){let E=S.element.getAttribute("style")??"",W=/url\((blob:[^)]+)\)/g,B;for(;(B=W.exec(E))!==null;)f.add(B[1])}return Array.from(f)}function Bn(a){return a.length===0||typeof Image>"u"?Promise.resolve():Promise.all(a.map(f=>{let S=new Image;S.src=f;let E=S.decode?.();return E?E.catch(()=>{}):Promise.resolve()})).then(()=>{})}function Qe(){let a=1/0,f=!1;for(let B of h)if(!B.disposed&&B.receiveShadow){f=!0;break}for(let B of h){if(B.disposed||!(f?B.receiveShadow:B.castShadow))continue;let G=B.handle.transform.position?.[2]??0;for(let Y of B.polygons)for(let ae of Y.vertices){let ne=ae[2]+G;ne<a&&(a=ne)}}if(!Number.isFinite(a)){let B=v.currentGroundCssZ!==null;v.currentGroundCssZ=null,B&&(g(),k());return}let S=s.shadow?.lift??.05,E=(a+S)*et,W=v.currentGroundCssZ;v.currentGroundCssZ=E,W!==E&&(k(),Ee())}async function cn(a,f){H(a);let S=at(s.directionalLight),E={doc:l,directionalLight:S,ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,strategies:s.strategies,lightOccludedPolyIndices:void 0},W=a.stableDom?_t(a.polygons,E):null;if(W){let G=dt(a.polygons,E);return ft(a.wrapper,G),m(a,W.rendered,W.dispose),_(a),Ae(a),Ue(a),!f()}let B=await Qt(a.polygons,{...E,skipDynamicNormalVars:s.textureLighting==="dynamic"},f);if(f())return B.dispose(),!1;ft(a.wrapper,B.solidPaintDefaults),m(a,B.rendered,B.dispose),a.skipBucketNormalCleanupOnce=s.textureLighting==="dynamic"&&!a.stableDom,_(a);let F=await qe(a,f);return F&&Ue(a),F}function ut(){let a=c,f=[0,0,0];if(s.autoCenter){let S=[];for(let E of h)!E.disposed&&!E.excludeFromAutoCenter&&S.push(...E.polygons);if(S.length>0){let E=_l(S);f=[(E.min[0]+E.max[0])/2,(E.min[1]+E.max[1])/2,(E.min[2]+E.max[2])/2]}}a[0]===f[0]&&a[1]===f[1]&&a[2]===f[2]||(c=f,x.autoCenter.offset=f,Q(d,s))}function di(a,f={}){let E=(d.ownerDocument??document).createElement("div");E.className="polycss-mesh",f.id&&E.setAttribute("data-poly-mesh-id",f.id);let W=`polycss-mesh-${x.meshAutoCounter.next++}`;E.setAttribute("data-poly-mesh-index",W);let B={...f},F=f.merge!==!1,G=!!f.stableDom,Y=0,ae=vn(B);ae&&(E.style.transform=ae);let ne=(N,X)=>a.voxelSource?N:X?Il(N,{meshResolution:f.meshResolution}):(G||f.excludeFromAutoCenter,N),K=ne(a.polygons,F),oe=null;function J(){let N=vn(B);E.style.transform=N??""}function Ie(N){if(N.length===0){oe=null,Ge&&(Ge.bboxCenterCss=null),J();return}let X=1/0,le=1/0,me=1/0,Me=-1/0,ce=-1/0,ge=-1/0;for(let Ye of N)for(let Fe of Ye.vertices)Fe[0]<X&&(X=Fe[0]),Fe[0]>Me&&(Me=Fe[0]),Fe[1]<le&&(le=Fe[1]),Fe[1]>ce&&(ce=Fe[1]),Fe[2]<me&&(me=Fe[2]),Fe[2]>ge&&(ge=Fe[2]);if(!Number.isFinite(X)){oe=null,Ge&&(Ge.bboxCenterCss=null),J();return}let He=(le+ce)/2*et,We=(X+Me)/2*et,Le=(me+ge)/2*et;oe=[He,We,Le],Ge&&(Ge.bboxCenterCss=oe),J()}let Ge=null;Ie(K),d.appendChild(E);let w={handle:void 0,wrapper:E,parseResult:a,rendered:[],renderedByPolygonIndex:[],shadowRendered:[],polygons:K,voxelSource:a.voxelSource,disposed:!1,stableDom:G,hasBuckets:!1,skipBucketNormalCleanupOnce:!1,excludeFromAutoCenter:!!f.excludeFromAutoCenter,castShadow:!!f.castShadow,bboxCenterCss:oe,receiveShadow:!!f.receiveShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",stableTriangleColorFrame:0,solidLightingPreviewPrepared:!1,solidLightingPreviewActive:!1,bakedRotation:f.rotation?[...f.rotation]:[0,0,0],autoMeshId:W,rebakeInFlight:!1,rebakeQueuedLightDir:null},je=null,zn=0,un=-1,Nt=null;function $t(){je=null,Nt=null,un=-1}function dr(){let N=je;if(!N||N.polygonCount!==w.polygons.length)return w.polygons;if(Nt&&un===zn)return Nt;let X=N.vertices,le=new Array(N.polygonCount);for(let me=0;me<N.polygonCount;me++){let Me=w.polygons[me],ce=me*9;le[me]={...Me,color:N.colors?.[me]??Me.color,vertices:[[X[ce],X[ce+1],X[ce+2]],[X[ce+3],X[ce+4],X[ce+5]],[X[ce+6],X[ce+7],X[ce+8]]]}}return Nt=le,un=zn,le}function pr(N,X){let le=N?.stableTriangleUpdateMode==="color-only";w.stableTriangleColorFrame++;let me=w.stableDom&&!X;if(me||Ie(w.polygons),w.stableDom&&!w.hasBuckets){let Me={doc:l,directionalLight:at(s.directionalLight),ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed},ce=w.rendered.length===w.polygons.length&&w.rendered.every(Le=>Le.kind==="triangle"),ge=w.stableDom&&!X,He=ce||ge?{}:dt(w.polygons,Me);ce||ft(w.wrapper,He);let We={...Me,solidPaintDefaults:He,optimizeStableTriangleStyle:!0,stableTriangleDebug:N?.stableTriangleDebug,stableTriangleUpdateMode:N?.stableTriangleUpdateMode,stableTriangleColorPolicy:N?.stableTriangleColorPolicy,stableTriangleColorSteps:N?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:N?.stableTriangleColorFreezeFrames,stableTriangleColorBudget:N?.stableTriangleColorBudget,stableTriangleColorMaxAge:N?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:N?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:N?.stableTriangleMatrixDecimals,stableTriangleColorFrame:w.stableTriangleColorFrame};if(Jt(w.rendered,w.polygons,We))return le||(_(w),de(w,!0),X&&ut()),!0}return me&&Ie(w.polygons),!1}let vt={get polygons(){return dr()},set polygons(N){$t(),w.polygons=N},element:E,id:f.id,get transform(){return B},remove(){Y++,E.parentNode&&E.parentNode.removeChild(E),H(w),h.delete(w),b.delete(E),z(w),I(w),ut(),Qe()},setPolygons(N,X){Y++,F=X?.merge??F,G=X?.stableDom??G,w.stableDom=G,w.voxelSource=void 0,w.polygons=ne(N,F),I(w),z(w),$t(),vt.polygons=w.polygons;let le=X?.recomputeAutoCenter??!0;pr(X,le)||(Se(w),le&&ut())},[Is](N,X){let le=X?.merge??F,me=X?.stableDom??G;if(!N.solidTriangles||!me||le||f.meshResolution!==void 0||w.hasBuckets||N.polygonCount!==w.polygons.length||N.vertices.length<N.polygonCount*9||w.rendered.length!==N.polygonCount)return!1;for(let ge=0;ge<w.rendered.length;ge++){let He=w.rendered[ge],We=w.polygons[ge];if(He?.kind!=="triangle"||He.polygonIndex!==ge||!We||We.vertices.length!==3||We.texture||We.material?.texture)return!1}let Me=X?.recomputeAutoCenter??!0;if(!Me){let ge=w.stableTriangleColorFrame+1,He={doc:l,directionalLight:at(s.directionalLight),ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed,solidPaintDefaults:{},optimizeStableTriangleStyle:!0,stableTriangleDebug:X?.stableTriangleDebug,stableTriangleUpdateMode:X?.stableTriangleUpdateMode,stableTriangleColorPolicy:X?.stableTriangleColorPolicy,stableTriangleColorSteps:X?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:X?.stableTriangleColorFreezeFrames??0,stableTriangleColorBudget:X?.stableTriangleColorBudget,stableTriangleColorMaxAge:X?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:X?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:X?.stableTriangleMatrixDecimals,stableTriangleColorFrame:ge};if(Kt(w.rendered,w.polygons,N,He))return Y++,F=le,G=me,w.stableDom=G,w.voxelSource=void 0,w.stableTriangleColorFrame=ge,je=N,zn++,Nt=null,un=-1,q(w)?(_(w),de(w,!0)):re(w),!0}Y++,F=le,G=me,w.stableDom=G,w.voxelSource=void 0;let ce=N.vertices;for(let ge=0;ge<N.polygonCount;ge++){let He=w.polygons[ge],We=N.colors?.[ge];We&&(He.color=We);let Le=He.vertices,Ye=ge*9;Le[0][0]=ce[Ye],Le[0][1]=ce[Ye+1],Le[0][2]=ce[Ye+2],Le[1][0]=ce[Ye+3],Le[1][1]=ce[Ye+4],Le[1][2]=ce[Ye+5],Le[2][0]=ce[Ye+6],Le[2][1]=ce[Ye+7],Le[2][2]=ce[Ye+8]}return $t(),vt.polygons=w.polygons,pr(X,Me)},updatePolygon(N,X){let le=typeof N=="number"?N:w.polygons.indexOf(N);if(le<0&&typeof N!="number"&&je&&(le=dr().indexOf(N)),le<0||le>=w.polygons.length)return;$t(),w.voxelSource=void 0,Object.assign(w.polygons[le],X);let me=Object.keys(X);Bt(w,le,me)||Se(w)},async setPolygonsChunked(N,X){let le=++Y;F=X?.merge??F,G=X?.stableDom??G,w.stableDom=G,w.voxelSource=void 0,w.polygons=ne(N,F),$t(),vt.polygons=w.polygons,Ie(w.polygons);let me=X?.recomputeAutoCenter??!0;if(!await cn(w,()=>w.disposed||le!==Y)){H(w);return}me&&ut()},setTransform(N){let X=w.castShadow,le=w.receiveShadow;N.castShadow!==void 0&&(w.castShadow=!!N.castShadow),N.receiveShadow!==void 0&&(w.receiveShadow=!!N.receiveShadow),B={...B,...N};let me=vn(B);E.style.transform=me??"",lt(w,B.rotation),N.rotation!==void 0&&de(w,!0),w.castShadow!==X&&(w.voxelSource&&Se(w),Ue(w),Qe()),w.receiveShadow!==le&&(w.receiveShadow||Co(w),k(),Ee()),(N.position!==void 0||N.scale!==void 0)&&(w.castShadow||w.receiveShadow)&&(Qe(),k(),Ee())},dispose(){if(!w.disposed){w.disposed=!0,Y++,E.parentNode&&E.parentNode.removeChild(E),H(w);try{a.dispose()}catch{}h.delete(w),b.delete(E),ut(),Qe()}},rebakeAtlas(){w.bakedRotation=B.rotation?[...B.rotation]:[0,0,0];let N=s.directionalLight?.direction??[.4,-.7,.59],X=To(N,w.bakedRotation);Fn(w,X)},getPosition(){return B.position},getRotation(){return B.rotation},getScale(){return B.scale},getPolygons(){return vt.polygons}};return w.handle=vt,Ge=w,b.set(E,w),h.add(w),Se(w),lt(w,B.rotation),ut(),Qe(),w.receiveShadow&&(k(),Ee()),vt}function pi(a){let f=!!s.autoCenter,S=s.strategies,E=s.seamBleed,W=s.textureLighting,B=s.directionalLight?.direction,F=s.shadow,G=Vs(a);s={...s,...G},x.options.current=s,Q(d,s);let Y=!!s.autoCenter;for(let je of h)lt(je,je.handle.transform.rotation);let ae=a.strategies!==void 0&&!cs(a.strategies,S),ne=Object.prototype.hasOwnProperty.call(a,"seamBleed")&&G.seamBleed!==E;if(ae||ne)for(let je of h)Se(je);f!==Y&&ut();let K=a.textureLighting!==void 0&&W!==s.textureLighting,oe=s.directionalLight?.direction,J=a.directionalLight!==void 0&&!us(B,oe),Ie=s.shadow,Ge=a.shadow!==void 0&&!ds(F,Ie),w=J||Ge;if(K){if(!ae&&!ne)for(let je of h)Se(je);Qe(),k(),Ee()}else w&&(Ge&&k(),Ee());Ge&&a.shadow?.lift!==F?.lift&&Qe()}function mi(){return s}function fi(){O(d);for(let a of h)de(a)}function hi(){let a=[];for(let f of h)a.push(f.handle);return a}function gi(a){let f=a;for(;f;){if(f instanceof HTMLElement){let S=b.get(f);if(S&&!S.disposed)return S.handle;if(f.classList.contains("polycss-mesh"))return null}f=f.parentElement}return null}function yi(){let a=Array.from(h);for(let f of a)try{f.handle.dispose()}catch{}u.parentNode&&u.parentNode.removeChild(u)}return{add:di,setOptions:pi,destroy:yi,host:e,camera:t,cameraEl:u,sceneElement:d,applyCamera:fi,getOptions:mi,meshes:hi,findMeshByElement:gi,previewBakedSolidLighting:se,commitBakedSolidLighting:In,clearBakedSolidLightingPreview:Hn}}import{buildPolyMeshTransform as Ff,worldDirectionToPolyCss as Vf,worldPositionToPolyCss as Bf}from"@layoutit/polycss-core";import{createIsometricCamera as Ns}from"@layoutit/polycss-core";var Bl=32e3;function en(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=Ns(n),o=`${e.perspective??Bl}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function ht(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=Ns(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var zl=ht;import{BASE_TILE as Nl}from"@layoutit/polycss-core";var Cn={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function Ot(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 tn(e){return e===!0?-1:e===!1?1:e}function Dt(){let e=[],n=[],t=[];function o(i){return i==="change"?e:i==="start"?n:t}function r(i){if(e.length===0)return;let c={type:"change",camera:i()},l=e.slice();for(let u of l)try{u(c)}catch(d){console.error("[polycss] controls 'change' listener threw:",d)}}function s(i,c){let l=i==="start"?n:t;if(l.length===0)return;let u={type:i,camera:c()},d=l.slice();for(let x of d)try{x(u)}catch(h){console.error(`[polycss] controls '${i}' listener threw:`,h)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function It(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 En(e,n,t,o,r,s){let i=!1,c=null;return{onWheel:d=>{let x=n();if(!x.wheel||t())return;d.preventDefault();let h=d.deltaMode===1?16:d.deltaMode===2?100:1,b=d.deltaY*h;d.ctrlKey?b*=10:b*=3;let v=e.camera.state;if(x.dolly){let P=v.distance??0,g=Math.max(x.minDistance,Math.min(x.maxDistance,P+b*.05));e.camera.update({distance:g})}else{let P=Math.exp(-b*513e-6),g=v.zoom??1,C=Math.max(x.minZoom,Math.min(x.maxZoom,g*P));e.camera.update({zoom:C})}e.applyCamera(),i||(i=!0,s("start",o)),r(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,i=!1,s("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),i=!1}}}function Tn(e,n,t,o,r,s,i){let c=null,l=0,u=b=>{if(c===null||o())return;let v=t();if(!v.animate){c=null;return}if(r())l=b;else{let P=Math.min(50,l?b-l:16.67);l=b;let g=v.animate.speed*(P/16.67),C=n.camera.state;if(v.animate.axis==="x"){let D=(((C.rotX??65)+g)%360+360)%360;n.camera.update({rotX:D})}else{let D=(((C.rotY??45)+g)%360+360)%360;n.camera.update({rotY:D})}n.applyCamera(),i(s)}c=e.requestAnimationFrame(u)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(u))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function wo(e,n={}){let t=Ot(Cn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,u=Dt(),d=It(e),{changeListeners:x,startListeners:h,endListeners:b,listenerArray:v,emitChange:P,emitInteraction:g}=u,C=Tn(r,e,()=>t,()=>l,()=>c,d,P),D=p=>{if(!(!t.drag||l)&&s===null&&p.isPrimary!==!1){p.preventDefault(),s=p.pointerId,i={x:p.clientX,y:p.clientY},o.style.cursor="grabbing";try{p.target.setPointerCapture(p.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),g("start",d)}},k=p=>{if(s===null||p.pointerId!==s||!t.drag||l)return;p.preventDefault();let T=p.clientX-i.x,M=p.clientY-i.y;i={x:p.clientX,y:p.clientY};let R=tn(t.invert),L=T/4*R,te=M/4*R,_=e.camera.state;if(p.shiftKey){let j=_.rotX??65,q=_.rotY??45,re=Math.max(.01,_.zoom??1),fe=Math.cos(j*Math.PI/180),de=fe>=0?Math.max(.1,fe):Math.min(-.1,fe),pe=Math.cos(q*Math.PI/180),Ce=Math.sin(q*Math.PI/180),be=re*Nl,Ae=(T*Ce-M*pe/de)/be,$e=-(T*pe+M*Ce/de)/be,qe=_.target??[0,0,0];e.camera.update({target:[qe[0]+Ae,qe[1]+$e,qe[2]]})}else{let j=Math.max(0,Math.min(89,(_.rotX??65)-te)),q=(((_.rotY??45)-L)%360+360)%360;e.camera.update({rotX:j,rotY:q})}e.applyCamera(),P(d)},z=p=>{if(s===p.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{p.target.releasePointerCapture(p.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),g("end",d)}},I=En(e,()=>t,()=>l,d,P,g);function Z(){o.addEventListener("pointerdown",D),o.addEventListener("pointermove",k),o.addEventListener("pointerup",z),o.addEventListener("pointercancel",z),o.addEventListener("wheel",I.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function Q(){o.removeEventListener("pointerdown",D),o.removeEventListener("pointermove",k),o.removeEventListener("pointerup",z),o.removeEventListener("pointercancel",z),o.removeEventListener("wheel",I.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",I.teardown()}Z(),C.start();function O(p){let T=!!t.animate;t=Ot(t,p),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let M=!!t.animate;T&&!M?C.stop():!T&&M&&C.start()}function H(){l&&(l=!1,Z(),C.start())}function V(){l||(l=!0,Q(),C.stop(),s=null,c=!1,I.teardown())}function $(){V(),x.length=0,h.length=0,b.length=0}function A(p,T){let M=v(p);M.includes(T)||M.push(T)}function y(p,T){let M=v(p),R=M.indexOf(T);R>=0&&M.splice(R,1)}function m(p,T){return v(p).includes(T)}return{update:O,resume:H,pause:V,destroy:$,addEventListener:A,removeEventListener:y,hasEventListener:m}}import{BASE_TILE as $l}from"@layoutit/polycss-core";function Mo(e,n={}){let t=Ot(Cn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,u=!1,d={x:0,y:0},x=Dt(),h=It(e),{changeListeners:b,startListeners:v,endListeners:P,listenerArray:g,emitChange:C,emitInteraction:D}=x,k=Tn(r,e,()=>t,()=>l,()=>c,h,C),z=_=>{if(!(!t.drag||l)&&s===null&&_.isPrimary!==!1){_.preventDefault(),s=_.pointerId,i={x:_.clientX,y:_.clientY},o.style.cursor="grabbing";try{_.target.setPointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),D("start",h)}},I=_=>{if(s===null||_.pointerId!==s||!t.drag||l)return;_.preventDefault();let j=_.clientX-i.x,q=_.clientY-i.y;i={x:_.clientX,y:_.clientY};let re=e.camera.state;if(_.shiftKey){let fe=tn(t.invert),de=j/4*fe,pe=q/4*fe,Ce=(re.rotX??65)-pe,be=(((re.rotY??45)-de)%360+360)%360;e.camera.update({rotX:Ce,rotY:be})}else{let fe=re.rotX??65,de=re.rotY??45,pe=Math.max(.01,re.zoom??1),Ce=Math.cos(fe*Math.PI/180),be=Ce>=0?Math.max(.1,Ce):Math.min(-.1,Ce),Ae=Math.cos(de*Math.PI/180),$e=Math.sin(de*Math.PI/180),qe=pe*$l,lt=(j*$e-q*Ae/be)/qe,bt=-(j*Ae+q*$e/be)/qe,ct=re.target??[0,0,0];e.camera.update({target:[ct[0]+lt,ct[1]+bt,ct[2]]})}e.applyCamera(),C(h)},Z=_=>{if(s===_.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{_.target.releasePointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),D("end",h)}},Q=_=>{_.preventDefault()},O=_=>{_.button===2&&(u=!0,d={x:_.clientX,y:_.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),D("start",h))},H=_=>{if(!u||!t.drag)return;let j=_.clientX-d.x,q=_.clientY-d.y;d={x:_.clientX,y:_.clientY};let re=tn(t.invert),fe=j/4*re,de=q/4*re,pe=e.camera.state,Ce=(pe.rotX??65)-de,be=(((pe.rotY??45)-fe)%360+360)%360;e.camera.update({rotX:Ce,rotY:be}),e.applyCamera(),C(h)},V=_=>{_.button===2&&u&&(u=!1,D("end",h))},$=En(e,()=>t,()=>l,h,C,D);function A(){o.addEventListener("pointerdown",z),o.addEventListener("pointermove",I),o.addEventListener("pointerup",Z),o.addEventListener("pointercancel",Z),o.addEventListener("wheel",$.onWheel,{passive:!1}),o.addEventListener("contextmenu",Q),o.addEventListener("mousedown",O),o.addEventListener("mousemove",H),o.addEventListener("mouseup",V),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function y(){o.removeEventListener("pointerdown",z),o.removeEventListener("pointermove",I),o.removeEventListener("pointerup",Z),o.removeEventListener("pointercancel",Z),o.removeEventListener("wheel",$.onWheel),o.removeEventListener("contextmenu",Q),o.removeEventListener("mousedown",O),o.removeEventListener("mousemove",H),o.removeEventListener("mouseup",V),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",$.teardown()}A(),k.start();function m(_){let j=!!t.animate;t=Ot(t,_),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let q=!!t.animate;j&&!q?k.stop():!j&&q&&k.start()}function p(){l&&(l=!1,A(),k.start())}function T(){l||(l=!0,y(),k.stop(),s=null,c=!1,u=!1,$.teardown())}function M(){T(),b.length=0,v.length=0,P.length=0}function R(_,j){let q=g(_);q.includes(j)||q.push(j)}function L(_,j){let q=g(_),re=q.indexOf(j);re>=0&&q.splice(re,1)}function te(_,j){return g(_).includes(j)}return{update:m,resume:p,pause:T,destroy:M,addEventListener:R,removeEventListener:L,hasEventListener:te}}import{BASE_TILE as Ul}from"@layoutit/polycss-core";var Gl={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 $s(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 Us=new Set(["KeyW","ArrowUp"]),Gs=new Set(["KeyS","ArrowDown"]),js=new Set(["KeyA","ArrowLeft"]),Ws=new Set(["KeyD","ArrowRight"]),Ys=new Set(["Space"]),Lo=new Set(["ControlLeft","ControlRight"]);function _o(e,n={}){let t=$s(Gl,n),o=e.host,r=e.cameraEl,s=o.ownerDocument??document,i=s.defaultView??globalThis,c=Dt(),l=It(e),{changeListeners:u,startListeners:d,endListeners:x,listenerArray:h,emitChange:b,emitInteraction:v}=c,P=new Set,g=!1,C=!1,D=0,k=0,z=!1,I=[0,0,t.groundZ+t.eyeHeight];function Z(U,se){let ie=U*Math.PI/180,we=se*Math.PI/180;return[-Math.sin(ie)*Math.cos(we),-Math.sin(ie)*Math.sin(we),-Math.cos(ie)]}function Q(){let U=e.camera.perspectiveStyle,se=U==="none"?0:parseFloat(U);return(Number.isFinite(se)&&se>0?se:2e3)/Ul}function O(){let U=e.camera.state,se=Z(U.rotX??90,U.rotY??0),ie=Q();return[I[0]+se[0]*ie,I[1]+se[1]*ie,I[2]+se[2]*ie]}function H(){let U=O();e.camera.update({target:U}),e.applyCamera()}function V(){let U=e.camera.state.target??[0,0,0];I=[U[0],U[1],t.groundZ+t.eyeHeight],H()}let $=()=>{if(!(!t.enabled||!t.lookEnabled||C||g))try{o.requestPointerLock()}catch{}},A=()=>{let U=s.pointerLockElement===o;U!==g&&(g=U,g?(z=!0,v("start",l)):z&&(z=!1,v("end",l)))},y=U=>{if(!g||!t.enabled||!t.lookEnabled||C)return;let se=U.movementX??0,ie=U.movementY??0;if(se===0&&ie===0)return;let we=e.camera.state,Bt=t.lookSensitivity,Ue=t.invertY?-1:1,Ee=(((we.rotY??0)-se*Bt)%360+360)%360,ve=(we.rotX??90)-ie*Bt*Ue;ve<t.minPitch?ve=t.minPitch:ve>t.maxPitch&&(ve=t.maxPitch);let Oe=Z(ve,Ee),De=Q(),Se=[I[0]+Oe[0]*De,I[1]+Oe[1]*De,I[2]+Oe[2]*De];e.camera.update({rotX:ve,rotY:Ee,target:Se}),e.applyCamera(),b(l)},m=U=>Us.has(U)||Gs.has(U)||js.has(U)||Ws.has(U)||Ys.has(U)||Lo.has(U),p=U=>{if(!(!t.enabled||C)&&m(U.code)&&!(!g&&!t.moveEnabled)){if(Ys.has(U.code)){if(!t.jumpEnabled)return;U.preventDefault(),!P.has(U.code)&&D===0&&k===0&&(D=t.jumpVelocity),P.add(U.code);return}Lo.has(U.code)&&!t.crouchEnabled||!t.moveEnabled&&!Lo.has(U.code)||(U.preventDefault(),P.add(U.code))}},T=U=>{m(U.code)&&P.delete(U.code)},M=()=>{P.clear()},R=null,L=0,te=.05,_=U=>{if(R===null||C)return;let se=Math.min(te,L?(U-L)/1e3:.0167);if(L=U,t.enabled){let ie=!1,we=e.camera.state;if(t.moveEnabled){let ve=0,Oe=0;for(let De of P)Us.has(De)?ve+=1:Gs.has(De)?ve-=1:Ws.has(De)?Oe+=1:js.has(De)&&(Oe-=1);if(ve!==0||Oe!==0){let Se=(we.rotY??0)*Math.PI/180,zt=-Math.cos(Se),Fn=-Math.sin(Se),Vn=-Math.sin(Se),Bn=Math.cos(Se),Qe=Math.hypot(ve,Oe)||1,cn=t.moveSpeed*se;I[0]+=(zt*ve+Vn*Oe)/Qe*cn,I[1]+=(Fn*ve+Bn*Oe)/Qe*cn,ie=!0}}let Ue=t.crouchEnabled&&(P.has("ControlLeft")||P.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(D!==0||k>0)?(D-=t.gravity*se,k+=D*se,k<=0&&(k=0,D=0)):t.jumpEnabled||(k=0,D=0);let Ee=t.groundZ+Ue+k;if(Math.abs(I[2]-Ee)>1e-4&&(I[2]=Ee,ie=!0),ie){let ve=O();e.camera.update({target:ve}),e.applyCamera(),b(l)}}R=i.requestAnimationFrame(_)};function j(){R!==null||C||(L=0,R=i.requestAnimationFrame(_))}function q(){R!==null&&(i.cancelAnimationFrame(R),R=null)}function re(){let se=r.ownerDocument?.defaultView?.getComputedStyle(r).perspective??"",ie=parseFloat(se),we=Number.isFinite(ie)&&ie>0?ie:2e3;r.style.setProperty("--polycss-fpv-perspective",`${we}px`),r.classList.add("polycss-fpv-host")}function fe(){r.classList.remove("polycss-fpv-host"),r.style.removeProperty("--polycss-fpv-perspective")}function de(){o.addEventListener("click",$),s.addEventListener("pointerlockchange",A),s.addEventListener("mousemove",y),i.addEventListener("keydown",p),i.addEventListener("keyup",T),i.addEventListener("blur",M),o.style.cursor=t.lookEnabled?"crosshair":"",re()}function pe(){if(o.removeEventListener("click",$),s.removeEventListener("pointerlockchange",A),s.removeEventListener("mousemove",y),i.removeEventListener("keydown",p),i.removeEventListener("keyup",T),i.removeEventListener("blur",M),o.style.cursor="",P.clear(),g)try{s.exitPointerLock()}catch{}fe()}V(),de(),j();function Ce(U){let se=t.eyeHeight,ie=t.groundZ;t=$s(t,U),C||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==se||t.groundZ!==ie)&&(I[2]=t.groundZ+t.eyeHeight,H(),b(l))}function be(){C&&(C=!1,de(),j())}function Ae(){C||(C=!0,pe(),q(),z&&(z=!1,v("end",l)))}function $e(){Ae(),u.length=0,d.length=0,x.length=0}function qe(){if(!(!t.enabled||!t.lookEnabled||C))try{o.requestPointerLock()}catch{}}function lt(){if(g)try{s.exitPointerLock()}catch{}}function bt(){return g}function ct(U,se){let ie=h(U);ie.includes(se)||ie.push(se)}function On(U,se){let ie=h(U),we=ie.indexOf(se);we>=0&&ie.splice(we,1)}function Dn(U,se){return h(U).includes(se)}function In(){return[I[0],I[1],I[2]]}function Hn(U){I[0]=U[0],I[1]=U[1],I[2]=U[2],H(),b(l)}return{update:Ce,resume:be,pause:Ae,destroy:$e,lock:qe,unlock:lt,isLocked:bt,getOrigin:In,setOrigin:Hn,addEventListener:ct,removeEventListener:On,hasEventListener:Dn}}function Ht(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let s=r.getBoundingClientRect();if(!(s.width<=0||s.height<=0)&&n>=s.left&&n<=s.right&&t>=s.top&&t<=s.bottom)return!0}return!1}function Xs(e,n,t,o){for(let r of e)if(!(o&&!o(r))&&Ht(r.element,n,t))return r;return null}function Ro(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let P of o)try{P(t)}catch(g){console.error("[polycss/createSelect] onChange threw:",g)}}function s(v){t=v,r()}function i(v){n.multiple?t.includes(v)||(t=[...t,v]):t=[v],r()}function c(v){t.includes(v)&&(t=t.filter(P=>P!==v),r())}function l(v){t.includes(v)?t=t.filter(P=>P!==v):n.multiple?t=[...t,v]:t=[v],r()}function u(){t.length!==0&&(t=[],r())}function d(v){return t.includes(v)}function x(v,P){return Xs(e.meshes(),v,P,g=>!g.element.classList.contains("polycss-transform-gizmo"))}let h=v=>{let P=v.target;if(P?.closest(".polycss-transform-gizmo"))return;let g=e.findMeshByElement(P)??x(v.clientX,v.clientY);if(!g){n.onPointerMissed&&n.onPointerMissed(v),n.clearOnMiss!==!1&&u();return}n.multiple&&(v.shiftKey||v.metaKey||v.ctrlKey)?l(g):t.length===1&&t[0]===g?u():s([g])};e.host.addEventListener("click",h);function b(){e.host.removeEventListener("click",h),o.clear()}return{get selected(){return t},set:s,add:i,remove:c,toggle:l,clear:u,has:d,destroy:b}}import{arrowPolygons as jl,eulerXYZFromQuat as Wl,planePolygons as Yl,quatFromAxisAngle as Xl,quatFromEulerXYZ as Zl,quatMultiply as ql,ringQuadPolygons as Ql,rotateVec3 as ko}from"@layoutit/polycss-core";var An="#ff3653",wn="#8adb00",Mn="#2c8fff",Ft=50,Zs=60,Kl=.6,Jl=.0125,ec=.15,tc=.04,nc=1,qs=.02,Oo=1.04,oc=.1,rc=.25,ei=1e-4,sc=.6,ic=.8,ac=1,tt={0:1,1:0,2:2},Qs=[{cssAxis:0,sign:1,key:"x",color:An},{cssAxis:0,sign:-1,key:"-x",color:An},{cssAxis:1,sign:1,key:"y",color:wn},{cssAxis:1,sign:-1,key:"-y",color:wn},{cssAxis:2,sign:1,key:"z",color:Mn},{cssAxis:2,sign:-1,key:"-z",color:Mn}],Ks=[{cssAxis:0,key:"x",color:An},{cssAxis:1,key:"y",color:wn},{cssAxis:2,key:"z",color:Mn}],Js=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:Mn},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:wn},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:An}];function Do(e,n,t,o){let r=t*Math.PI/180,s=o*Math.PI/180,i=[0,0,0];i[e]=n;let c=i[0]*Math.cos(s)-i[1]*Math.sin(s),l=i[0]*Math.sin(s)+i[1]*Math.cos(s),u=i[2];return l*Math.sin(r)+u*Math.cos(r)<0}function lc(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),s=parseInt(t[3],16);return`rgba(${o}, ${r}, ${s}, ${n})`}function Ln(e,n){return!n||n<=0?e:Math.round(e/n)*n}function cc(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let l of c.vertices)l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>s&&(s=l[1]),l[2]<o&&(o=l[2]),l[2]>i&&(i=l[2]);return Number.isFinite(n)?[(n+r)/2,(t+s)/2,(o+i)/2]:[0,0,0]}function Io(e){if(e.length===0)return Zs;let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let u of l.vertices)u[0]<n&&(n=u[0]),u[0]>r&&(r=u[0]),u[1]<t&&(t=u[1]),u[1]>s&&(s=u[1]),u[2]<o&&(o=u[2]),u[2]>i&&(i=u[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*Ft*Kl:Zs}function uc(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:c,translationSnap:l,onAxisDelta:u,onMouseDown:d,onMouseUp:x,onDraggingChanged:h}=e,b=o,v=[0,0,0];v[n]=t;let P=r.ownerDocument.createElement("div");P.style.position="absolute",P.style.left="0",P.style.top="0",P.style.width="0",P.style.height="0",P.style.transform=`translate3d(${v[0]*b}px, ${v[1]*b}px, ${v[2]*b}px)`,r.appendChild(P);let g=r.getBoundingClientRect(),C=P.getBoundingClientRect();r.removeChild(P);let D=(C.left-g.left)/b,k=(C.top-g.top)/b,z=D*D+k*k;if(z<ei)return;d?.(),h?.(!0);let I=Q=>{let O=Q.clientX-i,H=Q.clientY-c,V=(O*D+H*k)/z;V=Ln(V,l),u(V,v)},Z=()=>{window.removeEventListener("pointermove",I),window.removeEventListener("pointerup",Z),window.removeEventListener("pointercancel",Z);let Q=O=>{O.stopPropagation(),O.stopImmediatePropagation()};window.addEventListener("click",Q,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",Q,!0),0),x?.(),h?.(!1)};window.addEventListener("pointermove",I),window.addEventListener("pointerup",Z),window.addEventListener("pointercancel",Z)}function dc(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:s,startClientY:i,translationSnap:c,onPlaneDelta:l,onMouseDown:u,onMouseUp:d,onDraggingChanged:x}=e,h=[0,0,0];h[n]=1;let b=[0,0,0];b[t]=1;function v(z){let I=r.ownerDocument.createElement("div");I.style.position="absolute",I.style.left="0",I.style.top="0",I.style.width="0",I.style.height="0",I.style.transform=`translate3d(${z[0]*o}px, ${z[1]*o}px, ${z[2]*o}px)`,r.appendChild(I);let Z=r.getBoundingClientRect(),Q=I.getBoundingClientRect();return r.removeChild(I),{x:(Q.left-Z.left)/o,y:(Q.top-Z.top)/o}}let P=v(h),g=v(b),C=P.x*g.y-g.x*P.y;if(Math.abs(C)<ei)return;u?.(),x?.(!0);let D=z=>{let I=z.clientX-s,Z=z.clientY-i,Q=(g.y*I-g.x*Z)/C,O=(-P.y*I+P.x*Z)/C;Q=Ln(Q,c),O=Ln(O,c),l(Q,O,h,b)},k=()=>{window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k);let z=I=>{I.stopPropagation(),I.stopImmediatePropagation()};window.addEventListener("click",z,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",z,!0),0),d?.(),x?.(!1)};window.addEventListener("pointermove",D),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)}function pc(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:c,onMouseDown:l,onMouseUp:u,onDraggingChanged:d}=e,x=t.getBoundingClientRect(),h=x.left,b=x.top,v=Math.atan2(s-b,r-h),P=0;l?.(),d?.(!0);let g=D=>{let k=Math.atan2(D.clientY-b,D.clientX-h),z=k-v;z>Math.PI?z-=2*Math.PI:z<-Math.PI&&(z+=2*Math.PI),P+=z,v=k;let I=P*180/Math.PI;I=Ln(I,i),c(I)},C=()=>{window.removeEventListener("pointermove",g),window.removeEventListener("pointerup",C),window.removeEventListener("pointercancel",C);let D=k=>{k.stopPropagation(),k.stopImmediatePropagation()};window.addEventListener("click",D,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",D,!0),0),u?.(),d?.(!1)};window.addEventListener("pointermove",g),window.addEventListener("pointerup",C),window.addEventListener("pointercancel",C)}function Ho(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,c=null,l=null,u=[0,0,0];function d(){if(!t)return[0,0,0];let y=t.transform.position??[0,0,0],m=t.transform.rotation??[0,0,0],p=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,T=ko(u,m[0],m[1],m[2]);return[y[0]+p*T[0],y[1]+p*T[1],y[2]+p*T[2]]}function x(y){return l===y?ac:c===y?ic:sc}function h(){for(let[y,m]of i){let p=b(m.spec,x(y));m.handle.setPolygons(p,{recomputeAutoCenter:!1})}}function b(y,m){let T=Io(t?.polygons??[])*r,M=T/Ft,R=lc(y.color,m);if(y.kind==="arrow"){let _=e.camera.state,j=Do(y.cssAxis,y.sign,_.rotX??65,_.rotY??45);return jl({axis:tt[y.cssAxis],sign:y.sign,shaftLength:M,shaftHalfThickness:M*Jl,headLength:M*ec,headHalfThickness:M*tc,color:R,shaft:!j})}if(y.kind==="plane"){let _=e.camera.state,j=_.rotX??65,q=_.rotY??45,re=tt[y.perpAxis],fe=(re+1)%3,de=(re+2)%3,pe=tt[fe],Ce=tt[de],be=Do(pe,1,j,q)?-1:1,Ae=Do(Ce,1,j,q)?-1:1,$e=M*rc;return Yl({axis:re,size:M*oc,offset:[be*$e,Ae*$e],color:R})}let te=T*nc/Ft*Oo;return Ql({axis:tt[y.cssAxis],outerRadius:te,color:R})}function v(y){return y.kind==="arrow"?"polycss-transform-arrow":y.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function P(){if(o==="translate"){let y=Qs.map(p=>({kind:"arrow",key:p.key,cssAxis:p.cssAxis,sign:p.sign,color:p.color})),m=Js.map(p=>({kind:"plane",key:p.key,perpAxis:p.perpAxis,axisA:p.axisA,axisB:p.axisB,color:p.color}));return[...y,...m]}return o==="rotate"?Ks.map(y=>({kind:"ring",key:y.key,cssAxis:y.cssAxis,color:y.color})):[]}function g(){if(C(),!t)return;let y={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};function m(T){if(T.kind==="arrow"){let L=T.key.replace("-","")[0];return y[L]}if(T.kind==="ring")return y[T.key];let M=["x","y","z"][T.axisA],R=["x","y","z"][T.axisB];return y[M]&&y[R]}let p=d();for(let T of P()){if(!m(T))continue;let M=b(T,x(T.key)),R=e.add({polygons:M,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${T.key}`,position:p}),L=v(T);if(R.element.classList.add("polycss-transform-gizmo",L,`${L}--${T.key}`),T.kind==="ring"){let te=(1-qs)/Oo,_=(1+qs)/Oo;R.element.style.setProperty("--ring-inner-ratio",`${te}`),R.element.style.setProperty("--ring-outer-ratio",`${_}`)}i.set(T.key,{handle:R,spec:T})}}function C(){for(let{handle:y}of i.values())y.remove();i.clear(),c=null,l=null}function D(){if(!t)return;let y=d();for(let{handle:m}of i.values())m.setTransform({position:y})}function k(){t&&(i.size===0?g():D())}function z(y){if(t=y,!y){u=[0,0,0],C();return}u=cc(y.polygons),C(),g()}function I(){z(null)}function Z(y){y!==o&&(o=y,t&&(C(),g()))}function Q(y,m,p){if(!t||!O)return;let T=p[y.cssAxis],M=tt[y.cssAxis],R=m*T/Ft,L=O.slice();L[M]=O[M]+R,t.setTransform({position:L}),D(),s.onObjectChange?.({object:t,position:L}),s.onChange?.()}let O=null,H=null,V=y=>{if(!t||s.enabled===!1)return;let m={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate"){for(let p of Js){let T=["x","y","z"][p.axisA],M=["x","y","z"][p.axisB];if(!m[T]||!m[M])continue;let R=i.get(p.key);if(R&&Ht(R.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),O=(t.transform.position??[0,0,0]).slice(),dc({axisA:p.axisA,axisB:p.axisB,probeDistanceCss:Io(t.polygons)*r,wrapper:R.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,translationSnap:s.translationSnap??null,onPlaneDelta:(L,te,_,j)=>{if(!t||!O)return;let q=_[p.axisA],re=j[p.axisB],fe=tt[p.axisA],de=tt[p.axisB],pe=O.slice();pe[fe]+=L*q/Ft,pe[de]+=te*re/Ft,t.setTransform({position:pe}),D(),s.onObjectChange?.({object:t,position:pe}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:L=>{L||(l=null,O=null,h()),s.onDraggingChanged?.(L)}});return}}for(let p of Qs){let T=p.key.replace("-","")[0];if(!m[T])continue;let M=i.get(p.key);if(M&&Ht(M.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),O=(t.transform.position??[0,0,0]).slice(),uc({cssAxis:p.cssAxis,sign:p.sign,shaftLengthCss:Io(t.polygons)*r,wrapper:M.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(R,L)=>Q(p,R,L),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:R=>{R||(l=null,O=null,h()),s.onDraggingChanged?.(R)}});return}}}else if(o==="rotate")for(let p of Ks){if(!m[p.key])continue;let T=i.get(p.key);if(T&&Ht(T.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),H=(t.transform.rotation??[0,0,0]).slice(),O=(t.transform.position??[0,0,0]).slice(),pc({cssAxis:p.cssAxis,wrapper:T.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:M=>{if(!t||!H||!O)return;let R=tt[p.cssAxis],L=[0,0,0];L[R]=1;let te=-M*Math.PI/180,_=Zl(H),j=Xl(L,te),q=Wl(ql(j,_)),re=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,fe=ko(u,H[0],H[1],H[2]),de=ko(u,q[0],q[1],q[2]),pe=[O[0]+re*(fe[0]-de[0]),O[1]+re*(fe[1]-de[1]),O[2]+re*(fe[2]-de[2])];t.setTransform({rotation:q,position:pe}),D(),s.onObjectChange?.({object:t,rotation:q,position:pe}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:M=>{M||(l=null,H=null,O=null,h(),t?.rebakeAtlas()),s.onDraggingChanged?.(M)}});return}}};e.host.addEventListener("pointerdown",V,{capture:!0});let $=y=>{if(!t||l||s.enabled===!1)return;let m=null;for(let[p,T]of i)if(Ht(T.handle.element,y.clientX,y.clientY)){m=p;break}m!==c&&(c=m,h())};e.host.addEventListener("pointermove",$);function A(){e.host.removeEventListener("pointerdown",V,{capture:!0}),e.host.removeEventListener("pointermove",$),C()}return{attach:z,detach:I,setMode:Z,update:k,destroy:A}}var mc=typeof HTMLElement<"u"?HTMLElement:class{},fc=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function Ne(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function hc(e){return e==="false"?!1:Ne(e)}function Fo(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 gc(e){if(e==="baked"||e==="dynamic")return e}function yc(e){return e==="auto"?"auto":Ne(e)}function bc(e){return typeof e.getCamera=="function"}var Re=class extends mc{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...fc]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(bc(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=hc(this.getAttribute("perspective")),o=Ne(this.getAttribute("rot-x")),r=Ne(this.getAttribute("rot-y")),s=Ne(this.getAttribute("zoom")),i=Ne(this.getAttribute("distance")),c=Fo(this.getAttribute("target")),l={...o!==void 0?{rotX:o}:{},...r!==void 0?{rotY:r}:{},...s!==void 0?{zoom:s}:{},...i!==void 0?{distance:i}:{},...c!==void 0?{target:c}:{}};return t===!1?ht(l):t!==void 0?en({...l,perspective:t}):ht(l)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={};r.textureLighting=gc(this.getAttribute("texture-lighting"))??"baked";let s=yc(this.getAttribute("texture-quality"));return s!==void 0&&(r.textureQuality=s),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=Fo(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=Ne(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let s={direction:t??[.4,-.7,.59]};return o&&(s.color=o),r!==void 0&&(s.intensity=r),s}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=Ne(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){if(this._scene)return;let t=this._findAncestorCamera(),o;t?(o=t,this._implicitCamera=null):(this._implicitCamera=this._buildImplicitCamera(),o=this._implicitCamera),this._scene=Ao(this,{camera:o,...this._readNonCameraOptions()}),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1}))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null),this._implicitCamera=null}attributeChangedCallback(t,o,r){if(o!==r&&this._scene){if(this._implicitCamera&&["rot-x","rot-y","zoom","distance","target"].includes(t)){let i=Ne(this.getAttribute("rot-x")),c=Ne(this.getAttribute("rot-y")),l=Ne(this.getAttribute("zoom")),u=Ne(this.getAttribute("distance")),d=Fo(this.getAttribute("target"));i!==void 0&&this._implicitCamera.update({rotX:i}),c!==void 0&&this._implicitCamera.update({rotY:c}),l!==void 0&&this._implicitCamera.update({zoom:l}),u!==void 0&&this._implicitCamera.update({distance:u}),d!==void 0&&this._implicitCamera.update({target:d}),this._scene.applyCamera();return}this._scene.setOptions(this._readNonCameraOptions())}}};import{computeSceneBbox as vc,loadMesh as xc}from"@layoutit/polycss-core";var Pc=typeof HTMLElement<"u"?HTMLElement:class{},Sc=["src","mtl","mesh-resolution","position","scale","rotation","auto-center","cast-shadow","receive-shadow","target-size","default-color","palette","include-objects","exclude-objects"];function nn(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 ti(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return nn(e)}}function Vo(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 Cc(e){let n=e.getAttribute("target-size"),t=e.getAttribute("default-color"),o=Vo(e.getAttribute("palette")),r=Vo(e.getAttribute("include-objects")),s=Vo(e.getAttribute("exclude-objects")),i=n!==null?parseFloat(n):NaN,c={};return Number.isFinite(i)&&(c.targetSize=i),t&&(c.defaultColor=t),o&&(c.palette=o),r&&(c.includeObjects=r),s&&(c.excludeObjects=s),Object.keys(c).length>0?c:void 0}function Ec(e){return e.closest("poly-scene")??null}function Tc(e){if(e.length===0)return e;let n=vc(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s),...i.textureTriangles?.length?{textureTriangles:i.textureTriangles.map(c=>({...c,vertices:c.vertices.map(s)}))}:null}))}var on=class extends Pc{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Sc]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"||t==="mesh-resolution"||t==="target-size"||t==="default-color"||t==="palette"||t==="include-objects"||t==="exclude-objects"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:nn(this.getAttribute("position")),scale:ti(this.getAttribute("scale")),rotation:nn(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=Ec(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,l=Cc(this),u;try{let h=s||c!==void 0||l?{...s?{mtlUrl:s}:{},...c!==void 0?{meshResolution:c}:{},...l?{objOptions:l}:{}}:void 0;u=await xc(t,h)}catch(h){this.dispatchEvent(new CustomEvent("polycss:error",{detail:h,bubbles:!0}));return}if(r!==this._loadToken){try{u.dispose()}catch{}return}let d=o.getScene();if(!d){try{u.dispose()}catch{}return}this.hasAttribute("auto-center")&&(u={...u,polygons:Tc(u.polygons)}),this._parseResult=u,this._handle=d.add(u,{position:nn(this.getAttribute("position")),scale:ti(this.getAttribute("scale")),rotation:nn(this.getAttribute("rotation")),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};import{BASE_TILE as rn}from"@layoutit/polycss-core";var Ac=typeof HTMLElement<"u"?HTMLElement:class{},wc=["src","width","height","position","rotation","scale","allow","loading","referrerpolicy","sandbox","title"];function Bo(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 Mc(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Bo(e)}}function ni(e,n){if(e===null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}function Lc(e){let n=e.closest("poly-scene");return n?n.querySelector(".polycss-scene"):null}function _c(e,n,t,o,r){let s=typeof t=="number"?t:t?.[0]??1,i=typeof t=="number"?t:t?.[1]??1,c=typeof t=="number"?t:t?.[2]??1,l=s!==1||i!==1||c!==1,u=!!n&&(!!n[0]||!!n[1]||!!n[2]),d=(e?.[1]??0)*rn,x=(e?.[0]??0)*rn,h=(e?.[2]??0)*rn,b=[];return b.push(`translate3d(${d}px, ${x}px, ${h}px)`),u&&(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(${s}, ${i}, ${c})`),b.push(`translate(${-o/2}px, ${-r/2}px)`),b.join(" ")}var zo=class extends Ac{constructor(){super(...arguments);this._wrapper=null;this._iframe=null}static get observedAttributes(){return[...wc]}getIframeElement(){return this._iframe}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o!==r&&!(!this._wrapper||!this._iframe)){if(t==="src"){this._iframe.src=this.getAttribute("src")??"";return}if(t==="allow"||t==="loading"||t==="referrerpolicy"||t==="sandbox"||t==="title"){let s=this.getAttribute(t);s===null?this._iframe.removeAttribute(t):this._iframe.setAttribute(t,s);return}this._applyGeometry()}}_mount(){let t=Lc(this);if(!t)return;let o=this.ownerDocument;if(!o)return;let r=o.createElement("div");r.className="polycss-iframe",r.style.position="absolute",r.style.left="0",r.style.top="0",r.style.transformOrigin="0 0",r.style.transformStyle="preserve-3d";let s=o.createElement("iframe");s.style.display="block",s.style.border="0",s.style.background="#000";let i=this.getAttribute("src");i&&(s.src=i);let c=this.getAttribute("allow");c&&s.setAttribute("allow",c);for(let l of["loading","referrerpolicy","sandbox","title"]){let u=this.getAttribute(l);u!==null&&s.setAttribute(l,u)}r.appendChild(s),t.appendChild(r),this._wrapper=r,this._iframe=s,this._applyGeometry()}_applyGeometry(){if(!this._wrapper||!this._iframe)return;let t=ni(this.getAttribute("width"),16),o=ni(this.getAttribute("height"),9),r=t*rn,s=o*rn;this._iframe.style.width=`${r}px`,this._iframe.style.height=`${s}px`;let i=Bo(this.getAttribute("position")),c=Bo(this.getAttribute("rotation")),l=Mc(this.getAttribute("scale"));this._wrapper.style.transform=_c(i,c,l,r,s)}_teardown(){this._wrapper?.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null,this._iframe=null}};var Rc=typeof HTMLElement<"u"?HTMLElement:class{},kc=["vertices","color","texture","uvs","position","scale","rotation"];function oi(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function No(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Oc(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return No(e)}}function Dc(e){return e.closest("poly-scene")??null}var $o=class extends Rc{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...kc]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=Dc(this);if(!t)return;let o=t.getScene();if(!o)return;let r=oi(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let s=this.getAttribute("color")||void 0,i=this.getAttribute("texture")||void 0,c=oi(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 d={polygons:[{vertices:r,...s!==void 0?{color:s}:{},...i!==void 0?{texture:i}:{},...c!==void 0?{uvs:c}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(d,{position:No(this.getAttribute("position")),scale:Oc(this.getAttribute("scale")),rotation:No(this.getAttribute("rotation"))})}};function ee(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function _n(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Te(e){if(e!==null)return!(e==="false"||e==="0")}function Rn(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 kn(e){if(e==="x"||e==="y")return e}var Ic=typeof HTMLElement<"u"?HTMLElement:class{},Hc=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Uo=class extends Ic{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Hc]}getControls(){return this._controls}_readAnimate(){let t=ee(this.getAttribute("animate-speed")),o=kn(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:Te(r)}:{}}}_readOptions(){let t={},o=Te(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Te(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ee(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ee(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=Rn(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=ee(this.getAttribute("zoom-min")),u=ee(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Re)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=wo(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Fc=typeof HTMLElement<"u"?HTMLElement:class{},Vc=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Go=class extends Fc{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Vc]}_readAnimate(){let t=ee(this.getAttribute("animate-speed")),o=kn(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:Te(r)}:{}}}_readOptions(){let t={},o=Te(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Te(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=ee(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=ee(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=Rn(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=ee(this.getAttribute("zoom-min")),u=ee(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),u!==void 0&&(t.maxZoom=u),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Re)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=Mo(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Bc=typeof HTMLElement<"u"?HTMLElement:class{},zc=["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"],jo=class extends Bc{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...zc]}_readOptions(){let t={},o=Te(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let r=Te(this.getAttribute("look-enabled"));r!==void 0&&(t.lookEnabled=r);let s=Te(this.getAttribute("move-enabled"));s!==void 0&&(t.moveEnabled=s);let i=Te(this.getAttribute("jump-enabled"));i!==void 0&&(t.jumpEnabled=i);let c=Te(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let l=ee(this.getAttribute("look-sensitivity"));if(l!==void 0&&(t.lookSensitivity=l),this.hasAttribute("invert-y")){let C=Te(this.getAttribute("invert-y"));C!==void 0&&(t.invertY=C)}let u=ee(this.getAttribute("move-speed"));u!==void 0&&(t.moveSpeed=u);let d=ee(this.getAttribute("jump-velocity"));d!==void 0&&(t.jumpVelocity=d);let x=ee(this.getAttribute("gravity"));x!==void 0&&(t.gravity=x);let h=ee(this.getAttribute("eye-height"));h!==void 0&&(t.eyeHeight=h);let b=ee(this.getAttribute("crouch-height"));b!==void 0&&(t.crouchHeight=b);let v=ee(this.getAttribute("ground-z"));v!==void 0&&(t.groundZ=v);let P=ee(this.getAttribute("min-pitch"));P!==void 0&&(t.minPitch=P);let g=ee(this.getAttribute("max-pitch"));return g!==void 0&&(t.maxPitch=g),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Re)return t;t=t.parentNode}return null}_attach(){if(this._controls)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._controls=_o(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._controls&&(this._controls.destroy(),this._controls=null)}attributeChangedCallback(t,o,r){o!==r&&this._controls&&this._controls.update(this._readOptions())}};var Nc=typeof HTMLElement<"u"?HTMLElement:class{},$c=["perspective","zoom","rot-x","rot-y","target","distance"],Wo=class extends Nc{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...$c]}getCamera(){return this._camera}_readOptions(){return{perspective:ee(this.getAttribute("perspective")),zoom:ee(this.getAttribute("zoom")),rotX:ee(this.getAttribute("rot-x")),rotY:ee(this.getAttribute("rot-y")),target:_n(this.getAttribute("target")),distance:ee(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=en(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let s=this._readOptions();if(t==="perspective"){let l=s.perspective!==void 0?`${s.perspective}px`:"32000px";this._wrapper.style.perspective=l;return}this._camera.update({rotX:s.rotX,rotY:s.rotY,zoom:s.zoom,target:s.target,distance:s.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var Uc=typeof HTMLElement<"u"?HTMLElement:class{},Gc=["zoom","rot-x","rot-y","target","distance"],sn=class extends Uc{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Gc]}getCamera(){return this._camera}_readOptions(){return{zoom:ee(this.getAttribute("zoom")),rotX:ee(this.getAttribute("rot-x")),rotY:ee(this.getAttribute("rot-y")),target:_n(this.getAttribute("target")),distance:ee(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=ht(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let s=this._readOptions();s.zoom!==void 0&&this._camera.update({zoom:s.zoom}),s.rotX!==void 0&&this._camera.update({rotX:s.rotX}),s.rotY!==void 0&&this._camera.update({rotY:s.rotY}),s.target!==void 0&&this._camera.update({target:s.target}),s.distance!==void 0&&this._camera.update({distance:s.distance}),this.querySelector("poly-scene")?.getScene?.()?.applyCamera()}};var Yo=class extends sn{};var jc=typeof HTMLElement<"u"?HTMLElement:class{},Wc=["mode","target","size","enabled"];function ri(e){if(e==="translate"||e==="rotate")return e}var Xo=class extends jc{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Wc]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Re)return t;t=t.parentNode}return null}_findTargetMesh(){let t=this.getAttribute("target");if(!t)return null;let o=this._findScene();if(!o)return null;let r=null;try{r=o.querySelector(`#${t}`)??o.querySelector(t)}catch{r=o.querySelector(`[id="${t}"]`)}return r instanceof on?r:null}_readOptions(){let t={},o=ri(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=ee(this.getAttribute("size"));r!==void 0&&(t.size=r);let s=this.getAttribute("enabled");return s!==null&&(t.enabled=s!=="false"&&s!=="0"),t.onObjectChange=i=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:i.position,rotation:i.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let s=()=>{t.removeEventListener("polycss:scene-ready",s),this._attach()};t.addEventListener("polycss:scene-ready",s)}return}this._tc=Ho(o,this._readOptions());let r=this._findTargetMesh();if(r){let s=r.getMeshHandle();s&&this._tc.attach(s)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,r){if(o!==r&&this._tc){if(t==="mode"){let s=ri(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};var Yc=typeof HTMLElement<"u"?HTMLElement:class{},Xc=["multiple","clear-on-miss"],Zo=class extends Yc{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Xc]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Re)return t;t=t.parentNode}return null}_readOptions(){return{multiple:this.hasAttribute("multiple"),clearOnMiss:!this.hasAttribute("clear-on-miss")||this.getAttribute("clear-on-miss")!=="false",onChange:t=>{this.dispatchEvent(new CustomEvent("polycss:select",{bubbles:!0,detail:{selected:t}}))}}}_attach(){if(this._selection)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let r=()=>{t.removeEventListener("polycss:scene-ready",r),this._attach()};t.addEventListener("polycss:scene-ready",r)}return}this._selection=Ro(o,this._readOptions())}connectedCallback(){this._attach()}disconnectedCallback(){this._selection&&(this._selection.destroy(),this._selection=null)}attributeChangedCallback(t,o,r){o!==r&&(this._selection&&(this._selection.destroy(),this._selection=null),this._attach())}};var qo={quad:0,clippedSolid:0,atlas:0,stableTriangle:0},Zc={polygonCount:0,mountedPolygonLeafCount:0,shadowLeafCount:0,surfaceLeafCounts:qo,bucketCount:0};function qc(e){return typeof e=="number"?{polygonCount:e}:e??{}}function Vt(e,n){return e.querySelectorAll(n).length}function Qc(e,n){let t=e;return typeof t.matches=="function"&&t.matches(n)}function Kc(e,n){if(!n)return[e];let t=[];return Qc(e,n)&&t.push(e),t.push(...Array.from(e.querySelectorAll(n))),t}function Jc(e,n){let t=qc(n);if(!e)return{...Zc,surfaceLeafCounts:{...qo},polygonCount:t.polygonCount??0};let o=Kc(e,t.scopeSelector),r={...qo},s=0,i=0;for(let l of o)r.quad+=Vt(l,"b"),r.clippedSolid+=Vt(l,"i"),r.atlas+=Vt(l,"s"),r.stableTriangle+=Vt(l,"u"),s+=Vt(l,"q, .polycss-shadow-svg"),i+=Vt(l,".polycss-bucket");let c=r.quad+r.clippedSolid+r.atlas+r.stableTriangle;return{polygonCount:t.polygonCount??c,mountedPolygonLeafCount:c,shadowLeafCount:s,surfaceLeafCounts:r,bucketCount:i}}var gt=class extends Error{constructor(n,t,o){super(t),this.name="PolySceneSnapshotError",this.code=n,this.url=o,Object.setPrototypeOf(this,new.target.prototype)}},eu=`
520
520
  html,
521
521
  body {
522
522
  width: 100%;
@@ -796,4 +796,4 @@ ${an(t,".polycss-mesh.polycss-transform-ring ")} {
796
796
 
797
797
  `)}function Au(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function wu(e){return e.replace(/<\/style/gi,"<\\/style")}function Mu(e){return e.baseURI||e.URL||e.defaultView?.location.href||"http://localhost/"}async function Lu(e){if(!su(e))throw new gt("INVALID_TARGET","exportPolySceneSnapshot: target must be an Element.");let n=iu(e);if(!n)throw new gt("SCENE_NOT_FOUND","exportPolySceneSnapshot: target is not inside and does not contain a rendered PolyCSS scene.");let t=e.ownerDocument,o={baseUrl:Mu(t),cache:new Map},r=n.cloneNode(!0),s=au(r);mu(n,r,s),fu(r);let i=await Tu(r,o);await Su(r,o);let c=await Ko([du(s),i].filter(Boolean).join(`
798
798
 
799
- `),o);return["<!doctype html>","<html>","<head>",'<meta charset="utf-8">',t.title?`<title>${Au(t.title)}</title>`:"",`<style>${wu(c)}</style>`,"</head>","<body>",r.outerHTML,"</body>","</html>"].filter(Boolean).join("")}import{boxPolygons as _u,planePolygons as Ru,ringPolygons as ku,octahedronPolygons as Ou,spherePolygons as Du,tetrahedronPolygons as Iu,icosahedronPolygons as Hu,dodecahedronPolygons as Fu,cylinderPolygons as Vu,conePolygons as Bu,torusPolygons as zu}from"@layoutit/polycss-core";function Ze(e){return{polygons:e,objectUrls:[],warnings:[],dispose:()=>{}}}function Nu(e={}){return Ze(_u(e))}function $u(e){return Ze(Ru(e))}function Uu(e){return Ze(ku(e))}function Gu(e){return Ze(Ou(e))}function ju(e={}){return Ze(Du(e))}function Wu(e={}){return Ze(Iu(e))}function Yu(e={}){return Ze(Hu(e))}function Xu(e={}){return Ze(Fu(e))}function Zu(e={}){return Ze(Vu(e))}function qu(e={}){return Ze(Bu(e))}function Qu(e={}){return Ze(zu(e))}import{boxPolygons as Ku,planePolygons as Ju,ringPolygons as ed,octahedronPolygons as td,spherePolygons as nd,tetrahedronPolygons as od,icosahedronPolygons as rd,dodecahedronPolygons as sd,cylinderPolygons as id,conePolygons as ad,torusPolygons as ld,computeSceneBbox as cd}from"@layoutit/polycss-core";var ud=typeof HTMLElement<"u"?HTMLElement:class{};function dd(e){return e.closest("poly-scene")??null}function he(e,n,t){let o=e.getAttribute(n);if(!o)return t;let r=parseFloat(o);return Number.isFinite(r)?r:t}function qe(e,n,t){return e.getAttribute(n)??t}function yt(e,n){let t=e.getAttribute(n);if(!t)return;let o=t.split(",").map(r=>parseFloat(r.trim()));if(!(o.length!==3||o.some(r=>!Number.isFinite(r))))return[o[0],o[1],o[2]]}function pd(e){if(e.length===0)return e;let n=cd(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s)}))}var ke=class extends ud{constructor(){super(...arguments);this._handle=null}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="position"||t==="scale"||t==="rotation"||t==="cast-shadow"||t==="receive-shadow"){this._handle.setTransform({position:yt(this,"position"),scale:(()=>{let s=this.getAttribute("scale");if(!s)return;if(s.includes(","))return yt(this,"scale");let i=parseFloat(s);return Number.isFinite(i)?i:void 0})(),rotation:yt(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=dd(this);if(!t)return;let o=t.getScene?.();if(!o)return;let r=this.buildPolygons();this.hasAttribute("auto-center")&&(r=pd(r));let s={polygons:r,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(s,{position:yt(this,"position"),scale:(()=>{let i=this.getAttribute("scale");if(!i)return;if(i.includes(","))return yt(this,"scale");let c=parseFloat(i);return Number.isFinite(c)?c:void 0})(),rotation:yt(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow"),excludeFromAutoCenter:this.hasAttribute("exclude-from-auto-center"),merge:!1})}},er=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("size"),t=n?parseFloat(n):void 0;return Ku({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:qe(this,"color")})}},tr=class extends ke{static get observedAttributes(){return["axis","size","offset","color","auto-center","position","scale","rotation","cast-shadow","receive-shadow"]}buildPolygons(){let n=he(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("offset"),r=o===null?0:parseFloat(o);return Ju({axis:t,size:he(this,"size",.4),offset:Number.isFinite(r)?r:0,color:qe(this,"color")})}},nr=class extends ke{static get observedAttributes(){return["axis","radius","segments","half-thickness","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=he(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("half-thickness");return ed({axis:t,radius:he(this,"radius",50),segments:he(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:qe(this,"color")})}},or=class extends ke{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return td({center:yt(this,"center")??[0,0,0],size:he(this,"size",50),color:qe(this,"color")})}},rr=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return od({size:he(this,"size",100),color:qe(this,"color")})}},sr=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return rd({size:he(this,"size",100),color:qe(this,"color")})}},ir=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return sd({size:he(this,"size",100),color:qe(this,"color")})}},ar=class extends ke{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return nd({radius:he(this,"radius",50),subdivisions:he(this,"subdivisions",1),color:qe(this,"color")})}},lr=class extends ke{static get observedAttributes(){return["radius","radius-top","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("radius-top");return id({radius:he(this,"radius",50),radiusTop:n?parseFloat(n):void 0,height:he(this,"height",100),radialSegments:he(this,"radial-segments",12),color:qe(this,"color")})}},cr=class extends ke{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return ad({radius:he(this,"radius",50),height:he(this,"height",100),radialSegments:he(this,"radial-segments",12),color:qe(this,"color")})}},ur=class extends ke{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return ld({radius:he(this,"radius",50),tube:he(this,"tube",15),radialSegments:he(this,"radial-segments",12),tubularSegments:he(this,"tubular-segments",16),color:qe(this,"color")})}};export*from"@layoutit/polycss-core";export{er as PolyBoxElement,Yo as PolyCameraElement,cr as PolyConeElement,lr as PolyCylinderElement,ir as PolyDodecahedronElement,jo as PolyFirstPersonControlsElement,sr as PolyIcosahedronElement,zo as PolyIframeElement,Go as PolyMapControlsElement,on as PolyMeshElement,or as PolyOctahedronElement,Uo as PolyOrbitControlsElement,sn as PolyOrthographicCameraElement,Wo as PolyPerspectiveCameraElement,tr as PolyPlaneElement,$o as PolyPolygonElement,nr as PolyRingElement,Re as PolySceneElement,gt as PolySceneSnapshotError,Zo as PolySelectElement,ar as PolySphereElement,rr as PolyTetrahedronElement,ur as PolyTorusElement,Xo as PolyTransformControlsElement,Ct as buildAtlasPages,Ur as buildTextureEdgeRepairSets,Jc as collectPolyRenderStats,Gr as computeTextureAtlasPlanPublic,Nu as createPolyBox,zl as createPolyCamera,qu as createPolyCone,Zu as createPolyCylinder,Xu as createPolyDodecahedron,_o as createPolyFirstPersonControls,Yu as createPolyIcosahedron,Mo as createPolyMapControls,Gu as createPolyOctahedron,wo as createPolyOrbitControls,ht as createPolyOrthographicCamera,Ot as createPolyPerspectiveCamera,$u as createPolyPlane,Uu as createPolyRing,Ao as createPolyScene,ju as createPolySphere,Wu as createPolyTetrahedron,Qu as createPolyTorus,Ro as createSelect,Ho as createTransformControls,Zr as cssBorderShapeForPlan,Lu as exportPolySceneSnapshot,Wn as filterAtlasPlans,Xr as formatBorderShapeEntryMatrix,Wr as formatCssLengthPx,jr as formatMatrix3d,Yr as formatSolidQuadEntryMatrix,dt as getSolidPaintDefaults,jn as getSolidPaintDefaultsFromPlans,bo as injectPolyBaseStyles,mn as isBorderShapeSupported,Ve as isFullRectSolid,Be as isProjectiveQuadPlan,Je as isSolidTrianglePlan,fn as isSolidTriangleSupported,xt as packTextureAtlasPlansWithScale,_t as renderPolygonsWithStableTriangles,pt as renderPolygonsWithTextureAtlas,Kt as renderPolygonsWithTextureAtlasAsync,en as updatePolygonsWithStableTopology,uo as updatePolygonsWithStableTriangles,Jt as updateStableTriangleFrame};
799
+ `),o);return["<!doctype html>","<html>","<head>",'<meta charset="utf-8">',t.title?`<title>${Au(t.title)}</title>`:"",`<style>${wu(c)}</style>`,"</head>","<body>",r.outerHTML,"</body>","</html>"].filter(Boolean).join("")}import{boxPolygons as _u,planePolygons as Ru,ringPolygons as ku,octahedronPolygons as Ou,spherePolygons as Du,tetrahedronPolygons as Iu,icosahedronPolygons as Hu,dodecahedronPolygons as Fu,cylinderPolygons as Vu,conePolygons as Bu,torusPolygons as zu}from"@layoutit/polycss-core";function Xe(e){return{polygons:e,objectUrls:[],warnings:[],dispose:()=>{}}}function Nu(e={}){return Xe(_u(e))}function $u(e){return Xe(Ru(e))}function Uu(e){return Xe(ku(e))}function Gu(e){return Xe(Ou(e))}function ju(e={}){return Xe(Du(e))}function Wu(e={}){return Xe(Iu(e))}function Yu(e={}){return Xe(Hu(e))}function Xu(e={}){return Xe(Fu(e))}function Zu(e={}){return Xe(Vu(e))}function qu(e={}){return Xe(Bu(e))}function Qu(e={}){return Xe(zu(e))}import{boxPolygons as Ku,planePolygons as Ju,ringPolygons as ed,octahedronPolygons as td,spherePolygons as nd,tetrahedronPolygons as od,icosahedronPolygons as rd,dodecahedronPolygons as sd,cylinderPolygons as id,conePolygons as ad,torusPolygons as ld,computeSceneBbox as cd}from"@layoutit/polycss-core";var ud=typeof HTMLElement<"u"?HTMLElement:class{};function dd(e){return e.closest("poly-scene")??null}function he(e,n,t){let o=e.getAttribute(n);if(!o)return t;let r=parseFloat(o);return Number.isFinite(r)?r:t}function Ze(e,n,t){return e.getAttribute(n)??t}function yt(e,n){let t=e.getAttribute(n);if(!t)return;let o=t.split(",").map(r=>parseFloat(r.trim()));if(!(o.length!==3||o.some(r=>!Number.isFinite(r))))return[o[0],o[1],o[2]]}function pd(e){if(e.length===0)return e;let n=cd(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s)}))}var ke=class extends ud{constructor(){super(...arguments);this._handle=null}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r&&this._handle){if(t==="position"||t==="scale"||t==="rotation"||t==="cast-shadow"||t==="receive-shadow"){this._handle.setTransform({position:yt(this,"position"),scale:(()=>{let s=this.getAttribute("scale");if(!s)return;if(s.includes(","))return yt(this,"scale");let i=parseFloat(s);return Number.isFinite(i)?i:void 0})(),rotation:yt(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=dd(this);if(!t)return;let o=t.getScene?.();if(!o)return;let r=this.buildPolygons();this.hasAttribute("auto-center")&&(r=pd(r));let s={polygons:r,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(s,{position:yt(this,"position"),scale:(()=>{let i=this.getAttribute("scale");if(!i)return;if(i.includes(","))return yt(this,"scale");let c=parseFloat(i);return Number.isFinite(c)?c:void 0})(),rotation:yt(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow"),excludeFromAutoCenter:this.hasAttribute("exclude-from-auto-center"),merge:!1})}},er=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("size"),t=n?parseFloat(n):void 0;return Ku({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:Ze(this,"color")})}},tr=class extends ke{static get observedAttributes(){return["axis","size","offset","color","auto-center","position","scale","rotation","cast-shadow","receive-shadow"]}buildPolygons(){let n=he(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("offset"),r=o===null?0:parseFloat(o);return Ju({axis:t,size:he(this,"size",.4),offset:Number.isFinite(r)?r:0,color:Ze(this,"color")})}},nr=class extends ke{static get observedAttributes(){return["axis","radius","segments","half-thickness","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=he(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("half-thickness");return ed({axis:t,radius:he(this,"radius",50),segments:he(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:Ze(this,"color")})}},or=class extends ke{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return td({center:yt(this,"center")??[0,0,0],size:he(this,"size",50),color:Ze(this,"color")})}},rr=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return od({size:he(this,"size",100),color:Ze(this,"color")})}},sr=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return rd({size:he(this,"size",100),color:Ze(this,"color")})}},ir=class extends ke{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return sd({size:he(this,"size",100),color:Ze(this,"color")})}},ar=class extends ke{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return nd({radius:he(this,"radius",50),subdivisions:he(this,"subdivisions",1),color:Ze(this,"color")})}},lr=class extends ke{static get observedAttributes(){return["radius","radius-top","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("radius-top");return id({radius:he(this,"radius",50),radiusTop:n?parseFloat(n):void 0,height:he(this,"height",100),radialSegments:he(this,"radial-segments",12),color:Ze(this,"color")})}},cr=class extends ke{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return ad({radius:he(this,"radius",50),height:he(this,"height",100),radialSegments:he(this,"radial-segments",12),color:Ze(this,"color")})}},ur=class extends ke{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return ld({radius:he(this,"radius",50),tube:he(this,"tube",15),radialSegments:he(this,"radial-segments",12),tubularSegments:he(this,"tubular-segments",16),color:Ze(this,"color")})}};export*from"@layoutit/polycss-core";export{er as PolyBoxElement,Yo as PolyCameraElement,cr as PolyConeElement,lr as PolyCylinderElement,ir as PolyDodecahedronElement,jo as PolyFirstPersonControlsElement,sr as PolyIcosahedronElement,zo as PolyIframeElement,Go as PolyMapControlsElement,on as PolyMeshElement,or as PolyOctahedronElement,Uo as PolyOrbitControlsElement,sn as PolyOrthographicCameraElement,Wo as PolyPerspectiveCameraElement,tr as PolyPlaneElement,$o as PolyPolygonElement,nr as PolyRingElement,Re as PolySceneElement,gt as PolySceneSnapshotError,Zo as PolySelectElement,ar as PolySphereElement,rr as PolyTetrahedronElement,ur as PolyTorusElement,Xo as PolyTransformControlsElement,Ct as buildAtlasPages,Ff as buildPolyMeshTransform,Ur as buildTextureEdgeRepairSets,Jc as collectPolyRenderStats,Gr as computeTextureAtlasPlanPublic,Nu as createPolyBox,zl as createPolyCamera,qu as createPolyCone,Zu as createPolyCylinder,Xu as createPolyDodecahedron,_o as createPolyFirstPersonControls,Yu as createPolyIcosahedron,Mo as createPolyMapControls,Gu as createPolyOctahedron,wo as createPolyOrbitControls,ht as createPolyOrthographicCamera,en as createPolyPerspectiveCamera,$u as createPolyPlane,Uu as createPolyRing,Ao as createPolyScene,ju as createPolySphere,Wu as createPolyTetrahedron,Qu as createPolyTorus,Ro as createSelect,Ho as createTransformControls,Zr as cssBorderShapeForPlan,Lu as exportPolySceneSnapshot,Wn as filterAtlasPlans,Xr as formatBorderShapeEntryMatrix,Wr as formatCssLengthPx,jr as formatMatrix3d,Yr as formatSolidQuadEntryMatrix,dt as getSolidPaintDefaults,jn as getSolidPaintDefaultsFromPlans,bo as injectPolyBaseStyles,mn as isBorderShapeSupported,Ve as isFullRectSolid,Be as isProjectiveQuadPlan,Ke as isSolidTrianglePlan,fn as isSolidTriangleSupported,xt as packTextureAtlasPlansWithScale,_t as renderPolygonsWithStableTriangles,pt as renderPolygonsWithTextureAtlas,Qt as renderPolygonsWithTextureAtlasAsync,Jt as updatePolygonsWithStableTopology,uo as updatePolygonsWithStableTriangles,Kt as updateStableTriangleFrame,Vf as worldDirectionToPolyCss,Bf as worldPositionToPolyCss};