generateFullThemeCSS
The serializer that turns a theme config into a stylesheet of every token, and how it relates to generateThemeCSS, the lean default.
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:
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 frommergeThemeConfig(partial)(merges over the defaults, applies scenarios, validates; works in the browser), fromloadUserConfig(path)orloadConfigFromPath(path)(Node, same pipeline from a file), or usedefaultThemeConfig.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.nameand theschemessetting. :root { … }withcolor-schemeand every token:- colour: per role
--fp-{role}-h,-c,-seed(for seeds you set), steps1–12,-contrastand the matrix (-on-text,-on-text-soft,-on-icon) on every step,-text,-border, alphasa1–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.variantsset,--fp-vision-variants, the list of variants the theme ships.
- colour: per role
- 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: moreand 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).@propertyregistrations 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 whensettings.schemesis"both").- Old-engine fallbacks, with
output.legacyFallback: trueonly: sizes are declared withoutround(), and an@supports (width: round(nearest, 4px, 1px))block adds pixel snapping where the browser supports it; browsers withoutlight-dark()or relative colour get staticrgb()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.variantsset andvision.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:
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:
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.
Related
- 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.