bigcolor
A comprehensive Rust color manipulation library, inspired by TinyColor and Color.js. Designed to be intuitive, powerful, and fast for working with colors in various formats.
Features
-
Extensive Format Support
- Parse colors from RGB, RGBA, HSL, HSLA, HSV, HSVA, HSB, HSBA, HEX, CMYK, LAB, LCH, OKLAB, OKLCH
- Convert between any of these formats easily
- Support for named colors (CSS/SVG color keywords)
- Space-separated HSL format (e.g.
0 0% 12%) used in CSS variables
-
Color Manipulation
- Lighten, darken, saturate, desaturate, spin (adjust hue)
- Convert to greyscale, complement, invert
- Easily get brightness, luminance, and alpha values
-
Color Schemes
- Generate color schemes: analogous, monochromatic, triad, tetrad, split complement
- Create harmonious color palettes for design projects
-
Utilities
- Color mixing and blending
- WCAG contrast checking
- Color readability tools
- Bulk text color format conversion
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage Examples
Basic Color Creation and Conversion
use BigColor;
Color Modification
use BigColor;
Color Schemes
use BigColor;
Bulk Color Conversion
use ;
use Regex;
Demo Application
A demo web application is available to explore the capabilities of the BigColor library:
- Color parsing and conversion
- Color manipulation and scheme generation
- Bulk color conversion tool
- Interactive color previews
To run the demo:
Then open your browser to http://localhost:8080
Color Format Support
Input Formats
The library accepts the following color formats:
- Named Colors:
red,blue,rebeccapurple, etc. - Hex:
#f00,#ff0000,#ff0000ff - RGB:
rgb(255, 0, 0),rgba(255, 0, 0, 0.5),rgb(100%, 0%, 0%) - HSL:
hsl(0, 100%, 50%),hsla(0, 100%, 50%, 0.5) - HSV/HSB:
hsv(0, 100%, 100%),hsb(0, 100%, 100%) - CMYK:
cmyk(0%, 100%, 100%, 0%) - LAB:
lab(50, 80, 67) - LCH:
lch(50, 80, 20) - OKLAB:
oklab(60%, 0.1, 0.2) - OKLCH:
oklch(60%, 0.1, 30) - Space-separated HSL:
0 0% 12%(common in CSS variables)
Output Formats
Convert to any of these formats using the corresponding method:
let color = new;
color.to_hex_string; // "#ff0000"
color.to_rgb_string; // "rgb(255, 0, 0)"
color.to_hsl_string; // "hsl(0, 100%, 50%)"
color.to_hsv_string; // "hsv(0, 100%, 100%)"
color.to_hsb_string; // "hsb(0, 100%, 100%)"
color.to_cmyk_string; // "cmyk(0%, 100%, 100%, 0%)"
color.to_oklch_string; // "oklch(63% 0.26 29)"
License
MIT License - see the LICENSE file for details.
Credits
This library is partially a port of TinyColor by Brian Grinstead and inspired by Color.js.