@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
@@ -0,0 +1,313 @@
1
+ //#region src/arena.d.ts
2
+ declare const STYLESHEET = 1;
3
+ declare const STYLE_RULE = 2;
4
+ declare const AT_RULE = 3;
5
+ declare const DECLARATION = 4;
6
+ declare const SELECTOR = 5;
7
+ declare const COMMENT = 6;
8
+ declare const BLOCK = 7;
9
+ declare const RAW = 8;
10
+ declare const IDENTIFIER = 10;
11
+ declare const NUMBER = 11;
12
+ declare const DIMENSION = 12;
13
+ declare const STRING = 13;
14
+ declare const HASH = 14;
15
+ declare const FUNCTION = 15;
16
+ declare const OPERATOR = 16;
17
+ declare const PARENTHESIS = 17;
18
+ declare const URL = 18;
19
+ declare const SELECTOR_LIST = 20;
20
+ declare const TYPE_SELECTOR = 21;
21
+ declare const CLASS_SELECTOR = 22;
22
+ declare const ID_SELECTOR = 23;
23
+ declare const ATTRIBUTE_SELECTOR = 24;
24
+ declare const PSEUDO_CLASS_SELECTOR = 25;
25
+ declare const PSEUDO_ELEMENT_SELECTOR = 26;
26
+ declare const COMBINATOR = 27;
27
+ declare const UNIVERSAL_SELECTOR = 28;
28
+ declare const NESTING_SELECTOR = 29;
29
+ declare const NTH_SELECTOR = 30;
30
+ declare const NTH_OF_SELECTOR = 31;
31
+ declare const LANG_SELECTOR = 56;
32
+ declare const MEDIA_QUERY = 32;
33
+ declare const MEDIA_FEATURE = 33;
34
+ declare const MEDIA_TYPE = 34;
35
+ declare const CONTAINER_QUERY = 35;
36
+ declare const SUPPORTS_QUERY = 36;
37
+ declare const LAYER_NAME = 37;
38
+ declare const PRELUDE_OPERATOR = 38;
39
+ declare const FEATURE_RANGE = 39;
40
+ declare const AT_RULE_PRELUDE = 40;
41
+ declare const VALUE = 50;
42
+ declare const FLAG_IMPORTANT: number;
43
+ declare const ATTR_OPERATOR_NONE = 0;
44
+ declare const ATTR_OPERATOR_EQUAL = 1;
45
+ declare const ATTR_OPERATOR_TILDE_EQUAL = 2;
46
+ declare const ATTR_OPERATOR_PIPE_EQUAL = 3;
47
+ declare const ATTR_OPERATOR_CARET_EQUAL = 4;
48
+ declare const ATTR_OPERATOR_DOLLAR_EQUAL = 5;
49
+ declare const ATTR_OPERATOR_STAR_EQUAL = 6;
50
+ declare const ATTR_FLAG_NONE = 0;
51
+ declare const ATTR_FLAG_CASE_INSENSITIVE = 1;
52
+ declare const ATTR_FLAG_CASE_SENSITIVE = 2;
53
+ /** @internal */
54
+ declare class CSSDataArena {
55
+ private buffer;
56
+ private view;
57
+ private capacity;
58
+ private count;
59
+ private growth_count;
60
+ private overflow_lengths;
61
+ private static readonly GROWTH_FACTOR;
62
+ private static readonly NODES_PER_KB;
63
+ private static readonly CAPACITY_BUFFER;
64
+ constructor(initial_capacity?: number);
65
+ static capacity_for_source(source_length: number): number;
66
+ get_count(): number;
67
+ get_capacity(): number;
68
+ get_growth_count(): 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_next_sibling(node_index: number): number;
80
+ get_start_line(node_index: number): number;
81
+ get_start_column(node_index: number): number;
82
+ get_value_start(node_index: number): number;
83
+ get_value_length(node_index: number): number;
84
+ set_type(node_index: number, type: number): void;
85
+ set_flags(node_index: number, flags: number): void;
86
+ set_length(node_index: number, length: number): void;
87
+ set_content_start_delta(node_index: number, delta: number): void;
88
+ set_content_length(node_index: number, length: number): void;
89
+ set_attr_operator(node_index: number, operator: number): void;
90
+ set_attr_flags(node_index: number, flags: number): void;
91
+ set_first_child(node_index: number, childIndex: number): void;
92
+ set_next_sibling(node_index: number, siblingIndex: number): void;
93
+ set_value_start_delta(node_index: number, delta: number): void;
94
+ set_value_length(node_index: number, length: number): void;
95
+ private grow;
96
+ create_node(type: number, start_offset: number, length: number, start_line: number, start_column: number): number;
97
+ append_children(parent_index: number, children: number[]): void;
98
+ has_children(node_index: number): boolean;
99
+ has_next_sibling(node_index: number): boolean;
100
+ set_flag(node_index: number, flag: number): void;
101
+ clear_flag(node_index: number, flag: number): void;
102
+ has_flag(node_index: number, flag: number): boolean;
103
+ }
104
+ //#endregion
105
+ //#region src/css-node.d.ts
106
+ declare const TYPE_NAMES: {
107
+ readonly 1: "StyleSheet";
108
+ readonly 2: "Rule";
109
+ readonly 3: "Atrule";
110
+ readonly 4: "Declaration";
111
+ readonly 5: "Selector";
112
+ readonly 6: "Comment";
113
+ readonly 7: "Block";
114
+ readonly 8: "Raw";
115
+ readonly 10: "Identifier";
116
+ readonly 11: "Number";
117
+ readonly 12: "Dimension";
118
+ readonly 13: "String";
119
+ readonly 14: "Hash";
120
+ readonly 15: "Function";
121
+ readonly 16: "Operator";
122
+ readonly 17: "Parentheses";
123
+ readonly 18: "Url";
124
+ readonly 19: "UnicodeRange";
125
+ readonly 50: "Value";
126
+ readonly 20: "SelectorList";
127
+ readonly 21: "TypeSelector";
128
+ readonly 22: "ClassSelector";
129
+ readonly 23: "IdSelector";
130
+ readonly 24: "AttributeSelector";
131
+ readonly 25: "PseudoClassSelector";
132
+ readonly 26: "PseudoElementSelector";
133
+ readonly 27: "Combinator";
134
+ readonly 28: "UniversalSelector";
135
+ readonly 29: "NestingSelector";
136
+ readonly 30: "Nth";
137
+ readonly 31: "NthOf";
138
+ readonly 56: "Lang";
139
+ readonly 32: "MediaQuery";
140
+ readonly 33: "Feature";
141
+ readonly 34: "MediaType";
142
+ readonly 35: "ContainerQuery";
143
+ readonly 36: "SupportsQuery";
144
+ readonly 37: "Layer";
145
+ readonly 38: "Operator";
146
+ readonly 39: "MediaFeatureRange";
147
+ readonly 40: "AtrulePrelude";
148
+ };
149
+ type TypeName = (typeof TYPE_NAMES)[keyof typeof TYPE_NAMES] | 'unknown';
150
+ declare const ATTR_OPERATOR_NAMES: Record<number, string | null>;
151
+ declare const ATTR_FLAG_NAMES: Record<number, string | null>;
152
+ 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;
153
+ interface CloneOptions {
154
+ /**
155
+ * Recursively clone all children
156
+ * @default true
157
+ */
158
+ deep?: boolean;
159
+ /**
160
+ * Include location information (line, column, start, length)
161
+ * @default false
162
+ */
163
+ locations?: boolean;
164
+ }
165
+ type PlainCSSNode = {
166
+ type: number;
167
+ type_name: TypeName;
168
+ text: string;
169
+ children?: PlainCSSNode[];
170
+ name?: string;
171
+ property?: string;
172
+ value?: PlainCSSNode | string | number | null;
173
+ unit?: string;
174
+ prelude?: PlainCSSNode | null;
175
+ is_important?: boolean;
176
+ is_vendor_prefixed?: boolean;
177
+ is_browserhack?: boolean;
178
+ has_error?: boolean;
179
+ attr_operator?: string | null;
180
+ attr_flags?: string | null;
181
+ nth_a?: string | null;
182
+ nth_b?: string | null;
183
+ line?: number;
184
+ column?: number;
185
+ start?: number;
186
+ length?: number;
187
+ end?: number;
188
+ };
189
+ declare class CSSNode {
190
+ private arena;
191
+ private source;
192
+ private index;
193
+ constructor(arena: CSSDataArena, source: string, index: number);
194
+ /**
195
+ * @internal
196
+ * Get the arena (for internal/advanced use only)
197
+ */
198
+ __get_arena(): CSSDataArena;
199
+ private get_content;
200
+ /** Get node type as number (for performance) */
201
+ get type(): CSSNodeType;
202
+ /** Get node type as human-readable string */
203
+ get type_name(): TypeName;
204
+ /** Get the full text of this node from source */
205
+ get text(): string;
206
+ /** Get the "content" text (at-rule name for at-rules, layer name for import layers) */
207
+ get name(): string | undefined;
208
+ /**
209
+ * Alias for name (for declarations: "color" in "color: blue")
210
+ * More semantic than `name` for declaration nodes
211
+ */
212
+ get property(): string | undefined;
213
+ /**
214
+ * Get the value text (for declarations: "blue" in "color: blue")
215
+ * For dimension/number nodes: returns the numeric value as a number
216
+ * For string nodes: returns the string content without quotes
217
+ * For URL nodes with quoted string: returns the string with quotes (consistent with STRING node)
218
+ * For URL nodes with unquoted URL: returns the URL content without quotes
219
+ */
220
+ get value(): CSSNode | string | number | null | undefined;
221
+ /** Get the numeric value for NUMBER and DIMENSION nodes, or null for other node types */
222
+ get value_as_number(): number | null;
223
+ /**
224
+ * Get the prelude node:
225
+ * - For at-rules: AT_RULE_PRELUDE wrapper containing structured prelude children (media queries, layer names, etc.)
226
+ * - For style rules: SELECTOR_LIST or SELECTOR node
227
+ * Returns null if no prelude exists
228
+ */
229
+ get prelude(): CSSNode | null | undefined;
230
+ /**
231
+ * Get the attribute operator (for attribute selectors: =, ~=, |=, ^=, $=, *=)
232
+ * Returns one of the ATTR_OPERATOR_* constants
233
+ */
234
+ get attr_operator(): number | undefined;
235
+ /**
236
+ * Get the attribute flags (for attribute selectors: i, s)
237
+ * Returns one of the ATTR_FLAG_* constants
238
+ */
239
+ get attr_flags(): number | undefined;
240
+ /** Get the unit for dimension nodes (e.g., "px" from "100px", "%" from "50%") */
241
+ get unit(): string | undefined;
242
+ /** Check if this declaration has !important */
243
+ get is_important(): boolean | undefined;
244
+ /** Check if this declaration has a browser hack prefix */
245
+ get is_browserhack(): boolean | undefined;
246
+ /** Check if this has a vendor prefix (computed on-demand) */
247
+ get is_vendor_prefixed(): boolean;
248
+ /** Check if this node has an error */
249
+ get has_error(): boolean;
250
+ /** Check if this node has a prelude (at-rules and style rules) */
251
+ get has_prelude(): boolean;
252
+ /** Check if this rule has a block { } */
253
+ get has_block(): boolean;
254
+ /** Check if this style rule has declarations */
255
+ get has_declarations(): boolean;
256
+ /** Get the block node (for style rules and at-rules with blocks) */
257
+ get block(): CSSNode | null;
258
+ /** Check if this block is empty (no declarations or rules, only comments allowed) */
259
+ get is_empty(): boolean | undefined;
260
+ /** Get start line number */
261
+ get line(): number;
262
+ /** Get start column number */
263
+ get column(): number;
264
+ /** Get start offset in source */
265
+ get start(): number;
266
+ /** Get length in source */
267
+ get length(): number;
268
+ /**
269
+ * Get end offset in source
270
+ * End is not stored, must be calculated
271
+ */
272
+ get end(): number;
273
+ /** Get first child node */
274
+ get first_child(): CSSNode | null;
275
+ /** Get next sibling node */
276
+ get next_sibling(): CSSNode | null;
277
+ /** Check if this node has a next sibling */
278
+ get has_next(): boolean;
279
+ /**
280
+ * Check if this node has children
281
+ * For pseudo-class/pseudo-element functions, returns true if FLAG_HAS_PARENS is set
282
+ * This allows formatters to distinguish :lang() from :hover
283
+ */
284
+ get has_children(): boolean;
285
+ /** Get all children as an array */
286
+ get children(): CSSNode[];
287
+ /** Make CSSNode iterable over its children */
288
+ [Symbol.iterator](): Iterator<CSSNode>;
289
+ /** Get the 'a' coefficient from An+B expression (e.g., "2n" from "2n+1", "odd" from "odd") */
290
+ get nth_a(): string | undefined;
291
+ /** Get the 'b' coefficient from An+B expression (e.g., "+1" from "2n+1") */
292
+ get nth_b(): string | undefined;
293
+ /** Get the An+B formula node from :nth-child(2n+1 of .foo) */
294
+ get nth(): CSSNode | undefined;
295
+ /** Get the selector list from :nth-child(2n+1 of .foo) */
296
+ get selector(): CSSNode | undefined;
297
+ /**
298
+ * Get selector list from pseudo-class functions
299
+ * Works for :is(.a), :not(.b), :has(.c), :where(.d), :nth-child(2n of .e)
300
+ */
301
+ get selector_list(): CSSNode | undefined;
302
+ /**
303
+ * Clone this node as a mutable plain JavaScript object with children as arrays.
304
+ * See API.md for examples.
305
+ *
306
+ * @param options - Cloning configuration
307
+ * @param options.deep - Recursively clone children (default: true)
308
+ * @param options.locations - Include line/column/start/length (default: false)
309
+ */
310
+ clone(options?: CloneOptions): PlainCSSNode;
311
+ }
312
+ //#endregion
313
+ export { STYLESHEET as $, FLAG_IMPORTANT as A, NESTING_SELECTOR as B, COMBINATOR as C, DECLARATION as D, CSSDataArena as E, LANG_SELECTOR as F, PARENTHESIS as G, NTH_SELECTOR as H, LAYER_NAME as I, PSEUDO_ELEMENT_SELECTOR as J, PRELUDE_OPERATOR as K, MEDIA_FEATURE as L, HASH as M, IDENTIFIER as N, DIMENSION as O, ID_SELECTOR as P, STRING as Q, MEDIA_QUERY as R, CLASS_SELECTOR as S, CONTAINER_QUERY as T, NUMBER as U, NTH_OF_SELECTOR as V, OPERATOR as W, SELECTOR as X, RAW as Y, SELECTOR_LIST as Z, ATTR_OPERATOR_STAR_EQUAL as _, CloneOptions as a, VALUE as at, AT_RULE_PRELUDE as b, ATTRIBUTE_SELECTOR as c, ATTR_FLAG_NONE as d, STYLE_RULE as et, ATTR_OPERATOR_CARET_EQUAL as f, ATTR_OPERATOR_PIPE_EQUAL as g, ATTR_OPERATOR_NONE as h, CSSNodeType as i, URL as it, FUNCTION as j, FEATURE_RANGE as k, ATTR_FLAG_CASE_INSENSITIVE as l, ATTR_OPERATOR_EQUAL as m, ATTR_OPERATOR_NAMES as n, TYPE_SELECTOR as nt, PlainCSSNode as o, ATTR_OPERATOR_DOLLAR_EQUAL as p, PSEUDO_CLASS_SELECTOR as q, CSSNode as r, UNIVERSAL_SELECTOR as rt, TYPE_NAMES as s, ATTR_FLAG_NAMES as t, SUPPORTS_QUERY as tt, ATTR_FLAG_CASE_SENSITIVE as u, ATTR_OPERATOR_TILDE_EQUAL as v, COMMENT as w, BLOCK as x, AT_RULE as y, MEDIA_TYPE as z };
package/dist/index.d.ts CHANGED
@@ -1,16 +1,150 @@
1
- export { parse } from './parse';
2
- export { parse_selector } from './parse-selector';
3
- export { parse_atrule_prelude } from './parse-atrule-prelude';
4
- export { parse_declaration } from './parse-declaration';
5
- export { parse_value } from './parse-value';
6
- export { parse_dimension } from './parse-dimension';
7
- export { tokenize } from './tokenize';
8
- export { walk, traverse, SKIP, BREAK } from './walk';
9
- export { is_custom, is_vendor_prefixed, str_equals, str_starts_with, str_index_of } from './string-utils';
10
- export { type ParserOptions } from './parse';
11
- export { CSSNode, type CSSNodeType, TYPE_NAMES, type CloneOptions, type PlainCSSNode } from './css-node';
12
- export type { LexerPosition, CommentInfo } from './tokenize';
13
- 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';
14
- export * from './constants';
15
- export * from './token-types';
16
- export { NODE_TYPES } from './constants';
1
+ import { A as TOKEN_URL, C as TOKEN_PERCENTAGE, D as TOKEN_SEMICOLON, E as TOKEN_RIGHT_PAREN, M as Token, N as TokenType, O as TOKEN_STRING, S as TOKEN_NUMBER, T as TOKEN_RIGHT_BRACKET, _ as TOKEN_HASH, a as TOKEN_AT_KEYWORD, b as TOKEN_LEFT_BRACKET, c as TOKEN_CDC, d as TOKEN_COMMA, f as TOKEN_COMMENT, g as TOKEN_FUNCTION, h as TOKEN_EOF, i as tokenize, j as TOKEN_WHITESPACE, k as TOKEN_UNICODE_RANGE, l as TOKEN_CDO, m as TOKEN_DIMENSION, o as TOKEN_BAD_STRING, p as TOKEN_DELIM, r as LexerPosition, s as TOKEN_BAD_URL, t as CommentInfo, u as TOKEN_COLON, v as TOKEN_IDENT, w as TOKEN_RIGHT_BRACE, x as TOKEN_LEFT_PAREN, y as TOKEN_LEFT_BRACE } from "./tokenize-odLrcjj2.js";
2
+ import { $ as STYLESHEET, A as FLAG_IMPORTANT, B as NESTING_SELECTOR, C as COMBINATOR, D as DECLARATION, F as LANG_SELECTOR, G as PARENTHESIS, H as NTH_SELECTOR, I as LAYER_NAME, J as PSEUDO_ELEMENT_SELECTOR, K as PRELUDE_OPERATOR, L as MEDIA_FEATURE, M as HASH, N as IDENTIFIER, O as DIMENSION, P as ID_SELECTOR, Q as STRING, R as MEDIA_QUERY, S as CLASS_SELECTOR, T as CONTAINER_QUERY, U as NUMBER, V as NTH_OF_SELECTOR, W as OPERATOR, X as SELECTOR, Y as RAW, Z as SELECTOR_LIST, _ as ATTR_OPERATOR_STAR_EQUAL, a as CloneOptions, at as VALUE, b as AT_RULE_PRELUDE, c as ATTRIBUTE_SELECTOR, d as ATTR_FLAG_NONE, et as STYLE_RULE, f as ATTR_OPERATOR_CARET_EQUAL, g as ATTR_OPERATOR_PIPE_EQUAL, h as ATTR_OPERATOR_NONE, i as CSSNodeType, it as URL, j as FUNCTION, k as FEATURE_RANGE, l as ATTR_FLAG_CASE_INSENSITIVE, m as ATTR_OPERATOR_EQUAL, n as ATTR_OPERATOR_NAMES, nt as TYPE_SELECTOR, o as PlainCSSNode, p as ATTR_OPERATOR_DOLLAR_EQUAL, q as PSEUDO_CLASS_SELECTOR, r as CSSNode, rt as UNIVERSAL_SELECTOR, s as TYPE_NAMES, t as ATTR_FLAG_NAMES, tt as SUPPORTS_QUERY, u as ATTR_FLAG_CASE_SENSITIVE, v as ATTR_OPERATOR_TILDE_EQUAL, w as COMMENT, x as BLOCK, y as AT_RULE, z as MEDIA_TYPE } from "./css-node-DqyvMXBN.js";
3
+ import { ParserOptions, parse } from "./parse.js";
4
+ import { parse_selector } from "./parse-selector.js";
5
+ import { parse_atrule_prelude } from "./parse-atrule-prelude.js";
6
+ import { parse_declaration } from "./parse-declaration.js";
7
+ import { parse_value } from "./parse-value.js";
8
+ import { parse_dimension } from "./parse-dimension.js";
9
+
10
+ //#region src/walk.d.ts
11
+ declare const SKIP: unique symbol;
12
+ declare const BREAK: unique symbol;
13
+ type WalkCallback = (node: CSSNode, depth: number) => void | typeof SKIP | typeof BREAK;
14
+ /**
15
+ * Walk the AST in depth-first order, calling the callback for each node.
16
+ * Return SKIP to skip children, BREAK to stop traversal. See API.md for examples.
17
+ *
18
+ * @param node - The root node to start walking from
19
+ * @param callback - Function called for each node. Receives the node and its nesting depth.
20
+ * Depth increments only for STYLE_RULE and AT_RULE nodes (tracks rule nesting, not tree depth).
21
+ * @param depth - Starting depth (default: 0)
22
+ */
23
+ declare function walk(node: CSSNode, callback: WalkCallback, depth?: number): boolean;
24
+ type WalkEnterLeaveCallback = (node: CSSNode) => void | typeof SKIP | typeof BREAK;
25
+ interface WalkEnterLeaveOptions {
26
+ enter?: WalkEnterLeaveCallback;
27
+ leave?: WalkEnterLeaveCallback;
28
+ }
29
+ /**
30
+ * Walk the AST in depth-first order, calling enter before visiting children and leave after.
31
+ * Return SKIP in enter to skip children (leave still called), BREAK to stop (leave NOT called). See API.md for examples.
32
+ *
33
+ * @param node - The root node to start walking from
34
+ * @param options - Object with optional enter and leave callback functions
35
+ */
36
+ declare function traverse(node: CSSNode, {
37
+ enter,
38
+ leave
39
+ }?: WalkEnterLeaveOptions): boolean;
40
+ //#endregion
41
+ //#region src/string-utils.d.ts
42
+ /**
43
+ * @param a Base string, MUST be lowercase!
44
+ * @param b Compare string
45
+ */
46
+ declare function str_equals(a: string, b: string): boolean;
47
+ /**
48
+ * Case-insensitive ASCII prefix check without allocations
49
+ * Returns true if string `str` starts with prefix (case-insensitive)
50
+ *
51
+ * IMPORTANT: prefix MUST be lowercase for correct comparison
52
+ *
53
+ * @param str - The string to check
54
+ * @param prefix - The lowercase prefix to match against
55
+ */
56
+ declare function str_starts_with(str: string, prefix: string): boolean;
57
+ /**
58
+ * Case-insensitive character/substring search without allocations
59
+ * Returns the index of the first occurrence of searchChar (case-insensitive)
60
+ *
61
+ * IMPORTANT: searchChar MUST be lowercase for correct comparison
62
+ *
63
+ * @param str - The string to search in
64
+ * @param searchChar - The lowercase character/substring to find
65
+ * @returns The index of the first match, or -1 if not found
66
+ */
67
+ declare function str_index_of(str: string, searchChar: string): number;
68
+ /**
69
+ * Check if a string range has a vendor prefix
70
+ *
71
+ * @param source - The source string
72
+ * @param start - Start offset in source
73
+ * @param end - End offset in source
74
+ * @returns true if the range starts with a vendor prefix (-webkit-, -moz-, -ms-, -o-)
75
+ *
76
+ * Detects vendor prefixes by checking:
77
+ * 1. Starts with a single hyphen (not --)
78
+ * 2. Contains at least 3 characters (shortest is -o-)
79
+ * 3. Has a second hyphen after the vendor name
80
+ *
81
+ * Examples:
82
+ * - `-webkit-transform` → true
83
+ * - `-moz-appearance` → true
84
+ * - `-ms-filter` → true
85
+ * - `-o-border-image` → true
86
+ * - `--custom-property` → false (CSS custom property)
87
+ * - `border-radius` → false (doesn't start with hyphen)
88
+ */
89
+ declare function is_vendor_prefixed(text: string): boolean;
90
+ declare function is_vendor_prefixed(source: string, start: number, end: number): boolean;
91
+ /**
92
+ * Check if a string is a CSS custom property (starts with --)
93
+ *
94
+ * @param str - The string to check
95
+ * @returns true if the string starts with -- (custom property)
96
+ *
97
+ * Examples:
98
+ * - `--primary-color` → true
99
+ * - `--my-var` → true
100
+ * - `-webkit-transform` → false (vendor prefix, not custom)
101
+ * - `border-radius` → false (standard property)
102
+ * - `color` → false
103
+ */
104
+ declare function is_custom(str: string): boolean;
105
+ //#endregion
106
+ //#region src/constants.d.ts
107
+ declare const NODE_TYPES: {
108
+ readonly STYLESHEET: 1;
109
+ readonly STYLE_RULE: 2;
110
+ readonly AT_RULE: 3;
111
+ readonly DECLARATION: 4;
112
+ readonly SELECTOR: 5;
113
+ readonly COMMENT: 6;
114
+ readonly BLOCK: 7;
115
+ readonly RAW: 8;
116
+ readonly IDENTIFIER: 10;
117
+ readonly NUMBER: 11;
118
+ readonly DIMENSION: 12;
119
+ readonly STRING: 13;
120
+ readonly HASH: 14;
121
+ readonly FUNCTION: 15;
122
+ readonly OPERATOR: 16;
123
+ readonly PARENTHESIS: 17;
124
+ readonly URL: 18;
125
+ readonly VALUE: 50;
126
+ readonly SELECTOR_LIST: 20;
127
+ readonly TYPE_SELECTOR: 21;
128
+ readonly CLASS_SELECTOR: 22;
129
+ readonly ID_SELECTOR: 23;
130
+ readonly ATTRIBUTE_SELECTOR: 24;
131
+ readonly PSEUDO_CLASS_SELECTOR: 25;
132
+ readonly PSEUDO_ELEMENT_SELECTOR: 26;
133
+ readonly COMBINATOR: 27;
134
+ readonly UNIVERSAL_SELECTOR: 28;
135
+ readonly NESTING_SELECTOR: 29;
136
+ readonly NTH_SELECTOR: 30;
137
+ readonly NTH_OF_SELECTOR: 31;
138
+ readonly LANG_SELECTOR: 56;
139
+ readonly MEDIA_QUERY: 32;
140
+ readonly MEDIA_FEATURE: 33;
141
+ readonly MEDIA_TYPE: 34;
142
+ readonly CONTAINER_QUERY: 35;
143
+ readonly SUPPORTS_QUERY: 36;
144
+ readonly LAYER_NAME: 37;
145
+ readonly PRELUDE_OPERATOR: 38;
146
+ readonly FEATURE_RANGE: 39;
147
+ readonly AT_RULE_PRELUDE: 40;
148
+ };
149
+ //#endregion
150
+ export { ATTRIBUTE_SELECTOR, ATTR_FLAG_CASE_INSENSITIVE, ATTR_FLAG_CASE_SENSITIVE, ATTR_FLAG_NAMES, ATTR_FLAG_NONE, ATTR_OPERATOR_CARET_EQUAL, ATTR_OPERATOR_DOLLAR_EQUAL, ATTR_OPERATOR_EQUAL, ATTR_OPERATOR_NAMES, ATTR_OPERATOR_NONE, ATTR_OPERATOR_PIPE_EQUAL, ATTR_OPERATOR_STAR_EQUAL, ATTR_OPERATOR_TILDE_EQUAL, AT_RULE, AT_RULE_PRELUDE, BLOCK, BREAK, CLASS_SELECTOR, COMBINATOR, COMMENT, CONTAINER_QUERY, CSSNode, type CSSNodeType, type CloneOptions, type CommentInfo, DECLARATION, DIMENSION, FEATURE_RANGE, FLAG_IMPORTANT, FUNCTION, HASH, IDENTIFIER, ID_SELECTOR, LANG_SELECTOR, LAYER_NAME, type LexerPosition, 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, type ParserOptions, type PlainCSSNode, RAW, SELECTOR, SELECTOR_LIST, SKIP, STRING, STYLESHEET, STYLE_RULE, SUPPORTS_QUERY, TOKEN_AT_KEYWORD, TOKEN_BAD_STRING, TOKEN_BAD_URL, TOKEN_CDC, TOKEN_CDO, TOKEN_COLON, TOKEN_COMMA, TOKEN_COMMENT, TOKEN_DELIM, TOKEN_DIMENSION, TOKEN_EOF, TOKEN_FUNCTION, TOKEN_HASH, TOKEN_IDENT, TOKEN_LEFT_BRACE, TOKEN_LEFT_BRACKET, TOKEN_LEFT_PAREN, TOKEN_NUMBER, TOKEN_PERCENTAGE, TOKEN_RIGHT_BRACE, TOKEN_RIGHT_BRACKET, TOKEN_RIGHT_PAREN, TOKEN_SEMICOLON, TOKEN_STRING, TOKEN_UNICODE_RANGE, TOKEN_URL, TOKEN_WHITESPACE, TYPE_NAMES, TYPE_SELECTOR, Token, TokenType, UNIVERSAL_SELECTOR, URL, VALUE, is_custom, is_vendor_prefixed, parse, parse_atrule_prelude, parse_declaration, parse_dimension, parse_selector, parse_value, str_equals, str_index_of, str_starts_with, tokenize, traverse, walk };
package/dist/index.js CHANGED
@@ -1,13 +1,103 @@
1
- export { parse } from './parse.js';
2
- export { parse_selector } from './parse-selector.js';
3
- export { parse_atrule_prelude } from './parse-atrule-prelude.js';
4
- export { parse_declaration } from './parse-declaration.js';
5
- export { parse_value } from './parse-value.js';
6
- export { parse_dimension } from './parse-dimension.js';
7
- export { tokenize } from './tokenize.js';
8
- export { BREAK, SKIP, traverse, walk } from './walk.js';
9
- export { is_custom, is_vendor_prefixed, str_equals, str_index_of, str_starts_with } from './string-utils.js';
10
- export { CSSNode, TYPE_NAMES } from './css-node.js';
11
- 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, DECLARATION, DIMENSION, FEATURE_RANGE, 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, VALUE } from './arena.js';
12
- export { NODE_TYPES } from './constants.js';
13
- export { TOKEN_AT_KEYWORD, TOKEN_BAD_STRING, TOKEN_BAD_URL, TOKEN_CDC, TOKEN_CDO, TOKEN_COLON, TOKEN_COMMA, TOKEN_COMMENT, TOKEN_DELIM, TOKEN_DIMENSION, TOKEN_EOF, TOKEN_FUNCTION, TOKEN_HASH, TOKEN_IDENT, TOKEN_LEFT_BRACE, TOKEN_LEFT_BRACKET, TOKEN_LEFT_PAREN, TOKEN_NUMBER, TOKEN_PERCENTAGE, TOKEN_RIGHT_BRACE, TOKEN_RIGHT_BRACKET, TOKEN_RIGHT_PAREN, TOKEN_SEMICOLON, TOKEN_STRING, TOKEN_UNICODE_RANGE, TOKEN_URL, TOKEN_WHITESPACE } from './token-types.js';
1
+ import { C as TOKEN_RIGHT_BRACKET, D as TOKEN_UNICODE_RANGE, E as TOKEN_STRING, O as TOKEN_URL, S as TOKEN_RIGHT_BRACE, T as TOKEN_SEMICOLON, _ as TOKEN_LEFT_BRACE, a as TOKEN_BAD_URL, b as TOKEN_NUMBER, c as TOKEN_COLON, d as TOKEN_DELIM, f as TOKEN_DIMENSION, g as TOKEN_IDENT, h as TOKEN_HASH, i as TOKEN_BAD_STRING, k as TOKEN_WHITESPACE, l as TOKEN_COMMA, m as TOKEN_FUNCTION, n as tokenize, o as TOKEN_CDC, p as TOKEN_EOF, r as TOKEN_AT_KEYWORD, s as TOKEN_CDO, u as TOKEN_COMMENT, v as TOKEN_LEFT_BRACKET, w as TOKEN_RIGHT_PAREN, x as TOKEN_PERCENTAGE, y as TOKEN_LEFT_PAREN } from "./tokenize-BQFB1jXg.js";
2
+ import { $ as TYPE_SELECTOR, A as IDENTIFIER, B as NUMBER, D as FLAG_IMPORTANT, E as FEATURE_RANGE, F as MEDIA_QUERY, G as PSEUDO_ELEMENT_SELECTOR, H as PARENTHESIS, I as MEDIA_TYPE, J as SELECTOR_LIST, K as RAW, L as NESTING_SELECTOR, M as LANG_SELECTOR, N as LAYER_NAME, O as FUNCTION, P as MEDIA_FEATURE, Q as SUPPORTS_QUERY, R as NTH_OF_SELECTOR, S as CONTAINER_QUERY, T as DIMENSION, U as PRELUDE_OPERATOR, V as OPERATOR, W as PSEUDO_CLASS_SELECTOR, X as STYLESHEET, Y as STRING, Z as STYLE_RULE, _ as AT_RULE_PRELUDE, a as ATTRIBUTE_SELECTOR, b as COMBINATOR, c as ATTR_FLAG_NONE, d as ATTR_OPERATOR_EQUAL, et as UNIVERSAL_SELECTOR, f as ATTR_OPERATOR_NONE, g as AT_RULE, h as ATTR_OPERATOR_TILDE_EQUAL, i as TYPE_NAMES, j as ID_SELECTOR, k as HASH, l as ATTR_OPERATOR_CARET_EQUAL, m as ATTR_OPERATOR_STAR_EQUAL, n as ATTR_OPERATOR_NAMES, nt as VALUE, o as ATTR_FLAG_CASE_INSENSITIVE, p as ATTR_OPERATOR_PIPE_EQUAL, q as SELECTOR, r as CSSNode, s as ATTR_FLAG_CASE_SENSITIVE, t as ATTR_FLAG_NAMES, tt as URL, u as ATTR_OPERATOR_DOLLAR_EQUAL, v as BLOCK, w as DECLARATION, x as COMMENT, y as CLASS_SELECTOR, z as NTH_SELECTOR } from "./css-node-2ejJUrIw.js";
3
+ import { c as str_starts_with, i as is_vendor_prefixed, o as str_equals, r as is_custom, s as str_index_of, t as parse_dimension } from "./parse-dimension-CCn_XRDe.js";
4
+ import { parse_selector } from "./parse-selector.js";
5
+ import { parse_atrule_prelude } from "./parse-atrule-prelude.js";
6
+ import { parse_value } from "./parse-value.js";
7
+ import { parse_declaration } from "./parse-declaration.js";
8
+ import { parse } from "./parse.js";
9
+ //#region src/constants.ts
10
+ const NODE_TYPES = {
11
+ STYLESHEET: 1,
12
+ STYLE_RULE: 2,
13
+ AT_RULE: 3,
14
+ DECLARATION: 4,
15
+ SELECTOR: 5,
16
+ COMMENT: 6,
17
+ BLOCK: 7,
18
+ RAW: 8,
19
+ IDENTIFIER: 10,
20
+ NUMBER: 11,
21
+ DIMENSION: 12,
22
+ STRING: 13,
23
+ HASH: 14,
24
+ FUNCTION: 15,
25
+ OPERATOR: 16,
26
+ PARENTHESIS: 17,
27
+ URL: 18,
28
+ VALUE: 50,
29
+ SELECTOR_LIST: 20,
30
+ TYPE_SELECTOR: 21,
31
+ CLASS_SELECTOR: 22,
32
+ ID_SELECTOR: 23,
33
+ ATTRIBUTE_SELECTOR: 24,
34
+ PSEUDO_CLASS_SELECTOR: 25,
35
+ PSEUDO_ELEMENT_SELECTOR: 26,
36
+ COMBINATOR: 27,
37
+ UNIVERSAL_SELECTOR: 28,
38
+ NESTING_SELECTOR: 29,
39
+ NTH_SELECTOR: 30,
40
+ NTH_OF_SELECTOR: 31,
41
+ LANG_SELECTOR: 56,
42
+ MEDIA_QUERY: 32,
43
+ MEDIA_FEATURE: 33,
44
+ MEDIA_TYPE: 34,
45
+ CONTAINER_QUERY: 35,
46
+ SUPPORTS_QUERY: 36,
47
+ LAYER_NAME: 37,
48
+ PRELUDE_OPERATOR: 38,
49
+ FEATURE_RANGE: 39,
50
+ AT_RULE_PRELUDE: 40
51
+ };
52
+ //#endregion
53
+ //#region src/walk.ts
54
+ const SKIP = Symbol("SKIP");
55
+ const BREAK = Symbol("BREAK");
56
+ /**
57
+ * Walk the AST in depth-first order, calling the callback for each node.
58
+ * Return SKIP to skip children, BREAK to stop traversal. See API.md for examples.
59
+ *
60
+ * @param node - The root node to start walking from
61
+ * @param callback - Function called for each node. Receives the node and its nesting depth.
62
+ * Depth increments only for STYLE_RULE and AT_RULE nodes (tracks rule nesting, not tree depth).
63
+ * @param depth - Starting depth (default: 0)
64
+ */
65
+ function walk(node, callback, depth = 0) {
66
+ const result = callback(node, depth);
67
+ if (result === BREAK) return false;
68
+ if (result === SKIP) return true;
69
+ let child_depth = depth;
70
+ if (node.type === 2 || node.type === 3) child_depth = depth + 1;
71
+ let child = node.first_child;
72
+ while (child) {
73
+ if (!walk(child, callback, child_depth)) return false;
74
+ child = child.next_sibling;
75
+ }
76
+ return true;
77
+ }
78
+ const NOOP = function() {};
79
+ /**
80
+ * Walk the AST in depth-first order, calling enter before visiting children and leave after.
81
+ * Return SKIP in enter to skip children (leave still called), BREAK to stop (leave NOT called). See API.md for examples.
82
+ *
83
+ * @param node - The root node to start walking from
84
+ * @param options - Object with optional enter and leave callback functions
85
+ */
86
+ function traverse(node, { enter = NOOP, leave = NOOP } = {}) {
87
+ const enter_result = enter(node);
88
+ if (enter_result === BREAK) return false;
89
+ if (enter_result !== SKIP) {
90
+ let child = node.first_child;
91
+ while (child) {
92
+ if (!traverse(child, {
93
+ enter,
94
+ leave
95
+ })) return false;
96
+ child = child.next_sibling;
97
+ }
98
+ }
99
+ if (leave(node) === BREAK) return false;
100
+ return true;
101
+ }
102
+ //#endregion
103
+ export { ATTRIBUTE_SELECTOR, ATTR_FLAG_CASE_INSENSITIVE, ATTR_FLAG_CASE_SENSITIVE, ATTR_FLAG_NAMES, ATTR_FLAG_NONE, ATTR_OPERATOR_CARET_EQUAL, ATTR_OPERATOR_DOLLAR_EQUAL, ATTR_OPERATOR_EQUAL, ATTR_OPERATOR_NAMES, ATTR_OPERATOR_NONE, ATTR_OPERATOR_PIPE_EQUAL, ATTR_OPERATOR_STAR_EQUAL, ATTR_OPERATOR_TILDE_EQUAL, AT_RULE, AT_RULE_PRELUDE, BLOCK, BREAK, CLASS_SELECTOR, COMBINATOR, COMMENT, CONTAINER_QUERY, CSSNode, DECLARATION, DIMENSION, FEATURE_RANGE, FLAG_IMPORTANT, 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, SKIP, STRING, STYLESHEET, STYLE_RULE, SUPPORTS_QUERY, TOKEN_AT_KEYWORD, TOKEN_BAD_STRING, TOKEN_BAD_URL, TOKEN_CDC, TOKEN_CDO, TOKEN_COLON, TOKEN_COMMA, TOKEN_COMMENT, TOKEN_DELIM, TOKEN_DIMENSION, TOKEN_EOF, TOKEN_FUNCTION, TOKEN_HASH, TOKEN_IDENT, TOKEN_LEFT_BRACE, TOKEN_LEFT_BRACKET, TOKEN_LEFT_PAREN, TOKEN_NUMBER, TOKEN_PERCENTAGE, TOKEN_RIGHT_BRACE, TOKEN_RIGHT_BRACKET, TOKEN_RIGHT_PAREN, TOKEN_SEMICOLON, TOKEN_STRING, TOKEN_UNICODE_RANGE, TOKEN_URL, TOKEN_WHITESPACE, TYPE_NAMES, TYPE_SELECTOR, UNIVERSAL_SELECTOR, URL, VALUE, is_custom, is_vendor_prefixed, parse, parse_atrule_prelude, parse_declaration, parse_dimension, parse_selector, parse_value, str_equals, str_index_of, str_starts_with, tokenize, traverse, walk };
@@ -1,2 +1,26 @@
1
- import { CSSNode } from './css-node';
2
- export declare function parse_anplusb(expr: string): CSSNode | null;
1
+ import { E as CSSDataArena, r as CSSNode } from "./css-node-DqyvMXBN.js";
2
+
3
+ //#region src/parse-anplusb.d.ts
4
+ /** @internal */
5
+ declare class ANplusBParser {
6
+ private lexer;
7
+ private arena;
8
+ private source;
9
+ private expr_end;
10
+ constructor(arena: CSSDataArena, source: string);
11
+ /**
12
+ * Parse An+B expression
13
+ * Examples: odd, even, 3, n, -n, 2n, 2n+1, -3n-5
14
+ */
15
+ parse_anplusb(start: number, end: number, line?: number): number | null;
16
+ /**
17
+ * Parse the b part after 'n'
18
+ * Handles: +5, -3, whitespace variations
19
+ */
20
+ private parse_b_part;
21
+ private skip_whitespace;
22
+ private create_anplusb_node;
23
+ }
24
+ declare function parse_anplusb(expr: string): CSSNode | null;
25
+ //#endregion
26
+ export { ANplusBParser, parse_anplusb };