@projectwallace/css-parser 0.18.8 → 0.18.11

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.
Files changed (40) hide show
  1. package/README.md +186 -18
  2. package/dist/{arena-e9O_g2AN.js → arena-Bsf96CQK.js} +27 -19
  3. package/dist/{arena-BGvFdbj5.d.ts → arena-DvT75bvK.d.ts} +2 -0
  4. package/dist/constants.d.ts +1 -1
  5. package/dist/constants.js +1 -1
  6. package/dist/{css-node-CH5HqF0J.js → css-node-yoUdFtNg.js} +101 -106
  7. package/dist/index.d.ts +6 -20
  8. package/dist/index.js +9 -146
  9. package/dist/{node-types-YnOKcNfU.d.ts → node-types-DG8OKqPu.d.ts} +8 -54
  10. package/dist/node-types.d.ts +2 -0
  11. package/dist/node-types.js +142 -0
  12. package/dist/parse-anplusb.d.ts +2 -2
  13. package/dist/parse-anplusb.js +5 -4
  14. package/dist/parse-atrule-prelude.d.ts +4 -3
  15. package/dist/parse-atrule-prelude.js +82 -77
  16. package/dist/parse-declaration.d.ts +4 -3
  17. package/dist/parse-declaration.js +28 -26
  18. package/dist/parse-dimension.js +46 -1
  19. package/dist/{parse-selector-PhqFezCi.js → parse-selector-CqIpnBrQ.js} +74 -89
  20. package/dist/parse-selector.d.ts +2 -2
  21. package/dist/parse-selector.js +1 -2
  22. package/dist/parse-value.d.ts +2 -2
  23. package/dist/parse-value.js +8 -8
  24. package/dist/parse.d.ts +3 -3
  25. package/dist/parse.js +49 -47
  26. package/dist/string-helpers-BMWJduts.d.ts +18 -0
  27. package/dist/string-helpers.d.ts +2 -0
  28. package/dist/string-helpers.js +1 -0
  29. package/dist/{parse-dimension-CQELWb5z.js → string-utils-DiRRd28d.js} +9 -59
  30. package/dist/token-types-Bqsf5FX-.d.ts +38 -0
  31. package/dist/token-types.d.ts +2 -0
  32. package/dist/token-types.js +30 -0
  33. package/dist/{tokenize-BYl6GvyV.js → tokenize-Ccg58Z_k.js} +79 -96
  34. package/dist/tokenize.d.ts +97 -2
  35. package/dist/tokenize.js +1 -2
  36. package/dist/{value-node-parser-tjY982sG.js → value-node-parser-D0qnA_bD.js} +153 -219
  37. package/dist/walk.d.ts +3 -2
  38. package/dist/walk.js +2 -2
  39. package/package.json +29 -18
  40. package/dist/tokenize-CDEnYcVG.d.ts +0 -133
@@ -1,12 +1,13 @@
1
- import { l as CSSDataArena } from "./arena-BGvFdbj5.js";
2
- import { n as Lexer } from "./tokenize-CDEnYcVG.js";
3
- import { d as Declaration } from "./node-types-YnOKcNfU.js";
1
+ import { l as CSSDataArena } from "./arena-DvT75bvK.js";
2
+ import { Lexer } from "./tokenize.js";
3
+ import { f as Declaration } from "./node-types-DG8OKqPu.js";
4
4
  //#region src/parse-declaration.d.ts
5
5
  /** @internal */
6
6
  export declare class DeclarationParser {
7
7
  private arena;
8
8
  private source;
9
9
  private value_parser;
10
+ private lookahead_position;
10
11
  constructor(arena: CSSDataArena, source: string, parse_values?: boolean);
11
12
  parse_declaration(start: number, end: number, line?: number, column?: number): number | null;
12
13
  parse_declaration_with_lexer(lexer: Lexer, end: number): number | null;
@@ -1,8 +1,9 @@
1
- import { t as Lexer } from "./tokenize-BYl6GvyV.js";
2
- import { l as CSSDataArena } from "./arena-e9O_g2AN.js";
3
- import { a as is_vendor_prefixed } from "./parse-dimension-CQELWb5z.js";
4
- import { t as CSSNode } from "./css-node-CH5HqF0J.js";
5
- import { a as skip_whitespace_and_comments_backward, s as trim_boundaries } from "./parse-selector-PhqFezCi.js";
1
+ import { t as Lexer } from "./tokenize-Ccg58Z_k.js";
2
+ import "./token-types.js";
3
+ import { l as CSSDataArena } from "./arena-Bsf96CQK.js";
4
+ import { a as is_vendor_prefixed } from "./string-utils-DiRRd28d.js";
5
+ import { t as CSSNode } from "./css-node-yoUdFtNg.js";
6
+ import { a as skip_whitespace_and_comments_backward, o as skip_whitespace_and_comments_forward } from "./parse-selector-CqIpnBrQ.js";
6
7
  import { ValueParser } from "./parse-value.js";
7
8
  //#region src/parse-declaration.ts
8
9
  /** @internal */
@@ -10,6 +11,7 @@ var DeclarationParser = class {
10
11
  arena;
11
12
  source;
12
13
  value_parser;
14
+ lookahead_position = new Lexer("").save_position();
13
15
  constructor(arena, source, parse_values = true) {
14
16
  this.arena = arena;
15
17
  this.source = source;
@@ -22,9 +24,8 @@ var DeclarationParser = class {
22
24
  return this.parse_declaration_with_lexer(lexer, end);
23
25
  }
24
26
  parse_declaration_with_lexer(lexer, end) {
25
- const initial_saved = lexer.save_position();
27
+ let initial_saved = null;
26
28
  let has_browser_hack = false;
27
- let has_delimiter_prefix = false;
28
29
  let browser_hack_start = 0;
29
30
  let browser_hack_line = 1;
30
31
  let browser_hack_column = 1;
@@ -56,34 +57,34 @@ var DeclarationParser = class {
56
57
  lexer.next_token_fast(true);
57
58
  if (lexer.token_type === 1) {
58
59
  has_browser_hack = true;
59
- has_delimiter_prefix = true;
60
+ initial_saved = delim_saved;
60
61
  } else lexer.restore_position(delim_saved);
61
62
  }
62
63
  if (lexer.token_type !== 1 && lexer.token_type !== 3 && lexer.token_type !== 4) return null;
63
- let prop_start = has_browser_hack ? browser_hack_start : lexer.token_start;
64
- let prop_end = lexer.token_end;
65
- let decl_line = has_browser_hack ? browser_hack_line : lexer.token_line;
66
- let decl_column = has_browser_hack ? browser_hack_column : lexer.token_column;
67
- const saved = lexer.save_position();
64
+ const prop_start = has_browser_hack ? browser_hack_start : lexer.token_start;
65
+ const prop_end = lexer.token_end;
66
+ const decl_line = has_browser_hack ? browser_hack_line : lexer.token_line;
67
+ const decl_column = has_browser_hack ? browser_hack_column : lexer.token_column;
68
+ const saved = lexer.save_position_into(this.lookahead_position);
68
69
  lexer.next_token_fast(true);
69
70
  if (lexer.token_type !== 16) {
70
- lexer.restore_position(has_delimiter_prefix ? initial_saved : saved);
71
+ lexer.restore_position(initial_saved ?? saved);
71
72
  return null;
72
73
  }
73
74
  lexer.pos = lexer.token_end;
74
75
  lexer.skip_whitespace_in_range(this.source.length);
75
- let declaration = this.arena.create_node(4, prop_start, 0, decl_line, decl_column);
76
+ const declaration = this.arena.create_node(4, prop_start, 0, decl_line, decl_column);
76
77
  this.arena.set_content_start_delta(declaration, 0);
77
78
  this.arena.set_content_length(declaration, prop_end - prop_start);
78
- let value_start = lexer.pos;
79
- let value_start_line = lexer.line;
80
- let value_start_column = lexer.column;
79
+ const value_start = lexer.pos;
80
+ const value_start_line = lexer.line;
81
+ const value_start_column = lexer.column;
81
82
  let value_end = value_start;
82
83
  let has_important = false;
83
84
  let last_end = value_start;
84
85
  let paren_depth = 0;
85
86
  while (true) {
86
- let stop_ch = lexer.skip_to_declaration_stop(end);
87
+ const stop_ch = lexer.skip_to_declaration_stop(end);
87
88
  if (stop_ch === 40) {
88
89
  paren_depth++;
89
90
  lexer.pos++;
@@ -135,22 +136,23 @@ var DeclarationParser = class {
135
136
  }
136
137
  lexer.pos++;
137
138
  }
138
- let trimmed = trim_boundaries(this.source, value_start, value_end);
139
- if (trimmed) {
140
- this.arena.set_value_start_delta(declaration, trimmed[0] - prop_start);
141
- this.arena.set_value_length(declaration, trimmed[1] - trimmed[0]);
139
+ const trimmed_start = skip_whitespace_and_comments_forward(this.source, value_start, value_end);
140
+ const trimmed_end = skip_whitespace_and_comments_backward(this.source, value_end, trimmed_start);
141
+ if (trimmed_start < trimmed_end) {
142
+ this.arena.set_value_start_delta(declaration, trimmed_start - prop_start);
143
+ this.arena.set_value_length(declaration, trimmed_end - trimmed_start);
142
144
  if (this.value_parser) {
143
- let valueNode = this.value_parser.parse_value(value_start, trimmed[1], value_start_line, value_start_column);
145
+ const valueNode = this.value_parser.parse_value(value_start, trimmed_end, value_start_line, value_start_column);
144
146
  this.arena.set_first_child(declaration, valueNode);
145
147
  } else {
146
- let rawNode = this.arena.create_node(8, trimmed[0], trimmed[1] - trimmed[0], value_start_line, value_start_column);
148
+ const rawNode = this.arena.create_node(8, trimmed_start, trimmed_end - trimmed_start, value_start_line, value_start_column);
147
149
  this.arena.set_first_child(declaration, rawNode);
148
150
  }
149
151
  } else {
150
152
  this.arena.set_value_start_delta(declaration, value_start - prop_start);
151
153
  this.arena.set_value_length(declaration, 0);
152
154
  if (this.value_parser) {
153
- let valueNode = this.value_parser.parse_value(value_start, value_start, value_start_line, value_start_column);
155
+ const valueNode = this.value_parser.parse_value(value_start, value_start, value_start_line, value_start_column);
154
156
  this.arena.set_first_child(declaration, valueNode);
155
157
  }
156
158
  }
@@ -1,2 +1,47 @@
1
- import { n as parse_dimension, t as dimension_number_end } from "./parse-dimension-CQELWb5z.js";
1
+ import { i as is_digit } from "./string-utils-DiRRd28d.js";
2
+ //#region src/parse-dimension.ts
3
+ /**
4
+ * Find where a dimension's numeric part ends, e.g. 3 for "100px" or 2 for "2%".
5
+ * No allocation — callers that only need `value` or only `unit` can slice just
6
+ * the part they want instead of going through `parse_dimension`'s object + two
7
+ * substrings for both.
8
+ * @internal
9
+ */
10
+ function dimension_number_end(text) {
11
+ let num_end = 0;
12
+ for (let i = 0; i < text.length; i++) {
13
+ const ch = text.charCodeAt(i);
14
+ if (ch === 101 || ch === 69) {
15
+ if (i + 1 < text.length) {
16
+ const next_ch = text.charCodeAt(i + 1);
17
+ if (is_digit(next_ch)) {
18
+ num_end = i + 1;
19
+ continue;
20
+ }
21
+ if ((next_ch === 43 || next_ch === 45) && i + 2 < text.length) {
22
+ const afterSign = text.charCodeAt(i + 2);
23
+ if (is_digit(afterSign)) {
24
+ num_end = i + 1;
25
+ continue;
26
+ }
27
+ }
28
+ }
29
+ break;
30
+ }
31
+ if (is_digit(ch) || ch === 46 || ch === 45 || ch === 43) num_end = i + 1;
32
+ else break;
33
+ }
34
+ return num_end;
35
+ }
36
+ /** Parse a dimension string into value and unit, e.g. "100px" → { value: 100, unit: "px" } or "2%" → { value: 2, unit: "%" } */
37
+ function parse_dimension(text) {
38
+ const num_end = dimension_number_end(text);
39
+ const num_str = text.substring(0, num_end);
40
+ const unit = text.substring(num_end);
41
+ return {
42
+ value: num_str ? Number.parseFloat(num_str) : 0,
43
+ unit
44
+ };
45
+ }
46
+ //#endregion
2
47
  export { dimension_number_end, parse_dimension };
@@ -1,18 +1,17 @@
1
- import { t as Lexer } from "./tokenize-BYl6GvyV.js";
2
- import { l as CSSDataArena } from "./arena-e9O_g2AN.js";
3
- import { c as str_equals_range, o as is_whitespace, r as is_combinator } from "./parse-dimension-CQELWb5z.js";
4
- import { t as CSSNode } from "./css-node-CH5HqF0J.js";
1
+ import { t as Lexer } from "./tokenize-Ccg58Z_k.js";
2
+ import "./token-types.js";
3
+ import { l as CSSDataArena } from "./arena-Bsf96CQK.js";
4
+ import { c as str_equals_range, n as is_combinator, o as is_whitespace } from "./string-utils-DiRRd28d.js";
5
+ import { t as CSSNode } from "./css-node-yoUdFtNg.js";
5
6
  import { ANplusBParser } from "./parse-anplusb.js";
6
7
  //#region src/parse-utils.ts
7
- /** @internal */
8
8
  function skip_whitespace_forward(source, pos, end) {
9
9
  while (pos < end && is_whitespace(source.charCodeAt(pos))) pos++;
10
10
  return pos;
11
11
  }
12
- /** @internal */
13
12
  function skip_whitespace_and_comments_forward(source, pos, end) {
14
13
  while (pos < end) {
15
- let ch = source.charCodeAt(pos);
14
+ const ch = source.charCodeAt(pos);
16
15
  if (is_whitespace(ch)) {
17
16
  pos++;
18
17
  continue;
@@ -32,10 +31,9 @@ function skip_whitespace_and_comments_forward(source, pos, end) {
32
31
  }
33
32
  return pos;
34
33
  }
35
- /** @internal */
36
34
  function skip_whitespace_and_comments_backward(source, pos, start) {
37
35
  while (pos > start) {
38
- let ch = source.charCodeAt(pos - 1);
36
+ const ch = source.charCodeAt(pos - 1);
39
37
  if (is_whitespace(ch)) {
40
38
  pos--;
41
39
  continue;
@@ -55,21 +53,16 @@ function skip_whitespace_and_comments_backward(source, pos, start) {
55
53
  }
56
54
  return pos;
57
55
  }
58
- /**
59
- * Trims whitespace and CSS comments from both ends; returns null if the range is only whitespace/comments.
60
- * @internal
61
- */
62
56
  function trim_boundaries(source, start, end) {
63
57
  start = skip_whitespace_and_comments_forward(source, start, end);
64
58
  end = skip_whitespace_and_comments_backward(source, end, start);
65
59
  if (start >= end) return null;
66
60
  return [start, end];
67
61
  }
68
- /** Find the position of the first ':' at parenthesis depth 0 in [start, end). Returns -1 if not found. @internal */
69
62
  function find_colon_at_depth_zero(source, start, end) {
70
63
  let depth = 0;
71
64
  for (let i = start; i < end; i++) {
72
- let ch = source.charCodeAt(i);
65
+ const ch = source.charCodeAt(i);
73
66
  if (ch === 40) depth++;
74
67
  else if (ch === 41) depth--;
75
68
  else if (ch === 58 && depth === 0) return i;
@@ -100,16 +93,16 @@ var SelectorParser = class {
100
93
  parse_selector_list(allow_relative = true) {
101
94
  let first_selector = 0;
102
95
  let last_selector = 0;
103
- let list_start = this.lexer.pos;
104
- let list_line = this.lexer.line;
105
- let list_column = this.lexer.column;
96
+ const list_start = this.lexer.pos;
97
+ const list_line = this.lexer.line;
98
+ const list_column = this.lexer.column;
106
99
  while (this.lexer.pos < this.selector_end) {
107
- let selector_start = this.lexer.pos;
108
- let selector_line = this.lexer.line;
109
- let selector_column = this.lexer.column;
110
- let complex_selector = this.parse_complex_selector(allow_relative);
100
+ const selector_start = this.lexer.pos;
101
+ const selector_line = this.lexer.line;
102
+ const selector_column = this.lexer.column;
103
+ const complex_selector = this.parse_complex_selector(allow_relative);
111
104
  if (complex_selector !== null) {
112
- let selector_wrapper = this.arena.create_node(5, selector_start, this.lexer.pos - selector_start, selector_line, selector_column);
105
+ const selector_wrapper = this.arena.create_node(5, selector_start, this.lexer.pos - selector_start, selector_line, selector_column);
113
106
  this.arena.set_content_start_delta(selector_wrapper, 0);
114
107
  this.arena.set_content_length(selector_wrapper, this.lexer.pos - selector_start);
115
108
  this.arena.set_first_child(selector_wrapper, complex_selector);
@@ -126,7 +119,7 @@ var SelectorParser = class {
126
119
  } else break;
127
120
  }
128
121
  if (first_selector !== 0) {
129
- let list_node = this.arena.create_node(20, list_start, this.lexer.pos - list_start, list_line, list_column);
122
+ const list_node = this.arena.create_node(20, list_start, this.lexer.pos - list_start, list_line, list_column);
130
123
  this.arena.set_first_child(list_node, first_selector);
131
124
  return list_node;
132
125
  }
@@ -140,9 +133,9 @@ var SelectorParser = class {
140
133
  const saved = this.lexer.save_position();
141
134
  this.lexer.next_token_fast(false);
142
135
  if (this.lexer.token_type === 9) {
143
- let ch = this.source.charCodeAt(this.lexer.token_start);
136
+ const ch = this.source.charCodeAt(this.lexer.token_start);
144
137
  if (ch === 62 || ch === 43 || ch === 126) {
145
- let combinator = this.create_node(27, this.lexer.token_start, this.lexer.token_end);
138
+ const combinator = this.create_node(27, this.lexer.token_start, this.lexer.token_end);
146
139
  first_component = combinator;
147
140
  chain_tail = combinator;
148
141
  this.skip_whitespace();
@@ -150,30 +143,18 @@ var SelectorParser = class {
150
143
  } else this.lexer.restore_position(saved);
151
144
  }
152
145
  while (this.lexer.pos < this.selector_end) {
153
- let compound = this.parse_compound_selector();
146
+ const compound = this.parse_compound_selector();
154
147
  if (compound === null) break;
155
148
  if (chain_tail === 0) first_component = compound;
156
149
  else this.arena.set_next_sibling(chain_tail, compound);
157
150
  chain_tail = this.arena.get_last_sibling(compound);
158
- let combinator = this.try_parse_combinator();
151
+ const combinator = this.try_parse_combinator();
159
152
  if (combinator !== null) {
160
153
  this.arena.set_next_sibling(chain_tail, combinator);
161
154
  chain_tail = combinator;
162
155
  this.skip_whitespace();
163
156
  continue;
164
157
  }
165
- const saved = this.lexer.save_position();
166
- this.skip_whitespace();
167
- if (this.lexer.pos >= this.selector_end) {
168
- this.lexer.restore_position(saved);
169
- break;
170
- }
171
- this.lexer.next_token_fast(false);
172
- if (this.lexer.token_type === 18 || this.lexer.pos >= this.selector_end) {
173
- this.lexer.restore_position(saved);
174
- break;
175
- }
176
- this.lexer.restore_position(saved);
177
158
  break;
178
159
  }
179
160
  return first_component === 0 ? null : first_component;
@@ -186,7 +167,7 @@ var SelectorParser = class {
186
167
  this.lexer.next_token_fast(false);
187
168
  if (this.lexer.token_start >= this.selector_end) break;
188
169
  if (this.lexer.token_type === 26) break;
189
- let part = this.parse_simple_selector();
170
+ const part = this.parse_simple_selector();
190
171
  if (part === null) {
191
172
  this.lexer.restore_position(saved);
192
173
  break;
@@ -198,14 +179,14 @@ var SelectorParser = class {
198
179
  return first_part === 0 ? null : first_part;
199
180
  }
200
181
  parse_simple_selector() {
201
- let token_type = this.lexer.token_type;
202
- let start = this.lexer.token_start;
203
- let end = this.lexer.token_end;
182
+ const token_type = this.lexer.token_type;
183
+ const start = this.lexer.token_start;
184
+ const end = this.lexer.token_end;
204
185
  switch (token_type) {
205
186
  case 1: return this.parse_type_or_namespace_selector(start, end);
206
187
  case 4: return this.create_node(23, start, end);
207
188
  case 9: {
208
- let ch = this.source.charCodeAt(start);
189
+ const ch = this.source.charCodeAt(start);
209
190
  if (ch === 46) return this.parse_class_selector(start);
210
191
  else if (ch === 42) return this.parse_universal_or_namespace_selector(start, end);
211
192
  else if (ch === 38) return this.create_node(29, start, end);
@@ -231,9 +212,9 @@ var SelectorParser = class {
231
212
  this.lexer.restore_position(saved);
232
213
  return null;
233
214
  }
234
- let local_start = this.lexer.token_start;
235
- let local_end = this.lexer.token_end;
236
- let node = this.create_node(node_type, selector_start, local_end);
215
+ const local_start = this.lexer.token_start;
216
+ const local_end = this.lexer.token_end;
217
+ const node = this.create_node(node_type, selector_start, local_end);
237
218
  this.arena.set_flag(node, 16);
238
219
  this.arena.set_content_start_delta(node, local_start - selector_start);
239
220
  this.arena.set_content_length(node, local_end - local_start);
@@ -247,7 +228,7 @@ var SelectorParser = class {
247
228
  this.skip_whitespace();
248
229
  if (this.lexer.pos < this.selector_end && this.source.charCodeAt(this.lexer.pos) === 124) {
249
230
  this.lexer.pos++;
250
- let node = this.parse_namespace_local_part(start, start, end - start);
231
+ const node = this.parse_namespace_local_part(start, start, end - start);
251
232
  if (node !== null) return node;
252
233
  }
253
234
  this.lexer.restore_position(saved);
@@ -258,7 +239,7 @@ var SelectorParser = class {
258
239
  this.skip_whitespace();
259
240
  if (this.lexer.pos < this.selector_end && this.source.charCodeAt(this.lexer.pos) === 124) {
260
241
  this.lexer.pos++;
261
- let node = this.parse_namespace_local_part(start, start, end - start);
242
+ const node = this.parse_namespace_local_part(start, start, end - start);
262
243
  if (node !== null) return node;
263
244
  }
264
245
  this.lexer.restore_position(saved);
@@ -277,8 +258,12 @@ var SelectorParser = class {
277
258
  return null;
278
259
  }
279
260
  this.lexer.next_token_fast(false);
261
+ if (this.lexer.token_type === 18) {
262
+ this.lexer.restore_position(saved_whitespace_start);
263
+ return null;
264
+ }
280
265
  if (this.lexer.token_type === 9) {
281
- let ch = this.source.charCodeAt(this.lexer.token_start);
266
+ const ch = this.source.charCodeAt(this.lexer.token_start);
282
267
  if (is_combinator(ch)) return this.create_node(27, this.lexer.token_start, this.lexer.token_end);
283
268
  }
284
269
  if (has_whitespace) {
@@ -301,11 +286,11 @@ var SelectorParser = class {
301
286
  parse_attribute_selector(start) {
302
287
  let bracket_depth = 1;
303
288
  let end = this.lexer.token_end;
304
- let content_start = start + 1;
289
+ const content_start = start + 1;
305
290
  let content_end = content_start;
306
291
  while (this.lexer.pos < this.selector_end && bracket_depth > 0) {
307
292
  this.lexer.next_token_fast(false);
308
- let token_type = this.lexer.token_type;
293
+ const token_type = this.lexer.token_type;
309
294
  if (token_type === 19) bracket_depth++;
310
295
  else if (token_type === 20) {
311
296
  bracket_depth--;
@@ -316,7 +301,7 @@ var SelectorParser = class {
316
301
  }
317
302
  }
318
303
  }
319
- let node = this.create_node(24, start, end);
304
+ const node = this.create_node(24, start, end);
320
305
  this.parse_attribute_content(node, content_start, content_end);
321
306
  return node;
322
307
  }
@@ -324,13 +309,13 @@ var SelectorParser = class {
324
309
  start = skip_whitespace_and_comments_forward(this.source, start, end);
325
310
  end = skip_whitespace_and_comments_backward(this.source, end, start);
326
311
  if (start >= end) return;
327
- let name_start = start;
312
+ const name_start = start;
328
313
  let name_end = start;
329
314
  let operator_end = -1;
330
315
  let value_start = -1;
331
316
  let value_end = -1;
332
317
  while (name_end < end) {
333
- let ch = this.source.charCodeAt(name_end);
318
+ const ch = this.source.charCodeAt(name_end);
334
319
  if (is_whitespace(ch) || ch === 61 || ch === 126 || ch === 124 || ch === 94 || ch === 36 || ch === 42) break;
335
320
  name_end++;
336
321
  }
@@ -340,8 +325,8 @@ var SelectorParser = class {
340
325
  }
341
326
  let pos = skip_whitespace_and_comments_forward(this.source, name_end, end);
342
327
  if (pos >= end) return;
343
- let ch1 = this.source.charCodeAt(pos);
344
- let ch2 = pos + 1 < end ? this.source.charCodeAt(pos + 1) : 0;
328
+ const ch1 = this.source.charCodeAt(pos);
329
+ const ch2 = pos + 1 < end ? this.source.charCodeAt(pos + 1) : 0;
345
330
  if (ch1 === 61) operator_end = pos + 1;
346
331
  else if (ch1 === 126 && ch2 === 61) operator_end = pos + 2;
347
332
  else if (ch1 === 124 && ch2 === 61) operator_end = pos + 2;
@@ -352,13 +337,13 @@ var SelectorParser = class {
352
337
  pos = skip_whitespace_and_comments_forward(this.source, operator_end, end);
353
338
  if (pos >= end) return;
354
339
  value_start = pos;
355
- let ch = this.source.charCodeAt(pos);
340
+ const ch = this.source.charCodeAt(pos);
356
341
  if (ch === 39 || ch === 34) {
357
- let quote = ch;
342
+ const quote = ch;
358
343
  value_start = pos;
359
344
  pos++;
360
345
  while (pos < end) {
361
- let c = this.source.charCodeAt(pos);
346
+ const c = this.source.charCodeAt(pos);
362
347
  if (c === quote) {
363
348
  pos++;
364
349
  break;
@@ -367,7 +352,7 @@ var SelectorParser = class {
367
352
  else pos++;
368
353
  }
369
354
  } else while (pos < end) {
370
- let c = this.source.charCodeAt(pos);
355
+ const c = this.source.charCodeAt(pos);
371
356
  if (is_whitespace(c)) break;
372
357
  pos++;
373
358
  }
@@ -387,9 +372,9 @@ var SelectorParser = class {
387
372
  this.lexer.pos++;
388
373
  } else this.lexer.restore_position(saved_ws);
389
374
  this.lexer.next_token_fast(false);
390
- let token_type = this.lexer.token_type;
375
+ const token_type = this.lexer.token_type;
391
376
  if (token_type === 1) {
392
- let node = this.create_node(is_pseudo_element ? 26 : 25, start, this.lexer.token_end);
377
+ const node = this.create_node(is_pseudo_element ? 26 : 25, start, this.lexer.token_end);
393
378
  this.arena.set_content_start_delta(node, this.lexer.token_start - start);
394
379
  this.arena.set_content_length(node, this.lexer.token_end - this.lexer.token_start);
395
380
  return node;
@@ -401,15 +386,15 @@ var SelectorParser = class {
401
386
  return null;
402
387
  }
403
388
  parse_pseudo_function_after_colon(start, is_pseudo_element) {
404
- let func_name_start = this.lexer.token_start;
405
- let func_name_end = this.lexer.token_end - 1;
406
- let content_start = this.lexer.pos;
389
+ const func_name_start = this.lexer.token_start;
390
+ const func_name_end = this.lexer.token_end - 1;
391
+ const content_start = this.lexer.pos;
407
392
  let content_end = content_start;
408
393
  let paren_depth = 1;
409
394
  let end = this.lexer.token_end;
410
395
  while (this.lexer.pos < this.selector_end && paren_depth > 0) {
411
396
  this.lexer.next_token_fast(false);
412
- let token_type = this.lexer.token_type;
397
+ const token_type = this.lexer.token_type;
413
398
  if (token_type === 21 || token_type === 2) paren_depth++;
414
399
  else if (token_type === 22) {
415
400
  paren_depth--;
@@ -420,20 +405,20 @@ var SelectorParser = class {
420
405
  }
421
406
  }
422
407
  }
423
- let node = this.create_node(is_pseudo_element ? 26 : 25, start, end);
408
+ const node = this.create_node(is_pseudo_element ? 26 : 25, start, end);
424
409
  this.arena.set_content_start_delta(node, func_name_start - start);
425
410
  this.arena.set_content_length(node, func_name_end - func_name_start);
426
411
  this.arena.set_flag(node, 64);
427
412
  if (content_end > content_start) {
428
413
  if (this.is_nth_pseudo(func_name_start, func_name_end)) {
429
- let child = this.parse_nth_expression(content_start, content_end);
414
+ const child = this.parse_nth_expression(content_start, content_end);
430
415
  if (child !== null) this.arena.set_first_child(node, child);
431
416
  } else if (str_equals_range(this.source, func_name_start, func_name_end, "lang")) this.parse_lang_identifiers(content_start, content_end, node);
432
417
  else {
433
- let saved_selector_end = this.selector_end;
418
+ const saved_selector_end = this.selector_end;
434
419
  const saved = this.lexer.save_position();
435
- let allow_relative = str_equals_range(this.source, func_name_start, func_name_end, "has");
436
- let child_selector = this.parse_selector(content_start, content_end, this.lexer.line, this.lexer.column, allow_relative);
420
+ const allow_relative = str_equals_range(this.source, func_name_start, func_name_end, "has");
421
+ const child_selector = this.parse_selector(content_start, content_end, this.lexer.line, this.lexer.column, allow_relative);
437
422
  this.selector_end = saved_selector_end;
438
423
  this.lexer.restore_position(saved);
439
424
  if (child_selector !== null) this.arena.set_first_child(node, child_selector);
@@ -447,19 +432,19 @@ var SelectorParser = class {
447
432
  parse_lang_identifiers(start, end, parent_node) {
448
433
  const saved_position = this.lexer.save_position();
449
434
  this.lexer.seek(start, this.lexer.line, this.lexer.column);
450
- let saved_selector_end = this.selector_end;
435
+ const saved_selector_end = this.selector_end;
451
436
  this.selector_end = end;
452
437
  let first_child = null;
453
438
  let last_child = null;
454
439
  while (this.lexer.pos < end) {
455
440
  this.lexer.next_token_fast(false);
456
- let token_type = this.lexer.token_type;
457
- let token_start = this.lexer.token_start;
458
- let token_end = this.lexer.token_end;
441
+ const token_type = this.lexer.token_type;
442
+ const token_start = this.lexer.token_start;
443
+ const token_end = this.lexer.token_end;
459
444
  if (token_type === 13) continue;
460
445
  if (token_type === 18) continue;
461
446
  if (token_type === 5 || token_type === 1) {
462
- let lang_node = this.create_node(56, token_start, token_end);
447
+ const lang_node = this.create_node(56, token_start, token_end);
463
448
  if (first_child === null) first_child = lang_node;
464
449
  if (last_child !== null) this.arena.set_next_sibling(last_child, lang_node);
465
450
  last_child = lang_node;
@@ -471,20 +456,20 @@ var SelectorParser = class {
471
456
  this.lexer.restore_position(saved_position);
472
457
  }
473
458
  parse_nth_expression(start, end) {
474
- let of_index = this.find_of_keyword(start, end);
475
- let anplusb_parser = this.anplusb_parser;
459
+ const of_index = this.find_of_keyword(start, end);
460
+ const anplusb_parser = this.anplusb_parser;
476
461
  if (of_index === -1) return anplusb_parser.parse_anplusb(start, end, this.lexer.line);
477
- let anplusb_node = anplusb_parser.parse_anplusb(start, of_index, this.lexer.line);
462
+ const anplusb_node = anplusb_parser.parse_anplusb(start, of_index, this.lexer.line);
478
463
  let selector_start = of_index + 2;
479
464
  selector_start = skip_whitespace_forward(this.source, selector_start, end);
480
- let saved_selector_end = this.selector_end;
465
+ const saved_selector_end = this.selector_end;
481
466
  const saved = this.lexer.save_position();
482
467
  this.selector_end = end;
483
468
  this.lexer.pos = selector_start;
484
- let selector_list = this.parse_selector_list();
469
+ const selector_list = this.parse_selector_list();
485
470
  this.selector_end = saved_selector_end;
486
471
  this.lexer.restore_position(saved);
487
- let of_node = this.arena.create_node(31, start, end - start, this.lexer.line, 1);
472
+ const of_node = this.arena.create_node(31, start, end - start, this.lexer.line, 1);
488
473
  if (anplusb_node !== null && selector_list !== null) {
489
474
  this.arena.set_first_child(of_node, anplusb_node);
490
475
  this.arena.set_next_sibling(anplusb_node, selector_list);
@@ -496,11 +481,11 @@ var SelectorParser = class {
496
481
  while (i < end - 1) {
497
482
  i = skip_whitespace_and_comments_forward(this.source, i, end);
498
483
  if (i >= end - 1) break;
499
- let ch1 = this.source.charCodeAt(i);
500
- let ch2 = this.source.charCodeAt(i + 1);
484
+ const ch1 = this.source.charCodeAt(i);
485
+ const ch2 = this.source.charCodeAt(i + 1);
501
486
  if ((ch1 === 111 || ch1 === 79) && (ch2 === 102 || ch2 === 70)) {
502
- let before_ok = i === start || is_whitespace(this.source.charCodeAt(i - 1));
503
- let after_ok = i + 2 >= end || is_whitespace(this.source.charCodeAt(i + 2));
487
+ const before_ok = i === start || is_whitespace(this.source.charCodeAt(i - 1));
488
+ const after_ok = i + 2 >= end || is_whitespace(this.source.charCodeAt(i + 2));
504
489
  if (before_ok && after_ok) return i;
505
490
  }
506
491
  i++;
@@ -508,7 +493,7 @@ var SelectorParser = class {
508
493
  return -1;
509
494
  }
510
495
  create_node(type, start, end, line = this.lexer.token_line, column = this.lexer.token_column) {
511
- let node = this.arena.create_node(type, start, end - start, line, column);
496
+ const node = this.arena.create_node(type, start, end - start, line, column);
512
497
  this.arena.set_content_start_delta(node, 0);
513
498
  this.arena.set_content_length(node, end - start);
514
499
  return node;
@@ -1,5 +1,5 @@
1
- import { l as CSSDataArena } from "./arena-BGvFdbj5.js";
2
- import { R as Selector, z as SelectorList } from "./node-types-YnOKcNfU.js";
1
+ import { l as CSSDataArena } from "./arena-DvT75bvK.js";
2
+ import { B as SelectorList, z as Selector } from "./node-types-DG8OKqPu.js";
3
3
  //#region src/parse-selector.d.ts
4
4
  /** @internal */
5
5
  export declare class SelectorParser {
@@ -1,2 +1 @@
1
- import { n as parse_selector, r as parse_selector_list, t as SelectorParser } from "./parse-selector-PhqFezCi.js";
2
- export { SelectorParser, parse_selector, parse_selector_list };
1
+ export { t as SelectorParser, n as parse_selector, r as parse_selector_list } from "./parse-selector-CqIpnBrQ.js";
@@ -1,5 +1,5 @@
1
- import { l as CSSDataArena } from "./arena-BGvFdbj5.js";
2
- import { X as Value } from "./node-types-YnOKcNfU.js";
1
+ import { l as CSSDataArena } from "./arena-DvT75bvK.js";
2
+ import { Z as Value } from "./node-types-DG8OKqPu.js";
3
3
  //#region src/parse-value.d.ts
4
4
  /** @internal */
5
5
  export declare class ValueParser {
@@ -1,6 +1,6 @@
1
- import { l as CSSDataArena } from "./arena-e9O_g2AN.js";
2
- import { t as CSSNode } from "./css-node-CH5HqF0J.js";
3
- import { t as ValueNodeParser } from "./value-node-parser-tjY982sG.js";
1
+ import { l as CSSDataArena } from "./arena-Bsf96CQK.js";
2
+ import { t as CSSNode } from "./css-node-yoUdFtNg.js";
3
+ import { t as ValueNodeParser } from "./value-node-parser-D0qnA_bD.js";
4
4
  //#region src/parse-value.ts
5
5
  /** @internal */
6
6
  var ValueParser = class {
@@ -11,12 +11,12 @@ var ValueParser = class {
11
11
  this.nodes = new ValueNodeParser(arena, source);
12
12
  }
13
13
  parse_value(start, end, start_line, start_column) {
14
- let first_node = this.nodes.parse_chain(start, end, start_line, start_column);
14
+ const first_node = this.nodes.parse_chain(start, end, start_line, start_column);
15
15
  if (first_node === 0) return this.arena.create_node(50, start, 0, start_line, start_column);
16
- let last_node = this.nodes.last_chain_node;
17
- let first_node_start = this.arena.get_start_offset(first_node);
18
- let last_node_end = this.arena.get_start_offset(last_node) + this.arena.get_length(last_node);
19
- let value_node = this.arena.create_node(50, first_node_start, last_node_end - first_node_start, start_line, start_column);
16
+ const last_node = this.nodes.last_chain_node;
17
+ const first_node_start = this.arena.get_start_offset(first_node);
18
+ const last_node_end = this.arena.get_start_offset(last_node) + this.arena.get_length(last_node);
19
+ const value_node = this.arena.create_node(50, first_node_start, last_node_end - first_node_start, start_line, start_column);
20
20
  this.arena.set_first_child(value_node, first_node);
21
21
  return value_node;
22
22
  }
package/dist/parse.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { l as CSSDataArena } from "./arena-BGvFdbj5.js";
2
- import { t as CommentInfo } from "./tokenize-CDEnYcVG.js";
3
- import { H as StyleSheet } from "./node-types-YnOKcNfU.js";
1
+ import { l as CSSDataArena } from "./arena-DvT75bvK.js";
2
+ import { CommentInfo } from "./tokenize.js";
3
+ import { U as StyleSheet } from "./node-types-DG8OKqPu.js";
4
4
  //#region src/parse.d.ts
5
5
  export interface ParserOptions {
6
6
  parse_values?: boolean;