cssstyle 5.3.5 → 5.3.7

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 (86) hide show
  1. package/lib/CSSStyleDeclaration.js +6 -5
  2. package/lib/generated/implementedProperties.js +1 -1
  3. package/lib/generated/properties.js +2034 -2348
  4. package/lib/generated/propertyDefinitions.js +13033 -0
  5. package/lib/normalize.js +1252 -1095
  6. package/lib/parsers.js +589 -253
  7. package/lib/properties/background.js +90 -80
  8. package/lib/properties/backgroundAttachment.js +12 -15
  9. package/lib/properties/backgroundClip.js +12 -15
  10. package/lib/properties/backgroundColor.js +9 -14
  11. package/lib/properties/backgroundImage.js +12 -27
  12. package/lib/properties/backgroundOrigin.js +12 -15
  13. package/lib/properties/backgroundPosition.js +30 -19
  14. package/lib/properties/backgroundRepeat.js +12 -8
  15. package/lib/properties/backgroundSize.js +23 -17
  16. package/lib/properties/border.js +31 -88
  17. package/lib/properties/borderBottom.js +31 -87
  18. package/lib/properties/borderBottomColor.js +9 -15
  19. package/lib/properties/borderBottomStyle.js +9 -14
  20. package/lib/properties/borderBottomWidth.js +12 -24
  21. package/lib/properties/borderCollapse.js +5 -10
  22. package/lib/properties/borderColor.js +18 -24
  23. package/lib/properties/borderLeft.js +31 -87
  24. package/lib/properties/borderLeftColor.js +9 -15
  25. package/lib/properties/borderLeftStyle.js +9 -14
  26. package/lib/properties/borderLeftWidth.js +12 -24
  27. package/lib/properties/borderRight.js +31 -87
  28. package/lib/properties/borderRightColor.js +9 -15
  29. package/lib/properties/borderRightStyle.js +9 -14
  30. package/lib/properties/borderRightWidth.js +12 -24
  31. package/lib/properties/borderSpacing.js +13 -10
  32. package/lib/properties/borderStyle.js +18 -24
  33. package/lib/properties/borderTop.js +31 -87
  34. package/lib/properties/borderTopColor.js +9 -15
  35. package/lib/properties/borderTopStyle.js +9 -14
  36. package/lib/properties/borderTopWidth.js +12 -24
  37. package/lib/properties/borderWidth.js +19 -37
  38. package/lib/properties/bottom.js +7 -18
  39. package/lib/properties/clear.js +5 -10
  40. package/lib/properties/clip.js +11 -6
  41. package/lib/properties/color.js +5 -11
  42. package/lib/properties/display.js +12 -9
  43. package/lib/properties/flex.js +56 -54
  44. package/lib/properties/flexBasis.js +11 -21
  45. package/lib/properties/flexGrow.js +11 -20
  46. package/lib/properties/flexShrink.js +11 -20
  47. package/lib/properties/float.js +5 -10
  48. package/lib/properties/floodColor.js +5 -11
  49. package/lib/properties/font.js +47 -34
  50. package/lib/properties/fontFamily.js +17 -13
  51. package/lib/properties/fontSize.js +12 -23
  52. package/lib/properties/fontStyle.js +15 -9
  53. package/lib/properties/fontVariant.js +12 -19
  54. package/lib/properties/fontWeight.js +15 -26
  55. package/lib/properties/height.js +8 -18
  56. package/lib/properties/left.js +7 -18
  57. package/lib/properties/lightingColor.js +5 -11
  58. package/lib/properties/lineHeight.js +11 -25
  59. package/lib/properties/margin.js +15 -33
  60. package/lib/properties/marginBottom.js +11 -21
  61. package/lib/properties/marginLeft.js +11 -21
  62. package/lib/properties/marginRight.js +11 -21
  63. package/lib/properties/marginTop.js +11 -21
  64. package/lib/properties/opacity.js +7 -19
  65. package/lib/properties/outlineColor.js +5 -11
  66. package/lib/properties/padding.js +16 -31
  67. package/lib/properties/paddingBottom.js +12 -22
  68. package/lib/properties/paddingLeft.js +12 -22
  69. package/lib/properties/paddingRight.js +12 -22
  70. package/lib/properties/paddingTop.js +12 -22
  71. package/lib/properties/right.js +7 -18
  72. package/lib/properties/stopColor.js +5 -11
  73. package/lib/properties/top.js +7 -18
  74. package/lib/properties/webkitBorderAfterColor.js +5 -11
  75. package/lib/properties/webkitBorderBeforeColor.js +5 -11
  76. package/lib/properties/webkitBorderEndColor.js +5 -11
  77. package/lib/properties/webkitBorderStartColor.js +5 -11
  78. package/lib/properties/webkitColumnRuleColor.js +5 -11
  79. package/lib/properties/webkitTapHighlightColor.js +5 -11
  80. package/lib/properties/webkitTextEmphasisColor.js +5 -11
  81. package/lib/properties/webkitTextFillColor.js +5 -11
  82. package/lib/properties/webkitTextStrokeColor.js +5 -11
  83. package/lib/properties/width.js +8 -18
  84. package/lib/utils/propertyDescriptors.js +49 -13
  85. package/lib/utils/strings.js +6 -0
  86. package/package.json +8 -27
@@ -5,11 +5,12 @@ const parsers = require("../parsers");
5
5
  const property = "font-family";
6
6
  const shorthand = "font";
7
7
 
8
- module.exports.parse = function parse(v, opt = {}) {
8
+ module.exports.parse = (v, opt = {}) => {
9
9
  const { globalObject } = opt;
10
10
  if (v === "") {
11
11
  return v;
12
12
  }
13
+ const { AST_TYPES } = parsers;
13
14
  const values = parsers.splitValue(v, {
14
15
  delimiter: ","
15
16
  });
@@ -24,15 +25,16 @@ module.exports.parse = function parse(v, opt = {}) {
24
25
  if (value.length === 1) {
25
26
  const [{ name, type, value: itemValue }] = value;
26
27
  switch (type) {
27
- case "Function": {
28
+ case AST_TYPES.FUNCTION: {
28
29
  parsedValues.push(`${name}(${itemValue})`);
29
30
  break;
30
31
  }
31
- case "GlobalKeyword":
32
- case "Identifier": {
33
- if (name !== "undefined") {
34
- parsedValues.push(name);
32
+ case AST_TYPES.GLOBAL_KEYWORD:
33
+ case AST_TYPES.IDENTIFIER: {
34
+ if (name === "undefined") {
35
+ return;
35
36
  }
37
+ parsedValues.push(name);
36
38
  break;
37
39
  }
38
40
  case "String": {
@@ -48,11 +50,10 @@ module.exports.parse = function parse(v, opt = {}) {
48
50
  const parts = [];
49
51
  for (const item of value) {
50
52
  const { name, type } = item;
51
- if (type === "Identifier") {
52
- parts.push(name);
53
- } else {
53
+ if (type !== AST_TYPES.IDENTIFIER) {
54
54
  return;
55
55
  }
56
+ parts.push(name);
56
57
  }
57
58
  const parsedValue = parts.join(" ").replaceAll("\\", "").replaceAll('"', '\\"');
58
59
  parsedValues.push(`"${parsedValue}"`);
@@ -70,7 +71,7 @@ module.exports.parse = function parse(v, opt = {}) {
70
71
 
71
72
  module.exports.definition = {
72
73
  set(v) {
73
- v = parsers.prepareValue(v, this._global);
74
+ v = parsers.prepareValue(v);
74
75
  if (parsers.hasVarFunc(v)) {
75
76
  this._setProperty(shorthand, "");
76
77
  this._setProperty(property, v);
@@ -79,9 +80,10 @@ module.exports.definition = {
79
80
  globalObject: this._global
80
81
  });
81
82
  if (typeof val === "string") {
82
- const shorthandPriority = this._priorities.get(shorthand);
83
- const prior = this._priorities.get(property) ?? "";
84
- const priority = shorthandPriority && prior ? "" : prior;
83
+ const priority =
84
+ !this._priorities.get(shorthand) && this._priorities.has(property)
85
+ ? this._priorities.get(property)
86
+ : "";
85
87
  this._setProperty(property, val, priority);
86
88
  }
87
89
  }
@@ -92,3 +94,5 @@ module.exports.definition = {
92
94
  enumerable: true,
93
95
  configurable: true
94
96
  };
97
+
98
+ module.exports.property = property;
@@ -5,7 +5,7 @@ const parsers = require("../parsers");
5
5
  const property = "font-size";
6
6
  const shorthand = "font";
7
7
 
8
- module.exports.parse = function parse(v, opt = {}) {
8
+ module.exports.parse = (v, opt = {}) => {
9
9
  const { globalObject } = opt;
10
10
  if (v === "") {
11
11
  return v;
@@ -15,24 +15,10 @@ module.exports.parse = function parse(v, opt = {}) {
15
15
  inArray: true
16
16
  });
17
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
- }
18
+ return parsers.resolveNumericValue(value, {
19
+ min: 0,
20
+ type: "length"
21
+ });
36
22
  } else if (typeof value === "string") {
37
23
  return value;
38
24
  }
@@ -40,7 +26,7 @@ module.exports.parse = function parse(v, opt = {}) {
40
26
 
41
27
  module.exports.definition = {
42
28
  set(v) {
43
- v = parsers.prepareValue(v, this._global);
29
+ v = parsers.prepareValue(v);
44
30
  if (parsers.hasVarFunc(v)) {
45
31
  this._setProperty(shorthand, "");
46
32
  this._setProperty(property, v);
@@ -49,9 +35,10 @@ module.exports.definition = {
49
35
  globalObject: this._global
50
36
  });
51
37
  if (typeof val === "string") {
52
- const shorthandPriority = this._priorities.get(shorthand);
53
- const prior = this._priorities.get(property) ?? "";
54
- const priority = shorthandPriority && prior ? "" : prior;
38
+ const priority =
39
+ !this._priorities.get(shorthand) && this._priorities.has(property)
40
+ ? this._priorities.get(property)
41
+ : "";
55
42
  this._setProperty(property, val, priority);
56
43
  }
57
44
  }
@@ -62,3 +49,5 @@ module.exports.definition = {
62
49
  enumerable: true,
63
50
  configurable: true
64
51
  };
52
+
53
+ module.exports.property = property;
@@ -5,11 +5,12 @@ const parsers = require("../parsers");
5
5
  const property = "font-style";
6
6
  const shorthand = "font";
7
7
 
8
- module.exports.parse = function parse(v, opt = {}) {
8
+ module.exports.parse = (v, opt = {}) => {
9
9
  const { globalObject } = opt;
10
10
  if (v === "") {
11
11
  return v;
12
12
  }
13
+ const { AST_TYPES } = parsers;
13
14
  const value = parsers.parsePropertyValue(property, v, {
14
15
  globalObject,
15
16
  inArray: true
@@ -18,16 +19,18 @@ module.exports.parse = function parse(v, opt = {}) {
18
19
  if (value.length === 1) {
19
20
  const [{ name, type }] = value;
20
21
  switch (type) {
21
- case "GlobalKeyword":
22
- case "Identifier": {
22
+ case AST_TYPES.GLOBAL_KEYWORD:
23
+ case AST_TYPES.IDENTIFIER: {
23
24
  return name;
24
25
  }
25
26
  default:
26
27
  }
27
28
  } else if (value.length === 2) {
28
29
  const [part1, part2] = value;
29
- const val1 = part1.type === "Identifier" && part1.name;
30
- const val2 = parsers.parseAngle([part2]);
30
+ const val1 = part1.type === AST_TYPES.IDENTIFIER && part1.name;
31
+ const val2 = parsers.resolveNumericValue([part2], {
32
+ type: "angle"
33
+ });
31
34
  if (val1 && val1 === "oblique" && val2) {
32
35
  return `${val1} ${val2}`;
33
36
  }
@@ -39,7 +42,7 @@ module.exports.parse = function parse(v, opt = {}) {
39
42
 
40
43
  module.exports.definition = {
41
44
  set(v) {
42
- v = parsers.prepareValue(v, this._global);
45
+ v = parsers.prepareValue(v);
43
46
  if (parsers.hasVarFunc(v)) {
44
47
  this._setProperty(shorthand, "");
45
48
  this._setProperty(property, v);
@@ -48,9 +51,10 @@ module.exports.definition = {
48
51
  globalObject: this._global
49
52
  });
50
53
  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
+ const priority =
55
+ !this._priorities.get(shorthand) && this._priorities.has(property)
56
+ ? this._priorities.get(property)
57
+ : "";
54
58
  this._setProperty(property, val, priority);
55
59
  }
56
60
  }
@@ -61,3 +65,5 @@ module.exports.definition = {
61
65
  enumerable: true,
62
66
  configurable: true
63
67
  };
68
+
69
+ module.exports.property = property;
@@ -5,7 +5,7 @@ const parsers = require("../parsers");
5
5
  const property = "font-variant";
6
6
  const shorthand = "font";
7
7
 
8
- module.exports.parse = function parse(v, opt = {}) {
8
+ module.exports.parse = (v, opt = {}) => {
9
9
  const { globalObject } = opt;
10
10
  if (v === "") {
11
11
  return v;
@@ -18,21 +18,11 @@ module.exports.parse = function parse(v, opt = {}) {
18
18
  inArray: true
19
19
  });
20
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
- }
21
+ const parsedValue = parsers.resolveFunctionValue(value);
22
+ if (!parsedValue) {
23
+ return;
35
24
  }
25
+ parsedValues.push(parsedValue);
36
26
  } else if (typeof value === "string") {
37
27
  parsedValues.push(value);
38
28
  }
@@ -49,7 +39,7 @@ module.exports.parse = function parse(v, opt = {}) {
49
39
 
50
40
  module.exports.definition = {
51
41
  set(v) {
52
- v = parsers.prepareValue(v, this._global);
42
+ v = parsers.prepareValue(v);
53
43
  if (parsers.hasVarFunc(v)) {
54
44
  this._setProperty(shorthand, "");
55
45
  this._setProperty(property, v);
@@ -58,9 +48,10 @@ module.exports.definition = {
58
48
  globalObject: this._global
59
49
  });
60
50
  if (typeof val === "string") {
61
- const shorthandPriority = this._priorities.get(shorthand);
62
- const prior = this._priorities.get(property) ?? "";
63
- const priority = shorthandPriority && prior ? "" : prior;
51
+ const priority =
52
+ !this._priorities.get(shorthand) && this._priorities.has(property)
53
+ ? this._priorities.get(property)
54
+ : "";
64
55
  this._setProperty(property, val, priority);
65
56
  }
66
57
  }
@@ -71,3 +62,5 @@ module.exports.definition = {
71
62
  enumerable: true,
72
63
  configurable: true
73
64
  };
65
+
66
+ module.exports.property = property;
@@ -5,7 +5,7 @@ const parsers = require("../parsers");
5
5
  const property = "font-weight";
6
6
  const shorthand = "font";
7
7
 
8
- module.exports.parse = function parse(v, opt = {}) {
8
+ module.exports.parse = (v, opt = {}) => {
9
9
  const { globalObject } = opt;
10
10
  if (v === "") {
11
11
  return v;
@@ -15,28 +15,14 @@ module.exports.parse = function parse(v, opt = {}) {
15
15
  inArray: true
16
16
  });
17
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
- }
18
+ const parsedValue = parsers.resolveNumericValue(value, {
19
+ min: 1,
20
+ max: 1000
21
+ });
22
+ if (!parsedValue) {
23
+ return;
39
24
  }
25
+ return parsedValue;
40
26
  } else if (typeof value === "string") {
41
27
  return value;
42
28
  }
@@ -44,7 +30,7 @@ module.exports.parse = function parse(v, opt = {}) {
44
30
 
45
31
  module.exports.definition = {
46
32
  set(v) {
47
- v = parsers.prepareValue(v, this._global);
33
+ v = parsers.prepareValue(v);
48
34
  if (parsers.hasVarFunc(v)) {
49
35
  this._setProperty(shorthand, "");
50
36
  this._setProperty(property, v);
@@ -53,9 +39,10 @@ module.exports.definition = {
53
39
  globalObject: this._global
54
40
  });
55
41
  if (typeof val === "string") {
56
- const shorthandPriority = this._priorities.get(shorthand);
57
- const prior = this._priorities.get(property) ?? "";
58
- const priority = shorthandPriority && prior ? "" : prior;
42
+ const priority =
43
+ !this._priorities.get(shorthand) && this._priorities.has(property)
44
+ ? this._priorities.get(property)
45
+ : "";
59
46
  this._setProperty(property, val, priority);
60
47
  }
61
48
  }
@@ -66,3 +53,5 @@ module.exports.definition = {
66
53
  enumerable: true,
67
54
  configurable: true
68
55
  };
56
+
57
+ module.exports.property = property;
@@ -4,7 +4,7 @@ const parsers = require("../parsers");
4
4
 
5
5
  const property = "height";
6
6
 
7
- module.exports.parse = function parse(v, opt = {}) {
7
+ module.exports.parse = (v, opt = {}) => {
8
8
  const { globalObject } = opt;
9
9
  if (v === "") {
10
10
  return v;
@@ -14,22 +14,10 @@ module.exports.parse = function parse(v, opt = {}) {
14
14
  inArray: true
15
15
  });
16
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
- }
17
+ return parsers.resolveNumericValue(value, {
18
+ min: 0,
19
+ type: "length"
20
+ });
33
21
  } else if (typeof value === "string") {
34
22
  return value;
35
23
  }
@@ -37,7 +25,7 @@ module.exports.parse = function parse(v, opt = {}) {
37
25
 
38
26
  module.exports.definition = {
39
27
  set(v) {
40
- v = parsers.prepareValue(v, this._global);
28
+ v = parsers.prepareValue(v);
41
29
  if (parsers.hasVarFunc(v)) {
42
30
  this._setProperty(property, v);
43
31
  } else {
@@ -56,3 +44,5 @@ module.exports.definition = {
56
44
  enumerable: true,
57
45
  configurable: true
58
46
  };
47
+
48
+ module.exports.property = property;
@@ -4,7 +4,7 @@ const parsers = require("../parsers");
4
4
 
5
5
  const property = "left";
6
6
 
7
- module.exports.parse = function parse(v, opt = {}) {
7
+ module.exports.parse = (v, opt = {}) => {
8
8
  const { globalObject } = opt;
9
9
  if (v === "") {
10
10
  return v;
@@ -14,22 +14,9 @@ module.exports.parse = function parse(v, opt = {}) {
14
14
  inArray: true
15
15
  });
16
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
- }
17
+ return parsers.resolveNumericValue(value, {
18
+ type: "length"
19
+ });
33
20
  } else if (typeof value === "string") {
34
21
  return value;
35
22
  }
@@ -37,7 +24,7 @@ module.exports.parse = function parse(v, opt = {}) {
37
24
 
38
25
  module.exports.definition = {
39
26
  set(v) {
40
- v = parsers.prepareValue(v, this._global);
27
+ v = parsers.prepareValue(v);
41
28
  if (parsers.hasVarFunc(v)) {
42
29
  this._setProperty(property, v);
43
30
  } else {
@@ -56,3 +43,5 @@ module.exports.definition = {
56
43
  enumerable: true,
57
44
  configurable: true
58
45
  };
46
+
47
+ module.exports.property = property;
@@ -4,7 +4,7 @@ const parsers = require("../parsers");
4
4
 
5
5
  const property = "lighting-color";
6
6
 
7
- module.exports.parse = function parse(v, opt = {}) {
7
+ module.exports.parse = (v, opt = {}) => {
8
8
  const { globalObject } = opt;
9
9
  if (v === "") {
10
10
  return v;
@@ -14,15 +14,7 @@ module.exports.parse = function parse(v, opt = {}) {
14
14
  inArray: true
15
15
  });
16
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
- }
17
+ return parsers.resolveColorValue(value);
26
18
  } else if (typeof value === "string") {
27
19
  return value;
28
20
  }
@@ -30,7 +22,7 @@ module.exports.parse = function parse(v, opt = {}) {
30
22
 
31
23
  module.exports.definition = {
32
24
  set(v) {
33
- v = parsers.prepareValue(v, this._global);
25
+ v = parsers.prepareValue(v);
34
26
  if (parsers.hasVarFunc(v)) {
35
27
  this._setProperty(property, v);
36
28
  } else {
@@ -49,3 +41,5 @@ module.exports.definition = {
49
41
  enumerable: true,
50
42
  configurable: true
51
43
  };
44
+
45
+ module.exports.property = property;
@@ -5,7 +5,7 @@ const parsers = require("../parsers");
5
5
  const property = "line-height";
6
6
  const shorthand = "font";
7
7
 
8
- module.exports.parse = function parse(v, opt = {}) {
8
+ module.exports.parse = (v, opt = {}) => {
9
9
  const { globalObject } = opt;
10
10
  if (v === "") {
11
11
  return v;
@@ -15,26 +15,9 @@ module.exports.parse = function parse(v, opt = {}) {
15
15
  inArray: true
16
16
  });
17
17
  if (Array.isArray(value) && value.length === 1) {
18
- const [{ name, type, value: itemValue }] = value;
19
- switch (type) {
20
- case "Calc": {
21
- return `${name}(${itemValue})`;
22
- }
23
- case "GlobalKeyword":
24
- case "Identifier": {
25
- return name;
26
- }
27
- case "Number": {
28
- return parsers.parseNumber(value, {
29
- min: 0
30
- });
31
- }
32
- default: {
33
- return parsers.parseLengthPercentage(value, {
34
- min: 0
35
- });
36
- }
37
- }
18
+ return parsers.resolveNumericValue(value, {
19
+ min: 0
20
+ });
38
21
  } else if (typeof value === "string") {
39
22
  return value;
40
23
  }
@@ -42,7 +25,7 @@ module.exports.parse = function parse(v, opt = {}) {
42
25
 
43
26
  module.exports.definition = {
44
27
  set(v) {
45
- v = parsers.prepareValue(v, this._global);
28
+ v = parsers.prepareValue(v);
46
29
  if (parsers.hasVarFunc(v)) {
47
30
  this._setProperty(shorthand, "");
48
31
  this._setProperty(property, v);
@@ -51,9 +34,10 @@ module.exports.definition = {
51
34
  globalObject: this._global
52
35
  });
53
36
  if (typeof val === "string") {
54
- const shorthandPriority = this._priorities.get(shorthand);
55
- const prior = this._priorities.get(property) ?? "";
56
- const priority = shorthandPriority && prior ? "" : prior;
37
+ const priority =
38
+ !this._priorities.get(shorthand) && this._priorities.has(property)
39
+ ? this._priorities.get(property)
40
+ : "";
57
41
  this._setProperty(property, val, priority);
58
42
  }
59
43
  }
@@ -64,3 +48,5 @@ module.exports.definition = {
64
48
  enumerable: true,
65
49
  configurable: true
66
50
  };
51
+
52
+ module.exports.property = property;
@@ -11,13 +11,13 @@ const property = "margin";
11
11
  module.exports.position = "edges";
12
12
 
13
13
  module.exports.shorthandFor = new Map([
14
- ["margin-top", marginTop],
15
- ["margin-right", marginRight],
16
- ["margin-bottom", marginBottom],
17
- ["margin-left", marginLeft]
14
+ [marginTop.property, marginTop],
15
+ [marginRight.property, marginRight],
16
+ [marginBottom.property, marginBottom],
17
+ [marginLeft.property, marginLeft]
18
18
  ]);
19
19
 
20
- module.exports.parse = function parse(v, opt = {}) {
20
+ module.exports.parse = (v, opt = {}) => {
21
21
  const { globalObject } = opt;
22
22
  if (v === "") {
23
23
  return v;
@@ -32,34 +32,14 @@ module.exports.parse = function parse(v, opt = {}) {
32
32
  return;
33
33
  }
34
34
  for (const value of values) {
35
- const { isNumber, name, type, value: itemValue } = value;
36
- switch (type) {
37
- case "Calc": {
38
- if (isNumber) {
39
- return;
40
- }
41
- parsedValues.push(`${name}(${itemValue})`);
42
- break;
43
- }
44
- case "GlobalKeyword": {
45
- if (values.length !== 1) {
46
- return;
47
- }
48
- parsedValues.push(name);
49
- break;
50
- }
51
- case "Identifier": {
52
- parsedValues.push(name);
53
- break;
54
- }
55
- default: {
56
- const parsedValue = parsers.parseLengthPercentage([value]);
57
- if (!parsedValue) {
58
- return;
59
- }
60
- parsedValues.push(parsedValue);
61
- }
35
+ const parsedValue = parsers.resolveNumericValue([value], {
36
+ length: values.length,
37
+ type: "length"
38
+ });
39
+ if (!parsedValue) {
40
+ return;
62
41
  }
42
+ parsedValues.push(parsedValue);
63
43
  }
64
44
  } else if (typeof values === "string") {
65
45
  parsedValues.push(values);
@@ -71,7 +51,7 @@ module.exports.parse = function parse(v, opt = {}) {
71
51
 
72
52
  module.exports.definition = {
73
53
  set(v) {
74
- v = parsers.prepareValue(v, this._global);
54
+ v = parsers.prepareValue(v);
75
55
  if (parsers.hasVarFunc(v)) {
76
56
  for (const [longhand] of module.exports.shorthandFor) {
77
57
  this._setProperty(longhand, "");
@@ -93,3 +73,5 @@ module.exports.definition = {
93
73
  enumerable: true,
94
74
  configurable: true
95
75
  };
76
+
77
+ module.exports.property = property;
@@ -7,7 +7,7 @@ const shorthand = "margin";
7
7
 
8
8
  module.exports.position = "bottom";
9
9
 
10
- module.exports.parse = function parse(v, opt = {}) {
10
+ module.exports.parse = (v, opt = {}) => {
11
11
  const { globalObject } = opt;
12
12
  if (v === "") {
13
13
  return v;
@@ -17,22 +17,9 @@ module.exports.parse = function parse(v, opt = {}) {
17
17
  inArray: true
18
18
  });
19
19
  if (Array.isArray(value) && value.length === 1) {
20
- const [{ isNumber, name, type, value: itemValue }] = value;
21
- switch (type) {
22
- case "Calc": {
23
- if (isNumber) {
24
- return;
25
- }
26
- return `${name}(${itemValue})`;
27
- }
28
- case "GlobalKeyword":
29
- case "Identifier": {
30
- return name;
31
- }
32
- default: {
33
- return parsers.parseLengthPercentage(value);
34
- }
35
- }
20
+ return parsers.resolveNumericValue(value, {
21
+ type: "length"
22
+ });
36
23
  } else if (typeof value === "string") {
37
24
  return value;
38
25
  }
@@ -40,7 +27,7 @@ module.exports.parse = function parse(v, opt = {}) {
40
27
 
41
28
  module.exports.definition = {
42
29
  set(v) {
43
- v = parsers.prepareValue(v, this._global);
30
+ v = parsers.prepareValue(v);
44
31
  if (parsers.hasVarFunc(v)) {
45
32
  this._setProperty(shorthand, "");
46
33
  this._setProperty(property, v);
@@ -49,9 +36,10 @@ module.exports.definition = {
49
36
  globalObject: this._global
50
37
  });
51
38
  if (typeof val === "string") {
52
- const shorthandPriority = this._priorities.get(shorthand);
53
- const prior = this._priorities.get(property) ?? "";
54
- const priority = shorthandPriority && prior ? "" : prior;
39
+ const priority =
40
+ !this._priorities.get(shorthand) && this._priorities.has(property)
41
+ ? this._priorities.get(property)
42
+ : "";
55
43
  this._positionLonghandSetter(property, val, priority, shorthand);
56
44
  }
57
45
  }
@@ -62,3 +50,5 @@ module.exports.definition = {
62
50
  enumerable: true,
63
51
  configurable: true
64
52
  };
53
+
54
+ module.exports.property = property;