@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/string-utils.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
const CHAR_SPACE = 32;
|
|
2
|
-
const CHAR_TAB = 9;
|
|
3
|
-
const CHAR_NEWLINE = 10;
|
|
4
|
-
const CHAR_CARRIAGE_RETURN = 13;
|
|
5
|
-
const CHAR_FORM_FEED = 12;
|
|
6
|
-
const CHAR_FORWARD_SLASH = 47;
|
|
7
|
-
const CHAR_ASTERISK = 42;
|
|
8
|
-
const CHAR_MINUS_HYPHEN = 45;
|
|
9
|
-
const CHAR_SINGLE_QUOTE = 39;
|
|
10
|
-
const CHAR_DOUBLE_QUOTE = 34;
|
|
11
|
-
const CHAR_PLUS = 43;
|
|
12
|
-
const CHAR_PERIOD = 46;
|
|
13
|
-
const CHAR_TILDE = 126;
|
|
14
|
-
const CHAR_GREATER_THAN = 62;
|
|
15
|
-
const CHAR_AMPERSAND = 38;
|
|
16
|
-
const CHAR_EQUALS = 61;
|
|
17
|
-
const CHAR_PIPE = 124;
|
|
18
|
-
const CHAR_DOLLAR = 36;
|
|
19
|
-
const CHAR_CARET = 94;
|
|
20
|
-
const CHAR_COLON = 58;
|
|
21
|
-
const CHAR_LESS_THAN = 60;
|
|
22
|
-
function is_whitespace(ch) {
|
|
23
|
-
return ch === CHAR_SPACE || ch === CHAR_TAB || ch === CHAR_NEWLINE || ch === CHAR_CARRIAGE_RETURN || ch === CHAR_FORM_FEED;
|
|
24
|
-
}
|
|
25
|
-
function is_combinator(ch) {
|
|
26
|
-
return ch === CHAR_GREATER_THAN || ch === CHAR_PLUS || ch === CHAR_TILDE;
|
|
27
|
-
}
|
|
28
|
-
function is_digit(ch) {
|
|
29
|
-
return ch >= 48 && ch <= 57;
|
|
30
|
-
}
|
|
31
|
-
function str_equals(a, b) {
|
|
32
|
-
if (a.length !== b.length) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
for (let i = 0; i < a.length; i++) {
|
|
36
|
-
let ca = a.charCodeAt(i);
|
|
37
|
-
let cb = b.charCodeAt(i);
|
|
38
|
-
cb |= 32;
|
|
39
|
-
if (ca !== cb) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
function str_starts_with(str, prefix) {
|
|
46
|
-
if (str.length < prefix.length) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
for (let i = 0; i < prefix.length; i++) {
|
|
50
|
-
let ca = str.charCodeAt(i);
|
|
51
|
-
let cb = prefix.charCodeAt(i);
|
|
52
|
-
if (ca >= 65 && ca <= 90) ca |= 32;
|
|
53
|
-
if (ca !== cb) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
function str_index_of(str, searchChar) {
|
|
60
|
-
if (searchChar.length === 0) {
|
|
61
|
-
return -1;
|
|
62
|
-
}
|
|
63
|
-
if (searchChar.length === 1) {
|
|
64
|
-
const searchCode = searchChar.charCodeAt(0);
|
|
65
|
-
for (let i = 0; i < str.length; i++) {
|
|
66
|
-
let ca = str.charCodeAt(i);
|
|
67
|
-
if (ca >= 65 && ca <= 90) ca |= 32;
|
|
68
|
-
if (ca === searchCode) {
|
|
69
|
-
return i;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return -1;
|
|
73
|
-
}
|
|
74
|
-
for (let i = 0; i <= str.length - searchChar.length; i++) {
|
|
75
|
-
let match = true;
|
|
76
|
-
for (let j = 0; j < searchChar.length; j++) {
|
|
77
|
-
let ca = str.charCodeAt(i + j);
|
|
78
|
-
let cb = searchChar.charCodeAt(j);
|
|
79
|
-
if (ca >= 65 && ca <= 90) ca |= 32;
|
|
80
|
-
if (ca !== cb) {
|
|
81
|
-
match = false;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (match) {
|
|
86
|
-
return i;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return -1;
|
|
90
|
-
}
|
|
91
|
-
function is_vendor_prefixed(source, start, end) {
|
|
92
|
-
if (start === void 0 || end === void 0) {
|
|
93
|
-
start = 0;
|
|
94
|
-
end = source.length;
|
|
95
|
-
}
|
|
96
|
-
if (source.charCodeAt(start) !== CHAR_MINUS_HYPHEN) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
if (source.charCodeAt(start + 1) === CHAR_MINUS_HYPHEN) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
let length = end - start;
|
|
103
|
-
if (length < 3) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
for (let i = start + 2; i < end; i++) {
|
|
107
|
-
if (source.charCodeAt(i) === CHAR_MINUS_HYPHEN) {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
function is_custom(str) {
|
|
114
|
-
if (str.length < 3) return false;
|
|
115
|
-
return str.charCodeAt(0) === CHAR_MINUS_HYPHEN && str.charCodeAt(1) === CHAR_MINUS_HYPHEN;
|
|
116
|
-
}
|
|
117
|
-
function strip_vendor_prefix(str) {
|
|
118
|
-
if (!is_vendor_prefixed(str)) {
|
|
119
|
-
return str;
|
|
120
|
-
}
|
|
121
|
-
for (let i = 2; i < str.length; i++) {
|
|
122
|
-
if (str.charCodeAt(i) === CHAR_MINUS_HYPHEN) {
|
|
123
|
-
return str.substring(i + 1);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return str;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
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_LESS_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, strip_vendor_prefix };
|
package/dist/token-types.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export declare const TOKEN_IDENT = 1;
|
|
2
|
-
export declare const TOKEN_FUNCTION = 2;
|
|
3
|
-
export declare const TOKEN_AT_KEYWORD = 3;
|
|
4
|
-
export declare const TOKEN_HASH = 4;
|
|
5
|
-
export declare const TOKEN_STRING = 5;
|
|
6
|
-
export declare const TOKEN_BAD_STRING = 6;
|
|
7
|
-
export declare const TOKEN_URL = 7;
|
|
8
|
-
export declare const TOKEN_BAD_URL = 8;
|
|
9
|
-
export declare const TOKEN_DELIM = 9;
|
|
10
|
-
export declare const TOKEN_NUMBER = 10;
|
|
11
|
-
export declare const TOKEN_PERCENTAGE = 11;
|
|
12
|
-
export declare const TOKEN_DIMENSION = 12;
|
|
13
|
-
export declare const TOKEN_WHITESPACE = 13;
|
|
14
|
-
export declare const TOKEN_CDO = 14;
|
|
15
|
-
export declare const TOKEN_CDC = 15;
|
|
16
|
-
export declare const TOKEN_COLON = 16;
|
|
17
|
-
export declare const TOKEN_SEMICOLON = 17;
|
|
18
|
-
export declare const TOKEN_COMMA = 18;
|
|
19
|
-
export declare const TOKEN_LEFT_BRACKET = 19;
|
|
20
|
-
export declare const TOKEN_RIGHT_BRACKET = 20;
|
|
21
|
-
export declare const TOKEN_LEFT_PAREN = 21;
|
|
22
|
-
export declare const TOKEN_RIGHT_PAREN = 22;
|
|
23
|
-
export declare const TOKEN_LEFT_BRACE = 23;
|
|
24
|
-
export declare const TOKEN_RIGHT_BRACE = 24;
|
|
25
|
-
export declare const TOKEN_COMMENT = 25;
|
|
26
|
-
export declare const TOKEN_EOF = 26;
|
|
27
|
-
export declare const TOKEN_UNICODE_RANGE = 27;
|
|
28
|
-
export type TokenType = typeof TOKEN_IDENT | typeof TOKEN_FUNCTION | typeof TOKEN_AT_KEYWORD | typeof TOKEN_HASH | typeof TOKEN_STRING | typeof TOKEN_BAD_STRING | typeof TOKEN_URL | typeof TOKEN_BAD_URL | typeof TOKEN_DELIM | typeof TOKEN_NUMBER | typeof TOKEN_PERCENTAGE | typeof TOKEN_DIMENSION | typeof TOKEN_WHITESPACE | typeof TOKEN_CDO | typeof TOKEN_CDC | typeof TOKEN_COLON | typeof TOKEN_SEMICOLON | typeof TOKEN_COMMA | typeof TOKEN_LEFT_BRACKET | typeof TOKEN_RIGHT_BRACKET | typeof TOKEN_LEFT_PAREN | typeof TOKEN_RIGHT_PAREN | typeof TOKEN_LEFT_BRACE | typeof TOKEN_RIGHT_BRACE | typeof TOKEN_COMMENT | typeof TOKEN_EOF | typeof TOKEN_UNICODE_RANGE;
|
|
29
|
-
export type Token = {
|
|
30
|
-
type: TokenType;
|
|
31
|
-
start: number;
|
|
32
|
-
end: number;
|
|
33
|
-
line: number;
|
|
34
|
-
column: number;
|
|
35
|
-
};
|
package/dist/token-types.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const TOKEN_IDENT = 1;
|
|
2
|
-
const TOKEN_FUNCTION = 2;
|
|
3
|
-
const TOKEN_AT_KEYWORD = 3;
|
|
4
|
-
const TOKEN_HASH = 4;
|
|
5
|
-
const TOKEN_STRING = 5;
|
|
6
|
-
const TOKEN_BAD_STRING = 6;
|
|
7
|
-
const TOKEN_URL = 7;
|
|
8
|
-
const TOKEN_BAD_URL = 8;
|
|
9
|
-
const TOKEN_DELIM = 9;
|
|
10
|
-
const TOKEN_NUMBER = 10;
|
|
11
|
-
const TOKEN_PERCENTAGE = 11;
|
|
12
|
-
const TOKEN_DIMENSION = 12;
|
|
13
|
-
const TOKEN_WHITESPACE = 13;
|
|
14
|
-
const TOKEN_CDO = 14;
|
|
15
|
-
const TOKEN_CDC = 15;
|
|
16
|
-
const TOKEN_COLON = 16;
|
|
17
|
-
const TOKEN_SEMICOLON = 17;
|
|
18
|
-
const TOKEN_COMMA = 18;
|
|
19
|
-
const TOKEN_LEFT_BRACKET = 19;
|
|
20
|
-
const TOKEN_RIGHT_BRACKET = 20;
|
|
21
|
-
const TOKEN_LEFT_PAREN = 21;
|
|
22
|
-
const TOKEN_RIGHT_PAREN = 22;
|
|
23
|
-
const TOKEN_LEFT_BRACE = 23;
|
|
24
|
-
const TOKEN_RIGHT_BRACE = 24;
|
|
25
|
-
const TOKEN_COMMENT = 25;
|
|
26
|
-
const TOKEN_EOF = 26;
|
|
27
|
-
const TOKEN_UNICODE_RANGE = 27;
|
|
28
|
-
|
|
29
|
-
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 };
|
package/dist/walk.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { CSSNode } from './css-node';
|
|
2
|
-
export declare const SKIP: unique symbol;
|
|
3
|
-
export declare const BREAK: unique symbol;
|
|
4
|
-
type WalkCallback = (node: CSSNode, depth: number) => void | typeof SKIP | typeof BREAK;
|
|
5
|
-
/**
|
|
6
|
-
* Walk the AST in depth-first order, calling the callback for each node.
|
|
7
|
-
* Return SKIP to skip children, BREAK to stop traversal. See API.md for examples.
|
|
8
|
-
*
|
|
9
|
-
* @param node - The root node to start walking from
|
|
10
|
-
* @param callback - Function called for each node. Receives the node and its nesting depth.
|
|
11
|
-
* Depth increments only for STYLE_RULE and AT_RULE nodes (tracks rule nesting, not tree depth).
|
|
12
|
-
* @param depth - Starting depth (default: 0)
|
|
13
|
-
*/
|
|
14
|
-
export declare function walk(node: CSSNode, callback: WalkCallback, depth?: number): boolean;
|
|
15
|
-
type WalkEnterLeaveCallback = (node: CSSNode) => void | typeof SKIP | typeof BREAK;
|
|
16
|
-
interface WalkEnterLeaveOptions {
|
|
17
|
-
enter?: WalkEnterLeaveCallback;
|
|
18
|
-
leave?: WalkEnterLeaveCallback;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Walk the AST in depth-first order, calling enter before visiting children and leave after.
|
|
22
|
-
* Return SKIP in enter to skip children (leave still called), BREAK to stop (leave NOT called). See API.md for examples.
|
|
23
|
-
*
|
|
24
|
-
* @param node - The root node to start walking from
|
|
25
|
-
* @param options - Object with optional enter and leave callback functions
|
|
26
|
-
*/
|
|
27
|
-
export declare function traverse(node: CSSNode, { enter, leave }?: WalkEnterLeaveOptions): boolean;
|
|
28
|
-
export {};
|
package/dist/walk.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { STYLE_RULE, AT_RULE } from './arena.js';
|
|
2
|
-
|
|
3
|
-
const SKIP = /* @__PURE__ */ Symbol("SKIP");
|
|
4
|
-
const BREAK = /* @__PURE__ */ Symbol("BREAK");
|
|
5
|
-
function walk(node, callback, depth = 0) {
|
|
6
|
-
const result = callback(node, depth);
|
|
7
|
-
if (result === BREAK) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
if (result === SKIP) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
let child_depth = depth;
|
|
14
|
-
if (node.type === STYLE_RULE || node.type === AT_RULE) {
|
|
15
|
-
child_depth = depth + 1;
|
|
16
|
-
}
|
|
17
|
-
let child = node.first_child;
|
|
18
|
-
while (child) {
|
|
19
|
-
const should_continue = walk(child, callback, child_depth);
|
|
20
|
-
if (!should_continue) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
child = child.next_sibling;
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
const NOOP = function() {
|
|
28
|
-
};
|
|
29
|
-
function traverse(node, { enter = NOOP, leave = NOOP } = {}) {
|
|
30
|
-
const enter_result = enter(node);
|
|
31
|
-
if (enter_result === BREAK) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
if (enter_result !== SKIP) {
|
|
35
|
-
let child = node.first_child;
|
|
36
|
-
while (child) {
|
|
37
|
-
const should_continue = traverse(child, { enter, leave });
|
|
38
|
-
if (!should_continue) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
child = child.next_sibling;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const leave_result = leave(node);
|
|
45
|
-
if (leave_result === BREAK) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export { BREAK, SKIP, traverse, walk };
|