@tbela99/css-parser 1.4.3 → 1.4.5

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 (166) hide show
  1. package/CHANGELOG.md +196 -2
  2. package/README.md +68 -1120
  3. package/dist/config.json.js +43 -2
  4. package/dist/index-umd-web.js +18118 -15886
  5. package/dist/index.cjs +16838 -14611
  6. package/dist/index.d.ts +1804 -1684
  7. package/dist/lib/ast/clone.js +4 -3
  8. package/dist/lib/ast/expand.js +2 -2
  9. package/dist/lib/ast/features/calc.js +59 -54
  10. package/dist/lib/ast/features/if.js +64 -17
  11. package/dist/lib/ast/features/inlinecssvariables.js +2 -2
  12. package/dist/lib/ast/features/prefix.js +343 -6
  13. package/dist/lib/ast/features/transform.js +7 -4
  14. package/dist/lib/ast/find.js +5 -5
  15. package/dist/lib/ast/math/expression.js +12 -8
  16. package/dist/lib/ast/minify.js +28 -33
  17. package/dist/lib/ast/transform/minify.js +135 -131
  18. package/dist/lib/ast/transform/utils.js +3 -2
  19. package/dist/lib/ast/types.js +69 -8
  20. package/dist/lib/ast/walk.js +4 -5
  21. package/dist/lib/fs/resolve.js +71 -57
  22. package/dist/lib/parser/declaration/list.js +92 -3
  23. package/dist/lib/parser/declaration/map.js +5 -5
  24. package/dist/lib/parser/parse.js +530 -466
  25. package/dist/lib/parser/tokenize.js +110 -4
  26. package/dist/lib/parser/utils/angle.js +29 -0
  27. package/dist/lib/parser/utils/at-rule-container.js +2 -2
  28. package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
  29. package/dist/lib/parser/utils/at-rule-generic.js +1 -1
  30. package/dist/lib/parser/utils/at-rule-media.js +2 -2
  31. package/dist/lib/parser/utils/at-rule-support.js +73 -8
  32. package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
  33. package/dist/lib/parser/utils/at-rule.js +2 -8
  34. package/dist/lib/parser/utils/declaration.js +179 -76
  35. package/dist/lib/parser/utils/selector.js +53 -11
  36. package/dist/lib/parser/utils/token.js +13 -11
  37. package/dist/lib/renderer/render.js +501 -59
  38. package/dist/lib/syntax/color/alpha.js +64 -0
  39. package/dist/lib/syntax/color/cmyk.js +2 -2
  40. package/dist/lib/syntax/color/color-mix.js +283 -220
  41. package/dist/lib/syntax/color/color.js +37 -28
  42. package/dist/lib/syntax/color/hex.js +2 -2
  43. package/dist/lib/syntax/color/hsl.js +3 -3
  44. package/dist/lib/syntax/color/hwb.js +7 -7
  45. package/dist/lib/syntax/color/lab.js +5 -5
  46. package/dist/lib/syntax/color/lch.js +4 -4
  47. package/dist/lib/syntax/color/oklab.js +3 -3
  48. package/dist/lib/syntax/color/oklch.js +3 -3
  49. package/dist/lib/syntax/color/relativecolor.js +97 -12
  50. package/dist/lib/syntax/color/srgb.js +5 -5
  51. package/dist/lib/syntax/color/utils/color-type.js +18 -0
  52. package/dist/lib/syntax/color/utils/colorspace.js +46 -0
  53. package/dist/lib/syntax/color/utils/components.js +7 -3
  54. package/dist/lib/syntax/color/utils/distance.js +21 -4
  55. package/dist/lib/syntax/color/utils/make-color.js +56 -0
  56. package/dist/lib/syntax/color/xyz.js +2 -2
  57. package/dist/lib/syntax/constants.js +29 -1
  58. package/dist/lib/syntax/syntax.js +307 -39
  59. package/dist/lib/validation/config.js +2 -2
  60. package/dist/lib/validation/config.json.js +32 -17
  61. package/dist/lib/validation/match.js +239 -104
  62. package/dist/lib/validation/parser/parse.js +0 -1
  63. package/dist/lib/validation/parser/typedef.js +6 -0
  64. package/dist/node.js +64 -22
  65. package/dist/web.js +65 -18
  66. package/package.json +26 -15
  67. package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
  68. package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
  69. package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
  70. package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
  71. package/.repl_history +0 -4
  72. package/badges/coverage.svg +0 -20
  73. package/deno.lock +0 -2861
  74. package/dist/lib/ast/clone.d.ts +0 -10
  75. package/dist/lib/ast/expand.d.ts +0 -14
  76. package/dist/lib/ast/features/calc.d.ts +0 -10
  77. package/dist/lib/ast/features/if.d.ts +0 -10
  78. package/dist/lib/ast/features/index.d.ts +0 -6
  79. package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
  80. package/dist/lib/ast/features/prefix.d.ts +0 -8
  81. package/dist/lib/ast/features/shorthand.d.ts +0 -12
  82. package/dist/lib/ast/features/transform.d.ts +0 -10
  83. package/dist/lib/ast/features/type.d.ts +0 -15
  84. package/dist/lib/ast/find.d.ts +0 -165
  85. package/dist/lib/ast/math/expression.d.ts +0 -18
  86. package/dist/lib/ast/math/math.d.ts +0 -6
  87. package/dist/lib/ast/minify.d.ts +0 -19
  88. package/dist/lib/ast/transform/compute.d.ts +0 -8
  89. package/dist/lib/ast/transform/matrix.d.ts +0 -22
  90. package/dist/lib/ast/transform/minify.d.ts +0 -5
  91. package/dist/lib/ast/transform/perspective.d.ts +0 -3
  92. package/dist/lib/ast/transform/rotate.d.ts +0 -12
  93. package/dist/lib/ast/transform/scale.d.ts +0 -6
  94. package/dist/lib/ast/transform/skew.d.ts +0 -4
  95. package/dist/lib/ast/transform/translate.d.ts +0 -6
  96. package/dist/lib/ast/transform/utils.d.ts +0 -9
  97. package/dist/lib/ast/types.d.ts +0 -903
  98. package/dist/lib/ast/walk.d.ts +0 -162
  99. package/dist/lib/fs/resolve.d.ts +0 -20
  100. package/dist/lib/parser/declaration/list.d.ts +0 -16
  101. package/dist/lib/parser/declaration/map.d.ts +0 -15
  102. package/dist/lib/parser/declaration/set.d.ts +0 -9
  103. package/dist/lib/parser/node.d.ts +0 -7
  104. package/dist/lib/parser/parse.d.ts +0 -107
  105. package/dist/lib/parser/tokenize.d.ts +0 -57
  106. package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
  107. package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
  108. package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
  109. package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
  110. package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
  111. package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
  112. package/dist/lib/parser/utils/at-rule-page.js +0 -28
  113. package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
  114. package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
  115. package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
  116. package/dist/lib/parser/utils/at-rule.d.ts +0 -13
  117. package/dist/lib/parser/utils/cache.d.ts +0 -6
  118. package/dist/lib/parser/utils/config.d.ts +0 -2
  119. package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
  120. package/dist/lib/parser/utils/declaration.d.ts +0 -18
  121. package/dist/lib/parser/utils/eq.d.ts +0 -1
  122. package/dist/lib/parser/utils/hash.d.ts +0 -21
  123. package/dist/lib/parser/utils/selector.d.ts +0 -5
  124. package/dist/lib/parser/utils/text.d.ts +0 -3
  125. package/dist/lib/parser/utils/token.d.ts +0 -14
  126. package/dist/lib/parser/utils/type.d.ts +0 -2
  127. package/dist/lib/renderer/render.d.ts +0 -28
  128. package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
  129. package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
  130. package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
  131. package/dist/lib/syntax/color/cmyk.d.ts +0 -10
  132. package/dist/lib/syntax/color/color-mix.d.ts +0 -2
  133. package/dist/lib/syntax/color/color.d.ts +0 -42
  134. package/dist/lib/syntax/color/hex.d.ts +0 -16
  135. package/dist/lib/syntax/color/hsl.d.ts +0 -20
  136. package/dist/lib/syntax/color/hsv.d.ts +0 -2
  137. package/dist/lib/syntax/color/hwb.d.ts +0 -21
  138. package/dist/lib/syntax/color/lab.d.ts +0 -25
  139. package/dist/lib/syntax/color/lch.d.ts +0 -23
  140. package/dist/lib/syntax/color/oklab.d.ts +0 -22
  141. package/dist/lib/syntax/color/oklch.d.ts +0 -20
  142. package/dist/lib/syntax/color/p3.d.ts +0 -6
  143. package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
  144. package/dist/lib/syntax/color/rec2020.d.ts +0 -2
  145. package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
  146. package/dist/lib/syntax/color/rgb.d.ts +0 -20
  147. package/dist/lib/syntax/color/srgb.d.ts +0 -23
  148. package/dist/lib/syntax/color/utils/components.d.ts +0 -2
  149. package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
  150. package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
  151. package/dist/lib/syntax/color/xyz.d.ts +0 -5
  152. package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
  153. package/dist/lib/syntax/constants.d.ts +0 -67
  154. package/dist/lib/syntax/syntax.d.ts +0 -38
  155. package/dist/lib/validation/config.d.ts +0 -14
  156. package/dist/lib/validation/json.d.ts +0 -2
  157. package/dist/lib/validation/match.d.ts +0 -38
  158. package/dist/lib/validation/parser/parse.d.ts +0 -8
  159. package/dist/lib/validation/parser/typedef.d.ts +0 -95
  160. package/dist/lib/validation/utils/list.d.ts +0 -4
  161. package/dist/lib/validation/utils/whitespace.d.ts +0 -2
  162. package/dist/node.d.ts +0 -207
  163. package/dist/web.d.ts +0 -169
  164. package/playground/index.html +0 -1328
  165. package/playground/sw.js +0 -55
  166. package/playground/tree.js +0 -176
@@ -1,4 +1,5 @@
1
- import { multiply, epsilon, decompose, round, toZero, identity } from './utils.js';
1
+ import { multiply, decompose, round, toZero, identity } from './utils.js';
2
+ import { epsilon } from '../../syntax/constants.js';
2
3
  import { EnumToken } from '../types.js';
3
4
  import { computeMatrix } from './compute.js';
4
5
  import { parseMatrix } from './matrix.js';
@@ -9,233 +10,237 @@ function minify(matrix) {
9
10
  if (decomposed == null) {
10
11
  return null;
11
12
  }
12
- const transforms = new Set(['translate', 'scale', 'skew', 'perspective', 'rotate']);
13
- const scales = new Set(['x', 'y', 'z']);
14
- const skew = new Set(['x', 'y']);
13
+ const transforms = new Set(["translate", "scale", "skew", "perspective", "rotate"]);
14
+ const scales = new Set(["x", "y", "z"]);
15
+ const skew = new Set(["x", "y"]);
15
16
  let result = [];
16
17
  // check identity
17
- if (round(decomposed.translate[0]) == 0 && round(decomposed.translate[1]) == 0 && round(decomposed.translate[2]) == 0) {
18
- transforms.delete('translate');
18
+ if (round(decomposed.translate[0]) == 0 &&
19
+ round(decomposed.translate[1]) == 0 &&
20
+ round(decomposed.translate[2]) == 0) {
21
+ transforms.delete("translate");
19
22
  }
20
23
  if (round(decomposed.scale[0]) == 1 && round(decomposed.scale[1]) == 1 && round(decomposed.scale[2]) == 1) {
21
- transforms.delete('scale');
24
+ transforms.delete("scale");
22
25
  }
23
26
  if (round(decomposed.skew[0]) == 0 && round(decomposed.skew[1]) == 0) {
24
- transforms.delete('skew');
27
+ transforms.delete("skew");
25
28
  }
26
29
  if (round(decomposed.perspective[2]) == 0) {
27
- transforms.delete('perspective');
30
+ transforms.delete("perspective");
28
31
  }
29
32
  if (round(decomposed.rotate[3]) == 0) {
30
- transforms.delete('rotate');
33
+ transforms.delete("rotate");
31
34
  }
32
- if (transforms.has('translate')) {
33
- let coordinates = new Set(['x', 'y', 'z']);
35
+ if (transforms.has("translate")) {
36
+ let coordinates = new Set(["x", "y", "z"]);
34
37
  for (let i = 0; i < 3; i++) {
35
38
  if (round(decomposed.translate[i]) == 0) {
36
- coordinates.delete(i == 0 ? 'x' : i == 1 ? 'y' : 'z');
39
+ coordinates.delete(i == 0 ? "x" : i == 1 ? "y" : "z");
37
40
  }
38
41
  }
39
42
  if (coordinates.size == 1) {
40
- if (coordinates.has('x')) {
43
+ if (coordinates.has("x")) {
41
44
  result.push({
42
45
  typ: EnumToken.TransformFunctionTokenType,
43
- val: 'translate',
44
- chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' }]
46
+ val: "translate",
47
+ chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: "px" }],
45
48
  });
46
49
  }
47
50
  else {
48
- let axis = coordinates.has('y') ? 'y' : 'z';
49
- let index = axis == 'y' ? 1 : 2;
51
+ let axis = coordinates.has("y") ? "y" : "z";
52
+ let index = axis == "y" ? 1 : 2;
50
53
  result.push({
51
54
  typ: EnumToken.TransformFunctionTokenType,
52
- val: 'translate' + axis.toUpperCase(),
53
- chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[index]), unit: 'px' }]
55
+ val: "translate" + axis.toUpperCase(),
56
+ chi: [{ typ: EnumToken.LengthTokenType, val: round(decomposed.translate[index]), unit: "px" }],
54
57
  });
55
58
  }
56
59
  }
57
- else if (coordinates.has('z')) {
60
+ else if (coordinates.has("z")) {
58
61
  result.push({
59
62
  typ: EnumToken.TransformFunctionTokenType,
60
- val: 'translate3d',
63
+ val: "translate3d",
61
64
  chi: [
62
- decomposed.translate[0] == 0 ? {
63
- typ: EnumToken.NumberTokenType,
64
- val: 0
65
- } : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' },
65
+ decomposed.translate[0] == 0
66
+ ? {
67
+ typ: EnumToken.NumberTokenType,
68
+ val: 0,
69
+ }
70
+ : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: "px" },
66
71
  { typ: EnumToken.CommaTokenType },
67
- decomposed.translate[1] == 0 ? {
68
- typ: EnumToken.NumberTokenType,
69
- val: 0
70
- } : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: 'px' },
72
+ decomposed.translate[1] == 0
73
+ ? {
74
+ typ: EnumToken.NumberTokenType,
75
+ val: 0,
76
+ }
77
+ : { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: "px" },
71
78
  { typ: EnumToken.CommaTokenType },
72
- { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[2]), unit: 'px' }
73
- ]
79
+ { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[2]), unit: "px" },
80
+ ],
74
81
  });
75
82
  }
76
83
  else {
77
84
  result.push({
78
85
  typ: EnumToken.TransformFunctionTokenType,
79
- val: 'translate',
86
+ val: "translate",
80
87
  chi: [
81
- { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' },
88
+ { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: "px" },
82
89
  { typ: EnumToken.CommaTokenType },
83
- { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: 'px' }
84
- ]
90
+ { typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: "px" },
91
+ ],
85
92
  });
86
93
  }
87
94
  }
88
- if (transforms.has('rotate')) {
95
+ if (transforms.has("rotate")) {
89
96
  const [x, y, z, angle] = decomposed.rotate;
90
97
  if (y == 0 && z == 0) {
91
98
  result.push({
92
99
  typ: EnumToken.TransformFunctionTokenType,
93
- val: 'rotateX',
100
+ val: "rotateX",
94
101
  chi: [
95
102
  {
96
103
  typ: EnumToken.AngleTokenType,
97
104
  val: round(angle),
98
- unit: 'deg'
99
- }
100
- ]
105
+ unit: "deg",
106
+ },
107
+ ],
101
108
  });
102
109
  }
103
110
  else if (x == 0 && z == 0) {
104
111
  result.push({
105
112
  typ: EnumToken.TransformFunctionTokenType,
106
- val: 'rotateY',
113
+ val: "rotateY",
107
114
  chi: [
108
115
  {
109
116
  typ: EnumToken.AngleTokenType,
110
117
  val: round(angle),
111
- unit: 'deg'
112
- }
113
- ]
118
+ unit: "deg",
119
+ },
120
+ ],
114
121
  });
115
122
  }
116
123
  else if (x == 0 && y == 0) {
117
124
  result.push({
118
125
  typ: EnumToken.TransformFunctionTokenType,
119
- val: 'rotate',
126
+ val: "rotate",
120
127
  chi: [
121
128
  {
122
129
  typ: EnumToken.AngleTokenType,
123
130
  val: round(angle),
124
- unit: 'deg'
125
- }
126
- ]
131
+ unit: "deg",
132
+ },
133
+ ],
127
134
  });
128
135
  }
129
136
  else {
130
137
  result.push({
131
138
  typ: EnumToken.TransformFunctionTokenType,
132
- val: 'rotate3d',
139
+ val: "rotate3d",
133
140
  chi: [
134
141
  {
135
142
  typ: EnumToken.NumberTokenType,
136
- val: round(x)
143
+ val: round(x),
137
144
  },
138
145
  { typ: EnumToken.CommaTokenType },
139
146
  {
140
147
  typ: EnumToken.NumberTokenType,
141
- val: round(y)
148
+ val: round(y),
142
149
  },
143
150
  { typ: EnumToken.CommaTokenType },
144
151
  {
145
152
  typ: EnumToken.NumberTokenType,
146
- val: round(z)
153
+ val: round(z),
147
154
  },
148
155
  { typ: EnumToken.CommaTokenType },
149
156
  {
150
157
  typ: EnumToken.AngleTokenType,
151
158
  val: round(angle),
152
- unit: 'deg'
153
- }
154
- ]
159
+ unit: "deg",
160
+ },
161
+ ],
155
162
  });
156
163
  }
157
164
  }
158
- if (transforms.has('skew')) {
165
+ if (transforms.has("skew")) {
159
166
  if (round(decomposed.skew[1]) == 0) {
160
- skew.delete('y');
167
+ skew.delete("y");
161
168
  }
162
169
  for (let i = 0; i < 2; i++) {
163
- decomposed.skew[i] = round(Math.atan(decomposed.skew[i]) * 180 / Math.PI);
170
+ decomposed.skew[i] = round((Math.atan(decomposed.skew[i]) * 180) / Math.PI);
164
171
  }
165
172
  if (skew.size == 1) {
166
173
  result.push({
167
174
  typ: EnumToken.TransformFunctionTokenType,
168
- val: 'skew' + (skew.has('x') ? '' : 'Y'),
169
- chi: [
170
- { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' }
171
- ]
175
+ val: "skew" + (skew.has("x") ? "" : "Y"),
176
+ chi: [{ typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: "deg" }],
172
177
  });
173
178
  }
174
179
  else {
175
180
  result.push({
176
181
  typ: EnumToken.TransformFunctionTokenType,
177
- val: 'skew',
182
+ val: "skew",
178
183
  chi: [
179
- { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' },
184
+ { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: "deg" },
180
185
  { typ: EnumToken.CommaTokenType },
181
- { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[1]), unit: 'deg' }
182
- ]
186
+ { typ: EnumToken.AngleTokenType, val: round(decomposed.skew[1]), unit: "deg" },
187
+ ],
183
188
  });
184
189
  }
185
190
  }
186
- if (transforms.has('scale')) {
191
+ if (transforms.has("scale")) {
187
192
  const [sx, sy, sz] = toZero(decomposed.scale);
188
193
  if (sz == 1) {
189
- scales.delete('z');
194
+ scales.delete("z");
190
195
  }
191
196
  if (sy == 1) {
192
- scales.delete('y');
197
+ scales.delete("y");
193
198
  }
194
199
  if (sx == 1) {
195
- scales.delete('x');
200
+ scales.delete("x");
196
201
  }
197
202
  if (scales.size == 1) {
198
- let prefix = scales.has('x') ? 'X' : scales.has('y') ? 'Y' : 'Z';
203
+ let prefix = scales.has("x") ? "X" : scales.has("y") ? "Y" : "Z";
199
204
  result.push({
200
205
  typ: EnumToken.TransformFunctionTokenType,
201
- val: 'scale' + prefix,
202
- chi: [
203
- { typ: EnumToken.NumberTokenType, val: round(prefix == 'Z' ? sz : prefix == 'Y' ? sy : sx) }
204
- ]
206
+ val: "scale" + prefix,
207
+ chi: [{ typ: EnumToken.NumberTokenType, val: round(prefix == "Z" ? sz : prefix == "Y" ? sy : sx) }],
205
208
  });
206
209
  }
207
- else if (!scales.has('z')) {
210
+ else if (!scales.has("z")) {
208
211
  result.push({
209
212
  typ: EnumToken.TransformFunctionTokenType,
210
- val: 'scale',
213
+ val: "scale",
211
214
  chi: [
212
215
  { typ: EnumToken.NumberTokenType, val: round(sx) },
213
216
  { typ: EnumToken.CommaTokenType },
214
217
  { typ: EnumToken.NumberTokenType, val: round(sy) },
215
- ]
218
+ ],
216
219
  });
217
220
  }
218
221
  else {
219
222
  result.push({
220
223
  typ: EnumToken.TransformFunctionTokenType,
221
- val: 'scale3d',
224
+ val: "scale3d",
222
225
  chi: [
223
226
  { typ: EnumToken.NumberTokenType, val: round(sx) },
224
227
  { typ: EnumToken.CommaTokenType },
225
228
  { typ: EnumToken.NumberTokenType, val: round(sy) },
226
229
  { typ: EnumToken.CommaTokenType },
227
- { typ: EnumToken.NumberTokenType, val: round(sz) }
228
- ]
230
+ { typ: EnumToken.NumberTokenType, val: round(sz) },
231
+ ],
229
232
  });
230
233
  }
231
234
  }
232
235
  // identity
233
- return result.length == 0 || (result.length == 1 && eqMatrix(identity(), result)) ? [
234
- {
235
- typ: EnumToken.IdenTokenType,
236
- val: 'none'
237
- }
238
- ] : result;
236
+ return result.length == 0 || (result.length == 1 && eqMatrix(identity(), result))
237
+ ? [
238
+ {
239
+ typ: EnumToken.IdenTokenType,
240
+ val: "none",
241
+ },
242
+ ]
243
+ : result;
239
244
  }
240
245
  function eqMatrix(a, b) {
241
246
  let mat = identity();
@@ -262,102 +267,101 @@ function eqMatrix(a, b) {
262
267
  }
263
268
  function minifyTransformFunctions(transform) {
264
269
  const name = transform.val.toLowerCase();
265
- if ('skewx' == name) {
266
- transform.val = 'skew';
270
+ if ("skewx" == name) {
271
+ transform.val = "skew";
267
272
  return transform;
268
273
  }
269
- if (!['translate', 'translate3d', 'scale', 'scale3d'].includes(name)) {
274
+ if (!["translate", "translate3d", "scale", "scale3d"].includes(name)) {
270
275
  return transform;
271
276
  }
272
277
  const values = [];
273
278
  for (const token of transform.chi) {
274
- if (token.typ == EnumToken.CommentTokenType || token.typ == EnumToken.WhitespaceTokenType || token.typ == EnumToken.CommaTokenType) {
279
+ if (token.typ == EnumToken.CommentTokenType ||
280
+ token.typ == EnumToken.WhitespaceTokenType ||
281
+ token.typ == EnumToken.CommaTokenType) {
275
282
  continue;
276
283
  }
277
- if (![EnumToken.NumberTokenType, EnumToken.LengthTokenType, EnumToken.AngleTokenType, EnumToken.PercentageTokenType].includes(token.typ)) {
284
+ if (![
285
+ EnumToken.NumberTokenType,
286
+ EnumToken.LengthTokenType,
287
+ EnumToken.AngleTokenType,
288
+ EnumToken.PercentageTokenType,
289
+ ].includes(token.typ)) {
278
290
  return transform;
279
291
  }
280
- if (token.typ == EnumToken.PercentageTokenType && typeof token.val == 'number' && name.startsWith('scale')) {
281
- Object.assign(token, { typ: EnumToken.NumberTokenType, val: token.val / 100 });
292
+ if (token.typ == EnumToken.PercentageTokenType &&
293
+ typeof token.val == "number" &&
294
+ name.startsWith("scale")) {
295
+ Object.assign(token, {
296
+ typ: EnumToken.NumberTokenType,
297
+ val: token.val / 100,
298
+ });
282
299
  }
283
300
  values.push(token);
284
301
  }
285
- if ((name == 'translate' || name == 'scale') && values.length > 2) {
302
+ if (values.length == 0) {
286
303
  return transform;
287
304
  }
288
- const ignoredValue = name.startsWith('scale') ? 1 : 0;
289
- const t = new Set(['x', 'y', 'z']);
305
+ if ((name == "translate" || name == "scale") && values.length > 2) {
306
+ return transform;
307
+ }
308
+ const ignoredValue = name.startsWith("scale") ? 1 : 0;
309
+ const t = new Set(["x", "y", "z"]);
290
310
  let i = 3;
291
311
  while (i--) {
292
312
  if (values.length <= i || values[i].val == ignoredValue) {
293
- t.delete(i == 0 ? 'x' : i == 1 ? 'y' : 'z');
313
+ t.delete(i == 0 ? "x" : i == 1 ? "y" : "z");
294
314
  }
295
315
  }
296
- if (name == 'translate3d' || name == 'translate') {
316
+ if (name == "translate3d" || name == "translate") {
297
317
  if (t.size == 0) {
298
318
  return {
299
319
  typ: EnumToken.TransformFunctionTokenType,
300
- val: 'translate',
301
- chi: [
302
- { typ: EnumToken.NumberTokenType, val: 0 }
303
- ]
320
+ val: "translate",
321
+ chi: [{ typ: EnumToken.NumberTokenType, val: 0 }],
304
322
  };
305
323
  }
306
324
  if (t.size == 1) {
307
325
  return {
308
326
  typ: EnumToken.TransformFunctionTokenType,
309
- val: 'translate' + (t.has('x') ? '' : t.has('y') ? 'Y' : 'Z'),
310
- chi: [
311
- values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
312
- ]
327
+ val: "translate" + (t.has("x") ? "" : t.has("y") ? "Y" : "Z"),
328
+ chi: [values[t.has("x") ? 0 : t.has("y") ? 1 : 2]],
313
329
  };
314
330
  }
315
331
  if (t.size == 2) {
316
- if (t.has('z')) {
332
+ if (t.has("z")) {
317
333
  return transform;
318
334
  }
319
335
  return {
320
336
  typ: EnumToken.TransformFunctionTokenType,
321
- val: 'translate',
322
- chi: [
323
- values[0],
324
- { typ: EnumToken.CommaTokenType },
325
- values[1]
326
- ]
337
+ val: "translate",
338
+ chi: [values[0], { typ: EnumToken.CommaTokenType }, values[1]],
327
339
  };
328
340
  }
329
341
  }
330
- if (name == 'scale3d' || name == 'scale') {
342
+ if (name == "scale3d" || name == "scale") {
331
343
  if (t.size == 0) {
332
344
  return {
333
345
  typ: EnumToken.TransformFunctionTokenType,
334
- val: 'scale',
335
- chi: [
336
- { typ: EnumToken.NumberTokenType, val: 1 }
337
- ]
346
+ val: "scale",
347
+ chi: [{ typ: EnumToken.NumberTokenType, val: 1 }],
338
348
  };
339
349
  }
340
350
  if (t.size == 1) {
341
351
  return {
342
352
  typ: EnumToken.TransformFunctionTokenType,
343
- val: 'scale' + (t.has('x') ? 'X' : t.has('y') ? 'Y' : 'Z'),
344
- chi: [
345
- values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
346
- ]
353
+ val: "scale" + (t.has("x") ? "X" : t.has("y") ? "Y" : "Z"),
354
+ chi: [values[t.has("x") ? 0 : t.has("y") ? 1 : 2]],
347
355
  };
348
356
  }
349
357
  if (t.size == 2) {
350
- if (t.has('z')) {
358
+ if (t.has("z")) {
351
359
  return transform;
352
360
  }
353
361
  return {
354
362
  typ: EnumToken.TransformFunctionTokenType,
355
- val: 'scale',
356
- chi: [
357
- values[0],
358
- { typ: EnumToken.CommaTokenType },
359
- values[1]
360
- ]
363
+ val: "scale",
364
+ chi: [values[0], { typ: EnumToken.CommaTokenType }, values[1]],
361
365
  };
362
366
  }
363
367
  }
@@ -1,4 +1,5 @@
1
- const epsilon = 1e-5;
1
+ import { epsilon } from '../../syntax/constants.js';
2
+
2
3
  function identity() {
3
4
  return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
4
5
  }
@@ -240,4 +241,4 @@ function is2DMatrix(matrix) {
240
241
  matrix[15] === 1;
241
242
  }
242
243
 
243
- export { decompose, epsilon, identity, is2DMatrix, multiply, round, toZero };
244
+ export { decompose, identity, is2DMatrix, multiply, round, toZero };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * syntax validation enum
2
+ * Syntax validation enum
3
3
  */
4
4
  var SyntaxValidationResult;
5
5
  (function (SyntaxValidationResult) {
@@ -11,7 +11,46 @@ var SyntaxValidationResult;
11
11
  SyntaxValidationResult[SyntaxValidationResult["Lenient"] = 2] = "Lenient";
12
12
  })(SyntaxValidationResult || (SyntaxValidationResult = {}));
13
13
  /**
14
- * enum of validation levels
14
+ * Enum of node statuses
15
+ */
16
+ var EnumAstNodeStatus;
17
+ (function (EnumAstNodeStatus) {
18
+ /**
19
+ * Node passed validation
20
+ */
21
+ EnumAstNodeStatus[EnumAstNodeStatus["Validated"] = 0] = "Validated";
22
+ /**
23
+ * Node is invalid
24
+ */
25
+ EnumAstNodeStatus[EnumAstNodeStatus["Invalid"] = 1] = "Invalid";
26
+ /**
27
+ * node is not validated
28
+ */
29
+ EnumAstNodeStatus[EnumAstNodeStatus["Unvalidated"] = 2] = "Unvalidated";
30
+ /**
31
+ * Node did not pass validation, but is preserved.
32
+ */
33
+ EnumAstNodeStatus[EnumAstNodeStatus["ValidationFailed"] = 3] = "ValidationFailed";
34
+ /**
35
+ * Parsing the node is not supported yet or the node syntax definition does not exist.
36
+ */
37
+ EnumAstNodeStatus[EnumAstNodeStatus["Unknown"] = 4] = "Unknown";
38
+ /**
39
+ * Failed to parse the node.
40
+ */
41
+ EnumAstNodeStatus[EnumAstNodeStatus["Unparsed"] = 5] = "Unparsed";
42
+ /**
43
+ * Node is disallowed in the context
44
+ */
45
+ EnumAstNodeStatus[EnumAstNodeStatus["Disallowed"] = 6] = "Disallowed";
46
+ /**
47
+ * Node is malformed
48
+ */
49
+ EnumAstNodeStatus[EnumAstNodeStatus["Malformed"] = 7] = "Malformed";
50
+ })(EnumAstNodeStatus || (EnumAstNodeStatus = {}));
51
+ /**
52
+ * Enum of validation levels
53
+ * @deprecated
15
54
  */
16
55
  var ValidationLevel;
17
56
  (function (ValidationLevel) {
@@ -39,9 +78,13 @@ var ValidationLevel;
39
78
  * validate selectors, at-rules and declarations
40
79
  */
41
80
  ValidationLevel[ValidationLevel["All"] = 7] = "All";
81
+ /**
82
+ * Report only. Apply validation and report nodes that are marked as invalid
83
+ */
84
+ ValidationLevel[ValidationLevel["ReportOnly"] = 8] = "ReportOnly";
42
85
  })(ValidationLevel || (ValidationLevel = {}));
43
86
  /**
44
- * enum of all token types
87
+ * Enum of all token types
45
88
  */
46
89
  var EnumToken;
47
90
  (function (EnumToken) {
@@ -372,7 +415,8 @@ var EnumToken;
372
415
  */
373
416
  EnumToken[EnumToken["NestingSelectorTokenType"] = 80] = "NestingSelectorTokenType";
374
417
  /**
375
- * invalid rule token type
418
+ * Invalid rule token type
419
+ * @deprecated
376
420
  */
377
421
  EnumToken[EnumToken["InvalidRuleNodeType"] = 81] = "InvalidRuleNodeType";
378
422
  /**
@@ -384,7 +428,8 @@ var EnumToken;
384
428
  */
385
429
  EnumToken[EnumToken["InvalidAttrTokenType"] = 83] = "InvalidAttrTokenType";
386
430
  /**
387
- * invalid at rule token type
431
+ * Invalid at rule token type
432
+ * @deprecated
388
433
  */
389
434
  EnumToken[EnumToken["InvalidAtRuleNodeType"] = 84] = "InvalidAtRuleNodeType";
390
435
  /**
@@ -424,7 +469,8 @@ var EnumToken;
424
469
  */
425
470
  EnumToken[EnumToken["KeyframesAtRuleNodeType"] = 93] = "KeyframesAtRuleNodeType";
426
471
  /**
427
- * invalid declaration node type
472
+ * invalid declaration node type.
473
+ * @deprecated
428
474
  */
429
475
  EnumToken[EnumToken["InvalidDeclarationNodeType"] = 94] = "InvalidDeclarationNodeType";
430
476
  /* css module nodes */
@@ -721,7 +767,7 @@ var EnumToken;
721
767
  EnumToken[EnumToken["TimelineFunction"] = 16] = "TimelineFunction";
722
768
  })(EnumToken || (EnumToken = {}));
723
769
  /**
724
- * supported color types enum
770
+ * Supported color types enum
725
771
  */
726
772
  var ColorType;
727
773
  (function (ColorType) {
@@ -825,6 +871,10 @@ var ColorType;
825
871
  * custom color
826
872
  */
827
873
  ColorType[ColorType["CUSTOM_COLOR"] = 24] = "CUSTOM_COLOR";
874
+ /**
875
+ * alpha() color function
876
+ */
877
+ ColorType[ColorType["ALPHA"] = 25] = "ALPHA";
828
878
  /**
829
879
  * alias for rgba
830
880
  */
@@ -842,6 +892,9 @@ var ColorType;
842
892
  */
843
893
  ColorType[ColorType["DEVICE_CMYK"] = 7] = "DEVICE_CMYK";
844
894
  })(ColorType || (ColorType = {}));
895
+ /**
896
+ * Supported module case transform
897
+ */
845
898
  var ModuleCaseTransformEnum;
846
899
  (function (ModuleCaseTransformEnum) {
847
900
  /**
@@ -865,6 +918,9 @@ var ModuleCaseTransformEnum;
865
918
  */
866
919
  ModuleCaseTransformEnum[ModuleCaseTransformEnum["DashCaseOnly"] = 16] = "DashCaseOnly";
867
920
  })(ModuleCaseTransformEnum || (ModuleCaseTransformEnum = {}));
921
+ /**
922
+ * Supported module scope
923
+ */
868
924
  var ModuleScopeEnumOptions;
869
925
  (function (ModuleScopeEnumOptions) {
870
926
  /**
@@ -905,6 +961,11 @@ var ModuleScopeEnumOptions;
905
961
  ModuleScopeEnumOptions[ModuleScopeEnumOptions["Shortest"] = 512] = "Shortest";
906
962
  })(ModuleScopeEnumOptions || (ModuleScopeEnumOptions = {}));
907
963
  // https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
964
+ /**
965
+ * Convert length to px
966
+ * @param value
967
+ * @returns
968
+ */
908
969
  function length2Px(value) {
909
970
  let result = null;
910
971
  if (value.typ == EnumToken.NumberTokenType) {
@@ -965,4 +1026,4 @@ function minifyNumber(val) {
965
1026
  return val;
966
1027
  }
967
1028
 
968
- export { ColorType, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, SyntaxValidationResult, ValidationLevel, length2Px, minifyNumber };
1029
+ export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, SyntaxValidationResult, ValidationLevel, length2Px, minifyNumber };