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
use std::fmt::Write;
use super::*;
#[doc = include_str!("readme.md")]
#[derive(Copy, Clone, Debug)]
pub struct TailwindScale {
negative: bool,
scale: usize,
axis: Option<bool>,
}
impl Display for TailwindScale {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if self.negative {
f.write_char('-')?
}
match self.axis {
None => write!(f, "scale-{}", self.scale),
Some(true) => write!(f, "scale-x-{}", self.scale),
Some(false) => write!(f, "scale-y-{}", self.scale),
}
}
}
impl TailwindInstance for TailwindScale {
fn attributes(&self, _: &TailwindBuilder) -> BTreeSet<CssAttribute> {
let scale = self.scale as f32 / 100.0;
let scale = match self.axis {
None => format!("scale({})", scale),
Some(true) => format!("scaleX({})", scale),
Some(false) => format!("scaleY({})", scale),
};
css_attributes! {
"transform" => scale
}
}
}
impl TailwindScale {
pub fn parse(input: &[&str], arbitrary: &TailwindArbitrary, axis: Option<bool>, neg: bool) -> Result<Self> {
debug_assert!(arbitrary.is_none(), "forbidden arbitrary");
match input {
[n] => Ok(Self { negative: neg, scale: TailwindArbitrary::from(*n).as_integer()?, axis }),
_ => syntax_error!("Unknown scale instructions: {}", input.join("-")),
}
}
}