-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! The `@scope` rule. | ||
use super::Location; | ||
use super::{CssRuleList, MinifyContext}; | ||
use crate::error::{MinifyError, PrinterError}; | ||
use crate::parser::DefaultAtRule; | ||
use crate::printer::Printer; | ||
use crate::traits::ToCss; | ||
#[cfg(feature = "visitor")] | ||
use crate::visitor::Visit; | ||
|
||
/// A [@scope](https://drafts.csswg.org/css-cascade-6/#scope-atrule) rule. | ||
/// | ||
/// @scope (<scope-start>) [to (<scope-end>)]? { | ||
/// <stylesheet> | ||
/// } | ||
#[derive(Debug, PartialEq, Clone)] | ||
#[cfg_attr(feature = "visitor", derive(Visit))] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] | ||
pub struct ScopeRule<'i, R = DefaultAtRule> { | ||
// TODO: support (<scope-start>) [to (<scope-end>)]? | ||
/// Nested rules within the `@scope` rule. | ||
#[cfg_attr(feature = "serde", serde(borrow))] | ||
pub rules: CssRuleList<'i, R>, | ||
/// The location of the rule in the source file. | ||
#[cfg_attr(feature = "visitor", skip_visit)] | ||
pub loc: Location, | ||
} | ||
|
||
impl<'i, T> ScopeRule<'i, T> { | ||
pub(crate) fn minify(&mut self, context: &mut MinifyContext<'_, 'i>) -> Result<(), MinifyError> { | ||
self.rules.minify(context, false) | ||
} | ||
} | ||
|
||
impl<'i, T: ToCss> ToCss for ScopeRule<'i, T> { | ||
fn to_css<W>(&self, dest: &mut Printer<W>) -> Result<(), PrinterError> | ||
where | ||
W: std::fmt::Write, | ||
{ | ||
#[cfg(feature = "sourcemap")] | ||
dest.add_mapping(self.loc); | ||
dest.write_str("@scope")?; | ||
dest.whitespace()?; | ||
dest.write_char('{')?; | ||
dest.indent(); | ||
dest.newline()?; | ||
self.rules.to_css(dest)?; | ||
dest.dedent(); | ||
dest.newline()?; | ||
dest.write_char('}') | ||
} | ||
} |