@layoutit/polycss-morph 0.2.9 → 0.2.11
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 +31 -18
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +34 -1
- package/dist/index.d.ts +34 -1
- package/dist/index.js +1 -1
- package/dist/prepare.cjs +1 -1
- package/dist/prepare.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# @layoutit/polycss-morph
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Prepare, load, and animate retained DOM models with PolyCSS.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
```bash
|
|
6
|
+
npm install @layoutit/polycss-morph
|
|
7
|
+
```
|
|
7
8
|
|
|
8
|
-
##
|
|
9
|
+
## Package entries
|
|
9
10
|
|
|
10
11
|
Morph has two public entries:
|
|
11
12
|
|
|
@@ -18,9 +19,8 @@ Morph has two public entries:
|
|
|
18
19
|
packages, mounts one retained PolyCSS graph, and exposes imperative,
|
|
19
20
|
caller-driven runtimes.
|
|
20
21
|
|
|
21
|
-
The
|
|
22
|
-
|
|
23
|
-
profiles:
|
|
22
|
+
The Node preparer creates `static-prepared` and `morph-regions` models. The
|
|
23
|
+
browser runtime supports all four profiles:
|
|
24
24
|
|
|
25
25
|
| Profile | Runtime contract |
|
|
26
26
|
|---|---|
|
|
@@ -70,6 +70,9 @@ const frame = deformation.sample({
|
|
|
70
70
|
mounted.apply({ leaves: frame.leafUpdates });
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
See the [cube-to-sphere example](https://polycss.com/guides/morph/#example-cube-to-sphere)
|
|
74
|
+
for a complete rendered deformation example.
|
|
75
|
+
|
|
73
76
|
The browser API is intentionally imperative:
|
|
74
77
|
|
|
75
78
|
- load or validate a model;
|
|
@@ -81,21 +84,31 @@ The browser API is intentionally imperative:
|
|
|
81
84
|
`mounted.apply(sample.update)` succeeds;
|
|
82
85
|
- call `mounted.destroy()` at teardown.
|
|
83
86
|
|
|
87
|
+
Consumers that already own a retained DOM graph can adopt its source-ordered
|
|
88
|
+
model, shape, and leaf elements with `createPolyMorphPreparedDomTarget`.
|
|
89
|
+
The target owns write deduplication and invalidation, while the consumer
|
|
90
|
+
continues to own the elements and their teardown.
|
|
91
|
+
|
|
84
92
|
Morph owns no `requestAnimationFrame` loop, interval, or other scheduler. A
|
|
85
93
|
mounted model keeps the same leaf elements for its lifetime. Runtime updates do
|
|
86
94
|
not rebuild topology, add or remove leaves, construct image resources, or
|
|
87
95
|
redraw prepared image resources.
|
|
88
96
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
Sparse deformation supports retained solid triangles and affine solid quads.
|
|
98
|
+
Planar projective solid quads are available where PolyCSS enables projective
|
|
99
|
+
quad compositing. Deformation rejects non-coplanar, non-convex, or
|
|
100
|
+
compositor-unstable geometry, and the retained mount rejects projective quad
|
|
101
|
+
matrices on unsupported Safari-family browsers before DOM writes.
|
|
102
|
+
|
|
103
|
+
Morph chooses the triangle paint path once when it mounts. It uses
|
|
104
|
+
`corner-shape` where available, a larger CSS border triangle in Firefox, and
|
|
105
|
+
each leaf's prepared polygon-sized atlas slice in WebKit/Safari. Mount creates
|
|
106
|
+
object URLs from the loader's already-verified image bytes and revokes them at
|
|
107
|
+
teardown; it does not refetch package resources. Atlas pages are generated with
|
|
108
|
+
Node built-ins, so Morph has no Sharp or other native image dependency.
|
|
96
109
|
|
|
97
|
-
##
|
|
110
|
+
## Application ownership
|
|
98
111
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
112
|
+
Morph owns the prepared model format and sparse DOM updates. Your application
|
|
113
|
+
owns input, timing, presentation, model-specific preparation, and product
|
|
114
|
+
behavior.
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Je=Object.defineProperty;var Go=Object.getOwnPropertyDescriptor;var Qo=Object.getOwnPropertyNames;var Ko=Object.prototype.hasOwnProperty;var Xo=(o,e)=>{for(var t in e)Je(o,t,{get:e[t],enumerable:!0})},Zo=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Qo(e))!Ko.call(o,r)&&r!==t&&Je(o,r,{get:()=>e[r],enumerable:!(n=Go(e,r))||n.enumerable});return o};var et=o=>Zo(Je({},"__esModule",{value:!0}),o);var on={};Xo(on,{POLY_MORPH_CATALOG_SCHEMA:()=>de,POLY_MORPH_EXECUTABLE_PROFILES:()=>_o,POLY_MORPH_MODEL_SCHEMA:()=>ge,POLY_MORPH_PACKAGE_SCHEMA:()=>ce,PolyMorphContractError:()=>je,PolyMorphPackageError:()=>k,PolyMorphRenderError:()=>we,PolyMorphRuntimeError:()=>K,applyPolyMorphPlaybackFrame:()=>De,assertPolyMorphPackageModelBinding:()=>Ee,buildPolyMorphCatalog:()=>vo,buildPolyMorphPackage:()=>$o,createPolyMorphAnimationRuntime:()=>_e,createPolyMorphControlRuntime:()=>Lo,createPolyMorphControlState:()=>To,createPolyMorphDeformationRuntime:()=>Uo,createPolyMorphPlaybackRuntime:()=>Bo,createPolyMorphPreparedState:()=>Ne,createPolyMorphSkinningRuntime:()=>qo,createPolyMorphSpringRuntime:()=>Jo,createPolyMorphSpringState:()=>Wo,decodePolyMorphJson:()=>be,diffPolyMorphPreparedStates:()=>qe,encodePolyMorphCanonicalJson:()=>Pe,hashPolyMorphBytes:()=>ie,isPolyMorphId:()=>ze,isPolyMorphResourcePath:()=>Ve,loadPolyMorphCatalog:()=>oo,loadPolyMorphPackage:()=>So,mountPolyMorphModel:()=>Co,pickPolyMorphControl:()=>io,stepPolyMorphControls:()=>zo,stepPolyMorphSprings:()=>Yo,stringifyPolyMorphCanonicalJson:()=>Ge,validatePolyMorphCatalog:()=>$e,validatePolyMorphModel:()=>D,validatePolyMorphPackageManifest:()=>xe});module.exports=et(on);var ge="polycss-morph.model@1",de="polycss-morph.catalog@1",ce="polycss-morph.package@1";var uo=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,ot=/^[a-z0-9][a-z0-9._-]*$/,mo=/^\d+\.\d+\.\d+$/,tt=/^[a-f0-9]{64}$/,nt=new Set(["joint-skin","morph-regions","prepared-playback","static-prepared"]),rt=new Set(["animation","joint-skinning","morph-targets","prepared-playback","retained-render","semantic-controls","sparse-updates","springs"]),at=new Set(["atlas-slice","direct-image","solid-quad","solid-triangle"]),it=new Set(["control-value","joint-rotation","joint-scale","joint-translation","morph-weight","shape-matrix"]),je=class extends TypeError{constructor(e,t,n){super(`${t}: ${n}`),this.name="PolyMorphContractError",this.code=e,this.path=t}};function f(o,e,t){throw new je(o,e,t)}function A(o,e,t){(!o||typeof o!="object"||Array.isArray(o))&&f("invalid-type",e,"expected an object");let n=Object.keys(o).sort(),r=[...t].sort();return(n.length!==r.length||n.some((a,i)=>a!==r[i]))&&f("invalid-keys",e,`expected exactly ${r.join(", ")}`),o}function L(o,e){return Array.isArray(o)||f("invalid-type",e,"expected an array"),o}function Z(o,e){return(typeof o!="string"||o.length===0)&&f("invalid-string",e,"expected a non-empty string"),o}function J(o,e){return(typeof o!="number"||!Number.isFinite(o))&&f("invalid-number",e,"expected a finite number"),o}function X(o,e,t=0){let n=J(o,e);return(!Number.isSafeInteger(n)||n<t)&&f("invalid-integer",e,`expected an integer >= ${t}`),n}function We(o,e){return typeof o!="boolean"&&f("invalid-boolean",e,"expected a boolean"),o}function N(o,e){let t=Z(o,e);return uo.test(t)||f("invalid-id",e,"expected a normalized kebab-case id"),t}function G(o,e){let t=new Set;for(let n of o)t.has(n)&&f("duplicate-id",e,`duplicate id ${n}`),t.add(n)}function Me(o,e){let t=L(o,e);return t.length!==3&&f("invalid-vector",e,"expected three components"),t.map((n,r)=>J(n,`${e}[${r}]`))}function se(o,e){let t=L(o,e);return t.length!==16&&f("invalid-matrix",e,"expected sixteen components"),t.map((n,r)=>J(n,`${e}[${r}]`))}function fo(o,e){let t=Z(o,e);return t.split("/").some(n=>!ot.test(n))&&f("invalid-path",e,"expected lowercase URL-safe package path segments"),t}function Te(o,e,t){let n=X(o,e);return n>=t&&f("out-of-range",e,`expected an index below ${t}`),n}function st(o,e){let t=A(o,e,["normals","polygons","vertices"]),n=L(t.vertices,`${e}.vertices`).map((i,s)=>Me(i,`${e}.vertices[${s}]`)),r=L(t.normals,`${e}.normals`).map((i,s)=>Me(i,`${e}.normals[${s}]`));n.length===0&&f("missing-topology",`${e}.vertices`,"expected at least one vertex"),r.length===0&&f("missing-topology",`${e}.normals`,"expected at least one normal");let a=L(t.polygons,`${e}.polygons`).map((i,s)=>{let d=`${e}.polygons[${s}]`,l=A(i,d,["id","normalIndices","vertexIndices"]),c=L(l.vertexIndices,`${d}.vertexIndices`).map((y,b)=>Te(y,`${d}.vertexIndices[${b}]`,n.length)),p=L(l.normalIndices,`${d}.normalIndices`).map((y,b)=>Te(y,`${d}.normalIndices[${b}]`,r.length));return c.length<3&&f("invalid-polygon",d,"expected at least three vertices"),p.length!==c.length&&f("invalid-polygon",d,"normal and vertex index counts must match"),new Set(c).size!==c.length&&f("invalid-polygon",d,"vertex indices must be unique"),{id:N(l.id,`${d}.id`),vertexIndices:c,normalIndices:p}});return a.length===0&&f("missing-topology",`${e}.polygons`,"expected at least one polygon"),G(a.map(i=>i.id),`${e}.polygons`),{vertices:n,normals:r,polygons:a}}function lt(o,e,t){let n=A(o,e,["atlas","fallback","height","id","materialId","matrix","polygonId","shapeId","strategy","width"]),r=Z(n.strategy,`${e}.strategy`);at.has(r)||f("invalid-strategy",`${e}.strategy`,"unknown render strategy");let a=N(n.polygonId,`${e}.polygonId`),i=N(n.shapeId,`${e}.shapeId`),s=N(n.materialId,`${e}.materialId`);t.polygonIds.has(a)||f("unknown-reference",`${e}.polygonId`,a),t.shapeIds.has(i)||f("unknown-reference",`${e}.shapeId`,i),t.materialIds.has(s)||f("unknown-reference",`${e}.materialId`,s);let d=J(n.width,`${e}.width`),l=J(n.height,`${e}.height`);(d<=0||l<=0)&&f("invalid-size",e,"leaf dimensions must be positive");let c=r==="atlas-slice"||r==="direct-image",p=n.atlas===null?null:ho(n.atlas,`${e}.atlas`);c!==(p!==null)&&f("invalid-strategy",`${e}.atlas`,c?"image strategies require an atlas/source slice":"solid strategies cannot declare an atlas/source slice");let y=n.fallback===null?null:dt(n.fallback,`${e}.fallback`);return y!==null&&r!=="solid-triangle"&&f("invalid-strategy",`${e}.fallback`,"only solid-triangle leaves may declare a prepared fallback"),{id:N(n.id,`${e}.id`),polygonId:a,shapeId:i,materialId:s,strategy:r,width:d,height:l,matrix:se(n.matrix,`${e}.matrix`),atlas:p,fallback:y}}function dt(o,e){let t=A(o,e,["atlas","height","matrixFromLeaf","width"]),n=X(t.width,`${e}.width`,1),r=X(t.height,`${e}.height`,1),a=ho(t.atlas,`${e}.atlas`);return(a.width!==n||a.height!==r)&&f("invalid-size",e,"fallback dimensions must match its per-polygon atlas slice"),{width:n,height:r,matrixFromLeaf:se(t.matrixFromLeaf,`${e}.matrixFromLeaf`),atlas:a}}function ho(o,e){let t=A(o,e,["height","pageHeight","pageWidth","resourcePath","width","x","y"]),n={resourcePath:fo(t.resourcePath,`${e}.resourcePath`),x:X(t.x,`${e}.x`),y:X(t.y,`${e}.y`),width:X(t.width,`${e}.width`,1),height:X(t.height,`${e}.height`,1),pageWidth:X(t.pageWidth,`${e}.pageWidth`,1),pageHeight:X(t.pageHeight,`${e}.pageHeight`,1)};return(n.x+n.width>n.pageWidth||n.y+n.height>n.pageHeight)&&f("out-of-range",e,"slice must fit inside its page"),n}function ct(o,e,t){(!o||typeof o!="object"||Array.isArray(o))&&f("invalid-type",e,"expected a deformation object");let n=Z(o.kind,`${e}.kind`);if(n==="none")return A(o,e,["kind"]),{kind:n};if(n==="morph-regions"){let r=A(o,e,["kind","targets"]),a=L(r.targets,`${e}.targets`).map((i,s)=>{let d=`${e}.targets[${s}]`,l=A(i,d,["deltas","id"]),c=L(l.deltas,`${d}.deltas`).map((y,b)=>{let u=`${d}.deltas[${b}]`,M=A(y,u,["normal","position","vertexIndex"]),$=M.position===null?null:Me(M.position,`${u}.position`),h=M.normal===null?null:Me(M.normal,`${u}.normal`);return $===null&&h===null&&f("empty-delta",u,"expected a position or normal delta"),{vertexIndex:Te(M.vertexIndex,`${u}.vertexIndex`,t.vertices.length),position:$,normal:h}});c.length===0&&f("missing-deltas",`${d}.deltas`,"expected at least one delta");let p=c.map(y=>String(y.vertexIndex));return G(p,`${d}.deltas`),{id:N(l.id,`${d}.id`),deltas:c}});return a.length===0&&f("missing-targets",`${e}.targets`,"expected at least one target"),G(a.map(i=>i.id),`${e}.targets`),{kind:n,targets:a}}if(n==="joint-skin"){let r=A(o,e,["joints","kind","vertices"]),a=L(r.joints,`${e}.joints`).map((l,c)=>{let p=`${e}.joints[${c}]`,y=A(l,p,["id","inverseBindMatrix","parentId","restMatrix"]);return{id:N(y.id,`${p}.id`),parentId:y.parentId===null?null:N(y.parentId,`${p}.parentId`),restMatrix:se(y.restMatrix,`${p}.restMatrix`),inverseBindMatrix:se(y.inverseBindMatrix,`${p}.inverseBindMatrix`)}});a.length===0&&f("missing-joints",`${e}.joints`,"expected at least one joint"),G(a.map(l=>l.id),`${e}.joints`),pt(a,`${e}.joints`);let i=new Set(a.map(l=>l.id)),s=L(r.vertices,`${e}.vertices`).map((l,c)=>{let p=`${e}.vertices[${c}]`,y=A(l,p,["influences","vertexIndex"]),b=Te(y.vertexIndex,`${p}.vertexIndex`,t.vertices.length),u=L(y.influences,`${p}.influences`).map(($,h)=>{let v=`${p}.influences[${h}]`,I=A($,v,["jointId","weight"]),E=N(I.jointId,`${v}.jointId`);i.has(E)||f("unknown-reference",`${v}.jointId`,E);let x=J(I.weight,`${v}.weight`);return(x<=0||x>1)&&f("invalid-weight",`${v}.weight`,"expected 0 < weight <= 1"),{jointId:E,weight:x}});u.length===0&&f("missing-influences",`${p}.influences`,"expected at least one influence"),G(u.map($=>$.jointId),`${p}.influences`);let M=u.reduce(($,h)=>$+h.weight,0);return Math.abs(M-1)>1e-6&&f("invalid-weight",`${p}.influences`,"weights must sum to 1"),{vertexIndex:b,influences:u}});s.length!==t.vertices.length&&f("missing-skin-vertex",`${e}.vertices`,"every topology vertex must have one skin record");let d=s.map(l=>String(l.vertexIndex));return G(d,`${e}.vertices`),{kind:n,joints:a,vertices:s}}f("invalid-deformation",`${e}.kind`,`unknown deformation kind ${n}`)}function pt(o,e){let t=new Map(o.map(r=>[r.id,r]));o.filter(r=>r.parentId===null).length!==1&&f("invalid-hierarchy",e,"expected exactly one root joint");for(let r of o){r.parentId!==null&&!t.has(r.parentId)&&f("unknown-reference",e,`joint ${r.id} references ${r.parentId}`);let a=new Set,i=r;for(;i;)a.has(i.id)&&f("invalid-hierarchy",e,`cycle at joint ${i.id}`),a.add(i.id),i=i.parentId===null?void 0:t.get(i.parentId)}}function yt(o){return o==="control-value"||o==="morph-weight"?1:o==="joint-rotation"?4:o==="shape-matrix"?16:3}function mt(o,e,t,n){let r=A(o,e,["interpolation","target","targetId","timesMs","values"]),a=Z(r.target,`${e}.target`);it.has(a)||f("invalid-animation-target",`${e}.target`,a);let i=N(r.targetId,`${e}.targetId`);(a==="control-value"?t.controlIds:a==="morph-weight"?t.targetIds:a==="shape-matrix"?t.shapeIds:t.jointIds).has(i)||f("unknown-reference",`${e}.targetId`,i);let d=Z(r.interpolation,`${e}.interpolation`);d!=="linear"&&d!=="step"&&f("invalid-interpolation",`${e}.interpolation`,d),a==="shape-matrix"&&d!=="step"&&f("invalid-interpolation",`${e}.interpolation`,"shape matrices require step interpolation");let l=L(r.timesMs,`${e}.timesMs`).map((p,y)=>J(p,`${e}.timesMs[${y}]`)),c=L(r.values,`${e}.values`).map((p,y)=>{let b=L(p,`${e}.values[${y}]`),u=yt(a);b.length!==u&&f("invalid-animation-value",`${e}.values[${y}]`,`expected ${u} components`);let M=b.map(($,h)=>J($,`${e}.values[${y}][${h}]`));return a==="joint-rotation"&&Math.hypot(...M)<=1e-12&&f("invalid-animation-value",`${e}.values[${y}]`,"quaternion must be non-zero"),M});return(l.length===0||l.length!==c.length)&&f("invalid-animation-samples",e,"times and values must have the same non-zero length"),(l[0]!==0||l.some((p,y)=>p<0||p>n||y>0&&p<=l[y-1]))&&f("invalid-animation-time",`${e}.timesMs`,"times must start at zero and increase within the clip"),{target:a,targetId:i,interpolation:d,timesMs:l,values:c}}function ut(o,e,t,n){let r=A(o,e,["durationMs","frames","loop"]),a=J(r.durationMs,`${e}.durationMs`);a<=0&&f("invalid-duration",`${e}.durationMs`,"expected a positive duration");let i=L(r.frames,`${e}.frames`).map((s,d)=>{let l=`${e}.frames[${d}]`,c=A(s,l,["leaves","modelMatrix","shapes","timeMs"]),p=J(c.timeMs,`${l}.timeMs`),y=L(c.shapes,`${l}.shapes`).map((u,M)=>{let $=`${l}.shapes[${M}]`,h=A(u,$,["matrix","shapeId"]),v=N(h.shapeId,`${$}.shapeId`);return n.has(v)||f("unknown-reference",`${$}.shapeId`,v),{shapeId:v,matrix:se(h.matrix,`${$}.matrix`)}});G(y.map(u=>u.shapeId),`${l}.shapes`);let b=L(c.leaves,`${l}.leaves`).map((u,M)=>{let $=`${l}.leaves[${M}]`,h=A(u,$,["atlasRow","leafId","matrix","opacity","visible"]),v=N(h.leafId,`${$}.leafId`);t.has(v)||f("unknown-reference",`${$}.leafId`,v);let I=h.opacity===null?null:J(h.opacity,`${$}.opacity`);return I!==null&&(I<0||I>1)&&f("out-of-range",`${$}.opacity`,"expected 0 <= opacity <= 1"),{leafId:v,matrix:h.matrix===null?null:se(h.matrix,`${$}.matrix`),visible:h.visible===null?null:We(h.visible,`${$}.visible`),opacity:I,atlasRow:h.atlasRow===null?null:X(h.atlasRow,`${$}.atlasRow`)}});return G(b.map(u=>u.leafId),`${l}.leaves`),{timeMs:p,modelMatrix:c.modelMatrix===null?null:se(c.modelMatrix,`${l}.modelMatrix`),shapes:y,leaves:b}});return i.length===0&&f("missing-frames",`${e}.frames`,"expected at least one frame"),(i[0].timeMs!==0||i.some((s,d)=>s.timeMs<0||s.timeMs>a||d>0&&s.timeMs<=i[d-1].timeMs))&&f("invalid-frame-time",`${e}.frames`,"frames must start at zero and increase within the timeline"),{durationMs:a,loop:We(r.loop,`${e}.loop`),frames:i}}function ft(o,e){let t=["retained-render"];return o==="morph-regions"&&t.push("morph-targets","sparse-updates"),o==="joint-skin"&&t.push("joint-skinning","sparse-updates"),o==="prepared-playback"&&t.push("prepared-playback","sparse-updates"),e.controls.length>0&&t.push("semantic-controls"),e.springs.length>0&&t.push("springs"),e.animations.length>0&&t.push("animation"),t}function D(o){let t=A(o,"$",["animations","budgets","capabilities","controls","deformation","identity","materials","playback","profile","provenance","render","schema","springs","topology"]);t.schema!==ge&&f("invalid-schema","$.schema",`expected ${ge}`);let n=A(t.identity,"$.identity",["id","name","revision"]),r={id:N(n.id,"$.identity.id"),name:Z(n.name,"$.identity.name"),revision:Z(n.revision,"$.identity.revision")};mo.test(r.revision)||f("invalid-revision","$.identity.revision","expected x.y.z");let a=Z(t.profile,"$.profile");nt.has(a)||f("invalid-profile","$.profile",a);let i=L(t.capabilities,"$.capabilities").map((P,C)=>{let m=Z(P,`$.capabilities[${C}]`);return rt.has(m)||f("invalid-capability",`$.capabilities[${C}]`,m),m});G(i,"$.capabilities"),i.some((P,C)=>C>0&&P<=i[C-1])&&f("non-canonical-order","$.capabilities","capabilities must be sorted");let s=A(t.budgets,"$.budgets",["maxBytes","maxFrames","maxJoints","maxLeaves","maxPolygons","maxResources","maxVertices"]),d={maxVertices:X(s.maxVertices,"$.budgets.maxVertices"),maxPolygons:X(s.maxPolygons,"$.budgets.maxPolygons"),maxLeaves:X(s.maxLeaves,"$.budgets.maxLeaves"),maxFrames:X(s.maxFrames,"$.budgets.maxFrames"),maxJoints:X(s.maxJoints,"$.budgets.maxJoints"),maxResources:X(s.maxResources,"$.budgets.maxResources"),maxBytes:X(s.maxBytes,"$.budgets.maxBytes")},l=st(t.topology,"$.topology"),c=L(t.materials,"$.materials").map((P,C)=>{let m=`$.materials[${C}]`,S=A(P,m,["color","id"]),g=L(S.color,`${m}.color`);g.length!==4&&f("invalid-color",`${m}.color`,"expected four components");let R=g.map((z,q)=>{let ee=J(z,`${m}.color[${q}]`);return(ee<0||ee>1)&&f("out-of-range",`${m}.color[${q}]`,"expected 0 <= component <= 1"),ee});return{id:N(S.id,`${m}.id`),color:R}});c.length===0&&f("missing-materials","$.materials","expected at least one material"),G(c.map(P=>P.id),"$.materials");let p=A(t.render,"$.render",["leaves","modelMatrix","shapes"]),y=L(p.shapes,"$.render.shapes").map((P,C)=>{let m=`$.render.shapes[${C}]`,S=A(P,m,["id","matrix"]);return{id:N(S.id,`${m}.id`),matrix:se(S.matrix,`${m}.matrix`)}});y.length===0&&f("missing-shapes","$.render.shapes","expected at least one shape"),G(y.map(P=>P.id),"$.render.shapes");let b=L(p.leaves,"$.render.leaves").map((P,C)=>lt(P,`$.render.leaves[${C}]`,{polygonIds:new Set(l.polygons.map(m=>m.id)),shapeIds:new Set(y.map(m=>m.id)),materialIds:new Set(c.map(m=>m.id))}));G(b.map(P=>P.id),"$.render.leaves"),G(b.map(P=>P.polygonId),"$.render.leaves[*].polygonId"),b.length!==l.polygons.length&&f("unstable-topology","$.render.leaves","every polygon must bind exactly one retained leaf");let u={modelMatrix:se(p.modelMatrix,"$.render.modelMatrix"),shapes:y,leaves:b},M=ct(t.deformation,"$.deformation",l);(a==="static-prepared"||a==="prepared-playback"?M.kind!=="none":M.kind!==a)&&f("profile-mismatch","$.deformation.kind",`does not match profile ${a}`);let $=new Set(M.kind==="morph-regions"?M.targets.map(P=>P.id):[]),h=new Set(M.kind==="joint-skin"?M.joints.map(P=>P.id):[]),v=L(t.controls,"$.controls").map((P,C)=>{let m=`$.controls[${C}]`,S=A(P,m,["anchor","axis","id","initial","maximum","minimum","radius","targets"]),g=J(S.minimum,`${m}.minimum`),R=J(S.maximum,`${m}.maximum`),z=J(S.initial,`${m}.initial`);(g>R||z<g||z>R)&&f("invalid-control-bounds",m,"expected minimum <= initial <= maximum");let q=Me(S.anchor,`${m}.anchor`),ee=Me(S.axis,`${m}.axis`);Math.hypot(...ee)<1e-9&&f("invalid-control-axis",`${m}.axis`,"axis must be non-zero");let fe=J(S.radius,`${m}.radius`);fe<=0&&f("invalid-control-radius",`${m}.radius`,"radius must be positive");let he=L(S.targets,`${m}.targets`).map((ye,Se)=>{let j=`${m}.targets[${Se}]`,Q=A(ye,j,["scale","targetId"]),Y=N(Q.targetId,`${j}.targetId`);return $.has(Y)||f("unknown-reference",`${j}.targetId`,Y),{targetId:Y,scale:J(Q.scale,`${j}.scale`)}});return G(he.map(ye=>ye.targetId),`${m}.targets`),{id:N(S.id,`${m}.id`),anchor:q,axis:ee,radius:fe,minimum:g,maximum:R,initial:z,targets:he}});G(v.map(P=>P.id),"$.controls");let I=new Set(v.map(P=>P.id)),E=L(t.springs,"$.springs").map((P,C)=>{let m=`$.springs[${C}]`,S=A(P,m,["controlId","damping","id","stiffness"]),g=N(S.controlId,`${m}.controlId`);I.has(g)||f("unknown-reference",`${m}.controlId`,g);let R=J(S.stiffness,`${m}.stiffness`),z=J(S.damping,`${m}.damping`);return(R<=0||z<0)&&f("invalid-spring",m,"expected stiffness > 0 and damping >= 0"),{id:N(S.id,`${m}.id`),controlId:g,stiffness:R,damping:z}});G(E.map(P=>P.id),"$.springs");let x=new Set(y.map(P=>P.id)),w=L(t.animations,"$.animations").map((P,C)=>{let m=`$.animations[${C}]`,S=A(P,m,["channels","durationMs","id","loop"]),g=J(S.durationMs,`${m}.durationMs`);g<=0&&f("invalid-duration",`${m}.durationMs`,"expected a positive duration");let R=L(S.channels,`${m}.channels`).map((q,ee)=>mt(q,`${m}.channels[${ee}]`,{controlIds:I,jointIds:h,shapeIds:x,targetIds:$},g));R.length===0&&f("missing-channels",`${m}.channels`,"expected at least one channel");let z=R.map(q=>`${q.target}:${q.targetId}`);return G(z,`${m}.channels`),{id:N(S.id,`${m}.id`),durationMs:g,loop:We(S.loop,`${m}.loop`),channels:R}});G(w.map(P=>P.id),"$.animations");let W=t.playback===null?null:ut(t.playback,"$.playback",new Set(b.map(P=>P.id)),x);a==="prepared-playback"!=(W!==null)&&f("profile-mismatch","$.playback","playback is required only by the prepared-playback profile");let V=A(t.provenance,"$.provenance",["generator","generatorVersion","sources"]),B=L(V.sources,"$.provenance.sources").map((P,C)=>{let m=`$.provenance.sources[${C}]`,S=A(P,m,["id","kind","license","sha256","uri"]),g=Z(S.kind,`${m}.kind`);g!=="authored"&&g!=="generated"&&g!=="open-data"&&f("invalid-source-kind",`${m}.kind`,g);let R=Z(S.uri,`${m}.uri`);(R.startsWith("/")||R.startsWith("file:")||R.includes("\\"))&&f("invalid-source-uri",`${m}.uri`,"local filesystem paths are forbidden");let z=S.sha256===null?null:Z(S.sha256,`${m}.sha256`);return z!==null&&!tt.test(z)&&f("invalid-hash",`${m}.sha256`,"expected lowercase SHA-256"),{id:N(S.id,`${m}.id`),kind:g,uri:R,sha256:z,license:Z(S.license,`${m}.license`)}});B.length===0&&f("missing-provenance","$.provenance.sources","expected at least one source"),G(B.map(P=>P.id),"$.provenance.sources");let ne={generator:N(V.generator,"$.provenance.generator"),generatorVersion:Z(V.generatorVersion,"$.provenance.generatorVersion"),sources:B};mo.test(ne.generatorVersion)||f("invalid-revision","$.provenance.generatorVersion","expected x.y.z");let O=ft(a,{controls:v,springs:E,animations:w});for(let P of O)i.includes(P)||f("missing-capability","$.capabilities",`profile requires ${P}`);let T=M.kind==="joint-skin"?M.joints.length:0,_=W?.frames.length??0,H=[["maxVertices",l.vertices.length,d.maxVertices],["maxPolygons",l.polygons.length,d.maxPolygons],["maxLeaves",b.length,d.maxLeaves],["maxFrames",_,d.maxFrames],["maxJoints",T,d.maxJoints]];for(let[P,C,m]of H)C>m&&f("budget-exceeded",`$.budgets.${P}`,`${C} exceeds ${m}`);return{schema:ge,identity:r,profile:a,capabilities:i,budgets:d,topology:l,materials:c,render:u,deformation:M,controls:v,springs:E,animations:w,playback:W,provenance:ne}}function ze(o){return uo.test(o)}function Ve(o){try{return fo(o,"$"),!0}catch{return!1}}var k=class extends Error{constructor(e,t,n,r={}){super(`${t}: ${n}`),this.name="PolyMorphPackageError",this.code=e,this.path=t,"cause"in r&&(this.cause=r.cause)}};function Ye(o,e,t){if(o===null)return"null";if(typeof o=="string"||typeof o=="boolean")return JSON.stringify(o);if(typeof o=="number"){if(!Number.isFinite(o))throw new k("invalid-json",e,"numbers must be finite");return JSON.stringify(Object.is(o,-0)?0:o)}if(Array.isArray(o)){if(t.has(o))throw new k("invalid-json",e,"cycles are forbidden");t.add(o);let n=`[${o.map((r,a)=>Ye(r,`${e}[${a}]`,t)).join(",")}]`;return t.delete(o),n}if(typeof o=="object"&&o){if(t.has(o))throw new k("invalid-json",e,"cycles are forbidden");let n=Object.getPrototypeOf(o);if(n!==Object.prototype&&n!==null)throw new k("invalid-json",e,"expected a plain object");t.add(o);let r=o,a=`{${Object.keys(r).sort().map(i=>{let s=r[i];if(s===void 0||typeof s=="function"||typeof s=="symbol")throw new k("invalid-json",`${e}.${i}`,"value is not JSON");return`${JSON.stringify(i)}:${Ye(s,`${e}.${i}`,t)}`}).join(",")}}`;return t.delete(o),a}throw new k("invalid-json",e,"value is not JSON")}function Ge(o){return Ye(o,"$",new WeakSet)}function Pe(o){return new TextEncoder().encode(Ge(o))}function be(o,e="$"){let t;try{t=new TextDecoder("utf-8",{fatal:!0}).decode(o)}catch{throw new k("invalid-utf8",e,"expected UTF-8 bytes")}try{return JSON.parse(t)}catch{throw new k("invalid-json",e,"expected valid JSON")}}async function ie(o){if(!globalThis.crypto?.subtle)throw new k("missing-crypto","$","Web Crypto is required");let e=Uint8Array.from(o),t=await globalThis.crypto.subtle.digest("SHA-256",e);return[...new Uint8Array(t)].map(n=>n.toString(16).padStart(2,"0")).join("")}var ht=/^[a-f0-9]{64}$/,gt=/^\d+\.\d+\.\d+$/,Mt=/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/,Pt=new Set(["joint-skin","morph-regions","prepared-playback","static-prepared"]),bt=new Set(["data","image","model"]);function F(o,e,t){throw new k(o,e,t)}function Ce(o,e,t){(!o||typeof o!="object"||Array.isArray(o))&&F("invalid-type",e,"expected an object");let n=Object.keys(o).sort(),r=[...t].sort();return(n.length!==r.length||n.some((a,i)=>a!==r[i]))&&F("invalid-keys",e,`expected exactly ${r.join(", ")}`),o}function go(o,e){return Array.isArray(o)||F("invalid-type",e,"expected an array"),o}function le(o,e){return(typeof o!="string"||o.length===0)&&F("invalid-string",e,"expected a non-empty string"),o}function Ke(o,e){let t=le(o,e);return ze(t)||F("invalid-id",e,"expected a normalized kebab-case id"),t}function Xe(o,e){let t=le(o,e);return Ve(t)||F("invalid-path",e,"expected a normalized package-relative path"),t}function Mo(o,e){let t=le(o,e);return gt.test(t)||F("invalid-revision",e,"expected x.y.z"),t}function Po(o,e){let t=le(o,e);return Pt.has(t)||F("invalid-profile",e,t),t}function bo(o,e){let t=le(o,e);return ht.test(t)||F("invalid-hash",e,"expected lowercase SHA-256"),t}function xt(o,e){return(typeof o!="number"||!Number.isSafeInteger(o)||o<0)&&F("invalid-bytes",e,"expected a non-negative safe integer"),o}function $t(o,e){let t=Ce(o,e,["bytes","mediaType","path","role","sha256"]),n=le(t.role,`${e}.role`);bt.has(n)||F("invalid-role",`${e}.role`,n);let r=le(t.mediaType,`${e}.mediaType`).toLowerCase();return(!Mt.test(r)||r!==t.mediaType)&&F("invalid-media-type",`${e}.mediaType`,"expected a normalized type/subtype"),n==="image"&&!r.startsWith("image/")&&F("invalid-media-type",`${e}.mediaType`,"image resources require an image media type"),{path:Xe(t.path,`${e}.path`),role:n,mediaType:r,bytes:xt(t.bytes,`${e}.bytes`),sha256:bo(t.sha256,`${e}.sha256`)}}function Qe(o,e){let t=new Set;for(let n of o)t.has(n)&&F("duplicate",e,n),t.add(n)}function xo(o,e){o.some((t,n)=>n>0&&t<=o[n-1])&&F("non-canonical-order",e,"entries must be unique and sorted")}function xe(o){let e=Ce(o,"$",["identity","modelPath","profile","resources","schema"]);e.schema!==ce&&F("invalid-schema","$.schema",`expected ${ce}`);let t=Ce(e.identity,"$.identity",["id","name","revision"]),n={id:Ke(t.id,"$.identity.id"),name:le(t.name,"$.identity.name"),revision:Mo(t.revision,"$.identity.revision")},r=go(e.resources,"$.resources").map((d,l)=>$t(d,`$.resources[${l}]`));r.length===0&&F("missing-resource","$.resources","expected at least the model resource");let a=r.map(d=>d.path);Qe(a,"$.resources"),xo(a,"$.resources");let i=Xe(e.modelPath,"$.modelPath"),s=r.filter(d=>d.role==="model");return(s.length!==1||s[0].path!==i)&&F("invalid-model-resource","$.resources","expected exactly one model resource matching modelPath"),s[0].mediaType!=="application/json"&&F("invalid-model-resource","$.resources","model resource must be application/json"),{schema:ce,identity:n,profile:Po(e.profile,"$.profile"),modelPath:i,resources:r}}function vt(o,e){let t=Ce(o,e,["id","manifestPath","manifestSha256","name","profile","revision"]),n=Xe(t.manifestPath,`${e}.manifestPath`);return n.endsWith("/manifest.json")||F("invalid-manifest-path",`${e}.manifestPath`,"expected a package manifest.json path"),{id:Ke(t.id,`${e}.id`),name:le(t.name,`${e}.name`),revision:Mo(t.revision,`${e}.revision`),profile:Po(t.profile,`${e}.profile`),manifestPath:n,manifestSha256:bo(t.manifestSha256,`${e}.manifestSha256`)}}function $e(o){let e=Ce(o,"$",["defaultId","packages","schema"]);e.schema!==de&&F("invalid-schema","$.schema",`expected ${de}`);let t=go(e.packages,"$.packages").map((a,i)=>vt(a,`$.packages[${i}]`));t.length===0&&F("missing-package","$.packages","expected at least one package");let n=t.map(a=>a.id);Qe(n,"$.packages"),xo(n,"$.packages"),Qe(t.map(a=>a.manifestPath),"$.packages[*].manifestPath");let r=Ke(e.defaultId,"$.defaultId");return n.includes(r)||F("unknown-default","$.defaultId",r),{schema:de,defaultId:r,packages:t}}var Ze="model.json";function wt(o){return[...new Set(o.render.leaves.flatMap(e=>[...e.atlas?[e.atlas.resourcePath]:[],...e.fallback?[e.fallback.atlas.resourcePath]:[]]))].sort()}async function $o(o,e=[]){let t=D(o),n=Pe(t),r=new Map([[Ze,n]]),a=[{path:Ze,role:"model",mediaType:"application/json",bytes:n.byteLength,sha256:await ie(n)}];for(let l of e){if(r.has(l.path))throw new k("duplicate",l.path,"resource path is already present");let c=Uint8Array.from(l.bytes);r.set(l.path,c),a.push({path:l.path,role:l.role,mediaType:l.mediaType,bytes:c.byteLength,sha256:await ie(c)})}for(let l of wt(t)){let c=a.find(p=>p.path===l);if(!c)throw new k("missing-resource",l,"model image is not included in the package");if(c.role!=="image")throw new k("invalid-role",l,"model image resource must use the image role")}a.sort((l,c)=>l.path<c.path?-1:l.path>c.path?1:0);let i=xe({schema:ce,identity:t.identity,profile:t.profile,modelPath:Ze,resources:a}),s=a.reduce((l,c)=>l+c.bytes,0);if(a.length>t.budgets.maxResources)throw new k("budget-exceeded","$.budgets.maxResources",`${a.length} resources exceed ${t.budgets.maxResources}`);if(s>t.budgets.maxBytes)throw new k("budget-exceeded","$.budgets.maxBytes",`${s} bytes exceed ${t.budgets.maxBytes}`);let d=Pe(i);return{manifest:i,manifestBytes:d,manifestSha256:await ie(d),files:r}}async function vo(o,e){let t=e.map(a=>({id:a.manifest.identity.id,name:a.manifest.identity.name,revision:a.manifest.identity.revision,profile:a.manifest.profile,manifestPath:a.manifestPath,manifestSha256:a.manifestSha256}));t.sort((a,i)=>a.id<i.id?-1:a.id>i.id?1:0);let n=$e({schema:de,defaultId:o,packages:t}),r=Pe(n);return{catalog:n,bytes:r,sha256:await ie(r)}}function Ee(o,e){if(e.identity.id!==o.identity.id||e.identity.name!==o.identity.name||e.identity.revision!==o.identity.revision||e.profile!==o.profile)throw new k("profile-mismatch","$.model","model identity or profile does not match its manifest")}var ko=64*1024*1024,kt=1024,It=128*1024*1024,Io=3e4;function ve(o,e,t){let n=o??e;if(!Number.isSafeInteger(n)||n<=0)throw new k("invalid-limit",t,"expected a positive safe integer");return n}function Ro(o){if(typeof o!="string"||o.length===0||o.includes("\\")||o.includes("#")||o.includes("?"))throw new k("invalid-base-url","$.baseUrl","expected a clean HTTP(S) base URL");let e;try{e=new URL(o,globalThis.location?.href??"https://polycss.invalid/")}catch{throw new k("invalid-base-url","$.baseUrl","expected a valid URL")}if(e.protocol!=="http:"&&e.protocol!=="https:")throw new k("invalid-base-url","$.baseUrl","expected HTTP or HTTPS");return e.pathname.endsWith("/")||(e.pathname+="/"),e}async function Rt(o,e,t){let n=o.headers.get("content-length");if(n!==null){let a=Number(n);if(!Number.isSafeInteger(a)||a<0||a>t)throw new k("resource-too-large",e,`declared bytes exceed ${t}`)}if(o.body?.getReader){let a=o.body.getReader(),i=[],s=0;for(;;){let c=await a.read();if(c.done)break;if(s+=c.value.byteLength,s>t)throw await a.cancel(),new k("resource-too-large",e,`bytes exceed ${t}`);i.push(c.value)}let d=new Uint8Array(s),l=0;for(let c of i)d.set(c,l),l+=c.byteLength;return d}if(n===null)throw new k("resource-too-large",e,"content-length is required without a readable body");let r=new Uint8Array(await o.arrayBuffer());if(r.byteLength>t)throw new k("resource-too-large",e,`bytes exceed ${t}`);return r}async function eo(o,e,t,n,r){let a=n??AbortSignal.timeout(r),i;try{i=await o(e,{cache:"no-store",signal:a})}catch(s){throw a.aborted?s:new k("request-failed",e.pathname,"request failed",{cause:s})}if(!i.ok)throw new k("request-failed",e.pathname,`HTTP ${i.status}`);return Rt(i,e.pathname,t)}async function wo(o,e,t){let n=await ie(o);if(n!==e)throw new k("stale-hash",t,`expected ${e}, received ${n}`)}function St(o,e){let t=e.lastIndexOf("/");return Ue(o,e.slice(0,t+1))}function Ue(o,e){let t=new URL(e,o);if(t.origin!==o.origin||!t.href.startsWith(o.href))throw new k("invalid-path",e,"package path escapes its base URL");return t}async function oo(o,e={}){let t=Ro(o),n=ve(e.maxResourceBytes,ko,"$.maxResourceBytes"),r=e.fetchImpl??globalThis.fetch;if(typeof r!="function")throw new k("missing-fetch","$.fetchImpl","a fetch implementation is required");let a=ve(e.requestTimeoutMs,Io,"$.requestTimeoutMs"),i=await eo(r,Ue(t,"catalog.json"),n,e.signal,a);return{catalog:$e(be(i,"$.catalog")),bytes:i,sha256:await ie(i)}}async function So(o,e={}){let t=Ro(o),n=ve(e.maxResourceBytes,ko,"$.maxResourceBytes"),r=ve(e.maxResources,kt,"$.maxResources"),a=ve(e.maxTotalBytes,It,"$.maxTotalBytes"),i=ve(e.requestTimeoutMs,Io,"$.requestTimeoutMs"),s=e.fetchImpl??globalThis.fetch;if(typeof s!="function")throw new k("missing-fetch","$.fetchImpl","a fetch implementation is required");let d=await oo(t.href,{fetchImpl:s,maxResourceBytes:n,requestTimeoutMs:i,signal:e.signal}),l=e.modelId??d.catalog.defaultId,c=d.catalog.packages.find(x=>x.id===l);if(!c)throw new k("unknown-package","$.modelId",l);let p=await eo(s,Ue(t,c.manifestPath),n,e.signal,i);await wo(p,c.manifestSha256,c.manifestPath);let y=xe(be(p,"$.manifest"));if(y.identity.id!==c.id||y.identity.name!==c.name||y.identity.revision!==c.revision||y.profile!==c.profile)throw new k("profile-mismatch","$.manifest","catalog row does not match its manifest");let b=St(t,c.manifestPath);if(y.resources.length>r)throw new k("package-too-large","$.manifest.resources",`${y.resources.length} resources exceed ${r}`);let u=0;for(let x of y.resources){if(x.bytes>n)throw new k("resource-too-large",x.path,`declared bytes exceed ${n}`);if(u+=x.bytes,u>a)throw new k("package-too-large",x.path,`declared package bytes exceed ${a}`)}let M=new Map,$=async x=>{let w=await eo(s,Ue(b,x.path),Math.min(n,x.bytes),e.signal,i);if(w.byteLength!==x.bytes)throw new k("stale-size",x.path,`expected ${x.bytes}, received ${w.byteLength}`);return await wo(w,x.sha256,x.path),{descriptor:x,bytes:w}},h=y.resources.find(x=>x.path===y.modelPath),v=await $(h);M.set(h.path,v);let I=D(be(v.bytes,"$.model"));if(Ee(y,I),y.resources.length>I.budgets.maxResources)throw new k("budget-exceeded","$.budgets.maxResources",`${y.resources.length} resources exceed ${I.budgets.maxResources}`);if(u>I.budgets.maxBytes)throw new k("budget-exceeded","$.budgets.maxBytes",`${u} bytes exceed ${I.budgets.maxBytes}`);for(let x of y.resources)x!==h&&M.set(x.path,await $(x));let E=new Set(I.render.leaves.flatMap(x=>[...x.atlas?[x.atlas.resourcePath]:[],...x.fallback?[x.fallback.atlas.resourcePath]:[]]));for(let x of E){let w=M.get(x);if(!w)throw new k("missing-resource",x,"model image is not declared by the package");if(w.descriptor.role!=="image")throw new k("invalid-role",x,"model image resource must use the image role")}return{catalog:d.catalog,catalogSha256:d.sha256,catalogRow:c,manifest:y,manifestSha256:c.manifestSha256,model:I,resources:M}}var te=require("@layoutit/polycss");var we=class extends Error{constructor(e,t,n){super(`${t}: ${n}`),this.name="PolyMorphRenderError",this.code=e,this.path=t}};var jt={"atlas-slice":"s","direct-image":"s","solid-quad":"b","solid-triangle":"u"};function U(o,e,t){throw new we(o,e,t)}function no(o,e){return(!Array.isArray(o)||o.length!==16||o.some(t=>typeof t!="number"||!Number.isFinite(t)))&&U("invalid-matrix",e,"expected sixteen finite components"),o}function me(o){return`matrix3d(${(0,te.formatMatrix3dValues)(o)})`}function Ct(o,e){let t=new Array(16).fill(0);for(let n=0;n<4;n+=1)for(let r=0;r<4;r+=1){let a=0;for(let i=0;i<4;i+=1)a+=o[i*4+r]*e[n*4+i];t[n*4+r]=Object.is(a,-0)?0:a}return t}function to(o,e,t){return t&&o.fallback?Ct(e,o.fallback.matrixFromLeaf):e}function Ot(o){let[e,t,n,r]=o;return`rgba(${Math.round(e*255)}, ${Math.round(t*255)}, ${Math.round(n*255)}, ${r})`}function ro(o,e,t,n=[]){(!o||typeof o!="object"||Array.isArray(o))&&U("invalid-update",e,"expected an object");let r=new Set([...t,...n]),a=Object.keys(o);return(t.some(i=>!a.includes(i))||a.some(i=>!r.has(i)))&&U("invalid-update",e,`allowed keys are ${[...r].sort().join(", ")}`),o}function jo(o,e){let t=new Set;for(let n of o)t.has(n)&&U("duplicate-update",e,n),t.add(n)}function At(o,e){let t=ro(o,e,["matrix","shapeId"]);return typeof t.shapeId!="string"&&U("invalid-update",`${e}.shapeId`,"expected a string"),{shapeId:t.shapeId,matrix:no(t.matrix,`${e}.matrix`)}}function Lt(o,e){let t=ro(o,e,["leafId"],["atlasRow","matrix","opacity","visible"]);typeof t.leafId!="string"&&U("invalid-update",`${e}.leafId`,"expected a string");let n={leafId:t.leafId};return t.matrix!==void 0&&(n.matrix=no(t.matrix,`${e}.matrix`)),t.visible!==void 0&&(typeof t.visible!="boolean"&&U("invalid-update",`${e}.visible`,"expected a boolean"),n.visible=t.visible),t.opacity!==void 0&&((typeof t.opacity!="number"||!Number.isFinite(t.opacity)||t.opacity<0||t.opacity>1)&&U("invalid-update",`${e}.opacity`,"expected 0 <= opacity <= 1"),n.opacity=t.opacity),t.atlasRow!==void 0&&((!Number.isSafeInteger(t.atlasRow)||t.atlasRow<0)&&U("invalid-update",`${e}.atlasRow`,"expected a non-negative integer"),n.atlasRow=t.atlasRow),n}function Tt(o){let e=ro(o,"$",[],["leaves","modelMatrix","shapes"]),t=e.shapes===void 0?void 0:(()=>{Array.isArray(e.shapes)||U("invalid-update","$.shapes","expected an array");let r=e.shapes.map((a,i)=>At(a,`$.shapes[${i}]`));return jo(r.map(a=>a.shapeId),"$.shapes"),r})(),n=e.leaves===void 0?void 0:(()=>{Array.isArray(e.leaves)||U("invalid-update","$.leaves","expected an array");let r=e.leaves.map((a,i)=>Lt(a,`$.leaves[${i}]`));return jo(r.map(a=>a.leafId),"$.leaves"),r})();return{...e.modelMatrix===void 0?{}:{modelMatrix:no(e.modelMatrix,"$.modelMatrix")},...t===void 0?{}:{shapes:t},...n===void 0?{}:{leaves:n}}}function zt(o,e,t,n){o.style.setProperty("--polycss-atlas-width",`${e.width}px`),o.style.setProperty("--polycss-atlas-height",`${e.height}px`),o.style.backgroundImage=`url("${n.replace(/"/gu,"%22")}")`,o.style.backgroundPosition=`${-t.x}px ${-t.y}px`,o.style.backgroundSize=`${t.pageWidth}px ${t.pageHeight}px`}function Vt(o,e,t,n,r){let a=`url("${r.replace(/"/gu,"%22")}")`,i=`${-e.x}px ${-e.y}px`,s=`${e.pageWidth}px ${e.pageHeight}px`;o.style.width=`${t}px`,o.style.height=`${n}px`,o.style.backgroundColor="currentColor",o.style.setProperty("mask-image",a),o.style.setProperty("mask-mode","alpha"),o.style.setProperty("mask-position",i),o.style.setProperty("mask-repeat","no-repeat"),o.style.setProperty("mask-size",s),o.style.setProperty("-webkit-mask-image",a),o.style.setProperty("-webkit-mask-position",i),o.style.setProperty("-webkit-mask-repeat","no-repeat"),o.style.setProperty("-webkit-mask-size",s)}function Et(o,e,t,n,r){let a=r?e.fallback:null,i=o.createElement(a?"s":jt[e.strategy]);return i.className="polycss-morph-leaf",i.dataset.polyMorphLeaf=e.id,i.dataset.polyMorphStrategy=e.strategy,i.dataset.polyMorphResolvedStrategy=a?"atlas-slice":e.strategy,i.style.transform=me(to(e,e.matrix,a!==null)),i.style.color=Ot(t),i.style.backfaceVisibility="visible",i.style.backgroundRepeat="no-repeat",i.style.opacity="1",i.style.transformOrigin="0 0",i.style.visibility="visible",e.atlas?(i.style.width=`${e.width}px`,i.style.height=`${e.height}px`,zt(i,e,e.atlas,n(e.atlas.resourcePath,e.id))):a?Vt(i,a.atlas,a.width,a.height,n(a.atlas.resourcePath,e.id)):e.strategy==="solid-quad"&&(i.style.width=`${e.width}px`,i.style.height=`${e.height}px`),i}function Co(o,e,t={}){(!o||typeof o.appendChild!="function"||!o.ownerDocument)&&U("invalid-host","$.host","expected an HTMLElement");let n=D(e),r=o.ownerDocument,a=n.render.leaves.some(g=>g.strategy==="solid-triangle")&&!(0,te.isSolidTriangleSupported)(r),i=new Map,s=typeof r.defaultView?.URL?.createObjectURL=="function"?r.defaultView.URL:globalThis.URL,d=r.defaultView?.Blob??globalThis.Blob,l=()=>{for(let g of i.values())s.revokeObjectURL(g);i.clear()},c=(g,R)=>{let z=i.get(g);if(z)return z;let q=t.resources?.get(g);(!q||q.descriptor.path!==g||q.descriptor.role!=="image")&&U("missing-resource",R,"image-backed leaves require their verified package resource"),(typeof s?.createObjectURL!="function"||typeof s?.revokeObjectURL!="function"||typeof d!="function")&&U("missing-object-url",R,"this browser cannot mount verified image bytes");let ee=q.bytes.slice(),pe=s.createObjectURL(new d([ee.buffer],{type:q.descriptor.mediaType}));return i.set(g,pe),pe};try{for(let g of n.render.leaves)g.atlas&&c(g.atlas.resourcePath,g.id),a&&g.strategy==="solid-triangle"&&(g.fallback||U("missing-solid-triangle-fallback",`${g.id}.fallback`,"this browser requires a prepared per-polygon atlas slice"),c(g.fallback.atlas.resourcePath,g.id))}catch(g){throw l(),g}(0,te.injectPolyBaseStyles)(r);let p=r.defaultView?.getComputedStyle(o),y=o.style.position,b=!1;(!p||p.position==="static"||p.position==="")&&(o.style.position="relative",b=!0);let u=t.camera??(0,te.createPolyCamera)({zoom:1}),M=r.createElement("div");M.className="polycss-camera polycss-morph-camera";let $=(0,te.capturePolyCameraSnapshot)(u);M.style.perspective=$.appliedPerspectiveStyle,M.dataset.polycssCameraProjection=$.projection,o.appendChild(M);let h=r.createElement("div");h.className="polycss-scene polycss-morph-scene",h.setAttribute("aria-hidden","true");let v=(0,te.buildPolyCameraSceneTransform)(u.state);h.style.transform=v,M.appendChild(h);let I=r.createElement("div");I.className="polycss-mesh polycss-morph-model",I.dataset.polyMorphModel=n.identity.id;let E=me(n.render.modelMatrix);I.style.transform=E,h.appendChild(I);let x=new Map,w=new Map;for(let g of n.render.shapes){let R=r.createElement("div");R.className="polycss-mesh polycss-morph-shape",R.dataset.polyMorphShape=g.id;let z=me(g.matrix);R.style.transform=z,I.appendChild(R),x.set(g.id,R),w.set(g.id,z)}let W=new Map(n.materials.map(g=>[g.id,g])),V=new Map,B=new Map;for(let g of n.render.leaves){let R=x.get(g.shapeId),z=W.get(g.materialId);(!R||!z)&&U("mount-coverage",g.id,"leaf references are incomplete");let q=Et(r,g,z.color,c,a&&g.strategy==="solid-triangle");R.appendChild(q),V.set(g.id,{id:g.id,plan:g,element:q}),B.set(g.id,{transform:me(to(g,g.matrix,a&&g.strategy==="solid-triangle")),visible:!0,opacity:1,atlasRow:0})}let ne=[...x.entries()],O=[...V.entries()],T=!1,_=v,H={applyCount:0,totalTransformWrites:0,totalVisibilityWrites:0,totalOpacityWrites:0,totalAtlasRowWrites:0},P=()=>{T&&U("destroyed","$","mounted model is destroyed")},C=()=>{P(),(x.size!==ne.length||V.size!==O.length)&&U("identity-drift","$","retained handle maps changed");for(let[g,R]of ne)(x.get(g)!==R||R.parentElement!==I)&&U("identity-drift",g,"shape element identity changed");for(let[g,R]of O){let z=x.get(R.plan.shapeId);(V.get(g)!==R||R.element.parentElement!==z)&&U("identity-drift",g,"leaf element identity changed")}},S={model:n,camera:u,cameraElement:M,sceneElement:h,modelElement:I,shapeElements:x,leafHandles:V,get stats(){return{mountCount:1,shapeRoots:x.size,leafCount:V.size,topologyConstructions:1,atlasConstructions:0,schedulerCount:0,...H}},get destroyed(){return T},apply:g=>{P();let R=Tt(g),z=(R.shapes??[]).map(j=>{let Q=x.get(j.shapeId);return Q||U("unknown-shape",j.shapeId,"no retained shape handle"),{shape:j,element:Q}}),q=(R.leaves??[]).map(j=>{let Q=V.get(j.leafId),Y=B.get(j.leafId);(!Q||!Y)&&U("unknown-leaf",j.leafId,"no retained leaf handle");let Le;if(j.atlasRow!==void 0){let oe=Q.plan.atlas;oe||U("invalid-atlas-row",j.leafId,"leaf has no image rows");let yo=oe.y+j.atlasRow*oe.height;yo+oe.height>oe.pageHeight&&U("invalid-atlas-row",j.leafId,"row exceeds the image page"),Le=`${-oe.x}px ${-yo}px`}return{leaf:j,handle:Q,state:Y,atlasPosition:Le}});C();let ee=0,pe=0,fe=0,he=0,ye=0,Se=0;if(R.modelMatrix){let j=me(R.modelMatrix);E!==j&&(E=j,I.style.transform=j,ee+=1)}for(let{shape:j,element:Q}of z){let Y=me(j.matrix);w.get(j.shapeId)!==Y&&(w.set(j.shapeId,Y),Q.style.transform=Y,pe+=1)}for(let{leaf:j,handle:Q,state:Y,atlasPosition:Le}of q){if(j.matrix){let oe=me(to(Q.plan,j.matrix,a&&Q.plan.strategy==="solid-triangle"));Y.transform!==oe&&(Y.transform=oe,Q.element.style.transform=oe,fe+=1)}if(j.visible!==void 0){let oe=j.visible?"visible":"hidden";Y.visible!==j.visible&&(Y.visible=j.visible,Q.element.style.visibility=oe,he+=1)}if(j.opacity!==void 0){let oe=String(j.opacity);Y.opacity!==j.opacity&&(Y.opacity=j.opacity,Q.element.style.opacity=oe,ye+=1)}j.atlasRow!==void 0&&Y.atlasRow!==j.atlasRow&&(Y.atlasRow=j.atlasRow,Q.element.style.backgroundPosition=Le,Se+=1)}return C(),H.applyCount+=1,H.totalTransformWrites+=ee+pe+fe,H.totalVisibilityWrites+=he,H.totalOpacityWrites+=ye,H.totalAtlasRowWrites+=Se,{modelTransformWrites:ee,shapeTransformWrites:pe,leafTransformWrites:fe,visibilityWrites:he,opacityWrites:ye,atlasRowWrites:Se,dirtyLeavesVisited:R.leaves?.length??0,domCreations:0,domRemovals:0,topologyConstructions:0,atlasRedraws:0,schedulerCallbacks:0}},updateCamera(){P();let g=(0,te.buildPolyCameraSceneTransform)(u.state);if(_===g)return!1;_=g,h.style.transform=g;let R=(0,te.capturePolyCameraSnapshot)(u);return M.style.perspective=R.appliedPerspectiveStyle,M.dataset.polycssCameraProjection=R.projection,!0},assertStableDomIdentity:C,destroy(){T||(T=!0,M.remove(),x.clear(),V.clear(),B.clear(),w.clear(),l(),b&&o.style.position==="relative"&&(o.style.position=y))}};return S.assertStableDomIdentity(),S}var K=class extends Error{constructor(e,t,n){super(`${t}: ${n}`),this.name="PolyMorphRuntimeError",this.code=e,this.path=t}};function Oo(o,e,t){throw new K(o,e,t)}function Be(o){return Object.freeze([...o])}function Ut(o,e){let{timesMs:t,values:n}=o;if(e<=t[0])return Be(n[0]);for(let r=1;r<t.length;r+=1){let a=t[r];if(e>a)continue;let i=t[r-1],s=n[r-1],d=n[r];if(e===a)return Be(d);if(o.interpolation==="step")return Be(s);let l=(e-i)/(a-i);if(o.target==="joint-rotation"){let p=s.reduce((u,M,$)=>u+M*d[$],0)<0?-1:1,y=s.map((u,M)=>u+(d[M]*p-u)*l),b=Math.hypot(...y);return Object.freeze(y.map(u=>u/b))}return Object.freeze(s.map((c,p)=>c+(d[p]-c)*l))}return Be(n[n.length-1])}function Bt(o,e){if(o.loop){let t=e%o.durationMs;return Object.is(t,-0)?0:t}return Math.min(e,o.durationMs)}function _e(o){let e=D(o),t=new Map(e.animations.map(n=>[n.id,n]));return Object.freeze({model:e,clipIds:Object.freeze([...t.keys()]),sample(n,r){let a=t.get(n);a||Oo("unknown-clip","$.clipId",n),(!Number.isFinite(r)||r<0)&&Oo("invalid-time","$.timeMs","expected a finite non-negative time");let i=Bt(a,r),s={},d={},l=new Map,c=new Map;for(let p of a.channels){let y=Ut(p,i);if(p.target==="morph-weight"&&(s[p.targetId]=y[0]),p.target==="control-value"&&(d[p.targetId]=y[0]),p.target==="shape-matrix"&&c.set(p.targetId,y),p.target.startsWith("joint-")){let b=l.get(p.targetId)??{};p.target==="joint-translation"?b.translation=y:p.target==="joint-rotation"?b.rotation=y:b.scale=y,l.set(p.targetId,b)}}return{clipId:n,requestedTimeMs:r,sampledTimeMs:i,morphWeights:Object.freeze(s),controlValues:Object.freeze(d),jointTransforms:l,shapeMatrices:c}}})}function ao(o,e,t){throw new K(o,e,t)}function Ao(o){return o===null?null:((!Array.isArray(o)||o.length!==3||o.some(e=>typeof e!="number"||!Number.isFinite(e)))&&ao("invalid-point","$.point","expected three finite components or null"),[o[0],o[1],o[2]])}function _t(o){let e=Math.hypot(...o.axis);return[o.axis[0]/e,o.axis[1]/e,o.axis[2]/e]}function Lo(o){let e=D(o);return Object.freeze({model:e,controlIds:Object.freeze(e.controls.map(t=>t.id)),controls:new Map(e.controls.map(t=>[t.id,t]))})}function To(o){return Object.freeze({tick:-1,active:!1,heldControlId:null,holdStartPoint:null,holdStartValue:0,values:Object.freeze(Object.fromEntries(o.controlIds.map(e=>[e,o.controls.get(e).initial]))),frozenControlIds:Object.freeze([])})}function io(o,e){let t=Ao(e),n=null;for(let r of o.controlIds){let a=o.controls.get(r),i=Math.hypot(t[0]-a.anchor[0],t[1]-a.anchor[1],t[2]-a.anchor[2]);i<=a.radius&&(!n||i<n.distance)&&(n={id:r,distance:i})}return n?.id??null}function zo(o,e,t){(!e||!Number.isSafeInteger(e.tick)||e.tick<-1)&&ao("invalid-state","$.state","control state is invalid"),typeof t?.active!="boolean"&&ao("invalid-input","$.active","expected a boolean");let n=Ao(t.point),r=e.heldControlId,a=e.holdStartPoint,i=e.holdStartValue,s=null,d=null,l={...e.values},c=new Set(e.frozenControlIds),p=t.active&&!e.active,y=!t.active&&e.active;if(p&&n&&(r=io(o,n),r&&(s=r,a=n,i=l[r]??o.controls.get(r).initial,c.delete(r))),t.active&&r&&n&&a){let u=o.controls.get(r),M=_t(u),$=(n[0]-a[0])*M[0]+(n[1]-a[1])*M[1]+(n[2]-a[2])*M[2];l[r]=Math.max(u.minimum,Math.min(u.maximum,i+$))}y&&(d=r,r&&(t.freezeOnRelease===!0?c.add(r):c.delete(r)),r=null,a=null,i=0);let b=Object.freeze({tick:e.tick+1,active:t.active,heldControlId:r,holdStartPoint:a,holdStartValue:i,values:Object.freeze(l),frozenControlIds:Object.freeze([...c].sort())});return Object.freeze({state:b,pickedControlId:s,releasedControlId:d,heldTarget:t.active&&r?Object.freeze({controlId:r,value:l[r]}):null})}var ke=require("@layoutit/polycss");function re(o,e,t){throw new K(o,e,t)}function Ft(o,e){return(typeof o!="number"||!Number.isFinite(o))&&re("invalid-number",e,"expected a finite number"),Object.is(o,-0)?0:o}function Eo(o){let e=Math.hypot(...o);return e<=1e-12?[0,0,0]:[o[0]/e,o[1]/e,o[2]/e]}function Fe(o){return o.map(e=>[e[0],e[1],e[2]])}function He(o){for(let e of o)Object.freeze(e);return Object.freeze(o)}function Ht(o,e){let[t,n,r]=o.vertexIndices,a=e[t],i=e[n],s=e[r],d=(0,ke.computeSolidTrianglePlanFromCssPoints)(o.polygon,0,{seamBleed:0},{basis:o.basis??void 0,includeColor:!1,primitive:"corner-bevel"},a[0],a[1],a[2],i[0],i[1],i[2],s[0],s[1],s[2]);if(!d)return{matrix:null,visible:!1};let l=/^matrix3d\(([^)]+)\)$/u.exec(d.transformText);l||re("invalid-transform",o.leaf.id,"PolyCSS returned no matrix3d");let c=l[1].split(",").map(Number);(c.length!==16||c.some(b=>!Number.isFinite(b)))&&re("invalid-transform",o.leaf.id,"PolyCSS returned an invalid matrix3d");let p=ke.SOLID_TRIANGLE_CANONICAL_SIZE/o.leaf.width,y=ke.SOLID_TRIANGLE_CANONICAL_SIZE/o.leaf.height;for(let b of[0,1,2])c[b]*=p;for(let b of[4,5,6])c[b]*=y;return{matrix:c,visible:!0}}function Nt(o,e){let[t,n,r,a]=o.vertexIndices,i=e[t],s=e[n],d=e[r],l=e[a],c=[s[0]+l[0]-i[0],s[1]+l[1]-i[1],s[2]+l[2]-i[2]];Math.hypot(c[0]-d[0],c[1]-d[1],c[2]-d[2])>1e-6&&re("non-affine-polygon",o.leaf.id,"deformed quad is not a parallelogram");let p=[(s[0]-i[0])/o.leaf.width,(s[1]-i[1])/o.leaf.width,(s[2]-i[2])/o.leaf.width],y=[(l[0]-i[0])/o.leaf.height,(l[1]-i[1])/o.leaf.height,(l[2]-i[2])/o.leaf.height],b=[p[1]*y[2]-p[2]*y[1],p[2]*y[0]-p[0]*y[2],p[0]*y[1]-p[1]*y[0]],u=Eo(b);return Math.hypot(...u)<=1e-12&&re("degenerate-polygon",o.leaf.id,"deformed quad has no area"),{matrix:[p[0],p[1],p[2],0,y[0],y[1],y[2],0,u[0],u[1],u[2],0,i[0],i[1],i[2],1],visible:!0}}function so(o,e){if(o.vertexIndices.length===3)return Ht(o,e);if(o.vertexIndices.length===4)return Nt(o,e);re("unsupported-deformation",o.leaf.id,"caller-driven deformation supports prepared triangles and affine quads")}function lo(o,e){let t=o.topology.polygons.find(i=>i.id===e.polygonId);t||re("unknown-polygon",e.id,e.polygonId);let n=t.vertexIndices.map(i=>[...o.topology.vertices[i]]),r={vertices:n},a=null;if(n.length===3){let[i,s,d]=n,l=(0,ke.computeSolidTrianglePlanFromCssPoints)(r,0,{seamBleed:0},{includeColor:!1,primitive:"corner-bevel"},i[0],i[1],i[2],s[0],s[1],s[2],d[0],d[1],d[2]);l||re("degenerate-polygon",e.id,"base triangle has no area"),a=l.basis}return{leaf:e,vertexIndices:t.vertexIndices,polygon:r,basis:a}}function Vo(o,e,t,n){let r=o??{};(!r||typeof r!="object"||Array.isArray(r))&&re("invalid-input",t,"expected an object");let a=new Set(e),i=Object.keys(r).find(s=>!a.has(s));return i&&re("unknown-id",t,i),Object.fromEntries(e.map(s=>{let[d,l]=n.get(s)??[0,1],c=Ft(r[s]??0,`${t}.${s}`);return(c<d||c>l)&&re("out-of-range",`${t}.${s}`,`expected ${d} <= value <= ${l}`),[s,c]}))}function Dt(o){return new Map(o.deformation.kind==="morph-regions"?o.deformation.targets.map(e=>[e.id,e]):[])}function Uo(o){let e=D(o);e.deformation.kind==="joint-skin"&&re("profile-not-executable","$.profile","joint skin requires the skinning runtime");let t=Dt(e),n=[...t.keys()],r=e.controls.map(h=>h.id),a=new Map(n.map(h=>[h,[0,1]])),i=new Map(e.controls.map(h=>[h.id,[h.minimum,h.maximum]])),s=new Map(e.render.leaves.map(h=>[h.polygonId,h])),d=new Map;for(let h of e.topology.polygons)for(let v of h.vertexIndices){let I=d.get(v)??[];I.push(h.id),d.set(v,I)}let l=new Map;for(let h of t.values()){let v=new Set;for(let I of h.deltas)for(let E of d.get(I.vertexIndex)??[]){let x=s.get(E);x&&v.add(x.id)}l.set(h.id,v)}let c=new Map(e.render.leaves.map(h=>[h.id,lo(e,h)])),p=He(Fe(e.topology.vertices)),y=He(Fe(e.topology.normals)),b=Object.fromEntries(n.map(h=>[h,0])),u=p,M=y,$=h=>{(!h||!Number.isSafeInteger(h.tick)||h.tick<0)&&re("invalid-tick","$.tick","expected a non-negative safe integer");let v=Vo(h.morphWeights,n,"$.morphWeights",a),I=Vo(h.controlValues,r,"$.controlValues",i),E={...v};for(let O of e.controls){let T=I[O.id];for(let _ of O.targets)E[_.targetId]=Math.max(0,Math.min(1,(E[_.targetId]??0)+T*_.scale))}let x=n.filter(O=>E[O]!==b[O]),w=u,W=M;if(x.length>0){let O=Fe(p),T=Fe(y);for(let _ of n){let H=E[_];if(H!==0)for(let P of t.get(_).deltas){let C=O[P.vertexIndex];P.position&&(C[0]+=P.position[0]*H,C[1]+=P.position[1]*H,C[2]+=P.position[2]*H);let m=T[P.vertexIndex];P.normal&&(m[0]+=P.normal[0]*H,m[1]+=P.normal[1]*H,m[2]+=P.normal[2]*H)}}T=T.map(Eo),w=He(O),W=He(T)}let V=new Set;for(let O of x)for(let T of l.get(O)??[])V.add(T);let B=e.render.leaves.map(O=>O.id).filter(O=>V.has(O)),ne=B.map(O=>{let T=so(c.get(O),w);return{leafId:O,visible:T.visible,...T.matrix?{matrix:T.matrix}:{}}});return u=w,M=W,b={...E},{tick:h.tick,positions:w,normals:W,morphWeights:Object.freeze({...E}),controlValues:Object.freeze({...I}),dirtyLeafIds:Object.freeze(B),leafUpdates:Object.freeze(ne),runtimePolygonConstructions:0,runtimeTopologyConstructions:0,atlasRedraws:0}};return Object.freeze({model:e,targetIds:Object.freeze(n),controlIds:Object.freeze(r),basePositions:Object.freeze(p),baseNormals:Object.freeze(y),sample:$,reset(){b=Object.fromEntries(n.map(h=>[h,0])),u=p,M=y}})}function Oe(o,e,t){throw new K(o,e,t)}function Ie(o){return Object.freeze([...o])}function co(o,e){return o.every((t,n)=>t===e[n])}function Ne(o){let e=D(o);return Object.freeze({modelMatrix:Ie(e.render.modelMatrix),shapes:Object.freeze(e.render.shapes.map(t=>Object.freeze({shapeId:t.id,matrix:Ie(t.matrix)}))),leaves:Object.freeze(e.render.leaves.map(t=>Object.freeze({leafId:t.id,matrix:Ie(t.matrix),visible:!0,opacity:1,atlasRow:0})))})}function De(o,e){let t=new Map(e.shapes.map(r=>[r.shapeId,r])),n=new Map(e.leaves.map(r=>[r.leafId,r]));for(let r of t.keys())o.shapes.some(a=>a.shapeId===r)||Oe("unknown-shape","$.frame.shapes",r);for(let r of n.keys())o.leaves.some(a=>a.leafId===r)||Oe("unknown-leaf","$.frame.leaves",r);return Object.freeze({modelMatrix:e.modelMatrix===null?o.modelMatrix:Ie(e.modelMatrix),shapes:Object.freeze(o.shapes.map(r=>{let a=t.get(r.shapeId);return a?Object.freeze({shapeId:r.shapeId,matrix:Ie(a.matrix)}):r})),leaves:Object.freeze(o.leaves.map(r=>{let a=n.get(r.leafId);return a?Object.freeze({leafId:r.leafId,matrix:a.matrix===null?r.matrix:Ie(a.matrix),visible:a.visible??r.visible,opacity:a.opacity??r.opacity,atlasRow:a.atlasRow??r.atlasRow}):r}))})}function qe(o,e){(o.shapes.length!==e.shapes.length||o.leaves.length!==e.leaves.length)&&Oe("state-mismatch","$","prepared state topology differs");let t=!co(o.modelMatrix,e.modelMatrix),n=[];for(let a=0;a<e.shapes.length;a+=1){let i=o.shapes[a],s=e.shapes[a];i.shapeId!==s.shapeId&&Oe("state-mismatch","$.shapes","source order differs"),co(i.matrix,s.matrix)||n.push({shapeId:s.shapeId,matrix:s.matrix})}let r=[];for(let a=0;a<e.leaves.length;a+=1){let i=o.leaves[a],s=e.leaves[a];i.leafId!==s.leafId&&Oe("state-mismatch","$.leaves","source order differs");let d={leafId:s.leafId};co(i.matrix,s.matrix)||(d.matrix=s.matrix),i.visible!==s.visible&&(d.visible=s.visible),i.opacity!==s.opacity&&(d.opacity=s.opacity),i.atlasRow!==s.atlasRow&&(d.atlasRow=s.atlasRow),Object.keys(d).length>1&&r.push(d)}return Object.freeze({update:Object.freeze({...t?{modelMatrix:e.modelMatrix}:{},...n.length>0?{shapes:Object.freeze(n)}:{},...r.length>0?{leaves:Object.freeze(r)}:{}}),modelChanged:t,dirtyShapeIds:Object.freeze(n.map(a=>a.shapeId)),dirtyLeafIds:Object.freeze(r.map(a=>a.leafId))})}function Ae(o,e,t){throw new K(o,e,t)}function qt(o,e,t){if(e){let n=t%o;return Object.is(n,-0)?0:n}return Math.min(t,o)}function Jt(o,e){let t=0,n=o.length-1;for(;t<=n;){let r=Math.floor((t+n)/2);o[r]<=e?t=r+1:n=r-1}return Math.max(0,n)}function Bo(o){let e=D(o);(e.profile!=="prepared-playback"||!e.playback)&&Ae("profile-mismatch","$.profile","playback requires the prepared-playback profile");let t=e.playback,n=Ne(e),r=[],a=n,i=new Map(e.render.leaves.map(p=>[p.id,p]));for(let[p,y]of t.frames.entries()){for(let b of y.leaves){if(b.atlasRow===null)continue;let u=i.get(b.leafId);u.atlas||Ae("invalid-atlas-row",`$.playback.frames[${p}]`,`${u.id} has no image rows`),u.atlas.y+b.atlasRow*u.atlas.height+u.atlas.height>u.atlas.pageHeight&&Ae("invalid-atlas-row",`$.playback.frames[${p}]`,`${u.id} row exceeds its page`)}a=De(a,y),r.push(a)}let s=t.frames.map(p=>p.timeMs),d=n,l=null,c=p=>{(!Number.isFinite(p)||p<0)&&Ae("invalid-time","$.timeMs","expected a finite non-negative time");let y=qt(t.durationMs,t.loop,p),b=Jt(s,y),u=r[b],M=qe(d,u),$=Object.freeze({requestedTimeMs:p,sampledTimeMs:y,frameIndex:b,state:u,update:M.update,modelChanged:M.modelChanged,dirtyShapeIds:M.dirtyShapeIds,dirtyLeafIds:M.dirtyLeafIds,domCreations:0,domRemovals:0,topologyConstructions:0,atlasConstructions:0,atlasRedraws:0,schedulerCallbacks:0});return l=$,$};return Object.freeze({model:e,durationMs:t.durationMs,loop:t.loop,frameCount:t.frames.length,sample:c,commit(p){p!==l&&Ae("invalid-sample","$.sample","commit requires the latest unapplied playback sample"),d=p.state,l=null},reset(){d=n,l=null}})}var _o=Object.freeze(["joint-skin","morph-regions","prepared-playback","static-prepared"]);function ae(o,e,t){throw new K(o,e,t)}function Wt(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function po(o,e){let t=new Array(16).fill(0);for(let n=0;n<4;n+=1)for(let r=0;r<4;r+=1){let a=0;for(let i=0;i<4;i+=1)a+=o[i*4+r]*e[n*4+i];t[n*4+r]=Object.is(a,-0)?0:a}return Object.freeze(t)}function Yt(o,e){if(o===void 0)return[0,0,0,1];(!Array.isArray(o)||o.length!==4||o.some(n=>typeof n!="number"||!Number.isFinite(n)))&&ae("invalid-quaternion",e,"expected four finite components");let t=Math.hypot(...o);return t<=1e-12&&ae("invalid-quaternion",e,"quaternion must be non-zero"),[o[0]/t,o[1]/t,o[2]/t,o[3]/t]}function Fo(o,e,t,n=!1){return o===void 0?e:((!Array.isArray(o)||o.length!==3||o.some(r=>typeof r!="number"||!Number.isFinite(r)))&&ae("invalid-vector",t,"expected three finite components"),n&&o.some(r=>r<=0)&&ae("invalid-scale",t,"scale components must be positive"),[o[0],o[1],o[2]])}function Do(o,e){if(o===void 0)return Wt();(!o||typeof o!="object"||Array.isArray(o))&&ae("invalid-joint-transform",e,"expected an object"),Object.keys(o).some(v=>v!=="translation"&&v!=="rotation"&&v!=="scale")&&ae("invalid-joint-transform",e,"unknown transform field");let n=Fo(o.translation,[0,0,0],`${e}.translation`),r=Fo(o.scale,[1,1,1],`${e}.scale`,!0),[a,i,s,d]=Yt(o.rotation,`${e}.rotation`),l=a*a,c=i*i,p=s*s,y=a*i,b=a*s,u=i*s,M=d*a,$=d*i,h=d*s;return[(1-2*(c+p))*r[0],2*(y+h)*r[0],2*(b-$)*r[0],0,2*(y-h)*r[1],(1-2*(l+p))*r[1],2*(u+M)*r[1],0,2*(b+$)*r[2],2*(u-M)*r[2],(1-2*(l+c))*r[2],0,n[0],n[1],n[2],1]}function Gt(o,e){return[o[0]*e[0]+o[4]*e[1]+o[8]*e[2]+o[12],o[1]*e[0]+o[5]*e[1]+o[9]*e[2]+o[13],o[2]*e[0]+o[6]*e[1]+o[10]*e[2]+o[14]]}function Qt(o,e,t){let[n,r,a]=o,i=o[4],s=o[5],d=o[6],l=o[8],c=o[9],p=o[10],y=n*(s*p-c*d)-i*(r*p-c*a)+l*(r*d-s*a);return Math.abs(y)<=1e-12&&ae("invalid-normal-transform",t,"joint skin matrix is singular"),[((s*p-c*d)*e[0]+(c*a-r*p)*e[1]+(r*d-s*a)*e[2])/y,((l*d-i*p)*e[0]+(n*p-l*a)*e[1]+(i*a-n*d)*e[2])/y,((i*c-l*s)*e[0]+(l*r-n*c)*e[1]+(n*s-i*r)*e[2])/y]}function Kt(o){let e=Math.hypot(...o);return e<=1e-12?[0,0,0]:[o[0]/e,o[1]/e,o[2]/e]}function Re(o){for(let e of o)Object.freeze(e);return Object.freeze(o)}function Xt(o,e){return o.every((t,n)=>Math.abs(t-e[n])<=1e-12)}function Ho(o,e){let t=new Map(o.map(a=>[a.id,a])),n=new Map,r=a=>{let i=n.get(a.id);if(i)return i;let s=po(a.restMatrix,Do(e.get(a.id),`$.jointTransforms.${a.id}`)),d=a.parentId===null?s:po(r(t.get(a.parentId)),s);return n.set(a.id,d),d};for(let a of o)r(a);return n}function No(o,e){return new Map(o.map(t=>[t.id,po(e.get(t.id),t.inverseBindMatrix)]))}function Zt(o,e){let t=o??new Map;(!t||typeof t.entries!="function")&&ae("invalid-joint-transform","$.jointTransforms","expected a map");for(let[n,r]of t)e.has(n)||ae("unknown-joint","$.jointTransforms",n),Do(r,`$.jointTransforms.${n}`);return t}function qo(o){let e=D(o);e.deformation.kind!=="joint-skin"&&ae("profile-mismatch","$.profile","skinning requires the joint-skin profile");let t=e.deformation,n=t.joints.map(w=>w.id),r=new Set(n),a=Ho(t.joints,new Map),i=No(t.joints,a),s=Re(e.topology.vertices.map(w=>[...w])),d=Re(e.topology.normals.map(w=>[...w])),l=new Map(e.render.leaves.map(w=>[w.id,lo(e,w)])),c=new Map;for(let w of e.topology.polygons)for(let W of w.vertexIndices){let V=c.get(W)??[];V.push(w.id),c.set(W,V)}let p=new Map(e.render.leaves.map(w=>[w.polygonId,w.id])),y=new Map(t.vertices.map(w=>[w.vertexIndex,w])),b=w=>{let W=[],V=[];for(let B=0;B<s.length;B+=1){let ne=y.get(B),O=[0,0,0],T=[0,0,0];for(let _ of ne.influences){let H=w.get(_.jointId),P=Gt(H,s[B]),C=Qt(H,d[B],`$.skinMatrices.${_.jointId}`);O[0]+=P[0]*_.weight,O[1]+=P[1]*_.weight,O[2]+=P[2]*_.weight,T[0]+=C[0]*_.weight,T[1]+=C[1]*_.weight,T[2]+=C[2]*_.weight}W.push(O),V.push(Kt(T))}return{positions:W,normals:V}},u=b(i),M=Re(u.positions),$=Re(u.normals),h=new Map(i),v=M,I=$,E=_e(e),x=w=>{(!w||!Number.isSafeInteger(w.tick)||w.tick<0)&&ae("invalid-tick","$.tick","expected a non-negative safe integer");let W=Zt(w.jointTransforms,r),V=Ho(t.joints,W),B=No(t.joints,V),ne=new Set(n.filter(m=>!Xt(B.get(m),h.get(m)))),O=v,T=I;if(ne.size>0){let m=b(B);O=Re(m.positions),T=Re(m.normals)}let _=new Set;if(ne.size>0)for(let m of t.vertices)m.influences.some(S=>ne.has(S.jointId))&&_.add(m.vertexIndex);let H=new Set;for(let m of _)for(let S of c.get(m)??[]){let g=p.get(S);g&&H.add(g)}let P=e.render.leaves.map(m=>m.id).filter(m=>H.has(m)),C=P.map(m=>{let S=so(l.get(m),O);return{leafId:m,visible:S.visible,...S.matrix?{matrix:S.matrix}:{}}});return v=O,I=T,h=new Map(B),{tick:w.tick,positions:O,normals:T,globalJointMatrices:V,skinMatrices:B,dirtyLeafIds:Object.freeze(P),leafUpdates:Object.freeze(C),runtimePolygonConstructions:0,runtimeTopologyConstructions:0,atlasRedraws:0}};return Object.freeze({model:e,jointIds:Object.freeze(n),basePositions:Object.freeze(s),baseNormals:Object.freeze(d),sample:x,sampleClip(w,W,V){let B=E.sample(w,W);return x({tick:V,jointTransforms:B.jointTransforms})},reset(){h=new Map(i),v=M,I=$}})}function ue(o,e,t){throw new K(o,e,t)}function en(o,e,t,n,r){let a=n*n-4*t,i=1e-9*Math.max(1,n*n,t);if(Math.abs(a)<=i){let u=n/2,M=e+u*o,$=Math.exp(-u*r);return[$*(o+M*r),$*(e-u*M*r)]}if(a<0){let u=n/2,M=Math.sqrt(t-u*u),$=M*r,h=Math.cos($),v=Math.sin($),I=Math.exp(-u*r);return[I*(o*h+(e+u*o)/M*v),I*(e*h-(u*e+t*o)/M*v)]}let s=Math.sqrt(a),d=(-n+s)/2,l=(-n-s)/2,c=(e-l*o)/(d-l),p=o-c,y=c*Math.exp(d*r),b=p*Math.exp(l*r);return[y+b,d*y+l*b]}function Jo(o){let e=D(o),t=new Map;for(let n of e.springs)t.set(n.controlId,n);return Object.freeze({model:e,controlIds:Object.freeze(e.controls.map(n=>n.id)),controls:new Map(e.controls.map(n=>[n.id,n])),springs:t})}function Wo(o,e){let t=Object.keys(e??{}).find(r=>!o.controls.has(r));t&&ue("unknown-id","$.values",t);let n=Object.fromEntries(o.controlIds.map(r=>{let a=o.controls.get(r),i=e?.[r]??a.initial;return(!Number.isFinite(i)||i<a.minimum||i>a.maximum)&&ue("out-of-range",`$.values.${r}`,"value is outside control bounds"),[r,i]}));return Object.freeze({tick:-1,values:Object.freeze(n),velocities:Object.freeze(Object.fromEntries(o.controlIds.map(r=>[r,0]))),atRest:o.controlIds.every(r=>n[r]===o.controls.get(r).initial)})}function Yo(o,e,t){(!e||!Number.isSafeInteger(e.tick)||e.tick<-1)&&ue("invalid-state","$.state","spring state is invalid"),(!Number.isFinite(t?.deltaMs)||t.deltaMs<=0||t.deltaMs>1e3)&&ue("invalid-time","$.deltaMs","expected 0 < deltaMs <= 1000");let n=t.heldTarget??null;if(n){let l=o.controls.get(n.controlId);l||ue("unknown-id","$.heldTarget.controlId",n.controlId),(!Number.isFinite(n.value)||n.value<l.minimum||n.value>l.maximum)&&ue("out-of-range","$.heldTarget.value","value is outside control bounds")}let r=new Set(t.frozenControlIds??[]);for(let l of r)o.controls.has(l)||ue("unknown-id","$.frozenControlIds",l);let a=t.deltaMs/1e3,i={},s={},d=!0;for(let l of o.controlIds){let c=o.controls.get(l),p=e.values[l]??c.initial,y=e.velocities[l]??0;if(n?.controlId===l)i[l]=n.value,s[l]=0;else if(r.has(l)||!o.springs.has(l))i[l]=p,s[l]=0;else{let b=o.springs.get(l),u=p-c.initial,[M,$]=en(u,y,b.stiffness,b.damping,a),h=$,v=c.initial+M,I=Math.max(c.minimum,Math.min(c.maximum,v));I!==v&&(h=0),v=I,Math.abs(v-c.initial)<1e-6&&Math.abs(h)<1e-6&&(v=c.initial,h=0),i[l]=Object.is(v,-0)?0:v,s[l]=Object.is(h,-0)?0:h}(i[l]!==c.initial||s[l]!==0)&&(d=!1)}return Object.freeze({tick:e.tick+1,values:Object.freeze(i),velocities:Object.freeze(s),atRest:d})}0&&(module.exports={POLY_MORPH_CATALOG_SCHEMA,POLY_MORPH_EXECUTABLE_PROFILES,POLY_MORPH_MODEL_SCHEMA,POLY_MORPH_PACKAGE_SCHEMA,PolyMorphContractError,PolyMorphPackageError,PolyMorphRenderError,PolyMorphRuntimeError,applyPolyMorphPlaybackFrame,assertPolyMorphPackageModelBinding,buildPolyMorphCatalog,buildPolyMorphPackage,createPolyMorphAnimationRuntime,createPolyMorphControlRuntime,createPolyMorphControlState,createPolyMorphDeformationRuntime,createPolyMorphPlaybackRuntime,createPolyMorphPreparedState,createPolyMorphSkinningRuntime,createPolyMorphSpringRuntime,createPolyMorphSpringState,decodePolyMorphJson,diffPolyMorphPreparedStates,encodePolyMorphCanonicalJson,hashPolyMorphBytes,isPolyMorphId,isPolyMorphResourcePath,loadPolyMorphCatalog,loadPolyMorphPackage,mountPolyMorphModel,pickPolyMorphControl,stepPolyMorphControls,stepPolyMorphSprings,stringifyPolyMorphCanonicalJson,validatePolyMorphCatalog,validatePolyMorphModel,validatePolyMorphPackageManifest});
|
|
1
|
+
"use strict";var Xe=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var st=Object.prototype.hasOwnProperty;var lt=(o,e)=>{for(var t in e)Xe(o,t,{get:e[t],enumerable:!0})},dt=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of it(e))!st.call(o,r)&&r!==t&&Xe(o,r,{get:()=>e[r],enumerable:!(n=at(e,r))||n.enumerable});return o};var ct=o=>dt(Xe({},"__esModule",{value:!0}),o);var Mn={};lt(Mn,{POLY_MORPH_CATALOG_SCHEMA:()=>he,POLY_MORPH_EXECUTABLE_PROFILES:()=>Qo,POLY_MORPH_MODEL_SCHEMA:()=>$e,POLY_MORPH_PACKAGE_SCHEMA:()=>ge,PolyMorphContractError:()=>Ae,PolyMorphPackageError:()=>I,PolyMorphRenderError:()=>Me,PolyMorphRuntimeError:()=>X,applyPolyMorphPlaybackFrame:()=>Ye,assertPolyMorphPackageModelBinding:()=>De,buildPolyMorphCatalog:()=>jo,buildPolyMorphPackage:()=>So,createPolyMorphAnimationRuntime:()=>qe,createPolyMorphControlRuntime:()=>qo,createPolyMorphControlState:()=>Ho,createPolyMorphDeformationRuntime:()=>Yo,createPolyMorphPlaybackRuntime:()=>Go,createPolyMorphPreparedDomTarget:()=>Do,createPolyMorphPreparedState:()=>We,createPolyMorphSkinningRuntime:()=>ot,createPolyMorphSpringRuntime:()=>tt,createPolyMorphSpringState:()=>nt,decodePolyMorphJson:()=>ke,diffPolyMorphPreparedStates:()=>Ge,encodePolyMorphCanonicalJson:()=>we,hashPolyMorphBytes:()=>de,isPolyMorphId:()=>Be,isPolyMorphResourcePath:()=>Ne,loadPolyMorphCatalog:()=>io,loadPolyMorphPackage:()=>Ao,mountPolyMorphModel:()=>Uo,pickPolyMorphControl:()=>mo,stepPolyMorphControls:()=>Jo,stepPolyMorphSprings:()=>rt,stringifyPolyMorphCanonicalJson:()=>eo,validatePolyMorphCatalog:()=>Re,validatePolyMorphModel:()=>Y,validatePolyMorphPackageManifest:()=>Ie});module.exports=ct(Mn);var $e="polycss-morph.model@1",he="polycss-morph.catalog@1",ge="polycss-morph.package@1";var bo=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,pt=/^[a-z0-9][a-z0-9._-]*$/,Po=/^\d+\.\d+\.\d+$/,yt=/^[a-f0-9]{64}$/,mt=new Set(["joint-skin","morph-regions","prepared-playback","static-prepared"]),ut=new Set(["animation","joint-skinning","morph-targets","prepared-playback","retained-render","semantic-controls","sparse-updates","springs"]),ft=new Set(["atlas-slice","direct-image","solid-quad","solid-triangle"]),ht=new Set(["control-value","joint-rotation","joint-scale","joint-translation","morph-weight","shape-matrix"]),Ae=class extends TypeError{constructor(e,t,n){super(`${t}: ${n}`),this.name="PolyMorphContractError",this.code=e,this.path=t}};function g(o,e,t){throw new Ae(o,e,t)}function A(o,e,t){(!o||typeof o!="object"||Array.isArray(o))&&g("invalid-type",e,"expected an object");let n=Object.keys(o).sort(),r=[...t].sort();return(n.length!==r.length||n.some((a,i)=>a!==r[i]))&&g("invalid-keys",e,`expected exactly ${r.join(", ")}`),o}function z(o,e){return Array.isArray(o)||g("invalid-type",e,"expected an array"),o}function ne(o,e){return(typeof o!="string"||o.length===0)&&g("invalid-string",e,"expected a non-empty string"),o}function G(o,e){return(typeof o!="number"||!Number.isFinite(o))&&g("invalid-number",e,"expected a finite number"),o}function K(o,e,t=0){let n=G(o,e);return(!Number.isSafeInteger(n)||n<t)&&g("invalid-integer",e,`expected an integer >= ${t}`),n}function Ke(o,e){return typeof o!="boolean"&&g("invalid-boolean",e,"expected a boolean"),o}function W(o,e){let t=ne(o,e);return bo.test(t)||g("invalid-id",e,"expected a normalized kebab-case id"),t}function Q(o,e){let t=new Set;for(let n of o)t.has(n)&&g("duplicate-id",e,`duplicate id ${n}`),t.add(n)}function ve(o,e){let t=z(o,e);return t.length!==3&&g("invalid-vector",e,"expected three components"),t.map((n,r)=>G(n,`${e}[${r}]`))}function ye(o,e){let t=z(o,e);return t.length!==16&&g("invalid-matrix",e,"expected sixteen components"),t.map((n,r)=>G(n,`${e}[${r}]`))}function xo(o,e){let t=ne(o,e);return t.split("/").some(n=>!pt.test(n))&&g("invalid-path",e,"expected lowercase URL-safe package path segments"),t}function Ue(o,e,t){let n=K(o,e);return n>=t&&g("out-of-range",e,`expected an index below ${t}`),n}function gt(o,e){let t=A(o,e,["normals","polygons","vertices"]),n=z(t.vertices,`${e}.vertices`).map((i,s)=>ve(i,`${e}.vertices[${s}]`)),r=z(t.normals,`${e}.normals`).map((i,s)=>ve(i,`${e}.normals[${s}]`));n.length===0&&g("missing-topology",`${e}.vertices`,"expected at least one vertex"),r.length===0&&g("missing-topology",`${e}.normals`,"expected at least one normal");let a=z(t.polygons,`${e}.polygons`).map((i,s)=>{let d=`${e}.polygons[${s}]`,l=A(i,d,["id","normalIndices","vertexIndices"]),c=z(l.vertexIndices,`${d}.vertexIndices`).map((y,P)=>Ue(y,`${d}.vertexIndices[${P}]`,n.length)),p=z(l.normalIndices,`${d}.normalIndices`).map((y,P)=>Ue(y,`${d}.normalIndices[${P}]`,r.length));return c.length<3&&g("invalid-polygon",d,"expected at least three vertices"),p.length!==c.length&&g("invalid-polygon",d,"normal and vertex index counts must match"),new Set(c).size!==c.length&&g("invalid-polygon",d,"vertex indices must be unique"),{id:W(l.id,`${d}.id`),vertexIndices:c,normalIndices:p}});return a.length===0&&g("missing-topology",`${e}.polygons`,"expected at least one polygon"),Q(a.map(i=>i.id),`${e}.polygons`),{vertices:n,normals:r,polygons:a}}function Mt(o,e,t){let n=A(o,e,["atlas","fallback","height","id","materialId","matrix","polygonId","shapeId","strategy","width"]),r=ne(n.strategy,`${e}.strategy`);ft.has(r)||g("invalid-strategy",`${e}.strategy`,"unknown render strategy");let a=W(n.polygonId,`${e}.polygonId`),i=W(n.shapeId,`${e}.shapeId`),s=W(n.materialId,`${e}.materialId`);t.polygonIds.has(a)||g("unknown-reference",`${e}.polygonId`,a),t.shapeIds.has(i)||g("unknown-reference",`${e}.shapeId`,i),t.materialIds.has(s)||g("unknown-reference",`${e}.materialId`,s);let d=G(n.width,`${e}.width`),l=G(n.height,`${e}.height`);(d<=0||l<=0)&&g("invalid-size",e,"leaf dimensions must be positive");let c=r==="atlas-slice"||r==="direct-image",p=n.atlas===null?null:$o(n.atlas,`${e}.atlas`);c!==(p!==null)&&g("invalid-strategy",`${e}.atlas`,c?"image strategies require an atlas/source slice":"solid strategies cannot declare an atlas/source slice");let y=n.fallback===null?null:Pt(n.fallback,`${e}.fallback`);return y!==null&&r!=="solid-triangle"&&g("invalid-strategy",`${e}.fallback`,"only solid-triangle leaves may declare a prepared fallback"),{id:W(n.id,`${e}.id`),polygonId:a,shapeId:i,materialId:s,strategy:r,width:d,height:l,matrix:ye(n.matrix,`${e}.matrix`),atlas:p,fallback:y}}function Pt(o,e){let t=A(o,e,["atlas","height","matrixFromLeaf","width"]),n=K(t.width,`${e}.width`,1),r=K(t.height,`${e}.height`,1),a=$o(t.atlas,`${e}.atlas`);return(a.width!==n||a.height!==r)&&g("invalid-size",e,"fallback dimensions must match its per-polygon atlas slice"),{width:n,height:r,matrixFromLeaf:ye(t.matrixFromLeaf,`${e}.matrixFromLeaf`),atlas:a}}function $o(o,e){let t=A(o,e,["height","pageHeight","pageWidth","resourcePath","width","x","y"]),n={resourcePath:xo(t.resourcePath,`${e}.resourcePath`),x:K(t.x,`${e}.x`),y:K(t.y,`${e}.y`),width:K(t.width,`${e}.width`,1),height:K(t.height,`${e}.height`,1),pageWidth:K(t.pageWidth,`${e}.pageWidth`,1),pageHeight:K(t.pageHeight,`${e}.pageHeight`,1)};return(n.x+n.width>n.pageWidth||n.y+n.height>n.pageHeight)&&g("out-of-range",e,"slice must fit inside its page"),n}function bt(o,e,t){(!o||typeof o!="object"||Array.isArray(o))&&g("invalid-type",e,"expected a deformation object");let n=ne(o.kind,`${e}.kind`);if(n==="none")return A(o,e,["kind"]),{kind:n};if(n==="morph-regions"){let r=A(o,e,["kind","targets"]),a=z(r.targets,`${e}.targets`).map((i,s)=>{let d=`${e}.targets[${s}]`,l=A(i,d,["deltas","id"]),c=z(l.deltas,`${d}.deltas`).map((y,P)=>{let m=`${d}.deltas[${P}]`,f=A(y,m,["normal","position","vertexIndex"]),b=f.position===null?null:ve(f.position,`${m}.position`),h=f.normal===null?null:ve(f.normal,`${m}.normal`);return b===null&&h===null&&g("empty-delta",m,"expected a position or normal delta"),{vertexIndex:Ue(f.vertexIndex,`${m}.vertexIndex`,t.vertices.length),position:b,normal:h}});c.length===0&&g("missing-deltas",`${d}.deltas`,"expected at least one delta");let p=c.map(y=>String(y.vertexIndex));return Q(p,`${d}.deltas`),{id:W(l.id,`${d}.id`),deltas:c}});return a.length===0&&g("missing-targets",`${e}.targets`,"expected at least one target"),Q(a.map(i=>i.id),`${e}.targets`),{kind:n,targets:a}}if(n==="joint-skin"){let r=A(o,e,["joints","kind","vertices"]),a=z(r.joints,`${e}.joints`).map((l,c)=>{let p=`${e}.joints[${c}]`,y=A(l,p,["id","inverseBindMatrix","parentId","restMatrix"]);return{id:W(y.id,`${p}.id`),parentId:y.parentId===null?null:W(y.parentId,`${p}.parentId`),restMatrix:ye(y.restMatrix,`${p}.restMatrix`),inverseBindMatrix:ye(y.inverseBindMatrix,`${p}.inverseBindMatrix`)}});a.length===0&&g("missing-joints",`${e}.joints`,"expected at least one joint"),Q(a.map(l=>l.id),`${e}.joints`),xt(a,`${e}.joints`);let i=new Set(a.map(l=>l.id)),s=z(r.vertices,`${e}.vertices`).map((l,c)=>{let p=`${e}.vertices[${c}]`,y=A(l,p,["influences","vertexIndex"]),P=Ue(y.vertexIndex,`${p}.vertexIndex`,t.vertices.length),m=z(y.influences,`${p}.influences`).map((b,h)=>{let $=`${p}.influences[${h}]`,k=A(b,$,["jointId","weight"]),F=W(k.jointId,`${$}.jointId`);i.has(F)||g("unknown-reference",`${$}.jointId`,F);let v=G(k.weight,`${$}.weight`);return(v<=0||v>1)&&g("invalid-weight",`${$}.weight`,"expected 0 < weight <= 1"),{jointId:F,weight:v}});m.length===0&&g("missing-influences",`${p}.influences`,"expected at least one influence"),Q(m.map(b=>b.jointId),`${p}.influences`);let f=m.reduce((b,h)=>b+h.weight,0);return Math.abs(f-1)>1e-6&&g("invalid-weight",`${p}.influences`,"weights must sum to 1"),{vertexIndex:P,influences:m}});s.length!==t.vertices.length&&g("missing-skin-vertex",`${e}.vertices`,"every topology vertex must have one skin record");let d=s.map(l=>String(l.vertexIndex));return Q(d,`${e}.vertices`),{kind:n,joints:a,vertices:s}}g("invalid-deformation",`${e}.kind`,`unknown deformation kind ${n}`)}function xt(o,e){let t=new Map(o.map(r=>[r.id,r]));o.filter(r=>r.parentId===null).length!==1&&g("invalid-hierarchy",e,"expected exactly one root joint");for(let r of o){r.parentId!==null&&!t.has(r.parentId)&&g("unknown-reference",e,`joint ${r.id} references ${r.parentId}`);let a=new Set,i=r;for(;i;)a.has(i.id)&&g("invalid-hierarchy",e,`cycle at joint ${i.id}`),a.add(i.id),i=i.parentId===null?void 0:t.get(i.parentId)}}function $t(o){return o==="control-value"||o==="morph-weight"?1:o==="joint-rotation"?4:o==="shape-matrix"?16:3}function vt(o,e,t,n){let r=A(o,e,["interpolation","target","targetId","timesMs","values"]),a=ne(r.target,`${e}.target`);ht.has(a)||g("invalid-animation-target",`${e}.target`,a);let i=W(r.targetId,`${e}.targetId`);(a==="control-value"?t.controlIds:a==="morph-weight"?t.targetIds:a==="shape-matrix"?t.shapeIds:t.jointIds).has(i)||g("unknown-reference",`${e}.targetId`,i);let d=ne(r.interpolation,`${e}.interpolation`);d!=="linear"&&d!=="step"&&g("invalid-interpolation",`${e}.interpolation`,d),a==="shape-matrix"&&d!=="step"&&g("invalid-interpolation",`${e}.interpolation`,"shape matrices require step interpolation");let l=z(r.timesMs,`${e}.timesMs`).map((p,y)=>G(p,`${e}.timesMs[${y}]`)),c=z(r.values,`${e}.values`).map((p,y)=>{let P=z(p,`${e}.values[${y}]`),m=$t(a);P.length!==m&&g("invalid-animation-value",`${e}.values[${y}]`,`expected ${m} components`);let f=P.map((b,h)=>G(b,`${e}.values[${y}][${h}]`));return a==="joint-rotation"&&Math.hypot(...f)<=1e-12&&g("invalid-animation-value",`${e}.values[${y}]`,"quaternion must be non-zero"),f});return(l.length===0||l.length!==c.length)&&g("invalid-animation-samples",e,"times and values must have the same non-zero length"),(l[0]!==0||l.some((p,y)=>p<0||p>n||y>0&&p<=l[y-1]))&&g("invalid-animation-time",`${e}.timesMs`,"times must start at zero and increase within the clip"),{target:a,targetId:i,interpolation:d,timesMs:l,values:c}}function wt(o,e,t,n){let r=A(o,e,["durationMs","frames","loop"]),a=G(r.durationMs,`${e}.durationMs`);a<=0&&g("invalid-duration",`${e}.durationMs`,"expected a positive duration");let i=z(r.frames,`${e}.frames`).map((s,d)=>{let l=`${e}.frames[${d}]`,c=A(s,l,["leaves","modelMatrix","shapes","timeMs"]),p=G(c.timeMs,`${l}.timeMs`),y=z(c.shapes,`${l}.shapes`).map((m,f)=>{let b=`${l}.shapes[${f}]`,h=A(m,b,["matrix","shapeId"]),$=W(h.shapeId,`${b}.shapeId`);return n.has($)||g("unknown-reference",`${b}.shapeId`,$),{shapeId:$,matrix:ye(h.matrix,`${b}.matrix`)}});Q(y.map(m=>m.shapeId),`${l}.shapes`);let P=z(c.leaves,`${l}.leaves`).map((m,f)=>{let b=`${l}.leaves[${f}]`,h=A(m,b,["atlasRow","leafId","matrix","opacity","visible"]),$=W(h.leafId,`${b}.leafId`);t.has($)||g("unknown-reference",`${b}.leafId`,$);let k=h.opacity===null?null:G(h.opacity,`${b}.opacity`);return k!==null&&(k<0||k>1)&&g("out-of-range",`${b}.opacity`,"expected 0 <= opacity <= 1"),{leafId:$,matrix:h.matrix===null?null:ye(h.matrix,`${b}.matrix`),visible:h.visible===null?null:Ke(h.visible,`${b}.visible`),opacity:k,atlasRow:h.atlasRow===null?null:K(h.atlasRow,`${b}.atlasRow`)}});return Q(P.map(m=>m.leafId),`${l}.leaves`),{timeMs:p,modelMatrix:c.modelMatrix===null?null:ye(c.modelMatrix,`${l}.modelMatrix`),shapes:y,leaves:P}});return i.length===0&&g("missing-frames",`${e}.frames`,"expected at least one frame"),(i[0].timeMs!==0||i.some((s,d)=>s.timeMs<0||s.timeMs>a||d>0&&s.timeMs<=i[d-1].timeMs))&&g("invalid-frame-time",`${e}.frames`,"frames must start at zero and increase within the timeline"),{durationMs:a,loop:Ke(r.loop,`${e}.loop`),frames:i}}function kt(o,e){let t=["retained-render"];return o==="morph-regions"&&t.push("morph-targets","sparse-updates"),o==="joint-skin"&&t.push("joint-skinning","sparse-updates"),o==="prepared-playback"&&t.push("prepared-playback","sparse-updates"),e.controls.length>0&&t.push("semantic-controls"),e.springs.length>0&&t.push("springs"),e.animations.length>0&&t.push("animation"),t}function Y(o){let t=A(o,"$",["animations","budgets","capabilities","controls","deformation","identity","materials","playback","profile","provenance","render","schema","springs","topology"]);t.schema!==$e&&g("invalid-schema","$.schema",`expected ${$e}`);let n=A(t.identity,"$.identity",["id","name","revision"]),r={id:W(n.id,"$.identity.id"),name:ne(n.name,"$.identity.name"),revision:ne(n.revision,"$.identity.revision")};Po.test(r.revision)||g("invalid-revision","$.identity.revision","expected x.y.z");let a=ne(t.profile,"$.profile");mt.has(a)||g("invalid-profile","$.profile",a);let i=z(t.capabilities,"$.capabilities").map((M,S)=>{let u=ne(M,`$.capabilities[${S}]`);return ut.has(u)||g("invalid-capability",`$.capabilities[${S}]`,u),u});Q(i,"$.capabilities"),i.some((M,S)=>S>0&&M<=i[S-1])&&g("non-canonical-order","$.capabilities","capabilities must be sorted");let s=A(t.budgets,"$.budgets",["maxBytes","maxFrames","maxJoints","maxLeaves","maxPolygons","maxResources","maxVertices"]),d={maxVertices:K(s.maxVertices,"$.budgets.maxVertices"),maxPolygons:K(s.maxPolygons,"$.budgets.maxPolygons"),maxLeaves:K(s.maxLeaves,"$.budgets.maxLeaves"),maxFrames:K(s.maxFrames,"$.budgets.maxFrames"),maxJoints:K(s.maxJoints,"$.budgets.maxJoints"),maxResources:K(s.maxResources,"$.budgets.maxResources"),maxBytes:K(s.maxBytes,"$.budgets.maxBytes")},l=gt(t.topology,"$.topology"),c=z(t.materials,"$.materials").map((M,S)=>{let u=`$.materials[${S}]`,R=A(M,u,["color","id"]),j=z(R.color,`${u}.color`);j.length!==4&&g("invalid-color",`${u}.color`,"expected four components");let D=j.map((x,C)=>{let H=G(x,`${u}.color[${C}]`);return(H<0||H>1)&&g("out-of-range",`${u}.color[${C}]`,"expected 0 <= component <= 1"),H});return{id:W(R.id,`${u}.id`),color:D}});c.length===0&&g("missing-materials","$.materials","expected at least one material"),Q(c.map(M=>M.id),"$.materials");let p=A(t.render,"$.render",["leaves","modelMatrix","shapes"]),y=z(p.shapes,"$.render.shapes").map((M,S)=>{let u=`$.render.shapes[${S}]`,R=A(M,u,["id","matrix"]);return{id:W(R.id,`${u}.id`),matrix:ye(R.matrix,`${u}.matrix`)}});y.length===0&&g("missing-shapes","$.render.shapes","expected at least one shape"),Q(y.map(M=>M.id),"$.render.shapes");let P=z(p.leaves,"$.render.leaves").map((M,S)=>Mt(M,`$.render.leaves[${S}]`,{polygonIds:new Set(l.polygons.map(u=>u.id)),shapeIds:new Set(y.map(u=>u.id)),materialIds:new Set(c.map(u=>u.id))}));Q(P.map(M=>M.id),"$.render.leaves"),Q(P.map(M=>M.polygonId),"$.render.leaves[*].polygonId"),P.length!==l.polygons.length&&g("unstable-topology","$.render.leaves","every polygon must bind exactly one retained leaf");let m={modelMatrix:ye(p.modelMatrix,"$.render.modelMatrix"),shapes:y,leaves:P},f=bt(t.deformation,"$.deformation",l);(a==="static-prepared"||a==="prepared-playback"?f.kind!=="none":f.kind!==a)&&g("profile-mismatch","$.deformation.kind",`does not match profile ${a}`);let b=new Set(f.kind==="morph-regions"?f.targets.map(M=>M.id):[]),h=new Set(f.kind==="joint-skin"?f.joints.map(M=>M.id):[]),$=z(t.controls,"$.controls").map((M,S)=>{let u=`$.controls[${S}]`,R=A(M,u,["anchor","axis","id","initial","maximum","minimum","radius","targets"]),j=G(R.minimum,`${u}.minimum`),D=G(R.maximum,`${u}.maximum`),x=G(R.initial,`${u}.initial`);(j>D||x<j||x>D)&&g("invalid-control-bounds",u,"expected minimum <= initial <= maximum");let C=ve(R.anchor,`${u}.anchor`),H=ve(R.axis,`${u}.axis`);Math.hypot(...H)<1e-9&&g("invalid-control-axis",`${u}.axis`,"axis must be non-zero");let ue=G(R.radius,`${u}.radius`);ue<=0&&g("invalid-control-radius",`${u}.radius`,"radius must be positive");let pe=z(R.targets,`${u}.targets`).map((Pe,Oe)=>{let fe=`${u}.targets[${Oe}]`,xe=A(Pe,fe,["scale","targetId"]),T=W(xe.targetId,`${fe}.targetId`);return b.has(T)||g("unknown-reference",`${fe}.targetId`,T),{targetId:T,scale:G(xe.scale,`${fe}.scale`)}});return Q(pe.map(Pe=>Pe.targetId),`${u}.targets`),{id:W(R.id,`${u}.id`),anchor:C,axis:H,radius:ue,minimum:j,maximum:D,initial:x,targets:pe}});Q($.map(M=>M.id),"$.controls");let k=new Set($.map(M=>M.id)),F=z(t.springs,"$.springs").map((M,S)=>{let u=`$.springs[${S}]`,R=A(M,u,["controlId","damping","id","stiffness"]),j=W(R.controlId,`${u}.controlId`);k.has(j)||g("unknown-reference",`${u}.controlId`,j);let D=G(R.stiffness,`${u}.stiffness`),x=G(R.damping,`${u}.damping`);return(D<=0||x<0)&&g("invalid-spring",u,"expected stiffness > 0 and damping >= 0"),{id:W(R.id,`${u}.id`),controlId:j,stiffness:D,damping:x}});Q(F.map(M=>M.id),"$.springs");let v=new Set(y.map(M=>M.id)),w=z(t.animations,"$.animations").map((M,S)=>{let u=`$.animations[${S}]`,R=A(M,u,["channels","durationMs","id","loop"]),j=G(R.durationMs,`${u}.durationMs`);j<=0&&g("invalid-duration",`${u}.durationMs`,"expected a positive duration");let D=z(R.channels,`${u}.channels`).map((C,H)=>vt(C,`${u}.channels[${H}]`,{controlIds:k,jointIds:h,shapeIds:v,targetIds:b},j));D.length===0&&g("missing-channels",`${u}.channels`,"expected at least one channel");let x=D.map(C=>`${C.target}:${C.targetId}`);return Q(x,`${u}.channels`),{id:W(R.id,`${u}.id`),durationMs:j,loop:Ke(R.loop,`${u}.loop`),channels:D}});Q(w.map(M=>M.id),"$.animations");let L=t.playback===null?null:wt(t.playback,"$.playback",new Set(P.map(M=>M.id)),v);a==="prepared-playback"!=(L!==null)&&g("profile-mismatch","$.playback","playback is required only by the prepared-playback profile");let E=A(t.provenance,"$.provenance",["generator","generatorVersion","sources"]),B=z(E.sources,"$.provenance.sources").map((M,S)=>{let u=`$.provenance.sources[${S}]`,R=A(M,u,["id","kind","license","sha256","uri"]),j=ne(R.kind,`${u}.kind`);j!=="authored"&&j!=="generated"&&j!=="open-data"&&g("invalid-source-kind",`${u}.kind`,j);let D=ne(R.uri,`${u}.uri`);(D.startsWith("/")||D.startsWith("file:")||D.includes("\\"))&&g("invalid-source-uri",`${u}.uri`,"local filesystem paths are forbidden");let x=R.sha256===null?null:ne(R.sha256,`${u}.sha256`);return x!==null&&!yt.test(x)&&g("invalid-hash",`${u}.sha256`,"expected lowercase SHA-256"),{id:W(R.id,`${u}.id`),kind:j,uri:D,sha256:x,license:ne(R.license,`${u}.license`)}});B.length===0&&g("missing-provenance","$.provenance.sources","expected at least one source"),Q(B.map(M=>M.id),"$.provenance.sources");let q={generator:W(E.generator,"$.provenance.generator"),generatorVersion:ne(E.generatorVersion,"$.provenance.generatorVersion"),sources:B};Po.test(q.generatorVersion)||g("invalid-revision","$.provenance.generatorVersion","expected x.y.z");let O=kt(a,{controls:$,springs:F,animations:w});for(let M of O)i.includes(M)||g("missing-capability","$.capabilities",`profile requires ${M}`);let V=f.kind==="joint-skin"?f.joints.length:0,N=L?.frames.length??0,_=[["maxVertices",l.vertices.length,d.maxVertices],["maxPolygons",l.polygons.length,d.maxPolygons],["maxLeaves",P.length,d.maxLeaves],["maxFrames",N,d.maxFrames],["maxJoints",V,d.maxJoints]];for(let[M,S,u]of _)S>u&&g("budget-exceeded",`$.budgets.${M}`,`${S} exceeds ${u}`);return{schema:$e,identity:r,profile:a,capabilities:i,budgets:d,topology:l,materials:c,render:m,deformation:f,controls:$,springs:F,animations:w,playback:L,provenance:q}}function Be(o){return bo.test(o)}function Ne(o){try{return xo(o,"$"),!0}catch{return!1}}var I=class extends Error{constructor(e,t,n,r={}){super(`${t}: ${n}`),this.name="PolyMorphPackageError",this.code=e,this.path=t,"cause"in r&&(this.cause=r.cause)}};function Ze(o,e,t){if(o===null)return"null";if(typeof o=="string"||typeof o=="boolean")return JSON.stringify(o);if(typeof o=="number"){if(!Number.isFinite(o))throw new I("invalid-json",e,"numbers must be finite");return JSON.stringify(Object.is(o,-0)?0:o)}if(Array.isArray(o)){if(t.has(o))throw new I("invalid-json",e,"cycles are forbidden");t.add(o);let n=`[${o.map((r,a)=>Ze(r,`${e}[${a}]`,t)).join(",")}]`;return t.delete(o),n}if(typeof o=="object"&&o){if(t.has(o))throw new I("invalid-json",e,"cycles are forbidden");let n=Object.getPrototypeOf(o);if(n!==Object.prototype&&n!==null)throw new I("invalid-json",e,"expected a plain object");t.add(o);let r=o,a=`{${Object.keys(r).sort().map(i=>{let s=r[i];if(s===void 0||typeof s=="function"||typeof s=="symbol")throw new I("invalid-json",`${e}.${i}`,"value is not JSON");return`${JSON.stringify(i)}:${Ze(s,`${e}.${i}`,t)}`}).join(",")}}`;return t.delete(o),a}throw new I("invalid-json",e,"value is not JSON")}function eo(o){return Ze(o,"$",new WeakSet)}function we(o){return new TextEncoder().encode(eo(o))}function ke(o,e="$"){let t;try{t=new TextDecoder("utf-8",{fatal:!0}).decode(o)}catch{throw new I("invalid-utf8",e,"expected UTF-8 bytes")}try{return JSON.parse(t)}catch{throw new I("invalid-json",e,"expected valid JSON")}}async function de(o){if(!globalThis.crypto?.subtle)throw new I("missing-crypto","$","Web Crypto is required");let e=Uint8Array.from(o),t=await globalThis.crypto.subtle.digest("SHA-256",e);return[...new Uint8Array(t)].map(n=>n.toString(16).padStart(2,"0")).join("")}var It=/^[a-f0-9]{64}$/,Rt=/^\d+\.\d+\.\d+$/,St=/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/,jt=new Set(["joint-skin","morph-regions","prepared-playback","static-prepared"]),Ct=new Set(["data","image","model"]);function J(o,e,t){throw new I(o,e,t)}function ze(o,e,t){(!o||typeof o!="object"||Array.isArray(o))&&J("invalid-type",e,"expected an object");let n=Object.keys(o).sort(),r=[...t].sort();return(n.length!==r.length||n.some((a,i)=>a!==r[i]))&&J("invalid-keys",e,`expected exactly ${r.join(", ")}`),o}function vo(o,e){return Array.isArray(o)||J("invalid-type",e,"expected an array"),o}function me(o,e){return(typeof o!="string"||o.length===0)&&J("invalid-string",e,"expected a non-empty string"),o}function to(o,e){let t=me(o,e);return Be(t)||J("invalid-id",e,"expected a normalized kebab-case id"),t}function no(o,e){let t=me(o,e);return Ne(t)||J("invalid-path",e,"expected a normalized package-relative path"),t}function wo(o,e){let t=me(o,e);return Rt.test(t)||J("invalid-revision",e,"expected x.y.z"),t}function ko(o,e){let t=me(o,e);return jt.has(t)||J("invalid-profile",e,t),t}function Io(o,e){let t=me(o,e);return It.test(t)||J("invalid-hash",e,"expected lowercase SHA-256"),t}function Tt(o,e){return(typeof o!="number"||!Number.isSafeInteger(o)||o<0)&&J("invalid-bytes",e,"expected a non-negative safe integer"),o}function Ot(o,e){let t=ze(o,e,["bytes","mediaType","path","role","sha256"]),n=me(t.role,`${e}.role`);Ct.has(n)||J("invalid-role",`${e}.role`,n);let r=me(t.mediaType,`${e}.mediaType`).toLowerCase();return(!St.test(r)||r!==t.mediaType)&&J("invalid-media-type",`${e}.mediaType`,"expected a normalized type/subtype"),n==="image"&&!r.startsWith("image/")&&J("invalid-media-type",`${e}.mediaType`,"image resources require an image media type"),{path:no(t.path,`${e}.path`),role:n,mediaType:r,bytes:Tt(t.bytes,`${e}.bytes`),sha256:Io(t.sha256,`${e}.sha256`)}}function oo(o,e){let t=new Set;for(let n of o)t.has(n)&&J("duplicate",e,n),t.add(n)}function Ro(o,e){o.some((t,n)=>n>0&&t<=o[n-1])&&J("non-canonical-order",e,"entries must be unique and sorted")}function Ie(o){let e=ze(o,"$",["identity","modelPath","profile","resources","schema"]);e.schema!==ge&&J("invalid-schema","$.schema",`expected ${ge}`);let t=ze(e.identity,"$.identity",["id","name","revision"]),n={id:to(t.id,"$.identity.id"),name:me(t.name,"$.identity.name"),revision:wo(t.revision,"$.identity.revision")},r=vo(e.resources,"$.resources").map((d,l)=>Ot(d,`$.resources[${l}]`));r.length===0&&J("missing-resource","$.resources","expected at least the model resource");let a=r.map(d=>d.path);oo(a,"$.resources"),Ro(a,"$.resources");let i=no(e.modelPath,"$.modelPath"),s=r.filter(d=>d.role==="model");return(s.length!==1||s[0].path!==i)&&J("invalid-model-resource","$.resources","expected exactly one model resource matching modelPath"),s[0].mediaType!=="application/json"&&J("invalid-model-resource","$.resources","model resource must be application/json"),{schema:ge,identity:n,profile:ko(e.profile,"$.profile"),modelPath:i,resources:r}}function Lt(o,e){let t=ze(o,e,["id","manifestPath","manifestSha256","name","profile","revision"]),n=no(t.manifestPath,`${e}.manifestPath`);return n.endsWith("/manifest.json")||J("invalid-manifest-path",`${e}.manifestPath`,"expected a package manifest.json path"),{id:to(t.id,`${e}.id`),name:me(t.name,`${e}.name`),revision:wo(t.revision,`${e}.revision`),profile:ko(t.profile,`${e}.profile`),manifestPath:n,manifestSha256:Io(t.manifestSha256,`${e}.manifestSha256`)}}function Re(o){let e=ze(o,"$",["defaultId","packages","schema"]);e.schema!==he&&J("invalid-schema","$.schema",`expected ${he}`);let t=vo(e.packages,"$.packages").map((a,i)=>Lt(a,`$.packages[${i}]`));t.length===0&&J("missing-package","$.packages","expected at least one package");let n=t.map(a=>a.id);oo(n,"$.packages"),Ro(n,"$.packages"),oo(t.map(a=>a.manifestPath),"$.packages[*].manifestPath");let r=to(e.defaultId,"$.defaultId");return n.includes(r)||J("unknown-default","$.defaultId",r),{schema:he,defaultId:r,packages:t}}var ro="model.json";function At(o){return[...new Set(o.render.leaves.flatMap(e=>[...e.atlas?[e.atlas.resourcePath]:[],...e.fallback?[e.fallback.atlas.resourcePath]:[]]))].sort()}async function So(o,e=[]){let t=Y(o),n=we(t),r=new Map([[ro,n]]),a=[{path:ro,role:"model",mediaType:"application/json",bytes:n.byteLength,sha256:await de(n)}];for(let l of e){if(r.has(l.path))throw new I("duplicate",l.path,"resource path is already present");let c=Uint8Array.from(l.bytes);r.set(l.path,c),a.push({path:l.path,role:l.role,mediaType:l.mediaType,bytes:c.byteLength,sha256:await de(c)})}for(let l of At(t)){let c=a.find(p=>p.path===l);if(!c)throw new I("missing-resource",l,"model image is not included in the package");if(c.role!=="image")throw new I("invalid-role",l,"model image resource must use the image role")}a.sort((l,c)=>l.path<c.path?-1:l.path>c.path?1:0);let i=Ie({schema:ge,identity:t.identity,profile:t.profile,modelPath:ro,resources:a}),s=a.reduce((l,c)=>l+c.bytes,0);if(a.length>t.budgets.maxResources)throw new I("budget-exceeded","$.budgets.maxResources",`${a.length} resources exceed ${t.budgets.maxResources}`);if(s>t.budgets.maxBytes)throw new I("budget-exceeded","$.budgets.maxBytes",`${s} bytes exceed ${t.budgets.maxBytes}`);let d=we(i);return{manifest:i,manifestBytes:d,manifestSha256:await de(d),files:r}}async function jo(o,e){let t=e.map(a=>({id:a.manifest.identity.id,name:a.manifest.identity.name,revision:a.manifest.identity.revision,profile:a.manifest.profile,manifestPath:a.manifestPath,manifestSha256:a.manifestSha256}));t.sort((a,i)=>a.id<i.id?-1:a.id>i.id?1:0);let n=Re({schema:he,defaultId:o,packages:t}),r=we(n);return{catalog:n,bytes:r,sha256:await de(r)}}function De(o,e){if(e.identity.id!==o.identity.id||e.identity.name!==o.identity.name||e.identity.revision!==o.identity.revision||e.profile!==o.profile)throw new I("profile-mismatch","$.model","model identity or profile does not match its manifest")}var To=64*1024*1024,zt=1024,Vt=128*1024*1024,Oo=3e4;function Se(o,e,t){let n=o??e;if(!Number.isSafeInteger(n)||n<=0)throw new I("invalid-limit",t,"expected a positive safe integer");return n}function Lo(o){if(typeof o!="string"||o.length===0||o.includes("\\")||o.includes("#")||o.includes("?"))throw new I("invalid-base-url","$.baseUrl","expected a clean HTTP(S) base URL");let e;try{e=new URL(o,globalThis.location?.href??"https://polycss.invalid/")}catch{throw new I("invalid-base-url","$.baseUrl","expected a valid URL")}if(e.protocol!=="http:"&&e.protocol!=="https:")throw new I("invalid-base-url","$.baseUrl","expected HTTP or HTTPS");return e.pathname.endsWith("/")||(e.pathname+="/"),e}async function Et(o,e,t){let n=o.headers.get("content-length");if(n!==null){let a=Number(n);if(!Number.isSafeInteger(a)||a<0||a>t)throw new I("resource-too-large",e,`declared bytes exceed ${t}`)}if(o.body?.getReader){let a=o.body.getReader(),i=[],s=0;for(;;){let c=await a.read();if(c.done)break;if(s+=c.value.byteLength,s>t)throw await a.cancel(),new I("resource-too-large",e,`bytes exceed ${t}`);i.push(c.value)}let d=new Uint8Array(s),l=0;for(let c of i)d.set(c,l),l+=c.byteLength;return d}if(n===null)throw new I("resource-too-large",e,"content-length is required without a readable body");let r=new Uint8Array(await o.arrayBuffer());if(r.byteLength>t)throw new I("resource-too-large",e,`bytes exceed ${t}`);return r}async function ao(o,e,t,n,r){let a=n??AbortSignal.timeout(r),i;try{i=await o(e,{cache:"no-store",signal:a})}catch(s){throw a.aborted?s:new I("request-failed",e.pathname,"request failed",{cause:s})}if(!i.ok)throw new I("request-failed",e.pathname,`HTTP ${i.status}`);return Et(i,e.pathname,t)}async function Co(o,e,t){let n=await de(o);if(n!==e)throw new I("stale-hash",t,`expected ${e}, received ${n}`)}function Ut(o,e){let t=e.lastIndexOf("/");return Fe(o,e.slice(0,t+1))}function Fe(o,e){let t=new URL(e,o);if(t.origin!==o.origin||!t.href.startsWith(o.href))throw new I("invalid-path",e,"package path escapes its base URL");return t}async function io(o,e={}){let t=Lo(o),n=Se(e.maxResourceBytes,To,"$.maxResourceBytes"),r=e.fetchImpl??globalThis.fetch;if(typeof r!="function")throw new I("missing-fetch","$.fetchImpl","a fetch implementation is required");let a=Se(e.requestTimeoutMs,Oo,"$.requestTimeoutMs"),i=await ao(r,Fe(t,"catalog.json"),n,e.signal,a);return{catalog:Re(ke(i,"$.catalog")),bytes:i,sha256:await de(i)}}async function Ao(o,e={}){let t=Lo(o),n=Se(e.maxResourceBytes,To,"$.maxResourceBytes"),r=Se(e.maxResources,zt,"$.maxResources"),a=Se(e.maxTotalBytes,Vt,"$.maxTotalBytes"),i=Se(e.requestTimeoutMs,Oo,"$.requestTimeoutMs"),s=e.fetchImpl??globalThis.fetch;if(typeof s!="function")throw new I("missing-fetch","$.fetchImpl","a fetch implementation is required");let d=await io(t.href,{fetchImpl:s,maxResourceBytes:n,requestTimeoutMs:i,signal:e.signal}),l=e.modelId??d.catalog.defaultId,c=d.catalog.packages.find(v=>v.id===l);if(!c)throw new I("unknown-package","$.modelId",l);let p=await ao(s,Fe(t,c.manifestPath),n,e.signal,i);await Co(p,c.manifestSha256,c.manifestPath);let y=Ie(ke(p,"$.manifest"));if(y.identity.id!==c.id||y.identity.name!==c.name||y.identity.revision!==c.revision||y.profile!==c.profile)throw new I("profile-mismatch","$.manifest","catalog row does not match its manifest");let P=Ut(t,c.manifestPath);if(y.resources.length>r)throw new I("package-too-large","$.manifest.resources",`${y.resources.length} resources exceed ${r}`);let m=0;for(let v of y.resources){if(v.bytes>n)throw new I("resource-too-large",v.path,`declared bytes exceed ${n}`);if(m+=v.bytes,m>a)throw new I("package-too-large",v.path,`declared package bytes exceed ${a}`)}let f=new Map,b=async v=>{let w=await ao(s,Fe(P,v.path),Math.min(n,v.bytes),e.signal,i);if(w.byteLength!==v.bytes)throw new I("stale-size",v.path,`expected ${v.bytes}, received ${w.byteLength}`);return await Co(w,v.sha256,v.path),{descriptor:v,bytes:w}},h=y.resources.find(v=>v.path===y.modelPath),$=await b(h);f.set(h.path,$);let k=Y(ke($.bytes,"$.model"));if(De(y,k),y.resources.length>k.budgets.maxResources)throw new I("budget-exceeded","$.budgets.maxResources",`${y.resources.length} resources exceed ${k.budgets.maxResources}`);if(m>k.budgets.maxBytes)throw new I("budget-exceeded","$.budgets.maxBytes",`${m} bytes exceed ${k.budgets.maxBytes}`);for(let v of y.resources)v!==h&&f.set(v.path,await b(v));let F=new Set(k.render.leaves.flatMap(v=>[...v.atlas?[v.atlas.resourcePath]:[],...v.fallback?[v.fallback.atlas.resourcePath]:[]]));for(let v of F){let w=f.get(v);if(!w)throw new I("missing-resource",v,"model image is not declared by the package");if(w.descriptor.role!=="image")throw new I("invalid-role",v,"model image resource must use the image role")}return{catalog:d.catalog,catalogSha256:d.sha256,catalogRow:c,manifest:y,manifestSha256:c.manifestSha256,model:k,resources:f}}var ee=require("@layoutit/polycss");var Me=class extends Error{constructor(e,t,n){super(`${t}: ${n}`),this.name="PolyMorphRenderError",this.code=e,this.path=t}};var Bt={"atlas-slice":"s","direct-image":"s","solid-quad":"b","solid-triangle":"u"},zo=1e-12;function U(o,e,t){throw new Me(o,e,t)}function lo(o,e){return(!Array.isArray(o)||o.length!==16||o.some(t=>typeof t!="number"||!Number.isFinite(t)))&&U("invalid-matrix",e,"expected sixteen finite components"),o}function Nt(o){return o.map(e=>String(Object.is(e,-0)?0:e)).join(",")}function je(o,e=!1){return`matrix3d(${e?Nt(o):(0,ee.formatMatrix3dValues)(o)})`}function Dt(o,e){return e&&o.fallback?[o.fallback.width,o.fallback.height]:[o.width,o.height]}function Ft(o,e,t){let[n,r]=Dt(e,t);return Math.abs(o[3]*n)>zo||Math.abs(o[7]*r)>zo}function _t(o,e){let t=new Array(16).fill(0);for(let n=0;n<4;n+=1)for(let r=0;r<4;r+=1){let a=0;for(let i=0;i<4;i+=1)a+=o[i*4+r]*e[n*4+i];t[n*4+r]=Object.is(a,-0)?0:a}return t}function qt(o,e,t){return t&&o.fallback?_t(e,o.fallback.matrixFromLeaf):e}function so(o,e,t){let n=qt(o,e,t);return n.some(r=>!Number.isFinite(r))&&U("invalid-matrix",`${o.id}.matrix`,"resolved leaf matrix must remain finite"),{matrix:n,projective:Ft(n,o,t)}}function Eo(o,e,t){let n=so(o,e,t);return je(n.matrix,n.projective)}function Ht(o){let[e,t,n,r]=o;return`rgba(${Math.round(e*255)}, ${Math.round(t*255)}, ${Math.round(n*255)}, ${r})`}function co(o,e,t,n=[]){(!o||typeof o!="object"||Array.isArray(o))&&U("invalid-update",e,"expected an object");let r=new Set([...t,...n]),a=Object.keys(o);return(t.some(i=>!a.includes(i))||a.some(i=>!r.has(i)))&&U("invalid-update",e,`allowed keys are ${[...r].sort().join(", ")}`),o}function Vo(o,e){let t=new Set;for(let n of o)t.has(n)&&U("duplicate-update",e,n),t.add(n)}function Jt(o,e){let t=co(o,e,["matrix","shapeId"]);return typeof t.shapeId!="string"&&U("invalid-update",`${e}.shapeId`,"expected a string"),{shapeId:t.shapeId,matrix:lo(t.matrix,`${e}.matrix`)}}function Wt(o,e){let t=co(o,e,["leafId"],["atlasRow","matrix","opacity","visible"]);typeof t.leafId!="string"&&U("invalid-update",`${e}.leafId`,"expected a string");let n={leafId:t.leafId};return t.matrix!==void 0&&(n.matrix=lo(t.matrix,`${e}.matrix`)),t.visible!==void 0&&(typeof t.visible!="boolean"&&U("invalid-update",`${e}.visible`,"expected a boolean"),n.visible=t.visible),t.opacity!==void 0&&((typeof t.opacity!="number"||!Number.isFinite(t.opacity)||t.opacity<0||t.opacity>1)&&U("invalid-update",`${e}.opacity`,"expected 0 <= opacity <= 1"),n.opacity=t.opacity),t.atlasRow!==void 0&&((!Number.isSafeInteger(t.atlasRow)||t.atlasRow<0)&&U("invalid-update",`${e}.atlasRow`,"expected a non-negative integer"),n.atlasRow=t.atlasRow),n}function Yt(o){let e=co(o,"$",[],["leaves","modelMatrix","shapes"]),t=e.shapes===void 0?void 0:(()=>{Array.isArray(e.shapes)||U("invalid-update","$.shapes","expected an array");let r=e.shapes.map((a,i)=>Jt(a,`$.shapes[${i}]`));return Vo(r.map(a=>a.shapeId),"$.shapes"),r})(),n=e.leaves===void 0?void 0:(()=>{Array.isArray(e.leaves)||U("invalid-update","$.leaves","expected an array");let r=e.leaves.map((a,i)=>Wt(a,`$.leaves[${i}]`));return Vo(r.map(a=>a.leafId),"$.leaves"),r})();return{...e.modelMatrix===void 0?{}:{modelMatrix:lo(e.modelMatrix,"$.modelMatrix")},...t===void 0?{}:{shapes:t},...n===void 0?{}:{leaves:n}}}function Gt(o,e,t,n){o.style.setProperty("--polycss-atlas-width",`${e.width}px`),o.style.setProperty("--polycss-atlas-height",`${e.height}px`),o.style.backgroundImage=`url("${n.replace(/"/gu,"%22")}")`,o.style.backgroundPosition=`${-t.x}px ${-t.y}px`,o.style.backgroundSize=`${t.pageWidth}px ${t.pageHeight}px`}function Qt(o,e,t,n,r){let a=`url("${r.replace(/"/gu,"%22")}")`,i=`${-e.x}px ${-e.y}px`,s=`${e.pageWidth}px ${e.pageHeight}px`;o.style.width=`${t}px`,o.style.height=`${n}px`,o.style.backgroundColor="currentColor",o.style.setProperty("mask-image",a),o.style.setProperty("mask-mode","alpha"),o.style.setProperty("mask-position",i),o.style.setProperty("mask-repeat","no-repeat"),o.style.setProperty("mask-size",s),o.style.setProperty("-webkit-mask-image",a),o.style.setProperty("-webkit-mask-position",i),o.style.setProperty("-webkit-mask-repeat","no-repeat"),o.style.setProperty("-webkit-mask-size",s)}function Xt(o,e,t,n,r){let a=r?e.fallback:null,i=o.createElement(a?"s":Bt[e.strategy]);return i.className="polycss-morph-leaf",i.dataset.polyMorphLeaf=e.id,i.dataset.polyMorphStrategy=e.strategy,i.dataset.polyMorphResolvedStrategy=a?"atlas-slice":e.strategy,i.style.transform=Eo(e,e.matrix,a!==null),i.style.color=Ht(t),i.style.backfaceVisibility="visible",i.style.backgroundRepeat="no-repeat",i.style.opacity="1",i.style.transformOrigin="0 0",i.style.visibility="visible",e.atlas?(i.style.width=`${e.width}px`,i.style.height=`${e.height}px`,Gt(i,e,e.atlas,n(e.atlas.resourcePath,e.id))):a?Qt(i,a.atlas,a.width,a.height,n(a.atlas.resourcePath,e.id)):e.strategy==="solid-quad"&&(i.style.width=`${e.width}px`,i.style.height=`${e.height}px`),i}function Uo(o,e,t={}){(!o||typeof o.appendChild!="function"||!o.ownerDocument)&&U("invalid-host","$.host","expected an HTMLElement");let n=Y(e),r=o.ownerDocument,a=r.defaultView?.navigator?.userAgent??"",i=!(0,ee.safariCssProjectiveUnsupported)(a),s=n.render.leaves.some(x=>x.strategy==="solid-triangle")&&!(0,ee.isSolidTriangleSupported)(r),d=new Map,l=typeof r.defaultView?.URL?.createObjectURL=="function"?r.defaultView.URL:globalThis.URL,c=r.defaultView?.Blob??globalThis.Blob,p=()=>{for(let x of d.values())l.revokeObjectURL(x);d.clear()},y=(x,C)=>{let H=d.get(x);if(H)return H;let re=t.resources?.get(x);(!re||re.descriptor.path!==x||re.descriptor.role!=="image")&&U("missing-resource",C,"image-backed leaves require their verified package resource"),(typeof l?.createObjectURL!="function"||typeof l?.revokeObjectURL!="function"||typeof c!="function")&&U("missing-object-url",C,"this browser cannot mount verified image bytes");let ue=re.bytes.slice(),pe=l.createObjectURL(new c([ue.buffer],{type:re.descriptor.mediaType}));return d.set(x,pe),pe};try{for(let x of n.render.leaves){let C=s&&x.strategy==="solid-triangle",H=so(x,x.matrix,C);!i&&H.projective&&U("unsupported-projective-quad",`${x.id}.matrix`,"this browser does not support projective leaf matrices"),x.atlas&&y(x.atlas.resourcePath,x.id),s&&x.strategy==="solid-triangle"&&(x.fallback||U("missing-solid-triangle-fallback",`${x.id}.fallback`,"this browser requires a prepared per-polygon atlas slice"),y(x.fallback.atlas.resourcePath,x.id))}}catch(x){throw p(),x}(0,ee.injectPolyBaseStyles)(r);let P=r.defaultView?.getComputedStyle(o),m=o.style.position,f=!1;(!P||P.position==="static"||P.position==="")&&(o.style.position="relative",f=!0);let b=t.camera??(0,ee.createPolyCamera)({zoom:1}),h=r.createElement("div");h.className="polycss-camera polycss-morph-camera";let $=(0,ee.capturePolyCameraSnapshot)(b);h.style.perspective=$.appliedPerspectiveStyle,h.dataset.polycssCameraProjection=$.projection,o.appendChild(h);let k=r.createElement("div");k.className="polycss-scene polycss-morph-scene",k.setAttribute("aria-hidden","true");let F=(0,ee.buildPolyCameraSceneTransform)(b.state);k.style.transform=F,h.appendChild(k);let v=r.createElement("div");v.className="polycss-mesh polycss-morph-model",v.dataset.polyMorphModel=n.identity.id;let w=je(n.render.modelMatrix);v.style.transform=w,k.appendChild(v);let L=new Map,E=new Map;for(let x of n.render.shapes){let C=r.createElement("div");C.className="polycss-mesh polycss-morph-shape",C.dataset.polyMorphShape=x.id;let H=je(x.matrix);C.style.transform=H,v.appendChild(C),L.set(x.id,C),E.set(x.id,H)}let B=new Map(n.materials.map(x=>[x.id,x])),q=new Map,O=new Map;for(let x of n.render.leaves){let C=L.get(x.shapeId),H=B.get(x.materialId);(!C||!H)&&U("mount-coverage",x.id,"leaf references are incomplete");let re=Xt(r,x,H.color,y,s&&x.strategy==="solid-triangle");C.appendChild(re),q.set(x.id,{id:x.id,plan:x,element:re}),O.set(x.id,{transform:Eo(x,x.matrix,s&&x.strategy==="solid-triangle"),visible:!0,opacity:1,atlasRow:0})}let V=[...L.entries()],N=[...q.entries()],_=!1,M=F,S={applyCount:0,totalTransformWrites:0,totalVisibilityWrites:0,totalOpacityWrites:0,totalAtlasRowWrites:0},u=()=>{_&&U("destroyed","$","mounted model is destroyed")},R=()=>{u(),(L.size!==V.length||q.size!==N.length)&&U("identity-drift","$","retained handle maps changed");for(let[x,C]of V)(L.get(x)!==C||C.parentElement!==v)&&U("identity-drift",x,"shape element identity changed");for(let[x,C]of N){let H=L.get(C.plan.shapeId);(q.get(x)!==C||C.element.parentElement!==H)&&U("identity-drift",x,"leaf element identity changed")}},D={model:n,camera:b,cameraElement:h,sceneElement:k,modelElement:v,shapeElements:L,leafHandles:q,get stats(){return{mountCount:1,shapeRoots:L.size,leafCount:q.size,topologyConstructions:1,atlasConstructions:0,schedulerCount:0,...S}},get destroyed(){return _},apply:x=>{u();let C=Yt(x),H=(C.shapes??[]).map(T=>{let oe=L.get(T.shapeId);return oe||U("unknown-shape",T.shapeId,"no retained shape handle"),{shape:T,element:oe}}),re=(C.leaves??[]).map(T=>{let oe=q.get(T.leafId),te=O.get(T.leafId);(!oe||!te)&&U("unknown-leaf",T.leafId,"no retained leaf handle");let Qe=s&&oe.plan.strategy==="solid-triangle",Le;if(T.matrix){let le=so(oe.plan,T.matrix,Qe);!i&&le.projective&&U("unsupported-projective-quad",`${T.leafId}.matrix`,"this browser does not support projective leaf matrices"),Le=je(le.matrix,le.projective)}let se;if(T.atlasRow!==void 0){let le=oe.plan.atlas;le||U("invalid-atlas-row",T.leafId,"leaf has no image rows");let Mo=le.y+T.atlasRow*le.height;Mo+le.height>le.pageHeight&&U("invalid-atlas-row",T.leafId,"row exceeds the image page"),se=`${-le.x}px ${-Mo}px`}return{leaf:T,handle:oe,state:te,atlasPosition:se,transform:Le}});R();let ue=0,pe=0,Pe=0,Oe=0,fe=0,xe=0;if(C.modelMatrix){let T=je(C.modelMatrix);w!==T&&(w=T,v.style.transform=T,ue+=1)}for(let{shape:T,element:oe}of H){let te=je(T.matrix);E.get(T.shapeId)!==te&&(E.set(T.shapeId,te),oe.style.transform=te,pe+=1)}for(let{leaf:T,handle:oe,state:te,atlasPosition:Qe,transform:Le}of re){if(Le){let se=Le;te.transform!==se&&(te.transform=se,oe.element.style.transform=se,Pe+=1)}if(T.visible!==void 0){let se=T.visible?"visible":"hidden";te.visible!==T.visible&&(te.visible=T.visible,oe.element.style.visibility=se,Oe+=1)}if(T.opacity!==void 0){let se=String(T.opacity);te.opacity!==T.opacity&&(te.opacity=T.opacity,oe.element.style.opacity=se,fe+=1)}T.atlasRow!==void 0&&te.atlasRow!==T.atlasRow&&(te.atlasRow=T.atlasRow,oe.element.style.backgroundPosition=Qe,xe+=1)}return R(),S.applyCount+=1,S.totalTransformWrites+=ue+pe+Pe,S.totalVisibilityWrites+=Oe,S.totalOpacityWrites+=fe,S.totalAtlasRowWrites+=xe,{modelTransformWrites:ue,shapeTransformWrites:pe,leafTransformWrites:Pe,visibilityWrites:Oe,opacityWrites:fe,atlasRowWrites:xe,dirtyLeavesVisited:C.leaves?.length??0,domCreations:0,domRemovals:0,topologyConstructions:0,atlasRedraws:0,schedulerCallbacks:0}},updateCamera(){u();let x=(0,ee.buildPolyCameraSceneTransform)(b.state);if(M===x)return!1;M=x,k.style.transform=x;let C=(0,ee.capturePolyCameraSnapshot)(b);return h.style.perspective=C.appliedPerspectiveStyle,h.dataset.polycssCameraProjection=C.projection,!0},assertStableDomIdentity:R,destroy(){_||(_=!0,h.remove(),L.clear(),q.clear(),O.clear(),E.clear(),p(),f&&o.style.position==="relative"&&(o.style.position=m))}};return D.assertStableDomIdentity(),D}function ae(o,e,t){throw new Me(o,e,t)}function po(o,e){let t=o;return(!t||typeof t!="object"||!t.ownerDocument||typeof t.style?.setProperty!="function")&&ae("invalid-target",e,"expected an HTMLElement"),t}function No(o,e){return typeof o!="string"&&ae("invalid-transform",e,"expected a CSS transform string"),o}function Bo(o,e,t){let n,r,a,i;return Object.freeze({element:o,writeTransform(s){t();let d=No(s,`${e}.transform`);return n===d?!1:(o.style.transform=d,n=d,!0)},writeVisibility(s){return t(),typeof s!="boolean"&&ae("invalid-visibility",`${e}.visible`,"expected a boolean"),r===s?!1:(o.style.visibility=s?"visible":"hidden",r=s,!0)},writeOpacity(s){return t(),(!Number.isFinite(s)||s<0||s>1)&&ae("invalid-opacity",`${e}.opacity`,"expected a value in [0, 1]"),a===s?!1:(o.style.opacity=String(s),a=s,!0)},writeImagePositionY(s){return t(),(typeof s!="string"||s.length===0)&&ae("invalid-image-position",`${e}.imagePositionY`,"expected a CSS position"),i===s?!1:(o.style.backgroundPositionY=s,i=s,!0)}})}function Do(o){(!o||typeof o!="object"||Array.isArray(o))&&ae("invalid-target","$","expected a prepared DOM target");let e=po(o.model?.element,"$.model.element");typeof o.model?.writeTransform!="function"&&ae("invalid-target","$.model.writeTransform","expected a transform writer"),(!Array.isArray(o.shapes)||!Array.isArray(o.leaves))&&ae("invalid-target","$","expected shape and leaf target arrays");let t=o.shapes.map((m,f)=>po(m?.element,`$.shapes[${f}].element`)),n=o.leaves.map((m,f)=>po(m?.element,`$.leaves[${f}].element`)),r=e.parentNode,a=t.map(m=>m.parentNode),i=n.map(m=>m.parentNode),s=!1,d=()=>{s&&ae("target-destroyed","$","prepared DOM target is destroyed")},l=Object.freeze(t.map((m,f)=>Bo(m,`$.shapes[${f}]`,d))),c=Object.freeze(n.map((m,f)=>Bo(m,`$.leaves[${f}]`,d))),p,y=Object.freeze({element:e,writeTransform(m){d();let f=No(m,"$.model.transform");if(p===f)return!1;let b=o.model.writeTransform(f);return typeof b!="boolean"&&ae("invalid-writer-result","$.model.writeTransform","expected a boolean"),p=f,b}});return Object.freeze({model:y,shapes:l,leaves:c,get destroyed(){return s},assertStableDomIdentity:()=>{d(),(e.parentNode!==r||l.some((f,b)=>f.element.parentNode!==a[b])||c.some((f,b)=>f.element.parentNode!==i[b]))&&ae("identity-drift","$","retained DOM identity changed after adoption")},destroy(){s=!0}})}var X=class extends Error{constructor(e,t,n){super(`${t}: ${n}`),this.name="PolyMorphRuntimeError",this.code=e,this.path=t}};function Fo(o,e,t){throw new X(o,e,t)}function _e(o){return Object.freeze([...o])}function Kt(o,e){let{timesMs:t,values:n}=o;if(e<=t[0])return _e(n[0]);for(let r=1;r<t.length;r+=1){let a=t[r];if(e>a)continue;let i=t[r-1],s=n[r-1],d=n[r];if(e===a)return _e(d);if(o.interpolation==="step")return _e(s);let l=(e-i)/(a-i);if(o.target==="joint-rotation"){let p=s.reduce((m,f,b)=>m+f*d[b],0)<0?-1:1,y=s.map((m,f)=>m+(d[f]*p-m)*l),P=Math.hypot(...y);return Object.freeze(y.map(m=>m/P))}return Object.freeze(s.map((c,p)=>c+(d[p]-c)*l))}return _e(n[n.length-1])}function Zt(o,e){if(o.loop){let t=e%o.durationMs;return Object.is(t,-0)?0:t}return Math.min(e,o.durationMs)}function qe(o){let e=Y(o),t=new Map(e.animations.map(n=>[n.id,n]));return Object.freeze({model:e,clipIds:Object.freeze([...t.keys()]),sample(n,r){let a=t.get(n);a||Fo("unknown-clip","$.clipId",n),(!Number.isFinite(r)||r<0)&&Fo("invalid-time","$.timeMs","expected a finite non-negative time");let i=Zt(a,r),s={},d={},l=new Map,c=new Map;for(let p of a.channels){let y=Kt(p,i);if(p.target==="morph-weight"&&(s[p.targetId]=y[0]),p.target==="control-value"&&(d[p.targetId]=y[0]),p.target==="shape-matrix"&&c.set(p.targetId,y),p.target.startsWith("joint-")){let P=l.get(p.targetId)??{};p.target==="joint-translation"?P.translation=y:p.target==="joint-rotation"?P.rotation=y:P.scale=y,l.set(p.targetId,P)}}return{clipId:n,requestedTimeMs:r,sampledTimeMs:i,morphWeights:Object.freeze(s),controlValues:Object.freeze(d),jointTransforms:l,shapeMatrices:c}}})}function yo(o,e,t){throw new X(o,e,t)}function _o(o){return o===null?null:((!Array.isArray(o)||o.length!==3||o.some(e=>typeof e!="number"||!Number.isFinite(e)))&&yo("invalid-point","$.point","expected three finite components or null"),[o[0],o[1],o[2]])}function en(o){let e=Math.hypot(...o.axis);return[o.axis[0]/e,o.axis[1]/e,o.axis[2]/e]}function qo(o){let e=Y(o);return Object.freeze({model:e,controlIds:Object.freeze(e.controls.map(t=>t.id)),controls:new Map(e.controls.map(t=>[t.id,t]))})}function Ho(o){return Object.freeze({tick:-1,active:!1,heldControlId:null,holdStartPoint:null,holdStartValue:0,values:Object.freeze(Object.fromEntries(o.controlIds.map(e=>[e,o.controls.get(e).initial]))),frozenControlIds:Object.freeze([])})}function mo(o,e){let t=_o(e),n=null;for(let r of o.controlIds){let a=o.controls.get(r),i=Math.hypot(t[0]-a.anchor[0],t[1]-a.anchor[1],t[2]-a.anchor[2]);i<=a.radius&&(!n||i<n.distance)&&(n={id:r,distance:i})}return n?.id??null}function Jo(o,e,t){(!e||!Number.isSafeInteger(e.tick)||e.tick<-1)&&yo("invalid-state","$.state","control state is invalid"),typeof t?.active!="boolean"&&yo("invalid-input","$.active","expected a boolean");let n=_o(t.point),r=e.heldControlId,a=e.holdStartPoint,i=e.holdStartValue,s=null,d=null,l={...e.values},c=new Set(e.frozenControlIds),p=t.active&&!e.active,y=!t.active&&e.active;if(p&&n&&(r=mo(o,n),r&&(s=r,a=n,i=l[r]??o.controls.get(r).initial,c.delete(r))),t.active&&r&&n&&a){let m=o.controls.get(r),f=en(m),b=(n[0]-a[0])*f[0]+(n[1]-a[1])*f[1]+(n[2]-a[2])*f[2];l[r]=Math.max(m.minimum,Math.min(m.maximum,i+b))}y&&(d=r,r&&(t.freezeOnRelease===!0?c.add(r):c.delete(r)),r=null,a=null,i=0);let P=Object.freeze({tick:e.tick+1,active:t.active,heldControlId:r,holdStartPoint:a,holdStartValue:i,values:Object.freeze(l),frozenControlIds:Object.freeze([...c].sort())});return Object.freeze({state:P,pickedControlId:s,releasedControlId:d,heldTarget:t.active&&r?Object.freeze({controlId:r,value:l[r]}):null})}var ce=require("@layoutit/polycss");var on=(0,ce.resolveProjectiveQuadGuards)(void 0);function Z(o,e,t){throw new X(o,e,t)}function tn(o,e){return(typeof o!="number"||!Number.isFinite(o))&&Z("invalid-number",e,"expected a finite number"),Object.is(o,-0)?0:o}function nn(o){let e=Math.hypot(...o);return e<=1e-12?[0,0,0]:[o[0]/e,o[1]/e,o[2]/e]}function He(o){return o.map(e=>[e[0],e[1],e[2]])}function Je(o){for(let e of o)Object.freeze(e);return Object.freeze(o)}function rn(o,e){let[t,n,r]=o.vertexIndices,a=e[t],i=e[n],s=e[r],d=(0,ce.computeSolidTrianglePlanFromCssPoints)(o.polygon,0,{seamBleed:0},{basis:o.basis??void 0,includeColor:!1,primitive:"corner-bevel"},a[0],a[1],a[2],i[0],i[1],i[2],s[0],s[1],s[2]);if(!d)return{matrix:null,visible:!1};let l=/^matrix3d\(([^)]+)\)$/u.exec(d.transformText);l||Z("invalid-transform",o.leaf.id,"PolyCSS returned no matrix3d");let c=l[1].split(",").map(Number);(c.length!==16||c.some(P=>!Number.isFinite(P)))&&Z("invalid-transform",o.leaf.id,"PolyCSS returned an invalid matrix3d");let p=ce.SOLID_TRIANGLE_CANONICAL_SIZE/o.leaf.width,y=ce.SOLID_TRIANGLE_CANONICAL_SIZE/o.leaf.height;for(let P of[0,1,2])c[P]*=p;for(let P of[4,5,6])c[P]*=y;return{matrix:c,visible:!0}}function an(o,e){let[t,n,r,a]=o.vertexIndices,i=e[t],s=e[n],d=e[r],l=e[a],c=[s[0]-i[0],s[1]-i[1],s[2]-i[2]],p=[l[0]-i[0],l[1]-i[1],l[2]-i[2]],y=Math.hypot(...c),P=Math.hypot(...p);(!Number.isFinite(y)||!Number.isFinite(P)||y===0||P===0)&&Z("degenerate-polygon",o.leaf.id,"deformed quad has no area");let m=[c[0]/y,c[1]/y,c[2]/y],f=[p[0]/P,p[1]/P,p[2]/P],b=[m[1]*f[2]-m[2]*f[1],m[2]*f[0]-m[0]*f[2],m[0]*f[1]-m[1]*f[0]],h=Math.hypot(...b);(!Number.isFinite(h)||h<=1e-12)&&Z("degenerate-polygon",o.leaf.id,"deformed quad has no area");let $=[b[0]/h,b[1]/h,b[2]/h],k=[d[0]-i[0],d[1]-i[1],d[2]-i[2]],F=Math.hypot(...k),v=Math.abs($[0]*k[0]+$[1]*k[1]+$[2]*k[2]),w=Math.max(y,P,F);(!Number.isFinite(v)||!Number.isFinite(w)||v/w>1e-6)&&Z("non-planar-polygon",o.leaf.id,"deformed quad is not coplanar");let L=[[0,1],[0,2],[1,2]].map(([j,D])=>({first:j,second:D,determinant:m[j]*f[D]-m[D]*f[j]})).sort((j,D)=>Math.abs(D.determinant)-Math.abs(j.determinant))[0],E=[i,s,d,l].map(j=>[j[L.first],j[L.second]]),[B]=E,q=Math.max(...E.map(j=>Math.abs(j[0]-B[0]))),O=Math.max(...E.map(j=>Math.abs(j[1]-B[1])));(!Number.isFinite(q)||!Number.isFinite(O)||q===0||O===0)&&Z("degenerate-polygon",o.leaf.id,"deformed quad has no area");let V=E.map(j=>[(j[0]-B[0])/q,(j[1]-B[1])/O]),N=(0,ce.computeProjectiveQuadCoefficients)(V,on);N||Z("degenerate-polygon",o.leaf.id,"deformed quad has no stable convex projective transform");let{g:_,h:M}=N,S=[((1+_)*s[0]-i[0])/o.leaf.width,((1+_)*s[1]-i[1])/o.leaf.width,((1+_)*s[2]-i[2])/o.leaf.width],u=[((1+M)*l[0]-i[0])/o.leaf.height,((1+M)*l[1]-i[1])/o.leaf.height,((1+M)*l[2]-i[2])/o.leaf.height],R=[S[0],S[1],S[2],_/o.leaf.width,u[0],u[1],u[2],M/o.leaf.height,$[0],$[1],$[2],0,i[0],i[1],i[2],1];return R.some(j=>!Number.isFinite(j))&&Z("invalid-transform",o.leaf.id,"deformed quad produced a non-finite matrix"),{matrix:R,visible:!0}}function uo(o,e){if(o.vertexIndices.length===3)return rn(o,e);if(o.vertexIndices.length===4)return an(o,e);Z("unsupported-deformation",o.leaf.id,"caller-driven deformation supports prepared triangles and planar quads")}function fo(o,e){let t=o.topology.polygons.find(i=>i.id===e.polygonId);t||Z("unknown-polygon",e.id,e.polygonId);let n=t.vertexIndices.map(i=>[...o.topology.vertices[i]]),r={vertices:n},a=null;if(n.length===3){let[i,s,d]=n,l=(0,ce.computeSolidTrianglePlanFromCssPoints)(r,0,{seamBleed:0},{includeColor:!1,primitive:"corner-bevel"},i[0],i[1],i[2],s[0],s[1],s[2],d[0],d[1],d[2]);l||Z("degenerate-polygon",e.id,"base triangle has no area"),a=l.basis}return{leaf:e,vertexIndices:t.vertexIndices,polygon:r,basis:a}}function Wo(o,e,t,n){let r=o??{};(!r||typeof r!="object"||Array.isArray(r))&&Z("invalid-input",t,"expected an object");let a=new Set(e),i=Object.keys(r).find(s=>!a.has(s));return i&&Z("unknown-id",t,i),Object.fromEntries(e.map(s=>{let[d,l]=n.get(s)??[0,1],c=tn(r[s]??0,`${t}.${s}`);return(c<d||c>l)&&Z("out-of-range",`${t}.${s}`,`expected ${d} <= value <= ${l}`),[s,c]}))}function sn(o){return new Map(o.deformation.kind==="morph-regions"?o.deformation.targets.map(e=>[e.id,e]):[])}function Yo(o){let e=Y(o);e.deformation.kind==="joint-skin"&&Z("profile-not-executable","$.profile","joint skin requires the skinning runtime");let t=sn(e),n=[...t.keys()],r=e.controls.map(h=>h.id),a=new Map(n.map(h=>[h,[0,1]])),i=new Map(e.controls.map(h=>[h.id,[h.minimum,h.maximum]])),s=new Map(e.render.leaves.map(h=>[h.polygonId,h])),d=new Map;for(let h of e.topology.polygons)for(let $ of h.vertexIndices){let k=d.get($)??[];k.push(h.id),d.set($,k)}let l=new Map;for(let h of t.values()){let $=new Set;for(let k of h.deltas)for(let F of d.get(k.vertexIndex)??[]){let v=s.get(F);v&&$.add(v.id)}l.set(h.id,$)}let c=new Map(e.render.leaves.map(h=>[h.id,fo(e,h)])),p=Je(He(e.topology.vertices)),y=Je(He(e.topology.normals)),P=Object.fromEntries(n.map(h=>[h,0])),m=p,f=y,b=h=>{(!h||!Number.isSafeInteger(h.tick)||h.tick<0)&&Z("invalid-tick","$.tick","expected a non-negative safe integer");let $=Wo(h.morphWeights,n,"$.morphWeights",a),k=Wo(h.controlValues,r,"$.controlValues",i),F={...$};for(let O of e.controls){let V=k[O.id];for(let N of O.targets)F[N.targetId]=Math.max(0,Math.min(1,(F[N.targetId]??0)+V*N.scale))}let v=n.filter(O=>F[O]!==P[O]),w=m,L=f;if(v.length>0){let O=He(p),V=He(y);for(let N of n){let _=F[N];if(_!==0)for(let M of t.get(N).deltas){let S=O[M.vertexIndex];M.position&&(S[0]+=M.position[0]*_,S[1]+=M.position[1]*_,S[2]+=M.position[2]*_);let u=V[M.vertexIndex];M.normal&&(u[0]+=M.normal[0]*_,u[1]+=M.normal[1]*_,u[2]+=M.normal[2]*_)}}V=V.map(nn),w=Je(O),L=Je(V)}let E=new Set;for(let O of v)for(let V of l.get(O)??[])E.add(V);let B=e.render.leaves.map(O=>O.id).filter(O=>E.has(O)),q=B.map(O=>{let V=uo(c.get(O),w);return{leafId:O,visible:V.visible,...V.matrix?{matrix:V.matrix}:{}}});return m=w,f=L,P={...F},{tick:h.tick,positions:w,normals:L,morphWeights:Object.freeze({...F}),controlValues:Object.freeze({...k}),dirtyLeafIds:Object.freeze(B),leafUpdates:Object.freeze(q),runtimePolygonConstructions:0,runtimeTopologyConstructions:0,atlasRedraws:0}};return Object.freeze({model:e,targetIds:Object.freeze(n),controlIds:Object.freeze(r),basePositions:Object.freeze(p),baseNormals:Object.freeze(y),sample:b,reset(){P=Object.fromEntries(n.map(h=>[h,0])),m=p,f=y}})}function Ve(o,e,t){throw new X(o,e,t)}function Ce(o){return Object.freeze([...o])}function ho(o,e){return o.every((t,n)=>t===e[n])}function We(o){let e=Y(o);return Object.freeze({modelMatrix:Ce(e.render.modelMatrix),shapes:Object.freeze(e.render.shapes.map(t=>Object.freeze({shapeId:t.id,matrix:Ce(t.matrix)}))),leaves:Object.freeze(e.render.leaves.map(t=>Object.freeze({leafId:t.id,matrix:Ce(t.matrix),visible:!0,opacity:1,atlasRow:0})))})}function Ye(o,e){let t=new Map(e.shapes.map(r=>[r.shapeId,r])),n=new Map(e.leaves.map(r=>[r.leafId,r]));for(let r of t.keys())o.shapes.some(a=>a.shapeId===r)||Ve("unknown-shape","$.frame.shapes",r);for(let r of n.keys())o.leaves.some(a=>a.leafId===r)||Ve("unknown-leaf","$.frame.leaves",r);return Object.freeze({modelMatrix:e.modelMatrix===null?o.modelMatrix:Ce(e.modelMatrix),shapes:Object.freeze(o.shapes.map(r=>{let a=t.get(r.shapeId);return a?Object.freeze({shapeId:r.shapeId,matrix:Ce(a.matrix)}):r})),leaves:Object.freeze(o.leaves.map(r=>{let a=n.get(r.leafId);return a?Object.freeze({leafId:r.leafId,matrix:a.matrix===null?r.matrix:Ce(a.matrix),visible:a.visible??r.visible,opacity:a.opacity??r.opacity,atlasRow:a.atlasRow??r.atlasRow}):r}))})}function Ge(o,e){(o.shapes.length!==e.shapes.length||o.leaves.length!==e.leaves.length)&&Ve("state-mismatch","$","prepared state topology differs");let t=!ho(o.modelMatrix,e.modelMatrix),n=[];for(let a=0;a<e.shapes.length;a+=1){let i=o.shapes[a],s=e.shapes[a];i.shapeId!==s.shapeId&&Ve("state-mismatch","$.shapes","source order differs"),ho(i.matrix,s.matrix)||n.push({shapeId:s.shapeId,matrix:s.matrix})}let r=[];for(let a=0;a<e.leaves.length;a+=1){let i=o.leaves[a],s=e.leaves[a];i.leafId!==s.leafId&&Ve("state-mismatch","$.leaves","source order differs");let d={leafId:s.leafId};ho(i.matrix,s.matrix)||(d.matrix=s.matrix),i.visible!==s.visible&&(d.visible=s.visible),i.opacity!==s.opacity&&(d.opacity=s.opacity),i.atlasRow!==s.atlasRow&&(d.atlasRow=s.atlasRow),Object.keys(d).length>1&&r.push(d)}return Object.freeze({update:Object.freeze({...t?{modelMatrix:e.modelMatrix}:{},...n.length>0?{shapes:Object.freeze(n)}:{},...r.length>0?{leaves:Object.freeze(r)}:{}}),modelChanged:t,dirtyShapeIds:Object.freeze(n.map(a=>a.shapeId)),dirtyLeafIds:Object.freeze(r.map(a=>a.leafId))})}function Ee(o,e,t){throw new X(o,e,t)}function ln(o,e,t){if(e){let n=t%o;return Object.is(n,-0)?0:n}return Math.min(t,o)}function dn(o,e){let t=0,n=o.length-1;for(;t<=n;){let r=Math.floor((t+n)/2);o[r]<=e?t=r+1:n=r-1}return Math.max(0,n)}function Go(o){let e=Y(o);(e.profile!=="prepared-playback"||!e.playback)&&Ee("profile-mismatch","$.profile","playback requires the prepared-playback profile");let t=e.playback,n=We(e),r=[],a=n,i=new Map(e.render.leaves.map(p=>[p.id,p]));for(let[p,y]of t.frames.entries()){for(let P of y.leaves){if(P.atlasRow===null)continue;let m=i.get(P.leafId);m.atlas||Ee("invalid-atlas-row",`$.playback.frames[${p}]`,`${m.id} has no image rows`),m.atlas.y+P.atlasRow*m.atlas.height+m.atlas.height>m.atlas.pageHeight&&Ee("invalid-atlas-row",`$.playback.frames[${p}]`,`${m.id} row exceeds its page`)}a=Ye(a,y),r.push(a)}let s=t.frames.map(p=>p.timeMs),d=n,l=null,c=p=>{(!Number.isFinite(p)||p<0)&&Ee("invalid-time","$.timeMs","expected a finite non-negative time");let y=ln(t.durationMs,t.loop,p),P=dn(s,y),m=r[P],f=Ge(d,m),b=Object.freeze({requestedTimeMs:p,sampledTimeMs:y,frameIndex:P,state:m,update:f.update,modelChanged:f.modelChanged,dirtyShapeIds:f.dirtyShapeIds,dirtyLeafIds:f.dirtyLeafIds,domCreations:0,domRemovals:0,topologyConstructions:0,atlasConstructions:0,atlasRedraws:0,schedulerCallbacks:0});return l=b,b};return Object.freeze({model:e,durationMs:t.durationMs,loop:t.loop,frameCount:t.frames.length,sample:c,commit(p){p!==l&&Ee("invalid-sample","$.sample","commit requires the latest unapplied playback sample"),d=p.state,l=null},reset(){d=n,l=null}})}var Qo=Object.freeze(["joint-skin","morph-regions","prepared-playback","static-prepared"]);function ie(o,e,t){throw new X(o,e,t)}function cn(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function go(o,e){let t=new Array(16).fill(0);for(let n=0;n<4;n+=1)for(let r=0;r<4;r+=1){let a=0;for(let i=0;i<4;i+=1)a+=o[i*4+r]*e[n*4+i];t[n*4+r]=Object.is(a,-0)?0:a}return Object.freeze(t)}function pn(o,e){if(o===void 0)return[0,0,0,1];(!Array.isArray(o)||o.length!==4||o.some(n=>typeof n!="number"||!Number.isFinite(n)))&&ie("invalid-quaternion",e,"expected four finite components");let t=Math.hypot(...o);return t<=1e-12&&ie("invalid-quaternion",e,"quaternion must be non-zero"),[o[0]/t,o[1]/t,o[2]/t,o[3]/t]}function Xo(o,e,t,n=!1){return o===void 0?e:((!Array.isArray(o)||o.length!==3||o.some(r=>typeof r!="number"||!Number.isFinite(r)))&&ie("invalid-vector",t,"expected three finite components"),n&&o.some(r=>r<=0)&&ie("invalid-scale",t,"scale components must be positive"),[o[0],o[1],o[2]])}function et(o,e){if(o===void 0)return cn();(!o||typeof o!="object"||Array.isArray(o))&&ie("invalid-joint-transform",e,"expected an object"),Object.keys(o).some($=>$!=="translation"&&$!=="rotation"&&$!=="scale")&&ie("invalid-joint-transform",e,"unknown transform field");let n=Xo(o.translation,[0,0,0],`${e}.translation`),r=Xo(o.scale,[1,1,1],`${e}.scale`,!0),[a,i,s,d]=pn(o.rotation,`${e}.rotation`),l=a*a,c=i*i,p=s*s,y=a*i,P=a*s,m=i*s,f=d*a,b=d*i,h=d*s;return[(1-2*(c+p))*r[0],2*(y+h)*r[0],2*(P-b)*r[0],0,2*(y-h)*r[1],(1-2*(l+p))*r[1],2*(m+f)*r[1],0,2*(P+b)*r[2],2*(m-f)*r[2],(1-2*(l+c))*r[2],0,n[0],n[1],n[2],1]}function yn(o,e){return[o[0]*e[0]+o[4]*e[1]+o[8]*e[2]+o[12],o[1]*e[0]+o[5]*e[1]+o[9]*e[2]+o[13],o[2]*e[0]+o[6]*e[1]+o[10]*e[2]+o[14]]}function mn(o,e,t){let[n,r,a]=o,i=o[4],s=o[5],d=o[6],l=o[8],c=o[9],p=o[10],y=n*(s*p-c*d)-i*(r*p-c*a)+l*(r*d-s*a);return Math.abs(y)<=1e-12&&ie("invalid-normal-transform",t,"joint skin matrix is singular"),[((s*p-c*d)*e[0]+(c*a-r*p)*e[1]+(r*d-s*a)*e[2])/y,((l*d-i*p)*e[0]+(n*p-l*a)*e[1]+(i*a-n*d)*e[2])/y,((i*c-l*s)*e[0]+(l*r-n*c)*e[1]+(n*s-i*r)*e[2])/y]}function un(o){let e=Math.hypot(...o);return e<=1e-12?[0,0,0]:[o[0]/e,o[1]/e,o[2]/e]}function Te(o){for(let e of o)Object.freeze(e);return Object.freeze(o)}function fn(o,e){return o.every((t,n)=>Math.abs(t-e[n])<=1e-12)}function Ko(o,e){let t=new Map(o.map(a=>[a.id,a])),n=new Map,r=a=>{let i=n.get(a.id);if(i)return i;let s=go(a.restMatrix,et(e.get(a.id),`$.jointTransforms.${a.id}`)),d=a.parentId===null?s:go(r(t.get(a.parentId)),s);return n.set(a.id,d),d};for(let a of o)r(a);return n}function Zo(o,e){return new Map(o.map(t=>[t.id,go(e.get(t.id),t.inverseBindMatrix)]))}function hn(o,e){let t=o??new Map;(!t||typeof t.entries!="function")&&ie("invalid-joint-transform","$.jointTransforms","expected a map");for(let[n,r]of t)e.has(n)||ie("unknown-joint","$.jointTransforms",n),et(r,`$.jointTransforms.${n}`);return t}function ot(o){let e=Y(o);e.deformation.kind!=="joint-skin"&&ie("profile-mismatch","$.profile","skinning requires the joint-skin profile");let t=e.deformation,n=t.joints.map(w=>w.id),r=new Set(n),a=Ko(t.joints,new Map),i=Zo(t.joints,a),s=Te(e.topology.vertices.map(w=>[...w])),d=Te(e.topology.normals.map(w=>[...w])),l=new Map(e.render.leaves.map(w=>[w.id,fo(e,w)])),c=new Map;for(let w of e.topology.polygons)for(let L of w.vertexIndices){let E=c.get(L)??[];E.push(w.id),c.set(L,E)}let p=new Map(e.render.leaves.map(w=>[w.polygonId,w.id])),y=new Map(t.vertices.map(w=>[w.vertexIndex,w])),P=w=>{let L=[],E=[];for(let B=0;B<s.length;B+=1){let q=y.get(B),O=[0,0,0],V=[0,0,0];for(let N of q.influences){let _=w.get(N.jointId),M=yn(_,s[B]),S=mn(_,d[B],`$.skinMatrices.${N.jointId}`);O[0]+=M[0]*N.weight,O[1]+=M[1]*N.weight,O[2]+=M[2]*N.weight,V[0]+=S[0]*N.weight,V[1]+=S[1]*N.weight,V[2]+=S[2]*N.weight}L.push(O),E.push(un(V))}return{positions:L,normals:E}},m=P(i),f=Te(m.positions),b=Te(m.normals),h=new Map(i),$=f,k=b,F=qe(e),v=w=>{(!w||!Number.isSafeInteger(w.tick)||w.tick<0)&&ie("invalid-tick","$.tick","expected a non-negative safe integer");let L=hn(w.jointTransforms,r),E=Ko(t.joints,L),B=Zo(t.joints,E),q=new Set(n.filter(u=>!fn(B.get(u),h.get(u)))),O=$,V=k;if(q.size>0){let u=P(B);O=Te(u.positions),V=Te(u.normals)}let N=new Set;if(q.size>0)for(let u of t.vertices)u.influences.some(R=>q.has(R.jointId))&&N.add(u.vertexIndex);let _=new Set;for(let u of N)for(let R of c.get(u)??[]){let j=p.get(R);j&&_.add(j)}let M=e.render.leaves.map(u=>u.id).filter(u=>_.has(u)),S=M.map(u=>{let R=uo(l.get(u),O);return{leafId:u,visible:R.visible,...R.matrix?{matrix:R.matrix}:{}}});return $=O,k=V,h=new Map(B),{tick:w.tick,positions:O,normals:V,globalJointMatrices:E,skinMatrices:B,dirtyLeafIds:Object.freeze(M),leafUpdates:Object.freeze(S),runtimePolygonConstructions:0,runtimeTopologyConstructions:0,atlasRedraws:0}};return Object.freeze({model:e,jointIds:Object.freeze(n),basePositions:Object.freeze(s),baseNormals:Object.freeze(d),sample:v,sampleClip(w,L,E){let B=F.sample(w,L);return v({tick:E,jointTransforms:B.jointTransforms})},reset(){h=new Map(i),$=f,k=b}})}function be(o,e,t){throw new X(o,e,t)}function gn(o,e,t,n,r){let a=n*n-4*t,i=1e-9*Math.max(1,n*n,t);if(Math.abs(a)<=i){let m=n/2,f=e+m*o,b=Math.exp(-m*r);return[b*(o+f*r),b*(e-m*f*r)]}if(a<0){let m=n/2,f=Math.sqrt(t-m*m),b=f*r,h=Math.cos(b),$=Math.sin(b),k=Math.exp(-m*r);return[k*(o*h+(e+m*o)/f*$),k*(e*h-(m*e+t*o)/f*$)]}let s=Math.sqrt(a),d=(-n+s)/2,l=(-n-s)/2,c=(e-l*o)/(d-l),p=o-c,y=c*Math.exp(d*r),P=p*Math.exp(l*r);return[y+P,d*y+l*P]}function tt(o){let e=Y(o),t=new Map;for(let n of e.springs)t.set(n.controlId,n);return Object.freeze({model:e,controlIds:Object.freeze(e.controls.map(n=>n.id)),controls:new Map(e.controls.map(n=>[n.id,n])),springs:t})}function nt(o,e){let t=Object.keys(e??{}).find(r=>!o.controls.has(r));t&&be("unknown-id","$.values",t);let n=Object.fromEntries(o.controlIds.map(r=>{let a=o.controls.get(r),i=e?.[r]??a.initial;return(!Number.isFinite(i)||i<a.minimum||i>a.maximum)&&be("out-of-range",`$.values.${r}`,"value is outside control bounds"),[r,i]}));return Object.freeze({tick:-1,values:Object.freeze(n),velocities:Object.freeze(Object.fromEntries(o.controlIds.map(r=>[r,0]))),atRest:o.controlIds.every(r=>n[r]===o.controls.get(r).initial)})}function rt(o,e,t){(!e||!Number.isSafeInteger(e.tick)||e.tick<-1)&&be("invalid-state","$.state","spring state is invalid"),(!Number.isFinite(t?.deltaMs)||t.deltaMs<=0||t.deltaMs>1e3)&&be("invalid-time","$.deltaMs","expected 0 < deltaMs <= 1000");let n=t.heldTarget??null;if(n){let l=o.controls.get(n.controlId);l||be("unknown-id","$.heldTarget.controlId",n.controlId),(!Number.isFinite(n.value)||n.value<l.minimum||n.value>l.maximum)&&be("out-of-range","$.heldTarget.value","value is outside control bounds")}let r=new Set(t.frozenControlIds??[]);for(let l of r)o.controls.has(l)||be("unknown-id","$.frozenControlIds",l);let a=t.deltaMs/1e3,i={},s={},d=!0;for(let l of o.controlIds){let c=o.controls.get(l),p=e.values[l]??c.initial,y=e.velocities[l]??0;if(n?.controlId===l)i[l]=n.value,s[l]=0;else if(r.has(l)||!o.springs.has(l))i[l]=p,s[l]=0;else{let P=o.springs.get(l),m=p-c.initial,[f,b]=gn(m,y,P.stiffness,P.damping,a),h=b,$=c.initial+f,k=Math.max(c.minimum,Math.min(c.maximum,$));k!==$&&(h=0),$=k,Math.abs($-c.initial)<1e-6&&Math.abs(h)<1e-6&&($=c.initial,h=0),i[l]=Object.is($,-0)?0:$,s[l]=Object.is(h,-0)?0:h}(i[l]!==c.initial||s[l]!==0)&&(d=!1)}return Object.freeze({tick:e.tick+1,values:Object.freeze(i),velocities:Object.freeze(s),atRest:d})}0&&(module.exports={POLY_MORPH_CATALOG_SCHEMA,POLY_MORPH_EXECUTABLE_PROFILES,POLY_MORPH_MODEL_SCHEMA,POLY_MORPH_PACKAGE_SCHEMA,PolyMorphContractError,PolyMorphPackageError,PolyMorphRenderError,PolyMorphRuntimeError,applyPolyMorphPlaybackFrame,assertPolyMorphPackageModelBinding,buildPolyMorphCatalog,buildPolyMorphPackage,createPolyMorphAnimationRuntime,createPolyMorphControlRuntime,createPolyMorphControlState,createPolyMorphDeformationRuntime,createPolyMorphPlaybackRuntime,createPolyMorphPreparedDomTarget,createPolyMorphPreparedState,createPolyMorphSkinningRuntime,createPolyMorphSpringRuntime,createPolyMorphSpringState,decodePolyMorphJson,diffPolyMorphPreparedStates,encodePolyMorphCanonicalJson,hashPolyMorphBytes,isPolyMorphId,isPolyMorphResourcePath,loadPolyMorphCatalog,loadPolyMorphPackage,mountPolyMorphModel,pickPolyMorphControl,stepPolyMorphControls,stepPolyMorphSprings,stringifyPolyMorphCanonicalJson,validatePolyMorphCatalog,validatePolyMorphModel,validatePolyMorphPackageManifest});
|
package/dist/index.d.cts
CHANGED
|
@@ -86,9 +86,42 @@ interface PolyMorphMountedModel {
|
|
|
86
86
|
assertStableDomIdentity(): void;
|
|
87
87
|
destroy(): void;
|
|
88
88
|
}
|
|
89
|
+
interface PolyMorphPreparedModelTargetInput {
|
|
90
|
+
readonly element: HTMLElement;
|
|
91
|
+
writeTransform(transform: string): boolean;
|
|
92
|
+
}
|
|
93
|
+
interface PolyMorphPreparedElementTargetInput {
|
|
94
|
+
readonly element: HTMLElement;
|
|
95
|
+
}
|
|
96
|
+
interface PolyMorphPreparedDomTargetInput {
|
|
97
|
+
readonly model: PolyMorphPreparedModelTargetInput;
|
|
98
|
+
readonly shapes: readonly PolyMorphPreparedElementTargetInput[];
|
|
99
|
+
readonly leaves: readonly PolyMorphPreparedElementTargetInput[];
|
|
100
|
+
}
|
|
101
|
+
interface PolyMorphPreparedModelTarget {
|
|
102
|
+
readonly element: HTMLElement;
|
|
103
|
+
writeTransform(transform: string): boolean;
|
|
104
|
+
}
|
|
105
|
+
interface PolyMorphPreparedElementTarget {
|
|
106
|
+
readonly element: HTMLElement;
|
|
107
|
+
writeTransform(transform: string): boolean;
|
|
108
|
+
writeVisibility(visible: boolean): boolean;
|
|
109
|
+
writeOpacity(opacity: number): boolean;
|
|
110
|
+
writeImagePositionY(position: string): boolean;
|
|
111
|
+
}
|
|
112
|
+
interface PolyMorphPreparedDomTarget {
|
|
113
|
+
readonly model: PolyMorphPreparedModelTarget;
|
|
114
|
+
readonly shapes: readonly PolyMorphPreparedElementTarget[];
|
|
115
|
+
readonly leaves: readonly PolyMorphPreparedElementTarget[];
|
|
116
|
+
readonly destroyed: boolean;
|
|
117
|
+
assertStableDomIdentity(): void;
|
|
118
|
+
destroy(): void;
|
|
119
|
+
}
|
|
89
120
|
|
|
90
121
|
declare function mountPolyMorphModel(host: HTMLElement, modelInput: unknown, options?: PolyMorphMountOptions): PolyMorphMountedModel;
|
|
91
122
|
|
|
123
|
+
declare function createPolyMorphPreparedDomTarget(input: PolyMorphPreparedDomTargetInput): PolyMorphPreparedDomTarget;
|
|
124
|
+
|
|
92
125
|
declare class PolyMorphRenderError extends Error {
|
|
93
126
|
readonly code: string;
|
|
94
127
|
readonly path: string;
|
|
@@ -295,4 +328,4 @@ declare function createPolyMorphSpringRuntime(modelInput: unknown): PolyMorphSpr
|
|
|
295
328
|
declare function createPolyMorphSpringState(runtime: PolyMorphSpringRuntime, values?: Readonly<Record<string, number>>): PolyMorphSpringState;
|
|
296
329
|
declare function stepPolyMorphSprings(runtime: PolyMorphSpringRuntime, state: PolyMorphSpringState, options: PolyMorphSpringStepOptions): PolyMorphSpringState;
|
|
297
330
|
|
|
298
|
-
export { POLY_MORPH_EXECUTABLE_PROFILES, type PolyMorphAnimationRuntime, type PolyMorphAnimationSample, type PolyMorphApplyResult, type PolyMorphCamera, PolyMorphCatalog, PolyMorphControl, type PolyMorphControlInput, type PolyMorphControlRuntime, type PolyMorphControlState, type PolyMorphControlStep, type PolyMorphDeformationFrame, type PolyMorphDeformationInput, type PolyMorphDeformationRuntime, type PolyMorphJointAnimationSample, type PolyMorphLeafHandle, type PolyMorphLeafUpdate, type PolyMorphLoadOptions, PolyMorphLoadedPackage, PolyMorphLoadedResource, PolyMorphMat4, PolyMorphModel, type PolyMorphMountOptions, type PolyMorphMountedModel, PolyMorphPlaybackFrame, type PolyMorphPlaybackRuntime, type PolyMorphPlaybackSample, type PolyMorphPreparedLeafMatrix, type PolyMorphPreparedLeafState, type PolyMorphPreparedShapeState, type PolyMorphPreparedState, type PolyMorphPreparedStateDiff, PolyMorphQuat, PolyMorphRenderError, PolyMorphRenderLeaf, type PolyMorphRenderStats, type PolyMorphRetainedUpdate, PolyMorphRuntimeError, type PolyMorphShapeUpdate, type PolyMorphSkinningFrame, type PolyMorphSkinningInput, type PolyMorphSkinningRuntime, PolyMorphSpring, type PolyMorphSpringRuntime, type PolyMorphSpringState, type PolyMorphSpringStepOptions, PolyMorphVec3, applyPolyMorphPlaybackFrame, createPolyMorphAnimationRuntime, createPolyMorphControlRuntime, createPolyMorphControlState, createPolyMorphDeformationRuntime, createPolyMorphPlaybackRuntime, createPolyMorphPreparedState, createPolyMorphSkinningRuntime, createPolyMorphSpringRuntime, createPolyMorphSpringState, diffPolyMorphPreparedStates, loadPolyMorphCatalog, loadPolyMorphPackage, mountPolyMorphModel, pickPolyMorphControl, stepPolyMorphControls, stepPolyMorphSprings };
|
|
331
|
+
export { POLY_MORPH_EXECUTABLE_PROFILES, type PolyMorphAnimationRuntime, type PolyMorphAnimationSample, type PolyMorphApplyResult, type PolyMorphCamera, PolyMorphCatalog, PolyMorphControl, type PolyMorphControlInput, type PolyMorphControlRuntime, type PolyMorphControlState, type PolyMorphControlStep, type PolyMorphDeformationFrame, type PolyMorphDeformationInput, type PolyMorphDeformationRuntime, type PolyMorphJointAnimationSample, type PolyMorphLeafHandle, type PolyMorphLeafUpdate, type PolyMorphLoadOptions, PolyMorphLoadedPackage, PolyMorphLoadedResource, PolyMorphMat4, PolyMorphModel, type PolyMorphMountOptions, type PolyMorphMountedModel, PolyMorphPlaybackFrame, type PolyMorphPlaybackRuntime, type PolyMorphPlaybackSample, type PolyMorphPreparedDomTarget, type PolyMorphPreparedDomTargetInput, type PolyMorphPreparedElementTarget, type PolyMorphPreparedElementTargetInput, type PolyMorphPreparedLeafMatrix, type PolyMorphPreparedLeafState, type PolyMorphPreparedModelTarget, type PolyMorphPreparedModelTargetInput, type PolyMorphPreparedShapeState, type PolyMorphPreparedState, type PolyMorphPreparedStateDiff, PolyMorphQuat, PolyMorphRenderError, PolyMorphRenderLeaf, type PolyMorphRenderStats, type PolyMorphRetainedUpdate, PolyMorphRuntimeError, type PolyMorphShapeUpdate, type PolyMorphSkinningFrame, type PolyMorphSkinningInput, type PolyMorphSkinningRuntime, PolyMorphSpring, type PolyMorphSpringRuntime, type PolyMorphSpringState, type PolyMorphSpringStepOptions, PolyMorphVec3, applyPolyMorphPlaybackFrame, createPolyMorphAnimationRuntime, createPolyMorphControlRuntime, createPolyMorphControlState, createPolyMorphDeformationRuntime, createPolyMorphPlaybackRuntime, createPolyMorphPreparedDomTarget, createPolyMorphPreparedState, createPolyMorphSkinningRuntime, createPolyMorphSpringRuntime, createPolyMorphSpringState, diffPolyMorphPreparedStates, loadPolyMorphCatalog, loadPolyMorphPackage, mountPolyMorphModel, pickPolyMorphControl, stepPolyMorphControls, stepPolyMorphSprings };
|
package/dist/index.d.ts
CHANGED
|
@@ -86,9 +86,42 @@ interface PolyMorphMountedModel {
|
|
|
86
86
|
assertStableDomIdentity(): void;
|
|
87
87
|
destroy(): void;
|
|
88
88
|
}
|
|
89
|
+
interface PolyMorphPreparedModelTargetInput {
|
|
90
|
+
readonly element: HTMLElement;
|
|
91
|
+
writeTransform(transform: string): boolean;
|
|
92
|
+
}
|
|
93
|
+
interface PolyMorphPreparedElementTargetInput {
|
|
94
|
+
readonly element: HTMLElement;
|
|
95
|
+
}
|
|
96
|
+
interface PolyMorphPreparedDomTargetInput {
|
|
97
|
+
readonly model: PolyMorphPreparedModelTargetInput;
|
|
98
|
+
readonly shapes: readonly PolyMorphPreparedElementTargetInput[];
|
|
99
|
+
readonly leaves: readonly PolyMorphPreparedElementTargetInput[];
|
|
100
|
+
}
|
|
101
|
+
interface PolyMorphPreparedModelTarget {
|
|
102
|
+
readonly element: HTMLElement;
|
|
103
|
+
writeTransform(transform: string): boolean;
|
|
104
|
+
}
|
|
105
|
+
interface PolyMorphPreparedElementTarget {
|
|
106
|
+
readonly element: HTMLElement;
|
|
107
|
+
writeTransform(transform: string): boolean;
|
|
108
|
+
writeVisibility(visible: boolean): boolean;
|
|
109
|
+
writeOpacity(opacity: number): boolean;
|
|
110
|
+
writeImagePositionY(position: string): boolean;
|
|
111
|
+
}
|
|
112
|
+
interface PolyMorphPreparedDomTarget {
|
|
113
|
+
readonly model: PolyMorphPreparedModelTarget;
|
|
114
|
+
readonly shapes: readonly PolyMorphPreparedElementTarget[];
|
|
115
|
+
readonly leaves: readonly PolyMorphPreparedElementTarget[];
|
|
116
|
+
readonly destroyed: boolean;
|
|
117
|
+
assertStableDomIdentity(): void;
|
|
118
|
+
destroy(): void;
|
|
119
|
+
}
|
|
89
120
|
|
|
90
121
|
declare function mountPolyMorphModel(host: HTMLElement, modelInput: unknown, options?: PolyMorphMountOptions): PolyMorphMountedModel;
|
|
91
122
|
|
|
123
|
+
declare function createPolyMorphPreparedDomTarget(input: PolyMorphPreparedDomTargetInput): PolyMorphPreparedDomTarget;
|
|
124
|
+
|
|
92
125
|
declare class PolyMorphRenderError extends Error {
|
|
93
126
|
readonly code: string;
|
|
94
127
|
readonly path: string;
|
|
@@ -295,4 +328,4 @@ declare function createPolyMorphSpringRuntime(modelInput: unknown): PolyMorphSpr
|
|
|
295
328
|
declare function createPolyMorphSpringState(runtime: PolyMorphSpringRuntime, values?: Readonly<Record<string, number>>): PolyMorphSpringState;
|
|
296
329
|
declare function stepPolyMorphSprings(runtime: PolyMorphSpringRuntime, state: PolyMorphSpringState, options: PolyMorphSpringStepOptions): PolyMorphSpringState;
|
|
297
330
|
|
|
298
|
-
export { POLY_MORPH_EXECUTABLE_PROFILES, type PolyMorphAnimationRuntime, type PolyMorphAnimationSample, type PolyMorphApplyResult, type PolyMorphCamera, PolyMorphCatalog, PolyMorphControl, type PolyMorphControlInput, type PolyMorphControlRuntime, type PolyMorphControlState, type PolyMorphControlStep, type PolyMorphDeformationFrame, type PolyMorphDeformationInput, type PolyMorphDeformationRuntime, type PolyMorphJointAnimationSample, type PolyMorphLeafHandle, type PolyMorphLeafUpdate, type PolyMorphLoadOptions, PolyMorphLoadedPackage, PolyMorphLoadedResource, PolyMorphMat4, PolyMorphModel, type PolyMorphMountOptions, type PolyMorphMountedModel, PolyMorphPlaybackFrame, type PolyMorphPlaybackRuntime, type PolyMorphPlaybackSample, type PolyMorphPreparedLeafMatrix, type PolyMorphPreparedLeafState, type PolyMorphPreparedShapeState, type PolyMorphPreparedState, type PolyMorphPreparedStateDiff, PolyMorphQuat, PolyMorphRenderError, PolyMorphRenderLeaf, type PolyMorphRenderStats, type PolyMorphRetainedUpdate, PolyMorphRuntimeError, type PolyMorphShapeUpdate, type PolyMorphSkinningFrame, type PolyMorphSkinningInput, type PolyMorphSkinningRuntime, PolyMorphSpring, type PolyMorphSpringRuntime, type PolyMorphSpringState, type PolyMorphSpringStepOptions, PolyMorphVec3, applyPolyMorphPlaybackFrame, createPolyMorphAnimationRuntime, createPolyMorphControlRuntime, createPolyMorphControlState, createPolyMorphDeformationRuntime, createPolyMorphPlaybackRuntime, createPolyMorphPreparedState, createPolyMorphSkinningRuntime, createPolyMorphSpringRuntime, createPolyMorphSpringState, diffPolyMorphPreparedStates, loadPolyMorphCatalog, loadPolyMorphPackage, mountPolyMorphModel, pickPolyMorphControl, stepPolyMorphControls, stepPolyMorphSprings };
|
|
331
|
+
export { POLY_MORPH_EXECUTABLE_PROFILES, type PolyMorphAnimationRuntime, type PolyMorphAnimationSample, type PolyMorphApplyResult, type PolyMorphCamera, PolyMorphCatalog, PolyMorphControl, type PolyMorphControlInput, type PolyMorphControlRuntime, type PolyMorphControlState, type PolyMorphControlStep, type PolyMorphDeformationFrame, type PolyMorphDeformationInput, type PolyMorphDeformationRuntime, type PolyMorphJointAnimationSample, type PolyMorphLeafHandle, type PolyMorphLeafUpdate, type PolyMorphLoadOptions, PolyMorphLoadedPackage, PolyMorphLoadedResource, PolyMorphMat4, PolyMorphModel, type PolyMorphMountOptions, type PolyMorphMountedModel, PolyMorphPlaybackFrame, type PolyMorphPlaybackRuntime, type PolyMorphPlaybackSample, type PolyMorphPreparedDomTarget, type PolyMorphPreparedDomTargetInput, type PolyMorphPreparedElementTarget, type PolyMorphPreparedElementTargetInput, type PolyMorphPreparedLeafMatrix, type PolyMorphPreparedLeafState, type PolyMorphPreparedModelTarget, type PolyMorphPreparedModelTargetInput, type PolyMorphPreparedShapeState, type PolyMorphPreparedState, type PolyMorphPreparedStateDiff, PolyMorphQuat, PolyMorphRenderError, PolyMorphRenderLeaf, type PolyMorphRenderStats, type PolyMorphRetainedUpdate, PolyMorphRuntimeError, type PolyMorphShapeUpdate, type PolyMorphSkinningFrame, type PolyMorphSkinningInput, type PolyMorphSkinningRuntime, PolyMorphSpring, type PolyMorphSpringRuntime, type PolyMorphSpringState, type PolyMorphSpringStepOptions, PolyMorphVec3, applyPolyMorphPlaybackFrame, createPolyMorphAnimationRuntime, createPolyMorphControlRuntime, createPolyMorphControlState, createPolyMorphDeformationRuntime, createPolyMorphPlaybackRuntime, createPolyMorphPreparedDomTarget, createPolyMorphPreparedState, createPolyMorphSkinningRuntime, createPolyMorphSpringRuntime, createPolyMorphSpringState, diffPolyMorphPreparedStates, loadPolyMorphCatalog, loadPolyMorphPackage, mountPolyMorphModel, pickPolyMorphControl, stepPolyMorphControls, stepPolyMorphSprings };
|