@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.
Files changed (40) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +14 -1
  3. package/dist/footage/draft-overlays.d.ts +23 -0
  4. package/dist/footage/draft-overlays.d.ts.map +1 -1
  5. package/dist/footage/draft-overlays.js +42 -28
  6. package/dist/footage/draft-overlays.js.map +1 -1
  7. package/dist/footage/draft-text-width.d.ts +22 -0
  8. package/dist/footage/draft-text-width.d.ts.map +1 -1
  9. package/dist/footage/draft-text-width.js +31 -1
  10. package/dist/footage/draft-text-width.js.map +1 -1
  11. package/dist/footage/draft.d.ts +14 -1
  12. package/dist/footage/draft.d.ts.map +1 -1
  13. package/dist/footage/draft.js +27 -6
  14. package/dist/footage/draft.js.map +1 -1
  15. package/dist/footage/film.d.ts +2 -1
  16. package/dist/footage/film.d.ts.map +1 -1
  17. package/dist/footage/film.js.map +1 -1
  18. package/dist/footage/overlay-html.d.ts +13 -4
  19. package/dist/footage/overlay-html.d.ts.map +1 -1
  20. package/dist/footage/overlay-html.js +15 -9
  21. package/dist/footage/overlay-html.js.map +1 -1
  22. package/dist/footage/overlay-motion.d.ts +31 -4
  23. package/dist/footage/overlay-motion.d.ts.map +1 -1
  24. package/dist/footage/overlay-motion.js +53 -5
  25. package/dist/footage/overlay-motion.js.map +1 -1
  26. package/dist/footage/overlays.js +2 -2
  27. package/dist/footage/overlays.js.map +1 -1
  28. package/dist/index.d.ts +3 -3
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +3 -3
  31. package/dist/index.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/footage/draft-overlays.ts +55 -29
  34. package/src/footage/draft-text-width.ts +43 -1
  35. package/src/footage/draft.ts +29 -7
  36. package/src/footage/film.ts +2 -1
  37. package/src/footage/overlay-html.ts +20 -8
  38. package/src/footage/overlay-motion.ts +61 -5
  39. package/src/footage/overlays.ts +2 -2
  40. package/src/index.ts +8 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,35 @@ Newest first. Each version lists what changed for an app that uses `@softure-ai/
4
4
  production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
5
5
  "Definition of done"). Versions before the first one below are described in their GitHub Releases (`marketing-kit@x.y.z`).
6
6
 
7
+ ## 0.45.0
8
+
9
+ - **The draft sets every line on the render's baseline:** libass sets a line's baseline `usWinAscent` below its top,
10
+ a browser half the leading plus the content area's ascent; for a brand font whose win ascent stands far above its
11
+ typo ascent (a display serif's 1.3 em over 1.0 em) every heading line stood about 0.375 em lower in the draft: a
12
+ place card's title fell onto its subtitle, a keyword's last line hung out of its card. `DraftFont` reads
13
+ `drawnAscentEm` and `drawnDescentEm`; every overlay line placed by its top or its middle moves by
14
+ `getDraftLineShift` or `getDraftMiddleShift` (both 0 without the draft's fonts, as before).
15
+ - **The draft fits captions to `captionMaxLines` as the render does:** a chunk's font shrinks in 1 px steps, down to
16
+ `CAPTION_MIN_FONT_SCALE` of the box's size, until it takes at most that many lines (`fitDraftCaptionPlace`); a
17
+ fitted size gets a caption style of its own. Before, a long chunk took three lines at the box's size in the draft
18
+ and two smaller ones in the render.
19
+ - The draft-versus-render regression test runs a second scenario: a heading font with a raised win ascent and
20
+ captions limited to two lines, tops and feet within 1 % of the frame.
21
+
22
+ ## 0.44.0
23
+
24
+ - **The draft runs every animation at the render's pace:** at the same second a counter showed 2734 in the draft and
25
+ 2797 in the render. The kit's curves were not GSAP's: GSAP's `powerN` is of degree N + 1, so `power2.out` is
26
+ `1 - (1 - t)^3`, not `1 - (1 - t)^2`; `OVERLAY_EASES` now compute `power2.out`, `power3.out`, `power2.in` and
27
+ `expo.out` exactly as GSAP 3 does, which also moves the draft's dropped letters, pops and list growth onto the
28
+ render's curve. A counter in the draft shows the render's value in every frame (`getCounterValueAt`,
29
+ `getFrameSteps`) instead of a step every tenth of a second; typed letters are one render stagger apart
30
+ (`getTypingStep`, `getTypingTimes(start, text, speed, firstIndex)`), so a second line no longer drifts; a wipe's
31
+ card, text and accent panel move along the render's ease, one `\t` per frame (`getEasedClipTags`), not in a straight
32
+ line. A regression test seeks the render's composition in Chromium and reads the draft's ASS at the same seconds:
33
+ the counter's value, the typed letters and the wipe's opening agree within one frame.
34
+ - `OVERLAY_TYPING_DELAY`, `getTypingStep`, `getTypingTimes` and `getFrameSteps` are exported.
35
+
7
36
  ## 0.43.0
8
37
 
9
38
  - **The draft draws every overlay card in the render's size and shape:** with the draft's fonts, a keyword's and a
package/README.md CHANGED
@@ -1351,7 +1351,9 @@ What the draft matches and what it leaves out:
1351
1351
  and named by the family the file itself declares (libass matches that, not the CSS family). A body font shipped only
1352
1352
  as WOFF or WOFF2, or no `brand`, draws in DejaVu Sans Bold subset to Latin with every Polish letter, shipped in
1353
1353
  [`fonts/`](fonts/README.md) (`FOOTAGE_DRAFT_FONT`), and the log says so. Without `brand` a highlight film uses
1354
- `FOOTAGE_DRAFT_CAPTION_COLORS`. `captionMaxLines` is not applied: the draft wraps at the caption box.
1354
+ `FOOTAGE_DRAFT_CAPTION_COLORS`. With `captionMaxLines` each chunk's font shrinks as the render's does, in 1 px
1355
+ steps down to `CAPTION_MIN_FONT_SCALE` of the box's size, until it takes that many lines (`fitDraftCaptionPlace`,
1356
+ 0.45.0).
1355
1357
  - **Text at the render's size** (`loadFootageDraftFonts`): every font is drawn as large as the render draws it.
1356
1358
  libass sizes a font by `usWinAscent + usWinDescent`, a browser by its em, so each size the draft writes (`Fontsize`,
1357
1359
  `\fs`) is the render's CSS px times the font's own `(usWinAscent + usWinDescent) / unitsPerEm` (`DraftFont.assScale`;
@@ -1365,6 +1367,17 @@ What the draft matches and what it leaves out:
1365
1367
  accent edge, a lower third's dot, a counter's card following its number) and sizes highlight marks to the text
1366
1368
  (`getKeywordMarkBlock`, a hook title's marks to each line and its font's `contentArea`). An app reports the same
1367
1369
  cards with `getDrawnOverlayCard(overlay, createOverlayTextMeasure(fonts))`.
1370
+ - **Animations at the render's pace** (0.44.0): every animated value the draft draws is the render's own at that second.
1371
+ The curves (`OVERLAY_EASES`) are GSAP's (`power2.out` is cubic, `power3.out` quartic, as GSAP computes them); a
1372
+ counter shows the value the render's tween shows in every frame (`getCounterValueAt`, one step per frame, half a
1373
+ frame either side, `getFrameSteps`); typed letters come one render stagger apart (`getTypingStep`), a later line
1374
+ going on from the letters before it (`getTypingTimes`' `firstIndex`); a wipe's clips move along the render's ease
1375
+ in one `\t` per frame (`getEasedClipTags`). At any second the draft and the render differ by at most one frame.
1376
+ - **Lines on the render's baseline** (0.45.0): libass sets a line's baseline `usWinAscent` below its top, a browser half
1377
+ the leading plus the content area's ascent below the line box's top. With `fonts`, every overlay line placed by its
1378
+ top or its middle moves by the difference (`getDraftLineShift`, `getDraftMiddleShift`, from
1379
+ `DraftFont.drawnAscentEm` and `drawnDescentEm`), so a display serif whose win ascent stands far above its typo
1380
+ ascent no longer sits low in its card.
1368
1381
  - **Music without spending** (`cacheDir`, `providers`, as `renderFootage` takes them): a `file` source plays as is;
1369
1382
  a `prompt` or `video` source plays only when its paid cache entry exists (`findFootageMusic`, the render's lookup).
1370
1383
  It is ducked under the speech, looped and faded to the cut's length exactly as in the render. No provider is ever
@@ -1,6 +1,7 @@
1
1
  import { type BrandStyle, type CornerRadius } from "./brand-style.js";
2
2
  import { type DraftFont } from "./draft-text-width.js";
3
3
  import { type OverlayColors } from "./overlay-html.js";
4
+ import { type OverlayEase } from "./overlay-motion.js";
4
5
  import { type OverlayFontRole, type OverlayPoint, type OverlayTextMeasure, type ResolvedOverlay } from "./overlays.js";
5
6
  /** The two styles the overlays use: `OverlayShape` (drawings: cards, marks, pins) and `OverlayPlain` (text over them). */
6
7
  export declare function getDraftOverlayStyles(family: string, colors: OverlayColors): string[];
@@ -43,6 +44,13 @@ interface DraftContext {
43
44
  ascentEm: number;
44
45
  descentEm: number;
45
46
  };
47
+ /**
48
+ * 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
49
+ * `lineHeightEm` (`getDraftLineShift`), in px; 0 without the draft's fonts (as before).
50
+ */
51
+ lineShift: (role: DraftFontRole, cssPx: number, lineHeightEm: number) => number;
52
+ /** The same for a line placed by its middle (`getDraftMiddleShift`); 0 without the draft's fonts. */
53
+ middleShift: (role: DraftFontRole, cssPx: number) => number;
46
54
  }
47
55
  /**
48
56
  * A card's corner in px: its own token, else the brand style's (a search bar stays a pill unless it names its own),
@@ -54,6 +62,21 @@ export declare function getDraftCardRadius(overlay: {
54
62
  }, box: {
55
63
  height: number;
56
64
  }, context: Pick<DraftContext, "style" | "scale">, own: number): number;
65
+ type ClipBox = {
66
+ x0: number;
67
+ y0: number;
68
+ x1: number;
69
+ y1: number;
70
+ };
71
+ /**
72
+ * A clip moving from `from` to `to` between `fromMs` and `toMs` of its event along the render's `ease`: one `\\t` per
73
+ * render frame (libass interpolates each straight), so the draft's clip stands where the render's does in every frame.
74
+ */
75
+ export declare function getEasedClipTags(from: ClipBox, to: ClipBox, input: {
76
+ fromMs: number;
77
+ toMs: number;
78
+ ease: OverlayEase;
79
+ }): string;
57
80
  /**
58
81
  * A dropped text as one line of ASS: each letter transparent until its second (`times`, from `getDropLetterTimes`),
59
82
  * then fading in over half a fall. libass moves whole events only, so the draft shows the letters arriving on their
@@ -1 +1 @@
1
- {"version":3,"file":"draft-overlays.d.ts","sourceRoot":"","sources":["../../src/footage/draft-overlays.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGzF,OAAO,EAAwF,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAE7I,OAAO,EAA0E,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAmB/H,OAAO,EAsCL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EAErB,MAAM,eAAe,CAAC;AAgCvB,0H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GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAAG,MAAM,CAU/H;AAqKD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAS9F;AAusBD;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,SAAS,eAAe,EAAE,EACpC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACxC,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC,aAAa,EAAE,SAAS,CAAC,CAAA;CAAO,GACrJ,MAAM,EAAE,CAwBV"}
@@ -1,17 +1,18 @@
1
+ import { FOOTAGE_FPS } from "./normalize.js";
1
2
  import { getCornerRadiusPx } 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 } from "./draft-text-width.js";
5
+ import { DEFAULT_CONTENT_AREA, getDraftLineShift, getDraftMiddleShift, getSpacingWidth, toDraftAssSize, toDraftSpacing, wrapDraftLine } from "./draft-text-width.js";
5
6
  import { HAND_FONT, getHandFontAssSize } from "./hand-font.js";
6
- import { getCounterSeconds, getOverlayColors, getPlaceCardTimes, getTypingTimes } from "./overlay-html.js";
7
- import { DROP_LETTER_SECONDS, NOTE_GROW_FROM_SCALE, NOTE_GROW_SECONDS, NOTE_TICK_SECONDS, OVERLAY_EASES, getDropLetterTimes, PIN_DROP_SECONDS, PIN_DROP_SHARE, UNDERLINE_EM, UNDERLINE_SECONDS, getEntranceMotion, getExitMotion, getWipeHalves, } from "./overlay-motion.js";
7
+ import { getCounterValueAt, getOverlayColors, getPlaceCardTimes, getTypingStep, getTypingTimes } from "./overlay-html.js";
8
+ import { DROP_LETTER_SECONDS, NOTE_GROW_FROM_SCALE, NOTE_GROW_SECONDS, NOTE_TICK_SECONDS, OVERLAY_EASES, getDropLetterTimes, getFrameSteps, PIN_DROP_SECONDS, PIN_DROP_SHARE, UNDERLINE_EM, UNDERLINE_SECONDS, getEntranceMotion, getExitMotion, getWipeHalves, } from "./overlay-motion.js";
8
9
  import { NOTE_LINE_HEIGHT, OVERLAY_FONT_ROLES, OVERLAY_LINE_HEIGHT, OVERLAY_LIST_LINE_HEIGHT, OVERLAY_LETTER_SPACING_EM, OVERLAY_TITLE_LINE_HEIGHT, SEARCH_BAR_ICON_EM, SEARCH_BAR_PADDING_EM, estimateTextWidth, formatOverlayNumber, LIST_CHIP_COVERED_OPACITY, getChipCoveredTimes, getChipParts, getChipTickPoints, COUNTER_UNIT_GAP_EM, getCounterCard, getDrawnOverlayCard, getKeywordMarkBlock, getSideTextLayout, KEYWORD_EDGE_EM, MARK_PADDING_EM, MARK_RADIUS_EM, getListCardsByItem, getListItemTimes, getListStops, getNoteCentre, getNoteColors, getNotePaperPoints, getNoteTextBox, getNoteTickPoints, getNoteWordsByLine, getOverlayPadding, getPlaceCardPinRow, getPlaceCardPinSize, getSideTextLines, getTitleContentBox, } from "./overlays.js";
9
10
  /**
10
11
  * The draft's overlays as ASS (issue #1200): the same places and times as the render, simplified. Text overlays are
11
12
  * drawn rounded cards of the brand's background, fitted to their text, with the text in its foreground; an
12
13
  * arrow is a straight shaft and head in the accent; a highlight the accent's outline round its rectangle; a pin and a
13
14
  * magnifier are drawings in the accent. A typed text shows letter by letter (the rest transparent, so its card keeps
14
- * its size), a counter steps up to its value every tenth of a second, a slide moves up into place. A `punch_in` is drawn
15
+ * its size), a counter shows its value in every frame, a slide moves up into place. A `punch_in` is drawn
15
16
  * by the picture's zoom (`buildPictureFilters`), not here. They sit on layers 3 and 4, over the captions' 0 to 2.
16
17
  */
17
18
  /** An arrow's or a highlight's stroke and the arrow head's length, in px of a 1080 px wide frame (as the render). */
@@ -25,8 +26,6 @@ const FADE = `\\fad(${FADE_IN_MS},${FADE_OUT_MS})`;
25
26
  /** How far a slide starts below its place, in px of a 1080 px wide frame, and how long it takes. */
26
27
  const SLIDE_PX = 28;
27
28
  const SLIDE_MS = 300;
28
- /** A counter's step in the draft, in seconds. */
29
- const COUNT_STEP = 0.1;
30
29
  /** A transparent primary colour: the typed text not shown yet. */
31
30
  const HIDDEN = "{\\1a&HFF&}";
32
31
  const r0 = (value) => Math.round(value);
@@ -139,6 +138,21 @@ function getWipeClip(motion) {
139
138
  return { x0: r0(card.left - room / 4), y0: r0(card.top - room), x1: r0(card.left + card.width + room / 4), y1: r0(card.top + card.height + room) };
140
139
  }
141
140
  const toClip = (box) => `\\clip(${box.x0},${box.y0},${box.x1},${box.y1})`;
141
+ /**
142
+ * A clip moving from `from` to `to` between `fromMs` and `toMs` of its event along the render's `ease`: one `\\t` per
143
+ * render frame (libass interpolates each straight), so the draft's clip stands where the render's does in every frame.
144
+ */
145
+ export function getEasedClipTags(from, to, input) {
146
+ const frames = Math.max(1, Math.round(((input.toMs - input.fromMs) / 1000) * FOOTAGE_FPS));
147
+ const at = (share) => ({
148
+ x0: r0(from.x0 + (to.x0 - from.x0) * share),
149
+ y0: r0(from.y0 + (to.y0 - from.y0) * share),
150
+ x1: r0(from.x1 + (to.x1 - from.x1) * share),
151
+ y1: r0(from.y1 + (to.y1 - from.y1) * share),
152
+ });
153
+ const ms = (frame) => Math.round(input.fromMs + ((input.toMs - input.fromMs) * frame) / frames);
154
+ 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("");
155
+ }
142
156
  const toMs = (seconds) => Math.max(0, Math.round(seconds * 1000));
143
157
  /**
144
158
  * The position and motion tags of one event of a run: the first takes the entrance (a fade, a slide or a rise moving up
@@ -171,8 +185,9 @@ function getMotionTags(motion, input) {
171
185
  if (input.isFirst && entrance.kind === "wipe") {
172
186
  const halves = getWipeHalves(entrance.seconds);
173
187
  const [grow, reveal] = [toMs(halves.grow), toMs(halves.reveal)];
174
- const closed = toClip({ ...clip, x1: clip.x0 });
175
- tags.push(input.part === "card" ? `${closed}\\t(0,${grow},${toClip(clip)})` : `${closed}\\t(${grow},${grow + reveal},${toClip(clip)})`);
188
+ const closed = { ...clip, x1: clip.x0 };
189
+ const half = input.part === "card" ? { fromMs: 0, toMs: grow } : { fromMs: grow, toMs: grow + reveal };
190
+ tags.push(`${toClip(closed)}${getEasedClipTags(closed, clip, { ...half, ease: entrance.ease })}`);
176
191
  }
177
192
  let fadeOut = 0;
178
193
  if (input.isLast && exit.kind !== "none") {
@@ -180,7 +195,7 @@ function getMotionTags(motion, input) {
180
195
  const exitMs = toMs(exit.seconds);
181
196
  if (!(input.isFirst && entrance.kind === "wipe"))
182
197
  tags.push(toClip(clip));
183
- tags.push(`\\t(${Math.max(0, ms - exitMs)},${ms},${toClip({ ...clip, x0: clip.x1 })})`);
198
+ tags.push(getEasedClipTags(clip, { ...clip, x0: clip.x1 }, { fromMs: Math.max(0, ms - exitMs), toMs: ms, ease: exit.ease }));
184
199
  }
185
200
  else {
186
201
  fadeOut = motion.isSnappy ? r0(FADE_OUT_MS * 0.7) : FADE_OUT_MS;
@@ -283,7 +298,9 @@ function getWipePanelEvent(overlay, drawing, accent, motion) {
283
298
  const halves = getWipeHalves(motion.entrance.seconds);
284
299
  const [grow, reveal] = [toMs(halves.grow), toMs(halves.reveal)];
285
300
  const clip = getWipeClip(motion);
286
- const tags = `${toClip({ ...clip, x1: clip.x0 })}\\t(0,${grow},${toClip(clip)})\\t(${grow},${grow + reveal},${toClip({ ...clip, x0: clip.x1 })})`;
301
+ const ease = motion.entrance.ease;
302
+ const closed = { ...clip, x1: clip.x0 };
303
+ const tags = `${toClip(closed)}${getEasedClipTags(closed, clip, { fromMs: 0, toMs: grow, ease })}${getEasedClipTags(clip, { ...clip, x0: clip.x1 }, { fromMs: grow, toMs: grow + reveal, ease })}`;
287
304
  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}`];
288
305
  }
289
306
  /** The same motion with no entrance of its own: a part whose letters or words come in by themselves. */
@@ -462,7 +479,7 @@ function getLaidOutSideTextEvents(overlay, context, measure) {
462
479
  const isTyped = overlay.entrance !== null && overlay.entrance !== "drop" && overlay.typing !== null;
463
480
  let typedBefore = 0;
464
481
  const lines = layout.lines.flatMap((line, index) => {
465
- const pos = { x: layout.textX, y: layout.textTop + index * lineHeight };
482
+ const pos = { x: layout.textX, y: layout.textTop + index * lineHeight + context.lineShift(role, fontSize, OVERLAY_LINE_HEIGHT) };
466
483
  const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
467
484
  const count = [...line].length;
468
485
  const steps = overlay.entrance === "drop"
@@ -530,7 +547,8 @@ function getListEvents(overlay, context) {
530
547
  const name = overlay.entrance === null || overlay.entrance === "type" ? "fade" : overlay.entrance;
531
548
  const textTags = getTextTags(overlay, colors, context, OVERLAY_FONT_ROLES.list);
532
549
  const lines = getSideTextLines(overlay);
533
- const write = (pos, align, steps, motion, clip = "") => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags: `\\an${align}\\fs${context.toAssSize(OVERLAY_FONT_ROLES.list, fontSize)}${context.spacing(OVERLAY_LETTER_SPACING_EM.card, fontSize)}${textTags}${clip}`, steps, motion });
550
+ const shift = context.lineShift(OVERLAY_FONT_ROLES.list, fontSize, OVERLAY_LINE_HEIGHT);
551
+ const write = (at, align, steps, motion, clip = "") => 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 });
534
552
  if (overlay.chips !== undefined) {
535
553
  const covered = getChipCoveredTimes(overlay);
536
554
  return overlay.chips.flatMap((_chip, index) => {
@@ -684,7 +702,9 @@ function getCardEvents(overlay, context) {
684
702
  const tagsFor = (role) => getTextTags(overlay, colors, context, role);
685
703
  // The render spaces a title's heading lines tighter than the rest of a card's text, and a search query not at all.
686
704
  const spacingFor = (role) => 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;
687
- const text = (pos, align, size, role, steps, own = motion) => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags: `\\an${align}\\fs${context.toAssSize(role, r0(size))}${context.spacing(spacingFor(role), r0(size))}${tagsFor(role)}`, steps, motion: own });
705
+ // 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`).
706
+ const lineBoxFor = (role) => (role === "heading" && overlay.kind === "place_card" ? OVERLAY_TITLE_LINE_HEIGHT : OVERLAY_LINE_HEIGHT);
707
+ const text = (at, align, size, role, steps, own = motion) => 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 });
688
708
  const plain = { ...motion, name: "none", entrance: { kind: "none" } };
689
709
  if (overlay.kind === "hook_title" || overlay.kind === "place_card") {
690
710
  // The text block sits in the card's middle; centred lines on its axis, left ones from its left edge (RV-131).
@@ -714,7 +734,7 @@ function getCardEvents(overlay, context) {
714
734
  if (overlay.kind === "hook_title" && (isMarked || overlay.entrance === "drop")) {
715
735
  const letters = getDropLetterTimes(span.start, overlay.lines.join(""));
716
736
  overlay.lines.forEach((line) => {
717
- const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
737
+ const lineStart = overlay.typing === null ? span.start : span.start + typedBefore * getTypingStep(overlay.typing);
718
738
  if (isMarked) {
719
739
  const align = isLeft ? "left" : "center";
720
740
  const { layout } = context;
@@ -738,7 +758,7 @@ function getCardEvents(overlay, context) {
738
758
  overlay.lines.forEach((line) => {
739
759
  // The lines type one after the other, as the render's characters do; a left line holds its place transparent
740
760
  // from the start, a centred one shows its typed part only (`getTypedSteps`).
741
- const lineStart = overlay.typing === null ? times.title : span.start + typedBefore / overlay.typing;
761
+ const lineStart = overlay.typing === null ? times.title : span.start + typedBefore * getTypingStep(overlay.typing);
742
762
  const steps = getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
743
763
  // A centred typed line has no hidden first step to carry the entrance: its letters appear as typed, as the render's.
744
764
  const isTypedCentre = !isLeft && overlay.typing !== null;
@@ -768,18 +788,9 @@ function getCardEvents(overlay, context) {
768
788
  const gap = context.layout === undefined ? null : toDraftSpacing(overlay.fontSize * COUNTER_UNIT_GAP_EM - context.layout("heading", " ", overlay.unitFontSize, 0), 1);
769
789
  const space = gap === null ? " " : `{\\fsp${String(gap)}}\\h{\\fsp${String(toDraftSpacing(OVERLAY_LETTER_SPACING_EM.card, fontSize))}}`;
770
790
  const unit = overlay.unit === null ? "" : `{\\fs${context.toAssSize("heading", overlay.unitFontSize)}}${space}${toAssText(overlay.unit)}`;
771
- const count = getCounterSeconds(overlay);
772
- const steps = [];
773
- const ticks = Math.max(1, Math.round(count.duration / COUNT_STEP));
774
791
  const show = (value) => `${formatOverlayNumber(value, overlay.decimals, context.locale)}${unit}`;
775
- steps.push({ from: span.start, to: count.start, text: show(overlay.from) });
776
- for (let tick = 1; tick <= ticks; tick++) {
777
- const progress = tick / ticks;
778
- // power2.out, as the render's tween eases: the count slows down to its value.
779
- const eased = OVERLAY_EASES["power2.out"](progress);
780
- const value = overlay.from + (overlay.value - overlay.from) * eased;
781
- steps.push({ from: count.start + (tick - 1) * COUNT_STEP, to: tick === ticks ? span.end : count.start + tick * COUNT_STEP, text: show(value) });
782
- }
792
+ // One step per render frame, each the value the render's tween shows in that frame.
793
+ const steps = getFrameSteps({ start: span.start, end: span.end, fps: FOOTAGE_FPS, valueAt: (seconds) => show(getCounterValueAt(overlay, seconds)) });
783
794
  const shown = steps.filter((step) => step.to > step.from);
784
795
  const { layout } = context;
785
796
  if (layout === undefined)
@@ -897,13 +908,14 @@ function getNoteEvents(overlay, context) {
897
908
  const assSize = isStrip ? context.toAssSize("heading", overlay.fontSize) : getHandFontAssSize(overlay.fontSize);
898
909
  const tags = `\\an7\\fs${assSize}${isStrip ? context.spacing(OVERLAY_LETTER_SPACING_EM.strip, overlay.fontSize) : ""}${font}\\1c${toTagColor(colors.ink)}${turn}`;
899
910
  getNoteWordsByLine(overlay).forEach((words, index) => {
900
- const pos = { x: textBox.left, y: textBox.top + index * lineHeight };
911
+ // A strip's heading font stands on the render's baseline; the hand font is sized to its own letters (`getHandFontAssSize`).
912
+ const pos = { x: textBox.left, y: textBox.top + index * lineHeight + (isStrip ? context.lineShift("heading", overlay.fontSize, NOTE_LINE_HEIGHT) : 0) };
901
913
  const line = overlay.lines[index];
902
914
  const span = { start: overlay.start, end: overlay.end };
903
915
  if (isStrip) {
904
916
  const before = overlay.lines.slice(0, index).join("").length;
905
917
  const typing = overlay.typing ?? 14;
906
- const steps = getTypedSteps(line, { start: overlay.start + before / typing, end: overlay.end }, typing).map((step, stepIndex) => (stepIndex === 0 ? { ...step, from: overlay.start } : step));
918
+ const steps = getTypedSteps(line, { start: overlay.start + before * getTypingStep(typing), end: overlay.end }, typing).map((step, stepIndex) => (stepIndex === 0 ? { ...step, from: overlay.start } : step));
907
919
  events.push(...getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, motion: textMotion }));
908
920
  return;
909
921
  }
@@ -962,6 +974,8 @@ export function buildDraftOverlayEvents(overlays, colors, frame, options = {}) {
962
974
  measure: (role, text, cssPx, spacingEm) => (drawn === undefined ? estimateTextWidth(text, cssPx) : drawn[role].measure(text, cssPx) + getSpacingWidth(text, spacingEm, cssPx)),
963
975
  spacing: (spacingEm, cssPx) => (drawn === undefined || spacingEm === 0 ? "" : `\\fsp${String(toDraftSpacing(spacingEm, cssPx))}`),
964
976
  contentArea: (role) => drawn?.[role].contentArea ?? DEFAULT_CONTENT_AREA,
977
+ lineShift: (role, cssPx, lineHeightEm) => (drawn === undefined ? 0 : getDraftLineShift(drawn[role], cssPx, lineHeightEm)),
978
+ middleShift: (role, cssPx) => (drawn === undefined ? 0 : getDraftMiddleShift(drawn[role], cssPx)),
965
979
  ...(options.style === undefined ? {} : { style: options.style }),
966
980
  ...(drawn === undefined ? {} : { layout: (role, text, cssPx, spacingEm) => drawn[role].measure(text, cssPx) + getSpacingWidth(text, spacingEm, cssPx) }),
967
981
  };