Skip to content

Commit 1015f63

Browse files
committed
Remove properties from CSSStyleDeclaration
1 parent 82ae6fd commit 1015f63

File tree

4 files changed

+156
-1538
lines changed

4 files changed

+156
-1538
lines changed

lib/CSSStyleDeclaration.js

Lines changed: 44 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"use strict";
22

33
const allProperties = require("./generated/allProperties");
4-
const implementedProperties = require("./generated/implementedProperties");
5-
const generatedProperties = require("./generated/properties");
64
const {
75
borderProperties,
86
getPositionValue,
@@ -19,8 +17,6 @@ const {
1917
prepareValue
2018
} = require("./parsers");
2119
const allExtraProperties = require("./utils/allExtraProperties");
22-
const { dashedToCamelCase } = require("./utils/camelize");
23-
const { getPropertyDescriptor } = require("./utils/propertyDescriptors");
2420
const { asciiLowercase } = require("./utils/strings");
2521

2622
/**
@@ -118,6 +114,9 @@ class CSSStyleDeclaration {
118114
} else if (context.nodeType === 1 && Object.hasOwn(context, "style")) {
119115
this._global = context.ownerDocument.defaultView;
120116
this._ownerNode = context;
117+
if (typeof opt.onChange === "function") {
118+
this._onChange = opt.onChange;
119+
}
121120
} else if (Object.hasOwn(context, "parentRule")) {
122121
this._parentRule = context;
123122
// Find Window from the owner node of the StyleSheet.
@@ -127,10 +126,6 @@ class CSSStyleDeclaration {
127126
}
128127
}
129128
}
130-
const { onChange } = opt;
131-
if (typeof onChange === "function") {
132-
this._onChange = onChange;
133-
}
134129
if (!Object.hasOwn(opt, "format")) {
135130
opt.format = "specifiedValue";
136131
}
@@ -263,28 +258,6 @@ class CSSStyleDeclaration {
263258
this._length = len;
264259
}
265260

266-
// Readonly
267-
get parentRule() {
268-
return this._parentRule;
269-
}
270-
271-
/**
272-
* @param {string} property
273-
*/
274-
getPropertyPriority(property) {
275-
return this._priorities.get(property) || "";
276-
}
277-
278-
/**
279-
* @param {string} property
280-
*/
281-
getPropertyValue(property) {
282-
if (this._values.has(property)) {
283-
return this._values.get(property).toString();
284-
}
285-
return "";
286-
}
287-
288261
/**
289262
* @param {...number} args
290263
*/
@@ -304,26 +277,18 @@ class CSSStyleDeclaration {
304277
/**
305278
* @param {string} property
306279
*/
307-
removeProperty(property) {
308-
if (this._readonly) {
309-
const msg = `Property ${property} can not be modified.`;
310-
const name = "NoModificationAllowedError";
311-
throw new this._global.DOMException(msg, name);
312-
}
313-
if (!this._values.has(property)) {
314-
return "";
315-
}
316-
const prevValue = this._values.get(property);
317-
this._values.delete(property);
318-
this._priorities.delete(property);
319-
const index = Array.prototype.indexOf.call(this, property);
320-
if (index >= 0) {
321-
Array.prototype.splice.call(this, index, 1);
322-
if (typeof this._onChange === "function") {
323-
this._onChange(this.cssText);
324-
}
280+
getPropertyValue(property) {
281+
if (this._values.has(property)) {
282+
return this._values.get(property).toString();
325283
}
326-
return prevValue;
284+
return "";
285+
}
286+
287+
/**
288+
* @param {string} property
289+
*/
290+
getPropertyPriority(property) {
291+
return this._priorities.get(property) || "";
327292
}
328293

329294
/**
@@ -360,6 +325,36 @@ class CSSStyleDeclaration {
360325
}
361326
this[property] = value;
362327
}
328+
329+
/**
330+
* @param {string} property
331+
*/
332+
removeProperty(property) {
333+
if (this._readonly) {
334+
const msg = `Property ${property} can not be modified.`;
335+
const name = "NoModificationAllowedError";
336+
throw new this._global.DOMException(msg, name);
337+
}
338+
if (!this._values.has(property)) {
339+
return "";
340+
}
341+
const prevValue = this._values.get(property);
342+
this._values.delete(property);
343+
this._priorities.delete(property);
344+
const index = Array.prototype.indexOf.call(this, property);
345+
if (index >= 0) {
346+
Array.prototype.splice.call(this, index, 1);
347+
if (typeof this._onChange === "function") {
348+
this._onChange(this.cssText);
349+
}
350+
}
351+
return prevValue;
352+
}
353+
354+
// Readonly
355+
get parentRule() {
356+
return this._parentRule;
357+
}
363358
}
364359

365360
// Internal methods
@@ -614,23 +609,6 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
614609
}
615610
});
616611

617-
// Properties
618-
Object.defineProperties(CSSStyleDeclaration.prototype, generatedProperties);
619-
620-
// Additional properties
621-
[...allProperties, ...allExtraProperties].forEach((property) => {
622-
if (!implementedProperties.has(property)) {
623-
const declaration = getPropertyDescriptor(property);
624-
Object.defineProperty(CSSStyleDeclaration.prototype, property, declaration);
625-
const camel = dashedToCamelCase(property);
626-
Object.defineProperty(CSSStyleDeclaration.prototype, camel, declaration);
627-
if (/^webkit[A-Z]/.test(camel)) {
628-
const pascal = camel.replace(/^webkit/, "Webkit");
629-
Object.defineProperty(CSSStyleDeclaration.prototype, pascal, declaration);
630-
}
631-
}
632-
});
633-
634612
module.exports = {
635613
CSSStyleDeclaration
636614
};

lib/normalize.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,11 @@ exports.prepareBorderProperties = (property, value, priority, properties, opt =
513513
const longhandProperty = `${prop1}-${position}-${prop2}`;
514514
const longhandItem = getPropertyItem(longhandProperty, properties);
515515
if (propertyValue) {
516-
positionItem.value = replaceBorderShorthandValue(propertyValue, positionItem.value, parseOpt);
516+
positionItem.value = replaceBorderShorthandValue(
517+
propertyValue,
518+
positionItem.value,
519+
parseOpt
520+
);
517521
} else {
518522
positionItem.value = "";
519523
}
@@ -651,9 +655,7 @@ exports.prepareBorderProperties = (property, value, priority, properties, opt =
651655
const positionItem = getPropertyItem(positionProperty, properties);
652656
if (nameItem.value) {
653657
for (const positionValue of Object.values(value)) {
654-
if (
655-
!matchesBorderShorthandValue(property, positionValue, nameItem.value, parseOpt)
656-
) {
658+
if (!matchesBorderShorthandValue(property, positionValue, nameItem.value, parseOpt)) {
657659
nameItem.value = "";
658660
break;
659661
}

0 commit comments

Comments
 (0)