@projectwallace/css-parser 0.6.7 → 0.7.1
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/arena.d.ts +36 -91
- package/dist/arena.js +280 -0
- package/dist/char-types.js +55 -0
- package/dist/constants.d.ts +1 -0
- package/dist/css-node.d.ts +43 -5
- package/dist/css-node.js +455 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -24
- package/dist/lexer.d.ts +1 -37
- package/dist/{lexer-CtBKgfVv.js → lexer.js} +3 -81
- package/dist/parse-anplusb.d.ts +0 -20
- package/dist/parse-anplusb.js +28 -30
- package/dist/parse-atrule-prelude.d.ts +0 -25
- package/dist/parse-atrule-prelude.js +36 -42
- package/dist/parse-selector.d.ts +0 -30
- package/dist/parse-selector.js +64 -66
- package/dist/parse-utils.d.ts +0 -40
- package/dist/parse-utils.js +92 -0
- package/dist/parse-value.d.ts +0 -16
- package/dist/parse-value.js +50 -49
- package/dist/parse.d.ts +0 -27
- package/dist/parse.js +96 -73
- package/dist/string-utils.d.ts +0 -6
- package/dist/string-utils.js +63 -0
- package/dist/token-types.js +28 -0
- package/dist/tokenize.js +2 -1
- package/dist/walk.js +21 -0
- package/package.json +8 -10
- package/dist/css-node-GOEvp2OO.js +0 -876
package/dist/arena.d.ts
CHANGED
|
@@ -1,42 +1,39 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
25
|
-
export declare const
|
|
26
|
-
export declare const
|
|
27
|
-
export declare const
|
|
28
|
-
export declare const
|
|
29
|
-
export declare const
|
|
30
|
-
export declare const
|
|
31
|
-
export declare const
|
|
32
|
-
export declare const
|
|
33
|
-
export declare const
|
|
34
|
-
export declare const
|
|
35
|
-
export declare const
|
|
36
|
-
export declare const
|
|
37
|
-
export declare const NODE_PRELUDE_IMPORT_URL = 40;
|
|
38
|
-
export declare const NODE_PRELUDE_IMPORT_LAYER = 41;
|
|
39
|
-
export declare const NODE_PRELUDE_IMPORT_SUPPORTS = 42;
|
|
1
|
+
export declare const STYLESHEET = 1;
|
|
2
|
+
export declare const STYLE_RULE = 2;
|
|
3
|
+
export declare const AT_RULE = 3;
|
|
4
|
+
export declare const DECLARATION = 4;
|
|
5
|
+
export declare const SELECTOR = 5;
|
|
6
|
+
export declare const COMMENT = 6;
|
|
7
|
+
export declare const BLOCK = 7;
|
|
8
|
+
export declare const IDENTIFIER = 10;
|
|
9
|
+
export declare const NUMBER = 11;
|
|
10
|
+
export declare const DIMENSION = 12;
|
|
11
|
+
export declare const STRING = 13;
|
|
12
|
+
export declare const HASH = 14;
|
|
13
|
+
export declare const FUNCTION = 15;
|
|
14
|
+
export declare const OPERATOR = 16;
|
|
15
|
+
export declare const PARENTHESIS = 17;
|
|
16
|
+
export declare const URL = 18;
|
|
17
|
+
export declare const SELECTOR_LIST = 20;
|
|
18
|
+
export declare const TYPE_SELECTOR = 21;
|
|
19
|
+
export declare const CLASS_SELECTOR = 22;
|
|
20
|
+
export declare const ID_SELECTOR = 23;
|
|
21
|
+
export declare const ATTRIBUTE_SELECTOR = 24;
|
|
22
|
+
export declare const PSEUDO_CLASS_SELECTOR = 25;
|
|
23
|
+
export declare const PSEUDO_ELEMENT_SELECTOR = 26;
|
|
24
|
+
export declare const COMBINATOR = 27;
|
|
25
|
+
export declare const UNIVERSAL_SELECTOR = 28;
|
|
26
|
+
export declare const NESTING_SELECTOR = 29;
|
|
27
|
+
export declare const NTH_SELECTOR = 30;
|
|
28
|
+
export declare const NTH_OF_SELECTOR = 31;
|
|
29
|
+
export declare const LANG_SELECTOR = 56;
|
|
30
|
+
export declare const MEDIA_QUERY = 32;
|
|
31
|
+
export declare const MEDIA_FEATURE = 33;
|
|
32
|
+
export declare const MEDIA_TYPE = 34;
|
|
33
|
+
export declare const CONTAINER_QUERY = 35;
|
|
34
|
+
export declare const SUPPORTS_QUERY = 36;
|
|
35
|
+
export declare const LAYER_NAME = 37;
|
|
36
|
+
export declare const PRELUDE_OPERATOR = 38;
|
|
40
37
|
export declare const FLAG_IMPORTANT: number;
|
|
41
38
|
export declare const FLAG_HAS_ERROR: number;
|
|
42
39
|
export declare const FLAG_LENGTH_OVERFLOW: number;
|
|
@@ -54,55 +51,3 @@ export declare const ATTR_OPERATOR_STAR_EQUAL = 6;
|
|
|
54
51
|
export declare const ATTR_FLAG_NONE = 0;
|
|
55
52
|
export declare const ATTR_FLAG_CASE_INSENSITIVE = 1;
|
|
56
53
|
export declare const ATTR_FLAG_CASE_SENSITIVE = 2;
|
|
57
|
-
export declare class CSSDataArena {
|
|
58
|
-
private buffer;
|
|
59
|
-
private view;
|
|
60
|
-
private capacity;
|
|
61
|
-
private count;
|
|
62
|
-
private static readonly GROWTH_FACTOR;
|
|
63
|
-
private static readonly NODES_PER_KB;
|
|
64
|
-
private static readonly CAPACITY_BUFFER;
|
|
65
|
-
constructor(initial_capacity?: number);
|
|
66
|
-
static capacity_for_source(source_length: number): number;
|
|
67
|
-
get_count(): number;
|
|
68
|
-
get_capacity(): number;
|
|
69
|
-
private node_offset;
|
|
70
|
-
get_type(node_index: number): number;
|
|
71
|
-
get_flags(node_index: number): number;
|
|
72
|
-
get_start_offset(node_index: number): number;
|
|
73
|
-
get_length(node_index: number): number;
|
|
74
|
-
get_content_start(node_index: number): number;
|
|
75
|
-
get_content_length(node_index: number): number;
|
|
76
|
-
get_attr_operator(node_index: number): number;
|
|
77
|
-
get_attr_flags(node_index: number): number;
|
|
78
|
-
get_first_child(node_index: number): number;
|
|
79
|
-
get_last_child(node_index: number): number;
|
|
80
|
-
get_next_sibling(node_index: number): number;
|
|
81
|
-
get_start_line(node_index: number): number;
|
|
82
|
-
get_start_column(node_index: number): number;
|
|
83
|
-
get_value_start(node_index: number): number;
|
|
84
|
-
get_value_length(node_index: number): number;
|
|
85
|
-
set_type(node_index: number, type: number): void;
|
|
86
|
-
set_flags(node_index: number, flags: number): void;
|
|
87
|
-
set_start_offset(node_index: number, offset: number): void;
|
|
88
|
-
set_length(node_index: number, length: number): void;
|
|
89
|
-
set_content_start(node_index: number, offset: number): void;
|
|
90
|
-
set_content_length(node_index: number, length: number): void;
|
|
91
|
-
set_attr_operator(node_index: number, operator: number): void;
|
|
92
|
-
set_attr_flags(node_index: number, flags: number): void;
|
|
93
|
-
set_first_child(node_index: number, childIndex: number): void;
|
|
94
|
-
set_last_child(node_index: number, childIndex: number): void;
|
|
95
|
-
set_next_sibling(node_index: number, siblingIndex: number): void;
|
|
96
|
-
set_start_line(node_index: number, line: number): void;
|
|
97
|
-
set_start_column(node_index: number, column: number): void;
|
|
98
|
-
set_value_start(node_index: number, offset: number): void;
|
|
99
|
-
set_value_length(node_index: number, length: number): void;
|
|
100
|
-
private grow;
|
|
101
|
-
create_node(): number;
|
|
102
|
-
append_child(parentIndex: number, childIndex: number): void;
|
|
103
|
-
has_children(node_index: number): boolean;
|
|
104
|
-
has_next_sibling(node_index: number): boolean;
|
|
105
|
-
set_flag(node_index: number, flag: number): void;
|
|
106
|
-
clear_flag(node_index: number, flag: number): void;
|
|
107
|
-
has_flag(node_index: number, flag: number): boolean;
|
|
108
|
-
}
|
package/dist/arena.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
let BYTES_PER_NODE = 40;
|
|
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 SELECTOR_LIST = 20;
|
|
19
|
+
const TYPE_SELECTOR = 21;
|
|
20
|
+
const CLASS_SELECTOR = 22;
|
|
21
|
+
const ID_SELECTOR = 23;
|
|
22
|
+
const ATTRIBUTE_SELECTOR = 24;
|
|
23
|
+
const PSEUDO_CLASS_SELECTOR = 25;
|
|
24
|
+
const PSEUDO_ELEMENT_SELECTOR = 26;
|
|
25
|
+
const COMBINATOR = 27;
|
|
26
|
+
const UNIVERSAL_SELECTOR = 28;
|
|
27
|
+
const NESTING_SELECTOR = 29;
|
|
28
|
+
const NTH_SELECTOR = 30;
|
|
29
|
+
const NTH_OF_SELECTOR = 31;
|
|
30
|
+
const LANG_SELECTOR = 56;
|
|
31
|
+
const MEDIA_QUERY = 32;
|
|
32
|
+
const MEDIA_FEATURE = 33;
|
|
33
|
+
const MEDIA_TYPE = 34;
|
|
34
|
+
const CONTAINER_QUERY = 35;
|
|
35
|
+
const SUPPORTS_QUERY = 36;
|
|
36
|
+
const LAYER_NAME = 37;
|
|
37
|
+
const PRELUDE_OPERATOR = 38;
|
|
38
|
+
const FLAG_IMPORTANT = 1 << 0;
|
|
39
|
+
const FLAG_HAS_ERROR = 1 << 1;
|
|
40
|
+
const FLAG_HAS_BLOCK = 1 << 3;
|
|
41
|
+
const FLAG_VENDOR_PREFIXED = 1 << 4;
|
|
42
|
+
const FLAG_HAS_DECLARATIONS = 1 << 5;
|
|
43
|
+
const FLAG_HAS_PARENS = 1 << 6;
|
|
44
|
+
const ATTR_OPERATOR_NONE = 0;
|
|
45
|
+
const ATTR_OPERATOR_EQUAL = 1;
|
|
46
|
+
const ATTR_OPERATOR_TILDE_EQUAL = 2;
|
|
47
|
+
const ATTR_OPERATOR_PIPE_EQUAL = 3;
|
|
48
|
+
const ATTR_OPERATOR_CARET_EQUAL = 4;
|
|
49
|
+
const ATTR_OPERATOR_DOLLAR_EQUAL = 5;
|
|
50
|
+
const ATTR_OPERATOR_STAR_EQUAL = 6;
|
|
51
|
+
const ATTR_FLAG_NONE = 0;
|
|
52
|
+
const ATTR_FLAG_CASE_INSENSITIVE = 1;
|
|
53
|
+
const ATTR_FLAG_CASE_SENSITIVE = 2;
|
|
54
|
+
class CSSDataArena {
|
|
55
|
+
buffer;
|
|
56
|
+
view;
|
|
57
|
+
capacity;
|
|
58
|
+
// Number of nodes that can fit
|
|
59
|
+
count;
|
|
60
|
+
// Number of nodes currently allocated
|
|
61
|
+
// Growth multiplier when capacity is exceeded
|
|
62
|
+
static GROWTH_FACTOR = 1.3;
|
|
63
|
+
// Estimated nodes per KB of CSS (based on real-world data)
|
|
64
|
+
static NODES_PER_KB = 60;
|
|
65
|
+
// Buffer to avoid frequent growth (15%)
|
|
66
|
+
static CAPACITY_BUFFER = 1.15;
|
|
67
|
+
constructor(initial_capacity = 1024) {
|
|
68
|
+
this.capacity = initial_capacity;
|
|
69
|
+
this.count = 1;
|
|
70
|
+
this.buffer = new ArrayBuffer(initial_capacity * BYTES_PER_NODE);
|
|
71
|
+
this.view = new DataView(this.buffer);
|
|
72
|
+
}
|
|
73
|
+
// Calculate recommended initial capacity based on CSS source size
|
|
74
|
+
static capacity_for_source(source_length) {
|
|
75
|
+
let size_in_kb = source_length / 1024;
|
|
76
|
+
let estimated_nodes = Math.ceil(size_in_kb * CSSDataArena.NODES_PER_KB);
|
|
77
|
+
let capacity = Math.ceil(estimated_nodes * CSSDataArena.CAPACITY_BUFFER);
|
|
78
|
+
return Math.max(16, capacity);
|
|
79
|
+
}
|
|
80
|
+
// Get the number of nodes currently in the arena
|
|
81
|
+
get_count() {
|
|
82
|
+
return this.count;
|
|
83
|
+
}
|
|
84
|
+
// Get the capacity (max nodes without reallocation)
|
|
85
|
+
get_capacity() {
|
|
86
|
+
return this.capacity;
|
|
87
|
+
}
|
|
88
|
+
// Calculate byte offset for a node
|
|
89
|
+
node_offset(node_index) {
|
|
90
|
+
return node_index * BYTES_PER_NODE;
|
|
91
|
+
}
|
|
92
|
+
// Read node type
|
|
93
|
+
get_type(node_index) {
|
|
94
|
+
return this.view.getUint8(this.node_offset(node_index));
|
|
95
|
+
}
|
|
96
|
+
// Read node flags
|
|
97
|
+
get_flags(node_index) {
|
|
98
|
+
return this.view.getUint8(this.node_offset(node_index) + 1);
|
|
99
|
+
}
|
|
100
|
+
// Read start offset in source
|
|
101
|
+
get_start_offset(node_index) {
|
|
102
|
+
return this.view.getUint32(this.node_offset(node_index) + 4, true);
|
|
103
|
+
}
|
|
104
|
+
// Read length in source
|
|
105
|
+
get_length(node_index) {
|
|
106
|
+
return this.view.getUint16(this.node_offset(node_index) + 8, true);
|
|
107
|
+
}
|
|
108
|
+
// Read content start offset (stored as delta from startOffset)
|
|
109
|
+
get_content_start(node_index) {
|
|
110
|
+
const startOffset = this.get_start_offset(node_index);
|
|
111
|
+
const delta = this.view.getUint16(this.node_offset(node_index) + 12, true);
|
|
112
|
+
return startOffset + delta;
|
|
113
|
+
}
|
|
114
|
+
// Read content length
|
|
115
|
+
get_content_length(node_index) {
|
|
116
|
+
return this.view.getUint16(this.node_offset(node_index) + 14, true);
|
|
117
|
+
}
|
|
118
|
+
// Read attribute operator (for NODE_SELECTOR_ATTRIBUTE)
|
|
119
|
+
get_attr_operator(node_index) {
|
|
120
|
+
return this.view.getUint8(this.node_offset(node_index) + 2);
|
|
121
|
+
}
|
|
122
|
+
// Read attribute flags (for NODE_SELECTOR_ATTRIBUTE)
|
|
123
|
+
get_attr_flags(node_index) {
|
|
124
|
+
return this.view.getUint8(this.node_offset(node_index) + 3);
|
|
125
|
+
}
|
|
126
|
+
// Read first child index (0 = no children)
|
|
127
|
+
get_first_child(node_index) {
|
|
128
|
+
return this.view.getUint32(this.node_offset(node_index) + 20, true);
|
|
129
|
+
}
|
|
130
|
+
// Read last child index (0 = no children)
|
|
131
|
+
get_last_child(node_index) {
|
|
132
|
+
return this.view.getUint32(this.node_offset(node_index) + 24, true);
|
|
133
|
+
}
|
|
134
|
+
// Read next sibling index (0 = no sibling)
|
|
135
|
+
get_next_sibling(node_index) {
|
|
136
|
+
return this.view.getUint32(this.node_offset(node_index) + 28, true);
|
|
137
|
+
}
|
|
138
|
+
// Read start line
|
|
139
|
+
get_start_line(node_index) {
|
|
140
|
+
return this.view.getUint32(this.node_offset(node_index) + 32, true);
|
|
141
|
+
}
|
|
142
|
+
// Read start column
|
|
143
|
+
get_start_column(node_index) {
|
|
144
|
+
return this.view.getUint16(this.node_offset(node_index) + 36, true);
|
|
145
|
+
}
|
|
146
|
+
// Read value start offset (stored as delta from startOffset, declaration value / at-rule prelude)
|
|
147
|
+
get_value_start(node_index) {
|
|
148
|
+
const startOffset = this.get_start_offset(node_index);
|
|
149
|
+
const delta = this.view.getUint16(this.node_offset(node_index) + 16, true);
|
|
150
|
+
return startOffset + delta;
|
|
151
|
+
}
|
|
152
|
+
// Read value length
|
|
153
|
+
get_value_length(node_index) {
|
|
154
|
+
return this.view.getUint16(this.node_offset(node_index) + 18, true);
|
|
155
|
+
}
|
|
156
|
+
// --- Write Methods ---
|
|
157
|
+
// Write node type
|
|
158
|
+
set_type(node_index, type) {
|
|
159
|
+
this.view.setUint8(this.node_offset(node_index), type);
|
|
160
|
+
}
|
|
161
|
+
// Write node flags
|
|
162
|
+
set_flags(node_index, flags) {
|
|
163
|
+
this.view.setUint8(this.node_offset(node_index) + 1, flags);
|
|
164
|
+
}
|
|
165
|
+
// Write start offset in source
|
|
166
|
+
set_start_offset(node_index, offset) {
|
|
167
|
+
this.view.setUint32(this.node_offset(node_index) + 4, offset, true);
|
|
168
|
+
}
|
|
169
|
+
// Write length in source
|
|
170
|
+
set_length(node_index, length) {
|
|
171
|
+
this.view.setUint16(this.node_offset(node_index) + 8, length, true);
|
|
172
|
+
}
|
|
173
|
+
// Write content start delta (offset from startOffset)
|
|
174
|
+
set_content_start_delta(node_index, delta) {
|
|
175
|
+
this.view.setUint16(this.node_offset(node_index) + 12, delta, true);
|
|
176
|
+
}
|
|
177
|
+
// Write content length
|
|
178
|
+
set_content_length(node_index, length) {
|
|
179
|
+
this.view.setUint16(this.node_offset(node_index) + 14, length, true);
|
|
180
|
+
}
|
|
181
|
+
// Write attribute operator (for NODE_SELECTOR_ATTRIBUTE)
|
|
182
|
+
set_attr_operator(node_index, operator) {
|
|
183
|
+
this.view.setUint8(this.node_offset(node_index) + 2, operator);
|
|
184
|
+
}
|
|
185
|
+
// Write attribute flags (for NODE_SELECTOR_ATTRIBUTE)
|
|
186
|
+
set_attr_flags(node_index, flags) {
|
|
187
|
+
this.view.setUint8(this.node_offset(node_index) + 3, flags);
|
|
188
|
+
}
|
|
189
|
+
// Write first child index
|
|
190
|
+
set_first_child(node_index, childIndex) {
|
|
191
|
+
this.view.setUint32(this.node_offset(node_index) + 20, childIndex, true);
|
|
192
|
+
}
|
|
193
|
+
// Write last child index
|
|
194
|
+
set_last_child(node_index, childIndex) {
|
|
195
|
+
this.view.setUint32(this.node_offset(node_index) + 24, childIndex, true);
|
|
196
|
+
}
|
|
197
|
+
// Write next sibling index
|
|
198
|
+
set_next_sibling(node_index, siblingIndex) {
|
|
199
|
+
this.view.setUint32(this.node_offset(node_index) + 28, siblingIndex, true);
|
|
200
|
+
}
|
|
201
|
+
// Write start line
|
|
202
|
+
set_start_line(node_index, line) {
|
|
203
|
+
this.view.setUint32(this.node_offset(node_index) + 32, line, true);
|
|
204
|
+
}
|
|
205
|
+
// Write start column
|
|
206
|
+
set_start_column(node_index, column) {
|
|
207
|
+
this.view.setUint16(this.node_offset(node_index) + 36, column, true);
|
|
208
|
+
}
|
|
209
|
+
// Write value start delta (offset from startOffset, declaration value / at-rule prelude)
|
|
210
|
+
set_value_start_delta(node_index, delta) {
|
|
211
|
+
this.view.setUint16(this.node_offset(node_index) + 16, delta, true);
|
|
212
|
+
}
|
|
213
|
+
// Write value length
|
|
214
|
+
set_value_length(node_index, length) {
|
|
215
|
+
this.view.setUint16(this.node_offset(node_index) + 18, length, true);
|
|
216
|
+
}
|
|
217
|
+
// --- Node Creation ---
|
|
218
|
+
// Grow the arena by 1.3x when capacity is exceeded
|
|
219
|
+
grow() {
|
|
220
|
+
let new_capacity = Math.ceil(this.capacity * CSSDataArena.GROWTH_FACTOR);
|
|
221
|
+
let new_buffer = new ArrayBuffer(new_capacity * BYTES_PER_NODE);
|
|
222
|
+
new Uint8Array(new_buffer).set(new Uint8Array(this.buffer));
|
|
223
|
+
this.buffer = new_buffer;
|
|
224
|
+
this.view = new DataView(new_buffer);
|
|
225
|
+
this.capacity = new_capacity;
|
|
226
|
+
}
|
|
227
|
+
// Allocate and initialize a new node with core properties
|
|
228
|
+
// Automatically grows the arena if capacity is exceeded
|
|
229
|
+
create_node(type, start_offset, length, start_line, start_column) {
|
|
230
|
+
if (this.count >= this.capacity) {
|
|
231
|
+
this.grow();
|
|
232
|
+
}
|
|
233
|
+
const node_index = this.count;
|
|
234
|
+
this.count++;
|
|
235
|
+
const offset = node_index * BYTES_PER_NODE;
|
|
236
|
+
this.view.setUint8(offset, type);
|
|
237
|
+
this.view.setUint32(offset + 4, start_offset, true);
|
|
238
|
+
this.view.setUint16(offset + 8, length, true);
|
|
239
|
+
this.view.setUint32(offset + 32, start_line, true);
|
|
240
|
+
this.view.setUint16(offset + 36, start_column, true);
|
|
241
|
+
return node_index;
|
|
242
|
+
}
|
|
243
|
+
// --- Tree Building Helpers ---
|
|
244
|
+
// Link multiple child nodes to a parent
|
|
245
|
+
// Children are linked as siblings in the order provided
|
|
246
|
+
append_children(parent_index, children) {
|
|
247
|
+
if (children.length === 0) return;
|
|
248
|
+
const offset = this.node_offset(parent_index);
|
|
249
|
+
this.view.setUint32(offset + 20, children[0], true);
|
|
250
|
+
this.view.setUint32(offset + 24, children[children.length - 1], true);
|
|
251
|
+
for (let i = 0; i < children.length - 1; i++) {
|
|
252
|
+
this.set_next_sibling(children[i], children[i + 1]);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// Check if a node has any children
|
|
256
|
+
has_children(node_index) {
|
|
257
|
+
return this.get_first_child(node_index) !== 0;
|
|
258
|
+
}
|
|
259
|
+
// Check if a node has a next sibling
|
|
260
|
+
has_next_sibling(node_index) {
|
|
261
|
+
return this.get_next_sibling(node_index) !== 0;
|
|
262
|
+
}
|
|
263
|
+
// --- Flag Management Helpers ---
|
|
264
|
+
// Set a specific flag bit (doesn't clear other flags)
|
|
265
|
+
set_flag(node_index, flag) {
|
|
266
|
+
let current_flags = this.get_flags(node_index);
|
|
267
|
+
this.set_flags(node_index, current_flags | flag);
|
|
268
|
+
}
|
|
269
|
+
// Clear a specific flag bit (doesn't affect other flags)
|
|
270
|
+
clear_flag(node_index, flag) {
|
|
271
|
+
let current_flags = this.get_flags(node_index);
|
|
272
|
+
this.set_flags(node_index, current_flags & ~flag);
|
|
273
|
+
}
|
|
274
|
+
// Check if a specific flag is set
|
|
275
|
+
has_flag(node_index, flag) {
|
|
276
|
+
return (this.get_flags(node_index) & flag) !== 0;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
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, BLOCK, CLASS_SELECTOR, COMBINATOR, COMMENT, CONTAINER_QUERY, CSSDataArena, DECLARATION, DIMENSION, FLAG_HAS_BLOCK, FLAG_HAS_DECLARATIONS, FLAG_HAS_ERROR, FLAG_HAS_PARENS, FLAG_IMPORTANT, FLAG_VENDOR_PREFIXED, 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, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, SELECTOR, SELECTOR_LIST, STRING, STYLESHEET, STYLE_RULE, SUPPORTS_QUERY, TYPE_SELECTOR, UNIVERSAL_SELECTOR, URL };
|
|
@@ -0,0 +1,55 @@
|
|
|
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_types = new Uint8Array(128);
|
|
7
|
+
for (let i = 48; i <= 57; i++) {
|
|
8
|
+
char_types[i] = CHAR_DIGIT;
|
|
9
|
+
}
|
|
10
|
+
for (let i = 48; i <= 57; i++) {
|
|
11
|
+
char_types[i] |= CHAR_HEX;
|
|
12
|
+
}
|
|
13
|
+
for (let i = 65; i <= 70; i++) {
|
|
14
|
+
char_types[i] = CHAR_HEX;
|
|
15
|
+
}
|
|
16
|
+
for (let i = 97; i <= 102; i++) {
|
|
17
|
+
char_types[i] = CHAR_HEX;
|
|
18
|
+
}
|
|
19
|
+
for (let i = 65; i <= 90; i++) {
|
|
20
|
+
char_types[i] |= CHAR_ALPHA;
|
|
21
|
+
}
|
|
22
|
+
for (let i = 97; i <= 122; i++) {
|
|
23
|
+
char_types[i] |= CHAR_ALPHA;
|
|
24
|
+
}
|
|
25
|
+
char_types[32] = CHAR_WHITESPACE;
|
|
26
|
+
char_types[9] = CHAR_WHITESPACE;
|
|
27
|
+
char_types[10] = CHAR_NEWLINE;
|
|
28
|
+
char_types[13] = CHAR_NEWLINE;
|
|
29
|
+
char_types[12] = CHAR_NEWLINE;
|
|
30
|
+
function is_digit(ch) {
|
|
31
|
+
return ch < 128 && (char_types[ch] & CHAR_DIGIT) !== 0;
|
|
32
|
+
}
|
|
33
|
+
function is_hex_digit(ch) {
|
|
34
|
+
return ch < 128 && (char_types[ch] & CHAR_HEX) !== 0;
|
|
35
|
+
}
|
|
36
|
+
function is_alpha(ch) {
|
|
37
|
+
return ch < 128 && (char_types[ch] & CHAR_ALPHA) !== 0;
|
|
38
|
+
}
|
|
39
|
+
function is_whitespace(ch) {
|
|
40
|
+
return ch < 128 && (char_types[ch] & CHAR_WHITESPACE) !== 0;
|
|
41
|
+
}
|
|
42
|
+
function is_newline(ch) {
|
|
43
|
+
return ch < 128 && (char_types[ch] & CHAR_NEWLINE) !== 0;
|
|
44
|
+
}
|
|
45
|
+
function is_ident_start(ch) {
|
|
46
|
+
if (ch >= 128) return true;
|
|
47
|
+
if (ch === 95) return true;
|
|
48
|
+
return is_alpha(ch);
|
|
49
|
+
}
|
|
50
|
+
function is_ident_char(ch) {
|
|
51
|
+
if (ch === 45) return true;
|
|
52
|
+
return is_ident_start(ch) || is_digit(ch);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { is_alpha, is_digit, is_hex_digit, is_ident_char, is_ident_start, is_newline, is_whitespace };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { STYLESHEET, STYLE_RULE, AT_RULE, DECLARATION, SELECTOR, COMMENT, BLOCK, IDENTIFIER, NUMBER, DIMENSION, STRING, HASH, FUNCTION, OPERATOR, PARENTHESIS, URL, 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, 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';
|
package/dist/css-node.d.ts
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
import type { CSSDataArena } from './arena';
|
|
2
|
-
import {
|
|
3
|
-
export declare const TYPE_NAMES:
|
|
4
|
-
|
|
2
|
+
import { STYLESHEET, STYLE_RULE, AT_RULE, DECLARATION, SELECTOR, COMMENT, BLOCK, IDENTIFIER, NUMBER, DIMENSION, STRING, HASH, FUNCTION, OPERATOR, PARENTHESIS, URL, 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 } 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 20: "SelectorList";
|
|
21
|
+
readonly 21: "TypeSelector";
|
|
22
|
+
readonly 22: "ClassSelector";
|
|
23
|
+
readonly 23: "IdSelector";
|
|
24
|
+
readonly 24: "AttributeSelector";
|
|
25
|
+
readonly 25: "PseudoClassSelector";
|
|
26
|
+
readonly 26: "PseudoElementSelector";
|
|
27
|
+
readonly 27: "Combinator";
|
|
28
|
+
readonly 28: "UniversalSelector";
|
|
29
|
+
readonly 29: "NestingSelector";
|
|
30
|
+
readonly 30: "Nth";
|
|
31
|
+
readonly 31: "NthOf";
|
|
32
|
+
readonly 56: "Lang";
|
|
33
|
+
readonly 32: "MediaQuery";
|
|
34
|
+
readonly 33: "Feature";
|
|
35
|
+
readonly 34: "MediaType";
|
|
36
|
+
readonly 35: "ContainerQuery";
|
|
37
|
+
readonly 36: "SupportsQuery";
|
|
38
|
+
readonly 37: "Layer";
|
|
39
|
+
readonly 38: "Operator";
|
|
40
|
+
};
|
|
41
|
+
export type TypeName = (typeof TYPE_NAMES)[keyof typeof TYPE_NAMES] | 'unknown';
|
|
42
|
+
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 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;
|
|
5
43
|
export interface CloneOptions {
|
|
6
44
|
/**
|
|
7
45
|
* Recursively clone all children
|
|
@@ -16,7 +54,7 @@ export interface CloneOptions {
|
|
|
16
54
|
}
|
|
17
55
|
export type PlainCSSNode = {
|
|
18
56
|
type: number;
|
|
19
|
-
type_name:
|
|
57
|
+
type_name: TypeName;
|
|
20
58
|
text: string;
|
|
21
59
|
children: PlainCSSNode[];
|
|
22
60
|
name?: string;
|
|
@@ -43,7 +81,7 @@ export declare class CSSNode {
|
|
|
43
81
|
constructor(arena: CSSDataArena, source: string, index: number);
|
|
44
82
|
get_index(): number;
|
|
45
83
|
get type(): CSSNodeType;
|
|
46
|
-
get type_name():
|
|
84
|
+
get type_name(): TypeName;
|
|
47
85
|
get text(): string;
|
|
48
86
|
get name(): string;
|
|
49
87
|
get property(): string;
|