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