@softure-ai/marketing-kit 0.38.0 → 0.39.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>`;
@@ -93,6 +93,17 @@ export const LIST_CHIP_GAP_EM = 0.3;
93
93
  export const LIST_CHIP_BADGE_EM = { size: 1.1, gap: 0.35 } as const;
94
94
  /** How opaque a chip's point stays once the next point is in: it steps back, the newest point leads. */
95
95
  export const LIST_CHIP_COVERED_OPACITY = 0.55;
96
+ /**
97
+ * The smallest type a row of chips shrinks to, in px of a 1080 px wide frame: past a title's three shrinks a row keeps
98
+ * shrinking down to it, so the step badges never turn a row that fitted without them into a refusal.
99
+ */
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;
96
107
  /** A place card title's line height, tighter for its big type. */
97
108
  export const OVERLAY_TITLE_LINE_HEIGHT = 1.05;
98
109
  export const OVERLAY_PADDING_EM = { x: 0.6, y: 0.35 } as const;
@@ -203,6 +214,11 @@ export type ResolvedOverlay =
203
214
  isCentred?: boolean;
204
215
  /** Each point's own card in one row (`style.list_layout` chips, or auto when they fit); absent: one stacked card. */
205
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;
206
222
  })
207
223
  | (Drawn & { kind: "arrow"; from: OverlayPoint; to: OverlayPoint })
208
224
  | (Drawn & { kind: "highlight"; rect: OverlayBox })
@@ -230,6 +246,11 @@ export type ResolvedOverlay =
230
246
  pin?: "static" | "drop";
231
247
  /** Seconds its subtitle waits after its title (`style.subtitle_delay`); absent: none. */
232
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[];
233
254
  })
234
255
  | (Drawn & { kind: "counter"; value: number; from: number; decimals: number; unit: string | null; fontSize: number; unitFontSize: number; box: OverlayBox })
235
256
  | (Drawn & { kind: "date_stamp"; text: string; place: string | null; fontSize: number; placeFontSize: number; side: OverlaySide; box: OverlayBox })
@@ -435,13 +456,22 @@ function getBoxesUnion(boxes: readonly OverlayBox[]): OverlayBox {
435
456
  * A list's drawn boxes after each point has come in (RV-144 of an adopting app): `cards[i]` is what shows once points
436
457
  * 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
437
458
  * widest), so it never stands sized for the whole list nor empty: its first point comes in with it. Chips add one
438
- * card at a time, each in its final place (`overlay.chips`), so the row is centred once complete and nothing already
439
- * shown moves. Every entry holds one box per drawn card.
459
+ * 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
460
+ * an adopting app), as close to it as the box allows, their sizes and gaps kept; the last step is the full row
461
+ * (`overlay.chips`) exactly. Every entry holds one box per drawn card.
440
462
  */
441
463
  export function getListCardsByItem(overlay: Extract<ResolvedOverlay, { kind: "list" }>): OverlayBox[][] {
442
464
  if (overlay.chips !== undefined) {
443
465
  const chips = overlay.chips;
444
- return chips.map((_chip, index) => chips.slice(0, index + 1));
466
+ const first = (chips[0] as OverlayBox).left;
467
+ const axis = overlay.chipAxis ?? (first + getChipRight(chips[chips.length - 1] as OverlayBox)) / 2;
468
+ const { box } = overlay;
469
+ return chips.map((chip, index) => {
470
+ if (index === chips.length - 1) return chips;
471
+ const width = getChipRight(chip) - first;
472
+ const left = Math.round(Math.max(box.left, Math.min(box.left + box.width - width, axis - width / 2)));
473
+ return chips.slice(0, index + 1).map((shown) => ({ ...shown, left: shown.left - first + left }));
474
+ });
445
475
  }
446
476
  const lines = getSideTextLines(overlay);
447
477
  const padY = getOverlayPadding(overlay).y;
@@ -451,6 +481,21 @@ export function getListCardsByItem(overlay: Extract<ResolvedOverlay, { kind: "li
451
481
  });
452
482
  }
453
483
 
484
+ /** A chip's right edge, in px of the frame. */
485
+ function getChipRight(chip: OverlayBox): number {
486
+ return chip.left + chip.width;
487
+ }
488
+
489
+ /**
490
+ * Which step of `getListCardsByItem` shows from each distinct second a list's points come in at (RV-185 of an adopting
491
+ * app): points on the same second come in together, so the step is the last of them. In time order, the first at the
492
+ * list's start.
493
+ */
494
+ export function getListStops(overlay: Extract<ResolvedOverlay, { kind: "list" }>): { at: number; step: number }[] {
495
+ const times = getListItemTimes(overlay);
496
+ return times.flatMap((at, step) => (times[step + 1] === at ? [] : [{ at, step }]));
497
+ }
498
+
454
499
  /** The film seconds each point of a list comes in at: its own (`itemStarts`), the first with the card; else all with the card. */
455
500
  export function getListItemTimes(overlay: Extract<ResolvedOverlay, { kind: "list" }>): number[] {
456
501
  return overlay.items.map((_item, index) => (index === 0 ? overlay.start : (overlay.itemStarts?.[index] ?? overlay.start)));
@@ -675,10 +720,19 @@ function getCentredSpan(place: Pick<Placement, "zone" | "frame">, margin: number
675
720
  * wider than the centred span, else again in the centred span (smaller or on more lines), and only when it cannot fit
676
721
  * there either in the whole zone, as close to the axis as the zone allows. What fitted before still fits.
677
722
  */
678
- 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 {
679
- const wide = input.measure(input.whole);
680
- if (!wide.ok || input.getWidth(wide as T & { ok: true }) <= input.centred) return wide;
681
- const narrow = input.measure(input.centred);
723
+ function measureCentred<T extends { ok: true } | { ok: false; error: string }>(input: {
724
+ whole: number;
725
+ centred: number;
726
+ /** Measures in `room`; `isCentred` is true for the second measure, in the centred span. */
727
+ measure: (room: number, isCentred: boolean) => T;
728
+ getWidth: (result: T & { ok: true }) => number;
729
+ /** Measure in the centred span also when the whole zone refuses it (a measure that fits more there, a place card). */
730
+ isRetriedWhenRefused?: boolean;
731
+ }): T {
732
+ const wide = input.measure(input.whole, false);
733
+ if (!wide.ok && input.isRetriedWhenRefused !== true) return wide;
734
+ if (wide.ok && input.getWidth(wide as T & { ok: true }) <= input.centred) return wide;
735
+ const narrow = input.measure(input.centred, true);
682
736
  return narrow.ok ? narrow : wide;
683
737
  }
684
738
 
@@ -903,8 +957,11 @@ function placeSideText(overlay: EdlOverlay & { kind: "keyword" | "lower_third" |
903
957
  const chips = overlay.kind === "list" ? measureCentred({
904
958
  whole: room,
905
959
  centred: getCentredSpan(place, margin).width,
906
- measure: (width: number) => getListChipLayout({ items: overlay.items ?? [], layout: overlay.style?.list_layout ?? "stack", fontSize, padScale: place.padScale, room: width }),
960
+ measure: (width: number, isCentred: boolean) =>
961
+ 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 }),
907
962
  getWidth: (result) => result.row?.width ?? 0,
963
+ // A row refused in the whole zone may still fit the centred span a little smaller.
964
+ isRetriedWhenRefused: true,
908
965
  }) : null;
909
966
  if (chips !== null && !chips.ok) return chips;
910
967
  const row = chips?.row ?? null;
@@ -923,7 +980,7 @@ function placeSideText(overlay: EdlOverlay & { kind: "keyword" | "lower_third" |
923
980
  const centred = { ...box, ...getCentredSpan(place, margin) };
924
981
  if (overlay.kind === "list") {
925
982
  const isCentred = row === null && overlay.style?.side === undefined;
926
- const layout = row !== null ? { chips: placeChipRow(row, { ...box, left: getCentredLeft(place, row.width, margin), width: row.width }) } : isCentred ? { isCentred: true } : {};
983
+ 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 } : {};
927
984
  // A row of chips may be drawn smaller than the list's size, to fit one row.
928
985
  return { ok: true, overlay: { ...drawn, kind: "list", items: overlay.items ?? [], fontSize: row?.fontSize ?? fontSize, side, box: isCentred ? centred : box, ...layout } };
929
986
  }
@@ -964,15 +1021,20 @@ function measureChipRow(items: readonly string[], fontSize: number, padScale: nu
964
1021
 
965
1022
  /**
966
1023
  * Whether a list draws as chips and their row (null: the stack), or why it cannot. A row wider than `room` is tried
967
- * smaller, as a title is (by `OVERLAY_TITLE_SHRINK`, at most `MAX_TITLE_SHRINKS` times); one that never fits is refused
968
- * on `chips`, and `auto` falls back to the stack at the list's own size. `stack` never draws chips.
1024
+ * smaller, as a title is (by `OVERLAY_TITLE_SHRINK`, `MAX_TITLE_SHRINKS` times; an asked row of chips then on while its type
1025
+ * stays at or above `minFontSize`); one that never fits is refused on `chips`, and `auto` falls back to the stack at the list's
1026
+ * own size. `stack` never draws chips.
969
1027
  */
970
- function getListChipLayout(input: { items: readonly string[]; layout: OverlayListLayout; fontSize: number; padScale: number; room: number }): { ok: true; row: ChipRow | null } | { ok: false; error: string } {
1028
+ function getListChipLayout(input: { items: readonly string[]; layout: OverlayListLayout; fontSize: number; minFontSize: number; padScale: number; room: number }): { ok: true; row: ChipRow | null } | { ok: false; error: string } {
971
1029
  const { items, layout, room } = input;
972
1030
  if (layout === "stack") return { ok: true, row: null };
973
1031
  const own = measureChipRow(items, input.fontSize, input.padScale);
974
- for (let shrink = 0, row = own; shrink <= MAX_TITLE_SHRINKS; shrink++, row = measureChipRow(items, Math.round(row.fontSize * OVERLAY_TITLE_SHRINK), input.padScale)) {
1032
+ for (let shrink = 0, row = own; ; shrink++) {
975
1033
  if (row.width <= room) return { ok: true, row };
1034
+ const smaller = Math.round(row.fontSize * OVERLAY_TITLE_SHRINK);
1035
+ // `auto` has the stack to fall back to, so only an asked row of chips shrinks past a title's three steps.
1036
+ if (shrink >= MAX_TITLE_SHRINKS && (layout === "auto" || smaller < input.minFontSize)) break;
1037
+ row = measureChipRow(items, smaller, input.padScale);
976
1038
  }
977
1039
  if (layout === "auto") return { ok: true, row: null };
978
1040
  return { ok: false, error: `the list's points as chips (${own.width} px) do not fit one row (${room} px) even at a smaller size; use list_layout stack or auto, or shorter points` };
@@ -1073,9 +1135,12 @@ export function wrapOverlayTitle(text: string, fontSize: number, width: number):
1073
1135
  return best;
1074
1136
  }
1075
1137
 
1076
- /** 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. */
1077
- function fitTitle(text: string, fontSize: number, room: number): { lines: string[]; fontSize: number } | null {
1078
- for (let shrink = 0, size = fontSize; shrink <= MAX_TITLE_SHRINKS; shrink++, size = Math.round(size * OVERLAY_TITLE_SHRINK)) {
1138
+ /**
1139
+ * A title's lines and font size: its own size, else smaller by `OVERLAY_TITLE_SHRINK` until it fits two lines, at most
1140
+ * `maxShrinks` times; null when it never does.
1141
+ */
1142
+ function fitTitle(text: string, fontSize: number, room: number, maxShrinks = MAX_TITLE_SHRINKS): { lines: string[]; fontSize: number } | null {
1143
+ for (let shrink = 0, size = fontSize; shrink <= maxShrinks; shrink++, size = Math.round(size * OVERLAY_TITLE_SHRINK)) {
1079
1144
  const lines = wrapOverlayTitle(text, size, room);
1080
1145
  if (lines.length <= MAX_OVERLAY_TITLE_LINES && lines.every((line) => estimateTextWidth(line, size) <= room)) return { lines, fontSize: size };
1081
1146
  }
@@ -1087,12 +1152,45 @@ function fitTitle(text: string, fontSize: number, room: number): { lines: string
1087
1152
  * long for that shrinks to fit `room`, never below the `s` step (the size every subtitle had before, so nothing that
1088
1153
  * fitted then is refused now).
1089
1154
  */
1090
- function getSubtitleSize(input: { subtitle: string; titleSize: number; step: OverlaySize; room: number; scale: number }): number {
1091
- const wanted = Math.max(Math.round(MIN_OVERLAY_SUBTITLE_PX * input.scale), Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES[input.step]));
1155
+ function getSubtitleSize(input: { subtitle: string; titleSize: number; step: OverlaySize; room: number; scale: number; isCentred?: boolean }): number {
1156
+ const smallest = Math.round(MIN_OVERLAY_SUBTITLE_PX * input.scale);
1157
+ const wanted = Math.max(smallest, Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES[input.step]));
1092
1158
  const fitting = Math.floor(input.room / ([...input.subtitle].length * OVERLAY_CHAR_EM));
1093
- return Math.min(wanted, Math.max(fitting, Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES.s)));
1159
+ // In the centred span a subtitle may go down to `MIN_OVERLAY_SUBTITLE_PX` too when the `s` step is above it.
1160
+ const floor = Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES.s);
1161
+ return Math.min(wanted, Math.max(fitting, input.isCentred === true ? Math.min(floor, smallest) : floor));
1094
1162
  }
1095
1163
 
1164
+ /**
1165
+ * A place card's subtitle: one line at `getSubtitleSize` when it fits `room` (what fitted before keeps its size), else
1166
+ * two balanced lines, each sized as one line would be; null when even two lines are too wide (RV-184 of an adopting
1167
+ * app: a card whose subtitle cannot fit the centred span is placed off the frame's axis).
1168
+ */
1169
+ function fitPlaceSubtitle(input: { subtitle: string; titleSize: number; step: OverlaySize; room: number; scale: number; isCentred: boolean }): { lines: string[]; size: number } | null {
1170
+ const size = getSubtitleSize(input);
1171
+ if (estimateTextWidth(input.subtitle, size) <= input.room) return { lines: [input.subtitle], size };
1172
+ const lines = splitInTwoLines(input.subtitle);
1173
+ if (lines === null) return null;
1174
+ const longest = lines.reduce((widest, line) => ([...line].length > [...widest].length ? line : widest));
1175
+ const lineSize = getSubtitleSize({ ...input, subtitle: longest });
1176
+ return lines.every((line) => estimateTextWidth(line, lineSize) <= input.room) ? { lines, size: lineSize } : null;
1177
+ }
1178
+
1179
+ /** 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. */
1180
+ function splitInTwoLines(text: string): [string, string] | null {
1181
+ const words = text.split(/\s+/).filter((part) => part.length > 0);
1182
+ if (words.length < 2) return null;
1183
+ let best: [string, string] = [words[0] as string, words.slice(1).join(" ")];
1184
+ for (let split = 2; split < words.length; split++) {
1185
+ const pair: [string, string] = [words.slice(0, split).join(" "), words.slice(split).join(" ")];
1186
+ if (Math.max(...pair.map((line) => [...line].length)) < Math.max(...best.map((line) => [...line].length))) best = pair;
1187
+ }
1188
+ return best;
1189
+ }
1190
+
1191
+ /** A place card's title may shrink this many steps more in the centred span than in the whole zone (0.9² ≈ 0.81). */
1192
+ const CENTRED_TITLE_EXTRA_SHRINKS = 2;
1193
+
1096
1194
  /** A hook title's or a place card's second line: the place label (with its pin) or the subtitle. */
1097
1195
  type TitleOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "place_card" }>;
1098
1196
 
@@ -1101,17 +1199,29 @@ type TitleOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "place_card"
1101
1199
  * its pin, the subtitle, each title line) and its height. Its card is this plus the padding, so the draft and the
1102
1200
  * render find the block's left edge and top inside the card from it whatever the title's fitted size.
1103
1201
  */
1104
- export function getTitleContentSize(input: { kind: TitleOverlay["kind"]; lines: readonly string[]; fontSize: number; second: string | null; secondSize: number; pin?: boolean }): {
1202
+ export function getTitleContentSize(input: {
1203
+ kind: TitleOverlay["kind"];
1204
+ lines: readonly string[];
1205
+ fontSize: number;
1206
+ second: string | null;
1207
+ secondSize: number;
1208
+ pin?: boolean;
1209
+ /** A place card's wrapped subtitle (`subtitleLines`); absent: `second` on one line. */
1210
+ secondLines?: readonly string[];
1211
+ }): {
1105
1212
  width: number;
1106
1213
  height: number;
1107
1214
  } {
1108
1215
  const { kind, lines, fontSize, second, secondSize } = input;
1109
1216
  const isHook = kind === "hook_title";
1110
- const secondWidth = second === null ? 0 : estimateTextWidth(second, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0);
1217
+ const seconds = second === null ? [] : (input.secondLines ?? [second]);
1218
+ const secondWidth = Math.max(0, ...seconds.map((line) => estimateTextWidth(line, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0)));
1111
1219
  const lineHeight = isHook ? OVERLAY_LINE_HEIGHT : OVERLAY_TITLE_LINE_HEIGHT;
1220
+ // A wrapped subtitle's further lines each add a card line (`OVERLAY_LINE_HEIGHT`), as the render's `<br>` does.
1221
+ const secondHeight = seconds.length === 0 ? 0 : secondSize * 1.3 + fontSize * 0.12 + (seconds.length - 1) * secondSize * OVERLAY_LINE_HEIGHT;
1112
1222
  return {
1113
1223
  width: Math.max(secondWidth, input.pin === true ? getPlaceCardPinSize(fontSize) : 0, ...lines.map((line) => estimateTextWidth(line, fontSize))),
1114
- height: lines.length * fontSize * lineHeight + (second === null ? 0 : secondSize * 1.3 + fontSize * 0.12) + (input.pin === true ? getPlaceCardPinRow(fontSize) : 0),
1224
+ height: lines.length * fontSize * lineHeight + secondHeight + (input.pin === true ? getPlaceCardPinRow(fontSize) : 0),
1115
1225
  };
1116
1226
  }
1117
1227
 
@@ -1129,26 +1239,37 @@ export function getPlaceCardPinRow(fontSize: number): number {
1129
1239
  export function getTitleContentBox(overlay: TitleOverlay): OverlayBox {
1130
1240
  const second = overlay.kind === "hook_title" ? overlay.place : overlay.subtitle;
1131
1241
  const secondSize = overlay.kind === "hook_title" ? overlay.placeFontSize : overlay.subtitleFontSize;
1132
- const size = getTitleContentSize({ kind: overlay.kind, lines: overlay.lines, fontSize: overlay.fontSize, second, secondSize, pin: overlay.kind === "place_card" && overlay.pin !== undefined });
1242
+ const isPlace = overlay.kind === "place_card";
1243
+ const size = getTitleContentSize({
1244
+ kind: overlay.kind,
1245
+ lines: overlay.lines,
1246
+ fontSize: overlay.fontSize,
1247
+ second,
1248
+ secondSize,
1249
+ pin: isPlace && overlay.pin !== undefined,
1250
+ ...(isPlace && overlay.subtitleLines !== undefined ? { secondLines: overlay.subtitleLines } : {}),
1251
+ });
1133
1252
  const { box } = overlay;
1134
1253
  return { left: box.left + (box.width - size.width) / 2, top: box.top + (box.height - size.height) / 2, width: size.width, height: size.height };
1135
1254
  }
1136
1255
 
1137
1256
  /** A hook title's or a place card's lines and second line, aligned as its style says. */
1138
- function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card" }, metrics: CardMetrics): CardResult {
1257
+ function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card" }, metrics: CardMetrics, isCentred = false): CardResult {
1139
1258
  const { room, label } = metrics;
1140
- const fitted = fitTitle(overlay.text ?? "", metrics.fontSize, room);
1259
+ const isHook = overlay.kind === "hook_title";
1260
+ // In the centred span a place card's title may shrink further, so a card that fitted the whole zone stays on the axis.
1261
+ const fitted = fitTitle(overlay.text ?? "", metrics.fontSize, room, MAX_TITLE_SHRINKS + (isCentred && !isHook ? CENTRED_TITLE_EXTRA_SHRINKS : 0));
1141
1262
  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` };
1142
1263
  const { lines, fontSize } = fitted;
1143
- const isHook = overlay.kind === "hook_title";
1144
1264
  const second = (isHook ? overlay.place : overlay.subtitle) ?? null;
1145
- const secondSize =
1146
- !isHook && second !== null
1147
- ? getSubtitleSize({ subtitle: second, titleSize: metrics.fontSize, step: overlay.style?.subtitle_size ?? "m", room, scale: metrics.scale })
1148
- : Math.round(metrics.fontSize * OVERLAY_SECONDARY_SCALE[overlay.kind]);
1265
+ const subtitle =
1266
+ !isHook && second !== null ? fitPlaceSubtitle({ subtitle: second, titleSize: metrics.fontSize, step: overlay.style?.subtitle_size ?? "m", room, scale: metrics.scale, isCentred }) : null;
1267
+ if (!isHook && second !== null && subtitle === null) return tooWide(metrics, "subtitle");
1268
+ const secondSize = subtitle?.size ?? Math.round(metrics.fontSize * OVERLAY_SECONDARY_SCALE[overlay.kind]);
1269
+ const subtitleLines = subtitle !== null && subtitle.lines.length > 1 ? subtitle.lines : undefined;
1149
1270
  // The hook title's place label carries a pin about one label line wide before it.
1150
- const secondWidth = second === null ? 0 : estimateTextWidth(second, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0);
1151
- if (secondWidth > room) return tooWide(metrics, isHook ? "place label" : "subtitle");
1271
+ const secondWidth = second === null || !isHook ? 0 : estimateTextWidth(second, secondSize) + Math.round(secondSize * 1.1);
1272
+ if (secondWidth > room) return tooWide(metrics, "place label");
1152
1273
  // A title's align is center or left (the schema refuses right on it).
1153
1274
  const align: OverlayAlign = overlay.style?.align === "left" ? "left" : "center";
1154
1275
  const pin = !isHook && overlay.style?.pin !== undefined && overlay.style.pin !== "none" ? overlay.style.pin : undefined;
@@ -1156,10 +1277,20 @@ function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card"
1156
1277
  return {
1157
1278
  ok: true,
1158
1279
  content: {
1159
- ...getTitleContentSize({ kind: overlay.kind, lines, fontSize, second, secondSize, pin: pin !== undefined }),
1280
+ ...getTitleContentSize({ kind: overlay.kind, lines, fontSize, second, secondSize, pin: pin !== undefined, ...(subtitleLines === undefined ? {} : { secondLines: subtitleLines }) }),
1160
1281
  fields: isHook
1161
1282
  ? { kind: "hook_title", lines, place: second, fontSize, placeFontSize: secondSize, align, ...(overlay.style?.backdrop === "highlight" ? { backdrop: "highlight" } : {}) }
1162
- : { kind: "place_card", lines, subtitle: second, fontSize, subtitleFontSize: secondSize, align, ...(pin === undefined ? {} : { pin }), ...(delay === undefined ? {} : { subtitleDelay: delay }) },
1283
+ : {
1284
+ kind: "place_card",
1285
+ lines,
1286
+ subtitle: second,
1287
+ fontSize,
1288
+ subtitleFontSize: secondSize,
1289
+ align,
1290
+ ...(pin === undefined ? {} : { pin }),
1291
+ ...(delay === undefined ? {} : { subtitleDelay: delay }),
1292
+ ...(subtitleLines === undefined ? {} : { subtitleLines }),
1293
+ },
1163
1294
  },
1164
1295
  };
1165
1296
  }
@@ -1217,10 +1348,10 @@ function placeCard(overlay: EdlOverlay & { kind: CardKind }, drawn: Drawn, place
1217
1348
  const outer = frame.width - zone.left - zone.right - 2 * margin;
1218
1349
  const fontSize = Math.round(OVERLAY_FONT_SIZES[overlay.kind][overlay.style?.size ?? "m"] * scale);
1219
1350
  const pad = getOverlayPadding({ fontSize, padScale: place.padScale });
1220
- const measure = (room: number): CardResult => {
1351
+ const measure = (room: number, isCentred = false): CardResult => {
1221
1352
  const metrics = { fontSize, pad, room: room - 2 * pad.x, label: overlay.kind.replace("_", " "), scale };
1222
1353
  return overlay.kind === "hook_title" || overlay.kind === "place_card"
1223
- ? measureTitle({ ...overlay, kind: overlay.kind }, metrics)
1354
+ ? measureTitle({ ...overlay, kind: overlay.kind }, metrics, isCentred)
1224
1355
  : overlay.kind === "search_bar"
1225
1356
  ? measureSearchBar(overlay, metrics)
1226
1357
  : overlay.kind === "counter"
@@ -1231,7 +1362,13 @@ function placeCard(overlay: EdlOverlay & { kind: CardKind }, drawn: Drawn, place
1231
1362
  const measured =
1232
1363
  overlay.kind === "date_stamp"
1233
1364
  ? measure(outer)
1234
- : measureCentred({ whole: outer, centred: getCentredSpan(place, margin).width, measure, getWidth: (result) => Math.ceil(result.content.width + 2 * pad.x) });
1365
+ : measureCentred({
1366
+ whole: outer,
1367
+ centred: getCentredSpan(place, margin).width,
1368
+ measure,
1369
+ getWidth: (result) => Math.ceil(result.content.width + 2 * pad.x),
1370
+ isRetriedWhenRefused: overlay.kind === "place_card",
1371
+ });
1235
1372
  if (!measured.ok) return measured;
1236
1373
  const { content } = measured;
1237
1374
  const width = Math.ceil(content.width + 2 * pad.x);
package/src/index.ts CHANGED
@@ -171,6 +171,8 @@ export {
171
171
  LIST_CHIP_GAP_EM,
172
172
  LIST_CHIP_BADGE_EM,
173
173
  LIST_CHIP_COVERED_OPACITY,
174
+ LIST_CHIP_MIN_FONT_SIZE,
175
+ LIST_CHIP_CENTRED_MIN_FONT_SIZE,
174
176
  getCentredLeft,
175
177
  getChipBadgeSize,
176
178
  getChipCoveredTimes,
@@ -179,6 +181,7 @@ export {
179
181
  getDrawnOverlayCard,
180
182
  getListCardsByItem,
181
183
  getListItemTimes,
184
+ getListStops,
182
185
  getOverlayBounds,
183
186
  getOverlayPadding,
184
187
  getPlaceCardPinRow,