alpha2 0.4.5 → 0.5.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.
- package/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +48 -0
- package/dist/active-clock.d.ts +35 -0
- package/dist/active-clock.js +99 -0
- package/dist/assets.d.ts +28 -22
- package/dist/assets.js +8 -12
- package/dist/audio-layout.d.ts +52 -74
- package/dist/audio-layout.js +114 -148
- package/dist/audio-timeline.d.ts +89 -117
- package/dist/audio-timeline.js +102 -118
- package/dist/audio-worker.d.ts +12 -21
- package/dist/audio-worker.js +8 -13
- package/dist/audio-worklet-processor.js +45 -58
- package/dist/audio-worklet.d.ts +45 -76
- package/dist/audio-worklet.js +44 -79
- package/dist/audio.d.ts +15 -23
- package/dist/audio.js +9 -13
- package/dist/builder.d.ts +45 -63
- package/dist/builder.js +49 -45
- package/dist/capabilities.d.ts +99 -16
- package/dist/capabilities.js +2 -2
- package/dist/captions.d.ts +45 -22
- package/dist/captions.js +60 -15
- package/dist/chroma-siting.d.ts +24 -41
- package/dist/chroma-siting.js +38 -71
- package/dist/containers.d.ts +41 -30
- package/dist/containers.js +59 -27
- package/dist/decoder-fallback.d.ts +13 -0
- package/dist/decoder-fallback.js +38 -0
- package/dist/decoder-order.d.ts +24 -39
- package/dist/decoder-order.js +28 -42
- package/dist/edit.d.ts +77 -154
- package/dist/edit.js +98 -180
- package/dist/effects.d.ts +109 -173
- package/dist/effects.js +7 -9
- package/dist/export-destination.d.ts +25 -41
- package/dist/export-destination.js +20 -32
- package/dist/export-failure.d.ts +34 -59
- package/dist/export-failure.js +54 -48
- package/dist/export-metrics.d.ts +116 -0
- package/dist/export-metrics.js +74 -0
- package/dist/export-retry.d.ts +46 -29
- package/dist/export-retry.js +86 -51
- package/dist/exporter.d.ts +67 -116
- package/dist/exporter.js +133 -133
- package/dist/extensions.d.ts +69 -115
- package/dist/extensions.js +55 -82
- package/dist/frame-intake.d.ts +92 -0
- package/dist/frame-intake.js +114 -0
- package/dist/frame-supply.d.ts +98 -157
- package/dist/frame-supply.js +191 -162
- package/dist/generated/project-schema.d.ts +742 -464
- package/dist/generated/project-schema.js +63 -2
- package/dist/generated/project-shape.js +663 -118
- package/dist/geometry.d.ts +28 -34
- package/dist/geometry.js +18 -23
- package/dist/gpu-recovery.d.ts +92 -0
- package/dist/gpu-recovery.js +135 -0
- package/dist/hdr-frames.d.ts +88 -62
- package/dist/hdr-frames.js +123 -46
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/json-text.d.ts +13 -23
- package/dist/json-text.js +10 -20
- package/dist/layout-values.d.ts +14 -22
- package/dist/layout-values.js +18 -21
- package/dist/layout.d.ts +55 -55
- package/dist/layout.js +37 -36
- package/dist/loudness.d.ts +27 -32
- package/dist/loudness.js +19 -23
- package/dist/media.d.ts +85 -237
- package/dist/media.js +133 -287
- package/dist/mediabunny.d.ts +173 -237
- package/dist/mediabunny.js +943 -518
- package/dist/physical-frames.d.ts +5 -17
- package/dist/physical-frames.js +4 -11
- package/dist/player.d.ts +56 -47
- package/dist/player.js +155 -40
- package/dist/presented-frames.d.ts +2 -7
- package/dist/presented-frames.js +3 -8
- package/dist/project.d.ts +83 -110
- package/dist/project.js +421 -447
- package/dist/rate-control.d.ts +9 -23
- package/dist/rate-control.js +7 -18
- package/dist/renderer-choice.d.ts +41 -0
- package/dist/renderer-choice.js +82 -0
- package/dist/repacked-bytes.d.ts +0 -2
- package/dist/repacked-bytes.js +2 -5
- package/dist/robustness.d.ts +25 -37
- package/dist/robustness.js +71 -54
- package/dist/sha256.d.ts +5 -13
- package/dist/sha256.js +9 -24
- package/dist/text.d.ts +106 -63
- package/dist/text.js +44 -69
- package/dist/video-frames.d.ts +7 -25
- package/dist/video-frames.js +12 -29
- package/dist/waveform.d.ts +5 -11
- package/dist/waveform.js +4 -9
- package/dist/worker-error.d.ts +5 -20
- package/dist/worker-error.js +8 -25
- package/dist/worker.d.ts +82 -92
- package/dist/worker.js +239 -144
- package/package.json +26 -2
- package/wasm/alpha2_audio_worklet.wasm +0 -0
- package/wasm/alpha2_extensions.d.ts +26 -47
- package/wasm/alpha2_extensions.js +26 -47
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +487 -543
- package/wasm/alpha2_wasm.js +669 -572
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +20 -8
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-57b04ecc6db57e1f/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
package/dist/project.js
CHANGED
|
@@ -1,40 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The alpha2 project document (schema version 1).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Field names are the wire names, so a {@link Project} serializes directly with `JSON.stringify`.
|
|
5
|
+
* Types and limits are generated from `schema/project.v1.schema.json`; {@link validateProject}
|
|
6
|
+
* mirrors the model's invariants beyond the schema.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* (`schema/project.v1.schema.json`) into `generated/project-schema.ts`; this
|
|
10
|
-
* module adds conversion helpers and {@link validateProject}. The schema fixes
|
|
11
|
-
* the shape of a document, and `validateProject` mirrors the invariants the
|
|
12
|
-
* model checks beyond it, pinned by the shared validation corpus.
|
|
13
|
-
*
|
|
14
|
-
* Timeline values are integer ticks at {@link TICKS_PER_SECOND}. Ranges are
|
|
15
|
-
* half-open: `[start, end)`.
|
|
8
|
+
* Timeline values are integer ticks at {@link TICKS_PER_SECOND}. Ranges are half-open.
|
|
16
9
|
*/
|
|
17
10
|
import { parseHex, parseInsets, parseLength, parseOffset, parsePlacement, parseSize, parseTrackList, } from "./layout-values.js";
|
|
18
|
-
import { AUDIO_EFFECT_STATE_MARGIN_MS, MAX_CANVAS_DIMENSION, MAX_CANVAS_PIXELS, MAX_TEXT_CONTENT_BYTES, MAX_FONT_FAMILY_BYTES, MAX_COMPOSITIONS, MAX_COMPOSITION_NODES, MAX_COMPOSITION_CONTROLS, MAX_COMPOSITION_DEPTH, MAX_GROUP_INPUTS, MAX_EFFECT_INPUTS, MAX_FRAME_INLINED_NODES, MAX_INLINED_NODES, MAX_MERGE_LAYERS, MAX_CLIP_MASKS, MAX_DASH_ENTRIES, MAX_GRADIENT_STOPS, MAX_PATH_SUBPATHS, MAX_PATH_VERTICES, MAX_POLYSTAR_POINTS, MAX_SHAPE_DEPTH, MAX_SHAPE_ITEMS, MAX_LAYOUT_DEPTH, MAX_LAYOUT_FONT_SIZE, MAX_LAYOUT_ISOLATED, MAX_LAYOUT_NODES, MAX_LAYOUT_TEXTS, MAX_GRID_TRACKS, MIN_POLYSTAR_POINTS, MAX_CLIPS, MAX_CLIPS_PER_TRACK, MAX_AUDIO_DELAY_MS, MAX_AUDIO_EFFECTS, MAX_CAPTION_FONT_SIZE, MAX_TEXT_GENERATOR_FONT_SIZE,
|
|
11
|
+
import { AUDIO_EFFECT_STATE_MARGIN_MS, MAX_CANVAS_DIMENSION, MAX_CANVAS_PIXELS, MAX_TEXT_CONTENT_BYTES, MAX_FONT_FAMILY_BYTES, MAX_COMPOSITIONS, MAX_COMPOSITION_NODES, MAX_COMPOSITION_CONTROLS, MAX_COMPOSITION_DEPTH, MAX_GROUP_INPUTS, MAX_EFFECT_INPUTS, MAX_FRAME_INLINED_NODES, MAX_INLINED_NODES, MAX_MERGE_LAYERS, MAX_CLIP_MASKS, MAX_DASH_ENTRIES, MAX_GRADIENT_STOPS, MAX_PATH_SUBPATHS, MAX_PATH_VERTICES, MAX_POLYSTAR_POINTS, MAX_SHAPE_DEPTH, MAX_SHAPE_ITEMS, MAX_LAYOUT_DEPTH, MAX_LAYOUT_FONT_SIZE, MAX_LAYOUT_ISOLATED, MAX_LAYOUT_NODES, MAX_LAYOUT_TEXTS, MAX_GRID_TRACKS, MIN_POLYSTAR_POINTS, MAX_CLIPS, MAX_CLIPS_PER_TRACK, MAX_AUDIO_DELAY_MS, MAX_AUDIO_EFFECTS, MAX_CAPTION_FONT_SIZE, MAX_CAPTION_NAME_BYTES, MAX_CAPTION_STYLES, MAX_TEXT_GENERATOR_FONT_SIZE, MAX_FONT_WEIGHT, MAX_LETTER_SPACING, MAX_LINE_HEIGHT, MAX_TEXT_PADDING, MAX_ANIMATOR_SCALE, MAX_CLASS_NAME_BYTES, MAX_RANGE_INDEX, MAX_RANGE_PERCENT, MAX_RUN_CLASSES, MAX_TEXT_ANIMATORS, MAX_TEXT_RUNS, MIN_RANGE_PERCENT, MAX_TEXT_SHADOW_BLUR, MAX_TEXT_SHADOW_OFFSET, MAX_TEXT_SHADOWS, MAX_TEXT_STROKE_EXTENT, MAX_TEXT_STROKES, MAX_CHAIN_EFFECTS, MAX_COMPRESSOR_RATIO, MAX_ENVELOPE_MS, MAX_EQ_BANDS, MAX_LOOKAHEAD_MS, MIN_FONT_WEIGHT, MIN_LETTER_SPACING, MIN_LINE_HEIGHT, MIN_LEVEL_DB, MAX_EQ_FREQUENCY_HZ, MAX_EQ_GAIN_DB, MAX_EQ_Q, MAX_GAIN, MAX_PROJECT_JSON_BYTES, MAX_SAMPLE_RATE, MAX_TRACKS, MAX_TRANSITIONS_PER_TRACK, MIN_EQ_FREQUENCY_HZ, MIN_EQ_Q, MIN_SAMPLE_RATE, MIN_HDR_PEAK_NITS, MAX_HDR_PEAK_NITS, MAX_SEQUENCE_FRAMES, REVERB_DELAY_MS, TICKS_PER_SECOND, } from "./generated/project-schema.js";
|
|
19
12
|
import { PROJECT_SHAPE } from "./generated/project-shape.js";
|
|
20
13
|
import { MAX_JSON_DEPTH, hasLoneSurrogate, readJsonText, } from "./json-text.js";
|
|
21
14
|
export * from "./generated/project-schema.js";
|
|
22
15
|
/** The deepest nesting of arrays and objects the engine reads in a project (serde_json's limit). */
|
|
23
16
|
export { MAX_JSON_DEPTH };
|
|
24
17
|
/**
|
|
25
|
-
* A CSS `cubic-bezier
|
|
26
|
-
*
|
|
27
|
-
* lie in `0..=1`; `y1` and `y2` may overshoot.
|
|
18
|
+
* A CSS `cubic-bezier` curve, usable as an {@link Easing} or {@link Interpolation}. `x1` and `x2`
|
|
19
|
+
* must lie in `0..=1`; `y1` and `y2` may overshoot.
|
|
28
20
|
*/
|
|
29
21
|
export function cubicBezier(x1, y1, x2, y2) {
|
|
30
22
|
return { type: "cubic_bezier", x1, y1, x2, y2 };
|
|
31
23
|
}
|
|
32
|
-
/**
|
|
33
|
-
* The CSS Easing Functions Level 1 named curves.
|
|
34
|
-
*
|
|
35
|
-
* The engine knows only `linear` and `cubic_bezier`; these are the standard values of the latter,
|
|
36
|
-
* so a curve an editor calls `ease-in-out` means what the web and motion tools mean by it.
|
|
37
|
-
*/
|
|
24
|
+
/** The CSS Easing Functions Level 1 named curves, as `cubic_bezier` values. */
|
|
38
25
|
export const EASING_PRESETS = {
|
|
39
26
|
linear: { type: "linear" },
|
|
40
27
|
ease: cubicBezier(0.25, 0.1, 0.25, 1),
|
|
@@ -44,27 +31,21 @@ export const EASING_PRESETS = {
|
|
|
44
31
|
};
|
|
45
32
|
/** Keeps a keyframe's value until the next keyframe. */
|
|
46
33
|
export const HOLD = { type: "hold" };
|
|
47
|
-
/** Creates a constant animated value. */
|
|
48
34
|
export function constant(value) {
|
|
49
35
|
return { mode: "constant", value };
|
|
50
36
|
}
|
|
51
37
|
/**
|
|
52
|
-
* The tick nearest `seconds`,
|
|
53
|
-
*
|
|
54
|
-
* a time back its own tick: `secondsToTicks(ticksToSeconds(t)) === t`.
|
|
38
|
+
* The tick nearest `seconds`, ties away from zero, as the engine reads seconds. Rounding guarantees
|
|
39
|
+
* `secondsToTicks(ticksToSeconds(t)) === t`.
|
|
55
40
|
*/
|
|
56
41
|
export function secondsToTicks(seconds) {
|
|
57
42
|
const scaled = seconds * TICKS_PER_SECOND;
|
|
58
43
|
return Math.sign(scaled) * Math.round(Math.abs(scaled));
|
|
59
44
|
}
|
|
60
|
-
/** Converts timeline ticks to seconds. */
|
|
61
45
|
export function ticksToSeconds(ticks) {
|
|
62
46
|
return ticks / TICKS_PER_SECOND;
|
|
63
47
|
}
|
|
64
|
-
/**
|
|
65
|
-
* The tick at or before project-rate sample `samples`, negative samples included, as the engine's
|
|
66
|
-
* `sample_ticks_floor`.
|
|
67
|
-
*/
|
|
48
|
+
/** The tick at or before sample `samples`, matching the engine's `sample_ticks_floor`. */
|
|
68
49
|
export function samplesToTicks(samples, sampleRate) {
|
|
69
50
|
if (sampleRate <= 0)
|
|
70
51
|
return 0;
|
|
@@ -77,44 +58,30 @@ export function ticksToSamples(ticks, sampleRate) {
|
|
|
77
58
|
return Math.floor((ticks * sampleRate) / TICKS_PER_SECOND);
|
|
78
59
|
}
|
|
79
60
|
/**
|
|
80
|
-
* Structural problems found without opening any media
|
|
81
|
-
*
|
|
82
|
-
* This mirrors the checks the Rust model makes so an editor can reject a document before a round
|
|
83
|
-
* trip through wasm. The engine re-validates on load; this exists to give the UI a message, not to
|
|
84
|
-
* replace that check.
|
|
85
|
-
*
|
|
86
|
-
* It checks in the engine's two layers. First the document's shape against the generated project
|
|
87
|
-
* schema: JSON types, required fields, known enum and tag values, and no unknown fields. A document
|
|
88
|
-
* of the wrong shape reports only those problems, as the engine's parser stops there. Then the
|
|
89
|
-
* model's invariants: value ranges, limits, references, ordering, and transitions. A document over
|
|
90
|
-
* a count limit (tracks, clips, sources, compositions and their nodes, transitions, caption cues)
|
|
91
|
-
* reports only its counts, as the engine refuses it before reading what they count; a video track
|
|
92
|
-
* reports its first overlap no transition covers. Past the counts, the work is linear in the
|
|
93
|
-
* document.
|
|
61
|
+
* Structural problems found without opening any media, mirroring the engine's checks so an editor
|
|
62
|
+
* can reject a document before loading it. The engine still re-validates on load.
|
|
94
63
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
64
|
+
* Shape problems (types, required fields, enum values, unknown fields) are reported alone, as the
|
|
65
|
+
* engine's parser stops there. A document over a count limit reports only its counts. Otherwise the
|
|
66
|
+
* model's invariants are checked in time linear in the document.
|
|
98
67
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
68
|
+
* Never throws; returns an empty array for a valid document. JSON spelling (repeated keys, `1920.0`
|
|
69
|
+
* for an integer) is invisible to an object; use {@link validateProjectJson} for text.
|
|
101
70
|
*/
|
|
102
71
|
export function validateProject(project) {
|
|
103
72
|
return projectProblems(project, undefined);
|
|
104
73
|
}
|
|
105
74
|
function projectProblems(project, spelling) {
|
|
106
|
-
//
|
|
75
|
+
// Only objects can share parts with a document validated before.
|
|
107
76
|
const reuse = spelling === undefined;
|
|
108
77
|
const { problems: shape, read } = shapeProblems(project, spelling, reuse);
|
|
109
78
|
if (shape.length > 0)
|
|
110
79
|
return shape;
|
|
111
|
-
//
|
|
112
|
-
// earlier calls found; a problem is still worded by walking the whole document.
|
|
80
|
+
// Float fields are read as 32-bit, as the engine does. Problems are always worded by a full walk.
|
|
113
81
|
if (reuse && invariantsHold(read))
|
|
114
82
|
return [];
|
|
115
83
|
return invariantProblems(read);
|
|
116
84
|
}
|
|
117
|
-
/** The project's model invariants past its shape, worded, in document order. */
|
|
118
85
|
function invariantProblems(value) {
|
|
119
86
|
const project = value;
|
|
120
87
|
if (!isRecord(project))
|
|
@@ -133,8 +100,7 @@ function invariantProblems(value) {
|
|
|
133
100
|
if (timeline === undefined)
|
|
134
101
|
problems.push("timeline must be an object");
|
|
135
102
|
const tracks = list(timeline?.tracks, "timeline.tracks", timeline !== undefined);
|
|
136
|
-
//
|
|
137
|
-
// this: every check after this one is linear in a document within them.
|
|
103
|
+
// Like the engine, refuse over-count documents before reading what the counts hold.
|
|
138
104
|
const counts = countProblems(sourceList, compositionList, tracks);
|
|
139
105
|
if (counts.length > 0) {
|
|
140
106
|
for (const problem of counts)
|
|
@@ -174,7 +140,6 @@ function invariantProblems(value) {
|
|
|
174
140
|
problems.push(problem);
|
|
175
141
|
return problems;
|
|
176
142
|
}
|
|
177
|
-
/** The project's id, its settings and its master bus. */
|
|
178
143
|
function headerProblems(project) {
|
|
179
144
|
const problems = [];
|
|
180
145
|
if (text(project.id).length === 0)
|
|
@@ -219,7 +184,6 @@ function headerProblems(project) {
|
|
|
219
184
|
}
|
|
220
185
|
return problems;
|
|
221
186
|
}
|
|
222
|
-
/** The project's canvas, which its layouts' pixels are pixels of. */
|
|
223
187
|
function canvasOf(project) {
|
|
224
188
|
const settings = isRecord(project.settings)
|
|
225
189
|
? project.settings
|
|
@@ -316,7 +280,6 @@ function catalogOf(sourceList, resourceList, compositionList, canvas) {
|
|
|
316
280
|
for (const composition of compositionList)
|
|
317
281
|
if (isRecord(composition))
|
|
318
282
|
compositionsById.set(text(composition.id), composition);
|
|
319
|
-
// Each target's control names are built once for every group node drawing it.
|
|
320
283
|
const controlNames = new Map();
|
|
321
284
|
const controlNamesOf = (target) => {
|
|
322
285
|
let names = controlNames.get(target);
|
|
@@ -337,7 +300,6 @@ function catalogOf(sourceList, resourceList, compositionList, canvas) {
|
|
|
337
300
|
!compositions.has(text(source.composition)))
|
|
338
301
|
problems.push(`source ${sourceId} is not a valid composition source`);
|
|
339
302
|
const looping = compositionUsingItself(compositionsById, sources);
|
|
340
|
-
// The nodes each composition draws once inlined, when they are all within bounds.
|
|
341
303
|
let inlined;
|
|
342
304
|
if (looping !== undefined)
|
|
343
305
|
problems.push(`composition ${looping} uses itself`);
|
|
@@ -351,10 +313,9 @@ function catalogOf(sourceList, resourceList, compositionList, canvas) {
|
|
|
351
313
|
return { problems, sources, effectResources, compositions, inlined };
|
|
352
314
|
}
|
|
353
315
|
/**
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* catalog is not checked again.
|
|
316
|
+
* Problems of one track that depend on the rest of the project only through `catalog`. Adds the
|
|
317
|
+
* track's clip ids to `clipIds`. With `reuse`, clips that passed before with the same kind and
|
|
318
|
+
* catalog are skipped.
|
|
358
319
|
*/
|
|
359
320
|
function trackProblems(track, catalog, clipIds, reuse) {
|
|
360
321
|
const problems = [];
|
|
@@ -369,9 +330,9 @@ function trackProblems(track, catalog, clipIds, reuse) {
|
|
|
369
330
|
};
|
|
370
331
|
const clips = list(track.clips, `track ${trackId} clips`);
|
|
371
332
|
const transitions = list(track.transitions, `track ${trackId} transitions`);
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
333
|
+
const captions = captionsProblem(track, clips, transitions, trackId);
|
|
334
|
+
if (captions !== undefined)
|
|
335
|
+
problems.push(captions);
|
|
375
336
|
const overlap = uncoveredOverlap(trackId, trackKind, clips, transitions);
|
|
376
337
|
if (overlap !== undefined)
|
|
377
338
|
problems.push(overlap);
|
|
@@ -416,7 +377,6 @@ function trackProblems(track, catalog, clipIds, reuse) {
|
|
|
416
377
|
}
|
|
417
378
|
return problems;
|
|
418
379
|
}
|
|
419
|
-
/** The problems of one clip on a track of `trackKind`, but for its id being another clip's too. */
|
|
420
380
|
function clipProblems(clip, trackKind, catalog) {
|
|
421
381
|
const problems = [];
|
|
422
382
|
const clipId = text(clip.id);
|
|
@@ -474,9 +434,6 @@ function clipProblems(clip, trackKind, catalog) {
|
|
|
474
434
|
}
|
|
475
435
|
return problems;
|
|
476
436
|
}
|
|
477
|
-
/**
|
|
478
|
-
* Each track's ducking: valid settings, and a sidechain among `trackIds` that leads back to none.
|
|
479
|
-
*/
|
|
480
437
|
function duckingProblems(tracks, trackIds) {
|
|
481
438
|
const problems = [];
|
|
482
439
|
const cyclic = duckingCycles(tracks);
|
|
@@ -500,25 +457,15 @@ function duckingProblems(tracks, trackIds) {
|
|
|
500
457
|
}
|
|
501
458
|
return problems;
|
|
502
459
|
}
|
|
503
|
-
//
|
|
504
|
-
//
|
|
505
|
-
// rewalked.
|
|
506
|
-
/** Deep-frozen plain values, and the values read from them: neither can change. */
|
|
460
|
+
// Validation caches. Deep-frozen plain data cannot change, so an edit pays only for what it
|
|
461
|
+
// changed. Only passes are cached; problems are always rewalked.
|
|
507
462
|
const immutable = new WeakSet();
|
|
508
|
-
/** The value read from an immutable value whose shape matched `node`. */
|
|
509
463
|
const readShapes = new WeakMap();
|
|
510
|
-
/** Immutable clips that passed `clipProblems` on a track of `kind` with `catalog`. */
|
|
511
464
|
const checkedClips = new WeakMap();
|
|
512
|
-
/** The catalog of an immutable source list, with the immutable lists it was made with. */
|
|
513
465
|
const catalogs = new WeakMap();
|
|
514
|
-
/** What {@link invariantsHold} keeps of an immutable track that passed `trackProblems`. */
|
|
515
466
|
const trackSummaries = new WeakMap();
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
* enumerable fields, of the plain prototypes, whose own properties all hold values (a getter could
|
|
519
|
-
* answer differently next time). Such a value reads as a copy of its fields would. What is found
|
|
520
|
-
* so is remembered, so each object is looked into once.
|
|
521
|
-
*/
|
|
467
|
+
// Deep-frozen plain arrays and objects with data properties only (a getter could answer
|
|
468
|
+
// differently next time). Results are memoized in `immutable`.
|
|
522
469
|
function sealed(value) {
|
|
523
470
|
if (typeof value !== "object" || value === null)
|
|
524
471
|
return true;
|
|
@@ -547,7 +494,6 @@ function sealed(value) {
|
|
|
547
494
|
immutable.add(value);
|
|
548
495
|
return true;
|
|
549
496
|
}
|
|
550
|
-
/** Remembers that immutable `value` matched `node` and reads as `read`, when both are sealed. */
|
|
551
497
|
function rememberShape(node, value, read) {
|
|
552
498
|
if (!sealed(value))
|
|
553
499
|
return;
|
|
@@ -560,7 +506,6 @@ function rememberShape(node, value, read) {
|
|
|
560
506
|
}
|
|
561
507
|
readShapes.set(value, { node, read });
|
|
562
508
|
}
|
|
563
|
-
/** The catalog of the lists, the one made before when they are the same immutable lists. */
|
|
564
509
|
function catalogFor(sources, resources, compositions, canvas) {
|
|
565
510
|
const reusable = typeof sources === "object" &&
|
|
566
511
|
sources !== null &&
|
|
@@ -619,11 +564,7 @@ function summaryOf(track, catalog) {
|
|
|
619
564
|
trackSummaries.set(track, summary);
|
|
620
565
|
return summary;
|
|
621
566
|
}
|
|
622
|
-
|
|
623
|
-
* Whether the invariants hold for `value`, a project whose shape matched, decided from the parts
|
|
624
|
-
* earlier calls found to pass and a check of the rest. Holds exactly when
|
|
625
|
-
* {@link invariantProblems} finds none: each of its checks is made here, on the same parts.
|
|
626
|
-
*/
|
|
567
|
+
// Must agree exactly with `invariantProblems` finding none, reusing cached passes.
|
|
627
568
|
function invariantsHold(value) {
|
|
628
569
|
if (!isRecord(value))
|
|
629
570
|
return false;
|
|
@@ -664,13 +605,9 @@ function invariantsHold(value) {
|
|
|
664
605
|
audioEffectProblems(project.audio, summaries.map((summary) => summary.audio)).length === 0 &&
|
|
665
606
|
duckingProblems(tracks, trackIds).length === 0);
|
|
666
607
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
* later call checks only the ids of the tracks not among them against those still present. One
|
|
670
|
-
* set is kept, of the last project checked whole: an editor's projects share most tracks.
|
|
671
|
-
*/
|
|
608
|
+
// The last set of tracks found to share no clip id, so a later call checks only new tracks.
|
|
609
|
+
// Successive editor projects share most tracks.
|
|
672
610
|
let distinctTracks;
|
|
673
|
-
/** Whether no clip id is on two of the tracks (each track's own are distinct already). */
|
|
674
611
|
function clipIdsUnique(summaries) {
|
|
675
612
|
let total = 0;
|
|
676
613
|
let holding = 0;
|
|
@@ -688,9 +625,8 @@ function clipIdsUnique(summaries) {
|
|
|
688
625
|
let count = 0;
|
|
689
626
|
for (const summary of added)
|
|
690
627
|
count += summary.ids.length;
|
|
691
|
-
// Past half the ids, starting over costs no more.
|
|
692
628
|
if (count * 2 <= total) {
|
|
693
|
-
// A track's own ids are distinct
|
|
629
|
+
// A track's own ids are distinct, so only two or more new tracks can collide.
|
|
694
630
|
const seen = added.length > 1 ? new Set() : undefined;
|
|
695
631
|
for (const summary of added)
|
|
696
632
|
for (const id of summary.ids) {
|
|
@@ -716,10 +652,7 @@ function clipIdsUnique(summaries) {
|
|
|
716
652
|
distinctTracks = { members: present, owners };
|
|
717
653
|
return true;
|
|
718
654
|
}
|
|
719
|
-
|
|
720
|
-
* Whether every matte holds, as {@link matteProblems} finds them in a project whose clip ids are
|
|
721
|
-
* distinct: it names another clip on a video track, which has no matte and is in no transition.
|
|
722
|
-
*/
|
|
655
|
+
// Must agree with `matteProblems` for a project whose clip ids are distinct.
|
|
723
656
|
function mattesHold(summaries) {
|
|
724
657
|
const video = summaries.filter((summary) => summary.kind === "video");
|
|
725
658
|
for (const summary of video)
|
|
@@ -738,12 +671,7 @@ function mattesHold(summaries) {
|
|
|
738
671
|
}
|
|
739
672
|
return true;
|
|
740
673
|
}
|
|
741
|
-
|
|
742
|
-
* The counts the engine bounds before it reads what they count: sources, tracks and compositions in
|
|
743
|
-
* the project, nodes in each composition, clips, transitions and caption cues on each track, and
|
|
744
|
-
* clips in all. The lists past the project's own are read only when those are within their limits,
|
|
745
|
-
* so this is one step per track and composition of a document within them.
|
|
746
|
-
*/
|
|
674
|
+
// Nested lists are counted only when the top-level counts are within limits.
|
|
747
675
|
function countProblems(sources, compositions, tracks) {
|
|
748
676
|
const problems = [];
|
|
749
677
|
if (sources.length > MAX_CLIPS)
|
|
@@ -779,18 +707,10 @@ function countProblems(sources, compositions, tracks) {
|
|
|
779
707
|
return problems;
|
|
780
708
|
}
|
|
781
709
|
/**
|
|
782
|
-
*
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
786
|
-
* engine checks in the text: `loadProject` rejects anything over
|
|
787
|
-
* {@link MAX_PROJECT_JSON_BYTES} before it parses, and its parser refuses a
|
|
788
|
-
* struct field given twice, an integer field spelled with a fraction or
|
|
789
|
-
* exponent (`1920.0`, `1.92e3`, `-0`), and nesting deeper than 127 levels.
|
|
790
|
-
* Hosts that hand the engine a string should validate the string, or a
|
|
791
|
-
* document this package accepted can still be refused by the engine.
|
|
792
|
-
*
|
|
793
|
-
* Like {@link validateProject}, this never throws; malformed JSON is reported.
|
|
710
|
+
* Like {@link validateProject}, but also reports what only the text shows: size over
|
|
711
|
+
* {@link MAX_PROJECT_JSON_BYTES}, repeated fields, integers spelled with a fraction or exponent
|
|
712
|
+
* (`1920.0`, `1.92e3`, `-0`), and nesting deeper than 127 levels. Hosts that pass the engine a
|
|
713
|
+
* string should validate the string. Never throws; malformed JSON is reported.
|
|
794
714
|
*/
|
|
795
715
|
export function validateProjectJson(json) {
|
|
796
716
|
if (exceedsParseBudget(json)) {
|
|
@@ -799,8 +719,7 @@ export function validateProjectJson(json) {
|
|
|
799
719
|
`project JSON is ${bytes} bytes, over the ${MAX_PROJECT_JSON_BYTES} byte limit`,
|
|
800
720
|
];
|
|
801
721
|
}
|
|
802
|
-
// `JSON.parse`
|
|
803
|
-
// text.
|
|
722
|
+
// `JSON.parse` supplies the error message; `readJsonText` assumes valid JSON.
|
|
804
723
|
try {
|
|
805
724
|
JSON.parse(json);
|
|
806
725
|
}
|
|
@@ -816,9 +735,8 @@ export function validateProjectJson(json) {
|
|
|
816
735
|
return projectProblems(read.value, read.spelling);
|
|
817
736
|
}
|
|
818
737
|
/**
|
|
819
|
-
* Whether `rate`
|
|
820
|
-
*
|
|
821
|
-
* {@link TICKS_PER_SECOND} frames per second).
|
|
738
|
+
* Whether `rate` has positive 32-bit `num` and `den` and at most {@link TICKS_PER_SECOND} frames
|
|
739
|
+
* per second.
|
|
822
740
|
*/
|
|
823
741
|
export function validFrameRate(rate) {
|
|
824
742
|
return (isRecord(rate) &&
|
|
@@ -829,13 +747,8 @@ export function validFrameRate(rate) {
|
|
|
829
747
|
rate.num <= TICKS_PER_SECOND * rate.den);
|
|
830
748
|
}
|
|
831
749
|
const MAX_U32 = 0xffff_ffff;
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
*
|
|
835
|
-
* The engine measures UTF-8 bytes. Every UTF-16 code unit encodes to at least one UTF-8 byte and at
|
|
836
|
-
* most three, so the code-unit count brackets the byte count from both sides and ordinary documents
|
|
837
|
-
* are decided without the exact encode, which copies the whole string.
|
|
838
|
-
*/
|
|
750
|
+
// The engine measures UTF-8 bytes. Each UTF-16 unit encodes to 1 to 3 bytes, so most documents
|
|
751
|
+
// are decided without encoding the whole string.
|
|
839
752
|
function exceedsParseBudget(json) {
|
|
840
753
|
if (json.length > MAX_PROJECT_JSON_BYTES)
|
|
841
754
|
return true;
|
|
@@ -845,13 +758,9 @@ function exceedsParseBudget(json) {
|
|
|
845
758
|
}
|
|
846
759
|
const shapeRoot = PROJECT_SHAPE;
|
|
847
760
|
/**
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
*
|
|
852
|
-
* The walk covers exactly the keywords the generator keeps (it refuses to generate any other), and
|
|
853
|
-
* reports at most one problem per value: a tagged union is checked against the variant its tag
|
|
854
|
-
* names.
|
|
761
|
+
* Walks the generated schema and returns shape problems plus the document as the engine reads it,
|
|
762
|
+
* with `format: "float"` numbers rounded to 32 bits. Reports at most one problem per value. The
|
|
763
|
+
* walk must cover exactly the keywords the generator emits.
|
|
855
764
|
*/
|
|
856
765
|
function shapeProblems(value, spelling, reuse) {
|
|
857
766
|
const problems = [];
|
|
@@ -864,13 +773,8 @@ function shapeProblems(value, spelling, reuse) {
|
|
|
864
773
|
reusingShapes = false;
|
|
865
774
|
}
|
|
866
775
|
}
|
|
867
|
-
/** Whether the walk running now reuses, and keeps, what it finds of immutable values. */
|
|
868
776
|
let reusingShapes = false;
|
|
869
|
-
|
|
870
|
-
* The shapes with a rule between their fields, which the schema cannot state and the engine's
|
|
871
|
-
* parser enforces: a frame rate is at most one frame per tick, and a time range does not end before
|
|
872
|
-
* it starts.
|
|
873
|
-
*/
|
|
777
|
+
// Cross-field rules the schema cannot state but the engine's parser enforces.
|
|
874
778
|
const FRAME_RATE_SHAPE = shapeRoot.$defs
|
|
875
779
|
.FrameRate;
|
|
876
780
|
const TIME_RANGE_SHAPE = shapeRoot.$defs
|
|
@@ -886,20 +790,16 @@ function resolveShape(node) {
|
|
|
886
790
|
function describeValue(value) {
|
|
887
791
|
return JSON.stringify(value) ?? String(value);
|
|
888
792
|
}
|
|
889
|
-
|
|
890
|
-
* The integers each integer `format` of the schema holds: the Rust type the engine's parser reads
|
|
891
|
-
* the field as.
|
|
892
|
-
*/
|
|
793
|
+
// Ranges of the Rust integer types behind each schema `format`.
|
|
893
794
|
const INTEGER_FORMATS = {
|
|
795
|
+
uint16: { min: 0n, max: 2n ** 16n - 1n },
|
|
894
796
|
uint32: { min: 0n, max: 2n ** 32n - 1n },
|
|
895
797
|
uint64: { min: 0n, max: 2n ** 64n - 1n },
|
|
896
798
|
int64: { min: -(2n ** 63n), max: 2n ** 63n - 1n },
|
|
897
799
|
};
|
|
898
800
|
/**
|
|
899
|
-
* Checks `value` against `node` and returns it as the engine reads it
|
|
900
|
-
*
|
|
901
|
-
* members, when it came from text; `texts` are the texts of `value` itself
|
|
902
|
-
* when it is a number its value does not spell (`JsonSpelling.numbers`).
|
|
801
|
+
* Checks `value` against `node` and returns it as the engine reads it. `texts` are the source
|
|
802
|
+
* spellings of a number its value does not round-trip (`JsonSpelling.numbers`).
|
|
903
803
|
*/
|
|
904
804
|
function checkShape(node, value, path, problems, spelling, texts) {
|
|
905
805
|
if (!reusingShapes || typeof value !== "object" || value === null)
|
|
@@ -913,23 +813,16 @@ function checkShape(node, value, path, problems, spelling, texts) {
|
|
|
913
813
|
rememberShape(node, value, read);
|
|
914
814
|
return read;
|
|
915
815
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
* reads them (`alpha2_model::layout_values`): each problem worded as the parser words it, and the
|
|
919
|
-
* value given to the model's checks in one form. A color is `{ red, green, blue, alpha }`, a paint
|
|
920
|
-
* tagged, a layout length `{ unit, value }`, sides `{ top, right, bottom, left }` of lengths, an
|
|
921
|
-
* offset `{ x, y }` of lengths, a track list its parsed components, a grid placement
|
|
922
|
-
* `{ start, end }` edges.
|
|
923
|
-
*/
|
|
816
|
+
// Defs with CSS-style or alternative spellings are normalized to one form, with problems worded
|
|
817
|
+
// as `alpha2_model::layout_values` words them.
|
|
924
818
|
const SHAPE_DEFS = shapeRoot.$defs;
|
|
925
|
-
/** A value read by `parse`, its problem reported at `path` as the parser reports it. */
|
|
926
819
|
function parsedOr(parsed, path, problems, value) {
|
|
927
820
|
if (parsed.ok)
|
|
928
821
|
return parsed.value;
|
|
929
822
|
problems.push(`${path}: ${parsed.error}`);
|
|
930
823
|
return value;
|
|
931
824
|
}
|
|
932
|
-
|
|
825
|
+
// A number is a fraction; a string is `"<n>px"` or, with `percent`, `"<n>%"`.
|
|
933
826
|
function readLayoutLength(percent) {
|
|
934
827
|
return (value, path, problems) => {
|
|
935
828
|
if (typeof value === "number")
|
|
@@ -940,7 +833,6 @@ function readLayoutLength(percent) {
|
|
|
940
833
|
return value;
|
|
941
834
|
};
|
|
942
835
|
}
|
|
943
|
-
/** Fields of an object form: unknown ones refused, required ones present, each read by `read`. */
|
|
944
836
|
function readFields(value, path, problems, fields, required, read, spelling) {
|
|
945
837
|
for (const key of Object.keys(value)) {
|
|
946
838
|
if (!fields.includes(key))
|
|
@@ -967,7 +859,6 @@ const SHAPE_READERS = new Map([
|
|
|
967
859
|
(value, path, problems, spelling) => {
|
|
968
860
|
if (typeof value === "string")
|
|
969
861
|
return parsedOr(parseHex(value), path, problems, value);
|
|
970
|
-
// The object form, or what is wrong with a value of neither form.
|
|
971
862
|
const object = SHAPE_DEFS.Rgba.anyOf[0];
|
|
972
863
|
return checkShape(object, value, path, problems, spelling);
|
|
973
864
|
},
|
|
@@ -975,7 +866,7 @@ const SHAPE_READERS = new Map([
|
|
|
975
866
|
[
|
|
976
867
|
SHAPE_DEFS.Paint,
|
|
977
868
|
(value, path, problems, spelling) => {
|
|
978
|
-
//
|
|
869
|
+
// An untagged color paints solid.
|
|
979
870
|
if (typeof value === "string" ||
|
|
980
871
|
(isRecord(value) && !("type" in value))) {
|
|
981
872
|
const color = checkShape(SHAPE_DEFS.Rgba, value, path, problems, spelling);
|
|
@@ -1035,7 +926,7 @@ const SHAPE_READERS = new Map([
|
|
|
1035
926
|
},
|
|
1036
927
|
],
|
|
1037
928
|
]);
|
|
1038
|
-
|
|
929
|
+
// The shortest decimal that reads back as the same 32-bit float, as the engine writes it.
|
|
1039
930
|
function shortestFloat32(value) {
|
|
1040
931
|
const target = Math.fround(value);
|
|
1041
932
|
for (let digits = 1; digits < 9; digits++) {
|
|
@@ -1045,9 +936,14 @@ function shortestFloat32(value) {
|
|
|
1045
936
|
}
|
|
1046
937
|
return Number(target.toPrecision(9));
|
|
1047
938
|
}
|
|
939
|
+
/** The whole text of a caption cue or text generator, with runs joined. */
|
|
940
|
+
export function textOf(content) {
|
|
941
|
+
return typeof content === "string"
|
|
942
|
+
? content
|
|
943
|
+
: content.map((run) => run.text).join("");
|
|
944
|
+
}
|
|
1048
945
|
/**
|
|
1049
|
-
*
|
|
1050
|
-
* component the 32-bit value the engine reads, spelled shortest.
|
|
946
|
+
* Converts a CSS hex color to the object form, with 32-bit components spelled shortest.
|
|
1051
947
|
*
|
|
1052
948
|
* @throws A `TypeError` for a string that is not CSS hex.
|
|
1053
949
|
*/
|
|
@@ -1066,8 +962,7 @@ export function canonicalRgba(color) {
|
|
|
1066
962
|
};
|
|
1067
963
|
}
|
|
1068
964
|
/**
|
|
1069
|
-
*
|
|
1070
|
-
* every color in it the components object.
|
|
965
|
+
* Converts a paint to the tagged form the engine writes; a bare color becomes a solid paint.
|
|
1071
966
|
*
|
|
1072
967
|
* @throws A `TypeError` for a color string that is not CSS hex.
|
|
1073
968
|
*/
|
|
@@ -1086,21 +981,17 @@ export function canonicalPaint(paint) {
|
|
|
1086
981
|
})),
|
|
1087
982
|
};
|
|
1088
983
|
}
|
|
1089
|
-
/** A length read from a CSS token, written back as the engine writes it. */
|
|
1090
984
|
function lengthWritten(length) {
|
|
1091
985
|
const value = shortestFloat32(length.value);
|
|
1092
986
|
return length.unit === "px" ? `${value}px` : value;
|
|
1093
987
|
}
|
|
1094
|
-
// The
|
|
1095
|
-
//
|
|
1096
|
-
// form comes back as the same object, and a part that changes shares every part that did not.
|
|
1097
|
-
/** `color` as an object; a string that is not hex stays as it is. */
|
|
988
|
+
// The readers below leave unreadable values for validation to report, and return their input
|
|
989
|
+
// itself when nothing changes so unchanged parts are shared.
|
|
1098
990
|
function rgbaRead(color) {
|
|
1099
991
|
if (typeof color !== "string")
|
|
1100
992
|
return color;
|
|
1101
993
|
return parseHex(color).ok ? canonicalRgba(color) : color;
|
|
1102
994
|
}
|
|
1103
|
-
/** `paint` tagged, its colors objects; what is not a paint stays as it is. */
|
|
1104
995
|
function paintRead(paint) {
|
|
1105
996
|
if (typeof paint === "string" || (isRecord(paint) && !("type" in paint))) {
|
|
1106
997
|
const color = rgbaRead(paint);
|
|
@@ -1126,7 +1017,6 @@ function paintRead(paint) {
|
|
|
1126
1017
|
: { ...paint, stops: read };
|
|
1127
1018
|
}
|
|
1128
1019
|
const SIDE_NAMES = ["top", "right", "bottom", "left"];
|
|
1129
|
-
/** Sides as the four-side object; what cannot be read stays as it is. */
|
|
1130
1020
|
function insetsRead(value) {
|
|
1131
1021
|
if (typeof value === "number") {
|
|
1132
1022
|
return { top: value, right: value, bottom: value, left: value };
|
|
@@ -1145,7 +1035,6 @@ function insetsRead(value) {
|
|
|
1145
1035
|
...SIDE_NAMES.map((side) => [side, value[side] ?? 0]),
|
|
1146
1036
|
]);
|
|
1147
1037
|
}
|
|
1148
|
-
/** An offset as `{ x, y }`; what cannot be read stays as it is. */
|
|
1149
1038
|
function offsetRead(value) {
|
|
1150
1039
|
if (typeof value !== "string")
|
|
1151
1040
|
return value;
|
|
@@ -1155,17 +1044,12 @@ function offsetRead(value) {
|
|
|
1155
1044
|
: value;
|
|
1156
1045
|
}
|
|
1157
1046
|
/**
|
|
1158
|
-
* `project` in the forms the engine writes
|
|
1159
|
-
*
|
|
1160
|
-
*
|
|
1161
|
-
* sides shorthand, a `translate` string) are gone, so code that reads the document can take the
|
|
1162
|
-
* one form. A value it cannot read (a string that is not hex, say) stays as it is, for
|
|
1163
|
-
* {@link validateProject} to report: give it a document that validates to get a document in
|
|
1164
|
-
* canonical form.
|
|
1047
|
+
* Returns `project` in the forms the engine writes ({@link Canonical}): object colors, tagged
|
|
1048
|
+
* paints, four-side insets and `{ x, y }` offsets. Unreadable values are left for
|
|
1049
|
+
* {@link validateProject} to report, so pass a valid document to get a fully canonical one.
|
|
1165
1050
|
*
|
|
1166
|
-
* The input is not changed.
|
|
1167
|
-
*
|
|
1168
|
-
* again: run on a changed copy of a document read before, it costs the parts that changed.
|
|
1051
|
+
* The input is not changed. Already-canonical parts are returned as the same objects, and frozen
|
|
1052
|
+
* parts seen before are not walked again.
|
|
1169
1053
|
*/
|
|
1170
1054
|
export function canonicalProject(project) {
|
|
1171
1055
|
const reusing = reusingShapes;
|
|
@@ -1177,11 +1061,16 @@ export function canonicalProject(project) {
|
|
|
1177
1061
|
reusingShapes = reusing;
|
|
1178
1062
|
}
|
|
1179
1063
|
}
|
|
1180
|
-
/** The canonical form of frozen values met before, by the node they were read as. */
|
|
1181
1064
|
const canonicalShapes = new WeakMap();
|
|
1182
|
-
|
|
1065
|
+
// The defs that are canonicalized, plus every def that can contain one.
|
|
1183
1066
|
const CANONICAL_DEFS = (() => {
|
|
1184
|
-
const holding = new Set([
|
|
1067
|
+
const holding = new Set([
|
|
1068
|
+
"Rgba",
|
|
1069
|
+
"Paint",
|
|
1070
|
+
"Insets",
|
|
1071
|
+
"LayoutOffset",
|
|
1072
|
+
"VisualProperties",
|
|
1073
|
+
]);
|
|
1185
1074
|
const refs = Object.entries(SHAPE_DEFS).map(([name, def]) => [name, refsIn(def)]);
|
|
1186
1075
|
for (let grew = true; grew;) {
|
|
1187
1076
|
grew = false;
|
|
@@ -1193,17 +1082,13 @@ const CANONICAL_DEFS = (() => {
|
|
|
1193
1082
|
}
|
|
1194
1083
|
return holding;
|
|
1195
1084
|
})();
|
|
1196
|
-
/** The defs `node` refers to anywhere in it. */
|
|
1197
1085
|
function refsIn(node) {
|
|
1198
1086
|
return [
|
|
1199
1087
|
...JSON.stringify(node).matchAll(/"\$ref":"#\/\$defs\/([^"]+)"/g),
|
|
1200
1088
|
].map((match) => match[1]);
|
|
1201
1089
|
}
|
|
1202
1090
|
const holdingNodes = new WeakMap();
|
|
1203
|
-
|
|
1204
|
-
* Whether a value read as `node` can hold a color, paint, sides or offset. The walk does not
|
|
1205
|
-
* read a field that cannot: it costs nothing, and reads nothing it has no use for.
|
|
1206
|
-
*/
|
|
1091
|
+
// Fields that cannot hold a canonicalized value are skipped.
|
|
1207
1092
|
function mayHold(node) {
|
|
1208
1093
|
let holds = holdingNodes.get(node);
|
|
1209
1094
|
if (holds === undefined) {
|
|
@@ -1225,7 +1110,6 @@ function canonicalAt(node, value) {
|
|
|
1225
1110
|
canonicalShapes.set(value, { node, canonical });
|
|
1226
1111
|
return canonical;
|
|
1227
1112
|
}
|
|
1228
|
-
/** A string or number where a color, paint, sides or offset lies, in its canonical form. */
|
|
1229
1113
|
function canonicalLeaf(node, value) {
|
|
1230
1114
|
if (typeof node !== "object" || value === null || value === undefined)
|
|
1231
1115
|
return value;
|
|
@@ -1243,7 +1127,7 @@ function canonicalWalk(node, value) {
|
|
|
1243
1127
|
return offsetRead(value);
|
|
1244
1128
|
const variants = (schema.oneOf ?? schema.anyOf);
|
|
1245
1129
|
if (variants !== undefined) {
|
|
1246
|
-
//
|
|
1130
|
+
// Pick the first form that fits, as the parser does.
|
|
1247
1131
|
const fits = variants.find((variant) => {
|
|
1248
1132
|
const found = [];
|
|
1249
1133
|
checkShape(variant, value, "", found, undefined);
|
|
@@ -1267,7 +1151,6 @@ function canonicalWalk(node, value) {
|
|
|
1267
1151
|
let read;
|
|
1268
1152
|
for (const key of Object.keys(value)) {
|
|
1269
1153
|
const field = Object.hasOwn(properties, key) ? properties[key] : extra;
|
|
1270
|
-
// A field that cannot hold what is put in canonical form is not read.
|
|
1271
1154
|
if (typeof field !== "object" || !mayHold(field))
|
|
1272
1155
|
continue;
|
|
1273
1156
|
const before = value[key];
|
|
@@ -1275,9 +1158,15 @@ function canonicalWalk(node, value) {
|
|
|
1275
1158
|
if (canonical !== before)
|
|
1276
1159
|
(read ??= {})[key] = canonical;
|
|
1277
1160
|
}
|
|
1161
|
+
// The engine writes a clip's visual whole, filling omitted fields with schema defaults.
|
|
1162
|
+
if (schema === SHAPE_DEFS.VisualProperties) {
|
|
1163
|
+
for (const [key, field] of Object.entries(properties)) {
|
|
1164
|
+
if (value[key] === undefined && field.default !== undefined)
|
|
1165
|
+
(read ??= {})[key] = structuredClone(field.default);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1278
1168
|
return read === undefined ? value : { ...value, ...read };
|
|
1279
1169
|
}
|
|
1280
|
-
/** {@link checkShape} of a value not known to match `node`. */
|
|
1281
1170
|
function walkShape(node, value, path, problems, spelling, texts) {
|
|
1282
1171
|
const schema = resolveShape(node);
|
|
1283
1172
|
const reader = SHAPE_READERS.get(schema);
|
|
@@ -1372,16 +1261,11 @@ function integerBounds(schema) {
|
|
|
1372
1261
|
integerBoundsByShape.set(schema, bounds);
|
|
1373
1262
|
return bounds;
|
|
1374
1263
|
}
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
* one of `texts`, the field's texts in a document's text when its value does not spell them. A
|
|
1378
|
-
* number with a fraction, an exponent, or `-0` is not an integer to the engine, and one outside the
|
|
1379
|
-
* schema's bounds or the range of its `format` is refused, not rounded.
|
|
1380
|
-
*/
|
|
1264
|
+
// The engine refuses (never rounds) integers spelled with a fraction, exponent or `-0`, and those
|
|
1265
|
+
// outside the schema bounds or `format` range.
|
|
1381
1266
|
function checkInteger(schema, value, texts, path, problems) {
|
|
1382
1267
|
const { min, max } = integerBounds(schema);
|
|
1383
|
-
// A safe integer
|
|
1384
|
-
// the engine reads: the document's text, or what `JSON.stringify` writes for it.
|
|
1268
|
+
// A safe integer's value decides; otherwise the spelling the engine would read decides.
|
|
1385
1269
|
if (texts === undefined && Number.isSafeInteger(value)) {
|
|
1386
1270
|
if (min !== undefined && value < Number(min)) {
|
|
1387
1271
|
problems.push(`${path} must be at least ${min}`);
|
|
@@ -1428,8 +1312,7 @@ function isType(type, value) {
|
|
|
1428
1312
|
}
|
|
1429
1313
|
}
|
|
1430
1314
|
function checkVariants(variants, value, path, problems, spelling, texts) {
|
|
1431
|
-
//
|
|
1432
|
-
// only worth building when none fits, to report against the one the value meant.
|
|
1315
|
+
// The first fitting form wins. When none fits, report against the form the value meant.
|
|
1433
1316
|
const tried = [];
|
|
1434
1317
|
for (const variant of variants) {
|
|
1435
1318
|
const found = [];
|
|
@@ -1444,14 +1327,12 @@ function checkVariants(variants, value, path, problems, spelling, texts) {
|
|
|
1444
1327
|
problems.push(`${path} must be one of ${values.join(", ")}`);
|
|
1445
1328
|
return value;
|
|
1446
1329
|
}
|
|
1447
|
-
// An optional value: report against the one form that is not `null`.
|
|
1448
1330
|
const present = resolved.flatMap((variant, index) => variant.type === "null" ? [] : [index]);
|
|
1449
1331
|
if (value !== null && present.length === 1) {
|
|
1450
1332
|
for (const problem of tried[present[0]])
|
|
1451
1333
|
problems.push(problem);
|
|
1452
1334
|
return value;
|
|
1453
1335
|
}
|
|
1454
|
-
// A tagged union: report against the variant the value's tag selects.
|
|
1455
1336
|
const tag = tagName(resolved);
|
|
1456
1337
|
if (tag !== undefined && isRecord(value)) {
|
|
1457
1338
|
const index = resolved.findIndex((variant) => variant.properties[tag].const ===
|
|
@@ -1468,7 +1349,6 @@ function checkVariants(variants, value, path, problems, spelling, texts) {
|
|
|
1468
1349
|
problems.push(`${path} matches none of its allowed forms`);
|
|
1469
1350
|
return value;
|
|
1470
1351
|
}
|
|
1471
|
-
/** The property every variant of a tagged union fixes to a constant. */
|
|
1472
1352
|
function tagName(variants) {
|
|
1473
1353
|
const first = variants[0]?.properties;
|
|
1474
1354
|
if (!isRecord(first))
|
|
@@ -1505,23 +1385,21 @@ function checkArrayShape(schema, value, path, problems, spelling) {
|
|
|
1505
1385
|
}
|
|
1506
1386
|
function checkObjectShape(schema, value, path, problems, spelling) {
|
|
1507
1387
|
const properties = (schema.properties ?? {});
|
|
1508
|
-
// A
|
|
1509
|
-
// key, as `JSON.parse` does.
|
|
1388
|
+
// A map (`additionalProperties`) keeps the last repeated key, as `JSON.parse` does.
|
|
1510
1389
|
for (const name of spelling?.repeated.get(value) ?? []) {
|
|
1511
1390
|
if (Object.hasOwn(properties, name)) {
|
|
1512
1391
|
problems.push(`${path} has duplicate field ${describeValue(name)}`);
|
|
1513
1392
|
}
|
|
1514
1393
|
}
|
|
1515
1394
|
const numbers = spelling?.numbers.get(value);
|
|
1516
|
-
// `
|
|
1395
|
+
// `JSON.stringify` drops `undefined`, so it counts as omitted.
|
|
1517
1396
|
for (const name of (schema.required ?? [])) {
|
|
1518
1397
|
if (value[name] === undefined)
|
|
1519
1398
|
problems.push(`${path}.${name} is required`);
|
|
1520
1399
|
}
|
|
1521
1400
|
const extra = schema.additionalProperties;
|
|
1522
1401
|
const read = {};
|
|
1523
|
-
//
|
|
1524
|
-
// prototype and leave the key out of the checks that follow.
|
|
1402
|
+
// Assigning `__proto__` would replace the copy's prototype instead of adding the key.
|
|
1525
1403
|
const keep = (name, item) => {
|
|
1526
1404
|
if (name === "__proto__") {
|
|
1527
1405
|
Object.defineProperty(read, name, {
|
|
@@ -1567,11 +1445,9 @@ function checkObjectShape(schema, value, path, problems, spelling) {
|
|
|
1567
1445
|
}
|
|
1568
1446
|
return !changed && reusingShapes && sealed(value) ? value : read;
|
|
1569
1447
|
}
|
|
1570
|
-
/** Narrows an unknown value to a plain object. */
|
|
1571
1448
|
function isRecord(value) {
|
|
1572
1449
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1573
1450
|
}
|
|
1574
|
-
/** Returns a string field, or `""` when it is absent or mistyped. */
|
|
1575
1451
|
function text(value) {
|
|
1576
1452
|
return typeof value === "string" ? value : "";
|
|
1577
1453
|
}
|
|
@@ -1581,21 +1457,14 @@ function finiteNumber(value) {
|
|
|
1581
1457
|
function safeInteger(value) {
|
|
1582
1458
|
return typeof value === "number" && Number.isSafeInteger(value);
|
|
1583
1459
|
}
|
|
1584
|
-
|
|
1460
|
+
// `fallback` when absent or `null`, `undefined` when mistyped.
|
|
1585
1461
|
function optionalFinite(value, fallback) {
|
|
1586
1462
|
if (value === undefined || value === null)
|
|
1587
1463
|
return fallback;
|
|
1588
1464
|
return finiteNumber(value) ? value : undefined;
|
|
1589
1465
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
*
|
|
1593
|
-
* Two visual clips at one timestamp have no defined composition without a transition. Overlapping
|
|
1594
|
-
* audio does: the mixer sums it into the track bus, so audio tracks may overlay freely.
|
|
1595
|
-
*
|
|
1596
|
-
* Every clip still active when the next one starts overlaps it, so the walk meets at most one
|
|
1597
|
-
* covered overlap per transition side before it either ends or stops here.
|
|
1598
|
-
*/
|
|
1466
|
+
// The first video overlap no transition covers, as the engine reports it. Audio tracks may
|
|
1467
|
+
// overlap freely because the mixer sums them.
|
|
1599
1468
|
function uncoveredOverlap(trackId, trackKind, clips, transitions) {
|
|
1600
1469
|
if (trackKind !== "video")
|
|
1601
1470
|
return undefined;
|
|
@@ -1618,7 +1487,7 @@ function uncoveredOverlap(trackId, trackKind, clips, transitions) {
|
|
|
1618
1487
|
ordered.sort(byTime);
|
|
1619
1488
|
const active = [];
|
|
1620
1489
|
for (const b of ordered) {
|
|
1621
|
-
//
|
|
1490
|
+
// Keep only clips still active when `b` starts, in place.
|
|
1622
1491
|
let kept = 0;
|
|
1623
1492
|
for (const a of active)
|
|
1624
1493
|
if (a.timeline_range.end > b.timeline_range.start)
|
|
@@ -1634,9 +1503,8 @@ function uncoveredOverlap(trackId, trackKind, clips, transitions) {
|
|
|
1634
1503
|
}
|
|
1635
1504
|
}
|
|
1636
1505
|
active.push(b);
|
|
1637
|
-
//
|
|
1638
|
-
//
|
|
1639
|
-
// k - 1 others.
|
|
1506
|
+
// Transitions among simultaneously active clips must not form a cycle. A tournament is
|
|
1507
|
+
// acyclic exactly when its out-degrees are 0, 1, ..., k - 1.
|
|
1640
1508
|
if (active.length >= 3) {
|
|
1641
1509
|
const leads = active
|
|
1642
1510
|
.map((from) => active.filter((to) => directed.has(`${text(from.id)}\u0000${text(to.id)}`)).length)
|
|
@@ -1683,11 +1551,8 @@ function audioProblems(clipId, audio) {
|
|
|
1683
1551
|
}
|
|
1684
1552
|
return problems;
|
|
1685
1553
|
}
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
* checks: it grows with the timeline time, so the last instant has the largest, `offset +
|
|
1689
|
-
* floor((end - 1 - start) * num / den)`.
|
|
1690
|
-
*/
|
|
1554
|
+
// Composition time is largest at the clip's last instant: `offset + floor((end - 1 - start) *
|
|
1555
|
+
// num / den)`, which must fit a safe integer.
|
|
1691
1556
|
function compositionTimeHeld(clip, reference, scale) {
|
|
1692
1557
|
const range = clip.timeline_range;
|
|
1693
1558
|
const num = scale === undefined ? 1 : scale.num;
|
|
@@ -1698,7 +1563,7 @@ function compositionTimeHeld(clip, reference, scale) {
|
|
|
1698
1563
|
!positiveInteger(den) ||
|
|
1699
1564
|
!Number.isSafeInteger(offset))
|
|
1700
1565
|
return true;
|
|
1701
|
-
// The range is
|
|
1566
|
+
// The range is non-empty, so BigInt division here rounds down.
|
|
1702
1567
|
const elapsed = BigInt(range.end) - 1n - BigInt(range.start);
|
|
1703
1568
|
const local = BigInt(offset) + (elapsed * BigInt(num)) / BigInt(den);
|
|
1704
1569
|
return local <= BigInt(Number.MAX_SAFE_INTEGER);
|
|
@@ -1712,7 +1577,6 @@ function validRange(range) {
|
|
|
1712
1577
|
safeInteger(range.end) &&
|
|
1713
1578
|
range.end > range.start);
|
|
1714
1579
|
}
|
|
1715
|
-
/** A freeze's instant lies in the clip's half-open source range. */
|
|
1716
1580
|
function freezesInside(timeMap, sourceRange) {
|
|
1717
1581
|
if (!isRecord(timeMap) || timeMap.type !== "freeze")
|
|
1718
1582
|
return true;
|
|
@@ -1724,7 +1588,6 @@ function freezesInside(timeMap, sourceRange) {
|
|
|
1724
1588
|
instant >= sourceRange.start &&
|
|
1725
1589
|
instant < sourceRange.end);
|
|
1726
1590
|
}
|
|
1727
|
-
/** Returns a range start for ordering checks; invalid ranges report separately. */
|
|
1728
1591
|
function rangeStart(range) {
|
|
1729
1592
|
return isRecord(range) && finiteNumber(range.start) ? range.start : 0;
|
|
1730
1593
|
}
|
|
@@ -1753,10 +1616,7 @@ function animationValues(animation) {
|
|
|
1753
1616
|
}
|
|
1754
1617
|
return values;
|
|
1755
1618
|
}
|
|
1756
|
-
|
|
1757
|
-
* Whether an easing or interpolation's parameters are usable: a `cubic_bezier` keeps `x1` and `x2`
|
|
1758
|
-
* in `0..=1` so the curve stays a function of time. `y1` and `y2` may overshoot.
|
|
1759
|
-
*/
|
|
1619
|
+
// `x1` and `x2` must lie in `0..=1` so the curve stays a function of time.
|
|
1760
1620
|
function validCurve(curve) {
|
|
1761
1621
|
if (!isRecord(curve))
|
|
1762
1622
|
return false;
|
|
@@ -1787,13 +1647,12 @@ function validVisual(visual) {
|
|
|
1787
1647
|
if (visual === undefined)
|
|
1788
1648
|
return true;
|
|
1789
1649
|
return (isRecord(visual) &&
|
|
1790
|
-
validVec2(visual.anchor) &&
|
|
1791
|
-
validPointAnimation(visual.position) &&
|
|
1792
|
-
validVec2Animation(visual.scale) &&
|
|
1793
|
-
visual.rotation_degrees
|
|
1794
|
-
|
|
1795
|
-
visual.opacity
|
|
1796
|
-
validScalarAnimation(visual.opacity, 0, 1));
|
|
1650
|
+
(visual.anchor === undefined || validVec2(visual.anchor)) &&
|
|
1651
|
+
(visual.position === undefined || validPointAnimation(visual.position)) &&
|
|
1652
|
+
(visual.scale === undefined || validVec2Animation(visual.scale)) &&
|
|
1653
|
+
(visual.rotation_degrees === undefined ||
|
|
1654
|
+
validScalarAnimation(visual.rotation_degrees)) &&
|
|
1655
|
+
(visual.opacity === undefined || validScalarAnimation(visual.opacity, 0, 1)));
|
|
1797
1656
|
}
|
|
1798
1657
|
function validEffectValue(value) {
|
|
1799
1658
|
if (!isRecord(value))
|
|
@@ -1823,10 +1682,7 @@ function validEffectValue(value) {
|
|
|
1823
1682
|
return false;
|
|
1824
1683
|
}
|
|
1825
1684
|
}
|
|
1826
|
-
|
|
1827
|
-
* A constant or keyframed effect parameter: every value valid on its own, all of one type, and
|
|
1828
|
-
* `enum` and `bool` keyframes holding.
|
|
1829
|
-
*/
|
|
1685
|
+
// All values share one type, and `enum` and `bool` keyframes must hold.
|
|
1830
1686
|
function validEffectParam(param) {
|
|
1831
1687
|
const values = animationValues(param);
|
|
1832
1688
|
if (values === undefined || !values.every(validEffectValue))
|
|
@@ -1844,10 +1700,6 @@ function validEffectParam(param) {
|
|
|
1844
1700
|
param.keyframes.every((keyframe) => isRecord(keyframe.interpolation) &&
|
|
1845
1701
|
keyframe.interpolation.type === "hold"));
|
|
1846
1702
|
}
|
|
1847
|
-
/**
|
|
1848
|
-
* A parameter, resource, or named input an effect may bind: an ASCII identifier, as the model
|
|
1849
|
-
* requires.
|
|
1850
|
-
*/
|
|
1851
1703
|
const EFFECT_BINDING_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
1852
1704
|
function validClipEffect(effect) {
|
|
1853
1705
|
if (!isRecord(effect))
|
|
@@ -1863,7 +1715,6 @@ function validClipEffect(effect) {
|
|
|
1863
1715
|
Object.entries(params ?? {}).every(([name, value]) => EFFECT_BINDING_NAME.test(name) && validEffectParam(value)) &&
|
|
1864
1716
|
Object.entries(resources ?? {}).every(([name, id]) => EFFECT_BINDING_NAME.test(name) && text(id).length > 0));
|
|
1865
1717
|
}
|
|
1866
|
-
/** An effect node's named inputs: absent, or at most `MAX_EFFECT_INPUTS` well-named ones. */
|
|
1867
1718
|
function validEffectInputs(inputs) {
|
|
1868
1719
|
if (inputs === undefined)
|
|
1869
1720
|
return true;
|
|
@@ -1876,10 +1727,7 @@ function validEffectInputs(inputs) {
|
|
|
1876
1727
|
function positiveMs(value) {
|
|
1877
1728
|
return finiteNumber(value) && value > 0 && value <= MAX_ENVELOPE_MS;
|
|
1878
1729
|
}
|
|
1879
|
-
|
|
1880
|
-
* Whether `value`, read as the model's 32-bit float, lies in `[min, max]` (the model's limits,
|
|
1881
|
-
* already 32-bit).
|
|
1882
|
-
*/
|
|
1730
|
+
// The model stores these as 32-bit floats; its limits are already 32-bit.
|
|
1883
1731
|
function f32Within(value, min, max) {
|
|
1884
1732
|
if (!finiteNumber(value))
|
|
1885
1733
|
return false;
|
|
@@ -1930,26 +1778,19 @@ function validEffects(effects) {
|
|
|
1930
1778
|
effects.length <= MAX_CHAIN_EFFECTS &&
|
|
1931
1779
|
effects.every(validAudioEffect));
|
|
1932
1780
|
}
|
|
1933
|
-
/** Ticks in a millisecond. */
|
|
1934
1781
|
const TICKS_PER_MS = TICKS_PER_SECOND / 1000;
|
|
1935
|
-
|
|
1936
|
-
* What an effect counts toward {@link MAX_AUDIO_DELAY_MS}, in ticks, rounded up: a compressor its
|
|
1937
|
-
* `lookahead_ms` at the model's 32-bit precision (times 120, exact in a double), a reverb {@link
|
|
1938
|
-
* REVERB_DELAY_MS}. Whole ticks add up to the same number in any order, as the model's do.
|
|
1939
|
-
*/
|
|
1782
|
+
// Delay in whole ticks, rounded up, so sums match the model in any order.
|
|
1940
1783
|
function effectDelayTicks(effect) {
|
|
1941
1784
|
if (effect.type === "reverb")
|
|
1942
1785
|
return REVERB_DELAY_MS * TICKS_PER_MS;
|
|
1943
1786
|
return effectLookaheadTicks(effect);
|
|
1944
1787
|
}
|
|
1945
|
-
/** How early a mixer reads an effect's input, in ticks, rounded up: a compressor's lookahead. */
|
|
1946
1788
|
function effectLookaheadTicks(effect) {
|
|
1947
1789
|
if (effect.type !== "compressor" || !finiteNumber(effect.lookahead_ms))
|
|
1948
1790
|
return 0;
|
|
1949
1791
|
const lookahead = Math.fround(effect.lookahead_ms);
|
|
1950
1792
|
return lookahead > 0 ? Math.ceil(lookahead * TICKS_PER_MS) : 0;
|
|
1951
1793
|
}
|
|
1952
|
-
/** The effects of a chain, its delay, and its lookahead, in ticks. */
|
|
1953
1794
|
function chainLoad(effects) {
|
|
1954
1795
|
const load = { count: 0, delay: 0, lookahead: 0 };
|
|
1955
1796
|
if (!Array.isArray(effects))
|
|
@@ -1963,9 +1804,24 @@ function chainLoad(effects) {
|
|
|
1963
1804
|
}
|
|
1964
1805
|
return load;
|
|
1965
1806
|
}
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1807
|
+
// Mirrors `Clip::stretches_audio`.
|
|
1808
|
+
function stretchesAudio(clip) {
|
|
1809
|
+
if (!isRecord(clip.audio) || clip.audio.preserve_pitch !== true)
|
|
1810
|
+
return false;
|
|
1811
|
+
const map = clip.time_map;
|
|
1812
|
+
if (map !== undefined &&
|
|
1813
|
+
!(isRecord(map) && (map.type === "forward" || map.type === "reverse")))
|
|
1814
|
+
return false;
|
|
1815
|
+
const timeline = clip.timeline_range;
|
|
1816
|
+
const source = clip.source_range;
|
|
1817
|
+
if (!validRange(timeline) || !validRange(source))
|
|
1818
|
+
return false;
|
|
1819
|
+
const length = (range) => {
|
|
1820
|
+
const { start, end } = range;
|
|
1821
|
+
return end - start;
|
|
1822
|
+
};
|
|
1823
|
+
return length(timeline) !== length(source);
|
|
1824
|
+
}
|
|
1969
1825
|
function trackAudioLoad(track) {
|
|
1970
1826
|
if (!isRecord(track))
|
|
1971
1827
|
return undefined;
|
|
@@ -1978,7 +1834,12 @@ function trackAudioLoad(track) {
|
|
|
1978
1834
|
continue;
|
|
1979
1835
|
if (!validRange(clip.timeline_range))
|
|
1980
1836
|
continue;
|
|
1981
|
-
|
|
1837
|
+
// A stretched read holds state like one effect, without delay.
|
|
1838
|
+
const chain = chainLoad(clip.audio.effects);
|
|
1839
|
+
const own = {
|
|
1840
|
+
...chain,
|
|
1841
|
+
count: chain.count + Number(stretchesAudio(clip)),
|
|
1842
|
+
};
|
|
1982
1843
|
if (own.count === 0)
|
|
1983
1844
|
continue;
|
|
1984
1845
|
const lead = bus.lookahead + own.lookahead + margin;
|
|
@@ -1989,14 +1850,10 @@ function trackAudioLoad(track) {
|
|
|
1989
1850
|
return { count: bus.count, delay: bus.delay, edges };
|
|
1990
1851
|
}
|
|
1991
1852
|
/**
|
|
1992
|
-
* Mirrors
|
|
1993
|
-
*
|
|
1994
|
-
*
|
|
1995
|
-
*
|
|
1996
|
-
* {@link AUDIO_EFFECT_STATE_MARGIN_MS} and the lookahead of its track's and its own effects before
|
|
1997
|
-
* its start (never before zero) to its end, both included. Each limit reports its peak and the
|
|
1998
|
-
* earliest tick it is reached at, in whole ticks, so a document gets the same answer as natively.
|
|
1999
|
-
* `tracks` are the {@link trackAudioLoad} of each track.
|
|
1853
|
+
* Mirrors `Project::audio_effect_load`. Master and track effects hold state throughout; a clip's
|
|
1854
|
+
* hold from {@link AUDIO_EFFECT_STATE_MARGIN_MS} plus lookahead before its start to its end.
|
|
1855
|
+
* Each limit reports its peak and the earliest tick it is reached, in whole ticks, to match the
|
|
1856
|
+
* native result.
|
|
2000
1857
|
*/
|
|
2001
1858
|
function audioEffectProblems(master, tracks) {
|
|
2002
1859
|
const held = chainLoad(isRecord(master) ? master.effects : undefined);
|
|
@@ -2009,8 +1866,7 @@ function audioEffectProblems(master, tracks) {
|
|
|
2009
1866
|
delay += track.delay;
|
|
2010
1867
|
}
|
|
2011
1868
|
const edges = tracks.flatMap((track) => track?.edges ?? []);
|
|
2012
|
-
//
|
|
2013
|
-
// state with it.
|
|
1869
|
+
// Starts sort before ends at one position: a clip ending where another starts overlaps it.
|
|
2014
1870
|
edges.sort((a, b) => a.at - b.at || Number(a.ends) - Number(b.ends));
|
|
2015
1871
|
const peak = { effects, effectsAt: 0, delay, delayAt: 0 };
|
|
2016
1872
|
for (const edge of edges) {
|
|
@@ -2074,7 +1930,7 @@ function transitionProblems(trackId, trackKind, clips, transitions) {
|
|
|
2074
1930
|
const problems = [];
|
|
2075
1931
|
if (transitions.length === 0)
|
|
2076
1932
|
return problems;
|
|
2077
|
-
// The
|
|
1933
|
+
// The engine's track index keeps the first clip of each id.
|
|
2078
1934
|
const byId = new Map();
|
|
2079
1935
|
for (const clip of clips)
|
|
2080
1936
|
if (isRecord(clip) && !byId.has(text(clip.id)))
|
|
@@ -2104,7 +1960,7 @@ function transitionProblems(trackId, trackKind, clips, transitions) {
|
|
|
2104
1960
|
problems.push(`track ${trackId} has an invalid clip transition`);
|
|
2105
1961
|
continue;
|
|
2106
1962
|
}
|
|
2107
|
-
//
|
|
1963
|
+
// At most one transition per pair of clips, in either direction.
|
|
2108
1964
|
const ends = [text(transition.from_clip), text(transition.to_clip)].sort();
|
|
2109
1965
|
const pair = JSON.stringify(ends);
|
|
2110
1966
|
if (pairs.has(pair)) {
|
|
@@ -2114,65 +1970,257 @@ function transitionProblems(trackId, trackKind, clips, transitions) {
|
|
|
2114
1970
|
}
|
|
2115
1971
|
return problems;
|
|
2116
1972
|
}
|
|
2117
|
-
/**
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
function validCaptions(track, clips, transitions) {
|
|
1973
|
+
/** Mirrors `validate_captions`, worded as the engine words it. */
|
|
1974
|
+
function captionsProblem(track, clips, transitions, trackId) {
|
|
1975
|
+
const invalid = `track ${trackId} has invalid captions`;
|
|
2121
1976
|
if (track.kind !== "caption")
|
|
2122
|
-
return track.captions == null;
|
|
1977
|
+
return track.captions == null ? undefined : invalid;
|
|
2123
1978
|
const captions = track.captions;
|
|
2124
1979
|
if (!isRecord(captions) || clips.length > 0 || transitions.length > 0) {
|
|
2125
|
-
return
|
|
1980
|
+
return invalid;
|
|
2126
1981
|
}
|
|
2127
1982
|
const cues = captions.cues;
|
|
1983
|
+
const styles = captions.styles ?? {};
|
|
1984
|
+
const encoder = new TextEncoder();
|
|
1985
|
+
const name = (value) => typeof value === "string" &&
|
|
1986
|
+
value.length > 0 &&
|
|
1987
|
+
encoder.encode(value).length <= MAX_CAPTION_NAME_BYTES;
|
|
2128
1988
|
if (!Array.isArray(cues) ||
|
|
2129
|
-
!validTextStyle(captions.style ?? {}, MAX_CAPTION_FONT_SIZE)
|
|
2130
|
-
|
|
1989
|
+
!validTextStyle(captions.style ?? {}, MAX_CAPTION_FONT_SIZE) ||
|
|
1990
|
+
!isRecord(styles) ||
|
|
1991
|
+
Object.keys(styles).length > MAX_CAPTION_STYLES ||
|
|
1992
|
+
!Object.keys(styles).every(name)) {
|
|
1993
|
+
return invalid;
|
|
2131
1994
|
}
|
|
2132
|
-
const encoder = new TextEncoder();
|
|
2133
1995
|
let previousEnd = 0;
|
|
2134
|
-
|
|
1996
|
+
const cuesValid = cues.every((cue) => {
|
|
2135
1997
|
if (!isRecord(cue) || !validRange(cue.timeline_range))
|
|
2136
1998
|
return false;
|
|
2137
1999
|
const range = cue.timeline_range;
|
|
2138
|
-
const cueText = cue.text;
|
|
2139
2000
|
const valid = range.start >= previousEnd &&
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2001
|
+
validTextContent(cue.text, encoder) &&
|
|
2002
|
+
(cue.speaker == null || name(cue.speaker)) &&
|
|
2003
|
+
runTimesLieIn(cue.text, range.end - range.start);
|
|
2143
2004
|
previousEnd = range.end;
|
|
2144
2005
|
return valid;
|
|
2145
2006
|
});
|
|
2007
|
+
if (!cuesValid)
|
|
2008
|
+
return invalid;
|
|
2009
|
+
for (const [index, cue] of cues.entries()) {
|
|
2010
|
+
const own = cue.style;
|
|
2011
|
+
if (typeof own === "string" && !Object.hasOwn(styles, own)) {
|
|
2012
|
+
return `cue ${index} of track ${trackId} names style ${JSON.stringify(own)}, which the track does not have`;
|
|
2013
|
+
}
|
|
2014
|
+
const patchName = typeof own === "string"
|
|
2015
|
+
? own
|
|
2016
|
+
: typeof cue.speaker === "string" && Object.hasOwn(styles, cue.speaker)
|
|
2017
|
+
? cue.speaker
|
|
2018
|
+
: undefined;
|
|
2019
|
+
if (patchName === undefined)
|
|
2020
|
+
continue;
|
|
2021
|
+
const merged = patchedStyle(captions.style ?? {}, styles[patchName]);
|
|
2022
|
+
if (!validTextStyle(merged, MAX_CAPTION_FONT_SIZE)) {
|
|
2023
|
+
return `cue ${index} of track ${trackId} has a style out of range once its patch is applied`;
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
return undefined;
|
|
2027
|
+
}
|
|
2028
|
+
function runTimesLieIn(text, duration) {
|
|
2029
|
+
if (!Array.isArray(text))
|
|
2030
|
+
return true;
|
|
2031
|
+
return text.every((run) => {
|
|
2032
|
+
if (!isRecord(run) || run.time == null)
|
|
2033
|
+
return true;
|
|
2034
|
+
const time = run.time;
|
|
2035
|
+
return (finiteNumber(time.start) &&
|
|
2036
|
+
finiteNumber(time.end) &&
|
|
2037
|
+
time.start >= 0 &&
|
|
2038
|
+
time.end <= duration);
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
/** Mirrors `TextStylePatch::apply`; `null` clears a field. */
|
|
2042
|
+
function patchedStyle(base, patch) {
|
|
2043
|
+
const merged = isRecord(base) ? { ...base } : {};
|
|
2044
|
+
if (!isRecord(patch))
|
|
2045
|
+
return merged;
|
|
2046
|
+
for (const [field, value] of Object.entries(patch)) {
|
|
2047
|
+
if (value === undefined)
|
|
2048
|
+
continue;
|
|
2049
|
+
if (value === null)
|
|
2050
|
+
delete merged[field];
|
|
2051
|
+
else
|
|
2052
|
+
merged[field] = value;
|
|
2053
|
+
}
|
|
2054
|
+
return merged;
|
|
2146
2055
|
}
|
|
2147
|
-
/** Mirrors `TextStyle::is_valid
|
|
2056
|
+
/** Mirrors `TextStyle::is_valid`. */
|
|
2148
2057
|
function validTextStyle(style, maxFontSize) {
|
|
2149
2058
|
if (!isRecord(style))
|
|
2150
2059
|
return false;
|
|
2151
2060
|
const within = (value, low, high, open = false) => finiteNumber(value) && (open ? value > low : value >= low) && value <= high;
|
|
2152
|
-
const outline = style.outline;
|
|
2153
2061
|
const background = style.background;
|
|
2154
2062
|
const family = style.font_family;
|
|
2155
|
-
return (
|
|
2156
|
-
// `null` is an absent family, as the model reads it.
|
|
2157
|
-
(family == null ||
|
|
2063
|
+
return ((family == null ||
|
|
2158
2064
|
(typeof family === "string" &&
|
|
2159
2065
|
family.length > 0 &&
|
|
2160
2066
|
new TextEncoder().encode(family).length <= MAX_FONT_FAMILY_BYTES)) &&
|
|
2161
2067
|
within(style.font_size ?? 0.05, 0, maxFontSize, true) &&
|
|
2162
|
-
(style.
|
|
2068
|
+
(style.fill === undefined || validTextFill(style.fill)) &&
|
|
2163
2069
|
within(style.line_height ?? 1.2, MIN_LINE_HEIGHT, MAX_LINE_HEIGHT) &&
|
|
2070
|
+
within(style.letter_spacing ?? 0, MIN_LETTER_SPACING, MAX_LETTER_SPACING) &&
|
|
2071
|
+
validFontWeight(style.font_weight ?? 400) &&
|
|
2164
2072
|
within(style.max_width ?? 0.9, 0, 1, true) &&
|
|
2165
2073
|
(style.position === undefined || validVec2(style.position)) &&
|
|
2166
2074
|
(style.anchor === undefined || validVec2(style.anchor)) &&
|
|
2167
|
-
(
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2075
|
+
(style.strokes === undefined || validTextStrokes(style.strokes)) &&
|
|
2076
|
+
(style.shadows === undefined || validTextShadows(style.shadows)) &&
|
|
2077
|
+
(style.animators === undefined ||
|
|
2078
|
+
validTextAnimators(style.animators, false)) &&
|
|
2171
2079
|
(background == null ||
|
|
2172
2080
|
(isRecord(background) &&
|
|
2173
2081
|
validRgba(background.color) &&
|
|
2174
2082
|
within(background.padding ?? 0, 0, MAX_TEXT_PADDING))));
|
|
2175
2083
|
}
|
|
2084
|
+
/** Mirrors `TextContent::is_valid`. */
|
|
2085
|
+
function validTextContent(text, encoder) {
|
|
2086
|
+
if (typeof text === "string") {
|
|
2087
|
+
return (text.length > 0 && encoder.encode(text).length <= MAX_TEXT_CONTENT_BYTES);
|
|
2088
|
+
}
|
|
2089
|
+
if (!Array.isArray(text) || text.length > MAX_TEXT_RUNS)
|
|
2090
|
+
return false;
|
|
2091
|
+
let bytes = 0;
|
|
2092
|
+
for (const run of text) {
|
|
2093
|
+
if (!isRecord(run) || typeof run.text !== "string" || run.text.length === 0)
|
|
2094
|
+
return false;
|
|
2095
|
+
bytes += encoder.encode(run.text).length;
|
|
2096
|
+
const classes = run.class ?? [];
|
|
2097
|
+
if (!Array.isArray(classes) ||
|
|
2098
|
+
classes.length > MAX_RUN_CLASSES ||
|
|
2099
|
+
!classes.every(validClassName)) {
|
|
2100
|
+
return false;
|
|
2101
|
+
}
|
|
2102
|
+
const time = run.time;
|
|
2103
|
+
if (time != null &&
|
|
2104
|
+
!(isRecord(time) &&
|
|
2105
|
+
safeInteger(time.start) &&
|
|
2106
|
+
safeInteger(time.end) &&
|
|
2107
|
+
time.start >= 0 &&
|
|
2108
|
+
time.start < time.end)) {
|
|
2109
|
+
return false;
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
return bytes > 0 && bytes <= MAX_TEXT_CONTENT_BYTES;
|
|
2113
|
+
}
|
|
2114
|
+
/** Mirrors `valid_class_name`. */
|
|
2115
|
+
function validClassName(name) {
|
|
2116
|
+
return (typeof name === "string" &&
|
|
2117
|
+
name.length > 0 &&
|
|
2118
|
+
name.length <= MAX_CLASS_NAME_BYTES &&
|
|
2119
|
+
/^[A-Za-z0-9_-]+$/.test(name));
|
|
2120
|
+
}
|
|
2121
|
+
/** Mirrors `valid_animators`; `rangeOnly` allows only Range selectors (layout nodes). */
|
|
2122
|
+
function validTextAnimators(animators, rangeOnly) {
|
|
2123
|
+
if (!Array.isArray(animators) || animators.length > MAX_TEXT_ANIMATORS)
|
|
2124
|
+
return false;
|
|
2125
|
+
return animators.every((animator) => {
|
|
2126
|
+
if (!isRecord(animator) || !isRecord(animator.selector))
|
|
2127
|
+
return false;
|
|
2128
|
+
const selector = animator.selector;
|
|
2129
|
+
if (rangeOnly && selector.type !== "range")
|
|
2130
|
+
return false;
|
|
2131
|
+
let selected;
|
|
2132
|
+
switch (selector.type) {
|
|
2133
|
+
case "range": {
|
|
2134
|
+
const [low, high] = selector.units === "index"
|
|
2135
|
+
? [-MAX_RANGE_INDEX, 2 * MAX_RANGE_INDEX]
|
|
2136
|
+
: [MIN_RANGE_PERCENT, MAX_RANGE_PERCENT];
|
|
2137
|
+
selected =
|
|
2138
|
+
[selector.start, selector.end, selector.offset].every((value) => validScalarAnimation(value, low, high)) && validScalarAnimation(selector.amount, 0, 1);
|
|
2139
|
+
break;
|
|
2140
|
+
}
|
|
2141
|
+
case "timing":
|
|
2142
|
+
selected =
|
|
2143
|
+
selector.ramp === undefined ||
|
|
2144
|
+
(safeInteger(selector.ramp) && selector.ramp >= 0);
|
|
2145
|
+
break;
|
|
2146
|
+
case "class":
|
|
2147
|
+
selected = validClassName(selector.class);
|
|
2148
|
+
break;
|
|
2149
|
+
default:
|
|
2150
|
+
selected = false;
|
|
2151
|
+
}
|
|
2152
|
+
return selected && validAnimatorProperties(animator.properties ?? {});
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
/** Mirrors `TextAnimatorProperties::is_valid`. */
|
|
2156
|
+
function validAnimatorProperties(properties) {
|
|
2157
|
+
if (!isRecord(properties))
|
|
2158
|
+
return false;
|
|
2159
|
+
const vec2 = (animation, low, high) => {
|
|
2160
|
+
if (animation === undefined)
|
|
2161
|
+
return true;
|
|
2162
|
+
const values = animationValues(animation);
|
|
2163
|
+
return (values !== undefined &&
|
|
2164
|
+
values.every((value) => isRecord(value) &&
|
|
2165
|
+
[value.x, value.y].every((axis) => finiteNumber(axis) && axis >= low && axis <= high)));
|
|
2166
|
+
};
|
|
2167
|
+
const color = (animation) => {
|
|
2168
|
+
if (animation === undefined)
|
|
2169
|
+
return true;
|
|
2170
|
+
const values = animationValues(animation);
|
|
2171
|
+
return values !== undefined && values.every(validRgba);
|
|
2172
|
+
};
|
|
2173
|
+
return (vec2(properties.offset, -Infinity, Infinity) &&
|
|
2174
|
+
vec2(properties.scale, 0, MAX_ANIMATOR_SCALE) &&
|
|
2175
|
+
validScalarAnimation(properties.rotation_degrees) &&
|
|
2176
|
+
validScalarAnimation(properties.opacity, 0, 1) &&
|
|
2177
|
+
color(properties.fill) &&
|
|
2178
|
+
color(properties.stroke) &&
|
|
2179
|
+
validScalarAnimation(properties.tracking, MIN_LETTER_SPACING, MAX_LETTER_SPACING));
|
|
2180
|
+
}
|
|
2181
|
+
function validTextFill(fill) {
|
|
2182
|
+
return isRecord(fill) && "type" in fill ? validPaint(fill) : validRgba(fill);
|
|
2183
|
+
}
|
|
2184
|
+
/** Mirrors `valid_strokes`; widths are summed in `f32` as the model does. */
|
|
2185
|
+
function validTextStrokes(strokes) {
|
|
2186
|
+
if (!Array.isArray(strokes) || strokes.length > MAX_TEXT_STROKES)
|
|
2187
|
+
return false;
|
|
2188
|
+
let extent = 0;
|
|
2189
|
+
for (const stroke of strokes) {
|
|
2190
|
+
if (!isRecord(stroke) ||
|
|
2191
|
+
!validRgba(stroke.color) ||
|
|
2192
|
+
!finiteNumber(stroke.width) ||
|
|
2193
|
+
Math.fround(stroke.width) <= 0) {
|
|
2194
|
+
return false;
|
|
2195
|
+
}
|
|
2196
|
+
extent = Math.fround(extent + Math.fround(stroke.width));
|
|
2197
|
+
}
|
|
2198
|
+
return extent <= Math.fround(MAX_TEXT_STROKE_EXTENT);
|
|
2199
|
+
}
|
|
2200
|
+
/** Mirrors `valid_shadows`. */
|
|
2201
|
+
function validTextShadows(shadows) {
|
|
2202
|
+
if (!Array.isArray(shadows) || shadows.length > MAX_TEXT_SHADOWS)
|
|
2203
|
+
return false;
|
|
2204
|
+
const offset = (value) => finiteNumber(value) && Math.abs(value) <= MAX_TEXT_SHADOW_OFFSET;
|
|
2205
|
+
return shadows.every((shadow) => {
|
|
2206
|
+
if (!isRecord(shadow))
|
|
2207
|
+
return false;
|
|
2208
|
+
const blur = shadow.blur ?? 0;
|
|
2209
|
+
return (validRgba(shadow.color) &&
|
|
2210
|
+
(shadow.offset === undefined ||
|
|
2211
|
+
(isRecord(shadow.offset) &&
|
|
2212
|
+
offset(shadow.offset.x) &&
|
|
2213
|
+
offset(shadow.offset.y))) &&
|
|
2214
|
+
finiteNumber(blur) &&
|
|
2215
|
+
blur >= 0 &&
|
|
2216
|
+
blur <= MAX_TEXT_SHADOW_BLUR);
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
2219
|
+
function validFontWeight(weight) {
|
|
2220
|
+
return (Number.isInteger(weight) &&
|
|
2221
|
+
weight >= MIN_FONT_WEIGHT &&
|
|
2222
|
+
weight <= MAX_FONT_WEIGHT);
|
|
2223
|
+
}
|
|
2176
2224
|
/** Mirrors `ProviderSource::kind` and `ProviderSource::is_valid`. */
|
|
2177
2225
|
function validProvider(provider, kind) {
|
|
2178
2226
|
if (!isRecord(provider))
|
|
@@ -2225,11 +2273,7 @@ function validFingerprint(fingerprint) {
|
|
|
2225
2273
|
return (audio == null ||
|
|
2226
2274
|
(isRecord(audio) && positive(audio.channels) && positive(audio.sample_rate)));
|
|
2227
2275
|
}
|
|
2228
|
-
/**
|
|
2229
|
-
* Whether a color's dynamic range says what its transfer does: HDR exactly when the transfer is PQ
|
|
2230
|
-
* or HLG, as the engine's `ColorMetadata::is_consistent` requires. The schema checks each field's
|
|
2231
|
-
* shape.
|
|
2232
|
-
*/
|
|
2276
|
+
/** Mirrors `ColorMetadata::is_consistent`: HDR exactly when the transfer is PQ or HLG. */
|
|
2233
2277
|
function consistentColor(color) {
|
|
2234
2278
|
if (!isRecord(color))
|
|
2235
2279
|
return true;
|
|
@@ -2239,13 +2283,6 @@ function consistentColor(color) {
|
|
|
2239
2283
|
function positive(value) {
|
|
2240
2284
|
return typeof value === "number" && value > 0;
|
|
2241
2285
|
}
|
|
2242
|
-
/**
|
|
2243
|
-
* A fill whose paint is valid: colors in `0..=1`, gradients of two to {@link MAX_GRADIENT_STOPS}
|
|
2244
|
-
* ordered stops, a linear gradient's ends distinct, a radial radius positive. Or shapes whose
|
|
2245
|
-
* content tree is valid ({@link shapeItemsIssue}). Or text: non-empty, at most
|
|
2246
|
-
* {@link MAX_TEXT_CONTENT_BYTES} bytes, in a valid style whose font size is at most
|
|
2247
|
-
* {@link MAX_TEXT_GENERATOR_FONT_SIZE}. Or a layout whose tree is valid ({@link layoutIssue}).
|
|
2248
|
-
*/
|
|
2249
2286
|
function validGenerator(generator) {
|
|
2250
2287
|
if (!isRecord(generator))
|
|
2251
2288
|
return false;
|
|
@@ -2256,10 +2293,7 @@ function validGenerator(generator) {
|
|
|
2256
2293
|
if (generator.type === "layout")
|
|
2257
2294
|
return layoutIssue(generator.root) === undefined;
|
|
2258
2295
|
if (generator.type === "text")
|
|
2259
|
-
return (
|
|
2260
|
-
generator.text.length > 0 &&
|
|
2261
|
-
new TextEncoder().encode(generator.text).length <=
|
|
2262
|
-
MAX_TEXT_CONTENT_BYTES &&
|
|
2296
|
+
return (validTextContent(generator.text, new TextEncoder()) &&
|
|
2263
2297
|
validTextStyle(generator.style ?? {}, MAX_TEXT_GENERATOR_FONT_SIZE));
|
|
2264
2298
|
return false;
|
|
2265
2299
|
}
|
|
@@ -2274,13 +2308,11 @@ const SHAPE_PROBLEM = {
|
|
|
2274
2308
|
pathKeyframesDiffer: "has path keyframes that differ in structure",
|
|
2275
2309
|
paintKeyframesDiffer: "has paint keyframes that differ in kind or stops",
|
|
2276
2310
|
};
|
|
2277
|
-
/** A generator's shape problem, if it is a shapes generator with one. */
|
|
2278
2311
|
function generatorShapeIssue(generator) {
|
|
2279
2312
|
return isRecord(generator) && generator.type === "shapes"
|
|
2280
2313
|
? shapeItemsIssue(generator.items)
|
|
2281
2314
|
: undefined;
|
|
2282
2315
|
}
|
|
2283
|
-
/** `issue` as a problem of `owner` (`source s`, `clip c`, `node n of composition g`). */
|
|
2284
2316
|
function shapeProblem(owner, issue) {
|
|
2285
2317
|
return `${owner} has an invalid shape: ${issue.at} ${issue.problem}`;
|
|
2286
2318
|
}
|
|
@@ -2309,16 +2341,11 @@ const LAYOUT_PROBLEM = {
|
|
|
2309
2341
|
paintKeyframesDiffer: "has paint keyframes that differ in kind or stops",
|
|
2310
2342
|
textKeyframesInterpolate: "has text keyframes that do not hold",
|
|
2311
2343
|
};
|
|
2312
|
-
/**
|
|
2313
|
-
* A generator's layout problem, if it is a layout generator with one; pixel font sizes are held
|
|
2314
|
-
* to the limit on `canvas` when it is known.
|
|
2315
|
-
*/
|
|
2316
2344
|
function generatorLayoutIssue(generator, canvas) {
|
|
2317
2345
|
return isRecord(generator) && generator.type === "layout"
|
|
2318
2346
|
? layoutIssue(generator.root, canvas)
|
|
2319
2347
|
: undefined;
|
|
2320
2348
|
}
|
|
2321
|
-
/** `issue` as a problem of `owner`, worded as the engine words it. */
|
|
2322
2349
|
function layoutProblem(owner, issue) {
|
|
2323
2350
|
return issue.shape === true
|
|
2324
2351
|
? shapeProblem(owner, issue)
|
|
@@ -2382,27 +2409,21 @@ const LAYOUT_VISUAL_FIELDS = [
|
|
|
2382
2409
|
"scale",
|
|
2383
2410
|
"rotation_degrees",
|
|
2384
2411
|
];
|
|
2385
|
-
|
|
2412
|
+
// The model reads `null` as absent.
|
|
2386
2413
|
function present(value) {
|
|
2387
2414
|
return value !== undefined && value !== null;
|
|
2388
2415
|
}
|
|
2389
|
-
/** The first of `fields` present on `node`. */
|
|
2390
2416
|
function firstPresent(node, fields) {
|
|
2391
2417
|
return fields.find((field) => present(node[field]));
|
|
2392
2418
|
}
|
|
2393
|
-
/** A length as the shape walk reads it ({@link readLayoutLength}). */
|
|
2394
2419
|
function lengthOf(value) {
|
|
2395
2420
|
return isRecord(value) && typeof value.unit === "string"
|
|
2396
2421
|
? value
|
|
2397
2422
|
: undefined;
|
|
2398
2423
|
}
|
|
2399
2424
|
/**
|
|
2400
|
-
* Mirrors `validate_layout`: the first problem of a layout tree in preorder
|
|
2401
|
-
*
|
|
2402
|
-
* {@link MAX_LAYOUT_TEXTS} texts, {@link MAX_LAYOUT_ISOLATED} isolated nodes,
|
|
2403
|
-
* {@link MAX_SHAPE_ITEMS} shape items over every shape node), its structure, which fields apply
|
|
2404
|
-
* where, every value's range, and keyframes alike in kind. With `canvas`, a pixel font size is
|
|
2405
|
-
* held to the largest a layout's text may be.
|
|
2425
|
+
* Mirrors `validate_layout`: the first problem of a layout tree in preorder. With `canvas`, pixel
|
|
2426
|
+
* font sizes are checked against the layout text limit.
|
|
2406
2427
|
*/
|
|
2407
2428
|
function layoutIssue(root, canvas) {
|
|
2408
2429
|
const node = isRecord(root) ? root : {};
|
|
@@ -2493,7 +2514,7 @@ function layoutNodeIssue(value, at, depth, counts, context) {
|
|
|
2493
2514
|
}
|
|
2494
2515
|
return undefined;
|
|
2495
2516
|
}
|
|
2496
|
-
/**
|
|
2517
|
+
/** Mirrors `checks::animated`: keyframes first, then values. */
|
|
2497
2518
|
function layoutAnimatedIssue(animation, at, check) {
|
|
2498
2519
|
if (!present(animation))
|
|
2499
2520
|
return undefined;
|
|
@@ -2507,7 +2528,6 @@ function layoutAnimatedIssue(animation, at, check) {
|
|
|
2507
2528
|
function layoutScalarIssue(animation, at, check) {
|
|
2508
2529
|
return layoutAnimatedIssue(animation, at, (value) => finiteNumber(value) && check(value));
|
|
2509
2530
|
}
|
|
2510
|
-
/** A size that may not be a percent: each value's number. */
|
|
2511
2531
|
function layoutSizeIssue(animation, at, check) {
|
|
2512
2532
|
return layoutAnimatedIssue(animation, at, (value) => {
|
|
2513
2533
|
const length = lengthOf(value);
|
|
@@ -2523,7 +2543,7 @@ function layoutInsetsIssue(animation, at, check) {
|
|
|
2523
2543
|
check(length.value));
|
|
2524
2544
|
}));
|
|
2525
2545
|
}
|
|
2526
|
-
|
|
2546
|
+
// Checks values, then that keyframes are all percents or all lengths.
|
|
2527
2547
|
function layoutLengthIssue(animation, at, check) {
|
|
2528
2548
|
const issue = layoutSizeIssue(animation, at, check);
|
|
2529
2549
|
if (issue || !present(animation))
|
|
@@ -2592,7 +2612,6 @@ function layoutFieldsIssue(node, at) {
|
|
|
2592
2612
|
layoutAnimatedIssue(node.scale, field("scale"), validVec2) ??
|
|
2593
2613
|
layoutScalarIssue(node.rotation_degrees, field("rotation_degrees"), anyValue));
|
|
2594
2614
|
}
|
|
2595
|
-
/** A track size's lengths and `fr` share, as the shape walk reads it. */
|
|
2596
2615
|
function trackParts(size) {
|
|
2597
2616
|
const breadths = size.kind === "breadth"
|
|
2598
2617
|
? [size.breadth]
|
|
@@ -2605,7 +2624,7 @@ function trackParts(size) {
|
|
|
2605
2624
|
const last = breadths.at(-1);
|
|
2606
2625
|
return { lengths, share: last?.kind === "fr" ? last.share : undefined };
|
|
2607
2626
|
}
|
|
2608
|
-
/** Mirrors `TrackSize::is_fixed
|
|
2627
|
+
/** Mirrors `TrackSize::is_fixed`. */
|
|
2609
2628
|
function fixedTrack(size) {
|
|
2610
2629
|
const fixed = (breadth) => breadth.kind === "length";
|
|
2611
2630
|
if (size.kind === "breadth")
|
|
@@ -2671,7 +2690,7 @@ function layoutGridIssue(node, at) {
|
|
|
2671
2690
|
}
|
|
2672
2691
|
return undefined;
|
|
2673
2692
|
}
|
|
2674
|
-
/** Mirrors `layout::validate_style
|
|
2693
|
+
/** Mirrors `layout::validate_style`. */
|
|
2675
2694
|
function layoutStyleIssue(node, at, shorterSide) {
|
|
2676
2695
|
const outOfRange = (name) => ({
|
|
2677
2696
|
at: `${at}.${name}`,
|
|
@@ -2690,7 +2709,6 @@ function layoutStyleIssue(node, at, shorterSide) {
|
|
|
2690
2709
|
!finiteNumber(length.value) ||
|
|
2691
2710
|
length.value <= 0)
|
|
2692
2711
|
return false;
|
|
2693
|
-
// Pixels compare with the limit on a known canvas only.
|
|
2694
2712
|
const fraction = length.unit !== "px"
|
|
2695
2713
|
? length.value
|
|
2696
2714
|
: shorterSide === undefined
|
|
@@ -2700,8 +2718,8 @@ function layoutStyleIssue(node, at, shorterSide) {
|
|
|
2700
2718
|
});
|
|
2701
2719
|
if (size)
|
|
2702
2720
|
return size;
|
|
2703
|
-
if (present(node.
|
|
2704
|
-
return outOfRange("
|
|
2721
|
+
if (present(node.fill) && !validTextFill(node.fill)) {
|
|
2722
|
+
return outOfRange("fill");
|
|
2705
2723
|
}
|
|
2706
2724
|
const lineHeight = node.line_height;
|
|
2707
2725
|
if (present(lineHeight) &&
|
|
@@ -2710,18 +2728,29 @@ function layoutStyleIssue(node, at, shorterSide) {
|
|
|
2710
2728
|
lineHeight <= MAX_LINE_HEIGHT)) {
|
|
2711
2729
|
return outOfRange("line_height");
|
|
2712
2730
|
}
|
|
2713
|
-
const
|
|
2714
|
-
if (present(
|
|
2715
|
-
!(
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2731
|
+
const letterSpacing = node.letter_spacing;
|
|
2732
|
+
if (present(letterSpacing) &&
|
|
2733
|
+
!(finiteNumber(letterSpacing) &&
|
|
2734
|
+
letterSpacing >= MIN_LETTER_SPACING &&
|
|
2735
|
+
letterSpacing <= MAX_LETTER_SPACING)) {
|
|
2736
|
+
return outOfRange("letter_spacing");
|
|
2737
|
+
}
|
|
2738
|
+
if (present(node.font_weight) && !validFontWeight(node.font_weight)) {
|
|
2739
|
+
return outOfRange("font_weight");
|
|
2740
|
+
}
|
|
2741
|
+
if (present(node.strokes) && !validTextStrokes(node.strokes)) {
|
|
2742
|
+
return outOfRange("strokes");
|
|
2743
|
+
}
|
|
2744
|
+
if (present(node.shadows) && !validTextShadows(node.shadows)) {
|
|
2745
|
+
return outOfRange("shadows");
|
|
2746
|
+
}
|
|
2747
|
+
if (present(node.text_animators) &&
|
|
2748
|
+
!validTextAnimators(node.text_animators, true)) {
|
|
2749
|
+
return outOfRange("text_animators");
|
|
2721
2750
|
}
|
|
2722
2751
|
return undefined;
|
|
2723
2752
|
}
|
|
2724
|
-
/** Mirrors `layout::validate_text
|
|
2753
|
+
/** Mirrors `layout::validate_text`. */
|
|
2725
2754
|
function layoutTextIssue(content, at) {
|
|
2726
2755
|
const keyframes = layoutAnimatedIssue(content, at, () => true);
|
|
2727
2756
|
if (keyframes)
|
|
@@ -2736,11 +2765,7 @@ function layoutTextIssue(content, at) {
|
|
|
2736
2765
|
return layoutAnimatedIssue(content, at, (value) => typeof value === "string" &&
|
|
2737
2766
|
new TextEncoder().encode(value).length <= MAX_TEXT_CONTENT_BYTES);
|
|
2738
2767
|
}
|
|
2739
|
-
/**
|
|
2740
|
-
* Mirrors `validate_shape_items`: the first problem of a content tree in document order. Its
|
|
2741
|
-
* limits ({@link MAX_SHAPE_ITEMS} items over every group, groups {@link MAX_SHAPE_DEPTH}
|
|
2742
|
-
* deep), every value's range, and keyframed paths and paints alike in structure.
|
|
2743
|
-
*/
|
|
2768
|
+
/** Mirrors `validate_shape_items`: the first problem of a content tree in document order. */
|
|
2744
2769
|
function shapeItemsIssue(items) {
|
|
2745
2770
|
const counted = { count: 0 };
|
|
2746
2771
|
return shapeGroupIssue(items, "items", 1, counted);
|
|
@@ -2789,10 +2814,7 @@ function shapeItemIssue(item, at, depth, counted) {
|
|
|
2789
2814
|
const unitValue = (value) => value >= 0 && value <= 1;
|
|
2790
2815
|
const nonNegativeValue = (value) => value >= 0;
|
|
2791
2816
|
const anyValue = () => true;
|
|
2792
|
-
|
|
2793
|
-
* An animated scalar's problem: keyframes empty, out of order, or with an unusable curve, then any
|
|
2794
|
-
* value not finite or failing `check`. A missing value takes its default, which is valid.
|
|
2795
|
-
*/
|
|
2817
|
+
// Keyframe problems first, then values. A missing value takes its (valid) default.
|
|
2796
2818
|
function shapeScalarIssue(animation, at, check) {
|
|
2797
2819
|
if (animation === undefined)
|
|
2798
2820
|
return undefined;
|
|
@@ -2815,7 +2837,7 @@ function shapeVec2Issue(animation, at, check) {
|
|
|
2815
2837
|
? undefined
|
|
2816
2838
|
: { at, problem: SHAPE_PROBLEM.outOfRange };
|
|
2817
2839
|
}
|
|
2818
|
-
/** Mirrors `valid_point_animation
|
|
2840
|
+
/** Mirrors `valid_point_animation`. */
|
|
2819
2841
|
function validPointAnimation(animation) {
|
|
2820
2842
|
return shapePointIssue(animation, "") === undefined;
|
|
2821
2843
|
}
|
|
@@ -2837,7 +2859,7 @@ function shapePointIssue(animation, at) {
|
|
|
2837
2859
|
: { at, problem: SHAPE_PROBLEM.outOfRange };
|
|
2838
2860
|
}
|
|
2839
2861
|
const nonNegativeSize = (value) => value.x >= 0 && value.y >= 0;
|
|
2840
|
-
/** Mirrors `ShapeGeometry::validate
|
|
2862
|
+
/** Mirrors `ShapeGeometry::validate`. */
|
|
2841
2863
|
function shapeGeometryIssue(geometry, at) {
|
|
2842
2864
|
switch (geometry.type) {
|
|
2843
2865
|
case "rectangle":
|
|
@@ -2897,13 +2919,12 @@ function strokeIssue(stroke, at) {
|
|
|
2897
2919
|
if (entryIssue)
|
|
2898
2920
|
return entryIssue;
|
|
2899
2921
|
}
|
|
2900
|
-
//
|
|
2922
|
+
// The pattern needs some positive entry to have a length to repeat over.
|
|
2901
2923
|
const positive = pattern.some((entry) => (animationValues(entry) ?? []).some((value) => value > 0));
|
|
2902
2924
|
if (!positive)
|
|
2903
2925
|
return { at: patternAt, problem: SHAPE_PROBLEM.invalidDash };
|
|
2904
2926
|
return shapeScalarIssue(dash.offset, `${at}.dash.offset`, anyValue);
|
|
2905
2927
|
}
|
|
2906
|
-
/** A path's subpaths and vertex counts within the limits, every point and tangent finite. */
|
|
2907
2928
|
function pathIssue(path, at) {
|
|
2908
2929
|
const subpaths = isRecord(path) && Array.isArray(path.subpaths)
|
|
2909
2930
|
? path.subpaths
|
|
@@ -2925,7 +2946,7 @@ function pathIssue(path, at) {
|
|
|
2925
2946
|
(vertex.out_tangent === undefined || validVec2(vertex.out_tangent))));
|
|
2926
2947
|
return finite ? undefined : { at, problem: SHAPE_PROBLEM.outOfRange };
|
|
2927
2948
|
}
|
|
2928
|
-
|
|
2949
|
+
// Path keyframes must share each subpath's closing and vertex count.
|
|
2929
2950
|
function pathStructure(path) {
|
|
2930
2951
|
const subpaths = isRecord(path) && Array.isArray(path.subpaths)
|
|
2931
2952
|
? path.subpaths
|
|
@@ -2956,7 +2977,7 @@ function animatedPathIssue(animation, at) {
|
|
|
2956
2977
|
? undefined
|
|
2957
2978
|
: { at, problem: SHAPE_PROBLEM.pathKeyframesDiffer };
|
|
2958
2979
|
}
|
|
2959
|
-
|
|
2980
|
+
// Paint keyframes must share kind, stop count and gradient spread.
|
|
2960
2981
|
function paintStructure(paint) {
|
|
2961
2982
|
const record = isRecord(paint) ? paint : {};
|
|
2962
2983
|
const stops = Array.isArray(record.stops) ? record.stops.length : 1;
|
|
@@ -3029,12 +3050,10 @@ function validRgba(color) {
|
|
|
3029
3050
|
return (isRecord(color) &&
|
|
3030
3051
|
[color.red, color.green, color.blue, color.alpha].every((value) => finiteNumber(value) && value >= 0 && value <= 1));
|
|
3031
3052
|
}
|
|
3032
|
-
/** The inputs of a composition node's operation, named as diagnostics show them. */
|
|
3033
3053
|
function nodeInputs(op) {
|
|
3034
3054
|
switch (op.type) {
|
|
3035
3055
|
case "effect": {
|
|
3036
|
-
//
|
|
3037
|
-
// order is its byte order.
|
|
3056
|
+
// The model's map sorts by bytes; names are ASCII, so default string order matches.
|
|
3038
3057
|
const named = isRecord(op.inputs) ? op.inputs : {};
|
|
3039
3058
|
return [
|
|
3040
3059
|
["input", op.input],
|
|
@@ -3067,11 +3086,7 @@ function nodeInputs(op) {
|
|
|
3067
3086
|
return [];
|
|
3068
3087
|
}
|
|
3069
3088
|
}
|
|
3070
|
-
|
|
3071
|
-
* The compositions each of `composition`'s nodes draws in its place, as the model reads them: a
|
|
3072
|
-
* group node's, or a composition source's that a media node reads; one entry per node, `undefined`
|
|
3073
|
-
* for a node that draws none or names an absent one.
|
|
3074
|
-
*/
|
|
3089
|
+
// One entry per node: the composition it draws through a group or composition source, if any.
|
|
3075
3090
|
function drawnCompositions(composition, compositions, sources) {
|
|
3076
3091
|
return (Array.isArray(composition.nodes) ? composition.nodes : []).map((node) => {
|
|
3077
3092
|
let target;
|
|
@@ -3089,11 +3104,7 @@ function drawnCompositions(composition, compositions, sources) {
|
|
|
3089
3104
|
: undefined;
|
|
3090
3105
|
});
|
|
3091
3106
|
}
|
|
3092
|
-
|
|
3093
|
-
* Mirrors the model's check that no composition uses itself, through group nodes or composition
|
|
3094
|
-
* sources: the first found on its own path. The walk keeps its own stack, as the model's does, so a
|
|
3095
|
-
* long chain cannot exhaust the call stack.
|
|
3096
|
-
*/
|
|
3107
|
+
// Mirrors the model's self-use check. An explicit stack keeps long chains off the call stack.
|
|
3097
3108
|
function compositionUsingItself(compositions, sources) {
|
|
3098
3109
|
const uses = (id) => {
|
|
3099
3110
|
const composition = compositions.get(id);
|
|
@@ -3128,14 +3139,9 @@ function compositionUsingItself(compositions, sources) {
|
|
|
3128
3139
|
}
|
|
3129
3140
|
return undefined;
|
|
3130
3141
|
}
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
* MAX_COMPOSITION_DEPTH}, and together they draw at most {@link MAX_INLINED_NODES} nodes, each
|
|
3134
|
-
* group node or composition-source media node counted as the nodes of the composition it draws. The
|
|
3135
|
-
* references must be acyclic. Within the bounds, `nodes` is what each composition draws.
|
|
3136
|
-
*/
|
|
3142
|
+
// Mirrors the model's inlined depth and node bounds. References must be acyclic. Within bounds,
|
|
3143
|
+
// `nodes` is what each composition draws.
|
|
3137
3144
|
function compositionExpansion(compositions, sources) {
|
|
3138
|
-
// Counted in dependency order without recursion.
|
|
3139
3145
|
const walked = new Map();
|
|
3140
3146
|
let total = 0;
|
|
3141
3147
|
for (const root of compositions.keys()) {
|
|
@@ -3157,7 +3163,7 @@ function compositionExpansion(compositions, sources) {
|
|
|
3157
3163
|
for (const target of drawn) {
|
|
3158
3164
|
const inner = target === undefined ? { depth: 0, nodes: 1 } : walked.get(target);
|
|
3159
3165
|
depth = Math.max(depth, inner.depth + 1);
|
|
3160
|
-
//
|
|
3166
|
+
// Clamp so repeated doubling cannot reach Infinity.
|
|
3161
3167
|
nodes = Math.min(nodes + inner.nodes, MAX_INLINED_NODES + 1);
|
|
3162
3168
|
}
|
|
3163
3169
|
walked.set(id, { depth, nodes });
|
|
@@ -3177,10 +3183,6 @@ function compositionExpansion(compositions, sources) {
|
|
|
3177
3183
|
nodes: new Map([...walked].map(([id, { nodes }]) => [id, nodes])),
|
|
3178
3184
|
};
|
|
3179
3185
|
}
|
|
3180
|
-
/**
|
|
3181
|
-
* The clips on `track` drawing compositions, each at its start and its end, for {@link
|
|
3182
|
-
* frameNodesOver}.
|
|
3183
|
-
*/
|
|
3184
3186
|
function frameEdges(track, sources, inlined) {
|
|
3185
3187
|
const nodes = (id) => typeof id === "string" ? (inlined.get(id) ?? 0) : 0;
|
|
3186
3188
|
const edges = [];
|
|
@@ -3201,17 +3203,11 @@ function frameEdges(track, sources, inlined) {
|
|
|
3201
3203
|
}
|
|
3202
3204
|
return edges;
|
|
3203
3205
|
}
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
* draw more than {@link MAX_FRAME_INLINED_NODES} composition nodes together, each clip counting the
|
|
3207
|
-
* nodes its composition and its composition source draw once inlined. Reports the first clip, in
|
|
3208
|
-
* document order, starting at the first instant over the bound, with the count of all the clips
|
|
3209
|
-
* there. `tracks` are the {@link frameEdges} of each track, in document order.
|
|
3210
|
-
*/
|
|
3206
|
+
// Mirrors the model's per-frame inlined node bound, reporting the first clip at the first instant
|
|
3207
|
+
// over it.
|
|
3211
3208
|
function frameNodesOver(tracks) {
|
|
3212
3209
|
const edges = tracks.flat();
|
|
3213
|
-
//
|
|
3214
|
-
// document order: the sort is stable.
|
|
3210
|
+
// Ends sort before starts at one instant (half-open ranges); stable sort keeps document order.
|
|
3215
3211
|
edges.sort((a, b) => a.time - b.time || Number(a.starts) - Number(b.starts));
|
|
3216
3212
|
let drawn = 0;
|
|
3217
3213
|
for (let at = 0; at < edges.length;) {
|
|
@@ -3228,9 +3224,6 @@ function frameNodesOver(tracks) {
|
|
|
3228
3224
|
}
|
|
3229
3225
|
return undefined;
|
|
3230
3226
|
}
|
|
3231
|
-
/**
|
|
3232
|
-
* A composition's node identities, settings, and connections, as the model checks them.
|
|
3233
|
-
*/
|
|
3234
3227
|
function compositionProblems(composition, sources, effectResources, compositions, controlNamesOf, canvas) {
|
|
3235
3228
|
if (!isRecord(composition))
|
|
3236
3229
|
return ["each composition must be an object"];
|
|
@@ -3392,7 +3385,6 @@ function compositionProblems(composition, sources, effectResources, compositions
|
|
|
3392
3385
|
if (output != null && !byId.has(text(output))) {
|
|
3393
3386
|
problems.push(`composition ${id} outputs unknown node ${text(output)}`);
|
|
3394
3387
|
}
|
|
3395
|
-
// Depth-first: a node reached again while still on the walk's path closes a cycle.
|
|
3396
3388
|
const state = new Map();
|
|
3397
3389
|
const visit = (nodeId) => {
|
|
3398
3390
|
const mark = state.get(nodeId);
|
|
@@ -3419,7 +3411,6 @@ function compositionProblems(composition, sources, effectResources, compositions
|
|
|
3419
3411
|
}
|
|
3420
3412
|
return problems;
|
|
3421
3413
|
}
|
|
3422
|
-
/** At most {@link MAX_CLIP_MASKS} masks, and on visual clips only. */
|
|
3423
3414
|
function validMaskCount(masks, trackKind) {
|
|
3424
3415
|
if (masks === undefined)
|
|
3425
3416
|
return true;
|
|
@@ -3429,10 +3420,7 @@ function validMaskCount(masks, trackKind) {
|
|
|
3429
3420
|
return true;
|
|
3430
3421
|
return trackKind === "video" && masks.length <= MAX_CLIP_MASKS;
|
|
3431
3422
|
}
|
|
3432
|
-
/**
|
|
3433
|
-
* Mirrors `validate_masks`: the first problem among the masks in order, each outline checked as
|
|
3434
|
-
* geometry is and each feather non-negative.
|
|
3435
|
-
*/
|
|
3423
|
+
/** Mirrors `validate_masks`. */
|
|
3436
3424
|
function masksIssue(masks) {
|
|
3437
3425
|
if (!Array.isArray(masks))
|
|
3438
3426
|
return undefined;
|
|
@@ -3450,10 +3438,7 @@ function masksIssue(masks) {
|
|
|
3450
3438
|
}
|
|
3451
3439
|
return undefined;
|
|
3452
3440
|
}
|
|
3453
|
-
|
|
3454
|
-
* A matte names a visual clip other than its own, which has no matte of its own and is in no
|
|
3455
|
-
* transition.
|
|
3456
|
-
*/
|
|
3441
|
+
// A matte names another visual clip that has no matte and is in no transition.
|
|
3457
3442
|
function matteProblems(tracks) {
|
|
3458
3443
|
const visual = new Map();
|
|
3459
3444
|
const inTransition = new Set();
|
|
@@ -3488,15 +3473,9 @@ function matteProblems(tracks) {
|
|
|
3488
3473
|
}
|
|
3489
3474
|
return problems;
|
|
3490
3475
|
}
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
* Each track names at most one sidechain, so following them from any track ends, or enters the one
|
|
3495
|
-
* cycle its path reaches; a track is on a cycle exactly when its own walk returns to it. One walk
|
|
3496
|
-
* per track, each step visited once over all of them, as the engine's walk finds the same tracks
|
|
3497
|
-
* within a document's track limit. A repeated track id resolves to its first track, as the engine's
|
|
3498
|
-
* lookup does.
|
|
3499
|
-
*/
|
|
3476
|
+
// Tracks whose ducking sidechain leads back to themselves. Each track names at most one sidechain,
|
|
3477
|
+
// so each step is visited once over all walks. Repeated ids resolve to the first track, as in the
|
|
3478
|
+
// engine.
|
|
3500
3479
|
function duckingCycles(tracks) {
|
|
3501
3480
|
const sidechains = new Map();
|
|
3502
3481
|
for (const track of tracks) {
|
|
@@ -3507,7 +3486,7 @@ function duckingCycles(tracks) {
|
|
|
3507
3486
|
sidechains.set(text(track.id), isRecord(ducking) ? text(ducking.sidechain_track) : undefined);
|
|
3508
3487
|
}
|
|
3509
3488
|
const cyclic = new Set();
|
|
3510
|
-
//
|
|
3489
|
+
// A walk that meets its own mark has closed a cycle.
|
|
3511
3490
|
const walkOf = new Map();
|
|
3512
3491
|
let walk = 0;
|
|
3513
3492
|
for (const start of sidechains.keys()) {
|
|
@@ -3530,16 +3509,11 @@ function duckingCycles(tracks) {
|
|
|
3530
3509
|
return cyclic;
|
|
3531
3510
|
}
|
|
3532
3511
|
/**
|
|
3533
|
-
* A valid project's non-fatal diagnostics
|
|
3534
|
-
*
|
|
3535
|
-
*
|
|
3536
|
-
* clips, transitions, and cues.
|
|
3537
|
-
*
|
|
3538
|
-
* Diagnostics never block a load or an export; they flag what is probably a
|
|
3539
|
-
* mistake in a project the engine accepts.
|
|
3512
|
+
* A valid project's non-fatal diagnostics from the engine's `Project::lint`, in a fixed order:
|
|
3513
|
+
* unused sources, shapes generators, HDR sources, each track's clips, transitions and cues,
|
|
3514
|
+
* composition nodes, then generated sources' trees. Diagnostics never block a load or export.
|
|
3540
3515
|
*
|
|
3541
|
-
* @throws
|
|
3542
|
-
* `loadProject`.
|
|
3516
|
+
* @throws The binding's error when the project does not load, as for `loadProject`.
|
|
3543
3517
|
*/
|
|
3544
3518
|
export function lintProject(binding, project) {
|
|
3545
3519
|
return JSON.parse(binding.lintProject(JSON.stringify(project)));
|