Crates.io | csscolorparser |
lib.rs | csscolorparser |
version | 0.7.0 |
source | src |
created_at | 2020-12-13 17:07:25.830121 |
updated_at | 2024-08-05 14:25:17.147286 |
description | CSS color parser library |
homepage | |
repository | https://github.com/mazznoer/csscolorparser-rs |
max_upload_size | |
id | 322452 |
size | 72,891 |
Rust CSS Color Parser Library
Documentation • Changelog • Features
Rust library for parsing CSS color string as defined in the W3C's CSS Color Module Level 4.
#
prefix)
#rgb
#rgba
#rrggbb
#rrggbbaa
rgb()
and rgba()
hsl()
and hsla()
hwb()
lab()
lch()
hwba()
, hsv()
, hsva()
- not in CSS standard.transparent
gold
rebeccapurple
lime
#0f0
#0f0f
#00ff00
#00ff00ff
rgb(0,255,0)
rgb(0% 100% 0%)
rgb(0 255 0 / 100%)
rgba(0,255,0,1)
hsl(120,100%,50%)
hsl(120deg 100% 50%)
hsl(-240 100% 50%)
hsl(-240deg 100% 50%)
hsl(0.3333turn 100% 50%)
hsl(133.333grad 100% 50%)
hsl(2.0944rad 100% 50%)
hsla(120,100%,50%,100%)
hwb(120 0% 0%)
hwb(480deg 0% 0% / 100%)
hsv(120,100%,100%)
hsv(120deg 100% 100% / 100%)
Add this to your Cargo.toml
csscolorparser = "0.7.0"
Using csscolorparser::parse()
function.
let c = csscolorparser::parse("rgb(100%,0%,0%)")?;
assert_eq!(c.to_array(), [1.0, 0.0, 0.0, 1.0]);
assert_eq!(c.to_rgba8(), [255, 0, 0, 255]);
assert_eq!(c.to_hex_string(), "#ff0000");
assert_eq!(c.to_rgb_string(), "rgb(255,0,0)");
Using parse()
method on &str
.
use csscolorparser::Color;
let c = "#ff00007f".parse::<Color>()?;
assert_eq!(c.to_rgba8(), [255, 0, 0, 127]);
assert_eq!(c.to_hex_string(), "#ff00007f");
phf
. Can be disabled using default-features = false
.lab()
and lch()
color format.rgb
crate types into Color
.cint
crate types to and from Color
.serde
framework.