@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.
Files changed (41) hide show
  1. package/dist/css-node-DqyvMXBN.d.ts +313 -0
  2. package/dist/css-node-Uj4oBgaw.js +647 -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 +37 -8
  20. package/dist/parse.js +252 -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
package/dist/arena.js DELETED
@@ -1,291 +0,0 @@
1
- let BYTES_PER_NODE = 36;
2
- const STYLESHEET = 1;
3
- const STYLE_RULE = 2;
4
- const AT_RULE = 3;
5
- const DECLARATION = 4;
6
- const SELECTOR = 5;
7
- const COMMENT = 6;
8
- const BLOCK = 7;
9
- const RAW = 8;
10
- const IDENTIFIER = 10;
11
- const NUMBER = 11;
12
- const DIMENSION = 12;
13
- const STRING = 13;
14
- const HASH = 14;
15
- const FUNCTION = 15;
16
- const OPERATOR = 16;
17
- const PARENTHESIS = 17;
18
- const URL = 18;
19
- const UNICODE_RANGE = 19;
20
- const SELECTOR_LIST = 20;
21
- const TYPE_SELECTOR = 21;
22
- const CLASS_SELECTOR = 22;
23
- const ID_SELECTOR = 23;
24
- const ATTRIBUTE_SELECTOR = 24;
25
- const PSEUDO_CLASS_SELECTOR = 25;
26
- const PSEUDO_ELEMENT_SELECTOR = 26;
27
- const COMBINATOR = 27;
28
- const UNIVERSAL_SELECTOR = 28;
29
- const NESTING_SELECTOR = 29;
30
- const NTH_SELECTOR = 30;
31
- const NTH_OF_SELECTOR = 31;
32
- const LANG_SELECTOR = 56;
33
- const MEDIA_QUERY = 32;
34
- const MEDIA_FEATURE = 33;
35
- const MEDIA_TYPE = 34;
36
- const CONTAINER_QUERY = 35;
37
- const SUPPORTS_QUERY = 36;
38
- const LAYER_NAME = 37;
39
- const PRELUDE_OPERATOR = 38;
40
- const FEATURE_RANGE = 39;
41
- const AT_RULE_PRELUDE = 40;
42
- const PRELUDE_SELECTORLIST = 41;
43
- const VALUE = 50;
44
- const FLAG_IMPORTANT = 1 << 0;
45
- const FLAG_HAS_ERROR = 1 << 1;
46
- const FLAG_LENGTH_OVERFLOW = 1 << 2;
47
- const FLAG_HAS_BLOCK = 1 << 3;
48
- const FLAG_HAS_DECLARATIONS = 1 << 5;
49
- const FLAG_HAS_PARENS = 1 << 6;
50
- const FLAG_BROWSERHACK = 1 << 7;
51
- const ATTR_OPERATOR_NONE = 0;
52
- const ATTR_OPERATOR_EQUAL = 1;
53
- const ATTR_OPERATOR_TILDE_EQUAL = 2;
54
- const ATTR_OPERATOR_PIPE_EQUAL = 3;
55
- const ATTR_OPERATOR_CARET_EQUAL = 4;
56
- const ATTR_OPERATOR_DOLLAR_EQUAL = 5;
57
- const ATTR_OPERATOR_STAR_EQUAL = 6;
58
- const ATTR_FLAG_NONE = 0;
59
- const ATTR_FLAG_CASE_INSENSITIVE = 1;
60
- const ATTR_FLAG_CASE_SENSITIVE = 2;
61
- class CSSDataArena {
62
- buffer;
63
- view;
64
- capacity;
65
- // Number of nodes that can fit
66
- count;
67
- // Number of nodes currently allocated
68
- growth_count;
69
- // Number of times the arena has grown
70
- overflow_lengths;
71
- // Stores actual lengths for nodes > 65535 chars
72
- // Growth multiplier when capacity is exceeded
73
- static GROWTH_FACTOR = 1.3;
74
- // Estimated nodes per KB of CSS (based on real-world data)
75
- // Increased from 270 to 325 to account for VALUE wrapper nodes
76
- // (~20% of nodes are declarations, +1 VALUE node per declaration = +20% nodes)
77
- static NODES_PER_KB = 325;
78
- // Buffer to avoid frequent growth (15%)
79
- static CAPACITY_BUFFER = 1.2;
80
- constructor(initial_capacity = 1024) {
81
- this.capacity = initial_capacity;
82
- this.count = 1;
83
- this.growth_count = 0;
84
- this.buffer = new ArrayBuffer(initial_capacity * BYTES_PER_NODE);
85
- this.view = new DataView(this.buffer);
86
- this.overflow_lengths = /* @__PURE__ */ new Map();
87
- }
88
- // Calculate recommended initial capacity based on CSS source size
89
- static capacity_for_source(source_length) {
90
- let size_in_kb = source_length / 1024;
91
- let estimated_nodes = Math.ceil(size_in_kb * CSSDataArena.NODES_PER_KB);
92
- let capacity = Math.ceil(estimated_nodes * CSSDataArena.CAPACITY_BUFFER);
93
- return Math.max(16, capacity);
94
- }
95
- // Get the number of nodes currently in the arena
96
- get_count() {
97
- return this.count;
98
- }
99
- // Get the capacity (max nodes without reallocation)
100
- get_capacity() {
101
- return this.capacity;
102
- }
103
- // Get the number of times the arena has grown
104
- get_growth_count() {
105
- return this.growth_count;
106
- }
107
- // Calculate byte offset for a node
108
- node_offset(node_index) {
109
- return node_index * BYTES_PER_NODE;
110
- }
111
- // Read node type
112
- get_type(node_index) {
113
- return this.view.getUint8(this.node_offset(node_index));
114
- }
115
- // Read node flags
116
- get_flags(node_index) {
117
- return this.view.getUint8(this.node_offset(node_index) + 1);
118
- }
119
- // Read start offset in source
120
- get_start_offset(node_index) {
121
- return this.view.getUint32(this.node_offset(node_index) + 12, true);
122
- }
123
- // Read length in source
124
- get_length(node_index) {
125
- if (this.has_flag(node_index, FLAG_LENGTH_OVERFLOW)) {
126
- const overflow_length = this.overflow_lengths.get(node_index);
127
- if (overflow_length !== void 0) {
128
- return overflow_length;
129
- }
130
- }
131
- return this.view.getUint16(this.node_offset(node_index) + 2, true);
132
- }
133
- // Read content start offset (stored as delta from startOffset)
134
- get_content_start(node_index) {
135
- const startOffset = this.get_start_offset(node_index);
136
- const delta = this.view.getUint16(this.node_offset(node_index) + 16, true);
137
- return startOffset + delta;
138
- }
139
- // Read content length
140
- get_content_length(node_index) {
141
- return this.view.getUint16(this.node_offset(node_index) + 20, true);
142
- }
143
- // Read attribute operator (for NODE_SELECTOR_ATTRIBUTE)
144
- get_attr_operator(node_index) {
145
- return this.view.getUint8(this.node_offset(node_index) + 32);
146
- }
147
- // Read attribute flags (for NODE_SELECTOR_ATTRIBUTE)
148
- get_attr_flags(node_index) {
149
- return this.view.getUint8(this.node_offset(node_index) + 33);
150
- }
151
- // Read first child index (0 = no children)
152
- get_first_child(node_index) {
153
- return this.view.getUint32(this.node_offset(node_index) + 4, true);
154
- }
155
- // Read next sibling index (0 = no sibling)
156
- get_next_sibling(node_index) {
157
- return this.view.getUint32(this.node_offset(node_index) + 8, true);
158
- }
159
- // Read start line
160
- get_start_line(node_index) {
161
- return this.view.getUint32(this.node_offset(node_index) + 24, true);
162
- }
163
- // Read start column
164
- get_start_column(node_index) {
165
- return this.view.getUint32(this.node_offset(node_index) + 28, true);
166
- }
167
- // Read value start offset (stored as delta from startOffset, declaration value / at-rule prelude)
168
- get_value_start(node_index) {
169
- const startOffset = this.get_start_offset(node_index);
170
- const delta = this.view.getUint16(this.node_offset(node_index) + 18, true);
171
- return startOffset + delta;
172
- }
173
- // Read value length
174
- get_value_length(node_index) {
175
- return this.view.getUint16(this.node_offset(node_index) + 22, true);
176
- }
177
- // --- Write Methods ---
178
- // Write node type
179
- set_type(node_index, type) {
180
- this.view.setUint8(this.node_offset(node_index), type);
181
- }
182
- // Write node flags
183
- set_flags(node_index, flags) {
184
- this.view.setUint8(this.node_offset(node_index) + 1, flags);
185
- }
186
- // Write length in source
187
- set_length(node_index, length) {
188
- if (length > 65535) {
189
- this.view.setUint16(this.node_offset(node_index) + 2, 65535, true);
190
- this.set_flag(node_index, FLAG_LENGTH_OVERFLOW);
191
- this.overflow_lengths.set(node_index, length);
192
- } else {
193
- this.view.setUint16(this.node_offset(node_index) + 2, length, true);
194
- }
195
- }
196
- // Write content start delta (offset from startOffset)
197
- set_content_start_delta(node_index, delta) {
198
- this.view.setUint16(this.node_offset(node_index) + 16, delta, true);
199
- }
200
- // Write content length
201
- set_content_length(node_index, length) {
202
- this.view.setUint16(this.node_offset(node_index) + 20, length, true);
203
- }
204
- // Write attribute operator (for NODE_SELECTOR_ATTRIBUTE)
205
- set_attr_operator(node_index, operator) {
206
- this.view.setUint8(this.node_offset(node_index) + 32, operator);
207
- }
208
- // Write attribute flags (for NODE_SELECTOR_ATTRIBUTE)
209
- set_attr_flags(node_index, flags) {
210
- this.view.setUint8(this.node_offset(node_index) + 33, flags);
211
- }
212
- // Write first child index
213
- set_first_child(node_index, childIndex) {
214
- this.view.setUint32(this.node_offset(node_index) + 4, childIndex, true);
215
- }
216
- // Write next sibling index
217
- set_next_sibling(node_index, siblingIndex) {
218
- this.view.setUint32(this.node_offset(node_index) + 8, siblingIndex, true);
219
- }
220
- // Write value start delta (offset from startOffset, declaration value / at-rule prelude)
221
- set_value_start_delta(node_index, delta) {
222
- this.view.setUint16(this.node_offset(node_index) + 18, delta, true);
223
- }
224
- // Write value length
225
- set_value_length(node_index, length) {
226
- this.view.setUint16(this.node_offset(node_index) + 22, length, true);
227
- }
228
- // --- Node Creation ---
229
- // Grow the arena by 1.3x when capacity is exceeded
230
- grow() {
231
- this.growth_count++;
232
- let new_capacity = Math.ceil(this.capacity * CSSDataArena.GROWTH_FACTOR);
233
- let new_buffer = new ArrayBuffer(new_capacity * BYTES_PER_NODE);
234
- new Uint8Array(new_buffer).set(new Uint8Array(this.buffer));
235
- this.buffer = new_buffer;
236
- this.view = new DataView(new_buffer);
237
- this.capacity = new_capacity;
238
- }
239
- // Allocate and initialize a new node with core properties
240
- // Automatically grows the arena if capacity is exceeded
241
- create_node(type, start_offset, length, start_line, start_column) {
242
- if (this.count >= this.capacity) {
243
- this.grow();
244
- }
245
- const node_index = this.count;
246
- this.count++;
247
- const offset = node_index * BYTES_PER_NODE;
248
- this.view.setUint8(offset, type);
249
- this.view.setUint32(offset + 12, start_offset, true);
250
- this.view.setUint32(offset + 24, start_line, true);
251
- this.view.setUint32(offset + 28, start_column, true);
252
- this.set_length(node_index, length);
253
- return node_index;
254
- }
255
- // --- Tree Building Helpers ---
256
- // Link multiple child nodes to a parent
257
- // Children are linked as siblings in the order provided
258
- append_children(parent_index, children) {
259
- if (children.length === 0) return;
260
- const offset = this.node_offset(parent_index);
261
- this.view.setUint32(offset + 4, children[0], true);
262
- for (let i = 0; i < children.length - 1; i++) {
263
- this.set_next_sibling(children[i], children[i + 1]);
264
- }
265
- }
266
- // Check if a node has any children
267
- has_children(node_index) {
268
- return this.get_first_child(node_index) !== 0;
269
- }
270
- // Check if a node has a next sibling
271
- has_next_sibling(node_index) {
272
- return this.get_next_sibling(node_index) !== 0;
273
- }
274
- // --- Flag Management Helpers ---
275
- // Set a specific flag bit (doesn't clear other flags)
276
- set_flag(node_index, flag) {
277
- let current_flags = this.get_flags(node_index);
278
- this.set_flags(node_index, current_flags | flag);
279
- }
280
- // Clear a specific flag bit (doesn't affect other flags)
281
- clear_flag(node_index, flag) {
282
- let current_flags = this.get_flags(node_index);
283
- this.set_flags(node_index, current_flags & ~flag);
284
- }
285
- // Check if a specific flag is set
286
- has_flag(node_index, flag) {
287
- return (this.get_flags(node_index) & flag) !== 0;
288
- }
289
- }
290
-
291
- export { ATTRIBUTE_SELECTOR, ATTR_FLAG_CASE_INSENSITIVE, ATTR_FLAG_CASE_SENSITIVE, ATTR_FLAG_NONE, ATTR_OPERATOR_CARET_EQUAL, ATTR_OPERATOR_DOLLAR_EQUAL, ATTR_OPERATOR_EQUAL, ATTR_OPERATOR_NONE, ATTR_OPERATOR_PIPE_EQUAL, ATTR_OPERATOR_STAR_EQUAL, ATTR_OPERATOR_TILDE_EQUAL, AT_RULE, AT_RULE_PRELUDE, BLOCK, CLASS_SELECTOR, COMBINATOR, COMMENT, CONTAINER_QUERY, CSSDataArena, DECLARATION, DIMENSION, FEATURE_RANGE, FLAG_BROWSERHACK, FLAG_HAS_BLOCK, FLAG_HAS_DECLARATIONS, FLAG_HAS_ERROR, FLAG_HAS_PARENS, FLAG_IMPORTANT, FLAG_LENGTH_OVERFLOW, FUNCTION, HASH, IDENTIFIER, ID_SELECTOR, LANG_SELECTOR, LAYER_NAME, MEDIA_FEATURE, MEDIA_QUERY, MEDIA_TYPE, NESTING_SELECTOR, NTH_OF_SELECTOR, NTH_SELECTOR, NUMBER, OPERATOR, PARENTHESIS, PRELUDE_OPERATOR, PRELUDE_SELECTORLIST, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, RAW, SELECTOR, SELECTOR_LIST, STRING, STYLESHEET, STYLE_RULE, SUPPORTS_QUERY, TYPE_SELECTOR, UNICODE_RANGE, UNIVERSAL_SELECTOR, URL, VALUE };
@@ -1,14 +0,0 @@
1
- export declare let CHAR_ALPHA: number;
2
- export declare let CHAR_DIGIT: number;
3
- export declare let CHAR_HEX: number;
4
- export declare let CHAR_WHITESPACE: number;
5
- export declare let CHAR_NEWLINE: number;
6
- export declare let CHAR_IDENT: number;
7
- export declare let char_types: Uint8Array<ArrayBuffer>;
8
- export declare function is_digit(ch: number): boolean;
9
- export declare function is_hex_digit(ch: number): boolean;
10
- export declare function is_alpha(ch: number): boolean;
11
- export declare function is_whitespace(ch: number): boolean;
12
- export declare function is_newline(ch: number): boolean;
13
- export declare function is_ident_start(ch: number): boolean;
14
- export declare function is_ident_char(ch: number): boolean;
@@ -1,53 +0,0 @@
1
- let CHAR_ALPHA = 1 << 0;
2
- let CHAR_DIGIT = 1 << 1;
3
- let CHAR_HEX = 1 << 2;
4
- let CHAR_WHITESPACE = 1 << 3;
5
- let CHAR_NEWLINE = 1 << 4;
6
- let CHAR_IDENT = 1 << 5;
7
- let char_types = new Uint8Array(128);
8
- for (let i = 48; i <= 57; i++) {
9
- char_types[i] = CHAR_DIGIT;
10
- }
11
- for (let i = 48; i <= 57; i++) {
12
- char_types[i] |= CHAR_HEX;
13
- }
14
- for (let i = 65; i <= 70; i++) {
15
- char_types[i] = CHAR_HEX;
16
- }
17
- for (let i = 97; i <= 102; i++) {
18
- char_types[i] = CHAR_HEX;
19
- }
20
- for (let i = 65; i <= 90; i++) {
21
- char_types[i] |= CHAR_ALPHA;
22
- }
23
- for (let i = 97; i <= 122; i++) {
24
- char_types[i] |= CHAR_ALPHA;
25
- }
26
- char_types[32] = CHAR_WHITESPACE;
27
- char_types[9] = CHAR_WHITESPACE;
28
- char_types[10] = CHAR_NEWLINE;
29
- char_types[13] = CHAR_NEWLINE;
30
- char_types[12] = CHAR_NEWLINE;
31
- for (let i = 0; i < 128; i++) {
32
- if (char_types[i] & (CHAR_ALPHA | CHAR_DIGIT)) {
33
- char_types[i] |= CHAR_IDENT;
34
- }
35
- }
36
- char_types[45] |= CHAR_IDENT;
37
- char_types[95] |= CHAR_IDENT;
38
- function is_hex_digit(ch) {
39
- return ch < 128 && (char_types[ch] & CHAR_HEX) !== 0;
40
- }
41
- function is_alpha(ch) {
42
- return ch < 128 && (char_types[ch] & CHAR_ALPHA) !== 0;
43
- }
44
- function is_whitespace(ch) {
45
- return ch < 128 && (char_types[ch] & CHAR_WHITESPACE) !== 0;
46
- }
47
- function is_ident_start(ch) {
48
- if (ch >= 128) return true;
49
- if (ch === 95) return true;
50
- return is_alpha(ch);
51
- }
52
-
53
- export { CHAR_ALPHA, CHAR_DIGIT, CHAR_HEX, CHAR_IDENT, CHAR_NEWLINE, CHAR_WHITESPACE, char_types, is_alpha, is_hex_digit, is_ident_start, is_whitespace };
@@ -1,44 +0,0 @@
1
- import { STYLESHEET, STYLE_RULE, AT_RULE, DECLARATION, SELECTOR, COMMENT, BLOCK, RAW, IDENTIFIER, NUMBER, DIMENSION, STRING, HASH, FUNCTION, OPERATOR, PARENTHESIS, URL, VALUE, SELECTOR_LIST, TYPE_SELECTOR, CLASS_SELECTOR, ID_SELECTOR, ATTRIBUTE_SELECTOR, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, COMBINATOR, UNIVERSAL_SELECTOR, NESTING_SELECTOR, NTH_SELECTOR, NTH_OF_SELECTOR, LANG_SELECTOR, MEDIA_QUERY, MEDIA_FEATURE, MEDIA_TYPE, CONTAINER_QUERY, SUPPORTS_QUERY, LAYER_NAME, PRELUDE_OPERATOR, FEATURE_RANGE, AT_RULE_PRELUDE, FLAG_IMPORTANT, ATTR_OPERATOR_NONE, ATTR_OPERATOR_EQUAL, ATTR_OPERATOR_TILDE_EQUAL, ATTR_OPERATOR_PIPE_EQUAL, ATTR_OPERATOR_CARET_EQUAL, ATTR_OPERATOR_DOLLAR_EQUAL, ATTR_OPERATOR_STAR_EQUAL, ATTR_FLAG_NONE, ATTR_FLAG_CASE_INSENSITIVE, ATTR_FLAG_CASE_SENSITIVE } from './arena';
2
- export { STYLESHEET, STYLE_RULE, AT_RULE, DECLARATION, SELECTOR, COMMENT, BLOCK, RAW, IDENTIFIER, NUMBER, DIMENSION, STRING, HASH, FUNCTION, OPERATOR, PARENTHESIS, URL, VALUE, SELECTOR_LIST, TYPE_SELECTOR, CLASS_SELECTOR, ID_SELECTOR, ATTRIBUTE_SELECTOR, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, COMBINATOR, UNIVERSAL_SELECTOR, NESTING_SELECTOR, NTH_SELECTOR, NTH_OF_SELECTOR, LANG_SELECTOR, MEDIA_QUERY, MEDIA_FEATURE, MEDIA_TYPE, CONTAINER_QUERY, SUPPORTS_QUERY, LAYER_NAME, PRELUDE_OPERATOR, FEATURE_RANGE, AT_RULE_PRELUDE, FLAG_IMPORTANT, ATTR_OPERATOR_NONE, ATTR_OPERATOR_EQUAL, ATTR_OPERATOR_TILDE_EQUAL, ATTR_OPERATOR_PIPE_EQUAL, ATTR_OPERATOR_CARET_EQUAL, ATTR_OPERATOR_DOLLAR_EQUAL, ATTR_OPERATOR_STAR_EQUAL, ATTR_FLAG_NONE, ATTR_FLAG_CASE_INSENSITIVE, ATTR_FLAG_CASE_SENSITIVE, };
3
- export declare const NODE_TYPES: {
4
- readonly STYLESHEET: 1;
5
- readonly STYLE_RULE: 2;
6
- readonly AT_RULE: 3;
7
- readonly DECLARATION: 4;
8
- readonly SELECTOR: 5;
9
- readonly COMMENT: 6;
10
- readonly BLOCK: 7;
11
- readonly RAW: 8;
12
- readonly IDENTIFIER: 10;
13
- readonly NUMBER: 11;
14
- readonly DIMENSION: 12;
15
- readonly STRING: 13;
16
- readonly HASH: 14;
17
- readonly FUNCTION: 15;
18
- readonly OPERATOR: 16;
19
- readonly PARENTHESIS: 17;
20
- readonly URL: 18;
21
- readonly VALUE: 50;
22
- readonly SELECTOR_LIST: 20;
23
- readonly TYPE_SELECTOR: 21;
24
- readonly CLASS_SELECTOR: 22;
25
- readonly ID_SELECTOR: 23;
26
- readonly ATTRIBUTE_SELECTOR: 24;
27
- readonly PSEUDO_CLASS_SELECTOR: 25;
28
- readonly PSEUDO_ELEMENT_SELECTOR: 26;
29
- readonly COMBINATOR: 27;
30
- readonly UNIVERSAL_SELECTOR: 28;
31
- readonly NESTING_SELECTOR: 29;
32
- readonly NTH_SELECTOR: 30;
33
- readonly NTH_OF_SELECTOR: 31;
34
- readonly LANG_SELECTOR: 56;
35
- readonly MEDIA_QUERY: 32;
36
- readonly MEDIA_FEATURE: 33;
37
- readonly MEDIA_TYPE: 34;
38
- readonly CONTAINER_QUERY: 35;
39
- readonly SUPPORTS_QUERY: 36;
40
- readonly LAYER_NAME: 37;
41
- readonly PRELUDE_OPERATOR: 38;
42
- readonly FEATURE_RANGE: 39;
43
- readonly AT_RULE_PRELUDE: 40;
44
- };
package/dist/constants.js DELETED
@@ -1,51 +0,0 @@
1
- import { AT_RULE_PRELUDE, FEATURE_RANGE, PRELUDE_OPERATOR, LAYER_NAME, SUPPORTS_QUERY, CONTAINER_QUERY, MEDIA_TYPE, MEDIA_FEATURE, MEDIA_QUERY, LANG_SELECTOR, NTH_OF_SELECTOR, NTH_SELECTOR, NESTING_SELECTOR, UNIVERSAL_SELECTOR, COMBINATOR, PSEUDO_ELEMENT_SELECTOR, PSEUDO_CLASS_SELECTOR, ATTRIBUTE_SELECTOR, ID_SELECTOR, CLASS_SELECTOR, TYPE_SELECTOR, SELECTOR_LIST, VALUE, URL, PARENTHESIS, OPERATOR, FUNCTION, HASH, STRING, DIMENSION, NUMBER, IDENTIFIER, RAW, BLOCK, COMMENT, SELECTOR, DECLARATION, AT_RULE, STYLE_RULE, STYLESHEET } from './arena.js';
2
- export { ATTR_FLAG_CASE_INSENSITIVE, ATTR_FLAG_CASE_SENSITIVE, ATTR_FLAG_NONE, ATTR_OPERATOR_CARET_EQUAL, ATTR_OPERATOR_DOLLAR_EQUAL, ATTR_OPERATOR_EQUAL, ATTR_OPERATOR_NONE, ATTR_OPERATOR_PIPE_EQUAL, ATTR_OPERATOR_STAR_EQUAL, ATTR_OPERATOR_TILDE_EQUAL, FLAG_IMPORTANT } from './arena.js';
3
-
4
- const NODE_TYPES = {
5
- // Core nodes
6
- STYLESHEET,
7
- STYLE_RULE,
8
- AT_RULE,
9
- DECLARATION,
10
- SELECTOR,
11
- COMMENT,
12
- BLOCK,
13
- RAW,
14
- // Value nodes
15
- IDENTIFIER,
16
- NUMBER,
17
- DIMENSION,
18
- STRING,
19
- HASH,
20
- FUNCTION,
21
- OPERATOR,
22
- PARENTHESIS,
23
- URL,
24
- VALUE,
25
- // Selector nodes
26
- SELECTOR_LIST,
27
- TYPE_SELECTOR,
28
- CLASS_SELECTOR,
29
- ID_SELECTOR,
30
- ATTRIBUTE_SELECTOR,
31
- PSEUDO_CLASS_SELECTOR,
32
- PSEUDO_ELEMENT_SELECTOR,
33
- COMBINATOR,
34
- UNIVERSAL_SELECTOR,
35
- NESTING_SELECTOR,
36
- NTH_SELECTOR,
37
- NTH_OF_SELECTOR,
38
- LANG_SELECTOR,
39
- // At-rule prelude nodes
40
- MEDIA_QUERY,
41
- MEDIA_FEATURE,
42
- MEDIA_TYPE,
43
- CONTAINER_QUERY,
44
- SUPPORTS_QUERY,
45
- LAYER_NAME,
46
- PRELUDE_OPERATOR,
47
- FEATURE_RANGE,
48
- AT_RULE_PRELUDE
49
- };
50
-
51
- export { ATTRIBUTE_SELECTOR, AT_RULE, AT_RULE_PRELUDE, BLOCK, CLASS_SELECTOR, COMBINATOR, COMMENT, CONTAINER_QUERY, DECLARATION, DIMENSION, FEATURE_RANGE, FUNCTION, HASH, IDENTIFIER, ID_SELECTOR, LANG_SELECTOR, LAYER_NAME, MEDIA_FEATURE, MEDIA_QUERY, MEDIA_TYPE, NESTING_SELECTOR, NODE_TYPES, NTH_OF_SELECTOR, NTH_SELECTOR, NUMBER, OPERATOR, PARENTHESIS, PRELUDE_OPERATOR, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, RAW, SELECTOR, SELECTOR_LIST, STRING, STYLESHEET, STYLE_RULE, SUPPORTS_QUERY, TYPE_SELECTOR, UNIVERSAL_SELECTOR, URL, VALUE };
@@ -1,203 +0,0 @@
1
- import type { CSSDataArena } from './arena';
2
- import { RAW, STYLESHEET, STYLE_RULE, AT_RULE, DECLARATION, SELECTOR, COMMENT, BLOCK, IDENTIFIER, NUMBER, DIMENSION, STRING, HASH, FUNCTION, OPERATOR, PARENTHESIS, URL, VALUE, SELECTOR_LIST, TYPE_SELECTOR, CLASS_SELECTOR, ID_SELECTOR, ATTRIBUTE_SELECTOR, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, COMBINATOR, UNIVERSAL_SELECTOR, NESTING_SELECTOR, NTH_SELECTOR, NTH_OF_SELECTOR, LANG_SELECTOR, MEDIA_QUERY, MEDIA_FEATURE, MEDIA_TYPE, CONTAINER_QUERY, SUPPORTS_QUERY, LAYER_NAME, PRELUDE_OPERATOR, FEATURE_RANGE, AT_RULE_PRELUDE } from './arena';
3
- export declare const TYPE_NAMES: {
4
- readonly 1: "StyleSheet";
5
- readonly 2: "Rule";
6
- readonly 3: "Atrule";
7
- readonly 4: "Declaration";
8
- readonly 5: "Selector";
9
- readonly 6: "Comment";
10
- readonly 7: "Block";
11
- readonly 8: "Raw";
12
- readonly 10: "Identifier";
13
- readonly 11: "Number";
14
- readonly 12: "Dimension";
15
- readonly 13: "String";
16
- readonly 14: "Hash";
17
- readonly 15: "Function";
18
- readonly 16: "Operator";
19
- readonly 17: "Parentheses";
20
- readonly 18: "Url";
21
- readonly 19: "UnicodeRange";
22
- readonly 50: "Value";
23
- readonly 20: "SelectorList";
24
- readonly 21: "TypeSelector";
25
- readonly 22: "ClassSelector";
26
- readonly 23: "IdSelector";
27
- readonly 24: "AttributeSelector";
28
- readonly 25: "PseudoClassSelector";
29
- readonly 26: "PseudoElementSelector";
30
- readonly 27: "Combinator";
31
- readonly 28: "UniversalSelector";
32
- readonly 29: "NestingSelector";
33
- readonly 30: "Nth";
34
- readonly 31: "NthOf";
35
- readonly 56: "Lang";
36
- readonly 32: "MediaQuery";
37
- readonly 33: "Feature";
38
- readonly 34: "MediaType";
39
- readonly 35: "ContainerQuery";
40
- readonly 36: "SupportsQuery";
41
- readonly 37: "Layer";
42
- readonly 38: "Operator";
43
- readonly 39: "MediaFeatureRange";
44
- readonly 40: "AtrulePrelude";
45
- };
46
- export type TypeName = (typeof TYPE_NAMES)[keyof typeof TYPE_NAMES] | 'unknown';
47
- export declare const ATTR_OPERATOR_NAMES: Record<number, string | null>;
48
- export declare const ATTR_FLAG_NAMES: Record<number, string | null>;
49
- export type CSSNodeType = typeof STYLESHEET | typeof STYLE_RULE | typeof AT_RULE | typeof DECLARATION | typeof SELECTOR | typeof COMMENT | typeof BLOCK | typeof RAW | typeof IDENTIFIER | typeof NUMBER | typeof DIMENSION | typeof STRING | typeof HASH | typeof FUNCTION | typeof OPERATOR | typeof PARENTHESIS | typeof URL | typeof VALUE | typeof SELECTOR_LIST | typeof TYPE_SELECTOR | typeof CLASS_SELECTOR | typeof ID_SELECTOR | typeof ATTRIBUTE_SELECTOR | typeof PSEUDO_CLASS_SELECTOR | typeof PSEUDO_ELEMENT_SELECTOR | typeof COMBINATOR | typeof UNIVERSAL_SELECTOR | typeof NESTING_SELECTOR | typeof NTH_SELECTOR | typeof NTH_OF_SELECTOR | typeof LANG_SELECTOR | typeof MEDIA_QUERY | typeof MEDIA_FEATURE | typeof MEDIA_TYPE | typeof CONTAINER_QUERY | typeof SUPPORTS_QUERY | typeof LAYER_NAME | typeof PRELUDE_OPERATOR | typeof FEATURE_RANGE | typeof AT_RULE_PRELUDE;
50
- export interface CloneOptions {
51
- /**
52
- * Recursively clone all children
53
- * @default true
54
- */
55
- deep?: boolean;
56
- /**
57
- * Include location information (line, column, start, length)
58
- * @default false
59
- */
60
- locations?: boolean;
61
- }
62
- export type PlainCSSNode = {
63
- type: number;
64
- type_name: TypeName;
65
- text: string;
66
- children?: PlainCSSNode[];
67
- name?: string;
68
- property?: string;
69
- value?: PlainCSSNode | string | number | null;
70
- unit?: string;
71
- prelude?: PlainCSSNode | null;
72
- is_important?: boolean;
73
- is_vendor_prefixed?: boolean;
74
- is_browserhack?: boolean;
75
- has_error?: boolean;
76
- attr_operator?: string | null;
77
- attr_flags?: string | null;
78
- nth_a?: string | null;
79
- nth_b?: string | null;
80
- line?: number;
81
- column?: number;
82
- start?: number;
83
- length?: number;
84
- end?: number;
85
- };
86
- export declare class CSSNode {
87
- private arena;
88
- private source;
89
- private index;
90
- constructor(arena: CSSDataArena, source: string, index: number);
91
- private get_content;
92
- /** Get node type as number (for performance) */
93
- get type(): CSSNodeType;
94
- /** Get node type as human-readable string */
95
- get type_name(): TypeName;
96
- /** Get the full text of this node from source */
97
- get text(): string;
98
- /** Get the "content" text (at-rule name for at-rules, layer name for import layers) */
99
- get name(): string | undefined;
100
- /**
101
- * Alias for name (for declarations: "color" in "color: blue")
102
- * More semantic than `name` for declaration nodes
103
- */
104
- get property(): string | undefined;
105
- /**
106
- * Get the value text (for declarations: "blue" in "color: blue")
107
- * For dimension/number nodes: returns the numeric value as a number
108
- * For string nodes: returns the string content without quotes
109
- * For URL nodes with quoted string: returns the string with quotes (consistent with STRING node)
110
- * For URL nodes with unquoted URL: returns the URL content without quotes
111
- */
112
- get value(): CSSNode | string | number | null | undefined;
113
- /** Get the numeric value for NUMBER and DIMENSION nodes, or null for other node types */
114
- get value_as_number(): number | null;
115
- /**
116
- * Get the prelude node:
117
- * - For at-rules: AT_RULE_PRELUDE wrapper containing structured prelude children (media queries, layer names, etc.)
118
- * - For style rules: SELECTOR_LIST or SELECTOR node
119
- * Returns null if no prelude exists
120
- */
121
- get prelude(): CSSNode | null | undefined;
122
- /**
123
- * Get the attribute operator (for attribute selectors: =, ~=, |=, ^=, $=, *=)
124
- * Returns one of the ATTR_OPERATOR_* constants
125
- */
126
- get attr_operator(): number | undefined;
127
- /**
128
- * Get the attribute flags (for attribute selectors: i, s)
129
- * Returns one of the ATTR_FLAG_* constants
130
- */
131
- get attr_flags(): number | undefined;
132
- /** Get the unit for dimension nodes (e.g., "px" from "100px", "%" from "50%") */
133
- get unit(): string | undefined;
134
- /** Check if this declaration has !important */
135
- get is_important(): boolean | undefined;
136
- /** Check if this declaration has a browser hack prefix */
137
- get is_browserhack(): boolean | undefined;
138
- /** Check if this has a vendor prefix (computed on-demand) */
139
- get is_vendor_prefixed(): boolean;
140
- /** Check if this node has an error */
141
- get has_error(): boolean;
142
- /** Check if this node has a prelude (at-rules and style rules) */
143
- get has_prelude(): boolean;
144
- /** Check if this rule has a block { } */
145
- get has_block(): boolean;
146
- /** Check if this style rule has declarations */
147
- get has_declarations(): boolean;
148
- /** Get the block node (for style rules and at-rules with blocks) */
149
- get block(): CSSNode | null;
150
- /** Check if this block is empty (no declarations or rules, only comments allowed) */
151
- get is_empty(): boolean | undefined;
152
- /** Get start line number */
153
- get line(): number;
154
- /** Get start column number */
155
- get column(): number;
156
- /** Get start offset in source */
157
- get start(): number;
158
- /** Get length in source */
159
- get length(): number;
160
- /**
161
- * Get end offset in source
162
- * End is not stored, must be calculated
163
- */
164
- get end(): number;
165
- /** Get first child node */
166
- get first_child(): CSSNode | null;
167
- /** Get next sibling node */
168
- get next_sibling(): CSSNode | null;
169
- /** Check if this node has a next sibling */
170
- get has_next(): boolean;
171
- /**
172
- * Check if this node has children
173
- * For pseudo-class/pseudo-element functions, returns true if FLAG_HAS_PARENS is set
174
- * This allows formatters to distinguish :lang() from :hover
175
- */
176
- get has_children(): boolean;
177
- /** Get all children as an array */
178
- get children(): CSSNode[];
179
- /** Make CSSNode iterable over its children */
180
- [Symbol.iterator](): Iterator<CSSNode>;
181
- /** Get the 'a' coefficient from An+B expression (e.g., "2n" from "2n+1", "odd" from "odd") */
182
- get nth_a(): string | undefined;
183
- /** Get the 'b' coefficient from An+B expression (e.g., "+1" from "2n+1") */
184
- get nth_b(): string | undefined;
185
- /** Get the An+B formula node from :nth-child(2n+1 of .foo) */
186
- get nth(): CSSNode | undefined;
187
- /** Get the selector list from :nth-child(2n+1 of .foo) */
188
- get selector(): CSSNode | undefined;
189
- /**
190
- * Get selector list from pseudo-class functions
191
- * Works for :is(.a), :not(.b), :has(.c), :where(.d), :nth-child(2n of .e)
192
- */
193
- get selector_list(): CSSNode | undefined;
194
- /**
195
- * Clone this node as a mutable plain JavaScript object with children as arrays.
196
- * See API.md for examples.
197
- *
198
- * @param options - Cloning configuration
199
- * @param options.deep - Recursively clone children (default: true)
200
- * @param options.locations - Include line/column/start/length (default: false)
201
- */
202
- clone(options?: CloneOptions): PlainCSSNode;
203
- }