@softure-ai/marketing-kit 0.43.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +6 -0
- package/dist/footage/draft-overlays.d.ts +16 -0
- package/dist/footage/draft-overlays.d.ts.map +1 -1
- package/dist/footage/draft-overlays.js +31 -23
- package/dist/footage/draft-overlays.js.map +1 -1
- package/dist/footage/overlay-html.d.ts +13 -4
- package/dist/footage/overlay-html.d.ts.map +1 -1
- package/dist/footage/overlay-html.js +15 -9
- package/dist/footage/overlay-html.js.map +1 -1
- package/dist/footage/overlay-motion.d.ts +31 -4
- package/dist/footage/overlay-motion.d.ts.map +1 -1
- package/dist/footage/overlay-motion.js +53 -5
- package/dist/footage/overlay-motion.js.map +1 -1
- package/dist/footage/overlays.js +2 -2
- package/dist/footage/overlays.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/footage/draft-overlays.ts +35 -22
- package/src/footage/overlay-html.ts +20 -8
- package/src/footage/overlay-motion.ts +61 -5
- package/src/footage/overlays.ts +2 -2
- package/src/index.ts +5 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { FOOTAGE_FPS } from "./normalize.js";
|
|
1
2
|
import { getCornerRadiusPx, type BrandStyle, type CornerRadius } from "./brand-style.js";
|
|
2
3
|
import { getDraftBoxEvents } from "./draft-boxes.js";
|
|
3
4
|
import { toAssColor } from "./draft-color.js";
|
|
4
5
|
import { DEFAULT_CONTENT_AREA, getSpacingWidth, toDraftAssSize, toDraftSpacing, wrapDraftLine, type DraftFont } from "./draft-text-width.js";
|
|
5
6
|
import { HAND_FONT, getHandFontAssSize } from "./hand-font.js";
|
|
6
|
-
import {
|
|
7
|
+
import { getCounterValueAt, getOverlayColors, getPlaceCardTimes, getTypingStep, getTypingTimes, type OverlayColors } from "./overlay-html.js";
|
|
7
8
|
import {
|
|
8
9
|
DROP_LETTER_SECONDS,
|
|
9
10
|
NOTE_GROW_FROM_SCALE,
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
NOTE_TICK_SECONDS,
|
|
12
13
|
OVERLAY_EASES,
|
|
13
14
|
getDropLetterTimes,
|
|
15
|
+
getFrameSteps,
|
|
14
16
|
PIN_DROP_SECONDS,
|
|
15
17
|
PIN_DROP_SHARE,
|
|
16
18
|
UNDERLINE_EM,
|
|
@@ -18,6 +20,7 @@ import {
|
|
|
18
20
|
getEntranceMotion,
|
|
19
21
|
getExitMotion,
|
|
20
22
|
getWipeHalves,
|
|
23
|
+
type OverlayEase,
|
|
21
24
|
type OverlayEntranceMotion,
|
|
22
25
|
type OverlayExitMotion,
|
|
23
26
|
} from "./overlay-motion.js";
|
|
@@ -72,7 +75,7 @@ import {
|
|
|
72
75
|
* drawn rounded cards of the brand's background, fitted to their text, with the text in its foreground; an
|
|
73
76
|
* arrow is a straight shaft and head in the accent; a highlight the accent's outline round its rectangle; a pin and a
|
|
74
77
|
* magnifier are drawings in the accent. A typed text shows letter by letter (the rest transparent, so its card keeps
|
|
75
|
-
* its size), a counter
|
|
78
|
+
* its size), a counter shows its value in every frame, a slide moves up into place. A `punch_in` is drawn
|
|
76
79
|
* by the picture's zoom (`buildPictureFilters`), not here. They sit on layers 3 and 4, over the captions' 0 to 2.
|
|
77
80
|
*/
|
|
78
81
|
|
|
@@ -87,8 +90,6 @@ const FADE = `\\fad(${FADE_IN_MS},${FADE_OUT_MS})`;
|
|
|
87
90
|
/** How far a slide starts below its place, in px of a 1080 px wide frame, and how long it takes. */
|
|
88
91
|
const SLIDE_PX = 28;
|
|
89
92
|
const SLIDE_MS = 300;
|
|
90
|
-
/** A counter's step in the draft, in seconds. */
|
|
91
|
-
const COUNT_STEP = 0.1;
|
|
92
93
|
/** A transparent primary colour: the typed text not shown yet. */
|
|
93
94
|
const HIDDEN = "{\\1a&HFF&}";
|
|
94
95
|
|
|
@@ -268,6 +269,24 @@ function getWipeClip(motion: DraftMotion): { x0: number; y0: number; x1: number;
|
|
|
268
269
|
}
|
|
269
270
|
|
|
270
271
|
const toClip = (box: { x0: number; y0: number; x1: number; y1: number }): string => `\\clip(${box.x0},${box.y0},${box.x1},${box.y1})`;
|
|
272
|
+
|
|
273
|
+
type ClipBox = { x0: number; y0: number; x1: number; y1: number };
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* A clip moving from `from` to `to` between `fromMs` and `toMs` of its event along the render's `ease`: one `\\t` per
|
|
277
|
+
* render frame (libass interpolates each straight), so the draft's clip stands where the render's does in every frame.
|
|
278
|
+
*/
|
|
279
|
+
export function getEasedClipTags(from: ClipBox, to: ClipBox, input: { fromMs: number; toMs: number; ease: OverlayEase }): string {
|
|
280
|
+
const frames = Math.max(1, Math.round(((input.toMs - input.fromMs) / 1000) * FOOTAGE_FPS));
|
|
281
|
+
const at = (share: number): ClipBox => ({
|
|
282
|
+
x0: r0(from.x0 + (to.x0 - from.x0) * share),
|
|
283
|
+
y0: r0(from.y0 + (to.y0 - from.y0) * share),
|
|
284
|
+
x1: r0(from.x1 + (to.x1 - from.x1) * share),
|
|
285
|
+
y1: r0(from.y1 + (to.y1 - from.y1) * share),
|
|
286
|
+
});
|
|
287
|
+
const ms = (frame: number) => Math.round(input.fromMs + ((input.toMs - input.fromMs) * frame) / frames);
|
|
288
|
+
return Array.from({ length: frames }, (_unused, index) => `\\t(${ms(index)},${ms(index + 1)},${toClip(index + 1 === frames ? to : at(OVERLAY_EASES[input.ease]((index + 1) / frames)))})`).join("");
|
|
289
|
+
}
|
|
271
290
|
const toMs = (seconds: number): number => Math.max(0, Math.round(seconds * 1000));
|
|
272
291
|
|
|
273
292
|
/**
|
|
@@ -299,15 +318,16 @@ function getMotionTags(motion: DraftMotion, input: { isFirst: boolean; isLast: b
|
|
|
299
318
|
if (input.isFirst && entrance.kind === "wipe") {
|
|
300
319
|
const halves = getWipeHalves(entrance.seconds);
|
|
301
320
|
const [grow, reveal] = [toMs(halves.grow), toMs(halves.reveal)];
|
|
302
|
-
const closed =
|
|
303
|
-
|
|
321
|
+
const closed = { ...clip, x1: clip.x0 };
|
|
322
|
+
const half = input.part === "card" ? { fromMs: 0, toMs: grow } : { fromMs: grow, toMs: grow + reveal };
|
|
323
|
+
tags.push(`${toClip(closed)}${getEasedClipTags(closed, clip, { ...half, ease: entrance.ease })}`);
|
|
304
324
|
}
|
|
305
325
|
let fadeOut = 0;
|
|
306
326
|
if (input.isLast && exit.kind !== "none") {
|
|
307
327
|
if (exit.kind === "wipe") {
|
|
308
328
|
const exitMs = toMs(exit.seconds);
|
|
309
329
|
if (!(input.isFirst && entrance.kind === "wipe")) tags.push(toClip(clip));
|
|
310
|
-
tags.push(
|
|
330
|
+
tags.push(getEasedClipTags(clip, { ...clip, x0: clip.x1 }, { fromMs: Math.max(0, ms - exitMs), toMs: ms, ease: exit.ease }));
|
|
311
331
|
} else {
|
|
312
332
|
fadeOut = motion.isSnappy ? r0(FADE_OUT_MS * 0.7) : FADE_OUT_MS;
|
|
313
333
|
if (exit.kind === "tween" && exit.from.y > 0 && !motion.isCardMoved) {
|
|
@@ -420,7 +440,9 @@ function getWipePanelEvent(overlay: Pick<ResolvedOverlay, "start">, drawing: str
|
|
|
420
440
|
const halves = getWipeHalves(motion.entrance.seconds);
|
|
421
441
|
const [grow, reveal] = [toMs(halves.grow), toMs(halves.reveal)];
|
|
422
442
|
const clip = getWipeClip(motion);
|
|
423
|
-
const
|
|
443
|
+
const ease = motion.entrance.ease;
|
|
444
|
+
const closed = { ...clip, x1: clip.x0 };
|
|
445
|
+
const tags = `${toClip(closed)}${getEasedClipTags(closed, clip, { fromMs: 0, toMs: grow, ease })}${getEasedClipTags(clip, { ...clip, x0: clip.x1 }, { fromMs: grow, toMs: grow + reveal, ease })}`;
|
|
424
446
|
return [`Dialogue: 3,${toAssTime(overlay.start)},${toAssTime(overlay.start + motion.entrance.seconds)},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${tags}\\1c${toTagColor(accent)}\\p1}${drawing}{\\p0}`];
|
|
425
447
|
}
|
|
426
448
|
|
|
@@ -921,7 +943,7 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
|
921
943
|
if (overlay.kind === "hook_title" && (isMarked || overlay.entrance === "drop")) {
|
|
922
944
|
const letters = getDropLetterTimes(span.start, overlay.lines.join(""));
|
|
923
945
|
overlay.lines.forEach((line) => {
|
|
924
|
-
const lineStart = overlay.typing === null ? span.start : span.start + typedBefore
|
|
946
|
+
const lineStart = overlay.typing === null ? span.start : span.start + typedBefore * getTypingStep(overlay.typing);
|
|
925
947
|
if (isMarked) {
|
|
926
948
|
const align = isLeft ? "left" : "center";
|
|
927
949
|
const { layout } = context;
|
|
@@ -947,7 +969,7 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
|
947
969
|
overlay.lines.forEach((line) => {
|
|
948
970
|
// The lines type one after the other, as the render's characters do; a left line holds its place transparent
|
|
949
971
|
// from the start, a centred one shows its typed part only (`getTypedSteps`).
|
|
950
|
-
const lineStart = overlay.typing === null ? times.title : span.start + typedBefore
|
|
972
|
+
const lineStart = overlay.typing === null ? times.title : span.start + typedBefore * getTypingStep(overlay.typing);
|
|
951
973
|
const steps = getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
|
|
952
974
|
// A centred typed line has no hidden first step to carry the entrance: its letters appear as typed, as the render's.
|
|
953
975
|
const isTypedCentre = !isLeft && overlay.typing !== null;
|
|
@@ -977,18 +999,9 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
|
977
999
|
const gap = context.layout === undefined ? null : toDraftSpacing(overlay.fontSize * COUNTER_UNIT_GAP_EM - context.layout("heading", " ", overlay.unitFontSize, 0), 1);
|
|
978
1000
|
const space = gap === null ? " " : `{\\fsp${String(gap)}}\\h{\\fsp${String(toDraftSpacing(OVERLAY_LETTER_SPACING_EM.card, fontSize))}}`;
|
|
979
1001
|
const unit = overlay.unit === null ? "" : `{\\fs${context.toAssSize("heading", overlay.unitFontSize)}}${space}${toAssText(overlay.unit)}`;
|
|
980
|
-
const count = getCounterSeconds(overlay);
|
|
981
|
-
const steps: TextStep[] = [];
|
|
982
|
-
const ticks = Math.max(1, Math.round(count.duration / COUNT_STEP));
|
|
983
1002
|
const show = (value: number) => `${formatOverlayNumber(value, overlay.decimals, context.locale)}${unit}`;
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
const progress = tick / ticks;
|
|
987
|
-
// power2.out, as the render's tween eases: the count slows down to its value.
|
|
988
|
-
const eased = OVERLAY_EASES["power2.out"](progress);
|
|
989
|
-
const value = overlay.from + (overlay.value - overlay.from) * eased;
|
|
990
|
-
steps.push({ from: count.start + (tick - 1) * COUNT_STEP, to: tick === ticks ? span.end : count.start + tick * COUNT_STEP, text: show(value) });
|
|
991
|
-
}
|
|
1003
|
+
// One step per render frame, each the value the render's tween shows in that frame.
|
|
1004
|
+
const steps: TextStep[] = getFrameSteps({ start: span.start, end: span.end, fps: FOOTAGE_FPS, valueAt: (seconds) => show(getCounterValueAt(overlay, seconds)) });
|
|
992
1005
|
const shown = steps.filter((step) => step.to > step.from);
|
|
993
1006
|
const { layout } = context;
|
|
994
1007
|
if (layout === undefined) return [...events, ...text({ x: centerX, y: box.top + box.height / 2 }, 5, fontSize, "heading", shown)];
|
|
@@ -1112,7 +1125,7 @@ function getNoteEvents(overlay: Extract<ResolvedOverlay, { kind: "note" }>, cont
|
|
|
1112
1125
|
if (isStrip) {
|
|
1113
1126
|
const before = overlay.lines.slice(0, index).join("").length;
|
|
1114
1127
|
const typing = overlay.typing ?? 14;
|
|
1115
|
-
const steps = getTypedSteps(line, { start: overlay.start + before
|
|
1128
|
+
const steps = getTypedSteps(line, { start: overlay.start + before * getTypingStep(typing), end: overlay.end }, typing).map((step, stepIndex) => (stepIndex === 0 ? { ...step, from: overlay.start } : step));
|
|
1116
1129
|
events.push(...getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, motion: textMotion }));
|
|
1117
1130
|
return;
|
|
1118
1131
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
NOTE_GROW_FROM_SCALE,
|
|
12
12
|
NOTE_GROW_SECONDS,
|
|
13
13
|
NOTE_TICK_SECONDS,
|
|
14
|
+
OVERLAY_EASES,
|
|
14
15
|
getDropLetterTurns,
|
|
15
16
|
PIN_DROP_SECONDS,
|
|
16
17
|
PIN_DROP_SHARE,
|
|
@@ -19,10 +20,15 @@ import {
|
|
|
19
20
|
UNDERLINE_SECONDS,
|
|
20
21
|
getEntranceMotion,
|
|
21
22
|
getExitMotion,
|
|
23
|
+
getTypingStep,
|
|
22
24
|
getWipeHalves,
|
|
25
|
+
OVERLAY_TYPING_DELAY,
|
|
26
|
+
type OverlayEase,
|
|
23
27
|
type OverlayEntranceMotion,
|
|
24
28
|
type OverlayMotionOffset,
|
|
25
29
|
} from "./overlay-motion.js";
|
|
30
|
+
|
|
31
|
+
export { OVERLAY_TYPING_DELAY, getTypingStep, getTypingTimes } from "./overlay-motion.js";
|
|
26
32
|
import {
|
|
27
33
|
NOTE_LINE_HEIGHT,
|
|
28
34
|
OVERLAY_LETTER_SPACING_EM,
|
|
@@ -72,8 +78,6 @@ const EXIT_SECONDS = 0.3;
|
|
|
72
78
|
const STROKE_WIDTH = 10;
|
|
73
79
|
/** The arrow head's length, in px of a 1080 px wide frame. */
|
|
74
80
|
const ARROW_HEAD = 46;
|
|
75
|
-
/** When a typed overlay starts typing, after its card has faded in, in seconds from its start. */
|
|
76
|
-
export const OVERLAY_TYPING_DELAY = 0.3;
|
|
77
81
|
/** When a counter starts counting, in seconds from its start. */
|
|
78
82
|
const COUNT_DELAY = 0.15;
|
|
79
83
|
|
|
@@ -99,9 +103,17 @@ export function getCounterSeconds(overlay: { start: number; end: number }): { st
|
|
|
99
103
|
return { start: r3(overlay.start + COUNT_DELAY), duration: r3(Math.min(1.6, Math.max(0.6, (overlay.end - overlay.start) * 0.5))) };
|
|
100
104
|
}
|
|
101
105
|
|
|
102
|
-
/** The
|
|
103
|
-
export
|
|
104
|
-
|
|
106
|
+
/** The ease a counter counts along. */
|
|
107
|
+
export const COUNTER_EASE = "power2.out" satisfies OverlayEase;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A counter's value at film second `seconds`, as the render's tween sets it: `from` until it starts counting, then
|
|
111
|
+
* along `COUNTER_EASE` to `value`, and `value` after. The draft shows this value in every frame.
|
|
112
|
+
*/
|
|
113
|
+
export function getCounterValueAt(overlay: { start: number; end: number; from: number; value: number }, seconds: number): number {
|
|
114
|
+
const count = getCounterSeconds(overlay);
|
|
115
|
+
const progress = Math.min(1, Math.max(0, (seconds - count.start) / count.duration));
|
|
116
|
+
return overlay.from + (overlay.value - overlay.from) * OVERLAY_EASES[COUNTER_EASE](progress);
|
|
105
117
|
}
|
|
106
118
|
|
|
107
119
|
/** The CSS every overlay kind shares, written once when the film has any drawn overlay. */
|
|
@@ -320,7 +332,7 @@ function getExitTweens(target: string, overlay: Exclude<ResolvedOverlay, { kind:
|
|
|
320
332
|
/** The typing tweens: each character of `#<id>` shown at its time. */
|
|
321
333
|
function getTypingTweens(id: string, overlay: { start: number; typing: number | null }, length: number): string[] {
|
|
322
334
|
if (overlay.typing === null || length === 0) return [];
|
|
323
|
-
return [`tl.to("#${id} .ch", { opacity: 1, display: "inline", duration: 0.01, ease: "none", stagger: ${
|
|
335
|
+
return [`tl.to("#${id} .ch", { opacity: 1, display: "inline", duration: 0.01, ease: "none", stagger: ${getTypingStep(overlay.typing)} }, ${r3(overlay.start + OVERLAY_TYPING_DELAY)});`];
|
|
324
336
|
}
|
|
325
337
|
|
|
326
338
|
/** Shows each typed line's highlight mark (`#<id>m<line>`, a keyword's `#<id>t`) with the line's first letter. */
|
|
@@ -329,7 +341,7 @@ function getMarkRevealTweens(ids: readonly string[], overlay: { start: number; t
|
|
|
329
341
|
if (typing === null) return [];
|
|
330
342
|
let offset = 0;
|
|
331
343
|
return lines.flatMap((line, index) => {
|
|
332
|
-
const at = overlay.start + OVERLAY_TYPING_DELAY + offset
|
|
344
|
+
const at = overlay.start + OVERLAY_TYPING_DELAY + offset * getTypingStep(typing);
|
|
333
345
|
offset += [...line].length;
|
|
334
346
|
const target = ids[index];
|
|
335
347
|
return line === "" || target === undefined ? [] : [`tl.set("#${target}", { display: "inline" }, ${r3(at)});`];
|
|
@@ -540,7 +552,7 @@ function addCard(overlay: CardOverlay, id: string, context: MarkupContext, out:
|
|
|
540
552
|
const format = `new Intl.NumberFormat(${toScriptString(getScriptLocale(context.locale))}, { minimumFractionDigits: ${overlay.decimals}, maximumFractionDigits: ${overlay.decimals} })`;
|
|
541
553
|
// The number eases up to its value; the timeline renders it on every seek, so each frame shows its own count.
|
|
542
554
|
out.tweens.push(
|
|
543
|
-
`(function () { const el = document.getElementById("${id}n"); const nf = ${format}; const n = { v: ${overlay.from} }; tl.fromTo(n, { v: ${overlay.from} }, { v: ${overlay.value}, duration: ${count.duration}, ease: "
|
|
555
|
+
`(function () { const el = document.getElementById("${id}n"); const nf = ${format}; const n = { v: ${overlay.from} }; tl.fromTo(n, { v: ${overlay.from} }, { v: ${overlay.value}, duration: ${count.duration}, ease: "${COUNTER_EASE}", immediateRender: false, onUpdate: () => { el.textContent = nf.format(n.v).replace(/[\\u00a0\\u202f]/g, " "); } }, ${count.start}); })();`,
|
|
544
556
|
);
|
|
545
557
|
}
|
|
546
558
|
out.tweens.push(...getExitTweens(`#${id} .ov-card`, overlay, context.frame, `tl.to("#${id} .ov-card", { y: 10, opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${r3(overlay.end - EXIT_SECONDS)});`));
|
|
@@ -6,16 +6,54 @@ import type { OverlayEasing, OverlayEntrance, OverlayExit } from "./overlay-sche
|
|
|
6
6
|
* start to its rest and never past it, so no element grows past 100 % (`getEntranceScaleAt`). No bounce, no elastic.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
/**
|
|
9
|
+
/** GSAP 3's `expo.in`, of which `expo.out` is the mirror. */
|
|
10
|
+
const expoIn = (t: number): number => 2 ** (10 * (t - 1)) * t + t ** 6 * (1 - t);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A GSAP ease name and its curve, exactly as GSAP 3 computes it (the render's tweens name the ease, the draft computes
|
|
14
|
+
* its steps from the curve, so the two stand at the same place in every frame): each one rises from 0 to 1 and never
|
|
15
|
+
* passes 1. GSAP's `powerN` is a polynomial of degree N + 1 (`power1` is the quadratic), so `power2.out` is cubic.
|
|
16
|
+
*/
|
|
10
17
|
export const OVERLAY_EASES = {
|
|
11
|
-
"power2.out": (t: number) => 1 - (1 - t) **
|
|
12
|
-
"power3.out": (t: number) => 1 - (1 - t) **
|
|
13
|
-
"expo.out": (t: number) =>
|
|
14
|
-
"power2.in": (t: number) => t **
|
|
18
|
+
"power2.out": (t: number) => 1 - (1 - t) ** 3,
|
|
19
|
+
"power3.out": (t: number) => 1 - (1 - t) ** 4,
|
|
20
|
+
"expo.out": (t: number) => 1 - expoIn(1 - t),
|
|
21
|
+
"power2.in": (t: number) => t ** 3,
|
|
15
22
|
} as const;
|
|
16
23
|
|
|
17
24
|
export type OverlayEase = keyof typeof OVERLAY_EASES;
|
|
18
25
|
|
|
26
|
+
/** A step of a value the draft changes every frame: shown from `from` to `to` (film seconds). */
|
|
27
|
+
export interface FrameStep {
|
|
28
|
+
from: number;
|
|
29
|
+
to: number;
|
|
30
|
+
text: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A value that changes every frame, as the draft's steps: one step per film frame from `start` to `end`, showing
|
|
35
|
+
* `valueAt` that frame's second, each spanning half a frame either side of it (so rounding a step's edges to the
|
|
36
|
+
* centisecond never moves a frame into its neighbour's step); neighbours that show the same text are joined. A span
|
|
37
|
+
* with no frame in it shows `valueAt(start)`.
|
|
38
|
+
*/
|
|
39
|
+
export function getFrameSteps(input: { start: number; end: number; fps: number; valueAt: (seconds: number) => string }): FrameStep[] {
|
|
40
|
+
const { start, end, fps } = input;
|
|
41
|
+
if (!(end > start)) return [];
|
|
42
|
+
const first = Math.ceil(start * fps - 1e-6);
|
|
43
|
+
const last = Math.ceil(end * fps - 1e-6) - 1;
|
|
44
|
+
if (last < first) return [{ from: start, to: end, text: input.valueAt(start) }];
|
|
45
|
+
const steps: FrameStep[] = [];
|
|
46
|
+
for (let frame = first; frame <= last; frame++) {
|
|
47
|
+
const from = frame === first ? start : (frame - 0.5) / fps;
|
|
48
|
+
const to = frame === last ? end : (frame + 0.5) / fps;
|
|
49
|
+
const text = input.valueAt(frame / fps);
|
|
50
|
+
const previous = steps.at(-1);
|
|
51
|
+
if (previous?.text === text) previous.to = to;
|
|
52
|
+
else steps.push({ from, to, text });
|
|
53
|
+
}
|
|
54
|
+
return steps;
|
|
55
|
+
}
|
|
56
|
+
|
|
19
57
|
/** How far from its rest an overlay starts or ends: its opacity, its scale, px below its place, px of blur. */
|
|
20
58
|
export interface OverlayMotionOffset {
|
|
21
59
|
opacity: number;
|
|
@@ -54,6 +92,24 @@ export const OVERLAY_EXIT_SECONDS = 0.3;
|
|
|
54
92
|
/** How much quicker a snappy curve runs. */
|
|
55
93
|
const SNAPPY_SPEED = 0.7;
|
|
56
94
|
|
|
95
|
+
/** When a typed overlay starts typing, after its card has faded in, in seconds from its start. */
|
|
96
|
+
export const OVERLAY_TYPING_DELAY = 0.3;
|
|
97
|
+
|
|
98
|
+
/** The seconds between two typed characters at `speed` characters a second: the render's stagger, to the millisecond. */
|
|
99
|
+
export function getTypingStep(speed: number): number {
|
|
100
|
+
return r3(1 / speed);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The film seconds each character of a typed text appears at, from `OVERLAY_TYPING_DELAY` after `start`, one
|
|
105
|
+
* `getTypingStep` apart (the render's stagger). `firstIndex` characters were typed before it (a later line of the
|
|
106
|
+
* same overlay), so its first character comes that many steps later.
|
|
107
|
+
*/
|
|
108
|
+
export function getTypingTimes(start: number, text: string, speed: number, firstIndex = 0): number[] {
|
|
109
|
+
const step = getTypingStep(speed);
|
|
110
|
+
return [...text].map((_char, index) => r3(start + OVERLAY_TYPING_DELAY + (firstIndex + index) * step));
|
|
111
|
+
}
|
|
112
|
+
|
|
57
113
|
const REST: OverlayMotionOffset = { opacity: 1, scale: 1, y: 0, blur: 0 };
|
|
58
114
|
const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
|
|
59
115
|
|
package/src/footage/overlays.ts
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import { isCameraMoving, isSameCamera } from "./camera.js";
|
|
25
25
|
import { getSegmentZoomEases } from "./compose.js";
|
|
26
26
|
import { normalizeWord } from "./words.js";
|
|
27
|
-
import { NOTE_FIRST_WORD_LEAD, NOTE_TICK_DELAY, getListItemStarts } from "./overlay-motion.js";
|
|
27
|
+
import { NOTE_FIRST_WORD_LEAD, NOTE_TICK_DELAY, OVERLAY_TYPING_DELAY, getListItemStarts, getTypingStep } from "./overlay-motion.js";
|
|
28
28
|
import { STYLE_PADDING_SCALES, type BrandStyle, type CornerRadius } from "./brand-style.js";
|
|
29
29
|
import { measureHandText } from "./hand-font.js";
|
|
30
30
|
|
|
@@ -1008,7 +1008,7 @@ export function timeNote(note: Extract<ResolvedOverlay, { kind: "note" }>, words
|
|
|
1008
1008
|
const latest = r3(Math.max(first, note.end - 0.6));
|
|
1009
1009
|
if (note.noteStyle === "strip") {
|
|
1010
1010
|
const typed = note.typing ?? DEFAULT_OVERLAY_TYPING_SPEED;
|
|
1011
|
-
const lastLetter = note.start +
|
|
1011
|
+
const lastLetter = note.start + OVERLAY_TYPING_DELAY + ([...note.lines.join("")].length - 1) * getTypingStep(typed);
|
|
1012
1012
|
return { wordTimes: null, tickAt: tickAfter(lastLetter) };
|
|
1013
1013
|
}
|
|
1014
1014
|
const said = words.filter((word) => word.start >= note.start - 0.05 && word.start < note.end);
|
package/src/index.ts
CHANGED
|
@@ -230,6 +230,7 @@ export {
|
|
|
230
230
|
} from "./footage/overlays.js";
|
|
231
231
|
export {
|
|
232
232
|
OVERLAY_EASES,
|
|
233
|
+
OVERLAY_TYPING_DELAY,
|
|
233
234
|
POP_FROM_SCALE,
|
|
234
235
|
RISE_FROM_HEIGHT,
|
|
235
236
|
getEntranceMotion,
|
|
@@ -238,6 +239,10 @@ export {
|
|
|
238
239
|
getListItemStarts,
|
|
239
240
|
getDropLetterTimes,
|
|
240
241
|
getDropOffsetAt,
|
|
242
|
+
getFrameSteps,
|
|
243
|
+
getTypingStep,
|
|
244
|
+
getTypingTimes,
|
|
245
|
+
type FrameStep,
|
|
241
246
|
type OverlayEase,
|
|
242
247
|
type OverlayEntranceMotion,
|
|
243
248
|
type OverlayExitMotion,
|