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