@projectwallace/css-parser 0.18.4 → 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.
@@ -1,10 +1,9 @@
1
1
  import { t as Lexer } from "./tokenize-DK24ACbY.js";
2
- import { l as CSSDataArena } from "./arena-C-ZXJe7F.js";
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-Briho45Z.js";
5
- import { i as trim_boundaries, n as skip_whitespace_and_comments_forward } from "./parse-utils-D7srNG13.js";
6
- import { SelectorParser } from "./parse-selector.js";
7
- import { t as ValueNodeParser } from "./value-node-parser-B0WfJCvC.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
- selector_parser;
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.selector_parser = new SelectorParser(arena, source);
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) component = this.parse_media_feature();
140
- else if (token_type === 1) {
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, this.wrap_ratio_value(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) component = this.parse_media_feature();
217
- else if (token_type === 2) component = this.parse_function_condition();
218
- else if (token_type === 1) {
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
- let nodes = [];
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 colon_pos = this.find_colon_at_depth_zero(trimmed[0], trimmed[1]);
439
- if (colon_pos !== -1) {
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,25 +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
- wrap_ratio_value(first_node) {
471
- if (this.arena.get_type(first_node) !== 11) return first_node;
472
- let op_node = this.arena.get_next_sibling(first_node);
473
- if (op_node === 0 || this.arena.get_type(op_node) !== 16) return first_node;
474
- if (this.arena.get_length(op_node) !== 1) return first_node;
475
- if (this.source.charCodeAt(this.arena.get_start_offset(op_node)) !== 47) return first_node;
476
- let second_node = this.arena.get_next_sibling(op_node);
477
- if (second_node === 0 || this.arena.get_type(second_node) !== 11) return first_node;
478
- if (this.arena.get_next_sibling(second_node) !== 0) return first_node;
479
- let start = this.arena.get_start_offset(first_node);
480
- let end = this.arena.get_start_offset(second_node) + this.arena.get_length(second_node);
481
- let ratio_node = this.arena.create_node(58, start, end - start, this.arena.get_start_line(first_node), this.arena.get_start_column(first_node));
482
- this.arena.set_first_child(ratio_node, first_node);
483
- this.arena.set_next_sibling(first_node, second_node);
484
- return ratio_node;
485
- }
486
330
  parse_namespace_prelude() {
487
331
  let nodes = [];
488
332
  this.skip_whitespace();
@@ -532,50 +376,6 @@ var AtRulePreludeParser = class {
532
376
  nodes.push(this.create_node(10, this.lexer.token_start, this.lexer.token_end), ...this.parse_media_query_list());
533
377
  return nodes;
534
378
  }
535
- parse_feature_range(feature_start, feature_end, content_start, content_end) {
536
- let range_node = this.create_node(39, feature_start, feature_end);
537
- let first_child = 0;
538
- let last_child = 0;
539
- let feature_name_start = -1;
540
- let feature_name_end = -1;
541
- let pos = content_start;
542
- while (pos < content_end) {
543
- pos = skip_whitespace_and_comments_forward(this.source, pos, content_end);
544
- if (pos >= content_end) break;
545
- let ch = this.source.charCodeAt(pos);
546
- if (ch === 60 || ch === 62 || ch === 61) {
547
- let op_start = pos++;
548
- if (pos < content_end && this.source.charCodeAt(pos) === 61) pos++;
549
- let op = this.create_node(38, op_start, pos);
550
- if (first_child === 0) first_child = op;
551
- else this.arena.set_next_sibling(last_child, op);
552
- last_child = op;
553
- } else {
554
- let saved = this.lexer.save_position();
555
- this.lexer.pos = pos;
556
- this.next_token();
557
- if (this.lexer.token_type === 1) {
558
- feature_name_start = this.lexer.token_start;
559
- feature_name_end = this.lexer.token_end;
560
- } else {
561
- let value_first = this.parse_feature_value(this.lexer.token_start, this.lexer.token_end);
562
- if (value_first !== 0) {
563
- if (first_child === 0) first_child = value_first;
564
- else this.arena.set_next_sibling(last_child, value_first);
565
- last_child = this.arena.get_last_sibling(value_first);
566
- }
567
- }
568
- pos = this.lexer.pos;
569
- this.lexer.restore_position(saved);
570
- }
571
- }
572
- if (feature_name_start !== -1) {
573
- this.arena.set_content_start_delta(range_node, feature_name_start - feature_start);
574
- this.arena.set_content_length(range_node, feature_name_end - feature_name_start);
575
- }
576
- if (first_child !== 0) this.arena.set_first_child(range_node, first_child);
577
- return range_node;
578
- }
579
379
  };
580
380
  /**
581
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-C-uRgG5-.js";
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-Dh1wEDRK.js";
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-C-ZXJe7F.js";
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-Briho45Z.js";
5
- import { i as trim_boundaries, t as skip_whitespace_and_comments_backward } from "./parse-utils-D7srNG13.js";
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 */