@projectwallace/css-parser 0.8.4 → 0.8.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.
- package/dist/arena.js +36 -24
- package/dist/css-node.d.ts +4 -15
- package/dist/css-node.js +6 -15
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/parse-anplusb.js +1 -1
- package/dist/parse-atrule-prelude.js +1 -1
- package/dist/parse-declaration.js +1 -1
- package/dist/parse-selector.js +1 -1
- package/dist/parse-value.js +1 -1
- package/dist/parse.js +1 -1
- package/dist/string-utils.d.ts +14 -0
- package/dist/string-utils.js +5 -1
- package/dist/tokenize.d.ts +11 -1
- package/dist/tokenize.js +429 -3
- package/dist/walk.d.ts +5 -52
- package/dist/walk.js +2 -2
- package/package.json +8 -2
- package/dist/lexer.d.ts +0 -11
- package/dist/lexer.js +0 -431
package/dist/arena.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
let BYTES_PER_NODE =
|
|
1
|
+
let BYTES_PER_NODE = 36;
|
|
2
2
|
const STYLESHEET = 1;
|
|
3
3
|
const STYLE_RULE = 2;
|
|
4
4
|
const AT_RULE = 3;
|
|
@@ -37,6 +37,7 @@ const LAYER_NAME = 37;
|
|
|
37
37
|
const PRELUDE_OPERATOR = 38;
|
|
38
38
|
const FLAG_IMPORTANT = 1 << 0;
|
|
39
39
|
const FLAG_HAS_ERROR = 1 << 1;
|
|
40
|
+
const FLAG_LENGTH_OVERFLOW = 1 << 2;
|
|
40
41
|
const FLAG_HAS_BLOCK = 1 << 3;
|
|
41
42
|
const FLAG_HAS_DECLARATIONS = 1 << 5;
|
|
42
43
|
const FLAG_HAS_PARENS = 1 << 6;
|
|
@@ -57,17 +58,23 @@ class CSSDataArena {
|
|
|
57
58
|
// Number of nodes that can fit
|
|
58
59
|
count;
|
|
59
60
|
// Number of nodes currently allocated
|
|
61
|
+
growth_count;
|
|
62
|
+
// Number of times the arena has grown
|
|
63
|
+
overflow_lengths;
|
|
64
|
+
// Stores actual lengths for nodes > 65535 chars
|
|
60
65
|
// Growth multiplier when capacity is exceeded
|
|
61
66
|
static GROWTH_FACTOR = 1.3;
|
|
62
67
|
// Estimated nodes per KB of CSS (based on real-world data)
|
|
63
|
-
static NODES_PER_KB =
|
|
68
|
+
static NODES_PER_KB = 270;
|
|
64
69
|
// Buffer to avoid frequent growth (15%)
|
|
65
|
-
static CAPACITY_BUFFER = 1.
|
|
70
|
+
static CAPACITY_BUFFER = 1.2;
|
|
66
71
|
constructor(initial_capacity = 1024) {
|
|
67
72
|
this.capacity = initial_capacity;
|
|
68
73
|
this.count = 1;
|
|
74
|
+
this.growth_count = 0;
|
|
69
75
|
this.buffer = new ArrayBuffer(initial_capacity * BYTES_PER_NODE);
|
|
70
76
|
this.view = new DataView(this.buffer);
|
|
77
|
+
this.overflow_lengths = /* @__PURE__ */ new Map();
|
|
71
78
|
}
|
|
72
79
|
// Calculate recommended initial capacity based on CSS source size
|
|
73
80
|
static capacity_for_source(source_length) {
|
|
@@ -84,6 +91,10 @@ class CSSDataArena {
|
|
|
84
91
|
get_capacity() {
|
|
85
92
|
return this.capacity;
|
|
86
93
|
}
|
|
94
|
+
// Get the number of times the arena has grown
|
|
95
|
+
get_growth_count() {
|
|
96
|
+
return this.growth_count;
|
|
97
|
+
}
|
|
87
98
|
// Calculate byte offset for a node
|
|
88
99
|
node_offset(node_index) {
|
|
89
100
|
return node_index * BYTES_PER_NODE;
|
|
@@ -102,6 +113,12 @@ class CSSDataArena {
|
|
|
102
113
|
}
|
|
103
114
|
// Read length in source
|
|
104
115
|
get_length(node_index) {
|
|
116
|
+
if (this.has_flag(node_index, FLAG_LENGTH_OVERFLOW)) {
|
|
117
|
+
const overflow_length = this.overflow_lengths.get(node_index);
|
|
118
|
+
if (overflow_length !== void 0) {
|
|
119
|
+
return overflow_length;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
105
122
|
return this.view.getUint16(this.node_offset(node_index) + 2, true);
|
|
106
123
|
}
|
|
107
124
|
// Read content start offset (stored as delta from startOffset)
|
|
@@ -116,11 +133,11 @@ class CSSDataArena {
|
|
|
116
133
|
}
|
|
117
134
|
// Read attribute operator (for NODE_SELECTOR_ATTRIBUTE)
|
|
118
135
|
get_attr_operator(node_index) {
|
|
119
|
-
return this.view.getUint8(this.node_offset(node_index) +
|
|
136
|
+
return this.view.getUint8(this.node_offset(node_index) + 32);
|
|
120
137
|
}
|
|
121
138
|
// Read attribute flags (for NODE_SELECTOR_ATTRIBUTE)
|
|
122
139
|
get_attr_flags(node_index) {
|
|
123
|
-
return this.view.getUint8(this.node_offset(node_index) +
|
|
140
|
+
return this.view.getUint8(this.node_offset(node_index) + 33);
|
|
124
141
|
}
|
|
125
142
|
// Read first child index (0 = no children)
|
|
126
143
|
get_first_child(node_index) {
|
|
@@ -136,7 +153,7 @@ class CSSDataArena {
|
|
|
136
153
|
}
|
|
137
154
|
// Read start column
|
|
138
155
|
get_start_column(node_index) {
|
|
139
|
-
return this.view.
|
|
156
|
+
return this.view.getUint32(this.node_offset(node_index) + 28, true);
|
|
140
157
|
}
|
|
141
158
|
// Read value start offset (stored as delta from startOffset, declaration value / at-rule prelude)
|
|
142
159
|
get_value_start(node_index) {
|
|
@@ -157,13 +174,15 @@ class CSSDataArena {
|
|
|
157
174
|
set_flags(node_index, flags) {
|
|
158
175
|
this.view.setUint8(this.node_offset(node_index) + 1, flags);
|
|
159
176
|
}
|
|
160
|
-
// Write start offset in source
|
|
161
|
-
set_start_offset(node_index, offset) {
|
|
162
|
-
this.view.setUint32(this.node_offset(node_index) + 12, offset, true);
|
|
163
|
-
}
|
|
164
177
|
// Write length in source
|
|
165
178
|
set_length(node_index, length) {
|
|
166
|
-
|
|
179
|
+
if (length > 65535) {
|
|
180
|
+
this.view.setUint16(this.node_offset(node_index) + 2, 65535, true);
|
|
181
|
+
this.set_flag(node_index, FLAG_LENGTH_OVERFLOW);
|
|
182
|
+
this.overflow_lengths.set(node_index, length);
|
|
183
|
+
} else {
|
|
184
|
+
this.view.setUint16(this.node_offset(node_index) + 2, length, true);
|
|
185
|
+
}
|
|
167
186
|
}
|
|
168
187
|
// Write content start delta (offset from startOffset)
|
|
169
188
|
set_content_start_delta(node_index, delta) {
|
|
@@ -175,11 +194,11 @@ class CSSDataArena {
|
|
|
175
194
|
}
|
|
176
195
|
// Write attribute operator (for NODE_SELECTOR_ATTRIBUTE)
|
|
177
196
|
set_attr_operator(node_index, operator) {
|
|
178
|
-
this.view.setUint8(this.node_offset(node_index) +
|
|
197
|
+
this.view.setUint8(this.node_offset(node_index) + 32, operator);
|
|
179
198
|
}
|
|
180
199
|
// Write attribute flags (for NODE_SELECTOR_ATTRIBUTE)
|
|
181
200
|
set_attr_flags(node_index, flags) {
|
|
182
|
-
this.view.setUint8(this.node_offset(node_index) +
|
|
201
|
+
this.view.setUint8(this.node_offset(node_index) + 33, flags);
|
|
183
202
|
}
|
|
184
203
|
// Write first child index
|
|
185
204
|
set_first_child(node_index, childIndex) {
|
|
@@ -189,14 +208,6 @@ class CSSDataArena {
|
|
|
189
208
|
set_next_sibling(node_index, siblingIndex) {
|
|
190
209
|
this.view.setUint32(this.node_offset(node_index) + 8, siblingIndex, true);
|
|
191
210
|
}
|
|
192
|
-
// Write start line
|
|
193
|
-
set_start_line(node_index, line) {
|
|
194
|
-
this.view.setUint32(this.node_offset(node_index) + 24, line, true);
|
|
195
|
-
}
|
|
196
|
-
// Write start column
|
|
197
|
-
set_start_column(node_index, column) {
|
|
198
|
-
this.view.setUint16(this.node_offset(node_index) + 28, column, true);
|
|
199
|
-
}
|
|
200
211
|
// Write value start delta (offset from startOffset, declaration value / at-rule prelude)
|
|
201
212
|
set_value_start_delta(node_index, delta) {
|
|
202
213
|
this.view.setUint16(this.node_offset(node_index) + 18, delta, true);
|
|
@@ -208,6 +219,7 @@ class CSSDataArena {
|
|
|
208
219
|
// --- Node Creation ---
|
|
209
220
|
// Grow the arena by 1.3x when capacity is exceeded
|
|
210
221
|
grow() {
|
|
222
|
+
this.growth_count++;
|
|
211
223
|
let new_capacity = Math.ceil(this.capacity * CSSDataArena.GROWTH_FACTOR);
|
|
212
224
|
let new_buffer = new ArrayBuffer(new_capacity * BYTES_PER_NODE);
|
|
213
225
|
new Uint8Array(new_buffer).set(new Uint8Array(this.buffer));
|
|
@@ -225,10 +237,10 @@ class CSSDataArena {
|
|
|
225
237
|
this.count++;
|
|
226
238
|
const offset = node_index * BYTES_PER_NODE;
|
|
227
239
|
this.view.setUint8(offset, type);
|
|
228
|
-
this.view.setUint16(offset + 2, length, true);
|
|
229
240
|
this.view.setUint32(offset + 12, start_offset, true);
|
|
230
241
|
this.view.setUint32(offset + 24, start_line, true);
|
|
231
|
-
this.view.
|
|
242
|
+
this.view.setUint32(offset + 28, start_column, true);
|
|
243
|
+
this.set_length(node_index, length);
|
|
232
244
|
return node_index;
|
|
233
245
|
}
|
|
234
246
|
// --- Tree Building Helpers ---
|
|
@@ -267,4 +279,4 @@ class CSSDataArena {
|
|
|
267
279
|
}
|
|
268
280
|
}
|
|
269
281
|
|
|
270
|
-
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, 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 };
|
|
282
|
+
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_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, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, SELECTOR, SELECTOR_LIST, STRING, STYLESHEET, STYLE_RULE, SUPPORTS_QUERY, TYPE_SELECTOR, UNIVERSAL_SELECTOR, URL };
|
package/dist/css-node.d.ts
CHANGED
|
@@ -80,6 +80,8 @@ export declare class CSSNode {
|
|
|
80
80
|
private source;
|
|
81
81
|
private index;
|
|
82
82
|
constructor(arena: CSSDataArena, source: string, index: number);
|
|
83
|
+
/** Get the arena (for internal/advanced use only) */
|
|
84
|
+
__get_arena(): CSSDataArena;
|
|
83
85
|
/** Get node type as number (for performance) */
|
|
84
86
|
get type(): CSSNodeType;
|
|
85
87
|
/** Get node type as human-readable string */
|
|
@@ -200,25 +202,12 @@ export declare class CSSNode {
|
|
|
200
202
|
/** Get text of first compound selector (no node allocation) */
|
|
201
203
|
get first_compound_text(): string;
|
|
202
204
|
/**
|
|
203
|
-
* Clone this node as a mutable plain JavaScript object
|
|
204
|
-
*
|
|
205
|
-
* Extracts all properties from the arena into a plain object with children as an array.
|
|
206
|
-
* The resulting object can be freely modified.
|
|
205
|
+
* Clone this node as a mutable plain JavaScript object with children as arrays.
|
|
206
|
+
* See API.md for examples.
|
|
207
207
|
*
|
|
208
208
|
* @param options - Cloning configuration
|
|
209
209
|
* @param options.deep - Recursively clone children (default: true)
|
|
210
210
|
* @param options.locations - Include line/column/start/length (default: false)
|
|
211
|
-
* @returns Plain object with children as array
|
|
212
|
-
*
|
|
213
|
-
* @example
|
|
214
|
-
* const ast = parse('div { color: red; }')
|
|
215
|
-
* const decl = ast.first_child.block.first_child
|
|
216
|
-
* const plain = decl.clone()
|
|
217
|
-
*
|
|
218
|
-
* // Access children as array
|
|
219
|
-
* plain.children.length
|
|
220
|
-
* plain.children[0]
|
|
221
|
-
* plain.children.push(newChild)
|
|
222
211
|
*/
|
|
223
212
|
clone(options?: CloneOptions): PlainCSSNode;
|
|
224
213
|
}
|
package/dist/css-node.js
CHANGED
|
@@ -49,6 +49,10 @@ class CSSNode {
|
|
|
49
49
|
this.source = source;
|
|
50
50
|
this.index = index;
|
|
51
51
|
}
|
|
52
|
+
/** Get the arena (for internal/advanced use only) */
|
|
53
|
+
__get_arena() {
|
|
54
|
+
return this.arena;
|
|
55
|
+
}
|
|
52
56
|
/** Get node type as number (for performance) */
|
|
53
57
|
get type() {
|
|
54
58
|
return this.arena.get_type(this.index);
|
|
@@ -450,25 +454,12 @@ class CSSNode {
|
|
|
450
454
|
}
|
|
451
455
|
// --- Node Cloning ---
|
|
452
456
|
/**
|
|
453
|
-
* Clone this node as a mutable plain JavaScript object
|
|
454
|
-
*
|
|
455
|
-
* Extracts all properties from the arena into a plain object with children as an array.
|
|
456
|
-
* The resulting object can be freely modified.
|
|
457
|
+
* Clone this node as a mutable plain JavaScript object with children as arrays.
|
|
458
|
+
* See API.md for examples.
|
|
457
459
|
*
|
|
458
460
|
* @param options - Cloning configuration
|
|
459
461
|
* @param options.deep - Recursively clone children (default: true)
|
|
460
462
|
* @param options.locations - Include line/column/start/length (default: false)
|
|
461
|
-
* @returns Plain object with children as array
|
|
462
|
-
*
|
|
463
|
-
* @example
|
|
464
|
-
* const ast = parse('div { color: red; }')
|
|
465
|
-
* const decl = ast.first_child.block.first_child
|
|
466
|
-
* const plain = decl.clone()
|
|
467
|
-
*
|
|
468
|
-
* // Access children as array
|
|
469
|
-
* plain.children.length
|
|
470
|
-
* plain.children[0]
|
|
471
|
-
* plain.children.push(newChild)
|
|
472
463
|
*/
|
|
473
464
|
clone(options = {}) {
|
|
474
465
|
const { deep = true, locations = false } = options;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ export { parse_declaration } from './parse-declaration';
|
|
|
5
5
|
export { parse_value } from './parse-value';
|
|
6
6
|
export { tokenize } from './tokenize';
|
|
7
7
|
export { walk, traverse, SKIP, BREAK } from './walk';
|
|
8
|
+
export { is_custom, is_vendor_prefixed, str_equals, str_starts_with, str_index_of } from './string-utils';
|
|
8
9
|
export { type ParserOptions } from './parse';
|
|
9
10
|
export { CSSNode, type CSSNodeType, TYPE_NAMES, type CloneOptions, type PlainCSSNode } from './css-node';
|
|
10
|
-
export type { LexerPosition } from './
|
|
11
|
+
export type { LexerPosition } from './tokenize';
|
|
11
12
|
export { 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';
|
|
12
13
|
export * from './constants';
|
|
13
14
|
export * from './token-types';
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { parse_declaration } from './parse-declaration.js';
|
|
|
5
5
|
export { parse_value } from './parse-value.js';
|
|
6
6
|
export { tokenize } from './tokenize.js';
|
|
7
7
|
export { BREAK, SKIP, traverse, walk } from './walk.js';
|
|
8
|
+
export { is_custom, is_vendor_prefixed, str_equals, str_index_of, str_starts_with } from './string-utils.js';
|
|
8
9
|
export { CSSNode, TYPE_NAMES } from './css-node.js';
|
|
9
10
|
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, DECLARATION, DIMENSION, FLAG_IMPORTANT, 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 } from './arena.js';
|
|
10
11
|
export { NODE_TYPES } from './constants.js';
|
package/dist/parse-anplusb.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lexer } from './
|
|
1
|
+
import { Lexer } from './tokenize.js';
|
|
2
2
|
import { NTH_SELECTOR, CSSDataArena } from './arena.js';
|
|
3
3
|
import { TOKEN_IDENT, TOKEN_DELIM, TOKEN_DIMENSION, TOKEN_NUMBER } from './token-types.js';
|
|
4
4
|
import { str_equals, CHAR_MINUS_HYPHEN, CHAR_PLUS, str_index_of } from './string-utils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lexer } from './
|
|
1
|
+
import { Lexer } from './tokenize.js';
|
|
2
2
|
import { CSSDataArena, PRELUDE_OPERATOR, MEDIA_TYPE, MEDIA_QUERY, MEDIA_FEATURE, IDENTIFIER, CONTAINER_QUERY, SUPPORTS_QUERY, LAYER_NAME, URL } from './arena.js';
|
|
3
3
|
import { TOKEN_COMMA, TOKEN_IDENT, TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN, TOKEN_WHITESPACE, TOKEN_URL, TOKEN_FUNCTION, TOKEN_STRING, TOKEN_EOF } from './token-types.js';
|
|
4
4
|
import { str_equals } from './string-utils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lexer } from './
|
|
1
|
+
import { Lexer } from './tokenize.js';
|
|
2
2
|
import { CSSDataArena, DECLARATION, FLAG_IMPORTANT } from './arena.js';
|
|
3
3
|
import { ValueParser } from './parse-value.js';
|
|
4
4
|
import { TOKEN_IDENT, TOKEN_COLON, TOKEN_EOF, TOKEN_SEMICOLON, TOKEN_RIGHT_BRACE, TOKEN_LEFT_BRACE, TOKEN_DELIM } from './token-types.js';
|
package/dist/parse-selector.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lexer } from './
|
|
1
|
+
import { Lexer } from './tokenize.js';
|
|
2
2
|
import { CSSDataArena, SELECTOR_LIST, SELECTOR, COMBINATOR, NESTING_SELECTOR, ID_SELECTOR, TYPE_SELECTOR, UNIVERSAL_SELECTOR, CLASS_SELECTOR, ATTRIBUTE_SELECTOR, ATTR_OPERATOR_NONE, ATTR_FLAG_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_CASE_INSENSITIVE, ATTR_FLAG_CASE_SENSITIVE, PSEUDO_ELEMENT_SELECTOR, PSEUDO_CLASS_SELECTOR, FLAG_HAS_PARENS, LANG_SELECTOR, NTH_OF_SELECTOR } from './arena.js';
|
|
3
3
|
import { TOKEN_COMMA, TOKEN_DELIM, TOKEN_EOF, TOKEN_WHITESPACE, TOKEN_FUNCTION, TOKEN_COLON, TOKEN_LEFT_BRACKET, TOKEN_HASH, TOKEN_IDENT, TOKEN_RIGHT_BRACKET, TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN, TOKEN_STRING } from './token-types.js';
|
|
4
4
|
import { skip_whitespace_and_comments_forward, skip_whitespace_and_comments_backward, skip_whitespace_forward } from './parse-utils.js';
|
package/dist/parse-value.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lexer } from './
|
|
1
|
+
import { Lexer } from './tokenize.js';
|
|
2
2
|
import { CSSDataArena, OPERATOR, HASH, STRING, DIMENSION, NUMBER, IDENTIFIER, URL, FUNCTION, PARENTHESIS } from './arena.js';
|
|
3
3
|
import { TOKEN_EOF, TOKEN_LEFT_PAREN, TOKEN_COMMA, TOKEN_DELIM, TOKEN_FUNCTION, TOKEN_HASH, TOKEN_STRING, TOKEN_DIMENSION, TOKEN_PERCENTAGE, TOKEN_NUMBER, TOKEN_IDENT, TOKEN_RIGHT_PAREN } from './token-types.js';
|
|
4
4
|
import { is_whitespace, CHAR_PLUS, CHAR_MINUS_HYPHEN, CHAR_ASTERISK, CHAR_FORWARD_SLASH, str_equals } from './string-utils.js';
|
package/dist/parse.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Lexer } from './
|
|
1
|
+
import { Lexer } from './tokenize.js';
|
|
2
2
|
import { CSSDataArena, STYLESHEET, STYLE_RULE, FLAG_HAS_BLOCK, BLOCK, FLAG_HAS_DECLARATIONS, SELECTOR_LIST, AT_RULE } from './arena.js';
|
|
3
3
|
import { CSSNode } from './css-node.js';
|
|
4
4
|
import { SelectorParser } from './parse-selector.js';
|
package/dist/string-utils.d.ts
CHANGED
|
@@ -67,3 +67,17 @@ export declare function str_index_of(str: string, searchChar: string): number;
|
|
|
67
67
|
*/
|
|
68
68
|
export declare function is_vendor_prefixed(text: string): boolean;
|
|
69
69
|
export declare function is_vendor_prefixed(source: string, start: number, end: number): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Check if a string is a CSS custom property (starts with --)
|
|
72
|
+
*
|
|
73
|
+
* @param str - The string to check
|
|
74
|
+
* @returns true if the string starts with -- (custom property)
|
|
75
|
+
*
|
|
76
|
+
* Examples:
|
|
77
|
+
* - `--primary-color` → true
|
|
78
|
+
* - `--my-var` → true
|
|
79
|
+
* - `-webkit-transform` → false (vendor prefix, not custom)
|
|
80
|
+
* - `border-radius` → false (standard property)
|
|
81
|
+
* - `color` → false
|
|
82
|
+
*/
|
|
83
|
+
export declare function is_custom(str: string): boolean;
|
package/dist/string-utils.js
CHANGED
|
@@ -109,5 +109,9 @@ function is_vendor_prefixed(source, start, end) {
|
|
|
109
109
|
}
|
|
110
110
|
return false;
|
|
111
111
|
}
|
|
112
|
+
function is_custom(str) {
|
|
113
|
+
if (str.length < 3) return false;
|
|
114
|
+
return str.charCodeAt(0) === CHAR_MINUS_HYPHEN && str.charCodeAt(1) === CHAR_MINUS_HYPHEN;
|
|
115
|
+
}
|
|
112
116
|
|
|
113
|
-
export { CHAR_AMPERSAND, CHAR_ASTERISK, CHAR_CARET, CHAR_CARRIAGE_RETURN, CHAR_COLON, CHAR_DOLLAR, CHAR_DOUBLE_QUOTE, CHAR_EQUALS, CHAR_FORM_FEED, CHAR_FORWARD_SLASH, CHAR_GREATER_THAN, CHAR_MINUS_HYPHEN, CHAR_NEWLINE, CHAR_PERIOD, CHAR_PIPE, CHAR_PLUS, CHAR_SINGLE_QUOTE, CHAR_SPACE, CHAR_TAB, CHAR_TILDE, is_combinator, is_digit, is_vendor_prefixed, is_whitespace, str_equals, str_index_of, str_starts_with };
|
|
117
|
+
export { CHAR_AMPERSAND, CHAR_ASTERISK, CHAR_CARET, CHAR_CARRIAGE_RETURN, CHAR_COLON, CHAR_DOLLAR, CHAR_DOUBLE_QUOTE, CHAR_EQUALS, CHAR_FORM_FEED, CHAR_FORWARD_SLASH, CHAR_GREATER_THAN, CHAR_MINUS_HYPHEN, CHAR_NEWLINE, CHAR_PERIOD, CHAR_PIPE, CHAR_PLUS, CHAR_SINGLE_QUOTE, CHAR_SPACE, CHAR_TAB, CHAR_TILDE, is_combinator, is_custom, is_digit, is_vendor_prefixed, is_whitespace, str_equals, str_index_of, str_starts_with };
|
package/dist/tokenize.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Token, type TokenType } from './token-types';
|
|
2
|
+
export interface LexerPosition {
|
|
3
|
+
pos: number;
|
|
4
|
+
line: number;
|
|
5
|
+
column: number;
|
|
6
|
+
token_type: TokenType;
|
|
7
|
+
token_start: number;
|
|
8
|
+
token_end: number;
|
|
9
|
+
token_line: number;
|
|
10
|
+
token_column: number;
|
|
11
|
+
}
|
|
2
12
|
/**
|
|
3
13
|
* Tokenize CSS source code
|
|
4
14
|
* @param source - The CSS source code to tokenize
|