@softure-ai/marketing-kit 0.27.0 → 0.28.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.
@@ -331,6 +331,23 @@
331
331
  "l",
332
332
  "pill"
333
333
  ]
334
+ },
335
+ "align": {
336
+ "description": "center (the default) or left: how a hook_title's or a place_card's lines sit in their card.",
337
+ "type": "string",
338
+ "enum": [
339
+ "center",
340
+ "left"
341
+ ]
342
+ },
343
+ "subtitle_size": {
344
+ "description": "s, m (the default, about 55 % of the title) or l: a place_card's subtitle size.",
345
+ "type": "string",
346
+ "enum": [
347
+ "s",
348
+ "m",
349
+ "l"
350
+ ]
334
351
  }
335
352
  },
336
353
  "additionalProperties": false
@@ -6,14 +6,15 @@ import {
6
6
  OVERLAY_FONT_ROLES,
7
7
  OVERLAY_LINE_HEIGHT,
8
8
  OVERLAY_LIST_LINE_HEIGHT,
9
- OVERLAY_PADDING_EM,
10
9
  OVERLAY_TITLE_LINE_HEIGHT,
11
10
  SEARCH_BAR_ICON_EM,
12
11
  SEARCH_BAR_PADDING_EM,
13
12
  estimateTextWidth,
14
13
  formatOverlayNumber,
15
14
  getDrawnOverlayCard,
15
+ getOverlayPadding,
16
16
  getSideTextLines,
17
+ getTitleContentBox,
17
18
  type OverlayBox,
18
19
  type OverlayFontRole,
19
20
  type OverlayPoint,
@@ -172,19 +173,24 @@ function getTextEvents(input: { layer: number; style: string; pos: OverlayPoint;
172
173
  });
173
174
  }
174
175
 
175
- /** The steps of a text that types in letter by letter (the rest transparent), or one step showing it all. */
176
- function getTypedSteps(text: string, span: { start: number; end: number }, typing: number | null): TextStep[] {
176
+ /**
177
+ * The steps of a text that types in letter by letter, or one step showing it all. Text anchored at its start (left or
178
+ * right aligned) keeps the rest transparent so it types in place; centred text (`isCentred`) shows only what is typed,
179
+ * so the typed part stays centred in its card while the card keeps the whole text's width (RV-131 of an adopting app:
180
+ * the typed start sat left of an empty card).
181
+ */
182
+ function getTypedSteps(text: string, span: { start: number; end: number }, typing: number | null, isCentred = false): TextStep[] {
177
183
  const clean = toAssText(text);
178
184
  if (typing === null || clean.length === 0) return [{ from: span.start, to: span.end, text: clean }];
179
185
  const chars = [...clean];
180
186
  const times = getTypingTimes(span.start, clean, typing).map((time) => Math.min(time, span.end));
181
- const steps: TextStep[] = [{ from: span.start, to: times[0] as number, text: `${HIDDEN}${clean}` }];
187
+ const steps: TextStep[] = isCentred ? [] : [{ from: span.start, to: times[0] as number, text: `${HIDDEN}${clean}` }];
182
188
  times.forEach((time, index) => {
183
189
  const shown = chars.slice(0, index + 1).join("");
184
190
  const rest = chars.slice(index + 1).join("");
185
- steps.push({ from: time, to: times[index + 1] ?? span.end, text: rest.length === 0 ? shown : `${shown}${HIDDEN}${rest}` });
191
+ steps.push({ from: time, to: times[index + 1] ?? span.end, text: rest.length === 0 || isCentred ? shown.trimEnd() : `${shown}${HIDDEN}${rest}` });
186
192
  });
187
- return steps.filter((step) => step.to > step.from);
193
+ return steps.filter((step) => step.to > step.from && step.text.length > 0);
188
194
  }
189
195
 
190
196
  /** The colour and font override tags of an overlay's text: only what differs from the style. */
@@ -233,8 +239,7 @@ function getSideTextEvents(overlay: Extract<ResolvedOverlay, { kind: "keyword" |
233
239
  const { fontSize, side } = overlay;
234
240
  // A side text always has a card: only a punch_in has none.
235
241
  const card = getDrawnOverlayCard(overlay) as OverlayBox;
236
- const padX = r0(fontSize * OVERLAY_PADDING_EM.x);
237
- const padY = r0(fontSize * OVERLAY_PADDING_EM.y);
242
+ const { x: padX, y: padY } = getOverlayPadding(overlay);
238
243
  const isRight = side === "right";
239
244
  const x = isRight ? card.left + card.width - padX : card.left + padX;
240
245
  const isFoot = overlay.kind === "lower_third";
@@ -276,19 +281,23 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
276
281
  const slidePx = SLIDE_PX * context.scale;
277
282
  const span = { start: overlay.start, end: overlay.end };
278
283
  const events = getCardShapeEvents(overlay, box, fontSize, colors, entrance, context);
279
- const padX = r0(fontSize * OVERLAY_PADDING_EM.x);
280
- const padY = r0(fontSize * OVERLAY_PADDING_EM.y);
284
+ const { x: padX, y: padY } = getOverlayPadding(overlay);
281
285
  const centerX = box.left + box.width / 2;
282
286
  const tagsFor = (role: OverlayFontRole) => getTextTags(overlay, colors, context, role);
283
- const text = (pos: OverlayPoint, align: number, size: number, role: OverlayFontRole, steps: TextStep[]) =>
284
- getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags: `\\an${align}\\fs${r0(size)}${tagsFor(role)}`, steps, entrance, slidePx });
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 });
285
289
  if (overlay.kind === "hook_title" || overlay.kind === "place_card") {
286
- let y = box.top + padY;
290
+ // The text block sits in the card's middle; centred lines on its axis, left ones from its left edge (RV-131).
291
+ const content = getTitleContentBox(overlay);
292
+ const isLeft = overlay.align === "left";
293
+ const lineX = isLeft ? content.left : centerX;
294
+ const lineAlign = isLeft ? 7 : 8;
295
+ let y = content.top;
287
296
  if (overlay.kind === "hook_title" && overlay.place !== null) {
288
297
  const size = overlay.placeFontSize;
289
298
  const pin = Math.round(size * 1.05);
290
299
  const rowWidth = pin + Math.round(size * 0.25) + estimateTextWidth(overlay.place, size);
291
- const rowLeft = centerX - rowWidth / 2;
300
+ const rowLeft = isLeft ? content.left : centerX - rowWidth / 2;
292
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,"));
293
302
  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) }]));
294
303
  y += size * 1.3 + fontSize * 0.12;
@@ -296,14 +305,18 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
296
305
  const lineHeight = overlay.kind === "hook_title" ? OVERLAY_LINE_HEIGHT : OVERLAY_TITLE_LINE_HEIGHT;
297
306
  let typedBefore = 0;
298
307
  overlay.lines.forEach((line) => {
299
- // The lines type one after the other, as the render's characters do.
308
+ // The lines type one after the other, as the render's characters do; a left line holds its place transparent
309
+ // from the start, a centred one shows its typed part only (`getTypedSteps`).
300
310
  const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
301
- events.push(...text({ x: centerX, y }, 8, fontSize, "heading", getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing).map((step, index) => (index === 0 ? { ...step, from: span.start } : step))));
311
+ const steps = getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
312
+ // A centred typed line has no hidden first step to carry the entrance: its letters appear as typed, as the render's.
313
+ 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));
302
315
  typedBefore += [...line].length;
303
316
  y += fontSize * lineHeight;
304
317
  });
305
318
  if (overlay.kind === "place_card" && overlay.subtitle !== null) {
306
- events.push(...text({ x: centerX, y: y + fontSize * 0.12 }, 8, overlay.subtitleFontSize, "interface", [{ from: span.start, to: span.end, text: toAssText(overlay.subtitle) }]));
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) }]));
307
320
  }
308
321
  return events;
309
322
  }
@@ -724,7 +724,7 @@ async function runRenderFootageDraft(
724
724
  const { rawSpeechFile, declickedFile, speechFile } = getSpeechChainFiles(draftDir, { isDeclick: declickLevel !== "off", isLoudness: loudness !== null });
725
725
  const words = remapWords(edl, transcript.words, film.cut.fillers);
726
726
  const frame = getFrame(film);
727
- const resolved = resolveEdlOverlays({ film, edl, words, frame, caption: getFootageCaptionLayout(film, options.layout ?? {}) });
727
+ const resolved = resolveEdlOverlays({ film, edl, words, frame, caption: getFootageCaptionLayout(film, options.layout ?? {}), ...(options.brand?.style === undefined ? {} : { style: options.brand.style }) });
728
728
  if (!resolved.ok) return err(`footage film ${film.id}: the EDL's overlays cannot be drawn: ${resolved.problems.join("; ")}`, { kind: "input" });
729
729
  const overlays = resolved.overlays;
730
730
  const brandColors = options.brand?.colors;
@@ -2,7 +2,17 @@ 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 { OVERLAY_LINE_HEIGHT, OVERLAY_LIST_LINE_HEIGHT, OVERLAY_PADDING_EM, OVERLAY_TITLE_LINE_HEIGHT, SEARCH_BAR_PADDING_EM, formatOverlayNumber, type ResolvedOverlay } from "./overlays.js";
5
+ import {
6
+ OVERLAY_LINE_HEIGHT,
7
+ OVERLAY_LIST_LINE_HEIGHT,
8
+ OVERLAY_PADDING_EM,
9
+ OVERLAY_TITLE_LINE_HEIGHT,
10
+ SEARCH_BAR_PADDING_EM,
11
+ formatOverlayNumber,
12
+ getOverlayPadding,
13
+ getTitleContentBox,
14
+ type ResolvedOverlay,
15
+ } from "./overlays.js";
6
16
 
7
17
  /**
8
18
  * The render's overlays (issue #1200): HTML, CSS and GSAP tweens for the HyperFrames composition, every look in the
@@ -68,7 +78,13 @@ function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interfac
68
78
  `.ov-list li{display:flex;align-items:center;gap:.45em;list-style:none}`,
69
79
  `.ov-svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible}`,
70
80
  `.ov-search,.ov-counter .ov-card,.ov-date .ov-card,.ov-place,.ov-sub,.ov-line{white-space:nowrap}`,
71
- `.ov-stack{flex-direction:column;gap:0;text-align:center;transform-origin:50% 0%}`,
81
+ // A title card fills its fitted box, so a typed title keeps its width; a centred typed line hides its untyped
82
+ // characters (they take no room), so what is typed stays centred (RV-131 of an adopting app).
83
+ `.ov-stack{flex-direction:column;justify-content:center;gap:0;text-align:center;width:100%;height:100%;box-sizing:border-box;transform-origin:50% 0%}`,
84
+ `.ov-stack.left{align-items:flex-start;text-align:left}`,
85
+ `.ov-stack.left .ov-place{justify-content:flex-start}`,
86
+ `.ov-line{min-height:1lh}`,
87
+ `.ty .ov-stack:not(.left) .ch{display:none}`,
72
88
  `.ov-hook-title .ov-line{font-family:${fonts.heading};font-weight:800;letter-spacing:-.02em}`,
73
89
  `.ov-place{display:flex;align-items:center;justify-content:center;gap:.25em;font-weight:650;opacity:.92;margin-bottom:.12em}`,
74
90
  `.ov-pin{flex:none;width:1.05em;height:1.05em}`,
@@ -133,6 +149,14 @@ function getCardStyle(overlay: ResolvedOverlay, colors: OverlayColors, scale = 1
133
149
  const own = overlay.colors;
134
150
  const parts = [own.card === undefined ? "" : `background:${colors.background}`, own.text === undefined ? "" : `color:${colors.foreground}`];
135
151
  if (overlay.cornerRadius !== undefined && overlay.cornerRadius !== null) parts.push(`border-radius:${getCornerRadiusCss(overlay.cornerRadius, scale)}`);
152
+ if (overlay.kind === "hook_title" || overlay.kind === "place_card") {
153
+ // The text block sits where the draft draws it: the card's padding is what its fitted box leaves round it.
154
+ const content = getTitleContentBox(overlay);
155
+ parts.push(`padding:${r3(content.top - overlay.box.top)}px ${r3(content.left - overlay.box.left)}px`);
156
+ } else if (overlay.padScale !== undefined && overlay.kind !== "search_bar" && overlay.kind !== "arrow" && overlay.kind !== "highlight") {
157
+ const pad = getOverlayPadding(overlay);
158
+ parts.push(`padding:${pad.y}px ${pad.x}px`);
159
+ }
136
160
  if (overlay.kind === "keyword" && own.accent !== undefined) parts.push(`border-bottom-color:${colors.accent}`);
137
161
  const style = parts.filter((part) => part !== "").join(";");
138
162
  return style === "" ? "" : ` style="${style}"`;
@@ -149,7 +173,7 @@ function getEntranceTweens(target: string, entrance: OverlayEntrance, start: num
149
173
  /** The typing tweens: each character of `#<id>` shown at its time. */
150
174
  function getTypingTweens(id: string, overlay: { start: number; typing: number | null }, length: number): string[] {
151
175
  if (overlay.typing === null || length === 0) return [];
152
- return [`tl.to("#${id} .ch", { opacity: 1, duration: 0.01, ease: "none", stagger: ${r3(1 / overlay.typing)} }, ${r3(overlay.start + OVERLAY_TYPING_DELAY)});`];
176
+ return [`tl.to("#${id} .ch", { opacity: 1, display: "inline", duration: 0.01, ease: "none", stagger: ${r3(1 / overlay.typing)} }, ${r3(overlay.start + OVERLAY_TYPING_DELAY)});`];
153
177
  }
154
178
 
155
179
  /** Each new kind's own entrance when the overlay names none. */
@@ -203,12 +227,12 @@ function getCardBody(overlay: CardOverlay, id: string, colors: OverlayColors, lo
203
227
  if (overlay.kind === "hook_title") {
204
228
  const place = overlay.place === null ? "" : `<div class="ov-place" style="font-size:${overlay.placeFontSize}px">${getPinSvg(colors.accent)}<span>${escapeHtml(overlay.place)}</span></div>`;
205
229
  const lines = overlay.lines.map((line) => `<div class="ov-line">${typedOrPlain(line)}</div>`).join("");
206
- return { classes: "ov-hook-title center", body: `<div class="ov-card ov-stack"__STYLE__>${place}${lines}</div>`, typed: overlay.lines.join("").length };
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 };
207
231
  }
208
232
  if (overlay.kind === "place_card") {
209
233
  const subtitle = overlay.subtitle === null ? "" : `<div class="ov-sub" style="font-size:${overlay.subtitleFontSize}px">${escapeHtml(overlay.subtitle)}</div>`;
210
234
  const lines = overlay.lines.map((line) => `<div class="ov-line">${typedOrPlain(line)}</div>`).join("");
211
- return { classes: "ov-place-card center", body: `<div class="ov-card ov-stack"__STYLE__>${lines}${subtitle}</div>`, typed: overlay.lines.join("").length };
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 };
212
236
  }
213
237
  if (overlay.kind === "search_bar") {
214
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 };
@@ -36,6 +36,14 @@ export const OVERLAY_POSITIONS = ["top", "middle", "bottom"] as const;
36
36
 
37
37
  export type OverlayPosition = (typeof OVERLAY_POSITIONS)[number];
38
38
 
39
+ /** How a hook title's or a place card's lines sit in their card: centred (the default) or from its left padding. */
40
+ export const OVERLAY_ALIGNS = ["center", "left"] as const;
41
+
42
+ export type OverlayAlign = (typeof OVERLAY_ALIGNS)[number];
43
+
44
+ /** The kinds whose lines take an `align`: the two stacked title cards. */
45
+ export const OVERLAY_ALIGNED_KINDS: readonly OverlayKind[] = ["hook_title", "place_card"];
46
+
39
47
  /**
40
48
  * How an overlay enters: `fade` in place, `slide` up into place, `type` letter by letter (text kinds), `none` (it is
41
49
  * simply there). Without one, the kind's own entrance. Never a bounce or a pop: the reel stays natural.
@@ -109,6 +117,10 @@ export interface EdlOverlayStyle {
109
117
  colors?: EdlOverlayColors;
110
118
  /** Its card's corner in place of the brand style's (`BrandStyle.cornerRadius`); not on a punch_in, arrow or highlight. */
111
119
  corner_radius?: CornerRadius;
120
+ /** How a hook title's or a place card's lines sit in the card (`center` without it). */
121
+ align?: OverlayAlign;
122
+ /** A place card's subtitle size: `s`, `m` (about 55 % of the title, the default) or `l`. */
123
+ subtitle_size?: OverlaySize;
112
124
  }
113
125
 
114
126
  export interface EdlOverlay {
@@ -260,6 +272,8 @@ function checkOverlayStyle(overlay: EdlOverlay, issue: (path: string[], message:
260
272
  }
261
273
  if (style.typing_speed !== undefined && !isTypedOverlay(overlay)) issue(["style", "typing_speed"], "only a typed entrance or a search bar has a typing speed");
262
274
  if (style.corner_radius !== undefined && (kind === "punch_in" || kind === "arrow" || kind === "highlight")) issue(["style", "corner_radius"], `${article(kind)} draws no card; leave corner_radius out`);
275
+ if (style.align !== undefined && !OVERLAY_ALIGNED_KINDS.includes(kind)) issue(["style", "align"], "only a hook_title or a place_card aligns its lines; leave align out");
276
+ if (style.subtitle_size !== undefined && kind !== "place_card") issue(["style", "subtitle_size"], "only a place_card has a subtitle; leave subtitle_size out");
263
277
  if (style.colors === undefined) return;
264
278
  if (kind === "punch_in") issue(["style", "colors"], "a punch_in draws nothing to colour; leave colors out");
265
279
  if ((kind === "arrow" || kind === "highlight") && (style.colors.card !== undefined || style.colors.text !== undefined)) {
@@ -349,6 +363,8 @@ export const overlaySchema = z
349
363
  .enum(CORNER_RADII)
350
364
  .optional()
351
365
  .describe("The card's corner: none, s, m, l or pill; the brand style's without it (no punch_in, arrow or highlight)."),
366
+ align: z.enum(OVERLAY_ALIGNS).optional().describe("center (the default) or left: how a hook_title's or a place_card's lines sit in their card."),
367
+ subtitle_size: z.enum(OVERLAY_SIZES).optional().describe("s, m (the default, about 55 % of the title) or l: a place_card's subtitle size."),
352
368
  })
353
369
  .optional()
354
370
  .describe("The overlay's look: size, side, position, entrance, typing speed and colours; fonts are the brand's."),
@@ -9,6 +9,7 @@ import {
9
9
  isTypedOverlay,
10
10
  type EdlOverlay,
11
11
  type EdlOverlayColors,
12
+ type OverlayAlign,
12
13
  type OverlayEntrance,
13
14
  type OverlayKind,
14
15
  type OverlayPosition,
@@ -17,7 +18,7 @@ import {
17
18
  } from "./overlay-schema.js";
18
19
  import { getSegmentZoomEases } from "./compose.js";
19
20
  import { normalizeWord } from "./words.js";
20
- import type { CornerRadius } from "./brand-style.js";
21
+ import { STYLE_PADDING_SCALES, type BrandStyle, type CornerRadius } from "./brand-style.js";
21
22
 
22
23
  /**
23
24
  * An EDL's overlays resolved for the render and the draft (issue #1200): each one's film time (from its word through
@@ -39,14 +40,21 @@ export const OVERLAY_FONT_SIZES: Record<TextOverlayKind, Record<OverlaySize, num
39
40
  keyword: { s: 64, m: 84, l: 108 },
40
41
  lower_third: { s: 44, m: 52, l: 60 },
41
42
  list: { s: 40, m: 48, l: 56 },
42
- hook_title: { s: 52, m: 64, l: 76 },
43
+ hook_title: { s: 50, m: 64, l: 82 },
43
44
  search_bar: { s: 36, m: 42, l: 50 },
44
- place_card: { s: 72, m: 92, l: 112 },
45
+ place_card: { s: 70, m: 92, l: 118 },
45
46
  counter: { s: 84, m: 108, l: 132 },
46
47
  date_stamp: { s: 30, m: 36, l: 44 },
47
48
  };
48
49
  /** A second line's type size in main font sizes: the hook title's place label, the subtitle, the unit, the stamp's place. */
49
- export const OVERLAY_SECONDARY_SCALE = { hook_title: 0.55, place_card: 0.42, counter: 0.5, date_stamp: 0.78 } as const;
50
+ export const OVERLAY_SECONDARY_SCALE = { hook_title: 0.55, place_card: 0.55, counter: 0.5, date_stamp: 0.78 } as const;
51
+ /** A place card's subtitle size in title sizes, by its `subtitle_size` (RV-131 of an adopting app: 0.42 read tiny). */
52
+ export const OVERLAY_SUBTITLE_SCALES: Record<OverlaySize, number> = { s: 0.42, m: 0.55, l: 0.7 };
53
+ /** The smallest a place card's subtitle is drawn, in px of a 1080 px wide frame (2.3 % of a 1920 px tall one). */
54
+ export const MIN_OVERLAY_SUBTITLE_PX = 44;
55
+ /** How a title that does not fit two lines shrinks before it is refused: by this factor, at most `MAX_TITLE_SHRINKS` times. */
56
+ export const OVERLAY_TITLE_SHRINK = 0.9;
57
+ const MAX_TITLE_SHRINKS = 3;
50
58
  /** A text overlay's line height and its box's padding, in font sizes. */
51
59
  export const OVERLAY_LINE_HEIGHT = 1.15;
52
60
  export const OVERLAY_LIST_LINE_HEIGHT = 1.4;
@@ -117,6 +125,8 @@ export interface OverlayLook {
117
125
  colors: EdlOverlayColors;
118
126
  /** Its card's own corner (`style.corner_radius`), else null: the brand style's, or the kind's own without one. */
119
127
  cornerRadius?: CornerRadius | null;
128
+ /** Its card's padding in `OVERLAY_PADDING_EM`s: the brand style's `padding` (`STYLE_PADDING_SCALES`); absent: 1. */
129
+ padScale?: number;
120
130
  }
121
131
 
122
132
  type Drawn = OverlayBase & OverlayLook;
@@ -132,9 +142,9 @@ export type ResolvedOverlay =
132
142
  | (Drawn & { kind: "list"; items: string[]; fontSize: number; side: OverlaySide; box: OverlayBox })
133
143
  | (Drawn & { kind: "arrow"; from: OverlayPoint; to: OverlayPoint })
134
144
  | (Drawn & { kind: "highlight"; rect: OverlayBox })
135
- | (Drawn & { kind: "hook_title"; lines: string[]; place: string | null; fontSize: number; placeFontSize: number; box: OverlayBox })
145
+ | (Drawn & { kind: "hook_title"; lines: string[]; place: string | null; fontSize: number; placeFontSize: number; align?: OverlayAlign; box: OverlayBox })
136
146
  | (Drawn & { kind: "search_bar"; text: string; fontSize: number; box: OverlayBox })
137
- | (Drawn & { kind: "place_card"; lines: string[]; subtitle: string | null; fontSize: number; subtitleFontSize: number; box: OverlayBox })
147
+ | (Drawn & { kind: "place_card"; lines: string[]; subtitle: string | null; fontSize: number; subtitleFontSize: number; align?: OverlayAlign; box: OverlayBox })
138
148
  | (Drawn & { kind: "counter"; value: number; from: number; decimals: number; unit: string | null; fontSize: number; unitFontSize: number; box: OverlayBox })
139
149
  | (Drawn & { kind: "date_stamp"; text: string; place: string | null; fontSize: number; placeFontSize: number; side: OverlaySide; box: OverlayBox });
140
150
 
@@ -148,6 +158,8 @@ export interface ResolveOverlaysInput {
148
158
  frame: { width: number; height: number };
149
159
  /** The film's caption box (`getFootageCaptionLayout`). */
150
160
  caption: CaptionLayout;
161
+ /** The brand's style: its `padding` pads every overlay card (absent: `m`, the cards' own padding). */
162
+ style?: Pick<BrandStyle, "padding">;
151
163
  }
152
164
 
153
165
  /** The part of the frame no platform interface covers: a 9:16 film's caption preset zone (`all` without one), else 80 px. */
@@ -184,6 +196,12 @@ function findOverlayStart(overlay: EdlOverlay, words: TimedWord[]): { ok: true;
184
196
  const r1 = (value: number): number => Math.round(value * 10) / 10;
185
197
  const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
186
198
 
199
+ /** A drawn overlay's padding round its text, in px: `OVERLAY_PADDING_EM` of its font size, scaled by its `padScale`. */
200
+ export function getOverlayPadding(overlay: { fontSize: number; padScale?: number }): { x: number; y: number } {
201
+ const scale = overlay.padScale ?? 1;
202
+ return { x: Math.round(overlay.fontSize * OVERLAY_PADDING_EM.x * scale), y: Math.round(overlay.fontSize * OVERLAY_PADDING_EM.y * scale) };
203
+ }
204
+
187
205
  /** The estimated width of a line of text at a font size, in px (`OVERLAY_CHAR_EM` a letter). */
188
206
  export function estimateTextWidth(text: string, fontSize: number): number {
189
207
  return Math.ceil([...text].length * OVERLAY_CHAR_EM * fontSize - 1e-6);
@@ -249,7 +267,7 @@ export function getSideTextLines(overlay: SideTextOverlay): string[] {
249
267
  export function getDrawnOverlayCard(overlay: ResolvedOverlay): OverlayBox | null {
250
268
  if (overlay.kind !== "keyword" && overlay.kind !== "lower_third" && overlay.kind !== "list") return getOverlayBounds(overlay);
251
269
  const { box, fontSize, side } = overlay;
252
- const padX = Math.round(fontSize * OVERLAY_PADDING_EM.x);
270
+ const padX = getOverlayPadding(overlay).x;
253
271
  const textWidth = Math.max(0, ...getSideTextLines(overlay).map((line) => estimateTextWidth(line, fontSize)));
254
272
  const width = Math.min(box.width, Math.ceil(textWidth + 2 * padX));
255
273
  return { left: side === "right" ? box.left + box.width - width : box.left, top: box.top, width, height: box.height };
@@ -330,7 +348,7 @@ export function resolveEdlOverlays(input: ResolveOverlaysInput): ResolvedOverlay
330
348
  }
331
349
  }
332
350
  const base = { index, start, end, segment };
333
- const placed = placeOverlay(overlay, base, { zone, frame, band: getCaptionBand(input, segment) });
351
+ const placed = placeOverlay(overlay, base, { zone, frame, band: getCaptionBand(input, segment), padScale: STYLE_PADDING_SCALES[input.style?.padding ?? "m"] });
334
352
  if (!placed.ok) {
335
353
  problems.push(`${at}: ${placed.error}`);
336
354
  return;
@@ -391,6 +409,8 @@ interface Placement {
391
409
  zone: { top: number; bottom: number; left: number; right: number };
392
410
  frame: { width: number; height: number };
393
411
  band: { top: number; bottom: number } | null;
412
+ /** Every card's padding scale (`STYLE_PADDING_SCALES` of the brand's `padding`). */
413
+ padScale: number;
394
414
  }
395
415
 
396
416
  type Placed = { ok: true; overlay: ResolvedOverlay } | { ok: false; error: string };
@@ -435,7 +455,7 @@ function placeOverlay(overlay: EdlOverlay, base: OverlayBase, place: Placement):
435
455
  const ease = r3(Math.min(PUNCH_IN_EASE_SECONDS, (base.end - base.start) / 2));
436
456
  return { ok: true, overlay: { ...base, kind: "punch_in", scale: PUNCH_IN_SCALES[overlay.style?.size ?? "m"], ease } };
437
457
  }
438
- const drawn = { ...base, ...getLook(overlay) };
458
+ const drawn = { ...base, ...getLook(overlay), ...(place.padScale === 1 ? {} : { padScale: place.padScale }) };
439
459
  if (overlay.kind === "arrow" || overlay.kind === "highlight") return placeMark(overlay, drawn, place);
440
460
  if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") return placeSideText({ ...overlay, kind: overlay.kind }, drawn, place);
441
461
  return placeCard({ ...overlay, kind: overlay.kind }, drawn, place);
@@ -473,7 +493,7 @@ function placeSideText(overlay: EdlOverlay & { kind: "keyword" | "lower_third" |
473
493
  const scale = frame.width / 1080;
474
494
  const side = overlay.style?.side ?? (overlay.kind === "keyword" ? "right" : "left");
475
495
  const fontSize = Math.round(OVERLAY_FONT_SIZES[overlay.kind][overlay.style?.size ?? "m"] * scale);
476
- const padY = Math.round(fontSize * OVERLAY_PADDING_EM.y);
496
+ const padY = getOverlayPadding({ fontSize, padScale: place.padScale }).y;
477
497
  const lines = overlay.kind === "list" ? (overlay.items ?? []).length : 1;
478
498
  const lineHeight = overlay.kind === "list" ? OVERLAY_LIST_LINE_HEIGHT : OVERLAY_LINE_HEIGHT;
479
499
  const height = Math.ceil(lines * fontSize * lineHeight + 2 * padY);
@@ -512,30 +532,99 @@ interface CardMetrics {
512
532
  /** The widest the content may be, in px. */
513
533
  room: number;
514
534
  label: string;
535
+ /** The frame's width / 1080. */
536
+ scale: number;
515
537
  }
516
538
 
517
539
  const tooWide = (metrics: CardMetrics, what: string): CardResult => ({ ok: false, error: `the ${metrics.label}'s ${what} is too wide for one line; shorten it or use a smaller size` });
518
540
 
519
- /** A hook title's or a place card's lines and second line. */
520
- function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card" }, metrics: CardMetrics): CardResult {
521
- const { fontSize, room, label } = metrics;
522
- const lines = wrapOverlayText(overlay.text ?? "", fontSize, room);
523
- if (lines.length > MAX_OVERLAY_TITLE_LINES || lines.some((line) => estimateTextWidth(line, fontSize) > room)) {
524
- return { ok: false, error: `the ${label} takes more than ${MAX_OVERLAY_TITLE_LINES} lines; shorten it or use a smaller size` };
541
+ /**
542
+ * A title's lines at a font size: two lines balanced so neither is much wider than the other (the narrower the
543
+ * wider of the two, the better), or the greedy wrap when it takes one line or more than two.
544
+ */
545
+ export function wrapOverlayTitle(text: string, fontSize: number, width: number): string[] {
546
+ const lines = wrapOverlayText(text, fontSize, width);
547
+ if (lines.length !== 2) return lines;
548
+ const words = text.split(/\s+/).filter((part) => part.length > 0);
549
+ let best = lines;
550
+ let bestWidth = Math.max(...lines.map((line) => estimateTextWidth(line, fontSize)));
551
+ for (let split = 1; split < words.length; split++) {
552
+ const pair = [words.slice(0, split).join(" "), words.slice(split).join(" ")];
553
+ const widest = Math.max(...pair.map((line) => estimateTextWidth(line, fontSize)));
554
+ if (widest < bestWidth) [best, bestWidth] = [pair, widest];
555
+ }
556
+ return best;
557
+ }
558
+
559
+ /** A title's lines and font size: its own size, else smaller by `OVERLAY_TITLE_SHRINK` until it fits two lines; null when it never does. */
560
+ function fitTitle(text: string, fontSize: number, room: number): { lines: string[]; fontSize: number } | null {
561
+ for (let shrink = 0, size = fontSize; shrink <= MAX_TITLE_SHRINKS; shrink++, size = Math.round(size * OVERLAY_TITLE_SHRINK)) {
562
+ const lines = wrapOverlayTitle(text, size, room);
563
+ if (lines.length <= MAX_OVERLAY_TITLE_LINES && lines.every((line) => estimateTextWidth(line, size) <= room)) return { lines, fontSize: size };
525
564
  }
565
+ return null;
566
+ }
567
+
568
+ /**
569
+ * A place card's subtitle size: its `subtitle_size` of the title, at least `MIN_OVERLAY_SUBTITLE_PX`; a subtitle too
570
+ * long for that shrinks to fit `room`, never below the `s` step (the size every subtitle had before, so nothing that
571
+ * fitted then is refused now).
572
+ */
573
+ function getSubtitleSize(input: { subtitle: string; titleSize: number; step: OverlaySize; room: number; scale: number }): number {
574
+ const wanted = Math.max(Math.round(MIN_OVERLAY_SUBTITLE_PX * input.scale), Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES[input.step]));
575
+ const fitting = Math.floor(input.room / ([...input.subtitle].length * OVERLAY_CHAR_EM));
576
+ return Math.min(wanted, Math.max(fitting, Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES.s)));
577
+ }
578
+
579
+ /** A hook title's or a place card's second line: the place label (with its pin) or the subtitle. */
580
+ type TitleOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "place_card" }>;
581
+
582
+ /**
583
+ * The text block of a hook title or a place card without its padding, in px: its widest line (the place label with
584
+ * its pin, the subtitle, each title line) and its height. Its card is this plus the padding, so the draft and the
585
+ * render find the block's left edge and top inside the card from it whatever the title's fitted size.
586
+ */
587
+ export function getTitleContentSize(input: { kind: TitleOverlay["kind"]; lines: readonly string[]; fontSize: number; second: string | null; secondSize: number }): { width: number; height: number } {
588
+ const { kind, lines, fontSize, second, secondSize } = input;
589
+ const isHook = kind === "hook_title";
590
+ const secondWidth = second === null ? 0 : estimateTextWidth(second, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0);
591
+ const lineHeight = isHook ? OVERLAY_LINE_HEIGHT : OVERLAY_TITLE_LINE_HEIGHT;
592
+ return {
593
+ width: Math.max(secondWidth, ...lines.map((line) => estimateTextWidth(line, fontSize))),
594
+ height: lines.length * fontSize * lineHeight + (second === null ? 0 : secondSize * 1.3 + fontSize * 0.12),
595
+ };
596
+ }
597
+
598
+ /** A resolved title's text block inside its card: its left edge and top, in px of the frame. */
599
+ export function getTitleContentBox(overlay: TitleOverlay): OverlayBox {
600
+ const second = overlay.kind === "hook_title" ? overlay.place : overlay.subtitle;
601
+ const secondSize = overlay.kind === "hook_title" ? overlay.placeFontSize : overlay.subtitleFontSize;
602
+ const size = getTitleContentSize({ kind: overlay.kind, lines: overlay.lines, fontSize: overlay.fontSize, second, secondSize });
603
+ const { box } = overlay;
604
+ return { left: box.left + (box.width - size.width) / 2, top: box.top + (box.height - size.height) / 2, width: size.width, height: size.height };
605
+ }
606
+
607
+ /** A hook title's or a place card's lines and second line, aligned as its style says. */
608
+ function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card" }, metrics: CardMetrics): CardResult {
609
+ const { room, label } = metrics;
610
+ const fitted = fitTitle(overlay.text ?? "", metrics.fontSize, room);
611
+ if (fitted === null) return { ok: false, error: `the ${label} takes more than ${MAX_OVERLAY_TITLE_LINES} lines even at a smaller size; shorten it or use a smaller size` };
612
+ const { lines, fontSize } = fitted;
526
613
  const isHook = overlay.kind === "hook_title";
527
614
  const second = (isHook ? overlay.place : overlay.subtitle) ?? null;
528
- const secondSize = Math.round(fontSize * OVERLAY_SECONDARY_SCALE[overlay.kind]);
615
+ const secondSize =
616
+ !isHook && second !== null
617
+ ? getSubtitleSize({ subtitle: second, titleSize: metrics.fontSize, step: overlay.style?.subtitle_size ?? "m", room, scale: metrics.scale })
618
+ : Math.round(metrics.fontSize * OVERLAY_SECONDARY_SCALE[overlay.kind]);
529
619
  // The hook title's place label carries a pin about one label line wide before it.
530
620
  const secondWidth = second === null ? 0 : estimateTextWidth(second, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0);
531
621
  if (secondWidth > room) return tooWide(metrics, isHook ? "place label" : "subtitle");
532
- const lineHeight = isHook ? OVERLAY_LINE_HEIGHT : OVERLAY_TITLE_LINE_HEIGHT;
622
+ const align = overlay.style?.align ?? "center";
533
623
  return {
534
624
  ok: true,
535
625
  content: {
536
- width: Math.max(secondWidth, ...lines.map((line) => estimateTextWidth(line, fontSize))),
537
- height: lines.length * fontSize * lineHeight + (second === null ? 0 : secondSize * 1.3 + fontSize * 0.12),
538
- fields: isHook ? { kind: "hook_title", lines, place: second, fontSize, placeFontSize: secondSize } : { kind: "place_card", lines, subtitle: second, fontSize, subtitleFontSize: secondSize },
626
+ ...getTitleContentSize({ kind: overlay.kind, lines, fontSize, second, secondSize }),
627
+ fields: isHook ? { kind: "hook_title", lines, place: second, fontSize, placeFontSize: secondSize, align } : { kind: "place_card", lines, subtitle: second, fontSize, subtitleFontSize: secondSize, align },
539
628
  },
540
629
  };
541
630
  }
@@ -592,8 +681,8 @@ function placeCard(overlay: EdlOverlay & { kind: CardKind }, drawn: Drawn, place
592
681
  const margin = Math.round(OVERLAY_MARGIN * scale);
593
682
  const outer = frame.width - zone.left - zone.right - 2 * margin;
594
683
  const fontSize = Math.round(OVERLAY_FONT_SIZES[overlay.kind][overlay.style?.size ?? "m"] * scale);
595
- const pad = { x: Math.round(fontSize * OVERLAY_PADDING_EM.x), y: Math.round(fontSize * OVERLAY_PADDING_EM.y) };
596
- const metrics = { fontSize, pad, room: outer - 2 * pad.x, label: overlay.kind.replace("_", " ") };
684
+ const pad = getOverlayPadding({ fontSize, padScale: place.padScale });
685
+ const metrics = { fontSize, pad, room: outer - 2 * pad.x, label: overlay.kind.replace("_", " "), scale };
597
686
  const measured =
598
687
  overlay.kind === "hook_title" || overlay.kind === "place_card"
599
688
  ? measureTitle({ ...overlay, kind: overlay.kind }, metrics)
@@ -747,7 +747,7 @@ async function runRenderFootage(
747
747
  if (lowDisk.length > 0) return err(`not enough disk space to render: ${lowDisk.join(" ")}`);
748
748
  const seconds = getFootageFilmSeconds(film, edl);
749
749
  const words = remapWords(edl, transcript.words, film.cut.fillers);
750
- const overlays = resolveEdlOverlays({ film, edl, words, frame: getFrame(film), caption: getFootageCaptionLayout(film, options.layout ?? {}) });
750
+ const overlays = resolveEdlOverlays({ film, edl, words, frame: getFrame(film), caption: getFootageCaptionLayout(film, options.layout ?? {}), ...(options.brand.style === undefined ? {} : { style: options.brand.style }) });
751
751
  if (!overlays.ok) return err(`footage film ${film.id}: the EDL's overlays cannot be drawn: ${overlays.problems.join("; ")}`, { kind: "input" });
752
752
  const music = await getMusic(film, edl, clips, seconds, options);
753
753
  if (!music.ok) return music;
package/src/index.ts CHANGED
@@ -88,6 +88,8 @@ export {
88
88
  MAX_OVERLAY_UNIT_LENGTH,
89
89
  MIN_OVERLAY_SECONDS,
90
90
  MIN_OVERLAY_TYPING_SPEED,
91
+ OVERLAY_ALIGNED_KINDS,
92
+ OVERLAY_ALIGNS,
91
93
  OVERLAY_ENTRANCES,
92
94
  OVERLAY_ENTRANCES_BY_KIND,
93
95
  OVERLAY_KINDS,
@@ -102,6 +104,7 @@ export {
102
104
  type EdlOverlayColors,
103
105
  type EdlOverlayStyle,
104
106
  type EdlOverlayWord,
107
+ type OverlayAlign,
105
108
  type OverlayEntrance,
106
109
  type OverlayKind,
107
110
  type OverlayPosition,
@@ -133,12 +136,19 @@ export { createDraftTextMeasure, wrapDraftLine, type DraftTextMeasure } from "./
133
136
  export {
134
137
  OVERLAY_FONT_ROLES,
135
138
  OVERLAY_FONT_SIZES,
139
+ OVERLAY_SUBTITLE_SCALES,
140
+ MIN_OVERLAY_SUBTITLE_PX,
141
+ OVERLAY_TITLE_SHRINK,
136
142
  PUNCH_IN_EASE_SECONDS,
137
143
  PUNCH_IN_SCALES,
138
144
  findShotBreak,
139
145
  formatOverlayNumber,
140
146
  getDrawnOverlayCard,
141
147
  getOverlayBounds,
148
+ getOverlayPadding,
149
+ getTitleContentBox,
150
+ getTitleContentSize,
151
+ wrapOverlayTitle,
142
152
  getOverlaySafeZone,
143
153
  getOverlayTexts,
144
154
  getOverlayTextsByRole,