@projectwallace/css-parser 0.18.2 → 0.18.5
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/{arena-CFwM4uQs.js → arena-DKhfTFT5.js} +3 -1
- package/dist/{arena-Bx5vp6Sl.d.ts → arena-DcrS77hW.d.ts} +3 -1
- package/dist/constants.d.ts +4 -2
- package/dist/constants.js +5 -3
- package/dist/{css-node-Cf8K9nWd.js → css-node-DKr6cufe.js} +38 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.js +10 -4
- package/dist/{node-types-D41wr72y.d.ts → node-types-u3Sbl3_p.d.ts} +43 -7
- package/dist/parse-anplusb.d.ts +2 -2
- package/dist/parse-anplusb.js +2 -2
- package/dist/parse-atrule-prelude.d.ts +3 -9
- package/dist/parse-atrule-prelude.js +20 -204
- package/dist/parse-declaration.d.ts +2 -2
- package/dist/parse-declaration.js +3 -3
- package/dist/parse-selector-DBdUc04T.js +534 -0
- package/dist/parse-selector.d.ts +2 -2
- package/dist/parse-selector.js +1 -460
- package/dist/parse-value.d.ts +2 -2
- package/dist/parse-value.js +3 -3
- package/dist/parse.d.ts +2 -2
- package/dist/parse.js +3 -4
- package/dist/value-node-parser-JFFFJVX-.js +661 -0
- package/dist/walk.d.ts +1 -1
- package/dist/walk.js +2 -2
- package/package.json +3 -2
- package/dist/parse-utils-D7srNG13.js +0 -65
- package/dist/value-node-parser-jRoWXgOr.js +0 -173
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { t as Lexer } from "./tokenize-DK24ACbY.js";
|
|
2
|
-
import { l as CSSDataArena } from "./arena-
|
|
2
|
+
import { l as CSSDataArena } from "./arena-DKhfTFT5.js";
|
|
3
3
|
import { l as strip_vendor_prefix, o as str_equals } from "./parse-dimension-ouWXNHdx.js";
|
|
4
|
-
import { t as CSSNode } from "./css-node-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { t as ValueNodeParser } from "./value-node-parser-jRoWXgOr.js";
|
|
4
|
+
import { t as CSSNode } from "./css-node-DKr6cufe.js";
|
|
5
|
+
import { s as trim_boundaries } from "./parse-selector-DBdUc04T.js";
|
|
6
|
+
import { n as ConditionParser, t as ValueNodeParser } from "./value-node-parser-JFFFJVX-.js";
|
|
8
7
|
//#region src/parse-atrule-prelude.ts
|
|
9
8
|
/** @internal */
|
|
10
9
|
var AtRulePreludeParser = class {
|
|
@@ -13,14 +12,14 @@ var AtRulePreludeParser = class {
|
|
|
13
12
|
source;
|
|
14
13
|
prelude_end;
|
|
15
14
|
value_node_parser;
|
|
16
|
-
|
|
15
|
+
condition_parser;
|
|
17
16
|
constructor(arena, source) {
|
|
18
17
|
this.arena = arena;
|
|
19
18
|
this.source = source;
|
|
20
19
|
this.lexer = new Lexer(source);
|
|
21
20
|
this.prelude_end = 0;
|
|
22
21
|
this.value_node_parser = new ValueNodeParser(arena, source);
|
|
23
|
-
this.
|
|
22
|
+
this.condition_parser = new ConditionParser(arena, source, this.value_node_parser);
|
|
24
23
|
}
|
|
25
24
|
parse_prelude(at_rule_name, start, end, line = 1, column = 1) {
|
|
26
25
|
this.prelude_end = end;
|
|
@@ -91,28 +90,6 @@ var AtRulePreludeParser = class {
|
|
|
91
90
|
depth === 0
|
|
92
91
|
];
|
|
93
92
|
}
|
|
94
|
-
parse_function_condition() {
|
|
95
|
-
let func_name = this.source.substring(this.lexer.token_start, this.lexer.token_end - 1);
|
|
96
|
-
let func_start = this.lexer.token_start;
|
|
97
|
-
let content_start = this.lexer.token_end;
|
|
98
|
-
let [content_end, func_end] = this.scan_matching_paren();
|
|
99
|
-
let func_node = this.create_node(15, func_start, func_end);
|
|
100
|
-
this.arena.set_content_start_delta(func_node, 0);
|
|
101
|
-
this.arena.set_content_length(func_node, func_name.length);
|
|
102
|
-
this.arena.set_value_start_delta(func_node, content_start - func_start);
|
|
103
|
-
this.arena.set_value_length(func_node, content_end - content_start);
|
|
104
|
-
if (str_equals("selector", func_name)) {
|
|
105
|
-
let selector_list = this.selector_parser.parse_selector(content_start, content_end, this.lexer.line, this.lexer.column);
|
|
106
|
-
if (selector_list !== null) this.arena.set_first_child(func_node, selector_list);
|
|
107
|
-
} else if (str_equals("style", func_name)) {
|
|
108
|
-
let colon_pos = this.find_colon_at_depth_zero(content_start, content_end);
|
|
109
|
-
if (colon_pos !== -1) {
|
|
110
|
-
let decl_child = this.create_supports_declaration(content_start, content_end, colon_pos);
|
|
111
|
-
this.arena.set_first_child(func_node, decl_child);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return func_node;
|
|
115
|
-
}
|
|
116
93
|
parse_single_media_query() {
|
|
117
94
|
let query_start = this.lexer.pos;
|
|
118
95
|
this.skip_whitespace();
|
|
@@ -136,8 +113,10 @@ var AtRulePreludeParser = class {
|
|
|
136
113
|
this.next_token();
|
|
137
114
|
let token_type = this.lexer.token_type;
|
|
138
115
|
let component = null;
|
|
139
|
-
if (token_type === 21)
|
|
140
|
-
|
|
116
|
+
if (token_type === 21) {
|
|
117
|
+
component = this.condition_parser.parse_media_feature(this.lexer.token_start, this.prelude_end, this.lexer.token_line, this.lexer.token_column);
|
|
118
|
+
if (component !== null) this.lexer.seek(...this.condition_parser.end_position);
|
|
119
|
+
} else if (token_type === 1) {
|
|
141
120
|
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
142
121
|
if (this.is_and_or_not(text)) component = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
143
122
|
else component = this.create_node(34, this.lexer.token_start, this.lexer.token_end);
|
|
@@ -153,56 +132,6 @@ var AtRulePreludeParser = class {
|
|
|
153
132
|
this.arena.set_first_child(query_node, first_component);
|
|
154
133
|
return query_node;
|
|
155
134
|
}
|
|
156
|
-
parse_media_feature() {
|
|
157
|
-
let feature_start = this.lexer.token_start;
|
|
158
|
-
let content_start = this.lexer.pos;
|
|
159
|
-
let [content_end, feature_end, matched] = this.scan_matching_paren();
|
|
160
|
-
if (!matched) return null;
|
|
161
|
-
let has_comparison = false;
|
|
162
|
-
let i = content_start;
|
|
163
|
-
while (i < content_end) {
|
|
164
|
-
i = skip_whitespace_and_comments_forward(this.source, i, content_end);
|
|
165
|
-
if (i >= content_end) break;
|
|
166
|
-
let ch = this.source.charCodeAt(i);
|
|
167
|
-
if (ch === 60 || ch === 62 || ch === 61) {
|
|
168
|
-
has_comparison = true;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
i++;
|
|
172
|
-
}
|
|
173
|
-
if (has_comparison) return this.parse_feature_range(feature_start, feature_end, content_start, content_end);
|
|
174
|
-
let feature = this.create_node(33, feature_start, feature_end);
|
|
175
|
-
let colon_pos = -1;
|
|
176
|
-
let j = content_start;
|
|
177
|
-
while (j < content_end) {
|
|
178
|
-
j = skip_whitespace_and_comments_forward(this.source, j, content_end);
|
|
179
|
-
if (j >= content_end) break;
|
|
180
|
-
if (this.source.charCodeAt(j) === 58) {
|
|
181
|
-
colon_pos = j;
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
j++;
|
|
185
|
-
}
|
|
186
|
-
if (colon_pos === -1) {
|
|
187
|
-
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
188
|
-
if (trimmed) {
|
|
189
|
-
this.arena.set_content_start_delta(feature, trimmed[0] - feature_start);
|
|
190
|
-
this.arena.set_content_length(feature, trimmed[1] - trimmed[0]);
|
|
191
|
-
}
|
|
192
|
-
} else {
|
|
193
|
-
let name_trimmed = trim_boundaries(this.source, content_start, colon_pos);
|
|
194
|
-
if (name_trimmed) {
|
|
195
|
-
this.arena.set_content_start_delta(feature, name_trimmed[0] - feature_start);
|
|
196
|
-
this.arena.set_content_length(feature, name_trimmed[1] - name_trimmed[0]);
|
|
197
|
-
}
|
|
198
|
-
let value_trimmed = trim_boundaries(this.source, colon_pos + 1, content_end);
|
|
199
|
-
if (value_trimmed) {
|
|
200
|
-
let value_first = this.parse_feature_value(value_trimmed[0], value_trimmed[1]);
|
|
201
|
-
if (value_first !== 0) this.arena.set_first_child(feature, value_first);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return feature;
|
|
205
|
-
}
|
|
206
135
|
parse_container_query() {
|
|
207
136
|
let query_start = this.lexer.pos;
|
|
208
137
|
let first_component = 0;
|
|
@@ -213,9 +142,13 @@ var AtRulePreludeParser = class {
|
|
|
213
142
|
this.next_token();
|
|
214
143
|
let token_type = this.lexer.token_type;
|
|
215
144
|
let component = null;
|
|
216
|
-
if (token_type === 21)
|
|
217
|
-
|
|
218
|
-
|
|
145
|
+
if (token_type === 21) {
|
|
146
|
+
component = this.condition_parser.parse_media_feature(this.lexer.token_start, this.prelude_end, this.lexer.token_line, this.lexer.token_column);
|
|
147
|
+
if (component !== null) this.lexer.seek(...this.condition_parser.end_position);
|
|
148
|
+
} else if (token_type === 2) {
|
|
149
|
+
component = this.condition_parser.parse_function_condition(this.lexer.token_start, this.prelude_end, this.lexer.token_line, this.lexer.token_column);
|
|
150
|
+
this.lexer.seek(...this.condition_parser.end_position);
|
|
151
|
+
} else if (token_type === 1) {
|
|
219
152
|
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
220
153
|
if (this.is_and_or_not(text)) component = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
221
154
|
else component = this.create_node(10, this.lexer.token_start, this.lexer.token_end);
|
|
@@ -232,74 +165,7 @@ var AtRulePreludeParser = class {
|
|
|
232
165
|
return [query_node];
|
|
233
166
|
}
|
|
234
167
|
parse_supports_query() {
|
|
235
|
-
|
|
236
|
-
while (this.lexer.pos < this.prelude_end) {
|
|
237
|
-
this.skip_whitespace();
|
|
238
|
-
if (this.lexer.pos >= this.prelude_end) break;
|
|
239
|
-
this.next_token();
|
|
240
|
-
let token_type = this.lexer.token_type;
|
|
241
|
-
if (token_type === 21) {
|
|
242
|
-
let feature_start = this.lexer.token_start;
|
|
243
|
-
let content_start = this.lexer.pos;
|
|
244
|
-
let [content_end, feature_end, matched] = this.scan_matching_paren();
|
|
245
|
-
if (matched) {
|
|
246
|
-
let query = this.create_node(36, feature_start, feature_end);
|
|
247
|
-
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
248
|
-
if (trimmed) {
|
|
249
|
-
this.arena.set_value_start_delta(query, trimmed[0] - feature_start);
|
|
250
|
-
this.arena.set_value_length(query, trimmed[1] - trimmed[0]);
|
|
251
|
-
let colon_pos = this.find_colon_at_depth_zero(trimmed[0], trimmed[1]);
|
|
252
|
-
if (colon_pos !== -1) {
|
|
253
|
-
let decl_child = this.create_supports_declaration(trimmed[0], trimmed[1], colon_pos);
|
|
254
|
-
this.arena.set_first_child(query, decl_child);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
nodes.push(query);
|
|
258
|
-
}
|
|
259
|
-
} else if (token_type === 1) {
|
|
260
|
-
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
261
|
-
if (this.is_and_or_not(text)) {
|
|
262
|
-
let op = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
263
|
-
nodes.push(op);
|
|
264
|
-
}
|
|
265
|
-
} else if (token_type === 2) nodes.push(this.parse_function_condition());
|
|
266
|
-
}
|
|
267
|
-
return nodes;
|
|
268
|
-
}
|
|
269
|
-
find_colon_at_depth_zero(start, end) {
|
|
270
|
-
let depth = 0;
|
|
271
|
-
for (let i = start; i < end; i++) {
|
|
272
|
-
let ch = this.source.charCodeAt(i);
|
|
273
|
-
if (ch === 40) depth++;
|
|
274
|
-
else if (ch === 41) depth--;
|
|
275
|
-
else if (ch === 58 && depth === 0) return i;
|
|
276
|
-
}
|
|
277
|
-
return -1;
|
|
278
|
-
}
|
|
279
|
-
create_supports_declaration(content_start, content_end, colon_pos) {
|
|
280
|
-
let prop_trimmed = trim_boundaries(this.source, content_start, colon_pos);
|
|
281
|
-
let val_trimmed = trim_boundaries(this.source, colon_pos + 1, content_end);
|
|
282
|
-
if (!prop_trimmed) return this.create_node(57, content_start, content_end);
|
|
283
|
-
let decl_start = prop_trimmed[0];
|
|
284
|
-
let decl_end = val_trimmed ? val_trimmed[1] : colon_pos + 1;
|
|
285
|
-
let decl = this.create_node(4, decl_start, decl_end);
|
|
286
|
-
this.arena.set_content_start_delta(decl, 0);
|
|
287
|
-
this.arena.set_content_length(decl, prop_trimmed[1] - prop_trimmed[0]);
|
|
288
|
-
if (val_trimmed) {
|
|
289
|
-
let value_first = this.parse_feature_value(val_trimmed[0], val_trimmed[1]);
|
|
290
|
-
let value_node;
|
|
291
|
-
if (value_first === 0) value_node = this.arena.create_node(50, val_trimmed[0], 0, this.lexer.token_line, this.lexer.token_column);
|
|
292
|
-
else {
|
|
293
|
-
value_node = this.arena.create_node(50, val_trimmed[0], val_trimmed[1] - val_trimmed[0], this.lexer.token_line, this.lexer.token_column);
|
|
294
|
-
this.arena.set_first_child(value_node, value_first);
|
|
295
|
-
}
|
|
296
|
-
this.arena.set_first_child(decl, value_node);
|
|
297
|
-
}
|
|
298
|
-
let supports_decl = this.create_node(57, content_start, content_end);
|
|
299
|
-
this.arena.set_content_start_delta(supports_decl, prop_trimmed[0] - content_start);
|
|
300
|
-
this.arena.set_content_length(supports_decl, prop_trimmed[1] - prop_trimmed[0]);
|
|
301
|
-
this.arena.set_first_child(supports_decl, decl);
|
|
302
|
-
return supports_decl;
|
|
168
|
+
return this.condition_parser.parse_supports_condition(this.lexer.pos, this.prelude_end, this.lexer.line, this.lexer.column);
|
|
303
169
|
}
|
|
304
170
|
parse_layer_names() {
|
|
305
171
|
let nodes = [];
|
|
@@ -435,11 +301,8 @@ var AtRulePreludeParser = class {
|
|
|
435
301
|
if (trimmed) {
|
|
436
302
|
this.arena.set_value_start_delta(supports_node, trimmed[0] - supports_start);
|
|
437
303
|
this.arena.set_value_length(supports_node, trimmed[1] - trimmed[0]);
|
|
438
|
-
let
|
|
439
|
-
if (
|
|
440
|
-
let decl_child = this.create_supports_declaration(trimmed[0], trimmed[1], colon_pos);
|
|
441
|
-
this.arena.set_first_child(supports_node, decl_child);
|
|
442
|
-
}
|
|
304
|
+
let decl_child = this.condition_parser.parse_supports_declaration_content(trimmed[0], trimmed[1]);
|
|
305
|
+
if (decl_child !== null) this.arena.set_first_child(supports_node, decl_child);
|
|
443
306
|
}
|
|
444
307
|
return supports_node;
|
|
445
308
|
}
|
|
@@ -464,9 +327,6 @@ var AtRulePreludeParser = class {
|
|
|
464
327
|
}
|
|
465
328
|
return this.lexer.next_token_fast(false);
|
|
466
329
|
}
|
|
467
|
-
parse_feature_value(start, end) {
|
|
468
|
-
return this.value_node_parser.parse_chain(start, end, this.lexer.line, this.lexer.column);
|
|
469
|
-
}
|
|
470
330
|
parse_namespace_prelude() {
|
|
471
331
|
let nodes = [];
|
|
472
332
|
this.skip_whitespace();
|
|
@@ -516,50 +376,6 @@ var AtRulePreludeParser = class {
|
|
|
516
376
|
nodes.push(this.create_node(10, this.lexer.token_start, this.lexer.token_end), ...this.parse_media_query_list());
|
|
517
377
|
return nodes;
|
|
518
378
|
}
|
|
519
|
-
parse_feature_range(feature_start, feature_end, content_start, content_end) {
|
|
520
|
-
let range_node = this.create_node(39, feature_start, feature_end);
|
|
521
|
-
let first_child = 0;
|
|
522
|
-
let last_child = 0;
|
|
523
|
-
let feature_name_start = -1;
|
|
524
|
-
let feature_name_end = -1;
|
|
525
|
-
let pos = content_start;
|
|
526
|
-
while (pos < content_end) {
|
|
527
|
-
pos = skip_whitespace_and_comments_forward(this.source, pos, content_end);
|
|
528
|
-
if (pos >= content_end) break;
|
|
529
|
-
let ch = this.source.charCodeAt(pos);
|
|
530
|
-
if (ch === 60 || ch === 62 || ch === 61) {
|
|
531
|
-
let op_start = pos++;
|
|
532
|
-
if (pos < content_end && this.source.charCodeAt(pos) === 61) pos++;
|
|
533
|
-
let op = this.create_node(38, op_start, pos);
|
|
534
|
-
if (first_child === 0) first_child = op;
|
|
535
|
-
else this.arena.set_next_sibling(last_child, op);
|
|
536
|
-
last_child = op;
|
|
537
|
-
} else {
|
|
538
|
-
let saved = this.lexer.save_position();
|
|
539
|
-
this.lexer.pos = pos;
|
|
540
|
-
this.next_token();
|
|
541
|
-
if (this.lexer.token_type === 1) {
|
|
542
|
-
feature_name_start = this.lexer.token_start;
|
|
543
|
-
feature_name_end = this.lexer.token_end;
|
|
544
|
-
} else {
|
|
545
|
-
let value_first = this.parse_feature_value(this.lexer.token_start, this.lexer.token_end);
|
|
546
|
-
if (value_first !== 0) {
|
|
547
|
-
if (first_child === 0) first_child = value_first;
|
|
548
|
-
else this.arena.set_next_sibling(last_child, value_first);
|
|
549
|
-
last_child = this.arena.get_last_sibling(value_first);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
pos = this.lexer.pos;
|
|
553
|
-
this.lexer.restore_position(saved);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
if (feature_name_start !== -1) {
|
|
557
|
-
this.arena.set_content_start_delta(range_node, feature_name_start - feature_start);
|
|
558
|
-
this.arena.set_content_length(range_node, feature_name_end - feature_name_start);
|
|
559
|
-
}
|
|
560
|
-
if (first_child !== 0) this.arena.set_first_child(range_node, first_child);
|
|
561
|
-
return range_node;
|
|
562
|
-
}
|
|
563
379
|
};
|
|
564
380
|
/**
|
|
565
381
|
* Parse an at-rule prelude string and return an array of AST nodes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { l as CSSDataArena } from "./arena-
|
|
1
|
+
import { l as CSSDataArena } from "./arena-DcrS77hW.js";
|
|
2
2
|
import { n as Lexer } from "./tokenize-CDEnYcVG.js";
|
|
3
|
-
import { d as Declaration } from "./node-types-
|
|
3
|
+
import { d as Declaration } from "./node-types-u3Sbl3_p.js";
|
|
4
4
|
//#region src/parse-declaration.d.ts
|
|
5
5
|
/** @internal */
|
|
6
6
|
declare class DeclarationParser {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as Lexer } from "./tokenize-DK24ACbY.js";
|
|
2
|
-
import { l as CSSDataArena } from "./arena-
|
|
2
|
+
import { l as CSSDataArena } from "./arena-DKhfTFT5.js";
|
|
3
3
|
import { i as is_vendor_prefixed } from "./parse-dimension-ouWXNHdx.js";
|
|
4
|
-
import { t as CSSNode } from "./css-node-
|
|
5
|
-
import {
|
|
4
|
+
import { t as CSSNode } from "./css-node-DKr6cufe.js";
|
|
5
|
+
import { a as skip_whitespace_and_comments_backward, s as trim_boundaries } from "./parse-selector-DBdUc04T.js";
|
|
6
6
|
import { ValueParser } from "./parse-value.js";
|
|
7
7
|
//#region src/parse-declaration.ts
|
|
8
8
|
/** @internal */
|