cssstyle 5.2.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/lib/CSSStyleDeclaration.js +250 -254
  2. package/lib/generated/allProperties.js +39 -1
  3. package/lib/generated/implementedProperties.js +2219 -80
  4. package/lib/generated/properties.js +5253 -1904
  5. package/lib/normalize.js +1417 -0
  6. package/lib/parsers.js +372 -389
  7. package/lib/properties/background.js +76 -63
  8. package/lib/properties/backgroundAttachment.js +37 -22
  9. package/lib/properties/backgroundClip.js +37 -22
  10. package/lib/properties/backgroundColor.js +35 -15
  11. package/lib/properties/backgroundImage.js +49 -19
  12. package/lib/properties/backgroundOrigin.js +37 -22
  13. package/lib/properties/backgroundPosition.js +145 -128
  14. package/lib/properties/backgroundRepeat.js +55 -48
  15. package/lib/properties/backgroundSize.js +86 -46
  16. package/lib/properties/border.js +139 -22
  17. package/lib/properties/borderBottom.js +137 -21
  18. package/lib/properties/borderBottomColor.js +41 -16
  19. package/lib/properties/borderBottomStyle.js +39 -30
  20. package/lib/properties/borderBottomWidth.js +49 -16
  21. package/lib/properties/borderCollapse.js +32 -8
  22. package/lib/properties/borderColor.js +96 -23
  23. package/lib/properties/borderLeft.js +137 -21
  24. package/lib/properties/borderLeftColor.js +41 -16
  25. package/lib/properties/borderLeftStyle.js +39 -30
  26. package/lib/properties/borderLeftWidth.js +49 -16
  27. package/lib/properties/borderRight.js +137 -21
  28. package/lib/properties/borderRightColor.js +41 -16
  29. package/lib/properties/borderRightStyle.js +39 -30
  30. package/lib/properties/borderRightWidth.js +49 -16
  31. package/lib/properties/borderSpacing.js +42 -25
  32. package/lib/properties/borderStyle.js +96 -34
  33. package/lib/properties/borderTop.js +131 -15
  34. package/lib/properties/borderTopColor.js +41 -16
  35. package/lib/properties/borderTopStyle.js +39 -30
  36. package/lib/properties/borderTopWidth.js +49 -16
  37. package/lib/properties/borderWidth.js +108 -23
  38. package/lib/properties/bottom.js +40 -12
  39. package/lib/properties/clear.js +32 -22
  40. package/lib/properties/clip.js +46 -32
  41. package/lib/properties/color.js +34 -13
  42. package/lib/properties/display.js +169 -179
  43. package/lib/properties/flex.js +137 -38
  44. package/lib/properties/flexBasis.js +43 -14
  45. package/lib/properties/flexGrow.js +42 -9
  46. package/lib/properties/flexShrink.js +42 -9
  47. package/lib/properties/float.js +32 -9
  48. package/lib/properties/floodColor.js +34 -13
  49. package/lib/properties/font.js +145 -44
  50. package/lib/properties/fontFamily.js +66 -67
  51. package/lib/properties/fontSize.js +43 -26
  52. package/lib/properties/fontStyle.js +42 -11
  53. package/lib/properties/fontVariant.js +52 -15
  54. package/lib/properties/fontWeight.js +47 -15
  55. package/lib/properties/height.js +40 -13
  56. package/lib/properties/left.js +40 -12
  57. package/lib/properties/lightingColor.js +34 -13
  58. package/lib/properties/lineHeight.js +45 -18
  59. package/lib/properties/margin.js +73 -36
  60. package/lib/properties/marginBottom.js +43 -19
  61. package/lib/properties/marginLeft.js +43 -19
  62. package/lib/properties/marginRight.js +43 -19
  63. package/lib/properties/marginTop.js +43 -19
  64. package/lib/properties/opacity.js +41 -28
  65. package/lib/properties/outlineColor.js +34 -13
  66. package/lib/properties/padding.js +71 -36
  67. package/lib/properties/paddingBottom.js +44 -21
  68. package/lib/properties/paddingLeft.js +44 -19
  69. package/lib/properties/paddingRight.js +44 -19
  70. package/lib/properties/paddingTop.js +44 -19
  71. package/lib/properties/right.js +40 -12
  72. package/lib/properties/stopColor.js +34 -13
  73. package/lib/properties/top.js +40 -12
  74. package/lib/properties/webkitBorderAfterColor.js +34 -13
  75. package/lib/properties/webkitBorderBeforeColor.js +34 -13
  76. package/lib/properties/webkitBorderEndColor.js +34 -13
  77. package/lib/properties/webkitBorderStartColor.js +34 -13
  78. package/lib/properties/webkitColumnRuleColor.js +34 -13
  79. package/lib/properties/webkitTapHighlightColor.js +34 -13
  80. package/lib/properties/webkitTextEmphasisColor.js +34 -13
  81. package/lib/properties/webkitTextFillColor.js +34 -13
  82. package/lib/properties/webkitTextStrokeColor.js +34 -13
  83. package/lib/properties/width.js +40 -13
  84. package/lib/{allWebkitProperties.js → utils/allExtraProperties.js} +42 -1
  85. package/lib/utils/propertyDescriptors.js +6 -3
  86. package/package.json +11 -10
  87. package/lib/allExtraProperties.js +0 -49
  88. package/lib/shorthandProperties.js +0 -21
@@ -1,43 +1,128 @@
1
1
  "use strict";
2
2
 
3
3
  const parsers = require("../parsers");
4
+ const borderTopWidth = require("./borderTopWidth");
5
+ const borderRightWidth = require("./borderRightWidth");
6
+ const borderBottomWidth = require("./borderBottomWidth");
7
+ const borderLeftWidth = require("./borderLeftWidth");
4
8
 
5
- module.exports.parse = function parse(v) {
6
- const keywords = ["thin", "medium", "thick"];
7
- const key = parsers.parseKeyword(v, keywords);
8
- if (key) {
9
- return key;
10
- }
11
- return parsers.parseLength(v, true);
12
- };
9
+ const property = "border-width";
10
+ const shorthand = "border";
13
11
 
14
- module.exports.isValid = function isValid(v) {
12
+ module.exports.shorthandFor = new Map([
13
+ ["border-top-width", borderTopWidth],
14
+ ["border-right-width", borderRightWidth],
15
+ ["border-bottom-width", borderBottomWidth],
16
+ ["border-left-width", borderLeftWidth]
17
+ ]);
18
+
19
+ module.exports.parse = function parse(v, opt = {}) {
20
+ const { globalObject } = opt;
15
21
  if (v === "") {
16
- return true;
22
+ return v;
23
+ }
24
+ const values = parsers.parsePropertyValue(property, v, {
25
+ globalObject,
26
+ inArray: true
27
+ });
28
+ const parsedValues = [];
29
+ if (Array.isArray(values) && values.length) {
30
+ if (values.length > 4) {
31
+ return;
32
+ }
33
+ for (const value of values) {
34
+ const { isNumber, name, type, value: itemValue } = value;
35
+ switch (type) {
36
+ case "Calc": {
37
+ if (isNumber) {
38
+ return;
39
+ }
40
+ parsedValues.push(`${name}(${itemValue})`);
41
+ break;
42
+ }
43
+ case "GlobalKeyword": {
44
+ if (values.length !== 1) {
45
+ return;
46
+ }
47
+ return name;
48
+ }
49
+ case "Identifier": {
50
+ parsedValues.push(name);
51
+ break;
52
+ }
53
+ default: {
54
+ const parsedValue = parsers.parseLength([value], {
55
+ min: 0
56
+ });
57
+ if (!parsedValue) {
58
+ return;
59
+ }
60
+ parsedValues.push(parsedValue);
61
+ }
62
+ }
63
+ }
64
+ } else if (typeof values === "string") {
65
+ parsedValues.push(values);
66
+ }
67
+ if (parsedValues.length) {
68
+ switch (parsedValues.length) {
69
+ case 1: {
70
+ return parsedValues;
71
+ }
72
+ case 2: {
73
+ const [val1, val2] = parsedValues;
74
+ if (val1 === val2) {
75
+ return [val1];
76
+ }
77
+ return parsedValues;
78
+ }
79
+ case 3: {
80
+ const [val1, val2, val3] = parsedValues;
81
+ if (val1 === val3) {
82
+ if (val1 === val2) {
83
+ return [val1];
84
+ }
85
+ return [val1, val2];
86
+ }
87
+ return parsedValues;
88
+ }
89
+ case 4: {
90
+ const [val1, val2, val3, val4] = parsedValues;
91
+ if (val2 === val4) {
92
+ if (val1 === val3) {
93
+ if (val1 === val2) {
94
+ return [val1];
95
+ }
96
+ return [val1, val2];
97
+ }
98
+ return [val1, val2, val3];
99
+ }
100
+ return parsedValues;
101
+ }
102
+ default:
103
+ }
17
104
  }
18
- return typeof module.exports.parse(v) === "string";
19
105
  };
20
106
 
21
107
  module.exports.definition = {
22
108
  set(v) {
23
109
  v = parsers.prepareValue(v, this._global);
24
110
  if (parsers.hasVarFunc(v)) {
25
- this._setProperty("border", "");
26
- this._setProperty("border-width", v);
111
+ this._borderSetter(property, v, "");
27
112
  } else {
28
- const positions = ["top", "right", "bottom", "left"];
29
- this._implicitSetter(
30
- "border",
31
- "width",
32
- v,
33
- module.exports.isValid,
34
- module.exports.parse,
35
- positions
36
- );
113
+ const val = module.exports.parse(v, {
114
+ globalObject: this._global
115
+ });
116
+ if (Array.isArray(val) || typeof val === "string") {
117
+ const shorthandPriority = this._priorities.get(shorthand);
118
+ const prior = this._priorities.get(property) ?? "";
119
+ const priority = shorthandPriority && prior ? "" : prior;
120
+ this._borderSetter(property, val, priority);
121
+ }
37
122
  }
38
123
  },
39
124
  get() {
40
- return this.getPropertyValue("border-width");
125
+ return this.getPropertyValue(property);
41
126
  },
42
127
  enumerable: true,
43
128
  configurable: true
@@ -2,28 +2,56 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
6
- const dim = parsers.parseMeasurement(v);
7
- if (dim) {
8
- return dim;
9
- }
10
- return parsers.parseKeyword(v, ["auto"]);
11
- };
5
+ const property = "bottom";
12
6
 
13
- module.exports.isValid = function isValid(v) {
7
+ module.exports.parse = function parse(v, opt = {}) {
8
+ const { globalObject } = opt;
14
9
  if (v === "") {
15
- return true;
10
+ return v;
11
+ }
12
+ const value = parsers.parsePropertyValue(property, v, {
13
+ globalObject,
14
+ inArray: true
15
+ });
16
+ if (Array.isArray(value) && value.length === 1) {
17
+ const [{ isNumber, name, raw, type }] = value;
18
+ switch (type) {
19
+ case "Calc": {
20
+ if (!isNumber) {
21
+ return raw;
22
+ }
23
+ break;
24
+ }
25
+ case "GlobalKeyword":
26
+ case "Identifier": {
27
+ return name;
28
+ }
29
+ default: {
30
+ return parsers.parseLengthPercentage(value);
31
+ }
32
+ }
33
+ } else if (typeof value === "string") {
34
+ return value;
16
35
  }
17
- return typeof module.exports.parse(v) === "string";
18
36
  };
19
37
 
20
38
  module.exports.definition = {
21
39
  set(v) {
22
40
  v = parsers.prepareValue(v, this._global);
23
- this._setProperty("bottom", module.exports.parse(v));
41
+ if (parsers.hasVarFunc(v)) {
42
+ this._setProperty(property, v);
43
+ } else {
44
+ const val = module.exports.parse(v, {
45
+ globalObject: this._global
46
+ });
47
+ if (typeof val === "string") {
48
+ const priority = this._priorities.get(property) ?? "";
49
+ this._setProperty(property, val, priority);
50
+ }
51
+ }
24
52
  },
25
53
  get() {
26
- return this.getPropertyValue("bottom");
54
+ return this.getPropertyValue(property);
27
55
  },
28
56
  enumerable: true,
29
57
  configurable: true
@@ -2,38 +2,48 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
6
- const keywords = [
7
- "inline-start",
8
- "inline-end",
9
- "block-start",
10
- "block-end",
11
- "left",
12
- "right",
13
- "top",
14
- "bottom",
15
- "both-inline",
16
- "both-block",
17
- "both",
18
- "none"
19
- ];
20
- return parsers.parseKeyword(v, keywords);
21
- };
5
+ const property = "clear";
22
6
 
23
- module.exports.isValid = function isValid(v) {
7
+ module.exports.parse = function parse(v, opt = {}) {
8
+ const { globalObject } = opt;
24
9
  if (v === "") {
25
- return true;
10
+ return v;
11
+ }
12
+ const value = parsers.parsePropertyValue(property, v, {
13
+ globalObject,
14
+ inArray: true
15
+ });
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
+ }
25
+ } else if (typeof value === "string") {
26
+ return value;
26
27
  }
27
- return typeof module.exports.parse(v) === "string";
28
28
  };
29
29
 
30
30
  module.exports.definition = {
31
31
  set(v) {
32
32
  v = parsers.prepareValue(v, this._global);
33
- this._setProperty("clear", module.exports.parse(v));
33
+ if (parsers.hasVarFunc(v)) {
34
+ this._setProperty(property, v);
35
+ } else {
36
+ const val = module.exports.parse(v, {
37
+ globalObject: this._global
38
+ });
39
+ if (typeof val === "string") {
40
+ const priority = this._priorities.get(property) ?? "";
41
+ this._setProperty(property, val, priority);
42
+ }
43
+ }
34
44
  },
35
45
  get() {
36
- return this.getPropertyValue("clear");
46
+ return this.getPropertyValue(property);
37
47
  },
38
48
  enumerable: true,
39
49
  configurable: true
@@ -3,51 +3,65 @@
3
3
  // @see https://drafts.fxtf.org/css-masking/#clip-property
4
4
 
5
5
  const parsers = require("../parsers");
6
- const strings = require("../utils/strings");
7
6
 
8
- module.exports.parse = function parse(v) {
7
+ const property = "clip";
8
+
9
+ module.exports.parse = function parse(v, opt = {}) {
10
+ const { globalObject } = opt;
9
11
  if (v === "") {
10
12
  return v;
11
13
  }
12
- const val = parsers.parseKeyword(v, ["auto"]);
13
- if (val) {
14
- return val;
15
- }
16
- // parse legacy <shape>
17
- v = strings.asciiLowercase(v);
18
- const matches = v.match(/^rect\(\s*(.*)\s*\)$/);
19
- if (!matches) {
20
- return;
21
- }
22
- const parts = matches[1].split(/\s*,\s*/);
23
- if (parts.length !== 4) {
24
- return;
25
- }
26
- const valid = parts.every(function (part, index) {
27
- const measurement = parsers.parseMeasurement(part.trim());
28
- parts[index] = measurement;
29
- return typeof measurement === "string";
14
+ const value = parsers.parsePropertyValue(property, v, {
15
+ globalObject,
16
+ inArray: true
30
17
  });
31
- if (!valid) {
32
- return;
33
- }
34
- return `rect(${parts.join(", ")})`;
35
- };
36
-
37
- module.exports.isValid = function isValid(v) {
38
- if (v === "") {
39
- return true;
18
+ if (Array.isArray(value) && value.length === 1) {
19
+ const [{ name, type, value: itemValue }] = value;
20
+ switch (type) {
21
+ case "Function": {
22
+ const values = parsers.splitValue(itemValue, {
23
+ delimiter: ","
24
+ });
25
+ const parsedValues = [];
26
+ for (const item of values) {
27
+ const parsedValue = parsers.parseCSS(item, { context: "value" }, true);
28
+ const val = parsers.parseLengthPercentage(parsedValue.children);
29
+ if (val) {
30
+ parsedValues.push(val);
31
+ } else {
32
+ return;
33
+ }
34
+ }
35
+ return `${name}(${parsedValues.join(", ")})`;
36
+ }
37
+ case "GlobalKeyword":
38
+ case "Identifier": {
39
+ return name;
40
+ }
41
+ default:
42
+ }
43
+ } else if (typeof value === "string") {
44
+ return value;
40
45
  }
41
- return typeof module.exports.parse(v) === "string";
42
46
  };
43
47
 
44
48
  module.exports.definition = {
45
49
  set(v) {
46
50
  v = parsers.prepareValue(v, this._global);
47
- this._setProperty("clip", module.exports.parse(v));
51
+ if (parsers.hasVarFunc(v)) {
52
+ this._setProperty(property, v);
53
+ } else {
54
+ const val = module.exports.parse(v, {
55
+ globalObject: this._global
56
+ });
57
+ if (typeof val === "string") {
58
+ const priority = this._priorities.get(property) ?? "";
59
+ this._setProperty(property, val, priority);
60
+ }
61
+ }
48
62
  },
49
63
  get() {
50
- return this.getPropertyValue("clip");
64
+ return this.getPropertyValue(property);
51
65
  },
52
66
  enumerable: true,
53
67
  configurable: true
@@ -2,28 +2,49 @@
2
2
 
3
3
  const parsers = require("../parsers");
4
4
 
5
- module.exports.parse = function parse(v) {
6
- const val = parsers.parseColor(v);
7
- if (val) {
8
- return val;
9
- }
10
- return parsers.parseKeyword(v);
11
- };
5
+ const property = "color";
12
6
 
13
- module.exports.isValid = function isValid(v) {
14
- if (v === "" || typeof parsers.parseKeyword(v) === "string") {
15
- return true;
7
+ module.exports.parse = function parse(v, opt = {}) {
8
+ const { globalObject } = opt;
9
+ if (v === "") {
10
+ return v;
11
+ }
12
+ const value = parsers.parsePropertyValue(property, v, {
13
+ globalObject,
14
+ inArray: true
15
+ });
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
+ }
26
+ } else if (typeof value === "string") {
27
+ return value;
16
28
  }
17
- return parsers.isValidColor(v);
18
29
  };
19
30
 
20
31
  module.exports.definition = {
21
32
  set(v) {
22
33
  v = parsers.prepareValue(v, this._global);
23
- this._setProperty("color", module.exports.parse(v));
34
+ if (parsers.hasVarFunc(v)) {
35
+ this._setProperty(property, v);
36
+ } else {
37
+ const val = module.exports.parse(v, {
38
+ globalObject: this._global
39
+ });
40
+ if (typeof val === "string") {
41
+ const priority = this._priorities.get(property) ?? "";
42
+ this._setProperty(property, val, priority);
43
+ }
44
+ }
24
45
  },
25
46
  get() {
26
- return this.getPropertyValue("color");
47
+ return this.getPropertyValue(property);
27
48
  },
28
49
  enumerable: true,
29
50
  configurable: true