Skip to content

Commit 336bef6

Browse files
committed
Fix normalize.js
1 parent d399c7a commit 336bef6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1758
-795
lines changed

lib/CSSStyleDeclaration.js

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class CSSStyleDeclaration {
227227
});
228228
for (const [property, item] of parsedProperties) {
229229
const { priority, value } = item;
230+
this._priorities.set(property, priority);
230231
this.setProperty(property, value, priority);
231232
}
232233
}
@@ -453,19 +454,27 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
453454
enumerable: false
454455
},
455456

457+
// TODO: Working, but check later if this is really the right way to do.
456458
_shorthandSetter: {
457459
/**
458460
* @param {string} property
459461
* @param {string} val
462+
* @param {string} prior
460463
* @param {object} shorthandFor
461464
*/
462-
value(property, val, shorthandFor) {
465+
value(property, val, prior, shorthandFor) {
463466
const obj = parseShorthand(val, shorthandFor, {
464467
globalObject: this._global
465468
});
466469
if (!obj) {
467470
return;
468471
}
472+
let priority = "";
473+
if (typeof prior === "string") {
474+
priority = prior;
475+
} else {
476+
priority = this._priorities.get(property) ?? "";
477+
}
469478
for (const subprop of Object.keys(obj)) {
470479
// In case subprop is an implicit property, this will clear *its*
471480
// subpropertiesX.
@@ -476,7 +485,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
476485
this.removeProperty(subprop);
477486
// Don't add in empty properties.
478487
if (obj[subprop] !== "") {
479-
this._values.set(subprop, obj[subprop]);
488+
this._values.set(subprop, obj[subprop], priority);
480489
}
481490
}
482491
for (const [subprop] of shorthandFor) {
@@ -492,9 +501,8 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
492501
this.removeProperty(property);
493502
const calculated = this._shorthandGetter(property, shorthandFor);
494503
if (calculated !== "") {
495-
this._setProperty(property, calculated);
504+
this._setProperty(property, calculated, priority);
496505
}
497-
return obj;
498506
},
499507
enumerable: false
500508
},
@@ -503,8 +511,9 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
503511
/**
504512
* @param {string} prop
505513
* @param {Array|string} val
514+
* @param {string} prior
506515
*/
507-
value(prop, val) {
516+
value(prop, val, prior) {
508517
if (!shorthandProperties.has(prop)) {
509518
return;
510519
}
@@ -516,24 +525,33 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
516525
} else {
517526
return;
518527
}
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);
521535
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);
525539
if (priority) {
526-
this._setProperty(longhandProperty, longhandValue, longhandPriority);
527-
} else if (longhandPriority) {
528-
hasPriority = true;
540+
this._setProperty(longhandProperty, longhandValue, priority);
529541
} 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+
}
531548
}
532549
}
533550
if (hasPriority) {
534551
this.removeProperty(prop);
535552
} else {
536-
this._setProperty(prop, shorthandValues.join(" "), priority);
553+
const shorthandValue = getPositionValue(shorthandValues, position);
554+
this._setProperty(prop, shorthandValue, priority);
537555
}
538556
}
539557
},
@@ -542,15 +560,21 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
542560
/**
543561
* @param {string} prop
544562
* @param {string} val
563+
* @param {string} prior
545564
*/
546-
value(prop, val) {
565+
value(prop, val, prior) {
547566
const { logicalPropertyGroup: shorthandProperty } = implementedProperties.get(prop) ?? {};
548567
if (!shorthandProperty || !shorthandProperties.has(shorthandProperty)) {
549568
return;
550569
}
551570
const shorthandPriority = this._priorities.get(shorthandProperty);
552-
const priority = this._priorities.get(prop) ?? "";
553571
this._setProperty(shorthandProperty, "");
572+
let priority = "";
573+
if (typeof prior === "string") {
574+
priority = prior;
575+
} else {
576+
priority = this._priorities.get(prop) ?? "";
577+
}
554578
if (shorthandPriority && priority) {
555579
this._setProperty(prop, val);
556580
} else {
@@ -580,18 +604,28 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
580604
/**
581605
* @param {string} prop
582606
* @param {object|Array|string} val
607+
* @param {string} prior
583608
*/
584-
value(prop, val) {
609+
value(prop, val, prior) {
585610
const properties = new Map();
586611
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+
}
588618
properties.set(prop, { propery: prop, value: val, priority });
589619
} else {
590620
for (let i = 0; i < this._length; i++) {
591621
const property = this[i];
592622
if (borderProperties.has(property)) {
593623
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+
}
595629
properties.set(property, { property, value, priority });
596630
}
597631
}
@@ -612,7 +646,7 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
612646
Object.defineProperties(CSSStyleDeclaration.prototype, generatedProperties);
613647

614648
// Additional properties
615-
[...allProperties, ...allExtraProperties].forEach(function (property) {
649+
[...allProperties, ...allExtraProperties].forEach((property) => {
616650
if (!implementedProperties.has(property)) {
617651
const declaration = getPropertyDescriptor(property);
618652
Object.defineProperty(CSSStyleDeclaration.prototype, property, declaration);

0 commit comments

Comments
 (0)