From 8390e73dbd0de4630cb2f9781ca97f352e8565ce Mon Sep 17 00:00:00 2001 From: Daniel Joyce Date: Thu, 18 Jan 2024 20:38:37 -0800 Subject: [PATCH] When rendering declarations of KeyFrames disable minification so that KeyFrame transformations are not broken * Added Todo to TransformList::to_css as it needs to be refactored and we need more context. * 4 Tests are still broken --- src/properties/transform.rs | 4 ++++ src/rules/keyframes.rs | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/properties/transform.rs b/src/properties/transform.rs index 87699837..1dc2d044 100644 --- a/src/properties/transform.rs +++ b/src/properties/transform.rs @@ -57,6 +57,10 @@ impl ToCss for TransformList { return Ok(()); } + // TODO: Decouple minification of representation from minifaction of white space. + // We don't have access to context here, so we can't tell when to minify this + // vs when we shouldn't ( inside a KeyFrame decl ). + // Minification in to_css should be restricted to white space, if dest.minify { // Combine transforms into a single matrix. if let Some(matrix) = self.to_matrix() { diff --git a/src/rules/keyframes.rs b/src/rules/keyframes.rs index a9489f30..7b9222a3 100644 --- a/src/rules/keyframes.rs +++ b/src/rules/keyframes.rs @@ -355,7 +355,11 @@ impl<'i> ToCss for Keyframe<'i> { selector.to_css(dest)?; } - self.declarations.to_css_block(dest) + // We can't safely minify declarations of keyframes without doing more analysis + dest.minify = false; + let result = self.declarations.to_css_block(dest); + dest.minify = true; + result } } @@ -387,9 +391,18 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser { ) -> Result>> { // For now there are no options that apply within @keyframes let options = ParserOptions::default(); + + let mut declaration_block = DeclarationBlock::parse(input, &options)?; + + // Per https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes#!important_in_a_keyframe + // !important is ignored in a declaration block, so we strip it here. + declaration_block + .declarations + .append(&mut declaration_block.important_declarations); + Ok(Keyframe { selectors, - declarations: DeclarationBlock::parse(input, &options)?, + declarations: declaration_block, }) } }