CSS artifact generation
CSS artifact generation turns the resolved style model and extracted style usage into the files that an application consumes. It produces ordered CSS, runtime style APIs, type declarations, recipe and pattern modules, JSX helpers, and theme data while keeping these outputs aligned with the same design tokens, conditions, utilities, and configuration.
Generation boundary
The generator is the output boundary of the compiler pipeline. It reads the shared context built from configuration and extracted styles, then exposes complete artifacts or selected artifact groups for the build and incremental update paths. packages/…/generator.ts• L46-68 packages/…/index.ts• L5-14
Read this page with the broader compiler pipeline, the configuration resolution page, and the source extraction and parsing page. Those pages explain how the generator receives resolved settings and extracted style data.
An artifact is a named output group with one or more files. The group can represent CSS, a JavaScript API, type declarations, an index, or theme data. This common shape lets the writer coordinate different output kinds without treating each file as a separate compiler result. packages/…/artifact.ts• L3-59
CSS output layers
The CSS generator assembles a stylesheet from stable layers. Baseline CSS establishes the layer order and adds optional reset rules, token variables, static rules, global rules, and keyframes. Parser CSS then adds rules derived from styles found in source files. packages/…/generator.ts• L70-89
The following diagram shows how resolved configuration and extracted style data become one CSS result or a set of split CSS files.
flowchart LR
C[Resolved configuration] --> B[Baseline CSS]
E[Extracted style usage] --> P[Parser CSS]
B --> S[Stylesheet layers]
P --> S
S --> O[Single styles.css]
S --> X[Split layer, recipe, and theme CSS]
Each CSS generator owns one source of rules and appends it to the matching stylesheet layer. Token output creates custom properties and conditional theme values. Static output expands configured static styles. Global output adds configured global rules. Reset output adds the optional preflight rules. Keyframe output serializes configured animations. packages/…/token-css.ts• L7-48 packages/…/static-css.ts• L4-17 packages/…/global-css.ts• L3-11 packages/…/reset-css.ts• L6-10 packages/…/keyframe-css.ts• L4-19
Extracted style rules
Parser CSS converts the collected style decoder into stylesheet rules. The decoder carries the styles found during source processing, while the stylesheet handles their placement and serialization. If serialization fails, the generator reports the failure and returns no parser CSS instead of returning a partial string. packages/…/parser-css.ts• L5-19
The complete build adds parser CSS after baseline CSS. A minimal build skips the baseline layers and processes only the extracted rules. This distinction supports output that contains only source-driven CSS when the caller requests it. packages/…/cssgen.ts• L13-53
CSS artifact modes
The CSS entry point supports a full stylesheet, a named CSS artifact, and split output. A named artifact writes only one baseline category, while full output combines the configured baseline with extracted rules. Split output keeps layer order in a main index and places recipe and theme CSS in separate files. packages/…/cssgen.ts• L13-50 packages/…/generator.ts• L91-117
Split output treats themes as opt-in files rather than automatic imports. Recipes receive one file per recipe and are gathered by a recipes index. The main stylesheet imports the generated layer files and the recipes index in the configured layer order. packages/…/generator.ts• L131-205
Generated API outputs
Generated APIs give application code typed access to the same style model used for CSS. The generator creates the css function and related composition helpers, recipe and pattern modules, design-token access, and framework-specific JSX helpers when the selected syntax and framework support them. packages/…/setup-artifacts.ts• L121-173 packages/…/setup-artifacts.ts• L175-371
The generated css API embeds the utility map, shorthand rules, conditions, prefix, and hash behavior from the context. Its runtime output therefore follows the same naming and condition rules as the CSS generated from extracted source styles. packages/…/css-fn.ts• L4-8 packages/…/css-fn.ts• L99-128
Recipes turn configured variant data into callable style APIs and matching declarations. Their generated JavaScript carries variant behavior, while their declarations describe valid variant props and return values. Recipe files and their index are emitted only when recipes exist. packages/…/recipe.ts• L111-249 packages/…/setup-artifacts.ts• L191-223
Type and specification outputs
Type output describes the generated style surface for editors and type checkers. It covers style props, conditions, tokens, selectors, composition, recipes, patterns, JSX support, and system types. Some shared type material is adjusted for the configured JSX style-prop mode before it is written. packages/…/setup-artifacts.ts• L46-119 packages/…/generated.ts• L12-41
Specifications provide structured descriptions of the resolved design system for tools that need data rather than executable code. The generator can return the complete specification set or one named specification, with optional color-palette and theme specifications when those values exist. packages/…/generator.ts• L209-264
Artifact selection and coordination
Artifact coordination maps each artifact identifier to a generator and then applies the requested selection. Incremental work can narrow recipe and pattern files to the affected names while retaining index files, so dependent exports remain current without rewriting every generated module. packages/…/setup-artifacts.ts• L416-469
The emitTokensOnly setting is a special output mode. It bypasses the normal artifact set and emits only the design-token files. Type files receive an eslint disable header during final preparation, and empty generated files are removed from the result. packages/…/index.ts• L9-14 packages/…/setup-artifacts.ts• L510-529
Change checklist
When these files or sections are changed, remember to consider these:
- When a CSS layer name or layer order changes, update split-file imports and the recipes and theme placement together.
- When utility, condition, prefix, hash, or shorthand rules change, keep the generated
cssAPI and parser CSS behavior aligned. - When an artifact identifier changes, update its type, setup entry, selection filters, and any incremental affected-file mapping.
- When a generated type source changes, check the related runtime module and its index export so the type and value surfaces still match.
- When theme or recipe emission changes, preserve the distinction between automatic imports and files that users must import explicitly.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A CSS artifact type is not registered in the central dispatcher | A requested artifact fails with an unknown-artifact error | Keep the CSS artifact union and dispatcher cases in sync. |
| Split layer names differ from the names used in generated imports | The output index points to the wrong cascade layers or files | Treat configured layer names and split imports as one contract. |
| A recipe or pattern changes but its index is not regenerated | The new module exists but is not exported | Retain index files when filtering affected artifacts. |
| Token conditions refer to missing condition definitions | Conditional token rules are skipped | Validate condition names before emitting conditional variables. |
| CSS serialization throws for parser output | Extracted style rules are absent from the result | Use the serializer error path and inspect the reported CSS context. |
Key files
| File | Why to read it |
|---|---|
| packages/…/generator.ts | Shows the public coordination point for CSS layers, split output, and specifications. |
| packages/…/cssgen.ts | Shows how build mode, artifact mode, minimal output, and split output are selected. |
| packages/…/setup-artifacts.ts | Shows how generated runtime APIs, types, recipes, patterns, JSX files, and themes become artifact groups. |
| packages/…/parser-css.ts | Shows how extracted style data becomes serialized CSS. |
| packages/…/token-css.ts | Shows how design tokens and conditional theme values become CSS variables. |
| packages/…/artifact.ts | Defines the shared artifact contract and supported output identifiers. |