cssstyle 5.0.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.
- package/lib/CSSStyleDeclaration.js +39 -21
- package/lib/generated/implementedProperties.js +2 -1
- package/lib/generated/properties.js +210 -2
- package/lib/parsers.js +41 -8
- package/lib/properties/display.js +217 -0
- package/package.json +4 -3
|
@@ -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,5 +1,5 @@
|
|
|
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
|
module.exports = new Set([
|
|
@@ -47,6 +47,7 @@ module.exports = new Set([
|
|
|
47
47
|
"clear",
|
|
48
48
|
"clip",
|
|
49
49
|
"color",
|
|
50
|
+
"display",
|
|
50
51
|
"flex",
|
|
51
52
|
"flex-basis",
|
|
52
53
|
"flex-grow",
|
|
@@ -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 === "") {
|
|
@@ -1792,6 +1792,213 @@ color_export_definition = {
|
|
|
1792
1792
|
enumerable: true,
|
|
1793
1793
|
configurable: true
|
|
1794
1794
|
};
|
|
1795
|
+
var display_export_parse, display_export_isValid, display_export_definition;
|
|
1796
|
+
/* keywords */
|
|
1797
|
+
const display_local_var_displayOutside = ["block", "inline", "run-in"];
|
|
1798
|
+
const display_local_var_displayFlow = ["flow", "flow-root"];
|
|
1799
|
+
const display_local_var_displayInside = ["table", "flex", "grid", "ruby", ...display_local_var_displayFlow];
|
|
1800
|
+
const display_local_var_displayListItem = ["list-item"];
|
|
1801
|
+
const display_local_var_displayInternal = ["table-row-group", "table-header-group", "table-footer-group", "table-row", "table-cell", "table-column-group", "table-column", "table-caption", "ruby-base", "ruby-text", "ruby-base-container", "ruby-text-container"];
|
|
1802
|
+
const display_local_var_displayBox = ["contents", "none"];
|
|
1803
|
+
const display_local_var_displayLegacy = ["inline-block", "inline-table", "inline-flex", "inline-grid"];
|
|
1804
|
+
const display_local_var_keywords = [...display_local_var_displayOutside, ...display_local_var_displayInside, ...display_local_var_displayListItem, ...display_local_var_displayInternal, ...display_local_var_displayBox, ...display_local_var_displayLegacy];
|
|
1805
|
+
display_export_parse = function parse(v) {
|
|
1806
|
+
if (v === "") {
|
|
1807
|
+
return v;
|
|
1808
|
+
}
|
|
1809
|
+
const values = external_dependency_parsers_0.splitValue(v);
|
|
1810
|
+
switch (values.length) {
|
|
1811
|
+
case 1:
|
|
1812
|
+
{
|
|
1813
|
+
let [v1] = values;
|
|
1814
|
+
v1 = external_dependency_parsers_0.parseKeyword(v1, display_local_var_keywords);
|
|
1815
|
+
if (v1) {
|
|
1816
|
+
if (v1 === "flow") {
|
|
1817
|
+
return "block";
|
|
1818
|
+
}
|
|
1819
|
+
return v1;
|
|
1820
|
+
}
|
|
1821
|
+
break;
|
|
1822
|
+
}
|
|
1823
|
+
case 2:
|
|
1824
|
+
{
|
|
1825
|
+
let [v1, v2] = values;
|
|
1826
|
+
v1 = external_dependency_parsers_0.parseKeyword(v1, display_local_var_keywords);
|
|
1827
|
+
v2 = external_dependency_parsers_0.parseKeyword(v2, display_local_var_keywords);
|
|
1828
|
+
if (!v1 || !v2) {
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
let outerValue = "";
|
|
1832
|
+
let innerValue = "";
|
|
1833
|
+
if (v1 === "list-item") {
|
|
1834
|
+
outerValue = v2;
|
|
1835
|
+
innerValue = v1;
|
|
1836
|
+
} else if (v2 === "list-item") {
|
|
1837
|
+
outerValue = v1;
|
|
1838
|
+
innerValue = v2;
|
|
1839
|
+
} else if (display_local_var_displayOutside.includes(v1)) {
|
|
1840
|
+
outerValue = v1;
|
|
1841
|
+
innerValue = v2;
|
|
1842
|
+
} else if (display_local_var_displayOutside.includes(v2)) {
|
|
1843
|
+
outerValue = v2;
|
|
1844
|
+
innerValue = v1;
|
|
1845
|
+
}
|
|
1846
|
+
if (innerValue === "list-item") {
|
|
1847
|
+
switch (outerValue) {
|
|
1848
|
+
case "block":
|
|
1849
|
+
case "flow":
|
|
1850
|
+
{
|
|
1851
|
+
return innerValue;
|
|
1852
|
+
}
|
|
1853
|
+
case "flow-root":
|
|
1854
|
+
case "inline":
|
|
1855
|
+
case "run-in":
|
|
1856
|
+
{
|
|
1857
|
+
return `${outerValue} ${innerValue}`;
|
|
1858
|
+
}
|
|
1859
|
+
default:
|
|
1860
|
+
}
|
|
1861
|
+
} else if (outerValue === "block") {
|
|
1862
|
+
switch (innerValue) {
|
|
1863
|
+
case "flow":
|
|
1864
|
+
{
|
|
1865
|
+
return outerValue;
|
|
1866
|
+
}
|
|
1867
|
+
case "flow-root":
|
|
1868
|
+
case "flex":
|
|
1869
|
+
case "grid":
|
|
1870
|
+
case "table":
|
|
1871
|
+
{
|
|
1872
|
+
return innerValue;
|
|
1873
|
+
}
|
|
1874
|
+
case "ruby":
|
|
1875
|
+
{
|
|
1876
|
+
return `${outerValue} ${innerValue}`;
|
|
1877
|
+
}
|
|
1878
|
+
default:
|
|
1879
|
+
}
|
|
1880
|
+
} else if (outerValue === "inline") {
|
|
1881
|
+
switch (innerValue) {
|
|
1882
|
+
case "flow":
|
|
1883
|
+
{
|
|
1884
|
+
return outerValue;
|
|
1885
|
+
}
|
|
1886
|
+
case "flow-root":
|
|
1887
|
+
{
|
|
1888
|
+
return `${outerValue}-block`;
|
|
1889
|
+
}
|
|
1890
|
+
case "flex":
|
|
1891
|
+
case "grid":
|
|
1892
|
+
case "table":
|
|
1893
|
+
{
|
|
1894
|
+
return `${outerValue}-${innerValue}`;
|
|
1895
|
+
}
|
|
1896
|
+
case "ruby":
|
|
1897
|
+
{
|
|
1898
|
+
return innerValue;
|
|
1899
|
+
}
|
|
1900
|
+
default:
|
|
1901
|
+
}
|
|
1902
|
+
} else if (outerValue === "run-in") {
|
|
1903
|
+
switch (innerValue) {
|
|
1904
|
+
case "flow":
|
|
1905
|
+
{
|
|
1906
|
+
return outerValue;
|
|
1907
|
+
}
|
|
1908
|
+
case "flow-root":
|
|
1909
|
+
case "flex":
|
|
1910
|
+
case "grid":
|
|
1911
|
+
case "table":
|
|
1912
|
+
case "ruby":
|
|
1913
|
+
{
|
|
1914
|
+
return `${outerValue} ${innerValue}`;
|
|
1915
|
+
}
|
|
1916
|
+
default:
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
break;
|
|
1920
|
+
}
|
|
1921
|
+
case 3:
|
|
1922
|
+
{
|
|
1923
|
+
let [v1, v2, v3] = values;
|
|
1924
|
+
v1 = external_dependency_parsers_0.parseKeyword(v1, display_local_var_keywords);
|
|
1925
|
+
v2 = external_dependency_parsers_0.parseKeyword(v2, display_local_var_keywords);
|
|
1926
|
+
v3 = external_dependency_parsers_0.parseKeyword(v3, display_local_var_keywords);
|
|
1927
|
+
if (!v1 || !v2 || !v3) {
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1930
|
+
let outerValue = "";
|
|
1931
|
+
let flowValue = "";
|
|
1932
|
+
let listItemValue = "";
|
|
1933
|
+
if (v1 === "list-item") {
|
|
1934
|
+
listItemValue = v1;
|
|
1935
|
+
if (display_local_var_displayFlow.includes(v2)) {
|
|
1936
|
+
flowValue = v2;
|
|
1937
|
+
outerValue = v3;
|
|
1938
|
+
} else if (display_local_var_displayFlow.includes(v3)) {
|
|
1939
|
+
flowValue = v3;
|
|
1940
|
+
outerValue = v2;
|
|
1941
|
+
}
|
|
1942
|
+
} else if (v2 === "list-item") {
|
|
1943
|
+
listItemValue = v2;
|
|
1944
|
+
if (display_local_var_displayFlow.includes(v1)) {
|
|
1945
|
+
flowValue = v1;
|
|
1946
|
+
outerValue = v3;
|
|
1947
|
+
} else if (display_local_var_displayFlow.includes(v3)) {
|
|
1948
|
+
flowValue = v3;
|
|
1949
|
+
outerValue = v1;
|
|
1950
|
+
}
|
|
1951
|
+
} else if (v3 === "list-item") {
|
|
1952
|
+
listItemValue = v3;
|
|
1953
|
+
if (display_local_var_displayFlow.includes(v1)) {
|
|
1954
|
+
flowValue = v1;
|
|
1955
|
+
outerValue = v2;
|
|
1956
|
+
} else if (display_local_var_displayFlow.includes(v2)) {
|
|
1957
|
+
flowValue = v2;
|
|
1958
|
+
outerValue = v1;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
if (outerValue && flowValue && listItemValue) {
|
|
1962
|
+
switch (outerValue) {
|
|
1963
|
+
case "block":
|
|
1964
|
+
{
|
|
1965
|
+
if (flowValue === "flow") {
|
|
1966
|
+
return listItemValue;
|
|
1967
|
+
}
|
|
1968
|
+
return `${flowValue} ${listItemValue}`;
|
|
1969
|
+
}
|
|
1970
|
+
case "inline":
|
|
1971
|
+
case "run-in":
|
|
1972
|
+
{
|
|
1973
|
+
if (flowValue === "flow") {
|
|
1974
|
+
return `${outerValue} ${listItemValue}`;
|
|
1975
|
+
}
|
|
1976
|
+
return `${outerValue} ${flowValue} ${listItemValue}`;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
break;
|
|
1981
|
+
}
|
|
1982
|
+
default:
|
|
1983
|
+
}
|
|
1984
|
+
};
|
|
1985
|
+
display_export_isValid = function isValid(v) {
|
|
1986
|
+
if (v === "") {
|
|
1987
|
+
return true;
|
|
1988
|
+
}
|
|
1989
|
+
return typeof display_export_parse(v) === "string";
|
|
1990
|
+
};
|
|
1991
|
+
display_export_definition = {
|
|
1992
|
+
set(v) {
|
|
1993
|
+
v = external_dependency_parsers_0.prepareValue(v, this._global);
|
|
1994
|
+
this._setProperty("display", display_export_parse(v));
|
|
1995
|
+
},
|
|
1996
|
+
get() {
|
|
1997
|
+
return this.getPropertyValue("display");
|
|
1998
|
+
},
|
|
1999
|
+
enumerable: true,
|
|
2000
|
+
configurable: true
|
|
2001
|
+
};
|
|
1795
2002
|
var flexGrow_export_parse, flexGrow_export_isValid, flexGrow_export_definition;
|
|
1796
2003
|
flexGrow_export_parse = function parse(v) {
|
|
1797
2004
|
return external_dependency_parsers_0.parseNumber(v, true);
|
|
@@ -3306,6 +3513,7 @@ module.exports = {
|
|
|
3306
3513
|
clear: clear_export_definition,
|
|
3307
3514
|
clip: clip_export_definition,
|
|
3308
3515
|
color: color_export_definition,
|
|
3516
|
+
display: display_export_definition,
|
|
3309
3517
|
flexGrow: flexGrow_export_definition,
|
|
3310
3518
|
"flex-grow": flexGrow_export_definition,
|
|
3311
3519
|
flexShrink: flexShrink_export_definition,
|
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, isGradient, 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.
|
|
@@ -398,7 +404,7 @@ exports.parseKeyword = function parseKeyword(val, validKeywords = []) {
|
|
|
398
404
|
if (varRegEx.test(val)) {
|
|
399
405
|
return val;
|
|
400
406
|
}
|
|
401
|
-
val = asciiLowercase(val
|
|
407
|
+
val = asciiLowercase(val);
|
|
402
408
|
if (validKeywords.includes(val) || GLOBAL_VALUE.includes(val)) {
|
|
403
409
|
return val;
|
|
404
410
|
}
|
|
@@ -430,15 +436,17 @@ exports.parseImage = function parseImage(val) {
|
|
|
430
436
|
if (val === "") {
|
|
431
437
|
return "";
|
|
432
438
|
}
|
|
433
|
-
if (gradientRegEx.test(val) &&
|
|
439
|
+
if (gradientRegEx.test(val) && exports.hasVarFunc(val)) {
|
|
434
440
|
return val;
|
|
435
441
|
}
|
|
436
442
|
if (keywordRegEx.test(val)) {
|
|
437
443
|
return exports.parseKeyword(val, ["none"]);
|
|
438
444
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
445
|
+
const res = resolveGradient(val, {
|
|
446
|
+
format: "specifiedValue"
|
|
447
|
+
});
|
|
448
|
+
if (res) {
|
|
449
|
+
return res;
|
|
442
450
|
}
|
|
443
451
|
return exports.parseUrl(val);
|
|
444
452
|
};
|
|
@@ -506,6 +514,31 @@ exports.parseShorthand = function parseShorthand(val, shorthandFor, preserve = f
|
|
|
506
514
|
return obj;
|
|
507
515
|
};
|
|
508
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
|
+
|
|
509
542
|
// Returns `false` for global values, e.g. "inherit".
|
|
510
543
|
exports.isValidColor = function isValidColor(val) {
|
|
511
544
|
if (SYS_COLOR.includes(asciiLowercase(val))) {
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const parsers = require("../parsers");
|
|
4
|
+
|
|
5
|
+
/* keywords */
|
|
6
|
+
const displayOutside = ["block", "inline", "run-in"];
|
|
7
|
+
const displayFlow = ["flow", "flow-root"];
|
|
8
|
+
const displayInside = ["table", "flex", "grid", "ruby", ...displayFlow];
|
|
9
|
+
const displayListItem = ["list-item"];
|
|
10
|
+
const displayInternal = [
|
|
11
|
+
"table-row-group",
|
|
12
|
+
"table-header-group",
|
|
13
|
+
"table-footer-group",
|
|
14
|
+
"table-row",
|
|
15
|
+
"table-cell",
|
|
16
|
+
"table-column-group",
|
|
17
|
+
"table-column",
|
|
18
|
+
"table-caption",
|
|
19
|
+
"ruby-base",
|
|
20
|
+
"ruby-text",
|
|
21
|
+
"ruby-base-container",
|
|
22
|
+
"ruby-text-container"
|
|
23
|
+
];
|
|
24
|
+
const displayBox = ["contents", "none"];
|
|
25
|
+
const displayLegacy = ["inline-block", "inline-table", "inline-flex", "inline-grid"];
|
|
26
|
+
const keywords = [
|
|
27
|
+
...displayOutside,
|
|
28
|
+
...displayInside,
|
|
29
|
+
...displayListItem,
|
|
30
|
+
...displayInternal,
|
|
31
|
+
...displayBox,
|
|
32
|
+
...displayLegacy
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
module.exports.parse = function parse(v) {
|
|
36
|
+
if (v === "") {
|
|
37
|
+
return v;
|
|
38
|
+
}
|
|
39
|
+
const values = parsers.splitValue(v);
|
|
40
|
+
switch (values.length) {
|
|
41
|
+
case 1: {
|
|
42
|
+
let [v1] = values;
|
|
43
|
+
v1 = parsers.parseKeyword(v1, keywords);
|
|
44
|
+
if (v1) {
|
|
45
|
+
if (v1 === "flow") {
|
|
46
|
+
return "block";
|
|
47
|
+
}
|
|
48
|
+
return v1;
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case 2: {
|
|
53
|
+
let [v1, v2] = values;
|
|
54
|
+
v1 = parsers.parseKeyword(v1, keywords);
|
|
55
|
+
v2 = parsers.parseKeyword(v2, keywords);
|
|
56
|
+
if (!v1 || !v2) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
let outerValue = "";
|
|
60
|
+
let innerValue = "";
|
|
61
|
+
if (v1 === "list-item") {
|
|
62
|
+
outerValue = v2;
|
|
63
|
+
innerValue = v1;
|
|
64
|
+
} else if (v2 === "list-item") {
|
|
65
|
+
outerValue = v1;
|
|
66
|
+
innerValue = v2;
|
|
67
|
+
} else if (displayOutside.includes(v1)) {
|
|
68
|
+
outerValue = v1;
|
|
69
|
+
innerValue = v2;
|
|
70
|
+
} else if (displayOutside.includes(v2)) {
|
|
71
|
+
outerValue = v2;
|
|
72
|
+
innerValue = v1;
|
|
73
|
+
}
|
|
74
|
+
if (innerValue === "list-item") {
|
|
75
|
+
switch (outerValue) {
|
|
76
|
+
case "block":
|
|
77
|
+
case "flow": {
|
|
78
|
+
return innerValue;
|
|
79
|
+
}
|
|
80
|
+
case "flow-root":
|
|
81
|
+
case "inline":
|
|
82
|
+
case "run-in": {
|
|
83
|
+
return `${outerValue} ${innerValue}`;
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
}
|
|
87
|
+
} else if (outerValue === "block") {
|
|
88
|
+
switch (innerValue) {
|
|
89
|
+
case "flow": {
|
|
90
|
+
return outerValue;
|
|
91
|
+
}
|
|
92
|
+
case "flow-root":
|
|
93
|
+
case "flex":
|
|
94
|
+
case "grid":
|
|
95
|
+
case "table": {
|
|
96
|
+
return innerValue;
|
|
97
|
+
}
|
|
98
|
+
case "ruby": {
|
|
99
|
+
return `${outerValue} ${innerValue}`;
|
|
100
|
+
}
|
|
101
|
+
default:
|
|
102
|
+
}
|
|
103
|
+
} else if (outerValue === "inline") {
|
|
104
|
+
switch (innerValue) {
|
|
105
|
+
case "flow": {
|
|
106
|
+
return outerValue;
|
|
107
|
+
}
|
|
108
|
+
case "flow-root": {
|
|
109
|
+
return `${outerValue}-block`;
|
|
110
|
+
}
|
|
111
|
+
case "flex":
|
|
112
|
+
case "grid":
|
|
113
|
+
case "table": {
|
|
114
|
+
return `${outerValue}-${innerValue}`;
|
|
115
|
+
}
|
|
116
|
+
case "ruby": {
|
|
117
|
+
return innerValue;
|
|
118
|
+
}
|
|
119
|
+
default:
|
|
120
|
+
}
|
|
121
|
+
} else if (outerValue === "run-in") {
|
|
122
|
+
switch (innerValue) {
|
|
123
|
+
case "flow": {
|
|
124
|
+
return outerValue;
|
|
125
|
+
}
|
|
126
|
+
case "flow-root":
|
|
127
|
+
case "flex":
|
|
128
|
+
case "grid":
|
|
129
|
+
case "table":
|
|
130
|
+
case "ruby": {
|
|
131
|
+
return `${outerValue} ${innerValue}`;
|
|
132
|
+
}
|
|
133
|
+
default:
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
case 3: {
|
|
139
|
+
let [v1, v2, v3] = values;
|
|
140
|
+
v1 = parsers.parseKeyword(v1, keywords);
|
|
141
|
+
v2 = parsers.parseKeyword(v2, keywords);
|
|
142
|
+
v3 = parsers.parseKeyword(v3, keywords);
|
|
143
|
+
if (!v1 || !v2 || !v3) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
let outerValue = "";
|
|
147
|
+
let flowValue = "";
|
|
148
|
+
let listItemValue = "";
|
|
149
|
+
if (v1 === "list-item") {
|
|
150
|
+
listItemValue = v1;
|
|
151
|
+
if (displayFlow.includes(v2)) {
|
|
152
|
+
flowValue = v2;
|
|
153
|
+
outerValue = v3;
|
|
154
|
+
} else if (displayFlow.includes(v3)) {
|
|
155
|
+
flowValue = v3;
|
|
156
|
+
outerValue = v2;
|
|
157
|
+
}
|
|
158
|
+
} else if (v2 === "list-item") {
|
|
159
|
+
listItemValue = v2;
|
|
160
|
+
if (displayFlow.includes(v1)) {
|
|
161
|
+
flowValue = v1;
|
|
162
|
+
outerValue = v3;
|
|
163
|
+
} else if (displayFlow.includes(v3)) {
|
|
164
|
+
flowValue = v3;
|
|
165
|
+
outerValue = v1;
|
|
166
|
+
}
|
|
167
|
+
} else if (v3 === "list-item") {
|
|
168
|
+
listItemValue = v3;
|
|
169
|
+
if (displayFlow.includes(v1)) {
|
|
170
|
+
flowValue = v1;
|
|
171
|
+
outerValue = v2;
|
|
172
|
+
} else if (displayFlow.includes(v2)) {
|
|
173
|
+
flowValue = v2;
|
|
174
|
+
outerValue = v1;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (outerValue && flowValue && listItemValue) {
|
|
178
|
+
switch (outerValue) {
|
|
179
|
+
case "block": {
|
|
180
|
+
if (flowValue === "flow") {
|
|
181
|
+
return listItemValue;
|
|
182
|
+
}
|
|
183
|
+
return `${flowValue} ${listItemValue}`;
|
|
184
|
+
}
|
|
185
|
+
case "inline":
|
|
186
|
+
case "run-in": {
|
|
187
|
+
if (flowValue === "flow") {
|
|
188
|
+
return `${outerValue} ${listItemValue}`;
|
|
189
|
+
}
|
|
190
|
+
return `${outerValue} ${flowValue} ${listItemValue}`;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
default:
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
module.exports.isValid = function isValid(v) {
|
|
201
|
+
if (v === "") {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
return typeof module.exports.parse(v) === "string";
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
module.exports.definition = {
|
|
208
|
+
set(v) {
|
|
209
|
+
v = parsers.prepareValue(v, this._global);
|
|
210
|
+
this._setProperty("display", module.exports.parse(v));
|
|
211
|
+
},
|
|
212
|
+
get() {
|
|
213
|
+
return this.getPropertyValue("display");
|
|
214
|
+
},
|
|
215
|
+
enumerable: true,
|
|
216
|
+
configurable: true
|
|
217
|
+
};
|
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
|
{
|
|
@@ -37,8 +37,9 @@
|
|
|
37
37
|
],
|
|
38
38
|
"main": "./lib/CSSStyleDeclaration.js",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@asamuzakjp/css-color": "^
|
|
41
|
-
"
|
|
40
|
+
"@asamuzakjp/css-color": "^4.0.3",
|
|
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",
|