@softure-ai/marketing-kit 0.23.0 → 0.25.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 (59) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +23 -0
  3. package/dist/footage/captions.d.ts +8 -1
  4. package/dist/footage/captions.d.ts.map +1 -1
  5. package/dist/footage/captions.js +5 -3
  6. package/dist/footage/captions.js.map +1 -1
  7. package/dist/footage/compose.d.ts +2 -0
  8. package/dist/footage/compose.d.ts.map +1 -1
  9. package/dist/footage/compose.js +3 -2
  10. package/dist/footage/compose.js.map +1 -1
  11. package/dist/footage/draft-overlays.d.ts +21 -4
  12. package/dist/footage/draft-overlays.d.ts.map +1 -1
  13. package/dist/footage/draft-overlays.js +242 -36
  14. package/dist/footage/draft-overlays.js.map +1 -1
  15. package/dist/footage/draft.d.ts +7 -2
  16. package/dist/footage/draft.d.ts.map +1 -1
  17. package/dist/footage/draft.js +13 -2
  18. package/dist/footage/draft.js.map +1 -1
  19. package/dist/footage/edl.d.ts +27 -0
  20. package/dist/footage/edl.d.ts.map +1 -1
  21. package/dist/footage/edl.js +1 -1
  22. package/dist/footage/edl.js.map +1 -1
  23. package/dist/footage/overlay-html.d.ts +21 -1
  24. package/dist/footage/overlay-html.d.ts.map +1 -1
  25. package/dist/footage/overlay-html.js +217 -56
  26. package/dist/footage/overlay-html.js.map +1 -1
  27. package/dist/footage/overlay-schema.d.ts +98 -6
  28. package/dist/footage/overlay-schema.d.ts.map +1 -1
  29. package/dist/footage/overlay-schema.js +215 -45
  30. package/dist/footage/overlay-schema.js.map +1 -1
  31. package/dist/footage/overlays.d.ts +121 -16
  32. package/dist/footage/overlays.d.ts.map +1 -1
  33. package/dist/footage/overlays.js +323 -52
  34. package/dist/footage/overlays.js.map +1 -1
  35. package/dist/footage/pipeline.d.ts +5 -0
  36. package/dist/footage/pipeline.d.ts.map +1 -1
  37. package/dist/footage/pipeline.js +3 -2
  38. package/dist/footage/pipeline.js.map +1 -1
  39. package/dist/index.d.ts +2 -2
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +2 -2
  42. package/dist/index.js.map +1 -1
  43. package/dist/render/render.d.ts +4 -1
  44. package/dist/render/render.d.ts.map +1 -1
  45. package/dist/render/render.js +2 -1
  46. package/dist/render/render.js.map +1 -1
  47. package/package.json +1 -1
  48. package/schema/edl.schema.json +90 -8
  49. package/src/footage/captions.ts +13 -4
  50. package/src/footage/compose.ts +5 -3
  51. package/src/footage/draft-overlays.ts +291 -37
  52. package/src/footage/draft.ts +20 -4
  53. package/src/footage/edl.ts +1 -1
  54. package/src/footage/overlay-html.ts +239 -59
  55. package/src/footage/overlay-schema.ts +245 -40
  56. package/src/footage/overlays.ts +387 -55
  57. package/src/footage/pipeline.ts +8 -3
  58. package/src/index.ts +27 -0
  59. package/src/render/render.ts +3 -2
@@ -1,15 +1,18 @@
1
1
  import type { BrandColors } from "../config/colors.js";
2
2
  import { escapeHtml } from "../compose/html.js";
3
- import { OVERLAY_LINE_HEIGHT, OVERLAY_LIST_LINE_HEIGHT, OVERLAY_PADDING_EM, type ResolvedOverlay } from "./overlays.js";
3
+ import type { OverlayEntrance } from "./overlay-schema.js";
4
+ import { OVERLAY_LINE_HEIGHT, OVERLAY_LIST_LINE_HEIGHT, OVERLAY_PADDING_EM, OVERLAY_TITLE_LINE_HEIGHT, SEARCH_BAR_PADDING_EM, formatOverlayNumber, type ResolvedOverlay } from "./overlays.js";
4
5
 
5
6
  /**
6
7
  * The render's overlays (issue #1200): HTML, CSS and GSAP tweens for the HyperFrames composition, every look in the
7
- * brand's colours and fonts and every element a local clip (no network at render time).
8
+ * brand's colours and fonts (or the overlay's own colours) and every element a local clip (no network at render time).
8
9
  *
9
10
  * The motion is adapted from HyperFrames registry blocks (Apache-2.0, https://github.com/heygen-com/hyperframes):
10
11
  * `lt-soft-pill` (the lower third's scale-pop pill, dot and settling text), `marker-highlight` (the stroke drawn over
11
12
  * its target), `hw-arrow` (the drawn-on arrow whose head arrives last) and `push-in` (the eased camera push, in
12
- * `composeFootage`). They are rewritten for the kit's frame, timeline and brand tokens: see the package's NOTICE.
13
+ * `composeFootage`). They are rewritten for the kit's frame, timeline and brand tokens: see the package's NOTICE. The
14
+ * entrances (`fade`, `slide`, `type`, `none`), the typed search field, the counting number and the drawn pin are the
15
+ * kit's own, eased without overshoot.
13
16
  */
14
17
 
15
18
  /** The seconds an overlay takes to leave, ending with its clip. */
@@ -18,6 +21,10 @@ const EXIT_SECONDS = 0.3;
18
21
  const STROKE_WIDTH = 10;
19
22
  /** The arrow head's length, in px of a 1080 px wide frame. */
20
23
  const ARROW_HEAD = 46;
24
+ /** When a typed overlay starts typing, after its card has faded in, in seconds from its start. */
25
+ export const OVERLAY_TYPING_DELAY = 0.3;
26
+ /** When a counter starts counting, in seconds from its start. */
27
+ const COUNT_DELAY = 0.15;
21
28
 
22
29
  const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
23
30
 
@@ -30,18 +37,50 @@ export interface OverlayMarkup {
30
37
  /** The brand's colours an overlay paints with: its card, its text, its accent (the dot, the arrow, the marker). */
31
38
  export type OverlayColors = Pick<BrandColors, "background" | "foreground" | "accent">;
32
39
 
40
+ /** An overlay's colours: its own where it sets them, else the brand's. */
41
+ export function getOverlayColors(overlay: ResolvedOverlay, brand: OverlayColors): OverlayColors {
42
+ const own = overlay.kind === "punch_in" ? {} : overlay.colors;
43
+ return { background: own.card ?? brand.background, foreground: own.text ?? brand.foreground, accent: own.accent ?? brand.accent };
44
+ }
45
+
46
+ /** The seconds a counter counts over (from `COUNT_DELAY` after its start): half its span, between 0.6 and 1.6 s. */
47
+ export function getCounterSeconds(overlay: { start: number; end: number }): { start: number; duration: number } {
48
+ return { start: r3(overlay.start + COUNT_DELAY), duration: r3(Math.min(1.6, Math.max(0.6, (overlay.end - overlay.start) * 0.5))) };
49
+ }
50
+
51
+ /** The film seconds each character of a typed text appears at, from `OVERLAY_TYPING_DELAY` after the overlay's start. */
52
+ export function getTypingTimes(start: number, text: string, speed: number): number[] {
53
+ return [...text].map((_char, index) => r3(start + OVERLAY_TYPING_DELAY + index / speed));
54
+ }
55
+
33
56
  /** The CSS every overlay kind shares, written once when the film has any drawn overlay. */
34
- function getOverlayCss(colors: OverlayColors, headingFont: string): string[] {
57
+ function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interface: string }): string[] {
35
58
  return [
36
59
  `.ov{position:absolute;display:flex;pointer-events:none}`,
37
60
  `.ov.right{justify-content:flex-end}`,
38
- `.ov-card{display:flex;align-items:center;gap:.45em;padding:${OVERLAY_PADDING_EM.y}em ${OVERLAY_PADDING_EM.x}em;border-radius:.42em;background:${colors.background};color:${colors.foreground};box-shadow:0 14px 44px rgba(0,0,0,.35);line-height:${OVERLAY_LINE_HEIGHT};font-weight:700;letter-spacing:-.015em;max-width:100%;overflow-wrap:anywhere;transform-origin:0% 100%}`,
61
+ `.ov.center{justify-content:center}`,
62
+ `.ov-card{display:flex;align-items:center;gap:.45em;padding:${OVERLAY_PADDING_EM.y}em ${OVERLAY_PADDING_EM.x}em;border-radius:.42em;background:${colors.background};color:${colors.foreground};box-shadow:0 14px 44px rgba(0,0,0,.35);line-height:${OVERLAY_LINE_HEIGHT};font-family:${fonts.interface};font-weight:700;letter-spacing:-.015em;max-width:100%;overflow-wrap:anywhere;transform-origin:0% 100%}`,
39
63
  `.ov.right .ov-card{transform-origin:100% 100%}`,
40
- `.ov-keyword .ov-card{font-family:${headingFont};border-bottom:.12em solid ${colors.accent}}`,
64
+ `.ov-keyword .ov-card{font-family:${fonts.heading};border-bottom:.12em solid ${colors.accent}}`,
41
65
  `.ov-dot{flex:none;width:.36em;height:.36em;border-radius:50%;background:${colors.accent}}`,
42
66
  `.ov-list .ov-card{flex-direction:column;align-items:flex-start;gap:0;line-height:${OVERLAY_LIST_LINE_HEIGHT};font-weight:650}`,
43
67
  `.ov-list li{display:flex;align-items:center;gap:.45em;list-style:none}`,
44
68
  `.ov-svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible}`,
69
+ `.ov-search,.ov-counter .ov-card,.ov-date .ov-card,.ov-place,.ov-sub,.ov-line{white-space:nowrap}`,
70
+ `.ov-stack{flex-direction:column;gap:0;text-align:center;transform-origin:50% 0%}`,
71
+ `.ov-hook-title .ov-line{font-family:${fonts.heading};font-weight:800;letter-spacing:-.02em}`,
72
+ `.ov-place{display:flex;align-items:center;justify-content:center;gap:.25em;font-weight:650;opacity:.92;margin-bottom:.12em}`,
73
+ `.ov-pin{flex:none;width:1.05em;height:1.05em}`,
74
+ `.ov-place-card .ov-line{font-family:${fonts.heading};font-weight:800;line-height:${OVERLAY_TITLE_LINE_HEIGHT};letter-spacing:-.025em}`,
75
+ `.ov-sub{font-weight:600;opacity:.88;margin-top:.12em}`,
76
+ `.ov-search{width:100%;border-radius:999px;padding:${SEARCH_BAR_PADDING_EM.y}em ${SEARCH_BAR_PADDING_EM.x}em;gap:.5em;font-weight:600;letter-spacing:0;justify-content:flex-start;transform-origin:50% 50%}`,
77
+ `.ov-glass{flex:none;width:1em;height:1em}`,
78
+ `.ov-counter .ov-card{font-family:${fonts.heading};font-weight:800;align-items:baseline;gap:.3em;font-variant-numeric:tabular-nums;transform-origin:50% 50%}`,
79
+ `.ov-date .ov-card{flex-direction:column;gap:0;font-weight:800}`,
80
+ `.ov-date.right .ov-card{align-items:flex-end}`,
81
+ `.ov-date:not(.right) .ov-card{align-items:flex-start}`,
82
+ `.ov-date .ov-sub{font-weight:600;margin-top:0}`,
83
+ `.ty .ch{opacity:0}`,
45
84
  ];
46
85
  }
47
86
 
@@ -64,64 +103,205 @@ export function getArrowPaths(overlay: Extract<ResolvedOverlay, { kind: "arrow"
64
103
  };
65
104
  }
66
105
 
106
+ /** A map pin drawn in the accent: a rounded drop with a hole, one line of the label tall. */
107
+ function getPinSvg(accent: string): string {
108
+ return `<svg class="ov-pin" viewBox="0 0 24 24"><path fill="${accent}" fill-rule="evenodd" d="M12 1.5c-4.3 0-7.75 3.4-7.75 7.6 0 5.6 7.75 13.4 7.75 13.4s7.75-7.8 7.75-13.4c0-4.2-3.45-7.6-7.75-7.6zm0 10.6a3 3 0 1 1 0-6 3 3 0 0 1 0 6z"/></svg>`;
109
+ }
110
+
111
+ /** A magnifier drawn in the accent. */
112
+ function getGlassSvg(accent: string): string {
113
+ return `<svg class="ov-glass" viewBox="0 0 24 24"><circle cx="10" cy="10" r="6.6" fill="none" stroke="${accent}" stroke-width="2.6"/><path d="M15 15l6 6" stroke="${accent}" stroke-width="2.6" stroke-linecap="round"/></svg>`;
114
+ }
115
+
116
+ /** A text as one span per character, for the typed entrance (spaces kept). */
117
+ function toTypedHtml(text: string): string {
118
+ return [...text].map((char) => `<span class="ch">${char === " " ? "&#32;" : escapeHtml(char)}</span>`).join("");
119
+ }
120
+
121
+ /** The inline colours of a card that has its own. */
122
+ function getCardStyle(overlay: ResolvedOverlay, colors: OverlayColors): string {
123
+ if (overlay.kind === "punch_in") return "";
124
+ const own = overlay.colors;
125
+ const parts = [own.card === undefined ? "" : `background:${colors.background}`, own.text === undefined ? "" : `color:${colors.foreground}`];
126
+ if (overlay.kind === "keyword" && own.accent !== undefined) parts.push(`border-bottom-color:${colors.accent}`);
127
+ const style = parts.filter((part) => part !== "").join(";");
128
+ return style === "" ? "" : ` style="${style}"`;
129
+ }
130
+
131
+ /** The entrance tweens of a card: fade, slide, a typed card's fade, or nothing. */
132
+ function getEntranceTweens(target: string, entrance: OverlayEntrance, start: number): string[] {
133
+ if (entrance === "none") return [];
134
+ if (entrance === "slide") return [`tl.fromTo("${target}", { opacity: 0, y: 28 }, { opacity: 1, y: 0, duration: 0.5, ease: "power3.out", immediateRender: false }, ${start});`];
135
+ const duration = entrance === "type" ? 0.25 : 0.4;
136
+ return [`tl.fromTo("${target}", { opacity: 0 }, { opacity: 1, duration: ${duration}, ease: "power2.out", immediateRender: false }, ${start});`];
137
+ }
138
+
139
+ /** The typing tweens: each character of `#<id>` shown at its time. */
140
+ function getTypingTweens(id: string, overlay: { start: number; typing: number | null }, length: number): string[] {
141
+ if (overlay.typing === null || length === 0) return [];
142
+ return [`tl.to("#${id} .ch", { opacity: 1, duration: 0.01, ease: "none", stagger: ${r3(1 / overlay.typing)} }, ${r3(overlay.start + OVERLAY_TYPING_DELAY)});`];
143
+ }
144
+
145
+ /** Each new kind's own entrance when the overlay names none. */
146
+ const DEFAULT_ENTRANCES = { hook_title: "slide", search_bar: "fade", place_card: "slide", counter: "fade", date_stamp: "fade" } as const;
147
+
148
+ interface MarkupContext {
149
+ colors: OverlayColors;
150
+ scale: number;
151
+ locale: string;
152
+ frame: { width: number; height: number };
153
+ }
154
+
155
+ /** A keyword, a lower third or a list, entering as the soft pill (or by its own entrance). */
156
+ function addSideText(overlay: Extract<ResolvedOverlay, { kind: "keyword" | "lower_third" | "list" }>, id: string, context: MarkupContext, out: OverlayMarkup): void {
157
+ const { box, fontSize, side } = overlay;
158
+ const colors = getOverlayColors(overlay, context.colors);
159
+ const cardStyle = getCardStyle(overlay, colors);
160
+ const dotStyle = overlay.colors.accent === undefined ? "" : ` style="background:${colors.accent}"`;
161
+ const isTyped = overlay.typing !== null && overlay.kind !== "list";
162
+ 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"}`;
163
+ const text = overlay.kind === "list" ? "" : isTyped ? toTypedHtml(overlay.text) : escapeHtml(overlay.text);
164
+ const body =
165
+ overlay.kind === "list"
166
+ ? `<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>`
167
+ : `<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>`;
168
+ out.html.push(clipDiv(overlay, id, `ov ov-${overlay.kind.replace("_", "-")}${side === "right" ? " right" : ""}${isTyped ? " ty" : ""}`, style, body));
169
+ if (overlay.entrance !== null) {
170
+ out.tweens.push(...getEntranceTweens(`#${id} .ov-card`, overlay.entrance, overlay.start));
171
+ if (overlay.kind !== "list") out.tweens.push(...getTypingTweens(id, overlay, [...overlay.text].length));
172
+ } else {
173
+ // The soft pill's entrance: the card rises from its foot, then its dot and its text settle in.
174
+ 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});`);
175
+ if (overlay.kind === "lower_third") {
176
+ 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)});`);
177
+ 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)});`);
178
+ }
179
+ if (overlay.kind === "list") {
180
+ overlay.items.forEach((_item, i) => {
181
+ 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)});`);
182
+ });
183
+ }
184
+ }
185
+ 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)});`);
186
+ }
187
+
188
+ type CardOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "search_bar" | "place_card" | "counter" | "date_stamp" }>;
189
+
190
+ /** The inner HTML of a card kind, and how many characters it types in. */
191
+ function getCardBody(overlay: CardOverlay, id: string, colors: OverlayColors, locale: string): { classes: string; body: string; typed: number } {
192
+ const typedOrPlain = (text: string) => (overlay.typing === null ? escapeHtml(text) : toTypedHtml(text));
193
+ if (overlay.kind === "hook_title") {
194
+ const place = overlay.place === null ? "" : `<div class="ov-place" style="font-size:${overlay.placeFontSize}px">${getPinSvg(colors.accent)}<span>${escapeHtml(overlay.place)}</span></div>`;
195
+ const lines = overlay.lines.map((line) => `<div class="ov-line">${typedOrPlain(line)}</div>`).join("");
196
+ return { classes: "ov-hook-title center", body: `<div class="ov-card ov-stack"__STYLE__>${place}${lines}</div>`, typed: overlay.lines.join("").length };
197
+ }
198
+ if (overlay.kind === "place_card") {
199
+ const subtitle = overlay.subtitle === null ? "" : `<div class="ov-sub" style="font-size:${overlay.subtitleFontSize}px">${escapeHtml(overlay.subtitle)}</div>`;
200
+ const lines = overlay.lines.map((line) => `<div class="ov-line">${typedOrPlain(line)}</div>`).join("");
201
+ return { classes: "ov-place-card center", body: `<div class="ov-card ov-stack"__STYLE__>${lines}${subtitle}</div>`, typed: overlay.lines.join("").length };
202
+ }
203
+ if (overlay.kind === "search_bar") {
204
+ 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 };
205
+ }
206
+ if (overlay.kind === "counter") {
207
+ const unit = overlay.unit === null ? "" : `<span class="ov-unit" style="font-size:${overlay.unitFontSize}px">${escapeHtml(overlay.unit)}</span>`;
208
+ 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 };
209
+ }
210
+ const place = overlay.place === null ? "" : `<div class="ov-sub" style="font-size:${overlay.placeFontSize}px">${escapeHtml(overlay.place)}</div>`;
211
+ 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 };
212
+ }
213
+
214
+ /** A hook title, a search bar, a place card, a counter or a date stamp. */
215
+ function addCard(overlay: CardOverlay, id: string, context: MarkupContext, out: OverlayMarkup): void {
216
+ const colors = getOverlayColors(overlay, context.colors);
217
+ const { box, fontSize } = overlay;
218
+ const { classes, body, typed } = getCardBody(overlay, id, colors, context.locale);
219
+ 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`;
220
+ out.html.push(clipDiv(overlay, id, `ov ${classes}${overlay.typing === null ? "" : " ty"}`, style, body.replace("__STYLE__", getCardStyle(overlay, colors))));
221
+ const entrance = overlay.entrance ?? (overlay.typing !== null ? "type" : DEFAULT_ENTRANCES[overlay.kind]);
222
+ out.tweens.push(...getEntranceTweens(`#${id} .ov-card`, entrance, overlay.start));
223
+ out.tweens.push(...getTypingTweens(id, overlay, typed));
224
+ if (overlay.kind === "counter") {
225
+ const count = getCounterSeconds(overlay);
226
+ const format = `new Intl.NumberFormat(${toScriptString(getScriptLocale(context.locale))}, { minimumFractionDigits: ${overlay.decimals}, maximumFractionDigits: ${overlay.decimals} })`;
227
+ // The number eases up to its value; the timeline renders it on every seek, so each frame shows its own count.
228
+ out.tweens.push(
229
+ `(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}); })();`,
230
+ );
231
+ }
232
+ out.tweens.push(`tl.to("#${id} .ov-card", { y: 10, opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${r3(overlay.end - EXIT_SECONDS)});`);
233
+ }
234
+
235
+ /** The brand's locale as a canonical BCP 47 tag (letters, digits and dashes only), `en-US` when it is not one. */
236
+ export function getScriptLocale(locale: string | undefined): string {
237
+ try {
238
+ return Intl.getCanonicalLocales(locale ?? "en-US")[0] ?? "en-US";
239
+ } catch {
240
+ return "en-US";
241
+ }
242
+ }
243
+
244
+ /** A string as a script literal that cannot close the `<script>` element it sits in. */
245
+ function toScriptString(value: string): string {
246
+ return JSON.stringify(value).replace(/</g, "\\u003c");
247
+ }
248
+
249
+ /** An overlay's clip: shown for its own span. */
250
+ function clipDiv(overlay: ResolvedOverlay, id: string, classes: string, style: string, body: string): string {
251
+ return `<div id="${id}" class="clip ${classes}" data-start="${overlay.start}" data-duration="${r3(overlay.end - overlay.start)}" style="${style}">${body}</div>`;
252
+ }
253
+
254
+ /** An arrow drawn on from its tail, or a highlight's marker drawn round its target (or faded in, or simply there). */
255
+ function addMark(overlay: Extract<ResolvedOverlay, { kind: "arrow" | "highlight" }>, id: string, context: MarkupContext, out: OverlayMarkup): void {
256
+ const { frame, scale } = context;
257
+ const { accent } = getOverlayColors(overlay, context.colors);
258
+ const stroke = r3(STROKE_WIDTH * scale);
259
+ const view = `viewBox="0 0 ${frame.width} ${frame.height}"`;
260
+ const isDrawn = overlay.entrance === null;
261
+ const dash = isDrawn ? ` pathLength="1" stroke-dasharray="1" stroke-dashoffset="1"` : "";
262
+ if (overlay.kind === "arrow") {
263
+ const paths = getArrowPaths(overlay, scale);
264
+ const body = `<svg class="ov-svg" ${view}><path id="${id}c" d="${paths.curve}" fill="none" stroke="${accent}" stroke-width="${stroke}" stroke-linecap="round"${dash}/><path id="${id}h" d="${paths.head}" fill="none" stroke="${accent}" stroke-width="${stroke}" stroke-linecap="round" stroke-linejoin="round"${isDrawn ? ` opacity="0"` : ""}/></svg>`;
265
+ out.html.push(clipDiv(overlay, id, "ov ov-arrow", "inset:0", body));
266
+ if (isDrawn) {
267
+ // Drawn on from the tail; the head arrives as the stroke reaches the point.
268
+ out.tweens.push(`tl.fromTo("#${id}c", { attr: { "stroke-dashoffset": 1 } }, { attr: { "stroke-dashoffset": 0 }, duration: 0.45, ease: "power2.out", immediateRender: false }, ${overlay.start});`);
269
+ out.tweens.push(`tl.fromTo("#${id}h", { opacity: 0 }, { opacity: 1, duration: 0.12, ease: "none", immediateRender: false }, ${r3(overlay.start + 0.38)});`);
270
+ }
271
+ } else {
272
+ const { rect } = overlay;
273
+ const radius = r3(18 * scale);
274
+ const body = `<svg class="ov-svg" ${view}><rect x="${rect.left}" y="${rect.top}" width="${rect.width}" height="${rect.height}" rx="${radius}" fill="${accent}" fill-opacity="0.18" stroke="none" id="${id}f"${isDrawn ? ` opacity="0"` : ""}/><rect id="${id}s" x="${rect.left}" y="${rect.top}" width="${rect.width}" height="${rect.height}" rx="${radius}" fill="none" stroke="${accent}" stroke-width="${stroke}"${dash}/></svg>`;
275
+ out.html.push(clipDiv(overlay, id, "ov ov-highlight", "inset:0", body));
276
+ if (isDrawn) {
277
+ // The marker's stroke drawn round its target, the tint settling in behind it.
278
+ out.tweens.push(`tl.fromTo("#${id}s", { attr: { "stroke-dashoffset": 1 } }, { attr: { "stroke-dashoffset": 0 }, duration: 0.5, ease: "power2.inOut", immediateRender: false }, ${overlay.start});`);
279
+ out.tweens.push(`tl.fromTo("#${id}f", { opacity: 0 }, { opacity: 1, duration: 0.3, ease: "none", immediateRender: false }, ${r3(overlay.start + 0.3)});`);
280
+ }
281
+ }
282
+ if (overlay.entrance === "fade") out.tweens.push(...getEntranceTweens(`#${id} .ov-svg`, "fade", overlay.start));
283
+ out.tweens.push(`tl.to("#${id} .ov-svg", { opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${r3(overlay.end - EXIT_SECONDS)});`);
284
+ }
285
+
67
286
  /**
68
287
  * The drawn overlays' markup, CSS and tweens (a `punch_in` draws nothing: `composeFootage` zooms the picture). Each
69
- * overlay is a clip shown for its own span, entering at its start and leaving over its last 0.3 s.
288
+ * overlay is a clip shown for its own span, entering at its start and leaving over its last 0.3 s. Titles, numbers and
289
+ * keywords are drawn in `headingFont`, labels, lists, the search query and the stamp in `interfaceFont` (the body font
290
+ * without one); a counter's number is grouped as `locale` writes numbers.
70
291
  */
71
- export function getOverlayMarkup(overlays: readonly ResolvedOverlay[], input: { colors: OverlayColors; headingFont: string; frame: { width: number; height: number } }): OverlayMarkup {
72
- const drawn = overlays.filter((overlay) => overlay.kind !== "punch_in");
292
+ export function getOverlayMarkup(
293
+ overlays: readonly ResolvedOverlay[],
294
+ input: { colors: OverlayColors; headingFont: string; interfaceFont?: string; locale?: string; frame: { width: number; height: number } },
295
+ ): OverlayMarkup {
296
+ const drawn = overlays.filter((overlay): overlay is Exclude<ResolvedOverlay, { kind: "punch_in" }> => overlay.kind !== "punch_in");
73
297
  if (drawn.length === 0) return { html: [], css: [], tweens: [] };
74
- const { colors, frame } = input;
75
- const scale = frame.width / 1080;
76
- const stroke = r3(STROKE_WIDTH * scale);
77
- const html: string[] = [];
78
- const tweens: string[] = [];
298
+ const context: MarkupContext = { colors: input.colors, scale: input.frame.width / 1080, locale: input.locale ?? "en-US", frame: input.frame };
299
+ const out: OverlayMarkup = { html: [], css: getOverlayCss(input.colors, { heading: input.headingFont, interface: input.interfaceFont ?? "inherit" }), tweens: [] };
79
300
  for (const overlay of drawn) {
80
301
  const id = `ov${overlay.index}`;
81
- const duration = r3(overlay.end - overlay.start);
82
- const exitAt = r3(overlay.end - EXIT_SECONDS);
83
- const clip = (classes: string, style: string, body: string) =>
84
- `<div id="${id}" class="clip ${classes}" data-start="${overlay.start}" data-duration="${duration}" style="${style}">${body}</div>`;
85
- if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") {
86
- const { box, fontSize, side } = overlay;
87
- 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"}`;
88
- const body =
89
- overlay.kind === "list"
90
- ? `<ul class="ov-card">${overlay.items.map((item, i) => `<li id="${id}i${i}"><i class="ov-dot"></i>${escapeHtml(item)}</li>`).join("")}</ul>`
91
- : `<div class="ov-card">${overlay.kind === "lower_third" ? `<i class="ov-dot" id="${id}d"></i>` : ""}<span id="${id}t">${escapeHtml(overlay.text)}</span></div>`;
92
- html.push(clip(`ov ov-${overlay.kind.replace("_", "-")}${side === "right" ? " right" : ""}`, style, body));
93
- // The soft pill's entrance: the card pops up from its foot, then its dot and its text settle in.
94
- 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});`);
95
- if (overlay.kind === "lower_third") {
96
- tweens.push(`tl.fromTo("#${id}d", { scale: 0 }, { scale: 1, duration: 0.35, ease: "back.out(3)", immediateRender: false }, ${r3(overlay.start + 0.25)});`);
97
- 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)});`);
98
- }
99
- if (overlay.kind === "list") {
100
- overlay.items.forEach((_item, i) => {
101
- 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)});`);
102
- });
103
- }
104
- tweens.push(`tl.to("#${id} .ov-card", { scale: 0.94, y: 14, opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${exitAt});`);
105
- continue;
106
- }
107
- const view = `viewBox="0 0 ${frame.width} ${frame.height}"`;
108
- if (overlay.kind === "arrow") {
109
- const paths = getArrowPaths(overlay, scale);
110
- const body = `<svg class="ov-svg" ${view}><path id="${id}c" d="${paths.curve}" fill="none" stroke="${colors.accent}" stroke-width="${stroke}" stroke-linecap="round" pathLength="1" stroke-dasharray="1" stroke-dashoffset="1"/><path id="${id}h" d="${paths.head}" fill="none" stroke="${colors.accent}" stroke-width="${stroke}" stroke-linecap="round" stroke-linejoin="round" opacity="0"/></svg>`;
111
- html.push(clip("ov ov-arrow", "inset:0", body));
112
- // Drawn on from the tail; the head arrives as the stroke reaches the point.
113
- tweens.push(`tl.fromTo("#${id}c", { attr: { "stroke-dashoffset": 1 } }, { attr: { "stroke-dashoffset": 0 }, duration: 0.45, ease: "power2.out", immediateRender: false }, ${overlay.start});`);
114
- tweens.push(`tl.fromTo("#${id}h", { opacity: 0 }, { opacity: 1, duration: 0.12, ease: "none", immediateRender: false }, ${r3(overlay.start + 0.38)});`);
115
- } else if (overlay.kind === "highlight") {
116
- const { rect } = overlay;
117
- const radius = r3(18 * scale);
118
- const body = `<svg class="ov-svg" ${view}><rect x="${rect.left}" y="${rect.top}" width="${rect.width}" height="${rect.height}" rx="${radius}" fill="${colors.accent}" fill-opacity="0.18" stroke="none" id="${id}f" opacity="0"/><rect id="${id}s" x="${rect.left}" y="${rect.top}" width="${rect.width}" height="${rect.height}" rx="${radius}" fill="none" stroke="${colors.accent}" stroke-width="${stroke}" pathLength="1" stroke-dasharray="1" stroke-dashoffset="1"/></svg>`;
119
- html.push(clip("ov ov-highlight", "inset:0", body));
120
- // The marker's stroke drawn round its target, the tint settling in behind it.
121
- tweens.push(`tl.fromTo("#${id}s", { attr: { "stroke-dashoffset": 1 } }, { attr: { "stroke-dashoffset": 0 }, duration: 0.5, ease: "power2.inOut", immediateRender: false }, ${overlay.start});`);
122
- tweens.push(`tl.fromTo("#${id}f", { opacity: 0 }, { opacity: 1, duration: 0.3, ease: "none", immediateRender: false }, ${r3(overlay.start + 0.3)});`);
123
- }
124
- tweens.push(`tl.to("#${id} .ov-svg", { opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${exitAt});`);
302
+ if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") addSideText(overlay, id, context, out);
303
+ else if (overlay.kind === "arrow" || overlay.kind === "highlight") addMark(overlay, id, context, out);
304
+ else addCard(overlay, id, context, out);
125
305
  }
126
- return { html, css: getOverlayCss(colors, input.headingFont), tweens };
306
+ return out;
127
307
  }