@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
@@ -1,8 +1,5 @@
1
1
  import { findComposition, freeCompositionId } from "./compositions.js";
2
- /**
3
- * The preset of composition `id`, as a group node would draw it: it, every composition it uses, and
4
- * the sources, resources, and effects they read.
5
- */
2
+ /** The preset of composition `id`: it, every composition it uses, and what they read. */
6
3
  export function graphPreset(project, id, name) {
7
4
  const compositions = [];
8
5
  const sources = new Map();
@@ -60,8 +57,7 @@ export function graphPreset(project, id, name) {
60
57
  }
61
58
  /**
62
59
  * What `preset` needs that `document`'s project lacks: file-backed sources and effect resources by
63
- * id (a composition source it brings along is not missing), and effects `runs` says the engine does
64
- * not have.
60
+ * id (composition sources it brings are not missing), and effects `runs` says the engine lacks.
65
61
  */
66
62
  export function presetShortfall(document, preset, runs) {
67
63
  const project = document.project;
@@ -79,7 +75,7 @@ export function presetShortfall(document, preset, runs) {
79
75
  };
80
76
  }
81
77
  /**
82
- * Commands that add `preset`'s compositions (and the composition sources they read) to `document`
78
+ * Commands adding `preset`'s compositions (and the composition sources they read) to `document`
83
79
  * under free ids, and the id its group composition got.
84
80
  */
85
81
  function presetAdditions(document, preset) {
@@ -94,7 +90,7 @@ function presetAdditions(document, preset) {
94
90
  compositions: [...(taken.compositions ?? []), { id, nodes: [] }],
95
91
  };
96
92
  }
97
- // An id no existing source, bin asset or earlier-added source has: two of the preset's may share
93
+ // Ids unique among sources, bin assets and earlier additions, since two preset sources may share
98
94
  // a base id (`card`, and `card~2` from an earlier rename).
99
95
  const sourceIds = new Map();
100
96
  const takenSources = new Set([
@@ -162,11 +158,10 @@ function presetAdditions(document, preset) {
162
158
  return { commands, root, taken };
163
159
  }
164
160
  /**
165
- * The command that places `preset` in composition `compositionId` as one undoable edit: its
166
- * compositions added under free ids, and an unconnected group node `groupId` drawing the first, at
167
- * `position` in the node editor.
168
- * Returns `null` when the preset has no composition or `compositionId` does not exist. The command
169
- * may still be refused when executed.
161
+ * The command placing `preset` in composition `compositionId` as one undoable edit: its
162
+ * compositions under free ids and an unconnected group node `groupId` drawing the first, at
163
+ * `position`. Returns `null` when the preset has no composition or `compositionId` does not exist;
164
+ * the command may still be refused when executed.
170
165
  */
171
166
  export function placeGraphPreset(document, preset, compositionId, groupId, position) {
172
167
  const root = preset.compositions[0];
@@ -194,11 +189,10 @@ export function placeGraphPreset(document, preset, compositionId, groupId, posit
194
189
  };
195
190
  }
196
191
  /**
197
- * The command that applies `preset` to clip `clipId` as one undoable edit: its compositions added
198
- * under free ids, and a group node drawing the first placed after the clip composition's output
199
- * (reading it, when the group has an input) and made the output. A clip without a composition gets
200
- * one. Returns `null` for a preset with more than one input, which has no single place to go, and
201
- * for an unknown clip.
192
+ * The command applying `preset` to clip `clipId` as one undoable edit: its compositions under free
193
+ * ids, and a group node drawing the first placed after the clip composition's output (reading it
194
+ * if the group has an input) and made the output. A clip without a composition gets one. Returns
195
+ * `null` for an unknown clip or a preset with more than one input.
202
196
  */
203
197
  export function applyGraphPreset(document, preset, clipId, ids) {
204
198
  const root = preset.compositions[0];
@@ -21,10 +21,8 @@ export interface EditorSnapshot {
21
21
  }
22
22
  /**
23
23
  * Holds an editor document with undo history, selection, clipboard and pointer gestures. Every
24
- * document it holds is frozen; edits produce new documents through {@link Command}s.
25
- *
26
- * Methods other than `cancelGesture` and `dispose` throw an `EditorError` (`disposed`) after
27
- * {@link EditorSession.dispose}.
24
+ * document it holds is frozen; edits produce new documents through {@link Command}s. Methods other
25
+ * than `cancelGesture` and `dispose` throw an `EditorError` (`disposed`) after disposal.
28
26
  */
29
27
  export declare class EditorSession {
30
28
  #private;
@@ -34,9 +32,9 @@ export declare class EditorSession {
34
32
  * @param document The initial document, copied; an empty document by default. Throws an
35
33
  * `EditorError` when it does not validate.
36
34
  * @param historyLimit The most undo steps kept. Defaults to 120.
37
- * @param historyByteLimit The most bytes the undo history keeps beyond the document: each step
38
- * counts the serialized size of what it does not share with the document after it, by
39
- * object identity, and the oldest steps are dropped first. Defaults to 64 MiB.
35
+ * @param historyByteLimit Bytes the undo history may hold beyond the document, counting each
36
+ * step's serialized parts not shared with the next document; oldest steps drop first. Defaults
37
+ * to 64 MiB.
40
38
  * @throws RangeError when a limit is not a non-negative safe integer.
41
39
  */
42
40
  constructor(document?: EditorDocument, historyLimit?: number, historyByteLimit?: number);
@@ -46,14 +44,11 @@ export declare class EditorSession {
46
44
  get generation(): number;
47
45
  get disposed(): boolean;
48
46
  /**
49
- * Every document the session can still show or return to: the undo history, the document, the
50
- * active gesture's draft and the redo history. A host keeps what these refer to and may release
51
- * the rest.
47
+ * Every document the session can still show or return to (undo history, document, gesture draft,
48
+ * redo history). A host may release anything these do not refer to.
52
49
  */
53
50
  reachableDocuments(): readonly EditorDocument[];
54
- /**
55
- * The current snapshot; the same object until the next change, as `useSyncExternalStore` needs.
56
- */
51
+ /** The current snapshot, the same object until the next change (for `useSyncExternalStore`). */
57
52
  getSnapshot: () => EditorSnapshot;
58
53
  /** Calls `listener` after every change. Returns the unsubscribe function. */
59
54
  subscribe: (listener: () => void) => (() => void);
@@ -62,16 +57,12 @@ export declare class EditorSession {
62
57
  * default). Returns the unsubscribe function.
63
58
  */
64
59
  subscribeSelector<T>(selector: (snapshot: EditorSnapshot) => T, listener: (value: T) => void, equal?: (a: T, b: T) => boolean): () => void;
65
- /**
66
- * The document `command` would produce from the committed one, or why it is refused. Changes
67
- * nothing.
68
- */
60
+ /** The document `command` would produce from the committed one, or why it is refused. */
69
61
  canExecute(command: Command): Result<EditorDocument>;
70
62
  /**
71
63
  * Runs `command` on the committed document and commits the result as one undo step, cancelling an
72
- * active gesture first. A refusal is returned, not thrown, and leaves the session unchanged; so
73
- * does a command that changes nothing (its result is the committed document itself), which keeps
74
- * the redo history.
64
+ * active gesture first. A refusal is returned, not thrown, and leaves the session unchanged. A
65
+ * command that changes nothing also leaves it unchanged and keeps the redo history.
75
66
  */
76
67
  dispatch(command: Command): Result<EditorDocument>;
77
68
  /**
@@ -84,16 +75,14 @@ export declare class EditorSession {
84
75
  /** Reapplies the last undone change. Returns `false` when there is none. */
85
76
  redo(): boolean;
86
77
  /**
87
- * Forgets the undo and redo history and keeps everything else: the document (so `revision` and
88
- * `generation` stay), the selection, the clipboard and an active gesture. For a host that made
89
- * changes the user should not step back through, such as relinking media it restored, without
90
- * {@link open}'s new generation, which tells views and the bridge the document was replaced.
78
+ * Forgets the undo and redo history and keeps everything else (document, `revision`,
79
+ * `generation`, selection, clipboard, active gesture). For host changes the user should not step
80
+ * back through, such as relinking restored media, without {@link open}'s new generation.
91
81
  */
92
82
  clearHistory(): void;
93
83
  /**
94
- * Selects the clips `ids` names; unknown ids and duplicates are dropped. The selection it would
95
- * set already holds (the same ids in the same order), it changes nothing and tells no one: a
96
- * marquee calls it on every pointer move.
84
+ * Selects the clips `ids` names, dropping unknown ids and duplicates. Setting the same selection
85
+ * again notifies no one, since a marquee calls this on every pointer move.
97
86
  */
98
87
  select(ids: readonly string[]): void;
99
88
  /** The committed document's tracks and clips by id. */
@@ -112,24 +101,23 @@ export declare class EditorSession {
112
101
  */
113
102
  copy(ids?: readonly string[]): void;
114
103
  /**
115
- * Inserts the clipboard's clips on their original tracks, under their names, as one undo step,
116
- * the earliest starting at tick `at` and the others keeping their offsets from it. New clip ids
117
- * come from `idFactory`. With nothing copied it changes nothing and returns the document.
104
+ * Inserts the clipboard's clips on their original tracks as one undo step, the earliest at tick
105
+ * `at` and the rest at their offsets from it. New clip ids come from `idFactory`. With nothing
106
+ * copied it returns the document unchanged.
118
107
  */
119
108
  paste(at: number, idFactory?: () => string): Result<EditorDocument>;
120
109
  /**
121
- * Cancels the active gesture, if any, discarding its draft: nothing it previewed is committed.
122
- * Returns whether a gesture was active. A host calls it before it tears down the view a gesture
123
- * belongs to.
110
+ * Cancels the active gesture, discarding its draft, and returns whether one was active. Call it
111
+ * before tearing down the view a gesture belongs to.
124
112
  */
125
113
  cancelGesture(): boolean;
126
114
  /**
127
115
  * Starts a pointer gesture, cancelling an active one. Each `update` runs a command on the
128
- * document the gesture started from and, when valid, shows the result as the snapshot's `draft`
129
- * without touching history. `commit` validates the last candidate fully and commits it as one
130
- * undo step, returning whether anything was committed; `cancel` discards it. A gesture ends on
131
- * commit, cancel, a dispatch, undo, redo, open or dispose, or the next `beginGesture`; `update`
132
- * then returns a `stale_gesture` error.
116
+ * gesture's starting document and, when valid, shows the result as the snapshot's `draft` without
117
+ * touching history. `commit` validates the last candidate fully and commits it as one undo step,
118
+ * returning whether anything was committed; `cancel` discards it. A commit, cancel, dispatch,
119
+ * undo, redo, open, dispose or new `beginGesture` ends the gesture, after which `update` returns
120
+ * `stale_gesture`.
133
121
  */
134
122
  beginGesture(): {
135
123
  readonly candidate: EditorDocument;
@@ -4,10 +4,8 @@ import { executeCommand } from "./commands.js";
4
4
  import { frozenValid, owned } from "./validated.js";
5
5
  /**
6
6
  * Holds an editor document with undo history, selection, clipboard and pointer gestures. Every
7
- * document it holds is frozen; edits produce new documents through {@link Command}s.
8
- *
9
- * Methods other than `cancelGesture` and `dispose` throw an `EditorError` (`disposed`) after
10
- * {@link EditorSession.dispose}.
7
+ * document it holds is frozen; edits produce new documents through {@link Command}s. Methods other
8
+ * than `cancelGesture` and `dispose` throw an `EditorError` (`disposed`) after disposal.
11
9
  */
12
10
  export class EditorSession {
13
11
  historyLimit;
@@ -29,9 +27,9 @@ export class EditorSession {
29
27
  * @param document The initial document, copied; an empty document by default. Throws an
30
28
  * `EditorError` when it does not validate.
31
29
  * @param historyLimit The most undo steps kept. Defaults to 120.
32
- * @param historyByteLimit The most bytes the undo history keeps beyond the document: each step
33
- * counts the serialized size of what it does not share with the document after it, by
34
- * object identity, and the oldest steps are dropped first. Defaults to 64 MiB.
30
+ * @param historyByteLimit Bytes the undo history may hold beyond the document, counting each
31
+ * step's serialized parts not shared with the next document; oldest steps drop first. Defaults
32
+ * to 64 MiB.
35
33
  * @throws RangeError when a limit is not a non-negative safe integer.
36
34
  */
37
35
  constructor(document = createEmptyDocument(), historyLimit = 120, historyByteLimit = 64 * 1024 * 1024) {
@@ -63,9 +61,8 @@ export class EditorSession {
63
61
  return this.#disposed;
64
62
  }
65
63
  /**
66
- * Every document the session can still show or return to: the undo history, the document, the
67
- * active gesture's draft and the redo history. A host keeps what these refer to and may release
68
- * the rest.
64
+ * Every document the session can still show or return to (undo history, document, gesture draft,
65
+ * redo history). A host may release anything these do not refer to.
69
66
  */
70
67
  reachableDocuments() {
71
68
  return [
@@ -75,9 +72,7 @@ export class EditorSession {
75
72
  ...this.#redo,
76
73
  ];
77
74
  }
78
- /**
79
- * The current snapshot; the same object until the next change, as `useSyncExternalStore` needs.
80
- */
75
+ /** The current snapshot, the same object until the next change (for `useSyncExternalStore`). */
81
76
  getSnapshot = () => this.#snapshot;
82
77
  /** Calls `listener` after every change. Returns the unsubscribe function. */
83
78
  subscribe = (listener) => {
@@ -146,7 +141,7 @@ export class EditorSession {
146
141
  this.#undo.push(this.#document);
147
142
  this.#trimHistory(document);
148
143
  this.#redo = [];
149
- // What it commits passed a dispatch's checks.
144
+ // Already passed a dispatch's checks.
150
145
  this.#document = frozenValid(document);
151
146
  this.#revision++;
152
147
  this.#prune();
@@ -158,19 +153,15 @@ export class EditorSession {
158
153
  if (kept.length !== this.#selection.length)
159
154
  this.#selection = Object.freeze(kept);
160
155
  }
161
- /**
162
- * The document `command` would produce from the committed one, or why it is refused. Changes
163
- * nothing.
164
- */
156
+ /** The document `command` would produce from the committed one, or why it is refused. */
165
157
  canExecute(command) {
166
158
  this.#active();
167
159
  return executeCommand(this.#document, command);
168
160
  }
169
161
  /**
170
162
  * Runs `command` on the committed document and commits the result as one undo step, cancelling an
171
- * active gesture first. A refusal is returned, not thrown, and leaves the session unchanged; so
172
- * does a command that changes nothing (its result is the committed document itself), which keeps
173
- * the redo history.
163
+ * active gesture first. A refusal is returned, not thrown, and leaves the session unchanged. A
164
+ * command that changes nothing also leaves it unchanged and keeps the redo history.
174
165
  */
175
166
  dispatch(command) {
176
167
  this.#active();
@@ -228,10 +219,9 @@ export class EditorSession {
228
219
  return true;
229
220
  }
230
221
  /**
231
- * Forgets the undo and redo history and keeps everything else: the document (so `revision` and
232
- * `generation` stay), the selection, the clipboard and an active gesture. For a host that made
233
- * changes the user should not step back through, such as relinking media it restored, without
234
- * {@link open}'s new generation, which tells views and the bridge the document was replaced.
222
+ * Forgets the undo and redo history and keeps everything else (document, `revision`,
223
+ * `generation`, selection, clipboard, active gesture). For host changes the user should not step
224
+ * back through, such as relinking restored media, without {@link open}'s new generation.
235
225
  */
236
226
  clearHistory() {
237
227
  this.#active();
@@ -242,9 +232,8 @@ export class EditorSession {
242
232
  this.#emit();
243
233
  }
244
234
  /**
245
- * Selects the clips `ids` names; unknown ids and duplicates are dropped. The selection it would
246
- * set already holds (the same ids in the same order), it changes nothing and tells no one: a
247
- * marquee calls it on every pointer move.
235
+ * Selects the clips `ids` names, dropping unknown ids and duplicates. Setting the same selection
236
+ * again notifies no one, since a marquee calls this on every pointer move.
248
237
  */
249
238
  select(ids) {
250
239
  this.#active();
@@ -280,9 +269,9 @@ export class EditorSession {
280
269
  }));
281
270
  }
282
271
  /**
283
- * Inserts the clipboard's clips on their original tracks, under their names, as one undo step,
284
- * the earliest starting at tick `at` and the others keeping their offsets from it. New clip ids
285
- * come from `idFactory`. With nothing copied it changes nothing and returns the document.
272
+ * Inserts the clipboard's clips on their original tracks as one undo step, the earliest at tick
273
+ * `at` and the rest at their offsets from it. New clip ids come from `idFactory`. With nothing
274
+ * copied it returns the document unchanged.
286
275
  */
287
276
  paste(at, idFactory = () => crypto.randomUUID()) {
288
277
  this.#active();
@@ -302,14 +291,12 @@ export class EditorSession {
302
291
  });
303
292
  moves.push({ id, at: at + clip.timeline_range.start - anchor });
304
293
  }
305
- // Insert each copy where its original is, then move them all off together in one `clips.move`.
306
294
  commands.push({ type: "clips.move", moves });
307
295
  return this.dispatch({ type: "transaction", commands });
308
296
  }
309
297
  /**
310
- * Cancels the active gesture, if any, discarding its draft: nothing it previewed is committed.
311
- * Returns whether a gesture was active. A host calls it before it tears down the view a gesture
312
- * belongs to.
298
+ * Cancels the active gesture, discarding its draft, and returns whether one was active. Call it
299
+ * before tearing down the view a gesture belongs to.
313
300
  */
314
301
  cancelGesture() {
315
302
  const cancel = this.#cancelGesture;
@@ -320,11 +307,11 @@ export class EditorSession {
320
307
  }
321
308
  /**
322
309
  * Starts a pointer gesture, cancelling an active one. Each `update` runs a command on the
323
- * document the gesture started from and, when valid, shows the result as the snapshot's `draft`
324
- * without touching history. `commit` validates the last candidate fully and commits it as one
325
- * undo step, returning whether anything was committed; `cancel` discards it. A gesture ends on
326
- * commit, cancel, a dispatch, undo, redo, open or dispose, or the next `beginGesture`; `update`
327
- * then returns a `stale_gesture` error.
310
+ * gesture's starting document and, when valid, shows the result as the snapshot's `draft` without
311
+ * touching history. `commit` validates the last candidate fully and commits it as one undo step,
312
+ * returning whether anything was committed; `cancel` discards it. A commit, cancel, dispatch,
313
+ * undo, redo, open, dispose or new `beginGesture` ends the gesture, after which `update` returns
314
+ * `stale_gesture`.
328
315
  */
329
316
  beginGesture() {
330
317
  this.#active();
@@ -375,7 +362,7 @@ export class EditorSession {
375
362
  this.#emit();
376
363
  return false;
377
364
  }
378
- // Updates validated only the candidate's shape; the commit passes every dispatch check.
365
+ // Updates validated only the shape; the commit runs every dispatch check.
379
366
  try {
380
367
  validateDocument(value);
381
368
  }
@@ -431,9 +418,9 @@ export class EditorSession {
431
418
  export function createEditor(options = {}) {
432
419
  return new EditorSession(options.document, options.historyLimit, options.historyByteLimit);
433
420
  }
434
- /** {@link jsonBytes} of frozen objects, by identity: nothing can change them. */
421
+ /** {@link jsonBytes} of frozen objects, which cannot change. */
435
422
  const frozenBytes = new WeakMap();
436
- /** UTF-8 bytes of `text` as a JSON string, quotes included and escapes not. */
423
+ /** UTF-8 bytes of `text` as a JSON string, with quotes and without escapes. */
437
424
  function stringBytes(text) {
438
425
  let bytes = 2;
439
426
  for (let i = 0; i < text.length; i++) {
@@ -450,7 +437,6 @@ function stringBytes(text) {
450
437
  }
451
438
  return bytes;
452
439
  }
453
- /** The bytes a primitive serializes to. */
454
440
  function primitiveBytes(value) {
455
441
  if (typeof value === "string")
456
442
  return stringBytes(value);
@@ -458,7 +444,7 @@ function primitiveBytes(value) {
458
444
  typeof value === "boolean" ||
459
445
  typeof value === "bigint")
460
446
  return String(value).length;
461
- // `null`; `undefined`, functions and symbols are left out.
447
+ // `null`; `undefined`, functions and symbols are omitted.
462
448
  return value === null ? 4 : 0;
463
449
  }
464
450
  /** The fields a plain object serializes, as `JSON.stringify` writes them. */
@@ -466,8 +452,8 @@ function serializedEntries(value) {
466
452
  return Object.entries(value).filter(([, field]) => field !== undefined && typeof field !== "function");
467
453
  }
468
454
  /**
469
- * About the bytes `JSON.stringify(value)` writes (strings unescaped), without building the string.
470
- * A frozen part's size is kept, so a part every document shares is measured once.
455
+ * Approximate `JSON.stringify(value)` byte length (strings unescaped), without building the string.
456
+ * Sizes of frozen parts are cached, so shared parts are measured once.
471
457
  */
472
458
  function jsonBytes(value) {
473
459
  if (value === null || typeof value !== "object")
@@ -492,12 +478,11 @@ function jsonBytes(value) {
492
478
  return bytes;
493
479
  }
494
480
  /**
495
- * About the bytes an undo step holds that `after`, the document after it, does not: the serialized
496
- * size of its parts that are not the same objects as `after`'s. Edits share what they leave
497
- * unchanged, so a step that renames a marker in a project with a 100,000-frame image sequence holds
498
- * a few hundred bytes, not the sequence again. An array's item is matched to `after`'s by identity
499
- * anywhere in the array, then by its `id`, then by position; a part moved elsewhere is counted
500
- * whole, so the estimate errs high.
481
+ * Approximate bytes an undo step holds beyond `after` (the next document): the serialized size of
482
+ * its parts that are not the same objects as `after`'s. Edits share unchanged parts, so renaming a
483
+ * marker in a project with a huge image sequence costs a few hundred bytes. Array items match
484
+ * `after`'s by identity anywhere, then by `id`, then by position; moved parts count whole, so the
485
+ * estimate errs high.
501
486
  */
502
487
  function stepBytes(step, after) {
503
488
  if (step === after)
@@ -1,7 +1,6 @@
1
1
  /**
2
- * What a title's authoring style (`asset.authoring.text`) means where it leaves a field out: the
3
- * browser runtime draws the title with these. A UI that shows a title's style reads its fallbacks
4
- * here, so what it shows is what is drawn.
2
+ * Fallbacks for fields a title's authoring style (`asset.authoring.text`) leaves out, as the
3
+ * browser runtime draws it. UIs showing a title's style should read them here.
5
4
  */
6
5
  export declare const TEXT_DEFAULTS: Readonly<{
7
6
  readonly content: "alpha2";
package/dist/core/text.js CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
- * What a title's authoring style (`asset.authoring.text`) means where it leaves a field out: the
3
- * browser runtime draws the title with these. A UI that shows a title's style reads its fallbacks
4
- * here, so what it shows is what is drawn.
2
+ * Fallbacks for fields a title's authoring style (`asset.authoring.text`) leaves out, as the
3
+ * browser runtime draws it. UIs showing a title's style should read them here.
5
4
  */
6
5
  export const TEXT_DEFAULTS = Object.freeze({
7
6
  content: "alpha2",
@@ -37,8 +37,7 @@ export type IndexEntry = {
37
37
  readonly marker: Marker;
38
38
  };
39
39
  /**
40
- * Every clip, transition, caption cue, and marker of a document, in timeline order (then by kind,
41
- * then id). Derived from the document alone and kept per document, so a playing viewer never
42
- * rebuilds it: only an edit does.
40
+ * Every clip, transition, caption cue and marker of a document in timeline order (then by kind,
41
+ * then id). Cached per document, so only edits rebuild it.
43
42
  */
44
43
  export declare function timelineIndex(document: EditorDocument): readonly IndexEntry[];
@@ -1,23 +1,27 @@
1
+ import { textOf } from "alpha2/project";
1
2
  const indexes = new WeakMap();
2
3
  /**
3
- * Every clip, transition, caption cue, and marker of a document, in timeline order (then by kind,
4
- * then id). Derived from the document alone and kept per document, so a playing viewer never
5
- * rebuilds it: only an edit does.
4
+ * Every clip, transition, caption cue and marker of a document in timeline order (then by kind,
5
+ * then id). Cached per document, so only edits rebuild it.
6
6
  */
7
7
  export function timelineIndex(document) {
8
8
  const cached = indexes.get(document);
9
9
  if (cached)
10
10
  return cached;
11
11
  const names = new Map(Object.values(document.assets).map((asset) => [asset.id, asset.name]));
12
+ // A Map, because keyed reads of thousands of distinct ids from an object get slower per read as
13
+ // the object grows.
14
+ const clipNames = new Map(Object.entries(document.metadata.clips).map(([id, clip]) => [
15
+ id,
16
+ clip.name,
17
+ ]));
12
18
  const entries = [];
13
19
  for (const track of document.project.timeline.tracks) {
14
20
  for (const clip of track.clips ?? [])
15
21
  entries.push({
16
22
  kind: "clip",
17
23
  id: clip.id,
18
- name: document.metadata.clips[clip.id]?.name ??
19
- names.get(clip.source_id) ??
20
- clip.source_id,
24
+ name: clipNames.get(clip.id) ?? names.get(clip.source_id) ?? clip.source_id,
21
25
  trackId: track.id,
22
26
  start: clip.timeline_range.start,
23
27
  end: clip.timeline_range.end,
@@ -34,7 +38,7 @@ export function timelineIndex(document) {
34
38
  (track.captions?.cues ?? []).forEach((cue, index) => entries.push({
35
39
  kind: "caption",
36
40
  id: `${track.id}#${index}`,
37
- name: cue.text,
41
+ name: textOf(cue.text),
38
42
  trackId: track.id,
39
43
  start: cue.timeline_range.start,
40
44
  end: cue.timeline_range.end,
@@ -3,8 +3,8 @@ const fail = (message) => {
3
3
  throw new EditorError("invalid_transition", message, "transition");
4
4
  };
5
5
  /**
6
- * `value` with every keyframe time moved `delta` ticks. Every `Animated<T>` in a clip, masks
7
- * included, uses timeline ticks; its composition keeps its own time.
6
+ * `value` with every keyframe time moved `delta` ticks. Clip animation, masks included, uses
7
+ * timeline ticks; its composition keeps its own time.
8
8
  */
9
9
  function shifted(value, delta) {
10
10
  if (!value || typeof value !== "object")
@@ -23,9 +23,8 @@ function shifted(value, delta) {
23
23
  return Object.fromEntries(Object.entries(object).map(([key, v]) => [key, shifted(v, delta)]));
24
24
  }
25
25
  /**
26
- * `track` with clip `id` starting at `start`, and the clips that follow it through transitions (its
27
- * outgoing transition's clip, that clip's, and so on) moved as far with their transitions, so each
28
- * overlap the chain holds stays exact. Collisions with other clips are for validation to refuse.
26
+ * `track` with clip `id` starting at `start`, and the clips chained after it through transitions
27
+ * moved by the same amount, so every overlap stays exact. Collisions are left to validation.
29
28
  */
30
29
  function moveChain(track, id, start) {
31
30
  const clip = track.clips.find((c) => c.id === id);
@@ -1,23 +1,22 @@
1
1
  import type { Project } from "alpha2/project";
2
2
  /**
3
3
  * Records that `project` passed `validateProject`. A deep-frozen project is remembered for good;
4
- * another only until the `withValidated` call running now returns, since its owner may change it
5
- * later.
4
+ * others only until the current `withValidated` call returns, since their owner may change them.
6
5
  */
7
6
  export declare function rememberValid(project: Project): void;
8
7
  /** Whether `project` is known to pass `validateProject` (see `rememberValid`). */
9
8
  export declare function knownValid(project: Project): boolean;
10
- /** Runs `run`, forgetting when it returns the unfrozen projects it called valid. */
9
+ /** Runs `run`, then forgets the unfrozen projects marked valid during it. */
11
10
  export declare function withValidated<T>(run: () => T): T;
12
11
  /**
13
- * Deep-freezes `document`, which validated, and remembers its project as valid, so compiling it or
14
- * checking it again does not walk the project again.
12
+ * Deep-freezes the validated `document` and remembers its project as valid, so later checks skip
13
+ * walking it.
15
14
  */
16
15
  export declare function frozenValid<T extends {
17
16
  readonly project: Project;
18
17
  }>(document: T): T;
19
18
  /**
20
- * `document` itself when {@link frozenValid} froze it, which nothing can change, or else a copy
21
- * for a session to own. Keeping the frozen document keeps what validating its parts found.
19
+ * `document` itself when {@link frozenValid} froze it, else a copy for a session to own. Keeping
20
+ * the frozen document keeps its cached validation.
22
21
  */
23
22
  export declare function owned<T extends object>(document: T): T;
@@ -1,12 +1,11 @@
1
1
  import { freeze } from "./document.js";
2
- /** Deep-frozen projects that validated: they cannot change, so they stay valid. */
2
+ /** Deep-frozen projects that validated; they cannot change, so they stay valid. */
3
3
  const frozen = new WeakSet();
4
4
  /** Projects an edit validated during the `executeCommand` running now (see `withValidated`). */
5
5
  let current = null;
6
6
  /**
7
7
  * Records that `project` passed `validateProject`. A deep-frozen project is remembered for good;
8
- * another only until the `withValidated` call running now returns, since its owner may change it
9
- * later.
8
+ * others only until the current `withValidated` call returns, since their owner may change them.
10
9
  */
11
10
  export function rememberValid(project) {
12
11
  if (Object.isFrozen(project))
@@ -18,7 +17,7 @@ export function rememberValid(project) {
18
17
  export function knownValid(project) {
19
18
  return frozen.has(project) || (current?.has(project) ?? false);
20
19
  }
21
- /** Runs `run`, forgetting when it returns the unfrozen projects it called valid. */
20
+ /** Runs `run`, then forgets the unfrozen projects marked valid during it. */
22
21
  export function withValidated(run) {
23
22
  const previous = current;
24
23
  current = new WeakSet();
@@ -29,13 +28,11 @@ export function withValidated(run) {
29
28
  current = previous;
30
29
  }
31
30
  }
32
- /**
33
- * Documents {@link frozenValid} froze: plain data the editor made or copied, frozen all through.
34
- */
31
+ /** Documents {@link frozenValid} froze: editor-made plain data, deep-frozen. */
35
32
  const sealedDocuments = new WeakSet();
36
33
  /**
37
- * Deep-freezes `document`, which validated, and remembers its project as valid, so compiling it or
38
- * checking it again does not walk the project again.
34
+ * Deep-freezes the validated `document` and remembers its project as valid, so later checks skip
35
+ * walking it.
39
36
  */
40
37
  export function frozenValid(document) {
41
38
  freeze(document);
@@ -44,8 +41,8 @@ export function frozenValid(document) {
44
41
  return document;
45
42
  }
46
43
  /**
47
- * `document` itself when {@link frozenValid} froze it, which nothing can change, or else a copy
48
- * for a session to own. Keeping the frozen document keeps what validating its parts found.
44
+ * `document` itself when {@link frozenValid} froze it, else a copy for a session to own. Keeping
45
+ * the frozen document keeps its cached validation.
49
46
  */
50
47
  export function owned(document) {
51
48
  return sealedDocuments.has(document) ? document : structuredClone(document);