Agent-driven creation of editable, tastefully crafted visual artifacts.
Python
feat: add self-hosted typography kit
yejy53463046fb8526
diff --git a/README.md b/README.mdindex b83a946..626947a 100644--- a/README.md+++ b/README.md@@ -72,7 +72,7 @@ This repository now ships the code behind the workflow as two independent CodexInstall and initialize the editable-design Codex Skill from:https://github.com/yejy53/Editable-Design/tree/main/skills/editable-design- Run its dependency setup and doctor check after installation.+ Install its runtime dependencies and font kit, then run its doctor check.```2. Start a new Codex task, then describe the visual you want to create. For example:@@ -98,6 +98,7 @@ git sparse-checkout set skills/editable-designmkdir -p ~/.codex/skillscp -R skills/editable-design ~/.codex/skills/npm ci --prefix ~/.codex/skills/editable-design/scripts+~/.codex/skills/editable-design/scripts/install-font-kit.sh~/.codex/skills/editable-design/scripts/doctor.sh```diff --git a/TOOLKIT.md b/TOOLKIT.mdindex cf7c641..782c9cf 100644--- a/TOOLKIT.md+++ b/TOOLKIT.md@@ -33,9 +33,13 @@ Install the Editable Design runtime dependency and verify the browser setup:```bashnpm ci --prefix ~/.codex/skills/editable-design/scripts+~/.codex/skills/editable-design/scripts/install-font-kit.sh~/.codex/skills/editable-design/scripts/doctor.sh```+The font kit is self-hosted and versioned. Each generated project copies only+the WOFF2 files it selects, rather than carrying the full library.+For optional PowerPoint export, install its Python dependencies and Playwright browser:```bashdiff --git a/skills/editable-design/README.md b/skills/editable-design/README.mdindex 0271664..c3534c0 100644--- a/skills/editable-design/README.md+++ b/skills/editable-design/README.md@@ -13,9 +13,14 @@ Install the browser validation dependency once:```bashnpm ci --prefix scripts+scripts/install-font-kit.shscripts/doctor.sh```+The font-kit step installs a curated set of open-source Fontsource packages.+Generated projects copy only the WOFF2 files they actually use, together with+the corresponding license; the entire kit is never copied into one design.+Set `EDITABLE_DESIGN_BROWSER=/path/to/chromium` only when automatic browser discovery fails.Editable PPTX is provided by the separate companion skill `html-to-pptx`. Editable Design never exports PPTX unless the user asks for it after the core design is complete.diff --git a/skills/editable-design/SKILL.md b/skills/editable-design/SKILL.mdindex 8db0ab4..550d749 100644--- a/skills/editable-design/SKILL.md+++ b/skills/editable-design/SKILL.md@@ -317,6 +317,10 @@ focused pass. Trace only the stable artifacts named below.decision once in `design-plan.md`. When two or more shipping assets arerequired, also write the minimal machine-readable `asset-plan.json` fromthat same decision. Record both together under `P11_asset_plan`.+ When typography is a primary visual material or the editor needs stronger+ alternatives, read [Font system](references/font-system.md), choose fonts by+ role, and use the self-hosted kit rather than defaulting to the same system+ sans/serif pair.5. **Generate the artwork** per the batching, retry, import, and inspectionpolicy above, into `assets/`. Record the completed batch once. In multi-assetruns, every@@ -327,6 +331,9 @@ focused pass. Trace only the stable artifacts named below.requests, absolute positioning inside the canvas, fixed px for every layoutdimension. Declare the palette and font stacks on `:root` and reference themthroughout. Do not write comments.+ When the plan selects a bundled font, run `scripts/font-kit.mjs add <id>+ index.html` after the HTML exists, then assign its generated+ `--font-kit-<id>` variable to the intended type roles before checking fonts.For selected Lucide icons, resolve them from the bundled runtime at buildtime and inline only their SVG markup in the poster HTML; keep their size,stroke width, and color treatment consistent, and add no runtime import.@@ -421,6 +428,11 @@ contains them.Use as many families as the composition genuinely needs while preserving acoherent hierarchy. Every step of the size ramp must be clearly differentfrom the last.+- Distinguish the active type system from the editor palette. A poster normally+ uses two or three families, while three to five verified `:root` font roles+ may be exposed as meaningful alternatives. For a poster, cover, flyer, or+ campaign, do not ship only one generic sans stack unless the brief or brand+ deliberately requires it.- For vertical CJK type, set `white-space: nowrap` and centre it with flex.`text-align` controls the vertical axis under `writing-mode`, so a fixed-widthbox leaves the text against its right edge.@@ -429,6 +441,8 @@ contains them.image being dark enough exactly where you need it.- Do not default to a coloured or black text box: first use an existing calm region or a local scrim, and add a panel only when its material, edges, palette, and overlap make it an intentional part of the composition rather than a generic card.- When unsure about the layout, read [Layout and typography](references/layout-typography.md).+- When typography is prominent or the available choices feel generic, read+ [Font system](references/font-system.md) and use its self-hosted font kit.### Build the default editing contractdiff --git a/skills/editable-design/THIRD_PARTY_NOTICES.md b/skills/editable-design/THIRD_PARTY_NOTICES.mdindex 1f187a9..c64c7f9 100644--- a/skills/editable-design/THIRD_PARTY_NOTICES.md+++ b/skills/editable-design/THIRD_PARTY_NOTICES.md@@ -4,6 +4,7 @@ Editable Design uses or interoperates with the following third-party software. D- `puppeteer-core` — Apache License 2.0.- Puppeteer's transitive npm dependencies — Apache-2.0, MIT, ISC, BSD-2-Clause, BSD-3-Clause, and 0BSD packages as recorded in `scripts/package-lock.json`.+- Fontsource font packages — SIL Open Font License 1.1, as recorded in `font-kit/package-lock.json`. Generated projects copy the selected font's license alongside its WOFF2 files.- Pillow — HPND License; optional local cutout-processing dependency.Generated or user-supplied artwork is not included in this repository's license merely because it is processed by the skill. Bundled Editable Design runtime files retain their Apache-2.0 license when copied into generated projects.diff --git a/skills/editable-design/font-kit/package-lock.json b/skills/editable-design/font-kit/package-lock.jsonnew file mode 100644index 0000000..da64893--- /dev/null+++ b/skills/editable-design/font-kit/package-lock.json@@ -0,0 +1,115 @@+{+ "name": "editable-design-font-kit",+ "version": "0.1.0",+ "lockfileVersion": 3,+ "requires": true,+ "packages": {+ "": {+ "name": "editable-design-font-kit",+ "version": "0.1.0",+ "license": "Apache-2.0",+ "dependencies": {+ "@fontsource-variable/bodoni-moda": "5.3.0",+ "@fontsource-variable/fraunces": "5.3.0",+ "@fontsource-variable/instrument-sans": "5.3.0",+ "@fontsource-variable/noto-sans-sc": "5.3.0",+ "@fontsource-variable/noto-serif-sc": "5.3.0",+ "@fontsource-variable/roboto-condensed": "5.3.0",+ "@fontsource-variable/space-grotesk": "5.3.0",+ "@fontsource-variable/unbounded": "5.3.0",+ "@fontsource/ma-shan-zheng": "5.3.1",+ "@fontsource/zcool-xiaowei": "5.3.0"+ }+ },+ "node_modules/@fontsource-variable/bodoni-moda": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource-variable/bodoni-moda/-/bodoni-moda-5.3.0.tgz",+ "integrity": "sha512-yTDXk4+/J8I20KjtkHBbXDQNeE5PR3BZa0gv/YRza+kyxsz+mmg0la/n/hsr6+WvSfVP7Lc8lRTjHGIYwBW43A==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource-variable/fraunces": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource-variable/fraunces/-/fraunces-5.3.0.tgz",+ "integrity": "sha512-9BYGySn4AHEJdgp9Z28tQ3X+laJMEOITXkQarZXeloWQZDq5oOvXJ3kDA8c7MGIfpogIaZfjrQBqmda8POOCKA==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource-variable/instrument-sans": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource-variable/instrument-sans/-/instrument-sans-5.3.0.tgz",+ "integrity": "sha512-u4gKbDBTNFGkg997tfQn3eHOhHuquWUFTRT/rwzuKtrxX5P2ekfs2x+LgBPP4P32+cC+vUwF1Cr+IdRoPQbrGw==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource-variable/noto-sans-sc": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource-variable/noto-sans-sc/-/noto-sans-sc-5.3.0.tgz",+ "integrity": "sha512-lNar1dF7Ik/lHNPo/7JWG0TolXY29LtsqYgMvEysooZ5bsO9uH4shJmRrwyJ3PjyTPljhpMJEK0jDuLSU4vJ1w==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource-variable/noto-serif-sc": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource-variable/noto-serif-sc/-/noto-serif-sc-5.3.0.tgz",+ "integrity": "sha512-7LcN2NEf4HDjoSkGWc79WqDDyMK8JvSPdA/gsHjJpZ8l9A9mcK/GQTazp3klmkBwJooy0eqeNvlmaZFXPupHrA==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource-variable/roboto-condensed": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource-variable/roboto-condensed/-/roboto-condensed-5.3.0.tgz",+ "integrity": "sha512-RpYyF6G0h0nsVcCDLRIbZbK+l8cVDoe1PVbzvzVhtLzCiPqIEEGDs9xB9ZWPJawKS4bJzpKn42KgZFISF/AOuQ==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource-variable/space-grotesk": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource-variable/space-grotesk/-/space-grotesk-5.3.0.tgz",+ "integrity": "sha512-2IxmvfB08i9vnGB3Ym/AXvhRE+8XOjWMXIyDum03c+tPwH0FUoMNQfGpU8NXPxjbws0Vvss3AH0Zqt4oJBBAdw==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource-variable/unbounded": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource-variable/unbounded/-/unbounded-5.3.0.tgz",+ "integrity": "sha512-ea565Ncn4r7gPdBEHcmaF31V11hDfkL7b/JCklLobQbMfbu2ZZQrVWNgdeEFWFLqNh36yhieZWOgxdAnMTzrLg==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/ma-shan-zheng": {+ "version": "5.3.1",+ "resolved": "https://registry.npmjs.org/@fontsource/ma-shan-zheng/-/ma-shan-zheng-5.3.1.tgz",+ "integrity": "sha512-cGGn7Yje2RSduXVxEk+rCfNZyD/T/7FMGj03LNPiK8TRL9Sing0tq1zJF3n+W29szPqgb2RNs5oIvmm+ikeI+Q==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ },+ "node_modules/@fontsource/zcool-xiaowei": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/@fontsource/zcool-xiaowei/-/zcool-xiaowei-5.3.0.tgz",+ "integrity": "sha512-iRuUPl9ONFbYzi6JcEshpE4VedINyzQ4hv0Z5XEt0cB0pMPiQeqc2Qvv1NwJCNzkPwG02VCdcO+cF2K8ylYn2A==",+ "license": "OFL-1.1",+ "funding": {+ "url": "https://github.com/sponsors/ayuhito"+ }+ }+ }+}diff --git a/skills/editable-design/font-kit/package.json b/skills/editable-design/font-kit/package.jsonnew file mode 100644index 0000000..fe1f19c--- /dev/null+++ b/skills/editable-design/font-kit/package.json@@ -0,0 +1,19 @@+{+ "name": "editable-design-font-kit",+ "version": "0.1.0",+ "private": true,+ "description": "Curated, self-hosted open-source fonts for Editable Design",+ "license": "Apache-2.0",+ "dependencies": {+ "@fontsource-variable/bodoni-moda": "5.3.0",+ "@fontsource-variable/fraunces": "5.3.0",+ "@fontsource-variable/instrument-sans": "5.3.0",+ "@fontsource-variable/noto-sans-sc": "5.3.0",+ "@fontsource-variable/noto-serif-sc": "5.3.0",+ "@fontsource-variable/roboto-condensed": "5.3.0",+ "@fontsource-variable/space-grotesk": "5.3.0",+ "@fontsource-variable/unbounded": "5.3.0",+ "@fontsource/ma-shan-zheng": "5.3.1",+ "@fontsource/zcool-xiaowei": "5.3.0"+ }+}diff --git a/skills/editable-design/pack.sh b/skills/editable-design/pack.shindex bd3c26d..3d0992f 100755--- a/skills/editable-design/pack.sh+++ b/skills/editable-design/pack.sh@@ -8,6 +8,7 @@ out="${1:-${TMPDIR:-/tmp}/editable-design-skill.tar.gz}"mkdir -p "$(dirname "$out")"tar \--exclude='editable-design/scripts/node_modules' \+ --exclude='editable-design/font-kit/node_modules' \--exclude='editable-design/._*' \--exclude='editable-design/*/._*' \--exclude='editable-design/*/*/._*' \diff --git a/skills/editable-design/references/font-system.md b/skills/editable-design/references/font-system.mdnew file mode 100644index 0000000..51a5118--- /dev/null+++ b/skills/editable-design/references/font-system.md@@ -0,0 +1,89 @@+# Font system++Read this when typography carries the design, when the brief needs a distinctive+editorial voice, or when the visual editor needs more useful alternatives than+the platform defaults.++## Two different counts++The **active type system** and the **editable font palette** are not the same.++- A finished poster normally uses two or three families: one display voice, one+ text voice, and optionally one utility or accent voice.+- The editor may expose three to five verified font variables so a user has+ meaningful alternatives. Do not use every exposed family in the composition.++For a poster, cover, flyer, or campaign, declare at least three meaningfully+different selectable font roles unless the brief deliberately specifies a+single-family identity. A body sans, another nearly identical sans, and the+same sans at a different weight are not three roles.++## Curated self-hosted kit++The optional font kit uses versioned Fontsource packages and local WOFF2 files.+Install it once:++```bash+scripts/install-font-kit.sh+```++Inspect the available design roles:++```bash+node scripts/font-kit.mjs list+```++Add only the selected families to a poster. The command copies the required+WOFF2 files and license into `assets/fonts/`, injects local `@font-face` rules,+and exposes a `--font-kit-*` variable to the editor:++```bash+node scripts/font-kit.mjs add editorial-serif index.html+node scripts/font-kit.mjs add clean-sans index.html+node scripts/font-kit.mjs add cjk-serif index.html+```++Available roles:++| ID | Voice | Best use |+| --- | --- | --- |+| `editorial-serif` | Fraunces Variable | expressive editorial and cultural headlines |+| `luxury-serif` | Bodoni Moda Variable | fashion, beauty, luxury, magazine covers |+| `clean-sans` | Instrument Sans Variable | refined campaigns and editorial body copy |+| `geometric-sans` | Space Grotesk Variable | technology, information, contemporary labels |+| `condensed-sans` | Roboto Condensed Variable | dense layouts, deck lines, prices, utilities |+| `experimental-display` | Unbounded Variable | art, music, youth, experimental display |+| `cjk-sans` | Noto Sans SC Variable | Chinese body copy, campaigns, information design |+| `cjk-serif` | Noto Serif SC Variable | Chinese editorial, culture, literature, premium display |+| `cjk-calligraphy` | Ma Shan Zheng | short Chinese handwritten accents and titles |+| `cjk-display` | ZCOOL XiaoWei | distinctive Chinese editorial display titles |++Self-hosted fonts are preferred when reproducibility matters. System fonts may+still be used when their exact voice is appropriate and `check-fonts.sh`+confirms they are installed.++## Pairing by contrast++Choose pairs that differ in structure, not merely in weight:++- luxury campaign: `luxury-serif` + `clean-sans`+- editorial or culture: `editorial-serif` + `clean-sans`+- technical information: `geometric-sans` + `condensed-sans`+- Chinese editorial: `cjk-serif` + `cjk-sans`, optionally a Latin display face+- Chinese expressive poster: `cjk-display` or `cjk-calligraphy` for short display+ copy, with `cjk-sans` or `cjk-serif` for everything longer+- experimental art: `experimental-display` + a quiet sans or serif++Do not set paragraphs in a display or calligraphic face. Do not use synthetic+bold or italics on CJK fonts that do not supply those styles. Mixed Chinese and+Latin display lines may use separate editable spans when the intended Latin+voice would otherwise disappear behind the CJK family.++## Shipping rules++- Use local relative font URLs only; never depend on Google Fonts or another+ runtime network request.+- Copy only fonts selected for the current design.+- Keep each copied `LICENSE.txt` with its font files.+- Run `scripts/check-fonts.sh index.html` after font injection and before render.+- Wait for `document.fonts.ready` before measuring, baking, or capturing.diff --git a/skills/editable-design/references/layout-typography.md b/skills/editable-design/references/layout-typography.mdindex 065f94b..4a8e370 100644--- a/skills/editable-design/references/layout-typography.md+++ b/skills/editable-design/references/layout-typography.md@@ -63,6 +63,12 @@ throughout. Give every family a distinct job and valid script coverage. Add afamily when the brand, reference, script, or typographic contrast requires it,not as decoration.+Do not confuse visual consistency with typographic sameness. A finished poster+usually activates two or three families, but its editor should expose three to+five verified and meaningfully different font roles when the format benefits+from later type changes. Read [Font system](font-system.md) for the curated local+font kit, pairing patterns, and shipping rules.+**Build a real size ramp.** display, headline, subhead, body, caption, eachclearly different from the last. A ramp with 10 percent steps reads as an error.diff --git a/skills/editable-design/scripts/check-fonts.sh b/skills/editable-design/scripts/check-fonts.shindex b4a4fe3..62957fa 100755--- a/skills/editable-design/scripts/check-fonts.sh+++ b/skills/editable-design/scripts/check-fonts.sh@@ -41,6 +41,39 @@ if [[ -z "$requested" ]]; thentest -f "$html" || { echo "no such file: $html" >&2; exit 2; }fi+bundled_families=""+if [[ -n "$html" ]]; then+ bundled_families=$(+ perl -0ne '+ while (/\@font-face\s*\{(.*?)\}/sg) {+ $block = $1;+ if ($block =~ /font-family\s*:\s*(["'"'"']?)([^;"'"'"']+)\1\s*;/s) {+ $family = $2;+ $family =~ s/^\s+|\s+$//g;+ print "$family\n";+ }+ }+ ' "$html" | sort -u+ )++ html_dir="$(cd "$(dirname "$html")" && pwd)"+ missing_assets=0+ while IFS= read -r raw_url; do+ [[ -n "$raw_url" ]] || continue+ font_url="$(printf '%s' "$raw_url" | sed -e 's/^['"'"'"]//' -e 's/['"'"'"]$//' -e 's/[?#].*$//')"+ case "$font_url" in+ data:*|http://*|https://*) continue ;;+ esac+ if [[ ! -f "$html_dir/$font_url" ]]; then+ printf 'FAIL %-28s missing local font asset\n' "$font_url"+ missing_assets=$(( missing_assets + 1 ))+ fi+ done < <(+ perl -0ne 'while (/\@font-face\s*\{(.*?)\}/sg) { $b=$1; while ($b =~ /url\(([^)]+)\)/g) { print "$1\n" } }' "$html"+ )+ [[ "$missing_assets" -eq 0 ]] || exit 1+fi+# Collect every named family out of font-family declarations and --font-* custom# properties, dropping generic keywords and var() references.if [[ -n "$requested" ]]; then@@ -58,7 +91,22 @@ else)fi-[[ -n "$families" ]] || { echo "no named font families found in $html"; exit 0; }+if [[ -n "$bundled_families" ]]; then+ while IFS= read -r family; do+ [[ -n "$family" ]] || continue+ printf 'ok %-28s bundled @font-face\n' "$family"+ done <<< "$bundled_families"+ families=$(+ comm -23 \+ <(printf '%s\n' "$families" | sed '/^[[:space:]]*$/d' | sort -u) \+ <(printf '%s\n' "$bundled_families" | sed '/^[[:space:]]*$/d' | sort -u)+ )+fi++[[ -n "$families" ]] || {+ [[ -n "$bundled_families" ]] && echo "all named families are bundled and their local files exist" || echo "no named font families found in $html"+ exit 0+}browser="$("$here/render-poster.sh" --probe | awk '{ $1 = ""; sub(/^ +/, ""); print }')"[[ -n "$browser" && -x "$browser" ]] || {diff --git a/skills/editable-design/scripts/doctor.sh b/skills/editable-design/scripts/doctor.shindex a8e4e36..f0e2a0f 100755--- a/skills/editable-design/scripts/doctor.sh+++ b/skills/editable-design/scripts/doctor.sh@@ -28,6 +28,14 @@ elsebad "puppeteer-core" "run npm ci --prefix scripts"fi+font_kit="$here/../font-kit/node_modules"+if [[ -f "$font_kit/@fontsource-variable/fraunces/package.json" && -f "$font_kit/@fontsource-variable/noto-sans-sc/package.json" ]]; then+ font_count="$(find "$font_kit" -mindepth 3 -maxdepth 3 -name package.json | wc -l | tr -d ' ')"+ ok "Font kit" "$font_count curated packages"+else+ bad "Font kit" "run scripts/install-font-kit.sh"+fi+browser=""for candidate in "${EDITABLE_DESIGN_BROWSER:-}" "${PUPPETEER_EXECUTABLE_PATH:-}" "${POSTER_BROWSER:-}" "${CHROME_PATH:-}"; doif [[ -n "$candidate" && -x "$candidate" ]]; then browser="$candidate"; break; fidiff --git a/skills/editable-design/scripts/font-kit.mjs b/skills/editable-design/scripts/font-kit.mjsnew file mode 100755index 0000000..e74fdd8--- /dev/null+++ b/skills/editable-design/scripts/font-kit.mjs@@ -0,0 +1,187 @@+#!/usr/bin/env node+import fs from 'node:fs/promises';+import path from 'node:path';+import process from 'node:process';+import { fileURLToPath } from 'node:url';++const scriptDir = path.dirname(fileURLToPath(import.meta.url));+const skillDir = path.dirname(scriptDir);+const modulesDir = path.join(skillDir, 'font-kit', 'node_modules');++const fonts = {+ 'editorial-serif': {+ family: 'Fraunces Variable',+ package: '@fontsource-variable/fraunces',+ css: ['wght.css'],+ fallback: 'serif',+ coverage: 'Latin',+ role: 'expressive editorial headlines and culture posters'+ },+ 'luxury-serif': {+ family: 'Bodoni Moda Variable',+ package: '@fontsource-variable/bodoni-moda',+ css: ['wght.css'],+ fallback: 'serif',+ coverage: 'Latin',+ role: 'fashion, beauty, luxury, and magazine display type'+ },+ 'clean-sans': {+ family: 'Instrument Sans Variable',+ package: '@fontsource-variable/instrument-sans',+ css: ['wght.css'],+ fallback: 'sans-serif',+ coverage: 'Latin',+ role: 'clean editorial body copy and refined campaigns'+ },+ 'geometric-sans': {+ family: 'Space Grotesk Variable',+ package: '@fontsource-variable/space-grotesk',+ css: ['wght.css'],+ fallback: 'sans-serif',+ coverage: 'Latin',+ role: 'technology, information design, and contemporary labels'+ },+ 'condensed-sans': {+ family: 'Roboto Condensed Variable',+ package: '@fontsource-variable/roboto-condensed',+ css: ['wght.css'],+ fallback: 'sans-serif',+ coverage: 'Latin',+ role: 'dense posters, strong deck lines, prices, and utility copy'+ },+ 'experimental-display': {+ family: 'Unbounded Variable',+ package: '@fontsource-variable/unbounded',+ css: ['wght.css'],+ fallback: 'sans-serif',+ coverage: 'Latin',+ role: 'art, music, youth, and experimental display type'+ },+ 'cjk-sans': {+ family: 'Noto Sans SC Variable',+ package: '@fontsource-variable/noto-sans-sc',+ css: ['wght.css'],+ fallback: 'sans-serif',+ coverage: 'Simplified Chinese + Latin',+ role: 'clear Chinese body copy, information design, and campaigns'+ },+ 'cjk-serif': {+ family: 'Noto Serif SC Variable',+ package: '@fontsource-variable/noto-serif-sc',+ css: ['wght.css'],+ fallback: 'serif',+ coverage: 'Simplified Chinese + Latin',+ role: 'Chinese editorial, cultural, literary, and premium display type'+ },+ 'cjk-calligraphy': {+ family: 'Ma Shan Zheng',+ package: '@fontsource/ma-shan-zheng',+ css: ['400.css'],+ fallback: 'cursive',+ coverage: 'Simplified Chinese + Latin',+ role: 'short handwritten Chinese accents and expressive titles'+ },+ 'cjk-display': {+ family: 'ZCOOL XiaoWei',+ package: '@fontsource/zcool-xiaowei',+ css: ['400.css'],+ fallback: 'serif',+ coverage: 'Simplified Chinese + Latin',+ role: 'distinctive Chinese display titles with an editorial voice'+ }+};++function usage() {+ console.log('usage:');+ console.log(' node scripts/font-kit.mjs list');+ console.log(' node scripts/font-kit.mjs add FONT_ID HTML');+}++function list() {+ const rows = Object.entries(fonts).map(([id, font]) => ({+ id,+ family: font.family,+ coverage: font.coverage,+ role: font.role+ }));+ console.table(rows);+}++function stripCssComments(css) {+ return css.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\n{3,}/g, '\n\n').trim();+}++async function add(id, htmlArg) {+ const font = fonts[id];+ if (!font) throw new Error(`unknown font id: ${id}`);+ if (!htmlArg) throw new Error('missing HTML path');++ const htmlPath = path.resolve(htmlArg);+ const projectDir = path.dirname(htmlPath);+ const packageDir = path.join(modulesDir, ...font.package.split('/'));+ const packageJson = path.join(packageDir, 'package.json');+ try {+ await fs.access(packageJson);+ } catch {+ throw new Error(`font kit is not installed; run ${path.join(scriptDir, 'install-font-kit.sh')}`);+ }++ let html = await fs.readFile(htmlPath, 'utf8');+ const variable = `--font-kit-${id}`;+ if (html.includes(variable)) {+ console.log(`${id} is already present in ${htmlPath}`);+ return;+ }++ const outputDir = path.join(projectDir, 'assets', 'fonts', id);+ await fs.mkdir(outputDir, { recursive: true });+ const cssParts = [];++ for (const cssName of font.css) {+ let css = await fs.readFile(path.join(packageDir, cssName), 'utf8');+ css = css.replace(/,\s*url\((?:"|')?\.\/files\/[^)]*?\.woff(?:"|')?\)\s*format\((?:"|')woff(?:"|')\)/g, '');+ const files = [...css.matchAll(/url\((?:"|')?\.\/files\/([^)'"\s]+\.woff2)(?:"|')?\)/g)].map((match) => match[1]);+ for (const filename of new Set(files)) {+ await fs.copyFile(path.join(packageDir, 'files', filename), path.join(outputDir, filename));+ }+ const relativeDir = path.relative(projectDir, outputDir).split(path.sep).join('/');+ css = css.replace(/url\((?:"|')?\.\/files\/([^)'"\s]+\.woff2)(?:"|')?\)/g, `url("./${relativeDir}/$1")`);+ cssParts.push(stripCssComments(css));+ }++ try {+ await fs.copyFile(path.join(packageDir, 'LICENSE'), path.join(outputDir, 'LICENSE.txt'));+ } catch {+ throw new Error(`font package ${font.package} does not contain a LICENSE file`);+ }++ const faceCss = cssParts.join('\n\n');+ const styleOpen = html.match(/<style(?:\s[^>]*)?>/i);+ if (!styleOpen || styleOpen.index === undefined) throw new Error('HTML has no <style> block');+ const insertAt = styleOpen.index + styleOpen[0].length;+ html = `${html.slice(0, insertAt)}\n${faceCss}\n${html.slice(insertAt)}`;++ const rootMatch = html.match(/:root\s*\{/);+ if (!rootMatch || rootMatch.index === undefined) throw new Error('HTML has no :root block');+ const rootInsert = rootMatch.index + rootMatch[0].length;+ const declaration = `\n ${variable}: "${font.family}", ${font.fallback};`;+ html = `${html.slice(0, rootInsert)}${declaration}${html.slice(rootInsert)}`;++ await fs.writeFile(htmlPath, html);+ console.log(`added ${font.family} to ${htmlPath}`);+ console.log(`select it with var(${variable})`);+ console.log(`copied font files and license to ${outputDir}`);+}++const [command, id, html] = process.argv.slice(2);+try {+ if (command === 'list') list();+ else if (command === 'add') await add(id, html);+ else {+ usage();+ process.exitCode = 2;+ }+} catch (error) {+ console.error(error.message);+ process.exitCode = 1;+}diff --git a/skills/editable-design/scripts/install-font-kit.sh b/skills/editable-design/scripts/install-font-kit.shnew file mode 100755index 0000000..5a64064--- /dev/null+++ b/skills/editable-design/scripts/install-font-kit.sh@@ -0,0 +1,13 @@+#!/usr/bin/env bash+set -euo pipefail++skill_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"+font_dir="$skill_dir/font-kit"++test -f "$font_dir/package-lock.json" || {+ echo "missing font-kit/package-lock.json" >&2+ exit 1+}++npm ci --prefix "$font_dir"+printf 'Editable Design font kit installed in %s\n' "$font_dir/node_modules"