@softure-ai/marketing-kit 0.21.2 → 0.22.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 +22 -0
- package/NOTICE +11 -0
- package/README.md +35 -4
- package/dist/config/actions-schema.d.ts +35 -35
- package/dist/config/brand.d.ts.map +1 -1
- package/dist/config/brand.js +22 -1
- package/dist/config/brand.js.map +1 -1
- package/dist/config/colors.d.ts +12 -2
- package/dist/config/colors.d.ts.map +1 -1
- package/dist/config/colors.js +32 -0
- package/dist/config/colors.js.map +1 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +2 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/schema.d.ts +181 -172
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +16 -4
- package/dist/config/schema.js.map +1 -1
- package/dist/config/shot-steps.d.ts +40 -40
- package/dist/footage/caption-highlight.d.ts +44 -0
- package/dist/footage/caption-highlight.d.ts.map +1 -0
- package/dist/footage/caption-highlight.js +29 -0
- package/dist/footage/caption-highlight.js.map +1 -0
- package/dist/footage/compose.d.ts +3 -0
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +33 -6
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/draft-color.d.ts +6 -0
- package/dist/footage/draft-color.d.ts.map +1 -0
- package/dist/footage/draft-color.js +14 -0
- package/dist/footage/draft-color.js.map +1 -0
- package/dist/footage/draft-overlays.d.ts +12 -0
- package/dist/footage/draft-overlays.d.ts.map +1 -0
- package/dist/footage/draft-overlays.js +83 -0
- package/dist/footage/draft-overlays.js.map +1 -0
- package/dist/footage/draft.d.ts +27 -9
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +99 -37
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/edl.d.ts +41 -0
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +10 -0
- package/dist/footage/edl.js.map +1 -1
- package/dist/footage/film.d.ts +14 -0
- package/dist/footage/film.d.ts.map +1 -1
- package/dist/footage/film.js +2 -0
- package/dist/footage/film.js.map +1 -1
- package/dist/footage/overlay-html.d.ts +29 -0
- package/dist/footage/overlay-html.d.ts.map +1 -0
- package/dist/footage/overlay-html.js +112 -0
- package/dist/footage/overlay-html.js.map +1 -0
- package/dist/footage/overlay-schema.d.ts +97 -0
- package/dist/footage/overlay-schema.d.ts.map +1 -0
- package/dist/footage/overlay-schema.js +104 -0
- package/dist/footage/overlay-schema.js.map +1 -0
- package/dist/footage/overlays.d.ts +112 -0
- package/dist/footage/overlays.d.ts.map +1 -0
- package/dist/footage/overlays.js +222 -0
- package/dist/footage/overlays.js.map +1 -0
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +10 -1
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/og/index.d.ts +1 -1
- package/dist/og/index.d.ts.map +1 -1
- package/dist/og/index.js +1 -1
- package/dist/og/index.js.map +1 -1
- package/dist/og/photo-cover.d.ts +18 -1
- package/dist/og/photo-cover.d.ts.map +1 -1
- package/dist/og/photo-cover.js +56 -28
- package/dist/og/photo-cover.js.map +1 -1
- package/dist/render/hyperframes.d.ts +1 -1
- package/dist/render/hyperframes.d.ts.map +1 -1
- package/dist/render/hyperframes.js +1 -1
- package/dist/render/hyperframes.js.map +1 -1
- package/package.json +3 -2
- package/schema/edl.schema.json +130 -0
- package/schema/marketing.schema.json +33 -0
- package/src/config/brand.ts +20 -1
- package/src/config/colors.ts +39 -2
- package/src/config/config.ts +2 -0
- package/src/config/schema.ts +19 -7
- package/src/footage/caption-highlight.ts +52 -0
- package/src/footage/compose.ts +40 -6
- package/src/footage/draft-color.ts +12 -0
- package/src/footage/draft-overlays.ts +91 -0
- package/src/footage/draft.ts +117 -39
- package/src/footage/edl.ts +17 -0
- package/src/footage/film.ts +16 -0
- package/src/footage/overlay-html.ts +127 -0
- package/src/footage/overlay-schema.ts +146 -0
- package/src/footage/overlays.ts +272 -0
- package/src/footage/pipeline.ts +8 -1
- package/src/index.ts +56 -1
- package/src/og/index.ts +2 -0
- package/src/og/photo-cover.ts +83 -33
- package/src/render/hyperframes.ts +1 -1
package/src/config/schema.ts
CHANGED
|
@@ -15,11 +15,11 @@ import {
|
|
|
15
15
|
import { bigNumberDataSchema, carouselDataSchema, headlineChartDataSchema, headlineCtaDataSchema } from "../og/templates/schemas.js";
|
|
16
16
|
import { CHANNEL_CODE_MAX_LENGTH, CHANNEL_CODE_PATTERN, DEFAULT_LINK_IN_BIO, PLATFORMS } from "../platforms.js";
|
|
17
17
|
import { DECLICK_LEVELS } from "../footage/declick.js";
|
|
18
|
-
import { CAPTION_PRESETS, CAPTION_STYLES, CLIP_FITS, CLIP_ROLES, CUT_TRANSITIONS, JUMP_TRANSITIONS } from "../footage/film.js";
|
|
18
|
+
import { CAPTION_HIGHLIGHT_STYLES, CAPTION_PRESETS, CAPTION_STYLES, CLIP_FITS, CLIP_ROLES, CUT_TRANSITIONS, JUMP_TRANSITIONS } from "../footage/film.js";
|
|
19
19
|
import { normalizeKeyTerms } from "../footage/keyterms.js";
|
|
20
20
|
import { ELEVENLABS_DEFAULT_MODEL } from "../voice/voiceover.js";
|
|
21
21
|
import { actionSchema, type SceneAction } from "./actions-schema.js";
|
|
22
|
-
import { COLOR_ROLES, COLOR_THEMES, isHexColor, type ColorRole } from "./colors.js";
|
|
22
|
+
import { COLOR_ROLES, COLOR_THEMES, OPTIONAL_COLOR_ROLES, isHexColor, type ColorRole, type OptionalColorRole } from "./colors.js";
|
|
23
23
|
import { DAY_PATTERN, isCalendarDay } from "./day.js";
|
|
24
24
|
import { getOgImageNames } from "./og-image-names.js";
|
|
25
25
|
import { findMalformedPlaceholder, findPlaceholders } from "./placeholders.js";
|
|
@@ -114,7 +114,7 @@ const fontSchema = z.strictObject({
|
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
/** What each colour role paints; the descriptions of `brand.colors` and `brand.tokensFrom.roles`. */
|
|
117
|
-
const COLOR_ROLE_DESCRIPTIONS: Record<ColorRole, string> = {
|
|
117
|
+
const COLOR_ROLE_DESCRIPTIONS: Record<ColorRole | OptionalColorRole, string> = {
|
|
118
118
|
background: "The frame behind the phone and the vignette; #rrggbb, because the vignette appends an alpha.",
|
|
119
119
|
foreground: "Text on the background: the persona card's name, the end card.",
|
|
120
120
|
muted: "Secondary text: the persona card's tagline, the end card's note.",
|
|
@@ -124,21 +124,23 @@ const COLOR_ROLE_DESCRIPTIONS: Record<ColorRole, string> = {
|
|
|
124
124
|
captionBackground: "The caption pill.",
|
|
125
125
|
captionText: "Caption words not spoken yet.",
|
|
126
126
|
captionHighlight: "The word being spoken.",
|
|
127
|
+
captionHighlightBox: 'The box behind the word being spoken, with captionHighlightStyle "box"; optional otherwise.',
|
|
128
|
+
captionHighlightText: 'The text of the word being spoken on its box, with captionHighlightStyle "box"; optional otherwise.',
|
|
127
129
|
};
|
|
128
130
|
|
|
129
131
|
const colorRolesShape = Object.fromEntries(
|
|
130
|
-
COLOR_ROLES.map((role) => [role, hexColor.optional().describe(`${COLOR_ROLE_DESCRIPTIONS[role]} A hex colour; without it, the colour comes from tokensFrom.`)]),
|
|
132
|
+
[...COLOR_ROLES, ...OPTIONAL_COLOR_ROLES].map((role) => [role, hexColor.optional().describe(`${COLOR_ROLE_DESCRIPTIONS[role]} A hex colour; without it, the colour comes from tokensFrom.`)]),
|
|
131
133
|
) as Record<
|
|
132
|
-
|
|
134
|
+
ColorRole | OptionalColorRole,
|
|
133
135
|
z.ZodOptional<typeof hexColor>
|
|
134
136
|
>;
|
|
135
137
|
|
|
136
138
|
const tokenName = z.string().regex(TOKEN_NAME_PATTERN, "must be a token name such as accent-fill");
|
|
137
139
|
|
|
138
140
|
const roleTokensShape = Object.fromEntries(
|
|
139
|
-
COLOR_ROLES.map((role) => [role, tokenName.optional().describe(`The source token for the ${role} role (${COLOR_ROLE_DESCRIPTIONS[role]}) Default: the role's name in kebab case.`)]),
|
|
141
|
+
[...COLOR_ROLES, ...OPTIONAL_COLOR_ROLES].map((role) => [role, tokenName.optional().describe(`The source token for the ${role} role (${COLOR_ROLE_DESCRIPTIONS[role]}) Default: the role's name in kebab case.`)]),
|
|
140
142
|
) as Record<
|
|
141
|
-
|
|
143
|
+
ColorRole | OptionalColorRole,
|
|
142
144
|
z.ZodOptional<typeof tokenName>
|
|
143
145
|
>;
|
|
144
146
|
|
|
@@ -581,6 +583,16 @@ const footageSchema = z
|
|
|
581
583
|
.enum(CAPTION_STYLES)
|
|
582
584
|
.default("phrase")
|
|
583
585
|
.describe("phrase (the default): 2-6 words of plain text with a soft shadow; highlight: a pill that lights each word as it is said."),
|
|
586
|
+
captionHighlightStyle: z
|
|
587
|
+
.enum(CAPTION_HIGHLIGHT_STYLES)
|
|
588
|
+
.default("text")
|
|
589
|
+
.describe('How a highlight caption lights the word being said: text (the default) colours it captionHighlight; box puts it on a rounded box of brand.colors.captionHighlightBox with its text in captionHighlightText (both then required).'),
|
|
590
|
+
overlayMinSpacing: z
|
|
591
|
+
.number()
|
|
592
|
+
.min(0)
|
|
593
|
+
.max(60)
|
|
594
|
+
.optional()
|
|
595
|
+
.describe("The least seconds between the starts of two EDL overlays (the app's budget, e.g. 8); without it, only one overlay at a time."),
|
|
584
596
|
captionPreset: z
|
|
585
597
|
.enum(CAPTION_PRESETS)
|
|
586
598
|
.optional()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getContrastRatio, type BrandColors } from "../config/colors.js";
|
|
2
|
+
import type { FootageFilm } from "./film.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* How a footage film's `highlight` captions light the word being said (issue #1199): its text in `captionHighlight`
|
|
6
|
+
* (`text`), or the word on a rounded box of `captionHighlightBox` with its text in `captionHighlightText` (`box`).
|
|
7
|
+
* The render and the draft both draw what this resolves.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type CaptionHighlightLook = { style: "text"; color: string } | { style: "box"; box: string; text: string };
|
|
11
|
+
|
|
12
|
+
export type CaptionHighlightResult = { ok: true; look: CaptionHighlightLook } | { ok: false; error: string };
|
|
13
|
+
|
|
14
|
+
/** The colours the look reads. */
|
|
15
|
+
export type CaptionHighlightColors = Pick<BrandColors, "captionHighlight" | "captionHighlightBox" | "captionHighlightText">;
|
|
16
|
+
|
|
17
|
+
/** How long a word stays lit from its start, in seconds (render and draft alike). */
|
|
18
|
+
export const CAPTION_HIGHLIGHT_SECONDS = 0.32;
|
|
19
|
+
|
|
20
|
+
/** The box's padding beside the lit word, in font sizes; above and below, the line's own height is the room. */
|
|
21
|
+
export const CAPTION_HIGHLIGHT_BOX_PADDING_EM = 0.15;
|
|
22
|
+
|
|
23
|
+
/** The box's corner radius, in px: a little over half the pill's 22 px, so the box nests in the pill's rounding. */
|
|
24
|
+
export const CAPTION_HIGHLIGHT_BOX_RADIUS = 12;
|
|
25
|
+
|
|
26
|
+
/** The film's highlight look, or an error naming the missing brand colours when it asks for a box without them. */
|
|
27
|
+
export function getCaptionHighlight(film: Pick<FootageFilm, "captionHighlightStyle">, colors: CaptionHighlightColors): CaptionHighlightResult {
|
|
28
|
+
if ((film.captionHighlightStyle ?? "text") === "text") return { ok: true, look: { style: "text", color: colors.captionHighlight } };
|
|
29
|
+
const { captionHighlightBox: box, captionHighlightText: text } = colors;
|
|
30
|
+
if (box === undefined || text === undefined) {
|
|
31
|
+
const missing = [box === undefined ? "captionHighlightBox" : null, text === undefined ? "captionHighlightText" : null].filter((role) => role !== null);
|
|
32
|
+
return { ok: false, error: `captionHighlightStyle "box" needs the brand colours ${missing.join(" and ")} (brand.colors or brand.tokensFrom).` };
|
|
33
|
+
}
|
|
34
|
+
return { ok: true, look: { style: "box", box, text } };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface CaptionHighlightContrast {
|
|
38
|
+
/** The lit word's text (`captionHighlightText`) against its box (`captionHighlightBox`). */
|
|
39
|
+
textOnBox: number;
|
|
40
|
+
/** The box (`captionHighlightBox`) against the pill (`captionBackground`). */
|
|
41
|
+
boxOnPill: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The WCAG contrast ratios of a `box` highlight, for the app to warn on (the kit never changes the colours): the lit
|
|
46
|
+
* text on its box, and the box on the pill. Null when either box colour is missing.
|
|
47
|
+
*/
|
|
48
|
+
export function getCaptionHighlightContrast(colors: Pick<BrandColors, "captionBackground" | "captionHighlightBox" | "captionHighlightText">): CaptionHighlightContrast | null {
|
|
49
|
+
const { captionHighlightBox: box, captionHighlightText: text } = colors;
|
|
50
|
+
if (box === undefined || text === undefined) return null;
|
|
51
|
+
return { textOnBox: getContrastRatio(text, box), boxOnPill: getContrastRatio(box, colors.captionBackground) };
|
|
52
|
+
}
|
package/src/footage/compose.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { ComposeFont } from "../compose/compose.js";
|
|
|
4
4
|
import { assertLocalReferences, escapeHtml, fontFaces, fontStack } from "../compose/html.js";
|
|
5
5
|
import { CAPTION_LINE_HEIGHT, getCaptionPillCss, getCaptionPositionCss, type CaptionLayout } from "../compose/timeline.js";
|
|
6
6
|
import type { TimedWord } from "../voice/voiceover.js";
|
|
7
|
+
import { CAPTION_HIGHLIGHT_BOX_PADDING_EM, CAPTION_HIGHLIGHT_BOX_RADIUS, CAPTION_HIGHLIGHT_SECONDS, getCaptionHighlight } from "./caption-highlight.js";
|
|
7
8
|
import { CAPTION_SAFE_ZONES, getCaptionChunkLayouts, getCaptionSpans, getFootageCaptionChunks, isSameCaptionPlace, type CaptionSpan } from "./captions.js";
|
|
8
9
|
import { getEdlDuration, getSegmentStarts, type Edl } from "./edl.js";
|
|
9
10
|
import {
|
|
@@ -18,6 +19,8 @@ import {
|
|
|
18
19
|
type LogoFootageEndCard,
|
|
19
20
|
} from "./film.js";
|
|
20
21
|
import { FOOTAGE_FPS } from "./normalize.js";
|
|
22
|
+
import { getOverlayMarkup } from "./overlay-html.js";
|
|
23
|
+
import type { ResolvedOverlay } from "./overlays.js";
|
|
21
24
|
|
|
22
25
|
const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
|
|
23
26
|
|
|
@@ -76,6 +79,8 @@ export interface FootageComposeInput {
|
|
|
76
79
|
assets: FootageComposeAssets;
|
|
77
80
|
brandName: string;
|
|
78
81
|
locale: string;
|
|
82
|
+
/** The EDL's overlays, resolved (`resolveEdlOverlays`); absent or empty: none, and the composition is as without them. */
|
|
83
|
+
overlays?: ResolvedOverlay[];
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
/** The film's length: the cut plus the end card (`getEndCardSeconds`). */
|
|
@@ -189,8 +194,26 @@ export function composeFootage(input: FootageComposeInput): string {
|
|
|
189
194
|
}
|
|
190
195
|
});
|
|
191
196
|
|
|
197
|
+
// --- Overlays: the punch-in zooms the segment's picture (eased in, held, eased back), the others are clips of their own ---
|
|
198
|
+
const overlays = input.overlays ?? [];
|
|
199
|
+
for (const overlay of overlays) {
|
|
200
|
+
if (overlay.kind !== "punch_in") continue;
|
|
201
|
+
const target = picture === undefined ? `#seg${overlay.segment}` : "#picture";
|
|
202
|
+
const base = scales[overlay.segment] as number;
|
|
203
|
+
const peak = r3(base * overlay.scale);
|
|
204
|
+
tweens.push(
|
|
205
|
+
`tl.fromTo("${target}", { scale: ${base} }, { scale: ${peak}, duration: ${overlay.ease}, ease: "sine.inOut", immediateRender: false }, ${overlay.start});`,
|
|
206
|
+
`tl.fromTo("${target}", { scale: ${peak} }, { scale: ${base}, duration: ${overlay.ease}, ease: "sine.inOut", immediateRender: false }, ${r3(overlay.end - overlay.ease)});`,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
192
210
|
// --- Captions: plain phrases, or the pill that lights each word ---
|
|
193
211
|
const isHighlight = film.captionStyle === "highlight";
|
|
212
|
+
const highlight = isHighlight ? getCaptionHighlight(film, c) : ({ ok: true, look: { style: "text", color: c.captionHighlight } } as const);
|
|
213
|
+
// The pipeline refuses such a film before it composes; reaching here is a bug.
|
|
214
|
+
if (!highlight.ok) throw new Error(`composeFootage: ${highlight.error}`);
|
|
215
|
+
const look = highlight.look;
|
|
216
|
+
const isBox = isHighlight && look.style === "box";
|
|
194
217
|
const caption = getFootageCaptionChunks(film, words);
|
|
195
218
|
const spans = getCaptionSpans(caption, cutEnd);
|
|
196
219
|
const boxes = getCaptionChunkLayouts(caption, edl, captionBox);
|
|
@@ -201,7 +224,7 @@ export function composeFootage(input: FootageComposeInput): string {
|
|
|
201
224
|
// A chunk in a segment's own box overrides the shared rule's anchor; one in the film's box is written as before.
|
|
202
225
|
const style = isSameCaptionPlace(place, captionBox) ? "" : ` style="${place.bottom === undefined ? `bottom:auto;top:${place.top}px` : `top:auto;bottom:${place.bottom}px`}"`;
|
|
203
226
|
const box = isHighlight
|
|
204
|
-
? `<p class="pill">${chunk.words.map((w, j) => `<span id="cw${i}_${j}">${escapeHtml(w.text)}</span>`).join(" ")}</p>`
|
|
227
|
+
? `<p class="pill">${chunk.words.map((w, j) => `<span id="cw${i}_${j}">${isBox ? `<i class="hl" id="cb${i}_${j}"></i>` : ""}${escapeHtml(w.text)}</span>`).join(" ")}</p>`
|
|
205
228
|
: `<p class="phrase">${escapeHtml(chunk.words.map((w) => w.text).join(" "))}</p>`;
|
|
206
229
|
return `<div id="cap${i}" class="clip caption" data-start="${start}" data-duration="${r3(stop - start)}"${style}>${box}</div>`;
|
|
207
230
|
})
|
|
@@ -254,6 +277,7 @@ export function composeFootage(input: FootageComposeInput): string {
|
|
|
254
277
|
const bodyFont = fontStack(fonts.body, "sans-serif");
|
|
255
278
|
const headingFont = fonts.heading === null ? bodyFont : fontStack(fonts.heading, "sans-serif");
|
|
256
279
|
const faces = [...fontFaces(fonts.body), ...fontFaces(fonts.heading)];
|
|
280
|
+
const overlayMarkup = getOverlayMarkup(overlays, { colors: c, headingFont, frame });
|
|
257
281
|
|
|
258
282
|
return assertLocalReferences(`<!doctype html>
|
|
259
283
|
<html lang="${escapeHtml(input.locale)}">
|
|
@@ -272,7 +296,10 @@ html,body{width:${frame.width}px;height:${frame.height}px;overflow:hidden;backgr
|
|
|
272
296
|
.caption{position:absolute;left:${captionBox.left}px;right:${captionBox.right}px;${getCaptionPositionCss(captionBox)};display:flex;justify-content:center}
|
|
273
297
|
.pill{${getCaptionPillCss(captionBox.fontSize)};border-radius:22px;background:${c.captionBackground};box-shadow:0 14px 44px rgba(0,0,0,.5);color:${c.captionText}}
|
|
274
298
|
.pill span{display:inline-block}
|
|
275
|
-
|
|
299
|
+
${isBox ? `.pill{position:relative;z-index:0}
|
|
300
|
+
.pill span{position:relative}
|
|
301
|
+
.hl{position:absolute;top:0;bottom:0;left:-${CAPTION_HIGHLIGHT_BOX_PADDING_EM}em;right:-${CAPTION_HIGHLIGHT_BOX_PADDING_EM}em;z-index:-1;border-radius:${CAPTION_HIGHLIGHT_BOX_RADIUS}px;background:${look.box};opacity:0}
|
|
302
|
+
` : ""}.phrase{font-weight:650;font-size:${captionBox.fontSize}px;line-height:${CAPTION_LINE_HEIGHT};letter-spacing:-.01em;text-align:center;color:#fff;text-shadow:0 2px 6px rgba(0,0,0,.55),0 0 18px rgba(0,0,0,.35)}
|
|
276
303
|
.endcard{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:center;align-items:center;padding:0 80px;text-align:center}
|
|
277
304
|
.brand{display:flex;justify-content:center;align-items:center;gap:18px;font-family:${headingFont};font-size:46px}
|
|
278
305
|
.logo{height:60px;width:auto}
|
|
@@ -285,13 +312,13 @@ html,body{width:${frame.width}px;height:${frame.height}px;overflow:hidden;backgr
|
|
|
285
312
|
.mark.vector{width:min(100%,${LOGO_CARD_MARK.width}px);height:${LOGO_CARD_MARK.height}px;object-fit:contain}
|
|
286
313
|
.markname{font-family:${headingFont};font-weight:600;font-size:96px;letter-spacing:-.02em}
|
|
287
314
|
.logoline{font-family:${headingFont};font-weight:600;font-size:${LOGO_CARD_LINE_SIZE}px;line-height:1.15;letter-spacing:-.01em}
|
|
288
|
-
</style>
|
|
315
|
+
${overlayMarkup.css.map((rule) => `${rule}\n`).join("")}</style>
|
|
289
316
|
</head>
|
|
290
317
|
<body>
|
|
291
318
|
<div id="root" data-composition-id="${COMPOSITION_ID}" data-start="0" data-duration="${end}" data-width="${frame.width}" data-height="${frame.height}">
|
|
292
319
|
${segments.join("\n ")}
|
|
293
320
|
${endCardHtml}
|
|
294
|
-
${captionHtml}
|
|
321
|
+
${overlayMarkup.html.map((element) => `${element}\n `).join("")}${captionHtml}
|
|
295
322
|
${audio}
|
|
296
323
|
</div>
|
|
297
324
|
${captionFit}<script>
|
|
@@ -300,9 +327,16 @@ ${tweens.join("\n")}
|
|
|
300
327
|
const captions = ${JSON.stringify(isHighlight ? caption.map((chunk) => chunk.words.map((w) => w.start)) : [])};
|
|
301
328
|
captions.forEach((words, i) => {
|
|
302
329
|
tl.fromTo("#cap" + i + " .pill", { y: 14, opacity: 0 }, { y: 0, opacity: 1, duration: 0.16, ease: "power3.out" }, Math.max(0, words[0] - 0.05));
|
|
303
|
-
|
|
330
|
+
${
|
|
331
|
+
look.style === "box"
|
|
332
|
+
? ` words.forEach((t, j) => {
|
|
333
|
+
tl.fromTo("#cb" + i + "_" + j, { opacity: 0 }, { opacity: 1, duration: 0.06, immediateRender: false }, t).to("#cb" + i + "_" + j, { opacity: 0, duration: 0.2 }, t + ${CAPTION_HIGHLIGHT_SECONDS});
|
|
334
|
+
tl.fromTo("#cw" + i + "_" + j, { color: "${c.captionText}" }, { color: "${look.text}", duration: 0.06, immediateRender: false }, t).to("#cw" + i + "_" + j, { color: "${c.captionText}", duration: 0.2 }, t + ${CAPTION_HIGHLIGHT_SECONDS});
|
|
335
|
+
});`
|
|
336
|
+
: ` words.forEach((t, j) => tl.fromTo("#cw" + i + "_" + j, { color: "${c.captionText}" }, { color: "${look.color}", duration: 0.06, immediateRender: false }, t).to("#cw" + i + "_" + j, { color: "${c.captionText}", duration: 0.2 }, t + 0.32));`
|
|
337
|
+
}
|
|
304
338
|
});
|
|
305
|
-
${endCardTweens.join("\n")}
|
|
339
|
+
${overlayMarkup.tweens.map((tween) => `${tween}\n`).join("")}${endCardTweens.join("\n")}
|
|
306
340
|
tl.set({}, {}, ${end});
|
|
307
341
|
window.__timelines = window.__timelines || {};
|
|
308
342
|
window.__timelines["${COMPOSITION_ID}"] = tl;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hex colour (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`) as an ASS colour, `&HAABBGGRR&`-style without the closing
|
|
3
|
+
* `&`: ASS writes blue first and counts alpha the other way round (00 is opaque).
|
|
4
|
+
*/
|
|
5
|
+
export function toAssColor(hex: string): string {
|
|
6
|
+
const digits = hex.replace(/^#/, "");
|
|
7
|
+
const full = digits.length <= 4 ? [...digits].map((digit) => digit + digit).join("") : digits;
|
|
8
|
+
if (!/^(?:[0-9a-f]{6}|[0-9a-f]{8})$/i.test(full)) throw new Error(`Not a hex colour: "${hex}".`);
|
|
9
|
+
const pair = (index: number): string => full.slice(index, index + 2).toUpperCase();
|
|
10
|
+
const alpha = full.length === 8 ? (255 - parseInt(full.slice(6, 8), 16)).toString(16).padStart(2, "0").toUpperCase() : "00";
|
|
11
|
+
return `&H${alpha}${pair(4)}${pair(2)}${pair(0)}`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { toAssColor } from "./draft-color.js";
|
|
2
|
+
import type { OverlayColors } from "./overlay-html.js";
|
|
3
|
+
import { OVERLAY_PADDING_EM, type OverlayPoint, type ResolvedOverlay } from "./overlays.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 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 arrow is a straight shaft
|
|
8
|
+
* and head in the accent; a highlight the accent's outline round its rectangle. A `punch_in` is drawn by the picture's
|
|
9
|
+
* zoom (`buildPictureFilters`), not here. They sit on layers 3 and up, over the captions' 0 to 2.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** 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
|
+
const STROKE_WIDTH = 10;
|
|
14
|
+
const ARROW_HEAD = 46;
|
|
15
|
+
const FADE = "\\fad(150,250)";
|
|
16
|
+
|
|
17
|
+
const r0 = (value: number): number => Math.round(value);
|
|
18
|
+
|
|
19
|
+
/** An ASS colour for an override tag (`&HBBGGRR&`). */
|
|
20
|
+
const toTagColor = (hex: string): string => `${toAssColor(hex).replace(/^&H../, "&H")}&`;
|
|
21
|
+
|
|
22
|
+
/** The two styles the overlays use: `Overlay` (text on an opaque card) and `OverlayShape` (drawings). */
|
|
23
|
+
export function getDraftOverlayStyles(family: string, colors: OverlayColors): string[] {
|
|
24
|
+
const card = toAssColor(colors.background);
|
|
25
|
+
const text = toAssColor(colors.foreground);
|
|
26
|
+
const accent = toAssColor(colors.accent);
|
|
27
|
+
return [
|
|
28
|
+
`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
|
+
`Style: OverlayShape,${family},48,${accent},${accent},${accent},${accent},0,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1`,
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** An ASS time: `H:MM:SS.cc`. */
|
|
34
|
+
function toAssTime(seconds: number): string {
|
|
35
|
+
const centiseconds = Math.max(0, Math.round(seconds * 100));
|
|
36
|
+
const pad = (value: number): string => String(value).padStart(2, "0");
|
|
37
|
+
return `${Math.floor(centiseconds / 360000)}:${pad(Math.floor((centiseconds % 360000) / 6000))}:${pad(Math.floor((centiseconds % 6000) / 100))}.${pad(centiseconds % 100)}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Overlay text as ASS dialogue: braces and backslashes would read as tags. */
|
|
41
|
+
function toAssText(text: string): string {
|
|
42
|
+
return text.replace(/\\/g, "/").replace(/\{/g, "(").replace(/\}/g, ")").replace(/\s+/g, " ").trim();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A straight arrow from `from` to `to` as an ASS drawing: the shaft's quad and the head's triangle. */
|
|
46
|
+
export function getArrowDrawing(from: OverlayPoint, to: OverlayPoint, scale: number): string {
|
|
47
|
+
const length = Math.hypot(to.x - from.x, to.y - from.y) || 1;
|
|
48
|
+
const u = { x: (to.x - from.x) / length, y: (to.y - from.y) / length };
|
|
49
|
+
const n = { x: -u.y, y: u.x };
|
|
50
|
+
const half = (STROKE_WIDTH * scale) / 2;
|
|
51
|
+
const head = ARROW_HEAD * scale;
|
|
52
|
+
const base = { x: to.x - u.x * head, y: to.y - u.y * head };
|
|
53
|
+
const p = (x: number, y: number) => `${r0(x)} ${r0(y)}`;
|
|
54
|
+
const shaft = `m ${p(from.x + n.x * half, from.y + n.y * half)} l ${p(base.x + n.x * half, base.y + n.y * half)} ${p(base.x - n.x * half, base.y - n.y * half)} ${p(from.x - n.x * half, from.y - n.y * half)}`;
|
|
55
|
+
const wing = head * 0.6;
|
|
56
|
+
const tip = `m ${p(to.x, to.y)} l ${p(base.x + n.x * wing, base.y + n.y * wing)} ${p(base.x - n.x * wing, base.y - n.y * wing)}`;
|
|
57
|
+
return `${shaft} ${tip}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The overlays as ASS events, layer 3 and up. */
|
|
61
|
+
export function buildDraftOverlayEvents(overlays: readonly ResolvedOverlay[], colors: OverlayColors, frame: { width: number; height: number }): string[] {
|
|
62
|
+
const scale = frame.width / 1080;
|
|
63
|
+
const accent = toTagColor(colors.accent);
|
|
64
|
+
return overlays.flatMap((overlay) => {
|
|
65
|
+
const at = `${toAssTime(overlay.start)},${toAssTime(overlay.end)}`;
|
|
66
|
+
if (overlay.kind === "punch_in") return [];
|
|
67
|
+
if (overlay.kind === "arrow") {
|
|
68
|
+
return [`Dialogue: 3,${at},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${FADE}\\p1}${getArrowDrawing(overlay.from, overlay.to, scale)}{\\p0}`];
|
|
69
|
+
}
|
|
70
|
+
if (overlay.kind === "highlight") {
|
|
71
|
+
// libass grows a drawing's border outwards only: the shape is inset by half the stroke and bordered by all of
|
|
72
|
+
// it, so the stroke straddles the rectangle's edge as the render's SVG stroke does.
|
|
73
|
+
const stroke = r0(STROKE_WIDTH * scale);
|
|
74
|
+
const half = stroke / 2;
|
|
75
|
+
const [left, top] = [overlay.rect.left + half, overlay.rect.top + half];
|
|
76
|
+
const [right, bottom] = [overlay.rect.left + overlay.rect.width - half, overlay.rect.top + overlay.rect.height - half];
|
|
77
|
+
const shape = `m ${r0(left)} ${r0(top)} l ${r0(right)} ${r0(top)} ${r0(right)} ${r0(bottom)} ${r0(left)} ${r0(bottom)}`;
|
|
78
|
+
return [`Dialogue: 3,${at},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${FADE}\\1a&HFF&\\3c${accent}\\bord${stroke}\\p1}${shape}{\\p0}`];
|
|
79
|
+
}
|
|
80
|
+
const { box, fontSize, side } = overlay;
|
|
81
|
+
const pad = r0(fontSize * OVERLAY_PADDING_EM.y);
|
|
82
|
+
const isRight = side === "right";
|
|
83
|
+
const x = isRight ? box.left + box.width - pad : box.left + pad;
|
|
84
|
+
const isFoot = overlay.kind === "lower_third";
|
|
85
|
+
const y = isFoot ? box.top + box.height - pad : box.top + pad;
|
|
86
|
+
// \an: 7 top left, 9 top right, 1 bottom left, 3 bottom right.
|
|
87
|
+
const align = isFoot ? (isRight ? 3 : 1) : isRight ? 9 : 7;
|
|
88
|
+
const text = overlay.kind === "list" ? overlay.items.map((item) => `• ${toAssText(item)}`).join("\\N") : toAssText(overlay.text);
|
|
89
|
+
return [`Dialogue: 3,${at},Overlay,,0,0,0,,{\\an${align}\\pos(${r0(x)},${r0(y)})\\fs${fontSize}\\bord${pad}${FADE}}${text}`];
|
|
90
|
+
});
|
|
91
|
+
}
|