Skip to content

Pluggable font stacks for embedders #32

Open

Description

@calumk

Today

The engine keys all type off font style ids (draw / sans / serif / mono), but the id-to-stack mapping (FONTS in palette.js) is hardcoded. A host that wants brand fonts (a custom sans, a corporate serif) has no supported path: the stacks feeding measurement, canvas drawing, the editing textarea and any UI all read the same constant.

Proposal

A tiny registry API on the existing ids, no default behavior change:

import { setFontStacks, resetFontStacks, fontStackOf } from '@quickdrawjs/core'

// once at startup
setFontStacks({
  sans: "'Inter', system-ui, sans-serif",
  mono: "'JetBrains Mono', ui-monospace, monospace",
})
  • setFontStacks(partial) remaps ids (or registers brand-new ids — any font prop value resolves).
  • fontStackOf(id) is the single resolution point used by measurement, drawing and the editor; unknown ids fall back to draw.
  • resetFontStacks() restores bundled defaults.
  • Process-global by design (same model as a rendering backend): configure once at startup.

New ids also typecheck (FontId widens to accept custom strings while keeping autocomplete for the built-ins). Nothing renders differently unless the host opts in.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions