@softure-ai/marketing-kit 0.22.0 → 0.24.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 +27 -0
- package/README.md +21 -1
- package/dist/cli/failure.d.ts.map +1 -1
- package/dist/cli/failure.js.map +1 -1
- package/dist/cli/films.js.map +1 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/options.d.ts.map +1 -1
- package/dist/compose/timeline.d.ts +22 -1
- package/dist/compose/timeline.d.ts.map +1 -1
- package/dist/compose/timeline.js +52 -14
- package/dist/compose/timeline.js.map +1 -1
- package/dist/config/actions-schema.d.ts +85 -85
- package/dist/config/actions-schema.d.ts.map +1 -1
- package/dist/config/colors.d.ts +24 -2
- package/dist/config/colors.d.ts.map +1 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +3 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/placeholders.d.ts.map +1 -1
- package/dist/config/placeholders.js.map +1 -1
- package/dist/config/schema.d.ts +469 -466
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +15 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/config/shot-steps.d.ts +96 -96
- package/dist/film.d.ts.map +1 -1
- package/dist/footage/audio.js.map +1 -1
- package/dist/footage/captions.d.ts +22 -6
- package/dist/footage/captions.d.ts.map +1 -1
- package/dist/footage/captions.js +24 -14
- package/dist/footage/captions.js.map +1 -1
- package/dist/footage/clip-sound.d.ts.map +1 -1
- package/dist/footage/clip-sound.js.map +1 -1
- package/dist/footage/compose.d.ts +2 -0
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +3 -2
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/cuts.d.ts.map +1 -1
- package/dist/footage/cuts.js.map +1 -1
- package/dist/footage/declick.d.ts.map +1 -1
- package/dist/footage/disk.js.map +1 -1
- package/dist/footage/draft-font.js.map +1 -1
- package/dist/footage/draft-overlays.d.ts +24 -4
- package/dist/footage/draft-overlays.d.ts.map +1 -1
- package/dist/footage/draft-overlays.js +232 -34
- package/dist/footage/draft-overlays.js.map +1 -1
- package/dist/footage/draft.d.ts +7 -2
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +13 -2
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/edl.d.ts +46 -19
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +1 -1
- package/dist/footage/edl.js.map +1 -1
- package/dist/footage/elevenlabs.d.ts.map +1 -1
- package/dist/footage/failure.js.map +1 -1
- package/dist/footage/fake.js.map +1 -1
- package/dist/footage/ffmpeg-failure.d.ts.map +1 -1
- package/dist/footage/ffmpeg-failure.js.map +1 -1
- package/dist/footage/film.d.ts +9 -0
- package/dist/footage/film.d.ts.map +1 -1
- package/dist/footage/film.js.map +1 -1
- package/dist/footage/hyperframes-capture.d.ts.map +1 -1
- package/dist/footage/keyterms.d.ts.map +1 -1
- package/dist/footage/loudness.d.ts.map +1 -1
- package/dist/footage/loudness.js.map +1 -1
- package/dist/footage/mouth-clicks.d.ts.map +1 -1
- package/dist/footage/normalize.d.ts.map +1 -1
- package/dist/footage/normalize.js.map +1 -1
- package/dist/footage/overlay-html.d.ts +21 -1
- package/dist/footage/overlay-html.d.ts.map +1 -1
- package/dist/footage/overlay-html.js +217 -56
- package/dist/footage/overlay-html.js.map +1 -1
- package/dist/footage/overlay-schema.d.ts +104 -12
- package/dist/footage/overlay-schema.d.ts.map +1 -1
- package/dist/footage/overlay-schema.js +215 -45
- package/dist/footage/overlay-schema.js.map +1 -1
- package/dist/footage/overlays.d.ts +109 -16
- package/dist/footage/overlays.d.ts.map +1 -1
- package/dist/footage/overlays.js +303 -52
- package/dist/footage/overlays.js.map +1 -1
- package/dist/footage/paid.d.ts.map +1 -1
- package/dist/footage/pipeline.d.ts +5 -0
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +3 -2
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/footage/probe.js.map +1 -1
- package/dist/footage/process.js.map +1 -1
- package/dist/footage/publish.js.map +1 -1
- package/dist/footage/render.js.map +1 -1
- package/dist/footage/sound-analysis.d.ts.map +1 -1
- package/dist/footage/speech-ranges.js.map +1 -1
- package/dist/footage/tonemap-lut.d.ts.map +1 -1
- package/dist/footage/tonemap-lut.js.map +1 -1
- package/dist/footage/tools.d.ts.map +1 -1
- package/dist/footage/tools.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/messages/en.d.ts.map +1 -1
- package/dist/messages/index.js.map +1 -1
- package/dist/og/font-file.d.ts.map +1 -1
- package/dist/og/fonts.d.ts.map +1 -1
- package/dist/og/fonts.js.map +1 -1
- package/dist/og/photo-cover.d.ts.map +1 -1
- package/dist/og/result.d.ts.map +1 -1
- package/dist/og/templates/schemas.d.ts.map +1 -1
- package/dist/platforms.d.ts.map +1 -1
- package/dist/render/hyperframes.js.map +1 -1
- package/dist/render/render.d.ts +4 -1
- package/dist/render/render.d.ts.map +1 -1
- package/dist/render/render.js +2 -1
- package/dist/render/render.js.map +1 -1
- package/dist/screenshot/gates.d.ts.map +1 -1
- package/dist/voice/fake.js.map +1 -1
- package/dist/voice/provider.d.ts.map +1 -1
- package/package.json +2 -2
- package/schema/edl.schema.json +90 -8
- package/schema/marketing.schema.json +18 -0
- package/src/compose/timeline.ts +62 -13
- package/src/config/config.ts +3 -0
- package/src/config/schema.ts +15 -0
- package/src/footage/captions.ts +39 -16
- package/src/footage/compose.ts +5 -3
- package/src/footage/draft-overlays.ts +276 -35
- package/src/footage/draft.ts +20 -4
- package/src/footage/edl.ts +1 -1
- package/src/footage/film.ts +9 -0
- package/src/footage/overlay-html.ts +239 -59
- package/src/footage/overlay-schema.ts +245 -40
- package/src/footage/overlays.ts +364 -55
- package/src/footage/pipeline.ts +8 -3
- package/src/index.ts +28 -0
- package/src/render/render.ts +3 -2
package/src/compose/timeline.ts
CHANGED
|
@@ -328,6 +328,56 @@ export interface CaptionChunkOptions {
|
|
|
328
328
|
* its chunk. Absent: every word may end one.
|
|
329
329
|
*/
|
|
330
330
|
keepsWithNext?: (word: TimedWord) => boolean;
|
|
331
|
+
/** The fewest words a chunk shows (`balanceCaptionGroups`); default 1: chunks stay as they are cut. */
|
|
332
|
+
minWords?: number;
|
|
333
|
+
/** The most characters a short chunk's join may make, words joined by spaces (`balanceCaptionGroups`); absent: no limit. */
|
|
334
|
+
maxCharacters?: number;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** How short caption chunks are evened out (`balanceCaptionGroups`). */
|
|
338
|
+
export interface CaptionBalanceOptions {
|
|
339
|
+
/** The fewest words a chunk shows; 1 leaves the chunks as they are. */
|
|
340
|
+
minWords: number;
|
|
341
|
+
/** The words a chunk aims at; a short chunk's join may pass it by one word (a sentence's last word stays with it). */
|
|
342
|
+
maxWords: number;
|
|
343
|
+
/** The most characters a join may make, words joined by spaces (what fits the caption's width); absent: no limit. */
|
|
344
|
+
maxCharacters?: number;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function getGroupText(words: readonly TimedWord[]): string {
|
|
348
|
+
return words.map((word) => word.text).join(" ");
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Caption groups without one shorter than `minWords` where it can be helped (issue: one-word boards): a short group
|
|
353
|
+
* joins the group before it when the join fits (`maxWords` + 1 words, `maxCharacters`); otherwise words move over from
|
|
354
|
+
* the end of the group before it, as long as that one keeps `minWords`. A short first group does the same with the
|
|
355
|
+
* group after it. A text shorter than `minWords` stays as it is. The groups are new arrays; no word changes.
|
|
356
|
+
*/
|
|
357
|
+
export function balanceCaptionGroups(groups: readonly (readonly TimedWord[])[], options: CaptionBalanceOptions): TimedWord[][] {
|
|
358
|
+
const { minWords, maxWords, maxCharacters } = options;
|
|
359
|
+
const result = groups.map((group) => [...group]);
|
|
360
|
+
if (minWords <= 1) return result;
|
|
361
|
+
const fits = (words: readonly TimedWord[]): boolean => words.length <= maxWords + 1 && (maxCharacters === undefined || getGroupText(words).length <= maxCharacters);
|
|
362
|
+
const balanced: TimedWord[][] = [];
|
|
363
|
+
for (const group of result) {
|
|
364
|
+
const previous = balanced.at(-1);
|
|
365
|
+
if (group.length < minWords && previous !== undefined) {
|
|
366
|
+
if (fits([...previous, ...group])) {
|
|
367
|
+
previous.push(...group);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
// `previous` has more than `minWords` words while the loop runs, so `pop` returns a word.
|
|
371
|
+
while (group.length < minWords && previous.length > minWords) group.unshift(previous.pop() as TimedWord);
|
|
372
|
+
}
|
|
373
|
+
balanced.push(group);
|
|
374
|
+
}
|
|
375
|
+
const [first, second] = balanced;
|
|
376
|
+
if (first === undefined || second === undefined || first.length >= minWords) return balanced;
|
|
377
|
+
if (fits([...first, ...second])) return [[...first, ...second], ...balanced.slice(2)];
|
|
378
|
+
// `second` has more than `minWords` words while the loop runs, so `shift` returns a word.
|
|
379
|
+
while (first.length < minWords && second.length > minWords) first.push(second.shift() as TimedWord);
|
|
380
|
+
return balanced;
|
|
331
381
|
}
|
|
332
382
|
|
|
333
383
|
/**
|
|
@@ -344,31 +394,30 @@ export function splitAfterKept(words: TimedWord[], keepsWithNext: ((word: TimedW
|
|
|
344
394
|
/**
|
|
345
395
|
* Words → caption chunks: at most `maxWords` words, broken after the end of a sentence and after a comma, so a caption
|
|
346
396
|
* does not glue two thoughts together; never after a word `keepsWithNext` keeps, unless punctuation ends it or every
|
|
347
|
-
* word of the chunk is kept.
|
|
397
|
+
* word of the chunk is kept. With `minWords`, short chunks are evened out (`balanceCaptionGroups`). A number as
|
|
398
|
+
* `options` is `maxWords`.
|
|
348
399
|
*/
|
|
349
400
|
export function captionChunks(words: TimedWord[], options: number | CaptionChunkOptions = {}): CaptionChunk[] {
|
|
350
|
-
const { maxWords = 4, keepsWithNext } = typeof options === "number" ? { maxWords: options } : options;
|
|
351
|
-
const
|
|
401
|
+
const { maxWords = 4, keepsWithNext, minWords = 1, maxCharacters } = typeof options === "number" ? { maxWords: options } : options;
|
|
402
|
+
const groups: TimedWord[][] = [];
|
|
352
403
|
let current: TimedWord[] = [];
|
|
353
|
-
const push = (chunkWords: TimedWord[]) => {
|
|
354
|
-
const first = chunkWords[0];
|
|
355
|
-
const last = chunkWords[chunkWords.length - 1];
|
|
356
|
-
if (first === undefined || last === undefined) return;
|
|
357
|
-
chunks.push({ words: chunkWords, start: first.start, end: last.end });
|
|
358
|
-
};
|
|
359
404
|
for (const word of words) {
|
|
360
405
|
current.push(word);
|
|
361
406
|
if (/[.,?!:;]$/.test(word.text)) {
|
|
362
|
-
push(current);
|
|
407
|
+
groups.push(current);
|
|
363
408
|
current = [];
|
|
364
409
|
} else if (current.length >= maxWords) {
|
|
365
410
|
const { chunk, carry } = splitAfterKept(current, keepsWithNext);
|
|
366
|
-
push(chunk);
|
|
411
|
+
groups.push(chunk);
|
|
367
412
|
current = carry;
|
|
368
413
|
}
|
|
369
414
|
}
|
|
370
|
-
push(current);
|
|
371
|
-
return
|
|
415
|
+
if (current.length > 0) groups.push(current);
|
|
416
|
+
return balanceCaptionGroups(groups, { minWords, maxWords, maxCharacters }).map((group) => ({
|
|
417
|
+
words: group,
|
|
418
|
+
start: (group[0] as TimedWord).start,
|
|
419
|
+
end: (group[group.length - 1] as TimedWord).end,
|
|
420
|
+
}));
|
|
372
421
|
}
|
|
373
422
|
|
|
374
423
|
/**
|
package/src/config/config.ts
CHANGED
|
@@ -257,6 +257,9 @@ function resolveFootage(data: MarketingJson, at: (relative: string) => string):
|
|
|
257
257
|
...(film.overlayMinSpacing === undefined ? {} : { overlayMinSpacing: film.overlayMinSpacing }),
|
|
258
258
|
...(film.captionMaxLines === undefined ? {} : { captionMaxLines: film.captionMaxLines }),
|
|
259
259
|
...(film.captionKeepWithNext === undefined ? {} : { captionKeepWithNext: film.captionKeepWithNext }),
|
|
260
|
+
...(film.captionMaxWords === undefined ? {} : { captionMaxWords: film.captionMaxWords }),
|
|
261
|
+
...(film.captionMinWords === undefined ? {} : { captionMinWords: film.captionMinWords }),
|
|
262
|
+
...(film.captionMaxCharacters === undefined ? {} : { captionMaxCharacters: film.captionMaxCharacters }),
|
|
260
263
|
edit: {
|
|
261
264
|
zoomPercent: film.edit.zoomPercent,
|
|
262
265
|
zoomEaseFrames: film.edit.zoomEaseFrames,
|
package/src/config/schema.ts
CHANGED
|
@@ -609,6 +609,21 @@ const footageSchema = z
|
|
|
609
609
|
.max(100)
|
|
610
610
|
.optional()
|
|
611
611
|
.describe("Words a caption card must not end on (they move to the next card), compared lower-case; a number always keeps with the next word. Without it, the language's default (pl: one-letter words and short prepositions, en: articles); [] keeps numbers only."),
|
|
612
|
+
captionMaxWords: z.number().int().min(1).max(12).optional().describe("The words a caption card aims at (1-12, a brand's words per caption); without it, 4 for highlight and 6 for phrase captions."),
|
|
613
|
+
captionMinWords: z
|
|
614
|
+
.number()
|
|
615
|
+
.int()
|
|
616
|
+
.min(1)
|
|
617
|
+
.max(4)
|
|
618
|
+
.optional()
|
|
619
|
+
.describe("The fewest words a caption card shows (1-4; 2 means never a one-word card): a short card joins the one before it or takes words from it; without it, cards stay as cut."),
|
|
620
|
+
captionMaxCharacters: z
|
|
621
|
+
.number()
|
|
622
|
+
.int()
|
|
623
|
+
.min(8)
|
|
624
|
+
.max(200)
|
|
625
|
+
.optional()
|
|
626
|
+
.describe("The most characters a short card's join may make (8-200, what fits the caption's width); without it, no limit."),
|
|
612
627
|
edit: z
|
|
613
628
|
.strictObject({
|
|
614
629
|
zoomPercent: z.number().min(105).max(112).default(108).describe("How far a zoom cut punches in (105-112 %, default 108)."),
|
package/src/footage/captions.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
|
|
3
|
-
import { CAPTION_LINE_HEIGHT, CAPTION_PILL_PADDING, captionChunks, resolveLayout, splitAfterKept, type CaptionLayout, type LayoutOverride } from "../compose/timeline.js";
|
|
3
|
+
import { CAPTION_LINE_HEIGHT, CAPTION_PILL_PADDING, balanceCaptionGroups, captionChunks, resolveLayout, splitAfterKept, type CaptionLayout, type LayoutOverride } from "../compose/timeline.js";
|
|
4
4
|
import type { BrandFont } from "../config/config.js";
|
|
5
5
|
import { readCharacterMap, type CharacterMap } from "../og/character-map.js";
|
|
6
6
|
import type { TimedWord } from "../voice/voiceover.js";
|
|
@@ -31,15 +31,22 @@ export interface PhraseChunkOptions {
|
|
|
31
31
|
* phrase on one (a full phrase hands it to the next); punctuation still does. Absent: every word may end one.
|
|
32
32
|
*/
|
|
33
33
|
keepsWithNext?: (word: TimedWord) => boolean;
|
|
34
|
+
/** The most words a phrase holds; default 6. */
|
|
35
|
+
maxWords?: number;
|
|
36
|
+
/** The fewest words a phrase shows, across a pause too (`balanceCaptionGroups`); default 1: phrases stay as cut. */
|
|
37
|
+
minWords?: number;
|
|
38
|
+
/** The most characters a short phrase's join may make (`balanceCaptionGroups`); absent: no limit. */
|
|
39
|
+
maxCharacters?: number;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
/**
|
|
37
|
-
* The words as phrases of 2-6: a phrase ends at punctuation, after six words or at a pause, never on a
|
|
38
|
-
* `keepsWithNext` keeps (unless punctuation ends it or the phrase holds kept words only); a single word left
|
|
39
|
-
* joins the phrase before it when that one has room and no pause separates them.
|
|
43
|
+
* The words as phrases of 2-6: a phrase ends at punctuation, after six words (`maxWords`) or at a pause, never on a
|
|
44
|
+
* word `keepsWithNext` keeps (unless punctuation ends it or the phrase holds kept words only); a single word left
|
|
45
|
+
* alone joins the phrase before it when that one has room and no pause separates them. With `minWords`, short phrases
|
|
46
|
+
* are then evened out (`balanceCaptionGroups`).
|
|
40
47
|
*/
|
|
41
48
|
export function phraseChunks(words: TimedWord[], options: PhraseChunkOptions = {}): PhraseChunk[] {
|
|
42
|
-
const { keepsWithNext } = options;
|
|
49
|
+
const { keepsWithNext, maxWords = MAX_PHRASE_WORDS, minWords = 1, maxCharacters } = options;
|
|
43
50
|
const groups: TimedWord[][] = [];
|
|
44
51
|
let current: TimedWord[] = [];
|
|
45
52
|
words.forEach((word, index) => {
|
|
@@ -53,7 +60,7 @@ export function phraseChunks(words: TimedWord[], options: PhraseChunkOptions = {
|
|
|
53
60
|
if (/[.,?!:;…]$/u.test(word.text)) {
|
|
54
61
|
groups.push(current);
|
|
55
62
|
current = [];
|
|
56
|
-
} else if (current.length
|
|
63
|
+
} else if (current.length >= maxWords) {
|
|
57
64
|
const { chunk, carry } = splitAfterKept(current, keepsWithNext);
|
|
58
65
|
groups.push(chunk);
|
|
59
66
|
current = carry;
|
|
@@ -66,14 +73,14 @@ export function phraseChunks(words: TimedWord[], options: PhraseChunkOptions = {
|
|
|
66
73
|
const first = group[0] as TimedWord;
|
|
67
74
|
const last = previous?.at(-1);
|
|
68
75
|
const isClose = last !== undefined && first.start - last.end <= PHRASE_GAP_SECONDS;
|
|
69
|
-
if (previous !== undefined && group.length < MIN_PHRASE_WORDS && previous.length <
|
|
76
|
+
if (previous !== undefined && group.length < MIN_PHRASE_WORDS && previous.length < maxWords && isClose) previous.push(...group);
|
|
70
77
|
else merged.push(group);
|
|
71
78
|
}
|
|
72
|
-
return merged.map((group) => ({ words: group, start: (group[0] as TimedWord).start, end: (group[group.length - 1] as TimedWord).end }));
|
|
79
|
+
return balanceCaptionGroups(merged, { minWords, maxWords, maxCharacters }).map((group) => ({ words: group, start: (group[0] as TimedWord).start, end: (group[group.length - 1] as TimedWord).end }));
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
/** What a film's caption cards are cut by; without `language`, no language default applies. */
|
|
76
|
-
export type CaptionWordsFilm = Pick<FootageFilm, "captionKeepWithNext"> & { language?: string };
|
|
83
|
+
export type CaptionWordsFilm = Pick<FootageFilm, "captionKeepWithNext" | "captionMinWords" | "captionMaxWords" | "captionMaxCharacters"> & { language?: string };
|
|
77
84
|
|
|
78
85
|
const NUMBER_PATTERN = /^\d+(?:[.,]\d+)*$/u;
|
|
79
86
|
|
|
@@ -89,12 +96,19 @@ export function getCaptionKeepsWithNext(film: CaptionWordsFilm): (word: TimedWor
|
|
|
89
96
|
|
|
90
97
|
/**
|
|
91
98
|
* A footage film's caption cards in film time: none without captions, `captionChunks` for `highlight`, `phraseChunks`
|
|
92
|
-
* otherwise; both keep the film's kept words with the next (`getCaptionKeepsWithNext`)
|
|
99
|
+
* otherwise; both keep the film's kept words with the next (`getCaptionKeepsWithNext`) and take the film's
|
|
100
|
+
* `captionMaxWords`, `captionMinWords` and `captionMaxCharacters` (absent: each style's defaults, no evening out). The
|
|
101
|
+
* render and the draft share it.
|
|
93
102
|
*/
|
|
94
103
|
export function getFootageCaptionChunks(film: CaptionWordsFilm & Pick<FootageFilm, "captions" | "captionStyle">, words: TimedWord[]): PhraseChunk[] {
|
|
95
104
|
if (!film.captions) return [];
|
|
96
|
-
const
|
|
97
|
-
|
|
105
|
+
const options = {
|
|
106
|
+
keepsWithNext: getCaptionKeepsWithNext(film),
|
|
107
|
+
...(film.captionMaxWords === undefined ? {} : { maxWords: film.captionMaxWords }),
|
|
108
|
+
...(film.captionMinWords === undefined ? {} : { minWords: film.captionMinWords }),
|
|
109
|
+
...(film.captionMaxCharacters === undefined ? {} : { maxCharacters: film.captionMaxCharacters }),
|
|
110
|
+
};
|
|
111
|
+
return film.captionStyle === "highlight" ? captionChunks(words, options) : phraseChunks(words, options);
|
|
98
112
|
}
|
|
99
113
|
|
|
100
114
|
/** When a caption chunk is on screen, in film seconds. */
|
|
@@ -244,17 +258,26 @@ function findMissingInFamily(font: BrandFont | null, texts: string[], read: (pat
|
|
|
244
258
|
|
|
245
259
|
/**
|
|
246
260
|
* Glyphs the film's fonts lack: the body font against the captions and the end card's url and note, the heading font
|
|
247
|
-
* (the body font without one) against the brand name and the
|
|
261
|
+
* (the body font without one) against the brand name, the headline and the heading overlays' texts, and the interface
|
|
262
|
+
* font (the body font without one) against the interface overlays' texts. Empty when every letter is drawn.
|
|
248
263
|
*/
|
|
249
264
|
export function findMissingCaptionGlyphs(
|
|
250
|
-
input: {
|
|
265
|
+
input: {
|
|
266
|
+
fonts: { heading: BrandFont | null; body: BrandFont | null; interface?: BrandFont | null };
|
|
267
|
+
captions: string[];
|
|
268
|
+
/** The overlays' texts by the font that draws them (`getOverlayTextsByRole`). */
|
|
269
|
+
overlays?: { heading: string[]; interface: string[] };
|
|
270
|
+
endCard: { headline: string; url: string; note: string } | null;
|
|
271
|
+
brandName: string;
|
|
272
|
+
},
|
|
251
273
|
read: (path: string) => Buffer = readFileSync,
|
|
252
274
|
): MissingCaptionGlyphs[] {
|
|
253
275
|
const { fonts, endCard } = input;
|
|
254
276
|
const body = findMissingInFamily(fonts.body, [...input.captions, ...(endCard === null ? [] : [endCard.url, endCard.note])], read);
|
|
255
|
-
const headingTexts = endCard === null ? [] : [input.brandName, endCard.headline];
|
|
277
|
+
const headingTexts = [...(endCard === null ? [] : [input.brandName, endCard.headline]), ...(input.overlays?.heading ?? [])];
|
|
256
278
|
const heading = findMissingInFamily(fonts.heading ?? fonts.body, headingTexts, read);
|
|
257
|
-
const
|
|
279
|
+
const ui = findMissingInFamily(fonts.interface ?? fonts.body, input.overlays?.interface ?? [], read);
|
|
280
|
+
const missing = [body, heading, ui].filter((entry): entry is MissingCaptionGlyphs => entry !== null);
|
|
258
281
|
// One family serving both roles is reported once.
|
|
259
282
|
const merged = new Map<string, Set<string>>();
|
|
260
283
|
for (const entry of missing) merged.set(entry.font, new Set([...(merged.get(entry.font) ?? []), ...entry.characters]));
|
package/src/footage/compose.ts
CHANGED
|
@@ -75,7 +75,8 @@ export interface FootageComposeInput {
|
|
|
75
75
|
/** The end card's headline size. */
|
|
76
76
|
headlineSize: number;
|
|
77
77
|
colors: BrandColors;
|
|
78
|
-
|
|
78
|
+
/** The heading font (titles, keywords, numbers), the body font (captions) and the interface font (labels, lists); null falls back to the body font. */
|
|
79
|
+
fonts: { heading: ComposeFont | null; body: ComposeFont | null; interface?: ComposeFont | null };
|
|
79
80
|
assets: FootageComposeAssets;
|
|
80
81
|
brandName: string;
|
|
81
82
|
locale: string;
|
|
@@ -276,8 +277,9 @@ export function composeFootage(input: FootageComposeInput): string {
|
|
|
276
277
|
|
|
277
278
|
const bodyFont = fontStack(fonts.body, "sans-serif");
|
|
278
279
|
const headingFont = fonts.heading === null ? bodyFont : fontStack(fonts.heading, "sans-serif");
|
|
279
|
-
const
|
|
280
|
-
const
|
|
280
|
+
const interfaceFont = fonts.interface == null ? bodyFont : fontStack(fonts.interface, "sans-serif");
|
|
281
|
+
const faces = [...fontFaces(fonts.body), ...fontFaces(fonts.heading), ...fontFaces(fonts.interface ?? null)];
|
|
282
|
+
const overlayMarkup = getOverlayMarkup(overlays, { colors: c, headingFont, interfaceFont, locale: input.locale, frame });
|
|
281
283
|
|
|
282
284
|
return assertLocalReferences(`<!doctype html>
|
|
283
285
|
<html lang="${escapeHtml(input.locale)}">
|
|
@@ -1,25 +1,51 @@
|
|
|
1
1
|
import { toAssColor } from "./draft-color.js";
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
2
|
+
import { getCounterSeconds, getOverlayColors, getTypingTimes, type OverlayColors } from "./overlay-html.js";
|
|
3
|
+
import {
|
|
4
|
+
OVERLAY_FONT_ROLES,
|
|
5
|
+
OVERLAY_LINE_HEIGHT,
|
|
6
|
+
OVERLAY_PADDING_EM,
|
|
7
|
+
OVERLAY_TITLE_LINE_HEIGHT,
|
|
8
|
+
SEARCH_BAR_ICON_EM,
|
|
9
|
+
SEARCH_BAR_PADDING_EM,
|
|
10
|
+
estimateTextWidth,
|
|
11
|
+
formatOverlayNumber,
|
|
12
|
+
type OverlayFontRole,
|
|
13
|
+
type OverlayPoint,
|
|
14
|
+
type ResolvedOverlay,
|
|
15
|
+
} from "./overlays.js";
|
|
4
16
|
|
|
5
17
|
/**
|
|
6
18
|
* The draft's overlays as ASS (issue #1200): the same places and times as the render, simplified. Text overlays are
|
|
7
|
-
* cards of the brand's background (libass's opaque box) with the text in its foreground; an
|
|
8
|
-
* and head in the accent; a highlight the accent's outline round its rectangle
|
|
9
|
-
*
|
|
19
|
+
* cards of the brand's background (libass's opaque box, or a drawn rounded card) with the text in its foreground; an
|
|
20
|
+
* arrow is a straight shaft and head in the accent; a highlight the accent's outline round its rectangle; a pin and a
|
|
21
|
+
* magnifier are drawings in the accent. A typed text shows letter by letter (the rest transparent, so its card keeps
|
|
22
|
+
* its size), a counter steps up to its value every tenth of a second, a slide moves up into place. A `punch_in` is drawn
|
|
23
|
+
* by the picture's zoom (`buildPictureFilters`), not here. They sit on layers 3 and 4, over the captions' 0 to 2.
|
|
10
24
|
*/
|
|
11
25
|
|
|
12
26
|
/** An arrow's or a highlight's stroke and the arrow head's length, in px of a 1080 px wide frame (as the render). */
|
|
13
27
|
const STROKE_WIDTH = 10;
|
|
14
28
|
const ARROW_HEAD = 46;
|
|
15
|
-
const
|
|
29
|
+
const FADE_IN_MS = 150;
|
|
30
|
+
const FADE_OUT_MS = 250;
|
|
31
|
+
const FADE = `\\fad(${FADE_IN_MS},${FADE_OUT_MS})`;
|
|
32
|
+
/** How far a slide starts below its place, in px of a 1080 px wide frame, and how long it takes. */
|
|
33
|
+
const SLIDE_PX = 28;
|
|
34
|
+
const SLIDE_MS = 300;
|
|
35
|
+
/** A counter's step in the draft, in seconds. */
|
|
36
|
+
const COUNT_STEP = 0.1;
|
|
37
|
+
/** A transparent primary colour: the typed text not shown yet. */
|
|
38
|
+
const HIDDEN = "{\\1a&HFF&}";
|
|
16
39
|
|
|
17
40
|
const r0 = (value: number): number => Math.round(value);
|
|
18
41
|
|
|
19
42
|
/** An ASS colour for an override tag (`&HBBGGRR&`). */
|
|
20
43
|
const toTagColor = (hex: string): string => `${toAssColor(hex).replace(/^&H../, "&H")}&`;
|
|
21
44
|
|
|
22
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* The three styles the overlays use: `Overlay` (text on an opaque card), `OverlayShape` (drawings) and `OverlayPlain`
|
|
47
|
+
* (text over a drawn card).
|
|
48
|
+
*/
|
|
23
49
|
export function getDraftOverlayStyles(family: string, colors: OverlayColors): string[] {
|
|
24
50
|
const card = toAssColor(colors.background);
|
|
25
51
|
const text = toAssColor(colors.foreground);
|
|
@@ -27,6 +53,7 @@ export function getDraftOverlayStyles(family: string, colors: OverlayColors): st
|
|
|
27
53
|
return [
|
|
28
54
|
`Style: Overlay,${family},48,${text},${text},${card},${card},-1,0,0,0,100,100,0,0,3,16,0,7,0,0,0,1`,
|
|
29
55
|
`Style: OverlayShape,${family},48,${accent},${accent},${accent},${accent},0,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1`,
|
|
56
|
+
`Style: OverlayPlain,${family},48,${text},${text},${text},${text},-1,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1`,
|
|
30
57
|
];
|
|
31
58
|
}
|
|
32
59
|
|
|
@@ -57,35 +84,249 @@ export function getArrowDrawing(from: OverlayPoint, to: OverlayPoint, scale: num
|
|
|
57
84
|
return `${shaft} ${tip}`;
|
|
58
85
|
}
|
|
59
86
|
|
|
60
|
-
/**
|
|
61
|
-
export function
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
87
|
+
/** A rounded rectangle as an ASS drawing: straight sides and quarter-circle corners of radius `radius` (bezier). */
|
|
88
|
+
export function getRoundedRectDrawing(box: { left: number; top: number; width: number; height: number }, radius: number): string {
|
|
89
|
+
const r = Math.min(radius, box.width / 2, box.height / 2);
|
|
90
|
+
const k = r * 0.4477; // 1 - 0.5523, the bezier handle of a quarter circle
|
|
91
|
+
const [x0, y0, x1, y1] = [box.left, box.top, box.left + box.width, box.top + box.height];
|
|
92
|
+
const p = (x: number, y: number) => `${r0(x)} ${r0(y)}`;
|
|
93
|
+
return [
|
|
94
|
+
`m ${p(x0 + r, y0)} l ${p(x1 - r, y0)}`,
|
|
95
|
+
`b ${p(x1 - k, y0)} ${p(x1, y0 + k)} ${p(x1, y0 + r)} l ${p(x1, y1 - r)}`,
|
|
96
|
+
`b ${p(x1, y1 - k)} ${p(x1 - k, y1)} ${p(x1 - r, y1)} l ${p(x0 + r, y1)}`,
|
|
97
|
+
`b ${p(x0 + k, y1)} ${p(x0, y1 - k)} ${p(x0, y1 - r)} l ${p(x0, y0 + r)}`,
|
|
98
|
+
`b ${p(x0, y0 + k)} ${p(x0 + k, y0)} ${p(x0 + r, y0)}`,
|
|
99
|
+
].join(" ");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** A circle as an ASS drawing (four bezier quarters), clockwise, or the other way round to cut a hole. */
|
|
103
|
+
function getCircleDrawing(center: OverlayPoint, radius: number, isReversed = false): string {
|
|
104
|
+
const k = radius * 0.5523;
|
|
105
|
+
const p = (x: number, y: number) => `${r0(center.x + x)} ${r0(center.y + y)}`;
|
|
106
|
+
const turn = isReversed ? -1 : 1;
|
|
107
|
+
return `m ${p(0, -radius)} b ${p(turn * k, -radius)} ${p(turn * radius, -k)} ${p(turn * radius, 0)} b ${p(turn * radius, k)} ${p(turn * k, radius)} ${p(0, radius)} b ${p(-turn * k, radius)} ${p(-turn * radius, k)} ${p(-turn * radius, 0)} b ${p(-turn * radius, -k)} ${p(-turn * k, -radius)} ${p(0, -radius)}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A map pin `size` px tall with its top left at `at`: a drop, its hole cut by drawing it the other way round. */
|
|
111
|
+
export function getPinDrawing(at: OverlayPoint, size: number): string {
|
|
112
|
+
const s = size / 24;
|
|
113
|
+
const p = (x: number, y: number) => `${r0(at.x + x * s)} ${r0(at.y + y * s)}`;
|
|
114
|
+
const drop = `m ${p(12, 22.5)} b ${p(9, 19)} ${p(4.25, 13.5)} ${p(4.25, 9.1)} b ${p(4.25, 4.9)} ${p(7.7, 1.5)} ${p(12, 1.5)} b ${p(16.3, 1.5)} ${p(19.75, 4.9)} ${p(19.75, 9.1)} b ${p(19.75, 13.5)} ${p(15, 19)} ${p(12, 22.5)}`;
|
|
115
|
+
const hole = `m ${p(12, 6.1)} b ${p(10.3, 6.1)} ${p(9, 7.4)} ${p(9, 9.1)} b ${p(9, 10.8)} ${p(10.3, 12.1)} ${p(12, 12.1)} b ${p(13.7, 12.1)} ${p(15, 10.8)} ${p(15, 9.1)} b ${p(15, 7.4)} ${p(13.7, 6.1)} ${p(12, 6.1)}`;
|
|
116
|
+
return `${drop} ${hole}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** A magnifier `size` px wide with its top left at `at`: a ring and a handle. */
|
|
120
|
+
export function getGlassDrawing(at: OverlayPoint, size: number): string {
|
|
121
|
+
const s = size / 24;
|
|
122
|
+
const center = { x: at.x + 10 * s, y: at.y + 10 * s };
|
|
123
|
+
const ring = `${getCircleDrawing(center, 7.9 * s)} ${getCircleDrawing(center, 5.3 * s, true)}`;
|
|
124
|
+
const half = 1.3 * s;
|
|
125
|
+
const p = (x: number, y: number) => `${r0(at.x + x * s)} ${r0(at.y + y * s)}`;
|
|
126
|
+
const handle = `m ${p(15 - half, 15 + half)} l ${p(15 + half, 15 - half)} ${p(21 + half, 21 - half)} ${p(21 - half, 21 + half)}`;
|
|
127
|
+
return `${ring} ${handle}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
interface DraftContext {
|
|
131
|
+
brand: OverlayColors;
|
|
132
|
+
scale: number;
|
|
133
|
+
locale: string;
|
|
134
|
+
/** The font family per role, when it is not the styles' own. */
|
|
135
|
+
fonts: Partial<Record<OverlayFontRole, string>>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** One stretch of an overlay's text: what shows from `from` to `to`, and its tags. */
|
|
139
|
+
interface TextStep {
|
|
140
|
+
from: number;
|
|
141
|
+
to: number;
|
|
142
|
+
text: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The entrance and exit tags of a run of events: the first fades or slides in, the last fades out. */
|
|
146
|
+
function getMotionTags(entrance: "fade" | "slide" | "none", isFirst: boolean, isLast: boolean, slide: { x: number; y: number; dy: number } | null): string {
|
|
147
|
+
const fadeIn = isFirst && entrance !== "none" ? FADE_IN_MS : 0;
|
|
148
|
+
const fadeOut = isLast ? FADE_OUT_MS : 0;
|
|
149
|
+
const fade = fadeIn === 0 && fadeOut === 0 ? "" : `\\fad(${fadeIn},${fadeOut})`;
|
|
150
|
+
const move = isFirst && entrance === "slide" && slide !== null ? `\\move(${r0(slide.x)},${r0(slide.y + slide.dy)},${r0(slide.x)},${r0(slide.y)},0,${SLIDE_MS})` : "";
|
|
151
|
+
return `${move}${fade}`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Text events for a run of steps, positioned at `pos` with `tags`, the entrance on the first and the fade out on the last. */
|
|
155
|
+
function getTextEvents(input: { layer: number; style: string; pos: OverlayPoint; tags: string; steps: TextStep[]; entrance: "fade" | "slide" | "none"; slidePx: number }): string[] {
|
|
156
|
+
return input.steps.map((step, index) => {
|
|
157
|
+
const motion = getMotionTags(input.entrance, index === 0, index === input.steps.length - 1, { x: input.pos.x, y: input.pos.y, dy: input.slidePx });
|
|
158
|
+
const pos = motion.includes("\\move") ? "" : `\\pos(${r0(input.pos.x)},${r0(input.pos.y)})`;
|
|
159
|
+
return `Dialogue: ${input.layer},${toAssTime(step.from)},${toAssTime(step.to)},${input.style},,0,0,0,,{${input.tags}${pos}${motion}}${step.text}`;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** The steps of a text that types in letter by letter (the rest transparent), or one step showing it all. */
|
|
164
|
+
function getTypedSteps(text: string, span: { start: number; end: number }, typing: number | null): TextStep[] {
|
|
165
|
+
const clean = toAssText(text);
|
|
166
|
+
if (typing === null || clean.length === 0) return [{ from: span.start, to: span.end, text: clean }];
|
|
167
|
+
const chars = [...clean];
|
|
168
|
+
const times = getTypingTimes(span.start, clean, typing).map((time) => Math.min(time, span.end));
|
|
169
|
+
const steps: TextStep[] = [{ from: span.start, to: times[0] as number, text: `${HIDDEN}${clean}` }];
|
|
170
|
+
times.forEach((time, index) => {
|
|
171
|
+
const shown = chars.slice(0, index + 1).join("");
|
|
172
|
+
const rest = chars.slice(index + 1).join("");
|
|
173
|
+
steps.push({ from: time, to: times[index + 1] ?? span.end, text: rest.length === 0 ? shown : `${shown}${HIDDEN}${rest}` });
|
|
174
|
+
});
|
|
175
|
+
return steps.filter((step) => step.to > step.from);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The colour and font override tags of an overlay's text: only what differs from the style. */
|
|
179
|
+
function getTextTags(overlay: ResolvedOverlay, colors: OverlayColors, context: DraftContext, role: OverlayFontRole, withCard: boolean): string {
|
|
180
|
+
if (overlay.kind === "punch_in") return "";
|
|
181
|
+
const own = overlay.colors;
|
|
182
|
+
const font = context.fonts[role];
|
|
183
|
+
return [
|
|
184
|
+
font === undefined ? "" : `\\fn${font}`,
|
|
185
|
+
own.text === undefined ? "" : `\\1c${toTagColor(colors.foreground)}`,
|
|
186
|
+
withCard && own.card === undefined ? "" : withCard ? `\\3c${toTagColor(colors.background)}` : "",
|
|
187
|
+
].join("");
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** A keyword, a lower third or a list: text on libass's opaque box. */
|
|
191
|
+
function getSideTextEvents(overlay: Extract<ResolvedOverlay, { kind: "keyword" | "lower_third" | "list" }>, context: DraftContext): string[] {
|
|
192
|
+
const colors = getOverlayColors(overlay, context.brand);
|
|
193
|
+
const { box, fontSize, side } = overlay;
|
|
194
|
+
const pad = r0(fontSize * OVERLAY_PADDING_EM.y);
|
|
195
|
+
const isRight = side === "right";
|
|
196
|
+
const x = isRight ? box.left + box.width - pad : box.left + pad;
|
|
197
|
+
const isFoot = overlay.kind === "lower_third";
|
|
198
|
+
const y = isFoot ? box.top + box.height - pad : box.top + pad;
|
|
199
|
+
// \an: 7 top left, 9 top right, 1 bottom left, 3 bottom right.
|
|
200
|
+
const align = isFoot ? (isRight ? 3 : 1) : isRight ? 9 : 7;
|
|
201
|
+
const tags = `\\an${align}${getTextTags(overlay, colors, context, OVERLAY_FONT_ROLES[overlay.kind], true)}`;
|
|
202
|
+
const span = { start: overlay.start, end: overlay.end };
|
|
203
|
+
if (overlay.entrance === null) {
|
|
204
|
+
const text = overlay.kind === "list" ? overlay.items.map((item) => `• ${toAssText(item)}`).join("\\N") : toAssText(overlay.text);
|
|
205
|
+
return [`Dialogue: 3,${toAssTime(overlay.start)},${toAssTime(overlay.end)},Overlay,,0,0,0,,{${tags}\\pos(${r0(x)},${r0(y)})\\fs${fontSize}\\bord${pad}${FADE}}${text}`];
|
|
206
|
+
}
|
|
207
|
+
const steps = overlay.kind === "list" ? [{ from: overlay.start, to: overlay.end, text: overlay.items.map((item) => `• ${toAssText(item)}`).join("\\N") }] : getTypedSteps(overlay.text, span, overlay.typing);
|
|
208
|
+
const entrance = overlay.entrance === "type" ? "fade" : overlay.entrance;
|
|
209
|
+
return getTextEvents({ layer: 3, style: "Overlay", pos: { x, y }, tags: `${tags}\\fs${fontSize}\\bord${pad}`, steps, entrance, slidePx: SLIDE_PX * context.scale });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
type CardOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "search_bar" | "place_card" | "counter" | "date_stamp" }>;
|
|
213
|
+
|
|
214
|
+
/** Each card's own entrance when the overlay names none (a typed card fades its card in). */
|
|
215
|
+
const DEFAULT_ENTRANCES = { hook_title: "slide", search_bar: "fade", place_card: "slide", counter: "fade", date_stamp: "fade" } as const;
|
|
216
|
+
|
|
217
|
+
/** A drawing event in the overlay's card colour (or accent), with the overlay's entrance. */
|
|
218
|
+
function getShapeEvent(overlay: CardOverlay, drawing: string, colour: string, entrance: "fade" | "slide" | "none", scale: number): string {
|
|
219
|
+
const motion = getMotionTags(entrance, true, true, { x: 0, y: 0, dy: SLIDE_PX * scale });
|
|
220
|
+
const pos = motion.includes("\\move") ? "" : "\\pos(0,0)";
|
|
221
|
+
return `Dialogue: 3,${toAssTime(overlay.start)},${toAssTime(overlay.end)},OverlayShape,,0,0,0,,{\\an7${pos}${motion}\\1c${toTagColor(colour)}\\p1}${drawing}{\\p0}`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** A hook title, a search bar, a place card, a counter or a date stamp: a drawn rounded card and its text on layer 4. */
|
|
225
|
+
function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
226
|
+
const colors = getOverlayColors(overlay, context.brand);
|
|
227
|
+
const { box, fontSize } = overlay;
|
|
228
|
+
const entrance = overlay.entrance === null || overlay.entrance === "type" ? (overlay.typing !== null ? "fade" : DEFAULT_ENTRANCES[overlay.kind]) : overlay.entrance;
|
|
229
|
+
const slidePx = SLIDE_PX * context.scale;
|
|
230
|
+
const span = { start: overlay.start, end: overlay.end };
|
|
231
|
+
const radius = overlay.kind === "search_bar" ? box.height / 2 : fontSize * 0.42;
|
|
232
|
+
const events = [getShapeEvent(overlay, getRoundedRectDrawing(box, radius), colors.background, entrance, context.scale)];
|
|
233
|
+
const padX = r0(fontSize * OVERLAY_PADDING_EM.x);
|
|
234
|
+
const padY = r0(fontSize * OVERLAY_PADDING_EM.y);
|
|
235
|
+
const centerX = box.left + box.width / 2;
|
|
236
|
+
const tagsFor = (role: OverlayFontRole) => getTextTags(overlay, colors, context, role, false);
|
|
237
|
+
const text = (pos: OverlayPoint, align: number, size: number, role: OverlayFontRole, steps: TextStep[]) =>
|
|
238
|
+
getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags: `\\an${align}\\fs${r0(size)}${tagsFor(role)}`, steps, entrance, slidePx });
|
|
239
|
+
if (overlay.kind === "hook_title" || overlay.kind === "place_card") {
|
|
240
|
+
let y = box.top + padY;
|
|
241
|
+
if (overlay.kind === "hook_title" && overlay.place !== null) {
|
|
242
|
+
const size = overlay.placeFontSize;
|
|
243
|
+
const pin = Math.round(size * 1.05);
|
|
244
|
+
const rowWidth = pin + Math.round(size * 0.25) + estimateTextWidth(overlay.place, size);
|
|
245
|
+
const rowLeft = centerX - rowWidth / 2;
|
|
246
|
+
events.push(getShapeEvent(overlay, getPinDrawing({ x: rowLeft, y: y + (size * OVERLAY_LINE_HEIGHT - pin) / 2 }, pin), colors.accent, entrance, context.scale).replace("Dialogue: 3,", "Dialogue: 4,"));
|
|
247
|
+
events.push(...text({ x: rowLeft + pin + Math.round(size * 0.25), y }, 7, size, OVERLAY_FONT_ROLES.date_stamp, [{ from: span.start, to: span.end, text: toAssText(overlay.place) }]));
|
|
248
|
+
y += size * 1.3 + fontSize * 0.12;
|
|
69
249
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
250
|
+
const lineHeight = overlay.kind === "hook_title" ? OVERLAY_LINE_HEIGHT : OVERLAY_TITLE_LINE_HEIGHT;
|
|
251
|
+
let typedBefore = 0;
|
|
252
|
+
overlay.lines.forEach((line) => {
|
|
253
|
+
// The lines type one after the other, as the render's characters do.
|
|
254
|
+
const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
|
|
255
|
+
events.push(...text({ x: centerX, y }, 8, fontSize, "heading", getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing).map((step, index) => (index === 0 ? { ...step, from: span.start } : step))));
|
|
256
|
+
typedBefore += [...line].length;
|
|
257
|
+
y += fontSize * lineHeight;
|
|
258
|
+
});
|
|
259
|
+
if (overlay.kind === "place_card" && overlay.subtitle !== null) {
|
|
260
|
+
events.push(...text({ x: centerX, y: y + fontSize * 0.12 }, 8, overlay.subtitleFontSize, "interface", [{ from: span.start, to: span.end, text: toAssText(overlay.subtitle) }]));
|
|
79
261
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
262
|
+
return events;
|
|
263
|
+
}
|
|
264
|
+
if (overlay.kind === "search_bar") {
|
|
265
|
+
const searchPadX = r0(fontSize * SEARCH_BAR_PADDING_EM.x);
|
|
266
|
+
const middle = box.top + box.height / 2;
|
|
267
|
+
events.push(getShapeEvent(overlay, getGlassDrawing({ x: box.left + searchPadX, y: middle - fontSize / 2 }, fontSize), colors.accent, entrance, context.scale).replace("Dialogue: 3,", "Dialogue: 4,"));
|
|
268
|
+
events.push(...text({ x: box.left + searchPadX + Math.round(fontSize * SEARCH_BAR_ICON_EM), y: middle }, 4, fontSize, "interface", getTypedSteps(overlay.text, span, overlay.typing)));
|
|
269
|
+
return events;
|
|
270
|
+
}
|
|
271
|
+
if (overlay.kind === "counter") {
|
|
272
|
+
const unit = overlay.unit === null ? "" : `{\\fs${overlay.unitFontSize}} ${toAssText(overlay.unit)}`;
|
|
273
|
+
const count = getCounterSeconds(overlay);
|
|
274
|
+
const steps: TextStep[] = [];
|
|
275
|
+
const ticks = Math.max(1, Math.round(count.duration / COUNT_STEP));
|
|
276
|
+
const show = (value: number) => `${formatOverlayNumber(value, overlay.decimals, context.locale)}${unit}`;
|
|
277
|
+
steps.push({ from: span.start, to: count.start, text: show(overlay.from) });
|
|
278
|
+
for (let tick = 1; tick <= ticks; tick++) {
|
|
279
|
+
const progress = tick / ticks;
|
|
280
|
+
// power2.out, as the render's tween eases.
|
|
281
|
+
const eased = 1 - (1 - progress) ** 2;
|
|
282
|
+
const value = overlay.from + (overlay.value - overlay.from) * eased;
|
|
283
|
+
steps.push({ from: count.start + (tick - 1) * COUNT_STEP, to: tick === ticks ? span.end : count.start + tick * COUNT_STEP, text: show(value) });
|
|
284
|
+
}
|
|
285
|
+
return [...events, ...text({ x: centerX, y: box.top + box.height / 2 }, 5, fontSize, "heading", steps.filter((step) => step.to > step.from))];
|
|
286
|
+
}
|
|
287
|
+
const isRight = overlay.side === "right";
|
|
288
|
+
const x = isRight ? box.left + box.width - padX : box.left + padX;
|
|
289
|
+
events.push(...text({ x, y: box.top + padY }, isRight ? 9 : 7, fontSize, "interface", getTypedSteps(overlay.text, span, overlay.typing)));
|
|
290
|
+
if (overlay.place !== null) {
|
|
291
|
+
events.push(...text({ x, y: box.top + padY + fontSize * OVERLAY_LINE_HEIGHT }, isRight ? 9 : 7, overlay.placeFontSize, "interface", [{ from: span.start, to: span.end, text: toAssText(overlay.place) }]));
|
|
292
|
+
}
|
|
293
|
+
return events;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** An arrow or a highlight in its accent. */
|
|
297
|
+
function getMarkEvents(overlay: Extract<ResolvedOverlay, { kind: "arrow" | "highlight" }>, context: DraftContext): string[] {
|
|
298
|
+
const at = `${toAssTime(overlay.start)},${toAssTime(overlay.end)}`;
|
|
299
|
+
const accent = toTagColor(getOverlayColors(overlay, context.brand).accent);
|
|
300
|
+
const fade = overlay.entrance === "none" ? `\\fad(0,${FADE_OUT_MS})` : FADE;
|
|
301
|
+
const colour = overlay.colors.accent === undefined ? "" : `\\1c${accent}`;
|
|
302
|
+
if (overlay.kind === "arrow") {
|
|
303
|
+
return [`Dialogue: 3,${at},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${fade}${colour}\\p1}${getArrowDrawing(overlay.from, overlay.to, context.scale)}{\\p0}`];
|
|
304
|
+
}
|
|
305
|
+
// libass grows a drawing's border outwards only: the shape is inset by half the stroke and bordered by all of
|
|
306
|
+
// it, so the stroke straddles the rectangle's edge as the render's SVG stroke does.
|
|
307
|
+
const stroke = r0(STROKE_WIDTH * context.scale);
|
|
308
|
+
const half = stroke / 2;
|
|
309
|
+
const [left, top] = [overlay.rect.left + half, overlay.rect.top + half];
|
|
310
|
+
const [right, bottom] = [overlay.rect.left + overlay.rect.width - half, overlay.rect.top + overlay.rect.height - half];
|
|
311
|
+
const shape = `m ${r0(left)} ${r0(top)} l ${r0(right)} ${r0(top)} ${r0(right)} ${r0(bottom)} ${r0(left)} ${r0(bottom)}`;
|
|
312
|
+
return [`Dialogue: 3,${at},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${fade}\\1a&HFF&\\3c${accent}\\bord${stroke}\\p1}${shape}{\\p0}`];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The overlays as ASS events, layers 3 and 4. `fonts` names the heading and interface families where they are not the
|
|
317
|
+
* styles' own (the captions' font); `locale` groups a counter's number as the render does.
|
|
318
|
+
*/
|
|
319
|
+
export function buildDraftOverlayEvents(
|
|
320
|
+
overlays: readonly ResolvedOverlay[],
|
|
321
|
+
colors: OverlayColors,
|
|
322
|
+
frame: { width: number; height: number },
|
|
323
|
+
options: { fonts?: Partial<Record<OverlayFontRole, string>>; locale?: string } = {},
|
|
324
|
+
): string[] {
|
|
325
|
+
const context: DraftContext = { brand: colors, scale: frame.width / 1080, locale: options.locale ?? "en-US", fonts: options.fonts ?? {} };
|
|
326
|
+
return overlays.flatMap((overlay) => {
|
|
327
|
+
if (overlay.kind === "punch_in") return [];
|
|
328
|
+
if (overlay.kind === "arrow" || overlay.kind === "highlight") return getMarkEvents(overlay, context);
|
|
329
|
+
if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") return getSideTextEvents(overlay, context);
|
|
330
|
+
return getCardEvents(overlay, context);
|
|
90
331
|
});
|
|
91
332
|
}
|