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