Install Cortex

Install @flexpixels/cortex, pick the right entry point, and see what the package gives you.

Install the package with your package manager:

bash
npm install @flexpixels/cortex@beta
# or
pnpm add @flexpixels/cortex@beta
yarn add @flexpixels/cortex@beta
bun add @flexpixels/cortex@beta

Cortex runs on Node.js 20 or later, on Bun, and in the browser through a bundler. It needs no framework and touches no DOM. The package is ES modules only: import it. From CommonJS use await import("@flexpixels/cortex"); require() of an ES module works only from Node.js 20.19 and 22.12 on.

Runtime dependencies: culori, apca-w3 and zod. The package also lists @types/culori, so its type declarations compile under strict TypeScript; it holds types only and adds no code.

In the browser

The usual choice is to generate the stylesheet at build time and ship only the CSS: the page then loads no JavaScript from Cortex. Run the engine in the browser only when the theme changes at runtime, such as a theme editor.

The browser build imports zod and culori by bare name, so a plain <script type="module"> cannot load it: it needs a bundler (Vite, webpack, esbuild, Bun) to resolve them. An app that generates a theme at runtime with mergeThemeConfig and generateThemeCSS comes to about 290 KB minified (about 95 KB gzipped) through webpack, Vite or Bun, and more through esbuild, which keeps zod’s locale files. The package does not tree-shake today: importing a single helper such as autoContrastFg still bundles about 200 KB.

For live theming, import @flexpixels/cortex/runtime instead: CSS generation and the contrast check, with no zod and no schema validation (it still refuses unsafe CSS values), in about 166 KB minified (58 KB gzipped) with culori and apca-w3 bundled in. Its stylesheet is the full engine’s, byte for byte. See Runtime entry.

Entry points

Import pathUse it for
@flexpixels/cortexEverything, including the Node-only config loader (loadUserConfig, loadConfigFromPath, mergeWithDefaults). Bundlers that target the browser get the browser build.
@flexpixels/cortex/browserThe browser build: the same engine, schemas, contrast helpers and exports, without the config loader.
@flexpixels/cortex/runtimeLive theming in the browser: generateThemeCSS, mergeThemeConfig, defaultThemeConfig and checkContrast, without zod. See Runtime entry.
@flexpixels/cortex/nodeThe Node build, by name. Same as the default under Node and Bun.
@flexpixels/cortex/theme-config.schema.jsonThe JSON Schema for theme-config.json, for editor validation and completion.
@flexpixels/cortex/a2ui-bridge.cssA stylesheet that themes the A2UI v0.9 basic catalog with cortex tokens. See A2UI bridge.

What you get

  • generateThemeCSS(config) — the stylesheet a page loads by default: the lean set (599 tokens for the theme @flexpixels/ui ships), with light and dark values in light-dark() pairs.
  • generateFullThemeCSS(config) — every token the engine computes (1,034 for that theme), including the APCA contrast matrix and the chart palette. Both stylesheets also carry P3 wide-gamut overrides, a forced-colors block, [data-theme] switching, and static fallbacks for older browsers when output.legacyFallback is set (off by default).
  • ThemeEngine — a class that holds a validated config and its token tree.
  • exportDTCGTokens(config) — the tokens as W3C DTCG JSON.
  • exportDesignMd(config) — a Markdown description of the theme for people and AI agents.
  • Contrast helpers — calcLc, calcLcHex, wcagRatio, checkContrast, buildContrastMatrix. checkContrast(foreground, background, level?) takes CSS colour strings. wcagRatio(fgL, fgC, fgH, bgL, bgC, bgH) and calcLc take OKLCH components, not colour strings; for two CSS colours use checkContrast. See Contrast.
  • Zod schemas and validators — ThemeConfigSchema, validateThemeConfig, mergeThemeConfig.
  • Soft warnings — collectThemeWarnings(config) for checks that do not block generation.

See the API overview for the full list.

For AI agents

@flexpixels/cortex-mcp is cortex’s MCP server. An agent can read your tokens and theme, validate configs, generate theme CSS, and check typography, elevation and contrast. It needs Node.js 20 or later. Its only FlexPixels dependency is cortex:

json
{
  "mcpServers": {
    "cortex": { "command": "npx", "args": ["-y", "@flexpixels/cortex-mcp@beta"] }
  }
}

See AI agents (MCP) for the tools it offers.

Next