Debian Codegraph @

/

debian rust-csscolorparser 0.8.3-1debian librust-csscolorparser-dev debian librust-csscolorparser+cint-dev debian librust-csscolorparser+default-dev debian librust-csscolorparser+named-colors-dev debian librust-csscolorparser+rust-rgb-dev debian librust-csscolorparser+serde-dev debian librust-csscolorparser+std-dev debian librust-csscolorparser-0-dev debian librust-csscolorparser-0+cint-dev debian librust-csscolorparser-0+default-dev debian librust-csscolorparser-0+named-colors-dev debian librust-csscolorparser-0+rust-rgb-dev debian librust-csscolorparser-0+serde-dev debian librust-csscolorparser-0+std-dev debian librust-csscolorparser-0.8-dev debian librust-csscolorparser-0.8+cint-dev debian librust-csscolorparser-0.8+default-dev debian librust-csscolorparser-0.8+named-colors-dev debian librust-csscolorparser-0.8+rust-rgb-dev
10 more… debian librust-csscolorparser-0.8+serde-dev debian librust-csscolorparser-0.8+std-dev debian librust-csscolorparser-0.8.3-dev debian librust-csscolorparser-0.8.3+cint-dev debian librust-csscolorparser-0.8.3+default-dev debian librust-csscolorparser-0.8.3+named-colors-dev debian librust-csscolorparser-0.8.3+rust-rgb-dev debian librust-csscolorparser-0.8.3+serde-dev debian librust-csscolorparser-0.8.3+std-dev cargo csscolorparser 0.8.3
debianjsonmakemakefilemarkdownrustrustrust-c-abishelltoml 41 files · 638 symbols
View dependency graph

Depends on

  • dh-cargo (dh-sequence-cargo)
  • rust-cint (librust-cint-0.3+default-dev)
  • cargo, debhelper-compat, librust-num-traits-0.2+libm-dev, librust-phf-0.11+macros-dev, librust-phf-0.11+std-dev, librust-phf-0.11+uncased-dev, librust-rgb-0.8+default-dev, librust-serde-1+derive-dev, librust-serde-1+std-dev, librust-uncased-0.9-dev, libstd-rust-dev, rustc
README (full)

Rust CSS Color Parser Library

License crates.io Documentation Build Status Total Downloads

Documentation • Changelog • Features


Rust library for parsing CSS color string as defined in the W3C's CSS Color Module Level 4.

Supported Color Format

Absolute Color

  • Named colors
  • RGB hexadecimal (with and without # prefix)
    • Short format #rgb
    • Short format with alpha #rgba
    • Long format #rrggbb
    • Long format with alpha #rrggbbaa
  • rgb() and rgba()
  • hsl() and hsla()
  • hwb()
  • lab()
  • lch()
  • oklab()
  • oklch()
  • hwba(), hsv(), hsva() - not in CSS standard.

Relative Color

Example:

rgb(from red r g calc(b + 20))
rgb(from gold calc(((r + g) + b) / 3) 127 127)
hwb(from #bad455 calc(h + 35) w b)
hsl(from purple h s l / 0.5)

Relative Color Format Limitations

Doesn't support percentage.

calc() only support the following expression:

[OPERAND] [OPERATOR] [OPERAND]

OPERAND can be a number, a variable (r, g, b, alpha etc. depends on color function) or another expression wrapped in parenthesis. OPERATOR is one of +, -, * or /.

Not Supported
rgb(from #bad455 100% g b)
rgb(from #bad455 r g b / 50%)
rgb(from #bad455 calc(r+g-30) 90 b)
OK
rgb(from #bad455 255 g b)
rgb(from #bad455 r g b / 0.5)
rgb(from #bad455 calc(r+15) 90 b)
rgb(from #bad455 calc((r+g)-30) 90 b)
hwb(from rgb(from rgb(100% 0% 50%) r g 75) calc(h+25) w b)

Usage

Add this to your Cargo.toml

csscolorparser = "0.8"

Examples

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_css_hex(), "#ff0000");
assert_eq!(c.to_css_rgb(), "rgb(255 0 0)");
assert_eq!(c.name(), Some("red"));

Using parse() method on &str.

use csscolorparser::Color;

let c: Color = "#ff00007f".parse()?;

assert_eq!(c.to_rgba8(), [255, 0, 0, 127]);
assert_eq!(c.to_css_hex(), "#ff00007f");

Features

Default

  • std: Using the standard library.
  • named-colors: Enables parsing from named colors.

Default features can be disabled using default-features = false.

Optional

  • rust-rgb: Enables converting from rgb crate types into Color.
  • cint: Enables converting cint crate types to and from Color.
  • serde: Enables serializing (into HEX string) and deserializing (from any supported string color format) using serde framework.

Similar Projects

dir debian/
dir examples/
dir src/
dir tests/
file .cargo_vcs_info.json
file .gitignore
file CHANGELOG.md
file Cargo.lock
file Cargo.toml
file Cargo.toml.orig
file LICENSE-APACHE
file LICENSE-MIT
file Makefile
file README.md