Skip to content

ADR 0008: Brand-input theme generator and flagship themes ​

Identifiers updated for the GhostVue rebrand (ADR 0010).

  • Status: accepted
  • Date: 2026-11-11
  • Decision owners: Zac Pruett, repository maintainers
  • Relates to: ADR 0007 (pipeline, data-ghost-*, CSS names); GHO-68 / GHO-61f

Accepted 2026-11-11 with the answers in Decision record.

Proposed amendment (not approved): browser theme generation and a theme-aware startThemeTransition are measured and drafted in Amendment (proposed): browser generation and theme transitions. They await a maintainer decision. Until then the accepted text below stays authoritative.

Approved amendment (2026-12-04), not yet implemented: a shared palette sheet with small per-palette difference sheets, as an additive opt-in, is specified in Amendment (approved): shared palette sheet.

Context ​

ADR 0007 compiles one authored theme (default) from DTCG JSON. Brand seeds in seeds.json become 12-step OKLCH ramps; semantic files alias those ramps; CSS custom properties switch on data-ghost-theme, data-ghost-mode, and data-ghost-density. --ghost-roundness and --ghost-motion-intensity already scale nested subtrees through calc(). culori is a devDependency of @ghostvue/themes (ramps + pnpm contrast). Unset data-ghost-mode follows prefers-color-scheme in CSS, so SSR does not flash the opposite palette.

GHO-68 asks for defineTheme({ primaryHue, neutralTint, roundness, density, motionIntensity }) that emits a complete theme, runtime switching with no SSR flash, nested scoped themes, three flagship themes (calm enterprise, vibrant expressive, minimal monochrome), and a docs switcher that dogfoods a flagship. The generator is a new public contract: wrong delivery, scoping, or contrast rules would freeze a bad API.

Constraints: no new browser runtime dependency without Zac's approval; do not mutate consumer data; do not expose internal DOM as the customization API; default stays the authored DTCG source of truth.

Decision ​

1. Build-time generation; CSS string returned, .css files shipped ​

defineTheme runs on the Node side only (app build, package build, or a thin CLI wrapper). It returns a CSS string plus catalogs. Flagship themes are compiled at @ghostvue/themes build and published as .css files. Runtime switching applies pre-generated CSS with data-ghost-theme.

DeliveryRole
defineTheme(…).cssCanonical generator output
Published .css filesHow flagships (and typical apps) ship
CLI that writes that stringConvenience, not a second compiler
Vite pluginNot v1; writeFileSync / a virtual module is enough

Rejected for v1: generating ramps in the browser (would put culori on the client and flash unless every SSR response inlined fresh CSS); shipping only a Vite plugin (locks non-Vite consumers).

culori stays out of the browser graph. The Node generator may keep using it. Do not add culori as a runtime dependency of @ghostvue/themes's main entry. Promoting it to a browser dependency needs Zac's approval (dependency policy).

2. Signature ​

primary is a CSS color or an OKLCH hue. A hue-only input is the issue's primaryHue sketch; a color string is the brand-paste path and matches seeds.json. One seed drives both modes (dark is derived with the existing dark lightness/chroma curves, not a second required input).

ts
/** OKLCH hue in `[0, 360]` (`360` ≡ `0`), or a parseable sRGB/OKLCH/HSL CSS color. */
export type ColorSeed = number | string

export type ThemeDensity = 'compact' | 'comfortable' | 'spacious'
export type ElevationFlavor = 'subtle' | 'standard' | 'dramatic'
export type GradientFlavor = 'none' | 'subtle' | 'aurora'

export interface DefineThemeInput {
  /** `data-ghost-theme` value. Kebab-case. Not `default`. */
  name: string
  primary: ColorSeed
  /** Neutral hue/color, or `'none'` for chroma 0. Default: primary hue, low chroma. */
  neutralTint?: ColorSeed | 'none'
  /** Defaults: current `default` theme status seeds (not derived from primary). */
  status?: {
    success?: ColorSeed
    warning?: ColorSeed
    danger?: ColorSeed
    info?: ColorSeed
  }
  /** `0` sharp → `1` designed (including pill). Default `1`. */
  roundness?: number
  /** Unset `data-ghost-density` under this theme. Default `'comfortable'`. */
  density?: ThemeDensity
  /** Unitless duration scale. Default `1`. */
  motionIntensity?: number
  /** Shadow/lift recipe. Default `'standard'`. */
  elevation?: ElevationFlavor
  /** `gradient.accent` / aurora recipe. Default `'subtle'`. */
  gradient?: GradientFlavor
  /** CSS `font-family` list. Sets both family tokens. Default: system UI sans stack. */
  fontFamily?: string
}

export interface DefinedTheme {
  name: string
  css: string
  tokens: TokenManifest['tokens']
  manifest: TokenManifest
}

export function defineTheme(input: DefineThemeInput): DefinedTheme

TokenManifest is the ADR 0007 JSON catalog (theme set to input.name).

Defaults: neutralTint from primary's hue at library-neutral chroma; status = today's success/warning/danger/info seeds; roundness = 1; density = 'comfortable'; motionIntensity = 1; elevation = 'standard'; gradient = 'subtle'; fontFamily unset (the authored font.family.sans system stack).

Validation (throw, do not coerce): name matches /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/, length ≤ 64, not default. Hue is finite and in [0, 360] (360 is equivalent to 0). Color strings must parse to an absolute color (currentColor, inherit, relative colors rejected). roundness and motionIntensity in [0, 1]. Enums must be exact. fontFamily is a comma-separated list whose entries are each a quoted name or plain identifiers; ;, braces, <, >, backslashes, parentheses, newlines, unbalanced quotes, empty entries, and CSS-wide keywords are rejected, because the value is written verbatim into a custom property declaration. After fg auto-adjust, every WCAG AA pair from evaluateContrast must pass or defineTheme throws.

ts
import { defineTheme } from '@ghostvue/themes/define'
import { writeFileSync } from 'node:fs'

const acme = defineTheme({ name: 'acme', primary: '#0f766e', roundness: 0.5 })
writeFileSync('src/acme.css', acme.css)
html
<main class="ghost-theme" data-ghost-theme="acme">…</main>

3. Apply and scope ​

Token sheets set properties on :where([data-ghost-theme='<name>']). .ghost-theme withoutdata-ghost-theme continues to mean default. Implementation must stop treating .ghost-themed-scope as a token host (today it is in CSS_HOST, which would pin themed wrappers to default inside a nested flagship). .ghost-themed-scope stays a recipe scope only.

data-ghost-mode and data-ghost-density stay orthogonal and nestable: a descendant attribute wins. Generated CSS still follows prefers-color-scheme when mode is unset. Theme CSS sets --ghost-roundness and --ghost-motion-intensity on its host; nested hosts override. A theme's density default is the unset-density rule under that data-ghost-theme only; global unset density on default remains comfortable.

Recipes (default.css button/elevation/motion rules) stay theme-agnostic and consume --ghost-*. Flagship files are token sheets, not forks of default.css. Import recipes plus every theme the page might show:

ts
import '@ghostvue/themes/default.css'
import '@ghostvue/themes/calm.css'
import '@ghostvue/themes/vibrant.css'
import '@ghostvue/themes/mono.css'

No-flash: all used token sheets are in the document before first paint; the host HTML already has data-ghost-theme (SSG/SSR). Mode needs no JS. Persisted docs/app choice may use a tiny blocking inline script that writes data-ghost-theme from localStorage before paint. Do not generate or fetch theme CSS after hydrate as the supported path. startThemeTransition remains mode-only; theme switches are setAttribute('data-ghost-theme', name) (callers may wrap the View Transitions pattern themselves).

4. Flagships are checked-in defineTheme calls ​

Flagships are TypeScript configs compiled by the themes package build, not parallel hand-tuned DTCG trees. That dogfoods the generator. default stays authored DTCG (seeds.json + semantic overlays). Escape hatch: a small DTCG overlay next to a flagship config only when a knob cannot express a needed token.

ts
defineTheme({
  name: 'calm',
  primary: 215,
  neutralTint: 215,
  roundness: 0.5,
  density: 'compact',
  motionIntensity: 0.6,
  elevation: 'subtle',
  gradient: 'none',
})

defineTheme({
  name: 'vibrant',
  primary: 292,
  neutralTint: 280,
  roundness: 1,
  density: 'comfortable',
  motionIntensity: 1,
  elevation: 'dramatic',
  gradient: 'aurora',
})

defineTheme({
  name: 'mono',
  primary: '#171717',
  neutralTint: 'none',
  roundness: 0,
  density: 'comfortable',
  motionIntensity: 0.45,
  elevation: 'subtle',
  gradient: 'none',
})

mono keeps default status hues so danger/success stay distinguishable. Docs chrome boots into default (data-ghost-theme="default") on first paint and ships a switcher for default | calm | vibrant | mono. (Calibrated in #330: calm roundness moved from 0.3 to 0.5 so compact corners land on crisp 2px geometry instead of subpixel 1.2px/2.4px, and docs first paint switched from calm to the calibrated default Precision SaaS baseline while keeping all four themes in the live switcher.)

5. Contrast: auto-adjust fg, then fail loudly ​

Keep the existing WCAG 2 AA gate (4.5:1, APCA advisory). The generator does not mutate the caller's primary seed (anchor pin stays). It walks each ramp to choose *.fg / on-color steps (and hover/active pairs) that pass evaluateContrast. If no step works, throw — never return CSS that pnpm contrast would reject. Shipped default + flagships stay in pnpm contrast.

6. Package placement ​

Stay in @ghostvue/themes. No new package.

ExportContentsRuntime
@ghostvue/themeswrappers, tokens, startThemeTransition, flagship name unionbrowser; no defineTheme
@ghostvue/themes/definedefineTheme + typesNode only (exports.node / documented Node)
@ghostvue/themes/calm.css (and vibrant, mono)compiled token sheetsCSS
@ghostvue/themes/default.cssrecipes + default tokensCSS

Main entry must not re-export defineTheme, so app bundles cannot pull culori by accident. New browser runtime dependency: none, unless Zac approves an isomorphic generator.

Alternatives considered ​

Runtime (browser) generation. Rejected for v1. Bundle cost, SSR flash, and a new runtime culori dependency. Revisit only with Zac's approval.

Hand-tuned DTCG overlays as the flagship source. Rejected as the ordinary path; the generator would be unproven. Overlays remain an escape hatch.

Hue-only primaryHue. Rejected as the sole input. Brand guidelines hand over hex; hue drops chroma and lightness. The union preserves the sketch.

Vite plugin as the public API. Rejected. The function returning CSS is the API; a plugin would wrap it later if Vite-only ergonomics demand it.

Injecting <style> at runtime as the apply API. Rejected. Fights no-flash and duplicates data-ghost-theme scoping.

Deriving status hues from primary. Rejected. Danger must not collapse into the brand color.

Consequences ​

  • Node defineTheme lives at @ghostvue/themes/define (not the main entry). Flagship CSS is compiled at package build. pnpm contrast gates default, calm, vibrant, and mono. Docs chrome boots into default on first paint and restores a persisted choice with a blocking inline script.
  • default DTCG pipeline is unchanged.
  • Nested themed wrappers inherit the nearest data-ghost-theme because .ghost-themed-scope is no longer a token host.

Compatibility implications ​

Package is unpublished (0.0.0). Selector change for .ghost-themed-scope is required for nesting and is backwards-compatible for default if .ghost-theme / [data-ghost-theme='default'] keep emitting the same variables. Headless @ghostvue/vue is unchanged. No browser dependency added. Accessibility: AA remains a hard fail for every generated theme.

Decision record (Zac, 2026-11-11) ​

  1. Node-only. defineTheme runs in Node. culori stays a devDependency of @ghostvue/themes. No new runtime dependency.
  2. Flagship names: calm, vibrant, and mono.
  3. Docs chrome dogfoods calm on first paint (amended in #330 to boot into default on first paint once authored tokens were calibrated to Precision SaaS proportions, while keeping calm, vibrant, and mono in the live docs switcher). default stays the published baseline theme.
  4. default stays hand-authored DTCG for now.
  5. Ship elevation and gradient flavor knobs in v1.
  6. A small blocking inline script in the docs is acceptable to restore a persisted theme before paint.

Amendment: fontFamily input (2026-12-01) ​

A palette could not carry its own typeface, so a brand with a custom or monospace face had to override tokens by hand, and needed two of them: --ghost-type-family-sans for component text and --ghost-action-label-family for action labels (buttons, badges, checkboxes). Overriding only the first left action labels on the system stack.

Maintainer decision: add one input, fontFamily?: string. When set, it replaces the values of the semantic tokens type.family.sans and action.label.family (emitted as --ghost-type-family-sans and --ghost-action-label-family) under [data-ghost-theme='<name>']. These are the only family tokens the themed recipes read. When it is omitted, the generator does not touch either token, so generated CSS is byte-identical to themes defined before the input existed, including the flagships.

  • No monoFamily. The token catalog has no monospace family token for it to set. Revisit if recipes gain one.
  • No font loading. fontFamily only names families. Loading or bundling web fonts, and a type scale input, are out of scope.
  • Validation. Entries are allow-listed (quoted name or plain identifiers) rather than escaped, so a value cannot end the declaration or rule, open a comment or block that swallows the rest of the sheet, or close an inline <style>.
  • The CLI accepts the same value as --font-family.

Amendment (proposed): browser generation and theme transitions (2026-12-03) ​

Important

Proposed. Not approved. This amendment records measurements and a recommendation for two accepted decisions: defineTheme being Node-only (decision 1, section 6) and startThemeTransition covering only data-ghost-mode (section 3). It needs a maintainer decision before any implementation. Until then the sections above stay authoritative. This revision changes no code.

Evidence ​

Consumer feedback on 0.2.0 from an app builder:

  • A theme playground could not offer "pick any brand color and preview it live", because defineTheme runs only in Node. The reporter suggested a browser-safe, tree-shakable build, or a defineThemeTokens() that returns the token map without CSS.
  • Switching data-ghost-theme snaps. The reporter asked for startThemeTransition(el, { theme, mode, density }). The docs site already wraps the View Transitions pattern for theme switches in a docs-local helper (#351, shipped in #358), and that issue noted a public helper would need an update to this ADR.

Measurement: a browser entry for defineTheme ​

Measured at commit 63e94ca with Node 22.23.5, esbuild 0.28.2 (the @ghostvue/themes devDependency), and culori 4.0.2. Each bundle is ESM, bundle: true, minify: true, tree-shaking on, target es2022 for the browser (node22 for the baseline). It exports defineTheme and DefineThemeError from packages/themes/scripts/lib/define-theme.js. Gzip is zlib.gzipSync level 9, as in scripts/lib/bundle-size.js.

BundleMin (B)Gzip (B)culori in min (B)Token templates in min (B)
Today's Node dist/define.js (reads templates from disk at runtime)87,76630,44444,7900
Browser, import … from 'culori' (all modes registered)143,22240,00744,78856,193
Browser, culori/fn plus the CSS Color 4 modes culori/css registers127,81134,42329,39856,193
Browser, culori/fn plus only rgb, lrgb, hsl, oklab, oklch118,95031,63220,57856,193
renderTokenCss alone (shared code, for reference)7,4922,74600
Token-map-only path: CSS bundle above without the CSS, TypeScript and docs renderers115,70730,49329,38256,193
Token-map-only path that also drops the manifest renderer115,33330,33129,38256,193

Other figures from the same run:

  • The six token template files (seeds, primitives, semantic, and the dark, compact and spacious overlays) are 61,009 B as minified JSON and 9,724 B gzipped on their own. They are the largest part of a browser bundle, and no variant can drop them, because the generator clones and edits them.
  • One generated theme (acme, #0f766e) is 111,297 B of CSS, or 8,265 B gzipped. A live preview injects this once per change.
  • One warm defineTheme call takes about 19 ms (median of 50, p90 20 ms, max 30 ms) with the minimal browser bundle in Node on a 2.1 GHz Xeon. That is fast enough for a debounced color picker, not for every input event at 60 fps.

Parity. Both browser bundles that register the CSS Color 4 modes produce byte-identical CSS to the Node generator for 15 inputs: the three flagships, hex, a named color, rgb(), hsl(), oklch(), lab(), lch(), hwb(), color(display-p3 …), color(srgb …), and the rejected currentColor (same error). The minimal bundle rejects lab(), lch(), hwb(), and color(display-p3 …) as unparseable, so its validation would differ from Node.

What must be split. A plain platform: 'browser' build fails to resolve node:fs, node:path, node:url, and node:fs/promises:

  • define-theme.js reads the six templates with readFileSync at module load, after locating them with import.meta.url (resolveTokensDir). A browser build must import them as JSON instead. The measurement swapped that block for JSON imports.
  • compile-tokens.js imports node:fs/promises and node:path at module top for loadTokenDocuments and writeThemeTokenOutputs, which defineTheme never calls. The measurement stubbed those imports, and tree-shaking removed them from every browser bundle. An implementation should move the file I/O into a Node-only module so the compiler core has no Node imports.
  • Nothing else uses Node APIs (process, Buffer) on the generation path.

Main entry. An opt-in subpath leaves the main entry unchanged: it would be another esbuild output next to dist/define.js, built by scripts/bundle-define.mjs, and src/index.ts does not import it. The exports map gains one key, and typesVersions gains one entry. Existing keys, including ./define, keep their targets. Today the main entry pulls in neither culori nor defineTheme, which tests/integration/themes-main-entry-graph.test.ts asserts and which passed at this commit. Do not add a browser condition to the existing ./define key. That would change what existing imports resolve to, and a server build and a client build of the same import would get different modules.

Reproduce. Bundle the entry above with the esbuild API and three plugins: (1) an onLoad for define-theme.js that removes its three node: imports and replaces everything from function resolveTokensDir() up to export const flagshipThemes with six JSON imports of the same files from packages/themes/tokens/, (2) an onResolve that maps node:* to a stub module that throws, which must not survive tree-shaking, and (3) for the culori/fn rows, an onResolve for culori that points at a shim. One shim is import 'culori/css'; export { clampChroma, converter, formatHex, parse, wcagContrast } from 'culori/fn'. The other registers only the five modes with useMode and then re-exports. Read metafile bytesInOutput for the per-input shares. For parity, import each bundle in Node and compare defineTheme(input).css and error messages with scripts/lib/define-theme.js.

Recommendation: browser generation ​

Add an opt-in browser subpath, @ghostvue/themes/define/browser. It exports the same defineTheme, DefineThemeError, and types as ./define.

  • It costs about 34.4 KB gzip, paid only by apps that import it. The main entry and ./define stay as they are.
  • It uses culori/fn with the CSS Color 4 modes, so it is byte-identical to the Node generator. The minimal mode set saves 2.8 KB gzip but would accept fewer colors than Node does. One contract across both entries is worth more than that.
  • culori stays a devDependency, inlined at build time as it is in dist/define.js today. Consumers install nothing new. But culori code does reach the client for apps that opt in, and that is exactly the promotion decision 1 reserved for the maintainer. The amendment needs that approval explicitly.
  • The no-flash rules in section 3 do not change. The browser entry is for live previews and playgrounds. Production still ships generated CSS (built in Node, or exported from the playground) present before first paint. Injecting the preview <style> stays in caller code; this does not reopen the rejected "inject <style> at runtime" apply API.

Do not add a token-map-only function. defineTheme already returns tokens and manifest beside css. A real token-only path, measured by having compileTokenDocuments skip renderTokenCss, renderTokenTypescript and renderTokenDocs in the CSS Color 4 browser bundle, is 115,707 B min and 30,493 B gzip: about 12.1 KB min and 3.9 KB gzip (11%) less. Dropping the manifest renderer as well saves only 0.2 KB gzip more. culori and the templates still make up most of the cost. A playground also needs CSS to preview, so it would have to write its own CSS from the map, a second CSS writer that would drift from the selectors, print, and forced-colors rules in renderTokenCss.

Keeping Node-only remains the fallback if the maintainer does not want culori on any client. In that case the docs should say how a playground can preview through a server endpoint that calls defineTheme.

Recommendation: theme-aware startThemeTransition ​

The public helper (start-theme-transition.ts) writes data-ghost-mode inside document.startViewTransition. It writes immediately when there is no document (SSR), no matchMedia, no View Transitions support, or reduced motion is requested. Then it awaits finished.

The docs-local helper (docs-theme-transition.ts) uses the same pattern for data-ghost-theme and adds two things the public helper lacks:

  • Latest request wins. A transition's update runs a frame after it is requested, and a skipped transition still runs its update, so updates can run late or out of order. Every update writes the most recently requested value, so quick switches never end on, or flash, an older theme.
  • Skipped transitions stay quiet. Starting a second transition before the first is ready rejects the first one's ready promise. The docs helper catches that rejection. The public helper does not handle ready, so quick repeated calls can log an unhandled rejection.

Recommended: add an options form and keep the current one:

ts
type ThemeTransitionTarget = {
  /** `data-ghost-theme`. `null` removes the attribute. */
  theme?: string | null
  /** `data-ghost-mode`. `null` removes the attribute. */
  mode?: 'light' | 'dark' | null
  /** `data-ghost-density`. `null` removes the attribute. */
  density?: ThemeDensity | null
}

export function startThemeTransition(
  element: Element,
  target: 'light' | 'dark' | ThemeTransitionTarget,
): Promise<void>
  • null only removes the attribute from element. What applies afterwards depends on context, not on the helper: a removed data-ghost-mode or data-ghost-density resumes inheritance from the nearest ancestor that sets it, and only with no such ancestor does mode follow prefers-color-scheme and density fall back to the theme default. Removing data-ghost-theme from an element that also carries .ghost-theme makes that host use the default palette rather than inherit an ancestor's theme. The docs must say this, with a nested-scope example.
  • An omitted key leaves its attribute alone. All requested attributes are written in one update, so switching theme and mode together is one crossfade, not two.
  • Per element, the newest request wins (state in a WeakMap). ready rejections are caught. This also fixes both issues for today's mode-only callers.
  • theme must match the defineTheme name pattern or be default. An invalid value throws, as defineTheme does. The type stays string because consumers name their own generated themes.
  • Fallbacks are unchanged: immediate write without a document, without View Transitions, or under prefers-reduced-motion: reduce.

Risks to record in the docs:

  • Document-wide snapshot. document.startViewTransition crossfades the whole page, even when element is a nested scope. Element-scoped view transitions are not yet broadly available, so the helper should not promise them.
  • Duration source. The crossfade reads ::view-transition-*(root) timing from the root's motion tokens, not from a nested scope's theme.
  • Density changes geometry. Old and new layouts crossfade, so content of different sizes is briefly visible twice. This is acceptable at motion.duration.moderate, and reduced motion skips it.
  • Input during the crossfade. The page does not take pointer input for the length of the crossfade. Focus and the accessibility tree are unaffected.
  • SSR and first paint. The helper is never the first-paint path. Persisting a choice and restoring it with a blocking inline script remains the caller's job, as section 3 says.

Alternatives: keep the helper mode-only and document the docs pattern for callers (nothing new to maintain, but every app rebuilds the race handling the docs needed), or add a separate startThemeSwitch (two helpers that overlap for mode).

Decision requested ​

Recommended options first.

  1. Q1 — Browser generation. Recommended: opt-in @ghostvue/themes/define/browser, with maintainer approval for culori (inlined) on the client of apps that import it. Alternatives: keep Node-only; add a token-map-only function (not recommended, see above).
  2. Q2 — Accepted colors in the browser entry. Recommended: the CSS Color 4 modes, identical to Node (34.4 KB gzip). Alternative: the minimal mode set (31.6 KB gzip), which rejects lab(), lch(), hwb(), and color().
  3. Q3 — Subpath name. Recommended: @ghostvue/themes/define/browser. Alternative: @ghostvue/themes/define-browser.
  4. Q4 — Transition helper. Recommended: the options form of startThemeTransition above, keeping the positional mode form. Alternatives: stay mode-only and document the pattern; add a separate helper.
  5. Q5 — null means remove. Recommended: yes, for all three keys, as plain attribute removal with the context-dependent result described above. Alternative: no removal, which keeps today's inability to return mode to the system preference.

Follow-up work if approved ​

  1. Split template loading and file I/O out of define-theme.js and compile-tokens.js so the generator core has no Node imports. Keep dist/define.js output and pnpm contrast unchanged.
  2. Build dist/define-browser.js in scripts/bundle-define.mjs (browser platform, culori/fn with the chosen modes, templates inlined). Add the exports and typesVersions entries, a pnpm size budget, a THIRD_PARTY_NOTICES.md note, and a packed-consumer test that bundles the subpath for the browser and checks parity with Node. Extend the main-entry graph test to cover the new subpath staying out of the main entry.
  3. Document live previews in docs/themes/define-theme.md, including that production still ships pre-generated CSS. Add a Changeset (minor).
  4. Add the options form to startThemeTransition, with latest-request-wins and ready handling. Test a combined write making one transition, quick repeated calls ending on the newest value, reduced motion, missing View Transitions, no document, null removal, and invalid names. Update docs/themes/motion.md and this ADR's section 3. Add a Changeset (minor).
  5. Switch the docs theme switcher to the public helper. Keep the docs-local setter for the VitePress appearance toggle, which writes through Vue state rather than an attribute. tests/e2e/docs-landing.spec.ts must keep passing.

Amendment (approved): shared palette sheet (2026-12-04) ​

Important

Approved 2026-12-04, not yet implemented. @zprue743 approved the recommended option for each of Q1–Q6 in the decision in PR #776. This amendment measures emitting the declarations that every palette shares once, in a shared sheet, with each palette shipped as a small sheet of differences. It adds public exports and a new defineTheme output, both additive and opt-in; full palette sheets stay unchanged. The follow-up work implements it. This revision changes no code.

Evidence ​

Apps whose theme picker offers several palettes import a full sheet for each one (section 3). Since #762, each sheet declares mode-invariant tokens once per host, but every sheet still repeats the type, motion, focus, status, and other declarations that are identical in every palette. An app with four palettes ships those declarations four times.

Measurement ​

Measured at commit ee9d8f8 (after #762) with Node 22.23.5 and the packed tarballs and toolchain of pnpm consumer:packed (Vite 8.4.0, production build). Sizes are the bytes of the emitted .css assets, and gzip is zlib.gzipSync level 9, as in cssTransferSize in scripts/lib/consumer-packed.js. pnpm consumer:packed at the same commit printed 115.2 KB minified / 9.7 KB gzip for its opt-in page, matching the one-palette opt-in row below.

Palettes:

  • Built-in: default (tokens.css), calm, vibrant, mono.
  • defineTheme, generated by the packed @ghostvue/themes/define: acme (#0f766e, roundness 0.5), ocean (#1d4ed8), ember (hue 25, compact, roundness 0.25, motion 0.5, elevation dramatic, gradient none), and orchid (oklch(0.55 0.2 320), neutralTint: 'none', spacious, gradient aurora, interactivity expressive, a fontFamily).

"Today" imports the full sheets. "Shared" imports one shared sheet plus a difference sheet per palette, split from the same full sheets as described under How the split works. "One" is calm, "four" the built-ins, and "eight" the built-ins plus the four defineTheme palettes.

PagePalettesToday min (B)Today gzip (B)Shared min (B)Shared gzip (B)Change min / gzip
Palette CSS onlyone80,1855,82182,0555,804+2.3% / -0.3%
Palette CSS onlyfour320,16521,355227,73712,111-28.9% / -43.3%
Palette CSS onlyeight641,29042,135423,92320,310-33.9% / -51.8%
Opt-in page (base + 4 recipes + app)one115,2209,694117,1139,759+1.6% / +0.7%
Opt-in pagefour355,20025,264262,79516,103-26.0% / -36.3%
Opt-in pageeight676,32546,050458,98124,329-32.1% / -47.2%
All-in page (@ghostvue/themes + rest)one489,41840,328491,31140,313+0.4% / -0.0%
All-in pagefour648,25250,707587,56244,504-9.4% / -12.2%
All-in pageeight969,37771,502783,74852,730-19.1% / -26.3%

The all-in page keeps the full default palette that default.css already contains and adds the shared sheet and difference sheets for the others, so it saves less.

Each sheet on its own, as an on-demand import() chunk would load it:

SheetFull min (B)Full gzip (B)Difference min (B)Difference gzip (B)
default81,1705,89949,4922,872
calm80,1855,82148,9472,800
vibrant81,3635,99050,0923,059
mono77,5195,72446,2812,619
acme79,5955,88848,3572,876
ocean79,6405,88748,3912,876
ember80,6515,85749,4022,832
orchid81,3355,91150,2802,965
Shared (once)--33,1683,323

So a palette loaded on demand costs about half as much to transfer. With one palette the shared layout is no smaller than today's full sheet, as expected.

How the split works ​

The split is computed per property, against the four built-in palettes that a package build knows:

  • A property is shared when every built-in palette declares it in the same rules (same at-rules and selectors, with the theme host normalized) with the same values. 140 of 241 properties are shared: 706 of the 1,637 declarations in the default sheet. They are mostly type, motion, focus, status colors, state, track, and color-scheme.
  • Every other property stays in each palette's difference sheet, with all of its declarations. So do shared properties that a palette sets to different values; orchid's fontFamily overrides 2 of them. A palette's declarations of one property are then all in one layer, and source order and @scope proximity among them are unchanged.
  • What remains per palette is mostly the action, surface, text, and border colors, which repeat in every light and dark mode rule, plus elevation, gradients, and the density-scaled control, space, and radius tokens. The density tokens stay per palette because a palette with a non-default density (calm, ember, orchid) re-declares them in its unset-density rule.
  • A finer split, per rule and property, saved 2.4% more minified for four palettes but was larger gzipped (12,541 B against 12,111 B) and depends on reasoning about @scope proximity. It is not proposed.

The shared sheet uses the host :where(.ghost-theme, [data-ghost-theme]) (zero specificity, every token host) in @layer ghostvue-theme.shared. Difference sheets keep today's host selector for their palette in @layer ghostvue-theme.palette.

Equivalence in Chromium. Chrome for Testing 158 (Playwright 1.63.0) rendered 288 hosts: each of the eight palettes, with mode unset, light, and dark, density unset, compact, comfortable, and spacious, under no wrapper, a data-ghost-mode="dark" ancestor, and a data-ghost-density="compact" ancestor. Each host has 12 probe descendants, including dark and light islands, density islands, and a nested host of another palette. The check read all 241 properties with getComputedStyle under light and dark screens, reduced motion, forced colors, print, and touch with 2x device pixel ratio. It compared today's full sheets with three pages: the shared sheet first; the difference sheets in reverse order with the shared sheet last; and a mix of full default and acme sheets with difference sheets for the rest. All 16,241,472 values matched. Two negative controls failed as they should: without the shared sheet, 523,224 values differed; without the layer order statement and with the shared sheet last, orchid's font family lost to the shared value (936 values).

Reproduce. Pack @ghostvue/vue and @ghostvue/themes with packGhostvueTarballs from scripts/themes-define-packed-smoke.mjs, install them into a copy of tests/fixtures/consumer-packed/vite-app with the pins from consumerDependencyPins, and generate the four palettes above with the installed @ghostvue/themes/define. Parse each full sheet with PostCSS, replace its themeHostSelector(name) with a placeholder, and key each declaration by its at-rule chain, selector, and occurrence. Split as described above and write each sheet with @layer ghostvue-theme.shared, ghostvue-theme.palette; at the top. Build each page with vite build (GHOSTVUE_SMOKE_VARIANT=opt-in for the opt-in page and the CSS-only pages), replacing the entry's imports, and sum the emitted .css assets.

Proposal ​

Additive and opt-in. Every existing export and defineTheme().css stays a full, self-contained sheet. Apps with one palette keep using them, and nothing changes for them.

Layer order. base.css, the shared sheet, and every difference sheet start with the same statement:

css
@layer ghostvue-theme.shared, ghostvue-theme.palette;

Whichever sheet loads first fixes the order, and they all agree, so precedence holds in any load order. The negative control above shows that one statement in base.css alone would not be enough. Full sheets keep their declarations directly in ghostvue-theme, which outranks both sublayers, so an app can mix full and difference sheets. Recipes also sit directly in ghostvue-theme, but they declare no --ghost-* tokens or color-scheme, so they do not interact with either sublayer. The position of ghostvue-theme against the app's own layers does not change.

New exports. @ghostvue/themes/palettes/shared.css and @ghostvue/themes/palettes/<name>.css for default, calm, vibrant, and mono, generated in the same package build, so the built-in sheets cannot drift from the shared sheet. The opt-in path for several palettes gains one import:

ts
import '@ghostvue/themes/palettes/shared.css'
import '@ghostvue/themes/palettes/calm.css'
import '@ghostvue/themes/base.css'
import '@ghostvue/themes/recipes/button.css'

For on-demand loading, the shared sheet joins the initial CSS and each loader imports a difference sheet. The all-in path adds the shared sheet and difference sheets next to @ghostvue/themes; default.css keeps its full default palette.

defineTheme output and the version check. A difference sheet is only correct next to the shared sheet it was computed against. If an app upgrades without regenerating a checked-in sheet, a property that moved out of the shared sheet is missing for that palette, and a shared rule added for a property the palette overrides leaks the shared value into it. Nothing fails; the palette quietly changes. A full sheet from an old version, by contrast, stays self-consistent. So:

  • defineTheme returns a new paletteCss next to css, and the CLI gains --palette-only. css is unchanged.
  • paletteCss starts with a stamp comment naming the shared sheet it needs: the first 16 hex digits of the SHA-256 of the shared sheet, plus the package version for people reading it. A content hash, not the version, so a release that leaves the shared sheet alone does not force regeneration.
  • @ghostvue/themes/define exports sharedSheetHash and checkPaletteSheet(css), which throws DefineThemeError naming both hashes when the stamp is missing or different. The CLI gains --check <file>..., which exits non-zero on a mismatch. The docs tell apps that check in generated sheets to run it in CI. Apps that generate sheets in their build are always in step.
  • CSS cannot fail loudly on a mismatch, so the check is a build step, not a runtime one.
  • If a future input made a palette lack a declaration the shared sheet has, defineTheme must throw rather than return a paletteCss that leaks it. None of the four measured inputs did.

Behavior change to document. The shared sheet matches every token host. A host that names a palette whose difference sheet has not loaded gets the shared tokens without that palette's colors and density, instead of no tokens. The rule to load a palette before naming it is unchanged.

Recommendation ​

Ship, as the additive opt-in above. For apps with several palettes it roughly halves palette CSS transfer (gzip -43% for four palettes, -52% for eight) and cuts minified palette CSS by about a third, and each on-demand palette costs about 2.8 KB gzip instead of 5.9 KB. Apps with one palette are unaffected because the full sheets stay. The costs are five new export paths, a hash contract for defineTheme difference sheets with a check function and CLI flag, and one more import for apps that opt in.

The largest remaining per-palette cost is the colors repeated in each light and dark mode rule. Emitting those with light-dark() is a separate, out-of-scope question; it would shrink both the shared and the difference sheets, so it does not change this recommendation.

Declining is reasonable if the maintainer does not want a second palette format to support. Apps that load palettes on demand already avoid most of the cost.

Decision requested ​

Resolved 2026-12-04. The maintainer approved the recommended option for each question below: ship as an additive opt-in. The alternatives stay listed as the record of what was considered.

  1. Q1 - Ship. Recommended: yes, additive and opt-in, with full sheets unchanged. Alternatives: decline; or make the existing palette exports difference sheets (breaking for every opt-in app, and no gain for one palette).
  2. Q2 - Layers. Recommended: ghostvue-theme.shared and ghostvue-theme.palette, with the order statement at the top of base.css, the shared sheet, and every difference sheet.
  3. Q3 - Split rule. Recommended: per property, against the built-in palettes. Alternative: per rule and property (not smaller gzipped).
  4. Q4 - defineTheme output and check. Recommended: paletteCss, --palette-only, a shared-sheet content hash stamp, sharedSheetHash, checkPaletteSheet, and --check. Alternative: a package-version stamp (simpler, but every release forces regeneration).
  5. Q5 - Export paths. Recommended: palettes/shared.css and palettes/<name>.css. Alternative: shared.css and <name>.palette.css.
  6. Q6 - Unloaded palettes. Recommended: accept that a host naming an unloaded palette gets the shared tokens, and document it.

Follow-up work if approved ​

  1. In compile-tokens.js, compute the shared sheet from the built-in palettes and render difference sheets, keeping full sheets byte-identical. Add the layer order statement to base.css. Cover the split rule, the stamp, and the throw for a missing shared declaration in tests/integration/token-pipeline.test.ts.
  2. Add paletteCss, sharedSheetHash, checkPaletteSheet, and the CLI flags to define-theme.js, with tests for a matching stamp, a different stamp, and no stamp.
  3. Add the exports, typesVersions if needed, and pnpm size budgets for the new sheets.
  4. Add a Playwright check like the equivalence check above (a smaller matrix) comparing full and shared sheets in both load orders, and extend pnpm consumer:packed with a page that imports the shared sheet and several difference sheets and prints its size.
  5. Document the multi-palette setup, on-demand loading, and the check in docs/themes/default.md and docs/themes/define-theme.md. Update this ADR. Add a Changeset (minor).