1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//! A Rust port of [culori](https://github.com/evercoder/culori), the
//! JavaScript color library by Dan Burzo.
//!
//! culors implements 30+ color spaces, conversion between any pair of
//! them, a CSS Color Module 4 string parser and matching formatter,
//! interpolation, gamut mapping, ΔE, separable blend modes, mode-aware
//! averaging, WCAG contrast, and the CSS filter set. Output values
//! agree with culori 4.0.2 within 1e-10 across an exhaustive fixture
//! set (110 conversion pairs, 365 parse cases, 303 format
//! round-trips).
//!
//! # Quick start
//!
//! Parse two CSS strings, blend them, and format the result back:
//!
//! ```rust
//! use culors::{blend, format_css, parse, BlendMode};
//!
//! let red = parse("#ff0000").unwrap();
//! let blue = parse("rgb(0 0 255 / 0.5)").unwrap();
//! let mixed = blend(&[red, blue], BlendMode::Multiply);
//! let css = format_css(&mixed);
//! assert!(css.starts_with("color(srgb"));
//! ```
//!
//! Parse, convert, and format:
//!
//! ```rust
//! use culors::{convert, format_css, parse, Color};
//! use culors::spaces::Lab;
//!
//! let parsed = parse("oklch(70% 0.15 30deg)").expect("valid CSS");
//! let lab: Lab = match parsed {
//! Color::Oklch(c) => convert(c),
//! _ => unreachable!("oklch(...) parses as Color::Oklch"),
//! };
//! let css = format_css(&Color::Lab(lab));
//! assert!(css.starts_with("lab("));
//! ```
//!
//! # Supported color spaces
//!
//! Spaces are exposed as plain structs in [`spaces`] and as variants of
//! [`Color`].
//!
//! | Family | Spaces |
//! |---|---|
//! | sRGB and linear | [`Color::Rgb`], [`Color::LinearRgb`] |
//! | Cylindrical sRGB | [`Color::Hsl`], [`Color::Hsv`], [`Color::Hwb`] |
//! | CIE | [`Color::Lab`], [`Color::Lch`], [`Color::Luv`], [`Color::Lchuv`], [`Color::Xyz50`], [`Color::Xyz65`] |
//! | Oklab | [`Color::Oklab`], [`Color::Oklch`], [`Color::Okhsl`], [`Color::Okhsv`] |
//! | Wide-gamut RGB | [`Color::P3`], [`Color::Rec2020`], [`Color::A98`], [`Color::ProphotoRgb`] |
//! | DIN99o | [`Color::Dlab`], [`Color::Dlch`] |
//! | JzAzBz / ICtCp | [`Color::Jab`], [`Color::Jch`], [`Color::Itp`] |
//! | HSLuv | [`Color::Hsluv`], [`Color::Hpluv`] |
//! | Other | [`Color::Cubehelix`], [`Color::Hsi`], [`Color::Yiq`], [`Color::Xyb`], [`Color::Prismatic`] |
//!
//! [`Color::Prismatic`] is a culors extension; culori 4.0.2 has no
//! Prismatic mode.
//!
//! # Public API tour
//!
//! - [`Color`] is the tagged union over every supported space. Each
//! variant wraps the matching struct from [`spaces`].
//! - The [`ColorSpace`] trait defines `to_xyz65` / `from_xyz65` for
//! every space, plus alpha access.
//! - [`convert()`] is the generic conversion function. It routes
//! through XYZ D65, so any pair of [`ColorSpace`] implementors
//! works without enumerating conversion paths. For bit-exact culori
//! parity on precision-critical pairs, use the direct `From` impls
//! listed in [`mod@convert`], or the dynamic-dispatch
//! [`Color::convert_to`] / typed [`convert::convert_culori`] APIs
//! added in v1.2 — both follow culori's per-pair routing.
//! - [`parse()`] consumes CSS Color Module 4 syntax (named colors,
//! hex, functional notation, `color()` profiles including the four
//! wide-gamut spaces, and `color-mix()`). Malformed or unsupported
//! input yields `None`.
//! - [`format_css`] serializes a [`Color`] to canonical CSS.
//! - [`interpolate()`] / [`interpolate_with()`] return a closure
//! `Fn(f64) -> Color` that samples a multi-stop ramp at `t ∈ [0, 1]`
//! in the requested space. [`HueFixup`] selects the cylindrical
//! fixup strategy.
//! - [`blend()`] / [`blend_str()`] fold a stack of colors with one of the
//! 12 separable [`BlendMode`] modes, using Porter-Duff source-over
//! with premultiplied alpha. Output is always `Color::Rgb`.
//! - [`average()`], [`average_number()`], [`average_angle()`] reduce a slice
//! of colors / numbers / hue angles in a chosen mode.
//! - [`in_gamut`], [`clamp_gamut`], [`clamp_chroma`], [`to_gamut`]
//! provide the gamut-mapping ladder, with [`to_gamut`] implementing
//! the CSS Color Module 4 algorithm using ΔE OK.
//! - The `difference_*` family (Ciede76, Ciede94, Ciede2000, CMC, OK,
//! JzAzBz, ICtCp, Euclidean, hue-chroma, hue-saturation) returns
//! curried closures `Fn(&Color, &Color) -> f64`.
//! - [`wcag_luminance`] and [`wcag_contrast`] implement the WCAG 2.x
//! contrast formula on sRGB.
//! - The `filter_*` family (`brightness`, `contrast`, `grayscale`,
//! `hue_rotate`, `invert`, `saturate`, `sepia`, plus CVD `prot` /
//! `deuter` / `trit`) returns a closure `Fn(&Color) -> Color`.
//!
//! # Interpolation
//!
//! ```rust
//! use culors::{interpolate, parse};
//!
//! let a = parse("oklch(70% 0.15 30deg)").unwrap();
//! let b = parse("oklch(70% 0.15 200deg)").unwrap();
//! let ramp = interpolate(&[a, b], "oklab");
//! let mid = ramp(0.5);
//! let _ = mid;
//! ```
//!
//! # WCAG contrast
//!
//! ```rust
//! use culors::{parse, wcag_contrast};
//!
//! let bg = parse("white").unwrap();
//! let fg = parse("black").unwrap();
//! let ratio = wcag_contrast(&bg, &fg);
//! assert!(ratio > 20.0);
//! ```
//!
//! # ΔE
//!
//! ```rust
//! use culors::{difference_ciede2000, parse};
//!
//! let de = difference_ciede2000(1.0, 1.0, 1.0);
//! let red = parse("red").unwrap();
//! let crimson = parse("crimson").unwrap();
//! assert!(de(&red, &crimson) > 0.0);
//! ```
//!
//! # Feature flags
//!
//! - `serde` (off by default): derives `Serialize` and `Deserialize`
//! for every space struct and for [`Color`].
//!
//! # Status
//!
//! As of v1.5 culors tracks culori 4.0.2 at full feature parity, modulo
//! the intentional divergences listed in the
//! [README](https://github.com/koole/culors#intentional-divergences-from-culori).
//! The library is in maintenance mode: new features land in
//! [culori](https://github.com/Evercoder/culori) first; once accepted
//! upstream they're mirrored here. Bug fixes and culori version bumps
//! remain in scope.
//!
//! # Further reading
//!
//! See the project [README](https://github.com/koole/culors#readme) for
//! the features matrix, comparison to culori, and v1.0 known
//! divergences. Release history is in
//! [CHANGELOG.md](https://github.com/koole/culors/blob/main/CHANGELOG.md).
//!
//! # License
//!
//! MIT-licensed.
pub
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use nearest;
pub use parse;
pub use ;
pub use round;
pub use ;
pub use ColorSpace;