@tbela99/css-parser 1.6.0 → 1.6.2

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 (48) hide show
  1. package/CHANGELOG.md +118 -2
  2. package/README.md +4 -3
  3. package/dist/index-umd-web.js +1629 -467
  4. package/dist/index.cjs +1629 -467
  5. package/dist/index.d.ts +72 -7
  6. package/dist/lib/ast/features/prefix.js +9 -1
  7. package/dist/lib/ast/features/shorthand.js +1 -1
  8. package/dist/lib/ast/features/transform.js +1 -1
  9. package/dist/lib/ast/math/expression.js +175 -5
  10. package/dist/lib/ast/minify.js +84 -10
  11. package/dist/lib/ast/transform/compute.js +24 -55
  12. package/dist/lib/ast/transform/minify.js +1 -1
  13. package/dist/lib/ast/types.js +12 -0
  14. package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
  15. package/dist/lib/{validation/config.json.js → data/validation.json.js} +11 -8
  16. package/dist/lib/parser/declaration/list.js +8 -10
  17. package/dist/lib/parser/parse.js +8 -14
  18. package/dist/lib/parser/tokenize.js +89 -58
  19. package/dist/lib/parser/utils/at-rule-font-feature-values.js +1 -1
  20. package/dist/lib/parser/utils/at-rule-media.js +66 -0
  21. package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
  22. package/dist/lib/parser/utils/base64.js +14 -0
  23. package/dist/lib/parser/utils/config.js +1 -1
  24. package/dist/lib/parser/utils/declaration.js +18 -17
  25. package/dist/lib/parser/utils/eq.js +6 -0
  26. package/dist/lib/parser/utils/hash.js +1 -0
  27. package/dist/lib/parser/utils/selector.js +99 -89
  28. package/dist/lib/parser/utils/text.js +16 -0
  29. package/dist/lib/renderer/render.js +20 -6
  30. package/dist/lib/renderer/sourcemap/lib/codec.js +8 -3
  31. package/dist/lib/renderer/sourcemap/sourcemap.js +35 -5
  32. package/dist/lib/syntax/color/alpha.js +57 -22
  33. package/dist/lib/syntax/color/cmyk.js +4 -3
  34. package/dist/lib/syntax/color/color-mix.js +18 -18
  35. package/dist/lib/syntax/color/srgb.js +11 -5
  36. package/dist/lib/syntax/color/utils/components.js +1 -1
  37. package/dist/lib/syntax/color/utils/distance.js +2 -2
  38. package/dist/lib/syntax/color/utils/matrix.js +1 -0
  39. package/dist/lib/syntax/color/xyz.js +5 -0
  40. package/dist/lib/syntax/color/xyzd50.js +17 -0
  41. package/dist/lib/syntax/constants.js +1 -1
  42. package/dist/lib/syntax/syntax.js +549 -13
  43. package/dist/lib/validation/config.js +27 -1
  44. package/dist/lib/validation/match.js +16 -4
  45. package/dist/lib/validation/parser/parse.js +7 -3
  46. package/dist/node.js +8 -14
  47. package/dist/web.js +8 -14
  48. package/package.json +4 -4
@@ -29,6 +29,15 @@ function trimArray(tokens) {
29
29
  }
30
30
  return tokens;
31
31
  }
32
+ /**
33
+ * is a media feature
34
+ * @param featureName
35
+ * @returns
36
+ */
37
+ // export function isMFName(featureName: string): boolean {
38
+ // // @ts-expect-error
39
+ // return featureName.startsWith("--") || config.mediaFeatures[featureName.toLowerCase()] != null;
40
+ // }
32
41
  /**
33
42
  *
34
43
  * @param featureName
@@ -42,6 +51,7 @@ function getMFInfo(featureName) {
42
51
  *
43
52
  * @param featureName
44
53
  * @param tokens
54
+ * @param isMFRange
45
55
  * @returns object with:
46
56
  * - valid: boolean. true the media feaure is known or is a custom property. false otherwise
47
57
  * - success: boolean. validation result
@@ -159,9 +169,10 @@ function createValidationContext(tokens) {
159
169
  },
160
170
  /**
161
171
  *
162
- * @param stopCondition
163
- * @param matchCount
164
172
  * @returns
173
+ * @param open
174
+ * @param close
175
+ * @param counter
165
176
  */
166
177
  peekRange(open = EnumToken.StartParensTokenType, close = EnumToken.EndParensTokenType, counter = 0) {
167
178
  let index = this.index;
@@ -384,7 +395,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
384
395
  case EnumToken.CDOCOMMTokenType:
385
396
  break;
386
397
  case EnumToken.NestingSelectorTokenType:
387
- if (nested === false && !options.nestedRule) {
398
+ if (!nested && !options.nestedRule) {
388
399
  return {
389
400
  success: false,
390
401
  errors: [
@@ -1425,7 +1436,8 @@ function matchSyntax(syntaxes, context, options) {
1425
1436
  errors: [],
1426
1437
  };
1427
1438
  case ValidationTokenEnum.FunctionDefinition:
1428
- if (equalsIgnoreCase(token.val, syntaxes[i].val)) {
1439
+ if (token.val &&
1440
+ equalsIgnoreCase(token.val, syntaxes[i].val)) {
1429
1441
  if (tokensfuncDefMap.has(token.typ)) {
1430
1442
  const children = trimArray(context.peekRange());
1431
1443
  result = matchSyntax((getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(children.slice(1, -1)), options);
@@ -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
@@ -237,13 +237,10 @@ function transformSync(...args) {
237
237
  const parseResult = parseSync(stream, options);
238
238
  let mapping = null;
239
239
  let importMapping = null;
240
- if (typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) {
241
- mapping = parseResult.mapping;
242
- importMapping = parseResult.importMapping;
243
- }
244
- else if (typeof options.module == "object" &&
245
- typeof options.module.scoped == "number" &&
246
- options.module.scoped & ModuleScopeEnumOptions.ICSS) {
240
+ if ((typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) ||
241
+ (typeof options.module == "object" &&
242
+ typeof options.module.scoped == "number" &&
243
+ options.module.scoped & ModuleScopeEnumOptions.ICSS)) {
247
244
  mapping = parseResult.mapping;
248
245
  importMapping = parseResult.importMapping;
249
246
  }
@@ -460,13 +457,10 @@ async function transform(...args) {
460
457
  return parse(stream, options).then((parseResult) => {
461
458
  let mapping = null;
462
459
  let importMapping = null;
463
- if (typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) {
464
- mapping = parseResult.mapping;
465
- importMapping = parseResult.importMapping;
466
- }
467
- else if (typeof options.module == "object" &&
468
- typeof options.module.scoped == "number" &&
469
- options.module.scoped & ModuleScopeEnumOptions.ICSS) {
460
+ if ((typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) ||
461
+ (typeof options.module == "object" &&
462
+ typeof options.module.scoped == "number" &&
463
+ options.module.scoped & ModuleScopeEnumOptions.ICSS)) {
470
464
  mapping = parseResult.mapping;
471
465
  importMapping = parseResult.importMapping;
472
466
  }
package/dist/web.js CHANGED
@@ -225,13 +225,10 @@ function transformSync(...args) {
225
225
  const parseResult = parseSync(stream, options);
226
226
  let mapping = null;
227
227
  let importMapping = null;
228
- if (typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) {
229
- mapping = parseResult.mapping;
230
- importMapping = parseResult.importMapping;
231
- }
232
- else if (typeof options.module == "object" &&
233
- typeof options.module.scoped == "number" &&
234
- options.module.scoped & ModuleScopeEnumOptions.ICSS) {
228
+ if ((typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) ||
229
+ (typeof options.module == "object" &&
230
+ typeof options.module.scoped == "number" &&
231
+ options.module.scoped & ModuleScopeEnumOptions.ICSS)) {
235
232
  mapping = parseResult.mapping;
236
233
  importMapping = parseResult.importMapping;
237
234
  }
@@ -403,13 +400,10 @@ async function transform(...args) {
403
400
  return parse(stream, options).then((parseResult) => {
404
401
  let mapping = null;
405
402
  let importMapping = null;
406
- if (typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) {
407
- mapping = parseResult.mapping;
408
- importMapping = parseResult.importMapping;
409
- }
410
- else if (typeof options.module == "object" &&
411
- typeof options.module.scoped == "number" &&
412
- options.module.scoped & ModuleScopeEnumOptions.ICSS) {
403
+ if ((typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) ||
404
+ (typeof options.module == "object" &&
405
+ typeof options.module.scoped == "number" &&
406
+ options.module.scoped & ModuleScopeEnumOptions.ICSS)) {
413
407
  mapping = parseResult.mapping;
414
408
  importMapping = parseResult.importMapping;
415
409
  }
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.6.0",
4
+ "version": "1.6.2",
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",