@projectwallace/css-parser 0.13.5 → 0.13.8
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/css-node-DqyvMXBN.d.ts +313 -0
- package/dist/css-node-Uj4oBgaw.js +647 -0
- package/dist/index.d.ts +150 -16
- package/dist/index.js +103 -13
- package/dist/parse-anplusb.d.ts +26 -2
- package/dist/parse-anplusb.js +191 -207
- package/dist/parse-atrule-prelude.d.ts +40 -2
- package/dist/parse-atrule-prelude.js +556 -652
- package/dist/parse-declaration.d.ts +16 -2
- package/dist/parse-declaration.js +140 -167
- package/dist/parse-dimension-CCn_XRDe.js +177 -0
- package/dist/parse-dimension.d.ts +6 -3
- package/dist/parse-dimension.js +1 -35
- package/dist/parse-selector.d.ts +37 -2
- package/dist/parse-selector.js +508 -635
- package/dist/parse-utils-DnsZRpfd.js +98 -0
- package/dist/parse-value.d.ts +23 -2
- package/dist/parse-value.js +176 -224
- package/dist/parse.d.ts +37 -8
- package/dist/parse.js +252 -353
- package/dist/tokenize-BQFB1jXg.js +540 -0
- package/dist/tokenize-odLrcjj2.d.ts +110 -0
- package/dist/tokenize.d.ts +2 -26
- package/dist/tokenize.js +1 -545
- package/package.json +20 -26
- package/dist/arena.d.ts +0 -60
- package/dist/arena.js +0 -291
- package/dist/char-types.d.ts +0 -14
- package/dist/char-types.js +0 -53
- package/dist/constants.d.ts +0 -44
- package/dist/constants.js +0 -51
- package/dist/css-node.d.ts +0 -203
- package/dist/css-node.js +0 -498
- package/dist/parse-utils.d.ts +0 -1
- package/dist/parse-utils.js +0 -60
- package/dist/string-utils.d.ts +0 -99
- package/dist/string-utils.js +0 -129
- package/dist/token-types.d.ts +0 -35
- package/dist/token-types.js +0 -29
- package/dist/walk.d.ts +0 -28
- package/dist/walk.js +0 -51
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { a as is_whitespace } from "./parse-dimension-CCn_XRDe.js";
|
|
2
|
+
//#region src/parse-utils.ts
|
|
3
|
+
/**
|
|
4
|
+
* Skip whitespace forward from a position
|
|
5
|
+
*
|
|
6
|
+
* @param source - The source string
|
|
7
|
+
* @param pos - Starting position
|
|
8
|
+
* @param end - End boundary (exclusive)
|
|
9
|
+
* @returns New position after skipping whitespace
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
function skip_whitespace_forward(source, pos, end) {
|
|
13
|
+
while (pos < end && is_whitespace(source.charCodeAt(pos))) pos++;
|
|
14
|
+
return pos;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Skip whitespace and comments forward from a position
|
|
18
|
+
*
|
|
19
|
+
* @param source - The source string
|
|
20
|
+
* @param pos - Starting position
|
|
21
|
+
* @param end - End boundary (exclusive)
|
|
22
|
+
* @returns New position after skipping whitespace/comments
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
function skip_whitespace_and_comments_forward(source, pos, end) {
|
|
26
|
+
while (pos < end) {
|
|
27
|
+
let ch = source.charCodeAt(pos);
|
|
28
|
+
if (is_whitespace(ch)) {
|
|
29
|
+
pos++;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (ch === 47 && pos + 1 < end && source.charCodeAt(pos + 1) === 42) {
|
|
33
|
+
pos += 2;
|
|
34
|
+
while (pos < end) {
|
|
35
|
+
if (source.charCodeAt(pos) === 42 && pos + 1 < end && source.charCodeAt(pos + 1) === 47) {
|
|
36
|
+
pos += 2;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
pos++;
|
|
40
|
+
}
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return pos;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Skip whitespace and comments backward from a position
|
|
49
|
+
*
|
|
50
|
+
* @param source - The source string
|
|
51
|
+
* @param pos - Starting position (exclusive, scanning backward from pos-1)
|
|
52
|
+
* @param start - Start boundary (inclusive, won't go before this)
|
|
53
|
+
* @returns New position after skipping whitespace/comments backward
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
function skip_whitespace_and_comments_backward(source, pos, start) {
|
|
57
|
+
while (pos > start) {
|
|
58
|
+
let ch = source.charCodeAt(pos - 1);
|
|
59
|
+
if (is_whitespace(ch)) {
|
|
60
|
+
pos--;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (pos >= 2 && ch === 47 && source.charCodeAt(pos - 2) === 42) {
|
|
64
|
+
pos -= 2;
|
|
65
|
+
while (pos > start) {
|
|
66
|
+
if (pos >= 2 && source.charCodeAt(pos - 2) === 47 && source.charCodeAt(pos - 1) === 42) {
|
|
67
|
+
pos -= 2;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
pos--;
|
|
71
|
+
}
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
return pos;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Trim whitespace and comments from both ends of a string range
|
|
80
|
+
*
|
|
81
|
+
* @param source - The source string
|
|
82
|
+
* @param start - Start offset in source
|
|
83
|
+
* @param end - End offset in source
|
|
84
|
+
* @returns [trimmed_start, trimmed_end] or null if all whitespace/comments
|
|
85
|
+
* @internal
|
|
86
|
+
*
|
|
87
|
+
* Skips whitespace (space, tab, newline, CR, FF) and CSS comments from both ends
|
|
88
|
+
* of the specified range. Returns the trimmed boundaries or null if the range
|
|
89
|
+
* contains only whitespace and comments.
|
|
90
|
+
*/
|
|
91
|
+
function trim_boundaries(source, start, end) {
|
|
92
|
+
start = skip_whitespace_and_comments_forward(source, start, end);
|
|
93
|
+
end = skip_whitespace_and_comments_backward(source, end, start);
|
|
94
|
+
if (start >= end) return null;
|
|
95
|
+
return [start, end];
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { trim_boundaries as i, skip_whitespace_and_comments_forward as n, skip_whitespace_forward as r, skip_whitespace_and_comments_backward as t };
|
package/dist/parse-value.d.ts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
import { CSSNode } from
|
|
1
|
+
import { E as CSSDataArena, r as CSSNode } from "./css-node-DqyvMXBN.js";
|
|
2
|
+
|
|
3
|
+
//#region src/parse-value.d.ts
|
|
4
|
+
/** @internal */
|
|
5
|
+
declare class ValueParser {
|
|
6
|
+
private lexer;
|
|
7
|
+
private arena;
|
|
8
|
+
private source;
|
|
9
|
+
private value_end;
|
|
10
|
+
constructor(arena: CSSDataArena, source: string);
|
|
11
|
+
parse_value(start: number, end: number, start_line: number, start_column: number): number;
|
|
12
|
+
private parse_value_tokens;
|
|
13
|
+
private is_whitespace_inline;
|
|
14
|
+
private parse_value_node;
|
|
15
|
+
private create_node;
|
|
16
|
+
private create_operator_node;
|
|
17
|
+
private parse_operator_node;
|
|
18
|
+
private parse_function_node;
|
|
19
|
+
private parse_parenthesis_node;
|
|
20
|
+
}
|
|
2
21
|
/**
|
|
3
22
|
* Parse a CSS declaration value string and return a VALUE node
|
|
4
23
|
* @param value_string - The CSS value to parse (e.g., "1px solid red")
|
|
5
24
|
* @returns A CSSNode VALUE wrapper containing the parsed value tokens as children
|
|
6
25
|
*/
|
|
7
|
-
|
|
26
|
+
declare function parse_value(value_string: string): CSSNode;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { ValueParser, parse_value };
|
package/dist/parse-value.js
CHANGED
|
@@ -1,227 +1,179 @@
|
|
|
1
|
-
import { Lexer } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
let arg_node = this.parse_value_node();
|
|
175
|
-
if (arg_node !== null) {
|
|
176
|
-
args.push(arg_node);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
this.arena.set_length(node, func_end - start);
|
|
180
|
-
this.arena.set_value_start_delta(node, content_start - start);
|
|
181
|
-
this.arena.set_value_length(node, content_end - content_start);
|
|
182
|
-
this.arena.append_children(node, args);
|
|
183
|
-
return node;
|
|
184
|
-
}
|
|
185
|
-
parse_parenthesis_node(start, end) {
|
|
186
|
-
let node = this.arena.create_node(
|
|
187
|
-
PARENTHESIS,
|
|
188
|
-
start,
|
|
189
|
-
0,
|
|
190
|
-
// length unknown yet
|
|
191
|
-
this.lexer.token_line,
|
|
192
|
-
this.lexer.token_column
|
|
193
|
-
);
|
|
194
|
-
let children = [];
|
|
195
|
-
let paren_depth = 1;
|
|
196
|
-
let paren_end = end;
|
|
197
|
-
while (this.lexer.pos < this.value_end && paren_depth > 0) {
|
|
198
|
-
this.lexer.next_token_fast(false);
|
|
199
|
-
let token_type = this.lexer.token_type;
|
|
200
|
-
if (token_type === TOKEN_EOF) break;
|
|
201
|
-
if (this.lexer.token_start >= this.value_end) break;
|
|
202
|
-
if (token_type === TOKEN_RIGHT_PAREN) {
|
|
203
|
-
paren_depth--;
|
|
204
|
-
if (paren_depth === 0) {
|
|
205
|
-
paren_end = this.lexer.token_end;
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (this.is_whitespace_inline()) continue;
|
|
210
|
-
let child_node = this.parse_value_node();
|
|
211
|
-
if (child_node !== null) {
|
|
212
|
-
children.push(child_node);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
this.arena.set_length(node, paren_end - start);
|
|
216
|
-
this.arena.append_children(node, children);
|
|
217
|
-
return node;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
1
|
+
import { t as Lexer } from "./tokenize-BQFB1jXg.js";
|
|
2
|
+
import { C as CSSDataArena, r as CSSNode } from "./css-node-Uj4oBgaw.js";
|
|
3
|
+
import { a as is_whitespace, o as str_equals } from "./parse-dimension-CCn_XRDe.js";
|
|
4
|
+
//#region src/parse-value.ts
|
|
5
|
+
/** @internal */
|
|
6
|
+
var ValueParser = class {
|
|
7
|
+
lexer;
|
|
8
|
+
arena;
|
|
9
|
+
source;
|
|
10
|
+
value_end;
|
|
11
|
+
constructor(arena, source) {
|
|
12
|
+
this.arena = arena;
|
|
13
|
+
this.source = source;
|
|
14
|
+
this.lexer = new Lexer(source);
|
|
15
|
+
this.value_end = 0;
|
|
16
|
+
}
|
|
17
|
+
parse_value(start, end, start_line, start_column) {
|
|
18
|
+
this.value_end = end;
|
|
19
|
+
this.lexer.seek(start, start_line, start_column);
|
|
20
|
+
let value_nodes = this.parse_value_tokens();
|
|
21
|
+
if (value_nodes.length === 0) return this.arena.create_node(50, start, 0, start_line, start_column);
|
|
22
|
+
let first_node_start = this.arena.get_start_offset(value_nodes[0]);
|
|
23
|
+
let last_node_index = value_nodes[value_nodes.length - 1];
|
|
24
|
+
let last_node_end = this.arena.get_start_offset(last_node_index) + this.arena.get_length(last_node_index);
|
|
25
|
+
let value_node = this.arena.create_node(50, first_node_start, last_node_end - first_node_start, start_line, start_column);
|
|
26
|
+
this.arena.append_children(value_node, value_nodes);
|
|
27
|
+
return value_node;
|
|
28
|
+
}
|
|
29
|
+
parse_value_tokens() {
|
|
30
|
+
let nodes = [];
|
|
31
|
+
while (this.lexer.pos < this.value_end) {
|
|
32
|
+
this.lexer.next_token_fast(false);
|
|
33
|
+
if (this.lexer.token_start >= this.value_end) break;
|
|
34
|
+
if (this.lexer.token_type === 26) break;
|
|
35
|
+
if (this.is_whitespace_inline()) continue;
|
|
36
|
+
let node = this.parse_value_node();
|
|
37
|
+
if (node !== null) nodes.push(node);
|
|
38
|
+
}
|
|
39
|
+
return nodes;
|
|
40
|
+
}
|
|
41
|
+
is_whitespace_inline() {
|
|
42
|
+
if (this.lexer.token_start >= this.lexer.token_end) return false;
|
|
43
|
+
for (let i = this.lexer.token_start; i < this.lexer.token_end; i++) if (!is_whitespace(this.source.charCodeAt(i))) return false;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
parse_value_node() {
|
|
47
|
+
let token_type = this.lexer.token_type;
|
|
48
|
+
let start = this.lexer.token_start;
|
|
49
|
+
let end = this.lexer.token_end;
|
|
50
|
+
switch (token_type) {
|
|
51
|
+
case 1: return this.create_node(10, start, end);
|
|
52
|
+
case 10: return this.create_node(11, start, end);
|
|
53
|
+
case 11:
|
|
54
|
+
case 12: return this.create_node(12, start, end);
|
|
55
|
+
case 5: return this.create_node(13, start, end);
|
|
56
|
+
case 4: return this.create_node(14, start, end);
|
|
57
|
+
case 27: return this.create_node(19, start, end);
|
|
58
|
+
case 2: return this.parse_function_node(start, end);
|
|
59
|
+
case 9: return this.parse_operator_node(start, end);
|
|
60
|
+
case 18: return this.create_node(16, start, end);
|
|
61
|
+
case 21: return this.parse_parenthesis_node(start, end);
|
|
62
|
+
default: return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
create_node(node_type, start, end) {
|
|
66
|
+
let node = this.arena.create_node(node_type, start, end - start, this.lexer.token_line, this.lexer.token_column);
|
|
67
|
+
this.arena.set_content_length(node, end - start);
|
|
68
|
+
return node;
|
|
69
|
+
}
|
|
70
|
+
create_operator_node(start, end) {
|
|
71
|
+
return this.create_node(16, start, end);
|
|
72
|
+
}
|
|
73
|
+
parse_operator_node(start, end) {
|
|
74
|
+
let ch = this.source.charCodeAt(start);
|
|
75
|
+
if (ch === 43 || ch === 45 || ch === 42 || ch === 47) return this.create_operator_node(start, end);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
parse_function_node(start, end) {
|
|
79
|
+
let name_end = end - 1;
|
|
80
|
+
let func_name_substr = this.source.substring(start, name_end);
|
|
81
|
+
let node = this.arena.create_node(str_equals("url", func_name_substr) ? 18 : 15, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
82
|
+
this.arena.set_content_start_delta(node, 0);
|
|
83
|
+
this.arena.set_content_length(node, name_end - start);
|
|
84
|
+
if (str_equals("url", func_name_substr) || str_equals("src", func_name_substr)) {
|
|
85
|
+
let save_pos = this.lexer.save_position();
|
|
86
|
+
this.lexer.next_token_fast(false);
|
|
87
|
+
while (this.is_whitespace_inline() && this.lexer.pos < this.value_end) this.lexer.next_token_fast(false);
|
|
88
|
+
let first_token_type = this.lexer.token_type;
|
|
89
|
+
this.lexer.restore_position(save_pos);
|
|
90
|
+
if (first_token_type === 5) {} else {
|
|
91
|
+
let paren_depth = 1;
|
|
92
|
+
let func_end = end;
|
|
93
|
+
let content_start = end;
|
|
94
|
+
let content_end = end;
|
|
95
|
+
while (paren_depth > 0) {
|
|
96
|
+
this.lexer.next_token_fast(false);
|
|
97
|
+
let token_type = this.lexer.token_type;
|
|
98
|
+
if (token_type === 26) break;
|
|
99
|
+
if (token_type === 21 || token_type === 2) paren_depth++;
|
|
100
|
+
else if (token_type === 22) {
|
|
101
|
+
paren_depth--;
|
|
102
|
+
if (paren_depth === 0) {
|
|
103
|
+
content_end = this.lexer.token_start;
|
|
104
|
+
func_end = this.lexer.token_end;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
this.arena.set_length(node, func_end - start);
|
|
110
|
+
this.arena.set_value_start_delta(node, content_start - start);
|
|
111
|
+
this.arena.set_value_length(node, content_end - content_start);
|
|
112
|
+
return node;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
let args = [];
|
|
116
|
+
let paren_depth = 1;
|
|
117
|
+
let func_end = end;
|
|
118
|
+
let content_start = end;
|
|
119
|
+
let content_end = end;
|
|
120
|
+
while (this.lexer.pos < this.value_end && paren_depth > 0) {
|
|
121
|
+
this.lexer.next_token_fast(false);
|
|
122
|
+
let token_type = this.lexer.token_type;
|
|
123
|
+
if (token_type === 26) break;
|
|
124
|
+
if (this.lexer.token_start >= this.value_end) break;
|
|
125
|
+
if (token_type === 22) {
|
|
126
|
+
paren_depth--;
|
|
127
|
+
if (paren_depth === 0) {
|
|
128
|
+
content_end = this.lexer.token_start;
|
|
129
|
+
func_end = this.lexer.token_end;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (this.is_whitespace_inline()) continue;
|
|
134
|
+
let arg_node = this.parse_value_node();
|
|
135
|
+
if (arg_node !== null) args.push(arg_node);
|
|
136
|
+
}
|
|
137
|
+
this.arena.set_length(node, func_end - start);
|
|
138
|
+
this.arena.set_value_start_delta(node, content_start - start);
|
|
139
|
+
this.arena.set_value_length(node, content_end - content_start);
|
|
140
|
+
this.arena.append_children(node, args);
|
|
141
|
+
return node;
|
|
142
|
+
}
|
|
143
|
+
parse_parenthesis_node(start, end) {
|
|
144
|
+
let node = this.arena.create_node(17, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
145
|
+
let children = [];
|
|
146
|
+
let paren_depth = 1;
|
|
147
|
+
let paren_end = end;
|
|
148
|
+
while (this.lexer.pos < this.value_end && paren_depth > 0) {
|
|
149
|
+
this.lexer.next_token_fast(false);
|
|
150
|
+
let token_type = this.lexer.token_type;
|
|
151
|
+
if (token_type === 26) break;
|
|
152
|
+
if (this.lexer.token_start >= this.value_end) break;
|
|
153
|
+
if (token_type === 22) {
|
|
154
|
+
paren_depth--;
|
|
155
|
+
if (paren_depth === 0) {
|
|
156
|
+
paren_end = this.lexer.token_end;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (this.is_whitespace_inline()) continue;
|
|
161
|
+
let child_node = this.parse_value_node();
|
|
162
|
+
if (child_node !== null) children.push(child_node);
|
|
163
|
+
}
|
|
164
|
+
this.arena.set_length(node, paren_end - start);
|
|
165
|
+
this.arena.append_children(node, children);
|
|
166
|
+
return node;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Parse a CSS declaration value string and return a VALUE node
|
|
171
|
+
* @param value_string - The CSS value to parse (e.g., "1px solid red")
|
|
172
|
+
* @returns A CSSNode VALUE wrapper containing the parsed value tokens as children
|
|
173
|
+
*/
|
|
220
174
|
function parse_value(value_string) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const value_node_index = value_parser.parse_value(0, value_string.length, 1, 1);
|
|
224
|
-
return new CSSNode(arena, value_string, value_node_index);
|
|
175
|
+
const arena = new CSSDataArena(CSSDataArena.capacity_for_source(value_string.length));
|
|
176
|
+
return new CSSNode(arena, value_string, new ValueParser(arena, value_string).parse_value(0, value_string.length, 1, 1));
|
|
225
177
|
}
|
|
226
|
-
|
|
178
|
+
//#endregion
|
|
227
179
|
export { ValueParser, parse_value };
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CSSNode } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { t as CommentInfo } from "./tokenize-odLrcjj2.js";
|
|
2
|
+
import { E as CSSDataArena, r as CSSNode } from "./css-node-DqyvMXBN.js";
|
|
3
|
+
|
|
4
|
+
//#region src/parse.d.ts
|
|
5
|
+
interface ParserOptions {
|
|
6
|
+
parse_values?: boolean;
|
|
7
|
+
parse_selectors?: boolean;
|
|
8
|
+
parse_atrule_preludes?: boolean;
|
|
9
|
+
on_comment?: (info: CommentInfo) => void;
|
|
10
|
+
}
|
|
11
|
+
/** @internal */
|
|
12
|
+
declare class Parser {
|
|
13
|
+
private source;
|
|
14
|
+
private lexer;
|
|
15
|
+
private arena;
|
|
16
|
+
private selector_parser;
|
|
17
|
+
private prelude_parser;
|
|
18
|
+
private declaration_parser;
|
|
19
|
+
private parse_values_enabled;
|
|
20
|
+
private parse_selectors_enabled;
|
|
21
|
+
private parse_atrule_preludes_enabled;
|
|
22
|
+
constructor(source: string, options?: ParserOptions);
|
|
23
|
+
get_arena(): CSSDataArena;
|
|
24
|
+
get_source(): string;
|
|
25
|
+
private next_token;
|
|
26
|
+
private peek_type;
|
|
27
|
+
private is_eof;
|
|
28
|
+
parse(): CSSNode;
|
|
29
|
+
private parse_rule;
|
|
30
|
+
private parse_style_rule;
|
|
31
|
+
private parse_selector;
|
|
32
|
+
private parse_declaration;
|
|
33
|
+
private parse_atrule;
|
|
34
|
+
private atrule_has_declarations;
|
|
8
35
|
}
|
|
9
36
|
/**
|
|
10
37
|
* Parse CSS and return an AST
|
|
@@ -12,4 +39,6 @@ export interface ParserOptions {
|
|
|
12
39
|
* @param options - Parser options
|
|
13
40
|
* @returns The root CSSNode of the AST
|
|
14
41
|
*/
|
|
15
|
-
|
|
42
|
+
declare function parse(source: string, options?: ParserOptions): CSSNode;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { Parser, ParserOptions, parse };
|