@softure-ai/marketing-kit 0.42.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +11 -0
  3. package/dist/footage/draft-overlays.d.ts +27 -1
  4. package/dist/footage/draft-overlays.d.ts.map +1 -1
  5. package/dist/footage/draft-overlays.js +169 -37
  6. package/dist/footage/draft-overlays.js.map +1 -1
  7. package/dist/footage/draft-text-width.d.ts +13 -0
  8. package/dist/footage/draft-text-width.d.ts.map +1 -1
  9. package/dist/footage/draft-text-width.js +12 -1
  10. package/dist/footage/draft-text-width.js.map +1 -1
  11. package/dist/footage/draft.d.ts +7 -1
  12. package/dist/footage/draft.d.ts.map +1 -1
  13. package/dist/footage/draft.js +9 -1
  14. package/dist/footage/draft.js.map +1 -1
  15. package/dist/footage/overlay-html.d.ts +13 -4
  16. package/dist/footage/overlay-html.d.ts.map +1 -1
  17. package/dist/footage/overlay-html.js +15 -9
  18. package/dist/footage/overlay-html.js.map +1 -1
  19. package/dist/footage/overlay-motion.d.ts +31 -4
  20. package/dist/footage/overlay-motion.d.ts.map +1 -1
  21. package/dist/footage/overlay-motion.js +53 -5
  22. package/dist/footage/overlay-motion.js.map +1 -1
  23. package/dist/footage/overlays.d.ts +64 -2
  24. package/dist/footage/overlays.d.ts.map +1 -1
  25. package/dist/footage/overlays.js +112 -4
  26. package/dist/footage/overlays.js.map +1 -1
  27. package/dist/index.d.ts +4 -4
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +4 -4
  30. package/dist/index.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/footage/draft-overlays.ts +202 -36
  33. package/src/footage/draft-text-width.ts +22 -1
  34. package/src/footage/draft.ts +11 -2
  35. package/src/footage/overlay-html.ts +20 -8
  36. package/src/footage/overlay-motion.ts +61 -5
  37. package/src/footage/overlays.ts +132 -4
  38. package/src/index.ts +17 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,38 @@ 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.44.0
8
+
9
+ - **The draft runs every animation at the render's pace:** at the same second a counter showed 2734 in the draft and
10
+ 2797 in the render. The kit's curves were not GSAP's: GSAP's `powerN` is of degree N + 1, so `power2.out` is
11
+ `1 - (1 - t)^3`, not `1 - (1 - t)^2`; `OVERLAY_EASES` now compute `power2.out`, `power3.out`, `power2.in` and
12
+ `expo.out` exactly as GSAP 3 does, which also moves the draft's dropped letters, pops and list growth onto the
13
+ render's curve. A counter in the draft shows the render's value in every frame (`getCounterValueAt`,
14
+ `getFrameSteps`) instead of a step every tenth of a second; typed letters are one render stagger apart
15
+ (`getTypingStep`, `getTypingTimes(start, text, speed, firstIndex)`), so a second line no longer drifts; a wipe's
16
+ card, text and accent panel move along the render's ease, one `\t` per frame (`getEasedClipTags`), not in a straight
17
+ line. A regression test seeks the render's composition in Chromium and reads the draft's ASS at the same seconds:
18
+ the counter's value, the typed letters and the wipe's opening agree within one frame.
19
+ - `OVERLAY_TYPING_DELAY`, `getTypingStep`, `getTypingTimes` and `getFrameSteps` are exported.
20
+
21
+ ## 0.43.0
22
+
23
+ - **The draft draws every overlay card in the render's size and shape:** with the draft's fonts, a keyword's and a
24
+ lower third's card is laid out as the render's CSS lays it out (`getSideTextLayout`): its text broken inside the
25
+ box, the card as wide as its widest line (the whole box once it wraps) and as tall as its lines plus padding, a
26
+ keyword's `.12em` accent edge under it, a lower third's accent dot before its text; each line is its own event one
27
+ CSS line (1.15 em) below the last, so libass's own line pitch no longer stretches them. A counter's card fits its
28
+ number, the `.3em` gap and its unit (`getCounterCard`) and follows the number while it counts. A highlighted hook
29
+ title's marks hug each line's text and its font's content area (`DraftFont.contentArea`, from `hhea`, or the typo
30
+ metrics with `USE_TYPO_METRICS`); a highlighted keyword's mark is one block round all its lines
31
+ (`getKeywordMarkBlock`), as the render's flex item is. Without `fonts` the draft draws the estimated cards as before.
32
+ - **The card an app reports is the render's:** `getDrawnOverlayCard(overlay, measure)` with
33
+ `createOverlayTextMeasure(loadFootageDraftFonts(brand.fonts))` answers the laid-out card of a keyword, a lower third
34
+ and a counter (at its final value), and where a highlight's marks show. Without a measure it answers as before.
35
+ - A regression test draws a fixture cut (highlighted hook title and keyword with a wipe, wrapping keyword card, lower
36
+ third, place cards `size: s` and `subtitle_size: m`, counter) in Chromium and through libass: every card and mark
37
+ within 1 % of the frame, the text on as many lines, and the reported card within 1 % of the render's.
38
+
7
39
  ## 0.42.0
8
40
 
9
41
  - **The draft draws every text at the render's size:** libass sizes a font by `usWinAscent + usWinDescent`, a
package/README.md CHANGED
@@ -1360,6 +1360,17 @@ What the draft matches and what it leaves out:
1360
1360
  third's that is wider than its box (the render's card wraps it). An app that draws its own scenes with
1361
1361
  `buildFootageDraftCaptions` (a preset preview) passes the same `fonts` set; without it, the sizes go to libass
1362
1362
  unconverted, as before.
1363
+ - **Cards in the render's shape** (0.43.0): with `fonts`, the draft lays a keyword's, a lower third's and a counter's
1364
+ card out as the render does (`getSideTextLayout`, `getCounterCard`: wrapped lines one CSS line apart, a keyword's
1365
+ accent edge, a lower third's dot, a counter's card following its number) and sizes highlight marks to the text
1366
+ (`getKeywordMarkBlock`, a hook title's marks to each line and its font's `contentArea`). An app reports the same
1367
+ cards with `getDrawnOverlayCard(overlay, createOverlayTextMeasure(fonts))`.
1368
+ - **Animations at the render's pace** (0.44.0): every animated value the draft draws is the render's own at that second.
1369
+ The curves (`OVERLAY_EASES`) are GSAP's (`power2.out` is cubic, `power3.out` quartic, as GSAP computes them); a
1370
+ counter shows the value the render's tween shows in every frame (`getCounterValueAt`, one step per frame, half a
1371
+ frame either side, `getFrameSteps`); typed letters come one render stagger apart (`getTypingStep`), a later line
1372
+ going on from the letters before it (`getTypingTimes`' `firstIndex`); a wipe's clips move along the render's ease
1373
+ in one `\t` per frame (`getEasedClipTags`). At any second the draft and the render differ by at most one frame.
1363
1374
  - **Music without spending** (`cacheDir`, `providers`, as `renderFootage` takes them): a `file` source plays as is;
1364
1375
  a `prompt` or `video` source plays only when its paid cache entry exists (`findFootageMusic`, the render's lookup).
1365
1376
  It is ducked under the speech, looped and faded to the cut's length exactly as in the render. No provider is ever
@@ -1,7 +1,8 @@
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 OverlayFontRole, type OverlayPoint, type ResolvedOverlay } from "./overlays.js";
4
+ import { type OverlayEase } from "./overlay-motion.js";
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[];
7
8
  /** A straight arrow from `from` to `to` as an ASS drawing: the shaft's quad and the head's triangle. */
@@ -33,6 +34,16 @@ interface DraftContext {
33
34
  spacing: (spacingEm: number, cssPx: number) => string;
34
35
  /** The brand's style: the cards' radius, shadow and border; absent: each kind's own corner, no shadow, no border. */
35
36
  style?: BrandStyle;
37
+ /**
38
+ * With the draft's fonts: the render's measure, so side texts, counters and highlight marks are laid out as the
39
+ * render lays them out (`getSideTextLayout`, `getCounterCard`); absent: the estimated cards of before.
40
+ */
41
+ layout?: OverlayTextMeasure;
42
+ /** The content area (ascent, descent in ems) of the font of `role`, as a browser sizes an inline box. */
43
+ contentArea: (role: DraftFontRole) => {
44
+ ascentEm: number;
45
+ descentEm: number;
46
+ };
36
47
  }
37
48
  /**
38
49
  * 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),
@@ -44,6 +55,21 @@ export declare function getDraftCardRadius(overlay: {
44
55
  }, box: {
45
56
  height: number;
46
57
  }, context: Pick<DraftContext, "style" | "scale">, own: number): number;
58
+ type ClipBox = {
59
+ x0: number;
60
+ y0: number;
61
+ x1: number;
62
+ y1: number;
63
+ };
64
+ /**
65
+ * A clip moving from `from` to `to` between `fromMs` and `toMs` of its event along the render's `ease`: one `\\t` per
66
+ * render frame (libass interpolates each straight), so the draft's clip stands where the render's does in every frame.
67
+ */
68
+ export declare function getEasedClipTags(from: ClipBox, to: ClipBox, input: {
69
+ fromMs: number;
70
+ toMs: number;
71
+ ease: OverlayEase;
72
+ }): string;
47
73
  /**
48
74
  * A dropped text as one line of ASS: each letter transparent until its second (`times`, from `getDropLetterTimes`),
49
75
  * 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,EAAkE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvH,OAAO,EAA0E,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAmB/H,OAAO,EA+BL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAgCvB,0HAA0H;AAC1H,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,MAAM,EAAE,CAOrF;AAcD,wGAAwG;AACxG,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAY3F;AAED,oHAAoH;AACpH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EA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,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,CAsBV"}
@@ -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 { getSpacingWidth, toDraftAssSize, toDraftSpacing, wrapDraftLine } from "./draft-text-width.js";
5
+ import { DEFAULT_CONTENT_AREA, 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";
8
- 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, getDrawnOverlayCard, getListCardsByItem, getListItemTimes, getListStops, getNoteCentre, getNoteColors, getNotePaperPoints, getNoteTextBox, getNoteTickPoints, getNoteWordsByLine, getOverlayPadding, getPlaceCardPinRow, getPlaceCardPinSize, getSideTextLines, getTitleContentBox, } from "./overlays.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";
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. */
@@ -306,22 +323,21 @@ export function getDropText(text, times, eventStart) {
306
323
  })
307
324
  .join("");
308
325
  }
309
- /** A highlight mark's padding round its text and its corner, in font sizes (as the render's `.ov-mark`). */
310
- const MARK_PADDING_EM = { x: 0.22, y: 0.04 };
311
- const MARK_RADIUS_EM = 0.14;
312
326
  /**
313
327
  * A highlight backdrop's marks under one line of text (`style.backdrop` highlight): a tight rounded box in the card
314
328
  * colour, its width the text shown so far (each typed letter widens it, as the render's box grows), anchored where
315
329
  * the text is (`x` its left, middle or right edge, `top` its top).
316
330
  */
317
331
  function getBackdropMarkEvents(input) {
318
- const { fontSize, span } = input;
332
+ const { fontSize, span, measured } = input;
319
333
  const pad = { x: fontSize * MARK_PADDING_EM.x, y: fontSize * MARK_PADDING_EM.y };
320
- const height = fontSize * OVERLAY_LINE_HEIGHT + 2 * pad.y;
334
+ const content = measured === undefined ? fontSize * OVERLAY_LINE_HEIGHT : fontSize * (measured.contentArea.ascentEm + measured.contentArea.descentEm);
335
+ const height = content + 2 * pad.y;
336
+ const top = measured === undefined ? input.top - pad.y : input.top + (fontSize * measured.lineHeight - content) / 2 - pad.y;
321
337
  const boxFor = (shown) => {
322
- const width = estimateTextWidth(shown, fontSize) + 2 * pad.x;
338
+ const width = (measured === undefined ? estimateTextWidth(shown, fontSize) : measured.measure(shown)) + 2 * pad.x;
323
339
  const left = input.align === "left" ? input.x - pad.x : input.align === "right" ? input.x + pad.x - width : input.x - width / 2;
324
- return { left, top: input.top - pad.y, width, height };
340
+ return { left, top, width, height };
325
341
  };
326
342
  const clean = toAssText(input.text);
327
343
  const steps = input.typing === null
@@ -360,6 +376,8 @@ function getUnderlineEvent(overlay, card, colour, motion) {
360
376
  function getSideTextEvents(overlay, context) {
361
377
  if (overlay.kind === "list")
362
378
  return getListEvents(overlay, context);
379
+ if (context.layout !== undefined)
380
+ return getLaidOutSideTextEvents(overlay, context, context.layout);
363
381
  const colors = getOverlayColors(overlay, context.brand);
364
382
  const { fontSize, side } = overlay;
365
383
  // A side text always has a card: only a punch_in has none.
@@ -391,6 +409,93 @@ function getSideTextEvents(overlay, context) {
391
409
  const steps = overlay.entrance === null ? [{ from: span.start, to: span.end, text: toAssText(wrapped) }] : getTypedSteps(wrapped, span, overlay.typing, isCentred);
392
410
  return [...shape, ...text({ x, y }, steps), ...(overlay.kind === "keyword" ? getUnderlineEvent(overlay, card, colors.accent, motion) : [])];
393
411
  }
412
+ /**
413
+ * A highlighted keyword's mark as the render draws it (`getKeywordMarkBlock`): one rounded block round its lines;
414
+ * while it types, the block of the letters typed so far, on the lines they take in the whole text.
415
+ */
416
+ function getBlockMarkEvents(input) {
417
+ const { overlay, layout } = input;
418
+ const { fontSize } = overlay;
419
+ const blockFor = (lines) => getKeywordMarkBlock(overlay, layout, lines, input.measure);
420
+ const span = { start: overlay.start, end: overlay.end };
421
+ const text = layout.lines.join(" ");
422
+ const steps = overlay.typing === null || overlay.entrance === null || overlay.entrance === "drop"
423
+ ? [{ from: span.start, to: span.end, lines: layout.lines }]
424
+ : getTypingTimes(span.start, text, overlay.typing).map((at, index, times) => {
425
+ // The typed letters stay on the lines they take in the whole text.
426
+ let left = index + 1;
427
+ const lines = layout.lines.map((line) => {
428
+ const shown = [...line].slice(0, Math.max(0, left)).join("").trimEnd();
429
+ left -= [...line].length + 1;
430
+ return shown;
431
+ });
432
+ return { from: Math.min(at, span.end), to: Math.min(times[index + 1] ?? span.end, span.end), lines: lines.filter((line) => line.length > 0) };
433
+ });
434
+ const visible = steps.filter((step) => step.to > step.from && step.lines.length > 0);
435
+ return visible.map((step, index) => getShapeEvent({ start: step.from, end: step.to }, getRoundedRectDrawing(blockFor(step.lines), fontSize * MARK_RADIUS_EM), input.colour, input.motion, 3, {
436
+ start: step.from,
437
+ end: step.to,
438
+ isFirst: index === 0,
439
+ isLast: index === visible.length - 1,
440
+ }));
441
+ }
442
+ /**
443
+ * A keyword or a lower third laid out as the render lays it out (`getSideTextLayout`): its card as wide and tall as
444
+ * its lines (a keyword with its accent edge, a lower third with its dot), each line its own event one CSS line apart,
445
+ * so libass's own line pitch does not stretch them; a highlighted keyword has one mark per line.
446
+ */
447
+ function getLaidOutSideTextEvents(overlay, context, measure) {
448
+ const colors = getOverlayColors(overlay, context.brand);
449
+ const { fontSize } = overlay;
450
+ const layout = getSideTextLayout(overlay, measure);
451
+ const { card } = layout;
452
+ const role = OVERLAY_FONT_ROLES[overlay.kind];
453
+ const isCentred = overlay.kind === "keyword" && overlay.isCentred === true;
454
+ const isMarked = overlay.kind === "keyword" && overlay.backdrop === "highlight";
455
+ const motion = getDraftMotion(overlay, overlay.entrance === null || overlay.entrance === "type" ? "fade" : overlay.entrance, card, context);
456
+ const span = { start: overlay.start, end: overlay.end };
457
+ const lineHeight = fontSize * OVERLAY_LINE_HEIGHT;
458
+ const tags = `\\an${isCentred ? 8 : 7}\\fs${context.toAssSize(role, fontSize)}${context.spacing(OVERLAY_LETTER_SPACING_EM.card, fontSize)}${getTextTags(overlay, colors, context, role)}`;
459
+ const edge = overlay.kind === "keyword" && !isMarked ? Math.round(fontSize * KEYWORD_EDGE_EM) : 0;
460
+ const shapes = [];
461
+ if (isMarked) {
462
+ // The render's highlighted keyword is one block (a flex item): one mark round all its lines, growing as it types.
463
+ shapes.push(...getBlockMarkEvents({ overlay, layout, measure, colour: colors.background, motion }));
464
+ }
465
+ else {
466
+ const fill = getCardShapeEvents(overlay, { ...card, height: card.height - edge }, fontSize, colors, motion, context);
467
+ // The keyword's accent edge: the whole card in the accent under its fill, which leaves the edge's height at its foot.
468
+ const radius = getDraftCardRadius(overlay, card, context, getOwnCardRadius(overlay, card, fontSize));
469
+ const edgeEvents = edge === 0 || (overlay.kind === "keyword" && overlay.underline === true) ? [] : [getShapeEvent(overlay, getRoundedRectDrawing(card, radius), colors.accent, motion)];
470
+ const under = context.style?.shadow === "soft" ? 1 : 0;
471
+ shapes.push(...fill.slice(0, under), ...edgeEvents, ...fill.slice(under));
472
+ }
473
+ if (layout.dot !== null) {
474
+ // The dot settles in with the card (the render scales it in a little later; the draft shows it with its card).
475
+ shapes.push(getShapeEvent(overlay, getCircleDrawing(layout.dot.centre, layout.dot.radius), colors.accent, motion, 4));
476
+ }
477
+ const text = layout.lines.join(" ");
478
+ const letters = overlay.entrance === "drop" ? getDropLetterTimes(span.start, text) : [];
479
+ const isTyped = overlay.entrance !== null && overlay.entrance !== "drop" && overlay.typing !== null;
480
+ let typedBefore = 0;
481
+ const lines = layout.lines.flatMap((line, index) => {
482
+ const pos = { x: layout.textX, y: layout.textTop + index * lineHeight };
483
+ const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
484
+ const count = [...line].length;
485
+ const steps = overlay.entrance === "drop"
486
+ ? [{ from: span.start, to: span.end, text: getDropText(line, letters.slice(typedBefore, typedBefore + count), span.start) }]
487
+ : isTyped
488
+ ? getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, isCentred)
489
+ : [{ from: span.start, to: span.end, text: toAssText(line) }];
490
+ typedBefore += count + 1;
491
+ // A left line holds its place transparent from the start, so its first event carries the entrance.
492
+ const held = isTyped && !isCentred ? steps.map((step, at) => (at === 0 ? { ...step, from: span.start } : step)) : steps;
493
+ const own = overlay.entrance === "drop" || (isTyped && isCentred) ? getPlainMotion(motion) : motion;
494
+ return getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps: held, motion: own });
495
+ });
496
+ const underline = overlay.kind === "keyword" ? getUnderlineEvent(overlay, { ...card, height: card.height - edge }, colors.accent, motion) : [];
497
+ return [...shapes, ...lines, ...underline];
498
+ }
394
499
  /** A list's card grows to its next point's size over these seconds, in this many steps along the render's ease. */
395
500
  const LIST_GROW_SECONDS = 0.35;
396
501
  const LIST_GROW_STEPS = 3;
@@ -588,7 +693,9 @@ function getCardEvents(overlay, context) {
588
693
  const motion = getDraftMotion(overlay, name, box, context);
589
694
  const span = { start: overlay.start, end: overlay.end };
590
695
  const isMarked = overlay.kind === "hook_title" && overlay.backdrop === "highlight";
591
- const events = isMarked ? [] : getCardShapeEvents(overlay, box, fontSize, colors, motion, context);
696
+ // A laid-out counter draws its card with each number it shows (below), as the render's card follows its text.
697
+ const isCounterLaidOut = overlay.kind === "counter" && context.layout !== undefined;
698
+ const events = isMarked || isCounterLaidOut ? [] : getCardShapeEvents(overlay, box, fontSize, colors, motion, context);
592
699
  const { x: padX, y: padY } = getOverlayPadding(overlay);
593
700
  const centerX = box.left + box.width / 2;
594
701
  const tagsFor = (role) => getTextTags(overlay, colors, context, role);
@@ -624,16 +731,22 @@ function getCardEvents(overlay, context) {
624
731
  if (overlay.kind === "hook_title" && (isMarked || overlay.entrance === "drop")) {
625
732
  const letters = getDropLetterTimes(span.start, overlay.lines.join(""));
626
733
  overlay.lines.forEach((line) => {
627
- const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
734
+ const lineStart = overlay.typing === null ? span.start : span.start + typedBefore * getTypingStep(overlay.typing);
628
735
  if (isMarked) {
629
736
  const align = isLeft ? "left" : "center";
630
- events.push(...getBackdropMarkEvents({ text: line, x: lineX, align, top: y, fontSize, colour: colors.background, motion, span, typing: overlay.typing, typeFrom: lineStart }));
737
+ const { layout } = context;
738
+ const measured = layout === undefined
739
+ ? {}
740
+ : { measured: { measure: (shown) => layout("heading", shown, fontSize, spacingFor("heading")), contentArea: context.contentArea("heading"), lineHeight } };
741
+ events.push(...getBackdropMarkEvents({ text: line, x: lineX, align, top: y, fontSize, colour: colors.background, motion, span, typing: overlay.typing, typeFrom: lineStart, ...measured }));
631
742
  }
632
743
  const steps = overlay.entrance === "drop"
633
744
  ? [{ from: span.start, to: span.end, text: getDropText(line, letters.slice(typedBefore, typedBefore + [...line].length), span.start) }]
634
745
  : getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
635
746
  const isQuiet = overlay.entrance === "drop" || (!isLeft && overlay.typing !== null);
636
- events.push(...text({ x: lineX, y }, lineAlign, fontSize, "heading", isLeft && overlay.entrance !== "drop" ? steps.map((step, index) => (index === 0 ? { ...step, from: span.start } : step)) : steps, isQuiet ? plain : motion));
747
+ // A left mark's padding pushes its text in, as an inline box's padding does in the render.
748
+ const textX = isMarked && isLeft && context.layout !== undefined ? lineX + fontSize * MARK_PADDING_EM.x : lineX;
749
+ events.push(...text({ x: textX, y }, lineAlign, fontSize, "heading", isLeft && overlay.entrance !== "drop" ? steps.map((step, index) => (index === 0 ? { ...step, from: span.start } : step)) : steps, isQuiet ? plain : motion));
637
750
  typedBefore += [...line].length;
638
751
  y += fontSize * lineHeight;
639
752
  });
@@ -642,7 +755,7 @@ function getCardEvents(overlay, context) {
642
755
  overlay.lines.forEach((line) => {
643
756
  // The lines type one after the other, as the render's characters do; a left line holds its place transparent
644
757
  // from the start, a centred one shows its typed part only (`getTypedSteps`).
645
- const lineStart = overlay.typing === null ? times.title : span.start + typedBefore / overlay.typing;
758
+ const lineStart = overlay.typing === null ? times.title : span.start + typedBefore * getTypingStep(overlay.typing);
646
759
  const steps = getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
647
760
  // A centred typed line has no hidden first step to carry the entrance: its letters appear as typed, as the render's.
648
761
  const isTypedCentre = !isLeft && overlay.typing !== null;
@@ -668,20 +781,37 @@ function getCardEvents(overlay, context) {
668
781
  return events;
669
782
  }
670
783
  if (overlay.kind === "counter") {
671
- const unit = overlay.unit === null ? "" : `{\\fs${context.toAssSize("heading", overlay.unitFontSize)}} ${toAssText(overlay.unit)}`;
672
- const count = getCounterSeconds(overlay);
673
- const steps = [];
674
- const ticks = Math.max(1, Math.round(count.duration / COUNT_STEP));
784
+ // Laid out, the unit stands the render's gap after the number: a hard space widened to it.
785
+ const gap = context.layout === undefined ? null : toDraftSpacing(overlay.fontSize * COUNTER_UNIT_GAP_EM - context.layout("heading", " ", overlay.unitFontSize, 0), 1);
786
+ const space = gap === null ? " " : `{\\fsp${String(gap)}}\\h{\\fsp${String(toDraftSpacing(OVERLAY_LETTER_SPACING_EM.card, fontSize))}}`;
787
+ const unit = overlay.unit === null ? "" : `{\\fs${context.toAssSize("heading", overlay.unitFontSize)}}${space}${toAssText(overlay.unit)}`;
675
788
  const show = (value) => `${formatOverlayNumber(value, overlay.decimals, context.locale)}${unit}`;
676
- steps.push({ from: span.start, to: count.start, text: show(overlay.from) });
677
- for (let tick = 1; tick <= ticks; tick++) {
678
- const progress = tick / ticks;
679
- // power2.out, as the render's tween eases: the count slows down to its value.
680
- const eased = OVERLAY_EASES["power2.out"](progress);
681
- const value = overlay.from + (overlay.value - overlay.from) * eased;
682
- steps.push({ from: count.start + (tick - 1) * COUNT_STEP, to: tick === ticks ? span.end : count.start + tick * COUNT_STEP, text: show(value) });
683
- }
684
- return [...events, ...text({ x: centerX, y: box.top + box.height / 2 }, 5, fontSize, "heading", steps.filter((step) => step.to > step.from))];
789
+ // One step per render frame, each the value the render's tween shows in that frame.
790
+ const steps = getFrameSteps({ start: span.start, end: span.end, fps: FOOTAGE_FPS, valueAt: (seconds) => show(getCounterValueAt(overlay, seconds)) });
791
+ const shown = steps.filter((step) => step.to > step.from);
792
+ const { layout } = context;
793
+ if (layout === undefined)
794
+ return [...events, ...text({ x: centerX, y: box.top + box.height / 2 }, 5, fontSize, "heading", shown)];
795
+ // The render's card follows its number: one card per width the count shows, the entrance on the first, the exit on the last.
796
+ const cardFor = (value) => getCounterCard(overlay, value, layout);
797
+ // The number alone: the unit's override tags start at the first brace.
798
+ const values = shown.map((step) => {
799
+ const brace = step.text.indexOf("{");
800
+ return brace === -1 ? step.text : step.text.slice(0, brace);
801
+ });
802
+ const runs = [];
803
+ shown.forEach((step, index) => {
804
+ const card = cardFor(values[index]);
805
+ const last = runs[runs.length - 1];
806
+ if (last !== undefined && last.card.width === card.width)
807
+ last.to = step.to;
808
+ else
809
+ runs.push({ card, from: step.from, to: step.to });
810
+ });
811
+ const final = runs[runs.length - 1]?.card ?? cardFor(formatOverlayNumber(overlay.value, overlay.decimals, context.locale));
812
+ const counted = { ...motion, card: final };
813
+ const cards = runs.flatMap((run, index) => getCardShapeEvents(overlay, run.card, fontSize, colors, counted, context, { start: run.from, end: run.to, isFirst: index === 0, isLast: index === runs.length - 1 }));
814
+ return [...cards, ...text({ x: centerX, y: final.top + final.height / 2 }, 5, fontSize, "heading", shown, counted)];
685
815
  }
686
816
  const isRight = overlay.side === "right";
687
817
  const x = isRight ? box.left + box.width - padX : box.left + padX;
@@ -781,7 +911,7 @@ function getNoteEvents(overlay, context) {
781
911
  if (isStrip) {
782
912
  const before = overlay.lines.slice(0, index).join("").length;
783
913
  const typing = overlay.typing ?? 14;
784
- const steps = getTypedSteps(line, { start: overlay.start + before / typing, end: overlay.end }, typing).map((step, stepIndex) => (stepIndex === 0 ? { ...step, from: overlay.start } : step));
914
+ const steps = getTypedSteps(line, { start: overlay.start + before * getTypingStep(typing), end: overlay.end }, typing).map((step, stepIndex) => (stepIndex === 0 ? { ...step, from: overlay.start } : step));
785
915
  events.push(...getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, motion: textMotion }));
786
916
  return;
787
917
  }
@@ -839,7 +969,9 @@ export function buildDraftOverlayEvents(overlays, colors, frame, options = {}) {
839
969
  toAssSize: (role, cssPx) => (drawn === undefined ? cssPx : toDraftAssSize(cssPx, drawn[role].assScale)),
840
970
  measure: (role, text, cssPx, spacingEm) => (drawn === undefined ? estimateTextWidth(text, cssPx) : drawn[role].measure(text, cssPx) + getSpacingWidth(text, spacingEm, cssPx)),
841
971
  spacing: (spacingEm, cssPx) => (drawn === undefined || spacingEm === 0 ? "" : `\\fsp${String(toDraftSpacing(spacingEm, cssPx))}`),
972
+ contentArea: (role) => drawn?.[role].contentArea ?? DEFAULT_CONTENT_AREA,
842
973
  ...(options.style === undefined ? {} : { style: options.style }),
974
+ ...(drawn === undefined ? {} : { layout: (role, text, cssPx, spacingEm) => drawn[role].measure(text, cssPx) + getSpacingWidth(text, spacingEm, cssPx) }),
843
975
  };
844
976
  return overlays.flatMap((overlay) => {
845
977
  if (overlay.kind === "punch_in")