| 1 | //! # Overview |
| 2 | //! |
| 3 | //! Rust library for parsing CSS color string as defined in the W3C's [CSS Color Module Level 4](https://www.w3.org/TR/css-color-4/). |
| 4 | //! |
| 5 | //! ## Supported Color Format |
| 6 | //! |
| 7 | //! * [Named colors](https://www.w3.org/TR/css-color-4/#named-colors) |
| 8 | //! * RGB hexadecimal (with and without `#` prefix) |
| 9 | //! + Short format `#rgb` |
| 10 | //! + Short format with alpha `#rgba` |
| 11 | //! + Long format `#rrggbb` |
| 12 | //! + Long format with alpha `#rrggbbaa` |
| 13 | //! * `rgb()` and `rgba()` |
| 14 | //! * `hsl()` and `hsla()` |
| 15 | //! * `hwb()` |
| 16 | //! * `lab()` |
| 17 | //! * `lch()` |
| 18 | //! * `oklab()` |
| 19 | //! * `oklch()` |
| 20 | //! * `hwba()`, `hsv()`, `hsva()` - not in CSS standard. |
| 21 | //! |
| 22 | //! ## Examples |
| 23 | //! |
| 24 | //! Using [`csscolorparser::parse()`](fn.parse.html) function. |
| 25 | //! |
| 26 | //! ```rust |
| 27 | //! # fn main() -> Result<(), Box<dyn core::error::Error>> { |
| 28 | //! let c = csscolorparser::parse("rgb(100%,0%,0%)")?; |
| 29 | //! |
| 30 | //! assert_eq!(c.to_array(), [1.0, 0.0, 0.0, 1.0]); |
| 31 | //! assert_eq!(c.to_rgba8(), [255, 0, 0, 255]); |
| 32 | //! assert_eq!(c.to_css_hex(), "#ff0000"); |
| 33 | //! assert_eq!(c.to_css_rgb(), "rgb(255 0 0)"); |
| 34 | //! # Ok(()) |
| 35 | //! # } |
| 36 | //! ``` |
| 37 | //! |
| 38 | //! Using `parse()` method on `&str`. |
| 39 | //! |
| 40 | //! ```rust |
| 41 | //! use csscolorparser::Color; |
| 42 | //! # fn main() -> Result<(), Box<dyn core::error::Error>> { |
| 43 | //! |
| 44 | //! let c: Color = "#ff00007f".parse()?; |
| 45 | //! |
| 46 | //! assert_eq!(c.to_rgba8(), [255, 0, 0, 127]); |
| 47 | //! assert_eq!(c.to_css_hex(), "#ff00007f"); |
| 48 | //! # Ok(()) |
| 49 | //! # } |
| 50 | //! ``` |
| 51 | //! |
| 52 | //! ## Default Feature |
| 53 | //! |
| 54 | //! * `std`: Using the standard library. |
| 55 | //! * `named-colors`: Enables parsing from [named colors](https://www.w3.org/TR/css-color-4/#named-colors). |
| 56 | //! |
| 57 | //! ## Optional Features |
| 58 | //! |
| 59 | //! * `rust-rgb`: Enables converting from [`rgb`](https://crates.io/crates/rgb) crate types into `Color`. |
| 60 | //! * `cint`: Enables converting [`cint`](https://crates.io/crates/cint) crate types to and from `Color`. |
| 61 | //! * `serde`: Enables serializing (into HEX string) and deserializing (from any supported string color format) using [`serde`](https://serde.rs/) framework. |
| 62 | |
| 63 | #![forbid(unsafe_code)] |
| 64 | #![warn(missing_docs)] |
| 65 | #![no_std] |
| 66 | |
| 67 | #[cfg(feature = "std")] |
| 68 | extern crate stdrust-analyzer cargo csscolorparser 0.8.3 std/; |
| 69 | |
| 70 | extern crate allocrust-analyzer cargo csscolorparser 0.8.3 alloc/; |
| 71 | |
| 72 | mod colorrust-analyzer cargo csscolorparser 0.8.3 color/; |
| 73 | mod color2rust-analyzer cargo csscolorparser 0.8.3 color2/; |
| 74 | pub use colorrust-analyzer cargo csscolorparser 0.8.3 color/::Colorrust-analyzer cargo csscolorparser 0.8.3 color/Color#; |
| 75 | |
| 76 | mod errorrust-analyzer cargo csscolorparser 0.8.3 error/; |
| 77 | pub use errorrust-analyzer cargo csscolorparser 0.8.3 error/::ParseColorErrorrust-analyzer cargo csscolorparser 0.8.3 error/ParseColorError#; |
| 78 | |
| 79 | mod parserrust-analyzer cargo csscolorparser 0.8.3 parser/; |
| 80 | pub use parserrust-analyzer cargo csscolorparser 0.8.3 parser/::parserust-analyzer cargo csscolorparser 0.8.3 parser/parse().; |
| 81 | |
| 82 | #[cfg(feature = "named-colors")] |
| 83 | mod named_colorsrust-analyzer cargo csscolorparser 0.8.3 named_colors/; |
| 84 | #[cfg(feature = "named-colors")] |
| 85 | pub use named_colorsrust-analyzer cargo csscolorparser 0.8.3 named_colors/::NAMED_COLORSrust-analyzer cargo csscolorparser 0.8.3 named_colors/NAMED_COLORS.; |
| 86 | |
| 87 | #[cfg(feature = "cint")] |
| 88 | mod cintrust-analyzer cargo csscolorparser 0.8.3 cint/; |
| 89 | |
| 90 | mod labrust-analyzer cargo csscolorparser 0.8.3 lab/; |
| 91 | |
| 92 | mod utilsrust-analyzer cargo csscolorparser 0.8.3 utils/; |