@softure-ai/marketing-kit 0.26.0 → 0.27.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 +12 -0
- package/README.md +5 -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 +39 -9
- 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 +63 -15
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/edl.d.ts +7 -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 +16 -5
- package/dist/footage/overlay-html.js.map +1 -1
- package/dist/footage/overlay-schema.d.ts +10 -0
- package/dist/footage/overlay-schema.d.ts.map +1 -1
- package/dist/footage/overlay-schema.js +7 -0
- package/dist/footage/overlay-schema.js.map +1 -1
- package/dist/footage/overlays.d.ts +3 -0
- package/dist/footage/overlays.d.ts.map +1 -1
- package/dist/footage/overlays.js +1 -0
- 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 +1 -0
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- 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 +11 -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 +43 -10
- package/src/footage/draft-text-width.ts +67 -0
- package/src/footage/draft.ts +111 -16
- package/src/footage/overlay-html.ts +16 -6
- package/src/footage/overlay-schema.ts +9 -0
- package/src/footage/overlays.ts +4 -0
- package/src/footage/pipeline.ts +7 -0
- package/src/index.ts +22 -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/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.
|
|
@@ -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,5 +1,6 @@
|
|
|
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
5
|
import { OVERLAY_LINE_HEIGHT, OVERLAY_LIST_LINE_HEIGHT, OVERLAY_PADDING_EM, OVERLAY_TITLE_LINE_HEIGHT, SEARCH_BAR_PADDING_EM, formatOverlayNumber, type ResolvedOverlay } from "./overlays.js";
|
|
5
6
|
|
|
@@ -54,7 +55,7 @@ export function getTypingTimes(start: number, text: string, speed: number): numb
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/** 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[] {
|
|
58
|
+
function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interface: string }, style?: BrandStyle, scale = 1): string[] {
|
|
58
59
|
return [
|
|
59
60
|
`.ov{position:absolute;display:flex;pointer-events:none}`,
|
|
60
61
|
`.ov.right{justify-content:flex-end}`,
|
|
@@ -81,6 +82,14 @@ function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interfac
|
|
|
81
82
|
`.ov-date:not(.right) .ov-card{align-items:flex-start}`,
|
|
82
83
|
`.ov-date .ov-sub{font-weight:600;margin-top:0}`,
|
|
83
84
|
`.ty .ch{opacity:0}`,
|
|
85
|
+
// The brand's style (after the kinds' own rules, so it wins over them; the search bar stays a pill).
|
|
86
|
+
...(style === undefined
|
|
87
|
+
? []
|
|
88
|
+
: [
|
|
89
|
+
`.ov-card{border-radius:${getCornerRadiusCss(style.cornerRadius, scale)};box-shadow:${getStyleShadowCss(style, scale)};border:${getStyleBorderCss(style, colors.accent, scale)}}`,
|
|
90
|
+
`.ov-search{border-radius:999px}`,
|
|
91
|
+
...(style.border === "none" ? [] : [`.ov-keyword .ov-card{border-bottom:.12em solid ${colors.accent}}`]),
|
|
92
|
+
]),
|
|
84
93
|
];
|
|
85
94
|
}
|
|
86
95
|
|
|
@@ -119,10 +128,11 @@ function toTypedHtml(text: string): string {
|
|
|
119
128
|
}
|
|
120
129
|
|
|
121
130
|
/** The inline colours of a card that has its own. */
|
|
122
|
-
function getCardStyle(overlay: ResolvedOverlay, colors: OverlayColors): string {
|
|
131
|
+
function getCardStyle(overlay: ResolvedOverlay, colors: OverlayColors, scale = 1): string {
|
|
123
132
|
if (overlay.kind === "punch_in") return "";
|
|
124
133
|
const own = overlay.colors;
|
|
125
134
|
const parts = [own.card === undefined ? "" : `background:${colors.background}`, own.text === undefined ? "" : `color:${colors.foreground}`];
|
|
135
|
+
if (overlay.cornerRadius !== undefined && overlay.cornerRadius !== null) parts.push(`border-radius:${getCornerRadiusCss(overlay.cornerRadius, scale)}`);
|
|
126
136
|
if (overlay.kind === "keyword" && own.accent !== undefined) parts.push(`border-bottom-color:${colors.accent}`);
|
|
127
137
|
const style = parts.filter((part) => part !== "").join(";");
|
|
128
138
|
return style === "" ? "" : ` style="${style}"`;
|
|
@@ -156,7 +166,7 @@ interface MarkupContext {
|
|
|
156
166
|
function addSideText(overlay: Extract<ResolvedOverlay, { kind: "keyword" | "lower_third" | "list" }>, id: string, context: MarkupContext, out: OverlayMarkup): void {
|
|
157
167
|
const { box, fontSize, side } = overlay;
|
|
158
168
|
const colors = getOverlayColors(overlay, context.colors);
|
|
159
|
-
const cardStyle = getCardStyle(overlay, colors);
|
|
169
|
+
const cardStyle = getCardStyle(overlay, colors, context.scale);
|
|
160
170
|
const dotStyle = overlay.colors.accent === undefined ? "" : ` style="background:${colors.accent}"`;
|
|
161
171
|
const isTyped = overlay.typing !== null && overlay.kind !== "list";
|
|
162
172
|
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"}`;
|
|
@@ -217,7 +227,7 @@ function addCard(overlay: CardOverlay, id: string, context: MarkupContext, out:
|
|
|
217
227
|
const { box, fontSize } = overlay;
|
|
218
228
|
const { classes, body, typed } = getCardBody(overlay, id, colors, context.locale);
|
|
219
229
|
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))));
|
|
230
|
+
out.html.push(clipDiv(overlay, id, `ov ${classes}${overlay.typing === null ? "" : " ty"}`, style, body.replace("__STYLE__", getCardStyle(overlay, colors, context.scale))));
|
|
221
231
|
const entrance = overlay.entrance ?? (overlay.typing !== null ? "type" : DEFAULT_ENTRANCES[overlay.kind]);
|
|
222
232
|
out.tweens.push(...getEntranceTweens(`#${id} .ov-card`, entrance, overlay.start));
|
|
223
233
|
out.tweens.push(...getTypingTweens(id, overlay, typed));
|
|
@@ -291,12 +301,12 @@ function addMark(overlay: Extract<ResolvedOverlay, { kind: "arrow" | "highlight"
|
|
|
291
301
|
*/
|
|
292
302
|
export function getOverlayMarkup(
|
|
293
303
|
overlays: readonly ResolvedOverlay[],
|
|
294
|
-
input: { colors: OverlayColors; headingFont: string; interfaceFont?: string; locale?: string; frame: { width: number; height: number } },
|
|
304
|
+
input: { colors: OverlayColors; headingFont: string; interfaceFont?: string; locale?: string; frame: { width: number; height: number }; style?: BrandStyle },
|
|
295
305
|
): OverlayMarkup {
|
|
296
306
|
const drawn = overlays.filter((overlay): overlay is Exclude<ResolvedOverlay, { kind: "punch_in" }> => overlay.kind !== "punch_in");
|
|
297
307
|
if (drawn.length === 0) return { html: [], css: [], tweens: [] };
|
|
298
308
|
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: [] };
|
|
309
|
+
const out: OverlayMarkup = { html: [], css: getOverlayCss(input.colors, { heading: input.headingFont, interface: input.interfaceFont ?? "inherit" }, input.style, context.scale), tweens: [] };
|
|
300
310
|
for (const overlay of drawn) {
|
|
301
311
|
const id = `ov${overlay.index}`;
|
|
302
312
|
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
|
|
@@ -105,6 +107,8 @@ export interface EdlOverlayStyle {
|
|
|
105
107
|
/** Characters per second of the `type` entrance and the search bar's query. */
|
|
106
108
|
typing_speed?: number;
|
|
107
109
|
colors?: EdlOverlayColors;
|
|
110
|
+
/** Its card's corner in place of the brand style's (`BrandStyle.cornerRadius`); not on a punch_in, arrow or highlight. */
|
|
111
|
+
corner_radius?: CornerRadius;
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
export interface EdlOverlay {
|
|
@@ -255,6 +259,7 @@ function checkOverlayStyle(overlay: EdlOverlay, issue: (path: string[], message:
|
|
|
255
259
|
issue(["style", "entrance"], entrances.length === 0 ? `${article(kind)} has no entrance; leave it out` : `${article(kind)} enters by ${entrances.join(", ")}`);
|
|
256
260
|
}
|
|
257
261
|
if (style.typing_speed !== undefined && !isTypedOverlay(overlay)) issue(["style", "typing_speed"], "only a typed entrance or a search bar has a typing speed");
|
|
262
|
+
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`);
|
|
258
263
|
if (style.colors === undefined) return;
|
|
259
264
|
if (kind === "punch_in") issue(["style", "colors"], "a punch_in draws nothing to colour; leave colors out");
|
|
260
265
|
if ((kind === "arrow" || kind === "highlight") && (style.colors.card !== undefined || style.colors.text !== undefined)) {
|
|
@@ -340,6 +345,10 @@ export const overlaySchema = z
|
|
|
340
345
|
})
|
|
341
346
|
.optional()
|
|
342
347
|
.describe("The overlay's own colours in place of the brand's."),
|
|
348
|
+
corner_radius: z
|
|
349
|
+
.enum(CORNER_RADII)
|
|
350
|
+
.optional()
|
|
351
|
+
.describe("The card's corner: none, s, m, l or pill; the brand style's without it (no punch_in, arrow or highlight)."),
|
|
343
352
|
})
|
|
344
353
|
.optional()
|
|
345
354
|
.describe("The overlay's look: size, side, position, entrance, typing speed and colours; fonts are the brand's."),
|
package/src/footage/overlays.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "./overlay-schema.js";
|
|
18
18
|
import { getSegmentZoomEases } from "./compose.js";
|
|
19
19
|
import { normalizeWord } from "./words.js";
|
|
20
|
+
import type { CornerRadius } from "./brand-style.js";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* An EDL's overlays resolved for the render and the draft (issue #1200): each one's film time (from its word through
|
|
@@ -114,6 +115,8 @@ export interface OverlayLook {
|
|
|
114
115
|
typing: number | null;
|
|
115
116
|
/** Its own colours in place of the brand's (empty: the brand's). */
|
|
116
117
|
colors: EdlOverlayColors;
|
|
118
|
+
/** Its card's own corner (`style.corner_radius`), else null: the brand style's, or the kind's own without one. */
|
|
119
|
+
cornerRadius?: CornerRadius | null;
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
type Drawn = OverlayBase & OverlayLook;
|
|
@@ -423,6 +426,7 @@ function getLook(overlay: EdlOverlay): OverlayLook {
|
|
|
423
426
|
entrance: overlay.style?.entrance ?? null,
|
|
424
427
|
typing: isTypedOverlay(overlay) ? (overlay.style?.typing_speed ?? DEFAULT_OVERLAY_TYPING_SPEED) : null,
|
|
425
428
|
colors: { ...overlay.style?.colors },
|
|
429
|
+
cornerRadius: overlay.style?.corner_radius ?? null,
|
|
426
430
|
};
|
|
427
431
|
}
|
|
428
432
|
|
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 {
|
|
@@ -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
|
@@ -108,6 +108,28 @@ export {
|
|
|
108
108
|
type OverlaySide,
|
|
109
109
|
type OverlaySize,
|
|
110
110
|
} from "./footage/overlay-schema.js";
|
|
111
|
+
export {
|
|
112
|
+
CORNER_RADII,
|
|
113
|
+
CORNER_RADIUS_PX,
|
|
114
|
+
STYLE_BORDER_PX,
|
|
115
|
+
STYLE_BORDERS,
|
|
116
|
+
STYLE_PADDING_SCALES,
|
|
117
|
+
STYLE_PADDINGS,
|
|
118
|
+
STYLE_SHADOW,
|
|
119
|
+
STYLE_SHADOWS,
|
|
120
|
+
getCaptionCornerRadius,
|
|
121
|
+
getCornerRadiusCss,
|
|
122
|
+
getCornerRadiusPx,
|
|
123
|
+
getStyleBorderCss,
|
|
124
|
+
getStylePadding,
|
|
125
|
+
getStyleShadowCss,
|
|
126
|
+
type BrandStyle,
|
|
127
|
+
type CornerRadius,
|
|
128
|
+
type StyleBorder,
|
|
129
|
+
type StylePadding,
|
|
130
|
+
type StyleShadow,
|
|
131
|
+
} from "./footage/brand-style.js";
|
|
132
|
+
export { createDraftTextMeasure, wrapDraftLine, type DraftTextMeasure } from "./footage/draft-text-width.js";
|
|
111
133
|
export {
|
|
112
134
|
OVERLAY_FONT_ROLES,
|
|
113
135
|
OVERLAY_FONT_SIZES,
|
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);
|