@layoutit/polycss 0.0.1

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.
@@ -0,0 +1,220 @@
1
+ import { P as PolySceneHandle, a as PolyMeshHandle } from './PolySelectElement-DCuYJb5J.js';
2
+ export { b as PolyCameraOptions, c as PolyMapControlsElement, d as PolyMeshElement, e as PolyMeshTransform, f as PolyOrbitControlsElement, g as PolyOrthographicCameraElement, h as PolyOrthographicCameraHandle, i as PolyOrthographicCameraOptions, j as PolyPerspectiveCameraElement, k as PolyPerspectiveCameraHandle, l as PolyPerspectiveCameraOptions, m as PolyPolygonElement, n as PolySceneElement, o as PolySceneOptions, p as PolySelectElement, q as PolyTransformControlsElement, r as createPolyOrthographicCamera, s as createPolyPerspectiveCamera, t as createPolyScene } from './PolySelectElement-DCuYJb5J.js';
3
+ import { Vec3 } from '@layoutit/polycss-core';
4
+ export * from '@layoutit/polycss-core';
5
+
6
+ /**
7
+ * Shared types, constants, and utilities for orbit/map controls factories.
8
+ * Not part of the public API surface — use createPolyOrbitControls or
9
+ * createPolyMapControls.
10
+ */
11
+
12
+ interface PolyControlsAnimateOptions {
13
+ /**
14
+ * Rotation rate in degrees per 60 Hz-equivalent frame. The tick is
15
+ * dt-clamped so 0.3 deg/frame ≈ 18 deg/sec on every refresh rate.
16
+ * Default: 0.3.
17
+ */
18
+ speed?: number;
19
+ /** Rotation axis. Default: "y" (yaw, rotates around vertical world Z). */
20
+ axis?: "x" | "y";
21
+ /** Halt the loop while a pointer drag is in progress. Default: true. */
22
+ pauseOnInteraction?: boolean;
23
+ }
24
+ interface PolyControlsBaseOptions {
25
+ /** Pointer-drag. Default: true. */
26
+ drag?: boolean;
27
+ /** Wheel / pinch zoom. Default: true. */
28
+ wheel?: boolean;
29
+ /**
30
+ * When `true`, wheel events change `distance` (camera pull-back in CSS px)
31
+ * instead of `zoom`. Mirrors Three.js OrbitControls dolly behaviour.
32
+ * Default: false (zoom mode).
33
+ */
34
+ dolly?: boolean;
35
+ /**
36
+ * Drag-direction inversion. `false` = natural, `true` = invert (×-1),
37
+ * a number multiplies sensitivity (negative inverts). Default: false.
38
+ */
39
+ invert?: boolean | number;
40
+ /** Minimum CSS zoom. Default: 0.1. */
41
+ minZoom?: number;
42
+ /** Maximum CSS zoom. Default: 10. */
43
+ maxZoom?: number;
44
+ /** Minimum dolly distance in CSS pixels. Default: 0. Only used when `dolly: true`. */
45
+ minDistance?: number;
46
+ /** Maximum dolly distance in CSS pixels. Default: Infinity. Only used when `dolly: true`. */
47
+ maxDistance?: number;
48
+ /** Auto-rotate. Pass false (or omit) to disable. */
49
+ animate?: false | PolyControlsAnimateOptions;
50
+ }
51
+ interface PolyControlsCamera {
52
+ rotX: number;
53
+ rotY: number;
54
+ zoom: number;
55
+ target: Vec3;
56
+ distance: number;
57
+ }
58
+ interface PolyControlsChangeEvent {
59
+ type: "change";
60
+ camera: PolyControlsCamera;
61
+ }
62
+ interface PolyControlsInteractionEvent {
63
+ type: "start" | "end";
64
+ camera: PolyControlsCamera;
65
+ }
66
+ type PolyControlsEvent = PolyControlsChangeEvent | PolyControlsInteractionEvent;
67
+ type PolyControlsListener<E extends PolyControlsEvent = PolyControlsEvent> = (event: E) => void;
68
+ interface PolyControlsHandle {
69
+ update(partial: PolyControlsBaseOptions): void;
70
+ resume(): void;
71
+ pause(): void;
72
+ destroy(): void;
73
+ addEventListener<T extends PolyControlsEvent["type"]>(type: T, listener: PolyControlsListener<Extract<PolyControlsEvent, {
74
+ type: T;
75
+ }>>): void;
76
+ removeEventListener<T extends PolyControlsEvent["type"]>(type: T, listener: PolyControlsListener<Extract<PolyControlsEvent, {
77
+ type: T;
78
+ }>>): void;
79
+ hasEventListener<T extends PolyControlsEvent["type"]>(type: T, listener: PolyControlsListener<Extract<PolyControlsEvent, {
80
+ type: T;
81
+ }>>): boolean;
82
+ }
83
+
84
+ /**
85
+ * createPolyOrbitControls — orbit-mode camera input for a PolyScene.
86
+ *
87
+ * Left-drag rotates rotX / rotY around the target (orbit). Wheel zooms or
88
+ * dollies. Mirrors Three.js OrbitControls semantics.
89
+ *
90
+ * For map/pan semantics (left-drag pans, right-drag orbits) use
91
+ * `createPolyMapControls` instead.
92
+ */
93
+
94
+ type PolyOrbitControlsOptions = PolyControlsBaseOptions;
95
+ type PolyOrbitControlsHandle = PolyControlsHandle;
96
+ declare function createPolyOrbitControls(scene: PolySceneHandle, options?: PolyOrbitControlsOptions): PolyOrbitControlsHandle;
97
+
98
+ /**
99
+ * createPolyMapControls — map/pan-mode camera input for a PolyScene.
100
+ *
101
+ * Left-drag pans the target (slippy-map semantics — terrain follows pointer).
102
+ * Right-drag or Shift+left-drag orbits. Wheel zooms or dollies.
103
+ * Mirrors Three.js MapControls semantics.
104
+ *
105
+ * For orbit-only semantics (left-drag orbits) use `createPolyOrbitControls`
106
+ * instead.
107
+ */
108
+
109
+ type PolyMapControlsOptions = PolyControlsBaseOptions;
110
+ type PolyMapControlsHandle = PolyControlsHandle;
111
+ declare function createPolyMapControls(scene: PolySceneHandle, options?: PolyMapControlsOptions): PolyMapControlsHandle;
112
+
113
+ /**
114
+ * createSelect — additive selection layer for vanilla polycss scenes.
115
+ * Mirrors the React `<Select>` API: tracks one or more selected
116
+ * meshes, fires `onChange` whenever the set changes, supports
117
+ * single-click toggle (re-clicking the selected mesh deselects it),
118
+ * shift/meta/ctrl + click for multi-select extension, and a JS bbox
119
+ * hit-test fallback for clicks that fall through native polygon
120
+ * hit-testing (e.g. CSS `border-shape` clipping).
121
+ *
122
+ * Usage:
123
+ * const select = createSelect(scene, { onChange: (meshes) => ... });
124
+ * select.set([handle]); // imperative selection
125
+ * select.toggle(handle);
126
+ * select.clear();
127
+ * select.destroy(); // remove listeners
128
+ */
129
+
130
+ interface PolySelectOptions {
131
+ /** Allow multiple meshes selected at once. Default false. */
132
+ multiple?: boolean;
133
+ /** When true (default), clicking the background clears selection.
134
+ * Set false to keep the current selection on background clicks. */
135
+ clearOnMiss?: boolean;
136
+ /** Optional filter applied to every selection change — return the
137
+ * array that should become the new selection (drop / reorder). */
138
+ filter?: (meshes: PolyMeshHandle[]) => PolyMeshHandle[];
139
+ /** Fires after every selection change with the new array. */
140
+ onChange?: (meshes: PolyMeshHandle[]) => void;
141
+ /** Fires when a click resolves to no mesh (background click). */
142
+ onPointerMissed?: (event: MouseEvent) => void;
143
+ }
144
+ interface PolySelectionHandle {
145
+ /** Current selection. Reference is stable until selection changes. */
146
+ readonly selected: ReadonlyArray<PolyMeshHandle>;
147
+ /** Replace selection wholesale. */
148
+ set(next: PolyMeshHandle[]): void;
149
+ /** Add to selection (or replace, when `multiple` is false). */
150
+ add(mesh: PolyMeshHandle): void;
151
+ /** Remove from selection. No-op if not present. */
152
+ remove(mesh: PolyMeshHandle): void;
153
+ /** Toggle membership. With single-mode, toggling a non-selected
154
+ * mesh replaces selection; toggling the selected mesh clears. */
155
+ toggle(mesh: PolyMeshHandle): void;
156
+ /** Clear selection. */
157
+ clear(): void;
158
+ /** Membership test. */
159
+ has(mesh: PolyMeshHandle): boolean;
160
+ /** Remove the host listener. Idempotent. */
161
+ destroy(): void;
162
+ }
163
+ declare function createSelect(scene: PolySceneHandle, options?: PolySelectOptions): PolySelectionHandle;
164
+
165
+ type Mode = "translate" | "rotate";
166
+ interface PolyTransformControlsObjectChangeEvent {
167
+ object: PolyMeshHandle;
168
+ position?: Vec3;
169
+ rotation?: Vec3;
170
+ }
171
+ interface PolyTransformControlsOptions {
172
+ /** Drag mode. "translate" → axial arrows, "rotate" → axial rings. */
173
+ mode?: Mode;
174
+ /** Multiplier on gizmo size (shaft length / ring radius). Default 1. */
175
+ size?: number;
176
+ /** Snap step (CSS pixels) for translate-mode. */
177
+ translationSnap?: number | null;
178
+ /** Snap step (degrees) for rotate-mode. */
179
+ rotationSnap?: number | null;
180
+ /** Show / hide axis pairs. Default true for all. */
181
+ showX?: boolean;
182
+ showY?: boolean;
183
+ showZ?: boolean;
184
+ /** Disable interaction without unmounting. Default true. */
185
+ enabled?: boolean;
186
+ /** Fires for any transform change. Argument-less, mirrors three.js. */
187
+ onChange?: () => void;
188
+ /** Fires with the new transform during drag. The gizmo also calls
189
+ * `target.setTransform` internally; this callback lets parent code
190
+ * mirror the change into its own state. */
191
+ onObjectChange?: (event: PolyTransformControlsObjectChangeEvent) => void;
192
+ /** Fires once on drag start. */
193
+ onMouseDown?: () => void;
194
+ /** Fires once on drag end. */
195
+ onMouseUp?: () => void;
196
+ /** Fires with `true` on drag start, `false` on drag end. */
197
+ onDraggingChanged?: (dragging: boolean) => void;
198
+ }
199
+ interface PolyTransformControlsHandle {
200
+ /** Bind to a mesh — gizmo follows the mesh's transform. Pass `null`
201
+ * to detach. Calling `attach` again with a new target swaps the
202
+ * binding without rebuilding the gizmo geometry. */
203
+ attach(mesh: PolyMeshHandle | null): void;
204
+ /** Equivalent to `attach(null)`. */
205
+ detach(): void;
206
+ /** Switch between translate and rotate. Tears down the old gizmo
207
+ * and rebuilds the new one. */
208
+ setMode(mode: Mode): void;
209
+ /** Re-read the target's transform and reposition the gizmo. Call
210
+ * after mutating `target.setTransform` externally if you want the
211
+ * gizmo to follow. */
212
+ update(): void;
213
+ /** Remove all listeners + gizmo meshes from the scene. Idempotent. */
214
+ destroy(): void;
215
+ }
216
+ declare function createTransformControls(scene: PolySceneHandle, options?: PolyTransformControlsOptions): PolyTransformControlsHandle;
217
+
218
+ declare function injectPolyBaseStyles(doc?: Document): void;
219
+
220
+ export { type PolyControlsAnimateOptions, type PolyControlsBaseOptions, type PolyControlsCamera, type PolyControlsChangeEvent, type PolyControlsEvent, type PolyControlsHandle, type PolyControlsInteractionEvent, type PolyControlsListener, type PolyMapControlsHandle, type PolyMapControlsOptions, PolyMeshHandle, type PolyOrbitControlsHandle, type PolyOrbitControlsOptions, PolySceneHandle, type PolySelectOptions, type PolySelectionHandle, type PolyTransformControlsHandle, type PolyTransformControlsObjectChangeEvent, type PolyTransformControlsOptions, createPolyMapControls, createPolyOrbitControls, createSelect, createTransformControls, injectPolyBaseStyles };
package/dist/index.js ADDED
@@ -0,0 +1,234 @@
1
+ import{BASE_TILE as qn,computeSceneBbox as Kn,inverseRotateVec3 as kt,mergePolygons as Jn,parseHexColor as Ht}from"@layoutit/polycss-core";import{parsePureColor as ct}from"@layoutit/polycss-core";var Re=50,ut=[.4,-.7,.59],dt="#ffffff",pt=1,mt="#ffffff",ft=.4,ce=4096,st=1,Ut=.1,Wt=1,ht=ce*ce,Zt=ht*3,ke=2048,He=16*1024*1024,Gt=.995,ae=new Map,De=new WeakMap,B=.001,K=1e-9,jt=1e-4,qt=.1,Kt=.75,Jt=0,Qt=.45,en=3,tn=2;function nn(e){let n=ae.get(e);return n||(n=new Promise((t,o)=>{let r=new Image;r.decoding="async",r.onload=()=>t(r),r.onerror=()=>o(new Error(`texture load failed: ${e}`)),r.src=e}),ae.set(e,n),n.then(()=>{ae.get(e)===n&&ae.delete(e)},()=>{ae.get(e)===n&&ae.delete(e)})),n}function xe(e){let n=typeof e=="string"?Number(e):e;return n===void 0||!Number.isFinite(n)?1:Math.min(Wt,Math.max(Ut,n))}function yt(e,n){let t=e.toFixed(n).replace(/\.?0+$/,"");return Object.is(Number(t),-0)?"0":t}function gt(e,n=en){return e.map(t=>yt(t,n)).join(",")}function ge(e,n=tn){return`${yt(e,n)}%`}function bt(e){return e.reduce((n,t)=>n+t.width*t.height,0)}function on(e){let n=bt(e);if(n<=0)return 1;let t=Math.max(1,...e.map(s=>Math.max(s.width,s.height))),o=ke/t,r=Math.sqrt(He/(n*4));return xe(Math.min(o,r))}function rn(e){let n=bt(e),t=.5;return n<=ht?t=1:n<=Zt&&(t=.75),xe(Math.min(t,on(e)))}function sn(e,n){return e.reduce((t,o)=>Math.max(t,Math.ceil(o.width*n),Math.ceil(o.height*n)),0)}function an(e,n){return e.reduce((t,o)=>t+Math.ceil(o.width*n)*Math.ceil(o.height*n)*4,0)}function ln(e,n){let t=sn(e,n),o=an(e,n),r=t>ke?ke/t:1,s=o>He?Math.sqrt(He/o):1;return Math.min(r,s)}function cn(e,n){let t=rn(n.pages),o=t===1?n:ve(e,t);for(let r=0;r<4;r++){let s=ln(o.pages,t);if(s>=1)break;let i=xe(t*s*Gt);if(i>=t)break;t=i,o=ve(e,t)}return{packed:o,atlasScale:t}}function un(e,n){if(n!==void 0&&n!=="auto"){let o=xe(n);return{packed:ve(e,o),atlasScale:o}}let t=ve(e,1);return cn(e,t)}function dn(e){return Math.max(st,Math.ceil(st/e))}function J(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 oe(e){let n=ct(e);return n?{r:n.rgb[0],g:n.rgb[1],b:n.rgb[2]}:{r:255,g:255,b:255}}function pn(e){return ct(e)?.alpha??1}function mn({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(n)}${o(t)}`}function vt(e,n,t,o,r){let s=oe(e),i=oe(t),c=oe(o),l=c.r/255*r+i.r/255*n,a=c.g/255*r+i.g/255*n,d=c.b/255*r+i.b/255*n,m=Math.max(0,Math.min(255,Math.round(s.r*l))),f=Math.max(0,Math.min(255,Math.round(s.g*a))),h=Math.max(0,Math.min(255,Math.round(s.b*d))),u=pn(e);return u<1?`rgba(${m}, ${f}, ${h}, ${u})`:mn({r:m,g:f,b:h})}function fn(e,n,t,o){let r=oe(n),s=oe(t);return{r:s.r/255*o+r.r/255*e,g:s.g/255*o+r.g/255*e,b:s.b/255*o+r.b/255*e}}function hn({r:e,g:n,b:t}){let o=r=>Math.round(Math.max(0,Math.min(1,r))*255);return`rgb(${o(e)} ${o(n)} ${o(t)})`}function yn(e,n,t,o,r,s,i){Math.abs(s.r-1)<.001&&Math.abs(s.g-1)<.001&&Math.abs(s.b-1)<.001||(e.save(),J(e,i),e.globalCompositeOperation="multiply",e.fillStyle=hn(s),e.fillRect(n,t,o,r),e.restore())}function gn(e,n,t,o,r,s,i){let c=n.naturalWidth||n.width||1,l=n.naturalHeight||n.height||1,a=Math.max(r/c,s/l),d=c*a,m=l*a;J(e,i),e.drawImage(n,t+(r-d)/2,o+(s-m)/2,d,m)}function be(e){return`${e[0]},${e[1]},${e[2]}`}function bn(e,n){let t=be(e),o=be(n);return t<o?`${t}|${o}`:`${o}|${t}`}function xt(e,n){return be(e)<be(n)?[n[0]-e[0],n[1]-e[1],n[2]-e[2]]:[e[0]-n[0],e[1]-n[1],e[2]-n[2]]}function vn(e){return!e.texture}function Pe(e,n,t){return e.map(o=>[o[1]*n,o[0]*n,o[2]*t])}function Ie(e){if(e.length<3)return null;let n=e[0],t=e[1],o=e[2],r=[t[0]-n[0],t[1]-n[1],t[2]-n[2]],s=[o[0]-n[0],o[1]-n[1],o[2]-n[2]],i=-(r[1]*s[2]-r[2]*s[1]),c=-(r[2]*s[0]-r[0]*s[2]),l=-(r[0]*s[1]-r[1]*s[0]),a=Math.hypot(i,c,l);return a<=K?null:(i/=a,c/=a,l/=a,[i,c,l])}function ue(e,n){return e[0]*n[0]+e[1]*n[1]+e[2]*n[2]}function xn(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function Pn(e,n,t){if(!e.vertices||e.vertices.length<3)return null;let o=Pe(e.vertices,n,t),r=Ie(o);return r?{pts:o,normal:r,planeD:ue(r,o[0]),optimizable:vn(e)}:null}function An(e,n){return!e||!n||!e.optimizable||!n.optimizable||ue(e.normal,n.normal)<1-jt?!1:Math.abs(e.planeD-n.planeD)<=qt}function En(e){let n=[...e],t=Math.abs(n[0])>K?0:Math.abs(n[1])>K?1:2;return n[t]<0&&(n[0]*=-1,n[1]*=-1,n[2]*=-1),`${n[0].toFixed(6)},${n[1].toFixed(6)},${n[2].toFixed(6)}`}function me(e,n,t,o,r={}){let s=ue(o,t),i=[o[0]-s*t[0],o[1]-s*t[1],o[2]-s*t[2]],c=Math.hypot(i[0],i[1],i[2]);if(c<=K)return null;let l=[i[0]/c,i[1]/c,i[2]/c],a=[t[1]*l[2]-t[2]*l[1],t[2]*l[0]-t[0]*l[2],t[0]*l[1]-t[1]*l[0]],d=Math.hypot(a[0],a[1],a[2]);if(d<=K)return null;let m=[a[0]/d,a[1]/d,a[2]/d],f=e.map(A=>{let P=A[0]-n[0],D=A[1]-n[1],k=A[2]-n[2];return[P*l[0]+D*l[1]+k*l[2],P*m[0]+D*m[1]+k*m[2]]}),h=r.boundsOrigin??n,u=n[0]-h[0],p=n[1]-h[1],b=n[2]-h[2],x=u*l[0]+p*l[1]+b*l[2],C=u*m[0]+p*m[1]+b*m[2],M=1/0,H=1/0,y=-1/0,g=-1/0;for(let[A,P]of f){let D=A+x,k=P+C;D<M&&(M=D),D>y&&(y=D),k<H&&(H=k),k>g&&(g=k)}let _=y-M,E=g-H;if(!Number.isFinite(_)||!Number.isFinite(E))return null;let w=r.snapBounds?Math.floor(M+B):M,S=r.snapBounds?Math.floor(H+B):H,v=r.snapBounds?Math.ceil(y-B):y,O=r.snapBounds?Math.ceil(g-B):g,T=Math.max(1,r.snapBounds?v-w:Math.ceil(_)),R=Math.max(1,r.snapBounds?O-S:Math.ceil(E));return{xAxis:l,yAxis:m,local2D:f,shiftX:x-w,shiftY:C-S,canvasW:T,canvasH:R,pixelArea:T*R,rawArea:_*E}}function Cn(e,n,t,o){let r=0,s=0;for(let i of e){let c=n[i];if(!c)return null;let l=me(c.pts,c.pts[0],c.normal,t,{boundsOrigin:o,snapBounds:!0});if(!l)return null;r+=l.pixelArea,s+=l.rawArea}return{pixelArea:r,rawArea:s}}function Mn(e,n){let t=n[e[0]]?.pts[0];if(!t)return null;let o={pixelArea:0,rawArea:0},r=null,s=new Set;for(let i of e){let c=n[i];if(!c)continue;let l=[c.pts[1][0]-c.pts[0][0],c.pts[1][1]-c.pts[0][1],c.pts[1][2]-c.pts[0][2]],a=me(c.pts,c.pts[0],c.normal,l);o&&a?(o.pixelArea+=a.pixelArea,o.rawArea+=a.rawArea):o=null;for(let d=0;d<c.pts.length;d++){let m=xt(c.pts[d],c.pts[(d+1)%c.pts.length]),f=me(c.pts,c.pts[0],c.normal,m);if(!f)continue;let h=En(f.xAxis);if(s.has(h))continue;s.add(h);let u=Cn(e,n,f.xAxis,t);u&&(!r||u.pixelArea<r.pixelArea||u.pixelArea===r.pixelArea&&u.rawArea<r.rawArea-B)&&(r={xAxis:f.xAxis,...u})}}return r&&o&&(r.pixelArea<o.pixelArea||r.pixelArea===o.pixelArea&&r.rawArea<=o.rawArea+B)?{xAxis:r.xAxis,boundsOrigin:t,seamEdges:new Set}:null}function Tn(e,n){let t=n.tileSize??Re,o=n.layerElevation??t,r=e.map(d=>Pn(d,t,o)),s=new Map,i=e.map(()=>new Set);for(let d=0;d<e.length;d++){let m=e[d].vertices;if(!(!m||m.length<3))for(let f=0;f<m.length;f++){let h=bn(m[f],m[(f+1)%m.length]),u=s.get(h),p={polygon:d,edge:f};u?u.push(p):s.set(h,[p])}}let c=e.map(()=>new Set);for(let d of s.values())if(!(d.length<2)){for(let m of d)i[m.polygon].add(m.edge);for(let m=0;m<d.length;m++)for(let f=m+1;f<d.length;f++){let h=d[m].polygon,u=d[f].polygon;An(r[h],r[u])&&(c[h].add(u),c[u].add(h))}}let l=Array(e.length).fill(void 0),a=new Set;for(let d=0;d<e.length;d++){if(a.has(d)||!r[d]?.optimizable)continue;let m=[],f=[d];for(a.add(d);f.length>0;){let u=f.pop();m.push(u);for(let p of c[u])a.has(p)||(a.add(p),f.push(p))}if(m.length<2)continue;let h=Mn(m,r);if(h)for(let u of m)l[u]={xAxis:h.xAxis,boundsOrigin:h.boundsOrigin,seamEdges:i[u]}}for(let d=0;d<e.length;d++)!l[d]&&i[d].size>0&&(l[d]={seamEdges:i[d]});return l}function Ln(e){if(typeof e.toBlob=="function")return new Promise(n=>{e.toBlob(t=>{n(t?URL.createObjectURL(t):null)},"image/png")});try{return Promise.resolve(e.toDataURL("image/png"))}catch{return Promise.resolve(null)}}function it(e,n,t,o){if(o.optimize&&o.fixedXAxis)return me(e,n,t,o.fixedXAxis,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});let r=null,s=o.optimize&&o.seamEdges&&o.seamEdges.size>0?Array.from(o.seamEdges):null,i=s??(o.optimize?e.map((c,l)=>l):[0]);for(let c of i){let l=(c+1)%e.length,a=s?xt(e[c],e[l]):[e[l][0]-e[c][0],e[l][1]-e[c][1],e[l][2]-e[c][2]],d=me(e,n,t,a,{boundsOrigin:o.boundsOrigin,snapBounds:o.snapBounds});d&&(!r||d.pixelArea<r.pixelArea||d.pixelArea===r.pixelArea&&d.rawArea<r.rawArea-B)&&(r=d)}return r}function Sn(e){if(e.local2D.length!==4)return!1;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=B)return;r.push(s)};for(let[r,s]of e.local2D)o(n,r+e.shiftX),o(t,s+e.shiftY);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>B||Math.abs(t[0])>B||n[1]-n[0]<=B||t[1]-t[0]<=B))return!1;for(let[r,s]of e.local2D){let i=r+e.shiftX,c=s+e.shiftY,l=Math.abs(i-n[0])<=B||Math.abs(i-n[1])<=B,a=Math.abs(c-t[0])<=B||Math.abs(c-t[1])<=B;if(!l||!a)return!1}return!0}function Pt(e,n){if(e.length<3||n.length<3)return null;let[t,o,r]=e,[s,i,c]=n,l=t[0],a=t[1],d=o[0],m=o[1],f=r[0],h=r[1],u=s[0],p=1-s[1],b=i[0],x=1-i[1],C=c[0],M=1-c[1],H=b-u,y=x-p,g=C-u,_=M-p,E=H*_-g*y;if(Math.abs(E)<=1e-9)return null;let w=d-l,S=f-l,v=m-a,O=h-a,T={a:(w*_-S*y)/E,b:(H*S-g*w)/E,c:(v*_-O*y)/E,d:(H*O-g*v)/E,e:0,f:0};return T.e=l-T.a*u-T.b*p,T.f=a-T.c*u-T.d*p,T}function At(e){if(e.length===0)return null;let n=1/0,t=1/0,o=-1/0,r=-1/0;for(let s of e){let i=s[0],c=1-s[1];if(!Number.isFinite(i)||!Number.isFinite(c))return null;n=Math.min(n,i),o=Math.max(o,i),t=Math.min(t,c),r=Math.max(r,c)}return{minU:n,minV:t,maxU:o,maxV:r}}function _n(e,n,t,o,r,s,i,c){let a=Pe(e.vertices,n,t).map(f=>{let h=f[0]-o[0],u=f[1]-o[1],p=f[2]-o[2];return[h*r[0]+u*r[1]+p*r[2]+i,h*s[0]+u*s[1]+p*s[2]+c]}),d=Pt(a,e.uvs),m=At(e.uvs);return!d&&!m?null:{screenPts:a.flatMap(([f,h])=>[f,h]),uvAffine:d,uvSampleRect:m}}function wn(e,n){if(e.length<6||n<=0)return e;let t=0,o=0,r=e.length/2;for(let i=0;i<e.length;i+=2)t+=e[i],o+=e[i+1];t/=r,o/=r;let s=e.slice();for(let i=0;i<s.length;i+=2){let c=s[i]-t,l=s[i+1]-o,a=Math.hypot(c,l);a<=B||(s[i]+=c/a*n,s[i+1]+=l/a*n)}return s}function On(e){let n=0;for(let t=0;t<e.length;t+=2){let o=(t+2)%e.length;n+=e[t]*e[o+1]-e[o]*e[t+1]}return n/2}function Ve(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 kn(e,n,t,o,r,s){if(Ve(e,n,t,o),!r||r.size===0||s<=0)return;let i=o.length/2,c=On(o);for(let l of r){let a=l*2,d=(l+1)%i*2,m=o[a],f=o[a+1],h=o[d],u=o[d+1],p=h-m,b=u-f,x=Math.hypot(p,b);if(x<=B)continue;let C=c>=0?b/x:-b/x,M=c>=0?-p/x:p/x;e.moveTo(n+m,t+f),e.lineTo(n+h,t+u),e.lineTo(n+h+C*s,t+u+M*s),e.lineTo(n+m+C*s,t+f+M*s),e.closePath()}}function Hn(e,n,t,o){let{vertices:r,texture:s,uvs:i}=e;if(!r||r.length<3)return null;let c=t.tileSize??Re,l=t.layerElevation??c,a=Pe(r,c,l),d=a[0],m=a[1],f=[m[0]-d[0],m[1]-d[1],m[2]-d[2]];if(Math.hypot(f[0],f[1],f[2])===0)return null;let u=Ie(a);if(!u)return null;let p=it(a,d,u,{optimize:!1}),b=s||p&&Sn(p)?p:it(a,d,u,{optimize:!0,fixedXAxis:o?.xAxis,boundsOrigin:o?.boundsOrigin,snapBounds:!!o,seamEdges:o?.seamEdges});if(!b)return null;let{xAxis:x,yAxis:C,local2D:M,shiftX:H,shiftY:y}=b,g=[];for(let[Y,z]of M)g.push(Y+H,z+y);let _=d[0]-H*x[0]-y*C[0],E=d[1]-H*x[1]-y*C[1],w=d[2]-H*x[2]-y*C[2],S=gt([x[0],x[1],x[2],0,C[0],C[1],C[2],0,u[0],u[1],u[2],0,_,E,w,1]),v=t.directionalLight,O=t.ambientLight,T=v?.direction??ut,R=v?.color??dt,A=Math.max(0,v?.intensity??pt),P=O?.color??mt,D=Math.max(0,O?.intensity??ft),k=Math.hypot(T[0],T[1],T[2])||1,F=T[0]/k,Z=T[1]/k,L=T[2]/k,I=A*Math.max(0,u[0]*F+u[1]*Z+u[2]*L),V=fn(I,R,P,D),X=vt(e.color??"#cccccc",I,R,P,D),$=null,U=null;s&&i&&i.length>=3&&i.length===r.length&&(U=At(i),$=Pt(M.map(([Y,z])=>[Y+H,z+y]),i));let W=s&&e.textureTriangles?.length?e.textureTriangles.map(Y=>_n(Y,c,l,d,x,C,H,y)).filter(Y=>!!Y):null;return{index:n,polygon:e,texture:s,tileSize:c,layerElevation:l,matrix:S,canvasW:b.canvasW,canvasH:b.canvasH,screenPts:g,uvAffine:$,uvSampleRect:U,textureTriangles:W,seamEdges:o?.seamEdges.size?o.seamEdges:null,normal:u,textureTint:V,shadedColor:X}}function Et(e,n,t){if(e.texture||e.vertices.length!==3)return null;let o=t.tileSize??Re,r=t.layerElevation??o,s=Pe(e.vertices,o,r),i=Ie(s);if(!i)return null;let c=[{a:0,b:1,c:2},{a:1,b:2,c:0},{a:2,b:0,c:1}].map(q=>{let G=s[q.a],te=s[q.b];return{...q,length:Math.hypot(te[0]-G[0],te[1]-G[1],te[2]-G[2])}}).sort((q,G)=>G.length-q.length),l=c[0].a,a=c[0].b,d=c[0].c,m=s[l],f=s[a],h=s[d],u=c[0].length;if(u<=K)return null;let p=[(f[0]-m[0])/u,(f[1]-m[1])/u,(f[2]-m[2])/u],b=[h[0]-m[0],h[1]-m[1],h[2]-m[2]],x=ue(b,p),C=[m[0]+p[0]*x,m[1]+p[1]*x,m[2]+p[2]*x],M=[C[0]-h[0],C[1]-h[1],C[2]-h[2]],H=Math.hypot(M[0],M[1],M[2]);if(H<=K)return null;let y=[M[0]/H,M[1]/H,M[2]/H];if(ue(xn(p,y),i)<0){let q=a;if(a=l,l=q,m=s[l],f=s[a],u=Math.hypot(f[0]-m[0],f[1]-m[1],f[2]-m[2]),u<=K)return null;p=[(f[0]-m[0])/u,(f[1]-m[1])/u,(f[2]-m[2])/u];let G=[h[0]-m[0],h[1]-m[1],h[2]-m[2]];x=ue(G,p),C=[m[0]+p[0]*x,m[1]+p[1]*x,m[2]+p[2]*x],M=[C[0]-h[0],C[1]-h[1],C[2]-h[2]];let te=Math.hypot(M[0],M[1],M[2]);if(te<=K)return null;y=[M[0]/te,M[1]/te,M[2]/te]}let g=Math.max(0,Math.min(u,x)),_=Math.max(0,u-g),E=Qt,w=g+E,S=_+E,v=H+E*2,O=h[0]-w*p[0]-E*y[0],T=h[1]-w*p[1]-E*y[1],R=h[2]-w*p[2]-E*y[2],A=gt([p[0],p[1],p[2],0,y[0],y[1],y[2],0,i[0],i[1],i[2],0,O,T,R,1]),P=t.directionalLight,D=t.ambientLight,k=P?.direction??ut,F=P?.color??dt,Z=Math.max(0,P?.intensity??pt),L=D?.color??mt,I=Math.max(0,D?.intensity??ft),V=Math.hypot(k[0],k[1],k[2])||1,X=k[0]/V,$=k[1]/V,U=k[2]/V,W=Z*Math.max(0,i[0]*X+i[1]*$+i[2]*U),Y=vt(e.color??"#cccccc",W,F,L,I),z=t.textureLighting??"baked",Q=oe(e.color??"#cccccc"),ie=z==="dynamic"?"":`border-bottom-color:${Y};`,ee=z==="dynamic"?`--pnx:${i[0].toFixed(4)};--pny:${i[1].toFixed(4)};--pnz:${i[2].toFixed(4)};--psr:${(Q.r/255).toFixed(4)};--psg:${(Q.g/255).toFixed(4)};--psb:${(Q.b/255).toFixed(4)};`:"",Oe=`transform:matrix3d(${A});border-width:0 ${S}px ${v}px ${w}px;`+ie+ee;return{index:n,polygon:e,styleText:Oe}}function ve(e,n=1){let t=Array(e.length).fill(null),o=[],r=dn(n),s=e.filter(l=>!!l).sort((l,a)=>a.canvasH-l.canvasH||a.canvasW-l.canvasW||l.index-a.index),i=()=>({width:r,height:r,entries:[],shelves:[]}),c=(l,a,d)=>{if(l.sealed)return null;for(let h of l.shelves)if(a.canvasH<=h.height&&h.x+a.canvasW+r<=ce){let u={...a,pageIndex:d,x:h.x,y:h.y};return h.x+=a.canvasW+r*2,l.entries.push(u),l.width=Math.max(l.width,u.x+a.canvasW+r),u}let m=l.shelves.length===0?r:l.height+r;if(m+a.canvasH+r>ce)return null;let f={...a,pageIndex:d,x:r,y:m};return l.shelves.push({x:r+a.canvasW+r*2,y:m,height:a.canvasH}),l.entries.push(f),l.width=Math.max(l.width,f.x+a.canvasW+r),l.height=Math.max(l.height,m+a.canvasH+r),f};for(let l of s){if(l.canvasW+r*2>ce||l.canvasH+r*2>ce){let m=o.length,f={...l,pageIndex:m,x:r,y:r};t[l.index]=f,o.push({width:l.canvasW+r*2,height:l.canvasH+r*2,entries:[f],shelves:[],sealed:!0});continue}let d=null;for(let m=0;m<o.length&&(d=c(o[m],l,m),!d);m++);if(!d){let m=i(),f=o.length;o.push(m),d=c(m,l,f)}d&&(t[l.index]=d)}return{entries:t,pages:o.map(({width:l,height:a,entries:d})=>({width:l,height:a,entries:d}))}}function Dn(e,n,t,o){J(e,o),e.beginPath(),Ve(e,n.x,n.y,n.screenPts),e.clip(),J(e,o),e.fillStyle=t==="dynamic"?n.polygon.color??"#cccccc":n.shadedColor,e.fillRect(n.x,n.y,n.canvasW,n.canvasH)}function le(e,n){return Math.max(0,Math.min(n,e))}function at(e,n,t,o,r,s,i,c){let l=n.naturalWidth||n.width||1,a=n.naturalHeight||n.height||1,d=le(Math.min(t.minU,t.maxU)*l,l),m=le(Math.max(t.minU,t.maxU)*l,l),f=le(Math.min(t.minV,t.maxV)*a,a),h=le(Math.max(t.minV,t.maxV)*a,a),u=Math.floor(d),p=Math.floor(f),b=Math.ceil(m)-u,x=Math.ceil(h)-p;b<1&&(u=Math.floor(le((t.minU+t.maxU)/2*l,l-1)),b=1),x<1&&(p=Math.floor(le((t.minV+t.maxV)/2*a,a-1)),x=1),u=Math.max(0,Math.min(l-1,u)),p=Math.max(0,Math.min(a-1,p)),b=Math.max(1,Math.min(l-u,b)),x=Math.max(1,Math.min(a-p,x)),J(e,c),e.drawImage(n,u,p,b,x,o,r,s,i)}async function Rn(e,n,t,o){let r=t.createElement("canvas");r.width=Math.max(1,Math.ceil(e.width*o)),r.height=Math.max(1,Math.ceil(e.height*o));let s=r.getContext("2d");if(!s)return{width:e.width,height:e.height,url:null};let i=Array.from(new Set(e.entries.flatMap(a=>a.texture?[a.texture]:[]))),c=new Map;await Promise.all(i.map(async a=>{c.set(a,await nn(a))}));for(let a of e.entries){let d=a.texture?c.get(a.texture):null;if(s.save(),J(s,o),s.beginPath(),a.texture?kn(s,a.x,a.y,a.screenPts,a.seamEdges,Jt):Ve(s,a.x,a.y,a.screenPts),s.clip(),!a.texture)Dn(s,a,n,o);else if(d&&a.textureTriangles?.length){let m=d.naturalWidth||d.width||1,f=d.naturalHeight||d.height||1;for(let h of a.textureTriangles){let u=wn(h.screenPts,Kt);s.save(),J(s,o),s.beginPath();for(let p=0;p<u.length;p+=2){let b=a.x+u[p],x=a.y+u[p+1];p===0?s.moveTo(b,x):s.lineTo(b,x)}s.closePath(),s.clip(),h.uvAffine?(J(s,o,h.uvAffine.a/m,h.uvAffine.c/m,h.uvAffine.b/f,h.uvAffine.d/f,a.x+h.uvAffine.e,a.y+h.uvAffine.f),s.drawImage(d,0,0)):h.uvSampleRect&&at(s,d,h.uvSampleRect,a.x,a.y,a.canvasW,a.canvasH,o),s.restore()}}else if(d&&a.uvAffine){let m=d.naturalWidth||d.width||1,f=d.naturalHeight||d.height||1;J(s,o,a.uvAffine.a/m,a.uvAffine.c/m,a.uvAffine.b/f,a.uvAffine.d/f,a.x+a.uvAffine.e,a.y+a.uvAffine.f),s.drawImage(d,0,0)}else d&&a.uvSampleRect?at(s,d,a.uvSampleRect,a.x,a.y,a.canvasW,a.canvasH,o):d&&gn(s,d,a.x,a.y,a.canvasW,a.canvasH,o);a.texture&&n==="baked"&&yn(s,a.x,a.y,a.canvasW,a.canvasH,a.textureTint,o),s.restore()}let l=await Ln(r);return r.width=1,r.height=1,{width:e.width,height:e.height,url:l}}async function In(e,n,t,o,r){let s=[];for(let i of e){if(r())break;s.push(await Rn(i,n,t,o))}return s}function Vn(e,n,t,o){if(!n.url)return;let r=`url(${n.url})`,s=`-${o.x}px -${o.y}px`,i=`${n.width}px ${n.height}px`;t==="dynamic"?(e.style.backgroundImage=r,e.style.backgroundPosition=s,e.style.backgroundSize=i):e.style.background=`${r} ${s} / ${i} no-repeat`,t==="dynamic"?(e.style.maskImage=r,e.style.maskMode="alpha",e.style.maskPosition=s,e.style.maskSize=i,e.style.maskRepeat="no-repeat",e.style.setProperty("-webkit-mask-image",r),e.style.setProperty("-webkit-mask-position",s),e.style.setProperty("-webkit-mask-size",i),e.style.setProperty("-webkit-mask-repeat","no-repeat")):(e.style.maskImage="",e.style.maskMode="",e.style.maskPosition="",e.style.maskSize="",e.style.maskRepeat="",e.style.removeProperty("-webkit-mask-image"),e.style.removeProperty("-webkit-mask-position"),e.style.removeProperty("-webkit-mask-size"),e.style.removeProperty("-webkit-mask-repeat"))}function ze(e,n){let t=De.get(e);if(t)for(let r of t)e.removeAttribute(`data-${r}`);let o=[];if(n.data)for(let[r,s]of Object.entries(n.data))e.setAttribute(`data-${r}`,String(s)),o.push(r);De.set(e,o)}function Be(e,n){e.style.width=`${n.canvasW}px`,e.style.height=`${n.canvasH}px`,e.style.transform=`matrix3d(${n.matrix})`,ze(e,n.polygon)}function Ct(e,n){e.style.setProperty("--pnx",n.normal[0].toFixed(4)),e.style.setProperty("--pny",n.normal[1].toFixed(4)),e.style.setProperty("--pnz",n.normal[2].toFixed(4))}function zn(e){if(e.screenPts.length!==8)return null;let n=[],t=[],o=(r,s)=>{for(let i of r)if(Math.abs(i-s)<=B)return;r.push(s)};for(let r=0;r<e.screenPts.length;r+=2)o(n,e.screenPts[r]),o(t,e.screenPts[r+1]);if(n.length!==2||t.length!==2||(n.sort((r,s)=>r-s),t.sort((r,s)=>r-s),Math.abs(n[0])>B||Math.abs(t[0])>B||n[1]-n[0]<=B||t[1]-t[0]<=B))return null;for(let r=0;r<e.screenPts.length;r+=2){let s=e.screenPts[r],i=e.screenPts[r+1],c=Math.abs(s-n[0])<=B||Math.abs(s-n[1])<=B,l=Math.abs(i-t[0])<=B||Math.abs(i-t[1])<=B;if(!c||!l)return null}return{left:n[0],top:t[0],width:n[1]-n[0],height:t[1]-t[0]}}function lt(e){return!!zn(e)}function Bn(e){return!e.texture&&e.polygon.vertices.length===3}function Fn(e){if(!!!(e.defaultView?.CSS??(typeof CSS<"u"?CSS:void 0))?.supports?.("border-shape","polygon(0 0, 100% 0, 0 100%) polygon(50% 50%, 50% 50%, 50% 50%)"))return!1;let r=(e.defaultView??(typeof window<"u"?window:void 0))?.matchMedia;return r?r("(pointer: fine)").matches&&r("(hover: hover)").matches:!0}function Nn(e){let n=[],t=e.canvasW||1,o=e.canvasH||1;for(let r=0;r<e.screenPts.length;r+=2){let s=Math.max(0,Math.min(100,e.screenPts[r]/t*100)),i=Math.max(0,Math.min(100,e.screenPts[r+1]/o*100));n.push(`${ge(s)} ${ge(i)}`)}return`polygon(${n.join(", ")})`}function Xn(e){let n=0,t=0,o=Math.max(1,e.screenPts.length/2);for(let l=0;l<e.screenPts.length;l+=2)n+=e.screenPts[l],t+=e.screenPts[l+1];let r=e.canvasW||1,s=e.canvasH||1,i=ge(Math.max(0,Math.min(100,n/o/r*100))),c=ge(Math.max(0,Math.min(100,t/o/s*100)));return`polygon(${Array.from({length:o},()=>`${i} ${c}`).join(", ")})`}function Yn(e){return`${Nn(e)} ${Xn(e)}`}function $n(e,n,t){if(t==="dynamic"){Ct(e,n);let o=oe(n.polygon.color??"#cccccc");e.style.setProperty("--psr",(o.r/255).toFixed(4)),e.style.setProperty("--psg",(o.g/255).toFixed(4)),e.style.setProperty("--psb",(o.b/255).toFixed(4))}else e.style.background=n.shadedColor}function Un(e,n,t){let o=t.createElement("b");return Be(o,e),$n(o,e,n),o}function Wn(e,n){let t=n.createElement("i");return Be(t,e),t.style.color=e.shadedColor,t.style.setProperty("border-shape",Yn(e)),t}function Zn(e,n,t){let o=t.createElement("s");return Be(o,e),o.style.backgroundPosition=`-${e.x}px -${e.y}px`,o.style.opacity="0",n==="dynamic"&&Ct(o,e),o}function Mt(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=n.textureLighting??"baked",r=o!=="dynamic"&&Fn(t),s=Tn(e,n),i=e.map((p,b)=>Hn(p,b,n,s[b])),c=i.map(p=>p&&Bn(p)?Et(p.polygon,p.index,n):null),l=i.map((p,b)=>p&&(p.texture||!lt(p)&&!c[b]&&!r?p:null)),{packed:a,atlasScale:d}=un(l,n.atlasScale),m=new Map,f=[],h=!1,u=[];for(let p=0;p<e.length;p++){let b=i[p],x=c[p];if(!b)continue;let C=a.entries[p];if(C){let M=Zn(C,o,t);m.set(p,M),f.push({polygonIndex:p,element:M,kind:"atlas",dispose:()=>{}})}else if(!b.texture&&lt(b)){let M=Un(b,o,t);f.push({polygonIndex:p,element:M,kind:"solid",dispose:()=>{}})}else if(!b.texture&&x){let M=St(x,t);f.push({polygonIndex:p,element:M,kind:"triangle",dispose:()=>{}})}else if(!b.texture&&r){let M=Wn(b,t);f.push({polygonIndex:p,element:M,kind:"border",dispose:()=>{}})}}return f.sort((p,b)=>p.polygonIndex-b.polygonIndex),In(a.pages,o,t,d,()=>h).then(p=>{if(h){for(let b of p)b.url?.startsWith("blob:")&&URL.revokeObjectURL(b.url);return}u=p.flatMap(b=>b.url?.startsWith("blob:")?[b.url]:[]);for(let b=0;b<a.pages.length;b++){let x=a.pages[b],C=p[b];if(C)for(let M of x.entries){let H=m.get(M.index);!H||!C.url||(Vn(H,C,o,M),H.style.opacity="")}}}).catch(()=>{if(!h)for(let p of m.values())p.style.opacity="0.5",p.style.outline="1px dashed rgba(255, 0, 0, 0.6)"}),{rendered:f,dispose(){h=!0;for(let p of u)URL.revokeObjectURL(p);u=[]}}}function Tt(e,n){let t=e.map((o,r)=>Et(o,r,n));return t.some(o=>!o)?null:t}function Gn(e){e.style.backgroundImage="",e.style.backgroundPosition="",e.style.backgroundSize="",e.style.maskImage="",e.style.maskMode="",e.style.maskPosition="",e.style.maskSize="",e.style.maskRepeat="",e.style.removeProperty("-webkit-mask-image"),e.style.removeProperty("-webkit-mask-position"),e.style.removeProperty("-webkit-mask-size"),e.style.removeProperty("-webkit-mask-repeat")}function Lt(e,n){e.style.cssText=n.styleText,(n.polygon.data||De.get(e)?.length)&&ze(e,n.polygon)}function St(e,n){let t=n.createElement("u");return Gn(t),Lt(t,e),ze(t,e.polygon),t}function _t(e,n={}){let t=n.doc??(typeof document<"u"?document:null);if(!t)return{rendered:[],dispose:()=>{}};let o=Tt(e,n);if(!o)return null;let r=[];for(let s of o){let i=St(s,t);r.push({polygonIndex:s.index,element:i,kind:"triangle",dispose:()=>{}})}return r.sort((s,i)=>s.polygonIndex-i.polygonIndex),{rendered:r,dispose(){}}}function wt(e,n,t={}){if(!(t.doc??(typeof document<"u"?document:null)))return{rendered:e,dispose:()=>{}};if(e.some(s=>s.kind!=="triangle"))return null;let r=Tt(n,t);if(!r||r.length!==e.length)return null;for(let s=0;s<e.length;s++)if(e[s].polygonIndex!==r[s].index)return null;for(let s=0;s<e.length;s++)Lt(e[s].element,r[s]);return{rendered:e,dispose(){}}}var Ot="polycss-styles";function Fe(e){let n=e??(typeof document<"u"?document:void 0);if(!n||n.getElementById(Ot))return;let t=n.createElement("style");t.id=Ot,t.textContent=jn,n.head.appendChild(t)}var jn=`
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
+
4
+ .polycss-scene,
5
+ .polycss-scene *,
6
+ .polycss-scene *::before,
7
+ .polycss-scene *::after {
8
+ box-sizing: border-box;
9
+ }
10
+
11
+ .polycss-scene {
12
+ position: absolute;
13
+ top: 50%;
14
+ left: 50%;
15
+ width: 0;
16
+ height: 0;
17
+ transform-style: preserve-3d;
18
+ perspective: none;
19
+ transform: var(--scene-transform);
20
+ }
21
+
22
+ .polycss-offset {
23
+ transform-style: preserve-3d;
24
+ transform: var(--offset-transform);
25
+ }
26
+
27
+ /* \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 */
28
+
29
+ .polycss-mesh {
30
+ position: absolute;
31
+ transform-style: preserve-3d;
32
+ transform-origin: var(--origin);
33
+ }
34
+
35
+ /* \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 */
36
+
37
+ .polycss-scene b,
38
+ .polycss-scene i,
39
+ .polycss-scene s,
40
+ .polycss-scene u {
41
+ position: absolute;
42
+ display: block;
43
+ transform-origin: 0 0;
44
+ transform-style: preserve-3d;
45
+ margin: 0;
46
+ padding: 0;
47
+ font: inherit;
48
+ font-weight: normal;
49
+ font-style: normal;
50
+ line-height: 0;
51
+ text-decoration: none;
52
+ backface-visibility: hidden;
53
+ background-repeat: no-repeat;
54
+ }
55
+
56
+ .polycss-scene b {
57
+ }
58
+
59
+ .polycss-scene i {
60
+ border-color: currentColor;
61
+ }
62
+
63
+ .polycss-scene s {
64
+ }
65
+
66
+ .polycss-scene u {
67
+ width: 0px;
68
+ height: 0px;
69
+ background: transparent;
70
+ box-sizing: content-box;
71
+ border: 0 solid transparent;
72
+ }
73
+
74
+ /* \u2500\u2500 Gizmo override (createTransformControls) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
75
+
76
+ /*
77
+ * Translate arrows + rotate rings render through the same polygon
78
+ * pipeline as user content but the gizmo is a UI affordance \u2014 both
79
+ * faces of every polygon should remain visible regardless of camera
80
+ * orientation, otherwise the cuboid shafts and pyramid heads end up
81
+ * half-culled. Transitions on border-color and background-color smooth
82
+ * the idle / hover / drag alpha changes.
83
+ */
84
+ .polycss-mesh.polycss-transform-gizmo i,
85
+ .polycss-mesh.polycss-transform-gizmo b,
86
+ .polycss-mesh.polycss-transform-gizmo s,
87
+ .polycss-mesh.polycss-transform-gizmo u {
88
+ backface-visibility: visible;
89
+ transition: border-color 150ms ease-out, background-color 150ms ease-out;
90
+ }
91
+
92
+ /* \u2500\u2500 Dynamic lighting cascade vars (scene root \u2192 polygons) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
93
+
94
+ /*
95
+ * Dynamic mode: the scene root carries the directional + ambient light
96
+ * setup as custom properties. Each polygon leaf bakes its own normal
97
+ * directly into an inline calc() that reads these vars to resolve the
98
+ * Lambert dot product and per-channel tint. Sliding the light only
99
+ * writes these scene-root vars \u2014 no JS, no atlas redraw.
100
+ *
101
+ * Registering with @property forces the browser to parse the values as
102
+ * <number>s instead of opaque token streams; that makes the polygon-level
103
+ * calc() expressions resolve reliably across engines.
104
+ */
105
+
106
+ @property --plx { syntax: "<number>"; inherits: true; initial-value: 0; }
107
+ @property --ply { syntax: "<number>"; inherits: true; initial-value: 0; }
108
+ @property --plz { syntax: "<number>"; inherits: true; initial-value: 1; }
109
+ @property --plr { syntax: "<number>"; inherits: true; initial-value: 1; }
110
+ @property --plg { syntax: "<number>"; inherits: true; initial-value: 1; }
111
+ @property --plb { syntax: "<number>"; inherits: true; initial-value: 1; }
112
+ @property --pli { syntax: "<number>"; inherits: true; initial-value: 1; }
113
+ @property --par { syntax: "<number>"; inherits: true; initial-value: 1; }
114
+ @property --pag { syntax: "<number>"; inherits: true; initial-value: 1; }
115
+ @property --pab { syntax: "<number>"; inherits: true; initial-value: 1; }
116
+ @property --pai { syntax: "<number>"; inherits: true; initial-value: 0.4; }
117
+
118
+ /* Per-polygon surface normal \u2014 set inline by the renderer per leaf, OR by
119
+ a .polycss-bucket wrapper that groups axis-aligned polys sharing the
120
+ same face direction. inherits:true so polys inside a bucket pick up
121
+ the wrapper's normal automatically; polys outside any bucket still
122
+ override it inline. */
123
+ @property --pnx { syntax: "<number>"; inherits: true; initial-value: 0; }
124
+ @property --pny { syntax: "<number>"; inherits: true; initial-value: 0; }
125
+ @property --pnz { syntax: "<number>"; inherits: true; initial-value: 1; }
126
+ @property --psr { syntax: "<number>"; inherits: false; initial-value: 1; }
127
+ @property --psg { syntax: "<number>"; inherits: false; initial-value: 1; }
128
+ @property --psb { syntax: "<number>"; inherits: false; initial-value: 1; }
129
+
130
+ /* Hoisted Lambert dot product \u2014 computed once per element it's set on.
131
+ inherits:true so a bucket wrapper computes lambert ONCE for its whole
132
+ group (one calc per bucket, not per polygon). Solo polys still set it
133
+ themselves via the per-poly rule below. */
134
+ @property --plam { syntax: "<number>"; inherits: true; initial-value: 0; }
135
+
136
+ /* Calc-driven Lambert + tint, scoped to dynamic-lighting scenes. Lives
137
+ here (not inline per polygon) so each leaf only carries its tiny normal
138
+ declarations \u2014 ~12\xD7 smaller per-polygon style payload on big meshes.
139
+ --plam is computed once and reused 3\xD7 (one per channel),
140
+ cutting the dot-product calc count from 3 \u2192 1 per polygon per frame. */
141
+ /* Lambert-bucket wrapper: createPolyScene groups axis-aligned polys
142
+ sharing one face direction inside a .polycss-bucket div with the
143
+ bucket's normal as inline CSS vars. Lambert is computed ONCE per
144
+ bucket (inherits:true on --plam propagates the value to
145
+ every leaf child). For voxel meshes this collapses thousands of
146
+ per-frame dot products into a few dozen. */
147
+ .polycss-bucket {
148
+ position: absolute;
149
+ transform-style: preserve-3d;
150
+ }
151
+
152
+ /* Per-bucket lambert calc \u2014 runs once per bucket per frame. */
153
+ .polycss-scene[data-polycss-lighting="dynamic"] .polycss-bucket {
154
+ --plam: max(0, calc(
155
+ var(--pnx) * var(--plx) +
156
+ var(--pny) * var(--ply) +
157
+ var(--pnz) * var(--plz)
158
+ ));
159
+ }
160
+
161
+ /* Per-poly lambert calc \u2014 applies to any leaf whose direct parent is NOT
162
+ a .polycss-bucket. Covers:
163
+ - vanilla createPolyScene polys not inside a bucket (e.g. off-axis
164
+ curved polys that didn't make a bucket group)
165
+ - React <PolyScene polygons> path (leaves are direct children of
166
+ .polycss-scene; no <PolyMesh> wrapper)
167
+ - React <PolyScene><PolyMesh polygons></PolyMesh> path (leaves are
168
+ direct children of .polycss-mesh)
169
+ Bucketed leaves are skipped \u2014 their parent IS .polycss-bucket so they
170
+ inherit the bucket's hoisted lambert (one calc per bucket, not per
171
+ leaf). */
172
+ .polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > i,
173
+ .polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > b,
174
+ .polycss-scene[data-polycss-lighting="dynamic"] :not(.polycss-bucket) > u {
175
+ --plam: max(0, calc(
176
+ var(--pnx) * var(--plx) +
177
+ var(--pny) * var(--ply) +
178
+ var(--pnz) * var(--plz)
179
+ ));
180
+ }
181
+
182
+ /* All polys: containment + background-color from lambert (inherited or
183
+ own) and the scene-level light vars. Splitting this from the lambert
184
+ calc above lets bucketed polys skip the dot-product entirely. */
185
+ .polycss-scene[data-polycss-lighting="dynamic"] s {
186
+ /* Isolate each leaf's layout/style/paint walks from siblings. Works
187
+ because the leaf transform-style:preserve-3d was dropped above \u2014
188
+ the 3D context lives on .polycss-scene / .polycss-mesh, not the
189
+ leaves, so there's nothing inside a leaf that needs to participate
190
+ in 3D compositing across the contain boundary. */
191
+ contain: strict;
192
+ background-color: rgb(
193
+ calc(255 * (var(--par) * var(--pai)
194
+ + var(--plr) * var(--pli) * var(--plam)))
195
+ calc(255 * (var(--pag) * var(--pai)
196
+ + var(--plg) * var(--pli) * var(--plam)))
197
+ calc(255 * (var(--pab) * var(--pai)
198
+ + var(--plb) * var(--pli) * var(--plam)))
199
+ );
200
+ background-blend-mode: multiply;
201
+ }
202
+
203
+ .polycss-scene[data-polycss-lighting="dynamic"] b {
204
+ background-color: rgb(
205
+ calc(255 * var(--psr) * (var(--par) * var(--pai)
206
+ + var(--plr) * var(--pli) * max(0,
207
+ var(--pnx) * var(--plx) +
208
+ var(--pny) * var(--ply) +
209
+ var(--pnz) * var(--plz))))
210
+ calc(255 * var(--psg) * (var(--pag) * var(--pai)
211
+ + var(--plg) * var(--pli) * max(0,
212
+ var(--pnx) * var(--plx) +
213
+ var(--pny) * var(--ply) +
214
+ var(--pnz) * var(--plz))))
215
+ calc(255 * var(--psb) * (var(--pab) * var(--pai)
216
+ + var(--plb) * var(--pli) * max(0,
217
+ var(--pnx) * var(--plx) +
218
+ var(--pny) * var(--ply) +
219
+ var(--pnz) * var(--plz))))
220
+ );
221
+ background-blend-mode: normal;
222
+ }
223
+
224
+ .polycss-scene[data-polycss-lighting="dynamic"] u {
225
+ border-bottom-color: rgb(
226
+ calc(255 * var(--psr) * (var(--par) * var(--pai)
227
+ + var(--plr) * var(--pli) * var(--plam)))
228
+ calc(255 * var(--psg) * (var(--pag) * var(--pai)
229
+ + var(--plg) * var(--pli) * var(--plam)))
230
+ calc(255 * var(--psb) * (var(--pab) * var(--pai)
231
+ + var(--plb) * var(--pli) * var(--plam)))
232
+ );
233
+ }
234
+ `;var Qn=65,eo=45,to=1,re=qn;function Dt(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 no(e){let n=e.rotX??Qn,t=e.rotY??eo,o=e.zoom??to,r=e.distance??0,s=e.target??[0,0,0],i=s[1]*re,c=s[0]*re,l=s[2]*re;return`${r!==0?`translateZ(${-r}px) `:""}scale(${o}) rotateX(${n}deg) rotate(${t}deg) translate3d(${-i}px, ${-c}px, ${-l}px)`}var oo=.1;function ro(e){if(e.vertices.length<3)return null;let n=e.vertices[0],t=e.vertices[1],o=e.vertices[2],r=t[1]-n[1],s=t[0]-n[0],i=t[2]-n[2],c=o[1]-n[1],l=o[0]-n[0],a=o[2]-n[2],d=-(s*a-i*l),m=-(i*c-r*a),f=-(r*l-s*c),h=Math.hypot(d,m,f);if(h<1e-9)return null;d/=h,m/=h,f/=h;let u=1/oo,p=Math.round(d*u)/u,b=Math.round(m*u)/u,x=Math.round(f*u)/u,C=Math.hypot(p,b,x);return C<1e-9?null:{key:p+","+b+","+x,vec:[p/C,b/C,x/C]}}function Ne(e,n={}){if(!e||typeof e.appendChild!="function")throw new Error("createPolyScene: host must be an HTMLElement");e.ownerDocument&&Fe(e.ownerDocument),e.ownerDocument?.defaultView&&e.ownerDocument.defaultView.getComputedStyle(e).position==="static"&&(e.style.position="relative");let t={...n},o=e.ownerDocument??document,r=o.createElement("div");r.className="polycss-scene",r.setAttribute("aria-hidden","true"),c(r,t);let s=o.createElement("div");s.className="polycss-offset",r.appendChild(s),e.appendChild(r);let i=new Set;function c(y,g){y.style.setProperty("--scene-transform",no(g)),l(y,g)}function l(y,g){let _=g.textureLighting==="dynamic";y.dataset.polycssLighting=g.textureLighting??"baked";let E=["--plx","--ply","--plz","--plr","--plg","--plb","--pli","--par","--pag","--pab","--pai"];if(!_){for(let F of E)y.style.removeProperty(F);return}let w=g.directionalLight?.direction??[.4,-.7,.59],S=Math.hypot(w[0],w[1],w[2])||1,v=w[0]/S,O=w[1]/S,T=w[2]/S,R=Ht(g.directionalLight?.color??"#ffffff")?.rgb??[255,255,255],A=Ht(g.ambientLight?.color??"#ffffff")?.rgb??[255,255,255],P=g.directionalLight?.intensity??1,D=g.ambientLight?.intensity??.4,k=F=>(F/255).toFixed(4);y.style.setProperty("--plx",v.toFixed(4)),y.style.setProperty("--ply",O.toFixed(4)),y.style.setProperty("--plz",T.toFixed(4)),y.style.setProperty("--plr",k(R[0])),y.style.setProperty("--plg",k(R[1])),y.style.setProperty("--plb",k(R[2])),y.style.setProperty("--pli",P.toFixed(4)),y.style.setProperty("--par",k(A[0])),y.style.setProperty("--pag",k(A[1])),y.style.setProperty("--pab",k(A[2])),y.style.setProperty("--pai",D.toFixed(4))}function a(y){for(d(y.rendered,y.disposeAtlas),y.disposeAtlas=void 0,y.rendered.length=0;y.wrapper.firstChild;)y.wrapper.removeChild(y.wrapper.firstChild)}function d(y,g){g?.();for(let _ of y){try{_.dispose()}catch{}_.element.parentNode&&_.element.parentNode.removeChild(_.element)}}function m(y){let g=o.createDocumentFragment(),_=t.textureLighting==="dynamic"&&!y.stableDom,E=new Map,w=[];for(let S of y.rendered){let v=y.polygons[S.polygonIndex],O=_&&v?ro(v):null;if(!O){w.push(S);continue}let T=O.key+"|"+(v.color??""),R=E.get(T);R||(R={vec:O.vec,items:[]},E.set(T,R)),R.items.push(S)}for(let S of w)g.appendChild(S.element);for(let S of E.values()){if(S.items.length<2){for(let O of S.items)g.appendChild(O.element);continue}let v=o.createElement("div");v.className="polycss-bucket",v.style.setProperty("--pnx",String(S.vec[0])),v.style.setProperty("--pny",String(S.vec[1])),v.style.setProperty("--pnz",String(S.vec[2]));for(let O of S.items)v.appendChild(O.element),O.element.style.removeProperty("--pnx"),O.element.style.removeProperty("--pny"),O.element.style.removeProperty("--pnz");g.appendChild(v)}y.wrapper.appendChild(g)}function f(y,g){let _=t.textureLighting==="dynamic",E=t.directionalLight?.direction,w=g&&(g[0]!==0||g[1]!==0||g[2]!==0);if(!_||!w||!E){y.style.removeProperty("--plx"),y.style.removeProperty("--ply"),y.style.removeProperty("--plz");return}let S=kt(E,g),v=Math.hypot(S[0],S[1],S[2])||1;y.style.setProperty("--plx",(S[0]/v).toFixed(4)),y.style.setProperty("--ply",(S[1]/v).toFixed(4)),y.style.setProperty("--plz",(S[2]/v).toFixed(4))}function h(y,g){a(y);let _=t.directionalLight,E=g?{..._,direction:g}:_,w={doc:o,directionalLight:E,ambientLight:t.ambientLight,textureLighting:t.textureLighting,atlasScale:t.atlasScale},S=(y.stableDom?_t(y.polygons,w):null)??Mt(y.polygons,w);y.rendered=S.rendered,y.disposeAtlas=S.dispose,m(y)}function u(){if(!t.autoCenter){s.style.removeProperty("--offset-transform");return}let y=[];for(let v of i)!v.disposed&&!v.excludeFromAutoCenter&&y.push(...v.polygons);if(y.length===0){s.style.removeProperty("--offset-transform");return}let g=Kn(y),_=re,E=(g.min[1]+g.max[1])/2*_,w=(g.min[0]+g.max[0])/2*_,S=(g.min[2]+g.max[2])/2*_;s.style.setProperty("--offset-transform",`translate3d(${-E}px, ${-w}px, ${-S}px)`)}function p(y,g={}){let E=(r.ownerDocument??document).createElement("div");E.className="polycss-mesh",g.id&&E.setAttribute("data-poly-mesh-id",g.id);let w={...g},S=g.merge!==!1,v=!!g.stableDom,O=Dt(w);O&&(E.style.transform=O);let T=(k,F)=>F?Jn(k):k,R=T(y.polygons,S);function A(k){if(k.length===0){E.style.removeProperty("--origin");return}let F=1/0,Z=1/0,L=1/0,I=-1/0,V=-1/0,X=-1/0;for(let Y of k)for(let z of Y.vertices)z[0]<F&&(F=z[0]),z[0]>I&&(I=z[0]),z[1]<Z&&(Z=z[1]),z[1]>V&&(V=z[1]),z[2]<L&&(L=z[2]),z[2]>X&&(X=z[2]);if(!Number.isFinite(F)){E.style.removeProperty("--origin");return}let $=(Z+V)/2*re,U=(F+I)/2*re,W=(L+X)/2*re;E.style.setProperty("--origin",`${$}px ${U}px ${W}px`)}A(R),s.appendChild(E);let P={handle:void 0,wrapper:E,parseResult:y,rendered:[],polygons:R,disposed:!1,stableDom:v,excludeFromAutoCenter:!!g.excludeFromAutoCenter,bakedRotation:g.rotation?[...g.rotation]:[0,0,0]},D={polygons:R,element:E,id:g.id,get transform(){return w},remove(){E.parentNode&&E.parentNode.removeChild(E),a(P),i.delete(P),u()},setPolygons(k,F){S=F?.merge??S,v=F?.stableDom??v,P.stableDom=v,P.polygons=T(k,S),D.polygons=P.polygons,A(P.polygons);let Z=F?.recomputeAutoCenter??!0;if(P.stableDom&&!P.wrapper.querySelector(".polycss-bucket")){let L={doc:o,directionalLight:t.directionalLight,ambientLight:t.ambientLight,textureLighting:t.textureLighting,atlasScale:t.atlasScale},I=wt(P.rendered,P.polygons,L);if(I){P.disposeAtlas?.(),P.rendered=I.rendered,P.disposeAtlas=I.dispose,Z&&u();return}}h(P),Z&&u()},setTransform(k){w={...w,...k};let F=Dt(w);E.style.transform=F??"",f(E,w.rotation)},dispose(){if(!P.disposed){P.disposed=!0,E.parentNode&&E.parentNode.removeChild(E),a(P);try{y.dispose()}catch{}i.delete(P),u()}},rebakeAtlas(){P.bakedRotation=w.rotation?[...w.rotation]:[0,0,0];let k=t.directionalLight?.direction??[.4,-.7,.59],F=kt(k,P.bakedRotation);h(P,F)},getPosition(){return w.position},getRotation(){return w.rotation},getScale(){return w.scale},getPolygons(){return D.polygons}};return P.handle=D,i.add(P),h(P),f(E,w.rotation),u(),D}function b(y){let g=!!t.autoCenter;t={...t,...y},c(r,t);let _=!!t.autoCenter;for(let E of i)f(E.wrapper,E.handle.transform.rotation);g!==_&&u()}function x(){return t}function C(){let y=[];for(let g of i)y.push(g.handle);return y}function M(y){let g=y;for(;g;){if(g instanceof HTMLElement&&g.classList.contains("polycss-mesh")){for(let _ of i)if(_.wrapper===g)return _.handle;return null}g=g.parentElement}return null}function H(){let y=Array.from(i);for(let g of y)try{g.handle.dispose()}catch{}r.parentNode&&r.parentNode.removeChild(r)}return{add:p,setOptions:b,destroy:H,host:e,getOptions:x,meshes:C,findMeshByElement:M}}import{createIsometricCamera as Rt}from"@layoutit/polycss-core";var so=8e3;function Ae(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=Rt(n),o=`${e.perspective??so}px`;return{get state(){return t.state},update(r){t.update(r)},getStyle(r){return t.getStyle(r)},type:"perspective",perspectiveStyle:o}}function Xe(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=Rt(n);return{get state(){return t.state},update(o){t.update(o)},getStyle(o){return t.getStyle(o)},type:"orthographic",perspectiveStyle:"none"}}import{BASE_TILE as io}from"@layoutit/polycss-core";var Ee={drag:!0,wheel:!0,dolly:!1,invert:!1,minZoom:.1,maxZoom:10,minDistance:0,maxDistance:1/0,animate:!1};function de(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 fe(e){return e===!0?-1:e===!1?1:e}function Ce(){let e=[],n=[],t=[];function o(i){return i==="change"?e:i==="start"?n:t}function r(i){if(e.length===0)return;let c={type:"change",camera:i()},l=e.slice();for(let a of l)try{a(c)}catch(d){console.error("[polycss] controls 'change' listener threw:",d)}}function s(i,c){let l=i==="start"?n:t;if(l.length===0)return;let a={type:i,camera:c()},d=l.slice();for(let m of d)try{m(a)}catch(f){console.error(`[polycss] controls '${i}' listener threw:`,f)}}return{changeListeners:e,startListeners:n,endListeners:t,listenerArray:o,emitChange:r,emitInteraction:s}}function Me(e){return()=>{let n=e.getOptions(),t=n.target??[0,0,0];return{rotX:n.rotX??0,rotY:n.rotY??0,zoom:n.zoom??1,target:[t[0],t[1],t[2]],distance:n.distance??0}}}function Te(e,n,t,o,r,s){let i=!1,c=null;return{onWheel:d=>{let m=n();if(!m.wheel||t())return;d.preventDefault();let f=d.deltaMode===1?16:d.deltaMode===2?100:1,h=d.deltaY*f;d.ctrlKey?h*=10:h*=3;let u=e.getOptions();if(m.dolly){let p=u.distance??0,b=Math.max(m.minDistance,Math.min(m.maxDistance,p+h*.05));e.setOptions({distance:b})}else{let p=Math.exp(-h*513e-6),b=u.zoom??1,x=Math.max(m.minZoom,Math.min(m.maxZoom,b*p));e.setOptions({zoom:x})}i||(i=!0,s("start",o)),r(o),c!==null&&clearTimeout(c),c=setTimeout(()=>{c=null,i=!1,s("end",o)},150)},teardown:()=>{c!==null&&(clearTimeout(c),c=null),i=!1}}}function Le(e,n,t,o,r,s,i){let c=null,l=0,a=h=>{if(c===null||o())return;let u=t();if(!u.animate){c=null;return}if(r())l=h;else{let p=Math.min(50,l?h-l:16.67);l=h;let b=u.animate.speed*(p/16.67),x=n.getOptions();if(u.animate.axis==="x"){let C=(((x.rotX??65)+b)%360+360)%360;n.setOptions({rotX:C})}else{let C=(((x.rotY??45)+b)%360+360)%360;n.setOptions({rotY:C})}i(s)}c=e.requestAnimationFrame(a)};return{start:()=>{c!==null||!t().animate||o()||(l=0,c=e.requestAnimationFrame(a))},stop:()=>{c!==null&&(e.cancelAnimationFrame(c),c=null)},isRunning:()=>c!==null}}function Ye(e,n={}){let t=de(Ee,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,a=Ce(),d=Me(e),{changeListeners:m,startListeners:f,endListeners:h,listenerArray:u,emitChange:p,emitInteraction:b}=a,x=Le(r,e,()=>t,()=>l,()=>c,d,p),C=A=>{if(!(!t.drag||l)&&s===null&&A.isPrimary!==!1){A.preventDefault(),s=A.pointerId,i={x:A.clientX,y:A.clientY},o.style.cursor="grabbing";try{A.target.setPointerCapture(A.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),b("start",d)}},M=A=>{if(s===null||A.pointerId!==s||!t.drag||l)return;A.preventDefault();let P=A.clientX-i.x,D=A.clientY-i.y;i={x:A.clientX,y:A.clientY};let k=fe(t.invert),F=P/4*k,Z=D/4*k,L=e.getOptions();if(A.shiftKey){let I=L.rotX??65,V=L.rotY??45,X=Math.max(.01,L.zoom??1),$=Math.cos(I*Math.PI/180),U=$>=0?Math.max(.1,$):Math.min(-.1,$),W=Math.cos(V*Math.PI/180),Y=Math.sin(V*Math.PI/180),z=X*io,Q=(P*Y-D*W/U)/z,ie=-(P*W+D*Y/U)/z,ee=L.target??[0,0,0];e.setOptions({target:[ee[0]+Q,ee[1]+ie,ee[2]]})}else{let I=Math.max(0,Math.min(100,(L.rotX??65)-Z)),V=(((L.rotY??45)-F)%360+360)%360;e.setOptions({rotX:I,rotY:V})}p(d)},H=A=>{if(s===A.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{A.target.releasePointerCapture(A.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),b("end",d)}},y=Te(e,()=>t,()=>l,d,p,b);function g(){o.addEventListener("pointerdown",C),o.addEventListener("pointermove",M),o.addEventListener("pointerup",H),o.addEventListener("pointercancel",H),o.addEventListener("wheel",y.onWheel,{passive:!1}),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function _(){o.removeEventListener("pointerdown",C),o.removeEventListener("pointermove",M),o.removeEventListener("pointerup",H),o.removeEventListener("pointercancel",H),o.removeEventListener("wheel",y.onWheel),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",y.teardown()}g(),x.start();function E(A){let P=!!t.animate;t=de(t,A),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let D=!!t.animate;P&&!D?x.stop():!P&&D&&x.start()}function w(){l&&(l=!1,g(),x.start())}function S(){l||(l=!0,_(),x.stop(),s=null,c=!1,y.teardown())}function v(){S(),m.length=0,f.length=0,h.length=0}function O(A,P){let D=u(A);D.includes(P)||D.push(P)}function T(A,P){let D=u(A),k=D.indexOf(P);k>=0&&D.splice(k,1)}function R(A,P){return u(A).includes(P)}return{update:E,resume:w,pause:S,destroy:v,addEventListener:O,removeEventListener:T,hasEventListener:R}}import{BASE_TILE as ao}from"@layoutit/polycss-core";function $e(e,n={}){let t=de(Ee,n),o=e.host,r=o.ownerDocument?.defaultView??globalThis,s=null,i={x:0,y:0},c=!1,l=!1,a=!1,d={x:0,y:0},m=Ce(),f=Me(e),{changeListeners:h,startListeners:u,endListeners:p,listenerArray:b,emitChange:x,emitInteraction:C}=m,M=Le(r,e,()=>t,()=>l,()=>c,f,x),H=L=>{if(!(!t.drag||l)&&s===null&&L.isPrimary!==!1){L.preventDefault(),s=L.pointerId,i={x:L.clientX,y:L.clientY},o.style.cursor="grabbing";try{L.target.setPointerCapture(L.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!0),C("start",f)}},y=L=>{if(s===null||L.pointerId!==s||!t.drag||l)return;L.preventDefault();let I=L.clientX-i.x,V=L.clientY-i.y;i={x:L.clientX,y:L.clientY};let X=e.getOptions();if(L.shiftKey){let $=fe(t.invert),U=I/4*$,W=V/4*$,Y=Math.max(0,Math.min(100,(X.rotX??65)-W)),z=(((X.rotY??45)-U)%360+360)%360;e.setOptions({rotX:Y,rotY:z})}else{let $=X.rotX??65,U=X.rotY??45,W=Math.max(.01,X.zoom??1),Y=Math.cos($*Math.PI/180),z=Y>=0?Math.max(.1,Y):Math.min(-.1,Y),Q=Math.cos(U*Math.PI/180),ie=Math.sin(U*Math.PI/180),ee=W*ao,Oe=(I*ie-V*Q/z)/ee,q=-(I*Q+V*ie/z)/ee,G=X.target??[0,0,0];e.setOptions({target:[G[0]+Oe,G[1]+q,G[2]]})}x(f)},g=L=>{if(s===L.pointerId){s=null,o.style.cursor=t.drag&&!l?"grab":"";try{L.target.releasePointerCapture(L.pointerId)}catch{}t.animate&&t.animate.pauseOnInteraction&&(c=!1),C("end",f)}},_=L=>{L.preventDefault()},E=L=>{L.button===2&&(a=!0,d={x:L.clientX,y:L.clientY},t.animate&&t.animate.pauseOnInteraction&&(c=!0),C("start",f))},w=L=>{if(!a||!t.drag)return;let I=L.clientX-d.x,V=L.clientY-d.y;d={x:L.clientX,y:L.clientY};let X=fe(t.invert),$=I/4*X,U=V/4*X,W=e.getOptions(),Y=Math.max(0,Math.min(100,(W.rotX??65)-U)),z=(((W.rotY??45)-$)%360+360)%360;e.setOptions({rotX:Y,rotY:z}),x(f)},S=L=>{L.button===2&&a&&(a=!1,C("end",f))},v=Te(e,()=>t,()=>l,f,x,C);function O(){o.addEventListener("pointerdown",H),o.addEventListener("pointermove",y),o.addEventListener("pointerup",g),o.addEventListener("pointercancel",g),o.addEventListener("wheel",v.onWheel,{passive:!1}),o.addEventListener("contextmenu",_),o.addEventListener("mousedown",E),o.addEventListener("mousemove",w),o.addEventListener("mouseup",S),o.style.cursor=t.drag?"grab":"",o.style.touchAction="none",o.style.userSelect="none"}function T(){o.removeEventListener("pointerdown",H),o.removeEventListener("pointermove",y),o.removeEventListener("pointerup",g),o.removeEventListener("pointercancel",g),o.removeEventListener("wheel",v.onWheel),o.removeEventListener("contextmenu",_),o.removeEventListener("mousedown",E),o.removeEventListener("mousemove",w),o.removeEventListener("mouseup",S),o.style.cursor="",o.style.touchAction="",o.style.userSelect="",v.teardown()}O(),M.start();function R(L){let I=!!t.animate;t=de(t,L),!l&&s===null&&(o.style.cursor=t.drag?"grab":"");let V=!!t.animate;I&&!V?M.stop():!I&&V&&M.start()}function A(){l&&(l=!1,O(),M.start())}function P(){l||(l=!0,T(),M.stop(),s=null,c=!1,a=!1,v.teardown())}function D(){P(),h.length=0,u.length=0,p.length=0}function k(L,I){let V=b(L);V.includes(I)||V.push(I)}function F(L,I){let V=b(L),X=V.indexOf(I);X>=0&&V.splice(X,1)}function Z(L,I){return b(L).includes(I)}return{update:R,resume:A,pause:P,destroy:D,addEventListener:k,removeEventListener:F,hasEventListener:Z}}function lo(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 Ue(e,n={}){let t=[],o=new Set;n.onChange&&o.add(n.onChange);function r(){t=n.filter?n.filter(t):t;for(let p of o)try{p(t)}catch(b){console.error("[polycss/createSelect] onChange threw:",b)}}function s(u){t=u,r()}function i(u){n.multiple?t.includes(u)||(t=[...t,u]):t=[u],r()}function c(u){t.includes(u)&&(t=t.filter(p=>p!==u),r())}function l(u){t.includes(u)?t=t.filter(p=>p!==u):n.multiple?t=[...t,u]:t=[u],r()}function a(){t.length!==0&&(t=[],r())}function d(u){return t.includes(u)}function m(u,p){for(let b of e.meshes())if(!b.element.classList.contains("polycss-transform-gizmo")&&lo(b.element,u,p))return b;return null}let f=u=>{let p=u.target;if(p?.closest(".polycss-transform-gizmo"))return;let b=e.findMeshByElement(p)??m(u.clientX,u.clientY);if(!b){n.onPointerMissed&&n.onPointerMissed(u),n.clearOnMiss!==!1&&a();return}n.multiple&&(u.shiftKey||u.metaKey||u.ctrlKey)?l(b):t.length===1&&t[0]===b?a():s([b])};e.host.addEventListener("click",f);function h(){e.host.removeEventListener("click",f),o.clear()}return{get selected(){return t},set:s,add:i,remove:c,toggle:l,clear:a,has:d,destroy:h}}import{arrowPolygons as co,ringPolygons as uo}from"@layoutit/polycss-core";var Ze="#ff3653",Ge="#8adb00",je="#2c8fff",pe=50,It=60,po=.6,mo=.0125,fo=.15,ho=.04,yo=1,go=.012,bo=64,vo=1e-4,xo=.6,Po=.8,Ao=1,Vt={0:1,1:0,2:2},zt=[{cssAxis:0,sign:1,key:"x",color:Ze},{cssAxis:0,sign:-1,key:"-x",color:Ze},{cssAxis:1,sign:1,key:"y",color:Ge},{cssAxis:1,sign:-1,key:"-y",color:Ge},{cssAxis:2,sign:1,key:"z",color:je},{cssAxis:2,sign:-1,key:"-z",color:je}],Bt=[{cssAxis:0,key:"x",color:Ze},{cssAxis:1,key:"y",color:Ge},{cssAxis:2,key:"z",color:je}];function Eo(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 Nt(e,n){return!n||n<=0?e:Math.round(e/n)*n}function Co(e){if(e.length===0)return[0,0,0];let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let c of e)for(let l of c.vertices)l[0]<n&&(n=l[0]),l[0]>r&&(r=l[0]),l[1]<t&&(t=l[1]),l[1]>s&&(s=l[1]),l[2]<o&&(o=l[2]),l[2]>i&&(i=l[2]);return Number.isFinite(n)?[(t+s)/2*pe,(n+r)/2*pe,(o+i)/2*pe]:[0,0,0]}function Ft(e){if(e.length===0)return It;let n=1/0,t=1/0,o=1/0,r=-1/0,s=-1/0,i=-1/0;for(let l of e)for(let a of l.vertices)a[0]<n&&(n=a[0]),a[0]>r&&(r=a[0]),a[1]<t&&(t=a[1]),a[1]>s&&(s=a[1]),a[2]<o&&(o=a[2]),a[2]>i&&(i=a[2]);return Number.isFinite(n)?Math.max(r-n,s-t,i-o)*pe*po:It}function We(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 Mo(e){let{cssAxis:n,sign:t,shaftLengthCss:o,wrapper:r,target:s,startClientX:i,startClientY:c,translationSnap:l,onAxisDelta:a,onMouseDown:d,onMouseUp:m,onDraggingChanged:f}=e,h=o,u=[0,0,0];u[n]=t;let p=r.ownerDocument.createElement("div");p.style.position="absolute",p.style.left="0",p.style.top="0",p.style.width="0",p.style.height="0",p.style.transform=`translate3d(${u[0]*h}px, ${u[1]*h}px, ${u[2]*h}px)`,r.appendChild(p);let b=r.getBoundingClientRect(),x=p.getBoundingClientRect();r.removeChild(p);let C=(x.left-b.left)/h,M=(x.top-b.top)/h,H=C*C+M*M;if(H<vo)return;d?.(),f?.(!0);let y=_=>{let E=_.clientX-i,w=_.clientY-c,S=(E*C+w*M)/H;S=Nt(S,l),a(S,u)},g=()=>{window.removeEventListener("pointermove",y),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g);let _=E=>{E.stopPropagation(),E.stopImmediatePropagation()};window.addEventListener("click",_,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",_,!0),0),m?.(),f?.(!1)};window.addEventListener("pointermove",y),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g)}function To(e){let{cssAxis:n,wrapper:t,target:o,startClientX:r,startClientY:s,rotationSnap:i,onAngleDelta:c,onMouseDown:l,onMouseUp:a,onDraggingChanged:d}=e,m=t.getBoundingClientRect(),f=m.left,h=m.top,u=Math.atan2(s-h,r-f),p=0;l?.(),d?.(!0);let b=C=>{let M=Math.atan2(C.clientY-h,C.clientX-f),H=M-u;H>Math.PI?H-=2*Math.PI:H<-Math.PI&&(H+=2*Math.PI),p+=H,u=M;let y=p*180/Math.PI;y=Nt(y,i),c(y)},x=()=>{window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x);let C=M=>{M.stopPropagation(),M.stopImmediatePropagation()};window.addEventListener("click",C,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",C,!0),0),a?.(),d?.(!1)};window.addEventListener("pointermove",b),window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x)}function qe(e,n={}){let t=null,o=n.mode??"translate",r=n.size??1,s={...n},i=new Map,c=null,l=null,a=[0,0,0];function d(){if(!t)return[0,0,0];let v=t.transform.position??[0,0,0];return[v[0]+a[0],v[1]+a[1],v[2]+a[2]]}function m(v){return l===v?Ao:c===v?Po:xo}function f(){for(let[v,O]of i){let T=h(O.spec,m(v));O.handle.setPolygons(T,{recomputeAutoCenter:!1})}}function h(v,O){let R=Ft(t?.polygons??[])*r,A=R/pe,P=Eo(v.color,O);if(o==="translate")return co({axis:Vt[v.cssAxis],sign:v.sign??1,shaftLength:A,shaftHalfThickness:A*mo,headLength:A*fo,headHalfThickness:A*ho,color:P});let D=R*yo/pe;return uo({axis:Vt[v.cssAxis],radius:D,halfThickness:D*go,segments:bo,color:P})}function u(){if(p(),!t)return;let v={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1},O=o==="translate"?zt:o==="rotate"?Bt:[],T=o==="translate"?"polycss-transform-arrow":"polycss-transform-ring",R=d();for(let A of O){let P=A.key.replace("-","")[0];if(!v[P])continue;let D=h(A,m(A.key)),k=e.add({polygons:D,objectUrls:[],warnings:[],dispose:()=>{}},{excludeFromAutoCenter:!0,id:`__poly-gizmo-${A.key}`,position:R});k.element.classList.add("polycss-transform-gizmo",T,`${T}--${A.key}`),i.set(A.key,{handle:k,spec:A})}}function p(){for(let{handle:v}of i.values())v.remove();i.clear(),c=null,l=null}function b(){if(!t)return;let v=d();for(let{handle:O}of i.values())O.setTransform({position:v})}function x(){t&&(i.size===0?u():b())}function C(v){if(t=v,!v){a=[0,0,0],p();return}a=Co(v.polygons),p(),u()}function M(){C(null)}function H(v){v!==o&&(o=v,t&&(p(),u()))}function y(v,O,T){if(!t||!g)return;let R=[g[0]+O*T[0],g[1]+O*T[1],g[2]+O*T[2]];t.setTransform({position:R}),b(),s.onObjectChange?.({object:t,position:R}),s.onChange?.()}let g=null,_=null,E=v=>{if(!t||s.enabled===!1)return;let O={x:s.showX!==!1,y:s.showY!==!1,z:s.showZ!==!1};if(o==="translate")for(let T of zt){let R=T.key.replace("-","")[0];if(!O[R])continue;let A=i.get(T.key);if(A&&We(A.handle.element,v.clientX,v.clientY)){v.preventDefault(),v.stopPropagation(),l=T.key,f(),g=(t.transform.position??[0,0,0]).slice(),Mo({cssAxis:T.cssAxis,sign:T.sign,shaftLengthCss:Ft(t.polygons)*r,wrapper:A.handle.element,target:t,startClientX:v.clientX,startClientY:v.clientY,translationSnap:s.translationSnap??null,onAxisDelta:(P,D)=>y(T,P,D),onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:P=>{P||(l=null,g=null,f()),s.onDraggingChanged?.(P)}});return}}else if(o==="rotate")for(let T of Bt){if(!O[T.key])continue;let R=i.get(T.key);if(R&&We(R.handle.element,v.clientX,v.clientY)){v.preventDefault(),v.stopPropagation(),l=T.key,f(),_=(t.transform.rotation??[0,0,0]).slice(),To({cssAxis:T.cssAxis,wrapper:R.handle.element,target:t,startClientX:v.clientX,startClientY:v.clientY,rotationSnap:s.rotationSnap??null,onAngleDelta:A=>{if(!t||!_)return;let P=[_[0],_[1],_[2]],D=T.cssAxis===0?-1:1;P[T.cssAxis]=_[T.cssAxis]+A*D,t.setTransform({rotation:P}),s.onObjectChange?.({object:t,rotation:P}),s.onChange?.()},onMouseDown:s.onMouseDown,onMouseUp:s.onMouseUp,onDraggingChanged:A=>{A||(l=null,_=null,f(),t?.rebakeAtlas()),s.onDraggingChanged?.(A)}});return}}};e.host.addEventListener("pointerdown",E,{capture:!0});let w=v=>{if(!t||l||s.enabled===!1)return;let O=null;for(let[T,R]of i)if(We(R.handle.element,v.clientX,v.clientY)){O=T;break}O!==c&&(c=O,f())};e.host.addEventListener("pointermove",w);function S(){e.host.removeEventListener("pointerdown",E,{capture:!0}),e.host.removeEventListener("pointermove",w),p()}return{attach:C,detach:M,setMode:H,update:x,destroy:S}}var Lo=typeof HTMLElement<"u"?HTMLElement:class{},So=["perspective","rot-x","rot-y","zoom","directional-direction","directional-color","directional-intensity","ambient-color","ambient-intensity","texture-lighting","atlas-scale","auto-center"];function se(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function _o(e){return e==="false"?!1:se(e)}function wo(e){if(!e)return;let n=e.split(",").map(t=>parseFloat(t.trim()));if(!(n.length!==3||n.some(t=>!Number.isFinite(t))))return[n[0],n[1],n[2]]}function Oo(e){if(e==="baked"||e==="dynamic")return e}function ko(e){return e==="auto"?"auto":se(e)}var j=class extends Lo{constructor(){super(...arguments);this._scene=null}static get observedAttributes(){return[...So]}getScene(){return this._scene}_readOptions(){let t=this._readDirectionalLight(),o=this._readAmbientLight(),r={},s=_o(this.getAttribute("perspective"));s!==void 0&&(r.perspective=s);let i=se(this.getAttribute("rot-x"));i!==void 0&&(r.rotX=i);let c=se(this.getAttribute("rot-y"));c!==void 0&&(r.rotY=c);let l=se(this.getAttribute("zoom"));l!==void 0&&(r.zoom=l),r.textureLighting=Oo(this.getAttribute("texture-lighting"))??"baked";let a=ko(this.getAttribute("atlas-scale"));return a!==void 0&&(r.atlasScale=a),r.autoCenter=this.hasAttribute("auto-center"),t&&(r.directionalLight=t),o&&(r.ambientLight=o),r}_readDirectionalLight(){let t=wo(this.getAttribute("directional-direction")),o=this.getAttribute("directional-color")||void 0,r=se(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=se(this.getAttribute("ambient-intensity"));if(!t&&o===void 0)return;let r={};return t&&(r.color=t),o!==void 0&&(r.intensity=o),r}connectedCallback(){this._scene||(this._scene=Ne(this,this._readOptions()),this.dispatchEvent(new CustomEvent("polycss:scene-ready",{bubbles:!1})))}disconnectedCallback(){this._scene&&(this._scene.destroy(),this._scene=null)}attributeChangedCallback(t,o,r){o!==r&&this._scene&&this._scene.setOptions(this._readOptions())}};import{computeSceneBbox as Ho,loadMesh as Do}from"@layoutit/polycss-core";var Ro=typeof HTMLElement<"u"?HTMLElement:class{},Io=["src","mtl","position","scale","rotation","auto-center"];function he(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 Xt(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return he(e)}}function Vo(e){return e.closest("poly-scene")??null}function zo(e){if(e.length===0)return e;let n=Ho(e),t=(n.min[0]+n.max[0])/2,o=(n.min[1]+n.max[1])/2,r=(n.min[2]+n.max[2])/2;if(t===0&&o===0&&r===0)return e;let s=i=>[i[0]-t,i[1]-o,i[2]-r];return e.map(i=>({...i,vertices:i.vertices.map(s),...i.textureTriangles?.length?{textureTriangles:i.textureTriangles.map(c=>({...c,vertices:c.vertices.map(s)}))}:null}))}var ye=class extends Ro{constructor(){super(...arguments);this._handle=null;this._parseResult=null;this._loadToken=0}static get observedAttributes(){return[...Io]}getMeshHandle(){return this._handle}connectedCallback(){this._maybeLoad()}disconnectedCallback(){this._tearDown()}attributeChangedCallback(t,o,r){if(o!==r){if(t==="src"||t==="mtl"){this._tearDown(),this._maybeLoad();return}this._handle&&this._handle.setTransform({position:he(this.getAttribute("position")),scale:Xt(this.getAttribute("scale")),rotation:he(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=Vo(this);if(!o)return;let r=++this._loadToken,s=this.getAttribute("mtl")||void 0,i;try{i=await Do(t,s?{mtlUrl:s}:void 0)}catch(a){this.dispatchEvent(new CustomEvent("polycss:error",{detail:a,bubbles:!0}));return}if(r!==this._loadToken){try{i.dispose()}catch{}return}let c=o.getScene();if(!c){try{i.dispose()}catch{}return}this.hasAttribute("auto-center")&&(i={...i,polygons:zo(i.polygons)}),this._parseResult=i,this._handle=c.add(i,{position:he(this.getAttribute("position")),scale:Xt(this.getAttribute("scale")),rotation:he(this.getAttribute("rotation"))}),this.dispatchEvent(new CustomEvent("polycss:loaded",{detail:{polygons:this._handle.polygons},bubbles:!0}))}};var Bo=typeof HTMLElement<"u"?HTMLElement:class{},Fo=["vertices","color","texture","uvs","position","scale","rotation"];function Yt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Ke(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 No(e){if(e){if(!e.includes(",")){let n=parseFloat(e);return Number.isFinite(n)?n:void 0}return Ke(e)}}function Xo(e){return e.closest("poly-scene")??null}var Je=class extends Bo{constructor(){super(...arguments);this._handle=null}static get observedAttributes(){return[...Fo]}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=Xo(this);if(!t)return;let o=t.getScene();if(!o)return;let r=Yt(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=Yt(this.getAttribute("uvs"))??void 0,l={};for(let m of Array.from(this.attributes))m.name.startsWith("data-")&&(l[m.name.slice(5)]=m.value);let d={polygons:[{vertices:r,...s!==void 0?{color:s}:{},...i!==void 0?{texture:i}:{},...c!==void 0?{uvs:c}:{},...Object.keys(l).length>0?{data:l}:{}}],objectUrls:[],warnings:[],dispose:()=>{}};this._handle=o.add(d,{position:Ke(this.getAttribute("position")),scale:No(this.getAttribute("scale")),rotation:Ke(this.getAttribute("rotation"))})}};function N(e){if(e==null)return;let n=parseFloat(e);return Number.isFinite(n)?n:void 0}function Se(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 ne(e){if(e!==null)return!(e==="false"||e==="0")}function _e(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 we(e){if(e==="x"||e==="y")return e}var Yo=typeof HTMLElement<"u"?HTMLElement:class{},$o=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],Qe=class extends Yo{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...$o]}_readAnimate(){let t=N(this.getAttribute("animate-speed")),o=we(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:ne(r)}:{}}}_readOptions(){let t={},o=ne(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=ne(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=N(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=N(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=_e(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=N(this.getAttribute("zoom-min")),a=N(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),a!==void 0&&(t.maxZoom=a),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof j)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=Ye(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 Uo=typeof HTMLElement<"u"?HTMLElement:class{},Wo=["drag","wheel","dolly","min-distance","max-distance","invert","zoom-min","zoom-max","animate-speed","animate-axis","animate-pause-on-interaction"],et=class extends Uo{constructor(){super(...arguments);this._controls=null}static get observedAttributes(){return[...Wo]}_readAnimate(){let t=N(this.getAttribute("animate-speed")),o=we(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:ne(r)}:{}}}_readOptions(){let t={},o=ne(this.getAttribute("drag"));o!==void 0&&(t.drag=o);let r=ne(this.getAttribute("wheel"));r!==void 0&&(t.wheel=r),this.hasAttribute("dolly")&&(t.dolly=!0);let s=N(this.getAttribute("min-distance"));s!==void 0&&(t.minDistance=s);let i=N(this.getAttribute("max-distance"));i!==void 0&&(t.maxDistance=i);let c=_e(this.getAttribute("invert"));c!==void 0&&(t.invert=c);let l=N(this.getAttribute("zoom-min")),a=N(this.getAttribute("zoom-max"));return l!==void 0&&(t.minZoom=l),a!==void 0&&(t.maxZoom=a),t.animate=this._readAnimate()??!1,t}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof j)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=$e(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 Zo=typeof HTMLElement<"u"?HTMLElement:class{},Go=["perspective","zoom","rot-x","rot-y","target","distance"],tt=class extends Zo{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...Go]}getCamera(){return this._camera}_readOptions(){return{perspective:N(this.getAttribute("perspective")),zoom:N(this.getAttribute("zoom")),rotX:N(this.getAttribute("rot-x")),rotY:N(this.getAttribute("rot-y")),target:Se(this.getAttribute("target")),distance:N(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Ae(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera||!this._wrapper)return;let s=this._readOptions();this._camera=Ae(s),this._wrapper.style.perspective=this._camera.perspectiveStyle}};var jo=typeof HTMLElement<"u"?HTMLElement:class{},qo=["zoom","rot-x","rot-y","target","distance"],nt=class extends jo{constructor(){super(...arguments);this._camera=null;this._wrapper=null}static get observedAttributes(){return[...qo]}getCamera(){return this._camera}_readOptions(){return{zoom:N(this.getAttribute("zoom")),rotX:N(this.getAttribute("rot-x")),rotY:N(this.getAttribute("rot-y")),target:Se(this.getAttribute("target")),distance:N(this.getAttribute("distance"))}}_mount(){if(this._camera)return;let t=this._readOptions();for(this._camera=Xe(t),this._wrapper=this.ownerDocument.createElement("div"),this._wrapper.className="polycss-camera",this._wrapper.style.perspective=this._camera.perspectiveStyle;this.firstChild;)this._wrapper.appendChild(this.firstChild);this.appendChild(this._wrapper),this.dispatchEvent(new CustomEvent("polycss:camera-ready",{bubbles:!1}))}_teardown(){if(this._wrapper){for(;this._wrapper.firstChild;)this.insertBefore(this._wrapper.firstChild,this._wrapper);this._wrapper.parentNode&&this._wrapper.parentNode.removeChild(this._wrapper),this._wrapper=null}this._camera=null}connectedCallback(){this._mount()}disconnectedCallback(){this._teardown()}attributeChangedCallback(t,o,r){if(o===r||!this._camera)return;let s=this._readOptions();s.zoom!==void 0&&this._camera.update({zoom:s.zoom}),s.rotX!==void 0&&this._camera.update({rotX:s.rotX}),s.rotY!==void 0&&this._camera.update({rotY:s.rotY}),s.target!==void 0&&this._camera.update({target:s.target}),s.distance!==void 0&&this._camera.update({distance:s.distance})}};var Ko=typeof HTMLElement<"u"?HTMLElement:class{},Jo=["mode","target","size","enabled"];function $t(e){if(e==="translate"||e==="rotate")return e}var ot=class extends Ko{constructor(){super(...arguments);this._tc=null}static get observedAttributes(){return[...Jo]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof j)return t;t=t.parentNode}return null}_findTargetMesh(){let t=this.getAttribute("target");if(!t)return null;let o=this._findScene();if(!o)return null;let r=null;try{r=o.querySelector(`#${t}`)??o.querySelector(t)}catch{r=o.querySelector(`[id="${t}"]`)}return r instanceof ye?r:null}_readOptions(){let t={},o=$t(this.getAttribute("mode"));o!==void 0&&(t.mode=o);let r=N(this.getAttribute("size"));r!==void 0&&(t.size=r);let s=this.getAttribute("enabled");return s!==null&&(t.enabled=s!=="false"&&s!=="0"),t.onObjectChange=i=>{this.dispatchEvent(new CustomEvent("polycss:object-change",{bubbles:!0,detail:{position:i.position,rotation:i.rotation}}))},t}_attach(){if(this._tc)return;let t=this._findScene(),o=t?.getScene();if(!o){if(t){let s=()=>{t.removeEventListener("polycss:scene-ready",s),this._attach()};t.addEventListener("polycss:scene-ready",s)}return}this._tc=qe(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=$t(r);s&&this._tc.setMode(s)}else if(t==="target"){let s=this._findTargetMesh();this._tc.attach(s?s.getMeshHandle()??null:null)}}}};var Qo=typeof HTMLElement<"u"?HTMLElement:class{},er=["multiple","clear-on-miss"],rt=class extends Qo{constructor(){super(...arguments);this._selection=null}static get observedAttributes(){return[...er]}_findScene(){let t=this.parentNode;for(;t;){if(t instanceof j)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=Ue(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())}};export*from"@layoutit/polycss-core";export{et as PolyMapControlsElement,ye as PolyMeshElement,Qe as PolyOrbitControlsElement,nt as PolyOrthographicCameraElement,tt as PolyPerspectiveCameraElement,Je as PolyPolygonElement,j as PolySceneElement,rt as PolySelectElement,ot as PolyTransformControlsElement,$e as createPolyMapControls,Ye as createPolyOrbitControls,Xe as createPolyOrthographicCamera,Ae as createPolyPerspectiveCamera,Ne as createPolyScene,Ue as createSelect,qe as createTransformControls,Fe as injectPolyBaseStyles};