@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
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { readCharacterMap } from "../og/character-map.js";
|
|
2
|
+
import { OutOfBounds, readFontTables, readInt16, readUint16 } from "../og/font-tables.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The width of a line of text as libass draws it in a footage draft, measured from the draft font's own advance
|
|
6
|
+
* widths (`hmtx` through `cmap`), so the draft can draw a rounded caption pill that fits its text (libass sizes only
|
|
7
|
+
* its square `BorderStyle 3` box itself). libass scales a font the VSFilter way: `usWinAscent + usWinDescent` (OS/2,
|
|
8
|
+
* else the `hhea` ascender and descender) is the font size, so a line is one font size tall and an advance is
|
|
9
|
+
* `advance * fontSize / (winAscent + winDescent)`. Kerning is not read: a few px on a line, inside the pill's padding.
|
|
10
|
+
*/
|
|
11
|
+
export type DraftTextMeasure = (text: string, fontSize: number) => number;
|
|
12
|
+
|
|
13
|
+
interface Metrics {
|
|
14
|
+
/** The font's units per libass font size: `usWinAscent + usWinDescent`. */
|
|
15
|
+
unitsPerSize: number;
|
|
16
|
+
advances: (glyph: number) => number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function readMetrics(font: Buffer): Metrics | null {
|
|
20
|
+
const tables = readFontTables(font);
|
|
21
|
+
if (!tables.ok) return null;
|
|
22
|
+
const hhea = tables.value.get("hhea");
|
|
23
|
+
const hmtx = tables.value.get("hmtx");
|
|
24
|
+
if (hhea === undefined || hmtx === undefined) return null;
|
|
25
|
+
const os2 = tables.value.get("OS/2");
|
|
26
|
+
const winSum = os2 === undefined ? 0 : readUint16(os2, 74) + readUint16(os2, 76);
|
|
27
|
+
const unitsPerSize = winSum > 0 ? winSum : readInt16(hhea, 4) - readInt16(hhea, 6);
|
|
28
|
+
const count = readUint16(hhea, 34);
|
|
29
|
+
if (unitsPerSize <= 0 || count === 0 || hmtx.length < count * 4) return null;
|
|
30
|
+
// Glyphs past `numberOfHMetrics` share the last advance (OpenType `hmtx`).
|
|
31
|
+
return { unitsPerSize, advances: (glyph) => readUint16(hmtx, Math.min(glyph, count - 1) * 4) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A measure of the draft font `font` (a TrueType or OpenType file), or null when its tables cannot be read; the
|
|
36
|
+
* caller then falls back to an estimate. A character the font lacks is measured as its `.notdef` glyph, as drawn.
|
|
37
|
+
*/
|
|
38
|
+
export function createDraftTextMeasure(font: Buffer): DraftTextMeasure | null {
|
|
39
|
+
try {
|
|
40
|
+
const metrics = readMetrics(font);
|
|
41
|
+
const characters = readCharacterMap(font);
|
|
42
|
+
if (metrics === null || !characters.ok) return null;
|
|
43
|
+
const map = characters.value;
|
|
44
|
+
return (text, fontSize) => {
|
|
45
|
+
let units = 0;
|
|
46
|
+
for (const character of text) units += metrics.advances(map.getGlyph(character.codePointAt(0) ?? 0));
|
|
47
|
+
return Math.ceil((units * fontSize) / metrics.unitsPerSize);
|
|
48
|
+
};
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error instanceof OutOfBounds) return null;
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Words broken into lines that fit `width` by `measure`, greedily as a browser breaks the render's pill: each line is
|
|
57
|
+
* its words, and a word wider than a line stands alone on its own.
|
|
58
|
+
*/
|
|
59
|
+
export function wrapDraftLine(words: readonly string[], width: number, fontSize: number, measure: DraftTextMeasure): string[][] {
|
|
60
|
+
const lines: string[][] = [];
|
|
61
|
+
for (const word of words) {
|
|
62
|
+
const last = lines[lines.length - 1];
|
|
63
|
+
if (last !== undefined && measure([...last, word].join(" "), fontSize) <= width) last.push(word);
|
|
64
|
+
else lines.push([word]);
|
|
65
|
+
}
|
|
66
|
+
return lines;
|
|
67
|
+
}
|
package/src/footage/draft.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { copyFileSync, existsSync, mkdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, join, resolve } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
@@ -11,6 +11,11 @@ import { getCaptionChunkLayouts, getCaptionSpans, getFootageCaptionChunks, getFo
|
|
|
11
11
|
import { getSegmentScales, getSegmentZoomEases } from "./compose.js";
|
|
12
12
|
import { toAssColor } from "./draft-color.js";
|
|
13
13
|
import { buildDraftOverlayEvents, getDraftOverlayStyles } from "./draft-overlays.js";
|
|
14
|
+
import { getCaptionCornerRadius, getCornerRadiusPx, getStylePadding, type BrandStyle } from "./brand-style.js";
|
|
15
|
+
import { getDraftBoxEvents } from "./draft-boxes.js";
|
|
16
|
+
import { createDraftTextMeasure, wrapDraftLine, type DraftTextMeasure } from "./draft-text-width.js";
|
|
17
|
+
import { CAPTION_PILL_PADDING } from "../compose/timeline.js";
|
|
18
|
+
import { estimateTextWidth } from "./overlays.js";
|
|
14
19
|
import type { OverlayColors } from "./overlay-html.js";
|
|
15
20
|
import { resolveEdlOverlays, type OverlayFontRole, type ResolvedOverlay } from "./overlays.js";
|
|
16
21
|
import { chooseFootageDraftFont } from "./draft-font.js";
|
|
@@ -138,6 +143,14 @@ export interface FootageDraftCaptionsInput {
|
|
|
138
143
|
overlayFonts?: Partial<Record<OverlayFontRole, string>>;
|
|
139
144
|
/** How a counter groups its number (BCP 47); default `en-US`. */
|
|
140
145
|
locale?: string;
|
|
146
|
+
/**
|
|
147
|
+
* The brand's style (`FootageBrand.style`): a `highlight` chunk is drawn on a rounded pill of its radius, padding,
|
|
148
|
+
* shadow and border, its lines broken by `measure`; the overlay cards take its radius, shadow and border. Absent:
|
|
149
|
+
* libass's square box, as before.
|
|
150
|
+
*/
|
|
151
|
+
style?: BrandStyle;
|
|
152
|
+
/** The width of a line in the captions' font (`createDraftTextMeasure`); absent or null: the `OVERLAY_CHAR_EM` estimate. */
|
|
153
|
+
measure?: DraftTextMeasure | null;
|
|
141
154
|
}
|
|
142
155
|
|
|
143
156
|
/** The pieces of a `highlight` chunk's span: cut wherever a word lights up or goes out (in centiseconds), with the words lit in each. */
|
|
@@ -149,35 +162,105 @@ function getHighlightPieces(chunk: { words: TimedWord[] }, span: { start: number
|
|
|
149
162
|
return cuts.slice(0, -1).map((at, index) => ({ from: at, to: cuts[index + 1] as number, lit: lights.map((light) => light.on <= at && at < light.off) }));
|
|
150
163
|
}
|
|
151
164
|
|
|
165
|
+
/** Words joined for one ASS line: a space, or `\\N` after the words a drawn pill's lines end on. */
|
|
166
|
+
function joinWords(words: readonly string[], breaks: ReadonlySet<number>): string {
|
|
167
|
+
return words.map((word, index) => (index === 0 ? word : `${breaks.has(index - 1) ? "\\N" : " "}${word}`)).join("");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** How a chunk's events are laid out: its line breaks, and whether a drawn pill stands under it (so libass draws no box). */
|
|
171
|
+
interface ChunkLayout {
|
|
172
|
+
breaks: ReadonlySet<number>;
|
|
173
|
+
hasPill: boolean;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const BOXLESS_LAYOUT: ChunkLayout = { breaks: new Set(), hasPill: false };
|
|
177
|
+
/** The tags that hide libass's own box of a `BorderStyle 3` style, for text over a drawn pill. */
|
|
178
|
+
const NO_BOX = "{\\3a&HFF&\\4a&HFF&}";
|
|
179
|
+
|
|
152
180
|
/**
|
|
153
181
|
* A `highlight` chunk as ASS events: its span cut wherever a word lights up or goes out, each piece showing the chunk
|
|
154
182
|
* with the words lit then in `highlight` (a word stays lit for the render's 0.32 s from its start).
|
|
155
183
|
*/
|
|
156
|
-
function buildHighlightEvents(chunk: { words: TimedWord[] }, span: { start: number; end: number }, colors: { text: string; highlight: string }, styleName: string): string[] {
|
|
184
|
+
function buildHighlightEvents(chunk: { words: TimedWord[] }, span: { start: number; end: number }, colors: { text: string; highlight: string }, styleName: string, layout: ChunkLayout = BOXLESS_LAYOUT): string[] {
|
|
157
185
|
return getHighlightPieces(chunk, span).map((piece) => {
|
|
158
|
-
const
|
|
159
|
-
return `Dialogue: 0,${toAssTime(piece.from / 100)},${toAssTime(piece.to / 100)},${styleName},,0,0,0,,${
|
|
186
|
+
const words = chunk.words.map((word, wordIndex) => (piece.lit[wordIndex] === true ? `{\\1c${colors.highlight}&}${toAssText(word.text)}{\\1c${colors.text}&}` : toAssText(word.text)));
|
|
187
|
+
return `Dialogue: 0,${toAssTime(piece.from / 100)},${toAssTime(piece.to / 100)},${styleName},,0,0,0,,${layout.hasPill ? NO_BOX : ""}${joinWords(words, layout.breaks)}`;
|
|
160
188
|
});
|
|
161
189
|
}
|
|
162
190
|
|
|
163
191
|
/**
|
|
164
192
|
* A `box` highlight chunk as ASS events (issue #1199), three layers per piece of its span. libass draws a
|
|
165
193
|
* `BorderStyle 3` box per glyph, in each glyph's own `\3c` and `\3a`, so the layers share one layout: 0 is the pill
|
|
166
|
-
* (its text hidden), 1 the lit word's box (every other glyph's box transparent, grown by
|
|
167
|
-
* pill's), 2 the text alone (no box) with the lit word in its box text colour.
|
|
194
|
+
* (its text hidden; left out over a drawn pill), 1 the lit word's box (every other glyph's box transparent, grown by
|
|
195
|
+
* `boxPadding` instead of the pill's), 2 the text alone (no box) with the lit word in its box text colour.
|
|
168
196
|
*/
|
|
169
|
-
function buildHighlightBoxEvents(
|
|
197
|
+
function buildHighlightBoxEvents(
|
|
198
|
+
chunk: { words: TimedWord[] },
|
|
199
|
+
span: { start: number; end: number },
|
|
200
|
+
colors: { text: string; box: string; boxText: string },
|
|
201
|
+
boxPadding: number,
|
|
202
|
+
styleName: string,
|
|
203
|
+
layout: ChunkLayout = BOXLESS_LAYOUT,
|
|
204
|
+
): string[] {
|
|
170
205
|
return getHighlightPieces(chunk, span).flatMap((piece) => {
|
|
171
206
|
const at = `${toAssTime(piece.from / 100)},${toAssTime(piece.to / 100)},${styleName},,0,0,0,,`;
|
|
172
207
|
const shown = chunk.words.map((word) => toAssText(word.text));
|
|
173
|
-
const pill = `{\\1a&HFF&}${shown.
|
|
174
|
-
const box = `{\\1a&HFF&\\bord${boxPadding}\\3a&HFF&}${
|
|
175
|
-
|
|
208
|
+
const pill = `{\\1a&HFF&}${joinWords(shown, layout.breaks)}`;
|
|
209
|
+
const box = `{\\1a&HFF&\\bord${boxPadding}\\3a&HFF&}${joinWords(
|
|
210
|
+
shown.map((text, index) => (piece.lit[index] === true ? `{\\3c${colors.box}&\\3a&H00&}${text}{\\3a&HFF&}` : text)),
|
|
211
|
+
layout.breaks,
|
|
212
|
+
)}`;
|
|
213
|
+
const text = `{\\3a&HFF&\\4a&HFF&}${joinWords(
|
|
214
|
+
shown.map((word, index) => (piece.lit[index] === true ? `{\\1c${colors.boxText}&}${word}{\\1c${colors.text}&}` : word)),
|
|
215
|
+
layout.breaks,
|
|
216
|
+
)}`;
|
|
176
217
|
const isLit = piece.lit.some((lit) => lit);
|
|
177
|
-
return [`Dialogue: 0,${at}${pill}
|
|
218
|
+
return [...(layout.hasPill ? [] : [`Dialogue: 0,${at}${pill}`]), ...(isLit ? [`Dialogue: 1,${at}${box}`] : []), `Dialogue: 2,${at}${text}`];
|
|
178
219
|
});
|
|
179
220
|
}
|
|
180
221
|
|
|
222
|
+
/** The pill of a chunk drawn in the brand's style: its lines (broken by width) and its shadow, box and border events. */
|
|
223
|
+
interface DrawnPill {
|
|
224
|
+
breaks: Set<number>;
|
|
225
|
+
events: string[];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
interface DrawnPillInput {
|
|
229
|
+
words: readonly string[];
|
|
230
|
+
span: { start: number; end: number };
|
|
231
|
+
place: CaptionLayout;
|
|
232
|
+
frame: Frame;
|
|
233
|
+
style: BrandStyle;
|
|
234
|
+
measure: DraftTextMeasure;
|
|
235
|
+
colors: { background: string; accent: string };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* A chunk's rounded pill (`style`): its words broken greedily into lines that fit the caption box less the padding,
|
|
240
|
+
* the pill as wide as the widest line and as tall as the lines (libass draws a line one font size tall) plus the
|
|
241
|
+
* padding, centred in the box and hung from its foot (or its top) as the text is.
|
|
242
|
+
*/
|
|
243
|
+
function getDrawnPill(input: DrawnPillInput): DrawnPill {
|
|
244
|
+
const { place, frame, style, measure } = input;
|
|
245
|
+
const scale = frame.width / 1080;
|
|
246
|
+
const pad = getStylePadding(CAPTION_PILL_PADDING, style.padding);
|
|
247
|
+
const areaWidth = frame.width - place.left - place.right;
|
|
248
|
+
const lines = wrapDraftLine(input.words, areaWidth - 2 * pad.x, place.fontSize, measure);
|
|
249
|
+
const breaks = new Set<number>();
|
|
250
|
+
let counted = 0;
|
|
251
|
+
for (const line of lines.slice(0, -1)) {
|
|
252
|
+
counted += line.length;
|
|
253
|
+
breaks.add(counted - 1);
|
|
254
|
+
}
|
|
255
|
+
const width = Math.min(areaWidth, Math.max(...lines.map((line) => measure(line.join(" "), place.fontSize))) + 2 * pad.x);
|
|
256
|
+
const height = lines.length * place.fontSize + 2 * pad.y;
|
|
257
|
+
const textTop = place.bottom === undefined ? place.top : frame.height - place.bottom - lines.length * place.fontSize;
|
|
258
|
+
const box = { left: place.left + (areaWidth - width) / 2, top: textTop - pad.y, width, height };
|
|
259
|
+
const at = `${toAssTime(input.span.start)},${toAssTime(input.span.end)}`;
|
|
260
|
+
const radius = getCornerRadiusPx(getCaptionCornerRadius(style), height, scale);
|
|
261
|
+
return { breaks, events: getDraftBoxEvents({ layer: 0, at, styleName: "CaptionShape", box, radius, color: input.colors.background, accent: input.colors.accent, style, scale }) };
|
|
262
|
+
}
|
|
263
|
+
|
|
181
264
|
/** The highlight look the draft draws: `text` for a `phrase` film; a `box` film without its colours is an input error. */
|
|
182
265
|
function getDraftHighlightLook(film: Pick<FootageFilm, "captionStyle" | "captionHighlightStyle">, colors: FootageDraftCaptionColors): CaptionHighlightLook {
|
|
183
266
|
if (film.captionStyle !== "highlight") return { style: "text", color: colors.captionHighlight };
|
|
@@ -246,7 +329,8 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
246
329
|
// A chunk in a segment's own box gets a style of that box (Caption2, Caption3, ...); the film's box stays `Caption`.
|
|
247
330
|
const styles = [toStyle("Caption", caption)];
|
|
248
331
|
const moved: CaptionLayout[] = [];
|
|
249
|
-
const
|
|
332
|
+
const places = getCaptionChunkLayouts(chunks, input.edl, caption);
|
|
333
|
+
const styleNames = places.map((place) => {
|
|
250
334
|
if (isSameCaptionPlace(place, caption)) return "Caption";
|
|
251
335
|
let index = moved.findIndex((other) => isSameCaptionPlace(other, place));
|
|
252
336
|
if (index === -1) {
|
|
@@ -259,11 +343,19 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
259
343
|
const lit = getDraftHighlightLook(input.film, colors);
|
|
260
344
|
const boxColors = lit.style === "box" ? { text: highlight.text, box: toAssColor(lit.box).replace(/^&H../, "&H"), boxText: toAssColor(lit.text).replace(/^&H../, "&H") } : null;
|
|
261
345
|
const boxPadding = Math.max(1, Math.round(caption.fontSize * CAPTION_HIGHLIGHT_BOX_PADDING_EM));
|
|
346
|
+
// With the brand's style a `highlight` chunk stands on a drawn rounded pill (its lines broken here), not libass's box.
|
|
347
|
+
const style = isHighlight ? input.style : undefined;
|
|
348
|
+
const measure = input.measure ?? ((line: string, size: number) => estimateTextWidth(line, size));
|
|
349
|
+
const pillColors = { background: colors.captionBackground, accent: lit.style === "box" ? lit.box : colors.captionHighlight };
|
|
262
350
|
const events = chunks.flatMap((chunk, index) => {
|
|
263
351
|
const span = spans[index] as { start: number; end: number };
|
|
264
352
|
const styleName = styleNames[index] ?? "Caption";
|
|
265
|
-
|
|
266
|
-
|
|
353
|
+
const pill =
|
|
354
|
+
style === undefined ? null : getDrawnPill({ words: chunk.words.map((word) => word.text.replace(/\u00a0/g, " ")), span, place: places[index] ?? caption, frame, style, measure, colors: pillColors });
|
|
355
|
+
const layout: ChunkLayout = pill === null ? BOXLESS_LAYOUT : { breaks: pill.breaks, hasPill: true };
|
|
356
|
+
const drawn = pill?.events ?? [];
|
|
357
|
+
if (isHighlight && boxColors !== null) return [...drawn, ...buildHighlightBoxEvents(chunk, span, boxColors, boxPadding, styleName, layout)];
|
|
358
|
+
if (isHighlight) return [...drawn, ...buildHighlightEvents(chunk, span, highlight, styleName, layout)];
|
|
267
359
|
const line = toAssText(chunk.words.map((word) => word.text).join(" "));
|
|
268
360
|
return [`Dialogue: 0,${toAssTime(span.start)},${toAssTime(span.end)},${styleName},,0,0,0,,${line}`];
|
|
269
361
|
});
|
|
@@ -277,7 +369,8 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
277
369
|
"",
|
|
278
370
|
"[V4+ Styles]",
|
|
279
371
|
"Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding",
|
|
280
|
-
...styles.map((
|
|
372
|
+
...styles.map((line) => `Style: ${line}`),
|
|
373
|
+
...(style === undefined || chunks.length === 0 ? [] : [`Style: CaptionShape,${family},${String(caption.fontSize)},&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1`]),
|
|
281
374
|
...(overlays.length === 0 ? [] : getDraftOverlayStyles(family, input.overlayColors ?? FOOTAGE_DRAFT_OVERLAY_COLORS)),
|
|
282
375
|
"",
|
|
283
376
|
"[Events]",
|
|
@@ -286,6 +379,7 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
286
379
|
...buildDraftOverlayEvents(overlays, input.overlayColors ?? FOOTAGE_DRAFT_OVERLAY_COLORS, input.frame, {
|
|
287
380
|
...(input.overlayFonts === undefined ? {} : { fonts: input.overlayFonts }),
|
|
288
381
|
...(input.locale === undefined ? {} : { locale: input.locale }),
|
|
382
|
+
...(input.style === undefined ? {} : { style: input.style }),
|
|
289
383
|
}),
|
|
290
384
|
"",
|
|
291
385
|
].join("\n");
|
|
@@ -526,7 +620,7 @@ export interface RenderFootageDraftOptions extends Pick<FootageRunOptions, "buil
|
|
|
526
620
|
* OpenType file; DejaVu Sans when it has none) and its caption colours. Without it, DejaVu Sans and
|
|
527
621
|
* `FOOTAGE_DRAFT_CAPTION_COLORS`.
|
|
528
622
|
*/
|
|
529
|
-
brand?: { colors: FootageDraftCaptionColors & Partial<OverlayColors>; fonts: Pick<FootageBrand["fonts"], "body"> & Partial<Pick<FootageBrand["fonts"], "heading" | "interface">>; locale?: string };
|
|
623
|
+
brand?: { colors: FootageDraftCaptionColors & Partial<OverlayColors>; fonts: Pick<FootageBrand["fonts"], "body"> & Partial<Pick<FootageBrand["fonts"], "heading" | "interface">>; locale?: string; style?: BrandStyle };
|
|
530
624
|
/**
|
|
531
625
|
* ffmpeg's threads for the draft's decoders, filter graph and encoder (`buildFootageDraftArgs`); by default ffmpeg's
|
|
532
626
|
* own choice, which follows the host's cores. Set it from a CPU-limited container's quota.
|
|
@@ -630,7 +724,7 @@ async function runRenderFootageDraft(
|
|
|
630
724
|
const { rawSpeechFile, declickedFile, speechFile } = getSpeechChainFiles(draftDir, { isDeclick: declickLevel !== "off", isLoudness: loudness !== null });
|
|
631
725
|
const words = remapWords(edl, transcript.words, film.cut.fillers);
|
|
632
726
|
const frame = getFrame(film);
|
|
633
|
-
const resolved = resolveEdlOverlays({ film, edl, words, frame, caption: getFootageCaptionLayout(film, options.layout ?? {}) });
|
|
727
|
+
const resolved = resolveEdlOverlays({ film, edl, words, frame, caption: getFootageCaptionLayout(film, options.layout ?? {}), ...(options.brand?.style === undefined ? {} : { style: options.brand.style }) });
|
|
634
728
|
if (!resolved.ok) return err(`footage film ${film.id}: the EDL's overlays cannot be drawn: ${resolved.problems.join("; ")}`, { kind: "input" });
|
|
635
729
|
const overlays = resolved.overlays;
|
|
636
730
|
const brandColors = options.brand?.colors;
|
|
@@ -658,6 +752,7 @@ async function runRenderFootageDraft(
|
|
|
658
752
|
...(overlays.length === 0 ? {} : { overlays, overlayColors }),
|
|
659
753
|
...(Object.keys(roleFonts).length === 0 ? {} : { overlayFonts: Object.fromEntries(Object.entries(roleFonts).map(([role, chosen]) => [role, chosen.family])) }),
|
|
660
754
|
...(options.brand?.locale === undefined ? {} : { locale: options.brand.locale }),
|
|
755
|
+
...(options.brand?.style === undefined ? {} : { style: options.brand.style, measure: createDraftTextMeasure(readFileSync(font.file)) }),
|
|
661
756
|
});
|
|
662
757
|
if (captions !== null) {
|
|
663
758
|
writeFileSync(join(draftDir, "captions.ass"), captions);
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import type { BrandColors } from "../config/colors.js";
|
|
2
2
|
import { escapeHtml } from "../compose/html.js";
|
|
3
|
+
import { getCornerRadiusCss, getStyleBorderCss, getStyleShadowCss, type BrandStyle } from "./brand-style.js";
|
|
3
4
|
import type { OverlayEntrance } from "./overlay-schema.js";
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
OVERLAY_LINE_HEIGHT,
|
|
7
|
+
OVERLAY_LIST_LINE_HEIGHT,
|
|
8
|
+
OVERLAY_PADDING_EM,
|
|
9
|
+
OVERLAY_TITLE_LINE_HEIGHT,
|
|
10
|
+
SEARCH_BAR_PADDING_EM,
|
|
11
|
+
formatOverlayNumber,
|
|
12
|
+
getOverlayPadding,
|
|
13
|
+
getTitleContentBox,
|
|
14
|
+
type ResolvedOverlay,
|
|
15
|
+
} from "./overlays.js";
|
|
5
16
|
|
|
6
17
|
/**
|
|
7
18
|
* The render's overlays (issue #1200): HTML, CSS and GSAP tweens for the HyperFrames composition, every look in the
|
|
@@ -54,7 +65,7 @@ export function getTypingTimes(start: number, text: string, speed: number): numb
|
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
/** The CSS every overlay kind shares, written once when the film has any drawn overlay. */
|
|
57
|
-
function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interface: string }): string[] {
|
|
68
|
+
function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interface: string }, style?: BrandStyle, scale = 1): string[] {
|
|
58
69
|
return [
|
|
59
70
|
`.ov{position:absolute;display:flex;pointer-events:none}`,
|
|
60
71
|
`.ov.right{justify-content:flex-end}`,
|
|
@@ -67,7 +78,13 @@ function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interfac
|
|
|
67
78
|
`.ov-list li{display:flex;align-items:center;gap:.45em;list-style:none}`,
|
|
68
79
|
`.ov-svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible}`,
|
|
69
80
|
`.ov-search,.ov-counter .ov-card,.ov-date .ov-card,.ov-place,.ov-sub,.ov-line{white-space:nowrap}`,
|
|
70
|
-
|
|
81
|
+
// A title card fills its fitted box, so a typed title keeps its width; a centred typed line hides its untyped
|
|
82
|
+
// characters (they take no room), so what is typed stays centred (RV-131 of an adopting app).
|
|
83
|
+
`.ov-stack{flex-direction:column;justify-content:center;gap:0;text-align:center;width:100%;height:100%;box-sizing:border-box;transform-origin:50% 0%}`,
|
|
84
|
+
`.ov-stack.left{align-items:flex-start;text-align:left}`,
|
|
85
|
+
`.ov-stack.left .ov-place{justify-content:flex-start}`,
|
|
86
|
+
`.ov-line{min-height:1lh}`,
|
|
87
|
+
`.ty .ov-stack:not(.left) .ch{display:none}`,
|
|
71
88
|
`.ov-hook-title .ov-line{font-family:${fonts.heading};font-weight:800;letter-spacing:-.02em}`,
|
|
72
89
|
`.ov-place{display:flex;align-items:center;justify-content:center;gap:.25em;font-weight:650;opacity:.92;margin-bottom:.12em}`,
|
|
73
90
|
`.ov-pin{flex:none;width:1.05em;height:1.05em}`,
|
|
@@ -81,6 +98,14 @@ function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interfac
|
|
|
81
98
|
`.ov-date:not(.right) .ov-card{align-items:flex-start}`,
|
|
82
99
|
`.ov-date .ov-sub{font-weight:600;margin-top:0}`,
|
|
83
100
|
`.ty .ch{opacity:0}`,
|
|
101
|
+
// The brand's style (after the kinds' own rules, so it wins over them; the search bar stays a pill).
|
|
102
|
+
...(style === undefined
|
|
103
|
+
? []
|
|
104
|
+
: [
|
|
105
|
+
`.ov-card{border-radius:${getCornerRadiusCss(style.cornerRadius, scale)};box-shadow:${getStyleShadowCss(style, scale)};border:${getStyleBorderCss(style, colors.accent, scale)}}`,
|
|
106
|
+
`.ov-search{border-radius:999px}`,
|
|
107
|
+
...(style.border === "none" ? [] : [`.ov-keyword .ov-card{border-bottom:.12em solid ${colors.accent}}`]),
|
|
108
|
+
]),
|
|
84
109
|
];
|
|
85
110
|
}
|
|
86
111
|
|
|
@@ -119,10 +144,19 @@ function toTypedHtml(text: string): string {
|
|
|
119
144
|
}
|
|
120
145
|
|
|
121
146
|
/** The inline colours of a card that has its own. */
|
|
122
|
-
function getCardStyle(overlay: ResolvedOverlay, colors: OverlayColors): string {
|
|
147
|
+
function getCardStyle(overlay: ResolvedOverlay, colors: OverlayColors, scale = 1): string {
|
|
123
148
|
if (overlay.kind === "punch_in") return "";
|
|
124
149
|
const own = overlay.colors;
|
|
125
150
|
const parts = [own.card === undefined ? "" : `background:${colors.background}`, own.text === undefined ? "" : `color:${colors.foreground}`];
|
|
151
|
+
if (overlay.cornerRadius !== undefined && overlay.cornerRadius !== null) parts.push(`border-radius:${getCornerRadiusCss(overlay.cornerRadius, scale)}`);
|
|
152
|
+
if (overlay.kind === "hook_title" || overlay.kind === "place_card") {
|
|
153
|
+
// The text block sits where the draft draws it: the card's padding is what its fitted box leaves round it.
|
|
154
|
+
const content = getTitleContentBox(overlay);
|
|
155
|
+
parts.push(`padding:${r3(content.top - overlay.box.top)}px ${r3(content.left - overlay.box.left)}px`);
|
|
156
|
+
} else if (overlay.padScale !== undefined && overlay.kind !== "search_bar" && overlay.kind !== "arrow" && overlay.kind !== "highlight") {
|
|
157
|
+
const pad = getOverlayPadding(overlay);
|
|
158
|
+
parts.push(`padding:${pad.y}px ${pad.x}px`);
|
|
159
|
+
}
|
|
126
160
|
if (overlay.kind === "keyword" && own.accent !== undefined) parts.push(`border-bottom-color:${colors.accent}`);
|
|
127
161
|
const style = parts.filter((part) => part !== "").join(";");
|
|
128
162
|
return style === "" ? "" : ` style="${style}"`;
|
|
@@ -139,7 +173,7 @@ function getEntranceTweens(target: string, entrance: OverlayEntrance, start: num
|
|
|
139
173
|
/** The typing tweens: each character of `#<id>` shown at its time. */
|
|
140
174
|
function getTypingTweens(id: string, overlay: { start: number; typing: number | null }, length: number): string[] {
|
|
141
175
|
if (overlay.typing === null || length === 0) return [];
|
|
142
|
-
return [`tl.to("#${id} .ch", { opacity: 1, duration: 0.01, ease: "none", stagger: ${r3(1 / overlay.typing)} }, ${r3(overlay.start + OVERLAY_TYPING_DELAY)});`];
|
|
176
|
+
return [`tl.to("#${id} .ch", { opacity: 1, display: "inline", duration: 0.01, ease: "none", stagger: ${r3(1 / overlay.typing)} }, ${r3(overlay.start + OVERLAY_TYPING_DELAY)});`];
|
|
143
177
|
}
|
|
144
178
|
|
|
145
179
|
/** Each new kind's own entrance when the overlay names none. */
|
|
@@ -156,7 +190,7 @@ interface MarkupContext {
|
|
|
156
190
|
function addSideText(overlay: Extract<ResolvedOverlay, { kind: "keyword" | "lower_third" | "list" }>, id: string, context: MarkupContext, out: OverlayMarkup): void {
|
|
157
191
|
const { box, fontSize, side } = overlay;
|
|
158
192
|
const colors = getOverlayColors(overlay, context.colors);
|
|
159
|
-
const cardStyle = getCardStyle(overlay, colors);
|
|
193
|
+
const cardStyle = getCardStyle(overlay, colors, context.scale);
|
|
160
194
|
const dotStyle = overlay.colors.accent === undefined ? "" : ` style="background:${colors.accent}"`;
|
|
161
195
|
const isTyped = overlay.typing !== null && overlay.kind !== "list";
|
|
162
196
|
const style = `left:${box.left}px;top:${box.top}px;width:${box.width}px;height:${box.height}px;font-size:${fontSize}px;align-items:${overlay.kind === "lower_third" ? "flex-end" : "flex-start"}`;
|
|
@@ -193,12 +227,12 @@ function getCardBody(overlay: CardOverlay, id: string, colors: OverlayColors, lo
|
|
|
193
227
|
if (overlay.kind === "hook_title") {
|
|
194
228
|
const place = overlay.place === null ? "" : `<div class="ov-place" style="font-size:${overlay.placeFontSize}px">${getPinSvg(colors.accent)}<span>${escapeHtml(overlay.place)}</span></div>`;
|
|
195
229
|
const lines = overlay.lines.map((line) => `<div class="ov-line">${typedOrPlain(line)}</div>`).join("");
|
|
196
|
-
return { classes: "ov-hook-title center", body: `<div class="ov-card ov-stack"__STYLE__>${place}${lines}</div>`, typed: overlay.lines.join("").length };
|
|
230
|
+
return { classes: "ov-hook-title center", body: `<div class="ov-card ov-stack${overlay.align === "left" ? " left" : ""}"__STYLE__>${place}${lines}</div>`, typed: overlay.lines.join("").length };
|
|
197
231
|
}
|
|
198
232
|
if (overlay.kind === "place_card") {
|
|
199
233
|
const subtitle = overlay.subtitle === null ? "" : `<div class="ov-sub" style="font-size:${overlay.subtitleFontSize}px">${escapeHtml(overlay.subtitle)}</div>`;
|
|
200
234
|
const lines = overlay.lines.map((line) => `<div class="ov-line">${typedOrPlain(line)}</div>`).join("");
|
|
201
|
-
return { classes: "ov-place-card center", body: `<div class="ov-card ov-stack"__STYLE__>${lines}${subtitle}</div>`, typed: overlay.lines.join("").length };
|
|
235
|
+
return { classes: "ov-place-card center", body: `<div class="ov-card ov-stack${overlay.align === "left" ? " left" : ""}"__STYLE__>${lines}${subtitle}</div>`, typed: overlay.lines.join("").length };
|
|
202
236
|
}
|
|
203
237
|
if (overlay.kind === "search_bar") {
|
|
204
238
|
return { classes: "ov-search-bar center", body: `<div class="ov-card ov-search"__STYLE__>${getGlassSvg(colors.accent)}<span id="${id}t">${typedOrPlain(overlay.text)}</span></div>`, typed: [...overlay.text].length };
|
|
@@ -217,7 +251,7 @@ function addCard(overlay: CardOverlay, id: string, context: MarkupContext, out:
|
|
|
217
251
|
const { box, fontSize } = overlay;
|
|
218
252
|
const { classes, body, typed } = getCardBody(overlay, id, colors, context.locale);
|
|
219
253
|
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`;
|
|
220
|
-
out.html.push(clipDiv(overlay, id, `ov ${classes}${overlay.typing === null ? "" : " ty"}`, style, body.replace("__STYLE__", getCardStyle(overlay, colors))));
|
|
254
|
+
out.html.push(clipDiv(overlay, id, `ov ${classes}${overlay.typing === null ? "" : " ty"}`, style, body.replace("__STYLE__", getCardStyle(overlay, colors, context.scale))));
|
|
221
255
|
const entrance = overlay.entrance ?? (overlay.typing !== null ? "type" : DEFAULT_ENTRANCES[overlay.kind]);
|
|
222
256
|
out.tweens.push(...getEntranceTweens(`#${id} .ov-card`, entrance, overlay.start));
|
|
223
257
|
out.tweens.push(...getTypingTweens(id, overlay, typed));
|
|
@@ -291,12 +325,12 @@ function addMark(overlay: Extract<ResolvedOverlay, { kind: "arrow" | "highlight"
|
|
|
291
325
|
*/
|
|
292
326
|
export function getOverlayMarkup(
|
|
293
327
|
overlays: readonly ResolvedOverlay[],
|
|
294
|
-
input: { colors: OverlayColors; headingFont: string; interfaceFont?: string; locale?: string; frame: { width: number; height: number } },
|
|
328
|
+
input: { colors: OverlayColors; headingFont: string; interfaceFont?: string; locale?: string; frame: { width: number; height: number }; style?: BrandStyle },
|
|
295
329
|
): OverlayMarkup {
|
|
296
330
|
const drawn = overlays.filter((overlay): overlay is Exclude<ResolvedOverlay, { kind: "punch_in" }> => overlay.kind !== "punch_in");
|
|
297
331
|
if (drawn.length === 0) return { html: [], css: [], tweens: [] };
|
|
298
332
|
const context: MarkupContext = { colors: input.colors, scale: input.frame.width / 1080, locale: input.locale ?? "en-US", frame: input.frame };
|
|
299
|
-
const out: OverlayMarkup = { html: [], css: getOverlayCss(input.colors, { heading: input.headingFont, interface: input.interfaceFont ?? "inherit" }), tweens: [] };
|
|
333
|
+
const out: OverlayMarkup = { html: [], css: getOverlayCss(input.colors, { heading: input.headingFont, interface: input.interfaceFont ?? "inherit" }, input.style, context.scale), tweens: [] };
|
|
300
334
|
for (const overlay of drawn) {
|
|
301
335
|
const id = `ov${overlay.index}`;
|
|
302
336
|
if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") addSideText(overlay, id, context, out);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
|
+
import { CORNER_RADII, type CornerRadius } from "./brand-style.js";
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* An EDL's overlays (issue #1200): small graphics and an emphasis zoom placed on a word of the transcript or at a film
|
|
5
7
|
* second, drawn by the render and the draft alike from a fixed catalogue. Their shape lives here so the EDL schema can
|
|
@@ -34,6 +36,14 @@ export const OVERLAY_POSITIONS = ["top", "middle", "bottom"] as const;
|
|
|
34
36
|
|
|
35
37
|
export type OverlayPosition = (typeof OVERLAY_POSITIONS)[number];
|
|
36
38
|
|
|
39
|
+
/** How a hook title's or a place card's lines sit in their card: centred (the default) or from its left padding. */
|
|
40
|
+
export const OVERLAY_ALIGNS = ["center", "left"] as const;
|
|
41
|
+
|
|
42
|
+
export type OverlayAlign = (typeof OVERLAY_ALIGNS)[number];
|
|
43
|
+
|
|
44
|
+
/** The kinds whose lines take an `align`: the two stacked title cards. */
|
|
45
|
+
export const OVERLAY_ALIGNED_KINDS: readonly OverlayKind[] = ["hook_title", "place_card"];
|
|
46
|
+
|
|
37
47
|
/**
|
|
38
48
|
* How an overlay enters: `fade` in place, `slide` up into place, `type` letter by letter (text kinds), `none` (it is
|
|
39
49
|
* simply there). Without one, the kind's own entrance. Never a bounce or a pop: the reel stays natural.
|
|
@@ -105,6 +115,12 @@ export interface EdlOverlayStyle {
|
|
|
105
115
|
/** Characters per second of the `type` entrance and the search bar's query. */
|
|
106
116
|
typing_speed?: number;
|
|
107
117
|
colors?: EdlOverlayColors;
|
|
118
|
+
/** Its card's corner in place of the brand style's (`BrandStyle.cornerRadius`); not on a punch_in, arrow or highlight. */
|
|
119
|
+
corner_radius?: CornerRadius;
|
|
120
|
+
/** How a hook title's or a place card's lines sit in the card (`center` without it). */
|
|
121
|
+
align?: OverlayAlign;
|
|
122
|
+
/** A place card's subtitle size: `s`, `m` (about 55 % of the title, the default) or `l`. */
|
|
123
|
+
subtitle_size?: OverlaySize;
|
|
108
124
|
}
|
|
109
125
|
|
|
110
126
|
export interface EdlOverlay {
|
|
@@ -255,6 +271,9 @@ function checkOverlayStyle(overlay: EdlOverlay, issue: (path: string[], message:
|
|
|
255
271
|
issue(["style", "entrance"], entrances.length === 0 ? `${article(kind)} has no entrance; leave it out` : `${article(kind)} enters by ${entrances.join(", ")}`);
|
|
256
272
|
}
|
|
257
273
|
if (style.typing_speed !== undefined && !isTypedOverlay(overlay)) issue(["style", "typing_speed"], "only a typed entrance or a search bar has a typing speed");
|
|
274
|
+
if (style.corner_radius !== undefined && (kind === "punch_in" || kind === "arrow" || kind === "highlight")) issue(["style", "corner_radius"], `${article(kind)} draws no card; leave corner_radius out`);
|
|
275
|
+
if (style.align !== undefined && !OVERLAY_ALIGNED_KINDS.includes(kind)) issue(["style", "align"], "only a hook_title or a place_card aligns its lines; leave align out");
|
|
276
|
+
if (style.subtitle_size !== undefined && kind !== "place_card") issue(["style", "subtitle_size"], "only a place_card has a subtitle; leave subtitle_size out");
|
|
258
277
|
if (style.colors === undefined) return;
|
|
259
278
|
if (kind === "punch_in") issue(["style", "colors"], "a punch_in draws nothing to colour; leave colors out");
|
|
260
279
|
if ((kind === "arrow" || kind === "highlight") && (style.colors.card !== undefined || style.colors.text !== undefined)) {
|
|
@@ -340,6 +359,12 @@ export const overlaySchema = z
|
|
|
340
359
|
})
|
|
341
360
|
.optional()
|
|
342
361
|
.describe("The overlay's own colours in place of the brand's."),
|
|
362
|
+
corner_radius: z
|
|
363
|
+
.enum(CORNER_RADII)
|
|
364
|
+
.optional()
|
|
365
|
+
.describe("The card's corner: none, s, m, l or pill; the brand style's without it (no punch_in, arrow or highlight)."),
|
|
366
|
+
align: z.enum(OVERLAY_ALIGNS).optional().describe("center (the default) or left: how a hook_title's or a place_card's lines sit in their card."),
|
|
367
|
+
subtitle_size: z.enum(OVERLAY_SIZES).optional().describe("s, m (the default, about 55 % of the title) or l: a place_card's subtitle size."),
|
|
343
368
|
})
|
|
344
369
|
.optional()
|
|
345
370
|
.describe("The overlay's look: size, side, position, entrance, typing speed and colours; fonts are the brand's."),
|