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
66
67
68
69
70
use super::*;
#[doc = include_str!("readme.md")]
#[derive(Debug, Clone)]
pub struct TailwindUnderlineOffset {
kind: UnderlineOffset,
}
#[derive(Debug, Clone)]
enum UnderlineOffset {
Auto,
Unit(usize),
Length(LengthUnit),
}
impl Display for UnderlineOffset {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Auto => write!(f, "auto"),
Self::Unit(n) => write!(f, "{}", n),
Self::Length(n) => write!(f, "{}", n.get_class_arbitrary()),
}
}
}
impl Display for TailwindUnderlineOffset {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "underline-offset-{}", self)
}
}
impl TailwindInstance for TailwindUnderlineOffset {
fn attributes(&self, _: &TailwindBuilder) -> BTreeSet<CssAttribute> {
let offset = match self.kind {
UnderlineOffset::Auto => "auto".to_string(),
UnderlineOffset::Unit(n) => format!("{}px", n),
UnderlineOffset::Length(n) => n.get_properties(),
};
css_attributes! {
"text-underline-offset" => offset
}
}
}
impl TailwindUnderlineOffset {
pub fn parse(input: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
match input {
["auto"] => Ok(Self { kind: UnderlineOffset::Auto }),
[] => Self::parse_arbitrary(arbitrary),
[n] => {
let a = TailwindArbitrary::from(*n);
Self::parse_arbitrary(&a)
},
_ => syntax_error!("Unknown opacity instructions: {}", input.join("-")),
}
}
pub fn parse_arbitrary(arbitrary: &TailwindArbitrary) -> Result<Self> {
Self::maybe_no_unit(arbitrary).or_else(|_| Self::maybe_length(arbitrary))
}
fn maybe_length(arbitrary: &TailwindArbitrary) -> Result<Self> {
let n = arbitrary.as_length()?;
Ok(Self { kind: UnderlineOffset::Length(n) })
}
fn maybe_no_unit(arbitrary: &TailwindArbitrary) -> Result<Self> {
let n = arbitrary.as_integer()?;
Ok(Self { kind: UnderlineOffset::Unit(n) })
}
}