@tbela99/css-parser 1.2.0 → 1.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 (55) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +2 -2
  3. package/dist/index-umd-web.js +483 -849
  4. package/dist/index.cjs +483 -849
  5. package/dist/index.d.ts +107 -11
  6. package/dist/lib/ast/features/calc.js +1 -25
  7. package/dist/lib/ast/features/inlinecssvariables.js +0 -19
  8. package/dist/lib/ast/features/transform.js +2 -2
  9. package/dist/lib/ast/math/expression.js +26 -149
  10. package/dist/lib/ast/math/math.js +8 -8
  11. package/dist/lib/ast/transform/compute.js +4 -37
  12. package/dist/lib/ast/transform/matrix.js +33 -34
  13. package/dist/lib/ast/transform/minify.js +32 -51
  14. package/dist/lib/ast/transform/perspective.js +1 -1
  15. package/dist/lib/ast/transform/rotate.js +13 -13
  16. package/dist/lib/ast/transform/scale.js +8 -8
  17. package/dist/lib/ast/transform/skew.js +4 -4
  18. package/dist/lib/ast/transform/translate.js +8 -8
  19. package/dist/lib/ast/transform/utils.js +31 -39
  20. package/dist/lib/ast/types.js +91 -2
  21. package/dist/lib/parser/declaration/set.js +2 -2
  22. package/dist/lib/parser/parse.js +34 -12
  23. package/dist/lib/parser/tokenize.js +28 -40
  24. package/dist/lib/parser/utils/type.js +1 -1
  25. package/dist/lib/renderer/render.js +36 -27
  26. package/dist/lib/syntax/color/cmyk.js +2 -2
  27. package/dist/lib/syntax/color/color-mix.js +11 -12
  28. package/dist/lib/syntax/color/color.js +7 -7
  29. package/dist/lib/syntax/color/hsl.js +4 -4
  30. package/dist/lib/syntax/color/hwb.js +27 -8
  31. package/dist/lib/syntax/color/lab.js +4 -4
  32. package/dist/lib/syntax/color/lch.js +4 -4
  33. package/dist/lib/syntax/color/oklab.js +4 -4
  34. package/dist/lib/syntax/color/oklch.js +4 -4
  35. package/dist/lib/syntax/color/relativecolor.js +1 -1
  36. package/dist/lib/syntax/color/rgb.js +4 -4
  37. package/dist/lib/syntax/color/utils/components.js +15 -3
  38. package/dist/lib/syntax/color/utils/distance.js +11 -1
  39. package/dist/lib/syntax/syntax.js +8 -17
  40. package/dist/lib/syntax/utils.js +1 -1
  41. package/dist/lib/validation/at-rules/document.js +1 -1
  42. package/dist/lib/validation/at-rules/import.js +4 -4
  43. package/dist/lib/validation/at-rules/keyframes.js +0 -11
  44. package/dist/lib/validation/at-rules/supports.js +6 -6
  45. package/dist/lib/validation/config.js +0 -4
  46. package/dist/lib/validation/parser/parse.js +0 -8
  47. package/dist/lib/validation/selector.js +0 -9
  48. package/dist/lib/validation/syntax.js +14 -134
  49. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -11
  50. package/dist/lib/validation/syntaxes/family-name.js +0 -32
  51. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -11
  52. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -26
  53. package/dist/lib/validation/syntaxes/url.js +0 -33
  54. package/dist/lib/validation/utils/list.js +0 -8
  55. package/package.json +1 -1
@@ -42,15 +42,8 @@ function createContext(input) {
42
42
  },
43
43
  consume(token, howMany) {
44
44
  let newIndex = result.indexOf(token, this.index + 1);
45
- // if (newIndex == -1 || newIndex < this.index) {
46
- // return false;
47
- // }
48
45
  howMany ??= 0;
49
46
  let splice = 1;
50
- // if (result[newIndex - 1]?.typ == EnumToken.WhitespaceTokenType) {
51
- // splice++;
52
- // newIndex--;
53
- // }
54
47
  result.splice(this.index + 1, 0, ...result.splice(newIndex, splice + howMany));
55
48
  this.index += howMany + splice;
56
49
  return true;
@@ -72,10 +65,6 @@ function createContext(input) {
72
65
  this.index = index;
73
66
  return result[this.index] ?? null;
74
67
  },
75
- // tokens<Token>(): Token[] {
76
- //
77
- // return result as Token[];
78
- // },
79
68
  slice() {
80
69
  return result.slice(this.index + 1);
81
70
  },
@@ -83,16 +72,7 @@ function createContext(input) {
83
72
  const context = createContext(result.slice());
84
73
  context.index = this.index;
85
74
  return context;
86
- },
87
- // @ts-ignore
88
- // toJSON(): object {
89
- //
90
- // return {
91
- // index: this.index,
92
- // slice: this.slice(),
93
- // tokens: this.tokens()
94
- // }
95
- // }
75
+ }
96
76
  };
97
77
  }
98
78
  function evaluateSyntax(node, options) {
@@ -126,10 +106,6 @@ function evaluateSyntax(node, options) {
126
106
  if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
127
107
  let token = null;
128
108
  if ((token = result.context.next()) != null) {
129
- // if (token.typ == EnumToken.WhitespaceTokenType || token.typ == EnumToken.CommentTokenType) {
130
- //
131
- // continue;
132
- // }
133
109
  return {
134
110
  ...result,
135
111
  valid: SyntaxValidationResult.Drop,
@@ -145,13 +121,6 @@ function evaluateSyntax(node, options) {
145
121
  };
146
122
  }
147
123
  break;
148
- // case EnumToken.RuleNodeType:
149
- // case EnumToken.AtRuleNodeType:
150
- // case EnumToken.KeyframeAtRuleNodeType:
151
- // case EnumToken.KeyFrameRuleNodeType:
152
- // default:
153
- //
154
- // throw new Error(`Not implemented: ${node.typ}`);
155
124
  }
156
125
  return {
157
126
  valid: SyntaxValidationResult.Valid,
@@ -193,8 +162,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
193
162
  context
194
163
  };
195
164
  }
196
- // console.error(`>> ${syntaxes.reduce((acc, curr) => acc + renderSyntax(curr), '')}\n>> ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
197
- // console.error(new Error('doEvaluateSyntax'));
198
165
  for (; i < syntaxes.length; i++) {
199
166
  syntax = syntaxes[i];
200
167
  if (context.done()) {
@@ -205,7 +172,7 @@ function doEvaluateSyntax(syntaxes, context, options) {
205
172
  }
206
173
  token = context.peek();
207
174
  // if var() is the last token, then match the remaining syntax and return
208
- if (context.length == 1 && token.typ == EnumToken.FunctionTokenType && 'var'.localeCompare(token.val, undefined, { sensitivity: 'base' }) == 0) {
175
+ if (context.length == 1 && token.typ == EnumToken.FunctionTokenType && 'var' === token.val?.toLowerCase?.()) {
209
176
  return doEvaluateSyntax(getParsedSyntax("functions" /* ValidationSyntaxGroupEnum.Functions */, 'var')?.[0]?.chi ?? [], createContext(token.chi), options);
210
177
  }
211
178
  if (syntax.typ == ValidationTokenEnum.Whitespace) {
@@ -312,16 +279,6 @@ function matchList(syntax, context, options) {
312
279
  while (!con.done() && con.peek()?.typ != EnumToken.CommaTokenType) {
313
280
  tokens.push(con.next());
314
281
  }
315
- // if (tokens.length == 0) {
316
- //
317
- // return {
318
- // valid: SyntaxValidationResult.Drop,
319
- // node: context.peek(),
320
- // syntax,
321
- // error: `could not match syntax: ${renderSyntax(syntax)}`,
322
- // context
323
- // }
324
- // }
325
282
  result = doEvaluateSyntax([syntax], createContext(tokens), {
326
283
  ...options,
327
284
  isList: false,
@@ -406,22 +363,6 @@ function match(syntax, context, options) {
406
363
  };
407
364
  }
408
365
  }
409
- // if (token.typ == EnumToken.WhitespaceTokenType) {
410
- //
411
- // context.next();
412
- //
413
- // // @ts-ignore
414
- // if (syntax?.typ == ValidationTokenEnum.Whitespace) {
415
- //
416
- // return {
417
- // valid: SyntaxValidationResult.Valid,
418
- // node: null,
419
- // syntax,
420
- // error: '',
421
- // context
422
- // }
423
- // }
424
- // }
425
366
  if (syntax.typ != ValidationTokenEnum.PropertyType && (token?.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val))) {
426
367
  const result = doEvaluateSyntax(getParsedSyntax("functions" /* ValidationSyntaxGroupEnum.Functions */, token.val)?.[0]?.chi ?? [], createContext(token.chi), {
427
368
  ...options,
@@ -439,7 +380,7 @@ function match(syntax, context, options) {
439
380
  case ValidationTokenEnum.Keyword:
440
381
  success = (token.typ == EnumToken.IdenTokenType || token.typ == EnumToken.DashedIdenTokenType || isIdentColor(token)) &&
441
382
  (token.val == syntax.val ||
442
- syntax.val.localeCompare(token.val, undefined, { sensitivity: 'base' }) == 0 ||
383
+ syntax.val === token.val?.toLowerCase?.() ||
443
384
  // config.declarations.all
444
385
  allValues.includes(token.val.toLowerCase()));
445
386
  if (success) {
@@ -467,7 +408,6 @@ function match(syntax, context, options) {
467
408
  };
468
409
  }
469
410
  result = match(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()')?.[0], context, options);
470
- // console.error(`>>[]
471
411
  if (result.valid == SyntaxValidationResult.Valid) {
472
412
  context.next();
473
413
  result.context = context;
@@ -482,49 +422,12 @@ function match(syntax, context, options) {
482
422
  occurence: null,
483
423
  atLeastOnce: null
484
424
  });
485
- // case ValidationTokenEnum.Parens:
486
- //
487
- // token = context.peek() as Token;
488
- // if (token.typ != EnumToken.ParensTokenType) {
489
- //
490
- // break;
491
- // }
492
- //
493
- // success = doEvaluateSyntax((syntax as ValidationParensToken).chi as ValidationToken[], createContext((token as ParensToken).chi), {
494
- // ...options,
495
- // isRepeatable: null,
496
- // isList: null,
497
- // occurence: null,
498
- // atLeastOnce: null
499
- // } as ValidationOptions).valid == SyntaxValidationResult.Valid;
500
- // break;
501
425
  case ValidationTokenEnum.Comma:
502
426
  success = context.peek()?.typ == EnumToken.CommaTokenType;
503
427
  if (success) {
504
428
  context.next();
505
429
  }
506
430
  break;
507
- // case ValidationTokenEnum.Number:
508
- //
509
- // success = context.peek<Token>()?.typ == EnumToken.NumberTokenType;
510
- //
511
- // if (success) {
512
- //
513
- // context.next();
514
- // }
515
- //
516
- // break;
517
- //
518
- // case ValidationTokenEnum.Whitespace:
519
- //
520
- // success = context.peek<Token>()?.typ == EnumToken.WhitespaceTokenType;
521
- //
522
- // if (success) {
523
- //
524
- // context.next();
525
- // }
526
- //
527
- // break;
528
431
  case ValidationTokenEnum.Separator:
529
432
  {
530
433
  const token = context.peek();
@@ -540,14 +443,7 @@ function match(syntax, context, options) {
540
443
  break;
541
444
  }
542
445
  if (syntax.typ == ValidationTokenEnum.Function) {
543
- success = funcLike.includes(token.typ) && syntax.val.localeCompare(token.val, undefined, { sensitivity: 'base' }) == 0 && doEvaluateSyntax(syntax.chi, createContext(token.chi), options).valid == SyntaxValidationResult.Valid;
544
- // console.error(`>> match: ${JSON.stringify({
545
- // syntax,
546
- // token,
547
- // // result,
548
- // tr2: syntax,
549
- // success
550
- // }, null, 1)}`);
446
+ success = funcLike.includes(token.typ) && syntax.val.toLowerCase() === token.val?.toLowerCase?.() && doEvaluateSyntax(syntax.chi, createContext(token.chi), options).valid == SyntaxValidationResult.Valid;
551
447
  if (success) {
552
448
  context.next();
553
449
  }
@@ -566,7 +462,6 @@ function match(syntax, context, options) {
566
462
  }
567
463
  break;
568
464
  }
569
- // throw new Error(`Not implemented: ${ValidationTokenEnum[syntax.typ] ?? syntax.typ} : ${renderSyntax(syntax)} : ${renderToken(context.peek() as Token)} : ${JSON.stringify(syntax, null, 1)} | ${JSON.stringify(context.peek(), null, 1)}`);
570
465
  }
571
466
  if (!success && token.typ == EnumToken.IdenTokenType && allValues.includes(token.val.toLowerCase())) {
572
467
  success = true;
@@ -679,7 +574,7 @@ function matchPropertyType(syntax, context, options) {
679
574
  token = context.peek();
680
575
  continue;
681
576
  }
682
- success = token.typ == EnumToken.LengthTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0');
577
+ success = token.typ == EnumToken.LengthTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0);
683
578
  if (!success) {
684
579
  break;
685
580
  }
@@ -729,14 +624,14 @@ function matchPropertyType(syntax, context, options) {
729
624
  success = token.typ == EnumToken.DashedIdenTokenType;
730
625
  break;
731
626
  case 'system-color':
732
- success = (token.typ == EnumToken.ColorTokenType && token.kin == ColorType.SYS) || (token.typ == EnumToken.IdenTokenType && token.val.localeCompare('currentcolor', 'en', { sensitivity: 'base' }) == 0) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
627
+ success = (token.typ == EnumToken.ColorTokenType && token.kin == ColorType.SYS) || (token.typ == EnumToken.IdenTokenType && 'currentcolor' === token.val.toLowerCase()) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
733
628
  break;
734
629
  case 'deprecated-system-color':
735
- success = (token.typ == EnumToken.ColorTokenType && token.kin == ColorType.DPSYS) || (token.typ == EnumToken.IdenTokenType && token.val.localeCompare('currentcolor', 'en', { sensitivity: 'base' }) == 0) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
630
+ success = (token.typ == EnumToken.ColorTokenType && token.kin == ColorType.DPSYS) || (token.typ == EnumToken.IdenTokenType && 'currentcolor' === token.val.toLowerCase()) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
736
631
  break;
737
632
  case 'color':
738
633
  case 'color-base':
739
- success = token.typ == EnumToken.ColorTokenType || (token.typ == EnumToken.IdenTokenType && token.val.localeCompare('currentcolor', 'en', { sensitivity: 'base' }) == 0) || (token.typ == EnumToken.IdenTokenType && token.val.localeCompare('transparent', 'en', { sensitivity: 'base' }) == 0) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
634
+ success = token.typ == EnumToken.ColorTokenType || (token.typ == EnumToken.IdenTokenType && 'currentcolor' === token.val.toLowerCase()) || (token.typ == EnumToken.IdenTokenType && 'transparent' === token.val.toLowerCase()) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
740
635
  if (!success && token.typ == EnumToken.FunctionTokenType && colorsFunc.includes(token.val)) {
741
636
  success = doEvaluateSyntax(getParsedSyntax("functions" /* ValidationSyntaxGroupEnum.Functions */, token.val)?.[0]?.chi, createContext(token.chi), {
742
637
  ...options,
@@ -777,19 +672,19 @@ function matchPropertyType(syntax, context, options) {
777
672
  }
778
673
  break;
779
674
  case 'angle':
780
- success = token.typ == EnumToken.AngleTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0') || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
675
+ success = token.typ == EnumToken.AngleTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0) || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
781
676
  break;
782
677
  case 'length':
783
- success = token.typ == EnumToken.LengthTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0') || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
678
+ success = token.typ == EnumToken.LengthTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0) || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
784
679
  break;
785
680
  case 'percentage':
786
- success = token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0') || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
681
+ success = token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0) || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
787
682
  break;
788
683
  case 'length-percentage':
789
- success = token.typ == EnumToken.LengthTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0') || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
684
+ success = token.typ == EnumToken.LengthTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0) || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
790
685
  break;
791
686
  case 'resolution':
792
- success = token.typ == EnumToken.ResolutionTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0') || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
687
+ success = token.typ == EnumToken.ResolutionTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0) || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
793
688
  break;
794
689
  case 'hash-token':
795
690
  success = token.typ == EnumToken.HashTokenType;
@@ -801,7 +696,7 @@ function matchPropertyType(syntax, context, options) {
801
696
  success = token.typ == EnumToken.TimeTokenType || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
802
697
  break;
803
698
  case 'zero':
804
- success = token.val == '0' || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
699
+ success = token.val == 0 || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
805
700
  break;
806
701
  case 'pseudo-element-selector':
807
702
  success = token.typ == EnumToken.PseudoElementTokenType;
@@ -821,9 +716,6 @@ function matchPropertyType(syntax, context, options) {
821
716
  }
822
717
  }
823
718
  break;
824
- // default:
825
- //
826
- // throw new Error(`Not implemented: ${ValidationTokenEnum[syntax.typ] ?? syntax.typ} : ${renderSyntax(syntax)}\n${JSON.stringify(syntax, null, 1)}`);
827
719
  }
828
720
  if (!success &&
829
721
  token.typ == EnumToken.FunctionTokenType &&
@@ -859,12 +751,7 @@ function someOf(syntaxes, context, options) {
859
751
  let success = false;
860
752
  const matched = [];
861
753
  for (i = 0; i < syntaxes.length; i++) {
862
- // if (context.peek<Token>()?.typ == EnumToken.WhitespaceTokenType) {
863
- //
864
- // context.next();
865
- // }
866
754
  result = doEvaluateSyntax(syntaxes[i], context.clone(), options);
867
- // console.error(`>> someOf: ${JSON.stringify({result}, null, 1)}`);
868
755
  if (result.valid == SyntaxValidationResult.Valid) {
869
756
  success = true;
870
757
  if (result.context.done()) {
@@ -877,8 +764,6 @@ function someOf(syntaxes, context, options) {
877
764
  // pick the best match
878
765
  matched.sort((a, b) => a.context.done() ? -1 : b.context.done() ? 1 : b.context.index - a.context.index);
879
766
  }
880
- // console.error(JSON.stringify({matched}, null, 1));
881
- // console.error(new Error('someOf'));
882
767
  return matched[0] ?? {
883
768
  valid: SyntaxValidationResult.Drop,
884
769
  node: context.peek(),
@@ -934,10 +819,6 @@ function allOf(syntax, context, options) {
934
819
  for (i = 0; i < slice.length; i++) {
935
820
  if (slice[i].typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(slice[i].val.toLowerCase())) {
936
821
  vars.push(slice[i]);
937
- // if (slice[i + 1]?.typ == EnumToken.WhitespaceTokenType) {
938
- //
939
- // vars.push(slice[++i]);
940
- // }
941
822
  continue;
942
823
  }
943
824
  if (slice[i].typ == EnumToken.CommaTokenType || (slice[i].typ == EnumToken.LiteralTokenType && slice[i].val == '/')) {
@@ -964,7 +845,6 @@ function allOf(syntax, context, options) {
964
845
  }
965
846
  while (!cp.done()) {
966
847
  result = doEvaluateSyntax(syntax[i], cp.clone(), { ...options, isOptional: false });
967
- // console.error(`>> allOf: syntaxes[${i}]: ${syntax[i].length} ${syntax[i].reduce((acc, curr) => acc + renderSyntax(curr), '')}\n>> ${cp.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}\n>> ${JSON.stringify({result}, null, 1)}`);
968
848
  if (result.valid == SyntaxValidationResult.Valid) {
969
849
  let end = slice.indexOf(cp.current());
970
850
  if (end == -1) {
@@ -13,17 +13,6 @@ import { splitTokenList } from '../utils/list.js';
13
13
  function validateComplexSelectorList(tokens, root, options) {
14
14
  tokens = tokens.slice();
15
15
  consumeWhitespace(tokens);
16
- // if (tokens.length == 0) {
17
- //
18
- // return {
19
- // valid: SyntaxValidationResult.Drop,
20
- // context: [],
21
- // // @ts-ignore
22
- // node: root,
23
- // syntax: null,
24
- // error: 'expecting complex selector list'
25
- // }
26
- // }
27
16
  let result = null;
28
17
  for (const t of splitTokenList(tokens)) {
29
18
  result = validateSelector(t, root, options);
@@ -12,18 +12,6 @@ function validateFamilyName(tokens, atRule) {
12
12
  let node;
13
13
  tokens = tokens.slice();
14
14
  consumeWhitespace(tokens);
15
- // if (tokens.length == 0) {
16
- //
17
- // // @ts-ignore
18
- // return {
19
- // valid: SyntaxValidationResult.Drop,
20
- // matches: [],
21
- // node: atRule,
22
- // syntax: null,
23
- // error: 'expected at-rule prelude',
24
- // tokens
25
- // } as ValidationSyntaxResult;
26
- // }
27
15
  if (tokens.length == 0 || tokens[0].typ == EnumToken.CommaTokenType) {
28
16
  // @ts-ignore
29
17
  return {
@@ -36,26 +24,6 @@ function validateFamilyName(tokens, atRule) {
36
24
  };
37
25
  }
38
26
  while (tokens.length > 0) {
39
- // @ts-ignore
40
- // if (tokens[0].typ == EnumToken.CommaTokenType) {
41
- //
42
- // node = tokens.shift() as Token;
43
- //
44
- // consumeWhitespace(tokens);
45
- //
46
- // if (tokens.length == 0) {
47
- //
48
- // // @ts-ignore
49
- // return {
50
- // valid: SyntaxValidationResult.Drop,
51
- // matches: [],
52
- // node,
53
- // syntax: null,
54
- // error: 'unexpected token',
55
- // tokens
56
- // } as ValidationSyntaxResult;
57
- // }
58
- // }
59
27
  node = tokens[0];
60
28
  if (![EnumToken.IdenTokenType, EnumToken.StringTokenType].includes(node.typ)) {
61
29
  // @ts-ignore
@@ -11,17 +11,6 @@ import '../../renderer/sourcemap/lib/encode.js';
11
11
 
12
12
  function validateKeyframeSelector(tokens, options) {
13
13
  consumeWhitespace(tokens);
14
- // if (tokens.length == 0) {
15
- //
16
- // // @ts-ignore
17
- // return {
18
- // valid: SyntaxValidationResult.Drop,
19
- // context: [],
20
- // node: null,
21
- // syntax: null,
22
- // error: 'expected keyframe selector'
23
- // }
24
- // }
25
14
  for (const t of splitTokenList(tokens)) {
26
15
  if (t.length != 1 || (t[0].typ != EnumToken.PercentageTokenType && !(t[0].typ == EnumToken.IdenTokenType && ['from', 'to', 'cover', 'contain', 'entry', 'exit', 'entry-crossing', 'exit-crossing'].includes(t[0].val)))) {
27
16
  return {
@@ -13,33 +13,7 @@ import { splitTokenList } from '../utils/list.js';
13
13
  function validateRelativeSelectorList(tokens, root, options) {
14
14
  tokens = tokens.slice();
15
15
  consumeWhitespace(tokens);
16
- // if (tokens.length == 0) {
17
- //
18
- // return {
19
- // valid: SyntaxValidationResult.Drop,
20
- // matches: [],
21
- // // @ts-ignore
22
- // node: root,
23
- // // @ts-ignore
24
- // syntax: null,
25
- // error: 'expecting relative selector list',
26
- // tokens
27
- // }
28
- // }
29
16
  for (const t of splitTokenList(tokens)) {
30
- // if (t.length == 0) {
31
- //
32
- // return {
33
- // valid: SyntaxValidationResult.Drop,
34
- // matches: [],
35
- // // @ts-ignore
36
- // node: root,
37
- // // @ts-ignore
38
- // syntax: null,
39
- // error: 'unexpected comma',
40
- // tokens
41
- // }
42
- // }
43
17
  const result = validateRelativeSelector(t, root, options);
44
18
  if (result.valid == SyntaxValidationResult.Drop) {
45
19
  return result;
@@ -9,43 +9,10 @@ import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { consumeWhitespace } from '../utils/whitespace.js';
10
10
 
11
11
  function validateURL(token) {
12
- // if (token.typ == EnumToken.UrlTokenTokenType) {
13
- //
14
- // // @ts-ignore
15
- // return {
16
- // valid: SyntaxValidationResult.Valid,
17
- // context: [],
18
- // node: token,
19
- // // @ts-ignore
20
- // syntax: 'url()',
21
- // error: ''
22
- // }
23
- // }
24
- // if (token.typ != EnumToken.UrlFunctionTokenType) {
25
- //
26
- // // @ts-ignore
27
- // return {
28
- // valid: SyntaxValidationResult.Drop,
29
- // context: [],
30
- // node: token,
31
- // // @ts-ignore
32
- // syntax: 'url()',
33
- // error: 'expected url()'
34
- // }
35
- // }
36
12
  const children = token.chi.slice();
37
13
  consumeWhitespace(children);
38
14
  if (children.length > 0 && [EnumToken.UrlTokenTokenType, EnumToken.StringTokenType, EnumToken.HashTokenType].includes(children[0].typ)) {
39
15
  children.shift();
40
- // @ts-ignore
41
- // return {
42
- // valid: SyntaxValidationResult.Drop,
43
- // context: [],
44
- // node: children[0] ?? token,
45
- // // @ts-ignore
46
- // syntax: 'url()',
47
- // error: 'expected url-token'
48
- // }
49
16
  }
50
17
  consumeWhitespace(children);
51
18
  if (children.length > 0) {
@@ -10,10 +10,6 @@ import '../../renderer/sourcemap/lib/encode.js';
10
10
  function stripCommaToken(tokenList) {
11
11
  let result = [];
12
12
  for (let i = 0; i < tokenList.length; i++) {
13
- // if (tokenList[i].typ == EnumToken.CommaTokenType && last != null && last.typ == EnumToken.CommaTokenType) {
14
- //
15
- // return null;
16
- // }
17
13
  if (tokenList[i].typ != EnumToken.WhitespaceTokenType) {
18
14
  tokenList[i];
19
15
  }
@@ -26,10 +22,6 @@ function stripCommaToken(tokenList) {
26
22
  }
27
23
  function splitTokenList(tokenList, split = [EnumToken.CommaTokenType]) {
28
24
  return tokenList.reduce((acc, curr) => {
29
- // if (curr.typ == EnumToken.CommentTokenType) {
30
- //
31
- // return acc;
32
- // }
33
25
  if (split.includes(curr.typ)) {
34
26
  acc.push([]);
35
27
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tbela99/css-parser",
3
3
  "description": "CSS parser for node and the browser",
4
- "version": "v1.2.0",
4
+ "version": "v1.3.0",
5
5
  "exports": {
6
6
  ".": "./dist/node/index.js",
7
7
  "./node": "./dist/node/index.js",