@alpha2-sh/editor 0.4.5 → 0.5.0

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