lightningcss/rules/
viewport.rs

1//! The `@viewport` rule.
2
3use super::Location;
4use crate::declaration::DeclarationBlock;
5use crate::error::PrinterError;
6use crate::printer::Printer;
7use crate::traits::ToCss;
8use crate::vendor_prefix::VendorPrefix;
9#[cfg(feature = "visitor")]
10use crate::visitor::Visit;
11
12/// A [@viewport](https://drafts.csswg.org/css-device-adapt/#atviewport-rule) rule.
13#[derive(Debug, PartialEq, Clone)]
14#[cfg_attr(feature = "visitor", derive(Visit))]
15#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))]
16#[cfg_attr(
17  feature = "serde",
18  derive(serde::Serialize, serde::Deserialize),
19  serde(rename_all = "camelCase")
20)]
21#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
22pub struct ViewportRule<'i> {
23  /// The vendor prefix for this rule, e.g. `@-ms-viewport`.
24  #[cfg_attr(feature = "visitor", skip_visit)]
25  pub vendor_prefix: VendorPrefix,
26  /// The declarations within the `@viewport` rule.
27  #[cfg_attr(feature = "serde", serde(borrow))]
28  pub declarations: DeclarationBlock<'i>,
29  /// The location of the rule in the source file.
30  #[cfg_attr(feature = "visitor", skip_visit)]
31  pub loc: Location,
32}
33
34impl<'i> ToCss for ViewportRule<'i> {
35  fn to_css<W>(&self, dest: &mut Printer<W>) -> Result<(), PrinterError>
36  where
37    W: std::fmt::Write,
38  {
39    #[cfg(feature = "sourcemap")]
40    dest.add_mapping(self.loc);
41    dest.write_char('@')?;
42    self.vendor_prefix.to_css(dest)?;
43    dest.write_str("viewport")?;
44    self.declarations.to_css_block(dest)
45  }
46}