Design tokens (W3C DTCG)
Design tokens in the W3C Design Tokens Community Group format: validation, a build into CSS variables (light and dark schemes), and the token contract v1 (shadcn theme names + Tailwind v4 namespaces) with a check that a style meets it.
О пакете
Этот текст ещё не переведён. Ниже английский оригинал.
Tokens are one source of design values for tools and code. The file is in the W3C Design Tokens Community Group format (version 2025.10); the build action builds CSS variables from it.
What it installs
- The page Design tokens: how the file is arranged, the build, settings (
source,dark,out,prefix,darkSelector). - The token contract v1: the page The token contract and its data contract.json: the names a style must define (the shadcn theme variables, the Tailwind v4 namespaces), the colours that need a dark value, the optional
--sb-extension with defaults. - The convention A design style (page type
Convention, see Conventions): what a style gives, expects and may choose freely, the recipe for making an alternative, and its health. The skeleton style for the recipe is the folderskeleton/style/of the package (installed with it in.shtukbase/packages/design-tokens/skeleton/style/). - The page Design: the project's choice in its header,
style:andlibraries:. Style packages setstyleon install when it is empty. - An example
design/tokens.json(colors, spacing, radii, font, motion, shadow, border, text style) anddesign/tokens.dark.json(the dark scheme). - The
buildaction (runs by itself after install and update): tokens →design/tokens.css, references →var(--…), the dark scheme →.dark { … }.build --style <id>builds a style package's tokens (/design/<id>/tokens.json,tokens.dark.json→tokens.css, dark on.dark, [data-theme="dark"]);buildStyle(id)inactions/build.tsdoes the same for the style packages. - A small reader for other packages:
lib/contract.ts(readContract,styleChoice,styleCssPath,checkCss,fallbacks,defaultsCss). - Norms:
- DTK-R01: tokens are valid by the format, references lead to tokens of the right type, no cycles; the
validcheck. - DTK-R02: the CSS is built from the current tokens; the
freshcheck. - DTK-R04: the health of a style in bands (full, missing, fallbacks, extra), mode
warn: thehealthcheck informs and never fails. - DTK-R03: the built tokens of the chosen style define every name of the contract, and every colour also in the dark scheme; the
contractcheck. It names the optional names a style leaves out (the defaults apply).
- DTK-R01: tokens are valid by the format, references lead to tokens of the right type, no cycles; the
Where the boundary is
- The resolver for token sets and the "modes" from DTCG drafts are not supported: the dark scheme is a separate file. References are only
{a.b}, without$ref. - Export is only to CSS variables; not to JS, Swift or Android.
- Scales and the contrast of values belong to the
design-scalesanddesign-a11ypackages: they read the built CSS like any other.
Нормы 4
| ID | Норма | Уровень | Режим | Enforcer |
|---|---|---|---|---|
| DTK-R01 | Файл токенов — дерево групп и токенов по формату W3C DTCG: у токена есть $value и известный $type, значение подходит типу, каждая ссылка {a.b} ведёт к токену нужного типа, ссылок по кругу нет. |
MUST | не пускает | проверка |
| DTK-R02 | Файл CSS-переменных (out) совпадает с тем, что собирает build из текущих токенов. |
MUST | не пускает | проверка |
| DTK-R03 | The built tokens of the chosen style (/design/<style>/tokens.css) define every required name of the token contract v1 in :root, and every colour name also in the dark scheme. |
MUST | не пускает | проверка |
| DTK-R04 | The health of a style is reported in bands (full, missing, fallbacks, extra); a style that is not full is told, never stopped. |
SHOULD | предупреждает | проверка |
«Не пускает» — enforcer останавливает нарушение; «наблюдает» — только отмечает его. Уровень MUST — обязательно, SHOULD — по умолчанию да.
Действия 5
| Имя | Что делает | Файл | Когда |
|---|---|---|---|
| build | Build CSS variables from tokens (out on /design/tokens.md) | actions/build.ts | после установки после обновления |
| valid | Tokens are valid by the DTCG format норма DTK-R01 | checks/valid.ts | проверка |
| fresh | CSS from tokens is rebuilt норма DTK-R02 | checks/fresh.ts | проверка |
| contract | The chosen style meets the token contract (--css <file> judges any CSS file) норма DTK-R03 | checks/contract.ts | проверка |
| health | Health of a style in bands (full, missing, fallbacks, extra); warns, never fails (--style, --all, --css) норма DTK-R04 | checks/health.ts | проверка |
Проверки запускает shtuk check, любое действие — shtuk run design-tokens <имя>. Действия «после установки» запускаются сами, только если пакет из доверенного источника.
Страницы 11
Ложатся в проект по этим путям.
- /design/
- contract.json файл
- The token contract страница
- Design страница
- tokens.dark.json файл
- tokens.json файл
- Design tokens страница
- /design/conventions/
- A design style Convention
- /norms/rules/design-tokens/
- Токены валидны по формату DTCG DTK-R01
- CSS из токенов собран заново DTK-R02
- The style meets the token contract DTK-R03
- A style reports its health against the token contract DTK-R04
Файлы пакета 19
Ложатся в .shtukbase/packages/design-tokens/; отсюда запускаются действия.