@alpha2-sh/editor 0.4.6 → 0.5.1
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 +393 -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 +52 -28
- package/dist/browser/runtime/assets.js +136 -45
- package/dist/browser/runtime/audio.d.ts +16 -11
- package/dist/browser/runtime/audio.js +102 -59
- 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 +44 -44
- package/dist/browser/runtime/engine.js +87 -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 +19 -19
- package/dist/browser/runtime/proxies.js +72 -51
- 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 +244 -239
- package/dist/browser/worker.d.ts +10 -10
- package/dist/browser/worker.js +64 -22
- 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 +65 -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,15 +33,18 @@ 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",
|
|
47
|
+
proxy_stalled: "UNKNOWN",
|
|
45
48
|
relink_conflict: "INVALID_INPUT",
|
|
46
49
|
resource_budget: "RESOURCE_LIMIT",
|
|
47
50
|
resource_limit: "RESOURCE_LIMIT",
|
|
@@ -79,8 +82,8 @@ export class EditorError extends Error {
|
|
|
79
82
|
this.name = "EditorError";
|
|
80
83
|
}
|
|
81
84
|
/**
|
|
82
|
-
* The export failure class this error
|
|
83
|
-
*
|
|
85
|
+
* The export failure class this error implies, read by `classifyBrowserFailure`. `UNKNOWN` for
|
|
86
|
+
* a code without a class.
|
|
84
87
|
*/
|
|
85
88
|
get failureCode() {
|
|
86
89
|
return Object.hasOwn(EDITOR_FAILURE_CODES, this.code)
|
|
@@ -90,7 +93,7 @@ export class EditorError extends Error {
|
|
|
90
93
|
}
|
|
91
94
|
/** Deep-freezes `value` in place and returns it. Already frozen objects are not descended into. */
|
|
92
95
|
export function freeze(value) {
|
|
93
|
-
//
|
|
96
|
+
// Iterative, so values nested deeper than the stack are frozen too.
|
|
94
97
|
const pending = [value];
|
|
95
98
|
const sealing = [];
|
|
96
99
|
while (pending.length) {
|
|
@@ -98,7 +101,7 @@ export function freeze(value) {
|
|
|
98
101
|
if (!next || typeof next !== "object" || Object.isFrozen(next))
|
|
99
102
|
continue;
|
|
100
103
|
sealing.push(next);
|
|
101
|
-
//
|
|
104
|
+
// Skip frozen children: most of an edit's result is frozen parts it kept.
|
|
102
105
|
for (const child of Object.values(next))
|
|
103
106
|
if (child && typeof child === "object" && !Object.isFrozen(child))
|
|
104
107
|
pending.push(child);
|
|
@@ -108,14 +111,13 @@ export function freeze(value) {
|
|
|
108
111
|
return value;
|
|
109
112
|
}
|
|
110
113
|
/**
|
|
111
|
-
* The deepest
|
|
112
|
-
*
|
|
114
|
+
* The deepest array and object nesting an editor document may have: the engine's project limit
|
|
115
|
+
* ({@link MAX_JSON_DEPTH}) plus one for the document that holds it.
|
|
113
116
|
*/
|
|
114
117
|
export const MAX_DOCUMENT_JSON_DEPTH = MAX_JSON_DEPTH + 1;
|
|
115
118
|
/**
|
|
116
|
-
* Throws an `EditorError` (`invalid_document`) unless `value` is plain JSON
|
|
117
|
-
*
|
|
118
|
-
* ({@link MAX_DOCUMENT_JSON_DEPTH} by default).
|
|
119
|
+
* Throws an `EditorError` (`invalid_document`) unless `value` is plain JSON (finite numbers, arrays
|
|
120
|
+
* and plain objects) nested at most `maxDepth` deep ({@link MAX_DOCUMENT_JSON_DEPTH} by default).
|
|
119
121
|
*/
|
|
120
122
|
export function assertJson(value, maxDepth = MAX_DOCUMENT_JSON_DEPTH) {
|
|
121
123
|
const pending = [[value, 0]];
|
|
@@ -138,22 +140,22 @@ export function assertJson(value, maxDepth = MAX_DOCUMENT_JSON_DEPTH) {
|
|
|
138
140
|
}
|
|
139
141
|
/**
|
|
140
142
|
* Throws an `EditorError` unless `document` is a valid editor document: finite JSON within the
|
|
141
|
-
* engine and editor
|
|
142
|
-
*
|
|
143
|
+
* engine and editor size limits, a supported format and version, a project the engine accepts,
|
|
144
|
+
* and well-formed editor metadata and assets.
|
|
143
145
|
*/
|
|
144
146
|
export function validateDocument(document) {
|
|
145
147
|
assertJson(document);
|
|
146
148
|
if (!isRecord(document))
|
|
147
149
|
throw new EditorError("invalid_document", "An editor document is an object", "validate");
|
|
148
|
-
// Size first
|
|
150
|
+
// Size first, since the engine reads no project over its budget.
|
|
149
151
|
assertDocumentSize(document);
|
|
150
152
|
validateDocumentShape(document);
|
|
151
153
|
assertEditorMetadata(document);
|
|
152
154
|
assertProjection(document);
|
|
153
155
|
}
|
|
154
156
|
/**
|
|
155
|
-
* Throws the first `invalid_projection` error of `document`'s projection (the project without
|
|
156
|
-
* disabled tracks
|
|
157
|
+
* Throws the first `invalid_projection` error of `document`'s projection (the project without
|
|
158
|
+
* disabled tracks), so a document that opens is one the engine renders.
|
|
157
159
|
*/
|
|
158
160
|
export function assertProjection(document) {
|
|
159
161
|
if (!document.project.timeline.tracks.some((t) => document.metadata.tracks[t.id]?.enabled === false))
|
|
@@ -164,16 +166,13 @@ export function assertProjection(document) {
|
|
|
164
166
|
}
|
|
165
167
|
/**
|
|
166
168
|
* 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`).
|
|
169
|
+
* rules. The rest of `validateDocument` walks or serializes the whole document, so a gesture runs
|
|
170
|
+
* it once at commit. `validateProject` reuses its results for frozen parts the candidate shares
|
|
171
|
+
* with the gesture's start. Throws an `EditorError` (`unsupported_version` or `invalid_project`).
|
|
172
172
|
*/
|
|
173
173
|
export function validateDocumentShape(document) {
|
|
174
174
|
if (document.format !== "alpha2-editor-project" || document.version !== 1)
|
|
175
175
|
throw new EditorError("unsupported_version", "Unsupported editor format/version", "validate");
|
|
176
|
-
// A project the editor already validated is not walked again.
|
|
177
176
|
if (knownValid(document.project))
|
|
178
177
|
return;
|
|
179
178
|
const errors = validateProject(document.project);
|
|
@@ -184,10 +183,7 @@ export function validateDocumentShape(document) {
|
|
|
184
183
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
185
184
|
const optionalString = (value) => value === undefined || typeof value === "string";
|
|
186
185
|
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
|
-
*/
|
|
186
|
+
/** The largest editor file {@link parseDocument} opens; every valid document fits in it. */
|
|
191
187
|
export const MAX_EDITOR_FILE_BYTES = 128 * 1024 * 1024;
|
|
192
188
|
const utf8Length = (text) => new TextEncoder().encode(text).length;
|
|
193
189
|
function assertDocumentSize(document) {
|
|
@@ -197,8 +193,8 @@ function assertDocumentSize(document) {
|
|
|
197
193
|
throw new EditorError("too_large", "Editor document exceeds the 128 MiB file limit", "validate");
|
|
198
194
|
}
|
|
199
195
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
196
|
+
* The only color form accepted for markers and tracks, since a view paints it and other CSS values
|
|
197
|
+
* may load a resource.
|
|
202
198
|
*/
|
|
203
199
|
const COLOR = /^#[0-9a-f]{6}$/i;
|
|
204
200
|
const isColor = (value) => typeof value === "string" && COLOR.test(value);
|
|
@@ -209,7 +205,7 @@ function assertEditorMetadata(document) {
|
|
|
209
205
|
!Array.isArray(document.metadata.markers) ||
|
|
210
206
|
!isRecord(document.assets))
|
|
211
207
|
throw new EditorError("invalid_metadata", "Missing editor metadata", "validate");
|
|
212
|
-
// A non-string here
|
|
208
|
+
// A non-string here would crash the whole page that renders it.
|
|
213
209
|
const { tracks, clips, instanceIds } = document.metadata;
|
|
214
210
|
if (!isRecord(tracks) || !isRecord(clips) || !isRecord(instanceIds))
|
|
215
211
|
throw new EditorError("invalid_metadata", "Editor metadata maps must be objects", "validate");
|
|
@@ -238,7 +234,7 @@ function assertEditorMetadata(document) {
|
|
|
238
234
|
!(isRecord(graphNames) &&
|
|
239
235
|
Object.values(graphNames).every((name) => typeof name === "string")))
|
|
240
236
|
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
|
|
237
|
+
// A transition's id is the edge it joins, so a command can name the transition it means.
|
|
242
238
|
for (const track of document.project.timeline.tracks) {
|
|
243
239
|
const ids = instanceIds[`${track.id}/transitions`] ?? [];
|
|
244
240
|
const transitions = track.transitions ?? [];
|
|
@@ -255,8 +251,7 @@ function assertEditorMetadata(document) {
|
|
|
255
251
|
if (asset.kind === CAPTIONS_ASSET_KIND &&
|
|
256
252
|
!validCaptionsAuthoring(asset.authoring))
|
|
257
253
|
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.
|
|
254
|
+
// `authoring.text` is a text asset's style; other assets hold `null` or a file's contents.
|
|
260
255
|
const text = isRecord(asset.authoring) ? asset.authoring.text : undefined;
|
|
261
256
|
if (typeof asset.name !== "string" ||
|
|
262
257
|
typeof asset.kind !== "string" ||
|
|
@@ -294,13 +289,13 @@ function assertEditorMetadata(document) {
|
|
|
294
289
|
}
|
|
295
290
|
/**
|
|
296
291
|
* 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
|
|
292
|
+
* resource (offline unless generated or a composition), overridden by `assets`. Throws an
|
|
298
293
|
* `EditorError` when the result does not validate.
|
|
299
294
|
*/
|
|
300
295
|
export function createDocument(project, assets = {}) {
|
|
301
296
|
return withValidated(() => {
|
|
302
297
|
assertJson(project, MAX_JSON_DEPTH);
|
|
303
|
-
//
|
|
298
|
+
// Freeze before validation so validated parts are reused when edits check them.
|
|
304
299
|
const copy = freeze(canonicalProject(structuredClone(project)));
|
|
305
300
|
if (!knownValid(project)) {
|
|
306
301
|
const errors = validateProject(copy);
|
|
@@ -359,18 +354,17 @@ export function createEmptyDocument(settings = {}) {
|
|
|
359
354
|
});
|
|
360
355
|
}
|
|
361
356
|
/**
|
|
362
|
-
*
|
|
363
|
-
*
|
|
357
|
+
* Serializes `document` as compact JSON that {@link parseDocument} opens. Throws an `EditorError`
|
|
358
|
+
* when the document does not validate.
|
|
364
359
|
*/
|
|
365
360
|
export function serializeDocument(document) {
|
|
366
361
|
validateDocument(document);
|
|
367
362
|
return JSON.stringify(document);
|
|
368
363
|
}
|
|
369
364
|
/**
|
|
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.
|
|
365
|
+
* Opens an editor file, or a bare engine project (JSON with `schema_version`) as a new document,
|
|
366
|
+
* frozen. Every refusal is an `EditorError`: `too_large` past {@link MAX_EDITOR_FILE_BYTES},
|
|
367
|
+
* `invalid_document` for text that is not an editor document, else the code of the failed check.
|
|
374
368
|
*/
|
|
375
369
|
export function parseDocument(text) {
|
|
376
370
|
if (utf8Length(text) > MAX_EDITOR_FILE_BYTES)
|
|
@@ -392,25 +386,22 @@ export function parseDocument(text) {
|
|
|
392
386
|
catch (cause) {
|
|
393
387
|
if (cause instanceof EditorError)
|
|
394
388
|
throw cause;
|
|
395
|
-
//
|
|
389
|
+
// An unforeseen shape is still a fault of the file, not the editor.
|
|
396
390
|
throw new EditorError("invalid_document", `Editor file could not be read: ${cause instanceof Error ? cause.message : String(cause)}`, "open", undefined, true, { cause });
|
|
397
391
|
}
|
|
398
392
|
}
|
|
399
393
|
/**
|
|
400
|
-
* The id of `transition` on track `trackId`: the edge it joins
|
|
401
|
-
*
|
|
402
|
-
*
|
|
394
|
+
* The id of `transition` on track `trackId`: the edge it joins (a track has one transition per
|
|
395
|
+
* edge). It is stable while other transitions change, and changes with its clips (a split hands
|
|
396
|
+
* an outgoing transition to the right part).
|
|
403
397
|
*/
|
|
404
398
|
export function transitionInstanceId(trackId, transition) {
|
|
405
399
|
return `${trackId}/transitions/${encodeURIComponent(transition.from_clip)}/${encodeURIComponent(transition.to_clip)}`;
|
|
406
400
|
}
|
|
407
401
|
/**
|
|
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.
|
|
402
|
+
* `document` with its project in the forms the engine writes ({@link canonicalProject}). Returns
|
|
403
|
+
* `document` itself when already canonical and shares unchanged parts. A document of the wrong
|
|
404
|
+
* shape is left for validation to refuse.
|
|
414
405
|
*/
|
|
415
406
|
export function canonicalDocument(document) {
|
|
416
407
|
const project = document?.project;
|
|
@@ -421,25 +412,21 @@ export function canonicalDocument(document) {
|
|
|
421
412
|
? document
|
|
422
413
|
: { ...document, project: canonical };
|
|
423
414
|
}
|
|
424
|
-
/**
|
|
425
|
-
* Frozen tracks and clips {@link withInstanceIds} found named as they are in a frozen `instanceIds`
|
|
426
|
-
* record.
|
|
427
|
-
*/
|
|
415
|
+
/** Frozen tracks and clips {@link withInstanceIds} found fully named in a frozen `instanceIds`. */
|
|
428
416
|
const namedIn = new WeakMap();
|
|
429
417
|
/**
|
|
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.
|
|
418
|
+
* `document` with an instance id for every caption cue, transition and clip mask. Transitions are
|
|
419
|
+
* named by {@link transitionInstanceId}; cues and masks keep their ids and new ones get unique ids.
|
|
420
|
+
* Returns `document` itself when nothing changes, and leaves a malformed document for validation.
|
|
434
421
|
*/
|
|
435
422
|
export function withInstanceIds(document) {
|
|
436
423
|
const tracks = document?.project?.timeline?.tracks;
|
|
437
424
|
const original = document?.metadata?.instanceIds;
|
|
438
425
|
if (!Array.isArray(tracks) || !isRecord(original))
|
|
439
426
|
return document;
|
|
440
|
-
//
|
|
427
|
+
// Checked once, since the check is linear in the record's keys.
|
|
441
428
|
const lasting = Object.isFrozen(original);
|
|
442
|
-
// Copied on the first change
|
|
429
|
+
// Copied on the first change; a copy per changed key would be O(n^2) over n clips.
|
|
443
430
|
let changed;
|
|
444
431
|
const current = (key) => (changed ?? original)[key];
|
|
445
432
|
const set = (key, values) => {
|
|
@@ -450,9 +437,7 @@ export function withInstanceIds(document) {
|
|
|
450
437
|
return;
|
|
451
438
|
(changed ??= { ...original })[key] = values;
|
|
452
439
|
};
|
|
453
|
-
/**
|
|
454
|
-
* The ids a list of `count` keeps, `<key>/<index>` (numbered past one taken) for the new ones.
|
|
455
|
-
*/
|
|
440
|
+
/** The ids a list of `count` keeps; new ones are `<key>/<index>`, numbered past taken ones. */
|
|
456
441
|
const kept = (key, count) => {
|
|
457
442
|
const previous = current(key);
|
|
458
443
|
const ids = (Array.isArray(previous) ? previous : [])
|
|
@@ -472,7 +457,6 @@ export function withInstanceIds(document) {
|
|
|
472
457
|
for (const track of tracks) {
|
|
473
458
|
if (!isRecord(track) || typeof track.id !== "string")
|
|
474
459
|
return document;
|
|
475
|
-
// A track whose ids are unchanged in this frozen record needs nothing.
|
|
476
460
|
if (changed === undefined && namedIn.get(track) === original)
|
|
477
461
|
continue;
|
|
478
462
|
const transitions = track.transitions ?? [];
|
|
@@ -548,11 +532,9 @@ export function indexDocument(document) {
|
|
|
548
532
|
// A frozen document never changes, so its projection is computed once.
|
|
549
533
|
const compiled = new WeakMap();
|
|
550
534
|
/**
|
|
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.
|
|
535
|
+
* The project the engine renders for `document`; see `projectedTracks` for how disabled tracks
|
|
536
|
+
* project. Never throws for an invalid projection; the errors are in `diagnostics`. Cached for
|
|
537
|
+
* frozen documents.
|
|
556
538
|
*/
|
|
557
539
|
export function compileEditorDocument(document) {
|
|
558
540
|
const cached = compiled.get(document);
|
|
@@ -563,10 +545,7 @@ export function compileEditorDocument(document) {
|
|
|
563
545
|
compiled.set(document, result);
|
|
564
546
|
return result;
|
|
565
547
|
}
|
|
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
|
-
*/
|
|
548
|
+
/** End of `project`'s timeline in ticks: its last clip or caption cue, or 0 when empty. */
|
|
570
549
|
export function sequenceEnd(project) {
|
|
571
550
|
let end = 0;
|
|
572
551
|
for (const track of project.timeline.tracks) {
|
|
@@ -578,21 +557,18 @@ export function sequenceEnd(project) {
|
|
|
578
557
|
return end;
|
|
579
558
|
}
|
|
580
559
|
/**
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
* start set runs to it.
|
|
560
|
+
* End of `document`'s program in ticks: the {@link sequenceEnd} of its projection, so disabled
|
|
561
|
+
* tracks add no length. Playback and export without an export range stop there, and so does a
|
|
562
|
+
* range with only its start set.
|
|
585
563
|
*/
|
|
586
564
|
export function programEnd(document) {
|
|
587
565
|
return sequenceEnd(compileEditorDocument(document).project);
|
|
588
566
|
}
|
|
589
567
|
/**
|
|
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.
|
|
568
|
+
* The tracks the engine renders of `document`. A disabled track draws and plays nothing, but keeps
|
|
569
|
+
* the clips enabled tracks name as mattes, muted. Mattes only set coverage and are never
|
|
570
|
+
* composited, so nothing of the track draws. A track that ducks under a disabled track does not
|
|
571
|
+
* duck. A clip only disabled clips name as their matte stays a matte: not drawn, still playing.
|
|
596
572
|
*/
|
|
597
573
|
function projectedTracks(document) {
|
|
598
574
|
const tracks = document.project.timeline.tracks;
|
|
@@ -605,8 +581,7 @@ function projectedTracks(document) {
|
|
|
605
581
|
.filter((t) => disabled.has(t.id) !== enabled)
|
|
606
582
|
.flatMap((t) => (t.clips ?? []).flatMap((c) => c.matte?.source ?? [])));
|
|
607
583
|
const mattes = named(true);
|
|
608
|
-
// Named by hidden clips
|
|
609
|
-
// draw it as an ordinary clip.
|
|
584
|
+
// Named only by hidden clips, which the projection drops, so the engine would draw it plainly.
|
|
610
585
|
const orphaned = new Set([...named(false)].filter((id) => !mattes.has(id)));
|
|
611
586
|
return tracks.flatMap((track) => {
|
|
612
587
|
if (disabled.has(track.id)) {
|
|
@@ -674,8 +649,8 @@ function compileProjection(document) {
|
|
|
674
649
|
};
|
|
675
650
|
}
|
|
676
651
|
/**
|
|
677
|
-
* Seeds the {@link indexDocument} cache of `next` from
|
|
678
|
-
*
|
|
652
|
+
* Seeds the {@link indexDocument} cache of `next` from `previous`, rebuilding only changed tracks.
|
|
653
|
+
* Does nothing when `previous` has no index.
|
|
679
654
|
*/
|
|
680
655
|
export function inheritDocumentIndex(previous, next) {
|
|
681
656
|
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;
|