css colors

This commit is contained in:
annieversary 2022-08-15 12:22:03 +01:00
parent db4acd8995
commit 20b22c4c9e
3 changed files with 181 additions and 11 deletions

149
src/consts.rs Normal file
View File

@ -0,0 +1,149 @@
pub const CSS_COLORS: [&str; 147] = [
"aliceblue",
"antiquewhite",
"aqua",
"aquamarine",
"azure",
"beige",
"bisque",
"black",
"blanchedalmond",
"blue",
"blueviolet",
"brown",
"burlywood",
"cadetblue",
"chartreuse",
"chocolate",
"coral",
"cornflowerblue",
"cornsilk",
"crimson",
"cyan",
"darkblue",
"darkcyan",
"darkgoldenrod",
"darkgray",
"darkgreen",
"darkgrey",
"darkkhaki",
"darkmagenta",
"darkolivegreen",
"darkorange",
"darkorchid",
"darkred",
"darksalmon",
"darkseagreen",
"darkslateblue",
"darkslategray",
"darkslategrey",
"darkturquoise",
"darkviolet",
"deeppink",
"deepskyblue",
"dimgray",
"dodgerblue",
"firebrick",
"floralwhite",
"forestgreen",
"fuchsia",
"gainsboro",
"ghostwhite",
"gold",
"goldenrod",
"gray",
"green",
"greenyellow",
"grey",
"honeydew",
"hotpink",
"indianred",
"indigo",
"ivory",
"khaki",
"lavender",
"lavenderblush",
"lawngreen",
"lemonchiffon",
"lightblue",
"lightcoral",
"lightcyan",
"lightgoldenrodyellow",
"lightgray",
"lightgreen",
"lightgrey",
"lightpink",
"lightsalmon",
"lightseagreen",
"lightskyblue",
"lightslategray",
"lightslategrey",
"lightsteelblue",
"lightyellow",
"lime",
"limegreen",
"linen",
"magenta",
"maroon",
"mediumaquamarine",
"mediumblue",
"mediumorchid",
"mediumpurple",
"mediumseagreen",
"mediumslateblue",
"mediumspringgreen",
"mediumturquoise",
"mediumvioletred",
"midnightblue",
"mintcream",
"mistyrose",
"moccasin",
"navajowhite",
"navy",
"oldlace",
"olive",
"olivedrab",
"orange",
"orangered",
"orchid",
"palegoldenrod",
"palegreen",
"paleturquoise",
"palevioletred",
"papayawhip",
"peachpuff",
"peru",
"pink",
"plum",
"powderblue",
"purple",
"rebeccapurple",
"red",
"rosybrown",
"royalblue",
"saddlebrown",
"salmon",
"sandybrown",
"seagreen",
"seashell",
"sienna",
"silver",
"skyblue",
"slateblue",
"slategray",
"slategrey",
"snow",
"springgreen",
"steelblue",
"tan",
"teal",
"thistle",
"tomato",
"turquoise",
"violet",
"wheat",
"white",
"whitesmoke",
"yellow",
"yellowgreen",
];

View File

@ -1,13 +1,14 @@
use std::collections::HashMap;
use crate::SpecialDeclaration;
use crate::{consts::CSS_COLORS, SpecialDeclaration};
pub(crate) fn default_declarations() -> HashMap<String, String> {
vec![
("flex", "display:flex;"),
("flex-row", "display:flex;flex-direction:row;"),
("flex-col", "display:flex;flex-direction:column;"),
let mut h = vec![
("flex", "display:flex"),
("flex-row", "display:flex;flex-direction:row"),
("flex-col", "display:flex;flex-direction:column"),
("items-center", "align-items:center"),
("items-start", "align-items:flex-start"),
("items-end", "align-items:flex-end"),
("justify-center", "justify-content:center"),
("justify-between", "justify-content:space-between"),
@ -18,7 +19,16 @@ pub(crate) fn default_declarations() -> HashMap<String, String> {
]
.into_iter()
.map(|(a, b)| (a.to_string(), b.to_string()))
.collect()
.collect::<HashMap<_, _>>();
// add all css colors
h.extend(
CSS_COLORS
.iter()
.map(|c| (c.to_string(), format!("color:{c}"))),
);
h
}
pub(crate) fn default_properties() -> HashMap<String, String> {

View File

@ -5,6 +5,7 @@ use defaults::default_modifiers;
use crate::{defaults::*, parse::*};
mod class;
mod consts;
mod defaults;
mod media_queries;
mod modifiers;
@ -172,7 +173,7 @@ mod tests {
let z = Zephyr::new();
let classes = z.generate_classes(["flex-row"]);
assert_eq!(classes, r#".flex-row{display:flex;flex-direction:row;}"#);
assert_eq!(classes, r#".flex-row{display:flex;flex-direction:row}"#);
let classes = z.generate_classes(["m[3rem]hover,focus$placeholder"]);
assert_eq!(
@ -183,7 +184,7 @@ mod tests {
let classes = z.generate_classes(["flex|hover,focus$placeholder"]);
assert_eq!(
classes,
r#".flex\|hover,focus\$placeholder:hover:focus::placeholder{display:flex;}"#
r#".flex\|hover,focus\$placeholder:hover:focus::placeholder{display:flex}"#
);
let classes = z.generate_classes(["mr[0.5rem]"]);
@ -198,7 +199,7 @@ mod tests {
let classes_separate = z.generate_classes(["flex-row", "mt[1rem]"]);
assert_eq!(
classes_joined,
r#".flex-row{display:flex;flex-direction:row;}.mt\[1rem\]{margin-top:1rem;}"#
r#".flex-row{display:flex;flex-direction:row}.mt\[1rem\]{margin-top:1rem;}"#
);
assert_eq!(classes_separate, classes_joined);
}
@ -241,7 +242,6 @@ mod tests {
fn generate_with_media_query() {
let z = Zephyr::new();
// the curly brackets indicate that the value should not go through replacements
let classes = z.generate_classes(["m[1rem]sm"]);
assert_eq!(
classes,
@ -253,8 +253,19 @@ mod tests {
fn generate_variable() {
let z = Zephyr::new();
// the curly brackets indicate that the value should not go through replacements
// the parens indicate that it should be replaced by `var(--...)`
let classes = z.generate_classes(["m(my-margin)"]);
assert_eq!(classes, r#".m\(my-margin\){margin:var(--my-margin);}"#);
}
#[test]
fn generate_css_colors() {
let z = Zephyr::new();
let classes = z.generate_classes(["white blanchedalmond"]);
assert_eq!(
classes,
r#".white{color:white}.blanchedalmond{color:blanchedalmond}"#
);
}
}