ShtukbaseStandard
包页面→ /design/tokens.md

pages/design/tokens.md

53 行, 3.3 KB. 以页面形式查看.

这段内容尚未翻译,下面是英文原文。

  1. ---
  2. type: Page
  3. title: "Design tokens"
  4. description: "The project's design tokens in the W3C Design Tokens (DTCG) format: where they live, how to build CSS variables, norms."
  5. icon: "🎨"
  6. source: design/tokens.json
  7. dark: design/tokens.dark.json
  8. out: design/tokens.css
  9. prefix: ""
  10. darkSelector: .dark
  11. ---
  12. # Design tokens
  13. 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](https://www.designtokens.org/tr/2025.10/format/) (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.
  14. ## What is where
  15. - [tokens.json](tokens.json): the tokens. An example: colors, spacing, radii, font, motion, shadow, border, text style.
  16. - [tokens.dark.json](tokens.dark.json): the dark scheme: the same tokens with other values. Optional.
  17. - [tokens.css](tokens.css): CSS variables built from the tokens. Not edited by hand.
  18. ## How the file is arranged (briefly)
  19. - A group is an object without `$value`; a token is an object with `$value`.
  20. - `$type` is 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.
  21. - 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).
  22. - A color is an object `{colorSpace, components, alpha, hex}` or a hex string; a size is `{value, unit: px|rem}`.
  23. - A name cannot contain `{`, `}` or a dot; a name does not start with `$`.
  24. ## Build into CSS
  25. `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.
  26. ## Settings
  27. - `source` is the tokens file; `dark` is the dark scheme file (empty means none).
  28. - `out` is where to build the CSS; `prefix` is a prefix for variable names (`ds-` → `--ds-color-primary`).
  29. - `darkSelector` is the selector of the dark scheme.
  30. ## Styles and the contract
  31. 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](contract.md); the project's choice is on [Design](design.md). The check `contract` judges the chosen style, or any CSS file: `shtuk run design-tokens contract --css <file>`.
  32. ## Norms
  33. | Norm | What | Check |
  34. |---|---|---|
  35. | [DTK-R01](/norms/rules/design-tokens/DTK-R01.md) | Tokens are valid by the DTCG format, references lead to tokens of the right type | `valid` |
  36. | [DTK-R02](/norms/rules/design-tokens/DTK-R02.md) | CSS from tokens is rebuilt | `fresh` |
  37. | [DTK-R03](/norms/rules/design-tokens/DTK-R03.md) | The chosen style meets [the token contract](/design/contract.md) | `contract` |
  38. 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}`.