@ch-ui/colors

中文文档
1.2.1发布于 2025/10/30Ch Public LicenseTypeScriptESM + CJS近 30 天下载 6546

Procedural color algorithms based upon drawing helical bézier curves in LAB space.

原始使用文档
文档目录4 节
  1. Getting started
  2. Background
  3. Interpolating through color space
  4. Maintaining continuity while accommodating expressive aesth…

@ch-ui/colors

The colors package exports functions that help generate color systems by drawing an arc as helically transformed bézier curves through OK Lab color space. It uses the colorsjs.io package to convert between color spaces and output tokens for supported gamuts.

Getting started

You might prefer to use this package via @ch-ui/tokens, which surfaces a more use-case oriented API.

pnpm add @ch-ui/colors

Then, use the exported functions as you like. Examples are provided below.

Background

Most projects either inherit colors from a default set like Tailwind’s, or they have designers who manually select colors to use. Those approaches work fine for some, but there are others who both want customized color palettes and don’t have time to manually manage each and every shade in every gamut they want to support.

Interpolating through color space

The main part of the solution this package implements is predicated on a few assumptions:

  • a palette’s “true form” is not bound to a specific gamut, it exists in a perceptual color space; and
  • a palette of colors can be represented as points on a path starting from black, passing through a definitive “key color”, and ending at white in a cylindrical model.

In order to preserve chromaticity (“saturation”/“colorfulness”), so that all the other shades don’t look markedly more muted than the key color, the path between the key color and either of the extremes should curve, therefore the arc is two continuous bézier curves that meet at the key color.

Maintaining continuity while accommodating expressive aesthetics

Procedural color palettes often run into the “mustard problem”: in western cultures, if you reduce only the lightness of the prototypical shade of yellow and use that shade in a UI, users and designers find these shades unappealing. Essentially, there are zones of any gamut which folks prefer to avoid.

So that the arc has no sudden discontinuities and can be reasoned about as a smooth & differentiable shape in 3D space, this package supports applying torsion along the hue axis to the bézier curves. By applying torsion, a yellow color palette’s arc can gently twist toward the red part of the gamut as it gets darker, yielding procedural results that don’t exhibit any mustard shades.

版本与发布记录

@ch-ui/colors 共发布 14 个版本,首次发布于 2024/02/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.1latest2025/10/301 年前
1.2.02025/05/281.5 年前
1.1.02025/05/281.5 年前
1.0.12025/03/081.7 年前
1.0.02025/01/081.8 年前
1.0.0-rc.22025/01/071.8 年前

关于 @ch-ui/colors 的常见问题

@ch-ui/colors 是什么?

Procedural color algorithms based upon drawing helical bézier curves in LAB space.

如何安装 @ch-ui/colors?

在项目目录运行 npm install @ch-ui/colors,或使用 pnpm add / yarn add / bun add。

@ch-ui/colors 支持 TypeScript 吗?

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

@ch-ui/colors 支持 ESM 还是 CommonJS?

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

@ch-ui/colors 需要什么版本的 Node.js?

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

@ch-ui/colors 可以商用吗?

@ch-ui/colors 使用 Ch Public License 许可。声明的许可为 Ch Public License,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@ch-ui/colors 的下载量有多少?

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

@ch-ui/colors 还在维护吗?

最新版本 1.2.1 发布于 2025/10/30(1 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/02/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。