generateFullThemeCSS

The serializer that turns a theme config into a stylesheet of every token, and how it relates to generateThemeCSS, the lean default.

ts
import { generateFullThemeCSS, type ThemeConfig } from "@flexpixels/cortex";

const css: string = generateFullThemeCSS(config);

generateFullThemeCSS(config) returns a stylesheet with every token the engine computes. generateCSSOutput is the same function under another name.

Most pages want the smaller default instead:

ts
import { generateThemeCSS } from "@flexpixels/cortex";

const css = generateThemeCSS(config); // lean unless config.output.tokens is "full"

generateThemeCSS builds the full stylesheet and keeps the tokens in use: what FlexPixels components read, the public tier, the colour ramps, type roles and size axis, and everything those reference. It leaves out the APCA contrast matrix, -contrast on steps nobody reads, the chart palette and unreferenced primitives. Both functions return the same structure; see Build & Import for the trade-off.

Parameters

  • config: ThemeConfig — a complete config. Get one from mergeThemeConfig(partial) (merges over the defaults, applies scenarios, validates; works in the browser), from loadUserConfig(path) or loadConfigFromPath(path) (Node, same pipeline from a file), or use defaultThemeConfig. validateThemeConfig(input) also works but does not merge, so the input needs at least the three brand seeds. A plain object with the three seeds works as it is: the function reads the validated config, not the object you passed.

The function validates the config again (through ThemeEngine) and throws a ZodError if it is invalid.

Returns

One CSS string, in this order:

  • Header comment with config.name and the schemes setting.
  • :root { … } with color-scheme and every token:
    • colour: per role --fp-{role}-h, -c, -seed (for seeds you set), steps 1–12, -contrast and the matrix (-on-text, -on-text-soft, -on-icon) on every step, -text, -border, alphas a1–a5; the chroma curve --fp-C-1…12; static --fp-white-a* / --fp-black-a*; the chart palette --fp-chart-*;
    • spacing primitives (--fp-dim-*), the semantic scale --fp-s-1…12, insets, gaps, the size axis and icon sizes;
    • radius primitives and --fp-corner-*, border widths, --fp-stroke-* and glows;
    • elevation levels and aliases, surface tints, shadow tint, glass tokens, and the optional surface-aware and perceptual tokens;
    • typography primitives, --fp-text-{role}-* for every type role, reading-comfort tokens;
    • interaction (durations, easings, state layers, spring, stagger, focus ring, opacity, active scale), layout (breakpoints, containers, grid), scrollbar tokens;
    • surface aliases: --fp-surface-{app,subtle,element,hover,active}, --fp-border-subtle-color, --fp-border-strong-color, --fp-text-{subtle,muted,default};
    • with vision.variants set, --fp-vision-variants, the list of variants the theme ships.
  • Surface-style rules when the config asks for them (liquid glass, glow, ambient light), which give way to opaque surfaces under prefers-reduced-transparency, prefers-contrast: more and forced colours.
  • Size-axis rules: [data-size="sm"], "md", "lg" and a (pointer: coarse) block that raises minimum targets.
  • @media (color-gamut: p3), raising the chroma curve at steps 7, 8 and 10 on wide-gamut displays (step 9 is already at full chroma).
  • @property registrations for the motion switches --fp-transitions, --fp-animations (normal | reduced | none) and --fp-motion-scale.
  • @media (min-width: 1920px), setting --fp-viewport-scale: 1.125.
  • @media (forced-colors: active), mapping tokens to system colours.
  • [data-theme="light"] / [data-theme="dark"] rules (only when settings.schemes is "both").
  • Old-engine fallbacks, with output.legacyFallback: true only: sizes are declared without round(), and an @supports (width: round(nearest, 4px, 1px)) block adds pixel snapping where the browser supports it; browsers without light-dark() or relative colour get static rgb() colours from @supports not ((color: light-dark(red, blue)) and (color: oklch(from red l c h))). By default the stylesheet is modern-only (about 40% smaller) and those browsers resolve no colour token.
  • Vision palettes: with vision.variants set and vision.output: "inline" (the default), one block per variant on :root[data-vision="…"], holding the declarations that variant changes.

With settings.schemes: "light" or "dark", every light-dark() is reduced to that scheme’s value and the [data-theme] rules are left out.

The stylesheet does not contain a prefers-reduced-motion rule. Reduced motion is applied by the motion sheet components adopt (generateMotionHostCSS), which reads the switches above and the OS preference.

Browser usage

The browser entry has the same function:

ts
import { generateThemeCSS, mergeThemeConfig } from "@flexpixels/cortex/browser";

const css = generateThemeCSS(mergeThemeConfig(userPartial));
document.getElementById("runtime-theme")!.textContent = css;

This is how a live theme editor works: regenerate on each change and replace the <style> contents.

Without serializing: generateAllTokens

Most token values come from generateAllTokens(config), which returns the tree the serializer writes (AllTokens). The serializer adds some of its own: the rgb() fallbacks for old engines (when output.legacyFallback asks for them), the page text solved under elevation.ambient, the vision blocks, the surface-style rules (--fp-glow-size, --fp-surface-app-image and the liquid-glass surface fills), the P3 chroma overrides, the forced-colours map and the size-axis rules. Use generateAllTokens to walk tokens or compare two configs; a serializer of your own built on it would not have those additions:

ts
import { generateAllTokens } from "@flexpixels/cortex";

const tree = generateAllTokens(config);
tree.color.primary[9]; // { $value: "var(--fp-primary-seed)", $type: "color", … }
tree.elevation[1]; // the level-1 shadow token
tree["surface-tint"][2]; // surface tint, level 2

$value is often a CSS expression here, not a resolved colour. For portable JSON with resolved values, use exportDTCGTokens.

  • ThemeEngine — the class the serializer builds on.
  • Build & Import — writing the output and importing it in each bundler.
  • OKLCH — how the colour tokens are computed.