@softure-ai/marketing-kit 0.28.0 → 0.31.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 (68) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +23 -3
  3. package/dist/config/config.d.ts.map +1 -1
  4. package/dist/config/config.js +1 -0
  5. package/dist/config/config.js.map +1 -1
  6. package/dist/config/schema.d.ts +6 -0
  7. package/dist/config/schema.d.ts.map +1 -1
  8. package/dist/config/schema.js +6 -2
  9. package/dist/config/schema.js.map +1 -1
  10. package/dist/footage/caption-highlight.d.ts +23 -3
  11. package/dist/footage/caption-highlight.d.ts.map +1 -1
  12. package/dist/footage/caption-highlight.js +23 -2
  13. package/dist/footage/caption-highlight.js.map +1 -1
  14. package/dist/footage/compose.d.ts.map +1 -1
  15. package/dist/footage/compose.js +15 -6
  16. package/dist/footage/compose.js.map +1 -1
  17. package/dist/footage/draft-boxes.d.ts +3 -1
  18. package/dist/footage/draft-boxes.d.ts.map +1 -1
  19. package/dist/footage/draft-boxes.js +3 -2
  20. package/dist/footage/draft-boxes.js.map +1 -1
  21. package/dist/footage/draft-overlays.d.ts.map +1 -1
  22. package/dist/footage/draft-overlays.js +191 -41
  23. package/dist/footage/draft-overlays.js.map +1 -1
  24. package/dist/footage/draft.d.ts.map +1 -1
  25. package/dist/footage/draft.js +40 -5
  26. package/dist/footage/draft.js.map +1 -1
  27. package/dist/footage/edl.d.ts +27 -0
  28. package/dist/footage/edl.d.ts.map +1 -1
  29. package/dist/footage/film.d.ts +15 -3
  30. package/dist/footage/film.d.ts.map +1 -1
  31. package/dist/footage/film.js +7 -2
  32. package/dist/footage/film.js.map +1 -1
  33. package/dist/footage/overlay-html.d.ts +8 -0
  34. package/dist/footage/overlay-html.d.ts.map +1 -1
  35. package/dist/footage/overlay-html.js +127 -29
  36. package/dist/footage/overlay-html.js.map +1 -1
  37. package/dist/footage/overlay-motion.d.ts +107 -0
  38. package/dist/footage/overlay-motion.d.ts.map +1 -0
  39. package/dist/footage/overlay-motion.js +129 -0
  40. package/dist/footage/overlay-motion.js.map +1 -0
  41. package/dist/footage/overlay-schema.d.ts +63 -2
  42. package/dist/footage/overlay-schema.d.ts.map +1 -1
  43. package/dist/footage/overlay-schema.js +70 -5
  44. package/dist/footage/overlay-schema.js.map +1 -1
  45. package/dist/footage/overlays.d.ts +16 -1
  46. package/dist/footage/overlays.d.ts.map +1 -1
  47. package/dist/footage/overlays.js +43 -12
  48. package/dist/footage/overlays.js.map +1 -1
  49. package/dist/index.d.ts +5 -4
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +5 -4
  52. package/dist/index.js.map +1 -1
  53. package/package.json +1 -1
  54. package/schema/edl.schema.json +82 -1
  55. package/schema/marketing.schema.json +12 -2
  56. package/src/config/config.ts +1 -0
  57. package/src/config/schema.ts +6 -2
  58. package/src/footage/caption-highlight.ts +27 -5
  59. package/src/footage/compose.ts +15 -5
  60. package/src/footage/draft-boxes.ts +7 -3
  61. package/src/footage/draft-overlays.ts +224 -42
  62. package/src/footage/draft.ts +52 -6
  63. package/src/footage/film.ts +17 -3
  64. package/src/footage/overlay-html.ts +148 -27
  65. package/src/footage/overlay-motion.ts +157 -0
  66. package/src/footage/overlay-schema.ts +90 -5
  67. package/src/footage/overlays.ts +70 -16
  68. package/src/index.ts +28 -0
@@ -2880,11 +2880,21 @@
2880
2880
  },
2881
2881
  "captionHighlightStyle": {
2882
2882
  "default": "text",
2883
- "description": "How a highlight caption lights the word being said: text (the default) colours it captionHighlight; box puts it on a rounded box of brand.colors.captionHighlightBox with its text in captionHighlightText (both then required).",
2883
+ "description": "How a highlight caption lights the word being said: text (the default) colours it captionHighlight; box puts it on a rounded box of brand.colors.captionHighlightBox with its text in captionHighlightText (both then required); underline keeps its text and underlines it in captionHighlight.",
2884
2884
  "type": "string",
2885
2885
  "enum": [
2886
2886
  "text",
2887
- "box"
2887
+ "box",
2888
+ "underline"
2889
+ ]
2890
+ },
2891
+ "captionEntrance": {
2892
+ "description": "How a highlight caption's pill enters in the render: none, fade, or pop (grows from 96 % to 100 % while it fades in, no overshoot), 0.16 s; without it, a short rise while it fades in.",
2893
+ "type": "string",
2894
+ "enum": [
2895
+ "none",
2896
+ "fade",
2897
+ "pop"
2888
2898
  ]
2889
2899
  },
2890
2900
  "overlayMinSpacing": {
@@ -253,6 +253,7 @@ function resolveFootage(data: MarketingJson, at: (relative: string) => string):
253
253
  captions: film.captions,
254
254
  captionStyle: film.captionStyle,
255
255
  ...(film.captionHighlightStyle === "text" ? {} : { captionHighlightStyle: film.captionHighlightStyle }),
256
+ ...(film.captionEntrance === undefined ? {} : { captionEntrance: film.captionEntrance }),
256
257
  ...(film.captionPreset === undefined ? {} : { captionPreset: film.captionPreset }),
257
258
  ...(film.overlayMinSpacing === undefined ? {} : { overlayMinSpacing: film.overlayMinSpacing }),
258
259
  ...(film.captionMaxLines === undefined ? {} : { captionMaxLines: film.captionMaxLines }),
@@ -15,7 +15,7 @@ import {
15
15
  import { bigNumberDataSchema, carouselDataSchema, headlineChartDataSchema, headlineCtaDataSchema } from "../og/templates/schemas.js";
16
16
  import { CHANNEL_CODE_MAX_LENGTH, CHANNEL_CODE_PATTERN, DEFAULT_LINK_IN_BIO, PLATFORMS } from "../platforms.js";
17
17
  import { DECLICK_LEVELS } from "../footage/declick.js";
18
- import { CAPTION_HIGHLIGHT_STYLES, CAPTION_PRESETS, CAPTION_STYLES, CLIP_FITS, CLIP_ROLES, CUT_TRANSITIONS, JUMP_TRANSITIONS } from "../footage/film.js";
18
+ import { CAPTION_ENTRANCES, CAPTION_HIGHLIGHT_STYLES, CAPTION_PRESETS, CAPTION_STYLES, CLIP_FITS, CLIP_ROLES, CUT_TRANSITIONS, JUMP_TRANSITIONS } from "../footage/film.js";
19
19
  import { normalizeKeyTerms } from "../footage/keyterms.js";
20
20
  import { ELEVENLABS_DEFAULT_MODEL } from "../voice/voiceover.js";
21
21
  import { actionSchema, type SceneAction } from "./actions-schema.js";
@@ -586,7 +586,11 @@ const footageSchema = z
586
586
  captionHighlightStyle: z
587
587
  .enum(CAPTION_HIGHLIGHT_STYLES)
588
588
  .default("text")
589
- .describe('How a highlight caption lights the word being said: text (the default) colours it captionHighlight; box puts it on a rounded box of brand.colors.captionHighlightBox with its text in captionHighlightText (both then required).'),
589
+ .describe('How a highlight caption lights the word being said: text (the default) colours it captionHighlight; box puts it on a rounded box of brand.colors.captionHighlightBox with its text in captionHighlightText (both then required); underline keeps its text and underlines it in captionHighlight.'),
590
+ captionEntrance: z
591
+ .enum(CAPTION_ENTRANCES)
592
+ .optional()
593
+ .describe("How a highlight caption's pill enters in the render: none, fade, or pop (grows from 96 % to 100 % while it fades in, no overshoot), 0.16 s; without it, a short rise while it fades in."),
590
594
  overlayMinSpacing: z
591
595
  .number()
592
596
  .min(0)
@@ -1,13 +1,14 @@
1
1
  import { getContrastRatio, type BrandColors } from "../config/colors.js";
2
- import type { FootageFilm } from "./film.js";
2
+ import type { CaptionEntrance, FootageFilm } from "./film.js";
3
3
 
4
4
  /**
5
5
  * How a footage film's `highlight` captions light the word being said (issue #1199): its text in `captionHighlight`
6
- * (`text`), or the word on a rounded box of `captionHighlightBox` with its text in `captionHighlightText` (`box`).
7
- * The render and the draft both draw what this resolves.
6
+ * (`text`), the word on a rounded box of `captionHighlightBox` with its text in `captionHighlightText` (`box`), or the
7
+ * word in its own text colour over an underline of `captionHighlight` (`underline`). The render and the draft both
8
+ * draw what this resolves.
8
9
  */
9
10
 
10
- export type CaptionHighlightLook = { style: "text"; color: string } | { style: "box"; box: string; text: string };
11
+ export type CaptionHighlightLook = { style: "text"; color: string } | { style: "box"; box: string; text: string } | { style: "underline"; color: string };
11
12
 
12
13
  export type CaptionHighlightResult = { ok: true; look: CaptionHighlightLook } | { ok: false; error: string };
13
14
 
@@ -23,9 +24,30 @@ export const CAPTION_HIGHLIGHT_BOX_PADDING_EM = 0.15;
23
24
  /** The box's corner radius, in px: a little over half the pill's 22 px, so the box nests in the pill's rounding. */
24
25
  export const CAPTION_HIGHLIGHT_BOX_RADIUS = 12;
25
26
 
27
+ /**
28
+ * The underline under a lit word, in font sizes: its thickness, and how far its top sits below the line's top (the
29
+ * baseline's neighbourhood of a bold sans-serif at the pill's 1.18 line height).
30
+ */
31
+ export const CAPTION_UNDERLINE_EM = { thickness: 0.09, top: 1.0 } as const;
32
+
33
+ /** How long the pill's entrance lasts, in seconds; `pop` grows from this share of its size. */
34
+ export const CAPTION_ENTRANCE_SECONDS = 0.16;
35
+ export const CAPTION_POP_FROM_SCALE = 0.96;
36
+
37
+ /** A pill's entrance as a GSAP `fromTo` (`from`, `to` vars), or null for `none`; absent: the 14 px rise and fade. */
38
+ export function getCaptionEntranceTween(entrance: CaptionEntrance | undefined): { from: Record<string, number>; to: Record<string, number | string> } | null {
39
+ const timing = { duration: CAPTION_ENTRANCE_SECONDS };
40
+ if (entrance === undefined) return { from: { y: 14, opacity: 0 }, to: { y: 0, opacity: 1, ...timing, ease: "power3.out" } };
41
+ if (entrance === "none") return null;
42
+ if (entrance === "fade") return { from: { opacity: 0 }, to: { opacity: 1, ...timing, ease: "power1.out" } };
43
+ // An ease that ends at its target and never past it: the pill grows to 100 %, not beyond.
44
+ return { from: { scale: CAPTION_POP_FROM_SCALE, opacity: 0 }, to: { scale: 1, opacity: 1, ...timing, ease: "power2.out" } };
45
+ }
46
+
26
47
  /** The film's highlight look, or an error naming the missing brand colours when it asks for a box without them. */
27
48
  export function getCaptionHighlight(film: Pick<FootageFilm, "captionHighlightStyle">, colors: CaptionHighlightColors): CaptionHighlightResult {
28
- if ((film.captionHighlightStyle ?? "text") === "text") return { ok: true, look: { style: "text", color: colors.captionHighlight } };
49
+ const style = film.captionHighlightStyle ?? "text";
50
+ if (style === "text" || style === "underline") return { ok: true, look: { style, color: colors.captionHighlight } };
29
51
  const { captionHighlightBox: box, captionHighlightText: text } = colors;
30
52
  if (box === undefined || text === undefined) {
31
53
  const missing = [box === undefined ? "captionHighlightBox" : null, text === undefined ? "captionHighlightText" : null].filter((role) => role !== null);
@@ -4,7 +4,7 @@ import type { ComposeFont } from "../compose/compose.js";
4
4
  import { assertLocalReferences, escapeHtml, fontFaces, fontStack } from "../compose/html.js";
5
5
  import { CAPTION_LINE_HEIGHT, getCaptionPillCss, getCaptionPositionCss, type CaptionLayout } from "../compose/timeline.js";
6
6
  import type { TimedWord } from "../voice/voiceover.js";
7
- import { CAPTION_HIGHLIGHT_BOX_PADDING_EM, CAPTION_HIGHLIGHT_BOX_RADIUS, CAPTION_HIGHLIGHT_SECONDS, getCaptionHighlight } from "./caption-highlight.js";
7
+ import { CAPTION_HIGHLIGHT_BOX_PADDING_EM, CAPTION_HIGHLIGHT_BOX_RADIUS, CAPTION_HIGHLIGHT_SECONDS, CAPTION_UNDERLINE_EM, getCaptionEntranceTween, getCaptionHighlight } from "./caption-highlight.js";
8
8
  import { CAPTION_SAFE_ZONES, getCaptionChunkLayouts, getCaptionSpans, getFootageCaptionChunks, isSameCaptionPlace, type CaptionSpan } from "./captions.js";
9
9
  import { getEdlDuration, getSegmentStarts, type Edl } from "./edl.js";
10
10
  import {
@@ -219,6 +219,8 @@ export function composeFootage(input: FootageComposeInput): string {
219
219
  if (!highlight.ok) throw new Error(`composeFootage: ${highlight.error}`);
220
220
  const look = highlight.look;
221
221
  const isBox = isHighlight && look.style === "box";
222
+ const isUnderline = isHighlight && look.style === "underline";
223
+ const entrance = getCaptionEntranceTween(film.captionEntrance);
222
224
  const caption = getFootageCaptionChunks(film, words);
223
225
  const spans = getCaptionSpans(caption, cutEnd);
224
226
  const boxes = getCaptionChunkLayouts(caption, edl, captionBox);
@@ -229,7 +231,7 @@ export function composeFootage(input: FootageComposeInput): string {
229
231
  // A chunk in a segment's own box overrides the shared rule's anchor; one in the film's box is written as before.
230
232
  const style = isSameCaptionPlace(place, captionBox) ? "" : ` style="${place.bottom === undefined ? `bottom:auto;top:${place.top}px` : `top:auto;bottom:${place.bottom}px`}"`;
231
233
  const box = isHighlight
232
- ? `<p class="pill">${chunk.words.map((w, j) => `<span id="cw${i}_${j}">${isBox ? `<i class="hl" id="cb${i}_${j}"></i>` : ""}${escapeHtml(w.text)}</span>`).join(" ")}</p>`
234
+ ? `<p class="pill">${chunk.words.map((w, j) => `<span id="cw${i}_${j}">${isBox ? `<i class="hl" id="cb${i}_${j}"></i>` : ""}${isUnderline ? `<i class="ul" id="cu${i}_${j}"></i>` : ""}${escapeHtml(w.text)}</span>`).join(" ")}</p>`
233
235
  : `<p class="phrase">${escapeHtml(chunk.words.map((w) => w.text).join(" "))}</p>`;
234
236
  return `<div id="cap${i}" class="clip caption" data-start="${start}" data-duration="${r3(stop - start)}"${style}>${box}</div>`;
235
237
  })
@@ -305,6 +307,8 @@ ${input.style === undefined ? "" : `${getStyledPillCss(input.style, look.style =
305
307
  ${isBox ? `.pill{position:relative;z-index:0}
306
308
  .pill span{position:relative}
307
309
  .hl{position:absolute;top:0;bottom:0;left:-${CAPTION_HIGHLIGHT_BOX_PADDING_EM}em;right:-${CAPTION_HIGHLIGHT_BOX_PADDING_EM}em;z-index:-1;border-radius:${CAPTION_HIGHLIGHT_BOX_RADIUS}px;background:${look.box};opacity:0}
310
+ ` : ""}${isUnderline ? `.pill span{position:relative}
311
+ .ul{position:absolute;left:0;right:0;top:${CAPTION_UNDERLINE_EM.top}em;height:${CAPTION_UNDERLINE_EM.thickness}em;border-radius:${CAPTION_UNDERLINE_EM.thickness / 2}em;background:${look.color};opacity:0}
308
312
  ` : ""}.phrase{font-weight:650;font-size:${captionBox.fontSize}px;line-height:${CAPTION_LINE_HEIGHT};letter-spacing:-.01em;text-align:center;color:#fff;text-shadow:0 2px 6px rgba(0,0,0,.55),0 0 18px rgba(0,0,0,.35)}
309
313
  .endcard{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:center;align-items:center;padding:0 80px;text-align:center}
310
314
  .brand{display:flex;justify-content:center;align-items:center;gap:18px;font-family:${headingFont};font-size:46px}
@@ -332,9 +336,10 @@ const tl = gsap.timeline({ paused: true });
332
336
  ${tweens.join("\n")}
333
337
  const captions = ${JSON.stringify(isHighlight ? caption.map((chunk) => chunk.words.map((w) => w.start)) : [])};
334
338
  captions.forEach((words, i) => {
335
- tl.fromTo("#cap" + i + " .pill", { y: 14, opacity: 0 }, { y: 0, opacity: 1, duration: 0.16, ease: "power3.out" }, Math.max(0, words[0] - 0.05));
336
- ${
337
- look.style === "box"
339
+ ${entrance === null ? "" : ` tl.fromTo("#cap" + i + " .pill", ${toTweenVars(entrance.from)}, ${toTweenVars(entrance.to)}, Math.max(0, words[0] - 0.05));\n`}${
340
+ look.style === "underline"
341
+ ? ` words.forEach((t, j) => tl.fromTo("#cu" + i + "_" + j, { opacity: 0 }, { opacity: 1, duration: 0.06, immediateRender: false }, t).to("#cu" + i + "_" + j, { opacity: 0, duration: 0.2 }, t + ${CAPTION_HIGHLIGHT_SECONDS}));`
342
+ : look.style === "box"
338
343
  ? ` words.forEach((t, j) => {
339
344
  tl.fromTo("#cb" + i + "_" + j, { opacity: 0 }, { opacity: 1, duration: 0.06, immediateRender: false }, t).to("#cb" + i + "_" + j, { opacity: 0, duration: 0.2 }, t + ${CAPTION_HIGHLIGHT_SECONDS});
340
345
  tl.fromTo("#cw" + i + "_" + j, { color: "${c.captionText}" }, { color: "${look.text}", duration: 0.06, immediateRender: false }, t).to("#cw" + i + "_" + j, { color: "${c.captionText}", duration: 0.2 }, t + ${CAPTION_HIGHLIGHT_SECONDS});
@@ -352,6 +357,11 @@ window.__timelines["${COMPOSITION_ID}"] = tl;
352
357
  `);
353
358
  }
354
359
 
360
+ /** Tween vars as the page's script writes them: `{ y: 14, opacity: 0 }`, strings quoted. */
361
+ function toTweenVars(vars: Record<string, number | string>): string {
362
+ return `{ ${Object.entries(vars).map(([key, value]) => `${key}: ${typeof value === "string" ? JSON.stringify(value) : String(value)}`).join(", ")} }`;
363
+ }
364
+
355
365
  /** The caption pill's rule in the brand's style, after the pill's own: its radius, padding, shadow and border in `accent`. */
356
366
  export function getStyledPillCss(style: BrandStyle, accent: string): string {
357
367
  const pad = getStylePadding(CAPTION_PILL_PADDING, style.padding);
@@ -29,8 +29,10 @@ export interface DraftBoxEventsInput {
29
29
  style: Pick<BrandStyle, "shadow" | "border">;
30
30
  /** The frame's width / 1080. */
31
31
  scale: number;
32
- /** Motion tags every drawing takes (a fade, a move); a `\move` replaces the `\pos`. */
32
+ /** Motion tags every drawing takes (a fade, a move, a scale, a clip); a `\move` replaces the `\pos`. */
33
33
  motion?: string;
34
+ /** A blur entrance or exit: the tags for a drawing whose own blur is `own` (the shadow's, else 0). */
35
+ blurTags?: (own: number) => string;
34
36
  }
35
37
 
36
38
  /** An ASS colour and alpha as override tags of colour `slot` (1 fill, 3 border). */
@@ -45,12 +47,14 @@ export function getDraftBoxEvents(input: DraftBoxEventsInput): string[] {
45
47
  const motion = input.motion ?? "";
46
48
  const pos = motion.includes("\\move") ? "" : "\\pos(0,0)";
47
49
  const drawing = getRoundedRectDrawing(box, radius);
48
- const event = (tags: string, shape: string) => `Dialogue: ${String(input.layer)},${input.at},${input.styleName},,0,0,0,,{\\an7${pos}${motion}${tags}\\p1}${shape}{\\p0}`;
50
+ const event = (tags: string, shape: string, blur = 0) =>
51
+ `Dialogue: ${String(input.layer)},${input.at},${input.styleName},,0,0,0,,{\\an7${pos}${motion}${tags}${input.blurTags?.(blur) ?? ""}\\p1}${shape}{\\p0}`;
49
52
  const events: string[] = [];
50
53
  if (input.style.shadow === "soft") {
51
54
  const lowered = getRoundedRectDrawing({ ...box, top: box.top + STYLE_SHADOW.offsetY * scale }, radius);
52
55
  const alpha = Math.round((1 - STYLE_SHADOW.opacity) * 255).toString(16).padStart(2, "0").toUpperCase();
53
- events.push(event(`\\1c&H000000&\\1a&H${alpha}&\\bord0\\shad0\\blur${String(Math.round((STYLE_SHADOW.blur / 3) * scale))}`, lowered));
56
+ const blur = Math.round((STYLE_SHADOW.blur / 3) * scale);
57
+ events.push(event(`\\1c&H000000&\\1a&H${alpha}&\\bord0\\shad0\\blur${String(blur)}`, lowered, blur));
54
58
  }
55
59
  events.push(event(`${toColorTags(input.color, 1)}\\bord0\\shad0`, drawing));
56
60
  if (input.style.border === "thin") {
@@ -1,7 +1,20 @@
1
1
  import { getCornerRadiusPx, type BrandStyle, type CornerRadius } from "./brand-style.js";
2
2
  import { getDraftBoxEvents } from "./draft-boxes.js";
3
3
  import { toAssColor } from "./draft-color.js";
4
- import { getCounterSeconds, getOverlayColors, getTypingTimes, type OverlayColors } from "./overlay-html.js";
4
+ import { getCounterSeconds, getOverlayColors, getPlaceCardTimes, getTypingTimes, type OverlayColors } from "./overlay-html.js";
5
+ import {
6
+ OVERLAY_EASES,
7
+ PIN_DROP_SECONDS,
8
+ PIN_DROP_SHARE,
9
+ UNDERLINE_EM,
10
+ UNDERLINE_SECONDS,
11
+ getEntranceMotion,
12
+ getExitMotion,
13
+ getWipeHalves,
14
+ type OverlayEntranceMotion,
15
+ type OverlayExitMotion,
16
+ } from "./overlay-motion.js";
17
+ import type { OverlayEntrance } from "./overlay-schema.js";
5
18
  import {
6
19
  OVERLAY_FONT_ROLES,
7
20
  OVERLAY_LINE_HEIGHT,
@@ -13,6 +26,8 @@ import {
13
26
  formatOverlayNumber,
14
27
  getDrawnOverlayCard,
15
28
  getOverlayPadding,
29
+ getPlaceCardPinRow,
30
+ getPlaceCardPinSize,
16
31
  getSideTextLines,
17
32
  getTitleContentBox,
18
33
  type OverlayBox,
@@ -155,21 +170,123 @@ interface TextStep {
155
170
  text: string;
156
171
  }
157
172
 
158
- /** The entrance and exit tags of a run of events: the first fades or slides in, the last fades out. */
159
- function getMotionTags(entrance: "fade" | "slide" | "none", isFirst: boolean, isLast: boolean, slide: { x: number; y: number; dy: number } | null): string {
160
- const fadeIn = isFirst && entrance !== "none" ? FADE_IN_MS : 0;
161
- const fadeOut = isLast ? FADE_OUT_MS : 0;
173
+ /** How one overlay moves in the draft: its entrance and exit (`overlay-motion.ts`) and the card they scale about and wipe over. */
174
+ interface DraftMotion {
175
+ /** The entrance it shows (the kind's own already chosen when the overlay names none). */
176
+ name: OverlayEntrance;
177
+ entrance: OverlayEntranceMotion;
178
+ exit: OverlayExitMotion;
179
+ /** The card a pop scales about and a wipe reveals. */
180
+ card: OverlayBox;
181
+ /** The frame's width / 1080. */
182
+ scale: number;
183
+ isSnappy: boolean;
184
+ /** Whether the card's entrance moves it (slide, rise, pop): then no part moves on the way out, so they stay together. */
185
+ isCardMoved: boolean;
186
+ }
187
+
188
+ /** An overlay's draft motion with its entrance `name` (already the kind's own when it names none). */
189
+ function getDraftMotion(overlay: Exclude<ResolvedOverlay, { kind: "punch_in" }>, name: OverlayEntrance, card: OverlayBox, context: DraftContext): DraftMotion {
190
+ const easing = overlay.easing ?? "smooth";
191
+ const frame = { width: 1080 * context.scale, height: 1920 * context.scale };
192
+ return {
193
+ name,
194
+ entrance: getEntranceMotion(name, easing, frame),
195
+ exit: getExitMotion({ exit: overlay.exit ?? "auto", entrance: overlay.entrance, easing, frame }),
196
+ card,
197
+ scale: context.scale,
198
+ isSnappy: easing === "snappy",
199
+ isCardMoved: name === "slide" || name === "rise" || name === "pop",
200
+ };
201
+ }
202
+
203
+ /** The same motion entering by a plain fade: a part that comes in after its card (a delayed subtitle, a staggered point). */
204
+ function withFadeEntrance(motion: DraftMotion): DraftMotion {
205
+ return { ...motion, name: "fade", entrance: getEntranceMotion("fade", "smooth", { width: 1080, height: 1920 }) };
206
+ }
207
+
208
+ /** Which part of an overlay an event draws: its card (and drawings on it), its text, or a wipe's accent panel. */
209
+ type DraftPart = "card" | "text";
210
+
211
+ /** The rectangle a wipe clips to, round the card with room for its shadow and border. */
212
+ function getWipeClip(motion: DraftMotion): { x0: number; y0: number; x1: number; y1: number } {
213
+ const room = 24 * motion.scale;
214
+ const { card } = motion;
215
+ 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) };
216
+ }
217
+
218
+ const toClip = (box: { x0: number; y0: number; x1: number; y1: number }): string => `\\clip(${box.x0},${box.y0},${box.x1},${box.y1})`;
219
+ const toMs = (seconds: number): number => Math.max(0, Math.round(seconds * 1000));
220
+
221
+ /**
222
+ * 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
223
+ * into place, a pop growing about the card's middle, a wipe's clip), the last the exit (a fade, a move down, a wipe
224
+ * off to the right). libass scales about an event's position, so a pop moves the position with the scale (both linear)
225
+ * to keep the card's middle still. `pos` is the event's position, (0, 0) for a drawing.
226
+ */
227
+ function getMotionTags(motion: DraftMotion, input: { isFirst: boolean; isLast: boolean; pos: OverlayPoint; ms: number; part: DraftPart }): { position: string; rest: string } {
228
+ const { entrance, exit } = motion;
229
+ const { pos, ms } = input;
230
+ let move: string | null = null;
231
+ const tags: string[] = [];
232
+ let fadeIn = 0;
233
+ if (input.isFirst && entrance.kind === "tween") {
234
+ const enterMs = toMs(entrance.seconds);
235
+ fadeIn = motion.name === "fade" || motion.name === "slide" || motion.name === "type" ? FADE_IN_MS : r0(enterMs * 0.7);
236
+ if (motion.name === "slide") move = `\\move(${r0(pos.x)},${r0(pos.y + SLIDE_PX * motion.scale)},${r0(pos.x)},${r0(pos.y)},0,${SLIDE_MS})`;
237
+ if (entrance.from.y > 0 && motion.name !== "slide") move = `\\move(${r0(pos.x)},${r0(pos.y + entrance.from.y)},${r0(pos.x)},${r0(pos.y)},0,${enterMs})`;
238
+ if (entrance.from.scale < 1) {
239
+ const s = entrance.from.scale;
240
+ const centre = { x: motion.card.left + motion.card.width / 2, y: motion.card.top + motion.card.height / 2 };
241
+ move = `\\move(${r0(centre.x + s * (pos.x - centre.x))},${r0(centre.y + s * (pos.y - centre.y))},${r0(pos.x)},${r0(pos.y)},0,${enterMs})`;
242
+ const percent = Math.round(s * 100);
243
+ tags.push(`\\fscx${percent}\\fscy${percent}\\t(0,${enterMs},\\fscx100\\fscy100)`);
244
+ }
245
+ }
246
+ const clip = getWipeClip(motion);
247
+ if (input.isFirst && entrance.kind === "wipe") {
248
+ const halves = getWipeHalves(entrance.seconds);
249
+ const [grow, reveal] = [toMs(halves.grow), toMs(halves.reveal)];
250
+ const closed = toClip({ ...clip, x1: clip.x0 });
251
+ tags.push(input.part === "card" ? `${closed}\\t(0,${grow},${toClip(clip)})` : `${closed}\\t(${grow},${grow + reveal},${toClip(clip)})`);
252
+ }
253
+ let fadeOut = 0;
254
+ if (input.isLast && exit.kind !== "none") {
255
+ if (exit.kind === "wipe") {
256
+ const exitMs = toMs(exit.seconds);
257
+ if (!(input.isFirst && entrance.kind === "wipe")) tags.push(toClip(clip));
258
+ tags.push(`\\t(${Math.max(0, ms - exitMs)},${ms},${toClip({ ...clip, x0: clip.x1 })})`);
259
+ } else {
260
+ fadeOut = motion.isSnappy ? r0(FADE_OUT_MS * 0.7) : FADE_OUT_MS;
261
+ if (exit.kind === "tween" && exit.from.y > 0 && !motion.isCardMoved) {
262
+ const exitMs = toMs(exit.seconds);
263
+ move = `\\move(${r0(pos.x)},${r0(pos.y)},${r0(pos.x)},${r0(pos.y + exit.from.y)},${Math.max(0, ms - exitMs)},${ms})`;
264
+ }
265
+ }
266
+ }
162
267
  const fade = fadeIn === 0 && fadeOut === 0 ? "" : `\\fad(${fadeIn},${fadeOut})`;
163
- const move = isFirst && entrance === "slide" && slide !== null ? `\\move(${r0(slide.x)},${r0(slide.y + slide.dy)},${r0(slide.x)},${r0(slide.y)},0,${SLIDE_MS})` : "";
164
- return `${move}${fade}`;
268
+ return { position: move ?? `\\pos(${r0(pos.x)},${r0(pos.y)})`, rest: `${fade}${tags.join("")}` };
269
+ }
270
+
271
+ /** A blur entrance's and exit's tags for an event whose own blur is `own`: from blurred to its own, from its own to blurred. */
272
+ function getBlurTags(motion: DraftMotion, input: { isFirst: boolean; isLast: boolean; ms: number }, own: number): string {
273
+ const tags: string[] = [];
274
+ if (input.isFirst && motion.entrance.kind === "tween" && motion.entrance.from.blur > 0) {
275
+ tags.push(`\\blur${Math.max(own, r0(motion.entrance.from.blur / 2))}\\t(0,${toMs(motion.entrance.seconds)},\\blur${own})`);
276
+ }
277
+ if (input.isLast && motion.exit.kind === "tween" && motion.exit.from.blur > 0) {
278
+ const exitMs = toMs(motion.exit.seconds);
279
+ tags.push(`\\t(${Math.max(0, input.ms - exitMs)},${input.ms},\\blur${Math.max(own, r0(motion.exit.from.blur / 2))})`);
280
+ }
281
+ return tags.join("");
165
282
  }
166
283
 
167
- /** Text events for a run of steps, positioned at `pos` with `tags`, the entrance on the first and the fade out on the last. */
168
- function getTextEvents(input: { layer: number; style: string; pos: OverlayPoint; tags: string; steps: TextStep[]; entrance: "fade" | "slide" | "none"; slidePx: number }): string[] {
284
+ /** Text events for a run of steps, positioned at `pos` with `tags`, the entrance on the first and the exit on the last. */
285
+ function getTextEvents(input: { layer: number; style: string; pos: OverlayPoint; tags: string; steps: TextStep[]; motion: DraftMotion }): string[] {
169
286
  return input.steps.map((step, index) => {
170
- const motion = getMotionTags(input.entrance, index === 0, index === input.steps.length - 1, { x: input.pos.x, y: input.pos.y, dy: input.slidePx });
171
- const pos = motion.includes("\\move") ? "" : `\\pos(${r0(input.pos.x)},${r0(input.pos.y)})`;
172
- return `Dialogue: ${input.layer},${toAssTime(step.from)},${toAssTime(step.to)},${input.style},,0,0,0,,{${input.tags}${pos}${motion}}${step.text}`;
287
+ const at = { isFirst: index === 0, isLast: index === input.steps.length - 1, ms: toMs(step.to - step.from) };
288
+ const { position, rest } = getMotionTags(input.motion, { ...at, pos: input.pos, part: "text" });
289
+ return `Dialogue: ${input.layer},${toAssTime(step.from)},${toAssTime(step.to)},${input.style},,0,0,0,,{${input.tags}${position}${rest}${getBlurTags(input.motion, at, 0)}}${step.text}`;
173
290
  });
174
291
  }
175
292
 
@@ -210,13 +327,18 @@ function getOwnCardRadius(overlay: Pick<ResolvedOverlay, "kind">, box: { height:
210
327
  }
211
328
 
212
329
  /**
213
- * A card's drawn box on layer 3 with the overlay's entrance: one fill without a brand style, else the style's shadow,
214
- * fill and border (`getDraftBoxEvents`), at the brand style's corner or the overlay's own (`getDraftCardRadius`).
330
+ * A card's drawn box on layer 3 with the overlay's motion: one fill without a brand style, else the style's shadow,
331
+ * fill and border (`getDraftBoxEvents`), at the brand style's corner or the overlay's own (`getDraftCardRadius`); a
332
+ * wipe's accent panel over it.
215
333
  */
216
- function getCardShapeEvents(overlay: ResolvedOverlay, box: OverlayBox, fontSize: number, colors: { background: string; accent: string }, entrance: "fade" | "slide" | "none", context: DraftContext): string[] {
334
+ function getCardShapeEvents(overlay: Exclude<ResolvedOverlay, { kind: "punch_in" }>, box: OverlayBox, fontSize: number, colors: { background: string; accent: string }, motion: DraftMotion, context: DraftContext): string[] {
217
335
  const radius = getDraftCardRadius(overlay, box, context, getOwnCardRadius(overlay, box, fontSize));
218
- if (context.style === undefined) return [getShapeEvent(overlay, getRoundedRectDrawing(box, radius), colors.background, entrance, context.scale)];
219
- return getDraftBoxEvents({
336
+ const drawing = getRoundedRectDrawing(box, radius);
337
+ const panel = getWipePanelEvent(overlay, drawing, colors.accent, motion);
338
+ if (context.style === undefined) return [getShapeEvent(overlay, drawing, colors.background, motion), ...panel];
339
+ const at = { isFirst: true, isLast: true, ms: toMs(overlay.end - overlay.start) };
340
+ const { position, rest } = getMotionTags(motion, { ...at, pos: { x: 0, y: 0 }, part: "card" });
341
+ const events = getDraftBoxEvents({
220
342
  layer: 3,
221
343
  at: `${toAssTime(overlay.start)},${toAssTime(overlay.end)}`,
222
344
  styleName: "OverlayShape",
@@ -226,13 +348,43 @@ function getCardShapeEvents(overlay: ResolvedOverlay, box: OverlayBox, fontSize:
226
348
  accent: colors.accent,
227
349
  style: context.style,
228
350
  scale: context.scale,
229
- motion: getMotionTags(entrance, true, true, { x: 0, y: 0, dy: SLIDE_PX * context.scale }),
351
+ motion: `${position.startsWith("\\move") ? position : ""}${rest}`,
352
+ blurTags: (own) => getBlurTags(motion, at, own),
230
353
  });
354
+ return [...events, ...panel];
355
+ }
356
+
357
+ /** A wipe's accent panel: it grows over the card from the left, then slides off to the right, revealing the card and its text. */
358
+ function getWipePanelEvent(overlay: Pick<ResolvedOverlay, "start">, drawing: string, accent: string, motion: DraftMotion): string[] {
359
+ if (motion.entrance.kind !== "wipe") return [];
360
+ const halves = getWipeHalves(motion.entrance.seconds);
361
+ const [grow, reveal] = [toMs(halves.grow), toMs(halves.reveal)];
362
+ const clip = getWipeClip(motion);
363
+ const tags = `${toClip({ ...clip, x1: clip.x0 })}\\t(0,${grow},${toClip(clip)})\\t(${grow},${grow + reveal},${toClip({ ...clip, x0: clip.x1 })})`;
364
+ 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}`];
365
+ }
366
+
367
+ /** A keyword's underline: an accent bar under its text, drawn from the left once the keyword is in. */
368
+ function getUnderlineEvent(overlay: Extract<ResolvedOverlay, { kind: "keyword" }>, card: OverlayBox, colour: string, motion: DraftMotion): string[] {
369
+ if (overlay.underline !== true) return [];
370
+ const pad = getOverlayPadding(overlay);
371
+ const height = Math.max(2, r0(overlay.fontSize * UNDERLINE_EM.height));
372
+ const bar = { left: card.left + pad.x, top: card.top + card.height - pad.y + r0(overlay.fontSize * UNDERLINE_EM.gap), width: card.width - 2 * pad.x, height };
373
+ const after = motion.entrance.kind === "none" ? 0 : motion.entrance.seconds;
374
+ const from = Math.min(overlay.end, overlay.start + after);
375
+ const drawMs = toMs(UNDERLINE_SECONDS);
376
+ const x0 = r0(bar.left);
377
+ const clip = `\\clip(${x0},${r0(bar.top - 4)},${x0},${r0(bar.top + bar.height + 4)})\\t(0,${drawMs},\\clip(${x0},${r0(bar.top - 4)},${r0(bar.left + bar.width)},${r0(bar.top + bar.height + 4)}))`;
378
+ const fade = motion.exit.kind === "none" ? "" : `\\fad(0,${motion.isSnappy ? r0(FADE_OUT_MS * 0.7) : FADE_OUT_MS})`;
379
+ // Under a wipe off, the bar leaves as the wipe starts: it is not clipped with the card.
380
+ const until = motion.exit.kind === "wipe" ? Math.max(from, overlay.end - motion.exit.seconds) : overlay.end;
381
+ return [`Dialogue: 4,${toAssTime(from)},${toAssTime(until)},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${fade}${clip}\\1c${toTagColor(colour)}\\p1}${getRoundedRectDrawing(bar, height / 2)}{\\p0}`];
231
382
  }
232
383
 
233
384
  /**
234
385
  * A keyword, a lower third or a list: a drawn rounded card fitted to its text (`getDrawnOverlayCard`) on layer 3 and
235
- * its text on layer 4, inset by the card's padding on its side (a lower third from its foot).
386
+ * its text on layer 4, inset by the card's padding on its side (a lower third from its foot). A staggered list's points
387
+ * come in one by one; a keyword's underline is drawn once it is in.
236
388
  */
237
389
  function getSideTextEvents(overlay: Extract<ResolvedOverlay, { kind: "keyword" | "lower_third" | "list" }>, context: DraftContext): string[] {
238
390
  const colors = getOverlayColors(overlay, context.brand);
@@ -246,19 +398,27 @@ function getSideTextEvents(overlay: Extract<ResolvedOverlay, { kind: "keyword" |
246
398
  const y = isFoot ? card.top + card.height - padY : card.top + padY;
247
399
  // \an: 7 top left, 9 top right, 1 bottom left, 3 bottom right.
248
400
  const align = isFoot ? (isRight ? 3 : 1) : isRight ? 9 : 7;
249
- const entrance = overlay.entrance === null || overlay.entrance === "type" ? "fade" : overlay.entrance;
401
+ const motion = getDraftMotion(overlay, overlay.entrance === null || overlay.entrance === "type" ? "fade" : overlay.entrance, card, context);
250
402
  const span = { start: overlay.start, end: overlay.end };
251
403
  const tags = `\\an${align}\\fs${fontSize}${getTextTags(overlay, colors, context, OVERLAY_FONT_ROLES[overlay.kind])}`;
252
- const text = (pos: OverlayPoint, steps: TextStep[]) => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, entrance, slidePx: SLIDE_PX * context.scale });
253
- const shape = getCardShapeEvents(overlay, card, fontSize, colors, entrance, context);
404
+ const text = (pos: OverlayPoint, steps: TextStep[], own = motion) => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, motion: own });
405
+ const shape = getCardShapeEvents(overlay, card, fontSize, colors, motion, context);
254
406
  if (overlay.kind === "list") {
255
- // One event per point, on the render's line height (libass's own line spacing is tighter), all shown at once.
407
+ // One event per point, on the render's line height (libass's own line spacing is tighter); a staggered point from its second.
256
408
  const step = fontSize * OVERLAY_LIST_LINE_HEIGHT;
257
409
  const lead = (step - fontSize * OVERLAY_LINE_HEIGHT) / 2;
258
- return [...shape, ...getSideTextLines(overlay).flatMap((line, index) => text({ x, y: y + lead + index * step }, [{ from: span.start, to: span.end, text: toAssText(line) }]))];
410
+ return [
411
+ ...shape,
412
+ ...getSideTextLines(overlay).flatMap((line, index) => {
413
+ const from = overlay.itemStarts?.[index];
414
+ const pos = { x, y: y + lead + index * step };
415
+ return from === undefined ? text(pos, [{ from: span.start, to: span.end, text: toAssText(line) }]) : text(pos, [{ from, to: span.end, text: toAssText(line) }], withFadeEntrance(motion));
416
+ }),
417
+ ];
259
418
  }
260
419
  // A keyword or a lower third types in only when its entrance says so.
261
- return [...shape, ...text({ x, y }, overlay.entrance === null ? [{ from: span.start, to: span.end, text: toAssText(overlay.text) }] : getTypedSteps(overlay.text, span, overlay.typing))];
420
+ const steps = overlay.entrance === null ? [{ from: span.start, to: span.end, text: toAssText(overlay.text) }] : getTypedSteps(overlay.text, span, overlay.typing);
421
+ return [...shape, ...text({ x, y }, steps), ...(overlay.kind === "keyword" ? getUnderlineEvent(overlay, card, colors.accent, motion) : [])];
262
422
  }
263
423
 
264
424
  type CardOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "search_bar" | "place_card" | "counter" | "date_stamp" }>;
@@ -266,26 +426,40 @@ type CardOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "search_bar"
266
426
  /** Each card's own entrance when the overlay names none (a typed card fades its card in). */
267
427
  const DEFAULT_ENTRANCES = { hook_title: "slide", search_bar: "fade", place_card: "slide", counter: "fade", date_stamp: "fade" } as const;
268
428
 
269
- /** A drawing event in the overlay's card colour (or accent), with the overlay's entrance. */
270
- function getShapeEvent(overlay: Pick<ResolvedOverlay, "start" | "end">, drawing: string, colour: string, entrance: "fade" | "slide" | "none", scale: number): string {
271
- const motion = getMotionTags(entrance, true, true, { x: 0, y: 0, dy: SLIDE_PX * scale });
272
- const pos = motion.includes("\\move") ? "" : "\\pos(0,0)";
273
- return `Dialogue: 3,${toAssTime(overlay.start)},${toAssTime(overlay.end)},OverlayShape,,0,0,0,,{\\an7${pos}${motion}\\1c${toTagColor(colour)}\\p1}${drawing}{\\p0}`;
429
+ /** A drawing event in the overlay's card colour (or accent), with the overlay's motion. */
430
+ function getShapeEvent(overlay: Pick<ResolvedOverlay, "start" | "end">, drawing: string, colour: string, motion: DraftMotion, layer = 3): string {
431
+ const at = { isFirst: true, isLast: true, ms: toMs(overlay.end - overlay.start) };
432
+ const { position, rest } = getMotionTags(motion, { ...at, pos: { x: 0, y: 0 }, part: "card" });
433
+ return `Dialogue: ${layer},${toAssTime(overlay.start)},${toAssTime(overlay.end)},OverlayShape,,0,0,0,,{\\an7${position}${rest}${getBlurTags(motion, at, 0)}\\1c${toTagColor(colour)}\\p1}${drawing}{\\p0}`;
434
+ }
435
+
436
+ /** A place card's pin above its title: there with the card, or dropping a little onto its place. */
437
+ function getPinEvents(overlay: Extract<ResolvedOverlay, { kind: "place_card" }>, at: OverlayPoint, colour: string, motion: DraftMotion): string[] {
438
+ if (overlay.pin === undefined) return [];
439
+ const size = getPlaceCardPinSize(overlay.fontSize);
440
+ const drawing = getPinDrawing(at, size);
441
+ if (overlay.pin === "static") return [getShapeEvent(overlay, drawing, colour, motion, 4)];
442
+ const drop = r0(size * PIN_DROP_SHARE);
443
+ const fade = motion.exit.kind === "none" ? 0 : motion.isSnappy ? r0(FADE_OUT_MS * 0.7) : FADE_OUT_MS;
444
+ return [
445
+ `Dialogue: 4,${toAssTime(overlay.start)},${toAssTime(overlay.end)},OverlayShape,,0,0,0,,{\\an7\\move(0,${-drop},0,0,0,${toMs(PIN_DROP_SECONDS)})\\fad(${r0(toMs(PIN_DROP_SECONDS) * 0.6)},${fade})\\1c${toTagColor(colour)}\\p1}${drawing}{\\p0}`,
446
+ ];
274
447
  }
275
448
 
276
449
  /** A hook title, a search bar, a place card, a counter or a date stamp: a drawn rounded card and its text on layer 4. */
277
450
  function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
278
451
  const colors = getOverlayColors(overlay, context.brand);
279
452
  const { box, fontSize } = overlay;
280
- const entrance = overlay.entrance === null || overlay.entrance === "type" ? (overlay.typing !== null ? "fade" : DEFAULT_ENTRANCES[overlay.kind]) : overlay.entrance;
281
- const slidePx = SLIDE_PX * context.scale;
453
+ const name = overlay.entrance === null || overlay.entrance === "type" ? (overlay.typing !== null ? "fade" : DEFAULT_ENTRANCES[overlay.kind]) : overlay.entrance;
454
+ const motion = getDraftMotion(overlay, name, box, context);
282
455
  const span = { start: overlay.start, end: overlay.end };
283
- const events = getCardShapeEvents(overlay, box, fontSize, colors, entrance, context);
456
+ const events = getCardShapeEvents(overlay, box, fontSize, colors, motion, context);
284
457
  const { x: padX, y: padY } = getOverlayPadding(overlay);
285
458
  const centerX = box.left + box.width / 2;
286
459
  const tagsFor = (role: OverlayFontRole) => getTextTags(overlay, colors, context, role);
287
- const text = (pos: OverlayPoint, align: number, size: number, role: OverlayFontRole, steps: TextStep[], own: "fade" | "slide" | "none" = entrance) =>
288
- getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags: `\\an${align}\\fs${r0(size)}${tagsFor(role)}`, steps, entrance: own, slidePx });
460
+ const text = (pos: OverlayPoint, align: number, size: number, role: OverlayFontRole, steps: TextStep[], own: DraftMotion = motion) =>
461
+ getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags: `\\an${align}\\fs${r0(size)}${tagsFor(role)}`, steps, motion: own });
462
+ const plain = { ...motion, name: "none" as const, entrance: { kind: "none" as const } };
289
463
  if (overlay.kind === "hook_title" || overlay.kind === "place_card") {
290
464
  // The text block sits in the card's middle; centred lines on its axis, left ones from its left edge (RV-131).
291
465
  const content = getTitleContentBox(overlay);
@@ -298,32 +472,40 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
298
472
  const pin = Math.round(size * 1.05);
299
473
  const rowWidth = pin + Math.round(size * 0.25) + estimateTextWidth(overlay.place, size);
300
474
  const rowLeft = isLeft ? content.left : centerX - rowWidth / 2;
301
- events.push(getShapeEvent(overlay, getPinDrawing({ x: rowLeft, y: y + (size * OVERLAY_LINE_HEIGHT - pin) / 2 }, pin), colors.accent, entrance, context.scale).replace("Dialogue: 3,", "Dialogue: 4,"));
475
+ events.push(getShapeEvent(overlay, getPinDrawing({ x: rowLeft, y: y + (size * OVERLAY_LINE_HEIGHT - pin) / 2 }, pin), colors.accent, motion, 4));
302
476
  events.push(...text({ x: rowLeft + pin + Math.round(size * 0.25), y }, 7, size, OVERLAY_FONT_ROLES.date_stamp, [{ from: span.start, to: span.end, text: toAssText(overlay.place) }]));
303
477
  y += size * 1.3 + fontSize * 0.12;
304
478
  }
479
+ const times = overlay.kind === "place_card" ? getPlaceCardTimes(overlay) : { pin: null, title: span.start, subtitle: null };
480
+ if (overlay.kind === "place_card" && overlay.pin !== undefined) {
481
+ const size = getPlaceCardPinSize(fontSize);
482
+ events.push(...getPinEvents(overlay, { x: isLeft ? content.left : centerX - size / 2, y }, colors.accent, motion));
483
+ y += getPlaceCardPinRow(fontSize);
484
+ }
305
485
  const lineHeight = overlay.kind === "hook_title" ? OVERLAY_LINE_HEIGHT : OVERLAY_TITLE_LINE_HEIGHT;
486
+ const titleMotion = times.title > span.start ? withFadeEntrance(motion) : motion;
306
487
  let typedBefore = 0;
307
488
  overlay.lines.forEach((line) => {
308
489
  // The lines type one after the other, as the render's characters do; a left line holds its place transparent
309
490
  // from the start, a centred one shows its typed part only (`getTypedSteps`).
310
- const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
491
+ const lineStart = overlay.typing === null ? times.title : span.start + typedBefore / overlay.typing;
311
492
  const steps = getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
312
493
  // A centred typed line has no hidden first step to carry the entrance: its letters appear as typed, as the render's.
313
494
  const isTypedCentre = !isLeft && overlay.typing !== null;
314
- events.push(...text({ x: lineX, y }, lineAlign, fontSize, "heading", isLeft ? steps.map((step, index) => (index === 0 ? { ...step, from: span.start } : step)) : steps, isTypedCentre ? "none" : entrance));
495
+ events.push(...text({ x: lineX, y }, lineAlign, fontSize, "heading", isLeft ? steps.map((step, index) => (index === 0 ? { ...step, from: span.start } : step)) : steps, isTypedCentre ? plain : titleMotion));
315
496
  typedBefore += [...line].length;
316
497
  y += fontSize * lineHeight;
317
498
  });
318
499
  if (overlay.kind === "place_card" && overlay.subtitle !== null) {
319
- events.push(...text({ x: lineX, y: y + fontSize * 0.12 }, lineAlign, overlay.subtitleFontSize, "interface", [{ from: span.start, to: span.end, text: toAssText(overlay.subtitle) }]));
500
+ const from = times.subtitle ?? span.start;
501
+ events.push(...text({ x: lineX, y: y + fontSize * 0.12 }, lineAlign, overlay.subtitleFontSize, "interface", [{ from, to: span.end, text: toAssText(overlay.subtitle) }], from > span.start ? withFadeEntrance(motion) : motion));
320
502
  }
321
503
  return events;
322
504
  }
323
505
  if (overlay.kind === "search_bar") {
324
506
  const searchPadX = r0(fontSize * SEARCH_BAR_PADDING_EM.x);
325
507
  const middle = box.top + box.height / 2;
326
- events.push(getShapeEvent(overlay, getGlassDrawing({ x: box.left + searchPadX, y: middle - fontSize / 2 }, fontSize), colors.accent, entrance, context.scale).replace("Dialogue: 3,", "Dialogue: 4,"));
508
+ events.push(getShapeEvent(overlay, getGlassDrawing({ x: box.left + searchPadX, y: middle - fontSize / 2 }, fontSize), colors.accent, motion, 4));
327
509
  events.push(...text({ x: box.left + searchPadX + Math.round(fontSize * SEARCH_BAR_ICON_EM), y: middle }, 4, fontSize, "interface", getTypedSteps(overlay.text, span, overlay.typing)));
328
510
  return events;
329
511
  }
@@ -336,8 +518,8 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
336
518
  steps.push({ from: span.start, to: count.start, text: show(overlay.from) });
337
519
  for (let tick = 1; tick <= ticks; tick++) {
338
520
  const progress = tick / ticks;
339
- // power2.out, as the render's tween eases.
340
- const eased = 1 - (1 - progress) ** 2;
521
+ // power2.out, as the render's tween eases: the count slows down to its value.
522
+ const eased = OVERLAY_EASES["power2.out"](progress);
341
523
  const value = overlay.from + (overlay.value - overlay.from) * eased;
342
524
  steps.push({ from: count.start + (tick - 1) * COUNT_STEP, to: tick === ticks ? span.end : count.start + tick * COUNT_STEP, text: show(value) });
343
525
  }