color-map

中文文档
2.3.1发布于 2026/11/03MITTypeScriptESM + CJS零依赖构建来源已验证

Color map generator and color toolkit: a library, a CLI and an agent skill

原始使用文档
文档目录10 节
  1. Library
  2. Legacy API
  3. createColors(from, to, shades, alpha?)
  4. rgbHex(rgb)
  5. rgbaString(rgba)
  6. createColorsFromMap(colormap, shades, alpha?)
  7. The color-map command
  8. For agents
  9. Acknowledgements
  10. Contribute

color-map

NPM version NPM downloads

Github NodeJS Codecov

Semantic Release

Visual Studio Code

Color map generator with no dependency.

Inspired from colormap.

Library

import { parse, toCss, convert, semanticPalette, toTailwindTheme } from 'color-map'

toCss(convert(parse('#3b82f6'), 'oklch')) // oklch(0.62308 0.18801 259.81453)
toTailwindTheme(semanticPalette({ brand: '#3b82f6', mode: 'light' })) // an @theme { ... } block

color-map re-exports the subpaths color-map/color, color-map/scale, color-map/palette and color-map/tokens. With a bundler, the root costs the same bytes as a subpath. Code that runs without a bundler can import a subpath to load less. See the library docs for the full API.

Legacy API

The original API lives in color-map/legacy. The root color-map still exports it in 2.x, marked deprecated, and stops in 3.0.

createColors(from, to, shades, alpha?)

import { createColors } from 'color-map/legacy'

// creates array of [r,g,b,a]
const rgbaRange = createColors([0, 0, 255], [0, 255, 128], 72, [0, 1])

// creates array of [r,g,b,1]
const rgbRange = createColors([0, 0, 255], [0, 255, 128], 72)

rgbHex(rgb)

import { rgbHex } from 'color-map/legacy'

rgbHex([0, 128, 255]) // '#0080ff'
rgbHex([0, 128, 255, 0.3]) // '#0080ff'

rgbaString(rgba)

import { rgbaString } from 'color-map/legacy'

rgbaString([0, 128, 255, 0.2]) // 'rgba(0,128,255,0.2)`

createColorsFromMap(colormap, shades, alpha?)

import { createColorsFromMap, ColorMap } from 'color-map/legacy'

const summer: ColorMap = [{ index: 0, rgb: [0,128,102] }, { index: 1, rgb: [255,255,102] }]

const colors = createColorsFromMap(summer, 60)

createColorsFromMap is deprecated. Use createGradient instead:

import { createGradient } from 'color-map'

const colors = createGradient(['rgb(0 128 102)', 'rgb(255 255 102)'], 60, { in: 'srgb' })

It returns color objects with channels from 0 to 1, not whole numbers. See Gradients for the full recipe.

The color-map command

The package ships a command for agents, with no extra install and no runtime dependency:

npx color-map palette '#3b82f6'

Output is TOON by default, with --format json for JSON. It follows the AXI principles: essential fields by default and --full for the rest, precomputed contrast ratios, explicit empty results, coded errors with exit codes (1 failed, 2 wrong call), no prompts, and a suggested next command after each result.

CommandWhat it does
convert <color> --to <space>convert to any CSS color space, optionally gamut-mapped
mix <a> <b>mix as color-mix() does
contrast <fg> <bg>WCAG 2 ratio with AA and AAA verdicts
find-contrast <bg> --target 4.5find a color that reaches a ratio
scale <seed>a Tailwind, Radix, tone or even scale, a brand scale, or a contrast scale
palette <brand>a semantic palette; every text pair carries its ratio
harmony <color>complementary, split, analogous, triadic or tetradic colors
export [color]CSS variables, DTCG JSON or a Tailwind v4 theme
schema [command]the JSON Schema of a command's options

Contrast is WCAG 2.

For agents

  • JSON Schemas for every command's arguments and options ship in schemas/ (for example color-map/schemas/scale.schema.json) and print with color-map schema <command>.
  • The color-map agent skill ships in this package as a plugin for Claude Code, Cursor, Codex and Copilot CLI (plugin.json, skills/color-map).
  • llms.txt maps the commands.

The command is a separate bundle (bin/color-map.js) that inlines its parser. No library entry point loads it, so importing color-map costs nothing for it.

Acknowledgements

color-map follows CSS Color 4 and 5 (W3C), uses Björn Ottosson's OKLab, and writes Design Tokens color values. Its scales and palettes learn from Radix Colors, Material Design 3 and Tailwind CSS. It started from colormap. The Compare page measures it against culori, Color.js, chroma-js, @texel/color, @colordx/core, lightningcss and colord. No third-party source code is bundled. The Credits page says what each one contributed and under which license.

Contribute

# after fork and clone
npm install

# begin making changes
git checkout -b <branch>
npm run watch

# after making change(s)
git commit -m "<commit message>"
git push

# create PR

npm run size checks the gzip size of each entry point against its budget. npm run build && npm run bench times the same operations in color-map, culori and colorjs.io and prints ops/sec for each; --filter <name> runs only the matching operations.

版本与发布记录

color-map 共发布 38 个版本,首次发布于 2017/01/09;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.3.1latest2026/11/03今天
2.3.02026/11/03今天
2.2.02026/08/092 个月前
2.1.02026/08/092 个月前
2.0.82026/08/092 个月前
2.0.72026/08/092 个月前

关于 color-map 的常见问题

color-map 是什么?

颜色地图生成器和颜色工具包:一个库,一个CLI和一个代理技能

如何安装 color-map?

在项目目录运行 npm install color-map,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 color-map,可以用 npx color-map 直接运行。

color-map 支持 TypeScript 吗?

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

color-map 支持 ESM 还是 CommonJS?

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

color-map 需要什么版本的 Node.js?

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

color-map 可以商用吗?

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

color-map 还在维护吗?

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