@hanzo/tokens

中文文档
1.1.3发布于 2026/11/13MITTypeScriptESM + CJS零依赖近 30 天下载 1.3万

Design tokens for Hanzo UI: colors, spacing, radii, typography, themes

原始使用文档

@hanzo/tokens

The single source of truth for the Hanzo design tokens — colours, radius, type, spacing — for every surface. React reads the TypeScript; non-React surfaces (a Gitea fork, a Go dashboard, an Argo CD fork) embed the generated CSS. One edit propagates everywhere.

Hanzo's chrome is monochrome: one hue through an opacity ladder, dark by default. The only hues in chrome are the states (--state-error, --state-warning, --state-online, --state-success). Type is Zen + Zen Mono, from @hanzo/font.

Data is the one exception, and it is scoped: src/data.ts is a palette of twenty-six 12-step hues (--data-<hue>-<step>) for what a PERSON colours — a select option's tag, a kanban column, an object's icon tile, an avatar's initial, a chart series. Never a button, a border or a focus ring. Twenty of the twenty-one pickable hues and all five neutrals are Radix Colors scales (NOTICE); hueOf(seed) picks a record's hue from a stable string hash, so a record keeps its colour wherever it is drawn or imported.

The pipeline

src/theme.ts   ──gen-css──▶  dist/colors.css   ──▶  @hanzo/design/tokens/colors.css ──▶ styles.css
 (the source)                dist/tokens.css    ──▶  @hanzo/brand/styles/variables.css ──▶ git/ci/cd
  • src/theme.ts holds every colour token (dark → :root, light → .light) plus the radius/type/spacing scale. Values are raw CSS strings, so a var() reference stays a reference and the emitted bundle is what consumers already ship. This is the ONE place to edit a value.
  • scripts/gen-css.mjs reads the built dist/theme.mjs and emits:
    • dist/colors.css — the colour tokens only (@hanzo/tokens/css/colors); the contract @hanzo/design republishes.
    • dist/tokens.css — colours + radius + type + spacing + the data palette (@hanzo/tokens/css); what @hanzo/brand re-emits for Go surfaces.
    • dist/data.css — the data palette alone (@hanzo/tokens/css/data). Not in colors.css, which design republishes as the chrome contract.
  • @hanzo/ui composes data.css into its theme.css, and also every token this package declares that @hanzo/design's sheet does not ship yet — so a token added here reaches the components before design's next build copies it.
  • themes.ts / colors.ts are the resolved, flat views for JavaScript consumers that cannot dereference var(). They mirror theme.ts.

Regenerate

pnpm --filter @hanzo/tokens gen-css

Flow: edit src/theme.ts → gen-css → @hanzo/design and @hanzo/brand pull the generated CSS on their next gen/build → git / ci / cd pick it up. gen-css runs as part of build (and prepublish), so a published package always ships current CSS.

版本与发布记录

@hanzo/tokens 共发布 9 个版本,首次发布于 2026/03/23;过去 12 个月发布了 9 个版本。

版本发布日期距今
1.1.3latest2026/11/134 天前
1.1.22026/11/134 天前
1.1.12026/10/2127 天前
1.1.02026/10/1928 天前
1.0.42026/10/021 个月前
1.0.32026/10/021 个月前

关于 @hanzo/tokens 的常见问题

@hanzo/tokens 是什么?

Design tokens for Hanzo UI: colors, spacing, radii, typography, themes

如何安装 @hanzo/tokens?

在项目目录运行 npm install @hanzo/tokens,或使用 pnpm add / yarn add / bun add。

@hanzo/tokens 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@hanzo/tokens 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@hanzo/tokens 可以商用吗?

@hanzo/tokens 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@hanzo/tokens 的下载量有多少?

根据 npm 官方下载统计,@hanzo/tokens 在 2026/10/17 – 2026/11/15 这 30 天内被下载 13,212 次,日均约 440 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@hanzo/tokens 还在维护吗?

最新版本 1.1.3 发布于 2026/11/13(4 天前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/03/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。