@cssints/color-names

中文文档
0.35.1发布于 2026/11/07MITTypeScriptES Module构建来源已验证近 30 天下载 6950

The Color Name List for cssints: named("tangerine") as a hex colour, in hue sectors so completion stays short

原始使用文档
文档目录7 节
  1. Names
  2. Sectors
  3. CSS keywords
  4. nearest()
  5. Types
  6. The data
  7. Browsers

@cssints/color-names

The Color Name List (names.color.pizza, a colour at /color/<name>/) for cssints: a colour name as a hex colour, as members of cssints/plugin scope(). 31,939 names, no runtime. named(name) takes any name; colorNames.<sector>(name) is the same name in one hue sector, so an editor's completion is a few thousand names and not 31,939. Build time only: the sheet holds the hex, and the data never reaches the client.

import { bg, color, cn } from "cssints" with { type: "cssints" };
import { colorNames, named } from "@cssints/color-names" with { type: "cssints" };

export const tag = cn(color(named("tangerine")), bg(named("midnight-blue")));
export const flag = color(colorNames.red("ferrari-red"));
export const both = color(colorNames.orange("orange-red"));
export const grey = color(colorNames.neutral("abalone"));
export const brown = color(colorNames.brown("chocolate"));
export const css = color("lime"); // the CSS keyword, not the list's Lime
export const bad = color(named("tangerin")); // error: did you mean tangerine?
export const wrong = color(colorNames.red("abalone")); // error: "abalone" is in neutral
@layer _.a {
  ._h4vhuh {
    color: #ff9300;
  }
  ._19lu36g {
    background-color: #020035;
  }
  ._h4q7xz {
    color: #ff2800;
  }
  ._h428z9 {
    color: #fe4401;
  }
  ._g9cy5w {
    color: #f8f3f6;
  }
  ._ethye4 {
    color: #d2691e;
  }
  ._1b7kjqn {
    color: lime;
  }
}

Names

A name is a key of the list: NFC, lowercase, & to and, apostrophes removed, every run of characters that is not a letter or a digit to -, trimmed. So a key is letters (accents kept), digits and hyphens: tangerine, 100-mph, rosé, pi², pepper-and-spice. Name is the union of all 31,939 keys, behind one alias so an error message says Name and not the union. The list's one key collision (World’s Away and Worlds Away both give worlds-away) keeps a hyphen for the apostrophe: world-s-away.

An unknown name is an error in the types, and a build error that names the nearest key within three edits (colornames: no colour name "tangerin", did you mean tangerine?).

Sectors

One member per sector: red, orange, yellow, green, cyan, blue, purple, pink, brown, neutral.

The rule. A colour word in the name decides the sector, whatever the hue of its colour says: ferrari-red is in red though its oklch hue is orange. Words are whole words, split on anything that is not a letter: redwood and bored are not red. The words are red, orange, yellow, green, cyan, blue, purple, pink and brown; gray, grey, white and black are neutral. A name with several colour words is in each of its sectors (154 names): orange-red is in orange and in red.

A name with no colour word is placed by the hue of its colour in oklch: below 0.02 chroma it is neutral, and a hue in the orange-yellow band below 0.7 lightness is brown (brown is a dark orange or yellow). The hue cuts, tuned on version 14.61.0:

SectorHue (oklch)Names
redbelow 30°3,070
orange30° to 70°2,835
yellow70° to 105°4,179
green105° to 165°4,607
cyan165° to 215°1,805
blue215° to 265°3,570
purple265° to 330°2,269
pink330° to 360°1,736
brown40° to 105°, lightness below 0.73,194
neutralchroma below 0.024,828

The 31,939 names give 32,093 sector places: 7,703 names have a colour word (154 of them several), 24,236 are placed by hue, and the word and the hue disagree for 2,850. A name of another sector is an error in the types, and a build error that names the sectors it is in (colornames: "abalone" is in neutral).

The cuts are not the first ones: with the list's own rough cuts (red below 20°, orange to 55°, yellow to 110°, chroma below 0.03, no brown) yellow held 6,657 names and neutral 7,677, both too big to scan in an editor. brown is the sector that fixes yellow (the browns were most of it); without it the biggest sector stays above 6,000 names, and a colour with a hue cannot be called neutral. neutral stays the biggest member by its chroma cut alone, which is where the near-grays of the list are.

CSS keywords

Of the 148 CSS named colours, 63 have a list name whose spelling matches, ignoring case and punctuation, with the same hex (red #ff0000, orange #ffa500); 63 have such a list name with a different hex; and 22 have none (gray, slategray, deeppink, dimgray, lightgray, slateblue, ...). named() resolves list names, so named("green") is the list's Green #00ff00, not CSS #008000, and named("lime") is #aaff32, not #00ff00. A CSS keyword stays reachable as a string: color("green") prints color: green.

nearest()

@cssints/color-names/nearest is the reverse lookup: the name nearest to a colour, by CIEDE2000 on Lab, as the list's own API (api.color.pizza/v1) matches. Build time only: it imports the whole list and culori's colour maths, so a module that reaches the browser must not import it (a plain export from the package root would put the data in the bundle). The engine has no marker for such a module; the subpath and the README line are the marker, as for @cssints/tokens' sets and the lacking/inGroup helpers of cssints/plugin.

import { nearest } from "@cssints/color-names/nearest";

nearest("#3b82f6"); // { name: "dodger-blue", hex: "#3e82fc", distance: 0.93 }
nearest("not a colour"); // undefined

Types

Measured on 2026-10-17 (tsc 5.9.3 and tsgo 7.0.0-dev, one file per row; the union behind the Name alias, and the member through cssints/plugin):

CaseKeysTypesInstantiationsCheck (tsc)Completion (warm)
plain union, named(name: Name)31,93963,97100.10 s—
plain union, the biggest sector4,8289,74900.05 s—
scope() member, arg<Name>()31,93990,75937,2140.65 s31,939 in 10 ms
scope() member, the biggest sector4,82836,57237,2140.59 s4,828 in 1 ms

The union costs types, not instantiations: the two scope rows share 37,214 instantiations (the engine's own types), and their check time is the same within noise. What the sectors buy is the completion list, which is 6.6 times shorter and about ten times faster. A whole token set of these names was not taken: 31,935 DTCG leaves cost 15 to 26 s to check.

The data

src/<sector>.ts is generated by scripts/generate.ts from the color-name-list package 14.61.0 (a dependency; the list itself is not copied into the repository, the projection is). Each file is one as const record of key to hex plus the key union written out, so the declarations a build emits hold the union (548 kB) and not the record (2.2 MB). The committed data is 1.5 MB; the built data chunk is 865 kB. Run bun run generate after a bump; the package's test fails when the committed files differ from a fresh run.

The list is MIT, copyright David Aerne (2017), and its README asks for simple attribution. The list mixes sources (Wikipedia, paint makers, fiction) and carries brand-like names (Tiffany Blue, Ferrari Red); it says it removes offensive and protected names and that some may remain.

Browsers

A hex colour needs nothing: no runtime, no @supports, no support warning. The package's output is one declaration per call.

cd packages/color-names && bun run test        # the generated data, the engine (hex, errors), nearest()
cd packages/color-names && bun run typecheck   # and the type test, test/types/color-names.ts
cd packages/color-names && bun run generate    # src/<sector>.ts from the dependency

版本与发布记录

@cssints/color-names 共发布 39 个版本,首次发布于 2026/10/21;过去 12 个月发布了 39 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.35.1latest2026/11/073 天前
0.35.02026/11/073 天前
0.34.02026/11/073 天前
0.33.02026/11/046 天前
0.32.02026/11/046 天前
0.31.02026/11/047 天前

关于 @cssints/color-names 的常见问题

@cssints/color-names 是什么?

The Color Name List for cssints: named("tangerine") as a hex colour, in hue sectors so completion stays short

如何安装 @cssints/color-names?

在项目目录运行 npm install @cssints/color-names,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:cssints(^0.35.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cssints/color-names 支持 TypeScript 吗?

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

@cssints/color-names 支持 ESM 还是 CommonJS?

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

@cssints/color-names 需要什么版本的 Node.js?

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

@cssints/color-names 可以商用吗?

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

@cssints/color-names 的下载量有多少?

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

@cssints/color-names 还在维护吗?

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