@softure-ai/marketing-kit 0.27.0 → 0.29.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 (60) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +15 -2
  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-overlays.d.ts.map +1 -1
  18. package/dist/footage/draft-overlays.js +28 -16
  19. package/dist/footage/draft-overlays.js.map +1 -1
  20. package/dist/footage/draft.d.ts.map +1 -1
  21. package/dist/footage/draft.js +41 -6
  22. package/dist/footage/draft.js.map +1 -1
  23. package/dist/footage/edl.d.ts +9 -0
  24. package/dist/footage/edl.d.ts.map +1 -1
  25. package/dist/footage/film.d.ts +15 -3
  26. package/dist/footage/film.d.ts.map +1 -1
  27. package/dist/footage/film.js +7 -2
  28. package/dist/footage/film.js.map +1 -1
  29. package/dist/footage/overlay-html.d.ts.map +1 -1
  30. package/dist/footage/overlay-html.js +20 -5
  31. package/dist/footage/overlay-html.js.map +1 -1
  32. package/dist/footage/overlay-schema.d.ts +18 -0
  33. package/dist/footage/overlay-schema.d.ts.map +1 -1
  34. package/dist/footage/overlay-schema.js +10 -0
  35. package/dist/footage/overlay-schema.js.map +1 -1
  36. package/dist/footage/overlays.d.ts +49 -3
  37. package/dist/footage/overlays.d.ts.map +1 -1
  38. package/dist/footage/overlays.js +95 -20
  39. package/dist/footage/overlays.js.map +1 -1
  40. package/dist/footage/pipeline.js +1 -1
  41. package/dist/footage/pipeline.js.map +1 -1
  42. package/dist/index.d.ts +4 -4
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +4 -4
  45. package/dist/index.js.map +1 -1
  46. package/package.json +1 -1
  47. package/schema/edl.schema.json +17 -0
  48. package/schema/marketing.schema.json +12 -2
  49. package/src/config/config.ts +1 -0
  50. package/src/config/schema.ts +6 -2
  51. package/src/footage/caption-highlight.ts +27 -5
  52. package/src/footage/compose.ts +15 -5
  53. package/src/footage/draft-overlays.ts +30 -17
  54. package/src/footage/draft.ts +53 -7
  55. package/src/footage/film.ts +17 -3
  56. package/src/footage/overlay-html.ts +29 -5
  57. package/src/footage/overlay-schema.ts +16 -0
  58. package/src/footage/overlays.ts +112 -23
  59. package/src/footage/pipeline.ts +1 -1
  60. package/src/index.ts +16 -0
@@ -4,7 +4,7 @@ import type { ComposeFont } from "../compose/compose.js";
4
4
  import { assertLocalReferences, escapeHtml, fontFaces, fontStack } from "../compose/html.js";
5
5
  import { CAPTION_LINE_HEIGHT, getCaptionPillCss, getCaptionPositionCss, type CaptionLayout } from "../compose/timeline.js";
6
6
  import type { TimedWord } from "../voice/voiceover.js";
7
- import { CAPTION_HIGHLIGHT_BOX_PADDING_EM, CAPTION_HIGHLIGHT_BOX_RADIUS, CAPTION_HIGHLIGHT_SECONDS, getCaptionHighlight } from "./caption-highlight.js";
7
+ import { CAPTION_HIGHLIGHT_BOX_PADDING_EM, CAPTION_HIGHLIGHT_BOX_RADIUS, CAPTION_HIGHLIGHT_SECONDS, CAPTION_UNDERLINE_EM, getCaptionEntranceTween, getCaptionHighlight } from "./caption-highlight.js";
8
8
  import { CAPTION_SAFE_ZONES, getCaptionChunkLayouts, getCaptionSpans, getFootageCaptionChunks, isSameCaptionPlace, type CaptionSpan } from "./captions.js";
9
9
  import { getEdlDuration, getSegmentStarts, type Edl } from "./edl.js";
10
10
  import {
@@ -219,6 +219,8 @@ export function composeFootage(input: FootageComposeInput): string {
219
219
  if (!highlight.ok) throw new Error(`composeFootage: ${highlight.error}`);
220
220
  const look = highlight.look;
221
221
  const isBox = isHighlight && look.style === "box";
222
+ const isUnderline = isHighlight && look.style === "underline";
223
+ const entrance = getCaptionEntranceTween(film.captionEntrance);
222
224
  const caption = getFootageCaptionChunks(film, words);
223
225
  const spans = getCaptionSpans(caption, cutEnd);
224
226
  const boxes = getCaptionChunkLayouts(caption, edl, captionBox);
@@ -229,7 +231,7 @@ export function composeFootage(input: FootageComposeInput): string {
229
231
  // A chunk in a segment's own box overrides the shared rule's anchor; one in the film's box is written as before.
230
232
  const style = isSameCaptionPlace(place, captionBox) ? "" : ` style="${place.bottom === undefined ? `bottom:auto;top:${place.top}px` : `top:auto;bottom:${place.bottom}px`}"`;
231
233
  const box = isHighlight
232
- ? `<p class="pill">${chunk.words.map((w, j) => `<span id="cw${i}_${j}">${isBox ? `<i class="hl" id="cb${i}_${j}"></i>` : ""}${escapeHtml(w.text)}</span>`).join(" ")}</p>`
234
+ ? `<p class="pill">${chunk.words.map((w, j) => `<span id="cw${i}_${j}">${isBox ? `<i class="hl" id="cb${i}_${j}"></i>` : ""}${isUnderline ? `<i class="ul" id="cu${i}_${j}"></i>` : ""}${escapeHtml(w.text)}</span>`).join(" ")}</p>`
233
235
  : `<p class="phrase">${escapeHtml(chunk.words.map((w) => w.text).join(" "))}</p>`;
234
236
  return `<div id="cap${i}" class="clip caption" data-start="${start}" data-duration="${r3(stop - start)}"${style}>${box}</div>`;
235
237
  })
@@ -305,6 +307,8 @@ ${input.style === undefined ? "" : `${getStyledPillCss(input.style, look.style =
305
307
  ${isBox ? `.pill{position:relative;z-index:0}
306
308
  .pill span{position:relative}
307
309
  .hl{position:absolute;top:0;bottom:0;left:-${CAPTION_HIGHLIGHT_BOX_PADDING_EM}em;right:-${CAPTION_HIGHLIGHT_BOX_PADDING_EM}em;z-index:-1;border-radius:${CAPTION_HIGHLIGHT_BOX_RADIUS}px;background:${look.box};opacity:0}
310
+ ` : ""}${isUnderline ? `.pill span{position:relative}
311
+ .ul{position:absolute;left:0;right:0;top:${CAPTION_UNDERLINE_EM.top}em;height:${CAPTION_UNDERLINE_EM.thickness}em;border-radius:${CAPTION_UNDERLINE_EM.thickness / 2}em;background:${look.color};opacity:0}
308
312
  ` : ""}.phrase{font-weight:650;font-size:${captionBox.fontSize}px;line-height:${CAPTION_LINE_HEIGHT};letter-spacing:-.01em;text-align:center;color:#fff;text-shadow:0 2px 6px rgba(0,0,0,.55),0 0 18px rgba(0,0,0,.35)}
309
313
  .endcard{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:center;align-items:center;padding:0 80px;text-align:center}
310
314
  .brand{display:flex;justify-content:center;align-items:center;gap:18px;font-family:${headingFont};font-size:46px}
@@ -332,9 +336,10 @@ const tl = gsap.timeline({ paused: true });
332
336
  ${tweens.join("\n")}
333
337
  const captions = ${JSON.stringify(isHighlight ? caption.map((chunk) => chunk.words.map((w) => w.start)) : [])};
334
338
  captions.forEach((words, i) => {
335
- tl.fromTo("#cap" + i + " .pill", { y: 14, opacity: 0 }, { y: 0, opacity: 1, duration: 0.16, ease: "power3.out" }, Math.max(0, words[0] - 0.05));
336
- ${
337
- look.style === "box"
339
+ ${entrance === null ? "" : ` tl.fromTo("#cap" + i + " .pill", ${toTweenVars(entrance.from)}, ${toTweenVars(entrance.to)}, Math.max(0, words[0] - 0.05));\n`}${
340
+ look.style === "underline"
341
+ ? ` words.forEach((t, j) => tl.fromTo("#cu" + i + "_" + j, { opacity: 0 }, { opacity: 1, duration: 0.06, immediateRender: false }, t).to("#cu" + i + "_" + j, { opacity: 0, duration: 0.2 }, t + ${CAPTION_HIGHLIGHT_SECONDS}));`
342
+ : look.style === "box"
338
343
  ? ` words.forEach((t, j) => {
339
344
  tl.fromTo("#cb" + i + "_" + j, { opacity: 0 }, { opacity: 1, duration: 0.06, immediateRender: false }, t).to("#cb" + i + "_" + j, { opacity: 0, duration: 0.2 }, t + ${CAPTION_HIGHLIGHT_SECONDS});
340
345
  tl.fromTo("#cw" + i + "_" + j, { color: "${c.captionText}" }, { color: "${look.text}", duration: 0.06, immediateRender: false }, t).to("#cw" + i + "_" + j, { color: "${c.captionText}", duration: 0.2 }, t + ${CAPTION_HIGHLIGHT_SECONDS});
@@ -352,6 +357,11 @@ window.__timelines["${COMPOSITION_ID}"] = tl;
352
357
  `);
353
358
  }
354
359
 
360
+ /** Tween vars as the page's script writes them: `{ y: 14, opacity: 0 }`, strings quoted. */
361
+ function toTweenVars(vars: Record<string, number | string>): string {
362
+ return `{ ${Object.entries(vars).map(([key, value]) => `${key}: ${typeof value === "string" ? JSON.stringify(value) : String(value)}`).join(", ")} }`;
363
+ }
364
+
355
365
  /** The caption pill's rule in the brand's style, after the pill's own: its radius, padding, shadow and border in `accent`. */
356
366
  export function getStyledPillCss(style: BrandStyle, accent: string): string {
357
367
  const pad = getStylePadding(CAPTION_PILL_PADDING, style.padding);
@@ -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
  }
@@ -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(" "));
@@ -724,7 +770,7 @@ async function runRenderFootageDraft(
724
770
  const { rawSpeechFile, declickedFile, speechFile } = getSpeechChainFiles(draftDir, { isDeclick: declickLevel !== "off", isLoudness: loudness !== null });
725
771
  const words = remapWords(edl, transcript.words, film.cut.fillers);
726
772
  const frame = getFrame(film);
727
- const resolved = resolveEdlOverlays({ film, edl, words, frame, caption: getFootageCaptionLayout(film, options.layout ?? {}) });
773
+ const resolved = resolveEdlOverlays({ film, edl, words, frame, caption: getFootageCaptionLayout(film, options.layout ?? {}), ...(options.brand?.style === undefined ? {} : { style: options.brand.style }) });
728
774
  if (!resolved.ok) return err(`footage film ${film.id}: the EDL's overlays cannot be drawn: ${resolved.problems.join("; ")}`, { kind: "input" });
729
775
  const overlays = resolved.overlays;
730
776
  const brandColors = options.brand?.colors;
@@ -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,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."),