# color (engines/adapters/domain/color)

Color capability pack: conversions between hex/rgb/hsl/cmyk, a universal parse() that normalizes hex/rgb()/hsl()/named colors into { hex, rgb, hsl }, WCAG contrast ratio with AA/AAA pass flags...


Self-contained color capability pack. Zero deps, pure JS. Colors are held internally as
`{ r, g, b }` bytes; every tool takes one args object and returns plain JSON.

| tool | what it does |
|------|--------------|
| `hexToRgb` / `rgbToHex` | hex ⇄ `{r,g,b}` (accepts `#fff`, `#ffffff`, bare, and `#rgba`/`#rrggbbaa`) |
| `rgbToHsl` / `hslToRgb` | rgb ⇄ hsl |
| `rgbToCmyk` | rgb → cmyk (print) |
| `parse` | any color (hex / `rgb()` / `hsl()` / CSS name) → `{ hex, rgb, hsl, cmyk, name }` |
| `contrast` | WCAG ratio between `a` & `b` + `{ ratio, AA, AAA, AALarge, AAALarge }` pass flags |
| `luminance` | relative luminance (WCAG) of one color |
| `lighten` / `darken` | shift HSL lightness by `amount` (0-1) |
| `saturate` / `desaturate` | shift HSL saturation by `amount` (0-1) |
| `mix` | blend `a` & `b` by `weight` (0-1, toward `a`) |
| `palette` | `complementary` / `analogous` / `triadic` / `tetradic` / `monochromatic` → hex array |
| `randomPalette` | pleasant palette of `count` colors; optional `seed` = deterministic |
| `namedColors` | list the ~148 CSS named colors (or look one up by `name`) |

## Usage

```js
import color from './index.js';
color.adapters.parse({ color: 'rebeccapurple' });
// → { hex: '#663399', rgb: { r:102, g:51, b:153 }, hsl: { h:270, s:50, l:40 }, cmyk: {...}, name: 'rebeccapurple' }

color.adapters.contrast({ a: '#000', b: '#fff' }).ratio;      // 21
color.adapters.palette({ color: '#3498db', scheme: 'triadic' }).colors;
color.adapters.randomPalette({ count: 5, seed: 42 }).colors;  // deterministic
```

## DRY boundary

This pack does **color math** (space conversions, contrast, palettes). It does **not** own design
tokens or theme UI — that's `@leumas/theme`. It does not **validate** arbitrary strings (that's the
`validation` pack's `hexColor`); `parse()` throws on unparseable input. The ~148 CSS named colors
live in `data/named-colors.json`.


---
Source: shared/engines/adapters/domain/color/README.md
Canonical: https://docs.leumas.tech/p/adapters/domain/color
