@projectwallace/css-parser 0.13.5 → 0.13.6

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 (41) hide show
  1. package/dist/css-node-2ejJUrIw.js +645 -0
  2. package/dist/css-node-DqyvMXBN.d.ts +313 -0
  3. package/dist/index.d.ts +150 -16
  4. package/dist/index.js +103 -13
  5. package/dist/parse-anplusb.d.ts +26 -2
  6. package/dist/parse-anplusb.js +191 -207
  7. package/dist/parse-atrule-prelude.d.ts +40 -2
  8. package/dist/parse-atrule-prelude.js +556 -652
  9. package/dist/parse-declaration.d.ts +16 -2
  10. package/dist/parse-declaration.js +140 -167
  11. package/dist/parse-dimension-CCn_XRDe.js +177 -0
  12. package/dist/parse-dimension.d.ts +6 -3
  13. package/dist/parse-dimension.js +1 -35
  14. package/dist/parse-selector.d.ts +37 -2
  15. package/dist/parse-selector.js +508 -635
  16. package/dist/parse-utils-DnsZRpfd.js +98 -0
  17. package/dist/parse-value.d.ts +23 -2
  18. package/dist/parse-value.js +176 -224
  19. package/dist/parse.d.ts +38 -8
  20. package/dist/parse.js +274 -353
  21. package/dist/tokenize-BQFB1jXg.js +540 -0
  22. package/dist/tokenize-odLrcjj2.d.ts +110 -0
  23. package/dist/tokenize.d.ts +2 -26
  24. package/dist/tokenize.js +1 -545
  25. package/package.json +20 -26
  26. package/dist/arena.d.ts +0 -60
  27. package/dist/arena.js +0 -291
  28. package/dist/char-types.d.ts +0 -14
  29. package/dist/char-types.js +0 -53
  30. package/dist/constants.d.ts +0 -44
  31. package/dist/constants.js +0 -51
  32. package/dist/css-node.d.ts +0 -203
  33. package/dist/css-node.js +0 -498
  34. package/dist/parse-utils.d.ts +0 -1
  35. package/dist/parse-utils.js +0 -60
  36. package/dist/string-utils.d.ts +0 -99
  37. package/dist/string-utils.js +0 -129
  38. package/dist/token-types.d.ts +0 -35
  39. package/dist/token-types.js +0 -29
  40. package/dist/walk.d.ts +0 -28
  41. 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 };
@@ -1,7 +1,28 @@
1
- import { CSSNode } from './css-node';
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
- export declare function parse_value(value_string: string): CSSNode;
26
+ declare function parse_value(value_string: string): CSSNode;
27
+ //#endregion
28
+ export { ValueParser, parse_value };
@@ -1,227 +1,179 @@
1
- import { Lexer } from './tokenize.js';
2
- import { CSSDataArena, VALUE, OPERATOR, UNICODE_RANGE, HASH, STRING, DIMENSION, NUMBER, IDENTIFIER, URL, FUNCTION, PARENTHESIS } from './arena.js';
3
- import { TOKEN_EOF, TOKEN_LEFT_PAREN, TOKEN_COMMA, TOKEN_DELIM, TOKEN_FUNCTION, TOKEN_UNICODE_RANGE, TOKEN_HASH, TOKEN_STRING, TOKEN_DIMENSION, TOKEN_PERCENTAGE, TOKEN_NUMBER, TOKEN_IDENT, TOKEN_RIGHT_PAREN } from './token-types.js';
4
- import { is_whitespace, CHAR_PLUS, CHAR_MINUS_HYPHEN, CHAR_ASTERISK, CHAR_FORWARD_SLASH, str_equals } from './string-utils.js';
5
- import { CSSNode } from './css-node.js';
6
-
7
- class ValueParser {
8
- lexer;
9
- arena;
10
- source;
11
- value_end;
12
- constructor(arena, source) {
13
- this.arena = arena;
14
- this.source = source;
15
- this.lexer = new Lexer(source);
16
- this.value_end = 0;
17
- }
18
- // Parse a declaration value range into a VALUE wrapper node
19
- // Returns single VALUE node index
20
- parse_value(start, end, start_line, start_column) {
21
- this.value_end = end;
22
- this.lexer.seek(start, start_line, start_column);
23
- let value_nodes = this.parse_value_tokens();
24
- if (value_nodes.length === 0) {
25
- let value_node2 = this.arena.create_node(VALUE, start, 0, start_line, start_column);
26
- return value_node2;
27
- }
28
- let first_node_start = this.arena.get_start_offset(value_nodes[0]);
29
- let last_node_index = value_nodes[value_nodes.length - 1];
30
- let last_node_end = this.arena.get_start_offset(last_node_index) + this.arena.get_length(last_node_index);
31
- let value_node = this.arena.create_node(VALUE, first_node_start, last_node_end - first_node_start, start_line, start_column);
32
- this.arena.append_children(value_node, value_nodes);
33
- return value_node;
34
- }
35
- // Core token parsing logic
36
- parse_value_tokens() {
37
- let nodes = [];
38
- while (this.lexer.pos < this.value_end) {
39
- this.lexer.next_token_fast(false);
40
- if (this.lexer.token_start >= this.value_end) break;
41
- let token_type = this.lexer.token_type;
42
- if (token_type === TOKEN_EOF) break;
43
- if (this.is_whitespace_inline()) {
44
- continue;
45
- }
46
- let node = this.parse_value_node();
47
- if (node !== null) {
48
- nodes.push(node);
49
- }
50
- }
51
- return nodes;
52
- }
53
- // Helper to check if token is all whitespace (inline for hot paths)
54
- is_whitespace_inline() {
55
- if (this.lexer.token_start >= this.lexer.token_end) return false;
56
- for (let i = this.lexer.token_start; i < this.lexer.token_end; i++) {
57
- if (!is_whitespace(this.source.charCodeAt(i))) {
58
- return false;
59
- }
60
- }
61
- return true;
62
- }
63
- parse_value_node() {
64
- let token_type = this.lexer.token_type;
65
- let start = this.lexer.token_start;
66
- let end = this.lexer.token_end;
67
- switch (token_type) {
68
- case TOKEN_IDENT:
69
- return this.create_node(IDENTIFIER, start, end);
70
- case TOKEN_NUMBER:
71
- return this.create_node(NUMBER, start, end);
72
- case TOKEN_PERCENTAGE:
73
- case TOKEN_DIMENSION:
74
- return this.create_node(DIMENSION, start, end);
75
- case TOKEN_STRING:
76
- return this.create_node(STRING, start, end);
77
- case TOKEN_HASH:
78
- return this.create_node(HASH, start, end);
79
- case TOKEN_UNICODE_RANGE:
80
- return this.create_node(UNICODE_RANGE, start, end);
81
- case TOKEN_FUNCTION:
82
- return this.parse_function_node(start, end);
83
- case TOKEN_DELIM:
84
- return this.parse_operator_node(start, end);
85
- case TOKEN_COMMA:
86
- return this.create_node(OPERATOR, start, end);
87
- case TOKEN_LEFT_PAREN:
88
- return this.parse_parenthesis_node(start, end);
89
- default:
90
- return null;
91
- }
92
- }
93
- create_node(node_type, start, end) {
94
- let node = this.arena.create_node(node_type, start, end - start, this.lexer.token_line, this.lexer.token_column);
95
- this.arena.set_content_length(node, end - start);
96
- return node;
97
- }
98
- create_operator_node(start, end) {
99
- return this.create_node(OPERATOR, start, end);
100
- }
101
- parse_operator_node(start, end) {
102
- let ch = this.source.charCodeAt(start);
103
- if (ch === CHAR_PLUS || ch === CHAR_MINUS_HYPHEN || ch === CHAR_ASTERISK || ch === CHAR_FORWARD_SLASH) {
104
- return this.create_operator_node(start, end);
105
- }
106
- return null;
107
- }
108
- parse_function_node(start, end) {
109
- let name_end = end - 1;
110
- let func_name_substr = this.source.substring(start, name_end);
111
- let node = this.arena.create_node(
112
- str_equals("url", func_name_substr) ? URL : FUNCTION,
113
- start,
114
- 0,
115
- // length unknown yet
116
- this.lexer.token_line,
117
- this.lexer.token_column
118
- );
119
- this.arena.set_content_start_delta(node, 0);
120
- this.arena.set_content_length(node, name_end - start);
121
- if (str_equals("url", func_name_substr) || str_equals("src", func_name_substr)) {
122
- let save_pos = this.lexer.save_position();
123
- this.lexer.next_token_fast(false);
124
- while (this.is_whitespace_inline() && this.lexer.pos < this.value_end) {
125
- this.lexer.next_token_fast(false);
126
- }
127
- let first_token_type = this.lexer.token_type;
128
- this.lexer.restore_position(save_pos);
129
- if (first_token_type === TOKEN_STRING) ; else {
130
- let paren_depth2 = 1;
131
- let func_end2 = end;
132
- let content_start2 = end;
133
- let content_end2 = end;
134
- while (paren_depth2 > 0) {
135
- this.lexer.next_token_fast(false);
136
- let token_type = this.lexer.token_type;
137
- if (token_type === TOKEN_EOF) break;
138
- if (token_type === TOKEN_LEFT_PAREN || token_type === TOKEN_FUNCTION) {
139
- paren_depth2++;
140
- } else if (token_type === TOKEN_RIGHT_PAREN) {
141
- paren_depth2--;
142
- if (paren_depth2 === 0) {
143
- content_end2 = this.lexer.token_start;
144
- func_end2 = this.lexer.token_end;
145
- break;
146
- }
147
- }
148
- }
149
- this.arena.set_length(node, func_end2 - start);
150
- this.arena.set_value_start_delta(node, content_start2 - start);
151
- this.arena.set_value_length(node, content_end2 - content_start2);
152
- return node;
153
- }
154
- }
155
- let args = [];
156
- let paren_depth = 1;
157
- let func_end = end;
158
- let content_start = end;
159
- let content_end = end;
160
- while (this.lexer.pos < this.value_end && paren_depth > 0) {
161
- this.lexer.next_token_fast(false);
162
- let token_type = this.lexer.token_type;
163
- if (token_type === TOKEN_EOF) break;
164
- if (this.lexer.token_start >= this.value_end) break;
165
- if (token_type === TOKEN_RIGHT_PAREN) {
166
- paren_depth--;
167
- if (paren_depth === 0) {
168
- content_end = this.lexer.token_start;
169
- func_end = this.lexer.token_end;
170
- break;
171
- }
172
- }
173
- if (this.is_whitespace_inline()) continue;
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-2ejJUrIw.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
- const arena = new CSSDataArena(CSSDataArena.capacity_for_source(value_string.length));
222
- const value_parser = new ValueParser(arena, value_string);
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,38 @@
1
- import { type CommentInfo } from './tokenize';
2
- import { CSSNode } from './css-node';
3
- export interface ParserOptions {
4
- parse_values?: boolean;
5
- parse_selectors?: boolean;
6
- parse_atrule_preludes?: boolean;
7
- on_comment?: (info: CommentInfo) => void;
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;
35
+ private atrule_is_conditional;
8
36
  }
9
37
  /**
10
38
  * Parse CSS and return an AST
@@ -12,4 +40,6 @@ export interface ParserOptions {
12
40
  * @param options - Parser options
13
41
  * @returns The root CSSNode of the AST
14
42
  */
15
- export declare function parse(source: string, options?: ParserOptions): CSSNode;
43
+ declare function parse(source: string, options?: ParserOptions): CSSNode;
44
+ //#endregion
45
+ export { Parser, ParserOptions, parse };