@nodetool-ai/timeline 0.8.2 → 0.8.4-a13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/README.md +1 -0
  2. package/dist/.nodetool-build-stamp +1 -1
  3. package/dist/animation/compile.d.ts.map +1 -1
  4. package/dist/animation/compile.js +5 -1
  5. package/dist/animation/compile.js.map +1 -1
  6. package/dist/audioFade.d.ts +4 -2
  7. package/dist/audioFade.d.ts.map +1 -1
  8. package/dist/audioFade.js +4 -2
  9. package/dist/audioFade.js.map +1 -1
  10. package/dist/clipAudio.d.ts +32 -0
  11. package/dist/clipAudio.d.ts.map +1 -0
  12. package/dist/clipAudio.js +70 -0
  13. package/dist/clipAudio.js.map +1 -0
  14. package/dist/clipSpeed.d.ts +17 -0
  15. package/dist/clipSpeed.d.ts.map +1 -0
  16. package/dist/clipSpeed.js +58 -0
  17. package/dist/clipSpeed.js.map +1 -0
  18. package/dist/defaults.d.ts +6 -1
  19. package/dist/defaults.d.ts.map +1 -1
  20. package/dist/defaults.js +38 -0
  21. package/dist/defaults.js.map +1 -1
  22. package/dist/dropResolve.d.ts +14 -6
  23. package/dist/dropResolve.d.ts.map +1 -1
  24. package/dist/dropResolve.js +113 -37
  25. package/dist/dropResolve.js.map +1 -1
  26. package/dist/finish-storyboard.d.ts.map +1 -1
  27. package/dist/finish-storyboard.js +63 -43
  28. package/dist/finish-storyboard.js.map +1 -1
  29. package/dist/fonts/google-fonts-node.d.ts.map +1 -1
  30. package/dist/fonts/google-fonts-node.js +2 -1
  31. package/dist/fonts/google-fonts-node.js.map +1 -1
  32. package/dist/fonts/google-fonts.d.ts +6 -0
  33. package/dist/fonts/google-fonts.d.ts.map +1 -1
  34. package/dist/fonts/google-fonts.js +7 -1
  35. package/dist/fonts/google-fonts.js.map +1 -1
  36. package/dist/fonts/register-node.d.ts.map +1 -1
  37. package/dist/fonts/register-node.js +2 -1
  38. package/dist/fonts/register-node.js.map +1 -1
  39. package/dist/group.d.ts +16 -4
  40. package/dist/group.d.ts.map +1 -1
  41. package/dist/group.js +53 -6
  42. package/dist/group.js.map +1 -1
  43. package/dist/index.d.ts +4 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +4 -0
  46. package/dist/index.js.map +1 -1
  47. package/dist/interchange.d.ts +8 -0
  48. package/dist/interchange.d.ts.map +1 -1
  49. package/dist/interchange.js +225 -27
  50. package/dist/interchange.js.map +1 -1
  51. package/dist/interchangeImport.d.ts +88 -0
  52. package/dist/interchangeImport.d.ts.map +1 -0
  53. package/dist/interchangeImport.js +498 -0
  54. package/dist/interchangeImport.js.map +1 -0
  55. package/dist/keyframes.d.ts +12 -1
  56. package/dist/keyframes.d.ts.map +1 -1
  57. package/dist/keyframes.js +78 -21
  58. package/dist/keyframes.js.map +1 -1
  59. package/dist/linked.js +1 -1
  60. package/dist/mediaTrack.d.ts +11 -0
  61. package/dist/mediaTrack.d.ts.map +1 -1
  62. package/dist/mediaTrack.js +25 -0
  63. package/dist/mediaTrack.js.map +1 -1
  64. package/dist/midi/edit.d.ts +5 -0
  65. package/dist/midi/edit.d.ts.map +1 -1
  66. package/dist/midi/edit.js +2 -1
  67. package/dist/midi/edit.js.map +1 -1
  68. package/dist/midi/grid.d.ts.map +1 -1
  69. package/dist/midi/grid.js +8 -4
  70. package/dist/midi/grid.js.map +1 -1
  71. package/dist/midi/tempo.d.ts.map +1 -1
  72. package/dist/midi/tempo.js +8 -0
  73. package/dist/midi/tempo.js.map +1 -1
  74. package/dist/ops/apply.d.ts +9 -0
  75. package/dist/ops/apply.d.ts.map +1 -1
  76. package/dist/ops/apply.js +1822 -1426
  77. package/dist/ops/apply.js.map +1 -1
  78. package/dist/ops/op.d.ts +3 -1
  79. package/dist/ops/op.d.ts.map +1 -1
  80. package/dist/ops/op.js.map +1 -1
  81. package/dist/ops/parse.d.ts.map +1 -1
  82. package/dist/ops/parse.js +318 -357
  83. package/dist/ops/parse.js.map +1 -1
  84. package/dist/render/cpuLegacyEffects.d.ts.map +1 -1
  85. package/dist/render/cpuLegacyEffects.js +58 -18
  86. package/dist/render/cpuLegacyEffects.js.map +1 -1
  87. package/dist/render/draw.d.ts +43 -1
  88. package/dist/render/draw.d.ts.map +1 -1
  89. package/dist/render/draw.js +123 -3
  90. package/dist/render/draw.js.map +1 -1
  91. package/dist/render/frameCompositor.d.ts +31 -3
  92. package/dist/render/frameCompositor.d.ts.map +1 -1
  93. package/dist/render/frameCompositor.js +58 -10
  94. package/dist/render/frameCompositor.js.map +1 -1
  95. package/dist/render/headlessRender.d.ts +85 -0
  96. package/dist/render/headlessRender.d.ts.map +1 -0
  97. package/dist/render/headlessRender.js +26 -0
  98. package/dist/render/headlessRender.js.map +1 -0
  99. package/dist/render/index.d.ts +1 -0
  100. package/dist/render/index.d.ts.map +1 -1
  101. package/dist/render/index.js +1 -0
  102. package/dist/render/index.js.map +1 -1
  103. package/dist/render/sceneModel.d.ts +20 -8
  104. package/dist/render/sceneModel.d.ts.map +1 -1
  105. package/dist/render/sceneModel.js +265 -89
  106. package/dist/render/sceneModel.js.map +1 -1
  107. package/dist/render/temporal.d.ts +9 -1
  108. package/dist/render/temporal.d.ts.map +1 -1
  109. package/dist/render/temporal.js +18 -1
  110. package/dist/render/temporal.js.map +1 -1
  111. package/dist/render/textLayout.d.ts +6 -0
  112. package/dist/render/textLayout.d.ts.map +1 -1
  113. package/dist/render/textLayout.js +13 -1
  114. package/dist/render/textLayout.js.map +1 -1
  115. package/dist/rippleEdit.d.ts +20 -3
  116. package/dist/rippleEdit.d.ts.map +1 -1
  117. package/dist/rippleEdit.js +89 -17
  118. package/dist/rippleEdit.js.map +1 -1
  119. package/dist/scene.d.ts +1 -0
  120. package/dist/scene.d.ts.map +1 -1
  121. package/dist/scene.js +1 -0
  122. package/dist/scene.js.map +1 -1
  123. package/dist/shotLink.d.ts +47 -0
  124. package/dist/shotLink.d.ts.map +1 -0
  125. package/dist/shotLink.js +92 -0
  126. package/dist/shotLink.js.map +1 -0
  127. package/dist/splitClip.d.ts.map +1 -1
  128. package/dist/splitClip.js +16 -2
  129. package/dist/splitClip.js.map +1 -1
  130. package/dist/storyboard.js +1 -1
  131. package/dist/takes.d.ts.map +1 -1
  132. package/dist/takes.js +15 -2
  133. package/dist/takes.js.map +1 -1
  134. package/dist/testing/host-ops.d.ts +16 -0
  135. package/dist/testing/host-ops.d.ts.map +1 -0
  136. package/dist/testing/host-ops.js +378 -0
  137. package/dist/testing/host-ops.js.map +1 -0
  138. package/dist/testing/index.d.ts +3 -0
  139. package/dist/testing/index.d.ts.map +1 -0
  140. package/dist/testing/index.js +3 -0
  141. package/dist/testing/index.js.map +1 -0
  142. package/dist/testing/ops.d.ts +30 -0
  143. package/dist/testing/ops.d.ts.map +1 -0
  144. package/dist/testing/ops.js +814 -0
  145. package/dist/testing/ops.js.map +1 -0
  146. package/dist/transitionAtCut.d.ts +29 -5
  147. package/dist/transitionAtCut.d.ts.map +1 -1
  148. package/dist/transitionAtCut.js +69 -33
  149. package/dist/transitionAtCut.js.map +1 -1
  150. package/dist/trimClip.d.ts +5 -8
  151. package/dist/trimClip.d.ts.map +1 -1
  152. package/dist/trimClip.js +38 -2
  153. package/dist/trimClip.js.map +1 -1
  154. package/dist/types.d.ts +62 -0
  155. package/dist/types.d.ts.map +1 -1
  156. package/dist/types.js +29 -0
  157. package/dist/types.js.map +1 -1
  158. package/package.json +11 -5
@@ -16,15 +16,28 @@ import { renderableReframe, resolveReframeCrop } from "../reframe.js";
16
16
  import { compileClipAnimations, hasActiveAnimationWindow, hasStaggeredAnimation, isIdentitySample, parseStaggerUnit, sampleAnimations } from "../animation/index.js";
17
17
  import { resolveAnimatedStyleTracks, resolveAnimatedTextContent, resolveAnimationLinks } from "../animation/index.js";
18
18
  import { clipSourceMsAt } from "../timeRemap.js";
19
+ import { effectiveAssetId } from "../clipAudio.js";
19
20
  import { resolveBeatAnimations } from "../animation/beat.js";
21
+ import { textStyleSignature } from "./draw.js";
20
22
  import { countTextStaggerUnits } from "./textLayout.js";
21
23
  import { buildTransformMatrix } from "./transform.js";
22
24
  import { resolveClipLayoutsWithDiagnostics } from "./layout.js";
23
25
  import { resolveCamera2D, sampleCamera2D } from "./spatial.js";
24
26
  import { expandTemporalClips, clipSteppedTime } from "./temporal.js";
25
27
  import { resolveTransition } from "./transition.js";
28
+ import { clipFadeGain, resolveClipFades } from "../audioFade.js";
26
29
  /** Clamp a resolved opacity into the range both compositors agree on. */
27
30
  const clamp01 = (v) => (v < 0 ? 0 : v > 1 ? 1 : v);
31
+ /**
32
+ * A visual clip's `fadeInMs`/`fadeOutMs` as an opacity gain at `currentTimeMs`.
33
+ * It is the envelope that ramps the clip's audio, so a clip with sound fades
34
+ * picture and sound together, along the same shape.
35
+ */
36
+ function clipFadeOpacity(clip, currentTimeMs) {
37
+ if (!clip.fadeInMs && !clip.fadeOutMs)
38
+ return 1;
39
+ return clipFadeGain(clip, clip.durationMs, currentTimeMs - clip.startMs);
40
+ }
28
41
  /**
29
42
  * Top-of-UI track (lowest `track.index`) renders on top in the composite —
30
43
  * matches Premiere / Resolve / FCP. The compositor draws layers from low z to
@@ -136,7 +149,7 @@ function resolveDocumentTransitions(clips, currentTimeMs) {
136
149
  const groupIds = new Set(clips.filter((clip) => clip.mediaType === "group").map((clip) => clip.id));
137
150
  const byTrack = new Map();
138
151
  for (const clip of clips) {
139
- if (clip.mediaType === "adjustment" || !isClipActive(clip, currentTimeMs))
152
+ if (clip.mediaType === "adjustment" || clip.hidden || !isClipActive(clip, currentTimeMs))
140
153
  continue;
141
154
  const parentId = clip.parentId && groupIds.has(clip.parentId) ? clip.parentId : undefined;
142
155
  let byParent = byTrack.get(clip.trackId);
@@ -161,18 +174,8 @@ function resolveDocumentTransitions(clips, currentTimeMs) {
161
174
  }
162
175
  return transitions;
163
176
  }
164
- /** The asset id that should be drawn for a clip in its current status. */
165
- export function effectiveAssetId(clip) {
166
- switch (clip.status) {
167
- case "generated":
168
- case "stale":
169
- case "locked":
170
- case "generating":
171
- return clip.currentAssetId;
172
- default:
173
- return undefined;
174
- }
175
- }
177
+ /** The status rule lives beside the audio rules that share it. */
178
+ export { effectiveAssetId };
176
179
  function resolveBlendMode(b) {
177
180
  return b ?? "normal";
178
181
  }
@@ -204,18 +207,49 @@ export function clipSourceTimeSec(clip, currentTimeMs) {
204
207
  export function bakedClipSourceTimeSec(clip, currentTimeMs) {
205
208
  return Math.max(0, (currentTimeMs - clip.startMs) / 1000);
206
209
  }
210
+ /** A pause at least this long between two words starts a new caption cue. */
211
+ export const CAPTION_CUE_GAP_MS = 700;
212
+ /** The most words one caption cue shows at a time. */
213
+ export const CAPTION_CUE_MAX_WORDS = 10;
214
+ /**
215
+ * Split a clip's words into cues, the runs shown on screen together: a cue
216
+ * ends at a pause of {@link CAPTION_CUE_GAP_MS} or after
217
+ * {@link CAPTION_CUE_MAX_WORDS} words. Words outside the clip's window
218
+ * (`0..durationMs`, clip-local) are left out.
219
+ */
220
+ export function captionCues(clip) {
221
+ const cues = [];
222
+ let current = [];
223
+ for (const word of clip.caption?.words ?? []) {
224
+ if (word.endMs <= 0 || word.startMs >= clip.durationMs)
225
+ continue;
226
+ const previous = current[current.length - 1];
227
+ if (previous &&
228
+ (word.startMs - previous.endMs >= CAPTION_CUE_GAP_MS ||
229
+ current.length >= CAPTION_CUE_MAX_WORDS)) {
230
+ cues.push(current);
231
+ current = [];
232
+ }
233
+ current.push(word);
234
+ }
235
+ if (current.length > 0)
236
+ cues.push(current);
237
+ return cues;
238
+ }
207
239
  /**
208
240
  * Resolve a clip's caption to its on-screen word state at `currentTimeMs`.
209
241
  * Returns `undefined` for clips that carry no caption. Word timings are
210
242
  * clip-local (relative to `clip.startMs`), so moving or splitting the clip
211
- * needs no rewrite of the words.
243
+ * needs no rewrite of the words. Only the cue being spoken is shown, so a
244
+ * long transcript does not stack up the frame; between cues no words show.
212
245
  */
213
246
  export function resolveCaptionAtTime(clip, currentTimeMs) {
214
247
  if (!clip.caption)
215
248
  return undefined;
216
249
  const local = currentTimeMs - clip.startMs;
250
+ const cue = captionCues(clip).find((words) => local >= words[0].startMs && local < words[words.length - 1].endMs);
217
251
  return {
218
- words: clip.caption.words.map((w) => ({
252
+ words: (cue ?? []).map((w) => ({
219
253
  text: w.word,
220
254
  active: local >= w.startMs && local < w.endMs
221
255
  })),
@@ -312,6 +346,22 @@ export function resolveGroups(clips, currentTimeMs, canvas, cache, tempo, transi
312
346
  // A chain that reaches a cycle cannot say what any of its links inherit,
313
347
  // so none of them inherit anything.
314
348
  const parent = cycle ? undefined : inherited;
349
+ const window = {
350
+ startMs: Math.max(current.startMs, parent?.window.startMs ?? Number.NEGATIVE_INFINITY),
351
+ endMs: Math.min(current.startMs + current.durationMs, parent?.window.endMs ?? Number.POSITIVE_INFINITY)
352
+ };
353
+ // Off screen, the window is all a group contributes: every child is
354
+ // dropped before it reads the matrix, the opacity or the surface. A
355
+ // document holds far more groups than one frame shows, and sampling
356
+ // the animations of every one on every frame was most of a resolve.
357
+ if (currentTimeMs < window.startMs || currentTimeMs >= window.endMs) {
358
+ const offscreen = { opacity: 0, window };
359
+ if (cycle)
360
+ offscreen.cycle = true;
361
+ resolved.set(current.id, offscreen);
362
+ inherited = offscreen;
363
+ continue;
364
+ }
315
365
  const own = groupProps(current, currentTimeMs, canvas, cache, tempo);
316
366
  const spatial = camera && !parent?.cameraApplied && own.transform?.depthPx !== undefined
317
367
  ? resolveCamera2D(own.transform ?? IDENTITY_TRANSFORM, sampleCamera2D(camera, currentTimeMs), current.effects)
@@ -325,10 +375,7 @@ export function resolveGroups(clips, currentTimeMs, canvas, cache, tempo, transi
325
375
  // applied once, to the composed surface, which is the whole point of
326
376
  // the intermediate — two overlapping children must not each be dimmed.
327
377
  opacity: precompose ? 1 : folded,
328
- window: {
329
- startMs: Math.max(current.startMs, parent?.window.startMs ?? Number.NEGATIVE_INFINITY),
330
- endMs: Math.min(current.startMs + current.durationMs, parent?.window.endMs ?? Number.POSITIVE_INFINITY)
331
- }
378
+ window
332
379
  };
333
380
  if (spatial || parent?.cameraApplied)
334
381
  entry.cameraApplied = true;
@@ -412,19 +459,175 @@ export function parseMatteMode(mode) {
412
459
  * away is named in `droppedLayers` so a host can say what is missing from the
413
460
  * frame instead of showing a picture that quietly lost a layer.
414
461
  */
462
+ const groupPatchedCache = new WeakMap();
463
+ /**
464
+ * The clips `resolveGroups` places groups from, with each flex-managed group
465
+ * carrying its resolved transform. Cached by the layout result, which is itself
466
+ * cached per clip array, so steady playback reuses one array.
467
+ */
468
+ function groupPatchedFor(clips, resolution) {
469
+ const hit = groupPatchedCache.get(resolution);
470
+ if (hit && hit.clips === clips)
471
+ return hit.patched;
472
+ const layouts = resolution.transforms;
473
+ const patched = clips.map((clip) => {
474
+ if (clip.mediaType !== "group")
475
+ return clip;
476
+ const resolved = layouts.get(clip.id);
477
+ if (!resolved)
478
+ return clip;
479
+ if (clip.layout?.display !== "flex")
480
+ return { ...clip, transform: resolved };
481
+ return { ...clip, transform: { ...resolved, position: { x: 0, y: 0 } } };
482
+ });
483
+ groupPatchedCache.set(resolution, { clips, patched });
484
+ return patched;
485
+ }
486
+ const sceneIndexCache = new WeakMap();
487
+ function sceneIndex(clips) {
488
+ const cached = sceneIndexCache.get(clips);
489
+ if (cached)
490
+ return cached;
491
+ const clipById = new Map(clips.map((clip) => [clip.id, clip]));
492
+ const clipsByTrackId = new Map();
493
+ for (const c of clips) {
494
+ const arr = clipsByTrackId.get(c.trackId);
495
+ if (arr)
496
+ arr.push(c);
497
+ else
498
+ clipsByTrackId.set(c.trackId, [c]);
499
+ }
500
+ const matteSourceIds = new Set();
501
+ for (const clip of clips) {
502
+ const matte = clip.matte;
503
+ if (!matte || parseMatteMode(matte.mode) === null)
504
+ continue;
505
+ const source = clipById.get(matte.sourceClipId);
506
+ // An adjustment has no pixels to read a channel out of, so it is no more a
507
+ // matte source than a clip that is not in the document — the layer naming
508
+ // it draws unmatted rather than vanishing.
509
+ if (!source || source.mediaType === "adjustment")
510
+ continue;
511
+ matteSourceIds.add(matte.sourceClipId);
512
+ }
513
+ const inFlexTree = (clip) => {
514
+ let cursor = clip.parentId ? clipById.get(clip.parentId) : undefined;
515
+ for (let hops = 0; cursor && hops < MAX_PARENT_HOPS; hops++) {
516
+ if (cursor.layout?.display === "flex")
517
+ return true;
518
+ cursor = cursor.parentId ? clipById.get(cursor.parentId) : undefined;
519
+ }
520
+ return false;
521
+ };
522
+ const flexAnimatedText = clips.filter((clip) => clip.textStyle !== undefined && (clip.animations?.length ?? 0) > 0 && inFlexTree(clip));
523
+ const transitionEnds = [];
524
+ for (const clip of clips) {
525
+ if ((clip.transitionIn?.durationMs ?? 0) > 0) {
526
+ transitionEnds.push(clip.startMs + clip.transitionIn.durationMs);
527
+ }
528
+ }
529
+ const index = { clipById, clipsByTrackId, matteSourceIds, flexAnimatedText, transitionEnds, layoutInputs: new Map() };
530
+ sceneIndexCache.set(clips, index);
531
+ return index;
532
+ }
533
+ /** Bottom-to-top order of every clip on its track, computed once per clip array. */
534
+ function stackOrderOf(index) {
535
+ if (index.stackOrderByClipId)
536
+ return index.stackOrderByClipId;
537
+ const stackOrderByClipId = new Map();
538
+ for (const trackClips of index.clipsByTrackId.values()) {
539
+ const ordered = trackClips
540
+ .filter((clip) => clip.mediaType !== "adjustment")
541
+ .sort((a, b) => {
542
+ const depth = (a.transform?.depthPx ?? 0) - (b.transform?.depthPx ?? 0);
543
+ if (depth !== 0)
544
+ return depth;
545
+ const aEcho = a.id.includes(":echo:") ? 0 : 1;
546
+ const bEcho = b.id.includes(":echo:") ? 0 : 1;
547
+ if (aEcho !== bEcho)
548
+ return aEcho - bEcho;
549
+ return a.startMs - b.startMs;
550
+ });
551
+ ordered.forEach((clip, order) => stackOrderByClipId.set(clip.id, order));
552
+ }
553
+ index.stackOrderByClipId = stackOrderByClipId;
554
+ return stackOrderByClipId;
555
+ }
556
+ /** Distinct animated layouts kept per document before the oldest is dropped. */
557
+ const LAYOUT_INPUT_CACHE_MAX = 64;
558
+ /**
559
+ * The clips the layout resolver sees at `currentTimeMs`: the document's own,
560
+ * with an animated text style swapped in where the text sits under a flex
561
+ * container and so can resize its siblings. Answers `clips` itself when no
562
+ * such clip exists, and otherwise one array per distinct set of animated
563
+ * styles, so the layout cache, keyed by the array, hits whenever the styles
564
+ * repeat — which is every frame between two changes of the animated text.
565
+ */
566
+ const MEASURED_WIDTHS_MAX = 4096;
567
+ /**
568
+ * `canvas` with its text measurer memoized for this document. Animated text in
569
+ * a flex tree (a ticker counting up) changes the layout input every frame, and
570
+ * each re-layout measures every word of every text in every flex tree again;
571
+ * only the changed text measures anything new. The memo lives on the index, so
572
+ * it is as fresh as the layout cache, which already treats one measurer on one
573
+ * clips array as one answer.
574
+ */
575
+ function layoutCanvasFor(index, canvas) {
576
+ const source = canvas.measureText;
577
+ if (!source)
578
+ return canvas;
579
+ let measured = index.measured;
580
+ if (measured?.source !== source) {
581
+ const widths = new Map();
582
+ const memo = (text, font) => {
583
+ const key = `${font}\u0000${text}`;
584
+ let width = widths.get(key);
585
+ if (width === undefined) {
586
+ if (widths.size >= MEASURED_WIDTHS_MAX)
587
+ widths.clear();
588
+ width = source(text, font);
589
+ widths.set(key, width);
590
+ }
591
+ return width;
592
+ };
593
+ measured = index.measured = { source, memo };
594
+ }
595
+ return { ...canvas, measureText: measured.memo };
596
+ }
597
+ function layoutClipsAt(clips, index, currentTimeMs, canvas, options) {
598
+ if (index.flexAnimatedText.length === 0)
599
+ return clips;
600
+ const patched = new Map();
601
+ for (const clip of index.flexAnimatedText) {
602
+ const animated = resolveAnimatedLayerProps({ clip, transform: clip.transform, opacity: clip.opacity ?? 1 }, currentTimeMs, canvas, options.animationCache, { mediaTracks: options.mediaTracks ?? [], clips, tempo: options.tempo });
603
+ if (animated.textStyle)
604
+ patched.set(clip.id, { ...clip, textStyle: animated.textStyle });
605
+ }
606
+ if (patched.size === 0)
607
+ return clips;
608
+ let key = "";
609
+ for (const [id, clip] of patched)
610
+ key += `${id}\u0000${textStyleSignature(clip.textStyle, canvas.width, canvas.height)}\u0001`;
611
+ const hit = index.layoutInputs.get(key);
612
+ if (hit)
613
+ return hit;
614
+ const inputs = clips.map((clip) => patched.get(clip.id) ?? clip);
615
+ if (index.layoutInputs.size >= LAYOUT_INPUT_CACHE_MAX) {
616
+ const oldest = index.layoutInputs.keys().next().value;
617
+ if (oldest !== undefined)
618
+ index.layoutInputs.delete(oldest);
619
+ }
620
+ index.layoutInputs.set(key, inputs);
621
+ return inputs;
622
+ }
415
623
  function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, options = {}) {
416
624
  const maxVideoLayers = options.maxVideoLayers ?? MAX_VIDEO_LAYERS;
417
625
  const transitions = resolveDocumentTransitions(clips, currentTimeMs);
626
+ const index = sceneIndex(clips);
418
627
  const layoutCanvas = options.canvas;
419
- const layoutClips = layoutCanvas
420
- ? clips.map((clip) => {
421
- if (!clip.textStyle || !clip.animations?.length)
422
- return clip;
423
- const animated = resolveAnimatedLayerProps({ clip, transform: clip.transform, opacity: clip.opacity ?? 1 }, currentTimeMs, layoutCanvas, options.animationCache, { mediaTracks: options.mediaTracks ?? [], clips, tempo: options.tempo });
424
- return animated.textStyle ? { ...clip, textStyle: animated.textStyle } : clip;
425
- })
426
- : clips;
427
- const layoutResolved = layoutCanvas ? resolveClipLayoutsWithDiagnostics(layoutClips, layoutCanvas) : undefined;
628
+ const layoutResolved = layoutCanvas
629
+ ? resolveClipLayoutsWithDiagnostics(layoutClipsAt(clips, index, currentTimeMs, layoutCanvas, options), layoutCanvasFor(index, layoutCanvas))
630
+ : undefined;
428
631
  const layouts = layoutResolved?.transforms ?? new Map();
429
632
  // Every entry in `layouts` — leaf or nested (non-root) flex container — is
430
633
  // a delta already relative to the flex root's own untranslated frame
@@ -445,17 +648,8 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
445
648
  // only real translation this composition is meant to add. A plain group
446
649
  // inside a flex container is a leaf: flex moves the group and never lays
447
650
  // out its children, so it keeps its resolved transform, position included.
448
- const groupPatchedClips = layouts.size > 0
449
- ? clips.map((clip) => {
450
- if (clip.mediaType !== "group")
451
- return clip;
452
- const resolved = layouts.get(clip.id);
453
- if (!resolved)
454
- return clip;
455
- if (clip.layout?.display !== "flex")
456
- return { ...clip, transform: resolved };
457
- return { ...clip, transform: { ...resolved, position: { x: 0, y: 0 } } };
458
- })
651
+ const groupPatchedClips = layoutResolved && layouts.size > 0
652
+ ? groupPatchedFor(clips, layoutResolved)
459
653
  : clips;
460
654
  // Parents before children: a child's opacity, matrix and window all come
461
655
  // from a group that may sit on any track, so every group is resolved before
@@ -464,14 +658,7 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
464
658
  const sortedTracks = [...tracks].sort((a, b) => a.index - b.index);
465
659
  const layoutSizes = layoutResolved?.sizes ?? new Map();
466
660
  const canvasForLayout = layoutCanvas;
467
- const clipsByTrackId = new Map();
468
- for (const c of clips) {
469
- const arr = clipsByTrackId.get(c.trackId);
470
- if (arr)
471
- arr.push(c);
472
- else
473
- clipsByTrackId.set(c.trackId, [c]);
474
- }
661
+ const { clipById, clipsByTrackId, matteSourceIds } = index;
475
662
  const mediaLayers = [];
476
663
  const captionLayers = [];
477
664
  const resolvedAdjustments = [];
@@ -482,20 +669,6 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
482
669
  // `matte` are held aside as the walk reaches them and handed to the layers
483
670
  // that name them once the walk is over — the source may sit on a track below
484
671
  // the one that reads it (D6).
485
- const clipById = new Map(clips.map((clip) => [clip.id, clip]));
486
- const matteSourceIds = new Set();
487
- for (const clip of clips) {
488
- const matte = clip.matte;
489
- if (!matte || parseMatteMode(matte.mode) === null)
490
- continue;
491
- const source = clipById.get(matte.sourceClipId);
492
- // An adjustment has no pixels to read a channel out of, so it is no more a
493
- // matte source than a clip that is not in the document — the layer naming
494
- // it draws unmatted rather than vanishing.
495
- if (!source || source.mediaType === "adjustment")
496
- continue;
497
- matteSourceIds.add(matte.sourceClipId);
498
- }
499
672
  const matteLayers = new Map();
500
673
  const emitMedia = (layer) => {
501
674
  layer.transform = layouts.get(layer.clipId) ?? layer.transform;
@@ -544,11 +717,8 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
544
717
  considerBoundary(group.window.startMs);
545
718
  considerBoundary(group.window.endMs);
546
719
  }
547
- for (const clip of clips) {
548
- if ((clip.transitionIn?.durationMs ?? 0) > 0) {
549
- considerBoundary(clip.startMs + clip.transitionIn.durationMs);
550
- }
551
- }
720
+ for (const end of index.transitionEnds)
721
+ considerBoundary(end);
552
722
  for (const track of sortedTracks) {
553
723
  if (!track.visible)
554
724
  continue;
@@ -563,10 +733,12 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
563
733
  // carry its contribution to the frame. The transition resolver handles
564
734
  // group clips as siblings separately, without pairing them with children.
565
735
  // An adjustment is held out for the same reason: it treats the picture beneath,
566
- // so it can be neither side of a cut.
736
+ // so it can be neither side of a cut. A hidden clip draws nothing, caption
737
+ // included, except as a matte source, which is never drawn itself.
567
738
  const activeClips = trackClips
568
739
  .filter((c) => c.mediaType !== "group" &&
569
740
  c.mediaType !== "adjustment" &&
741
+ (!c.hidden || matteSourceIds.has(c.id)) &&
570
742
  isClipActive(c, options.layerTimeMs?.(c) ?? currentTimeMs))
571
743
  .sort((a, b) => a.startMs - b.startMs);
572
744
  const drawClips = [...activeClips].sort((a, b) => {
@@ -585,7 +757,7 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
585
757
  // z their treatment runs at. Only a visual track has a composite to treat.
586
758
  if (isVisual) {
587
759
  for (const clip of trackClips) {
588
- if (clip.mediaType !== "adjustment")
760
+ if (clip.mediaType !== "adjustment" || clip.hidden)
589
761
  continue;
590
762
  if (!isClipActive(clip, currentTimeMs))
591
763
  continue;
@@ -618,13 +790,14 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
618
790
  if (precomposeGroupId)
619
791
  usedSurfaces.add(precomposeGroupId);
620
792
  const transition = transitions.get(clip.id);
793
+ const fade = clipFadeOpacity(clip, currentTimeMs);
621
794
  const baseOpacity = (clip.opacity ?? 1) * (parent?.opacity ?? 1);
622
795
  // Clamped here and nowhere else: the GPU compositor multiplies this into
623
796
  // the shader raw while Canvas 2D clamps it, so an out-of-range clip or
624
797
  // group opacity drew a different picture on each host. Animations still
625
798
  // multiply on top afterwards (I3) — `clampSample` settles those.
626
- const opacity = clamp01(baseOpacity * (transition?.opacity ?? 1));
627
- const opacityCoverage = clamp01((parent?.opacity ?? 1) * (transition?.opacity ?? 1));
799
+ const opacity = clamp01(baseOpacity * (transition?.opacity ?? 1) * fade);
800
+ const opacityCoverage = clamp01((parent?.opacity ?? 1) * (transition?.opacity ?? 1) * fade);
628
801
  // Captions ride on their media clip and always render on top.
629
802
  const caption = resolveCaptionAtTime(clip, currentTimeMs);
630
803
  if (caption && !matteSourceIds.has(clip.id)) {
@@ -850,22 +1023,7 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
850
1023
  const drawn = attachMattes(mediaLayers, matteLayers, clipById, droppedLayers);
851
1024
  const precomposites = collectPrecomposites(clips, tracks, groups, usedSurfaces);
852
1025
  if (precomposites.length > 0) {
853
- const stackOrderByClipId = new Map();
854
- for (const trackClips of clipsByTrackId.values()) {
855
- const ordered = trackClips
856
- .filter((clip) => clip.mediaType !== "adjustment")
857
- .sort((a, b) => {
858
- const depth = (a.transform?.depthPx ?? 0) - (b.transform?.depthPx ?? 0);
859
- if (depth !== 0)
860
- return depth;
861
- const aEcho = a.id.includes(":echo:") ? 0 : 1;
862
- const bEcho = b.id.includes(":echo:") ? 0 : 1;
863
- if (aEcho !== bEcho)
864
- return aEcho - bEcho;
865
- return a.startMs - b.startMs;
866
- });
867
- ordered.forEach((clip, index) => stackOrderByClipId.set(clip.id, index));
868
- }
1026
+ const stackOrderByClipId = stackOrderOf(index);
869
1027
  for (const layer of drawn) {
870
1028
  layer.stackOrder = stackOrderByClipId.get(layer.clipId);
871
1029
  }
@@ -900,9 +1058,10 @@ export function computeActiveLayersWithHorizon(tracks, clips, currentTimeMs, opt
900
1058
  * same fallback a group's transform takes.
901
1059
  */
902
1060
  function resolveAdjustment(clip, trackIndex, parent, currentTimeMs, options, clips) {
903
- const base = (clip.opacity ?? 1) * (parent?.opacity ?? 1);
1061
+ const fade = clipFadeOpacity(clip, currentTimeMs);
1062
+ const base = (clip.opacity ?? 1) * (parent?.opacity ?? 1) * fade;
904
1063
  const animated = options.canvas
905
- ? resolveAnimatedLayerProps({ clip, opacity: base, opacityCoverage: parent?.opacity ?? 1 }, currentTimeMs, options.canvas, options.animationCache, { mediaTracks: options.mediaTracks ?? [], clips, tempo: options.tempo })
1064
+ ? resolveAnimatedLayerProps({ clip, opacity: base, opacityCoverage: (parent?.opacity ?? 1) * fade }, currentTimeMs, options.canvas, options.animationCache, { mediaTracks: options.mediaTracks ?? [], clips, tempo: options.tempo })
906
1065
  : null;
907
1066
  const effects = (animated?.effects ?? clip.effects ?? []).filter((effect) => effect.enabled);
908
1067
  if (effects.length === 0)
@@ -1473,7 +1632,7 @@ export function hasActiveAnimation(layers, currentTimeMs, canvas, cache, clips,
1473
1632
  // child through `parentMatrix`, so a still child of a moving group is a
1474
1633
  // moving layer. `clips` is how the ancestors are reached; without it only
1475
1634
  // the layers' own animations are seen.
1476
- const byId = clips ? new Map(clips.map((clip) => [clip.id, clip])) : null;
1635
+ const byId = clips ? sceneIndex(clips).clipById : null;
1477
1636
  const animating = (clip) => {
1478
1637
  if (clip.animationLinks?.length)
1479
1638
  return true;
@@ -1497,6 +1656,8 @@ export function hasActiveAnimation(layers, currentTimeMs, canvas, cache, clips,
1497
1656
  for (const layer of layers) {
1498
1657
  if (layer.camera2d?.keyframes?.length)
1499
1658
  return true;
1659
+ if (isClipFading(layer.clip, currentTimeMs))
1660
+ return true;
1500
1661
  if (chainAnimating(layer.clip))
1501
1662
  return true;
1502
1663
  if (layer.matte && chainAnimating(layer.matte.layer.clip))
@@ -1506,4 +1667,19 @@ export function hasActiveAnimation(layers, currentTimeMs, canvas, cache, clips,
1506
1667
  }
1507
1668
  /** Longest parent chain the motion check follows before giving up. */
1508
1669
  const MAX_PARENT_HOPS = 64;
1670
+ /**
1671
+ * How long past a fade-in's end the preview keeps redrawing. The last frame
1672
+ * inside the ramp can land a whole frame short of full opacity; on a still
1673
+ * image nothing else redraws, so that frame would otherwise stay on screen.
1674
+ */
1675
+ const FADE_SETTLE_MS = 100;
1676
+ /** True while a clip's fade-in or fade-out ramps its opacity at `currentTimeMs`. */
1677
+ function isClipFading(clip, currentTimeMs) {
1678
+ if (!clip.fadeInMs && !clip.fadeOutMs)
1679
+ return false;
1680
+ const fades = resolveClipFades(clip, clip.durationMs);
1681
+ const ms = currentTimeMs - clip.startMs;
1682
+ return ((fades.fadeInMs > 0 && ms < fades.fadeInMs + FADE_SETTLE_MS) ||
1683
+ (fades.fadeOutMs > 0 && ms > clip.durationMs - fades.fadeOutMs));
1684
+ }
1509
1685
  //# sourceMappingURL=sceneModel.js.map