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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use crate::{Result, TailwindBuilder, TailwindInstance};
use std::fmt::{Display, Formatter, Write};
#[derive(Clone, Debug)]
pub struct PreflightSystem {
pub remove_margins: bool,
pub unstyle_head: bool,
pub unstyle_list: bool,
pub block_level_image: bool,
pub unstyle_border: bool,
pub button_outline: bool,
pub custom: String,
}
impl Default for PreflightSystem {
fn default() -> Self {
Self {
remove_margins: true,
unstyle_head: true,
unstyle_list: true,
block_level_image: true,
unstyle_border: true,
button_outline: true,
custom: String::new(),
}
}
}
impl PreflightSystem {
const REMOVE_MARGINS: &'static str = r#"
p, blockquote, hr, dl, dd, h1, h2, h3, h4, h5, h6, figure, pre {
margin: 0;
}
"#;
const RESET_HEAD: &'static str = r#"
h1, h2, h3, h4, h5, h6 {
font-size: inherit;
font-weight: inherit;
}
"#;
const RESET_LIST: &'static str = r#"
ol, ul {
list-style: none;
margin: 0;
padding: 0;
}
"#;
const IMAGE_BLOCK: &'static str = r#"
img, svg, video, canvas, audio, iframe, embed, object {
display: block;
vertical-align: middle;
}
"#;
const RESET_BORDER: &'static str = r#"
*, ::before, ::after {
border-width: 0;
border-style: solid;
border-color: theme('borderColor.DEFAULT', currentColor);
}
"#;
const BUTTON_OUTLINE: &'static str = r#"
button:focus {
outline: 1px dotted;
outline: 5px auto -webkit-focus-ring-color;
}
"#;
}
impl Display for PreflightSystem {
fn fmt(&self, _: &mut Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl TailwindInstance for PreflightSystem {
#[track_caller]
fn id(&self) -> String {
panic!("can't call id on `PreflightSystem`")
}
#[track_caller]
fn selectors(&self, _: &TailwindBuilder) -> String {
panic!("can't call selectors on `PreflightSystem`")
}
fn write_css(&self, f: &mut (dyn Write), _: &TailwindBuilder) -> Result<()> {
if self.remove_margins {
f.write_str(Self::REMOVE_MARGINS.trim())?;
writeln!(f)?;
}
if self.unstyle_head {
f.write_str(Self::RESET_HEAD.trim())?;
writeln!(f)?;
}
if self.unstyle_list {
f.write_str(Self::RESET_LIST.trim())?;
writeln!(f)?;
}
if self.block_level_image {
f.write_str(Self::IMAGE_BLOCK.trim())?;
writeln!(f)?;
}
if self.unstyle_border {
f.write_str(Self::RESET_BORDER.trim())?;
writeln!(f)?;
}
if self.button_outline {
f.write_str(Self::BUTTON_OUTLINE.trim())?;
writeln!(f)?;
}
f.write_str(&self.custom)?;
Ok(())
}
}