Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(skills): preserve captured font subsets (#4358)
Miguel Ángel922be55e55b2
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 56e382fd9e..cb8b11f040 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -117,6 +117,7 @@ jobs:- "bun.lock"- ".github/workflows/ci.yml"skills:+ - "scripts/generate-captured-font-copies.mjs"- "packages/cli/src/media-use/**"- "scripts/check-media-use-copy-parity.test.mjs"- "skills/**"diff --git a/scripts/generate-captured-font-copies.mjs b/scripts/generate-captured-font-copies.mjsnew file mode 100644index 0000000000..9c07a5d27a--- /dev/null+++ b/scripts/generate-captured-font-copies.mjs@@ -0,0 +1,13 @@+import { copyFileSync } from "node:fs";++// Each workflow installs independently. Edit the product-launch-video owner.+const source = new URL(+ "../skills/product-launch-video/scripts/lib/captured-fonts.mjs",+ import.meta.url,+);+for (const skill of ["faceless-explainer", "pr-to-video"]) {+ copyFileSync(+ source,+ new URL(`../skills/${skill}/scripts/lib/captured-fonts.mjs`, import.meta.url),+ );+}diff --git a/scripts/test-reachability.json b/scripts/test-reachability.jsonindex ea3eed5eab..414188990e 100644--- a/scripts/test-reachability.json+++ b/scripts/test-reachability.json@@ -20,7 +20,19 @@"scripts/**","packages/producer/**"],- "scripts/generate-catalog-payloads.test.ts": ["registry/**", "scripts/**"]+ "scripts/generate-catalog-payloads.test.ts": ["registry/**", "scripts/**"],+ "skills/product-launch-video/scripts/build-frame-subsets.test.mjs": [+ "scripts/generate-captured-font-copies.mjs",+ "skills/product-launch-video/scripts/build-frame.mjs",+ "skills/product-launch-video/scripts/captions.mjs",+ "skills/product-launch-video/scripts/lib/captured-fonts.mjs",+ "skills/faceless-explainer/scripts/build-frame.mjs",+ "skills/faceless-explainer/scripts/captions.mjs",+ "skills/faceless-explainer/scripts/lib/captured-fonts.mjs",+ "skills/pr-to-video/scripts/build-frame.mjs",+ "skills/pr-to-video/scripts/captions.mjs",+ "skills/pr-to-video/scripts/lib/captured-fonts.mjs"+ ]},"runners": [{diff --git a/skills-manifest.json b/skills-manifest.jsonindex 9da07ccaf3..4a7131fbe7 100644--- a/skills-manifest.json+++ b/skills-manifest.json@@ -6,8 +6,8 @@"files": 142},"faceless-explainer": {- "hash": "37dffa6e8f81bffc",- "files": 24+ "hash": "3dfdfe562df85799",+ "files": 25},"figma": {"hash": "642cce1b5e211182",@@ -66,12 +66,12 @@"files": 169},"pr-to-video": {- "hash": "1a0f65e1cec1263b",- "files": 30+ "hash": "56f66423f93dafc5",+ "files": 31},"product-launch-video": {- "hash": "ced501f76c52716b",- "files": 30+ "hash": "8a1406f7c1afa598",+ "files": 32},"remotion-to-hyperframes": {"hash": "1da9494cf3a6b1f3",diff --git a/skills/faceless-explainer/scripts/build-frame.mjs b/skills/faceless-explainer/scripts/build-frame.mjsindex ec08e112a6..f84940bcab 100644--- a/skills/faceless-explainer/scripts/build-frame.mjs+++ b/skills/faceless-explainer/scripts/build-frame.mjs@@ -41,6 +41,8 @@ import {UA_DEFAULT_COLORS,} from "./lib/tokens.mjs";+import { stageCapturedFonts } from "./lib/captured-fonts.mjs";+const __dirname = dirname(fileURLToPath(import.meta.url));const argv = process.argv.slice(2);const flag = (name, def) => {@@ -481,11 +483,12 @@ if (brandFonts.length) {const famOf = (f) =>fams.length === 1 ? fams[0] : ranked.find((x) => norm(f).includes(norm(x)));const outDir = join(hyperframesDir, "assets/fonts");- const faces = [];- const stagedNames = new Set();+ const captured = stageCapturedFonts(hyperframesDir, fams);+ const faces = [...captured.faces];+ const stagedNames = new Set(captured.files);for (const { d, f } of files) {const fam = famOf(f);- if (!fam) continue;+ if (!fam || captured.families.has(fam.toLowerCase())) continue;const { n, w } = weightInfo(f);const style = styleOf(f);const clean = `${fam.replace(/[^A-Za-z0-9]/g, "")}-${w}${style === "italic" ? "-Italic" : ""}.${extOf(f)}`;diff --git a/skills/faceless-explainer/scripts/captions.mjs b/skills/faceless-explainer/scripts/captions.mjsindex 8390686583..b2e2fa0168 100644--- a/skills/faceless-explainer/scripts/captions.mjs+++ b/skills/faceless-explainer/scripts/captions.mjs@@ -1,4 +1,5 @@#!/usr/bin/env node+import { stageCapturedFonts } from "./lib/captured-fonts.mjs";// captions.mjs — build the captions sub-composition from STORYBOARD + audio_meta.//// One mode: `build`. Reads STORYBOARD.md (frame order + durations → cumulative@@ -344,7 +345,8 @@ function brandFontFaces(framePath, hyperframesDir) {// underscore/hyphen-named brand font (e.g. TT Norms Pro), which is exactly the// font_family_without_font_face bug.const norm = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");- const faces = [];+ const captured = stageCapturedFonts(hyperframesDir, families);+ const faces = [...captured.faces];const seen = new Set();const claimed = new Set(); // each file is claimed by the MOST SPECIFIC family only// Match the longest family key first so "TT Norms Pro" can't swallow the files that@@ -363,12 +365,13 @@ function brandFontFaces(framePath, hyperframesDir) {if (!/\.(woff2|woff|ttf|otf)$/i.test(f)) continue;if (claimed.has(f)) continue; // a more specific family already took this fileif (!norm(f.replace(/\.(woff2|woff|ttf|otf)$/i, "")).startsWith(key)) continue;+ claimed.add(f);+ if (captured.families.has(fam.toLowerCase())) continue;const w = weightOf(f);const style = styleOf(f);const dedup = `${fam}-${w}-${style}`;if (seen.has(dedup)) continue; // one src per face; assets/fonts wins over captureseen.add(dedup);- claimed.add(f);faces.push(` @font-face { font-family: '${fam}'; src: url('${d.rel}/${f}') format('${fmtOf(f)}'); font-weight: ${w}; font-style: ${style}; font-display: block; }`,);diff --git a/skills/faceless-explainer/scripts/lib/captured-fonts.mjs b/skills/faceless-explainer/scripts/lib/captured-fonts.mjsnew file mode 100644index 0000000000..c798346f6a--- /dev/null+++ b/skills/faceless-explainer/scripts/lib/captured-fonts.mjs@@ -0,0 +1,58 @@+import { copyFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";+import { join } from "node:path";++// Capture preserves subset and variable-axis descriptors in extracted/page.html.+// Filenames alone cannot identify a face's character coverage.+export function stageCapturedFonts(projectDir, families) {+ const page = join(projectDir, "capture/extracted/page.html");+ const result = { faces: [], families: new Set(), files: new Set() };+ if (!existsSync(page)) return result;+ const wanted = new Set(families.map((family) => family.toLowerCase()));+ const html = readFileSync(page, "utf8");+ const copied = new Set();+ for (const style of html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style\s*>/gi)) {+ const css = style[1].replace(/\/\*[\s\S]*?\*\//g, "");+ for (const match of css.matchAll(/@font-face\s*\{([^}]+)\}/gi)) {+ const body = match[1];+ const familyValue = /(?:^|;)\s*font-family\s*:\s*([^;]+)/i.exec(body)?.[1]?.trim();+ if (!familyValue) continue;+ const family = familyValue.replace(/^(['"])(.*)\1$/, "$2");+ if (!wanted.has(family.toLowerCase())) continue;+ result.families.add(family.toLowerCase());+ const source = /(?:^|;)\s*src\s*:\s*([^;]+)/i.exec(body);+ if (!source) continue;+ const sources = localFontSources(source[1], projectDir);+ if (!sources.length) {+ console.warn("Captured font has no downloaded source: " + family);+ continue;+ }+ for (const file of sources) {+ if (copied.has(file.name)) continue;+ if (!copied.size) mkdirSync(join(projectDir, "assets/fonts"), { recursive: true });+ copyFileSync(file.source, join(projectDir, file.target));+ copied.add(file.name);+ result.files.add(file.target);+ }+ const src = sources.map((file) => file.css).join(", ");+ const rule = "@font-face{" + body.replace(source[1], src) + "}";+ if (!result.faces.includes(rule)) result.faces.push(rule);+ }+ }+ return result;+}++function localFontSources(source, projectDir) {+ const files = [];+ for (const match of source.matchAll(+ /url\(\s*(?:"([^"]+)"|'([^']+)'|([^\s)]+))\s*\)(\s*format\([^)]*\))?/gi,+ )) {+ const url = match[1] ?? match[2] ?? match[3];+ const name = /^assets\/fonts\/([a-z0-9_.-]+\.(?:woff2?|ttf|otf))$/i.exec(url)?.[1];+ if (!name) continue;+ const path = join(projectDir, "capture/assets/fonts", name);+ if (!existsSync(path)) continue;+ const target = "assets/fonts/captured-" + name;+ files.push({ name, source: path, target, css: 'url("' + target + '")' + (match[4] ?? "") });+ }+ return files;+}diff --git a/skills/pr-to-video/scripts/build-frame.mjs b/skills/pr-to-video/scripts/build-frame.mjsindex b5f685598d..617b1d3fa2 100644--- a/skills/pr-to-video/scripts/build-frame.mjs+++ b/skills/pr-to-video/scripts/build-frame.mjs@@ -41,6 +41,8 @@ import {UA_DEFAULT_COLORS,} from "./lib/tokens.mjs";+import { stageCapturedFonts } from "./lib/captured-fonts.mjs";+const __dirname = dirname(fileURLToPath(import.meta.url));const argv = process.argv.slice(2);const flag = (name, def) => {@@ -516,11 +518,12 @@ if (brandFonts.length) {const famOf = (f) =>fams.length === 1 ? fams[0] : ranked.find((x) => norm(f).includes(norm(x)));const outDir = join(hyperframesDir, "assets/fonts");- const faces = [];- const stagedNames = new Set();+ const captured = stageCapturedFonts(hyperframesDir, fams);+ const faces = [...captured.faces];+ const stagedNames = new Set(captured.files);for (const { d, f } of files) {const fam = famOf(f);- if (!fam) continue;+ if (!fam || captured.families.has(fam.toLowerCase())) continue;const { n, w } = weightInfo(f);const style = styleOf(f);const clean = `${fam.replace(/[^A-Za-z0-9]/g, "")}-${w}${style === "italic" ? "-Italic" : ""}.${extOf(f)}`;diff --git a/skills/pr-to-video/scripts/captions.mjs b/skills/pr-to-video/scripts/captions.mjsindex 8390686583..b2e2fa0168 100644--- a/skills/pr-to-video/scripts/captions.mjs+++ b/skills/pr-to-video/scripts/captions.mjs@@ -1,4 +1,5 @@#!/usr/bin/env node+import { stageCapturedFonts } from "./lib/captured-fonts.mjs";// captions.mjs — build the captions sub-composition from STORYBOARD + audio_meta.//// One mode: `build`. Reads STORYBOARD.md (frame order + durations → cumulative@@ -344,7 +345,8 @@ function brandFontFaces(framePath, hyperframesDir) {// underscore/hyphen-named brand font (e.g. TT Norms Pro), which is exactly the// font_family_without_font_face bug.const norm = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");- const faces = [];+ const captured = stageCapturedFonts(hyperframesDir, families);+ const faces = [...captured.faces];const seen = new Set();const claimed = new Set(); // each file is claimed by the MOST SPECIFIC family only// Match the longest family key first so "TT Norms Pro" can't swallow the files that@@ -363,12 +365,13 @@ function brandFontFaces(framePath, hyperframesDir) {if (!/\.(woff2|woff|ttf|otf)$/i.test(f)) continue;if (claimed.has(f)) continue; // a more specific family already took this fileif (!norm(f.replace(/\.(woff2|woff|ttf|otf)$/i, "")).startsWith(key)) continue;+ claimed.add(f);+ if (captured.families.has(fam.toLowerCase())) continue;const w = weightOf(f);const style = styleOf(f);const dedup = `${fam}-${w}-${style}`;if (seen.has(dedup)) continue; // one src per face; assets/fonts wins over captureseen.add(dedup);- claimed.add(f);faces.push(` @font-face { font-family: '${fam}'; src: url('${d.rel}/${f}') format('${fmtOf(f)}'); font-weight: ${w}; font-style: ${style}; font-display: block; }`,);diff --git a/skills/pr-to-video/scripts/lib/captured-fonts.mjs b/skills/pr-to-video/scripts/lib/captured-fonts.mjsnew file mode 100644index 0000000000..c798346f6a--- /dev/null+++ b/skills/pr-to-video/scripts/lib/captured-fonts.mjs@@ -0,0 +1,58 @@+import { copyFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";+import { join } from "node:path";++// Capture preserves subset and variable-axis descriptors in extracted/page.html.+// Filenames alone cannot identify a face's character coverage.+export function stageCapturedFonts(projectDir, families) {+ const page = join(projectDir, "capture/extracted/page.html");+ const result = { faces: [], families: new Set(), files: new Set() };+ if (!existsSync(page)) return result;+ const wanted = new Set(families.map((family) => family.toLowerCase()));+ const html = readFileSync(page, "utf8");+ const copied = new Set();+ for (const style of html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style\s*>/gi)) {+ const css = style[1].replace(/\/\*[\s\S]*?\*\//g, "");+ for (const match of css.matchAll(/@font-face\s*\{([^}]+)\}/gi)) {+ const body = match[1];+ const familyValue = /(?:^|;)\s*font-family\s*:\s*([^;]+)/i.exec(body)?.[1]?.trim();+ if (!familyValue) continue;+ const family = familyValue.replace(/^(['"])(.*)\1$/, "$2");+ if (!wanted.has(family.toLowerCase())) continue;+ result.families.add(family.toLowerCase());+ const source = /(?:^|;)\s*src\s*:\s*([^;]+)/i.exec(body);+ if (!source) continue;+ const sources = localFontSources(source[1], projectDir);+ if (!sources.length) {+ console.warn("Captured font has no downloaded source: " + family);+ continue;+ }+ for (const file of sources) {+ if (copied.has(file.name)) continue;+ if (!copied.size) mkdirSync(join(projectDir, "assets/fonts"), { recursive: true });+ copyFileSync(file.source, join(projectDir, file.target));+ copied.add(file.name);+ result.files.add(file.target);+ }+ const src = sources.map((file) => file.css).join(", ");+ const rule = "@font-face{" + body.replace(source[1], src) + "}";+ if (!result.faces.includes(rule)) result.faces.push(rule);+ }+ }+ return result;+}++function localFontSources(source, projectDir) {+ const files = [];+ for (const match of source.matchAll(+ /url\(\s*(?:"([^"]+)"|'([^']+)'|([^\s)]+))\s*\)(\s*format\([^)]*\))?/gi,+ )) {+ const url = match[1] ?? match[2] ?? match[3];+ const name = /^assets\/fonts\/([a-z0-9_.-]+\.(?:woff2?|ttf|otf))$/i.exec(url)?.[1];+ if (!name) continue;+ const path = join(projectDir, "capture/assets/fonts", name);+ if (!existsSync(path)) continue;+ const target = "assets/fonts/captured-" + name;+ files.push({ name, source: path, target, css: 'url("' + target + '")' + (match[4] ?? "") });+ }+ return files;+}diff --git a/skills/product-launch-video/scripts/build-frame-subsets.test.mjs b/skills/product-launch-video/scripts/build-frame-subsets.test.mjsnew file mode 100644index 0000000000..f3108080e7--- /dev/null+++ b/skills/product-launch-video/scripts/build-frame-subsets.test.mjs@@ -0,0 +1,152 @@+import assert from "node:assert/strict";+import { execFileSync } from "node:child_process";+import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { fileURLToPath } from "node:url";+import test from "node:test";++const workflows = ["product-launch-video", "faceless-explainer", "pr-to-video"];+const css = `<style>+/* cyrillic */+@font-face { font-family: 'Manrope'; font-style: normal; font-weight: 200 800;+ src: url(assets/fonts/aaa.woff2) format('woff2'); unicode-range: U+0400-045F; }+/* latin */+@font-face { font-family: 'Manrope'; font-style: normal; font-weight: 200 800;+ src: url("assets/fonts/zzz.woff2") format('woff2'); unicode-range: U+0000-00FF; }+</style>`;++for (const skill of workflows) {+ const scripts = new URL("../../" + skill + "/scripts/", import.meta.url);+ const { brandFontFaces } = await import(new URL("captions.mjs", scripts));+ test(skill + " stages every captured subset and captions preserve the same coverage", () => {+ const project = mkdtempSync(join(tmpdir(), "frame-subsets-"));+ try {+ mkdirSync(join(project, "capture/extracted"), { recursive: true });+ mkdirSync(join(project, "capture/assets/fonts"), { recursive: true });+ writeFileSync(+ join(project, "capture/extracted/tokens.json"),+ JSON.stringify({ fonts: [{ family: "Manrope" }] }),+ );+ writeFileSync(join(project, "capture/extracted/page.html"), css);+ writeFileSync(join(project, "capture/assets/fonts/aaa.woff2"), "cyrillic bytes");+ writeFileSync(join(project, "capture/assets/fonts/zzz.woff2"), "latin bytes");+ for (let pass = 0; pass < 2; pass++) {+ execFileSync(+ process.execPath,+ [+ fileURLToPath(new URL("build-frame.mjs", scripts)),+ "--preset",+ "capsule",+ "--hyperframes",+ project,+ ],+ { stdio: "pipe" },+ );+ const frame = readFileSync(join(project, "frame.md"), "utf8");+ const captions = brandFontFaces(join(project, "frame.md"), project);+ for (const output of [frame, captions]) {+ assert.match(output, /unicode-range:\s*U\+0400-045F/);+ assert.match(output, /unicode-range:\s*U\+0000-00FF/);+ assert.equal((output.match(/font-weight:\s*200 800/g) ?? []).length, 2);+ assert.equal((output.match(/@font-face/g) ?? []).length, 2);+ for (const match of output.matchAll(/url\(["']?(assets\/fonts\/[^"')]+)["']?\)/g)) {+ assert.ok(+ ["cyrillic bytes", "latin bytes"].includes(+ readFileSync(join(project, match[1]), "utf8"),+ ),+ );+ }+ }+ assert.equal(readdirSync(join(project, "assets/fonts")).length, 2);+ }+ } finally {+ rmSync(project, { recursive: true, force: true });+ }+ });+}++test("captured font helper copies stay equal to the owner", () => {+ const owner = readFileSync(new URL("./lib/captured-fonts.mjs", import.meta.url), "utf8");+ for (const skill of workflows.slice(1)) {+ assert.equal(+ readFileSync(+ new URL("../../" + skill + "/scripts/lib/captured-fonts.mjs", import.meta.url),+ "utf8",+ ),+ owner,+ );+ }+});++test("captured rules stage only available local sources for requested families", async () => {+ const { stageCapturedFonts } = await import("./lib/captured-fonts.mjs");+ const project = mkdtempSync(join(tmpdir(), "captured-font-sources-"));+ try {+ mkdirSync(join(project, "capture/extracted"), { recursive: true });+ mkdirSync(join(project, "capture/assets/fonts"), { recursive: true });+ writeFileSync(join(project, "capture/assets/fonts/local.woff2"), "first");+ writeFileSync(+ join(project, "capture/extracted/page.html"),+ `<style>+ @font-face { font-family: Other; src: url(assets/fonts/local.woff2); }+ @font-face { font-family: Manrope; font-weight: 600; unicode-range: U+0000-00FF;+ src: local(Manrope), url(https://example.com/remote.woff2), url(assets/fonts/missing.woff2), url(assets/fonts/local.woff2) format("woff2"); }+ </style>`,+ );+ const first = stageCapturedFonts(project, ["Manrope"]);+ assert.equal(first.faces.length, 1);+ assert.deepEqual([...first.families], ["manrope"]);+ assert.doesNotMatch(first.faces[0], /Other|https:|missing|local\(/);+ assert.match(first.faces[0], /unicode-range: U\+0000-00FF/);+ const [file] = first.files;+ assert.equal(readFileSync(join(project, file), "utf8"), "first");+ writeFileSync(join(project, "capture/assets/fonts/local.woff2"), "refreshed");+ stageCapturedFonts(project, ["Manrope"]);+ assert.equal(readFileSync(join(project, file), "utf8"), "refreshed");+ } finally {+ rmSync(project, { recursive: true, force: true });+ }+});++for (const skill of workflows) {+ test(+ skill + " keeps captured family ownership when downloads are missing or names overlap",+ async () => {+ const { brandFontFaces } = await import(+ new URL("../../" + skill + "/scripts/captions.mjs", import.meta.url)+ );+ const project = mkdtempSync(join(tmpdir(), "font-ownership-"));+ try {+ mkdirSync(join(project, "capture/extracted"), { recursive: true });+ mkdirSync(join(project, "capture/assets/fonts"), { recursive: true });+ writeFileSync(+ join(project, "frame.md"),+ 'typography:\n display: { fontFamily: "TT Norms Pro Mono", weight: 400 }\n body: { fontFamily: "TT Norms Pro", weight: 400 }\n',+ );+ writeFileSync(+ join(project, "capture/assets/fonts/TT_Norms_Pro_Mono_Regular.woff2"),+ "mono",+ );+ writeFileSync(+ join(project, "capture/extracted/page.html"),+ `<style>+ @font-face { font-family: 'TT Norms Pro Mono'; src: url(assets/fonts/TT_Norms_Pro_Mono_Regular.woff2); unicode-range: U+0000-00FF; }+ </style>`,+ );+ const mixed = brandFontFaces(join(project, "frame.md"), project);+ assert.equal((mixed.match(/@font-face/g) ?? []).length, 1);+ assert.doesNotMatch(mixed, /font-family: 'TT Norms Pro';/);+ writeFileSync(+ join(project, "capture/extracted/page.html"),+ `<style>+ @font-face { font-family: 'TT Norms Pro Mono'; src: url(assets/fonts/missing.woff2); }+ </style>`,+ );+ assert.equal(brandFontFaces(join(project, "frame.md"), project), "");+ } finally {+ rmSync(project, { recursive: true, force: true });+ }+ },+ );+}diff --git a/skills/product-launch-video/scripts/build-frame.mjs b/skills/product-launch-video/scripts/build-frame.mjsindex 7f3bf0144f..caaa587e92 100644--- a/skills/product-launch-video/scripts/build-frame.mjs+++ b/skills/product-launch-video/scripts/build-frame.mjs@@ -42,6 +42,8 @@ import {UA_DEFAULT_COLORS,} from "./lib/tokens.mjs";+import { stageCapturedFonts } from "./lib/captured-fonts.mjs";+const __dirname = dirname(fileURLToPath(import.meta.url));const argv = process.argv.slice(2);const flag = (name, def) => {@@ -479,11 +481,12 @@ if (brandFonts.length) {const famOf = (f) =>fams.length === 1 ? fams[0] : ranked.find((x) => norm(f).includes(norm(x)));const outDir = join(hyperframesDir, "assets/fonts");- const faces = [];- const stagedNames = new Set();+ const captured = stageCapturedFonts(hyperframesDir, fams);+ const faces = [...captured.faces];+ const stagedNames = new Set(captured.files);for (const { d, f } of files) {const fam = famOf(f);- if (!fam) continue;+ if (!fam || captured.families.has(fam.toLowerCase())) continue;const { n, w } = weightInfo(f);const style = styleOf(f);const clean = `${fam.replace(/[^A-Za-z0-9]/g, "")}-${w}${style === "italic" ? "-Italic" : ""}.${extOf(f)}`;diff --git a/skills/product-launch-video/scripts/captions.mjs b/skills/product-launch-video/scripts/captions.mjsindex 8390686583..b2e2fa0168 100644--- a/skills/product-launch-video/scripts/captions.mjs+++ b/skills/product-launch-video/scripts/captions.mjs@@ -1,4 +1,5 @@#!/usr/bin/env node+import { stageCapturedFonts } from "./lib/captured-fonts.mjs";// captions.mjs — build the captions sub-composition from STORYBOARD + audio_meta.//// One mode: `build`. Reads STORYBOARD.md (frame order + durations → cumulative@@ -344,7 +345,8 @@ function brandFontFaces(framePath, hyperframesDir) {// underscore/hyphen-named brand font (e.g. TT Norms Pro), which is exactly the// font_family_without_font_face bug.const norm = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");- const faces = [];+ const captured = stageCapturedFonts(hyperframesDir, families);+ const faces = [...captured.faces];const seen = new Set();const claimed = new Set(); // each file is claimed by the MOST SPECIFIC family only// Match the longest family key first so "TT Norms Pro" can't swallow the files that@@ -363,12 +365,13 @@ function brandFontFaces(framePath, hyperframesDir) {if (!/\.(woff2|woff|ttf|otf)$/i.test(f)) continue;if (claimed.has(f)) continue; // a more specific family already took this fileif (!norm(f.replace(/\.(woff2|woff|ttf|otf)$/i, "")).startsWith(key)) continue;+ claimed.add(f);+ if (captured.families.has(fam.toLowerCase())) continue;const w = weightOf(f);const style = styleOf(f);const dedup = `${fam}-${w}-${style}`;if (seen.has(dedup)) continue; // one src per face; assets/fonts wins over captureseen.add(dedup);- claimed.add(f);faces.push(` @font-face { font-family: '${fam}'; src: url('${d.rel}/${f}') format('${fmtOf(f)}'); font-weight: ${w}; font-style: ${style}; font-display: block; }`,);diff --git a/skills/product-launch-video/scripts/lib/captured-fonts.mjs b/skills/product-launch-video/scripts/lib/captured-fonts.mjsnew file mode 100644index 0000000000..c798346f6a--- /dev/null+++ b/skills/product-launch-video/scripts/lib/captured-fonts.mjs@@ -0,0 +1,58 @@+import { copyFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";+import { join } from "node:path";++// Capture preserves subset and variable-axis descriptors in extracted/page.html.+// Filenames alone cannot identify a face's character coverage.+export function stageCapturedFonts(projectDir, families) {+ const page = join(projectDir, "capture/extracted/page.html");+ const result = { faces: [], families: new Set(), files: new Set() };+ if (!existsSync(page)) return result;+ const wanted = new Set(families.map((family) => family.toLowerCase()));+ const html = readFileSync(page, "utf8");+ const copied = new Set();+ for (const style of html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style\s*>/gi)) {+ const css = style[1].replace(/\/\*[\s\S]*?\*\//g, "");+ for (const match of css.matchAll(/@font-face\s*\{([^}]+)\}/gi)) {+ const body = match[1];+ const familyValue = /(?:^|;)\s*font-family\s*:\s*([^;]+)/i.exec(body)?.[1]?.trim();+ if (!familyValue) continue;+ const family = familyValue.replace(/^(['"])(.*)\1$/, "$2");+ if (!wanted.has(family.toLowerCase())) continue;+ result.families.add(family.toLowerCase());+ const source = /(?:^|;)\s*src\s*:\s*([^;]+)/i.exec(body);+ if (!source) continue;+ const sources = localFontSources(source[1], projectDir);+ if (!sources.length) {+ console.warn("Captured font has no downloaded source: " + family);+ continue;+ }+ for (const file of sources) {+ if (copied.has(file.name)) continue;+ if (!copied.size) mkdirSync(join(projectDir, "assets/fonts"), { recursive: true });+ copyFileSync(file.source, join(projectDir, file.target));+ copied.add(file.name);+ result.files.add(file.target);+ }+ const src = sources.map((file) => file.css).join(", ");+ const rule = "@font-face{" + body.replace(source[1], src) + "}";+ if (!result.faces.includes(rule)) result.faces.push(rule);+ }+ }+ return result;+}++function localFontSources(source, projectDir) {+ const files = [];+ for (const match of source.matchAll(+ /url\(\s*(?:"([^"]+)"|'([^']+)'|([^\s)]+))\s*\)(\s*format\([^)]*\))?/gi,+ )) {+ const url = match[1] ?? match[2] ?? match[3];+ const name = /^assets\/fonts\/([a-z0-9_.-]+\.(?:woff2?|ttf|otf))$/i.exec(url)?.[1];+ if (!name) continue;+ const path = join(projectDir, "capture/assets/fonts", name);+ if (!existsSync(path)) continue;+ const target = "assets/fonts/captured-" + name;+ files.push({ name, source: path, target, css: 'url("' + target + '")' + (match[4] ?? "") });+ }+ return files;+}