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
use super::*;
#[derive(Clone, Debug)]
pub enum AnchorPoint {
LeftTop,
Top,
RightTop,
Left,
Center,
Right,
LeftBottom,
Bottom,
RightBottom,
Custom(String),
Global(CssBehavior),
}
impl AnchorPoint {
pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
let out = match pattern {
["7"] | ["left", "top"] | ["top", "left"] => Self::LeftTop,
["8"] | ["top"] => Self::Top,
["9"] | ["right", "top"] | ["top", "right"] => Self::RightTop,
["4"] | ["left"] => Self::Left,
["5"] | ["center"] => Self::Center,
["6"] | ["right"] => Self::Right,
["1"] | ["left", "bottom"] | ["bottom", "left"] => Self::LeftBottom,
["2"] | ["bottom"] => Self::Bottom,
["3"] | ["right", "bottom"] | ["bottom", "right"] => Self::RightBottom,
[] => Self::parse_arbitrary(arbitrary)?,
_ => return syntax_error!("Unknown anchor-point instructions: {}", pattern.join("-")),
};
Ok(out)
}
pub fn parse_arbitrary(arbitrary: &TailwindArbitrary) -> Result<Self> {
debug_assert!(arbitrary.is_some());
Ok(Self::Custom(arbitrary.to_string()))
}
pub fn get_class(&self) -> String {
match self {
Self::Global(g) => g.to_string(),
_ => format!("[{}]", self.get_properties()),
}
}
pub fn get_properties(&self) -> String {
match self {
Self::LeftTop => "0% 0%".to_string(),
Self::Top => "50% 0%".to_string(),
Self::RightTop => "100% 0%".to_string(),
Self::Left => "0% 50%".to_string(),
Self::Center => "50% 50%".to_string(),
Self::Right => "100% 50%".to_string(),
Self::LeftBottom => "0% 100%".to_string(),
Self::Bottom => "50% 100%".to_string(),
Self::RightBottom => "100% 100%".to_string(),
Self::Custom(c) => c.to_string(),
Self::Global(g) => g.to_string(),
}
}
}