@nodetool-ai/timeline 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.nodetool-build-stamp +1 -1
- package/dist/animation/compile.d.ts.map +1 -1
- package/dist/animation/compile.js +5 -1
- package/dist/animation/compile.js.map +1 -1
- package/dist/clipAudio.d.ts +32 -0
- package/dist/clipAudio.d.ts.map +1 -0
- package/dist/clipAudio.js +70 -0
- package/dist/clipAudio.js.map +1 -0
- package/dist/clipSpeed.d.ts +17 -0
- package/dist/clipSpeed.d.ts.map +1 -0
- package/dist/clipSpeed.js +58 -0
- package/dist/clipSpeed.js.map +1 -0
- package/dist/dropResolve.d.ts +14 -6
- package/dist/dropResolve.d.ts.map +1 -1
- package/dist/dropResolve.js +113 -37
- package/dist/dropResolve.js.map +1 -1
- package/dist/finish-storyboard.d.ts.map +1 -1
- package/dist/finish-storyboard.js +46 -39
- package/dist/finish-storyboard.js.map +1 -1
- package/dist/fonts/google-fonts.d.ts +6 -0
- package/dist/fonts/google-fonts.d.ts.map +1 -1
- package/dist/fonts/google-fonts.js +7 -1
- package/dist/fonts/google-fonts.js.map +1 -1
- package/dist/group.d.ts +16 -4
- package/dist/group.d.ts.map +1 -1
- package/dist/group.js +53 -6
- package/dist/group.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/interchange.d.ts +8 -0
- package/dist/interchange.d.ts.map +1 -1
- package/dist/interchange.js +217 -27
- package/dist/interchange.js.map +1 -1
- package/dist/interchangeImport.d.ts +87 -0
- package/dist/interchangeImport.d.ts.map +1 -0
- package/dist/interchangeImport.js +404 -0
- package/dist/interchangeImport.js.map +1 -0
- package/dist/keyframes.d.ts +12 -1
- package/dist/keyframes.d.ts.map +1 -1
- package/dist/keyframes.js +78 -21
- package/dist/keyframes.js.map +1 -1
- package/dist/linked.js +1 -1
- package/dist/mediaTrack.d.ts +11 -0
- package/dist/mediaTrack.d.ts.map +1 -1
- package/dist/mediaTrack.js +25 -0
- package/dist/mediaTrack.js.map +1 -1
- package/dist/midi/edit.d.ts +5 -0
- package/dist/midi/edit.d.ts.map +1 -1
- package/dist/midi/edit.js +2 -1
- package/dist/midi/edit.js.map +1 -1
- package/dist/midi/grid.d.ts.map +1 -1
- package/dist/midi/grid.js +8 -4
- package/dist/midi/grid.js.map +1 -1
- package/dist/midi/tempo.d.ts.map +1 -1
- package/dist/midi/tempo.js +8 -0
- package/dist/midi/tempo.js.map +1 -1
- package/dist/ops/apply.d.ts +9 -0
- package/dist/ops/apply.d.ts.map +1 -1
- package/dist/ops/apply.js +1816 -1425
- package/dist/ops/apply.js.map +1 -1
- package/dist/ops/parse.d.ts.map +1 -1
- package/dist/ops/parse.js +318 -357
- package/dist/ops/parse.js.map +1 -1
- package/dist/render/draw.d.ts +43 -1
- package/dist/render/draw.d.ts.map +1 -1
- package/dist/render/draw.js +123 -3
- package/dist/render/draw.js.map +1 -1
- package/dist/render/frameCompositor.d.ts +31 -3
- package/dist/render/frameCompositor.d.ts.map +1 -1
- package/dist/render/frameCompositor.js +58 -10
- package/dist/render/frameCompositor.js.map +1 -1
- package/dist/render/sceneModel.d.ts +18 -6
- package/dist/render/sceneModel.d.ts.map +1 -1
- package/dist/render/sceneModel.js +231 -85
- package/dist/render/sceneModel.js.map +1 -1
- package/dist/render/temporal.d.ts +9 -1
- package/dist/render/temporal.d.ts.map +1 -1
- package/dist/render/temporal.js +18 -1
- package/dist/render/temporal.js.map +1 -1
- package/dist/render/textLayout.d.ts +6 -0
- package/dist/render/textLayout.d.ts.map +1 -1
- package/dist/render/textLayout.js +13 -1
- package/dist/render/textLayout.js.map +1 -1
- package/dist/rippleEdit.d.ts +20 -3
- package/dist/rippleEdit.d.ts.map +1 -1
- package/dist/rippleEdit.js +89 -17
- package/dist/rippleEdit.js.map +1 -1
- package/dist/shotLink.d.ts +47 -0
- package/dist/shotLink.d.ts.map +1 -0
- package/dist/shotLink.js +92 -0
- package/dist/shotLink.js.map +1 -0
- package/dist/splitClip.d.ts.map +1 -1
- package/dist/splitClip.js +16 -2
- package/dist/splitClip.js.map +1 -1
- package/dist/storyboard.js +1 -1
- package/dist/takes.d.ts.map +1 -1
- package/dist/takes.js +15 -2
- package/dist/takes.js.map +1 -1
- package/dist/testing/host-ops.d.ts +16 -0
- package/dist/testing/host-ops.d.ts.map +1 -0
- package/dist/testing/host-ops.js +378 -0
- package/dist/testing/host-ops.js.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/ops.d.ts +30 -0
- package/dist/testing/ops.d.ts.map +1 -0
- package/dist/testing/ops.js +814 -0
- package/dist/testing/ops.js.map +1 -0
- package/dist/transitionAtCut.d.ts +29 -5
- package/dist/transitionAtCut.d.ts.map +1 -1
- package/dist/transitionAtCut.js +69 -33
- package/dist/transitionAtCut.js.map +1 -1
- package/dist/trimClip.d.ts +5 -8
- package/dist/trimClip.d.ts.map +1 -1
- package/dist/trimClip.js +38 -2
- package/dist/trimClip.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +11 -5
|
@@ -16,7 +16,9 @@ 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";
|
|
@@ -136,7 +138,7 @@ function resolveDocumentTransitions(clips, currentTimeMs) {
|
|
|
136
138
|
const groupIds = new Set(clips.filter((clip) => clip.mediaType === "group").map((clip) => clip.id));
|
|
137
139
|
const byTrack = new Map();
|
|
138
140
|
for (const clip of clips) {
|
|
139
|
-
if (clip.mediaType === "adjustment" || !isClipActive(clip, currentTimeMs))
|
|
141
|
+
if (clip.mediaType === "adjustment" || clip.hidden || !isClipActive(clip, currentTimeMs))
|
|
140
142
|
continue;
|
|
141
143
|
const parentId = clip.parentId && groupIds.has(clip.parentId) ? clip.parentId : undefined;
|
|
142
144
|
let byParent = byTrack.get(clip.trackId);
|
|
@@ -161,18 +163,8 @@ function resolveDocumentTransitions(clips, currentTimeMs) {
|
|
|
161
163
|
}
|
|
162
164
|
return transitions;
|
|
163
165
|
}
|
|
164
|
-
/** The
|
|
165
|
-
export
|
|
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
|
-
}
|
|
166
|
+
/** The status rule lives beside the audio rules that share it. */
|
|
167
|
+
export { effectiveAssetId };
|
|
176
168
|
function resolveBlendMode(b) {
|
|
177
169
|
return b ?? "normal";
|
|
178
170
|
}
|
|
@@ -204,18 +196,49 @@ export function clipSourceTimeSec(clip, currentTimeMs) {
|
|
|
204
196
|
export function bakedClipSourceTimeSec(clip, currentTimeMs) {
|
|
205
197
|
return Math.max(0, (currentTimeMs - clip.startMs) / 1000);
|
|
206
198
|
}
|
|
199
|
+
/** A pause at least this long between two words starts a new caption cue. */
|
|
200
|
+
export const CAPTION_CUE_GAP_MS = 700;
|
|
201
|
+
/** The most words one caption cue shows at a time. */
|
|
202
|
+
export const CAPTION_CUE_MAX_WORDS = 10;
|
|
203
|
+
/**
|
|
204
|
+
* Split a clip's words into cues, the runs shown on screen together: a cue
|
|
205
|
+
* ends at a pause of {@link CAPTION_CUE_GAP_MS} or after
|
|
206
|
+
* {@link CAPTION_CUE_MAX_WORDS} words. Words outside the clip's window
|
|
207
|
+
* (`0..durationMs`, clip-local) are left out.
|
|
208
|
+
*/
|
|
209
|
+
export function captionCues(clip) {
|
|
210
|
+
const cues = [];
|
|
211
|
+
let current = [];
|
|
212
|
+
for (const word of clip.caption?.words ?? []) {
|
|
213
|
+
if (word.endMs <= 0 || word.startMs >= clip.durationMs)
|
|
214
|
+
continue;
|
|
215
|
+
const previous = current[current.length - 1];
|
|
216
|
+
if (previous &&
|
|
217
|
+
(word.startMs - previous.endMs >= CAPTION_CUE_GAP_MS ||
|
|
218
|
+
current.length >= CAPTION_CUE_MAX_WORDS)) {
|
|
219
|
+
cues.push(current);
|
|
220
|
+
current = [];
|
|
221
|
+
}
|
|
222
|
+
current.push(word);
|
|
223
|
+
}
|
|
224
|
+
if (current.length > 0)
|
|
225
|
+
cues.push(current);
|
|
226
|
+
return cues;
|
|
227
|
+
}
|
|
207
228
|
/**
|
|
208
229
|
* Resolve a clip's caption to its on-screen word state at `currentTimeMs`.
|
|
209
230
|
* Returns `undefined` for clips that carry no caption. Word timings are
|
|
210
231
|
* clip-local (relative to `clip.startMs`), so moving or splitting the clip
|
|
211
|
-
* needs no rewrite of the words.
|
|
232
|
+
* needs no rewrite of the words. Only the cue being spoken is shown, so a
|
|
233
|
+
* long transcript does not stack up the frame; between cues no words show.
|
|
212
234
|
*/
|
|
213
235
|
export function resolveCaptionAtTime(clip, currentTimeMs) {
|
|
214
236
|
if (!clip.caption)
|
|
215
237
|
return undefined;
|
|
216
238
|
const local = currentTimeMs - clip.startMs;
|
|
239
|
+
const cue = captionCues(clip).find((words) => local >= words[0].startMs && local < words[words.length - 1].endMs);
|
|
217
240
|
return {
|
|
218
|
-
words:
|
|
241
|
+
words: (cue ?? []).map((w) => ({
|
|
219
242
|
text: w.word,
|
|
220
243
|
active: local >= w.startMs && local < w.endMs
|
|
221
244
|
})),
|
|
@@ -312,6 +335,22 @@ export function resolveGroups(clips, currentTimeMs, canvas, cache, tempo, transi
|
|
|
312
335
|
// A chain that reaches a cycle cannot say what any of its links inherit,
|
|
313
336
|
// so none of them inherit anything.
|
|
314
337
|
const parent = cycle ? undefined : inherited;
|
|
338
|
+
const window = {
|
|
339
|
+
startMs: Math.max(current.startMs, parent?.window.startMs ?? Number.NEGATIVE_INFINITY),
|
|
340
|
+
endMs: Math.min(current.startMs + current.durationMs, parent?.window.endMs ?? Number.POSITIVE_INFINITY)
|
|
341
|
+
};
|
|
342
|
+
// Off screen, the window is all a group contributes: every child is
|
|
343
|
+
// dropped before it reads the matrix, the opacity or the surface. A
|
|
344
|
+
// document holds far more groups than one frame shows, and sampling
|
|
345
|
+
// the animations of every one on every frame was most of a resolve.
|
|
346
|
+
if (currentTimeMs < window.startMs || currentTimeMs >= window.endMs) {
|
|
347
|
+
const offscreen = { opacity: 0, window };
|
|
348
|
+
if (cycle)
|
|
349
|
+
offscreen.cycle = true;
|
|
350
|
+
resolved.set(current.id, offscreen);
|
|
351
|
+
inherited = offscreen;
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
315
354
|
const own = groupProps(current, currentTimeMs, canvas, cache, tempo);
|
|
316
355
|
const spatial = camera && !parent?.cameraApplied && own.transform?.depthPx !== undefined
|
|
317
356
|
? resolveCamera2D(own.transform ?? IDENTITY_TRANSFORM, sampleCamera2D(camera, currentTimeMs), current.effects)
|
|
@@ -325,10 +364,7 @@ export function resolveGroups(clips, currentTimeMs, canvas, cache, tempo, transi
|
|
|
325
364
|
// applied once, to the composed surface, which is the whole point of
|
|
326
365
|
// the intermediate — two overlapping children must not each be dimmed.
|
|
327
366
|
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
|
-
}
|
|
367
|
+
window
|
|
332
368
|
};
|
|
333
369
|
if (spatial || parent?.cameraApplied)
|
|
334
370
|
entry.cameraApplied = true;
|
|
@@ -412,19 +448,175 @@ export function parseMatteMode(mode) {
|
|
|
412
448
|
* away is named in `droppedLayers` so a host can say what is missing from the
|
|
413
449
|
* frame instead of showing a picture that quietly lost a layer.
|
|
414
450
|
*/
|
|
451
|
+
const groupPatchedCache = new WeakMap();
|
|
452
|
+
/**
|
|
453
|
+
* The clips `resolveGroups` places groups from, with each flex-managed group
|
|
454
|
+
* carrying its resolved transform. Cached by the layout result, which is itself
|
|
455
|
+
* cached per clip array, so steady playback reuses one array.
|
|
456
|
+
*/
|
|
457
|
+
function groupPatchedFor(clips, resolution) {
|
|
458
|
+
const hit = groupPatchedCache.get(resolution);
|
|
459
|
+
if (hit && hit.clips === clips)
|
|
460
|
+
return hit.patched;
|
|
461
|
+
const layouts = resolution.transforms;
|
|
462
|
+
const patched = clips.map((clip) => {
|
|
463
|
+
if (clip.mediaType !== "group")
|
|
464
|
+
return clip;
|
|
465
|
+
const resolved = layouts.get(clip.id);
|
|
466
|
+
if (!resolved)
|
|
467
|
+
return clip;
|
|
468
|
+
if (clip.layout?.display !== "flex")
|
|
469
|
+
return { ...clip, transform: resolved };
|
|
470
|
+
return { ...clip, transform: { ...resolved, position: { x: 0, y: 0 } } };
|
|
471
|
+
});
|
|
472
|
+
groupPatchedCache.set(resolution, { clips, patched });
|
|
473
|
+
return patched;
|
|
474
|
+
}
|
|
475
|
+
const sceneIndexCache = new WeakMap();
|
|
476
|
+
function sceneIndex(clips) {
|
|
477
|
+
const cached = sceneIndexCache.get(clips);
|
|
478
|
+
if (cached)
|
|
479
|
+
return cached;
|
|
480
|
+
const clipById = new Map(clips.map((clip) => [clip.id, clip]));
|
|
481
|
+
const clipsByTrackId = new Map();
|
|
482
|
+
for (const c of clips) {
|
|
483
|
+
const arr = clipsByTrackId.get(c.trackId);
|
|
484
|
+
if (arr)
|
|
485
|
+
arr.push(c);
|
|
486
|
+
else
|
|
487
|
+
clipsByTrackId.set(c.trackId, [c]);
|
|
488
|
+
}
|
|
489
|
+
const matteSourceIds = new Set();
|
|
490
|
+
for (const clip of clips) {
|
|
491
|
+
const matte = clip.matte;
|
|
492
|
+
if (!matte || parseMatteMode(matte.mode) === null)
|
|
493
|
+
continue;
|
|
494
|
+
const source = clipById.get(matte.sourceClipId);
|
|
495
|
+
// An adjustment has no pixels to read a channel out of, so it is no more a
|
|
496
|
+
// matte source than a clip that is not in the document — the layer naming
|
|
497
|
+
// it draws unmatted rather than vanishing.
|
|
498
|
+
if (!source || source.mediaType === "adjustment")
|
|
499
|
+
continue;
|
|
500
|
+
matteSourceIds.add(matte.sourceClipId);
|
|
501
|
+
}
|
|
502
|
+
const inFlexTree = (clip) => {
|
|
503
|
+
let cursor = clip.parentId ? clipById.get(clip.parentId) : undefined;
|
|
504
|
+
for (let hops = 0; cursor && hops < MAX_PARENT_HOPS; hops++) {
|
|
505
|
+
if (cursor.layout?.display === "flex")
|
|
506
|
+
return true;
|
|
507
|
+
cursor = cursor.parentId ? clipById.get(cursor.parentId) : undefined;
|
|
508
|
+
}
|
|
509
|
+
return false;
|
|
510
|
+
};
|
|
511
|
+
const flexAnimatedText = clips.filter((clip) => clip.textStyle !== undefined && (clip.animations?.length ?? 0) > 0 && inFlexTree(clip));
|
|
512
|
+
const transitionEnds = [];
|
|
513
|
+
for (const clip of clips) {
|
|
514
|
+
if ((clip.transitionIn?.durationMs ?? 0) > 0) {
|
|
515
|
+
transitionEnds.push(clip.startMs + clip.transitionIn.durationMs);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
const index = { clipById, clipsByTrackId, matteSourceIds, flexAnimatedText, transitionEnds, layoutInputs: new Map() };
|
|
519
|
+
sceneIndexCache.set(clips, index);
|
|
520
|
+
return index;
|
|
521
|
+
}
|
|
522
|
+
/** Bottom-to-top order of every clip on its track, computed once per clip array. */
|
|
523
|
+
function stackOrderOf(index) {
|
|
524
|
+
if (index.stackOrderByClipId)
|
|
525
|
+
return index.stackOrderByClipId;
|
|
526
|
+
const stackOrderByClipId = new Map();
|
|
527
|
+
for (const trackClips of index.clipsByTrackId.values()) {
|
|
528
|
+
const ordered = trackClips
|
|
529
|
+
.filter((clip) => clip.mediaType !== "adjustment")
|
|
530
|
+
.sort((a, b) => {
|
|
531
|
+
const depth = (a.transform?.depthPx ?? 0) - (b.transform?.depthPx ?? 0);
|
|
532
|
+
if (depth !== 0)
|
|
533
|
+
return depth;
|
|
534
|
+
const aEcho = a.id.includes(":echo:") ? 0 : 1;
|
|
535
|
+
const bEcho = b.id.includes(":echo:") ? 0 : 1;
|
|
536
|
+
if (aEcho !== bEcho)
|
|
537
|
+
return aEcho - bEcho;
|
|
538
|
+
return a.startMs - b.startMs;
|
|
539
|
+
});
|
|
540
|
+
ordered.forEach((clip, order) => stackOrderByClipId.set(clip.id, order));
|
|
541
|
+
}
|
|
542
|
+
index.stackOrderByClipId = stackOrderByClipId;
|
|
543
|
+
return stackOrderByClipId;
|
|
544
|
+
}
|
|
545
|
+
/** Distinct animated layouts kept per document before the oldest is dropped. */
|
|
546
|
+
const LAYOUT_INPUT_CACHE_MAX = 64;
|
|
547
|
+
/**
|
|
548
|
+
* The clips the layout resolver sees at `currentTimeMs`: the document's own,
|
|
549
|
+
* with an animated text style swapped in where the text sits under a flex
|
|
550
|
+
* container and so can resize its siblings. Answers `clips` itself when no
|
|
551
|
+
* such clip exists, and otherwise one array per distinct set of animated
|
|
552
|
+
* styles, so the layout cache, keyed by the array, hits whenever the styles
|
|
553
|
+
* repeat — which is every frame between two changes of the animated text.
|
|
554
|
+
*/
|
|
555
|
+
const MEASURED_WIDTHS_MAX = 4096;
|
|
556
|
+
/**
|
|
557
|
+
* `canvas` with its text measurer memoized for this document. Animated text in
|
|
558
|
+
* a flex tree (a ticker counting up) changes the layout input every frame, and
|
|
559
|
+
* each re-layout measures every word of every text in every flex tree again;
|
|
560
|
+
* only the changed text measures anything new. The memo lives on the index, so
|
|
561
|
+
* it is as fresh as the layout cache, which already treats one measurer on one
|
|
562
|
+
* clips array as one answer.
|
|
563
|
+
*/
|
|
564
|
+
function layoutCanvasFor(index, canvas) {
|
|
565
|
+
const source = canvas.measureText;
|
|
566
|
+
if (!source)
|
|
567
|
+
return canvas;
|
|
568
|
+
let measured = index.measured;
|
|
569
|
+
if (measured?.source !== source) {
|
|
570
|
+
const widths = new Map();
|
|
571
|
+
const memo = (text, font) => {
|
|
572
|
+
const key = `${font}\u0000${text}`;
|
|
573
|
+
let width = widths.get(key);
|
|
574
|
+
if (width === undefined) {
|
|
575
|
+
if (widths.size >= MEASURED_WIDTHS_MAX)
|
|
576
|
+
widths.clear();
|
|
577
|
+
width = source(text, font);
|
|
578
|
+
widths.set(key, width);
|
|
579
|
+
}
|
|
580
|
+
return width;
|
|
581
|
+
};
|
|
582
|
+
measured = index.measured = { source, memo };
|
|
583
|
+
}
|
|
584
|
+
return { ...canvas, measureText: measured.memo };
|
|
585
|
+
}
|
|
586
|
+
function layoutClipsAt(clips, index, currentTimeMs, canvas, options) {
|
|
587
|
+
if (index.flexAnimatedText.length === 0)
|
|
588
|
+
return clips;
|
|
589
|
+
const patched = new Map();
|
|
590
|
+
for (const clip of index.flexAnimatedText) {
|
|
591
|
+
const animated = resolveAnimatedLayerProps({ clip, transform: clip.transform, opacity: clip.opacity ?? 1 }, currentTimeMs, canvas, options.animationCache, { mediaTracks: options.mediaTracks ?? [], clips, tempo: options.tempo });
|
|
592
|
+
if (animated.textStyle)
|
|
593
|
+
patched.set(clip.id, { ...clip, textStyle: animated.textStyle });
|
|
594
|
+
}
|
|
595
|
+
if (patched.size === 0)
|
|
596
|
+
return clips;
|
|
597
|
+
let key = "";
|
|
598
|
+
for (const [id, clip] of patched)
|
|
599
|
+
key += `${id}\u0000${textStyleSignature(clip.textStyle, canvas.width, canvas.height)}\u0001`;
|
|
600
|
+
const hit = index.layoutInputs.get(key);
|
|
601
|
+
if (hit)
|
|
602
|
+
return hit;
|
|
603
|
+
const inputs = clips.map((clip) => patched.get(clip.id) ?? clip);
|
|
604
|
+
if (index.layoutInputs.size >= LAYOUT_INPUT_CACHE_MAX) {
|
|
605
|
+
const oldest = index.layoutInputs.keys().next().value;
|
|
606
|
+
if (oldest !== undefined)
|
|
607
|
+
index.layoutInputs.delete(oldest);
|
|
608
|
+
}
|
|
609
|
+
index.layoutInputs.set(key, inputs);
|
|
610
|
+
return inputs;
|
|
611
|
+
}
|
|
415
612
|
function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, options = {}) {
|
|
416
613
|
const maxVideoLayers = options.maxVideoLayers ?? MAX_VIDEO_LAYERS;
|
|
417
614
|
const transitions = resolveDocumentTransitions(clips, currentTimeMs);
|
|
615
|
+
const index = sceneIndex(clips);
|
|
418
616
|
const layoutCanvas = options.canvas;
|
|
419
|
-
const
|
|
420
|
-
?
|
|
421
|
-
|
|
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;
|
|
617
|
+
const layoutResolved = layoutCanvas
|
|
618
|
+
? resolveClipLayoutsWithDiagnostics(layoutClipsAt(clips, index, currentTimeMs, layoutCanvas, options), layoutCanvasFor(index, layoutCanvas))
|
|
619
|
+
: undefined;
|
|
428
620
|
const layouts = layoutResolved?.transforms ?? new Map();
|
|
429
621
|
// Every entry in `layouts` — leaf or nested (non-root) flex container — is
|
|
430
622
|
// a delta already relative to the flex root's own untranslated frame
|
|
@@ -445,17 +637,8 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
445
637
|
// only real translation this composition is meant to add. A plain group
|
|
446
638
|
// inside a flex container is a leaf: flex moves the group and never lays
|
|
447
639
|
// out its children, so it keeps its resolved transform, position included.
|
|
448
|
-
const groupPatchedClips = layouts.size > 0
|
|
449
|
-
? clips
|
|
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
|
-
})
|
|
640
|
+
const groupPatchedClips = layoutResolved && layouts.size > 0
|
|
641
|
+
? groupPatchedFor(clips, layoutResolved)
|
|
459
642
|
: clips;
|
|
460
643
|
// Parents before children: a child's opacity, matrix and window all come
|
|
461
644
|
// from a group that may sit on any track, so every group is resolved before
|
|
@@ -464,14 +647,7 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
464
647
|
const sortedTracks = [...tracks].sort((a, b) => a.index - b.index);
|
|
465
648
|
const layoutSizes = layoutResolved?.sizes ?? new Map();
|
|
466
649
|
const canvasForLayout = layoutCanvas;
|
|
467
|
-
const clipsByTrackId =
|
|
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
|
-
}
|
|
650
|
+
const { clipById, clipsByTrackId, matteSourceIds } = index;
|
|
475
651
|
const mediaLayers = [];
|
|
476
652
|
const captionLayers = [];
|
|
477
653
|
const resolvedAdjustments = [];
|
|
@@ -482,20 +658,6 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
482
658
|
// `matte` are held aside as the walk reaches them and handed to the layers
|
|
483
659
|
// that name them once the walk is over — the source may sit on a track below
|
|
484
660
|
// 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
661
|
const matteLayers = new Map();
|
|
500
662
|
const emitMedia = (layer) => {
|
|
501
663
|
layer.transform = layouts.get(layer.clipId) ?? layer.transform;
|
|
@@ -544,11 +706,8 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
544
706
|
considerBoundary(group.window.startMs);
|
|
545
707
|
considerBoundary(group.window.endMs);
|
|
546
708
|
}
|
|
547
|
-
for (const
|
|
548
|
-
|
|
549
|
-
considerBoundary(clip.startMs + clip.transitionIn.durationMs);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
709
|
+
for (const end of index.transitionEnds)
|
|
710
|
+
considerBoundary(end);
|
|
552
711
|
for (const track of sortedTracks) {
|
|
553
712
|
if (!track.visible)
|
|
554
713
|
continue;
|
|
@@ -563,10 +722,12 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
563
722
|
// carry its contribution to the frame. The transition resolver handles
|
|
564
723
|
// group clips as siblings separately, without pairing them with children.
|
|
565
724
|
// An adjustment is held out for the same reason: it treats the picture beneath,
|
|
566
|
-
// so it can be neither side of a cut.
|
|
725
|
+
// so it can be neither side of a cut. A hidden clip draws nothing, caption
|
|
726
|
+
// included, except as a matte source, which is never drawn itself.
|
|
567
727
|
const activeClips = trackClips
|
|
568
728
|
.filter((c) => c.mediaType !== "group" &&
|
|
569
729
|
c.mediaType !== "adjustment" &&
|
|
730
|
+
(!c.hidden || matteSourceIds.has(c.id)) &&
|
|
570
731
|
isClipActive(c, options.layerTimeMs?.(c) ?? currentTimeMs))
|
|
571
732
|
.sort((a, b) => a.startMs - b.startMs);
|
|
572
733
|
const drawClips = [...activeClips].sort((a, b) => {
|
|
@@ -585,7 +746,7 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
585
746
|
// z their treatment runs at. Only a visual track has a composite to treat.
|
|
586
747
|
if (isVisual) {
|
|
587
748
|
for (const clip of trackClips) {
|
|
588
|
-
if (clip.mediaType !== "adjustment")
|
|
749
|
+
if (clip.mediaType !== "adjustment" || clip.hidden)
|
|
589
750
|
continue;
|
|
590
751
|
if (!isClipActive(clip, currentTimeMs))
|
|
591
752
|
continue;
|
|
@@ -850,22 +1011,7 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
850
1011
|
const drawn = attachMattes(mediaLayers, matteLayers, clipById, droppedLayers);
|
|
851
1012
|
const precomposites = collectPrecomposites(clips, tracks, groups, usedSurfaces);
|
|
852
1013
|
if (precomposites.length > 0) {
|
|
853
|
-
const stackOrderByClipId =
|
|
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
|
-
}
|
|
1014
|
+
const stackOrderByClipId = stackOrderOf(index);
|
|
869
1015
|
for (const layer of drawn) {
|
|
870
1016
|
layer.stackOrder = stackOrderByClipId.get(layer.clipId);
|
|
871
1017
|
}
|
|
@@ -1473,7 +1619,7 @@ export function hasActiveAnimation(layers, currentTimeMs, canvas, cache, clips,
|
|
|
1473
1619
|
// child through `parentMatrix`, so a still child of a moving group is a
|
|
1474
1620
|
// moving layer. `clips` is how the ancestors are reached; without it only
|
|
1475
1621
|
// the layers' own animations are seen.
|
|
1476
|
-
const byId = clips ?
|
|
1622
|
+
const byId = clips ? sceneIndex(clips).clipById : null;
|
|
1477
1623
|
const animating = (clip) => {
|
|
1478
1624
|
if (clip.animationLinks?.length)
|
|
1479
1625
|
return true;
|