@webstudio-is/css-data 0.91.0 → 0.267.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.
- package/lib/index.js +17534 -15
- package/lib/types/__generated__/animatable-properties.d.ts +1 -0
- package/lib/types/__generated__/html.d.ts +2 -0
- package/lib/types/__generated__/keyword-values.d.ts +4 -358
- package/lib/types/__generated__/properties.d.ts +10 -3674
- package/lib/types/__generated__/property-value-descriptions.d.ts +7 -5446
- package/lib/types/__generated__/pseudo-classes.d.ts +1 -0
- package/lib/types/__generated__/pseudo-elements.d.ts +1 -0
- package/lib/types/__generated__/pseudo-selector-descriptions.d.ts +2 -0
- package/lib/types/__generated__/shorthand-properties.d.ts +1 -0
- package/lib/types/css-tree.d.ts +772 -0
- package/lib/types/index.d.ts +18 -3680
- package/lib/types/media-condition-simulator.d.ts +7 -0
- package/lib/types/parse-css-value.d.ts +8 -3
- package/lib/types/parse-css.d.ts +75 -6
- package/lib/types/property-parsers/conic-gradient.d.ts +3 -0
- package/lib/types/property-parsers/gradient-utils.d.ts +20 -0
- package/lib/types/property-parsers/grid-template-areas.d.ts +21 -0
- package/lib/types/property-parsers/grid-template-tracks.d.ts +128 -0
- package/lib/types/property-parsers/index.d.ts +6 -2
- package/lib/types/property-parsers/linear-gradient.d.ts +4 -0
- package/lib/types/property-parsers/radial-gradient.d.ts +3 -0
- package/lib/types/property-parsers/types.d.ts +28 -0
- package/lib/types/selector-validation.d.ts +13 -0
- package/lib/types/shorthands.d.ts +2 -0
- package/package.json +29 -33
- package/lib/__generated__/keyword-values.js +0 -5255
- package/lib/__generated__/properties.js +0 -3697
- package/lib/__generated__/property-value-descriptions.js +0 -2740
- package/lib/__generated__/units.js +0 -65
- package/lib/cjs/__generated__/keyword-values.js +0 -5275
- package/lib/cjs/__generated__/properties.js +0 -3717
- package/lib/cjs/__generated__/property-value-descriptions.js +0 -2760
- package/lib/cjs/__generated__/units.js +0 -85
- package/lib/cjs/custom-data.js +0 -64
- package/lib/cjs/html-check.js +0 -25
- package/lib/cjs/html.js +0 -581
- package/lib/cjs/index.js +0 -48
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/parse-css-value.js +0 -152
- package/lib/cjs/parse-css.js +0 -136
- package/lib/cjs/popularity-index.js +0 -4633
- package/lib/cjs/property-parsers/background.js +0 -119
- package/lib/cjs/property-parsers/box-shadow.js +0 -129
- package/lib/cjs/property-parsers/index.js +0 -19
- package/lib/cjs/property-parsers/parsers.js +0 -26
- package/lib/cjs/property-parsers/to-longhand.js +0 -24
- package/lib/cjs/schema.js +0 -135
- package/lib/custom-data.js +0 -44
- package/lib/html-check.js +0 -2
- package/lib/html.js +0 -561
- package/lib/parse-css-value.js +0 -122
- package/lib/parse-css.js +0 -106
- package/lib/popularity-index.js +0 -4613
- package/lib/property-parsers/background.js +0 -89
- package/lib/property-parsers/box-shadow.js +0 -99
- package/lib/property-parsers/index.js +0 -2
- package/lib/property-parsers/parsers.js +0 -6
- package/lib/property-parsers/to-longhand.js +0 -4
- package/lib/schema.js +0 -115
- package/lib/types/custom-data.d.ts +0 -15
- package/lib/types/html-check.d.ts +0 -1
- package/lib/types/html.d.ts +0 -62
- package/lib/types/parse-css-value.test.d.ts +0 -1
- package/lib/types/parse-css.test.d.ts +0 -1
- package/lib/types/popularity-index.d.ts +0 -6
- package/lib/types/property-parsers/background.d.ts +0 -11
- package/lib/types/property-parsers/background.test.d.ts +0 -1
- package/lib/types/property-parsers/box-shadow.d.ts +0 -3
- package/lib/types/property-parsers/box-shadow.test.d.ts +0 -1
- package/lib/types/property-parsers/parsers.d.ts +0 -2
- package/lib/types/property-parsers/to-longhand.d.ts +0 -1
- package/lib/types/schema.d.ts +0 -3243
- package/src/__generated__/keyword-values.ts +0 -5253
- package/src/__generated__/properties.ts +0 -3696
- package/src/__generated__/property-value-descriptions.ts +0 -4008
- package/src/__generated__/units.ts +0 -63
- package/src/custom-data.ts +0 -57
- package/src/html-check.ts +0 -8
- package/src/html.ts +0 -617
- package/src/index.ts +0 -25
- package/src/parse-css-value.test.ts +0 -136
- package/src/parse-css-value.ts +0 -157
- package/src/parse-css.test.ts +0 -101
- package/src/parse-css.ts +0 -137
- package/src/popularity-index.ts +0 -4611
- package/src/property-parsers/README.md +0 -11
- package/src/property-parsers/background.test.ts +0 -184
- package/src/property-parsers/background.ts +0 -147
- package/src/property-parsers/box-shadow.test.ts +0 -294
- package/src/property-parsers/box-shadow.ts +0 -130
- package/src/property-parsers/index.ts +0 -2
- package/src/property-parsers/parsers.ts +0 -5
- package/src/property-parsers/to-longhand.ts +0 -4
- package/src/schema.ts +0 -193
|
@@ -0,0 +1,772 @@
|
|
|
1
|
+
// Minimal-yet-safe TypeScript typings for css-tree v3.x
|
|
2
|
+
// Covers: AST node types, parse/generate, walk/find, List, lexer API,
|
|
3
|
+
// value definition syntax helpers, and common utils used in this project.
|
|
4
|
+
|
|
5
|
+
declare module "css-tree" {
|
|
6
|
+
// -------------------------------------------------
|
|
7
|
+
// Common
|
|
8
|
+
// -------------------------------------------------
|
|
9
|
+
export interface SourceLocation {
|
|
10
|
+
source: string;
|
|
11
|
+
start: { offset: number; line: number; column: number };
|
|
12
|
+
end: { offset: number; line: number; column: number };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface BaseNode {
|
|
16
|
+
type: string;
|
|
17
|
+
loc: SourceLocation | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Doubly-linked list used by csstree
|
|
21
|
+
export interface ListItem<T> {
|
|
22
|
+
prev: ListItem<T> | null;
|
|
23
|
+
next: ListItem<T> | null;
|
|
24
|
+
data: T;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class List<T> implements Iterable<T> {
|
|
28
|
+
static createItem<T>(data: T): ListItem<T>;
|
|
29
|
+
|
|
30
|
+
constructor();
|
|
31
|
+
// iteration
|
|
32
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
33
|
+
// props
|
|
34
|
+
readonly size: number;
|
|
35
|
+
readonly isEmpty: boolean;
|
|
36
|
+
readonly first: T | null;
|
|
37
|
+
readonly last: T | null;
|
|
38
|
+
// traversal helpers
|
|
39
|
+
forEach(
|
|
40
|
+
fn: (data: T, item: ListItem<T>, list: List<T>) => void,
|
|
41
|
+
thisArg?: any
|
|
42
|
+
): void;
|
|
43
|
+
forEachRight(
|
|
44
|
+
fn: (data: T, item: ListItem<T>, list: List<T>) => void,
|
|
45
|
+
thisArg?: any
|
|
46
|
+
): void;
|
|
47
|
+
// conversion
|
|
48
|
+
fromArray(items: T[]): this;
|
|
49
|
+
toArray(): T[];
|
|
50
|
+
toJSON(): T[];
|
|
51
|
+
// mutation (minimal surface used by walkers)
|
|
52
|
+
clear(): void;
|
|
53
|
+
remove(item: ListItem<T>): ListItem<T>;
|
|
54
|
+
insert(item: ListItem<T>, before?: ListItem<T> | null): void;
|
|
55
|
+
insertData(data: T, before?: ListItem<T> | null): void;
|
|
56
|
+
append(item: ListItem<T>): void;
|
|
57
|
+
appendData(data: T): void;
|
|
58
|
+
prepend(item: ListItem<T>): void;
|
|
59
|
+
prependData(data: T): void;
|
|
60
|
+
replace(oldItem: ListItem<T>, newItemOrList: ListItem<T> | List<T>): void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// -------------------------------------------------
|
|
64
|
+
// AST Nodes (as per docs/ast.md)
|
|
65
|
+
// -------------------------------------------------
|
|
66
|
+
export interface AnPlusB extends BaseNode {
|
|
67
|
+
type: "AnPlusB";
|
|
68
|
+
a: string | null;
|
|
69
|
+
b: string | null;
|
|
70
|
+
}
|
|
71
|
+
export interface Atrule extends BaseNode {
|
|
72
|
+
type: "Atrule";
|
|
73
|
+
name: string;
|
|
74
|
+
prelude: AtrulePrelude | Raw | null;
|
|
75
|
+
block: Block | null;
|
|
76
|
+
}
|
|
77
|
+
export interface AtrulePrelude extends BaseNode {
|
|
78
|
+
type: "AtrulePrelude";
|
|
79
|
+
children: List<CssNode>;
|
|
80
|
+
}
|
|
81
|
+
export interface AttributeSelector extends BaseNode {
|
|
82
|
+
type: "AttributeSelector";
|
|
83
|
+
name: Identifier;
|
|
84
|
+
matcher: string | null;
|
|
85
|
+
value: StringNode | Identifier | null;
|
|
86
|
+
flags: string | null;
|
|
87
|
+
}
|
|
88
|
+
export interface Block extends BaseNode {
|
|
89
|
+
type: "Block";
|
|
90
|
+
children: List<Atrule | Rule | Declaration>;
|
|
91
|
+
}
|
|
92
|
+
export interface Brackets extends BaseNode {
|
|
93
|
+
type: "Brackets";
|
|
94
|
+
children: List<CssNode>;
|
|
95
|
+
}
|
|
96
|
+
export interface CDC extends BaseNode {
|
|
97
|
+
type: "CDC";
|
|
98
|
+
}
|
|
99
|
+
export interface CDO extends BaseNode {
|
|
100
|
+
type: "CDO";
|
|
101
|
+
}
|
|
102
|
+
export interface ClassSelector extends BaseNode {
|
|
103
|
+
type: "ClassSelector";
|
|
104
|
+
name: string;
|
|
105
|
+
}
|
|
106
|
+
export interface Combinator extends BaseNode {
|
|
107
|
+
type: "Combinator";
|
|
108
|
+
name: string;
|
|
109
|
+
}
|
|
110
|
+
export interface Comment extends BaseNode {
|
|
111
|
+
type: "Comment";
|
|
112
|
+
value: string;
|
|
113
|
+
}
|
|
114
|
+
export interface Condition extends BaseNode {
|
|
115
|
+
type: "Condition";
|
|
116
|
+
kind: string;
|
|
117
|
+
children: List<
|
|
118
|
+
| Identifier
|
|
119
|
+
| Feature
|
|
120
|
+
| FeatureFunction
|
|
121
|
+
| FeatureRange
|
|
122
|
+
| SupportsDeclaration
|
|
123
|
+
>;
|
|
124
|
+
}
|
|
125
|
+
export interface Declaration extends BaseNode {
|
|
126
|
+
type: "Declaration";
|
|
127
|
+
important: boolean | string;
|
|
128
|
+
property: string;
|
|
129
|
+
value: Value | Raw;
|
|
130
|
+
}
|
|
131
|
+
export interface DeclarationList extends BaseNode {
|
|
132
|
+
type: "DeclarationList";
|
|
133
|
+
children: List<Declaration | Atrule | Rule>;
|
|
134
|
+
}
|
|
135
|
+
export interface Dimension extends BaseNode {
|
|
136
|
+
type: "Dimension";
|
|
137
|
+
value: string;
|
|
138
|
+
unit: string;
|
|
139
|
+
}
|
|
140
|
+
export interface Feature extends BaseNode {
|
|
141
|
+
type: "Feature";
|
|
142
|
+
kind: string;
|
|
143
|
+
name: string;
|
|
144
|
+
value: Identifier | NumberNode | Dimension | Ratio | FunctionNode | null;
|
|
145
|
+
}
|
|
146
|
+
export interface FeatureFunction extends BaseNode {
|
|
147
|
+
type: "FeatureFunction";
|
|
148
|
+
kind: string;
|
|
149
|
+
feature: string;
|
|
150
|
+
value: Declaration | Selector;
|
|
151
|
+
}
|
|
152
|
+
export interface FeatureRange extends BaseNode {
|
|
153
|
+
type: "FeatureRange";
|
|
154
|
+
kind: string;
|
|
155
|
+
left: Identifier | NumberNode | Dimension | Ratio | FunctionNode;
|
|
156
|
+
leftComparison: string;
|
|
157
|
+
middle: Identifier | NumberNode | Dimension | Ratio | FunctionNode;
|
|
158
|
+
rightComparison: string | null;
|
|
159
|
+
right: Identifier | NumberNode | Dimension | Ratio | FunctionNode | null;
|
|
160
|
+
}
|
|
161
|
+
export interface FunctionNode extends BaseNode {
|
|
162
|
+
type: "Function";
|
|
163
|
+
name: string;
|
|
164
|
+
children: List<CssNode>;
|
|
165
|
+
}
|
|
166
|
+
export interface GeneralEnclosed extends BaseNode {
|
|
167
|
+
type: "GeneralEnclosed";
|
|
168
|
+
kind: string;
|
|
169
|
+
function: string | null;
|
|
170
|
+
children: List<CssNode>;
|
|
171
|
+
}
|
|
172
|
+
export interface Hash extends BaseNode {
|
|
173
|
+
type: "Hash";
|
|
174
|
+
value: string;
|
|
175
|
+
}
|
|
176
|
+
export interface IdSelector extends BaseNode {
|
|
177
|
+
type: "IdSelector";
|
|
178
|
+
name: string;
|
|
179
|
+
}
|
|
180
|
+
export interface Identifier extends BaseNode {
|
|
181
|
+
type: "Identifier";
|
|
182
|
+
name: string;
|
|
183
|
+
}
|
|
184
|
+
export interface Layer extends BaseNode {
|
|
185
|
+
type: "Layer";
|
|
186
|
+
name: string;
|
|
187
|
+
}
|
|
188
|
+
export interface LayerList extends BaseNode {
|
|
189
|
+
type: "LayerList";
|
|
190
|
+
children: List<Layer>;
|
|
191
|
+
}
|
|
192
|
+
export interface MediaQuery extends BaseNode {
|
|
193
|
+
type: "MediaQuery";
|
|
194
|
+
modifier: string | null;
|
|
195
|
+
mediaType: string | null;
|
|
196
|
+
condition: Condition | null;
|
|
197
|
+
}
|
|
198
|
+
export interface MediaQueryList extends BaseNode {
|
|
199
|
+
type: "MediaQueryList";
|
|
200
|
+
children: List<MediaQuery>;
|
|
201
|
+
}
|
|
202
|
+
export interface NestingSelector extends BaseNode {
|
|
203
|
+
type: "NestingSelector";
|
|
204
|
+
}
|
|
205
|
+
export interface Nth extends BaseNode {
|
|
206
|
+
type: "Nth";
|
|
207
|
+
nth: AnPlusB | Identifier;
|
|
208
|
+
selector: SelectorList | null;
|
|
209
|
+
}
|
|
210
|
+
export interface NumberNode extends BaseNode {
|
|
211
|
+
type: "Number";
|
|
212
|
+
value: string;
|
|
213
|
+
}
|
|
214
|
+
export interface Operator extends BaseNode {
|
|
215
|
+
type: "Operator";
|
|
216
|
+
value: string;
|
|
217
|
+
}
|
|
218
|
+
export interface Parentheses extends BaseNode {
|
|
219
|
+
type: "Parentheses";
|
|
220
|
+
children: List<CssNode>;
|
|
221
|
+
}
|
|
222
|
+
export interface Percentage extends BaseNode {
|
|
223
|
+
type: "Percentage";
|
|
224
|
+
value: string;
|
|
225
|
+
}
|
|
226
|
+
export interface PseudoClassSelector extends BaseNode {
|
|
227
|
+
type: "PseudoClassSelector";
|
|
228
|
+
name: string;
|
|
229
|
+
children: List<Raw> | null;
|
|
230
|
+
}
|
|
231
|
+
export interface PseudoElementSelector extends BaseNode {
|
|
232
|
+
type: "PseudoElementSelector";
|
|
233
|
+
name: string;
|
|
234
|
+
children: List<Raw> | null;
|
|
235
|
+
}
|
|
236
|
+
export interface Ratio extends BaseNode {
|
|
237
|
+
type: "Ratio";
|
|
238
|
+
left: NumberNode | FunctionNode;
|
|
239
|
+
right: NumberNode | FunctionNode | null;
|
|
240
|
+
}
|
|
241
|
+
export interface Raw extends BaseNode {
|
|
242
|
+
type: "Raw";
|
|
243
|
+
value: string;
|
|
244
|
+
}
|
|
245
|
+
export interface Rule extends BaseNode {
|
|
246
|
+
type: "Rule";
|
|
247
|
+
prelude: SelectorList | Raw;
|
|
248
|
+
block: Block;
|
|
249
|
+
}
|
|
250
|
+
export interface Scope extends BaseNode {
|
|
251
|
+
type: "Scope";
|
|
252
|
+
root: SelectorList | Raw | null;
|
|
253
|
+
limit: SelectorList | Raw | null;
|
|
254
|
+
}
|
|
255
|
+
export interface Selector extends BaseNode {
|
|
256
|
+
type: "Selector";
|
|
257
|
+
children: List<
|
|
258
|
+
| TypeSelector
|
|
259
|
+
| IdSelector
|
|
260
|
+
| ClassSelector
|
|
261
|
+
| AttributeSelector
|
|
262
|
+
| PseudoClassSelector
|
|
263
|
+
| PseudoElementSelector
|
|
264
|
+
| Combinator
|
|
265
|
+
| NestingSelector
|
|
266
|
+
>;
|
|
267
|
+
}
|
|
268
|
+
export interface SelectorList extends BaseNode {
|
|
269
|
+
type: "SelectorList";
|
|
270
|
+
children: List<Selector | Raw>;
|
|
271
|
+
}
|
|
272
|
+
export interface StringNode extends BaseNode {
|
|
273
|
+
type: "String";
|
|
274
|
+
value: string;
|
|
275
|
+
}
|
|
276
|
+
export interface StyleSheet extends BaseNode {
|
|
277
|
+
type: "StyleSheet";
|
|
278
|
+
children: List<Comment | CDO | CDC | Atrule | Rule | Raw>;
|
|
279
|
+
}
|
|
280
|
+
export interface SupportsDeclaration extends BaseNode {
|
|
281
|
+
type: "SupportsDeclaration";
|
|
282
|
+
declaration: Declaration;
|
|
283
|
+
}
|
|
284
|
+
export interface TypeSelector extends BaseNode {
|
|
285
|
+
type: "TypeSelector";
|
|
286
|
+
name: string;
|
|
287
|
+
}
|
|
288
|
+
export interface UnicodeRange extends BaseNode {
|
|
289
|
+
type: "UnicodeRange";
|
|
290
|
+
value: string;
|
|
291
|
+
}
|
|
292
|
+
export interface Url extends BaseNode {
|
|
293
|
+
type: "Url";
|
|
294
|
+
value: string;
|
|
295
|
+
}
|
|
296
|
+
export interface Value extends BaseNode {
|
|
297
|
+
type: "Value";
|
|
298
|
+
children: List<CssNode>;
|
|
299
|
+
}
|
|
300
|
+
export interface WhiteSpace extends BaseNode {
|
|
301
|
+
type: "WhiteSpace";
|
|
302
|
+
value: string;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export type CssNode =
|
|
306
|
+
| AnPlusB
|
|
307
|
+
| Atrule
|
|
308
|
+
| AtrulePrelude
|
|
309
|
+
| AttributeSelector
|
|
310
|
+
| Block
|
|
311
|
+
| Brackets
|
|
312
|
+
| CDC
|
|
313
|
+
| CDO
|
|
314
|
+
| ClassSelector
|
|
315
|
+
| Combinator
|
|
316
|
+
| Comment
|
|
317
|
+
| Condition
|
|
318
|
+
| Declaration
|
|
319
|
+
| DeclarationList
|
|
320
|
+
| Dimension
|
|
321
|
+
| Feature
|
|
322
|
+
| FeatureFunction
|
|
323
|
+
| FeatureRange
|
|
324
|
+
| FunctionNode
|
|
325
|
+
| GeneralEnclosed
|
|
326
|
+
| Hash
|
|
327
|
+
| IdSelector
|
|
328
|
+
| Identifier
|
|
329
|
+
| Layer
|
|
330
|
+
| LayerList
|
|
331
|
+
| MediaQuery
|
|
332
|
+
| MediaQueryList
|
|
333
|
+
| NestingSelector
|
|
334
|
+
| Nth
|
|
335
|
+
| NumberNode
|
|
336
|
+
| Operator
|
|
337
|
+
| Parentheses
|
|
338
|
+
| Percentage
|
|
339
|
+
| PseudoClassSelector
|
|
340
|
+
| PseudoElementSelector
|
|
341
|
+
| Ratio
|
|
342
|
+
| Raw
|
|
343
|
+
| Rule
|
|
344
|
+
| Scope
|
|
345
|
+
| Selector
|
|
346
|
+
| SelectorList
|
|
347
|
+
| StringNode
|
|
348
|
+
| StyleSheet
|
|
349
|
+
| SupportsDeclaration
|
|
350
|
+
| TypeSelector
|
|
351
|
+
| UnicodeRange
|
|
352
|
+
| Url
|
|
353
|
+
| Value
|
|
354
|
+
| WhiteSpace;
|
|
355
|
+
|
|
356
|
+
// A plain-object form where children are arrays (for JSON, etc.)
|
|
357
|
+
export type CssNodePlain = Omit<CssNode, "children" | "loc"> & {
|
|
358
|
+
children?: CssNodePlain[] | null;
|
|
359
|
+
loc?: SourceLocation | null;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// -------------------------------------------------
|
|
363
|
+
// Parsing / Generation
|
|
364
|
+
// -------------------------------------------------
|
|
365
|
+
export type ParseContext =
|
|
366
|
+
| "stylesheet"
|
|
367
|
+
| "atrule"
|
|
368
|
+
| "atrulePrelude"
|
|
369
|
+
| "mediaQueryList"
|
|
370
|
+
| "mediaQuery"
|
|
371
|
+
| "rule"
|
|
372
|
+
| "selectorList"
|
|
373
|
+
| "selector"
|
|
374
|
+
| "block"
|
|
375
|
+
| "declarationList"
|
|
376
|
+
| "declaration"
|
|
377
|
+
| "value";
|
|
378
|
+
|
|
379
|
+
export interface ParseOptions {
|
|
380
|
+
context?: ParseContext;
|
|
381
|
+
atrule?: string | null;
|
|
382
|
+
positions?: boolean;
|
|
383
|
+
onParseError?: (error: any, fallbackNode?: Raw) => void;
|
|
384
|
+
onComment?: (value: string, loc: SourceLocation | null) => void;
|
|
385
|
+
onToken?:
|
|
386
|
+
| ((type: number, start: number, end: number, index: number) => void)
|
|
387
|
+
| Array<{ type: number; start: number; end: number }>
|
|
388
|
+
| null;
|
|
389
|
+
filename?: string;
|
|
390
|
+
offset?: number;
|
|
391
|
+
line?: number;
|
|
392
|
+
column?: number;
|
|
393
|
+
parseAtrulePrelude?: boolean;
|
|
394
|
+
parseRulePrelude?: boolean;
|
|
395
|
+
parseValue?: boolean;
|
|
396
|
+
parseCustomProperty?: boolean;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Strict overloads by context
|
|
400
|
+
export function parse(source: string): StyleSheet;
|
|
401
|
+
export function parse(
|
|
402
|
+
source: string,
|
|
403
|
+
options: ParseOptions & { context?: "stylesheet" }
|
|
404
|
+
): StyleSheet;
|
|
405
|
+
export function parse(
|
|
406
|
+
source: string,
|
|
407
|
+
options: ParseOptions & { context: "atrule" }
|
|
408
|
+
): Atrule;
|
|
409
|
+
export function parse(
|
|
410
|
+
source: string,
|
|
411
|
+
options: ParseOptions & { context: "atrulePrelude" }
|
|
412
|
+
): AtrulePrelude;
|
|
413
|
+
export function parse(
|
|
414
|
+
source: string,
|
|
415
|
+
options: ParseOptions & { context: "mediaQueryList" }
|
|
416
|
+
): MediaQueryList;
|
|
417
|
+
export function parse(
|
|
418
|
+
source: string,
|
|
419
|
+
options: ParseOptions & { context: "mediaQuery" }
|
|
420
|
+
): MediaQuery;
|
|
421
|
+
export function parse(
|
|
422
|
+
source: string,
|
|
423
|
+
options: ParseOptions & { context: "rule" }
|
|
424
|
+
): Rule;
|
|
425
|
+
export function parse(
|
|
426
|
+
source: string,
|
|
427
|
+
options: ParseOptions & { context: "selectorList" }
|
|
428
|
+
): SelectorList;
|
|
429
|
+
export function parse(
|
|
430
|
+
source: string,
|
|
431
|
+
options: ParseOptions & { context: "selector" }
|
|
432
|
+
): Selector;
|
|
433
|
+
export function parse(
|
|
434
|
+
source: string,
|
|
435
|
+
options: ParseOptions & { context: "block" }
|
|
436
|
+
): Block;
|
|
437
|
+
export function parse(
|
|
438
|
+
source: string,
|
|
439
|
+
options: ParseOptions & { context: "declarationList" }
|
|
440
|
+
): DeclarationList;
|
|
441
|
+
export function parse(
|
|
442
|
+
source: string,
|
|
443
|
+
options: ParseOptions & { context: "declaration" }
|
|
444
|
+
): Declaration;
|
|
445
|
+
export function parse(
|
|
446
|
+
source: string,
|
|
447
|
+
options: ParseOptions & { context: "value" }
|
|
448
|
+
): Value;
|
|
449
|
+
// Fallback
|
|
450
|
+
export function parse(source: string, options: ParseOptions): CssNode;
|
|
451
|
+
|
|
452
|
+
export function generate(
|
|
453
|
+
ast: CssNode,
|
|
454
|
+
options: {
|
|
455
|
+
sourceMap: true;
|
|
456
|
+
decorator?: (node: CssNode) => any;
|
|
457
|
+
mode?: "spec" | "safe";
|
|
458
|
+
}
|
|
459
|
+
): { css: string; map: any };
|
|
460
|
+
export function generate(
|
|
461
|
+
ast: CssNode,
|
|
462
|
+
options?: {
|
|
463
|
+
sourceMap?: false;
|
|
464
|
+
decorator?: (node: CssNode) => any;
|
|
465
|
+
mode?: "spec" | "safe";
|
|
466
|
+
}
|
|
467
|
+
): string;
|
|
468
|
+
|
|
469
|
+
// -------------------------------------------------
|
|
470
|
+
// Traversal helpers
|
|
471
|
+
// -------------------------------------------------
|
|
472
|
+
export type WalkHandler = (
|
|
473
|
+
node: CssNode,
|
|
474
|
+
item?: ListItem<CssNode>,
|
|
475
|
+
list?: List<CssNode>
|
|
476
|
+
) => any;
|
|
477
|
+
export interface WalkOptions {
|
|
478
|
+
enter?: WalkHandler;
|
|
479
|
+
leave?: WalkHandler;
|
|
480
|
+
visit?: CssNode["type"] | null;
|
|
481
|
+
reverse?: boolean;
|
|
482
|
+
}
|
|
483
|
+
export function walk(ast: CssNode, options: WalkOptions | WalkHandler): void;
|
|
484
|
+
export function find(ast: CssNode, fn: WalkHandler): CssNode | null;
|
|
485
|
+
export function findLast(ast: CssNode, fn: WalkHandler): CssNode | null;
|
|
486
|
+
export function findAll(ast: CssNode, fn: WalkHandler): CssNode[];
|
|
487
|
+
|
|
488
|
+
// -------------------------------------------------
|
|
489
|
+
// Utils
|
|
490
|
+
// -------------------------------------------------
|
|
491
|
+
export function clone<T extends CssNode>(ast: T): T;
|
|
492
|
+
export function fromPlainObject<T extends { children?: any }>(obj: T): T;
|
|
493
|
+
export function toPlainObject<T extends { children?: any }>(ast: T): T;
|
|
494
|
+
|
|
495
|
+
export interface PropertyInfo {
|
|
496
|
+
basename: string;
|
|
497
|
+
name: string;
|
|
498
|
+
hack: string;
|
|
499
|
+
vendor: string;
|
|
500
|
+
prefix: string;
|
|
501
|
+
custom: boolean;
|
|
502
|
+
}
|
|
503
|
+
export function property(name: string): PropertyInfo;
|
|
504
|
+
|
|
505
|
+
export interface KeywordInfo {
|
|
506
|
+
basename: string;
|
|
507
|
+
name: string;
|
|
508
|
+
vendor: string;
|
|
509
|
+
prefix: string;
|
|
510
|
+
custom: boolean;
|
|
511
|
+
}
|
|
512
|
+
export function keyword(name: string): KeywordInfo;
|
|
513
|
+
|
|
514
|
+
export namespace ident {
|
|
515
|
+
function decode(value: string): string;
|
|
516
|
+
function encode(value: string): string;
|
|
517
|
+
}
|
|
518
|
+
export namespace string {
|
|
519
|
+
function decode(value: string): string;
|
|
520
|
+
function encode(value: string, preferSingleQuotes?: boolean): string;
|
|
521
|
+
}
|
|
522
|
+
export namespace url {
|
|
523
|
+
function decode(value: string): string;
|
|
524
|
+
function encode(value: string): string;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// -------------------------------------------------
|
|
528
|
+
// Definition syntax (values) sub-API
|
|
529
|
+
// -------------------------------------------------
|
|
530
|
+
export namespace definitionSyntax {
|
|
531
|
+
// AST nodes for definition syntax are intentionally minimal here
|
|
532
|
+
interface Base {
|
|
533
|
+
type: string;
|
|
534
|
+
}
|
|
535
|
+
interface Group extends Base {
|
|
536
|
+
type: "Group";
|
|
537
|
+
terms: Base[];
|
|
538
|
+
combinator: " " | "|" | "||" | "&&";
|
|
539
|
+
disallowEmpty: boolean;
|
|
540
|
+
explicit: boolean;
|
|
541
|
+
}
|
|
542
|
+
interface Keyword extends Base {
|
|
543
|
+
type: "Keyword";
|
|
544
|
+
name: string;
|
|
545
|
+
}
|
|
546
|
+
interface Function extends Base {
|
|
547
|
+
type: "Function";
|
|
548
|
+
name: string;
|
|
549
|
+
}
|
|
550
|
+
interface String extends Base {
|
|
551
|
+
type: "String";
|
|
552
|
+
value: string;
|
|
553
|
+
}
|
|
554
|
+
interface Property extends Base {
|
|
555
|
+
type: "Property";
|
|
556
|
+
name: string;
|
|
557
|
+
}
|
|
558
|
+
interface Type extends Base {
|
|
559
|
+
type: "Type";
|
|
560
|
+
name: string;
|
|
561
|
+
opts: Range | null;
|
|
562
|
+
}
|
|
563
|
+
interface Range extends Base {
|
|
564
|
+
type: "Range";
|
|
565
|
+
min: number | null;
|
|
566
|
+
max: number | null;
|
|
567
|
+
}
|
|
568
|
+
interface Multiplier extends Base {
|
|
569
|
+
type: "Multiplier";
|
|
570
|
+
comma: boolean;
|
|
571
|
+
min: number;
|
|
572
|
+
max: number;
|
|
573
|
+
term: Base;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
type Node =
|
|
577
|
+
| Group
|
|
578
|
+
| Keyword
|
|
579
|
+
| Function
|
|
580
|
+
| String
|
|
581
|
+
| Property
|
|
582
|
+
| Type
|
|
583
|
+
| Range
|
|
584
|
+
| Multiplier
|
|
585
|
+
| Base;
|
|
586
|
+
|
|
587
|
+
function parse(source: string): Node;
|
|
588
|
+
function walk(
|
|
589
|
+
node: Node,
|
|
590
|
+
options:
|
|
591
|
+
| { enter?: (n: Node) => void; leave?: (n: Node) => void }
|
|
592
|
+
| ((n: Node) => void),
|
|
593
|
+
context?: any
|
|
594
|
+
): void;
|
|
595
|
+
function generate(
|
|
596
|
+
node: Node,
|
|
597
|
+
options?: {
|
|
598
|
+
forceBraces?: boolean;
|
|
599
|
+
compact?: boolean;
|
|
600
|
+
decorate?: (content: string, node: Node) => string;
|
|
601
|
+
}
|
|
602
|
+
): string;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// -------------------------------------------------
|
|
606
|
+
// Lexer
|
|
607
|
+
// -------------------------------------------------
|
|
608
|
+
export interface AtruleSyntaxConfig {
|
|
609
|
+
prelude?: string | definitionSyntax.Node | ((ref?: any) => any) | null;
|
|
610
|
+
descriptors?: Record<
|
|
611
|
+
string,
|
|
612
|
+
string | definitionSyntax.Node | ((ref?: any) => any)
|
|
613
|
+
> | null;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
export interface LexerConfig {
|
|
617
|
+
generic?: boolean;
|
|
618
|
+
cssWideKeywords?: string[];
|
|
619
|
+
units?: Record<string, string[]>;
|
|
620
|
+
types?: Record<
|
|
621
|
+
string,
|
|
622
|
+
string | definitionSyntax.Node | ((ref?: any) => any)
|
|
623
|
+
>;
|
|
624
|
+
atrules?: Record<string, AtruleSyntaxConfig>;
|
|
625
|
+
properties?: Record<
|
|
626
|
+
string,
|
|
627
|
+
string | definitionSyntax.Node | ((ref?: any) => any)
|
|
628
|
+
>;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
export interface MatchResult {
|
|
632
|
+
matched: any;
|
|
633
|
+
error: Error | null;
|
|
634
|
+
iterations: number;
|
|
635
|
+
isType(node: CssNode | null | undefined, name: string): boolean;
|
|
636
|
+
getTrace(
|
|
637
|
+
node: CssNode | null | undefined
|
|
638
|
+
): Array<{ type: string; name: string }>;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export interface FragmentResult {
|
|
642
|
+
parent: List<CssNode>;
|
|
643
|
+
nodes: List<CssNode>;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
export class Lexer {
|
|
647
|
+
constructor(config?: LexerConfig, syntax?: any, structure?: any);
|
|
648
|
+
|
|
649
|
+
cssWideKeywords: string[];
|
|
650
|
+
units: Record<string, string[]>;
|
|
651
|
+
|
|
652
|
+
checkStructure(
|
|
653
|
+
ast: CssNode
|
|
654
|
+
): false | Array<{ node: CssNode; message: string }>;
|
|
655
|
+
|
|
656
|
+
checkAtruleName(atruleName: string): Error | void;
|
|
657
|
+
checkAtrulePrelude(
|
|
658
|
+
atruleName: string,
|
|
659
|
+
prelude?: string | CssNode | null
|
|
660
|
+
): Error | void;
|
|
661
|
+
checkAtruleDescriptorName(
|
|
662
|
+
atruleName: string,
|
|
663
|
+
descriptorName: string
|
|
664
|
+
): Error | void;
|
|
665
|
+
checkPropertyName(propertyName: string): Error | void;
|
|
666
|
+
|
|
667
|
+
matchAtrulePrelude(
|
|
668
|
+
atruleName: string,
|
|
669
|
+
prelude?: string | CssNode | null
|
|
670
|
+
): MatchResult;
|
|
671
|
+
matchAtruleDescriptor(
|
|
672
|
+
atruleName: string,
|
|
673
|
+
descriptorName: string,
|
|
674
|
+
value: string | CssNode
|
|
675
|
+
): MatchResult;
|
|
676
|
+
matchDeclaration(node: CssNode): MatchResult;
|
|
677
|
+
matchProperty(propertyName: string, value: string | CssNode): MatchResult;
|
|
678
|
+
matchType(typeName: string, value: string | CssNode): MatchResult;
|
|
679
|
+
match(
|
|
680
|
+
syntax: string | definitionSyntax.Node,
|
|
681
|
+
value: string | CssNode
|
|
682
|
+
): MatchResult;
|
|
683
|
+
|
|
684
|
+
findValueFragments(
|
|
685
|
+
propertyName: string,
|
|
686
|
+
value: Value,
|
|
687
|
+
type: string,
|
|
688
|
+
name: string
|
|
689
|
+
): FragmentResult[];
|
|
690
|
+
findDeclarationValueFragments(
|
|
691
|
+
declaration: Declaration,
|
|
692
|
+
type: string,
|
|
693
|
+
name: string
|
|
694
|
+
): FragmentResult[];
|
|
695
|
+
findAllFragments(
|
|
696
|
+
ast: CssNode,
|
|
697
|
+
type: string,
|
|
698
|
+
name: string
|
|
699
|
+
): FragmentResult[];
|
|
700
|
+
|
|
701
|
+
// descriptor getters
|
|
702
|
+
getAtrule(atruleName: string, fallbackBasename?: boolean): any | null;
|
|
703
|
+
getAtrulePrelude(
|
|
704
|
+
atruleName: string,
|
|
705
|
+
fallbackBasename?: boolean
|
|
706
|
+
): any | null;
|
|
707
|
+
getAtruleDescriptor(atruleName: string, name: string): any | null;
|
|
708
|
+
getProperty(propertyName: string, fallbackBasename?: boolean): any | null;
|
|
709
|
+
getType(name: string): any | null;
|
|
710
|
+
|
|
711
|
+
validate(): null | {
|
|
712
|
+
errors: string[];
|
|
713
|
+
types: string[];
|
|
714
|
+
properties: string[];
|
|
715
|
+
};
|
|
716
|
+
dump(syntaxAsAst?: boolean, pretty?: boolean): any;
|
|
717
|
+
toString(): string;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
export const lexer: Lexer;
|
|
721
|
+
export function createLexer(config?: LexerConfig): Lexer;
|
|
722
|
+
|
|
723
|
+
// -------------------------------------------------
|
|
724
|
+
// Tokenizer / misc exports (lightly typed)
|
|
725
|
+
// -------------------------------------------------
|
|
726
|
+
export const tokenTypes: Record<string, number>;
|
|
727
|
+
export const tokenNames: string[];
|
|
728
|
+
export function tokenize(input: string): IterableIterator<any>;
|
|
729
|
+
|
|
730
|
+
// Syntax factory and forking
|
|
731
|
+
export function createSyntax(config: any): any;
|
|
732
|
+
export function fork(ext?: any): any;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// Optional subpath module shims to enable tree-shake-style imports
|
|
736
|
+
declare module "css-tree/lexer" {
|
|
737
|
+
export * from "css-tree";
|
|
738
|
+
}
|
|
739
|
+
declare module "css-tree/parser" {
|
|
740
|
+
export type { ParseOptions, CssNode } from "css-tree";
|
|
741
|
+
export { parse as default } from "css-tree";
|
|
742
|
+
}
|
|
743
|
+
declare module "css-tree/generator" {
|
|
744
|
+
export { generate as default } from "css-tree";
|
|
745
|
+
}
|
|
746
|
+
declare module "css-tree/walker" {
|
|
747
|
+
export {
|
|
748
|
+
walk,
|
|
749
|
+
find,
|
|
750
|
+
findAll,
|
|
751
|
+
findLast,
|
|
752
|
+
WalkOptions,
|
|
753
|
+
WalkHandler,
|
|
754
|
+
} from "css-tree";
|
|
755
|
+
}
|
|
756
|
+
declare module "css-tree/definition-syntax" {
|
|
757
|
+
export { definitionSyntax } from "css-tree";
|
|
758
|
+
}
|
|
759
|
+
declare module "css-tree/utils" {
|
|
760
|
+
export {
|
|
761
|
+
List,
|
|
762
|
+
ListItem,
|
|
763
|
+
clone,
|
|
764
|
+
fromPlainObject,
|
|
765
|
+
toPlainObject,
|
|
766
|
+
property,
|
|
767
|
+
keyword,
|
|
768
|
+
ident,
|
|
769
|
+
string,
|
|
770
|
+
url,
|
|
771
|
+
} from "css-tree";
|
|
772
|
+
}
|