chromajs

Work with colors using chroma.js: convert between color spaces (RGB, HSL, LAB, LCH), generate palettes and scales, blend and mix colors, check contrast, and build accessible color systems. Suitable for creating palettes, theme design, accessibility checks, or data-visualization color scales.

Last repository push
GitHub Stars
219
Forks
38
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "chromajs" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-071a35403ba65bff1d1fa21d7623dcf506ee8b11891c2dad60be45eb0e5e493e. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Work with colors using chroma.js: convert between color spaces (RGB, HSL, LAB, LCH), generate palettes and scales, blend and mix colors, check contrast, and build accessible color systems. Suitable for creating palettes, theme design, accessibility checks, or data-visualization color scales.

0 Downloads

Introduction source: third_party · TerminalSkills · 1.0.0 Reference

SkillPi interpretation

Software, accounts and paid services
```bash
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: chromajs
description: >-
  Manipulate colors with chroma.js — convert between color spaces (RGB, HSL,
  LAB, LCH), generate palettes and scales, mix and blend colors, check contrast
  ratios, and build accessible color systems. Use when tasks involve creating
  color palettes, theming, accessibility checks, or data visualization color
  scales.
license: Apache-2.0
compatibility: "Node.js 14+ or browser"
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: design
  tags: ["color", "palette", "accessibility", "chroma", "design-tokens"]

chroma.js

Color manipulation library for JavaScript. Handles conversions, scales, blending, and WCAG contrast calculations.

Setup

# Install chroma.js — works in Node and browser.
npm install chroma-js
npm install -D @types/chroma-js

Basic Color Operations

// src/colors/basics.ts — Create colors, convert between spaces, adjust properties.
import chroma from "chroma-js";

// Parse from any format
const red = chroma("#ff0000");
const blue = chroma("rgb(0, 0, 255)");
const green = chroma(120, 1, 0.5, "hsl");

// Convert between formats
console.log(red.hex());       // "#ff0000"
console.log(red.rgb());       // [255, 0, 0]
console.log(red.hsl());       // [0, 1, 0.5]
console.log(red.lab());       // [53.23, 80.11, 67.22]

// Adjust properties
const lighter = red.brighten(2);
const muted = red.desaturate(1.5);
const translucent = red.alpha(0.5);

Generating Color Scales

// src/colors/scales.ts — Build continuous color scales for data visualization.
// Scales interpolate between stops and can output any number of discrete colors.
import chroma from "chroma-js";

// Two-stop scale
const heatScale = chroma.scale(["#fafa6e", "#2A4858"]).mode("lch");
console.log(heatScale(0.5).hex()); // midpoint color

// Multi-stop diverging scale
const diverging = chroma
  .scale(["#d73027", "#ffffbf", "#1a9850"])
  .mode("lab")
  .domain([-1, 0, 1]);

// Generate 7 discrete colors from a scale
const palette = chroma.scale(["#fce4ec", "#880e4f"]).colors(7);

Accessible Contrast Checking

// src/colors/accessibility.ts — Check WCAG contrast ratios between foreground
// and background colors. Returns ratio and pass/fail for AA and AAA.
import chroma from "chroma-js";

export function checkContrast(fg: string, bg: string) {
  const contrast = chroma.contrast(fg, bg);
  return {
    ratio: Math.round(contrast * 100) / 100,
    aa: contrast >= 4.5,
    aaLarge: contrast >= 3,
    aaa: contrast >= 7,
  };
}

// Find the best text color for a given background
export function autoTextColor(bg: string): string {
  return chroma(bg).luminance() > 0.45 ? "#000000" : "#ffffff";
}

Palette Generation

// src/colors/palette.ts — Generate harmonious palettes from a base color
// using color theory (complementary, triadic, analogous).
import chroma from "chroma-js";

export function generatePalette(base: string, type: "complementary" | "triadic" | "analogous") {
  const [h, s, l] = chroma(base).hsl();
  const shifts: Record<string, number[]> = {
    complementary: [0, 180],
    triadic: [0, 120, 240],
    analogous: [-30, 0, 30],
  };
  return shifts[type].map((shift) =>
    chroma.hsl((h + shift + 360) % 360, s, l).hex()
  );
}

// Bezier interpolation for smoother multi-color palettes
const smooth = chroma.bezier(["#f00", "#ff0", "#0f0"]).scale().colors(9);

Mixing and Blending

// src/colors/blending.ts — Mix two colors in a given color space.
// LAB mixing produces more perceptually uniform results than RGB.
import chroma from "chroma-js";

const mixed = chroma.mix("#ff0000", "#0000ff", 0.5, "lab");
console.log(mixed.hex()); // perceptual midpoint

// Average multiple colors
const avg = chroma.average(["#ddd", "#ff0", "#09f"], "lab");

Current listing version

1.0.0

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value85/100

Highlights

  • 提供颜色空间转换、调色板生成、对比度检查等核心功能,适用于设计、主题开发、数据可视化等多个高价值场景
  • 支持无障碍色彩系统构建,符合现代设计规范要求
Trigger Precision90/100

Highlights

  • 触发描述清晰明确,覆盖创建调色板、主题设计、无障碍检查、数据可视化色阶等典型使用场景
  • 边界定义合理,不易与其他 Skill 混淆
Structure and Standards95/100

Areas to improve

  • 缺少显式 When to Use 章节 Reported severity: Minor

    文档未设置独立的 When to Use 章节,但 frontmatter 的 description 已充分覆盖使用场景

    Recommendation: 建议在正文开头增加显式的 When to Use 章节以提升可读性

Highlights

  • 文档结构清晰,分模块介绍各项功能,每部分均配有完整代码示例
  • frontmatter 完整,包含名称、描述、许可证、兼容性、元数据等信息
Execution Reliability80/100

Areas to improve

  • 未显式处理 chroma.js 导入失败异常 Reported severity: Minor

    示例代码中未展示对 chroma.js 导入失败或无效颜色输入的异常处理

    Recommendation: 建议在关键函数中添加 try-catch 或输入验证以提升健壮性

Highlights

  • 工具来源明确(chroma-js),参数使用正确,示例代码可直接运行
  • 提供了多种颜色操作场景的完整实现,逻辑清晰可靠
Evidence Verifiability (mean of the first four)88/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

  • Install or fetch external dependencies

    Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.

    Mentioned in main document · lines 26, 27

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

```bash

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.