@projectwallace/css-parser 0.13.5 → 0.13.8
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/dist/css-node-DqyvMXBN.d.ts +313 -0
- package/dist/css-node-Uj4oBgaw.js +647 -0
- package/dist/index.d.ts +150 -16
- package/dist/index.js +103 -13
- package/dist/parse-anplusb.d.ts +26 -2
- package/dist/parse-anplusb.js +191 -207
- package/dist/parse-atrule-prelude.d.ts +40 -2
- package/dist/parse-atrule-prelude.js +556 -652
- package/dist/parse-declaration.d.ts +16 -2
- package/dist/parse-declaration.js +140 -167
- package/dist/parse-dimension-CCn_XRDe.js +177 -0
- package/dist/parse-dimension.d.ts +6 -3
- package/dist/parse-dimension.js +1 -35
- package/dist/parse-selector.d.ts +37 -2
- package/dist/parse-selector.js +508 -635
- package/dist/parse-utils-DnsZRpfd.js +98 -0
- package/dist/parse-value.d.ts +23 -2
- package/dist/parse-value.js +176 -224
- package/dist/parse.d.ts +37 -8
- package/dist/parse.js +252 -353
- package/dist/tokenize-BQFB1jXg.js +540 -0
- package/dist/tokenize-odLrcjj2.d.ts +110 -0
- package/dist/tokenize.d.ts +2 -26
- package/dist/tokenize.js +1 -545
- package/package.json +20 -26
- package/dist/arena.d.ts +0 -60
- package/dist/arena.js +0 -291
- package/dist/char-types.d.ts +0 -14
- package/dist/char-types.js +0 -53
- package/dist/constants.d.ts +0 -44
- package/dist/constants.js +0 -51
- package/dist/css-node.d.ts +0 -203
- package/dist/css-node.js +0 -498
- package/dist/parse-utils.d.ts +0 -1
- package/dist/parse-utils.js +0 -60
- package/dist/string-utils.d.ts +0 -99
- package/dist/string-utils.js +0 -129
- package/dist/token-types.d.ts +0 -35
- package/dist/token-types.js +0 -29
- package/dist/walk.d.ts +0 -28
- package/dist/walk.js +0 -51
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
//#region src/arena.d.ts
|
|
2
|
+
declare const STYLESHEET = 1;
|
|
3
|
+
declare const STYLE_RULE = 2;
|
|
4
|
+
declare const AT_RULE = 3;
|
|
5
|
+
declare const DECLARATION = 4;
|
|
6
|
+
declare const SELECTOR = 5;
|
|
7
|
+
declare const COMMENT = 6;
|
|
8
|
+
declare const BLOCK = 7;
|
|
9
|
+
declare const RAW = 8;
|
|
10
|
+
declare const IDENTIFIER = 10;
|
|
11
|
+
declare const NUMBER = 11;
|
|
12
|
+
declare const DIMENSION = 12;
|
|
13
|
+
declare const STRING = 13;
|
|
14
|
+
declare const HASH = 14;
|
|
15
|
+
declare const FUNCTION = 15;
|
|
16
|
+
declare const OPERATOR = 16;
|
|
17
|
+
declare const PARENTHESIS = 17;
|
|
18
|
+
declare const URL = 18;
|
|
19
|
+
declare const SELECTOR_LIST = 20;
|
|
20
|
+
declare const TYPE_SELECTOR = 21;
|
|
21
|
+
declare const CLASS_SELECTOR = 22;
|
|
22
|
+
declare const ID_SELECTOR = 23;
|
|
23
|
+
declare const ATTRIBUTE_SELECTOR = 24;
|
|
24
|
+
declare const PSEUDO_CLASS_SELECTOR = 25;
|
|
25
|
+
declare const PSEUDO_ELEMENT_SELECTOR = 26;
|
|
26
|
+
declare const COMBINATOR = 27;
|
|
27
|
+
declare const UNIVERSAL_SELECTOR = 28;
|
|
28
|
+
declare const NESTING_SELECTOR = 29;
|
|
29
|
+
declare const NTH_SELECTOR = 30;
|
|
30
|
+
declare const NTH_OF_SELECTOR = 31;
|
|
31
|
+
declare const LANG_SELECTOR = 56;
|
|
32
|
+
declare const MEDIA_QUERY = 32;
|
|
33
|
+
declare const MEDIA_FEATURE = 33;
|
|
34
|
+
declare const MEDIA_TYPE = 34;
|
|
35
|
+
declare const CONTAINER_QUERY = 35;
|
|
36
|
+
declare const SUPPORTS_QUERY = 36;
|
|
37
|
+
declare const LAYER_NAME = 37;
|
|
38
|
+
declare const PRELUDE_OPERATOR = 38;
|
|
39
|
+
declare const FEATURE_RANGE = 39;
|
|
40
|
+
declare const AT_RULE_PRELUDE = 40;
|
|
41
|
+
declare const VALUE = 50;
|
|
42
|
+
declare const FLAG_IMPORTANT: number;
|
|
43
|
+
declare const ATTR_OPERATOR_NONE = 0;
|
|
44
|
+
declare const ATTR_OPERATOR_EQUAL = 1;
|
|
45
|
+
declare const ATTR_OPERATOR_TILDE_EQUAL = 2;
|
|
46
|
+
declare const ATTR_OPERATOR_PIPE_EQUAL = 3;
|
|
47
|
+
declare const ATTR_OPERATOR_CARET_EQUAL = 4;
|
|
48
|
+
declare const ATTR_OPERATOR_DOLLAR_EQUAL = 5;
|
|
49
|
+
declare const ATTR_OPERATOR_STAR_EQUAL = 6;
|
|
50
|
+
declare const ATTR_FLAG_NONE = 0;
|
|
51
|
+
declare const ATTR_FLAG_CASE_INSENSITIVE = 1;
|
|
52
|
+
declare const ATTR_FLAG_CASE_SENSITIVE = 2;
|
|
53
|
+
/** @internal */
|
|
54
|
+
declare class CSSDataArena {
|
|
55
|
+
private buffer;
|
|
56
|
+
private view;
|
|
57
|
+
private capacity;
|
|
58
|
+
private count;
|
|
59
|
+
private growth_count;
|
|
60
|
+
private overflow_lengths;
|
|
61
|
+
private static readonly GROWTH_FACTOR;
|
|
62
|
+
private static readonly NODES_PER_KB;
|
|
63
|
+
private static readonly CAPACITY_BUFFER;
|
|
64
|
+
constructor(initial_capacity?: number);
|
|
65
|
+
static capacity_for_source(source_length: number): number;
|
|
66
|
+
get_count(): number;
|
|
67
|
+
get_capacity(): number;
|
|
68
|
+
get_growth_count(): number;
|
|
69
|
+
private node_offset;
|
|
70
|
+
get_type(node_index: number): number;
|
|
71
|
+
get_flags(node_index: number): number;
|
|
72
|
+
get_start_offset(node_index: number): number;
|
|
73
|
+
get_length(node_index: number): number;
|
|
74
|
+
get_content_start(node_index: number): number;
|
|
75
|
+
get_content_length(node_index: number): number;
|
|
76
|
+
get_attr_operator(node_index: number): number;
|
|
77
|
+
get_attr_flags(node_index: number): number;
|
|
78
|
+
get_first_child(node_index: number): number;
|
|
79
|
+
get_next_sibling(node_index: number): number;
|
|
80
|
+
get_start_line(node_index: number): number;
|
|
81
|
+
get_start_column(node_index: number): number;
|
|
82
|
+
get_value_start(node_index: number): number;
|
|
83
|
+
get_value_length(node_index: number): number;
|
|
84
|
+
set_type(node_index: number, type: number): void;
|
|
85
|
+
set_flags(node_index: number, flags: number): void;
|
|
86
|
+
set_length(node_index: number, length: number): void;
|
|
87
|
+
set_content_start_delta(node_index: number, delta: number): void;
|
|
88
|
+
set_content_length(node_index: number, length: number): void;
|
|
89
|
+
set_attr_operator(node_index: number, operator: number): void;
|
|
90
|
+
set_attr_flags(node_index: number, flags: number): void;
|
|
91
|
+
set_first_child(node_index: number, childIndex: number): void;
|
|
92
|
+
set_next_sibling(node_index: number, siblingIndex: number): void;
|
|
93
|
+
set_value_start_delta(node_index: number, delta: number): void;
|
|
94
|
+
set_value_length(node_index: number, length: number): void;
|
|
95
|
+
private grow;
|
|
96
|
+
create_node(type: number, start_offset: number, length: number, start_line: number, start_column: number): number;
|
|
97
|
+
append_children(parent_index: number, children: number[]): void;
|
|
98
|
+
has_children(node_index: number): boolean;
|
|
99
|
+
has_next_sibling(node_index: number): boolean;
|
|
100
|
+
set_flag(node_index: number, flag: number): void;
|
|
101
|
+
clear_flag(node_index: number, flag: number): void;
|
|
102
|
+
has_flag(node_index: number, flag: number): boolean;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/css-node.d.ts
|
|
106
|
+
declare const TYPE_NAMES: {
|
|
107
|
+
readonly 1: "StyleSheet";
|
|
108
|
+
readonly 2: "Rule";
|
|
109
|
+
readonly 3: "Atrule";
|
|
110
|
+
readonly 4: "Declaration";
|
|
111
|
+
readonly 5: "Selector";
|
|
112
|
+
readonly 6: "Comment";
|
|
113
|
+
readonly 7: "Block";
|
|
114
|
+
readonly 8: "Raw";
|
|
115
|
+
readonly 10: "Identifier";
|
|
116
|
+
readonly 11: "Number";
|
|
117
|
+
readonly 12: "Dimension";
|
|
118
|
+
readonly 13: "String";
|
|
119
|
+
readonly 14: "Hash";
|
|
120
|
+
readonly 15: "Function";
|
|
121
|
+
readonly 16: "Operator";
|
|
122
|
+
readonly 17: "Parentheses";
|
|
123
|
+
readonly 18: "Url";
|
|
124
|
+
readonly 19: "UnicodeRange";
|
|
125
|
+
readonly 50: "Value";
|
|
126
|
+
readonly 20: "SelectorList";
|
|
127
|
+
readonly 21: "TypeSelector";
|
|
128
|
+
readonly 22: "ClassSelector";
|
|
129
|
+
readonly 23: "IdSelector";
|
|
130
|
+
readonly 24: "AttributeSelector";
|
|
131
|
+
readonly 25: "PseudoClassSelector";
|
|
132
|
+
readonly 26: "PseudoElementSelector";
|
|
133
|
+
readonly 27: "Combinator";
|
|
134
|
+
readonly 28: "UniversalSelector";
|
|
135
|
+
readonly 29: "NestingSelector";
|
|
136
|
+
readonly 30: "Nth";
|
|
137
|
+
readonly 31: "NthOf";
|
|
138
|
+
readonly 56: "Lang";
|
|
139
|
+
readonly 32: "MediaQuery";
|
|
140
|
+
readonly 33: "Feature";
|
|
141
|
+
readonly 34: "MediaType";
|
|
142
|
+
readonly 35: "ContainerQuery";
|
|
143
|
+
readonly 36: "SupportsQuery";
|
|
144
|
+
readonly 37: "Layer";
|
|
145
|
+
readonly 38: "Operator";
|
|
146
|
+
readonly 39: "MediaFeatureRange";
|
|
147
|
+
readonly 40: "AtrulePrelude";
|
|
148
|
+
};
|
|
149
|
+
type TypeName = (typeof TYPE_NAMES)[keyof typeof TYPE_NAMES] | 'unknown';
|
|
150
|
+
declare const ATTR_OPERATOR_NAMES: Record<number, string | null>;
|
|
151
|
+
declare const ATTR_FLAG_NAMES: Record<number, string | null>;
|
|
152
|
+
type CSSNodeType = typeof STYLESHEET | typeof STYLE_RULE | typeof AT_RULE | typeof DECLARATION | typeof SELECTOR | typeof COMMENT | typeof BLOCK | typeof RAW | typeof IDENTIFIER | typeof NUMBER | typeof DIMENSION | typeof STRING | typeof HASH | typeof FUNCTION | typeof OPERATOR | typeof PARENTHESIS | typeof URL | typeof VALUE | typeof SELECTOR_LIST | typeof TYPE_SELECTOR | typeof CLASS_SELECTOR | typeof ID_SELECTOR | typeof ATTRIBUTE_SELECTOR | typeof PSEUDO_CLASS_SELECTOR | typeof PSEUDO_ELEMENT_SELECTOR | typeof COMBINATOR | typeof UNIVERSAL_SELECTOR | typeof NESTING_SELECTOR | typeof NTH_SELECTOR | typeof NTH_OF_SELECTOR | typeof LANG_SELECTOR | typeof MEDIA_QUERY | typeof MEDIA_FEATURE | typeof MEDIA_TYPE | typeof CONTAINER_QUERY | typeof SUPPORTS_QUERY | typeof LAYER_NAME | typeof PRELUDE_OPERATOR | typeof FEATURE_RANGE | typeof AT_RULE_PRELUDE;
|
|
153
|
+
interface CloneOptions {
|
|
154
|
+
/**
|
|
155
|
+
* Recursively clone all children
|
|
156
|
+
* @default true
|
|
157
|
+
*/
|
|
158
|
+
deep?: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Include location information (line, column, start, length)
|
|
161
|
+
* @default false
|
|
162
|
+
*/
|
|
163
|
+
locations?: boolean;
|
|
164
|
+
}
|
|
165
|
+
type PlainCSSNode = {
|
|
166
|
+
type: number;
|
|
167
|
+
type_name: TypeName;
|
|
168
|
+
text: string;
|
|
169
|
+
children?: PlainCSSNode[];
|
|
170
|
+
name?: string;
|
|
171
|
+
property?: string;
|
|
172
|
+
value?: PlainCSSNode | string | number | null;
|
|
173
|
+
unit?: string;
|
|
174
|
+
prelude?: PlainCSSNode | null;
|
|
175
|
+
is_important?: boolean;
|
|
176
|
+
is_vendor_prefixed?: boolean;
|
|
177
|
+
is_browserhack?: boolean;
|
|
178
|
+
has_error?: boolean;
|
|
179
|
+
attr_operator?: string | null;
|
|
180
|
+
attr_flags?: string | null;
|
|
181
|
+
nth_a?: string | null;
|
|
182
|
+
nth_b?: string | null;
|
|
183
|
+
line?: number;
|
|
184
|
+
column?: number;
|
|
185
|
+
start?: number;
|
|
186
|
+
length?: number;
|
|
187
|
+
end?: number;
|
|
188
|
+
};
|
|
189
|
+
declare class CSSNode {
|
|
190
|
+
private arena;
|
|
191
|
+
private source;
|
|
192
|
+
private index;
|
|
193
|
+
constructor(arena: CSSDataArena, source: string, index: number);
|
|
194
|
+
/**
|
|
195
|
+
* @internal
|
|
196
|
+
* Get the arena (for internal/advanced use only)
|
|
197
|
+
*/
|
|
198
|
+
__get_arena(): CSSDataArena;
|
|
199
|
+
private get_content;
|
|
200
|
+
/** Get node type as number (for performance) */
|
|
201
|
+
get type(): CSSNodeType;
|
|
202
|
+
/** Get node type as human-readable string */
|
|
203
|
+
get type_name(): TypeName;
|
|
204
|
+
/** Get the full text of this node from source */
|
|
205
|
+
get text(): string;
|
|
206
|
+
/** Get the "content" text (at-rule name for at-rules, layer name for import layers) */
|
|
207
|
+
get name(): string | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* Alias for name (for declarations: "color" in "color: blue")
|
|
210
|
+
* More semantic than `name` for declaration nodes
|
|
211
|
+
*/
|
|
212
|
+
get property(): string | undefined;
|
|
213
|
+
/**
|
|
214
|
+
* Get the value text (for declarations: "blue" in "color: blue")
|
|
215
|
+
* For dimension/number nodes: returns the numeric value as a number
|
|
216
|
+
* For string nodes: returns the string content without quotes
|
|
217
|
+
* For URL nodes with quoted string: returns the string with quotes (consistent with STRING node)
|
|
218
|
+
* For URL nodes with unquoted URL: returns the URL content without quotes
|
|
219
|
+
*/
|
|
220
|
+
get value(): CSSNode | string | number | null | undefined;
|
|
221
|
+
/** Get the numeric value for NUMBER and DIMENSION nodes, or null for other node types */
|
|
222
|
+
get value_as_number(): number | null;
|
|
223
|
+
/**
|
|
224
|
+
* Get the prelude node:
|
|
225
|
+
* - For at-rules: AT_RULE_PRELUDE wrapper containing structured prelude children (media queries, layer names, etc.)
|
|
226
|
+
* - For style rules: SELECTOR_LIST or SELECTOR node
|
|
227
|
+
* Returns null if no prelude exists
|
|
228
|
+
*/
|
|
229
|
+
get prelude(): CSSNode | null | undefined;
|
|
230
|
+
/**
|
|
231
|
+
* Get the attribute operator (for attribute selectors: =, ~=, |=, ^=, $=, *=)
|
|
232
|
+
* Returns one of the ATTR_OPERATOR_* constants
|
|
233
|
+
*/
|
|
234
|
+
get attr_operator(): number | undefined;
|
|
235
|
+
/**
|
|
236
|
+
* Get the attribute flags (for attribute selectors: i, s)
|
|
237
|
+
* Returns one of the ATTR_FLAG_* constants
|
|
238
|
+
*/
|
|
239
|
+
get attr_flags(): number | undefined;
|
|
240
|
+
/** Get the unit for dimension nodes (e.g., "px" from "100px", "%" from "50%") */
|
|
241
|
+
get unit(): string | undefined;
|
|
242
|
+
/** Check if this declaration has !important */
|
|
243
|
+
get is_important(): boolean | undefined;
|
|
244
|
+
/** Check if this declaration has a browser hack prefix */
|
|
245
|
+
get is_browserhack(): boolean | undefined;
|
|
246
|
+
/** Check if this has a vendor prefix (computed on-demand) */
|
|
247
|
+
get is_vendor_prefixed(): boolean;
|
|
248
|
+
/** Check if this node has an error */
|
|
249
|
+
get has_error(): boolean;
|
|
250
|
+
/** Check if this node has a prelude (at-rules and style rules) */
|
|
251
|
+
get has_prelude(): boolean;
|
|
252
|
+
/** Check if this rule has a block { } */
|
|
253
|
+
get has_block(): boolean;
|
|
254
|
+
/** Check if this style rule has declarations */
|
|
255
|
+
get has_declarations(): boolean;
|
|
256
|
+
/** Get the block node (for style rules and at-rules with blocks) */
|
|
257
|
+
get block(): CSSNode | null;
|
|
258
|
+
/** Check if this block is empty (no declarations or rules, only comments allowed) */
|
|
259
|
+
get is_empty(): boolean | undefined;
|
|
260
|
+
/** Get start line number */
|
|
261
|
+
get line(): number;
|
|
262
|
+
/** Get start column number */
|
|
263
|
+
get column(): number;
|
|
264
|
+
/** Get start offset in source */
|
|
265
|
+
get start(): number;
|
|
266
|
+
/** Get length in source */
|
|
267
|
+
get length(): number;
|
|
268
|
+
/**
|
|
269
|
+
* Get end offset in source
|
|
270
|
+
* End is not stored, must be calculated
|
|
271
|
+
*/
|
|
272
|
+
get end(): number;
|
|
273
|
+
/** Get first child node */
|
|
274
|
+
get first_child(): CSSNode | null;
|
|
275
|
+
/** Get next sibling node */
|
|
276
|
+
get next_sibling(): CSSNode | null;
|
|
277
|
+
/** Check if this node has a next sibling */
|
|
278
|
+
get has_next(): boolean;
|
|
279
|
+
/**
|
|
280
|
+
* Check if this node has children
|
|
281
|
+
* For pseudo-class/pseudo-element functions, returns true if FLAG_HAS_PARENS is set
|
|
282
|
+
* This allows formatters to distinguish :lang() from :hover
|
|
283
|
+
*/
|
|
284
|
+
get has_children(): boolean;
|
|
285
|
+
/** Get all children as an array */
|
|
286
|
+
get children(): CSSNode[];
|
|
287
|
+
/** Make CSSNode iterable over its children */
|
|
288
|
+
[Symbol.iterator](): Iterator<CSSNode>;
|
|
289
|
+
/** Get the 'a' coefficient from An+B expression (e.g., "2n" from "2n+1", "odd" from "odd") */
|
|
290
|
+
get nth_a(): string | undefined;
|
|
291
|
+
/** Get the 'b' coefficient from An+B expression (e.g., "+1" from "2n+1") */
|
|
292
|
+
get nth_b(): string | undefined;
|
|
293
|
+
/** Get the An+B formula node from :nth-child(2n+1 of .foo) */
|
|
294
|
+
get nth(): CSSNode | undefined;
|
|
295
|
+
/** Get the selector list from :nth-child(2n+1 of .foo) */
|
|
296
|
+
get selector(): CSSNode | undefined;
|
|
297
|
+
/**
|
|
298
|
+
* Get selector list from pseudo-class functions
|
|
299
|
+
* Works for :is(.a), :not(.b), :has(.c), :where(.d), :nth-child(2n of .e)
|
|
300
|
+
*/
|
|
301
|
+
get selector_list(): CSSNode | undefined;
|
|
302
|
+
/**
|
|
303
|
+
* Clone this node as a mutable plain JavaScript object with children as arrays.
|
|
304
|
+
* See API.md for examples.
|
|
305
|
+
*
|
|
306
|
+
* @param options - Cloning configuration
|
|
307
|
+
* @param options.deep - Recursively clone children (default: true)
|
|
308
|
+
* @param options.locations - Include line/column/start/length (default: false)
|
|
309
|
+
*/
|
|
310
|
+
clone(options?: CloneOptions): PlainCSSNode;
|
|
311
|
+
}
|
|
312
|
+
//#endregion
|
|
313
|
+
export { STYLESHEET as $, FLAG_IMPORTANT as A, NESTING_SELECTOR as B, COMBINATOR as C, DECLARATION as D, CSSDataArena as E, LANG_SELECTOR as F, PARENTHESIS as G, NTH_SELECTOR as H, LAYER_NAME as I, PSEUDO_ELEMENT_SELECTOR as J, PRELUDE_OPERATOR as K, MEDIA_FEATURE as L, HASH as M, IDENTIFIER as N, DIMENSION as O, ID_SELECTOR as P, STRING as Q, MEDIA_QUERY as R, CLASS_SELECTOR as S, CONTAINER_QUERY as T, NUMBER as U, NTH_OF_SELECTOR as V, OPERATOR as W, SELECTOR as X, RAW as Y, SELECTOR_LIST as Z, ATTR_OPERATOR_STAR_EQUAL as _, CloneOptions as a, VALUE as at, AT_RULE_PRELUDE as b, ATTRIBUTE_SELECTOR as c, ATTR_FLAG_NONE as d, STYLE_RULE as et, ATTR_OPERATOR_CARET_EQUAL as f, ATTR_OPERATOR_PIPE_EQUAL as g, ATTR_OPERATOR_NONE as h, CSSNodeType as i, URL as it, FUNCTION as j, FEATURE_RANGE as k, ATTR_FLAG_CASE_INSENSITIVE as l, ATTR_OPERATOR_EQUAL as m, ATTR_OPERATOR_NAMES as n, TYPE_SELECTOR as nt, PlainCSSNode as o, ATTR_OPERATOR_DOLLAR_EQUAL as p, PSEUDO_CLASS_SELECTOR as q, CSSNode as r, UNIVERSAL_SELECTOR as rt, TYPE_NAMES as s, ATTR_FLAG_NAMES as t, SUPPORTS_QUERY as tt, ATTR_FLAG_CASE_SENSITIVE as u, ATTR_OPERATOR_TILDE_EQUAL as v, COMMENT as w, BLOCK as x, AT_RULE as y, MEDIA_TYPE as z };
|