color
Colors without a dependency: parsing, hex, HSL, blending and WCAG contrast.
Rgb is an 8-bit sRGB color that parses from #rgb, #rrggbb, rgb(r, g, b) or a basic CSS name;
Hsl converts to and from it; mix blends two colors; contrast_ratio and best_text_color answer
“is this text readable on that background”.
Install
Section titled “Install”Cargo feature color (enabled by default). To compile only this module:
or in Cargo.toml:
Import path: helpers4::color.
| Item | What it does |
|---|---|
best_text_color | Picks black or white text, whichever contrasts more with background. |
contrast_ratio | The WCAG contrast ratio between two colors, from 1.0 (identical) to 21.0 (black on white). |
Hsl | A color as hue, saturation and lightness. |
mix | Blends two colors channel by channel. |
Rgb | An sRGB color with 8 bits per channel. |
Error types
Section titled “Error types”Documented on the page of the helper that returns them.
| Type | Returned by |
|---|---|
ParseColorError | Rgb |
