@softure-ai/marketing-kit 0.38.1 → 0.40.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.
@@ -38,6 +38,7 @@ import {
38
38
  getDrawnOverlayCard,
39
39
  getListCardsByItem,
40
40
  getListItemTimes,
41
+ getListStops,
41
42
  getNoteCentre,
42
43
  getNoteColors,
43
44
  getNotePaperPoints,
@@ -568,21 +569,27 @@ function getListEvents(overlay: Extract<ResolvedOverlay, { kind: "list" }>, cont
568
569
  getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags: `\\an${align}\\fs${fontSize}${textTags}${clip}`, steps, motion });
569
570
  if (overlay.chips !== undefined) {
570
571
  const covered = getChipCoveredTimes(overlay);
571
- return overlay.chips.flatMap((chip, index) => {
572
- const from = times[index] as number;
572
+ return overlay.chips.flatMap((_chip, index) => {
573
573
  const until = covered[index] ?? null;
574
- const motion = getDraftMotion(overlay, name, chip, context);
575
- const span = { start: from, end: overlay.end, isFirst: true, isLast: true };
576
- const parts = getChipParts(chip, overlay);
577
574
  const text = toAssText(lines[index] as string);
578
575
  // The point leads until the next one is in, then steps back (fainter), as a countdown does (RV-181).
579
576
  const fainter = `{\\1a${toAssAlpha(LIST_CHIP_COVERED_OPACITY)}}`;
580
- const steps = until === null ? [{ from, to: overlay.end, text }] : [{ from, to: until, text }, { from: until, to: overlay.end, text: `${fainter}${text}` }];
581
- return [
582
- ...getCardShapeEvents(overlay, chip, fontSize, colors, motion, context, span),
583
- ...write({ x: parts.textX, y: chip.top + pad.y }, 8, steps, motion),
584
- ...getChipBadgeEvents({ overlay, index, from, until, parts, colors, motion }),
585
- ];
577
+ // The chip's places over time: it slides aside as each later point comes in, so the row stays on the axis (RV-185).
578
+ const places = getChipPlaces(overlay, index);
579
+ return places.flatMap((place, part) => {
580
+ const span = { start: place.start, end: place.end, isFirst: part === 0, isLast: part === places.length - 1 };
581
+ const motion = getPartMotion(getDraftMotion(overlay, name, place.box, context), span);
582
+ const parts = getChipParts(place.box, overlay);
583
+ const steps = [
584
+ { from: place.start, to: until === null ? place.end : Math.min(place.end, until), text },
585
+ { from: until === null ? place.end : Math.max(place.start, until), to: place.end, text: `${fainter}${text}` },
586
+ ].filter((step) => step.to > step.from);
587
+ return [
588
+ ...getCardShapeEvents(overlay, place.box, fontSize, colors, motion, context, span),
589
+ ...write({ x: parts.textX, y: place.box.top + pad.y }, 8, steps, motion),
590
+ ...getChipBadgeEvents({ index, span, until, parts, colors, motion }),
591
+ ];
592
+ });
586
593
  });
587
594
  }
588
595
  // The text sits on the whole list's card: centred on its axis, or from its side.
@@ -620,36 +627,78 @@ function toAssAlpha(opacity: number): string {
620
627
  * is in, the number gives way to a tick drawn in, as the paper note's is.
621
628
  */
622
629
  function getChipBadgeEvents(input: {
623
- overlay: Extract<ResolvedOverlay, { kind: "list" }>;
624
630
  index: number;
625
- from: number;
631
+ span: ShapeSpan;
626
632
  until: number | null;
627
633
  parts: ReturnType<typeof getChipParts>;
628
634
  colors: OverlayColors;
629
635
  motion: DraftMotion;
630
636
  }): string[] {
631
- const { overlay, from, until, parts, colors, motion } = input;
637
+ const { span, until, parts, colors, motion } = input;
632
638
  const { centre, radius } = parts.badge;
633
- const span = { start: from, end: overlay.end };
634
- const mark = getShapeEvent(span, getCircleDrawing(centre, radius), colors.accent, motion, 5);
639
+ const mark = getShapeEvent(span, getCircleDrawing(centre, radius), colors.accent, motion, 5, span);
635
640
  const numberSize = r0(radius * 1.45);
636
- const number = getTextEvents({
637
- layer: 6,
638
- style: "OverlayPlain",
639
- pos: centre,
640
- tags: `\\an5\\fs${numberSize}\\b1\\1c${toTagColor(colors.background)}`,
641
- steps: [{ from, to: until ?? overlay.end, text: String(input.index + 1) }],
642
- motion: until === null ? motion : { ...motion, exit: { ...motion.exit, kind: "none" } },
643
- });
644
- if (until === null) return [mark, ...number];
641
+ const numberEnd = until === null ? span.end : Math.min(span.end, until);
642
+ const number =
643
+ numberEnd > span.start
644
+ ? getTextEvents({
645
+ layer: 6,
646
+ style: "OverlayPlain",
647
+ pos: centre,
648
+ tags: `\\an5\\fs${numberSize}\\b1\\1c${toTagColor(colors.background)}`,
649
+ steps: [{ from: span.start, to: numberEnd, text: String(input.index + 1) }],
650
+ motion: numberEnd === span.end ? motion : { ...motion, exit: { ...motion.exit, kind: "none" } },
651
+ })
652
+ : [];
653
+ if (until === null || until >= span.end) return [mark, ...number];
654
+ // The tick draws in from the next point's second; a part that starts later picks it up as far as it has come.
655
+ const start = Math.max(span.start, until);
656
+ const drawn = Math.min(1, (start - until) / CHIP_TICK_SECONDS);
645
657
  const points = getChipTickPoints(parts.badge);
646
658
  const clip = { x0: r0(centre.x - radius), y0: r0(centre.y - radius), x1: r0(centre.x + radius), y1: r0(centre.y + radius) };
647
- const draw = `${toClip({ ...clip, x1: clip.x0 })}\\t(0,${toMs(CHIP_TICK_SECONDS)},${toClip(clip)})`;
648
- const fade = motion.exit.kind === "none" ? "" : `\\fad(0,${FADE_OUT_MS})`;
649
- const tick = `Dialogue: 6,${toAssTime(until)},${toAssTime(overlay.end)},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${fade}${draw}\\1c${toTagColor(colors.background)}\\p1}${getStrokeDrawing(points, radius * 0.24)}{\\p0}`;
659
+ const draw = drawn >= 1 ? toClip(clip) : `${toClip({ ...clip, x1: r0(clip.x0 + (clip.x1 - clip.x0) * drawn) })}\\t(0,${toMs(CHIP_TICK_SECONDS * (1 - drawn))},${toClip(clip)})`;
660
+ const fade = !span.isLast || motion.exit.kind === "none" ? "" : `\\fad(0,${FADE_OUT_MS})`;
661
+ const tick = `Dialogue: 6,${toAssTime(start)},${toAssTime(span.end)},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${fade}${draw}\\1c${toTagColor(colors.background)}\\p1}${getStrokeDrawing(points, radius * 0.24)}{\\p0}`;
650
662
  return [mark, ...number, tick];
651
663
  }
652
664
 
665
+ /** One stretch a chip stands still for: its box from `start` to `end`. */
666
+ interface ChipPlace {
667
+ start: number;
668
+ end: number;
669
+ box: OverlayBox;
670
+ }
671
+
672
+ /**
673
+ * A chip's places over the list's life (RV-185 of an adopting app): from its own second at its place in the row so far,
674
+ * then, as each later point comes in, `LIST_GROW_STEPS` steps easing it aside along the render's `power3.out` to its
675
+ * place in the wider row, so the chips shown stay on the list's axis. Only the stretches the list shows.
676
+ */
677
+ function getChipPlaces(overlay: Extract<ResolvedOverlay, { kind: "list" }>, index: number): ChipPlace[] {
678
+ const cards = getListCardsByItem(overlay);
679
+ const from = getListItemTimes(overlay)[index] as number;
680
+ const stops = getListStops(overlay).filter((stop) => stop.at >= from);
681
+ const moves = stops.flatMap((stop, at) => {
682
+ const box = (cards[stop.step] as OverlayBox[])[index] as OverlayBox;
683
+ const previous = stops[at - 1];
684
+ if (previous === undefined) return [{ start: stop.at, box }];
685
+ const before = (cards[previous.step] as OverlayBox[])[index] as OverlayBox;
686
+ return Array.from({ length: LIST_GROW_STEPS }, (_step, step) => {
687
+ const share = (step + 1) / LIST_GROW_STEPS;
688
+ return { start: stop.at + (step * LIST_GROW_SECONDS) / LIST_GROW_STEPS, box: step === LIST_GROW_STEPS - 1 ? box : getBoxBetween(before, box, OVERLAY_EASES["power3.out"](share)) };
689
+ });
690
+ });
691
+ return moves
692
+ .map((move, at) => ({ ...move, end: Math.min(overlay.end, moves[at + 1]?.start ?? overlay.end) }))
693
+ .filter((move) => move.start < move.end);
694
+ }
695
+
696
+ /** A part's motion: the entrance only on its first part, the exit only on its last, so a moving chip neither fades nor slides between its parts. */
697
+ function getPartMotion(motion: DraftMotion, span: ShapeSpan): DraftMotion {
698
+ const entered = span.isFirst ? motion : { ...motion, name: "none" as const, entrance: { kind: "none" as const } };
699
+ return span.isLast ? entered : { ...entered, exit: { ...entered.exit, kind: "none" as const } };
700
+ }
701
+
653
702
  type CardOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "search_bar" | "place_card" | "counter" | "date_stamp" }>;
654
703
 
655
704
  /** Each card's own entrance when the overlay names none (a typed card fades its card in). */
@@ -755,7 +804,11 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
755
804
  });
756
805
  if (overlay.kind === "place_card" && overlay.subtitle !== null) {
757
806
  const from = times.subtitle ?? span.start;
758
- events.push(...text({ x: lineX, y: y + fontSize * 0.12 }, lineAlign, overlay.subtitleFontSize, "interface", [{ from, to: span.end, text: toAssText(overlay.subtitle) }], from > span.start ? withFadeEntrance(motion) : motion));
807
+ // A wrapped subtitle draws each of its lines one card line apart, on the same axis (RV-184 of an adopting app).
808
+ (overlay.subtitleLines ?? [overlay.subtitle]).forEach((line, index) => {
809
+ const lineY = y + fontSize * 0.12 + index * overlay.subtitleFontSize * OVERLAY_LINE_HEIGHT;
810
+ events.push(...text({ x: lineX, y: lineY }, lineAlign, overlay.subtitleFontSize, "interface", [{ from, to: span.end, text: toAssText(line) }], from > span.start ? withFadeEntrance(motion) : motion));
811
+ });
759
812
  }
760
813
  return events;
761
814
  }
@@ -35,6 +35,7 @@ import {
35
35
  getPlaceCardPinSize,
36
36
  getListCardsByItem,
37
37
  getListItemTimes,
38
+ getListStops,
38
39
  LIST_CHIP_BADGE_EM,
39
40
  LIST_CHIP_COVERED_OPACITY,
40
41
  getChipCoveredTimes,
@@ -399,8 +400,8 @@ function getListCardSize(card: OverlayBox, pad: { x: number; y: number }): strin
399
400
  /**
400
401
  * A list (RV-144 of an adopting app): a stack, one card whose first point comes in with it and which grows to each next
401
402
  * point as it comes in (eased out, no overshoot; centred lines in the frame's middle without a side), or chips, one card
402
- * per point in its final place of a centred row, each entering on its own second from the left. Every card leaves
403
- * together.
403
+ * per point, each entering on its own second at its place in the row so far, the chips already shown easing aside so
404
+ * the row stays on the list's axis (RV-185 of an adopting app). Every card leaves together.
404
405
  */
405
406
  function addList(overlay: Extract<ResolvedOverlay, { kind: "list" }>, id: string, context: MarkupContext, out: OverlayMarkup): void {
406
407
  const { box, fontSize } = overlay;
@@ -413,9 +414,13 @@ function addList(overlay: Extract<ResolvedOverlay, { kind: "list" }>, id: string
413
414
  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`;
414
415
  if (overlay.chips !== undefined) {
415
416
  const covered = getChipCoveredTimes(overlay);
417
+ const stops = getListStops(overlay);
418
+ // Each chip starts at its place in the row it joins (RV-185 of an adopting app), the shown chips on the list's axis.
419
+ const entered = overlay.chips.map((chip, i) => (cards[stops.find((stop) => stop.at === times[i])?.step ?? -1]?.[i] ?? chip));
416
420
  const chips = overlay.chips.map((chip, i) => {
421
+ const start = entered[i] as OverlayBox;
417
422
  // The badge sits as far from the chip's left edge as from its top.
418
- const place = `left:${chip.left - box.left}px;top:${chip.top - box.top}px;${getListCardSize(chip, pad)} ${pad.y}px ${pad.y}px${i === 0 ? "" : ";visibility:hidden"}${own === "" ? "" : `;${own}`}`;
423
+ const place = `left:${start.left - box.left}px;top:${chip.top - box.top}px;${getListCardSize(chip, pad)} ${pad.y}px ${pad.y}px${i === 0 ? "" : ";visibility:hidden"}${own === "" ? "" : `;${own}`}`;
419
424
  const { radius } = getChipParts(chip, overlay).badge;
420
425
  const size = 2 * radius;
421
426
  const local = getChipTickPoints({ centre: { x: radius, y: radius }, radius });
@@ -431,6 +436,15 @@ function addList(overlay: Extract<ResolvedOverlay, { kind: "list" }>, id: string
431
436
  if (i > 0) out.tweens.push(`tl.set("#${id}c${i}", { visibility: "visible" }, ${at});`);
432
437
  out.tweens.push(...getListCardEntrance(overlay, `#${id}c${i}`, at, context));
433
438
  });
439
+ // As each point comes in, the chips already shown slide aside to keep the row on the axis, as a stack's card grows.
440
+ stops.forEach((stop) => {
441
+ if (stop.at >= overlay.end) return;
442
+ const row = cards[stop.step] as OverlayBox[];
443
+ row.forEach((place, i) => {
444
+ if ((times[i] as number) >= stop.at) return;
445
+ out.tweens.push(`tl.to("#${id}c${i}", { left: ${place.left - box.left}, duration: ${LIST_GROW_SECONDS}, ease: "power3.out" }, ${stop.at});`);
446
+ });
447
+ });
434
448
  // Each point leads until the next one is in, then steps back: fainter, its number turned into a tick (RV-181).
435
449
  covered.forEach((at, i) => {
436
450
  if (at === null) return;
@@ -485,7 +499,9 @@ function getCardBody(overlay: CardOverlay, id: string, colors: OverlayColors, lo
485
499
  };
486
500
  }
487
501
  if (overlay.kind === "place_card") {
488
- const subtitle = overlay.subtitle === null ? "" : `<div class="ov-sub" style="font-size:${overlay.subtitleFontSize}px">${escapeHtml(overlay.subtitle)}</div>`;
502
+ // A wrapped subtitle breaks between its lines (RV-184 of an adopting app); the card's line height spaces them.
503
+ const subtitleHtml = (overlay.subtitleLines ?? (overlay.subtitle === null ? [] : [overlay.subtitle])).map((line) => escapeHtml(line)).join("<br>");
504
+ const subtitle = overlay.subtitle === null ? "" : `<div class="ov-sub" style="font-size:${overlay.subtitleFontSize}px">${subtitleHtml}</div>`;
489
505
  const lines = overlay.lines.map((line) => `<div class="ov-line">${typedOrPlain(line)}</div>`).join("");
490
506
  const pinSize = getPlaceCardPinSize(overlay.fontSize);
491
507
  const pin = overlay.pin === undefined ? "" : `<div class="ov-pinrow" id="${id}p" style="height:${getPlaceCardPinRow(overlay.fontSize)}px">${getPinSvg(colors.accent).replace('class="ov-pin"', `class="ov-pin" style="width:${pinSize}px;height:${pinSize}px"`)}</div>`;
@@ -149,12 +149,19 @@ export const UNDERLINE_EM = { height: 0.09, gap: 0.05 } as const;
149
149
 
150
150
  /**
151
151
  * The film seconds each point of a staggered list comes in at: on its word (`words`, the said times, never before the
152
- * list nor later than its last 0.6 s), else spaced over the first part of its span (0.25 to 0.6 s apart).
152
+ * list nor later than its last 0.6 s, and never before the point ahead of it, so the points come in in their order),
153
+ * else spaced over the first part of its span (0.25 to 0.6 s apart).
153
154
  */
154
155
  export function getListItemStarts(input: { start: number; end: number; count: number; words?: readonly number[] }): number[] {
155
156
  const { start, end, count } = input;
156
157
  const latest = Math.max(start, end - 0.6);
157
- if (input.words !== undefined) return input.words.map((word) => r3(Math.min(latest, Math.max(start, word))));
158
+ if (input.words !== undefined) {
159
+ let previous = start;
160
+ return input.words.map((word) => {
161
+ previous = r3(Math.min(latest, Math.max(previous, word)));
162
+ return previous;
163
+ });
164
+ }
158
165
  const gap = Math.min(0.6, Math.max(0.25, ((end - start) * 0.4) / count));
159
166
  return Array.from({ length: count }, (_item, index) => r3(Math.min(latest, start + 0.2 + index * gap)));
160
167
  }
@@ -98,6 +98,12 @@ export const LIST_CHIP_COVERED_OPACITY = 0.55;
98
98
  * shrinking down to it, so the step badges never turn a row that fitted without them into a refusal.
99
99
  */
100
100
  export const LIST_CHIP_MIN_FONT_SIZE = 36;
101
+ /**
102
+ * The smallest type a row of chips shrinks to so it can sit on the frame's axis (RV-185 of an adopting app), in px of a
103
+ * 1080 px wide frame: in the centred span only, where a row that fits the whole zone at `LIST_CHIP_MIN_FONT_SIZE` would
104
+ * otherwise stand off the axis.
105
+ */
106
+ export const LIST_CHIP_CENTRED_MIN_FONT_SIZE = 32;
101
107
  /** A place card title's line height, tighter for its big type. */
102
108
  export const OVERLAY_TITLE_LINE_HEIGHT = 1.05;
103
109
  export const OVERLAY_PADDING_EM = { x: 0.6, y: 0.35 } as const;
@@ -208,6 +214,11 @@ export type ResolvedOverlay =
208
214
  isCentred?: boolean;
209
215
  /** Each point's own card in one row (`style.list_layout` chips, or auto when they fit); absent: one stacked card. */
210
216
  chips?: OverlayBox[];
217
+ /**
218
+ * The x the chips shown so far centre on, the frame's axis (RV-185 of an adopting app), kept inside `box`; absent
219
+ * (a list resolved before it): the full row's middle.
220
+ */
221
+ chipAxis?: number;
211
222
  })
212
223
  | (Drawn & { kind: "arrow"; from: OverlayPoint; to: OverlayPoint })
213
224
  | (Drawn & { kind: "highlight"; rect: OverlayBox })
@@ -235,6 +246,11 @@ export type ResolvedOverlay =
235
246
  pin?: "static" | "drop";
236
247
  /** Seconds its subtitle waits after its title (`style.subtitle_delay`); absent: none. */
237
248
  subtitleDelay?: number;
249
+ /**
250
+ * Its subtitle's two balanced lines when one line does not fit the card's room at its smallest size, so the
251
+ * card stays on the frame's axis (RV-184 of an adopting app); absent: one line, `subtitle`.
252
+ */
253
+ subtitleLines?: string[];
238
254
  })
239
255
  | (Drawn & { kind: "counter"; value: number; from: number; decimals: number; unit: string | null; fontSize: number; unitFontSize: number; box: OverlayBox })
240
256
  | (Drawn & { kind: "date_stamp"; text: string; place: string | null; fontSize: number; placeFontSize: number; side: OverlaySide; box: OverlayBox })
@@ -307,11 +323,14 @@ function findOverlayStart(overlay: EdlOverlay, words: TimedWord[]): { ok: true;
307
323
  }
308
324
 
309
325
  /** The film second a word of the transcript starts at, or why it is not there (`field` names it in the reason). */
310
- function findWordStart(wanted: NonNullable<EdlOverlay["at_word"]>, words: TimedWord[], field: string): { ok: true; start: number } | { ok: false; error: string } {
326
+ function findWordStart(wanted: NonNullable<EdlOverlay["at_word"]>, words: TimedWord[], field: string, from?: number): { ok: true; start: number } | { ok: false; error: string } {
311
327
  const key = normalizeWord(wanted.text);
312
328
  const occurrence = wanted.occurrence ?? 1;
313
329
  const matches = words.filter((word) => normalizeWord(word.text) === key);
314
- const word = matches[occurrence - 1];
330
+ // A list's point is said after the list starts (RV-192 of an adopting app): its occurrence counts from there, and only
331
+ // a word the list never reaches falls back to the whole cut's count, as before.
332
+ const after = from === undefined ? [] : matches.filter((word) => word.start >= from - WORD_START_TOLERANCE);
333
+ const word = after[occurrence - 1] ?? matches[occurrence - 1];
315
334
  if (word === undefined) {
316
335
  const said = matches.length === 0 ? "the film never says it" : `the film says it ${matches.length} time${matches.length === 1 ? "" : "s"}`;
317
336
  return { ok: false, error: `${field}: no word "${wanted.text}"${occurrence > 1 ? ` (occurrence ${occurrence})` : ""} in the cut; ${said}` };
@@ -319,6 +338,9 @@ function findWordStart(wanted: NonNullable<EdlOverlay["at_word"]>, words: TimedW
319
338
  return { ok: true, start: word.start };
320
339
  }
321
340
 
341
+ /** How far before a list's start its point's word may begin and still count as said after it: one frame at 30 fps. */
342
+ const WORD_START_TOLERANCE = 0.034;
343
+
322
344
  const r1 = (value: number): number => Math.round(value * 10) / 10;
323
345
  const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
324
346
 
@@ -440,13 +462,22 @@ function getBoxesUnion(boxes: readonly OverlayBox[]): OverlayBox {
440
462
  * A list's drawn boxes after each point has come in (RV-144 of an adopting app): `cards[i]` is what shows once points
441
463
  * 0 to i are in. A stack's card grows with each point, fitted to the points in so far (one line taller, as wide as the
442
464
  * widest), so it never stands sized for the whole list nor empty: its first point comes in with it. Chips add one
443
- * card at a time, each in its final place (`overlay.chips`), so the row is centred once complete and nothing already
444
- * shown moves. Every entry holds one box per drawn card.
465
+ * card at a time, and the chips shown so far are always a row of their own on the frame's axis (`chipAxis`, RV-185 of
466
+ * an adopting app), as close to it as the box allows, their sizes and gaps kept; the last step is the full row
467
+ * (`overlay.chips`) exactly. Every entry holds one box per drawn card.
445
468
  */
446
469
  export function getListCardsByItem(overlay: Extract<ResolvedOverlay, { kind: "list" }>): OverlayBox[][] {
447
470
  if (overlay.chips !== undefined) {
448
471
  const chips = overlay.chips;
449
- return chips.map((_chip, index) => chips.slice(0, index + 1));
472
+ const first = (chips[0] as OverlayBox).left;
473
+ const axis = overlay.chipAxis ?? (first + getChipRight(chips[chips.length - 1] as OverlayBox)) / 2;
474
+ const { box } = overlay;
475
+ return chips.map((chip, index) => {
476
+ if (index === chips.length - 1) return chips;
477
+ const width = getChipRight(chip) - first;
478
+ const left = Math.round(Math.max(box.left, Math.min(box.left + box.width - width, axis - width / 2)));
479
+ return chips.slice(0, index + 1).map((shown) => ({ ...shown, left: shown.left - first + left }));
480
+ });
450
481
  }
451
482
  const lines = getSideTextLines(overlay);
452
483
  const padY = getOverlayPadding(overlay).y;
@@ -456,6 +487,21 @@ export function getListCardsByItem(overlay: Extract<ResolvedOverlay, { kind: "li
456
487
  });
457
488
  }
458
489
 
490
+ /** A chip's right edge, in px of the frame. */
491
+ function getChipRight(chip: OverlayBox): number {
492
+ return chip.left + chip.width;
493
+ }
494
+
495
+ /**
496
+ * Which step of `getListCardsByItem` shows from each distinct second a list's points come in at (RV-185 of an adopting
497
+ * app): points on the same second come in together, so the step is the last of them. In time order, the first at the
498
+ * list's start.
499
+ */
500
+ export function getListStops(overlay: Extract<ResolvedOverlay, { kind: "list" }>): { at: number; step: number }[] {
501
+ const times = getListItemTimes(overlay);
502
+ return times.flatMap((at, step) => (times[step + 1] === at ? [] : [{ at, step }]));
503
+ }
504
+
459
505
  /** The film seconds each point of a list comes in at: its own (`itemStarts`), the first with the card; else all with the card. */
460
506
  export function getListItemTimes(overlay: Extract<ResolvedOverlay, { kind: "list" }>): number[] {
461
507
  return overlay.items.map((_item, index) => (index === 0 ? overlay.start : (overlay.itemStarts?.[index] ?? overlay.start)));
@@ -550,7 +596,7 @@ export function resolveEdlOverlays(input: ResolveOverlaysInput): ResolvedOverlay
550
596
  // Chips always come in one by one, as a countdown of the points (RV-181 of an adopting app); a stack only when asked.
551
597
  const isStaggered = overlay.style?.stagger === true || overlay.item_words !== undefined || overlay.item_at !== undefined;
552
598
  if (placed.overlay.kind === "list" && (isStaggered || placed.overlay.chips !== undefined)) {
553
- const said = (overlay.item_words ?? []).map((word, item) => findWordStart(word, input.words, `item_words[${item}]`));
599
+ const said = (overlay.item_words ?? []).map((word, item) => findWordStart(word, input.words, `item_words[${item}]`, start));
554
600
  const missing = said.flatMap((word) => (word.ok ? [] : [word.error]));
555
601
  if (missing.length > 0) {
556
602
  problems.push(...missing.map((error) => `${at}.${error}`));
@@ -680,10 +726,19 @@ function getCentredSpan(place: Pick<Placement, "zone" | "frame">, margin: number
680
726
  * wider than the centred span, else again in the centred span (smaller or on more lines), and only when it cannot fit
681
727
  * there either in the whole zone, as close to the axis as the zone allows. What fitted before still fits.
682
728
  */
683
- function measureCentred<T extends { ok: true } | { ok: false; error: string }>(input: { whole: number; centred: number; measure: (room: number) => T; getWidth: (result: T & { ok: true }) => number }): T {
684
- const wide = input.measure(input.whole);
685
- if (!wide.ok || input.getWidth(wide as T & { ok: true }) <= input.centred) return wide;
686
- const narrow = input.measure(input.centred);
729
+ function measureCentred<T extends { ok: true } | { ok: false; error: string }>(input: {
730
+ whole: number;
731
+ centred: number;
732
+ /** Measures in `room`; `isCentred` is true for the second measure, in the centred span. */
733
+ measure: (room: number, isCentred: boolean) => T;
734
+ getWidth: (result: T & { ok: true }) => number;
735
+ /** Measure in the centred span also when the whole zone refuses it (a measure that fits more there, a place card). */
736
+ isRetriedWhenRefused?: boolean;
737
+ }): T {
738
+ const wide = input.measure(input.whole, false);
739
+ if (!wide.ok && input.isRetriedWhenRefused !== true) return wide;
740
+ if (wide.ok && input.getWidth(wide as T & { ok: true }) <= input.centred) return wide;
741
+ const narrow = input.measure(input.centred, true);
687
742
  return narrow.ok ? narrow : wide;
688
743
  }
689
744
 
@@ -908,8 +963,11 @@ function placeSideText(overlay: EdlOverlay & { kind: "keyword" | "lower_third" |
908
963
  const chips = overlay.kind === "list" ? measureCentred({
909
964
  whole: room,
910
965
  centred: getCentredSpan(place, margin).width,
911
- measure: (width: number) => getListChipLayout({ items: overlay.items ?? [], layout: overlay.style?.list_layout ?? "stack", fontSize, minFontSize: Math.round(LIST_CHIP_MIN_FONT_SIZE * scale), padScale: place.padScale, room: width }),
966
+ measure: (width: number, isCentred: boolean) =>
967
+ getListChipLayout({ items: overlay.items ?? [], layout: overlay.style?.list_layout ?? "stack", fontSize, minFontSize: Math.round((isCentred ? LIST_CHIP_CENTRED_MIN_FONT_SIZE : LIST_CHIP_MIN_FONT_SIZE) * scale), padScale: place.padScale, room: width }),
912
968
  getWidth: (result) => result.row?.width ?? 0,
969
+ // A row refused in the whole zone may still fit the centred span a little smaller.
970
+ isRetriedWhenRefused: true,
913
971
  }) : null;
914
972
  if (chips !== null && !chips.ok) return chips;
915
973
  const row = chips?.row ?? null;
@@ -928,7 +986,7 @@ function placeSideText(overlay: EdlOverlay & { kind: "keyword" | "lower_third" |
928
986
  const centred = { ...box, ...getCentredSpan(place, margin) };
929
987
  if (overlay.kind === "list") {
930
988
  const isCentred = row === null && overlay.style?.side === undefined;
931
- const layout = row !== null ? { chips: placeChipRow(row, { ...box, left: getCentredLeft(place, row.width, margin), width: row.width }) } : isCentred ? { isCentred: true } : {};
989
+ const layout = row !== null ? { chips: placeChipRow(row, { ...box, left: getCentredLeft(place, row.width, margin), width: row.width }), chipAxis: place.frame.width / 2 } : isCentred ? { isCentred: true } : {};
932
990
  // A row of chips may be drawn smaller than the list's size, to fit one row.
933
991
  return { ok: true, overlay: { ...drawn, kind: "list", items: overlay.items ?? [], fontSize: row?.fontSize ?? fontSize, side, box: isCentred ? centred : box, ...layout } };
934
992
  }
@@ -1016,15 +1074,16 @@ export function getChipTickPoints(badge: { centre: OverlayPoint; radius: number
1016
1074
  }
1017
1075
 
1018
1076
  /**
1019
- * When each chip of a row is covered: the second the next point comes in, after which the chip steps back (its point
1020
- * fainter, its number a tick) and the newest point leads, as a countdown does; null for the last chip, and for one
1021
- * whose next point comes in with it or after the list has gone.
1077
+ * When each chip of a row is covered: the first second a later point comes in after it, after which the chip steps
1078
+ * back (its point fainter, its number a tick) and the newest point leads, as a countdown does. So every point before
1079
+ * the one leading is ticked, in order, even when two came in together (RV-192 of an adopting app). Null for the
1080
+ * points that lead last, and for one whose next point comes in only after the list has gone.
1022
1081
  */
1023
1082
  export function getChipCoveredTimes(overlay: Extract<ResolvedOverlay, { kind: "list" }>): (number | null)[] {
1024
1083
  const times = getListItemTimes(overlay);
1025
1084
  return times.map((at, index) => {
1026
- const next = times[index + 1];
1027
- return next !== undefined && next > at && next < overlay.end ? next : null;
1085
+ const next = times.slice(index + 1).find((later) => later > at);
1086
+ return next !== undefined && next < overlay.end ? next : null;
1028
1087
  });
1029
1088
  }
1030
1089
 
@@ -1083,9 +1142,12 @@ export function wrapOverlayTitle(text: string, fontSize: number, width: number):
1083
1142
  return best;
1084
1143
  }
1085
1144
 
1086
- /** 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. */
1087
- function fitTitle(text: string, fontSize: number, room: number): { lines: string[]; fontSize: number } | null {
1088
- for (let shrink = 0, size = fontSize; shrink <= MAX_TITLE_SHRINKS; shrink++, size = Math.round(size * OVERLAY_TITLE_SHRINK)) {
1145
+ /**
1146
+ * A title's lines and font size: its own size, else smaller by `OVERLAY_TITLE_SHRINK` until it fits two lines, at most
1147
+ * `maxShrinks` times; null when it never does.
1148
+ */
1149
+ function fitTitle(text: string, fontSize: number, room: number, maxShrinks = MAX_TITLE_SHRINKS): { lines: string[]; fontSize: number } | null {
1150
+ for (let shrink = 0, size = fontSize; shrink <= maxShrinks; shrink++, size = Math.round(size * OVERLAY_TITLE_SHRINK)) {
1089
1151
  const lines = wrapOverlayTitle(text, size, room);
1090
1152
  if (lines.length <= MAX_OVERLAY_TITLE_LINES && lines.every((line) => estimateTextWidth(line, size) <= room)) return { lines, fontSize: size };
1091
1153
  }
@@ -1097,12 +1159,45 @@ function fitTitle(text: string, fontSize: number, room: number): { lines: string
1097
1159
  * long for that shrinks to fit `room`, never below the `s` step (the size every subtitle had before, so nothing that
1098
1160
  * fitted then is refused now).
1099
1161
  */
1100
- function getSubtitleSize(input: { subtitle: string; titleSize: number; step: OverlaySize; room: number; scale: number }): number {
1101
- const wanted = Math.max(Math.round(MIN_OVERLAY_SUBTITLE_PX * input.scale), Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES[input.step]));
1162
+ function getSubtitleSize(input: { subtitle: string; titleSize: number; step: OverlaySize; room: number; scale: number; isCentred?: boolean }): number {
1163
+ const smallest = Math.round(MIN_OVERLAY_SUBTITLE_PX * input.scale);
1164
+ const wanted = Math.max(smallest, Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES[input.step]));
1102
1165
  const fitting = Math.floor(input.room / ([...input.subtitle].length * OVERLAY_CHAR_EM));
1103
- return Math.min(wanted, Math.max(fitting, Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES.s)));
1166
+ // In the centred span a subtitle may go down to `MIN_OVERLAY_SUBTITLE_PX` too when the `s` step is above it.
1167
+ const floor = Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES.s);
1168
+ return Math.min(wanted, Math.max(fitting, input.isCentred === true ? Math.min(floor, smallest) : floor));
1104
1169
  }
1105
1170
 
1171
+ /**
1172
+ * A place card's subtitle: one line at `getSubtitleSize` when it fits `room` (what fitted before keeps its size), else
1173
+ * two balanced lines, each sized as one line would be; null when even two lines are too wide (RV-184 of an adopting
1174
+ * app: a card whose subtitle cannot fit the centred span is placed off the frame's axis).
1175
+ */
1176
+ function fitPlaceSubtitle(input: { subtitle: string; titleSize: number; step: OverlaySize; room: number; scale: number; isCentred: boolean }): { lines: string[]; size: number } | null {
1177
+ const size = getSubtitleSize(input);
1178
+ if (estimateTextWidth(input.subtitle, size) <= input.room) return { lines: [input.subtitle], size };
1179
+ const lines = splitInTwoLines(input.subtitle);
1180
+ if (lines === null) return null;
1181
+ const longest = lines.reduce((widest, line) => ([...line].length > [...widest].length ? line : widest));
1182
+ const lineSize = getSubtitleSize({ ...input, subtitle: longest });
1183
+ return lines.every((line) => estimateTextWidth(line, lineSize) <= input.room) ? { lines, size: lineSize } : null;
1184
+ }
1185
+
1186
+ /** A text's two lines of words as even as they can be (the longer line as short as it can be); null for one word. */
1187
+ function splitInTwoLines(text: string): [string, string] | null {
1188
+ const words = text.split(/\s+/).filter((part) => part.length > 0);
1189
+ if (words.length < 2) return null;
1190
+ let best: [string, string] = [words[0] as string, words.slice(1).join(" ")];
1191
+ for (let split = 2; split < words.length; split++) {
1192
+ const pair: [string, string] = [words.slice(0, split).join(" "), words.slice(split).join(" ")];
1193
+ if (Math.max(...pair.map((line) => [...line].length)) < Math.max(...best.map((line) => [...line].length))) best = pair;
1194
+ }
1195
+ return best;
1196
+ }
1197
+
1198
+ /** A place card's title may shrink this many steps more in the centred span than in the whole zone (0.9² ≈ 0.81). */
1199
+ const CENTRED_TITLE_EXTRA_SHRINKS = 2;
1200
+
1106
1201
  /** A hook title's or a place card's second line: the place label (with its pin) or the subtitle. */
1107
1202
  type TitleOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "place_card" }>;
1108
1203
 
@@ -1111,17 +1206,29 @@ type TitleOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "place_card"
1111
1206
  * its pin, the subtitle, each title line) and its height. Its card is this plus the padding, so the draft and the
1112
1207
  * render find the block's left edge and top inside the card from it whatever the title's fitted size.
1113
1208
  */
1114
- export function getTitleContentSize(input: { kind: TitleOverlay["kind"]; lines: readonly string[]; fontSize: number; second: string | null; secondSize: number; pin?: boolean }): {
1209
+ export function getTitleContentSize(input: {
1210
+ kind: TitleOverlay["kind"];
1211
+ lines: readonly string[];
1212
+ fontSize: number;
1213
+ second: string | null;
1214
+ secondSize: number;
1215
+ pin?: boolean;
1216
+ /** A place card's wrapped subtitle (`subtitleLines`); absent: `second` on one line. */
1217
+ secondLines?: readonly string[];
1218
+ }): {
1115
1219
  width: number;
1116
1220
  height: number;
1117
1221
  } {
1118
1222
  const { kind, lines, fontSize, second, secondSize } = input;
1119
1223
  const isHook = kind === "hook_title";
1120
- const secondWidth = second === null ? 0 : estimateTextWidth(second, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0);
1224
+ const seconds = second === null ? [] : (input.secondLines ?? [second]);
1225
+ const secondWidth = Math.max(0, ...seconds.map((line) => estimateTextWidth(line, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0)));
1121
1226
  const lineHeight = isHook ? OVERLAY_LINE_HEIGHT : OVERLAY_TITLE_LINE_HEIGHT;
1227
+ // A wrapped subtitle's further lines each add a card line (`OVERLAY_LINE_HEIGHT`), as the render's `<br>` does.
1228
+ const secondHeight = seconds.length === 0 ? 0 : secondSize * 1.3 + fontSize * 0.12 + (seconds.length - 1) * secondSize * OVERLAY_LINE_HEIGHT;
1122
1229
  return {
1123
1230
  width: Math.max(secondWidth, input.pin === true ? getPlaceCardPinSize(fontSize) : 0, ...lines.map((line) => estimateTextWidth(line, fontSize))),
1124
- height: lines.length * fontSize * lineHeight + (second === null ? 0 : secondSize * 1.3 + fontSize * 0.12) + (input.pin === true ? getPlaceCardPinRow(fontSize) : 0),
1231
+ height: lines.length * fontSize * lineHeight + secondHeight + (input.pin === true ? getPlaceCardPinRow(fontSize) : 0),
1125
1232
  };
1126
1233
  }
1127
1234
 
@@ -1139,26 +1246,37 @@ export function getPlaceCardPinRow(fontSize: number): number {
1139
1246
  export function getTitleContentBox(overlay: TitleOverlay): OverlayBox {
1140
1247
  const second = overlay.kind === "hook_title" ? overlay.place : overlay.subtitle;
1141
1248
  const secondSize = overlay.kind === "hook_title" ? overlay.placeFontSize : overlay.subtitleFontSize;
1142
- const size = getTitleContentSize({ kind: overlay.kind, lines: overlay.lines, fontSize: overlay.fontSize, second, secondSize, pin: overlay.kind === "place_card" && overlay.pin !== undefined });
1249
+ const isPlace = overlay.kind === "place_card";
1250
+ const size = getTitleContentSize({
1251
+ kind: overlay.kind,
1252
+ lines: overlay.lines,
1253
+ fontSize: overlay.fontSize,
1254
+ second,
1255
+ secondSize,
1256
+ pin: isPlace && overlay.pin !== undefined,
1257
+ ...(isPlace && overlay.subtitleLines !== undefined ? { secondLines: overlay.subtitleLines } : {}),
1258
+ });
1143
1259
  const { box } = overlay;
1144
1260
  return { left: box.left + (box.width - size.width) / 2, top: box.top + (box.height - size.height) / 2, width: size.width, height: size.height };
1145
1261
  }
1146
1262
 
1147
1263
  /** A hook title's or a place card's lines and second line, aligned as its style says. */
1148
- function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card" }, metrics: CardMetrics): CardResult {
1264
+ function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card" }, metrics: CardMetrics, isCentred = false): CardResult {
1149
1265
  const { room, label } = metrics;
1150
- const fitted = fitTitle(overlay.text ?? "", metrics.fontSize, room);
1266
+ const isHook = overlay.kind === "hook_title";
1267
+ // In the centred span a place card's title may shrink further, so a card that fitted the whole zone stays on the axis.
1268
+ const fitted = fitTitle(overlay.text ?? "", metrics.fontSize, room, MAX_TITLE_SHRINKS + (isCentred && !isHook ? CENTRED_TITLE_EXTRA_SHRINKS : 0));
1151
1269
  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` };
1152
1270
  const { lines, fontSize } = fitted;
1153
- const isHook = overlay.kind === "hook_title";
1154
1271
  const second = (isHook ? overlay.place : overlay.subtitle) ?? null;
1155
- const secondSize =
1156
- !isHook && second !== null
1157
- ? getSubtitleSize({ subtitle: second, titleSize: metrics.fontSize, step: overlay.style?.subtitle_size ?? "m", room, scale: metrics.scale })
1158
- : Math.round(metrics.fontSize * OVERLAY_SECONDARY_SCALE[overlay.kind]);
1272
+ const subtitle =
1273
+ !isHook && second !== null ? fitPlaceSubtitle({ subtitle: second, titleSize: metrics.fontSize, step: overlay.style?.subtitle_size ?? "m", room, scale: metrics.scale, isCentred }) : null;
1274
+ if (!isHook && second !== null && subtitle === null) return tooWide(metrics, "subtitle");
1275
+ const secondSize = subtitle?.size ?? Math.round(metrics.fontSize * OVERLAY_SECONDARY_SCALE[overlay.kind]);
1276
+ const subtitleLines = subtitle !== null && subtitle.lines.length > 1 ? subtitle.lines : undefined;
1159
1277
  // The hook title's place label carries a pin about one label line wide before it.
1160
- const secondWidth = second === null ? 0 : estimateTextWidth(second, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0);
1161
- if (secondWidth > room) return tooWide(metrics, isHook ? "place label" : "subtitle");
1278
+ const secondWidth = second === null || !isHook ? 0 : estimateTextWidth(second, secondSize) + Math.round(secondSize * 1.1);
1279
+ if (secondWidth > room) return tooWide(metrics, "place label");
1162
1280
  // A title's align is center or left (the schema refuses right on it).
1163
1281
  const align: OverlayAlign = overlay.style?.align === "left" ? "left" : "center";
1164
1282
  const pin = !isHook && overlay.style?.pin !== undefined && overlay.style.pin !== "none" ? overlay.style.pin : undefined;
@@ -1166,10 +1284,20 @@ function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card"
1166
1284
  return {
1167
1285
  ok: true,
1168
1286
  content: {
1169
- ...getTitleContentSize({ kind: overlay.kind, lines, fontSize, second, secondSize, pin: pin !== undefined }),
1287
+ ...getTitleContentSize({ kind: overlay.kind, lines, fontSize, second, secondSize, pin: pin !== undefined, ...(subtitleLines === undefined ? {} : { secondLines: subtitleLines }) }),
1170
1288
  fields: isHook
1171
1289
  ? { kind: "hook_title", lines, place: second, fontSize, placeFontSize: secondSize, align, ...(overlay.style?.backdrop === "highlight" ? { backdrop: "highlight" } : {}) }
1172
- : { kind: "place_card", lines, subtitle: second, fontSize, subtitleFontSize: secondSize, align, ...(pin === undefined ? {} : { pin }), ...(delay === undefined ? {} : { subtitleDelay: delay }) },
1290
+ : {
1291
+ kind: "place_card",
1292
+ lines,
1293
+ subtitle: second,
1294
+ fontSize,
1295
+ subtitleFontSize: secondSize,
1296
+ align,
1297
+ ...(pin === undefined ? {} : { pin }),
1298
+ ...(delay === undefined ? {} : { subtitleDelay: delay }),
1299
+ ...(subtitleLines === undefined ? {} : { subtitleLines }),
1300
+ },
1173
1301
  },
1174
1302
  };
1175
1303
  }
@@ -1227,10 +1355,10 @@ function placeCard(overlay: EdlOverlay & { kind: CardKind }, drawn: Drawn, place
1227
1355
  const outer = frame.width - zone.left - zone.right - 2 * margin;
1228
1356
  const fontSize = Math.round(OVERLAY_FONT_SIZES[overlay.kind][overlay.style?.size ?? "m"] * scale);
1229
1357
  const pad = getOverlayPadding({ fontSize, padScale: place.padScale });
1230
- const measure = (room: number): CardResult => {
1358
+ const measure = (room: number, isCentred = false): CardResult => {
1231
1359
  const metrics = { fontSize, pad, room: room - 2 * pad.x, label: overlay.kind.replace("_", " "), scale };
1232
1360
  return overlay.kind === "hook_title" || overlay.kind === "place_card"
1233
- ? measureTitle({ ...overlay, kind: overlay.kind }, metrics)
1361
+ ? measureTitle({ ...overlay, kind: overlay.kind }, metrics, isCentred)
1234
1362
  : overlay.kind === "search_bar"
1235
1363
  ? measureSearchBar(overlay, metrics)
1236
1364
  : overlay.kind === "counter"
@@ -1241,7 +1369,13 @@ function placeCard(overlay: EdlOverlay & { kind: CardKind }, drawn: Drawn, place
1241
1369
  const measured =
1242
1370
  overlay.kind === "date_stamp"
1243
1371
  ? measure(outer)
1244
- : measureCentred({ whole: outer, centred: getCentredSpan(place, margin).width, measure, getWidth: (result) => Math.ceil(result.content.width + 2 * pad.x) });
1372
+ : measureCentred({
1373
+ whole: outer,
1374
+ centred: getCentredSpan(place, margin).width,
1375
+ measure,
1376
+ getWidth: (result) => Math.ceil(result.content.width + 2 * pad.x),
1377
+ isRetriedWhenRefused: overlay.kind === "place_card",
1378
+ });
1245
1379
  if (!measured.ok) return measured;
1246
1380
  const { content } = measured;
1247
1381
  const width = Math.ceil(content.width + 2 * pad.x);