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
use super::*;
#[doc = include_str!("readme.md")]
#[derive(Clone, Debug)]
pub struct TailwindScrollMargin {
negative: bool,
axis: SpacingAxis,
size: SpacingSize,
}
impl Display for TailwindScrollMargin {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if self.negative {
f.write_char('-')?
}
write!(f, "{}-{}", self.axis, self.size)
}
}
impl TailwindInstance for TailwindScrollMargin {
fn attributes(&self, _: &TailwindBuilder) -> BTreeSet<CssAttribute> {
let mut out = BTreeSet::new();
self.axis.write_attributes(&mut out, self.size.get_properties());
out
}
}
impl TailwindScrollMargin {
pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary, negative: bool) -> Result<Self> {
let (axis, rest) = match pattern {
["m", rest @ ..] => (SpacingAxis::new("scroll-m", &["scroll-margin"]), rest),
["ml", rest @ ..] => (SpacingAxis::new("scroll-ml", &["scroll-margin-left"]), rest),
["mr", rest @ ..] => (SpacingAxis::new("scroll-mr", &["scroll-margin-right"]), rest),
["mt", rest @ ..] => (SpacingAxis::new("scroll-mt", &["scroll-margin-top"]), rest),
["mb", rest @ ..] => (SpacingAxis::new("scroll-mb", &["scroll-margin-bottom"]), rest),
["mx", rest @ ..] => (SpacingAxis::new("scroll-mx", &["scroll-margin-left", "scroll-margin-right"]), rest),
["my", rest @ ..] => (SpacingAxis::new("scroll-my", &["scroll-margin"]), rest),
_ => return syntax_error!("Unknown scroll-margin axis"),
};
let size = SpacingSize::parse(rest, arbitrary)?;
Ok(Self { negative, axis, size })
}
pub fn parse_arbitrary(arbitrary: &TailwindArbitrary, axis: SpacingAxis, negative: bool) -> Result<Self> {
let size = SpacingSize::parse_arbitrary(arbitrary)?;
Ok(Self { negative, axis, size })
}
}