1// (c) Dean McNamee <dean@gmail.com>, 2012.
2// (c) Rust port by Katkov Oleksandr <alexx.katkoff@gmail.com>, 2016.
3//
4// https://github.com/deanm/css-color-parser-js
5// https://github.com/7thSigil/css-color-parser-rs
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to
9// deal in the Software without restriction, including without limitation the
10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11// sell copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23// IN THE SOFTWARE.
24
25//! Easy-to-use Rust parser for CSS3 color strings.<br>
26//! Lightweight.<br>
27//! Reliable (Provides tests, handles all errors to avoid panic!s).<br>
28//!
29//! Not 100% spec compliant in the name of convenience (see examples below):<br>
30//! * allows for extra whitespaces<br>
31//! * allows for floats where standard allows percentages only<br>
32//!
33//! CSS3 Color spec: <br>
34//! http://www.w3.org/TR/css3-color/<br>
35//! https://developer.mozilla.org/en-US/docs/Web/CSS/color<br>
36//!
37//! Repository:<br>
38//! https://github.com/7thSigil/css-color-parser-rs.git
39//!
40//! Original js parser:<br>
41//! https://github.com/deanm/css-color-parser-js
42//!
43//! #Examples
44//!
45//! use css_color_parser::Color as CssColor;
46//!
47//! let transparent_black = CssColor { r: 0, g: 0, b: 0, a: 1.0 };
48//!
49//! println!("{:?}", " rgba (255, 128, 12, 0.5)".parse::<CssColor>()
50//! .unwrap_or(transparent_black));
51//! //Color { r: 255, g: 128, b: 12, a: 0.5 }
52//!
53//! println!("{:?}", "#fff".parse::<CssColor>()
54//! .unwrap_or(transparent_black));
55//! //Color { r: 255, g: 255, b: 255, a: 1 }
56//!
57//! println!("{:?}", "#ff0011".parse::<CssColor>()
58//! .unwrap_or(transparent_black));
59//! //Color { r: 255, g: 0, b: 17, a: 1 }
60//!
61//! println!("{:?}", "slateblue".parse::<CssColor>()
62//! .unwrap_or(transparent_black));
63//! //Color { r: 106, g: 90, b: 205, a: 1 }
64//!
65//! println!("{:?}", "blah".parse::<CssColor>()
66//! .unwrap_or(transparent_black));
67//! //Color { r: 0, g: 0, b: 0, a: 0 } - ColorParseError
68//!
69//! println!("{:?}", "ffffff".parse::<CssColor>()
70//! .unwrap_or(transparent_black));
71//! //Color { r: 0, g: 0, b: 0, a: 0 } - ColorParseError
72//!
73//! println!("{:?}", "hsla(900, 15%, 90%, 0.5)".parse::<CssColor>()
74//! .unwrap_or(transparent_black));
75//! //Color { r: 226, g: 233, b: 233, a: 0.5 }
76//!
77//! println!("{:?}", "hsla(900, 15%, 90%)".parse::<CssColor>()
78//! .unwrap_or(transparent_black));
79//! //Color { r: 0, g: 0, b: 0, a: 0 } - ColorParseError
80//! println!("{:?}", "hsl(900, 15%, 90%)".parse::<CssColor>()
81//! .unwrap_or(transparent_black));
82//! //Color { r: 226, g: 233, b: 233, a: 1 }
83//!
84//! // NOTE: not spec compliant.
85//! println!("{:?}", "hsl(900, 0.15, 90%)".parse::<CssColor>()
86//! .unwrap_or(transparent_black));
87//! //Color { r: 226, g: 233, b: 233, a: 1 }
88//!
89
90pub use crate::color::color::{Color, ColorParseError};
91pub use crate::color::named_colors::NAMED_COLORS;
92
93mod color;
94
95#[cfg(test)]
96mod tests;
97