alpha2 0.5.2 → 0.6.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 +71 -5
- package/THIRD_PARTY_NOTICES.md +191 -1
- package/dist/apply-edit.d.ts +124 -0
- package/dist/apply-edit.js +15 -0
- package/dist/assets.d.ts +12 -0
- package/dist/audio-layout.js +6 -3
- package/dist/audio-worklet-processor.js +27 -33
- package/dist/audio.d.ts +5 -4
- package/dist/audio.js +8 -6
- package/dist/compose.d.ts +105 -0
- package/dist/compose.js +63 -0
- package/dist/decoder-fallback.d.ts +3 -2
- package/dist/decoder-fallback.js +11 -3
- package/dist/decoder-stall.d.ts +15 -0
- package/dist/decoder-stall.js +52 -0
- package/dist/edit-data.d.ts +24 -0
- package/dist/edit-data.js +224 -0
- package/dist/edit-keys.d.ts +16 -0
- package/dist/edit-keys.js +233 -0
- package/dist/edit.d.ts +41 -8
- package/dist/edit.js +123 -30
- package/dist/export-failure.d.ts +10 -2
- package/dist/export-failure.js +55 -4
- package/dist/export-retry.d.ts +6 -1
- package/dist/export-retry.js +12 -1
- package/dist/exporter.d.ts +11 -7
- package/dist/exporter.js +10 -9
- package/dist/extensions.d.ts +86 -28
- package/dist/extensions.js +204 -61
- package/dist/extract.d.ts +65 -0
- package/dist/extract.js +291 -0
- package/dist/extractor.d.ts +151 -0
- package/dist/extractor.js +141 -0
- package/dist/float32.d.ts +2 -0
- package/dist/float32.js +10 -0
- package/dist/frame-intake.d.ts +5 -0
- package/dist/frame-intake.js +10 -3
- package/dist/generated/builtin-effects.d.ts +3 -0
- package/dist/generated/builtin-effects.js +1804 -0
- package/dist/generated/project-schema.d.ts +696 -41
- package/dist/generated/project-schema.js +67 -0
- package/dist/generated/project-shape.js +986 -383
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json-text.js +14 -2
- package/dist/layout-values.js +7 -1
- package/dist/layout.d.ts +12 -4
- package/dist/media.d.ts +44 -11
- package/dist/media.js +256 -67
- package/dist/mediabunny.d.ts +32 -12
- package/dist/mediabunny.js +276 -90
- package/dist/player.d.ts +9 -3
- package/dist/player.js +114 -18
- package/dist/plugins.d.ts +62 -0
- package/dist/plugins.js +506 -0
- package/dist/project-data.d.ts +56 -0
- package/dist/project-data.js +765 -0
- package/dist/project.d.ts +36 -1
- package/dist/project.js +515 -42
- package/dist/robustness.d.ts +6 -33
- package/dist/robustness.js +2 -63
- package/dist/sha256.d.ts +3 -2
- package/dist/sha256.js +14 -6
- package/dist/wasm-module.d.ts +37 -0
- package/dist/wasm-module.js +47 -0
- package/dist/worker-error.d.ts +3 -2
- package/dist/worker-error.js +3 -1
- package/dist/worker.d.ts +13 -3
- package/dist/worker.js +36 -9
- package/package.json +36 -2
- package/wasm/alpha2_compose.d.ts +92 -0
- package/wasm/alpha2_compose.js +445 -0
- package/wasm/alpha2_compose_bg.wasm +0 -0
- package/wasm/alpha2_compose_bg.wasm.d.ts +17 -0
- package/wasm/alpha2_extensions.d.ts +4 -4
- package/wasm/alpha2_extensions.js +16 -4
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf.d.ts +227 -0
- package/wasm/alpha2_extensions_pdf.js +841 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm.d.ts +38 -0
- package/wasm/alpha2_wasm.d.ts +151 -18
- package/wasm/alpha2_wasm.js +403 -59
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +21 -6
- package/wasm/rust-crate-licenses.md +493 -54
- package/wasm/snippets/alpha2-wasm-1b02e9f302d283ba/inline3.js +7 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline1.js → alpha2-wasm-1b02e9f302d283ba/inline0.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline2.js → alpha2-wasm-1b02e9f302d283ba/inline1.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline3.js → alpha2-wasm-1b02e9f302d283ba/inline2.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline0.js → alpha2-wasm-1b02e9f302d283ba/inline4.js} +0 -0
package/dist/project.js
CHANGED
|
@@ -7,8 +7,12 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Timeline values are integer ticks at {@link TICKS_PER_SECOND}. Ranges are half-open.
|
|
9
9
|
*/
|
|
10
|
+
import { BUILTIN_EFFECT_RULES } from "./generated/builtin-effects.js";
|
|
11
|
+
import { dataProblems } from "./project-data.js";
|
|
12
|
+
import { shortestFloat32 } from "./float32.js";
|
|
13
|
+
export { dataReferences, describeDataReference, } from "./project-data.js";
|
|
10
14
|
import { parseHex, parseInsets, parseLength, parseOffset, parsePlacement, parseSize, parseTrackList, } from "./layout-values.js";
|
|
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";
|
|
15
|
+
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, MAX_LOOP_PASSES, MAX_ANIMATOR_OFFSET, MAX_ASPECT_RATIO, MAX_FLEX_FACTOR, MAX_LAYOUT_FRACTION, MAX_LAYOUT_PERCENT, MAX_LAYOUT_PX, MAX_TEXT_POSITION, MIN_ASPECT_RATIO, 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, MAX_SELECTED_CHANNELS, MAX_AUDIO_CHANNELS, MAX_LATEX_BYTES, MAX_LATEX_FONT_SIZE, MAX_PDF_PAGES, REVERB_DELAY_MS, TICKS_PER_SECOND, } from "./generated/project-schema.js";
|
|
12
16
|
import { PROJECT_SHAPE } from "./generated/project-shape.js";
|
|
13
17
|
import { MAX_JSON_DEPTH, hasLoneSurrogate, readJsonText, } from "./json-text.js";
|
|
14
18
|
export * from "./generated/project-schema.js";
|
|
@@ -129,6 +133,8 @@ function invariantProblems(value) {
|
|
|
129
133
|
}
|
|
130
134
|
for (const problem of matteProblems(tracks))
|
|
131
135
|
problems.push(problem);
|
|
136
|
+
for (const problem of projectDataProblems(project))
|
|
137
|
+
problems.push(problem);
|
|
132
138
|
if (catalog.inlined !== undefined) {
|
|
133
139
|
const frame = frameNodesOver(tracks.map((track) => frameEdges(track, catalog.sources, catalog.inlined)));
|
|
134
140
|
if (frame !== undefined)
|
|
@@ -140,6 +146,9 @@ function invariantProblems(value) {
|
|
|
140
146
|
problems.push(problem);
|
|
141
147
|
return problems;
|
|
142
148
|
}
|
|
149
|
+
function projectDataProblems(project) {
|
|
150
|
+
return dataProblems(project, (id, name) => builtinParamRule(id, name)?.type, validFingerprint, sealed);
|
|
151
|
+
}
|
|
143
152
|
function headerProblems(project) {
|
|
144
153
|
const problems = [];
|
|
145
154
|
if (text(project.id).length === 0)
|
|
@@ -253,6 +262,14 @@ function catalogOf(sourceList, resourceList, compositionList, canvas) {
|
|
|
253
262
|
else if (source.generator != null) {
|
|
254
263
|
problems.push(`source ${sourceId} has an invalid generator`);
|
|
255
264
|
}
|
|
265
|
+
else if (isRecord(source.provider) &&
|
|
266
|
+
typeof source.provider.format === "string" &&
|
|
267
|
+
!providerReadsFile({ format: source.provider.format })) {
|
|
268
|
+
// Mirrors `validate_fileless_source`.
|
|
269
|
+
if (text(source.locator).length > 0 || source.fingerprint != null) {
|
|
270
|
+
problems.push(`source ${sourceId} has an invalid provider`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
256
273
|
else if (text(source.locator).length === 0) {
|
|
257
274
|
problems.push(`source ${sourceId} has an empty locator`);
|
|
258
275
|
}
|
|
@@ -289,8 +306,17 @@ function catalogOf(sourceList, resourceList, compositionList, canvas) {
|
|
|
289
306
|
}
|
|
290
307
|
return names;
|
|
291
308
|
};
|
|
309
|
+
const builtinControls = new Map();
|
|
310
|
+
const builtinControlsOf = (target) => {
|
|
311
|
+
let found = builtinControls.get(target);
|
|
312
|
+
if (found === undefined) {
|
|
313
|
+
found = builtinControlTargets(target);
|
|
314
|
+
builtinControls.set(target, found);
|
|
315
|
+
}
|
|
316
|
+
return found;
|
|
317
|
+
};
|
|
292
318
|
for (const composition of compositionList) {
|
|
293
|
-
const found = compositionProblems(composition, sources, effectResources, compositionsById, controlNamesOf, canvas);
|
|
319
|
+
const found = compositionProblems(composition, sources, effectResources, compositionsById, controlNamesOf, builtinControlsOf, canvas);
|
|
294
320
|
for (const problem of found)
|
|
295
321
|
problems.push(problem);
|
|
296
322
|
}
|
|
@@ -395,6 +421,10 @@ function clipProblems(clip, trackKind, catalog) {
|
|
|
395
421
|
if (!freezesInside(clip.time_map, clip.source_range)) {
|
|
396
422
|
problems.push(`clip ${clipId} freezes outside its source range`);
|
|
397
423
|
}
|
|
424
|
+
const passes = loopPasses(clip);
|
|
425
|
+
if (passes > BigInt(MAX_LOOP_PASSES)) {
|
|
426
|
+
problems.push(`clip ${clipId} loops ${passes} times; the maximum is ${MAX_LOOP_PASSES}`);
|
|
427
|
+
}
|
|
398
428
|
const sourceId = text(clip.source_id);
|
|
399
429
|
const source = catalog.sources.get(sourceId);
|
|
400
430
|
if (source === undefined || !isRecord(source)) {
|
|
@@ -601,6 +631,7 @@ function invariantsHold(value) {
|
|
|
601
631
|
}
|
|
602
632
|
return (clipIdsUnique(summaries) &&
|
|
603
633
|
mattesHold(summaries) &&
|
|
634
|
+
projectDataProblems(project).length === 0 &&
|
|
604
635
|
frameNodesOver(summaries.map((summary) => summary.frames)) === undefined &&
|
|
605
636
|
audioEffectProblems(project.audio, summaries.map((summary) => summary.audio)).length === 0 &&
|
|
606
637
|
duckingProblems(tracks, trackIds).length === 0);
|
|
@@ -730,7 +761,7 @@ export function validateProjectJson(json) {
|
|
|
730
761
|
}
|
|
731
762
|
const read = readJsonText(json);
|
|
732
763
|
if (read === undefined) {
|
|
733
|
-
return [
|
|
764
|
+
return [TOO_DEEP];
|
|
734
765
|
}
|
|
735
766
|
return projectProblems(read.value, read.spelling);
|
|
736
767
|
}
|
|
@@ -767,13 +798,34 @@ function shapeProblems(value, spelling, reuse) {
|
|
|
767
798
|
reusingShapes = reuse;
|
|
768
799
|
try {
|
|
769
800
|
const read = checkShape(shapeRoot, value, "project", problems, spelling);
|
|
770
|
-
return { problems, read };
|
|
801
|
+
return { problems: tooDeep ? [TOO_DEEP] : problems, read };
|
|
771
802
|
}
|
|
772
803
|
finally {
|
|
773
804
|
reusingShapes = false;
|
|
805
|
+
shapeDepth = 0;
|
|
806
|
+
tooDeep = false;
|
|
774
807
|
}
|
|
775
808
|
}
|
|
776
809
|
let reusingShapes = false;
|
|
810
|
+
// Arrays and objects the shape walk is inside; past `MAX_JSON_DEPTH` it stops descending.
|
|
811
|
+
let shapeDepth = 0;
|
|
812
|
+
let tooDeep = false;
|
|
813
|
+
const TOO_DEEP = `project JSON nests deeper than ${MAX_JSON_DEPTH} levels`;
|
|
814
|
+
/** Runs `walk` one container deeper, or reports the depth problem without running it. */
|
|
815
|
+
function nested(value, problems, walk) {
|
|
816
|
+
if (shapeDepth >= MAX_JSON_DEPTH) {
|
|
817
|
+
tooDeep = true;
|
|
818
|
+
problems.push(TOO_DEEP);
|
|
819
|
+
return value;
|
|
820
|
+
}
|
|
821
|
+
shapeDepth += 1;
|
|
822
|
+
try {
|
|
823
|
+
return walk();
|
|
824
|
+
}
|
|
825
|
+
finally {
|
|
826
|
+
shapeDepth -= 1;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
777
829
|
// Cross-field rules the schema cannot state but the engine's parser enforces.
|
|
778
830
|
const FRAME_RATE_SHAPE = shapeRoot.$defs
|
|
779
831
|
.FrameRate;
|
|
@@ -926,16 +978,6 @@ const SHAPE_READERS = new Map([
|
|
|
926
978
|
},
|
|
927
979
|
],
|
|
928
980
|
]);
|
|
929
|
-
// The shortest decimal that reads back as the same 32-bit float, as the engine writes it.
|
|
930
|
-
function shortestFloat32(value) {
|
|
931
|
-
const target = Math.fround(value);
|
|
932
|
-
for (let digits = 1; digits < 9; digits++) {
|
|
933
|
-
const short = Number(target.toPrecision(digits));
|
|
934
|
-
if (Math.fround(short) === target)
|
|
935
|
-
return short;
|
|
936
|
-
}
|
|
937
|
-
return Number(target.toPrecision(9));
|
|
938
|
-
}
|
|
939
981
|
/** The whole text of a caption cue or text generator, with runs joined. */
|
|
940
982
|
export function textOf(content) {
|
|
941
983
|
return typeof content === "string"
|
|
@@ -1167,6 +1209,129 @@ function canonicalWalk(node, value) {
|
|
|
1167
1209
|
}
|
|
1168
1210
|
return read === undefined ? value : { ...value, ...read };
|
|
1169
1211
|
}
|
|
1212
|
+
/**
|
|
1213
|
+
* `next` with every part that equals the matching part of `previous` replaced by that part, so
|
|
1214
|
+
* a project an engine edit wrote keeps the objects of the project it was computed from wherever
|
|
1215
|
+
* the edit changed nothing. A field one side omits counts as its schema default, as the engine
|
|
1216
|
+
* reads it; arrays match items by string `id` when they have one, else by position. Both projects
|
|
1217
|
+
* must be valid. The result reads as `next` does, though parts taken from `previous` keep its
|
|
1218
|
+
* spelling of defaults.
|
|
1219
|
+
*/
|
|
1220
|
+
export function shareUnchangedParts(previous, next) {
|
|
1221
|
+
return shareAt(shapeRoot, previous, next);
|
|
1222
|
+
}
|
|
1223
|
+
const idOfItem = (item) => isRecord(item) ? item.id : undefined;
|
|
1224
|
+
/** Whether `value` can be an instance of variant `node`, judged by its constant fields. */
|
|
1225
|
+
function fitsVariant(node, value) {
|
|
1226
|
+
const schema = resolveShape(node);
|
|
1227
|
+
if ("const" in schema)
|
|
1228
|
+
return value === schema.const;
|
|
1229
|
+
if (schema.type === "null")
|
|
1230
|
+
return value === null;
|
|
1231
|
+
if (schema.type === "array")
|
|
1232
|
+
return Array.isArray(value);
|
|
1233
|
+
if (schema.type === "object" || schema.properties !== undefined) {
|
|
1234
|
+
if (!isRecord(value))
|
|
1235
|
+
return false;
|
|
1236
|
+
const properties = (schema.properties ?? {});
|
|
1237
|
+
return Object.entries(properties).every(([key, field]) => {
|
|
1238
|
+
const constant = resolveShape(field);
|
|
1239
|
+
return !("const" in constant) || value[key] === constant.const;
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
if (schema.type === "string")
|
|
1243
|
+
return typeof value === "string";
|
|
1244
|
+
if (schema.type === "number" || schema.type === "integer")
|
|
1245
|
+
return typeof value === "number";
|
|
1246
|
+
if (schema.type === "boolean")
|
|
1247
|
+
return typeof value === "boolean";
|
|
1248
|
+
return true;
|
|
1249
|
+
}
|
|
1250
|
+
/** Whether `value` is the default of `field`, or `field` has none and `value` is absent. */
|
|
1251
|
+
function isFieldDefault(field, value) {
|
|
1252
|
+
if (typeof field !== "object" || field.default === undefined)
|
|
1253
|
+
return value === undefined;
|
|
1254
|
+
return (value === undefined ||
|
|
1255
|
+
shareAt(field, field.default, value) === field.default);
|
|
1256
|
+
}
|
|
1257
|
+
function shareAt(node, previous, next) {
|
|
1258
|
+
if (previous === next)
|
|
1259
|
+
return previous;
|
|
1260
|
+
if (typeof node !== "object")
|
|
1261
|
+
return next;
|
|
1262
|
+
const schema = resolveShape(node);
|
|
1263
|
+
const variants = (schema.oneOf ?? schema.anyOf);
|
|
1264
|
+
if (variants !== undefined) {
|
|
1265
|
+
const variant = variants.find((candidate) => fitsVariant(candidate, next));
|
|
1266
|
+
return variant === undefined || !fitsVariant(variant, previous)
|
|
1267
|
+
? next
|
|
1268
|
+
: shareAt(variant, previous, next);
|
|
1269
|
+
}
|
|
1270
|
+
if (typeof next !== "object" ||
|
|
1271
|
+
next === null ||
|
|
1272
|
+
typeof previous !== "object" ||
|
|
1273
|
+
previous === null)
|
|
1274
|
+
return next;
|
|
1275
|
+
if (Array.isArray(next)) {
|
|
1276
|
+
if (!Array.isArray(previous))
|
|
1277
|
+
return next;
|
|
1278
|
+
let same = next.length === previous.length;
|
|
1279
|
+
let nested = false;
|
|
1280
|
+
for (let index = 0; same && index < next.length; index++) {
|
|
1281
|
+
const item = next[index];
|
|
1282
|
+
if (typeof item === "object" && item !== null)
|
|
1283
|
+
nested = true;
|
|
1284
|
+
else if (item !== previous[index])
|
|
1285
|
+
same = false;
|
|
1286
|
+
}
|
|
1287
|
+
if (same && !nested)
|
|
1288
|
+
return previous;
|
|
1289
|
+
const prefix = schema.prefixItems;
|
|
1290
|
+
const rest = (schema.items ?? true);
|
|
1291
|
+
let byId;
|
|
1292
|
+
const items = next.map((item, index) => {
|
|
1293
|
+
const id = idOfItem(item);
|
|
1294
|
+
let counterpart = previous[index];
|
|
1295
|
+
if (typeof id === "string" && idOfItem(counterpart) !== id) {
|
|
1296
|
+
byId ??= new Map(previous.map((other) => [idOfItem(other), other]));
|
|
1297
|
+
counterpart = byId.get(id);
|
|
1298
|
+
}
|
|
1299
|
+
const field = prefix !== undefined && index < prefix.length ? prefix[index] : rest;
|
|
1300
|
+
const shared = counterpart === undefined ? item : shareAt(field, counterpart, item);
|
|
1301
|
+
if (shared !== previous[index])
|
|
1302
|
+
same = false;
|
|
1303
|
+
return shared;
|
|
1304
|
+
});
|
|
1305
|
+
return same ? previous : items;
|
|
1306
|
+
}
|
|
1307
|
+
if (Array.isArray(previous) || !isRecord(next) || !isRecord(previous))
|
|
1308
|
+
return next;
|
|
1309
|
+
const properties = (schema.properties ?? {});
|
|
1310
|
+
const extra = (schema.additionalProperties ?? true);
|
|
1311
|
+
const fieldOf = (key) => Object.hasOwn(properties, key) ? properties[key] : extra;
|
|
1312
|
+
let same = true;
|
|
1313
|
+
const read = {};
|
|
1314
|
+
for (const key of Object.keys(next)) {
|
|
1315
|
+
const value = next[key];
|
|
1316
|
+
if (value === undefined)
|
|
1317
|
+
continue;
|
|
1318
|
+
const before = previous[key];
|
|
1319
|
+
if (before === undefined) {
|
|
1320
|
+
if (!isFieldDefault(fieldOf(key), value))
|
|
1321
|
+
same = false;
|
|
1322
|
+
read[key] = value;
|
|
1323
|
+
continue;
|
|
1324
|
+
}
|
|
1325
|
+
const shared = shareAt(fieldOf(key), before, value);
|
|
1326
|
+
if (shared !== before)
|
|
1327
|
+
same = false;
|
|
1328
|
+
read[key] = shared;
|
|
1329
|
+
}
|
|
1330
|
+
for (const key of Object.keys(previous))
|
|
1331
|
+
if (next[key] === undefined && !isFieldDefault(fieldOf(key), previous[key]))
|
|
1332
|
+
same = false;
|
|
1333
|
+
return same ? previous : read;
|
|
1334
|
+
}
|
|
1170
1335
|
function walkShape(node, value, path, problems, spelling, texts) {
|
|
1171
1336
|
const schema = resolveShape(node);
|
|
1172
1337
|
const reader = SHAPE_READERS.get(schema);
|
|
@@ -1219,11 +1384,11 @@ function walkShape(node, value, path, problems, spelling, texts) {
|
|
|
1219
1384
|
}
|
|
1220
1385
|
}
|
|
1221
1386
|
else if (Array.isArray(value)) {
|
|
1222
|
-
return checkArrayShape(schema, value, path, problems, spelling);
|
|
1387
|
+
return nested(value, problems, () => checkArrayShape(schema, value, path, problems, spelling));
|
|
1223
1388
|
}
|
|
1224
1389
|
else if (isRecord(value)) {
|
|
1225
1390
|
const before = problems.length;
|
|
1226
|
-
const read = checkObjectShape(schema, value, path, problems, spelling);
|
|
1391
|
+
const read = nested(value, problems, () => checkObjectShape(schema, value, path, problems, spelling));
|
|
1227
1392
|
if (schema === FRAME_RATE_SHAPE &&
|
|
1228
1393
|
problems.length === before &&
|
|
1229
1394
|
!validFrameRate(value)) {
|
|
@@ -1369,20 +1534,84 @@ function checkArrayShape(schema, value, path, problems, spelling) {
|
|
|
1369
1534
|
problems.push(`${path} must have at most ${schema.maxItems} items`);
|
|
1370
1535
|
}
|
|
1371
1536
|
const prefix = (schema.prefixItems ?? []);
|
|
1537
|
+
const scalar = prefix.length === 0 && schema.items !== undefined
|
|
1538
|
+
? plainScalar(schema.items)
|
|
1539
|
+
: undefined;
|
|
1372
1540
|
let changed = false;
|
|
1373
|
-
|
|
1541
|
+
// By index rather than `map`, so a hole is read as `undefined` and fails its item shape.
|
|
1542
|
+
const read = [];
|
|
1543
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
1544
|
+
const item = value[index];
|
|
1545
|
+
// Valid numbers of a plain number schema need no path or generic walk.
|
|
1546
|
+
const quick = scalar?.(item, numbers?.get(index));
|
|
1547
|
+
if (quick !== undefined) {
|
|
1548
|
+
if (quick !== item)
|
|
1549
|
+
changed = true;
|
|
1550
|
+
read.push(quick);
|
|
1551
|
+
continue;
|
|
1552
|
+
}
|
|
1374
1553
|
const itemSchema = prefix[index] ?? schema.items;
|
|
1375
|
-
if (itemSchema === undefined)
|
|
1376
|
-
|
|
1554
|
+
if (itemSchema === undefined) {
|
|
1555
|
+
read.push(item);
|
|
1556
|
+
continue;
|
|
1557
|
+
}
|
|
1377
1558
|
const itemRead = checkShape(itemSchema, item, `${path}[${index}]`, problems, spelling, numbers?.get(index));
|
|
1378
1559
|
if (itemRead !== item)
|
|
1379
1560
|
changed = true;
|
|
1380
|
-
|
|
1381
|
-
}
|
|
1561
|
+
read.push(itemRead);
|
|
1562
|
+
}
|
|
1382
1563
|
return !changed && reusingShapes && sealed(value)
|
|
1383
1564
|
? value
|
|
1384
1565
|
: read;
|
|
1385
1566
|
}
|
|
1567
|
+
/**
|
|
1568
|
+
* For an item schema that is only a number, integer or null type, a reader that returns a valid
|
|
1569
|
+
* item as the generic walk reads it, and `undefined` for anything it leaves to that walk.
|
|
1570
|
+
*/
|
|
1571
|
+
function plainScalar(node) {
|
|
1572
|
+
const known = plainScalars.get(node);
|
|
1573
|
+
if (known !== undefined || plainScalars.has(node))
|
|
1574
|
+
return known ?? undefined;
|
|
1575
|
+
const schema = resolveShape(node);
|
|
1576
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
1577
|
+
const plain = !SHAPE_READERS.has(schema) &&
|
|
1578
|
+
schema.oneOf === undefined &&
|
|
1579
|
+
schema.anyOf === undefined &&
|
|
1580
|
+
!("const" in schema) &&
|
|
1581
|
+
schema.enum === undefined &&
|
|
1582
|
+
schema.minimum === undefined &&
|
|
1583
|
+
schema.maximum === undefined &&
|
|
1584
|
+
types.every((type) => type === "number" || type === "integer" || type === "null") &&
|
|
1585
|
+
!(types.includes("number") && types.includes("integer"));
|
|
1586
|
+
let reader;
|
|
1587
|
+
if (plain) {
|
|
1588
|
+
const nullable = types.includes("null");
|
|
1589
|
+
const float = schema.format === "float";
|
|
1590
|
+
const { min, max } = types.includes("integer")
|
|
1591
|
+
? integerBounds(schema)
|
|
1592
|
+
: { min: undefined, max: undefined };
|
|
1593
|
+
const low = min === undefined ? -Infinity : Number(min);
|
|
1594
|
+
const high = max === undefined ? Infinity : Number(max);
|
|
1595
|
+
reader = types.includes("integer")
|
|
1596
|
+
? (item, texts) => (nullable && item === null) ||
|
|
1597
|
+
(texts === undefined &&
|
|
1598
|
+
Number.isSafeInteger(item) &&
|
|
1599
|
+
item >= low &&
|
|
1600
|
+
item <= high)
|
|
1601
|
+
? item
|
|
1602
|
+
: undefined
|
|
1603
|
+
: (item) => nullable && item === null
|
|
1604
|
+
? item
|
|
1605
|
+
: typeof item === "number" && Number.isFinite(item)
|
|
1606
|
+
? float
|
|
1607
|
+
? Math.fround(item)
|
|
1608
|
+
: item
|
|
1609
|
+
: undefined;
|
|
1610
|
+
}
|
|
1611
|
+
plainScalars.set(node, reader);
|
|
1612
|
+
return reader;
|
|
1613
|
+
}
|
|
1614
|
+
const plainScalars = new Map();
|
|
1386
1615
|
function checkObjectShape(schema, value, path, problems, spelling) {
|
|
1387
1616
|
const properties = (schema.properties ?? {});
|
|
1388
1617
|
// A map (`additionalProperties`) keeps the last repeated key, as `JSON.parse` does.
|
|
@@ -1397,6 +1626,12 @@ function checkObjectShape(schema, value, path, problems, spelling) {
|
|
|
1397
1626
|
if (value[name] === undefined)
|
|
1398
1627
|
problems.push(`${path}.${name} is required`);
|
|
1399
1628
|
}
|
|
1629
|
+
if (typeof schema.maxProperties === "number") {
|
|
1630
|
+
const present = Object.values(value).filter((item) => item !== undefined);
|
|
1631
|
+
if (present.length > schema.maxProperties) {
|
|
1632
|
+
problems.push(`${path} must have at most ${schema.maxProperties} properties`);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1400
1635
|
const extra = schema.additionalProperties;
|
|
1401
1636
|
const read = {};
|
|
1402
1637
|
// Assigning `__proto__` would replace the copy's prototype instead of adding the key.
|
|
@@ -1549,8 +1784,21 @@ function audioProblems(clipId, audio) {
|
|
|
1549
1784
|
if (!validEffects(audio.effects)) {
|
|
1550
1785
|
problems.push(`clip ${clipId} has invalid audio effects`);
|
|
1551
1786
|
}
|
|
1787
|
+
if (audio.channels != null && !validChannelSelection(audio.channels)) {
|
|
1788
|
+
problems.push(`clip ${clipId} has invalid audio properties`);
|
|
1789
|
+
}
|
|
1552
1790
|
return problems;
|
|
1553
1791
|
}
|
|
1792
|
+
/** Mirrors `valid_channel_selection`: one or two distinct stream channels, each in range. */
|
|
1793
|
+
function validChannelSelection(channels) {
|
|
1794
|
+
return (Array.isArray(channels) &&
|
|
1795
|
+
channels.length >= 1 &&
|
|
1796
|
+
channels.length <= MAX_SELECTED_CHANNELS &&
|
|
1797
|
+
channels.every((channel) => Number.isInteger(channel) &&
|
|
1798
|
+
channel >= 0 &&
|
|
1799
|
+
channel < MAX_AUDIO_CHANNELS) &&
|
|
1800
|
+
channels[0] !== channels[1]);
|
|
1801
|
+
}
|
|
1554
1802
|
// Composition time is largest at the clip's last instant: `offset + floor((end - 1 - start) *
|
|
1555
1803
|
// num / den)`, which must fit a safe integer.
|
|
1556
1804
|
function compositionTimeHeld(clip, reference, scale) {
|
|
@@ -1588,6 +1836,20 @@ function freezesInside(timeMap, sourceRange) {
|
|
|
1588
1836
|
instant >= sourceRange.start &&
|
|
1589
1837
|
instant < sourceRange.end);
|
|
1590
1838
|
}
|
|
1839
|
+
/** Passes of a valid looping clip, rounded up, as `loop_passes`; else 0. */
|
|
1840
|
+
function loopPasses(clip) {
|
|
1841
|
+
const map = clip.time_map;
|
|
1842
|
+
if (!isRecord(map) || map.type !== "loop")
|
|
1843
|
+
return 0n;
|
|
1844
|
+
if (!validRange(clip.timeline_range) || !validRange(clip.source_range))
|
|
1845
|
+
return 0n;
|
|
1846
|
+
const length = (range) => {
|
|
1847
|
+
const { start, end } = range;
|
|
1848
|
+
return BigInt(end) - BigInt(start);
|
|
1849
|
+
};
|
|
1850
|
+
const source = length(clip.source_range);
|
|
1851
|
+
return (length(clip.timeline_range) + source - 1n) / source;
|
|
1852
|
+
}
|
|
1591
1853
|
function rangeStart(range) {
|
|
1592
1854
|
return isRecord(range) && finiteNumber(range.start) ? range.start : 0;
|
|
1593
1855
|
}
|
|
@@ -1596,6 +1858,9 @@ function animationValues(animation) {
|
|
|
1596
1858
|
return undefined;
|
|
1597
1859
|
if (animation.mode === "constant")
|
|
1598
1860
|
return [animation.value];
|
|
1861
|
+
// A binding holds no authored value; `dataProblems` checks it.
|
|
1862
|
+
if (animation.mode === "data")
|
|
1863
|
+
return [];
|
|
1599
1864
|
if (animation.mode !== "keyframes" || !Array.isArray(animation.keyframes)) {
|
|
1600
1865
|
return undefined;
|
|
1601
1866
|
}
|
|
@@ -1636,6 +1901,12 @@ function validRgb(value) {
|
|
|
1636
1901
|
return (isRecord(value) &&
|
|
1637
1902
|
[value.red, value.green, value.blue].every((component) => finiteNumber(component) && component >= 0 && component <= 1));
|
|
1638
1903
|
}
|
|
1904
|
+
/** Mirrors the `position` and `anchor` check of `TextStyle::is_valid`. */
|
|
1905
|
+
function textPosition(value) {
|
|
1906
|
+
return (validVec2(value) &&
|
|
1907
|
+
Math.abs(value.x) <= MAX_TEXT_POSITION &&
|
|
1908
|
+
Math.abs(value.y) <= MAX_TEXT_POSITION);
|
|
1909
|
+
}
|
|
1639
1910
|
function validVec2(value) {
|
|
1640
1911
|
return isRecord(value) && finiteNumber(value.x) && finiteNumber(value.y);
|
|
1641
1912
|
}
|
|
@@ -1684,6 +1955,8 @@ function validEffectValue(value) {
|
|
|
1684
1955
|
}
|
|
1685
1956
|
// All values share one type, and `enum` and `bool` keyframes must hold.
|
|
1686
1957
|
function validEffectParam(param) {
|
|
1958
|
+
if (isRecord(param) && param.mode === "data")
|
|
1959
|
+
return true;
|
|
1687
1960
|
const values = animationValues(param);
|
|
1688
1961
|
if (values === undefined || !values.every(validEffectValue))
|
|
1689
1962
|
return false;
|
|
@@ -1715,6 +1988,118 @@ function validClipEffect(effect) {
|
|
|
1715
1988
|
Object.entries(params ?? {}).every(([name, value]) => EFFECT_BINDING_NAME.test(name) && validEffectParam(value)) &&
|
|
1716
1989
|
Object.entries(resources ?? {}).every(([name, id]) => EFFECT_BINDING_NAME.test(name) && text(id).length > 0));
|
|
1717
1990
|
}
|
|
1991
|
+
/** Ids under this prefix must name a built-in. Mirrors `alpha2_model::BUILTIN_EFFECT_PREFIX`. */
|
|
1992
|
+
const BUILTIN_EFFECT_PREFIX = "alpha2.";
|
|
1993
|
+
function builtinRules(id) {
|
|
1994
|
+
return Object.hasOwn(BUILTIN_EFFECT_RULES, id)
|
|
1995
|
+
? BUILTIN_EFFECT_RULES[id]
|
|
1996
|
+
: undefined;
|
|
1997
|
+
}
|
|
1998
|
+
/** Each control of `composition` that sets a built-in parameter, by name; the first of a name. */
|
|
1999
|
+
function builtinControlTargets(composition) {
|
|
2000
|
+
const nodes = new Map();
|
|
2001
|
+
for (const node of Array.isArray(composition.nodes)
|
|
2002
|
+
? composition.nodes
|
|
2003
|
+
: []) {
|
|
2004
|
+
if (isRecord(node) && !nodes.has(text(node.id))) {
|
|
2005
|
+
nodes.set(text(node.id), node);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
const found = new Map();
|
|
2009
|
+
const seen = new Set();
|
|
2010
|
+
for (const control of Array.isArray(composition.controls)
|
|
2011
|
+
? composition.controls
|
|
2012
|
+
: []) {
|
|
2013
|
+
if (!isRecord(control) || seen.has(text(control.name)))
|
|
2014
|
+
continue;
|
|
2015
|
+
seen.add(text(control.name));
|
|
2016
|
+
const node = nodes.get(text(control.node));
|
|
2017
|
+
const effect = isRecord(node) && isRecord(node.op) ? node.op.effect : undefined;
|
|
2018
|
+
if (!isRecord(effect))
|
|
2019
|
+
continue;
|
|
2020
|
+
const param = text(control.param);
|
|
2021
|
+
const rule = builtinParamRule(text(effect.id), param);
|
|
2022
|
+
if (rule)
|
|
2023
|
+
found.set(text(control.name), { effect: text(effect.id), param, rule });
|
|
2024
|
+
}
|
|
2025
|
+
return found;
|
|
2026
|
+
}
|
|
2027
|
+
function builtinParamRule(id, name) {
|
|
2028
|
+
const rules = builtinRules(id);
|
|
2029
|
+
return rules && Object.hasOwn(rules.params, name)
|
|
2030
|
+
? rules.params[name]
|
|
2031
|
+
: undefined;
|
|
2032
|
+
}
|
|
2033
|
+
function acceptsBuiltinParam(param, animation) {
|
|
2034
|
+
if (isRecord(animation) && animation.mode === "data") {
|
|
2035
|
+
return param.type === "float" || param.type === "vec2";
|
|
2036
|
+
}
|
|
2037
|
+
const values = animationValues(animation) ?? [];
|
|
2038
|
+
const scalar = (value) => finiteNumber(value) &&
|
|
2039
|
+
(param.min === undefined || Math.fround(value) >= param.min) &&
|
|
2040
|
+
(param.max === undefined || Math.fround(value) <= param.max);
|
|
2041
|
+
return values.every((held) => {
|
|
2042
|
+
if (!isRecord(held) || held.type !== param.type)
|
|
2043
|
+
return false;
|
|
2044
|
+
const value = held.value;
|
|
2045
|
+
switch (param.type) {
|
|
2046
|
+
case "float":
|
|
2047
|
+
return scalar(value);
|
|
2048
|
+
case "vec2":
|
|
2049
|
+
case "vec4":
|
|
2050
|
+
return Array.isArray(value) && value.every(scalar);
|
|
2051
|
+
case "color":
|
|
2052
|
+
return (Array.isArray(value) &&
|
|
2053
|
+
value.every((part) => finiteNumber(part) &&
|
|
2054
|
+
Math.fround(part) >= 0 &&
|
|
2055
|
+
Math.fround(part) <= 1));
|
|
2056
|
+
case "enum":
|
|
2057
|
+
return (Number.isInteger(value) &&
|
|
2058
|
+
value >= 0 &&
|
|
2059
|
+
value < (param.choices ?? 0));
|
|
2060
|
+
default:
|
|
2061
|
+
return true;
|
|
2062
|
+
}
|
|
2063
|
+
});
|
|
2064
|
+
}
|
|
2065
|
+
/** How `effect`, used as `kind`, fails its built-in definition, worded as the model words it. */
|
|
2066
|
+
function builtinEffectProblem(effect, kind, inputs) {
|
|
2067
|
+
if (!isRecord(effect))
|
|
2068
|
+
return undefined;
|
|
2069
|
+
const id = text(effect.id);
|
|
2070
|
+
if (!id.startsWith(BUILTIN_EFFECT_PREFIX))
|
|
2071
|
+
return undefined;
|
|
2072
|
+
const rules = builtinRules(id);
|
|
2073
|
+
if (rules === undefined)
|
|
2074
|
+
return "is not a built-in";
|
|
2075
|
+
if (effect.version !== rules.version)
|
|
2076
|
+
return `needs version ${rules.version}`;
|
|
2077
|
+
if (rules.kind !== kind)
|
|
2078
|
+
return "is used as the wrong kind";
|
|
2079
|
+
const params = isRecord(effect.params) ? effect.params : {};
|
|
2080
|
+
// The model reads parameters in name order.
|
|
2081
|
+
for (const name of Object.keys(params).sort()) {
|
|
2082
|
+
const param = Object.hasOwn(rules.params, name)
|
|
2083
|
+
? rules.params[name]
|
|
2084
|
+
: undefined;
|
|
2085
|
+
if (param === undefined)
|
|
2086
|
+
return `has no parameter ${name}`;
|
|
2087
|
+
if (!acceptsBuiltinParam(param, params[name])) {
|
|
2088
|
+
return `has a parameter ${name} of the wrong type or out of range`;
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
const declared = (names, used) => {
|
|
2092
|
+
const keys = Object.keys(isRecord(used) ? used : {});
|
|
2093
|
+
return (keys.length === names.length && keys.every((key) => names.includes(key)));
|
|
2094
|
+
};
|
|
2095
|
+
if (!declared(rules.inputs, inputs)) {
|
|
2096
|
+
return "does not get exactly its declared inputs";
|
|
2097
|
+
}
|
|
2098
|
+
if (!declared(rules.resources, effect.resources)) {
|
|
2099
|
+
return "does not get exactly its declared resources";
|
|
2100
|
+
}
|
|
2101
|
+
return undefined;
|
|
2102
|
+
}
|
|
1718
2103
|
function validEffectInputs(inputs) {
|
|
1719
2104
|
if (inputs === undefined)
|
|
1720
2105
|
return true;
|
|
@@ -1960,6 +2345,10 @@ function transitionProblems(trackId, trackKind, clips, transitions) {
|
|
|
1960
2345
|
problems.push(`track ${trackId} has an invalid clip transition`);
|
|
1961
2346
|
continue;
|
|
1962
2347
|
}
|
|
2348
|
+
const builtin = builtinEffectProblem(transition.effect, "transition", undefined);
|
|
2349
|
+
if (builtin !== undefined) {
|
|
2350
|
+
problems.push(`effect ${text(transition.effect.id)} in the transition from ${text(transition.from_clip)} to ${text(transition.to_clip)} on track ${trackId} ${builtin}`);
|
|
2351
|
+
}
|
|
1963
2352
|
// At most one transition per pair of clips, in either direction.
|
|
1964
2353
|
const ends = [text(transition.from_clip), text(transition.to_clip)].sort();
|
|
1965
2354
|
const pair = JSON.stringify(ends);
|
|
@@ -1979,13 +2368,14 @@ function captionsProblem(track, clips, transitions, trackId) {
|
|
|
1979
2368
|
if (!isRecord(captions) || clips.length > 0 || transitions.length > 0) {
|
|
1980
2369
|
return invalid;
|
|
1981
2370
|
}
|
|
1982
|
-
const cues = captions.cues;
|
|
2371
|
+
const cues = captions.cues ?? [];
|
|
1983
2372
|
const styles = captions.styles ?? {};
|
|
1984
2373
|
const encoder = new TextEncoder();
|
|
1985
2374
|
const name = (value) => typeof value === "string" &&
|
|
1986
2375
|
value.length > 0 &&
|
|
1987
2376
|
encoder.encode(value).length <= MAX_CAPTION_NAME_BYTES;
|
|
1988
2377
|
if (!Array.isArray(cues) ||
|
|
2378
|
+
(captions.from_words != null && cues.length > 0) ||
|
|
1989
2379
|
!validTextStyle(captions.style ?? {}, MAX_CAPTION_FONT_SIZE) ||
|
|
1990
2380
|
!isRecord(styles) ||
|
|
1991
2381
|
Object.keys(styles).length > MAX_CAPTION_STYLES ||
|
|
@@ -2070,8 +2460,8 @@ function validTextStyle(style, maxFontSize) {
|
|
|
2070
2460
|
within(style.letter_spacing ?? 0, MIN_LETTER_SPACING, MAX_LETTER_SPACING) &&
|
|
2071
2461
|
validFontWeight(style.font_weight ?? 400) &&
|
|
2072
2462
|
within(style.max_width ?? 0.9, 0, 1, true) &&
|
|
2073
|
-
(style.position === undefined ||
|
|
2074
|
-
(style.anchor === undefined ||
|
|
2463
|
+
(style.position === undefined || textPosition(style.position)) &&
|
|
2464
|
+
(style.anchor === undefined || textPosition(style.anchor)) &&
|
|
2075
2465
|
(style.strokes === undefined || validTextStrokes(style.strokes)) &&
|
|
2076
2466
|
(style.shadows === undefined || validTextShadows(style.shadows)) &&
|
|
2077
2467
|
(style.animators === undefined ||
|
|
@@ -2170,7 +2560,7 @@ function validAnimatorProperties(properties) {
|
|
|
2170
2560
|
const values = animationValues(animation);
|
|
2171
2561
|
return values !== undefined && values.every(validRgba);
|
|
2172
2562
|
};
|
|
2173
|
-
return (vec2(properties.offset, -
|
|
2563
|
+
return (vec2(properties.offset, -MAX_ANIMATOR_OFFSET, MAX_ANIMATOR_OFFSET) &&
|
|
2174
2564
|
vec2(properties.scale, 0, MAX_ANIMATOR_SCALE) &&
|
|
2175
2565
|
validScalarAnimation(properties.rotation_degrees) &&
|
|
2176
2566
|
validScalarAnimation(properties.opacity, 0, 1) &&
|
|
@@ -2221,6 +2611,20 @@ function validFontWeight(weight) {
|
|
|
2221
2611
|
weight >= MIN_FONT_WEIGHT &&
|
|
2222
2612
|
weight <= MAX_FONT_WEIGHT);
|
|
2223
2613
|
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Whether a provider reads a file of the source's own. One that does not, such as LaTeX, holds its
|
|
2616
|
+
* content in its settings, so its source has an empty locator and no fingerprint. Mirrors
|
|
2617
|
+
* `ProviderSource::reads_file`.
|
|
2618
|
+
*/
|
|
2619
|
+
export function providerReadsFile(provider) {
|
|
2620
|
+
return provider.format !== "latex";
|
|
2621
|
+
}
|
|
2622
|
+
/** The kind of source a provider's media is. Mirrors `ProviderSource::kind`. */
|
|
2623
|
+
export function providerKind(provider) {
|
|
2624
|
+
return ["svg", "exr", "latex", "pdf"].includes(provider.format)
|
|
2625
|
+
? "image"
|
|
2626
|
+
: "video";
|
|
2627
|
+
}
|
|
2224
2628
|
/** Mirrors `ProviderSource::kind` and `ProviderSource::is_valid`. */
|
|
2225
2629
|
function validProvider(provider, kind) {
|
|
2226
2630
|
if (!isRecord(provider))
|
|
@@ -2229,6 +2633,27 @@ function validProvider(provider, kind) {
|
|
|
2229
2633
|
return kind === "image";
|
|
2230
2634
|
if (provider.format === "animated_image")
|
|
2231
2635
|
return kind === "video";
|
|
2636
|
+
if (provider.format === "latex") {
|
|
2637
|
+
const { latex, font_size: size, color } = provider;
|
|
2638
|
+
return (kind === "image" &&
|
|
2639
|
+
typeof latex === "string" &&
|
|
2640
|
+
latex.length > 0 &&
|
|
2641
|
+
new TextEncoder().encode(latex).length <= MAX_LATEX_BYTES &&
|
|
2642
|
+
finiteNumber(size) &&
|
|
2643
|
+
size > 0 &&
|
|
2644
|
+
size <= MAX_LATEX_FONT_SIZE &&
|
|
2645
|
+
(color == null || validRgba(color)) &&
|
|
2646
|
+
(provider.display == null || typeof provider.display === "boolean"));
|
|
2647
|
+
}
|
|
2648
|
+
if (provider.format === "pdf") {
|
|
2649
|
+
const { page, background } = provider;
|
|
2650
|
+
return (kind === "image" &&
|
|
2651
|
+
(page == null ||
|
|
2652
|
+
(Number.isInteger(page) &&
|
|
2653
|
+
page >= 1 &&
|
|
2654
|
+
page <= MAX_PDF_PAGES)) &&
|
|
2655
|
+
(background == null || validRgba(background)));
|
|
2656
|
+
}
|
|
2232
2657
|
if (provider.format === "lottie")
|
|
2233
2658
|
return (kind === "video" &&
|
|
2234
2659
|
(provider.animation == null ||
|
|
@@ -2528,19 +2953,26 @@ function layoutAnimatedIssue(animation, at, check) {
|
|
|
2528
2953
|
function layoutScalarIssue(animation, at, check) {
|
|
2529
2954
|
return layoutAnimatedIssue(animation, at, (value) => finiteNumber(value) && check(value));
|
|
2530
2955
|
}
|
|
2956
|
+
/** Mirrors `LayoutLength::in_bounds`: finite and within its unit's bound. */
|
|
2957
|
+
function lengthInBounds(length) {
|
|
2958
|
+
const bound = length.unit === "px"
|
|
2959
|
+
? MAX_LAYOUT_PX
|
|
2960
|
+
: length.unit === "percent"
|
|
2961
|
+
? MAX_LAYOUT_PERCENT
|
|
2962
|
+
: MAX_LAYOUT_FRACTION;
|
|
2963
|
+
return finiteNumber(length.value) && Math.abs(length.value) <= bound;
|
|
2964
|
+
}
|
|
2531
2965
|
function layoutSizeIssue(animation, at, check) {
|
|
2532
2966
|
return layoutAnimatedIssue(animation, at, (value) => {
|
|
2533
2967
|
const length = lengthOf(value);
|
|
2534
|
-
return (length !== undefined &&
|
|
2968
|
+
return (length !== undefined && lengthInBounds(length) && check(length.value));
|
|
2535
2969
|
});
|
|
2536
2970
|
}
|
|
2537
2971
|
function layoutInsetsIssue(animation, at, check) {
|
|
2538
2972
|
return layoutAnimatedIssue(animation, at, (value) => isRecord(value) &&
|
|
2539
2973
|
["top", "right", "bottom", "left"].every((side) => {
|
|
2540
2974
|
const length = lengthOf(value[side]);
|
|
2541
|
-
return (length !== undefined &&
|
|
2542
|
-
finiteNumber(length.value) &&
|
|
2543
|
-
check(length.value));
|
|
2975
|
+
return (length !== undefined && lengthInBounds(length) && check(length.value));
|
|
2544
2976
|
}));
|
|
2545
2977
|
}
|
|
2546
2978
|
// Checks values, then that keyframes are all percents or all lengths.
|
|
@@ -2589,12 +3021,14 @@ function layoutFieldsIssue(node, at) {
|
|
|
2589
3021
|
return issue;
|
|
2590
3022
|
}
|
|
2591
3023
|
if (present(node.aspect_ratio) &&
|
|
2592
|
-
!(finiteNumber(node.aspect_ratio) &&
|
|
3024
|
+
!(finiteNumber(node.aspect_ratio) &&
|
|
3025
|
+
node.aspect_ratio >= MIN_ASPECT_RATIO &&
|
|
3026
|
+
node.aspect_ratio <= MAX_ASPECT_RATIO)) {
|
|
2593
3027
|
return { at: field("aspect_ratio"), problem: LAYOUT_PROBLEM.outOfRange };
|
|
2594
3028
|
}
|
|
2595
3029
|
const item = layoutInsetsIssue(node.margin, field("margin"), anyValue) ??
|
|
2596
|
-
layoutScalarIssue(node.flex_grow, field("flex_grow"),
|
|
2597
|
-
layoutScalarIssue(node.flex_shrink, field("flex_shrink"),
|
|
3030
|
+
layoutScalarIssue(node.flex_grow, field("flex_grow"), flexFactor) ??
|
|
3031
|
+
layoutScalarIssue(node.flex_shrink, field("flex_shrink"), flexFactor) ??
|
|
2598
3032
|
layoutLengthIssue(node.flex_basis, field("flex_basis"), nonNegativeValue);
|
|
2599
3033
|
if (item)
|
|
2600
3034
|
return item;
|
|
@@ -2606,9 +3040,15 @@ function layoutFieldsIssue(node, at) {
|
|
|
2606
3040
|
}
|
|
2607
3041
|
}
|
|
2608
3042
|
return (layoutScalarIssue(node.opacity, field("opacity"), unitValue) ??
|
|
2609
|
-
layoutAnimatedIssue(node.translate, field("translate"), (value) =>
|
|
2610
|
-
|
|
2611
|
-
|
|
3043
|
+
layoutAnimatedIssue(node.translate, field("translate"), (value) => {
|
|
3044
|
+
if (!isRecord(value))
|
|
3045
|
+
return false;
|
|
3046
|
+
const [x, y] = [lengthOf(value.x), lengthOf(value.y)];
|
|
3047
|
+
return (x !== undefined &&
|
|
3048
|
+
y !== undefined &&
|
|
3049
|
+
lengthInBounds(x) &&
|
|
3050
|
+
lengthInBounds(y));
|
|
3051
|
+
}) ??
|
|
2612
3052
|
layoutAnimatedIssue(node.scale, field("scale"), validVec2) ??
|
|
2613
3053
|
layoutScalarIssue(node.rotation_degrees, field("rotation_degrees"), anyValue));
|
|
2614
3054
|
}
|
|
@@ -2637,7 +3077,7 @@ function fixedTrack(size) {
|
|
|
2637
3077
|
function trackProblem(tracks, explicit) {
|
|
2638
3078
|
const sizes = tracks.flatMap((component) => component.kind === "single" ? [component.size] : component.tracks);
|
|
2639
3079
|
const parts = sizes.map(trackParts);
|
|
2640
|
-
if (!parts.every(({ lengths, share }) => lengths.every((length) =>
|
|
3080
|
+
if (!parts.every(({ lengths, share }) => lengths.every((length) => lengthInBounds(length) && length.value >= 0) &&
|
|
2641
3081
|
(share === undefined || (Number.isFinite(share) && share > 0)))) {
|
|
2642
3082
|
return LAYOUT_PROBLEM.outOfRange;
|
|
2643
3083
|
}
|
|
@@ -2813,6 +3253,7 @@ function shapeItemIssue(item, at, depth, counted) {
|
|
|
2813
3253
|
}
|
|
2814
3254
|
const unitValue = (value) => value >= 0 && value <= 1;
|
|
2815
3255
|
const nonNegativeValue = (value) => value >= 0;
|
|
3256
|
+
const flexFactor = (value) => value >= 0 && value <= MAX_FLEX_FACTOR;
|
|
2816
3257
|
const anyValue = () => true;
|
|
2817
3258
|
// Keyframe problems first, then values. A missing value takes its (valid) default.
|
|
2818
3259
|
function shapeScalarIssue(animation, at, check) {
|
|
@@ -3203,8 +3644,8 @@ function frameEdges(track, sources, inlined) {
|
|
|
3203
3644
|
}
|
|
3204
3645
|
return edges;
|
|
3205
3646
|
}
|
|
3206
|
-
// Mirrors the model's per-frame inlined node bound
|
|
3207
|
-
//
|
|
3647
|
+
// Mirrors the model's per-frame inlined node bound and reports the first clip at the first
|
|
3648
|
+
// instant past it.
|
|
3208
3649
|
function frameNodesOver(tracks) {
|
|
3209
3650
|
const edges = tracks.flat();
|
|
3210
3651
|
// Ends sort before starts at one instant (half-open ranges); stable sort keeps document order.
|
|
@@ -3224,7 +3665,7 @@ function frameNodesOver(tracks) {
|
|
|
3224
3665
|
}
|
|
3225
3666
|
return undefined;
|
|
3226
3667
|
}
|
|
3227
|
-
function compositionProblems(composition, sources, effectResources, compositions, controlNamesOf, canvas) {
|
|
3668
|
+
function compositionProblems(composition, sources, effectResources, compositions, controlNamesOf, builtinControlsOf, canvas) {
|
|
3228
3669
|
if (!isRecord(composition))
|
|
3229
3670
|
return ["each composition must be an object"];
|
|
3230
3671
|
const id = text(composition.id);
|
|
@@ -3273,6 +3714,19 @@ function compositionProblems(composition, sources, effectResources, compositions
|
|
|
3273
3714
|
controls.length > MAX_COMPOSITION_CONTROLS ||
|
|
3274
3715
|
!controlsValid)
|
|
3275
3716
|
problems.push(`composition ${id} has invalid group inputs or controls`);
|
|
3717
|
+
else {
|
|
3718
|
+
for (const control of controls.filter(isRecord)) {
|
|
3719
|
+
const target = byId.get(text(control.node));
|
|
3720
|
+
const effect = isRecord(target) && isRecord(target.op) ? target.op.effect : undefined;
|
|
3721
|
+
const param = text(control.param);
|
|
3722
|
+
if (isRecord(effect) &&
|
|
3723
|
+
builtinRules(text(effect.id)) !== undefined &&
|
|
3724
|
+
builtinParamRule(text(effect.id), param) === undefined) {
|
|
3725
|
+
problems.push(`effect ${text(effect.id)} in composition ${id} node ${text(control.node)} has no parameter ${param}`);
|
|
3726
|
+
break;
|
|
3727
|
+
}
|
|
3728
|
+
}
|
|
3729
|
+
}
|
|
3276
3730
|
for (const node of nodes) {
|
|
3277
3731
|
if (!isRecord(node) || !isRecord(node.op))
|
|
3278
3732
|
continue;
|
|
@@ -3281,6 +3735,12 @@ function compositionProblems(composition, sources, effectResources, compositions
|
|
|
3281
3735
|
const invalid = () => {
|
|
3282
3736
|
problems.push(`node ${nodeId} of composition ${id} has an invalid setting`);
|
|
3283
3737
|
};
|
|
3738
|
+
const builtinProblem = (effect, kind, effectInputs) => {
|
|
3739
|
+
const problem = builtinEffectProblem(effect, kind, effectInputs);
|
|
3740
|
+
if (problem !== undefined && isRecord(effect)) {
|
|
3741
|
+
problems.push(`effect ${text(effect.id)} in composition ${id} node ${nodeId} ${problem}`);
|
|
3742
|
+
}
|
|
3743
|
+
};
|
|
3284
3744
|
const inputs = nodeInputs(op);
|
|
3285
3745
|
if (node.bypass === true &&
|
|
3286
3746
|
(["clip", "media", "generator", "group_input"].includes(text(op.type)) ||
|
|
@@ -3317,10 +3777,15 @@ function compositionProblems(composition, sources, effectResources, compositions
|
|
|
3317
3777
|
if (!validClipEffect(op.effect) || !validEffectInputs(op.inputs)) {
|
|
3318
3778
|
invalid();
|
|
3319
3779
|
}
|
|
3780
|
+
else {
|
|
3781
|
+
builtinProblem(op.effect, "effect", op.inputs);
|
|
3782
|
+
}
|
|
3320
3783
|
break;
|
|
3321
3784
|
case "transition":
|
|
3322
3785
|
if (!validClipEffect(op.effect) || !unit(op.progress))
|
|
3323
3786
|
invalid();
|
|
3787
|
+
else
|
|
3788
|
+
builtinProblem(op.effect, "transition", undefined);
|
|
3324
3789
|
break;
|
|
3325
3790
|
case "transform":
|
|
3326
3791
|
if (!validVisual(op.transform))
|
|
@@ -3356,8 +3821,17 @@ function compositionProblems(composition, sources, effectResources, compositions
|
|
|
3356
3821
|
if (!Array.isArray(op.inputs ?? []) ||
|
|
3357
3822
|
inputs.length !== targetPorts.length ||
|
|
3358
3823
|
!isRecord(values) ||
|
|
3359
|
-
!Object.entries(values).every(([name, value]) => targetControls.has(name) && validEffectParam(value)))
|
|
3824
|
+
!Object.entries(values).every(([name, value]) => targetControls.has(name) && validEffectParam(value))) {
|
|
3360
3825
|
invalid();
|
|
3826
|
+
break;
|
|
3827
|
+
}
|
|
3828
|
+
for (const [name, value] of Object.entries(values)) {
|
|
3829
|
+
const control = builtinControlsOf(target).get(name);
|
|
3830
|
+
if (control && !acceptsBuiltinParam(control.rule, value)) {
|
|
3831
|
+
problems.push(`effect ${control.effect} in composition ${id} node ${nodeId} has a parameter ${control.param} of the wrong type or out of range`);
|
|
3832
|
+
break;
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3361
3835
|
break;
|
|
3362
3836
|
}
|
|
3363
3837
|
case "group_input":
|
|
@@ -3474,8 +3948,7 @@ function matteProblems(tracks) {
|
|
|
3474
3948
|
return problems;
|
|
3475
3949
|
}
|
|
3476
3950
|
// 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.
|
|
3478
|
-
// engine.
|
|
3951
|
+
// so each step is visited once over all walks. A repeated id means its first track, as in Rust.
|
|
3479
3952
|
function duckingCycles(tracks) {
|
|
3480
3953
|
const sidechains = new Map();
|
|
3481
3954
|
for (const track of tracks) {
|