@layoutit/polycss-morph 0.2.9
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/LICENSE +21 -0
- package/README.md +101 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +298 -0
- package/dist/index.d.ts +298 -0
- package/dist/index.js +1 -0
- package/dist/prepare.cjs +1 -0
- package/dist/prepare.d.cts +118 -0
- package/dist/prepare.d.ts +118 -0
- package/dist/prepare.js +1 -0
- package/dist/validation-CY2nydbS.d.cts +306 -0
- package/dist/validation-CY2nydbS.d.ts +306 -0
- package/package.json +72 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { P as PolyMorphCatalog, a as PolyMorphLoadedPackage, b as PolyMorphMat4, c as PolyMorphRenderLeaf, d as PolyMorphLoadedResource, e as PolyMorphModel, f as PolyMorphVec3, g as PolyMorphQuat, h as PolyMorphControl, i as PolyMorphPlaybackFrame, j as PolyMorphSpring } from './validation-CY2nydbS.js';
|
|
2
|
+
export { k as POLY_MORPH_CATALOG_SCHEMA, l as POLY_MORPH_MODEL_SCHEMA, m as POLY_MORPH_PACKAGE_SCHEMA, n as PolyMorphAnimationChannel, o as PolyMorphAnimationClip, p as PolyMorphAnimationTarget, q as PolyMorphAtlasSlice, r as PolyMorphBudgets, s as PolyMorphBuiltCatalog, t as PolyMorphBuiltPackage, u as PolyMorphCapability, v as PolyMorphCatalogRow, w as PolyMorphColor, x as PolyMorphContractError, y as PolyMorphControlTarget, z as PolyMorphDeformation, A as PolyMorphJoint, B as PolyMorphJointDeformation, C as PolyMorphJointInfluence, D as PolyMorphMaterial, E as PolyMorphModelIdentity, F as PolyMorphNoDeformation, G as PolyMorphPackageError, H as PolyMorphPackageManifest, I as PolyMorphPlayback, J as PolyMorphPlaybackLeafUpdate, K as PolyMorphPlaybackShapeUpdate, L as PolyMorphPolygon, M as PolyMorphProfile, N as PolyMorphProvenance, O as PolyMorphProvenanceSource, Q as PolyMorphRegionDeformation, R as PolyMorphRenderFallback, S as PolyMorphRenderPlan, T as PolyMorphRenderShape, U as PolyMorphRenderStrategy, V as PolyMorphResourceDescriptor, W as PolyMorphResourceInput, X as PolyMorphResourceRole, Y as PolyMorphSkinVertex, Z as PolyMorphSparseDelta, _ as PolyMorphTarget, $ as PolyMorphTopology, a0 as assertPolyMorphPackageModelBinding, a1 as buildPolyMorphCatalog, a2 as buildPolyMorphPackage, a3 as decodePolyMorphJson, a4 as encodePolyMorphCanonicalJson, a5 as hashPolyMorphBytes, a6 as isPolyMorphId, a7 as isPolyMorphResourcePath, a8 as stringifyPolyMorphCanonicalJson, a9 as validatePolyMorphCatalog, aa as validatePolyMorphModel, ab as validatePolyMorphPackageManifest } from './validation-CY2nydbS.js';
|
|
3
|
+
import { PolyOrthographicCameraHandle, PolyPerspectiveCameraHandle } from '@layoutit/polycss';
|
|
4
|
+
|
|
5
|
+
interface PolyMorphLoadOptions {
|
|
6
|
+
readonly fetchImpl?: typeof fetch;
|
|
7
|
+
readonly modelId?: string;
|
|
8
|
+
readonly maxResourceBytes?: number;
|
|
9
|
+
readonly maxResources?: number;
|
|
10
|
+
readonly maxTotalBytes?: number;
|
|
11
|
+
readonly requestTimeoutMs?: number;
|
|
12
|
+
readonly signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
declare function loadPolyMorphCatalog(baseUrl: string, options?: Omit<PolyMorphLoadOptions, "maxResources" | "maxTotalBytes" | "modelId">): Promise<{
|
|
15
|
+
readonly catalog: PolyMorphCatalog;
|
|
16
|
+
readonly bytes: Uint8Array;
|
|
17
|
+
readonly sha256: string;
|
|
18
|
+
}>;
|
|
19
|
+
declare function loadPolyMorphPackage(baseUrl: string, options?: PolyMorphLoadOptions): Promise<PolyMorphLoadedPackage>;
|
|
20
|
+
|
|
21
|
+
type PolyMorphCamera = PolyOrthographicCameraHandle | PolyPerspectiveCameraHandle;
|
|
22
|
+
interface PolyMorphMountOptions {
|
|
23
|
+
readonly camera?: PolyMorphCamera;
|
|
24
|
+
readonly resources?: ReadonlyMap<string, PolyMorphLoadedResource>;
|
|
25
|
+
}
|
|
26
|
+
interface PolyMorphShapeUpdate {
|
|
27
|
+
readonly shapeId: string;
|
|
28
|
+
readonly matrix: PolyMorphMat4;
|
|
29
|
+
}
|
|
30
|
+
interface PolyMorphLeafUpdate {
|
|
31
|
+
readonly leafId: string;
|
|
32
|
+
readonly matrix?: PolyMorphMat4;
|
|
33
|
+
readonly visible?: boolean;
|
|
34
|
+
readonly opacity?: number;
|
|
35
|
+
readonly atlasRow?: number;
|
|
36
|
+
}
|
|
37
|
+
interface PolyMorphRetainedUpdate {
|
|
38
|
+
readonly modelMatrix?: PolyMorphMat4;
|
|
39
|
+
readonly shapes?: readonly PolyMorphShapeUpdate[];
|
|
40
|
+
readonly leaves?: readonly PolyMorphLeafUpdate[];
|
|
41
|
+
}
|
|
42
|
+
interface PolyMorphApplyResult {
|
|
43
|
+
readonly modelTransformWrites: number;
|
|
44
|
+
readonly shapeTransformWrites: number;
|
|
45
|
+
readonly leafTransformWrites: number;
|
|
46
|
+
readonly visibilityWrites: number;
|
|
47
|
+
readonly opacityWrites: number;
|
|
48
|
+
readonly atlasRowWrites: number;
|
|
49
|
+
readonly dirtyLeavesVisited: number;
|
|
50
|
+
readonly domCreations: 0;
|
|
51
|
+
readonly domRemovals: 0;
|
|
52
|
+
readonly topologyConstructions: 0;
|
|
53
|
+
readonly atlasRedraws: 0;
|
|
54
|
+
readonly schedulerCallbacks: 0;
|
|
55
|
+
}
|
|
56
|
+
interface PolyMorphRenderStats {
|
|
57
|
+
readonly mountCount: 1;
|
|
58
|
+
readonly shapeRoots: number;
|
|
59
|
+
readonly leafCount: number;
|
|
60
|
+
readonly topologyConstructions: 1;
|
|
61
|
+
readonly atlasConstructions: 0;
|
|
62
|
+
readonly schedulerCount: 0;
|
|
63
|
+
readonly applyCount: number;
|
|
64
|
+
readonly totalTransformWrites: number;
|
|
65
|
+
readonly totalVisibilityWrites: number;
|
|
66
|
+
readonly totalOpacityWrites: number;
|
|
67
|
+
readonly totalAtlasRowWrites: number;
|
|
68
|
+
}
|
|
69
|
+
interface PolyMorphLeafHandle {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly plan: PolyMorphRenderLeaf;
|
|
72
|
+
readonly element: HTMLElement;
|
|
73
|
+
}
|
|
74
|
+
interface PolyMorphMountedModel {
|
|
75
|
+
readonly model: PolyMorphModel;
|
|
76
|
+
readonly camera: PolyMorphCamera;
|
|
77
|
+
readonly cameraElement: HTMLElement;
|
|
78
|
+
readonly sceneElement: HTMLElement;
|
|
79
|
+
readonly modelElement: HTMLElement;
|
|
80
|
+
readonly shapeElements: ReadonlyMap<string, HTMLElement>;
|
|
81
|
+
readonly leafHandles: ReadonlyMap<string, PolyMorphLeafHandle>;
|
|
82
|
+
readonly stats: PolyMorphRenderStats;
|
|
83
|
+
readonly destroyed: boolean;
|
|
84
|
+
apply(update: PolyMorphRetainedUpdate): PolyMorphApplyResult;
|
|
85
|
+
updateCamera(): boolean;
|
|
86
|
+
assertStableDomIdentity(): void;
|
|
87
|
+
destroy(): void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare function mountPolyMorphModel(host: HTMLElement, modelInput: unknown, options?: PolyMorphMountOptions): PolyMorphMountedModel;
|
|
91
|
+
|
|
92
|
+
declare class PolyMorphRenderError extends Error {
|
|
93
|
+
readonly code: string;
|
|
94
|
+
readonly path: string;
|
|
95
|
+
constructor(code: string, path: string, message: string);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface PolyMorphJointAnimationSample {
|
|
99
|
+
readonly translation?: PolyMorphVec3;
|
|
100
|
+
readonly rotation?: PolyMorphQuat;
|
|
101
|
+
readonly scale?: PolyMorphVec3;
|
|
102
|
+
}
|
|
103
|
+
interface PolyMorphAnimationSample {
|
|
104
|
+
readonly clipId: string;
|
|
105
|
+
readonly requestedTimeMs: number;
|
|
106
|
+
readonly sampledTimeMs: number;
|
|
107
|
+
readonly morphWeights: Readonly<Record<string, number>>;
|
|
108
|
+
readonly controlValues: Readonly<Record<string, number>>;
|
|
109
|
+
readonly jointTransforms: ReadonlyMap<string, PolyMorphJointAnimationSample>;
|
|
110
|
+
readonly shapeMatrices: ReadonlyMap<string, PolyMorphMat4>;
|
|
111
|
+
}
|
|
112
|
+
interface PolyMorphAnimationRuntime {
|
|
113
|
+
readonly model: PolyMorphModel;
|
|
114
|
+
readonly clipIds: readonly string[];
|
|
115
|
+
sample(clipId: string, timeMs: number): PolyMorphAnimationSample;
|
|
116
|
+
}
|
|
117
|
+
declare function createPolyMorphAnimationRuntime(modelInput: unknown): PolyMorphAnimationRuntime;
|
|
118
|
+
|
|
119
|
+
interface PolyMorphControlRuntime {
|
|
120
|
+
readonly model: PolyMorphModel;
|
|
121
|
+
readonly controlIds: readonly string[];
|
|
122
|
+
readonly controls: ReadonlyMap<string, PolyMorphControl>;
|
|
123
|
+
}
|
|
124
|
+
interface PolyMorphControlState {
|
|
125
|
+
readonly tick: number;
|
|
126
|
+
readonly active: boolean;
|
|
127
|
+
readonly heldControlId: string | null;
|
|
128
|
+
readonly holdStartPoint: PolyMorphVec3 | null;
|
|
129
|
+
readonly holdStartValue: number;
|
|
130
|
+
readonly values: Readonly<Record<string, number>>;
|
|
131
|
+
readonly frozenControlIds: readonly string[];
|
|
132
|
+
}
|
|
133
|
+
interface PolyMorphControlInput {
|
|
134
|
+
readonly point: PolyMorphVec3 | null;
|
|
135
|
+
readonly active: boolean;
|
|
136
|
+
readonly freezeOnRelease?: boolean;
|
|
137
|
+
}
|
|
138
|
+
interface PolyMorphControlStep {
|
|
139
|
+
readonly state: PolyMorphControlState;
|
|
140
|
+
readonly pickedControlId: string | null;
|
|
141
|
+
readonly releasedControlId: string | null;
|
|
142
|
+
readonly heldTarget: Readonly<{
|
|
143
|
+
controlId: string;
|
|
144
|
+
value: number;
|
|
145
|
+
}> | null;
|
|
146
|
+
}
|
|
147
|
+
declare function createPolyMorphControlRuntime(modelInput: unknown): PolyMorphControlRuntime;
|
|
148
|
+
declare function createPolyMorphControlState(runtime: PolyMorphControlRuntime): PolyMorphControlState;
|
|
149
|
+
declare function pickPolyMorphControl(runtime: PolyMorphControlRuntime, inputPoint: PolyMorphVec3): string | null;
|
|
150
|
+
declare function stepPolyMorphControls(runtime: PolyMorphControlRuntime, state: PolyMorphControlState, input: PolyMorphControlInput): PolyMorphControlStep;
|
|
151
|
+
|
|
152
|
+
interface PolyMorphDeformationInput {
|
|
153
|
+
readonly tick: number;
|
|
154
|
+
readonly morphWeights?: Readonly<Record<string, number>>;
|
|
155
|
+
readonly controlValues?: Readonly<Record<string, number>>;
|
|
156
|
+
}
|
|
157
|
+
interface PolyMorphDeformationFrame {
|
|
158
|
+
readonly tick: number;
|
|
159
|
+
readonly positions: readonly PolyMorphVec3[];
|
|
160
|
+
readonly normals: readonly PolyMorphVec3[];
|
|
161
|
+
readonly morphWeights: Readonly<Record<string, number>>;
|
|
162
|
+
readonly controlValues: Readonly<Record<string, number>>;
|
|
163
|
+
readonly dirtyLeafIds: readonly string[];
|
|
164
|
+
readonly leafUpdates: readonly PolyMorphLeafUpdate[];
|
|
165
|
+
readonly runtimePolygonConstructions: 0;
|
|
166
|
+
readonly runtimeTopologyConstructions: 0;
|
|
167
|
+
readonly atlasRedraws: 0;
|
|
168
|
+
}
|
|
169
|
+
interface PolyMorphDeformationRuntime {
|
|
170
|
+
readonly model: PolyMorphModel;
|
|
171
|
+
readonly targetIds: readonly string[];
|
|
172
|
+
readonly controlIds: readonly string[];
|
|
173
|
+
readonly basePositions: readonly PolyMorphVec3[];
|
|
174
|
+
readonly baseNormals: readonly PolyMorphVec3[];
|
|
175
|
+
sample(input: PolyMorphDeformationInput): PolyMorphDeformationFrame;
|
|
176
|
+
reset(): void;
|
|
177
|
+
}
|
|
178
|
+
interface PolyMorphPreparedLeafMatrix {
|
|
179
|
+
readonly leafId: string;
|
|
180
|
+
readonly matrix: PolyMorphMat4 | null;
|
|
181
|
+
readonly visible: boolean;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
declare function createPolyMorphDeformationRuntime(modelInput: unknown): PolyMorphDeformationRuntime;
|
|
185
|
+
|
|
186
|
+
interface PolyMorphPreparedShapeState {
|
|
187
|
+
readonly shapeId: string;
|
|
188
|
+
readonly matrix: PolyMorphMat4;
|
|
189
|
+
}
|
|
190
|
+
interface PolyMorphPreparedLeafState {
|
|
191
|
+
readonly leafId: string;
|
|
192
|
+
readonly matrix: PolyMorphMat4;
|
|
193
|
+
readonly visible: boolean;
|
|
194
|
+
readonly opacity: number;
|
|
195
|
+
readonly atlasRow: number;
|
|
196
|
+
}
|
|
197
|
+
interface PolyMorphPreparedState {
|
|
198
|
+
readonly modelMatrix: PolyMorphMat4;
|
|
199
|
+
readonly shapes: readonly PolyMorphPreparedShapeState[];
|
|
200
|
+
readonly leaves: readonly PolyMorphPreparedLeafState[];
|
|
201
|
+
}
|
|
202
|
+
interface PolyMorphPreparedStateDiff {
|
|
203
|
+
readonly update: PolyMorphRetainedUpdate;
|
|
204
|
+
readonly modelChanged: boolean;
|
|
205
|
+
readonly dirtyShapeIds: readonly string[];
|
|
206
|
+
readonly dirtyLeafIds: readonly string[];
|
|
207
|
+
}
|
|
208
|
+
declare function createPolyMorphPreparedState(modelInput: unknown): PolyMorphPreparedState;
|
|
209
|
+
declare function applyPolyMorphPlaybackFrame(state: PolyMorphPreparedState, frame: PolyMorphPlaybackFrame): PolyMorphPreparedState;
|
|
210
|
+
declare function diffPolyMorphPreparedStates(previous: PolyMorphPreparedState, next: PolyMorphPreparedState): PolyMorphPreparedStateDiff;
|
|
211
|
+
|
|
212
|
+
interface PolyMorphPlaybackSample {
|
|
213
|
+
readonly requestedTimeMs: number;
|
|
214
|
+
readonly sampledTimeMs: number;
|
|
215
|
+
readonly frameIndex: number;
|
|
216
|
+
readonly state: PolyMorphPreparedState;
|
|
217
|
+
readonly update: PolyMorphRetainedUpdate;
|
|
218
|
+
readonly modelChanged: boolean;
|
|
219
|
+
readonly dirtyShapeIds: readonly string[];
|
|
220
|
+
readonly dirtyLeafIds: readonly string[];
|
|
221
|
+
readonly domCreations: 0;
|
|
222
|
+
readonly domRemovals: 0;
|
|
223
|
+
readonly topologyConstructions: 0;
|
|
224
|
+
readonly atlasConstructions: 0;
|
|
225
|
+
readonly atlasRedraws: 0;
|
|
226
|
+
readonly schedulerCallbacks: 0;
|
|
227
|
+
}
|
|
228
|
+
interface PolyMorphPlaybackRuntime {
|
|
229
|
+
readonly model: PolyMorphModel;
|
|
230
|
+
readonly durationMs: number;
|
|
231
|
+
readonly loop: boolean;
|
|
232
|
+
readonly frameCount: number;
|
|
233
|
+
sample(timeMs: number): PolyMorphPlaybackSample;
|
|
234
|
+
commit(sample: PolyMorphPlaybackSample): void;
|
|
235
|
+
reset(): void;
|
|
236
|
+
}
|
|
237
|
+
declare function createPolyMorphPlaybackRuntime(modelInput: unknown): PolyMorphPlaybackRuntime;
|
|
238
|
+
|
|
239
|
+
declare const POLY_MORPH_EXECUTABLE_PROFILES: readonly ["joint-skin", "morph-regions", "prepared-playback", "static-prepared"];
|
|
240
|
+
|
|
241
|
+
declare class PolyMorphRuntimeError extends Error {
|
|
242
|
+
readonly code: string;
|
|
243
|
+
readonly path: string;
|
|
244
|
+
constructor(code: string, path: string, message: string);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
interface PolyMorphSkinningInput {
|
|
248
|
+
readonly tick: number;
|
|
249
|
+
readonly jointTransforms?: ReadonlyMap<string, PolyMorphJointAnimationSample>;
|
|
250
|
+
}
|
|
251
|
+
interface PolyMorphSkinningFrame {
|
|
252
|
+
readonly tick: number;
|
|
253
|
+
readonly positions: readonly PolyMorphVec3[];
|
|
254
|
+
readonly normals: readonly PolyMorphVec3[];
|
|
255
|
+
readonly globalJointMatrices: ReadonlyMap<string, PolyMorphMat4>;
|
|
256
|
+
readonly skinMatrices: ReadonlyMap<string, PolyMorphMat4>;
|
|
257
|
+
readonly dirtyLeafIds: readonly string[];
|
|
258
|
+
readonly leafUpdates: readonly PolyMorphLeafUpdate[];
|
|
259
|
+
readonly runtimePolygonConstructions: 0;
|
|
260
|
+
readonly runtimeTopologyConstructions: 0;
|
|
261
|
+
readonly atlasRedraws: 0;
|
|
262
|
+
}
|
|
263
|
+
interface PolyMorphSkinningRuntime {
|
|
264
|
+
readonly model: PolyMorphModel;
|
|
265
|
+
readonly jointIds: readonly string[];
|
|
266
|
+
readonly basePositions: readonly PolyMorphVec3[];
|
|
267
|
+
readonly baseNormals: readonly PolyMorphVec3[];
|
|
268
|
+
sample(input: PolyMorphSkinningInput): PolyMorphSkinningFrame;
|
|
269
|
+
sampleClip(clipId: string, timeMs: number, tick: number): PolyMorphSkinningFrame;
|
|
270
|
+
reset(): void;
|
|
271
|
+
}
|
|
272
|
+
declare function createPolyMorphSkinningRuntime(modelInput: unknown): PolyMorphSkinningRuntime;
|
|
273
|
+
|
|
274
|
+
interface PolyMorphSpringRuntime {
|
|
275
|
+
readonly model: PolyMorphModel;
|
|
276
|
+
readonly controlIds: readonly string[];
|
|
277
|
+
readonly controls: ReadonlyMap<string, PolyMorphControl>;
|
|
278
|
+
readonly springs: ReadonlyMap<string, PolyMorphSpring>;
|
|
279
|
+
}
|
|
280
|
+
interface PolyMorphSpringState {
|
|
281
|
+
readonly tick: number;
|
|
282
|
+
readonly values: Readonly<Record<string, number>>;
|
|
283
|
+
readonly velocities: Readonly<Record<string, number>>;
|
|
284
|
+
readonly atRest: boolean;
|
|
285
|
+
}
|
|
286
|
+
interface PolyMorphSpringStepOptions {
|
|
287
|
+
readonly deltaMs: number;
|
|
288
|
+
readonly heldTarget?: Readonly<{
|
|
289
|
+
controlId: string;
|
|
290
|
+
value: number;
|
|
291
|
+
}> | null;
|
|
292
|
+
readonly frozenControlIds?: readonly string[];
|
|
293
|
+
}
|
|
294
|
+
declare function createPolyMorphSpringRuntime(modelInput: unknown): PolyMorphSpringRuntime;
|
|
295
|
+
declare function createPolyMorphSpringState(runtime: PolyMorphSpringRuntime, values?: Readonly<Record<string, number>>): PolyMorphSpringState;
|
|
296
|
+
declare function stepPolyMorphSprings(runtime: PolyMorphSpringRuntime, state: PolyMorphSpringState, options: PolyMorphSpringStepOptions): PolyMorphSpringState;
|
|
297
|
+
|
|
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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var xe="polycss-morph.model@1",ce="polycss-morph.catalog@1",pe="polycss-morph.package@1";var so=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Vo=/^[a-z0-9][a-z0-9._-]*$/,io=/^\d+\.\d+\.\d+$/,Eo=/^[a-f0-9]{64}$/,Uo=new Set(["joint-skin","morph-regions","prepared-playback","static-prepared"]),Bo=new Set(["animation","joint-skinning","morph-targets","prepared-playback","retained-render","semantic-controls","sparse-updates","springs"]),_o=new Set(["atlas-slice","direct-image","solid-quad","solid-triangle"]),Fo=new Set(["control-value","joint-rotation","joint-scale","joint-translation","morph-weight","shape-matrix"]),Oe=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 Oe(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 K(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 Ee(o,e){return typeof o!="boolean"&&f("invalid-boolean",e,"expected a boolean"),o}function N(o,e){let t=Z(o,e);return so.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 he(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 ae(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 lo(o,e){let t=Z(o,e);return t.split("/").some(n=>!Vo.test(n))&&f("invalid-path",e,"expected lowercase URL-safe package path segments"),t}function Ae(o,e,t){let n=K(o,e);return n>=t&&f("out-of-range",e,`expected an index below ${t}`),n}function Ho(o,e){let t=A(o,e,["normals","polygons","vertices"]),n=L(t.vertices,`${e}.vertices`).map((i,s)=>he(i,`${e}.vertices[${s}]`)),r=L(t.normals,`${e}.normals`).map((i,s)=>he(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)=>Ae(y,`${d}.vertexIndices[${b}]`,n.length)),p=L(l.normalIndices,`${d}.normalIndices`).map((y,b)=>Ae(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 No(o,e,t){let n=A(o,e,["atlas","fallback","height","id","materialId","matrix","polygonId","shapeId","strategy","width"]),r=Z(n.strategy,`${e}.strategy`);_o.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:co(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:Do(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:ae(n.matrix,`${e}.matrix`),atlas:p,fallback:y}}function Do(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=co(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:ae(t.matrixFromLeaf,`${e}.matrixFromLeaf`),atlas:a}}function co(o,e){let t=A(o,e,["height","pageHeight","pageWidth","resourcePath","width","x","y"]),n={resourcePath:lo(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)&&f("out-of-range",e,"slice must fit inside its page"),n}function qo(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:he(M.position,`${u}.position`),h=M.normal===null?null:he(M.normal,`${u}.normal`);return $===null&&h===null&&f("empty-delta",u,"expected a position or normal delta"),{vertexIndex:Ae(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:ae(y.restMatrix,`${p}.restMatrix`),inverseBindMatrix:ae(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`),Jo(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=Ae(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 Jo(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 Wo(o){return o==="control-value"||o==="morph-weight"?1:o==="joint-rotation"?4:o==="shape-matrix"?16:3}function Yo(o,e,t,n){let r=A(o,e,["interpolation","target","targetId","timesMs","values"]),a=Z(r.target,`${e}.target`);Fo.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=Wo(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 Go(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:ae(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:ae(h.matrix,`${$}.matrix`),visible:h.visible===null?null:Ee(h.visible,`${$}.visible`),opacity:I,atlasRow:h.atlasRow===null?null:K(h.atlasRow,`${$}.atlasRow`)}});return G(b.map(u=>u.leafId),`${l}.leaves`),{timeMs:p,modelMatrix:c.modelMatrix===null?null:ae(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:Ee(r.loop,`${e}.loop`),frames:i}}function Qo(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!==xe&&f("invalid-schema","$.schema",`expected ${xe}`);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")};io.test(r.revision)||f("invalid-revision","$.identity.revision","expected x.y.z");let a=Z(t.profile,"$.profile");Uo.has(a)||f("invalid-profile","$.profile",a);let i=L(t.capabilities,"$.capabilities").map((P,C)=>{let m=Z(P,`$.capabilities[${C}]`);return Bo.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: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=Ho(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:ae(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)=>No(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:ae(p.modelMatrix,"$.render.modelMatrix"),shapes:y,leaves:b},M=qo(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=he(S.anchor,`${m}.anchor`),ee=he(S.axis,`${m}.axis`);Math.hypot(...ee)<1e-9&&f("invalid-control-axis",`${m}.axis`,"axis must be non-zero");let ue=J(S.radius,`${m}.radius`);ue<=0&&f("invalid-control-radius",`${m}.radius`,"radius must be positive");let fe=L(S.targets,`${m}.targets`).map((de,be)=>{let j=`${m}.targets[${be}]`,Q=A(de,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(fe.map(de=>de.targetId),`${m}.targets`),{id:N(S.id,`${m}.id`),anchor:q,axis:ee,radius:ue,minimum:g,maximum:R,initial:z,targets:fe}});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)=>Yo(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:Ee(S.loop,`${m}.loop`),channels:R}});G(w.map(P=>P.id),"$.animations");let W=t.playback===null?null:Go(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&&!Eo.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 te={generator:N(V.generator,"$.provenance.generator"),generatorVersion:Z(V.generatorVersion,"$.provenance.generatorVersion"),sources:B};io.test(te.generatorVersion)||f("invalid-revision","$.provenance.generatorVersion","expected x.y.z");let O=Qo(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:xe,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:te}}function Ue(o){return so.test(o)}function Be(o){try{return lo(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 _e(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)=>_e(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)}:${_e(s,`${e}.${i}`,t)}`}).join(",")}}`;return t.delete(o),a}throw new k("invalid-json",e,"value is not JSON")}function po(o){return _e(o,"$",new WeakSet)}function $e(o){return new TextEncoder().encode(po(o))}function ve(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 Ko=/^[a-f0-9]{64}$/,Xo=/^\d+\.\d+\.\d+$/,Zo=/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/,et=new Set(["joint-skin","morph-regions","prepared-playback","static-prepared"]),ot=new Set(["data","image","model"]);function F(o,e,t){throw new k(o,e,t)}function we(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 yo(o,e){return Array.isArray(o)||F("invalid-type",e,"expected an array"),o}function se(o,e){return(typeof o!="string"||o.length===0)&&F("invalid-string",e,"expected a non-empty string"),o}function He(o,e){let t=se(o,e);return Ue(t)||F("invalid-id",e,"expected a normalized kebab-case id"),t}function Ne(o,e){let t=se(o,e);return Be(t)||F("invalid-path",e,"expected a normalized package-relative path"),t}function mo(o,e){let t=se(o,e);return Xo.test(t)||F("invalid-revision",e,"expected x.y.z"),t}function uo(o,e){let t=se(o,e);return et.has(t)||F("invalid-profile",e,t),t}function fo(o,e){let t=se(o,e);return Ko.test(t)||F("invalid-hash",e,"expected lowercase SHA-256"),t}function tt(o,e){return(typeof o!="number"||!Number.isSafeInteger(o)||o<0)&&F("invalid-bytes",e,"expected a non-negative safe integer"),o}function nt(o,e){let t=we(o,e,["bytes","mediaType","path","role","sha256"]),n=se(t.role,`${e}.role`);ot.has(n)||F("invalid-role",`${e}.role`,n);let r=se(t.mediaType,`${e}.mediaType`).toLowerCase();return(!Zo.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:Ne(t.path,`${e}.path`),role:n,mediaType:r,bytes:tt(t.bytes,`${e}.bytes`),sha256:fo(t.sha256,`${e}.sha256`)}}function Fe(o,e){let t=new Set;for(let n of o)t.has(n)&&F("duplicate",e,n),t.add(n)}function ho(o,e){o.some((t,n)=>n>0&&t<=o[n-1])&&F("non-canonical-order",e,"entries must be unique and sorted")}function ke(o){let e=we(o,"$",["identity","modelPath","profile","resources","schema"]);e.schema!==pe&&F("invalid-schema","$.schema",`expected ${pe}`);let t=we(e.identity,"$.identity",["id","name","revision"]),n={id:He(t.id,"$.identity.id"),name:se(t.name,"$.identity.name"),revision:mo(t.revision,"$.identity.revision")},r=yo(e.resources,"$.resources").map((d,l)=>nt(d,`$.resources[${l}]`));r.length===0&&F("missing-resource","$.resources","expected at least the model resource");let a=r.map(d=>d.path);Fe(a,"$.resources"),ho(a,"$.resources");let i=Ne(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:pe,identity:n,profile:uo(e.profile,"$.profile"),modelPath:i,resources:r}}function rt(o,e){let t=we(o,e,["id","manifestPath","manifestSha256","name","profile","revision"]),n=Ne(t.manifestPath,`${e}.manifestPath`);return n.endsWith("/manifest.json")||F("invalid-manifest-path",`${e}.manifestPath`,"expected a package manifest.json path"),{id:He(t.id,`${e}.id`),name:se(t.name,`${e}.name`),revision:mo(t.revision,`${e}.revision`),profile:uo(t.profile,`${e}.profile`),manifestPath:n,manifestSha256:fo(t.manifestSha256,`${e}.manifestSha256`)}}function Ie(o){let e=we(o,"$",["defaultId","packages","schema"]);e.schema!==ce&&F("invalid-schema","$.schema",`expected ${ce}`);let t=yo(e.packages,"$.packages").map((a,i)=>rt(a,`$.packages[${i}]`));t.length===0&&F("missing-package","$.packages","expected at least one package");let n=t.map(a=>a.id);Fe(n,"$.packages"),ho(n,"$.packages"),Fe(t.map(a=>a.manifestPath),"$.packages[*].manifestPath");let r=He(e.defaultId,"$.defaultId");return n.includes(r)||F("unknown-default","$.defaultId",r),{schema:ce,defaultId:r,packages:t}}var De="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 it(o,e=[]){let t=D(o),n=$e(t),r=new Map([[De,n]]),a=[{path:De,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 at(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=ke({schema:pe,identity:t.identity,profile:t.profile,modelPath:De,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=$e(i);return{manifest:i,manifestBytes:d,manifestSha256:await ie(d),files:r}}async function st(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=Ie({schema:ce,defaultId:o,packages:t}),r=$e(n);return{catalog:n,bytes:r,sha256:await ie(r)}}function qe(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 Mo=64*1024*1024,lt=1024,dt=128*1024*1024,Po=3e4;function ge(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 bo(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 ct(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 Je(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 ct(i,e.pathname,t)}async function go(o,e,t){let n=await ie(o);if(n!==e)throw new k("stale-hash",t,`expected ${e}, received ${n}`)}function pt(o,e){let t=e.lastIndexOf("/");return Le(o,e.slice(0,t+1))}function Le(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 xo(o,e={}){let t=bo(o),n=ge(e.maxResourceBytes,Mo,"$.maxResourceBytes"),r=e.fetchImpl??globalThis.fetch;if(typeof r!="function")throw new k("missing-fetch","$.fetchImpl","a fetch implementation is required");let a=ge(e.requestTimeoutMs,Po,"$.requestTimeoutMs"),i=await Je(r,Le(t,"catalog.json"),n,e.signal,a);return{catalog:Ie(ve(i,"$.catalog")),bytes:i,sha256:await ie(i)}}async function yt(o,e={}){let t=bo(o),n=ge(e.maxResourceBytes,Mo,"$.maxResourceBytes"),r=ge(e.maxResources,lt,"$.maxResources"),a=ge(e.maxTotalBytes,dt,"$.maxTotalBytes"),i=ge(e.requestTimeoutMs,Po,"$.requestTimeoutMs"),s=e.fetchImpl??globalThis.fetch;if(typeof s!="function")throw new k("missing-fetch","$.fetchImpl","a fetch implementation is required");let d=await xo(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 Je(s,Le(t,c.manifestPath),n,e.signal,i);await go(p,c.manifestSha256,c.manifestPath);let y=ke(ve(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=pt(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 Je(s,Le(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 go(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(ve(v.bytes,"$.model"));if(qe(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}}import{buildPolyCameraSceneTransform as $o,capturePolyCameraSnapshot as vo,createPolyCamera as mt,formatMatrix3dValues as ut,injectPolyBaseStyles as ft,isSolidTriangleSupported as ht}from"@layoutit/polycss";var Re=class extends Error{constructor(e,t,n){super(`${t}: ${n}`),this.name="PolyMorphRenderError",this.code=e,this.path=t}};var gt={"atlas-slice":"s","direct-image":"s","solid-quad":"b","solid-triangle":"u"};function U(o,e,t){throw new Re(o,e,t)}function Ye(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 ye(o){return`matrix3d(${ut(o)})`}function Mt(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 We(o,e,t){return t&&o.fallback?Mt(e,o.fallback.matrixFromLeaf):e}function Pt(o){let[e,t,n,r]=o;return`rgba(${Math.round(e*255)}, ${Math.round(t*255)}, ${Math.round(n*255)}, ${r})`}function Ge(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 wo(o,e){let t=new Set;for(let n of o)t.has(n)&&U("duplicate-update",e,n),t.add(n)}function bt(o,e){let t=Ge(o,e,["matrix","shapeId"]);return typeof t.shapeId!="string"&&U("invalid-update",`${e}.shapeId`,"expected a string"),{shapeId:t.shapeId,matrix:Ye(t.matrix,`${e}.matrix`)}}function xt(o,e){let t=Ge(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=Ye(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 $t(o){let e=Ge(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)=>bt(a,`$.shapes[${i}]`));return wo(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)=>xt(a,`$.leaves[${i}]`));return wo(r.map(a=>a.leafId),"$.leaves"),r})();return{...e.modelMatrix===void 0?{}:{modelMatrix:Ye(e.modelMatrix,"$.modelMatrix")},...t===void 0?{}:{shapes:t},...n===void 0?{}:{leaves:n}}}function vt(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 wt(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 kt(o,e,t,n,r){let a=r?e.fallback:null,i=o.createElement(a?"s":gt[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=ye(We(e,e.matrix,a!==null)),i.style.color=Pt(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`,vt(i,e,e.atlas,n(e.atlas.resourcePath,e.id))):a?wt(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 It(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")&&!ht(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(),le=s.createObjectURL(new d([ee.buffer],{type:q.descriptor.mediaType}));return i.set(g,le),le};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}ft(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??mt({zoom:1}),M=r.createElement("div");M.className="polycss-camera polycss-morph-camera";let $=vo(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=$o(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=ye(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=ye(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=kt(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:ye(We(g,g.matrix,a&&g.strategy==="solid-triangle")),visible:!0,opacity:1,atlasRow:0})}let te=[...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!==te.length||V.size!==O.length)&&U("identity-drift","$","retained handle maps changed");for(let[g,R]of te)(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=$t(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 Ce;if(j.atlasRow!==void 0){let oe=Q.plan.atlas;oe||U("invalid-atlas-row",j.leafId,"leaf has no image rows");let ao=oe.y+j.atlasRow*oe.height;ao+oe.height>oe.pageHeight&&U("invalid-atlas-row",j.leafId,"row exceeds the image page"),Ce=`${-oe.x}px ${-ao}px`}return{leaf:j,handle:Q,state:Y,atlasPosition:Ce}});C();let ee=0,le=0,ue=0,fe=0,de=0,be=0;if(R.modelMatrix){let j=ye(R.modelMatrix);E!==j&&(E=j,I.style.transform=j,ee+=1)}for(let{shape:j,element:Q}of z){let Y=ye(j.matrix);w.get(j.shapeId)!==Y&&(w.set(j.shapeId,Y),Q.style.transform=Y,le+=1)}for(let{leaf:j,handle:Q,state:Y,atlasPosition:Ce}of q){if(j.matrix){let oe=ye(We(Q.plan,j.matrix,a&&Q.plan.strategy==="solid-triangle"));Y.transform!==oe&&(Y.transform=oe,Q.element.style.transform=oe,ue+=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,fe+=1)}if(j.opacity!==void 0){let oe=String(j.opacity);Y.opacity!==j.opacity&&(Y.opacity=j.opacity,Q.element.style.opacity=oe,de+=1)}j.atlasRow!==void 0&&Y.atlasRow!==j.atlasRow&&(Y.atlasRow=j.atlasRow,Q.element.style.backgroundPosition=Ce,be+=1)}return C(),H.applyCount+=1,H.totalTransformWrites+=ee+le+ue,H.totalVisibilityWrites+=fe,H.totalOpacityWrites+=de,H.totalAtlasRowWrites+=be,{modelTransformWrites:ee,shapeTransformWrites:le,leafTransformWrites:ue,visibilityWrites:fe,opacityWrites:de,atlasRowWrites:be,dirtyLeavesVisited:R.leaves?.length??0,domCreations:0,domRemovals:0,topologyConstructions:0,atlasRedraws:0,schedulerCallbacks:0}},updateCamera(){P();let g=$o(u.state);if(_===g)return!1;_=g,h.style.transform=g;let R=vo(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 X=class extends Error{constructor(e,t,n){super(`${t}: ${n}`),this.name="PolyMorphRuntimeError",this.code=e,this.path=t}};function ko(o,e,t){throw new X(o,e,t)}function Te(o){return Object.freeze([...o])}function Rt(o,e){let{timesMs:t,values:n}=o;if(e<=t[0])return Te(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 Te(d);if(o.interpolation==="step")return Te(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 Te(n[n.length-1])}function St(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=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||ko("unknown-clip","$.clipId",n),(!Number.isFinite(r)||r<0)&&ko("invalid-time","$.timeMs","expected a finite non-negative time");let i=St(a,r),s={},d={},l=new Map,c=new Map;for(let p of a.channels){let y=Rt(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 Ke(o,e,t){throw new X(o,e,t)}function Io(o){return o===null?null:((!Array.isArray(o)||o.length!==3||o.some(e=>typeof e!="number"||!Number.isFinite(e)))&&Ke("invalid-point","$.point","expected three finite components or null"),[o[0],o[1],o[2]])}function jt(o){let e=Math.hypot(...o.axis);return[o.axis[0]/e,o.axis[1]/e,o.axis[2]/e]}function Ct(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 Ot(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 Ro(o,e){let t=Io(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 At(o,e,t){(!e||!Number.isSafeInteger(e.tick)||e.tick<-1)&&Ke("invalid-state","$.state","control state is invalid"),typeof t?.active!="boolean"&&Ke("invalid-input","$.active","expected a boolean");let n=Io(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=Ro(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=jt(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})}import{computeSolidTrianglePlanFromCssPoints as Co,SOLID_TRIANGLE_CANONICAL_SIZE as So}from"@layoutit/polycss";function ne(o,e,t){throw new X(o,e,t)}function Lt(o,e){return(typeof o!="number"||!Number.isFinite(o))&&ne("invalid-number",e,"expected a finite number"),Object.is(o,-0)?0:o}function Oo(o){let e=Math.hypot(...o);return e<=1e-12?[0,0,0]:[o[0]/e,o[1]/e,o[2]/e]}function ze(o){return o.map(e=>[e[0],e[1],e[2]])}function Ve(o){for(let e of o)Object.freeze(e);return Object.freeze(o)}function Tt(o,e){let[t,n,r]=o.vertexIndices,a=e[t],i=e[n],s=e[r],d=Co(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||ne("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)))&&ne("invalid-transform",o.leaf.id,"PolyCSS returned an invalid matrix3d");let p=So/o.leaf.width,y=So/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 zt(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&&ne("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=Oo(b);return Math.hypot(...u)<=1e-12&&ne("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 Xe(o,e){if(o.vertexIndices.length===3)return Tt(o,e);if(o.vertexIndices.length===4)return zt(o,e);ne("unsupported-deformation",o.leaf.id,"caller-driven deformation supports prepared triangles and affine quads")}function Ze(o,e){let t=o.topology.polygons.find(i=>i.id===e.polygonId);t||ne("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=Co(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||ne("degenerate-polygon",e.id,"base triangle has no area"),a=l.basis}return{leaf:e,vertexIndices:t.vertexIndices,polygon:r,basis:a}}function jo(o,e,t,n){let r=o??{};(!r||typeof r!="object"||Array.isArray(r))&&ne("invalid-input",t,"expected an object");let a=new Set(e),i=Object.keys(r).find(s=>!a.has(s));return i&&ne("unknown-id",t,i),Object.fromEntries(e.map(s=>{let[d,l]=n.get(s)??[0,1],c=Lt(r[s]??0,`${t}.${s}`);return(c<d||c>l)&&ne("out-of-range",`${t}.${s}`,`expected ${d} <= value <= ${l}`),[s,c]}))}function Vt(o){return new Map(o.deformation.kind==="morph-regions"?o.deformation.targets.map(e=>[e.id,e]):[])}function Et(o){let e=D(o);e.deformation.kind==="joint-skin"&&ne("profile-not-executable","$.profile","joint skin requires the skinning runtime");let t=Vt(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,Ze(e,h)])),p=Ve(ze(e.topology.vertices)),y=Ve(ze(e.topology.normals)),b=Object.fromEntries(n.map(h=>[h,0])),u=p,M=y,$=h=>{(!h||!Number.isSafeInteger(h.tick)||h.tick<0)&&ne("invalid-tick","$.tick","expected a non-negative safe integer");let v=jo(h.morphWeights,n,"$.morphWeights",a),I=jo(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=ze(p),T=ze(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(Oo),w=Ve(O),W=Ve(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)),te=B.map(O=>{let T=Xe(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(te),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 Se(o,e,t){throw new X(o,e,t)}function Me(o){return Object.freeze([...o])}function eo(o,e){return o.every((t,n)=>t===e[n])}function oo(o){let e=D(o);return Object.freeze({modelMatrix:Me(e.render.modelMatrix),shapes:Object.freeze(e.render.shapes.map(t=>Object.freeze({shapeId:t.id,matrix:Me(t.matrix)}))),leaves:Object.freeze(e.render.leaves.map(t=>Object.freeze({leafId:t.id,matrix:Me(t.matrix),visible:!0,opacity:1,atlasRow:0})))})}function to(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)||Se("unknown-shape","$.frame.shapes",r);for(let r of n.keys())o.leaves.some(a=>a.leafId===r)||Se("unknown-leaf","$.frame.leaves",r);return Object.freeze({modelMatrix:e.modelMatrix===null?o.modelMatrix:Me(e.modelMatrix),shapes:Object.freeze(o.shapes.map(r=>{let a=t.get(r.shapeId);return a?Object.freeze({shapeId:r.shapeId,matrix:Me(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:Me(a.matrix),visible:a.visible??r.visible,opacity:a.opacity??r.opacity,atlasRow:a.atlasRow??r.atlasRow}):r}))})}function no(o,e){(o.shapes.length!==e.shapes.length||o.leaves.length!==e.leaves.length)&&Se("state-mismatch","$","prepared state topology differs");let t=!eo(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&&Se("state-mismatch","$.shapes","source order differs"),eo(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&&Se("state-mismatch","$.leaves","source order differs");let d={leafId:s.leafId};eo(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 je(o,e,t){throw new X(o,e,t)}function Ut(o,e,t){if(e){let n=t%o;return Object.is(n,-0)?0:n}return Math.min(t,o)}function Bt(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 _t(o){let e=D(o);(e.profile!=="prepared-playback"||!e.playback)&&je("profile-mismatch","$.profile","playback requires the prepared-playback profile");let t=e.playback,n=oo(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||je("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&&je("invalid-atlas-row",`$.playback.frames[${p}]`,`${u.id} row exceeds its page`)}a=to(a,y),r.push(a)}let s=t.frames.map(p=>p.timeMs),d=n,l=null,c=p=>{(!Number.isFinite(p)||p<0)&&je("invalid-time","$.timeMs","expected a finite non-negative time");let y=Ut(t.durationMs,t.loop,p),b=Bt(s,y),u=r[b],M=no(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&&je("invalid-sample","$.sample","commit requires the latest unapplied playback sample"),d=p.state,l=null},reset(){d=n,l=null}})}var Ft=Object.freeze(["joint-skin","morph-regions","prepared-playback","static-prepared"]);function re(o,e,t){throw new X(o,e,t)}function Ht(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function ro(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 Nt(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)))&&re("invalid-quaternion",e,"expected four finite components");let t=Math.hypot(...o);return t<=1e-12&&re("invalid-quaternion",e,"quaternion must be non-zero"),[o[0]/t,o[1]/t,o[2]/t,o[3]/t]}function Ao(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)))&&re("invalid-vector",t,"expected three finite components"),n&&o.some(r=>r<=0)&&re("invalid-scale",t,"scale components must be positive"),[o[0],o[1],o[2]])}function zo(o,e){if(o===void 0)return Ht();(!o||typeof o!="object"||Array.isArray(o))&&re("invalid-joint-transform",e,"expected an object"),Object.keys(o).some(v=>v!=="translation"&&v!=="rotation"&&v!=="scale")&&re("invalid-joint-transform",e,"unknown transform field");let n=Ao(o.translation,[0,0,0],`${e}.translation`),r=Ao(o.scale,[1,1,1],`${e}.scale`,!0),[a,i,s,d]=Nt(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 Dt(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&&re("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 Jt(o){let e=Math.hypot(...o);return e<=1e-12?[0,0,0]:[o[0]/e,o[1]/e,o[2]/e]}function Pe(o){for(let e of o)Object.freeze(e);return Object.freeze(o)}function Wt(o,e){return o.every((t,n)=>Math.abs(t-e[n])<=1e-12)}function Lo(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=ro(a.restMatrix,zo(e.get(a.id),`$.jointTransforms.${a.id}`)),d=a.parentId===null?s:ro(r(t.get(a.parentId)),s);return n.set(a.id,d),d};for(let a of o)r(a);return n}function To(o,e){return new Map(o.map(t=>[t.id,ro(e.get(t.id),t.inverseBindMatrix)]))}function Yt(o,e){let t=o??new Map;(!t||typeof t.entries!="function")&&re("invalid-joint-transform","$.jointTransforms","expected a map");for(let[n,r]of t)e.has(n)||re("unknown-joint","$.jointTransforms",n),zo(r,`$.jointTransforms.${n}`);return t}function Gt(o){let e=D(o);e.deformation.kind!=="joint-skin"&&re("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=Lo(t.joints,new Map),i=To(t.joints,a),s=Pe(e.topology.vertices.map(w=>[...w])),d=Pe(e.topology.normals.map(w=>[...w])),l=new Map(e.render.leaves.map(w=>[w.id,Ze(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 te=y.get(B),O=[0,0,0],T=[0,0,0];for(let _ of te.influences){let H=w.get(_.jointId),P=Dt(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(Jt(T))}return{positions:W,normals:V}},u=b(i),M=Pe(u.positions),$=Pe(u.normals),h=new Map(i),v=M,I=$,E=Qe(e),x=w=>{(!w||!Number.isSafeInteger(w.tick)||w.tick<0)&&re("invalid-tick","$.tick","expected a non-negative safe integer");let W=Yt(w.jointTransforms,r),V=Lo(t.joints,W),B=To(t.joints,V),te=new Set(n.filter(m=>!Wt(B.get(m),h.get(m)))),O=v,T=I;if(te.size>0){let m=b(B);O=Pe(m.positions),T=Pe(m.normals)}let _=new Set;if(te.size>0)for(let m of t.vertices)m.influences.some(S=>te.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=Xe(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 me(o,e,t){throw new X(o,e,t)}function Qt(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 Kt(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 Xt(o,e){let t=Object.keys(e??{}).find(r=>!o.controls.has(r));t&&me("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)&&me("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 Zt(o,e,t){(!e||!Number.isSafeInteger(e.tick)||e.tick<-1)&&me("invalid-state","$.state","spring state is invalid"),(!Number.isFinite(t?.deltaMs)||t.deltaMs<=0||t.deltaMs>1e3)&&me("invalid-time","$.deltaMs","expected 0 < deltaMs <= 1000");let n=t.heldTarget??null;if(n){let l=o.controls.get(n.controlId);l||me("unknown-id","$.heldTarget.controlId",n.controlId),(!Number.isFinite(n.value)||n.value<l.minimum||n.value>l.maximum)&&me("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)||me("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,$]=Qt(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})}export{ce as POLY_MORPH_CATALOG_SCHEMA,Ft as POLY_MORPH_EXECUTABLE_PROFILES,xe as POLY_MORPH_MODEL_SCHEMA,pe as POLY_MORPH_PACKAGE_SCHEMA,Oe as PolyMorphContractError,k as PolyMorphPackageError,Re as PolyMorphRenderError,X as PolyMorphRuntimeError,to as applyPolyMorphPlaybackFrame,qe as assertPolyMorphPackageModelBinding,st as buildPolyMorphCatalog,it as buildPolyMorphPackage,Qe as createPolyMorphAnimationRuntime,Ct as createPolyMorphControlRuntime,Ot as createPolyMorphControlState,Et as createPolyMorphDeformationRuntime,_t as createPolyMorphPlaybackRuntime,oo as createPolyMorphPreparedState,Gt as createPolyMorphSkinningRuntime,Kt as createPolyMorphSpringRuntime,Xt as createPolyMorphSpringState,ve as decodePolyMorphJson,no as diffPolyMorphPreparedStates,$e as encodePolyMorphCanonicalJson,ie as hashPolyMorphBytes,Ue as isPolyMorphId,Be as isPolyMorphResourcePath,xo as loadPolyMorphCatalog,yt as loadPolyMorphPackage,It as mountPolyMorphModel,Ro as pickPolyMorphControl,At as stepPolyMorphControls,Zt as stepPolyMorphSprings,po as stringifyPolyMorphCanonicalJson,Ie as validatePolyMorphCatalog,D as validatePolyMorphModel,ke as validatePolyMorphPackageManifest};
|