Skip to content
Unverified: This page has not yet been anchored to automated code tests.

Design token system

Vox compiles vox.tokens.json into typed CSS custom properties and validates every token reference at compile time. Unknown token names are compile errors; raw color literals on color-accepting properties are warnings.

Token files must conform to contracts/tokens/tokens.v1.json. The minimal structure:

{
"$schema": "./contracts/tokens/tokens.v1.json",
"color": {
"primary": "#3a86ff",
"background": "#ffffff",
"text": {
"value": "#1d3557",
"on": "color.background",
"text_role": "body"
}
},
"spacing": { "md": "16px" },
"font": { "base": "16px" }
}

Token paths become CSS custom properties by joining segments with - and prefixing --vox-:

JSON pathCSS custom property
color.primary--vox-color-primary
color.text--vox-color-text
spacing.md--vox-spacing-md

In Vox source use tokens.<path> syntax:

// vox:skip -- illustrative future syntax; style {} only supports .selector { prop: "literal" } today, no token references
component Button {
style {
color: tokens.color.text
background: tokens.color.primary
}
}

Color tokens with on and text_role metadata are validated against WCAG 2.1 §1.4.3 at token-load time:

text_roleWarn belowError below
body4.5:13:1
large3:13:1
ui3:13:1

Validation runs via TokenRegistry::validate_contrast() in crates/vox-compiler/src/tokens/mod.rs. The contrast algorithm is WCAG 2.1 relative luminance (IEC 61966-2-1 sRGB linearization) implemented in crates/vox-compiler/src/tokens/contrast.rs.

CodeSeverityMeaning
web_ir_validate.style.unknown_tokenerrorTokenRef not present in vox.tokens.json
web_ir_validate.style.raw_color_valuewarningRaw hex/rgb/named color on a color property
web_ir_validate.style.token_contrast_warningwarningDeclared contrast pair below warn threshold
web_ir_validate.style.token_contrast_errorerrorDeclared contrast pair below error threshold

The normative machine-readable contract is contracts/tokens/tokens.v1.json (JSON Schema Draft 2020-12).