@softure-ai/marketing-kit 0.42.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 +18 -0
- package/README.md +5 -0
- package/dist/footage/draft-overlays.d.ts +11 -1
- package/dist/footage/draft-overlays.d.ts.map +1 -1
- package/dist/footage/draft-overlays.js +138 -14
- package/dist/footage/draft-overlays.js.map +1 -1
- package/dist/footage/draft-text-width.d.ts +13 -0
- package/dist/footage/draft-text-width.d.ts.map +1 -1
- package/dist/footage/draft-text-width.js +12 -1
- package/dist/footage/draft-text-width.js.map +1 -1
- package/dist/footage/draft.d.ts +7 -1
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +9 -1
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/overlays.d.ts +64 -2
- package/dist/footage/overlays.d.ts.map +1 -1
- package/dist/footage/overlays.js +110 -2
- package/dist/footage/overlays.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/package.json +1 -1
- package/src/footage/draft-overlays.ts +167 -14
- package/src/footage/draft-text-width.ts +22 -1
- package/src/footage/draft.ts +11 -2
- package/src/footage/overlays.ts +130 -2
- package/src/index.ts +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,24 @@ Newest first. Each version lists what changed for an app that uses `@softure-ai/
|
|
|
4
4
|
production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
|
|
5
5
|
"Definition of done"). Versions before the first one below are described in their GitHub Releases (`marketing-kit@x.y.z`).
|
|
6
6
|
|
|
7
|
+
## 0.43.0
|
|
8
|
+
|
|
9
|
+
- **The draft draws every overlay card in the render's size and shape:** with the draft's fonts, a keyword's and a
|
|
10
|
+
lower third's card is laid out as the render's CSS lays it out (`getSideTextLayout`): its text broken inside the
|
|
11
|
+
box, the card as wide as its widest line (the whole box once it wraps) and as tall as its lines plus padding, a
|
|
12
|
+
keyword's `.12em` accent edge under it, a lower third's accent dot before its text; each line is its own event one
|
|
13
|
+
CSS line (1.15 em) below the last, so libass's own line pitch no longer stretches them. A counter's card fits its
|
|
14
|
+
number, the `.3em` gap and its unit (`getCounterCard`) and follows the number while it counts. A highlighted hook
|
|
15
|
+
title's marks hug each line's text and its font's content area (`DraftFont.contentArea`, from `hhea`, or the typo
|
|
16
|
+
metrics with `USE_TYPO_METRICS`); a highlighted keyword's mark is one block round all its lines
|
|
17
|
+
(`getKeywordMarkBlock`), as the render's flex item is. Without `fonts` the draft draws the estimated cards as before.
|
|
18
|
+
- **The card an app reports is the render's:** `getDrawnOverlayCard(overlay, measure)` with
|
|
19
|
+
`createOverlayTextMeasure(loadFootageDraftFonts(brand.fonts))` answers the laid-out card of a keyword, a lower third
|
|
20
|
+
and a counter (at its final value), and where a highlight's marks show. Without a measure it answers as before.
|
|
21
|
+
- A regression test draws a fixture cut (highlighted hook title and keyword with a wipe, wrapping keyword card, lower
|
|
22
|
+
third, place cards `size: s` and `subtitle_size: m`, counter) in Chromium and through libass: every card and mark
|
|
23
|
+
within 1 % of the frame, the text on as many lines, and the reported card within 1 % of the render's.
|
|
24
|
+
|
|
7
25
|
## 0.42.0
|
|
8
26
|
|
|
9
27
|
- **The draft draws every text at the render's size:** libass sizes a font by `usWinAscent + usWinDescent`, a
|
package/README.md
CHANGED
|
@@ -1360,6 +1360,11 @@ What the draft matches and what it leaves out:
|
|
|
1360
1360
|
third's that is wider than its box (the render's card wraps it). An app that draws its own scenes with
|
|
1361
1361
|
`buildFootageDraftCaptions` (a preset preview) passes the same `fonts` set; without it, the sizes go to libass
|
|
1362
1362
|
unconverted, as before.
|
|
1363
|
+
- **Cards in the render's shape** (0.43.0): with `fonts`, the draft lays a keyword's, a lower third's and a counter's
|
|
1364
|
+
card out as the render does (`getSideTextLayout`, `getCounterCard`: wrapped lines one CSS line apart, a keyword's
|
|
1365
|
+
accent edge, a lower third's dot, a counter's card following its number) and sizes highlight marks to the text
|
|
1366
|
+
(`getKeywordMarkBlock`, a hook title's marks to each line and its font's `contentArea`). An app reports the same
|
|
1367
|
+
cards with `getDrawnOverlayCard(overlay, createOverlayTextMeasure(fonts))`.
|
|
1363
1368
|
- **Music without spending** (`cacheDir`, `providers`, as `renderFootage` takes them): a `file` source plays as is;
|
|
1364
1369
|
a `prompt` or `video` source plays only when its paid cache entry exists (`findFootageMusic`, the render's lookup).
|
|
1365
1370
|
It is ducked under the speech, looped and faded to the cut's length exactly as in the render. No provider is ever
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type BrandStyle, type CornerRadius } from "./brand-style.js";
|
|
2
2
|
import { type DraftFont } from "./draft-text-width.js";
|
|
3
3
|
import { type OverlayColors } from "./overlay-html.js";
|
|
4
|
-
import { type OverlayFontRole, type OverlayPoint, type ResolvedOverlay } from "./overlays.js";
|
|
4
|
+
import { type OverlayFontRole, type OverlayPoint, type OverlayTextMeasure, type ResolvedOverlay } from "./overlays.js";
|
|
5
5
|
/** The two styles the overlays use: `OverlayShape` (drawings: cards, marks, pins) and `OverlayPlain` (text over them). */
|
|
6
6
|
export declare function getDraftOverlayStyles(family: string, colors: OverlayColors): string[];
|
|
7
7
|
/** A straight arrow from `from` to `to` as an ASS drawing: the shaft's quad and the head's triangle. */
|
|
@@ -33,6 +33,16 @@ interface DraftContext {
|
|
|
33
33
|
spacing: (spacingEm: number, cssPx: number) => string;
|
|
34
34
|
/** The brand's style: the cards' radius, shadow and border; absent: each kind's own corner, no shadow, no border. */
|
|
35
35
|
style?: BrandStyle;
|
|
36
|
+
/**
|
|
37
|
+
* With the draft's fonts: the render's measure, so side texts, counters and highlight marks are laid out as the
|
|
38
|
+
* render lays them out (`getSideTextLayout`, `getCounterCard`); absent: the estimated cards of before.
|
|
39
|
+
*/
|
|
40
|
+
layout?: OverlayTextMeasure;
|
|
41
|
+
/** The content area (ascent, descent in ems) of the font of `role`, as a browser sizes an inline box. */
|
|
42
|
+
contentArea: (role: DraftFontRole) => {
|
|
43
|
+
ascentEm: number;
|
|
44
|
+
descentEm: number;
|
|
45
|
+
};
|
|
36
46
|
}
|
|
37
47
|
/**
|
|
38
48
|
* 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),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft-overlays.d.ts","sourceRoot":"","sources":["../../src/footage/draft-overlays.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGzF,OAAO,
|
|
1
|
+
{"version":3,"file":"draft-overlays.d.ts","sourceRoot":"","sources":["../../src/footage/draft-overlays.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,11 +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 { getSpacingWidth, toDraftAssSize, toDraftSpacing, wrapDraftLine } from "./draft-text-width.js";
|
|
4
|
+
import { DEFAULT_CONTENT_AREA, getSpacingWidth, toDraftAssSize, toDraftSpacing, wrapDraftLine } from "./draft-text-width.js";
|
|
5
5
|
import { HAND_FONT, getHandFontAssSize } from "./hand-font.js";
|
|
6
6
|
import { getCounterSeconds, getOverlayColors, getPlaceCardTimes, getTypingTimes } from "./overlay-html.js";
|
|
7
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";
|
|
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, 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";
|
|
9
9
|
/**
|
|
10
10
|
* The draft's overlays as ASS (issue #1200): the same places and times as the render, simplified. Text overlays are
|
|
11
11
|
* drawn rounded cards of the brand's background, fitted to their text, with the text in its foreground; an
|
|
@@ -306,22 +306,21 @@ export function getDropText(text, times, eventStart) {
|
|
|
306
306
|
})
|
|
307
307
|
.join("");
|
|
308
308
|
}
|
|
309
|
-
/** A highlight mark's padding round its text and its corner, in font sizes (as the render's `.ov-mark`). */
|
|
310
|
-
const MARK_PADDING_EM = { x: 0.22, y: 0.04 };
|
|
311
|
-
const MARK_RADIUS_EM = 0.14;
|
|
312
309
|
/**
|
|
313
310
|
* A highlight backdrop's marks under one line of text (`style.backdrop` highlight): a tight rounded box in the card
|
|
314
311
|
* colour, its width the text shown so far (each typed letter widens it, as the render's box grows), anchored where
|
|
315
312
|
* the text is (`x` its left, middle or right edge, `top` its top).
|
|
316
313
|
*/
|
|
317
314
|
function getBackdropMarkEvents(input) {
|
|
318
|
-
const { fontSize, span } = input;
|
|
315
|
+
const { fontSize, span, measured } = input;
|
|
319
316
|
const pad = { x: fontSize * MARK_PADDING_EM.x, y: fontSize * MARK_PADDING_EM.y };
|
|
320
|
-
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;
|
|
321
320
|
const boxFor = (shown) => {
|
|
322
|
-
const width = estimateTextWidth(shown, fontSize) + 2 * pad.x;
|
|
321
|
+
const width = (measured === undefined ? estimateTextWidth(shown, fontSize) : measured.measure(shown)) + 2 * pad.x;
|
|
323
322
|
const left = input.align === "left" ? input.x - pad.x : input.align === "right" ? input.x + pad.x - width : input.x - width / 2;
|
|
324
|
-
return { left, top
|
|
323
|
+
return { left, top, width, height };
|
|
325
324
|
};
|
|
326
325
|
const clean = toAssText(input.text);
|
|
327
326
|
const steps = input.typing === null
|
|
@@ -360,6 +359,8 @@ function getUnderlineEvent(overlay, card, colour, motion) {
|
|
|
360
359
|
function getSideTextEvents(overlay, context) {
|
|
361
360
|
if (overlay.kind === "list")
|
|
362
361
|
return getListEvents(overlay, context);
|
|
362
|
+
if (context.layout !== undefined)
|
|
363
|
+
return getLaidOutSideTextEvents(overlay, context, context.layout);
|
|
363
364
|
const colors = getOverlayColors(overlay, context.brand);
|
|
364
365
|
const { fontSize, side } = overlay;
|
|
365
366
|
// A side text always has a card: only a punch_in has none.
|
|
@@ -391,6 +392,93 @@ function getSideTextEvents(overlay, context) {
|
|
|
391
392
|
const steps = overlay.entrance === null ? [{ from: span.start, to: span.end, text: toAssText(wrapped) }] : getTypedSteps(wrapped, span, overlay.typing, isCentred);
|
|
392
393
|
return [...shape, ...text({ x, y }, steps), ...(overlay.kind === "keyword" ? getUnderlineEvent(overlay, card, colors.accent, motion) : [])];
|
|
393
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
|
+
}
|
|
394
482
|
/** A list's card grows to its next point's size over these seconds, in this many steps along the render's ease. */
|
|
395
483
|
const LIST_GROW_SECONDS = 0.35;
|
|
396
484
|
const LIST_GROW_STEPS = 3;
|
|
@@ -588,7 +676,9 @@ function getCardEvents(overlay, context) {
|
|
|
588
676
|
const motion = getDraftMotion(overlay, name, box, context);
|
|
589
677
|
const span = { start: overlay.start, end: overlay.end };
|
|
590
678
|
const isMarked = overlay.kind === "hook_title" && overlay.backdrop === "highlight";
|
|
591
|
-
|
|
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);
|
|
592
682
|
const { x: padX, y: padY } = getOverlayPadding(overlay);
|
|
593
683
|
const centerX = box.left + box.width / 2;
|
|
594
684
|
const tagsFor = (role) => getTextTags(overlay, colors, context, role);
|
|
@@ -627,13 +717,19 @@ function getCardEvents(overlay, context) {
|
|
|
627
717
|
const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
|
|
628
718
|
if (isMarked) {
|
|
629
719
|
const align = isLeft ? "left" : "center";
|
|
630
|
-
|
|
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 }));
|
|
631
725
|
}
|
|
632
726
|
const steps = overlay.entrance === "drop"
|
|
633
727
|
? [{ from: span.start, to: span.end, text: getDropText(line, letters.slice(typedBefore, typedBefore + [...line].length), span.start) }]
|
|
634
728
|
: getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
|
|
635
729
|
const isQuiet = overlay.entrance === "drop" || (!isLeft && overlay.typing !== null);
|
|
636
|
-
|
|
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));
|
|
637
733
|
typedBefore += [...line].length;
|
|
638
734
|
y += fontSize * lineHeight;
|
|
639
735
|
});
|
|
@@ -668,7 +764,10 @@ function getCardEvents(overlay, context) {
|
|
|
668
764
|
return events;
|
|
669
765
|
}
|
|
670
766
|
if (overlay.kind === "counter") {
|
|
671
|
-
|
|
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)}`;
|
|
672
771
|
const count = getCounterSeconds(overlay);
|
|
673
772
|
const steps = [];
|
|
674
773
|
const ticks = Math.max(1, Math.round(count.duration / COUNT_STEP));
|
|
@@ -681,7 +780,30 @@ function getCardEvents(overlay, context) {
|
|
|
681
780
|
const value = overlay.from + (overlay.value - overlay.from) * eased;
|
|
682
781
|
steps.push({ from: count.start + (tick - 1) * COUNT_STEP, to: tick === ticks ? span.end : count.start + tick * COUNT_STEP, text: show(value) });
|
|
683
782
|
}
|
|
684
|
-
|
|
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)];
|
|
685
807
|
}
|
|
686
808
|
const isRight = overlay.side === "right";
|
|
687
809
|
const x = isRight ? box.left + box.width - padX : box.left + padX;
|
|
@@ -839,7 +961,9 @@ export function buildDraftOverlayEvents(overlays, colors, frame, options = {}) {
|
|
|
839
961
|
toAssSize: (role, cssPx) => (drawn === undefined ? cssPx : toDraftAssSize(cssPx, drawn[role].assScale)),
|
|
840
962
|
measure: (role, text, cssPx, spacingEm) => (drawn === undefined ? estimateTextWidth(text, cssPx) : drawn[role].measure(text, cssPx) + getSpacingWidth(text, spacingEm, cssPx)),
|
|
841
963
|
spacing: (spacingEm, cssPx) => (drawn === undefined || spacingEm === 0 ? "" : `\\fsp${String(toDraftSpacing(spacingEm, cssPx))}`),
|
|
964
|
+
contentArea: (role) => drawn?.[role].contentArea ?? DEFAULT_CONTENT_AREA,
|
|
842
965
|
...(options.style === undefined ? {} : { style: options.style }),
|
|
966
|
+
...(drawn === undefined ? {} : { layout: (role, text, cssPx, spacingEm) => drawn[role].measure(text, cssPx) + getSpacingWidth(text, spacingEm, cssPx) }),
|
|
843
967
|
};
|
|
844
968
|
return overlays.flatMap((overlay) => {
|
|
845
969
|
if (overlay.kind === "punch_in")
|