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
71
72
73
74
75
76
77
78
79
80
81
mod builder;
mod parser;
use super::*;
#[doc = include_str ! ("spacing.md")]
#[derive(Copy, Clone, Debug)]
pub struct TailwindSpacing {
kind: TailwindSpacingKind,
size: TailwindSpacingSize,
}
#[derive(Copy, Clone, Debug)]
pub enum TailwindSpacingKind {
Padding,
PaddingL,
PaddingR,
PaddingT,
PaddingB,
PaddingX,
PaddingY,
Margin,
MarginL,
MarginR,
MarginT,
MarginB,
MarginX,
MarginY,
SpaceBetweenX,
SpaceBetweenY,
}
#[derive(Copy, Clone, Debug)]
pub enum TailwindSpacingSize {
Auto,
Reversed,
Px(usize),
Number(usize),
}
#[derive(Clone, Debug)]
pub struct SpacingSystem {
inner: HashMap<String, Spacing>,
}
impl Default for SpacingSystem {
fn default() -> Self {
Self { inner: Default::default() }
}
}
impl SpacingSystem {
pub fn builtin() -> Self {
let mut new = Self::default();
new.register("sm".to_string(), 640);
new.register("md".to_string(), 768);
new.register("lg".to_string(), 1024);
new.register("xl".to_string(), 1280);
new.register("2xl".to_string(), 1536);
return new;
}
#[inline]
pub fn register(&mut self, name: String, width: usize) -> Option<Spacing> {
self.inner.insert(name, Spacing { width })
}
}
#[derive(Clone, Debug)]
pub struct Spacing {
width: usize,
}
impl Display for Spacing {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(f, "@media (min-width: {}px) {{", self.width)?;
f.write_str("}")
}
}