这段内容尚未翻译,下面是英文原文。
Design tokens
The project's design tokens in the W3C Design Tokens (DTCG) format: where they live, how to build CSS variables, norms.
A token is a named design value: a color, a size, a font, a shadow. Tokens live in one JSON file in the W3C Design Tokens Community Group (DTCG) format. Figma (through plugins), Style Dictionary, Tokens Studio and other tools read this format, so the file is a common language of design and code.
What is where
- tokens.json: the tokens. An example: colors, spacing, radii, font, motion, shadow, border, text style.
- tokens.dark.json: the dark scheme: the same tokens with other values. Optional.
- tokens.css: CSS variables built from the tokens. Not edited by hand.
How the file is arranged (briefly)
- A group is an object without
$value; a token is an object with$value. $typeis the type of the value:color,dimension,fontFamily,fontWeight,duration,cubicBezier,number,strokeStyle,border,transition,shadow,gradient,typography. A type can be set on a group; all tokens inside inherit it.- A reference is
"{color.neutral.900}": the value is taken from another token. A reference can also stand inside a composite value ("color": "{color.muted}"in a border). - A color is an object
{colorSpace, components, alpha, hex}or a hex string; a size is{value, unit: px|rem}. - A name cannot contain
{,}or a dot; a name does not start with$.
Build into CSS
shtuk run design-tokens build writes out (by default design/tokens.css): each token becomes a variable --<path-joined-by-hyphens> in :root; a reference becomes var(--…); a text style is split into --text-body-font-size and its neighbors; the dark scheme is a .dark block (the darkSelector field). The build runs by itself after the package is installed and updated.
Settings
sourceis the tokens file;darkis the dark scheme file (empty means none).outis where to build the CSS;prefixis a prefix for variable names (ds-→--ds-color-primary).darkSelectoris the selector of the dark scheme.
Styles and the contract
A style package keeps its own tokens in /design/<style>/ and builds them with shtuk run design-tokens build --style <style>. What names a style defines is fixed by the token contract; the project's choice is on Design. The check contract judges the chosen style, or any CSS file: shtuk run design-tokens contract --css <file>.
Norms
| Norm | What | Check |
|---|---|---|
| DTK-R01 | Tokens are valid by the DTCG format, references lead to tokens of the right type | valid |
| DTK-R02 | CSS from tokens is rebuilt | fresh |
| DTK-R03 | The chosen style meets the token contract | contract |
Boundary: "modes" and the resolver for token sets (a DTCG draft) are not read by the package; the dark scheme is a separate file. References in the form $ref (JSON Pointer) are not supported, only {a.b}.
/design/tokens.md。源文本