@code-sherpas/pharos-tokens

中文文档
1.1.1发布于 2026/11/09MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2170

Design tokens de Code Sherpas — agnóstico de framework. DTCG + Style Dictionary + OKLCH.

原始使用文档
文档目录11 节
  1. What's in this package
  2. Installation
  3. Usage
  4. Option A — CSS custom properties (recommended)
  5. Option B — Typed object (JS/TS)
  6. Option C — Flat constants (selective imports)
  7. Option D — DTCG source (custom pipelines)
  8. Rules for consumers
  9. Token structure
  10. Contributing
  11. License

@code-sherpas/pharos-tokens

Design tokens for Code Sherpas. Framework-agnostic. DTCG + Style Dictionary v4 + OKLCH.

Part of Pharos, Code Sherpas' design system: its visual direction and the values of every token are decided in the Pharos design system artifact, published here as tokens and as components in pharos-react, and the program's documentation (decisions, roadmap, quality standard) lives in Notion → Programa Pharos.

What's in this package

This package defines the atomic values of Code Sherpas's visual system: colors, spacing, radius, typography, shadows, z-index, duration, easing, and layout widths and breakpoints. They are consumable from any frontend (React, Vue, Svelte, React Native) and from backends (transactional emails, PDFs, reports).

It contains no components. React components live in @code-sherpas/pharos-react and consume this package as a peer dependency.

Installation

pnpm add @code-sherpas/pharos-tokens
# or npm / yarn

Usage

Import the CSS tokens at your app's entry point:

@import '@code-sherpas/pharos-tokens/styles.css';

or, from a JS/TS entry point:

import '@code-sherpas/pharos-tokens/styles.css';

Both entry points ship type declarations, so the side-effect import type-checks with noUncheckedSideEffectImports (on by default since TypeScript 6) without any declare module. @code-sherpas/pharos-tokens/css is the same stylesheet under its original name and keeps working.

This exposes --pharos-* on :root. Use them directly or via Tailwind arbitrary values:

.button-primary {
  background: var(--pharos-color-primary-600);
  color: white;
}
<div class="bg-[var(--pharos-color-neutral-900)] text-white p-[var(--pharos-spacing-4)]">…</div>

Option B — Typed object (JS/TS)

import { tokens } from '@code-sherpas/pharos-tokens';

const darkSurface = tokens.color.neutral['900'];
const cardRadius = tokens.radius['2xl'];

Every token path is typed, so a renamed or removed token fails your compilation. The declarations need neither resolveJsonModule nor skipLibCheck, and compile with moduleResolution bundler, node16 and nodenext.

Option C — Flat constants (selective imports)

import { PharosColorPrimary600, PharosRadius2xl } from '@code-sherpas/pharos-tokens/tokens.js';

Option D — DTCG source (custom pipelines)

For your own transforms (iOS, Android, Figma, etc.):

import colorDtcg from '@code-sherpas/pharos-tokens/dtcg/color';
// DTCG object with $value, $type, $description

Rules for consumers

See the rules for consumers in Notion (Programa Pharos), where Pharos keeps its documentation (decision D27).

Token structure

FamilyExample pathDescription
Basecolor.base.{white,black}Pure white and black.
Neutralscolor.neutral.{50..950}Grayscale, slightly navy-tinted in the darker steps.
Primarycolor.primary.{50..900}Sea blue, scale 50-900. 600 is the base hue.
Semanticcolor.semantic.{success,error,warning,info}.{fg,bg,on}Success/error/warning/info. fg + on pairs pass WCAG AA.
Spacingspacing.{0..24}Tailwind-compatible scale in rem.
Radiusradius.{none,sm,md,lg,xl,2xl,3xl,full}Corner rounding.
Typographyfont.{family,weight,size,lineHeight,letterSpacing}.*Typography. Body default = size.sm (14px).
Shadowshadow.{sm,md,lg,xl}Elevation.
Z-indexz.{0,header,above-header,modal-overlay,modal,drawer-overlay,drawer,dropdown,tooltip}Semantic, not literal.
Durationduration.{fast,normal,slow}Transitions.
Easingeasing.{in,out,in-out}Cubic-bezier curves.
Widthwidth.panelWidths by role. panel: Sheet and SidePanel (24rem).
Breakpointbreakpoint.panelViewport breakpoints by role (D32); read them in JS.

Contributing

  1. pnpm install
  2. Modify or add tokens in src/*.tokens.json (DTCG format).
  3. pnpm build — verify that Style Dictionary compiles.
  4. pnpm test — WCAG + DTCG validations must pass.
  5. pnpm changeset — declare the type of change (patch / minor / major).
  6. Open a PR.

CI validates WCAG 2.1 AA contrast on every color/on-color pair. A PR cannot be merged if it breaks contrast.

License

MIT. See LICENSE.

版本与发布记录

@code-sherpas/pharos-tokens 共发布 15 个版本,首次发布于 2026/04/20;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.1latest2026/11/091 天前
1.1.02026/11/082 天前
1.0.12026/11/063 天前
1.0.02026/10/3011 天前
0.8.12026/10/2812 天前
0.8.02026/10/1625 天前

关于 @code-sherpas/pharos-tokens 的常见问题

@code-sherpas/pharos-tokens 是什么?

Design tokens de Code Sherpas — agnóstico de framework. DTCG + Style Dictionary + OKLCH.

如何安装 @code-sherpas/pharos-tokens?

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

@code-sherpas/pharos-tokens 支持 TypeScript 吗?

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

@code-sherpas/pharos-tokens 支持 ESM 还是 CommonJS?

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

@code-sherpas/pharos-tokens 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@code-sherpas/pharos-tokens 可以商用吗?

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

@code-sherpas/pharos-tokens 的下载量有多少?

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

@code-sherpas/pharos-tokens 还在维护吗?

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