@tbela99/css-parser 1.4.8 → 1.4.10

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 (56) hide show
  1. package/CHANGELOG.md +32 -3
  2. package/README.md +1 -1
  3. package/dist/index-umd-web.js +12950 -13310
  4. package/dist/index.cjs +16447 -16809
  5. package/dist/index.d.ts +2481 -1754
  6. package/dist/lib/ast/features/calc.js +3 -1
  7. package/dist/lib/ast/features/if.js +2 -96
  8. package/dist/lib/ast/features/prefix.js +7 -2
  9. package/dist/lib/ast/features/shorthand.js +1 -1
  10. package/dist/lib/ast/features/transform.js +1 -1
  11. package/dist/lib/ast/find.js +6 -6
  12. package/dist/lib/ast/math/expression.js +30 -12
  13. package/dist/lib/ast/math/math.js +2 -1
  14. package/dist/lib/ast/minify.js +34 -5
  15. package/dist/lib/ast/transform/compute.js +2 -1
  16. package/dist/lib/ast/transform/perspective.js +1 -1
  17. package/dist/lib/ast/transform/utils.js +29 -21
  18. package/dist/lib/ast/types.js +9 -66
  19. package/dist/lib/fs/resolve.js +1 -16
  20. package/dist/lib/parser/declaration/list.js +6 -1
  21. package/dist/lib/parser/{linemap.js → linesmap.js} +25 -9
  22. package/dist/lib/parser/parse.js +1264 -151
  23. package/dist/lib/parser/source.js +48 -17
  24. package/dist/lib/parser/tokenize.js +112 -133
  25. package/dist/lib/parser/utils/at-rule-container.js +12 -44
  26. package/dist/lib/parser/utils/at-rule-generic.js +12 -24
  27. package/dist/lib/parser/utils/at-rule-import.js +4 -172
  28. package/dist/lib/parser/utils/at-rule-media.js +14 -251
  29. package/dist/lib/parser/utils/at-rule-support.js +8 -258
  30. package/dist/lib/parser/utils/at-rule-when-else.js +4 -214
  31. package/dist/lib/parser/utils/declaration.js +5 -95
  32. package/dist/lib/parser/utils/hash.js +54 -1
  33. package/dist/lib/parser/utils/selector.js +1 -1
  34. package/dist/lib/parser/utils/token.js +1 -0
  35. package/dist/lib/renderer/render.js +79 -87
  36. package/dist/lib/renderer/sourcemap/sourcemap.js +47 -43
  37. package/dist/lib/syntax/color/cmyk.js +3 -3
  38. package/dist/lib/syntax/color/color-mix.js +7 -7
  39. package/dist/lib/syntax/color/color.js +9 -27
  40. package/dist/lib/syntax/color/hsl.js +6 -6
  41. package/dist/lib/syntax/color/hwb.js +6 -6
  42. package/dist/lib/syntax/color/lab.js +5 -5
  43. package/dist/lib/syntax/color/lch.js +6 -6
  44. package/dist/lib/syntax/color/oklab.js +5 -5
  45. package/dist/lib/syntax/color/oklch.js +5 -5
  46. package/dist/lib/syntax/color/relative-color.js +8 -1
  47. package/dist/lib/syntax/color/utils/distance.js +2 -1
  48. package/dist/lib/syntax/constants.js +2 -1
  49. package/dist/lib/syntax/syntax.js +96 -9
  50. package/dist/lib/validation/config.json.js +27 -6
  51. package/dist/lib/validation/match.js +42 -845
  52. package/dist/node.js +134 -9
  53. package/dist/web.js +133 -6
  54. package/llms.txt +73 -0
  55. package/package.json +13 -16
  56. package/dist/lib/parser/arena.js +0 -206
@@ -31,13 +31,25 @@ function inverse(matrix) {
31
31
  // Create augmented matrix [matrix | identity]
32
32
  let augmented = [
33
33
  ...matrix.slice(0, 4),
34
- 1, 0, 0, 0,
34
+ 1,
35
+ 0,
36
+ 0,
37
+ 0,
35
38
  ...matrix.slice(4, 8),
36
- 0, 1, 0, 0,
39
+ 0,
40
+ 1,
41
+ 0,
42
+ 0,
37
43
  ...matrix.slice(8, 12),
38
- 0, 0, 1, 0,
44
+ 0,
45
+ 0,
46
+ 1,
47
+ 0,
39
48
  ...matrix.slice(12, 16),
40
- 0, 0, 0, 1
49
+ 0,
50
+ 0,
51
+ 0,
52
+ 1,
41
53
  ];
42
54
  // Gaussian elimination with partial pivoting
43
55
  for (let col = 0; col < 4; col++) {
@@ -52,7 +64,7 @@ function inverse(matrix) {
52
64
  }
53
65
  }
54
66
  // Check for singularity
55
- if (maxVal < 1e-5) {
67
+ if (maxVal < epsilon) {
56
68
  return null;
57
69
  }
58
70
  // Swap rows if necessary
@@ -132,11 +144,7 @@ function decompose(original) {
132
144
  const scaleX = Math.hypot(...row0);
133
145
  const row0Norm = normalize(row0);
134
146
  const skewXY = dot(row0Norm, row1);
135
- const row1Proj = [
136
- row1[0] - skewXY * row0Norm[0],
137
- row1[1] - skewXY * row0Norm[1],
138
- row1[2] - skewXY * row0Norm[2]
139
- ];
147
+ const row1Proj = [row1[0] - skewXY * row0Norm[0], row1[1] - skewXY * row0Norm[1], row1[2] - skewXY * row0Norm[2]];
140
148
  const scaleY = Math.hypot(...row1Proj);
141
149
  const row1Norm = normalize(row1Proj);
142
150
  const skewXZ = dot(row0Norm, row2);
@@ -144,7 +152,7 @@ function decompose(original) {
144
152
  const row2Proj = [
145
153
  row2[0] - skewXZ * row0Norm[0] - skewYZ * row1Norm[0],
146
154
  row2[1] - skewXZ * row0Norm[1] - skewYZ * row1Norm[1],
147
- row2[2] - skewXZ * row0Norm[2] - skewYZ * row1Norm[2]
155
+ row2[2] - skewXZ * row0Norm[2] - skewYZ * row1Norm[2],
148
156
  ];
149
157
  const row2Norm = normalize(row2Proj);
150
158
  const determinant = row0[0] * cross[0] + row0[1] * cross[1] + row0[2] * cross[2];
@@ -196,7 +204,12 @@ function decompose(original) {
196
204
  qy /= q;
197
205
  qz /= q;
198
206
  }
199
- const rotate = [qx, qy, qz, Object.is(qw, 0) ? 0 : 2 * Math.acos(qw) * 180 / Math.PI];
207
+ const rotate = [
208
+ qx,
209
+ qy,
210
+ qz,
211
+ Object.is(qw, 0) ? 0 : (2 * Math.acos(qw) * 180) / Math.PI,
212
+ ];
200
213
  const scale = [scaleX, scaleY, scaleZ];
201
214
  const skew = [skewXY, skewXZ, skewYZ];
202
215
  return {
@@ -204,16 +217,11 @@ function decompose(original) {
204
217
  scale,
205
218
  rotate,
206
219
  skew,
207
- perspective
220
+ perspective,
208
221
  };
209
222
  }
210
223
  function transposeMatrix4(m) {
211
- return [
212
- m[0], m[4], m[8], m[12],
213
- m[1], m[5], m[9], m[13],
214
- m[2], m[6], m[10], m[14],
215
- m[3], m[7], m[11], m[15],
216
- ];
224
+ return [m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[13], m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]];
217
225
  }
218
226
  function toZero(v) {
219
227
  for (let i = 0; i < v.length; i++) {
@@ -229,7 +237,7 @@ function toZero(v) {
229
237
  // https://drafts.csswg.org/css-transforms-1/#2d-matrix
230
238
  function is2DMatrix(matrix) {
231
239
  // m13,m14, m23, m24, m31, m32, m34, m43 are all 0
232
- return matrix[2] === 0 &&
240
+ return (matrix[2] === 0 &&
233
241
  matrix[3] === 0 &&
234
242
  matrix[6] === 0 &&
235
243
  matrix[7] === 0 &&
@@ -238,7 +246,7 @@ function is2DMatrix(matrix) {
238
246
  matrix[11] === 0 &&
239
247
  matrix[14] === 0 &&
240
248
  matrix[10] === 1 &&
241
- matrix[15] === 1;
249
+ matrix[15] === 1);
242
250
  }
243
251
 
244
252
  export { decompose, identity, is2DMatrix, multiply, round, toZero };
@@ -883,6 +883,14 @@ var ColorType;
883
883
  * color using display-p3-linear
884
884
  */
885
885
  ColorType[ColorType["DISPLAY_P3_LINEAR"] = 26] = "DISPLAY_P3_LINEAR";
886
+ /**
887
+ * Contrast color
888
+ */
889
+ ColorType[ColorType["CONTRAST_COLOR"] = 27] = "CONTRAST_COLOR";
890
+ /**
891
+ * color layers
892
+ */
893
+ ColorType[ColorType["COLOR_LAYERS"] = 28] = "COLOR_LAYERS";
886
894
  /**
887
895
  * alias for rgba
888
896
  */
@@ -968,70 +976,5 @@ var ModuleScopeEnumOptions;
968
976
  */
969
977
  ModuleScopeEnumOptions[ModuleScopeEnumOptions["Shortest"] = 512] = "Shortest";
970
978
  })(ModuleScopeEnumOptions || (ModuleScopeEnumOptions = {}));
971
- // https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
972
- /**
973
- * Convert length to px
974
- * @param value
975
- * @returns
976
- */
977
- function length2Px(value) {
978
- let result = null;
979
- if (value.typ == EnumToken.NumberTokenType) {
980
- result = +value.val;
981
- }
982
- else {
983
- switch (value.unit) {
984
- case "cm":
985
- // @ts-ignore
986
- result = value.val * 37.8;
987
- break;
988
- case "mm":
989
- // @ts-ignore
990
- result = value.val * 3.78;
991
- break;
992
- case "Q":
993
- // @ts-ignore
994
- result = (value.val * 37.8) / 40;
995
- break;
996
- case "in":
997
- // @ts-ignore
998
- result = value.val / 96;
999
- break;
1000
- case "pc":
1001
- // @ts-ignore
1002
- result = value.val / 16;
1003
- break;
1004
- case "pt":
1005
- // @ts-ignore
1006
- result = (value.val * 4) / 3;
1007
- break;
1008
- case "px":
1009
- result = +value.val;
1010
- break;
1011
- }
1012
- }
1013
- return isNaN(result) ? null : result;
1014
- }
1015
- /**
1016
- * minify number
1017
- * @param val
1018
- */
1019
- function minifyNumber(val) {
1020
- val = String(val);
1021
- if (val === "0") {
1022
- return "0";
1023
- }
1024
- const chr = val.charAt(0);
1025
- if (chr == "-") {
1026
- const slice = val.slice(0, 2);
1027
- if (slice == "-0") {
1028
- return val.length == 2 ? "0" : "-" + val.slice(2);
1029
- }
1030
- }
1031
- if (chr == "0") {
1032
- return val.slice(1);
1033
- }
1034
- return val;
1035
- }
1036
979
 
1037
- export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, SyntaxValidationResult, ValidationLevel, length2Px, minifyNumber };
980
+ export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, SyntaxValidationResult, ValidationLevel };
@@ -151,24 +151,9 @@ const resolve = memoize(function (url, currentDirectory, cwd) {
151
151
  };
152
152
  }
153
153
  }
154
- // if (matchUrl.test(currentDirectory)) {
155
- // const path: string = new URL(url, currentDirectory).href;
156
- // return {
157
- // absolute: path,
158
- // relative: path,
159
- // };
160
- // }
161
- // let result: string = "";
162
- // if (url.charAt(0) == "/") {
163
- // result = url;
164
- // }
165
- // else if (currentDirectory.charAt(0) == "/") {
166
- // result = dirname(currentDirectory) + "/" + url;
167
- // }
168
- // const absolute = url; // normalize(result);
169
154
  return {
170
155
  absolute: url,
171
- relative: url === "" ? "" : diff(url, cwd ?? currentDirectory),
156
+ relative: url === "" ? "" : diff(url, cwd || currentDirectory),
172
157
  };
173
158
  });
174
159
 
@@ -7,6 +7,7 @@ import { getParsedSyntax } from '../../validation/config.js';
7
7
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
8
8
  import { matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
9
9
  import { STATE } from '../../syntax/constants.js';
10
+ import { objectHash } from '../utils/hash.js';
10
11
 
11
12
  const config = getConfig();
12
13
  class PropertyList {
@@ -42,7 +43,11 @@ class PropertyList {
42
43
  (Array.isArray(this.options.removeDuplicateDeclarations)
43
44
  ? this.options.removeDuplicateDeclarations.includes(declaration.nam)
44
45
  : !this.options.removeDuplicateDeclarations)) {
45
- this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
46
+ const key = objectHash(declaration);
47
+ if (this.declarations.has(key)) {
48
+ this.declarations.delete(key);
49
+ }
50
+ this.declarations.set(key, declaration);
46
51
  continue;
47
52
  }
48
53
  if (!this.options.computeShorthand) {
@@ -6,7 +6,14 @@ class LineMap {
6
6
  * line starts
7
7
  */
8
8
  lineStarts;
9
+ /**
10
+ * Constructor
11
+ * @param lines
12
+ */
9
13
  constructor(lines) {
14
+ if (lines.length === 0) {
15
+ lines.push(0);
16
+ }
10
17
  this.lineStarts = lines;
11
18
  }
12
19
  /**
@@ -14,11 +21,14 @@ class LineMap {
14
21
  * @param offset
15
22
  * @returns
16
23
  */
17
- position(offset) {
24
+ getOffsets(offset) {
18
25
  const line = this.search(offset);
26
+ if (offset < 0 || line < 0) {
27
+ return [1, 1];
28
+ }
19
29
  const column = offset - this.lineStarts[line];
20
30
  // [line, column]
21
- return [line + 1, column == 0 ? 1 : column];
31
+ return [line + 1, column === 0 ? 1 : column];
22
32
  }
23
33
  /**
24
34
  * search the greatest index of the value less than or equal to offset
@@ -43,13 +53,6 @@ class LineMap {
43
53
  }
44
54
  return result;
45
55
  }
46
- /**
47
- * set line starts
48
- * @param lines
49
- */
50
- setLineStarts(lines) {
51
- this.lineStarts = lines;
52
- }
53
56
  /**
54
57
  * get line starts
55
58
  * @returns
@@ -57,6 +60,19 @@ class LineMap {
57
60
  getLineStarts() {
58
61
  return this.lineStarts;
59
62
  }
63
+ /**
64
+ * add line start
65
+ */
66
+ addLineStart(lineStart) {
67
+ this.lineStarts.push(lineStart);
68
+ }
69
+ /**
70
+ * clone the linemap
71
+ * @returns
72
+ */
73
+ clone() {
74
+ return new LineMap(this.lineStarts.slice());
75
+ }
60
76
  }
61
77
 
62
78
  export { LineMap };