Skip to main content

rspack_lightningcss/rules/
position_try.rs

1//! The `@position-try` rule.
2
3use super::Location;
4use crate::declaration::DeclarationBlock;
5use crate::error::PrinterError;
6use crate::traits::ToCss;
7use crate::values::ident::DashedIdent;
8#[cfg(feature = "visitor")]
9use crate::visitor::Visit;
10
11/// A [@position-try](https://drafts.csswg.org/css-anchor-position-1/#position-try) rule.
12#[derive(Debug, PartialEq, Clone)]
13#[cfg_attr(feature = "visitor", derive(Visit))]
14#[cfg_attr(feature = "into_owned", derive(rspack_lightningcss_static_self::IntoOwned))]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
17pub struct PositionTryRule<'i> {
18  /// The name of the position-try fallback.
19  #[cfg_attr(feature = "serde", serde(borrow))]
20  pub name: DashedIdent<'i>,
21  /// Declarations in the `@position-try` rule.
22  pub declarations: DeclarationBlock<'i>,
23  /// The location of the rule in the source file.
24  #[cfg_attr(feature = "visitor", skip_visit)]
25  pub loc: Location,
26}
27
28impl<'i> ToCss for PositionTryRule<'i> {
29  fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
30    dest.add_mapping(self.loc);
31    dest.write_str("@position-try ")?;
32    self.name.to_css(dest)?;
33    self.declarations.to_css_block(dest)
34  }
35}