1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use super::*;
pub(crate) mod color;
pub(crate) mod line;
pub(crate) mod style;
#[cfg(test)]
mod test;
pub(crate) mod thickness;
#[derive(Debug, Clone)]
pub struct TailwindDecoration {
arbitrary: String,
}
impl TailwindDecoration {
pub fn parse(str: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
let color = |color| TailwindDecorationColor::from(color).boxed();
let out = match str {
[s @ ("solid" | "double" | "dotted" | "dashed" | "wavy")] => TailwindDecorationStyle::from(*s).boxed(),
["style", rest @ ..] => TailwindDecorationStyle::parse(rest, arbitrary)?.boxed(),
["auto"] => TailwindDecorationThickness::from("auto").boxed(),
["from", "font"] => TailwindDecorationThickness::from("from-font").boxed(),
["current"] => color(TailwindColor::Current),
["transparent"] => color(TailwindColor::Transparent),
["inherit"] => color(TailwindColor::Inherit),
["black"] => color(TailwindColor::Black),
["white"] => color(TailwindColor::White),
["color"] => {
debug_assert!(arbitrary.is_some());
color(TailwindColor::parse_arbitrary(arbitrary)?)
},
["color", rest] => {
let a = TailwindArbitrary::from(*rest);
color(TailwindColor::parse_arbitrary(&a)?)
},
[theme, weight] => color(TailwindColor::parse_themed(theme, weight)?),
[n] => TailwindDecorationThickness::parse(n)?.boxed(),
[] => {
debug_assert!(arbitrary.is_some());
TailwindDecoration { arbitrary: arbitrary.to_string() }.boxed()
},
_ => return syntax_error!("Unknown decoration instructions: {}", str.join("-")),
};
Ok(out)
}
}
impl Display for TailwindDecoration {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "decoration-[{}]", self.arbitrary)
}
}
impl TailwindInstance for TailwindDecoration {
fn attributes(&self, _: &TailwindBuilder) -> BTreeSet<CssAttribute> {
css_attributes! {
"text-decoration" => self.arbitrary
}
}
}