@tbela99/css-parser 1.5.0 → 1.6.1

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 (78) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +10 -10
  3. package/dist/index-umd-web.js +5998 -4972
  4. package/dist/index.cjs +6001 -4977
  5. package/dist/index.d.ts +52 -38
  6. package/dist/lib/ast/expand.js +21 -7
  7. package/dist/lib/ast/features/calc.js +17 -55
  8. package/dist/lib/ast/features/if.js +7 -3
  9. package/dist/lib/ast/features/inlinecssvariables.js +6 -5
  10. package/dist/lib/ast/features/prefix.js +41 -44
  11. package/dist/lib/ast/features/shorthand.js +10 -5
  12. package/dist/lib/ast/features/transform.js +2 -2
  13. package/dist/lib/ast/math/expression.js +207 -34
  14. package/dist/lib/ast/minify.js +121 -24
  15. package/dist/lib/ast/node.js +5 -3
  16. package/dist/lib/ast/transform/compute.js +37 -5
  17. package/dist/lib/ast/transform/minify.js +7 -7
  18. package/dist/lib/ast/transform/perspective.js +1 -1
  19. package/dist/lib/ast/transform/rotate.js +1 -1
  20. package/dist/lib/ast/transform/scale.js +1 -1
  21. package/dist/lib/ast/transform/skew.js +1 -1
  22. package/dist/lib/ast/transform/translate.js +1 -1
  23. package/dist/lib/ast/transform/utils.js +46 -18
  24. package/dist/lib/ast/walk.js +28 -4
  25. package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
  26. package/dist/lib/{validation/config.json.js → data/validation.json.js} +14 -8
  27. package/dist/lib/fs/resolve.js +11 -2
  28. package/dist/lib/parser/declaration/list.js +22 -7
  29. package/dist/lib/parser/declaration/map.js +26 -8
  30. package/dist/lib/parser/declaration/set.js +3 -1
  31. package/dist/lib/parser/linesmap.js +2 -4
  32. package/dist/lib/parser/parse.js +393 -231
  33. package/dist/lib/parser/tokenize.js +1478 -819
  34. package/dist/lib/parser/utils/at-rule-container.js +28 -196
  35. package/dist/lib/parser/utils/at-rule-generic.js +6 -7
  36. package/dist/lib/parser/utils/at-rule-import.js +17 -13
  37. package/dist/lib/parser/utils/at-rule-media.js +36 -19
  38. package/dist/lib/parser/utils/at-rule-support.js +19 -9
  39. package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
  40. package/dist/lib/parser/utils/at-rule.js +0 -18
  41. package/dist/lib/parser/utils/config.js +1 -1
  42. package/dist/lib/parser/utils/declaration.js +40 -97
  43. package/dist/lib/parser/utils/hash.js +4 -4
  44. package/dist/lib/parser/utils/selector.js +179 -224
  45. package/dist/lib/parser/utils/text.js +4 -2
  46. package/dist/lib/renderer/render.js +104 -74
  47. package/dist/lib/renderer/sourcemap/lib/codec.js +3 -3
  48. package/dist/lib/renderer/sourcemap/sourcemap.js +2 -5
  49. package/dist/lib/syntax/color/a98rgb.js +14 -4
  50. package/dist/lib/syntax/color/cmyk.js +14 -21
  51. package/dist/lib/syntax/color/color-mix.js +21 -34
  52. package/dist/lib/syntax/color/color.js +32 -49
  53. package/dist/lib/syntax/color/hsl.js +15 -15
  54. package/dist/lib/syntax/color/hwb.js +18 -17
  55. package/dist/lib/syntax/color/lab.js +17 -17
  56. package/dist/lib/syntax/color/lch.js +13 -13
  57. package/dist/lib/syntax/color/oklab.js +10 -11
  58. package/dist/lib/syntax/color/oklch.js +15 -18
  59. package/dist/lib/syntax/color/p3.js +18 -12
  60. package/dist/lib/syntax/color/prophotorgb.js +26 -28
  61. package/dist/lib/syntax/color/rec2020.js +8 -4
  62. package/dist/lib/syntax/color/relative-color.js +26 -10
  63. package/dist/lib/syntax/color/srgb.js +9 -7
  64. package/dist/lib/syntax/color/utils/distance.js +1 -1
  65. package/dist/lib/syntax/color/xyz.js +2 -2
  66. package/dist/lib/syntax/color/xyzd50.js +2 -2
  67. package/dist/lib/syntax/constants.js +13 -3
  68. package/dist/lib/syntax/syntax.js +32 -108
  69. package/dist/lib/validation/config.js +1 -1
  70. package/dist/lib/validation/match.js +29 -26
  71. package/dist/lib/validation/parser/parse.js +7 -3
  72. package/dist/node.js +16 -9
  73. package/dist/types.d.ts +5 -1
  74. package/dist/types.js +4 -0
  75. package/dist/utils/sync.js +22 -1
  76. package/dist/web.js +13 -4
  77. package/package.json +4 -4
  78. package/llms.txt +0 -80
@@ -1,7 +1,7 @@
1
1
  import { getParsedSyntax, getSyntaxConfig } from './config.js';
2
2
  import { EnumToken } from '../ast/types.js';
3
3
  import { ValidationSyntaxGroupEnum, ValidationTokenEnum, MediaFeatureType } from './parser/typedef.js';
4
- import { LOC, tokensfuncDefMap, tokensfuncSet, funcLike, mFLT, mFGT } from '../syntax/constants.js';
4
+ import { LOCSTA, tokensfuncDefMap, tokensfuncSet, funcLike, mFLT, mFGT } from '../syntax/constants.js';
5
5
  import { isColor } from '../syntax/syntax.js';
6
6
  import { equalsIgnoreCase } from '../parser/utils/text.js';
7
7
  import { cloneNode } from '../ast/clone.js';
@@ -13,11 +13,8 @@ const allValues = config.declarations.all.syntax.split(/[\s|]+/g);
13
13
  /**
14
14
  * @type {Array.<EnumToken>}
15
15
  */
16
- const funcTypes = [
17
- ...tokensfuncDefMap.values(),
18
- EnumToken.FunctionTokenType,
19
- EnumToken.PseudoClassFuncTokenType,
20
- ];
16
+ const funcTypes = Array.from(tokensfuncDefMap.values());
17
+ funcTypes.push(EnumToken.FunctionTokenType, EnumToken.PseudoClassFuncTokenType);
21
18
  /**
22
19
  * trim leading and trailing whitespace
23
20
  * @param tokens
@@ -340,7 +337,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
340
337
  message: `Unexpected token ${EnumToken[stream[i].typ]}`,
341
338
  node: stream[i],
342
339
  // @ts-expect-error
343
- location: options.source.getSourceLocation(stream[i][LOC].sta),
340
+ location: options.source.getSourceLocation(stream[i][LOCSTA]),
344
341
  },
345
342
  ],
346
343
  };
@@ -375,7 +372,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
375
372
  if (!result.success) {
376
373
  success = false;
377
374
  if (result.errors.length > 0) {
378
- errors.push(...result.errors);
375
+ for (const error of result.errors) {
376
+ errors.push(error);
377
+ }
379
378
  }
380
379
  }
381
380
  }
@@ -394,7 +393,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
394
393
  message: `Nesting selector is not allowed`,
395
394
  node: token,
396
395
  // @ts-expect-error
397
- location: options.source.getSourceLocation(token[LOC].sta),
396
+ location: options.source.getSourceLocation(token[LOCSTA]),
398
397
  },
399
398
  ],
400
399
  };
@@ -428,7 +427,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
428
427
  message: `Unexpected combinator ${EnumToken[token.typ]}`,
429
428
  node: token,
430
429
  // @ts-expect-error
431
- location: options.source.getSourceLocation(token[LOC].sta),
430
+ location: options.source.getSourceLocation(token[LOCSTA]),
432
431
  },
433
432
  ],
434
433
  };
@@ -472,7 +471,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
472
471
  message: `Unexpected token ${EnumToken[token.typ]}`,
473
472
  node: token,
474
473
  // @ts-expect-error
475
- location: options.source.getSourceLocation(token[LOC].sta),
474
+ location: options.source.getSourceLocation(token[LOCSTA]),
476
475
  },
477
476
  ],
478
477
  };
@@ -523,7 +522,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
523
522
  message: `Unexpected token ${EnumToken[slice[0].typ]}`,
524
523
  node: slice[0],
525
524
  // @ts-expect-error
526
- location: options.source.getSourceLocation(slice[0][LOC].sta),
525
+ location: options.source.getSourceLocation(slice[0][LOCSTA]),
527
526
  },
528
527
  ],
529
528
  };
@@ -535,8 +534,8 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
535
534
  // errors: [
536
535
  // {
537
536
  // action: "drop",
538
- // message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0][LOC]!.src}:${slice[0][LOC]!.sta.lin}:${
539
- // slice[0][LOC]!.sta.col
537
+ // message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0][LOC]!.src}:${slice[0][LOCSTA].lin}:${
538
+ // slice[0][LOCSTA].col
540
539
  // }`,
541
540
  // node: slice[0],
542
541
  // location: slice[0][LOC],
@@ -574,8 +573,8 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
574
573
  // errors: [
575
574
  // {
576
575
  // action: "drop",
577
- // message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
578
- // token[LOC]!.sta.col
576
+ // message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOCSTA].lin}:${
577
+ // token[LOCSTA].col
579
578
  // }`,
580
579
  // node: token,
581
580
  // location: token[LOC],
@@ -607,8 +606,8 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
607
606
  // errors: [
608
607
  // {
609
608
  // action: "drop",
610
- // message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
611
- // token[LOC]!.sta.col
609
+ // message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOCSTA].lin}:${
610
+ // token[LOCSTA].col
612
611
  // }`,
613
612
  // node: token,
614
613
  // location: token[LOC],
@@ -637,7 +636,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
637
636
  message: `Unexpected token ${EnumToken[token.typ]}`,
638
637
  node: token,
639
638
  // @ts-expect-error
640
- location: options.source.getSourceLocation(token[LOC].sta),
639
+ location: options.source.getSourceLocation(token[LOCSTA]),
641
640
  },
642
641
  ],
643
642
  };
@@ -666,7 +665,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
666
665
  if (!result.success) {
667
666
  success = false;
668
667
  if (result.errors.length > 0) {
669
- errors.push(...result.errors);
668
+ for (const error of result.errors) {
669
+ errors.push(error);
670
+ }
670
671
  }
671
672
  }
672
673
  stack.pop();
@@ -680,7 +681,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
680
681
  message: `Unexpected token ${EnumToken[token.typ]}`,
681
682
  node: token,
682
683
  // @ts-expect-error
683
- location: options.source.getSourceLocation(token[LOC].sta),
684
+ location: options.source.getSourceLocation(token[LOCSTA]),
684
685
  },
685
686
  ],
686
687
  };
@@ -702,7 +703,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
702
703
  message: `Unsupported selector token ${EnumToken[token.typ]}`,
703
704
  node: token,
704
705
  // @ts-expect-error
705
- location: options.source.getSourceLocation(token[LOC].sta),
706
+ location: options.source.getSourceLocation(token[LOCSTA]),
706
707
  },
707
708
  ],
708
709
  };
@@ -728,13 +729,15 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
728
729
  message: `Unmatched token ${EnumToken[stack.at(-1).typ]}`,
729
730
  node: stack.at(-1),
730
731
  // @ts-expect-error
731
- location: options.source.getSourceLocation(stack.at(-1)[LOC].sta),
732
+ location: options.source.getSourceLocation(stack.at(-1)[LOCSTA]),
732
733
  },
733
734
  ],
734
735
  };
735
736
  }
736
737
  stream.length = 0;
737
- stream.push(...tokens);
738
+ for (let i = 0; i < tokens.length; i++) {
739
+ stream.push(tokens[i]);
740
+ }
738
741
  return { success, errors };
739
742
  }
740
743
  /**
@@ -775,7 +778,7 @@ function matchAllSyntaxes(syntaxes, context, options) {
775
778
  message: result.errors[0]?.message || "could not match syntax",
776
779
  node: result.token,
777
780
  syntax: result.syntaxToken,
778
- location: options.source.getSourceLocation((result.token?.[LOC] ?? context.tokens.at(-1)?.[LOC]).sta),
781
+ location: options.source.getSourceLocation((result.token?.[LOCSTA] ?? context.tokens.at(-1)?.[LOCSTA])),
779
782
  },
780
783
  ]
781
784
  : result.errors,
@@ -870,7 +873,7 @@ function matchOccurenceSyntax(syntax, context, options) {
870
873
  action: "drop",
871
874
  message: "could not match syntax",
872
875
  node: context.peek(),
873
- // location: options.source!.getSourceLocation(context.peek()?.[LOC]!.sta),
876
+ // location: options.source!.getSourceLocation(context.peek()?.[LOCSTA]),
874
877
  },
875
878
  ],
876
879
  syntaxToken: null,
@@ -677,9 +677,13 @@ function parseSyntax(syntax) {
677
677
  stack.pop();
678
678
  }
679
679
  }
680
- if (stack.length > 0) {
681
- throw new SyntaxError(`Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ]} at ${stack.at(-1)?.[LOC]?.lin}:${stack.at(-1)?.[LOC]?.col}`);
682
- }
680
+ // if (stack.length > 0) {
681
+ // throw new SyntaxError(
682
+ // `Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ as ValidationTokenEnum]} at ${
683
+ // stack.at(-1)?.[LOC]?.lin
684
+ // }:${stack.at(-1)?.[LOC]?.col}`,
685
+ // );
686
+ // }
683
687
  return trimSyntaxArray(tokens);
684
688
  }
685
689
 
package/dist/node.js CHANGED
@@ -8,7 +8,7 @@ import { doRender } from './lib/renderer/render.js';
8
8
  export { renderValue as renderToken } from './lib/renderer/render.js';
9
9
  import { ModuleScopeEnumOptions } from './lib/ast/types.js';
10
10
  export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ValidationLevel } from './lib/ast/types.js';
11
- import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
11
+ import { Tokenizer } from './lib/parser/tokenize.js';
12
12
  import { dirname, resolve, matchUrl } from './lib/fs/resolve.js';
13
13
  import { ResponseType } from './types.js';
14
14
  import { resolve as resolve$1 } from 'node:path';
@@ -52,6 +52,9 @@ async function load(url, currentDirectory = ".", responseType = false) {
52
52
  if (responseType == ResponseType.ArrayBuffer) {
53
53
  return response.arrayBuffer();
54
54
  }
55
+ if (responseType == ResponseType.JSON) {
56
+ return response.json();
57
+ }
55
58
  return responseType == ResponseType.ReadableStream
56
59
  ? response.body
57
60
  : response.text();
@@ -60,8 +63,8 @@ async function load(url, currentDirectory = ".", responseType = false) {
60
63
  try {
61
64
  const stats = await lstat(resolved.absolute);
62
65
  if (stats.isFile()) {
63
- if (responseType == ResponseType.Text) {
64
- return readFile(resolved.absolute, "utf-8");
66
+ if (responseType == ResponseType.Text || responseType == ResponseType.JSON) {
67
+ return readFile(resolved.absolute, "utf-8").then((buffer) => responseType == ResponseType.JSON ? JSON.parse(buffer) : buffer);
65
68
  }
66
69
  if (responseType == ResponseType.ArrayBuffer) {
67
70
  return readFile(resolved.absolute).then((buffer) => buffer.buffer);
@@ -72,9 +75,7 @@ async function load(url, currentDirectory = ".", responseType = false) {
72
75
  }));
73
76
  }
74
77
  }
75
- catch (error) {
76
- console.warn(error);
77
- }
78
+ catch (error) { }
78
79
  throw new Error(`File not found: '${resolved.absolute || url}'`);
79
80
  }
80
81
  /**
@@ -190,8 +191,10 @@ function parseSync(...args) {
190
191
  position: 0,
191
192
  currentPosition: 0,
192
193
  };
193
- const result = doParseSync(tokenize(options.parseInfo), options);
194
- return !options.module && !options.inputSourceMap && !options.sourcemap ? result : parseResult(result, options);
194
+ const result = doParseSync(new Tokenizer(options.parseInfo), options);
195
+ return options.module == null && options.inputSourceMap == null && !options.sourcemap
196
+ ? result
197
+ : parseResult(result, options);
195
198
  }
196
199
  /**
197
200
  * Transform CSS
@@ -348,7 +351,11 @@ async function parse(...args) {
348
351
  position: 0,
349
352
  currentPosition: 0,
350
353
  };
351
- return doParse(stream instanceof ReadableStream ? tokenizeStream(stream, options.parseInfo) : tokenize(options.parseInfo), options).then((result) => (!options.module && !options.inputSourceMap ? result : parseResult(result, options)));
354
+ return doParse(stream instanceof ReadableStream
355
+ ? new Tokenizer(options.parseInfo, stream).tokenizeStream()
356
+ : new Tokenizer(options.parseInfo), options).then((result) => options.module == null && options.inputSourceMap == null && !options.sourcemap
357
+ ? result
358
+ : parseResult(result, options));
352
359
  }
353
360
  /**
354
361
  * Transform CSS file
package/dist/types.d.ts CHANGED
@@ -13,5 +13,9 @@ export declare enum ResponseType {
13
13
  /**
14
14
  * return an arraybuffer
15
15
  */
16
- ArrayBuffer = 2
16
+ ArrayBuffer = 2,
17
+ /**
18
+ * return a json object
19
+ */
20
+ JSON = 3
17
21
  }
package/dist/types.js CHANGED
@@ -15,6 +15,10 @@ var ResponseType;
15
15
  * return an arraybuffer
16
16
  */
17
17
  ResponseType[ResponseType["ArrayBuffer"] = 2] = "ArrayBuffer";
18
+ /**
19
+ * return a json object
20
+ */
21
+ ResponseType[ResponseType["JSON"] = 3] = "JSON";
18
22
  })(ResponseType || (ResponseType = {}));
19
23
 
20
24
  export { ResponseType };
@@ -1,4 +1,6 @@
1
1
  import { EnumToken } from '../lib/ast/types.js';
2
+ import { dirname } from '../lib/fs/resolve.js';
3
+ import { ResponseType } from '../types.js';
2
4
 
3
5
  /**
4
6
  * parse result. process input sourcemap
@@ -17,7 +19,26 @@ function parseResult(result, options) {
17
19
  const token = result.ast.chi.at(-1);
18
20
  if (token?.typ == EnumToken.CommentTokenType &&
19
21
  token.val.startsWith("/*# sourceMappingURL=")) {
20
- options.source.setInputSourceMap(token.val.slice(21, -2).trim());
22
+ let data = token.val.slice(21, -2).trim();
23
+ if (data.endsWith(".map")) {
24
+ if (options.load == null) {
25
+ data = "";
26
+ }
27
+ else {
28
+ options
29
+ .load(options.resolve(data, dirname(options.src)).absolute, ".", ResponseType.JSON)
30
+ .catch((error) => console.error({ error }))
31
+ .then((res) => {
32
+ if (res != null) {
33
+ // @ts-expect-error
34
+ options.source.setInputSourceMap(res);
35
+ }
36
+ });
37
+ }
38
+ }
39
+ else {
40
+ options.source.setInputSourceMap(data);
41
+ }
21
42
  }
22
43
  }
23
44
  }
package/dist/web.js CHANGED
@@ -4,7 +4,7 @@ import { doRender } from './lib/renderer/render.js';
4
4
  export { renderValue as renderToken } from './lib/renderer/render.js';
5
5
  import { ModuleScopeEnumOptions } from './lib/ast/types.js';
6
6
  export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ValidationLevel } from './lib/ast/types.js';
7
- import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
7
+ import { Tokenizer } from './lib/parser/tokenize.js';
8
8
  import { matchUrl, resolve, dirname } from './lib/fs/resolve.js';
9
9
  import { ResponseType } from './types.js';
10
10
  import { SourceFile } from './lib/parser/source.js';
@@ -58,6 +58,9 @@ async function load(url, currentDirectory = ".", responseType = false) {
58
58
  if (responseType == ResponseType.ArrayBuffer) {
59
59
  return response.arrayBuffer();
60
60
  }
61
+ if (responseType == ResponseType.JSON) {
62
+ return response.json();
63
+ }
61
64
  return responseType == ResponseType.ReadableStream ? response.body : response.text();
62
65
  });
63
66
  }
@@ -184,8 +187,10 @@ function parseSync(...args) {
184
187
  position: 0,
185
188
  currentPosition: 0,
186
189
  };
187
- const result = doParseSync(tokenize(options.parseInfo), options);
188
- return !options.module && !options.inputSourceMap && !options.sourcemap ? result : parseResult(result, options);
190
+ const result = doParseSync(new Tokenizer(options.parseInfo), options);
191
+ return options.module == null && options.inputSourceMap == null && !options.sourcemap
192
+ ? result
193
+ : parseResult(result, options);
189
194
  }
190
195
  /**
191
196
  * Transform CSS
@@ -318,7 +323,11 @@ async function parse(...args) {
318
323
  position: 0,
319
324
  currentPosition: 0,
320
325
  };
321
- return doParse(stream instanceof ReadableStream ? tokenizeStream(stream, options.parseInfo) : tokenize(options.parseInfo), options).then((result) => (!options.module && !options.inputSourceMap ? result : parseResult(result, options)));
326
+ return doParse(stream instanceof ReadableStream
327
+ ? new Tokenizer(options.parseInfo, stream).tokenizeStream()
328
+ : new Tokenizer(options.parseInfo), options).then((result) => options.module == null && options.inputSourceMap == null && !options.sourcemap
329
+ ? result
330
+ : parseResult(result, options));
322
331
  }
323
332
  /**
324
333
  * Transform CSS file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tbela99/css-parser",
3
3
  "description": "CSS parser, minifier and validator for node and the browser",
4
- "version": "1.5.0",
4
+ "version": "1.6.1",
5
5
  "exports": {
6
6
  ".": "./dist/node.js",
7
7
  "./node": "./dist/node.js",
@@ -66,16 +66,16 @@
66
66
  "@rollup/plugin-typescript": "^12.3.0",
67
67
  "@types/chai": "^5.2.3",
68
68
  "@types/mocha": "^10.0.10",
69
- "@types/node": "^26.2.0",
69
+ "@types/node": "^26.4.1",
70
70
  "@types/web": "^0.0.354",
71
71
  "@web/test-runner": "^1.0.0",
72
72
  "@web/test-runner-playwright": "^1.0.0",
73
73
  "chai": "^6.2.2",
74
74
  "esno": "^4.8.0",
75
75
  "markdown-it-task-lists": "^2.1.1",
76
- "mocha": "^11.8.0",
76
+ "mocha": "^12.0.0",
77
77
  "playwright": "^1.62.1",
78
- "rollup": "^4.62.4",
78
+ "rollup": "^4.63.1",
79
79
  "rollup-plugin-dts": "^6.5.1",
80
80
  "superc8": "^12.7.0",
81
81
  "tslib": "^2.8.1",
package/llms.txt DELETED
@@ -1,80 +0,0 @@
1
- # css-parser
2
-
3
- ## Project overview
4
- - This repository contains css-parser, a dependency-free all-in-one CSS parsing solution for Node.js and browsers.
5
- - The library follows the CSS Syntax Module Level 3 specification and uses MDN syntax data for validation.
6
- - It is designed for fault-tolerant parsing, full AST and typed-token analysis, AST manipulation, CSS Modules, minification, color processing, and syntax lowering.
7
- - CSS is always fully parsed into a structured AST, and token values are typed so plugins and transforms can work against semantic data instead of raw strings.
8
-
9
- ## Installation
10
- - npm: npm install @tbela99/css-parser
11
- - jsr: deno add @tbela99/css-parser
12
- - Main entry points:
13
- - @tbela99/css-parser or @tbela99/css-parser/node
14
- - @tbela99/css-parser/web
15
-
16
- ## Core APIs
17
- - parse(css, options): async api to parse CSS and returns an AST, errors, and stats.
18
- - parseSync(css, options): sync api to parse CSS and returns an AST, errors, and stats.
19
- - render(ast, options): renders an AST back to CSS text.
20
- - transform(css, options): async api to parse CSS and generate output in one step.
21
- - transformSync(css, options): sync api to parse CSS and generate output in one step.
22
- - walk(ast, filter): traverses the AST for custom transformations.
23
-
24
- ## Common capabilities
25
- - Parse CSS into an AST and inspect or modify it.
26
- - Validate declarations against CSS syntax definitions.
27
- - Support CSS Modules with scoped class generation.
28
- - Minify CSS safely with options such as inlineCssVariables, computeCalcExpression, removeDuplicateDeclarations, and beautify.
29
- - Transform ASTs through visitors and custom traversal logic.
30
- - Support plugin-style extensions through the visitor API, where custom handlers can observe and mutate AST nodes during enter/visit/leave phases.
31
- - Lower modern CSS syntax such as nested CSS and if() to broadly compatible output.
32
- - Generate source maps and handle advanced color functions and conversions.
33
-
34
- ## Visitor-based plugin model
35
- - The parser exposes a visitor option that accepts node-specific handlers keyed by AST node type and event type.
36
- - Plugins can be implemented as reusable visitor maps that inspect or transform nodes such as Rule, AtRule, Declaration, KeyframesRule, and Value nodes.
37
- - This allows extension code to run alongside the core parser without modifying the parser itself.
38
-
39
- ## Typical usage
40
- ```ts
41
- import {transform, ColorType} from '@tbela99/css-parser';
42
-
43
- const css = `.foo { color: red; }`;
44
- const result = await transform(css, {
45
- beautify: true,
46
- convertColor: ColorType.SRGB,
47
- });
48
-
49
- console.log(result.code);
50
- ```
51
-
52
- ## Important behavior notes
53
- - parse(), parseSync(), transform() and transformSync() are lenient by default and preserve unknown constructs unless configured otherwise.
54
- - Comments are removed by default; preserve them with removeComments: false or preserveLicense: true.
55
- - Validation errors are available through the parse/transform result and through node.state and node.errors.
56
- - The library prioritizes compact output while preserving semantics.
57
-
58
- ## Useful concepts
59
- - parse(), parseSync() return AST, errors, and stats.
60
- - render() turns an AST into CSS text.
61
- - transform(), transformSync() perform parsing and rendering together.
62
- - AST node types include StyleSheet, Rule, AtRule, Declaration, Comment, and Keyframes variants.
63
-
64
- ## Documentation files
65
- - files/getting-started.md
66
- - files/usage.md
67
- - files/validation.md
68
- - files/css-module.md
69
- - files/minification.md
70
- - files/transform.md
71
- - files/syntax-lowering.md
72
- - files/ast.md
73
- - files/utilities.md
74
-
75
- ## Repository layout
76
- - src/: parser implementation and core library code
77
- - test/: regression and behavior tests
78
- - files/: documentation content used by the docs site
79
- - benchmark/: performance and minification benchmarks
80
- - scripts/: helper scripts and patches