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