feat: font resolution pipeline — compositions capture and embed their own fonts (#1255)

Compositions are now self-contained: the compiler captures font files
and embeds them as woff2 data URIs, eliminating silent render-time
fallback when the render environment lacks the author's fonts.

Resolution order (each tier falls through to the next):
1. Existing @font-face → use as-is
2. Bundled alias (38 cross-platform mappings) → embed data URI
3. Google Fonts → fetch, cache, embed
4. Local system font → locate on OS, compress to woff2, embed
5. Local @font-face paths → read file, compress, inline as data URI
6. External CDN stylesheets → fetch CSS, extract @font-face, inline
7. Alias map fallback → closest bundled equivalent
8. Actionable error with guidance

Key changes:
- System font locator (macOS/Windows/Linux) with path-bounding and
  symlink defense (realpathSync + O_NOFOLLOW)
- woff2 compression via wawoff2 (WASM, cross-platform)
- Multi-weight/style variant capture with length-sorted token matching
- External stylesheet inlining with SSRF defense (assertPublicHttpsUrl,
  HTTPS-only, private-host blocking, 2MB cap, 4-concurrent limit)
- Studio auto-import via GET /fonts/file API + renderAliasFor() derived
  from shared FONT_ALIAS_MAP (no more hand-curated drift)
- failClosedFontFetch throws on unresolved fonts in distributed renders
- Single source of truth: @hyperframes/core/fonts/aliases
- system_font_will_alias lint rule (escalates to warning for distributed)
- Default to Inter + JetBrains Mono in templates and CSS reset
This commit is contained in:
Miguel Ángel
2026-06-07 17:52:19 -04:00
committed by GitHub
parent 4da567df22
commit 0bf15119f8
29 changed files with 2244 additions and 226 deletions
+1
View File
@@ -100,6 +100,7 @@ describe("constants", () => {
});
it("TEXT_STYLES includes font and alignment", () => {
expect(TEXT_STYLES).toContain('font-family: "Inter"');
expect(TEXT_STYLES).toContain("font-size: 48px");
expect(TEXT_STYLES).toContain("font-weight: bold");
expect(TEXT_STYLES).toContain("color: white");
+1 -1
View File
@@ -7,6 +7,6 @@ export const ELEMENT_BASE_STYLES = `position: absolute; visibility: hidden;`;
export const MEDIA_STYLES = `width: 100%; height: 100%; object-fit: contain;`;
export const TEXT_STYLES = `display: flex; align-items: center; justify-content: center; font-family: system-ui, -apple-system, sans-serif; font-size: 48px; font-weight: bold; color: white; text-shadow: 2px 2px 4px rgba(0,0,0,0.8); width: 100%; height: 100%;`;
export const TEXT_STYLES = `display: flex; align-items: center; justify-content: center; font-family: "Inter", sans-serif; font-size: 48px; font-weight: bold; color: white; text-shadow: 2px 2px 4px rgba(0,0,0,0.8); width: 100%; height: 100%;`;
export const ZOOM_CONTAINER_STYLES = `position: absolute; inset: 0; transform-origin: 0 0;`;