logo
  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
use super::*;

/// https://tailwindcss.com/docs/preflight
#[derive(Clone, Debug)]
pub struct PreflightSystem {
    /// ## Default margins are removed
    /// Preflight removes all of the default margins from elements like headings, blockquotes, paragraphs, etc.
    /// This makes it harder to accidentally rely on margin values applied by the user-agent stylesheet that are not part of your spacing scale.
    pub remove_margins: bool,
    /// ## Headings are unstyled
    /// All heading elements are completely unstyled by default, and have the same font-size and font-weight as normal text.
    pub unstyle_head: bool,
    /// ## Lists are unstyled
    /// Ordered and unordered lists are unstyled by default, with no bullets/numbers and no margin or padding.
    pub unstyle_list: bool,
    /// ## Images are block-level
    /// Images and other replaced elements (like svg, video, canvas, and others) are display: block by default.
    pub block_level_image: bool,
    /// ## Border styles are reset globally
    /// In order to make it easy to add a border by simply adding the border class, Tailwind overrides the default border styles for all elements with the following rules:
    pub unstyle_border: bool,
    /// ## Buttons have a default outline
    /// To ensure that we provide accessible styles out of the box, we made sure that buttons have a default outline. You can of course override this by applying focus:ring or similar utilities to your buttons.
    pub button_outline: bool,
    /// Custom field for preflight
    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;
}
"#;
    // TODO: read theme here
    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(())
    }
}