@softure-ai/marketing-kit 0.33.0 → 0.35.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 +53 -0
- package/NOTICE +6 -0
- package/README.md +39 -0
- package/dist/config/schema.d.ts +8 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/footage/camera.d.ts +67 -0
- package/dist/footage/camera.d.ts.map +1 -0
- package/dist/footage/camera.js +89 -0
- package/dist/footage/camera.js.map +1 -0
- package/dist/footage/compose.d.ts +7 -1
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +45 -10
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/draft-overlays.d.ts +6 -0
- package/dist/footage/draft-overlays.d.ts.map +1 -1
- package/dist/footage/draft-overlays.js +194 -9
- package/dist/footage/draft-overlays.js.map +1 -1
- package/dist/footage/draft.d.ts +21 -2
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +70 -31
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/drawn-transitions.d.ts +63 -0
- package/dist/footage/drawn-transitions.d.ts.map +1 -0
- package/dist/footage/drawn-transitions.js +177 -0
- package/dist/footage/drawn-transitions.js.map +1 -0
- package/dist/footage/edl.d.ts +39 -0
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +48 -1
- package/dist/footage/edl.js.map +1 -1
- package/dist/footage/film.d.ts +4 -3
- package/dist/footage/film.d.ts.map +1 -1
- package/dist/footage/film.js +3 -2
- package/dist/footage/film.js.map +1 -1
- package/dist/footage/hand-font.d.ts +16 -0
- package/dist/footage/hand-font.d.ts.map +1 -0
- package/dist/footage/hand-font.js +43 -0
- package/dist/footage/hand-font.js.map +1 -0
- package/dist/footage/overlay-html.d.ts +1 -0
- package/dist/footage/overlay-html.d.ts.map +1 -1
- package/dist/footage/overlay-html.js +138 -9
- package/dist/footage/overlay-html.js.map +1 -1
- package/dist/footage/overlay-motion.d.ts +35 -0
- package/dist/footage/overlay-motion.d.ts.map +1 -1
- package/dist/footage/overlay-motion.js +45 -0
- package/dist/footage/overlay-motion.js.map +1 -1
- package/dist/footage/overlay-schema.d.ts +57 -8
- package/dist/footage/overlay-schema.d.ts.map +1 -1
- package/dist/footage/overlay-schema.js +87 -21
- package/dist/footage/overlay-schema.js.map +1 -1
- package/dist/footage/overlays.d.ts +127 -1
- package/dist/footage/overlays.d.ts.map +1 -1
- package/dist/footage/overlays.js +277 -12
- package/dist/footage/overlays.js.map +1 -1
- package/dist/footage/picture.d.ts +8 -2
- package/dist/footage/picture.d.ts.map +1 -1
- package/dist/footage/picture.js +41 -15
- package/dist/footage/picture.js.map +1 -1
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +7 -1
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/footage/tools.d.ts +1 -1
- package/dist/footage/tools.d.ts.map +1 -1
- package/dist/footage/tools.js +1 -1
- package/dist/footage/tools.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/fonts/Caveat-SemiBold-Latin.ttf +0 -0
- package/fonts/LICENSE-Caveat.txt +93 -0
- package/fonts/README.md +14 -0
- package/package.json +1 -1
- package/schema/edl.schema.json +108 -13
- package/schema/marketing.schema.json +10 -2
- package/src/config/schema.ts +1 -1
- package/src/footage/camera.ts +129 -0
- package/src/footage/compose.ts +42 -11
- package/src/footage/draft-overlays.ts +223 -7
- package/src/footage/draft.ts +83 -32
- package/src/footage/drawn-transitions.ts +214 -0
- package/src/footage/edl.ts +45 -1
- package/src/footage/film.ts +3 -2
- package/src/footage/hand-font.ts +47 -0
- package/src/footage/overlay-html.ts +145 -8
- package/src/footage/overlay-motion.ts +49 -0
- package/src/footage/overlay-schema.ts +100 -23
- package/src/footage/overlays.ts +332 -15
- package/src/footage/picture.ts +48 -17
- package/src/footage/pipeline.ts +7 -1
- package/src/footage/tools.ts +1 -1
- package/src/index.ts +56 -0
package/dist/footage/overlays.js
CHANGED
|
@@ -4,10 +4,12 @@ import { getEdlDuration, getSegmentStarts, findSegmentAt } from "./edl.js";
|
|
|
4
4
|
import { getFootageEdit } from "./film.js";
|
|
5
5
|
import { FOOTAGE_FPS } from "./normalize.js";
|
|
6
6
|
import { DEFAULT_OVERLAY_TYPING_SPEED, isTypedOverlay, } from "./overlay-schema.js";
|
|
7
|
+
import { isCameraMoving, isSameCamera } from "./camera.js";
|
|
7
8
|
import { getSegmentZoomEases } from "./compose.js";
|
|
8
9
|
import { normalizeWord } from "./words.js";
|
|
9
|
-
import { getListItemStarts } from "./overlay-motion.js";
|
|
10
|
+
import { NOTE_FIRST_WORD_LEAD, NOTE_TICK_DELAY, getListItemStarts } from "./overlay-motion.js";
|
|
10
11
|
import { STYLE_PADDING_SCALES } from "./brand-style.js";
|
|
12
|
+
import { measureHandText } from "./hand-font.js";
|
|
11
13
|
/**
|
|
12
14
|
* An EDL's overlays resolved for the render and the draft (issue #1200): each one's film time (from its word through
|
|
13
15
|
* the cut, or its second), the segment it plays in, and where it sits in the frame, inside the platform safe zone and
|
|
@@ -28,7 +30,29 @@ export const OVERLAY_FONT_SIZES = {
|
|
|
28
30
|
place_card: { s: 70, m: 92, l: 118 },
|
|
29
31
|
counter: { s: 84, m: 108, l: 132 },
|
|
30
32
|
date_stamp: { s: 30, m: 36, l: 44 },
|
|
33
|
+
note: { s: 46, m: 56, l: 68 },
|
|
34
|
+
end_word: { s: 120, m: 150, l: 180 },
|
|
31
35
|
};
|
|
36
|
+
/** A note strip's type size (its capitals), in px of a 1080 px wide frame; a note card's is `OVERLAY_FONT_SIZES.note`. */
|
|
37
|
+
export const NOTE_STRIP_FONT_SIZES = { s: 38, m: 46, l: 54 };
|
|
38
|
+
/** A note's line height, and its padding round the text, in font sizes. */
|
|
39
|
+
export const NOTE_LINE_HEIGHT = 1.2;
|
|
40
|
+
export const NOTE_PADDING_EM = { x: 0.55, y: 0.4 };
|
|
41
|
+
/** How deep a note's torn edge cuts into the paper, in font sizes (the card's foot, the strip's top). */
|
|
42
|
+
export const NOTE_TEAR_EM = 0.22;
|
|
43
|
+
/** The points along a note's torn edge. */
|
|
44
|
+
export const NOTE_TEAR_POINTS = 14;
|
|
45
|
+
/** A note's tick: its size and its gap after the last line, in font sizes. */
|
|
46
|
+
export const NOTE_TICK_EM = { size: 0.9, gap: 0.3 };
|
|
47
|
+
/** The most words a line of a note card takes, and the most lines a note takes. */
|
|
48
|
+
export const MAX_NOTE_LINE_WORDS = 6;
|
|
49
|
+
export const MAX_NOTE_LINES = 4;
|
|
50
|
+
/** The share of the safe zone's width a note may take: a small card beside the subject, not a banner. */
|
|
51
|
+
export const NOTE_WIDTH_SHARE = 0.62;
|
|
52
|
+
/** A note's tilt in degrees, counter-clockwise positive as ASS turns (a note on the left leans back, on the right forward). */
|
|
53
|
+
export const NOTE_TILT = { card: 3, strip: 2 };
|
|
54
|
+
/** A note's paper and ink without its own colours: an off-white paper and near-black ink, a green tick. */
|
|
55
|
+
export const NOTE_COLORS = { paper: "#fbf8f1", ink: "#1d1f24", tick: "#2f9e4f" };
|
|
32
56
|
/** A second line's type size in main font sizes: the hook title's place label, the subtitle, the unit, the stamp's place. */
|
|
33
57
|
export const OVERLAY_SECONDARY_SCALE = { hook_title: 0.55, place_card: 0.55, counter: 0.5, date_stamp: 0.78 };
|
|
34
58
|
/** A place card's subtitle size in title sizes, by its `subtitle_size` (RV-131 of an adopting app: 0.42 read tiny). */
|
|
@@ -72,6 +96,9 @@ export const OVERLAY_FONT_ROLES = {
|
|
|
72
96
|
list: "interface",
|
|
73
97
|
search_bar: "interface",
|
|
74
98
|
date_stamp: "interface",
|
|
99
|
+
// A note strip types in the heading font; a note card and an end word are handwritten (the kit's own `HAND_FONT`).
|
|
100
|
+
note: "heading",
|
|
101
|
+
end_word: "heading",
|
|
75
102
|
};
|
|
76
103
|
/** The part of the frame no platform interface covers: a 9:16 film's caption preset zone (`all` without one), else 80 px. */
|
|
77
104
|
export function getOverlaySafeZone(film, frame) {
|
|
@@ -128,6 +155,16 @@ export function getOverlayPadding(overlay) {
|
|
|
128
155
|
export function estimateTextWidth(text, fontSize) {
|
|
129
156
|
return Math.ceil([...text].length * OVERLAY_CHAR_EM * fontSize - 1e-6);
|
|
130
157
|
}
|
|
158
|
+
/** How a note's line is measured: a card's handwriting from the hand font itself, a strip's capitals by their own wider average. */
|
|
159
|
+
export function getNoteMeasure(noteStyle) {
|
|
160
|
+
return noteStyle === "card" ? measureHandText : measureStripText;
|
|
161
|
+
}
|
|
162
|
+
/** A strip's capitals per character, in font sizes: bold capitals run about 0.72 em, plus the strip's letter spacing. */
|
|
163
|
+
export const NOTE_STRIP_CHAR_EM = 0.76;
|
|
164
|
+
/** How wide a strip's capitals are at `fontSize`: wider than `estimateTextWidth`'s mixed-case average. */
|
|
165
|
+
function measureStripText(text, fontSize) {
|
|
166
|
+
return Math.ceil([...text].length * NOTE_STRIP_CHAR_EM * fontSize - 1e-6);
|
|
167
|
+
}
|
|
131
168
|
/** Text broken into lines at spaces so each fits `width` at `fontSize` by the estimate; a word longer than a line stands alone. */
|
|
132
169
|
export function wrapOverlayText(text, fontSize, width) {
|
|
133
170
|
const lines = [];
|
|
@@ -192,13 +229,13 @@ export function getDrawnOverlayCard(overlay) {
|
|
|
192
229
|
return getBoxesUnion(overlay.chips);
|
|
193
230
|
return getSideTextCard(overlay, getSideTextLines(overlay), overlay.box.height);
|
|
194
231
|
}
|
|
195
|
-
/** The card of a side text fitted to `lines`, `height` tall from the box's top: on its side, or in the box's middle. */
|
|
232
|
+
/** The card of a side text fitted to `lines`, `height` tall from the box's top: on its side, or in the box's middle (a centred list or keyword). */
|
|
196
233
|
function getSideTextCard(overlay, lines, height) {
|
|
197
234
|
const { box, fontSize, side } = overlay;
|
|
198
235
|
const padX = getOverlayPadding(overlay).x;
|
|
199
236
|
const textWidth = Math.max(0, ...lines.map((line) => estimateTextWidth(line, fontSize)));
|
|
200
237
|
const width = Math.min(box.width, Math.ceil(textWidth + 2 * padX));
|
|
201
|
-
const isCentred = overlay.kind === "list" && overlay.isCentred === true;
|
|
238
|
+
const isCentred = (overlay.kind === "list" || overlay.kind === "keyword") && overlay.isCentred === true;
|
|
202
239
|
const left = isCentred ? box.left + Math.round((box.width - width) / 2) : side === "right" ? box.left + box.width - width : box.left;
|
|
203
240
|
return { left, top: box.top, width, height };
|
|
204
241
|
}
|
|
@@ -249,6 +286,8 @@ export function findShotBreak(edl, index) {
|
|
|
249
286
|
return `segment "${segment.id}" starts on a ${segment.transition}, not a plain cut`;
|
|
250
287
|
if (segment.motion === "kenburns" || previous.motion === "kenburns")
|
|
251
288
|
return `a Ken Burns zoom at segment "${segment.id}"`;
|
|
289
|
+
if (isCameraMoving(segment.camera) || isCameraMoving(previous.camera) || !isSameCamera(segment.camera, previous.camera))
|
|
290
|
+
return `a camera move or a new framing at segment "${segment.id}"`;
|
|
252
291
|
if (segment.caption?.bottom !== previous.caption?.bottom || segment.caption?.top !== previous.caption?.top)
|
|
253
292
|
return `segment "${segment.id}" moves the captions`;
|
|
254
293
|
return null;
|
|
@@ -304,7 +343,7 @@ export function resolveEdlOverlays(input) {
|
|
|
304
343
|
const segment = findSegmentAt(edl, start);
|
|
305
344
|
const segmentStart = starts[segment];
|
|
306
345
|
const segmentId = edl.segments[segment]?.id ?? "";
|
|
307
|
-
if (overlay.kind
|
|
346
|
+
if (!isTitleBand(overlay.kind)) {
|
|
308
347
|
const shot = findShotSpan(edl, starts, { segment, end, isPunchIn: overlay.kind === "punch_in" });
|
|
309
348
|
if (end > shot.end + 0.01) {
|
|
310
349
|
const inside = shot.last === segment ? `segment "${segmentId}"` : `segments "${segmentId}" to "${edl.segments[shot.last]?.id ?? ""}"`;
|
|
@@ -329,11 +368,20 @@ export function resolveEdlOverlays(input) {
|
|
|
329
368
|
// The first point comes in with the card, so the card never stands empty (RV-144 of an adopting app).
|
|
330
369
|
placed.overlay.itemStarts = getListItemStarts({ start, end, count: placed.overlay.items.length, ...(times === undefined ? {} : { words: times }) }).map((at, item) => (item === 0 ? start : at));
|
|
331
370
|
}
|
|
371
|
+
if (placed.overlay.kind === "note") {
|
|
372
|
+
const timed = timeNote(placed.overlay, input.words);
|
|
373
|
+
placed.overlay.wordTimes = timed.wordTimes;
|
|
374
|
+
placed.overlay.tickAt = timed.tickAt;
|
|
375
|
+
}
|
|
332
376
|
if (placed.overlay.kind === "punch_in") {
|
|
333
377
|
if (edl.segments[segment]?.motion === "kenburns") {
|
|
334
378
|
problems.push(`${at}: segment "${segmentId}" has a Ken Burns zoom, which owns the picture's scale; put the punch-in on a still segment`);
|
|
335
379
|
return;
|
|
336
380
|
}
|
|
381
|
+
if (edl.segments[segment]?.camera !== undefined) {
|
|
382
|
+
problems.push(`${at}: segment "${segmentId}" has a camera (a move or a framing), which owns the picture's scale; put the punch-in on a segment without one`);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
337
385
|
const easeEnd = r3(segmentStart + (eases[segment] ?? 0) / FOOTAGE_FPS);
|
|
338
386
|
if (start < easeEnd) {
|
|
339
387
|
problems.push(`${at}: starts at ${start} s, inside the zoom cut's ease of segment "${segmentId}" (until ${easeEnd} s); start it later`);
|
|
@@ -346,6 +394,10 @@ export function resolveEdlOverlays(input) {
|
|
|
346
394
|
problems.push(...findTimingProblems(ordered, film.overlayMinSpacing ?? 0));
|
|
347
395
|
return problems.length > 0 ? { ok: false, problems } : { ok: true, overlays: ordered };
|
|
348
396
|
}
|
|
397
|
+
/** The kinds that live in the top band (a hook title, an end word): not counted against one overlay at a time. */
|
|
398
|
+
export function isTitleBand(kind) {
|
|
399
|
+
return kind === "hook_title" || kind === "end_word";
|
|
400
|
+
}
|
|
349
401
|
/** Whether two overlays are on screen at the same time. */
|
|
350
402
|
function isConcurrent(a, b) {
|
|
351
403
|
return a.start < b.end - 0.001 && b.start < a.end - 0.001;
|
|
@@ -353,7 +405,7 @@ function isConcurrent(a, b) {
|
|
|
353
405
|
/** Two overlays on screen at once, two too close, two hook titles at once, or a drawing on a hook title while it shows. */
|
|
354
406
|
function findTimingProblems(ordered, spacing) {
|
|
355
407
|
const problems = [];
|
|
356
|
-
const counted = ordered.filter((overlay) => overlay.kind
|
|
408
|
+
const counted = ordered.filter((overlay) => !isTitleBand(overlay.kind));
|
|
357
409
|
counted.forEach((overlay, place) => {
|
|
358
410
|
const previous = counted[place - 1];
|
|
359
411
|
if (previous === undefined)
|
|
@@ -365,18 +417,19 @@ function findTimingProblems(ordered, spacing) {
|
|
|
365
417
|
problems.push(`overlays[${overlay.index}]: starts ${r1(overlay.start - previous.start)} s after overlays[${previous.index}]; the film keeps overlays ${spacing} s apart (overlayMinSpacing)`);
|
|
366
418
|
}
|
|
367
419
|
});
|
|
368
|
-
const titles = ordered.filter((overlay) => overlay.kind
|
|
420
|
+
const titles = ordered.filter((overlay) => isTitleBand(overlay.kind));
|
|
369
421
|
titles.forEach((title, place) => {
|
|
422
|
+
const name = title.kind.replace("_", " ");
|
|
370
423
|
const previous = titles[place - 1];
|
|
371
424
|
if (previous !== undefined && isConcurrent(title, previous)) {
|
|
372
|
-
problems.push(`overlays[${title.index}]: starts at ${title.start} s while the
|
|
425
|
+
problems.push(`overlays[${title.index}]: starts at ${title.start} s while the ${previous.kind.replace("_", " ")} overlays[${previous.index}] is on screen (until ${previous.end} s); one title at the top at a time`);
|
|
373
426
|
}
|
|
374
427
|
const titleBox = title.box;
|
|
375
428
|
for (const other of counted) {
|
|
376
429
|
const bounds = getOverlayBounds(other);
|
|
377
430
|
if (bounds === null || !isConcurrent(title, other) || !isOverlapping(bounds, titleBox))
|
|
378
431
|
continue;
|
|
379
|
-
problems.push(`overlays[${other.index}]: the ${other.kind.replace("_", " ")} would sit on the
|
|
432
|
+
problems.push(`overlays[${other.index}]: the ${other.kind.replace("_", " ")} would sit on the ${name} overlays[${title.index}] (on screen until ${title.end} s); move it lower or start it after the ${name}`);
|
|
380
433
|
}
|
|
381
434
|
});
|
|
382
435
|
return problems;
|
|
@@ -427,8 +480,153 @@ function placeOverlay(overlay, base, place) {
|
|
|
427
480
|
return placeMark(overlay, drawn, place);
|
|
428
481
|
if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list")
|
|
429
482
|
return placeSideText({ ...overlay, kind: overlay.kind }, drawn, place);
|
|
483
|
+
if (overlay.kind === "note")
|
|
484
|
+
return placeNote(overlay, drawn, place);
|
|
485
|
+
if (overlay.kind === "end_word")
|
|
486
|
+
return placeEndWord(overlay, drawn, place);
|
|
430
487
|
return placeCard({ ...overlay, kind: overlay.kind }, drawn, place);
|
|
431
488
|
}
|
|
489
|
+
/** A note's lines: broken at spaces to fit `width`, at most `MAX_NOTE_LINE_WORDS` words a line; null when a word alone is wider. */
|
|
490
|
+
export function wrapNoteText(text, fontSize, width, measure = estimateTextWidth) {
|
|
491
|
+
const lines = [];
|
|
492
|
+
for (const word of text.split(/\s+/).filter((part) => part.length > 0)) {
|
|
493
|
+
if (measure(word, fontSize) > width)
|
|
494
|
+
return null;
|
|
495
|
+
const last = lines[lines.length - 1];
|
|
496
|
+
if (last !== undefined && last.length < MAX_NOTE_LINE_WORDS && measure([...last, word].join(" "), fontSize) <= width)
|
|
497
|
+
last.push(word);
|
|
498
|
+
else
|
|
499
|
+
lines.push([word]);
|
|
500
|
+
}
|
|
501
|
+
return lines.map((line) => line.join(" "));
|
|
502
|
+
}
|
|
503
|
+
/** A number from 0 to 1 for each of `count` points, the same for the same text: a torn edge that is not a pattern. */
|
|
504
|
+
export function getTornEdge(text, count = NOTE_TEAR_POINTS) {
|
|
505
|
+
let seed = 2166136261;
|
|
506
|
+
for (const char of text)
|
|
507
|
+
seed = Math.imul(seed ^ (char.codePointAt(0) ?? 0), 16777619) >>> 0;
|
|
508
|
+
return Array.from({ length: count }, () => {
|
|
509
|
+
seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
|
|
510
|
+
return r3(0.25 + 0.75 * (seed / 4294967296));
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
/** A note's tick size and the gap before it, in px. */
|
|
514
|
+
export function getNoteTickSize(fontSize) {
|
|
515
|
+
return { size: Math.round(fontSize * NOTE_TICK_EM.size), gap: Math.round(fontSize * NOTE_TICK_EM.gap) };
|
|
516
|
+
}
|
|
517
|
+
/** A note's padding round its text, in px. */
|
|
518
|
+
export function getNotePadding(fontSize) {
|
|
519
|
+
return { x: Math.round(fontSize * NOTE_PADDING_EM.x), y: Math.round(fontSize * NOTE_PADDING_EM.y), tear: Math.round(fontSize * NOTE_TEAR_EM) };
|
|
520
|
+
}
|
|
521
|
+
/** A note's text block inside its paper: its left edge and top, in px (the tear takes the card's foot, the strip's top). */
|
|
522
|
+
export function getNoteTextBox(note) {
|
|
523
|
+
const pad = getNotePadding(note.fontSize);
|
|
524
|
+
const top = note.box.top + pad.y + (note.noteStyle === "strip" ? pad.tear : 0);
|
|
525
|
+
return { left: note.box.left + pad.x, top, width: note.box.width - 2 * pad.x, height: note.lines.length * note.fontSize * NOTE_LINE_HEIGHT };
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* A note: a paper card (handwritten, its words coming in as they are said) or a strip (typed capitals), on its side
|
|
529
|
+
* in the top or the middle of the room above the captions, at most `NOTE_WIDTH_SHARE` of the safe width; a text that
|
|
530
|
+
* takes more than `MAX_NOTE_LINES` lines is refused.
|
|
531
|
+
*/
|
|
532
|
+
function placeNote(overlay, drawn, place) {
|
|
533
|
+
const { zone, frame } = place;
|
|
534
|
+
const scale = frame.width / 1080;
|
|
535
|
+
const noteStyle = overlay.style?.note_style ?? "card";
|
|
536
|
+
const size = overlay.style?.size ?? "m";
|
|
537
|
+
const fontSize = Math.round((noteStyle === "strip" ? NOTE_STRIP_FONT_SIZES : OVERLAY_FONT_SIZES.note)[size] * scale);
|
|
538
|
+
const pad = getNotePadding(fontSize);
|
|
539
|
+
const margin = Math.round(OVERLAY_MARGIN * scale);
|
|
540
|
+
const room = Math.round((frame.width - zone.left - zone.right - 2 * margin) * NOTE_WIDTH_SHARE) - 2 * pad.x;
|
|
541
|
+
const text = noteStyle === "strip" ? (overlay.text ?? "").toUpperCase() : (overlay.text ?? "");
|
|
542
|
+
const measure = getNoteMeasure(noteStyle);
|
|
543
|
+
const lines = wrapNoteText(text, fontSize, room, measure);
|
|
544
|
+
if (lines === null)
|
|
545
|
+
return { ok: false, error: "a word of the note is too wide for its card; shorten it or use a smaller size" };
|
|
546
|
+
if (lines.length > MAX_NOTE_LINES)
|
|
547
|
+
return { ok: false, error: `the note takes ${lines.length} lines, more than ${MAX_NOTE_LINES}; shorten it or use a smaller size` };
|
|
548
|
+
const isTick = overlay.style?.tick === true;
|
|
549
|
+
const tick = getNoteTickSize(fontSize);
|
|
550
|
+
const lastWidth = measure(lines[lines.length - 1] ?? "", fontSize) + (isTick ? tick.gap + tick.size : 0);
|
|
551
|
+
const contentWidth = Math.max(lastWidth, ...lines.map((line) => measure(line, fontSize)));
|
|
552
|
+
if (contentWidth > room)
|
|
553
|
+
return { ok: false, error: "the note's last line and its tick are too wide for its card; shorten it or leave the tick out" };
|
|
554
|
+
const width = Math.ceil(contentWidth + 2 * pad.x);
|
|
555
|
+
const height = Math.ceil(lines.length * fontSize * NOTE_LINE_HEIGHT + 2 * pad.y + pad.tear);
|
|
556
|
+
const region = getTextRegion(place);
|
|
557
|
+
const top = getPositionTop(region, overlay.style?.position ?? "top", height);
|
|
558
|
+
if (top < region.top || top + height > region.bottom) {
|
|
559
|
+
return { ok: false, error: `the note (${height} px tall) does not fit between the platform safe zone and the captions; use a smaller size or shorter text` };
|
|
560
|
+
}
|
|
561
|
+
const side = overlay.style?.side ?? "left";
|
|
562
|
+
const left = side === "right" ? frame.width - zone.right - margin - width : zone.left + margin;
|
|
563
|
+
const tilt = (side === "right" ? -1 : 1) * NOTE_TILT[noteStyle];
|
|
564
|
+
return {
|
|
565
|
+
ok: true,
|
|
566
|
+
overlay: { ...drawn, kind: "note", noteStyle, lines, fontSize, side, box: { left, top, width, height }, tilt, tear: getTornEdge(text), wordTimes: null, tick: isTick, tickAt: null },
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* A note card's word times and its tick's start: each word of the note comes in on the same word said inside its span
|
|
571
|
+
* (matched in order, compared like fillers are), a word not said with the one before it; when none is said, the words
|
|
572
|
+
* are spaced over the first part of the span. The card is there one frame before its first word, and no word comes
|
|
573
|
+
* later than 0.6 s before its end. A strip types its text (`getTypingTimes`), its tick after its last letter.
|
|
574
|
+
*/
|
|
575
|
+
export function timeNote(note, words) {
|
|
576
|
+
// The tick comes after the last word, but never in the note's last 0.4 s nor before it starts.
|
|
577
|
+
const tickAfter = (at) => (note.tick ? r3(Math.max(note.start, Math.min(note.end - 0.4, at + NOTE_TICK_DELAY))) : null);
|
|
578
|
+
const noteWords = note.lines.join(" ").split(" ");
|
|
579
|
+
const first = r3(note.start + NOTE_FIRST_WORD_LEAD);
|
|
580
|
+
const latest = r3(Math.max(first, note.end - 0.6));
|
|
581
|
+
if (note.noteStyle === "strip") {
|
|
582
|
+
const typed = note.typing ?? DEFAULT_OVERLAY_TYPING_SPEED;
|
|
583
|
+
const lastLetter = note.start + 0.3 + ([...note.lines.join("")].length - 1) / typed;
|
|
584
|
+
return { wordTimes: null, tickAt: tickAfter(lastLetter) };
|
|
585
|
+
}
|
|
586
|
+
const said = words.filter((word) => word.start >= note.start - 0.05 && word.start < note.end);
|
|
587
|
+
let cursor = 0;
|
|
588
|
+
let previous = null;
|
|
589
|
+
const matched = noteWords.map((word) => {
|
|
590
|
+
const key = normalizeWord(word);
|
|
591
|
+
const found = said.findIndex((spoken, index) => index >= cursor && normalizeWord(spoken.text) === key);
|
|
592
|
+
if (found === -1)
|
|
593
|
+
return previous;
|
|
594
|
+
cursor = found + 1;
|
|
595
|
+
previous = said[found]?.start ?? null;
|
|
596
|
+
return previous;
|
|
597
|
+
});
|
|
598
|
+
const isSaid = matched.some((time) => time !== null);
|
|
599
|
+
const gap = Math.min(0.35, Math.max(0.12, ((note.end - note.start) * 0.5) / noteWords.length));
|
|
600
|
+
const times = noteWords.map((_word, index) => {
|
|
601
|
+
const at = isSaid ? (matched[index] ?? first) : first + index * gap;
|
|
602
|
+
return r3(Math.min(latest, Math.max(first, at)));
|
|
603
|
+
});
|
|
604
|
+
// Never earlier than the word before: a later word matched before an earlier one keeps the reading order.
|
|
605
|
+
for (let index = 1; index < times.length; index++)
|
|
606
|
+
times[index] = Math.max(times[index], times[index - 1]);
|
|
607
|
+
return { wordTimes: times, tickAt: tickAfter(times[times.length - 1] ?? first) };
|
|
608
|
+
}
|
|
609
|
+
/** An end word: one big handwritten line at the top of the room, no card, shrunk to fit the width or refused. */
|
|
610
|
+
function placeEndWord(overlay, drawn, place) {
|
|
611
|
+
const { zone, frame } = place;
|
|
612
|
+
const scale = frame.width / 1080;
|
|
613
|
+
const margin = Math.round(OVERLAY_MARGIN * scale);
|
|
614
|
+
const room = frame.width - zone.left - zone.right - 2 * margin;
|
|
615
|
+
const text = (overlay.text ?? "").replace(/\s+/g, " ").trim();
|
|
616
|
+
let fontSize = Math.round(OVERLAY_FONT_SIZES.end_word[overlay.style?.size ?? "m"] * scale);
|
|
617
|
+
for (let shrink = 0; measureHandText(text, fontSize) > room; shrink++) {
|
|
618
|
+
if (shrink === MAX_TITLE_SHRINKS)
|
|
619
|
+
return { ok: false, error: "the end word is too wide for one line even at a smaller size; shorten it or use a smaller size" };
|
|
620
|
+
fontSize = Math.round(fontSize * OVERLAY_TITLE_SHRINK);
|
|
621
|
+
}
|
|
622
|
+
const width = measureHandText(text, fontSize);
|
|
623
|
+
const height = Math.ceil(fontSize * OVERLAY_LINE_HEIGHT);
|
|
624
|
+
const region = getTextRegion(place);
|
|
625
|
+
if (region.top + height > region.bottom)
|
|
626
|
+
return { ok: false, error: `the end word (${height} px tall) does not fit above the captions; use a smaller size` };
|
|
627
|
+
const left = Math.round(zone.left + margin + (room - width) / 2);
|
|
628
|
+
return { ok: true, overlay: { ...drawn, kind: "end_word", text, fontSize, box: { left, top: region.top, width, height } } };
|
|
629
|
+
}
|
|
432
630
|
/** An arrow's tail and point, or a highlight's rectangle. */
|
|
433
631
|
function placeMark(overlay, drawn, place) {
|
|
434
632
|
const { zone, frame } = place;
|
|
@@ -464,7 +662,9 @@ function placeMark(overlay, drawn, place) {
|
|
|
464
662
|
function placeSideText(overlay, drawn, place) {
|
|
465
663
|
const { zone, frame } = place;
|
|
466
664
|
const scale = frame.width / 1080;
|
|
467
|
-
const
|
|
665
|
+
const align = overlay.kind === "keyword" ? overlay.style?.align : undefined;
|
|
666
|
+
// A keyword's align left or right is its side; center puts its card in the middle (`isCentred`).
|
|
667
|
+
const side = align === "left" || align === "right" ? align : (overlay.style?.side ?? (overlay.kind === "keyword" ? "right" : "left"));
|
|
468
668
|
const fontSize = Math.round(OVERLAY_FONT_SIZES[overlay.kind][overlay.style?.size ?? "m"] * scale);
|
|
469
669
|
const pad = getOverlayPadding({ fontSize, padScale: place.padScale });
|
|
470
670
|
const margin = Math.round(OVERLAY_MARGIN * scale);
|
|
@@ -492,7 +692,17 @@ function placeSideText(overlay, drawn, place) {
|
|
|
492
692
|
const fields = { text: overlay.text ?? "", fontSize, side, box };
|
|
493
693
|
if (overlay.kind === "lower_third")
|
|
494
694
|
return { ok: true, overlay: { ...drawn, kind: "lower_third", ...fields } };
|
|
495
|
-
return {
|
|
695
|
+
return {
|
|
696
|
+
ok: true,
|
|
697
|
+
overlay: {
|
|
698
|
+
...drawn,
|
|
699
|
+
kind: "keyword",
|
|
700
|
+
...fields,
|
|
701
|
+
...(overlay.style?.underline === true ? { underline: true } : {}),
|
|
702
|
+
...(align === "center" ? { isCentred: true } : {}),
|
|
703
|
+
...(overlay.style?.backdrop === "highlight" ? { backdrop: "highlight" } : {}),
|
|
704
|
+
},
|
|
705
|
+
};
|
|
496
706
|
}
|
|
497
707
|
/** A row of chips at one type size. */
|
|
498
708
|
function measureChipRow(items, fontSize, padScale) {
|
|
@@ -617,7 +827,8 @@ function measureTitle(overlay, metrics) {
|
|
|
617
827
|
const secondWidth = second === null ? 0 : estimateTextWidth(second, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0);
|
|
618
828
|
if (secondWidth > room)
|
|
619
829
|
return tooWide(metrics, isHook ? "place label" : "subtitle");
|
|
620
|
-
|
|
830
|
+
// A title's align is center or left (the schema refuses right on it).
|
|
831
|
+
const align = overlay.style?.align === "left" ? "left" : "center";
|
|
621
832
|
const pin = !isHook && overlay.style?.pin !== undefined && overlay.style.pin !== "none" ? overlay.style.pin : undefined;
|
|
622
833
|
const delay = !isHook && second !== null && overlay.style?.subtitle_delay !== undefined && overlay.style.subtitle_delay > 0 ? overlay.style.subtitle_delay : undefined;
|
|
623
834
|
return {
|
|
@@ -625,7 +836,7 @@ function measureTitle(overlay, metrics) {
|
|
|
625
836
|
content: {
|
|
626
837
|
...getTitleContentSize({ kind: overlay.kind, lines, fontSize, second, secondSize, pin: pin !== undefined }),
|
|
627
838
|
fields: isHook
|
|
628
|
-
? { kind: "hook_title", lines, place: second, fontSize, placeFontSize: secondSize, align }
|
|
839
|
+
? { kind: "hook_title", lines, place: second, fontSize, placeFontSize: secondSize, align, ...(overlay.style?.backdrop === "highlight" ? { backdrop: "highlight" } : {}) }
|
|
629
840
|
: { kind: "place_card", lines, subtitle: second, fontSize, subtitleFontSize: secondSize, align, ...(pin === undefined ? {} : { pin }), ...(delay === undefined ? {} : { subtitleDelay: delay }) },
|
|
630
841
|
},
|
|
631
842
|
};
|
|
@@ -726,6 +937,10 @@ export function getOverlayTextsByRole(overlays, locale = "en-US") {
|
|
|
726
937
|
else if (overlay.kind === "date_stamp") {
|
|
727
938
|
texts.interface.push(overlay.text, ...(overlay.place === null ? [] : [overlay.place]));
|
|
728
939
|
}
|
|
940
|
+
else if (overlay.kind === "note" && overlay.noteStyle === "strip") {
|
|
941
|
+
// A note card and an end word are drawn in the kit's own handwriting, which covers every Latin letter.
|
|
942
|
+
texts.heading.push(...overlay.lines);
|
|
943
|
+
}
|
|
729
944
|
}
|
|
730
945
|
return texts;
|
|
731
946
|
}
|
|
@@ -734,4 +949,54 @@ export function getOverlayTexts(overlays, locale = "en-US") {
|
|
|
734
949
|
const texts = getOverlayTextsByRole(overlays, locale);
|
|
735
950
|
return [...texts.heading, ...texts.interface];
|
|
736
951
|
}
|
|
952
|
+
/**
|
|
953
|
+
* A note's paper as a polygon in px of the frame, before its tilt: straight sides and a torn edge (`tear`) along the
|
|
954
|
+
* card's foot or the strip's top, cutting at most `NOTE_TEAR_EM` into the paper. Both paths draw this outline.
|
|
955
|
+
*/
|
|
956
|
+
export function getNotePaperPoints(note) {
|
|
957
|
+
const { left, top, width, height } = note.box;
|
|
958
|
+
const depth = getNotePadding(note.fontSize).tear;
|
|
959
|
+
const last = Math.max(1, note.tear.length - 1);
|
|
960
|
+
const torn = note.tear.map((share, index) => ({ x: r1(left + (width * index) / last), share }));
|
|
961
|
+
if (note.noteStyle === "strip") {
|
|
962
|
+
const edge = torn.map(({ x, share }) => ({ x, y: r1(top + depth * share) }));
|
|
963
|
+
return [...edge, { x: left + width, y: top + height }, { x: left, y: top + height }];
|
|
964
|
+
}
|
|
965
|
+
const edge = torn.map(({ x, share }) => ({ x, y: r1(top + height - depth * share) })).reverse();
|
|
966
|
+
return [{ x: left, y: top }, { x: left + width, y: top }, ...edge];
|
|
967
|
+
}
|
|
968
|
+
/** The middle of a note's paper: the point its tilt turns it about. */
|
|
969
|
+
export function getNoteCentre(note) {
|
|
970
|
+
return { x: r1(note.box.left + note.box.width / 2), y: r1(note.box.top + note.box.height / 2) };
|
|
971
|
+
}
|
|
972
|
+
/** A note's tick as three points of a hand-drawn check (down to the left, then a long stroke up), in px before the tilt. */
|
|
973
|
+
export function getNoteTickPoints(note) {
|
|
974
|
+
const text = getNoteTextBox(note);
|
|
975
|
+
const tick = getNoteTickSize(note.fontSize);
|
|
976
|
+
const lastTop = text.top + (note.lines.length - 1) * note.fontSize * NOTE_LINE_HEIGHT;
|
|
977
|
+
const x = text.left + getNoteMeasure(note.noteStyle)(note.lines[note.lines.length - 1] ?? "", note.fontSize) + tick.gap;
|
|
978
|
+
const y = lastTop + (note.fontSize * NOTE_LINE_HEIGHT - tick.size) / 2;
|
|
979
|
+
return [
|
|
980
|
+
{ x: r1(x), y: r1(y + tick.size * 0.55) },
|
|
981
|
+
{ x: r1(x + tick.size * 0.35), y: r1(y + tick.size * 0.9) },
|
|
982
|
+
{ x: r1(x + tick.size), y: r1(y + tick.size * 0.08) },
|
|
983
|
+
];
|
|
984
|
+
}
|
|
985
|
+
/** A note's words line by line, each with its film second (a card's `wordTimes`; a strip's are typed, so its start). */
|
|
986
|
+
export function getNoteWordsByLine(note) {
|
|
987
|
+
let index = 0;
|
|
988
|
+
return note.lines.map((line) => line.split(" ").map((text) => {
|
|
989
|
+
const at = note.wordTimes?.[index] ?? note.start;
|
|
990
|
+
index += 1;
|
|
991
|
+
return { text, at };
|
|
992
|
+
}));
|
|
993
|
+
}
|
|
994
|
+
/** A note's paper, ink and tick colours: its own (`style.colors` card, text, accent), else paper, near-black and green. */
|
|
995
|
+
export function getNoteColors(note) {
|
|
996
|
+
return { paper: note.colors.card ?? NOTE_COLORS.paper, ink: note.colors.text ?? NOTE_COLORS.ink, tick: note.colors.accent ?? NOTE_COLORS.tick };
|
|
997
|
+
}
|
|
998
|
+
/** Whether the overlays draw in the kit's handwriting: a note card or an end word. */
|
|
999
|
+
export function isHandFontNeeded(overlays) {
|
|
1000
|
+
return overlays.some((overlay) => overlay.kind === "end_word" || (overlay.kind === "note" && overlay.noteStyle === "card"));
|
|
1001
|
+
}
|
|
737
1002
|
//# sourceMappingURL=overlays.js.map
|