@softure-ai/marketing-kit 0.41.0 → 0.43.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 +35 -0
- package/README.md +13 -0
- package/dist/compose/timeline.d.ts +6 -0
- package/dist/compose/timeline.d.ts.map +1 -1
- package/dist/compose/timeline.js +9 -1
- package/dist/compose/timeline.js.map +1 -1
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +3 -3
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/draft-overlays.d.ts +21 -1
- package/dist/footage/draft-overlays.d.ts.map +1 -1
- package/dist/footage/draft-overlays.js +180 -26
- package/dist/footage/draft-overlays.js.map +1 -1
- package/dist/footage/draft-text-width.d.ts +43 -0
- package/dist/footage/draft-text-width.d.ts.map +1 -1
- package/dist/footage/draft-text-width.js +62 -1
- package/dist/footage/draft-text-width.js.map +1 -1
- package/dist/footage/draft.d.ts +29 -2
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +64 -29
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/overlay-html.d.ts.map +1 -1
- package/dist/footage/overlay-html.js +6 -5
- package/dist/footage/overlay-html.js.map +1 -1
- package/dist/footage/overlays.d.ts +74 -2
- package/dist/footage/overlays.d.ts.map +1 -1
- package/dist/footage/overlays.js +115 -2
- package/dist/footage/overlays.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/compose/timeline.ts +12 -1
- package/src/footage/compose.ts +3 -3
- package/src/footage/draft-overlays.ts +226 -27
- package/src/footage/draft-text-width.ts +90 -1
- package/src/footage/draft.ts +91 -32
- package/src/footage/overlay-html.ts +6 -4
- package/src/footage/overlays.ts +135 -2
- package/src/index.ts +29 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getCornerRadiusPx } from "./brand-style.js";
|
|
2
2
|
import { getDraftBoxEvents } from "./draft-boxes.js";
|
|
3
3
|
import { toAssColor } from "./draft-color.js";
|
|
4
|
+
import { DEFAULT_CONTENT_AREA, getSpacingWidth, toDraftAssSize, toDraftSpacing, wrapDraftLine } from "./draft-text-width.js";
|
|
4
5
|
import { HAND_FONT, getHandFontAssSize } from "./hand-font.js";
|
|
5
6
|
import { getCounterSeconds, getOverlayColors, getPlaceCardTimes, getTypingTimes } from "./overlay-html.js";
|
|
6
7
|
import { DROP_LETTER_SECONDS, NOTE_GROW_FROM_SCALE, NOTE_GROW_SECONDS, NOTE_TICK_SECONDS, OVERLAY_EASES, getDropLetterTimes, PIN_DROP_SECONDS, PIN_DROP_SHARE, UNDERLINE_EM, UNDERLINE_SECONDS, getEntranceMotion, getExitMotion, getWipeHalves, } from "./overlay-motion.js";
|
|
7
|
-
import { NOTE_LINE_HEIGHT, OVERLAY_FONT_ROLES, OVERLAY_LINE_HEIGHT, OVERLAY_LIST_LINE_HEIGHT, OVERLAY_TITLE_LINE_HEIGHT, SEARCH_BAR_ICON_EM, SEARCH_BAR_PADDING_EM, estimateTextWidth, formatOverlayNumber, LIST_CHIP_COVERED_OPACITY, getChipCoveredTimes, getChipParts, getChipTickPoints, getDrawnOverlayCard, getListCardsByItem, getListItemTimes, getListStops, getNoteCentre, getNoteColors, getNotePaperPoints, getNoteTextBox, getNoteTickPoints, getNoteWordsByLine, getOverlayPadding, getPlaceCardPinRow, getPlaceCardPinSize, getSideTextLines, getTitleContentBox, } from "./overlays.js";
|
|
8
|
+
import { NOTE_LINE_HEIGHT, OVERLAY_FONT_ROLES, OVERLAY_LINE_HEIGHT, OVERLAY_LIST_LINE_HEIGHT, OVERLAY_LETTER_SPACING_EM, OVERLAY_TITLE_LINE_HEIGHT, SEARCH_BAR_ICON_EM, SEARCH_BAR_PADDING_EM, estimateTextWidth, formatOverlayNumber, LIST_CHIP_COVERED_OPACITY, getChipCoveredTimes, getChipParts, getChipTickPoints, COUNTER_UNIT_GAP_EM, getCounterCard, getDrawnOverlayCard, getKeywordMarkBlock, getSideTextLayout, KEYWORD_EDGE_EM, MARK_PADDING_EM, MARK_RADIUS_EM, getListCardsByItem, getListItemTimes, getListStops, getNoteCentre, getNoteColors, getNotePaperPoints, getNoteTextBox, getNoteTickPoints, getNoteWordsByLine, getOverlayPadding, getPlaceCardPinRow, getPlaceCardPinSize, getSideTextLines, getTitleContentBox, } from "./overlays.js";
|
|
8
9
|
/**
|
|
9
10
|
* The draft's overlays as ASS (issue #1200): the same places and times as the render, simplified. Text overlays are
|
|
10
11
|
* drawn rounded cards of the brand's background, fitted to their text, with the text in its foreground; an
|
|
@@ -103,6 +104,8 @@ export function getGlassDrawing(at, size) {
|
|
|
103
104
|
const handle = `m ${p(15 - half, 15 + half)} l ${p(15 + half, 15 - half)} ${p(21 + half, 21 - half)} ${p(21 - half, 21 + half)}`;
|
|
104
105
|
return `${ring} ${handle}`;
|
|
105
106
|
}
|
|
107
|
+
/** A character that stands for a line break in an overlay's text until it is written as ASS (`\\N`): one character, as the space it replaces. */
|
|
108
|
+
const LINE_BREAK = "\uE000";
|
|
106
109
|
/**
|
|
107
110
|
* A card's corner in px: its own token, else the brand style's (a search bar stays a pill unless it names its own),
|
|
108
111
|
* else `own` (the kind's look before the style).
|
|
@@ -303,22 +306,21 @@ export function getDropText(text, times, eventStart) {
|
|
|
303
306
|
})
|
|
304
307
|
.join("");
|
|
305
308
|
}
|
|
306
|
-
/** A highlight mark's padding round its text and its corner, in font sizes (as the render's `.ov-mark`). */
|
|
307
|
-
const MARK_PADDING_EM = { x: 0.22, y: 0.04 };
|
|
308
|
-
const MARK_RADIUS_EM = 0.14;
|
|
309
309
|
/**
|
|
310
310
|
* A highlight backdrop's marks under one line of text (`style.backdrop` highlight): a tight rounded box in the card
|
|
311
311
|
* colour, its width the text shown so far (each typed letter widens it, as the render's box grows), anchored where
|
|
312
312
|
* the text is (`x` its left, middle or right edge, `top` its top).
|
|
313
313
|
*/
|
|
314
314
|
function getBackdropMarkEvents(input) {
|
|
315
|
-
const { fontSize, span } = input;
|
|
315
|
+
const { fontSize, span, measured } = input;
|
|
316
316
|
const pad = { x: fontSize * MARK_PADDING_EM.x, y: fontSize * MARK_PADDING_EM.y };
|
|
317
|
-
const
|
|
317
|
+
const content = measured === undefined ? fontSize * OVERLAY_LINE_HEIGHT : fontSize * (measured.contentArea.ascentEm + measured.contentArea.descentEm);
|
|
318
|
+
const height = content + 2 * pad.y;
|
|
319
|
+
const top = measured === undefined ? input.top - pad.y : input.top + (fontSize * measured.lineHeight - content) / 2 - pad.y;
|
|
318
320
|
const boxFor = (shown) => {
|
|
319
|
-
const width = estimateTextWidth(shown, fontSize) + 2 * pad.x;
|
|
321
|
+
const width = (measured === undefined ? estimateTextWidth(shown, fontSize) : measured.measure(shown)) + 2 * pad.x;
|
|
320
322
|
const left = input.align === "left" ? input.x - pad.x : input.align === "right" ? input.x + pad.x - width : input.x - width / 2;
|
|
321
|
-
return { left, top
|
|
323
|
+
return { left, top, width, height };
|
|
322
324
|
};
|
|
323
325
|
const clean = toAssText(input.text);
|
|
324
326
|
const steps = input.typing === null
|
|
@@ -357,32 +359,126 @@ function getUnderlineEvent(overlay, card, colour, motion) {
|
|
|
357
359
|
function getSideTextEvents(overlay, context) {
|
|
358
360
|
if (overlay.kind === "list")
|
|
359
361
|
return getListEvents(overlay, context);
|
|
362
|
+
if (context.layout !== undefined)
|
|
363
|
+
return getLaidOutSideTextEvents(overlay, context, context.layout);
|
|
360
364
|
const colors = getOverlayColors(overlay, context.brand);
|
|
361
365
|
const { fontSize, side } = overlay;
|
|
362
366
|
// A side text always has a card: only a punch_in has none.
|
|
363
367
|
const card = getDrawnOverlayCard(overlay);
|
|
364
368
|
const { x: padX, y: padY } = getOverlayPadding(overlay);
|
|
365
369
|
const isCentred = overlay.kind === "keyword" && overlay.isCentred === true;
|
|
366
|
-
const
|
|
367
|
-
|
|
370
|
+
const role = OVERLAY_FONT_ROLES[overlay.kind];
|
|
371
|
+
// The render's card wraps its text inside the box (`max-width: 100%`): the same breaks, by the font's own widths.
|
|
372
|
+
const wrapped = getWrappedText(overlay.text, overlay.box.width - 2 * padX, fontSize, (line, size) => context.measure(role, line, size, OVERLAY_LETTER_SPACING_EM.card));
|
|
373
|
+
// A wrapped card fills its box and its lines start at its left on either side, as the render's do (`text-align` start).
|
|
374
|
+
const isWrapped = wrapped.includes(LINE_BREAK);
|
|
375
|
+
const isRight = !isCentred && side === "right" && !isWrapped;
|
|
376
|
+
const x = isCentred ? card.left + card.width / 2 : isRight ? card.left + card.width - padX : (isWrapped ? overlay.box.left : card.left) + padX;
|
|
368
377
|
const isFoot = overlay.kind === "lower_third";
|
|
369
378
|
const y = isFoot ? card.top + card.height - padY : card.top + padY;
|
|
370
379
|
// \an: 7 top left, 8 top centre, 9 top right, 1 bottom left, 3 bottom right.
|
|
371
380
|
const align = isFoot ? (isRight ? 3 : 1) : isCentred ? 8 : isRight ? 9 : 7;
|
|
372
381
|
const motion = getDraftMotion(overlay, overlay.entrance === null || overlay.entrance === "type" ? "fade" : overlay.entrance, card, context);
|
|
373
382
|
const span = { start: overlay.start, end: overlay.end };
|
|
374
|
-
const tags = `\\an${align}\\fs${fontSize}${getTextTags(overlay, colors, context,
|
|
375
|
-
const text = (pos, steps, own = motion) => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, motion: own });
|
|
383
|
+
const tags = `\\an${align}\\fs${context.toAssSize(role, fontSize)}${context.spacing(OVERLAY_LETTER_SPACING_EM.card, fontSize)}${getTextTags(overlay, colors, context, role)}`;
|
|
384
|
+
const text = (pos, steps, own = motion) => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps: steps.map((step) => ({ ...step, text: step.text.replaceAll(LINE_BREAK, "\\N") })), motion: own });
|
|
376
385
|
const isMarked = overlay.kind === "keyword" && overlay.backdrop === "highlight";
|
|
377
386
|
const shape = isMarked
|
|
378
387
|
? getBackdropMarkEvents({ text: overlay.text, x, align: isCentred ? "center" : isRight ? "right" : "left", top: y, fontSize, colour: colors.background, motion, span, typing: overlay.typing })
|
|
379
388
|
: getCardShapeEvents(overlay, card, fontSize, colors, motion, context);
|
|
380
389
|
if (overlay.entrance === "drop")
|
|
381
|
-
return [...shape, ...text({ x, y }, [{ from: span.start, to: span.end, text: getDropText(
|
|
390
|
+
return [...shape, ...text({ x, y }, [{ from: span.start, to: span.end, text: getDropText(wrapped, getDropLetterTimes(span.start, overlay.text), span.start) }], getPlainMotion(motion))];
|
|
382
391
|
// A keyword or a lower third types in only when its entrance says so.
|
|
383
|
-
const steps = overlay.entrance === null ? [{ from: span.start, to: span.end, text: toAssText(
|
|
392
|
+
const steps = overlay.entrance === null ? [{ from: span.start, to: span.end, text: toAssText(wrapped) }] : getTypedSteps(wrapped, span, overlay.typing, isCentred);
|
|
384
393
|
return [...shape, ...text({ x, y }, steps), ...(overlay.kind === "keyword" ? getUnderlineEvent(overlay, card, colors.accent, motion) : [])];
|
|
385
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* A highlighted keyword's mark as the render draws it (`getKeywordMarkBlock`): one rounded block round its lines;
|
|
397
|
+
* while it types, the block of the letters typed so far, on the lines they take in the whole text.
|
|
398
|
+
*/
|
|
399
|
+
function getBlockMarkEvents(input) {
|
|
400
|
+
const { overlay, layout } = input;
|
|
401
|
+
const { fontSize } = overlay;
|
|
402
|
+
const blockFor = (lines) => getKeywordMarkBlock(overlay, layout, lines, input.measure);
|
|
403
|
+
const span = { start: overlay.start, end: overlay.end };
|
|
404
|
+
const text = layout.lines.join(" ");
|
|
405
|
+
const steps = overlay.typing === null || overlay.entrance === null || overlay.entrance === "drop"
|
|
406
|
+
? [{ from: span.start, to: span.end, lines: layout.lines }]
|
|
407
|
+
: getTypingTimes(span.start, text, overlay.typing).map((at, index, times) => {
|
|
408
|
+
// The typed letters stay on the lines they take in the whole text.
|
|
409
|
+
let left = index + 1;
|
|
410
|
+
const lines = layout.lines.map((line) => {
|
|
411
|
+
const shown = [...line].slice(0, Math.max(0, left)).join("").trimEnd();
|
|
412
|
+
left -= [...line].length + 1;
|
|
413
|
+
return shown;
|
|
414
|
+
});
|
|
415
|
+
return { from: Math.min(at, span.end), to: Math.min(times[index + 1] ?? span.end, span.end), lines: lines.filter((line) => line.length > 0) };
|
|
416
|
+
});
|
|
417
|
+
const visible = steps.filter((step) => step.to > step.from && step.lines.length > 0);
|
|
418
|
+
return visible.map((step, index) => getShapeEvent({ start: step.from, end: step.to }, getRoundedRectDrawing(blockFor(step.lines), fontSize * MARK_RADIUS_EM), input.colour, input.motion, 3, {
|
|
419
|
+
start: step.from,
|
|
420
|
+
end: step.to,
|
|
421
|
+
isFirst: index === 0,
|
|
422
|
+
isLast: index === visible.length - 1,
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* A keyword or a lower third laid out as the render lays it out (`getSideTextLayout`): its card as wide and tall as
|
|
427
|
+
* its lines (a keyword with its accent edge, a lower third with its dot), each line its own event one CSS line apart,
|
|
428
|
+
* so libass's own line pitch does not stretch them; a highlighted keyword has one mark per line.
|
|
429
|
+
*/
|
|
430
|
+
function getLaidOutSideTextEvents(overlay, context, measure) {
|
|
431
|
+
const colors = getOverlayColors(overlay, context.brand);
|
|
432
|
+
const { fontSize } = overlay;
|
|
433
|
+
const layout = getSideTextLayout(overlay, measure);
|
|
434
|
+
const { card } = layout;
|
|
435
|
+
const role = OVERLAY_FONT_ROLES[overlay.kind];
|
|
436
|
+
const isCentred = overlay.kind === "keyword" && overlay.isCentred === true;
|
|
437
|
+
const isMarked = overlay.kind === "keyword" && overlay.backdrop === "highlight";
|
|
438
|
+
const motion = getDraftMotion(overlay, overlay.entrance === null || overlay.entrance === "type" ? "fade" : overlay.entrance, card, context);
|
|
439
|
+
const span = { start: overlay.start, end: overlay.end };
|
|
440
|
+
const lineHeight = fontSize * OVERLAY_LINE_HEIGHT;
|
|
441
|
+
const tags = `\\an${isCentred ? 8 : 7}\\fs${context.toAssSize(role, fontSize)}${context.spacing(OVERLAY_LETTER_SPACING_EM.card, fontSize)}${getTextTags(overlay, colors, context, role)}`;
|
|
442
|
+
const edge = overlay.kind === "keyword" && !isMarked ? Math.round(fontSize * KEYWORD_EDGE_EM) : 0;
|
|
443
|
+
const shapes = [];
|
|
444
|
+
if (isMarked) {
|
|
445
|
+
// The render's highlighted keyword is one block (a flex item): one mark round all its lines, growing as it types.
|
|
446
|
+
shapes.push(...getBlockMarkEvents({ overlay, layout, measure, colour: colors.background, motion }));
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
const fill = getCardShapeEvents(overlay, { ...card, height: card.height - edge }, fontSize, colors, motion, context);
|
|
450
|
+
// The keyword's accent edge: the whole card in the accent under its fill, which leaves the edge's height at its foot.
|
|
451
|
+
const radius = getDraftCardRadius(overlay, card, context, getOwnCardRadius(overlay, card, fontSize));
|
|
452
|
+
const edgeEvents = edge === 0 || (overlay.kind === "keyword" && overlay.underline === true) ? [] : [getShapeEvent(overlay, getRoundedRectDrawing(card, radius), colors.accent, motion)];
|
|
453
|
+
const under = context.style?.shadow === "soft" ? 1 : 0;
|
|
454
|
+
shapes.push(...fill.slice(0, under), ...edgeEvents, ...fill.slice(under));
|
|
455
|
+
}
|
|
456
|
+
if (layout.dot !== null) {
|
|
457
|
+
// The dot settles in with the card (the render scales it in a little later; the draft shows it with its card).
|
|
458
|
+
shapes.push(getShapeEvent(overlay, getCircleDrawing(layout.dot.centre, layout.dot.radius), colors.accent, motion, 4));
|
|
459
|
+
}
|
|
460
|
+
const text = layout.lines.join(" ");
|
|
461
|
+
const letters = overlay.entrance === "drop" ? getDropLetterTimes(span.start, text) : [];
|
|
462
|
+
const isTyped = overlay.entrance !== null && overlay.entrance !== "drop" && overlay.typing !== null;
|
|
463
|
+
let typedBefore = 0;
|
|
464
|
+
const lines = layout.lines.flatMap((line, index) => {
|
|
465
|
+
const pos = { x: layout.textX, y: layout.textTop + index * lineHeight };
|
|
466
|
+
const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
|
|
467
|
+
const count = [...line].length;
|
|
468
|
+
const steps = overlay.entrance === "drop"
|
|
469
|
+
? [{ from: span.start, to: span.end, text: getDropText(line, letters.slice(typedBefore, typedBefore + count), span.start) }]
|
|
470
|
+
: isTyped
|
|
471
|
+
? getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, isCentred)
|
|
472
|
+
: [{ from: span.start, to: span.end, text: toAssText(line) }];
|
|
473
|
+
typedBefore += count + 1;
|
|
474
|
+
// A left line holds its place transparent from the start, so its first event carries the entrance.
|
|
475
|
+
const held = isTyped && !isCentred ? steps.map((step, at) => (at === 0 ? { ...step, from: span.start } : step)) : steps;
|
|
476
|
+
const own = overlay.entrance === "drop" || (isTyped && isCentred) ? getPlainMotion(motion) : motion;
|
|
477
|
+
return getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps: held, motion: own });
|
|
478
|
+
});
|
|
479
|
+
const underline = overlay.kind === "keyword" ? getUnderlineEvent(overlay, { ...card, height: card.height - edge }, colors.accent, motion) : [];
|
|
480
|
+
return [...shapes, ...lines, ...underline];
|
|
481
|
+
}
|
|
386
482
|
/** A list's card grows to its next point's size over these seconds, in this many steps along the render's ease. */
|
|
387
483
|
const LIST_GROW_SECONDS = 0.35;
|
|
388
484
|
const LIST_GROW_STEPS = 3;
|
|
@@ -434,7 +530,7 @@ function getListEvents(overlay, context) {
|
|
|
434
530
|
const name = overlay.entrance === null || overlay.entrance === "type" ? "fade" : overlay.entrance;
|
|
435
531
|
const textTags = getTextTags(overlay, colors, context, OVERLAY_FONT_ROLES.list);
|
|
436
532
|
const lines = getSideTextLines(overlay);
|
|
437
|
-
const write = (pos, align, steps, motion, clip = "") => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags: `\\an${align}\\fs${fontSize}${textTags}${clip}`, steps, motion });
|
|
533
|
+
const write = (pos, align, steps, motion, clip = "") => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags: `\\an${align}\\fs${context.toAssSize(OVERLAY_FONT_ROLES.list, fontSize)}${context.spacing(OVERLAY_LETTER_SPACING_EM.card, fontSize)}${textTags}${clip}`, steps, motion });
|
|
438
534
|
if (overlay.chips !== undefined) {
|
|
439
535
|
const covered = getChipCoveredTimes(overlay);
|
|
440
536
|
return overlay.chips.flatMap((_chip, index) => {
|
|
@@ -455,7 +551,7 @@ function getListEvents(overlay, context) {
|
|
|
455
551
|
return [
|
|
456
552
|
...getCardShapeEvents(overlay, place.box, fontSize, colors, motion, context, span),
|
|
457
553
|
...write({ x: parts.textX, y: place.box.top + pad.y }, 8, steps, motion),
|
|
458
|
-
...getChipBadgeEvents({ index, span, until, parts, colors, motion }),
|
|
554
|
+
...getChipBadgeEvents({ index, span, until, parts, colors, motion, toAssSize: (cssPx) => context.toAssSize("body", cssPx) }),
|
|
459
555
|
];
|
|
460
556
|
});
|
|
461
557
|
});
|
|
@@ -504,7 +600,7 @@ function getChipBadgeEvents(input) {
|
|
|
504
600
|
layer: 6,
|
|
505
601
|
style: "OverlayPlain",
|
|
506
602
|
pos: centre,
|
|
507
|
-
tags: `\\an5\\fs${numberSize}\\b1\\1c${toTagColor(colors.background)}`,
|
|
603
|
+
tags: `\\an5\\fs${input.toAssSize(numberSize)}\\b1\\1c${toTagColor(colors.background)}`,
|
|
508
604
|
steps: [{ from: span.start, to: numberEnd, text: String(input.index + 1) }],
|
|
509
605
|
motion: numberEnd === span.end ? motion : { ...motion, exit: { ...motion.exit, kind: "none" } },
|
|
510
606
|
})
|
|
@@ -580,11 +676,15 @@ function getCardEvents(overlay, context) {
|
|
|
580
676
|
const motion = getDraftMotion(overlay, name, box, context);
|
|
581
677
|
const span = { start: overlay.start, end: overlay.end };
|
|
582
678
|
const isMarked = overlay.kind === "hook_title" && overlay.backdrop === "highlight";
|
|
583
|
-
|
|
679
|
+
// A laid-out counter draws its card with each number it shows (below), as the render's card follows its text.
|
|
680
|
+
const isCounterLaidOut = overlay.kind === "counter" && context.layout !== undefined;
|
|
681
|
+
const events = isMarked || isCounterLaidOut ? [] : getCardShapeEvents(overlay, box, fontSize, colors, motion, context);
|
|
584
682
|
const { x: padX, y: padY } = getOverlayPadding(overlay);
|
|
585
683
|
const centerX = box.left + box.width / 2;
|
|
586
684
|
const tagsFor = (role) => getTextTags(overlay, colors, context, role);
|
|
587
|
-
|
|
685
|
+
// The render spaces a title's heading lines tighter than the rest of a card's text, and a search query not at all.
|
|
686
|
+
const spacingFor = (role) => overlay.kind === "search_bar" ? 0 : role !== "heading" ? OVERLAY_LETTER_SPACING_EM.card : overlay.kind === "hook_title" ? OVERLAY_LETTER_SPACING_EM.hookTitle : overlay.kind === "place_card" ? OVERLAY_LETTER_SPACING_EM.placeTitle : OVERLAY_LETTER_SPACING_EM.card;
|
|
687
|
+
const text = (pos, align, size, role, steps, own = motion) => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags: `\\an${align}\\fs${context.toAssSize(role, r0(size))}${context.spacing(spacingFor(role), r0(size))}${tagsFor(role)}`, steps, motion: own });
|
|
588
688
|
const plain = { ...motion, name: "none", entrance: { kind: "none" } };
|
|
589
689
|
if (overlay.kind === "hook_title" || overlay.kind === "place_card") {
|
|
590
690
|
// The text block sits in the card's middle; centred lines on its axis, left ones from its left edge (RV-131).
|
|
@@ -617,13 +717,19 @@ function getCardEvents(overlay, context) {
|
|
|
617
717
|
const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
|
|
618
718
|
if (isMarked) {
|
|
619
719
|
const align = isLeft ? "left" : "center";
|
|
620
|
-
|
|
720
|
+
const { layout } = context;
|
|
721
|
+
const measured = layout === undefined
|
|
722
|
+
? {}
|
|
723
|
+
: { measured: { measure: (shown) => layout("heading", shown, fontSize, spacingFor("heading")), contentArea: context.contentArea("heading"), lineHeight } };
|
|
724
|
+
events.push(...getBackdropMarkEvents({ text: line, x: lineX, align, top: y, fontSize, colour: colors.background, motion, span, typing: overlay.typing, typeFrom: lineStart, ...measured }));
|
|
621
725
|
}
|
|
622
726
|
const steps = overlay.entrance === "drop"
|
|
623
727
|
? [{ from: span.start, to: span.end, text: getDropText(line, letters.slice(typedBefore, typedBefore + [...line].length), span.start) }]
|
|
624
728
|
: getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
|
|
625
729
|
const isQuiet = overlay.entrance === "drop" || (!isLeft && overlay.typing !== null);
|
|
626
|
-
|
|
730
|
+
// A left mark's padding pushes its text in, as an inline box's padding does in the render.
|
|
731
|
+
const textX = isMarked && isLeft && context.layout !== undefined ? lineX + fontSize * MARK_PADDING_EM.x : lineX;
|
|
732
|
+
events.push(...text({ x: textX, y }, lineAlign, fontSize, "heading", isLeft && overlay.entrance !== "drop" ? steps.map((step, index) => (index === 0 ? { ...step, from: span.start } : step)) : steps, isQuiet ? plain : motion));
|
|
627
733
|
typedBefore += [...line].length;
|
|
628
734
|
y += fontSize * lineHeight;
|
|
629
735
|
});
|
|
@@ -658,7 +764,10 @@ function getCardEvents(overlay, context) {
|
|
|
658
764
|
return events;
|
|
659
765
|
}
|
|
660
766
|
if (overlay.kind === "counter") {
|
|
661
|
-
|
|
767
|
+
// Laid out, the unit stands the render's gap after the number: a hard space widened to it.
|
|
768
|
+
const gap = context.layout === undefined ? null : toDraftSpacing(overlay.fontSize * COUNTER_UNIT_GAP_EM - context.layout("heading", " ", overlay.unitFontSize, 0), 1);
|
|
769
|
+
const space = gap === null ? " " : `{\\fsp${String(gap)}}\\h{\\fsp${String(toDraftSpacing(OVERLAY_LETTER_SPACING_EM.card, fontSize))}}`;
|
|
770
|
+
const unit = overlay.unit === null ? "" : `{\\fs${context.toAssSize("heading", overlay.unitFontSize)}}${space}${toAssText(overlay.unit)}`;
|
|
662
771
|
const count = getCounterSeconds(overlay);
|
|
663
772
|
const steps = [];
|
|
664
773
|
const ticks = Math.max(1, Math.round(count.duration / COUNT_STEP));
|
|
@@ -671,7 +780,30 @@ function getCardEvents(overlay, context) {
|
|
|
671
780
|
const value = overlay.from + (overlay.value - overlay.from) * eased;
|
|
672
781
|
steps.push({ from: count.start + (tick - 1) * COUNT_STEP, to: tick === ticks ? span.end : count.start + tick * COUNT_STEP, text: show(value) });
|
|
673
782
|
}
|
|
674
|
-
|
|
783
|
+
const shown = steps.filter((step) => step.to > step.from);
|
|
784
|
+
const { layout } = context;
|
|
785
|
+
if (layout === undefined)
|
|
786
|
+
return [...events, ...text({ x: centerX, y: box.top + box.height / 2 }, 5, fontSize, "heading", shown)];
|
|
787
|
+
// The render's card follows its number: one card per width the count shows, the entrance on the first, the exit on the last.
|
|
788
|
+
const cardFor = (value) => getCounterCard(overlay, value, layout);
|
|
789
|
+
// The number alone: the unit's override tags start at the first brace.
|
|
790
|
+
const values = shown.map((step) => {
|
|
791
|
+
const brace = step.text.indexOf("{");
|
|
792
|
+
return brace === -1 ? step.text : step.text.slice(0, brace);
|
|
793
|
+
});
|
|
794
|
+
const runs = [];
|
|
795
|
+
shown.forEach((step, index) => {
|
|
796
|
+
const card = cardFor(values[index]);
|
|
797
|
+
const last = runs[runs.length - 1];
|
|
798
|
+
if (last !== undefined && last.card.width === card.width)
|
|
799
|
+
last.to = step.to;
|
|
800
|
+
else
|
|
801
|
+
runs.push({ card, from: step.from, to: step.to });
|
|
802
|
+
});
|
|
803
|
+
const final = runs[runs.length - 1]?.card ?? cardFor(formatOverlayNumber(overlay.value, overlay.decimals, context.locale));
|
|
804
|
+
const counted = { ...motion, card: final };
|
|
805
|
+
const cards = runs.flatMap((run, index) => getCardShapeEvents(overlay, run.card, fontSize, colors, counted, context, { start: run.from, end: run.to, isFirst: index === 0, isLast: index === runs.length - 1 }));
|
|
806
|
+
return [...cards, ...text({ x: centerX, y: final.top + final.height / 2 }, 5, fontSize, "heading", shown, counted)];
|
|
675
807
|
}
|
|
676
808
|
const isRight = overlay.side === "right";
|
|
677
809
|
const x = isRight ? box.left + box.width - padX : box.left + padX;
|
|
@@ -762,8 +894,8 @@ function getNoteEvents(overlay, context) {
|
|
|
762
894
|
const font = isStrip ? `${context.fonts.heading === undefined ? "" : `\\fn${context.fonts.heading}`}\\b1` : `\\fn${HAND_FONT.family}\\b0`;
|
|
763
895
|
const textMotion = getPlainMotion(motion);
|
|
764
896
|
// libass sizes the hand font by its ascent and descent: its \\fs is scaled so the letters match the render's.
|
|
765
|
-
const assSize = isStrip ? overlay.fontSize : getHandFontAssSize(overlay.fontSize);
|
|
766
|
-
const tags = `\\an7\\fs${assSize}${font}\\1c${toTagColor(colors.ink)}${turn}`;
|
|
897
|
+
const assSize = isStrip ? context.toAssSize("heading", overlay.fontSize) : getHandFontAssSize(overlay.fontSize);
|
|
898
|
+
const tags = `\\an7\\fs${assSize}${isStrip ? context.spacing(OVERLAY_LETTER_SPACING_EM.strip, overlay.fontSize) : ""}${font}\\1c${toTagColor(colors.ink)}${turn}`;
|
|
767
899
|
getNoteWordsByLine(overlay).forEach((words, index) => {
|
|
768
900
|
const pos = { x: textBox.left, y: textBox.top + index * lineHeight };
|
|
769
901
|
const line = overlay.lines[index];
|
|
@@ -805,12 +937,34 @@ function getEndWordEvents(overlay, context) {
|
|
|
805
937
|
}
|
|
806
938
|
return getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps: [{ from: span.start, to: span.end, text: toAssText(overlay.text) }], motion });
|
|
807
939
|
}
|
|
940
|
+
/**
|
|
941
|
+
* `text` with the spaces it breaks at turned into `LINE_BREAK`, greedily as a browser breaks a line that does not fit
|
|
942
|
+
* `width` (a word wider than a line stands alone); the text as it is when it fits on one line.
|
|
943
|
+
*/
|
|
944
|
+
function getWrappedText(text, width, fontSize, measure) {
|
|
945
|
+
const words = text.replace(/\s+/g, " ").trim().split(" ");
|
|
946
|
+
return wrapDraftLine(words, width, fontSize, measure)
|
|
947
|
+
.map((line) => line.join(" "))
|
|
948
|
+
.join(LINE_BREAK);
|
|
949
|
+
}
|
|
808
950
|
/**
|
|
809
951
|
* The overlays as ASS events, layers 3 and 4. `fonts` names the heading and interface families where they are not the
|
|
810
952
|
* styles' own (the captions' font); `locale` groups a counter's number as the render does.
|
|
811
953
|
*/
|
|
812
954
|
export function buildDraftOverlayEvents(overlays, colors, frame, options = {}) {
|
|
813
|
-
const
|
|
955
|
+
const drawn = options.drawnFonts;
|
|
956
|
+
const context = {
|
|
957
|
+
brand: colors,
|
|
958
|
+
scale: frame.width / 1080,
|
|
959
|
+
locale: options.locale ?? "en-US",
|
|
960
|
+
fonts: options.fonts ?? {},
|
|
961
|
+
toAssSize: (role, cssPx) => (drawn === undefined ? cssPx : toDraftAssSize(cssPx, drawn[role].assScale)),
|
|
962
|
+
measure: (role, text, cssPx, spacingEm) => (drawn === undefined ? estimateTextWidth(text, cssPx) : drawn[role].measure(text, cssPx) + getSpacingWidth(text, spacingEm, cssPx)),
|
|
963
|
+
spacing: (spacingEm, cssPx) => (drawn === undefined || spacingEm === 0 ? "" : `\\fsp${String(toDraftSpacing(spacingEm, cssPx))}`),
|
|
964
|
+
contentArea: (role) => drawn?.[role].contentArea ?? DEFAULT_CONTENT_AREA,
|
|
965
|
+
...(options.style === undefined ? {} : { style: options.style }),
|
|
966
|
+
...(drawn === undefined ? {} : { layout: (role, text, cssPx, spacingEm) => drawn[role].measure(text, cssPx) + getSpacingWidth(text, spacingEm, cssPx) }),
|
|
967
|
+
};
|
|
814
968
|
return overlays.flatMap((overlay) => {
|
|
815
969
|
if (overlay.kind === "punch_in")
|
|
816
970
|
return [];
|