@softure-ai/marketing-kit 0.43.0 → 0.45.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 +29 -0
- package/README.md +14 -1
- package/dist/footage/draft-overlays.d.ts +23 -0
- package/dist/footage/draft-overlays.d.ts.map +1 -1
- package/dist/footage/draft-overlays.js +42 -28
- package/dist/footage/draft-overlays.js.map +1 -1
- package/dist/footage/draft-text-width.d.ts +22 -0
- package/dist/footage/draft-text-width.d.ts.map +1 -1
- package/dist/footage/draft-text-width.js +31 -1
- package/dist/footage/draft-text-width.js.map +1 -1
- package/dist/footage/draft.d.ts +14 -1
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +27 -6
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/film.d.ts +2 -1
- package/dist/footage/film.d.ts.map +1 -1
- package/dist/footage/film.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 +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/footage/draft-overlays.ts +55 -29
- package/src/footage/draft-text-width.ts +43 -1
- package/src/footage/draft.ts +29 -7
- package/src/footage/film.ts +2 -1
- 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 +8 -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
|
-
import { DEFAULT_CONTENT_AREA, getSpacingWidth, toDraftAssSize, toDraftSpacing, wrapDraftLine, type DraftFont } from "./draft-text-width.js";
|
|
5
|
+
import { DEFAULT_CONTENT_AREA, getDraftLineShift, getDraftMiddleShift, 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
|
|
|
@@ -204,6 +205,13 @@ interface DraftContext {
|
|
|
204
205
|
layout?: OverlayTextMeasure;
|
|
205
206
|
/** The content area (ascent, descent in ems) of the font of `role`, as a browser sizes an inline box. */
|
|
206
207
|
contentArea: (role: DraftFontRole) => { ascentEm: number; descentEm: number };
|
|
208
|
+
/**
|
|
209
|
+
* How far a line of `role` placed by its top moves so its baseline stands where the render's does in a line box of
|
|
210
|
+
* `lineHeightEm` (`getDraftLineShift`), in px; 0 without the draft's fonts (as before).
|
|
211
|
+
*/
|
|
212
|
+
lineShift: (role: DraftFontRole, cssPx: number, lineHeightEm: number) => number;
|
|
213
|
+
/** The same for a line placed by its middle (`getDraftMiddleShift`); 0 without the draft's fonts. */
|
|
214
|
+
middleShift: (role: DraftFontRole, cssPx: number) => number;
|
|
207
215
|
}
|
|
208
216
|
|
|
209
217
|
/**
|
|
@@ -268,6 +276,24 @@ function getWipeClip(motion: DraftMotion): { x0: number; y0: number; x1: number;
|
|
|
268
276
|
}
|
|
269
277
|
|
|
270
278
|
const toClip = (box: { x0: number; y0: number; x1: number; y1: number }): string => `\\clip(${box.x0},${box.y0},${box.x1},${box.y1})`;
|
|
279
|
+
|
|
280
|
+
type ClipBox = { x0: number; y0: number; x1: number; y1: number };
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* A clip moving from `from` to `to` between `fromMs` and `toMs` of its event along the render's `ease`: one `\\t` per
|
|
284
|
+
* render frame (libass interpolates each straight), so the draft's clip stands where the render's does in every frame.
|
|
285
|
+
*/
|
|
286
|
+
export function getEasedClipTags(from: ClipBox, to: ClipBox, input: { fromMs: number; toMs: number; ease: OverlayEase }): string {
|
|
287
|
+
const frames = Math.max(1, Math.round(((input.toMs - input.fromMs) / 1000) * FOOTAGE_FPS));
|
|
288
|
+
const at = (share: number): ClipBox => ({
|
|
289
|
+
x0: r0(from.x0 + (to.x0 - from.x0) * share),
|
|
290
|
+
y0: r0(from.y0 + (to.y0 - from.y0) * share),
|
|
291
|
+
x1: r0(from.x1 + (to.x1 - from.x1) * share),
|
|
292
|
+
y1: r0(from.y1 + (to.y1 - from.y1) * share),
|
|
293
|
+
});
|
|
294
|
+
const ms = (frame: number) => Math.round(input.fromMs + ((input.toMs - input.fromMs) * frame) / frames);
|
|
295
|
+
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("");
|
|
296
|
+
}
|
|
271
297
|
const toMs = (seconds: number): number => Math.max(0, Math.round(seconds * 1000));
|
|
272
298
|
|
|
273
299
|
/**
|
|
@@ -299,15 +325,16 @@ function getMotionTags(motion: DraftMotion, input: { isFirst: boolean; isLast: b
|
|
|
299
325
|
if (input.isFirst && entrance.kind === "wipe") {
|
|
300
326
|
const halves = getWipeHalves(entrance.seconds);
|
|
301
327
|
const [grow, reveal] = [toMs(halves.grow), toMs(halves.reveal)];
|
|
302
|
-
const closed =
|
|
303
|
-
|
|
328
|
+
const closed = { ...clip, x1: clip.x0 };
|
|
329
|
+
const half = input.part === "card" ? { fromMs: 0, toMs: grow } : { fromMs: grow, toMs: grow + reveal };
|
|
330
|
+
tags.push(`${toClip(closed)}${getEasedClipTags(closed, clip, { ...half, ease: entrance.ease })}`);
|
|
304
331
|
}
|
|
305
332
|
let fadeOut = 0;
|
|
306
333
|
if (input.isLast && exit.kind !== "none") {
|
|
307
334
|
if (exit.kind === "wipe") {
|
|
308
335
|
const exitMs = toMs(exit.seconds);
|
|
309
336
|
if (!(input.isFirst && entrance.kind === "wipe")) tags.push(toClip(clip));
|
|
310
|
-
tags.push(
|
|
337
|
+
tags.push(getEasedClipTags(clip, { ...clip, x0: clip.x1 }, { fromMs: Math.max(0, ms - exitMs), toMs: ms, ease: exit.ease }));
|
|
311
338
|
} else {
|
|
312
339
|
fadeOut = motion.isSnappy ? r0(FADE_OUT_MS * 0.7) : FADE_OUT_MS;
|
|
313
340
|
if (exit.kind === "tween" && exit.from.y > 0 && !motion.isCardMoved) {
|
|
@@ -420,7 +447,9 @@ function getWipePanelEvent(overlay: Pick<ResolvedOverlay, "start">, drawing: str
|
|
|
420
447
|
const halves = getWipeHalves(motion.entrance.seconds);
|
|
421
448
|
const [grow, reveal] = [toMs(halves.grow), toMs(halves.reveal)];
|
|
422
449
|
const clip = getWipeClip(motion);
|
|
423
|
-
const
|
|
450
|
+
const ease = motion.entrance.ease;
|
|
451
|
+
const closed = { ...clip, x1: clip.x0 };
|
|
452
|
+
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
453
|
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
454
|
}
|
|
426
455
|
|
|
@@ -631,7 +660,7 @@ function getLaidOutSideTextEvents(overlay: Extract<ResolvedOverlay, { kind: "key
|
|
|
631
660
|
const isTyped = overlay.entrance !== null && overlay.entrance !== "drop" && overlay.typing !== null;
|
|
632
661
|
let typedBefore = 0;
|
|
633
662
|
const lines = layout.lines.flatMap((line, index) => {
|
|
634
|
-
const pos = { x: layout.textX, y: layout.textTop + index * lineHeight };
|
|
663
|
+
const pos = { x: layout.textX, y: layout.textTop + index * lineHeight + context.lineShift(role, fontSize, OVERLAY_LINE_HEIGHT) };
|
|
635
664
|
const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
|
|
636
665
|
const count = [...line].length;
|
|
637
666
|
const steps =
|
|
@@ -704,8 +733,9 @@ function getListEvents(overlay: Extract<ResolvedOverlay, { kind: "list" }>, cont
|
|
|
704
733
|
const name = overlay.entrance === null || overlay.entrance === "type" ? "fade" : overlay.entrance;
|
|
705
734
|
const textTags = getTextTags(overlay, colors, context, OVERLAY_FONT_ROLES.list);
|
|
706
735
|
const lines = getSideTextLines(overlay);
|
|
707
|
-
const
|
|
708
|
-
|
|
736
|
+
const shift = context.lineShift(OVERLAY_FONT_ROLES.list, fontSize, OVERLAY_LINE_HEIGHT);
|
|
737
|
+
const write = (at: OverlayPoint, align: number, steps: TextStep[], motion: DraftMotion, clip = "") =>
|
|
738
|
+
getTextEvents({ layer: 4, style: "OverlayPlain", pos: { x: at.x, y: at.y + shift }, tags: `\\an${align}\\fs${context.toAssSize(OVERLAY_FONT_ROLES.list, fontSize)}${context.spacing(OVERLAY_LETTER_SPACING_EM.card, fontSize)}${textTags}${clip}`, steps, motion });
|
|
709
739
|
if (overlay.chips !== undefined) {
|
|
710
740
|
const covered = getChipCoveredTimes(overlay);
|
|
711
741
|
return overlay.chips.flatMap((_chip, index) => {
|
|
@@ -890,8 +920,10 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
|
890
920
|
// The render spaces a title's heading lines tighter than the rest of a card's text, and a search query not at all.
|
|
891
921
|
const spacingFor = (role: OverlayFontRole): number =>
|
|
892
922
|
overlay.kind === "search_bar" ? 0 : role !== "heading" ? OVERLAY_LETTER_SPACING_EM.card : overlay.kind === "hook_title" ? OVERLAY_LETTER_SPACING_EM.hookTitle : overlay.kind === "place_card" ? OVERLAY_LETTER_SPACING_EM.placeTitle : OVERLAY_LETTER_SPACING_EM.card;
|
|
893
|
-
|
|
894
|
-
|
|
923
|
+
// Every card line is set by its top in the render's line box (a title's heading lines in theirs, the rest in `OVERLAY_LINE_HEIGHT`).
|
|
924
|
+
const lineBoxFor = (role: OverlayFontRole): number => (role === "heading" && overlay.kind === "place_card" ? OVERLAY_TITLE_LINE_HEIGHT : OVERLAY_LINE_HEIGHT);
|
|
925
|
+
const text = (at: OverlayPoint, align: number, size: number, role: OverlayFontRole, steps: TextStep[], own: DraftMotion = motion) =>
|
|
926
|
+
getTextEvents({ layer: 4, style: "OverlayPlain", pos: { x: at.x, y: at.y + (align >= 7 ? context.lineShift(role, r0(size), lineBoxFor(role)) : align >= 4 ? context.middleShift(role, r0(size)) : 0) }, tags: `\\an${align}\\fs${context.toAssSize(role, r0(size))}${context.spacing(spacingFor(role), r0(size))}${tagsFor(role)}`, steps, motion: own });
|
|
895
927
|
const plain = { ...motion, name: "none" as const, entrance: { kind: "none" as const } };
|
|
896
928
|
if (overlay.kind === "hook_title" || overlay.kind === "place_card") {
|
|
897
929
|
// The text block sits in the card's middle; centred lines on its axis, left ones from its left edge (RV-131).
|
|
@@ -921,7 +953,7 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
|
921
953
|
if (overlay.kind === "hook_title" && (isMarked || overlay.entrance === "drop")) {
|
|
922
954
|
const letters = getDropLetterTimes(span.start, overlay.lines.join(""));
|
|
923
955
|
overlay.lines.forEach((line) => {
|
|
924
|
-
const lineStart = overlay.typing === null ? span.start : span.start + typedBefore
|
|
956
|
+
const lineStart = overlay.typing === null ? span.start : span.start + typedBefore * getTypingStep(overlay.typing);
|
|
925
957
|
if (isMarked) {
|
|
926
958
|
const align = isLeft ? "left" : "center";
|
|
927
959
|
const { layout } = context;
|
|
@@ -947,7 +979,7 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
|
947
979
|
overlay.lines.forEach((line) => {
|
|
948
980
|
// The lines type one after the other, as the render's characters do; a left line holds its place transparent
|
|
949
981
|
// from the start, a centred one shows its typed part only (`getTypedSteps`).
|
|
950
|
-
const lineStart = overlay.typing === null ? times.title : span.start + typedBefore
|
|
982
|
+
const lineStart = overlay.typing === null ? times.title : span.start + typedBefore * getTypingStep(overlay.typing);
|
|
951
983
|
const steps = getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
|
|
952
984
|
// A centred typed line has no hidden first step to carry the entrance: its letters appear as typed, as the render's.
|
|
953
985
|
const isTypedCentre = !isLeft && overlay.typing !== null;
|
|
@@ -977,18 +1009,9 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
|
977
1009
|
const gap = context.layout === undefined ? null : toDraftSpacing(overlay.fontSize * COUNTER_UNIT_GAP_EM - context.layout("heading", " ", overlay.unitFontSize, 0), 1);
|
|
978
1010
|
const space = gap === null ? " " : `{\\fsp${String(gap)}}\\h{\\fsp${String(toDraftSpacing(OVERLAY_LETTER_SPACING_EM.card, fontSize))}}`;
|
|
979
1011
|
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
1012
|
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
|
-
}
|
|
1013
|
+
// One step per render frame, each the value the render's tween shows in that frame.
|
|
1014
|
+
const steps: TextStep[] = getFrameSteps({ start: span.start, end: span.end, fps: FOOTAGE_FPS, valueAt: (seconds) => show(getCounterValueAt(overlay, seconds)) });
|
|
992
1015
|
const shown = steps.filter((step) => step.to > step.from);
|
|
993
1016
|
const { layout } = context;
|
|
994
1017
|
if (layout === undefined) return [...events, ...text({ x: centerX, y: box.top + box.height / 2 }, 5, fontSize, "heading", shown)];
|
|
@@ -1106,13 +1129,14 @@ function getNoteEvents(overlay: Extract<ResolvedOverlay, { kind: "note" }>, cont
|
|
|
1106
1129
|
const assSize = isStrip ? context.toAssSize("heading", overlay.fontSize) : getHandFontAssSize(overlay.fontSize);
|
|
1107
1130
|
const tags = `\\an7\\fs${assSize}${isStrip ? context.spacing(OVERLAY_LETTER_SPACING_EM.strip, overlay.fontSize) : ""}${font}\\1c${toTagColor(colors.ink)}${turn}`;
|
|
1108
1131
|
getNoteWordsByLine(overlay).forEach((words, index) => {
|
|
1109
|
-
|
|
1132
|
+
// A strip's heading font stands on the render's baseline; the hand font is sized to its own letters (`getHandFontAssSize`).
|
|
1133
|
+
const pos = { x: textBox.left, y: textBox.top + index * lineHeight + (isStrip ? context.lineShift("heading", overlay.fontSize, NOTE_LINE_HEIGHT) : 0) };
|
|
1110
1134
|
const line = overlay.lines[index] as string;
|
|
1111
1135
|
const span = { start: overlay.start, end: overlay.end };
|
|
1112
1136
|
if (isStrip) {
|
|
1113
1137
|
const before = overlay.lines.slice(0, index).join("").length;
|
|
1114
1138
|
const typing = overlay.typing ?? 14;
|
|
1115
|
-
const steps = getTypedSteps(line, { start: overlay.start + before
|
|
1139
|
+
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
1140
|
events.push(...getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, motion: textMotion }));
|
|
1117
1141
|
return;
|
|
1118
1142
|
}
|
|
@@ -1179,6 +1203,8 @@ export function buildDraftOverlayEvents(
|
|
|
1179
1203
|
measure: (role, text, cssPx, spacingEm) => (drawn === undefined ? estimateTextWidth(text, cssPx) : drawn[role].measure(text, cssPx) + getSpacingWidth(text, spacingEm, cssPx)),
|
|
1180
1204
|
spacing: (spacingEm, cssPx) => (drawn === undefined || spacingEm === 0 ? "" : `\\fsp${String(toDraftSpacing(spacingEm, cssPx))}`),
|
|
1181
1205
|
contentArea: (role) => drawn?.[role].contentArea ?? DEFAULT_CONTENT_AREA,
|
|
1206
|
+
lineShift: (role, cssPx, lineHeightEm) => (drawn === undefined ? 0 : getDraftLineShift(drawn[role], cssPx, lineHeightEm)),
|
|
1207
|
+
middleShift: (role, cssPx) => (drawn === undefined ? 0 : getDraftMiddleShift(drawn[role], cssPx)),
|
|
1182
1208
|
...(options.style === undefined ? {} : { style: options.style }),
|
|
1183
1209
|
...(drawn === undefined ? {} : { layout: (role: OverlayFontRole, text: string, cssPx: number, spacingEm: number) => drawn[role].measure(text, cssPx) + getSpacingWidth(text, spacingEm, cssPx) }),
|
|
1184
1210
|
};
|
|
@@ -13,6 +13,10 @@ export type DraftTextMeasure = (text: string, fontSize: number) => number;
|
|
|
13
13
|
interface Metrics {
|
|
14
14
|
/** The font's units per libass font size: `usWinAscent + usWinDescent`. */
|
|
15
15
|
unitsPerSize: number;
|
|
16
|
+
/** How far below a line's top libass sets its baseline, in font units: `usWinAscent` (else the `hhea` ascender). */
|
|
17
|
+
drawnAscent: number;
|
|
18
|
+
/** How far above a line's foot libass sets its baseline, in font units: `usWinDescent` (else the `hhea` descender). */
|
|
19
|
+
drawnDescent: number;
|
|
16
20
|
/** The font's units per em (`head`), what a browser sizes it by; 0 when the font has no `head`. */
|
|
17
21
|
unitsPerEm: number;
|
|
18
22
|
advances: (glyph: number) => number;
|
|
@@ -39,12 +43,15 @@ function readMetrics(font: Buffer): Metrics | null {
|
|
|
39
43
|
const os2 = tables.value.get("OS/2");
|
|
40
44
|
const winSum = os2 === undefined ? 0 : readUint16(os2, 74) + readUint16(os2, 76);
|
|
41
45
|
const unitsPerSize = winSum > 0 ? winSum : readInt16(hhea, 4) - readInt16(hhea, 6);
|
|
46
|
+
const isWin = winSum > 0 && os2 !== undefined;
|
|
47
|
+
const drawnAscent = isWin ? readUint16(os2, 74) : readInt16(hhea, 4);
|
|
48
|
+
const drawnDescent = isWin ? readUint16(os2, 76) : -readInt16(hhea, 6);
|
|
42
49
|
const count = readUint16(hhea, 34);
|
|
43
50
|
if (unitsPerSize <= 0 || count === 0 || hmtx.length < count * 4) return null;
|
|
44
51
|
const head = tables.value.get("head");
|
|
45
52
|
const unitsPerEm = head === undefined ? 0 : readUint16(head, 18);
|
|
46
53
|
// Glyphs past `numberOfHMetrics` share the last advance (OpenType `hmtx`).
|
|
47
|
-
return { unitsPerSize, unitsPerEm, advances: (glyph) => readUint16(hmtx, Math.min(glyph, count - 1) * 4), ...readContentArea(hhea, os2) };
|
|
54
|
+
return { unitsPerSize, drawnAscent, drawnDescent, unitsPerEm, advances: (glyph) => readUint16(hmtx, Math.min(glyph, count - 1) * 4), ...readContentArea(hhea, os2) };
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
/**
|
|
@@ -86,6 +93,14 @@ export interface DraftFont {
|
|
|
86
93
|
* elsewhere, which then takes `DEFAULT_CONTENT_AREA`.
|
|
87
94
|
*/
|
|
88
95
|
contentArea?: { ascentEm: number; descentEm: number };
|
|
96
|
+
/**
|
|
97
|
+
* How far below a line's top libass sets the baseline, in ems: `usWinAscent / unitsPerEm`. A browser sets it at the
|
|
98
|
+
* half-leading plus the content area's ascent, so a line placed by its top is moved by the difference
|
|
99
|
+
* (`getDraftLineShift`); absent for a font made elsewhere, which is not moved.
|
|
100
|
+
*/
|
|
101
|
+
drawnAscentEm?: number;
|
|
102
|
+
/** How far above a line's foot libass sets the baseline, in ems: `usWinDescent / unitsPerEm`; absent with `drawnAscentEm`. */
|
|
103
|
+
drawnDescentEm?: number;
|
|
89
104
|
}
|
|
90
105
|
|
|
91
106
|
/** The content area a font without its own is given, in ems: a common sans serif's. */
|
|
@@ -96,6 +111,31 @@ export function toDraftAssSize(cssPx: number, assScale: number): number {
|
|
|
96
111
|
return Math.round(cssPx * assScale * 100) / 100;
|
|
97
112
|
}
|
|
98
113
|
|
|
114
|
+
/**
|
|
115
|
+
* How far to move a line of `font` drawn by its top (`\\an7`, `\\an8`, `\\an9`) so its baseline stands where the
|
|
116
|
+
* render's does in a line box of `lineHeightEm` at `cssPx`, in px (negative: up). libass sets the baseline
|
|
117
|
+
* `drawnAscentEm` below the top; a browser half the leading plus the content area's ascent. 0 for a font without its
|
|
118
|
+
* metrics (as before).
|
|
119
|
+
*/
|
|
120
|
+
export function getDraftLineShift(font: Pick<DraftFont, "contentArea" | "drawnAscentEm">, cssPx: number, lineHeightEm: number): number {
|
|
121
|
+
if (font.drawnAscentEm === undefined || font.contentArea === undefined) return 0;
|
|
122
|
+
const { ascentEm, descentEm } = font.contentArea;
|
|
123
|
+
const browserBaseline = (lineHeightEm - ascentEm - descentEm) / 2 + ascentEm;
|
|
124
|
+
return Math.round((browserBaseline - font.drawnAscentEm) * cssPx * 100) / 100;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* How far to move a line of `font` drawn by its middle (`\\an4`, `\\an5`, `\\an6`) so its baseline stands where a
|
|
129
|
+
* browser's does in a line box centred on the same point, in px (negative: up): a browser's baseline stands half the
|
|
130
|
+
* content area's ascent less its descent below the middle, libass's half the win ascent less the win descent. 0 for a
|
|
131
|
+
* font without its metrics (as before).
|
|
132
|
+
*/
|
|
133
|
+
export function getDraftMiddleShift(font: Pick<DraftFont, "contentArea" | "drawnAscentEm" | "drawnDescentEm">, cssPx: number): number {
|
|
134
|
+
if (font.drawnAscentEm === undefined || font.drawnDescentEm === undefined || font.contentArea === undefined) return 0;
|
|
135
|
+
const { ascentEm, descentEm } = font.contentArea;
|
|
136
|
+
return Math.round(((ascentEm - descentEm - (font.drawnAscentEm - font.drawnDescentEm)) / 2) * cssPx * 100) / 100;
|
|
137
|
+
}
|
|
138
|
+
|
|
99
139
|
/** The ASS letter spacing (`\\fsp`, `Spacing`, in the frame's px) of the render's `letter-spacing` of `spacingEm` at `cssPx`, to 0.01. */
|
|
100
140
|
export function toDraftSpacing(spacingEm: number, cssPx: number): number {
|
|
101
141
|
return Math.round(spacingEm * cssPx * 100) / 100;
|
|
@@ -128,6 +168,8 @@ export function createDraftFont(source: { family: string; file: string }, data:
|
|
|
128
168
|
file: source.file,
|
|
129
169
|
assScale: metrics.unitsPerSize / unitsPerEm,
|
|
130
170
|
contentArea: { ascentEm: metrics.ascent / unitsPerEm, descentEm: metrics.descent / unitsPerEm },
|
|
171
|
+
drawnAscentEm: metrics.drawnAscent / unitsPerEm,
|
|
172
|
+
drawnDescentEm: metrics.drawnDescent / unitsPerEm,
|
|
131
173
|
measure: (text, fontSize) => {
|
|
132
174
|
let units = 0;
|
|
133
175
|
for (const character of text) units += metrics.advances(map.getGlyph(character.codePointAt(0) ?? 0));
|
package/src/footage/draft.ts
CHANGED
|
@@ -25,7 +25,7 @@ import { resolveEdlOverlays, type OverlayFontRole, type OverlayTextMeasure, type
|
|
|
25
25
|
import { chooseFootageDraftFont } from "./draft-font.js";
|
|
26
26
|
import { getEdlDuration, getSegmentStarts, remapWords, type Edl } from "./edl.js";
|
|
27
27
|
import { declickSpeech, describeDeclick, type DeclickReport } from "./declick.js";
|
|
28
|
-
import { CAPTION_RIBBON, getDeclickLevel, getFootageEdit, type FootageFilm } from "./film.js";
|
|
28
|
+
import { CAPTION_MIN_FONT_SCALE, CAPTION_RIBBON, getDeclickLevel, getFootageEdit, type FootageFilm } from "./film.js";
|
|
29
29
|
import { buildFilmMixArgs } from "./film-mix.js";
|
|
30
30
|
import { DEFAULT_LOUDNESS, formatDb, getLoudnessVerdict, measureLoudness, normalizeLoudness, type MixLoudnessTarget } from "./loudness.js";
|
|
31
31
|
import { duckingKeyframes, getDuckingOptions } from "./music.js";
|
|
@@ -167,7 +167,7 @@ function toAssText(text: string): string {
|
|
|
167
167
|
export type FootageDraftCaptionColors = Pick<BrandColors, "captionBackground" | "captionText" | "captionHighlight" | "captionHighlightBox" | "captionHighlightText">;
|
|
168
168
|
|
|
169
169
|
export interface FootageDraftCaptionsInput {
|
|
170
|
-
film: Pick<FootageFilm, "captions" | "captionStyle" | "captionHighlightStyle" | "captionRibbonTilt"> & CaptionWordsFilm;
|
|
170
|
+
film: Pick<FootageFilm, "captions" | "captionStyle" | "captionHighlightStyle" | "captionRibbonTilt" | "captionMaxLines"> & CaptionWordsFilm;
|
|
171
171
|
edl: Edl;
|
|
172
172
|
/** The film's words in film time (`remapWords`). */
|
|
173
173
|
words: TimedWord[];
|
|
@@ -339,6 +339,19 @@ function getDrawnPill(input: DrawnPillInput): DrawnPill {
|
|
|
339
339
|
return { breaks, events: getDraftBoxEvents({ layer: 0, at, styleName: "CaptionShape", box, radius, color: input.colors.background, accent: input.colors.accent, style, scale }), words };
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
+
/**
|
|
343
|
+
* A caption chunk's place at the size the render's fit script gives it (`getCaptionFitScript`): with `maxLines`, the
|
|
344
|
+
* font shrinks in 1 px steps while its words (each kept whole, as the render's inline blocks are) take more lines of
|
|
345
|
+
* `width` than that, down to `minFontSize`; without, the place as it is.
|
|
346
|
+
*/
|
|
347
|
+
export function fitDraftCaptionPlace(input: { words: readonly string[]; place: CaptionLayout; width: number; maxLines: number | undefined; minFontSize: number; measure: DraftTextMeasure }): CaptionLayout {
|
|
348
|
+
const { maxLines } = input;
|
|
349
|
+
if (maxLines === undefined || input.words.length === 0) return input.place;
|
|
350
|
+
let size = input.place.fontSize;
|
|
351
|
+
while (wrapDraftLine(input.words, input.width, size, input.measure).length > maxLines && size > input.minFontSize) size -= 1;
|
|
352
|
+
return size === input.place.fontSize ? input.place : { ...input.place, fontSize: size };
|
|
353
|
+
}
|
|
354
|
+
|
|
342
355
|
interface RibbonInput {
|
|
343
356
|
text: string;
|
|
344
357
|
span: { start: number; end: number };
|
|
@@ -456,7 +469,7 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
456
469
|
const toStyle = (name: string, place: CaptionLayout): string => [
|
|
457
470
|
name,
|
|
458
471
|
family,
|
|
459
|
-
styleSize,
|
|
472
|
+
place.fontSize === caption.fontSize ? styleSize : toDraftAssSize(place.fontSize, lineScale),
|
|
460
473
|
look.primary,
|
|
461
474
|
look.primary,
|
|
462
475
|
look.outlineColor,
|
|
@@ -467,7 +480,7 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
467
480
|
0,
|
|
468
481
|
100,
|
|
469
482
|
100,
|
|
470
|
-
spacing,
|
|
483
|
+
place.fontSize === caption.fontSize || fonts === undefined ? spacing : toDraftSpacing(isRibbon ? CAPTION_RIBBON_LETTER_SPACING_EM : CAPTION_LETTER_SPACING_EM, place.fontSize),
|
|
471
484
|
0,
|
|
472
485
|
look.borderStyle,
|
|
473
486
|
look.outline,
|
|
@@ -482,10 +495,19 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
482
495
|
// A chunk in a segment's own box gets a style of that box (Caption2, Caption3, ...); the film's box stays `Caption`.
|
|
483
496
|
const styles = [toStyle("Caption", caption)];
|
|
484
497
|
const moved: CaptionLayout[] = [];
|
|
485
|
-
|
|
498
|
+
// Each chunk at the size the render's fit gives it (`captionMaxLines`): a smaller one takes a style of its own.
|
|
499
|
+
const fitWidth = (place: CaptionLayout) => frame.width - place.left - place.right - (isHighlight && input.style !== undefined ? 2 * getStylePadding(CAPTION_PILL_PADDING, input.style.padding).x : 0);
|
|
500
|
+
const fitMeasure = fonts === undefined ? (input.measure ?? ((line: string, size: number) => estimateTextWidth(line, size))) : withLetterSpacing(fonts.body.measure, CAPTION_LETTER_SPACING_EM);
|
|
501
|
+
const minFontSize = Math.round(caption.fontSize * CAPTION_MIN_FONT_SCALE);
|
|
502
|
+
const places = getCaptionChunkLayouts(chunks, input.edl, caption).map((place, index) =>
|
|
503
|
+
isRibbon
|
|
504
|
+
? place
|
|
505
|
+
: fitDraftCaptionPlace({ words: (chunks[index]?.words ?? []).map((word) => word.text.replace(/\u00a0/g, " ")), place, width: fitWidth(place), maxLines: input.film.captionMaxLines, minFontSize, measure: fitMeasure }),
|
|
506
|
+
);
|
|
507
|
+
const isSameStyle = (a: CaptionLayout, b: CaptionLayout) => isSameCaptionPlace(a, b) && a.fontSize === b.fontSize;
|
|
486
508
|
const styleNames = places.map((place) => {
|
|
487
|
-
if (
|
|
488
|
-
let index = moved.findIndex((other) =>
|
|
509
|
+
if (isSameStyle(place, caption)) return "Caption";
|
|
510
|
+
let index = moved.findIndex((other) => isSameStyle(other, place));
|
|
489
511
|
if (index === -1) {
|
|
490
512
|
index = moved.push(place) - 1;
|
|
491
513
|
styles.push(toStyle(`Caption${index + 2}`, place));
|
package/src/footage/film.ts
CHANGED
|
@@ -148,7 +148,8 @@ export interface FootageFilm {
|
|
|
148
148
|
captionPreset?: CaptionPreset;
|
|
149
149
|
/**
|
|
150
150
|
* The most lines a caption card may take: the render shrinks a longer card's font (to at most
|
|
151
|
-
* `CAPTION_MIN_FONT_SCALE` of the box's size) until it fits. Absent: no limit. The draft
|
|
151
|
+
* `CAPTION_MIN_FONT_SCALE` of the box's size) until it fits. Absent: no limit. The draft fits each chunk the same
|
|
152
|
+
* way (`fitDraftCaptionPlace`).
|
|
152
153
|
*/
|
|
153
154
|
captionMaxLines?: number;
|
|
154
155
|
/**
|
|
@@ -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
|
@@ -161,6 +161,8 @@ export {
|
|
|
161
161
|
DEFAULT_CONTENT_AREA,
|
|
162
162
|
createDraftFont,
|
|
163
163
|
createDraftTextMeasure,
|
|
164
|
+
getDraftLineShift,
|
|
165
|
+
getDraftMiddleShift,
|
|
164
166
|
getSpacingWidth,
|
|
165
167
|
toDraftAssSize,
|
|
166
168
|
toDraftSpacing,
|
|
@@ -230,6 +232,7 @@ export {
|
|
|
230
232
|
} from "./footage/overlays.js";
|
|
231
233
|
export {
|
|
232
234
|
OVERLAY_EASES,
|
|
235
|
+
OVERLAY_TYPING_DELAY,
|
|
233
236
|
POP_FROM_SCALE,
|
|
234
237
|
RISE_FROM_HEIGHT,
|
|
235
238
|
getEntranceMotion,
|
|
@@ -238,6 +241,10 @@ export {
|
|
|
238
241
|
getListItemStarts,
|
|
239
242
|
getDropLetterTimes,
|
|
240
243
|
getDropOffsetAt,
|
|
244
|
+
getFrameSteps,
|
|
245
|
+
getTypingStep,
|
|
246
|
+
getTypingTimes,
|
|
247
|
+
type FrameStep,
|
|
241
248
|
type OverlayEase,
|
|
242
249
|
type OverlayEntranceMotion,
|
|
243
250
|
type OverlayExitMotion,
|
|
@@ -712,6 +719,7 @@ export {
|
|
|
712
719
|
FOOTAGE_DRAFT_OVERLAY_COLORS,
|
|
713
720
|
FOOTAGE_DRAFT_FONT,
|
|
714
721
|
FOOTAGE_DRAFT_WIDTH,
|
|
722
|
+
fitDraftCaptionPlace,
|
|
715
723
|
loadFootageDraftFonts,
|
|
716
724
|
createOverlayTextMeasure,
|
|
717
725
|
type FootageDraftFonts,
|