@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
@@ -6,11 +6,11 @@ import type { CaptionLayout, LayoutOverride } from "../compose/timeline.js";
6
6
  import type { BrandColors } from "../config/colors.js";
7
7
  import { err, ok } from "./failure.js";
8
8
  import type { TimedWord } from "../voice/voiceover.js";
9
- import { CAPTION_HIGHLIGHT_BOX_PADDING_EM, CAPTION_HIGHLIGHT_SECONDS, getCaptionHighlight, type CaptionHighlightLook } from "./caption-highlight.js";
9
+ import { CAPTION_HIGHLIGHT_BOX_PADDING_EM, CAPTION_HIGHLIGHT_SECONDS, CAPTION_UNDERLINE_EM, getCaptionHighlight, type CaptionHighlightLook } from "./caption-highlight.js";
10
10
  import { getCaptionChunkLayouts, getCaptionSpans, getFootageCaptionChunks, getFootageCaptionLayout, isSameCaptionPlace, type CaptionWordsFilm } from "./captions.js";
11
11
  import { getSegmentScales, getSegmentZoomEases } from "./compose.js";
12
12
  import { toAssColor } from "./draft-color.js";
13
- import { buildDraftOverlayEvents, getDraftOverlayStyles } from "./draft-overlays.js";
13
+ import { buildDraftOverlayEvents, getDraftOverlayStyles, getRoundedRectDrawing } from "./draft-overlays.js";
14
14
  import { getCaptionCornerRadius, getCornerRadiusPx, getStylePadding, type BrandStyle } from "./brand-style.js";
15
15
  import { getDraftBoxEvents } from "./draft-boxes.js";
16
16
  import { createDraftTextMeasure, wrapDraftLine, type DraftTextMeasure } from "./draft-text-width.js";
@@ -181,9 +181,10 @@ const NO_BOX = "{\\3a&HFF&\\4a&HFF&}";
181
181
  * A `highlight` chunk as ASS events: its span cut wherever a word lights up or goes out, each piece showing the chunk
182
182
  * with the words lit then in `highlight` (a word stays lit for the render's 0.32 s from its start).
183
183
  */
184
- function buildHighlightEvents(chunk: { words: TimedWord[] }, span: { start: number; end: number }, colors: { text: string; highlight: string }, styleName: string, layout: ChunkLayout = BOXLESS_LAYOUT): string[] {
184
+ function buildHighlightEvents(chunk: { words: TimedWord[] }, span: { start: number; end: number }, colors: { text: string; highlight: string }, styleName: string, layout: ChunkLayout = BOXLESS_LAYOUT, isUnderlined = false): string[] {
185
+ const [on, off] = isUnderlined ? ["\\u1", "\\u0"] : ["", ""];
185
186
  return getHighlightPieces(chunk, span).map((piece) => {
186
- const words = chunk.words.map((word, wordIndex) => (piece.lit[wordIndex] === true ? `{\\1c${colors.highlight}&}${toAssText(word.text)}{\\1c${colors.text}&}` : toAssText(word.text)));
187
+ const words = chunk.words.map((word, wordIndex) => (piece.lit[wordIndex] === true ? `{${on}\\1c${colors.highlight}&}${toAssText(word.text)}{${off}\\1c${colors.text}&}` : toAssText(word.text)));
187
188
  return `Dialogue: 0,${toAssTime(piece.from / 100)},${toAssTime(piece.to / 100)},${styleName},,0,0,0,,${layout.hasPill ? NO_BOX : ""}${joinWords(words, layout.breaks)}`;
188
189
  });
189
190
  }
@@ -219,10 +220,18 @@ function buildHighlightBoxEvents(
219
220
  });
220
221
  }
221
222
 
222
- /** The pill of a chunk drawn in the brand's style: its lines (broken by width) and its shadow, box and border events. */
223
+ /** Where a word of a drawn pill sits: its left edge, width and its line's top, in the draft's frame. */
224
+ interface DrawnWord {
225
+ left: number;
226
+ width: number;
227
+ lineTop: number;
228
+ }
229
+
230
+ /** The pill of a chunk drawn in the brand's style: its lines (broken by width), its shadow, box and border events, and each word's place. */
223
231
  interface DrawnPill {
224
232
  breaks: Set<number>;
225
233
  events: string[];
234
+ words: DrawnWord[];
226
235
  }
227
236
 
228
237
  interface DrawnPillInput {
@@ -258,7 +267,39 @@ function getDrawnPill(input: DrawnPillInput): DrawnPill {
258
267
  const box = { left: place.left + (areaWidth - width) / 2, top: textTop - pad.y, width, height };
259
268
  const at = `${toAssTime(input.span.start)},${toAssTime(input.span.end)}`;
260
269
  const radius = getCornerRadiusPx(getCaptionCornerRadius(style), height, scale);
261
- return { breaks, events: getDraftBoxEvents({ layer: 0, at, styleName: "CaptionShape", box, radius, color: input.colors.background, accent: input.colors.accent, style, scale }) };
270
+ // libass centres each line in the caption box, as the pill is: a word starts where the words before it and a space end.
271
+ const words = lines.flatMap((line, lineIndex) => {
272
+ const lineLeft = place.left + (areaWidth - measure(line.join(" "), place.fontSize)) / 2;
273
+ return line.map((word, index) => {
274
+ const width = measure(word, place.fontSize);
275
+ return { left: lineLeft + measure(line.slice(0, index + 1).join(" "), place.fontSize) - width, width, lineTop: textTop + lineIndex * place.fontSize };
276
+ });
277
+ });
278
+ return { breaks, events: getDraftBoxEvents({ layer: 0, at, styleName: "CaptionShape", box, radius, color: input.colors.background, accent: input.colors.accent, style, scale }), words };
279
+ }
280
+
281
+ /** Where the draft's underline sits under a line, in font sizes: libass draws a line one font size tall, its baseline near 0.8. */
282
+ const DRAFT_UNDERLINE_TOP_EM = 0.9;
283
+
284
+ /**
285
+ * An `underline` highlight's bars over a drawn pill: for each piece of the chunk's span, a rounded bar in `color` under
286
+ * every word lit then, as wide as the word, `CAPTION_UNDERLINE_EM.thickness` font sizes thick.
287
+ */
288
+ function buildUnderlineEvents(chunk: { words: TimedWord[] }, span: { start: number; end: number }, words: readonly DrawnWord[], fontSize: number, color: string): string[] {
289
+ const thickness = Math.max(2, Math.round(fontSize * CAPTION_UNDERLINE_EM.thickness));
290
+ return getHighlightPieces(chunk, span).flatMap((piece) =>
291
+ words.flatMap((word, index) => {
292
+ if (piece.lit[index] !== true) return [];
293
+ const bar = { left: word.left, top: word.lineTop + Math.round(fontSize * DRAFT_UNDERLINE_TOP_EM), width: word.width, height: thickness };
294
+ return [`Dialogue: 0,${toAssTime(piece.from / 100)},${toAssTime(piece.to / 100)},CaptionShape,,0,0,0,,{\\an7\\pos(0,0)${toUnderlineColorTags(color)}\\bord0\\shad0\\p1}${getRoundedRectDrawing(bar, thickness / 2)}{\\p0}`];
295
+ }),
296
+ );
297
+ }
298
+
299
+ /** A `#rrggbb` colour as an ASS fill colour and alpha. */
300
+ function toUnderlineColorTags(hex: string): string {
301
+ const ass = toAssColor(hex);
302
+ return `\\1c&H${ass.slice(4)}&\\1a&H${ass.slice(2, 4)}&`;
262
303
  }
263
304
 
264
305
  /** The highlight look the draft draws: `text` for a `phrase` film; a `box` film without its colours is an input error. */
@@ -354,6 +395,11 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
354
395
  style === undefined ? null : getDrawnPill({ words: chunk.words.map((word) => word.text.replace(/\u00a0/g, " ")), span, place: places[index] ?? caption, frame, style, measure, colors: pillColors });
355
396
  const layout: ChunkLayout = pill === null ? BOXLESS_LAYOUT : { breaks: pill.breaks, hasPill: true };
356
397
  const drawn = pill?.events ?? [];
398
+ if (isHighlight && lit.style === "underline") {
399
+ // Over a drawn pill the bar is drawn under the lit word, its text unchanged; without one libass underlines it in the accent.
400
+ if (pill === null) return buildHighlightEvents(chunk, span, highlight, styleName, layout, true);
401
+ return [...drawn, ...buildUnderlineEvents(chunk, span, pill.words, (places[index] ?? caption).fontSize, colors.captionHighlight), ...buildHighlightEvents(chunk, span, { text: highlight.text, highlight: highlight.text }, styleName, layout)];
402
+ }
357
403
  if (isHighlight && boxColors !== null) return [...drawn, ...buildHighlightBoxEvents(chunk, span, boxColors, boxPadding, styleName, layout)];
358
404
  if (isHighlight) return [...drawn, ...buildHighlightEvents(chunk, span, highlight, styleName, layout)];
359
405
  const line = toAssText(chunk.words.map((word) => word.text).join(" "));
@@ -128,9 +128,15 @@ export interface FootageFilm {
128
128
  /**
129
129
  * How a `highlight` caption lights the word being said: `text` (the default) colours its text `captionHighlight`;
130
130
  * `box` puts it on a rounded box of `captionHighlightBox` with its text in `captionHighlightText` (both brand colours
131
- * then required). Ignored by `phrase` captions.
131
+ * then required); `underline` keeps its text and draws an underline in `captionHighlight` under it. Ignored by
132
+ * `phrase` captions.
132
133
  */
133
134
  captionHighlightStyle?: CaptionHighlightStyle;
135
+ /**
136
+ * How a `highlight` caption's pill enters (`CAPTION_ENTRANCES`) in the render; absent: a 14 px rise while it fades
137
+ * in, as before. The draft draws the captions without an entrance.
138
+ */
139
+ captionEntrance?: CaptionEntrance;
134
140
  /** Places the 9:16 caption box inside a platform's safe zone (`CAPTION_SAFE_ZONES`); absent: the layout as it is. */
135
141
  captionPreset?: CaptionPreset;
136
142
  /**
@@ -279,11 +285,19 @@ export const CAPTION_STYLES = ["phrase", "highlight"] as const;
279
285
 
280
286
  export type CaptionStyle = (typeof CAPTION_STYLES)[number];
281
287
 
282
- /** How a `highlight` caption lights the word being said: its text colour, or a box behind it (issue #1199). */
283
- export const CAPTION_HIGHLIGHT_STYLES = ["text", "box"] as const;
288
+ /** How a `highlight` caption lights the word being said: its text colour, a box behind it (issue #1199), or an accent underline. */
289
+ export const CAPTION_HIGHLIGHT_STYLES = ["text", "box", "underline"] as const;
284
290
 
285
291
  export type CaptionHighlightStyle = (typeof CAPTION_HIGHLIGHT_STYLES)[number];
286
292
 
293
+ /**
294
+ * How a `highlight` caption's pill enters: at once (`none`), fading in (`fade`), or fading in while it grows from 96 %
295
+ * to 100 % without overshooting (`pop`); 0.16 s each.
296
+ */
297
+ export const CAPTION_ENTRANCES = ["none", "fade", "pop"] as const;
298
+
299
+ export type CaptionEntrance = (typeof CAPTION_ENTRANCES)[number];
300
+
287
301
  /** The smallest a caption line limit shrinks a card's font to, as a share of the caption box's size. */
288
302
  export const CAPTION_MIN_FONT_SCALE = 0.7;
289
303
 
@@ -2,6 +2,18 @@ import type { BrandColors } from "../config/colors.js";
2
2
  import { escapeHtml } from "../compose/html.js";
3
3
  import { getCornerRadiusCss, getStyleBorderCss, getStyleShadowCss, type BrandStyle } from "./brand-style.js";
4
4
  import type { OverlayEntrance } from "./overlay-schema.js";
5
+ import {
6
+ PIN_DROP_SECONDS,
7
+ PIN_DROP_SHARE,
8
+ PIN_TITLE_LEAD,
9
+ UNDERLINE_EM,
10
+ UNDERLINE_SECONDS,
11
+ getEntranceMotion,
12
+ getExitMotion,
13
+ getWipeHalves,
14
+ type OverlayEntranceMotion,
15
+ type OverlayMotionOffset,
16
+ } from "./overlay-motion.js";
5
17
  import {
6
18
  OVERLAY_LINE_HEIGHT,
7
19
  OVERLAY_LIST_LINE_HEIGHT,
@@ -10,6 +22,8 @@ import {
10
22
  SEARCH_BAR_PADDING_EM,
11
23
  formatOverlayNumber,
12
24
  getOverlayPadding,
25
+ getPlaceCardPinRow,
26
+ getPlaceCardPinSize,
13
27
  getTitleContentBox,
14
28
  type ResolvedOverlay,
15
29
  } from "./overlays.js";
@@ -22,8 +36,8 @@ import {
22
36
  * `lt-soft-pill` (the lower third's scale-pop pill, dot and settling text), `marker-highlight` (the stroke drawn over
23
37
  * its target), `hw-arrow` (the drawn-on arrow whose head arrives last) and `push-in` (the eased camera push, in
24
38
  * `composeFootage`). They are rewritten for the kit's frame, timeline and brand tokens: see the package's NOTICE. The
25
- * entrances (`fade`, `slide`, `type`, `none`), the typed search field, the counting number and the drawn pin are the
26
- * kit's own, eased without overshoot.
39
+ * entrances and exits (`overlay-motion.ts`), the typed search field, the counting number and the drawn pin are the
40
+ * kit's own, eased without overshoot: nothing grows past its size.
27
41
  */
28
42
 
29
43
  /** The seconds an overlay takes to leave, ending with its clip. */
@@ -98,6 +112,15 @@ function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interfac
98
112
  `.ov-date:not(.right) .ov-card{align-items:flex-start}`,
99
113
  `.ov-date .ov-sub{font-weight:600;margin-top:0}`,
100
114
  `.ty .ch{opacity:0}`,
115
+ // A wipe's accent panel over its card, the keyword's underline, a dropped pin, and the parts that come in later.
116
+ `.ov-card{position:relative}`,
117
+ `.ov-wipe{position:absolute;inset:0;border-radius:inherit;background:${colors.accent};transform-origin:100% 50%}`,
118
+ `.ov-ul{position:absolute;height:${UNDERLINE_EM.height}em;border-radius:${UNDERLINE_EM.height / 2}em;background:${colors.accent};transform:scaleX(0);transform-origin:0% 50%}`,
119
+ `.ov-pinrow{display:flex;justify-content:center}`,
120
+ `.ov-stack.left .ov-pinrow{justify-content:flex-start}`,
121
+ `.st li,.pd .ov-pinrow svg,.pl .ov-line,.sd .ov-sub{opacity:0}`,
122
+ // An underlined keyword keeps only its drawn bar: the card's own accent edge would be a second line under it.
123
+ `.ov-keyword.ul .ov-card{border-bottom-color:transparent}`,
101
124
  // The brand's style (after the kinds' own rules, so it wins over them; the search bar stays a pill).
102
125
  ...(style === undefined
103
126
  ? []
@@ -162,12 +185,55 @@ function getCardStyle(overlay: ResolvedOverlay, colors: OverlayColors, scale = 1
162
185
  return style === "" ? "" : ` style="${style}"`;
163
186
  }
164
187
 
165
- /** The entrance tweens of a card: fade, slide, a typed card's fade, or nothing. */
166
- function getEntranceTweens(target: string, entrance: OverlayEntrance, start: number): string[] {
167
- if (entrance === "none") return [];
168
- if (entrance === "slide") return [`tl.fromTo("${target}", { opacity: 0, y: 28 }, { opacity: 1, y: 0, duration: 0.5, ease: "power3.out", immediateRender: false }, ${start});`];
169
- const duration = entrance === "type" ? 0.25 : 0.4;
170
- return [`tl.fromTo("${target}", { opacity: 0 }, { opacity: 1, duration: ${duration}, ease: "power2.out", immediateRender: false }, ${start});`];
188
+ /** The GSAP properties of a motion offset: only what differs from rest, in a fixed order. */
189
+ function toTweenVars(offset: OverlayMotionOffset): string[] {
190
+ return [
191
+ `opacity: ${offset.opacity}`,
192
+ ...(offset.scale === 1 ? [] : [`scale: ${offset.scale}`]),
193
+ ...(offset.y === 0 ? [] : [`y: ${offset.y}`]),
194
+ ...(offset.blur === 0 ? [] : [`filter: "blur(${offset.blur}px)"`]),
195
+ ];
196
+ }
197
+
198
+ /** The same properties at rest: opacity 1, scale 1, in place, sharp. */
199
+ function toRestVars(offset: OverlayMotionOffset): string[] {
200
+ return [`opacity: 1`, ...(offset.scale === 1 ? [] : [`scale: 1`]), ...(offset.y === 0 ? [] : [`y: 0`]), ...(offset.blur === 0 ? [] : [`filter: "blur(0px)"`])];
201
+ }
202
+
203
+ /** The entrance tweens of a card (`target`): tweened from its offset, a wipe (its panel `wipe`), or nothing. */
204
+ function getMotionTweens(target: string, motion: OverlayEntranceMotion, start: number, wipe?: string): string[] {
205
+ if (motion.kind === "none") return [];
206
+ if (motion.kind === "wipe") {
207
+ // The card grows from the left under the accent panel, then the panel slides off to the right over the card and its text.
208
+ const halves = getWipeHalves(motion.seconds);
209
+ return [
210
+ `tl.fromTo("${target}", { clipPath: "inset(0% 100% 0% 0%)" }, { clipPath: "inset(0% 0% 0% 0%)", duration: ${halves.grow}, ease: "${motion.ease}", immediateRender: false }, ${start});`,
211
+ `tl.fromTo("${wipe ?? `${target} .ov-wipe`}", { scaleX: 1 }, { scaleX: 0, duration: ${halves.reveal}, ease: "${motion.ease}", immediateRender: false }, ${r3(start + halves.grow)});`,
212
+ ];
213
+ }
214
+ return [`tl.fromTo("${target}", { ${toTweenVars(motion.from).join(", ")} }, { ${[...toRestVars(motion.from), `duration: ${motion.seconds}`, `ease: "${motion.ease}"`, "immediateRender: false"].join(", ")} }, ${start});`];
215
+ }
216
+
217
+ /** The entrance tweens of a card by its named entrance (fade, slide, type, pop, rise, blur, wipe, or none). */
218
+ function getEntranceTweens(target: string, entrance: OverlayEntrance, start: number, look: { easing?: "smooth" | "snappy"; frame?: { width: number; height: number } } = {}): string[] {
219
+ return getMotionTweens(target, getEntranceMotion(entrance, look.easing ?? "smooth", look.frame ?? { width: 1080, height: 1920 }), start);
220
+ }
221
+
222
+ /** The seconds an overlay's entrance takes, so what comes after it (an underline) starts once it is in. */
223
+ function getEntranceSeconds(entrance: OverlayEntrance | null, overlay: ResolvedOverlay, frame: { width: number; height: number }): number {
224
+ if (entrance === null) return 0.45;
225
+ const motion = getEntranceMotion(entrance, overlay.kind === "punch_in" ? "smooth" : (overlay.easing ?? "smooth"), frame);
226
+ return motion.kind === "none" ? 0 : motion.seconds;
227
+ }
228
+
229
+ /** The exit tweens of an overlay's `target`, ending with its clip: its own (`own`, the kind's), tweened, wiped off, or none. */
230
+ function getExitTweens(target: string, overlay: Exclude<ResolvedOverlay, { kind: "punch_in" }>, frame: { width: number; height: number }, own: string): string[] {
231
+ const motion = getExitMotion({ exit: overlay.exit ?? "auto", entrance: overlay.entrance, easing: overlay.easing ?? "smooth", frame });
232
+ if (motion.kind === "none") return [];
233
+ if (motion.kind === "own") return [own];
234
+ const at = r3(overlay.end - motion.seconds);
235
+ if (motion.kind === "wipe") return [`tl.to("${target}", { clipPath: "inset(0% 0% 0% 100%)", duration: ${motion.seconds}, ease: "${motion.ease}" }, ${at});`];
236
+ return [`tl.to("${target}", { ${[...toTweenVars(motion.from), `duration: ${motion.seconds}`, `ease: "${motion.ease}"`].join(", ")} }, ${at});`];
171
237
  }
172
238
 
173
239
  /** The typing tweens: each character of `#<id>` shown at its time. */
@@ -195,28 +261,48 @@ function addSideText(overlay: Extract<ResolvedOverlay, { kind: "keyword" | "lowe
195
261
  const isTyped = overlay.typing !== null && overlay.kind !== "list";
196
262
  const style = `left:${box.left}px;top:${box.top}px;width:${box.width}px;height:${box.height}px;font-size:${fontSize}px;align-items:${overlay.kind === "lower_third" ? "flex-end" : "flex-start"}`;
197
263
  const text = overlay.kind === "list" ? "" : isTyped ? toTypedHtml(overlay.text) : escapeHtml(overlay.text);
264
+ const wipe = overlay.entrance === "wipe" ? `<i class="ov-wipe" id="${id}w"></i>` : "";
265
+ const underline = overlay.kind === "keyword" && overlay.underline === true ? `<i class="ov-ul" id="${id}u" style="${getUnderlineStyle(overlay)}"></i>` : "";
266
+ const staggered = overlay.kind === "list" ? overlay.itemStarts : undefined;
198
267
  const body =
199
268
  overlay.kind === "list"
200
- ? `<ul class="ov-card"${cardStyle}>${overlay.items.map((item, i) => `<li id="${id}i${i}"><i class="ov-dot"${dotStyle}></i>${escapeHtml(item)}</li>`).join("")}</ul>`
201
- : `<div class="ov-card"${cardStyle}>${overlay.kind === "lower_third" ? `<i class="ov-dot" id="${id}d"${dotStyle}></i>` : ""}<span id="${id}t">${text}</span></div>`;
202
- out.html.push(clipDiv(overlay, id, `ov ov-${overlay.kind.replace("_", "-")}${side === "right" ? " right" : ""}${isTyped ? " ty" : ""}`, style, body));
269
+ ? `<ul class="ov-card"${cardStyle}>${wipe}${overlay.items.map((item, i) => `<li id="${id}i${i}"><i class="ov-dot"${dotStyle}></i>${escapeHtml(item)}</li>`).join("")}</ul>`
270
+ : `<div class="ov-card"${cardStyle}>${wipe}${overlay.kind === "lower_third" ? `<i class="ov-dot" id="${id}d"${dotStyle}></i>` : ""}<span id="${id}t">${text}</span>${underline}</div>`;
271
+ out.html.push(clipDiv(overlay, id, `ov ov-${overlay.kind.replace("_", "-")}${side === "right" ? " right" : ""}${isTyped ? " ty" : ""}${staggered === undefined ? "" : " st"}${underline === "" ? "" : " ul"}`, style, body));
203
272
  if (overlay.entrance !== null) {
204
- out.tweens.push(...getEntranceTweens(`#${id} .ov-card`, overlay.entrance, overlay.start));
273
+ out.tweens.push(...getMotionTweens(`#${id} .ov-card`, getEntranceMotion(overlay.entrance, overlay.easing ?? "smooth", context.frame), overlay.start));
205
274
  if (overlay.kind !== "list") out.tweens.push(...getTypingTweens(id, overlay, [...overlay.text].length));
206
275
  } else {
207
- // The soft pill's entrance: the card rises from its foot, then its dot and its text settle in.
208
- out.tweens.push(`tl.fromTo("#${id} .ov-card", { scale: 0.88, y: 18, opacity: 0 }, { scale: 1, y: 0, opacity: 1, duration: 0.45, ease: "back.out(1.7)", immediateRender: false }, ${overlay.start});`);
276
+ // The soft pill's entrance: the card rises from its foot, then its dot and its text settle in, eased out without
277
+ // overshoot (RV-133 of an adopting app: nothing grows past its size).
278
+ out.tweens.push(`tl.fromTo("#${id} .ov-card", { scale: 0.88, y: 18, opacity: 0 }, { scale: 1, y: 0, opacity: 1, duration: 0.45, ease: "power3.out", immediateRender: false }, ${overlay.start});`);
209
279
  if (overlay.kind === "lower_third") {
210
- out.tweens.push(`tl.fromTo("#${id}d", { scale: 0 }, { scale: 1, duration: 0.35, ease: "back.out(3)", immediateRender: false }, ${r3(overlay.start + 0.25)});`);
280
+ out.tweens.push(`tl.fromTo("#${id}d", { scale: 0 }, { scale: 1, duration: 0.35, ease: "power2.out", immediateRender: false }, ${r3(overlay.start + 0.25)});`);
211
281
  out.tweens.push(`tl.fromTo("#${id}t", { opacity: 0, x: -10 }, { opacity: 1, x: 0, duration: 0.4, ease: "power3.out", immediateRender: false }, ${r3(overlay.start + 0.3)});`);
212
282
  }
213
- if (overlay.kind === "list") {
283
+ if (overlay.kind === "list" && staggered === undefined) {
214
284
  overlay.items.forEach((_item, i) => {
215
285
  out.tweens.push(`tl.fromTo("#${id}i${i}", { opacity: 0, y: 14 }, { opacity: 1, y: 0, duration: 0.35, ease: "power3.out", immediateRender: false }, ${r3(overlay.start + 0.2 + 0.12 * i)});`);
216
286
  });
217
287
  }
218
288
  }
219
- out.tweens.push(`tl.to("#${id} .ov-card", { scale: 0.94, y: 14, opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${r3(overlay.end - EXIT_SECONDS)});`);
289
+ // A staggered list's points come in one by one, each on its own second (`itemStarts`).
290
+ staggered?.forEach((at, i) => {
291
+ out.tweens.push(`tl.fromTo("#${id}i${i}", { opacity: 0, y: ${r3(14 * context.scale)} }, { opacity: 1, y: 0, duration: 0.35, ease: "power3.out", immediateRender: false }, ${at});`);
292
+ });
293
+ if (underline !== "") {
294
+ out.tweens.push(`tl.fromTo("#${id}u", { scaleX: 0 }, { scaleX: 1, duration: ${UNDERLINE_SECONDS}, ease: "power2.out", immediateRender: false }, ${r3(overlay.start + getEntranceSeconds(overlay.entrance, overlay, context.frame))});`);
295
+ }
296
+ out.tweens.push(
297
+ ...getExitTweens(`#${id} .ov-card`, overlay, context.frame, `tl.to("#${id} .ov-card", { scale: 0.94, y: 14, opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${r3(overlay.end - EXIT_SECONDS)});`),
298
+ );
299
+ }
300
+
301
+ /** Where a keyword's underline sits in its card: under the text, inside the card's padding. */
302
+ function getUnderlineStyle(overlay: Extract<ResolvedOverlay, { kind: "keyword" }>): string {
303
+ const pad = overlay.padScale ?? 1;
304
+ const x = r3(OVERLAY_PADDING_EM.x * pad);
305
+ return `left:${x}em;right:${x}em;bottom:${r3(Math.max(0.04, OVERLAY_PADDING_EM.y * pad - UNDERLINE_EM.gap - UNDERLINE_EM.height))}em`;
220
306
  }
221
307
 
222
308
  type CardOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "search_bar" | "place_card" | "counter" | "date_stamp" }>;
@@ -227,22 +313,25 @@ function getCardBody(overlay: CardOverlay, id: string, colors: OverlayColors, lo
227
313
  if (overlay.kind === "hook_title") {
228
314
  const place = overlay.place === null ? "" : `<div class="ov-place" style="font-size:${overlay.placeFontSize}px">${getPinSvg(colors.accent)}<span>${escapeHtml(overlay.place)}</span></div>`;
229
315
  const lines = overlay.lines.map((line) => `<div class="ov-line">${typedOrPlain(line)}</div>`).join("");
230
- return { classes: "ov-hook-title center", body: `<div class="ov-card ov-stack${overlay.align === "left" ? " left" : ""}"__STYLE__>${place}${lines}</div>`, typed: overlay.lines.join("").length };
316
+ return { classes: "ov-hook-title center", body: `<div class="ov-card ov-stack${overlay.align === "left" ? " left" : ""}"__STYLE__>__WIPE__${place}${lines}</div>`, typed: overlay.lines.join("").length };
231
317
  }
232
318
  if (overlay.kind === "place_card") {
233
319
  const subtitle = overlay.subtitle === null ? "" : `<div class="ov-sub" style="font-size:${overlay.subtitleFontSize}px">${escapeHtml(overlay.subtitle)}</div>`;
234
320
  const lines = overlay.lines.map((line) => `<div class="ov-line">${typedOrPlain(line)}</div>`).join("");
235
- return { classes: "ov-place-card center", body: `<div class="ov-card ov-stack${overlay.align === "left" ? " left" : ""}"__STYLE__>${lines}${subtitle}</div>`, typed: overlay.lines.join("").length };
321
+ const pinSize = getPlaceCardPinSize(overlay.fontSize);
322
+ const pin = overlay.pin === undefined ? "" : `<div class="ov-pinrow" id="${id}p" style="height:${getPlaceCardPinRow(overlay.fontSize)}px">${getPinSvg(colors.accent).replace('class="ov-pin"', `class="ov-pin" style="width:${pinSize}px;height:${pinSize}px"`)}</div>`;
323
+ const later = [overlay.pin === "drop" ? " pd" : "", overlay.pin !== undefined && overlay.typing === null ? " pl" : "", overlay.subtitleDelay === undefined || subtitle === "" ? "" : " sd"].join("");
324
+ return { classes: `ov-place-card center${later}`, body: `<div class="ov-card ov-stack${overlay.align === "left" ? " left" : ""}"__STYLE__>__WIPE__${pin}${lines}${subtitle}</div>`, typed: overlay.lines.join("").length };
236
325
  }
237
326
  if (overlay.kind === "search_bar") {
238
- return { classes: "ov-search-bar center", body: `<div class="ov-card ov-search"__STYLE__>${getGlassSvg(colors.accent)}<span id="${id}t">${typedOrPlain(overlay.text)}</span></div>`, typed: [...overlay.text].length };
327
+ return { classes: "ov-search-bar center", body: `<div class="ov-card ov-search"__STYLE__>__WIPE__${getGlassSvg(colors.accent)}<span id="${id}t">${typedOrPlain(overlay.text)}</span></div>`, typed: [...overlay.text].length };
239
328
  }
240
329
  if (overlay.kind === "counter") {
241
330
  const unit = overlay.unit === null ? "" : `<span class="ov-unit" style="font-size:${overlay.unitFontSize}px">${escapeHtml(overlay.unit)}</span>`;
242
- return { classes: "ov-counter center", body: `<div class="ov-card"__STYLE__><span id="${id}n">${escapeHtml(formatOverlayNumber(overlay.from, overlay.decimals, locale))}</span>${unit}</div>`, typed: 0 };
331
+ return { classes: "ov-counter center", body: `<div class="ov-card"__STYLE__>__WIPE__<span id="${id}n">${escapeHtml(formatOverlayNumber(overlay.from, overlay.decimals, locale))}</span>${unit}</div>`, typed: 0 };
243
332
  }
244
333
  const place = overlay.place === null ? "" : `<div class="ov-sub" style="font-size:${overlay.placeFontSize}px">${escapeHtml(overlay.place)}</div>`;
245
- return { classes: `ov-date${overlay.side === "right" ? " right" : ""}`, body: `<div class="ov-card"__STYLE__><span>${typedOrPlain(overlay.text)}</span>${place}</div>`, typed: [...overlay.text].length };
334
+ return { classes: `ov-date${overlay.side === "right" ? " right" : ""}`, body: `<div class="ov-card"__STYLE__>__WIPE__<span>${typedOrPlain(overlay.text)}</span>${place}</div>`, typed: [...overlay.text].length };
246
335
  }
247
336
 
248
337
  /** A hook title, a search bar, a place card, a counter or a date stamp. */
@@ -251,10 +340,12 @@ function addCard(overlay: CardOverlay, id: string, context: MarkupContext, out:
251
340
  const { box, fontSize } = overlay;
252
341
  const { classes, body, typed } = getCardBody(overlay, id, colors, context.locale);
253
342
  const style = `left:${box.left}px;top:${box.top}px;width:${box.width}px;height:${box.height}px;font-size:${fontSize}px;align-items:flex-start`;
254
- out.html.push(clipDiv(overlay, id, `ov ${classes}${overlay.typing === null ? "" : " ty"}`, style, body.replace("__STYLE__", getCardStyle(overlay, colors, context.scale))));
343
+ const wipe = overlay.entrance === "wipe" ? `<i class="ov-wipe" id="${id}w"></i>` : "";
344
+ out.html.push(clipDiv(overlay, id, `ov ${classes}${overlay.typing === null ? "" : " ty"}`, style, body.replace("__STYLE__", getCardStyle(overlay, colors, context.scale)).replace("__WIPE__", wipe)));
255
345
  const entrance = overlay.entrance ?? (overlay.typing !== null ? "type" : DEFAULT_ENTRANCES[overlay.kind]);
256
- out.tweens.push(...getEntranceTweens(`#${id} .ov-card`, entrance, overlay.start));
346
+ out.tweens.push(...getEntranceTweens(`#${id} .ov-card`, entrance, overlay.start, { ...(overlay.easing === undefined ? {} : { easing: overlay.easing }), frame: context.frame }));
257
347
  out.tweens.push(...getTypingTweens(id, overlay, typed));
348
+ if (overlay.kind === "place_card") out.tweens.push(...getPlaceCardPartTweens(overlay, id, context));
258
349
  if (overlay.kind === "counter") {
259
350
  const count = getCounterSeconds(overlay);
260
351
  const format = `new Intl.NumberFormat(${toScriptString(getScriptLocale(context.locale))}, { minimumFractionDigits: ${overlay.decimals}, maximumFractionDigits: ${overlay.decimals} })`;
@@ -263,7 +354,37 @@ function addCard(overlay: CardOverlay, id: string, context: MarkupContext, out:
263
354
  `(function () { const el = document.getElementById("${id}n"); const nf = ${format}; const n = { v: ${overlay.from} }; tl.fromTo(n, { v: ${overlay.from} }, { v: ${overlay.value}, duration: ${count.duration}, ease: "power2.out", immediateRender: false, onUpdate: () => { el.textContent = nf.format(n.v).replace(/[\\u00a0\\u202f]/g, " "); } }, ${count.start}); })();`,
264
355
  );
265
356
  }
266
- out.tweens.push(`tl.to("#${id} .ov-card", { y: 10, opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${r3(overlay.end - EXIT_SECONDS)});`);
357
+ out.tweens.push(...getExitTweens(`#${id} .ov-card`, overlay, context.frame, `tl.to("#${id} .ov-card", { y: 10, opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${r3(overlay.end - EXIT_SECONDS)});`));
358
+ }
359
+
360
+ /**
361
+ * A place card's parts that come in after its card: its pin dropping a little onto its place (eased out, no bounce),
362
+ * its title once the pin is there, and its subtitle after its delay; the film seconds of each in `getPlaceCardTimes`.
363
+ */
364
+ function getPlaceCardPartTweens(overlay: Extract<ResolvedOverlay, { kind: "place_card" }>, id: string, context: MarkupContext): string[] {
365
+ const times = getPlaceCardTimes(overlay);
366
+ const tweens: string[] = [];
367
+ if (overlay.pin === "drop") {
368
+ const drop = r3(getPlaceCardPinSize(overlay.fontSize) * PIN_DROP_SHARE);
369
+ tweens.push(`tl.fromTo("#${id}p svg", { opacity: 0, y: -${drop} }, { opacity: 1, y: 0, duration: ${PIN_DROP_SECONDS}, ease: "power2.out", immediateRender: false }, ${overlay.start});`);
370
+ }
371
+ if (overlay.pin !== undefined && overlay.typing === null) {
372
+ tweens.push(`tl.fromTo("#${id} .ov-line", { opacity: 0 }, { opacity: 1, duration: 0.3, ease: "power2.out", immediateRender: false }, ${times.title});`);
373
+ }
374
+ if (times.subtitle !== null && overlay.subtitleDelay !== undefined) {
375
+ tweens.push(`tl.fromTo("#${id} .ov-sub", { opacity: 0, y: ${r3(8 * context.scale)} }, { opacity: 1, y: 0, duration: 0.3, ease: "power2.out", immediateRender: false }, ${times.subtitle});`);
376
+ }
377
+ return tweens;
378
+ }
379
+
380
+ /** When a place card's pin, title and subtitle come in, in film seconds: pin first, then the title, then the subtitle. */
381
+ export function getPlaceCardTimes(overlay: Pick<Extract<ResolvedOverlay, { kind: "place_card" }>, "start" | "pin" | "typing" | "subtitle" | "subtitleDelay">): {
382
+ pin: number | null;
383
+ title: number;
384
+ subtitle: number | null;
385
+ } {
386
+ const title = overlay.pin !== undefined && overlay.typing === null ? r3(overlay.start + PIN_TITLE_LEAD) : overlay.start;
387
+ return { pin: overlay.pin === undefined ? null : overlay.start, title, subtitle: overlay.subtitle === null ? null : r3(title + (overlay.subtitleDelay ?? 0)) };
267
388
  }
268
389
 
269
390
  /** The brand's locale as a canonical BCP 47 tag (letters, digits and dashes only), `en-US` when it is not one. */
@@ -313,8 +434,8 @@ function addMark(overlay: Extract<ResolvedOverlay, { kind: "arrow" | "highlight"
313
434
  out.tweens.push(`tl.fromTo("#${id}f", { opacity: 0 }, { opacity: 1, duration: 0.3, ease: "none", immediateRender: false }, ${r3(overlay.start + 0.3)});`);
314
435
  }
315
436
  }
316
- if (overlay.entrance === "fade") out.tweens.push(...getEntranceTweens(`#${id} .ov-svg`, "fade", overlay.start));
317
- out.tweens.push(`tl.to("#${id} .ov-svg", { opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${r3(overlay.end - EXIT_SECONDS)});`);
437
+ if (overlay.entrance === "fade") out.tweens.push(...getEntranceTweens(`#${id} .ov-svg`, "fade", overlay.start, { ...(overlay.easing === undefined ? {} : { easing: overlay.easing }), frame }));
438
+ out.tweens.push(...getExitTweens(`#${id} .ov-svg`, overlay, frame, `tl.to("#${id} .ov-svg", { opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${r3(overlay.end - EXIT_SECONDS)});`));
318
439
  }
319
440
 
320
441
  /**
@@ -0,0 +1,157 @@
1
+ import type { OverlayEasing, OverlayEntrance, OverlayExit } from "./overlay-schema.js";
2
+
3
+ /**
4
+ * How a drawn overlay moves in and out (RV-133 of an adopting app): one model the render's GSAP tweens and the draft's
5
+ * ASS tags both read, so the two stay one look. Every curve eases out without overshoot: a value travels from its
6
+ * start to its rest and never past it, so no element grows past 100 % (`getEntranceScaleAt`). No bounce, no elastic.
7
+ */
8
+
9
+ /** A GSAP ease name and its curve: each one rises from 0 to 1 and never passes 1. */
10
+ export const OVERLAY_EASES = {
11
+ "power2.out": (t: number) => 1 - (1 - t) ** 2,
12
+ "power3.out": (t: number) => 1 - (1 - t) ** 3,
13
+ "expo.out": (t: number) => (t >= 1 ? 1 : 1 - 2 ** (-10 * t)),
14
+ "power2.in": (t: number) => t ** 2,
15
+ } as const;
16
+
17
+ export type OverlayEase = keyof typeof OVERLAY_EASES;
18
+
19
+ /** How far from its rest an overlay starts or ends: its opacity, its scale, px below its place, px of blur. */
20
+ export interface OverlayMotionOffset {
21
+ opacity: number;
22
+ scale: number;
23
+ y: number;
24
+ blur: number;
25
+ }
26
+
27
+ /** A tweened entrance: from `from` to rest over `seconds` along `ease`. */
28
+ export interface OverlayTween {
29
+ from: OverlayMotionOffset;
30
+ seconds: number;
31
+ ease: OverlayEase;
32
+ }
33
+
34
+ /** The entrance of an overlay: tweened, a wipe (accent in, then the card and its text), or none (simply there). */
35
+ export type OverlayEntranceMotion = ({ kind: "tween" } & OverlayTween) | { kind: "wipe"; seconds: number; ease: OverlayEase } | { kind: "none" };
36
+
37
+ /** The exit of an overlay: tweened to `from` over its last `seconds`, wiped off to the right, the kind's own, or none. */
38
+ export type OverlayExitMotion = ({ kind: "tween" } & OverlayTween) | { kind: "wipe"; seconds: number; ease: OverlayEase } | { kind: "own" } | { kind: "none" };
39
+
40
+ /** A pop's start scale: 92 % of its size. */
41
+ export const POP_FROM_SCALE = 0.92;
42
+ /** A pop's exit scale: it shrinks to 96 % as it fades. */
43
+ const POP_EXIT_SCALE = 0.96;
44
+ /** A rise starts this share of the frame's height below its place (4 to 6 %). */
45
+ export const RISE_FROM_HEIGHT = 0.05;
46
+ /** A blur's start, in px of a 1080 px wide frame. */
47
+ export const BLUR_FROM_PX = 14;
48
+ /** A slide's start below its place, in px of a 1080 px wide frame. */
49
+ const SLIDE_FROM_PX = 28;
50
+ /** A slide exit's travel down, in px of a 1080 px wide frame. */
51
+ const SLIDE_EXIT_PX = 14;
52
+ /** The seconds of an exit (smooth). */
53
+ export const OVERLAY_EXIT_SECONDS = 0.3;
54
+ /** How much quicker a snappy curve runs. */
55
+ const SNAPPY_SPEED = 0.7;
56
+
57
+ const REST: OverlayMotionOffset = { opacity: 1, scale: 1, y: 0, blur: 0 };
58
+ const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
59
+
60
+ /** The smooth entrances' offsets, seconds and eases; `scale` is the frame's width / 1080, `height` its height. */
61
+ function getSmoothEntrance(entrance: Exclude<OverlayEntrance, "none" | "wipe">, frame: { scale: number; height: number }): OverlayTween {
62
+ switch (entrance) {
63
+ case "fade":
64
+ return { from: { ...REST, opacity: 0 }, seconds: 0.4, ease: "power2.out" };
65
+ case "type":
66
+ return { from: { ...REST, opacity: 0 }, seconds: 0.25, ease: "power2.out" };
67
+ case "slide":
68
+ return { from: { ...REST, opacity: 0, y: r3(SLIDE_FROM_PX * frame.scale) }, seconds: 0.5, ease: "power3.out" };
69
+ case "pop":
70
+ return { from: { ...REST, opacity: 0, scale: POP_FROM_SCALE }, seconds: 0.3, ease: "power2.out" };
71
+ case "rise":
72
+ return { from: { ...REST, opacity: 0, y: r3(RISE_FROM_HEIGHT * frame.height) }, seconds: 0.3, ease: "power3.out" };
73
+ case "blur":
74
+ return { from: { ...REST, opacity: 0, blur: r3(BLUR_FROM_PX * frame.scale) }, seconds: 0.3, ease: "power2.out" };
75
+ }
76
+ }
77
+
78
+ /** A curve's seconds and ease for the easing: snappy runs 0.7 as long on `expo.out`. */
79
+ function withEasing<T extends { seconds: number; ease: OverlayEase }>(motion: T, easing: OverlayEasing): T {
80
+ return easing === "snappy" ? { ...motion, seconds: r3(motion.seconds * SNAPPY_SPEED), ease: "expo.out" } : motion;
81
+ }
82
+
83
+ /** An overlay's entrance motion: `entrance` already resolved to a named one (the kind's own when the overlay names none). */
84
+ export function getEntranceMotion(entrance: OverlayEntrance, easing: OverlayEasing, frame: { width: number; height: number }): OverlayEntranceMotion {
85
+ if (entrance === "none") return { kind: "none" };
86
+ if (entrance === "wipe") return withEasing({ kind: "wipe" as const, seconds: 0.5, ease: "power3.out" }, easing);
87
+ return withEasing({ kind: "tween" as const, ...getSmoothEntrance(entrance, { scale: frame.width / 1080, height: frame.height }) }, easing);
88
+ }
89
+
90
+ /**
91
+ * An overlay's exit motion. `auto` mirrors its named entrance: a fade, a typed or a slid entrance leave by fading or
92
+ * sliding down; a pop shrinks to 96 % as it fades; a rise sinks half its way; a blur blurs; a wipe is wiped off to the
93
+ * right; no entrance (`entrance` null) or `none` leave the kind's own way (`own`), as before RV-133. Only `exit: none`
94
+ * leaves at once.
95
+ */
96
+ export function getExitMotion(input: { exit: OverlayExit; entrance: OverlayEntrance | null; easing: OverlayEasing; frame: { width: number; height: number } }): OverlayExitMotion {
97
+ const { exit, entrance, easing, frame } = input;
98
+ const scale = frame.width / 1080;
99
+ const fade: OverlayTween = { from: { ...REST, opacity: 0 }, seconds: OVERLAY_EXIT_SECONDS, ease: "power2.in" };
100
+ const slide: OverlayTween = { ...fade, from: { ...fade.from, y: r3(SLIDE_EXIT_PX * scale) } };
101
+ const tween = (motion: OverlayTween): OverlayExitMotion => ({ kind: "tween", ...withEasing(motion, easing), ease: easing === "snappy" ? "power2.in" : motion.ease });
102
+ if (exit === "none") return { kind: "none" };
103
+ if (exit === "fade") return tween(fade);
104
+ if (exit === "slide") return tween(slide);
105
+ switch (entrance) {
106
+ case null:
107
+ case "none":
108
+ return { kind: "own" };
109
+ case "fade":
110
+ case "type":
111
+ return tween(fade);
112
+ case "slide":
113
+ return tween(slide);
114
+ case "pop":
115
+ return tween({ ...fade, from: { ...fade.from, scale: POP_EXIT_SCALE } });
116
+ case "rise":
117
+ return tween({ ...fade, from: { ...fade.from, y: r3((RISE_FROM_HEIGHT / 2) * frame.height) } });
118
+ case "blur":
119
+ return tween({ ...fade, from: { ...fade.from, blur: r3((BLUR_FROM_PX / 1.4) * scale) } });
120
+ case "wipe":
121
+ return { kind: "wipe", seconds: easing === "snappy" ? r3(OVERLAY_EXIT_SECONDS * SNAPPY_SPEED) : OVERLAY_EXIT_SECONDS, ease: "power2.in" };
122
+ }
123
+ }
124
+
125
+ /** The scale an entrance gives `seconds` after it starts: from its start scale up to 1, never past it. */
126
+ export function getEntranceScaleAt(motion: OverlayEntranceMotion, seconds: number): number {
127
+ if (motion.kind !== "tween") return 1;
128
+ const progress = Math.min(1, Math.max(0, seconds / motion.seconds));
129
+ return motion.from.scale + (1 - motion.from.scale) * OVERLAY_EASES[motion.ease](progress);
130
+ }
131
+
132
+ /** A wipe's two halves: the accent panel grows from the left over the first, then slides off to the right over the second. */
133
+ export function getWipeHalves(seconds: number): { grow: number; reveal: number } {
134
+ return { grow: r3(seconds / 2), reveal: r3(seconds / 2) };
135
+ }
136
+
137
+ /** A place card's pin drops this share of its own size before it stops, over these seconds. */
138
+ export const PIN_DROP_SHARE = 0.6;
139
+ export const PIN_DROP_SECONDS = 0.35;
140
+ /** A place card's title follows its pin by this long, so the pin comes first. */
141
+ export const PIN_TITLE_LEAD = 0.2;
142
+ /** A keyword's underline is drawn over these seconds, after its entrance. */
143
+ export const UNDERLINE_SECONDS = 0.35;
144
+ /** A keyword's underline: its thickness and its gap under the text, in em of the keyword. */
145
+ export const UNDERLINE_EM = { height: 0.09, gap: 0.05 } as const;
146
+
147
+ /**
148
+ * The film seconds each point of a staggered list comes in at: on its word (`words`, the said times, never before the
149
+ * list nor later than its last 0.6 s), else spaced over the first part of its span (0.25 to 0.6 s apart).
150
+ */
151
+ export function getListItemStarts(input: { start: number; end: number; count: number; words?: readonly number[] }): number[] {
152
+ const { start, end, count } = input;
153
+ const latest = Math.max(start, end - 0.6);
154
+ if (input.words !== undefined) return input.words.map((word) => r3(Math.min(latest, Math.max(start, word))));
155
+ const gap = Math.min(0.6, Math.max(0.25, ((end - start) * 0.4) / count));
156
+ return Array.from({ length: count }, (_item, index) => r3(Math.min(latest, start + 0.2 + index * gap)));
157
+ }