12 releases
Uses new Rust 2024
| 0.1.5 | Jan 20, 2025 |
|---|---|
| 0.1.4 | Jan 16, 2025 |
| 0.0.7 | Jan 8, 2025 |
#2778 in Parser implementations
1,324 downloads per month
Used in win-color
88KB
2K
SLoC
colorparser-css
lib.rs:
Overview
Rust library for parsing CSS color string as defined in the W3C's CSS Color Module Level 4.
Supported Color Format
- Named colors
- RGB hexadecimal (with and without
#prefix)- Short format
#rgb - Short format with alpha
#rgba - Long format
#rrggbb - Long format with alpha
#rrggbbaa
- Short format
rgb()andrgba()hsl()andhsla()gradient()
Example Color Format
Click to expand!
transparent
gold
rebeccapurple
lime
accent
accent_inactive
#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%)
gradient(rgb(0, 255, 0), #0f0, to right)
Usage
Add this to your Cargo.toml
colorparser_css = "0.1.0"
Default Feature
named-colors: Enables parsing from named colors. Requiresrustc-hash.theme: Enables to add custom theme.
Optional Features
serde: Enables serializing (into HEX string) and deserializing (from any supported string color format) usingserdeframework.
Dependencies
~2–16MB
~165K SLoC