@softure-ai/marketing-kit 0.34.0 → 0.36.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 (102) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/NOTICE +6 -0
  3. package/README.md +49 -1
  4. package/dist/config/config.d.ts.map +1 -1
  5. package/dist/config/config.js +1 -0
  6. package/dist/config/config.js.map +1 -1
  7. package/dist/config/schema.d.ts +10 -0
  8. package/dist/config/schema.d.ts.map +1 -1
  9. package/dist/config/schema.js +9 -3
  10. package/dist/config/schema.js.map +1 -1
  11. package/dist/footage/captions.d.ts +22 -2
  12. package/dist/footage/captions.d.ts.map +1 -1
  13. package/dist/footage/captions.js +23 -4
  14. package/dist/footage/captions.js.map +1 -1
  15. package/dist/footage/compose.d.ts +11 -1
  16. package/dist/footage/compose.d.ts.map +1 -1
  17. package/dist/footage/compose.js +51 -17
  18. package/dist/footage/compose.js.map +1 -1
  19. package/dist/footage/draft-overlays.d.ts +6 -0
  20. package/dist/footage/draft-overlays.d.ts.map +1 -1
  21. package/dist/footage/draft-overlays.js +188 -4
  22. package/dist/footage/draft-overlays.js.map +1 -1
  23. package/dist/footage/draft.d.ts +14 -1
  24. package/dist/footage/draft.d.ts.map +1 -1
  25. package/dist/footage/draft.js +117 -17
  26. package/dist/footage/draft.js.map +1 -1
  27. package/dist/footage/drawn-transitions.d.ts +63 -0
  28. package/dist/footage/drawn-transitions.d.ts.map +1 -0
  29. package/dist/footage/drawn-transitions.js +177 -0
  30. package/dist/footage/drawn-transitions.js.map +1 -0
  31. package/dist/footage/edl.d.ts +42 -0
  32. package/dist/footage/edl.d.ts.map +1 -1
  33. package/dist/footage/edl.js +72 -2
  34. package/dist/footage/edl.js.map +1 -1
  35. package/dist/footage/film.d.ts +29 -5
  36. package/dist/footage/film.d.ts.map +1 -1
  37. package/dist/footage/film.js +13 -3
  38. package/dist/footage/film.js.map +1 -1
  39. package/dist/footage/hand-font.d.ts +16 -0
  40. package/dist/footage/hand-font.d.ts.map +1 -0
  41. package/dist/footage/hand-font.js +43 -0
  42. package/dist/footage/hand-font.js.map +1 -0
  43. package/dist/footage/overlay-html.d.ts +1 -0
  44. package/dist/footage/overlay-html.d.ts.map +1 -1
  45. package/dist/footage/overlay-html.js +134 -8
  46. package/dist/footage/overlay-html.js.map +1 -1
  47. package/dist/footage/overlay-motion.d.ts +35 -0
  48. package/dist/footage/overlay-motion.d.ts.map +1 -1
  49. package/dist/footage/overlay-motion.js +45 -0
  50. package/dist/footage/overlay-motion.js.map +1 -1
  51. package/dist/footage/overlay-schema.d.ts +48 -6
  52. package/dist/footage/overlay-schema.d.ts.map +1 -1
  53. package/dist/footage/overlay-schema.js +71 -18
  54. package/dist/footage/overlay-schema.js.map +1 -1
  55. package/dist/footage/overlays.d.ts +125 -1
  56. package/dist/footage/overlays.d.ts.map +1 -1
  57. package/dist/footage/overlays.js +265 -8
  58. package/dist/footage/overlays.js.map +1 -1
  59. package/dist/footage/picture.d.ts +10 -2
  60. package/dist/footage/picture.d.ts.map +1 -1
  61. package/dist/footage/picture.js +53 -13
  62. package/dist/footage/picture.js.map +1 -1
  63. package/dist/footage/pipeline.d.ts.map +1 -1
  64. package/dist/footage/pipeline.js +14 -4
  65. package/dist/footage/pipeline.js.map +1 -1
  66. package/dist/footage/split-screen.d.ts +167 -0
  67. package/dist/footage/split-screen.d.ts.map +1 -0
  68. package/dist/footage/split-screen.js +233 -0
  69. package/dist/footage/split-screen.js.map +1 -0
  70. package/dist/footage/tools.d.ts +1 -1
  71. package/dist/footage/tools.d.ts.map +1 -1
  72. package/dist/footage/tools.js +1 -1
  73. package/dist/footage/tools.js.map +1 -1
  74. package/dist/index.d.ts +8 -5
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +8 -5
  77. package/dist/index.js.map +1 -1
  78. package/fonts/Caveat-SemiBold-Latin.ttf +0 -0
  79. package/fonts/LICENSE-Caveat.txt +93 -0
  80. package/fonts/README.md +14 -0
  81. package/package.json +1 -1
  82. package/schema/edl.schema.json +167 -11
  83. package/schema/marketing.schema.json +19 -4
  84. package/src/config/config.ts +1 -0
  85. package/src/config/schema.ts +9 -3
  86. package/src/footage/captions.ts +32 -4
  87. package/src/footage/compose.ts +44 -11
  88. package/src/footage/draft-overlays.ts +217 -2
  89. package/src/footage/draft.ts +137 -17
  90. package/src/footage/drawn-transitions.ts +214 -0
  91. package/src/footage/edl.ts +67 -2
  92. package/src/footage/film.ts +23 -4
  93. package/src/footage/hand-font.ts +47 -0
  94. package/src/footage/overlay-html.ts +141 -7
  95. package/src/footage/overlay-motion.ts +49 -0
  96. package/src/footage/overlay-schema.ts +78 -19
  97. package/src/footage/overlays.ts +311 -10
  98. package/src/footage/picture.ts +58 -15
  99. package/src/footage/pipeline.ts +14 -4
  100. package/src/footage/split-screen.ts +319 -0
  101. package/src/footage/tools.ts +1 -1
  102. package/src/index.ts +62 -0
@@ -5,11 +5,13 @@ import { assertLocalReferences, escapeHtml, fontFaces, fontStack } from "../comp
5
5
  import { CAPTION_LINE_HEIGHT, getCaptionPillCss, getCaptionPositionCss, type CaptionLayout } from "../compose/timeline.js";
6
6
  import type { TimedWord } from "../voice/voiceover.js";
7
7
  import { CAPTION_HIGHLIGHT_BOX_PADDING_EM, CAPTION_HIGHLIGHT_BOX_RADIUS, CAPTION_HIGHLIGHT_SECONDS, CAPTION_UNDERLINE_EM, getCaptionEntranceTween, getCaptionHighlight } from "./caption-highlight.js";
8
- import { CAPTION_SAFE_ZONES, getCaptionChunkLayouts, getCaptionSpans, getFootageCaptionChunks, isSameCaptionPlace, type CaptionSpan } from "./captions.js";
8
+ import { CAPTION_SAFE_ZONES, getCaptionChunkLayouts, getCaptionRibbonTilt, getCaptionSpans, getFootageCaptionChunks, isSameCaptionPlace, toCaptionDisplayText, type CaptionSpan } from "./captions.js";
9
9
  import { getCameraGsapEase, getCameraMoveSeconds, getCameraOrigin, isCameraMoving, toTransformOrigin } from "./camera.js";
10
+ import { STUTTER_FRAMES, STUTTER_SCALE } from "./drawn-transitions.js";
10
11
  import { getEdlDuration, getSegmentStarts, type Edl, type EdlSegment } from "./edl.js";
11
12
  import {
12
13
  CAPTION_MIN_FONT_SCALE,
14
+ CAPTION_RIBBON,
13
15
  DEFAULT_EDIT,
14
16
  DEFAULT_END_CARD_SECONDS,
15
17
  DEFAULT_LOGO_END_CARD_FADE_SECONDS,
@@ -31,7 +33,8 @@ const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
31
33
  * The HyperFrames composition of a footage film (the same 0.8.85 contract as `composeFilm`): one `<video>` clip per
32
34
  * EDL segment over the normalized clip with its media start, the transitions (`fade` cross-fades from the segment
33
35
  * before over `fadeFrames`, `zoom` punches in by `zoomPercent` on alternate jump cuts, eased over `zoomEaseFrames`, `whoosh` plays the whoosh
34
- * sound), a slow zoom on `kenburns` segments, the captions (plain phrases, or the word-highlight pill), the end card
36
+ * sound, `stutter` holds the full frame for `STUTTER_FRAMES` and then its tight framing; the drawn `whip`, `card` and
37
+ * `paper` are in the picture, and the per-segment videos without one play them as plain cuts), a slow zoom on `kenburns` segments, the captions (plain phrases, or the word-highlight pill), the end card
35
38
  * over the cut's last frame (the full card, or the short logo card; its whoosh only with `isEndCardWhoosh`), the cut
36
39
  * speech track and the ducked music.
37
40
  */
@@ -96,13 +99,15 @@ export function getFootageFilmSeconds(film: Pick<FootageFilm, "endCard">, edl: E
96
99
 
97
100
  /**
98
101
  * The picture scale each segment starts at: `zoom` cuts alternate between punched in (`zoomPercent`) and back out; a
99
- * segment with a `camera` starts at its camera's `from`.
102
+ * segment with a `camera` starts at its camera's `from`; a `stutter` holds its camera's framing or `STUTTER_SCALE`
103
+ * once its wide frames are over.
100
104
  */
101
105
  export function getSegmentScales(edl: Edl, zoomPercent = DEFAULT_EDIT.zoomPercent): number[] {
102
106
  const scales: number[] = [];
103
107
  edl.segments.forEach((segment, index) => {
104
108
  const previous = scales[index - 1] ?? 1;
105
109
  if (segment.camera !== undefined) scales.push(segment.camera.from);
110
+ else if (segment.transition === "stutter") scales.push(STUTTER_SCALE);
106
111
  else scales.push(segment.transition === "zoom" && index > 0 ? (previous === 1 ? zoomPercent / 100 : 1) : 1);
107
112
  });
108
113
  return scales;
@@ -175,6 +180,8 @@ export function composeFootage(input: FootageComposeInput): string {
175
180
  const kenBurnsScale = 1 + (edit.kenBurnsPercent > 0 ? edit.kenBurnsPercent : HAND_KEN_BURNS_PERCENT) / 100;
176
181
 
177
182
  const picture = assets.picture;
183
+ // A split screen is drawn only into the cut's picture (`planFootagePicture`); one video per segment cannot show it.
184
+ if (picture === undefined && edl.segments.some((segment) => segment.split !== undefined)) throw new Error("The EDL has a split screen, which needs the cut's picture (assets.picture).");
178
185
  const segments =
179
186
  picture === undefined
180
187
  ? edl.segments.map((segment, index) => {
@@ -196,7 +203,14 @@ export function composeFootage(input: FootageComposeInput): string {
196
203
  const scale = scales[index] as number;
197
204
  const target = picture === undefined ? `#seg${index}` : "#picture";
198
205
  // One video carries every segment: each one sets the zoom it starts at (a fade is already in the picture).
199
- if (picture !== undefined) tweens.push(hasCamera ? `tl.set("#picture", { scale: ${scale}, transformOrigin: "${originOf(segment)}" }, ${start});` : `tl.set("#picture", { scale: ${scale} }, ${start});`);
206
+ const isStutter = segment.transition === "stutter";
207
+ // A stutter shows the full frame first, then cuts to its framing.
208
+ const opening = isStutter ? 1 : scale;
209
+ if (picture !== undefined) tweens.push(hasCamera ? `tl.set("#picture", { scale: ${opening}, transformOrigin: "${originOf(segment)}" }, ${start});` : `tl.set("#picture", { scale: ${opening} }, ${start});`);
210
+ if (isStutter) {
211
+ if (picture === undefined) tweens.push(`tl.set("${target}", { scale: 1 }, ${start});`);
212
+ tweens.push(`tl.set("${target}", { scale: ${scale} }, ${r3(start + STUTTER_FRAMES / FOOTAGE_FPS)});`);
213
+ }
200
214
  if (picture === undefined && segment.transition === "fade" && index > 0) {
201
215
  tweens.push(`tl.fromTo("${target}", { opacity: 0 }, { opacity: 1, duration: ${fadeSecondsAt(index)}, ease: "none", immediateRender: false }, ${start});`);
202
216
  }
@@ -232,8 +246,9 @@ export function composeFootage(input: FootageComposeInput): string {
232
246
  );
233
247
  }
234
248
 
235
- // --- Captions: plain phrases, or the pill that lights each word ---
249
+ // --- Captions: plain phrases, the pill that lights each word, or the turned ribbon ---
236
250
  const isHighlight = film.captionStyle === "highlight";
251
+ const isRibbon = film.captionStyle === "ribbon";
237
252
  const highlight = isHighlight ? getCaptionHighlight(film, c) : ({ ok: true, look: { style: "text", color: c.captionHighlight } } as const);
238
253
  // The pipeline refuses such a film before it composes; reaching here is a bug.
239
254
  if (!highlight.ok) throw new Error(`composeFootage: ${highlight.error}`);
@@ -250,10 +265,12 @@ export function composeFootage(input: FootageComposeInput): string {
250
265
  const place = boxes[i] ?? captionBox;
251
266
  // A chunk in a segment's own box overrides the shared rule's anchor; one in the film's box is written as before.
252
267
  const style = isSameCaptionPlace(place, captionBox) ? "" : ` style="${place.bottom === undefined ? `bottom:auto;top:${place.top}px` : `top:auto;bottom:${place.bottom}px`}"`;
253
- const box = isHighlight
268
+ const box = isRibbon
269
+ ? `<p class="ribbon"><span class="rb">${escapeHtml(toCaptionDisplayText(film, chunk.words.map((w) => w.text).join(" "), input.locale))}</span></p>`
270
+ : isHighlight
254
271
  ? `<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>`
255
272
  : `<p class="phrase">${escapeHtml(chunk.words.map((w) => w.text).join(" "))}</p>`;
256
- return `<div id="cap${i}" class="clip caption" data-start="${start}" data-duration="${r3(stop - start)}"${style}>${box}</div>`;
273
+ return `<div id="cap${i}" class="clip caption${isRibbon ? " turned" : ""}" data-start="${start}" data-duration="${r3(stop - start)}"${style}>${box}</div>`;
257
274
  })
258
275
  .join("\n ");
259
276
 
@@ -329,7 +346,7 @@ ${isBox ? `.pill{position:relative;z-index:0}
329
346
  .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}
330
347
  ` : ""}${isUnderline ? `.pill span{position:relative}
331
348
  .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}
332
- ` : ""}.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)}
349
+ ` : ""}${isRibbon ? `${getRibbonCaptionCss(captionBox.fontSize, getCaptionRibbonTilt(film), { background: c.captionBackground, text: c.captionText })}\n` : ""}.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)}
333
350
  .endcard{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:center;align-items:center;padding:0 80px;text-align:center}
334
351
  .brand{display:flex;justify-content:center;align-items:center;gap:18px;font-family:${headingFont};font-size:46px}
335
352
  .logo{height:60px;width:auto}
@@ -354,10 +371,12 @@ ${overlayMarkup.css.map((rule) => `${rule}\n`).join("")}</style>
354
371
  ${captionFit}<script>
355
372
  const tl = gsap.timeline({ paused: true });
356
373
  ${tweens.join("\n")}
357
- const captions = ${JSON.stringify(isHighlight ? caption.map((chunk) => chunk.words.map((w) => w.start)) : [])};
374
+ const captions = ${JSON.stringify(isHighlight ? caption.map((chunk) => chunk.words.map((w) => w.start)) : isRibbon ? caption.map((chunk) => [chunk.start]) : [])};
358
375
  captions.forEach((words, i) => {
359
- ${entrance === null ? "" : ` tl.fromTo("#cap" + i + " .pill", ${toTweenVars(entrance.from)}, ${toTweenVars(entrance.to)}, Math.max(0, words[0] - 0.05));\n`}${
360
- look.style === "underline"
376
+ ${entrance === null ? "" : ` tl.fromTo("#cap" + i + " ${isRibbon ? ".ribbon" : ".pill"}", ${toTweenVars(entrance.from)}, ${toTweenVars(entrance.to)}, Math.max(0, words[0] - 0.05));\n`}${
377
+ isRibbon
378
+ ? ""
379
+ : look.style === "underline"
361
380
  ? ` 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}));`
362
381
  : look.style === "box"
363
382
  ? ` words.forEach((t, j) => {
@@ -382,6 +401,20 @@ function toTweenVars(vars: Record<string, number | string>): string {
382
401
  return `{ ${Object.entries(vars).map(([key, value]) => `${key}: ${typeof value === "string" ? JSON.stringify(value) : String(value)}`).join(", ")} }`;
383
402
  }
384
403
 
404
+ /**
405
+ * A `ribbon` caption's rules: the caption box turned `tilt` degrees (counter-clockwise positive, as the draft turns it)
406
+ * about its middle; its capitals bold and centred, each wrapped line on its own flat strip of `background`
407
+ * (`box-decoration-break: clone` repeats the strip's padding and corner on every line).
408
+ */
409
+ export function getRibbonCaptionCss(fontSize: number, tilt: number, colors: { background: string; text: string }): string {
410
+ const { lineHeight, padding, radius, weight } = CAPTION_RIBBON;
411
+ return [
412
+ `.caption.turned{transform:rotate(${String(-tilt)}deg);transform-origin:50% 50%}`,
413
+ `.ribbon{font-weight:${String(weight)};font-size:${String(fontSize)}px;line-height:${String(lineHeight)};letter-spacing:.01em;text-align:center;color:${colors.text}}`,
414
+ `.rb{background:${colors.background};padding:${String(padding.y)}em ${String(padding.x)}em;border-radius:${String(radius)}px;-webkit-box-decoration-break:clone;box-decoration-break:clone}`,
415
+ ].join("\n");
416
+ }
417
+
385
418
  /** The caption pill's rule in the brand's style, after the pill's own: its radius, padding, shadow and border in `accent`. */
386
419
  export function getStyledPillCss(style: BrandStyle, accent: string): string {
387
420
  const pad = getStylePadding(CAPTION_PILL_PADDING, style.padding);
@@ -1,9 +1,15 @@
1
1
  import { getCornerRadiusPx, type BrandStyle, type CornerRadius } from "./brand-style.js";
2
2
  import { getDraftBoxEvents } from "./draft-boxes.js";
3
3
  import { toAssColor } from "./draft-color.js";
4
+ import { HAND_FONT, getHandFontAssSize } from "./hand-font.js";
4
5
  import { getCounterSeconds, getOverlayColors, getPlaceCardTimes, getTypingTimes, type OverlayColors } from "./overlay-html.js";
5
6
  import {
7
+ DROP_LETTER_SECONDS,
8
+ NOTE_GROW_FROM_SCALE,
9
+ NOTE_GROW_SECONDS,
10
+ NOTE_TICK_SECONDS,
6
11
  OVERLAY_EASES,
12
+ getDropLetterTimes,
7
13
  PIN_DROP_SECONDS,
8
14
  PIN_DROP_SHARE,
9
15
  UNDERLINE_EM,
@@ -16,6 +22,7 @@ import {
16
22
  } from "./overlay-motion.js";
17
23
  import type { OverlayEntrance } from "./overlay-schema.js";
18
24
  import {
25
+ NOTE_LINE_HEIGHT,
19
26
  OVERLAY_FONT_ROLES,
20
27
  OVERLAY_LINE_HEIGHT,
21
28
  OVERLAY_LIST_LINE_HEIGHT,
@@ -27,6 +34,12 @@ import {
27
34
  getDrawnOverlayCard,
28
35
  getListCardsByItem,
29
36
  getListItemTimes,
37
+ getNoteCentre,
38
+ getNoteColors,
39
+ getNotePaperPoints,
40
+ getNoteTextBox,
41
+ getNoteTickPoints,
42
+ getNoteWordsByLine,
30
43
  getOverlayPadding,
31
44
  getPlaceCardPinRow,
32
45
  getPlaceCardPinSize,
@@ -374,6 +387,73 @@ function getWipePanelEvent(overlay: Pick<ResolvedOverlay, "start">, drawing: str
374
387
  return [`Dialogue: 3,${toAssTime(overlay.start)},${toAssTime(overlay.start + motion.entrance.seconds)},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${tags}\\1c${toTagColor(accent)}\\p1}${drawing}{\\p0}`];
375
388
  }
376
389
 
390
+ /** The same motion with no entrance of its own: a part whose letters or words come in by themselves. */
391
+ function getPlainMotion(motion: DraftMotion): DraftMotion {
392
+ return { ...motion, name: "none", entrance: { kind: "none" } };
393
+ }
394
+
395
+ /**
396
+ * A dropped text as one line of ASS: each letter transparent until its second (`times`, from `getDropLetterTimes`),
397
+ * then fading in over half a fall. libass moves whole events only, so the draft shows the letters arriving on their
398
+ * times without the fall the render draws.
399
+ */
400
+ export function getDropText(text: string, times: readonly number[], eventStart: number): string {
401
+ const fade = toMs(DROP_LETTER_SECONDS / 2);
402
+ return [...toAssText(text)]
403
+ .map((char, index) => {
404
+ if (char.trim() === "") return char;
405
+ const from = toMs((times[index] ?? eventStart) - eventStart);
406
+ return `{\\alpha&HFF&\\t(${from},${from + fade},\\alpha&H00&)}${char}`;
407
+ })
408
+ .join("");
409
+ }
410
+
411
+ /** A highlight mark's padding round its text and its corner, in font sizes (as the render's `.ov-mark`). */
412
+ const MARK_PADDING_EM = { x: 0.22, y: 0.04 } as const;
413
+ const MARK_RADIUS_EM = 0.14;
414
+
415
+ /**
416
+ * A highlight backdrop's marks under one line of text (`style.backdrop` highlight): a tight rounded box in the card
417
+ * colour, its width the text shown so far (each typed letter widens it, as the render's box grows), anchored where
418
+ * the text is (`x` its left, middle or right edge, `top` its top).
419
+ */
420
+ function getBackdropMarkEvents(input: {
421
+ text: string;
422
+ x: number;
423
+ align: "left" | "center" | "right";
424
+ top: number;
425
+ fontSize: number;
426
+ colour: string;
427
+ motion: DraftMotion;
428
+ span: { start: number; end: number };
429
+ typing: number | null;
430
+ /** When the line starts typing, if not at the span's start (a second line of a title). */
431
+ typeFrom?: number;
432
+ }): string[] {
433
+ const { fontSize, span } = input;
434
+ const pad = { x: fontSize * MARK_PADDING_EM.x, y: fontSize * MARK_PADDING_EM.y };
435
+ const height = fontSize * OVERLAY_LINE_HEIGHT + 2 * pad.y;
436
+ const boxFor = (shown: string): OverlayBox => {
437
+ const width = estimateTextWidth(shown, fontSize) + 2 * pad.x;
438
+ const left = input.align === "left" ? input.x - pad.x : input.align === "right" ? input.x + pad.x - width : input.x - width / 2;
439
+ return { left, top: input.top - pad.y, width, height };
440
+ };
441
+ const clean = toAssText(input.text);
442
+ const steps =
443
+ input.typing === null
444
+ ? [{ from: span.start, to: span.end, shown: clean }]
445
+ : getTypingTimes(input.typeFrom ?? span.start, clean, input.typing).map((at, index, times) => ({ from: Math.min(at, span.end), to: Math.min(times[index + 1] ?? span.end, span.end), shown: [...clean].slice(0, index + 1).join("").trimEnd() }));
446
+ const visible = steps.filter((step) => step.to > step.from && step.shown.length > 0);
447
+ return visible.map((step, index) =>
448
+ getShapeEvent({ start: step.from, end: step.to }, getRoundedRectDrawing(boxFor(step.shown), fontSize * MARK_RADIUS_EM), input.colour, input.motion, 3, {
449
+ start: step.from,
450
+ end: step.to,
451
+ isFirst: index === 0,
452
+ isLast: index === visible.length - 1,
453
+ }),
454
+ );
455
+ }
456
+
377
457
  /** A keyword's underline: an accent bar under its text, drawn from the left once the keyword is in. */
378
458
  function getUnderlineEvent(overlay: Extract<ResolvedOverlay, { kind: "keyword" }>, card: OverlayBox, colour: string, motion: DraftMotion): string[] {
379
459
  if (overlay.underline !== true) return [];
@@ -414,7 +494,11 @@ function getSideTextEvents(overlay: Extract<ResolvedOverlay, { kind: "keyword" |
414
494
  const span = { start: overlay.start, end: overlay.end };
415
495
  const tags = `\\an${align}\\fs${fontSize}${getTextTags(overlay, colors, context, OVERLAY_FONT_ROLES[overlay.kind])}`;
416
496
  const text = (pos: OverlayPoint, steps: TextStep[], own = motion) => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, motion: own });
417
- const shape = getCardShapeEvents(overlay, card, fontSize, colors, motion, context);
497
+ const isMarked = overlay.kind === "keyword" && overlay.backdrop === "highlight";
498
+ const shape = isMarked
499
+ ? getBackdropMarkEvents({ text: overlay.text, x, align: isCentred ? "center" : isRight ? "right" : "left", top: y, fontSize, colour: colors.background, motion, span, typing: overlay.typing })
500
+ : getCardShapeEvents(overlay, card, fontSize, colors, motion, context);
501
+ if (overlay.entrance === "drop") return [...shape, ...text({ x, y }, [{ from: span.start, to: span.end, text: getDropText(overlay.text, getDropLetterTimes(span.start, overlay.text), span.start) }], getPlainMotion(motion))];
418
502
  // A keyword or a lower third types in only when its entrance says so.
419
503
  const steps = overlay.entrance === null ? [{ from: span.start, to: span.end, text: toAssText(overlay.text) }] : getTypedSteps(overlay.text, span, overlay.typing, isCentred);
420
504
  return [...shape, ...text({ x, y }, steps), ...(overlay.kind === "keyword" ? getUnderlineEvent(overlay, card, colors.accent, motion) : [])];
@@ -550,7 +634,8 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
550
634
  const name = overlay.entrance === null || overlay.entrance === "type" ? (overlay.typing !== null ? "fade" : DEFAULT_ENTRANCES[overlay.kind]) : overlay.entrance;
551
635
  const motion = getDraftMotion(overlay, name, box, context);
552
636
  const span = { start: overlay.start, end: overlay.end };
553
- const events = getCardShapeEvents(overlay, box, fontSize, colors, motion, context);
637
+ const isMarked = overlay.kind === "hook_title" && overlay.backdrop === "highlight";
638
+ const events = isMarked ? [] : getCardShapeEvents(overlay, box, fontSize, colors, motion, context);
554
639
  const { x: padX, y: padY } = getOverlayPadding(overlay);
555
640
  const centerX = box.left + box.width / 2;
556
641
  const tagsFor = (role: OverlayFontRole) => getTextTags(overlay, colors, context, role);
@@ -582,6 +667,25 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
582
667
  const lineHeight = overlay.kind === "hook_title" ? OVERLAY_LINE_HEIGHT : OVERLAY_TITLE_LINE_HEIGHT;
583
668
  const titleMotion = times.title > span.start ? withFadeEntrance(motion) : motion;
584
669
  let typedBefore = 0;
670
+ if (overlay.kind === "hook_title" && (isMarked || overlay.entrance === "drop")) {
671
+ const letters = getDropLetterTimes(span.start, overlay.lines.join(""));
672
+ overlay.lines.forEach((line) => {
673
+ const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
674
+ if (isMarked) {
675
+ const align = isLeft ? "left" : "center";
676
+ events.push(...getBackdropMarkEvents({ text: line, x: lineX, align, top: y, fontSize, colour: colors.background, motion, span, typing: overlay.typing, typeFrom: lineStart }));
677
+ }
678
+ const steps =
679
+ overlay.entrance === "drop"
680
+ ? [{ from: span.start, to: span.end, text: getDropText(line, letters.slice(typedBefore, typedBefore + [...line].length), span.start) }]
681
+ : getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
682
+ const isQuiet = overlay.entrance === "drop" || (!isLeft && overlay.typing !== null);
683
+ events.push(...text({ x: lineX, y }, lineAlign, fontSize, "heading", isLeft && overlay.entrance !== "drop" ? steps.map((step, index) => (index === 0 ? { ...step, from: span.start } : step)) : steps, isQuiet ? plain : motion));
684
+ typedBefore += [...line].length;
685
+ y += fontSize * lineHeight;
686
+ });
687
+ return events;
688
+ }
585
689
  overlay.lines.forEach((line) => {
586
690
  // The lines type one after the other, as the render's characters do; a left line holds its place transparent
587
691
  // from the start, a centred one shows its typed part only (`getTypedSteps`).
@@ -650,6 +754,115 @@ function getMarkEvents(overlay: Extract<ResolvedOverlay, { kind: "arrow" | "high
650
754
  return [`Dialogue: 3,${at},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${fade}\\1a&HFF&\\3c${accent}\\bord${stroke}\\p1}${shape}{\\p0}`];
651
755
  }
652
756
 
757
+ /** A polygon as an ASS drawing. */
758
+ function getPolygonDrawing(points: readonly OverlayPoint[]): string {
759
+ const [first, ...rest] = points;
760
+ if (first === undefined) return "";
761
+ return `m ${r0(first.x)} ${r0(first.y)} l ${rest.map((point) => `${r0(point.x)} ${r0(point.y)}`).join(" ")}`;
762
+ }
763
+
764
+ /** A stroke along `points` `width` px wide as an ASS drawing: one quad per segment and a square cap at each joint. */
765
+ function getStrokeDrawing(points: readonly OverlayPoint[], width: number): string {
766
+ const half = width / 2;
767
+ const parts: string[] = [];
768
+ points.slice(1).forEach((to, index) => {
769
+ const from = points[index] as OverlayPoint;
770
+ const length = Math.hypot(to.x - from.x, to.y - from.y) || 1;
771
+ const n = { x: (-(to.y - from.y) / length) * half, y: ((to.x - from.x) / length) * half };
772
+ const u = { x: ((to.x - from.x) / length) * half, y: ((to.y - from.y) / length) * half };
773
+ parts.push(getPolygonDrawing([
774
+ { x: from.x - u.x + n.x, y: from.y - u.y + n.y },
775
+ { x: to.x + u.x + n.x, y: to.y + u.y + n.y },
776
+ { x: to.x + u.x - n.x, y: to.y + u.y - n.y },
777
+ { x: from.x - u.x - n.x, y: from.y - u.y - n.y },
778
+ ]));
779
+ });
780
+ return parts.join(" ");
781
+ }
782
+
783
+ /**
784
+ * A note: its paper's torn outline and a soft shadow (layer 3), turned by its tilt about its middle (`\org`, `\frz`);
785
+ * a card's handwritten words each fading in on its said second, a strip's capitals typed in after it grows; the tick
786
+ * drawn from the left after the last word (layer 4). A strip's grow is the same `NOTE_GROW_FROM_SCALE` to full size.
787
+ */
788
+ function getNoteEvents(overlay: Extract<ResolvedOverlay, { kind: "note" }>, context: DraftContext): string[] {
789
+ const colors = getNoteColors(overlay);
790
+ const centre = getNoteCentre(overlay);
791
+ const turn = `\\org(${r0(centre.x)},${r0(centre.y)})\\frz${overlay.tilt}`;
792
+ const isStrip = overlay.noteStyle === "strip";
793
+ const frame = { width: 1080 * context.scale, height: 1920 * context.scale };
794
+ const easing = overlay.easing ?? "smooth";
795
+ const grow: OverlayEntranceMotion = { kind: "tween", from: { opacity: 1, scale: NOTE_GROW_FROM_SCALE, y: 0, blur: 0 }, seconds: NOTE_GROW_SECONDS, ease: "power2.out" };
796
+ const name = overlay.entrance ?? (isStrip ? "pop" : "none");
797
+ const motion: DraftMotion = {
798
+ name,
799
+ entrance: isStrip && overlay.entrance === null ? grow : getEntranceMotion(name, easing, frame),
800
+ exit: getExitMotion({ exit: overlay.exit ?? "auto", entrance: overlay.entrance ?? "fade", easing, frame }),
801
+ card: overlay.box,
802
+ scale: context.scale,
803
+ isSnappy: easing === "snappy",
804
+ isCardMoved: name === "pop",
805
+ };
806
+ const at = { isFirst: true, isLast: true, ms: toMs(overlay.end - overlay.start) };
807
+ const shapeTags = getMotionTags(motion, { ...at, pos: { x: 0, y: 0 }, part: "card" });
808
+ const time = `${toAssTime(overlay.start)},${toAssTime(overlay.end)}`;
809
+ const paper = getPolygonDrawing(getNotePaperPoints(overlay));
810
+ const shadowOffset = r0(6 * context.scale);
811
+ const shadow = getPolygonDrawing(getNotePaperPoints({ ...overlay, box: { ...overlay.box, top: overlay.box.top + shadowOffset } }));
812
+ const events = [
813
+ `Dialogue: 3,${time},OverlayShape,,0,0,0,,{\\an7${shapeTags.position}${shapeTags.rest}${turn}\\blur${r0(10 * context.scale)}\\1c&H000000&\\1a&HB0&\\p1}${shadow}{\\p0}`,
814
+ `Dialogue: 3,${time},OverlayShape,,0,0,0,,{\\an7${shapeTags.position}${shapeTags.rest}${turn}\\1c${toTagColor(colors.paper)}\\p1}${paper}{\\p0}`,
815
+ ];
816
+ const textBox = getNoteTextBox(overlay);
817
+ const lineHeight = overlay.fontSize * NOTE_LINE_HEIGHT;
818
+ const font = isStrip ? `${context.fonts.heading === undefined ? "" : `\\fn${context.fonts.heading}`}\\b1` : `\\fn${HAND_FONT.family}\\b0`;
819
+ const textMotion = getPlainMotion(motion);
820
+ // libass sizes the hand font by its ascent and descent: its \\fs is scaled so the letters match the render's.
821
+ const assSize = isStrip ? overlay.fontSize : getHandFontAssSize(overlay.fontSize);
822
+ const tags = `\\an7\\fs${assSize}${font}\\1c${toTagColor(colors.ink)}${turn}`;
823
+ getNoteWordsByLine(overlay).forEach((words, index) => {
824
+ const pos = { x: textBox.left, y: textBox.top + index * lineHeight };
825
+ const line = overlay.lines[index] as string;
826
+ const span = { start: overlay.start, end: overlay.end };
827
+ if (isStrip) {
828
+ const before = overlay.lines.slice(0, index).join("").length;
829
+ const typing = overlay.typing ?? 14;
830
+ const steps = getTypedSteps(line, { start: overlay.start + before / typing, end: overlay.end }, typing).map((step, stepIndex) => (stepIndex === 0 ? { ...step, from: overlay.start } : step));
831
+ events.push(...getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, motion: textMotion }));
832
+ return;
833
+ }
834
+ const fade = 100;
835
+ const shown = words.map((word) => `{\\alpha&HFF&\\t(${toMs(word.at - span.start)},${toMs(word.at - span.start) + fade},\\alpha&H00&)}${toAssText(word.text)}`).join(" ");
836
+ events.push(...getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps: [{ from: span.start, to: span.end, text: shown }], motion: textMotion }));
837
+ });
838
+ if (overlay.tickAt !== null) {
839
+ const points = getNoteTickPoints(overlay);
840
+ const xs = points.map((point) => point.x);
841
+ const ys = points.map((point) => point.y);
842
+ const room = overlay.fontSize * 0.2;
843
+ const clip = { x0: r0(Math.min(...xs) - room), y0: r0(Math.min(...ys) - room), x1: r0(Math.max(...xs) + room), y1: r0(Math.max(...ys) + room) };
844
+ const draw = `${toClip({ ...clip, x1: clip.x0 })}\\t(0,${toMs(NOTE_TICK_SECONDS)},${toClip(clip)})`;
845
+ const fade = motion.exit.kind === "none" ? "" : `\\fad(0,${FADE_OUT_MS})`;
846
+ events.push(`Dialogue: 4,${toAssTime(overlay.tickAt)},${toAssTime(overlay.end)},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${fade}${draw}${turn}\\1c${toTagColor(colors.tick)}\\p1}${getStrokeDrawing(points, overlay.fontSize * 0.12)}{\\p0}`);
847
+ }
848
+ return events;
849
+ }
850
+
851
+ /** An end word: one big handwritten line at the top, no card, white with a soft shadow, its letters dropping in (or its own entrance). */
852
+ function getEndWordEvents(overlay: Extract<ResolvedOverlay, { kind: "end_word" }>, context: DraftContext): string[] {
853
+ const name = overlay.entrance ?? "drop";
854
+ const motion = getDraftMotion(overlay, name, overlay.box, context);
855
+ const colour = overlay.colors.text ?? "#ffffff";
856
+ const tags = `\\an8\\fs${getHandFontAssSize(overlay.fontSize)}\\fn${HAND_FONT.family}\\b0\\1c${toTagColor(colour)}\\shad${r0(3 * context.scale)}\\4c&H000000&\\4a&H90&`;
857
+ const pos = { x: overlay.box.left + overlay.box.width / 2, y: overlay.box.top };
858
+ const span = { start: overlay.start, end: overlay.end };
859
+ if (name === "drop") {
860
+ const text = getDropText(overlay.text, getDropLetterTimes(span.start, overlay.text), span.start);
861
+ return getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps: [{ from: span.start, to: span.end, text }], motion: getPlainMotion(motion) });
862
+ }
863
+ return getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps: [{ from: span.start, to: span.end, text: toAssText(overlay.text) }], motion });
864
+ }
865
+
653
866
  /**
654
867
  * The overlays as ASS events, layers 3 and 4. `fonts` names the heading and interface families where they are not the
655
868
  * styles' own (the captions' font); `locale` groups a counter's number as the render does.
@@ -665,6 +878,8 @@ export function buildDraftOverlayEvents(
665
878
  if (overlay.kind === "punch_in") return [];
666
879
  if (overlay.kind === "arrow" || overlay.kind === "highlight") return getMarkEvents(overlay, context);
667
880
  if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") return getSideTextEvents(overlay, context);
881
+ if (overlay.kind === "note") return getNoteEvents(overlay, context);
882
+ if (overlay.kind === "end_word") return getEndWordEvents(overlay, context);
668
883
  return getCardEvents(overlay, context);
669
884
  });
670
885
  }