parse aliased named colors as colors
This commit is contained in:
parent
05e3c94e00
commit
1afbacb7c1
@ -1,5 +1,4 @@
|
||||
//! A big dictionary of named colors and their
|
||||
//! corresponding RGBA values
|
||||
//! A big dictionary of named colors and their corresponding RGBA values
|
||||
|
||||
pub(crate) struct NamedColorMap {
|
||||
name_to_rgba: phf::Map<&'static str, [u8; 4]>,
|
||||
@ -11,18 +10,17 @@ impl NamedColorMap {
|
||||
self.name_to_rgba.get(name)
|
||||
}
|
||||
|
||||
// transparent is not handled
|
||||
pub fn get_by_rgba(&self, rgba: [u8; 3]) -> Option<&&str> {
|
||||
self.rgba_to_name.get(&rgba)
|
||||
}
|
||||
}
|
||||
|
||||
// Adding one color requires adding to both map due to limitation in phf crate.
|
||||
pub(crate) static NAMED_COLORS: NamedColorMap = NamedColorMap {
|
||||
name_to_rgba: phf::phf_map! {
|
||||
"aliceblue" => [0xF0, 0xF8, 0xFF, 0xFF],
|
||||
"antiquewhite" => [0xFA, 0xEB, 0xD7, 0xFF],
|
||||
"aqua" => [0x00, 0xFF, 0xFF, 0xFF],
|
||||
"cyan" => [0x00, 0xFF, 0xFF, 0xFF],
|
||||
"aquamarine" => [0x7F, 0xFF, 0xD4, 0xFF],
|
||||
"azure" => [0xF0, 0xFF, 0xFF, 0xFF],
|
||||
"beige" => [0xF5, 0xF5, 0xDC, 0xFF],
|
||||
@ -44,6 +42,7 @@ pub(crate) static NAMED_COLORS: NamedColorMap = NamedColorMap {
|
||||
"darkcyan" => [0x00, 0x8B, 0x8B, 0xFF],
|
||||
"darkgoldenrod" => [0xB8, 0x86, 0x0B, 0xFF],
|
||||
"darkgray" => [0xA9, 0xA9, 0xA9, 0xFF],
|
||||
"darkgrey" => [0xA9, 0xA9, 0xA9, 0xFF],
|
||||
"darkgreen" => [0x00, 0x64, 0x00, 0xFF],
|
||||
"darkkhaki" => [0xBD, 0xB7, 0x6B, 0xFF],
|
||||
"darkmagenta" => [0x8B, 0x00, 0x8B, 0xFF],
|
||||
@ -55,21 +54,25 @@ pub(crate) static NAMED_COLORS: NamedColorMap = NamedColorMap {
|
||||
"darkseagreen" => [0x8F, 0xBC, 0x8F, 0xFF],
|
||||
"darkslateblue" => [0x48, 0x3D, 0x8B, 0xFF],
|
||||
"darkslategray" => [0x2F, 0x4F, 0x4F, 0xFF],
|
||||
"darkslategrey" => [0x2F, 0x4F, 0x4F, 0xFF],
|
||||
"darkturquoise" => [0x00, 0xCE, 0xD1, 0xFF],
|
||||
"darkviolet" => [0x94, 0x00, 0xD3, 0xFF],
|
||||
"deeppink" => [0xFF, 0x14, 0x93, 0xFF],
|
||||
"deepskyblue" => [0x00, 0xBF, 0xFF, 0xFF],
|
||||
"dimgray" => [0x69, 0x69, 0x69, 0xFF],
|
||||
"dimgrey" => [0x69, 0x69, 0x69, 0xFF],
|
||||
"dodgerblue" => [0x1E, 0x90, 0xFF, 0xFF],
|
||||
"firebrick" => [0xB2, 0x22, 0x22, 0xFF],
|
||||
"floralwhite" => [0xFF, 0xFA, 0xF0, 0xFF],
|
||||
"forestgreen" => [0x22, 0x8B, 0x22, 0xFF],
|
||||
"fuchsia" => [0xFF, 0x00, 0xFF, 0xFF],
|
||||
"magenta" => [0xFF, 0x00, 0xFF, 0xFF],
|
||||
"gainsboro" => [0xDC, 0xDC, 0xDC, 0xFF],
|
||||
"ghostwhite" => [0xF8, 0xF8, 0xFF, 0xFF],
|
||||
"gold" => [0xFF, 0xD7, 0x00, 0xFF],
|
||||
"goldenrod" => [0xDA, 0xA5, 0x20, 0xFF],
|
||||
"gray" => [0x80, 0x80, 0x80, 0xFF],
|
||||
"grey" => [0x80, 0x80, 0x80, 0xFF],
|
||||
"green" => [0x00, 0x80, 0x00, 0xFF],
|
||||
"greenyellow" => [0xAD, 0xFF, 0x2F, 0xFF],
|
||||
"honeydew" => [0xF0, 0xFF, 0xF0, 0xFF],
|
||||
@ -87,12 +90,14 @@ pub(crate) static NAMED_COLORS: NamedColorMap = NamedColorMap {
|
||||
"lightcyan" => [0xE0, 0xFF, 0xFF, 0xFF],
|
||||
"lightgoldenrodyellow" => [0xFA, 0xFA, 0xD2, 0xFF],
|
||||
"lightgray" => [0xD3, 0xD3, 0xD3, 0xFF],
|
||||
"lightgrey" => [0xD3, 0xD3, 0xD3, 0xFF],
|
||||
"lightgreen" => [0x90, 0xEE, 0x90, 0xFF],
|
||||
"lightpink" => [0xFF, 0xB6, 0xC1, 0xFF],
|
||||
"lightsalmon" => [0xFF, 0xA0, 0x7A, 0xFF],
|
||||
"lightseagreen" => [0x20, 0xB2, 0xAA, 0xFF],
|
||||
"lightskyblue" => [0x87, 0xCE, 0xFA, 0xFF],
|
||||
"lightslategray" => [0x77, 0x88, 0x99, 0xFF],
|
||||
"lightslategrey" => [0x77, 0x88, 0x99, 0xFF],
|
||||
"lightsteelblue" => [0xB0, 0xC4, 0xDE, 0xFF],
|
||||
"lightyellow" => [0xFF, 0xFF, 0xE0, 0xFF],
|
||||
"lime" => [0x00, 0xFF, 0x00, 0xFF],
|
||||
@ -145,6 +150,7 @@ pub(crate) static NAMED_COLORS: NamedColorMap = NamedColorMap {
|
||||
"skyblue" => [0x87, 0xCE, 0xEB, 0xFF],
|
||||
"slateblue" => [0x6A, 0x5A, 0xCD, 0xFF],
|
||||
"slategray" => [0x70, 0x80, 0x90, 0xFF],
|
||||
"slategrey" => [0x70, 0x80, 0x90, 0xFF],
|
||||
"snow" => [0xFF, 0xFA, 0xFA, 0xFF],
|
||||
"springgreen" => [0x00, 0xFF, 0x7F, 0xFF],
|
||||
"steelblue" => [0x46, 0x82, 0xB4, 0xFF],
|
||||
|
@ -705,6 +705,16 @@ test!(
|
||||
"a {\n color: change-color(red, $whiteness: 50%, $hue: 230);\n}\n",
|
||||
"a {\n color: #8095ff;\n}\n"
|
||||
);
|
||||
test!(
|
||||
aqua_alias,
|
||||
"a {\n color: cyan == aqua;\n}\n",
|
||||
"a {\n color: true;\n}\n"
|
||||
);
|
||||
test!(
|
||||
fuchsia_alias,
|
||||
"a {\n color: magenta == fuchsia;\n}\n",
|
||||
"a {\n color: true;\n}\n"
|
||||
);
|
||||
error!(
|
||||
hex_color_starts_with_number_non_hex_digit_at_position_6,
|
||||
"a {\n color: #00000z;\n}\n", "Error: Expected hex digit."
|
||||
|
@ -152,3 +152,9 @@ test!(
|
||||
"a{width:calc(100% + 32px)}",
|
||||
grass::Options::default().style(grass::OutputStyle::Compressed)
|
||||
);
|
||||
test!(
|
||||
cyan_normalized_to_aqua,
|
||||
"a {\n color: cyan;\n}\n",
|
||||
"a{color:aqua}",
|
||||
grass::Options::default().style(grass::OutputStyle::Compressed)
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user