|
1 | 1 | //! CSS properties related to keyframe animations. |
2 | 2 |
|
| 3 | +use std::borrow::Cow; |
| 4 | + |
3 | 5 | use crate::context::PropertyHandlerContext; |
4 | 6 | use crate::declaration::{DeclarationBlock, DeclarationList}; |
5 | 7 | use crate::error::{ParserError, PrinterError}; |
6 | 8 | use crate::macros::*; |
7 | 9 | use crate::prefixes::Feature; |
8 | 10 | use crate::printer::Printer; |
9 | | -use crate::properties::{Property, PropertyId, VendorPrefix}; |
| 11 | +use crate::properties::{Property, PropertyId, TokenOrValue, VendorPrefix}; |
10 | 12 | use crate::traits::{Parse, PropertyHandler, Shorthand, ToCss, Zero}; |
11 | 13 | use crate::values::number::CSSNumber; |
12 | 14 | use crate::values::string::CowArcStr; |
@@ -346,8 +348,6 @@ impl<'i> PropertyHandler<'i> for AnimationHandler<'i> { |
346 | 348 | dest: &mut DeclarationList<'i>, |
347 | 349 | context: &mut PropertyHandlerContext<'i, '_>, |
348 | 350 | ) -> bool { |
349 | | - use Property::*; |
350 | | - |
351 | 351 | macro_rules! maybe_flush { |
352 | 352 | ($prop: ident, $val: expr, $vp: ident) => {{ |
353 | 353 | // If two vendor prefixes for the same property have different |
@@ -376,15 +376,15 @@ impl<'i> PropertyHandler<'i> for AnimationHandler<'i> { |
376 | 376 | } |
377 | 377 |
|
378 | 378 | match property { |
379 | | - AnimationName(val, vp) => property!(names, val, vp), |
380 | | - AnimationDuration(val, vp) => property!(durations, val, vp), |
381 | | - AnimationTimingFunction(val, vp) => property!(timing_functions, val, vp), |
382 | | - AnimationIterationCount(val, vp) => property!(iteration_counts, val, vp), |
383 | | - AnimationDirection(val, vp) => property!(directions, val, vp), |
384 | | - AnimationPlayState(val, vp) => property!(play_states, val, vp), |
385 | | - AnimationDelay(val, vp) => property!(delays, val, vp), |
386 | | - AnimationFillMode(val, vp) => property!(fill_modes, val, vp), |
387 | | - Animation(val, vp) => { |
| 379 | + Property::AnimationName(val, vp) => property!(names, val, vp), |
| 380 | + Property::AnimationDuration(val, vp) => property!(durations, val, vp), |
| 381 | + Property::AnimationTimingFunction(val, vp) => property!(timing_functions, val, vp), |
| 382 | + Property::AnimationIterationCount(val, vp) => property!(iteration_counts, val, vp), |
| 383 | + Property::AnimationDirection(val, vp) => property!(directions, val, vp), |
| 384 | + Property::AnimationPlayState(val, vp) => property!(play_states, val, vp), |
| 385 | + Property::AnimationDelay(val, vp) => property!(delays, val, vp), |
| 386 | + Property::AnimationFillMode(val, vp) => property!(fill_modes, val, vp), |
| 387 | + Property::Animation(val, vp) => { |
388 | 388 | let names = val.iter().map(|b| b.name.clone()).collect(); |
389 | 389 | maybe_flush!(names, &names, vp); |
390 | 390 |
|
@@ -418,7 +418,33 @@ impl<'i> PropertyHandler<'i> for AnimationHandler<'i> { |
418 | 418 | property!(delays, &delays, vp); |
419 | 419 | property!(fill_modes, &fill_modes, vp); |
420 | 420 | } |
421 | | - Unparsed(val) if is_animation_property(&val.property_id) => { |
| 421 | + Property::Unparsed(val) if is_animation_property(&val.property_id) => { |
| 422 | + let mut val = Cow::Borrowed(val); |
| 423 | + if matches!(val.property_id, PropertyId::Animation(_)) { |
| 424 | + use crate::properties::custom::Token; |
| 425 | + |
| 426 | + // Find an identifier that isn't a keyword and replace it with an |
| 427 | + // AnimationName token so it is scoped in CSS modules. |
| 428 | + for token in &mut val.to_mut().value.0 { |
| 429 | + match token { |
| 430 | + TokenOrValue::Token(Token::Ident(id)) => { |
| 431 | + if AnimationDirection::parse_string(&id).is_err() |
| 432 | + && AnimationPlayState::parse_string(&id).is_err() |
| 433 | + && AnimationFillMode::parse_string(&id).is_err() |
| 434 | + && !EasingFunction::is_ident(&id) |
| 435 | + && id.as_ref() != "infinite" |
| 436 | + { |
| 437 | + *token = TokenOrValue::AnimationName(AnimationName::Ident(CustomIdent(id.clone()))); |
| 438 | + } |
| 439 | + } |
| 440 | + TokenOrValue::Token(Token::String(s)) => { |
| 441 | + *token = TokenOrValue::AnimationName(AnimationName::String(s.clone())); |
| 442 | + } |
| 443 | + _ => {} |
| 444 | + } |
| 445 | + } |
| 446 | + } |
| 447 | + |
422 | 448 | self.flush(dest, context); |
423 | 449 | dest.push(Property::Unparsed( |
424 | 450 | val.get_prefixed(context.targets, Feature::Animation), |
|
0 commit comments