tailwind_css/systems/preflight/
mod.rs1use std::fmt::{Display, Formatter};
2
3#[derive(Clone, Debug)]
5pub struct PreflightSystem {
6 pub disable: bool,
8 pub remove_margins: bool,
12 pub unstyle_head: bool,
15 pub unstyle_list: bool,
18 pub block_level_image: bool,
21 pub unstyle_border: bool,
24 pub button_outline: bool,
27 pub custom: String,
29}
30
31impl Default for PreflightSystem {
32 fn default() -> Self {
33 Self {
34 disable: false,
35 remove_margins: true,
36 unstyle_head: true,
37 unstyle_list: true,
38 block_level_image: true,
39 unstyle_border: true,
40 button_outline: true,
41 custom: String::new(),
42 }
43 }
44}
45
46impl PreflightSystem {
47 const REMOVE_MARGINS: &'static str = r#"
48p, blockquote, hr, dl, dd, h1, h2, h3, h4, h5, h6, figure, pre {
49 margin: 0;
50}
51"#;
52 const RESET_HEAD: &'static str = r#"
53h1, h2, h3, h4, h5, h6 {
54 font-size: inherit;
55 font-weight: inherit;
56}
57"#;
58 const RESET_LIST: &'static str = r#"
59ol, ul {
60 list-style: none;
61 margin: 0;
62 padding: 0;
63}
64"#;
65 const IMAGE_BLOCK: &'static str = r#"
66img, svg, video, canvas, audio, iframe, embed, object {
67 display: block;
68 vertical-align: middle;
69}
70"#;
71 const RESET_BORDER: &'static str = r#"
73*, ::before, ::after {
74 border-width: 0;
75 border-style: solid;
76 border-color: theme('borderColor.DEFAULT', currentColor);
77}
78"#;
79 const BUTTON_OUTLINE: &'static str = r#"
80button:focus {
81 outline: 1px dotted;
82 outline: 5px auto -webkit-focus-ring-color;
83}
84"#;
85}
86
87impl Display for PreflightSystem {
88 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
89 f.write_str(&self.custom)?;
90 if self.remove_margins {
92 f.write_str(Self::REMOVE_MARGINS.trim())?;
93 writeln!(f)?;
94 }
95 if self.unstyle_head {
96 f.write_str(Self::RESET_HEAD.trim())?;
97 writeln!(f)?;
98 }
99 if self.unstyle_list {
100 f.write_str(Self::RESET_LIST.trim())?;
101 writeln!(f)?;
102 }
103 if self.block_level_image {
104 f.write_str(Self::IMAGE_BLOCK.trim())?;
105 writeln!(f)?;
106 }
107 if self.unstyle_border {
108 f.write_str(Self::RESET_BORDER.trim())?;
109 writeln!(f)?;
110 }
111 if self.button_outline {
112 f.write_str(Self::BUTTON_OUTLINE.trim())?;
113 writeln!(f)?;
114 }
115 Ok(())
116 }
117}