@tbela99/css-parser 2.0.1 → 2.2.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 (128) hide show
  1. package/CHANGELOG.md +86 -1
  2. package/README.md +15 -7
  3. package/architecture.png +0 -0
  4. package/dist/{src/data → data}/properties.json.js +86 -2
  5. package/dist/{src/data → data}/validation.json.js +4848 -3750
  6. package/dist/index-umd-web.js +18234 -9498
  7. package/dist/index.d.ts +1251 -373
  8. package/dist/{src/lib → lib}/ast/arena-node.js +119 -57
  9. package/dist/{src/lib → lib}/ast/arena.js +1034 -655
  10. package/dist/{src/lib → lib}/ast/cache.js +36 -31
  11. package/dist/{src/lib → lib}/ast/features/calc.js +37 -27
  12. package/dist/{src/lib → lib}/ast/features/if.js +24 -19
  13. package/dist/{src/lib → lib}/ast/features/index.js +3 -2
  14. package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +42 -23
  15. package/dist/lib/ast/features/mixin.js +953 -0
  16. package/dist/{src/lib → lib}/ast/features/prefix.js +82 -69
  17. package/dist/lib/ast/features/shorthand.js +129 -0
  18. package/dist/lib/ast/features/transform.js +188 -0
  19. package/dist/{src/lib → lib}/ast/features/type.js +2 -2
  20. package/dist/{src/lib → lib}/ast/math/expression.js +150 -150
  21. package/dist/{src/lib → lib}/ast/math/math.js +8 -8
  22. package/dist/{src/lib → lib}/ast/minify.js +932 -354
  23. package/dist/lib/ast/mixins/custom-function.js +393 -0
  24. package/dist/lib/ast/mixins/utils.js +53 -0
  25. package/dist/lib/ast/mixins/variables.js +678 -0
  26. package/dist/lib/ast/strings.js +906 -0
  27. package/dist/lib/ast/transform/compute.js +560 -0
  28. package/dist/lib/ast/transform/matrix.js +67 -0
  29. package/dist/lib/ast/transform/minify.js +325 -0
  30. package/dist/lib/ast/transform/perspective.js +24 -0
  31. package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
  32. package/dist/lib/ast/transform/scale.js +43 -0
  33. package/dist/lib/ast/transform/skew.js +38 -0
  34. package/dist/lib/ast/transform/translate.js +56 -0
  35. package/dist/lib/ast/transform/utils.js +390 -0
  36. package/dist/{src/lib → lib}/ast/types.js +7 -15
  37. package/dist/{src/lib → lib}/ast/walk.js +19 -19
  38. package/dist/{src/lib → lib}/fs/resolve.js +15 -15
  39. package/dist/{src/lib → lib}/parser/declaration/list.js +55 -26
  40. package/dist/{src/lib → lib}/parser/declaration/map.js +85 -72
  41. package/dist/{src/lib → lib}/parser/declaration/set.js +32 -27
  42. package/dist/lib/parser/input.js +85 -0
  43. package/dist/{src/lib → lib}/parser/linesmap.js +3 -16
  44. package/dist/{src/lib → lib}/parser/parse.js +852 -619
  45. package/dist/lib/parser/source.js +71 -0
  46. package/dist/{src/lib → lib}/parser/tokenize.js +886 -722
  47. package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
  48. package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +68 -35
  49. package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
  50. package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +31 -13
  51. package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +29 -16
  52. package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +77 -58
  53. package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +18 -20
  54. package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +9 -8
  55. package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
  56. package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
  57. package/dist/lib/parser/utils/cache.js +53 -0
  58. package/dist/lib/parser/utils/canonical.js +78 -0
  59. package/dist/lib/parser/utils/codes.js +93 -0
  60. package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
  61. package/dist/{src/lib → lib}/parser/utils/declaration.js +67 -49
  62. package/dist/{src/lib → lib}/parser/utils/eq.js +14 -14
  63. package/dist/{src/lib → lib}/parser/utils/hash.js +4 -4
  64. package/dist/lib/parser/utils/selector.js +720 -0
  65. package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
  66. package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
  67. package/dist/{src/lib → lib}/parser/utils/type.js +11 -9
  68. package/dist/{src/lib → lib}/printer/render.js +536 -243
  69. package/dist/lib/printer/result.js +148 -0
  70. package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +5 -8
  71. package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +13 -13
  72. package/dist/lib/printer/writer.js +252 -0
  73. package/dist/{src/lib → lib}/syntax/color/a98rgb.js +6 -6
  74. package/dist/{src/lib → lib}/syntax/color/alpha.js +12 -11
  75. package/dist/{src/lib → lib}/syntax/color/cmyk.js +11 -6
  76. package/dist/{src/lib → lib}/syntax/color/color-mix.js +78 -67
  77. package/dist/{src/lib → lib}/syntax/color/color.js +52 -47
  78. package/dist/{src/lib → lib}/syntax/color/hex.js +17 -17
  79. package/dist/{src/lib → lib}/syntax/color/hsl.js +8 -8
  80. package/dist/{src/lib → lib}/syntax/color/hwb.js +6 -7
  81. package/dist/{src/lib → lib}/syntax/color/lab.js +8 -8
  82. package/dist/{src/lib → lib}/syntax/color/lch.js +12 -11
  83. package/dist/{src/lib → lib}/syntax/color/oklab.js +9 -9
  84. package/dist/{src/lib → lib}/syntax/color/oklch.js +5 -5
  85. package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
  86. package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +4 -4
  87. package/dist/{src/lib → lib}/syntax/color/rec2020.js +3 -3
  88. package/dist/{src/lib → lib}/syntax/color/relative-color.js +41 -34
  89. package/dist/{src/lib → lib}/syntax/color/rgb.js +17 -17
  90. package/dist/{src/lib → lib}/syntax/color/srgb.js +20 -20
  91. package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +6 -4
  92. package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +12 -14
  93. package/dist/{src/lib → lib}/syntax/color/utils/components.js +13 -13
  94. package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
  95. package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +6 -4
  96. package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
  97. package/dist/{src/lib → lib}/syntax/color/xyz.js +5 -10
  98. package/dist/{src/lib → lib}/syntax/color/xyzd50.js +3 -3
  99. package/dist/{src/lib → lib}/syntax/constants.js +30 -3
  100. package/dist/{src/lib → lib}/syntax/syntax.js +151 -116
  101. package/dist/lib/validation/config.js +173 -0
  102. package/dist/lib/validation/first.js +571 -0
  103. package/dist/{src/lib → lib}/validation/match.js +1256 -579
  104. package/dist/{src/lib → lib}/validation/parser/parse.js +85 -59
  105. package/dist/{src/lib → lib}/validation/parser/typedef.js +6 -2
  106. package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
  107. package/dist/{src/node.js → node.js} +92 -80
  108. package/dist/{src/types.js → types.js} +2 -2
  109. package/dist/{src/utils → utils}/sync.js +13 -8
  110. package/dist/version.d.ts +4 -0
  111. package/dist/version.js +13 -0
  112. package/dist/{src/web.js → web.js} +80 -75
  113. package/package.json +13 -13
  114. package/dist/package.json.js +0 -10
  115. package/dist/src/lib/ast/features/shorthand.js +0 -87
  116. package/dist/src/lib/ast/features/transform.js +0 -85
  117. package/dist/src/lib/ast/transform/compute.js +0 -358
  118. package/dist/src/lib/ast/transform/matrix.js +0 -88
  119. package/dist/src/lib/ast/transform/minify.js +0 -267
  120. package/dist/src/lib/ast/transform/perspective.js +0 -16
  121. package/dist/src/lib/ast/transform/scale.js +0 -39
  122. package/dist/src/lib/ast/transform/skew.js +0 -30
  123. package/dist/src/lib/ast/transform/translate.js +0 -39
  124. package/dist/src/lib/ast/transform/utils.js +0 -287
  125. package/dist/src/lib/parser/source.js +0 -127
  126. package/dist/src/lib/parser/utils/cache.js +0 -54
  127. package/dist/src/lib/parser/utils/selector.js +0 -440
  128. package/dist/src/lib/validation/config.js +0 -120
@@ -1,14 +1,14 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.0.1
5
+ Version: 2.2.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
9
9
  import { LOC } from '../../syntax/constants.js';
10
10
  import { ValidationTokenEnum } from './typedef.js';
11
- import { isIdentStart, isIdent, parseDimension, isPseudo } from '../../syntax/syntax.js';
11
+ import { isIdentStart, parseDimension, isPseudo, isIdent } from '../../syntax/syntax.js';
12
12
 
13
13
  const SymbolsMapTokens = {
14
14
  "&&": ValidationTokenEnum.Ampersand,
@@ -48,7 +48,7 @@ const makeBinaryOp = new Map([
48
48
  */
49
49
  const symbolTypes = new Map();
50
50
  for (const [key, type] of Object.entries(SymbolsMapTokens)) {
51
- if (key.length == 1) {
51
+ if (key.length === 1) {
52
52
  symbolTypes.set(key.charCodeAt(0), type);
53
53
  }
54
54
  }
@@ -57,7 +57,7 @@ for (const [key, type] of Object.entries(SymbolsMapTokens)) {
57
57
  */
58
58
  const pairSymbols = new Map();
59
59
  for (const [key, type] of Object.entries(SymbolsMapTokens)) {
60
- if (key.length == 2) {
60
+ if (key.length === 2) {
61
61
  const list = pairSymbols.get(key.charCodeAt(0)) ?? [];
62
62
  list.push([key.charCodeAt(1), type]);
63
63
  pairSymbols.set(key.charCodeAt(0), list);
@@ -76,7 +76,7 @@ function pairSymbolType(syntax, index) {
76
76
  if (list != null) {
77
77
  const next = syntax.charCodeAt(index + 1);
78
78
  for (let k = 0; k < list.length; k++) {
79
- if (list[k][0] == next) {
79
+ if (list[k][0] === next) {
80
80
  return list[k][1];
81
81
  }
82
82
  }
@@ -109,7 +109,7 @@ function codePoints(str, start, end) {
109
109
  * @param str
110
110
  */
111
111
  function isDigits(str) {
112
- if (str.length == 0) {
112
+ if (str.length === 0) {
113
113
  return false;
114
114
  }
115
115
  for (let k = 0; k < str.length; k++) {
@@ -135,14 +135,15 @@ function getTokenType(token, loc) {
135
135
  }
136
136
  const first = token.charCodeAt(0);
137
137
  // " or '
138
- if (first == 34 || first == 39) {
138
+ if (first === 34 || first === 39) {
139
139
  return {
140
140
  typ: ValidationTokenEnum.StringToken,
141
141
  val: token,
142
142
  [LOC]: loc,
143
143
  };
144
144
  }
145
- if (isDigits(token)) {
145
+ // integer, optionally negative: range bounds such as `<integer [-∞,-1]>`
146
+ if (isDigits(token) || (first === 45 && isDigits(token.slice(1)))) {
146
147
  return {
147
148
  typ: ValidationTokenEnum.Number,
148
149
  val: Number(token),
@@ -168,7 +169,7 @@ function getTokenType(token, loc) {
168
169
  };
169
170
  }
170
171
  // @
171
- if (first == 64 && isIdent(token.slice(1))) {
172
+ if (first === 64 && isIdent(token.slice(1))) {
172
173
  return {
173
174
  typ: ValidationTokenEnum.AtRule,
174
175
  val: token.slice(1),
@@ -234,9 +235,9 @@ function tokenizeSyntax(syntax, position = {
234
235
  let code;
235
236
  let type;
236
237
  const bufferLength = () => prefix.length + bufferEnd - bufferStart;
237
- const buffer = () => prefix.length == 0 ? syntax.slice(bufferStart, bufferEnd) : prefix + syntax.slice(bufferStart, bufferEnd);
238
+ const buffer = () => prefix.length === 0 ? syntax.slice(bufferStart, bufferEnd) : prefix + syntax.slice(bufferStart, bufferEnd);
238
239
  const append = (index) => {
239
- if (bufferEnd == bufferStart) {
240
+ if (bufferEnd === bufferStart) {
240
241
  bufferStart = index;
241
242
  }
242
243
  bufferEnd = index + 1;
@@ -258,7 +259,7 @@ function tokenizeSyntax(syntax, position = {
258
259
  curCol++;
259
260
  curInd++;
260
261
  // <an+b>
261
- if (code == 60 && syntax.startsWith("an+b>", i + 1)) {
262
+ if (code === 60 && syntax.startsWith("an+b>", i + 1)) {
262
263
  if (bufferLength() > 0) {
263
264
  prefix = buffer();
264
265
  bufferStart = bufferEnd = 0;
@@ -288,17 +289,17 @@ function tokenizeSyntax(syntax, position = {
288
289
  continue;
289
290
  }
290
291
  // :
291
- if (code == 58) {
292
- if (syntax.charCodeAt(i + 1) == 58) {
292
+ if (code === 58) {
293
+ if (syntax.charCodeAt(i + 1) === 58) {
293
294
  if (isIdentStart(syntax.charCodeAt(i + 2)) ||
294
- (syntax.charCodeAt(i + 2) == 45 && isIdentStart(syntax.charCodeAt(i + 3)))) {
295
+ (syntax.charCodeAt(i + 2) === 45 && isIdentStart(syntax.charCodeAt(i + 3)))) {
295
296
  append(i);
296
297
  append(++i);
297
298
  continue;
298
299
  }
299
300
  }
300
301
  if (isIdentStart(syntax.charCodeAt(i + 1)) ||
301
- (syntax.charCodeAt(i + 1) == 45 && isIdentStart(syntax.charCodeAt(i + 2)))) {
302
+ (syntax.charCodeAt(i + 1) === 45 && isIdentStart(syntax.charCodeAt(i + 2)))) {
302
303
  append(i);
303
304
  continue;
304
305
  }
@@ -310,7 +311,7 @@ function tokenizeSyntax(syntax, position = {
310
311
  while (k + 1 < length && symbolTypes.get(syntax.charCodeAt(k + 1)) === ValidationTokenEnum.Whitespace) {
311
312
  k++;
312
313
  }
313
- if (k != i) {
314
+ if (k !== i) {
314
315
  curCol += k - i;
315
316
  curInd += k - i;
316
317
  i = k;
@@ -329,20 +330,19 @@ function tokenizeSyntax(syntax, position = {
329
330
  }
330
331
  switch (code) {
331
332
  // :
332
- case 58:
333
- if (isIdent(buffer())) {
334
- tokens.push({
335
- typ: ValidationTokenEnum.DeclarationNameToken,
336
- val: buffer(),
337
- [LOC]: { ind: posInd, lin: posLin, col: posCol },
338
- });
333
+ case 58: {
334
+ // `<ident-token> : <declaration-value>?`, `name: <value>`: the colon is a token
335
+ const loc = startToken();
336
+ if (bufferLength() > 0) {
337
+ tokens.push(getTokenType(buffer(), startToken()));
339
338
  clear();
340
- curCol++;
341
- curInd++;
342
- break;
343
339
  }
344
- append(i);
340
+ tokens.push({
341
+ typ: ValidationTokenEnum.Colon,
342
+ [LOC]: loc,
343
+ });
345
344
  break;
345
+ }
346
346
  // " and '
347
347
  case 34:
348
348
  case 39:
@@ -351,7 +351,7 @@ function tokenizeSyntax(syntax, position = {
351
351
  append(i);
352
352
  while (i + 1 < length) {
353
353
  append(++i);
354
- if (syntax.charCodeAt(i) == quote) {
354
+ if (syntax.charCodeAt(i) === quote) {
355
355
  break;
356
356
  }
357
357
  }
@@ -383,7 +383,7 @@ function tokenizeSyntax(syntax, position = {
383
383
  return tokens;
384
384
  }
385
385
  /**
386
- * parse mdn data syntax
386
+ * parse a css value definition syntax (webref)
387
387
  * @param syntax
388
388
  * @returns
389
389
  */
@@ -398,17 +398,17 @@ function parseSyntax(syntax) {
398
398
  tokens.push(token);
399
399
  switch (token.typ) {
400
400
  case ValidationTokenEnum.EOF:
401
- if (stack.at(-1)?.typ == ValidationTokenEnum.PipeToken) {
401
+ if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
402
402
  let index = tokens.lastIndexOf(stack.at(-1));
403
403
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
404
404
  stack.pop();
405
405
  }
406
- else if (stack.at(-1)?.typ == ValidationTokenEnum.AmpersandToken) {
406
+ else if (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken) {
407
407
  let index = tokens.lastIndexOf(stack.at(-1));
408
408
  stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
409
409
  stack.pop();
410
410
  }
411
- else if (stack.at(-1)?.typ == ValidationTokenEnum.ColumnToken) {
411
+ else if (stack.at(-1)?.typ === ValidationTokenEnum.ColumnToken) {
412
412
  let index = tokens.lastIndexOf(stack.at(-1));
413
413
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
414
414
  stack.pop();
@@ -417,10 +417,10 @@ function parseSyntax(syntax) {
417
417
  break;
418
418
  case ValidationTokenEnum.Pipe:
419
419
  {
420
- while (stack.at(-1)?.typ == ValidationTokenEnum.AmpersandToken ||
421
- stack.at(-1)?.typ == ValidationTokenEnum.ColumnToken) {
420
+ while (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken ||
421
+ stack.at(-1)?.typ === ValidationTokenEnum.ColumnToken) {
422
422
  let index = tokens.lastIndexOf(stack.at(-1));
423
- if (stack.at(-1)?.typ == ValidationTokenEnum.AmpersandToken) {
423
+ if (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken) {
424
424
  stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
425
425
  }
426
426
  else {
@@ -428,8 +428,8 @@ function parseSyntax(syntax) {
428
428
  }
429
429
  stack.pop();
430
430
  }
431
- let index = stack.length == 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
432
- if (stack.at(-1)?.typ != ValidationTokenEnum.PipeToken) {
431
+ let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
432
+ if (stack.at(-1)?.typ !== ValidationTokenEnum.PipeToken) {
433
433
  stack.push(Object.assign(token, {
434
434
  typ: ValidationTokenEnum.PipeToken,
435
435
  chi: [trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2))],
@@ -442,7 +442,7 @@ function parseSyntax(syntax) {
442
442
  break;
443
443
  case ValidationTokenEnum.Ampersand:
444
444
  {
445
- let index = stack.length == 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
445
+ let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
446
446
  if (stack.at(-1)?.typ === makeBinaryOp.get(token.typ)) {
447
447
  if (token.typ === ValidationTokenEnum.Ampersand) {
448
448
  stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
@@ -478,13 +478,13 @@ function parseSyntax(syntax) {
478
478
  break;
479
479
  case ValidationTokenEnum.Column:
480
480
  {
481
- let index = stack.length == 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
481
+ let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
482
482
  if (stack.at(-1)?.typ === makeBinaryOp.get(token.typ)) {
483
483
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
484
484
  tokens.pop();
485
485
  }
486
486
  else {
487
- if (index != -1) {
487
+ if (index !== -1) {
488
488
  stack.push(Object.assign(token, {
489
489
  typ: makeBinaryOp.get(token.typ),
490
490
  chi: [trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2))],
@@ -500,7 +500,7 @@ function parseSyntax(syntax) {
500
500
  }
501
501
  break;
502
502
  case ValidationTokenEnum.OpenParenthesis:
503
- if (tokens.at(-2)?.typ == ValidationTokenEnum.Keyword) {
503
+ if (tokens.at(-2)?.typ === ValidationTokenEnum.Keyword) {
504
504
  stack.push(Object.assign(tokens.at(-2), {
505
505
  typ: ValidationTokenEnum.Function,
506
506
  chi: [],
@@ -508,7 +508,7 @@ function parseSyntax(syntax) {
508
508
  tokens.pop();
509
509
  break;
510
510
  }
511
- if (tokens.at(-2)?.typ == ValidationTokenEnum.PseudoClassToken) {
511
+ if (tokens.at(-2)?.typ === ValidationTokenEnum.PseudoClassToken) {
512
512
  stack.push(Object.assign(tokens.at(-2), {
513
513
  typ: ValidationTokenEnum.PseudoClassFunctionToken,
514
514
  chi: [],
@@ -519,13 +519,13 @@ function parseSyntax(syntax) {
519
519
  stack.push(token);
520
520
  break;
521
521
  case ValidationTokenEnum.CloseParenthesis:
522
- if (stack.at(-1)?.typ == ValidationTokenEnum.PipeToken) {
522
+ if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
523
523
  let index = tokens.lastIndexOf(stack.at(-1));
524
524
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
525
525
  stack.pop();
526
526
  }
527
- if (stack.at(-1)?.typ == ValidationTokenEnum.OpenParenthesis ||
528
- (stack.at(-1)?.typ == ValidationTokenEnum.PropertyType &&
527
+ if (stack.at(-1)?.typ === ValidationTokenEnum.OpenParenthesis ||
528
+ (stack.at(-1)?.typ === ValidationTokenEnum.PropertyType &&
529
529
  stack.at(-1).val === "function-token")) {
530
530
  stack.pop();
531
531
  }
@@ -561,7 +561,7 @@ function parseSyntax(syntax) {
561
561
  tokens[tokens.length - 3].range = tokens[tokens.length - 2].range;
562
562
  }
563
563
  tokens.splice(tokens.length - 2, 2);
564
- if (tokens.at(-1).val == "function-token") {
564
+ if (tokens.at(-1).val === "function-token") {
565
565
  // consume the closing ')'
566
566
  stack.push(tokens.at(-1));
567
567
  }
@@ -587,19 +587,19 @@ function parseSyntax(syntax) {
587
587
  break;
588
588
  case ValidationTokenEnum.CloseBracket:
589
589
  while (true) {
590
- if (stack.at(-1).typ == ValidationTokenEnum.AmpersandToken) {
590
+ if (stack.at(-1).typ === ValidationTokenEnum.AmpersandToken) {
591
591
  let index = tokens.lastIndexOf(stack.at(-1));
592
592
  stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
593
593
  stack.pop();
594
594
  continue;
595
595
  }
596
- else if (stack.at(-1).typ == ValidationTokenEnum.ColumnToken) {
596
+ else if (stack.at(-1).typ === ValidationTokenEnum.ColumnToken) {
597
597
  let index = tokens.lastIndexOf(stack.at(-1));
598
598
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
599
599
  stack.pop();
600
600
  continue;
601
601
  }
602
- if (stack.at(-1).typ == ValidationTokenEnum.PipeToken) {
602
+ if (stack.at(-1).typ === ValidationTokenEnum.PipeToken) {
603
603
  let index = tokens.lastIndexOf(stack.at(-1));
604
604
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
605
605
  stack.pop();
@@ -614,6 +614,32 @@ function parseSyntax(syntax) {
614
614
  // }
615
615
  {
616
616
  let index = tokens.lastIndexOf(stack.at(-1));
617
+ // the lower bound of a range may be '-∞': <integer [-∞,-1]>
618
+ const isNegativeInfinity = tokens[index + 1]?.typ === ValidationTokenEnum.Keyword &&
619
+ tokens[index + 1].val === "-" &&
620
+ tokens[index + 2]?.typ === ValidationTokenEnum.InfinityToken;
621
+ if (isNegativeInfinity &&
622
+ (tokens[index - 2]?.typ === ValidationTokenEnum.Keyword ||
623
+ tokens[index - 2]?.typ === ValidationTokenEnum.StringToken) &&
624
+ tokens[index - 1]?.typ === ValidationTokenEnum.Whitespace &&
625
+ tokens[index + 3]?.typ === ValidationTokenEnum.Comma &&
626
+ (tokens[index + 4]?.typ === ValidationTokenEnum.Number ||
627
+ tokens[index + 4]?.typ === ValidationTokenEnum.Dimension ||
628
+ tokens[index + 4]?.typ === ValidationTokenEnum.InfinityToken) &&
629
+ tokens[index + 5]?.typ === ValidationTokenEnum.CloseBracket) {
630
+ stack.pop();
631
+ // a null bound is unbounded
632
+ Object.assign(tokens[index - 2], {
633
+ range: {
634
+ min: null,
635
+ max: tokens[index + 4]?.typ === ValidationTokenEnum.InfinityToken
636
+ ? null
637
+ : tokens[index + 4],
638
+ },
639
+ });
640
+ tokens.splice(index - 1, 8);
641
+ break;
642
+ }
617
643
  if ((tokens[index - 2]?.typ === ValidationTokenEnum.Keyword ||
618
644
  tokens[index - 2]?.typ === ValidationTokenEnum.StringToken) &&
619
645
  tokens[index - 1]?.typ === ValidationTokenEnum.Whitespace &&
@@ -672,13 +698,13 @@ function parseSyntax(syntax) {
672
698
  // stack.pop();
673
699
  // continue;
674
700
  // } else
675
- if (stack.at(-1).typ == ValidationTokenEnum.ColumnToken) {
701
+ if (stack.at(-1).typ === ValidationTokenEnum.ColumnToken) {
676
702
  let index = tokens.lastIndexOf(stack.at(-1));
677
703
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
678
704
  stack.pop();
679
705
  continue;
680
706
  }
681
- if (stack.at(-1)?.typ == ValidationTokenEnum.PipeToken) {
707
+ if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
682
708
  let index = tokens.lastIndexOf(stack.at(-1));
683
709
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
684
710
  stack.pop();
@@ -693,7 +719,7 @@ function parseSyntax(syntax) {
693
719
  let index = tokens.lastIndexOf(stack.at(-1));
694
720
  const slice = tokens.slice(index + 1, -1);
695
721
  if (slice.length === 1 || slice.length === 3) {
696
- if (slice[0].typ == ValidationTokenEnum.Number) {
722
+ if (slice[0].typ === ValidationTokenEnum.Number) {
697
723
  Object.assign(tokens[index - 1], {
698
724
  match: {
699
725
  min: slice[0],
@@ -715,7 +741,7 @@ function parseSyntax(syntax) {
715
741
  Object.assign(tokens[index - 1], {
716
742
  match: {
717
743
  min: slice[0],
718
- max: slice[2].typ == ValidationTokenEnum.InfinityToken
744
+ max: slice[2].typ === ValidationTokenEnum.InfinityToken
719
745
  ? Number.POSITIVE_INFINITY
720
746
  : slice[2],
721
747
  },
@@ -743,7 +769,7 @@ function parseSyntax(syntax) {
743
769
  // sliceIndex = tokens.length - 2;
744
770
  // } else
745
771
  // {
746
- isGroup = tokens.at(-3)?.typ == ValidationTokenEnum.Comma;
772
+ isGroup = tokens.at(-3)?.typ === ValidationTokenEnum.Comma;
747
773
  if (isGroup) {
748
774
  sliceIndex = tokens.length - 3;
749
775
  }
@@ -766,12 +792,12 @@ function parseSyntax(syntax) {
766
792
  // if (tokens.at(-2)?.isOptional && tokens.at(-2)!.typ !== ValidationTokenEnum.OptionalGroupToken) {
767
793
  // sliceIndex = tokens.length - 2;
768
794
  // } else
769
- if (tokens.at(-2).typ == ValidationTokenEnum.Whitespace &&
795
+ if (tokens.at(-2).typ === ValidationTokenEnum.Whitespace &&
770
796
  tokens.at(-3)?.isOptional &&
771
797
  tokens.at(-3).typ !== ValidationTokenEnum.OptionalGroupToken) {
772
798
  sliceIndex = tokens.length - 3;
773
799
  }
774
- if (sliceIndex != -1) {
800
+ if (sliceIndex !== -1) {
775
801
  if (tokens[sliceIndex].isList) {
776
802
  tokens.pop();
777
803
  }
@@ -801,7 +827,7 @@ function parseSyntax(syntax) {
801
827
  }
802
828
  }
803
829
  if (stack.length > 0) {
804
- if (stack.at(-1)?.typ == ValidationTokenEnum.PipeToken) {
830
+ if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
805
831
  let index = tokens.lastIndexOf(stack.at(-1));
806
832
  stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 1)));
807
833
  stack.pop();
@@ -1,8 +1,8 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.0.1
5
+ Version: 2.2.0
6
6
  License: MIT
7
7
  */
8
8
  var ValidationTokenEnum;
@@ -89,6 +89,10 @@ var ValidationSyntaxGroupEnum;
89
89
  ValidationSyntaxGroupEnum["Declarations"] = "declarations";
90
90
  ValidationSyntaxGroupEnum["Functions"] = "functions";
91
91
  ValidationSyntaxGroupEnum["Syntaxes"] = "syntaxes";
92
+ /**
93
+ * value types, keyed by their name without the angle brackets (`color` for `<color>`). referenced as {@link Syntaxes}
94
+ */
95
+ ValidationSyntaxGroupEnum["Types"] = "types";
92
96
  ValidationSyntaxGroupEnum["Selectors"] = "selectors";
93
97
  ValidationSyntaxGroupEnum["AtRules"] = "atRules";
94
98
  ValidationSyntaxGroupEnum["Units"] = "units";
@@ -1,28 +1,12 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.0.1
5
+ Version: 2.2.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
9
9
 
10
- /**
11
- * remove comma and comment tokens
12
- * @param arena
13
- * @param tokenList
14
- */
15
- function stripCommaToken(arena, tokenList) {
16
- let result = [];
17
- for (let i = 0; i < tokenList.length; i++) {
18
- const typ = arena.dataTypes[tokenList[i]];
19
- if (typ == EnumToken.CommentTokenType || typ == EnumToken.CommaTokenType) {
20
- continue;
21
- }
22
- result.push(tokenList[i]);
23
- }
24
- return result;
25
- }
26
10
  /**
27
11
  * split a token list
28
12
  * @param arena
@@ -47,4 +31,4 @@ function splitTokenList(arena, tokenList, split = [EnumToken.CommaTokenType], in
47
31
  return result;
48
32
  }
49
33
 
50
- export { splitTokenList, stripCommaToken };
34
+ export { splitTokenList };