@tbela99/css-parser 1.4.1 → 1.4.3

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 (216) hide show
  1. package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  2. package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  3. package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  4. package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  5. package/.repl_history +4 -0
  6. package/CHANGELOG.md +168 -4
  7. package/README.md +82 -0
  8. package/badges/coverage.svg +20 -0
  9. package/deno.lock +2861 -0
  10. package/dist/config.json.js +33 -1
  11. package/dist/index-umd-web.js +24393 -18479
  12. package/dist/index.cjs +27430 -21519
  13. package/dist/index.d.ts +1403 -933
  14. package/dist/lib/ast/clone.d.ts +10 -0
  15. package/dist/lib/ast/clone.js +45 -0
  16. package/dist/lib/ast/expand.d.ts +14 -0
  17. package/dist/lib/ast/expand.js +89 -64
  18. package/dist/lib/ast/features/calc.d.ts +10 -0
  19. package/dist/lib/ast/features/calc.js +62 -24
  20. package/dist/lib/ast/features/if.d.ts +10 -0
  21. package/dist/lib/ast/features/if.js +215 -0
  22. package/dist/lib/ast/features/index.d.ts +6 -0
  23. package/dist/lib/ast/features/index.js +1 -0
  24. package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
  25. package/dist/lib/ast/features/inlinecssvariables.js +32 -27
  26. package/dist/lib/ast/features/prefix.d.ts +8 -0
  27. package/dist/lib/ast/features/prefix.js +68 -43
  28. package/dist/lib/ast/features/shorthand.d.ts +12 -0
  29. package/dist/lib/ast/features/shorthand.js +6 -9
  30. package/dist/lib/ast/features/transform.d.ts +10 -0
  31. package/dist/lib/ast/features/transform.js +9 -13
  32. package/dist/lib/ast/features/type.d.ts +15 -0
  33. package/dist/lib/ast/find.d.ts +165 -0
  34. package/dist/lib/ast/find.js +175 -0
  35. package/dist/lib/ast/math/expression.d.ts +18 -0
  36. package/dist/lib/ast/math/expression.js +140 -98
  37. package/dist/lib/ast/math/math.d.ts +6 -0
  38. package/dist/lib/ast/math/math.js +30 -41
  39. package/dist/lib/ast/minify.d.ts +19 -0
  40. package/dist/lib/ast/minify.js +543 -215
  41. package/dist/lib/ast/transform/compute.d.ts +8 -0
  42. package/dist/lib/ast/transform/compute.js +82 -69
  43. package/dist/lib/ast/transform/matrix.d.ts +22 -0
  44. package/dist/lib/ast/transform/matrix.js +12 -26
  45. package/dist/lib/ast/transform/minify.d.ts +5 -0
  46. package/dist/lib/ast/transform/minify.js +20 -20
  47. package/dist/lib/ast/transform/perspective.d.ts +3 -0
  48. package/dist/lib/ast/transform/perspective.js +1 -1
  49. package/dist/lib/ast/transform/rotate.d.ts +12 -0
  50. package/dist/lib/ast/transform/rotate.js +1 -1
  51. package/dist/lib/ast/transform/scale.d.ts +6 -0
  52. package/dist/lib/ast/transform/scale.js +1 -1
  53. package/dist/lib/ast/transform/skew.d.ts +4 -0
  54. package/dist/lib/ast/transform/skew.js +1 -1
  55. package/dist/lib/ast/transform/translate.d.ts +6 -0
  56. package/dist/lib/ast/transform/translate.js +1 -1
  57. package/dist/lib/ast/transform/utils.d.ts +9 -0
  58. package/dist/lib/ast/types.d.ts +903 -0
  59. package/dist/lib/ast/types.js +277 -23
  60. package/dist/lib/ast/walk.d.ts +162 -0
  61. package/dist/lib/ast/walk.js +116 -60
  62. package/dist/lib/fs/resolve.d.ts +20 -0
  63. package/dist/lib/fs/resolve.js +37 -45
  64. package/dist/lib/parser/declaration/list.d.ts +16 -0
  65. package/dist/lib/parser/declaration/list.js +26 -24
  66. package/dist/lib/parser/declaration/map.d.ts +15 -0
  67. package/dist/lib/parser/declaration/map.js +140 -95
  68. package/dist/lib/parser/declaration/set.d.ts +9 -0
  69. package/dist/lib/parser/declaration/set.js +30 -25
  70. package/dist/lib/parser/node.d.ts +7 -0
  71. package/dist/lib/parser/parse.d.ts +107 -0
  72. package/dist/lib/parser/parse.js +1454 -1445
  73. package/dist/lib/parser/tokenize.d.ts +57 -0
  74. package/dist/lib/parser/tokenize.js +557 -404
  75. package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
  76. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  77. package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
  78. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  79. package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
  80. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  81. package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
  82. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  83. package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
  84. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  85. package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
  86. package/dist/lib/parser/utils/at-rule-page.js +28 -0
  87. package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
  88. package/dist/lib/parser/utils/at-rule-support.js +366 -0
  89. package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
  90. package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
  91. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  92. package/dist/lib/parser/utils/at-rule.d.ts +13 -0
  93. package/dist/lib/parser/utils/at-rule.js +37 -0
  94. package/dist/lib/parser/utils/cache.d.ts +6 -0
  95. package/dist/lib/parser/utils/cache.js +19 -0
  96. package/dist/lib/parser/utils/config.d.ts +2 -0
  97. package/dist/lib/parser/utils/config.js +1 -0
  98. package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
  99. package/dist/lib/parser/utils/declaration.d.ts +18 -0
  100. package/dist/lib/parser/utils/declaration.js +569 -91
  101. package/dist/lib/parser/utils/eq.d.ts +1 -0
  102. package/dist/lib/parser/utils/hash.d.ts +21 -0
  103. package/dist/lib/parser/utils/hash.js +1 -1
  104. package/dist/lib/parser/utils/selector.d.ts +5 -0
  105. package/dist/lib/parser/utils/selector.js +476 -0
  106. package/dist/lib/parser/utils/text.d.ts +3 -0
  107. package/dist/lib/parser/utils/text.js +17 -1
  108. package/dist/lib/parser/utils/token.d.ts +14 -0
  109. package/dist/lib/parser/utils/token.js +102 -0
  110. package/dist/lib/parser/utils/type.d.ts +2 -0
  111. package/dist/lib/parser/utils/type.js +29 -18
  112. package/dist/lib/renderer/render.d.ts +28 -0
  113. package/dist/lib/renderer/render.js +421 -262
  114. package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
  115. package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
  116. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  117. package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
  118. package/dist/lib/syntax/color/a98rgb.js +8 -12
  119. package/dist/lib/syntax/color/cmyk.d.ts +10 -0
  120. package/dist/lib/syntax/color/cmyk.js +23 -21
  121. package/dist/lib/syntax/color/color-mix.d.ts +2 -0
  122. package/dist/lib/syntax/color/color-mix.js +88 -77
  123. package/dist/lib/syntax/color/color.d.ts +42 -0
  124. package/dist/lib/syntax/color/color.js +65 -68
  125. package/dist/lib/syntax/color/hex.d.ts +16 -0
  126. package/dist/lib/syntax/color/hex.js +27 -31
  127. package/dist/lib/syntax/color/hsl.d.ts +20 -0
  128. package/dist/lib/syntax/color/hsl.js +5 -12
  129. package/dist/lib/syntax/color/hsv.d.ts +2 -0
  130. package/dist/lib/syntax/color/hwb.d.ts +21 -0
  131. package/dist/lib/syntax/color/hwb.js +8 -21
  132. package/dist/lib/syntax/color/lab.d.ts +25 -0
  133. package/dist/lib/syntax/color/lab.js +20 -21
  134. package/dist/lib/syntax/color/lch.d.ts +23 -0
  135. package/dist/lib/syntax/color/lch.js +13 -15
  136. package/dist/lib/syntax/color/oklab.d.ts +22 -0
  137. package/dist/lib/syntax/color/oklab.js +20 -39
  138. package/dist/lib/syntax/color/oklch.d.ts +20 -0
  139. package/dist/lib/syntax/color/oklch.js +14 -16
  140. package/dist/lib/syntax/color/p3.d.ts +6 -0
  141. package/dist/lib/syntax/color/p3.js +0 -8
  142. package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
  143. package/dist/lib/syntax/color/rec2020.d.ts +2 -0
  144. package/dist/lib/syntax/color/rec2020.js +9 -13
  145. package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
  146. package/dist/lib/syntax/color/relativecolor.js +68 -41
  147. package/dist/lib/syntax/color/rgb.d.ts +20 -0
  148. package/dist/lib/syntax/color/rgb.js +14 -18
  149. package/dist/lib/syntax/color/srgb.d.ts +23 -0
  150. package/dist/lib/syntax/color/srgb.js +27 -26
  151. package/dist/lib/syntax/color/utils/components.d.ts +2 -0
  152. package/dist/lib/syntax/color/utils/components.js +30 -14
  153. package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
  154. package/dist/lib/syntax/color/utils/distance.js +1 -8
  155. package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
  156. package/dist/lib/syntax/color/xyz.d.ts +5 -0
  157. package/dist/lib/syntax/color/xyz.js +8 -20
  158. package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
  159. package/dist/lib/syntax/color/xyzd50.js +6 -20
  160. package/dist/lib/syntax/constants.d.ts +67 -0
  161. package/dist/lib/syntax/constants.js +436 -0
  162. package/dist/lib/syntax/syntax.d.ts +38 -0
  163. package/dist/lib/syntax/syntax.js +533 -568
  164. package/dist/lib/validation/config.d.ts +14 -0
  165. package/dist/lib/validation/config.js +72 -33
  166. package/dist/lib/validation/config.json.js +1159 -74
  167. package/dist/lib/validation/json.d.ts +2 -0
  168. package/dist/lib/validation/match.d.ts +38 -0
  169. package/dist/lib/validation/match.js +2985 -0
  170. package/dist/lib/validation/parser/parse.d.ts +8 -0
  171. package/dist/lib/validation/parser/parse.js +684 -935
  172. package/dist/lib/validation/parser/typedef.d.ts +95 -0
  173. package/dist/lib/validation/parser/typedef.js +100 -0
  174. package/dist/lib/validation/utils/list.d.ts +4 -0
  175. package/dist/lib/validation/utils/list.js +4 -11
  176. package/dist/lib/validation/utils/whitespace.d.ts +2 -0
  177. package/dist/lib/validation/utils/whitespace.js +2 -8
  178. package/dist/node.d.ts +207 -0
  179. package/dist/node.js +53 -47
  180. package/dist/web.d.ts +169 -0
  181. package/dist/web.js +50 -41
  182. package/package.json +18 -13
  183. package/playground/index.html +1328 -0
  184. package/playground/sw.js +55 -0
  185. package/playground/tree.js +176 -0
  186. package/dist/lib/syntax/color/utils/constants.js +0 -214
  187. package/dist/lib/syntax/utils.js +0 -70
  188. package/dist/lib/validation/at-rules/container.js +0 -342
  189. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  190. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  191. package/dist/lib/validation/at-rules/document.js +0 -89
  192. package/dist/lib/validation/at-rules/else.js +0 -5
  193. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  194. package/dist/lib/validation/at-rules/import.js +0 -150
  195. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  196. package/dist/lib/validation/at-rules/layer.js +0 -41
  197. package/dist/lib/validation/at-rules/media.js +0 -255
  198. package/dist/lib/validation/at-rules/namespace.js +0 -81
  199. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  200. package/dist/lib/validation/at-rules/page.js +0 -100
  201. package/dist/lib/validation/at-rules/supports.js +0 -295
  202. package/dist/lib/validation/at-rules/when.js +0 -185
  203. package/dist/lib/validation/atrule.js +0 -184
  204. package/dist/lib/validation/selector.js +0 -36
  205. package/dist/lib/validation/syntax.js +0 -1073
  206. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  207. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  208. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  209. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  210. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  211. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  212. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  213. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  214. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  215. package/dist/lib/validation/syntaxes/selector.js +0 -5
  216. package/dist/lib/validation/syntaxes/url.js +0 -40
@@ -38,7 +38,7 @@ var ValidationLevel;
38
38
  /**
39
39
  * validate selectors, at-rules and declarations
40
40
  */
41
- ValidationLevel[ValidationLevel["All"] = 7] = "All"; // selectors + at-rules + declarations
41
+ ValidationLevel[ValidationLevel["All"] = 7] = "All";
42
42
  })(ValidationLevel || (ValidationLevel = {}));
43
43
  /**
44
44
  * enum of all token types
@@ -374,7 +374,7 @@ var EnumToken;
374
374
  /**
375
375
  * invalid rule token type
376
376
  */
377
- EnumToken[EnumToken["InvalidRuleTokenType"] = 81] = "InvalidRuleTokenType";
377
+ EnumToken[EnumToken["InvalidRuleNodeType"] = 81] = "InvalidRuleNodeType";
378
378
  /**
379
379
  * invalid class selector token type
380
380
  */
@@ -386,7 +386,7 @@ var EnumToken;
386
386
  /**
387
387
  * invalid at rule token type
388
388
  */
389
- EnumToken[EnumToken["InvalidAtRuleTokenType"] = 84] = "InvalidAtRuleTokenType";
389
+ EnumToken[EnumToken["InvalidAtRuleNodeType"] = 84] = "InvalidAtRuleNodeType";
390
390
  /**
391
391
  * media query condition token type
392
392
  */
@@ -398,19 +398,19 @@ var EnumToken;
398
398
  /**
399
399
  * media feature only token type
400
400
  */
401
- EnumToken[EnumToken["MediaFeatureOnlyTokenType"] = 87] = "MediaFeatureOnlyTokenType";
401
+ EnumToken[EnumToken["OnlyTokenType"] = 87] = "OnlyTokenType";
402
402
  /**
403
403
  * media feature not token type
404
404
  */
405
- EnumToken[EnumToken["MediaFeatureNotTokenType"] = 88] = "MediaFeatureNotTokenType";
405
+ EnumToken[EnumToken["NotTokenType"] = 88] = "NotTokenType";
406
406
  /**
407
407
  * media feature and token type
408
408
  */
409
- EnumToken[EnumToken["MediaFeatureAndTokenType"] = 89] = "MediaFeatureAndTokenType";
409
+ EnumToken[EnumToken["AndTokenType"] = 89] = "AndTokenType";
410
410
  /**
411
411
  * media feature or token type
412
412
  */
413
- EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
413
+ EnumToken[EnumToken["OrTokenType"] = 90] = "OrTokenType";
414
414
  /**
415
415
  * pseudo page token type
416
416
  */
@@ -444,6 +444,172 @@ var EnumToken;
444
444
  * css variable declaration map token type
445
445
  */
446
446
  EnumToken[EnumToken["CssVariableDeclarationMapTokenType"] = 98] = "CssVariableDeclarationMapTokenType";
447
+ /**
448
+ * media range query token type
449
+ */
450
+ EnumToken[EnumToken["MediaRangeQueryTokenType"] = 99] = "MediaRangeQueryTokenType";
451
+ /**
452
+ * invalid media query token type
453
+ */
454
+ EnumToken[EnumToken["InvalidMediaQueryTokenType"] = 100] = "InvalidMediaQueryTokenType";
455
+ /**
456
+ * supports query condition token type
457
+ */
458
+ EnumToken[EnumToken["SupportsQueryConditionTokenType"] = 101] = "SupportsQueryConditionTokenType";
459
+ /**
460
+ * supports query unary condition token type
461
+ */
462
+ EnumToken[EnumToken["SupportsQueryUnaryConditionTokenType"] = 102] = "SupportsQueryUnaryConditionTokenType";
463
+ /**
464
+ * when else query condition token type
465
+ */
466
+ EnumToken[EnumToken["WhenElseQueryConditionTokenType"] = 103] = "WhenElseQueryConditionTokenType";
467
+ /**
468
+ * when else query unary condition token type
469
+ */
470
+ EnumToken[EnumToken["WhenElseUnaryConditionTokenType"] = 104] = "WhenElseUnaryConditionTokenType";
471
+ /**
472
+ * container style range token type
473
+ */
474
+ EnumToken[EnumToken["ContainerStyleRangeTokenType"] = 105] = "ContainerStyleRangeTokenType";
475
+ /**
476
+ * '*'
477
+ */
478
+ EnumToken[EnumToken["Star"] = 106] = "Star";
479
+ /**
480
+ * '+'
481
+ */
482
+ EnumToken[EnumToken["Plus"] = 107] = "Plus";
483
+ /**
484
+ * '~'
485
+ */
486
+ EnumToken[EnumToken["Tilda"] = 108] = "Tilda";
487
+ /**
488
+ * '|'
489
+ */
490
+ EnumToken[EnumToken["Pipe"] = 109] = "Pipe";
491
+ /**
492
+ * '::'
493
+ */
494
+ EnumToken[EnumToken["DoubleColonTokenType"] = 110] = "DoubleColonTokenType";
495
+ /**
496
+ * math function token type such as'calc(' etc.
497
+ */
498
+ EnumToken[EnumToken["MathFunctionTokenType"] = 111] = "MathFunctionTokenType";
499
+ /**
500
+ * transform function token type such as 'translate(' etc.
501
+ */
502
+ EnumToken[EnumToken["TransformFunctionTokenType"] = 112] = "TransformFunctionTokenType";
503
+ /**
504
+ * when function token type such as 'supports(' etc.
505
+ */
506
+ EnumToken[EnumToken["WhenElseFunctionTokenType"] = 113] = "WhenElseFunctionTokenType";
507
+ /**
508
+ * general enclosed function token type 'font-tech(' etc.
509
+ */
510
+ EnumToken[EnumToken["GeneralEnclosedFunctionTokenType"] = 114] = "GeneralEnclosedFunctionTokenType";
511
+ /**
512
+ * supports function token type such as 'at-rule('
513
+ */
514
+ EnumToken[EnumToken["SupportsFunctionTokenType"] = 115] = "SupportsFunctionTokenType";
515
+ /**
516
+ * container function token type such as 'style(' or 'scroll-state('
517
+ */
518
+ EnumToken[EnumToken["ContainerFunctionTokenType"] = 116] = "ContainerFunctionTokenType";
519
+ /**
520
+ * unrecognized node token type
521
+ */
522
+ EnumToken[EnumToken["RawNodeTokenType"] = 117] = "RawNodeTokenType";
523
+ /**
524
+ * media query boolean token type
525
+ * @media not ()
526
+ * @media only ()
527
+ */
528
+ EnumToken[EnumToken["MediaQueryUnaryFeatureTokenType"] = 118] = "MediaQueryUnaryFeatureTokenType";
529
+ /**
530
+ * grid template function token type such as 'minmax('
531
+ */
532
+ EnumToken[EnumToken["GridTemplateFuncTokenDefType"] = 119] = "GridTemplateFuncTokenDefType";
533
+ /**
534
+ * image function token type such as 'image(' etc.
535
+ */
536
+ EnumToken[EnumToken["ImageFunctionTokenDefType"] = 120] = "ImageFunctionTokenDefType";
537
+ /**
538
+ * function token type such as 'view(' etc.
539
+ */
540
+ EnumToken[EnumToken["TimelineFunctionTokenDefType"] = 121] = "TimelineFunctionTokenDefType";
541
+ /**
542
+ * function token type
543
+ */
544
+ EnumToken[EnumToken["FunctionTokenDefType"] = 122] = "FunctionTokenDefType";
545
+ /**
546
+ * timing function token type such as 'linear(' etc.
547
+ */
548
+ EnumToken[EnumToken["TimingFunctionTokenDefType"] = 123] = "TimingFunctionTokenDefType";
549
+ /**
550
+ * color function token type such as 'rgb(' etc.
551
+ */
552
+ EnumToken[EnumToken["ColorFunctionTokenDefType"] = 124] = "ColorFunctionTokenDefType";
553
+ /**
554
+ * math function token type such as 'calc(' etc.
555
+ */
556
+ EnumToken[EnumToken["MathFunctionTokenDefType"] = 125] = "MathFunctionTokenDefType";
557
+ /**
558
+ * container function token type such as 'style(' or 'scroll-state('
559
+ */
560
+ EnumToken[EnumToken["ContainerFunctionTokenDefType"] = 126] = "ContainerFunctionTokenDefType";
561
+ /**
562
+ * url function token type 'url('
563
+ */
564
+ EnumToken[EnumToken["UrlFunctionTokenDefType"] = 127] = "UrlFunctionTokenDefType";
565
+ /**
566
+ * pseudo-class function token type
567
+ */
568
+ EnumToken[EnumToken["PseudoClassFunctionTokenDefType"] = 128] = "PseudoClassFunctionTokenDefType";
569
+ /**
570
+ * transform function token type such as 'translate(' etc.
571
+ */
572
+ EnumToken[EnumToken["TransformFunctionTokenDefType"] = 129] = "TransformFunctionTokenDefType";
573
+ /**
574
+ * when function token type such as 'supports(' or 'media('
575
+ */
576
+ EnumToken[EnumToken["WhenElseFunctionTokenDefType"] = 130] = "WhenElseFunctionTokenDefType";
577
+ /**
578
+ * general enclosed function token type 'font-tech(' etc.
579
+ */
580
+ EnumToken[EnumToken["GeneralEnclosedFunctionTokenDefType"] = 131] = "GeneralEnclosedFunctionTokenDefType";
581
+ /**
582
+ * supports function token type 'font-tech('
583
+ */
584
+ EnumToken[EnumToken["SupportsFunctionTokenDefType"] = 132] = "SupportsFunctionTokenDefType";
585
+ /**
586
+ * CDOCOMMTokenType not allowed in this context
587
+ */
588
+ EnumToken[EnumToken["InvalidCommentTokenType"] = 133] = "InvalidCommentTokenType";
589
+ /**
590
+ * custom function token type '--function-name('
591
+ */
592
+ EnumToken[EnumToken["CustomFunctionTokenDefType"] = 134] = "CustomFunctionTokenDefType";
593
+ /**
594
+ * custom function token type
595
+ */
596
+ EnumToken[EnumToken["CustomFunctionTokenType"] = 135] = "CustomFunctionTokenType";
597
+ /**
598
+ * function tokens such as 'var(', 'env(', 'if(')
599
+ */
600
+ EnumToken[EnumToken["WildCardFunctionTokenDefType"] = 136] = "WildCardFunctionTokenDefType";
601
+ /**
602
+ * function such as 'var()', 'env()', 'if()'
603
+ */
604
+ EnumToken[EnumToken["WildCardFunctionTokenType"] = 137] = "WildCardFunctionTokenType";
605
+ /**
606
+ * if condition token
607
+ */
608
+ EnumToken[EnumToken["IfConditionTokenType"] = 138] = "IfConditionTokenType";
609
+ /**
610
+ * if-Else condition token
611
+ */
612
+ EnumToken[EnumToken["IfElseConditionTokenType"] = 139] = "IfElseConditionTokenType";
447
613
  /* aliases */
448
614
  /**
449
615
  * alias for time token type
@@ -580,31 +746,31 @@ var ColorType;
580
746
  */
581
747
  ColorType[ColorType["RGBA"] = 4] = "RGBA";
582
748
  /**
583
- * colors as hsl values
749
+ * colors using rgb
584
750
  */
585
751
  ColorType[ColorType["HSLA"] = 5] = "HSLA";
586
752
  /**
587
- * colors as hwb values
753
+ * colors using hwb
588
754
  */
589
755
  ColorType[ColorType["HWB"] = 6] = "HWB";
590
756
  /**
591
- * colors as cmyk values
757
+ * colors using cmyk
592
758
  */
593
759
  ColorType[ColorType["CMYK"] = 7] = "CMYK";
594
760
  /**
595
- * colors as oklab values
761
+ * colors using oklab
596
762
  * */
597
763
  ColorType[ColorType["OKLAB"] = 8] = "OKLAB";
598
764
  /**
599
- * colors as oklch values
765
+ * colors using oklch
600
766
  * */
601
767
  ColorType[ColorType["OKLCH"] = 9] = "OKLCH";
602
768
  /**
603
- * colors as lab values
769
+ * colors using lab
604
770
  */
605
771
  ColorType[ColorType["LAB"] = 10] = "LAB";
606
772
  /**
607
- * colors as lch values
773
+ * colors using lch
608
774
  */
609
775
  ColorType[ColorType["LCH"] = 11] = "LCH";
610
776
  /**
@@ -612,35 +778,35 @@ var ColorType;
612
778
  */
613
779
  ColorType[ColorType["COLOR"] = 12] = "COLOR";
614
780
  /**
615
- * color using srgb values
781
+ * color using srgb
616
782
  */
617
783
  ColorType[ColorType["SRGB"] = 13] = "SRGB";
618
784
  /**
619
- * color using prophoto-rgb values
785
+ * color using prophoto-rgb
620
786
  */
621
787
  ColorType[ColorType["PROPHOTO_RGB"] = 14] = "PROPHOTO_RGB";
622
788
  /**
623
- * color using a98-rgb values
789
+ * color using a98-rgb
624
790
  */
625
791
  ColorType[ColorType["A98_RGB"] = 15] = "A98_RGB";
626
792
  /**
627
- * color using rec2020 values
793
+ * color using rec2020
628
794
  */
629
795
  ColorType[ColorType["REC2020"] = 16] = "REC2020";
630
796
  /**
631
- * color using display-p3 values
797
+ * color using display-p3
632
798
  */
633
799
  ColorType[ColorType["DISPLAY_P3"] = 17] = "DISPLAY_P3";
634
800
  /**
635
- * color using srgb-linear values
801
+ * color using srgb-linear
636
802
  */
637
803
  ColorType[ColorType["SRGB_LINEAR"] = 18] = "SRGB_LINEAR";
638
804
  /**
639
- * color using xyz-d50 values
805
+ * color using xyz-d50
640
806
  */
641
807
  ColorType[ColorType["XYZ_D50"] = 19] = "XYZ_D50";
642
808
  /**
643
- * color using xyz-d65 values
809
+ * color using xyz-d65
644
810
  */
645
811
  ColorType[ColorType["XYZ_D65"] = 20] = "XYZ_D65";
646
812
  /**
@@ -651,6 +817,14 @@ var ColorType;
651
817
  * color-mix() color function
652
818
  */
653
819
  ColorType[ColorType["COLOR_MIX"] = 22] = "COLOR_MIX";
820
+ /**
821
+ * non-standard color
822
+ */
823
+ ColorType[ColorType["NON_STD"] = 23] = "NON_STD";
824
+ /**
825
+ * custom color
826
+ */
827
+ ColorType[ColorType["CUSTOM_COLOR"] = 24] = "CUSTOM_COLOR";
654
828
  /**
655
829
  * alias for rgba
656
830
  */
@@ -709,6 +883,86 @@ var ModuleScopeEnumOptions;
709
883
  * export using ICSS module format
710
884
  */
711
885
  ModuleScopeEnumOptions[ModuleScopeEnumOptions["ICSS"] = 256] = "ICSS";
886
+ /**
887
+ * use the shortest name possible. pattern is ignored.
888
+ * it will produce names such as
889
+ *
890
+ * ```css
891
+ * .a {
892
+ * content: 'a';
893
+ * }
894
+ *
895
+ * .b {
896
+ * content: 'b';
897
+ * }
898
+ *
899
+ * .c {
900
+ * content: 'c';
901
+ * }
902
+ * ...
903
+ * ```
904
+ */
905
+ ModuleScopeEnumOptions[ModuleScopeEnumOptions["Shortest"] = 512] = "Shortest";
712
906
  })(ModuleScopeEnumOptions || (ModuleScopeEnumOptions = {}));
907
+ // https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
908
+ function length2Px(value) {
909
+ let result = null;
910
+ if (value.typ == EnumToken.NumberTokenType) {
911
+ result = +value.val;
912
+ }
913
+ else {
914
+ switch (value.unit) {
915
+ case "cm":
916
+ // @ts-ignore
917
+ result = value.val * 37.8;
918
+ break;
919
+ case "mm":
920
+ // @ts-ignore
921
+ result = value.val * 3.78;
922
+ break;
923
+ case "Q":
924
+ // @ts-ignore
925
+ result = (value.val * 37.8) / 40;
926
+ break;
927
+ case "in":
928
+ // @ts-ignore
929
+ result = value.val / 96;
930
+ break;
931
+ case "pc":
932
+ // @ts-ignore
933
+ result = value.val / 16;
934
+ break;
935
+ case "pt":
936
+ // @ts-ignore
937
+ result = (value.val * 4) / 3;
938
+ break;
939
+ case "px":
940
+ result = +value.val;
941
+ break;
942
+ }
943
+ }
944
+ return isNaN(result) ? null : result;
945
+ }
946
+ /**
947
+ * minify number
948
+ * @param val
949
+ */
950
+ function minifyNumber(val) {
951
+ val = String(val);
952
+ if (val === "0") {
953
+ return "0";
954
+ }
955
+ const chr = val.charAt(0);
956
+ if (chr == "-") {
957
+ const slice = val.slice(0, 2);
958
+ if (slice == "-0") {
959
+ return val.length == 2 ? "0" : "-" + val.slice(2);
960
+ }
961
+ }
962
+ if (chr == "0") {
963
+ return val.slice(1);
964
+ }
965
+ return val;
966
+ }
713
967
 
714
- export { ColorType, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, SyntaxValidationResult, ValidationLevel };
968
+ export { ColorType, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, SyntaxValidationResult, ValidationLevel, length2Px, minifyNumber };
@@ -0,0 +1,162 @@
1
+ import type { AstNode, Token, WalkAttributesResult, WalkerFilter, WalkerValueFilter, WalkResult } from "../../@types/index.d.ts";
2
+ import { EnumToken } from "./types.ts";
3
+ /**
4
+ * options for the walk function
5
+ */
6
+ export declare enum WalkerOptionEnum {
7
+ /**
8
+ * ignore the current node and its children
9
+ */
10
+ Ignore = 1,
11
+ /**
12
+ * stop walking the tree
13
+ */
14
+ Stop = 2,
15
+ /**
16
+ * ignore the current node and process its children
17
+ */
18
+ Children = 4,
19
+ /**
20
+ * ignore the current node children
21
+ */
22
+ IgnoreChildren = 8
23
+ }
24
+ /**
25
+ * event types for the walkValues function
26
+ */
27
+ export declare enum WalkerEvent {
28
+ /**
29
+ * enter node
30
+ */
31
+ Enter = 1,
32
+ /**
33
+ * leave node
34
+ */
35
+ Leave = 2
36
+ }
37
+ /**
38
+ * walk ast nodes
39
+ * @param node initial node
40
+ * @param filter control the walk process
41
+ * @param reverse walk in reverse order
42
+ *
43
+ * ```ts
44
+ *
45
+ * import {walk} from '@tbela99/css-parser';
46
+ *
47
+ * const css = `
48
+ * body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
49
+ *
50
+ * html,
51
+ * body {
52
+ * line-height: 1.474;
53
+ * }
54
+ *
55
+ * .ruler {
56
+ *
57
+ * height: 10px;
58
+ * }
59
+ * `;
60
+ *
61
+ * for (const {node, parent, root} of walk(ast)) {
62
+ *
63
+ * // do something with node
64
+ * }
65
+ * ```
66
+ *
67
+ * Using a {@link filter} function to control the ast traversal. the filter function returns a value of type {@link WalkerOption}.
68
+ *
69
+ * ```ts
70
+ * import {EnumToken, transform, walk, WalkerOptionEnum} from '@tbela99/css-parser';
71
+ *
72
+ * const css = `
73
+ * body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
74
+ *
75
+ * html,
76
+ * body {
77
+ * line-height: 1.474;
78
+ * }
79
+ *
80
+ * .ruler {
81
+ *
82
+ * height: 10px;
83
+ * }
84
+ * `;
85
+ *
86
+ * function filter(node) {
87
+ *
88
+ * if (node.typ == EnumToken.AstRule && node.sel.includes('html')) {
89
+ *
90
+ * // skip the children of the current node
91
+ * return WalkerOptionEnum.IgnoreChildren;
92
+ * }
93
+ * }
94
+ *
95
+ * const result = await transform(css);
96
+ * for (const {node} of walk(result.ast, filter)) {
97
+ *
98
+ * console.error([EnumToken[node.typ]]);
99
+ * }
100
+ *
101
+ * // [ "StyleSheetNodeType" ]
102
+ * // [ "RuleNodeType" ]
103
+ * // [ "DeclarationNodeType" ]
104
+ * // [ "RuleNodeType" ]
105
+ * // [ "DeclarationNodeType" ]
106
+ * // [ "RuleNodeType" ]
107
+ * // [ "DeclarationNodeType" ]
108
+ * ```
109
+ */
110
+ export declare function walk(node: AstNode, filter?: WalkerFilter | null, reverse?: boolean): Generator<WalkResult>;
111
+ /**
112
+ * walk ast node value tokens
113
+ * @param values
114
+ * @param root
115
+ * @param filter
116
+ * @param reverse
117
+ *
118
+ * Example:
119
+ *
120
+ * ```ts
121
+ *
122
+ * import {AstDeclaration, EnumToken, transform, walkValues} from '@tbela99/css-parser';
123
+ *
124
+ * const css = `
125
+ * body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
126
+ * `;
127
+ *
128
+ * const result = await transform(css);
129
+ * const declaration = result.ast.chi[0].chi[0] as AstDeclaration;
130
+ *
131
+ * // walk the node attribute's tokens in reverse order
132
+ * for (const {value} of walkValues(declaration.val, null, null,true)) {
133
+ *
134
+ * console.error([EnumToken[value.typ], value.val]);
135
+ * }
136
+ *
137
+ * // [ "Color", "color" ]
138
+ * // [ "FunctionTokenType", "calc" ]
139
+ * // [ "Number", 0.15 ]
140
+ * // [ "Add", undefined ]
141
+ * // [ "Iden", "b" ]
142
+ * // [ "Whitespace", undefined ]
143
+ * // [ "FunctionTokenType", "calc" ]
144
+ * // [ "Number", 0.24 ]
145
+ * // [ "Add", undefined ]
146
+ * // [ "Iden", "g" ]
147
+ * // [ "Whitespace", undefined ]
148
+ * // [ "Iden", "r" ]
149
+ * // [ "Whitespace", undefined ]
150
+ * // [ "Iden", "display-p3" ]
151
+ * // [ "Whitespace", undefined ]
152
+ * // [ "FunctionTokenType", "var" ]
153
+ * // [ "DashedIden", "--base-color" ]
154
+ * // [ "Whitespace", undefined ]
155
+ * // [ "Iden", "from" ]
156
+ * ```
157
+ */
158
+ export declare function walkValues(values: Token[], root?: AstNode | Token | null, filter?: WalkerValueFilter | null | {
159
+ event?: WalkerEvent;
160
+ fn?: WalkerValueFilter;
161
+ type?: EnumToken | EnumToken[] | ((token: Token) => boolean);
162
+ }, reverse?: boolean): Generator<WalkAttributesResult>;