alpha2 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 (119) hide show
  1. package/README.md +5 -4
  2. package/THIRD_PARTY_NOTICES.md +4 -0
  3. package/dist/abort.d.ts +12 -0
  4. package/dist/abort.js +48 -0
  5. package/dist/active-clock.d.ts +35 -0
  6. package/dist/active-clock.js +99 -0
  7. package/dist/assets.d.ts +28 -22
  8. package/dist/assets.js +8 -12
  9. package/dist/audio-layout.d.ts +52 -74
  10. package/dist/audio-layout.js +114 -148
  11. package/dist/audio-timeline.d.ts +89 -117
  12. package/dist/audio-timeline.js +102 -118
  13. package/dist/audio-worker.d.ts +12 -21
  14. package/dist/audio-worker.js +8 -13
  15. package/dist/audio-worklet-processor.js +45 -58
  16. package/dist/audio-worklet.d.ts +45 -76
  17. package/dist/audio-worklet.js +44 -79
  18. package/dist/audio.d.ts +15 -23
  19. package/dist/audio.js +9 -13
  20. package/dist/builder.d.ts +45 -63
  21. package/dist/builder.js +49 -45
  22. package/dist/capabilities.d.ts +99 -16
  23. package/dist/capabilities.js +2 -2
  24. package/dist/captions.d.ts +45 -22
  25. package/dist/captions.js +60 -15
  26. package/dist/chroma-siting.d.ts +24 -41
  27. package/dist/chroma-siting.js +38 -71
  28. package/dist/containers.d.ts +41 -30
  29. package/dist/containers.js +59 -27
  30. package/dist/decoder-fallback.d.ts +13 -0
  31. package/dist/decoder-fallback.js +38 -0
  32. package/dist/decoder-order.d.ts +24 -39
  33. package/dist/decoder-order.js +28 -42
  34. package/dist/edit.d.ts +77 -154
  35. package/dist/edit.js +98 -180
  36. package/dist/effects.d.ts +109 -173
  37. package/dist/effects.js +7 -9
  38. package/dist/export-destination.d.ts +25 -41
  39. package/dist/export-destination.js +20 -32
  40. package/dist/export-failure.d.ts +34 -59
  41. package/dist/export-failure.js +54 -48
  42. package/dist/export-metrics.d.ts +116 -0
  43. package/dist/export-metrics.js +74 -0
  44. package/dist/export-retry.d.ts +46 -29
  45. package/dist/export-retry.js +86 -51
  46. package/dist/exporter.d.ts +67 -116
  47. package/dist/exporter.js +133 -133
  48. package/dist/extensions.d.ts +69 -115
  49. package/dist/extensions.js +55 -82
  50. package/dist/frame-intake.d.ts +92 -0
  51. package/dist/frame-intake.js +114 -0
  52. package/dist/frame-supply.d.ts +98 -157
  53. package/dist/frame-supply.js +191 -162
  54. package/dist/generated/project-schema.d.ts +742 -464
  55. package/dist/generated/project-schema.js +63 -2
  56. package/dist/generated/project-shape.js +663 -118
  57. package/dist/geometry.d.ts +28 -34
  58. package/dist/geometry.js +18 -23
  59. package/dist/gpu-recovery.d.ts +92 -0
  60. package/dist/gpu-recovery.js +135 -0
  61. package/dist/hdr-frames.d.ts +88 -62
  62. package/dist/hdr-frames.js +123 -46
  63. package/dist/index.d.ts +4 -0
  64. package/dist/index.js +4 -0
  65. package/dist/json-text.d.ts +13 -23
  66. package/dist/json-text.js +10 -20
  67. package/dist/layout-values.d.ts +14 -22
  68. package/dist/layout-values.js +18 -21
  69. package/dist/layout.d.ts +55 -55
  70. package/dist/layout.js +37 -36
  71. package/dist/loudness.d.ts +27 -32
  72. package/dist/loudness.js +19 -23
  73. package/dist/media.d.ts +85 -237
  74. package/dist/media.js +133 -287
  75. package/dist/mediabunny.d.ts +173 -237
  76. package/dist/mediabunny.js +943 -518
  77. package/dist/physical-frames.d.ts +5 -17
  78. package/dist/physical-frames.js +4 -11
  79. package/dist/player.d.ts +56 -47
  80. package/dist/player.js +155 -40
  81. package/dist/presented-frames.d.ts +2 -7
  82. package/dist/presented-frames.js +3 -8
  83. package/dist/project.d.ts +83 -110
  84. package/dist/project.js +421 -447
  85. package/dist/rate-control.d.ts +9 -23
  86. package/dist/rate-control.js +7 -18
  87. package/dist/renderer-choice.d.ts +41 -0
  88. package/dist/renderer-choice.js +82 -0
  89. package/dist/repacked-bytes.d.ts +0 -2
  90. package/dist/repacked-bytes.js +2 -5
  91. package/dist/robustness.d.ts +25 -37
  92. package/dist/robustness.js +71 -54
  93. package/dist/sha256.d.ts +5 -13
  94. package/dist/sha256.js +9 -24
  95. package/dist/text.d.ts +106 -63
  96. package/dist/text.js +44 -69
  97. package/dist/video-frames.d.ts +7 -25
  98. package/dist/video-frames.js +12 -29
  99. package/dist/waveform.d.ts +5 -11
  100. package/dist/waveform.js +4 -9
  101. package/dist/worker-error.d.ts +5 -20
  102. package/dist/worker-error.js +8 -25
  103. package/dist/worker.d.ts +82 -92
  104. package/dist/worker.js +239 -144
  105. package/package.json +26 -2
  106. package/wasm/alpha2_audio_worklet.wasm +0 -0
  107. package/wasm/alpha2_extensions.d.ts +26 -47
  108. package/wasm/alpha2_extensions.js +26 -47
  109. package/wasm/alpha2_extensions_bg.wasm +0 -0
  110. package/wasm/alpha2_wasm.d.ts +487 -543
  111. package/wasm/alpha2_wasm.js +669 -572
  112. package/wasm/alpha2_wasm_bg.wasm +0 -0
  113. package/wasm/alpha2_wasm_bg.wasm.d.ts +20 -8
  114. package/wasm/rust-crate-licenses.md +2 -2
  115. package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
  116. package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
  117. package/wasm/snippets/alpha2-wasm-57b04ecc6db57e1f/inline2.js +0 -52
  118. /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
  119. /package/wasm/snippets/{alpha2-wasm-57b04ecc6db57e1f → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
package/dist/edit.js CHANGED
@@ -1,54 +1,32 @@
1
1
  /**
2
- * Document editing operations: split, trim, ripple, roll, slip, slide,
3
- * retime, move (one clip or several at once), and the three ways to put a
4
- * clip down (insert, overwrite, append), as pure functions from one valid
5
- * project to another.
2
+ * Document editing operations (split, trim, ripple, roll, slip, slide, retime, move, insert,
3
+ * overwrite, append) as pure functions from one valid project to another.
6
4
  *
7
- * Each operation keeps the document's invariants the way the engine
8
- * specifies them (the cases in `tests/cases/edit-corpus.json`), returns a
9
- * new project that passes {@link validateProject}, or a typed error, and never
10
- * changes its input. History, selection, and snapping stay with the host: a
11
- * host keeps the projects it has returned to undo.
5
+ * Each returns a new project that passes {@link validateProject}, or a typed error, and never
6
+ * modifies its input. Undo history, selection and snapping are the host's job.
12
7
  *
13
- * Times are ticks. A clip keeps its speed across an edit: the source range
14
- * follows the clip's own mapping, so a reversed clip trimmed at its start
15
- * loses the end of its source.
8
+ * Times, deltas and durations are whole ticks (`invalid_time` otherwise). A clip keeps its speed
9
+ * across an edit, so a reversed clip trimmed at its start loses the end of its source.
16
10
  *
17
- * A clip's composition keeps its own time. Moving a clip keeps its offset,
18
- * so the composition's animation moves with it; trimming its start by `delta`
19
- * adds `delta * scale` to the offset, so what remains stays where it was; and
20
- * splitting gives the right half a copy of the composition and of the group
21
- * definitions it draws ({@link copyComposition}), starting where the cut
22
- * falls in it.
11
+ * A clip's composition keeps its own time: moving a clip moves its animation with it, trimming the
12
+ * start by `delta` adds `delta * scale` to the offset, and splitting gives the right half a copy
13
+ * ({@link copyComposition}).
23
14
  *
24
- * A source's length is what its fingerprint records (`duration_ticks`); an
25
- * edit that would read past it, or before the source's start, is refused
26
- * (`outside_source`). A source without a recorded length is bounded only at
27
- * its start.
15
+ * Edits may not read before a source's start or past its fingerprint's `duration_ticks`
16
+ * (`outside_source`).
28
17
  *
29
- * Ripple edits (`insert`, `rippleTrim`, `rippleDelete`) move later content on
30
- * the edited track and, with `syncTracks`, on those tracks too, by the same
31
- * amount, so their events keep their offsets to each other. A participating
32
- * track whose clip, transition, or caption cue lies across the edit point
33
- * refuses the whole edit (`sync_conflict`): nothing is split or trimmed on a
34
- * track the edit does not target. So does one where content the edit pulls
35
- * earlier would land on content that stays.
18
+ * Ripple edits move later content on the edited track and on `syncTracks` by the same amount. A
19
+ * sync track with content across the edit point, or where pulled content would land on content
20
+ * that stays, refuses the whole edit (`sync_conflict`).
36
21
  *
37
- * Times, deltas, and durations are whole ticks; any other number is refused
38
- * (`invalid_time`).
39
- *
40
- * A batch of edits valid only as a whole runs in {@link deferValidation}, whose caller validates
41
- * the project it keeps instead of each edit validating its own.
22
+ * Use {@link deferValidation} for a batch of edits that is valid only as a whole.
42
23
  */
43
24
  import { validateProject } from "./project.js";
44
25
  /**
45
- * Cuts a clip in two at `at`. The left part keeps the clip's id, its incoming transitions, and its
46
- * fade in; the right part is `newId`, with its outgoing transitions and fade out. The right part
47
- * shows a copy of the clip's composition and of the group definitions it draws ({@link
48
- * copyComposition}), each copy's id the original's root and `newId` joined by `~` (numbered if
49
- * taken), so editing one half does not edit the other. Refused inside a transition or a fade (a
50
- * fade is a ramp from the clip's edge, which neither half could continue), for a clip that is
51
- * another clip's matte, and for a loop.
26
+ * Splits a clip at `at`. The left part keeps the id, incoming transitions and fade in; the right
27
+ * part becomes `newId` with outgoing transitions, fade out, and its own copy of the composition
28
+ * ({@link copyComposition}). Refused inside a transition or fade, for a matte source, and for a
29
+ * loop.
52
30
  */
53
31
  export function split(project, clipId, at, newId) {
54
32
  const time = notTicks(at, "the split time");
@@ -80,7 +58,6 @@ export function split(project, clipId, at, newId) {
80
58
  if (sources === undefined) {
81
59
  return failure("unsupported_time_map", `a loop cannot be split`);
82
60
  }
83
- // The fade in stays at the clip's start, the fade out at its end.
84
61
  const audio = clip.audio;
85
62
  const left = {
86
63
  ...clip,
@@ -122,9 +99,8 @@ export function split(project, clipId, at, newId) {
122
99
  }));
123
100
  }
124
101
  /**
125
- * Moves one edge of a clip to `to`, keeping the clip's speed. Refused when the edge is in a
126
- * transition, before the timeline's start, and where the clip would read further outside its
127
- * source (`outside_source`); a loop's start cannot move.
102
+ * Moves one edge of a clip to `to`, keeping its speed. Refused for an edge in a transition, before
103
+ * the timeline start, past the source (`outside_source`), or at a loop's start.
128
104
  */
129
105
  export function trim(project, clipId, edge, to) {
130
106
  const time = notTicks(to, "the trim time");
@@ -136,11 +112,8 @@ export function trim(project, clipId, edge, to) {
136
112
  return finish(replaceClip(project, trimmed.track, trimmed.clip));
137
113
  }
138
114
  /**
139
- * Trims like {@link trim} and moves the clips after the trimmed edge on the
140
- * same track by the same amount, so nothing after it gains or loses a gap.
141
- * Trimming the start keeps the clip's start in place and moves its end, so
142
- * `to` may be before the timeline's start: the head grows by as much as the
143
- * source has before it.
115
+ * Trims like {@link trim} and shifts later clips on the track by the same amount. A start trim
116
+ * keeps the clip's start in place, so `to` may be before the timeline start.
144
117
  */
145
118
  export function rippleTrim(project, clipId, edge, to, options = {}) {
146
119
  const time = notTicks(to, "the trim time");
@@ -157,7 +130,7 @@ export function rippleTrim(project, clipId, edge, to, options = {}) {
157
130
  delta = to - before.end;
158
131
  }
159
132
  else {
160
- // The head is trimmed, and the clip then slides back to where it began.
133
+ // Trim the head, then slide the clip back to its original start.
161
134
  delta = before.start - to;
162
135
  edited = shift(clip, delta);
163
136
  }
@@ -180,9 +153,8 @@ export function rippleTrim(project, clipId, edge, to, options = {}) {
180
153
  }));
181
154
  }
182
155
  /**
183
- * Removes a clip and its transitions, and moves the clips after it on the same track back by the
184
- * time it alone occupied ({@link rippleDeleteSpan}). Refused for a clip that is another clip's
185
- * matte, and when a track in `syncTracks` has content in that time.
156
+ * Removes a clip and its transitions and closes the gap ({@link rippleDeleteSpan}). Refused for a
157
+ * matte source, and when a sync track has content in that span.
186
158
  */
187
159
  export function rippleDelete(project, clipId, options = {}) {
188
160
  const found = locate(project, clipId);
@@ -205,7 +177,6 @@ export function rippleDelete(project, clipId, options = {}) {
205
177
  .map((transition) => transition.timeline_range.start >= range.start
206
178
  ? shiftTransition(transition, delta)
207
179
  : transition);
208
- // The time the clip frees must be empty on the tracks that close it too.
209
180
  for (const other of syncTracksOf(project, options.syncTracks, track.id))
210
181
  if (occupies(other, gap))
211
182
  return failure("sync_conflict", `track ${other.id} has content in the time the delete closes`);
@@ -215,11 +186,9 @@ export function rippleDelete(project, clipId, options = {}) {
215
186
  return finish(replaceTrack(synced.project, { ...track, clips, transitions }));
216
187
  }
217
188
  /**
218
- * The time {@link rippleDelete} closes for clip `clipId`: the part of its span no other clip on its
219
- * track shares, from where the clips that start before it end (an incoming dissolve's overlap is
220
- * shared) to where the next clip starts. Empty (`start === end`) when other clips cover it all;
221
- * `undefined` for an unknown clip. A host moving its own timeline items (markers) with the delete
222
- * moves those from `start` on back by its length.
189
+ * The span {@link rippleDelete} closes: the part of the clip's span no other clip on its track
190
+ * shares. Empty when fully covered; `undefined` for an unknown clip. Hosts can use it to move their
191
+ * own timeline items, such as markers.
223
192
  */
224
193
  export function rippleDeleteSpan(project, clipId) {
225
194
  const found = locate(project, clipId);
@@ -241,10 +210,8 @@ function aloneSpan(track, clip) {
241
210
  return { start, end: Math.max(start, end) };
242
211
  }
243
212
  /**
244
- * Moves the cut between clip `leftId` and the clip `rightId` that starts where it ends to `at`: the
245
- * left clip ends there and the right one starts there, each keeping its speed, so the two together
246
- * span what they did. Refused unless the clips meet, when a transition joins them, and when the cut
247
- * would empty either.
213
+ * Moves the cut between adjacent clips `leftId` and `rightId` to `at`, each keeping its speed.
214
+ * Refused unless they meet, when a transition joins them, or when either would become empty.
248
215
  */
249
216
  export function rollTrim(project, leftId, rightId, at) {
250
217
  const time = notTicks(at, "the cut");
@@ -279,10 +246,7 @@ export function rollTrim(project, leftId, rightId, at) {
279
246
  : candidate),
280
247
  }));
281
248
  }
282
- /**
283
- * How far {@link slip} may move a clip's source window, in source ticks: to the source's start one
284
- * way and to its recorded end the other (unbounded without one).
285
- */
249
+ /** Source-tick range {@link slip} allows, bounded by the source's start and recorded end. */
286
250
  export function slipLimits(project, clipId) {
287
251
  const found = locate(project, clipId);
288
252
  if (!found.ok)
@@ -298,9 +262,8 @@ export function slipLimits(project, clipId) {
298
262
  };
299
263
  }
300
264
  /**
301
- * Shows another part of a clip's source in the same place: its source window, and a frozen clip's
302
- * instant, move by `delta` source ticks; the clip's place, length, speed, keyframes, and
303
- * composition stay. Refused past the source's start or recorded end.
265
+ * Moves a clip's source window (or a frozen clip's instant) by `delta` source ticks, leaving its
266
+ * timeline placement unchanged. Refused past the source's start or recorded end.
304
267
  */
305
268
  export function slip(project, clipId, delta) {
306
269
  const time = notTicks(delta, "the slip");
@@ -326,11 +289,9 @@ export function slip(project, clipId, delta) {
326
289
  }));
327
290
  }
328
291
  /**
329
- * How far {@link slide} may move a clip, in timeline ticks: until a neighbour it meets would be
330
- * empty, read outside its source, or uncover a transition at its far edge, or until it reaches the
331
- * content across a gap. Nothing but 0 when a neighbour's edge it trims cannot move (a transition
332
- * there, a loop's start); refused (`in_transition`) for a clip in a transition, which slide never
333
- * moves.
292
+ * Timeline-tick range {@link slide} allows, limited by neighbours becoming empty, reading outside
293
+ * their source or uncovering a transition, and by content across a gap. Only 0 when a neighbour's
294
+ * edge cannot move; refused (`in_transition`) for a clip in a transition.
334
295
  */
335
296
  export function slideLimits(project, clipId) {
336
297
  const found = locate(project, clipId);
@@ -347,7 +308,7 @@ export function slideLimits(project, clipId) {
347
308
  const edges = transitionsOf(track, left.id).map((t) => t.timeline_range);
348
309
  if (edges.some((t) => t.end >= left.timeline_range.end))
349
310
  return { ok: true, min: 0, max: 0 };
350
- // Its end may not pass back over the transition at its start.
311
+ // The left neighbour's end may not pass back over its transitions.
351
312
  min = Math.max(min, left.timeline_range.start + 1 - range.start, ...edges.map((t) => t.end - range.start));
352
313
  const room = extensionRoom(project, left, "end");
353
314
  if (room !== undefined)
@@ -366,12 +327,9 @@ export function slideLimits(project, clipId) {
366
327
  return { ok: true, min, max };
367
328
  }
368
329
  /**
369
- * Moves a clip by `delta` between its neighbours, which give and take the time: a clip that ends
370
- * where it starts is trimmed at its end, and one that starts where it ends at its start, each
371
- * keeping its speed, so the three together span what they did. A side with no clip meeting it is a
372
- * gap the clip moves into or leaves. The clip keeps its source window, keyframes (moved with it),
373
- * and composition. Refused in a transition, when a neighbour would be empty or read outside its
374
- * source, and past the content across a gap.
330
+ * Moves a clip by `delta`, trimming the adjacent neighbours so the total span is unchanged; a side
331
+ * without an adjacent clip is a gap. The clip keeps its source window and composition. Refused
332
+ * within the limits described by {@link slideLimits}.
375
333
  */
376
334
  export function slide(project, clipId, delta) {
377
335
  const time = notTicks(delta, "the slide");
@@ -407,10 +365,9 @@ export function slide(project, clipId, delta) {
407
365
  }));
408
366
  }
409
367
  /**
410
- * Gives a clip a new length on the timeline, `duration` ticks from where it starts. A clip that
411
- * plays forward or reversed plays its whole source window over it, so its speed becomes the ratio
412
- * of the two; a frozen clip holds its instant longer or shorter, and a loop plays more or fewer
413
- * passes. Refused when the clip's end is in a transition.
368
+ * Sets a clip's timeline length to `duration`. Forward and reversed clips change speed to fit the
369
+ * same source window; frozen clips hold longer or shorter; loops play more or fewer passes.
370
+ * Refused when the clip's end is in a transition.
414
371
  */
415
372
  export function retime(project, clipId, duration, options = {}) {
416
373
  const found = locate(project, clipId);
@@ -485,10 +442,8 @@ export function retime(project, clipId, duration, options = {}) {
485
442
  }));
486
443
  }
487
444
  /**
488
- * Puts `clip` on track `trackId` at `at` and moves everything from `at` on, on that track and on
489
- * `syncTracks`, later by its length. A clip across `at` on the target track is split there first;
490
- * its right part is `splitId`. Refused (`needs_id`) when more than one clip is across `at`, as
491
- * overlapping audio clips can be.
445
+ * Inserts `clip` at `at`, pushing later content on the track and `syncTracks` by its length. A clip
446
+ * across `at` is split first, its right part becoming `splitId`; `needs_id` when more than one is.
492
447
  */
493
448
  export function insert(project, trackId, clip, at, options = {}) {
494
449
  const placed = placeAt(project, trackId, clip, at);
@@ -523,11 +478,10 @@ export function insert(project, trackId, clip, at, options = {}) {
523
478
  }));
524
479
  }
525
480
  /**
526
- * Puts `clip` on track `trackId` at `at` in place of whatever that track shows there: clips inside
527
- * the range are removed, clips across its edges are trimmed back to it (one across both is split;
528
- * its right part is `splitId`). Nothing moves and no other track changes. Refused where a
529
- * transition or a matte source would be cut, and (`needs_id`) when more than one clip is across
530
- * both edges.
481
+ * Places `clip` at `at`, replacing whatever the track shows there. Clips inside are removed, clips
482
+ * across an edge are trimmed, and a clip across both is split (right part `splitId`). Refused where
483
+ * a transition or matte source would be cut, and (`needs_id`) when more than one clip spans both
484
+ * edges.
531
485
  */
532
486
  export function overwrite(project, trackId, clip, at, options = {}) {
533
487
  const placed = placeAt(project, trackId, clip, at);
@@ -573,7 +527,7 @@ export function overwrite(project, trackId, clip, at, options = {}) {
573
527
  clips.push(placed.clip);
574
528
  return finish(replaceTrack(edited, { ...track, clips }));
575
529
  }
576
- /** Puts `clip` on track `trackId` right after the last clip there, or at 0. */
530
+ /** Places `clip` after the track's last clip, or at 0. */
577
531
  export function append(project, trackId, clip) {
578
532
  const track = project.timeline.tracks.find((t) => t.id === trackId);
579
533
  if (!track)
@@ -581,10 +535,7 @@ export function append(project, trackId, clip) {
581
535
  const end = Math.max(0, ...(track.clips ?? []).map((c) => c.timeline_range.end));
582
536
  return overwrite(project, trackId, clip, end);
583
537
  }
584
- /**
585
- * `clip` placed at `at` on track `trackId`, keeping its length, after the checks every placement
586
- * makes.
587
- */
538
+ /** Places `clip` at `at` after the checks every placement makes. */
588
539
  function placeAt(project, trackId, clip, at) {
589
540
  const track = project.timeline.tracks.find((t) => t.id === trackId);
590
541
  if (!track)
@@ -622,8 +573,8 @@ function occupies(track, range) {
622
573
  (track.captions?.cues ?? []).some((c) => meets(c.timeline_range)));
623
574
  }
624
575
  /**
625
- * `project` with the content of tracks `ids` (but `edited`) from `pivot` on moved by `delta`, or a
626
- * refusal when one of them has content across `pivot`.
576
+ * Shifts content from `pivot` on by `delta` on tracks `ids` other than `edited`; refuses when one
577
+ * has content across `pivot`.
627
578
  */
628
579
  function rippleSyncTracks(project, ids, edited, pivot, delta) {
629
580
  if (delta === 0)
@@ -659,10 +610,8 @@ function rippleSyncTracks(project, ids, edited, pivot, delta) {
659
610
  return { ok: true, project: result };
660
611
  }
661
612
  /**
662
- * Whether moving the content of `track` that starts at or after `pivot` by `delta` would put some
663
- * of it on or before content that starts before `pivot` and ended where it started or earlier:
664
- * content apart before the edit would overlap or change order. Content that already overlapped
665
- * (audio clips may) is left as it was. `except` is the edited clip, which the edit itself shortens.
613
+ * Whether shifting content from `pivot` on by `delta` would make previously separate content
614
+ * overlap or reorder. Pre-existing overlaps are ignored; `except` is the edited clip.
666
615
  */
667
616
  function pullsOnto(track, pivot, delta, except) {
668
617
  if (delta >= 0)
@@ -683,7 +632,7 @@ function pullsOnto(track, pivot, delta, except) {
683
632
  return spans.some((r) => {
684
633
  if (r.start < pivot)
685
634
  return false;
686
- // The first end after where this lands; a collision when it is no later than where it was.
635
+ // Find the first end after the landing point; it collides if that end is not after `r.start`.
687
636
  let low = 0;
688
637
  let high = ends.length;
689
638
  while (low < high) {
@@ -699,24 +648,22 @@ function pullsOnto(track, pivot, delta, except) {
699
648
  function pulledOnto(track) {
700
649
  return failure("sync_conflict", `track ${track.id} has content the edit would pull onto content that stays`);
701
650
  }
702
- /** Moves a clip to start at `to` on its track. Refused while in a transition. */
651
+ /** Moves a clip to start at `to`. Refused while in a transition. */
703
652
  export function move(project, clipId, to) {
704
653
  const moved = relocate(project, { clip: clipId, to });
705
654
  return moved.ok ? finish(moved.project) : moved;
706
655
  }
707
656
  /**
708
- * Moves a clip to another track, starting at `to` (by default where it starts now). Refused while
709
- * in a transition, and onto a track whose kind does not take its source.
657
+ * Moves a clip to another track, at `to` or its current start. Refused while in a transition or
658
+ * onto an incompatible track.
710
659
  */
711
660
  export function moveToTrack(project, clipId, trackId, to) {
712
661
  const moved = relocate(project, { clip: clipId, track: trackId, to });
713
662
  return moved.ok ? finish(moved.project) : moved;
714
663
  }
715
664
  /**
716
- * Moves several clips at once, each as {@link move} or {@link moveToTrack} would. Only the result
717
- * is checked, so clips that move together may pass through where the others were: a selection moves
718
- * as one whatever order its moves come in. Refused for a clip listed twice (`duplicate_id`), and
719
- * wherever one of the moves alone is refused.
665
+ * Moves several clips at once. Only the final result is checked, so the order of moves does not
666
+ * matter. Refused for a clip listed twice (`duplicate_id`) or wherever a single move would be.
720
667
  */
721
668
  export function moveClips(project, moves) {
722
669
  const moved = new Set();
@@ -733,7 +680,7 @@ export function moveClips(project, moves) {
733
680
  }
734
681
  return finish(edited);
735
682
  }
736
- /** `project` with one clip moved, not yet checked as a whole. */
683
+ /** Moves one clip without validating the whole project. */
737
684
  function relocate(project, { clip: clipId, to, track: trackId }) {
738
685
  const time = notTicks(to, "the move target");
739
686
  if (time)
@@ -786,21 +733,18 @@ function locate(project, clipId) {
786
733
  function failure(code, message) {
787
734
  return { ok: false, error: { code, message } };
788
735
  }
789
- /** A refusal when `value`, a time argument, is given and is not a whole number of ticks. */
736
+ /** Refuses a provided time argument that is not whole ticks. */
790
737
  function notTicks(value, what) {
791
738
  if (value === undefined || Number.isSafeInteger(value))
792
739
  return undefined;
793
740
  return failure("invalid_time", `${what} ${value} is not a whole number of ticks`);
794
741
  }
795
- /** How many {@link deferValidation} calls are running: while any is, edits do not check results. */
742
+ /** Nesting depth of {@link deferValidation}. */
796
743
  let deferring = 0;
797
744
  /**
798
- * Runs `run`, in which the edits do not check their results with {@link validateProject}: each
799
- * still refuses what it refuses itself (`sync_conflict`, `outside_source`, ...), but returns the
800
- * project it made even when that breaks a model rule, and the caller validates the project it
801
- * keeps. For a batch of edits valid only as a whole, such as an editor transaction, which then pays
802
- * for one validation instead of one per edit. `run` is synchronous; nested calls and a throw end
803
- * the deferral where they began.
745
+ * Runs `run` with {@link validateProject} skipped after each edit. Edits still apply their own
746
+ * checks (`sync_conflict`, `outside_source`, ...); the caller validates the final project. `run` is
747
+ * synchronous and may nest.
804
748
  */
805
749
  export function deferValidation(run) {
806
750
  deferring += 1;
@@ -827,15 +771,14 @@ function finish(project) {
827
771
  }
828
772
  return { ok: true, project };
829
773
  }
830
- /** The length a source's fingerprint records, in ticks, if any. */
774
+ /** Source length in ticks from its fingerprint, if recorded. */
831
775
  function sourceLength(project, sourceId) {
832
776
  const source = project.sources.find((candidate) => candidate.id === sourceId);
833
777
  return source?.fingerprint?.duration_ticks ?? undefined;
834
778
  }
835
779
  /**
836
- * A refusal when `range` reads before the source's start or past its recorded end; with `before`,
837
- * the range it replaces, only when an edge reads further outside than it did, so an edit can still
838
- * shorten a clip that already reads past a source found shorter than it was.
780
+ * Refuses a `range` outside the source. With `before`, only an edge that moves further outside is
781
+ * refused, so a clip already past a shorter source can still be shortened.
839
782
  */
840
783
  function outsideSource(project, sourceId, range, before) {
841
784
  const length = sourceLength(project, sourceId);
@@ -848,9 +791,8 @@ function outsideSource(project, sourceId, range, before) {
848
791
  return undefined;
849
792
  }
850
793
  /**
851
- * The clips meeting `clip` on its track (`left` ends where it starts, `right` starts where it
852
- * ends), and how far the content beside it reaches: `before` is where the content before it ends,
853
- * `after` where the content after it starts.
794
+ * Adjacent clips (`left`, `right`) and the nearest content edges on either side (`before`,
795
+ * `after`).
854
796
  */
855
797
  function neighbours(track, clip) {
856
798
  const range = clip.timeline_range;
@@ -874,17 +816,14 @@ function neighbours(track, clip) {
874
816
  after,
875
817
  };
876
818
  }
877
- /**
878
- * How many timeline ticks `clip` can grow at `edge` before it reads outside its source, at its
879
- * speed; `undefined` when unbounded.
880
- */
819
+ /** Timeline ticks `clip` can grow at `edge` before leaving its source; `undefined` if unbounded. */
881
820
  function extensionRoom(project, clip, edge) {
882
821
  const map = clip.time_map ?? { type: "forward" };
883
822
  if (map.type === "freeze" || map.type === "loop")
884
823
  return undefined;
885
824
  const source = clip.source_range;
886
825
  const timeline = clip.timeline_range;
887
- // Which end of the source window the edge reads: a reversed clip's end reads its source start.
826
+ // A reversed clip's end reads its source start.
888
827
  const readsStart = (edge === "start") === (map.type === "forward");
889
828
  const available = readsStart
890
829
  ? source.start
@@ -894,13 +833,10 @@ function extensionRoom(project, clip, edge) {
894
833
  })();
895
834
  if (available === undefined)
896
835
  return undefined;
897
- // The largest growth whose source edge stays inside: floor(available * T / S).
836
+ // floor(available * T / S).
898
837
  return stretched(available, timeline.end - timeline.start, source.end - source.start);
899
838
  }
900
- /**
901
- * `value` with every keyframe time `t` of every animated value in it moved to `start + floor((t -
902
- * start) * to / from)`: stretched from `start` by `to / from`.
903
- */
839
+ /** Maps every keyframe time `t` to `start + floor((t - start) * to / from)`. */
904
840
  function stretchKeyframes(value, start, to, from) {
905
841
  if (Array.isArray(value))
906
842
  return value.map((item) => stretchKeyframes(item, start, to, from));
@@ -923,12 +859,11 @@ function stretchKeyframes(value, start, to, from) {
923
859
  stretchKeyframes(field, start, to, from),
924
860
  ]));
925
861
  }
926
- /** The largest term a composition's time scale holds. */
862
+ /** Largest term a composition time scale may hold. */
927
863
  const MAX_SCALE_TERM = 0xffff_ffff;
928
864
  /**
929
- * `scale * from / to` in lowest terms; when a term exceeds what the model holds, the nearest
930
- * fraction whose terms fit (the closest convergent), so the composition keeps to the clip within a
931
- * fraction of a tick.
865
+ * `scale * from / to` in lowest terms, or the closest convergent whose terms fit
866
+ * {@link MAX_SCALE_TERM}.
932
867
  */
933
868
  function rescaled(scale, from, to) {
934
869
  let num = BigInt(scale.num) * BigInt(from);
@@ -984,27 +919,21 @@ function replaceClip(project, track, clip) {
984
919
  function offset(range, delta) {
985
920
  return { start: range.start + delta, end: range.end + delta };
986
921
  }
987
- /**
988
- * A clip moved by `delta` on the timeline. Keyframe times are timeline times, so its animations
989
- * move with it. Its composition keeps its own time, and so is left as it is.
990
- */
922
+ /** Moves a clip and its keyframes by `delta`; the composition keeps its own time. */
991
923
  function shift(clip, delta) {
992
924
  return {
993
925
  ...shiftKeyframes(clip, delta),
994
926
  timeline_range: offset(clip.timeline_range, delta),
995
927
  };
996
928
  }
997
- /** A transition moved by `delta`, its animated parameters with it. */
929
+ /** Moves a transition and its keyframes by `delta`. */
998
930
  function shiftTransition(transition, delta) {
999
931
  return {
1000
932
  ...shiftKeyframes(transition, delta),
1001
933
  timeline_range: offset(transition.timeline_range, delta),
1002
934
  };
1003
935
  }
1004
- /**
1005
- * `value` with the time of every keyframe of every animated value in it moved by `delta`: whatever
1006
- * fields are animated, now or later.
1007
- */
936
+ /** Moves every keyframe time in `value` by `delta`, whatever fields are animated. */
1008
937
  function shiftKeyframes(value, delta) {
1009
938
  if (delta === 0)
1010
939
  return value;
@@ -1038,9 +967,8 @@ function shiftTransitions(track, from, delta) {
1038
967
  : transition);
1039
968
  }
1040
969
  /**
1041
- * The source instant at `elapsed` timeline ticks into a stretched clip: `floor(elapsed * S / T)`
1042
- * source ticks past the source start, in exact integer arithmetic, as the engine maps it. `elapsed`
1043
- * is negative for a time before the clip, where a trim extends it.
970
+ * `floor(elapsed * S / T)` in exact integer arithmetic, matching the engine. `elapsed` may be
971
+ * negative for a trim that extends the clip.
1044
972
  */
1045
973
  function stretched(elapsed, source, timeline) {
1046
974
  const numerator = BigInt(elapsed) * BigInt(source);
@@ -1049,7 +977,7 @@ function stretched(elapsed, source, timeline) {
1049
977
  // BigInt division truncates toward zero; below zero, floor is one less.
1050
978
  return Number(numerator % denominator < 0n ? quotient - 1n : quotient);
1051
979
  }
1052
- /** The source ranges of a clip's two halves at `at`, or `undefined` for a loop. */
980
+ /** Source ranges of a clip's two halves at `at`, or `undefined` for a loop. */
1053
981
  function splitSource(clip, at) {
1054
982
  const timeline = clip.timeline_range;
1055
983
  const source = clip.source_range;
@@ -1080,9 +1008,8 @@ function splitSource(clip, at) {
1080
1008
  }
1081
1009
  }
1082
1010
  /**
1083
- * Clip `clipId` with its `edge` moved to `to` at its speed, or why it cannot be. `ripple` is for a
1084
- * start trim that then slides the clip back to where it began, so `to` may be before the
1085
- * timeline's start.
1011
+ * Clip `clipId` with `edge` moved to `to` at its speed, or a refusal. With `ripple`, a start trim
1012
+ * slides back afterwards, so `to` may precede the timeline start.
1086
1013
  */
1087
1014
  function trimmedClip(project, clipId, edge, to, ripple = false) {
1088
1015
  const found = locate(project, clipId);
@@ -1127,10 +1054,7 @@ function trimmedClip(project, clipId, edge, to, ripple = false) {
1127
1054
  },
1128
1055
  };
1129
1056
  }
1130
- /**
1131
- * A composition reference for a clip whose start moved `delta` ticks later (earlier when negative):
1132
- * its offset moves by `delta * scale`, rounded down as the engine maps composition time.
1133
- */
1057
+ /** Advances a composition offset by `delta * scale`, rounded down as the engine does. */
1134
1058
  function advance(reference, delta) {
1135
1059
  if (delta === 0)
1136
1060
  return reference;
@@ -1139,16 +1063,12 @@ function advance(reference, delta) {
1139
1063
  return { ...reference, offset };
1140
1064
  }
1141
1065
  /**
1142
- * `project` with a copy of composition `id` for clip `clipId` to show, so that editing the clip's
1143
- * graph edits no other clip's: the composition and every group definition it draws, through group
1144
- * nodes inside group definitions too, each under the first free id of `<root>~<clipId>`,
1145
- * `<root>~<clipId>~2`, and so on, where `<root>` is the original's id up to its first `~` after
1146
- * the first character (a copy of a copy is named from the same root, so ids stay as long however
1147
- * often a clip's right part is split again), with the copies' group nodes drawing the copies. A
1148
- * definition drawn twice in it is copied once. Composition sources are Library items, shown as
1149
- * media are, and stay shared. `from` holds the compositions to copy, by default the project's own;
1150
- * a host pasting a clip whose composition the project no longer has passes those it kept. Returns
1151
- * the copy's id, and the id of each copy by its original's.
1066
+ * Copies composition `id` and every group definition it draws (recursively) so clip `clipId` can
1067
+ * be edited independently. Copies take the first free id of `<root>~<clipId>`, `<root>~<clipId>~2`
1068
+ * and so on, where `<root>` is the original's id up to its first `~` after the first character, so
1069
+ * repeated splits do not grow ids. Composition sources stay shared. `from` supplies the
1070
+ * compositions to copy (default: the project's), for pasting a clip whose composition was removed.
1071
+ * Returns the copy's id and a map from original to copy ids.
1152
1072
  */
1153
1073
  export function copyComposition(project, id, clipId, from = project.compositions ?? []) {
1154
1074
  const originals = new Map(from.map((composition) => [composition.id, composition]));
@@ -1198,9 +1118,8 @@ export function copyComposition(project, id, clipId, from = project.compositions
1198
1118
  };
1199
1119
  }
1200
1120
  /**
1201
- * The source range of a clip retimed to `start..end` at its own speed, or `undefined` when a loop's
1202
- * start would move. Each edge of a forward or reverse clip's source is where the clip maps that
1203
- * edge's timeline time, as a split cuts it, so the edge the trim leaves stays exactly in place.
1121
+ * Source range of a clip trimmed to `start..end` at its own speed, or `undefined` when a loop's
1122
+ * start would move. Edges are mapped as a split maps them, so the untouched edge stays exact.
1204
1123
  */
1205
1124
  function trimmedSource(clip, start, end) {
1206
1125
  const timeline = clip.timeline_range;
@@ -1208,7 +1127,6 @@ function trimmedSource(clip, start, end) {
1208
1127
  const length = timeline.end - timeline.start;
1209
1128
  const sourceLength = source.end - source.start;
1210
1129
  const map = clip.time_map ?? { type: "forward" };
1211
- // The source instant `elapsed` timeline ticks past the clip's start.
1212
1130
  const at = (elapsed) => source.start + stretched(elapsed, sourceLength, length);
1213
1131
  switch (map.type) {
1214
1132
  case "forward":
@@ -1217,7 +1135,7 @@ function trimmedSource(clip, start, end) {
1217
1135
  end: at(end - timeline.start),
1218
1136
  };
1219
1137
  case "reverse":
1220
- // The timeline's end plays the source's start.
1138
+ // Reversed: the timeline end plays the source start.
1221
1139
  return { start: at(timeline.end - end), end: at(timeline.end - start) };
1222
1140
  case "freeze":
1223
1141
  return source;