DESIGN.md export

Generate a Markdown description of the resolved theme, for people and AI agents to read beside your code.

ts
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:

SectionSource
Headerconfig.name, the WCAG level, the schemes and the CSS prefix.
Token ArchitectureThree-layer API table (primitives / DNA / semantics) for every pillar.
Color PaletteSeeds, hex previews of step 9, the full 12-step usage guide, primary-scale preview, alpha stops — all sized to the actual token tree.
TypographyFamily slots, base size, line-height formula, the font-size + line-height scale, weights, letter-spacings, and your own typeStyles (when the config sets any).
SpacingBase unit, scale mode, s-1..s-N table with multipliers and px/rem values.
Border RadiusBase value, primitive scale, semantic corner-* aliases.
BordersBase width, width scale, semantic stroke-* aliases, gradient block (only when configured).
Elevation & ShadowsThe elevation style, shadow intensity / tint chroma, the level ladder, and the surface tints (from neutral step 9).
InteractionTransitions, focus ring, disabled opacity, active scale.
LayoutGrid columns/gutter, breakpoints, section spacing.
Data-Viz PalettesThe categorical, sequential and diverging chart colours and their roles.
Surface SemanticsThe 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 VariantsEach vision palette, what it is for, the seeds it changes and whether it met its targets (only with vision.variants).
UsageCSS 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 an fp-* component or a component hook. With tier: "public" it covers, in order: how to use the document; applying the theme (loading the stylesheet, the Tailwind imports, color-scheme and data-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’s export_design_md returns by default. With tier: "all" it is the whole-theme document above without the component-hook pattern.
  • "flexpixels" is for a project built with the fp-* components, which carry the theme themselves: text through <fp-typography>, a component changed through its own hooks. It is what @flexpixels/mcp’s export_design_md returns by default, and the version the FlexPixels repository commits as its DESIGN.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

OptionDefaultDescription
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.
includeUsageExamplestrueAppend the “Usage” block with concrete CSS snippets for cards, buttons, and the two-tier component hook pattern.
includeComponentHookstrueWith 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.md beside 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

ts
// 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.