@@ -347,24 +347,20 @@ function localizeDeclarationValues(localize, declaration, context) {
347
347
declaration . value = valueNodes . toString ( ) ;
348
348
}
349
349
350
- function localizeDeclaration ( declaration , context ) {
351
- const isAnimation = / a n i m a t i o n $ / i. test ( declaration . prop ) ;
352
-
353
- if ( isAnimation ) {
354
- // letter
355
- // An uppercase letter or a lowercase letter.
356
- //
357
- // ident-start code point
358
- // A letter, a non-ASCII code point, or U+005F LOW LINE (_).
359
- //
360
- // ident code point
361
- // An ident-start code point, a digit, or U+002D HYPHEN-MINUS (-).
362
-
363
- // We don't validate `hex digits`, because we don't need it, it is work of linters.
364
- const validIdent =
365
- / ^ - ? ( [ a - z \u0080 - \uFFFF _ ] | ( \\ [ ^ \r \n \f ] ) | - (? ! [ 0 - 9 ] ) ) ( ( \\ [ ^ \r \n \f ] ) | [ a - z \u0080 - \uFFFF _ 0 - 9 - ] ) * $ / i;
366
-
367
- /*
350
+ // letter
351
+ // An uppercase letter or a lowercase letter.
352
+ //
353
+ // ident-start code point
354
+ // A letter, a non-ASCII code point, or U+005F LOW LINE (_).
355
+ //
356
+ // ident code point
357
+ // An ident-start code point, a digit, or U+002D HYPHEN-MINUS (-).
358
+
359
+ // We don't validate `hex digits`, because we don't need it, it is work of linters.
360
+ const validIdent =
361
+ / ^ - ? ( [ a - z \u0080 - \uFFFF _ ] | ( \\ [ ^ \r \n \f ] ) | - (? ! [ 0 - 9 ] ) ) ( ( \\ [ ^ \r \n \f ] ) | [ a - z \u0080 - \uFFFF _ 0 - 9 - ] ) * $ / i;
362
+
363
+ /*
368
364
The spec defines some keywords that you can use to describe properties such as the timing
369
365
function. These are still valid animation names, so as long as there is a property that accepts
370
366
a keyword, it is given priority. Only when all the properties that can take a keyword are
@@ -375,48 +371,72 @@ function localizeDeclaration(declaration, context) {
375
371
The animation will repeat an infinite number of times from the first argument, and will have an
376
372
animation name of infinite from the second.
377
373
*/
378
- const animationKeywords = {
379
- // animation-direction
380
- $normal : 1 ,
381
- $reverse : 1 ,
382
- $alternate : 1 ,
383
- "$alternate-reverse" : 1 ,
384
- // animation-fill-mode
385
- $forwards : 1 ,
386
- $backwards : 1 ,
387
- $both : 1 ,
388
- // animation-iteration-count
389
- $infinite : 1 ,
390
- // animation-play-state
391
- $paused : 1 ,
392
- $running : 1 ,
393
- // animation-timing-function
394
- $ease : 1 ,
395
- "$ease-in" : 1 ,
396
- "$ease-out" : 1 ,
397
- "$ease-in-out" : 1 ,
398
- $linear : 1 ,
399
- "$step-end" : 1 ,
400
- "$step-start" : 1 ,
401
- // Special
402
- $none : Infinity , // No matter how many times you write none, it will never be an animation name
403
- // Global values
404
- $initial : Infinity ,
405
- $inherit : Infinity ,
406
- $unset : Infinity ,
407
- $revert : Infinity ,
408
- "$revert-layer" : Infinity ,
409
- } ;
374
+ const animationKeywords = {
375
+ // animation-direction
376
+ $normal : 1 ,
377
+ $reverse : 1 ,
378
+ $alternate : 1 ,
379
+ "$alternate-reverse" : 1 ,
380
+ // animation-fill-mode
381
+ $forwards : 1 ,
382
+ $backwards : 1 ,
383
+ $both : 1 ,
384
+ // animation-iteration-count
385
+ $infinite : 1 ,
386
+ // animation-play-state
387
+ $paused : 1 ,
388
+ $running : 1 ,
389
+ // animation-timing-function
390
+ $ease : 1 ,
391
+ "$ease-in" : 1 ,
392
+ "$ease-out" : 1 ,
393
+ "$ease-in-out" : 1 ,
394
+ $linear : 1 ,
395
+ "$step-end" : 1 ,
396
+ "$step-start" : 1 ,
397
+ // Special
398
+ $none : Infinity , // No matter how many times you write none, it will never be an animation name
399
+ // Global values
400
+ $initial : Infinity ,
401
+ $inherit : Infinity ,
402
+ $unset : Infinity ,
403
+ $revert : Infinity ,
404
+ "$revert-layer" : Infinity ,
405
+ } ;
406
+
407
+ function localizeDeclaration ( declaration , context ) {
408
+ const isAnimation = / a n i m a t i o n ( - n a m e ) ? $ / i. test ( declaration . prop ) ;
409
+
410
+ if ( isAnimation ) {
410
411
let parsedAnimationKeywords = { } ;
411
412
const valueNodes = valueParser ( declaration . value ) . walk ( ( node ) => {
412
413
// If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh.
413
414
if ( node . type === "div" ) {
414
415
parsedAnimationKeywords = { } ;
415
416
416
417
return ;
417
- }
418
- // Do not handle nested functions
419
- else if ( node . type === "function" ) {
418
+ } else if (
419
+ node . type === "function" &&
420
+ node . value . toLowerCase ( ) === "local" &&
421
+ node . nodes . length === 1
422
+ ) {
423
+ node . type = "word" ;
424
+ node . value = node . nodes [ 0 ] . value ;
425
+
426
+ return localizeDeclNode ( node , {
427
+ options : context . options ,
428
+ global : context . global ,
429
+ localizeNextItem : true ,
430
+ localAliasMap : context . localAliasMap ,
431
+ } ) ;
432
+ } else if ( node . type === "function" ) {
433
+ // replace `animation: global(example)` with `animation-name: example`
434
+ if ( node . value . toLowerCase ( ) === "global" && node . nodes . length === 1 ) {
435
+ node . type = "word" ;
436
+ node . value = node . nodes [ 0 ] . value ;
437
+ }
438
+
439
+ // Do not handle nested functions
420
440
return false ;
421
441
}
422
442
// Ignore all except word
@@ -443,30 +463,20 @@ function localizeDeclaration(declaration, context) {
443
463
}
444
464
}
445
465
446
- const subContext = {
466
+ return localizeDeclNode ( node , {
447
467
options : context . options ,
448
468
global : context . global ,
449
469
localizeNextItem : shouldParseAnimationName && ! context . global ,
450
470
localAliasMap : context . localAliasMap ,
451
- } ;
452
-
453
- return localizeDeclNode ( node , subContext ) ;
471
+ } ) ;
454
472
} ) ;
455
473
456
474
declaration . value = valueNodes . toString ( ) ;
457
475
458
476
return ;
459
477
}
460
478
461
- const isAnimationName = / a n i m a t i o n ( - n a m e ) ? $ / i. test ( declaration . prop ) ;
462
-
463
- if ( isAnimationName ) {
464
- return localizeDeclarationValues ( true , declaration , context ) ;
465
- }
466
-
467
- const hasUrl = / u r l \( / i. test ( declaration . value ) ;
468
-
469
- if ( hasUrl ) {
479
+ if ( / u r l \( / i. test ( declaration . value ) ) {
470
480
return localizeDeclarationValues ( false , declaration , context ) ;
471
481
}
472
482
}
0 commit comments