Skip to main content

rspack_lightningcss/rules/
counter_style.rs

1//! The `@counter-style` rule.
2
3use super::Location;
4use crate::declaration::DeclarationBlock;
5use crate::error::PrinterError;
6use crate::traits::ToCss;
7use crate::values::ident::CustomIdent;
8#[cfg(feature = "visitor")]
9use crate::visitor::Visit;
10
11/// A [@counter-style](https://drafts.csswg.org/css-counter-styles/#the-counter-style-rule) 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 CounterStyleRule<'i> {
18  /// The name of the counter style to declare.
19  #[cfg_attr(feature = "serde", serde(borrow))]
20  pub name: CustomIdent<'i>,
21  // TODO: eventually parse these properties
22  /// Declarations in the `@counter-style` rule.
23  pub declarations: DeclarationBlock<'i>,
24  /// The location of the rule in the source file.
25  #[cfg_attr(feature = "visitor", skip_visit)]
26  pub loc: Location,
27}
28
29impl<'i> ToCss for CounterStyleRule<'i> {
30  fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
31    #[cfg(feature = "custom_sourcemap")]
32    dest.add_mapping(self.loc);
33    dest.write_str("@counter-style ")?;
34    self.name.to_css(dest)?;
35    self.declarations.to_css_block(dest)
36  }
37}