@nodetool-ai/timeline 0.8.1 → 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/authoring.d.ts.map +1 -1
- package/dist/authoring.js +46 -6
- package/dist/authoring.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/composition.d.ts +11 -1
- package/dist/composition.d.ts.map +1 -1
- package/dist/composition.js +58 -12
- package/dist/composition.js.map +1 -1
- 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/examples/node.d.ts +18 -0
- package/dist/examples/node.d.ts.map +1 -1
- package/dist/examples/node.js +26 -0
- package/dist/examples/node.js.map +1 -1
- package/dist/finish-storyboard.d.ts +36 -0
- package/dist/finish-storyboard.d.ts.map +1 -0
- package/dist/finish-storyboard.js +561 -0
- package/dist/finish-storyboard.js.map +1 -0
- package/dist/fonts/google-fonts-fetch.d.ts +53 -0
- package/dist/fonts/google-fonts-fetch.d.ts.map +1 -0
- package/dist/fonts/google-fonts-fetch.js +184 -0
- package/dist/fonts/google-fonts-fetch.js.map +1 -0
- package/dist/fonts/google-fonts-node.d.ts +32 -0
- package/dist/fonts/google-fonts-node.d.ts.map +1 -0
- package/dist/fonts/google-fonts-node.js +60 -0
- package/dist/fonts/google-fonts-node.js.map +1 -0
- package/dist/fonts/google-fonts.d.ts +111 -0
- package/dist/fonts/google-fonts.d.ts.map +1 -0
- package/dist/fonts/google-fonts.js +184 -0
- package/dist/fonts/google-fonts.js.map +1 -0
- package/dist/fonts/index.d.ts +1 -0
- package/dist/fonts/index.d.ts.map +1 -1
- package/dist/fonts/index.js +1 -0
- package/dist/fonts/index.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 +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -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.d.ts +2 -1
- package/dist/linked.d.ts.map +1 -1
- package/dist/linked.js +19 -11
- package/dist/linked.js.map +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/engines/kits.d.ts +2 -0
- package/dist/midi/engines/kits.d.ts.map +1 -1
- package/dist/midi/engines/kits.js +146 -0
- package/dist/midi/engines/kits.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/index.d.ts +1 -0
- package/dist/midi/index.d.ts.map +1 -1
- package/dist/midi/index.js +1 -0
- package/dist/midi/index.js.map +1 -1
- package/dist/midi/instrument.d.ts.map +1 -1
- package/dist/midi/instrument.js +5 -0
- package/dist/midi/instrument.js.map +1 -1
- package/dist/midi/presets.d.ts.map +1 -1
- package/dist/midi/presets.js +251 -1
- package/dist/midi/presets.js.map +1 -1
- package/dist/midi/sampler.d.ts +15 -0
- package/dist/midi/sampler.d.ts.map +1 -0
- package/dist/midi/sampler.js +72 -0
- package/dist/midi/sampler.js.map +1 -0
- 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/midi/voice.d.ts +4 -1
- package/dist/midi/voice.d.ts.map +1 -1
- package/dist/midi/voice.js +8 -4
- package/dist/midi/voice.js.map +1 -1
- package/dist/ops/apply.d.ts +15 -1
- package/dist/ops/apply.d.ts.map +1 -1
- package/dist/ops/apply.js +2123 -1090
- package/dist/ops/apply.js.map +1 -1
- package/dist/ops/index.d.ts +3 -2
- package/dist/ops/index.d.ts.map +1 -1
- package/dist/ops/index.js +3 -2
- package/dist/ops/index.js.map +1 -1
- package/dist/ops/op.d.ts +15 -3
- package/dist/ops/op.d.ts.map +1 -1
- package/dist/ops/op.js +17 -8
- package/dist/ops/op.js.map +1 -1
- package/dist/ops/parse.d.ts +6 -0
- package/dist/ops/parse.d.ts.map +1 -0
- package/dist/ops/parse.js +351 -0
- package/dist/ops/parse.js.map +1 -0
- package/dist/ops/serialize.d.ts +9 -1
- package/dist/ops/serialize.d.ts.map +1 -1
- package/dist/ops/serialize.js +19 -2
- package/dist/ops/serialize.js.map +1 -1
- package/dist/ops/types.d.ts +30 -8
- package/dist/ops/types.d.ts.map +1 -1
- package/dist/ops/types.js +2 -5
- package/dist/ops/types.js.map +1 -1
- package/dist/production.d.ts.map +1 -1
- package/dist/production.js +7 -0
- package/dist/production.js.map +1 -1
- package/dist/reassemble.d.ts +3 -1
- package/dist/reassemble.d.ts.map +1 -1
- package/dist/reassemble.js +7 -0
- package/dist/reassemble.js.map +1 -1
- package/dist/render/canvas2d.d.ts +3 -3
- package/dist/render/canvas2d.d.ts.map +1 -1
- package/dist/render/draw.d.ts +72 -3
- package/dist/render/draw.d.ts.map +1 -1
- package/dist/render/draw.js +168 -4
- 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/layout.d.ts +27 -3
- package/dist/render/layout.d.ts.map +1 -1
- package/dist/render/layout.js +464 -103
- package/dist/render/layout.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 +288 -93
- package/dist/render/sceneModel.js.map +1 -1
- package/dist/render/svgPath.d.ts +36 -8
- package/dist/render/svgPath.d.ts.map +1 -1
- package/dist/render/svgPath.js +303 -30
- package/dist/render/svgPath.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 +42 -0
- package/dist/render/textLayout.d.ts.map +1 -1
- package/dist/render/textLayout.js +59 -4
- package/dist/render/textLayout.js.map +1 -1
- package/dist/render/transform.d.ts +10 -0
- package/dist/render/transform.d.ts.map +1 -1
- package/dist/render/transform.js +15 -5
- package/dist/render/transform.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/source-merge.d.ts +84 -0
- package/dist/source-merge.d.ts.map +1 -0
- package/dist/source-merge.js +200 -0
- package/dist/source-merge.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.d.ts +20 -3
- package/dist/storyboard.d.ts.map +1 -1
- package/dist/storyboard.js +62 -28
- package/dist/storyboard.js.map +1 -1
- package/dist/storyboardDesignFrame.d.ts +15 -0
- package/dist/storyboardDesignFrame.d.ts.map +1 -0
- package/dist/storyboardDesignFrame.js +44 -0
- package/dist/storyboardDesignFrame.js.map +1 -0
- package/dist/storyboardValidation.d.ts +10 -0
- package/dist/storyboardValidation.d.ts.map +1 -0
- package/dist/storyboardValidation.js +47 -0
- package/dist/storyboardValidation.js.map +1 -0
- 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 +172 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +34 -4
|
@@ -16,10 +16,12 @@ 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
|
-
import {
|
|
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";
|
|
@@ -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,24 +448,36 @@ 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
|
*/
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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]));
|
|
433
481
|
const clipsByTrackId = new Map();
|
|
434
482
|
for (const c of clips) {
|
|
435
483
|
const arr = clipsByTrackId.get(c.trackId);
|
|
@@ -438,17 +486,6 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
438
486
|
else
|
|
439
487
|
clipsByTrackId.set(c.trackId, [c]);
|
|
440
488
|
}
|
|
441
|
-
const mediaLayers = [];
|
|
442
|
-
const captionLayers = [];
|
|
443
|
-
const resolvedAdjustments = [];
|
|
444
|
-
const droppedLayers = [];
|
|
445
|
-
let videoCount = 0;
|
|
446
|
-
let model3dCount = 0;
|
|
447
|
-
// Matte sources are diverted, not drawn: the clips named by a readable
|
|
448
|
-
// `matte` are held aside as the walk reaches them and handed to the layers
|
|
449
|
-
// that name them once the walk is over — the source may sit on a track below
|
|
450
|
-
// the one that reads it (D6).
|
|
451
|
-
const clipById = new Map(clips.map((clip) => [clip.id, clip]));
|
|
452
489
|
const matteSourceIds = new Set();
|
|
453
490
|
for (const clip of clips) {
|
|
454
491
|
const matte = clip.matte;
|
|
@@ -462,9 +499,184 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
462
499
|
continue;
|
|
463
500
|
matteSourceIds.add(matte.sourceClipId);
|
|
464
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
|
+
}
|
|
612
|
+
function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, options = {}) {
|
|
613
|
+
const maxVideoLayers = options.maxVideoLayers ?? MAX_VIDEO_LAYERS;
|
|
614
|
+
const transitions = resolveDocumentTransitions(clips, currentTimeMs);
|
|
615
|
+
const index = sceneIndex(clips);
|
|
616
|
+
const layoutCanvas = options.canvas;
|
|
617
|
+
const layoutResolved = layoutCanvas
|
|
618
|
+
? resolveClipLayoutsWithDiagnostics(layoutClipsAt(clips, index, currentTimeMs, layoutCanvas, options), layoutCanvasFor(index, layoutCanvas))
|
|
619
|
+
: undefined;
|
|
620
|
+
const layouts = layoutResolved?.transforms ?? new Map();
|
|
621
|
+
// Every entry in `layouts` — leaf or nested (non-root) flex container — is
|
|
622
|
+
// a delta already relative to the flex root's own untranslated frame
|
|
623
|
+
// (`layout.ts`'s `originX`/`originY` leave the root's own `position` out on
|
|
624
|
+
// purpose, so `resolveGroups`'s ordinary parent-matrix composition can add
|
|
625
|
+
// it exactly once when it places the root). A nested flex container's own
|
|
626
|
+
// *translation* is therefore already folded into every one of its
|
|
627
|
+
// descendants' resolved positions — composing it a second time, by handing
|
|
628
|
+
// `resolveGroups` this container's resolved (translated) transform as if it
|
|
629
|
+
// were freshly authored, would double it, the same bug the root itself had.
|
|
630
|
+
// What a nested container's own group matrix still has to contribute is any
|
|
631
|
+
// rotation/scale the author put on *it* — flex never touches those (`moved`
|
|
632
|
+
// only overwrites `position`) — so `resolveGroups` sees every flex-managed
|
|
633
|
+
// group's transform with `position` zeroed but everything else exactly as
|
|
634
|
+
// `layouts` left it. The flex root itself is untouched either way: it has
|
|
635
|
+
// no entry in `layouts` (excluded on purpose), so it keeps its own fully
|
|
636
|
+
// authored transform, position included — that position is the one and
|
|
637
|
+
// only real translation this composition is meant to add. A plain group
|
|
638
|
+
// inside a flex container is a leaf: flex moves the group and never lays
|
|
639
|
+
// out its children, so it keeps its resolved transform, position included.
|
|
640
|
+
const groupPatchedClips = layoutResolved && layouts.size > 0
|
|
641
|
+
? groupPatchedFor(clips, layoutResolved)
|
|
642
|
+
: clips;
|
|
643
|
+
// Parents before children: a child's opacity, matrix and window all come
|
|
644
|
+
// from a group that may sit on any track, so every group is resolved before
|
|
645
|
+
// the track walk starts.
|
|
646
|
+
const groups = resolveGroups(groupPatchedClips, currentTimeMs, options.canvas, options.animationCache, options.tempo, transitions, options.camera2d);
|
|
647
|
+
const sortedTracks = [...tracks].sort((a, b) => a.index - b.index);
|
|
648
|
+
const layoutSizes = layoutResolved?.sizes ?? new Map();
|
|
649
|
+
const canvasForLayout = layoutCanvas;
|
|
650
|
+
const { clipById, clipsByTrackId, matteSourceIds } = index;
|
|
651
|
+
const mediaLayers = [];
|
|
652
|
+
const captionLayers = [];
|
|
653
|
+
const resolvedAdjustments = [];
|
|
654
|
+
const droppedLayers = [];
|
|
655
|
+
let videoCount = 0;
|
|
656
|
+
let model3dCount = 0;
|
|
657
|
+
// Matte sources are diverted, not drawn: the clips named by a readable
|
|
658
|
+
// `matte` are held aside as the walk reaches them and handed to the layers
|
|
659
|
+
// that name them once the walk is over — the source may sit on a track below
|
|
660
|
+
// the one that reads it (D6).
|
|
465
661
|
const matteLayers = new Map();
|
|
466
662
|
const emitMedia = (layer) => {
|
|
467
663
|
layer.transform = layouts.get(layer.clipId) ?? layer.transform;
|
|
664
|
+
// A flex container resized this leaf (rect/ellipse's box, or a text
|
|
665
|
+
// clip's wrap width): apply it to the drawn clip, not just the measured
|
|
666
|
+
// one `resolveClipLayoutsWithDiagnostics` used internally, or the raster
|
|
667
|
+
// would still draw the authored size at the resolved position.
|
|
668
|
+
const flexSize = layoutSizes.get(layer.clipId);
|
|
669
|
+
if (flexSize && canvasForLayout) {
|
|
670
|
+
if (layer.clip.mediaType === "shape" && layer.clip.shapeStyle) {
|
|
671
|
+
// x/y pinned to 0 for the same reason layout.ts's own size override
|
|
672
|
+
// does: the resized box is measured from the top-left, not from
|
|
673
|
+
// `shapeBox`'s centered (0.25/0.25) default for an unset origin.
|
|
674
|
+
layer.clip = { ...layer.clip, shapeStyle: { ...layer.clip.shapeStyle, x: 0, y: 0, width: flexSize.width / canvasForLayout.width, height: flexSize.height / canvasForLayout.height } };
|
|
675
|
+
}
|
|
676
|
+
else if (layer.clip.mediaType === "text" && layer.clip.textStyle) {
|
|
677
|
+
layer.clip = { ...layer.clip, textStyle: { ...layer.clip.textStyle, maxWidthFrac: Math.min(1, Math.max(0.05, flexSize.width / canvasForLayout.width)) } };
|
|
678
|
+
}
|
|
679
|
+
}
|
|
468
680
|
layer.camera2d = layer.parentMatrix && layer.clip.parentId && groups.get(layer.clip.parentId)?.cameraApplied
|
|
469
681
|
? null
|
|
470
682
|
: options.camera2d;
|
|
@@ -494,11 +706,8 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
494
706
|
considerBoundary(group.window.startMs);
|
|
495
707
|
considerBoundary(group.window.endMs);
|
|
496
708
|
}
|
|
497
|
-
for (const
|
|
498
|
-
|
|
499
|
-
considerBoundary(clip.startMs + clip.transitionIn.durationMs);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
709
|
+
for (const end of index.transitionEnds)
|
|
710
|
+
considerBoundary(end);
|
|
502
711
|
for (const track of sortedTracks) {
|
|
503
712
|
if (!track.visible)
|
|
504
713
|
continue;
|
|
@@ -513,10 +722,12 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
513
722
|
// carry its contribution to the frame. The transition resolver handles
|
|
514
723
|
// group clips as siblings separately, without pairing them with children.
|
|
515
724
|
// An adjustment is held out for the same reason: it treats the picture beneath,
|
|
516
|
-
// 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.
|
|
517
727
|
const activeClips = trackClips
|
|
518
728
|
.filter((c) => c.mediaType !== "group" &&
|
|
519
729
|
c.mediaType !== "adjustment" &&
|
|
730
|
+
(!c.hidden || matteSourceIds.has(c.id)) &&
|
|
520
731
|
isClipActive(c, options.layerTimeMs?.(c) ?? currentTimeMs))
|
|
521
732
|
.sort((a, b) => a.startMs - b.startMs);
|
|
522
733
|
const drawClips = [...activeClips].sort((a, b) => {
|
|
@@ -535,7 +746,7 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
535
746
|
// z their treatment runs at. Only a visual track has a composite to treat.
|
|
536
747
|
if (isVisual) {
|
|
537
748
|
for (const clip of trackClips) {
|
|
538
|
-
if (clip.mediaType !== "adjustment")
|
|
749
|
+
if (clip.mediaType !== "adjustment" || clip.hidden)
|
|
539
750
|
continue;
|
|
540
751
|
if (!isClipActive(clip, currentTimeMs))
|
|
541
752
|
continue;
|
|
@@ -800,22 +1011,7 @@ function computeActiveLayersWithHorizonBase(tracks, clips, currentTimeMs, option
|
|
|
800
1011
|
const drawn = attachMattes(mediaLayers, matteLayers, clipById, droppedLayers);
|
|
801
1012
|
const precomposites = collectPrecomposites(clips, tracks, groups, usedSurfaces);
|
|
802
1013
|
if (precomposites.length > 0) {
|
|
803
|
-
const stackOrderByClipId =
|
|
804
|
-
for (const trackClips of clipsByTrackId.values()) {
|
|
805
|
-
const ordered = trackClips
|
|
806
|
-
.filter((clip) => clip.mediaType !== "adjustment")
|
|
807
|
-
.sort((a, b) => {
|
|
808
|
-
const depth = (a.transform?.depthPx ?? 0) - (b.transform?.depthPx ?? 0);
|
|
809
|
-
if (depth !== 0)
|
|
810
|
-
return depth;
|
|
811
|
-
const aEcho = a.id.includes(":echo:") ? 0 : 1;
|
|
812
|
-
const bEcho = b.id.includes(":echo:") ? 0 : 1;
|
|
813
|
-
if (aEcho !== bEcho)
|
|
814
|
-
return aEcho - bEcho;
|
|
815
|
-
return a.startMs - b.startMs;
|
|
816
|
-
});
|
|
817
|
-
ordered.forEach((clip, index) => stackOrderByClipId.set(clip.id, index));
|
|
818
|
-
}
|
|
1014
|
+
const stackOrderByClipId = stackOrderOf(index);
|
|
819
1015
|
for (const layer of drawn) {
|
|
820
1016
|
layer.stackOrder = stackOrderByClipId.get(layer.clipId);
|
|
821
1017
|
}
|
|
@@ -957,27 +1153,26 @@ function attachMattes(layers, matteLayers, clipById, droppedLayers) {
|
|
|
957
1153
|
}
|
|
958
1154
|
const matte = layer.clip.matte;
|
|
959
1155
|
const mode = matte ? parseMatteMode(matte.mode) : null;
|
|
960
|
-
if (
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1156
|
+
if (matte && mode !== null) {
|
|
1157
|
+
const source = matteLayers.get(matte.sourceClipId);
|
|
1158
|
+
if (source) {
|
|
1159
|
+
layer.matte = { mode, invert: matte.invert ?? false, layer: source };
|
|
1160
|
+
}
|
|
1161
|
+
else {
|
|
1162
|
+
// A source that is not in the document, and an adjustment — which has
|
|
1163
|
+
// no pixels of its own — are the same case: no matte, and the layer
|
|
1164
|
+
// draws.
|
|
1165
|
+
const sourceClip = clipById.get(matte.sourceClipId);
|
|
1166
|
+
if (sourceClip && sourceClip.mediaType !== "adjustment") {
|
|
1167
|
+
droppedLayers.push({
|
|
1168
|
+
clipId: layer.clipId,
|
|
1169
|
+
reason: "matte_source_inactive"
|
|
1170
|
+
});
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
976
1174
|
}
|
|
977
|
-
|
|
978
|
-
clipId: layer.clipId,
|
|
979
|
-
reason: "matte_source_inactive"
|
|
980
|
-
});
|
|
1175
|
+
out.push(layer);
|
|
981
1176
|
}
|
|
982
1177
|
return out;
|
|
983
1178
|
}
|
|
@@ -1424,7 +1619,7 @@ export function hasActiveAnimation(layers, currentTimeMs, canvas, cache, clips,
|
|
|
1424
1619
|
// child through `parentMatrix`, so a still child of a moving group is a
|
|
1425
1620
|
// moving layer. `clips` is how the ancestors are reached; without it only
|
|
1426
1621
|
// the layers' own animations are seen.
|
|
1427
|
-
const byId = clips ?
|
|
1622
|
+
const byId = clips ? sceneIndex(clips).clipById : null;
|
|
1428
1623
|
const animating = (clip) => {
|
|
1429
1624
|
if (clip.animationLinks?.length)
|
|
1430
1625
|
return true;
|