API overview
The main public exports of @flexpixels/cortex, grouped by purpose, with the entry point for each.
@flexpixels/cortex turns a theme config into tokens and CSS. Apart from the ThemeEngine class, which holds one config, its exports are functions and data whose results depend only on their inputs. It touches no DOM, and only the config loader reads files. Every export below comes from the package root; everything except the config loader also comes from @flexpixels/cortex/browser.
Entry points
| Path | When to use |
|---|---|
@flexpixels/cortex | Everything, including the Node-only config loader. Under a bundler’s browser condition it resolves to the browser build. |
@flexpixels/cortex/browser | Everything except loadUserConfig, loadConfigFromPath and mergeWithDefaults. Safe to bundle for the browser. |
@flexpixels/cortex/runtime | Live theming in the browser: CSS generation and checkContrast, without zod. See Runtime entry. |
@flexpixels/cortex/node | The Node build by name; the same as the root under Node and Bun. |
@flexpixels/cortex/theme-config.schema.json | The JSON Schema of theme-config.json, for editors. |
@flexpixels/cortex/a2ui-bridge.css | A stylesheet that maps the A2UI v0.9 basic-catalog variables onto cortex tokens. See A2UI bridge. |
Theme stylesheets
generateThemeCSS(config, options?)— the stylesheet a page loads by default. It honoursconfig.output: the lean token set unlessoutput.tokensis"full". Options:reads(the token names your components use; defaults to what FlexPixels components read) andfull(a full stylesheet you already generated, to skip generating it again).generateFullThemeCSS(config)— every token the engine computes. Alias:generateCSSOutput.generateThemeSubsetCSS(config, { roots, name?, full? })— a stylesheet with only the tokens named inrootsand everything they reference.subsetThemeCSS(css, roots)— the same, from a stylesheet you already have.diffThemeCSS(base, next, { reset? })— the declarations ofnextthat differ frombase, and a reset for each custom property onlybasedeclares: what to load afterbaseto getnext.reset: falseonly adds and overrides. A diff cannot undo an@propertyregistration: after a prefix change, the base’s registered motion switches keep their initial values.declaredCustomProperties(css),themeTokenNames(css)— the custom property names a stylesheet declares (the second also counts@propertyregistrations).leanThemeRoots(css, config, reads?),LEAN_FAMILIES,CONTRAST_MATRIX,COMPONENT_READS— what decides the lean set.generateSizeHostCSS(config),generateMotionHostCSS(config),generateMotionCSS(prefix, scope)(the scope is what sits inside the root, such as":root *"; the root itself has no parent to read the switches from and is refused) — the size-axis and motion sheets FlexPixels components adopt in their shadow roots.CONDITIONAL_THEME_TOKENS— tokens a theme declares only under some configs (glow-size,surface-app-image,vision-variants).buildModernThemeCSS(config)— the full stylesheet before the compatibility fallbacks and the vision blocks are added.parseCssNodes(css)— parses a stylesheet intoCssNodes (blocks, declarations, block-less at-rules). It is written for the theme’s own output and throws on an unbalanced brace.retargetRoot(css, selector, drop?)— moves every:rootrule toselectorand leaves out the blocks whose preludedropreturns true for.
See Build & Import for choosing between lean and full.
Token tree
ThemeEngine— holds a validated config and its token tree (getTokens,getConfig,getPrefix,getContrast,updateConfigto merge a change,setConfigto replace).generateAllTokens(config)— the token tree as plain data (AllTokens), without serializing it.- Per-domain generators, for advanced pipelines:
generateColorTokens,generateDataVizTokens,generateSpacingTokens,generateRadiusTokens,generateBorderTokens,generateElevationTokens,generateInsetTokens,generateGapTokens,generateSizeTokens,generateInteractionTokens,generateLayoutTokens,generateScrollTokens,generateTypographyTokens.
Config: schemas, validation, loading
validateThemeConfig,mergeThemeConfig,deepMergeand the schemas —ThemeConfigSchema,ThemeSettingsSchema,SeedsSchema,LayoutConfigSchema,InteractionConfigSchema.loadUserConfig,loadConfigFromPath,mergeWithDefaults— Node-only helpers that read a config file.defaultThemeConfig— the complete default config, frozen.
Export formats
exportDTCGTokens(config, options?)— the tokens as W3C DTCG 2025.10 JSON, for Figma Tokens, Style Dictionary and other tools (Style Dictionary needs custom transforms for native sizes and dark values: see Style Dictionary).exportDesignMd(config, options?)— a Markdown description of the theme for people and AI agents.
The public token tier
The closed set of tokens the AI-facing outputs (DESIGN.md with tier: "public", the MCP token tools) offer by default:
PUBLIC_TIER— the tokens, each with a group and a purpose;TIER_GROUPS— the group names.isPublicToken(name, prefix?),publicTierByGroup()— look-ups.publicTierValues(config)— each public token’s resolved value for a config.resolveTokens(css, names, prefix?, scheme?)— resolve token names to values in a stylesheet.namesare bare ("primary-9", not"--fp-primary-9"), and a name the stylesheet does not declare throws.
Contrast and colour math
calcLc,calcLcHex,wcagRatio,checkContrast,buildContrastMatrix— APCA and WCAG primitives.LC_TARGETS,WCAG_FLOORS,WCAG_FLOORS_AAA— the per-tier targets the engine applies (the AAA floors whensettings.accessibilityis"AAA").srgbChromaCeil(h)— the highest seed chroma at huehthat keeps steps 7–10 inside sRGB;maxSrgbChroma(h, l)— the highest chroma sRGB can show at a hue and lightness.hoverOf(seed, scheme),HOVER_DELTA_L— how step 10 is derived from a brand seed.textColor(base, page)— the nearest colour tobasethat reaches 4.5:1 on every page colour.resolveSurfaceAnchor(seeds, neutralSeed, scheme)— the neutral steps thatseeds.surfaceoverrides in a scheme ("dark"when left out).
See Contrast for how they fit together.
Soft warnings
collectThemeWarnings,collectTypographyWarnings,collectElevationWarnings,collectColorWarnings,collectSizeWarnings— checks that never block generation, returned asThemeWarning[].
Typography metadata
getResolvedTypeStyle(typography, role)— the type style for a role: yours fromtypography.typeStylesif you define it, otherwise the built-in one.listBuiltInTextRoles()— the 14 built-in roles:caption,label,body,body-lg,title,headline,display,button,input,helper,code,link,quote,data.computeLineHeights(fontSizes, formula?, roundTo?)— the default line-height ladder for a scale.
Font metrics and shadow visibility
INTER_METRICS,GEIST_MONO_METRICS— bundledFontMetricsfor the default families.computeTrim(metrics, lineHeightEm)— leading-trim offsets for cap-height and baseline alignment.computeShadowVisibility(shadowL, bgL, alpha)—{ contrast, perceivedDepth }for a shadow on a background.SURFACE_BACKGROUND_LIGHTNESS,FLAT_SHADOW_LIGHTNESS— the lightness constants behind the opt-in perceptual elevation tokens.FLAT_SHADOW_LIGHTNESSis also the lightness of the surface-aware shadow tints.
Token helpers and DTCG types
- Factories:
dimToken,dimPx,aliasToken,colorToken,cssExprToken,shadowToken,numberToken,durationToken,cubicBezierToken,fontFamilyToken,compositeTypographyToken. - Type guards:
isDimension,isColor,isShadowObject,isShadowArray. - Types:
DTCGValue,DTCGDimension,DTCGColor,DTCGShadowObject,W3CToken,TokenTree.
Constants
Plain data, safe to read from tooling and agent code:
HUE_ANCHORS— hues of the generated semantic roles (success 145, danger 25, warning 85, info 250).CHROMA_LIGHTNESS_RAMP_LIGHT,CHROMA_LIGHTNESS_RAMP_DARK— the 12-step OKLCH lightness ramps.CHROMA_CURVE— the per-step share of the seed’s chroma.ALPHA_RAMP— the staticwhite/blackalpha ramp;ALPHA_STOPS— thea1..a5opacities of each role.STEP_USAGE— what each of the 12 steps is for.TYPOGRAPHY_SCENARIOS,ELEVATION_SCENARIOS— the bundles behindtypography.scenarioandelevation.scenario.COLOR_ROLES—primary,secondary,neutral,success,danger,warning,info.DEFAULT_BREAKPOINTS—xs320,sm640,md768,lg1024,xl1280,2xl1920.GRADIENT_PRESETS—none,primary-secondary,primary-neutral,secondary-neutral.
Vision palettes and colour-vision simulation
How the palettes are used is on Vision variants.
visionPalettes(config, kinds?, policy?)— oneVisionPaletteper kind (all four by default): the seeds and settings the variant changes, the variant’s full config, and a report on whether it met its targets.adaptPaletteForVision(config, kind, policy?)— the same for one kind.generateVisionCSS(config)— each variant’s block (the declarations its palette changes, on:root[data-vision="…"]), keyed by kind.generateFullThemeCSSinlines these blocks unlessvision.outputis"separate".variantConfig(config, seeds, settings?)— your config with a variant’s seeds and settings applied, and no variants of its own.VISION_KINDS—red-green,blue-yellow,monochrome,high-contrast.VISION_SIMULATES— the deficiencies each kind is measured under.VISION_TARGETS— the smallest CIEDE2000 between two roles’ step 9 that each kind aims for.SEMANTIC_HUE_WINDOWS,inHueWindow(role, hue)— the OKLCH hue range each semantic role stays in, and whether a hue is inside it.simulateCvd(color, kind)— a colour as seen with protanopia, deuteranopia or tritanopia (theMACHADO_2009matrices on linear sRGB), or achromatopsia (a grey of the same luminance).cvdDeltaE(a, b, kind)— the CIEDE2000 between two colours as that vision sees them.
Auto-contrast
For a background colour that is known only at runtime, so no token can be solved for it:
autoContrastFg(r, g, b)—"#ffffff"or"#000000", picked by luminance. It clears 4.5:1 on every sRGB colour.autoContrastTint(r, g, b, tint?)— that colour mixedtint(default 0.25) of the way back toward the background in oklab. For icons and boundaries (3:1), not text.autoLuminance(r, g, b)— the luminance the CSS rule computes (channels 0–255, linearised withpow(x, 2.2)).autoContrastCss()— the--fp-auto-textand--fp-auto-icondeclarations that@flexpixels/uiships intheme/auto-contrast.css.AUTO_CONTRAST— the rule’s gamma, threshold, luminance coefficients, tint and floors.
Rendered colours and contrast pairs
renderedColors(css, { overlay? })— returns a lookup(name, mode) => string: the colour a browser paints for a token ofcssin"light"or"dark".nameis the full custom property name ("--fp-primary-9", not"primary-9"asresolveTokenstakes).overlaylays extra declarations over:root.renderedContrast(a, b)— the WCAG 2 ratio of two CSS colours. Throws if either is not a colour.colorChannels(css)— a CSS colour as sRGB channels on 0–1 with alpha, ornull.tokenAliases(css)— returns(name) => string[]: the tokens a token is a plainvar()alias of, nearest first.contrastPartners(background, roles?)— the foreground tokens the contrast contract pairs with a background, for text, soft text and icons, with the background’s kind and a one-line note.isContrastPartner(foreground, background, roles?)— whether a foreground token is one of those partners.tokenName(value)— the bare token name:--fp-primary-9,var(--fp-primary-9)andprimary-9all giveprimary-9. It returnsnullfor a value it does not recognise.
Their types are exported too: VisionKind, VisionPolicy, VisionPalette, VisionReport, VisionMetrics, CvdKind, Rendered, RenderedOptions, BackgroundKind, ContrastPartners, CssNode.
The sidebar pages cover the most-used groups in depth; Helpers & constants covers the token factories, constants and metrics.