cssstyle 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,13 +3,19 @@
|
|
|
3
3
|
* https://github.com/NV/CSSOM
|
|
4
4
|
*/
|
|
5
5
|
"use strict";
|
|
6
|
-
const CSSOM = require("rrweb-cssom");
|
|
7
6
|
const allExtraProperties = require("./allExtraProperties");
|
|
8
7
|
const { shorthandProperties } = require("./shorthandProperties");
|
|
9
8
|
const allProperties = require("./generated/allProperties");
|
|
10
9
|
const implementedProperties = require("./generated/implementedProperties");
|
|
11
10
|
const generatedProperties = require("./generated/properties");
|
|
12
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
hasVarFunc,
|
|
13
|
+
isValidPropertyValue,
|
|
14
|
+
parseCSS,
|
|
15
|
+
parseShorthand,
|
|
16
|
+
prepareValue,
|
|
17
|
+
splitValue
|
|
18
|
+
} = require("./parsers");
|
|
13
19
|
const { dashedToCamelCase } = require("./utils/camelize");
|
|
14
20
|
const { getPropertyDescriptor } = require("./utils/propertyDescriptors");
|
|
15
21
|
const { asciiLowercase } = require("./utils/strings");
|
|
@@ -157,21 +163,37 @@ class CSSStyleDeclaration {
|
|
|
157
163
|
return;
|
|
158
164
|
}
|
|
159
165
|
this._setInProgress = true;
|
|
160
|
-
let dummyRule;
|
|
161
166
|
try {
|
|
162
|
-
|
|
167
|
+
const valueObj = parseCSS(
|
|
168
|
+
value,
|
|
169
|
+
{
|
|
170
|
+
context: "declarationList",
|
|
171
|
+
parseValue: false
|
|
172
|
+
},
|
|
173
|
+
true
|
|
174
|
+
);
|
|
175
|
+
if (valueObj?.children) {
|
|
176
|
+
for (const item of valueObj.children) {
|
|
177
|
+
const {
|
|
178
|
+
important,
|
|
179
|
+
property,
|
|
180
|
+
value: { value: rawValue }
|
|
181
|
+
} = item;
|
|
182
|
+
const isCustomProperty = property.startsWith("--");
|
|
183
|
+
if (
|
|
184
|
+
isCustomProperty ||
|
|
185
|
+
hasVarFunc(rawValue) ||
|
|
186
|
+
isValidPropertyValue(property, rawValue)
|
|
187
|
+
) {
|
|
188
|
+
this.setProperty(property, rawValue, important ? "important" : "");
|
|
189
|
+
} else {
|
|
190
|
+
this.removeProperty(property);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
163
194
|
} catch {
|
|
164
|
-
// Malformed css, just return.
|
|
165
195
|
return;
|
|
166
196
|
}
|
|
167
|
-
for (let i = 0; i < dummyRule.length; i++) {
|
|
168
|
-
const property = dummyRule[i];
|
|
169
|
-
this.setProperty(
|
|
170
|
-
property,
|
|
171
|
-
dummyRule.getPropertyValue(property),
|
|
172
|
-
dummyRule.getPropertyPriority(property)
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
197
|
this._setInProgress = false;
|
|
176
198
|
if (typeof this._onChange === "function") {
|
|
177
199
|
this._onChange(this.cssText);
|
|
@@ -505,22 +527,18 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
|
|
|
505
527
|
if (part) {
|
|
506
528
|
part = `-${part}`;
|
|
507
529
|
}
|
|
530
|
+
const shorthandProp = `${prefix}${part}`;
|
|
508
531
|
let parts = [];
|
|
509
532
|
if (val === "") {
|
|
510
533
|
parts.push(val);
|
|
511
|
-
} else {
|
|
512
|
-
|
|
513
|
-
if (key) {
|
|
514
|
-
parts.push(key);
|
|
515
|
-
} else {
|
|
516
|
-
parts.push(...splitValue(val));
|
|
517
|
-
}
|
|
534
|
+
} else if (isValidPropertyValue(shorthandProp, val)) {
|
|
535
|
+
parts.push(...splitValue(val));
|
|
518
536
|
}
|
|
519
537
|
if (!parts.length || parts.length > positions.length || !parts.every(isValid)) {
|
|
520
538
|
return;
|
|
521
539
|
}
|
|
522
540
|
parts = parts.map((p) => parser(p));
|
|
523
|
-
this._setProperty(
|
|
541
|
+
this._setProperty(shorthandProp, parts.join(" "));
|
|
524
542
|
switch (positions.length) {
|
|
525
543
|
case 4:
|
|
526
544
|
if (parts.length === 1) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// autogenerated - 2025-07-
|
|
2
|
+
// autogenerated - 2025-07-28
|
|
3
3
|
// https://www.w3.org/Style/CSS/all-properties.en.html
|
|
4
4
|
|
|
5
5
|
var external_dependency_parsers_0 = require("../parsers.js");
|
|
6
|
-
var external_dependency_strings_1 = require("../utils
|
|
6
|
+
var external_dependency_strings_1 = require("../utils\\strings.js");
|
|
7
7
|
var backgroundImage_export_parse, backgroundImage_export_isValid, backgroundImage_export_definition;
|
|
8
8
|
backgroundImage_export_parse = function parse(v) {
|
|
9
9
|
if (v === "") {
|
package/lib/parsers.js
CHANGED
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const {
|
|
8
|
+
resolve: resolveColor,
|
|
9
|
+
utils: { cssCalc, isColor, resolveGradient, splitValue }
|
|
10
|
+
} = require("@asamuzakjp/css-color");
|
|
11
|
+
const { next: syntaxes } = require("@csstools/css-syntax-patches-for-csstree");
|
|
12
|
+
const csstree = require("css-tree");
|
|
8
13
|
const { asciiLowercase } = require("./utils/strings");
|
|
9
14
|
|
|
10
|
-
const { cssCalc, isColor, resolveGradient, splitValue } = utils;
|
|
11
|
-
|
|
12
15
|
// CSS global values
|
|
13
16
|
// @see https://drafts.csswg.org/css-cascade-5/#defaulting-keywords
|
|
14
17
|
const GLOBAL_VALUE = Object.freeze(["initial", "inherit", "unset", "revert", "revert-layer"]);
|
|
@@ -111,6 +114,9 @@ const getNumericType = function getNumericType(val) {
|
|
|
111
114
|
return NUM_TYPE.UNDEFINED;
|
|
112
115
|
};
|
|
113
116
|
|
|
117
|
+
// Patch css-tree
|
|
118
|
+
const cssTree = csstree.fork(syntaxes);
|
|
119
|
+
|
|
114
120
|
// Prepare stringified value.
|
|
115
121
|
exports.prepareValue = function prepareValue(value, globalObject = globalThis) {
|
|
116
122
|
// `null` is converted to an empty string.
|
|
@@ -508,6 +514,31 @@ exports.parseShorthand = function parseShorthand(val, shorthandFor, preserve = f
|
|
|
508
514
|
return obj;
|
|
509
515
|
};
|
|
510
516
|
|
|
517
|
+
exports.parseCSS = function parseCSS(val, opt, toObject = false) {
|
|
518
|
+
const ast = cssTree.parse(val, opt);
|
|
519
|
+
if (toObject) {
|
|
520
|
+
return cssTree.toPlainObject(ast);
|
|
521
|
+
}
|
|
522
|
+
return ast;
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// Returns `false` for custom property and/or var().
|
|
526
|
+
exports.isValidPropertyValue = function isValidPropertyValue(prop, val) {
|
|
527
|
+
// cssTree.lexer does not support deprecated system colors
|
|
528
|
+
// @see https://github.com/w3c/webref/issues/1519#issuecomment-3120290261
|
|
529
|
+
if (SYS_COLOR.includes(asciiLowercase(val))) {
|
|
530
|
+
if (/^(?:-webkit-)?(?:[a-z][a-z\d]*-)*color$/i.test(prop)) {
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
const ast = exports.parseCSS(val, {
|
|
536
|
+
context: "value"
|
|
537
|
+
});
|
|
538
|
+
const { error, matched } = cssTree.lexer.matchProperty(prop, ast);
|
|
539
|
+
return error === null && matched !== null;
|
|
540
|
+
};
|
|
541
|
+
|
|
511
542
|
// Returns `false` for global values, e.g. "inherit".
|
|
512
543
|
exports.isValidColor = function isValidColor(val) {
|
|
513
544
|
if (SYS_COLOR.includes(asciiLowercase(val))) {
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"CSSStyleDeclaration",
|
|
7
7
|
"StyleSheet"
|
|
8
8
|
],
|
|
9
|
-
"version": "5.
|
|
9
|
+
"version": "5.2.0",
|
|
10
10
|
"homepage": "https://github.com/jsdom/cssstyle",
|
|
11
11
|
"maintainers": [
|
|
12
12
|
{
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"main": "./lib/CSSStyleDeclaration.js",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@asamuzakjp/css-color": "^4.0.3",
|
|
41
|
-
"
|
|
41
|
+
"@csstools/css-syntax-patches-for-csstree": "^1.0.14",
|
|
42
|
+
"css-tree": "^3.1.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@babel/generator": "^7.26.9",
|