@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
@@ -0,0 +1,95 @@
1
+ export declare enum ValidationTokenEnum {
2
+ Root = 0,
3
+ Keyword = 1,
4
+ PropertyType = 2,
5
+ DeclarationType = 3,
6
+ AtRule = 4,
7
+ FunctionDefinition = 5,
8
+ OpenBracket = 6,
9
+ CloseBracket = 7,
10
+ OpenParenthesis = 8,
11
+ CloseParenthesis = 9,
12
+ Comma = 10,
13
+ Pipe = 11,
14
+ Column = 12,
15
+ Star = 13,
16
+ OpenCurlyBrace = 14,
17
+ CloseCurlyBrace = 15,
18
+ HashMark = 16,
19
+ QuestionMark = 17,
20
+ Function = 18,
21
+ Number = 19,
22
+ Whitespace = 20,
23
+ Parenthesis = 21,
24
+ Bracket = 22,
25
+ Block = 23,
26
+ Plus = 24,
27
+ Separator = 25,
28
+ Exclamation = 26,
29
+ Ampersand = 27,
30
+ PipeToken = 28,
31
+ ColumnToken = 29,
32
+ AmpersandToken = 30,
33
+ Parens = 31,
34
+ PseudoClassToken = 32,
35
+ PseudoClassFunctionToken = 33,
36
+ StringToken = 34,
37
+ AtRuleDefinition = 35,
38
+ DeclarationNameToken = 36,
39
+ DeclarationDefinitionToken = 37,
40
+ SemiColon = 38,
41
+ Character = 39,
42
+ InfinityToken = 40,
43
+ LessThan = 41,
44
+ GreaterThan = 42,
45
+ /**
46
+ * end of token stream
47
+ */
48
+ EOF = 43,
49
+ /**
50
+ * optional group or tokens, used to group validation tokens
51
+ *
52
+ * ```ts
53
+ * // <bg-layer>#? , <final-bg-layer> -> [<bg-layer>#? ,]? <final-bg-layer>
54
+ * // , <angular-color-stop> ]#? -> [, <angular-color-stop> ]#?]?
55
+ * ```
56
+ */
57
+ OptionalGroupToken = 44,
58
+ /**
59
+ * dimension token
60
+ *
61
+ * ```ts
62
+ * // <time [0s,∞]> -> {
63
+ * // typ: ValidationTokenEnum.PropertyType
64
+ * // val: 'time',
65
+ * // range: {
66
+ * // min: ValidationNumberToken,
67
+ * // max: null | ValidationNumberToken | ValidationInfinityToken
68
+ * // }
69
+ * // }
70
+ * ```
71
+ */
72
+ Dimension = 45,
73
+ DisallowWhitespace = 46,
74
+ Colon = 47
75
+ }
76
+ export declare enum ValidationSyntaxGroupEnum {
77
+ Declarations = "declarations",
78
+ Functions = "functions",
79
+ Syntaxes = "syntaxes",
80
+ Selectors = "selectors",
81
+ AtRules = "atRules",
82
+ Units = "units",
83
+ Languages = "languages",
84
+ mediaFeatures = "mediaFeatures"
85
+ }
86
+ export declare enum MediaFeatureType {
87
+ BooleanType = "boolean",
88
+ IntergerType = "integer",
89
+ KeywordType = "keyword",
90
+ LengthType = "length",
91
+ NumberType = "number",
92
+ RatioType = "ratio",
93
+ ResolutionType = "resolution",
94
+ StringType = "string"
95
+ }
@@ -0,0 +1,100 @@
1
+ var ValidationTokenEnum;
2
+ (function (ValidationTokenEnum) {
3
+ ValidationTokenEnum[ValidationTokenEnum["Root"] = 0] = "Root";
4
+ ValidationTokenEnum[ValidationTokenEnum["Keyword"] = 1] = "Keyword";
5
+ ValidationTokenEnum[ValidationTokenEnum["PropertyType"] = 2] = "PropertyType";
6
+ ValidationTokenEnum[ValidationTokenEnum["DeclarationType"] = 3] = "DeclarationType";
7
+ ValidationTokenEnum[ValidationTokenEnum["AtRule"] = 4] = "AtRule";
8
+ ValidationTokenEnum[ValidationTokenEnum["FunctionDefinition"] = 5] = "FunctionDefinition";
9
+ ValidationTokenEnum[ValidationTokenEnum["OpenBracket"] = 6] = "OpenBracket";
10
+ ValidationTokenEnum[ValidationTokenEnum["CloseBracket"] = 7] = "CloseBracket";
11
+ ValidationTokenEnum[ValidationTokenEnum["OpenParenthesis"] = 8] = "OpenParenthesis";
12
+ ValidationTokenEnum[ValidationTokenEnum["CloseParenthesis"] = 9] = "CloseParenthesis";
13
+ ValidationTokenEnum[ValidationTokenEnum["Comma"] = 10] = "Comma";
14
+ ValidationTokenEnum[ValidationTokenEnum["Pipe"] = 11] = "Pipe";
15
+ ValidationTokenEnum[ValidationTokenEnum["Column"] = 12] = "Column";
16
+ ValidationTokenEnum[ValidationTokenEnum["Star"] = 13] = "Star";
17
+ ValidationTokenEnum[ValidationTokenEnum["OpenCurlyBrace"] = 14] = "OpenCurlyBrace";
18
+ ValidationTokenEnum[ValidationTokenEnum["CloseCurlyBrace"] = 15] = "CloseCurlyBrace";
19
+ ValidationTokenEnum[ValidationTokenEnum["HashMark"] = 16] = "HashMark";
20
+ ValidationTokenEnum[ValidationTokenEnum["QuestionMark"] = 17] = "QuestionMark";
21
+ ValidationTokenEnum[ValidationTokenEnum["Function"] = 18] = "Function";
22
+ ValidationTokenEnum[ValidationTokenEnum["Number"] = 19] = "Number";
23
+ ValidationTokenEnum[ValidationTokenEnum["Whitespace"] = 20] = "Whitespace";
24
+ ValidationTokenEnum[ValidationTokenEnum["Parenthesis"] = 21] = "Parenthesis";
25
+ ValidationTokenEnum[ValidationTokenEnum["Bracket"] = 22] = "Bracket";
26
+ ValidationTokenEnum[ValidationTokenEnum["Block"] = 23] = "Block";
27
+ ValidationTokenEnum[ValidationTokenEnum["Plus"] = 24] = "Plus";
28
+ ValidationTokenEnum[ValidationTokenEnum["Separator"] = 25] = "Separator";
29
+ ValidationTokenEnum[ValidationTokenEnum["Exclamation"] = 26] = "Exclamation";
30
+ ValidationTokenEnum[ValidationTokenEnum["Ampersand"] = 27] = "Ampersand";
31
+ ValidationTokenEnum[ValidationTokenEnum["PipeToken"] = 28] = "PipeToken";
32
+ ValidationTokenEnum[ValidationTokenEnum["ColumnToken"] = 29] = "ColumnToken";
33
+ ValidationTokenEnum[ValidationTokenEnum["AmpersandToken"] = 30] = "AmpersandToken";
34
+ ValidationTokenEnum[ValidationTokenEnum["Parens"] = 31] = "Parens";
35
+ ValidationTokenEnum[ValidationTokenEnum["PseudoClassToken"] = 32] = "PseudoClassToken";
36
+ ValidationTokenEnum[ValidationTokenEnum["PseudoClassFunctionToken"] = 33] = "PseudoClassFunctionToken";
37
+ ValidationTokenEnum[ValidationTokenEnum["StringToken"] = 34] = "StringToken";
38
+ ValidationTokenEnum[ValidationTokenEnum["AtRuleDefinition"] = 35] = "AtRuleDefinition";
39
+ ValidationTokenEnum[ValidationTokenEnum["DeclarationNameToken"] = 36] = "DeclarationNameToken";
40
+ ValidationTokenEnum[ValidationTokenEnum["DeclarationDefinitionToken"] = 37] = "DeclarationDefinitionToken";
41
+ ValidationTokenEnum[ValidationTokenEnum["SemiColon"] = 38] = "SemiColon";
42
+ ValidationTokenEnum[ValidationTokenEnum["Character"] = 39] = "Character";
43
+ ValidationTokenEnum[ValidationTokenEnum["InfinityToken"] = 40] = "InfinityToken";
44
+ ValidationTokenEnum[ValidationTokenEnum["LessThan"] = 41] = "LessThan";
45
+ ValidationTokenEnum[ValidationTokenEnum["GreaterThan"] = 42] = "GreaterThan";
46
+ /**
47
+ * end of token stream
48
+ */
49
+ ValidationTokenEnum[ValidationTokenEnum["EOF"] = 43] = "EOF";
50
+ /**
51
+ * optional group or tokens, used to group validation tokens
52
+ *
53
+ * ```ts
54
+ * // <bg-layer>#? , <final-bg-layer> -> [<bg-layer>#? ,]? <final-bg-layer>
55
+ * // , <angular-color-stop> ]#? -> [, <angular-color-stop> ]#?]?
56
+ * ```
57
+ */
58
+ ValidationTokenEnum[ValidationTokenEnum["OptionalGroupToken"] = 44] = "OptionalGroupToken";
59
+ /**
60
+ * dimension token
61
+ *
62
+ * ```ts
63
+ * // <time [0s,∞]> -> {
64
+ * // typ: ValidationTokenEnum.PropertyType
65
+ * // val: 'time',
66
+ * // range: {
67
+ * // min: ValidationNumberToken,
68
+ * // max: null | ValidationNumberToken | ValidationInfinityToken
69
+ * // }
70
+ * // }
71
+ * ```
72
+ */
73
+ ValidationTokenEnum[ValidationTokenEnum["Dimension"] = 45] = "Dimension";
74
+ ValidationTokenEnum[ValidationTokenEnum["DisallowWhitespace"] = 46] = "DisallowWhitespace";
75
+ ValidationTokenEnum[ValidationTokenEnum["Colon"] = 47] = "Colon";
76
+ })(ValidationTokenEnum || (ValidationTokenEnum = {}));
77
+ var ValidationSyntaxGroupEnum;
78
+ (function (ValidationSyntaxGroupEnum) {
79
+ ValidationSyntaxGroupEnum["Declarations"] = "declarations";
80
+ ValidationSyntaxGroupEnum["Functions"] = "functions";
81
+ ValidationSyntaxGroupEnum["Syntaxes"] = "syntaxes";
82
+ ValidationSyntaxGroupEnum["Selectors"] = "selectors";
83
+ ValidationSyntaxGroupEnum["AtRules"] = "atRules";
84
+ ValidationSyntaxGroupEnum["Units"] = "units";
85
+ ValidationSyntaxGroupEnum["Languages"] = "languages";
86
+ ValidationSyntaxGroupEnum["mediaFeatures"] = "mediaFeatures";
87
+ })(ValidationSyntaxGroupEnum || (ValidationSyntaxGroupEnum = {}));
88
+ var MediaFeatureType;
89
+ (function (MediaFeatureType) {
90
+ MediaFeatureType["BooleanType"] = "boolean";
91
+ MediaFeatureType["IntergerType"] = "integer";
92
+ MediaFeatureType["KeywordType"] = "keyword";
93
+ MediaFeatureType["LengthType"] = "length";
94
+ MediaFeatureType["NumberType"] = "number";
95
+ MediaFeatureType["RatioType"] = "ratio";
96
+ MediaFeatureType["ResolutionType"] = "resolution";
97
+ MediaFeatureType["StringType"] = "string";
98
+ })(MediaFeatureType || (MediaFeatureType = {}));
99
+
100
+ export { MediaFeatureType, ValidationSyntaxGroupEnum, ValidationTokenEnum };
@@ -0,0 +1,4 @@
1
+ import { EnumToken } from "../../ast/types.ts";
2
+ import type { Token } from "../../../@types/index.d.ts";
3
+ export declare function stripCommaToken(tokenList: Token[]): Token[] | null;
4
+ export declare function splitTokenList(tokenList: Token[], split?: EnumToken[], includeSplitToken?: boolean): Token[][];
@@ -1,18 +1,8 @@
1
1
  import { EnumToken } from '../../ast/types.js';
2
- import '../../ast/minify.js';
3
- import '../../ast/walk.js';
4
- import '../../parser/parse.js';
5
- import '../../parser/tokenize.js';
6
- import '../../parser/utils/config.js';
7
- import '../../syntax/color/utils/constants.js';
8
- import '../../renderer/sourcemap/lib/encode.js';
9
2
 
10
3
  function stripCommaToken(tokenList) {
11
4
  let result = [];
12
5
  for (let i = 0; i < tokenList.length; i++) {
13
- if (tokenList[i].typ != EnumToken.WhitespaceTokenType) {
14
- tokenList[i];
15
- }
16
6
  if (tokenList[i].typ == EnumToken.CommentTokenType || tokenList[i].typ == EnumToken.CommaTokenType) {
17
7
  continue;
18
8
  }
@@ -20,9 +10,12 @@ function stripCommaToken(tokenList) {
20
10
  }
21
11
  return result;
22
12
  }
23
- function splitTokenList(tokenList, split = [EnumToken.CommaTokenType]) {
13
+ function splitTokenList(tokenList, split = [EnumToken.CommaTokenType], includeSplitToken = false) {
24
14
  return tokenList.reduce((acc, curr) => {
25
15
  if (split.includes(curr.typ)) {
16
+ if (includeSplitToken && Array.isArray(acc[acc.length - 1])) {
17
+ acc[acc.length - 1].push(curr);
18
+ }
26
19
  acc.push([]);
27
20
  }
28
21
  else {
@@ -0,0 +1,2 @@
1
+ import type { Token } from "../../../@types/token.d.ts";
2
+ export declare function consumeWhitespace(tokens: Token[]): boolean;
@@ -1,11 +1,4 @@
1
1
  import { EnumToken } from '../../ast/types.js';
2
- import '../../ast/minify.js';
3
- import '../../ast/walk.js';
4
- import '../../parser/parse.js';
5
- import '../../parser/tokenize.js';
6
- import '../../parser/utils/config.js';
7
- import '../../syntax/color/utils/constants.js';
8
- import '../../renderer/sourcemap/lib/encode.js';
9
2
 
10
3
  function consumeWhitespace(tokens) {
11
4
  if (tokens.length == 0) {
@@ -14,7 +7,8 @@ function consumeWhitespace(tokens) {
14
7
  if (tokens[0].typ != EnumToken.WhitespaceTokenType && tokens[0].typ != EnumToken.DescendantCombinatorTokenType) {
15
8
  return false;
16
9
  }
17
- while (tokens.length > 0 && (tokens[0].typ == EnumToken.WhitespaceTokenType || tokens[0].typ == EnumToken.DescendantCombinatorTokenType)) {
10
+ while (tokens.length > 0 &&
11
+ (tokens[0].typ == EnumToken.WhitespaceTokenType || tokens[0].typ == EnumToken.DescendantCombinatorTokenType)) {
18
12
  tokens.shift();
19
13
  }
20
14
  return true;
package/dist/node.d.ts ADDED
@@ -0,0 +1,207 @@
1
+ import type { AstNode, ParseResult, ParserOptions, RenderOptions, RenderResult, TransformOptions, TransformResult } from "./@types/index.d.ts";
2
+ import { dirname, resolve } from "./lib/fs/resolve.ts";
3
+ import { ResponseType } from "./types.ts";
4
+ export type * from "./@types/index.d.ts";
5
+ export type * from "./@types/ast.d.ts";
6
+ export type * from "./@types/token.d.ts";
7
+ export type * from "./@types/parse.d.ts";
8
+ export type * from "./@types/validation.d.ts";
9
+ export type * from "./@types/walker.d.ts";
10
+ export type { AstNode, ParseResult, ParserOptions, RenderOptions, RenderResult, TransformOptions, TransformResult, } from "./@types/index.d.ts";
11
+ export { minify } from "./lib/ast/minify.ts";
12
+ export { expand } from "./lib/ast/expand.ts";
13
+ export { walk, walkValues, WalkerEvent, WalkerOptionEnum } from "./lib/ast/walk.ts";
14
+ export { parseString } from "./lib/parser/parse.ts";
15
+ export { renderToken } from "./lib/renderer/render.ts";
16
+ export { convertColor } from "./lib/syntax/color/color.ts";
17
+ export { isOkLabClose, okLabDistance } from "./lib/syntax/color/utils/distance.ts";
18
+ export { parseDeclarations } from "./lib/parser/parse.ts";
19
+ export { find, findLast, findByValue, findAll } from "./lib/ast/find.ts";
20
+ export { cloneNode } from "./lib/ast/clone.ts";
21
+ export { EnumToken, ColorType, ValidationLevel, ModuleScopeEnumOptions, ModuleCaseTransformEnum, } from "./lib/ast/types.ts";
22
+ export { SourceMap } from "./lib/renderer/sourcemap/sourcemap.ts";
23
+ export type { ValidationToken } from "./lib/validation/parser/types.d.ts";
24
+ export { FeatureWalkMode } from "./lib/ast/features/type.ts";
25
+ export { dirname, resolve, ResponseType };
26
+ /**
27
+ * load file or url
28
+ * @param url
29
+ * @param currentDirectory
30
+ * @param responseType
31
+ * @throws Error file not found
32
+ *
33
+ * ```ts
34
+ * import {load, ResponseType} from '@tbela99/css-parser';
35
+ * const result = await load(file, '.', ResponseType.ArrayBuffer) as ArrayBuffer;
36
+ * ```
37
+ */
38
+ export declare function load(url: string, currentDirectory?: string, responseType?: boolean | ResponseType): Promise<string | ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>>>;
39
+ /**
40
+ * render the ast tree
41
+ * @param data
42
+ * @param options
43
+ * @param mapping
44
+ *
45
+ * Example:
46
+ *
47
+ * ```ts
48
+ *
49
+ * import {render, ColorType} from '@tbela99/css-parser';
50
+ *
51
+ * const css = 'body { color: color(from hsl(0 100% 50%) xyz x y z); }';
52
+ * const parseResult = await parse(css);
53
+ *
54
+ * let renderResult = render(parseResult.ast);
55
+ * console.log(result.code);
56
+ *
57
+ * // body{color:red}
58
+ *
59
+ *
60
+ * renderResult = render(parseResult.ast, {beautify: true, convertColor: ColorType.SRGB});
61
+ * console.log(renderResult.code);
62
+ *
63
+ * // body {
64
+ * // color: color(srgb 1 0 0)
65
+ * // }
66
+ * ```
67
+ */
68
+ export declare function render(data: AstNode, options?: RenderOptions, mapping?: {
69
+ mapping: Record<string, string>;
70
+ importMapping: Record<string, Record<string, string>> | null;
71
+ } | null): RenderResult;
72
+ /**
73
+ * parse css file
74
+ * @param file url or path
75
+ * @param options
76
+ * @param asStream load file as stream
77
+ *
78
+ * @throws Error file not found
79
+ *
80
+ * Example:
81
+ *
82
+ * ```ts
83
+ *
84
+ * import {parseFile} from '@tbela99/css-parser';
85
+ *
86
+ * // remote file
87
+ * let result = await parseFile('https://docs.deno.com/styles.css');
88
+ * console.log(result.ast);
89
+ *
90
+ * // local file
91
+ * result = await parseFile('./css/styles.css');
92
+ * console.log(result.ast);
93
+ * ```
94
+ */
95
+ export declare function parseFile(file: string, options?: ParserOptions, asStream?: boolean): Promise<ParseResult>;
96
+ /**
97
+ * parse css
98
+ * @param stream
99
+ * @param options
100
+ *
101
+ * Example:
102
+ *
103
+ * ```ts
104
+ *
105
+ * import {parse} from '@tbela99/css-parser';
106
+ *
107
+ * // css string
108
+ * let result = await parse(css);
109
+ * console.log(result.ast);
110
+ * ```
111
+ *
112
+ * Example using stream
113
+ *
114
+ * ```ts
115
+ *
116
+ * import {parse} from '@tbela99/css-parser';
117
+ * import {Readable} from "node:stream";
118
+ *
119
+ * // usage: node index.ts < styles.css or cat styles.css | node index.ts
120
+ *
121
+ * const readableStream = Readable.toWeb(process.stdin);
122
+ * let result = await parse(readableStream, {beautify: true});
123
+ *
124
+ * console.log(result.ast);
125
+ * ```
126
+ *
127
+ * Example using fetch and readable stream
128
+ *
129
+ * ```ts
130
+ *
131
+ * import {parse} from '@tbela99/css-parser';
132
+ *
133
+ * const response = await fetch('https://docs.deno.com/styles.css');
134
+ * const result = await parse(response.body, {beautify: true});
135
+ *
136
+ * console.log(result.ast);
137
+ * ```
138
+ */
139
+ export declare function parse(stream: string | ReadableStream<Uint8Array>, options?: ParserOptions): Promise<ParseResult>;
140
+ /**
141
+ * transform css file
142
+ * @param file url or path
143
+ * @param options
144
+ * @param asStream load file as stream
145
+ *
146
+ * @throws Error file not found
147
+ *
148
+ * Example:
149
+ *
150
+ * ```ts
151
+ *
152
+ * import {transformFile} from '@tbela99/css-parser';
153
+ *
154
+ * // remote file
155
+ * let result = await transformFile('https://docs.deno.com/styles.css');
156
+ * console.log(result.code);
157
+ *
158
+ * // local file
159
+ * result = await transformFile('./css/styles.css');
160
+ * console.log(result.code);
161
+ * ```
162
+ */
163
+ export declare function transformFile(file: string, options?: TransformOptions, asStream?: boolean): Promise<TransformResult>;
164
+ /**
165
+ * transform css
166
+ * @param css
167
+ * @param options
168
+ *
169
+ * Example:
170
+ *
171
+ * ```ts
172
+ *
173
+ * import {transform} from '@tbela99/css-parser';
174
+ *
175
+ * // css string
176
+ * const result = await transform(css);
177
+ * console.log(result.code);
178
+ * ```
179
+ *
180
+ * Example using stream
181
+ *
182
+ * ```ts
183
+ *
184
+ * import {transform} from '@tbela99/css-parser';
185
+ * import {Readable} from "node:stream";
186
+ *
187
+ * // usage: node index.ts < styles.css or cat styles.css | node index.ts
188
+ *
189
+ * const readableStream = Readable.toWeb(process.stdin);
190
+ * const result = await transform(readableStream, {beautify: true});
191
+ *
192
+ * console.log(result.code);
193
+ * ```
194
+ *
195
+ * Example using fetch
196
+ *
197
+ * ```ts
198
+ *
199
+ * import {transform} from '@tbela99/css-parser';
200
+ *
201
+ * const response = await fetch('https://docs.deno.com/styles.css');
202
+ * result = await transform(response.body, {beautify: true});
203
+ *
204
+ * console.log(result.code);
205
+ * ```
206
+ */
207
+ export declare function transform(css: string | ReadableStream<Uint8Array>, options?: TransformOptions): Promise<TransformResult>;
package/dist/node.js CHANGED
@@ -1,42 +1,41 @@
1
1
  import process from 'node:process';
2
+ import { Readable } from 'node:stream';
3
+ import { createReadStream } from 'node:fs';
4
+ import { lstat, readFile } from 'node:fs/promises';
5
+ import { doParse } from './lib/parser/parse.js';
6
+ export { parseDeclarations, parseString } from './lib/parser/parse.js';
7
+ import { doRender } from './lib/renderer/render.js';
8
+ export { renderToken } from './lib/renderer/render.js';
2
9
  import { ModuleScopeEnumOptions } from './lib/ast/types.js';
3
10
  export { ColorType, EnumToken, ModuleCaseTransformEnum, ValidationLevel } from './lib/ast/types.js';
11
+ import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
12
+ import { resolve, matchUrl, dirname } from './lib/fs/resolve.js';
13
+ import { ResponseType } from './types.js';
4
14
  export { minify } from './lib/ast/minify.js';
5
- export { WalkerEvent, WalkerOptionEnum, walk, walkValues } from './lib/ast/walk.js';
6
15
  export { expand } from './lib/ast/expand.js';
7
- import { doRender } from './lib/renderer/render.js';
8
- export { renderToken } from './lib/renderer/render.js';
9
- export { SourceMap } from './lib/renderer/sourcemap/sourcemap.js';
10
- import { doParse } from './lib/parser/parse.js';
11
- export { parseDeclarations, parseString, parseTokens } from './lib/parser/parse.js';
12
- import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
13
- import './lib/parser/utils/config.js';
16
+ export { WalkerEvent, WalkerOptionEnum, walk, walkValues } from './lib/ast/walk.js';
14
17
  export { convertColor } from './lib/syntax/color/color.js';
15
- import './lib/syntax/color/utils/constants.js';
16
18
  export { isOkLabClose, okLabDistance } from './lib/syntax/color/utils/distance.js';
17
- import './lib/validation/config.js';
18
- import './lib/validation/parser/parse.js';
19
- import './lib/validation/syntaxes/complex-selector.js';
20
- import './lib/validation/syntax.js';
21
- import { resolve, matchUrl, dirname } from './lib/fs/resolve.js';
22
- import { Readable } from 'node:stream';
23
- import { createReadStream } from 'node:fs';
24
- import { readFile, lstat } from 'node:fs/promises';
25
- import { ResponseType } from './types.js';
19
+ export { find, findAll, findByValue, findLast } from './lib/ast/find.js';
20
+ export { cloneNode } from './lib/ast/clone.js';
21
+ export { SourceMap } from './lib/renderer/sourcemap/sourcemap.js';
26
22
  export { FeatureWalkMode } from './lib/ast/features/type.js';
27
23
 
28
24
  /**
29
- * load file or url as stream
25
+ * load file or url
30
26
  * @param url
31
- * @param currentFile
27
+ * @param currentDirectory
32
28
  * @param responseType
33
29
  * @throws Error file not found
34
30
  *
35
- * @private
31
+ * ```ts
32
+ * import {load, ResponseType} from '@tbela99/css-parser';
33
+ * const result = await load(file, '.', ResponseType.ArrayBuffer) as ArrayBuffer;
34
+ * ```
36
35
  */
37
- async function load(url, currentFile = '.', responseType = false) {
38
- const resolved = resolve(url, currentFile);
39
- if (typeof responseType == 'boolean') {
36
+ async function load(url, currentDirectory = ".", responseType = false) {
37
+ const resolved = resolve(url, currentDirectory);
38
+ if (typeof responseType == "boolean") {
40
39
  responseType = responseType ? ResponseType.ReadableStream : ResponseType.Text;
41
40
  }
42
41
  if (matchUrl.test(resolved.absolute)) {
@@ -47,21 +46,23 @@ async function load(url, currentFile = '.', responseType = false) {
47
46
  if (responseType == ResponseType.ArrayBuffer) {
48
47
  return response.arrayBuffer();
49
48
  }
50
- return responseType == ResponseType.ReadableStream ? response.body : await response.text();
49
+ return responseType == ResponseType.ReadableStream
50
+ ? response.body
51
+ : response.text();
51
52
  });
52
53
  }
53
54
  try {
54
- if (responseType == ResponseType.Text) {
55
- return readFile(resolved.absolute, 'utf-8');
56
- }
57
- if (responseType == ResponseType.ArrayBuffer) {
58
- return readFile(resolved.absolute).then(buffer => buffer.buffer);
59
- }
60
55
  const stats = await lstat(resolved.absolute);
61
56
  if (stats.isFile()) {
57
+ if (responseType == ResponseType.Text) {
58
+ return readFile(resolved.absolute, "utf-8");
59
+ }
60
+ if (responseType == ResponseType.ArrayBuffer) {
61
+ return readFile(resolved.absolute).then((buffer) => buffer.buffer);
62
+ }
62
63
  return Readable.toWeb(createReadStream(resolved.absolute, {
63
- encoding: 'utf-8',
64
- highWaterMark: 64 * 1024
64
+ encoding: "utf-8",
65
+ highWaterMark: 64 * 1024,
65
66
  }));
66
67
  }
67
68
  }
@@ -126,7 +127,7 @@ function render(data, options = {}, mapping) {
126
127
  * ```
127
128
  */
128
129
  async function parseFile(file, options = {}, asStream = false) {
129
- return Promise.resolve((options.load ?? load)(file, '.', asStream)).then(stream => parse(stream, { src: file, ...options }));
130
+ return Promise.resolve((options.load ?? load)(file, ".", asStream)).then((stream) => parse(stream, { src: file, ...options }));
130
131
  }
131
132
  /**
132
133
  * parse css
@@ -172,18 +173,21 @@ async function parseFile(file, options = {}, asStream = false) {
172
173
  * ```
173
174
  */
174
175
  async function parse(stream, options = {}) {
175
- return doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize({
176
+ options.parseInfo = {
176
177
  stream,
177
- buffer: '',
178
+ buffer: "",
179
+ src: options.src ?? "",
178
180
  offset: 0,
179
- position: { ind: 0, lin: 1, col: 1 },
180
- currentPosition: { ind: -1, lin: 1, col: 0 }
181
- }), Object.assign(options, {
181
+ time: 0,
182
+ position: { ind: 0, lin: 1, col: 0 },
183
+ currentPosition: { ind: -1, lin: 1, col: 0 },
184
+ };
185
+ return doParse(stream instanceof ReadableStream ? tokenizeStream(stream, options.parseInfo) : tokenize(options.parseInfo), Object.assign(options, {
182
186
  load,
183
187
  resolve,
184
188
  dirname,
185
- cwd: options.cwd ?? process.cwd()
186
- })).then(result => {
189
+ cwd: options.cwd ?? process.cwd(),
190
+ })).then((result) => {
187
191
  const { revMapping, ...res } = result;
188
192
  return res;
189
193
  });
@@ -212,7 +216,7 @@ async function parse(stream, options = {}) {
212
216
  * ```
213
217
  */
214
218
  async function transformFile(file, options = {}, asStream = false) {
215
- return Promise.resolve((options.load ?? load)(file, '.', asStream)).then(stream => transform(stream, { src: file, ...options }));
219
+ return Promise.resolve((options.load ?? load)(file, ".", asStream)).then((stream) => transform(stream, { src: file, ...options }));
216
220
  }
217
221
  /**
218
222
  * transform css
@@ -263,18 +267,20 @@ async function transform(css, options = {}) {
263
267
  return parse(css, options).then((parseResult) => {
264
268
  let mapping = null;
265
269
  let importMapping = null;
266
- if (typeof options.module == 'number' && (options.module & ModuleScopeEnumOptions.ICSS)) {
270
+ if (typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) {
267
271
  mapping = parseResult.mapping;
268
272
  importMapping = parseResult.importMapping;
269
273
  }
270
- else if (typeof options.module == 'object' && typeof options.module.scoped == 'number' && (options.module.scoped & ModuleScopeEnumOptions.ICSS)) {
274
+ else if (typeof options.module == "object" &&
275
+ typeof options.module.scoped == "number" &&
276
+ options.module.scoped & ModuleScopeEnumOptions.ICSS) {
271
277
  mapping = parseResult.mapping;
272
278
  importMapping = parseResult.importMapping;
273
279
  }
274
280
  // ast already expanded by parse
275
281
  const rendered = render(parseResult.ast, {
276
282
  ...options,
277
- expandNestingRules: false
283
+ expandNestingRules: false,
278
284
  }, mapping != null ? { mapping, importMapping } : null);
279
285
  return {
280
286
  ...parseResult,
@@ -284,8 +290,8 @@ async function transform(css, options = {}) {
284
290
  bytesOut: rendered.code.length,
285
291
  ...parseResult.stats,
286
292
  render: rendered.stats.total,
287
- total: `${(performance.now() - startTime).toFixed(2)}ms`
288
- }
293
+ total: `${(performance.now() - startTime).toFixed(2)}ms`,
294
+ },
289
295
  };
290
296
  });
291
297
  }