@projectwallace/css-parser 0.19.2 → 0.19.4
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/README.md +15 -2
- package/dist/{arena-CsJhQRUX.js → arena-CaLnNKbP.js} +7 -4
- package/dist/{arena-7RLvyGPB.d.ts → arena-D689Bo6V.d.ts} +4 -3
- package/dist/constants.d.ts +46 -48
- package/dist/constants.js +2 -3
- package/dist/{css-node-BKcf0ZeS.js → css-node-CDTLvxo3.js} +3 -4
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/{node-types-CD7A-d_c.d.ts → node-types-BF6bhAjo.d.ts} +56 -64
- package/dist/node-types.d.ts +1 -1
- package/dist/node-types.js +2 -3
- package/dist/parse-anplusb.d.ts +3 -5
- package/dist/parse-anplusb.js +5 -6
- package/dist/{value-node-parser-B568SwUx.js → parse-atrule-prelude-BMkgCZjw.js} +465 -15
- package/dist/parse-atrule-prelude.d.ts +13 -6
- package/dist/parse-atrule-prelude.js +1 -431
- package/dist/parse-declaration.d.ts +4 -6
- package/dist/parse-declaration.js +8 -9
- package/dist/parse-dimension.d.ts +1 -3
- package/dist/parse-dimension.js +2 -3
- package/dist/{parse-selector-DORsuJvq.js → parse-selector-CMKZgPmu.js} +6 -8
- package/dist/parse-selector.d.ts +3 -5
- package/dist/parse-selector.js +1 -1
- package/dist/parse-value.d.ts +4 -6
- package/dist/parse-value.js +6 -7
- package/dist/parse.d.ts +10 -5
- package/dist/parse.js +9 -10
- package/dist/{string-helpers-t7UofIfp.d.ts → string-helpers-CwNEcEhd.d.ts} +0 -2
- package/dist/string-helpers.d.ts +1 -1
- package/dist/string-helpers.js +1 -1
- package/dist/{string-utils-aEEsA2CS.js → string-utils-BYH1Oe8a.js} +0 -1
- package/dist/{token-types-Bqsf5FX-.d.ts → token-types-BhoXrORA.d.ts} +0 -2
- package/dist/token-types.d.ts +1 -1
- package/dist/token-types.js +1 -2
- package/dist/{tokenize-B2QSzdrM.js → tokenize-DC2Vb0J_.js} +20 -6
- package/dist/tokenize.d.ts +17 -5
- package/dist/tokenize.js +1 -1
- package/dist/walk.d.ts +1 -3
- package/dist/walk.js +3 -4
- package/package.json +3 -3
|
@@ -1,431 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import "./token-types.js";
|
|
3
|
-
import { l as CSSDataArena } from "./arena-CsJhQRUX.js";
|
|
4
|
-
import { c as str_equals_range, d as strip_vendor_prefix, t as is_and_or_not_range } from "./string-utils-aEEsA2CS.js";
|
|
5
|
-
import { t as CSSNode } from "./css-node-BKcf0ZeS.js";
|
|
6
|
-
import { s as trim_boundaries, t as SelectorParser } from "./parse-selector-DORsuJvq.js";
|
|
7
|
-
import { n as ConditionParser, t as ValueNodeParser } from "./value-node-parser-B568SwUx.js";
|
|
8
|
-
//#region src/parse-atrule-prelude.ts
|
|
9
|
-
/** @internal */
|
|
10
|
-
var AtRulePreludeParser = class {
|
|
11
|
-
lexer;
|
|
12
|
-
arena;
|
|
13
|
-
source;
|
|
14
|
-
prelude_end;
|
|
15
|
-
value_node_parser;
|
|
16
|
-
condition_parser;
|
|
17
|
-
selector_parser;
|
|
18
|
-
constructor(arena, source) {
|
|
19
|
-
this.arena = arena;
|
|
20
|
-
this.source = source;
|
|
21
|
-
this.lexer = new Lexer(source);
|
|
22
|
-
this.prelude_end = 0;
|
|
23
|
-
this.value_node_parser = new ValueNodeParser(arena, source);
|
|
24
|
-
this.condition_parser = new ConditionParser(arena, source, this.value_node_parser);
|
|
25
|
-
this.selector_parser = new SelectorParser(arena, source);
|
|
26
|
-
}
|
|
27
|
-
parse_prelude(at_rule_name, start, end, line = 1, column = 1) {
|
|
28
|
-
this.prelude_end = end;
|
|
29
|
-
this.lexer.seek(start, line, column);
|
|
30
|
-
return this.parse_prelude_dispatch(at_rule_name);
|
|
31
|
-
}
|
|
32
|
-
parse_prelude_dispatch(at_rule_name) {
|
|
33
|
-
switch (strip_vendor_prefix(at_rule_name).toLowerCase()) {
|
|
34
|
-
case "media": return this.parse_media_query_list();
|
|
35
|
-
case "container": return this.parse_container_query();
|
|
36
|
-
case "supports": return this.parse_supports_query();
|
|
37
|
-
case "layer": return this.parse_layer_names();
|
|
38
|
-
case "keyframes":
|
|
39
|
-
case "property":
|
|
40
|
-
case "counter-style":
|
|
41
|
-
case "color-profile":
|
|
42
|
-
case "font-palette-values":
|
|
43
|
-
case "position-try":
|
|
44
|
-
case "font-feature-values":
|
|
45
|
-
case "page": return this.parse_identifier();
|
|
46
|
-
case "function": return this.parse_function_prelude();
|
|
47
|
-
case "import": return this.parse_import_prelude();
|
|
48
|
-
case "charset": return this.parse_charset_prelude();
|
|
49
|
-
case "namespace": return this.parse_namespace_prelude();
|
|
50
|
-
case "scope": return this.parse_scope_prelude();
|
|
51
|
-
case "custom-media": return this.parse_custom_media_prelude();
|
|
52
|
-
}
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
parse_media_query_list() {
|
|
56
|
-
const nodes = [];
|
|
57
|
-
while (this.lexer.pos < this.prelude_end) {
|
|
58
|
-
this.skip_whitespace();
|
|
59
|
-
if (this.lexer.pos >= this.prelude_end) break;
|
|
60
|
-
const query = this.parse_single_media_query();
|
|
61
|
-
if (query !== null) nodes.push(query);
|
|
62
|
-
this.skip_whitespace();
|
|
63
|
-
const saved = this.lexer.save_position();
|
|
64
|
-
this.next_token();
|
|
65
|
-
if (this.lexer.token_type !== 18) this.lexer.restore_position(saved);
|
|
66
|
-
}
|
|
67
|
-
return nodes;
|
|
68
|
-
}
|
|
69
|
-
create_node(type, start, end) {
|
|
70
|
-
return this.arena.create_node(type, start, end - start, this.lexer.token_line, this.lexer.token_column);
|
|
71
|
-
}
|
|
72
|
-
paren_content_end = 0;
|
|
73
|
-
paren_close_end = 0;
|
|
74
|
-
scan_matching_paren() {
|
|
75
|
-
let depth = 1;
|
|
76
|
-
let content_end = this.lexer.pos;
|
|
77
|
-
let close_end = this.lexer.token_end;
|
|
78
|
-
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
79
|
-
const token_type = this.next_token();
|
|
80
|
-
if (token_type === 21 || token_type === 2) depth++;
|
|
81
|
-
else if (token_type === 22) {
|
|
82
|
-
depth--;
|
|
83
|
-
if (depth === 0) {
|
|
84
|
-
content_end = this.lexer.token_start;
|
|
85
|
-
close_end = this.lexer.token_end;
|
|
86
|
-
}
|
|
87
|
-
} else if (token_type === 26) break;
|
|
88
|
-
}
|
|
89
|
-
this.paren_content_end = content_end;
|
|
90
|
-
this.paren_close_end = close_end;
|
|
91
|
-
return depth === 0;
|
|
92
|
-
}
|
|
93
|
-
parse_single_media_query() {
|
|
94
|
-
const query_start = this.lexer.pos;
|
|
95
|
-
this.skip_whitespace();
|
|
96
|
-
if (this.lexer.pos >= this.prelude_end) return null;
|
|
97
|
-
let first_component = 0;
|
|
98
|
-
let last_component = 0;
|
|
99
|
-
const saved_token_start = this.lexer.save_position();
|
|
100
|
-
this.next_token();
|
|
101
|
-
if (this.lexer.token_type === 1) {
|
|
102
|
-
const source = this.source;
|
|
103
|
-
const token_start = this.lexer.token_start;
|
|
104
|
-
const token_end = this.lexer.token_end;
|
|
105
|
-
if (str_equals_range(source, token_start, token_end, "only") || str_equals_range(source, token_start, token_end, "not")) {
|
|
106
|
-
const modifier = this.create_node(38, token_start, token_end);
|
|
107
|
-
first_component = modifier;
|
|
108
|
-
last_component = modifier;
|
|
109
|
-
} else this.lexer.restore_position(saved_token_start);
|
|
110
|
-
} else this.lexer.restore_position(saved_token_start);
|
|
111
|
-
while (this.lexer.pos < this.prelude_end) {
|
|
112
|
-
this.skip_whitespace();
|
|
113
|
-
if (this.lexer.pos >= this.prelude_end) break;
|
|
114
|
-
if (this.peek_token_type() === 18) break;
|
|
115
|
-
this.next_token();
|
|
116
|
-
const token_type = this.lexer.token_type;
|
|
117
|
-
let component = null;
|
|
118
|
-
if (token_type === 21) {
|
|
119
|
-
component = this.condition_parser.parse_media_feature(this.lexer.token_start, this.prelude_end, this.lexer.token_line, this.lexer.token_column);
|
|
120
|
-
if (component !== null) this.condition_parser.seek_to_end(this.lexer);
|
|
121
|
-
} else if (token_type === 1) {
|
|
122
|
-
const token_start = this.lexer.token_start;
|
|
123
|
-
const token_end = this.lexer.token_end;
|
|
124
|
-
if (is_and_or_not_range(this.source, token_start, token_end)) component = this.create_node(38, token_start, token_end);
|
|
125
|
-
else component = this.create_node(34, token_start, token_end);
|
|
126
|
-
} else break;
|
|
127
|
-
if (component !== null) {
|
|
128
|
-
if (first_component === 0) first_component = component;
|
|
129
|
-
else this.arena.set_next_sibling(last_component, component);
|
|
130
|
-
last_component = component;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (first_component === 0) return null;
|
|
134
|
-
const query_node = this.create_node(32, query_start, this.lexer.pos);
|
|
135
|
-
this.arena.set_first_child(query_node, first_component);
|
|
136
|
-
return query_node;
|
|
137
|
-
}
|
|
138
|
-
parse_container_query() {
|
|
139
|
-
const query_start = this.lexer.pos;
|
|
140
|
-
let first_component = 0;
|
|
141
|
-
let last_component = 0;
|
|
142
|
-
while (this.lexer.pos < this.prelude_end) {
|
|
143
|
-
this.skip_whitespace();
|
|
144
|
-
if (this.lexer.pos >= this.prelude_end) break;
|
|
145
|
-
this.next_token();
|
|
146
|
-
const token_type = this.lexer.token_type;
|
|
147
|
-
let component = null;
|
|
148
|
-
if (token_type === 21) {
|
|
149
|
-
component = this.condition_parser.parse_media_feature(this.lexer.token_start, this.prelude_end, this.lexer.token_line, this.lexer.token_column);
|
|
150
|
-
if (component !== null) this.condition_parser.seek_to_end(this.lexer);
|
|
151
|
-
} else if (token_type === 2) {
|
|
152
|
-
component = this.condition_parser.parse_function_condition(this.lexer.token_start, this.prelude_end, this.lexer.token_line, this.lexer.token_column);
|
|
153
|
-
this.condition_parser.seek_to_end(this.lexer);
|
|
154
|
-
} else if (token_type === 1) {
|
|
155
|
-
const token_start = this.lexer.token_start;
|
|
156
|
-
const token_end = this.lexer.token_end;
|
|
157
|
-
if (is_and_or_not_range(this.source, token_start, token_end)) component = this.create_node(38, token_start, token_end);
|
|
158
|
-
else component = this.create_node(10, token_start, token_end);
|
|
159
|
-
}
|
|
160
|
-
if (component !== null) {
|
|
161
|
-
if (first_component === 0) first_component = component;
|
|
162
|
-
else this.arena.set_next_sibling(last_component, component);
|
|
163
|
-
last_component = component;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (first_component === 0) return [];
|
|
167
|
-
const query_node = this.create_node(35, query_start, this.lexer.pos);
|
|
168
|
-
this.arena.set_first_child(query_node, first_component);
|
|
169
|
-
return [query_node];
|
|
170
|
-
}
|
|
171
|
-
parse_supports_query() {
|
|
172
|
-
return this.condition_parser.parse_supports_condition(this.lexer.pos, this.prelude_end, this.lexer.line, this.lexer.column);
|
|
173
|
-
}
|
|
174
|
-
parse_layer_names() {
|
|
175
|
-
const nodes = [];
|
|
176
|
-
while (this.lexer.pos < this.prelude_end) {
|
|
177
|
-
this.skip_whitespace();
|
|
178
|
-
if (this.lexer.pos >= this.prelude_end) break;
|
|
179
|
-
this.next_token();
|
|
180
|
-
const token_type = this.lexer.token_type;
|
|
181
|
-
if (token_type === 1) {
|
|
182
|
-
const name_start = this.lexer.token_start;
|
|
183
|
-
let name_end = this.lexer.token_end;
|
|
184
|
-
while (this.lexer.pos < this.prelude_end) {
|
|
185
|
-
const saved = this.lexer.save_position();
|
|
186
|
-
if (this.next_token() !== 9 || this.source.charCodeAt(this.lexer.token_start) !== 46 || this.lexer.token_start !== name_end) {
|
|
187
|
-
this.lexer.restore_position(saved);
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
const dot_end = this.lexer.token_end;
|
|
191
|
-
if (this.next_token() !== 1 || this.lexer.token_start !== dot_end) {
|
|
192
|
-
this.lexer.restore_position(saved);
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
name_end = this.lexer.token_end;
|
|
196
|
-
}
|
|
197
|
-
const layer = this.create_node(37, name_start, name_end);
|
|
198
|
-
this.arena.set_content_start_delta(layer, 0);
|
|
199
|
-
this.arena.set_content_length(layer, name_end - name_start);
|
|
200
|
-
nodes.push(layer);
|
|
201
|
-
} else if (token_type === 18) continue;
|
|
202
|
-
else if (token_type === 13) continue;
|
|
203
|
-
}
|
|
204
|
-
return nodes;
|
|
205
|
-
}
|
|
206
|
-
parse_function_prelude() {
|
|
207
|
-
this.skip_whitespace();
|
|
208
|
-
if (this.lexer.pos >= this.prelude_end) return [];
|
|
209
|
-
this.next_token();
|
|
210
|
-
if (this.lexer.token_type !== 2) return [];
|
|
211
|
-
const name_start = this.lexer.token_start;
|
|
212
|
-
const name_end = this.lexer.token_end - 1;
|
|
213
|
-
return [this.create_node(10, name_start, name_end)];
|
|
214
|
-
}
|
|
215
|
-
parse_identifier() {
|
|
216
|
-
this.skip_whitespace();
|
|
217
|
-
if (this.lexer.pos >= this.prelude_end) return [];
|
|
218
|
-
this.next_token();
|
|
219
|
-
if (this.lexer.token_type !== 1) return [];
|
|
220
|
-
return [this.create_node(10, this.lexer.token_start, this.lexer.token_end)];
|
|
221
|
-
}
|
|
222
|
-
parse_charset_prelude() {
|
|
223
|
-
this.skip_whitespace();
|
|
224
|
-
if (this.lexer.pos >= this.prelude_end) return [];
|
|
225
|
-
this.next_token();
|
|
226
|
-
if (this.lexer.token_type !== 5) return [];
|
|
227
|
-
return [this.create_node(13, this.lexer.token_start, this.lexer.token_end)];
|
|
228
|
-
}
|
|
229
|
-
parse_import_prelude() {
|
|
230
|
-
const nodes = [];
|
|
231
|
-
this.skip_whitespace();
|
|
232
|
-
if (this.lexer.pos >= this.prelude_end) return [];
|
|
233
|
-
const url_node = this.parse_import_url();
|
|
234
|
-
if (url_node === null) return [];
|
|
235
|
-
nodes.push(url_node);
|
|
236
|
-
this.skip_whitespace();
|
|
237
|
-
if (this.lexer.pos >= this.prelude_end) return nodes;
|
|
238
|
-
const layer_node = this.parse_import_layer();
|
|
239
|
-
if (layer_node !== null) nodes.push(layer_node);
|
|
240
|
-
this.skip_whitespace();
|
|
241
|
-
if (this.lexer.pos >= this.prelude_end) return nodes;
|
|
242
|
-
const supports_node = this.parse_import_supports();
|
|
243
|
-
if (supports_node !== null) nodes.push(supports_node);
|
|
244
|
-
this.skip_whitespace();
|
|
245
|
-
if (this.lexer.pos >= this.prelude_end) return nodes;
|
|
246
|
-
const media_nodes = this.parse_media_query_list();
|
|
247
|
-
nodes.push(...media_nodes);
|
|
248
|
-
return nodes;
|
|
249
|
-
}
|
|
250
|
-
parse_import_url() {
|
|
251
|
-
this.next_token();
|
|
252
|
-
if (this.lexer.token_type !== 7 && this.lexer.token_type !== 2 && this.lexer.token_type !== 5) return null;
|
|
253
|
-
const url_start = this.lexer.token_start;
|
|
254
|
-
let url_end = this.lexer.token_end;
|
|
255
|
-
if (this.lexer.token_type === 2) {
|
|
256
|
-
this.scan_matching_paren();
|
|
257
|
-
url_end = this.paren_close_end;
|
|
258
|
-
}
|
|
259
|
-
return this.create_node(18, url_start, url_end);
|
|
260
|
-
}
|
|
261
|
-
parse_import_layer() {
|
|
262
|
-
const saved = this.lexer.save_position();
|
|
263
|
-
this.next_token();
|
|
264
|
-
if (this.lexer.token_type === 1 || this.lexer.token_type === 2) {
|
|
265
|
-
const name_end = this.lexer.token_type === 2 ? this.lexer.token_end - 1 : this.lexer.token_end;
|
|
266
|
-
if (str_equals_range(this.source, this.lexer.token_start, name_end, "layer")) {
|
|
267
|
-
const layer_start = this.lexer.token_start;
|
|
268
|
-
if (this.lexer.token_type === 1) {
|
|
269
|
-
const layer_node = this.create_node(37, layer_start, this.lexer.token_end);
|
|
270
|
-
this.arena.set_content_start_delta(layer_node, 0);
|
|
271
|
-
this.arena.set_content_length(layer_node, 0);
|
|
272
|
-
return layer_node;
|
|
273
|
-
}
|
|
274
|
-
const content_start = this.lexer.token_end;
|
|
275
|
-
const after_open = this.lexer.save_position();
|
|
276
|
-
const matched = this.scan_matching_paren();
|
|
277
|
-
const content_end = this.paren_content_end;
|
|
278
|
-
const layer_end = matched ? this.paren_close_end : this.lexer.pos;
|
|
279
|
-
const func_node = this.create_node(15, layer_start, layer_end);
|
|
280
|
-
this.arena.set_content_start_delta(func_node, 0);
|
|
281
|
-
this.arena.set_content_length(func_node, name_end - layer_start);
|
|
282
|
-
const trimmed = matched ? trim_boundaries(this.source, content_start, content_end) : null;
|
|
283
|
-
if (trimmed) {
|
|
284
|
-
this.arena.set_value_start_delta(func_node, trimmed[0] - layer_start);
|
|
285
|
-
this.arena.set_value_length(func_node, trimmed[1] - trimmed[0]);
|
|
286
|
-
const after_close = this.lexer.save_position();
|
|
287
|
-
const saved_prelude_end = this.prelude_end;
|
|
288
|
-
this.lexer.restore_position(after_open);
|
|
289
|
-
this.prelude_end = content_end;
|
|
290
|
-
const names = this.parse_layer_names();
|
|
291
|
-
this.prelude_end = saved_prelude_end;
|
|
292
|
-
this.lexer.restore_position(after_close);
|
|
293
|
-
this.arena.append_children(func_node, names);
|
|
294
|
-
}
|
|
295
|
-
return func_node;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
this.lexer.restore_position(saved);
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
301
|
-
parse_import_supports() {
|
|
302
|
-
const saved = this.lexer.save_position();
|
|
303
|
-
this.next_token();
|
|
304
|
-
if (this.lexer.token_type === 2) {
|
|
305
|
-
if (str_equals_range(this.source, this.lexer.token_start, this.lexer.token_end - 1, "supports")) {
|
|
306
|
-
const supports_start = this.lexer.token_start;
|
|
307
|
-
const name_end = this.lexer.token_end - 1;
|
|
308
|
-
const content_start = this.lexer.token_end;
|
|
309
|
-
const line = this.lexer.line;
|
|
310
|
-
const column = this.lexer.column;
|
|
311
|
-
this.scan_matching_paren();
|
|
312
|
-
const content_end = this.paren_content_end;
|
|
313
|
-
const supports_end = this.paren_close_end;
|
|
314
|
-
const func_node = this.create_node(15, supports_start, supports_end);
|
|
315
|
-
this.arena.set_content_start_delta(func_node, 0);
|
|
316
|
-
this.arena.set_content_length(func_node, name_end - supports_start);
|
|
317
|
-
const trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
318
|
-
if (trimmed) {
|
|
319
|
-
const condition_start = trimmed[0];
|
|
320
|
-
const condition_end = trimmed[1];
|
|
321
|
-
const condition_length = condition_end - condition_start;
|
|
322
|
-
this.arena.set_value_start_delta(func_node, condition_start - supports_start);
|
|
323
|
-
this.arena.set_value_length(func_node, condition_length);
|
|
324
|
-
const decl_child = this.condition_parser.parse_supports_declaration_content(condition_start, condition_end);
|
|
325
|
-
if (decl_child === null) {
|
|
326
|
-
const children = this.condition_parser.parse_supports_condition(condition_start, condition_end, line, column);
|
|
327
|
-
this.arena.append_children(func_node, children);
|
|
328
|
-
} else {
|
|
329
|
-
const query = this.create_node(36, condition_start, condition_end);
|
|
330
|
-
this.arena.set_value_start_delta(query, 0);
|
|
331
|
-
this.arena.set_value_length(query, condition_length);
|
|
332
|
-
this.arena.set_first_child(query, decl_child);
|
|
333
|
-
this.arena.set_first_child(func_node, query);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return func_node;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
this.lexer.restore_position(saved);
|
|
340
|
-
return null;
|
|
341
|
-
}
|
|
342
|
-
skip_whitespace() {
|
|
343
|
-
this.lexer.skip_whitespace_in_range(this.prelude_end);
|
|
344
|
-
}
|
|
345
|
-
peek_token_type() {
|
|
346
|
-
const saved = this.lexer.save_position();
|
|
347
|
-
this.next_token();
|
|
348
|
-
const type = this.lexer.token_type;
|
|
349
|
-
this.lexer.restore_position(saved);
|
|
350
|
-
return type;
|
|
351
|
-
}
|
|
352
|
-
next_token() {
|
|
353
|
-
if (this.lexer.pos >= this.prelude_end) {
|
|
354
|
-
this.lexer.token_type = 26;
|
|
355
|
-
return 26;
|
|
356
|
-
}
|
|
357
|
-
return this.lexer.next_token(false);
|
|
358
|
-
}
|
|
359
|
-
parse_namespace_prelude() {
|
|
360
|
-
const nodes = [];
|
|
361
|
-
this.skip_whitespace();
|
|
362
|
-
if (this.lexer.pos >= this.prelude_end) return [];
|
|
363
|
-
const saved = this.lexer.save_position();
|
|
364
|
-
this.next_token();
|
|
365
|
-
if (this.lexer.token_type === 1) {
|
|
366
|
-
nodes.push(this.create_node(10, this.lexer.token_start, this.lexer.token_end));
|
|
367
|
-
this.skip_whitespace();
|
|
368
|
-
} else this.lexer.restore_position(saved);
|
|
369
|
-
const url_node = this.parse_import_url();
|
|
370
|
-
if (url_node !== null) nodes.push(url_node);
|
|
371
|
-
return nodes;
|
|
372
|
-
}
|
|
373
|
-
parse_scope_prelude() {
|
|
374
|
-
const nodes = [];
|
|
375
|
-
while (this.lexer.pos < this.prelude_end) {
|
|
376
|
-
this.skip_whitespace();
|
|
377
|
-
if (this.lexer.pos >= this.prelude_end) break;
|
|
378
|
-
const token_type = this.peek_token_type();
|
|
379
|
-
if (token_type === 21) {
|
|
380
|
-
this.next_token();
|
|
381
|
-
const paren_start = this.lexer.token_start;
|
|
382
|
-
const content_start = this.lexer.pos;
|
|
383
|
-
const content_line = this.lexer.token_line;
|
|
384
|
-
const content_column = this.lexer.token_column;
|
|
385
|
-
this.scan_matching_paren();
|
|
386
|
-
const content_end = this.paren_content_end;
|
|
387
|
-
const paren_end = this.paren_close_end;
|
|
388
|
-
const scope_node = this.create_node(41, paren_start, paren_end);
|
|
389
|
-
const trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
390
|
-
if (trimmed) {
|
|
391
|
-
this.arena.set_value_start_delta(scope_node, trimmed[0] - paren_start);
|
|
392
|
-
this.arena.set_value_length(scope_node, trimmed[1] - trimmed[0]);
|
|
393
|
-
let line = content_line;
|
|
394
|
-
let column = content_column;
|
|
395
|
-
for (let i = content_start; i < trimmed[0]; i++) if (this.source.charCodeAt(i) === 10) {
|
|
396
|
-
line++;
|
|
397
|
-
column = 1;
|
|
398
|
-
} else column++;
|
|
399
|
-
const selector_list = this.selector_parser.parse_selector(trimmed[0], trimmed[1], line, column, false);
|
|
400
|
-
if (selector_list !== null) this.arena.set_first_child(scope_node, selector_list);
|
|
401
|
-
}
|
|
402
|
-
nodes.push(scope_node);
|
|
403
|
-
} else if (token_type === 1) {
|
|
404
|
-
this.next_token();
|
|
405
|
-
if (str_equals_range(this.source, this.lexer.token_start, this.lexer.token_end, "to")) nodes.push(this.create_node(38, this.lexer.token_start, this.lexer.token_end));
|
|
406
|
-
} else this.next_token();
|
|
407
|
-
}
|
|
408
|
-
return nodes;
|
|
409
|
-
}
|
|
410
|
-
parse_custom_media_prelude() {
|
|
411
|
-
const nodes = [];
|
|
412
|
-
this.skip_whitespace();
|
|
413
|
-
if (this.lexer.pos >= this.prelude_end) return [];
|
|
414
|
-
this.next_token();
|
|
415
|
-
if (this.lexer.token_type !== 1) return [];
|
|
416
|
-
nodes.push(this.create_node(10, this.lexer.token_start, this.lexer.token_end), ...this.parse_media_query_list());
|
|
417
|
-
return nodes;
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
/**
|
|
421
|
-
* Parse an at-rule prelude string and return an array of AST nodes
|
|
422
|
-
* @param at_rule_name - The name of the at-rule (e.g., "media", "supports", "layer")
|
|
423
|
-
* @param prelude - The at-rule prelude to parse (e.g., "(min-width: 768px)", "utilities")
|
|
424
|
-
* @returns An array of CSSNode objects representing the parsed prelude
|
|
425
|
-
*/
|
|
426
|
-
function parse_atrule_prelude(at_rule_name, prelude) {
|
|
427
|
-
const arena = new CSSDataArena(CSSDataArena.capacity_for_source(prelude.length));
|
|
428
|
-
return new AtRulePreludeParser(arena, prelude).parse_prelude(at_rule_name, 0, prelude.length).map((index) => new CSSNode(arena, prelude, index));
|
|
429
|
-
}
|
|
430
|
-
//#endregion
|
|
431
|
-
export { AtRulePreludeParser, parse_atrule_prelude };
|
|
1
|
+
export { t as AtRulePreludeParser, n as parse_atrule_prelude } from "./parse-atrule-prelude-BMkgCZjw.js";
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { l as CSSDataArena } from "./arena-
|
|
1
|
+
import { l as CSSDataArena } from "./arena-D689Bo6V.js";
|
|
2
2
|
import { Lexer } from "./tokenize.js";
|
|
3
|
-
import { f as Declaration } from "./node-types-
|
|
4
|
-
//#region src/parse-declaration.d.ts
|
|
3
|
+
import { f as Declaration } from "./node-types-BF6bhAjo.js";
|
|
5
4
|
/** @internal */
|
|
6
5
|
export declare class DeclarationParser {
|
|
7
6
|
private arena;
|
|
8
7
|
private source;
|
|
9
8
|
private value_parser;
|
|
10
9
|
private lookahead_position;
|
|
11
|
-
constructor(arena: CSSDataArena, source: string, parse_values?: boolean);
|
|
10
|
+
constructor(arena: CSSDataArena, source: string, parse_values?: boolean, media_feature_range_name_as_child?: boolean);
|
|
12
11
|
parse_declaration(start: number, end: number, line?: number, column?: number): number | null;
|
|
13
12
|
parse_declaration_with_lexer(lexer: Lexer, end: number): number | null;
|
|
14
13
|
}
|
|
@@ -17,5 +16,4 @@ export declare class DeclarationParser {
|
|
|
17
16
|
* @param source - The CSS declaration to parse (e.g., "color: red", "margin: 10px !important")
|
|
18
17
|
* @returns The DECLARATION CSSNode
|
|
19
18
|
*/
|
|
20
|
-
export declare function parse_declaration(source: string): Declaration;
|
|
21
|
-
//#endregion
|
|
19
|
+
export declare function parse_declaration(source: string): Declaration;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-
|
|
1
|
+
import { t as Lexer } from "./tokenize-DC2Vb0J_.js";
|
|
2
2
|
import "./token-types.js";
|
|
3
|
-
import { l as CSSDataArena } from "./arena-
|
|
4
|
-
import { a as is_vendor_prefixed } from "./string-utils-
|
|
5
|
-
import { t as CSSNode } from "./css-node-
|
|
6
|
-
import { a as skip_whitespace_and_comments_backward, o as skip_whitespace_and_comments_forward } from "./parse-selector-
|
|
3
|
+
import { l as CSSDataArena } from "./arena-CaLnNKbP.js";
|
|
4
|
+
import { a as is_vendor_prefixed } from "./string-utils-BYH1Oe8a.js";
|
|
5
|
+
import { t as CSSNode } from "./css-node-CDTLvxo3.js";
|
|
6
|
+
import { a as skip_whitespace_and_comments_backward, o as skip_whitespace_and_comments_forward } from "./parse-selector-CMKZgPmu.js";
|
|
7
7
|
import { ValueParser } from "./parse-value.js";
|
|
8
|
-
|
|
8
|
+
// src/parse-declaration.ts
|
|
9
9
|
/** @internal */
|
|
10
10
|
var DeclarationParser = class {
|
|
11
11
|
arena;
|
|
12
12
|
source;
|
|
13
13
|
value_parser;
|
|
14
14
|
lookahead_position = new Lexer("").save_position();
|
|
15
|
-
constructor(arena, source, parse_values = true) {
|
|
15
|
+
constructor(arena, source, parse_values = true, media_feature_range_name_as_child = false) {
|
|
16
16
|
this.arena = arena;
|
|
17
17
|
this.source = source;
|
|
18
|
-
this.value_parser = parse_values ? new ValueParser(arena, source) : null;
|
|
18
|
+
this.value_parser = parse_values ? new ValueParser(arena, source, media_feature_range_name_as_child) : null;
|
|
19
19
|
}
|
|
20
20
|
parse_declaration(start, end, line = 1, column = 1) {
|
|
21
21
|
const lexer = new Lexer(this.source);
|
|
@@ -180,5 +180,4 @@ function parse_declaration(source) {
|
|
|
180
180
|
}
|
|
181
181
|
return new CSSNode(arena, source, decl_index);
|
|
182
182
|
}
|
|
183
|
-
//#endregion
|
|
184
183
|
export { DeclarationParser, parse_declaration };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/parse-dimension.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Find where a dimension's numeric part ends, e.g. 3 for "100px" or 2 for "2%".
|
|
4
3
|
* No allocation — callers that only need `value` or only `unit` can slice just
|
|
@@ -11,5 +10,4 @@ export declare function dimension_number_end(text: string): number;
|
|
|
11
10
|
export declare function parse_dimension(text: string): {
|
|
12
11
|
value: number;
|
|
13
12
|
unit: string;
|
|
14
|
-
};
|
|
15
|
-
//#endregion
|
|
13
|
+
};
|
package/dist/parse-dimension.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as is_digit } from "./string-utils-
|
|
2
|
-
|
|
1
|
+
import { i as is_digit } from "./string-utils-BYH1Oe8a.js";
|
|
2
|
+
// src/parse-dimension.ts
|
|
3
3
|
/**
|
|
4
4
|
* Find where a dimension's numeric part ends, e.g. 3 for "100px" or 2 for "2%".
|
|
5
5
|
* No allocation — callers that only need `value` or only `unit` can slice just
|
|
@@ -43,5 +43,4 @@ function parse_dimension(text) {
|
|
|
43
43
|
unit
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
//#endregion
|
|
47
46
|
export { dimension_number_end, parse_dimension };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-
|
|
1
|
+
import { t as Lexer } from "./tokenize-DC2Vb0J_.js";
|
|
2
2
|
import "./token-types.js";
|
|
3
|
-
import { l as CSSDataArena } from "./arena-
|
|
4
|
-
import { c as str_equals_range, n as is_combinator, o as is_whitespace } from "./string-utils-
|
|
5
|
-
import { t as CSSNode } from "./css-node-
|
|
3
|
+
import { l as CSSDataArena } from "./arena-CaLnNKbP.js";
|
|
4
|
+
import { c as str_equals_range, n as is_combinator, o as is_whitespace } from "./string-utils-BYH1Oe8a.js";
|
|
5
|
+
import { t as CSSNode } from "./css-node-CDTLvxo3.js";
|
|
6
6
|
import { ANplusBParser } from "./parse-anplusb.js";
|
|
7
|
-
|
|
7
|
+
// src/parse-utils.ts
|
|
8
8
|
function skip_whitespace_forward(source, pos, end) {
|
|
9
9
|
while (pos < end && is_whitespace(source.charCodeAt(pos))) pos++;
|
|
10
10
|
return pos;
|
|
@@ -69,8 +69,7 @@ function find_colon_at_depth_zero(source, start, end) {
|
|
|
69
69
|
}
|
|
70
70
|
return -1;
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
//#region src/parse-selector.ts
|
|
72
|
+
// src/parse-selector.ts
|
|
74
73
|
/** @internal */
|
|
75
74
|
var SelectorParser = class {
|
|
76
75
|
lexer;
|
|
@@ -514,5 +513,4 @@ function parse_selector_list(source) {
|
|
|
514
513
|
function parse_selector(source) {
|
|
515
514
|
return parse_selector_list(source).first_child;
|
|
516
515
|
}
|
|
517
|
-
//#endregion
|
|
518
516
|
export { skip_whitespace_and_comments_backward as a, find_colon_at_depth_zero as i, parse_selector as n, skip_whitespace_and_comments_forward as o, parse_selector_list as r, trim_boundaries as s, SelectorParser as t };
|
package/dist/parse-selector.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { l as CSSDataArena } from "./arena-
|
|
2
|
-
import { B as SelectorList, z as Selector } from "./node-types-
|
|
3
|
-
//#region src/parse-selector.d.ts
|
|
1
|
+
import { l as CSSDataArena } from "./arena-D689Bo6V.js";
|
|
2
|
+
import { B as SelectorList, z as Selector } from "./node-types-BF6bhAjo.js";
|
|
4
3
|
/** @internal */
|
|
5
4
|
export declare class SelectorParser {
|
|
6
5
|
private lexer;
|
|
@@ -33,5 +32,4 @@ export declare class SelectorParser {
|
|
|
33
32
|
private skip_whitespace;
|
|
34
33
|
}
|
|
35
34
|
export declare function parse_selector_list(source: string): SelectorList;
|
|
36
|
-
export declare function parse_selector(source: string): Selector;
|
|
37
|
-
//#endregion
|
|
35
|
+
export declare function parse_selector(source: string): Selector;
|
package/dist/parse-selector.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as SelectorParser, n as parse_selector, r as parse_selector_list } from "./parse-selector-
|
|
1
|
+
export { t as SelectorParser, n as parse_selector, r as parse_selector_list } from "./parse-selector-CMKZgPmu.js";
|
package/dist/parse-value.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { l as CSSDataArena } from "./arena-
|
|
2
|
-
import { Z as Value } from "./node-types-
|
|
3
|
-
//#region src/parse-value.d.ts
|
|
1
|
+
import { l as CSSDataArena } from "./arena-D689Bo6V.js";
|
|
2
|
+
import { Z as Value } from "./node-types-BF6bhAjo.js";
|
|
4
3
|
/** @internal */
|
|
5
4
|
export declare class ValueParser {
|
|
6
5
|
private nodes;
|
|
7
6
|
private arena;
|
|
8
|
-
constructor(arena: CSSDataArena, source: string);
|
|
7
|
+
constructor(arena: CSSDataArena, source: string, media_feature_range_name_as_child?: boolean);
|
|
9
8
|
parse_value(start: number, end: number, start_line: number, start_column: number): number;
|
|
10
9
|
}
|
|
11
10
|
/**
|
|
@@ -13,5 +12,4 @@ export declare class ValueParser {
|
|
|
13
12
|
* @param value_string - The CSS value to parse (e.g., "1px solid red")
|
|
14
13
|
* @returns A CSSNode VALUE wrapper containing the parsed value tokens as children
|
|
15
14
|
*/
|
|
16
|
-
export declare function parse_value(value_string: string): Value;
|
|
17
|
-
//#endregion
|
|
15
|
+
export declare function parse_value(value_string: string): Value;
|
package/dist/parse-value.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { l as CSSDataArena } from "./arena-
|
|
2
|
-
import { t as CSSNode } from "./css-node-
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { l as CSSDataArena } from "./arena-CaLnNKbP.js";
|
|
2
|
+
import { t as CSSNode } from "./css-node-CDTLvxo3.js";
|
|
3
|
+
import { r as ValueNodeParser } from "./parse-atrule-prelude-BMkgCZjw.js";
|
|
4
|
+
// src/parse-value.ts
|
|
5
5
|
/** @internal */
|
|
6
6
|
var ValueParser = class {
|
|
7
7
|
nodes;
|
|
8
8
|
arena;
|
|
9
|
-
constructor(arena, source) {
|
|
9
|
+
constructor(arena, source, media_feature_range_name_as_child = false) {
|
|
10
10
|
this.arena = arena;
|
|
11
|
-
this.nodes = new ValueNodeParser(arena, source);
|
|
11
|
+
this.nodes = new ValueNodeParser(arena, source, media_feature_range_name_as_child);
|
|
12
12
|
}
|
|
13
13
|
parse_value(start, end, start_line, start_column) {
|
|
14
14
|
const first_node = this.nodes.parse_chain(start, end, start_line, start_column);
|
|
@@ -31,5 +31,4 @@ function parse_value(value_string) {
|
|
|
31
31
|
const value_node_index = new ValueParser(arena, value_string).parse_value(0, value_string.length, 1, 1);
|
|
32
32
|
return new CSSNode(arena, value_string, value_node_index);
|
|
33
33
|
}
|
|
34
|
-
//#endregion
|
|
35
34
|
export { ValueParser, parse_value };
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { l as CSSDataArena } from "./arena-
|
|
1
|
+
import { l as CSSDataArena } from "./arena-D689Bo6V.js";
|
|
2
2
|
import { CommentInfo } from "./tokenize.js";
|
|
3
|
-
import { U as StyleSheet } from "./node-types-
|
|
4
|
-
//#region src/parse.d.ts
|
|
3
|
+
import { U as StyleSheet } from "./node-types-BF6bhAjo.js";
|
|
5
4
|
export interface ParserOptions {
|
|
6
5
|
parse_values?: boolean;
|
|
7
6
|
parse_selectors?: boolean;
|
|
8
7
|
parse_atrule_preludes?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Also add the feature name of a media range, e.g. `width` in `(400px < width)`, as an Identifier child.
|
|
10
|
+
* Defaults to `false`, but this will become the default in 0.20.0.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated Opt-in only as a migration aid: in 0.20.0 this behavior is always on and the option will be removed.
|
|
13
|
+
*/
|
|
14
|
+
media_feature_range_name_as_child?: boolean;
|
|
9
15
|
on_comment?: (info: CommentInfo) => void;
|
|
10
16
|
}
|
|
11
17
|
/** @internal */
|
|
@@ -40,5 +46,4 @@ export declare class Parser {
|
|
|
40
46
|
* @param options - Parser options
|
|
41
47
|
* @returns The root CSSNode of the AST
|
|
42
48
|
*/
|
|
43
|
-
export declare function parse(source: string, options?: ParserOptions): StyleSheet;
|
|
44
|
-
//#endregion
|
|
49
|
+
export declare function parse(source: string, options?: ParserOptions): StyleSheet;
|