@layoutit/polycss 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -13
- package/dist/{PolyShapeElements-prI_DBZX.d.cts → PolyShapeElements-CoKhApyN.d.cts} +141 -31
- package/dist/{PolyShapeElements-prI_DBZX.d.ts → PolyShapeElements-CoKhApyN.d.ts} +141 -31
- package/dist/elements.cjs +128 -53
- package/dist/elements.d.cts +1 -1
- package/dist/elements.d.ts +1 -1
- package/dist/elements.js +128 -53
- package/dist/index.cjs +407 -52
- package/dist/index.d.cts +35 -95
- package/dist/index.d.ts +35 -95
- package/dist/index.js +407 -52
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var $o=Object.defineProperty;var os=Object.getOwnPropertyDescriptor;var rs=Object.getOwnPropertyNames;var is=Object.prototype.hasOwnProperty;var ss=(e,n)=>{for(var t in n)$o(e,t,{get:n[t],enumerable:!0})},Uo=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of rs(n))!is.call(e,r)&&r!==t&&$o(e,r,{get:()=>n[r],enumerable:!(o=os(n,r))||o.enumerable});return e},Te=(e,n,t)=>(Uo(e,n,"default"),t&&Uo(t,n,"default"));var as=e=>Uo($o({},"__esModule",{value:!0}),e);var ve={};ss(ve,{PolyBoxElement:()=>To,PolyCameraElement:()=>Po,PolyConeElement:()=>Do,PolyCylinderElement:()=>Ro,PolyDodecahedronElement:()=>_o,PolyFirstPersonControlsElement:()=>bo,PolyIcosahedronElement:()=>wo,PolyMapControlsElement:()=>ho,PolyMeshElement:()=>un,PolyOctahedronElement:()=>Mo,PolyOrbitControlsElement:()=>yo,PolyOrthographicCameraElement:()=>dn,PolyPerspectiveCameraElement:()=>xo,PolyPlaneElement:()=>Eo,PolyPolygonElement:()=>po,PolyRingElement:()=>Ao,PolySceneElement:()=>Je,PolySelectElement:()=>Co,PolySphereElement:()=>Oo,PolyTetrahedronElement:()=>Lo,PolyTorusElement:()=>ko,PolyTransformControlsElement:()=>vo,buildAtlasPages:()=>zt,buildTextureEdgeRepairSets:()=>Ot.buildTextureEdgeRepairSets,collectPolyRenderStats:()=>Hi,computeTextureAtlasPlanPublic:()=>Xn.computeTextureAtlasPlanPublic,createPolyBox:()=>Ii,createPolyCamera:()=>hi,createPolyCone:()=>ji,createPolyCylinder:()=>Yi,createPolyDodecahedron:()=>Gi,createPolyFirstPersonControls:()=>no,createPolyIcosahedron:()=>$i,createPolyMapControls:()=>to,createPolyOctahedron:()=>Bi,createPolyOrbitControls:()=>eo,createPolyOrthographicCamera:()=>Dt,createPolyPerspectiveCamera:()=>$t,createPolyPlane:()=>Vi,createPolyRing:()=>zi,createPolyScene:()=>Qn,createPolySphere:()=>Ni,createPolyTetrahedron:()=>Ui,createPolyTorus:()=>Wi,createSelect:()=>oo,createTransformControls:()=>co,cssBorderShapeForPlan:()=>Rt.cssBorderShapeForPlan,filterAtlasPlans:()=>Bn,formatBorderShapeEntryMatrix:()=>Rt.formatBorderShapeEntryMatrix,formatCssLengthPx:()=>at.formatCssLengthPx,formatMatrix3d:()=>at.formatMatrix3d,formatSolidQuadEntryMatrix:()=>at.formatSolidQuadEntryMatrix,getSolidPaintDefaults:()=>_t,getSolidPaintDefaultsFromPlans:()=>zn,injectPolyBaseStyles:()=>Zn,isBorderShapeSupported:()=>Sn,isFullRectSolid:()=>Z.isFullRectSolid,isProjectiveQuadPlan:()=>Z.isProjectiveQuadPlan,isSolidTrianglePlan:()=>Z.isSolidTrianglePlan,isSolidTriangleSupported:()=>Tn,packTextureAtlasPlansWithScale:()=>Vt,renderPolygonsWithStableTriangles:()=>Nt,renderPolygonsWithTextureAtlas:()=>Ut,renderPolygonsWithTextureAtlasAsync:()=>tn,updatePolygonsWithStableTopology:()=>on,updatePolygonsWithStableTriangles:()=>Wn,updateStableTriangleFrame:()=>nn});module.exports=as(ve);var X=require("@layoutit/polycss-core");var wr=require("@layoutit/polycss-core");function ls(e){if(!e)return!1;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return t?t("(pointer: coarse)").matches||t("(hover: none)").matches:!1}function Vt(e,n,t){return(0,wr.packTextureAtlasPlansWithScaleCore)(e,n,ls(t))}var Ot=require("@layoutit/polycss-core");var xt=require("@layoutit/polycss-core"),Fr=require("@layoutit/polycss-core"),Hr=require("@layoutit/polycss-core"),Ir=require("@layoutit/polycss-core"),Yt=new Map;function cs(e){let n=Yt.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}),Yt.set(e,n),n.then(()=>{Yt.get(e)===n&&Yt.delete(e)},()=>{Yt.get(e)===n&&Yt.delete(e)})),n}function qe(e,n,t=1,o=0,r=0,i=1,s=0,c=0){e.setTransform(t*n,o*n,r*n,i*n,s*n,c*n)}function us(e,n,t,o,r,i,s){Math.abs(i.r-1)<.001&&Math.abs(i.g-1)<.001&&Math.abs(i.b-1)<.001||(e.save(),qe(e,s),e.globalCompositeOperation="multiply",e.fillStyle=(0,Fr.tintToCss)(i),e.fillRect(n,t,o,r),e.restore())}function ds(e,n,t,o,r,i,s){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,p=Math.max(r/c,i/l),m=c*p,b=l*p;qe(e,s),e.drawImage(n,t+(r-m)/2,o+(i-b)/2,m,b)}function jt(e,n){return Math.max(0,Math.min(n,e))}function _r(e,n,t,o,r,i,s,c){let l=n.naturalWidth||n.width||1,p=n.naturalHeight||n.height||1,m=jt(Math.min(t.minU,t.maxU)*l,l),b=jt(Math.max(t.minU,t.maxU)*l,l),y=jt(Math.min(t.minV,t.maxV)*p,p),P=jt(Math.max(t.minV,t.maxV)*p,p),h=Math.floor(m),v=Math.floor(y),f=Math.ceil(b)-h,C=Math.ceil(P)-v;f<1&&(h=Math.floor(jt((t.minU+t.maxU)/2*l,l-1)),f=1),C<1&&(v=Math.floor(jt((t.minV+t.maxV)/2*p,p-1)),C=1),h=Math.max(0,Math.min(l-1,h)),v=Math.max(0,Math.min(p-1,v)),f=Math.max(1,Math.min(l-h,f)),C=Math.max(1,Math.min(p-v,C)),qe(e,c),e.drawImage(n,h,v,f,C,o,r,i,s)}function Vr(e){return e==="repeat"||e==="mirrored-repeat"}function Or(e,n){return Vr(e)?Math.floor(n):0}function Rr(e,n){return Vr(e)?Math.ceil(n)-1:0}function Dr(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function kr(e,n,t,o,r,i,s){let c=r?Or(i,r.minU):0,l=r?Rr(i,r.maxU):0,p=r?Or(s,r.minV):0,m=r?Rr(s,r.maxV):0;for(let b=c;b<=l;b++)for(let y=p;y<=m;y++){let P=Dr(i,b),h=Dr(s,y);if(!P&&!h){e.drawImage(n,b*t,y*o);continue}e.save(),e.translate((P?b+1:b)*t,(h?y+1:y)*o),e.scale(P?-1:1,h?-1:1),e.drawImage(n,0,0),e.restore()}}function Go(e,n,t,o){for(let r=0;r<o.length;r+=2){let i=n+o[r],s=t+o[r+1];r===0?e.moveTo(i,s):e.lineTo(i,s)}e.closePath()}function Hn(e,n,t,o,r,i){for(let s=0;s<o.length;s+=2){let c=n+o[s]+r,l=t+o[s+1]+i;s===0?e.moveTo(c,l):e.lineTo(c,l)}e.closePath()}function ps(e,n,t,o){qe(e,o),e.beginPath(),Go(e,n.x,n.y,n.screenPts),e.clip(),qe(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function In(e,n,t,o,r){n.polygon.textureAlphaMode==="opaque"&&(qe(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+r,n.canvasW,n.canvasH))}function ms(e,n,t,o,r=0,i=0){if(n.textureTriangles?.length){let s=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1;for(let l of n.textureTriangles){let p=(0,Hr.expandClipPoints)(l.screenPts,xt.TEXTURE_TRIANGLE_BLEED);e.save(),qe(e,o),e.beginPath(),Hn(e,n.x,n.y,p,r,i),e.clip(),In(e,n,o,r,i),l.uvAffine?(qe(e,o,l.uvAffine.a/s,l.uvAffine.c/s,l.uvAffine.b/c,l.uvAffine.d/c,n.x+l.uvAffine.e+r,n.y+l.uvAffine.f+i),kr(e,t,s,c,l.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t)):l.uvSampleRect&&_r(e,t,l.uvSampleRect,n.x+r,n.y+i,n.canvasW,n.canvasH,o),e.restore()}}else if(n.uvAffine){let s=t.naturalWidth||t.width||1,c=t.naturalHeight||t.height||1,l=n.polygon.textureAlphaMode==="opaque";l&&(e.save(),qe(e,o),e.beginPath(),Hn(e,n.x,n.y,n.screenPts,r,i),e.clip(),In(e,n,o,r,i)),qe(e,o,n.uvAffine.a/s,n.uvAffine.c/s,n.uvAffine.b/c,n.uvAffine.d/c,n.x+n.uvAffine.e+r,n.y+n.uvAffine.f+i),kr(e,t,s,c,n.uvSampleRect,n.polygon.textureWrap?.s,n.polygon.textureWrap?.t),l&&e.restore()}else if(n.uvSampleRect){let s=n.polygon.textureAlphaMode==="opaque";s&&(e.save(),qe(e,o),e.beginPath(),Hn(e,n.x,n.y,n.screenPts,r,i),e.clip(),In(e,n,o,r,i)),_r(e,t,n.uvSampleRect,n.x+r,n.y+i,n.canvasW,n.canvasH,o),s&&e.restore()}else{let s=n.polygon.textureAlphaMode==="opaque";s&&(e.save(),qe(e,o),e.beginPath(),Hn(e,n.x,n.y,n.screenPts,r,i),e.clip(),In(e,n,o,r,i)),ds(e,t,n.x+r,n.y+i,n.canvasW,n.canvasH,o),s&&e.restore()}}function fs(e,n,t,o,r,i){let s=r-t,c=i-o,l=s*s+c*c;if(l<=Ir.BASIS_EPS)return Math.hypot(e-t,n-o);let p=Math.max(0,Math.min(1,((e-t)*s+(n-o)*c)/l));return Math.hypot(e-(t+s*p),n-(o+c*p))}function gs(e,n,t,o){let r=1/0,i=t.length/2;for(let s of o){if(s<0||s>=i)continue;let c=s*2,l=(s+1)%i*2;r=Math.min(r,fs(e,n,t[c],t[c+1],t[l],t[l+1]))}return r}function ys(e,n,t,o,r,i){let s=Math.max(0,o-i),c=Math.min(n-1,o+i),l=Math.max(0,r-i),p=Math.min(t-1,r+i),m=null,b=1/0;for(let y=l;y<=p;y++)for(let P=s;P<=c;P++){if(P===o&&y===r)continue;let h=P-o,v=y-r,f=h*h+v*v;if(f>i*i||f>=b)continue;let C=(y*n+P)*4;e[C+3]<xt.TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN||(m=C,b=f)}return m}function hs(e,n,t){if(!n.textureEdgeRepair||!n.texture||!n.textureEdgeRepairEdges||n.textureEdgeRepairEdges.size===0)return;let o=e.canvas;if(!o)return;let r=Math.max(0,Math.floor(n.x*t)),i=Math.max(0,Math.floor(n.y*t)),s=Math.max(1,Math.min(o.width-r,Math.ceil(n.canvasW*t))),c=Math.max(1,Math.min(o.height-i,Math.ceil(n.canvasH*t)));if(s<=0||c<=0)return;let l;try{l=e.getImageData(r,i,s,c)}catch{return}let p=l.data,m=new Uint8ClampedArray(p),b=Math.max(xt.TEXTURE_EDGE_REPAIR_RADIUS,xt.TEXTURE_EDGE_REPAIR_RADIUS/t),y=Math.max(2,Math.ceil(b*t)+1),P=!1;for(let h=0;h<c;h++)for(let v=0;v<s;v++){let f=(h*s+v)*4,C=p[f+3];if(C<xt.TEXTURE_EDGE_REPAIR_ALPHA_MIN||C===255)continue;let R=(r+v+.5)/t-n.x,k=(i+h+.5)/t-n.y;if(gs(R,k,n.screenPts,n.textureEdgeRepairEdges)>b)continue;let N=ys(m,s,c,v,h,y);N!==null&&(p[f]=m[N],p[f+1]=m[N+1],p[f+2]=m[N+2],p[f+3]=255,P=!0)}P&&e.putImageData(l,r,i)}function bs(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 xs(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let i=e.entries.some(m=>m.textureEdgeRepair&&m.texture&&m.textureEdgeRepairEdges&&m.textureEdgeRepairEdges.size>0),s=r.getContext("2d",i?{willReadFrequently:!0}:void 0);if(!s)return{width:e.width,height:e.height,url:null};let c=Array.from(new Set(e.entries.flatMap(m=>m.texture?[m.texture]:[]))),l=new Map;await Promise.all(c.map(async m=>{l.set(m,await cs(m))}));for(let m of e.entries){let b=m.texture?l.get(m.texture):null;if(!m.texture){s.save(),ps(s,m,n,o),s.restore();continue}b&&(s.save(),qe(s,o),s.beginPath(),Go(s,m.x,m.y,m.screenPts),s.clip(),ms(s,m,b,o),s.restore()),m.texture&&n==="baked"&&(s.save(),qe(s,o),s.beginPath(),Go(s,m.x,m.y,m.screenPts),s.clip(),us(s,m.x,m.y,m.canvasW,m.canvasH,m.textureTint,o),s.restore()),hs(s,m,o)}let p=await bs(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:p}}async function zt(e,n,t,o,r){let i=[];for(let s of e){if(r())break;i.push(await xs(s,n,t,o))}return i}var Z=require("@layoutit/polycss-core"),Vn=require("@layoutit/polycss-core"),Br=require("@layoutit/polycss-core");var zr=require("@layoutit/polycss-core");function Wt(e){let t=e?.defaultView?.__polycssProjectiveQuadGuards;return(0,zr.resolveProjectiveQuadGuards)(t)}function Xt(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 Yo(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,Z.safariCssProjectiveUnsupported)(t):!0}function Pn(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 Ps(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 vs(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function it(e,n){return n?.disable?.includes("u")?null:Ps(e)?"corner-bevel":Yo(e)?vs(e)?"border-large":"border":null}function vn(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,Z.safariCssProjectiveUnsupported)(t):!0}function Cn(e,n,t,o,r){let i=new Set(o?.disable??[]);return(0,Z.getSolidPaintDefaultsForPlansCore)(e,n,i,{solidTriangleSupported:Yo(t),projectiveQuadSupported:vn(t),cornerShapeSupported:Pn(t),borderShapeSupported:Xt(t)},Vn.parseHex,Vn.rgbKey,r)}function zn(e,n,t=new Set,o){let r=o??(typeof document<"u"?document:null);if(!r)return{};let i=t.size>0?{disable:Array.from(t)}:void 0;return Cn(e,n,r,i)}function Sn(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 Xt(n)}function Tn(e){let n=e??(typeof document<"u"?document:null);if(!n){let t=(typeof navigator<"u"?navigator:globalThis.navigator)?.userAgent??"";if(!t)return!0;let o=/\b(?:Chrome|HeadlessChrome|Chromium|Edg|OPR)\//.test(t);return!/\bVersion\/[\d.]+.*\bSafari\//.test(t)||o}return Yo(n)}function Bn(e,n,t,o){return(0,Z.filterAtlasPlans)(e,n,t,{solidTriangleSupported:Tn(o),borderShapeSupported:Sn(o)})}var yt=require("@layoutit/polycss-core"),st=require("@layoutit/polycss-core");var en=require("@layoutit/polycss-core");var vt=require("@layoutit/polycss-core"),Nr=require("@layoutit/polycss-core");var Zt=require("@layoutit/polycss-core");function Ne(e,n,t){let o=e.getAttribute("style")??"",r=`${n}:${t}`,i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(`(^|;)\\s*${i}\\s*:[^;]*`,"i"),c=s.test(o)?o.replace(s,(l,p)=>`${p}${r}`):`${o}${o.trim()&&!o.trim().endsWith(";")?";":""}${r}`;c!==o&&e.setAttribute("style",c)}function At(e,n){let t=e.getAttribute("style")??"";if(!t||!t.toLowerCase().includes(n.toLowerCase()))return;let o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`^\\s*${o}\\s*:`,"i"),i=t.split(";").map(s=>s.trim()).filter(s=>s&&!r.test(s)).join(";");i?e.setAttribute("style",i):e.removeAttribute("style")}function En(e,n,t,o=!1){if(n==="dynamic"){let r=(0,Zt.parseHex)(e.polygon.color??"#cccccc"),i=o?"":`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`;return(0,Zt.rgbKey)(r)!==t?.dynamicColorKey&&(i+=`;--psr:${(r.r/255).toFixed(4)};--psg:${(r.g/255).toFixed(4)};--psb:${(r.b/255).toFixed(4)}`),i}return e.shadedColor&&e.shadedColor!==t?.paintColor?`;color:${e.shadedColor}`:""}function Cs(e,n){Ne(e,"--pnx",n.normal[0].toFixed(4)),Ne(e,"--pny",n.normal[1].toFixed(4)),Ne(e,"--pnz",n.normal[2].toFixed(4))}function Qt(e,n,t,o){if(t==="dynamic"){At(e,"color"),At(e,"background"),Cs(e,n);let r=(0,Zt.parseHex)(n.polygon.color??"#cccccc");(0,Zt.rgbKey)(r)===o?.dynamicColorKey?(At(e,"--psr"),At(e,"--psg"),At(e,"--psb")):(Ne(e,"--psr",(r.r/255).toFixed(4)),Ne(e,"--psg",(r.g/255).toFixed(4)),Ne(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(At(e,"background"),Ne(e,"color",n.shadedColor)):(At(e,"background"),At(e,"color"))}var qt=require("@layoutit/polycss-core"),Pt=require("@layoutit/polycss-core"),Nn=require("@layoutit/polycss-core"),gt=require("@layoutit/polycss-core"),jo=new WeakMap,Wo=new WeakMap;function Ue(e,n){let t=jo.get(e),o=Wo.get(e);if(!n.data&&(!t||t.length===0)){e.__polycssHasDataAttrs=!1;return}let r=new Map;if(n.data)for(let[s,c]of Object.entries(n.data))r.set(s,String(c));if(t)for(let s of t)r.has(s)||e.removeAttribute(`data-${s}`);for(let[s,c]of r)o?.get(s)!==c&&e.setAttribute(`data-${s}`,c);let i=Array.from(r.keys());i.length>0?jo.set(e,i):jo.delete(e),r.size>0?Wo.set(e,r):Wo.delete(e),e.__polycssHasDataAttrs=i.length>0}function Kt(e){return e.__polycssHasDataAttrs===!0}function Xo(e,n,t,o,r=t==="dynamic"){if(!n.url)return;let i=`url(${n.url})`,s=o.canvasW||1,c=o.canvasH||1,l=(0,Pt.atlasCanonicalSizeForEntry)(o),p=`${(0,vt.formatCssLength)(-o.x/s*l)} ${(0,vt.formatCssLength)(-o.y/c*l)}`,m=`${(0,vt.formatCssLength)(n.width/s*l)} ${(0,vt.formatCssLength)(n.height/c*l)}`,b=`transform:matrix3d(${o.atlasMatrix});--polycss-atlas-size:${l}px`,y=`${b};--polycss-atlas-position:${p};--polycss-atlas-image-size:${m}`;if(t==="dynamic"){let P=r?`;--pnx:${o.normal[0].toFixed(4)};--pny:${o.normal[1].toFixed(4)};--pnz:${o.normal[2].toFixed(4)}`:"";e.setAttribute("style",y+`;--polycss-atlas-url:${i}`+P)}else e.setAttribute("style",b+`;background:${i} ${p} / ${m} no-repeat`)}function Ur(e,n,t,o){if(n.texture){if(!t.texture||n.texture!==t.texture)return!1}else if(t.texture)return!1;let r=$r(n,t);return r?(e.style.visibility="",Ne(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(Ne(e,"--pnx",r.normal[0].toFixed(4)),Ne(e,"--pny",r.normal[1].toFixed(4)),Ne(e,"--pnz",r.normal[2].toFixed(4))),Ue(e,t),!0):(e.style.visibility="hidden",Ue(e,t),!0)}function Zo(e,n,t,o,r){if(o!=="baked")return{...e,polygon:n,normal:t};let i=r.directionalLight,s=r.ambientLight,c=i?.direction??gt.DEFAULT_LIGHT_DIR,l=i?.color??gt.DEFAULT_LIGHT_COLOR,p=Math.max(0,i?.intensity??gt.DEFAULT_LIGHT_INTENSITY),m=s?.color??gt.DEFAULT_AMBIENT_COLOR,b=Math.max(0,s?.intensity??gt.DEFAULT_AMBIENT_INTENSITY),y=Math.hypot(c[0],c[1],c[2])||1,P=c[0]/y,h=c[1]/y,v=c[2]/y,f=p*Math.max(0,t[0]*P+t[1]*h+t[2]*v);return{...e,polygon:n,normal:t,shadedColor:(0,Nr.shadePolygon)(n.color??"#cccccc",f,l,m,b)}}function $r(e,n){let t=Gr(e,n);if(!t)return null;let{normal:o,xAxis:r,yAxis:i,tx:s,ty:c,tz:l}=t;return{normal:o,matrix:(0,vt.formatMatrix3dValues)([r[0]*e.canvasW/(0,Pt.atlasCanonicalSizeForEntry)(e),r[1]*e.canvasW/(0,Pt.atlasCanonicalSizeForEntry)(e),r[2]*e.canvasW/(0,Pt.atlasCanonicalSizeForEntry)(e),0,i[0]*e.canvasH/(0,Pt.atlasCanonicalSizeForEntry)(e),i[1]*e.canvasH/(0,Pt.atlasCanonicalSizeForEntry)(e),i[2]*e.canvasH/(0,Pt.atlasCanonicalSizeForEntry)(e),0,o[0],o[1],o[2],0,s,c,l,1])}}var Gr=Nn.stableBasisFromPlan;function Ss(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=Gr(e,n);if(!o)return null;let r=(0,Nn.computeProjectiveQuadMatrix)(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return r?{matrix:r,normal:o.normal}:null}function Qo(e,n,t,o,r=!1){let i=t.createElement("b");return i.setAttribute("style",`transform:matrix3d(${(0,vt.formatSolidQuadMatrix)(e)})`+En(e,n,o,r)),Ue(i,e.polygon),i}function qo(e,n,t,o,r=!1){let i=t.createElement("i");return i.setAttribute("style",(0,qt.formatBorderShapeElementStyle)(e)+En(e,n,o,r)),Ue(i,e.polygon),i}function Ko(e,n,t,o,r,i=!1){let s=o.createElement("u");return s.setAttribute("style",(0,qt.formatCornerShapeElementStyle)(e,n)+En(e,t,r,i)),Ue(s,e.polygon),s}function Jo(e,n,t,o,r=!1){let i=t.createElement("b");return i.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+En(e,n,o,r)),Ue(i,e.polygon),i}function Yr(e,n,t,o,r,i,s){let c=n.projectiveMatrix?Ss(n,t,i):$r(n,t);if(!c)return!1;let l=Zo(n,t,c.normal,o,r);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,Qt(e,l,o,s),Ue(e,l.polygon),!0}function jr(e,n,t,o){e.style.visibility="",e.setAttribute("style",(0,qt.formatBorderShapeElementStyle)(n)),Qt(e,n,t,o),Ue(e,n.polygon)}function Wr(e,n,t,o,r){e.style.visibility="",e.setAttribute("style",(0,qt.formatCornerShapeElementStyle)(n,t)),Qt(e,n,o,r),Ne(e,"background","currentColor"),Ue(e,n.polygon)}function er(e,n,t,o=!1){let r=t.createElement("s"),i=(0,Pt.atlasCanonicalSizeForEntry)(e),s=n==="dynamic"&&!o?`;--pnx:${e.normal[0].toFixed(4)};--pny:${e.normal[1].toFixed(4)};--pnz:${e.normal[2].toFixed(4)}`:"";return r.setAttribute("style",`transform:matrix3d(${e.atlasMatrix});--polycss-atlas-size:${i}px;opacity:0`+s),Ue(r,e.polygon),r}var Qr=require("@layoutit/polycss-core");var Un=require("@layoutit/polycss-core");function Mt(e,n,t,o={}){let r=o.primitive!=null?void 0:(()=>{let i=t.doc??(typeof document<"u"?document:null);return i?it(i,t.strategies)??"border":"border"})();return(0,Un.computeSolidTrianglePlan)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??r})}function tr(e,n,t,o,r,i,s,c,l,p,m,b,y){let P=o.primitive!=null?void 0:(()=>{let h=t.doc??(typeof document<"u"?document:null);return h?it(h,t.strategies)??"border":"border"})();return(0,Un.computeSolidTrianglePlanFromCssPoints)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??P},r,i,s,c,l,p,m,b,y)}var Bt=require("@layoutit/polycss-core"),wt=require("@layoutit/polycss-core"),nr=require("@layoutit/polycss-core");var $n=require("@layoutit/polycss-core");var Ts=1.5;function or(e,n){return(0,Bt.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function rr(e,n,t){return n?{...t,seamBleed:n.has(e)?Ts:void 0,seamEdges:n.get(e)}:t}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 Xr(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function Lt(e,n,t,o,r,i){return t?i.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:r==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:Xr(n,i):!0}function ir(e,n){let t=e;t.__polycssSolidTrianglePrimitive!==n&&(e.classList.toggle(Bt.SOLID_TRIANGLE_CORNER_CLASS,n==="corner-bevel"),e.classList.toggle(Bt.SOLID_TRIANGLE_LARGE_BORDER_CLASS,n==="border-large"),t.__polycssSolidTrianglePrimitive=n)}function sr(e){let n=e;n.__polycssSolidTriangleHidden&&(e.style.visibility="",n.__polycssSolidTriangleHidden=!1)}function Jt(e){let n=e;n.__polycssSolidTriangleHidden||(e.style.visibility="hidden",n.__polycssSolidTriangleHidden=!0)}function An(e,n){e.setAttribute("style",n.styleText),ir(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||Kt(e))&&Ue(e,n.polygon)}function Zr(e,n,t,o){if(!n.colorComputed){(n.polygon.data||Kt(e))&&Ue(e,n.polygon);return}let r=e,i=n.bakedColor??"",s=n.bakedRgb,c=n.bakedAlpha??1,l=r.__polycssSolidTriangleColor,p=r.__polycssSolidTriangleColorRgb,m=r.__polycssSolidTriangleColorAlpha??1,b=o??Xr(n.index,t);if(!t.updatesDisabled&&l!==i&&(l===void 0||b)){let y=i,P=s;if(t.maxStep>0&&p&&s&&m===c){let h=(0,wt.stepRgbToward)(p,s,t.maxStep);P=h,y=(0,wt.rgbToCss)(h,c)}(y!==l||!(0,wt.rgbEqual)(P,p))&&(e.style.color=y),r.__polycssSolidTriangleColor=y,r.__polycssSolidTriangleColorRgb=P,r.__polycssSolidTriangleColorAlpha=c,r.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||Kt(e))&&Ue(e,n.polygon)}function Mn(e,n,t,o){let r=e;ir(e,n.primitive),r.__polycssSolidTriangleBasis!==n.basis&&(r.__polycssSolidTriangleBasis=n.basis),sr(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||Kt(e))&&Zr(e,n,t,o)}function Yn(e,n,t,o){sr(e),Zr(e,n,t,o)}function Ln(e,n){let t=e;ir(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),sr(e),e.style.transform=n.transformText,(n.polygon.data||Kt(e))&&Ue(e,n.polygon)}function Es(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 ar(e,n,t){if(t.stableTriangleColorPolicy!=="adaptive")return null;if(t.stableTriangleColorFreezeFrames===0)return new Set;let o=Math.max(0,Math.floor(t.stableTriangleColorFrame??0)),r=Math.max(1,Math.floor(t.stableTriangleColorFreezeFrames??1));if(r<=1&&!Number.isFinite(t.stableTriangleColorBudget))return null;let i=Es(e.length,t),s=Math.max(1,Math.floor(t.stableTriangleColorMaxAge??Math.max(2,r*2))),c=[];for(let l=0;l<e.length;l++){let p=e[l],m=n[l];if(p.kind!=="triangle"||!m)continue;let b=p.element,y=b.__polycssSolidTriangleColor,P=m.bakedColor??"";if(y===P)continue;let h=b.__polycssSolidTriangleColorFrame??0,v=Math.max(0,o-h),f=(0,wt.colorErrorScore)(y,P);c.push({index:l,score:(v>=s?1e6:0)+f*1e4+v})}return c.length===0?new Set:(c.sort((l,p)=>p.score-l.score),new Set(c.slice(0,i).map(l=>l.index)))}function jn(e,n){let t=n.createElement("u");return An(t,e),t}function As(e,n){let t=n.createElement("u");return Jt(t),e.data&&Ue(t,e),t}function lr(e,n,t,o,r,i){let s=t,c=s.stableTriangleDebug,l=o&&r==="color-only";if(s.stableTriangleColorPolicy==="adaptive"||e.length!==n.length)return!1;let p=(0,$n.stableTriangleMatrixDecimals)(s.stableTriangleMatrixDecimals),m=t.doc??(typeof document<"u"?document:null),b=m?it(m,t.strategies)??"border":"border";for(let P=0;P<e.length;P++){let h=e[P];if(h.kind!=="triangle"||h.polygonIndex!==P||!n[P])return!1}let y=or(n,t);for(let P=0;P<e.length;P++){let h=e[P].element,v=n[P];if(l){if(Lt(h,P,o,c,s.stableTriangleColorPolicy,i)){let C=(0,nr.computeSolidTriangleColorPlan)(v,P,t);if(!C)continue;Yn(h,C,i)}continue}let f=Mt(v,P,rr(P,y,t),{basis:h.__polycssSolidTriangleBasis,matrixDecimals:p,primitive:b,includeColor:r!=="plan-only"&&r!=="transform-only"&&Lt(h,P,o,c,s.stableTriangleColorPolicy,i)});if(!f){Jt(h);continue}o&&r==="plan-only"||(o&&r==="transform-only"?Ln(h,f):o?Mn(h,f,i):An(h,f))}return!0}function Nt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=it(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let r=(0,$n.stableTriangleMatrixDecimals)(n.stableTriangleMatrixDecimals),i=[],s=or(e,n);for(let c=0;c<e.length;c+=1){let l=e[c],p=Mt(l,c,rr(c,s,n),{matrixDecimals:r,primitive:o}),m=p?jn(p,t):As(l,t);i.push({polygonIndex:c,element:m,kind:"triangle",dispose:()=>{}})}return{rendered:i,dispose(){}}}function Wn(e,n,t={}){let o=t.doc??(typeof document<"u"?document:null);if(!o)return{rendered:e,dispose:()=>{}};let r=it(o,t.strategies);if(!r||e.some(f=>f.kind!=="triangle")||n.length!==e.length)return null;for(let f=0;f<e.length;f++)if(e[f].polygonIndex!==f)return null;let i=t.optimizeStableTriangleStyle===!0&&(t.textureLighting??"baked")==="baked",s=t,c=s.stableTriangleDebug,l=s.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full"),p=i&&l==="color-only",m=Gn(s),b=(0,$n.stableTriangleMatrixDecimals)(s.stableTriangleMatrixDecimals);if(lr(e,n,t,i,l,m))return{rendered:e,dispose(){}};let y=new Array(e.length),P=new Array(e.length),h=or(n,t);for(let f=0;f<e.length;f++){let C=e[f].element;if(p){let R=s.stableTriangleColorPolicy==="adaptive"||Lt(C,f,i,c,s.stableTriangleColorPolicy,m);P[f]=R?(0,nr.computeSolidTriangleColorPlan)(n[f],f,t):null;continue}y[f]=Mt(n[f],f,rr(f,h,t),{basis:C.__polycssSolidTriangleBasis,matrixDecimals:b,primitive:r,includeColor:l!=="plan-only"&&l!=="transform-only"&&Lt(C,f,i,c,s.stableTriangleColorPolicy,m)})}let v=i&&l!=="plan-only"&&l!=="transform-only"?ar(e,p?P:y,s):null;for(let f=0;f<e.length;f++){if(p){let R=P[f];R&&Yn(e[f].element,R,m,v?.has(f));continue}let C=y[f];if(!C){Jt(e[f].element);continue}i&&l==="plan-only"||(i&&l==="transform-only"?Ln(e[f].element,C):i?Mn(e[f].element,C,m,v?.has(f)):An(e[f].element,C))}return{rendered:e,dispose(){}}}var ur=require("@layoutit/polycss-core"),qr=1.5;function Kr(){return new Promise(e=>setTimeout(e,0))}async function cr(e){return performance.now()-e<yt.ASYNC_RENDER_BUDGET_MS?e:(await Kr(),performance.now())}function Jr(e,n){return e.seamBleedEdges?.size?{...n,seamBleed:qr,seamEdges:e.seamBleedEdges}:{...n,seamBleed:void 0,seamEdges:void 0}}function ei(e,n){return(0,st.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function ti(e,n,t){return n?{...t,seamBleed:n.has(e)?qr:void 0,seamEdges:n.get(e)}:t}function _t(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=(0,st.buildBasisHints)(e,n),r=Wt(t),i=e.map((s,c)=>(0,st.computeTextureAtlasPlan)(s,c,n,r,o[c]));return Cn(i,n.textureLighting??"baked",t,n.strategies)}function Ut(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=n,i=o==="dynamic"&&r.skipDynamicNormalVars===!0,s=new Set(n.strategies?.disable??[]),c=!s.has("b"),l=c&&vn(t),p=it(t,n.strategies),m=p!==null,b=!s.has("i")&&Pn(t),y=!s.has("i")&&Xt(t),P=(0,st.buildBasisHints)(e,n),h=Wt(t),v=ei(e,n),f=e.map((u,g)=>(0,st.computeTextureAtlasPlan)(u,g,ti(g,v,n),h,P[g])),C=n.solidPaintDefaults??(r.computeSolidPaintDefaults?Cn(f,o,t,n.strategies):void 0),R=C?{...n,solidPaintDefaults:C}:n,k=f.map(u=>u&&m&&(0,Z.isSolidTrianglePlan)(u)?Mt(u.polygon,u.index,Jr(u,R),{primitive:p??void 0}):null),N=f.map(u=>u&&b&&!(0,Z.isSolidTrianglePlan)(u)&&!(c&&(0,Z.isFullRectSolid)(u))&&!(l&&(0,Z.isProjectiveQuadPlan)(u))?(0,en.cornerShapeGeometryForPlan)(u):null),O=f.map((u,g)=>u&&(u.texture||!(c&&(0,Z.isFullRectSolid)(u))&&!k[g]&&!(l&&(0,Z.isProjectiveQuadPlan)(u))&&!N[g]&&!y?u:null)),{packed:ee,atlasScale:z}=Vt(O,n.textureQuality,t),F=new Map,$=[],U=!1,ae=[];for(let u=0;u<e.length;u++){let g=f[u],T=k[u],A=N[u];if(!g)continue;let L=ee.entries[u];if(L){let M=er(L,o,t,i);F.set(u,M),$.push({polygonIndex:u,element:M,kind:"atlas",plan:L,dispose:()=>{}})}else if(!g.texture&&c&&(0,Z.isFullRectSolid)(g)){let M=Qo(g,o,t,C,i);$.push({polygonIndex:u,element:M,kind:"solid",plan:g,dispose:()=>{}})}else if(!g.texture&&T){let M=jn(T,t);$.push({polygonIndex:u,element:M,kind:"triangle",plan:g,dispose:()=>{}})}else if(!g.texture&&l&&(0,Z.isProjectiveQuadPlan)(g)){let M=Jo(g,o,t,C,i);$.push({polygonIndex:u,element:M,kind:"solid",plan:g,dispose:()=>{}})}else if(!g.texture&&A){let M=Ko(g,A,o,t,C,i);$.push({polygonIndex:u,element:M,kind:"corner",plan:g,dispose:()=>{}})}else if(!g.texture&&y){let M=qo(g,o,t,C,i);$.push({polygonIndex:u,element:M,kind:"border",plan:g,dispose:()=>{}})}}return $.sort((u,g)=>u.polygonIndex-g.polygonIndex),zt(ee.pages,o,t,z,()=>U).then(u=>{if(U){for(let g of u)g.url?.startsWith("blob:")&&URL.revokeObjectURL(g.url);return}ae=u.flatMap(g=>g.url?.startsWith("blob:")?[g.url]:[]);for(let g=0;g<ee.pages.length;g++){let T=ee.pages[g],A=u[g];if(A)for(let L of T.entries){let M=F.get(L.index);!M||!A.url||Xo(M,A,o,L,!i)}}}).catch(()=>{if(!U)for(let u of F.values())Ne(u,"opacity","0.5"),Ne(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:$,solidPaintDefaults:C??{},dispose(){U=!0;for(let u of ae)URL.revokeObjectURL(u);ae=[]}}}async function tn(e,n={},t=()=>!1){let o=n.doc??(typeof document<"u"?document:null);if(!o||t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let r=n.textureLighting??"baked",s=r==="dynamic"&&n.skipDynamicNormalVars===!0,c=new Set(n.strategies?.disable??[]),l=!c.has("b"),p=l&&vn(o),m=it(o,n.strategies),b=m!==null,y=!c.has("i")&&Pn(o),P=!c.has("i")&&Xt(o);if(await Kr(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let h=(0,st.buildBasisHints)(e,n),v=Wt(o),f=ei(e,n),C=performance.now(),R=new Array(e.length);for(let u=0;u<e.length;u++)if(R[u]=(0,st.computeTextureAtlasPlan)(e[u],u,ti(u,f,n),v,h[u]),C=await cr(C),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let k=n.solidPaintDefaults??Cn(R,r,o,n.strategies),N=new Array(R.length),O=new Array(R.length),ee=new Array(R.length);for(let u=0;u<R.length;u++){let g=R[u],T=g&&b&&(0,Z.isSolidTrianglePlan)(g)?Mt(g.polygon,g.index,Jr(g,{...n,solidPaintDefaults:k}),{primitive:m??void 0}):null;N[u]=T;let A=g&&y&&!(0,Z.isSolidTrianglePlan)(g)&&!(l&&(0,Z.isFullRectSolid)(g))&&!(p&&(0,Z.isProjectiveQuadPlan)(g))?(0,en.cornerShapeGeometryForPlan)(g):null;if(O[u]=A,ee[u]=g&&(g.texture||!(l&&(0,Z.isFullRectSolid)(g))&&!T&&!(p&&(0,Z.isProjectiveQuadPlan)(g))&&!A&&!P?g:null),C=await cr(C),t())return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}let{packed:z,atlasScale:F}=Vt(ee,n.textureQuality,o),$=new Map,U=[],ae=!1,Ee=[];for(let u=0;u<e.length;u++){let g=R[u],T=N[u],A=O[u];if(!g)continue;let L=z.entries[u];if(L){let M=er(L,r,o,s);$.set(u,M),U.push({polygonIndex:u,element:M,kind:"atlas",plan:L,dispose:()=>{}})}else if(!g.texture&&l&&(0,Z.isFullRectSolid)(g)){let M=Qo(g,r,o,k,s);U.push({polygonIndex:u,element:M,kind:"solid",plan:g,dispose:()=>{}})}else if(!g.texture&&T){let M=jn(T,o);U.push({polygonIndex:u,element:M,kind:"triangle",plan:g,dispose:()=>{}})}else if(!g.texture&&p&&(0,Z.isProjectiveQuadPlan)(g)){let M=Jo(g,r,o,k,s);U.push({polygonIndex:u,element:M,kind:"solid",plan:g,dispose:()=>{}})}else if(!g.texture&&A){let M=Ko(g,A,r,o,k,s);U.push({polygonIndex:u,element:M,kind:"corner",plan:g,dispose:()=>{}})}else if(!g.texture&&P){let M=qo(g,r,o,k,s);U.push({polygonIndex:u,element:M,kind:"border",plan:g,dispose:()=>{}})}if(C=await cr(C),t()){for(let M of U)M.dispose();return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}}return U.sort((u,g)=>u.polygonIndex-g.polygonIndex),zt(z.pages,r,o,F,()=>ae||t()).then(u=>{if(ae||t()){for(let g of u)g.url?.startsWith("blob:")&&URL.revokeObjectURL(g.url);return}Ee=u.flatMap(g=>g.url?.startsWith("blob:")?[g.url]:[]);for(let g=0;g<z.pages.length;g++){let T=z.pages[g],A=u[g];if(A)for(let L of T.entries){let M=$.get(L.index);!M||!A.url||Xo(M,A,r,L,!s)}}}).catch(()=>{if(!(ae||t()))for(let u of $.values())Ne(u,"opacity","0.5"),Ne(u,"outline","1px dashed rgba(255, 0, 0, 0.6)")}),{rendered:U,solidPaintDefaults:k,dispose(){ae=!0;for(let u of Ee)URL.revokeObjectURL(u);Ee=[]}}}function nn(e,n,t,o={}){let r=o.textureLighting??"baked",i=o,s=i.optimizeStableTriangleStyle===!0&&r==="baked";if(!s||i.stableTriangleColorPolicy==="adaptive"||e.length!==t.polygonCount||n.length!==t.polygonCount||t.vertices.length<t.polygonCount*9)return!1;let c=i.stableTriangleDebug,l=i.stableTriangleUpdateMode??(c==="plan-only"||c==="transform-only"?c:"full");if(l==="color-only")return!1;let p=(0,ur.stableTriangleMatrixDecimals)(i.stableTriangleMatrixDecimals),m=Gn(i),b=o.tileSize??yt.DEFAULT_TILE,y=o.layerElevation??b,P=o.doc??(typeof document<"u"?document:null),h=P?it(P,o.strategies)??"border":"border";for(let f=0;f<e.length;f++){let C=e[f],R=n[f];if(C.kind!=="triangle"||C.polygonIndex!==f||!R||R.vertices.length!==3||R.texture||R.material?.texture)return!1}let v=t.vertices;for(let f=0;f<e.length;f++){let C=e[f].element,R=n[f],k=f*9,N=v[k+1]*b,O=v[k]*b,ee=v[k+2]*y,z=v[k+4]*b,F=v[k+3]*b,$=v[k+5]*y,U=v[k+7]*b,ae=v[k+6]*b,Ee=v[k+8]*y,u=tr(R,f,o,{basis:C.__polycssSolidTriangleBasis,matrixDecimals:p,primitive:h,color:t.colors?.[f],includeColor:l!=="plan-only"&&l!=="transform-only"&&Lt(C,f,s,c,i.stableTriangleColorPolicy,m)},N,O,ee,z,F,$,U,ae,Ee);if(!u){Jt(C);continue}l!=="plan-only"&&(l==="transform-only"?Ln(C,u):Mn(C,u,m))}return!0}function on(e,n,t={}){if(e.length!==n.length)return!1;let o=t.doc??(typeof document<"u"?document:null),r=t.textureLighting??"baked",i=new Set(t.strategies?.disable??[]),s=!i.has("b"),c=!!o&&s&&vn(o),l=!!o&&!i.has("i")&&Pn(o),p=!!o&&!i.has("i")&&Xt(o),m=o?Wt(o):{denomEps:yt.PROJECTIVE_QUAD_DENOM_EPS,maxWeightRatio:yt.PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,bleed:yt.PROJECTIVE_QUAD_BLEED,disableGuards:!1},b=t.optimizeStableTriangleStyle===!0&&r==="baked",y=t,P=y.stableTriangleDebug,h=y.stableTriangleUpdateMode??(P==="plan-only"||P==="transform-only"?P:"full"),v=b&&h==="color-only",f=Gn(y),C=(0,ur.stableTriangleMatrixDecimals)(y.stableTriangleMatrixDecimals),R=o?it(o,t.strategies)??"border":"border";if(lr(e,n,t,b,h,f))return!0;let k=[],N=[],O=[];for(let z=0;z<e.length;z++){let F=e[z];if(F.polygonIndex!==z)return!1;let $=n[z];if(!$||v&&F.kind!=="triangle")return!1;if(F.kind==="atlas"){if(!F.plan||!Ur(F.element,F.plan,$,r))return!1;continue}if(F.kind==="triangle"){let U=F.element;if(v){let Ee=y.stableTriangleColorPolicy==="adaptive"||Lt(U,z,b,P,y.stableTriangleColorPolicy,f);N[z]=Ee?(0,Qr.computeSolidTriangleColorPlan)($,z,t):null;continue}let ae=Mt($,z,t,{basis:U.__polycssSolidTriangleBasis,matrixDecimals:C,primitive:R,includeColor:h!=="plan-only"&&h!=="transform-only"&&Lt(U,z,b,P,y.stableTriangleColorPolicy,f)});if(!ae){k[z]=null;continue}k[z]=ae;continue}if(F.kind==="solid"){if(!F.plan||$.texture||$.vertices.length!==F.plan.polygon.vertices.length)return!1;O[z]=F.plan;continue}if(F.kind==="border"){let U=(0,st.computeTextureAtlasPlan)($,z,t,m);if(!U||U.texture||!p||s&&(0,Z.isFullRectSolid)(U)||c&&(0,Z.isProjectiveQuadPlan)(U)||l&&(0,en.cornerShapeGeometryForPlan)(U))return!1;O[z]=U;continue}if(F.kind==="corner"){let U=(0,st.computeTextureAtlasPlan)($,z,t,m);if(!U||U.texture||!l||(0,Z.isSolidTrianglePlan)(U)||s&&(0,Z.isFullRectSolid)(U)||c&&(0,Z.isProjectiveQuadPlan)(U)||!(0,en.cornerShapeGeometryForPlan)(U))return!1;O[z]=U;continue}return!1}let ee=b&&h!=="plan-only"&&h!=="transform-only"?ar(e,v?N:k,y):null;for(let z=0;z<e.length;z++){let F=e[z];if(F.kind==="triangle"){if(v){let U=N[z];U&&Yn(F.element,U,f,ee?.has(z));continue}let $=k[z];if(!$){Jt(F.element);continue}if(b&&h==="plan-only")continue;b&&h==="transform-only"?Ln(F.element,$):b?Mn(F.element,$,f,ee?.has(z)):An(F.element,$)}else if(F.kind==="solid"){let $=O[z];if(!$||!Yr(F.element,$,n[z],r,t,m,y.solidPaintDefaults))return!1}else if(F.kind==="border"){let $=O[z];if(!$)return!1;jr(F.element,$,r,y.solidPaintDefaults)}else if(F.kind==="corner"){let $=O[z],U=$?(0,en.cornerShapeGeometryForPlan)($):null;if(!$||!U)return!1;Wr(F.element,$,U,r,y.solidPaintDefaults)}}return!0}var Xn=require("@layoutit/polycss-core"),at=require("@layoutit/polycss-core"),Rt=require("@layoutit/polycss-core");var ce=require("@layoutit/polycss-core"),Ms=[.4,-.7,.59],Ls="#ffffff",ws=1,_s="#ffffff",Os=.4,ai=1,Rs=8,Ds=ce.PROJECTIVE_QUAD_BLEED,Ct=1e-6,ks=(0,ce.resolveProjectiveQuadGuards)({bleed:0}),li={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},mr=["t","b","bl","br","fr","fl"],Fs=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 ni(e){let n=[];for(let t of mr)(0,ce.normalFacesCamera)(li[t],e)&&n.push(t);return n.join("|")}function Hs(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 Is(e){let n=e.vertices;if(n.length<3)return null;let t=n[0],o=0,r=0,i=0;for(let c=1;c+1<n.length;c+=1){let l=n[c],p=n[c+1],m=l[1]-t[1],b=l[0]-t[0],y=l[2]-t[2],P=p[1]-t[1],h=p[0]-t[0],v=p[2]-t[2];o-=b*v-y*h,r-=y*P-m*v,i-=m*h-b*P}let s=Math.hypot(o,r,i);return s<=1e-9?null:[Math.round(o/s),Math.round(r/s),Math.round(i/s)]}function Vs(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=Is(e),t=n?Fs.get(n.join(",")):void 0;if(!t)return null;let o=1/0,r=1/0,i=1/0,s=-1/0,c=-1/0,l=-1/0;for(let b of e.vertices)o=Math.min(o,b[0]),r=Math.min(r,b[1]),i=Math.min(i,b[2]),s=Math.max(s,b[0]),c=Math.max(c,b[1]),l=Math.max(l,b[2]);let p=1e-6,m=Gs(e.color);return Math.abs(l-i)<=p?{axis:"z",face:t,left:r*ce.BASE_TILE,top:o*ce.BASE_TILE,width:Math.max(0,(c-r)*ce.BASE_TILE),height:Math.max(0,(s-o)*ce.BASE_TILE),z:i*ce.BASE_TILE,baseColor:m,bleed:dr()}:Math.abs(s-o)<=p?{axis:"x",face:t,left:r*ce.BASE_TILE,top:i*ce.BASE_TILE,width:Math.max(0,(c-r)*ce.BASE_TILE),height:Math.max(0,(l-i)*ce.BASE_TILE),z:-o*ce.BASE_TILE,baseColor:m,bleed:dr()}:Math.abs(c-r)<=p?{axis:"y",face:t,left:i*ce.BASE_TILE,top:o*ce.BASE_TILE,width:Math.max(0,(l-i)*ce.BASE_TILE),height:Math.max(0,(s-o)*ce.BASE_TILE),z:-r*ce.BASE_TILE,baseColor:m,bleed:dr()}:null}function dr(){return{left:0,right:0,top:0,bottom:0}}function zs(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 oi(e){return[e[1]*ce.BASE_TILE,e[0]*ce.BASE_TILE,e[2]*ce.BASE_TILE]}function ri(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function Bs(e,n,t){let o=e.left,r=e.left+e.width,i=e.top,s=e.top+e.height;if(Math.abs(n[0]-t[0])<=Ct){if(Math.abs(n[0]-o)<=Ct)return"left";if(Math.abs(n[0]-r)<=Ct)return"right"}if(Math.abs(n[1]-t[1])<=Ct){if(Math.abs(n[1]-i)<=Ct)return"top";if(Math.abs(n[1]-s)<=Ct)return"bottom"}return null}function Ns(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=Ct)){if(t!==null)return null;t=o}return t}function Us(e,n,t){let o=n.vertices,r=oi(o[t]),i=oi(o[(t+1)%o.length]),s=Bs(e,ri(e,r),ri(e,i));if(!s)return null;let c=Ns(r,i);if(c===null)return null;let l=Math.min(r[c],i[c]),p=Math.max(r[c],i[c]);return p-l>Ct?{item:e,side:s,variableAxis:c,fixed:r,start:l,end:p}:null}function ii(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],Ds)}function $s(e,n){let t=new Map;for(let o of n){let r=e[o.sourceIndex];if(r)for(let i=0;i<r.vertices.length;i+=1){let s=Us(o,r,i);if(!s)continue;let c=zs(s),l=t.get(c);l?l.push(s):t.set(c,[s])}}for(let o of t.values()){if(o.length<2)continue;o.sort((i,s)=>i.start-s.start||i.end-s.end);let r=[];for(let i of o){r=r.filter(s=>s.end>i.start+Ct);for(let s of r)s.item.sourceIndex!==i.item.sourceIndex&&(ii(s),ii(i));r.push(i)}}}function pr(e){let n=(0,ce.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha}:{r:255,g:255,b:255,alpha:1}}function Gs(e){if(!e)return"#cccccc";let n=(0,ce.parsePureColor)(e);if(!n)return e;let t={r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha};if(t.alpha<1){let o=Math.round(Math.max(0,t.alpha)*1e3)/1e3;return`rgba(${rn(t.r)}, ${rn(t.g)}, ${rn(t.b)}, ${o})`}return ci(t)}function ci({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 rn(e){return Math.round(Math.max(0,Math.min(255,e)))}function Ys(e,n,t,o){let r=pr(n),i=pr(t?.color??Ls),s=pr(o?.color??_s),c=t?.direction??Ms,l=Math.hypot(c[0],c[1],c[2])||1,p=c[0]/l,m=c[1]/l,b=c[2]/l,y=Math.max(0,t?.intensity??ws)*Math.max(0,e[0]*p+e[1]*m+e[2]*b),P=Math.max(0,o?.intensity??Os),h=s.r/255*P+i.r/255*y,v=s.g/255*P+i.g/255*y,f=s.b/255*P+i.b/255*y,C={r:r.r*h,g:r.g*v,b:r.b*f,alpha:r.alpha};return C.alpha<1?`rgba(${rn(C.r)}, ${rn(C.g)}, ${rn(C.b)}, ${C.alpha})`:ci(C)}function js(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=Vs(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return $s(e,n),n}function Ws(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 Xs(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 Zs(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function Qs(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(r=>!Number.isFinite(r)))return null;let o=ce.SOLID_QUAD_CANONICAL_SIZE/n;for(let r=0;r<8;r+=1)t[r]*=o;return`matrix3d(${t.map(r=>Number(r.toFixed(6))).join(",")})`}function si(e,n){let t=e.left-e.bleed.left,o=e.top-e.bleed.top,r=e.width+e.bleed.left+e.bleed.right,i=e.height+e.bleed.top+e.bleed.bottom,s=e.z,c=r/n,l=i/n;return`matrix3d(${(e.axis==="x"?[c,0,0,0,0,0,l,0,0,-1,0,0,t,-s,o,1]:e.axis==="y"?[0,0,c,0,0,l,0,0,-1,0,0,0,-s,o,t,1]:[c,0,0,0,0,l,0,0,0,0,1,0,t,o,s,1]).map(m=>Number(m.toFixed(6))).join(",")})`}function qs(e,n){let{xAxis:t,yAxis:o,normal:r,tx:i,ty:s,tz:c}=Ws(e),l=(0,ce.computeProjectiveQuadMatrix)(Xs(e),t,o,r,i,s,c,ks,Zs(e));return l?Qs(l,n)??si(e,n):si(e,n)}function Ks(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function Js(e){return Ks(e)?Rs:ai}function ea(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 ta(e,n){let t=ea(e),o=n.meshRotation;o&&(t=(0,ce.rotateVec3)(t,o[0]??0,o[1]??0,o[2]??0));let[r,i]=(0,ce.rotateVec3)(t,n.rotX,0,n.rotY);return{x:r,y:i}}function na(e,n,t){let o=e.filter(y=>n.has(y.face)).map(y=>({item:y,...ta(y,t)}));if(o.length===0)return[];let r=1/0,i=-1/0,s=1/0,c=-1/0;for(let y of o)r=Math.min(r,y.x),i=Math.max(i,y.x),s=Math.min(s,y.y),c=Math.max(c,y.y);let l=4,p=Math.max(1e-6,i-r),m=Math.max(1e-6,c-s),b=new Map;for(let y of o){let P=Math.min(l-1,Math.max(0,Math.floor((y.x-r)/p*l))),h=Math.min(l-1,Math.max(0,Math.floor((y.y-s)/m*l))),v=`${P}:${h}`,f=b.get(v);f||(f={tx:P,ty:h,sourceIndex:y.item.sourceIndex,items:[]},b.set(v,f)),f.items.push(y.item),f.sourceIndex=Math.min(f.sourceIndex,y.item.sourceIndex)}return Array.from(b.values()).sort((y,P)=>y.ty-P.ty||y.tx-P.tx||y.sourceIndex-P.sourceIndex).flatMap(y=>y.items)}function ui(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:i}=e,s=js(o);if(s.length===0)return null;let c=new Set(s.map(u=>u.face));t.classList.add("polycss-voxel-mesh");let l=Js(n);l!==ai&&t.style.setProperty("--polycss-voxel-primitive",`${l}px`);let p=new Map,m=(u,g)=>{let T=`${u}|${g}`,A=p.get(T);if(A)return A;let L=Ys(li[u],g,r,i);return p.set(T,L),L},b=new Map,y=new Map,P=new Map,h=new Map;for(let u of s){let g=h.get(u.face);g||(g=[],h.set(u.face,g)),g.push(u)}let v="",f=0,C=new Set,R=u=>{let g=b.get(u.sourceIndex);return g||(g=n.createElement("b"),b.set(u.sourceIndex,g),Hs(g,m(u.face,u.baseColor),qs(u,l))),g},k=u=>{let g=y.get(u);return g||(g=n.createElement("span"),g.className=`polycss-voxel-face polycss-voxel-face-${u}`,g.dataset.polycssVoxelFace=u,g.__polycssVoxelFaceHost=!0,y.set(u,g)),g},N=()=>{for(let u of Array.from(t.childNodes))if(!u.__polycssVoxelFaceHost)return u;return null},O=(u,g)=>{let T=g.map(M=>M.sourceIndex).join(",");if(P.get(u)===T)return;let A=k(u),L=n.createDocumentFragment();for(let M of g)L.appendChild(R(M));A.replaceChildren(L),P.set(u,T)},ee=()=>{for(let u of mr)c.has(u)&&O(u,h.get(u)??[])},z=u=>new Set(u.split("|").filter(Boolean)),F=u=>{let g=z(u);return mr.filter(T=>g.has(T)&&c.has(T))},$=u=>{let g=0;for(let T of u)g+=h.get(T)?.length??0;return g},U=u=>{let g=new Set,T=[],A=new Map;for(let L of u){g.has(L.face)||(g.add(L.face),T.push(L.face));let M=A.get(L.face);M||(M=[],A.set(L.face,M)),M.push(L)}return{orderedFaces:T,itemsByFace:A}},ae=(u,g)=>{let T=new Set(u);for(let A of C){if(T.has(A))continue;let L=y.get(A);L?.parentNode===t&&t.removeChild(L)}if(g){let A=n.createDocumentFragment();for(let L of u)A.appendChild(k(L));t.insertBefore(A,N()),C=T;return}for(let A=0;A<u.length;A+=1){let L=u[A],M=k(L);if(M.parentNode===t)continue;let le=null;for(let xe=A+1;xe<u.length;xe+=1){let _=y.get(u[xe]);if(_?.parentNode===t){le=_;break}}t.insertBefore(M,le??N())}C=T},Ee=(u,g,T)=>{if(!T){let xe=F(u);ae(xe,!1),f=$(xe);return}let A=new Set(u.split("|").filter(Boolean)),L=na(s,A,g),{orderedFaces:M,itemsByFace:le}=U(L);for(let xe of M)O(xe,le.get(xe)??[]);ae(M,!0),f=L.length};return ee(),{get brushCount(){return f},render(u){v=ni(u),Ee(v,u,!0)},syncCamera(u){let g=ni(u);g!==v&&(v=g,Ee(g,u,!1))},dispose(){for(let u of y.values())u.remove();t.classList.remove("polycss-voxel-mesh"),t.style.removeProperty("--polycss-voxel-primitive"),b.clear(),y.clear(),P.clear(),f=0,C=new Set,v=""}}}var di="polycss-styles";function Zn(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(di))return;let t=n.createElement("style");t.id=di,t.textContent=oa,n.head.appendChild(t)}var oa=`
|
|
1
|
+
"use strict";var Uo=Object.defineProperty;var zi=Object.getOwnPropertyDescriptor;var Ni=Object.getOwnPropertyNames;var $i=Object.prototype.hasOwnProperty;var Ui=(e,n)=>{for(var t in n)Uo(e,t,{get:n[t],enumerable:!0})},$o=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Ni(n))!$i.call(e,r)&&r!==t&&Uo(e,r,{get:()=>n[r],enumerable:!(o=zi(n,r))||o.enumerable});return e},pe=(e,n,t)=>($o(e,n,"default"),t&&$o(t,n,"default"));var Gi=e=>$o(Uo({},"__esModule",{value:!0}),e);var le={};Ui(le,{PolyBoxElement:()=>Co,PolyCameraElement:()=>xo,PolyConeElement:()=>ko,PolyCylinderElement:()=>Ro,PolyDodecahedronElement:()=>Lo,PolyFirstPersonControlsElement:()=>bo,PolyIcosahedronElement:()=>Mo,PolyIframeElement:()=>uo,PolyMapControlsElement:()=>yo,PolyMeshElement:()=>ln,PolyOctahedronElement:()=>Ao,PolyOrbitControlsElement:()=>go,PolyOrthographicCameraElement:()=>un,PolyPerspectiveCameraElement:()=>vo,PolyPlaneElement:()=>Eo,PolyPolygonElement:()=>po,PolyRingElement:()=>To,PolySceneElement:()=>He,PolySceneSnapshotError:()=>At,PolySelectElement:()=>So,PolySphereElement:()=>_o,PolyTetrahedronElement:()=>wo,PolyTorusElement:()=>Oo,PolyTransformControlsElement:()=>Po,buildAtlasPages:()=>Rt,buildPolyMeshTransform:()=>pn.buildPolyMeshTransform,buildTextureEdgeRepairSets:()=>Pt.buildTextureEdgeRepairSets,collectPolyRenderStats:()=>fi,computeTextureAtlasPlanPublic:()=>Un.computeTextureAtlasPlanPublic,createPolyBox:()=>Si,createPolyCamera:()=>Ys,createPolyCone:()=>Ri,createPolyCylinder:()=>_i,createPolyDodecahedron:()=>Li,createPolyFirstPersonControls:()=>no,createPolyIcosahedron:()=>Mi,createPolyMapControls:()=>to,createPolyOctahedron:()=>Ti,createPolyOrbitControls:()=>eo,createPolyOrthographicCamera:()=>Tt,createPolyPerspectiveCamera:()=>tn,createPolyPlane:()=>Ci,createPolyRing:()=>Ei,createPolyScene:()=>qn,createPolySphere:()=>Ai,createPolyTetrahedron:()=>wi,createPolyTorus:()=>ki,createSelect:()=>oo,createTransformControls:()=>lo,cssBorderShapeForPlan:()=>St.cssBorderShapeForPlan,exportPolySceneSnapshot:()=>Pi,filterAtlasPlans:()=>In,formatBorderShapeEntryMatrix:()=>St.formatBorderShapeEntryMatrix,formatCssLengthPx:()=>Ze.formatCssLengthPx,formatMatrix3d:()=>Ze.formatMatrix3d,formatSolidQuadEntryMatrix:()=>Ze.formatSolidQuadEntryMatrix,getSolidPaintDefaults:()=>vt,getSolidPaintDefaultsFromPlans:()=>Dn,injectPolyBaseStyles:()=>Gn,isBorderShapeSupported:()=>vn,isFullRectSolid:()=>q.isFullRectSolid,isProjectiveQuadPlan:()=>q.isProjectiveQuadPlan,isSolidTrianglePlan:()=>q.isSolidTrianglePlan,isSolidTriangleSupported:()=>xn,packTextureAtlasPlansWithScale:()=>_t,renderPolygonsWithStableTriangles:()=>Ot,renderPolygonsWithTextureAtlas:()=>xt,renderPolygonsWithTextureAtlasAsync:()=>qt,updatePolygonsWithStableTopology:()=>Kt,updatePolygonsWithStableTriangles:()=>$n,updateStableTriangleFrame:()=>Qt,worldDirectionToPolyCss:()=>pn.worldDirectionToPolyCss,worldPositionToPolyCss:()=>pn.worldPositionToPolyCss});module.exports=Gi(le);var ne=require("@layoutit/polycss-core");var Hr=require("@layoutit/polycss-core");function ji(e){if(!e)return!1;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return t?t("(pointer: coarse)").matches||t("(hover: none)").matches:!1}function _t(e,n,t){return(0,Hr.packTextureAtlasPlansWithScaleCore)(e,n,ji(t))}var Pt=require("@layoutit/polycss-core");var lt=require("@layoutit/polycss-core"),$r=require("@layoutit/polycss-core"),Ur=require("@layoutit/polycss-core"),Bt=new Map;function Wi(e){let n=Bt.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}),Bt.set(e,n),n.then(()=>{Bt.get(e)===n&&Bt.delete(e)},()=>{Bt.get(e)===n&&Bt.delete(e)})),n}function Be(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 Go(e){let n=e/255;return n<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function jo(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 Yi(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]=jo(Go(h[g])*b),h[g+1]=jo(Go(h[g+1])*v),h[g+2]=jo(Go(h[g+2])*P));e.putImageData(x,c,l)}function Xi(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;Be(e,i),e.drawImage(n,t+(r-d)/2,o+(s-x)/2,d,x)}function zt(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=zt(Math.min(t.minU,t.maxU)*l,l),x=zt(Math.max(t.minU,t.maxU)*l,l),h=zt(Math.min(t.minV,t.maxV)*u,u),b=zt(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(zt((t.minU+t.maxU)/2*l,l-1)),g=1),C<1&&(P=Math.floor(zt((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)),Be(e,c),e.drawImage(n,v,P,g,C,o,r,s,i)}function Gr(e){return e==="repeat"||e==="mirrored-repeat"}function Vr(e,n){return Gr(e)?Math.floor(n):0}function Br(e,n){return Gr(e)?Math.ceil(n)-1:0}function zr(e,n){return e==="mirrored-repeat"&&Math.abs(n%2)===1}function Nr(e,n,t,o,r,s,i){let c=r?Vr(s,r.minU):0,l=r?Br(s,r.maxU):0,u=r?Vr(i,r.minV):0,d=r?Br(i,r.maxV):0;for(let x=c;x<=l;x++)for(let h=u;h<=d;h++){let b=zr(s,x),v=zr(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 Wo(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 Rn(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 Zi(e,n,t,o){Be(e,o),e.beginPath(),Wo(e,n.x,n.y,n.screenPts),e.clip(),Be(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function kn(e,n,t,o,r){n.polygon.textureAlphaMode==="opaque"&&(Be(e,t),e.fillStyle=n.polygon.color??"#cccccc",e.fillRect(n.x+o,n.y+r,n.canvasW,n.canvasH))}function qi(e,n,t,o,r=0,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=(0,$r.expandClipPoints)(l.screenPts,lt.TEXTURE_TRIANGLE_BLEED*(n.bleedRatio??1));e.save(),Be(e,o),e.beginPath(),Rn(e,n.x,n.y,u,r,s),e.clip(),kn(e,n,o,r,s),l.uvAffine?(Be(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),Nr(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(),Be(e,o),e.beginPath(),Rn(e,n.x,n.y,n.screenPts,r,s),e.clip(),kn(e,n,o,r,s)),Be(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),Nr(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(),Be(e,o),e.beginPath(),Rn(e,n.x,n.y,n.screenPts,r,s),e.clip(),kn(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(),Be(e,o),e.beginPath(),Rn(e,n.x,n.y,n.screenPts,r,s),e.clip(),kn(e,n,o,r,s)),Xi(e,t,n.x+r,n.y+s,n.canvasW,n.canvasH,o),i&&e.restore()}}function Qi(e,n,t,o,r,s){let i=r-t,c=s-o,l=i*i+c*c;if(l<=Ur.BASIS_EPS)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 Ki(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,Qi(e,n,t[c],t[c+1],t[l],t[l+1]))}return r}function Ji(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]<lt.TEXTURE_EDGE_REPAIR_SOURCE_ALPHA_MIN||(d=C,x=g)}return d}function ea(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(lt.TEXTURE_EDGE_REPAIR_RADIUS,lt.TEXTURE_EDGE_REPAIR_RADIUS/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<lt.TEXTURE_EDGE_REPAIR_ALPHA_MIN||C===255)continue;let D=(r+P+.5)/t-n.x,k=(s+v+.5)/t-n.y;if(Ki(D,k,n.screenPts,n.textureEdgeRepairEdges)>x)continue;let z=Ji(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 ta(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 na(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 Wi(d))}));for(let d of e.entries){let x=d.texture?l.get(d.texture):null;if(!d.texture){i.save(),Zi(i,d,n,o),i.restore();continue}x&&(i.save(),Be(i,o),i.beginPath(),Wo(i,d.x,d.y,d.screenPts),i.clip(),qi(i,d,x,o),i.restore()),d.texture&&n==="baked"&&(i.save(),Be(i,o),i.beginPath(),Wo(i,d.x,d.y,d.screenPts),i.clip(),Yi(i,d.x,d.y,d.canvasW,d.canvasH,d.textureTint,o),i.restore()),ea(i,d,o)}let u=await ta(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:u}}async function Rt(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await na(i,n,t,o))}return s}var q=require("@layoutit/polycss-core"),On=require("@layoutit/polycss-core"),Wr=require("@layoutit/polycss-core");var jr=require("@layoutit/polycss-core");function Nt(e,n){let o=e?.defaultView?.__polycssProjectiveQuadGuards,r=n&&o?{...n,...o}:o??n;return(0,jr.resolveProjectiveQuadGuards)(r)}function $t(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 Yo(e){if(Yr(e))return!0;let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,q.safariCssProjectiveUnsupported)(t):!0}function yn(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 Yr(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 oa(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return/\bFirefox\//.test(t)}function Ye(e,n){return n?.disable?.includes("u")?null:Yr(e)?"corner-bevel":Yo(e)?oa(e)?"border-large":"border":null}function Ut(e){let t=(e.defaultView??(typeof window<"u"?window:void 0))?.navigator?.userAgent??"";return t?!(0,q.safariCssProjectiveUnsupported)(t):!0}function bn(e,n,t,o,r){let s=new Set(o?.disable??[]);return(0,q.getSolidPaintDefaultsForPlansCore)(e,n,s,{solidTriangleSupported:Yo(t),projectiveQuadSupported:Ut(t),cornerShapeSupported:yn(t),borderShapeSupported:$t(t)},On.parseHex,On.rgbKey,r)}function Dn(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 bn(e,n,r,s)}function vn(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 $t(n)}function xn(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 Yo(n)}function In(e,n,t,o){let r=o??(typeof document<"u"?document:null);return(0,q.filterAtlasPlans)(e,n,t,{solidTriangleSupported:xn(o),projectiveQuadSupported:r?Ut(r):!0,borderShapeSupported:vn(o)})}var Me=require("@layoutit/polycss-core"),Xe=require("@layoutit/polycss-core");var Zt=require("@layoutit/polycss-core");var ut=require("@layoutit/polycss-core"),Xr=require("@layoutit/polycss-core");var Gt=require("@layoutit/polycss-core");function we(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 ht(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 Pn(e,n,t,o=!1){if(n==="dynamic"){let r=(0,Gt.parseHex)(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(0,Gt.rgbKey)(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 ra(e,n){we(e,"--pnx",n.normal[0].toFixed(4)),we(e,"--pny",n.normal[1].toFixed(4)),we(e,"--pnz",n.normal[2].toFixed(4))}function jt(e,n,t,o){if(t==="dynamic"){ht(e,"color"),ht(e,"background"),ra(e,n);let r=(0,Gt.parseHex)(n.polygon.color??"#cccccc");(0,Gt.rgbKey)(r)===o?.dynamicColorKey?(ht(e,"--psr"),ht(e,"--psg"),ht(e,"--psb")):(we(e,"--psr",(r.r/255).toFixed(4)),we(e,"--psg",(r.g/255).toFixed(4)),we(e,"--psb",(r.b/255).toFixed(4)))}else n.shadedColor!==o?.paintColor?(ht(e,"background"),we(e,"color",n.shadedColor)):(ht(e,"background"),ht(e,"color"))}var Wt=require("@layoutit/polycss-core"),ct=require("@layoutit/polycss-core"),Hn=require("@layoutit/polycss-core"),at=require("@layoutit/polycss-core"),Zr="polycss-corner-shape-solid",Xo=new WeakMap,Zo=new WeakMap;function Ee(e,n,t){let o=Xo.get(e),r=Zo.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?Xo.set(e,c):Xo.delete(e),i.size>0?Zo.set(e,i):Zo.delete(e),e.__polycssHasDataAttrs=c.length>0}function Yt(e){return e.__polycssHasDataAttrs===!0}function qo(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=(0,ct.atlasCanonicalSizeForEntry)(o),u=`${(0,ut.formatCssLength)(-o.x/i*l)} ${(0,ut.formatCssLength)(-o.y/c*l)}`,d=`${(0,ut.formatCssLength)(n.width/i*l)} ${(0,ut.formatCssLength)(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 qr(e,n,t,o){if(n.texture){if(!t.texture||n.texture!==t.texture)return!1}else if(t.texture)return!1;let r=Qr(n,t);return r?(e.style.visibility="",we(e,"transform",`matrix3d(${r.matrix})`),o==="dynamic"&&(we(e,"--pnx",r.normal[0].toFixed(4)),we(e,"--pny",r.normal[1].toFixed(4)),we(e,"--pnz",r.normal[2].toFixed(4))),Ee(e,t,n.index),!0):(e.style.visibility="hidden",Ee(e,t,n.index),!0)}function Qo(e,n,t,o,r){if(o!=="baked")return{...e,polygon:n,normal:t};let s=r.directionalLight,i=r.ambientLight,c=s?.direction??at.DEFAULT_LIGHT_DIR,l=s?.color??at.DEFAULT_LIGHT_COLOR,u=Math.max(0,s?.intensity??at.DEFAULT_LIGHT_INTENSITY),d=i?.color??at.DEFAULT_AMBIENT_COLOR,x=Math.max(0,i?.intensity??at.DEFAULT_AMBIENT_INTENSITY),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:(0,Xr.shadePolygon)(n.color??"#cccccc",C,l,d,x)}}function Qr(e,n){let t=Kr(e,n);if(!t)return null;let{normal:o,xAxis:r,yAxis:s,tx:i,ty:c,tz:l}=t;return{normal:o,matrix:(0,ut.formatMatrix3dValues)([r[0]*e.canvasW/(0,ct.atlasCanonicalSizeForEntry)(e),r[1]*e.canvasW/(0,ct.atlasCanonicalSizeForEntry)(e),r[2]*e.canvasW/(0,ct.atlasCanonicalSizeForEntry)(e),0,s[0]*e.canvasH/(0,ct.atlasCanonicalSizeForEntry)(e),s[1]*e.canvasH/(0,ct.atlasCanonicalSizeForEntry)(e),s[2]*e.canvasH/(0,ct.atlasCanonicalSizeForEntry)(e),0,o[0],o[1],o[2],0,i,c,l,1])}}var Kr=Hn.stableBasisFromPlan;function sa(e,n,t){if(e.screenPts.length!==8||n.vertices.length!==4)return null;let o=Kr(e,n);if(!o)return null;let r=(0,Hn.computeProjectiveQuadMatrix)(e.screenPts,o.xAxis,o.yAxis,o.normal,o.tx,o.ty,o.tz,t);return r?{matrix:r,normal:o.normal}:null}function Ko(e,n,t,o,r=!1){let s=t.createElement("b");return s.setAttribute("style",`transform:matrix3d(${(0,ut.formatSolidQuadMatrix)(e)})`+Pn(e,n,o,r)),Ee(s,e.polygon,e.index),s}function Jo(e,n,t,o,r=!1){let s=t.createElement("i");return s.setAttribute("style",(0,Wt.formatBorderShapeElementStyle)(e)+Pn(e,n,o,r)),Ee(s,e.polygon,e.index),s}function er(e,n,t,o,r,s=!1){let i=o.createElement("u");return i.className=Zr,i.setAttribute("style",(0,Wt.formatCornerShapeElementStyle)(e,n)+Pn(e,t,r,s)),Ee(i,e.polygon,e.index),i}function tr(e,n,t,o,r=!1){let s=t.createElement("b");return s.setAttribute("style",`transform:matrix3d(${e.projectiveMatrix})`+Pn(e,n,o,r)),Ee(s,e.polygon,e.index),s}function Jr(e,n,t,o,r,s,i){let c=n.projectiveMatrix?sa(n,t,s):Qr(n,t);if(!c)return!1;let l=Qo(n,t,c.normal,o,r);return e.style.visibility="",e.style.transform=`matrix3d(${c.matrix})`,jt(e,l,o,i),Ee(e,l.polygon,l.index),!0}function es(e,n,t,o){e.style.visibility="",e.setAttribute("style",(0,Wt.formatBorderShapeElementStyle)(n)),jt(e,n,t,o),Ee(e,n.polygon,n.index)}function ts(e,n,t,o,r){e.style.visibility="",e.className=Zr,e.setAttribute("style",(0,Wt.formatCornerShapeElementStyle)(n,t)),jt(e,n,o,r),we(e,"background","currentColor"),Ee(e,n.polygon,n.index)}function nr(e,n,t,o=!1){let r=t.createElement("s"),s=(0,ct.atlasCanonicalSizeForEntry)(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),Ee(r,e.polygon,e.index),r}var rs=require("@layoutit/polycss-core");var Fn=require("@layoutit/polycss-core");function gt(e,n,t,o={}){let r=o.primitive!=null?void 0:(()=>{let s=t.doc??(typeof document<"u"?document:null);return s?Ye(s,t.strategies)??"border":"border"})();return(0,Fn.computeSolidTrianglePlan)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??r})}function or(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?Ye(v,t.strategies)??"border":"border"})();return(0,Fn.computeSolidTrianglePlanFromCssPoints)(e,n,t,{...o,resolvedPrimitive:o.resolvedPrimitive??b},r,s,i,c,l,u,d,x,h)}var kt=require("@layoutit/polycss-core"),bt=require("@layoutit/polycss-core"),rr=require("@layoutit/polycss-core");var Vn=require("@layoutit/polycss-core");var ia="0 48px 96px 48px";function sr(e,n){return(0,kt.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function ir(e,n,t){let o=(0,kt.resolveBleedRatio)(t.seamBleed),r=kt.DEFAULT_SEAM_BLEED*o,s={...t,bleedRatio:o};return n&&r>0?{...s,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:s}function Bn(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 ns(e,n){return!n.updatesDisabled&&(n.freezeFrames<=1||(n.colorFrame+e)%n.freezeFrames===0)}function yt(e,n,t,o,r,s){return t?s.updatesDisabled||o==="plan-only"||o==="transform-only"?!1:r==="adaptive"||e.__polycssSolidTriangleColor===void 0?!0:ns(n,s):!0}function ar(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"?ia:""),t.__polycssSolidTrianglePrimitive=n)}function lr(e){let n=e;n.__polycssSolidTriangleHidden&&(e.style.visibility="",n.__polycssSolidTriangleHidden=!1)}function Xt(e){let n=e;n.__polycssSolidTriangleHidden||(e.style.visibility="hidden",n.__polycssSolidTriangleHidden=!0)}function Sn(e,n){e.setAttribute("style",n.styleText),ar(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||Yt(e))&&Ee(e,n.polygon)}function os(e,n,t,o){if(!n.colorComputed){(n.polygon.data||Yt(e))&&Ee(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??ns(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=(0,bt.stepRgbToward)(u,i,t.maxStep);b=v,h=(0,bt.rgbToCss)(v,c)}(h!==l||!(0,bt.rgbEqual)(b,u))&&(e.style.color=h),r.__polycssSolidTriangleColor=h,r.__polycssSolidTriangleColorRgb=b,r.__polycssSolidTriangleColorAlpha=c,r.__polycssSolidTriangleColorFrame=t.colorFrame}(n.polygon.data||Yt(e))&&Ee(e,n.polygon)}function Cn(e,n,t,o){let r=e;ar(e,n.primitive),r.__polycssSolidTriangleBasis!==n.basis&&(r.__polycssSolidTriangleBasis=n.basis),lr(e),e.style.transform=n.transformText,(n.colorComputed||n.polygon.data||Yt(e))&&os(e,n,t,o)}function zn(e,n,t,o){lr(e),os(e,n,t,o)}function En(e,n){let t=e;ar(e,n.primitive),t.__polycssSolidTriangleBasis!==n.basis&&(t.__polycssSolidTriangleBasis=n.basis),lr(e),e.style.transform=n.transformText,(n.polygon.data||Yt(e))&&Ee(e,n.polygon)}function aa(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 cr(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=aa(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=(0,bt.colorErrorScore)(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 Nn(e,n){let t=n.createElement("u");return Sn(t,e),Ee(t,e.polygon,e.index),t}function la(e,n,t){let o=t.createElement("u");return Xt(o),Ee(o,e,n),o}function ur(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=(0,Vn.stableTriangleMatrixDecimals)(i.stableTriangleMatrixDecimals),d=t.doc??(typeof document<"u"?document:null),x=d?Ye(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=sr(n,t);for(let b=0;b<e.length;b++){let v=e[b].element,P=n[b];if(l){if(yt(v,b,o,c,i.stableTriangleColorPolicy,s)){let C=(0,rr.computeSolidTriangleColorPlan)(P,b,t);if(!C)continue;zn(v,C,s)}continue}let g=gt(P,b,ir(b,h,t),{basis:v.__polycssSolidTriangleBasis,matrixDecimals:u,primitive:x,includeColor:r!=="plan-only"&&r!=="transform-only"&&yt(v,b,o,c,i.stableTriangleColorPolicy,s)});if(!g){Xt(v);continue}o&&r==="plan-only"||(o&&r==="transform-only"?En(v,g):o?Cn(v,g,s):Sn(v,g))}return!0}function Ot(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=Ye(t,n.strategies);if(!o||e.some(c=>c.texture||c.vertices.length!==3))return null;let r=(0,Vn.stableTriangleMatrixDecimals)(n.stableTriangleMatrixDecimals),s=[],i=sr(e,n);for(let c=0;c<e.length;c+=1){let l=e[c],u=gt(l,c,ir(c,i,n),{matrixDecimals:r,primitive:o}),d=u?Nn(u,t):la(l,c,t);s.push({polygonIndex:c,element:d,kind:"triangle",dispose:()=>{}})}return{rendered:s,dispose(){}}}function $n(e,n,t={}){let o=t.doc??(typeof document<"u"?document:null);if(!o)return{rendered:e,dispose:()=>{}};let r=Ye(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=Bn(i),x=(0,Vn.stableTriangleMatrixDecimals)(i.stableTriangleMatrixDecimals);if(ur(e,n,t,s,l,d))return{rendered:e,dispose(){}};let h=new Array(e.length),b=new Array(e.length),v=sr(n,t);for(let g=0;g<e.length;g++){let C=e[g].element;if(u){let D=i.stableTriangleColorPolicy==="adaptive"||yt(C,g,s,c,i.stableTriangleColorPolicy,d);b[g]=D?(0,rr.computeSolidTriangleColorPlan)(n[g],g,t):null;continue}h[g]=gt(n[g],g,ir(g,v,t),{basis:C.__polycssSolidTriangleBasis,matrixDecimals:x,primitive:r,includeColor:l!=="plan-only"&&l!=="transform-only"&&yt(C,g,s,c,i.stableTriangleColorPolicy,d)})}let P=s&&l!=="plan-only"&&l!=="transform-only"?cr(e,u?b:h,i):null;for(let g=0;g<e.length;g++){if(u){let D=b[g];D&&zn(e[g].element,D,d,P?.has(g));continue}let C=h[g];if(!C){Xt(e[g].element);continue}s&&l==="plan-only"||(s&&l==="transform-only"?En(e[g].element,C):s?Cn(e[g].element,C,d,P?.has(g)):Sn(e[g].element,C))}return{rendered:e,dispose(){}}}var pr=require("@layoutit/polycss-core");function ss(){return new Promise(e=>setTimeout(e,0))}async function dr(e){return performance.now()-e<Me.ASYNC_RENDER_BUDGET_MS?e:(await ss(),performance.now())}function is(e,n){let t=(0,Me.resolveBleedRatio)(n.seamBleed),o=Me.DEFAULT_SEAM_BLEED*t,r={...n,bleedRatio:t};return e.seamBleedEdges?.size&&o>0?{...r,seamBleed:o,seamEdges:e.seamBleedEdges}:{...r,seamBleed:void 0,seamEdges:void 0}}function as(e,n){return(0,Xe.buildSeamBleedPolygonEdges)(e,{tileSize:n.tileSize,layerElevation:n.layerElevation,directionalLight:n.directionalLight,ambientLight:n.ambientLight})}function ls(e,n,t){let o=(0,Me.resolveBleedRatio)(t.seamBleed),r=Me.DEFAULT_SEAM_BLEED*o,s={...t,bleedRatio:o};return n&&r>0?{...s,seamBleed:n.has(e)?r:void 0,seamEdges:n.get(e)}:s}function vt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{};let o=(0,Xe.buildBasisHints)(e,n),r=Nt(t),s=e.map((i,c)=>(0,Xe.computeTextureAtlasPlan)(i,c,n,r,o[c]));return bn(s,n.textureLighting??"baked",t,n.strategies)}function xt(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&&Ut(t),u=Ye(t,n.strategies),d=u!==null,x=!i.has("i")&&yn(t),h=!i.has("i")&&$t(t),b=(0,Xe.buildBasisHints)(e,n),v=Nt(t),P=as(e,n),g=e.map((m,p)=>(0,Xe.computeTextureAtlasPlan)(m,p,ls(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?bn(g,o,t,n.strategies):void 0),D=C?{...n,solidPaintDefaults:C}:n,k=g.map(m=>m&&d&&(0,q.isSolidTrianglePlan)(m)?gt(m.polygon,m.index,is(m,D),{primitive:u??void 0}):null),z=g.map(m=>m&&x&&!(0,q.isSolidTrianglePlan)(m)&&!(c&&(0,q.isFullRectSolid)(m))&&!(l&&(0,q.isProjectiveQuadPlan)(m))?(0,Zt.cornerShapeGeometryForPlan)(m):null),I=g.map((m,p)=>m&&(m.texture||!(c&&(0,q.isFullRectSolid)(m))&&!k[p]&&!(l&&(0,q.isProjectiveQuadPlan)(m))&&!z[p]&&!h?m:null)),{packed:Z,atlasScale:K}=_t(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=nr(R,o,t,s);O.set(m,L),H.push({polygonIndex:m,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!p.texture&&c&&(0,q.isFullRectSolid)(p)){let L=Ko(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&T){let L=Nn(T,t);H.push({polygonIndex:m,element:L,kind:"triangle",plan:p,dispose:()=>{}})}else if(!p.texture&&l&&(0,q.isProjectiveQuadPlan)(p)){let L=tr(p,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&M){let L=er(p,M,o,t,C,s);H.push({polygonIndex:m,element:L,kind:"corner",plan:p,dispose:()=>{}})}else if(!p.texture&&h){let L=Jo(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=Rt(Z.pages,o,t,K,()=>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||qo(L,M,o,R,!0)}}}).catch(()=>{if(!V)for(let m of O.values())we(m,"opacity","0.5"),we(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&&Ut(o),d=Ye(o,n.strategies),x=d!==null,h=!c.has("i")&&yn(o),b=!c.has("i")&&$t(o);if(await ss(),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let v=(0,Xe.buildBasisHints)(e,n),P=Nt(o),g=as(e,n),C=performance.now(),D=new Array(e.length);for(let m=0;m<e.length;m++)if(D[m]=(0,Xe.computeTextureAtlasPlan)(e[m],m,ls(m,g,n),P,v[m]),C=await dr(C),t())return{rendered:[],solidPaintDefaults:{},dispose:()=>{}};let k=n.solidPaintDefaults??bn(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&&(0,q.isSolidTrianglePlan)(p)?gt(p.polygon,p.index,is(p,{...n,solidPaintDefaults:k}),{primitive:d??void 0}):null;z[m]=T;let M=p&&h&&!(0,q.isSolidTrianglePlan)(p)&&!(l&&(0,q.isFullRectSolid)(p))&&!(u&&(0,q.isProjectiveQuadPlan)(p))?(0,Zt.cornerShapeGeometryForPlan)(p):null;if(I[m]=M,Z[m]=p&&(p.texture||!(l&&(0,q.isFullRectSolid)(p))&&!T&&!(u&&(0,q.isProjectiveQuadPlan)(p))&&!M&&!b?p:null),C=await dr(C),t())return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}let{packed:K,atlasScale:O}=_t(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=K.entries[m];if(R){let L=nr(R,r,o,i);H.set(m,L),V.push({polygonIndex:m,element:L,kind:"atlas",plan:R,dispose:()=>{}})}else if(!p.texture&&l&&(0,q.isFullRectSolid)(p)){let L=Ko(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&T){let L=Nn(T,o);V.push({polygonIndex:m,element:L,kind:"triangle",plan:p,dispose:()=>{}})}else if(!p.texture&&u&&(0,q.isProjectiveQuadPlan)(p)){let L=tr(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"solid",plan:p,dispose:()=>{}})}else if(!p.texture&&M){let L=er(p,M,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"corner",plan:p,dispose:()=>{}})}else if(!p.texture&&b){let L=Jo(p,r,o,k,i);V.push({polygonIndex:m,element:L,kind:"border",plan:p,dispose:()=>{}})}if(C=await dr(C),t()){for(let L of V)L.dispose();return{rendered:[],solidPaintDefaults:k,dispose:()=>{}}}}V.sort((m,p)=>m.polygonIndex-p.polygonIndex);let y=Rt(K.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<K.pages.length;p++){let T=K.pages[p],M=m[p];if(M)for(let R of T.entries){let L=H.get(R.index);!L||!M.url||qo(L,M,r,R,!0)}}}).catch(()=>{if(!($||t()))for(let m of H.values())we(m,"opacity","0.5"),we(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 Qt(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=(0,pr.stableTriangleMatrixDecimals)(s.stableTriangleMatrixDecimals),d=Bn(s),x=o.tileSize??Me.DEFAULT_TILE,h=o.layerElevation??x,b=o.doc??(typeof document<"u"?document:null),v=b?Ye(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,K=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=or(D,g,o,{basis:C.__polycssSolidTriangleBasis,matrixDecimals:u,primitive:v,color:t.colors?.[g],includeColor:l!=="plan-only"&&l!=="transform-only"&&yt(C,g,i,c,s.stableTriangleColorPolicy,d)},z,I,Z,K,O,H,V,$,A);if(!y){Xt(C);continue}l!=="plan-only"&&(l==="transform-only"?En(C,y):Cn(C,y,d))}return!0}function Kt(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&&Ut(r),u=!!r&&!i.has("i")&&yn(r),d=!!r&&!i.has("i")&&$t(r),x=(0,Me.resolveBleedRatio)(o.seamBleed),h=r?Nt(r,{bleed:Me.PROJECTIVE_QUAD_BLEED*x}):{denomEps:Me.PROJECTIVE_QUAD_DENOM_EPS,maxWeightRatio:Me.PROJECTIVE_QUAD_MAX_WEIGHT_RATIO,bleed:Me.PROJECTIVE_QUAD_BLEED*x,disableGuards:!1},b=o.optimizeStableTriangleStyle===!0&&s==="baked",v=o.stableTriangleDebug,P=o.stableTriangleUpdateMode??(v==="plan-only"||v==="transform-only"?v:"full"),g=b&&P==="color-only",C=Bn(o),D=(0,pr.stableTriangleMatrixDecimals)(o.stableTriangleMatrixDecimals),k=r?Ye(r,t.strategies)??"border":"border";if(ur(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||!qr(H.element,H.plan,V,s))return!1;continue}if(H.kind==="triangle"){let $=H.element;if(g){let y=o.stableTriangleColorPolicy==="adaptive"||yt($,O,b,v,o.stableTriangleColorPolicy,C);I[O]=y?(0,rs.computeSolidTriangleColorPlan)(V,O,t):null;continue}let A=gt(V,O,t,{basis:$.__polycssSolidTriangleBasis,matrixDecimals:D,primitive:k,includeColor:P!=="plan-only"&&P!=="transform-only"&&yt($,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 $=(0,Xe.computeTextureAtlasPlan)(V,O,t,h);if(!$||$.texture||!d||c&&(0,q.isFullRectSolid)($)||l&&(0,q.isProjectiveQuadPlan)($)||u&&(0,Zt.cornerShapeGeometryForPlan)($))return!1;Z[O]=$;continue}if(H.kind==="corner"){let $=(0,Xe.computeTextureAtlasPlan)(V,O,t,h);if(!$||$.texture||!u||(0,q.isSolidTrianglePlan)($)||c&&(0,q.isFullRectSolid)($)||l&&(0,q.isProjectiveQuadPlan)($)||!(0,Zt.cornerShapeGeometryForPlan)($))return!1;Z[O]=$;continue}return!1}let K=b&&P!=="plan-only"&&P!=="transform-only"?cr(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];$&&zn(H.element,$,C,K?.has(O));continue}let V=z[O];if(!V){Xt(H.element);continue}if(b&&P==="plan-only")continue;b&&P==="transform-only"?En(H.element,V):b?Cn(H.element,V,C,K?.has(O)):Sn(H.element,V)}else if(H.kind==="solid"){let V=Z[O];if(!V||!Jr(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;es(H.element,V,s,o.solidPaintDefaults)}else if(H.kind==="corner"){let V=Z[O],$=V?(0,Zt.cornerShapeGeometryForPlan)(V):null;if(!V||!$)return!1;ts(H.element,V,$,s,o.solidPaintDefaults)}}return!0}var Un=require("@layoutit/polycss-core"),Ze=require("@layoutit/polycss-core"),St=require("@layoutit/polycss-core");var ee=require("@layoutit/polycss-core"),ca=[.4,-.7,.59],ua="#ffffff",da=1,pa="#ffffff",ma=.4,fs=1,fa=8,ha=ee.PROJECTIVE_QUAD_BLEED,dt=1e-6,ga=(0,ee.resolveProjectiveQuadGuards)({bleed:0}),hs={t:[0,0,1],b:[0,0,-1],fl:[0,1,0],br:[0,-1,0],fr:[1,0,0],bl:[-1,0,0]},hr=["t","b","bl","br","fr","fl"],ya=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 cs(e){let n=[];for(let t of hr)(0,ee.normalFacesCamera)(hs[t],e)&&n.push(t);return n.join("|")}function ba(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 xa(e){if(e.texture||e.material||e.uvs||e.textureTriangles||e.vertices.length!==4)return null;let n=va(e),t=n?ya.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*ee.BASE_TILE,top:o*ee.BASE_TILE,width:Math.max(0,(c-r)*ee.BASE_TILE),height:Math.max(0,(i-o)*ee.BASE_TILE),z:s*ee.BASE_TILE,baseColor:d,bleed:mr()}:Math.abs(i-o)<=u?{axis:"x",face:t,left:r*ee.BASE_TILE,top:s*ee.BASE_TILE,width:Math.max(0,(c-r)*ee.BASE_TILE),height:Math.max(0,(l-s)*ee.BASE_TILE),z:-o*ee.BASE_TILE,baseColor:d,bleed:mr()}:Math.abs(c-r)<=u?{axis:"y",face:t,left:s*ee.BASE_TILE,top:o*ee.BASE_TILE,width:Math.max(0,(l-s)*ee.BASE_TILE),height:Math.max(0,(i-o)*ee.BASE_TILE),z:-r*ee.BASE_TILE,baseColor:d,bleed:mr()}:null}function mr(){return{left:0,right:0,top:0,bottom:0}}function Pa(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 us(e){return[e[1]*ee.BASE_TILE,e[0]*ee.BASE_TILE,e[2]*ee.BASE_TILE]}function ds(e,n){return e.axis==="x"?[n[0],n[2]]:e.axis==="y"?[n[2],n[1]]:[n[0],n[1]]}function Sa(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])<=dt){if(Math.abs(n[0]-o)<=dt)return"left";if(Math.abs(n[0]-r)<=dt)return"right"}if(Math.abs(n[1]-t[1])<=dt){if(Math.abs(n[1]-s)<=dt)return"top";if(Math.abs(n[1]-i)<=dt)return"bottom"}return null}function Ca(e,n){let t=null;for(let o=0;o<3;o+=1)if(!(Math.abs(e[o]-n[o])<=dt)){if(t!==null)return null;t=o}return t}function Ea(e,n,t){let o=n.vertices,r=us(o[t]),s=us(o[(t+1)%o.length]),i=Sa(e,ds(e,r),ds(e,s));if(!i)return null;let c=Ca(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>dt?{item:e,side:i,variableAxis:c,fixed:r,start:l,end:u}:null}function ps(e){e.item.bleed[e.side]=Math.max(e.item.bleed[e.side],ha)}function Ta(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=Ea(o,r,s);if(!i)continue;let c=Pa(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+dt);for(let i of r)i.item.sourceIndex!==s.item.sourceIndex&&(ps(i),ps(s));r.push(s)}}}function Aa(e){let n=(0,ee.parsePureColor)(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha}:{r:255,g:255,b:255,alpha:1}}function wa(e){if(!e)return"#cccccc";let n=(0,ee.parsePureColor)(e);if(!n)return e;let t={r:n.rgb[0],g:n.rgb[1],b:n.rgb[2],alpha:n.alpha};if(t.alpha<1){let o=Math.round(Math.max(0,t.alpha)*1e3)/1e3;return`rgba(${fr(t.r)}, ${fr(t.g)}, ${fr(t.b)}, ${o})`}return Ma(t)}function Ma({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 fr(e){return Math.round(Math.max(0,Math.min(255,e)))}function La(e,n,t,o){let r=t?.direction??ca,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??da)*Math.max(0,e[0]*i+e[1]*c+e[2]*l),d=Math.max(0,o?.intensity??ma),x=t?.color??ua,h=o?.color??pa,b=(0,ee.shadePolygon)(n,u,x,h,d),v=Aa(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 _a(e){if(!e?.length)return[];let n=[];for(let t=0;t<e.length;t+=1){let o=e[t],r=xa(o);if(!r||r.width<=0||r.height<=0)return[];n.push({...r,sourceIndex:t})}return Ta(e,n),n}function Ra(e){return e.axis==="x"?{xAxis:[1,0,0],yAxis:[0,0,1],normal:[0,-1,0],tx:0,ty:-e.z,tz:0}:e.axis==="y"?{xAxis:[0,0,1],yAxis:[0,1,0],normal:[-1,0,0],tx:-e.z,ty:0,tz:0}:{xAxis:[1,0,0],yAxis:[0,1,0],normal:[0,0,1],tx:0,ty:0,tz:e.z}}function ka(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 Oa(e){return new Map([[0,e.bleed.top],[1,e.bleed.right],[2,e.bleed.bottom],[3,e.bleed.left]])}function Da(e,n){let t=e.split(",").map(Number);if(t.length!==16||t.some(r=>!Number.isFinite(r)))return null;let o=ee.SOLID_QUAD_CANONICAL_SIZE/n;for(let r=0;r<8;r+=1)t[r]*=o;return`matrix3d(${t.map(r=>Number(r.toFixed(6))).join(",")})`}function ms(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 Ia(e,n){let{xAxis:t,yAxis:o,normal:r,tx:s,ty:i,tz:c}=Ra(e),l=(0,ee.computeProjectiveQuadMatrix)(ka(e),t,o,r,s,i,c,ga,Oa(e));return l?Da(l,n)??ms(e,n):ms(e,n)}function Ha(e){let n=e.defaultView?.matchMedia;return n?n("(pointer: coarse)").matches||n("(hover: none)").matches:!1}function Fa(e){return Ha(e)?fa:fs}function Va(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 Ba(e,n){let t=Va(e),o=n.meshRotation;o&&(t=(0,ee.rotateVec3InWrapperCssFrame)(t,o));let[r,s]=(0,ee.rotateVec3)(t,n.rotX,0,n.rotY);return{x:r,y:s}}function za(e,n,t){let o=e.filter(h=>n.has(h.face)).map(h=>({item:h,...Ba(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 gs(e){let{doc:n,wrapper:t,polygons:o,directionalLight:r,ambientLight:s}=e,i=_a(o);if(i.length===0)return null;let c=new Set(i.map(y=>y.face));t.classList.add("polycss-voxel-mesh");let l=Fa(n);l!==fs&&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=La(hs[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),ba(m,d(y.face,y.baseColor),Ia(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 hr)c.has(y)&&I(y,v.get(y)??[])},K=y=>new Set(y.split("|").filter(Boolean)),O=y=>{let m=K(y);return hr.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 re=T+1;re<y.length;re+=1){let _=h.get(y[re]);if(_?.parentNode===t){L=_;break}}t.insertBefore(R,L??z())}C=p},A=(y,m,p)=>{if(!p){let re=O(y);$(re,!1),g=H(re);return}let T=new Set(y.split("|").filter(Boolean)),M=za(i,T,m),{orderedFaces:R,itemsByFace:L}=V(M);for(let re of R)I(re,L.get(re)??[]);$(R,!0),g=M.length};return Z(),{get brushCount(){return g},render(y){P=cs(y),A(P,y,!0)},syncCamera(y){let m=cs(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 ys="polycss-styles";function Gn(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(ys))return;let t=n.createElement("style");t.id=ys,t.textContent=Na,n.head.appendChild(t)}var Na=`
|
|
2
2
|
/* \u2500\u2500 Scene container \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
3
3
|
|
|
4
4
|
.polycss-scene,
|
|
@@ -51,12 +51,32 @@
|
|
|
51
51
|
transform-style: preserve-3d !important;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/* \u2500\u2500 Shadow root wrapper \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
55
|
+
|
|
56
|
+
/* Single 0\xD70 preserve-3d container that owns every shadow SVG (ground +
|
|
57
|
+
per-face receiver). Children composite via their own absolute matrix3d
|
|
58
|
+
transforms exactly as if mounted on .polycss-scene directly. The wrapper
|
|
59
|
+
exists so the DOM has one obvious "shadows live here" node and so
|
|
60
|
+
future toggles (clip-region, hide-all-shadows) flip a single ancestor. */
|
|
61
|
+
.polycss-shadows {
|
|
62
|
+
position: absolute;
|
|
63
|
+
top: 0;
|
|
64
|
+
left: 0;
|
|
65
|
+
width: 0;
|
|
66
|
+
height: 0;
|
|
67
|
+
transform-style: preserve-3d;
|
|
68
|
+
pointer-events: none;
|
|
69
|
+
}
|
|
70
|
+
|
|
54
71
|
/* \u2500\u2500 Mesh wrapper \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
55
72
|
|
|
56
73
|
.polycss-mesh {
|
|
57
74
|
position: absolute;
|
|
58
75
|
transform-style: preserve-3d;
|
|
59
|
-
|
|
76
|
+
/* Pivot at wrapper local (0,0,0) for three.js mesh.position/rotation/scale
|
|
77
|
+
parity. Geometry is positioned by the parser (bbox-min-at-origin by
|
|
78
|
+
default, or pre-centered via parseGltf/parseObj { center: true }). */
|
|
79
|
+
transform-origin: 0 0 0;
|
|
60
80
|
}
|
|
61
81
|
|
|
62
82
|
/* \u2500\u2500 Polygon leaf element \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
@@ -138,30 +158,39 @@
|
|
|
138
158
|
border-width: 0 16px 32px 16px;
|
|
139
159
|
}
|
|
140
160
|
|
|
141
|
-
|
|
142
|
-
|
|
161
|
+
@supports (corner-top-left-shape: bevel) and (corner-top-right-shape: bevel) {
|
|
162
|
+
.polycss-scene > u,
|
|
163
|
+
.polycss-mesh > u,
|
|
164
|
+
.polycss-bucket > u {
|
|
165
|
+
border-width: 0;
|
|
166
|
+
width: 32px;
|
|
167
|
+
height: 32px;
|
|
168
|
+
background-color: currentColor;
|
|
169
|
+
border-top-left-radius: 50% 100%;
|
|
170
|
+
border-top-right-radius: 50% 100%;
|
|
171
|
+
corner-top-left-shape: bevel;
|
|
172
|
+
corner-top-right-shape: bevel;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.polycss-scene > u.polycss-corner-shape-solid,
|
|
176
|
+
.polycss-mesh > u.polycss-corner-shape-solid,
|
|
177
|
+
.polycss-bucket > u.polycss-corner-shape-solid {
|
|
178
|
+
width: 16px;
|
|
179
|
+
height: 16px;
|
|
180
|
+
box-sizing: border-box;
|
|
181
|
+
border: 0;
|
|
182
|
+
background: currentColor;
|
|
183
|
+
border-radius: 0;
|
|
184
|
+
corner-top-left-shape: initial;
|
|
185
|
+
corner-top-right-shape: initial;
|
|
186
|
+
corner-bottom-right-shape: initial;
|
|
187
|
+
corner-bottom-left-shape: initial;
|
|
188
|
+
}
|
|
143
189
|
}
|
|
144
190
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
background: currentColor;
|
|
149
|
-
border: 0;
|
|
150
|
-
border-top-left-radius: 50% 100%;
|
|
151
|
-
border-top-right-radius: 50% 100%;
|
|
152
|
-
corner-top-left-shape: bevel;
|
|
153
|
-
corner-top-right-shape: bevel;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/* <q> \u2014 dedicated shadow leaf. Same border-shape rendering trick as <i>
|
|
157
|
-
(border-color: currentColor fills the polygon outline) but with its
|
|
158
|
-
own tag so we don't have to thread :not(.polycss-shadow) exclusions
|
|
159
|
-
through every dynamic-mode color rule. backface-visibility must be
|
|
160
|
-
visible because the projection matrix is near-rank-deficient and the
|
|
161
|
-
resulting plane's normal can read as back-facing under some camera
|
|
162
|
-
angles; the leaf is intentionally always painted. Strip the UA's
|
|
163
|
-
default ::before/::after open-/close-quote so the element is just a
|
|
164
|
-
styled box. */
|
|
191
|
+
/* Reserved internal <q> shadow element rules. Current shadow emission uses SVG
|
|
192
|
+
surfaces; these rules keep any retained <q> markup styled as a plain
|
|
193
|
+
border-shape leaf instead of inheriting UA quote styling. */
|
|
165
194
|
.polycss-scene q {
|
|
166
195
|
position: absolute;
|
|
167
196
|
display: block;
|
|
@@ -344,13 +373,34 @@
|
|
|
344
373
|
leaves, so there's nothing inside a leaf that needs to participate
|
|
345
374
|
in 3D compositing across the contain boundary. */
|
|
346
375
|
contain: strict;
|
|
376
|
+
/*
|
|
377
|
+
* Three.js MeshLambertMaterial parity for textured surfaces:
|
|
378
|
+
*
|
|
379
|
+
* target = sRGB_encode(albedo_linear \xD7 irradiance_linear / \u03C0)
|
|
380
|
+
*
|
|
381
|
+
* background-blend-mode: multiply produces (bitmap \xD7 tint) in sRGB
|
|
382
|
+
* \u2014 approximately sRGB(albedo_linear \xD7 tint_linear) when bitmap \u2248
|
|
383
|
+
* sRGB(albedo_linear). So we want tint = sRGB_encode(irradiance /\u03C0).
|
|
384
|
+
*
|
|
385
|
+
* Each light/ambient colour channel is sRGB-to-linearised
|
|
386
|
+
* via pow((c + 0.055) / 1.055, 2.4) before the dot product so the
|
|
387
|
+
* irradiance accumulates in linear space; final encode is
|
|
388
|
+
* 1.055 \xD7 pow(c, 1/2.4) - 0.055. min(1, \u2026) clamps inside the encode
|
|
389
|
+
* domain. Matches the solid <b>/<i>/<u> pipeline below.
|
|
390
|
+
*/
|
|
347
391
|
background-color: rgb(
|
|
348
|
-
calc(255 * (
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
calc(255 * (
|
|
353
|
-
|
|
392
|
+
calc(255 * max(0, 1.055 * pow(min(1, (
|
|
393
|
+
pow((var(--par) + 0.055) / 1.055, 2.4) * var(--pai) +
|
|
394
|
+
pow((var(--plr) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
|
|
395
|
+
) / 3.14159265), 0.4167) - 0.055))
|
|
396
|
+
calc(255 * max(0, 1.055 * pow(min(1, (
|
|
397
|
+
pow((var(--pag) + 0.055) / 1.055, 2.4) * var(--pai) +
|
|
398
|
+
pow((var(--plg) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
|
|
399
|
+
) / 3.14159265), 0.4167) - 0.055))
|
|
400
|
+
calc(255 * max(0, 1.055 * pow(min(1, (
|
|
401
|
+
pow((var(--pab) + 0.055) / 1.055, 2.4) * var(--pai) +
|
|
402
|
+
pow((var(--plb) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
|
|
403
|
+
) / 3.14159265), 0.4167) - 0.055))
|
|
354
404
|
);
|
|
355
405
|
background-blend-mode: multiply;
|
|
356
406
|
background-image: var(--polycss-atlas-url);
|
|
@@ -371,21 +421,55 @@
|
|
|
371
421
|
.polycss-scene[data-polycss-lighting="dynamic"] b,
|
|
372
422
|
.polycss-scene[data-polycss-lighting="dynamic"] i,
|
|
373
423
|
.polycss-scene[data-polycss-lighting="dynamic"] u {
|
|
424
|
+
/*
|
|
425
|
+
* Three.js MeshLambertMaterial parity (default useLegacyLights=false,
|
|
426
|
+
* physically-correct pipeline):
|
|
427
|
+
*
|
|
428
|
+
* lit_linear = albedo_linear \xD7 (lightColor_linear \xD7 intensity \xD7 lambert
|
|
429
|
+
* + ambient_linear \xD7 ambientIntensity) / \u03C0
|
|
430
|
+
* output = 255 \xD7 sRGB_encode(min(1, lit_linear))
|
|
431
|
+
*
|
|
432
|
+
* sRGB\u2192linear: pow((c + 0.055) / 1.055, 2.4) for c > 0.04045
|
|
433
|
+
* 12.92 \xD7 c otherwise (skipped \u2014 tiny)
|
|
434
|
+
* linear\u2192sRGB: 1.055 \xD7 pow(c, 1/2.4) - 0.055 for c > 0.0031308
|
|
435
|
+
* 12.92 \xD7 c otherwise (skipped \u2014 tiny)
|
|
436
|
+
*
|
|
437
|
+
* The naive pow(c, 2.4) shortcut undershoots by ~2x for small c
|
|
438
|
+
* (dark channels of a saturated colour) \u2014 the +0.055/1.055 offset
|
|
439
|
+
* is load-bearing for the G/B drift on saturated fixtures.
|
|
440
|
+
*
|
|
441
|
+
* Verified against per-pixel screenshots in bench/three-parity.html
|
|
442
|
+
* (cube #dc2626 top face): drift <3 per channel across i=0.5..3,
|
|
443
|
+
* ambient=0..0.3, lambert=0..1.
|
|
444
|
+
*/
|
|
374
445
|
color: rgb(
|
|
375
|
-
calc(255 *
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
446
|
+
calc(255 * max(0, 1.055 * pow(min(1,
|
|
447
|
+
pow((var(--psr) + 0.055) / 1.055, 2.4) * (
|
|
448
|
+
pow((var(--par) + 0.055) / 1.055, 2.4) * var(--pai) +
|
|
449
|
+
pow((var(--plr) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
|
|
450
|
+
) / 3.14159265
|
|
451
|
+
), 0.4167) - 0.055))
|
|
452
|
+
calc(255 * max(0, 1.055 * pow(min(1,
|
|
453
|
+
pow((var(--psg) + 0.055) / 1.055, 2.4) * (
|
|
454
|
+
pow((var(--pag) + 0.055) / 1.055, 2.4) * var(--pai) +
|
|
455
|
+
pow((var(--plg) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
|
|
456
|
+
) / 3.14159265
|
|
457
|
+
), 0.4167) - 0.055))
|
|
458
|
+
calc(255 * max(0, 1.055 * pow(min(1,
|
|
459
|
+
pow((var(--psb) + 0.055) / 1.055, 2.4) * (
|
|
460
|
+
pow((var(--pab) + 0.055) / 1.055, 2.4) * var(--pai) +
|
|
461
|
+
pow((var(--plb) + 0.055) / 1.055, 2.4) * var(--pli) * var(--plam)
|
|
462
|
+
) / 3.14159265
|
|
463
|
+
), 0.4167) - 0.055))
|
|
381
464
|
);
|
|
382
465
|
}
|
|
383
466
|
|
|
384
|
-
/* \u2500\u2500
|
|
467
|
+
/* \u2500\u2500 Retained <q> shadow projection (dynamic-mode CSS path) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
385
468
|
|
|
386
469
|
/*
|
|
387
|
-
*
|
|
388
|
-
* ground plane (cssZ \u2248 G) along the CSS-space
|
|
470
|
+
* Projection matrix for retained internal <q> shadow leaves. Projects any
|
|
471
|
+
* 3D point P onto the horizontal ground plane (cssZ \u2248 G) along the CSS-space
|
|
472
|
+
* light direction (--clx/y/z).
|
|
389
473
|
*
|
|
390
474
|
* In PolyCSS's world convention world Z is up (red-green plane is the
|
|
391
475
|
* floor in the axes helper). After the world\u2192CSS swap (Y\u2194X), world Z stays
|
|
@@ -398,7 +482,7 @@
|
|
|
398
482
|
* has a valid layout box. The fix: collapse along z by a near-zero
|
|
399
483
|
* scale (Z_SQUASH = 0.01) instead of exactly zero \u2014 output.z is then
|
|
400
484
|
* approximately G with ~1% drift from the input, full-rank and renderable.
|
|
401
|
-
* The
|
|
485
|
+
* The result still looks flat to the eye (the drift is sub-pixel for
|
|
402
486
|
* any realistic scene size).
|
|
403
487
|
*
|
|
404
488
|
* out.cssX = P.cssX - (--clx/--clz) * (P.cssZ - G)
|
|
@@ -426,19 +510,290 @@
|
|
|
426
510
|
);
|
|
427
511
|
}
|
|
428
512
|
|
|
429
|
-
/* <q>
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
513
|
+
/* Retained <q> opacity gate. Polygons facing the light cast full shadow;
|
|
514
|
+
polygons facing away cast zero shadow. The * 10 multiplier sharpens the
|
|
515
|
+
cutoff so small positive Lambert values jump quickly to 1. */
|
|
516
|
+
.polycss-scene[data-polycss-lighting="dynamic"] q {
|
|
517
|
+
opacity: clamp(0, calc((var(--pnx) * var(--clx) + var(--pny) * var(--cly) + var(--pnz) * var(--clz)) * 10), 1);
|
|
518
|
+
}
|
|
519
|
+
`;var jn=require("@layoutit/polycss-core"),$a=1,pt=jn.BASE_TILE,Ua=.1;function Jt(e){return[e[1],e[0],e[2]]}function Ct(e){return e?.direction?{...e,direction:Jt(e.direction)}:e}function Wn(e){return(0,jn.buildPolyMeshTransform)(e)}function gr(e,n=[0,0,0],t=1){let o=e.state,r=o.rotX,s=o.rotY,c=(o.zoom??$a)/pt*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*pt,v=d*pt,P=h*pt;return`${l!==0?`translateZ(${-l}px) `:""}scale(${c}) rotateX(${r}deg) rotate(${s}deg) translate3d(${-b}px, ${-v}px, ${-P}px)`}function Ga(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 bs(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=Ga(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function vs(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}function xs(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/Ua,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 Ps(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 Ss(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function Cs(e,n){return e===n?!0:(e?.color??"#000000")===(n?.color??"#000000")&&(e?.opacity??.25)===(n?.opacity??.25)&&(e?.lift??.05)===(n?.lift??.05)&&(e?.maxExtend??2e3)===(n?.maxExtend??2e3)}var Et=require("@layoutit/polycss-core");var ja=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"],en="--polycss-light-preview-active",Es=`var(${en}, 0)`,Wa="max(0, calc(var(--pnx, 0) * var(--plx, 0) + var(--pny, 0) * var(--ply, 0) + var(--pnz, 1) * var(--plz, 1)))",yr=(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))`,Ya=yr("--psr","--par","--plr"),Xa=yr("--psg","--pag","--plg"),Za=yr("--psb","--pab","--plb");function he(e,n,t){return e.style.getPropertyValue(n)===t?!1:(e.style.setProperty(n,t),!0)}function Dt(e){for(let n of ja)e.style.getPropertyValue(n)&&e.style.removeProperty(n)}function Yn(e,n){let t=n.directionalLight?.direction??[.4,-.7,.59],o=Jt(t),r=Math.hypot(o[0],o[1],o[2])||1,s=o[0]/r,i=o[1]/r,c=o[2]/r,l=(0,Et.parseHexColor)(n.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],u=(0,Et.parseHexColor)(n.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],d=n.directionalLight?.intensity??1,x=n.ambientLight?.intensity??.4,h=P=>(P/255).toFixed(4);he(e,"--plx",s.toFixed(2)),he(e,"--ply",i.toFixed(2)),he(e,"--plz",c.toFixed(2)),he(e,"--plr",h(l[0])),he(e,"--plg",h(l[1])),he(e,"--plb",h(l[2])),he(e,"--pli",d.toFixed(4)),he(e,"--par",h(u[0])),he(e,"--pag",h(u[1])),he(e,"--pab",h(u[2])),he(e,"--pai",x.toFixed(4));let b=c,v=Math.sign(b||1)*Math.max(Math.abs(b),.01);he(e,"--clx",s.toFixed(2)),he(e,"--cly",i.toFixed(2)),he(e,"--clz",v.toFixed(2))}function Ts(e,n){let t=n.textureLighting==="dynamic";if(e.dataset.polycssLighting=n.textureLighting??"baked",!t){Dt(e);return}Yn(e,n)}function It(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 As(e,n){let t=(0,Et.parseHex)(n??"#cccccc");e.style.setProperty("--psr",(t.r/255).toFixed(4)),e.style.setProperty("--psg",(t.g/255).toFixed(4)),e.style.setProperty("--psb",(t.b/255).toFixed(4))}function br(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=t.textureLighting??"baked",r={directionalLight:Ct(t.directionalLight),ambientLight:t.ambientLight,textureLighting:o,textureQuality:t.textureQuality,seamBleed:t.seamBleed,strategies:t.strategies},s=Qo(e.plan,n,e.plan.normal,o,r);return jt(e.element,s,o),o==="baked"&&Qa(e.element),!0}function qa(e){let n=(0,Et.parsePureColor)(e)??{rgb:[255,255,255],alpha:1},[t,o,r]=n.rgb,s=(c,l)=>`calc(${c} * (1 - ${Es}) + var(${l}, ${c}) * ${Es})`,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 ws(e,n,t){if(!e.plan||e.kind==="atlas"||e.plan.texture)return!1;let o=e.element,r=e.plan.normal,s=(0,Et.parseHex)(n.color??"#cccccc"),i=!1;return i=he(o,"--pnx",r[0].toFixed(4))||i,i=he(o,"--pny",r[1].toFixed(4))||i,i=he(o,"--pnz",r[2].toFixed(4))||i,i=he(o,"--psr",(s.r/255).toFixed(4))||i,i=he(o,"--psg",(s.g/255).toFixed(4))||i,i=he(o,"--psb",(s.b/255).toFixed(4))||i,i=he(o,"--plam",Wa)||i,i=he(o,"--polycss-preview-r",Ya)||i,i=he(o,"--polycss-preview-g",Xa)||i,i=he(o,"--polycss-preview-b",Za)||i,i=he(o,"--polycss-paint",qa(t))||i,o.style.getPropertyValue("color")&&(o.style.removeProperty("color"),i=!0),i}function Qa(e){e.style.removeProperty("--pnx"),e.style.removeProperty("--pny"),e.style.removeProperty("--pnz"),e.style.removeProperty("--psr"),e.style.removeProperty("--psg"),e.style.removeProperty("--psb"),e.style.removeProperty("--plam"),e.style.removeProperty("--polycss-preview-r"),e.style.removeProperty("--polycss-preview-g"),e.style.removeProperty("--polycss-preview-b"),e.style.removeProperty("--polycss-paint")}var Ka="http://www.w3.org/2000/svg",Xn=class{constructor(){this.groundSvg=null;this.groundVisible=!1;this.currentGroundCssZ=null;this.shadowRoot=null}};function Ms(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 Ls(e){e.groundSvg?.parentNode&&e.groundSvg.parentNode.removeChild(e.groundSvg),e.groundSvg=null,e.groundVisible=!1}function _s(e){e.groundSvg&&e.groundVisible&&(e.groundSvg.style.display="none",e.groundVisible=!1)}function Rs(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(Ka,"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 ks(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 Xn,receiverShadowCache:new Map,receiverShadowCacheKey:new Map,casterItemsCache:new Map,casterItemsCacheKey:new Map}}var ze=require("@layoutit/polycss-core");function Os(e){for(let n of e)n.svg&&n.svg.parentNode&&n.svg.parentNode.removeChild(n.svg),n.svg=null}function Ds(e,n){if(n){let t=e.receiverShadowCache.get(n);t&&Os(t),e.receiverShadowCache.delete(n),e.receiverShadowCacheKey.delete(n)}else{for(let t of e.receiverShadowCache.values())Os(t);e.receiverShadowCache.clear(),e.receiverShadowCacheKey.clear()}}function Is(e,n){n?(e.casterItemsCache.delete(n),e.casterItemsCacheKey.delete(n)):(e.casterItemsCache.clear(),e.casterItemsCacheKey.clear())}function Hs(e){Ls(e.shadowSvgState),Fs(e)}function vr(e){return e.handle.id??e.autoMeshId}var Ja="http://www.w3.org/2000/svg",Zn=new WeakMap,Vs=new WeakMap,Bs=new WeakMap,zs=new WeakMap,Ns=new WeakMap;function $s(e){let n=Zn.get(e);return n||(n=new Map,Zn.set(e,n)),n}function xr(e){let n=Zn.get(e);if(n){for(let t of n.values())t.svg&&t.svg.parentNode&&t.svg.parentNode.removeChild(t.svg);n.clear(),Zn.delete(e)}}function Fs(e){for(let n of e.meshes)xr(n)}function Us(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=(0,ze.meshScaleVec3)(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=(0,ze.prepareReceiverFacePlanes)(o.polygons,P,o.handle.transform.scale,r,z,g),x.set(o,Z),h.set(o,I);let A=$s(o);for(let y of A.values())y.svg&&y.svg.parentNode&&y.svg.parentNode.removeChild(y.svg);A.clear()}let K=[];for(let A of n){let y=A.handle.transform.position??[0,0,0],m=A.handle.transform.rotation??[0,0,0],p=(0,ze.meshScaleVec3)(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=(0,ze.prepareCasterPolyItems)(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 _=Vs.get(A);(_===void 0||Bs.get(A)!==A.polygons)&&(_=(0,ze.buildSharedEdgeMap)(A.polygons),Vs.set(A,_),Bs.set(A,A.polygons)),L=_}let re;if(A!==o&&A.polygons.length>=40){let _=zs.get(A);(_===void 0||Ns.get(A)!==M)&&(_=(0,ze.prepareCasterEdgeOwners)(A.polygons,y,A.handle.transform.scale,m),zs.set(A,_),Ns.set(A,M)),re=_}K.push({id:A,items:R,selfShadowEdgeMap:L,edgeOwners:re,casterPolygonCount:A.polygons.length})}let O={rotX:e.camera.state.rotX,rotY:e.camera.state.rotY,meshRotation:o.handle.transform.rotation},H=(0,ze.computeReceiverShadowFaces)({receiverPlanes:Z,receiverPolygons:o.polygons,receiverHasTexture:C,casters:K,lightDir:s,cameraRot:O,ambientLight:d.ambientLight,directionalLight:d.directionalLight,shadow:{color:d.shadow?.color,opacity:u,maxExtend:d.shadow?.maxExtend}}),V=$s(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(Ja,"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",vr(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}`),Ms(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=Rs(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 re=A.paths[L],_=R?vr(re.casterId):"";R&&M.push(_);let j=p[L];if(j.setAttribute("d",re.d),j.getAttribute("fill")!==A.fill&&j.setAttribute("fill",A.fill),j.getAttribute("stroke")!==A.fill&&j.setAttribute("stroke",A.fill),j.getAttribute("opacity")!==T&&j.setAttribute("opacity",T),R){j.getAttribute("data-poly-shadow-caster")!==_&&j.setAttribute("data-poly-shadow-caster",_);let Q=JSON.stringify(re.casterPolygonIndices);j.getAttribute("data-poly-shadow-caster-polys")!==Q&&j.setAttribute("data-poly-shadow-caster-polys",Q)}}if(R){let L=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 Gs=Symbol.for("polycss.animation.triangleFrameTarget");var el=750;function js(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:ne.DEFAULT_SEAM_BLEED}}var tl={key:"non-cullable",normal:[1,1,0]};function Ws(){return[tl]}function qn(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&&Gn(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...r}=n,s=js({seamBleed:ne.DEFAULT_SEAM_BLEED,...r}),i=bs(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"),K(d,s),u.appendChild(d);let x=ks({host:e,doc:l,cameraEl:u,sceneEl:d,camera:t,layoutScale:i,options:s}),h=x.meshes,b=new WeakMap,v=x.shadowSvgState,P=()=>_s(v),g=()=>Hs(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=>Ds(x,a),I=a=>Is(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 K(a,f){vs(a,i),a.style.transform=gr(t,c,i),Ts(a,f)}function O(a){a.style.transform=gr(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?(0,ne.polygonCssSurfaceNormal)(S):f.plan?.normal??(S?(0,ne.polygonCssSurfaceNormal)(S):null)}function R(a){if(!Q(a))return a.rendered;let f=L(a);return a.rendered.filter(S=>re(a,S,ne.CAMERA_BACKFACE_CULL_EPS,f))}function L(a){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:a.handle.transform.rotation}}function re(a,f,S=ne.CAMERA_BACKFACE_CULL_EPS,E=L(a)){let W=M(a,f);return W===null||(0,ne.normalFacesCamera)(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(!(0,ne.isAxisAlignedSurfaceNormal)(E)){a.cameraCullGroups=Ws();return}let W=(0,ne.cameraCullNormalKey)(E);if(!f.has(W)&&(f.set(W,E),f.size>ne.VOXEL_CAMERA_CULL_NORMAL_LIMIT)){a.cameraCullGroups=Ws();return}}a.cameraCullGroups=Array.from(f,([S,E])=>({key:S,normal:E}))}function j(a){return Q(a)?(0,ne.cameraCullVisibleSignature)(a.cameraCullGroups,L(a)):"all"}function Q(a){return!a.excludeFromAutoCenter&&(0,ne.isVoxelCameraCullableNormalGroups)(a.cameraCullGroups)}function ae(a){a.cameraCullSignature=Q(a)?j(a):"all"}function xe(a,f){let S=new Array(a.rendered.length),E=!1,W=L(a);for(let J=0;J<a.rendered.length;J+=1){let ie=a.rendered[J],te=re(a,ie,f,W);S[J]=te}let B=null,F=null,G=()=>{if(!(!B||!F)){if(B===F)B.remove();else{let J=l.createRange();J.setStartBefore(B),J.setEndAfter(F),J.deleteContents(),J.detach()}B=null,F=null,E=!0}};for(let J=0;J<a.rendered.length;J+=1){let ie=a.rendered[J];!S[J]&&ie.element.parentNode===a.wrapper?(F&&F.nextSibling===ie.element||(G(),B=ie.element),F=ie.element):G()}G();let Y=J=>{for(let ie=J;ie<a.rendered.length;ie+=1){let te=a.rendered[ie].element;if(te.parentNode===a.wrapper)return te}return V(a)},de=-1,se=J=>{if(de<0)return;let ie=l.createDocumentFragment();for(let te=de;te<J;te+=1){let Ge=a.rendered[te];Te(a,Ge),ie.appendChild(Ge.element)}$(a,ie,Y(J)),de=-1,E=!0};for(let J=0;J<a.rendered.length;J+=1){let ie=a.rendered[J];S[J]&&ie.element.parentNode!==a.wrapper?de<0&&(de=J):se(J)}return se(a.rendered.length),E}function ge(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&&Ae(a);return}if(a.hasBuckets){be(a,f);return}let S=j(a);if(!f&&S===a.cameraCullSignature)return;let E=xe(a,ne.CAMERA_BACKFACE_CULL_EPS);a.cameraCullSignature=S,E&&Ke(a)}function be(a,f=!1){let S=Q(a)?j(a):"all";!f&&S===a.cameraCullSignature||Ae(a)}function Re(a,f){return M(a,f)}function Te(a,f){if(s.textureLighting!=="dynamic")return;let S=Re(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 De(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?xs(G):null;if(!Y){B.push(F);continue}let de=Y.key+"|"+(G.color??""),se=W.get(de);se||(se={vec:Y.vec,items:[]},W.set(de,se)),se.items.push(F)}for(let F of B)Te(a,F),S.appendChild(F.element);for(let F of W.values()){if(F.items.length<2){for(let Y of F.items)Te(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)),ae(a)}function Qe(){return new Promise(a=>setTimeout(a,0))}async function st(a,f){if(s.textureLighting==="dynamic"&&!a.stableDom)return De(a),!f();T(a);let E=l.createDocumentFragment(),W=V(a),B=0;for(let F of R(a)){if(f())return!1;Te(a,F),E.appendChild(F.element),B++,B%el===0&&($(a,E,W),E=l.createDocumentFragment(),await Qe())}return E.childNodes.length>0&&$(a,E,W),ae(a),!f()}function wt(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=(0,ne.inverseRotateVec3)(E,f),F=Jt(B),G=Math.hypot(F[0],F[1],F[2])||1,Y=(F[0]/G).toFixed(2),de=(F[1]/G).toFixed(2),se=(F[2]/G).toFixed(2),J=`${Y}|${de}|${se}`;a.lightOverrideSignature!==J&&(a.wrapper.style.setProperty("--plx",Y),a.wrapper.style.setProperty("--ply",de),a.wrapper.style.setProperty("--plz",se),a.lightOverrideSignature=J)}function Ft(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=br(S,E,s)||f)}return a.solidLightingPreviewPrepared=!1,a.solidLightingPreviewActive=!1,f}function Mt(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&&(ws(S,E,S.plan.shadedColor),f=!0)}return a.solidLightingPreviewPrepared=f,f}function Do(a){return(s.textureLighting??"baked")!=="baked"||!a.solidLightingPreviewPrepared&&!Mt(a)?!1:(a.solidLightingPreviewActive=!0,!0)}function Io(a){return a.kind==="atlas"||!!a.plan?.texture}function Ho(){if((s.textureLighting??"baked")!=="baked")return!1;let a=!1;for(let f of h)a=Ft(f)||a,f.rendered.some(Io)&&(fn(f),a=!0);d.style.removeProperty(en);for(let f of h)Dt(f.wrapper),f.solidLightingPreviewActive=!1;return Dt(d),a}function Fo(){d.style.removeProperty(en);for(let a of h)a.solidLightingPreviewActive&&(Ft(a),Dt(a.wrapper));(s.textureLighting??"baked")!=="dynamic"&&(Dt(d),k(),ke())}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){Dt(a.wrapper);return}let B=(0,ne.inverseRotateVec3)(E,S);Yn(a.wrapper,{...s,...f,directionalLight:{...s.directionalLight,...f.directionalLight,direction:B}})}function ce(a){if((s.textureLighting??"baked")!=="baked")return!1;Yn(d,{...s,...a}),!a.skipShadows&&a.directionalLight?.direction&&ke(a.directionalLight.direction);let f=!1;for(let S of h)U(S,a),f=Do(S)||f;return f?he(d,en,"1"):d.style.removeProperty(en),f}function ue(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"?(As(W.element,S),!0):B==="baked"?br(W,E,s):!1}function Ie(a,f){let S=a.polygons[f];if(!S)return!1;let E=p(a,f);return E?(Ee(E.element,S,f),!0):!1}function mn(a,f,S){return!(S.length===0||!S.every(E=>E==="color"||E==="data")||S.includes("color")&&!ue(a,f,a.polygons[f]?.color)||S.includes("data")&&!Ie(a,f))}function Ke(a){k(),ke()}function ke(a){let f=[];for(let te of h)!te.disposed&&te.castShadow&&f.push(te);if(f.length===0){g(),C=null;return}let S=s.shadow?.color??"#000000",E=s.shadow?.opacity??.25,W=(0,ne.parseHexColor)(S)?.rgb??[0,0,0],B=W[0],F=W[1],G=W[2],Y=a??s.directionalLight?.direction??[.4,-.7,.59],de=Jt(Y),se=D(de);if(se!==null&&se===C)return;let J=new Map;for(let te of f)J.set(te,(0,ne.findOverlappingPolygonDuplicates)(te.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.95,preserveDoubleSidedBackfaces:!1}));let ie=new Map;for(let te of h)te.disposed||!te.receiveShadow||ie.set(te,new Set);P();for(let te of h)te.disposed||!te.receiveShadow||Us(x,f,J,te,ie.get(te)??new Set,de,B,F,G,E);C=se}function Ae(a){if(a.voxelRenderer){a.voxelRenderer.render(L(a)),a.cameraCullSignature="voxel-direct";return}A(a),De(a),Ke(a)}function $e(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=J=>Math.round(J*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 de=Y&&Y.polygons===a.polygons?Y.dedupDropped:(0,ne.findOverlappingPolygonDuplicates)(a.polygons,{normalTolerance:.1,distanceTolerance:.12,overlapFraction:.98,preserveDoubleSidedBackfaces:!1}),se=(0,ne.computeLightVisibility)(a.polygons,[E,W,B],de);return a.lightOcclusionCache={polygons:a.polygons,lightDirKey:G,occluded:se,dedupDropped:de},se}function Ue(a){return!!a.voxelSource&&s.textureLighting!=="dynamic"&&!a.stableDom&&!a.castShadow}function _e(a,f){H(a);let S=s.directionalLight,E=f?{...S,direction:f}:S,W=Ct(E),B=void 0;if(Ue(a)){let Y=gs({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=vt(a.polygons,F);return It(a.wrapper,Y),Ot(a.polygons,{...F,solidPaintDefaults:Y})??xt(a.polygons,{...F,solidPaintDefaults:Y})})():xt(a.polygons,{...F,computeSolidPaintDefaults:!0,skipDynamicNormalVars:s.textureLighting==="dynamic"});a.stableDom||It(a.wrapper,G.solidPaintDefaults??{}),m(a,G.rendered,G.dispose),a.skipBucketNormalCleanupOnce=s.textureLighting==="dynamic"&&!a.stableDom,_(a),De(a),Ke(a)}function fn(a,f){if(a.rendered.length===0||a.voxelRenderer||a.stableDom||Ue(a)){_e(a,f);return}if(a.rendered[0]?.element.parentNode===null){_e(a,f);return}let S=s.directionalLight,E=f?{...S,direction:f}:S,W=Ct(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=xt(a.polygons,B),G=()=>{a.rebakeInFlight=!1;let se=a.rebakeQueuedLightDir;se!==null&&(a.rebakeQueuedLightDir=null,fn(a,se))},Y=()=>{if(a.disposed){F.dispose(),G();return}if(F.rendered.length!==a.rendered.length){F.dispose(),_e(a,f),G();return}for(let ie of F.rendered){let te=a.renderedByPolygonIndex[ie.polygonIndex];if(!te)continue;let Ge=ie.element.getAttribute("style");Ge!==null&&te.element.setAttribute("style",Ge)}let se=F.solidPaintDefaults;se&&It(a.wrapper,se);let J=a.disposeAtlas;a.disposeAtlas=F.dispose,J&&(typeof requestAnimationFrame=="function"?te=>{requestAnimationFrame(te)}:te=>{setTimeout(te,0)})(J),Ke(a),G()},de=F.pagesReady;de&&typeof de.then=="function"?de.then(()=>Bo(F.rendered)).then(zo).then(Y,()=>{F.dispose(),a.disposed||_e(a,f),G()}):Y()}function Vo(a,f){if(a.rebakeInFlight){a.rebakeQueuedLightDir=f;return}a.rebakeInFlight=!0,fn(a,f)}function Bo(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 zo(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 it(){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 de of Y.vertices){let se=de[2]+G;se<a&&(a=se)}}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)*pt,W=v.currentGroundCssZ;v.currentGroundCssZ=E,W!==E&&(k(),ke())}async function Ln(a,f){H(a);let S=Ct(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?Ot(a.polygons,E):null;if(W){let G=vt(a.polygons,E);return It(a.wrapper,G),m(a,W.rendered,W.dispose),_(a),De(a),Ke(a),!f()}let B=await qt(a.polygons,{...E,skipDynamicNormalVars:s.textureLighting==="dynamic"},f);if(f())return B.dispose(),!1;It(a.wrapper,B.solidPaintDefaults),m(a,B.rendered,B.dispose),a.skipBucketNormalCleanupOnce=s.textureLighting==="dynamic"&&!a.stableDom,_(a);let F=await st(a,f);return F&&Ke(a),F}function Lt(){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=(0,ne.computeSceneBbox)(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,K(d,s))}function Oi(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,de=Wn(B);de&&(E.style.transform=de);let se=(N,X)=>a.voxelSource?N:X?(0,ne.optimizeMeshPolygons)(N,{meshResolution:f.meshResolution}):(G||f.excludeFromAutoCenter,N),J=se(a.polygons,F),ie=null;function te(){let N=Wn(B);E.style.transform=N??""}function Ge(N){if(N.length===0){ie=null,Je&&(Je.bboxCenterCss=null),te();return}let X=1/0,me=1/0,ve=1/0,Fe=-1/0,fe=-1/0,Ce=-1/0;for(let nt of N)for(let We of nt.vertices)We[0]<X&&(X=We[0]),We[0]>Fe&&(Fe=We[0]),We[1]<me&&(me=We[1]),We[1]>fe&&(fe=We[1]),We[2]<ve&&(ve=We[2]),We[2]>Ce&&(Ce=We[2]);if(!Number.isFinite(X)){ie=null,Je&&(Je.bboxCenterCss=null),te();return}let je=(me+fe)/2*pt,tt=(X+Fe)/2*pt,Ve=(ve+Ce)/2*pt;ie=[je,tt,Ve],Je&&(Je.bboxCenterCss=ie),te()}let Je=null;Ge(J),d.appendChild(E);let w={handle:void 0,wrapper:E,parseResult:a,rendered:[],renderedByPolygonIndex:[],shadowRendered:[],polygons:J,voxelSource:a.voxelSource,disposed:!1,stableDom:G,hasBuckets:!1,skipBucketNormalCleanupOnce:!1,excludeFromAutoCenter:!!f.excludeFromAutoCenter,castShadow:!!f.castShadow,bboxCenterCss:ie,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},et=null,No=0,_n=-1,hn=null;function gn(){et=null,hn=null,_n=-1}function Dr(){let N=et;if(!N||N.polygonCount!==w.polygons.length)return w.polygons;if(hn&&_n===No)return hn;let X=N.vertices,me=new Array(N.polygonCount);for(let ve=0;ve<N.polygonCount;ve++){let Fe=w.polygons[ve],fe=ve*9;me[ve]={...Fe,color:N.colors?.[ve]??Fe.color,vertices:[[X[fe],X[fe+1],X[fe+2]],[X[fe+3],X[fe+4],X[fe+5]],[X[fe+6],X[fe+7],X[fe+8]]]}}return hn=me,_n=No,me}function Ir(N,X){let me=N?.stableTriangleUpdateMode==="color-only";w.stableTriangleColorFrame++;let ve=w.stableDom&&!X;if(ve||Ge(w.polygons),w.stableDom&&!w.hasBuckets){let Fe={doc:l,directionalLight:Ct(s.directionalLight),ambientLight:s.ambientLight,textureLighting:s.textureLighting,textureQuality:s.textureQuality,seamBleed:s.seamBleed},fe=w.rendered.length===w.polygons.length&&w.rendered.every(Ve=>Ve.kind==="triangle"),Ce=w.stableDom&&!X,je=fe||Ce?{}:vt(w.polygons,Fe);fe||It(w.wrapper,je);let tt={...Fe,solidPaintDefaults:je,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(Kt(w.rendered,w.polygons,tt))return me||(_(w),ge(w,!0),X&&Lt()),!0}return ve&&Ge(w.polygons),!1}let Vt={get polygons(){return Dr()},set polygons(N){gn(),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),Lt(),it()},setPolygons(N,X){Y++,F=X?.merge??F,G=X?.stableDom??G,w.stableDom=G,w.voxelSource=void 0,w.polygons=se(N,F),I(w),z(w),gn(),Vt.polygons=w.polygons;let me=X?.recomputeAutoCenter??!0;Ir(X,me)||(_e(w),me&&Lt())},[Gs](N,X){let me=X?.merge??F,ve=X?.stableDom??G;if(!N.solidTriangles||!ve||me||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 Ce=0;Ce<w.rendered.length;Ce++){let je=w.rendered[Ce],tt=w.polygons[Ce];if(je?.kind!=="triangle"||je.polygonIndex!==Ce||!tt||tt.vertices.length!==3||tt.texture||tt.material?.texture)return!1}let Fe=X?.recomputeAutoCenter??!0;if(!Fe){let Ce=w.stableTriangleColorFrame+1,je={doc:l,directionalLight:Ct(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:Ce};if(Qt(w.rendered,w.polygons,N,je))return Y++,F=me,G=ve,w.stableDom=G,w.voxelSource=void 0,w.stableTriangleColorFrame=Ce,et=N,No++,hn=null,_n=-1,Q(w)?(_(w),ge(w,!0)):ae(w),!0}Y++,F=me,G=ve,w.stableDom=G,w.voxelSource=void 0;let fe=N.vertices;for(let Ce=0;Ce<N.polygonCount;Ce++){let je=w.polygons[Ce],tt=N.colors?.[Ce];tt&&(je.color=tt);let Ve=je.vertices,nt=Ce*9;Ve[0][0]=fe[nt],Ve[0][1]=fe[nt+1],Ve[0][2]=fe[nt+2],Ve[1][0]=fe[nt+3],Ve[1][1]=fe[nt+4],Ve[1][2]=fe[nt+5],Ve[2][0]=fe[nt+6],Ve[2][1]=fe[nt+7],Ve[2][2]=fe[nt+8]}return gn(),Vt.polygons=w.polygons,Ir(X,Fe)},updatePolygon(N,X){let me=typeof N=="number"?N:w.polygons.indexOf(N);if(me<0&&typeof N!="number"&&et&&(me=Dr().indexOf(N)),me<0||me>=w.polygons.length)return;gn(),w.voxelSource=void 0,Object.assign(w.polygons[me],X);let ve=Object.keys(X);mn(w,me,ve)||_e(w)},async setPolygonsChunked(N,X){let me=++Y;F=X?.merge??F,G=X?.stableDom??G,w.stableDom=G,w.voxelSource=void 0,w.polygons=se(N,F),gn(),Vt.polygons=w.polygons,Ge(w.polygons);let ve=X?.recomputeAutoCenter??!0;if(!await Ln(w,()=>w.disposed||me!==Y)){H(w);return}ve&&Lt()},setTransform(N){let X=w.castShadow,me=w.receiveShadow;N.castShadow!==void 0&&(w.castShadow=!!N.castShadow),N.receiveShadow!==void 0&&(w.receiveShadow=!!N.receiveShadow),B={...B,...N};let ve=Wn(B);E.style.transform=ve??"",wt(w,B.rotation),N.rotation!==void 0&&ge(w,!0),w.castShadow!==X&&(w.voxelSource&&_e(w),Ke(w),it()),w.receiveShadow!==me&&(w.receiveShadow||xr(w),k(),ke()),(N.position!==void 0||N.scale!==void 0)&&(w.castShadow||w.receiveShadow)&&(it(),k(),ke())},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),Lt(),it()}},rebakeAtlas(){w.bakedRotation=B.rotation?[...B.rotation]:[0,0,0];let N=s.directionalLight?.direction??[.4,-.7,.59],X=(0,ne.inverseRotateVec3)(N,w.bakedRotation);Vo(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),_e(w),wt(w,B.rotation),Lt(),it(),w.receiveShadow&&(k(),ke()),Vt}function Di(a){let f=!!s.autoCenter,S=s.strategies,E=s.seamBleed,W=s.textureLighting,B=s.directionalLight?.direction,F=s.shadow,G=js(a);s={...s,...G},x.options.current=s,K(d,s);let Y=!!s.autoCenter;for(let et of h)wt(et,et.handle.transform.rotation);let de=a.strategies!==void 0&&!Ps(a.strategies,S),se=Object.prototype.hasOwnProperty.call(a,"seamBleed")&&G.seamBleed!==E;if(de||se)for(let et of h)_e(et);f!==Y&&Lt();let J=a.textureLighting!==void 0&&W!==s.textureLighting,ie=s.directionalLight?.direction,te=a.directionalLight!==void 0&&!Ss(B,ie),Ge=s.shadow,Je=a.shadow!==void 0&&!Cs(F,Ge),w=te||Je;if(J){if(!de&&!se)for(let et of h)_e(et);it(),k(),ke()}else w&&(Je&&k(),ke());Je&&a.shadow?.lift!==F?.lift&&it()}function Ii(){return s}function Hi(){O(d);for(let a of h)ge(a)}function Fi(){let a=[];for(let f of h)a.push(f.handle);return a}function Vi(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 Bi(){let a=Array.from(h);for(let f of a)try{f.handle.dispose()}catch{}u.parentNode&&u.parentNode.removeChild(u)}return{add:Oi,setOptions:Di,destroy:Bi,host:e,camera:t,cameraEl:u,sceneElement:d,applyCamera:Hi,getOptions:Ii,meshes:Fi,findMeshByElement:Vi,previewBakedSolidLighting:ce,commitBakedSolidLighting:Ho,clearBakedSolidLightingPreview:Fo}}var pn=require("@layoutit/polycss-core");var Pr=require("@layoutit/polycss-core"),nl=32e3;function tn(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,Pr.createIsometricCamera)(n),o=`${e.perspective??nl}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function Tt(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,Pr.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var Ys=Tt;var Xs=require("@layoutit/polycss-core");var Qn={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function nn(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 on(){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 rn(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 Kn(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 Jn(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 eo(e,n={}){let t=nn(Qn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,u=on(),d=rn(e),{changeListeners:x,startListeners:h,endListeners:b,listenerArray:v,emitChange:P,emitInteraction:g}=u,C=Jn(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,re=M/4*R,_=e.camera.state;if(p.shiftKey){let j=_.rotX??65,Q=_.rotY??45,ae=Math.max(.01,_.zoom??1),xe=Math.cos(j*Math.PI/180),ge=xe>=0?Math.max(.1,xe):Math.min(-.1,xe),be=Math.cos(Q*Math.PI/180),Re=Math.sin(Q*Math.PI/180),Te=ae*Xs.BASE_TILE,De=(T*Re-M*be/ge)/Te,Qe=-(T*be+M*Re/ge)/Te,st=_.target??[0,0,0];e.camera.update({target:[st[0]+De,st[1]+Qe,st[2]]})}else{let j=Math.max(0,Math.min(89,(_.rotX??65)-re)),Q=(((_.rotY??45)-L)%360+360)%360;e.camera.update({rotX:j,rotY:Q})}e.applyCamera(),P(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=Kn(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 K(){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=nn(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,K(),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}}var Zs=require("@layoutit/polycss-core");function to(e,n={}){let t=nn(Qn,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=on(),h=rn(e),{changeListeners:b,startListeners:v,endListeners:P,listenerArray:g,emitChange:C,emitInteraction:D}=x,k=Jn(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 ae=e.camera.state;if(_.shiftKey){let xe=Tn(t.invert),ge=j/4*xe,be=Q/4*xe,Re=(ae.rotX??65)-be,Te=(((ae.rotY??45)-ge)%360+360)%360;e.camera.update({rotX:Re,rotY:Te})}else{let xe=ae.rotX??65,ge=ae.rotY??45,be=Math.max(.01,ae.zoom??1),Re=Math.cos(xe*Math.PI/180),Te=Re>=0?Math.max(.1,Re):Math.min(-.1,Re),De=Math.cos(ge*Math.PI/180),Qe=Math.sin(ge*Math.PI/180),st=be*Zs.BASE_TILE,wt=(j*Qe-Q*De/Te)/st,Ft=-(j*De+Q*Qe/Te)/st,Mt=ae.target??[0,0,0];e.camera.update({target:[Mt[0]+wt,Mt[1]+Ft,Mt[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)}},K=_=>{_.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 ae=Tn(t.invert),xe=j/4*ae,ge=Q/4*ae,be=e.camera.state,Re=(be.rotX??65)-ge,Te=(((be.rotY??45)-xe)%360+360)%360;e.camera.update({rotX:Re,rotY:Te}),e.applyCamera(),C(h)},V=_=>{_.button===2&&u&&(u=!1,D("end",h))},$=Kn(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",K),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",K),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=nn(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(_),ae=Q.indexOf(j);ae>=0&&Q.splice(ae,1)}function re(_,j){return g(_).includes(j)}return{update:m,resume:p,pause:T,destroy:M,addEventListener:R,removeEventListener:L,hasEventListener:re}}var ni=require("@layoutit/polycss-core");var ol={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 qs(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 Qs=new Set(["KeyW","ArrowUp"]),Ks=new Set(["KeyS","ArrowDown"]),Js=new Set(["KeyA","ArrowLeft"]),ei=new Set(["KeyD","ArrowRight"]),ti=new Set(["Space"]),Sr=new Set(["ControlLeft","ControlRight"]);function no(e,n={}){let t=qs(ol,n),o=e.host,r=e.cameraEl,s=o.ownerDocument??document,i=s.defaultView??globalThis,c=on(),l=rn(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,ce){let ue=U*Math.PI/180,Ie=ce*Math.PI/180;return[-Math.sin(ue)*Math.cos(Ie),-Math.sin(ue)*Math.sin(Ie),-Math.cos(ue)]}function K(){let U=e.camera.perspectiveStyle,ce=U==="none"?0:parseFloat(U);return(Number.isFinite(ce)&&ce>0?ce:2e3)/ni.BASE_TILE}function O(){let U=e.camera.state,ce=Z(U.rotX??90,U.rotY??0),ue=K();return[I[0]+ce[0]*ue,I[1]+ce[1]*ue,I[2]+ce[2]*ue]}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 ce=U.movementX??0,ue=U.movementY??0;if(ce===0&&ue===0)return;let Ie=e.camera.state,mn=t.lookSensitivity,Ke=t.invertY?-1:1,ke=(((Ie.rotY??0)-ce*mn)%360+360)%360,Ae=(Ie.rotX??90)-ue*mn*Ke;Ae<t.minPitch?Ae=t.minPitch:Ae>t.maxPitch&&(Ae=t.maxPitch);let $e=Z(Ae,ke),Ue=K(),_e=[I[0]+$e[0]*Ue,I[1]+$e[1]*Ue,I[2]+$e[2]*Ue];e.camera.update({rotX:Ae,rotY:ke,target:_e}),e.applyCamera(),b(l)},m=U=>Qs.has(U)||Ks.has(U)||Js.has(U)||ei.has(U)||ti.has(U)||Sr.has(U),p=U=>{if(!(!t.enabled||C)&&m(U.code)&&!(!g&&!t.moveEnabled)){if(ti.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}Sr.has(U.code)&&!t.crouchEnabled||!t.moveEnabled&&!Sr.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,re=.05,_=U=>{if(R===null||C)return;let ce=Math.min(re,L?(U-L)/1e3:.0167);if(L=U,t.enabled){let ue=!1,Ie=e.camera.state;if(t.moveEnabled){let Ae=0,$e=0;for(let Ue of P)Qs.has(Ue)?Ae+=1:Ks.has(Ue)?Ae-=1:ei.has(Ue)?$e+=1:Js.has(Ue)&&($e-=1);if(Ae!==0||$e!==0){let _e=(Ie.rotY??0)*Math.PI/180,fn=-Math.cos(_e),Vo=-Math.sin(_e),Bo=-Math.sin(_e),zo=Math.cos(_e),it=Math.hypot(Ae,$e)||1,Ln=t.moveSpeed*ce;I[0]+=(fn*Ae+Bo*$e)/it*Ln,I[1]+=(Vo*Ae+zo*$e)/it*Ln,ue=!0}}let Ke=t.crouchEnabled&&(P.has("ControlLeft")||P.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(D!==0||k>0)?(D-=t.gravity*ce,k+=D*ce,k<=0&&(k=0,D=0)):t.jumpEnabled||(k=0,D=0);let ke=t.groundZ+Ke+k;if(Math.abs(I[2]-ke)>1e-4&&(I[2]=ke,ue=!0),ue){let Ae=O();e.camera.update({target:Ae}),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 ae(){let ce=r.ownerDocument?.defaultView?.getComputedStyle(r).perspective??"",ue=parseFloat(ce),Ie=Number.isFinite(ue)&&ue>0?ue:2e3;r.style.setProperty("--polycss-fpv-perspective",`${Ie}px`),r.classList.add("polycss-fpv-host")}function xe(){r.classList.remove("polycss-fpv-host"),r.style.removeProperty("--polycss-fpv-perspective")}function ge(){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":"",ae()}function be(){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{}xe()}V(),ge(),j();function Re(U){let ce=t.eyeHeight,ue=t.groundZ;t=qs(t,U),C||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==ce||t.groundZ!==ue)&&(I[2]=t.groundZ+t.eyeHeight,H(),b(l))}function Te(){C&&(C=!1,ge(),j())}function De(){C||(C=!0,be(),Q(),z&&(z=!1,v("end",l)))}function Qe(){De(),u.length=0,d.length=0,x.length=0}function st(){if(!(!t.enabled||!t.lookEnabled||C))try{o.requestPointerLock()}catch{}}function wt(){if(g)try{s.exitPointerLock()}catch{}}function Ft(){return g}function Mt(U,ce){let ue=h(U);ue.includes(ce)||ue.push(ce)}function Do(U,ce){let ue=h(U),Ie=ue.indexOf(ce);Ie>=0&&ue.splice(Ie,1)}function Io(U,ce){return h(U).includes(ce)}function Ho(){return[I[0],I[1],I[2]]}function Fo(U){I[0]=U[0],I[1]=U[1],I[2]=U[2],H(),b(l)}return{update:Re,resume:Te,pause:De,destroy:Qe,lock:st,unlock:wt,isLocked:Ft,getOrigin:Ho,setOrigin:Fo,addEventListener:Mt,removeEventListener:Do,hasEventListener:Io}}function sn(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 oi(e,n,t,o){for(let r of e)if(!(o&&!o(r))&&sn(r.element,n,t))return r;return null}function oo(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 oi(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}}var Le=require("@layoutit/polycss-core");var ro="#ff3653",so="#8adb00",io="#2c8fff",an=50,ri=60,rl=.6,sl=.0125,il=.15,al=.04,ll=1,si=.02,Cr=1.04,cl=.1,ul=.25,ci=1e-4,dl=.6,pl=.8,ml=1,mt={0:1,1:0,2:2},ii=[{cssAxis:0,sign:1,key:"x",color:ro},{cssAxis:0,sign:-1,key:"-x",color:ro},{cssAxis:1,sign:1,key:"y",color:so},{cssAxis:1,sign:-1,key:"-y",color:so},{cssAxis:2,sign:1,key:"z",color:io},{cssAxis:2,sign:-1,key:"-z",color:io}],ai=[{cssAxis:0,key:"x",color:ro},{cssAxis:1,key:"y",color:so},{cssAxis:2,key:"z",color:io}],li=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:io},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:so},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:ro}];function Er(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 fl(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),s=parseInt(t[3],16);return`rgba(${o}, ${r}, ${s}, ${n})`}function ao(e,n){return!n||n<=0?e:Math.round(e/n)*n}function hl(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 Tr(e){if(e.length===0)return ri;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)*an*rl:ri}function gl(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<ci)return;d?.(),h?.(!0);let I=K=>{let O=K.clientX-i,H=K.clientY-c,V=(O*D+H*k)/z;V=ao(V,l),u(V,v)},Z=()=>{window.removeEventListener("pointermove",I),window.removeEventListener("pointerup",Z),window.removeEventListener("pointercancel",Z);let K=O=>{O.stopPropagation(),O.stopImmediatePropagation()};window.addEventListener("click",K,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",K,!0),0),x?.(),h?.(!1)};window.addEventListener("pointermove",I),window.addEventListener("pointerup",Z),window.addEventListener("pointercancel",Z)}function yl(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(),K=I.getBoundingClientRect();return r.removeChild(I),{x:(K.left-Z.left)/o,y:(K.top-Z.top)/o}}let P=v(h),g=v(b),C=P.x*g.y-g.x*P.y;if(Math.abs(C)<ci)return;u?.(),x?.(!0);let D=z=>{let I=z.clientX-s,Z=z.clientY-i,K=(g.y*I-g.x*Z)/C,O=(-P.y*I+P.x*Z)/C;K=ao(K,c),O=ao(O,c),l(K,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 bl(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=ao(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 lo(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=(0,Le.rotateVec3)(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?ml:c===y?pl:dl}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=Tr(t?.polygons??[])*r,M=T/an,R=fl(y.color,m);if(y.kind==="arrow"){let _=e.camera.state,j=Er(y.cssAxis,y.sign,_.rotX??65,_.rotY??45);return(0,Le.arrowPolygons)({axis:mt[y.cssAxis],sign:y.sign,shaftLength:M,shaftHalfThickness:M*sl,headLength:M*il,headHalfThickness:M*al,color:R,shaft:!j})}if(y.kind==="plane"){let _=e.camera.state,j=_.rotX??65,Q=_.rotY??45,ae=mt[y.perpAxis],xe=(ae+1)%3,ge=(ae+2)%3,be=mt[xe],Re=mt[ge],Te=Er(be,1,j,Q)?-1:1,De=Er(Re,1,j,Q)?-1:1,Qe=M*ul;return(0,Le.planePolygons)({axis:ae,size:M*cl,offset:[Te*Qe,De*Qe],color:R})}let re=T*ll/an*Cr;return(0,Le.ringQuadPolygons)({axis:mt[y.cssAxis],outerRadius:re,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=ii.map(p=>({kind:"arrow",key:p.key,cssAxis:p.cssAxis,sign:p.sign,color:p.color})),m=li.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"?ai.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 re=(1-si)/Cr,_=(1+si)/Cr;R.element.style.setProperty("--ring-inner-ratio",`${re}`),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=hl(y.polygons),C(),g()}function I(){z(null)}function Z(y){y!==o&&(o=y,t&&(C(),g()))}function K(y,m,p){if(!t||!O)return;let T=p[y.cssAxis],M=mt[y.cssAxis],R=m*T/an,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 li){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&&sn(R.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),O=(t.transform.position??[0,0,0]).slice(),yl({axisA:p.axisA,axisB:p.axisB,probeDistanceCss:Tr(t.polygons)*r,wrapper:R.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,translationSnap:s.translationSnap??null,onPlaneDelta:(L,re,_,j)=>{if(!t||!O)return;let Q=_[p.axisA],ae=j[p.axisB],xe=mt[p.axisA],ge=mt[p.axisB],be=O.slice();be[xe]+=L*Q/an,be[ge]+=re*ae/an,t.setTransform({position:be}),D(),s.onObjectChange?.({object:t,position:be}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:L=>{L||(l=null,O=null,h()),s.onDraggingChanged?.(L)}});return}}for(let p of ii){let T=p.key.replace("-","")[0];if(!m[T])continue;let M=i.get(p.key);if(M&&sn(M.handle.element,y.clientX,y.clientY)){y.preventDefault(),y.stopPropagation(),l=p.key,h(),O=(t.transform.position??[0,0,0]).slice(),gl({cssAxis:p.cssAxis,sign:p.sign,shaftLengthCss:Tr(t.polygons)*r,wrapper:M.handle.element,target:t,startClientX:y.clientX,startClientY:y.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(R,L)=>K(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 ai){if(!m[p.key])continue;let T=i.get(p.key);if(T&&sn(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(),bl({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=mt[p.cssAxis],L=[0,0,0];L[R]=1;let re=-M*Math.PI/180,_=(0,Le.quatFromEulerXYZ)(H),j=(0,Le.quatFromAxisAngle)(L,re),Q=(0,Le.eulerXYZFromQuat)((0,Le.quatMultiply)(j,_)),ae=typeof t.transform.scale=="number"?t.transform.scale:t.transform.scale?.[0]??1,xe=(0,Le.rotateVec3)(u,H[0],H[1],H[2]),ge=(0,Le.rotateVec3)(u,Q[0],Q[1],Q[2]),be=[O[0]+ae*(xe[0]-ge[0]),O[1]+ae*(xe[1]-ge[1]),O[2]+ae*(xe[2]-ge[2])];t.setTransform({rotation:Q,position:be}),D(),s.onObjectChange?.({object:t,rotation:Q,position:be}),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(sn(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 vl=typeof HTMLElement<"u"?HTMLElement:class{},xl=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function qe(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Pl(e){return e==="false"?!1:qe(e)}function Ar(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 Sl(e){if(e==="baked"||e==="dynamic")return e}function Cl(e){return e==="auto"?"auto":qe(e)}function El(e){return typeof e.getCamera=="function"}var He=class extends vl{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...xl]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(El(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=Pl(this.getAttribute("perspective")),o=qe(this.getAttribute("rot-x")),r=qe(this.getAttribute("rot-y")),s=qe(this.getAttribute("zoom")),i=qe(this.getAttribute("distance")),c=Ar(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?Tt(l):t!==void 0?tn({...l,perspective:t}):Tt(l)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={};r.textureLighting=Sl(this.getAttribute("texture-lighting"))??"baked";let s=Cl(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=Ar(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=qe(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=qe(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=qn(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=qe(this.getAttribute("rot-x")),c=qe(this.getAttribute("rot-y")),l=qe(this.getAttribute("zoom")),u=qe(this.getAttribute("distance")),d=Ar(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())}}};var co=require("@layoutit/polycss-core"),Tl=typeof HTMLElement<"u"?HTMLElement:class{},Al=["src","mtl","mesh-resolution","position","scale","rotation","auto-center","cast-shadow","receive-shadow","target-size","default-color","palette","include-objects","exclude-objects"];function An(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function ui(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return An(e)}}function wr(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 wl(e){let n=e.getAttribute("target-size"),t=e.getAttribute("default-color"),o=wr(e.getAttribute("palette")),r=wr(e.getAttribute("include-objects")),s=wr(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 Ml(e){return e.closest("poly-scene")??null}function Ll(e){if(e.length===0)return e;let n=(0,co.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s),...i.textureTriangles?.length?{textureTriangles:i.textureTriangles.map(c=>({...c,vertices:c.vertices.map(s)}))}:null}))}var ln=class extends Tl{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Al]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"||t==="mesh-resolution"||t==="target-size"||t==="default-color"||t==="palette"||t==="include-objects"||t==="exclude-objects"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:An(this.getAttribute("position")),scale:ui(this.getAttribute("scale")),rotation:An(this.getAttribute("rotation")),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")})}}_tearDown(){if(this._loadToken+=1,this._handle){try{this._handle.dispose()}catch{}this._handle=null}this._parseResult=null}async _maybeLoad(){let t=this.getAttribute("src");if(!t)return;let o=Ml(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,l=wl(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(0,co.loadMesh)(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:Ll(u.polygons)}),this._parseResult=u,this._handle=d.add(u,{position:An(this.getAttribute("position")),scale:ui(this.getAttribute("scale")),rotation:An(this.getAttribute("rotation")),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow")}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var cn=require("@layoutit/polycss-core"),_l=typeof HTMLElement<"u"?HTMLElement:class{},Rl=["src","width","height","position","rotation","scale","allow","loading","referrerpolicy","sandbox","title"];function Mr(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 kl(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Mr(e)}}function di(e,n){if(e===null)return n;let t=parseFloat(e);return Number.isFinite(t)?t:n}function Ol(e){let n=e.closest("poly-scene");return n?n.querySelector(".polycss-scene"):null}function Dl(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)*cn.BASE_TILE,x=(e?.[0]??0)*cn.BASE_TILE,h=(e?.[2]??0)*cn.BASE_TILE,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 uo=class extends _l{constructor(){super(...arguments);this._wrapper=null;this._iframe=null}static get observedAttributes(){return[...Rl]}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=Ol(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=di(this.getAttribute("width"),16),o=di(this.getAttribute("height"),9),r=t*cn.BASE_TILE,s=o*cn.BASE_TILE;this._iframe.style.width=`${r}px`,this._iframe.style.height=`${s}px`;let i=Mr(this.getAttribute("position")),c=Mr(this.getAttribute("rotation")),l=kl(this.getAttribute("scale"));this._wrapper.style.transform=Dl(i,c,l,r,s)}_teardown(){this._wrapper?.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null,this._iframe=null}};var Il=typeof HTMLElement<"u"?HTMLElement:class{},Hl=["vertices","color","texture","uvs","position","scale","rotation"];function pi(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Lr(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 Fl(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Lr(e)}}function Vl(e){return e.closest("poly-scene")??null}var po=class extends Il{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Hl]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=Vl(this);if(!t)return;let o=t.getScene();if(!o)return;let r=pi(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=pi(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:Lr(this.getAttribute("position")),scale:Fl(this.getAttribute("scale")),rotation:Lr(this.getAttribute("rotation"))})}};function oe(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function mo(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Oe(e){if(e!==null)return!(e==="false"||e==="0")}function fo(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 ho(e){if(e==="x"||e==="y")return e}var Bl=typeof HTMLElement<"u"?HTMLElement:class{},zl=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],go=class extends Bl{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...zl]}getControls(){return this._controls}_readAnimate(){let t=oe(this.getAttribute("animate-speed")),o=ho(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:Oe(r)}:{}}}_readOptions(){let t={},o=Oe(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Oe(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=oe(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=oe(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=fo(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=oe(this.getAttribute("zoom-min")),u=oe(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 He)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=eo(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 Nl=typeof HTMLElement<"u"?HTMLElement:class{},$l=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],yo=class extends Nl{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...$l]}_readAnimate(){let t=oe(this.getAttribute("animate-speed")),o=ho(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:Oe(r)}:{}}}_readOptions(){let t={},o=Oe(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=Oe(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=oe(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=oe(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=fo(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=oe(this.getAttribute("zoom-min")),u=oe(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 He)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=to(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 Ul=typeof HTMLElement<"u"?HTMLElement:class{},Gl=["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"],bo=class extends Ul{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Gl]}_readOptions(){let t={},o=Oe(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let r=Oe(this.getAttribute("look-enabled"));r!==void 0&&(t.lookEnabled=r);let s=Oe(this.getAttribute("move-enabled"));s!==void 0&&(t.moveEnabled=s);let i=Oe(this.getAttribute("jump-enabled"));i!==void 0&&(t.jumpEnabled=i);let c=Oe(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let l=oe(this.getAttribute("look-sensitivity"));if(l!==void 0&&(t.lookSensitivity=l),this.hasAttribute("invert-y")){let C=Oe(this.getAttribute("invert-y"));C!==void 0&&(t.invertY=C)}let u=oe(this.getAttribute("move-speed"));u!==void 0&&(t.moveSpeed=u);let d=oe(this.getAttribute("jump-velocity"));d!==void 0&&(t.jumpVelocity=d);let x=oe(this.getAttribute("gravity"));x!==void 0&&(t.gravity=x);let h=oe(this.getAttribute("eye-height"));h!==void 0&&(t.eyeHeight=h);let b=oe(this.getAttribute("crouch-height"));b!==void 0&&(t.crouchHeight=b);let v=oe(this.getAttribute("ground-z"));v!==void 0&&(t.groundZ=v);let P=oe(this.getAttribute("min-pitch"));P!==void 0&&(t.minPitch=P);let g=oe(this.getAttribute("max-pitch"));return g!==void 0&&(t.maxPitch=g),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof He)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=no(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 jl=typeof HTMLElement<"u"?HTMLElement:class{},Wl=["perspective","zoom","rot-x","rot-y","target","distance"],vo=class extends jl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Wl]}getCamera(){return this._camera}_readOptions(){return{perspective:oe(this.getAttribute("perspective")),zoom:oe(this.getAttribute("zoom")),rotX:oe(this.getAttribute("rot-x")),rotY:oe(this.getAttribute("rot-y")),target:mo(this.getAttribute("target")),distance:oe(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=tn(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 Yl=typeof HTMLElement<"u"?HTMLElement:class{},Xl=["zoom","rot-x","rot-y","target","distance"],un=class extends Yl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Xl]}getCamera(){return this._camera}_readOptions(){return{zoom:oe(this.getAttribute("zoom")),rotX:oe(this.getAttribute("rot-x")),rotY:oe(this.getAttribute("rot-y")),target:mo(this.getAttribute("target")),distance:oe(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Tt(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 xo=class extends un{};var Zl=typeof HTMLElement<"u"?HTMLElement:class{},ql=["mode","target","size","enabled"];function mi(e){if(e==="translate"||e==="rotate")return e}var Po=class extends Zl{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...ql]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof He)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 ln?r:null}_readOptions(){let t={},o=mi(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=oe(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=lo(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=mi(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};var Ql=typeof HTMLElement<"u"?HTMLElement:class{},Kl=["multiple","clear-on-miss"],So=class extends Ql{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...Kl]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof He)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=oo(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 _r={quad:0,clippedSolid:0,atlas:0,stableTriangle:0},Jl={polygonCount:0,mountedPolygonLeafCount:0,shadowLeafCount:0,surfaceLeafCounts:_r,bucketCount:0};function ec(e){return typeof e=="number"?{polygonCount:e}:e??{}}function dn(e,n){return e.querySelectorAll(n).length}function tc(e,n){let t=e;return typeof t.matches=="function"&&t.matches(n)}function nc(e,n){if(!n)return[e];let t=[];return tc(e,n)&&t.push(e),t.push(...Array.from(e.querySelectorAll(n))),t}function fi(e,n){let t=ec(n);if(!e)return{...Jl,surfaceLeafCounts:{..._r},polygonCount:t.polygonCount??0};let o=nc(e,t.scopeSelector),r={..._r},s=0,i=0;for(let l of o)r.quad+=dn(l,"b"),r.clippedSolid+=dn(l,"i"),r.atlas+=dn(l,"s"),r.stableTriangle+=dn(l,"u"),s+=dn(l,"q, .polycss-shadow-svg"),i+=dn(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 At=class extends Error{constructor(n,t,o){super(t),this.name="PolySceneSnapshotError",this.code=n,this.url=o,Object.setPrototypeOf(this,new.target.prototype)}},oc=`
|
|
520
|
+
html,
|
|
521
|
+
body {
|
|
522
|
+
width: 100%;
|
|
523
|
+
height: 100%;
|
|
524
|
+
margin: 0;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
body {
|
|
528
|
+
position: relative;
|
|
529
|
+
overflow: hidden;
|
|
530
|
+
}
|
|
531
|
+
`,Rr=["b","i","s","u"],rc=["b","i","u"],sc=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--pnx","--pny","--pnz","--psr","--psg","--psb","--plam","--polycss-light-preview-active","--polycss-preview-r","--polycss-preview-g","--polycss-preview-b"],ic=["--clx","--cly","--clz","--shadow-ground-cssz"],ac=["--polycss-atlas-size","--polycss-atlas-url","--polycss-atlas-position","--polycss-atlas-image-size"];function lc(e){return!!e&&typeof e.querySelector=="function"&&typeof e.cloneNode=="function"}function cc(e){let n=e.closest(".polycss-camera");if(n)return n;let t=e.closest(".polycss-scene");return t?t.closest(".polycss-camera")??t:e.querySelector(".polycss-camera")??e.querySelector(".polycss-scene")}function Mn(e){return[e,...Array.from(e.querySelectorAll("*"))]}function ft(e,n){return e.matches(n)||!!e.querySelector(n)}function hi(e,n){return e.tagName.toLowerCase()===n||!!e.querySelector(n)}function uc(e){let n=Rr.filter(o=>hi(e,o)),t=rc.filter(o=>n.includes(o));return{hasCamera:ft(e,".polycss-camera"),hasScene:ft(e,".polycss-scene"),hasMesh:ft(e,".polycss-mesh"),hasFpvHost:ft(e,".polycss-fpv-host"),hasBucket:ft(e,".polycss-bucket"),hasVoxelMesh:ft(e,".polycss-voxel-mesh"),hasTransformGizmo:ft(e,".polycss-transform-gizmo"),hasTransformRing:ft(e,".polycss-transform-ring"),hasDynamicLighting:ft(e,'.polycss-scene[data-polycss-lighting="dynamic"]'),hasQ:hi(e,"q"),leafTags:n,solidLeafTags:t}}function wn(e,n=".polycss-scene "){return e.map(t=>`${n}${t}`).join(`,
|
|
532
|
+
`)}function dc(e){return e.map(n=>`.polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > ${n}`).join(`,
|
|
533
|
+
`)}function pc(e){let n=['@property --plx { syntax: "<number>"; inherits: true; initial-value: 0; }','@property --ply { syntax: "<number>"; inherits: true; initial-value: 0; }','@property --plz { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --plr { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --plg { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --plb { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --pli { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --par { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --pag { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --pab { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --pai { syntax: "<number>"; inherits: true; initial-value: 0.4; }','@property --pnx { syntax: "<number>"; inherits: true; initial-value: 0; }','@property --pny { syntax: "<number>"; inherits: true; initial-value: 0; }','@property --pnz { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --psr { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --psg { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --psb { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --plam { syntax: "<number>"; inherits: true; initial-value: 0; }'];return e&&n.push('@property --clx { syntax: "<number>"; inherits: true; initial-value: 0.01; }','@property --cly { syntax: "<number>"; inherits: true; initial-value: 0; }','@property --clz { syntax: "<number>"; inherits: true; initial-value: 1; }','@property --shadow-ground-cssz { syntax: "<number>"; inherits: true; initial-value: 0; }'),n.join(`
|
|
534
|
+
`)}function mc(e){let n=[pc(e.hasQ)];return e.hasBucket&&n.push(`
|
|
535
|
+
.polycss-scene[data-polycss-lighting="dynamic"] .polycss-bucket {
|
|
536
|
+
--plam: max(0, calc(
|
|
537
|
+
var(--pnx) * var(--plx) +
|
|
538
|
+
var(--pny) * var(--ply) +
|
|
539
|
+
var(--pnz) * var(--plz)
|
|
540
|
+
));
|
|
541
|
+
}
|
|
542
|
+
`),e.leafTags.length>0&&n.push(`
|
|
543
|
+
${dc(e.leafTags)} {
|
|
544
|
+
--plam: max(0, calc(
|
|
545
|
+
var(--pnx) * var(--plx) +
|
|
546
|
+
var(--pny) * var(--ply) +
|
|
547
|
+
var(--pnz) * var(--plz)
|
|
548
|
+
));
|
|
549
|
+
}
|
|
550
|
+
`),e.leafTags.includes("s")&&n.push(`
|
|
551
|
+
.polycss-scene[data-polycss-lighting="dynamic"] s {
|
|
552
|
+
contain: strict;
|
|
553
|
+
background-color: rgb(
|
|
554
|
+
calc(255 * (var(--par) * var(--pai)
|
|
555
|
+
+ var(--plr) * var(--pli) * var(--plam)))
|
|
556
|
+
calc(255 * (var(--pag) * var(--pai)
|
|
557
|
+
+ var(--plg) * var(--pli) * var(--plam)))
|
|
558
|
+
calc(255 * (var(--pab) * var(--pai)
|
|
559
|
+
+ var(--plb) * var(--pli) * var(--plam)))
|
|
560
|
+
);
|
|
561
|
+
background-blend-mode: multiply;
|
|
562
|
+
background-image: var(--polycss-atlas-url);
|
|
563
|
+
background-position: var(--polycss-atlas-position);
|
|
564
|
+
background-repeat: no-repeat;
|
|
565
|
+
background-size: var(--polycss-atlas-image-size);
|
|
566
|
+
mask-image: var(--polycss-atlas-url);
|
|
567
|
+
mask-mode: alpha;
|
|
568
|
+
mask-position: var(--polycss-atlas-position);
|
|
569
|
+
mask-repeat: no-repeat;
|
|
570
|
+
mask-size: var(--polycss-atlas-image-size);
|
|
571
|
+
-webkit-mask-image: var(--polycss-atlas-url);
|
|
572
|
+
-webkit-mask-position: var(--polycss-atlas-position);
|
|
573
|
+
-webkit-mask-repeat: no-repeat;
|
|
574
|
+
-webkit-mask-size: var(--polycss-atlas-image-size);
|
|
575
|
+
}
|
|
576
|
+
`),e.solidLeafTags.length>0&&n.push(`
|
|
577
|
+
${wn(e.solidLeafTags)} {
|
|
578
|
+
color: rgb(
|
|
579
|
+
calc(255 * var(--psr) * (var(--par) * var(--pai)
|
|
580
|
+
+ var(--plr) * var(--pli) * var(--plam)))
|
|
581
|
+
calc(255 * var(--psg) * (var(--pag) * var(--pai)
|
|
582
|
+
+ var(--plg) * var(--pli) * var(--plam)))
|
|
583
|
+
calc(255 * var(--psb) * (var(--pab) * var(--pai)
|
|
584
|
+
+ var(--plb) * var(--pli) * var(--plam)))
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
`),e.hasQ&&n.push(`
|
|
588
|
+
.polycss-scene[data-polycss-lighting="dynamic"] {
|
|
589
|
+
--shadow-proj: matrix3d(
|
|
590
|
+
1, 0, 0, 0,
|
|
591
|
+
0, 1, 0, 0,
|
|
592
|
+
calc(-1 * var(--clx) / var(--clz)),
|
|
593
|
+
calc(-1 * var(--cly) / var(--clz)),
|
|
594
|
+
0.01,
|
|
595
|
+
0,
|
|
596
|
+
calc(var(--shadow-ground-cssz) * var(--clx) / var(--clz)),
|
|
597
|
+
calc(var(--shadow-ground-cssz) * var(--cly) / var(--clz)),
|
|
598
|
+
calc(var(--shadow-ground-cssz) * 0.99),
|
|
599
|
+
1
|
|
600
|
+
);
|
|
601
|
+
}
|
|
435
602
|
|
|
436
|
-
Scoped to dynamic mode: baked-mode shadow leaves are dropped from the
|
|
437
|
-
DOM up-front by isBakedShadowCaster() and don't carry --pnx/--pny/--pnz,
|
|
438
|
-
so an unscoped gate would silently zero them via the @property
|
|
439
|
-
initial values. The base layout / positioning / pseudo-element-strip
|
|
440
|
-
rules for <q> live in the polygon-leaf section above. */
|
|
441
603
|
.polycss-scene[data-polycss-lighting="dynamic"] q {
|
|
442
604
|
opacity: clamp(0, calc((var(--pnx) * var(--clx) + var(--pny) * var(--cly) + var(--pnz) * var(--clz)) * 10), 1);
|
|
443
605
|
}
|
|
444
|
-
`;var ra=750;function pi(e){return!Object.prototype.hasOwnProperty.call(e,"seamBleed")||e.seamBleed!==void 0?e:{...e,seamBleed:X.DEFAULT_SEAM_BLEED}}var ia=1,tt=X.BASE_TILE,sa=Symbol.for("polycss.animation.triangleFrameTarget"),aa={key:"non-cullable",normal:[1,1,0]};function mi(){return[aa]}function la(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 ca(e,n){return e===n?!0:!e||!n?!1:e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2]}function ua(e,n){return e===n?!0:(e?.color??"#000000")===(n?.color??"#000000")&&(e?.opacity??.25)===(n?.opacity??.25)&&(e?.lift??.05)===(n?.lift??.05)&&(e?.maxExtend??2e3)===(n?.maxExtend??2e3)}function fi(e){let n=[];return e.position&&n.push(`translate3d(${e.position[0]}px, ${e.position[1]}px, ${e.position[2]}px)`),e.scale!==void 0&&(typeof e.scale=="number"?e.scale!==1&&n.push(`scale3d(${e.scale}, ${e.scale}, ${e.scale})`):n.push(`scale3d(${e.scale[0]}, ${e.scale[1]}, ${e.scale[2]})`)),e.rotation&&(e.rotation[0]&&n.push(`rotateX(${e.rotation[0]}deg)`),e.rotation[1]&&n.push(`rotateY(${e.rotation[1]}deg)`),e.rotation[2]&&n.push(`rotateZ(${e.rotation[2]}deg)`)),n.length>0?n.join(" "):void 0}function gi(e,n=[0,0,0],t=1){let o=e.state,r=o.rotX,i=o.rotY,s=(o.zoom??ia)*t,c=(o.distance??0)*t,l=o.target??[0,0,0],p=l[0]+n[0],m=l[1]+n[1],b=l[2]+n[2],y=m*tt,P=p*tt,h=b*tt;return`${c!==0?`translateZ(${-c}px) `:""}scale(${s}) rotateX(${r}deg) rotate(${i}deg) translate3d(${-y}px, ${-P}px, ${-h}px)`}function da(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 pa(e){let n=e.ownerDocument?.defaultView;if(!n)return 1;let t=1;for(let o=e;o;o=o.parentElement)t*=da(n.getComputedStyle(o).getPropertyValue("zoom"));return Number.isFinite(t)&&t>0?t:1}function yi(e,n){return n===1?e:e*n}function ma(e,n){Math.abs(n-1)<1e-6?e.style.removeProperty("zoom"):e.style.setProperty("zoom",String(1/n))}var fa=.1;function ga(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=0,o=0,r=0;for(let b=1;b+1<e.vertices.length;b++){let y=e.vertices[b],P=e.vertices[b+1],h=y[1]-n[1],v=y[0]-n[0],f=y[2]-n[2],C=P[1]-n[1],R=P[0]-n[0],k=P[2]-n[2];t-=v*k-f*R,o-=f*C-h*k,r-=h*R-v*C}let i=Math.hypot(t,o,r);if(i<1e-9)return null;t/=i,o/=i,r/=i;let s=1/fa,c=Math.round(t*s)/s,l=Math.round(o*s)/s,p=Math.round(r*s)/s,m=Math.hypot(c,l,p);return m<1e-9?null:{key:c+","+l+","+p,vec:[c/m,l/m,p/m]}}function Qn(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&&Zn(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let{camera:o,...r}=n,i=pi({seamBleed:X.DEFAULT_SEAM_BLEED,...r}),s=pa(e),c=[0,0,0],l=e.ownerDocument??document,p=l.createElement("div");p.className="polycss-camera",z(p,i),e.appendChild(p);let m=l.createElement("div");m.className="polycss-scene",m.setAttribute("aria-hidden","true"),F(m,i),p.appendChild(m);let b=new Set,y=null,P=[];function h(){for(let a of P)a.parentNode&&a.parentNode.removeChild(a);P.length=0,k()}let v=new Map,f=new Map;function C(a){for(let d of a)d.svg&&d.svg.parentNode&&d.svg.parentNode.removeChild(d.svg),d.svg=null,d.path=null}function R(a){if(a){let d=v.get(a);d&&C(d),v.delete(a),f.delete(a)}else{for(let d of v.values())C(d);v.clear(),f.clear()}}function k(){for(let a of v.values())for(let d of a)d.svg&&d.visible&&(d.svg.style.display="none",d.visible=!1)}let N=new Map,O=new Map;function ee(a){a?(N.delete(a),O.delete(a)):(N.clear(),O.clear())}function z(a,d){let S=t.perspectiveStyle;if(S==="none")a.style.perspective=`${yi(1e6,s)}px`;else{let E=parseFloat(S);Number.isFinite(E)&&(a.style.perspective=`${yi(E,s)}px`)}}function F(a,d){ma(a,s),a.style.transform=gi(t,c,s),U(a,d)}function $(a){a.style.transform=gi(t,c,s)}function U(a,d){let S=d.textureLighting==="dynamic";a.dataset.polycssLighting=d.textureLighting??"baked";let E=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai","--clx","--cly","--clz"];if(!S){for(let Ae of E)a.style.removeProperty(Ae);return}let I=d.directionalLight?.direction??[.4,-.7,.59],V=Math.hypot(I[0],I[1],I[2])||1,H=I[0]/V,J=I[1]/V,Y=I[2]/V,B=(0,X.parseHexColor)(d.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],ne=(0,X.parseHexColor)(d.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],j=d.directionalLight?.intensity??1,x=d.ambientLight?.intensity??.4,te=Ae=>(Ae/255).toFixed(4);a.style.setProperty("--plx",H.toFixed(4)),a.style.setProperty("--ply",J.toFixed(4)),a.style.setProperty("--plz",Y.toFixed(4)),a.style.setProperty("--plr",te(B[0])),a.style.setProperty("--plg",te(B[1])),a.style.setProperty("--plb",te(B[2])),a.style.setProperty("--pli",j.toFixed(4)),a.style.setProperty("--par",te(ne[0])),a.style.setProperty("--pag",te(ne[1])),a.style.setProperty("--pab",te(ne[2])),a.style.setProperty("--pai",x.toFixed(4));let Le=Y,Re=Math.sign(Le||1)*Math.max(Math.abs(Le),.01);a.style.setProperty("--clx",H.toFixed(4)),a.style.setProperty("--cly",J.toFixed(4)),a.style.setProperty("--clz",Re.toFixed(4))}function ae(a){a.voxelRenderer?.dispose(),a.voxelRenderer=void 0,T(a.rendered,a.disposeAtlas),a.disposeAtlas=void 0,a.rendered.length=0,a.renderedByPolygonIndex=[],a.cameraCullGroups=[],a.cameraCullSignature="",g(a);for(let d of Array.from(a.wrapper.children))d instanceof HTMLElement&&d.classList.contains("polycss-bucket")&&d.remove();a.hasBuckets=!1}function Ee(a){for(let d of Array.from(a.wrapper.childNodes)){if(!(d instanceof HTMLElement))return d;if(d.classList.contains("polycss-bucket")||d.classList.contains("polycss-shadow"))continue;let S=d.tagName.toLowerCase();if(!(S==="b"||S==="i"||S==="s"||S==="u"||S==="q"))return d}return null}function u(a,d,S){S?.parentNode===a.wrapper?a.wrapper.insertBefore(d,S):a.wrapper.appendChild(d)}function g(a){for(let d of a.shadowRendered)d.parentNode&&d.parentNode.removeChild(d);a.shadowRendered.length=0,h()}function T(a,d){d?.();for(let S of a){try{S.dispose()}catch{}S.element.parentNode&&S.element.parentNode.removeChild(S.element)}}function A(a,d,S){a.rendered=d,a.renderedByPolygonIndex=[];for(let E of d)a.renderedByPolygonIndex[E.polygonIndex]=E;a.disposeAtlas=S}function L(a,d){let S=a.renderedByPolygonIndex[d];return S?.polygonIndex===d?S:void 0}function M(a){for(let d of Array.from(a.wrapper.children))d instanceof HTMLElement&&d.classList.contains("polycss-bucket")&&d.remove();a.hasBuckets=!1;for(let d of a.rendered)d.element.parentNode&&d.element.parentNode.removeChild(d.element)}function le(a,d){let S=a.polygons[d.polygonIndex];return a.stableDom&&S?(0,X.polygonCssSurfaceNormal)(S):d.plan?.normal??(S?(0,X.polygonCssSurfaceNormal)(S):null)}function xe(a){if(!Oe(a))return a.rendered;let d=_(a);return a.rendered.filter(S=>re(a,S,X.CAMERA_BACKFACE_CULL_EPS,d))}function _(a){return{rotX:t.state.rotX,rotY:t.state.rotY,meshRotation:a.handle.transform.rotation}}function re(a,d,S=X.CAMERA_BACKFACE_CULL_EPS,E=_(a)){let I=le(a,d);return I===null||(0,X.normalFacesCamera)(I,E,S)}function ie(a){if(a.excludeFromAutoCenter){a.cameraCullGroups=[];return}let d=new Map;for(let S of a.rendered){let E=le(a,S);if(!E)continue;if(!(0,X.isAxisAlignedSurfaceNormal)(E)){a.cameraCullGroups=mi();return}let I=(0,X.cameraCullNormalKey)(E);if(!d.has(I)&&(d.set(I,E),d.size>X.VOXEL_CAMERA_CULL_NORMAL_LIMIT)){a.cameraCullGroups=mi();return}}a.cameraCullGroups=Array.from(d,([S,E])=>({key:S,normal:E}))}function Me(a){return Oe(a)?(0,X.cameraCullVisibleSignature)(a.cameraCullGroups,_(a)):"all"}function Oe(a){return!a.excludeFromAutoCenter&&(0,X.isVoxelCameraCullableNormalGroups)(a.cameraCullGroups)}function ze(a){a.cameraCullSignature=Oe(a)?Me(a):"all"}function Ge(a,d){let S=new Array(a.rendered.length),E=!1,I=_(a);for(let j=0;j<a.rendered.length;j+=1){let x=a.rendered[j],te=re(a,x,d,I);S[j]=te}let V=null,H=null,J=()=>{if(!(!V||!H)){if(V===H)V.remove();else{let j=l.createRange();j.setStartBefore(V),j.setEndAfter(H),j.deleteContents(),j.detach()}V=null,H=null,E=!0}};for(let j=0;j<a.rendered.length;j+=1){let x=a.rendered[j];!S[j]&&x.element.parentNode===a.wrapper?(H&&H.nextSibling===x.element||(J(),V=x.element),H=x.element):J()}J();let Y=j=>{for(let x=j;x<a.rendered.length;x+=1){let te=a.rendered[x].element;if(te.parentNode===a.wrapper)return te}return Ee(a)},B=-1,ne=j=>{if(B<0)return;let x=l.createDocumentFragment();for(let te=B;te<j;te+=1){let Le=a.rendered[te];Xe(a,Le),x.appendChild(Le.element)}u(a,x,Y(j)),B=-1,E=!0};for(let j=0;j<a.rendered.length;j+=1){let x=a.rendered[j];S[j]&&x.element.parentNode!==a.wrapper?B<0&&(B=j):ne(j)}return ne(a.rendered.length),E}function Ie(a,d=!1){if(a.voxelRenderer){d?a.voxelRenderer.render(_(a)):a.voxelRenderer.syncCamera(_(a)),a.cameraCullSignature="voxel-direct";return}if(!Oe(a)){let I=a.cameraCullSignature!=="all";a.cameraCullSignature="all",I&&Be(a);return}if(a.hasBuckets){Ye(a,d);return}let S=Me(a);if(!d&&S===a.cameraCullSignature)return;let E=Ge(a,X.CAMERA_BACKFACE_CULL_EPS);a.cameraCullSignature=S,E&&de(a)}function Ye(a,d=!1){let S=Oe(a)?Me(a):"all";!d&&S===a.cameraCullSignature||Be(a)}function ct(a,d){return le(a,d)}function Xe(a,d){if(i.textureLighting!=="dynamic")return;let S=ct(a,d);S&&(d.element.style.setProperty("--pnx",S[0].toFixed(4)),d.element.style.setProperty("--pny",S[1].toFixed(4)),d.element.style.setProperty("--pnz",S[2].toFixed(4)))}function et(a){M(a),a.hasBuckets=!1;let d=a.skipBucketNormalCleanupOnce;a.skipBucketNormalCleanupOnce=!1;let S=l.createDocumentFragment(),E=i.textureLighting==="dynamic"&&!a.stableDom,I=new Map,V=[];for(let H of xe(a)){let J=a.polygons[H.polygonIndex],Y=E&&J?ga(J):null;if(!Y){V.push(H);continue}let B=Y.key+"|"+(J.color??""),ne=I.get(B);ne||(ne={vec:Y.vec,items:[]},I.set(B,ne)),ne.items.push(H)}for(let H of V)Xe(a,H),S.appendChild(H.element);for(let H of I.values()){if(H.items.length<2){for(let Y of H.items)Xe(a,Y),S.appendChild(Y.element);continue}let J=l.createElement("div");J.className="polycss-bucket",a.hasBuckets=!0,J.style.setProperty("--pnx",String(H.vec[0])),J.style.setProperty("--pny",String(H.vec[1])),J.style.setProperty("--pnz",String(H.vec[2]));for(let Y of H.items)J.appendChild(Y.element),(!d||Y.kind==="triangle")&&(Y.element.style.removeProperty("--pnx"),Y.element.style.removeProperty("--pny"),Y.element.style.removeProperty("--pnz"));S.appendChild(J)}u(a,S,Ee(a)),ze(a)}function mn(){return new Promise(a=>setTimeout(a,0))}async function fn(a,d){if(i.textureLighting==="dynamic"&&!a.stableDom)return et(a),!d();M(a);let E=l.createDocumentFragment(),I=Ee(a),V=0;for(let H of xe(a)){if(d())return!1;Xe(a,H),E.appendChild(H.element),V++,V%ra===0&&(u(a,E,I),E=l.createDocumentFragment(),await mn())}return E.childNodes.length>0&&u(a,E,I),ze(a),!d()}function ht(a,d){let S=i.textureLighting==="dynamic",E=i.directionalLight?.direction,I=d&&(d[0]!==0||d[1]!==0||d[2]!==0);if(!S||!I||!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 V=(0,X.inverseRotateVec3)(E,d),H=Math.hypot(V[0],V[1],V[2])||1,J=(V[0]/H).toFixed(4),Y=(V[1]/H).toFixed(4),B=(V[2]/H).toFixed(4),ne=`${J}|${Y}|${B}`;a.lightOverrideSignature!==ne&&(a.wrapper.style.setProperty("--plx",J),a.wrapper.style.setProperty("--ply",Y),a.wrapper.style.setProperty("--plz",B),a.lightOverrideSignature=ne)}function kt(a,d){d.paintColor?a.style.setProperty("--polycss-paint",d.paintColor):a.style.getPropertyValue("--polycss-paint")&&a.style.removeProperty("--polycss-paint"),d.dynamicColor?(a.style.setProperty("--psr",(d.dynamicColor.r/255).toFixed(4)),a.style.setProperty("--psg",(d.dynamicColor.g/255).toFixed(4)),a.style.setProperty("--psb",(d.dynamicColor.b/255).toFixed(4))):(a.style.getPropertyValue("--psr")||a.style.getPropertyValue("--psg")||a.style.getPropertyValue("--psb"))&&(a.style.removeProperty("--psr"),a.style.removeProperty("--psg"),a.style.removeProperty("--psb"))}function Fo(a,d){let S=(0,X.parseHex)(d??"#cccccc");a.style.setProperty("--psr",(S.r/255).toFixed(4)),a.style.setProperty("--psg",(S.g/255).toFixed(4)),a.style.setProperty("--psb",(S.b/255).toFixed(4))}function Ho(a,d){if(!a.plan||a.kind==="atlas"||a.plan.texture)return!1;let S=i.textureLighting??"baked",E={directionalLight:i.directionalLight,ambientLight:i.ambientLight,textureLighting:S,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies},I=Zo(a.plan,d,a.plan.normal,S,E);return Qt(a.element,I,S),!0}function Io(a,d,S){let E=a.polygons[d];if(!E)return!1;let I=L(a,d);if(!I)return!1;let V=i.textureLighting??"baked";return V==="dynamic"?(Fo(I.element,S),!0):V==="baked"?Ho(I,E):!1}function G(a,d){let S=a.polygons[d];if(!S)return!1;let E=L(a,d);return E?(Ue(E.element,S),!0):!1}function be(a,d,S){return!(S.length===0||!S.every(E=>E==="color"||E==="data")||S.includes("color")&&!Io(a,d,a.polygons[d]?.color)||S.includes("data")&&!G(a,d))}function de(a){Fe()}function Fe(){h();let a=[];for(let B of b)!B.disposed&&B.castShadow&&a.push(B);if(a.length===0)return;let d=i.shadow?.color??"#000000",S=i.shadow?.opacity??.25,E=(0,X.parseHexColor)(d)?.rgb??[0,0,0],I=E[0],V=E[1],H=E[2],J=i.directionalLight?.direction??[.4,-.7,.59],Y=new Map;for(let B of a)Y.set(B,(0,X.findOverlappingPolygonDuplicates)(B.polygons,{normalTolerance:.1,distanceTolerance:.5,overlapFraction:.4,preserveDoubleSidedBackfaces:!1}));y!==null&&gn(a,Y,J,y,I,V,H,S);for(let B of b)B.disposed||!B.receiveShadow||Ft(a,Y,B,J,I,V,H,S)}function gn(a,d,S,E,I,V,H,J){let Y=[],B=1/0,ne=1/0,j=-1/0,x=-1/0,te=1/0,Le=1/0,Re=-1/0,Ae=-1/0;for(let me of a){let fe=me.handle.transform.position??[0,0,0],he=d.get(me);for(let ut of me.rendered){if(he.has(ut.polygonIndex)||!ut.plan)continue;let hn=me.polygons[ut.polygonIndex];if(!hn)continue;let St=[];for(let Tt of hn.vertices){let De=[Tt[1]*tt+fe[0],Tt[0]*tt+fe[1],Tt[2]*tt+fe[2]];De[0]<te&&(te=De[0]),De[1]<Le&&(Le=De[1]),De[0]>Re&&(Re=De[0]),De[1]>Ae&&(Ae=De[1]);let He=(0,X.projectCssVertexToGround)(De,S,E);St.push(He),He[0]<B&&(B=He[0]),He[1]<ne&&(ne=He[1]),He[0]>j&&(j=He[0]),He[1]>x&&(x=He[1])}let je=St.length>3?(0,X.convexHull2D)(St):St;je.length>=3&&Y.push(je)}}if(Y.length===0)return;let ge=i.shadow?.maxExtend??2e3,Q=Math.max(B,te-ge),pe=Math.max(ne,Le-ge),oe=Math.min(j,Re+ge),w=Math.min(x,Ae+ge),D=oe-Q,q=w-pe;if(!(D>0)||!(q>0))return;let se="";for(let me of Y){let fe=(0,X.ensureCcw2D)(me);se+=`M${(fe[0][0]-Q).toFixed(3)},${(fe[0][1]-pe).toFixed(3)}`;for(let he=1;he<fe.length;he++)se+=`L${(fe[he][0]-Q).toFixed(3)},${(fe[he][1]-pe).toFixed(3)}`;se+="Z"}let ye="http://www.w3.org/2000/svg",W=l.createElementNS(ye,"svg");W.setAttribute("class","polycss-shadow polycss-shadow-svg"),W.setAttribute("width",String(D)),W.setAttribute("height",String(q)),W.setAttribute("viewBox",`0 0 ${D} ${q}`),W.setAttribute("style",`position:absolute;top:0;left:0;display:block;overflow:hidden;transform-origin:0 0;pointer-events:none;will-change:transform;transform:translate3d(${Q.toFixed(3)}px,${pe.toFixed(3)}px,${E.toFixed(3)}px)`);let K=l.createElementNS(ye,"path");K.setAttribute("d",se);let Pe=`rgb(${I},${V},${H})`;K.setAttribute("fill",Pe),K.setAttribute("fill-rule","nonzero"),K.setAttribute("stroke",Pe),K.setAttribute("stroke-width","2"),K.setAttribute("stroke-linejoin","round"),K.setAttribute("opacity",J.toFixed(4)),W.appendChild(K),P.push(W);let Ce=m.firstChild;Ce?m.insertBefore(W,Ce):m.appendChild(W)}function yn(a,d,S){let E=[];for(let Y of a.polygons){if(Y.vertices.length<3)continue;let B=S(Y.vertices[0],d),ne=S(Y.vertices[1],d),j=S(Y.vertices[2],d),x=[ne[0]-B[0],ne[1]-B[1],ne[2]-B[2]],te=[j[0]-B[0],j[1]-B[1],j[2]-B[2]],Le=te[1]*x[2]-te[2]*x[1],Re=te[2]*x[0]-te[0]*x[2],Ae=te[0]*x[1]-te[1]*x[0],ge=Math.hypot(Le,Re,Ae);if(ge<1e-9)continue;let Q=[Le/ge,Re/ge,Ae/ge],pe=Math.hypot(x[0],x[1],x[2]);if(pe<1e-9)continue;let oe=[x[0]/pe,x[1]/pe,x[2]/pe],w=[Q[1]*oe[2]-Q[2]*oe[1],Q[2]*oe[0]-Q[0]*oe[2],Q[0]*oe[1]-Q[1]*oe[0]],D=Q[0]*B[0]+Q[1]*B[1]+Q[2]*B[2];E.push({face:Y,O:B,n:Q,u:oe,v:w,offset:D})}let I=.001,V=.5,H=[];for(let Y of E){let B=!1;for(let ne of H){let j=ne.rep;if(!(1-(Y.n[0]*j.n[0]+Y.n[1]*j.n[1]+Y.n[2]*j.n[2])>I)&&!(Math.abs(Y.offset-j.offset)>V)){ne.faces.push(Y),B=!0;break}}B||H.push({rep:Y,faces:[Y]})}let J=[];for(let Y of H){let{O:B,n:ne,u:j,v:x}=Y.rep,te=[];for(let Re of Y.faces)for(let Ae of Re.face.vertices){let ge=S(Ae,d),Q=ge[0]-B[0],pe=ge[1]-B[1],oe=ge[2]-B[2];te.push([Q*j[0]+pe*j[1]+oe*j[2],Q*x[0]+pe*x[1]+oe*x[2]])}if(te.length<3)continue;let Le=(0,X.convexHull2D)(te);Le.length<3||J.push({O:B,n:ne,u:j,v:x,outlineUv:(0,X.ensureCcw2D)(Le)})}return J}function Ft(a,d,S,E,I,V,H,J){let Y=Math.hypot(E[0],E[1],E[2])||1,B=E[0]/Y,ne=E[1]/Y,j=E[2]/Y,x="http://www.w3.org/2000/svg",te=S.handle.transform.position??[0,0,0],Le=(Q,pe)=>[Q[1]*tt+pe[0],Q[0]*tt+pe[1],Q[2]*tt+pe[2]],Re=`${S.polygons.length}|${te.join(",")}`,Ae=v.get(S);(Ae===void 0||f.get(S)!==Re)&&(Ae=yn(S,te,Le).map(pe=>{let{O:oe,n:w,u:D,v:q,outlineUv:se}=pe,ye=1/0,W=1/0,K=-1/0,Pe=-1/0;for(let je of se)je[0]<ye&&(ye=je[0]),je[1]<W&&(W=je[1]),je[0]>K&&(K=je[0]),je[1]>Pe&&(Pe=je[1]);let Ce=K-ye,me=Pe-W,fe=5,he=oe[0]+ye*D[0]+W*q[0]+fe*w[0],ut=oe[1]+ye*D[1]+W*q[1]+fe*w[1],Ve=oe[2]+ye*D[2]+W*q[2]+fe*w[2],St=`matrix3d(${[D[0],D[1],D[2],0,q[0],q[1],q[2],0,w[0],w[1],w[2],0,he,ut,Ve,1].map(je=>je.toFixed(4)).join(",")})`;return{O:oe,n:w,u:D,v:q,outlineUv:se,minU:ye,minV:W,width:Ce,height:me,matrixCss:St,svg:null,path:null,visible:!1}}),v.set(S,Ae),f.set(S,Re));let ge=[];for(let Q of a){if(Q===S)continue;let pe=Q.handle.transform.position??[0,0,0],oe=`${Q.polygons.length}|${pe.join(",")}`,w=N.get(Q);if(w===void 0||O.get(Q)!==oe){let D=d.get(Q);w=[];for(let q of Q.rendered){if(D.has(q.polygonIndex)||!q.plan)continue;let ye=Q.polygons[q.polygonIndex];if(!ye)continue;let W=ye.vertices.map(Ve=>Le(Ve,pe)),K=1/0,Pe=1/0,Ce=1/0,me=-1/0,fe=-1/0,he=-1/0;for(let Ve of W)Ve[0]<K&&(K=Ve[0]),Ve[0]>me&&(me=Ve[0]),Ve[1]<Pe&&(Pe=Ve[1]),Ve[1]>fe&&(fe=Ve[1]),Ve[2]<Ce&&(Ce=Ve[2]),Ve[2]>he&&(he=Ve[2]);let ut=[[K,Pe,Ce],[me,Pe,Ce],[K,fe,Ce],[me,fe,Ce],[K,Pe,he],[me,Pe,he],[K,fe,he],[me,fe,he]];w.push({wv:W,bboxCorners:ut})}N.set(Q,w),O.set(Q,oe)}for(let D of w)ge.push(D)}for(let Q of Ae){let{O:pe,n:oe,u:w,v:D,outlineUv:q,minU:se,minV:ye,width:W,height:K,matrixCss:Pe}=Q,Ce=B*oe[0]+ne*oe[1]+j*oe[2];if(Ce<=1e-6)continue;let me=Se=>(Se[0]-pe[0])*oe[0]+(Se[1]-pe[1])*oe[1]+(Se[2]-pe[2])*oe[2],fe=(Se,rt,Ht,It)=>{let dt=Ht/(Ht-It);return[Se[0]+dt*(rt[0]-Se[0]),Se[1]+dt*(rt[1]-Se[1]),Se[2]+dt*(rt[2]-Se[2])]},he=Se=>{let rt=Se[0]-pe[0],Ht=Se[1]-pe[1],It=Se[2]-pe[2],dt=(rt*oe[0]+Ht*oe[1]+It*oe[2])/Ce,bn=Se[0]-dt*B,xn=Se[1]-dt*ne,Gt=Se[2]-dt*j,pt=bn-pe[0],Et=xn-pe[1],Qe=Gt-pe[2];return[pt*w[0]+Et*w[1]+Qe*w[2],pt*D[0]+Et*D[1]+Qe*D[2]]},ut=[],Ve=se,hn=ye,St=Q.minU+W,je=Q.minV+K;for(let Se of ge){let rt=Se.bboxCorners,Ht=!1,It=1/0,dt=1/0,bn=-1/0,xn=-1/0;for(let pt=0;pt<8;pt++){let Et=rt[pt];me(Et)>=0&&(Ht=!0);let Qe=he(Et);Qe[0]<It&&(It=Qe[0]),Qe[0]>bn&&(bn=Qe[0]),Qe[1]<dt&&(dt=Qe[1]),Qe[1]>xn&&(xn=Qe[1])}if(!Ht||bn<Ve||It>St||xn<hn||dt>je)continue;let Gt=Se.wv;for(let pt=1;pt<Gt.length-1;pt++){let Et=Gt[0],Qe=Gt[pt],Tr=Gt[pt+1],qi=me(Et),Ki=me(Qe),Ji=me(Tr),kn=[],Er=[[Et,qi],[Qe,Ki],[Tr,Ji]];for(let Fn=0;Fn<3;Fn++){let[Mr,No]=Er[Fn],[ns,Lr]=Er[(Fn+1)%3];No>=0&&kn.push(Mr),No>=0!=Lr>=0&&kn.push(fe(Mr,ns,No,Lr))}if(kn.length<3)continue;let es=kn.map(he),ts=(0,X.ensureCcw2D)(es),Ar=(0,X.clipPolygonToConvex2D)(ts,q);Ar.length<3||ut.push(Ar)}}if(ut.length===0||!(W>0)||!(K>0))continue;let Tt="";for(let Se of ut){Tt+=`M${(Se[0][0]-se).toFixed(1)},${(Se[0][1]-ye).toFixed(1)}`;for(let rt=1;rt<Se.length;rt++)Tt+=`L${(Se[rt][0]-se).toFixed(1)},${(Se[rt][1]-ye).toFixed(1)}`;Tt+="Z"}let De=Q.svg,He=Q.path;!De||!He?(De=l.createElementNS(x,"svg"),De.setAttribute("class","polycss-shadow polycss-shadow-svg polycss-shadow-receiver"),De.setAttribute("width",String(W)),De.setAttribute("height",String(K)),De.setAttribute("viewBox",`0 0 ${W} ${K}`),De.setAttribute("style",`position:absolute;top:0;left:0;display:block;overflow:hidden;transform-origin:0 0;pointer-events:none;will-change:transform;transform:${Pe}`),He=l.createElementNS(x,"path"),He.setAttribute("fill-rule","nonzero"),De.appendChild(He),m.insertBefore(De,m.firstChild),Q.svg=De,Q.path=He):Q.visible||(De.style.display="block"),Q.visible=!0,He.setAttribute("d",Tt);let Cr=`rgb(${I},${V},${H})`;He.getAttribute("fill")!==Cr&&He.setAttribute("fill",Cr);let Sr=J.toFixed(4);He.getAttribute("opacity")!==Sr&&He.setAttribute("opacity",Sr)}}function Be(a){if(a.voxelRenderer){a.voxelRenderer.render(_(a)),a.cameraCullSignature="voxel-direct";return}g(a),et(a),de(a)}function ot(a){return!!a.voxelSource&&i.textureLighting!=="dynamic"&&!a.stableDom&&!a.castShadow}function $e(a,d){ae(a);let S=i.directionalLight,E=d?{...S,direction:d}:S;if(ot(a)){let H=ui({doc:l,wrapper:a.wrapper,polygons:a.parseResult.polygons,directionalLight:E,ambientLight:i.ambientLight});if(H){a.voxelRenderer=H,H.render(_(a)),a.cameraCullSignature="voxel-direct";return}}let I={doc:l,directionalLight:E,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies},V=a.stableDom?(()=>{let H=_t(a.polygons,I);return kt(a.wrapper,H),Nt(a.polygons,{...I,solidPaintDefaults:H})??Ut(a.polygons,{...I,solidPaintDefaults:H})})():Ut(a.polygons,{...I,computeSolidPaintDefaults:!0,skipDynamicNormalVars:i.textureLighting==="dynamic"});a.stableDom||kt(a.wrapper,V.solidPaintDefaults??{}),A(a,V.rendered,V.dispose),a.skipBucketNormalCleanupOnce=i.textureLighting==="dynamic"&&!a.stableDom,ie(a),et(a),de(a)}function Ze(){let a=1/0,d=!1;for(let V of b)if(!V.disposed&&V.receiveShadow){d=!0;break}for(let V of b){if(V.disposed||!(d?V.receiveShadow:V.castShadow))continue;let J=V.handle.transform.position?.[2]??0;for(let Y of V.polygons)for(let B of Y.vertices){let ne=B[2]+J;ne<a&&(a=ne)}}if(!Number.isFinite(a)){let V=y!==null;y=null,V&&h();return}let S=i.shadow?.lift??.05,E=(a+S)*tt,I=y;y=E,I!==E&&Fe()}async function Vo(a,d){ae(a);let S={doc:l,directionalLight:i.directionalLight,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,strategies:i.strategies},E=a.stableDom?Nt(a.polygons,S):null;if(E){let H=_t(a.polygons,S);return kt(a.wrapper,H),A(a,E.rendered,E.dispose),ie(a),et(a),de(a),!d()}let I=await tn(a.polygons,{...S,skipDynamicNormalVars:i.textureLighting==="dynamic"},d);if(d())return I.dispose(),!1;kt(a.wrapper,I.solidPaintDefaults),A(a,I.rendered,I.dispose),a.skipBucketNormalCleanupOnce=i.textureLighting==="dynamic"&&!a.stableDom,ie(a);let V=await fn(a,d);return V&&de(a),V}function bt(){let a=c,d=[0,0,0];if(i.autoCenter){let S=[];for(let E of b)!E.disposed&&!E.excludeFromAutoCenter&&S.push(...E.polygons);if(S.length>0){let E=(0,X.computeSceneBbox)(S);d=[(E.min[0]+E.max[0])/2,(E.min[1]+E.max[1])/2,(E.min[2]+E.max[2])/2]}}a[0]===d[0]&&a[1]===d[1]&&a[2]===d[2]||(c=d,F(m,i))}function zo(a,d={}){let E=(m.ownerDocument??document).createElement("div");E.className="polycss-mesh",d.id&&E.setAttribute("data-poly-mesh-id",d.id);let I={...d},V=d.merge!==!1,H=!!d.stableDom,J=0,Y=fi(I);Y&&(E.style.transform=Y);let B=(w,D)=>a.voxelSource||!D?w:(0,X.optimizeMeshPolygons)(w,{meshResolution:d.meshResolution}),ne=B(a.polygons,V);function j(w){if(w.length===0){E.style.removeProperty("--origin");return}let D=1/0,q=1/0,se=1/0,ye=-1/0,W=-1/0,K=-1/0;for(let fe of w)for(let he of fe.vertices)he[0]<D&&(D=he[0]),he[0]>ye&&(ye=he[0]),he[1]<q&&(q=he[1]),he[1]>W&&(W=he[1]),he[2]<se&&(se=he[2]),he[2]>K&&(K=he[2]);if(!Number.isFinite(D)){E.style.removeProperty("--origin");return}let Pe=(q+W)/2*tt,Ce=(D+ye)/2*tt,me=(se+K)/2*tt;E.style.setProperty("--origin",`${Pe}px ${Ce}px ${me}px`)}j(ne),m.appendChild(E);let x={handle:void 0,wrapper:E,parseResult:a,rendered:[],renderedByPolygonIndex:[],shadowRendered:[],polygons:ne,voxelSource:a.voxelSource,disposed:!1,stableDom:H,hasBuckets:!1,skipBucketNormalCleanupOnce:!1,excludeFromAutoCenter:!!d.excludeFromAutoCenter,castShadow:!!d.castShadow,receiveShadow:!!d.receiveShadow,cameraCullGroups:[],cameraCullSignature:"",lightOverrideSignature:"clear",stableTriangleColorFrame:0,bakedRotation:d.rotation?[...d.rotation]:[0,0,0]},te=null,Le=0,Re=-1,Ae=null;function ge(){te=null,Ae=null,Re=-1}function Q(){let w=te;if(!w||w.polygonCount!==x.polygons.length)return x.polygons;if(Ae&&Re===Le)return Ae;let D=w.vertices,q=new Array(w.polygonCount);for(let se=0;se<w.polygonCount;se++){let ye=x.polygons[se],W=se*9;q[se]={...ye,color:w.colors?.[se]??ye.color,vertices:[[D[W],D[W+1],D[W+2]],[D[W+3],D[W+4],D[W+5]],[D[W+6],D[W+7],D[W+8]]]}}return Ae=q,Re=Le,q}function pe(w,D){let q=w?.stableTriangleUpdateMode==="color-only";x.stableTriangleColorFrame++;let se=x.stableDom&&!D;if(se||j(x.polygons),x.stableDom&&!x.hasBuckets){let ye={doc:l,directionalLight:i.directionalLight,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed},W=x.rendered.length===x.polygons.length&&x.rendered.every(me=>me.kind==="triangle"),K=x.stableDom&&!D,Pe=W||K?{}:_t(x.polygons,ye);W||kt(x.wrapper,Pe);let Ce={...ye,solidPaintDefaults:Pe,optimizeStableTriangleStyle:!0,stableTriangleDebug:w?.stableTriangleDebug,stableTriangleUpdateMode:w?.stableTriangleUpdateMode,stableTriangleColorPolicy:w?.stableTriangleColorPolicy,stableTriangleColorSteps:w?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:w?.stableTriangleColorFreezeFrames,stableTriangleColorBudget:w?.stableTriangleColorBudget,stableTriangleColorMaxAge:w?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:w?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:w?.stableTriangleMatrixDecimals,stableTriangleColorFrame:x.stableTriangleColorFrame};if(on(x.rendered,x.polygons,Ce))return q||(ie(x),Ie(x,!0),D&&bt()),!0}return se&&j(x.polygons),!1}let oe={get polygons(){return Q()},set polygons(w){ge(),x.polygons=w},element:E,id:d.id,get transform(){return I},remove(){J++,E.parentNode&&E.parentNode.removeChild(E),ae(x),b.delete(x),R(x),ee(x),bt(),Ze()},setPolygons(w,D){J++,V=D?.merge??V,H=D?.stableDom??H,x.stableDom=H,x.voxelSource=void 0,x.polygons=B(w,V),ee(x),R(x),ge(),oe.polygons=x.polygons;let q=D?.recomputeAutoCenter??!0;pe(D,q)||($e(x),q&&bt())},[sa](w,D){let q=D?.merge??V,se=D?.stableDom??H;if(!w.solidTriangles||!se||q||d.meshResolution!==void 0||x.hasBuckets||w.polygonCount!==x.polygons.length||w.vertices.length<w.polygonCount*9||x.rendered.length!==w.polygonCount)return!1;for(let K=0;K<x.rendered.length;K++){let Pe=x.rendered[K],Ce=x.polygons[K];if(Pe?.kind!=="triangle"||Pe.polygonIndex!==K||!Ce||Ce.vertices.length!==3||Ce.texture||Ce.material?.texture)return!1}let ye=D?.recomputeAutoCenter??!0;if(!ye){let K=x.stableTriangleColorFrame+1,Pe={doc:l,directionalLight:i.directionalLight,ambientLight:i.ambientLight,textureLighting:i.textureLighting,textureQuality:i.textureQuality,seamBleed:i.seamBleed,solidPaintDefaults:{},optimizeStableTriangleStyle:!0,stableTriangleDebug:D?.stableTriangleDebug,stableTriangleUpdateMode:D?.stableTriangleUpdateMode,stableTriangleColorPolicy:D?.stableTriangleColorPolicy,stableTriangleColorSteps:D?.stableTriangleColorSteps,stableTriangleColorFreezeFrames:D?.stableTriangleColorFreezeFrames??0,stableTriangleColorBudget:D?.stableTriangleColorBudget,stableTriangleColorMaxAge:D?.stableTriangleColorMaxAge,stableTriangleColorMaxStep:D?.stableTriangleColorMaxStep,stableTriangleMatrixDecimals:D?.stableTriangleMatrixDecimals,stableTriangleColorFrame:K};if(nn(x.rendered,x.polygons,w,Pe))return J++,V=q,H=se,x.stableDom=H,x.voxelSource=void 0,x.stableTriangleColorFrame=K,te=w,Le++,Ae=null,Re=-1,Oe(x)?(ie(x),Ie(x,!0)):ze(x),!0}J++,V=q,H=se,x.stableDom=H,x.voxelSource=void 0;let W=w.vertices;for(let K=0;K<w.polygonCount;K++){let Pe=x.polygons[K],Ce=w.colors?.[K];Ce&&(Pe.color=Ce);let me=Pe.vertices,fe=K*9;me[0][0]=W[fe],me[0][1]=W[fe+1],me[0][2]=W[fe+2],me[1][0]=W[fe+3],me[1][1]=W[fe+4],me[1][2]=W[fe+5],me[2][0]=W[fe+6],me[2][1]=W[fe+7],me[2][2]=W[fe+8]}return ge(),oe.polygons=x.polygons,pe(D,ye)},updatePolygon(w,D){let q=typeof w=="number"?w:x.polygons.indexOf(w);if(q<0&&typeof w!="number"&&te&&(q=Q().indexOf(w)),q<0||q>=x.polygons.length)return;ge(),x.voxelSource=void 0,Object.assign(x.polygons[q],D);let se=Object.keys(D);be(x,q,se)||$e(x)},async setPolygonsChunked(w,D){let q=++J;V=D?.merge??V,H=D?.stableDom??H,x.stableDom=H,x.voxelSource=void 0,x.polygons=B(w,V),ge(),oe.polygons=x.polygons,j(x.polygons);let se=D?.recomputeAutoCenter??!0;if(!await Vo(x,()=>x.disposed||q!==J)){ae(x);return}se&&bt()},setTransform(w){let D=x.castShadow,q=x.receiveShadow;w.castShadow!==void 0&&(x.castShadow=!!w.castShadow),w.receiveShadow!==void 0&&(x.receiveShadow=!!w.receiveShadow),I={...I,...w};let se=fi(I);E.style.transform=se??"",ht(x,I.rotation),w.rotation!==void 0&&Ie(x,!0),x.castShadow!==D&&(de(x),Ze()),x.receiveShadow!==q&&Fe(),w.position!==void 0&&(Ze(),Fe())},dispose(){if(!x.disposed){x.disposed=!0,J++,E.parentNode&&E.parentNode.removeChild(E),ae(x);try{a.dispose()}catch{}b.delete(x),bt(),Ze()}},rebakeAtlas(){x.bakedRotation=I.rotation?[...I.rotation]:[0,0,0];let w=i.directionalLight?.direction??[.4,-.7,.59],D=(0,X.inverseRotateVec3)(w,x.bakedRotation);$e(x,D)},getPosition(){return I.position},getRotation(){return I.rotation},getScale(){return I.scale},getPolygons(){return oe.polygons}};return x.handle=oe,b.add(x),$e(x),ht(x,I.rotation),bt(),Ze(),x.receiveShadow&&Fe(),oe}function Bo(a){let d=!!i.autoCenter,S=i.strategies,E=i.seamBleed,I=i.textureLighting,V=i.directionalLight?.direction,H=i.shadow,J=pi(a);i={...i,...J},F(m,i);let Y=!!i.autoCenter;for(let ge of b)ht(ge,ge.handle.transform.rotation);let B=a.strategies!==void 0&&!la(a.strategies,S),ne=Object.prototype.hasOwnProperty.call(a,"seamBleed")&&J.seamBleed!==E;if(B||ne)for(let ge of b)$e(ge);d!==Y&&bt();let j=a.textureLighting!==void 0&&I!==i.textureLighting,x=i.directionalLight?.direction,te=a.directionalLight!==void 0&&!ca(V,x),Le=i.shadow,Re=a.shadow!==void 0&&!ua(H,Le),Ae=te||Re;if(j){for(let ge of b)!B&&!ne&&(ge.voxelSource||ge.voxelRenderer)&&$e(ge);Ze(),Fe()}else Ae&&Fe();Re&&a.shadow?.lift!==H?.lift&&Ze()}function Rn(){return i}function Dn(){$(m);for(let a of b)Ie(a)}function Xi(){let a=[];for(let d of b)a.push(d.handle);return a}function Zi(a){let d=a;for(;d;){if(d instanceof HTMLElement&&d.classList.contains("polycss-mesh")){for(let S of b)if(S.wrapper===d)return S.handle;return null}d=d.parentElement}return null}function Qi(){let a=Array.from(b);for(let d of a)try{d.handle.dispose()}catch{}p.parentNode&&p.parentNode.removeChild(p)}return{add:zo,setOptions:Bo,destroy:Qi,host:e,camera:t,cameraEl:p,applyCamera:Dn,getOptions:Rn,meshes:Xi,findMeshByElement:Zi}}var fr=require("@layoutit/polycss-core"),ya=8e3;function $t(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,fr.createIsometricCamera)(n),o=`${e.perspective??ya}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function Dt(e={}){let n={};e.zoom!==void 0&&(n.zoom=e.zoom),e.target!==void 0&&(n.target=e.target),e.rotX!==void 0&&(n.rotX=e.rotX),e.rotY!==void 0&&(n.rotY=e.rotY),e.distance!==void 0&&(n.distance=e.distance);let t=(0,fr.createIsometricCamera)(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}var hi=Dt;var bi=require("@layoutit/polycss-core");var qn={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function sn(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 wn(e){return e===!0?-1:e===!1?1:e}function an(){let e=[],n=[],t=[];function o(s){return s==="change"?e:s==="start"?n:t}function r(s){if(e.length===0)return;let c={type:"change",camera:s()},l=e.slice();for(let p of l)try{p(c)}catch(m){console.error("[polycss] controls 'change' listener threw:",m)}}function i(s,c){let l=s==="start"?n:t;if(l.length===0)return;let p={type:s,camera:c()},m=l.slice();for(let b of m)try{b(p)}catch(y){console.error(`[polycss] controls '${s}' listener threw:`,y)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:i}}function ln(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 Kn(e,n,t,o,r,i){let s=!1,c=null;return{onWheel:m=>{let b=n();if(!b.wheel||t())return;m.preventDefault();let y=m.deltaMode===1?16:m.deltaMode===2?100:1,P=m.deltaY*y;m.ctrlKey?P*=10:P*=3;let h=e.camera.state;if(b.dolly){let v=h.distance??0,f=Math.max(b.minDistance,Math.min(b.maxDistance,v+P*.05));e.camera.update({distance:f})}else{let v=Math.exp(-P*513e-6),f=h.zoom??1,C=Math.max(b.minZoom,Math.min(b.maxZoom,f*v));e.camera.update({zoom:C})}e.applyCamera(),s||(s=!0,i("start",o)),r(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,s=!1,i("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),s=!1}}}function Jn(e,n,t,o,r,i,s){let c=null,l=0,p=P=>{if(c===null||o())return;let h=t();if(!h.animate){c=null;return}if(r())l=P;else{let v=Math.min(50,l?P-l:16.67);l=P;let f=h.animate.speed*(v/16.67),C=n.camera.state;if(h.animate.axis==="x"){let R=(((C.rotX??65)+f)%360+360)%360;n.camera.update({rotX:R})}else{let R=(((C.rotY??45)+f)%360+360)%360;n.camera.update({rotY:R})}n.applyCamera(),s(i)}c=e.requestAnimationFrame(p)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(p))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function eo(e,n={}){let t=sn(qn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,i=null,s={x:0,y:0},c=!1,l=!1,p=an(),m=ln(e),{changeListeners:b,startListeners:y,endListeners:P,listenerArray:h,emitChange:v,emitInteraction:f}=p,C=Jn(r,e,()=>t,()=>l,()=>c,m,v),R=T=>{if(!(!t.drag||l)&&i===null&&T.isPrimary!==!1){T.preventDefault(),i=T.pointerId,s={x:T.clientX,y:T.clientY},o.style.cursor="grabbing";try{T.target.setPointerCapture(T.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),f("start",m)}},k=T=>{if(i===null||T.pointerId!==i||!t.drag||l)return;T.preventDefault();let A=T.clientX-s.x,L=T.clientY-s.y;s={x:T.clientX,y:T.clientY};let M=wn(t.invert),le=A/4*M,xe=L/4*M,_=e.camera.state;if(T.shiftKey){let re=_.rotX??65,ie=_.rotY??45,Me=Math.max(.01,_.zoom??1),Oe=Math.cos(re*Math.PI/180),ze=Oe>=0?Math.max(.1,Oe):Math.min(-.1,Oe),Ge=Math.cos(ie*Math.PI/180),Ie=Math.sin(ie*Math.PI/180),Ye=Me*bi.BASE_TILE,ct=(A*Ie-L*Ge/ze)/Ye,Xe=-(A*Ge+L*Ie/ze)/Ye,et=_.target??[0,0,0];e.camera.update({target:[et[0]+ct,et[1]+Xe,et[2]]})}else{let re=Math.max(0,Math.min(100,(_.rotX??65)-xe)),ie=(((_.rotY??45)-le)%360+360)%360;e.camera.update({rotX:re,rotY:ie})}e.applyCamera(),v(m)},N=T=>{if(i===T.pointerId){i=null,o.style.cursor=t.drag&&!l?"grab":"";try{T.target.releasePointerCapture(T.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),f("end",m)}},O=Kn(e,()=>t,()=>l,m,v,f);function ee(){o.addEventListener("pointerdown",R),o.addEventListener("pointermove",k),o.addEventListener("pointerup",N),o.addEventListener("pointercancel",N),o.addEventListener("wheel",O.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function z(){o.removeEventListener("pointerdown",R),o.removeEventListener("pointermove",k),o.removeEventListener("pointerup",N),o.removeEventListener("pointercancel",N),o.removeEventListener("wheel",O.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",O.teardown()}ee(),C.start();function F(T){let A=!!t.animate;t=sn(t,T),!l&&i===null&&(o.style.cursor=t.drag?"grab":"");let L=!!t.animate;A&&!L?C.stop():!A&&L&&C.start()}function $(){l&&(l=!1,ee(),C.start())}function U(){l||(l=!0,z(),C.stop(),i=null,c=!1,O.teardown())}function ae(){U(),b.length=0,y.length=0,P.length=0}function Ee(T,A){let L=h(T);L.includes(A)||L.push(A)}function u(T,A){let L=h(T),M=L.indexOf(A);M>=0&&L.splice(M,1)}function g(T,A){return h(T).includes(A)}return{update:F,resume:$,pause:U,destroy:ae,addEventListener:Ee,removeEventListener:u,hasEventListener:g}}var xi=require("@layoutit/polycss-core");function to(e,n={}){let t=sn(qn,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,i=null,s={x:0,y:0},c=!1,l=!1,p=!1,m={x:0,y:0},b=an(),y=ln(e),{changeListeners:P,startListeners:h,endListeners:v,listenerArray:f,emitChange:C,emitInteraction:R}=b,k=Jn(r,e,()=>t,()=>l,()=>c,y,C),N=_=>{if(!(!t.drag||l)&&i===null&&_.isPrimary!==!1){_.preventDefault(),i=_.pointerId,s={x:_.clientX,y:_.clientY},o.style.cursor="grabbing";try{_.target.setPointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),R("start",y)}},O=_=>{if(i===null||_.pointerId!==i||!t.drag||l)return;_.preventDefault();let re=_.clientX-s.x,ie=_.clientY-s.y;s={x:_.clientX,y:_.clientY};let Me=e.camera.state;if(_.shiftKey){let Oe=wn(t.invert),ze=re/4*Oe,Ge=ie/4*Oe,Ie=Math.max(0,Math.min(100,(Me.rotX??65)-Ge)),Ye=(((Me.rotY??45)-ze)%360+360)%360;e.camera.update({rotX:Ie,rotY:Ye})}else{let Oe=Me.rotX??65,ze=Me.rotY??45,Ge=Math.max(.01,Me.zoom??1),Ie=Math.cos(Oe*Math.PI/180),Ye=Ie>=0?Math.max(.1,Ie):Math.min(-.1,Ie),ct=Math.cos(ze*Math.PI/180),Xe=Math.sin(ze*Math.PI/180),et=Ge*xi.BASE_TILE,mn=(re*Xe-ie*ct/Ye)/et,fn=-(re*ct+ie*Xe/Ye)/et,ht=Me.target??[0,0,0];e.camera.update({target:[ht[0]+mn,ht[1]+fn,ht[2]]})}e.applyCamera(),C(y)},ee=_=>{if(i===_.pointerId){i=null,o.style.cursor=t.drag&&!l?"grab":"";try{_.target.releasePointerCapture(_.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),R("end",y)}},z=_=>{_.preventDefault()},F=_=>{_.button===2&&(p=!0,m={x:_.clientX,y:_.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),R("start",y))},$=_=>{if(!p||!t.drag)return;let re=_.clientX-m.x,ie=_.clientY-m.y;m={x:_.clientX,y:_.clientY};let Me=wn(t.invert),Oe=re/4*Me,ze=ie/4*Me,Ge=e.camera.state,Ie=Math.max(0,Math.min(100,(Ge.rotX??65)-ze)),Ye=(((Ge.rotY??45)-Oe)%360+360)%360;e.camera.update({rotX:Ie,rotY:Ye}),e.applyCamera(),C(y)},U=_=>{_.button===2&&p&&(p=!1,R("end",y))},ae=Kn(e,()=>t,()=>l,y,C,R);function Ee(){o.addEventListener("pointerdown",N),o.addEventListener("pointermove",O),o.addEventListener("pointerup",ee),o.addEventListener("pointercancel",ee),o.addEventListener("wheel",ae.onWheel,{passive:!1}),o.addEventListener("contextmenu",z),o.addEventListener("mousedown",F),o.addEventListener("mousemove",$),o.addEventListener("mouseup",U),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function u(){o.removeEventListener("pointerdown",N),o.removeEventListener("pointermove",O),o.removeEventListener("pointerup",ee),o.removeEventListener("pointercancel",ee),o.removeEventListener("wheel",ae.onWheel),o.removeEventListener("contextmenu",z),o.removeEventListener("mousedown",F),o.removeEventListener("mousemove",$),o.removeEventListener("mouseup",U),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",ae.teardown()}Ee(),k.start();function g(_){let re=!!t.animate;t=sn(t,_),!l&&i===null&&(o.style.cursor=t.drag?"grab":"");let ie=!!t.animate;re&&!ie?k.stop():!re&&ie&&k.start()}function T(){l&&(l=!1,Ee(),k.start())}function A(){l||(l=!0,u(),k.stop(),i=null,c=!1,p=!1,ae.teardown())}function L(){A(),P.length=0,h.length=0,v.length=0}function M(_,re){let ie=f(_);ie.includes(re)||ie.push(re)}function le(_,re){let ie=f(_),Me=ie.indexOf(re);Me>=0&&ie.splice(Me,1)}function xe(_,re){return f(_).includes(re)}return{update:g,resume:T,pause:A,destroy:L,addEventListener:M,removeEventListener:le,hasEventListener:xe}}var Ai=require("@layoutit/polycss-core");var ha={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 Pi(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 vi=new Set(["KeyW","ArrowUp"]),Ci=new Set(["KeyS","ArrowDown"]),Si=new Set(["KeyA","ArrowLeft"]),Ti=new Set(["KeyD","ArrowRight"]),Ei=new Set(["Space"]),gr=new Set(["ControlLeft","ControlRight"]);function no(e,n={}){let t=Pi(ha,n),o=e.host,r=e.cameraEl,i=o.ownerDocument??document,s=i.defaultView??globalThis,c=an(),l=ln(e),{changeListeners:p,startListeners:m,endListeners:b,listenerArray:y,emitChange:P,emitInteraction:h}=c,v=new Set,f=!1,C=!1,R=0,k=0,N=!1,O=[0,0,t.groundZ+t.eyeHeight];function ee(G,be){let de=G*Math.PI/180,Fe=be*Math.PI/180;return[-Math.sin(de)*Math.cos(Fe),-Math.sin(de)*Math.sin(Fe),-Math.cos(de)]}function z(){let G=e.camera.perspectiveStyle,be=G==="none"?0:parseFloat(G);return(Number.isFinite(be)&&be>0?be:2e3)/Ai.BASE_TILE}function F(){let G=e.camera.state,be=ee(G.rotX??90,G.rotY??0),de=z();return[O[0]+be[0]*de,O[1]+be[1]*de,O[2]+be[2]*de]}function $(){let G=F();e.camera.update({target:G}),e.applyCamera()}function U(){let G=e.camera.state.target??[0,0,0];O=[G[0],G[1],t.groundZ+t.eyeHeight],$()}let ae=()=>{if(!(!t.enabled||!t.lookEnabled||C||f))try{o.requestPointerLock()}catch{}},Ee=()=>{let G=i.pointerLockElement===o;G!==f&&(f=G,f?(N=!0,h("start",l)):N&&(N=!1,h("end",l)))},u=G=>{if(!f||!t.enabled||!t.lookEnabled||C)return;let be=G.movementX??0,de=G.movementY??0;if(be===0&&de===0)return;let Fe=e.camera.state,gn=t.lookSensitivity,yn=t.invertY?-1:1,Ft=(((Fe.rotY??0)-be*gn)%360+360)%360,Be=(Fe.rotX??90)-de*gn*yn;Be<t.minPitch?Be=t.minPitch:Be>t.maxPitch&&(Be=t.maxPitch);let ot=ee(Be,Ft),$e=z(),Ze=[O[0]+ot[0]*$e,O[1]+ot[1]*$e,O[2]+ot[2]*$e];e.camera.update({rotX:Be,rotY:Ft,target:Ze}),e.applyCamera(),P(l)},g=G=>vi.has(G)||Ci.has(G)||Si.has(G)||Ti.has(G)||Ei.has(G)||gr.has(G),T=G=>{if(!(!t.enabled||C)&&g(G.code)&&!(!f&&!t.moveEnabled)){if(Ei.has(G.code)){if(!t.jumpEnabled)return;G.preventDefault(),!v.has(G.code)&&R===0&&k===0&&(R=t.jumpVelocity),v.add(G.code);return}gr.has(G.code)&&!t.crouchEnabled||!t.moveEnabled&&!gr.has(G.code)||(G.preventDefault(),v.add(G.code))}},A=G=>{g(G.code)&&v.delete(G.code)},L=()=>{v.clear()},M=null,le=0,xe=.05,_=G=>{if(M===null||C)return;let be=Math.min(xe,le?(G-le)/1e3:.0167);if(le=G,t.enabled){let de=!1,Fe=e.camera.state;if(t.moveEnabled){let Be=0,ot=0;for(let $e of v)vi.has($e)?Be+=1:Ci.has($e)?Be-=1:Ti.has($e)?ot+=1:Si.has($e)&&(ot-=1);if(Be!==0||ot!==0){let Ze=(Fe.rotY??0)*Math.PI/180,Vo=-Math.cos(Ze),bt=-Math.sin(Ze),zo=-Math.sin(Ze),Bo=Math.cos(Ze),Rn=Math.hypot(Be,ot)||1,Dn=t.moveSpeed*be;O[0]+=(Vo*Be+zo*ot)/Rn*Dn,O[1]+=(bt*Be+Bo*ot)/Rn*Dn,de=!0}}let yn=t.crouchEnabled&&(v.has("ControlLeft")||v.has("ControlRight"))?t.crouchHeight:t.eyeHeight;t.jumpEnabled&&(R!==0||k>0)?(R-=t.gravity*be,k+=R*be,k<=0&&(k=0,R=0)):t.jumpEnabled||(k=0,R=0);let Ft=t.groundZ+yn+k;if(Math.abs(O[2]-Ft)>1e-4&&(O[2]=Ft,de=!0),de){let Be=F();e.camera.update({target:Be}),e.applyCamera(),P(l)}}M=s.requestAnimationFrame(_)};function re(){M!==null||C||(le=0,M=s.requestAnimationFrame(_))}function ie(){M!==null&&(s.cancelAnimationFrame(M),M=null)}function Me(){let be=r.ownerDocument?.defaultView?.getComputedStyle(r).perspective??"",de=parseFloat(be),Fe=Number.isFinite(de)&&de>0?de:2e3;r.style.setProperty("--polycss-fpv-perspective",`${Fe}px`),r.classList.add("polycss-fpv-host")}function Oe(){r.classList.remove("polycss-fpv-host"),r.style.removeProperty("--polycss-fpv-perspective")}function ze(){o.addEventListener("click",ae),i.addEventListener("pointerlockchange",Ee),i.addEventListener("mousemove",u),s.addEventListener("keydown",T),s.addEventListener("keyup",A),s.addEventListener("blur",L),o.style.cursor=t.lookEnabled?"crosshair":"",Me()}function Ge(){if(o.removeEventListener("click",ae),i.removeEventListener("pointerlockchange",Ee),i.removeEventListener("mousemove",u),s.removeEventListener("keydown",T),s.removeEventListener("keyup",A),s.removeEventListener("blur",L),o.style.cursor="",v.clear(),f)try{i.exitPointerLock()}catch{}Oe()}U(),ze(),re();function Ie(G){let be=t.eyeHeight,de=t.groundZ;t=Pi(t,G),C||(o.style.cursor=t.lookEnabled?"crosshair":""),(t.eyeHeight!==be||t.groundZ!==de)&&(O[2]=t.groundZ+t.eyeHeight,$(),P(l))}function Ye(){C&&(C=!1,ze(),re())}function ct(){C||(C=!0,Ge(),ie(),N&&(N=!1,h("end",l)))}function Xe(){ct(),p.length=0,m.length=0,b.length=0}function et(){if(!(!t.enabled||!t.lookEnabled||C))try{o.requestPointerLock()}catch{}}function mn(){if(f)try{i.exitPointerLock()}catch{}}function fn(){return f}function ht(G,be){let de=y(G);de.includes(be)||de.push(be)}function kt(G,be){let de=y(G),Fe=de.indexOf(be);Fe>=0&&de.splice(Fe,1)}function Fo(G,be){return y(G).includes(be)}function Ho(){return[O[0],O[1],O[2]]}function Io(G){O[0]=G[0],O[1]=G[1],O[2]=G[2],$(),P(l)}return{update:Ie,resume:Ye,pause:ct,destroy:Xe,lock:et,unlock:mn,isLocked:fn,getOrigin:Ho,setOrigin:Io,addEventListener:ht,removeEventListener:kt,hasEventListener:Fo}}function ba(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let i=r.getBoundingClientRect();if(!(i.width<=0||i.height<=0)&&n>=i.left&&n<=i.right&&t>=i.top&&t<=i.bottom)return!0}return!1}function oo(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let v of o)try{v(t)}catch(f){console.error("[polycss/createSelect] onChange threw:",f)}}function i(h){t=h,r()}function s(h){n.multiple?t.includes(h)||(t=[...t,h]):t=[h],r()}function c(h){t.includes(h)&&(t=t.filter(v=>v!==h),r())}function l(h){t.includes(h)?t=t.filter(v=>v!==h):n.multiple?t=[...t,h]:t=[h],r()}function p(){t.length!==0&&(t=[],r())}function m(h){return t.includes(h)}function b(h,v){for(let f of e.meshes())if(!f.element.classList.contains("polycss-transform-gizmo")&&ba(f.element,h,v))return f;return null}let y=h=>{let v=h.target;if(v?.closest(".polycss-transform-gizmo"))return;let f=e.findMeshByElement(v)??b(h.clientX,h.clientY);if(!f){n.onPointerMissed&&n.onPointerMissed(h),n.clearOnMiss!==!1&&p();return}n.multiple&&(h.shiftKey||h.metaKey||h.ctrlKey)?l(f):t.length===1&&t[0]===f?p():i([f])};e.host.addEventListener("click",y);function P(){e.host.removeEventListener("click",y),o.clear()}return{get selected(){return t},set:i,add:s,remove:c,toggle:l,clear:p,has:m,destroy:P}}var Ke=require("@layoutit/polycss-core"),io="#ff3653",so="#8adb00",ao="#2c8fff",cn=50,Mi=60,xa=.6,Pa=.0125,va=.15,Ca=.04,Sa=1,Li=.02,yr=1.04,Ta=.1,Ea=.25,Ri=1e-4,Aa=.6,Ma=.8,La=1,_n={0:1,1:0,2:2},wi=[{cssAxis:0,sign:1,key:"x",color:io},{cssAxis:0,sign:-1,key:"-x",color:io},{cssAxis:1,sign:1,key:"y",color:so},{cssAxis:1,sign:-1,key:"-y",color:so},{cssAxis:2,sign:1,key:"z",color:ao},{cssAxis:2,sign:-1,key:"-z",color:ao}],_i=[{cssAxis:0,key:"x",color:io},{cssAxis:1,key:"y",color:so},{cssAxis:2,key:"z",color:ao}],Oi=[{perpAxis:2,axisA:0,axisB:1,key:"xy",color:ao},{perpAxis:1,axisA:0,axisB:2,key:"xz",color:so},{perpAxis:0,axisA:1,axisB:2,key:"yz",color:io}];function hr(e,n,t,o){let r=t*Math.PI/180,i=o*Math.PI/180,s=[0,0,0];s[e]=n;let c=s[0]*Math.cos(i)-s[1]*Math.sin(i),l=s[0]*Math.sin(i)+s[1]*Math.cos(i),p=s[2];return l*Math.sin(r)+p*Math.cos(r)<0}function wa(e,n){let t=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!t)return e;let o=parseInt(t[1],16),r=parseInt(t[2],16),i=parseInt(t[3],16);return`rgba(${o}, ${r}, ${i}, ${n})`}function lo(e,n){return!n||n<=0?e:Math.round(e/n)*n}function _a(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let c of e)for(let l of c.vertices)l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>i&&(i=l[1]),l[2]<o&&(o=l[2]),l[2]>s&&(s=l[2]);return Number.isFinite(n)?[(t+i)/2*cn,(n+r)/2*cn,(o+s)/2*cn]:[0,0,0]}function br(e){if(e.length===0)return Mi;let n=1/0,t=1/0,o=1/0,r=-1/0,i=-1/0,s=-1/0;for(let l of e)for(let p of l.vertices)p[0]<n&&(n=p[0]),p[0]>r&&(r=p[0]),p[1]<t&&(t=p[1]),p[1]>i&&(i=p[1]),p[2]<o&&(o=p[2]),p[2]>s&&(s=p[2]);return Number.isFinite(n)?Math.max(r-n,i-t,s-o)*cn*xa:Mi}function ro(e,n,t){let o=Array.from(e.querySelectorAll("i,b,s,u"));for(let r of o){let i=r.getBoundingClientRect();if(!(i.width<=0||i.height<=0)&&n>=i.left&&n<=i.right&&t>=i.top&&t<=i.bottom)return!0}return!1}function Oa(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:i,startClientX:s,startClientY:c,translationSnap:l,onAxisDelta:p,onMouseDown:m,onMouseUp:b,onDraggingChanged:y}=e,P=o,h=[0,0,0];h[n]=t;let v=r.ownerDocument.createElement("div");v.style.position="absolute",v.style.left="0",v.style.top="0",v.style.width="0",v.style.height="0",v.style.transform=`translate3d(${h[0]*P}px, ${h[1]*P}px, ${h[2]*P}px)`,r.appendChild(v);let f=r.getBoundingClientRect(),C=v.getBoundingClientRect();r.removeChild(v);let R=(C.left-f.left)/P,k=(C.top-f.top)/P,N=R*R+k*k;if(N<Ri)return;m?.(),y?.(!0);let O=z=>{let F=z.clientX-s,$=z.clientY-c,U=(F*R+$*k)/N;U=lo(U,l),p(U,h)},ee=()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",ee),window.removeEventListener("pointercancel",ee);let z=F=>{F.stopPropagation(),F.stopImmediatePropagation()};window.addEventListener("click",z,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",z,!0),0),b?.(),y?.(!1)};window.addEventListener("pointermove",O),window.addEventListener("pointerup",ee),window.addEventListener("pointercancel",ee)}function Ra(e){let{axisA:n,axisB:t,probeDistanceCss:o,wrapper:r,startClientX:i,startClientY:s,translationSnap:c,onPlaneDelta:l,onMouseDown:p,onMouseUp:m,onDraggingChanged:b}=e,y=[0,0,0];y[n]=1;let P=[0,0,0];P[t]=1;function h(N){let O=r.ownerDocument.createElement("div");O.style.position="absolute",O.style.left="0",O.style.top="0",O.style.width="0",O.style.height="0",O.style.transform=`translate3d(${N[0]*o}px, ${N[1]*o}px, ${N[2]*o}px)`,r.appendChild(O);let ee=r.getBoundingClientRect(),z=O.getBoundingClientRect();return r.removeChild(O),{x:(z.left-ee.left)/o,y:(z.top-ee.top)/o}}let v=h(y),f=h(P),C=v.x*f.y-f.x*v.y;if(Math.abs(C)<Ri)return;p?.(),b?.(!0);let R=N=>{let O=N.clientX-i,ee=N.clientY-s,z=(f.y*O-f.x*ee)/C,F=(-v.y*O+v.x*ee)/C;z=lo(z,c),F=lo(F,c),l(z,F,y,P)},k=()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k);let N=O=>{O.stopPropagation(),O.stopImmediatePropagation()};window.addEventListener("click",N,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",N,!0),0),m?.(),b?.(!1)};window.addEventListener("pointermove",R),window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k)}function Da(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:i,rotationSnap:s,onAngleDelta:c,onMouseDown:l,onMouseUp:p,onDraggingChanged:m}=e,b=t.getBoundingClientRect(),y=b.left,P=b.top,h=Math.atan2(i-P,r-y),v=0;l?.(),m?.(!0);let f=R=>{let k=Math.atan2(R.clientY-P,R.clientX-y),N=k-h;N>Math.PI?N-=2*Math.PI:N<-Math.PI&&(N+=2*Math.PI),v+=N,h=k;let O=v*180/Math.PI;O=lo(O,s),c(O)},C=()=>{window.removeEventListener("pointermove",f),window.removeEventListener("pointerup",C),window.removeEventListener("pointercancel",C);let R=k=>{k.stopPropagation(),k.stopImmediatePropagation()};window.addEventListener("click",R,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",R,!0),0),p?.(),m?.(!1)};window.addEventListener("pointermove",f),window.addEventListener("pointerup",C),window.addEventListener("pointercancel",C)}function co(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,i={...n},s=new Map,c=null,l=null,p=[0,0,0];function m(){if(!t)return[0,0,0];let u=t.transform.position??[0,0,0];return[u[0]+p[0],u[1]+p[1],u[2]+p[2]]}function b(u){return l===u?La:c===u?Ma:Aa}function y(){for(let[u,g]of s){let T=P(g.spec,b(u));g.handle.setPolygons(T,{recomputeAutoCenter:!1})}}function P(u,g){let A=br(t?.polygons??[])*r,L=A/cn,M=wa(u.color,g);if(u.kind==="arrow"){let _=e.camera.state,re=hr(u.cssAxis,u.sign,_.rotX??65,_.rotY??45);return(0,Ke.arrowPolygons)({axis:_n[u.cssAxis],sign:u.sign,shaftLength:L,shaftHalfThickness:L*Pa,headLength:L*va,headHalfThickness:L*Ca,color:M,shaft:!re})}if(u.kind==="plane"){let _=e.camera.state,re=_.rotX??65,ie=_.rotY??45,Me=_n[u.perpAxis],Oe=(Me+1)%3,ze=(Me+2)%3,Ge=_n[Oe],Ie=_n[ze],Ye=hr(Ge,1,re,ie)?-1:1,ct=hr(Ie,1,re,ie)?-1:1,Xe=L*Ea;return(0,Ke.planePolygons)({axis:Me,size:L*Ta,offset:[Ye*Xe,ct*Xe],color:M})}let xe=A*Sa/cn*yr;return(0,Ke.ringQuadPolygons)({axis:_n[u.cssAxis],outerRadius:xe,color:M})}function h(u){return u.kind==="arrow"?"polycss-transform-arrow":u.kind==="plane"?"polycss-transform-plane":"polycss-transform-ring"}function v(){if(o==="translate"){let u=wi.map(T=>({kind:"arrow",key:T.key,cssAxis:T.cssAxis,sign:T.sign,color:T.color})),g=Oi.map(T=>({kind:"plane",key:T.key,perpAxis:T.perpAxis,axisA:T.axisA,axisB:T.axisB,color:T.color}));return[...u,...g]}return o==="rotate"?_i.map(u=>({kind:"ring",key:u.key,cssAxis:u.cssAxis,color:u.color})):[]}function f(){if(C(),!t)return;let u={x:i.showX!==!1,y:i.showY!==!1,z:i.showZ!==!1};function g(A){if(A.kind==="arrow"){let le=A.key.replace("-","")[0];return u[le]}if(A.kind==="ring")return u[A.key];let L=["x","y","z"][A.axisA],M=["x","y","z"][A.axisB];return u[L]&&u[M]}let T=m();for(let A of v()){if(!g(A))continue;let L=P(A,b(A.key)),M=e.add({polygons:L,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${A.key}`,position:T}),le=h(A);if(M.element.classList.add("polycss-transform-gizmo",le,`${le}--${A.key}`),A.kind==="ring"){let xe=(1-Li)/yr,_=(1+Li)/yr;M.element.style.setProperty("--ring-inner-ratio",`${xe}`),M.element.style.setProperty("--ring-outer-ratio",`${_}`)}s.set(A.key,{handle:M,spec:A})}}function C(){for(let{handle:u}of s.values())u.remove();s.clear(),c=null,l=null}function R(){if(!t)return;let u=m();for(let{handle:g}of s.values())g.setTransform({position:u})}function k(){t&&(s.size===0?f():R())}function N(u){if(t=u,!u){p=[0,0,0],C();return}p=_a(u.polygons),C(),f()}function O(){N(null)}function ee(u){u!==o&&(o=u,t&&(C(),f()))}function z(u,g,T){if(!t||!F)return;let A=[F[0]+g*T[0],F[1]+g*T[1],F[2]+g*T[2]];t.setTransform({position:A}),R(),i.onObjectChange?.({object:t,position:A}),i.onChange?.()}let F=null,$=null,U=u=>{if(!t||i.enabled===!1)return;let g={x:i.showX!==!1,y:i.showY!==!1,z:i.showZ!==!1};if(o==="translate"){for(let T of Oi){let A=["x","y","z"][T.axisA],L=["x","y","z"][T.axisB];if(!g[A]||!g[L])continue;let M=s.get(T.key);if(M&&ro(M.handle.element,u.clientX,u.clientY)){u.preventDefault(),u.stopPropagation(),l=T.key,y(),F=(t.transform.position??[0,0,0]).slice(),Ra({axisA:T.axisA,axisB:T.axisB,probeDistanceCss:br(t.polygons)*r,wrapper:M.handle.element,target:t,startClientX:u.clientX,startClientY:u.clientY,translationSnap:i.translationSnap??null,onPlaneDelta:(le,xe,_,re)=>{if(!t||!F)return;let ie=[F[0]+le*_[0]+xe*re[0],F[1]+le*_[1]+xe*re[1],F[2]+le*_[2]+xe*re[2]];t.setTransform({position:ie}),R(),i.onObjectChange?.({object:t,position:ie}),i.onChange?.()},onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:le=>{le||(l=null,F=null,y()),i.onDraggingChanged?.(le)}});return}}for(let T of wi){let A=T.key.replace("-","")[0];if(!g[A])continue;let L=s.get(T.key);if(L&&ro(L.handle.element,u.clientX,u.clientY)){u.preventDefault(),u.stopPropagation(),l=T.key,y(),F=(t.transform.position??[0,0,0]).slice(),Oa({cssAxis:T.cssAxis,sign:T.sign,shaftLengthCss:br(t.polygons)*r,wrapper:L.handle.element,target:t,startClientX:u.clientX,startClientY:u.clientY,translationSnap:i.translationSnap??null,onAxisDelta:(M,le)=>z(T,M,le),onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:M=>{M||(l=null,F=null,y()),i.onDraggingChanged?.(M)}});return}}}else if(o==="rotate")for(let T of _i){if(!g[T.key])continue;let A=s.get(T.key);if(A&&ro(A.handle.element,u.clientX,u.clientY)){u.preventDefault(),u.stopPropagation(),l=T.key,y(),$=(t.transform.rotation??[0,0,0]).slice(),Da({cssAxis:T.cssAxis,wrapper:A.handle.element,target:t,startClientX:u.clientX,startClientY:u.clientY,rotationSnap:i.rotationSnap??null,onAngleDelta:L=>{if(!t||!$)return;let M=T.cssAxis===0?-1:1,le=[0,0,0];le[T.cssAxis]=1;let xe=L*M*Math.PI/180,_=(0,Ke.quatFromEulerXYZ)($),re=(0,Ke.quatFromAxisAngle)(le,xe),ie=(0,Ke.eulerXYZFromQuat)((0,Ke.quatMultiply)(re,_));t.setTransform({rotation:ie}),i.onObjectChange?.({object:t,rotation:ie}),i.onChange?.()},onMouseDown:i.onMouseDown,onMouseUp:i.onMouseUp,onDraggingChanged:L=>{L||(l=null,$=null,y(),t?.rebakeAtlas()),i.onDraggingChanged?.(L)}});return}}};e.host.addEventListener("pointerdown",U,{capture:!0});let ae=u=>{if(!t||l||i.enabled===!1)return;let g=null;for(let[T,A]of s)if(ro(A.handle.element,u.clientX,u.clientY)){g=T;break}g!==c&&(c=g,y())};e.host.addEventListener("pointermove",ae);function Ee(){e.host.removeEventListener("pointerdown",U,{capture:!0}),e.host.removeEventListener("pointermove",ae),C()}return{attach:N,detach:O,setMode:ee,update:k,destroy:Ee}}var ka=typeof HTMLElement<"u"?HTMLElement:class{},Fa=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","texture-quality","auto-center"];function lt(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Ha(e){return e==="false"?!1:lt(e)}function xr(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 Ia(e){if(e==="baked"||e==="dynamic")return e}function Va(e){return e==="auto"?"auto":lt(e)}function za(e){return typeof e.getCamera=="function"}var Je=class extends ka{constructor(){super(...arguments);this._scene=null;this._implicitCamera=null}static get observedAttributes(){return[...Fa]}getScene(){return this._scene}_findAncestorCamera(){let t=this.parentElement;for(;t;){if(za(t)){let o=t.getCamera();if(o)return o}t=t.parentElement}return null}_buildImplicitCamera(){let t=Ha(this.getAttribute("perspective")),o=lt(this.getAttribute("rot-x")),r=lt(this.getAttribute("rot-y")),i=lt(this.getAttribute("zoom")),s=lt(this.getAttribute("distance")),c=xr(this.getAttribute("target")),l={...o!==void 0?{rotX:o}:{},...r!==void 0?{rotY:r}:{},...i!==void 0?{zoom:i}:{},...s!==void 0?{distance:s}:{},...c!==void 0?{target:c}:{}};return t===!1?Dt(l):t!==void 0?$t({...l,perspective:t}):Dt(l)}_readNonCameraOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={};r.textureLighting=Ia(this.getAttribute("texture-lighting"))??"baked";let i=Va(this.getAttribute("texture-quality"));return i!==void 0&&(r.textureQuality=i),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=xr(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=lt(this.getAttribute("directional-intensity"));if(!t&&!o&&r===void 0)return;let i={direction:t??[.4,-.7,.59]};return o&&(i.color=o),r!==void 0&&(i.intensity=r),i}_readAmbientLight(){let t=this.getAttribute("ambient-color")||void 0,o=lt(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=Qn(this,{camera:o,...this._readNonCameraOptions()}),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1}))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null),this._implicitCamera=null}attributeChangedCallback(t,o,r){if(o!==r&&this._scene){if(this._implicitCamera&&["rot-x","rot-y","zoom","distance","target"].includes(t)){let s=lt(this.getAttribute("rot-x")),c=lt(this.getAttribute("rot-y")),l=lt(this.getAttribute("zoom")),p=lt(this.getAttribute("distance")),m=xr(this.getAttribute("target"));s!==void 0&&this._implicitCamera.update({rotX:s}),c!==void 0&&this._implicitCamera.update({rotY:c}),l!==void 0&&this._implicitCamera.update({zoom:l}),p!==void 0&&this._implicitCamera.update({distance:p}),m!==void 0&&this._implicitCamera.update({target:m}),this._scene.applyCamera();return}this._scene.setOptions(this._readNonCameraOptions())}}};var uo=require("@layoutit/polycss-core"),Ba=typeof HTMLElement<"u"?HTMLElement:class{},Na=["src","mtl","mesh-resolution","position","scale","rotation","auto-center"];function On(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 Di(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return On(e)}}function Ua(e){return e.closest("poly-scene")??null}function $a(e){if(e.length===0)return e;let n=(0,uo.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let i=s=>[s[0]-t,s[1]-o,s[2]-r];return e.map(s=>({...s,vertices:s.vertices.map(i),...s.textureTriangles?.length?{textureTriangles:s.textureTriangles.map(c=>({...c,vertices:c.vertices.map(i)}))}:null}))}var un=class extends Ba{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Na]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"||t==="mesh-resolution"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:On(this.getAttribute("position")),scale:Di(this.getAttribute("scale")),rotation:On(this.getAttribute("rotation"))})}}_tearDown(){if(this._loadToken+=1,this._handle){try{this._handle.dispose()}catch{}this._handle=null}this._parseResult=null}async _maybeLoad(){let t=this.getAttribute("src");if(!t)return;let o=Ua(this);if(!o)return;let r=++this._loadToken,i=this.getAttribute("mtl")||void 0,c=this.getAttribute("mesh-resolution")==="lossless"?"lossless":void 0,l;try{let b=i||c!==void 0?{...i?{mtlUrl:i}:{},...c!==void 0?{meshResolution:c}:{}}:void 0;l=await(0,uo.loadMesh)(t,b)}catch(b){this.dispatchEvent(new CustomEvent("polycss:error",{detail:b,bubbles:!0}));return}if(r!==this._loadToken){try{l.dispose()}catch{}return}let p=o.getScene();if(!p){try{l.dispose()}catch{}return}this.hasAttribute("auto-center")&&(l={...l,polygons:$a(l.polygons)}),this._parseResult=l,this._handle=p.add(l,{position:On(this.getAttribute("position")),scale:Di(this.getAttribute("scale")),rotation:On(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var Ga=typeof HTMLElement<"u"?HTMLElement:class{},Ya=["vertices","color","texture","uvs","position","scale","rotation"];function ki(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Pr(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 ja(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Pr(e)}}function Wa(e){return e.closest("poly-scene")??null}var po=class extends Ga{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Ya]}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){o!==r&&(this._tearDown(),this.isConnected&&this._mount())}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=Wa(this);if(!t)return;let o=t.getScene();if(!o)return;let r=ki(this.getAttribute("vertices"));if(!r||!Array.isArray(r)||r.length<3)return;let i=this.getAttribute("color")||void 0,s=this.getAttribute("texture")||void 0,c=ki(this.getAttribute("uvs"))??void 0,l={};for(let b of Array.from(this.attributes))b.name.startsWith("data-")&&(l[b.name.slice(5)]=b.value);let m={polygons:[{vertices:r,...i!==void 0?{color:i}:{},...s!==void 0?{texture:s}:{},...c!==void 0?{uvs:c}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(m,{position:Pr(this.getAttribute("position")),scale:ja(this.getAttribute("scale")),rotation:Pr(this.getAttribute("rotation"))})}};function ue(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function mo(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function We(e){if(e!==null)return!(e==="false"||e==="0")}function fo(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 go(e){if(e==="x"||e==="y")return e}var Xa=typeof HTMLElement<"u"?HTMLElement:class{},Za=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],yo=class extends Xa{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Za]}_readAnimate(){let t=ue(this.getAttribute("animate-speed")),o=go(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:We(r)}:{}}}_readOptions(){let t={},o=We(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=We(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let i=ue(this.getAttribute("min-distance"));i!==void 0&&(t.minDistance=i);let s=ue(this.getAttribute("max-distance"));s!==void 0&&(t.maxDistance=s);let c=fo(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=ue(this.getAttribute("zoom-min")),p=ue(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),p!==void 0&&(t.maxZoom=p),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Je)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=eo(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 Qa=typeof HTMLElement<"u"?HTMLElement:class{},qa=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],ho=class extends Qa{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...qa]}_readAnimate(){let t=ue(this.getAttribute("animate-speed")),o=go(this.getAttribute("animate-axis")),r=this.getAttribute("animate-pause-on-interaction");if(this.hasAttribute("animate-speed")||this.hasAttribute("animate-axis")||this.hasAttribute("animate-pause-on-interaction"))return{...t!==void 0?{speed:t}:{},...o!==void 0?{axis:o}:{},...r!==null?{pauseOnInteraction:We(r)}:{}}}_readOptions(){let t={},o=We(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=We(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let i=ue(this.getAttribute("min-distance"));i!==void 0&&(t.minDistance=i);let s=ue(this.getAttribute("max-distance"));s!==void 0&&(t.maxDistance=s);let c=fo(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=ue(this.getAttribute("zoom-min")),p=ue(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),p!==void 0&&(t.maxZoom=p),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Je)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=to(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 Ka=typeof HTMLElement<"u"?HTMLElement:class{},Ja=["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"],bo=class extends Ka{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Ja]}_readOptions(){let t={},o=We(this.getAttribute("enabled"));o!==void 0&&(t.enabled=o);let r=We(this.getAttribute("look-enabled"));r!==void 0&&(t.lookEnabled=r);let i=We(this.getAttribute("move-enabled"));i!==void 0&&(t.moveEnabled=i);let s=We(this.getAttribute("jump-enabled"));s!==void 0&&(t.jumpEnabled=s);let c=We(this.getAttribute("crouch-enabled"));c!==void 0&&(t.crouchEnabled=c);let l=ue(this.getAttribute("look-sensitivity"));if(l!==void 0&&(t.lookSensitivity=l),this.hasAttribute("invert-y")){let C=We(this.getAttribute("invert-y"));C!==void 0&&(t.invertY=C)}let p=ue(this.getAttribute("move-speed"));p!==void 0&&(t.moveSpeed=p);let m=ue(this.getAttribute("jump-velocity"));m!==void 0&&(t.jumpVelocity=m);let b=ue(this.getAttribute("gravity"));b!==void 0&&(t.gravity=b);let y=ue(this.getAttribute("eye-height"));y!==void 0&&(t.eyeHeight=y);let P=ue(this.getAttribute("crouch-height"));P!==void 0&&(t.crouchHeight=P);let h=ue(this.getAttribute("ground-z"));h!==void 0&&(t.groundZ=h);let v=ue(this.getAttribute("min-pitch"));v!==void 0&&(t.minPitch=v);let f=ue(this.getAttribute("max-pitch"));return f!==void 0&&(t.maxPitch=f),t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Je)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=no(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 el=typeof HTMLElement<"u"?HTMLElement:class{},tl=["perspective","zoom","rot-x","rot-y","target","distance"],xo=class extends el{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...tl]}getCamera(){return this._camera}_readOptions(){return{perspective:ue(this.getAttribute("perspective")),zoom:ue(this.getAttribute("zoom")),rotX:ue(this.getAttribute("rot-x")),rotY:ue(this.getAttribute("rot-y")),target:mo(this.getAttribute("target")),distance:ue(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=$t(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let i=this._readOptions();this._camera=$t(i),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var nl=typeof HTMLElement<"u"?HTMLElement:class{},ol=["zoom","rot-x","rot-y","target","distance"],dn=class extends nl{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...ol]}getCamera(){return this._camera}_readOptions(){return{zoom:ue(this.getAttribute("zoom")),rotX:ue(this.getAttribute("rot-x")),rotY:ue(this.getAttribute("rot-y")),target:mo(this.getAttribute("target")),distance:ue(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Dt(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let i=this._readOptions();i.zoom!==void 0&&this._camera.update({zoom:i.zoom}),i.rotX!==void 0&&this._camera.update({rotX:i.rotX}),i.rotY!==void 0&&this._camera.update({rotY:i.rotY}),i.target!==void 0&&this._camera.update({target:i.target}),i.distance!==void 0&&this._camera.update({distance:i.distance})}};var Po=class extends dn{};var rl=typeof HTMLElement<"u"?HTMLElement:class{},il=["mode","target","size","enabled"];function Fi(e){if(e==="translate"||e==="rotate")return e}var vo=class extends rl{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...il]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Je)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 un?r:null}_readOptions(){let t={},o=Fi(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=ue(this.getAttribute("size"));r!==void 0&&(t.size=r);let i=this.getAttribute("enabled");return i!==null&&(t.enabled=i!=="false"&&i!=="0"),t.onObjectChange=s=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:s.position,rotation:s.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let i=()=>{t.removeEventListener("polycss:scene-ready",i),this._attach()};t.addEventListener("polycss:scene-ready",i)}return}this._tc=co(o,this._readOptions());let r=this._findTargetMesh();if(r){let i=r.getMeshHandle();i&&this._tc.attach(i)}}connectedCallback(){this._attach()}disconnectedCallback(){this._tc&&(this._tc.destroy(),this._tc=null)}attributeChangedCallback(t,o,r){if(o!==r&&this._tc){if(t==="mode"){let i=Fi(r);i&&this._tc.setMode(i)}else if(t==="target"){let i=this._findTargetMesh();this._tc.attach(i?i.getMeshHandle()??null:null)}}}};var sl=typeof HTMLElement<"u"?HTMLElement:class{},al=["multiple","clear-on-miss"],Co=class extends sl{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...al]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof Je)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=oo(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 vr={quad:0,clippedSolid:0,atlas:0,stableTriangle:0},ll={polygonCount:0,mountedPolygonLeafCount:0,shadowLeafCount:0,surfaceLeafCounts:vr,bucketCount:0};function cl(e){return typeof e=="number"?{polygonCount:e}:e??{}}function pn(e,n){return e.querySelectorAll(n).length}function ul(e,n){let t=e;return typeof t.matches=="function"&&t.matches(n)}function dl(e,n){if(!n)return[e];let t=[];return ul(e,n)&&t.push(e),t.push(...Array.from(e.querySelectorAll(n))),t}function Hi(e,n){let t=cl(n);if(!e)return{...ll,surfaceLeafCounts:{...vr},polygonCount:t.polygonCount??0};let o=dl(e,t.scopeSelector),r={...vr},i=0,s=0;for(let l of o)r.quad+=pn(l,"b"),r.clippedSolid+=pn(l,"i"),r.atlas+=pn(l,"s"),r.stableTriangle+=pn(l,"u"),i+=pn(l,"q"),s+=pn(l,".polycss-bucket");let c=r.quad+r.clippedSolid+r.atlas+r.stableTriangle;return{polygonCount:t.polygonCount??c,mountedPolygonLeafCount:c,shadowLeafCount:i,surfaceLeafCounts:r,bucketCount:s}}var _e=require("@layoutit/polycss-core");function mt(e){return{polygons:e,objectUrls:[],warnings:[],dispose:()=>{}}}function Ii(e={}){return mt((0,_e.boxPolygons)(e))}function Vi(e){return mt((0,_e.planePolygons)(e))}function zi(e){return mt((0,_e.ringPolygons)(e))}function Bi(e){return mt((0,_e.octahedronPolygons)(e))}function Ni(e={}){return mt((0,_e.spherePolygons)(e))}function Ui(e={}){return mt((0,_e.tetrahedronPolygons)(e))}function $i(e={}){return mt((0,_e.icosahedronPolygons)(e))}function Gi(e={}){return mt((0,_e.dodecahedronPolygons)(e))}function Yi(e={}){return mt((0,_e.cylinderPolygons)(e))}function ji(e={}){return mt((0,_e.conePolygons)(e))}function Wi(e={}){return mt((0,_e.torusPolygons)(e))}var we=require("@layoutit/polycss-core"),pl=typeof HTMLElement<"u"?HTMLElement:class{};function ml(e){return e.closest("poly-scene")??null}function ke(e,n,t){let o=e.getAttribute(n);if(!o)return t;let r=parseFloat(o);return Number.isFinite(r)?r:t}function ft(e,n,t){return e.getAttribute(n)??t}function So(e,n){let t=e.getAttribute(n);if(!t)return;let o=t.split(",").map(r=>parseFloat(r.trim()));if(!(o.length!==3||o.some(r=>!Number.isFinite(r))))return[o[0],o[1],o[2]]}function fl(e){if(e.length===0)return e;let n=(0,we.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let i=s=>[s[0]-t,s[1]-o,s[2]-r];return e.map(s=>({...s,vertices:s.vertices.map(i)}))}var nt=class extends pl{constructor(){super(...arguments);this._handle=null}connectedCallback(){this._mount()}disconnectedCallback(){this._tearDown()}_tearDown(){if(this._handle){try{this._handle.dispose()}catch{}this._handle=null}}_mount(){let t=ml(this);if(!t)return;let o=t.getScene?.();if(!o)return;let r=this.buildPolygons();this.hasAttribute("auto-center")&&(r=fl(r));let i={polygons:r,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(i,{position:So(this,"position"),scale:(()=>{let s=this.getAttribute("scale");if(!s)return;if(s.includes(","))return So(this,"scale");let c=parseFloat(s);return Number.isFinite(c)?c:void 0})(),rotation:So(this,"rotation"),merge:!1})}},To=class extends nt{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("size"),t=n?parseFloat(n):void 0;return(0,we.boxPolygons)({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:ft(this,"color")})}},Eo=class extends nt{static get observedAttributes(){return["axis","size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=ke(this,"axis",2);return(0,we.planePolygons)({axis:n===0||n===1||n===2?n:2,size:ke(this,"size",.4),color:ft(this,"color")})}},Ao=class extends nt{static get observedAttributes(){return["axis","radius","segments","half-thickness","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=ke(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("half-thickness");return(0,we.ringPolygons)({axis:t,radius:ke(this,"radius",50),segments:ke(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:ft(this,"color")})}},Mo=class extends nt{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return(0,we.octahedronPolygons)({center:So(this,"center")??[0,0,0],size:ke(this,"size",50),color:ft(this,"color")})}},Lo=class extends nt{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,we.tetrahedronPolygons)({size:ke(this,"size",100),color:ft(this,"color")})}},wo=class extends nt{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,we.icosahedronPolygons)({size:ke(this,"size",100),color:ft(this,"color")})}},_o=class extends nt{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,we.dodecahedronPolygons)({size:ke(this,"size",100),color:ft(this,"color")})}},Oo=class extends nt{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,we.spherePolygons)({radius:ke(this,"radius",50),subdivisions:ke(this,"subdivisions",1),color:ft(this,"color")})}},Ro=class extends nt{static get observedAttributes(){return["radius","radius-top","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("radius-top");return(0,we.cylinderPolygons)({radius:ke(this,"radius",50),radiusTop:n?parseFloat(n):void 0,height:ke(this,"height",100),radialSegments:ke(this,"radial-segments",12),color:ft(this,"color")})}},Do=class extends nt{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,we.conePolygons)({radius:ke(this,"radius",50),height:ke(this,"height",100),radialSegments:ke(this,"radial-segments",12),color:ft(this,"color")})}},ko=class extends nt{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,we.torusPolygons)({radius:ke(this,"radius",50),tube:ke(this,"tube",15),radialSegments:ke(this,"radial-segments",12),tubularSegments:ke(this,"tubular-segments",16),color:ft(this,"color")})}};Te(ve,require("@layoutit/polycss-core"),module.exports);0&&(module.exports={PolyBoxElement,PolyCameraElement,PolyConeElement,PolyCylinderElement,PolyDodecahedronElement,PolyFirstPersonControlsElement,PolyIcosahedronElement,PolyMapControlsElement,PolyMeshElement,PolyOctahedronElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPlaneElement,PolyPolygonElement,PolyRingElement,PolySceneElement,PolySelectElement,PolySphereElement,PolyTetrahedronElement,PolyTorusElement,PolyTransformControlsElement,buildAtlasPages,buildTextureEdgeRepairSets,collectPolyRenderStats,computeTextureAtlasPlanPublic,createPolyBox,createPolyCamera,createPolyCone,createPolyCylinder,createPolyDodecahedron,createPolyFirstPersonControls,createPolyIcosahedron,createPolyMapControls,createPolyOctahedron,createPolyOrbitControls,createPolyOrthographicCamera,createPolyPerspectiveCamera,createPolyPlane,createPolyRing,createPolyScene,createPolySphere,createPolyTetrahedron,createPolyTorus,createSelect,createTransformControls,cssBorderShapeForPlan,filterAtlasPlans,formatBorderShapeEntryMatrix,formatCssLengthPx,formatMatrix3d,formatSolidQuadEntryMatrix,getSolidPaintDefaults,getSolidPaintDefaultsFromPlans,injectPolyBaseStyles,isBorderShapeSupported,isFullRectSolid,isProjectiveQuadPlan,isSolidTrianglePlan,isSolidTriangleSupported,packTextureAtlasPlansWithScale,renderPolygonsWithStableTriangles,renderPolygonsWithTextureAtlas,renderPolygonsWithTextureAtlasAsync,updatePolygonsWithStableTopology,updatePolygonsWithStableTriangles,updateStableTriangleFrame,...require("@layoutit/polycss-core")});
|
|
606
|
+
`),n.join(`
|
|
607
|
+
`)}function fc(e){let n=[oc];if(e.hasScene&&n.push(`
|
|
608
|
+
.polycss-scene,
|
|
609
|
+
.polycss-scene *,
|
|
610
|
+
.polycss-scene *::before,
|
|
611
|
+
.polycss-scene *::after {
|
|
612
|
+
box-sizing: border-box;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
.polycss-scene {
|
|
616
|
+
position: absolute;
|
|
617
|
+
top: 50%;
|
|
618
|
+
left: 50%;
|
|
619
|
+
width: 0;
|
|
620
|
+
height: 0;
|
|
621
|
+
transform-style: preserve-3d;
|
|
622
|
+
}
|
|
623
|
+
`),e.hasCamera&&n.push(`
|
|
624
|
+
.polycss-camera {
|
|
625
|
+
position: relative;
|
|
626
|
+
display: block;
|
|
627
|
+
width: 100%;
|
|
628
|
+
height: 100%;
|
|
629
|
+
}
|
|
630
|
+
`),e.hasFpvHost&&n.push(`
|
|
631
|
+
.polycss-fpv-host {
|
|
632
|
+
perspective: var(--polycss-fpv-perspective, 2000px) !important;
|
|
633
|
+
transform-style: preserve-3d !important;
|
|
634
|
+
}
|
|
635
|
+
`),e.hasMesh&&n.push(`
|
|
636
|
+
.polycss-mesh {
|
|
637
|
+
position: absolute;
|
|
638
|
+
transform-style: preserve-3d;
|
|
639
|
+
}
|
|
640
|
+
`),e.hasBucket&&n.push(`
|
|
641
|
+
.polycss-bucket {
|
|
642
|
+
position: absolute;
|
|
643
|
+
transform-style: preserve-3d;
|
|
644
|
+
}
|
|
645
|
+
`),e.leafTags.length>0&&n.push(`
|
|
646
|
+
${wn(e.leafTags)} {
|
|
647
|
+
position: absolute;
|
|
648
|
+
display: block;
|
|
649
|
+
transform-origin: 0 0;
|
|
650
|
+
transform-style: preserve-3d;
|
|
651
|
+
margin: 0;
|
|
652
|
+
padding: 0;
|
|
653
|
+
font: inherit;
|
|
654
|
+
font-weight: normal;
|
|
655
|
+
font-style: normal;
|
|
656
|
+
line-height: 0;
|
|
657
|
+
text-decoration: none;
|
|
658
|
+
backface-visibility: hidden;
|
|
659
|
+
background-repeat: no-repeat;
|
|
660
|
+
}
|
|
661
|
+
`),e.solidLeafTags.length>0&&!e.hasDynamicLighting&&n.push(`
|
|
662
|
+
${wn(e.solidLeafTags)} {
|
|
663
|
+
color: currentColor;
|
|
664
|
+
}
|
|
665
|
+
`),e.leafTags.includes("b")&&n.push(`
|
|
666
|
+
.polycss-scene b {
|
|
667
|
+
background: currentColor;
|
|
668
|
+
width: 64px;
|
|
669
|
+
height: 64px;
|
|
670
|
+
}
|
|
671
|
+
`),e.hasVoxelMesh&&n.push(`
|
|
672
|
+
.polycss-mesh.polycss-voxel-mesh > .polycss-voxel-face {
|
|
673
|
+
position: absolute;
|
|
674
|
+
display: block;
|
|
675
|
+
top: 0;
|
|
676
|
+
left: 0;
|
|
677
|
+
width: 0;
|
|
678
|
+
height: 0;
|
|
679
|
+
transform-style: preserve-3d;
|
|
680
|
+
transform-origin: 0 0;
|
|
681
|
+
margin: 0;
|
|
682
|
+
padding: 0;
|
|
683
|
+
font: inherit;
|
|
684
|
+
line-height: 0;
|
|
685
|
+
pointer-events: none;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
.polycss-mesh.polycss-voxel-mesh > .polycss-voxel-face > b {
|
|
689
|
+
top: 0;
|
|
690
|
+
left: 0;
|
|
691
|
+
width: var(--polycss-voxel-primitive, 1px);
|
|
692
|
+
height: var(--polycss-voxel-primitive, 1px);
|
|
693
|
+
backface-visibility: visible;
|
|
694
|
+
pointer-events: none;
|
|
695
|
+
}
|
|
696
|
+
`),e.leafTags.includes("i")&&n.push(`
|
|
697
|
+
.polycss-scene i {
|
|
698
|
+
width: 16px;
|
|
699
|
+
height: 16px;
|
|
700
|
+
border-color: currentColor;
|
|
701
|
+
}
|
|
702
|
+
`),e.leafTags.includes("s")&&n.push(`
|
|
703
|
+
.polycss-scene s {
|
|
704
|
+
width: 64px;
|
|
705
|
+
height: 64px;
|
|
706
|
+
}
|
|
707
|
+
`),e.leafTags.includes("u")&&n.push(`
|
|
708
|
+
.polycss-scene u {
|
|
709
|
+
width: 0;
|
|
710
|
+
height: 0;
|
|
711
|
+
background: transparent;
|
|
712
|
+
box-sizing: content-box;
|
|
713
|
+
border: 0 solid transparent;
|
|
714
|
+
border-color: transparent transparent currentColor transparent;
|
|
715
|
+
border-width: 0 16px 32px 16px;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
@supports (corner-top-left-shape: bevel) and (corner-top-right-shape: bevel) {
|
|
719
|
+
.polycss-scene > u,
|
|
720
|
+
.polycss-mesh > u,
|
|
721
|
+
.polycss-bucket > u {
|
|
722
|
+
border-width: 0;
|
|
723
|
+
width: 32px;
|
|
724
|
+
height: 32px;
|
|
725
|
+
background-color: currentColor;
|
|
726
|
+
border-top-left-radius: 50% 100%;
|
|
727
|
+
border-top-right-radius: 50% 100%;
|
|
728
|
+
corner-top-left-shape: bevel;
|
|
729
|
+
corner-top-right-shape: bevel;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
.polycss-scene > u.polycss-corner-shape-solid,
|
|
733
|
+
.polycss-mesh > u.polycss-corner-shape-solid,
|
|
734
|
+
.polycss-bucket > u.polycss-corner-shape-solid {
|
|
735
|
+
width: 16px;
|
|
736
|
+
height: 16px;
|
|
737
|
+
box-sizing: border-box;
|
|
738
|
+
border: 0;
|
|
739
|
+
background: currentColor;
|
|
740
|
+
border-radius: 0;
|
|
741
|
+
corner-top-left-shape: initial;
|
|
742
|
+
corner-top-right-shape: initial;
|
|
743
|
+
corner-bottom-right-shape: initial;
|
|
744
|
+
corner-bottom-left-shape: initial;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
`),e.hasQ&&n.push(`
|
|
748
|
+
.polycss-scene q {
|
|
749
|
+
position: absolute;
|
|
750
|
+
display: block;
|
|
751
|
+
transform-origin: 0 0;
|
|
752
|
+
transform-style: preserve-3d;
|
|
753
|
+
margin: 0;
|
|
754
|
+
padding: 0;
|
|
755
|
+
font: inherit;
|
|
756
|
+
font-weight: normal;
|
|
757
|
+
font-style: normal;
|
|
758
|
+
line-height: 0;
|
|
759
|
+
text-decoration: none;
|
|
760
|
+
backface-visibility: visible;
|
|
761
|
+
border-color: currentColor;
|
|
762
|
+
pointer-events: none;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
.polycss-scene q::before,
|
|
766
|
+
.polycss-scene q::after {
|
|
767
|
+
content: none;
|
|
768
|
+
}
|
|
769
|
+
`),e.hasTransformGizmo){let t=e.leafTags.length>0?e.leafTags:Rr;n.push(`
|
|
770
|
+
${wn(t,".polycss-mesh.polycss-transform-gizmo ")} {
|
|
771
|
+
backface-visibility: visible;
|
|
772
|
+
transition: color 150ms ease-out, border-color 150ms ease-out, background-color 150ms ease-out;
|
|
773
|
+
}
|
|
774
|
+
`)}if(e.hasTransformRing){let t=e.leafTags.length>0?e.leafTags:Rr;n.push(`
|
|
775
|
+
${wn(t,".polycss-mesh.polycss-transform-ring ")} {
|
|
776
|
+
--ring-inner-r: calc(var(--ring-inner-ratio, 0.92) * 50%);
|
|
777
|
+
--ring-outer-r: calc(var(--ring-outer-ratio, 1) * 50%);
|
|
778
|
+
-webkit-mask: radial-gradient(circle at 50% 50%,
|
|
779
|
+
transparent 0%,
|
|
780
|
+
transparent var(--ring-inner-r),
|
|
781
|
+
black var(--ring-inner-r),
|
|
782
|
+
black var(--ring-outer-r),
|
|
783
|
+
transparent var(--ring-outer-r));
|
|
784
|
+
mask: radial-gradient(circle at 50% 50%,
|
|
785
|
+
transparent 0%,
|
|
786
|
+
transparent var(--ring-inner-r),
|
|
787
|
+
black var(--ring-inner-r),
|
|
788
|
+
black var(--ring-outer-r),
|
|
789
|
+
transparent var(--ring-outer-r));
|
|
790
|
+
}
|
|
791
|
+
`)}return e.hasDynamicLighting&&n.push(mc(e)),n.map(t=>t.trim()).filter(Boolean).join(`
|
|
792
|
+
|
|
793
|
+
`)}function Or(e){let n=e.style;return n&&typeof n.getPropertyValue=="function"?n:null}function yi(e){let n=e.getAttribute("style");n!==null&&n.trim()===""&&e.removeAttribute("style")}function hc(e,n){let t=e;for(;t;){let o=Or(t)?.getPropertyValue(n).trim();if(o)return o;t=t.parentElement}return""}function gc(e,n,t){let o=Mn(e),r=Mn(n);for(let s=0;s<r.length;s++){let i=o[s],c=r[s];if(!i||!c)continue;let l=Or(c);if(!l)continue;if(c.classList.contains("polycss-mesh")){let d=l.getPropertyValue("--origin").trim();d&&(l.setProperty("transform-origin",d),l.removeProperty("--origin"))}let u=c.tagName.toLowerCase();if(u==="s"){let d=l.getPropertyValue("--polycss-atlas-size").trim();if(d&&(l.setProperty("width",d),l.setProperty("height",d)),t.hasDynamicLighting)l.removeProperty("--polycss-atlas-size");else for(let x of ac)l.removeProperty(x)}else if(u==="b"||u==="i"||u==="u"){let d=hc(i,"--polycss-paint"),x=t.hasDynamicLighting?"":i.ownerDocument.defaultView?.getComputedStyle(i).color;x?l.setProperty("color",x):d&&!l.getPropertyValue("color")&&l.setProperty("color",d)}if(!t.hasDynamicLighting)for(let d of sc)l.removeProperty(d);if(!t.hasQ)for(let d of ic)l.removeProperty(d);l.removeProperty("will-change"),l.removeProperty("--polycss-paint"),yi(c)}}function yc(e){for(let n of Array.from(e.querySelectorAll("script")))n.remove();for(let n of Mn(e))for(let t of Array.from(n.attributes))t.name.toLowerCase().startsWith("on")&&n.removeAttribute(t.name)}function bi(e){let n=e.trim();return n===""||n.startsWith("#")||/^data:/i.test(n)}function bc(e,n){return/^data:/i.test(e.trim())?e.trim():vi(e,n.baseUrl)}function gi(e){let n=/url\(\s*(?:(["'])(.*?)\1|([^)]*?))\s*\)/i.exec(e);return(n?.[2]??n?.[3]??"").trim()||null}function vc(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\a ")}function vi(e,n){try{return new URL(e,n).href}catch{throw new At("ASSET_INLINE_FAILED",`exportPolySceneSnapshot: could not resolve asset URL "${e}".`,e)}}function xc(e){let n=(()=>{try{return new URL(e).pathname.toLowerCase()}catch{return e.toLowerCase()}})();return n.endsWith(".jpg")||n.endsWith(".jpeg")?"image/jpeg":n.endsWith(".png")?"image/png":n.endsWith(".webp")?"image/webp":n.endsWith(".gif")?"image/gif":n.endsWith(".svg")?"image/svg+xml":n.endsWith(".avif")?"image/avif":"application/octet-stream"}function Pc(e){let n=new Uint8Array(e),t=32768,o="";for(let r=0;r<n.length;r+=t){let s=n.subarray(r,r+t);o+=String.fromCharCode(...s)}return btoa(o)}function Sc(e){return/^(blob|filesystem):/i.test(e.trim())}function Cc(e){return new Promise((n,t)=>{let o=new XMLHttpRequest;o.open("GET",e,!0),o.responseType="blob",o.onload=()=>{o.status===0||o.status>=200&&o.status<300?n(o.response):t(new Error(`XHR ${o.status}`))},o.onerror=()=>t(new Error("XHR request failed")),o.send()})}async function Ec(e){let n=Sc(e);try{if(typeof fetch!="function")throw new Error("fetch is not available");let t=await fetch(e,n?void 0:{credentials:"same-origin"});if(!t.ok)throw new Error(`HTTP ${t.status}`);return await t.blob()}catch(t){if(n&&typeof XMLHttpRequest=="function")return Cc(e);throw t}}async function xi(e,n){if(bi(e))return e;let t=vi(e,n.baseUrl),o=n.cache.get(t);if(o)return o;let r=(async()=>{try{let s=await Ec(t),i=s.type||xc(t),c=Pc(await s.arrayBuffer());return`data:${i};base64,${c}`}catch{throw new At("ASSET_INLINE_FAILED",`exportPolySceneSnapshot: could not inline asset "${t}".`,t)}})();return n.cache.set(t,r),r}async function kr(e,n){let t=/url\(\s*(?:(["'])(.*?)\1|([^)]*?))\s*\)/gi,o="",r=0,s;for(;(s=t.exec(e))!==null;){o+=e.slice(r,s.index);let i=(s[2]??s[3]??"").trim(),c=await xi(i,n);o+=bi(i)?s[0]:`url("${c}")`,r=t.lastIndex}return o+e.slice(r)}async function Tc(e,n){for(let t of Mn(e)){let o=t.getAttribute("style");o&&t.setAttribute("style",await kr(o,n))}for(let t of Array.from(e.querySelectorAll("style")))t.textContent=await kr(t.textContent??"",n)}function Ac(e){return{position:e.getPropertyValue("background-position").trim(),size:e.getPropertyValue("background-size").trim(),repeat:e.getPropertyValue("background-repeat").trim()}}function wc(e,n){n.position&&e.setProperty("background-position",n.position),n.size&&e.setProperty("background-size",n.size),n.repeat&&e.setProperty("background-repeat",n.repeat)}async function Mc(e,n){let t=[],o=new Map,r=new Map,s=async l=>{let u=bc(l,n),d=o.get(u);if(d)return d;let x=`a${o.size}`;return o.set(u,x),r.set(u,await xi(l,n)),x},i=l=>{for(let[u,d]of o)if(d===l)return r.get(u)??"";return""};for(let l of Mn(e)){let u=Or(l);if(!u||l.tagName.toLowerCase()!=="s")continue;let d=gi(u.getPropertyValue("--polycss-atlas-url"));if(d&&!d.startsWith("#")){let P=await s(d),g="data-polycss-snapshot-atlas";l.setAttribute(g,P),u.removeProperty("--polycss-atlas-url"),t.push({attr:g,value:P,property:"--polycss-atlas-url",dataUrl:i(P)})}let x=gi(u.getPropertyValue("background-image"));if(!x||x.startsWith("#"))continue;let h=await s(x),b="data-polycss-snapshot-bg",v=Ac(u);l.setAttribute(b,h),u.removeProperty("background"),u.removeProperty("background-image"),wc(u,v),t.push({attr:b,value:h,property:"background-image",dataUrl:i(h)}),yi(l)}let c=new Set;return t.filter(l=>{let u=`${l.attr}|${l.value}|${l.property}`;return c.has(u)?!1:(c.add(u),!0)}).map(l=>`.polycss-scene [${l.attr}="${l.value}"] {
|
|
794
|
+
${l.property}: url("${vc(l.dataUrl)}");
|
|
795
|
+
}`).join(`
|
|
796
|
+
|
|
797
|
+
`)}function Lc(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function _c(e){return e.replace(/<\/style/gi,"<\\/style")}function Rc(e){return e.baseURI||e.URL||e.defaultView?.location.href||"http://localhost/"}async function Pi(e){if(!lc(e))throw new At("INVALID_TARGET","exportPolySceneSnapshot: target must be an Element.");let n=cc(e);if(!n)throw new At("SCENE_NOT_FOUND","exportPolySceneSnapshot: target is not inside and does not contain a rendered PolyCSS scene.");let t=e.ownerDocument,o={baseUrl:Rc(t),cache:new Map},r=n.cloneNode(!0),s=uc(r);gc(n,r,s),yc(r);let i=await Mc(r,o);await Tc(r,o);let c=await kr([fc(s),i].filter(Boolean).join(`
|
|
798
|
+
|
|
799
|
+
`),o);return["<!doctype html>","<html>","<head>",'<meta charset="utf-8">',t.title?`<title>${Lc(t.title)}</title>`:"",`<style>${_c(c)}</style>`,"</head>","<body>",r.outerHTML,"</body>","</html>"].filter(Boolean).join("")}var Pe=require("@layoutit/polycss-core");function ot(e){return{polygons:e,objectUrls:[],warnings:[],dispose:()=>{}}}function Si(e={}){return ot((0,Pe.boxPolygons)(e))}function Ci(e){return ot((0,Pe.planePolygons)(e))}function Ei(e){return ot((0,Pe.ringPolygons)(e))}function Ti(e){return ot((0,Pe.octahedronPolygons)(e))}function Ai(e={}){return ot((0,Pe.spherePolygons)(e))}function wi(e={}){return ot((0,Pe.tetrahedronPolygons)(e))}function Mi(e={}){return ot((0,Pe.icosahedronPolygons)(e))}function Li(e={}){return ot((0,Pe.dodecahedronPolygons)(e))}function _i(e={}){return ot((0,Pe.cylinderPolygons)(e))}function Ri(e={}){return ot((0,Pe.conePolygons)(e))}function ki(e={}){return ot((0,Pe.torusPolygons)(e))}var ye=require("@layoutit/polycss-core"),kc=typeof HTMLElement<"u"?HTMLElement:class{};function Oc(e){return e.closest("poly-scene")??null}function Se(e,n,t){let o=e.getAttribute(n);if(!o)return t;let r=parseFloat(o);return Number.isFinite(r)?r:t}function rt(e,n,t){return e.getAttribute(n)??t}function Ht(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 Dc(e){if(e.length===0)return e;let n=(0,ye.computeSceneBbox)(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s)}))}var Ne=class extends kc{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:Ht(this,"position"),scale:(()=>{let s=this.getAttribute("scale");if(!s)return;if(s.includes(","))return Ht(this,"scale");let i=parseFloat(s);return Number.isFinite(i)?i:void 0})(),rotation:Ht(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=Oc(this);if(!t)return;let o=t.getScene?.();if(!o)return;let r=this.buildPolygons();this.hasAttribute("auto-center")&&(r=Dc(r));let s={polygons:r,objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(s,{position:Ht(this,"position"),scale:(()=>{let i=this.getAttribute("scale");if(!i)return;if(i.includes(","))return Ht(this,"scale");let c=parseFloat(i);return Number.isFinite(c)?c:void 0})(),rotation:Ht(this,"rotation"),castShadow:this.hasAttribute("cast-shadow"),receiveShadow:this.hasAttribute("receive-shadow"),excludeFromAutoCenter:this.hasAttribute("exclude-from-auto-center"),merge:!1})}},Co=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("size"),t=n?parseFloat(n):void 0;return(0,ye.boxPolygons)({size:t!==void 0&&Number.isFinite(t)?t:void 0,color:rt(this,"color")})}},Eo=class extends Ne{static get observedAttributes(){return["axis","size","offset","color","auto-center","position","scale","rotation","cast-shadow","receive-shadow"]}buildPolygons(){let n=Se(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("offset"),r=o===null?0:parseFloat(o);return(0,ye.planePolygons)({axis:t,size:Se(this,"size",.4),offset:Number.isFinite(r)?r:0,color:rt(this,"color")})}},To=class extends Ne{static get observedAttributes(){return["axis","radius","segments","half-thickness","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=Se(this,"axis",2),t=n===0||n===1||n===2?n:2,o=this.getAttribute("half-thickness");return(0,ye.ringPolygons)({axis:t,radius:Se(this,"radius",50),segments:Se(this,"segments",32),halfThickness:o?parseFloat(o):void 0,color:rt(this,"color")})}},Ao=class extends Ne{static get observedAttributes(){return["size","color","center","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.octahedronPolygons)({center:Ht(this,"center")??[0,0,0],size:Se(this,"size",50),color:rt(this,"color")})}},wo=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.tetrahedronPolygons)({size:Se(this,"size",100),color:rt(this,"color")})}},Mo=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.icosahedronPolygons)({size:Se(this,"size",100),color:rt(this,"color")})}},Lo=class extends Ne{static get observedAttributes(){return["size","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.dodecahedronPolygons)({size:Se(this,"size",100),color:rt(this,"color")})}},_o=class extends Ne{static get observedAttributes(){return["radius","subdivisions","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.spherePolygons)({radius:Se(this,"radius",50),subdivisions:Se(this,"subdivisions",1),color:rt(this,"color")})}},Ro=class extends Ne{static get observedAttributes(){return["radius","radius-top","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){let n=this.getAttribute("radius-top");return(0,ye.cylinderPolygons)({radius:Se(this,"radius",50),radiusTop:n?parseFloat(n):void 0,height:Se(this,"height",100),radialSegments:Se(this,"radial-segments",12),color:rt(this,"color")})}},ko=class extends Ne{static get observedAttributes(){return["radius","height","radial-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.conePolygons)({radius:Se(this,"radius",50),height:Se(this,"height",100),radialSegments:Se(this,"radial-segments",12),color:rt(this,"color")})}},Oo=class extends Ne{static get observedAttributes(){return["radius","tube","radial-segments","tubular-segments","color","auto-center","position","scale","rotation"]}buildPolygons(){return(0,ye.torusPolygons)({radius:Se(this,"radius",50),tube:Se(this,"tube",15),radialSegments:Se(this,"radial-segments",12),tubularSegments:Se(this,"tubular-segments",16),color:rt(this,"color")})}};pe(le,require("@layoutit/polycss-core"),module.exports);0&&(module.exports={PolyBoxElement,PolyCameraElement,PolyConeElement,PolyCylinderElement,PolyDodecahedronElement,PolyFirstPersonControlsElement,PolyIcosahedronElement,PolyIframeElement,PolyMapControlsElement,PolyMeshElement,PolyOctahedronElement,PolyOrbitControlsElement,PolyOrthographicCameraElement,PolyPerspectiveCameraElement,PolyPlaneElement,PolyPolygonElement,PolyRingElement,PolySceneElement,PolySceneSnapshotError,PolySelectElement,PolySphereElement,PolyTetrahedronElement,PolyTorusElement,PolyTransformControlsElement,buildAtlasPages,buildPolyMeshTransform,buildTextureEdgeRepairSets,collectPolyRenderStats,computeTextureAtlasPlanPublic,createPolyBox,createPolyCamera,createPolyCone,createPolyCylinder,createPolyDodecahedron,createPolyFirstPersonControls,createPolyIcosahedron,createPolyMapControls,createPolyOctahedron,createPolyOrbitControls,createPolyOrthographicCamera,createPolyPerspectiveCamera,createPolyPlane,createPolyRing,createPolyScene,createPolySphere,createPolyTetrahedron,createPolyTorus,createSelect,createTransformControls,cssBorderShapeForPlan,exportPolySceneSnapshot,filterAtlasPlans,formatBorderShapeEntryMatrix,formatCssLengthPx,formatMatrix3d,formatSolidQuadEntryMatrix,getSolidPaintDefaults,getSolidPaintDefaultsFromPlans,injectPolyBaseStyles,isBorderShapeSupported,isFullRectSolid,isProjectiveQuadPlan,isSolidTrianglePlan,isSolidTriangleSupported,packTextureAtlasPlansWithScale,renderPolygonsWithStableTriangles,renderPolygonsWithTextureAtlas,renderPolygonsWithTextureAtlasAsync,updatePolygonsWithStableTopology,updatePolygonsWithStableTriangles,updateStableTriangleFrame,worldDirectionToPolyCss,worldPositionToPolyCss,...require("@layoutit/polycss-core")});
|