cssstyle 4.3.1 → 4.5.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 (94) hide show
  1. package/lib/CSSStyleDeclaration.js +545 -206
  2. package/lib/allExtraProperties.js +42 -60
  3. package/lib/allWebkitProperties.js +107 -187
  4. package/lib/generated/allProperties.js +615 -0
  5. package/lib/{implementedProperties.js → generated/implementedProperties.js} +11 -18
  6. package/lib/generated/properties.js +2661 -0
  7. package/lib/parsers.js +382 -547
  8. package/lib/properties/background.js +40 -13
  9. package/lib/properties/backgroundAttachment.js +23 -15
  10. package/lib/properties/backgroundColor.js +21 -19
  11. package/lib/properties/backgroundImage.js +19 -14
  12. package/lib/properties/backgroundPosition.js +35 -41
  13. package/lib/properties/backgroundRepeat.js +20 -20
  14. package/lib/properties/border.js +34 -25
  15. package/lib/properties/borderBottom.js +34 -11
  16. package/lib/properties/borderBottomColor.js +27 -8
  17. package/lib/properties/borderBottomStyle.js +42 -13
  18. package/lib/properties/borderBottomWidth.js +28 -8
  19. package/lib/properties/borderCollapse.js +16 -16
  20. package/lib/properties/borderColor.js +32 -18
  21. package/lib/properties/borderLeft.js +34 -11
  22. package/lib/properties/borderLeftColor.js +27 -8
  23. package/lib/properties/borderLeftStyle.js +42 -13
  24. package/lib/properties/borderLeftWidth.js +28 -8
  25. package/lib/properties/borderRight.js +34 -11
  26. package/lib/properties/borderRightColor.js +27 -8
  27. package/lib/properties/borderRightStyle.js +42 -13
  28. package/lib/properties/borderRightWidth.js +28 -8
  29. package/lib/properties/borderSpacing.js +31 -27
  30. package/lib/properties/borderStyle.js +43 -27
  31. package/lib/properties/borderTop.js +34 -11
  32. package/lib/properties/borderTopColor.js +27 -8
  33. package/lib/properties/borderTopStyle.js +42 -13
  34. package/lib/properties/borderTopWidth.js +28 -9
  35. package/lib/properties/borderWidth.js +32 -34
  36. package/lib/properties/bottom.js +23 -7
  37. package/lib/properties/clear.js +32 -8
  38. package/lib/properties/clip.js +33 -27
  39. package/lib/properties/color.js +23 -7
  40. package/lib/properties/flex.js +59 -29
  41. package/lib/properties/flexBasis.js +21 -16
  42. package/lib/properties/flexGrow.js +19 -10
  43. package/lib/properties/flexShrink.js +19 -10
  44. package/lib/properties/float.js +21 -6
  45. package/lib/properties/floodColor.js +23 -7
  46. package/lib/properties/font.js +185 -33
  47. package/lib/properties/fontFamily.js +73 -21
  48. package/lib/properties/fontSize.js +37 -28
  49. package/lib/properties/fontStyle.js +23 -9
  50. package/lib/properties/fontVariant.js +26 -8
  51. package/lib/properties/fontWeight.js +26 -23
  52. package/lib/properties/height.js +21 -14
  53. package/lib/properties/left.js +23 -7
  54. package/lib/properties/lightingColor.js +23 -7
  55. package/lib/properties/lineHeight.js +29 -16
  56. package/lib/properties/margin.js +42 -57
  57. package/lib/properties/marginBottom.js +34 -7
  58. package/lib/properties/marginLeft.js +34 -7
  59. package/lib/properties/marginRight.js +34 -7
  60. package/lib/properties/marginTop.js +34 -7
  61. package/lib/properties/opacity.js +39 -7
  62. package/lib/properties/outlineColor.js +23 -7
  63. package/lib/properties/padding.js +43 -51
  64. package/lib/properties/paddingBottom.js +36 -7
  65. package/lib/properties/paddingLeft.js +34 -7
  66. package/lib/properties/paddingRight.js +34 -7
  67. package/lib/properties/paddingTop.js +34 -7
  68. package/lib/properties/right.js +23 -7
  69. package/lib/properties/stopColor.js +23 -7
  70. package/lib/properties/top.js +23 -7
  71. package/lib/properties/webkitBorderAfterColor.js +23 -7
  72. package/lib/properties/webkitBorderBeforeColor.js +23 -7
  73. package/lib/properties/webkitBorderEndColor.js +23 -7
  74. package/lib/properties/webkitBorderStartColor.js +23 -7
  75. package/lib/properties/webkitColumnRuleColor.js +23 -7
  76. package/lib/properties/webkitTapHighlightColor.js +23 -7
  77. package/lib/properties/webkitTextEmphasisColor.js +23 -7
  78. package/lib/properties/webkitTextFillColor.js +23 -7
  79. package/lib/properties/webkitTextStrokeColor.js +23 -7
  80. package/lib/properties/width.js +21 -14
  81. package/lib/utils/camelize.js +35 -0
  82. package/lib/utils/propertyDescriptors.js +16 -0
  83. package/package.json +5 -4
  84. package/lib/allProperties.js +0 -529
  85. package/lib/constants.js +0 -6
  86. package/lib/named_colors.json +0 -152
  87. package/lib/properties/azimuth.js +0 -64
  88. package/lib/properties/cssFloat.js +0 -12
  89. package/lib/properties/textLineThroughColor.js +0 -14
  90. package/lib/properties/textOverlineColor.js +0 -14
  91. package/lib/properties/textUnderlineColor.js +0 -14
  92. package/lib/properties/webkitMatchNearestMailBlockquoteColor.js +0 -14
  93. package/lib/properties.js +0 -1672
  94. package/lib/utils/getBasicPropertyDescriptor.js +0 -14
@@ -1,43 +1,73 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var shorthandParser = require('../parsers').shorthandParser;
4
- var shorthandSetter = require('../parsers').shorthandSetter;
5
- var shorthandGetter = require('../parsers').shorthandGetter;
3
+ const parsers = require("../parsers");
4
+ const flexGrow = require("./flexGrow");
5
+ const flexShrink = require("./flexShrink");
6
+ const flexBasis = require("./flexBasis");
6
7
 
7
- var shorthand_for = {
8
- 'flex-grow': require('./flexGrow'),
9
- 'flex-shrink': require('./flexShrink'),
10
- 'flex-basis': require('./flexBasis'),
11
- };
8
+ const shorthandFor = new Map([
9
+ ["flex-grow", flexGrow],
10
+ ["flex-shrink", flexShrink],
11
+ ["flex-basis", flexBasis]
12
+ ]);
12
13
 
13
- var myShorthandSetter = shorthandSetter('flex', shorthand_for);
14
+ module.exports.parse = function parse(v) {
15
+ const key = parsers.parseKeyword(v, ["auto", "none"]);
16
+ if (key) {
17
+ if (key === "auto") {
18
+ return "1 1 auto";
19
+ }
20
+ if (key === "none") {
21
+ return "0 0 auto";
22
+ }
23
+ if (key === "initial") {
24
+ return "0 1 auto";
25
+ }
26
+ return;
27
+ }
28
+ const obj = parsers.parseShorthand(v, shorthandFor);
29
+ if (obj) {
30
+ const flex = {
31
+ "flex-grow": "1",
32
+ "flex-shrink": "1",
33
+ "flex-basis": "0%"
34
+ };
35
+ const items = Object.entries(obj);
36
+ for (const [property, value] of items) {
37
+ flex[property] = value;
38
+ }
39
+ return [...Object.values(flex)].join(" ");
40
+ }
41
+ };
14
42
 
15
43
  module.exports.isValid = function isValid(v) {
16
- return shorthandParser(v, shorthand_for) !== undefined;
44
+ if (v === "") {
45
+ return true;
46
+ }
47
+ return typeof module.exports.parse(v) === "string";
17
48
  };
18
49
 
19
50
  module.exports.definition = {
20
- set: function (v) {
21
- var normalizedValue = String(v).trim().toLowerCase();
22
-
23
- if (normalizedValue === 'none') {
24
- myShorthandSetter.call(this, '0 0 auto');
25
- return;
51
+ set(v) {
52
+ v = parsers.prepareValue(v, this._global);
53
+ if (parsers.hasVarFunc(v)) {
54
+ this._shorthandSetter("flex", "", shorthandFor);
55
+ this._setProperty("flex", v);
56
+ } else {
57
+ this._shorthandSetter("flex", module.exports.parse(v), shorthandFor);
26
58
  }
27
- if (normalizedValue === 'initial') {
28
- myShorthandSetter.call(this, '0 1 auto');
29
- return;
59
+ },
60
+ get() {
61
+ let val = this.getPropertyValue("flex");
62
+ if (parsers.hasVarFunc(val)) {
63
+ return val;
30
64
  }
31
- if (normalizedValue === 'auto') {
32
- this.removeProperty('flex-grow');
33
- this.removeProperty('flex-shrink');
34
- this.setProperty('flex-basis', normalizedValue);
35
- return;
65
+ val = this._shorthandGetter("flex", shorthandFor);
66
+ if (parsers.hasVarFunc(val)) {
67
+ return "";
36
68
  }
37
-
38
- myShorthandSetter.call(this, v);
69
+ return val;
39
70
  },
40
- get: shorthandGetter('flex', shorthand_for),
41
71
  enumerable: true,
42
- configurable: true,
72
+ configurable: true
43
73
  };
@@ -1,28 +1,33 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var parseMeasurement = require('../parsers').parseMeasurement;
3
+ const parsers = require("../parsers");
4
4
 
5
- function parse(v) {
6
- if (String(v).toLowerCase() === 'auto') {
7
- return 'auto';
5
+ module.exports.parse = function parse(v) {
6
+ const val = parsers.parseMeasurement(v);
7
+ if (val) {
8
+ return val;
8
9
  }
9
- if (String(v).toLowerCase() === 'inherit') {
10
- return 'inherit';
11
- }
12
- return parseMeasurement(v);
13
- }
10
+ const keywords = ["content", "auto", "min-content", "max-content"];
11
+ return parsers.parseKeyword(v, keywords);
12
+ };
14
13
 
15
14
  module.exports.isValid = function isValid(v) {
16
- return parse(v) !== undefined;
15
+ return typeof module.exports.parse(v) === "string";
17
16
  };
18
17
 
19
18
  module.exports.definition = {
20
- set: function (v) {
21
- this._setProperty('flex-basis', parse(v));
19
+ set(v) {
20
+ v = parsers.prepareValue(v, this._global);
21
+ if (parsers.hasVarFunc(v)) {
22
+ this._setProperty("flex", "");
23
+ this._setProperty("flex-basis", v);
24
+ } else {
25
+ this._setProperty("flex-basis", module.exports.parse(v));
26
+ }
22
27
  },
23
- get: function () {
24
- return this.getPropertyValue('flex-basis');
28
+ get() {
29
+ return this.getPropertyValue("flex-basis");
25
30
  },
26
31
  enumerable: true,
27
- configurable: true,
32
+ configurable: true
28
33
  };
@@ -1,19 +1,28 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var parseNumber = require('../parsers').parseNumber;
4
- var POSITION_AT_SHORTHAND = require('../constants').POSITION_AT_SHORTHAND;
3
+ const parsers = require("../parsers");
5
4
 
6
- module.exports.isValid = function isValid(v, positionAtFlexShorthand) {
7
- return parseNumber(v) !== undefined && positionAtFlexShorthand === POSITION_AT_SHORTHAND.first;
5
+ module.exports.parse = function parse(v) {
6
+ return parsers.parseNumber(v, true);
7
+ };
8
+
9
+ module.exports.isValid = function isValid(v) {
10
+ return typeof module.exports.parse(v) === "string";
8
11
  };
9
12
 
10
13
  module.exports.definition = {
11
- set: function (v) {
12
- this._setProperty('flex-grow', parseNumber(v));
14
+ set(v) {
15
+ v = parsers.prepareValue(v, this._global);
16
+ if (parsers.hasVarFunc(v)) {
17
+ this._setProperty("flex", "");
18
+ this._setProperty("flex-grow", v);
19
+ } else {
20
+ this._setProperty("flex-grow", module.exports.parse(v));
21
+ }
13
22
  },
14
- get: function () {
15
- return this.getPropertyValue('flex-grow');
23
+ get() {
24
+ return this.getPropertyValue("flex-grow");
16
25
  },
17
26
  enumerable: true,
18
- configurable: true,
27
+ configurable: true
19
28
  };
@@ -1,19 +1,28 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var parseNumber = require('../parsers').parseNumber;
4
- var POSITION_AT_SHORTHAND = require('../constants').POSITION_AT_SHORTHAND;
3
+ const parsers = require("../parsers");
5
4
 
6
- module.exports.isValid = function isValid(v, positionAtFlexShorthand) {
7
- return parseNumber(v) !== undefined && positionAtFlexShorthand === POSITION_AT_SHORTHAND.second;
5
+ module.exports.parse = function parse(v) {
6
+ return parsers.parseNumber(v, true);
7
+ };
8
+
9
+ module.exports.isValid = function isValid(v) {
10
+ return typeof module.exports.parse(v) === "string";
8
11
  };
9
12
 
10
13
  module.exports.definition = {
11
- set: function (v) {
12
- this._setProperty('flex-shrink', parseNumber(v));
14
+ set(v) {
15
+ v = parsers.prepareValue(v, this._global);
16
+ if (parsers.hasVarFunc(v)) {
17
+ this._setProperty("flex", "");
18
+ this._setProperty("flex-shrink", v);
19
+ } else {
20
+ this._setProperty("flex-shrink", module.exports.parse(v));
21
+ }
13
22
  },
14
- get: function () {
15
- return this.getPropertyValue('flex-shrink');
23
+ get() {
24
+ return this.getPropertyValue("flex-shrink");
16
25
  },
17
26
  enumerable: true,
18
- configurable: true,
27
+ configurable: true
19
28
  };
@@ -1,12 +1,27 @@
1
- 'use strict';
1
+ "use strict";
2
+
3
+ const parsers = require("../parsers");
4
+
5
+ module.exports.parse = function parse(v) {
6
+ const keywords = ["left", "right", "none", "inline-start", "inline-end"];
7
+ return parsers.parseKeyword(v, keywords);
8
+ };
9
+
10
+ module.exports.isValid = function isValid(v) {
11
+ if (v === "") {
12
+ return true;
13
+ }
14
+ return typeof module.exports.parse(v) === "string";
15
+ };
2
16
 
3
17
  module.exports.definition = {
4
- set: function (v) {
5
- this._setProperty('float', v);
18
+ set(v) {
19
+ v = parsers.prepareValue(v, this._global);
20
+ this._setProperty("float", module.exports.parse(v));
6
21
  },
7
- get: function () {
8
- return this.getPropertyValue('float');
22
+ get() {
23
+ return this.getPropertyValue("float");
9
24
  },
10
25
  enumerable: true,
11
- configurable: true,
26
+ configurable: true
12
27
  };
@@ -1,14 +1,30 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var parseColor = require('../parsers').parseColor;
3
+ const parsers = require("../parsers");
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
+ };
12
+
13
+ module.exports.isValid = function isValid(v) {
14
+ if (v === "" || typeof parsers.parseKeyword(v) === "string") {
15
+ return true;
16
+ }
17
+ return parsers.isValidColor(v);
18
+ };
4
19
 
5
20
  module.exports.definition = {
6
- set: function (v) {
7
- this._setProperty('flood-color', parseColor(v));
21
+ set(v) {
22
+ v = parsers.prepareValue(v, this._global);
23
+ this._setProperty("flood-color", module.exports.parse(v));
8
24
  },
9
- get: function () {
10
- return this.getPropertyValue('flood-color');
25
+ get() {
26
+ return this.getPropertyValue("flood-color");
11
27
  },
12
28
  enumerable: true,
13
- configurable: true,
29
+ configurable: true
14
30
  };
@@ -1,43 +1,195 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var TYPES = require('../parsers').TYPES;
4
- var valueType = require('../parsers').valueType;
5
- var shorthandParser = require('../parsers').shorthandParser;
6
- var shorthandSetter = require('../parsers').shorthandSetter;
7
- var shorthandGetter = require('../parsers').shorthandGetter;
3
+ const parsers = require("../parsers");
4
+ const fontStyle = require("./fontStyle");
5
+ const fontVariant = require("./fontVariant");
6
+ const fontWeight = require("./fontWeight");
7
+ const fontSize = require("./fontSize");
8
+ const lineHeight = require("./lineHeight");
9
+ const fontFamily = require("./fontFamily");
8
10
 
9
- var shorthand_for = {
10
- 'font-family': require('./fontFamily'),
11
- 'font-size': require('./fontSize'),
12
- 'font-style': require('./fontStyle'),
13
- 'font-variant': require('./fontVariant'),
14
- 'font-weight': require('./fontWeight'),
15
- 'line-height': require('./lineHeight'),
16
- };
17
-
18
- var static_fonts = [
19
- 'caption',
20
- 'icon',
21
- 'menu',
22
- 'message-box',
23
- 'small-caption',
24
- 'status-bar',
25
- 'inherit',
26
- ];
11
+ const shorthandFor = new Map([
12
+ ["font-style", fontStyle],
13
+ ["font-variant", fontVariant],
14
+ ["font-weight", fontWeight],
15
+ ["font-size", fontSize],
16
+ ["line-height", lineHeight],
17
+ ["font-family", fontFamily]
18
+ ]);
27
19
 
28
- var setter = shorthandSetter('font', shorthand_for);
20
+ module.exports.parse = function parse(v) {
21
+ const keywords = ["caption", "icon", "menu", "message-box", "small-caption", "status-bar"];
22
+ const key = parsers.parseKeyword(v, keywords);
23
+ if (key) {
24
+ return key;
25
+ }
26
+ const [fontBlock, ...families] = parsers.splitValue(v, {
27
+ delimiter: ","
28
+ });
29
+ const [fontBlockA, fontBlockB] = parsers.splitValue(fontBlock, {
30
+ delimiter: "/"
31
+ });
32
+ const font = {
33
+ "font-style": "normal",
34
+ "font-variant": "normal",
35
+ "font-weight": "normal"
36
+ };
37
+ const fontFamilies = new Set();
38
+ if (fontBlockB) {
39
+ const [lineB, ...familiesB] = fontBlockB.trim().split(" ");
40
+ if (!lineB || !lineHeight.isValid(lineB) || !familiesB.length) {
41
+ return;
42
+ }
43
+ const lineHeightB = lineHeight.parse(lineB);
44
+ const familyB = familiesB.join(" ");
45
+ if (fontFamily.isValid(familyB)) {
46
+ fontFamilies.add(fontFamily.parse(familyB));
47
+ } else {
48
+ return;
49
+ }
50
+ const parts = parsers.splitValue(fontBlockA.trim());
51
+ const properties = ["font-style", "font-variant", "font-weight", "font-size"];
52
+ for (const part of parts) {
53
+ if (part === "normal") {
54
+ continue;
55
+ } else {
56
+ for (const property of properties) {
57
+ switch (property) {
58
+ case "font-style":
59
+ case "font-variant":
60
+ case "font-weight": {
61
+ const value = shorthandFor.get(property);
62
+ if (value.isValid(part)) {
63
+ font[property] = value.parse(part);
64
+ }
65
+ break;
66
+ }
67
+ case "font-size": {
68
+ const value = shorthandFor.get(property);
69
+ if (value.isValid(part)) {
70
+ font[property] = value.parse(part);
71
+ }
72
+ break;
73
+ }
74
+ default:
75
+ }
76
+ }
77
+ }
78
+ }
79
+ if (Object.hasOwn(font, "font-size")) {
80
+ font["line-height"] = lineHeightB;
81
+ } else {
82
+ return;
83
+ }
84
+ } else {
85
+ // FIXME: Switch to toReversed() when we can drop Node.js 18 support.
86
+ const revParts = [...parsers.splitValue(fontBlockA.trim())].reverse();
87
+ const revFontFamily = [];
88
+ const properties = ["font-style", "font-variant", "font-weight", "line-height"];
89
+ font["font-style"] = "normal";
90
+ font["font-variant"] = "normal";
91
+ font["font-weight"] = "normal";
92
+ font["line-height"] = "normal";
93
+ let fontSizeA;
94
+ for (const part of revParts) {
95
+ if (fontSizeA) {
96
+ if (part === "normal") {
97
+ continue;
98
+ } else {
99
+ for (const property of properties) {
100
+ switch (property) {
101
+ case "font-style":
102
+ case "font-variant":
103
+ case "font-weight":
104
+ case "line-height": {
105
+ const value = shorthandFor.get(property);
106
+ if (value.isValid(part)) {
107
+ font[property] = value.parse(part);
108
+ }
109
+ break;
110
+ }
111
+ default:
112
+ }
113
+ }
114
+ }
115
+ } else if (fontSize.isValid(part)) {
116
+ fontSizeA = fontSize.parse(part);
117
+ } else if (fontFamily.isValid(part)) {
118
+ revFontFamily.push(part);
119
+ } else {
120
+ return;
121
+ }
122
+ }
123
+ const family = revFontFamily.reverse().join(" ");
124
+ if (fontSizeA && fontFamily.isValid(family)) {
125
+ font["font-size"] = fontSizeA;
126
+ fontFamilies.add(fontFamily.parse(family));
127
+ } else {
128
+ return;
129
+ }
130
+ }
131
+ for (const family of families) {
132
+ if (fontFamily.isValid(family)) {
133
+ fontFamilies.add(fontFamily.parse(family));
134
+ } else {
135
+ return;
136
+ }
137
+ }
138
+ font["font-family"] = [...fontFamilies].join(", ");
139
+ return font;
140
+ };
29
141
 
30
142
  module.exports.definition = {
31
- set: function (v) {
32
- var short = shorthandParser(v, shorthand_for);
33
- if (short !== undefined) {
34
- return setter.call(this, v);
143
+ set(v) {
144
+ v = parsers.prepareValue(v, this._global);
145
+ if (v === "" || parsers.hasVarFunc(v)) {
146
+ for (const [key] of shorthandFor) {
147
+ this._setProperty(key, "");
148
+ }
149
+ this._setProperty("font", v);
150
+ } else {
151
+ const obj = module.exports.parse(v);
152
+ if (!obj) {
153
+ return;
154
+ }
155
+ const str = new Set();
156
+ for (const [key] of shorthandFor) {
157
+ const val = obj[key];
158
+ if (typeof val === "string") {
159
+ this._setProperty(key, val);
160
+ if (val && val !== "normal" && !str.has(val)) {
161
+ if (key === "line-height") {
162
+ str.add(`/ ${val}`);
163
+ } else {
164
+ str.add(val);
165
+ }
166
+ }
167
+ }
168
+ }
169
+ this._setProperty("font", [...str].join(" "));
170
+ }
171
+ },
172
+ get() {
173
+ const val = this.getPropertyValue("font");
174
+ if (parsers.hasVarFunc(val)) {
175
+ return val;
35
176
  }
36
- if (valueType(v) === TYPES.KEYWORD && static_fonts.indexOf(v.toLowerCase()) !== -1) {
37
- this._setProperty('font', v);
177
+ const str = new Set();
178
+ for (const [key] of shorthandFor) {
179
+ const v = this.getPropertyValue(key);
180
+ if (parsers.hasVarFunc(v)) {
181
+ return "";
182
+ }
183
+ if (v && v !== "normal" && !str.has(v)) {
184
+ if (key === "line-height") {
185
+ str.add(`/ ${v}`);
186
+ } else {
187
+ str.add(`${v}`);
188
+ }
189
+ }
38
190
  }
191
+ return [...str].join(" ");
39
192
  },
40
- get: shorthandGetter('font', shorthand_for),
41
193
  enumerable: true,
42
- configurable: true,
194
+ configurable: true
43
195
  };
@@ -1,33 +1,85 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var TYPES = require('../parsers').TYPES;
4
- var valueType = require('../parsers').valueType;
3
+ const parsers = require("../parsers");
5
4
 
6
- var partsRegEx = /\s*,\s*/;
7
- module.exports.isValid = function isValid(v) {
8
- if (v === '' || v === null) {
9
- return true;
5
+ module.exports.parse = function parse(v) {
6
+ if (v === "") {
7
+ return v;
10
8
  }
11
- var parts = v.split(partsRegEx);
12
- var len = parts.length;
13
- var i;
14
- var type;
15
- for (i = 0; i < len; i++) {
16
- type = valueType(parts[i]);
17
- if (type === TYPES.STRING || type === TYPES.KEYWORD) {
18
- return true;
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 val = parsers.splitValue(v, {
23
+ delimiter: ","
24
+ });
25
+ const font = [];
26
+ let valid = false;
27
+ for (const i of val) {
28
+ const str = parsers.parseString(i);
29
+ if (str) {
30
+ font.push(str);
31
+ valid = true;
32
+ continue;
33
+ }
34
+ const key = parsers.parseKeyword(i, keywords);
35
+ if (key) {
36
+ font.push(key);
37
+ valid = true;
38
+ continue;
39
+ }
40
+ // This implementation does not strictly follow the specification.
41
+ // The spec does not require the first letter of the font-family to be
42
+ // capitalized, and unquoted font-family names are not restricted to ASCII.
43
+ // However, in the real world, the first letter of the ASCII font-family
44
+ // names are capitalized, and unquoted font-family names do not contain
45
+ // spaces, e.g. `Times`. And non-ASCII font-family names are quoted even
46
+ // without spaces, e.g. `"メイリオ"`.
47
+ // @see https://drafts.csswg.org/css-fonts/#font-family-prop
48
+ if (
49
+ i !== "undefined" &&
50
+ /^(?:[A-Z][A-Za-z\d-]+(?:\s+[A-Z][A-Za-z\d-]+)*|-?[a-z][a-z-]+)$/.test(i)
51
+ ) {
52
+ font.push(i.trim());
53
+ valid = true;
54
+ continue;
55
+ }
56
+ if (!valid) {
57
+ return;
19
58
  }
20
59
  }
21
- return false;
60
+ return font.join(", ");
61
+ };
62
+
63
+ module.exports.isValid = function isValid(v) {
64
+ if (v === "") {
65
+ return true;
66
+ }
67
+ return typeof module.exports.parse(v) === "string";
22
68
  };
23
69
 
24
70
  module.exports.definition = {
25
- set: function (v) {
26
- this._setProperty('font-family', v);
71
+ set(v) {
72
+ v = parsers.prepareValue(v, this._global);
73
+ if (parsers.hasVarFunc(v)) {
74
+ this._setProperty("font", "");
75
+ this._setProperty("font-family", v);
76
+ } else {
77
+ this._setProperty("font-family", module.exports.parse(v));
78
+ }
27
79
  },
28
- get: function () {
29
- return this.getPropertyValue('font-family');
80
+ get() {
81
+ return this.getPropertyValue("font-family");
30
82
  },
31
83
  enumerable: true,
32
- configurable: true,
84
+ configurable: true
33
85
  };