@gener8v/tokens

中文文档
0.64.0发布于 2026/11/10MITTypeScriptES Module零依赖近 30 天下载 5172

GENER8V design tokens — one source, generated to CSS, TypeScript, Tailwind and DTCG.

原始使用文档
文档目录5 节
  1. What generates what
  2. What is in here
  3. How the ramps work
  4. The vocabulary
  5. Changing the look

@gener8v/tokens

The source of truth for the GENER8V design system. Everything else in the repository is generated from one file here.

npm i @gener8v/tokens      # public on npm, MIT
import tokens from '@gener8v/tokens';
tokens['--color-action'];      // '#1547B7'
tokens['--control-h-md'];      // '44px'
@import '@gener8v/tokens/styles.css';   /* the whole stylesheet, if not using @gener8v/ui */

What generates what

src/theme.mjs is the only file anyone edits. pnpm build:tokens fans it out:

src/theme.mjs
  ├──▶ design/styles.css                    the only stylesheet — tokens + component layer
  ├──▶ packages/tokens/styles.css           the same sheet, shipped in this package
  ├──▶ dist/tokens.{mjs,d.ts,json}          the same values as JS, for logic and tests
  ├──▶ design/theme.json                    machine-readable record of the parameters
  ├──▶ design/_adherence.oxlintrc.json      lint config a consuming repo can enforce
  ├──▶ packages/tailwind-preset/theme.css   the same values as Tailwind utilities
  ├──▶ figma/plugin/tokens.json             DTCG, for the Figma generator
  ├──▶ design/foundations/*.html            the foundations pages, from the real values
  ├──▶ design/index.html                    the home page
  └──▶ skills/…/references/components.md    the class index the Claude skill reads

Never hand-edit any of those. CI rebuilds and fails if a generated file differs, so a hand-edit cannot reach main. Change src/theme.mjs, or the component CSS in src/components/, and rebuild.

What is in here

FileWhat it holds
src/theme.mjsPalette pins, fonts, density, radius, the space and type scales, control heights
src/color.mjsThe OKLCH engine — ramp generation, gamut mapping, WCAG contrast. No dependencies
src/base.cssReset, base typography, focus ring, layout primitives, atmosphere utilities
src/components/*.cssThe component layer, one file per family. zz-adaptive.css is last on purpose — it holds the forced-colors and print overrides
build.mjsEmits tokens, the stylesheet, theme.json, the adherence config
build-pages.mjsEmits the foundations pages, home page, responsive harness and skill reference

How the ramps work

Every ramp is generated in OKLCH on one shared perceptual lightness scale, so the same step of any ramp carries the same visual weight. Two details are load-bearing:

Neutral chroma rises toward the dark end. --color-neutral-100 is almost white while -900 is distinctly cool. That is what keeps a light interface from reading as undesigned default grey. It is a different curve from the accent ramps, not an oversight.

Actions do not use the accent. --color-action is ramp step 700 (#1547B7). The accent #2563EB stays for focus rings, links and atmosphere. That one indirection is what stops the interface reading as default framework blue, and it puts the primary button at 8.02:1.

The vocabulary

GroupNames
Roles--color-bg --color-surface --color-text --color-accent --color-accent-2 --color-divider
Action--color-action --color-action-hover --color-action-active
Ramps--color-{neutral,accent,accent-2}-{100…900}
Status--color-{success,warning,danger} + -{100,300,700,800} — reserved, never decoration
Chart series--series-1 … --series-8 — fixed order, never cycled
Type--font-{heading,heading-weight,body,mono} --text-* --leading-* --tracking-*
Space--space-{1…32} — the name is the multiple of 4px, so --space-12 is 48px
Controls--control-h-{xs,sm,md,lg,xl} — buttons, inputs and selects share these
Radius--radius-{xs,sm,md,lg,full}
Elevation--shadow-{sm,md,lg}
Motion--ease-out --ease-in-out --dur-{fast,base,slow}

Scales are authored, not computed. There are no fractional pixel values anywhere — an earlier version multiplied a base by a density factor and produced 14.4px, which is how a system starts looking unconsidered.

Changing the look

Edit src/theme.mjs, run pnpm check. Two gates will argue with you if the change is unsafe: lint:contrast fails any text or chrome pair under WCAG 2.2 AA computed from the real ramps, and lint:palette re-runs the data-viz validator over the chart series — including a check that the documented three-series cap for scatter and map forms is still correct.

That is the point of the gates. A colour change that breaks colour-blind separation should fail loudly, not ship.

版本与发布记录

@gener8v/tokens 共发布 80 个版本,首次发布于 2026/08/24;过去 12 个月发布了 80 个版本。

版本发布日期距今
0.64.0latest2026/11/106 天前
0.63.02026/11/0511 天前
0.62.02026/11/0511 天前
0.61.02026/11/0411 天前
0.60.02026/11/0412 天前
0.59.12026/11/0312 天前

关于 @gener8v/tokens 的常见问题

@gener8v/tokens 是什么?

GENER8V design tokens — one source, generated to CSS, TypeScript, Tailwind and DTCG.

如何安装 @gener8v/tokens?

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

@gener8v/tokens 支持 TypeScript 吗?

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

@gener8v/tokens 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@gener8v/tokens 可以商用吗?

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

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

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

@gener8v/tokens 还在维护吗?

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