ShtukbaseStandard

Design tokens (W3C DTCG)

design-tokens · 版本 0.2.2
设计4 条规范4 项检查

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 folder skeleton/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: and libraries:. Style packages set style on install when it is empty.
  • An example design/tokens.json (colors, spacing, radii, font, motion, shadow, border, text style) and design/tokens.dark.json (the dark scheme).
  • The build action (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) in actions/build.ts does 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 valid check.
    • DTK-R02: the CSS is built from the current tokens; the fresh check.
    • DTK-R04: the health of a style in bands (full, missing, fallbacks, extra), mode warn: the health check 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 contract check. It names the optional names a style leaves out (the defaults apply).

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-scales and design-a11y packages: they read the built CSS like any other.

规范 4

ID规范级别模式Enforcer
DTK-R01
令牌文件是按 W3C DTCG 格式组织的组与令牌树:令牌具有 $value 和已知的 $type,取值符合类型,每个引用 {a.b} 都指向正确类型的令牌,且不存在循环引用。
MUST 拦截
检查
DTK-R02
CSS 变量文件(out)与当前令牌经构建后产生的结果一致。
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

名称作用文件时机
buildBuild CSS variables from tokens (out on /design/tokens.md)actions/build.ts
安装后 更新后
validTokens are valid by the DTCG format
规范 DTK-R01
checks/valid.ts
检查
freshCSS from tokens is rebuilt
规范 DTK-R02
checks/fresh.ts
检查
contractThe chosen style meets the token contract (--css <file> judges any CSS file)
规范 DTK-R03
checks/contract.ts
检查
healthHealth 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

这些页面会放到项目中的以下路径。

包文件 19

它们会放到 .shtukbase/packages/design-tokens/,动作从那里运行。