Open source CapCut alternative.
TypeScript
fix(site): self-host fonts from npm packages so builds never call Google Fonts
David Le7ab29c71cbf8
diff --git a/.github/workflows/deploy-cut-worker.yml b/.github/workflows/deploy-cut-worker.ymlindex 42af32d2..0ee2e9d6 100644--- a/.github/workflows/deploy-cut-worker.yml+++ b/.github/workflows/deploy-cut-worker.yml@@ -15,7 +15,7 @@ on:# change to the drawing, decoding or effects code ships in this image.- site/src/cut/lib/**- site/packages/effects-kit/**- - site/scripts/fetch-cut-fonts.mjs+ - site/scripts/stage-cut-fonts.mjs- site/src/cut/server/exportPipeline.ts- site/src/cut/server/exportPipeline.e2e.test.ts- site/src/cut/server/filterGraph.tsdiff --git a/site/package-lock.json b/site/package-lock.jsonindex 0e671c3c..080bdc6c 100644--- a/site/package-lock.json+++ b/site/package-lock.json@@ -27,6 +27,25 @@"@earendil-works/pi-agent-core": "0.84.1","@earendil-works/pi-ai": "0.84.1","@elevenlabs/elevenlabs-js": "^2.49.1",+ "@fontsource/anton": "^5.3.0",+ "@fontsource/archivo-black": "^5.3.0",+ "@fontsource/bangers": "^5.3.0",+ "@fontsource/bebas-neue": "^5.3.0",+ "@fontsource/caveat": "^5.3.0",+ "@fontsource/dm-serif-display": "^5.3.0",+ "@fontsource/inter": "^5.3.0",+ "@fontsource/lobster": "^5.3.0",+ "@fontsource/montserrat": "^5.3.0",+ "@fontsource/noto-serif": "^5.3.0",+ "@fontsource/nunito": "^5.3.0",+ "@fontsource/oswald": "^5.3.0",+ "@fontsource/pacifico": "^5.3.0",+ "@fontsource/permanent-marker": "^5.3.0",+ "@fontsource/playfair-display": "^5.3.0",+ "@fontsource/poppins": "^5.3.0",+ "@fontsource/roboto": "^5.3.0",+ "@fontsource/roboto-mono": "^5.3.0",+ "@fontsource/space-grotesk": "^5.3.0","@google/genai": "2.21.0","@mdx-js/loader": "^3.1.1","@mdx-js/react": "^3.1.1",@@ -57,6 +76,7 @@"cn": "^0.2.6","date-fns": "^4.4.0","defuddle": "^0.18.1",+ "geist": "^1.7.2","lexical": "^0.48.0","linkedom": "^0.18.12","lucide-react": "^1.23.0",@@ -2960,6 +2980,177 @@"integrity": "sha512-HpCo8tmWzLVad5s2d19EhAz5zqrrQ6s69qd6moPMQvkOuSwDT1YgRfWSVuc4ennqrgv3OHppiOGMQ7oC13yIww==","license": "MIT"},+ "node_modules/@fontsource/anton": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/anton/-/anton-5.3.0.tgz",+ "integrity": "sha512-OR1D5n124n2XRs66SbX7IjcOSptljEJE8FcDNnlni2y1/M6KpTx7cU2PIWzTSsBj4WFkHPw24On8qw3qkQZuTw==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/archivo-black": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/archivo-black/-/archivo-black-5.3.0.tgz",+ "integrity": "sha512-7EsTIQ+Blf96ktpzTUpI7msi+u9/AJxM/GZxOSkEubVd1jSTrFSTNxMgfpX/8rQsjZ+19a+qvRbtcTEp5J/72g==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/bangers": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/bangers/-/bangers-5.3.0.tgz",+ "integrity": "sha512-tSRpmWwkqrO9PCqo9wjA/99/5sLOIWm5cf51G3ooEHd8qZus8sVSSJoWp/7EvM5rIgZMjKRG6XtY9yeisKxE7g==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/bebas-neue": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/bebas-neue/-/bebas-neue-5.3.0.tgz",+ "integrity": "sha512-nCxMEb9Bg9sjNWm9TIOsvHKDMLRUfEZPWpLgYu6m9KavZZVSA/WoHzI5wROwqA+eNwEi/PNBAcB5Co7HA3S0Cw==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/caveat": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/caveat/-/caveat-5.3.0.tgz",+ "integrity": "sha512-eHTfzQxFSW9ABERRLNruHoNJmKed2J7pqTUc5lp4a4POMgXGKpxmWj3d9Hz10kmAg6iuTTLe6UagbA4bnsmfQw==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/dm-serif-display": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/dm-serif-display/-/dm-serif-display-5.3.0.tgz",+ "integrity": "sha512-ecRclUcYeto9fB7ghkB36H4MtUoaUYFjjornWYYeLCMHzaWEDPk2kIWgZOq0mKBNRxclRSieKcFeLonlMYDTKg==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/inter": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/inter/-/inter-5.3.0.tgz",+ "integrity": "sha512-RofMylZmjlJEfELXeNHFWBRcSs75rGU/6bV2S2jfnvv/3rPXPGe0LgUJTklcHZ9lM4OZmAVFhcJPnACfb91A3g==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/lobster": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/lobster/-/lobster-5.3.0.tgz",+ "integrity": "sha512-jt+RDk/8Sstl1Omhox62gTbvRSLbh06kn5BNfDFgf4rNuDPHF+19eWYFxzq5FsdkalbRJNtc5p5C3qE0+leNVg==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/montserrat": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/montserrat/-/montserrat-5.3.0.tgz",+ "integrity": "sha512-iQPDtZOnmM5ih4JBGaMSXisRap0ixb9bAUw2hDtY7EjVfaqiiNlKtVuJl9XclxUwtwMMHNcWXfQR6zI9x05+Tg==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/noto-serif": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/noto-serif/-/noto-serif-5.3.0.tgz",+ "integrity": "sha512-ZrMzjuQlBIcw+qma1slZQdU3YDJvrjLG+9CWU1bxSf3YTkucwqd3EYa/Kfo4Ts19w8IMTGAmtOE3d6wWlgnBtA==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/nunito": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/nunito/-/nunito-5.3.0.tgz",+ "integrity": "sha512-vw9TaTQJ/zpEpKrsODuPmOvaVjXgdda6B+xXA4YqjrdeJ62MLgVoDerdRXFQHyBnSCt2yQ2nHKCHPP/Pv7Xq4Q==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/oswald": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/oswald/-/oswald-5.3.0.tgz",+ "integrity": "sha512-16r2aHActe0pH+9FLdk/74/YxXM7HpGak05kAzx3RvSToiJwGvyhv6GvckPz+YuZmvL1nxWbEop2jAXRcXYPRg==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/pacifico": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/pacifico/-/pacifico-5.3.0.tgz",+ "integrity": "sha512-bWv0fHR1n36p7scRn+maaEaVeQCOq9yvfVfjyAeUzKrK4Y/3qiRAEj4hJgfxj/sjgZZGkeHyKPrbWdDaZtpCVw==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/permanent-marker": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/permanent-marker/-/permanent-marker-5.3.0.tgz",+ "integrity": "sha512-ZO/NtYW4SCc/iY8N3dmjWyDITcXJ/vhWZFgnwRcvzwCKKnScMrM/a2/6VHlsjCVuIgmPzNrCFbedEYhv+/jJBg==",+ "license": "Apache-2.0",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/playfair-display": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/playfair-display/-/playfair-display-5.3.0.tgz",+ "integrity": "sha512-uJSABalvdWc10fEPppQjQocamT21LEyRfzzWfRfqbkPz+sRv+kKpYDKyluBUskvJREkJTos9epj1WjQROGu99Q==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/poppins": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/poppins/-/poppins-5.3.0.tgz",+ "integrity": "sha512-cms1nM7U6SN8epIV1WMVOV8VsA645aSm3wHfzIQnkk188U341ThbJGSl2Sv54V29gnDbT2arMPfLzvVIIVCceQ==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/roboto": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/roboto/-/roboto-5.3.0.tgz",+ "integrity": "sha512-BapRJOWYP+LZ21zp+wBQjfpPYKRoxc4LspJ/RLuI+HSMBD5u/X4O+ESDrSvEqDSy0rAl7GwBJ+09mdc16cVQ1Q==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/roboto-mono": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/roboto-mono/-/roboto-mono-5.3.0.tgz",+ "integrity": "sha512-yhwplHMHW9dCk+1pZuERfcJe+K3rosGVZEoK0XktkxRSqQ9qsipSwwiuW2/8Qmtp9lzu3Ixa/ie4BMH3i8CkZQ==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/space-grotesk": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/space-grotesk/-/space-grotesk-5.3.0.tgz",+ "integrity": "sha512-ksnGizDPXIDuvqcTYTSrmZ+evx9sDlS8rp7+42BQ7wU+spt3twEoXfbJz672C+5CLg6VeUQwRy5RXshWb67LcQ==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },"node_modules/@google/genai": {"version": "2.21.0","resolved": "https://registry.npmjs.org/@google/genai/-/genai-2.21.0.tgz",@@ -14822,6 +15013,15 @@"node": ">=18"}},+ "node_modules/geist": {+ "version": "1.7.2",+ "resolved": "https://registry.npmjs.org/geist/-/geist-1.7.2.tgz",+ "integrity": "sha512-Gu5lDFa3pLRyoBlBPf0QIFHVdWAnpco7fS1bJm41jyLPFoguBgiubseUN2oLXMgqZ7uxAxDoXcHMhCY/fOTTgg==",+ "license": "SIL OPEN FONT LICENSE",+ "peerDependencies": {+ "next": ">=13.2.0"+ }+ },"node_modules/generate-function": {"version": "2.3.1","resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz",diff --git a/site/package.json b/site/package.jsonindex 67d0a121..1e45cc38 100644--- a/site/package.json+++ b/site/package.json@@ -14,7 +14,7 @@"lint": "node --max-old-space-size=8192 node_modules/eslint/bin/eslint.js","firewall:check": "node scripts/firewall.mjs check","firewall:stage": "node scripts/firewall.mjs stage",- "postinstall": "patch-package && node scripts/check-mediabunny-patch.mjs && prisma generate && node scripts/copy-mediapipe-assets.mjs && node scripts/fetch-cut-fonts.mjs && node scripts/stage-frame-synth.mjs",+ "postinstall": "patch-package && node scripts/check-mediabunny-patch.mjs && prisma generate && node scripts/copy-mediapipe-assets.mjs && node scripts/stage-cut-fonts.mjs && node scripts/stage-frame-synth.mjs","db:generate": "prisma generate","db:pull": "prisma db pull","prisma:dev": "dotenv -e .env.development -- npx prisma migrate dev",@@ -68,13 +68,31 @@"@earendil-works/pi-agent-core": "0.84.1","@earendil-works/pi-ai": "0.84.1","@elevenlabs/elevenlabs-js": "^2.49.1",+ "@fontsource/anton": "^5.3.0",+ "@fontsource/archivo-black": "^5.3.0",+ "@fontsource/bangers": "^5.3.0",+ "@fontsource/bebas-neue": "^5.3.0",+ "@fontsource/caveat": "^5.3.0",+ "@fontsource/dm-serif-display": "^5.3.0",+ "@fontsource/inter": "^5.3.0",+ "@fontsource/lobster": "^5.3.0",+ "@fontsource/montserrat": "^5.3.0",+ "@fontsource/noto-serif": "^5.3.0",+ "@fontsource/nunito": "^5.3.0",+ "@fontsource/oswald": "^5.3.0",+ "@fontsource/pacifico": "^5.3.0",+ "@fontsource/permanent-marker": "^5.3.0",+ "@fontsource/playfair-display": "^5.3.0",+ "@fontsource/poppins": "^5.3.0",+ "@fontsource/roboto": "^5.3.0",+ "@fontsource/roboto-mono": "^5.3.0",+ "@fontsource/space-grotesk": "^5.3.0","@google/genai": "2.21.0","@mdx-js/loader": "^3.1.1","@mdx-js/react": "^3.1.1","@mdxeditor/editor": "^4.2.4","@mediabunny/prores": "^1.55.1","@mediabunny/server": "^1.55.1",- "node-av": "^6.1.1","@mediapipe/tasks-vision": "^1.0.1","@modelcontextprotocol/client": "^2.0.0","@modelcontextprotocol/core": "^2.0.0",@@ -99,12 +117,14 @@"cn": "^0.2.6","date-fns": "^4.4.0","defuddle": "^0.18.1",+ "geist": "^1.7.2","lexical": "^0.48.0","linkedom": "^0.18.12","lucide-react": "^1.23.0","mediabunny": "^1.55.5","next": "16.3.4","next-mdx-remote": "^6.0.0",+ "node-av": "^6.1.1","node-web-audio-api": "^2.2.0","onnxruntime-web": "1.29.0","openai": "^6.39.0",diff --git a/site/scripts/fetch-cut-fonts.mjs b/site/scripts/fetch-cut-fonts.mjsdeleted file mode 100644index a896a773..00000000--- a/site/scripts/fetch-cut-fonts.mjs+++ /dev/null@@ -1,136 +0,0 @@-// Stage the Cut font files into public/ so a headless render draws text with-// the same faces the editor shows. The page gets these families from-// next/font/google, which downloads them during `next build` and serves them-// under hashed names — fine for a browser, useless to a render worker that-// needs a file path to hand skia. So the same faces are staged here under-// stable names, with a manifest the headless bootstrap reads.-//-// The alias-only families at the bottom cover the base system set (SF Pro,-// New York, Impact…). Those live on a Mac and nowhere else, so a Linux-// container would draw tofu for the default font; the aliases register a-// close stand-in under each name the CSS stacks ask for.-//-// Files are fetched once and kept, so a re-install is free and an offline one-// keeps working. Runs from postinstall; a failure warns and leaves whatever-// is already staged.-import { mkdirSync, readdirSync, writeFileSync } from "node:fs";-import path from "node:path";-import { fileURLToPath } from "node:url";--const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));-const dest = path.join(root, "public", "cut-fonts");--/** Keep in step with googleFonts.ts, which registers the same families for- * the page. An id here is a Cut font id; a family with no id is a stand-in. */-const FAMILIES = [- { id: "inter", label: "Inter", family: "Inter", weights: [400, 700] },- { id: "montserrat", label: "Montserrat", family: "Montserrat", weights: [400, 700] },- { id: "poppins", label: "Poppins", family: "Poppins", weights: [400, 700] },- { id: "oswald", label: "Oswald", family: "Oswald", weights: [400, 700] },- { id: "space-grotesk", label: "Space Grotesk", family: "Space Grotesk", weights: [400, 700] },- { id: "playfair", label: "Playfair Display", family: "Playfair Display", weights: [400, 700] },- { id: "caveat", label: "Caveat", family: "Caveat", weights: [400, 700] },- { id: "bebas", label: "Bebas Neue", family: "Bebas Neue", weights: [400] },- {- id: "anton",- label: "Anton",- family: "Anton",- weights: [400],- aliases: ["Impact", "Arial Black"],- },- { id: "archivo-black", label: "Archivo Black", family: "Archivo Black", weights: [400] },- { id: "bangers", label: "Bangers", family: "Bangers", weights: [400] },- { id: "lobster", label: "Lobster", family: "Lobster", weights: [400] },- { id: "pacifico", label: "Pacifico", family: "Pacifico", weights: [400] },- { id: "permanent-marker", label: "Permanent Marker", family: "Permanent Marker", weights: [400] },- { id: "dm-serif", label: "DM Serif Display", family: "DM Serif Display", weights: [400] },- {- family: "Roboto",- weights: [400, 700],- aliases: [- "-apple-system",- "system-ui",- "SF Pro Display",- "SF Pro Text",- "Helvetica Neue",- "Helvetica",- "Arial",- "sans-serif",- ],- },- {- family: "Noto Serif",- weights: [400, 700],- aliases: ["New York", "ui-serif", "Georgia", "Times New Roman", "serif"],- },- {- family: "Nunito",- weights: [400, 700],- aliases: ["ui-rounded", "SF Pro Rounded", "Arial Rounded MT Bold"],- },- {- family: "Roboto Mono",- weights: [400, 700],- aliases: ["ui-monospace", "SF Mono", "Menlo", "Courier New", "monospace"],- },-];--// A browser UA gets woff2 back; skia reads it, and it is a fraction of a ttf.-const UA =- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0 Safari/537.36";--const slug = (family) => family.toLowerCase().replace(/[^a-z0-9]+/g, "-");--/** The latin-subset file URL for each weight of one family. Blocks arrive one- * per subset, each headed by its /* subset *\/ comment; latin carries the- * characters a title is written in. */-async function faceUrls(family, weights) {- const spec = `${family.replace(/ /g, "+")}:wght@${weights.join(";")}`;- const res = await fetch(`https://fonts.googleapis.com/css2?family=${spec}&display=swap`, {- headers: { "User-Agent": UA },- });- if (!res.ok) throw new Error(`css2 answered ${res.status}`);- const css = await res.text();- const found = new Map();- for (const [, subset, body] of css.matchAll(/\/\*\s*([\w-]+)\s*\*\/\s*@font-face\s*\{([^}]*)\}/g)) {- if (subset !== "latin") continue;- const weight = Number(body.match(/font-weight:\s*(\d+)/)?.[1]);- const url = body.match(/src:\s*url\((https:[^)]+)\)/)?.[1];- if (weight && url && !found.has(weight)) found.set(weight, url);- }- return found;-}--mkdirSync(dest, { recursive: true });-const staged = new Set(readdirSync(dest));-const manifest = [];-for (const entry of FAMILIES) {- const fileFor = (weight) => `${slug(entry.family)}-${weight}.woff2`;- const files = entry.weights.map(fileFor);- try {- if (files.some((f) => !staged.has(f))) {- const urls = await faceUrls(entry.family, entry.weights);- for (const weight of entry.weights) {- const name = fileFor(weight);- if (staged.has(name)) continue;- const url = urls.get(weight);- if (!url) throw new Error(`no latin face at weight ${weight}`);- const res = await fetch(url, { headers: { "User-Agent": UA } });- if (!res.ok) throw new Error(`weight ${weight} answered ${res.status}`);- writeFileSync(path.join(dest, name), Buffer.from(await res.arrayBuffer()));- staged.add(name);- }- }- manifest.push({- ...(entry.id ? { id: entry.id, label: entry.label } : {}),- family: entry.family,- ...(entry.aliases ? { aliases: entry.aliases } : {}),- files,- });- } catch (err) {- // One family that will not come down is one font a headless render falls- // back for; the rest still stage.- console.warn(`fetch-cut-fonts: ${entry.family}: ${err instanceof Error ? err.message : err}`);- }-}-writeFileSync(path.join(dest, "manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`);diff --git a/site/scripts/stage-cut-fonts.mjs b/site/scripts/stage-cut-fonts.mjsnew file mode 100644index 00000000..c2fa04fc--- /dev/null+++ b/site/scripts/stage-cut-fonts.mjs@@ -0,0 +1,98 @@+// Stage the Cut font files into public/ so a headless render draws text with+// the same faces the editor shows. The page declares these families from the+// @fontsource stylesheets (googleFonts.ts); a render worker hands skia a file+// path instead, so the latin face of each weight is copied here from the same+// packages under stable names, with a manifest the headless bootstrap reads.+//+// The alias-only families at the bottom cover the base system set (SF Pro,+// New York, Impact…). Those live on a Mac and nowhere else, so a Linux+// container would draw tofu for the default font; the aliases register a+// close stand-in under each name the CSS stacks ask for.+//+// Runs from postinstall and reads only node_modules, so it needs no network.+// A missing face fails the install: the package versions pin the files.+import { copyFileSync, mkdirSync, rmSync, writeFileSync } from "node:fs";+import { createRequire } from "node:module";+import path from "node:path";+import { fileURLToPath } from "node:url";++const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));+const dest = path.join(root, "public", "cut-fonts");+const require = createRequire(import.meta.url);++/** Keep in step with googleFonts.ts, which declares the same families for+ * the page. An id here is a Cut font id; a family with no id is a stand-in. */+const FAMILIES = [+ { id: "inter", label: "Inter", family: "Inter", weights: [400, 700] },+ { id: "montserrat", label: "Montserrat", family: "Montserrat", weights: [400, 700] },+ { id: "poppins", label: "Poppins", family: "Poppins", weights: [400, 700] },+ { id: "oswald", label: "Oswald", family: "Oswald", weights: [400, 700] },+ { id: "space-grotesk", label: "Space Grotesk", family: "Space Grotesk", weights: [400, 700] },+ { id: "playfair", label: "Playfair Display", family: "Playfair Display", weights: [400, 700] },+ { id: "caveat", label: "Caveat", family: "Caveat", weights: [400, 700] },+ { id: "bebas", label: "Bebas Neue", family: "Bebas Neue", weights: [400] },+ {+ id: "anton",+ label: "Anton",+ family: "Anton",+ weights: [400],+ aliases: ["Impact", "Arial Black"],+ },+ { id: "archivo-black", label: "Archivo Black", family: "Archivo Black", weights: [400] },+ { id: "bangers", label: "Bangers", family: "Bangers", weights: [400] },+ { id: "lobster", label: "Lobster", family: "Lobster", weights: [400] },+ { id: "pacifico", label: "Pacifico", family: "Pacifico", weights: [400] },+ { id: "permanent-marker", label: "Permanent Marker", family: "Permanent Marker", weights: [400] },+ { id: "dm-serif", label: "DM Serif Display", family: "DM Serif Display", weights: [400] },+ {+ family: "Roboto",+ weights: [400, 700],+ aliases: [+ "-apple-system",+ "system-ui",+ "SF Pro Display",+ "SF Pro Text",+ "Helvetica Neue",+ "Helvetica",+ "Arial",+ "sans-serif",+ ],+ },+ {+ family: "Noto Serif",+ weights: [400, 700],+ aliases: ["New York", "ui-serif", "Georgia", "Times New Roman", "serif"],+ },+ {+ family: "Nunito",+ weights: [400, 700],+ aliases: ["ui-rounded", "SF Pro Rounded", "Arial Rounded MT Bold"],+ },+ {+ family: "Roboto Mono",+ weights: [400, 700],+ aliases: ["ui-monospace", "SF Mono", "Menlo", "Courier New", "monospace"],+ },+];++const slug = (family) => family.toLowerCase().replace(/[^a-z0-9]+/g, "-");++rmSync(dest, { recursive: true, force: true });+mkdirSync(dest, { recursive: true });+const manifest = [];+for (const entry of FAMILIES) {+ const pkg = slug(entry.family);+ const files = path.join(path.dirname(require.resolve(`@fontsource/${pkg}/package.json`)), "files");+ const staged = entry.weights.map((weight) => {+ const name = `${pkg}-${weight}.woff2`;+ copyFileSync(path.join(files, `${pkg}-latin-${weight}-normal.woff2`), path.join(dest, name));+ return name;+ });+ manifest.push({+ ...(entry.id ? { id: entry.id, label: entry.label } : {}),+ family: entry.family,+ ...(entry.aliases ? { aliases: entry.aliases } : {}),+ files: staged,+ });+}+writeFileSync(path.join(dest, "manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`);diff --git a/site/src/app/layout.tsx b/site/src/app/layout.tsxindex b8770885..374dc4df 100644--- a/site/src/app/layout.tsx+++ b/site/src/app/layout.tsx@@ -1,21 +1,12 @@import type { Metadata } from "next";-import { Geist, Geist_Mono } from "next/font/google";+import { GeistMono } from "geist/font/mono";+import { GeistSans } from "geist/font/sans";import "./globals.css";import { DONKEYCUT_CANONICAL } from "@/cut/lib/hosts";import { QueryProvider } from "@/queries/QueryProvider";import { PostHogProvider } from "./_components/PostHogProvider";-const geistSans = Geist({- variable: "--font-geist-sans",- subsets: ["latin"],-});--const geistMono = Geist_Mono({- variable: "--font-geist-mono",- subsets: ["latin"],-});-export const metadata: Metadata = {// The base every relative card and canonical URL resolves against. Left// unset, Next reads the request's own host to resolve them, which makes the@@ -48,7 +39,7 @@ export default function RootLayout({return (<htmllang="en"- className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}+ className={`${GeistSans.variable} ${GeistMono.variable} h-full antialiased`}><body className="min-h-full flex flex-col"><PostHogProvider>diff --git a/site/src/cut/lib/fontCatalog.ts b/site/src/cut/lib/fontCatalog.tsindex 3a080b3f..b3a8ab09 100644--- a/site/src/cut/lib/fontCatalog.ts+++ b/site/src/cut/lib/fontCatalog.ts@@ -1,10 +1,11 @@/*** The bundled font families, named once.*- * `googleFonts.ts` maps the next/font loaders onto this list to register them,- * and the assistant's catalog builds its font sentence from it, so the menu the- * user sees and the ids the model is taught can't drift apart. Framework-free- * on purpose: the server imports it too.+ * `googleFonts.ts` registers this list for the page, and the assistant's+ * catalog builds its font sentence from it, so the menu the user sees and the+ * ids the model is taught can't drift apart. A label is the family's own name,+ * the one its stylesheet and the headless renderer declare it under.+ * Framework-free on purpose: the server imports it too.*/export interface BundledFont {diff --git a/site/src/cut/lib/googleFonts.ts b/site/src/cut/lib/googleFonts.tsindex 453b0dcc..6134562a 100644--- a/site/src/cut/lib/googleFonts.ts+++ b/site/src/cut/lib/googleFonts.ts@@ -1,67 +1,38 @@"use client";/**- * The bundled Google font families, self-hosted at build time via- * next/font/google — the loader downloads the files during `next build` and- * serves them from our origin, so nothing fetches Google at runtime and a- * rasterize is deterministic offline. Importing this module (the editor root- * does) registers every family into the shared font registry.+ * The bundled Google font families, self-hosted from the @fontsource packages.+ * Their stylesheets declare one face per unicode subset, served from our+ * origin, so nothing fetches Google at build or run time and a rasterize is+ * deterministic offline. Each family is declared under its own name, the name+ * the catalog labels it with and the headless renderer loads it under.+ * Importing this module (the editor root does) registers every family into the+ * shared font registry.*/-import {- Anton,- Archivo_Black,- Bangers,- Bebas_Neue,- Caveat,- DM_Serif_Display,- Inter,- Lobster,- Montserrat,- Oswald,- Pacifico,- Permanent_Marker,- Playfair_Display,- Poppins,- Space_Grotesk,-} from "next/font/google";+import "@fontsource/inter/400.css";+import "@fontsource/inter/700.css";+import "@fontsource/montserrat/400.css";+import "@fontsource/montserrat/700.css";+import "@fontsource/poppins/400.css";+import "@fontsource/poppins/700.css";+import "@fontsource/oswald/400.css";+import "@fontsource/oswald/700.css";+import "@fontsource/space-grotesk/400.css";+import "@fontsource/space-grotesk/700.css";+import "@fontsource/playfair-display/400.css";+import "@fontsource/playfair-display/700.css";+import "@fontsource/caveat/400.css";+import "@fontsource/caveat/700.css";+import "@fontsource/bebas-neue/400.css";+import "@fontsource/anton/400.css";+import "@fontsource/archivo-black/400.css";+import "@fontsource/bangers/400.css";+import "@fontsource/lobster/400.css";+import "@fontsource/pacifico/400.css";+import "@fontsource/permanent-marker/400.css";+import "@fontsource/dm-serif-display/400.css";import { GOOGLE_FONTS } from "./fontCatalog";import { registerFonts } from "./types";-const inter = Inter({ subsets: ["latin"], weight: ["400", "700"], preload: false });-const montserrat = Montserrat({ subsets: ["latin"], weight: ["400", "700"], preload: false });-const poppins = Poppins({ subsets: ["latin"], weight: ["400", "700"], preload: false });-const oswald = Oswald({ subsets: ["latin"], weight: ["400", "700"], preload: false });-const spaceGrotesk = Space_Grotesk({ subsets: ["latin"], weight: ["400", "700"], preload: false });-const playfair = Playfair_Display({ subsets: ["latin"], weight: ["400", "700"], preload: false });-const caveat = Caveat({ subsets: ["latin"], weight: ["400", "700"], preload: false });-const bebas = Bebas_Neue({ subsets: ["latin"], weight: "400", preload: false });-const anton = Anton({ subsets: ["latin"], weight: "400", preload: false });-const archivoBlack = Archivo_Black({ subsets: ["latin"], weight: "400", preload: false });-const bangers = Bangers({ subsets: ["latin"], weight: "400", preload: false });-const lobster = Lobster({ subsets: ["latin"], weight: "400", preload: false });-const pacifico = Pacifico({ subsets: ["latin"], weight: "400", preload: false });-const permanentMarker = Permanent_Marker({ subsets: ["latin"], weight: "400", preload: false });-const dmSerifDisplay = DM_Serif_Display({ subsets: ["latin"], weight: "400", preload: false });--// One stack per bundled id; the list itself lives in fontCatalog.ts, which the-// assistant's catalog reads too.-const STACKS: Record<string, string> = {- inter: inter.style.fontFamily,- montserrat: montserrat.style.fontFamily,- poppins: poppins.style.fontFamily,- oswald: oswald.style.fontFamily,- "space-grotesk": spaceGrotesk.style.fontFamily,- playfair: playfair.style.fontFamily,- caveat: caveat.style.fontFamily,- bebas: bebas.style.fontFamily,- anton: anton.style.fontFamily,- "archivo-black": archivoBlack.style.fontFamily,- bangers: bangers.style.fontFamily,- lobster: lobster.style.fontFamily,- pacifico: pacifico.style.fontFamily,- "permanent-marker": permanentMarker.style.fontFamily,- "dm-serif": dmSerifDisplay.style.fontFamily,-};--registerFonts(GOOGLE_FONTS.map((f) => ({ ...f, stack: STACKS[f.id] })));+registerFonts(GOOGLE_FONTS.map((f) => ({ ...f, stack: `"${f.label}"` })));diff --git a/site/src/cut/lib/headless/nodeFonts.ts b/site/src/cut/lib/headless/nodeFonts.tsindex aa7596bf..1585a6da 100644--- a/site/src/cut/lib/headless/nodeFonts.ts+++ b/site/src/cut/lib/headless/nodeFonts.ts@@ -5,11 +5,11 @@ import { registerFonts } from "../types";/*** Fonts for a headless render.*- * A page gets its faces from next/font, which serves them to the browser and- * hands the painters a CSS stack. Nothing in that reaches a render worker, so- * the same faces are staged as files by scripts/fetch-cut-fonts.mjs and- * loaded into skia here, under both their own names and the names the base- * system stacks ask for ("SF Pro Display", "Impact", "New York"). After this+ * A page gets its faces from the @fontsource stylesheets, which serve them to+ * the browser. Nothing in that reaches a render worker, so the same faces are+ * staged as files by scripts/stage-cut-fonts.mjs and loaded into skia here,+ * under both their own names and the names the base system stacks ask for+ * ("SF Pro Display", "Impact", "New York"). After this* runs, `fontStack` resolves every Cut font id to a family skia can draw, and* a title rendered headless looks like the title in the tab.*diff --git a/site/src/cut/lib/types.ts b/site/src/cut/lib/types.tsindex 8c7f9073..c75a3c8d 100644--- a/site/src/cut/lib/types.ts+++ b/site/src/cut/lib/types.ts@@ -1250,8 +1250,8 @@ export const FONTS: FontDef[] = [{ id: "impact", label: "Impact", stack: 'Impact, "Arial Black", "Helvetica Neue", sans-serif' },];-// Fonts registered at runtime: the bundled Google families (build-time-// self-hosted via next/font) and per-project uploaded fonts. The page+// Fonts registered at runtime: the bundled Google families (self-hosted+// from @fontsource) and per-project uploaded fonts. The page// registers them before text renders; the engine imports this module but// never rasterizes, so an empty registry there is fine.const registeredFonts: FontDef[] = [];diff --git a/site/src/cut/worker/Dockerfile b/site/src/cut/worker/Dockerfileindex 43c1b174..98b52ced 100644--- a/site/src/cut/worker/Dockerfile+++ b/site/src/cut/worker/Dockerfile@@ -62,11 +62,9 @@ RUN npm install --no-package-lock --omit=dev \node-web-audio-api@^2.2.0COPY dist/cut-worker/main.js ./main.js# The faces the editor shows, staged as files the canvas loads at startup so a-# title renders in its own font. Fetched here so the image carries them-# whatever state the build context is in; a family that will not come down-# leaves the rest staged and falls back at draw time.-COPY scripts/fetch-cut-fonts.mjs ./scripts/fetch-cut-fonts.mjs-RUN node scripts/fetch-cut-fonts.mjs+# title renders in its own font. npm install stages them from the @fontsource+# packages (scripts/stage-cut-fonts.mjs).+COPY public/cut-fonts ./public/cut-fontsENV NODE_ENV=productionENTRYPOINT ["node", "main.js"]