@tbela99/css-parser 2.2.0 → 2.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 (117) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/{lib/ast → ast}/arena-node.js +1 -1
  3. package/dist/{lib/ast → ast}/arena.js +1 -1
  4. package/dist/{lib/ast → ast}/cache.js +39 -23
  5. package/dist/{lib/ast → ast}/features/calc.js +1 -1
  6. package/dist/{lib/ast → ast}/features/if.js +1 -1
  7. package/dist/ast/features/index.d.ts +7 -0
  8. package/dist/{lib/ast → ast}/features/index.js +1 -1
  9. package/dist/{lib/ast → ast}/features/inlinecssvariables.js +1 -1
  10. package/dist/{lib/ast → ast}/features/mixin.js +1 -1
  11. package/dist/{lib/ast → ast}/features/prefix.js +1 -1
  12. package/dist/{lib/ast → ast}/features/shorthand.js +1 -1
  13. package/dist/{lib/ast → ast}/features/transform.js +1 -1
  14. package/dist/{lib/ast → ast}/features/type.js +1 -1
  15. package/dist/{lib/ast → ast}/math/expression.js +1 -1
  16. package/dist/{lib/ast → ast}/math/math.js +1 -1
  17. package/dist/{lib/ast → ast}/minify.js +1 -1
  18. package/dist/{lib/ast → ast}/mixins/custom-function.js +1 -1
  19. package/dist/{lib/ast → ast}/mixins/utils.js +1 -1
  20. package/dist/{lib/ast → ast}/mixins/variables.js +1 -1
  21. package/dist/{lib/ast → ast}/strings.js +5 -1
  22. package/dist/{lib/ast → ast}/transform/compute.js +1 -1
  23. package/dist/{lib/ast → ast}/transform/matrix.js +1 -1
  24. package/dist/{lib/ast → ast}/transform/minify.js +1 -1
  25. package/dist/{lib/ast → ast}/transform/perspective.js +1 -1
  26. package/dist/{lib/ast → ast}/transform/rotate.js +1 -1
  27. package/dist/{lib/ast → ast}/transform/scale.js +1 -1
  28. package/dist/{lib/ast → ast}/transform/skew.js +1 -1
  29. package/dist/{lib/ast → ast}/transform/translate.js +1 -1
  30. package/dist/{lib/ast → ast}/transform/utils.js +1 -1
  31. package/dist/{lib/ast → ast}/types.js +1 -1
  32. package/dist/{lib/ast → ast}/walk.js +1 -1
  33. package/dist/data/properties.json.js +1 -1
  34. package/dist/data/validation.json.js +26 -20
  35. package/dist/{lib/fs → fs}/resolve.js +1 -1
  36. package/dist/index-umd-web.js +2755 -126
  37. package/dist/index.d.ts +6 -2
  38. package/dist/node.js +21 -21
  39. package/dist/{lib/parser → parser}/declaration/list.js +1 -1
  40. package/dist/{lib/parser → parser}/declaration/map.js +1 -1
  41. package/dist/{lib/parser → parser}/declaration/set.js +1 -1
  42. package/dist/{lib/parser → parser}/input.js +1 -1
  43. package/dist/{lib/parser → parser}/linesmap.js +1 -1
  44. package/dist/{lib/parser → parser}/parse.js +20 -21
  45. package/dist/{lib/parser → parser}/source.js +2 -2
  46. package/dist/{lib/parser → parser}/tokenize.js +1 -1
  47. package/dist/{lib/parser → parser}/utils/angle.js +1 -1
  48. package/dist/{lib/parser → parser}/utils/at-rule-container.js +1 -1
  49. package/dist/{lib/parser → parser}/utils/at-rule-font-feature-values.js +1 -1
  50. package/dist/{lib/parser → parser}/utils/at-rule-generic.js +1 -1
  51. package/dist/{lib/parser → parser}/utils/at-rule-import.js +1 -1
  52. package/dist/{lib/parser → parser}/utils/at-rule-media.js +1 -1
  53. package/dist/{lib/parser → parser}/utils/at-rule-support.js +1 -1
  54. package/dist/{lib/parser → parser}/utils/at-rule-when-else.js +1 -1
  55. package/dist/{lib/parser → parser}/utils/at-rule.js +1 -1
  56. package/dist/{lib/parser → parser}/utils/base64.js +1 -1
  57. package/dist/{lib/parser → parser}/utils/cache.js +1 -1
  58. package/dist/{lib/parser → parser}/utils/canonical.js +1 -1
  59. package/dist/{lib/parser → parser}/utils/codes.js +1 -1
  60. package/dist/{lib/parser → parser}/utils/config.js +2 -2
  61. package/dist/{lib/parser → parser}/utils/declaration.js +1 -1
  62. package/dist/{lib/parser → parser}/utils/eq.js +1 -1
  63. package/dist/{lib/parser → parser}/utils/hash.js +1 -1
  64. package/dist/{lib/parser → parser}/utils/selector.js +38 -28
  65. package/dist/{lib/parser → parser}/utils/text.js +1 -1
  66. package/dist/{lib/parser → parser}/utils/token.js +1 -1
  67. package/dist/{lib/parser → parser}/utils/type.js +1 -1
  68. package/dist/{lib/printer/sourcemap → printer}/lib/codec.js +1 -1
  69. package/dist/{lib/printer → printer}/render.js +184 -23
  70. package/dist/{lib/printer → printer}/result.js +1 -1
  71. package/dist/{lib/printer/sourcemap → printer}/sourcemap.js +3 -2
  72. package/dist/{lib/printer → printer}/writer.js +1 -1
  73. package/dist/{lib/syntax → syntax}/color/a98rgb.js +1 -1
  74. package/dist/{lib/syntax → syntax}/color/alpha.js +1 -1
  75. package/dist/{lib/syntax → syntax}/color/cmyk.js +1 -1
  76. package/dist/{lib/syntax → syntax}/color/color-mix.js +1 -1
  77. package/dist/{lib/syntax → syntax}/color/color.js +1 -1
  78. package/dist/{lib/syntax → syntax}/color/hex.js +1 -1
  79. package/dist/{lib/syntax → syntax}/color/hsl.js +1 -1
  80. package/dist/{lib/syntax → syntax}/color/hwb.js +1 -1
  81. package/dist/{lib/syntax → syntax}/color/lab.js +1 -1
  82. package/dist/{lib/syntax → syntax}/color/lch.js +1 -1
  83. package/dist/{lib/syntax → syntax}/color/oklab.js +1 -1
  84. package/dist/{lib/syntax → syntax}/color/oklch.js +1 -1
  85. package/dist/{lib/syntax → syntax}/color/p3.js +1 -1
  86. package/dist/{lib/syntax → syntax}/color/prophotorgb.js +1 -1
  87. package/dist/{lib/syntax → syntax}/color/rec2020.js +1 -1
  88. package/dist/{lib/syntax → syntax}/color/relative-color.js +1 -1
  89. package/dist/{lib/syntax → syntax}/color/rgb.js +1 -1
  90. package/dist/{lib/syntax → syntax}/color/srgb.js +1 -1
  91. package/dist/{lib/syntax → syntax}/color/utils/color-type.js +1 -1
  92. package/dist/{lib/syntax → syntax}/color/utils/colorspace.js +1 -1
  93. package/dist/{lib/syntax → syntax}/color/utils/components.js +1 -1
  94. package/dist/{lib/syntax → syntax}/color/utils/distance.js +1 -1
  95. package/dist/{lib/syntax → syntax}/color/utils/make-color.js +1 -1
  96. package/dist/{lib/syntax → syntax}/color/utils/matrix.js +1 -1
  97. package/dist/{lib/syntax → syntax}/color/xyz.js +1 -1
  98. package/dist/{lib/syntax → syntax}/color/xyzd50.js +1 -1
  99. package/dist/{lib/syntax → syntax}/constants.js +2 -2
  100. package/dist/{lib/syntax → syntax}/syntax.js +1 -1
  101. package/dist/types.js +1 -1
  102. package/dist/utils/sync.js +3 -3
  103. package/dist/validation/compiled/builtins.js +32 -0
  104. package/dist/validation/compiled/runtime.js +705 -0
  105. package/dist/validation/compiled/syntaxes.js +1620 -0
  106. package/dist/{lib/validation → validation}/config.js +41 -7
  107. package/dist/{lib/validation → validation}/first.js +6 -3
  108. package/dist/{lib/validation → validation}/match.js +87 -14
  109. package/dist/{lib/validation → validation}/parser/parse.js +1 -1
  110. package/dist/{lib/validation → validation}/parser/typedef.js +1 -1
  111. package/dist/{lib/validation → validation}/utils/list.js +1 -1
  112. package/dist/version.js +2 -2
  113. package/dist/web.js +23 -23
  114. package/package.json +4 -2
  115. package/dist/types.d.ts +0 -21
  116. package/dist/utils/sync.d.ts +0 -16
  117. package/dist/version.d.ts +0 -4
package/dist/index.d.ts CHANGED
@@ -1312,7 +1312,11 @@ declare const enum StringDerived {
1312
1312
  /**
1313
1313
  * the kind of a transform function name or of a transform property name (see `transformKind()`)
1314
1314
  */
1315
- TransformKind = 2
1315
+ TransformKind = 2,
1316
+ /**
1317
+ * true if the rules are allowed in the block of an at-rule (by name, without `@`), see `parseSelector()`
1318
+ */
1319
+ AtRuleAcceptsRules = 3
1316
1320
  }
1317
1321
  /**
1318
1322
  * structured-cloneable copy of a string table, see {@link StringTable.export}
@@ -8403,7 +8407,7 @@ declare function parseSyntax(syntax: string): ValidationToken$1[];
8403
8407
  /**
8404
8408
  * Version number
8405
8409
  */
8406
- declare const version = "2.2.0";
8410
+ declare const version = "2.3.0";
8407
8411
 
8408
8412
  /**
8409
8413
  * Load file or url
package/dist/node.js CHANGED
@@ -2,37 +2,37 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { Readable } from 'node:stream';
9
9
  import { createReadStream } from 'node:fs';
10
10
  import { lstat, readFile } from 'node:fs/promises';
11
- import { doParse, doParseSync } from './lib/parser/parse.js';
12
- export { parseDeclarations, parseString } from './lib/parser/parse.js';
13
- import { doRender } from './lib/printer/render.js';
14
- export { renderValue } from './lib/printer/render.js';
15
- import { TransformResult, RenderResult } from './lib/printer/result.js';
16
- import { useNativeBuffer } from './lib/printer/writer.js';
11
+ import { doParse, doParseSync } from './parser/parse.js';
12
+ export { parseDeclarations, parseString } from './parser/parse.js';
13
+ import { doRender } from './printer/render.js';
14
+ export { renderValue } from './printer/render.js';
15
+ import { TransformResult, RenderResult } from './printer/result.js';
16
+ import { useNativeBuffer } from './printer/writer.js';
17
17
  import { Buffer } from 'node:buffer';
18
- import { ModuleScopeEnumOptions } from './lib/ast/types.js';
19
- export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './lib/ast/types.js';
20
- import { createParseInfo, Tokenizer } from './lib/parser/tokenize.js';
21
- import { isCssInput } from './lib/parser/input.js';
22
- import { resolve, matchUrl, dirname } from './lib/fs/resolve.js';
18
+ import { ModuleScopeEnumOptions } from './ast/types.js';
19
+ export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './ast/types.js';
20
+ import { createParseInfo, Tokenizer } from './parser/tokenize.js';
21
+ import { isCssInput } from './parser/input.js';
22
+ import { resolve, matchUrl, dirname } from './fs/resolve.js';
23
23
  import { ResponseType } from './types.js';
24
24
  import { resolve as resolve$1 } from 'node:path';
25
- import { SourceFile } from './lib/parser/source.js';
25
+ import { SourceFile } from './parser/source.js';
26
26
  import { cwd } from 'node:process';
27
27
  import { validateSyncArguments, parseResult } from './utils/sync.js';
28
- export { minify } from './lib/ast/minify.js';
29
- export { convertColor } from './lib/syntax/color/color.js';
30
- export { isOkLabClose, okLabDistance } from './lib/syntax/color/utils/distance.js';
31
- export { Arena, AstArena, TokenField, arenaColumns } from './lib/ast/arena.js';
32
- export { ARENA, ARENAID, AstArenaNode } from './lib/ast/arena-node.js';
33
- export { SourceMap } from './lib/printer/sourcemap/sourcemap.js';
34
- export { FeatureWalkMode } from './lib/ast/features/type.js';
35
- export { parseSyntax } from './lib/validation/parser/parse.js';
28
+ export { minify } from './ast/minify.js';
29
+ export { convertColor } from './syntax/color/color.js';
30
+ export { isOkLabClose, okLabDistance } from './syntax/color/utils/distance.js';
31
+ export { Arena, AstArena, TokenField, arenaColumns } from './ast/arena.js';
32
+ export { ARENA, ARENAID, AstArenaNode } from './ast/arena-node.js';
33
+ export { SourceMap } from './printer/sourcemap.js';
34
+ export { FeatureWalkMode } from './ast/features/type.js';
35
+ export { parseSyntax } from './validation/parser/parse.js';
36
36
  export { version } from './version.js';
37
37
 
38
38
  // the rendered css is encoded with the node.js Buffer: faster than TextEncoder.encodeInto()
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { PropertySet } from './set.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { eqToken } from '../utils/eq.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { numericTokenTypes } from '../../ast/arena.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { nativeBufferClass } from '../printer/writer.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { isIdentColor, parseColor, isColor } from '../syntax/syntax.js';
@@ -11,7 +11,7 @@ import { renderValue } from '../printer/render.js';
11
11
  import { EnumToken, EnumAstNodeStatus, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent } from '../ast/types.js';
12
12
  import { minify } from '../ast/minify.js';
13
13
  import { Tokenizer, createParseInfo } from './tokenize.js';
14
- import { ResponseType } from '../../types.js';
14
+ import { ResponseType } from '../types.js';
15
15
  import { AstArena, TokenField } from '../ast/arena.js';
16
16
  import { AstArenaNode, ARENAID } from '../ast/arena-node.js';
17
17
  import { isFunctionDefType, tokensfuncDefMap, pageMarginBoxType } from '../syntax/constants.js';
@@ -242,13 +242,12 @@ function reject(reason) {
242
242
  * @private
243
243
  */
244
244
  const getKeyName = memoize((key, how) => {
245
- switch (how) {
246
- case ModuleCaseTransformEnum.CamelCase:
247
- case ModuleCaseTransformEnum.CamelCaseOnly:
248
- return camelize(key);
249
- case ModuleCaseTransformEnum.DashCase:
250
- case ModuleCaseTransformEnum.DashCaseOnly:
251
- return dasherize(key);
245
+ // the case transforms are flags
246
+ if (how & (ModuleCaseTransformEnum.CamelCase | ModuleCaseTransformEnum.CamelCaseOnly)) {
247
+ return camelize(key);
248
+ }
249
+ if (how & (ModuleCaseTransformEnum.DashCase | ModuleCaseTransformEnum.DashCaseOnly)) {
250
+ return dasherize(key);
252
251
  }
253
252
  return key;
254
253
  });
@@ -496,8 +495,8 @@ function parseVisitors(visitorsDef, errors) {
496
495
  valuesHandlers.get(EnumToken[key]).push(value);
497
496
  }
498
497
  else if (typeof value === "object") {
499
- if ("type" in value && "handler" in value && value.type in WalkerEvent) {
500
- if (value.type == WalkerEvent.Enter) {
498
+ if ("type" in value && "handler" in value && typeof value.type == "number" && (value.type & (WalkerEvent.Enter | WalkerEvent.Leave)) != 0) {
499
+ if (value.type & WalkerEvent.Enter) {
501
500
  if (!preValuesHandlers.has(EnumToken[key])) {
502
501
  preValuesHandlers.set(EnumToken[key], []);
503
502
  }
@@ -505,7 +504,7 @@ function parseVisitors(visitorsDef, errors) {
505
504
  .get(EnumToken[key])
506
505
  .push(value.handler);
507
506
  }
508
- else if (value.type == WalkerEvent.Leave) {
507
+ if (value.type & WalkerEvent.Leave) {
509
508
  if (!postValuesHandlers.has(EnumToken[key])) {
510
509
  postValuesHandlers.set(EnumToken[key], []);
511
510
  }
@@ -534,8 +533,8 @@ function parseVisitors(visitorsDef, errors) {
534
533
  .push(value);
535
534
  }
536
535
  else if (typeof value === "object") {
537
- if ("type" in value && "handler" in value && value.type in WalkerEvent) {
538
- if (value.type == WalkerEvent.Enter) {
536
+ if ("type" in value && "handler" in value && typeof value.type == "number" && (value.type & (WalkerEvent.Enter | WalkerEvent.Leave)) != 0) {
537
+ if (value.type & WalkerEvent.Enter) {
539
538
  if (!preVisitorsHandlersMap.has(key)) {
540
539
  preVisitorsHandlersMap.set(key, []);
541
540
  }
@@ -543,7 +542,7 @@ function parseVisitors(visitorsDef, errors) {
543
542
  .get(key)
544
543
  .push(value.handler);
545
544
  }
546
- else if (value.type == WalkerEvent.Leave) {
545
+ if (value.type & WalkerEvent.Leave) {
547
546
  if (!postVisitorsHandlersMap.has(key)) {
548
547
  postVisitorsHandlersMap.set(key, []);
549
548
  }
@@ -570,11 +569,11 @@ function parseVisitors(visitorsDef, errors) {
570
569
  allVisitorsHandlers.add(value);
571
570
  }
572
571
  else if (typeof value === "object") {
573
- if ("type" in value && "handler" in value && value.type in WalkerEvent) {
574
- if (value.type == WalkerEvent.Enter) {
572
+ if ("type" in value && "handler" in value && typeof value.type == "number" && (value.type & (WalkerEvent.Enter | WalkerEvent.Leave)) != 0) {
573
+ if (value.type & WalkerEvent.Enter) {
575
574
  preAllVisitorsHandlers.add(value.handler);
576
575
  }
577
- else if (value.type == WalkerEvent.Leave) {
576
+ if (value.type & WalkerEvent.Leave) {
578
577
  postAllVisitorsHandlers.add(value.handler);
579
578
  }
580
579
  }
@@ -1529,7 +1528,7 @@ function doParseSync(tokenizer, options = {}) {
1529
1528
  }
1530
1529
  }
1531
1530
  }
1532
- if (moduleSettings.naming !== ModuleCaseTransformEnum.IgnoreCase) {
1531
+ if ((moduleSettings.naming & ModuleCaseTransformEnum.IgnoreCase) == 0) {
1533
1532
  revMapping = {};
1534
1533
  mapping = {};
1535
1534
  let keyName;
@@ -2615,7 +2614,7 @@ async function doParse(iter, options = {}) {
2615
2614
  }
2616
2615
  }
2617
2616
  }
2618
- if (moduleSettings.naming !== ModuleCaseTransformEnum.IgnoreCase) {
2617
+ if ((moduleSettings.naming & ModuleCaseTransformEnum.IgnoreCase) == 0) {
2619
2618
  revMapping = {};
2620
2619
  mapping = Object.entries(mapping).reduce((acc, [key, value]) => {
2621
2620
  const keyName = getKeyName(key, moduleSettings.naming);
@@ -3377,7 +3376,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
3377
3376
  success = false;
3378
3377
  }
3379
3378
  else {
3380
- context = createValidationContext(arena, stream.slice(index));
3379
+ context = createValidationContext(arena, stream, index);
3381
3380
  // @ts-ignore
3382
3381
  range = context.peekRange((t) => arena.dataTypes[t] === EnumToken.EndParensTokenType);
3383
3382
  // inlined: arena.typeOf(range.at(-1))
@@ -2,10 +2,10 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
- import { SourceMap } from '../printer/sourcemap/sourcemap.js';
8
+ import { SourceMap } from '../printer/sourcemap.js';
9
9
  import { LineMap } from './linesmap.js';
10
10
 
11
11
  /**
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken, ColorType } from '../ast/types.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { TokenField } from '../../ast/arena.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { getSyntaxRule } from '../../validation/config.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { TokenField } from '../../ast/arena.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { TokenField } from '../../ast/arena.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -2,10 +2,10 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
- import config from '../../../data/properties.json.js';
8
+ import config from '../../data/properties.json.js';
9
9
 
10
10
  Object.freeze(config);
11
11
  // @ts-expect-error
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken, ColorType, EnumAstNodeStatus } from '../../ast/types.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  // Alphabet: a-z, A-Z, 0-9, _, -
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
@@ -10,8 +10,8 @@ import { StringBuilder } from '../../ast/strings.js';
10
10
  import { renderValue } from '../../printer/render.js';
11
11
  import { isFunctionDefType, tokensfuncDefMap, pseudoElements, combinators } from '../../syntax/constants.js';
12
12
  import { isHash, isIdent } from '../../syntax/syntax.js';
13
- import { getParsedSyntax, getSyntaxRule, getSyntaxConfig } from '../../validation/config.js';
14
- import { matchAllSyntaxes, createValidationContext, trimArray, matchSelectorSyntax } from '../../validation/match.js';
13
+ import { getParsedSyntax, getSyntaxRule } from '../../validation/config.js';
14
+ import { matchAllSyntaxes, createValidationContext, trimArray, selectorFunctionSyntax, matchSelectorSyntax } from '../../validation/match.js';
15
15
  import { ValidationSyntaxGroupEnum, ValidationTokenEnum } from '../../validation/parser/typedef.js';
16
16
  import { splitTokenList } from '../../validation/utils/list.js';
17
17
  import { trimWhiteSpace } from '../parse.js';
@@ -239,26 +239,12 @@ function parseSelector(arena, tokens, context, options, errors) {
239
239
  let index;
240
240
  let parent = context;
241
241
  let nested = false;
242
- let val;
243
242
  if (contextType !== EnumToken.StyleSheetNodeType && contextType !== EnumToken.RuleNodeType) {
244
243
  allowed = false;
245
244
  if (contextType === EnumToken.AtRuleNodeType) {
246
- const syntaxRule = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.resolveString(arena.name[context]));
247
- allowed = syntaxRule?.acceptAnyRule ?? false;
248
- if (!allowed) {
249
- const rules = syntaxRule?.getBlockRules?.();
250
- if (rules != null) {
251
- for (const rule of rules) {
252
- if (ValidationTokenEnum.PropertyType === rule.typ) {
253
- if ("block-contents" === rule.val ||
254
- "rule-list" === rule.val) {
255
- allowed = true;
256
- break;
257
- }
258
- }
259
- }
260
- }
261
- }
245
+ // computed once per at-rule name: the name is not concatenated for each selector
246
+ atRuleArena = arena;
247
+ allowed = arena.stringDerived(arena.name[context], 3 /* StringDerived.AtRuleAcceptsRules */, atRuleAcceptsRules);
262
248
  }
263
249
  }
264
250
  while (parent != null && parent > 0) {
@@ -293,13 +279,12 @@ function parseSelector(arena, tokens, context, options, errors) {
293
279
  continue;
294
280
  }
295
281
  if (arena.dataTypes[next] === EnumToken.FunctionTokenDefType) {
296
- val = ":" + arena.resolveString(arena.stringValue[next]);
282
+ // ":" + name, no string is created. `:name()` is a selector function: looked up once per name
283
+ arena.stringValue[token] = arena.internBuilder(arena.appendString(pseudoBuilder.reset().appendCode(0x3a), arena.stringValue[next]));
297
284
  arena.dataTypes[token] =
298
- val + "()" in getSyntaxConfig().selectors
285
+ selectorFunctionSyntax(arena, token) != null
299
286
  ? EnumToken.PseudoClassFunctionTokenDefType
300
287
  : arena.dataTypes[next];
301
- // inlined: arena.setStr(token, val)
302
- arena.stringValue[token] = arena.internString(val);
303
288
  arena.spanLocation(token, token, next);
304
289
  all[write++] = token;
305
290
  read++;
@@ -323,13 +308,12 @@ function parseSelector(arena, tokens, context, options, errors) {
323
308
  continue;
324
309
  }
325
310
  if (arena.dataTypes[next] === EnumToken.FunctionTokenDefType) {
326
- val = "::" + arena.resolveString(arena.stringValue[next]);
311
+ // "::" + name, no string is created
312
+ arena.stringValue[token] = arena.internBuilder(arena.appendString(pseudoBuilder.reset().appendCode(0x3a).appendCode(0x3a), arena.stringValue[next]));
327
313
  arena.dataTypes[token] =
328
- val + "()" in getSyntaxConfig().selectors
314
+ selectorFunctionSyntax(arena, token) != null
329
315
  ? EnumToken.PseudoClassFunctionTokenDefType
330
316
  : EnumToken.FunctionTokenDefType;
331
- // inlined: arena.setStr(token, val)
332
- arena.stringValue[token] = arena.internString(val);
333
317
  arena.spanLocation(token, token, next);
334
318
  all[write++] = token;
335
319
  read++;
@@ -431,6 +415,32 @@ const selectorRenderOptions = { minify: false };
431
415
  * builder of the pseudo classes and pseudo elements
432
416
  */
433
417
  const pseudoBuilder = new StringBuilder();
418
+ /**
419
+ * the arena of the at-rule names read by {@link atRuleAcceptsRules}: the function passed to the string table is not a
420
+ * closure
421
+ */
422
+ let atRuleArena = null;
423
+ /**
424
+ * true if the rules are allowed in the block of an at-rule, by name (see {@link StringDerived.AtRuleAcceptsRules})
425
+ * @param id the at-rule name
426
+ */
427
+ function atRuleAcceptsRules(id) {
428
+ const syntaxRule = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + atRuleArena.resolveString(id));
429
+ if (syntaxRule?.acceptAnyRule) {
430
+ return true;
431
+ }
432
+ const rules = syntaxRule?.getBlockRules?.();
433
+ if (rules != null) {
434
+ for (const rule of rules) {
435
+ if (ValidationTokenEnum.PropertyType === rule.typ &&
436
+ ("block-contents" === rule.val ||
437
+ "rule-list" === rule.val)) {
438
+ return true;
439
+ }
440
+ }
441
+ }
442
+ return false;
443
+ }
434
444
  /**
435
445
  * true if ":" + the string is a pseudo element with a single colon syntax (`:before`). the string is not created
436
446
  * @param arena
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.2.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  // from https://github.com/Rich-Harris/vlq/tree/master