@eslint/css-tree 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +194 -0
  3. package/cjs/convertor/create.cjs +32 -0
  4. package/cjs/convertor/index.cjs +8 -0
  5. package/cjs/data-patch.cjs +7 -0
  6. package/cjs/data.cjs +120 -0
  7. package/cjs/definition-syntax/SyntaxError.cjs +16 -0
  8. package/cjs/definition-syntax/generate.cjs +139 -0
  9. package/cjs/definition-syntax/index.cjs +13 -0
  10. package/cjs/definition-syntax/parse.cjs +556 -0
  11. package/cjs/definition-syntax/scanner.cjs +113 -0
  12. package/cjs/definition-syntax/walk.cjs +57 -0
  13. package/cjs/generator/create.cjs +102 -0
  14. package/cjs/generator/index.cjs +8 -0
  15. package/cjs/generator/sourceMap.cjs +96 -0
  16. package/cjs/generator/token-before.cjs +170 -0
  17. package/cjs/index.cjs +65 -0
  18. package/cjs/lexer/Lexer.cjs +517 -0
  19. package/cjs/lexer/error.cjs +128 -0
  20. package/cjs/lexer/generic-an-plus-b.cjs +235 -0
  21. package/cjs/lexer/generic-const.cjs +12 -0
  22. package/cjs/lexer/generic-urange.cjs +149 -0
  23. package/cjs/lexer/generic.cjs +589 -0
  24. package/cjs/lexer/index.cjs +7 -0
  25. package/cjs/lexer/match-graph.cjs +530 -0
  26. package/cjs/lexer/match.cjs +632 -0
  27. package/cjs/lexer/prepare-tokens.cjs +54 -0
  28. package/cjs/lexer/search.cjs +65 -0
  29. package/cjs/lexer/structure.cjs +173 -0
  30. package/cjs/lexer/trace.cjs +73 -0
  31. package/cjs/lexer/units.cjs +38 -0
  32. package/cjs/parser/SyntaxError.cjs +74 -0
  33. package/cjs/parser/create.cjs +378 -0
  34. package/cjs/parser/index.cjs +8 -0
  35. package/cjs/parser/parse-selector.cjs +8 -0
  36. package/cjs/parser/sequence.cjs +47 -0
  37. package/cjs/syntax/atrule/container.cjs +32 -0
  38. package/cjs/syntax/atrule/font-face.cjs +12 -0
  39. package/cjs/syntax/atrule/import.cjs +101 -0
  40. package/cjs/syntax/atrule/index.cjs +27 -0
  41. package/cjs/syntax/atrule/layer.cjs +16 -0
  42. package/cjs/syntax/atrule/media.cjs +16 -0
  43. package/cjs/syntax/atrule/nest.cjs +16 -0
  44. package/cjs/syntax/atrule/page.cjs +16 -0
  45. package/cjs/syntax/atrule/scope.cjs +16 -0
  46. package/cjs/syntax/atrule/starting-style.cjs +12 -0
  47. package/cjs/syntax/atrule/supports.cjs +16 -0
  48. package/cjs/syntax/config/generator.cjs +9 -0
  49. package/cjs/syntax/config/lexer.cjs +14 -0
  50. package/cjs/syntax/config/mix.cjs +126 -0
  51. package/cjs/syntax/config/parser-selector.cjs +19 -0
  52. package/cjs/syntax/config/parser.cjs +49 -0
  53. package/cjs/syntax/config/walker.cjs +9 -0
  54. package/cjs/syntax/create.cjs +58 -0
  55. package/cjs/syntax/function/expression.cjs +11 -0
  56. package/cjs/syntax/function/var.cjs +43 -0
  57. package/cjs/syntax/index.cjs +14 -0
  58. package/cjs/syntax/node/AnPlusB.cjs +293 -0
  59. package/cjs/syntax/node/Atrule.cjs +103 -0
  60. package/cjs/syntax/node/AtrulePrelude.cjs +52 -0
  61. package/cjs/syntax/node/AttributeSelector.cjs +148 -0
  62. package/cjs/syntax/node/Block.cjs +96 -0
  63. package/cjs/syntax/node/Brackets.cjs +38 -0
  64. package/cjs/syntax/node/CDC.cjs +26 -0
  65. package/cjs/syntax/node/CDO.cjs +26 -0
  66. package/cjs/syntax/node/ClassSelector.cjs +31 -0
  67. package/cjs/syntax/node/Combinator.cjs +61 -0
  68. package/cjs/syntax/node/Comment.cjs +40 -0
  69. package/cjs/syntax/node/Condition.cjs +120 -0
  70. package/cjs/syntax/node/Declaration.cjs +166 -0
  71. package/cjs/syntax/node/DeclarationList.cjs +62 -0
  72. package/cjs/syntax/node/Dimension.cjs +30 -0
  73. package/cjs/syntax/node/Feature.cjs +101 -0
  74. package/cjs/syntax/node/FeatureFunction.cjs +67 -0
  75. package/cjs/syntax/node/FeatureRange.cjs +133 -0
  76. package/cjs/syntax/node/Function.cjs +45 -0
  77. package/cjs/syntax/node/GeneralEnclosed.cjs +68 -0
  78. package/cjs/syntax/node/Hash.cjs +30 -0
  79. package/cjs/syntax/node/IdSelector.cjs +33 -0
  80. package/cjs/syntax/node/Identifier.cjs +25 -0
  81. package/cjs/syntax/node/Layer.cjs +35 -0
  82. package/cjs/syntax/node/LayerList.cjs +43 -0
  83. package/cjs/syntax/node/MediaQuery.cjs +100 -0
  84. package/cjs/syntax/node/MediaQueryList.cjs +41 -0
  85. package/cjs/syntax/node/NestingSelector.cjs +29 -0
  86. package/cjs/syntax/node/Nth.cjs +54 -0
  87. package/cjs/syntax/node/Number.cjs +25 -0
  88. package/cjs/syntax/node/Operator.cjs +28 -0
  89. package/cjs/syntax/node/Parentheses.cjs +38 -0
  90. package/cjs/syntax/node/Percentage.cjs +25 -0
  91. package/cjs/syntax/node/PseudoClassSelector.cjs +67 -0
  92. package/cjs/syntax/node/PseudoElementSelector.cjs +69 -0
  93. package/cjs/syntax/node/Ratio.cjs +71 -0
  94. package/cjs/syntax/node/Raw.cjs +48 -0
  95. package/cjs/syntax/node/Rule.cjs +58 -0
  96. package/cjs/syntax/node/Scope.cjs +69 -0
  97. package/cjs/syntax/node/Selector.cjs +38 -0
  98. package/cjs/syntax/node/SelectorList.cjs +43 -0
  99. package/cjs/syntax/node/String.cjs +26 -0
  100. package/cjs/syntax/node/StyleSheet.cjs +83 -0
  101. package/cjs/syntax/node/SupportsDeclaration.cjs +38 -0
  102. package/cjs/syntax/node/TypeSelector.cjs +59 -0
  103. package/cjs/syntax/node/UnicodeRange.cjs +158 -0
  104. package/cjs/syntax/node/Url.cjs +54 -0
  105. package/cjs/syntax/node/Value.cjs +26 -0
  106. package/cjs/syntax/node/WhiteSpace.cjs +34 -0
  107. package/cjs/syntax/node/index-generate.cjs +103 -0
  108. package/cjs/syntax/node/index-parse-selector.cjs +39 -0
  109. package/cjs/syntax/node/index-parse.cjs +103 -0
  110. package/cjs/syntax/node/index.cjs +103 -0
  111. package/cjs/syntax/pseudo/index.cjs +60 -0
  112. package/cjs/syntax/pseudo/lang.cjs +37 -0
  113. package/cjs/syntax/scope/atrulePrelude.cjs +9 -0
  114. package/cjs/syntax/scope/default.cjs +76 -0
  115. package/cjs/syntax/scope/index.cjs +11 -0
  116. package/cjs/syntax/scope/selector.cjs +88 -0
  117. package/cjs/syntax/scope/value.cjs +29 -0
  118. package/cjs/tokenizer/OffsetToLocation.cjs +91 -0
  119. package/cjs/tokenizer/TokenStream.cjs +358 -0
  120. package/cjs/tokenizer/adopt-buffer.cjs +13 -0
  121. package/cjs/tokenizer/char-code-definitions.cjs +236 -0
  122. package/cjs/tokenizer/index.cjs +554 -0
  123. package/cjs/tokenizer/names.cjs +32 -0
  124. package/cjs/tokenizer/types.cjs +57 -0
  125. package/cjs/tokenizer/utils.cjs +261 -0
  126. package/cjs/utils/List.cjs +473 -0
  127. package/cjs/utils/clone.cjs +25 -0
  128. package/cjs/utils/create-custom-error.cjs +18 -0
  129. package/cjs/utils/ident.cjs +102 -0
  130. package/cjs/utils/index.cjs +20 -0
  131. package/cjs/utils/names.cjs +113 -0
  132. package/cjs/utils/string.cjs +99 -0
  133. package/cjs/utils/url.cjs +108 -0
  134. package/cjs/version.cjs +5 -0
  135. package/cjs/walker/create.cjs +291 -0
  136. package/cjs/walker/index.cjs +8 -0
  137. package/data/patch.json +874 -0
  138. package/dist/csstree.esm.js +12 -0
  139. package/dist/csstree.js +12 -0
  140. package/dist/data.cjs +1341 -0
  141. package/dist/data.js +1341 -0
  142. package/dist/version.cjs +1 -0
  143. package/dist/version.js +1 -0
  144. package/lib/convertor/create.js +28 -0
  145. package/lib/convertor/index.js +4 -0
  146. package/lib/data-patch.js +6 -0
  147. package/lib/data.js +118 -0
  148. package/lib/definition-syntax/SyntaxError.js +12 -0
  149. package/lib/definition-syntax/generate.js +135 -0
  150. package/lib/definition-syntax/index.js +4 -0
  151. package/lib/definition-syntax/parse.js +552 -0
  152. package/lib/definition-syntax/scanner.js +109 -0
  153. package/lib/definition-syntax/walk.js +53 -0
  154. package/lib/generator/create.js +97 -0
  155. package/lib/generator/index.js +4 -0
  156. package/lib/generator/sourceMap.js +92 -0
  157. package/lib/generator/token-before.js +182 -0
  158. package/lib/index.d.ts +3016 -0
  159. package/lib/index.js +30 -0
  160. package/lib/lexer/Lexer.js +511 -0
  161. package/lib/lexer/error.js +123 -0
  162. package/lib/lexer/generic-an-plus-b.js +238 -0
  163. package/lib/lexer/generic-const.js +8 -0
  164. package/lib/lexer/generic-urange.js +151 -0
  165. package/lib/lexer/generic.js +622 -0
  166. package/lib/lexer/index.js +1 -0
  167. package/lib/lexer/match-graph.js +527 -0
  168. package/lib/lexer/match.js +630 -0
  169. package/lib/lexer/prepare-tokens.js +50 -0
  170. package/lib/lexer/search.js +61 -0
  171. package/lib/lexer/structure.js +169 -0
  172. package/lib/lexer/trace.js +66 -0
  173. package/lib/lexer/units.js +27 -0
  174. package/lib/parser/SyntaxError.js +70 -0
  175. package/lib/parser/create.js +388 -0
  176. package/lib/parser/index.js +4 -0
  177. package/lib/parser/parse-selector.js +4 -0
  178. package/lib/parser/sequence.js +43 -0
  179. package/lib/syntax/atrule/container.js +28 -0
  180. package/lib/syntax/atrule/font-face.js +8 -0
  181. package/lib/syntax/atrule/import.js +104 -0
  182. package/lib/syntax/atrule/index.js +23 -0
  183. package/lib/syntax/atrule/layer.js +12 -0
  184. package/lib/syntax/atrule/media.js +12 -0
  185. package/lib/syntax/atrule/nest.js +12 -0
  186. package/lib/syntax/atrule/page.js +12 -0
  187. package/lib/syntax/atrule/scope.js +12 -0
  188. package/lib/syntax/atrule/starting-style.js +8 -0
  189. package/lib/syntax/atrule/supports.js +12 -0
  190. package/lib/syntax/config/generator.js +5 -0
  191. package/lib/syntax/config/lexer.js +10 -0
  192. package/lib/syntax/config/mix.js +122 -0
  193. package/lib/syntax/config/parser-selector.js +15 -0
  194. package/lib/syntax/config/parser.js +45 -0
  195. package/lib/syntax/config/walker.js +5 -0
  196. package/lib/syntax/create.js +55 -0
  197. package/lib/syntax/function/expression.js +7 -0
  198. package/lib/syntax/function/var.js +39 -0
  199. package/lib/syntax/index.js +10 -0
  200. package/lib/syntax/node/AnPlusB.js +292 -0
  201. package/lib/syntax/node/Atrule.js +100 -0
  202. package/lib/syntax/node/AtrulePrelude.js +47 -0
  203. package/lib/syntax/node/AttributeSelector.js +147 -0
  204. package/lib/syntax/node/Block.js +95 -0
  205. package/lib/syntax/node/Brackets.js +35 -0
  206. package/lib/syntax/node/CDC.js +19 -0
  207. package/lib/syntax/node/CDO.js +19 -0
  208. package/lib/syntax/node/ClassSelector.js +24 -0
  209. package/lib/syntax/node/Combinator.js +54 -0
  210. package/lib/syntax/node/Comment.js +33 -0
  211. package/lib/syntax/node/Condition.js +123 -0
  212. package/lib/syntax/node/Declaration.js +165 -0
  213. package/lib/syntax/node/DeclarationList.js +62 -0
  214. package/lib/syntax/node/Dimension.js +23 -0
  215. package/lib/syntax/node/Feature.js +103 -0
  216. package/lib/syntax/node/FeatureFunction.js +63 -0
  217. package/lib/syntax/node/FeatureRange.js +133 -0
  218. package/lib/syntax/node/Function.js +41 -0
  219. package/lib/syntax/node/GeneralEnclosed.js +66 -0
  220. package/lib/syntax/node/Hash.js +23 -0
  221. package/lib/syntax/node/IdSelector.js +26 -0
  222. package/lib/syntax/node/Identifier.js +18 -0
  223. package/lib/syntax/node/Layer.js +28 -0
  224. package/lib/syntax/node/LayerList.js +36 -0
  225. package/lib/syntax/node/MediaQuery.js +102 -0
  226. package/lib/syntax/node/MediaQueryList.js +34 -0
  227. package/lib/syntax/node/NestingSelector.js +22 -0
  228. package/lib/syntax/node/Nth.js +47 -0
  229. package/lib/syntax/node/Number.js +18 -0
  230. package/lib/syntax/node/Operator.js +21 -0
  231. package/lib/syntax/node/Parentheses.js +34 -0
  232. package/lib/syntax/node/Percentage.js +18 -0
  233. package/lib/syntax/node/PseudoClassSelector.js +65 -0
  234. package/lib/syntax/node/PseudoElementSelector.js +66 -0
  235. package/lib/syntax/node/Ratio.js +68 -0
  236. package/lib/syntax/node/Raw.js +41 -0
  237. package/lib/syntax/node/Rule.js +51 -0
  238. package/lib/syntax/node/Scope.js +66 -0
  239. package/lib/syntax/node/Selector.js +31 -0
  240. package/lib/syntax/node/SelectorList.js +35 -0
  241. package/lib/syntax/node/String.js +19 -0
  242. package/lib/syntax/node/StyleSheet.js +82 -0
  243. package/lib/syntax/node/SupportsDeclaration.js +34 -0
  244. package/lib/syntax/node/TypeSelector.js +52 -0
  245. package/lib/syntax/node/UnicodeRange.js +156 -0
  246. package/lib/syntax/node/Url.js +52 -0
  247. package/lib/syntax/node/Value.js +19 -0
  248. package/lib/syntax/node/WhiteSpace.js +27 -0
  249. package/lib/syntax/node/index-generate.js +49 -0
  250. package/lib/syntax/node/index-parse-selector.js +17 -0
  251. package/lib/syntax/node/index-parse.js +49 -0
  252. package/lib/syntax/node/index.js +49 -0
  253. package/lib/syntax/pseudo/index.js +56 -0
  254. package/lib/syntax/pseudo/lang.js +33 -0
  255. package/lib/syntax/scope/atrulePrelude.js +5 -0
  256. package/lib/syntax/scope/default.js +85 -0
  257. package/lib/syntax/scope/index.js +3 -0
  258. package/lib/syntax/scope/selector.js +94 -0
  259. package/lib/syntax/scope/value.js +25 -0
  260. package/lib/tokenizer/OffsetToLocation.js +87 -0
  261. package/lib/tokenizer/TokenStream.js +366 -0
  262. package/lib/tokenizer/adopt-buffer.js +9 -0
  263. package/lib/tokenizer/char-code-definitions.js +212 -0
  264. package/lib/tokenizer/index.js +513 -0
  265. package/lib/tokenizer/names.js +28 -0
  266. package/lib/tokenizer/types.js +28 -0
  267. package/lib/tokenizer/utils.js +254 -0
  268. package/lib/utils/List.js +469 -0
  269. package/lib/utils/clone.js +21 -0
  270. package/lib/utils/create-custom-error.js +14 -0
  271. package/lib/utils/ident.js +101 -0
  272. package/lib/utils/index.js +6 -0
  273. package/lib/utils/names.js +106 -0
  274. package/lib/utils/string.js +99 -0
  275. package/lib/utils/url.js +108 -0
  276. package/lib/version.js +5 -0
  277. package/lib/walker/create.js +287 -0
  278. package/lib/walker/index.js +4 -0
  279. package/package.json +133 -0
package/lib/index.d.ts ADDED
@@ -0,0 +1,3016 @@
1
+ /**
2
+ * @fileoverview Type definitions for @eslint/css-tree
3
+ * @author ScriptHunter7
4
+ * @license MIT
5
+ * Based on https://github.com/scripthunter7/DefinitelyTyped/blob/master/types/css-tree/index.d.ts
6
+ */
7
+
8
+ /*
9
+ * MIT License
10
+ * Copyright (c) Microsoft Corporation.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE
29
+ */
30
+
31
+
32
+ // FIXME: Custom context / nodes for every fork, maybe add a template for internal context
33
+
34
+ // ----------------------------------------------------------
35
+ // CSS Locations
36
+ // ----------------------------------------------------------
37
+
38
+ /**
39
+ * Represents a location within a CSS source.
40
+ */
41
+ export interface CssLocation {
42
+ /**
43
+ * The 0-indexed character offset from the beginning of the source.
44
+ */
45
+ offset: number;
46
+
47
+ /**
48
+ * The 1-indexed line number.
49
+ */
50
+ line: number;
51
+
52
+ /**
53
+ * The 1-indexed column number.
54
+ */
55
+ column: number;
56
+ }
57
+
58
+ /**
59
+ * Represents a range of locations within a CSS source.
60
+ */
61
+ export interface CssLocationRange {
62
+ /**
63
+ * The source file name. If not provided, it will be set to `<unknown>`.
64
+ */
65
+ source: string;
66
+
67
+ /**
68
+ * The starting location of the range.
69
+ */
70
+ start: CssLocation;
71
+
72
+ /**
73
+ * The ending location of the range.
74
+ */
75
+ end: CssLocation;
76
+ }
77
+
78
+ // ----------------------------------------------------------
79
+ // Linked list utils
80
+ // https://github.com/csstree/csstree/blob/master/lib/utils/List.js
81
+ // ----------------------------------------------------------
82
+
83
+ /**
84
+ * Represents an item in a linked list.
85
+ *
86
+ * @template TData - The type of data stored in the item.
87
+ */
88
+ export interface ListItem<TData> {
89
+ /**
90
+ * The previous item in the list.
91
+ */
92
+ prev: ListItem<TData> | null;
93
+
94
+ /**
95
+ * The next item in the list.
96
+ */
97
+ next: ListItem<TData> | null;
98
+
99
+ /**
100
+ * The data stored in the item.
101
+ */
102
+ data: TData;
103
+ }
104
+
105
+ /**
106
+ * A callback function used for iterating over a list.
107
+ *
108
+ * @template TData - The type of data in the list.
109
+ * @template TResult - The type of the result returned by the function.
110
+ * @template TContext - The type of the context object passed to the function. Defaults to List<TData>.
111
+ *
112
+ * @param {TData} item - The current item being iterated over.
113
+ * @param {ListItem<TData>} node - The list item associated with the current item.
114
+ * @param {List<TData>} list - The list being iterated over.
115
+ * @returns {TResult} The result of the function.
116
+ */
117
+ export type IteratorFn<TData, TResult, TContext = List<TData>> = (
118
+ this: TContext,
119
+ item: TData,
120
+ node: ListItem<TData>,
121
+ list: List<TData>,
122
+ ) => TResult;
123
+
124
+ /**
125
+ * A callback function used for filtering a list.
126
+ *
127
+ * @template TData - The type of data in the list.
128
+ * @template TResult - The type of the result returned by the function, which must extend TData.
129
+ * @template TContext - The type of the context object passed to the function. Defaults to List<TData>.
130
+ *
131
+ * @param {TData} item - The current item being iterated over.
132
+ * @param {ListItem<TData>} node - The list item associated with the current item.
133
+ * @param {List<TData>} list - The list being filtered.
134
+ * @returns {boolean} Whether the item should be included in the filtered list.
135
+ */
136
+ export type FilterFn<TData, TResult extends TData, TContext = List<TData>> = (
137
+ this: TContext,
138
+ item: TData,
139
+ node: ListItem<TData>,
140
+ list: List<TData>,
141
+ ) => item is TResult;
142
+
143
+ /**
144
+ * A callback function used for reducing a list to a single value.
145
+ *
146
+ * @template TData - The type of data in the list.
147
+ * @template TValue - The type of the accumulator value.
148
+ * @template TContext - The type of the context object passed to the function. Defaults to List<TData>.
149
+ *
150
+ * @param {TValue} accum - The accumulator value.
151
+ * @param {TData} data - The current item being iterated over.
152
+ * @param {ListItem<TData>} node - The list item associated with the current item.
153
+ * @param {List<TData>} list - The list being reduced.
154
+ * @returns {TValue} The new accumulator value.
155
+ */
156
+ export type ReduceFn<TData, TValue, TContext = List<TData>> = (this: TContext, accum: TValue, data: TData) => TValue;
157
+
158
+ /**
159
+ * A doubly linked list implementation.
160
+ *
161
+ * ```plaintext
162
+ * list
163
+ * ┌──────┐
164
+ * ┌──────────────┼─head │
165
+ * │ │ tail─┼─────────────┐
166
+ * │ └──────┘ │
167
+ * ▼ ▼
168
+ * item item item item
169
+ * ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐
170
+ * null <──┼─prev │<───┼─prev │<───┼─prev │<───┼─prev │
171
+ * │ next─┼───>│ next─┼───>│ next─┼───>│ next─┼──> null
172
+ * ├──────┤ ├──────┤ ├──────┤ ├──────┤
173
+ * │ data │ │ data │ │ data │ │ data │
174
+ * └──────┘ └──────┘ └──────┘ └──────┘
175
+ * ```
176
+ *
177
+ * @template TData - The type of data stored in the list elements.
178
+ */
179
+ export class List<TData> {
180
+ /**
181
+ * Creates a new empty linked list.
182
+ */
183
+ constructor();
184
+
185
+ /**
186
+ * Static factory method for creating list items.
187
+ *
188
+ * @param data Item data.
189
+ * @returns
190
+ */
191
+ static createItem<TData>(data: TData): ListItem<TData>;
192
+
193
+ /**
194
+ * Gets the number of items in the list.
195
+ *
196
+ * @returns {number} The number of items in the list.
197
+ */
198
+ get size(): number;
199
+
200
+ /**
201
+ * Checks if the list is empty.
202
+ *
203
+ * @returns {boolean} True if the list is empty, false otherwise.
204
+ */
205
+ get isEmpty(): boolean;
206
+
207
+ /**
208
+ * Gets the first item in the list.
209
+ *
210
+ * @returns {TData | null} The first item in the list, or null if the list is empty.
211
+ */
212
+ get first(): TData | null;
213
+
214
+ /**
215
+ * Gets the last item in the list.
216
+ *
217
+ * @returns {TData | null} The last item in the list, or null if the list is empty.
218
+ */
219
+ get last(): TData | null;
220
+
221
+ /**
222
+ * Returns an iterator for the list.
223
+ *
224
+ * @returns {IterableIterator<TData>} An iterator for the list.
225
+ */
226
+ [Symbol.iterator](): IterableIterator<TData>;
227
+
228
+ /**
229
+ * Creates a new list from an array.
230
+ *
231
+ * @param {TData[]} array - The array to create the list from.
232
+ * @returns {List<TData>} The new list.
233
+ */
234
+ fromArray(array: TData[]): List<TData>;
235
+
236
+ /**
237
+ * Creates a new list item.
238
+ *
239
+ * @param {TData} data - The data to store in the item.
240
+ * @returns {ListItem<TData>} The new list item.
241
+ */
242
+ createItem(data: TData): ListItem<TData>;
243
+
244
+ /**
245
+ * Converts the list to an array.
246
+ *
247
+ * @returns {TData[]} The list as an array.
248
+ */
249
+ toArray(): TData[];
250
+
251
+ /**
252
+ * Converts the list to a JSON array.
253
+ *
254
+ * @returns {TData[]} The list as a JSON array.
255
+ */
256
+ toJSON(): TData[];
257
+
258
+ /**
259
+ * Iterates over each item in the list, calling the provided callback function for each item.
260
+ *
261
+ * @template TContext - The type of the context object passed to the callback function.
262
+ *
263
+ * @param {IteratorFn<TData, void, TContext>} fn - The callback function to be called for each item.
264
+ * @param {TContext} context - The context object to be passed to the callback function.
265
+ */
266
+ forEach<TContext>(fn: IteratorFn<TData, void, TContext>, context: TContext): void;
267
+ forEach(fn: IteratorFn<TData, void>): void;
268
+
269
+ /**
270
+ * Iterates over each item in the list, starting from the end and moving towards the beginning, calling the provided callback function for each item.
271
+ *
272
+ * @template TContext - The type of the context object passed to the callback function.
273
+ *
274
+ * @param {IteratorFn<TData, void, TContext>} fn - The callback function to be called for each item.
275
+ * @param {TContext} context - The context object to be passed to the callback function.
276
+ */
277
+ forEachRight<TContext>(fn: IteratorFn<TData, void, TContext>, context: TContext): void;
278
+ forEachRight(fn: IteratorFn<TData, void>): void;
279
+
280
+ /**
281
+ * Iterates over the items in the list starting from the specified item until the provided callback function returns true.
282
+ *
283
+ * @template TContext - The type of the context object passed to the callback function.
284
+ *
285
+ * @param {ListItem<TData>} start - The starting item for the iteration.
286
+ * @param {IteratorFn<TData, boolean, TContext>} fn - The callback function to be called for each item.
287
+ * @param {TContext} context - The context object to be passed to the callback function.
288
+ */
289
+ nextUntil<TContext>(start: ListItem<TData>, fn: IteratorFn<TData, boolean, TContext>, context: TContext): void;
290
+ nextUntil(start: ListItem<TData>, fn: IteratorFn<TData, boolean>): void;
291
+
292
+ /**
293
+ * Iterates over the items in the list starting from the specified item and moving towards the beginning until the provided callback function returns true.
294
+ *
295
+ * @template TContext - The type of the context object passed to the callback function.
296
+ *
297
+ * @param {ListItem<TData>} start - The starting item for the iteration.
298
+ * @param {IteratorFn<TData, boolean, TContext>} fn - The callback function to be called for each item.
299
+ * @param {TContext} context - The context object to be passed to the callback function.
300
+ */
301
+ prevUntil<TContext>(start: ListItem<TData>, fn: IteratorFn<TData, boolean, TContext>, context: TContext): void;
302
+ prevUntil(start: ListItem<TData>, fn: IteratorFn<TData, boolean>): void;
303
+
304
+ /**
305
+ * Reduces the list to a single value.
306
+ *
307
+ * @template TValue - The type of the accumulator value.
308
+ * @template TContext - The type of the context object passed to the callback function.
309
+ *
310
+ * @param {ReduceFn<TData, TValue, TContext>} fn - The callback function to be called for each item.
311
+ * @param {TValue} initialValue - The initial value of the accumulator.
312
+ * @param {TContext} context - The context object to be passed to the callback function.
313
+ * @returns {TValue} The final value of the accumulator.
314
+ */
315
+ reduce<TValue, TContext>(fn: ReduceFn<TData, TValue, TContext>, initialValue: TValue, context: TContext): TValue;
316
+ reduce<TValue>(fn: ReduceFn<TData, TValue>, initialValue: TValue): TValue;
317
+
318
+ /**
319
+ * Reduces the list to a single value, starting from the end and moving towards the beginning.
320
+ *
321
+ * @template TValue - The type of the accumulator value.
322
+ * @template TContext - The type of the context object passed to the callback function.
323
+ *
324
+ * @param {ReduceFn<TData, TValue, TContext>} fn - The callback function to be called for each item.
325
+ * @param {TValue} initialValue - The initial value of the accumulator.
326
+ * @param {TContext} context - The context object to be passed to the callback function.
327
+ * @returns {TValue} The final value of the accumulator.
328
+ */
329
+ reduceRight<TValue, TContext>(
330
+ fn: ReduceFn<TData, TValue, TContext>,
331
+ initialValue: TValue,
332
+ context: TContext,
333
+ ): TValue;
334
+ reduceRight<TValue>(fn: ReduceFn<TData, TValue>, initialValue: TValue): TValue;
335
+
336
+ /**
337
+ * Checks if at least one item in the list satisfies the provided callback function.
338
+ *
339
+ * @template TContext - The type of the context object passed to the callback function.
340
+ *
341
+ * @param {IteratorFn<TData, boolean, TContext>} fn - The callback function to be called for each item.
342
+ * @param {TContext} context - The context object to be passed to the callback function.
343
+ * @returns {boolean} True if at least one item satisfies the callback function, false otherwise.
344
+ */
345
+ some<TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): boolean;
346
+ some(fn: IteratorFn<TData, boolean>): boolean;
347
+
348
+ /**
349
+ * Creates a new list by applying the provided callback function to each item in the current list.
350
+ *
351
+ * @template TContext - The type of the context object passed to the callback function.
352
+ * @template TResult - The type of the elements in the new list.
353
+ *
354
+ * @param {IteratorFn<TData, TResult, TContext>} fn - The callback function to be called for each item.
355
+ * @param {TContext} context - The context object to be passed to the callback function.
356
+ * @returns {List<TResult>} The new list containing the transformed elements.
357
+ */
358
+ map<TContext, TResult>(fn: IteratorFn<TData, TResult, TContext>, context: TContext): List<TResult>;
359
+ map<TResult>(fn: IteratorFn<TData, TResult>): List<TResult>;
360
+
361
+ /**
362
+ * Creates a new list containing only the items from the current list that satisfy the provided callback function.
363
+ *
364
+ * @template TContext - The type of the context object passed to the callback function.
365
+ * @template TResult - The type of the elements in the new list, which must extend TData.
366
+ *
367
+ * @param {FilterFn<TData, TResult, TContext>} fn - The callback function to be called for each item.
368
+ * @param {TContext} context - The context object to be passed to the callback function.
369
+ * @returns {List<TResult>} The new list containing the filtered elements.
370
+ */
371
+ filter<TContext, TResult extends TData>(fn: FilterFn<TData, TResult, TContext>, context: TContext): List<TResult>;
372
+ filter<TResult extends TData>(fn: FilterFn<TData, TResult>): List<TResult>;
373
+ /**
374
+ * Creates a new list containing only the items from the current list that satisfy the provided callback function.
375
+ *
376
+ * @template TContext - The type of the context object passed to the callback function.
377
+ *
378
+ * @param {IteratorFn<TData, boolean, TContext>} fn - The callback function to be called for each item.
379
+ * @param {TContext} context - The context object to be passed to the callback function.
380
+ * @returns {List<TData>} The new list containing the filtered elements.
381
+ */
382
+ filter<TContext>(fn: IteratorFn<TData, boolean, TContext>, context: TContext): List<TData>;
383
+ filter(fn: IteratorFn<TData, boolean>): List<TData>;
384
+
385
+
386
+ /**
387
+ * Removes all items from the list.
388
+ */
389
+ clear(): void;
390
+
391
+ /**
392
+ * Creates a copy of the list.
393
+ *
394
+ * @returns {List<TData>} A copy of the list.
395
+ */
396
+ copy(): List<TData>;
397
+
398
+ /**
399
+ * Inserts an item at the beginning of the list.
400
+ *
401
+ * @param {ListItem<TData>} item - The item to insert.
402
+ * @returns {List<TData>} The list itself.
403
+ */
404
+ prepend(item: ListItem<TData>): List<TData>;
405
+
406
+ /**
407
+ * Inserts a new item at the beginning of the list.
408
+ *
409
+ * @param {TData} data - The data for the new item.
410
+ * @returns {List<TData>} The list itself.
411
+ */
412
+ prependData(data: TData): List<TData>;
413
+
414
+ /**
415
+ * Inserts an item at the end of the list.
416
+ *
417
+ * @param {ListItem<TData>} item - The item to insert.
418
+ * @returns {List<TData>} The list itself.
419
+ */
420
+ append(item: ListItem<TData>): List<TData>;
421
+
422
+ /**
423
+ * Inserts a new item at the end of the list.
424
+ *
425
+ * @param {TData} data - The data for the new item.
426
+ * @returns {List<TData>} The list itself.
427
+ */
428
+ appendData(data: TData): List<TData>;
429
+
430
+ /**
431
+ * Inserts an item before the specified item in the list.
432
+ *
433
+ * @param {ListItem<TData>} item - The item to insert.
434
+ * @param {ListItem<TData>} before - The item before which to insert the new item.
435
+ * @returns {List<TData>} The list itself.
436
+ */
437
+ insert(item: ListItem<TData>, before: ListItem<TData>): List<TData>;
438
+
439
+ /**
440
+ * Inserts a new item before the specified item in the list.
441
+ *
442
+ * @param {TData} data - The data for the new item.
443
+ * @param {ListItem<TData>} before - The item before which to insert the new item.
444
+ * @returns {List<TData>} The list itself.
445
+ */
446
+ insertData(data: TData, before: ListItem<TData>): List<TData>;
447
+
448
+ /**
449
+ * Removes an item from the list.
450
+ *
451
+ * @param {ListItem<TData>} item - The item to remove.
452
+ * @returns {ListItem<TData>} The removed item, or null if the item was not found.
453
+ */
454
+ remove(item: ListItem<TData>): ListItem<TData>;
455
+
456
+ /**
457
+ * Adds an item to the end of the list.
458
+ *
459
+ * @param {TData} item - The item to add.
460
+ */
461
+ push(item: TData): void;
462
+
463
+ /**
464
+ * Removes the last item from the list and returns it.
465
+ *
466
+ * @returns {ListItem<TData> | undefined} The removed item, or undefined if the list is empty.
467
+ */
468
+ pop(): ListItem<TData> | undefined;
469
+
470
+ /**
471
+ * Adds an item to the beginning of the list.
472
+ *
473
+ * @param {TData} data - The data for the new item.
474
+ */
475
+ unshift(data: TData): void;
476
+
477
+ /**
478
+ * Removes the first item from the list and returns it.
479
+ *
480
+ * @returns {ListItem<TData> | undefined} The removed item, or undefined if the list is empty.
481
+ */
482
+ shift(): ListItem<TData> | undefined;
483
+
484
+ /**
485
+ * Inserts a list at the beginning of this list.
486
+ *
487
+ * @param {List<TData>} list - The list to insert.
488
+ * @returns {List<TData>} The list itself.
489
+ */
490
+ prependList(list: List<TData>): List<TData>;
491
+
492
+ /**
493
+ * Inserts a list at the end of this list.
494
+ *
495
+ * @param {List<TData>} list - The list to insert.
496
+ * @returns {List<TData>} The list itself.
497
+ */
498
+ appendList(list: List<TData>): List<TData>;
499
+
500
+ /**
501
+ * Inserts a list before the specified item in this list.
502
+ *
503
+ * @param {List<TData>} list - The list to insert.
504
+ * @param {ListItem<TData>} before - The item before which to insert the new list.
505
+ * @returns {List<TData>} The list itself.
506
+ */
507
+ insertList(list: List<TData>, before: ListItem<TData>): List<TData>;
508
+
509
+ /**
510
+ * Replaces an item in the list with another item or list.
511
+ *
512
+ * @param {ListItem<TData>} oldItem - The item to replace.
513
+ * @param {List<TData> | ListItem<TData>} newItemOrList - The new item or list to insert.
514
+ * @returns {List<TData>} The list itself.
515
+ */
516
+ replace(oldItem: ListItem<TData>, newItemOrList: List<TData> | ListItem<TData>): List<TData>;
517
+ }
518
+
519
+ // ----------------------------------------------------------
520
+ // CSS Nodes
521
+ // ----------------------------------------------------------
522
+
523
+ export interface CssNodeCommon {
524
+ type: string;
525
+ loc?: CssLocationRange | undefined;
526
+ }
527
+
528
+ export interface AnPlusB extends CssNodeCommon {
529
+ type: "AnPlusB";
530
+ a: string | null;
531
+ b: string | null;
532
+ }
533
+
534
+ export interface Atrule extends CssNodeCommon {
535
+ type: "Atrule";
536
+ name: string;
537
+ prelude: AtrulePrelude | Raw | null;
538
+ block: Block | null;
539
+ }
540
+
541
+ export interface AtrulePlain extends CssNodeCommon {
542
+ type: "Atrule";
543
+ name: string;
544
+ prelude: AtrulePreludePlain | Raw | null;
545
+ block: BlockPlain | null;
546
+ }
547
+
548
+ export interface AtrulePrelude extends CssNodeCommon {
549
+ type: "AtrulePrelude";
550
+ children: List<CssNode>;
551
+ }
552
+
553
+ export interface AtrulePreludePlain extends CssNodeCommon {
554
+ type: "AtrulePrelude";
555
+ children: CssNodePlain[];
556
+ }
557
+
558
+ export interface AttributeSelector extends CssNodeCommon {
559
+ type: "AttributeSelector";
560
+ name: Identifier;
561
+ matcher: string | null;
562
+ value: StringNode | Identifier | null;
563
+ flags: string | null;
564
+ }
565
+
566
+ export interface Block extends CssNodeCommon {
567
+ type: "Block";
568
+ children: List<CssNode>;
569
+ }
570
+
571
+ export interface BlockPlain extends CssNodeCommon {
572
+ type: "Block";
573
+ children: CssNodePlain[];
574
+ }
575
+
576
+ export interface Brackets extends CssNodeCommon {
577
+ type: "Brackets";
578
+ children: List<CssNode>;
579
+ }
580
+
581
+ export interface BracketsPlain extends CssNodeCommon {
582
+ type: "Brackets";
583
+ children: CssNodePlain[];
584
+ }
585
+
586
+ export interface CDC extends CssNodeCommon {
587
+ type: "CDC";
588
+ }
589
+
590
+ export interface CDO extends CssNodeCommon {
591
+ type: "CDO";
592
+ }
593
+
594
+ export interface ClassSelector extends CssNodeCommon {
595
+ type: "ClassSelector";
596
+ name: string;
597
+ }
598
+
599
+ export interface Combinator extends CssNodeCommon {
600
+ type: "Combinator";
601
+ name: string;
602
+ }
603
+
604
+ export interface Comment extends CssNodeCommon {
605
+ type: "Comment";
606
+ value: string;
607
+ }
608
+
609
+ export interface Declaration extends CssNodeCommon {
610
+ type: "Declaration";
611
+ important: boolean | string;
612
+ property: string;
613
+ value: Value | Raw;
614
+ }
615
+
616
+ export interface DeclarationPlain extends CssNodeCommon {
617
+ type: "Declaration";
618
+ important: boolean | string;
619
+ property: string;
620
+ value: ValuePlain | Raw;
621
+ }
622
+
623
+ export interface DeclarationList extends CssNodeCommon {
624
+ type: "DeclarationList";
625
+ children: List<CssNode>;
626
+ }
627
+
628
+ export interface DeclarationListPlain extends CssNodeCommon {
629
+ type: "DeclarationList";
630
+ children: CssNodePlain[];
631
+ }
632
+
633
+ export interface Dimension extends CssNodeCommon {
634
+ type: "Dimension";
635
+ value: string;
636
+ unit: string;
637
+ }
638
+
639
+ export interface FunctionNode extends CssNodeCommon {
640
+ type: "Function";
641
+ name: string;
642
+ children: List<CssNode>;
643
+ }
644
+
645
+ export interface FunctionNodePlain extends CssNodeCommon {
646
+ type: "Function";
647
+ name: string;
648
+ children: CssNodePlain[];
649
+ }
650
+
651
+ export interface Hash extends CssNodeCommon {
652
+ type: "Hash";
653
+ value: string;
654
+ }
655
+
656
+ export interface IdSelector extends CssNodeCommon {
657
+ type: "IdSelector";
658
+ name: string;
659
+ }
660
+
661
+ export interface Identifier extends CssNodeCommon {
662
+ type: "Identifier";
663
+ name: string;
664
+ }
665
+
666
+ export interface MediaFeature extends CssNodeCommon {
667
+ type: "MediaFeature";
668
+ name: string;
669
+ value: Identifier | NumberNode | Dimension | Ratio | null;
670
+ }
671
+
672
+ export interface MediaQuery extends CssNodeCommon {
673
+ type: "MediaQuery";
674
+ children: List<CssNode>;
675
+ }
676
+
677
+ export interface MediaQueryPlain extends CssNodeCommon {
678
+ type: "MediaQuery";
679
+ children: CssNodePlain[];
680
+ }
681
+
682
+ export interface MediaQueryList extends CssNodeCommon {
683
+ type: "MediaQueryList";
684
+ children: List<CssNode>;
685
+ }
686
+
687
+ export interface MediaQueryListPlain extends CssNodeCommon {
688
+ type: "MediaQueryList";
689
+ children: CssNodePlain[];
690
+ }
691
+
692
+ export interface NestingSelector extends CssNodeCommon {
693
+ type: "NestingSelector";
694
+ }
695
+
696
+ export interface Nth extends CssNodeCommon {
697
+ type: "Nth";
698
+ nth: AnPlusB | Identifier;
699
+ selector: SelectorList | null;
700
+ }
701
+
702
+ export interface NthPlain extends CssNodeCommon {
703
+ type: "Nth";
704
+ nth: AnPlusB | Identifier;
705
+ selector: SelectorListPlain | null;
706
+ }
707
+
708
+ export interface NumberNode extends CssNodeCommon {
709
+ type: "Number";
710
+ value: string;
711
+ }
712
+
713
+ export interface Operator extends CssNodeCommon {
714
+ type: "Operator";
715
+ value: string;
716
+ }
717
+
718
+ export interface Parentheses extends CssNodeCommon {
719
+ type: "Parentheses";
720
+ children: List<CssNode>;
721
+ }
722
+
723
+ export interface ParenthesesPlain extends CssNodeCommon {
724
+ type: "Parentheses";
725
+ children: CssNodePlain[];
726
+ }
727
+
728
+ export interface Percentage extends CssNodeCommon {
729
+ type: "Percentage";
730
+ value: string;
731
+ }
732
+
733
+ export interface PseudoClassSelector extends CssNodeCommon {
734
+ type: "PseudoClassSelector";
735
+ name: string;
736
+ children: List<CssNode> | null;
737
+ }
738
+
739
+ export interface PseudoClassSelectorPlain extends CssNodeCommon {
740
+ type: "PseudoClassSelector";
741
+ name: string;
742
+ children: CssNodePlain[] | null;
743
+ }
744
+
745
+ export interface PseudoElementSelector extends CssNodeCommon {
746
+ type: "PseudoElementSelector";
747
+ name: string;
748
+ children: List<CssNode> | null;
749
+ }
750
+
751
+ export interface PseudoElementSelectorPlain extends CssNodeCommon {
752
+ type: "PseudoElementSelector";
753
+ name: string;
754
+ children: CssNodePlain[] | null;
755
+ }
756
+
757
+ export interface Ratio extends CssNodeCommon {
758
+ type: "Ratio";
759
+ left: string;
760
+ right: string;
761
+ }
762
+
763
+ export interface Raw extends CssNodeCommon {
764
+ type: "Raw";
765
+ value: string;
766
+ }
767
+
768
+ export interface Rule extends CssNodeCommon {
769
+ type: "Rule";
770
+ prelude: SelectorList | Raw;
771
+ block: Block;
772
+ }
773
+
774
+ export interface RulePlain extends CssNodeCommon {
775
+ type: "Rule";
776
+ prelude: SelectorListPlain | Raw;
777
+ block: BlockPlain;
778
+ }
779
+
780
+ export interface Selector extends CssNodeCommon {
781
+ type: "Selector";
782
+ children: List<CssNode>;
783
+ }
784
+
785
+ export interface SelectorPlain extends CssNodeCommon {
786
+ type: "Selector";
787
+ children: CssNodePlain[];
788
+ }
789
+
790
+ export interface SelectorList extends CssNodeCommon {
791
+ type: "SelectorList";
792
+ children: List<CssNode>;
793
+ }
794
+
795
+ export interface SelectorListPlain extends CssNodeCommon {
796
+ type: "SelectorList";
797
+ children: CssNodePlain[];
798
+ }
799
+
800
+ export interface StringNode extends CssNodeCommon {
801
+ type: "String";
802
+ value: string;
803
+ }
804
+
805
+ export interface StyleSheet extends CssNodeCommon {
806
+ type: "StyleSheet";
807
+ children: List<CssNode>;
808
+ }
809
+
810
+ export interface StyleSheetPlain extends CssNodeCommon {
811
+ type: "StyleSheet";
812
+ children: CssNodePlain[];
813
+ }
814
+
815
+ export interface TypeSelector extends CssNodeCommon {
816
+ type: "TypeSelector";
817
+ name: string;
818
+ }
819
+
820
+ export interface UnicodeRange extends CssNodeCommon {
821
+ type: "UnicodeRange";
822
+ value: string;
823
+ }
824
+
825
+ export interface Url extends CssNodeCommon {
826
+ type: "Url";
827
+ value: string;
828
+ }
829
+
830
+ export interface Value extends CssNodeCommon {
831
+ type: "Value";
832
+ children: List<CssNode>;
833
+ }
834
+
835
+ export interface ValuePlain extends CssNodeCommon {
836
+ type: "Value";
837
+ children: CssNodePlain[];
838
+ }
839
+
840
+ export interface WhiteSpace extends CssNodeCommon {
841
+ type: "WhiteSpace";
842
+ value: string;
843
+ }
844
+
845
+ export type CssNode =
846
+ | AnPlusB
847
+ | Atrule
848
+ | AtrulePrelude
849
+ | AttributeSelector
850
+ | Block
851
+ | Brackets
852
+ | CDC
853
+ | CDO
854
+ | ClassSelector
855
+ | Combinator
856
+ | Comment
857
+ | Declaration
858
+ | DeclarationList
859
+ | Dimension
860
+ | FunctionNode
861
+ | Hash
862
+ | IdSelector
863
+ | Identifier
864
+ | MediaFeature
865
+ | MediaQuery
866
+ | MediaQueryList
867
+ | NestingSelector
868
+ | Nth
869
+ | NumberNode
870
+ | Operator
871
+ | Parentheses
872
+ | Percentage
873
+ | PseudoClassSelector
874
+ | PseudoElementSelector
875
+ | Ratio
876
+ | Raw
877
+ | Rule
878
+ | Selector
879
+ | SelectorList
880
+ | StringNode
881
+ | StyleSheet
882
+ | TypeSelector
883
+ | UnicodeRange
884
+ | Url
885
+ | Value
886
+ | WhiteSpace;
887
+
888
+ export type CssNodePlain =
889
+ | AnPlusB
890
+ | AtrulePlain
891
+ | AtrulePreludePlain
892
+ | AttributeSelector
893
+ | BlockPlain
894
+ | BracketsPlain
895
+ | CDC
896
+ | CDO
897
+ | ClassSelector
898
+ | Combinator
899
+ | Comment
900
+ | DeclarationPlain
901
+ | DeclarationListPlain
902
+ | Dimension
903
+ | FunctionNodePlain
904
+ | Hash
905
+ | IdSelector
906
+ | Identifier
907
+ | MediaFeature
908
+ | MediaQueryPlain
909
+ | MediaQueryListPlain
910
+ | NthPlain
911
+ | NumberNode
912
+ | Operator
913
+ | ParenthesesPlain
914
+ | Percentage
915
+ | PseudoClassSelectorPlain
916
+ | PseudoElementSelectorPlain
917
+ | Ratio
918
+ | Raw
919
+ | RulePlain
920
+ | SelectorPlain
921
+ | SelectorListPlain
922
+ | StringNode
923
+ | StyleSheetPlain
924
+ | TypeSelector
925
+ | UnicodeRange
926
+ | Url
927
+ | ValuePlain
928
+ | WhiteSpace;
929
+
930
+ type CssNodeNames =
931
+ | "AnPlusB"
932
+ | "Atrule"
933
+ | "AtrulePrelude"
934
+ | "AttributeSelector"
935
+ | "Block"
936
+ | "Brackets"
937
+ | "CDC"
938
+ | "CDO"
939
+ | "ClassSelector"
940
+ | "Combinator"
941
+ | "Comment"
942
+ | "Declaration"
943
+ | "DeclarationList"
944
+ | "Dimension"
945
+ | "Function"
946
+ | "Hash"
947
+ | "IdSelector"
948
+ | "Identifier"
949
+ | "MediaFeature"
950
+ | "MediaQuery"
951
+ | "MediaQueryList"
952
+ | "NestingSelector"
953
+ | "Nth"
954
+ | "Number"
955
+ | "Operator"
956
+ | "Parentheses"
957
+ | "Percentage"
958
+ | "PseudoClassSelector"
959
+ | "PseudoElementSelector"
960
+ | "Ratio"
961
+ | "Raw"
962
+ | "Rule"
963
+ | "Selector"
964
+ | "SelectorList"
965
+ | "String"
966
+ | "StyleSheet"
967
+ | "TypeSelector"
968
+ | "UnicodeRange"
969
+ | "Url"
970
+ | "Value"
971
+ | "WhiteSpace";
972
+
973
+ // ----------------------------------------------------------
974
+ // Tokenizer
975
+ // https://github.com/csstree/csstree/tree/master/lib/tokenizer
976
+ // ----------------------------------------------------------
977
+
978
+ type ReadonlyRecord<K extends keyof any, T> = Readonly<Record<K, T>>;
979
+
980
+ /**
981
+ * A dictionary mapping token names (strings) to their corresponding numeric token types.
982
+ */
983
+ export const tokenTypes: ReadonlyRecord<string, number>;
984
+
985
+ /**
986
+ * An array containing all the possible token names as strings, indexed by their numeric token types.
987
+ */
988
+ export const tokenNames: ReadonlyArray<string>;
989
+
990
+ /**
991
+ * A callback function used during tokenization. It takes three arguments:
992
+ *
993
+ * @param token - The numeric type of the current token.
994
+ * @param start - The starting index of the token in the source string.
995
+ * @param end - The ending index (exclusive) of the token in the source string.
996
+ */
997
+ export type CssTokenizerCallback = (token: number, start: number, end: number) => void;
998
+
999
+ /**
1000
+ * A function used to tokenize CSS source code.
1001
+ *
1002
+ * @param css - The CSS source code to tokenize.
1003
+ * @param onToken - The callback function to be called for each token found in the source code.
1004
+ */
1005
+ export type TokenizeFunction = (css: string, onToken: CssTokenizerCallback) => void;
1006
+
1007
+ /**
1008
+ * Tokenizes a CSS source code string.
1009
+ *
1010
+ * @param css - The CSS source code to tokenize.
1011
+ * @param onToken - The callback function to be called for each token found in the source code.
1012
+ */
1013
+ export const tokenize: TokenizeFunction;
1014
+
1015
+ export interface TokenStreamDumpEntry {
1016
+ idx: number;
1017
+ type: string;
1018
+ chunk: string;
1019
+ balance: number;
1020
+ }
1021
+
1022
+ export type TokenStreamDump = TokenStreamDumpEntry[];
1023
+
1024
+ export type TokenStreamIteratorFunction = (token: number, start: number, end: number, index: number) => void;
1025
+
1026
+ export type TokenStreamConsumeStopFunction = (charCode: number) => number;
1027
+
1028
+ /**
1029
+ * This class represents a stream of tokens generated from a CSS string.
1030
+ */
1031
+ export class TokenStream {
1032
+ /**
1033
+ * The original CSS source string.
1034
+ */
1035
+ readonly source: string;
1036
+
1037
+ /**
1038
+ * The offset of the first character in the source string (usually 0).
1039
+ */
1040
+ readonly firstCharOffset: number;
1041
+
1042
+ /**
1043
+ * A boolean flag indicating whether the end of the stream has been reached.
1044
+ */
1045
+ readonly eof: boolean;
1046
+
1047
+ /**
1048
+ * The total number of tokens in the stream.
1049
+ */
1050
+ readonly tokenCount: number;
1051
+
1052
+ /**
1053
+ * The index of the current token in the stream (starts at -1 before `next()` is called).
1054
+ */
1055
+ readonly tokenIndex: number;
1056
+
1057
+ /**
1058
+ * The numeric type of the current token.
1059
+ */
1060
+ readonly tokenType: number;
1061
+
1062
+ /**
1063
+ * The starting index of the current token in the source string.
1064
+ */
1065
+ readonly tokenStart: number;
1066
+
1067
+ /**
1068
+ * The ending index (exclusive) of the current token in the source string.
1069
+ */
1070
+ readonly tokenEnd: number;
1071
+
1072
+ /**
1073
+ * An internal buffer used for managing balance between opening and closing tokens.
1074
+ */
1075
+ readonly balance: Uint32Array;
1076
+
1077
+ /**
1078
+ * An internal buffer used for storing token information, including type and offset.
1079
+ * The 32-bit integer at each index contains two pieces of information:
1080
+ * - The starting index (inclusive) of the token within the source string is stored in the lower 24 bits of the 32-bit integer.
1081
+ * - The numeric type of the token is stored in the upper 8 bits of the 32-bit integer.
1082
+ */
1083
+ readonly offsetAndType: Uint32Array;
1084
+
1085
+ /**
1086
+ * Creates a new token stream from a CSS source string.
1087
+ *
1088
+ * @param source - The CSS source code to tokenize.
1089
+ * @param tokenize - The tokenizer function to use.
1090
+ */
1091
+ constructor(source: string, tokenize: TokenizeFunction);
1092
+
1093
+ /**
1094
+ * Resets the stream to its initial state (all properties set to their default values).
1095
+ */
1096
+ reset(): void;
1097
+
1098
+ /**
1099
+ * Sets a new source string and optionally a new tokenize function for the stream.
1100
+ *
1101
+ * @param source - The new CSS source code to tokenize.
1102
+ * @param tokenize - The new tokenizer function to use.
1103
+ */
1104
+ setSource(source?: string, tokenize?: TokenizeFunction): void;
1105
+
1106
+ /**
1107
+ * Returns the numeric type of the token at a specific offset (relative to the current position).
1108
+ *
1109
+ * @param offset - The offset of the token to look up.
1110
+ * @returns The numeric type of the token at the specified offset.
1111
+ */
1112
+ lookupType(offset: number): number;
1113
+
1114
+ /**
1115
+ * Returns the numeric type of the idx-th non-whitespace/comment token in the TokenStream. This method skips whitespace and comment tokens until it finds the specified non-whitespace/comment token.
1116
+ *
1117
+ * @param index - The index of the non-whitespace/comment token to look up (starting from 0).
1118
+ * @returns The numeric type of the idx-th non-whitespace/comment token, or EOF if the index is out of bounds or if the end of the stream is reached before the specified token is found.
1119
+ */
1120
+ lookupTypeNonSC(index: number): number;
1121
+
1122
+ /**
1123
+ * Returns the starting index (inclusive) of the token at a specific offset (relative to the current position) within the TokenStream.
1124
+ *
1125
+ * @param offset - The offset from the current token's starting index. A positive offset indicates a position later in the stream, while a negative offset indicates a position earlier in the stream.
1126
+ * @returns The starting index of the token at the specified offset, or the length of the source string if the offset is out of bounds.
1127
+ */
1128
+ lookupOffset(offset: number): number;
1129
+
1130
+ /**
1131
+ * Skips whitespace and comments and returns the starting index (inclusive) of the `idx`-th non-whitespace/comment token in the `TokenStream`.
1132
+ *
1133
+ * @param index - The index of the non-whitespace/comment token to look up (starting from 0).
1134
+ * @returns The starting index of the `idx`-th non-whitespace/comment token, or `EOF` if the index is out of bounds or if the end of the stream is reached before the specified token is found.
1135
+ */
1136
+ lookupOffsetNonSC(index: number): number;
1137
+
1138
+ /**
1139
+ * Compares the value of the token at a specific offset with a given reference string and returns true if they match.
1140
+ *
1141
+ * @param offset - The offset from the current token's starting index. A positive offset indicates a position later in the stream, while a negative offset indicates a position earlier in the stream.
1142
+ * @param referenceStr - The reference string to compare with the token value.
1143
+ * @returns True if the token value matches the reference string, false otherwise.
1144
+ */
1145
+ lookupValue(offset: number, referenceStr: string): boolean;
1146
+
1147
+ /**
1148
+ * Returns the starting index (inclusive) of the token at a specific index in the `TokenStream`.
1149
+ *
1150
+ * @param tokenIndex - The index of the token to look up (starting from 0).
1151
+ * @returns The starting index of the token at the specified index, or `EOF` if the index is out of bounds.
1152
+ */
1153
+ getTokenStart(tokenIndex: number): number;
1154
+
1155
+ /**
1156
+ * Returns the substring of the source string from the specified starting index to the current token's starting index.
1157
+ *
1158
+ * @param start The starting index of the substring.
1159
+ * @returns The extracted substring.
1160
+ */
1161
+ substrToCursor(start: number): string;
1162
+
1163
+ /**
1164
+ * Checks if the current position is at the edge of a balanced block (e.g., before an opening parenthesis).
1165
+ *
1166
+ * @param pos - The position to check.
1167
+ * @returns True if the position is at a balance edge, false otherwise.
1168
+ */
1169
+ isBalanceEdge(pos: number): boolean;
1170
+
1171
+ /**
1172
+ * Checks if the current token (or the token at a specific offset) is a delimiter with a specific character code.
1173
+ *
1174
+ * @param code - The character code to check for.
1175
+ * @param offset - The offset from the current token's starting index (optional). If provided, the function checks the token at the specified offset instead of the current token.
1176
+ * @returns True if the token is a delimiter with the specified character code, false otherwise.
1177
+ */
1178
+ isDelim(code: number, offset: number): boolean;
1179
+
1180
+ /**
1181
+ * Skips a specified number of tokens forward in the stream.
1182
+ *
1183
+ * @param tokenCount - The number of tokens to skip.
1184
+ */
1185
+ skip(tokenCount: number): void;
1186
+
1187
+ /**
1188
+ * Moves the stream forward to the next token.
1189
+ */
1190
+ next(): void;
1191
+
1192
+ /**
1193
+ * Skips any whitespace or comment tokens until encountering a non-whitespace/comment token.
1194
+ */
1195
+ skipSC(): void;
1196
+
1197
+ /**
1198
+ * Skips tokens until a balanced block is reached, optionally stopping at a specified condition.
1199
+ *
1200
+ * @param startToken - The index of the starting token of the balanced block.
1201
+ * @param stopConsume - A function that determines whether to stop skipping tokens. It should take a character code as input and return:
1202
+ * - 1: Stop skipping immediately.
1203
+ * - 2: Stop skipping and include the current token.
1204
+ * - 0: Continue skipping.
1205
+ */
1206
+ skipUntilBalanced(startToken: number, stopConsume: TokenStreamConsumeStopFunction): void;
1207
+
1208
+ /**
1209
+ * Iterates over each token in the stream and calls the provided function for each token.
1210
+ *
1211
+ * @param fn - The function to be called for each token. It should take the following arguments:
1212
+ * - token: The numeric type of the token.
1213
+ * - start: The starting index of the token in the source string.
1214
+ * - end: The ending index (exclusive) of the token in the source string.
1215
+ * - index: The index of the token in the stream.
1216
+ */
1217
+ forEachToken(fn: TokenStreamIteratorFunction): void;
1218
+
1219
+ /**
1220
+ * Dumps the token stream data.
1221
+ *
1222
+ * @returns An array of token stream entries.
1223
+ */
1224
+ dump(): TokenStreamDump;
1225
+ }
1226
+
1227
+ /**
1228
+ * A class that maps offsets within a source string to their corresponding line and column numbers.
1229
+ */
1230
+ export class OffsetToLocation {
1231
+ /**
1232
+ * Sets the source string and optionally the starting offset, line, and column.
1233
+ *
1234
+ * @param source - The source string.
1235
+ * @param startOffset The offset of the first character in the source string (default: 0).
1236
+ * @param startLine - The line number of the first character in the source string (default: 1).
1237
+ * @param startColumn - The column number of the first character in the source string (default: 1).
1238
+ */
1239
+ setSource(source: string, startOffset?: number, startLine?: number, startColumn?: number): void;
1240
+
1241
+ /**
1242
+ * Gets the line and column numbers for a given offset within the source string.
1243
+ *
1244
+ * @param offset - The offset within the source string.
1245
+ * @param filename - The filename associated with the source string (optional).
1246
+ * @returns A {@link CssLocation} object containing the line and column numbers.
1247
+ */
1248
+ getLocation(offset: number, filename?: string): CssLocation;
1249
+
1250
+ /**
1251
+ * Gets the line and column numbers for a range of offsets within the source string.
1252
+ *
1253
+ * @param start - The starting offset within the source string.
1254
+ * @param end - The ending offset within the source string (exclusive).
1255
+ * @param filename - The filename associated with the source string (optional).
1256
+ * @returns A {@link CssLocationRange} object containing the line and column numbers for the start and end positions.
1257
+ */
1258
+ getLocationRange(start: number, end: number, filename?: string): CssLocationRange;
1259
+ }
1260
+
1261
+ // ----------------------------------------------------------
1262
+ // Parser
1263
+ // https://github.com/csstree/csstree/tree/master/lib/parser
1264
+ // ----------------------------------------------------------
1265
+
1266
+ /**
1267
+ * Represents an error that occurs during CSS parsing. Extends the standard `SyntaxError`
1268
+ * to include additional details about the parsing error.
1269
+ */
1270
+ export interface SyntaxParseError extends SyntaxError {
1271
+ /**
1272
+ * The original input string that caused the error.
1273
+ */
1274
+ input: string;
1275
+
1276
+ /**
1277
+ * The character offset in the input string where the error occurred.
1278
+ */
1279
+ offset: number;
1280
+
1281
+ /**
1282
+ * The raw error message without formatting.
1283
+ */
1284
+ rawMessage: string;
1285
+
1286
+ /**
1287
+ * The formatted error message, including contextual information such as
1288
+ * the location in the input string.
1289
+ */
1290
+ formattedMessage: string;
1291
+ }
1292
+
1293
+ /**
1294
+ * A callback function invoked when a comment is encountered during parsing.
1295
+ *
1296
+ * @param value - The content of the comment.
1297
+ * @param loc - The location range of the comment in the source input.
1298
+ */
1299
+ export type OnParseCommentCallback = (value: string, loc: CssLocationRange) => void;
1300
+
1301
+ /**
1302
+ * A callback function invoked when a parsing error occurs.
1303
+ *
1304
+ * @param error - The parsing error details as a `SyntaxParseError`.
1305
+ * @param fallbackNode - A fallback `CssNode` that can be used in place of the invalid input.
1306
+ */
1307
+ export type OnParseErrorCallback = (error: SyntaxParseError, fallbackNode: CssNode) => void;
1308
+
1309
+ /**
1310
+ * Options for controlling the behavior of the CSS parser.
1311
+ */
1312
+ export interface ParseOptions {
1313
+ /**
1314
+ * The parsing context (e.g., "stylesheet", "value").
1315
+ */
1316
+ context?: string | undefined;
1317
+
1318
+ /**
1319
+ * The at-rule name for parsing its prelude.
1320
+ */
1321
+ atrule?: string | undefined;
1322
+
1323
+ /**
1324
+ * Whether to include position information in the parsed nodes.
1325
+ */
1326
+ positions?: boolean | undefined;
1327
+
1328
+ /**
1329
+ * A callback function invoked for each comment encountered during parsing.
1330
+ */
1331
+ onComment?: OnParseCommentCallback;
1332
+
1333
+ /**
1334
+ * A callback function invoked for handling parsing errors.
1335
+ */
1336
+ onParseError?: OnParseErrorCallback;
1337
+
1338
+ /**
1339
+ * The name of the file being parsed, used for error reporting.
1340
+ */
1341
+ filename?: string | undefined;
1342
+
1343
+ /**
1344
+ * The character offset to start parsing from in the input string.
1345
+ */
1346
+ offset?: number | undefined;
1347
+
1348
+ /**
1349
+ * The line number to start parsing from in the input string.
1350
+ */
1351
+ line?: number | undefined;
1352
+
1353
+ /**
1354
+ * The column number to start parsing from in the input string.
1355
+ */
1356
+ column?: number | undefined;
1357
+
1358
+ /**
1359
+ * Whether to parse the prelude of at-rules.
1360
+ */
1361
+ parseAtrulePrelude?: boolean | undefined;
1362
+
1363
+ /**
1364
+ * Whether to parse the prelude of rules.
1365
+ */
1366
+ parseRulePrelude?: boolean | undefined;
1367
+
1368
+ /**
1369
+ * Whether to parse CSS values.
1370
+ */
1371
+ parseValue?: boolean | undefined;
1372
+
1373
+ /**
1374
+ * Whether to parse custom property values.
1375
+ */
1376
+ parseCustomProperty?: boolean | undefined;
1377
+ }
1378
+
1379
+ /**
1380
+ * A function that parses a CSS string into an abstract syntax tree (AST).
1381
+ *
1382
+ * @param source - The CSS source string to parse.
1383
+ * @param options - Optional configuration for the parser.
1384
+ * @returns The parsed CSS as a `CssNode`.
1385
+ */
1386
+ export type ParseFunction = (source: string, options?: ParseOptions) => CssNode;
1387
+
1388
+ /**
1389
+ * Parses a CSS string into an abstract syntax tree (AST).
1390
+ */
1391
+ export const parse: ParseFunction;
1392
+
1393
+ // ----------------------------------------------------------
1394
+ // Generator
1395
+ // https://github.com/csstree/csstree/tree/master/lib/generator
1396
+ // ----------------------------------------------------------
1397
+
1398
+ /**
1399
+ * Handlers used during the generation of a CSS string from an abstract syntax tree (AST).
1400
+ */
1401
+ export interface GenerateHandlers {
1402
+ /**
1403
+ * Handles traversal of child nodes and applies a delimiter between nodes if specified.
1404
+ *
1405
+ * @param node - The current CSS node whose children are being processed.
1406
+ * @param delimiter - An optional function invoked to add a delimiter between child nodes.
1407
+ */
1408
+ children: (node: CssNode, delimiter?: (node: CssNode) => void) => void;
1409
+
1410
+ /**
1411
+ * Processes an individual CSS node and adds it to the generated output.
1412
+ *
1413
+ * @param node - The current CSS node being processed.
1414
+ */
1415
+ node: (node: CssNode) => void;
1416
+
1417
+ /**
1418
+ * Adds a chunk of CSS text to the generated output.
1419
+ *
1420
+ * @param chunk - The CSS string chunk to add to the output.
1421
+ */
1422
+ chunk: (chunk: string) => void;
1423
+
1424
+ /**
1425
+ * Retrieves the final generated CSS string.
1426
+ *
1427
+ * @returns The generated CSS string.
1428
+ */
1429
+ result: () => string;
1430
+ }
1431
+
1432
+ /**
1433
+ * Specifies the mode to use during CSS generation.
1434
+ * - `"safe"`: Ensures compatibility and avoids unsafe constructs.
1435
+ * - `"spec"`: Adheres strictly to the CSS specification.
1436
+ */
1437
+ export type GenerateMode = "safe" | "spec";
1438
+
1439
+ /**
1440
+ * Options for customizing the behavior of the CSS generator.
1441
+ */
1442
+ export interface GenerateOptions {
1443
+ /**
1444
+ * Whether to include source map information in the generated output.
1445
+ */
1446
+ sourceMap?: boolean | undefined;
1447
+
1448
+ /**
1449
+ * A function to decorate the `GenerateHandlers`, allowing customization
1450
+ * of the behavior during CSS generation.
1451
+ *
1452
+ * @param handlers - The default `GenerateHandlers` instance.
1453
+ * @returns A modified or new `GenerateHandlers` instance.
1454
+ */
1455
+ decorator?: ((handlers: GenerateHandlers) => GenerateHandlers) | undefined;
1456
+
1457
+ /**
1458
+ * The mode to use for CSS generation. Defaults to `"safe"`.
1459
+ */
1460
+ mode?: GenerateMode | undefined;
1461
+ }
1462
+
1463
+ /**
1464
+ * A function that generates a CSS string from an abstract syntax tree (AST).
1465
+ *
1466
+ * @param ast - The CSS abstract syntax tree to generate from.
1467
+ * @param options - Optional configuration for the generator.
1468
+ * @returns The generated CSS string.
1469
+ */
1470
+ export type GenerateFunction = (ast: CssNode, options?: GenerateOptions) => string;
1471
+
1472
+ /**
1473
+ * Generates a CSS string from an abstract syntax tree (AST).
1474
+ */
1475
+ export const generate: GenerateFunction;
1476
+
1477
+ // ----------------------------------------------------------
1478
+ // Walker
1479
+ // ----------------------------------------------------------
1480
+
1481
+ /**
1482
+ * Represents the context in which a tree-walking traversal occurs.
1483
+ */
1484
+ export interface WalkContext {
1485
+ /**
1486
+ * Stops traversal. No visitor function will be invoked once this value is
1487
+ * returned by a visitor.
1488
+ */
1489
+ break: symbol;
1490
+
1491
+ /**
1492
+ * Prevents the current node from being iterated. No visitor function will
1493
+ * be invoked for its properties or children nodes. This value only affects
1494
+ * the `enter` visitor; the `leave` visitor is invoked after iterating
1495
+ * over all node's properties and children.
1496
+ */
1497
+ skip: symbol;
1498
+
1499
+ /**
1500
+ * The root node of the tree being traversed.
1501
+ */
1502
+ root: CssNode;
1503
+
1504
+ /**
1505
+ * The current stylesheet node being visited, or `null` if not applicable.
1506
+ */
1507
+ stylesheet: StyleSheet | null;
1508
+
1509
+ /**
1510
+ * The current at-rule node being visited, or `null` if not applicable.
1511
+ */
1512
+ atrule: Atrule | null;
1513
+
1514
+ /**
1515
+ * The prelude of the current at-rule being visited, or `null` if not applicable.
1516
+ */
1517
+ atrulePrelude: AtrulePrelude | null;
1518
+
1519
+ /**
1520
+ * The current rule node being visited, or `null` if not applicable.
1521
+ */
1522
+ rule: Rule | null;
1523
+
1524
+ /**
1525
+ * The selector list of the current rule, or `null` if not applicable.
1526
+ */
1527
+ selector: SelectorList | null;
1528
+
1529
+ /**
1530
+ * The block of the current rule or at-rule, or `null` if not applicable.
1531
+ */
1532
+ block: Block | null;
1533
+
1534
+ /**
1535
+ * The current declaration node being visited, or `null` if not applicable.
1536
+ */
1537
+ declaration: Declaration | null;
1538
+
1539
+ /**
1540
+ * The current function or pseudo-class/element node being visited,
1541
+ * or `null` if not applicable.
1542
+ */
1543
+ function: FunctionNode | PseudoClassSelector | PseudoElementSelector | null;
1544
+ }
1545
+
1546
+ /**
1547
+ * A function called during tree traversal for entering or leaving a node.
1548
+ *
1549
+ * @param node - The current node being visited.
1550
+ * @param item - The list item corresponding to the current node.
1551
+ * @param list - The list containing the current node.
1552
+ */
1553
+ export type EnterOrLeaveFn<NodeType = CssNode> = (
1554
+ this: WalkContext,
1555
+ node: NodeType,
1556
+ item: ListItem<CssNode>,
1557
+ list: List<CssNode>,
1558
+ ) => void;
1559
+
1560
+ /**
1561
+ * Options for controlling the tree-walking process without specifying a node type to visit.
1562
+ */
1563
+ export interface WalkOptionsNoVisit {
1564
+ /**
1565
+ * A function to invoke when entering a node.
1566
+ */
1567
+ enter?: EnterOrLeaveFn | undefined;
1568
+
1569
+ /**
1570
+ * A function to invoke when leaving a node.
1571
+ */
1572
+ leave?: EnterOrLeaveFn | undefined;
1573
+
1574
+ /**
1575
+ * Whether to traverse the tree in reverse order.
1576
+ */
1577
+ reverse?: boolean | undefined;
1578
+ }
1579
+
1580
+ /**
1581
+ * Options for controlling the tree-walking process with a specific node type to visit.
1582
+ *
1583
+ * @template NodeType - The specific type of node to visit.
1584
+ */
1585
+ export interface WalkOptionsVisit<NodeType extends CssNode = CssNode> {
1586
+ /**
1587
+ * The type of node to visit during traversal.
1588
+ */
1589
+ visit: NodeType["type"];
1590
+
1591
+ /**
1592
+ * A function to invoke when entering a node.
1593
+ */
1594
+ enter?: EnterOrLeaveFn<NodeType> | undefined;
1595
+
1596
+ /**
1597
+ * A function to invoke when leaving a node.
1598
+ */
1599
+ leave?: EnterOrLeaveFn<NodeType> | undefined;
1600
+
1601
+ /**
1602
+ * Whether to traverse the tree in reverse order.
1603
+ */
1604
+ reverse?: boolean | undefined;
1605
+ }
1606
+
1607
+ /**
1608
+ * Combined options for tree-walking, supporting specific node types or general traversal options.
1609
+ */
1610
+ export type WalkOptions =
1611
+ | WalkOptionsVisit<AnPlusB>
1612
+ | WalkOptionsVisit<Atrule>
1613
+ | WalkOptionsVisit<AtrulePrelude>
1614
+ | WalkOptionsVisit<AttributeSelector>
1615
+ | WalkOptionsVisit<Block>
1616
+ | WalkOptionsVisit<Brackets>
1617
+ | WalkOptionsVisit<CDC>
1618
+ | WalkOptionsVisit<CDO>
1619
+ | WalkOptionsVisit<ClassSelector>
1620
+ | WalkOptionsVisit<Combinator>
1621
+ | WalkOptionsVisit<Comment>
1622
+ | WalkOptionsVisit<Declaration>
1623
+ | WalkOptionsVisit<DeclarationList>
1624
+ | WalkOptionsVisit<Dimension>
1625
+ | WalkOptionsVisit<FunctionNode>
1626
+ | WalkOptionsVisit<Hash>
1627
+ | WalkOptionsVisit<IdSelector>
1628
+ | WalkOptionsVisit<Identifier>
1629
+ | WalkOptionsVisit<MediaFeature>
1630
+ | WalkOptionsVisit<MediaQuery>
1631
+ | WalkOptionsVisit<MediaQueryList>
1632
+ | WalkOptionsVisit<Nth>
1633
+ | WalkOptionsVisit<NumberNode>
1634
+ | WalkOptionsVisit<Operator>
1635
+ | WalkOptionsVisit<Parentheses>
1636
+ | WalkOptionsVisit<Percentage>
1637
+ | WalkOptionsVisit<PseudoClassSelector>
1638
+ | WalkOptionsVisit<PseudoElementSelector>
1639
+ | WalkOptionsVisit<Ratio>
1640
+ | WalkOptionsVisit<Raw>
1641
+ | WalkOptionsVisit<Rule>
1642
+ | WalkOptionsVisit<Selector>
1643
+ | WalkOptionsVisit<SelectorList>
1644
+ | WalkOptionsVisit<StringNode>
1645
+ | WalkOptionsVisit<StyleSheet>
1646
+ | WalkOptionsVisit<TypeSelector>
1647
+ | WalkOptionsVisit<UnicodeRange>
1648
+ | WalkOptionsVisit<Url>
1649
+ | WalkOptionsVisit<Value>
1650
+ | WalkOptionsVisit<WhiteSpace>
1651
+ | WalkOptionsNoVisit;
1652
+
1653
+ /**
1654
+ * Walks through a CSS abstract syntax tree (AST) and invokes callback functions on nodes.
1655
+ */
1656
+ export const walk: {
1657
+ /**
1658
+ * Performs a traversal of the given AST.
1659
+ *
1660
+ * @param ast - The CSS abstract syntax tree to traverse.
1661
+ * @param options - The options controlling the traversal process.
1662
+ */
1663
+ (ast: CssNode, options: EnterOrLeaveFn | WalkOptions): void;
1664
+
1665
+ /**
1666
+ * Stops traversal. No visitor function will be invoked once this value is returned by a visitor.
1667
+ */
1668
+ readonly break: symbol;
1669
+
1670
+ /**
1671
+ * Prevents the current node from being iterated. No visitor function will be invoked for its properties or children
1672
+ * nodes. This value only affects the `enter` visitor.
1673
+ */
1674
+ readonly skip: symbol;
1675
+ };
1676
+
1677
+ /**
1678
+ * A predicate function used to find specific nodes during tree traversal.
1679
+ *
1680
+ * @param node - The current node being visited.
1681
+ * @param item - The list item corresponding to the current node.
1682
+ * @param list - The list containing the current node.
1683
+ * @returns `true` if the node matches the condition; `false` otherwise.
1684
+ */
1685
+ export type FindFn = (this: WalkContext, node: CssNode, item: ListItem<CssNode>, list: List<CssNode>) => boolean;
1686
+
1687
+ /**
1688
+ * Finds the first node in the tree that matches the specified predicate function.
1689
+ *
1690
+ * @param ast - The CSS abstract syntax tree to search.
1691
+ * @param fn - The predicate function to match nodes.
1692
+ * @returns The first matching node, or `null` if no match is found.
1693
+ */
1694
+ export function find(ast: CssNode, fn: FindFn): CssNode | null;
1695
+
1696
+ /**
1697
+ * Finds the last node in the tree that matches the specified predicate function.
1698
+ *
1699
+ * @param ast - The CSS abstract syntax tree to search.
1700
+ * @param fn - The predicate function to match nodes.
1701
+ * @returns The last matching node, or `null` if no match is found.
1702
+ */
1703
+ export function findLast(ast: CssNode, fn: FindFn): CssNode | null;
1704
+
1705
+ /**
1706
+ * Finds all nodes in the tree that match the specified predicate function.
1707
+ *
1708
+ * @param ast - The CSS abstract syntax tree to search.
1709
+ * @param fn - The predicate function to match nodes.
1710
+ * @returns An array of all matching nodes.
1711
+ */
1712
+ export function findAll(ast: CssNode, fn: FindFn): CssNode[];
1713
+
1714
+ // ----------------------------------------------------------
1715
+ // Name utils
1716
+ // https://github.com/csstree/csstree/blob/master/lib/utils/names.js
1717
+ // ----------------------------------------------------------
1718
+
1719
+ /**
1720
+ * Represents a CSS property with detailed metadata, including vendor and custom information.
1721
+ */
1722
+ export interface Property {
1723
+ /**
1724
+ * The base name of the property, excluding vendor prefixes or hacks.
1725
+ */
1726
+ readonly basename: string;
1727
+
1728
+ /**
1729
+ * The full name of the property, including any vendor prefixes or hacks.
1730
+ */
1731
+ readonly name: string;
1732
+
1733
+ /**
1734
+ * Any hack associated with the property (e.g., `_`, `*`, `$`).
1735
+ */
1736
+ readonly hack: string;
1737
+
1738
+ /**
1739
+ * The vendor prefix of the property, if present (e.g., `-webkit-`).
1740
+ */
1741
+ readonly vendor: string;
1742
+
1743
+ /**
1744
+ * The prefix used for the property, including vendor prefixes or hacks.
1745
+ */
1746
+ readonly prefix: string;
1747
+
1748
+ /**
1749
+ * Indicates whether the property is a custom property (e.g., `--property-name`).
1750
+ */
1751
+ readonly custom: boolean;
1752
+ }
1753
+
1754
+ /**
1755
+ * Parses a CSS property name and returns detailed metadata about the property.
1756
+ *
1757
+ * @param value - The CSS property name to parse.
1758
+ * @returns A `Property` object with metadata about the parsed property.
1759
+ */
1760
+ export function property(value: string): Property;
1761
+
1762
+ /**
1763
+ * Represents a CSS keyword with detailed metadata, including vendor and custom information.
1764
+ */
1765
+ export interface Keyword {
1766
+ /**
1767
+ * The base name of the keyword, excluding vendor prefixes.
1768
+ */
1769
+ readonly basename: string;
1770
+
1771
+ /**
1772
+ * The full name of the keyword, including any vendor prefixes.
1773
+ */
1774
+ readonly name: string;
1775
+
1776
+ /**
1777
+ * The vendor prefix of the keyword, if present (e.g., `-webkit-`).
1778
+ */
1779
+ readonly vendor: string;
1780
+
1781
+ /**
1782
+ * The prefix used for the keyword, including vendor prefixes.
1783
+ */
1784
+ readonly prefix: string;
1785
+
1786
+ /**
1787
+ * Indicates whether the keyword is a custom property.
1788
+ */
1789
+ readonly custom: boolean;
1790
+ }
1791
+
1792
+ /**
1793
+ * Parses a CSS keyword and returns detailed metadata about the keyword.
1794
+ *
1795
+ * @param value - The CSS keyword to parse.
1796
+ * @returns A `Keyword` object with metadata about the parsed keyword.
1797
+ */
1798
+ export function keyword(value: string): Keyword;
1799
+
1800
+ /**
1801
+ * Extracts the vendor prefix from a given string.
1802
+ *
1803
+ * @param str - The string to extract the vendor prefix from.
1804
+ * @param offset - The starting position in the string.
1805
+ * @returns The extracted vendor prefix, or an empty string if none exists.
1806
+ */
1807
+ export function vendorPrefix(str: string, offset: number): string;
1808
+
1809
+ /**
1810
+ * Determines whether a given string represents a custom property.
1811
+ *
1812
+ * @param str - The string to check.
1813
+ * @param offset - The starting position in the string.
1814
+ * @returns `true` if the string represents a custom property, `false` otherwise.
1815
+ */
1816
+ export function isCustomProperty(str: string, offset: number): boolean;
1817
+
1818
+ // ----------------------------------------------------------
1819
+ // Clone
1820
+ // https://github.com/csstree/csstree/blob/master/lib/utils/clone.js
1821
+ // ----------------------------------------------------------
1822
+
1823
+ /**
1824
+ * Creates a deep copy of a CSS abstract syntax tree (AST) node.
1825
+ *
1826
+ * @param node - The `CssNode` to clone.
1827
+ * @returns A new `CssNode` instance that is a deep copy of the provided node.
1828
+ */
1829
+ export function clone(node: CssNode): CssNode;
1830
+
1831
+ // ----------------------------------------------------------
1832
+ // Convertor
1833
+ // https://github.com/csstree/csstree/blob/master/lib/convertor/create.js
1834
+ // ----------------------------------------------------------
1835
+
1836
+ export function fromPlainObject(node: CssNodePlain): CssNode;
1837
+
1838
+ export function toPlainObject(node: CssNode): CssNodePlain;
1839
+
1840
+ // ----------------------------------------------------------
1841
+ // Definition syntax
1842
+ // https://github.com/csstree/csstree/tree/master/lib/definition-syntax
1843
+ // ----------------------------------------------------------
1844
+
1845
+ /**
1846
+ * Definition syntax AtWord node
1847
+ */
1848
+ export interface DSNodeAtWord {
1849
+ type: "AtKeyword";
1850
+ name: string;
1851
+ }
1852
+
1853
+ /**
1854
+ * Definition syntax Comma node
1855
+ */
1856
+ export interface DSNodeComma {
1857
+ type: "Comma";
1858
+ }
1859
+
1860
+ /**
1861
+ * Definition syntax Function node
1862
+ */
1863
+ export interface DSNodeFunction {
1864
+ type: "Function";
1865
+ name: string;
1866
+ }
1867
+
1868
+ export type DSNodeCombinator = "|" | "||" | "&&" | " ";
1869
+
1870
+ /**
1871
+ * Definition syntax Group node
1872
+ */
1873
+ export interface DSNodeGroup {
1874
+ type: "Group";
1875
+ terms: DSNode[];
1876
+ combinator: DSNodeCombinator;
1877
+ disallowEmpty: boolean;
1878
+ explicit: boolean;
1879
+ }
1880
+
1881
+ /**
1882
+ * Definition syntax Keyword node
1883
+ */
1884
+ export interface DSNodeKeyword {
1885
+ type: "Keyword";
1886
+ name: string;
1887
+ }
1888
+
1889
+ /**
1890
+ * Definition syntax Multiplier node
1891
+ */
1892
+ export interface DSNodeMultiplier {
1893
+ type: "Multiplier";
1894
+ comma: boolean;
1895
+ min: number;
1896
+ max: number;
1897
+ term: DSNodeMultiplied;
1898
+ }
1899
+
1900
+ /**
1901
+ * Definition syntax Property node
1902
+ */
1903
+ export interface DSNodeProperty {
1904
+ type: "Property";
1905
+ name: string;
1906
+ }
1907
+
1908
+ /**
1909
+ * Definition syntax String node
1910
+ */
1911
+ export interface DSNodeString {
1912
+ type: "String";
1913
+ value: string;
1914
+ }
1915
+
1916
+ /**
1917
+ * Definition syntax Token node
1918
+ */
1919
+ export interface DSNodeToken {
1920
+ type: "Token";
1921
+ value: string;
1922
+ }
1923
+
1924
+ /**
1925
+ * Definition syntax Type node options
1926
+ */
1927
+ export interface DSNodeTypeOpts {
1928
+ type: "Range";
1929
+ min: number | null;
1930
+ max: number | null;
1931
+ }
1932
+
1933
+ /**
1934
+ * Definition syntax Type node
1935
+ */
1936
+ export interface DSNodeType {
1937
+ type: "Type";
1938
+ name: string;
1939
+ opts: DSNodeTypeOpts | null;
1940
+ }
1941
+
1942
+ /**
1943
+ * Definition syntax node
1944
+ */
1945
+ export type DSNode =
1946
+ | DSNodeAtWord
1947
+ | DSNodeComma
1948
+ | DSNodeFunction
1949
+ | DSNodeGroup
1950
+ | DSNodeKeyword
1951
+ | DSNodeMultiplier
1952
+ | DSNodeProperty
1953
+ | DSNodeString
1954
+ | DSNodeToken
1955
+ | DSNodeType;
1956
+
1957
+ /**
1958
+ * Definition syntax node compatible with a multiplier
1959
+ */
1960
+ export type DSNodeMultiplied =
1961
+ | DSNodeFunction
1962
+ | DSNodeGroup
1963
+ | DSNodeKeyword
1964
+ | DSNodeProperty
1965
+ | DSNodeString
1966
+ | DSNodeType;
1967
+
1968
+ /**
1969
+ * Definition syntax generate options
1970
+ */
1971
+ export interface DSGenerateOptions {
1972
+ forceBraces?: boolean | undefined;
1973
+ compact?: boolean | undefined;
1974
+ decorate?: ((result: string, node: DSNode) => void) | undefined;
1975
+ }
1976
+
1977
+ /**
1978
+ * Definition syntax walk options
1979
+ */
1980
+ export interface DSWalkOptions {
1981
+ enter?: DSWalkEnterOrLeaveFn | undefined;
1982
+ leave?: DSWalkEnterOrLeaveFn | undefined;
1983
+ }
1984
+
1985
+ /**
1986
+ * Definition syntax walk callback
1987
+ */
1988
+ export type DSWalkEnterOrLeaveFn = (node: DSNode) => void;
1989
+
1990
+ /**
1991
+ * DefinitionSyntax
1992
+ */
1993
+ export interface DefinitionSyntax {
1994
+ /**
1995
+ * Generates CSS value definition syntax from an AST
1996
+ *
1997
+ * @param node - The AST
1998
+ * @param options - Options that affect generation
1999
+ *
2000
+ * @example
2001
+ * generate({type: 'Keyword', name: 'foo'}) => 'foo'
2002
+ */
2003
+ generate(node: DSNode, options?: DSGenerateOptions): string;
2004
+
2005
+ /**
2006
+ * Generates an AST from a CSS value syntax
2007
+ *
2008
+ * @param source - The CSS value syntax to parse
2009
+ *
2010
+ * @example
2011
+ * parse('foo | bar') =>
2012
+ * {
2013
+ * type: 'Group',
2014
+ * terms: [
2015
+ * { type: 'Keyword', name: 'foo' },
2016
+ * { type: 'Keyword', name: 'bar' }
2017
+ * ],
2018
+ * combinator: '|',
2019
+ * disallowEmpty: false,
2020
+ * explicit: false
2021
+ * }
2022
+ */
2023
+ parse(source: string): DSNodeGroup;
2024
+
2025
+ /**
2026
+ * Walks definition syntax AST
2027
+ */
2028
+ walk(node: DSNode, options: DSWalkEnterOrLeaveFn | DSWalkOptions, context?: any): void;
2029
+
2030
+ /**
2031
+ * Wrapper for syntax errors
2032
+ */
2033
+ syntaxError: SyntaxError;
2034
+ }
2035
+
2036
+ export const definitionSyntax: DefinitionSyntax;
2037
+
2038
+ // ----------------------------------------------------------
2039
+ // Ident utils
2040
+ // https://github.com/csstree/csstree/blob/master/lib/utils/ident.js
2041
+ // ----------------------------------------------------------
2042
+
2043
+ /**
2044
+ * Utilities for encoding and decoding CSS identifiers.
2045
+ */
2046
+ export const ident: {
2047
+ /**
2048
+ * Decodes a CSS identifier from its escaped form.
2049
+ *
2050
+ * @param input - The escaped CSS identifier to decode.
2051
+ * @returns The decoded identifier as a string.
2052
+ */
2053
+ decode(input: string): string;
2054
+
2055
+ /**
2056
+ * Encodes a string into a valid CSS identifier, escaping special characters as necessary.
2057
+ *
2058
+ * @param input - The string to encode as a CSS identifier.
2059
+ * @returns The encoded CSS identifier.
2060
+ */
2061
+ encode(input: string): string;
2062
+ };
2063
+
2064
+ // ----------------------------------------------------------
2065
+ // String utils
2066
+ // https://github.com/csstree/csstree/blob/master/lib/utils/string.js
2067
+ // ----------------------------------------------------------
2068
+
2069
+ /**
2070
+ * Utilities for encoding and decoding CSS strings.
2071
+ */
2072
+ export const string: {
2073
+ /**
2074
+ * Encodes a string into a valid CSS string, escaping special characters as necessary.
2075
+ * Optionally uses apostrophes (`'`) instead of quotation marks (`"`).
2076
+ *
2077
+ * @param input - The string to encode.
2078
+ * @param apostrophe - Whether to use apostrophes for the string. Defaults to `false`.
2079
+ * @returns The encoded CSS string.
2080
+ */
2081
+ encode(input: string, apostrophe?: boolean): string;
2082
+
2083
+ /**
2084
+ * Decodes a CSS string from its escaped form.
2085
+ *
2086
+ * @param input - The escaped CSS string to decode.
2087
+ * @returns The decoded string.
2088
+ */
2089
+ decode(input: string): string;
2090
+ };
2091
+
2092
+ // ----------------------------------------------------------
2093
+ // URL utils
2094
+ // https://github.com/csstree/csstree/blob/master/lib/utils/url.js
2095
+ // ----------------------------------------------------------
2096
+
2097
+ /**
2098
+ * Utilities for encoding and decoding CSS URLs.
2099
+ */
2100
+ export const url: {
2101
+ /**
2102
+ * Decodes a CSS URL from its escaped form.
2103
+ *
2104
+ * @param input - The escaped CSS URL to decode.
2105
+ * @returns The decoded URL as a string.
2106
+ */
2107
+ decode(input: string): string;
2108
+
2109
+ /**
2110
+ * Encodes a string into a valid CSS URL, escaping special characters as necessary.
2111
+ *
2112
+ * @param input - The string to encode as a CSS URL.
2113
+ * @returns The encoded CSS URL.
2114
+ */
2115
+ encode(input: string): string;
2116
+ };
2117
+
2118
+ // ----------------------------------------------------------
2119
+ // Lexer
2120
+ // https://github.com/csstree/csstree/blob/master/lib/lexer/Lexer.js
2121
+ // ----------------------------------------------------------
2122
+
2123
+ /**
2124
+ * Represents an error that occurs during the syntax matching process.
2125
+ * Extends the standard `SyntaxError` with additional properties specific to CSS parsing.
2126
+ */
2127
+ export class SyntaxMatchError extends SyntaxError {
2128
+ /**
2129
+ * The raw error message before formatting.
2130
+ */
2131
+ rawMessage: string;
2132
+
2133
+ /**
2134
+ * The CSS syntax that was being matched when the error occurred.
2135
+ */
2136
+ syntax: string;
2137
+
2138
+ /**
2139
+ * The CSS code where the mismatch occurred.
2140
+ */
2141
+ css: string;
2142
+
2143
+ /**
2144
+ * The offset (character position) within the CSS string where the mismatch occurred.
2145
+ */
2146
+ mismatchOffset: number;
2147
+
2148
+ /**
2149
+ * The length (number of characters) of the mismatched segment.
2150
+ */
2151
+ mismatchLength: number;
2152
+
2153
+ /**
2154
+ * The overall offset (character position) from the start of the CSS input.
2155
+ */
2156
+ offset: number;
2157
+
2158
+ /**
2159
+ * The line number (1-indexed) where the mismatch occurred.
2160
+ */
2161
+ line: number;
2162
+
2163
+ /**
2164
+ * The column number (1-indexed) within the line where the mismatch occurred.
2165
+ */
2166
+ column: number;
2167
+
2168
+ /**
2169
+ * The location range within the CSS input where the mismatch occurred.
2170
+ */
2171
+ loc: CssLocationRange;
2172
+ }
2173
+
2174
+ /**
2175
+ * Represents an error that occurs when a reference to a syntax rule is invalid
2176
+ * or cannot be resolved. Extends the standard `SyntaxError`.
2177
+ */
2178
+ export class SyntaxReferenceError extends SyntaxError {
2179
+ /**
2180
+ * The reference to the syntax rule that caused the error.
2181
+ */
2182
+ reference: string;
2183
+ }
2184
+
2185
+ /**
2186
+ * Represents the result of a lexer match operation.
2187
+ */
2188
+ export interface LexerMatchResult {
2189
+ /**
2190
+ * The matched CSS node, or `null` if no match was found.
2191
+ */
2192
+ matched: CssNode | null;
2193
+
2194
+ /**
2195
+ * The number of iterations performed during the matching process.
2196
+ */
2197
+ iterations: number;
2198
+
2199
+ /**
2200
+ * An error object if a matching error occurred, or `null` if no error.
2201
+ */
2202
+ error: Error | SyntaxMatchError | SyntaxReferenceError | null;
2203
+
2204
+ /**
2205
+ * Retrieves the trace of matching operations for a specific node.
2206
+ *
2207
+ * @param node - The CSS node to trace.
2208
+ * @returns An array of `SyntaxDescriptor` objects or `null` if tracing is not applicable.
2209
+ */
2210
+ getTrace: (node: CssNode) => SyntaxDescriptor[] | null;
2211
+
2212
+ /**
2213
+ * Checks if the specified node is a keyword.
2214
+ *
2215
+ * @param node - The CSS node to check.
2216
+ * @returns `true` if the node is a keyword, `false` otherwise.
2217
+ */
2218
+ isKeyword: (node: CssNode) => boolean;
2219
+
2220
+ /**
2221
+ * Checks if the specified node matches a specific property.
2222
+ *
2223
+ * @param node - The CSS node to check.
2224
+ * @param property - The property name to match against.
2225
+ * @returns `true` if the node matches the property, `false` otherwise.
2226
+ */
2227
+ isProperty: (node: CssNode, property: string) => boolean;
2228
+
2229
+ /**
2230
+ * Checks if the specified node matches a specific type.
2231
+ *
2232
+ * @param node - The CSS node to check.
2233
+ * @param type - The type name to match against.
2234
+ * @returns `true` if the node matches the type, `false` otherwise.
2235
+ */
2236
+ isType: (node: CssNode, type: string) => boolean;
2237
+ }
2238
+
2239
+ type ConsumerFunction = (this: ParserContext, ...args: unknown[]) => CssNode;
2240
+
2241
+ // https://github.com/csstree/csstree/tree/master/lib/syntax/scope
2242
+ /**
2243
+ * Recognizer is responsible for identifying specific patterns or constructs within the CSS syntax.
2244
+ * It provides methods to interpret and handle these constructs during parsing.
2245
+ */
2246
+ // FIXME
2247
+ interface Recognizer {
2248
+ /**
2249
+ * Retrieves a node based on the provided parsing context.
2250
+ *
2251
+ * @param context - The parsing context, which contains relevant state and configuration for the parser.
2252
+ * @returns A function that, when executed, produces a `CssNode`.
2253
+ */
2254
+ getNode(context: ParserContext): (this: ParserContext) => CssNode;
2255
+
2256
+ // /**
2257
+ // * Handles whitespace between CSS selectors during parsing.
2258
+ // * Ensures that whitespace is correctly interpreted as a descendant combinator.
2259
+ // *
2260
+ // * @param next - The next node or token in the parsing sequence.
2261
+ // * @param children - The list of parsed nodes, which will be modified to include a `Combinator` node if applicable.
2262
+ // */
2263
+ // onWhiteSpace?(next: CssNode | null, children: CssNodeList): void;
2264
+ }
2265
+
2266
+ /**
2267
+ * The `Parser` interface defines the methods and properties used for parsing CSS syntax.
2268
+ *
2269
+ * @see {@link https://github.com/csstree/csstree/blob/9de5189fadd6fb4e3a149eec0e80d6ed0d0541e5/lib/parser/create.js#L91-L293}
2270
+ */
2271
+ interface Parser {
2272
+ /**
2273
+ * Indicates whether at-rule prelude parsing is enabled.
2274
+ */
2275
+ parseAtrulePrelude: boolean;
2276
+
2277
+ /**
2278
+ * Indicates whether rule prelude parsing is enabled.
2279
+ */
2280
+ parseRulePrelude: boolean;
2281
+
2282
+ /**
2283
+ * Indicates whether value parsing is enabled.
2284
+ */
2285
+ parseValue: boolean;
2286
+
2287
+ /**
2288
+ * Indicates whether custom property parsing is enabled.
2289
+ */
2290
+ parseCustomProperty: boolean;
2291
+
2292
+ /**
2293
+ * Reads a sequence of CSS nodes based on the provided recognizer.
2294
+ *
2295
+ * @param recognizer - A recognizer instance to determine node boundaries.
2296
+ * @returns A list of parsed `CssNode` objects.
2297
+ */
2298
+ readSequence(this: ParserContext, recognizer: Recognizer): List<CssNode>;
2299
+
2300
+ /**
2301
+ * Consumes input until the end of a balance context is reached.
2302
+ *
2303
+ * @returns Always returns `0`.
2304
+ */
2305
+ consumeUntilBalanceEnd: (this: ParserContext) => 0;
2306
+
2307
+ /**
2308
+ * Consumes input until a left curly bracket (`{`) is encountered.
2309
+ *
2310
+ * @param code - The character code to check.
2311
+ * @returns `0` or `1` depending on the outcome.
2312
+ */
2313
+ consumeUntilLeftCurlyBracket: (this: ParserContext, code: number) => 0 | 1;
2314
+
2315
+ /**
2316
+ * Consumes input until a left curly bracket (`{`) or semicolon (`;`) is encountered.
2317
+ *
2318
+ * @param code - The character code to check.
2319
+ * @returns `0` or `1` depending on the outcome.
2320
+ */
2321
+ consumeUntilLeftCurlyBracketOrSemicolon: (this: ParserContext, code: number) => 0 | 1;
2322
+
2323
+ /**
2324
+ * Consumes input until an exclamation mark (`!`) or semicolon (`;`) is encountered.
2325
+ *
2326
+ * @param code - The character code to check.
2327
+ * @returns `0` or `1` depending on the outcome.
2328
+ */
2329
+ consumeUntilExclamationMarkOrSemicolon: (this: ParserContext, code: number) => 0 | 1;
2330
+
2331
+ /**
2332
+ * Consumes input until a semicolon (`;`) is included.
2333
+ *
2334
+ * @returns `0` or `2` depending on the outcome.
2335
+ */
2336
+ consumeUntilSemicolonIncluded: (this: ParserContext) => 0 | 2;
2337
+
2338
+ /**
2339
+ * Creates a new, empty list of CSS nodes.
2340
+ *
2341
+ * @returns A new `List` of `CssNode` objects.
2342
+ */
2343
+ createList: (this: ParserContext) => List<CssNode>;
2344
+
2345
+ /**
2346
+ * Creates a new list containing a single CSS node.
2347
+ *
2348
+ * @param node - The node to include in the list.
2349
+ * @returns A new `List` containing the provided node.
2350
+ */
2351
+ createSingleNodeList: (this: ParserContext, node: CssNode) => List<CssNode>;
2352
+
2353
+ /**
2354
+ * Retrieves the first item from a list of CSS nodes.
2355
+ *
2356
+ * @param list - The list to process.
2357
+ * @returns The first list item, or `null` if the list is empty.
2358
+ */
2359
+ getFirstListNode: (this: ParserContext, list: List<CssNode>) => ListItem<CssNode> | null;
2360
+
2361
+ /**
2362
+ * Retrieves the last item from a list of CSS nodes.
2363
+ *
2364
+ * @param list - The list to process.
2365
+ * @returns The last list item, or `null` if the list is empty.
2366
+ */
2367
+ getLastListNode: (this: ParserContext, list: List<CssNode>) => ListItem<CssNode> | null;
2368
+
2369
+ /**
2370
+ * Parses input using a consumer function, with a fallback function as a backup.
2371
+ *
2372
+ * @param consumer - The primary function to parse input.
2373
+ * @param fallback - The fallback function to use if the primary function fails.
2374
+ * @returns A `CssNode` parsed from the input.
2375
+ */
2376
+ parseWithFallback: (this: ParserContext, consumer: ConsumerFunction, fallback: ConsumerFunction) => CssNode;
2377
+
2378
+ /**
2379
+ * Looks up a non-whitespace token type at a given offset.
2380
+ *
2381
+ * @param offset - The offset to check.
2382
+ * @returns The token type code.
2383
+ */
2384
+ lookupNonWSType: (this: ParserContext, offset: number) => number;
2385
+
2386
+ /**
2387
+ * Retrieves the character code at a specific offset.
2388
+ *
2389
+ * @param offset - The offset to check.
2390
+ * @returns The character code.
2391
+ */
2392
+ charCodeAt: (this: ParserContext, offset: number) => number;
2393
+
2394
+ /**
2395
+ * Extracts a substring from the input based on the provided offsets.
2396
+ *
2397
+ * @param offsetStart - The start offset.
2398
+ * @param offsetEnd - The end offset.
2399
+ * @returns The extracted substring.
2400
+ */
2401
+ substring: (this: ParserContext, offsetStart: number, offsetEnd: number) => string;
2402
+
2403
+ /**
2404
+ * Extracts a substring from the input starting at a specific point up to the cursor.
2405
+ *
2406
+ * @param start - The start offset.
2407
+ * @returns The extracted substring.
2408
+ */
2409
+ substrToCursor: (this: ParserContext, start: number) => string;
2410
+
2411
+ /**
2412
+ * Compares a character at a specific offset with a given character code.
2413
+ *
2414
+ * @param offset - The offset to check.
2415
+ * @param charCode - The character code to compare against.
2416
+ * @returns `true` if the character matches, `false` otherwise.
2417
+ */
2418
+ cmpChar: (this: ParserContext, offset: number, charCode: number) => boolean;
2419
+
2420
+ /**
2421
+ * Compares a substring with a given string.
2422
+ *
2423
+ * @param offsetStart - The start offset.
2424
+ * @param offsetEnd - The end offset.
2425
+ * @param str - The string to compare against.
2426
+ * @returns `true` if the substring matches, `false` otherwise.
2427
+ */
2428
+ cmpStr: (this: ParserContext, offsetStart: number, offsetEnd: number, str: string) => boolean;
2429
+
2430
+ /**
2431
+ * Consumes a token of a specific type from the input.
2432
+ *
2433
+ * @param tokenType - The token type to consume.
2434
+ * @returns The consumed token value.
2435
+ */
2436
+ consume: (this: ParserContext, tokenType: number) => string;
2437
+
2438
+ /**
2439
+ * Consumes a function name token from the input.
2440
+ *
2441
+ * @returns The consumed function name.
2442
+ */
2443
+ consumeFunctionName: (this: ParserContext) => string;
2444
+
2445
+ /**
2446
+ * Consumes a number token from the input.
2447
+ *
2448
+ * @param type - The type of number to consume.
2449
+ * @returns The consumed number value.
2450
+ */
2451
+ consumeNumber: (this: ParserContext, type: number) => string;
2452
+
2453
+ /**
2454
+ * Consumes a specific token type from the input without returning its value.
2455
+ *
2456
+ * @param tokenType - The token type to consume.
2457
+ */
2458
+ eat: (this: ParserContext, tokenType: number) => void;
2459
+
2460
+ /**
2461
+ * Consumes an identifier token with a specific name.
2462
+ *
2463
+ * @param name - The name of the identifier to consume.
2464
+ */
2465
+ eatIdent: (this: ParserContext, name: string) => void;
2466
+
2467
+ /**
2468
+ * Consumes a delimiter token with a specific character code.
2469
+ *
2470
+ * @param code - The character code of the delimiter to consume.
2471
+ */
2472
+ eatDelim: (this: ParserContext, code: number) => void;
2473
+
2474
+ /**
2475
+ * Retrieves the location range of a specific segment of input.
2476
+ *
2477
+ * @param start - The start offset.
2478
+ * @param end - The end offset.
2479
+ * @returns The location range, or `null` if unavailable.
2480
+ */
2481
+ getLocation: (this: ParserContext, start: number, end: number) => CssLocationRange | null;
2482
+
2483
+ /**
2484
+ * Retrieves the location range from a list of CSS nodes.
2485
+ *
2486
+ * @param list - The list of CSS nodes.
2487
+ * @returns The location range, or `null` if unavailable.
2488
+ */
2489
+ getLocationFromList: (this: ParserContext, list: List<CssNode>) => CssLocationRange | null;
2490
+
2491
+ /**
2492
+ * Reports a parsing error with a specific message and offset.
2493
+ *
2494
+ * @param message - The error message.
2495
+ * @param offset - The offset at which the error occurred.
2496
+ */
2497
+ error: (this: ParserContext, message: string, offset: number) => void;
2498
+ }
2499
+
2500
+ // https://github.com/csstree/csstree/blob/9de5189fadd6fb4e3a149eec0e80d6ed0d0541e5/lib/parser/create.js#L53-L80
2501
+ type ParseConfig = {
2502
+ context: Record<string, ConsumerFunction | undefined>;
2503
+ atrule: Record<string, ConsumerFunction | undefined>;
2504
+ pseudo: Record<string, ConsumerFunction | undefined>;
2505
+ // node: Record<CssNodeNames, ConsumerFunction> & Record<string, ConsumerFunction | undefined>;
2506
+ node: Record<string, ConsumerFunction | undefined>;
2507
+ } & Pick<SyntaxConfig, 'features' | 'scope'>;
2508
+
2509
+ // https://github.com/csstree/csstree/blob/9de5189fadd6fb4e3a149eec0e80d6ed0d0541e5/lib/parser/create.js#L90
2510
+ type ParserContext = TokenStream
2511
+ & ParseConfig
2512
+ & { config: ParseConfig }
2513
+ & Parser
2514
+ & {
2515
+ // Anything else
2516
+ [key: string]: unknown;
2517
+ };
2518
+
2519
+ interface StructureDescriptor {
2520
+ type: string;
2521
+ optional?: boolean;
2522
+ parse?: (this: ParserContext) => CssNodeCommon;
2523
+ generate?: (this: ParserContext, node: CssNodeCommon) => void;
2524
+ }
2525
+
2526
+ interface NodeSyntaxConfig<T extends CssNodeCommon = CssNodeCommon> {
2527
+ name: string;
2528
+ structure: Record<string, StructureDescriptor>;
2529
+ parse(this: ParserContext): T;
2530
+ generate(this: ParserContext, node: T): void;
2531
+ walkContext: WalkContext;
2532
+ }
2533
+
2534
+ interface AtruleSyntax {
2535
+ prelude: string | null;
2536
+ descriptors: Record<string, string> | null;
2537
+ }
2538
+
2539
+ // https://github.com/csstree/csstree/blob/9de5189fadd6fb4e3a149eec0e80d6ed0d0541e5/lib/syntax/config/parser.js#L7-L28
2540
+ interface ParseContext {
2541
+ default: string;
2542
+
2543
+ /**
2544
+ * Key is name
2545
+ * Value is context
2546
+ */
2547
+ [key: string]: string | ((options: Record<string, unknown>) => CssNode);
2548
+ }
2549
+
2550
+ export interface SyntaxConfig<T extends CssNodeCommon = CssNodeCommon> {
2551
+ generic: boolean;
2552
+ units: Record<string, string[]>;
2553
+ types: Record<string, string>;
2554
+ properties: Record<string, string>;
2555
+ atrules: Record<string, AtruleSyntax>;
2556
+ node: Record<string, NodeSyntaxConfig<T>>;
2557
+ atrule: Record<string, { parse: ConsumerFunction; }>;
2558
+ pseudo: Record<string, { parse: ConsumerFunction; }>;
2559
+ scope: Record<string, Recognizer>;
2560
+ features: Record<string, Recognizer>;
2561
+ parseContext: ParseContext;
2562
+ }
2563
+
2564
+ interface LexerStructureWarning {
2565
+ node: CssNode;
2566
+ message: string;
2567
+ }
2568
+
2569
+ type StructureDocs = Record<string, string>;
2570
+
2571
+ type StructureCheckCallback = (node: CssNode, message: string) => void;
2572
+
2573
+ type StructureCheckFunction = (node: CssNode, warn: StructureCheckCallback) => void;
2574
+
2575
+ interface StructureData {
2576
+ docs: StructureDocs;
2577
+ check: StructureCheckFunction;
2578
+ }
2579
+
2580
+ type Structure = Record<string, StructureData>;
2581
+
2582
+ /**
2583
+ * Represents a collection of tools and utilities for working with CSS syntax,
2584
+ * including parsing, generating, walking, and manipulating CSS abstract syntax trees (ASTs).
2585
+ */
2586
+ interface Syntax {
2587
+ /**
2588
+ * The `Lexer` instance used for matching and validating CSS syntax.
2589
+ */
2590
+ lexer: Lexer;
2591
+
2592
+ /**
2593
+ * Creates a new `Lexer` instance with the specified configuration.
2594
+ *
2595
+ * @param config - The syntax configuration object.
2596
+ * @returns A new `Lexer` instance.
2597
+ */
2598
+ createLexer: (config: SyntaxConfig) => Lexer;
2599
+
2600
+ /**
2601
+ * Tokenizes a CSS string into a stream of tokens.
2602
+ */
2603
+ tokenize: TokenizeFunction;
2604
+
2605
+ /**
2606
+ * Parses a CSS string into an abstract syntax tree (AST).
2607
+ */
2608
+ parse: ParseFunction;
2609
+
2610
+ /**
2611
+ * Generates a CSS string from an abstract syntax tree (AST).
2612
+ */
2613
+ generate: GenerateFunction;
2614
+
2615
+ /**
2616
+ * Walks through a CSS abstract syntax tree (AST) and applies a callback function to each node.
2617
+ *
2618
+ * @see {@link walk}
2619
+ */
2620
+ walk: typeof walk;
2621
+
2622
+ /**
2623
+ * Finds the first node in a CSS abstract syntax tree (AST) that matches a given condition.
2624
+ *
2625
+ * @see {@link find}
2626
+ */
2627
+ find: typeof find;
2628
+
2629
+ /**
2630
+ * Finds the last node in a CSS abstract syntax tree (AST) that matches a given condition.
2631
+ *
2632
+ * @see {@link findLast}
2633
+ */
2634
+ findLast: typeof findLast;
2635
+
2636
+ /**
2637
+ * Finds all nodes in a CSS abstract syntax tree (AST) that match a given condition.
2638
+ *
2639
+ * @see {@link findAll}
2640
+ */
2641
+ findAll: typeof findAll;
2642
+
2643
+ /**
2644
+ * Converts a plain JavaScript object into a CSS abstract syntax tree (AST).
2645
+ *
2646
+ * @see {@link fromPlainObject}
2647
+ */
2648
+ fromPlainObject: typeof fromPlainObject;
2649
+
2650
+ /**
2651
+ * Converts a CSS abstract syntax tree (AST) into a plain JavaScript object.
2652
+ *
2653
+ * @see {@link toPlainObject}
2654
+ */
2655
+ toPlainObject: typeof toPlainObject;
2656
+
2657
+ /**
2658
+ * Creates a new `Syntax` instance with customized or extended functionality.
2659
+ *
2660
+ * @returns A new forked `Syntax` instance.
2661
+ */
2662
+ fork: ForkFunction;
2663
+ }
2664
+
2665
+ /**
2666
+ * Represents a match in the syntax, containing details about the type,
2667
+ * name, and corresponding syntax tree node.
2668
+ */
2669
+ interface SyntaxMatch {
2670
+ /**
2671
+ * The type of the matched syntax (e.g., "Type", "Property").
2672
+ */
2673
+ type: string;
2674
+
2675
+ /**
2676
+ * The name of the matched syntax rule.
2677
+ */
2678
+ name: string;
2679
+
2680
+ /**
2681
+ * The syntax tree node representing the matched syntax.
2682
+ */
2683
+ syntax: DSNode;
2684
+ }
2685
+
2686
+ /**
2687
+ * Represents a graph of syntax matches, including the match type,
2688
+ * syntax tree node, and source node.
2689
+ */
2690
+ interface SyntaxMatchGraph {
2691
+ /**
2692
+ * The type of the syntax match graph (e.g., "Type", "Property").
2693
+ */
2694
+ type: string;
2695
+
2696
+ /**
2697
+ * The primary match information.
2698
+ */
2699
+ match: SyntaxMatch;
2700
+
2701
+ /**
2702
+ * The syntax tree node representing the match graph.
2703
+ */
2704
+ syntax: DSNode;
2705
+
2706
+ /**
2707
+ * The source syntax tree node for the match graph.
2708
+ */
2709
+ source: DSNode;
2710
+ }
2711
+
2712
+ /**
2713
+ * Describes a syntax rule or definition.
2714
+ */
2715
+ type SyntaxDescriptor = {
2716
+ /**
2717
+ * The type of the syntax descriptor (e.g., "Type", "Property").
2718
+ */
2719
+ type: string;
2720
+
2721
+ /**
2722
+ * The name of the syntax descriptor.
2723
+ */
2724
+ name: string;
2725
+
2726
+ /**
2727
+ * The name of the parent syntax descriptor, or `null` if none exists.
2728
+ */
2729
+ parent: string | null;
2730
+
2731
+ /**
2732
+ * Whether the syntax descriptor can be serialized.
2733
+ */
2734
+ serializable: boolean;
2735
+
2736
+ /**
2737
+ * The syntax object associated with the descriptor.
2738
+ */
2739
+ syntax: Syntax;
2740
+
2741
+ /**
2742
+ * The graph of syntax matches for this descriptor, or `null` if none exists.
2743
+ */
2744
+ match: SyntaxMatchGraph | null;
2745
+
2746
+ /**
2747
+ * A reference to a graph of syntax matches, or `null` if none exists.
2748
+ */
2749
+ matchRef?: SyntaxMatchGraph | null;
2750
+ };
2751
+
2752
+ /**
2753
+ * Represents a fragment match, including its parent list and nodes.
2754
+ */
2755
+ type FragmentMatch<T extends CssNode = CssNode> = {
2756
+ /**
2757
+ * The parent list of CSS nodes containing the fragment.
2758
+ */
2759
+ parent: List<CssNode>;
2760
+
2761
+ /**
2762
+ * The list of nodes that make up the fragment.
2763
+ */
2764
+ nodes: List<T>;
2765
+ };
2766
+
2767
+ /**
2768
+ * Represents the result of validating a set of syntax rules.
2769
+ */
2770
+ type LexerValidationResult = {
2771
+ /**
2772
+ * Broken types as an array of type names.
2773
+ */
2774
+ types: string[];
2775
+
2776
+ /**
2777
+ * Broken properties as an array of property names.
2778
+ */
2779
+ properties: string[];
2780
+ };
2781
+
2782
+ /**
2783
+ * The `Lexer` class is responsible for matching and validating CSS syntax.
2784
+ * It provides utilities for handling at-rules, properties, types, and general syntax.
2785
+ */
2786
+ export class Lexer {
2787
+ /**
2788
+ * Creates a new `Lexer` instance.
2789
+ *
2790
+ * @param config - The syntax configuration object.
2791
+ * @param syntax - (Optional) A reference to the associated `Syntax` object.
2792
+ * @param structure - (Optional) The structure definitions for the lexer.
2793
+ */
2794
+ constructor(config: SyntaxConfig, syntax?: Syntax, structure?: Structure);
2795
+
2796
+ /**
2797
+ * Checks the structure of the given CSS AST.
2798
+ *
2799
+ * @param ast - The CSS abstract syntax tree to validate.
2800
+ * @returns An array of structure warnings or `false` if the structure is valid.
2801
+ */
2802
+ checkStructure(ast: CssNode): LexerStructureWarning[] | false;
2803
+
2804
+ /**
2805
+ * Creates a syntax descriptor for the given syntax string or object.
2806
+ *
2807
+ * @param syntax - The syntax definition.
2808
+ * @param type - The type of syntax (e.g., "Type", "Property").
2809
+ * @param name - The name of the syntax rule.
2810
+ * @param parent - (Optional) The parent rule, if applicable.
2811
+ * @returns A `SyntaxDescriptor` for the provided syntax.
2812
+ */
2813
+ createDescriptor(syntax: Syntax | string, type: string, name: string, parent: string | null): SyntaxDescriptor;
2814
+
2815
+ /**
2816
+ * Checks if an at-rule name is valid.
2817
+ *
2818
+ * @param atruleName - The name of the at-rule.
2819
+ * @returns A `SyntaxReferenceError` if invalid, or `undefined` if valid.
2820
+ */
2821
+ checkAtruleName(atruleName: string): SyntaxReferenceError | undefined;
2822
+
2823
+ /**
2824
+ * Checks if an at-rule prelude is valid.
2825
+ *
2826
+ * @param atruleName - The name of the at-rule.
2827
+ * @param prelude - The prelude content as a CSS node or string.
2828
+ * @returns A `SyntaxError` if invalid, or `undefined` if valid.
2829
+ */
2830
+ checkAtrulePrelude(atruleName: string, prelude: CssNode | string): SyntaxError | undefined;
2831
+
2832
+ /**
2833
+ * Checks if an at-rule descriptor name is valid.
2834
+ *
2835
+ * @param atruleName - The name of the at-rule.
2836
+ * @param descriptorName - The name of the descriptor.
2837
+ * @returns A syntax error or `undefined` if valid.
2838
+ */
2839
+ checkAtruleDescriptorName(
2840
+ atruleName: string,
2841
+ descriptorName: string,
2842
+ ): SyntaxReferenceError | SyntaxError | undefined;
2843
+
2844
+ /**
2845
+ * Checks if a property name is valid.
2846
+ *
2847
+ * @param propertyName - The name of the property.
2848
+ * @returns A `SyntaxReferenceError` if invalid, or `undefined` if valid.
2849
+ */
2850
+ checkPropertyName(propertyName: string): SyntaxReferenceError | undefined;
2851
+
2852
+ /**
2853
+ * Matches an at-rule prelude against its syntax definition.
2854
+ *
2855
+ * @param atruleName - The name of the at-rule.
2856
+ * @param prelude - The prelude content.
2857
+ * @returns The match result as a `LexerMatchResult`.
2858
+ */
2859
+ matchAtrulePrelude(atruleName: string, prelude: CssNode | string): LexerMatchResult;
2860
+
2861
+ /**
2862
+ * Matches an at-rule descriptor value against its syntax definition.
2863
+ *
2864
+ * @param atruleName - The name of the at-rule.
2865
+ * @param descriptorName - The descriptor name.
2866
+ * @param value - The value to match.
2867
+ * @returns The match result as a `LexerMatchResult`.
2868
+ */
2869
+ matchAtruleDescriptor(atruleName: string, descriptorName: string, value: CssNode | string): LexerMatchResult;
2870
+
2871
+ /**
2872
+ * Matches a declaration node against its syntax definition.
2873
+ *
2874
+ * @param node - The declaration node to match.
2875
+ * @returns The match result as a `LexerMatchResult`.
2876
+ */
2877
+ matchDeclaration(node: CssNode): LexerMatchResult;
2878
+
2879
+ /**
2880
+ * Matches a property value against its syntax definition.
2881
+ *
2882
+ * @param propertyName - The name of the property.
2883
+ * @param value - The value to match.
2884
+ * @returns The match result as a `LexerMatchResult`.
2885
+ */
2886
+ matchProperty(propertyName: string, value: CssNode | string): LexerMatchResult;
2887
+
2888
+ /**
2889
+ * Matches a type value against its syntax definition.
2890
+ *
2891
+ * @param typeName - The name of the type.
2892
+ * @param value - The value to match.
2893
+ * @returns The match result as a `LexerMatchResult`.
2894
+ */
2895
+ matchType(typeName: string, value: CssNode | string): LexerMatchResult;
2896
+
2897
+ /**
2898
+ * Matches a generic syntax descriptor against a value.
2899
+ *
2900
+ * @param syntax - The syntax descriptor or string.
2901
+ * @param value - The value to match.
2902
+ * @returns The match result as a `LexerMatchResult`.
2903
+ */
2904
+ match(syntax: SyntaxDescriptor | string, value: CssNode | string): LexerMatchResult;
2905
+
2906
+ /**
2907
+ * Finds fragments of a value that match a specific syntax type and name.
2908
+ *
2909
+ * @param propertyName - The name of the property.
2910
+ * @param value - The value to search.
2911
+ * @param type - The type to match.
2912
+ * @param name - The name to match.
2913
+ * @returns An array of matching fragments.
2914
+ */
2915
+ findValueFragments(propertyName: string, value: CssNode, type: string, name: string): FragmentMatch<Value>[];
2916
+
2917
+ /**
2918
+ * Finds fragments of a declaration value that match a specific syntax type and name.
2919
+ *
2920
+ * @param declaration - The declaration node to search.
2921
+ * @param type - The type to match.
2922
+ * @param name - The name to match.
2923
+ * @returns An array of matching fragments.
2924
+ */
2925
+ findDeclarationValueFragments(declaration: Declaration, type: string, name: string): FragmentMatch<Value>[];
2926
+
2927
+ /**
2928
+ * Finds all fragments in an AST that match a specific syntax type and name.
2929
+ *
2930
+ * @param ast - The AST to search.
2931
+ * @param type - The type to match.
2932
+ * @param name - The name to match.
2933
+ * @returns An array of matching fragments.
2934
+ */
2935
+ findAllFragments(ast: CssNode, type: string, name: string): FragmentMatch[];
2936
+
2937
+ /**
2938
+ * Retrieves the syntax descriptor for an at-rule.
2939
+ *
2940
+ * @param atruleName - The name of the at-rule.
2941
+ * @param fallbackBasename - (Optional) Whether to use a fallback basename.
2942
+ * @returns The syntax descriptor or `null` if not found.
2943
+ */
2944
+ getAtrule(atruleName: string, fallbackBasename?: boolean): SyntaxDescriptor | null;
2945
+
2946
+ /**
2947
+ * Retrieves the prelude descriptor for an at-rule.
2948
+ *
2949
+ * @param atruleName - The name of the at-rule.
2950
+ * @param fallbackBasename - (Optional) Whether to use a fallback basename.
2951
+ * @returns The syntax descriptor or `null` if not found.
2952
+ */
2953
+ getAtrulePrelude(atruleName: string, fallbackBasename?: boolean): SyntaxDescriptor | null;
2954
+
2955
+ /**
2956
+ * Retrieves the descriptor for an at-rule's property.
2957
+ *
2958
+ * @param atruleName - The name of the at-rule.
2959
+ * @param name - The property name.
2960
+ * @returns The syntax descriptor or `null` if not found.
2961
+ */
2962
+ getAtruleDescriptor(atruleName: string, name: string): SyntaxDescriptor | null;
2963
+
2964
+ /**
2965
+ * Retrieves the syntax descriptor for a property.
2966
+ *
2967
+ * @param propertyName - The name of the property.
2968
+ * @param fallbackBasename - (Optional) Whether to use a fallback basename.
2969
+ * @returns The syntax descriptor or `null` if not found.
2970
+ */
2971
+ getProperty(propertyName: string, fallbackBasename?: boolean): SyntaxDescriptor | null;
2972
+
2973
+ /**
2974
+ * Retrieves the syntax descriptor for a type.
2975
+ *
2976
+ * @param name - The name of the type.
2977
+ * @returns The syntax descriptor or `null` if not found.
2978
+ */
2979
+ getType(name: string): SyntaxDescriptor | null;
2980
+
2981
+ /**
2982
+ * Validates the syntax rules and properties.
2983
+ *
2984
+ * @returns Validation results or `null` if everything is valid.
2985
+ */
2986
+ validate(): LexerValidationResult | null;
2987
+
2988
+ /**
2989
+ * Dumps the current syntax configuration as a configuration object.
2990
+ *
2991
+ * @param syntaxAsAst - Whether to return syntax as AST.
2992
+ * @param pretty - Whether to format the output for readability.
2993
+ * @returns The syntax configuration.
2994
+ */
2995
+ dump(syntaxAsAst: Syntax, pretty: boolean): SyntaxConfig;
2996
+
2997
+ /**
2998
+ * Converts the lexer to a string representation.
2999
+ *
3000
+ * @returns A string representation of the lexer.
3001
+ */
3002
+ toString(): string;
3003
+ }
3004
+
3005
+ /**
3006
+ * Lexer instance.
3007
+ */
3008
+ export const lexer: Lexer;
3009
+
3010
+ type SyntaxExtensionCallback = (prev: SyntaxConfig, assign?: typeof Object.assign) => SyntaxConfig;
3011
+
3012
+ type SyntaxExtension = Partial<SyntaxConfig> | SyntaxExtensionCallback;
3013
+
3014
+ type ForkFunction = (extension: SyntaxExtension) => Syntax;
3015
+
3016
+ export const fork: ForkFunction;