@haiyue/animation-spec 0.1.0 → 0.2.0

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.
Files changed (77) hide show
  1. package/README.md +40 -6
  2. package/SPECIFICATION.md +12 -2
  3. package/bin/hya-live2d-convert.mjs +76 -0
  4. package/bin/{hya-convert.mjs → hya-lottie-convert.mjs} +1 -1
  5. package/dist/chunks/binary-DvuTJ_hy.js +1 -0
  6. package/dist/chunks/clip-baked-Dv-wjX9d.js +1 -0
  7. package/dist/chunks/errors-Bzs3GOD9.js +1 -0
  8. package/dist/chunks/expression-D1cKtNwM.js +1 -0
  9. package/dist/chunks/extensions-DxL4AxOC.js +1 -0
  10. package/dist/conversion.d.ts +1 -0
  11. package/dist/conversion.js +1 -0
  12. package/dist/cubism.d.ts +1 -0
  13. package/dist/cubism.js +1 -0
  14. package/dist/deformable2d.d.ts +1 -0
  15. package/dist/deformable2d.js +1 -0
  16. package/dist/index.d.ts +1 -10
  17. package/dist/index.js +1 -2927
  18. package/dist/live2d/clip-baked.d.ts +1 -0
  19. package/dist/live2d/clip-baked.js +1 -0
  20. package/dist/live2d.d.ts +1 -0
  21. package/dist/live2d.js +1 -0
  22. package/dist/lottie.d.ts +1 -62
  23. package/dist/lottie.js +1 -2642
  24. package/dist/native3d.d.ts +1 -2
  25. package/dist/native3d.js +1 -907
  26. package/dist/shared.d.ts +1493 -0
  27. package/package.json +30 -10
  28. package/schema/animation.schema.json +92 -0
  29. package/schema/deformable-mesh-2d-extension.schema.json +18 -0
  30. package/schema/deformable-mesh-2d.contract.json +58 -0
  31. package/schema/parameterized-rig-2d.contract.json +63 -0
  32. package/schema/parameterized-rig-2d.schema.json +57 -0
  33. package/schema/parameterized-rig-census-map.json +128 -0
  34. package/schema/responsive-layout-2d-census-map.json +49 -0
  35. package/schema/responsive-layout-2d.contract.json +58 -0
  36. package/schema/responsive-layout-2d.schema.json +34 -0
  37. package/schema/state-machine-v2-census-map.json +1 -0
  38. package/schema/state-machine-v2.contract.json +66 -0
  39. package/schema/state-machine-v2.schema.json +55 -0
  40. package/schema/vector-visual-census-map.json +120 -0
  41. package/schema/vector-visual.contract.json +47 -0
  42. package/schema/vector-visual.schema.json +72 -0
  43. package/dist/binary.d.ts +0 -7
  44. package/dist/chunks/types-l6nBVYwx.js +0 -8
  45. package/dist/chunks/types-l6nBVYwx.js.map +0 -1
  46. package/dist/errors.d.ts +0 -7
  47. package/dist/extensions.d.ts +0 -19
  48. package/dist/index.js.map +0 -1
  49. package/dist/lottie-merge-path.d.ts +0 -11
  50. package/dist/lottie.js.map +0 -1
  51. package/dist/native3d/Animation3DError.d.ts +0 -8
  52. package/dist/native3d/Animation3DParser.d.ts +0 -7
  53. package/dist/native3d/Animation3DTypes.d.ts +0 -285
  54. package/dist/native3d/index.d.ts +0 -5
  55. package/dist/native3d.js.map +0 -1
  56. package/dist/parser.d.ts +0 -2
  57. package/dist/state-machine.d.ts +0 -130
  58. package/dist/text-selector.d.ts +0 -2
  59. package/dist/types.d.ts +0 -419
  60. package/dist/validation.d.ts +0 -32
  61. package/src/binary.ts +0 -1441
  62. package/src/errors.ts +0 -18
  63. package/src/extensions.ts +0 -55
  64. package/src/index.ts +0 -90
  65. package/src/lottie-merge-path.ts +0 -204
  66. package/src/lottie.ts +0 -3073
  67. package/src/native3d/Animation3DError.ts +0 -20
  68. package/src/native3d/Animation3DParser.ts +0 -964
  69. package/src/native3d/Animation3DTypes.ts +0 -322
  70. package/src/native3d/index.ts +0 -14
  71. package/src/native3d.ts +0 -2
  72. package/src/parser.ts +0 -41
  73. package/src/state-machine.ts +0 -645
  74. package/src/text-selector.ts +0 -7
  75. package/src/types.ts +0 -483
  76. package/src/validation.ts +0 -1286
  77. package/test/fixtures/basic-lottie.json +0 -31
package/dist/native3d.js CHANGED
@@ -1,907 +1 @@
1
- import { AnimationExtensionRegistry, parseAnimation } from './index.js';
2
- import './chunks/types-l6nBVYwx.js';
3
-
4
- const NATIVE_3D_ANIMATION_EXTENSION_ID = 'org.haiyue.animation-3d@1';
5
- const NATIVE_3D_ANIMATION_FORMAT = 'haiyue-animation-3d@1';
6
- const NATIVE_3D_CLIP_FORMAT = 'haiyue-animation3d-clip@1';
7
- const NATIVE_3D_STATE_MACHINE_FORMAT = 'haiyue-animation3d-state-machine@1';
8
-
9
- /** Stable native-3D extension diagnostic. */
10
- class Native3DAnimationFormatError extends Error {
11
- code;
12
- path;
13
- name = 'Native3DAnimationFormatError';
14
- constructor(code, message, path) {
15
- super(`${message} (${path})`);
16
- this.code = code;
17
- this.path = path;
18
- }
19
- }
20
-
21
- const EXTENSION_PATH = `$.extensions.${NATIVE_3D_ANIMATION_EXTENSION_ID}`;
22
- const MODEL_MIME_TYPES = new Set(['model/gltf-binary', 'model/gltf+json']);
23
- const FORBIDDEN_URI_SCHEMES = new Set(['blob', 'file', 'javascript']);
24
- const DEFAULT_LIMITS = Object.freeze({
25
- maxMaterials: 10_000,
26
- maxNodes: 100_000,
27
- maxComponents: 200_000,
28
- maxClips: 10_000,
29
- maxTracks: 200_000,
30
- maxKeyframes: 5_000_000,
31
- maxParticleCapacity: 2_000_000,
32
- maxStateMachineDepth: 64,
33
- });
34
- function createNative3DAnimationExtensionHandler(options = {}, onValidated) {
35
- return Object.freeze({
36
- id: NATIVE_3D_ANIMATION_EXTENSION_ID,
37
- validateDocument(value) {
38
- onValidated?.(parseNative3DAnimationPayload(value, options));
39
- },
40
- });
41
- }
42
- /** Parses the required 3D extension and rejects mixed 2D/3D carriers. */
43
- function parseNative3DAnimation(source, options = {}) {
44
- const extensions = new AnimationExtensionRegistry();
45
- let payload;
46
- extensions.register(createNative3DAnimationExtensionHandler(options, value => { payload = value; }));
47
- const coreOptions = {
48
- ...pickCoreLimits(options),
49
- extensions,
50
- ...(options.copyFloatData === undefined ? {} : { copyFloatData: options.copyFloatData }),
51
- };
52
- const document = parseAnimation(source, coreOptions);
53
- if (!payload) {
54
- throw new Native3DAnimationFormatError('E_ANIMATION_3D_INVALID_PAYLOAD', `Required extension "${NATIVE_3D_ANIMATION_EXTENSION_ID}" has no document payload.`, EXTENSION_PATH);
55
- }
56
- validateCarrier(document, payload);
57
- validateResourceReferences(document.resources, payload);
58
- return Object.freeze({ document, payload, resources: document.resources });
59
- }
60
- /** Validates and canonicalizes the extension before any runtime allocation. */
61
- function parseNative3DAnimationPayload(value, options = {}) {
62
- const limits = resolveLimits(options);
63
- const root = object(value, EXTENSION_PATH, [
64
- 'format', 'mode', 'coordinateSystem', 'viewport', 'materials', 'nodes', 'clips',
65
- ], ['format', 'mode', 'coordinateSystem', 'viewport', 'materials', 'nodes', 'clips', 'stateMachine']);
66
- exact(root.format, NATIVE_3D_ANIMATION_FORMAT, `${EXTENSION_PATH}.format`);
67
- exact(root.mode, 'native-3d', `${EXTENSION_PATH}.mode`);
68
- const coordinateSystem = parseCoordinateSystem(root.coordinateSystem, `${EXTENSION_PATH}.coordinateSystem`);
69
- const viewport = parseViewport(root.viewport, `${EXTENSION_PATH}.viewport`);
70
- const materialValues = array(root.materials, `${EXTENSION_PATH}.materials`);
71
- budget(materialValues.length, limits.maxMaterials, 'materials', `${EXTENSION_PATH}.materials`);
72
- const materialIds = new Set();
73
- const materials = materialValues.map((entry, index) => {
74
- const material = parseMaterial(entry, `${EXTENSION_PATH}.materials[${index}]`);
75
- unique(materialIds, material.id, `${EXTENSION_PATH}.materials[${index}].id`, 'material');
76
- return material;
77
- });
78
- const nodeValues = array(root.nodes, `${EXTENSION_PATH}.nodes`);
79
- budget(nodeValues.length, limits.maxNodes, 'nodes', `${EXTENSION_PATH}.nodes`);
80
- const nodeIds = new Set();
81
- const componentIds = new Set();
82
- let componentCount = 0;
83
- let particleCapacity = 0;
84
- const nodes = nodeValues.map((entry, index) => {
85
- const path = `${EXTENSION_PATH}.nodes[${index}]`;
86
- const node = parseNode(entry, path);
87
- unique(nodeIds, node.id, `${path}.id`, 'node');
88
- for (let componentIndex = 0; componentIndex < node.components.length; componentIndex++) {
89
- const component = node.components[componentIndex];
90
- unique(componentIds, component.id, `${path}.components[${componentIndex}].id`, 'component');
91
- componentCount++;
92
- if (component.kind === 'particle3d')
93
- particleCapacity += component.descriptor.maxParticles;
94
- }
95
- budget(componentCount, limits.maxComponents, 'components', `${path}.components`);
96
- budget(particleCapacity, limits.maxParticleCapacity, 'particle capacity', `${path}.components`);
97
- return node;
98
- });
99
- validateNodeSemantics(nodes, nodeIds, materialIds);
100
- const clipValues = array(root.clips, `${EXTENSION_PATH}.clips`);
101
- budget(clipValues.length, limits.maxClips, 'clips', `${EXTENSION_PATH}.clips`);
102
- const clipIds = new Set();
103
- const bindingIds = new Set();
104
- let trackCount = 0;
105
- let keyframeCount = 0;
106
- const clips = clipValues.map((entry, index) => {
107
- const path = `${EXTENSION_PATH}.clips[${index}]`;
108
- const clip = parseClip(entry, path);
109
- unique(clipIds, clip.id, `${path}.id`, 'clip');
110
- trackCount += clip.tracks.length;
111
- keyframeCount += clip.tracks.reduce((sum, track) => sum + track.times.length, 0);
112
- budget(trackCount, limits.maxTracks, 'tracks', `${path}.tracks`);
113
- budget(keyframeCount, limits.maxKeyframes, 'keyframes', `${path}.tracks`);
114
- const clipBindingIds = new Set();
115
- for (let trackIndex = 0; trackIndex < clip.tracks.length; trackIndex++) {
116
- const track = clip.tracks[trackIndex];
117
- unique(clipBindingIds, track.binding.id, `${path}.tracks[${trackIndex}].binding.id`, 'binding');
118
- bindingIds.add(track.binding.id);
119
- validateBindingTarget(track.binding, nodes, materialIds, `${path}.tracks[${trackIndex}].binding`);
120
- }
121
- return clip;
122
- });
123
- const stateMachine = root.stateMachine === undefined || root.stateMachine === null
124
- ? root.stateMachine
125
- : parseStateMachine(root.stateMachine, `${EXTENSION_PATH}.stateMachine`, limits.maxStateMachineDepth);
126
- if (stateMachine)
127
- validateStateMachineReferences(stateMachine, clipIds, bindingIds, `${EXTENSION_PATH}.stateMachine`);
128
- return deepFreeze({
129
- format: NATIVE_3D_ANIMATION_FORMAT,
130
- mode: 'native-3d',
131
- coordinateSystem,
132
- viewport,
133
- materials,
134
- nodes,
135
- clips,
136
- ...(root.stateMachine === undefined ? {} : { stateMachine: stateMachine ?? null }),
137
- });
138
- }
139
- function parseCoordinateSystem(value, path) {
140
- const item = object(value, path, ['handedness', 'upAxis', 'forwardAxis', 'unit', 'angles', 'rotationStorage'], ['handedness', 'upAxis', 'forwardAxis', 'unit', 'angles', 'rotationStorage']);
141
- exact(item.handedness, 'right', `${path}.handedness`);
142
- exact(item.upAxis, '+y', `${path}.upAxis`);
143
- exact(item.forwardAxis, '-z', `${path}.forwardAxis`);
144
- exact(item.unit, 'meter', `${path}.unit`);
145
- exact(item.angles, 'radian', `${path}.angles`);
146
- exact(item.rotationStorage, 'normalized-xyzw-quaternion', `${path}.rotationStorage`);
147
- return Object.freeze({
148
- handedness: 'right', upAxis: '+y', forwardAxis: '-z', unit: 'meter', angles: 'radian',
149
- rotationStorage: 'normalized-xyzw-quaternion',
150
- });
151
- }
152
- function parseViewport(value, path) {
153
- const item = object(value, path, ['width', 'height'], ['width', 'height']);
154
- return Object.freeze({ width: positive(item.width, `${path}.width`), height: positive(item.height, `${path}.height`) });
155
- }
156
- function parseMaterial(value, path) {
157
- const item = object(value, path, ['id', 'name', 'baseColorFactor', 'metallicFactor', 'roughnessFactor', 'emissiveFactor', 'alphaMode', 'doubleSided'], ['id', 'name', 'baseColorFactor', 'metallicFactor', 'roughnessFactor', 'emissiveFactor', 'alphaMode', 'alphaCutoff', 'doubleSided', 'baseColorTexture', 'normalTexture', 'metallicRoughnessTexture', 'emissiveTexture']);
158
- return Object.freeze({
159
- id: nonEmpty(item.id, `${path}.id`),
160
- name: string(item.name, `${path}.name`),
161
- baseColorFactor: vec4(item.baseColorFactor, `${path}.baseColorFactor`, 0, 1),
162
- metallicFactor: bounded(item.metallicFactor, `${path}.metallicFactor`, 0, 1),
163
- roughnessFactor: bounded(item.roughnessFactor, `${path}.roughnessFactor`, 0, 1),
164
- emissiveFactor: vec3(item.emissiveFactor, `${path}.emissiveFactor`, 0),
165
- alphaMode: enumeration(item.alphaMode, ['opaque', 'mask', 'blend'], `${path}.alphaMode`),
166
- ...(item.alphaCutoff === undefined ? {} : { alphaCutoff: bounded(item.alphaCutoff, `${path}.alphaCutoff`, 0, 1) }),
167
- doubleSided: boolean(item.doubleSided, `${path}.doubleSided`),
168
- ...optionalStrings(item, path, ['baseColorTexture', 'normalTexture', 'metallicRoughnessTexture', 'emissiveTexture']),
169
- });
170
- }
171
- function parseNode(value, path) {
172
- const item = object(value, path, ['id', 'name', 'transform', 'components'], ['id', 'name', 'parent', 'start', 'duration', 'transform', 'components']);
173
- const components = array(item.components, `${path}.components`).map((entry, index) => (parseComponent(entry, `${path}.components[${index}]`)));
174
- return Object.freeze({
175
- id: nonEmpty(item.id, `${path}.id`),
176
- name: string(item.name, `${path}.name`),
177
- ...(item.parent === undefined ? {} : { parent: nonEmpty(item.parent, `${path}.parent`) }),
178
- ...(item.start === undefined ? {} : { start: nonNegative(item.start, `${path}.start`) }),
179
- ...(item.duration === undefined ? {} : { duration: positive(item.duration, `${path}.duration`) }),
180
- transform: parseTransform(item.transform, `${path}.transform`),
181
- components: Object.freeze(components),
182
- });
183
- }
184
- function parseTransform(value, path) {
185
- const item = object(value, path, ['translation', 'rotation', 'scale'], ['translation', 'rotation', 'scale']);
186
- const rotation = vec4(item.rotation, `${path}.rotation`);
187
- assertNormalizedQuaternion(rotation, `${path}.rotation`);
188
- return Object.freeze({
189
- translation: vec3(item.translation, `${path}.translation`),
190
- rotation,
191
- scale: vec3(item.scale, `${path}.scale`),
192
- });
193
- }
194
- function parseComponent(value, path) {
195
- const kind = object(value, path).kind;
196
- if (kind === 'camera3d') {
197
- const item = object(value, path, ['id', 'kind', 'projection'], ['id', 'kind', 'projection']);
198
- return Object.freeze({ id: nonEmpty(item.id, `${path}.id`), kind, projection: parseCamera(item.projection, `${path}.projection`) });
199
- }
200
- if (kind === 'primitive3d') {
201
- const item = object(value, path, ['id', 'kind', 'primitive', 'materialId'], ['id', 'kind', 'primitive', 'materialId']);
202
- return Object.freeze({
203
- id: nonEmpty(item.id, `${path}.id`), kind,
204
- primitive: enumeration(item.primitive, ['box', 'sphere', 'plane', 'cylinder', 'cone'], `${path}.primitive`),
205
- materialId: nonEmpty(item.materialId, `${path}.materialId`),
206
- });
207
- }
208
- if (kind === 'model3d') {
209
- const item = object(value, path, ['id', 'kind', 'resource'], ['id', 'kind', 'resource', 'materialOverrides']);
210
- const materialOverrides = item.materialOverrides === undefined ? undefined : array(item.materialOverrides, `${path}.materialOverrides`).map((entry, index) => {
211
- const overridePath = `${path}.materialOverrides[${index}]`;
212
- const override = object(entry, overridePath, ['slot', 'materialId'], ['slot', 'materialId']);
213
- return Object.freeze({ slot: nonEmpty(override.slot, `${overridePath}.slot`), materialId: nonEmpty(override.materialId, `${overridePath}.materialId`) });
214
- });
215
- return Object.freeze({
216
- id: nonEmpty(item.id, `${path}.id`), kind, resource: nonEmpty(item.resource, `${path}.resource`),
217
- ...(materialOverrides ? { materialOverrides: Object.freeze(materialOverrides) } : {}),
218
- });
219
- }
220
- if (kind === 'particle3d') {
221
- const item = object(value, path, ['id', 'kind', 'descriptor'], ['id', 'kind', 'descriptor']);
222
- return Object.freeze({
223
- id: nonEmpty(item.id, `${path}.id`), kind,
224
- descriptor: parseParticle(item.descriptor, `${path}.descriptor`),
225
- });
226
- }
227
- invalid(`Unsupported component kind "${String(kind)}".`, `${path}.kind`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
228
- }
229
- function parseCamera(value, path) {
230
- const kind = object(value, path).kind;
231
- if (kind === 'perspective') {
232
- const item = object(value, path, ['kind', 'fovYRadians', 'near', 'far'], ['kind', 'fovYRadians', 'near', 'far']);
233
- const near = positive(item.near, `${path}.near`);
234
- const far = positive(item.far, `${path}.far`);
235
- if (far <= near)
236
- invalid('Camera far must be greater than near.', `${path}.far`);
237
- return Object.freeze({
238
- kind, fovYRadians: bounded(item.fovYRadians, `${path}.fovYRadians`, Number.MIN_VALUE, Math.PI, false), near, far,
239
- });
240
- }
241
- if (kind === 'orthographic') {
242
- const item = object(value, path, ['kind', 'orthoHeight', 'near', 'far'], ['kind', 'orthoHeight', 'near', 'far']);
243
- const near = nonNegative(item.near, `${path}.near`);
244
- const far = positive(item.far, `${path}.far`);
245
- if (far <= near)
246
- invalid('Camera far must be greater than near.', `${path}.far`);
247
- return Object.freeze({ kind, orthoHeight: positive(item.orthoHeight, `${path}.orthoHeight`), near, far });
248
- }
249
- invalid(`Unsupported camera projection "${String(kind)}".`, `${path}.kind`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
250
- }
251
- function parseParticle(value, path) {
252
- const required = ['maxParticles', 'emissionRate', 'burst', 'duration', 'loop', 'seed', 'lifetime', 'speed', 'direction', 'spread', 'gravity', 'startSize', 'endSize', 'rotation', 'angularVelocity', 'startColor', 'endColor', 'shape', 'blendMode', 'radial', 'opacity', 'depthTest', 'depthWrite', 'sortMode'];
253
- const item = object(value, path, required, [...required, 'shapeSize', 'shapeRadius', 'textureResource']);
254
- return Object.freeze({
255
- maxParticles: integer(item.maxParticles, `${path}.maxParticles`, 1, 1_000_000),
256
- emissionRate: nonNegative(item.emissionRate, `${path}.emissionRate`),
257
- burst: integer(item.burst, `${path}.burst`, 0, 1_000_000),
258
- duration: positive(item.duration, `${path}.duration`),
259
- loop: boolean(item.loop, `${path}.loop`),
260
- seed: integer(item.seed, `${path}.seed`, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER),
261
- lifetime: range(item.lifetime, `${path}.lifetime`, 0),
262
- speed: range(item.speed, `${path}.speed`),
263
- direction: vec3(item.direction, `${path}.direction`),
264
- spread: bounded(item.spread, `${path}.spread`, 0, Math.PI),
265
- gravity: vec3(item.gravity, `${path}.gravity`),
266
- startSize: range(item.startSize, `${path}.startSize`, 0),
267
- endSize: range(item.endSize, `${path}.endSize`, 0),
268
- rotation: range(item.rotation, `${path}.rotation`),
269
- angularVelocity: range(item.angularVelocity, `${path}.angularVelocity`),
270
- startColor: vec4(item.startColor, `${path}.startColor`, 0, 1),
271
- endColor: vec4(item.endColor, `${path}.endColor`, 0, 1),
272
- shape: enumeration(item.shape, ['point', 'box', 'sphere'], `${path}.shape`),
273
- ...(item.shapeSize === undefined ? {} : { shapeSize: vec3(item.shapeSize, `${path}.shapeSize`, 0) }),
274
- ...(item.shapeRadius === undefined ? {} : { shapeRadius: nonNegative(item.shapeRadius, `${path}.shapeRadius`) }),
275
- blendMode: enumeration(item.blendMode, ['normal', 'additive'], `${path}.blendMode`),
276
- ...(item.textureResource === undefined ? {} : { textureResource: nonEmpty(item.textureResource, `${path}.textureResource`) }),
277
- radial: boolean(item.radial, `${path}.radial`),
278
- opacity: bounded(item.opacity, `${path}.opacity`, 0, 1),
279
- depthTest: boolean(item.depthTest, `${path}.depthTest`),
280
- depthWrite: boolean(item.depthWrite, `${path}.depthWrite`),
281
- sortMode: enumeration(item.sortMode, ['none', 'back-to-front'], `${path}.sortMode`),
282
- });
283
- }
284
- function parseClip(value, path) {
285
- const item = object(value, path, ['format', 'id', 'name', 'duration', 'tracks', 'events'], ['format', 'id', 'name', 'duration', 'tracks', 'events']);
286
- exact(item.format, NATIVE_3D_CLIP_FORMAT, `${path}.format`);
287
- const duration = positive(item.duration, `${path}.duration`);
288
- const trackIds = new Set();
289
- const tracks = array(item.tracks, `${path}.tracks`).map((entry, index) => {
290
- const trackPath = `${path}.tracks[${index}]`;
291
- const track = parseTrack(entry, trackPath, duration);
292
- unique(trackIds, track.id, `${trackPath}.id`, 'track');
293
- return track;
294
- });
295
- const eventIds = new Set();
296
- const events = array(item.events, `${path}.events`).map((entry, index) => {
297
- const eventPath = `${path}.events[${index}]`;
298
- const event = parseEvent(entry, eventPath, duration);
299
- unique(eventIds, event.id, `${eventPath}.id`, 'event');
300
- return event;
301
- });
302
- return Object.freeze({
303
- format: NATIVE_3D_CLIP_FORMAT,
304
- id: nonEmpty(item.id, `${path}.id`),
305
- name: string(item.name, `${path}.name`),
306
- duration,
307
- tracks: Object.freeze(tracks),
308
- events: Object.freeze(events),
309
- });
310
- }
311
- function parseTrack(value, path, duration) {
312
- const item = object(value, path, ['id', 'binding', 'interpolation', 'times', 'values'], ['id', 'binding', 'interpolation', 'times', 'values']);
313
- const binding = parseBinding(item.binding, `${path}.binding`);
314
- const interpolation = enumeration(item.interpolation, ['step', 'linear', 'cubic-spline'], `${path}.interpolation`);
315
- const times = numericArray(item.times, `${path}.times`, 1);
316
- for (let index = 0; index < times.length; index++) {
317
- const time = times[index];
318
- if (time < 0 || time > duration)
319
- invalid('Track time must lie within clip duration.', `${path}.times[${index}]`, 'E_ANIMATION_3D_BINDING_MISMATCH');
320
- if (index > 0 && time <= times[index - 1])
321
- invalid('Track times must be strictly increasing.', `${path}.times[${index}]`, 'E_ANIMATION_3D_BINDING_MISMATCH');
322
- }
323
- const values = numericArray(item.values, `${path}.values`, 1);
324
- const expected = times.length * binding.valueSize * (interpolation === 'cubic-spline' ? 3 : 1);
325
- if (values.length !== expected) {
326
- invalid(`Track values length ${values.length} does not match expected ${expected}.`, `${path}.values`, 'E_ANIMATION_3D_BINDING_MISMATCH');
327
- }
328
- if (binding.path === 'transform.rotation')
329
- validateTrackQuaternions(values, times.length, interpolation, `${path}.values`);
330
- return Object.freeze({ id: nonEmpty(item.id, `${path}.id`), binding, interpolation, times, values });
331
- }
332
- function parseBinding(value, path) {
333
- const base = object(value, path);
334
- const target = parseBindingTarget(base.target, `${path}.target`);
335
- const id = nonEmpty(base.id, `${path}.id`);
336
- if (base.path === 'transform.translation' || base.path === 'transform.scale') {
337
- const item = object(value, path, ['id', 'target', 'path', 'valueType', 'valueSize'], ['id', 'target', 'path', 'valueType', 'valueSize']);
338
- exact(item.valueType, 'vec3', `${path}.valueType`);
339
- exact(item.valueSize, 3, `${path}.valueSize`, 'E_ANIMATION_3D_BINDING_MISMATCH');
340
- return Object.freeze({ id, target, path: base.path, valueType: 'vec3', valueSize: 3 });
341
- }
342
- if (base.path === 'transform.rotation') {
343
- const item = object(value, path, ['id', 'target', 'path', 'valueType', 'valueSize'], ['id', 'target', 'path', 'valueType', 'valueSize']);
344
- exact(item.valueType, 'quaternion', `${path}.valueType`);
345
- exact(item.valueSize, 4, `${path}.valueSize`, 'E_ANIMATION_3D_BINDING_MISMATCH');
346
- return Object.freeze({ id, target, path: base.path, valueType: 'quaternion', valueSize: 4 });
347
- }
348
- if (base.path === 'morph.weights') {
349
- const item = object(value, path, ['id', 'target', 'path', 'valueType', 'valueSize'], ['id', 'target', 'path', 'valueType', 'valueSize']);
350
- exact(item.valueType, 'weights', `${path}.valueType`);
351
- return Object.freeze({ id, target, path: base.path, valueType: 'weights', valueSize: integer(item.valueSize, `${path}.valueSize`, 1, 65_536) });
352
- }
353
- if (base.path === 'property') {
354
- const item = object(value, path, ['id', 'target', 'path', 'component', 'property', 'valueType', 'valueSize'], ['id', 'target', 'path', 'component', 'property', 'valueType', 'valueSize']);
355
- const component = enumeration(item.component, ['material3d', 'camera3d'], `${path}.component`);
356
- const property = enumeration(item.property, ['baseColorFactor', 'metallicFactor', 'roughnessFactor', 'emissiveFactor', 'alphaCutoff', 'fovYRadians', 'near', 'far', 'orthoHeight'], `${path}.property`);
357
- const contract = propertyContract(component, property, `${path}.property`);
358
- exact(item.valueType, contract.valueType, `${path}.valueType`, 'E_ANIMATION_3D_BINDING_MISMATCH');
359
- exact(item.valueSize, contract.valueSize, `${path}.valueSize`, 'E_ANIMATION_3D_BINDING_MISMATCH');
360
- return Object.freeze({ id, target, path: 'property', component, property, ...contract });
361
- }
362
- invalid(`Unsupported binding path "${String(base.path)}".`, `${path}.path`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
363
- }
364
- function parseBindingTarget(value, path) {
365
- const kind = object(value, path).kind;
366
- if (kind === 'node-id') {
367
- const item = object(value, path, ['kind', 'nodeId'], ['kind', 'nodeId']);
368
- return Object.freeze({ kind, nodeId: nonEmpty(item.nodeId, `${path}.nodeId`) });
369
- }
370
- if (kind === 'node-path') {
371
- const item = object(value, path, ['kind', 'segments'], ['kind', 'segments']);
372
- const segments = array(item.segments, `${path}.segments`);
373
- if (segments.length === 0)
374
- invalid('Node path must contain at least one segment.', `${path}.segments`);
375
- return Object.freeze({ kind, segments: Object.freeze(segments.map((segment, index) => nonEmpty(segment, `${path}.segments[${index}]`))) });
376
- }
377
- if (kind === 'slot') {
378
- const item = object(value, path, ['kind', 'slot'], ['kind', 'slot']);
379
- return Object.freeze({ kind, slot: nonEmpty(item.slot, `${path}.slot`) });
380
- }
381
- invalid(`Unsupported binding target "${String(kind)}".`, `${path}.kind`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
382
- }
383
- function parseEvent(value, path, duration) {
384
- const item = object(value, path, ['id', 'time', 'name'], ['id', 'time', 'name', 'payload']);
385
- const time = nonNegative(item.time, `${path}.time`);
386
- if (time > duration)
387
- invalid('Event time must lie within clip duration.', `${path}.time`);
388
- return Object.freeze({
389
- id: nonEmpty(item.id, `${path}.id`), time, name: nonEmpty(item.name, `${path}.name`),
390
- ...(item.payload === undefined ? {} : { payload: parseJsonObject(item.payload, `${path}.payload`) }),
391
- });
392
- }
393
- function parseStateMachine(value, path, maxDepth) {
394
- const item = object(value, path, ['format', 'id', 'name', 'parameters', 'layers'], ['format', 'id', 'name', 'parameters', 'layers']);
395
- exact(item.format, NATIVE_3D_STATE_MACHINE_FORMAT, `${path}.format`);
396
- const parameterNames = new Set();
397
- const parameters = array(item.parameters, `${path}.parameters`).map((entry, index) => {
398
- const parameterPath = `${path}.parameters[${index}]`;
399
- const parameter = parseParameter(entry, parameterPath);
400
- unique(parameterNames, parameter.name, `${parameterPath}.name`, 'state-machine parameter');
401
- return parameter;
402
- });
403
- const layerIds = new Set();
404
- const layers = array(item.layers, `${path}.layers`).map((entry, index) => {
405
- const layerPath = `${path}.layers[${index}]`;
406
- const layer = parseLayer(entry, layerPath, maxDepth);
407
- unique(layerIds, layer.id, `${layerPath}.id`, 'state-machine layer');
408
- return layer;
409
- });
410
- return Object.freeze({
411
- format: NATIVE_3D_STATE_MACHINE_FORMAT,
412
- id: nonEmpty(item.id, `${path}.id`), name: string(item.name, `${path}.name`),
413
- parameters: Object.freeze(parameters), layers: Object.freeze(layers),
414
- });
415
- }
416
- function parseParameter(value, path) {
417
- const base = object(value, path);
418
- const name = nonEmpty(base.name, `${path}.name`);
419
- if (base.type === 'trigger') {
420
- object(value, path, ['name', 'type'], ['name', 'type']);
421
- return Object.freeze({ name, type: 'trigger' });
422
- }
423
- object(value, path, ['name', 'type', 'defaultValue'], ['name', 'type', 'defaultValue']);
424
- if (base.type === 'float')
425
- return Object.freeze({ name, type: 'float', defaultValue: finite(base.defaultValue, `${path}.defaultValue`) });
426
- if (base.type === 'integer')
427
- return Object.freeze({ name, type: 'integer', defaultValue: integer(base.defaultValue, `${path}.defaultValue`, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER) });
428
- if (base.type === 'boolean')
429
- return Object.freeze({ name, type: 'boolean', defaultValue: boolean(base.defaultValue, `${path}.defaultValue`) });
430
- invalid(`Unsupported parameter type "${String(base.type)}".`, `${path}.type`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
431
- }
432
- function parseLayer(value, path, maxDepth) {
433
- const item = object(value, path, ['id', 'name', 'initialStateId', 'states', 'transitions'], ['id', 'name', 'initialStateId', 'states', 'transitions', 'blendMode', 'weight', 'mask']);
434
- const stateIds = new Set();
435
- const states = array(item.states, `${path}.states`).map((entry, index) => {
436
- const statePath = `${path}.states[${index}]`;
437
- const state = parseState(entry, statePath, maxDepth);
438
- unique(stateIds, state.id, `${statePath}.id`, 'state');
439
- return state;
440
- });
441
- const transitionIds = new Set();
442
- const transitions = array(item.transitions, `${path}.transitions`).map((entry, index) => {
443
- const transitionPath = `${path}.transitions[${index}]`;
444
- const transition = parseTransition(entry, transitionPath);
445
- unique(transitionIds, transition.id, `${transitionPath}.id`, 'transition');
446
- return transition;
447
- });
448
- const mask = item.mask === undefined ? undefined : parseMask(item.mask, `${path}.mask`);
449
- return Object.freeze({
450
- id: nonEmpty(item.id, `${path}.id`), name: string(item.name, `${path}.name`),
451
- initialStateId: nonEmpty(item.initialStateId, `${path}.initialStateId`),
452
- states: Object.freeze(states), transitions: Object.freeze(transitions),
453
- ...(item.blendMode === undefined ? {} : { blendMode: enumeration(item.blendMode, ['override', 'additive'], `${path}.blendMode`) }),
454
- ...(item.weight === undefined ? {} : { weight: bounded(item.weight, `${path}.weight`, 0, 1) }),
455
- ...(mask ? { mask } : {}),
456
- });
457
- }
458
- function parseState(value, path, maxDepth) {
459
- const item = object(value, path, ['id', 'name', 'motion'], ['id', 'name', 'motion', 'speed', 'speedParameter', 'loop']);
460
- return Object.freeze({
461
- id: nonEmpty(item.id, `${path}.id`), name: string(item.name, `${path}.name`),
462
- motion: parseMotion(item.motion, `${path}.motion`, 0, maxDepth),
463
- ...(item.speed === undefined ? {} : { speed: finite(item.speed, `${path}.speed`) }),
464
- ...(item.speedParameter === undefined ? {} : { speedParameter: nonEmpty(item.speedParameter, `${path}.speedParameter`) }),
465
- ...(item.loop === undefined ? {} : { loop: enumeration(item.loop, ['once', 'repeat', 'ping-pong'], `${path}.loop`) }),
466
- });
467
- }
468
- function parseMotion(value, path, depth, maxDepth) {
469
- if (depth >= maxDepth)
470
- budget(depth + 1, maxDepth, 'state-machine motion depth', path);
471
- const base = object(value, path);
472
- if (base.kind === 'clip') {
473
- const item = object(value, path, ['kind', 'clipId'], ['kind', 'clipId']);
474
- return Object.freeze({ kind: 'clip', clipId: nonEmpty(item.clipId, `${path}.clipId`) });
475
- }
476
- if (base.kind === 'blend-1d') {
477
- const item = object(value, path, ['kind', 'parameter', 'children'], ['kind', 'parameter', 'children']);
478
- const children = nonEmptyArray(item.children, `${path}.children`).map((entry, index) => {
479
- const childPath = `${path}.children[${index}]`;
480
- const child = object(entry, childPath, ['threshold', 'motion'], ['threshold', 'motion']);
481
- return Object.freeze({ threshold: finite(child.threshold, `${childPath}.threshold`), motion: parseMotion(child.motion, `${childPath}.motion`, depth + 1, maxDepth) });
482
- });
483
- return Object.freeze({ kind: 'blend-1d', parameter: nonEmpty(item.parameter, `${path}.parameter`), children: Object.freeze(children) });
484
- }
485
- if (base.kind === 'blend-2d') {
486
- const item = object(value, path, ['kind', 'algorithm', 'parameterX', 'parameterY', 'children'], ['kind', 'algorithm', 'parameterX', 'parameterY', 'children']);
487
- const children = nonEmptyArray(item.children, `${path}.children`).map((entry, index) => {
488
- const childPath = `${path}.children[${index}]`;
489
- const child = object(entry, childPath, ['position', 'motion'], ['position', 'motion']);
490
- return Object.freeze({ position: vec2(child.position, `${childPath}.position`), motion: parseMotion(child.motion, `${childPath}.motion`, depth + 1, maxDepth) });
491
- });
492
- return Object.freeze({
493
- kind: 'blend-2d', algorithm: enumeration(item.algorithm, ['cartesian', 'directional'], `${path}.algorithm`),
494
- parameterX: nonEmpty(item.parameterX, `${path}.parameterX`), parameterY: nonEmpty(item.parameterY, `${path}.parameterY`),
495
- children: Object.freeze(children),
496
- });
497
- }
498
- invalid(`Unsupported motion kind "${String(base.kind)}".`, `${path}.kind`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
499
- }
500
- function parseTransition(value, path) {
501
- const item = object(value, path, ['id', 'from', 'to', 'conditions', 'duration'], ['id', 'from', 'to', 'conditions', 'duration', 'hasExitTime', 'exitTime', 'destinationOffset', 'interruption']);
502
- const conditions = array(item.conditions, `${path}.conditions`).map((entry, index) => parseCondition(entry, `${path}.conditions[${index}]`));
503
- return Object.freeze({
504
- id: nonEmpty(item.id, `${path}.id`), from: nonEmpty(item.from, `${path}.from`), to: nonEmpty(item.to, `${path}.to`),
505
- conditions: Object.freeze(conditions), duration: nonNegative(item.duration, `${path}.duration`),
506
- ...(item.hasExitTime === undefined ? {} : { hasExitTime: boolean(item.hasExitTime, `${path}.hasExitTime`) }),
507
- ...(item.exitTime === undefined ? {} : { exitTime: nonNegative(item.exitTime, `${path}.exitTime`) }),
508
- ...(item.destinationOffset === undefined ? {} : { destinationOffset: nonNegative(item.destinationOffset, `${path}.destinationOffset`) }),
509
- ...(item.interruption === undefined ? {} : { interruption: enumeration(item.interruption, ['none', 'source', 'destination', 'source-then-destination', 'destination-then-source'], `${path}.interruption`) }),
510
- });
511
- }
512
- function parseCondition(value, path) {
513
- const item = object(value, path, ['parameter', 'operator'], ['parameter', 'operator', 'value']);
514
- const operator = enumeration(item.operator, ['greater', 'greater-or-equal', 'less', 'less-or-equal', 'equal', 'not-equal', 'is-true', 'is-false', 'triggered'], `${path}.operator`);
515
- return Object.freeze({
516
- parameter: nonEmpty(item.parameter, `${path}.parameter`), operator,
517
- ...(item.value === undefined ? {} : { value: typeof item.value === 'boolean' ? item.value : finite(item.value, `${path}.value`) }),
518
- });
519
- }
520
- function parseMask(value, path) {
521
- const item = object(value, path, [], ['include', 'exclude']);
522
- const parseList = (entry, entryPath) => {
523
- const seen = new Set();
524
- return Object.freeze(array(entry, entryPath).map((value, index) => {
525
- const result = nonEmpty(value, `${entryPath}[${index}]`);
526
- unique(seen, result, `${entryPath}[${index}]`, 'mask binding');
527
- return result;
528
- }));
529
- };
530
- return Object.freeze({
531
- ...(item.include === undefined ? {} : { include: parseList(item.include, `${path}.include`) }),
532
- ...(item.exclude === undefined ? {} : { exclude: parseList(item.exclude, `${path}.exclude`) }),
533
- });
534
- }
535
- function validateCarrier(document, payload) {
536
- if (document.extensionsUsed.length !== 1 || document.extensionsUsed[0] !== NATIVE_3D_ANIMATION_EXTENSION_ID
537
- || document.extensionsRequired.length !== 1 || document.extensionsRequired[0] !== NATIVE_3D_ANIMATION_EXTENSION_ID) {
538
- invalid(`Native 3D carrier must use and require only "${NATIVE_3D_ANIMATION_EXTENSION_ID}".`, '$.extensionsRequired');
539
- }
540
- if (document.nodes.length > 0) {
541
- invalid('Native 3D carrier cannot contain core 2D nodes.', '$.nodes', 'E_ANIMATION_3D_MIXED_DIMENSIONS');
542
- }
543
- if (document.tracks.length > 0) {
544
- invalid('Native 3D carrier cannot contain core 2D tracks.', '$.tracks', 'E_ANIMATION_3D_MIXED_DIMENSIONS');
545
- }
546
- if (document.canvas.width !== payload.viewport.width || document.canvas.height !== payload.viewport.height) {
547
- invalid('Core canvas and native 3D viewport dimensions must match.', `${EXTENSION_PATH}.viewport`);
548
- }
549
- for (let index = 0; index < payload.nodes.length; index++) {
550
- const node = payload.nodes[index];
551
- const start = node.start ?? 0;
552
- if (start > document.duration || start + (node.duration ?? document.duration - start) > document.duration + 1e-6) {
553
- invalid('Node time range must fit inside composition duration.', `${EXTENSION_PATH}.nodes[${index}]`);
554
- }
555
- }
556
- for (let index = 0; index < payload.clips.length; index++) {
557
- if (payload.clips[index].duration > document.duration + 1e-6) {
558
- invalid('Clip duration must fit inside composition duration.', `${EXTENSION_PATH}.clips[${index}].duration`);
559
- }
560
- }
561
- }
562
- function validateNodeSemantics(nodes, nodeIds, materialIds) {
563
- const byId = new Map(nodes.map(node => [node.id, node]));
564
- for (let index = 0; index < nodes.length; index++) {
565
- const node = nodes[index];
566
- if (node.parent !== undefined && !nodeIds.has(node.parent)) {
567
- invalid(`Node parent "${node.parent}" does not exist.`, `${EXTENSION_PATH}.nodes[${index}].parent`, 'E_ANIMATION_3D_BINDING_MISMATCH');
568
- }
569
- if (node.parent === node.id)
570
- invalid('Node cannot parent itself.', `${EXTENSION_PATH}.nodes[${index}].parent`, 'E_ANIMATION_3D_BINDING_MISMATCH');
571
- for (let componentIndex = 0; componentIndex < node.components.length; componentIndex++) {
572
- const component = node.components[componentIndex];
573
- const path = `${EXTENSION_PATH}.nodes[${index}].components[${componentIndex}]`;
574
- if (component.kind === 'primitive3d' && !materialIds.has(component.materialId)) {
575
- invalid(`Primitive material "${component.materialId}" does not exist.`, `${path}.materialId`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
576
- }
577
- if (component.kind === 'model3d') {
578
- for (let overrideIndex = 0; overrideIndex < (component.materialOverrides?.length ?? 0); overrideIndex++) {
579
- const materialId = component.materialOverrides[overrideIndex].materialId;
580
- if (!materialIds.has(materialId))
581
- invalid(`Material override "${materialId}" does not exist.`, `${path}.materialOverrides[${overrideIndex}].materialId`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
582
- }
583
- }
584
- }
585
- }
586
- for (const node of nodes) {
587
- const visited = new Set();
588
- let current = node;
589
- while (current?.parent) {
590
- if (visited.has(current.id))
591
- invalid('Node hierarchy contains a cycle.', `${EXTENSION_PATH}.nodes`, 'E_ANIMATION_3D_BINDING_MISMATCH');
592
- visited.add(current.id);
593
- current = byId.get(current.parent);
594
- }
595
- }
596
- }
597
- function validateResourceReferences(resources, payload) {
598
- const byId = new Map(resources.map(resource => [resource.id, resource]));
599
- for (let index = 0; index < resources.length; index++) {
600
- const resource = resources[index];
601
- const scheme = uriScheme(resource.uri);
602
- if (scheme && FORBIDDEN_URI_SCHEMES.has(scheme)) {
603
- invalid(`Delivery URI scheme "${scheme}:" is forbidden.`, `$.resources[${index}].uri`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
604
- }
605
- }
606
- for (let materialIndex = 0; materialIndex < payload.materials.length; materialIndex++) {
607
- const material = payload.materials[materialIndex];
608
- for (const key of ['baseColorTexture', 'normalTexture', 'metallicRoughnessTexture', 'emissiveTexture']) {
609
- const id = material[key];
610
- if (id === undefined)
611
- continue;
612
- const resource = byId.get(id);
613
- if (!resource || resource.type !== 'image')
614
- invalid(`Material texture "${id}" must reference an image resource.`, `${EXTENSION_PATH}.materials[${materialIndex}].${key}`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
615
- }
616
- }
617
- for (let nodeIndex = 0; nodeIndex < payload.nodes.length; nodeIndex++) {
618
- const node = payload.nodes[nodeIndex];
619
- for (let componentIndex = 0; componentIndex < node.components.length; componentIndex++) {
620
- const component = node.components[componentIndex];
621
- const path = `${EXTENSION_PATH}.nodes[${nodeIndex}].components[${componentIndex}]`;
622
- if (component.kind === 'model3d') {
623
- const resource = byId.get(component.resource);
624
- if (!resource || resource.type !== 'binary' || !resource.mimeType || !MODEL_MIME_TYPES.has(resource.mimeType)) {
625
- invalid(`Model "${component.resource}" must reference a binary glTF/GLB resource.`, `${path}.resource`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
626
- }
627
- }
628
- if (component.kind === 'particle3d' && component.descriptor.textureResource !== undefined) {
629
- const resource = byId.get(component.descriptor.textureResource);
630
- if (!resource || resource.type !== 'image')
631
- invalid(`Particle texture "${component.descriptor.textureResource}" must reference an image resource.`, `${path}.descriptor.textureResource`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
632
- }
633
- }
634
- }
635
- }
636
- function validateBindingTarget(binding, nodes, materialIds, path) {
637
- const byId = new Map(nodes.map(node => [node.id, node]));
638
- const target = binding.target;
639
- if (target.kind === 'node-id' && !byId.has(target.nodeId)) {
640
- invalid(`Binding node "${target.nodeId}" does not exist.`, `${path}.target.nodeId`, 'E_ANIMATION_3D_BINDING_MISMATCH');
641
- }
642
- if (target.kind === 'node-path' && !byId.has(target.segments[0])) {
643
- invalid(`Binding node path root "${target.segments[0]}" does not exist.`, `${path}.target.segments[0]`, 'E_ANIMATION_3D_BINDING_MISMATCH');
644
- }
645
- if (binding.path === 'property' && binding.component === 'material3d') {
646
- if (target.kind !== 'slot' || !materialIds.has(target.slot))
647
- invalid('Material property bindings require a material-id slot target.', `${path}.target`, 'E_ANIMATION_3D_BINDING_MISMATCH');
648
- }
649
- if (binding.path === 'property' && binding.component === 'camera3d') {
650
- if (target.kind !== 'node-id' || !byId.get(target.nodeId)?.components.some(component => component.kind === 'camera3d')) {
651
- invalid('Camera property bindings require a node-id target with Camera3D.', `${path}.target`, 'E_ANIMATION_3D_BINDING_MISMATCH');
652
- }
653
- }
654
- }
655
- function validateStateMachineReferences(machine, clipIds, bindingIds, path) {
656
- const parameterNames = new Set(machine.parameters.map(parameter => parameter.name));
657
- const visitMotion = (motion, motionPath) => {
658
- if (motion.kind === 'clip') {
659
- if (!clipIds.has(motion.clipId))
660
- invalid(`Motion clip "${motion.clipId}" does not exist.`, `${motionPath}.clipId`, 'E_ANIMATION_3D_BINDING_MISMATCH');
661
- return;
662
- }
663
- for (let index = 0; index < motion.children.length; index++)
664
- visitMotion(motion.children[index].motion, `${motionPath}.children[${index}].motion`);
665
- };
666
- for (let layerIndex = 0; layerIndex < machine.layers.length; layerIndex++) {
667
- const layer = machine.layers[layerIndex];
668
- const layerPath = `${path}.layers[${layerIndex}]`;
669
- const stateIds = new Set(layer.states.map(state => state.id));
670
- if (!stateIds.has(layer.initialStateId))
671
- invalid(`Initial state "${layer.initialStateId}" does not exist.`, `${layerPath}.initialStateId`, 'E_ANIMATION_3D_BINDING_MISMATCH');
672
- for (let stateIndex = 0; stateIndex < layer.states.length; stateIndex++) {
673
- const state = layer.states[stateIndex];
674
- visitMotion(state.motion, `${layerPath}.states[${stateIndex}].motion`);
675
- if (state.speedParameter && !parameterNames.has(state.speedParameter))
676
- invalid(`Speed parameter "${state.speedParameter}" does not exist.`, `${layerPath}.states[${stateIndex}].speedParameter`, 'E_ANIMATION_3D_BINDING_MISMATCH');
677
- }
678
- for (let transitionIndex = 0; transitionIndex < layer.transitions.length; transitionIndex++) {
679
- const transition = layer.transitions[transitionIndex];
680
- const transitionPath = `${layerPath}.transitions[${transitionIndex}]`;
681
- if (transition.from !== '*' && !stateIds.has(transition.from))
682
- invalid(`Transition source "${transition.from}" does not exist.`, `${transitionPath}.from`, 'E_ANIMATION_3D_BINDING_MISMATCH');
683
- if (!stateIds.has(transition.to))
684
- invalid(`Transition destination "${transition.to}" does not exist.`, `${transitionPath}.to`, 'E_ANIMATION_3D_BINDING_MISMATCH');
685
- for (let conditionIndex = 0; conditionIndex < transition.conditions.length; conditionIndex++) {
686
- if (!parameterNames.has(transition.conditions[conditionIndex].parameter))
687
- invalid(`Condition parameter "${transition.conditions[conditionIndex].parameter}" does not exist.`, `${transitionPath}.conditions[${conditionIndex}].parameter`, 'E_ANIMATION_3D_BINDING_MISMATCH');
688
- }
689
- }
690
- for (const [kind, values] of [['include', layer.mask?.include], ['exclude', layer.mask?.exclude]]) {
691
- for (let index = 0; index < (values?.length ?? 0); index++) {
692
- if (!bindingIds.has(values[index]))
693
- invalid(`Mask binding "${values[index]}" does not exist.`, `${layerPath}.mask.${kind}[${index}]`, 'E_ANIMATION_3D_BINDING_MISMATCH');
694
- }
695
- }
696
- }
697
- }
698
- function propertyContract(component, property, path) {
699
- const material = { baseColorFactor: ['vec4', 4], metallicFactor: ['scalar', 1], roughnessFactor: ['scalar', 1], emissiveFactor: ['vec3', 3], alphaCutoff: ['scalar', 1] };
700
- const camera = { fovYRadians: ['scalar', 1], near: ['scalar', 1], far: ['scalar', 1], orthoHeight: ['scalar', 1] };
701
- const contract = component === 'material3d'
702
- ? material[property]
703
- : camera[property];
704
- if (!contract)
705
- invalid(`Property "${property}" is not valid for ${component}.`, path, 'E_ANIMATION_3D_BINDING_MISMATCH');
706
- return { valueType: contract[0], valueSize: contract[1] };
707
- }
708
- function validateTrackQuaternions(values, keyCount, interpolation, path) {
709
- const stride = interpolation === 'cubic-spline' ? 12 : 4;
710
- const valueOffset = interpolation === 'cubic-spline' ? 4 : 0;
711
- for (let index = 0; index < keyCount; index++) {
712
- assertNormalizedQuaternion(values.slice(index * stride + valueOffset, index * stride + valueOffset + 4), `${path}[${index * stride + valueOffset}]`);
713
- }
714
- }
715
- function assertNormalizedQuaternion(value, path) {
716
- const length = Math.hypot(...value);
717
- if (Math.abs(length - 1) > 1e-4)
718
- invalid('Quaternion must be normalized XYZW.', path, 'E_ANIMATION_3D_BINDING_MISMATCH');
719
- }
720
- function pickCoreLimits(options) {
721
- const keys = ['maxInputBytes', 'maxMetadataBytes', 'maxNodes', 'maxComponents', 'maxTracks', 'maxKeyframes', 'maxResources', 'maxPathValues', 'maxTextCharacters', 'maxParticleCapacity'];
722
- const result = {};
723
- for (const key of keys)
724
- if (options[key] !== undefined)
725
- result[key] = options[key];
726
- return result;
727
- }
728
- function resolveLimits(options) {
729
- return Object.freeze({
730
- maxMaterials: positiveLimit(options.maxMaterials, DEFAULT_LIMITS.maxMaterials, 'maxMaterials'),
731
- maxNodes: positiveLimit(options.maxNodes, DEFAULT_LIMITS.maxNodes, 'maxNodes'),
732
- maxComponents: positiveLimit(options.maxComponents, DEFAULT_LIMITS.maxComponents, 'maxComponents'),
733
- maxClips: positiveLimit(options.maxClips, DEFAULT_LIMITS.maxClips, 'maxClips'),
734
- maxTracks: positiveLimit(options.maxTracks, DEFAULT_LIMITS.maxTracks, 'maxTracks'),
735
- maxKeyframes: positiveLimit(options.maxKeyframes, DEFAULT_LIMITS.maxKeyframes, 'maxKeyframes'),
736
- maxParticleCapacity: positiveLimit(options.maxParticleCapacity, DEFAULT_LIMITS.maxParticleCapacity, 'maxParticleCapacity'),
737
- maxStateMachineDepth: positiveLimit(options.maxStateMachineDepth, DEFAULT_LIMITS.maxStateMachineDepth, 'maxStateMachineDepth'),
738
- });
739
- }
740
- function positiveLimit(value, fallback, name) {
741
- if (value === undefined)
742
- return fallback;
743
- if (!Number.isSafeInteger(value) || value <= 0)
744
- throw new RangeError(`${name} must be a positive safe integer.`);
745
- return value;
746
- }
747
- function object(value, path, required = [], allowed) {
748
- if (!value || typeof value !== 'object' || Array.isArray(value))
749
- invalid('Expected an object.', path);
750
- const result = value;
751
- for (const key of required)
752
- if (!(key in result))
753
- invalid(`Missing required property "${key}".`, `${path}.${key}`);
754
- if (allowed) {
755
- const allowedSet = new Set(allowed);
756
- for (const key of Object.keys(result))
757
- if (!allowedSet.has(key))
758
- invalid(`Unknown property "${key}".`, `${path}.${key}`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
759
- }
760
- return result;
761
- }
762
- function array(value, path) {
763
- if (!Array.isArray(value))
764
- invalid('Expected an array.', path);
765
- return value;
766
- }
767
- function nonEmptyArray(value, path) {
768
- const result = array(value, path);
769
- if (result.length === 0)
770
- invalid('Expected at least one item.', path);
771
- return result;
772
- }
773
- function numericArray(value, path, minimumLength = 0) {
774
- const result = array(value, path);
775
- if (result.length < minimumLength)
776
- invalid(`Expected at least ${minimumLength} numeric value(s).`, path);
777
- return Object.freeze(result.map((entry, index) => finite(entry, `${path}[${index}]`)));
778
- }
779
- function vec2(value, path) {
780
- return tuple(value, path, 2);
781
- }
782
- function vec3(value, path, minimum = -Number.MAX_VALUE, maximum = Number.MAX_VALUE) {
783
- return tuple(value, path, 3, minimum, maximum);
784
- }
785
- function vec4(value, path, minimum = -Number.MAX_VALUE, maximum = Number.MAX_VALUE) {
786
- return tuple(value, path, 4, minimum, maximum);
787
- }
788
- function tuple(value, path, size, minimum = -Number.MAX_VALUE, maximum = Number.MAX_VALUE) {
789
- const result = array(value, path);
790
- if (result.length !== size)
791
- invalid(`Expected exactly ${size} numbers.`, path);
792
- return Object.freeze(result.map((entry, index) => bounded(entry, `${path}[${index}]`, minimum, maximum)));
793
- }
794
- function range(value, path, minimum = -Number.MAX_VALUE) {
795
- if (Array.isArray(value)) {
796
- const result = tuple(value, path, 2, minimum);
797
- if (result[0] > result[1])
798
- invalid('Range minimum cannot exceed maximum.', path);
799
- return result;
800
- }
801
- return bounded(value, path, minimum);
802
- }
803
- function finite(value, path) {
804
- if (typeof value !== 'number' || !Number.isFinite(value))
805
- invalid('Expected a finite number.', path);
806
- return value;
807
- }
808
- function positive(value, path) {
809
- const result = finite(value, path);
810
- if (result <= 0)
811
- invalid('Expected a positive number.', path);
812
- return result;
813
- }
814
- function nonNegative(value, path) {
815
- const result = finite(value, path);
816
- if (result < 0)
817
- invalid('Expected a non-negative number.', path);
818
- return result;
819
- }
820
- function bounded(value, path, minimum, maximum = Number.MAX_VALUE, inclusiveMaximum = true) {
821
- const result = finite(value, path);
822
- if (result < minimum || (inclusiveMaximum ? result > maximum : result >= maximum))
823
- invalid(`Expected a number in ${inclusiveMaximum ? '[' : '('}${minimum}, ${maximum}${inclusiveMaximum ? ']' : ')'}.`, path);
824
- return result;
825
- }
826
- function integer(value, path, minimum, maximum) {
827
- if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < minimum || value > maximum)
828
- invalid(`Expected a safe integer in [${minimum}, ${maximum}].`, path);
829
- return value;
830
- }
831
- function string(value, path) {
832
- if (typeof value !== 'string')
833
- invalid('Expected a string.', path);
834
- return value;
835
- }
836
- function nonEmpty(value, path) {
837
- const result = string(value, path);
838
- if (result.length === 0)
839
- invalid('Expected a non-empty string.', path);
840
- return result;
841
- }
842
- function boolean(value, path) {
843
- if (typeof value !== 'boolean')
844
- invalid('Expected a boolean.', path);
845
- return value;
846
- }
847
- function enumeration(value, values, path) {
848
- if (typeof value !== 'string' || !values.includes(value))
849
- invalid(`Expected one of ${values.join(', ')}.`, path);
850
- return value;
851
- }
852
- function exact(value, expected, path, code = 'E_ANIMATION_3D_INVALID_PAYLOAD') {
853
- if (value !== expected)
854
- invalid(`Expected ${JSON.stringify(expected)}.`, path, code);
855
- }
856
- function unique(seen, value, path, label) {
857
- if (seen.has(value))
858
- invalid(`Duplicate ${label} id "${value}".`, path, 'E_ANIMATION_3D_BINDING_MISMATCH');
859
- seen.add(value);
860
- }
861
- function budget(actual, maximum, label, path) {
862
- if (actual > maximum)
863
- invalid(`${label} count ${actual} exceeds limit ${maximum}.`, path, 'E_ANIMATION_3D_LIMIT_EXCEEDED');
864
- }
865
- function optionalStrings(item, path, keys) {
866
- const result = {};
867
- for (const key of keys)
868
- if (item[key] !== undefined)
869
- result[key] = nonEmpty(item[key], `${path}.${key}`);
870
- return result;
871
- }
872
- function parseJsonObject(value, path, depth = 0) {
873
- if (depth > 64)
874
- budget(depth, 64, 'event payload depth', path);
875
- const item = object(value, path);
876
- const result = {};
877
- for (const [key, child] of Object.entries(item))
878
- result[key] = parseJsonValue(child, `${path}.${key}`, depth + 1);
879
- return Object.freeze(result);
880
- }
881
- function parseJsonValue(value, path, depth) {
882
- if (value === null || typeof value === 'string' || typeof value === 'boolean')
883
- return value;
884
- if (typeof value === 'number')
885
- return finite(value, path);
886
- if (Array.isArray(value))
887
- return Object.freeze(value.map((child, index) => parseJsonValue(child, `${path}[${index}]`, depth + 1)));
888
- return parseJsonObject(value, path, depth);
889
- }
890
- function uriScheme(uri) {
891
- const match = /^([a-z][a-z0-9+.-]*):/i.exec(uri);
892
- return match?.[1]?.toLowerCase() ?? null;
893
- }
894
- function deepFreeze(value) {
895
- if (value && typeof value === 'object' && !Object.isFrozen(value)) {
896
- for (const child of Object.values(value))
897
- deepFreeze(child);
898
- Object.freeze(value);
899
- }
900
- return value;
901
- }
902
- function invalid(message, path, code = 'E_ANIMATION_3D_INVALID_PAYLOAD') {
903
- throw new Native3DAnimationFormatError(code, message, path);
904
- }
905
-
906
- export { NATIVE_3D_ANIMATION_EXTENSION_ID, NATIVE_3D_ANIMATION_FORMAT, NATIVE_3D_CLIP_FORMAT, NATIVE_3D_STATE_MACHINE_FORMAT, Native3DAnimationFormatError, createNative3DAnimationExtensionHandler, parseNative3DAnimation, parseNative3DAnimationPayload };
907
- //# sourceMappingURL=native3d.js.map
1
+ import{A as e}from"./chunks/extensions-DxL4AxOC.js";import{parseAnimation as t}from"./index.js";import"./chunks/errors-Bzs3GOD9.js";import"./chunks/expression-D1cKtNwM.js";import"./chunks/binary-DvuTJ_hy.js";const n="org.haiyue.animation-3d@1",a="haiyue-animation-3d@1",r="haiyue-animation3d-clip@1",i="haiyue-animation3d-state-machine@1";class o extends Error{code;path;name="Native3DAnimationFormatError";constructor(e,t,n){super(`${t} (${n})`),this.code=e,this.path=n}}const s=`$.extensions.${n}`,d=new Set(["model/gltf-binary","model/gltf+json"]),c=new Set(["blob","file","javascript"]),m=Object.freeze({maxMaterials:1e4,maxNodes:1e5,maxComponents:2e5,maxClips:1e4,maxTracks:2e5,maxKeyframes:5e6,maxParticleCapacity:2e6,maxStateMachineDepth:64});function l(e={},t){return Object.freeze({id:n,validateDocument(n){t?.(u(n,e))}})}function p(a,r={}){const i=new e;let m;i.register(l(r,e=>{m=e}));const p={..._(r),extensions:i,...void 0===r.copyFloatData?{}:{copyFloatData:r.copyFloatData}},u=t(a,p);if(!m)throw new o("E_ANIMATION_3D_INVALID_PAYLOAD",`Required extension "${n}" has no document payload.`,s);return function(e,t){1===e.extensionsUsed.length&&e.extensionsUsed[0]===n&&1===e.extensionsRequired.length&&e.extensionsRequired[0]===n||Y(`Native 3D carrier must use and require only "${n}".`,"$.extensionsRequired");e.nodes.length>0&&Y("Native 3D carrier cannot contain core 2D nodes.","$.nodes","E_ANIMATION_3D_MIXED_DIMENSIONS");e.tracks.length>0&&Y("Native 3D carrier cannot contain core 2D tracks.","$.tracks","E_ANIMATION_3D_MIXED_DIMENSIONS");e.canvas.width===t.viewport.width&&e.canvas.height===t.viewport.height||Y("Core canvas and native 3D viewport dimensions must match.",`${s}.viewport`);for(let n=0;n<t.nodes.length;n++){const a=t.nodes[n],r=a.start??0;(r>e.duration||r+(a.duration??e.duration-r)>e.duration+1e-6)&&Y("Node time range must fit inside composition duration.",`${s}.nodes[${n}]`)}for(let n=0;n<t.clips.length;n++)t.clips[n].duration>e.duration+1e-6&&Y("Clip duration must fit inside composition duration.",`${s}.clips[${n}].duration`)}(u,m),function(e,t){const n=new Map(e.map(e=>[e.id,e]));for(let t=0;t<e.length;t++){const n=L(e[t].uri);n&&c.has(n)&&Y(`Delivery URI scheme "${n}:" is forbidden.`,`$.resources[${t}].uri`,"E_ANIMATION_3D_UNKNOWN_RESOURCE")}for(let e=0;e<t.materials.length;e++){const a=t.materials[e];for(const t of["baseColorTexture","normalTexture","metallicRoughnessTexture","emissiveTexture"]){const r=a[t];if(void 0===r)continue;const i=n.get(r);i&&"image"===i.type||Y(`Material texture "${r}" must reference an image resource.`,`${s}.materials[${e}].${t}`,"E_ANIMATION_3D_UNKNOWN_RESOURCE")}}for(let e=0;e<t.nodes.length;e++){const a=t.nodes[e];for(let t=0;t<a.components.length;t++){const r=a.components[t],i=`${s}.nodes[${e}].components[${t}]`;if("model3d"===r.kind){const e=n.get(r.resource);e&&"binary"===e.type&&e.mimeType&&d.has(e.mimeType)||Y(`Model "${r.resource}" must reference a binary glTF/GLB resource.`,`${i}.resource`,"E_ANIMATION_3D_UNKNOWN_RESOURCE")}if("particle3d"===r.kind&&void 0!==r.descriptor.textureResource){const e=n.get(r.descriptor.textureResource);e&&"image"===e.type||Y(`Particle texture "${r.descriptor.textureResource}" must reference an image resource.`,`${i}.descriptor.textureResource`,"E_ANIMATION_3D_UNKNOWN_RESOURCE")}}}}(u.resources,m),Object.freeze({document:u,payload:m,resources:u.resources})}function u(e,t={}){const n=function(e){return Object.freeze({maxMaterials:v(e.maxMaterials,m.maxMaterials,"maxMaterials"),maxNodes:v(e.maxNodes,m.maxNodes,"maxNodes"),maxComponents:v(e.maxComponents,m.maxComponents,"maxComponents"),maxClips:v(e.maxClips,m.maxClips,"maxClips"),maxTracks:v(e.maxTracks,m.maxTracks,"maxTracks"),maxKeyframes:v(e.maxKeyframes,m.maxKeyframes,"maxKeyframes"),maxParticleCapacity:v(e.maxParticleCapacity,m.maxParticleCapacity,"maxParticleCapacity"),maxStateMachineDepth:v(e.maxStateMachineDepth,m.maxStateMachineDepth,"maxStateMachineDepth")})}(t),o=A(e,s,["format","mode","coordinateSystem","viewport","materials","nodes","clips"],["format","mode","coordinateSystem","viewport","materials","nodes","clips","stateMachine"]);P(o.format,a,`${s}.format`),P(o.mode,"native-3d",`${s}.mode`);const d=function(e,t){const n=A(e,t,["handedness","upAxis","forwardAxis","unit","angles","rotationStorage"],["handedness","upAxis","forwardAxis","unit","angles","rotationStorage"]);return P(n.handedness,"right",`${t}.handedness`),P(n.upAxis,"+y",`${t}.upAxis`),P(n.forwardAxis,"-z",`${t}.forwardAxis`),P(n.unit,"meter",`${t}.unit`),P(n.angles,"radian",`${t}.angles`),P(n.rotationStorage,"normalized-xyzw-quaternion",`${t}.rotationStorage`),Object.freeze({handedness:"right",upAxis:"+y",forwardAxis:"-z",unit:"meter",angles:"radian",rotationStorage:"normalized-xyzw-quaternion"})}(o.coordinateSystem,`${s}.coordinateSystem`),c=function(e,t){const n=A(e,t,["width","height"],["width","height"]);return Object.freeze({width:D(n.width,`${t}.width`),height:D(n.height,`${t}.height`)})}(o.viewport,`${s}.viewport`),l=b(o.materials,`${s}.materials`);B(l.length,n.maxMaterials,"materials",`${s}.materials`);const p=new Set,u=l.map((e,t)=>{const n=function(e,t){const n=A(e,t,["id","name","baseColorFactor","metallicFactor","roughnessFactor","emissiveFactor","alphaMode","doubleSided"],["id","name","baseColorFactor","metallicFactor","roughnessFactor","emissiveFactor","alphaMode","alphaCutoff","doubleSided","baseColorTexture","normalTexture","metallicRoughnessTexture","emissiveTexture"]);return Object.freeze({id:w(n.id,`${t}.id`),name:R(n.name,`${t}.name`),baseColorFactor:O(n.baseColorFactor,`${t}.baseColorFactor`,0,1),metallicFactor:C(n.metallicFactor,`${t}.metallicFactor`,0,1),roughnessFactor:C(n.roughnessFactor,`${t}.roughnessFactor`,0,1),emissiveFactor:T(n.emissiveFactor,`${t}.emissiveFactor`,0),alphaMode:F(n.alphaMode,["opaque","mask","blend"],`${t}.alphaMode`),...void 0===n.alphaCutoff?{}:{alphaCutoff:C(n.alphaCutoff,`${t}.alphaCutoff`,0,1)},doubleSided:U(n.doubleSided,`${t}.doubleSided`),...G(n,t,["baseColorTexture","normalTexture","metallicRoughnessTexture","emissiveTexture"])})}(e,`${s}.materials[${t}]`);return H(p,n.id,`${s}.materials[${t}].id`,"material"),n}),_=b(o.nodes,`${s}.nodes`);B(_.length,n.maxNodes,"nodes",`${s}.nodes`);const x=new Set,y=new Set;let S=0,E=0;const X=_.map((e,t)=>{const a=`${s}.nodes[${t}]`,r=function(e,t){const n=A(e,t,["id","name","transform","components"],["id","name","parent","start","duration","transform","components"]),a=b(n.components,`${t}.components`).map((e,n)=>function(e,t){const n=A(e,t).kind;if("camera3d"===n){const a=A(e,t,["id","kind","projection"],["id","kind","projection"]);return Object.freeze({id:w(a.id,`${t}.id`),kind:n,projection:f(a.projection,`${t}.projection`)})}if("primitive3d"===n){const a=A(e,t,["id","kind","primitive","materialId"],["id","kind","primitive","materialId"]);return Object.freeze({id:w(a.id,`${t}.id`),kind:n,primitive:F(a.primitive,["box","sphere","plane","cylinder","cone"],`${t}.primitive`),materialId:w(a.materialId,`${t}.materialId`)})}if("model3d"===n){const a=A(e,t,["id","kind","resource"],["id","kind","resource","materialOverrides"]),r=void 0===a.materialOverrides?void 0:b(a.materialOverrides,`${t}.materialOverrides`).map((e,n)=>{const a=`${t}.materialOverrides[${n}]`,r=A(e,a,["slot","materialId"],["slot","materialId"]);return Object.freeze({slot:w(r.slot,`${a}.slot`),materialId:w(r.materialId,`${a}.materialId`)})});return Object.freeze({id:w(a.id,`${t}.id`),kind:n,resource:w(a.resource,`${t}.resource`),...r?{materialOverrides:Object.freeze(r)}:{}})}if("particle3d"===n){const a=A(e,t,["id","kind","descriptor"],["id","kind","descriptor"]);return Object.freeze({id:w(a.id,`${t}.id`),kind:n,descriptor:h(a.descriptor,`${t}.descriptor`)})}Y(`Unsupported component kind "${String(n)}".`,`${t}.kind`,"E_ANIMATION_3D_UNSUPPORTED_FEATURE")}(e,`${t}.components[${n}]`));return Object.freeze({id:w(n.id,`${t}.id`),name:R(n.name,`${t}.name`),...void 0===n.parent?{}:{parent:w(n.parent,`${t}.parent`)},...void 0===n.start?{}:{start:z(n.start,`${t}.start`)},...void 0===n.duration?{}:{duration:D(n.duration,`${t}.duration`)},transform:$(n.transform,`${t}.transform`),components:Object.freeze(a)})}(e,a);H(x,r.id,`${a}.id`,"node");for(let e=0;e<r.components.length;e++){const t=r.components[e];H(y,t.id,`${a}.components[${e}].id`,"component"),S++,"particle3d"===t.kind&&(E+=t.descriptor.maxParticles)}return B(S,n.maxComponents,"components",`${a}.components`),B(E,n.maxParticleCapacity,"particle capacity",`${a}.components`),r});!function(e,t,n){const a=new Map(e.map(e=>[e.id,e]));for(let a=0;a<e.length;a++){const r=e[a];void 0===r.parent||t.has(r.parent)||Y(`Node parent "${r.parent}" does not exist.`,`${s}.nodes[${a}].parent`,"E_ANIMATION_3D_BINDING_MISMATCH"),r.parent===r.id&&Y("Node cannot parent itself.",`${s}.nodes[${a}].parent`,"E_ANIMATION_3D_BINDING_MISMATCH");for(let e=0;e<r.components.length;e++){const t=r.components[e],i=`${s}.nodes[${a}].components[${e}]`;if("primitive3d"!==t.kind||n.has(t.materialId)||Y(`Primitive material "${t.materialId}" does not exist.`,`${i}.materialId`,"E_ANIMATION_3D_UNKNOWN_RESOURCE"),"model3d"===t.kind)for(let e=0;e<(t.materialOverrides?.length??0);e++){const a=t.materialOverrides[e].materialId;n.has(a)||Y(`Material override "${a}" does not exist.`,`${i}.materialOverrides[${e}].materialId`,"E_ANIMATION_3D_UNKNOWN_RESOURCE")}}}for(const t of e){const e=new Set;let n=t;for(;n?.parent;)e.has(n.id)&&Y("Node hierarchy contains a cycle.",`${s}.nodes`,"E_ANIMATION_3D_BINDING_MISMATCH"),e.add(n.id),n=a.get(n.parent)}}(X,x,p);const L=b(o.clips,`${s}.clips`);B(L.length,n.maxClips,"clips",`${s}.clips`);const K=new Set,W=new Set;let J=0,Q=0;const Z=L.map((e,t)=>{const a=`${s}.clips[${t}]`,i=function(e,t){const n=A(e,t,["format","id","name","duration","tracks","events"],["format","id","name","duration","tracks","events"]);P(n.format,r,`${t}.format`);const a=D(n.duration,`${t}.duration`),i=new Set,o=b(n.tracks,`${t}.tracks`).map((e,n)=>{const r=`${t}.tracks[${n}]`,o=function(e,t,n){const a=A(e,t,["id","binding","interpolation","times","values"],["id","binding","interpolation","times","values"]),r=function(e,t){const n=A(e,t),a=function(e,t){const n=A(e,t).kind;if("node-id"===n){const a=A(e,t,["kind","nodeId"],["kind","nodeId"]);return Object.freeze({kind:n,nodeId:w(a.nodeId,`${t}.nodeId`)})}if("node-path"===n){const a=b(A(e,t,["kind","segments"],["kind","segments"]).segments,`${t}.segments`);return 0===a.length&&Y("Node path must contain at least one segment.",`${t}.segments`),Object.freeze({kind:n,segments:Object.freeze(a.map((e,n)=>w(e,`${t}.segments[${n}]`)))})}if("slot"===n){const a=A(e,t,["kind","slot"],["kind","slot"]);return Object.freeze({kind:n,slot:w(a.slot,`${t}.slot`)})}Y(`Unsupported binding target "${String(n)}".`,`${t}.kind`,"E_ANIMATION_3D_UNSUPPORTED_FEATURE")}(n.target,`${t}.target`),r=w(n.id,`${t}.id`);if("transform.translation"===n.path||"transform.scale"===n.path){const i=A(e,t,["id","target","path","valueType","valueSize"],["id","target","path","valueType","valueSize"]);return P(i.valueType,"vec3",`${t}.valueType`),P(i.valueSize,3,`${t}.valueSize`,"E_ANIMATION_3D_BINDING_MISMATCH"),Object.freeze({id:r,target:a,path:n.path,valueType:"vec3",valueSize:3})}if("transform.rotation"===n.path){const i=A(e,t,["id","target","path","valueType","valueSize"],["id","target","path","valueType","valueSize"]);return P(i.valueType,"quaternion",`${t}.valueType`),P(i.valueSize,4,`${t}.valueSize`,"E_ANIMATION_3D_BINDING_MISMATCH"),Object.freeze({id:r,target:a,path:n.path,valueType:"quaternion",valueSize:4})}if("morph.weights"===n.path){const i=A(e,t,["id","target","path","valueType","valueSize"],["id","target","path","valueType","valueSize"]);return P(i.valueType,"weights",`${t}.valueType`),Object.freeze({id:r,target:a,path:n.path,valueType:"weights",valueSize:j(i.valueSize,`${t}.valueSize`,1,65536)})}if("property"===n.path){const n=A(e,t,["id","target","path","component","property","valueType","valueSize"],["id","target","path","component","property","valueType","valueSize"]),i=F(n.component,["material3d","camera3d"],`${t}.component`),o=F(n.property,["baseColorFactor","metallicFactor","roughnessFactor","emissiveFactor","alphaCutoff","fovYRadians","near","far","orthoHeight"],`${t}.property`),s=function(e,t,n){const a={baseColorFactor:["vec4",4],metallicFactor:["scalar",1],roughnessFactor:["scalar",1],emissiveFactor:["vec3",3],alphaCutoff:["scalar",1]},r={fovYRadians:["scalar",1],near:["scalar",1],far:["scalar",1],orthoHeight:["scalar",1]},i="material3d"===e?a[t]:r[t];i||Y(`Property "${t}" is not valid for ${e}.`,n,"E_ANIMATION_3D_BINDING_MISMATCH");return{valueType:i[0],valueSize:i[1]}}(i,o,`${t}.property`);return P(n.valueType,s.valueType,`${t}.valueType`,"E_ANIMATION_3D_BINDING_MISMATCH"),P(n.valueSize,s.valueSize,`${t}.valueSize`,"E_ANIMATION_3D_BINDING_MISMATCH"),Object.freeze({id:r,target:a,path:"property",component:i,property:o,...s})}Y(`Unsupported binding path "${String(n.path)}".`,`${t}.path`,"E_ANIMATION_3D_UNSUPPORTED_FEATURE")}(a.binding,`${t}.binding`),i=F(a.interpolation,["step","linear","cubic-spline"],`${t}.interpolation`),o=M(a.times,`${t}.times`,1);for(let e=0;e<o.length;e++){const a=o[e];(a<0||a>n)&&Y("Track time must lie within clip duration.",`${t}.times[${e}]`,"E_ANIMATION_3D_BINDING_MISMATCH"),e>0&&a<=o[e-1]&&Y("Track times must be strictly increasing.",`${t}.times[${e}]`,"E_ANIMATION_3D_BINDING_MISMATCH")}const s=M(a.values,`${t}.values`,1),d=o.length*r.valueSize*("cubic-spline"===i?3:1);s.length!==d&&Y(`Track values length ${s.length} does not match expected ${d}.`,`${t}.values`,"E_ANIMATION_3D_BINDING_MISMATCH");"transform.rotation"===r.path&&function(e,t,n,a){const r="cubic-spline"===n?12:4,i="cubic-spline"===n?4:0;for(let n=0;n<t;n++)g(e.slice(n*r+i,n*r+i+4),`${a}[${n*r+i}]`)}(s,o.length,i,`${t}.values`);return Object.freeze({id:w(a.id,`${t}.id`),binding:r,interpolation:i,times:o,values:s})}(e,r,a);return H(i,o.id,`${r}.id`,"track"),o}),s=new Set,d=b(n.events,`${t}.events`).map((e,n)=>{const r=`${t}.events[${n}]`,i=function(e,t,n){const a=A(e,t,["id","time","name"],["id","time","name","payload"]),r=z(a.time,`${t}.time`);r>n&&Y("Event time must lie within clip duration.",`${t}.time`);return Object.freeze({id:w(a.id,`${t}.id`),time:r,name:w(a.name,`${t}.name`),...void 0===a.payload?{}:{payload:V(a.payload,`${t}.payload`)}})}(e,r,a);return H(s,i.id,`${r}.id`,"event"),i});return Object.freeze({format:r,id:w(n.id,`${t}.id`),name:R(n.name,`${t}.name`),duration:a,tracks:Object.freeze(o),events:Object.freeze(d)})}(e,a);H(K,i.id,`${a}.id`,"clip"),J+=i.tracks.length,Q+=i.tracks.reduce((e,t)=>e+t.times.length,0),B(J,n.maxTracks,"tracks",`${a}.tracks`),B(Q,n.maxKeyframes,"keyframes",`${a}.tracks`);const o=new Set;for(let e=0;e<i.tracks.length;e++){const t=i.tracks[e];H(o,t.binding.id,`${a}.tracks[${e}].binding.id`,"binding"),W.add(t.binding.id),N(t.binding,X,p,`${a}.tracks[${e}].binding`)}return i}),ee=void 0===o.stateMachine||null===o.stateMachine?o.stateMachine:function(e,t,n){const a=A(e,t,["format","id","name","parameters","layers"],["format","id","name","parameters","layers"]);P(a.format,i,`${t}.format`);const r=new Set,o=b(a.parameters,`${t}.parameters`).map((e,n)=>{const a=`${t}.parameters[${n}]`,i=function(e,t){const n=A(e,t),a=w(n.name,`${t}.name`);if("trigger"===n.type)return A(e,t,["name","type"],["name","type"]),Object.freeze({name:a,type:"trigger"});if(A(e,t,["name","type","defaultValue"],["name","type","defaultValue"]),"float"===n.type)return Object.freeze({name:a,type:"float",defaultValue:k(n.defaultValue,`${t}.defaultValue`)});if("integer"===n.type)return Object.freeze({name:a,type:"integer",defaultValue:j(n.defaultValue,`${t}.defaultValue`,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER)});if("boolean"===n.type)return Object.freeze({name:a,type:"boolean",defaultValue:U(n.defaultValue,`${t}.defaultValue`)});Y(`Unsupported parameter type "${String(n.type)}".`,`${t}.type`,"E_ANIMATION_3D_UNSUPPORTED_FEATURE")}(e,a);return H(r,i.name,`${a}.name`,"state-machine parameter"),i}),s=new Set,d=b(a.layers,`${t}.layers`).map((e,a)=>{const r=`${t}.layers[${a}]`,i=function(e,t,n){const a=A(e,t,["id","name","initialStateId","states","transitions"],["id","name","initialStateId","states","transitions","blendMode","weight","mask"]),r=new Set,i=b(a.states,`${t}.states`).map((e,a)=>{const i=`${t}.states[${a}]`,o=function(e,t,n){const a=A(e,t,["id","name","motion"],["id","name","motion","speed","speedParameter","loop"]);return Object.freeze({id:w(a.id,`${t}.id`),name:R(a.name,`${t}.name`),motion:I(a.motion,`${t}.motion`,0,n),...void 0===a.speed?{}:{speed:k(a.speed,`${t}.speed`)},...void 0===a.speedParameter?{}:{speedParameter:w(a.speedParameter,`${t}.speedParameter`)},...void 0===a.loop?{}:{loop:F(a.loop,["once","repeat","ping-pong"],`${t}.loop`)}})}(e,i,n);return H(r,o.id,`${i}.id`,"state"),o}),o=new Set,s=b(a.transitions,`${t}.transitions`).map((e,n)=>{const a=`${t}.transitions[${n}]`,r=function(e,t){const n=A(e,t,["id","from","to","conditions","duration"],["id","from","to","conditions","duration","hasExitTime","exitTime","destinationOffset","interruption"]),a=b(n.conditions,`${t}.conditions`).map((e,n)=>function(e,t){const n=A(e,t,["parameter","operator"],["parameter","operator","value"]),a=F(n.operator,["greater","greater-or-equal","less","less-or-equal","equal","not-equal","is-true","is-false","triggered"],`${t}.operator`);return Object.freeze({parameter:w(n.parameter,`${t}.parameter`),operator:a,...void 0===n.value?{}:{value:"boolean"==typeof n.value?n.value:k(n.value,`${t}.value`)}})}(e,`${t}.conditions[${n}]`));return Object.freeze({id:w(n.id,`${t}.id`),from:w(n.from,`${t}.from`),to:w(n.to,`${t}.to`),conditions:Object.freeze(a),duration:z(n.duration,`${t}.duration`),...void 0===n.hasExitTime?{}:{hasExitTime:U(n.hasExitTime,`${t}.hasExitTime`)},...void 0===n.exitTime?{}:{exitTime:z(n.exitTime,`${t}.exitTime`)},...void 0===n.destinationOffset?{}:{destinationOffset:z(n.destinationOffset,`${t}.destinationOffset`)},...void 0===n.interruption?{}:{interruption:F(n.interruption,["none","source","destination","source-then-destination","destination-then-source"],`${t}.interruption`)}})}(e,a);return H(o,r.id,`${a}.id`,"transition"),r}),d=void 0===a.mask?void 0:function(e,t){const n=A(e,t,[],["include","exclude"]),a=(e,t)=>{const n=new Set;return Object.freeze(b(e,t).map((e,a)=>{const r=w(e,`${t}[${a}]`);return H(n,r,`${t}[${a}]`,"mask binding"),r}))};return Object.freeze({...void 0===n.include?{}:{include:a(n.include,`${t}.include`)},...void 0===n.exclude?{}:{exclude:a(n.exclude,`${t}.exclude`)}})}(a.mask,`${t}.mask`);return Object.freeze({id:w(a.id,`${t}.id`),name:R(a.name,`${t}.name`),initialStateId:w(a.initialStateId,`${t}.initialStateId`),states:Object.freeze(i),transitions:Object.freeze(s),...void 0===a.blendMode?{}:{blendMode:F(a.blendMode,["override","additive"],`${t}.blendMode`)},...void 0===a.weight?{}:{weight:C(a.weight,`${t}.weight`,0,1)},...d?{mask:d}:{}})}(e,r,n);return H(s,i.id,`${r}.id`,"state-machine layer"),i});return Object.freeze({format:i,id:w(a.id,`${t}.id`),name:R(a.name,`${t}.name`),parameters:Object.freeze(o),layers:Object.freeze(d)})}(o.stateMachine,`${s}.stateMachine`,n.maxStateMachineDepth);return ee&&function(e,t,n,a){const r=new Set(e.parameters.map(e=>e.name)),i=(e,n)=>{if("clip"!==e.kind)for(let t=0;t<e.children.length;t++)i(e.children[t].motion,`${n}.children[${t}].motion`);else t.has(e.clipId)||Y(`Motion clip "${e.clipId}" does not exist.`,`${n}.clipId`,"E_ANIMATION_3D_BINDING_MISMATCH")};for(let t=0;t<e.layers.length;t++){const o=e.layers[t],s=`${a}.layers[${t}]`,d=new Set(o.states.map(e=>e.id));d.has(o.initialStateId)||Y(`Initial state "${o.initialStateId}" does not exist.`,`${s}.initialStateId`,"E_ANIMATION_3D_BINDING_MISMATCH");for(let e=0;e<o.states.length;e++){const t=o.states[e];i(t.motion,`${s}.states[${e}].motion`),t.speedParameter&&!r.has(t.speedParameter)&&Y(`Speed parameter "${t.speedParameter}" does not exist.`,`${s}.states[${e}].speedParameter`,"E_ANIMATION_3D_BINDING_MISMATCH")}for(let e=0;e<o.transitions.length;e++){const t=o.transitions[e],n=`${s}.transitions[${e}]`;"*"===t.from||d.has(t.from)||Y(`Transition source "${t.from}" does not exist.`,`${n}.from`,"E_ANIMATION_3D_BINDING_MISMATCH"),d.has(t.to)||Y(`Transition destination "${t.to}" does not exist.`,`${n}.to`,"E_ANIMATION_3D_BINDING_MISMATCH");for(let e=0;e<t.conditions.length;e++)r.has(t.conditions[e].parameter)||Y(`Condition parameter "${t.conditions[e].parameter}" does not exist.`,`${n}.conditions[${e}].parameter`,"E_ANIMATION_3D_BINDING_MISMATCH")}for(const[e,t]of[["include",o.mask?.include],["exclude",o.mask?.exclude]])for(let a=0;a<(t?.length??0);a++)n.has(t[a])||Y(`Mask binding "${t[a]}" does not exist.`,`${s}.mask.${e}[${a}]`,"E_ANIMATION_3D_BINDING_MISMATCH")}}(ee,K,W,`${s}.stateMachine`),q({format:a,mode:"native-3d",coordinateSystem:d,viewport:c,materials:u,nodes:X,clips:Z,...void 0===o.stateMachine?{}:{stateMachine:ee??null}})}function $(e,t){const n=A(e,t,["translation","rotation","scale"],["translation","rotation","scale"]),a=O(n.rotation,`${t}.rotation`);return g(a,`${t}.rotation`),Object.freeze({translation:T(n.translation,`${t}.translation`),rotation:a,scale:T(n.scale,`${t}.scale`)})}function f(e,t){const n=A(e,t).kind;if("perspective"===n){const a=A(e,t,["kind","fovYRadians","near","far"],["kind","fovYRadians","near","far"]),r=D(a.near,`${t}.near`),i=D(a.far,`${t}.far`);return i<=r&&Y("Camera far must be greater than near.",`${t}.far`),Object.freeze({kind:n,fovYRadians:C(a.fovYRadians,`${t}.fovYRadians`,Number.MIN_VALUE,Math.PI,!1),near:r,far:i})}if("orthographic"===n){const a=A(e,t,["kind","orthoHeight","near","far"],["kind","orthoHeight","near","far"]),r=z(a.near,`${t}.near`),i=D(a.far,`${t}.far`);return i<=r&&Y("Camera far must be greater than near.",`${t}.far`),Object.freeze({kind:n,orthoHeight:D(a.orthoHeight,`${t}.orthoHeight`),near:r,far:i})}Y(`Unsupported camera projection "${String(n)}".`,`${t}.kind`,"E_ANIMATION_3D_UNSUPPORTED_FEATURE")}function h(e,t){const n=["maxParticles","emissionRate","burst","duration","loop","seed","lifetime","speed","direction","spread","gravity","startSize","endSize","rotation","angularVelocity","startColor","endColor","shape","blendMode","radial","opacity","depthTest","depthWrite","sortMode"],a=A(e,t,n,[...n,"shapeSize","shapeRadius","textureResource"]);return Object.freeze({maxParticles:j(a.maxParticles,`${t}.maxParticles`,1,1e6),emissionRate:z(a.emissionRate,`${t}.emissionRate`),burst:j(a.burst,`${t}.burst`,0,1e6),duration:D(a.duration,`${t}.duration`),loop:U(a.loop,`${t}.loop`),seed:j(a.seed,`${t}.seed`,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),lifetime:E(a.lifetime,`${t}.lifetime`,0),speed:E(a.speed,`${t}.speed`),direction:T(a.direction,`${t}.direction`),spread:C(a.spread,`${t}.spread`,0,Math.PI),gravity:T(a.gravity,`${t}.gravity`),startSize:E(a.startSize,`${t}.startSize`,0),endSize:E(a.endSize,`${t}.endSize`,0),rotation:E(a.rotation,`${t}.rotation`),angularVelocity:E(a.angularVelocity,`${t}.angularVelocity`),startColor:O(a.startColor,`${t}.startColor`,0,1),endColor:O(a.endColor,`${t}.endColor`,0,1),shape:F(a.shape,["point","box","sphere"],`${t}.shape`),...void 0===a.shapeSize?{}:{shapeSize:T(a.shapeSize,`${t}.shapeSize`,0)},...void 0===a.shapeRadius?{}:{shapeRadius:z(a.shapeRadius,`${t}.shapeRadius`)},blendMode:F(a.blendMode,["normal","additive"],`${t}.blendMode`),...void 0===a.textureResource?{}:{textureResource:w(a.textureResource,`${t}.textureResource`)},radial:U(a.radial,`${t}.radial`),opacity:C(a.opacity,`${t}.opacity`,0,1),depthTest:U(a.depthTest,`${t}.depthTest`),depthWrite:U(a.depthWrite,`${t}.depthWrite`),sortMode:F(a.sortMode,["none","back-to-front"],`${t}.sortMode`)})}function I(e,t,n,a){n>=a&&B(n+1,a,"state-machine motion depth",t);const r=A(e,t);if("clip"===r.kind){const n=A(e,t,["kind","clipId"],["kind","clipId"]);return Object.freeze({kind:"clip",clipId:w(n.clipId,`${t}.clipId`)})}if("blend-1d"===r.kind){const r=A(e,t,["kind","parameter","children"],["kind","parameter","children"]),i=x(r.children,`${t}.children`).map((e,r)=>{const i=`${t}.children[${r}]`,o=A(e,i,["threshold","motion"],["threshold","motion"]);return Object.freeze({threshold:k(o.threshold,`${i}.threshold`),motion:I(o.motion,`${i}.motion`,n+1,a)})});return Object.freeze({kind:"blend-1d",parameter:w(r.parameter,`${t}.parameter`),children:Object.freeze(i)})}if("blend-2d"===r.kind){const r=A(e,t,["kind","algorithm","parameterX","parameterY","children"],["kind","algorithm","parameterX","parameterY","children"]),i=x(r.children,`${t}.children`).map((e,r)=>{const i=`${t}.children[${r}]`,o=A(e,i,["position","motion"],["position","motion"]);return Object.freeze({position:y(o.position,`${i}.position`),motion:I(o.motion,`${i}.motion`,n+1,a)})});return Object.freeze({kind:"blend-2d",algorithm:F(r.algorithm,["cartesian","directional"],`${t}.algorithm`),parameterX:w(r.parameterX,`${t}.parameterX`),parameterY:w(r.parameterY,`${t}.parameterY`),children:Object.freeze(i)})}Y(`Unsupported motion kind "${String(r.kind)}".`,`${t}.kind`,"E_ANIMATION_3D_UNSUPPORTED_FEATURE")}function N(e,t,n,a){const r=new Map(t.map(e=>[e.id,e])),i=e.target;"node-id"!==i.kind||r.has(i.nodeId)||Y(`Binding node "${i.nodeId}" does not exist.`,`${a}.target.nodeId`,"E_ANIMATION_3D_BINDING_MISMATCH"),"node-path"!==i.kind||r.has(i.segments[0])||Y(`Binding node path root "${i.segments[0]}" does not exist.`,`${a}.target.segments[0]`,"E_ANIMATION_3D_BINDING_MISMATCH"),"property"===e.path&&"material3d"===e.component&&("slot"===i.kind&&n.has(i.slot)||Y("Material property bindings require a material-id slot target.",`${a}.target`,"E_ANIMATION_3D_BINDING_MISMATCH")),"property"===e.path&&"camera3d"===e.component&&("node-id"===i.kind&&r.get(i.nodeId)?.components.some(e=>"camera3d"===e.kind)||Y("Camera property bindings require a node-id target with Camera3D.",`${a}.target`,"E_ANIMATION_3D_BINDING_MISMATCH"))}function g(e,t){const n=Math.hypot(...e);Math.abs(n-1)>1e-4&&Y("Quaternion must be normalized XYZW.",t,"E_ANIMATION_3D_BINDING_MISMATCH")}function _(e){const t=["maxInputBytes","maxMetadataBytes","maxNodes","maxComponents","maxTracks","maxKeyframes","maxResources","maxPathValues","maxTextCharacters","maxParticleCapacity"],n={};for(const a of t)void 0!==e[a]&&(n[a]=e[a]);return n}function v(e,t,n){if(void 0===e)return t;if(!Number.isSafeInteger(e)||e<=0)throw new RangeError(`${n} must be a positive safe integer.`);return e}function A(e,t,n=[],a){e&&"object"==typeof e&&!Array.isArray(e)||Y("Expected an object.",t);const r=e;for(const e of n)e in r||Y(`Missing required property "${e}".`,`${t}.${e}`);if(a){const e=new Set(a);for(const n of Object.keys(r))e.has(n)||Y(`Unknown property "${n}".`,`${t}.${n}`,"E_ANIMATION_3D_UNSUPPORTED_FEATURE")}return r}function b(e,t){return Array.isArray(e)||Y("Expected an array.",t),e}function x(e,t){const n=b(e,t);return 0===n.length&&Y("Expected at least one item.",t),n}function M(e,t,n=0){const a=b(e,t);return a.length<n&&Y(`Expected at least ${n} numeric value(s).`,t),Object.freeze(a.map((e,n)=>k(e,`${t}[${n}]`)))}function y(e,t){return S(e,t,2)}function T(e,t,n=-Number.MAX_VALUE,a=Number.MAX_VALUE){return S(e,t,3,n,a)}function O(e,t,n=-Number.MAX_VALUE,a=Number.MAX_VALUE){return S(e,t,4,n,a)}function S(e,t,n,a=-Number.MAX_VALUE,r=Number.MAX_VALUE){const i=b(e,t);return i.length!==n&&Y(`Expected exactly ${n} numbers.`,t),Object.freeze(i.map((e,n)=>C(e,`${t}[${n}]`,a,r)))}function E(e,t,n=-Number.MAX_VALUE){if(Array.isArray(e)){const a=S(e,t,2,n);return a[0]>a[1]&&Y("Range minimum cannot exceed maximum.",t),a}return C(e,t,n)}function k(e,t){return"number"==typeof e&&Number.isFinite(e)||Y("Expected a finite number.",t),e}function D(e,t){const n=k(e,t);return n<=0&&Y("Expected a positive number.",t),n}function z(e,t){const n=k(e,t);return n<0&&Y("Expected a non-negative number.",t),n}function C(e,t,n,a=Number.MAX_VALUE,r=!0){const i=k(e,t);return(i<n||(r?i>a:i>=a))&&Y(`Expected a number in ${r?"[":"("}${n}, ${a}${r?"]":")"}.`,t),i}function j(e,t,n,a){return("number"!=typeof e||!Number.isSafeInteger(e)||e<n||e>a)&&Y(`Expected a safe integer in [${n}, ${a}].`,t),e}function R(e,t){return"string"!=typeof e&&Y("Expected a string.",t),e}function w(e,t){const n=R(e,t);return 0===n.length&&Y("Expected a non-empty string.",t),n}function U(e,t){return"boolean"!=typeof e&&Y("Expected a boolean.",t),e}function F(e,t,n){return"string"==typeof e&&t.includes(e)||Y(`Expected one of ${t.join(", ")}.`,n),e}function P(e,t,n,a="E_ANIMATION_3D_INVALID_PAYLOAD"){e!==t&&Y(`Expected ${JSON.stringify(t)}.`,n,a)}function H(e,t,n,a){e.has(t)&&Y(`Duplicate ${a} id "${t}".`,n,"E_ANIMATION_3D_BINDING_MISMATCH"),e.add(t)}function B(e,t,n,a){e>t&&Y(`${n} count ${e} exceeds limit ${t}.`,a,"E_ANIMATION_3D_LIMIT_EXCEEDED")}function G(e,t,n){const a={};for(const r of n)void 0!==e[r]&&(a[r]=w(e[r],`${t}.${r}`));return a}function V(e,t,n=0){n>64&&B(n,64,"event payload depth",t);const a=A(e,t),r={};for(const[e,i]of Object.entries(a))r[e]=X(i,`${t}.${e}`,n+1);return Object.freeze(r)}function X(e,t,n){return null===e||"string"==typeof e||"boolean"==typeof e?e:"number"==typeof e?k(e,t):Array.isArray(e)?Object.freeze(e.map((e,a)=>X(e,`${t}[${a}]`,n+1))):V(e,t,n)}function L(e){const t=/^([a-z][a-z0-9+.-]*):/i.exec(e);return t?.[1]?.toLowerCase()??null}function q(e){if(e&&"object"==typeof e&&!Object.isFrozen(e)){for(const t of Object.values(e))q(t);Object.freeze(e)}return e}function Y(e,t,n="E_ANIMATION_3D_INVALID_PAYLOAD"){throw new o(n,e,t)}export{n as NATIVE_3D_ANIMATION_EXTENSION_ID,a as NATIVE_3D_ANIMATION_FORMAT,r as NATIVE_3D_CLIP_FORMAT,i as NATIVE_3D_STATE_MACHINE_FORMAT,o as Native3DAnimationFormatError,l as createNative3DAnimationExtensionHandler,p as parseNative3DAnimation,u as parseNative3DAnimationPayload};//# sourceMappingURL=native3d.js.map