parcel_css/rules/
document.rs

1//! The `@-moz-document` rule.
2
3use super::Location;
4use super::{CssRuleList, MinifyContext};
5use crate::error::{MinifyError, PrinterError};
6use crate::printer::Printer;
7use crate::traits::ToCss;
8
9/// A [@-moz-document](https://www.w3.org/TR/2012/WD-css3-conditional-20120911/#at-document) rule.
10///
11/// Note that only the `url-prefix()` function with no arguments is supported, and only the `-moz` prefix
12/// is allowed since Firefox was the only browser that ever implemented this rule.
13#[derive(Debug, PartialEq, Clone)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct MozDocumentRule<'i> {
16  /// Nested rules within the `@-moz-document` rule.
17  #[cfg_attr(feature = "serde", serde(borrow))]
18  pub rules: CssRuleList<'i>,
19  /// The location of the rule in the source file.
20  pub loc: Location,
21}
22
23impl<'i> MozDocumentRule<'i> {
24  pub(crate) fn minify(&mut self, context: &mut MinifyContext<'_, 'i>) -> Result<(), MinifyError> {
25    self.rules.minify(context, false)
26  }
27}
28
29impl<'i> ToCss for MozDocumentRule<'i> {
30  fn to_css<W>(&self, dest: &mut Printer<W>) -> Result<(), PrinterError>
31  where
32    W: std::fmt::Write,
33  {
34    dest.add_mapping(self.loc);
35    dest.write_str("@-moz-document url-prefix()")?;
36    dest.whitespace()?;
37    dest.write_char('{')?;
38    dest.indent();
39    dest.newline()?;
40    self.rules.to_css(dest)?;
41    dest.dedent();
42    dest.newline()?;
43    dest.write_char('}')
44  }
45}