Code-first video & image, rendered natively on WebGPU.
fix(text): draw ✓ ★ © ™ from the text font; fall back across fonts
okanasl7a9e97deb305
diff --git a/.changeset/text-dingbats.md b/.changeset/text-dingbats.mdnew file mode 100644index 00000000..5dc691e0--- /dev/null+++ b/.changeset/text-dingbats.md@@ -0,0 +1,7 @@+---+"framefields": patch+---++Symbols like ✓ ✗ ★ ☆ ❯ © ™ draw from the text font instead of as emoji. Layout treated every character in U+2600–27BF, and every emoji-capable pictograph, as a color emoji, so a ✓ (which no emoji font has) drew nothing and "© 2026" got an emoji bitmap. Text now follows Unicode's emoji presentation rules: a grapheme is emoji when it defaults to emoji presentation (🚀 ✅ ⚡), carries VS16 (❤️), a skin tone or a keycap, or is a ZWJ sequence. Pictographs that default to text (❤ ✈ ☀ ✔ © ™) use the text font's glyph when it has one, and the emoji font when it doesn't. A glyph missing from the text font is taken from another registered family that has it, so a ✓ in JetBrains Mono draws from Inter instead of as a .notdef box. The `missing_emoji_font` lint uses the same rule, so it no longer flags © or ✓.++Terminal also drops a done line's leading check mark when color markup wraps it (`{green}✓{/} done`), as it already did for a bare `✓ done`. The drawn check takes its place. Until now the text ✓ drew nothing, so the second mark went unnoticed.diff --git a/packages/components/src/terminal/plan.test.ts b/packages/components/src/terminal/plan.test.tsindex 7c4d7b82..5135bf04 100644--- a/packages/components/src/terminal/plan.test.ts+++ b/packages/components/src/terminal/plan.test.ts@@ -70,6 +70,23 @@ describe("terminal plan", () => {expect(p.checks[0]?.at).toBe(spin?.to);});+ it("drops a done line's check mark even when it's colored", () => {+ const doneOf = (done: string) =>+ plan([{ spinner: "x", for: 10, done }]).lines.find(+ (l) => l.kind === "done",+ )?.spans;+ expect(doneOf("{green}✓{/} 2 components")).toEqual([+ { text: "2 components" },+ ]);+ expect(doneOf(" ✓ {bold}ok{/}")?.map((s) => s.text)).toEqual(["ok"]);+ // Only a leading mark: one later in the line is text.+ expect(+ doneOf("passed ✓")+ ?.map((s) => s.text)+ .join(""),+ ).toBe("passed ✓");+ });+it("clears the screen at once", () => {const p = plan([{ output: "a" }, { clear: true }, { output: "b" }]);const a = p.lines.find((l) => l.spans[0]?.text === "a");diff --git a/packages/components/src/terminal/plan.ts b/packages/components/src/terminal/plan.tsindex a340ca47..51fb14c7 100644--- a/packages/components/src/terminal/plan.ts+++ b/packages/components/src/terminal/plan.ts@@ -130,6 +130,25 @@ export const SCROLL_GLIDE = 4;/** A check mark replaces these leading glyphs (fonts often lack them). */const DONE_MARK = /^\s*[✔✓√]\s*/;+/**+ * The spans without a leading check mark, found in the first span with+ * visible text, so `{green}✓{/} done` loses it as `✓ done` does (the+ * drawn check takes its place).+ */+export function withoutDoneMark(spans: Span[]): Span[] {+ const first = spans.findIndex((sp) => sp.text.trim() !== "");+ const span = spans[first];+ if (!span || !DONE_MARK.test(span.text)) return spans;+ const rest = [+ { ...span, text: span.text.replace(DONE_MARK, "") },+ ...spans.slice(first + 1),+ ];+ // The mark's trailing space goes with it, even when it's in the next span.+ while (rest[0] && rest[0].text.trimStart() === "") rest.shift();+ if (rest[0]) rest[0] = { ...rest[0], text: rest[0].text.trimStart() };+ return rest;+}+export function planTerminal(script: readonly Step[],o: PlanOptions,@@ -231,10 +250,11 @@ export function planTerminal(spinning.until = to;plan.spinners.push({ row: spinning.row, from, to, step: s });row--;- const doneText = (step.done ?? step.spinner).replace(DONE_MARK, "");show({appear: to,- spans: parseMarkup(doneText, o.markup),+ spans: withoutDoneMark(+ parseMarkup(step.done ?? step.spinner, o.markup),+ ),indent: 2,step: s,kind: "done",diff --git a/packages/compositions/src/program/lint.test.ts b/packages/compositions/src/program/lint.test.tsindex a4e90e6d..2f9ce14a 100644--- a/packages/compositions/src/program/lint.test.ts+++ b/packages/compositions/src/program/lint.test.ts@@ -211,6 +211,8 @@ describe("lintComposition", () => {kind: "box",children: [text("plain", "Ship it"),+ // Symbols the text font draws: no emoji font needed.+ text("symbols", "✓ done · © 2026 Acme™ ★"),text("rocket", "Ship it 🚀"),text("span", "x", [{ text: "❤️" }]),],diff --git a/packages/compositions/src/program/lint.ts b/packages/compositions/src/program/lint.tsindex 4cfae954..c630008b 100644--- a/packages/compositions/src/program/lint.ts+++ b/packages/compositions/src/program/lint.ts@@ -6,6 +6,7 @@*/import {Color,+ emojiPresentation,parseCssColor,parseCssGradient,type RenderDiagnostic,@@ -32,12 +33,18 @@ const COLOR_PROPS = [*/export const LARGE_ANIMATION_KEYFRAMES = 2000;-/**- * Characters layout draws from the color emoji font (the renderer's own- * test, `emojiGraphemes` in webgpu-renderers).- */-const EMOJI =- /(\p{Extended_Pictographic}|\p{Emoji_Presentation}|[\u2600-\u27BF])/u;+/** Whether `text` has a grapheme layout always draws from the color emoji font. */+function hasEmoji(text: string): boolean {+ for (const { segment } of graphemes().segment(text))+ if (emojiPresentation(segment) === "emoji") return true;+ return false;+}++let segmenter: Intl.Segmenter | undefined;+function graphemes(): Intl.Segmenter {+ segmenter ??= new Intl.Segmenter(undefined, { granularity: "grapheme" });+ return segmenter;+}/** The text a text node draws: its string and its spans'. */function textOf(node: AnyNode): string {@@ -120,7 +127,7 @@ export function lintComposition(if (options.emojiFont === false &&node.kind === "text" &&- EMOJI.test(textOf(node))+ hasEmoji(textOf(node)))emojiText.push(id);diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex b8faf372..e3287830 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -7,6 +7,7 @@ export * from "./signals/index.js";export * from "./types/index.js";export * from "./utils/assert.js";export * from "./utils/color.js";+export * from "./utils/emoji.js";export * from "./utils/gradient.js";export * from "./utils/is-equal.js";export * from "./utils/result-cache.js";diff --git a/packages/core/src/utils/emoji.test.ts b/packages/core/src/utils/emoji.test.tsnew file mode 100644index 00000000..acb110a9--- /dev/null+++ b/packages/core/src/utils/emoji.test.ts@@ -0,0 +1,41 @@+import { describe, expect, it } from "vitest";+import { emojiPresentation } from "./emoji.js";++describe("emojiPresentation", () => {+ it("keeps plain symbols in the text font", () => {+ for (const g of ["✓", "✗", "★", "☆", "☐", "❯", "➜", "→", "A", "1", "#"])+ expect([g, emojiPresentation(g)]).toEqual([g, "text"]);+ });++ it("draws default-emoji characters and sequences as emoji", () => {+ for (const g of [+ "🚀",+ "✅",+ "⚡",+ "✨",+ "⭐",+ "❌",+ "🇹🇷",+ "👍🏽",+ "☝🏽",+ "1️⃣",+ "👩💻",+ "❤️🔥",+ ])+ expect([g, emojiPresentation(g)]).toEqual([g, "emoji"]);+ });++ it("follows the variation selectors", () => {+ expect(emojiPresentation("❤️")).toBe("emoji"); // VS16+ expect(emojiPresentation("✔️")).toBe("emoji");+ expect(emojiPresentation("❤︎")).toBe("text"); // VS15+ expect(emojiPresentation("🚀︎")).toBe("text");+ // VS16 on a character that isn't a pictograph changes nothing.+ expect(emojiPresentation("✓️")).toBe("text");+ });++ it("leaves text-default pictographs to the font", () => {+ for (const g of ["❤", "✈", "☀", "⚠", "✔", "©", "™", "♥"])+ expect([g, emojiPresentation(g)]).toEqual([g, "either"]);+ });+});diff --git a/packages/core/src/utils/emoji.ts b/packages/core/src/utils/emoji.tsnew file mode 100644index 00000000..ef33c963--- /dev/null+++ b/packages/core/src/utils/emoji.ts@@ -0,0 +1,35 @@+/**+ * How a grapheme presents, after Unicode's emoji presentation rules+ * (UTS #51): as a color emoji, as text, or as text when the text font has+ * the glyph. Layout and the emoji preload use it, and so does the+ * `missing_emoji_font` lint, so they agree on which characters need the+ * color emoji font.+ */++/** Default emoji presentation (✅ ⚡ 🚀), a skin tone, or a keycap. */+const EMOJI_STYLE = /\p{Emoji_Presentation}|\p{Emoji_Modifier}|⃣/u;+/** Pictographs that can be emoji (❤ ✈ © ™ ✔): emoji only when asked for. */+const PICTOGRAPHIC = /\p{Extended_Pictographic}/u;+/** A pictograph followed by VS16 asks for emoji presentation (❤️). */+const VS16_AFTER_PICTOGRAPH = /\p{Extended_Pictographic}️/u;+const VS15 = "︎";+const ZWJ = "";++/**+ * `"emoji"`: draw from the color emoji font. `"text"`: draw from the text+ * font (✓ ★ ❯, letters). `"either"`: a pictograph that defaults to text+ * (❤ ✈ ☀ © ™ without VS16), drawn from the text font when it has the glyph+ * and from the emoji font when it doesn't, as browsers fall back.+ */+export type EmojiPresentation = "emoji" | "text" | "either";++export function emojiPresentation(grapheme: string): EmojiPresentation {+ if (grapheme.includes(VS15)) return "text";+ if (+ EMOJI_STYLE.test(grapheme) ||+ VS16_AFTER_PICTOGRAPH.test(grapheme) ||+ (grapheme.includes(ZWJ) && PICTOGRAPHIC.test(grapheme))+ )+ return "emoji";+ return PICTOGRAPHIC.test(grapheme) ? "either" : "text";+}diff --git a/packages/framefields/src/emoji.render.test.ts b/packages/framefields/src/emoji.render.test.tsindex 4b000d8f..7d3427f1 100644--- a/packages/framefields/src/emoji.render.test.ts+++ b/packages/framefields/src/emoji.render.test.ts@@ -13,12 +13,13 @@ const asset = (path: string) =>beforeAll(async () => {await FontManager.register("assets/fonts/Inter.ttf");+ await FontManager.register("assets/fonts/JetBrainsMono.ttf");await FontManager.registerEmojiFont(asset("packages/renderer/src/assets/NotoColorEmoji.ttf"),);});-async function render(text: string) {+async function render(text: string, fontFamily = "Inter") {const comp = new Composition({width: 300,height: 100,@@ -36,7 +37,7 @@ async function render(text: string) {position: "absolute",x: 20,y: 20,- fontFamily: "Inter",+ fontFamily,fontSize: 40,fill: "#ffffff",}),@@ -50,6 +51,21 @@ async function render(text: string) {return ctx.getImageData(0, 0, img.width, img.height).data;}+/** Pixels with any ink (not the black background). */+function inked(data: Uint8ClampedArray): number {+ let n = 0;+ for (let i = 0; i < data.length; i += 4)+ if (+ Math.max(+ data[i] as number,+ data[i + 1] as number,+ data[i + 2] as number,+ ) > 60+ )+ n++;+ return n;+}+/** Pixels that are clearly coloured (not black, white or grey). */function colored(data: Uint8ClampedArray): number {let n = 0;@@ -68,4 +84,28 @@ describe("emoji", () => {expect(colored(await render("a 🚀"))).toBeGreaterThan(200);expect(colored(await render("a ❤️"))).toBeGreaterThan(200);});++ it("draws symbols like ✓ and © from the text font, not as blank emoji", async () => {+ for (const symbol of ["✓", "©", "★"]) {+ const img = await render(`a ${symbol}`);+ // White text ink, no color bitmap, and more ink than "a" alone.+ expect(colored(img)).toBe(0);+ expect(inked(img)).toBeGreaterThan(inked(await render("a")) + 30);+ }+ });++ it("takes a glyph the font lacks from another registered family", async () => {+ // JetBrains Mono has no ✓ or ★; Inter does.+ for (const symbol of ["✓", "★"]) {+ const img = await render(symbol, "JetBrains Mono");+ expect(colored(img)).toBe(0);+ expect(inked(img)).toBeGreaterThan(30);+ }+ });++ it("keeps text-default pictographs as text when the font has them", async () => {+ // Inter has ❤ (drawn white); ✈ it lacks, so that one is the color emoji.+ expect(colored(await render("a ❤"))).toBe(0);+ expect(colored(await render("a ✈"))).toBeGreaterThan(200);+ });});diff --git a/packages/webgpu-renderers/src/slug/slug-font-cache.ts b/packages/webgpu-renderers/src/slug/slug-font-cache.tsindex 9ac7b557..c49c2859 100644--- a/packages/webgpu-renderers/src/slug/slug-font-cache.ts+++ b/packages/webgpu-renderers/src/slug/slug-font-cache.ts@@ -208,6 +208,11 @@ export class SlugFontCache {return SlugFontCache.parsedFontCache.get(fontFamily) || null;}+ /** Registered families, in registration order (font fallback tries them in turn). */+ public static families(): string[] {+ return [...SlugFontCache.parsedFontCache.keys()];+ }+public static getAllParsed(): FontkitFont[] {return Array.from(SlugFontCache.parsedFontCache.values());}diff --git a/packages/webgpu-renderers/src/slug/slug-generator.ts b/packages/webgpu-renderers/src/slug/slug-generator.tsindex e1bf46ab..de48f29e 100644--- a/packages/webgpu-renderers/src/slug/slug-generator.ts+++ b/packages/webgpu-renderers/src/slug/slug-generator.ts@@ -32,6 +32,7 @@ export interface FontkitFont {numGlyphs: number;getGlyph?(id: number): FontkitGlyph;glyphForCodePoint?(codePoint: number): FontkitGlyph;+ hasGlyphForCodePoint?(codePoint: number): boolean;characterSet: number[] | Iterable<number>;ascent: number;descent: number;diff --git a/packages/webgpu-renderers/src/slug/slug-geometry.ts b/packages/webgpu-renderers/src/slug/slug-geometry.tsindex 04c5477c..0108659f 100644--- a/packages/webgpu-renderers/src/slug/slug-geometry.ts+++ b/packages/webgpu-renderers/src/slug/slug-geometry.ts@@ -55,6 +55,44 @@ export interface SlugGlyphLayout {mark?: TextSpanMark;}+/**+ * Font fallback for shaping: the first other registered family with a glyph+ * for `codePoint`, at the same weight and size. Fonts are per family, so a+ * ✓ in a mono face that lacks one draws from, say, Inter.+ */+function fallbackFont(+ base: SlugFont,+ fontSize: number,+ codePoint: number,+): SlugFont | undefined {+ for (const family of SlugFontCache.families()) {+ if (family === base.fontFamily) continue;+ if (!SlugFontCache.getParsed(family)?.hasGlyphForCodePoint?.(codePoint))+ continue;+ return SlugFontCache.getFont(+ family,+ base.weight,+ null,+ undefined,+ fontSize,+ );+ }+ return undefined;+}++/** `shapeParagraph`'s fallback: the style with a fallback font (and its scale). */+const fallback = <T extends ShapeStyle>(style: T, codePoint: number) => {+ const font = fallbackFont(style.font, style.fontSize, codePoint);+ if (!font) return undefined;+ return {+ ...style,+ font,+ ...("fontScale" in style && {+ fontScale: style.fontSize / font.unitsPerEm,+ }),+ } as T;+};+export interface SlugEmojiLayout {char: string;x: number;@@ -241,6 +279,7 @@ export class SlugGeometry {const shaped = shapeParagraph([{ text: paragraph, style }], {direction,ligatures,+ fallback,});for (const clusters of breakLines(shaped.clusters, maxWidth)) {lines.push({ clusters, baseLevel: shaped.baseLevel, textOffset });@@ -304,6 +343,12 @@ export class SlugGeometry {clusterAdvance: c.advance - c.spacing,clusterX: x,baseRtl: (baseLevel & 1) === 1,+ // A glyph from a fallback family draws with that font.+ ...(c.style.font !== font && {+ font: c.style.font,+ fontFamily: c.style.font.fontFamily,+ fontScale: fontSize / c.style.font.unitsPerEm,+ }),});}}@@ -461,7 +506,11 @@ export class SlugGeometry {}const lines: Line[] = [];for (const segments of paragraphs) {- const shaped = shapeParagraph(segments, { direction, ligatures });+ const shaped = shapeParagraph(segments, {+ direction,+ ligatures,+ fallback,+ });for (const clusters of breakLines(shaped.clusters, maxWidth)) {lines.push({ clusters, baseLevel: shaped.baseLevel });}diff --git a/packages/webgpu-renderers/src/slug/text-shaping.test.ts b/packages/webgpu-renderers/src/slug/text-shaping.test.tsindex 3afbc405..b2998fbf 100644--- a/packages/webgpu-renderers/src/slug/text-shaping.test.ts+++ b/packages/webgpu-renderers/src/slug/text-shaping.test.ts@@ -316,3 +316,54 @@ describe.skipIf(!sfArabic)("Arabic shaping (SF Arabic)", () => {}});});++describe("emoji presentation and font fallback", () => {+ // "✓" and "©" are in this font; "❤" and "★" are not.+ const text = mockFont("ab ✓©");+ const style = { font: text, fontSize: 10, letterSpacing: 0 };+ const shapeOne = (s: string, options = {}) =>+ shapeParagraph([{ text: s, style }], options).clusters;++ it("draws plain symbols from the text font, not as emoji", () => {+ const clusters = shapeOne("a ✓ ©");+ expect(clusters.filter((c) => c.isEmoji)).toEqual([]);+ const check = clusters.find((c) => c.text === "✓");+ expect(check?.glyphs[0]?.cp.codePoint).toBe(0x2713);+ });++ it("keeps default-emoji and VS16 graphemes as emoji", () => {+ const emoji = shapeOne("🚀 ❤️ ✅")+ .filter((c) => c.isEmoji)+ .map((c) => c.text);+ expect(emoji).toEqual(["🚀", "❤️", "✅"]);+ });++ it("falls back to the emoji font for a text-default pictograph the font lacks", () => {+ expect(shapeOne("❤").map((c) => c.isEmoji)).toEqual([true]);+ // With the glyph, a text-default pictograph stays text.+ expect(shapeOne("©").map((c) => c.isEmoji)).toEqual([false]);+ });++ it("takes a missing glyph from the fallback font, in its own style", () => {+ const other = mockFont("★");+ const seen: number[] = [];+ const clusters = shapeOne("a★b", {+ fallback: <T extends typeof style>(s: T, cp: number) => {+ seen.push(cp);+ return { ...s, font: other } as T;+ },+ });+ expect(seen).toEqual([0x2605]);+ expect(clusters.map((c) => [c.text, c.style.font === other])).toEqual([+ ["a", false],+ ["★", true],+ ["b", false],+ ]);+ expect(clusters[1]?.glyphs[0]?.cp.codePoint).toBe(0x2605);+ });++ it("lists only graphemes that may draw as emoji for preloading", async () => {+ const { emojiGraphemes } = await import("./text-shaping.js");+ expect(emojiGraphemes("✓ done © ★ ❤ ❤️ 🚀")).toEqual(["©", "❤", "❤️", "🚀"]);+ });+});diff --git a/packages/webgpu-renderers/src/slug/text-shaping.ts b/packages/webgpu-renderers/src/slug/text-shaping.tsindex 84308b9e..f369ba18 100644--- a/packages/webgpu-renderers/src/slug/text-shaping.ts+++ b/packages/webgpu-renderers/src/slug/text-shaping.ts@@ -7,6 +7,7 @@* Clusters stay in logical (reading) order until {@link placeLine}, so line* breaking, word/char indices and typewriter prefixes all follow the text.*/+import { emojiPresentation } from "@framefields/core";import bidiFactory from "bidi-js";import {type FontkitFont,@@ -66,20 +67,27 @@ interface ShapeOptions {ligatures?: boolean;/** Set emoji apart for bitmap drawing (default); false shapes them as glyphs. */emoji?: boolean;+ /**+ * A style for a grapheme the run's font has no glyph for (another+ * registered family that has it), or undefined to keep .notdef.+ */+ fallback?: <T extends ShapeStyle>(+ style: T,+ codePoint: number,+ ) => T | undefined;}-const EMOJI_REGEX =- /(\p{Extended_Pictographic}|\p{Emoji_Presentation}|[☀-➿])/u;-/**- * The emoji in `text`, one per grapheme, as layout draws them: "❤️" keeps- * its variation selector, "👍🏽" its skin tone. Preloading uses these, so its- * textures are the ones drawing looks up.+ * The graphemes in `text` that may draw as emoji, as layout sees them: "❤️"+ * keeps its variation selector, "👍🏽" its skin tone. Preloading uses these,+ * so its textures are the ones drawing looks up. Text-default pictographs+ * (❤ © ™ without VS16) are included, since layout falls back to the emoji+ * font when the text font lacks them; plain symbols (✓ ★ ❯) are not.*/export function emojiGraphemes(text: string): string[] {return segmentGraphemes(text).map((g) => g.text)- .filter((g) => EMOJI_REGEX.test(g));+ .filter((g) => emojiPresentation(g) !== "text");}/** Characters that make bidi analysis necessary (RTL letters and explicit RTL controls). */@@ -226,6 +234,19 @@ function resolveShapingSource(font: SlugFont): FontkitFont | null {return parsed?.get(font.fontFamily) ?? null;}+/** Whether `font` has its own glyph for `codePoint` (not .notdef). */+function fontHasCodePoint(font: SlugFont, codePoint: number): boolean {+ if (font.codePoints.has(codePoint)) return true;+ const source = resolveShapingSource(font);+ if (typeof source?.hasGlyphForCodePoint === "function")+ return source.hasGlyphForCodePoint(codePoint);+ if (!source) return false;+ const set = source.characterSet;+ return Array.isArray(set)+ ? set.includes(codePoint)+ : new Set(set).has(codePoint);+}+function notdef(font: SlugFont): SlugCodePoint | undefined {return font.codePoints.get(-1) ?? font.glyphs?.get(0);}@@ -525,9 +546,31 @@ export function shapeParagraph<S extends ShapeStyle>(const { start, text: gt } = graphemes[g];for (let k = 0; k < gt.length; k++) graphemeAt[start + k] = g;}- const isEmojiGrapheme = graphemes.map(- (g) => options.emoji !== false && EMOJI_REGEX.test(g.text),- );+ const isEmojiGrapheme = graphemes.map((g) => {+ if (options.emoji === false) return false;+ const presentation = emojiPresentation(g.text);+ // Text-default pictographs use the text font's glyph when it has one.+ return (+ presentation === "emoji" ||+ (presentation === "either" &&+ !fontHasCodePoint(styleAt[g.start].font, g.text.codePointAt(0) ?? 0))+ );+ });++ // A grapheme its font can't draw takes another family that can (✓ in a+ // mono face without one), as browsers fall back; its run splits there.+ if (options.fallback) {+ for (let g = 0; g < graphemes.length; g++) {+ if (isEmojiGrapheme[g]) continue;+ const { start, text: gt } = graphemes[g];+ const cp = gt.codePointAt(0) ?? 0;+ if (isIgnorable(cp) || SPACE_REGEX.test(gt) || cp < 0x20) continue;+ const style = styleAt[start];+ if (fontHasCodePoint(style.font, cp)) continue;+ const other = options.fallback(style, cp);+ if (other) for (let k = 0; k < gt.length; k++) styleAt[start + k] = other;+ }+ }// Glyphs per grapheme, and ligature merges (a glyph spanning graphemes).const glyphsOf: RunGlyph[][] = graphemes.map(() => []);