Token Exports
Three export formats for brand tokens -- JSON, CSS custom properties, and Figma Token Studio v2
Token Exports
Brand Studio exports resolved tokens in three formats via pure functions in token-export.ts. All functions take a TokenWithInheritance[] array and a brand slug string, and return a download-ready string with no side effects.
JSON Tokens
toJSONTokens(resolved, brandSlug) produces a flat JSON object with metadata and a tokens map. Each token entry includes type-specific fields plus a type discriminator.
Output Structure
Token Entry Shapes by Type
| Token Type | Fields |
|---|---|
color | hex, rgb_r, rgb_g, rgb_b, type |
typography | font_family, font_size_pt, font_weight, context, type |
spacing | value_px, context, type |
The resolvedValue is used for every token -- if a brand overrides a token, the override value appears; otherwise the global value appears. There is no indication in the JSON output of whether a token is overridden or inherited.
CSS Custom Properties
toCSSVars(resolved, brandSlug) produces a :root CSS block. Overridden tokens include a trailing /* overridden */ comment.
Output Structure
Variable Naming Rules
The cssVarName() helper from @regen/design-tokens converts token names to CSS custom property names by prepending --. Underscores are preserved, not converted to dashes.
Type-Specific CSS Property Mapping
| Token Type | CSS Properties Generated |
|---|---|
| Color | --{token_name}: {hex}; |
| Typography | --{token_name}-family: "{font_family}"; --{token_name}-size: {font_size_pt}pt; --{token_name}-weight: {font_weight}; |
| Spacing | --{token_name}: {value_px}px; |
Typography tokens expand into up to three CSS properties (family, size, weight). Properties with null or undefined values are omitted.
The /* overridden */ comment appears only on the first property for typography tokens (the -family line).
Figma Token Studio v2
toFigmaTokensV2(resolved, brandSlug) produces output compatible with the Token Studio Figma plugin (v2 format).
Output Structure
Type Mapping
| Brand Studio Type | Figma Token Studio $type | $value Format |
|---|---|---|
color | color | Hex string (#548235) |
typography | fontFamily | Font family name only (Calibri Light) |
spacing | spacing | Numeric string without units (16) |
Typography tokens export only the font family. Token Studio handles font size and weight as separate token types, so font_size_pt and font_weight are not included in this format.
Tokens with null or undefined critical fields (no hex for colors, no font_family for typography) are omitted from the output.
Download Pattern
The export page at /brands/[id]/export uses this browser download pattern for all three formats: