@bysages/tokens

中文文档
0.6.0发布于 2026/11/07MITTypeScriptES Module零依赖近 30 天下载 1926

Design tokens for By Sages Elements — DTCG source compiled to CSS variables and JavaScript: surface ramps, elevation from light, density tiers, themes

原始使用文档
文档目录5 节
  1. Features
  2. Installation
  3. Quick Start
  4. Rebuilding
  5. License

@bysages/tokens

npm version npm downloads npm license

The design tokens of By Sages Elements — DTCG sources compiled with Style Dictionary into CSS custom properties and TypeScript types. The only allowed source of visual values in the system.

Features

  • 🎨 Two tiers — primitives (the raw palettes, type ramps, spacing) and semantic tokens (surface ladder, ink, borders, elevation, motion) that components actually consume
  • 🌗 Theme dimensions as data — light/dark modes, mineral-pigment accents (qinghua / celadon / zhusha), fixed semantic colors (bamboo / ochre / cinnabar / ultramarine), four density tiers, contrast tiers, and scene presets
  • 💡 Lighting-aware elevation — shadows computed from --bs-light-x / --bs-light-reach parts, never copy-pasted, so the light source is a variable too
  • 📦 Three outputs — the compiled stylesheet (@bysages/tokens/css), the token tree as data (.), and the semantic layer as JS (./styles)
  • 🔤 Typography with a voice — song-serif headings, hei-sans UI chrome, CJK label tracking — dual-track stacks for the Chinese × Western register

Installation

# pnpm
pnpm add @bysages/tokens

# npm
npm install @bysages/tokens

# yarn
yarn add @bysages/tokens

# bun
bun add @bysages/tokens

Quick Start

Import the compiled stylesheet once at the app root — every token lands as a CSS custom property on :root:

import "@bysages/tokens/css";

Then consume tokens anywhere — this is the contract every component style follows:

.card {
  background: var(--bs-color-surface-2);
  border: 1px solid var(--bs-color-border);
  border-radius: var(--bs-radius-lg);
  box-shadow: var(--bs-elevation-1);
  padding: var(--bs-space-4);
}

Rebuilding

The tokens compile at build time (node scripts/build.mjs); pnpm dev in the package root watches and recompiles. Consumers in the monorepo read the compiled dist, so rebuild here before their changes pick up new tokens.

License

版本与发布记录

@bysages/tokens 共发布 17 个版本,首次发布于 2026/09/16;过去 12 个月发布了 17 个版本。

版本发布日期距今
0.6.0latest2026/11/072 天前
0.5.02026/11/036 天前
0.4.42026/10/1921 天前
0.4.32026/10/1525 天前
0.4.22026/10/1327 天前
0.4.12026/10/1129 天前

关于 @bysages/tokens 的常见问题

@bysages/tokens 是什么?

Design tokens for By Sages Elements — DTCG source compiled to CSS variables and JavaScript: surface ramps, elevation from light, density tiers, themes

如何安装 @bysages/tokens?

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

@bysages/tokens 支持 TypeScript 吗?

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

@bysages/tokens 支持 ESM 还是 CommonJS?

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

@bysages/tokens 可以商用吗?

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

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

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

@bysages/tokens 还在维护吗?

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