@projectwallace/css-parser 0.13.5 → 0.13.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css-node-DqyvMXBN.d.ts +313 -0
- package/dist/css-node-Uj4oBgaw.js +647 -0
- package/dist/index.d.ts +150 -16
- package/dist/index.js +103 -13
- package/dist/parse-anplusb.d.ts +26 -2
- package/dist/parse-anplusb.js +191 -207
- package/dist/parse-atrule-prelude.d.ts +40 -2
- package/dist/parse-atrule-prelude.js +556 -652
- package/dist/parse-declaration.d.ts +16 -2
- package/dist/parse-declaration.js +140 -167
- package/dist/parse-dimension-CCn_XRDe.js +177 -0
- package/dist/parse-dimension.d.ts +6 -3
- package/dist/parse-dimension.js +1 -35
- package/dist/parse-selector.d.ts +37 -2
- package/dist/parse-selector.js +508 -635
- package/dist/parse-utils-DnsZRpfd.js +98 -0
- package/dist/parse-value.d.ts +23 -2
- package/dist/parse-value.js +176 -224
- package/dist/parse.d.ts +37 -8
- package/dist/parse.js +252 -353
- package/dist/tokenize-BQFB1jXg.js +540 -0
- package/dist/tokenize-odLrcjj2.d.ts +110 -0
- package/dist/tokenize.d.ts +2 -26
- package/dist/tokenize.js +1 -545
- package/package.json +20 -26
- package/dist/arena.d.ts +0 -60
- package/dist/arena.js +0 -291
- package/dist/char-types.d.ts +0 -14
- package/dist/char-types.js +0 -53
- package/dist/constants.d.ts +0 -44
- package/dist/constants.js +0 -51
- package/dist/css-node.d.ts +0 -203
- package/dist/css-node.js +0 -498
- package/dist/parse-utils.d.ts +0 -1
- package/dist/parse-utils.js +0 -60
- package/dist/string-utils.d.ts +0 -99
- package/dist/string-utils.js +0 -129
- package/dist/token-types.d.ts +0 -35
- package/dist/token-types.js +0 -29
- package/dist/walk.d.ts +0 -28
- package/dist/walk.js +0 -51
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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-Uj4oBgaw.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 };
|
package/dist/parse-anplusb.d.ts
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
import { CSSNode } from
|
|
2
|
-
|
|
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 };
|