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
@@ -8,123 +8,124 @@ const flexBasis = require("./flexBasis");
8
8
  const property = "flex";
9
9
 
10
10
  module.exports.initialValues = new Map([
11
- ["flex-grow", "0"],
12
- ["flex-shrink", "1"],
13
- ["flex-basis", "auto"]
11
+ [flexGrow.property, "0"],
12
+ [flexShrink.property, "1"],
13
+ [flexBasis.property, "auto"]
14
14
  ]);
15
15
 
16
16
  module.exports.shorthandFor = new Map([
17
- ["flex-grow", flexGrow],
18
- ["flex-shrink", flexShrink],
19
- ["flex-basis", flexBasis]
17
+ [flexGrow.property, flexGrow],
18
+ [flexShrink.property, flexShrink],
19
+ [flexBasis.property, flexBasis]
20
20
  ]);
21
21
 
22
- module.exports.parse = function parse(v, opt = {}) {
22
+ module.exports.parse = (v, opt = {}) => {
23
23
  const { globalObject } = opt;
24
24
  if (v === "") {
25
25
  return v;
26
26
  }
27
+ const { AST_TYPES } = parsers;
27
28
  const value = parsers.parsePropertyValue(property, v, {
28
29
  globalObject,
29
30
  inArray: true
30
31
  });
31
32
  if (Array.isArray(value) && value.length) {
32
33
  const flex = {
33
- "flex-grow": "1",
34
- "flex-shrink": "1",
35
- "flex-basis": "0%"
34
+ [flexGrow.property]: "1",
35
+ [flexShrink.property]: "1",
36
+ [flexBasis.property]: "0%"
36
37
  };
37
38
  if (value.length === 1) {
38
39
  const [{ isNumber, name, type, unit, value: itemValue }] = value;
39
40
  switch (type) {
40
- case "Calc": {
41
+ case AST_TYPES.CALC: {
41
42
  if (isNumber) {
42
- flex["flex-grow"] = `${name}(${itemValue})`;
43
+ flex[flexGrow.property] = `${name}(${itemValue})`;
43
44
  return flex;
44
45
  }
45
- flex["flex-basis"] = `${name}(${itemValue})`;
46
+ flex[flexBasis.property] = `${name}(${itemValue})`;
46
47
  return flex;
47
48
  }
48
- case "Dimension": {
49
- flex["flex-basis"] = `${itemValue}${unit}`;
49
+ case AST_TYPES.DIMENSION: {
50
+ flex[flexBasis.property] = `${itemValue}${unit}`;
50
51
  return flex;
51
52
  }
52
- case "GlobalKeyword": {
53
+ case AST_TYPES.GLOBAL_KEYWORD: {
53
54
  return name;
54
55
  }
55
- case "Identifier": {
56
+ case AST_TYPES.IDENTIFIER: {
56
57
  if (name === "none") {
57
58
  return {
58
- "flex-grow": "0",
59
- "flex-shrink": "0",
60
- "flex-basis": "auto"
59
+ [flexGrow.property]: "0",
60
+ [flexShrink.property]: "0",
61
+ [flexBasis.property]: "auto"
61
62
  };
62
63
  }
63
- flex["flex-basis"] = name;
64
+ flex[flexBasis.property] = name;
64
65
  return flex;
65
66
  }
66
- case "Number": {
67
- flex["flex-grow"] = itemValue;
67
+ case AST_TYPES.NUMBER: {
68
+ flex[flexGrow.property] = itemValue;
68
69
  return flex;
69
70
  }
70
- case "Percentage": {
71
- flex["flex-basis"] = `${itemValue}%`;
71
+ case AST_TYPES.PERCENTAGE: {
72
+ flex[flexBasis.property] = `${itemValue}%`;
72
73
  return flex;
73
74
  }
74
75
  default:
75
76
  }
76
77
  } else {
77
78
  const [val1, val2, val3] = value;
78
- if (val1.type === "Calc" && val1.isNumber) {
79
- flex["flex-grow"] = `${val1.name}(${val1.value})`;
80
- } else if (val1.type === "Number") {
81
- flex["flex-grow"] = val1.value;
79
+ if (val1.type === AST_TYPES.CALC && val1.isNumber) {
80
+ flex[flexGrow.property] = `${val1.name}(${val1.value})`;
81
+ } else if (val1.type === AST_TYPES.NUMBER) {
82
+ flex[flexGrow.property] = val1.value;
82
83
  } else {
83
84
  return;
84
85
  }
85
86
  if (val3) {
86
- if (val2.type === "Calc" && val2.isNumber) {
87
- flex["flex-shrink"] = `${val2.name}(${val2.value})`;
88
- } else if (val2.type === "Number") {
89
- flex["flex-shrink"] = val2.value;
87
+ if (val2.type === AST_TYPES.CALC && val2.isNumber) {
88
+ flex[flexShrink.property] = `${val2.name}(${val2.value})`;
89
+ } else if (val2.type === AST_TYPES.NUMBER) {
90
+ flex[flexShrink.property] = val2.value;
90
91
  } else {
91
92
  return;
92
93
  }
93
- if (val3.type === "GlobalKeyword" || val3.type === "Identifier") {
94
- flex["flex-basis"] = val3.name;
95
- } else if (val3.type === "Calc" && !val3.isNumber) {
96
- flex["flex-basis"] = `${val3.name}(${val3.value})`;
97
- } else if (val3.type === "Dimension") {
98
- flex["flex-basis"] = `${val3.value}${val3.unit}`;
99
- } else if (val3.type === "Percentage") {
100
- flex["flex-basis"] = `${val3.value}%`;
94
+ if (val3.type === AST_TYPES.GLOBAL_KEYWORD || val3.type === AST_TYPES.IDENTIFIER) {
95
+ flex[flexBasis.property] = val3.name;
96
+ } else if (val3.type === AST_TYPES.CALC && !val3.isNumber) {
97
+ flex[flexBasis.property] = `${val3.name}(${val3.value})`;
98
+ } else if (val3.type === AST_TYPES.DIMENSION) {
99
+ flex[flexBasis.property] = `${val3.value}${val3.unit}`;
100
+ } else if (val3.type === AST_TYPES.PERCENTAGE) {
101
+ flex[flexBasis.property] = `${val3.value}%`;
101
102
  } else {
102
103
  return;
103
104
  }
104
105
  } else {
105
106
  switch (val2.type) {
106
- case "Calc": {
107
+ case AST_TYPES.CALC: {
107
108
  if (val2.isNumber) {
108
- flex["flex-shrink"] = `${val2.name}(${val2.value})`;
109
+ flex[flexShrink.property] = `${val2.name}(${val2.value})`;
109
110
  } else {
110
- flex["flex-basis"] = `${val2.name}(${val2.value})`;
111
+ flex[flexBasis.property] = `${val2.name}(${val2.value})`;
111
112
  }
112
113
  break;
113
114
  }
114
- case "Dimension": {
115
- flex["flex-basis"] = `${val2.value}${val2.unit}`;
115
+ case AST_TYPES.DIMENSION: {
116
+ flex[flexBasis.property] = `${val2.value}${val2.unit}`;
116
117
  break;
117
118
  }
118
- case "Number": {
119
- flex["flex-shrink"] = val2.value;
119
+ case AST_TYPES.NUMBER: {
120
+ flex[flexShrink.property] = val2.value;
120
121
  break;
121
122
  }
122
- case "Percentage": {
123
- flex["flex-basis"] = `${val2.value}%`;
123
+ case AST_TYPES.PERCENTAGE: {
124
+ flex[flexBasis.property] = `${val2.value}%`;
124
125
  break;
125
126
  }
126
- case "Identifier": {
127
- flex["flex-basis"] = val2.name;
127
+ case AST_TYPES.IDENTIFIER: {
128
+ flex[flexBasis.property] = val2.name;
128
129
  break;
129
130
  }
130
131
  default: {
@@ -133,7 +134,6 @@ module.exports.parse = function parse(v, opt = {}) {
133
134
  }
134
135
  }
135
136
  return flex;
136
- // return [...Object.values(flex)].join(" ");
137
137
  }
138
138
  } else if (typeof value === "string") {
139
139
  return value;
@@ -142,7 +142,7 @@ module.exports.parse = function parse(v, opt = {}) {
142
142
 
143
143
  module.exports.definition = {
144
144
  set(v) {
145
- v = parsers.prepareValue(v, this._global);
145
+ v = parsers.prepareValue(v);
146
146
  if (parsers.hasVarFunc(v)) {
147
147
  for (const [longhand] of module.exports.shorthandFor) {
148
148
  this._setProperty(longhand, "");
@@ -174,3 +174,5 @@ module.exports.definition = {
174
174
  enumerable: true,
175
175
  configurable: true
176
176
  };
177
+
178
+ module.exports.property = property;
@@ -5,7 +5,7 @@ const parsers = require("../parsers");
5
5
  const property = "flex-basis";
6
6
  const shorthand = "flex";
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,22 +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 [{ 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
- }
33
- }
18
+ return parsers.resolveNumericValue(value, {
19
+ type: "length"
20
+ });
34
21
  } else if (typeof value === "string") {
35
22
  return value;
36
23
  }
@@ -38,7 +25,7 @@ module.exports.parse = function parse(v, opt = {}) {
38
25
 
39
26
  module.exports.definition = {
40
27
  set(v) {
41
- v = parsers.prepareValue(v, this._global);
28
+ v = parsers.prepareValue(v);
42
29
  if (parsers.hasVarFunc(v)) {
43
30
  this._setProperty(shorthand, "");
44
31
  this._setProperty(property, v);
@@ -47,9 +34,10 @@ module.exports.definition = {
47
34
  globalObject: this._global
48
35
  });
49
36
  if (typeof val === "string") {
50
- const shorthandPriority = this._priorities.get(shorthand);
51
- const prior = this._priorities.get(property) ?? "";
52
- const priority = shorthandPriority && prior ? "" : prior;
37
+ const priority =
38
+ !this._priorities.get(shorthand) && this._priorities.has(property)
39
+ ? this._priorities.get(property)
40
+ : "";
53
41
  this._flexBoxSetter(property, val, priority, shorthand);
54
42
  }
55
43
  }
@@ -60,3 +48,5 @@ module.exports.definition = {
60
48
  enumerable: true,
61
49
  configurable: true
62
50
  };
51
+
52
+ module.exports.property = property;
@@ -5,7 +5,7 @@ const parsers = require("../parsers");
5
5
  const property = "flex-grow";
6
6
  const shorthand = "flex";
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,21 +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 [{ 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
- return name;
28
- }
29
- default: {
30
- return parsers.parseNumber(value);
31
- }
32
- }
18
+ return parsers.resolveNumericValue(value, {
19
+ min: 0
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(shorthand, "");
43
31
  this._setProperty(property, v);
@@ -46,9 +34,10 @@ module.exports.definition = {
46
34
  globalObject: this._global
47
35
  });
48
36
  if (typeof val === "string") {
49
- const shorthandPriority = this._priorities.get(shorthand);
50
- const prior = this._priorities.get(property) ?? "";
51
- const priority = shorthandPriority && prior ? "" : prior;
37
+ const priority =
38
+ !this._priorities.get(shorthand) && this._priorities.has(property)
39
+ ? this._priorities.get(property)
40
+ : "";
52
41
  this._flexBoxSetter(property, val, priority, shorthand);
53
42
  }
54
43
  }
@@ -59,3 +48,5 @@ module.exports.definition = {
59
48
  enumerable: true,
60
49
  configurable: true
61
50
  };
51
+
52
+ module.exports.property = property;
@@ -5,7 +5,7 @@ const parsers = require("../parsers");
5
5
  const property = "flex-shrink";
6
6
  const shorthand = "flex";
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,21 +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 [{ 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
- return name;
28
- }
29
- default: {
30
- return parsers.parseNumber(value);
31
- }
32
- }
18
+ return parsers.resolveNumericValue(value, {
19
+ min: 0
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(shorthand, "");
43
31
  this._setProperty(property, v);
@@ -46,9 +34,10 @@ module.exports.definition = {
46
34
  globalObject: this._global
47
35
  });
48
36
  if (typeof val === "string") {
49
- const shorthandPriority = this._priorities.get(shorthand);
50
- const prior = this._priorities.get(property) ?? "";
51
- const priority = shorthandPriority && prior ? "" : prior;
37
+ const priority =
38
+ !this._priorities.get(shorthand) && this._priorities.has(property)
39
+ ? this._priorities.get(property)
40
+ : "";
52
41
  this._flexBoxSetter(property, val, priority, shorthand);
53
42
  }
54
43
  }
@@ -59,3 +48,5 @@ module.exports.definition = {
59
48
  enumerable: true,
60
49
  configurable: true
61
50
  };
51
+
52
+ module.exports.property = property;
@@ -4,7 +4,7 @@ const parsers = require("../parsers");
4
4
 
5
5
  const property = "float";
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,14 +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
- case "Identifier": {
21
- return name;
22
- }
23
- default:
24
- }
17
+ return parsers.resolveKeywordValue(value);
25
18
  } else if (typeof value === "string") {
26
19
  return value;
27
20
  }
@@ -29,7 +22,7 @@ module.exports.parse = function parse(v, opt = {}) {
29
22
 
30
23
  module.exports.definition = {
31
24
  set(v) {
32
- v = parsers.prepareValue(v, this._global);
25
+ v = parsers.prepareValue(v);
33
26
  if (parsers.hasVarFunc(v)) {
34
27
  this._setProperty(property, v);
35
28
  } else {
@@ -48,3 +41,5 @@ module.exports.definition = {
48
41
  enumerable: true,
49
42
  configurable: true
50
43
  };
44
+
45
+ module.exports.property = property;
@@ -4,7 +4,7 @@ const parsers = require("../parsers");
4
4
 
5
5
  const property = "flood-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;
@@ -11,15 +11,15 @@ const fontFamily = require("./fontFamily");
11
11
  const property = "font";
12
12
 
13
13
  module.exports.shorthandFor = new Map([
14
- ["font-style", fontStyle],
15
- ["font-variant", fontVariant],
16
- ["font-weight", fontWeight],
17
- ["font-size", fontSize],
18
- ["line-height", lineHeight],
19
- ["font-family", fontFamily]
14
+ [fontStyle.property, fontStyle],
15
+ [fontVariant.property, fontVariant],
16
+ [fontWeight.property, fontWeight],
17
+ [fontSize.property, fontSize],
18
+ [lineHeight.property, lineHeight],
19
+ [fontFamily.property, fontFamily]
20
20
  ]);
21
21
 
22
- module.exports.parse = function parse(v, opt = {}) {
22
+ module.exports.parse = (v, opt = {}) => {
23
23
  const { globalObject } = opt;
24
24
  if (v === "") {
25
25
  return v;
@@ -29,6 +29,7 @@ module.exports.parse = function parse(v, opt = {}) {
29
29
  if (!parsers.isValidPropertyValue(property, v)) {
30
30
  return;
31
31
  }
32
+ const { AST_TYPES } = parsers;
32
33
  const [fontBlock, ...families] = parsers.splitValue(v, {
33
34
  delimiter: ","
34
35
  });
@@ -36,9 +37,9 @@ module.exports.parse = function parse(v, opt = {}) {
36
37
  delimiter: "/"
37
38
  });
38
39
  const font = {
39
- "font-style": "normal",
40
- "font-variant": "normal",
41
- "font-weight": "normal"
40
+ [fontStyle.property]: "normal",
41
+ [fontVariant.property]: "normal",
42
+ [fontWeight.property]: "normal"
42
43
  };
43
44
  const fontFamilies = new Set();
44
45
  if (fontBlockB) {
@@ -62,14 +63,19 @@ module.exports.parse = function parse(v, opt = {}) {
62
63
  return;
63
64
  }
64
65
  const parts = parsers.splitValue(fontBlockA.trim());
65
- const properties = ["font-style", "font-variant", "font-weight", "font-size"];
66
+ const properties = [
67
+ fontStyle.property,
68
+ fontVariant.property,
69
+ fontWeight.property,
70
+ fontSize.property
71
+ ];
66
72
  for (const part of parts) {
67
73
  if (part === "normal") {
68
74
  continue;
69
75
  } else {
70
76
  for (const longhand of properties) {
71
77
  switch (longhand) {
72
- case "font-size": {
78
+ case fontSize.property: {
73
79
  const parsedValue = fontSize.parse(part, {
74
80
  globalObject
75
81
  });
@@ -78,8 +84,8 @@ module.exports.parse = function parse(v, opt = {}) {
78
84
  }
79
85
  break;
80
86
  }
81
- case "font-style":
82
- case "font-weight": {
87
+ case fontStyle.property:
88
+ case fontWeight.property: {
83
89
  if (font[longhand] === "normal") {
84
90
  const longhandItem = module.exports.shorthandFor.get(longhand);
85
91
  const parsedValue = longhandItem.parse(part, {
@@ -91,7 +97,7 @@ module.exports.parse = function parse(v, opt = {}) {
91
97
  }
92
98
  break;
93
99
  }
94
- case "font-variant": {
100
+ case fontVariant.property: {
95
101
  if (font[longhand] === "normal") {
96
102
  const parsedValue = fontVariant.parse(part, {
97
103
  globalObject
@@ -111,8 +117,8 @@ module.exports.parse = function parse(v, opt = {}) {
111
117
  }
112
118
  }
113
119
  }
114
- if (Object.hasOwn(font, "font-size")) {
115
- font["line-height"] = lineHeightB;
120
+ if (Object.hasOwn(font, fontSize.property)) {
121
+ font[lineHeight.property] = lineHeightB;
116
122
  } else {
117
123
  return;
118
124
  }
@@ -126,20 +132,25 @@ module.exports.parse = function parse(v, opt = {}) {
126
132
  });
127
133
  if (Array.isArray(value) && value.length === 1) {
128
134
  const [{ name, type }] = value;
129
- if (type === "GlobalKeyword") {
135
+ if (type === AST_TYPES.GLOBAL_KEYWORD) {
130
136
  return {
131
- "font-style": name,
132
- "font-variant": name,
133
- "font-weight": name,
134
- "font-size": name,
135
- "line-height": name,
136
- "font-family": name
137
+ [fontStyle.property]: name,
138
+ [fontVariant.property]: name,
139
+ [fontWeight.property]: name,
140
+ [fontSize.property]: name,
141
+ [lineHeight.property]: name,
142
+ [fontFamily.property]: name
137
143
  };
138
144
  }
139
145
  }
140
146
  return;
141
147
  }
142
- const properties = ["font-style", "font-variant", "font-weight", "line-height"];
148
+ const properties = [
149
+ fontStyle.property,
150
+ fontVariant.property,
151
+ fontWeight.property,
152
+ lineHeight.property
153
+ ];
143
154
  for (const longhand of properties) {
144
155
  font[longhand] = "normal";
145
156
  }
@@ -152,9 +163,9 @@ module.exports.parse = function parse(v, opt = {}) {
152
163
  } else {
153
164
  for (const longhand of properties) {
154
165
  switch (longhand) {
155
- case "font-style":
156
- case "font-weight":
157
- case "line-height": {
166
+ case fontStyle.property:
167
+ case fontWeight.property:
168
+ case lineHeight.property: {
158
169
  if (font[longhand] === "normal") {
159
170
  const longhandItem = module.exports.shorthandFor.get(longhand);
160
171
  const parsedValue = longhandItem.parse(part, {
@@ -166,7 +177,7 @@ module.exports.parse = function parse(v, opt = {}) {
166
177
  }
167
178
  break;
168
179
  }
169
- case "font-variant": {
180
+ case fontVariant.property: {
170
181
  if (font[longhand] === "normal") {
171
182
  const parsedValue = fontVariant.parse(part, {
172
183
  globalObject
@@ -209,7 +220,7 @@ module.exports.parse = function parse(v, opt = {}) {
209
220
  caseSensitive: true
210
221
  });
211
222
  if (fontSizeA && family) {
212
- font["font-size"] = fontSizeA;
223
+ font[fontSize.property] = fontSizeA;
213
224
  fontFamilies.add(fontFamily.parse(family));
214
225
  } else {
215
226
  return;
@@ -226,13 +237,13 @@ module.exports.parse = function parse(v, opt = {}) {
226
237
  return;
227
238
  }
228
239
  }
229
- font["font-family"] = [...fontFamilies].join(", ");
240
+ font[fontFamily.property] = [...fontFamilies].join(", ");
230
241
  return font;
231
242
  };
232
243
 
233
244
  module.exports.definition = {
234
245
  set(v) {
235
- v = parsers.prepareValue(v, this._global);
246
+ v = parsers.prepareValue(v);
236
247
  if (v === "" || parsers.hasVarFunc(v)) {
237
248
  for (const [key] of module.exports.shorthandFor) {
238
249
  this._setProperty(key, "");
@@ -252,7 +263,7 @@ module.exports.definition = {
252
263
  if (typeof val === "string") {
253
264
  this._setProperty(key, val, priority);
254
265
  if (val && val !== "normal" && !str.has(val)) {
255
- if (key === "line-height") {
266
+ if (key === lineHeight.property) {
256
267
  str.add(`/ ${val}`);
257
268
  } else {
258
269
  str.add(val);
@@ -275,7 +286,7 @@ module.exports.definition = {
275
286
  return "";
276
287
  }
277
288
  if (v && v !== "normal" && !str.has(v)) {
278
- if (key === "line-height") {
289
+ if (key === lineHeight.property) {
279
290
  str.add(`/ ${v}`);
280
291
  } else {
281
292
  str.add(`${v}`);
@@ -287,3 +298,5 @@ module.exports.definition = {
287
298
  enumerable: true,
288
299
  configurable: true
289
300
  };
301
+
302
+ module.exports.property = property;