DESIGN.md export
Generate a Markdown description of the resolved theme, for people and AI agents to read beside your code.
import { exportDesignMd, type DesignMdOptions } from "@flexpixels/cortex";
const markdown: string = exportDesignMd(config, {
audience: "cortex", // default; "flexpixels" for a project built with the fp-* components
includeUsageExamples: true, // default
includeComponentHooks: true, // default; only the "flexpixels" edition has component hooks
tier: "all", // default; "public" for the short, agent-facing version
});exportDesignMd(config, options?) builds a ThemeEngine from the config and writes a Markdown document from its token tree. Token names, counts, scale steps and colour previews come from the engine output, so a regenerated DESIGN.md always matches the theme it describes.
What it covers
With tier: "all" (the default) the document describes the whole theme:
| Section | Source |
|---|---|
| Header | config.name, the WCAG level, the schemes and the CSS prefix. |
| Token Architecture | Three-layer API table (primitives / DNA / semantics) for every pillar. |
| Color Palette | Seeds, hex previews of step 9, the full 12-step usage guide, primary-scale preview, alpha stops — all sized to the actual token tree. |
| Typography | Family slots, base size, line-height formula, the font-size + line-height scale, weights, letter-spacings, and your own typeStyles (when the config sets any). |
| Spacing | Base unit, scale mode, s-1..s-N table with multipliers and px/rem values. |
| Border Radius | Base value, primitive scale, semantic corner-* aliases. |
| Borders | Base width, width scale, semantic stroke-* aliases, gradient block (only when configured). |
| Elevation & Shadows | The elevation style, shadow intensity / tint chroma, the level ladder, and the surface tints (from neutral step 9). |
| Interaction | Transitions, focus ring, disabled opacity, active scale. |
| Layout | Grid columns/gutter, breakpoints, section spacing. |
| Data-Viz Palettes | The categorical, sequential and diverging chart colours and their roles. |
| Surface Semantics | The surface, border and text aliases (--fp-surface-*, --fp-border-{subtle,strong}-color, --fp-text-{subtle,muted,default}), from the same list the CSS serializer uses. |
| Accessibility Variants | Each vision palette, what it is for, the seeds it changes and whether it met its targets (only with vision.variants). |
| Usage | CSS Custom Property + component-hook examples (toggled via options). |
With tier: "public" it describes only the public token tier: a table per group (surface, text, border, intent, spacing, radius, elevation, type, motion and so on) of the tokens to build screens with, each with its Tailwind utility, its light and dark value and its purpose. includeUsageExamples and includeComponentHooks do not apply to it.
Two editions
audience says who reads the document.
"cortex"(the default) is for a project that uses the theme with its own components: plain CSS, Tailwind through@flexpixels/tailwind, shadcn/ui or anything that reads CSS variables. It never names anfp-*component or a component hook. Withtier: "public"it covers, in order: how to use the document; applying the theme (loading the stylesheet, the Tailwind imports,color-schemeanddata-theme, the page’s own background and text); the seeds and the page colour of each scheme when the config sets one; which text goes on which surface and the floor each pair is held to; the token tables; the type roles, each with its Tailwind utility, family utility and variables; a card in plain CSS and in Tailwind; and what not to do. It is what@flexpixels/cortex-mcp’sexport_design_mdreturns by default. Withtier: "all"it is the whole-theme document above without the component-hook pattern."flexpixels"is for a project built with thefp-*components, which carry the theme themselves: text through<fp-typography>, a component changed through its own hooks. It is what@flexpixels/mcp’sexport_design_mdreturns by default, and the version the FlexPixels repository commits as itsDESIGN.md.
The "cortex" edition’s test fails if it ever names an fp-* tag, and the Tailwind bridge’s test compiles every utility it names and checks that it resolves to a token.
Options
| Option | Default | Description |
|---|---|---|
audience | "cortex" | "cortex": for a project with its own components; names no fp-* component. "flexpixels": for a project built with the fp-* components. See Two editions. |
includeUsageExamples | true | Append the “Usage” block with concrete CSS snippets for cards, buttons, and the two-tier component hook pattern. |
includeComponentHooks | true | With audience: "flexpixels" and includeUsageExamples on, include the “Component Hook Pattern” subsection: a component reads its own hook first, then the system token (--_radius: var(--fp-button-border-radius, …)), and is overridden with fp-button { --fp-button-background: … }. |
tier | "all" | "all": the whole theme, as above. "public": only the public token tier, for AI agents. |
Why ship it
- One file for agents. Commit
DESIGN.mdbeside the code so agents and contributors read one file for the theme’s tokens. - Checked in CI. Regenerate it in CI and compare with the committed file to catch a config change nobody re-exported.
- Plain Markdown. People and agents read it as it is.
Example pipeline
// scripts/build-design-md.ts
import { writeFileSync } from "node:fs";
import { exportDesignMd, loadUserConfig } from "@flexpixels/cortex";
const config = loadUserConfig("theme-config.json");
writeFileSync("./DESIGN.md", exportDesignMd(config));The FlexPixels repository does the same in scripts/build-design-md.ts (with tier: "public" and audience: "flexpixels"); bun run design:md:verify fails when the committed file is out of date.
Browser-safe
exportDesignMd is exported from both the root entry and the /browser build. It has no Node.js dependency (no fs or path), so it runs in the browser too. writeFileSync in the example above is the only Node-only piece; in a browser you would take the returned string and download or display it instead.