# color/v1 — Color conversion and contrast

Converts between sRGB color representations and computes the WCAG 2.1
contrast ratio, using only Go's standard library `math`.

Supported formats: `hex`, `rgb`, `hsl`, `hsv`.

### `POST /v1/color/convert`

**Request**

```json
{ "from": "hex", "to": "rgb", "value": "#ff8000" }
```

`value`'s shape depends on `from`:

- `hex` — a string, `"#rrggbb"` or `"#rrggbbaa"` (the `#` is optional).
- `rgb` — `{"r":0-255,"g":0-255,"b":0-255,"a":0-1 (optional, default 1)}`.
- `hsl` — `{"h":0-360,"s":0-100,"l":0-100,"a":0-1 (optional)}`.
- `hsv` — `{"h":0-360,"s":0-100,"v":0-100,"a":0-1 (optional)}`.

**Response**

```json
{ "value": { "r": 255, "g": 128, "b": 0 } }
```

`value`'s shape matches `to`, following the same rules as the request. A
hex `value` omits the alpha pair when alpha is 1; `rgb`/`hsl`/`hsv` omit
the `a` field entirely when alpha is 1.

**Error response**

```json
{ "error": "unsupported format \"foo\": expected one of hex, rgb, hsl, hsv" }
```

### `POST /v1/color/contrast`

WCAG 2.1 contrast ratio between two opaque or translucent colors, given as
hex strings. To compute contrast starting from `rgb`/`hsl`/`hsv`, convert
to `hex` first via `/convert`.

**Request**

```json
{ "colorA": "#ffffff", "colorB": "#000000" }
```

**Response**

```json
{ "ratio": 21, "formula": "WCAG21" }
```

`formula` names the specification version the relative-luminance and
contrast-ratio formulas come from, since later WCAG revisions could
redefine them.

## Notes

- All conversions assume sRGB; no ICC profile or wide-gamut handling.
- `hsl`/`hsv` are display models derived from RGB, not calibrated color
  spaces — round-tripping through them can shift a color by up to ±1 in
  each RGB channel due to rounding.
- If `value`'s alpha is less than 1, `/contrast` composites it over a
  solid white background before computing luminance, since contrast ratio
  is only defined between two fully opaque colors.

## Out of scope

CMYK, Lab/LCH, named CSS colors, and gamut/profile-aware conversion — ask
if you need one added.

## Files

- `color.go` — module wiring (routes, HTTP handlers)
- `convert.go` — pure conversion and contrast logic
- `convert_test.go` — known-vector and error tests
