use std::fmt::{Display, Formatter};
#[derive(Clone, Debug)]
pub struct PreflightSystem {
pub disable: bool,
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 {
disable: false,
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, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.custom)?;
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)?;
}
Ok(())
}
}