lightningcss/rules/
document.rs

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