@@ -31,12 +31,12 @@ reference color values, and palettes.
3131Four color spaces are used. ** sRGB** is the canonical storage format; all others
3232are conversion targets/sources.
3333
34- | Color space | Components | Ranges | Role |
35- | ----------- | ---------------------------------- | ------------------------------------------------- | ---- |
36- | ** sRGB** | ` r ` , ` g ` , ` b ` | 0–1 each (may exceed 1 for wide-gamut) | Canonical. Every color-returning function produces sRGB tuples. |
37- | ** OKLCh** | ` L ` (lightness), ` C ` (chroma), ` h ` (hue) | L: 0–1, C: 0–0.4, h: 0–360° | Perceptually uniform cylindrical space. Used for all interpolation, gamut mapping, and lightness/chroma manipulation. |
38- | ** OKLab** | ` L ` (lightness), ` a ` (green–red), ` b ` (blue–yellow) | L: 0–1, a: −0.4–0.4, b: −0.4–0.4 | Perceptually uniform rectangular space. OKLCh is its cylindrical form. Useful for computing color differences (ΔE). Accepted as ` "oklab" ` or ` "lab" ` . |
39- | ** HSL** | ` h ` (hue), ` s ` (saturation), ` l ` (lightness) | h: 0–360°, s: 0–1, l: 0–1 | Legacy CSS color space. Familiar to web developers. Not perceptually uniform. |
34+ | Color space | Components | Ranges | Role |
35+ | ----------- | --------------------------------------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- ---- |
36+ | ** sRGB** | ` r ` , ` g ` , ` b ` | 0–1 each (may exceed 1 for wide-gamut) | Canonical. Every color-returning function produces sRGB tuples. |
37+ | ** OKLCh** | ` L ` (lightness), ` C ` (chroma), ` h ` (hue) | L: 0–1, C: 0–0.4, h: 0–360° | Perceptually uniform cylindrical space. Used for all interpolation, gamut mapping, and lightness/chroma manipulation. |
38+ | ** OKLab** | ` L ` (lightness), ` a ` (green–red), ` b ` (blue–yellow) | L: 0–1, a: −0.4–0.4, b: −0.4–0.4 | Perceptually uniform rectangular space. OKLCh is its cylindrical form. Useful for computing color differences (ΔE). Accepted as ` "oklab" ` or ` "lab" ` . |
39+ | ** HSL** | ` h ` (hue), ` s ` (saturation), ` l ` (lightness) | h: 0–360°, s: 0–1, l: 0–1 | Legacy CSS color space. Familiar to web developers. Not perceptually uniform. |
4040
4141### Why OKLCh for interpolation?
4242
@@ -61,8 +61,8 @@ HSL ⟷ sRGB ⟷ OKLab ⟷ OKLCh
6161```
6262
6363Full bidirectional conversion exists between all four spaces, with sRGB as the
64- hub. Conversions between non-adjacent spaces go through sRGB (e.g.
65- HSL → sRGB → OKLab).
64+ hub. Conversions between non-adjacent spaces go through sRGB (e.g. HSL → sRGB →
65+ OKLab).
6666
6767** Implementation note** : ` hslToRgb ` exists in ` src/color/manipulation.ts ` .
6868` rgbToHsl ` needs to be added for the reverse direction.
@@ -81,18 +81,18 @@ Color(input: string) -> Tuple<real, real, real> | Tuple<real, real, real, real>
8181
8282#### Accepted input formats
8383
84- | Format | Example | Notes |
85- | ------------------- | ------------------------------ | --- ----------------------------------------------- |
86- | Hex (3 digits) | ` "#f2c" ` | Expanded to ` #ff22cc ` |
87- | Hex (6 digits) | ` "#fedaca" ` | |
88- | Hex (8 digits) | ` "#fedacaff" ` | Last two digits are alpha |
89- | ` rgb() ` / ` rgba() ` | ` "rgb(255, 100, 20)" ` | Values 0–255; values ≤ 1.0 treated as fractions |
90- | ` rgb() ` modern | ` "rgb(255 100 20 / 0.5)" ` | Space-separated, slash-alpha |
91- | ` rgb() ` percent | ` "rgb(50%, 25%, 10%)" ` | Percentages |
92- | ` hsl() ` / ` hsla() ` | ` "hsl(210, 80%, 50%)" ` | H: 0–360°, S/L: 0–100% |
93- | ` oklch() ` | ` "oklch(0.7 0.15 210)" ` | L: 0–1, C: 0–0.4, H: 0–360° |
94- | Named color | ` "red" ` , ` "teal" ` , ` "white" ` | See named colors table |
95- | ` "transparent" ` | ` "transparent" ` | Returns ` (0, 0, 0, 0) ` |
84+ | Format | Example | Notes |
85+ | ------------------ | ---------------------------- | ----------------------------------------------- |
86+ | Hex (3 digits) | ` "#f2c" ` | Expanded to ` #ff22cc ` |
87+ | Hex (6 digits) | ` "#fedaca" ` | |
88+ | Hex (8 digits) | ` "#fedacaff" ` | Last two digits are alpha |
89+ | ` rgb() ` / ` rgba() ` | ` "rgb(255, 100, 20)" ` | Values 0–255; values ≤ 1.0 treated as fractions |
90+ | ` rgb() ` modern | ` "rgb(255 100 20 / 0.5)" ` | Space-separated, slash-alpha |
91+ | ` rgb() ` percent | ` "rgb(50%, 25%, 10%)" ` | Percentages |
92+ | ` hsl() ` / ` hsla() ` | ` "hsl(210, 80%, 50%)" ` | H: 0–360°, S/L: 0–100% |
93+ | ` oklch() ` | ` "oklch(0.7 0.15 210)" ` | L: 0–1, C: 0–0.4, H: 0–360° |
94+ | Named color | ` "red" ` , ` "teal" ` , ` "white" ` | See named colors table |
95+ | ` "transparent" ` | ` "transparent" ` | Returns ` (0, 0, 0, 0) ` |
9696
9797#### Named colors
9898
@@ -170,21 +170,19 @@ ensure perceptual uniformity. Hue interpolation uses the shorter arc.
170170
171171#### Available palettes
172172
173- ** Sequential** (256-stop, perceptually uniform):
174- ` turbo ` , ` inferno ` , ` magma ` , ` plasma ` , ` viridis ` , ` cividis ` , ` rocket ` , ` mako `
173+ ** Sequential** (256-stop, perceptually uniform): ` turbo ` , ` inferno ` , ` magma ` ,
174+ ` plasma ` , ` viridis ` , ` cividis ` , ` rocket ` , ` mako `
175175
176- Each sequential palette also has a ` -reversed ` variant (e.g. ` viridis-reversed ` ).
176+ Each sequential palette also has a ` -reversed ` variant (e.g.
177+ ` viridis-reversed ` ).
177178
178- ** Sequential (short)** :
179- ` grey ` (18 stops)
179+ ** Sequential (short)** : ` grey ` (18 stops)
180180
181- ** Categorical** (discrete, not meaningful to interpolate between):
182- ` tycho11 ` (11), ` tableau10 ` (10), ` kelly22 ` (22), ` graph6 ` (6),
183- ` spectrum6 ` (6), ` spectrum12 ` (12)
181+ ** Categorical** (discrete, not meaningful to interpolate between): ` tycho11 `
182+ (11), ` tableau10 ` (10), ` kelly22 ` (22), ` graph6 ` (6), ` spectrum12 ` (12)
184183
185- ** Diverging** (symmetric around a neutral midpoint):
186- ` roma ` (261), ` vik ` (9), ` broc ` (9), ` rdbu ` (21), ` coolwarm ` (21),
187- ` ocean-balance ` (22)
184+ ** Diverging** (symmetric around a neutral midpoint): ` roma ` (261), ` vik ` (9),
185+ ` broc ` (9), ` rdbu ` (21), ` coolwarm ` (21), ` ocean-balance ` (22)
188186
189187Each diverging palette also has a ` -reversed ` variant.
190188
@@ -207,16 +205,17 @@ Convert a color to component values in a target color space.
207205ColorToColorspace(color, colorspace: string) -> Tuple
208206```
209207
210- The first argument may be a canonical RGB tuple or any value accepted by ` Color ` .
208+ The first argument may be a canonical RGB tuple or any value accepted by
209+ ` Color ` .
211210
212211#### Supported color spaces
213212
214- | Name | Components | Ranges |
215- | --------------------- | ---------------------- | ----------- -------------------------------- |
216- | ` "rgb" ` | ` (r, g, b) ` | 0–1 each (sRGB) |
217- | ` "hsl" ` | ` (h, s, l) ` | h: 0–360, s: 0–1, l: 0–1 |
218- | ` "oklch" ` | ` (L, C, h) ` | L: 0–1, C: 0–0.4, h: 0–360 |
219- | ` "oklab" ` or ` "lab" ` | ` (L, a, b) ` | L: 0–1, a: −0.4–0.4, b: −0.4–0.4 |
213+ | Name | Components | Ranges |
214+ | -------------------- | ----------- | -------------------------------- |
215+ | ` "rgb" ` | ` (r, g, b) ` | 0–1 each (sRGB) |
216+ | ` "hsl" ` | ` (h, s, l) ` | h: 0–360, s: 0–1, l: 0–1 |
217+ | ` "oklch" ` | ` (L, C, h) ` | L: 0–1, C: 0–0.4, h: 0–360 |
218+ | ` "oklab" ` or ` "lab" ` | ` (L, a, b) ` | L: 0–1, a: −0.4–0.4, b: −0.4–0.4 |
220219
221220Alpha, if present and ≠ 1, is appended as a fourth component in every case.
222221
@@ -240,9 +239,9 @@ ColorFromColorspace(components: Tuple, colorspace: string) -> Tuple
240239```
241240
242241The same color space names as ` ColorToColorspace ` are accepted (` "rgb" ` ,
243- ` "hsl" ` , ` "oklch" ` , ` "oklab" ` / ` "lab" ` ). If the input color is outside the
244- sRGB gamut, chroma is reduced (in OKLCh) while preserving hue until the color
245- fits, using a binary-search gamut-mapping algorithm (see Color Spaces section).
242+ ` "hsl" ` , ` "oklch" ` , ` "oklab" ` / ` "lab" ` ). If the input color is outside the sRGB
243+ gamut, chroma is reduced (in OKLCh) while preserving hue until the color fits,
244+ using a binary-search gamut-mapping algorithm (see Color Spaces section).
246245
247246#### Examples
248247
0 commit comments