@projectwallace/css-parser 0.18.9 → 0.18.12
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 +186 -18
- package/dist/{arena-e9O_g2AN.js → arena-Bsf96CQK.js} +27 -19
- package/dist/{arena-BGvFdbj5.d.ts → arena-DvT75bvK.d.ts} +2 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/{css-node-DfJEsKN0.js → css-node-yoUdFtNg.js} +101 -100
- package/dist/index.d.ts +6 -20
- package/dist/index.js +9 -146
- package/dist/{node-types-YnOKcNfU.d.ts → node-types-CY0JK9_a.d.ts} +9 -55
- package/dist/node-types.d.ts +2 -0
- package/dist/node-types.js +142 -0
- package/dist/parse-anplusb.d.ts +2 -2
- package/dist/parse-anplusb.js +5 -4
- package/dist/parse-atrule-prelude.d.ts +2 -2
- package/dist/parse-atrule-prelude.js +62 -61
- package/dist/parse-declaration.d.ts +3 -3
- package/dist/parse-declaration.js +20 -19
- package/dist/parse-dimension.js +47 -1
- package/dist/{parse-selector-rTXB4IN2.js → parse-selector-CqIpnBrQ.js} +74 -81
- package/dist/parse-selector.d.ts +2 -2
- package/dist/parse-selector.js +1 -1
- package/dist/parse-value.d.ts +2 -2
- package/dist/parse-value.js +8 -8
- package/dist/parse.d.ts +3 -3
- package/dist/parse.js +67 -46
- package/dist/string-helpers-BMWJduts.d.ts +18 -0
- package/dist/string-helpers.d.ts +2 -0
- package/dist/string-helpers.js +1 -0
- package/dist/{parse-dimension-CIaPOmBc.js → string-utils-DiRRd28d.js} +5 -49
- package/dist/token-types-Bqsf5FX-.d.ts +38 -0
- package/dist/token-types.d.ts +2 -0
- package/dist/token-types.js +30 -0
- package/dist/{tokenize-0ADWAELW.js → tokenize-Ccg58Z_k.js} +67 -96
- package/dist/tokenize.d.ts +97 -2
- package/dist/tokenize.js +1 -1
- package/dist/{value-node-parser-DizbcN1a.js → value-node-parser-BBwBxFR_.js} +133 -135
- package/dist/walk.d.ts +3 -2
- package/dist/walk.js +2 -2
- package/package.json +17 -4
- package/dist/tokenize-CaWtrHw_.d.ts +0 -134
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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 */
|
|
@@ -60,10 +61,10 @@ var DeclarationParser = class {
|
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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;
|
|
67
68
|
const saved = lexer.save_position_into(this.lookahead_position);
|
|
68
69
|
lexer.next_token_fast(true);
|
|
69
70
|
if (lexer.token_type !== 16) {
|
|
@@ -72,18 +73,18 @@ var DeclarationParser = class {
|
|
|
72
73
|
}
|
|
73
74
|
lexer.pos = lexer.token_end;
|
|
74
75
|
lexer.skip_whitespace_in_range(this.source.length);
|
|
75
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
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,23 +136,23 @@ var DeclarationParser = class {
|
|
|
135
136
|
}
|
|
136
137
|
lexer.pos++;
|
|
137
138
|
}
|
|
138
|
-
|
|
139
|
-
|
|
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);
|
|
140
141
|
if (trimmed_start < trimmed_end) {
|
|
141
142
|
this.arena.set_value_start_delta(declaration, trimmed_start - prop_start);
|
|
142
143
|
this.arena.set_value_length(declaration, trimmed_end - trimmed_start);
|
|
143
144
|
if (this.value_parser) {
|
|
144
|
-
|
|
145
|
+
const valueNode = this.value_parser.parse_value(value_start, trimmed_end, value_start_line, value_start_column);
|
|
145
146
|
this.arena.set_first_child(declaration, valueNode);
|
|
146
147
|
} else {
|
|
147
|
-
|
|
148
|
+
const rawNode = this.arena.create_node(8, trimmed_start, trimmed_end - trimmed_start, value_start_line, value_start_column);
|
|
148
149
|
this.arena.set_first_child(declaration, rawNode);
|
|
149
150
|
}
|
|
150
151
|
} else {
|
|
151
152
|
this.arena.set_value_start_delta(declaration, value_start - prop_start);
|
|
152
153
|
this.arena.set_value_length(declaration, 0);
|
|
153
154
|
if (this.value_parser) {
|
|
154
|
-
|
|
155
|
+
const valueNode = this.value_parser.parse_value(value_start, value_start, value_start_line, value_start_column);
|
|
155
156
|
this.arena.set_first_child(declaration, valueNode);
|
|
156
157
|
}
|
|
157
158
|
}
|
package/dist/parse-dimension.js
CHANGED
|
@@ -1 +1,47 @@
|
|
|
1
|
-
|
|
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
|
|
47
|
+
export { dimension_number_end, parse_dimension };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
8
|
function skip_whitespace_forward(source, pos, end) {
|
|
@@ -10,7 +11,7 @@ function skip_whitespace_forward(source, pos, end) {
|
|
|
10
11
|
}
|
|
11
12
|
function skip_whitespace_and_comments_forward(source, pos, end) {
|
|
12
13
|
while (pos < end) {
|
|
13
|
-
|
|
14
|
+
const ch = source.charCodeAt(pos);
|
|
14
15
|
if (is_whitespace(ch)) {
|
|
15
16
|
pos++;
|
|
16
17
|
continue;
|
|
@@ -32,7 +33,7 @@ function skip_whitespace_and_comments_forward(source, pos, end) {
|
|
|
32
33
|
}
|
|
33
34
|
function skip_whitespace_and_comments_backward(source, pos, start) {
|
|
34
35
|
while (pos > start) {
|
|
35
|
-
|
|
36
|
+
const ch = source.charCodeAt(pos - 1);
|
|
36
37
|
if (is_whitespace(ch)) {
|
|
37
38
|
pos--;
|
|
38
39
|
continue;
|
|
@@ -61,7 +62,7 @@ function trim_boundaries(source, start, end) {
|
|
|
61
62
|
function find_colon_at_depth_zero(source, start, end) {
|
|
62
63
|
let depth = 0;
|
|
63
64
|
for (let i = start; i < end; i++) {
|
|
64
|
-
|
|
65
|
+
const ch = source.charCodeAt(i);
|
|
65
66
|
if (ch === 40) depth++;
|
|
66
67
|
else if (ch === 41) depth--;
|
|
67
68
|
else if (ch === 58 && depth === 0) return i;
|
|
@@ -92,16 +93,16 @@ var SelectorParser = class {
|
|
|
92
93
|
parse_selector_list(allow_relative = true) {
|
|
93
94
|
let first_selector = 0;
|
|
94
95
|
let last_selector = 0;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
const list_start = this.lexer.pos;
|
|
97
|
+
const list_line = this.lexer.line;
|
|
98
|
+
const list_column = this.lexer.column;
|
|
98
99
|
while (this.lexer.pos < this.selector_end) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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);
|
|
103
104
|
if (complex_selector !== null) {
|
|
104
|
-
|
|
105
|
+
const selector_wrapper = this.arena.create_node(5, selector_start, this.lexer.pos - selector_start, selector_line, selector_column);
|
|
105
106
|
this.arena.set_content_start_delta(selector_wrapper, 0);
|
|
106
107
|
this.arena.set_content_length(selector_wrapper, this.lexer.pos - selector_start);
|
|
107
108
|
this.arena.set_first_child(selector_wrapper, complex_selector);
|
|
@@ -118,7 +119,7 @@ var SelectorParser = class {
|
|
|
118
119
|
} else break;
|
|
119
120
|
}
|
|
120
121
|
if (first_selector !== 0) {
|
|
121
|
-
|
|
122
|
+
const list_node = this.arena.create_node(20, list_start, this.lexer.pos - list_start, list_line, list_column);
|
|
122
123
|
this.arena.set_first_child(list_node, first_selector);
|
|
123
124
|
return list_node;
|
|
124
125
|
}
|
|
@@ -132,9 +133,9 @@ var SelectorParser = class {
|
|
|
132
133
|
const saved = this.lexer.save_position();
|
|
133
134
|
this.lexer.next_token_fast(false);
|
|
134
135
|
if (this.lexer.token_type === 9) {
|
|
135
|
-
|
|
136
|
+
const ch = this.source.charCodeAt(this.lexer.token_start);
|
|
136
137
|
if (ch === 62 || ch === 43 || ch === 126) {
|
|
137
|
-
|
|
138
|
+
const combinator = this.create_node(27, this.lexer.token_start, this.lexer.token_end);
|
|
138
139
|
first_component = combinator;
|
|
139
140
|
chain_tail = combinator;
|
|
140
141
|
this.skip_whitespace();
|
|
@@ -142,30 +143,18 @@ var SelectorParser = class {
|
|
|
142
143
|
} else this.lexer.restore_position(saved);
|
|
143
144
|
}
|
|
144
145
|
while (this.lexer.pos < this.selector_end) {
|
|
145
|
-
|
|
146
|
+
const compound = this.parse_compound_selector();
|
|
146
147
|
if (compound === null) break;
|
|
147
148
|
if (chain_tail === 0) first_component = compound;
|
|
148
149
|
else this.arena.set_next_sibling(chain_tail, compound);
|
|
149
150
|
chain_tail = this.arena.get_last_sibling(compound);
|
|
150
|
-
|
|
151
|
+
const combinator = this.try_parse_combinator();
|
|
151
152
|
if (combinator !== null) {
|
|
152
153
|
this.arena.set_next_sibling(chain_tail, combinator);
|
|
153
154
|
chain_tail = combinator;
|
|
154
155
|
this.skip_whitespace();
|
|
155
156
|
continue;
|
|
156
157
|
}
|
|
157
|
-
const saved = this.lexer.save_position();
|
|
158
|
-
this.skip_whitespace();
|
|
159
|
-
if (this.lexer.pos >= this.selector_end) {
|
|
160
|
-
this.lexer.restore_position(saved);
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
this.lexer.next_token_fast(false);
|
|
164
|
-
if (this.lexer.token_type === 18 || this.lexer.pos >= this.selector_end) {
|
|
165
|
-
this.lexer.restore_position(saved);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
this.lexer.restore_position(saved);
|
|
169
158
|
break;
|
|
170
159
|
}
|
|
171
160
|
return first_component === 0 ? null : first_component;
|
|
@@ -178,7 +167,7 @@ var SelectorParser = class {
|
|
|
178
167
|
this.lexer.next_token_fast(false);
|
|
179
168
|
if (this.lexer.token_start >= this.selector_end) break;
|
|
180
169
|
if (this.lexer.token_type === 26) break;
|
|
181
|
-
|
|
170
|
+
const part = this.parse_simple_selector();
|
|
182
171
|
if (part === null) {
|
|
183
172
|
this.lexer.restore_position(saved);
|
|
184
173
|
break;
|
|
@@ -190,14 +179,14 @@ var SelectorParser = class {
|
|
|
190
179
|
return first_part === 0 ? null : first_part;
|
|
191
180
|
}
|
|
192
181
|
parse_simple_selector() {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
182
|
+
const token_type = this.lexer.token_type;
|
|
183
|
+
const start = this.lexer.token_start;
|
|
184
|
+
const end = this.lexer.token_end;
|
|
196
185
|
switch (token_type) {
|
|
197
186
|
case 1: return this.parse_type_or_namespace_selector(start, end);
|
|
198
187
|
case 4: return this.create_node(23, start, end);
|
|
199
188
|
case 9: {
|
|
200
|
-
|
|
189
|
+
const ch = this.source.charCodeAt(start);
|
|
201
190
|
if (ch === 46) return this.parse_class_selector(start);
|
|
202
191
|
else if (ch === 42) return this.parse_universal_or_namespace_selector(start, end);
|
|
203
192
|
else if (ch === 38) return this.create_node(29, start, end);
|
|
@@ -223,9 +212,9 @@ var SelectorParser = class {
|
|
|
223
212
|
this.lexer.restore_position(saved);
|
|
224
213
|
return null;
|
|
225
214
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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);
|
|
229
218
|
this.arena.set_flag(node, 16);
|
|
230
219
|
this.arena.set_content_start_delta(node, local_start - selector_start);
|
|
231
220
|
this.arena.set_content_length(node, local_end - local_start);
|
|
@@ -239,7 +228,7 @@ var SelectorParser = class {
|
|
|
239
228
|
this.skip_whitespace();
|
|
240
229
|
if (this.lexer.pos < this.selector_end && this.source.charCodeAt(this.lexer.pos) === 124) {
|
|
241
230
|
this.lexer.pos++;
|
|
242
|
-
|
|
231
|
+
const node = this.parse_namespace_local_part(start, start, end - start);
|
|
243
232
|
if (node !== null) return node;
|
|
244
233
|
}
|
|
245
234
|
this.lexer.restore_position(saved);
|
|
@@ -250,7 +239,7 @@ var SelectorParser = class {
|
|
|
250
239
|
this.skip_whitespace();
|
|
251
240
|
if (this.lexer.pos < this.selector_end && this.source.charCodeAt(this.lexer.pos) === 124) {
|
|
252
241
|
this.lexer.pos++;
|
|
253
|
-
|
|
242
|
+
const node = this.parse_namespace_local_part(start, start, end - start);
|
|
254
243
|
if (node !== null) return node;
|
|
255
244
|
}
|
|
256
245
|
this.lexer.restore_position(saved);
|
|
@@ -269,8 +258,12 @@ var SelectorParser = class {
|
|
|
269
258
|
return null;
|
|
270
259
|
}
|
|
271
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
|
+
}
|
|
272
265
|
if (this.lexer.token_type === 9) {
|
|
273
|
-
|
|
266
|
+
const ch = this.source.charCodeAt(this.lexer.token_start);
|
|
274
267
|
if (is_combinator(ch)) return this.create_node(27, this.lexer.token_start, this.lexer.token_end);
|
|
275
268
|
}
|
|
276
269
|
if (has_whitespace) {
|
|
@@ -293,11 +286,11 @@ var SelectorParser = class {
|
|
|
293
286
|
parse_attribute_selector(start) {
|
|
294
287
|
let bracket_depth = 1;
|
|
295
288
|
let end = this.lexer.token_end;
|
|
296
|
-
|
|
289
|
+
const content_start = start + 1;
|
|
297
290
|
let content_end = content_start;
|
|
298
291
|
while (this.lexer.pos < this.selector_end && bracket_depth > 0) {
|
|
299
292
|
this.lexer.next_token_fast(false);
|
|
300
|
-
|
|
293
|
+
const token_type = this.lexer.token_type;
|
|
301
294
|
if (token_type === 19) bracket_depth++;
|
|
302
295
|
else if (token_type === 20) {
|
|
303
296
|
bracket_depth--;
|
|
@@ -308,7 +301,7 @@ var SelectorParser = class {
|
|
|
308
301
|
}
|
|
309
302
|
}
|
|
310
303
|
}
|
|
311
|
-
|
|
304
|
+
const node = this.create_node(24, start, end);
|
|
312
305
|
this.parse_attribute_content(node, content_start, content_end);
|
|
313
306
|
return node;
|
|
314
307
|
}
|
|
@@ -316,13 +309,13 @@ var SelectorParser = class {
|
|
|
316
309
|
start = skip_whitespace_and_comments_forward(this.source, start, end);
|
|
317
310
|
end = skip_whitespace_and_comments_backward(this.source, end, start);
|
|
318
311
|
if (start >= end) return;
|
|
319
|
-
|
|
312
|
+
const name_start = start;
|
|
320
313
|
let name_end = start;
|
|
321
314
|
let operator_end = -1;
|
|
322
315
|
let value_start = -1;
|
|
323
316
|
let value_end = -1;
|
|
324
317
|
while (name_end < end) {
|
|
325
|
-
|
|
318
|
+
const ch = this.source.charCodeAt(name_end);
|
|
326
319
|
if (is_whitespace(ch) || ch === 61 || ch === 126 || ch === 124 || ch === 94 || ch === 36 || ch === 42) break;
|
|
327
320
|
name_end++;
|
|
328
321
|
}
|
|
@@ -332,8 +325,8 @@ var SelectorParser = class {
|
|
|
332
325
|
}
|
|
333
326
|
let pos = skip_whitespace_and_comments_forward(this.source, name_end, end);
|
|
334
327
|
if (pos >= end) return;
|
|
335
|
-
|
|
336
|
-
|
|
328
|
+
const ch1 = this.source.charCodeAt(pos);
|
|
329
|
+
const ch2 = pos + 1 < end ? this.source.charCodeAt(pos + 1) : 0;
|
|
337
330
|
if (ch1 === 61) operator_end = pos + 1;
|
|
338
331
|
else if (ch1 === 126 && ch2 === 61) operator_end = pos + 2;
|
|
339
332
|
else if (ch1 === 124 && ch2 === 61) operator_end = pos + 2;
|
|
@@ -344,13 +337,13 @@ var SelectorParser = class {
|
|
|
344
337
|
pos = skip_whitespace_and_comments_forward(this.source, operator_end, end);
|
|
345
338
|
if (pos >= end) return;
|
|
346
339
|
value_start = pos;
|
|
347
|
-
|
|
340
|
+
const ch = this.source.charCodeAt(pos);
|
|
348
341
|
if (ch === 39 || ch === 34) {
|
|
349
|
-
|
|
342
|
+
const quote = ch;
|
|
350
343
|
value_start = pos;
|
|
351
344
|
pos++;
|
|
352
345
|
while (pos < end) {
|
|
353
|
-
|
|
346
|
+
const c = this.source.charCodeAt(pos);
|
|
354
347
|
if (c === quote) {
|
|
355
348
|
pos++;
|
|
356
349
|
break;
|
|
@@ -359,7 +352,7 @@ var SelectorParser = class {
|
|
|
359
352
|
else pos++;
|
|
360
353
|
}
|
|
361
354
|
} else while (pos < end) {
|
|
362
|
-
|
|
355
|
+
const c = this.source.charCodeAt(pos);
|
|
363
356
|
if (is_whitespace(c)) break;
|
|
364
357
|
pos++;
|
|
365
358
|
}
|
|
@@ -379,9 +372,9 @@ var SelectorParser = class {
|
|
|
379
372
|
this.lexer.pos++;
|
|
380
373
|
} else this.lexer.restore_position(saved_ws);
|
|
381
374
|
this.lexer.next_token_fast(false);
|
|
382
|
-
|
|
375
|
+
const token_type = this.lexer.token_type;
|
|
383
376
|
if (token_type === 1) {
|
|
384
|
-
|
|
377
|
+
const node = this.create_node(is_pseudo_element ? 26 : 25, start, this.lexer.token_end);
|
|
385
378
|
this.arena.set_content_start_delta(node, this.lexer.token_start - start);
|
|
386
379
|
this.arena.set_content_length(node, this.lexer.token_end - this.lexer.token_start);
|
|
387
380
|
return node;
|
|
@@ -393,15 +386,15 @@ var SelectorParser = class {
|
|
|
393
386
|
return null;
|
|
394
387
|
}
|
|
395
388
|
parse_pseudo_function_after_colon(start, is_pseudo_element) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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;
|
|
399
392
|
let content_end = content_start;
|
|
400
393
|
let paren_depth = 1;
|
|
401
394
|
let end = this.lexer.token_end;
|
|
402
395
|
while (this.lexer.pos < this.selector_end && paren_depth > 0) {
|
|
403
396
|
this.lexer.next_token_fast(false);
|
|
404
|
-
|
|
397
|
+
const token_type = this.lexer.token_type;
|
|
405
398
|
if (token_type === 21 || token_type === 2) paren_depth++;
|
|
406
399
|
else if (token_type === 22) {
|
|
407
400
|
paren_depth--;
|
|
@@ -412,20 +405,20 @@ var SelectorParser = class {
|
|
|
412
405
|
}
|
|
413
406
|
}
|
|
414
407
|
}
|
|
415
|
-
|
|
408
|
+
const node = this.create_node(is_pseudo_element ? 26 : 25, start, end);
|
|
416
409
|
this.arena.set_content_start_delta(node, func_name_start - start);
|
|
417
410
|
this.arena.set_content_length(node, func_name_end - func_name_start);
|
|
418
411
|
this.arena.set_flag(node, 64);
|
|
419
412
|
if (content_end > content_start) {
|
|
420
413
|
if (this.is_nth_pseudo(func_name_start, func_name_end)) {
|
|
421
|
-
|
|
414
|
+
const child = this.parse_nth_expression(content_start, content_end);
|
|
422
415
|
if (child !== null) this.arena.set_first_child(node, child);
|
|
423
416
|
} else if (str_equals_range(this.source, func_name_start, func_name_end, "lang")) this.parse_lang_identifiers(content_start, content_end, node);
|
|
424
417
|
else {
|
|
425
|
-
|
|
418
|
+
const saved_selector_end = this.selector_end;
|
|
426
419
|
const saved = this.lexer.save_position();
|
|
427
|
-
|
|
428
|
-
|
|
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);
|
|
429
422
|
this.selector_end = saved_selector_end;
|
|
430
423
|
this.lexer.restore_position(saved);
|
|
431
424
|
if (child_selector !== null) this.arena.set_first_child(node, child_selector);
|
|
@@ -439,19 +432,19 @@ var SelectorParser = class {
|
|
|
439
432
|
parse_lang_identifiers(start, end, parent_node) {
|
|
440
433
|
const saved_position = this.lexer.save_position();
|
|
441
434
|
this.lexer.seek(start, this.lexer.line, this.lexer.column);
|
|
442
|
-
|
|
435
|
+
const saved_selector_end = this.selector_end;
|
|
443
436
|
this.selector_end = end;
|
|
444
437
|
let first_child = null;
|
|
445
438
|
let last_child = null;
|
|
446
439
|
while (this.lexer.pos < end) {
|
|
447
440
|
this.lexer.next_token_fast(false);
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
441
|
+
const token_type = this.lexer.token_type;
|
|
442
|
+
const token_start = this.lexer.token_start;
|
|
443
|
+
const token_end = this.lexer.token_end;
|
|
451
444
|
if (token_type === 13) continue;
|
|
452
445
|
if (token_type === 18) continue;
|
|
453
446
|
if (token_type === 5 || token_type === 1) {
|
|
454
|
-
|
|
447
|
+
const lang_node = this.create_node(56, token_start, token_end);
|
|
455
448
|
if (first_child === null) first_child = lang_node;
|
|
456
449
|
if (last_child !== null) this.arena.set_next_sibling(last_child, lang_node);
|
|
457
450
|
last_child = lang_node;
|
|
@@ -463,20 +456,20 @@ var SelectorParser = class {
|
|
|
463
456
|
this.lexer.restore_position(saved_position);
|
|
464
457
|
}
|
|
465
458
|
parse_nth_expression(start, end) {
|
|
466
|
-
|
|
467
|
-
|
|
459
|
+
const of_index = this.find_of_keyword(start, end);
|
|
460
|
+
const anplusb_parser = this.anplusb_parser;
|
|
468
461
|
if (of_index === -1) return anplusb_parser.parse_anplusb(start, end, this.lexer.line);
|
|
469
|
-
|
|
462
|
+
const anplusb_node = anplusb_parser.parse_anplusb(start, of_index, this.lexer.line);
|
|
470
463
|
let selector_start = of_index + 2;
|
|
471
464
|
selector_start = skip_whitespace_forward(this.source, selector_start, end);
|
|
472
|
-
|
|
465
|
+
const saved_selector_end = this.selector_end;
|
|
473
466
|
const saved = this.lexer.save_position();
|
|
474
467
|
this.selector_end = end;
|
|
475
468
|
this.lexer.pos = selector_start;
|
|
476
|
-
|
|
469
|
+
const selector_list = this.parse_selector_list();
|
|
477
470
|
this.selector_end = saved_selector_end;
|
|
478
471
|
this.lexer.restore_position(saved);
|
|
479
|
-
|
|
472
|
+
const of_node = this.arena.create_node(31, start, end - start, this.lexer.line, 1);
|
|
480
473
|
if (anplusb_node !== null && selector_list !== null) {
|
|
481
474
|
this.arena.set_first_child(of_node, anplusb_node);
|
|
482
475
|
this.arena.set_next_sibling(anplusb_node, selector_list);
|
|
@@ -488,11 +481,11 @@ var SelectorParser = class {
|
|
|
488
481
|
while (i < end - 1) {
|
|
489
482
|
i = skip_whitespace_and_comments_forward(this.source, i, end);
|
|
490
483
|
if (i >= end - 1) break;
|
|
491
|
-
|
|
492
|
-
|
|
484
|
+
const ch1 = this.source.charCodeAt(i);
|
|
485
|
+
const ch2 = this.source.charCodeAt(i + 1);
|
|
493
486
|
if ((ch1 === 111 || ch1 === 79) && (ch2 === 102 || ch2 === 70)) {
|
|
494
|
-
|
|
495
|
-
|
|
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));
|
|
496
489
|
if (before_ok && after_ok) return i;
|
|
497
490
|
}
|
|
498
491
|
i++;
|
|
@@ -500,7 +493,7 @@ var SelectorParser = class {
|
|
|
500
493
|
return -1;
|
|
501
494
|
}
|
|
502
495
|
create_node(type, start, end, line = this.lexer.token_line, column = this.lexer.token_column) {
|
|
503
|
-
|
|
496
|
+
const node = this.arena.create_node(type, start, end - start, line, column);
|
|
504
497
|
this.arena.set_content_start_delta(node, 0);
|
|
505
498
|
this.arena.set_content_length(node, end - start);
|
|
506
499
|
return node;
|
package/dist/parse-selector.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as CSSDataArena } from "./arena-
|
|
2
|
-
import {
|
|
1
|
+
import { l as CSSDataArena } from "./arena-DvT75bvK.js";
|
|
2
|
+
import { B as SelectorList, z as Selector } from "./node-types-CY0JK9_a.js";
|
|
3
3
|
//#region src/parse-selector.d.ts
|
|
4
4
|
/** @internal */
|
|
5
5
|
export declare class SelectorParser {
|
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-CqIpnBrQ.js";
|
package/dist/parse-value.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as CSSDataArena } from "./arena-
|
|
2
|
-
import {
|
|
1
|
+
import { l as CSSDataArena } from "./arena-DvT75bvK.js";
|
|
2
|
+
import { Z as Value } from "./node-types-CY0JK9_a.js";
|
|
3
3
|
//#region src/parse-value.d.ts
|
|
4
4
|
/** @internal */
|
|
5
5
|
export declare class ValueParser {
|
package/dist/parse-value.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { l as CSSDataArena } from "./arena-
|
|
2
|
-
import { t as CSSNode } from "./css-node-
|
|
3
|
-
import { t as ValueNodeParser } from "./value-node-parser-
|
|
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-BBwBxFR_.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
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { l as CSSDataArena } from "./arena-DvT75bvK.js";
|
|
2
|
+
import { CommentInfo } from "./tokenize.js";
|
|
3
|
+
import { U as StyleSheet } from "./node-types-CY0JK9_a.js";
|
|
4
4
|
//#region src/parse.d.ts
|
|
5
5
|
export interface ParserOptions {
|
|
6
6
|
parse_values?: boolean;
|