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
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
// Data sets and the places that bind to them, mirroring `alpha2-model`'s `data` and `data_places`.
|
|
2
|
+
import { MAX_DATA_CHANNELS, MAX_DATA_COORDINATE, MAX_DATA_ID_BYTES, MAX_DATA_INTERVALS, MAX_DATA_LABEL_BYTES, MAX_DATA_ROTATION_DEGREES, MAX_DATA_SCALAR, MAX_DATA_SCALE, MAX_DATA_SETS, MAX_DATA_VALUES, MAX_DATA_WORDS, MAX_FOLLOW_DEPTH, } from "./generated/project-schema.js";
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function bytes(text) {
|
|
8
|
+
return encoder.encode(text).length;
|
|
9
|
+
}
|
|
10
|
+
function finite(value) {
|
|
11
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
12
|
+
}
|
|
13
|
+
function isData(value) {
|
|
14
|
+
return isRecord(value) && value.mode === "data";
|
|
15
|
+
}
|
|
16
|
+
function arityOf(kind) {
|
|
17
|
+
return kind === "points"
|
|
18
|
+
? 2
|
|
19
|
+
: kind === "scalars"
|
|
20
|
+
? 1
|
|
21
|
+
: kind === "similarity"
|
|
22
|
+
? 4
|
|
23
|
+
: undefined;
|
|
24
|
+
}
|
|
25
|
+
/** Mirrors `value_in_bounds`. */
|
|
26
|
+
function inBounds(kind, component, value) {
|
|
27
|
+
if (!finite(value))
|
|
28
|
+
return false;
|
|
29
|
+
const v = Math.fround(value);
|
|
30
|
+
if (kind === "points")
|
|
31
|
+
return Math.abs(v) <= MAX_DATA_COORDINATE;
|
|
32
|
+
if (kind === "similarity") {
|
|
33
|
+
if (component < 2)
|
|
34
|
+
return Math.abs(v) <= MAX_DATA_COORDINATE;
|
|
35
|
+
if (component === 2)
|
|
36
|
+
return Math.abs(v) <= MAX_DATA_ROTATION_DEGREES;
|
|
37
|
+
return v > 0 && v <= MAX_DATA_SCALE;
|
|
38
|
+
}
|
|
39
|
+
return Math.abs(v) <= MAX_DATA_SCALAR;
|
|
40
|
+
}
|
|
41
|
+
function label(text) {
|
|
42
|
+
return typeof text === "string" && bytes(text) <= MAX_DATA_LABEL_BYTES;
|
|
43
|
+
}
|
|
44
|
+
/** Mirrors `DataSet::check`. */
|
|
45
|
+
function setProblem(set, validFingerprint) {
|
|
46
|
+
const id = String(set.id);
|
|
47
|
+
if (bytes(id) > MAX_DATA_ID_BYTES)
|
|
48
|
+
return `has an id over ${MAX_DATA_ID_BYTES} bytes`;
|
|
49
|
+
const madeBy = set.made_by;
|
|
50
|
+
if (isRecord(madeBy)) {
|
|
51
|
+
const plugin = madeBy.plugin;
|
|
52
|
+
const pluginOk = plugin == null ||
|
|
53
|
+
(isRecord(plugin) &&
|
|
54
|
+
typeof plugin.version === "string" &&
|
|
55
|
+
plugin.version.length > 0 &&
|
|
56
|
+
typeof plugin.artifact_sha256 === "string" &&
|
|
57
|
+
/^[0-9a-f]{64}$/.test(plugin.artifact_sha256));
|
|
58
|
+
if (madeBy.extractor === "" || !pluginOk)
|
|
59
|
+
return "has an invalid made_by";
|
|
60
|
+
}
|
|
61
|
+
const anchor = isRecord(set.anchor) ? set.anchor : {};
|
|
62
|
+
if (set.made_from != null) {
|
|
63
|
+
if (anchor.type === "timeline")
|
|
64
|
+
return "has an invalid made_from.anchor";
|
|
65
|
+
if (!validFingerprint(set.made_from))
|
|
66
|
+
return "has an invalid made_from";
|
|
67
|
+
}
|
|
68
|
+
const timeProblem = (time) => typeof time !== "number" || time < 0 ? "has a negative time" : undefined;
|
|
69
|
+
const kind = set.kind;
|
|
70
|
+
const arity = arityOf(kind);
|
|
71
|
+
if (arity !== undefined) {
|
|
72
|
+
const channels = kind === "similarity"
|
|
73
|
+
? [""]
|
|
74
|
+
: Array.isArray(set.channels)
|
|
75
|
+
? set.channels
|
|
76
|
+
: [];
|
|
77
|
+
if (kind !== "similarity") {
|
|
78
|
+
if (channels.length === 0 || channels.length > MAX_DATA_CHANNELS)
|
|
79
|
+
return `needs 1 to ${MAX_DATA_CHANNELS} channels`;
|
|
80
|
+
const seen = new Set();
|
|
81
|
+
for (const name of channels) {
|
|
82
|
+
if (typeof name !== "string" ||
|
|
83
|
+
name.length === 0 ||
|
|
84
|
+
!label(name) ||
|
|
85
|
+
seen.has(name))
|
|
86
|
+
return "has an empty, overlong or repeated channel name";
|
|
87
|
+
seen.add(name);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const times = Array.isArray(set.times) ? set.times : [];
|
|
91
|
+
const values = Array.isArray(set.values) ? set.values : [];
|
|
92
|
+
if (values.length > MAX_DATA_VALUES)
|
|
93
|
+
return `has more than ${MAX_DATA_VALUES} values`;
|
|
94
|
+
if (values.length !== times.length * channels.length * arity)
|
|
95
|
+
return "does not have times * channels * arity values";
|
|
96
|
+
for (const [index, time] of times.entries()) {
|
|
97
|
+
if (index > 0 && times[index - 1] >= time)
|
|
98
|
+
return "has times that are not strictly ascending";
|
|
99
|
+
const problem = timeProblem(time);
|
|
100
|
+
if (problem)
|
|
101
|
+
return problem;
|
|
102
|
+
}
|
|
103
|
+
for (let group = 0; group * arity < values.length; group += 1) {
|
|
104
|
+
const lost = values[group * arity] === null;
|
|
105
|
+
for (let component = 0; component < arity; component += 1) {
|
|
106
|
+
const index = group * arity + component;
|
|
107
|
+
const value = values[index];
|
|
108
|
+
const ok = value === null ? lost : !lost && inBounds(kind, component, value);
|
|
109
|
+
if (!ok)
|
|
110
|
+
return `has an invalid value at values[${index}]`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
const words = kind === "words";
|
|
116
|
+
const items = (words ? set.words : set.intervals);
|
|
117
|
+
const list = Array.isArray(items) ? items : [];
|
|
118
|
+
if (list.length > (words ? MAX_DATA_WORDS : MAX_DATA_INTERVALS))
|
|
119
|
+
return `has more than ${MAX_DATA_WORDS} words or ${MAX_DATA_INTERVALS} intervals`;
|
|
120
|
+
for (const [index, item] of list.entries()) {
|
|
121
|
+
if (!isRecord(item))
|
|
122
|
+
return `has an invalid item at [${index}]`;
|
|
123
|
+
const start = item.start;
|
|
124
|
+
const end = item.end;
|
|
125
|
+
const before = index > 0 ? list[index - 1] : undefined;
|
|
126
|
+
const ordered = before === undefined ||
|
|
127
|
+
before.start < start ||
|
|
128
|
+
(before.start === start && before.end <= end);
|
|
129
|
+
const own = words
|
|
130
|
+
? start >= 0 &&
|
|
131
|
+
start < end &&
|
|
132
|
+
typeof item.text === "string" &&
|
|
133
|
+
item.text.length > 0 &&
|
|
134
|
+
label(item.text) &&
|
|
135
|
+
(item.speaker == null || label(item.speaker))
|
|
136
|
+
: start >= 0 &&
|
|
137
|
+
start <= end &&
|
|
138
|
+
(item.label == null || label(item.label)) &&
|
|
139
|
+
(item.score == null || inBounds("scalars", 0, item.score));
|
|
140
|
+
if (!own || !ordered)
|
|
141
|
+
return `has an invalid item at [${index}]`;
|
|
142
|
+
const problem = timeProblem(start) ?? timeProblem(end);
|
|
143
|
+
if (problem)
|
|
144
|
+
return problem;
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
/** Every `{ mode: "data" }` value under `node`, with its path, for places that refuse data. */
|
|
149
|
+
function bindingsUnder(node, at, found) {
|
|
150
|
+
if (Array.isArray(node)) {
|
|
151
|
+
node.forEach((item, index) => bindingsUnder(item, `${at}[${index}]`, found));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (!isRecord(node))
|
|
155
|
+
return;
|
|
156
|
+
if (isData(node)) {
|
|
157
|
+
found.push([at, node]);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
for (const [key, value] of Object.entries(node)) {
|
|
161
|
+
bindingsUnder(value, at ? `${at}.${key}` : key, found);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function slotOf(kind) {
|
|
165
|
+
return { kind };
|
|
166
|
+
}
|
|
167
|
+
/** Each data binding of a clip mask or composition shape mask's geometry and feather. */
|
|
168
|
+
function maskBindings(masks, prefix, found) {
|
|
169
|
+
if (!Array.isArray(masks))
|
|
170
|
+
return;
|
|
171
|
+
masks.forEach((mask, index) => {
|
|
172
|
+
if (!isRecord(mask))
|
|
173
|
+
return;
|
|
174
|
+
const at = `${prefix}masks[${index}]`;
|
|
175
|
+
const shape = isRecord(mask.shape) ? mask.shape : {};
|
|
176
|
+
for (const [field, value] of Object.entries(shape)) {
|
|
177
|
+
if (!isData(value))
|
|
178
|
+
continue;
|
|
179
|
+
const kind = field === "center" ? "point" : field === "size" ? "vec2" : "scalar";
|
|
180
|
+
found.push([`${at}.shape.${field}`, value, slotOf(kind)]);
|
|
181
|
+
}
|
|
182
|
+
if (isData(mask.feather))
|
|
183
|
+
found.push([`${at}.feather`, mask.feather, slotOf("scalar")]);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/** Each data binding of a visual (a clip's, or a transform node's). */
|
|
187
|
+
function visualBindings(visual, prefix, found) {
|
|
188
|
+
if (!isRecord(visual))
|
|
189
|
+
return;
|
|
190
|
+
const fields = [
|
|
191
|
+
["position", "point"],
|
|
192
|
+
["scale", "vec2"],
|
|
193
|
+
["rotation_degrees", "scalar"],
|
|
194
|
+
["opacity", "scalar"],
|
|
195
|
+
];
|
|
196
|
+
for (const [field, kind] of fields) {
|
|
197
|
+
const value = visual[field];
|
|
198
|
+
if (isData(value))
|
|
199
|
+
found.push([`${prefix}.${field}`, value, slotOf(kind)]);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function ownerText(owner) {
|
|
203
|
+
switch (owner.kind) {
|
|
204
|
+
case "clip":
|
|
205
|
+
return `clip ${owner.clip}`;
|
|
206
|
+
case "track":
|
|
207
|
+
return `track ${owner.track}`;
|
|
208
|
+
case "transition":
|
|
209
|
+
return `track ${owner.track} transition ${owner.from} to ${owner.to}`;
|
|
210
|
+
case "node":
|
|
211
|
+
return `composition ${owner.composition} node ${owner.node}`;
|
|
212
|
+
case "master":
|
|
213
|
+
return "the master bus";
|
|
214
|
+
case "source":
|
|
215
|
+
return `source ${owner.source}`;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** `reference` as text in the lint path syntax, such as `clip c1 visual.position`. */
|
|
219
|
+
export function describeDataReference(reference) {
|
|
220
|
+
return `${ownerText(reference.owner)} ${reference.property}`;
|
|
221
|
+
}
|
|
222
|
+
/** Visits every binding, correction and caption words reference in `data_places` order. */
|
|
223
|
+
function walkPlaces(project, paramType, visit) {
|
|
224
|
+
const timeline = isRecord(project.timeline) ? project.timeline : {};
|
|
225
|
+
const tracks = (Array.isArray(timeline.tracks) ? timeline.tracks : []).filter(isRecord);
|
|
226
|
+
const timelineClock = { kind: "timeline" };
|
|
227
|
+
const pictureClock = { kind: "picture" };
|
|
228
|
+
const scalar = { kind: "scalar" };
|
|
229
|
+
for (const track of tracks) {
|
|
230
|
+
const trackId = String(track.id);
|
|
231
|
+
for (const clip of Array.isArray(track.clips) ? track.clips : []) {
|
|
232
|
+
if (!isRecord(clip))
|
|
233
|
+
continue;
|
|
234
|
+
const clipId = String(clip.id);
|
|
235
|
+
const owner = { kind: "clip", clip: clipId };
|
|
236
|
+
const found = [];
|
|
237
|
+
visualBindings(clip.visual, "visual", found);
|
|
238
|
+
maskBindings(clip.masks, "", found);
|
|
239
|
+
const audio = isRecord(clip.audio) ? clip.audio : {};
|
|
240
|
+
for (const field of ["gain", "pan"]) {
|
|
241
|
+
if (isData(audio[field]))
|
|
242
|
+
found.push([`audio.${field}`, audio[field], slotOf("scalar")]);
|
|
243
|
+
}
|
|
244
|
+
for (const [at, binding, slot] of found)
|
|
245
|
+
visit({
|
|
246
|
+
use: "binding",
|
|
247
|
+
owner,
|
|
248
|
+
at,
|
|
249
|
+
binding,
|
|
250
|
+
clock: timelineClock,
|
|
251
|
+
slot,
|
|
252
|
+
follower: clipId,
|
|
253
|
+
});
|
|
254
|
+
const visual = isRecord(clip.visual) ? clip.visual : {};
|
|
255
|
+
if (isRecord(visual.correction))
|
|
256
|
+
visit({
|
|
257
|
+
use: "correction",
|
|
258
|
+
owner,
|
|
259
|
+
at: "visual.correction",
|
|
260
|
+
reference: visual.correction,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
for (const transition of Array.isArray(track.transitions)
|
|
264
|
+
? track.transitions
|
|
265
|
+
: []) {
|
|
266
|
+
if (!isRecord(transition) || !isRecord(transition.effect))
|
|
267
|
+
continue;
|
|
268
|
+
const owner = {
|
|
269
|
+
kind: "transition",
|
|
270
|
+
track: trackId,
|
|
271
|
+
from: String(transition.from_clip),
|
|
272
|
+
to: String(transition.to_clip),
|
|
273
|
+
};
|
|
274
|
+
const params = isRecord(transition.effect.params)
|
|
275
|
+
? transition.effect.params
|
|
276
|
+
: {};
|
|
277
|
+
for (const [name, value] of Object.entries(params)) {
|
|
278
|
+
if (!isData(value))
|
|
279
|
+
continue;
|
|
280
|
+
visit({
|
|
281
|
+
use: "binding",
|
|
282
|
+
owner,
|
|
283
|
+
at: `effect.params.${name}`,
|
|
284
|
+
binding: value,
|
|
285
|
+
clock: timelineClock,
|
|
286
|
+
slot: {
|
|
287
|
+
kind: "param",
|
|
288
|
+
type: paramType(String(transition.effect.id), name),
|
|
289
|
+
},
|
|
290
|
+
follower: undefined,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const owner = { kind: "track", track: trackId };
|
|
295
|
+
const audio = isRecord(track.audio) ? track.audio : {};
|
|
296
|
+
for (const field of ["gain", "pan"]) {
|
|
297
|
+
const value = audio[field];
|
|
298
|
+
if (isData(value))
|
|
299
|
+
visit({
|
|
300
|
+
use: "binding",
|
|
301
|
+
owner,
|
|
302
|
+
at: `audio.${field}`,
|
|
303
|
+
binding: value,
|
|
304
|
+
clock: timelineClock,
|
|
305
|
+
slot: scalar,
|
|
306
|
+
follower: undefined,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (isRecord(track.captions)) {
|
|
310
|
+
const captions = track.captions;
|
|
311
|
+
const found = [];
|
|
312
|
+
bindingsUnder(captions.style, "captions.style", found);
|
|
313
|
+
bindingsUnder(captions.styles, "captions.styles", found);
|
|
314
|
+
for (const [at, binding] of found)
|
|
315
|
+
visit({
|
|
316
|
+
use: "binding",
|
|
317
|
+
owner,
|
|
318
|
+
at,
|
|
319
|
+
binding,
|
|
320
|
+
clock: pictureClock,
|
|
321
|
+
slot: scalar,
|
|
322
|
+
follower: undefined,
|
|
323
|
+
});
|
|
324
|
+
if (isRecord(captions.from_words))
|
|
325
|
+
visit({
|
|
326
|
+
use: "words",
|
|
327
|
+
owner,
|
|
328
|
+
at: "captions.from_words",
|
|
329
|
+
reference: captions.from_words,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const master = isRecord(project.audio) ? project.audio : {};
|
|
334
|
+
if (isData(master.gain))
|
|
335
|
+
visit({
|
|
336
|
+
use: "binding",
|
|
337
|
+
owner: { kind: "master" },
|
|
338
|
+
at: "audio.gain",
|
|
339
|
+
binding: master.gain,
|
|
340
|
+
clock: timelineClock,
|
|
341
|
+
slot: slotOf("scalar"),
|
|
342
|
+
follower: undefined,
|
|
343
|
+
});
|
|
344
|
+
const compositions = new Map();
|
|
345
|
+
for (const composition of Array.isArray(project.compositions)
|
|
346
|
+
? project.compositions
|
|
347
|
+
: []) {
|
|
348
|
+
if (isRecord(composition))
|
|
349
|
+
compositions.set(String(composition.id), composition);
|
|
350
|
+
}
|
|
351
|
+
for (const composition of compositions.values()) {
|
|
352
|
+
for (const node of Array.isArray(composition.nodes)
|
|
353
|
+
? composition.nodes
|
|
354
|
+
: []) {
|
|
355
|
+
if (!isRecord(node) || !isRecord(node.op))
|
|
356
|
+
continue;
|
|
357
|
+
const op = node.op;
|
|
358
|
+
const owner = {
|
|
359
|
+
kind: "node",
|
|
360
|
+
composition: String(composition.id),
|
|
361
|
+
node: String(node.id),
|
|
362
|
+
};
|
|
363
|
+
const clock = { kind: "composition", composition };
|
|
364
|
+
const found = [];
|
|
365
|
+
const effectParams = (effect) => {
|
|
366
|
+
if (!isRecord(effect) || !isRecord(effect.params))
|
|
367
|
+
return;
|
|
368
|
+
for (const [name, value] of Object.entries(effect.params)) {
|
|
369
|
+
if (isData(value))
|
|
370
|
+
found.push([
|
|
371
|
+
`effect.params.${name}`,
|
|
372
|
+
value,
|
|
373
|
+
{ kind: "param", type: paramType(String(effect.id), name) },
|
|
374
|
+
]);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
switch (op.type) {
|
|
378
|
+
case "effect":
|
|
379
|
+
effectParams(op.effect);
|
|
380
|
+
break;
|
|
381
|
+
case "transition":
|
|
382
|
+
effectParams(op.effect);
|
|
383
|
+
if (isData(op.progress))
|
|
384
|
+
found.push(["progress", op.progress, slotOf("scalar")]);
|
|
385
|
+
break;
|
|
386
|
+
case "transform":
|
|
387
|
+
if (isRecord(op.transform) && op.transform.correction != null)
|
|
388
|
+
visit({
|
|
389
|
+
use: "refused",
|
|
390
|
+
owner,
|
|
391
|
+
at: "transform.correction",
|
|
392
|
+
problem: "has `correction` where it does not apply",
|
|
393
|
+
});
|
|
394
|
+
visualBindings(op.transform, "transform", found);
|
|
395
|
+
break;
|
|
396
|
+
case "merge":
|
|
397
|
+
(Array.isArray(op.layers) ? op.layers : []).forEach((layer, index) => {
|
|
398
|
+
if (isRecord(layer) && isData(layer.opacity))
|
|
399
|
+
found.push([
|
|
400
|
+
`layers[${index}].opacity`,
|
|
401
|
+
layer.opacity,
|
|
402
|
+
slotOf("scalar"),
|
|
403
|
+
]);
|
|
404
|
+
});
|
|
405
|
+
break;
|
|
406
|
+
case "shape_mask":
|
|
407
|
+
maskBindings(op.masks, "", found);
|
|
408
|
+
break;
|
|
409
|
+
case "group": {
|
|
410
|
+
const controls = isRecord(op.controls) ? op.controls : {};
|
|
411
|
+
const group = compositions.get(String(op.composition));
|
|
412
|
+
for (const [name, value] of Object.entries(controls)) {
|
|
413
|
+
if (!isData(value))
|
|
414
|
+
continue;
|
|
415
|
+
const control = (Array.isArray(group?.controls) ? group.controls : []).find((candidate) => isRecord(candidate) && candidate.name === name);
|
|
416
|
+
const target = (Array.isArray(group?.nodes) ? group.nodes : []).find((candidate) => isRecord(candidate) && candidate.id === control?.node);
|
|
417
|
+
const targetOp = isRecord(target?.op) ? target.op : undefined;
|
|
418
|
+
const type = (targetOp?.type === "effect" ||
|
|
419
|
+
targetOp?.type === "transition") &&
|
|
420
|
+
isRecord(targetOp.effect)
|
|
421
|
+
? paramType(String(targetOp.effect.id), String(control?.param))
|
|
422
|
+
: undefined;
|
|
423
|
+
found.push([`controls.${name}`, value, { kind: "param", type }]);
|
|
424
|
+
}
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
case "generator": {
|
|
428
|
+
const nested = [];
|
|
429
|
+
bindingsUnder(op.generator, "generator", nested);
|
|
430
|
+
for (const [at, binding] of nested)
|
|
431
|
+
found.push([at, binding, scalar]);
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
default:
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
for (const [at, binding, slot] of found)
|
|
438
|
+
visit({
|
|
439
|
+
use: "binding",
|
|
440
|
+
owner,
|
|
441
|
+
at,
|
|
442
|
+
binding,
|
|
443
|
+
clock: op.type === "generator" ? pictureClock : clock,
|
|
444
|
+
slot,
|
|
445
|
+
follower: undefined,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
for (const source of Array.isArray(project.sources) ? project.sources : []) {
|
|
450
|
+
if (!isRecord(source) || !isRecord(source.generator))
|
|
451
|
+
continue;
|
|
452
|
+
const found = [];
|
|
453
|
+
bindingsUnder(source.generator, "", found);
|
|
454
|
+
for (const [at, binding] of found)
|
|
455
|
+
visit({
|
|
456
|
+
use: "binding",
|
|
457
|
+
owner: { kind: "source", source: String(source.id) },
|
|
458
|
+
at,
|
|
459
|
+
binding,
|
|
460
|
+
clock: pictureClock,
|
|
461
|
+
slot: scalar,
|
|
462
|
+
follower: undefined,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Every place of `project` that reads a data set, in document order: bindings, corrections and
|
|
468
|
+
* caption words. References to sets the project lacks are listed too.
|
|
469
|
+
*/
|
|
470
|
+
export function dataReferences(project) {
|
|
471
|
+
const references = [];
|
|
472
|
+
walkPlaces(project, () => undefined, (place) => {
|
|
473
|
+
if (place.use === "refused")
|
|
474
|
+
return;
|
|
475
|
+
const reference = place.use === "binding" ? place.binding : place.reference;
|
|
476
|
+
const via = place.use === "binding" ? place.binding.via : undefined;
|
|
477
|
+
references.push({
|
|
478
|
+
data: String(reference.data),
|
|
479
|
+
owner: place.owner,
|
|
480
|
+
property: place.use === "words" ? "captions" : place.at,
|
|
481
|
+
...(isRecord(via) && typeof via.clip === "string"
|
|
482
|
+
? { via: { clip: via.clip } }
|
|
483
|
+
: isRecord(via) && typeof via.node === "string"
|
|
484
|
+
? { via: { node: via.node } }
|
|
485
|
+
: {}),
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
return references;
|
|
489
|
+
}
|
|
490
|
+
/** Data sets whose own checks passed. */
|
|
491
|
+
const passedSets = new WeakSet();
|
|
492
|
+
/**
|
|
493
|
+
* Problems of the project's data sets and of every binding, correction and caption words
|
|
494
|
+
* reference. `validFingerprint` is the validator's own fingerprint check. A set `sealed` reports
|
|
495
|
+
* as unchangeable skips its own checks once it has passed them with the same source duration.
|
|
496
|
+
*/
|
|
497
|
+
export function dataProblems(project, paramType, validFingerprint, sealed = () => false) {
|
|
498
|
+
const problems = [];
|
|
499
|
+
const sets = Array.isArray(project.data) ? project.data : [];
|
|
500
|
+
if (sets.length > MAX_DATA_SETS) {
|
|
501
|
+
return [
|
|
502
|
+
`project has ${sets.length} data sets; the maximum is ${MAX_DATA_SETS}`,
|
|
503
|
+
];
|
|
504
|
+
}
|
|
505
|
+
const sources = new Map();
|
|
506
|
+
for (const source of Array.isArray(project.sources) ? project.sources : []) {
|
|
507
|
+
if (isRecord(source))
|
|
508
|
+
sources.set(String(source.id), source);
|
|
509
|
+
}
|
|
510
|
+
const data = new Map();
|
|
511
|
+
for (const set of sets) {
|
|
512
|
+
if (!isRecord(set))
|
|
513
|
+
continue;
|
|
514
|
+
const id = String(set.id);
|
|
515
|
+
if (data.has(id)) {
|
|
516
|
+
problems.push(`duplicate data set id ${id}`);
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
data.set(id, set);
|
|
520
|
+
const anchor = isRecord(set.anchor) ? set.anchor : {};
|
|
521
|
+
if (anchor.type === "source") {
|
|
522
|
+
const source = sources.get(String(anchor.source_id));
|
|
523
|
+
if (source === undefined) {
|
|
524
|
+
problems.push(`data set ${id} is anchored to unknown source ${String(anchor.source_id)}`);
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
if (!["video", "audio", "image"].includes(String(source.kind))) {
|
|
528
|
+
problems.push(`data set ${id} is anchored to source ${String(source.id)}, which has no media`);
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (passedSets.has(set))
|
|
533
|
+
continue;
|
|
534
|
+
const problem = setProblem(set, validFingerprint);
|
|
535
|
+
if (problem)
|
|
536
|
+
problems.push(`data set ${id} ${problem}`);
|
|
537
|
+
else if (sealed(set))
|
|
538
|
+
passedSets.add(set);
|
|
539
|
+
}
|
|
540
|
+
const timeline = isRecord(project.timeline) ? project.timeline : {};
|
|
541
|
+
const tracks = (Array.isArray(timeline.tracks) ? timeline.tracks : []).filter(isRecord);
|
|
542
|
+
const clips = new Map();
|
|
543
|
+
for (const track of tracks) {
|
|
544
|
+
for (const clip of Array.isArray(track.clips) ? track.clips : []) {
|
|
545
|
+
if (isRecord(clip))
|
|
546
|
+
clips.set(String(clip.id), { clip, trackKind: track.kind });
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const follows = [];
|
|
550
|
+
/** Mirrors `Places::check`; `undefined` when the binding is usable. */
|
|
551
|
+
const check = (binding, clock, slot, follower, at) => {
|
|
552
|
+
const set = data.get(String(binding.data));
|
|
553
|
+
if (set === undefined)
|
|
554
|
+
return "names an unknown data set";
|
|
555
|
+
const kind = set.kind;
|
|
556
|
+
const vec2Slot = slot.kind === "point" ||
|
|
557
|
+
slot.kind === "vec2" ||
|
|
558
|
+
(slot.kind === "param" &&
|
|
559
|
+
(slot.type === "vec2" || slot.type === undefined));
|
|
560
|
+
const scalarSlot = slot.kind === "scalar" ||
|
|
561
|
+
(slot.kind === "param" && slot.type === "float");
|
|
562
|
+
if (!vec2Slot && !scalarSlot)
|
|
563
|
+
return "is a value whose type takes no data";
|
|
564
|
+
const accepted = vec2Slot ? ["points", "scalars"] : ["scalars"];
|
|
565
|
+
if (!accepted.includes(String(kind)))
|
|
566
|
+
return `cannot follow ${String(kind)} data`;
|
|
567
|
+
const channels = Array.isArray(set.channels) ? set.channels : [];
|
|
568
|
+
if (!channels.includes(binding.channel))
|
|
569
|
+
return "names an unknown channel";
|
|
570
|
+
const offset = binding.offset;
|
|
571
|
+
const remap = binding.remap;
|
|
572
|
+
const offsetOk = offset == null || (Array.isArray(offset) && offset.every(finite));
|
|
573
|
+
const remapOk = remap == null ||
|
|
574
|
+
(isRecord(remap) &&
|
|
575
|
+
Array.isArray(remap.input) &&
|
|
576
|
+
Array.isArray(remap.output) &&
|
|
577
|
+
[...remap.input, ...remap.output].every(finite) &&
|
|
578
|
+
Math.fround(remap.input[0]) !==
|
|
579
|
+
Math.fround(remap.input[1]));
|
|
580
|
+
if (!offsetOk || !remapOk)
|
|
581
|
+
return "has a non-finite offset or remap, or a remap with equal inputs";
|
|
582
|
+
const points = kind === "points";
|
|
583
|
+
if (points && remap != null)
|
|
584
|
+
return "has `remap` where it does not apply";
|
|
585
|
+
if (!points && offset != null)
|
|
586
|
+
return "has `offset` where it does not apply";
|
|
587
|
+
if (!points && binding.space != null)
|
|
588
|
+
return "has `space` where it does not apply";
|
|
589
|
+
const anchor = isRecord(set.anchor) ? set.anchor : {};
|
|
590
|
+
if (clock.kind === "picture" ||
|
|
591
|
+
(anchor.type === "timeline" && clock.kind === "composition"))
|
|
592
|
+
return "is keyed on a clock that refuses this anchor";
|
|
593
|
+
if (anchor.type === "timeline") {
|
|
594
|
+
if (binding.via != null)
|
|
595
|
+
return "takes no `via` for a timeline-anchored data set";
|
|
596
|
+
if (binding.space != null)
|
|
597
|
+
return "has `space` where it does not apply";
|
|
598
|
+
return undefined;
|
|
599
|
+
}
|
|
600
|
+
const via = binding.via;
|
|
601
|
+
if (!isRecord(via))
|
|
602
|
+
return "needs `via` for a source-anchored data set";
|
|
603
|
+
if (points && binding.space == null)
|
|
604
|
+
return "needs `space` for a point read through `via`";
|
|
605
|
+
const source = String(anchor.source_id);
|
|
606
|
+
if (typeof via.clip === "string" && clock.kind === "timeline") {
|
|
607
|
+
const entry = clips.get(via.clip);
|
|
608
|
+
if (entry === undefined)
|
|
609
|
+
return "reads through an unknown clip";
|
|
610
|
+
if (String(entry.clip.source_id) !== source)
|
|
611
|
+
return "reads through a reader of another source";
|
|
612
|
+
if (binding.space === "canvas") {
|
|
613
|
+
if (entry.trackKind !== "video")
|
|
614
|
+
return "names a reader of the wrong kind for its clock";
|
|
615
|
+
if (follower === via.clip)
|
|
616
|
+
return "follows clips in canvas space in a cycle";
|
|
617
|
+
if (follower !== undefined)
|
|
618
|
+
follows.push({ follower, via: via.clip, at });
|
|
619
|
+
}
|
|
620
|
+
return undefined;
|
|
621
|
+
}
|
|
622
|
+
if (typeof via.node === "string" && clock.kind === "composition") {
|
|
623
|
+
const nodes = Array.isArray(clock.composition.nodes)
|
|
624
|
+
? clock.composition.nodes
|
|
625
|
+
: [];
|
|
626
|
+
const node = nodes.find((candidate) => isRecord(candidate) && candidate.id === via.node);
|
|
627
|
+
const op = isRecord(node) && isRecord(node.op) ? node.op : undefined;
|
|
628
|
+
if (op?.type !== "media")
|
|
629
|
+
return "reads through a node that is not a media node of its composition";
|
|
630
|
+
if (String(op.source_id) !== source)
|
|
631
|
+
return "reads through a reader of another source";
|
|
632
|
+
if (binding.space === "canvas")
|
|
633
|
+
return "has `space` where it does not apply";
|
|
634
|
+
return undefined;
|
|
635
|
+
}
|
|
636
|
+
return "names a reader of the wrong kind for its clock";
|
|
637
|
+
};
|
|
638
|
+
const report = (owner, at, problem) => {
|
|
639
|
+
if (problem)
|
|
640
|
+
problems.push(`${owner} ${at} ${problem}`);
|
|
641
|
+
};
|
|
642
|
+
const usable = (id, at, owner) => {
|
|
643
|
+
const set = data.get(String(id));
|
|
644
|
+
if (set === undefined)
|
|
645
|
+
report(owner, at, "names an unknown data set");
|
|
646
|
+
return set;
|
|
647
|
+
};
|
|
648
|
+
walkPlaces(project, paramType, (place) => {
|
|
649
|
+
const owner = ownerText(place.owner);
|
|
650
|
+
if (place.use === "refused") {
|
|
651
|
+
report(owner, place.at, place.problem);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
if (place.use === "binding") {
|
|
655
|
+
report(owner, place.at, check(place.binding, place.clock, place.slot, place.follower, place.at));
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
const set = usable(place.reference.data, place.at, owner);
|
|
659
|
+
if (set === undefined)
|
|
660
|
+
return;
|
|
661
|
+
const anchor = isRecord(set.anchor) ? set.anchor : {};
|
|
662
|
+
if (place.use === "correction") {
|
|
663
|
+
const clip = clips.get(place.owner.clip)?.clip;
|
|
664
|
+
if (set.kind !== "similarity")
|
|
665
|
+
report(owner, place.at, `cannot follow ${String(set.kind)} data`);
|
|
666
|
+
else if (anchor.type !== "source" || anchor.source_id !== clip?.source_id)
|
|
667
|
+
report(owner, place.at, "corrects with data anchored to another source");
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
const words = place.reference;
|
|
671
|
+
const trackOk = anchor.type === "source"
|
|
672
|
+
? typeof words.track === "string" &&
|
|
673
|
+
tracks.some((other) => other.id === words.track && other.kind !== "caption")
|
|
674
|
+
: words.track == null;
|
|
675
|
+
if (set.kind !== "words")
|
|
676
|
+
report(owner, place.at, `cannot follow ${String(set.kind)} data`);
|
|
677
|
+
else if (!trackOk || words.max_chars === 0)
|
|
678
|
+
report(owner, place.at, "has an invalid words track or max_chars");
|
|
679
|
+
});
|
|
680
|
+
const graph = followProblem(follows);
|
|
681
|
+
if (graph)
|
|
682
|
+
problems.push(`clip ${graph.follow.follower} ${graph.follow.at} ${graph.problem}`);
|
|
683
|
+
return problems;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* The first canvas follow, in document order, that lies on a cycle; else the first whose
|
|
687
|
+
* follower follows more than `MAX_FOLLOW_DEPTH` links deep. Mirrors `check_follow_graph`.
|
|
688
|
+
*/
|
|
689
|
+
function followProblem(follows) {
|
|
690
|
+
const index = new Map();
|
|
691
|
+
const node = (clip) => {
|
|
692
|
+
let found = index.get(clip);
|
|
693
|
+
if (found === undefined) {
|
|
694
|
+
found = index.size;
|
|
695
|
+
index.set(clip, found);
|
|
696
|
+
}
|
|
697
|
+
return found;
|
|
698
|
+
};
|
|
699
|
+
const edges = follows.map((follow) => [
|
|
700
|
+
node(follow.follower),
|
|
701
|
+
node(follow.via),
|
|
702
|
+
]);
|
|
703
|
+
const next = Array.from({ length: index.size }, () => []);
|
|
704
|
+
for (const [from, to] of edges)
|
|
705
|
+
next[from].push(to);
|
|
706
|
+
const unseen = -1;
|
|
707
|
+
const order = new Array(index.size).fill(unseen);
|
|
708
|
+
const low = new Array(index.size).fill(0);
|
|
709
|
+
const component = new Array(index.size).fill(unseen);
|
|
710
|
+
const depth = new Array(index.size).fill(0);
|
|
711
|
+
const open = [];
|
|
712
|
+
let visited = 0;
|
|
713
|
+
let components = 0;
|
|
714
|
+
for (let root = 0; root < index.size; root++) {
|
|
715
|
+
if (order[root] !== unseen)
|
|
716
|
+
continue;
|
|
717
|
+
order[root] = low[root] = visited++;
|
|
718
|
+
open.push(root);
|
|
719
|
+
const calls = [[root, 0]];
|
|
720
|
+
while (calls.length > 0) {
|
|
721
|
+
const call = calls[calls.length - 1];
|
|
722
|
+
const at = call[0];
|
|
723
|
+
if (call[1] < next[at].length) {
|
|
724
|
+
const target = next[at][call[1]++];
|
|
725
|
+
if (order[target] === unseen) {
|
|
726
|
+
order[target] = low[target] = visited++;
|
|
727
|
+
open.push(target);
|
|
728
|
+
calls.push([target, 0]);
|
|
729
|
+
}
|
|
730
|
+
else if (component[target] === unseen) {
|
|
731
|
+
low[at] = Math.min(low[at], order[target]);
|
|
732
|
+
}
|
|
733
|
+
continue;
|
|
734
|
+
}
|
|
735
|
+
calls.pop();
|
|
736
|
+
if (calls.length > 0) {
|
|
737
|
+
const parent = calls[calls.length - 1][0];
|
|
738
|
+
low[parent] = Math.min(low[parent], low[at]);
|
|
739
|
+
}
|
|
740
|
+
depth[at] = next[at].reduce((most, target) => Math.max(most, depth[target] + 1), 0);
|
|
741
|
+
if (low[at] === order[at]) {
|
|
742
|
+
for (;;) {
|
|
743
|
+
const member = open.pop();
|
|
744
|
+
component[member] = components;
|
|
745
|
+
if (member === at)
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
components++;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
const cycle = edges.findIndex(([from, to]) => component[from] === component[to]);
|
|
753
|
+
if (cycle >= 0)
|
|
754
|
+
return {
|
|
755
|
+
follow: follows[cycle],
|
|
756
|
+
problem: "follows clips in canvas space in a cycle",
|
|
757
|
+
};
|
|
758
|
+
const deep = edges.findIndex(([from]) => depth[from] > MAX_FOLLOW_DEPTH);
|
|
759
|
+
if (deep >= 0)
|
|
760
|
+
return {
|
|
761
|
+
follow: follows[deep],
|
|
762
|
+
problem: `follows clips in canvas space more than ${MAX_FOLLOW_DEPTH} deep`,
|
|
763
|
+
};
|
|
764
|
+
return undefined;
|
|
765
|
+
}
|