cssstyle 5.2.1 → 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
@@ -10,17 +10,7 @@ const backgroundClip = require("./backgroundClip");
10
10
  const backgroundAttachment = require("./backgroundAttachment");
11
11
  const backgroundColor = require("./backgroundColor");
12
12
 
13
- module.exports.shorthandFor = new Map([
14
- ["background-image", backgroundImage],
15
- ["background-position", backgroundPosition],
16
- ["background-size", backgroundSize],
17
- ["background-repeat", backgroundRepeat],
18
- ["background-origin", backgroundOrigin],
19
- ["background-clip", backgroundClip],
20
- ["background-attachment", backgroundAttachment],
21
- ["background-color", backgroundColor]
22
- ]);
23
-
13
+ const property = "background";
24
14
  const initialValues = new Map([
25
15
  ["background-image", "none"],
26
16
  ["background-position", "0% 0%"],
@@ -32,7 +22,27 @@ const initialValues = new Map([
32
22
  ["background-color", "transparent"]
33
23
  ]);
34
24
 
35
- module.exports.parse = function parse(v) {
25
+ module.exports.shorthandFor = new Map([
26
+ ["background-image", backgroundImage],
27
+ ["background-position", backgroundPosition],
28
+ ["background-size", backgroundSize],
29
+ ["background-repeat", backgroundRepeat],
30
+ ["background-origin", backgroundOrigin],
31
+ ["background-clip", backgroundClip],
32
+ ["background-attachment", backgroundAttachment],
33
+ ["background-color", backgroundColor]
34
+ ]);
35
+
36
+ module.exports.parse = function parse(v, opt = {}) {
37
+ const { globalObject } = opt;
38
+ if (v === "") {
39
+ return v;
40
+ } else if (parsers.hasCalcFunc(v)) {
41
+ v = parsers.resolveCalc(v);
42
+ }
43
+ if (!parsers.isValidPropertyValue(property, v)) {
44
+ return;
45
+ }
36
46
  const values = parsers.splitValue(v, {
37
47
  delimiter: ","
38
48
  });
@@ -74,13 +84,13 @@ module.exports.parse = function parse(v) {
74
84
  const parts1 = parsers.splitValue(bgPart1);
75
85
  for (const part of parts1) {
76
86
  let partValid = false;
77
- for (const [property, value] of module.exports.shorthandFor) {
78
- if (value.isValid(part)) {
87
+ for (const [longhand, value] of module.exports.shorthandFor) {
88
+ if (parsers.isValidPropertyValue(longhand, part)) {
79
89
  partValid = true;
80
- switch (property) {
90
+ switch (longhand) {
81
91
  case "background-clip":
82
92
  case "background-origin": {
83
- const parsedValue = value.parse(part);
93
+ const parsedValue = value.parse(part, { globalObject });
84
94
  if (parsedValue) {
85
95
  bgBox.push(parsedValue);
86
96
  }
@@ -90,21 +100,21 @@ module.exports.parse = function parse(v) {
90
100
  if (i !== values.length - 1) {
91
101
  return;
92
102
  }
93
- const parsedValue = value.parse(part);
103
+ const parsedValue = value.parse(part, { globalObject });
94
104
  if (parsedValue) {
95
- bg[property] = parsedValue;
105
+ bg[longhand] = parsedValue;
96
106
  }
97
107
  break;
98
108
  }
99
109
  case "background-position": {
100
- const parsedValue = value.parse(part);
110
+ const parsedValue = value.parse(part, { globalObject });
101
111
  if (parsedValue) {
102
112
  bgPosition.push(parsedValue);
103
113
  }
104
114
  break;
105
115
  }
106
116
  case "background-repeat": {
107
- const parsedValue = value.parse(part);
117
+ const parsedValue = value.parse(part, { globalObject });
108
118
  if (parsedValue) {
109
119
  bgRepeat.push(parsedValue);
110
120
  }
@@ -114,9 +124,9 @@ module.exports.parse = function parse(v) {
114
124
  break;
115
125
  }
116
126
  default: {
117
- const parsedValue = value.parse(part);
127
+ const parsedValue = value.parse(part, { globalObject });
118
128
  if (parsedValue) {
119
- bg[property] = parsedValue;
129
+ bg[longhand] = parsedValue;
120
130
  }
121
131
  }
122
132
  }
@@ -130,13 +140,13 @@ module.exports.parse = function parse(v) {
130
140
  const parts2 = parsers.splitValue(bgPart2);
131
141
  for (const part of parts2) {
132
142
  let partValid = false;
133
- for (const [property, value] of module.exports.shorthandFor) {
134
- if (value.isValid(part)) {
143
+ for (const [longhand, value] of module.exports.shorthandFor) {
144
+ if (parsers.isValidPropertyValue(longhand, part)) {
135
145
  partValid = true;
136
- switch (property) {
146
+ switch (longhand) {
137
147
  case "background-clip":
138
148
  case "background-origin": {
139
- const parsedValue = value.parse(part);
149
+ const parsedValue = value.parse(part, { globalObject });
140
150
  if (parsedValue) {
141
151
  bgBox.push(parsedValue);
142
152
  }
@@ -146,9 +156,9 @@ module.exports.parse = function parse(v) {
146
156
  if (i !== l - 1) {
147
157
  return;
148
158
  }
149
- const parsedValue = value.parse(part);
159
+ const parsedValue = value.parse(part, { globalObject });
150
160
  if (parsedValue) {
151
- bg[property] = parsedValue;
161
+ bg[longhand] = parsedValue;
152
162
  }
153
163
  break;
154
164
  }
@@ -156,23 +166,23 @@ module.exports.parse = function parse(v) {
156
166
  break;
157
167
  }
158
168
  case "background-repeat": {
159
- const parsedValue = value.parse(part);
169
+ const parsedValue = value.parse(part, { globalObject });
160
170
  if (parsedValue) {
161
171
  bgRepeat.push(parsedValue);
162
172
  }
163
173
  break;
164
174
  }
165
175
  case "background-size": {
166
- const parsedValue = value.parse(part);
176
+ const parsedValue = value.parse(part, { globalObject });
167
177
  if (parsedValue) {
168
178
  bgSize.push(parsedValue);
169
179
  }
170
180
  break;
171
181
  }
172
182
  default: {
173
- const parsedValue = value.parse(part);
183
+ const parsedValue = value.parse(part, { globalObject });
174
184
  if (parsedValue) {
175
- bg[property] = parsedValue;
185
+ bg[longhand] = parsedValue;
176
186
  }
177
187
  }
178
188
  }
@@ -185,21 +195,21 @@ module.exports.parse = function parse(v) {
185
195
  }
186
196
  if (bgPosition.length) {
187
197
  const { parse: parser } = module.exports.shorthandFor.get("background-position");
188
- const value = parser(bgPosition.join(" "));
198
+ const value = parser(bgPosition.join(" "), { globalObject });
189
199
  if (value) {
190
200
  bg["background-position"] = value;
191
201
  }
192
202
  }
193
203
  if (bgSize.length) {
194
204
  const { parse: parser } = module.exports.shorthandFor.get("background-size");
195
- const value = parser(bgSize.join(" "));
205
+ const value = parser(bgSize.join(" "), { globalObject });
196
206
  if (value) {
197
207
  bg["background-size"] = value;
198
208
  }
199
209
  }
200
210
  if (bgRepeat.length) {
201
211
  const { parse: parser } = module.exports.shorthandFor.get("background-repeat");
202
- const value = parser(bgRepeat.join(" "));
212
+ const value = parser(bgRepeat.join(" "), { globalObject });
203
213
  if (value) {
204
214
  bg["background-repeat"] = value;
205
215
  }
@@ -235,9 +245,11 @@ module.exports.definition = {
235
245
  for (const [key] of module.exports.shorthandFor) {
236
246
  this._setProperty(key, "");
237
247
  }
238
- this._setProperty("background", v);
248
+ this._setProperty(property, v);
239
249
  } else {
240
- const bgValues = module.exports.parse(v);
250
+ const bgValues = module.exports.parse(v, {
251
+ globalObject: this._global
252
+ });
241
253
  if (!Array.isArray(bgValues)) {
242
254
  return;
243
255
  }
@@ -254,22 +266,22 @@ module.exports.definition = {
254
266
  const backgrounds = [];
255
267
  for (const bgValue of bgValues) {
256
268
  const bg = [];
257
- for (const [property, value] of Object.entries(bgValue)) {
269
+ for (const [longhand, value] of Object.entries(bgValue)) {
258
270
  if (value) {
259
- const arr = bgMap.get(property);
271
+ const arr = bgMap.get(longhand);
260
272
  arr.push(value);
261
- bgMap.set(property, arr);
262
- if (value !== initialValues.get(property)) {
263
- if (property === "background-size") {
273
+ bgMap.set(longhand, arr);
274
+ if (value !== initialValues.get(longhand)) {
275
+ if (longhand === "background-size") {
264
276
  bg.push(`/ ${value}`);
265
277
  } else {
266
278
  bg.push(value);
267
279
  }
268
- } else if (property === "background-image") {
280
+ } else if (longhand === "background-image") {
269
281
  if (v === "none") {
270
282
  bg.push(value);
271
283
  }
272
- } else if (property === "background-color") {
284
+ } else if (longhand === "background-color") {
273
285
  if (v === "transparent") {
274
286
  bg.push(value);
275
287
  }
@@ -278,22 +290,23 @@ module.exports.definition = {
278
290
  }
279
291
  backgrounds.push(bg.join(" "));
280
292
  }
281
- for (const [property, value] of bgMap) {
282
- this._setProperty(property, value.join(", "));
293
+ const priority = this._priorities.get(property) ?? "";
294
+ for (const [longhand, value] of bgMap) {
295
+ this._setProperty(longhand, value.join(", "), priority);
283
296
  }
284
- this._setProperty("background", backgrounds.join(", "));
297
+ this._setProperty(property, backgrounds.join(", "), priority);
285
298
  }
286
299
  },
287
300
  get() {
288
- const v = this.getPropertyValue("background");
301
+ const v = this.getPropertyValue(property);
289
302
  if (parsers.hasVarFunc(v)) {
290
303
  return v;
291
304
  }
292
305
  const bgMap = new Map();
293
306
  let l = 0;
294
- for (const [property] of module.exports.shorthandFor) {
295
- const val = this.getPropertyValue(property);
296
- if (property === "background-image") {
307
+ for (const [longhand] of module.exports.shorthandFor) {
308
+ const val = this.getPropertyValue(longhand);
309
+ if (longhand === "background-image") {
297
310
  if (
298
311
  val === "none" &&
299
312
  v === "none" &&
@@ -301,20 +314,20 @@ module.exports.definition = {
301
314
  ) {
302
315
  return val;
303
316
  }
304
- if (val !== initialValues.get(property)) {
317
+ if (val !== initialValues.get(longhand)) {
305
318
  const imgValues = parsers.splitValue(val, {
306
319
  delimiter: ","
307
320
  });
308
321
  l = imgValues.length;
309
- bgMap.set(property, imgValues);
322
+ bgMap.set(longhand, imgValues);
310
323
  }
311
- } else if (property === "background-color") {
312
- if (val !== initialValues.get(property) || v.includes(val)) {
313
- bgMap.set(property, [val]);
324
+ } else if (longhand === "background-color") {
325
+ if (val !== initialValues.get(longhand) || v.includes(val)) {
326
+ bgMap.set(longhand, [val]);
314
327
  }
315
- } else if (val !== initialValues.get(property)) {
328
+ } else if (val !== initialValues.get(longhand)) {
316
329
  bgMap.set(
317
- property,
330
+ longhand,
318
331
  parsers.splitValue(val, {
319
332
  delimiter: ","
320
333
  })
@@ -332,16 +345,16 @@ module.exports.definition = {
332
345
  for (let i = 0; i < l; i++) {
333
346
  bgValues[i] = [];
334
347
  }
335
- for (const [property, values] of bgMap) {
348
+ for (const [longhand, values] of bgMap) {
336
349
  for (let i = 0; i < l; i++) {
337
- switch (property) {
350
+ switch (longhand) {
338
351
  case "background-color": {
339
352
  if (i === l - 1) {
340
353
  const value = values[0];
341
354
  if (parsers.hasVarFunc(value)) {
342
355
  return "";
343
356
  }
344
- if (value && value !== initialValues.get(property)) {
357
+ if (value && value !== initialValues.get(longhand)) {
345
358
  const bgValue = bgValues[i];
346
359
  bgValue.push(value);
347
360
  }
@@ -353,7 +366,7 @@ module.exports.definition = {
353
366
  if (parsers.hasVarFunc(value)) {
354
367
  return "";
355
368
  }
356
- if (value && value !== initialValues.get(property)) {
369
+ if (value && value !== initialValues.get(longhand)) {
357
370
  const bgValue = bgValues[i];
358
371
  bgValue.push(`/ ${value}`);
359
372
  }
@@ -364,7 +377,7 @@ module.exports.definition = {
364
377
  if (parsers.hasVarFunc(value)) {
365
378
  return "";
366
379
  }
367
- if (value && value !== initialValues.get(property)) {
380
+ if (value && value !== initialValues.get(longhand)) {
368
381
  const bgValue = bgValues[i];
369
382
  bgValue.push(value);
370
383
  }
@@ -2,21 +2,35 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
5
+ const property = "background-attachment";
6
+ const shorthand = "background";
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 values = parsers.splitValue(v, {
10
- delimiter: ","
11
- });
12
- const keywords = ["fixed", "scroll", "local"];
13
+ const values = parsers.splitValue(v, { delimiter: "," });
13
14
  const parsedValues = [];
14
- for (const value of values) {
15
- const parsedValue = parsers.parseKeyword(value, keywords);
16
- if (parsedValue) {
17
- parsedValues.push(parsedValue);
18
- } else {
19
- return;
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;
22
+ switch (type) {
23
+ case "GlobalKeyword":
24
+ case "Identifier": {
25
+ parsedValues.push(name);
26
+ break;
27
+ }
28
+ default: {
29
+ return;
30
+ }
31
+ }
32
+ } else if (typeof value === "string") {
33
+ parsedValues.push(value);
20
34
  }
21
35
  }
22
36
  if (parsedValues.length) {
@@ -24,25 +38,26 @@ module.exports.parse = function parse(v) {
24
38
  }
25
39
  };
26
40
 
27
- module.exports.isValid = function isValid(v) {
28
- if (v === "") {
29
- return true;
30
- }
31
- return typeof module.exports.parse(v) === "string";
32
- };
33
-
34
41
  module.exports.definition = {
35
42
  set(v) {
36
43
  v = parsers.prepareValue(v, this._global);
37
44
  if (parsers.hasVarFunc(v)) {
38
- this._setProperty("background", "");
39
- this._setProperty("background-attachment", v);
45
+ this._setProperty(shorthand, "");
46
+ this._setProperty(property, v);
40
47
  } else {
41
- this._setProperty("background-attachment", 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
+ }
42
57
  }
43
58
  },
44
59
  get() {
45
- return this.getPropertyValue("background-attachment");
60
+ return this.getPropertyValue(property);
46
61
  },
47
62
  enumerable: true,
48
63
  configurable: true
@@ -2,21 +2,35 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
5
+ const property = "background-clip";
6
+ const shorthand = "background";
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 values = parsers.splitValue(v, {
10
- delimiter: ","
11
- });
12
- const keywords = ["border-box", "padding-box", "content-box"];
13
+ const values = parsers.splitValue(v, { delimiter: "," });
13
14
  const parsedValues = [];
14
- for (const value of values) {
15
- const parsedValue = parsers.parseKeyword(value, keywords);
16
- if (parsedValue) {
17
- parsedValues.push(parsedValue);
18
- } else {
19
- return;
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;
22
+ switch (type) {
23
+ case "GlobalKeyword":
24
+ case "Identifier": {
25
+ parsedValues.push(name);
26
+ break;
27
+ }
28
+ default: {
29
+ return;
30
+ }
31
+ }
32
+ } else if (typeof value === "string") {
33
+ parsedValues.push(value);
20
34
  }
21
35
  }
22
36
  if (parsedValues.length) {
@@ -24,25 +38,26 @@ module.exports.parse = function parse(v) {
24
38
  }
25
39
  };
26
40
 
27
- module.exports.isValid = function isValid(v) {
28
- if (v === "") {
29
- return true;
30
- }
31
- return typeof module.exports.parse(v) === "string";
32
- };
33
-
34
41
  module.exports.definition = {
35
42
  set(v) {
36
43
  v = parsers.prepareValue(v, this._global);
37
44
  if (parsers.hasVarFunc(v)) {
38
- this._setProperty("background", "");
39
- this._setProperty("background-clip", v);
45
+ this._setProperty(shorthand, "");
46
+ this._setProperty(property, v);
40
47
  } else {
41
- this._setProperty("background-clip", 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
+ }
42
57
  }
43
58
  },
44
59
  get() {
45
- return this.getPropertyValue("background-clip");
60
+ return this.getPropertyValue(property);
46
61
  },
47
62
  enumerable: true,
48
63
  configurable: true
@@ -2,33 +2,53 @@
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 = "background-color";
6
+ const shorthand = "background";
12
7
 
13
- module.exports.isValid = function isValid(v) {
14
- if (v === "" || typeof parsers.parseKeyword(v) === "string") {
15
- return true;
8
+ module.exports.parse = function parse(v, opt = {}) {
9
+ const { globalObject } = opt;
10
+ if (v === "") {
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 [{ name, type }] = value;
19
+ switch (type) {
20
+ case "GlobalKeyword": {
21
+ return name;
22
+ }
23
+ default: {
24
+ return parsers.parseColor(value);
25
+ }
26
+ }
27
+ } else if (typeof value === "string") {
28
+ return value;
16
29
  }
17
- return parsers.isValidColor(v);
18
30
  };
19
31
 
20
32
  module.exports.definition = {
21
33
  set(v) {
22
34
  v = parsers.prepareValue(v, this._global);
23
35
  if (parsers.hasVarFunc(v)) {
24
- this._setProperty("background", "");
25
- this._setProperty("background-color", v);
36
+ this._setProperty(shorthand, "");
37
+ this._setProperty(property, v);
26
38
  } else {
27
- this._setProperty("background-color", module.exports.parse(v));
39
+ const val = module.exports.parse(v, {
40
+ globalObject: this._global
41
+ });
42
+ if (typeof val === "string") {
43
+ const shorthandPriority = this._priorities.get(shorthand);
44
+ const prior = this._priorities.get(property) ?? "";
45
+ const priority = shorthandPriority && prior ? "" : prior;
46
+ this._setProperty(property, val, priority);
47
+ }
28
48
  }
29
49
  },
30
50
  get() {
31
- return this.getPropertyValue("background-color");
51
+ return this.getPropertyValue(property);
32
52
  },
33
53
  enumerable: true,
34
54
  configurable: true
@@ -2,18 +2,47 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
5
+ const property = "background-image";
6
+ const shorthand = "background";
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 values = parsers.splitValue(v, {
10
- delimiter: ","
11
- });
13
+ const values = parsers.splitValue(v, { delimiter: "," });
12
14
  const parsedValues = [];
13
- for (const value of values) {
14
- const parsedValue = parsers.parseImage(value);
15
- if (parsedValue) {
16
- parsedValues.push(parsedValue);
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;
22
+ switch (type) {
23
+ case "GlobalKeyword":
24
+ case "Identifier": {
25
+ parsedValues.push(name);
26
+ break;
27
+ }
28
+ case "Url": {
29
+ const parsedValue = parsers.parseUrl(value);
30
+ if (!parsedValue) {
31
+ return;
32
+ }
33
+ parsedValues.push(parsedValue);
34
+ break;
35
+ }
36
+ default: {
37
+ const parsedValue = parsers.parseGradient(value);
38
+ if (!parsedValue) {
39
+ return;
40
+ }
41
+ parsedValues.push(parsedValue);
42
+ }
43
+ }
44
+ } else if (typeof value === "string") {
45
+ parsedValues.push(value);
17
46
  } else {
18
47
  return;
19
48
  }
@@ -23,25 +52,26 @@ module.exports.parse = function parse(v) {
23
52
  }
24
53
  };
25
54
 
26
- module.exports.isValid = function isValid(v) {
27
- if (v === "") {
28
- return true;
29
- }
30
- return typeof module.exports.parse(v) === "string";
31
- };
32
-
33
55
  module.exports.definition = {
34
56
  set(v) {
35
57
  v = parsers.prepareValue(v, this._global);
36
58
  if (parsers.hasVarFunc(v)) {
37
- this._setProperty("background", "");
38
- this._setProperty("background-image", v);
59
+ this._setProperty(shorthand, "");
60
+ this._setProperty(property, v);
39
61
  } else {
40
- this._setProperty("background-image", module.exports.parse(v));
62
+ const val = module.exports.parse(v, {
63
+ globalObject: this._global
64
+ });
65
+ if (typeof val === "string") {
66
+ const shorthandPriority = this._priorities.get(shorthand);
67
+ const prior = this._priorities.get(property) ?? "";
68
+ const priority = shorthandPriority && prior ? "" : prior;
69
+ this._setProperty(property, val, priority);
70
+ }
41
71
  }
42
72
  },
43
73
  get() {
44
- return this.getPropertyValue("background-image");
74
+ return this.getPropertyValue(property);
45
75
  },
46
76
  enumerable: true,
47
77
  configurable: true