@@ -227,6 +227,7 @@ class CSSStyleDeclaration {
227
227
} ) ;
228
228
for ( const [ property , item ] of parsedProperties ) {
229
229
const { priority, value } = item ;
230
+ this . _priorities . set ( property , priority ) ;
230
231
this . setProperty ( property , value , priority ) ;
231
232
}
232
233
}
@@ -453,19 +454,27 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
453
454
enumerable : false
454
455
} ,
455
456
457
+ // TODO: Working, but check later if this is really the right way to do.
456
458
_shorthandSetter : {
457
459
/**
458
460
* @param {string } property
459
461
* @param {string } val
462
+ * @param {string } prior
460
463
* @param {object } shorthandFor
461
464
*/
462
- value ( property , val , shorthandFor ) {
465
+ value ( property , val , prior , shorthandFor ) {
463
466
const obj = parseShorthand ( val , shorthandFor , {
464
467
globalObject : this . _global
465
468
} ) ;
466
469
if ( ! obj ) {
467
470
return ;
468
471
}
472
+ let priority = "" ;
473
+ if ( typeof prior === "string" ) {
474
+ priority = prior ;
475
+ } else {
476
+ priority = this . _priorities . get ( property ) ?? "" ;
477
+ }
469
478
for ( const subprop of Object . keys ( obj ) ) {
470
479
// In case subprop is an implicit property, this will clear *its*
471
480
// subpropertiesX.
@@ -476,7 +485,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
476
485
this . removeProperty ( subprop ) ;
477
486
// Don't add in empty properties.
478
487
if ( obj [ subprop ] !== "" ) {
479
- this . _values . set ( subprop , obj [ subprop ] ) ;
488
+ this . _values . set ( subprop , obj [ subprop ] , priority ) ;
480
489
}
481
490
}
482
491
for ( const [ subprop ] of shorthandFor ) {
@@ -492,9 +501,8 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
492
501
this . removeProperty ( property ) ;
493
502
const calculated = this . _shorthandGetter ( property , shorthandFor ) ;
494
503
if ( calculated !== "" ) {
495
- this . _setProperty ( property , calculated ) ;
504
+ this . _setProperty ( property , calculated , priority ) ;
496
505
}
497
- return obj ;
498
506
} ,
499
507
enumerable : false
500
508
} ,
@@ -503,8 +511,9 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
503
511
/**
504
512
* @param {string } prop
505
513
* @param {Array|string } val
514
+ * @param {string } prior
506
515
*/
507
- value ( prop , val ) {
516
+ value ( prop , val , prior ) {
508
517
if ( ! shorthandProperties . has ( prop ) ) {
509
518
return ;
510
519
}
@@ -516,24 +525,33 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
516
525
} else {
517
526
return ;
518
527
}
519
- const priority = this . _priorities . get ( prop ) ?? "" ;
520
- const { shorthandFor } = shorthandProperties . get ( prop ) ;
528
+ let priority = "" ;
529
+ if ( typeof prior === "string" ) {
530
+ priority = prior ;
531
+ } else {
532
+ priority = this . _priorities . get ( prop ) ?? "" ;
533
+ }
534
+ const { position, shorthandFor } = shorthandProperties . get ( prop ) ;
521
535
let hasPriority = false ;
522
- for ( const [ longhandProperty , { position } ] of shorthandFor ) {
523
- const longhandValue = getPositionValue ( shorthandValues , position ) ;
524
- const longhandPriority = this . _priorities . get ( longhandProperty ) ?? "" ;
536
+ for ( const [ longhandProperty , longhandItem ] of shorthandFor ) {
537
+ const { position : longhandPosition } = longhandItem ;
538
+ const longhandValue = getPositionValue ( shorthandValues , longhandPosition ) ;
525
539
if ( priority ) {
526
- this . _setProperty ( longhandProperty , longhandValue , longhandPriority ) ;
527
- } else if ( longhandPriority ) {
528
- hasPriority = true ;
540
+ this . _setProperty ( longhandProperty , longhandValue , priority ) ;
529
541
} else {
530
- this . _setProperty ( longhandProperty , longhandValue , longhandPriority ) ;
542
+ const longhandPriority = this . _priorities . get ( longhandProperty ) ?? "" ;
543
+ if ( longhandPriority ) {
544
+ hasPriority = true ;
545
+ } else {
546
+ this . _setProperty ( longhandProperty , longhandValue , priority ) ;
547
+ }
531
548
}
532
549
}
533
550
if ( hasPriority ) {
534
551
this . removeProperty ( prop ) ;
535
552
} else {
536
- this . _setProperty ( prop , shorthandValues . join ( " " ) , priority ) ;
553
+ const shorthandValue = getPositionValue ( shorthandValues , position ) ;
554
+ this . _setProperty ( prop , shorthandValue , priority ) ;
537
555
}
538
556
}
539
557
} ,
@@ -542,15 +560,21 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
542
560
/**
543
561
* @param {string } prop
544
562
* @param {string } val
563
+ * @param {string } prior
545
564
*/
546
- value ( prop , val ) {
565
+ value ( prop , val , prior ) {
547
566
const { logicalPropertyGroup : shorthandProperty } = implementedProperties . get ( prop ) ?? { } ;
548
567
if ( ! shorthandProperty || ! shorthandProperties . has ( shorthandProperty ) ) {
549
568
return ;
550
569
}
551
570
const shorthandPriority = this . _priorities . get ( shorthandProperty ) ;
552
- const priority = this . _priorities . get ( prop ) ?? "" ;
553
571
this . _setProperty ( shorthandProperty , "" ) ;
572
+ let priority = "" ;
573
+ if ( typeof prior === "string" ) {
574
+ priority = prior ;
575
+ } else {
576
+ priority = this . _priorities . get ( prop ) ?? "" ;
577
+ }
554
578
if ( shorthandPriority && priority ) {
555
579
this . _setProperty ( prop , val ) ;
556
580
} else {
@@ -580,18 +604,28 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
580
604
/**
581
605
* @param {string } prop
582
606
* @param {object|Array|string } val
607
+ * @param {string } prior
583
608
*/
584
- value ( prop , val ) {
609
+ value ( prop , val , prior ) {
585
610
const properties = new Map ( ) ;
586
611
if ( prop === "border" ) {
587
- const priority = this . _priorities . get ( prop ) ?? "" ;
612
+ let priority = "" ;
613
+ if ( typeof prior === "string" ) {
614
+ priority = prior ;
615
+ } else {
616
+ priority = this . _priorities . get ( prop ) ?? "" ;
617
+ }
588
618
properties . set ( prop , { propery : prop , value : val , priority } ) ;
589
619
} else {
590
620
for ( let i = 0 ; i < this . _length ; i ++ ) {
591
621
const property = this [ i ] ;
592
622
if ( borderProperties . has ( property ) ) {
593
623
const value = this . getPropertyValue ( property ) ;
594
- const priority = this . _priorities . get ( property ) ?? "" ;
624
+ const longhandPriority = this . _priorities . get ( property ) ?? "" ;
625
+ let priority = longhandPriority ;
626
+ if ( prop === property && typeof prior === "string" ) {
627
+ priority = prior ;
628
+ }
595
629
properties . set ( property , { property, value, priority } ) ;
596
630
}
597
631
}
@@ -612,7 +646,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
612
646
Object . defineProperties ( CSSStyleDeclaration . prototype , generatedProperties ) ;
613
647
614
648
// Additional properties
615
- [ ...allProperties , ...allExtraProperties ] . forEach ( function ( property ) {
649
+ [ ...allProperties , ...allExtraProperties ] . forEach ( ( property ) => {
616
650
if ( ! implementedProperties . has ( property ) ) {
617
651
const declaration = getPropertyDescriptor ( property ) ;
618
652
Object . defineProperty ( CSSStyleDeclaration . prototype , property , declaration ) ;
0 commit comments