@@ -5,7 +5,7 @@ import { isSupportsBrowserhack, isMediaBrowserhack } from './atrules/atrules.js'
5
5
import { getCombinators , getComplexity , isAccessibility , isPrefixed , hasPseudoClass } from './selectors/utils.js'
6
6
import { colorFunctions , colorKeywords , namedColors , systemColors } from './values/colors.js'
7
7
import { destructure , isSystemFont } from './values/destructure-font-shorthand.js'
8
- import { isValueKeyword , keywords } from './values/values.js'
8
+ import { isValueKeyword , keywords , isValueReset } from './values/values.js'
9
9
import { analyzeAnimation } from './values/animations.js'
10
10
import { isValuePrefixed } from './values/vendor-prefix.js'
11
11
import { ContextCollection } from './context-collection.js'
@@ -193,6 +193,7 @@ export function analyze(css, options = {}) {
193
193
let gradients = new Collection ( useLocations )
194
194
let valueKeywords = new Collection ( useLocations )
195
195
let borderRadiuses = new ContextCollection ( useLocations )
196
+ let resets = new Collection ( useLocations )
196
197
197
198
walk ( ast , function ( node ) {
198
199
switch ( node . type ) {
@@ -452,6 +453,7 @@ export function analyze(css, options = {}) {
452
453
break
453
454
}
454
455
456
+ /** @type {import('css-tree').Declaration } */
455
457
let declaration = this . declaration
456
458
let { property, important } = declaration
457
459
let complexity = 1
@@ -482,10 +484,31 @@ export function analyze(css, options = {}) {
482
484
483
485
// Process properties first that don't have colors,
484
486
// so we can avoid further walking them;
485
- if ( isProperty ( 'z-index' , property ) ) {
487
+ if (
488
+ isProperty ( 'margin' , property ) ||
489
+ isProperty ( 'margin-block' , property ) ||
490
+ isProperty ( 'margin-inline' , property ) ||
491
+ isProperty ( 'margin-top' , property ) ||
492
+ isProperty ( 'margin-right' , property ) ||
493
+ isProperty ( 'margin-bottom' , property ) ||
494
+ isProperty ( 'margin-left' , property ) ||
495
+ isProperty ( 'padding' , property ) ||
496
+ isProperty ( 'padding-block' , property ) ||
497
+ isProperty ( 'padding-inline' , property ) ||
498
+ isProperty ( 'padding-top' , property ) ||
499
+ isProperty ( 'padding-right' , property ) ||
500
+ isProperty ( 'padding-bottom' , property ) ||
501
+ isProperty ( 'padding-left' , property )
502
+ ) {
503
+ if ( isValueReset ( node ) ) {
504
+ resets . p ( property , declaration . loc )
505
+ }
506
+ }
507
+ else if ( isProperty ( 'z-index' , property ) ) {
486
508
zindex . p ( stringifyNode ( node ) , loc )
487
509
return this . skip
488
- } else if ( isProperty ( 'font' , property ) ) {
510
+ }
511
+ else if ( isProperty ( 'font' , property ) ) {
489
512
if ( isSystemFont ( node ) ) return
490
513
491
514
let { font_size, line_height, font_family } = destructure ( node , stringifyNode , function ( item ) {
@@ -507,48 +530,58 @@ export function analyze(css, options = {}) {
507
530
}
508
531
509
532
break
510
- } else if ( isProperty ( 'font-size' , property ) ) {
533
+ }
534
+ else if ( isProperty ( 'font-size' , property ) ) {
511
535
if ( ! isSystemFont ( node ) ) {
512
536
fontSizes . p ( stringifyNode ( node ) , loc )
513
537
}
514
538
break
515
- } else if ( isProperty ( 'font-family' , property ) ) {
539
+ }
540
+ else if ( isProperty ( 'font-family' , property ) ) {
516
541
if ( ! isSystemFont ( node ) ) {
517
542
fontFamilies . p ( stringifyNode ( node ) , loc )
518
543
}
519
544
break
520
- } else if ( isProperty ( 'line-height' , property ) ) {
545
+ }
546
+ else if ( isProperty ( 'line-height' , property ) ) {
521
547
lineHeights . p ( stringifyNode ( node ) , loc )
522
- } else if ( isProperty ( 'transition' , property ) || isProperty ( 'animation' , property ) ) {
548
+ }
549
+ else if ( isProperty ( 'transition' , property ) || isProperty ( 'animation' , property ) ) {
523
550
analyzeAnimation ( children , function ( item ) {
524
551
if ( item . type === 'fn' ) {
525
552
timingFunctions . p ( stringifyNode ( item . value ) , loc )
526
- } else if ( item . type === 'duration' ) {
553
+ }
554
+ else if ( item . type === 'duration' ) {
527
555
durations . p ( stringifyNode ( item . value ) , loc )
528
- } else if ( item . type === 'keyword' ) {
556
+ }
557
+ else if ( item . type === 'keyword' ) {
529
558
valueKeywords . p ( stringifyNode ( item . value ) , loc )
530
559
}
531
560
} )
532
561
break
533
- } else if ( isProperty ( 'animation-duration' , property ) || isProperty ( 'transition-duration' , property ) ) {
562
+ }
563
+ else if ( isProperty ( 'animation-duration' , property ) || isProperty ( 'transition-duration' , property ) ) {
534
564
if ( children && children . size > 1 ) {
535
565
children . forEach ( child => {
536
566
if ( child . type !== Operator ) {
537
567
durations . p ( stringifyNode ( child ) , loc )
538
568
}
539
569
} )
540
- } else {
570
+ }
571
+ else {
541
572
durations . p ( stringifyNode ( node ) , loc )
542
573
}
543
574
break
544
- } else if ( isProperty ( 'transition-timing-function' , property ) || isProperty ( 'animation-timing-function' , property ) ) {
575
+ }
576
+ else if ( isProperty ( 'transition-timing-function' , property ) || isProperty ( 'animation-timing-function' , property ) ) {
545
577
if ( children && children . size > 1 ) {
546
578
children . forEach ( child => {
547
579
if ( child . type !== Operator ) {
548
580
timingFunctions . p ( stringifyNode ( child ) , loc )
549
581
}
550
582
} )
551
- } else {
583
+ }
584
+ else {
552
585
timingFunctions . p ( stringifyNode ( node ) , loc )
553
586
}
554
587
break
@@ -568,12 +601,14 @@ export function analyze(css, options = {}) {
568
601
borderRadiuses . push ( stringifyNode ( node ) , property , loc )
569
602
}
570
603
break
571
- } else if ( isProperty ( 'text-shadow' , property ) ) {
604
+ }
605
+ else if ( isProperty ( 'text-shadow' , property ) ) {
572
606
if ( ! isValueKeyword ( node ) ) {
573
607
textShadows . p ( stringifyNode ( node ) , loc )
574
608
}
575
609
// no break here: potentially contains colors
576
- } else if ( isProperty ( 'box-shadow' , property ) ) {
610
+ }
611
+ else if ( isProperty ( 'box-shadow' , property ) ) {
577
612
if ( ! isValueKeyword ( node ) ) {
578
613
boxShadows . p ( stringifyNode ( node ) , loc )
579
614
}
@@ -936,6 +971,7 @@ export function analyze(css, options = {}) {
936
971
units : units . count ( ) ,
937
972
complexity : valueComplexity ,
938
973
keywords : valueKeywords . c ( ) ,
974
+ resets : resets . c ( ) ,
939
975
} ,
940
976
__meta__ : {
941
977
parseTime : startAnalysis - startParse ,
0 commit comments