cssstyle 5.2.0 → 5.3.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.
Files changed (88) hide show
  1. package/lib/CSSStyleDeclaration.js +250 -254
  2. package/lib/generated/allProperties.js +39 -1
  3. package/lib/generated/implementedProperties.js +2219 -80
  4. package/lib/generated/properties.js +5253 -1904
  5. package/lib/normalize.js +1417 -0
  6. package/lib/parsers.js +372 -389
  7. package/lib/properties/background.js +76 -63
  8. package/lib/properties/backgroundAttachment.js +37 -22
  9. package/lib/properties/backgroundClip.js +37 -22
  10. package/lib/properties/backgroundColor.js +35 -15
  11. package/lib/properties/backgroundImage.js +49 -19
  12. package/lib/properties/backgroundOrigin.js +37 -22
  13. package/lib/properties/backgroundPosition.js +145 -128
  14. package/lib/properties/backgroundRepeat.js +55 -48
  15. package/lib/properties/backgroundSize.js +86 -46
  16. package/lib/properties/border.js +139 -22
  17. package/lib/properties/borderBottom.js +137 -21
  18. package/lib/properties/borderBottomColor.js +41 -16
  19. package/lib/properties/borderBottomStyle.js +39 -30
  20. package/lib/properties/borderBottomWidth.js +49 -16
  21. package/lib/properties/borderCollapse.js +32 -8
  22. package/lib/properties/borderColor.js +96 -23
  23. package/lib/properties/borderLeft.js +137 -21
  24. package/lib/properties/borderLeftColor.js +41 -16
  25. package/lib/properties/borderLeftStyle.js +39 -30
  26. package/lib/properties/borderLeftWidth.js +49 -16
  27. package/lib/properties/borderRight.js +137 -21
  28. package/lib/properties/borderRightColor.js +41 -16
  29. package/lib/properties/borderRightStyle.js +39 -30
  30. package/lib/properties/borderRightWidth.js +49 -16
  31. package/lib/properties/borderSpacing.js +42 -25
  32. package/lib/properties/borderStyle.js +96 -34
  33. package/lib/properties/borderTop.js +131 -15
  34. package/lib/properties/borderTopColor.js +41 -16
  35. package/lib/properties/borderTopStyle.js +39 -30
  36. package/lib/properties/borderTopWidth.js +49 -16
  37. package/lib/properties/borderWidth.js +108 -23
  38. package/lib/properties/bottom.js +40 -12
  39. package/lib/properties/clear.js +32 -22
  40. package/lib/properties/clip.js +46 -32
  41. package/lib/properties/color.js +34 -13
  42. package/lib/properties/display.js +169 -179
  43. package/lib/properties/flex.js +137 -38
  44. package/lib/properties/flexBasis.js +43 -14
  45. package/lib/properties/flexGrow.js +42 -9
  46. package/lib/properties/flexShrink.js +42 -9
  47. package/lib/properties/float.js +32 -9
  48. package/lib/properties/floodColor.js +34 -13
  49. package/lib/properties/font.js +145 -44
  50. package/lib/properties/fontFamily.js +66 -67
  51. package/lib/properties/fontSize.js +43 -26
  52. package/lib/properties/fontStyle.js +42 -11
  53. package/lib/properties/fontVariant.js +52 -15
  54. package/lib/properties/fontWeight.js +47 -15
  55. package/lib/properties/height.js +40 -13
  56. package/lib/properties/left.js +40 -12
  57. package/lib/properties/lightingColor.js +34 -13
  58. package/lib/properties/lineHeight.js +45 -18
  59. package/lib/properties/margin.js +73 -36
  60. package/lib/properties/marginBottom.js +43 -19
  61. package/lib/properties/marginLeft.js +43 -19
  62. package/lib/properties/marginRight.js +43 -19
  63. package/lib/properties/marginTop.js +43 -19
  64. package/lib/properties/opacity.js +41 -28
  65. package/lib/properties/outlineColor.js +34 -13
  66. package/lib/properties/padding.js +71 -36
  67. package/lib/properties/paddingBottom.js +44 -21
  68. package/lib/properties/paddingLeft.js +44 -19
  69. package/lib/properties/paddingRight.js +44 -19
  70. package/lib/properties/paddingTop.js +44 -19
  71. package/lib/properties/right.js +40 -12
  72. package/lib/properties/stopColor.js +34 -13
  73. package/lib/properties/top.js +40 -12
  74. package/lib/properties/webkitBorderAfterColor.js +34 -13
  75. package/lib/properties/webkitBorderBeforeColor.js +34 -13
  76. package/lib/properties/webkitBorderEndColor.js +34 -13
  77. package/lib/properties/webkitBorderStartColor.js +34 -13
  78. package/lib/properties/webkitColumnRuleColor.js +34 -13
  79. package/lib/properties/webkitTapHighlightColor.js +34 -13
  80. package/lib/properties/webkitTextEmphasisColor.js +34 -13
  81. package/lib/properties/webkitTextFillColor.js +34 -13
  82. package/lib/properties/webkitTextStrokeColor.js +34 -13
  83. package/lib/properties/width.js +40 -13
  84. package/lib/{allWebkitProperties.js → utils/allExtraProperties.js} +42 -1
  85. package/lib/utils/propertyDescriptors.js +6 -3
  86. package/package.json +11 -10
  87. package/lib/allExtraProperties.js +0 -49
  88. package/lib/shorthandProperties.js +0 -21
@@ -2,93 +2,92 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
5
+ const property = "font-family";
6
+ const shorthand = "font";
7
+
8
+ module.exports.parse = function parse(v, opt = {}) {
9
+ const { globalObject } = opt;
6
10
  if (v === "") {
7
11
  return v;
8
12
  }
9
- const keywords = [
10
- "serif",
11
- "sans-serif",
12
- "cursive",
13
- "fantasy",
14
- "monospace",
15
- "system-ui",
16
- "math",
17
- "ui-serif",
18
- "ui-sans-serif",
19
- "ui-monospace",
20
- "ui-rounded"
21
- ];
22
- const genericValues = ["fangsong", "kai", "khmer-mul", "nastaliq"];
23
- const val = parsers.splitValue(v, {
13
+ const values = parsers.splitValue(v, {
24
14
  delimiter: ","
25
15
  });
26
- const font = [];
27
- let valid = false;
28
- for (const i of val) {
29
- const str = parsers.parseString(i);
30
- if (str) {
31
- font.push(str);
32
- valid = true;
33
- continue;
34
- }
35
- const key = parsers.parseKeyword(i, keywords);
36
- if (key) {
37
- font.push(key);
38
- valid = true;
39
- continue;
40
- }
41
- const obj = parsers.parseFunction(i);
42
- if (obj) {
43
- const { name, value } = obj;
44
- if (name === "generic" && genericValues.includes(value)) {
45
- font.push(`${name}(${value})`);
46
- valid = true;
47
- continue;
16
+ const parsedValues = [];
17
+ for (const val of values) {
18
+ const value = parsers.parsePropertyValue(property, val, {
19
+ globalObject,
20
+ caseSensitive: true,
21
+ inArray: true
22
+ });
23
+ if (Array.isArray(value) && value.length) {
24
+ if (value.length === 1) {
25
+ const [{ name, type, value: itemValue }] = value;
26
+ switch (type) {
27
+ case "Function": {
28
+ parsedValues.push(`${name}(${itemValue})`);
29
+ break;
30
+ }
31
+ case "GlobalKeyword":
32
+ case "Identifier": {
33
+ if (name !== "undefined") {
34
+ parsedValues.push(name);
35
+ }
36
+ break;
37
+ }
38
+ case "String": {
39
+ const parsedValue = itemValue.replaceAll("\\", "").replaceAll('"', '\\"');
40
+ parsedValues.push(`"${parsedValue}"`);
41
+ break;
42
+ }
43
+ default: {
44
+ return;
45
+ }
46
+ }
47
+ } else {
48
+ const parts = [];
49
+ for (const item of value) {
50
+ const { name, type } = item;
51
+ if (type === "Identifier") {
52
+ parts.push(name);
53
+ } else {
54
+ return;
55
+ }
56
+ }
57
+ const parsedValue = parts.join(" ").replaceAll("\\", "").replaceAll('"', '\\"');
58
+ parsedValues.push(`"${parsedValue}"`);
48
59
  }
49
- }
50
- // This implementation does not strictly follow the specification.
51
- // The spec does not require the first letter of the font-family to be
52
- // capitalized, and unquoted font-family names are not restricted to ASCII.
53
- // However, in the real world, the first letter of the ASCII font-family
54
- // names are capitalized, and unquoted font-family names do not contain
55
- // spaces, e.g. `Times`. And non-ASCII font-family names are quoted even
56
- // without spaces, e.g. `"メイリオ"`.
57
- // @see https://drafts.csswg.org/css-fonts/#font-family-prop
58
- if (
59
- i !== "undefined" &&
60
- /^(?:[A-Z][A-Za-z\d-]+(?:\s+[A-Z][A-Za-z\d-]+)*|-?[a-z][a-z-]+)$/.test(i)
61
- ) {
62
- font.push(i.trim());
63
- valid = true;
64
- continue;
65
- }
66
- if (!valid) {
60
+ } else if (typeof value === "string") {
61
+ parsedValues.push(value);
62
+ } else {
67
63
  return;
68
64
  }
69
65
  }
70
- return font.join(", ");
71
- };
72
-
73
- module.exports.isValid = function isValid(v) {
74
- if (v === "") {
75
- return true;
66
+ if (parsedValues.length) {
67
+ return parsedValues.join(", ");
76
68
  }
77
- return typeof module.exports.parse(v) === "string";
78
69
  };
79
70
 
80
71
  module.exports.definition = {
81
72
  set(v) {
82
73
  v = parsers.prepareValue(v, this._global);
83
74
  if (parsers.hasVarFunc(v)) {
84
- this._setProperty("font", "");
85
- this._setProperty("font-family", v);
75
+ this._setProperty(shorthand, "");
76
+ this._setProperty(property, v);
86
77
  } else {
87
- this._setProperty("font-family", module.exports.parse(v));
78
+ const val = module.exports.parse(v, {
79
+ globalObject: this._global
80
+ });
81
+ if (typeof val === "string") {
82
+ const shorthandPriority = this._priorities.get(shorthand);
83
+ const prior = this._priorities.get(property) ?? "";
84
+ const priority = shorthandPriority && prior ? "" : prior;
85
+ this._setProperty(property, val, priority);
86
+ }
88
87
  }
89
88
  },
90
89
  get() {
91
- return this.getPropertyValue("font-family");
90
+ return this.getPropertyValue(property);
92
91
  },
93
92
  enumerable: true,
94
93
  configurable: true
@@ -2,45 +2,62 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
6
- const val = parsers.parseMeasurement(v, true);
7
- if (val) {
8
- return val;
9
- }
10
- const keywords = [
11
- "xx-small",
12
- "x-small",
13
- "small",
14
- "medium",
15
- "large",
16
- "x-large",
17
- "xx-large",
18
- "xxx-large",
19
- "smaller",
20
- "larger"
21
- ];
22
- return parsers.parseKeyword(v, keywords);
23
- };
5
+ const property = "font-size";
6
+ const shorthand = "font";
24
7
 
25
- module.exports.isValid = function isValid(v) {
8
+ module.exports.parse = function parse(v, opt = {}) {
9
+ const { globalObject } = opt;
26
10
  if (v === "") {
27
- return true;
11
+ return v;
12
+ }
13
+ const value = parsers.parsePropertyValue(property, v, {
14
+ globalObject,
15
+ inArray: true
16
+ });
17
+ if (Array.isArray(value) && value.length === 1) {
18
+ const [{ isNumber, name, type, value: itemValue }] = value;
19
+ switch (type) {
20
+ case "Calc": {
21
+ if (isNumber) {
22
+ return;
23
+ }
24
+ return `${name}(${itemValue})`;
25
+ }
26
+ case "GlobalKeyword":
27
+ case "Identifier": {
28
+ return name;
29
+ }
30
+ default: {
31
+ return parsers.parseLengthPercentage(value, {
32
+ min: 0
33
+ });
34
+ }
35
+ }
36
+ } else if (typeof value === "string") {
37
+ return value;
28
38
  }
29
- return typeof module.exports.parse(v) === "string";
30
39
  };
31
40
 
32
41
  module.exports.definition = {
33
42
  set(v) {
34
43
  v = parsers.prepareValue(v, this._global);
35
44
  if (parsers.hasVarFunc(v)) {
36
- this._setProperty("font", "");
37
- this._setProperty("font-size", v);
45
+ this._setProperty(shorthand, "");
46
+ this._setProperty(property, v);
38
47
  } else {
39
- this._setProperty("font-size", module.exports.parse(v));
48
+ const val = module.exports.parse(v, {
49
+ globalObject: this._global
50
+ });
51
+ if (typeof val === "string") {
52
+ const shorthandPriority = this._priorities.get(shorthand);
53
+ const prior = this._priorities.get(property) ?? "";
54
+ const priority = shorthandPriority && prior ? "" : prior;
55
+ this._setProperty(property, val, priority);
56
+ }
40
57
  }
41
58
  },
42
59
  get() {
43
- return this.getPropertyValue("font-size");
60
+ return this.getPropertyValue(property);
44
61
  },
45
62
  enumerable: true,
46
63
  configurable: true
@@ -2,30 +2,61 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
6
- const keywords = ["normal", "italic", "oblique"];
7
- return parsers.parseKeyword(v, keywords);
8
- };
5
+ const property = "font-style";
6
+ const shorthand = "font";
9
7
 
10
- module.exports.isValid = function isValid(v) {
8
+ module.exports.parse = function parse(v, opt = {}) {
9
+ const { globalObject } = opt;
11
10
  if (v === "") {
12
- return true;
11
+ return v;
12
+ }
13
+ const value = parsers.parsePropertyValue(property, v, {
14
+ globalObject,
15
+ inArray: true
16
+ });
17
+ if (Array.isArray(value) && value.length) {
18
+ if (value.length === 1) {
19
+ const [{ name, type }] = value;
20
+ switch (type) {
21
+ case "GlobalKeyword":
22
+ case "Identifier": {
23
+ return name;
24
+ }
25
+ default:
26
+ }
27
+ } else if (value.length === 2) {
28
+ const [part1, part2] = value;
29
+ const val1 = part1.type === "Identifier" && part1.name;
30
+ const val2 = parsers.parseAngle([part2]);
31
+ if (val1 && val1 === "oblique" && val2) {
32
+ return `${val1} ${val2}`;
33
+ }
34
+ }
35
+ } else if (typeof value === "string") {
36
+ return value;
13
37
  }
14
- return typeof module.exports.parse(v) === "string";
15
38
  };
16
39
 
17
40
  module.exports.definition = {
18
41
  set(v) {
19
42
  v = parsers.prepareValue(v, this._global);
20
43
  if (parsers.hasVarFunc(v)) {
21
- this._setProperty("font", "");
22
- this._setProperty("font-style", v);
44
+ this._setProperty(shorthand, "");
45
+ this._setProperty(property, v);
23
46
  } else {
24
- this._setProperty("font-style", module.exports.parse(v));
47
+ const val = module.exports.parse(v, {
48
+ globalObject: this._global
49
+ });
50
+ if (typeof val === "string") {
51
+ const shorthandPriority = this._priorities.get(shorthand);
52
+ const prior = this._priorities.get(property) ?? "";
53
+ const priority = shorthandPriority && prior ? "" : prior;
54
+ this._setProperty(property, val, priority);
55
+ }
25
56
  }
26
57
  },
27
58
  get() {
28
- return this.getPropertyValue("font-style");
59
+ return this.getPropertyValue(property);
29
60
  },
30
61
  enumerable: true,
31
62
  configurable: true
@@ -2,34 +2,71 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
6
- const num = parsers.parseNumber(v, true);
7
- if (num && parseFloat(num) <= 1000) {
8
- return num;
9
- }
10
- const keywords = ["normal", "none", "small-caps"];
11
- return parsers.parseKeyword(v, keywords);
12
- };
5
+ const property = "font-variant";
6
+ const shorthand = "font";
13
7
 
14
- module.exports.isValid = function isValid(v) {
8
+ module.exports.parse = function parse(v, opt = {}) {
9
+ const { globalObject } = opt;
15
10
  if (v === "") {
16
- return true;
11
+ return v;
12
+ }
13
+ const values = parsers.splitValue(v);
14
+ const parsedValues = [];
15
+ for (const val of values) {
16
+ const value = parsers.parsePropertyValue(property, val, {
17
+ globalObject,
18
+ inArray: true
19
+ });
20
+ if (Array.isArray(value) && value.length === 1) {
21
+ const [{ name, type, value: itemValue }] = value;
22
+ switch (type) {
23
+ case "Function": {
24
+ parsedValues.push(`${name}(${itemValue})`);
25
+ break;
26
+ }
27
+ case "GlobalKeyword":
28
+ case "Identifier": {
29
+ parsedValues.push(name);
30
+ break;
31
+ }
32
+ default: {
33
+ return;
34
+ }
35
+ }
36
+ } else if (typeof value === "string") {
37
+ parsedValues.push(value);
38
+ }
39
+ }
40
+ if (parsedValues.length) {
41
+ if (parsedValues.length > 1) {
42
+ if (parsedValues.includes("normal") || parsedValues.includes("none")) {
43
+ return;
44
+ }
45
+ }
46
+ return parsedValues.join(" ");
17
47
  }
18
- return typeof module.exports.parse(v) === "string";
19
48
  };
20
49
 
21
50
  module.exports.definition = {
22
51
  set(v) {
23
52
  v = parsers.prepareValue(v, this._global);
24
53
  if (parsers.hasVarFunc(v)) {
25
- this._setProperty("font", "");
26
- this._setProperty("font-valiant", v);
54
+ this._setProperty(shorthand, "");
55
+ this._setProperty(property, v);
27
56
  } else {
28
- this._setProperty("font-variant", module.exports.parse(v));
57
+ const val = module.exports.parse(v, {
58
+ globalObject: this._global
59
+ });
60
+ if (typeof val === "string") {
61
+ const shorthandPriority = this._priorities.get(shorthand);
62
+ const prior = this._priorities.get(property) ?? "";
63
+ const priority = shorthandPriority && prior ? "" : prior;
64
+ this._setProperty(property, val, priority);
65
+ }
29
66
  }
30
67
  },
31
68
  get() {
32
- return this.getPropertyValue("font-variant");
69
+ return this.getPropertyValue(property);
33
70
  },
34
71
  enumerable: true,
35
72
  configurable: true
@@ -2,34 +2,66 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
6
- const num = parsers.parseNumber(v, true);
7
- if (num && parseFloat(num) <= 1000) {
8
- return num;
9
- }
10
- const keywords = ["normal", "bold", "lighter", "bolder"];
11
- return parsers.parseKeyword(v, keywords);
12
- };
5
+ const property = "font-weight";
6
+ const shorthand = "font";
13
7
 
14
- module.exports.isValid = function isValid(v) {
8
+ module.exports.parse = function parse(v, opt = {}) {
9
+ const { globalObject } = opt;
15
10
  if (v === "") {
16
- return true;
11
+ return v;
12
+ }
13
+ const value = parsers.parsePropertyValue(property, v, {
14
+ globalObject,
15
+ inArray: true
16
+ });
17
+ if (Array.isArray(value) && value.length === 1) {
18
+ const [{ isNumber, name, type, value: itemValue }] = value;
19
+ switch (type) {
20
+ case "Calc": {
21
+ if (isNumber) {
22
+ return `${name}(${itemValue})`;
23
+ }
24
+ break;
25
+ }
26
+ case "GlobalKeyword":
27
+ case "Identifier": {
28
+ return name;
29
+ }
30
+ default: {
31
+ const parsedValue = parsers.parseNumber(value, {
32
+ min: 1,
33
+ max: 1000
34
+ });
35
+ if (parsedValue) {
36
+ return parsedValue;
37
+ }
38
+ }
39
+ }
40
+ } else if (typeof value === "string") {
41
+ return value;
17
42
  }
18
- return typeof module.exports.parse(v) === "string";
19
43
  };
20
44
 
21
45
  module.exports.definition = {
22
46
  set(v) {
23
47
  v = parsers.prepareValue(v, this._global);
24
48
  if (parsers.hasVarFunc(v)) {
25
- this._setProperty("font", "");
26
- this._setProperty("font-weight", v);
49
+ this._setProperty(shorthand, "");
50
+ this._setProperty(property, v);
27
51
  } else {
28
- this._setProperty("font-weight", module.exports.parse(v));
52
+ const val = module.exports.parse(v, {
53
+ globalObject: this._global
54
+ });
55
+ if (typeof val === "string") {
56
+ const shorthandPriority = this._priorities.get(shorthand);
57
+ const prior = this._priorities.get(property) ?? "";
58
+ const priority = shorthandPriority && prior ? "" : prior;
59
+ this._setProperty(property, val, priority);
60
+ }
29
61
  }
30
62
  },
31
63
  get() {
32
- return this.getPropertyValue("font-weight");
64
+ return this.getPropertyValue(property);
33
65
  },
34
66
  enumerable: true,
35
67
  configurable: true
@@ -2,29 +2,56 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
6
- const dim = parsers.parseMeasurement(v, true);
7
- if (dim) {
8
- return dim;
9
- }
10
- const keywords = ["auto", "min-content", "max-content", "fit-content"];
11
- return parsers.parseKeyword(v, keywords);
12
- };
5
+ const property = "height";
13
6
 
14
- module.exports.isValid = function isValid(v) {
7
+ module.exports.parse = function parse(v, opt = {}) {
8
+ const { globalObject } = opt;
15
9
  if (v === "") {
16
- return true;
10
+ return v;
11
+ }
12
+ const value = parsers.parsePropertyValue(property, v, {
13
+ globalObject,
14
+ inArray: true
15
+ });
16
+ if (Array.isArray(value) && value.length === 1) {
17
+ const [{ isNumber, name, type, value: itemValue }] = value;
18
+ switch (type) {
19
+ case "Calc": {
20
+ if (isNumber) {
21
+ return;
22
+ }
23
+ return `${name}(${itemValue})`;
24
+ }
25
+ case "GlobalKeyword":
26
+ case "Identifier": {
27
+ return name;
28
+ }
29
+ default: {
30
+ return parsers.parseLengthPercentage(value);
31
+ }
32
+ }
33
+ } else if (typeof value === "string") {
34
+ return value;
17
35
  }
18
- return typeof module.exports.parse(v) === "string";
19
36
  };
20
37
 
21
38
  module.exports.definition = {
22
39
  set(v) {
23
40
  v = parsers.prepareValue(v, this._global);
24
- this._setProperty("height", module.exports.parse(v));
41
+ if (parsers.hasVarFunc(v)) {
42
+ this._setProperty(property, v);
43
+ } else {
44
+ const val = module.exports.parse(v, {
45
+ globalObject: this._global
46
+ });
47
+ if (typeof val === "string") {
48
+ const priority = this._priorities.get(property) ?? "";
49
+ this._setProperty(property, val, priority);
50
+ }
51
+ }
25
52
  },
26
53
  get() {
27
- return this.getPropertyValue("height");
54
+ return this.getPropertyValue(property);
28
55
  },
29
56
  enumerable: true,
30
57
  configurable: true
@@ -2,28 +2,56 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
6
- const dim = parsers.parseMeasurement(v);
7
- if (dim) {
8
- return dim;
9
- }
10
- return parsers.parseKeyword(v, ["auto"]);
11
- };
5
+ const property = "left";
12
6
 
13
- module.exports.isValid = function isValid(v) {
7
+ module.exports.parse = function parse(v, opt = {}) {
8
+ const { globalObject } = opt;
14
9
  if (v === "") {
15
- return true;
10
+ return v;
11
+ }
12
+ const value = parsers.parsePropertyValue(property, v, {
13
+ globalObject,
14
+ inArray: true
15
+ });
16
+ if (Array.isArray(value) && value.length === 1) {
17
+ const [{ isNumber, name, type, value: itemValue }] = value;
18
+ switch (type) {
19
+ case "Calc": {
20
+ if (isNumber) {
21
+ return;
22
+ }
23
+ return `${name}(${itemValue})`;
24
+ }
25
+ case "GlobalKeyword":
26
+ case "Identifier": {
27
+ return name;
28
+ }
29
+ default: {
30
+ return parsers.parseLengthPercentage(value);
31
+ }
32
+ }
33
+ } else if (typeof value === "string") {
34
+ return value;
16
35
  }
17
- return typeof module.exports.parse(v) === "string";
18
36
  };
19
37
 
20
38
  module.exports.definition = {
21
39
  set(v) {
22
40
  v = parsers.prepareValue(v, this._global);
23
- this._setProperty("left", module.exports.parse(v));
41
+ if (parsers.hasVarFunc(v)) {
42
+ this._setProperty(property, v);
43
+ } else {
44
+ const val = module.exports.parse(v, {
45
+ globalObject: this._global
46
+ });
47
+ if (typeof val === "string") {
48
+ const priority = this._priorities.get(property) ?? "";
49
+ this._setProperty(property, val, priority);
50
+ }
51
+ }
24
52
  },
25
53
  get() {
26
- return this.getPropertyValue("left");
54
+ return this.getPropertyValue(property);
27
55
  },
28
56
  enumerable: true,
29
57
  configurable: true
@@ -2,28 +2,49 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
6
- const val = parsers.parseColor(v);
7
- if (val) {
8
- return val;
9
- }
10
- return parsers.parseKeyword(v);
11
- };
5
+ const property = "lighting-color";
12
6
 
13
- module.exports.isValid = function isValid(v) {
14
- if (v === "" || typeof parsers.parseKeyword(v) === "string") {
15
- return true;
7
+ module.exports.parse = function parse(v, opt = {}) {
8
+ const { globalObject } = opt;
9
+ if (v === "") {
10
+ return v;
11
+ }
12
+ const value = parsers.parsePropertyValue(property, v, {
13
+ globalObject,
14
+ inArray: true
15
+ });
16
+ if (Array.isArray(value) && value.length === 1) {
17
+ const [{ name, type }] = value;
18
+ switch (type) {
19
+ case "GlobalKeyword": {
20
+ return name;
21
+ }
22
+ default: {
23
+ return parsers.parseColor(value);
24
+ }
25
+ }
26
+ } else if (typeof value === "string") {
27
+ return value;
16
28
  }
17
- return parsers.isValidColor(v);
18
29
  };
19
30
 
20
31
  module.exports.definition = {
21
32
  set(v) {
22
33
  v = parsers.prepareValue(v, this._global);
23
- this._setProperty("lighting-color", module.exports.parse(v));
34
+ if (parsers.hasVarFunc(v)) {
35
+ this._setProperty(property, v);
36
+ } else {
37
+ const val = module.exports.parse(v, {
38
+ globalObject: this._global
39
+ });
40
+ if (typeof val === "string") {
41
+ const priority = this._priorities.get(property) ?? "";
42
+ this._setProperty(property, val, priority);
43
+ }
44
+ }
24
45
  },
25
46
  get() {
26
- return this.getPropertyValue("lighting-color");
47
+ return this.getPropertyValue(property);
27
48
  },
28
49
  enumerable: true,
29
50
  configurable: true