@softure-ai/marketing-kit 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +12 -0
- package/dist/footage/brand-style.d.ts +57 -0
- package/dist/footage/brand-style.d.ts.map +1 -0
- package/dist/footage/brand-style.js +49 -0
- package/dist/footage/brand-style.js.map +1 -0
- package/dist/footage/compose.d.ts +5 -0
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +10 -3
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/draft-boxes.d.ts +32 -0
- package/dist/footage/draft-boxes.d.ts.map +1 -0
- package/dist/footage/draft-boxes.js +28 -0
- package/dist/footage/draft-boxes.js.map +1 -0
- package/dist/footage/draft-overlays.d.ts +22 -0
- package/dist/footage/draft-overlays.d.ts.map +1 -1
- package/dist/footage/draft-overlays.js +67 -25
- package/dist/footage/draft-overlays.js.map +1 -1
- package/dist/footage/draft-text-width.d.ts +19 -0
- package/dist/footage/draft-text-width.d.ts.map +1 -0
- package/dist/footage/draft-text-width.js +59 -0
- package/dist/footage/draft-text-width.js.map +1 -0
- package/dist/footage/draft.d.ts +11 -0
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +64 -16
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/edl.d.ts +16 -0
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/overlay-html.d.ts +2 -0
- package/dist/footage/overlay-html.d.ts.map +1 -1
- package/dist/footage/overlay-html.js +36 -10
- package/dist/footage/overlay-html.js.map +1 -1
- package/dist/footage/overlay-schema.d.ts +28 -0
- package/dist/footage/overlay-schema.d.ts.map +1 -1
- package/dist/footage/overlay-schema.js +17 -0
- package/dist/footage/overlay-schema.js.map +1 -1
- package/dist/footage/overlays.d.ts +51 -2
- package/dist/footage/overlays.d.ts.map +1 -1
- package/dist/footage/overlays.js +96 -20
- package/dist/footage/overlays.js.map +1 -1
- package/dist/footage/pipeline.d.ts +6 -0
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +2 -1
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/og/character-map.d.ts +2 -0
- package/dist/og/character-map.d.ts.map +1 -1
- package/dist/og/character-map.js +12 -8
- package/dist/og/character-map.js.map +1 -1
- package/dist/og/index.d.ts +1 -0
- package/dist/og/index.d.ts.map +1 -1
- package/dist/og/index.js +1 -0
- package/dist/og/index.js.map +1 -1
- package/dist/og/photo-cover.d.ts +6 -0
- package/dist/og/photo-cover.d.ts.map +1 -1
- package/dist/og/photo-cover.js +12 -3
- package/dist/og/photo-cover.js.map +1 -1
- package/package.json +1 -1
- package/schema/edl.schema.json +28 -0
- package/src/footage/brand-style.ts +77 -0
- package/src/footage/compose.ts +13 -3
- package/src/footage/draft-boxes.ts +60 -0
- package/src/footage/draft-overlays.ts +73 -27
- package/src/footage/draft-text-width.ts +67 -0
- package/src/footage/draft.ts +112 -17
- package/src/footage/overlay-html.ts +45 -11
- package/src/footage/overlay-schema.ts +25 -0
- package/src/footage/overlays.ts +115 -22
- package/src/footage/pipeline.ts +8 -1
- package/src/index.ts +32 -0
- package/src/og/character-map.ts +12 -6
- package/src/og/index.ts +1 -0
- package/src/og/photo-cover.ts +18 -3
package/src/footage/overlays.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
isTypedOverlay,
|
|
10
10
|
type EdlOverlay,
|
|
11
11
|
type EdlOverlayColors,
|
|
12
|
+
type OverlayAlign,
|
|
12
13
|
type OverlayEntrance,
|
|
13
14
|
type OverlayKind,
|
|
14
15
|
type OverlayPosition,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
} from "./overlay-schema.js";
|
|
18
19
|
import { getSegmentZoomEases } from "./compose.js";
|
|
19
20
|
import { normalizeWord } from "./words.js";
|
|
21
|
+
import { STYLE_PADDING_SCALES, type BrandStyle, type CornerRadius } from "./brand-style.js";
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* An EDL's overlays resolved for the render and the draft (issue #1200): each one's film time (from its word through
|
|
@@ -38,14 +40,21 @@ export const OVERLAY_FONT_SIZES: Record<TextOverlayKind, Record<OverlaySize, num
|
|
|
38
40
|
keyword: { s: 64, m: 84, l: 108 },
|
|
39
41
|
lower_third: { s: 44, m: 52, l: 60 },
|
|
40
42
|
list: { s: 40, m: 48, l: 56 },
|
|
41
|
-
hook_title: { s:
|
|
43
|
+
hook_title: { s: 50, m: 64, l: 82 },
|
|
42
44
|
search_bar: { s: 36, m: 42, l: 50 },
|
|
43
|
-
place_card: { s:
|
|
45
|
+
place_card: { s: 70, m: 92, l: 118 },
|
|
44
46
|
counter: { s: 84, m: 108, l: 132 },
|
|
45
47
|
date_stamp: { s: 30, m: 36, l: 44 },
|
|
46
48
|
};
|
|
47
49
|
/** A second line's type size in main font sizes: the hook title's place label, the subtitle, the unit, the stamp's place. */
|
|
48
|
-
export const OVERLAY_SECONDARY_SCALE = { hook_title: 0.55, place_card: 0.
|
|
50
|
+
export const OVERLAY_SECONDARY_SCALE = { hook_title: 0.55, place_card: 0.55, counter: 0.5, date_stamp: 0.78 } as const;
|
|
51
|
+
/** A place card's subtitle size in title sizes, by its `subtitle_size` (RV-131 of an adopting app: 0.42 read tiny). */
|
|
52
|
+
export const OVERLAY_SUBTITLE_SCALES: Record<OverlaySize, number> = { s: 0.42, m: 0.55, l: 0.7 };
|
|
53
|
+
/** The smallest a place card's subtitle is drawn, in px of a 1080 px wide frame (2.3 % of a 1920 px tall one). */
|
|
54
|
+
export const MIN_OVERLAY_SUBTITLE_PX = 44;
|
|
55
|
+
/** How a title that does not fit two lines shrinks before it is refused: by this factor, at most `MAX_TITLE_SHRINKS` times. */
|
|
56
|
+
export const OVERLAY_TITLE_SHRINK = 0.9;
|
|
57
|
+
const MAX_TITLE_SHRINKS = 3;
|
|
49
58
|
/** A text overlay's line height and its box's padding, in font sizes. */
|
|
50
59
|
export const OVERLAY_LINE_HEIGHT = 1.15;
|
|
51
60
|
export const OVERLAY_LIST_LINE_HEIGHT = 1.4;
|
|
@@ -114,6 +123,10 @@ export interface OverlayLook {
|
|
|
114
123
|
typing: number | null;
|
|
115
124
|
/** Its own colours in place of the brand's (empty: the brand's). */
|
|
116
125
|
colors: EdlOverlayColors;
|
|
126
|
+
/** Its card's own corner (`style.corner_radius`), else null: the brand style's, or the kind's own without one. */
|
|
127
|
+
cornerRadius?: CornerRadius | null;
|
|
128
|
+
/** Its card's padding in `OVERLAY_PADDING_EM`s: the brand style's `padding` (`STYLE_PADDING_SCALES`); absent: 1. */
|
|
129
|
+
padScale?: number;
|
|
117
130
|
}
|
|
118
131
|
|
|
119
132
|
type Drawn = OverlayBase & OverlayLook;
|
|
@@ -129,9 +142,9 @@ export type ResolvedOverlay =
|
|
|
129
142
|
| (Drawn & { kind: "list"; items: string[]; fontSize: number; side: OverlaySide; box: OverlayBox })
|
|
130
143
|
| (Drawn & { kind: "arrow"; from: OverlayPoint; to: OverlayPoint })
|
|
131
144
|
| (Drawn & { kind: "highlight"; rect: OverlayBox })
|
|
132
|
-
| (Drawn & { kind: "hook_title"; lines: string[]; place: string | null; fontSize: number; placeFontSize: number; box: OverlayBox })
|
|
145
|
+
| (Drawn & { kind: "hook_title"; lines: string[]; place: string | null; fontSize: number; placeFontSize: number; align?: OverlayAlign; box: OverlayBox })
|
|
133
146
|
| (Drawn & { kind: "search_bar"; text: string; fontSize: number; box: OverlayBox })
|
|
134
|
-
| (Drawn & { kind: "place_card"; lines: string[]; subtitle: string | null; fontSize: number; subtitleFontSize: number; box: OverlayBox })
|
|
147
|
+
| (Drawn & { kind: "place_card"; lines: string[]; subtitle: string | null; fontSize: number; subtitleFontSize: number; align?: OverlayAlign; box: OverlayBox })
|
|
135
148
|
| (Drawn & { kind: "counter"; value: number; from: number; decimals: number; unit: string | null; fontSize: number; unitFontSize: number; box: OverlayBox })
|
|
136
149
|
| (Drawn & { kind: "date_stamp"; text: string; place: string | null; fontSize: number; placeFontSize: number; side: OverlaySide; box: OverlayBox });
|
|
137
150
|
|
|
@@ -145,6 +158,8 @@ export interface ResolveOverlaysInput {
|
|
|
145
158
|
frame: { width: number; height: number };
|
|
146
159
|
/** The film's caption box (`getFootageCaptionLayout`). */
|
|
147
160
|
caption: CaptionLayout;
|
|
161
|
+
/** The brand's style: its `padding` pads every overlay card (absent: `m`, the cards' own padding). */
|
|
162
|
+
style?: Pick<BrandStyle, "padding">;
|
|
148
163
|
}
|
|
149
164
|
|
|
150
165
|
/** The part of the frame no platform interface covers: a 9:16 film's caption preset zone (`all` without one), else 80 px. */
|
|
@@ -181,6 +196,12 @@ function findOverlayStart(overlay: EdlOverlay, words: TimedWord[]): { ok: true;
|
|
|
181
196
|
const r1 = (value: number): number => Math.round(value * 10) / 10;
|
|
182
197
|
const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
|
|
183
198
|
|
|
199
|
+
/** A drawn overlay's padding round its text, in px: `OVERLAY_PADDING_EM` of its font size, scaled by its `padScale`. */
|
|
200
|
+
export function getOverlayPadding(overlay: { fontSize: number; padScale?: number }): { x: number; y: number } {
|
|
201
|
+
const scale = overlay.padScale ?? 1;
|
|
202
|
+
return { x: Math.round(overlay.fontSize * OVERLAY_PADDING_EM.x * scale), y: Math.round(overlay.fontSize * OVERLAY_PADDING_EM.y * scale) };
|
|
203
|
+
}
|
|
204
|
+
|
|
184
205
|
/** The estimated width of a line of text at a font size, in px (`OVERLAY_CHAR_EM` a letter). */
|
|
185
206
|
export function estimateTextWidth(text: string, fontSize: number): number {
|
|
186
207
|
return Math.ceil([...text].length * OVERLAY_CHAR_EM * fontSize - 1e-6);
|
|
@@ -246,7 +267,7 @@ export function getSideTextLines(overlay: SideTextOverlay): string[] {
|
|
|
246
267
|
export function getDrawnOverlayCard(overlay: ResolvedOverlay): OverlayBox | null {
|
|
247
268
|
if (overlay.kind !== "keyword" && overlay.kind !== "lower_third" && overlay.kind !== "list") return getOverlayBounds(overlay);
|
|
248
269
|
const { box, fontSize, side } = overlay;
|
|
249
|
-
const padX =
|
|
270
|
+
const padX = getOverlayPadding(overlay).x;
|
|
250
271
|
const textWidth = Math.max(0, ...getSideTextLines(overlay).map((line) => estimateTextWidth(line, fontSize)));
|
|
251
272
|
const width = Math.min(box.width, Math.ceil(textWidth + 2 * padX));
|
|
252
273
|
return { left: side === "right" ? box.left + box.width - width : box.left, top: box.top, width, height: box.height };
|
|
@@ -327,7 +348,7 @@ export function resolveEdlOverlays(input: ResolveOverlaysInput): ResolvedOverlay
|
|
|
327
348
|
}
|
|
328
349
|
}
|
|
329
350
|
const base = { index, start, end, segment };
|
|
330
|
-
const placed = placeOverlay(overlay, base, { zone, frame, band: getCaptionBand(input, segment) });
|
|
351
|
+
const placed = placeOverlay(overlay, base, { zone, frame, band: getCaptionBand(input, segment), padScale: STYLE_PADDING_SCALES[input.style?.padding ?? "m"] });
|
|
331
352
|
if (!placed.ok) {
|
|
332
353
|
problems.push(`${at}: ${placed.error}`);
|
|
333
354
|
return;
|
|
@@ -388,6 +409,8 @@ interface Placement {
|
|
|
388
409
|
zone: { top: number; bottom: number; left: number; right: number };
|
|
389
410
|
frame: { width: number; height: number };
|
|
390
411
|
band: { top: number; bottom: number } | null;
|
|
412
|
+
/** Every card's padding scale (`STYLE_PADDING_SCALES` of the brand's `padding`). */
|
|
413
|
+
padScale: number;
|
|
391
414
|
}
|
|
392
415
|
|
|
393
416
|
type Placed = { ok: true; overlay: ResolvedOverlay } | { ok: false; error: string };
|
|
@@ -423,6 +446,7 @@ function getLook(overlay: EdlOverlay): OverlayLook {
|
|
|
423
446
|
entrance: overlay.style?.entrance ?? null,
|
|
424
447
|
typing: isTypedOverlay(overlay) ? (overlay.style?.typing_speed ?? DEFAULT_OVERLAY_TYPING_SPEED) : null,
|
|
425
448
|
colors: { ...overlay.style?.colors },
|
|
449
|
+
cornerRadius: overlay.style?.corner_radius ?? null,
|
|
426
450
|
};
|
|
427
451
|
}
|
|
428
452
|
|
|
@@ -431,7 +455,7 @@ function placeOverlay(overlay: EdlOverlay, base: OverlayBase, place: Placement):
|
|
|
431
455
|
const ease = r3(Math.min(PUNCH_IN_EASE_SECONDS, (base.end - base.start) / 2));
|
|
432
456
|
return { ok: true, overlay: { ...base, kind: "punch_in", scale: PUNCH_IN_SCALES[overlay.style?.size ?? "m"], ease } };
|
|
433
457
|
}
|
|
434
|
-
const drawn = { ...base, ...getLook(overlay) };
|
|
458
|
+
const drawn = { ...base, ...getLook(overlay), ...(place.padScale === 1 ? {} : { padScale: place.padScale }) };
|
|
435
459
|
if (overlay.kind === "arrow" || overlay.kind === "highlight") return placeMark(overlay, drawn, place);
|
|
436
460
|
if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") return placeSideText({ ...overlay, kind: overlay.kind }, drawn, place);
|
|
437
461
|
return placeCard({ ...overlay, kind: overlay.kind }, drawn, place);
|
|
@@ -469,7 +493,7 @@ function placeSideText(overlay: EdlOverlay & { kind: "keyword" | "lower_third" |
|
|
|
469
493
|
const scale = frame.width / 1080;
|
|
470
494
|
const side = overlay.style?.side ?? (overlay.kind === "keyword" ? "right" : "left");
|
|
471
495
|
const fontSize = Math.round(OVERLAY_FONT_SIZES[overlay.kind][overlay.style?.size ?? "m"] * scale);
|
|
472
|
-
const padY =
|
|
496
|
+
const padY = getOverlayPadding({ fontSize, padScale: place.padScale }).y;
|
|
473
497
|
const lines = overlay.kind === "list" ? (overlay.items ?? []).length : 1;
|
|
474
498
|
const lineHeight = overlay.kind === "list" ? OVERLAY_LIST_LINE_HEIGHT : OVERLAY_LINE_HEIGHT;
|
|
475
499
|
const height = Math.ceil(lines * fontSize * lineHeight + 2 * padY);
|
|
@@ -508,30 +532,99 @@ interface CardMetrics {
|
|
|
508
532
|
/** The widest the content may be, in px. */
|
|
509
533
|
room: number;
|
|
510
534
|
label: string;
|
|
535
|
+
/** The frame's width / 1080. */
|
|
536
|
+
scale: number;
|
|
511
537
|
}
|
|
512
538
|
|
|
513
539
|
const tooWide = (metrics: CardMetrics, what: string): CardResult => ({ ok: false, error: `the ${metrics.label}'s ${what} is too wide for one line; shorten it or use a smaller size` });
|
|
514
540
|
|
|
515
|
-
/**
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
541
|
+
/**
|
|
542
|
+
* A title's lines at a font size: two lines balanced so neither is much wider than the other (the narrower the
|
|
543
|
+
* wider of the two, the better), or the greedy wrap when it takes one line or more than two.
|
|
544
|
+
*/
|
|
545
|
+
export function wrapOverlayTitle(text: string, fontSize: number, width: number): string[] {
|
|
546
|
+
const lines = wrapOverlayText(text, fontSize, width);
|
|
547
|
+
if (lines.length !== 2) return lines;
|
|
548
|
+
const words = text.split(/\s+/).filter((part) => part.length > 0);
|
|
549
|
+
let best = lines;
|
|
550
|
+
let bestWidth = Math.max(...lines.map((line) => estimateTextWidth(line, fontSize)));
|
|
551
|
+
for (let split = 1; split < words.length; split++) {
|
|
552
|
+
const pair = [words.slice(0, split).join(" "), words.slice(split).join(" ")];
|
|
553
|
+
const widest = Math.max(...pair.map((line) => estimateTextWidth(line, fontSize)));
|
|
554
|
+
if (widest < bestWidth) [best, bestWidth] = [pair, widest];
|
|
555
|
+
}
|
|
556
|
+
return best;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** A title's lines and font size: its own size, else smaller by `OVERLAY_TITLE_SHRINK` until it fits two lines; null when it never does. */
|
|
560
|
+
function fitTitle(text: string, fontSize: number, room: number): { lines: string[]; fontSize: number } | null {
|
|
561
|
+
for (let shrink = 0, size = fontSize; shrink <= MAX_TITLE_SHRINKS; shrink++, size = Math.round(size * OVERLAY_TITLE_SHRINK)) {
|
|
562
|
+
const lines = wrapOverlayTitle(text, size, room);
|
|
563
|
+
if (lines.length <= MAX_OVERLAY_TITLE_LINES && lines.every((line) => estimateTextWidth(line, size) <= room)) return { lines, fontSize: size };
|
|
521
564
|
}
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* A place card's subtitle size: its `subtitle_size` of the title, at least `MIN_OVERLAY_SUBTITLE_PX`; a subtitle too
|
|
570
|
+
* long for that shrinks to fit `room`, never below the `s` step (the size every subtitle had before, so nothing that
|
|
571
|
+
* fitted then is refused now).
|
|
572
|
+
*/
|
|
573
|
+
function getSubtitleSize(input: { subtitle: string; titleSize: number; step: OverlaySize; room: number; scale: number }): number {
|
|
574
|
+
const wanted = Math.max(Math.round(MIN_OVERLAY_SUBTITLE_PX * input.scale), Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES[input.step]));
|
|
575
|
+
const fitting = Math.floor(input.room / ([...input.subtitle].length * OVERLAY_CHAR_EM));
|
|
576
|
+
return Math.min(wanted, Math.max(fitting, Math.round(input.titleSize * OVERLAY_SUBTITLE_SCALES.s)));
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/** A hook title's or a place card's second line: the place label (with its pin) or the subtitle. */
|
|
580
|
+
type TitleOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "place_card" }>;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* The text block of a hook title or a place card without its padding, in px: its widest line (the place label with
|
|
584
|
+
* its pin, the subtitle, each title line) and its height. Its card is this plus the padding, so the draft and the
|
|
585
|
+
* render find the block's left edge and top inside the card from it whatever the title's fitted size.
|
|
586
|
+
*/
|
|
587
|
+
export function getTitleContentSize(input: { kind: TitleOverlay["kind"]; lines: readonly string[]; fontSize: number; second: string | null; secondSize: number }): { width: number; height: number } {
|
|
588
|
+
const { kind, lines, fontSize, second, secondSize } = input;
|
|
589
|
+
const isHook = kind === "hook_title";
|
|
590
|
+
const secondWidth = second === null ? 0 : estimateTextWidth(second, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0);
|
|
591
|
+
const lineHeight = isHook ? OVERLAY_LINE_HEIGHT : OVERLAY_TITLE_LINE_HEIGHT;
|
|
592
|
+
return {
|
|
593
|
+
width: Math.max(secondWidth, ...lines.map((line) => estimateTextWidth(line, fontSize))),
|
|
594
|
+
height: lines.length * fontSize * lineHeight + (second === null ? 0 : secondSize * 1.3 + fontSize * 0.12),
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** A resolved title's text block inside its card: its left edge and top, in px of the frame. */
|
|
599
|
+
export function getTitleContentBox(overlay: TitleOverlay): OverlayBox {
|
|
600
|
+
const second = overlay.kind === "hook_title" ? overlay.place : overlay.subtitle;
|
|
601
|
+
const secondSize = overlay.kind === "hook_title" ? overlay.placeFontSize : overlay.subtitleFontSize;
|
|
602
|
+
const size = getTitleContentSize({ kind: overlay.kind, lines: overlay.lines, fontSize: overlay.fontSize, second, secondSize });
|
|
603
|
+
const { box } = overlay;
|
|
604
|
+
return { left: box.left + (box.width - size.width) / 2, top: box.top + (box.height - size.height) / 2, width: size.width, height: size.height };
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** A hook title's or a place card's lines and second line, aligned as its style says. */
|
|
608
|
+
function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card" }, metrics: CardMetrics): CardResult {
|
|
609
|
+
const { room, label } = metrics;
|
|
610
|
+
const fitted = fitTitle(overlay.text ?? "", metrics.fontSize, room);
|
|
611
|
+
if (fitted === null) return { ok: false, error: `the ${label} takes more than ${MAX_OVERLAY_TITLE_LINES} lines even at a smaller size; shorten it or use a smaller size` };
|
|
612
|
+
const { lines, fontSize } = fitted;
|
|
522
613
|
const isHook = overlay.kind === "hook_title";
|
|
523
614
|
const second = (isHook ? overlay.place : overlay.subtitle) ?? null;
|
|
524
|
-
const secondSize =
|
|
615
|
+
const secondSize =
|
|
616
|
+
!isHook && second !== null
|
|
617
|
+
? getSubtitleSize({ subtitle: second, titleSize: metrics.fontSize, step: overlay.style?.subtitle_size ?? "m", room, scale: metrics.scale })
|
|
618
|
+
: Math.round(metrics.fontSize * OVERLAY_SECONDARY_SCALE[overlay.kind]);
|
|
525
619
|
// The hook title's place label carries a pin about one label line wide before it.
|
|
526
620
|
const secondWidth = second === null ? 0 : estimateTextWidth(second, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0);
|
|
527
621
|
if (secondWidth > room) return tooWide(metrics, isHook ? "place label" : "subtitle");
|
|
528
|
-
const
|
|
622
|
+
const align = overlay.style?.align ?? "center";
|
|
529
623
|
return {
|
|
530
624
|
ok: true,
|
|
531
625
|
content: {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
fields: isHook ? { kind: "hook_title", lines, place: second, fontSize, placeFontSize: secondSize } : { kind: "place_card", lines, subtitle: second, fontSize, subtitleFontSize: secondSize },
|
|
626
|
+
...getTitleContentSize({ kind: overlay.kind, lines, fontSize, second, secondSize }),
|
|
627
|
+
fields: isHook ? { kind: "hook_title", lines, place: second, fontSize, placeFontSize: secondSize, align } : { kind: "place_card", lines, subtitle: second, fontSize, subtitleFontSize: secondSize, align },
|
|
535
628
|
},
|
|
536
629
|
};
|
|
537
630
|
}
|
|
@@ -588,8 +681,8 @@ function placeCard(overlay: EdlOverlay & { kind: CardKind }, drawn: Drawn, place
|
|
|
588
681
|
const margin = Math.round(OVERLAY_MARGIN * scale);
|
|
589
682
|
const outer = frame.width - zone.left - zone.right - 2 * margin;
|
|
590
683
|
const fontSize = Math.round(OVERLAY_FONT_SIZES[overlay.kind][overlay.style?.size ?? "m"] * scale);
|
|
591
|
-
const pad = {
|
|
592
|
-
const metrics = { fontSize, pad, room: outer - 2 * pad.x, label: overlay.kind.replace("_", " ") };
|
|
684
|
+
const pad = getOverlayPadding({ fontSize, padScale: place.padScale });
|
|
685
|
+
const metrics = { fontSize, pad, room: outer - 2 * pad.x, label: overlay.kind.replace("_", " "), scale };
|
|
593
686
|
const measured =
|
|
594
687
|
overlay.kind === "hook_title" || overlay.kind === "place_card"
|
|
595
688
|
? measureTitle({ ...overlay, kind: overlay.kind }, metrics)
|
package/src/footage/pipeline.ts
CHANGED
|
@@ -80,6 +80,7 @@ import {
|
|
|
80
80
|
} from "./publish.js";
|
|
81
81
|
import { describePaidSteps, toPaidAudio, type FootageCharge, type FootageProgress, type FootageProviders, type FootageStage, type PaidAudio, type PaidStep } from "./providers.js";
|
|
82
82
|
import { buildAudioArgs, buildCutPreviewArgs, buildLastFrameArgs, buildMusicArgs, buildSpeechArgs, getSpeechCutOptions } from "./render.js";
|
|
83
|
+
import type { BrandStyle } from "./brand-style.js";
|
|
83
84
|
|
|
84
85
|
export { getEdlPath } from "./paid.js";
|
|
85
86
|
|
|
@@ -121,6 +122,11 @@ export interface FootageBrand {
|
|
|
121
122
|
*/
|
|
122
123
|
fonts: { heading: BrandFont | null; body: BrandFont | null; interface?: BrandFont | null };
|
|
123
124
|
logo: string | null;
|
|
125
|
+
/**
|
|
126
|
+
* One look for every box (`brand-style.ts`): the caption pill's and each overlay card's corner radius, the pill's
|
|
127
|
+
* padding, a soft shadow and a thin accent border, in the draft and the render. Absent: each box as before.
|
|
128
|
+
*/
|
|
129
|
+
style?: BrandStyle;
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
export interface FootageRunOptions {
|
|
@@ -741,7 +747,7 @@ async function runRenderFootage(
|
|
|
741
747
|
if (lowDisk.length > 0) return err(`not enough disk space to render: ${lowDisk.join(" ")}`);
|
|
742
748
|
const seconds = getFootageFilmSeconds(film, edl);
|
|
743
749
|
const words = remapWords(edl, transcript.words, film.cut.fillers);
|
|
744
|
-
const overlays = resolveEdlOverlays({ film, edl, words, frame: getFrame(film), caption: getFootageCaptionLayout(film, options.layout ?? {}) });
|
|
750
|
+
const overlays = resolveEdlOverlays({ film, edl, words, frame: getFrame(film), caption: getFootageCaptionLayout(film, options.layout ?? {}), ...(options.brand.style === undefined ? {} : { style: options.brand.style }) });
|
|
745
751
|
if (!overlays.ok) return err(`footage film ${film.id}: the EDL's overlays cannot be drawn: ${overlays.problems.join("; ")}`, { kind: "input" });
|
|
746
752
|
const music = await getMusic(film, edl, clips, seconds, options);
|
|
747
753
|
if (!music.ok) return music;
|
|
@@ -882,6 +888,7 @@ async function runRenderFootage(
|
|
|
882
888
|
brandName: options.brand.name,
|
|
883
889
|
locale: options.brand.locale,
|
|
884
890
|
...(overlays.overlays.length === 0 ? {} : { overlays: overlays.overlays }),
|
|
891
|
+
...(options.brand.style === undefined ? {} : { style: options.brand.style }),
|
|
885
892
|
});
|
|
886
893
|
writeFileSync(join(buildDir, "index.html"), html);
|
|
887
894
|
mkdirSync(dirname(options.output), { recursive: true });
|
package/src/index.ts
CHANGED
|
@@ -88,6 +88,8 @@ export {
|
|
|
88
88
|
MAX_OVERLAY_UNIT_LENGTH,
|
|
89
89
|
MIN_OVERLAY_SECONDS,
|
|
90
90
|
MIN_OVERLAY_TYPING_SPEED,
|
|
91
|
+
OVERLAY_ALIGNED_KINDS,
|
|
92
|
+
OVERLAY_ALIGNS,
|
|
91
93
|
OVERLAY_ENTRANCES,
|
|
92
94
|
OVERLAY_ENTRANCES_BY_KIND,
|
|
93
95
|
OVERLAY_KINDS,
|
|
@@ -102,21 +104,51 @@ export {
|
|
|
102
104
|
type EdlOverlayColors,
|
|
103
105
|
type EdlOverlayStyle,
|
|
104
106
|
type EdlOverlayWord,
|
|
107
|
+
type OverlayAlign,
|
|
105
108
|
type OverlayEntrance,
|
|
106
109
|
type OverlayKind,
|
|
107
110
|
type OverlayPosition,
|
|
108
111
|
type OverlaySide,
|
|
109
112
|
type OverlaySize,
|
|
110
113
|
} from "./footage/overlay-schema.js";
|
|
114
|
+
export {
|
|
115
|
+
CORNER_RADII,
|
|
116
|
+
CORNER_RADIUS_PX,
|
|
117
|
+
STYLE_BORDER_PX,
|
|
118
|
+
STYLE_BORDERS,
|
|
119
|
+
STYLE_PADDING_SCALES,
|
|
120
|
+
STYLE_PADDINGS,
|
|
121
|
+
STYLE_SHADOW,
|
|
122
|
+
STYLE_SHADOWS,
|
|
123
|
+
getCaptionCornerRadius,
|
|
124
|
+
getCornerRadiusCss,
|
|
125
|
+
getCornerRadiusPx,
|
|
126
|
+
getStyleBorderCss,
|
|
127
|
+
getStylePadding,
|
|
128
|
+
getStyleShadowCss,
|
|
129
|
+
type BrandStyle,
|
|
130
|
+
type CornerRadius,
|
|
131
|
+
type StyleBorder,
|
|
132
|
+
type StylePadding,
|
|
133
|
+
type StyleShadow,
|
|
134
|
+
} from "./footage/brand-style.js";
|
|
135
|
+
export { createDraftTextMeasure, wrapDraftLine, type DraftTextMeasure } from "./footage/draft-text-width.js";
|
|
111
136
|
export {
|
|
112
137
|
OVERLAY_FONT_ROLES,
|
|
113
138
|
OVERLAY_FONT_SIZES,
|
|
139
|
+
OVERLAY_SUBTITLE_SCALES,
|
|
140
|
+
MIN_OVERLAY_SUBTITLE_PX,
|
|
141
|
+
OVERLAY_TITLE_SHRINK,
|
|
114
142
|
PUNCH_IN_EASE_SECONDS,
|
|
115
143
|
PUNCH_IN_SCALES,
|
|
116
144
|
findShotBreak,
|
|
117
145
|
formatOverlayNumber,
|
|
118
146
|
getDrawnOverlayCard,
|
|
119
147
|
getOverlayBounds,
|
|
148
|
+
getOverlayPadding,
|
|
149
|
+
getTitleContentBox,
|
|
150
|
+
getTitleContentSize,
|
|
151
|
+
wrapOverlayTitle,
|
|
120
152
|
getOverlaySafeZone,
|
|
121
153
|
getOverlayTexts,
|
|
122
154
|
getOverlayTextsByRole,
|
package/src/og/character-map.ts
CHANGED
|
@@ -10,6 +10,8 @@ import { err, ok, type OgResult } from "./result.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export interface CharacterMap {
|
|
12
12
|
has(codePoint: number): boolean;
|
|
13
|
+
/** The glyph the code point maps to; 0 (`.notdef`) when the font lacks it or the table is broken there. */
|
|
14
|
+
getGlyph(codePoint: number): number;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/** The raw `cmap` table of a font file, or a reason it has none. */
|
|
@@ -70,14 +72,18 @@ function readCmap(table: Buffer): OgResult<CharacterMap> {
|
|
|
70
72
|
const format = readUint16(table, start);
|
|
71
73
|
if (format !== 4 && format !== 12) return err(`the font's character map has format ${format}; Satori reads formats 4 and 12`);
|
|
72
74
|
const getGlyph = format === 4 ? getFormat4Glyph : getFormat12Glyph;
|
|
75
|
+
const findGlyph = (codePoint: number): number => {
|
|
76
|
+
try {
|
|
77
|
+
return getGlyph(table, start, codePoint);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error instanceof OutOfBounds) return 0;
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
73
83
|
return ok({
|
|
84
|
+
getGlyph: findGlyph,
|
|
74
85
|
has(codePoint) {
|
|
75
|
-
|
|
76
|
-
return getGlyph(table, start, codePoint) !== 0;
|
|
77
|
-
} catch (error) {
|
|
78
|
-
if (error instanceof OutOfBounds) return false;
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
86
|
+
return findGlyph(codePoint) !== 0;
|
|
81
87
|
},
|
|
82
88
|
});
|
|
83
89
|
}
|
package/src/og/index.ts
CHANGED
package/src/og/photo-cover.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { describeCharacter, findMissingGlyphs } from "./glyphs.js";
|
|
|
12
12
|
import { toOpaqueHex, withAlpha } from "./palette.js";
|
|
13
13
|
import { getCoverCrop, getOrientationMatrix, getOrientedSize, readPhotoInfo, type FocusPoint } from "./photo.js";
|
|
14
14
|
import { err, ok, type OgResult } from "./result.js";
|
|
15
|
+
import { CORNER_RADII, CORNER_RADIUS_PX, type CornerRadius } from "../footage/brand-style.js";
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* A publish-ready cover for a vertical video from a photo the owner picks: the photo scaled to cover the frame and
|
|
@@ -120,6 +121,7 @@ const coverOptionsSchema = z.object({
|
|
|
120
121
|
tone: z.enum(["light", "dark"]).optional(),
|
|
121
122
|
accent: z.boolean().optional(),
|
|
122
123
|
accentStyle: z.enum(PHOTO_COVER_ACCENT_STYLES).optional(),
|
|
124
|
+
cornerRadius: z.enum(CORNER_RADII).optional(),
|
|
123
125
|
quality: z.number().int().min(1).max(100).default(PHOTO_COVER_QUALITY),
|
|
124
126
|
});
|
|
125
127
|
|
|
@@ -150,6 +152,11 @@ export interface PhotoCoverInput {
|
|
|
150
152
|
colors: BrandColors;
|
|
151
153
|
/** The brand's fonts (`loadOgFonts`); the text is set in the heading (display) family. */
|
|
152
154
|
fonts: OgFonts;
|
|
155
|
+
/**
|
|
156
|
+
* The brand style's corner (`BrandStyle.cornerRadius`) for the `pill` box and the kicker's accent box, in px of a
|
|
157
|
+
* 1080 px wide band; each layout's own corner by default.
|
|
158
|
+
*/
|
|
159
|
+
cornerRadius?: CornerRadius;
|
|
153
160
|
/** JPEG quality, 1-100; 90 by default. */
|
|
154
161
|
quality?: number;
|
|
155
162
|
/** Names the cover in errors, e.g. the video's id. */
|
|
@@ -313,6 +320,13 @@ interface TextLayout {
|
|
|
313
320
|
text: CoverText;
|
|
314
321
|
fonts: OgFonts;
|
|
315
322
|
ink: CoverInk;
|
|
323
|
+
cornerRadius?: CornerRadius;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** A box's corner on the cover: the style's token (a pill as 999 px, which Satori keeps to half the height), else `own`. */
|
|
327
|
+
function getCoverRadius(token: CornerRadius | undefined, own: number, scale: number): number {
|
|
328
|
+
if (token === undefined) return Math.round(own * scale);
|
|
329
|
+
return token === "pill" ? 999 : Math.round(CORNER_RADIUS_PX[token] * scale);
|
|
316
330
|
}
|
|
317
331
|
|
|
318
332
|
/** Where the text block sits: its foot above the band's lower edge, its head below the band's top, or centred in the middle third. */
|
|
@@ -346,7 +360,7 @@ function buildTextTree(layout: TextLayout): OgNode {
|
|
|
346
360
|
display: "flex",
|
|
347
361
|
maxWidth: "100%",
|
|
348
362
|
padding: `${String(Math.round(PILL_PADDING[0] * scale))}px ${String(Math.round(PILL_PADDING[1] * scale))}px`,
|
|
349
|
-
borderRadius:
|
|
363
|
+
borderRadius: getCoverRadius(layout.cornerRadius, PILL_SIZE, scale),
|
|
350
364
|
backgroundColor: withAlpha(ink.pill.box, ink.pill.alpha),
|
|
351
365
|
textAlign: "center",
|
|
352
366
|
wordBreak: "break-word",
|
|
@@ -371,7 +385,7 @@ function buildTextTree(layout: TextLayout): OgNode {
|
|
|
371
385
|
display: "flex",
|
|
372
386
|
maxWidth: "100%",
|
|
373
387
|
padding: `${String(Math.round(KICKER_BOX_PADDING[0] * scale))}px ${String(Math.round(KICKER_BOX_PADDING[1] * scale))}px`,
|
|
374
|
-
borderRadius:
|
|
388
|
+
borderRadius: getCoverRadius(layout.cornerRadius, KICKER_BOX_RADIUS, scale),
|
|
375
389
|
backgroundColor: ink.kickerBox,
|
|
376
390
|
textAlign: "center",
|
|
377
391
|
wordBreak: "break-word",
|
|
@@ -523,6 +537,7 @@ export async function renderPhotoCover(input: PhotoCoverInput): Promise<OgResult
|
|
|
523
537
|
tone: input.tone,
|
|
524
538
|
accent: input.accent,
|
|
525
539
|
accentStyle: input.accentStyle,
|
|
540
|
+
cornerRadius: input.cornerRadius,
|
|
526
541
|
quality: input.quality,
|
|
527
542
|
});
|
|
528
543
|
if (!parsed.success) {
|
|
@@ -542,7 +557,7 @@ export async function renderPhotoCover(input: PhotoCoverInput): Promise<OgResult
|
|
|
542
557
|
const band = getCoverBand(size);
|
|
543
558
|
const ink = getCoverInk(input.colors, { tone: options.tone ?? "light", layout: text.value?.layout ?? null, accent: options.accent ?? false, accentStyle: options.accentStyle ?? "text" });
|
|
544
559
|
if (!ink.ok) return err(`${name}: ${ink.error}.`);
|
|
545
|
-
const drawn = text.value === null ? null : await layOutText({ size, band, text: text.value, fonts: input.fonts, ink: ink.value });
|
|
560
|
+
const drawn = text.value === null ? null : await layOutText({ size, band, text: text.value, fonts: input.fonts, ink: ink.value, ...(options.cornerRadius === undefined ? {} : { cornerRadius: options.cornerRadius }) });
|
|
546
561
|
if (drawn !== null && !drawn.ok) return err(`${name}: ${drawn.error}.`);
|
|
547
562
|
|
|
548
563
|
const oriented = getOrientedSize(info.value);
|