cssstyle 4.3.0 → 4.4.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 +2574 -0
  7. package/lib/parsers.js +400 -544
  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 +120 -33
  47. package/lib/properties/fontFamily.js +59 -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,130 @@
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
+ let blockA, blockB;
30
+ if (fontBlock.includes("/")) {
31
+ [blockA, blockB] = parsers.splitValue(fontBlock, {
32
+ delimiter: "/"
33
+ });
34
+ } else {
35
+ blockA = fontBlock.trim();
36
+ }
37
+ const obj = parsers.parseShorthand(blockA, shorthandFor, true);
38
+ if (!obj) {
39
+ return;
40
+ }
41
+ const font = {};
42
+ const fontFamilies = new Set();
43
+ for (const [property, value] of Object.entries(obj)) {
44
+ if (property === "font-family") {
45
+ if (!blockB) {
46
+ fontFamilies.add(value);
47
+ }
48
+ } else {
49
+ font[property] = value;
50
+ }
51
+ }
52
+ // blockB, if matched, includes line-height and first font-family
53
+ if (blockB) {
54
+ const [lineheight, family] = parsers.splitValue(blockB);
55
+ if (lineHeight.isValid(lineheight)) {
56
+ font["line-height"] = lineHeight.parse(lineheight);
57
+ } else {
58
+ return;
59
+ }
60
+ if (fontFamily.isValid(family)) {
61
+ fontFamilies.add(fontFamily.parse(family));
62
+ } else {
63
+ return;
64
+ }
65
+ }
66
+ for (const family of families) {
67
+ if (fontFamily.isValid(family)) {
68
+ fontFamilies.add(fontFamily.parse(family));
69
+ } else {
70
+ return;
71
+ }
72
+ }
73
+ font["font-family"] = [...fontFamilies].join(", ");
74
+ return font;
75
+ };
29
76
 
30
77
  module.exports.definition = {
31
- set: function (v) {
32
- var short = shorthandParser(v, shorthand_for);
33
- if (short !== undefined) {
34
- return setter.call(this, v);
78
+ set(v) {
79
+ v = parsers.prepareValue(v, this._global);
80
+ if (parsers.hasVarFunc(v)) {
81
+ for (const [key] of shorthandFor) {
82
+ this._setProperty(key, "");
83
+ }
84
+ this._setProperty("font", v);
85
+ } else {
86
+ const obj = module.exports.parse(v);
87
+ if (!obj) {
88
+ return;
89
+ }
90
+ const str = new Set();
91
+ for (const [key] of shorthandFor) {
92
+ const val = obj[key];
93
+ if (typeof val === "string") {
94
+ this._setProperty(key, val);
95
+ if (val && !str.has(val)) {
96
+ if (key === "line-height") {
97
+ str.add(`/ ${val}`);
98
+ } else {
99
+ str.add(val);
100
+ }
101
+ }
102
+ }
103
+ }
104
+ this._setProperty("font", [...str].join(" "));
105
+ }
106
+ },
107
+ get() {
108
+ const val = this.getPropertyValue("font");
109
+ if (parsers.hasVarFunc(val)) {
110
+ return val;
35
111
  }
36
- if (valueType(v) === TYPES.KEYWORD && static_fonts.indexOf(v.toLowerCase()) !== -1) {
37
- this._setProperty('font', v);
112
+ const str = new Set();
113
+ for (const [key] of shorthandFor) {
114
+ const v = this.getPropertyValue(key);
115
+ if (parsers.hasVarFunc(v)) {
116
+ return "";
117
+ }
118
+ if (v && !str.has(v)) {
119
+ if (key === "line-height") {
120
+ str.add(`/ ${v}`);
121
+ } else {
122
+ str.add(`${v}`);
123
+ }
124
+ }
38
125
  }
126
+ return [...str].join(" ");
39
127
  },
40
- get: shorthandGetter('font', shorthand_for),
41
128
  enumerable: true,
42
- configurable: true,
129
+ configurable: true
43
130
  };
@@ -1,33 +1,71 @@
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 = ["serif", "sans-serif", "system-ui", "cursive", "fantasy", "monospace"];
10
+ const val = parsers.splitValue(v, {
11
+ delimiter: ","
12
+ });
13
+ const font = [];
14
+ let valid = false;
15
+ for (const i of val) {
16
+ const str = parsers.parseString(i);
17
+ if (str) {
18
+ font.push(str);
19
+ valid = true;
20
+ continue;
21
+ }
22
+ const key = parsers.parseKeyword(i, keywords);
23
+ if (key) {
24
+ font.push(key);
25
+ valid = true;
26
+ continue;
27
+ }
28
+ // This implementation does not strictly follow the specification. The spec
29
+ // does not require the first letter of the font-family to be capitalized.
30
+ // Also, unquoted font-family names are not restricted to ASCII only.
31
+ // However, in the real world, the first letter of the ASCII font-family
32
+ // names are always capitalized, and unquoted font-family names do not
33
+ // contain spaces, e.g. `Times`, and AFAIK, non-ASCII font-family names are
34
+ // always quoted even without spaces, e.g. `"メイリオ"`.
35
+ // Therefore, it is unlikely that this implementation will cause problems.
36
+ // @see https://drafts.csswg.org/css-fonts/#font-family-prop
37
+ if (/^\s*(?:[A-Z][A-Za-z\d\s-]+)\s*$/.test(i)) {
38
+ font.push(i.trim());
39
+ valid = true;
40
+ continue;
41
+ }
42
+ if (!valid) {
43
+ return;
19
44
  }
20
45
  }
21
- return false;
46
+ return font.join(", ");
47
+ };
48
+
49
+ module.exports.isValid = function isValid(v) {
50
+ if (v === "") {
51
+ return true;
52
+ }
53
+ return typeof module.exports.parse(v) === "string";
22
54
  };
23
55
 
24
56
  module.exports.definition = {
25
- set: function (v) {
26
- this._setProperty('font-family', v);
57
+ set(v) {
58
+ v = parsers.prepareValue(v, this._global);
59
+ if (parsers.hasVarFunc(v)) {
60
+ this._setProperty("font", "");
61
+ this._setProperty("font-family", v);
62
+ } else {
63
+ this._setProperty("font-family", module.exports.parse(v));
64
+ }
27
65
  },
28
- get: function () {
29
- return this.getPropertyValue('font-family');
66
+ get() {
67
+ return this.getPropertyValue("font-family");
30
68
  },
31
69
  enumerable: true,
32
- configurable: true,
70
+ configurable: true
33
71
  };
@@ -1,38 +1,47 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var TYPES = require('../parsers').TYPES;
4
- var valueType = require('../parsers').valueType;
5
- var parseMeasurement = require('../parsers').parseMeasurement;
3
+ const parsers = require("../parsers");
6
4
 
7
- var absoluteSizes = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'];
8
- var relativeSizes = ['larger', 'smaller'];
9
-
10
- module.exports.isValid = function (v) {
11
- var type = valueType(v.toLowerCase());
12
- return (
13
- type === TYPES.LENGTH ||
14
- type === TYPES.PERCENT ||
15
- (type === TYPES.KEYWORD && absoluteSizes.indexOf(v.toLowerCase()) !== -1) ||
16
- (type === TYPES.KEYWORD && relativeSizes.indexOf(v.toLowerCase()) !== -1)
17
- );
5
+ module.exports.parse = function parse(v) {
6
+ const val = parsers.parseMeasurement(v, true);
7
+ if (val) {
8
+ return val;
9
+ }
10
+ const keywords = [
11
+ "xx-small",
12
+ "x-small",
13
+ "small",
14
+ "medium",
15
+ "large",
16
+ "x-large",
17
+ "xx-large",
18
+ "xxx-large",
19
+ "smaller",
20
+ "larger"
21
+ ];
22
+ return parsers.parseKeyword(v, keywords);
18
23
  };
19
24
 
20
- function parse(v) {
21
- const valueAsString = String(v).toLowerCase();
22
- const optionalArguments = absoluteSizes.concat(relativeSizes);
23
- const isOptionalArgument = optionalArguments.some(
24
- (stringValue) => stringValue.toLowerCase() === valueAsString
25
- );
26
- return isOptionalArgument ? valueAsString : parseMeasurement(v);
27
- }
25
+ module.exports.isValid = function isValid(v) {
26
+ if (v === "") {
27
+ return true;
28
+ }
29
+ return typeof module.exports.parse(v) === "string";
30
+ };
28
31
 
29
32
  module.exports.definition = {
30
- set: function (v) {
31
- this._setProperty('font-size', parse(v));
33
+ set(v) {
34
+ v = parsers.prepareValue(v, this._global);
35
+ if (parsers.hasVarFunc(v)) {
36
+ this._setProperty("font", "");
37
+ this._setProperty("font-size", v);
38
+ } else {
39
+ this._setProperty("font-size", module.exports.parse(v));
40
+ }
32
41
  },
33
- get: function () {
34
- return this.getPropertyValue('font-size');
42
+ get() {
43
+ return this.getPropertyValue("font-size");
35
44
  },
36
45
  enumerable: true,
37
- configurable: true,
46
+ configurable: true
38
47
  };