@alpha2-sh/editor 0.4.6 → 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/dist/browser/bridge.d.ts +15 -16
- package/dist/browser/bridge.js +396 -312
- package/dist/browser/extensions-worker.d.ts +12 -16
- package/dist/browser/extensions-worker.js +17 -24
- package/dist/browser/hash-worker.d.ts +4 -5
- package/dist/browser/hash-worker.js +7 -8
- package/dist/browser/jobs.d.ts +17 -19
- package/dist/browser/jobs.js +41 -28
- package/dist/browser/resources.d.ts +6 -11
- package/dist/browser/resources.js +5 -9
- package/dist/browser/runtime/assets.d.ts +47 -28
- package/dist/browser/runtime/assets.js +129 -45
- package/dist/browser/runtime/audio.d.ts +16 -11
- package/dist/browser/runtime/audio.js +58 -31
- package/dist/browser/runtime/budget.d.ts +4 -5
- package/dist/browser/runtime/budget.js +4 -5
- package/dist/browser/runtime/caption-fonts.d.ts +3 -7
- package/dist/browser/runtime/caption-fonts.js +4 -8
- package/dist/browser/runtime/engine.d.ts +39 -44
- package/dist/browser/runtime/engine.js +78 -64
- package/dist/browser/runtime/export-audio.d.ts +6 -6
- package/dist/browser/runtime/export-audio.js +8 -9
- package/dist/browser/runtime/exporter.d.ts +33 -66
- package/dist/browser/runtime/exporter.js +111 -137
- package/dist/browser/runtime/extension-import.d.ts +28 -35
- package/dist/browser/runtime/extension-import.js +36 -46
- package/dist/browser/runtime/fingerprint.d.ts +11 -14
- package/dist/browser/runtime/fingerprint.js +20 -24
- package/dist/browser/runtime/generators.d.ts +2 -3
- package/dist/browser/runtime/generators.js +5 -7
- package/dist/browser/runtime/locks.d.ts +5 -7
- package/dist/browser/runtime/locks.js +5 -7
- package/dist/browser/runtime/output.d.ts +7 -9
- package/dist/browser/runtime/output.js +17 -21
- package/dist/browser/runtime/preview-utils.js +10 -6
- package/dist/browser/runtime/proxies.d.ts +10 -17
- package/dist/browser/runtime/proxies.js +33 -45
- package/dist/browser/runtime/proxy-storage.d.ts +15 -19
- package/dist/browser/runtime/proxy-storage.js +20 -24
- package/dist/browser/runtime/sources.d.ts +23 -31
- package/dist/browser/runtime/sources.js +85 -103
- package/dist/browser/runtime/staging.d.ts +2 -6
- package/dist/browser/runtime/staging.js +7 -11
- package/dist/browser/runtime/still.d.ts +2 -6
- package/dist/browser/runtime/still.js +6 -12
- package/dist/browser/runtime/text.d.ts +14 -0
- package/dist/browser/runtime/text.js +27 -0
- package/dist/browser/runtime/wasm.d.ts +4 -5
- package/dist/browser/runtime/wasm.js +4 -5
- package/dist/browser/types.d.ts +233 -238
- package/dist/browser/worker.d.ts +8 -9
- package/dist/browser/worker.js +50 -21
- package/dist/core/captions.d.ts +8 -10
- package/dist/core/captions.js +10 -18
- package/dist/core/clip-time.d.ts +8 -10
- package/dist/core/clip-time.js +12 -15
- package/dist/core/commands.d.ts +46 -46
- package/dist/core/commands.js +38 -36
- package/dist/core/compositions.d.ts +78 -112
- package/dist/core/compositions.js +66 -94
- package/dist/core/document.d.ts +59 -92
- package/dist/core/document.js +64 -90
- package/dist/core/keyframes.d.ts +11 -12
- package/dist/core/keyframes.js +11 -13
- package/dist/core/presets.d.ts +14 -20
- package/dist/core/presets.js +12 -18
- package/dist/core/session.d.ts +26 -38
- package/dist/core/session.js +38 -53
- package/dist/core/text.d.ts +2 -3
- package/dist/core/text.js +2 -3
- package/dist/core/timeline-index.d.ts +2 -3
- package/dist/core/timeline-index.js +11 -7
- package/dist/core/transitions.js +4 -5
- package/dist/core/validated.d.ts +6 -7
- package/dist/core/validated.js +8 -11
- package/dist/native-client/index.d.ts +31 -32
- package/dist/native-client/index.js +40 -41
- package/dist/ports/index.d.ts +19 -20
- package/dist/react/index.d.ts +5 -6
- package/dist/react/index.js +5 -6
- package/package.json +4 -4
package/dist/core/document.js
CHANGED
|
@@ -2,11 +2,10 @@ import { frozenValid, knownValid, rememberValid, withValidated, } from "./valida
|
|
|
2
2
|
import { canonicalProject, validateProject, MAX_JSON_DEPTH, MAX_PROJECT_JSON_BYTES, } from "alpha2/project";
|
|
3
3
|
import { CAPTIONS_ASSET_KIND, validCaptionsAuthoring } from "./captions.js";
|
|
4
4
|
/**
|
|
5
|
-
* The export failure class each editor error code
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `tests/cases/failure-classes.json` holds the same table, and a test checks
|
|
9
|
-
* is in it.
|
|
5
|
+
* The export failure class each editor error code implies (`alpha2/export-failure`). Refusals of
|
|
6
|
+
* the document or its media are `INVALID_INPUT` (a retry meets them again), budget and storage
|
|
7
|
+
* refusals say so, and states that may pass (a busy export, a pending conform) are `UNKNOWN`.
|
|
8
|
+
* `tests/cases/failure-classes.json` holds the same table, and a test checks they agree.
|
|
10
9
|
*/
|
|
11
10
|
const EDITOR_FAILURE_CODES = Object.freeze({
|
|
12
11
|
audio_unavailable: "UNKNOWN",
|
|
@@ -16,6 +15,7 @@ const EDITOR_FAILURE_CODES = Object.freeze({
|
|
|
16
15
|
conform_pending: "UNKNOWN",
|
|
17
16
|
disposed: "UNKNOWN",
|
|
18
17
|
duplicate_resource: "INVALID_INPUT",
|
|
18
|
+
effect_unavailable: "INVALID_INPUT",
|
|
19
19
|
effect_conflict: "INVALID_INPUT",
|
|
20
20
|
empty_export: "INVALID_INPUT",
|
|
21
21
|
export_busy: "UNKNOWN",
|
|
@@ -33,12 +33,14 @@ const EDITOR_FAILURE_CODES = Object.freeze({
|
|
|
33
33
|
invalid_project: "INVALID_INPUT",
|
|
34
34
|
invalid_projection: "INVALID_INPUT",
|
|
35
35
|
invalid_rate: "INVALID_INPUT",
|
|
36
|
+
invalid_text: "INVALID_INPUT",
|
|
36
37
|
invalid_time: "INVALID_INPUT",
|
|
37
38
|
invalid_transition: "INVALID_INPUT",
|
|
38
39
|
invalid_video_conversion: "INVALID_INPUT",
|
|
39
40
|
invalid_video_decode: "INVALID_INPUT",
|
|
40
41
|
locked: "INVALID_INPUT",
|
|
41
42
|
missing_asset: "INVALID_INPUT",
|
|
43
|
+
preview_unavailable: "DEVICE_LOST",
|
|
42
44
|
preview_worker_failed: "UNKNOWN",
|
|
43
45
|
provider_stalled: "RESOURCE_LIMIT",
|
|
44
46
|
proxy_busy: "UNKNOWN",
|
|
@@ -79,8 +81,8 @@ export class EditorError extends Error {
|
|
|
79
81
|
this.name = "EditorError";
|
|
80
82
|
}
|
|
81
83
|
/**
|
|
82
|
-
* The export failure class this error
|
|
83
|
-
*
|
|
84
|
+
* The export failure class this error implies, read by `classifyBrowserFailure`. `UNKNOWN` for
|
|
85
|
+
* a code without a class.
|
|
84
86
|
*/
|
|
85
87
|
get failureCode() {
|
|
86
88
|
return Object.hasOwn(EDITOR_FAILURE_CODES, this.code)
|
|
@@ -90,7 +92,7 @@ export class EditorError extends Error {
|
|
|
90
92
|
}
|
|
91
93
|
/** Deep-freezes `value` in place and returns it. Already frozen objects are not descended into. */
|
|
92
94
|
export function freeze(value) {
|
|
93
|
-
//
|
|
95
|
+
// Iterative, so values nested deeper than the stack are frozen too.
|
|
94
96
|
const pending = [value];
|
|
95
97
|
const sealing = [];
|
|
96
98
|
while (pending.length) {
|
|
@@ -98,7 +100,7 @@ export function freeze(value) {
|
|
|
98
100
|
if (!next || typeof next !== "object" || Object.isFrozen(next))
|
|
99
101
|
continue;
|
|
100
102
|
sealing.push(next);
|
|
101
|
-
//
|
|
103
|
+
// Skip frozen children: most of an edit's result is frozen parts it kept.
|
|
102
104
|
for (const child of Object.values(next))
|
|
103
105
|
if (child && typeof child === "object" && !Object.isFrozen(child))
|
|
104
106
|
pending.push(child);
|
|
@@ -108,14 +110,13 @@ export function freeze(value) {
|
|
|
108
110
|
return value;
|
|
109
111
|
}
|
|
110
112
|
/**
|
|
111
|
-
* The deepest
|
|
112
|
-
*
|
|
113
|
+
* The deepest array and object nesting an editor document may have: the engine's project limit
|
|
114
|
+
* ({@link MAX_JSON_DEPTH}) plus one for the document that holds it.
|
|
113
115
|
*/
|
|
114
116
|
export const MAX_DOCUMENT_JSON_DEPTH = MAX_JSON_DEPTH + 1;
|
|
115
117
|
/**
|
|
116
|
-
* Throws an `EditorError` (`invalid_document`) unless `value` is plain JSON
|
|
117
|
-
*
|
|
118
|
-
* ({@link MAX_DOCUMENT_JSON_DEPTH} by default).
|
|
118
|
+
* Throws an `EditorError` (`invalid_document`) unless `value` is plain JSON (finite numbers, arrays
|
|
119
|
+
* and plain objects) nested at most `maxDepth` deep ({@link MAX_DOCUMENT_JSON_DEPTH} by default).
|
|
119
120
|
*/
|
|
120
121
|
export function assertJson(value, maxDepth = MAX_DOCUMENT_JSON_DEPTH) {
|
|
121
122
|
const pending = [[value, 0]];
|
|
@@ -138,22 +139,22 @@ export function assertJson(value, maxDepth = MAX_DOCUMENT_JSON_DEPTH) {
|
|
|
138
139
|
}
|
|
139
140
|
/**
|
|
140
141
|
* Throws an `EditorError` unless `document` is a valid editor document: finite JSON within the
|
|
141
|
-
* engine and editor
|
|
142
|
-
*
|
|
142
|
+
* engine and editor size limits, a supported format and version, a project the engine accepts,
|
|
143
|
+
* and well-formed editor metadata and assets.
|
|
143
144
|
*/
|
|
144
145
|
export function validateDocument(document) {
|
|
145
146
|
assertJson(document);
|
|
146
147
|
if (!isRecord(document))
|
|
147
148
|
throw new EditorError("invalid_document", "An editor document is an object", "validate");
|
|
148
|
-
// Size first
|
|
149
|
+
// Size first, since the engine reads no project over its budget.
|
|
149
150
|
assertDocumentSize(document);
|
|
150
151
|
validateDocumentShape(document);
|
|
151
152
|
assertEditorMetadata(document);
|
|
152
153
|
assertProjection(document);
|
|
153
154
|
}
|
|
154
155
|
/**
|
|
155
|
-
* Throws the first `invalid_projection` error of `document`'s projection (the project without
|
|
156
|
-
* disabled tracks
|
|
156
|
+
* Throws the first `invalid_projection` error of `document`'s projection (the project without
|
|
157
|
+
* disabled tracks), so a document that opens is one the engine renders.
|
|
157
158
|
*/
|
|
158
159
|
export function assertProjection(document) {
|
|
159
160
|
if (!document.project.timeline.tracks.some((t) => document.metadata.tracks[t.id]?.enabled === false))
|
|
@@ -164,16 +165,13 @@ export function assertProjection(document) {
|
|
|
164
165
|
}
|
|
165
166
|
/**
|
|
166
167
|
* The checks a gesture's candidate needs on every pointer move: the format and the project's
|
|
167
|
-
* rules.
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* `validateProject` reuses what it found of the frozen parts the candidate shares with the
|
|
171
|
-
* gesture's start. Throws an `EditorError` (`unsupported_version` or `invalid_project`).
|
|
168
|
+
* rules. The rest of `validateDocument` walks or serializes the whole document, so a gesture runs
|
|
169
|
+
* it once at commit. `validateProject` reuses its results for frozen parts the candidate shares
|
|
170
|
+
* with the gesture's start. Throws an `EditorError` (`unsupported_version` or `invalid_project`).
|
|
172
171
|
*/
|
|
173
172
|
export function validateDocumentShape(document) {
|
|
174
173
|
if (document.format !== "alpha2-editor-project" || document.version !== 1)
|
|
175
174
|
throw new EditorError("unsupported_version", "Unsupported editor format/version", "validate");
|
|
176
|
-
// A project the editor already validated is not walked again.
|
|
177
175
|
if (knownValid(document.project))
|
|
178
176
|
return;
|
|
179
177
|
const errors = validateProject(document.project);
|
|
@@ -184,10 +182,7 @@ export function validateDocumentShape(document) {
|
|
|
184
182
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
185
183
|
const optionalString = (value) => value === undefined || typeof value === "string";
|
|
186
184
|
const optionalBoolean = (value) => value === undefined || typeof value === "boolean";
|
|
187
|
-
/**
|
|
188
|
-
* The largest editor file {@link parseDocument} opens. Every document that validates fits it, as
|
|
189
|
-
* {@link serializeDocument} writes it.
|
|
190
|
-
*/
|
|
185
|
+
/** The largest editor file {@link parseDocument} opens; every valid document fits in it. */
|
|
191
186
|
export const MAX_EDITOR_FILE_BYTES = 128 * 1024 * 1024;
|
|
192
187
|
const utf8Length = (text) => new TextEncoder().encode(text).length;
|
|
193
188
|
function assertDocumentSize(document) {
|
|
@@ -197,8 +192,8 @@ function assertDocumentSize(document) {
|
|
|
197
192
|
throw new EditorError("too_large", "Editor document exceeds the 128 MiB file limit", "validate");
|
|
198
193
|
}
|
|
199
194
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
195
|
+
* The only color form accepted for markers and tracks, since a view paints it and other CSS values
|
|
196
|
+
* may load a resource.
|
|
202
197
|
*/
|
|
203
198
|
const COLOR = /^#[0-9a-f]{6}$/i;
|
|
204
199
|
const isColor = (value) => typeof value === "string" && COLOR.test(value);
|
|
@@ -209,7 +204,7 @@ function assertEditorMetadata(document) {
|
|
|
209
204
|
!Array.isArray(document.metadata.markers) ||
|
|
210
205
|
!isRecord(document.assets))
|
|
211
206
|
throw new EditorError("invalid_metadata", "Missing editor metadata", "validate");
|
|
212
|
-
// A non-string here
|
|
207
|
+
// A non-string here would crash the whole page that renders it.
|
|
213
208
|
const { tracks, clips, instanceIds } = document.metadata;
|
|
214
209
|
if (!isRecord(tracks) || !isRecord(clips) || !isRecord(instanceIds))
|
|
215
210
|
throw new EditorError("invalid_metadata", "Editor metadata maps must be objects", "validate");
|
|
@@ -238,7 +233,7 @@ function assertEditorMetadata(document) {
|
|
|
238
233
|
!(isRecord(graphNames) &&
|
|
239
234
|
Object.values(graphNames).every((name) => typeof name === "string")))
|
|
240
235
|
throw new EditorError("invalid_metadata", "Group names must be text by composition", "validate");
|
|
241
|
-
// A transition's id is the edge it joins, so a command
|
|
236
|
+
// A transition's id is the edge it joins, so a command can name the transition it means.
|
|
242
237
|
for (const track of document.project.timeline.tracks) {
|
|
243
238
|
const ids = instanceIds[`${track.id}/transitions`] ?? [];
|
|
244
239
|
const transitions = track.transitions ?? [];
|
|
@@ -255,8 +250,7 @@ function assertEditorMetadata(document) {
|
|
|
255
250
|
if (asset.kind === CAPTIONS_ASSET_KIND &&
|
|
256
251
|
!validCaptionsAuthoring(asset.authoring))
|
|
257
252
|
throw new EditorError("invalid_asset", "Invalid captions: each row must be a list of cues", "validate", id);
|
|
258
|
-
// `authoring.text` is a text asset's style; other assets
|
|
259
|
-
// contents (a string) there.
|
|
253
|
+
// `authoring.text` is a text asset's style; other assets hold `null` or a file's contents.
|
|
260
254
|
const text = isRecord(asset.authoring) ? asset.authoring.text : undefined;
|
|
261
255
|
if (typeof asset.name !== "string" ||
|
|
262
256
|
typeof asset.kind !== "string" ||
|
|
@@ -294,13 +288,13 @@ function assertEditorMetadata(document) {
|
|
|
294
288
|
}
|
|
295
289
|
/**
|
|
296
290
|
* A new frozen document holding a copy of `project`, with an asset for each source and effect
|
|
297
|
-
* resource (offline unless generated or a composition) overridden by `assets`. Throws an
|
|
291
|
+
* resource (offline unless generated or a composition), overridden by `assets`. Throws an
|
|
298
292
|
* `EditorError` when the result does not validate.
|
|
299
293
|
*/
|
|
300
294
|
export function createDocument(project, assets = {}) {
|
|
301
295
|
return withValidated(() => {
|
|
302
296
|
assertJson(project, MAX_JSON_DEPTH);
|
|
303
|
-
//
|
|
297
|
+
// Freeze before validation so validated parts are reused when edits check them.
|
|
304
298
|
const copy = freeze(canonicalProject(structuredClone(project)));
|
|
305
299
|
if (!knownValid(project)) {
|
|
306
300
|
const errors = validateProject(copy);
|
|
@@ -359,18 +353,17 @@ export function createEmptyDocument(settings = {}) {
|
|
|
359
353
|
});
|
|
360
354
|
}
|
|
361
355
|
/**
|
|
362
|
-
*
|
|
363
|
-
*
|
|
356
|
+
* Serializes `document` as compact JSON that {@link parseDocument} opens. Throws an `EditorError`
|
|
357
|
+
* when the document does not validate.
|
|
364
358
|
*/
|
|
365
359
|
export function serializeDocument(document) {
|
|
366
360
|
validateDocument(document);
|
|
367
361
|
return JSON.stringify(document);
|
|
368
362
|
}
|
|
369
363
|
/**
|
|
370
|
-
* Opens an editor file, or a bare engine project (JSON with `schema_version`) as a new document
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* and the code of the check a document (or project) fails otherwise.
|
|
364
|
+
* Opens an editor file, or a bare engine project (JSON with `schema_version`) as a new document,
|
|
365
|
+
* frozen. Every refusal is an `EditorError`: `too_large` past {@link MAX_EDITOR_FILE_BYTES},
|
|
366
|
+
* `invalid_document` for text that is not an editor document, else the code of the failed check.
|
|
374
367
|
*/
|
|
375
368
|
export function parseDocument(text) {
|
|
376
369
|
if (utf8Length(text) > MAX_EDITOR_FILE_BYTES)
|
|
@@ -392,25 +385,22 @@ export function parseDocument(text) {
|
|
|
392
385
|
catch (cause) {
|
|
393
386
|
if (cause instanceof EditorError)
|
|
394
387
|
throw cause;
|
|
395
|
-
//
|
|
388
|
+
// An unforeseen shape is still a fault of the file, not the editor.
|
|
396
389
|
throw new EditorError("invalid_document", `Editor file could not be read: ${cause instanceof Error ? cause.message : String(cause)}`, "open", undefined, true, { cause });
|
|
397
390
|
}
|
|
398
391
|
}
|
|
399
392
|
/**
|
|
400
|
-
* The id of `transition` on track `trackId`: the edge it joins
|
|
401
|
-
*
|
|
402
|
-
*
|
|
393
|
+
* The id of `transition` on track `trackId`: the edge it joins (a track has one transition per
|
|
394
|
+
* edge). It is stable while other transitions change, and changes with its clips (a split hands
|
|
395
|
+
* an outgoing transition to the right part).
|
|
403
396
|
*/
|
|
404
397
|
export function transitionInstanceId(trackId, transition) {
|
|
405
398
|
return `${trackId}/transitions/${encodeURIComponent(transition.from_clip)}/${encodeURIComponent(transition.to_clip)}`;
|
|
406
399
|
}
|
|
407
400
|
/**
|
|
408
|
-
* `document` with its project in the forms the engine writes ({@link canonicalProject})
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
* that are, and leaves a document of the wrong shape, or a value it cannot read, for validation to
|
|
412
|
-
* refuse. Each place a document enters the editor puts it in this form, so the editor's own code
|
|
413
|
-
* and its callers read one form.
|
|
401
|
+
* `document` with its project in the forms the engine writes ({@link canonicalProject}). Returns
|
|
402
|
+
* `document` itself when already canonical and shares unchanged parts. A document of the wrong
|
|
403
|
+
* shape is left for validation to refuse.
|
|
414
404
|
*/
|
|
415
405
|
export function canonicalDocument(document) {
|
|
416
406
|
const project = document?.project;
|
|
@@ -421,25 +411,21 @@ export function canonicalDocument(document) {
|
|
|
421
411
|
? document
|
|
422
412
|
: { ...document, project: canonical };
|
|
423
413
|
}
|
|
424
|
-
/**
|
|
425
|
-
* Frozen tracks and clips {@link withInstanceIds} found named as they are in a frozen `instanceIds`
|
|
426
|
-
* record.
|
|
427
|
-
*/
|
|
414
|
+
/** Frozen tracks and clips {@link withInstanceIds} found fully named in a frozen `instanceIds`. */
|
|
428
415
|
const namedIn = new WeakMap();
|
|
429
416
|
/**
|
|
430
|
-
* `document` with an instance id for every caption cue, transition and clip mask
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
* changes, and leaves a document of the wrong shape for validation to refuse.
|
|
417
|
+
* `document` with an instance id for every caption cue, transition and clip mask. Transitions are
|
|
418
|
+
* named by {@link transitionInstanceId}; cues and masks keep their ids and new ones get unique ids.
|
|
419
|
+
* Returns `document` itself when nothing changes, and leaves a malformed document for validation.
|
|
434
420
|
*/
|
|
435
421
|
export function withInstanceIds(document) {
|
|
436
422
|
const tracks = document?.project?.timeline?.tracks;
|
|
437
423
|
const original = document?.metadata?.instanceIds;
|
|
438
424
|
if (!Array.isArray(tracks) || !isRecord(original))
|
|
439
425
|
return document;
|
|
440
|
-
//
|
|
426
|
+
// Checked once, since the check is linear in the record's keys.
|
|
441
427
|
const lasting = Object.isFrozen(original);
|
|
442
|
-
// Copied on the first change
|
|
428
|
+
// Copied on the first change; a copy per changed key would be O(n^2) over n clips.
|
|
443
429
|
let changed;
|
|
444
430
|
const current = (key) => (changed ?? original)[key];
|
|
445
431
|
const set = (key, values) => {
|
|
@@ -450,9 +436,7 @@ export function withInstanceIds(document) {
|
|
|
450
436
|
return;
|
|
451
437
|
(changed ??= { ...original })[key] = values;
|
|
452
438
|
};
|
|
453
|
-
/**
|
|
454
|
-
* The ids a list of `count` keeps, `<key>/<index>` (numbered past one taken) for the new ones.
|
|
455
|
-
*/
|
|
439
|
+
/** The ids a list of `count` keeps; new ones are `<key>/<index>`, numbered past taken ones. */
|
|
456
440
|
const kept = (key, count) => {
|
|
457
441
|
const previous = current(key);
|
|
458
442
|
const ids = (Array.isArray(previous) ? previous : [])
|
|
@@ -472,7 +456,6 @@ export function withInstanceIds(document) {
|
|
|
472
456
|
for (const track of tracks) {
|
|
473
457
|
if (!isRecord(track) || typeof track.id !== "string")
|
|
474
458
|
return document;
|
|
475
|
-
// A track whose ids are unchanged in this frozen record needs nothing.
|
|
476
459
|
if (changed === undefined && namedIn.get(track) === original)
|
|
477
460
|
continue;
|
|
478
461
|
const transitions = track.transitions ?? [];
|
|
@@ -548,11 +531,9 @@ export function indexDocument(document) {
|
|
|
548
531
|
// A frozen document never changes, so its projection is computed once.
|
|
549
532
|
const compiled = new WeakMap();
|
|
550
533
|
/**
|
|
551
|
-
* The project the engine renders for `document
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* as their matte draws nothing but still plays. Never throws for an invalid projection; the errors
|
|
555
|
-
* are in `diagnostics`. Cached for frozen documents.
|
|
534
|
+
* The project the engine renders for `document`; see `projectedTracks` for how disabled tracks
|
|
535
|
+
* project. Never throws for an invalid projection; the errors are in `diagnostics`. Cached for
|
|
536
|
+
* frozen documents.
|
|
556
537
|
*/
|
|
557
538
|
export function compileEditorDocument(document) {
|
|
558
539
|
const cached = compiled.get(document);
|
|
@@ -563,10 +544,7 @@ export function compileEditorDocument(document) {
|
|
|
563
544
|
compiled.set(document, result);
|
|
564
545
|
return result;
|
|
565
546
|
}
|
|
566
|
-
/**
|
|
567
|
-
* Where `project`'s timeline ends, in ticks: the end of its last clip or caption cue, 0 when it has
|
|
568
|
-
* neither.
|
|
569
|
-
*/
|
|
547
|
+
/** End of `project`'s timeline in ticks: its last clip or caption cue, or 0 when empty. */
|
|
570
548
|
export function sequenceEnd(project) {
|
|
571
549
|
let end = 0;
|
|
572
550
|
for (const track of project.timeline.tracks) {
|
|
@@ -578,21 +556,18 @@ export function sequenceEnd(project) {
|
|
|
578
556
|
return end;
|
|
579
557
|
}
|
|
580
558
|
/**
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
* start set runs to it.
|
|
559
|
+
* End of `document`'s program in ticks: the {@link sequenceEnd} of its projection, so disabled
|
|
560
|
+
* tracks add no length. Playback and export without an export range stop there, and so does a
|
|
561
|
+
* range with only its start set.
|
|
585
562
|
*/
|
|
586
563
|
export function programEnd(document) {
|
|
587
564
|
return sequenceEnd(compileEditorDocument(document).project);
|
|
588
565
|
}
|
|
589
566
|
/**
|
|
590
|
-
* The tracks the engine renders of `document`. A disabled track draws and plays nothing, but
|
|
591
|
-
*
|
|
592
|
-
* nothing
|
|
593
|
-
*
|
|
594
|
-
* under silence, so it does not duck. A clip that only disabled clips name as their matte is still
|
|
595
|
-
* a matte: it is not drawn (no opacity), and it plays as before.
|
|
567
|
+
* The tracks the engine renders of `document`. A disabled track draws and plays nothing, but keeps
|
|
568
|
+
* the clips enabled tracks name as mattes, muted. Mattes only set coverage and are never
|
|
569
|
+
* composited, so nothing of the track draws. A track that ducks under a disabled track does not
|
|
570
|
+
* duck. A clip only disabled clips name as their matte stays a matte: not drawn, still playing.
|
|
596
571
|
*/
|
|
597
572
|
function projectedTracks(document) {
|
|
598
573
|
const tracks = document.project.timeline.tracks;
|
|
@@ -605,8 +580,7 @@ function projectedTracks(document) {
|
|
|
605
580
|
.filter((t) => disabled.has(t.id) !== enabled)
|
|
606
581
|
.flatMap((t) => (t.clips ?? []).flatMap((c) => c.matte?.source ?? [])));
|
|
607
582
|
const mattes = named(true);
|
|
608
|
-
// Named by hidden clips
|
|
609
|
-
// draw it as an ordinary clip.
|
|
583
|
+
// Named only by hidden clips, which the projection drops, so the engine would draw it plainly.
|
|
610
584
|
const orphaned = new Set([...named(false)].filter((id) => !mattes.has(id)));
|
|
611
585
|
return tracks.flatMap((track) => {
|
|
612
586
|
if (disabled.has(track.id)) {
|
|
@@ -674,8 +648,8 @@ function compileProjection(document) {
|
|
|
674
648
|
};
|
|
675
649
|
}
|
|
676
650
|
/**
|
|
677
|
-
* Seeds the {@link indexDocument} cache of `next` from
|
|
678
|
-
*
|
|
651
|
+
* Seeds the {@link indexDocument} cache of `next` from `previous`, rebuilding only changed tracks.
|
|
652
|
+
* Does nothing when `previous` has no index.
|
|
679
653
|
*/
|
|
680
654
|
export function inheritDocumentIndex(previous, next) {
|
|
681
655
|
const prior = indexes.get(previous);
|
package/dist/core/keyframes.d.ts
CHANGED
|
@@ -30,23 +30,23 @@ export declare const EASINGS: {
|
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
|
-
* The keyframe at `from` moved to `to`,
|
|
34
|
-
*
|
|
33
|
+
* The keyframe at `from` moved to `to`, clamped a tick inside its neighbours so keyframe order
|
|
34
|
+
* never changes. Returns the value and where the keyframe landed.
|
|
35
35
|
*
|
|
36
|
-
* Throws when `value` is not keyframed or has no keyframe at `from
|
|
36
|
+
* Throws when `value` is not keyframed or has no keyframe at `from`; the other keyframe-editing
|
|
37
37
|
* functions below throw in the same cases.
|
|
38
38
|
*/
|
|
39
39
|
export declare function moveKeyframe<T>(value: Animated<T>, from: number, to: number): {
|
|
40
40
|
readonly value: Animated<T>;
|
|
41
41
|
readonly time: number;
|
|
42
42
|
};
|
|
43
|
-
/** The keyframe at `time` removed; the last one
|
|
43
|
+
/** The keyframe at `time` removed; removing the last one leaves its value as a constant. */
|
|
44
44
|
export declare function removeKeyframe<T>(value: Animated<T>, time: number): Animated<T>;
|
|
45
45
|
/** How the keyframe at `time` eases to the next. */
|
|
46
46
|
export declare function setInterpolation<T>(value: Animated<T>, time: number, interpolation: Interpolation): Animated<T>;
|
|
47
47
|
/**
|
|
48
|
-
* The timing curve from the keyframe at `time` to the next, as
|
|
49
|
-
*
|
|
48
|
+
* The timing curve from the keyframe at `time` to the next, as two Bezier handles: `x` in `0..=1`
|
|
49
|
+
* of the time, `y` any fraction of the value change (beyond `0..=1` overshoots).
|
|
50
50
|
*/
|
|
51
51
|
export declare function setHandles<T>(value: Animated<T>, time: number, handles: {
|
|
52
52
|
x1: number;
|
|
@@ -57,8 +57,8 @@ export declare function setHandles<T>(value: Animated<T>, time: number, handles:
|
|
|
57
57
|
/** The keyframe at `time` given `next` as its value. */
|
|
58
58
|
export declare function setKeyframeValue<T>(value: Animated<T>, time: number, next: T): Animated<T>;
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
61
|
-
* straight line's (
|
|
60
|
+
* A timing curve's handles for a curve editor: a Bezier's own, or for a linear segment the
|
|
61
|
+
* straight line's (at one and two thirds). A held segment has none.
|
|
62
62
|
*/
|
|
63
63
|
export declare function handlesOf(interpolation: Interpolation): {
|
|
64
64
|
x1: number;
|
|
@@ -68,10 +68,9 @@ export declare function handlesOf(interpolation: Interpolation): {
|
|
|
68
68
|
} | null;
|
|
69
69
|
/**
|
|
70
70
|
* A CSS `cubic-bezier(x1, y1, x2, y2)` curve's output at linear `progress` (clamped to `0..=1`),
|
|
71
|
-
* bit for bit as the engine
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* that shows a keyframed value takes it from here, so it shows what the render draws.
|
|
71
|
+
* bit for bit as the engine's `CubicBezier::apply`: handles as 32-bit floats, Newton from
|
|
72
|
+
* `t = progress` while it stays on the curve, then bisection for flat curves. Displays of keyframed
|
|
73
|
+
* values should use this so they match the render.
|
|
75
74
|
*/
|
|
76
75
|
export declare function cubicBezierAt(curve: {
|
|
77
76
|
x1: number;
|
package/dist/core/keyframes.js
CHANGED
|
@@ -16,10 +16,10 @@ function indexAt(keys, time) {
|
|
|
16
16
|
return index;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* The keyframe at `from` moved to `to`,
|
|
20
|
-
*
|
|
19
|
+
* The keyframe at `from` moved to `to`, clamped a tick inside its neighbours so keyframe order
|
|
20
|
+
* never changes. Returns the value and where the keyframe landed.
|
|
21
21
|
*
|
|
22
|
-
* Throws when `value` is not keyframed or has no keyframe at `from
|
|
22
|
+
* Throws when `value` is not keyframed or has no keyframe at `from`; the other keyframe-editing
|
|
23
23
|
* functions below throw in the same cases.
|
|
24
24
|
*/
|
|
25
25
|
export function moveKeyframe(value, from, to) {
|
|
@@ -31,7 +31,7 @@ export function moveKeyframe(value, from, to) {
|
|
|
31
31
|
keys[index] = { ...keys[index], time };
|
|
32
32
|
return { value: { mode: "keyframes", keyframes: keys }, time };
|
|
33
33
|
}
|
|
34
|
-
/** The keyframe at `time` removed; the last one
|
|
34
|
+
/** The keyframe at `time` removed; removing the last one leaves its value as a constant. */
|
|
35
35
|
export function removeKeyframe(value, time) {
|
|
36
36
|
const keys = keyframesOf(value);
|
|
37
37
|
const [removed] = keys.splice(indexAt(keys, time), 1);
|
|
@@ -47,8 +47,8 @@ export function setInterpolation(value, time, interpolation) {
|
|
|
47
47
|
return { mode: "keyframes", keyframes: keys };
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
* The timing curve from the keyframe at `time` to the next, as
|
|
51
|
-
*
|
|
50
|
+
* The timing curve from the keyframe at `time` to the next, as two Bezier handles: `x` in `0..=1`
|
|
51
|
+
* of the time, `y` any fraction of the value change (beyond `0..=1` overshoots).
|
|
52
52
|
*/
|
|
53
53
|
export function setHandles(value, time, handles) {
|
|
54
54
|
const clampX = (x) => Math.min(1, Math.max(0, x));
|
|
@@ -68,8 +68,8 @@ export function setKeyframeValue(value, time, next) {
|
|
|
68
68
|
return { mode: "keyframes", keyframes: keys };
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
* straight line's (
|
|
71
|
+
* A timing curve's handles for a curve editor: a Bezier's own, or for a linear segment the
|
|
72
|
+
* straight line's (at one and two thirds). A held segment has none.
|
|
73
73
|
*/
|
|
74
74
|
export function handlesOf(interpolation) {
|
|
75
75
|
if (interpolation.type === "cubic_bezier")
|
|
@@ -83,7 +83,6 @@ export function handlesOf(interpolation) {
|
|
|
83
83
|
return { x1: 1 / 3, y1: 1 / 3, x2: 2 / 3, y2: 2 / 3 };
|
|
84
84
|
return null;
|
|
85
85
|
}
|
|
86
|
-
/** Newton steps tried before bisection takes over. */
|
|
87
86
|
const NEWTON_STEPS = 8;
|
|
88
87
|
/** Bisection halvings; 2^-64 is far below the tolerance. */
|
|
89
88
|
const BISECTION_STEPS = 64;
|
|
@@ -93,10 +92,9 @@ const TOLERANCE = 1e-12;
|
|
|
93
92
|
const MIN_SLOPE = 1e-9;
|
|
94
93
|
/**
|
|
95
94
|
* A CSS `cubic-bezier(x1, y1, x2, y2)` curve's output at linear `progress` (clamped to `0..=1`),
|
|
96
|
-
* bit for bit as the engine
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* that shows a keyframed value takes it from here, so it shows what the render draws.
|
|
95
|
+
* bit for bit as the engine's `CubicBezier::apply`: handles as 32-bit floats, Newton from
|
|
96
|
+
* `t = progress` while it stays on the curve, then bisection for flat curves. Displays of keyframed
|
|
97
|
+
* values should use this so they match the render.
|
|
100
98
|
*/
|
|
101
99
|
export function cubicBezierAt(curve, progress) {
|
|
102
100
|
const x = Math.min(1, Math.max(0, progress));
|
package/dist/core/presets.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { Composition, EffectResource, MediaSource, Project } from "alpha2/p
|
|
|
2
2
|
import type { Command } from "./commands.js";
|
|
3
3
|
import type { EditorDocument } from "./document.js";
|
|
4
4
|
/**
|
|
5
|
-
* A reusable group: the composition a group node draws, the compositions it uses
|
|
6
|
-
*
|
|
5
|
+
* A reusable group: the composition a group node draws, the compositions it uses, and what it needs
|
|
6
|
+
* from the target project. Saved outside any project, as JSON.
|
|
7
7
|
*/
|
|
8
8
|
export interface GraphPreset {
|
|
9
9
|
readonly format: "alpha2-graph-preset";
|
|
@@ -23,41 +23,35 @@ export interface GraphPreset {
|
|
|
23
23
|
}
|
|
24
24
|
/** What a preset needs that a project lacks. */
|
|
25
25
|
export interface PresetShortfall {
|
|
26
|
-
/**
|
|
26
|
+
/** Ids of sources its media nodes read that the project lacks. */
|
|
27
27
|
readonly sources: readonly string[];
|
|
28
|
-
/**
|
|
28
|
+
/** Ids of effect resources (LUTs) its effects use that the project lacks. */
|
|
29
29
|
readonly resources: readonly string[];
|
|
30
30
|
/** Effects the engine does not run, as `id@version`. */
|
|
31
31
|
readonly effects: readonly string[];
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
* The preset of composition `id`, as a group node would draw it: it, every composition it uses, and
|
|
35
|
-
* the sources, resources, and effects they read.
|
|
36
|
-
*/
|
|
33
|
+
/** The preset of composition `id`: it, every composition it uses, and what they read. */
|
|
37
34
|
export declare function graphPreset(project: Project, id: string, name: string): GraphPreset;
|
|
38
35
|
/**
|
|
39
36
|
* What `preset` needs that `document`'s project lacks: file-backed sources and effect resources by
|
|
40
|
-
* id (
|
|
41
|
-
* not have.
|
|
37
|
+
* id (composition sources it brings are not missing), and effects `runs` says the engine lacks.
|
|
42
38
|
*/
|
|
43
39
|
export declare function presetShortfall(document: EditorDocument, preset: GraphPreset, runs: (id: string, version: number) => boolean): PresetShortfall;
|
|
44
40
|
/**
|
|
45
|
-
* The command
|
|
46
|
-
* compositions
|
|
47
|
-
* `position`
|
|
48
|
-
*
|
|
49
|
-
* may still be refused when executed.
|
|
41
|
+
* The command placing `preset` in composition `compositionId` as one undoable edit: its
|
|
42
|
+
* compositions under free ids and an unconnected group node `groupId` drawing the first, at
|
|
43
|
+
* `position`. Returns `null` when the preset has no composition or `compositionId` does not exist;
|
|
44
|
+
* the command may still be refused when executed.
|
|
50
45
|
*/
|
|
51
46
|
export declare function placeGraphPreset(document: EditorDocument, preset: GraphPreset, compositionId: string, groupId: string, position?: {
|
|
52
47
|
readonly x: number;
|
|
53
48
|
readonly y: number;
|
|
54
49
|
}): Command | null;
|
|
55
50
|
/**
|
|
56
|
-
* The command
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* for an unknown clip.
|
|
51
|
+
* The command applying `preset` to clip `clipId` as one undoable edit: its compositions under free
|
|
52
|
+
* ids, and a group node drawing the first placed after the clip composition's output (reading it
|
|
53
|
+
* if the group has an input) and made the output. A clip without a composition gets one. Returns
|
|
54
|
+
* `null` for an unknown clip or a preset with more than one input.
|
|
61
55
|
*/
|
|
62
56
|
export declare function applyGraphPreset(document: EditorDocument, preset: GraphPreset, clipId: string, ids: {
|
|
63
57
|
readonly groupId: string;
|