@projectwallace/css-parser 0.17.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{css-node-B3EzCweR.js → css-node-Cf8K9nWd.js} +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{node-types-BRnQyc9B.d.ts → node-types-D41wr72y.d.ts} +8 -4
- package/dist/parse-anplusb.d.ts +1 -1
- package/dist/parse-anplusb.js +1 -1
- package/dist/parse-atrule-prelude.d.ts +4 -2
- package/dist/parse-atrule-prelude.js +65 -67
- package/dist/parse-declaration.d.ts +1 -1
- package/dist/parse-declaration.js +1 -1
- package/dist/parse-selector.d.ts +1 -1
- package/dist/parse-selector.js +1 -1
- package/dist/parse-value.d.ts +2 -11
- package/dist/parse-value.js +6 -162
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +1 -1
- package/dist/value-node-parser-CZ47v3hp.js +176 -0
- package/dist/walk.d.ts +1 -1
- package/dist/walk.js +1 -1
- package/package.json +1 -1
|
@@ -161,7 +161,7 @@ var CSSNode = class CSSNode {
|
|
|
161
161
|
/** Alias for `name` on declarations ("color" in "color: blue"), more semantic than `name` there. */
|
|
162
162
|
get property() {
|
|
163
163
|
let { type } = this;
|
|
164
|
-
if (type !== 4 && type !== 33) return;
|
|
164
|
+
if (type !== 4 && type !== 33 && type !== 57) return;
|
|
165
165
|
return this.get_content();
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
@@ -174,6 +174,7 @@ var CSSNode = class CSSNode {
|
|
|
174
174
|
if (type === 34) return text;
|
|
175
175
|
if (type === 4 && first_child) return first_child;
|
|
176
176
|
if (type === 33) return first_child ?? null;
|
|
177
|
+
if (type === 57) return first_child?.first_child ?? null;
|
|
177
178
|
if (type === 12) return parse_dimension(text).value;
|
|
178
179
|
if (type === 11) return Number(text);
|
|
179
180
|
if (type === 18) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { B as SUPPORTS_QUERY, C as NESTING_SELECTOR, D as OPERATOR, E as NUMBER, F as SELECTOR_LIST, G as VALUE, H as UNICODE_RANGE, I as STRING, L as STYLESHEET, M as PSEUDO_ELEMENT_SELECTOR, N as RAW, O as PARENTHESIS, P as SELECTOR, R as STYLE_RULE, S as MEDIA_TYPE, T as NTH_SELECTOR, U as UNIVERSAL_SELECTOR, V as TYPE_SELECTOR, W as URL, _ as ID_SELECTOR, a as CLASS_SELECTOR, b as MEDIA_FEATURE, c as CONTAINER_QUERY, d as DIMENSION, f as FEATURE_RANGE, g as IDENTIFIER, h as HASH, i as BLOCK, j as PSEUDO_CLASS_SELECTOR, k as PRELUDE_OPERATOR, m as FUNCTION, n as AT_RULE, o as COMBINATOR, p as FLAG_IMPORTANT, r as AT_RULE_PRELUDE, s as COMMENT, t as ATTRIBUTE_SELECTOR, u as DECLARATION, v as LANG_SELECTOR, w as NTH_OF_SELECTOR, x as MEDIA_QUERY, y as LAYER_NAME, z as SUPPORTS_DECLARATION } from "./arena-Bx5vp6Sl.js";
|
|
2
2
|
import { NODE_TYPES } from "./constants.js";
|
|
3
3
|
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-DeZYFa9R.js";
|
|
4
|
-
import { $ as is_class_selector, A as PreludeSelectorList, At as is_stylesheet, B as SupportsDeclaration, Bt as TYPE_NAMES, C as NestingSelector, Ct as is_pseudo_class_selector, D as Operator, Dt as is_selector, E as Number, Et as is_rule, F as Selector, Ft as is_universal_selector, G as UniversalSelector, H as ToPlain, I as SelectorList, It as is_url, J as WithChildren, K as Url, L as SelectorNode, Lt as is_value, M as PseudoElementSelector, Mt as is_supports_query, N as Raw, Nt as is_type_selector, O as Parenthesis, Ot as is_selector_list, P as Rule, Pt as is_unicode_range, Q as is_block, R as String, Rt as CloneOptions, S as MediaType, St as is_prelude_selectorlist, T as NthSelector, Tt as is_raw, U as TypeSelector, V as SupportsQuery, W as UnicodeRange, X as is_atrule_prelude, Y as is_atrule, Z as is_attribute_selector, _ as Identifier, _t as is_nth_selector, a as Block, at as is_feature_range, b as MediaFeature, bt as is_parenthesis, c as Combinator, ct as is_id_selector, d as Declaration, dt as is_layer_name, et as is_combinator, f as Dimension, ft as is_media_feature, g as IdSelector, gt as is_nth_of_selector, h as Hash, ht as is_nesting_selector, i as AttributeSelector, it as is_dimension, j as PseudoClassSelector, jt as is_supports_declaration, k as PreludeOperator, kt as is_string, l as Comment, lt as is_identifier, m as Function, mt as is_media_type, n as Atrule, nt as is_container_query, o as CSSNode, ot as is_function, p as FeatureRange, pt as is_media_query, q as Value, r as AtrulePrelude, rt as is_declaration, s as ClassSelector, st as is_hash, t as AnyNode, tt as is_comment, u as ContainerQuery, ut as is_lang_selector, v as LangSelector, vt as is_number, w as NthOfSelector, wt as is_pseudo_element_selector, x as MediaQuery, xt as is_prelude_operator, y as LayerName, yt as is_operator, z as StyleSheet, zt as PlainCSSNode } from "./node-types-
|
|
4
|
+
import { $ as is_class_selector, A as PreludeSelectorList, At as is_stylesheet, B as SupportsDeclaration, Bt as TYPE_NAMES, C as NestingSelector, Ct as is_pseudo_class_selector, D as Operator, Dt as is_selector, E as Number, Et as is_rule, F as Selector, Ft as is_universal_selector, G as UniversalSelector, H as ToPlain, I as SelectorList, It as is_url, J as WithChildren, K as Url, L as SelectorNode, Lt as is_value, M as PseudoElementSelector, Mt as is_supports_query, N as Raw, Nt as is_type_selector, O as Parenthesis, Ot as is_selector_list, P as Rule, Pt as is_unicode_range, Q as is_block, R as String, Rt as CloneOptions, S as MediaType, St as is_prelude_selectorlist, T as NthSelector, Tt as is_raw, U as TypeSelector, V as SupportsQuery, W as UnicodeRange, X as is_atrule_prelude, Y as is_atrule, Z as is_attribute_selector, _ as Identifier, _t as is_nth_selector, a as Block, at as is_feature_range, b as MediaFeature, bt as is_parenthesis, c as Combinator, ct as is_id_selector, d as Declaration, dt as is_layer_name, et as is_combinator, f as Dimension, ft as is_media_feature, g as IdSelector, gt as is_nth_of_selector, h as Hash, ht as is_nesting_selector, i as AttributeSelector, it as is_dimension, j as PseudoClassSelector, jt as is_supports_declaration, k as PreludeOperator, kt as is_string, l as Comment, lt as is_identifier, m as Function, mt as is_media_type, n as Atrule, nt as is_container_query, o as CSSNode, ot as is_function, p as FeatureRange, pt as is_media_query, q as Value, r as AtrulePrelude, rt as is_declaration, s as ClassSelector, st as is_hash, t as AnyNode, tt as is_comment, u as ContainerQuery, ut as is_lang_selector, v as LangSelector, vt as is_number, w as NthOfSelector, wt as is_pseudo_element_selector, x as MediaQuery, xt as is_prelude_operator, y as LayerName, yt as is_operator, z as StyleSheet, zt as PlainCSSNode } from "./node-types-D41wr72y.js";
|
|
5
5
|
import { ParserOptions, parse } from "./parse.js";
|
|
6
6
|
import { parse_selector, parse_selector_list } from "./parse-selector.js";
|
|
7
7
|
import { parse_atrule_prelude } from "./parse-atrule-prelude.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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-BiRLfVbm.js";
|
|
2
2
|
import { A as PSEUDO_CLASS_SELECTOR, B as TYPE_SELECTOR, C as NESTING_SELECTOR, D as OPERATOR, E as NUMBER, F as STRING, H as UNIVERSAL_SELECTOR, I as STYLESHEET, L as STYLE_RULE, M as RAW, N as SELECTOR, O as PARENTHESIS, P as SELECTOR_LIST, R as SUPPORTS_DECLARATION, S as MEDIA_TYPE, T as NTH_SELECTOR, U as URL, V as UNICODE_RANGE, W as VALUE, _ as ID_SELECTOR, a as CLASS_SELECTOR, b as MEDIA_FEATURE, c as CONTAINER_QUERY, d as DIMENSION, f as FEATURE_RANGE, g as IDENTIFIER, h as HASH, i as BLOCK, j as PSEUDO_ELEMENT_SELECTOR, k as PRELUDE_OPERATOR, m as FUNCTION, n as AT_RULE, o as COMBINATOR, p as FLAG_IMPORTANT, r as AT_RULE_PRELUDE, s as COMMENT, t as ATTRIBUTE_SELECTOR, u as DECLARATION, v as LANG_SELECTOR, w as NTH_OF_SELECTOR, x as MEDIA_QUERY, y as LAYER_NAME, z as SUPPORTS_QUERY } from "./arena-CFwM4uQs.js";
|
|
3
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-ouWXNHdx.js";
|
|
4
|
-
import { n as TYPE_NAMES } from "./css-node-
|
|
4
|
+
import { n as TYPE_NAMES } from "./css-node-Cf8K9nWd.js";
|
|
5
5
|
import { parse_selector, parse_selector_list } from "./parse-selector.js";
|
|
6
6
|
import { parse_atrule_prelude } from "./parse-atrule-prelude.js";
|
|
7
7
|
import { parse_value } from "./parse-value.js";
|
|
@@ -192,7 +192,7 @@ type Block = WithClone<CSSNode & WithChildren<Raw | Declaration | Atrule | Rule>
|
|
|
192
192
|
}>;
|
|
193
193
|
type Comment = Leaf<typeof COMMENT, 'Comment'>;
|
|
194
194
|
type Raw = Leaf<typeof RAW, 'Raw'>;
|
|
195
|
-
type ValueLike = Function | Identifier | Operator | Parenthesis | Url | UnicodeRange | String | Hash | Dimension | Number;
|
|
195
|
+
type ValueLike = Function | Identifier | Operator | Parenthesis | Url | UnicodeRange | String | Hash | Dimension | Number | SelectorList | SupportsDeclaration;
|
|
196
196
|
type Identifier = Leaf<typeof IDENTIFIER, 'Identifier', {
|
|
197
197
|
readonly name: string;
|
|
198
198
|
}>;
|
|
@@ -294,7 +294,7 @@ type LangSelector = Leaf<typeof LANG_SELECTOR, 'Lang', {
|
|
|
294
294
|
/** `"nl"`, `en-US` */
|
|
295
295
|
readonly name: string | null;
|
|
296
296
|
}>;
|
|
297
|
-
type AtrulePrelude = WithClone<CSSNode & WithChildren<Raw | MediaQuery | MediaType | ContainerQuery | SupportsQuery | LayerName | PreludeOperator | PreludeSelectorList | Parenthesis | Url> & {
|
|
297
|
+
type AtrulePrelude = WithClone<CSSNode & WithChildren<Raw | MediaQuery | MediaType | ContainerQuery | SupportsQuery | LayerName | PreludeOperator | PreludeSelectorList | Parenthesis | Url | Function | Identifier | String> & {
|
|
298
298
|
readonly type: typeof AT_RULE_PRELUDE;
|
|
299
299
|
readonly type_name: 'AtrulePrelude';
|
|
300
300
|
}>;
|
|
@@ -312,7 +312,7 @@ type MediaType = Leaf<typeof MEDIA_TYPE, 'MediaType', {
|
|
|
312
312
|
/** Media type text, e.g. "screen", "print" */
|
|
313
313
|
readonly value: string;
|
|
314
314
|
}>;
|
|
315
|
-
type ContainerQuery = WithClone<CSSNode & WithChildren<Identifier | MediaFeature | Function> & {
|
|
315
|
+
type ContainerQuery = WithClone<CSSNode & WithChildren<Identifier | MediaFeature | Function | PreludeOperator> & {
|
|
316
316
|
readonly type: typeof CONTAINER_QUERY;
|
|
317
317
|
readonly type_name: 'ContainerQuery';
|
|
318
318
|
}>;
|
|
@@ -325,6 +325,10 @@ type SupportsQuery = WithClone<CSSNode & WithChildren<SupportsDeclaration> & {
|
|
|
325
325
|
type SupportsDeclaration = WithClone<CSSNode & WithChildren<Declaration> & {
|
|
326
326
|
readonly type: typeof SUPPORTS_DECLARATION;
|
|
327
327
|
readonly type_name: 'SupportsDeclaration';
|
|
328
|
+
/** Property name, e.g. "display" from "(display: flex)" */
|
|
329
|
+
readonly property: string;
|
|
330
|
+
/** VALUE node for the declaration's value, e.g. "flex" from "(display: flex)" */
|
|
331
|
+
readonly value: Value | null;
|
|
328
332
|
}>;
|
|
329
333
|
type LayerName = Leaf<typeof LAYER_NAME, 'Layer', {
|
|
330
334
|
readonly name: string;
|
|
@@ -341,7 +345,7 @@ type PreludeSelectorList = Leaf<typeof PRELUDE_SELECTORLIST, 'PreludeSelectorLis
|
|
|
341
345
|
readonly value: string;
|
|
342
346
|
}>;
|
|
343
347
|
type PreludeOperator = Leaf<typeof PRELUDE_OPERATOR, 'Operator'>;
|
|
344
|
-
type FeatureRange = WithClone<CSSNode & WithChildren<Dimension |
|
|
348
|
+
type FeatureRange = WithClone<CSSNode & WithChildren<Dimension | PreludeOperator> & {
|
|
345
349
|
readonly type: typeof FEATURE_RANGE;
|
|
346
350
|
readonly type_name: 'MediaFeatureRange';
|
|
347
351
|
/** The feature name in a range comparison, e.g. "width" from "(width >= 400px)" */
|
package/dist/parse-anplusb.d.ts
CHANGED
package/dist/parse-anplusb.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as Lexer } from "./tokenize-BiRLfVbm.js";
|
|
2
2
|
import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
|
|
3
3
|
import { o as str_equals, s as str_index_of } from "./parse-dimension-ouWXNHdx.js";
|
|
4
|
-
import { t as CSSNode } from "./css-node-
|
|
4
|
+
import { t as CSSNode } from "./css-node-Cf8K9nWd.js";
|
|
5
5
|
//#region src/parse-anplusb.ts
|
|
6
6
|
/** @internal */
|
|
7
7
|
var ANplusBParser = class {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as CSSDataArena } from "./arena-Bx5vp6Sl.js";
|
|
2
|
-
import { t as AnyNode } from "./node-types-
|
|
2
|
+
import { t as AnyNode } from "./node-types-D41wr72y.js";
|
|
3
3
|
//#region src/parse-atrule-prelude.d.ts
|
|
4
4
|
/** @internal */
|
|
5
5
|
declare class AtRulePreludeParser {
|
|
@@ -7,12 +7,15 @@ declare class AtRulePreludeParser {
|
|
|
7
7
|
private arena;
|
|
8
8
|
private source;
|
|
9
9
|
private prelude_end;
|
|
10
|
+
private value_node_parser;
|
|
11
|
+
private selector_parser;
|
|
10
12
|
constructor(arena: CSSDataArena, source: string);
|
|
11
13
|
parse_prelude(at_rule_name: string, start: number, end: number, line?: number, column?: number): number[];
|
|
12
14
|
private parse_prelude_dispatch;
|
|
13
15
|
private parse_media_query_list;
|
|
14
16
|
private create_node;
|
|
15
17
|
private is_and_or_not;
|
|
18
|
+
private parse_function_condition;
|
|
16
19
|
private parse_single_media_query;
|
|
17
20
|
private parse_media_feature;
|
|
18
21
|
private parse_container_query;
|
|
@@ -30,7 +33,6 @@ declare class AtRulePreludeParser {
|
|
|
30
33
|
private skip_whitespace;
|
|
31
34
|
private peek_token_type;
|
|
32
35
|
private next_token;
|
|
33
|
-
private parse_value_token;
|
|
34
36
|
private parse_feature_value;
|
|
35
37
|
private parse_namespace_prelude;
|
|
36
38
|
private parse_scope_prelude;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { t as Lexer } from "./tokenize-BiRLfVbm.js";
|
|
2
2
|
import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
|
|
3
|
-
import {
|
|
4
|
-
import { t as CSSNode } from "./css-node-
|
|
3
|
+
import { l as strip_vendor_prefix, o as str_equals } from "./parse-dimension-ouWXNHdx.js";
|
|
4
|
+
import { t as CSSNode } from "./css-node-Cf8K9nWd.js";
|
|
5
5
|
import { i as trim_boundaries, n as skip_whitespace_and_comments_forward } from "./parse-utils-D7srNG13.js";
|
|
6
|
+
import { SelectorParser } from "./parse-selector.js";
|
|
7
|
+
import { t as ValueNodeParser } from "./value-node-parser-CZ47v3hp.js";
|
|
6
8
|
//#region src/parse-atrule-prelude.ts
|
|
7
9
|
/** @internal */
|
|
8
10
|
var AtRulePreludeParser = class {
|
|
@@ -10,11 +12,15 @@ var AtRulePreludeParser = class {
|
|
|
10
12
|
arena;
|
|
11
13
|
source;
|
|
12
14
|
prelude_end;
|
|
15
|
+
value_node_parser;
|
|
16
|
+
selector_parser;
|
|
13
17
|
constructor(arena, source) {
|
|
14
18
|
this.arena = arena;
|
|
15
19
|
this.source = source;
|
|
16
20
|
this.lexer = new Lexer(source);
|
|
17
21
|
this.prelude_end = 0;
|
|
22
|
+
this.value_node_parser = new ValueNodeParser(arena, source);
|
|
23
|
+
this.selector_parser = new SelectorParser(arena, source);
|
|
18
24
|
}
|
|
19
25
|
parse_prelude(at_rule_name, start, end, line = 1, column = 1) {
|
|
20
26
|
this.prelude_end = end;
|
|
@@ -64,18 +70,58 @@ var AtRulePreludeParser = class {
|
|
|
64
70
|
is_and_or_not(str) {
|
|
65
71
|
return str_equals("and", str) || str_equals("or", str) || str_equals("not", str);
|
|
66
72
|
}
|
|
73
|
+
parse_function_condition() {
|
|
74
|
+
let func_name = this.source.substring(this.lexer.token_start, this.lexer.token_end - 1);
|
|
75
|
+
let func_start = this.lexer.token_start;
|
|
76
|
+
let content_start = this.lexer.token_end;
|
|
77
|
+
let paren_depth = 1;
|
|
78
|
+
let func_end = this.lexer.token_end;
|
|
79
|
+
let content_end = content_start;
|
|
80
|
+
while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
|
|
81
|
+
this.next_token();
|
|
82
|
+
let inner_token = this.lexer.token_type;
|
|
83
|
+
if (inner_token === 21 || inner_token === 2) paren_depth++;
|
|
84
|
+
else if (inner_token === 22) {
|
|
85
|
+
paren_depth--;
|
|
86
|
+
if (paren_depth === 0) {
|
|
87
|
+
content_end = this.lexer.token_start;
|
|
88
|
+
func_end = this.lexer.token_end;
|
|
89
|
+
}
|
|
90
|
+
} else if (inner_token === 26) break;
|
|
91
|
+
}
|
|
92
|
+
let func_node = this.create_node(15, func_start, func_end);
|
|
93
|
+
this.arena.set_content_start_delta(func_node, 0);
|
|
94
|
+
this.arena.set_content_length(func_node, func_name.length);
|
|
95
|
+
this.arena.set_value_start_delta(func_node, content_start - func_start);
|
|
96
|
+
this.arena.set_value_length(func_node, content_end - content_start);
|
|
97
|
+
if (str_equals("selector", func_name)) {
|
|
98
|
+
let selector_list = this.selector_parser.parse_selector(content_start, content_end, this.lexer.line, this.lexer.column);
|
|
99
|
+
if (selector_list !== null) this.arena.set_first_child(func_node, selector_list);
|
|
100
|
+
} else if (str_equals("style", func_name)) {
|
|
101
|
+
let colon_pos = this.find_colon_at_depth_zero(content_start, content_end);
|
|
102
|
+
if (colon_pos !== -1) {
|
|
103
|
+
let decl_child = this.create_supports_declaration(content_start, content_end, colon_pos);
|
|
104
|
+
this.arena.set_first_child(func_node, decl_child);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return func_node;
|
|
108
|
+
}
|
|
67
109
|
parse_single_media_query() {
|
|
68
110
|
let query_start = this.lexer.pos;
|
|
69
111
|
this.skip_whitespace();
|
|
70
112
|
if (this.lexer.pos >= this.prelude_end) return null;
|
|
113
|
+
let first_component = 0;
|
|
114
|
+
let last_component = 0;
|
|
71
115
|
const saved_token_start = this.lexer.save_position();
|
|
72
116
|
this.next_token();
|
|
73
117
|
if (this.lexer.token_type === 1) {
|
|
74
118
|
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
75
|
-
if (
|
|
119
|
+
if (str_equals("only", text) || str_equals("not", text)) {
|
|
120
|
+
let modifier = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
121
|
+
first_component = modifier;
|
|
122
|
+
last_component = modifier;
|
|
123
|
+
} else this.lexer.restore_position(saved_token_start);
|
|
76
124
|
} else this.lexer.restore_position(saved_token_start);
|
|
77
|
-
let first_component = 0;
|
|
78
|
-
let last_component = 0;
|
|
79
125
|
while (this.lexer.pos < this.prelude_end) {
|
|
80
126
|
this.skip_whitespace();
|
|
81
127
|
if (this.lexer.pos >= this.prelude_end) break;
|
|
@@ -107,7 +153,7 @@ var AtRulePreludeParser = class {
|
|
|
107
153
|
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
108
154
|
this.next_token();
|
|
109
155
|
let token_type = this.lexer.token_type;
|
|
110
|
-
if (token_type === 21) depth++;
|
|
156
|
+
if (token_type === 21 || token_type === 2) depth++;
|
|
111
157
|
else if (token_type === 22) depth--;
|
|
112
158
|
}
|
|
113
159
|
if (depth !== 0) return null;
|
|
@@ -169,32 +215,8 @@ var AtRulePreludeParser = class {
|
|
|
169
215
|
let token_type = this.lexer.token_type;
|
|
170
216
|
let component = null;
|
|
171
217
|
if (token_type === 21) component = this.parse_media_feature();
|
|
172
|
-
else if (token_type === 2)
|
|
173
|
-
|
|
174
|
-
let func_start = this.lexer.token_start;
|
|
175
|
-
let content_start = this.lexer.token_end;
|
|
176
|
-
let paren_depth = 1;
|
|
177
|
-
let func_end = this.lexer.token_end;
|
|
178
|
-
let content_end = content_start;
|
|
179
|
-
while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
|
|
180
|
-
this.next_token();
|
|
181
|
-
let inner_token = this.lexer.token_type;
|
|
182
|
-
if (inner_token === 21 || inner_token === 2) paren_depth++;
|
|
183
|
-
else if (inner_token === 22) {
|
|
184
|
-
paren_depth--;
|
|
185
|
-
if (paren_depth === 0) {
|
|
186
|
-
content_end = this.lexer.token_start;
|
|
187
|
-
func_end = this.lexer.token_end;
|
|
188
|
-
}
|
|
189
|
-
} else if (inner_token === 26) break;
|
|
190
|
-
}
|
|
191
|
-
let func_node = this.create_node(15, func_start, func_end);
|
|
192
|
-
this.arena.set_content_start_delta(func_node, 0);
|
|
193
|
-
this.arena.set_content_length(func_node, func_name.length);
|
|
194
|
-
this.arena.set_value_start_delta(func_node, content_start - func_start);
|
|
195
|
-
this.arena.set_value_length(func_node, content_end - content_start);
|
|
196
|
-
component = func_node;
|
|
197
|
-
} else if (token_type === 1) {
|
|
218
|
+
else if (token_type === 2) component = this.parse_function_condition();
|
|
219
|
+
else if (token_type === 1) {
|
|
198
220
|
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
199
221
|
if (this.is_and_or_not(text)) component = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
200
222
|
else component = this.create_node(10, this.lexer.token_start, this.lexer.token_end);
|
|
@@ -224,7 +246,7 @@ var AtRulePreludeParser = class {
|
|
|
224
246
|
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
225
247
|
this.next_token();
|
|
226
248
|
let inner_token_type = this.lexer.token_type;
|
|
227
|
-
if (inner_token_type === 21) depth++;
|
|
249
|
+
if (inner_token_type === 21 || inner_token_type === 2) depth++;
|
|
228
250
|
else if (inner_token_type === 22) depth--;
|
|
229
251
|
}
|
|
230
252
|
if (depth === 0) {
|
|
@@ -249,7 +271,7 @@ var AtRulePreludeParser = class {
|
|
|
249
271
|
let op = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
250
272
|
nodes.push(op);
|
|
251
273
|
}
|
|
252
|
-
}
|
|
274
|
+
} else if (token_type === 2) nodes.push(this.parse_function_condition());
|
|
253
275
|
}
|
|
254
276
|
return nodes;
|
|
255
277
|
}
|
|
@@ -283,6 +305,8 @@ var AtRulePreludeParser = class {
|
|
|
283
305
|
this.arena.set_first_child(decl, value_node);
|
|
284
306
|
}
|
|
285
307
|
let supports_decl = this.create_node(57, content_start, content_end);
|
|
308
|
+
this.arena.set_content_start_delta(supports_decl, prop_trimmed[0] - content_start);
|
|
309
|
+
this.arena.set_content_length(supports_decl, prop_trimmed[1] - prop_trimmed[0]);
|
|
286
310
|
this.arena.set_first_child(supports_decl, decl);
|
|
287
311
|
return supports_decl;
|
|
288
312
|
}
|
|
@@ -446,6 +470,11 @@ var AtRulePreludeParser = class {
|
|
|
446
470
|
if (trimmed) {
|
|
447
471
|
this.arena.set_value_start_delta(supports_node, trimmed[0] - supports_start);
|
|
448
472
|
this.arena.set_value_length(supports_node, trimmed[1] - trimmed[0]);
|
|
473
|
+
let colon_pos = this.find_colon_at_depth_zero(trimmed[0], trimmed[1]);
|
|
474
|
+
if (colon_pos !== -1) {
|
|
475
|
+
let decl_child = this.create_supports_declaration(trimmed[0], trimmed[1], colon_pos);
|
|
476
|
+
this.arena.set_first_child(supports_node, decl_child);
|
|
477
|
+
}
|
|
449
478
|
}
|
|
450
479
|
return supports_node;
|
|
451
480
|
}
|
|
@@ -470,39 +499,8 @@ var AtRulePreludeParser = class {
|
|
|
470
499
|
}
|
|
471
500
|
return this.lexer.next_token_fast(false);
|
|
472
501
|
}
|
|
473
|
-
parse_value_token() {
|
|
474
|
-
switch (this.lexer.token_type) {
|
|
475
|
-
case 1: return this.create_node(10, this.lexer.token_start, this.lexer.token_end);
|
|
476
|
-
case 10: return this.create_node(11, this.lexer.token_start, this.lexer.token_end);
|
|
477
|
-
case 11:
|
|
478
|
-
case 12: return this.create_node(12, this.lexer.token_start, this.lexer.token_end);
|
|
479
|
-
case 5: return this.create_node(13, this.lexer.token_start, this.lexer.token_end);
|
|
480
|
-
default: return null;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
502
|
parse_feature_value(start, end) {
|
|
484
|
-
|
|
485
|
-
this.lexer.seek(start, this.lexer.line, this.lexer.column);
|
|
486
|
-
let first_node = 0;
|
|
487
|
-
let last_node = 0;
|
|
488
|
-
while (this.lexer.pos < end) {
|
|
489
|
-
this.lexer.next_token_fast(false);
|
|
490
|
-
if (this.lexer.token_start >= end) break;
|
|
491
|
-
let all_whitespace = true;
|
|
492
|
-
for (let i = this.lexer.token_start; i < this.lexer.token_end && i < end; i++) if (!is_whitespace(this.source.charCodeAt(i))) {
|
|
493
|
-
all_whitespace = false;
|
|
494
|
-
break;
|
|
495
|
-
}
|
|
496
|
-
if (all_whitespace) continue;
|
|
497
|
-
let node = this.parse_value_token();
|
|
498
|
-
if (node !== null) {
|
|
499
|
-
if (first_node === 0) first_node = node;
|
|
500
|
-
else this.arena.set_next_sibling(last_node, node);
|
|
501
|
-
last_node = node;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
this.lexer.restore_position(saved_position);
|
|
505
|
-
return first_node;
|
|
503
|
+
return this.value_node_parser.parse_chain(start, end, this.lexer.line, this.lexer.column);
|
|
506
504
|
}
|
|
507
505
|
parse_namespace_prelude() {
|
|
508
506
|
let nodes = [];
|
|
@@ -531,7 +529,7 @@ var AtRulePreludeParser = class {
|
|
|
531
529
|
let depth = 1;
|
|
532
530
|
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
533
531
|
this.next_token();
|
|
534
|
-
if (this.lexer.token_type === 21) depth++;
|
|
532
|
+
if (this.lexer.token_type === 21 || this.lexer.token_type === 2) depth++;
|
|
535
533
|
else if (this.lexer.token_type === 22) depth--;
|
|
536
534
|
}
|
|
537
535
|
let content_end = this.lexer.token_start;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { l as CSSDataArena } from "./arena-Bx5vp6Sl.js";
|
|
2
2
|
import { n as Lexer } from "./tokenize-DeZYFa9R.js";
|
|
3
|
-
import { d as Declaration } from "./node-types-
|
|
3
|
+
import { d as Declaration } from "./node-types-D41wr72y.js";
|
|
4
4
|
//#region src/parse-declaration.d.ts
|
|
5
5
|
/** @internal */
|
|
6
6
|
declare class DeclarationParser {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as Lexer } from "./tokenize-BiRLfVbm.js";
|
|
2
2
|
import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
|
|
3
3
|
import { i as is_vendor_prefixed } from "./parse-dimension-ouWXNHdx.js";
|
|
4
|
-
import { t as CSSNode } from "./css-node-
|
|
4
|
+
import { t as CSSNode } from "./css-node-Cf8K9nWd.js";
|
|
5
5
|
import { i as trim_boundaries } from "./parse-utils-D7srNG13.js";
|
|
6
6
|
import { ValueParser } from "./parse-value.js";
|
|
7
7
|
//#region src/parse-declaration.ts
|
package/dist/parse-selector.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as CSSDataArena } from "./arena-Bx5vp6Sl.js";
|
|
2
|
-
import { F as Selector, I as SelectorList } from "./node-types-
|
|
2
|
+
import { F as Selector, I as SelectorList } from "./node-types-D41wr72y.js";
|
|
3
3
|
//#region src/parse-selector.d.ts
|
|
4
4
|
/** @internal */
|
|
5
5
|
declare class SelectorParser {
|
package/dist/parse-selector.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as Lexer } from "./tokenize-BiRLfVbm.js";
|
|
2
2
|
import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
|
|
3
3
|
import { a as is_whitespace, n as is_combinator, o as str_equals } from "./parse-dimension-ouWXNHdx.js";
|
|
4
|
-
import { t as CSSNode } from "./css-node-
|
|
4
|
+
import { t as CSSNode } from "./css-node-Cf8K9nWd.js";
|
|
5
5
|
import { n as skip_whitespace_and_comments_forward, r as skip_whitespace_forward, t as skip_whitespace_and_comments_backward } from "./parse-utils-D7srNG13.js";
|
|
6
6
|
import { ANplusBParser } from "./parse-anplusb.js";
|
|
7
7
|
//#region src/parse-selector.ts
|
package/dist/parse-value.d.ts
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import { l as CSSDataArena } from "./arena-Bx5vp6Sl.js";
|
|
2
|
-
import { q as Value } from "./node-types-
|
|
2
|
+
import { q as Value } from "./node-types-D41wr72y.js";
|
|
3
3
|
//#region src/parse-value.d.ts
|
|
4
4
|
/** @internal */
|
|
5
5
|
declare class ValueParser {
|
|
6
|
-
private
|
|
6
|
+
private nodes;
|
|
7
7
|
private arena;
|
|
8
|
-
private source;
|
|
9
|
-
private value_end;
|
|
10
8
|
constructor(arena: CSSDataArena, source: string);
|
|
11
9
|
parse_value(start: number, end: number, start_line: number, start_column: number): number;
|
|
12
|
-
private is_whitespace_inline;
|
|
13
|
-
private parse_value_node;
|
|
14
|
-
private create_node;
|
|
15
|
-
private create_operator_node;
|
|
16
|
-
private parse_operator_node;
|
|
17
|
-
private parse_function_node;
|
|
18
|
-
private parse_parenthesis_node;
|
|
19
10
|
}
|
|
20
11
|
/**
|
|
21
12
|
* Parse a CSS declaration value string and return a VALUE node
|
package/dist/parse-value.js
CHANGED
|
@@ -1,181 +1,25 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-BiRLfVbm.js";
|
|
2
1
|
import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
2
|
+
import { t as CSSNode } from "./css-node-Cf8K9nWd.js";
|
|
3
|
+
import { t as ValueNodeParser } from "./value-node-parser-CZ47v3hp.js";
|
|
5
4
|
//#region src/parse-value.ts
|
|
6
5
|
/** @internal */
|
|
7
6
|
var ValueParser = class {
|
|
8
|
-
|
|
7
|
+
nodes;
|
|
9
8
|
arena;
|
|
10
|
-
source;
|
|
11
|
-
value_end;
|
|
12
9
|
constructor(arena, source) {
|
|
13
10
|
this.arena = arena;
|
|
14
|
-
this.
|
|
15
|
-
this.lexer = new Lexer(source);
|
|
16
|
-
this.value_end = 0;
|
|
11
|
+
this.nodes = new ValueNodeParser(arena, source);
|
|
17
12
|
}
|
|
18
13
|
parse_value(start, end, start_line, start_column) {
|
|
19
|
-
this.
|
|
20
|
-
this.lexer.seek(start, start_line, start_column);
|
|
21
|
-
let first_node = 0;
|
|
22
|
-
let last_node = 0;
|
|
23
|
-
while (this.lexer.pos < this.value_end) {
|
|
24
|
-
this.lexer.next_token_fast(false);
|
|
25
|
-
if (this.lexer.token_start >= this.value_end) break;
|
|
26
|
-
if (this.lexer.token_type === 26) break;
|
|
27
|
-
if (this.is_whitespace_inline()) continue;
|
|
28
|
-
let node = this.parse_value_node();
|
|
29
|
-
if (node !== null) {
|
|
30
|
-
if (first_node === 0) first_node = node;
|
|
31
|
-
else this.arena.set_next_sibling(last_node, node);
|
|
32
|
-
last_node = node;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
14
|
+
let first_node = this.nodes.parse_chain(start, end, start_line, start_column);
|
|
35
15
|
if (first_node === 0) return this.arena.create_node(50, start, 0, start_line, start_column);
|
|
16
|
+
let last_node = this.nodes.last_chain_node;
|
|
36
17
|
let first_node_start = this.arena.get_start_offset(first_node);
|
|
37
18
|
let last_node_end = this.arena.get_start_offset(last_node) + this.arena.get_length(last_node);
|
|
38
19
|
let value_node = this.arena.create_node(50, first_node_start, last_node_end - first_node_start, start_line, start_column);
|
|
39
20
|
this.arena.set_first_child(value_node, first_node);
|
|
40
21
|
return value_node;
|
|
41
22
|
}
|
|
42
|
-
is_whitespace_inline() {
|
|
43
|
-
if (this.lexer.token_start >= this.lexer.token_end) return false;
|
|
44
|
-
for (let i = this.lexer.token_start; i < this.lexer.token_end; i++) if (!is_whitespace(this.source.charCodeAt(i))) return false;
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
parse_value_node() {
|
|
48
|
-
let token_type = this.lexer.token_type;
|
|
49
|
-
let start = this.lexer.token_start;
|
|
50
|
-
let end = this.lexer.token_end;
|
|
51
|
-
switch (token_type) {
|
|
52
|
-
case 1: return this.create_node(10, start, end);
|
|
53
|
-
case 10: return this.create_node(11, start, end);
|
|
54
|
-
case 11:
|
|
55
|
-
case 12: return this.create_node(12, start, end);
|
|
56
|
-
case 5: return this.create_node(13, start, end);
|
|
57
|
-
case 4: return this.create_node(14, start, end);
|
|
58
|
-
case 27: return this.create_node(19, start, end);
|
|
59
|
-
case 2: return this.parse_function_node(start, end);
|
|
60
|
-
case 9: return this.parse_operator_node(start, end);
|
|
61
|
-
case 18: return this.create_node(16, start, end);
|
|
62
|
-
case 21: return this.parse_parenthesis_node(start, end);
|
|
63
|
-
default: return null;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
create_node(node_type, start, end) {
|
|
67
|
-
let node = this.arena.create_node(node_type, start, end - start, this.lexer.token_line, this.lexer.token_column);
|
|
68
|
-
this.arena.set_content_length(node, end - start);
|
|
69
|
-
return node;
|
|
70
|
-
}
|
|
71
|
-
create_operator_node(start, end) {
|
|
72
|
-
return this.create_node(16, start, end);
|
|
73
|
-
}
|
|
74
|
-
parse_operator_node(start, end) {
|
|
75
|
-
let ch = this.source.charCodeAt(start);
|
|
76
|
-
if (ch === 43 || ch === 45 || ch === 42 || ch === 47) return this.create_operator_node(start, end);
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
parse_function_node(start, end) {
|
|
80
|
-
let name_end = end - 1;
|
|
81
|
-
let func_name_substr = this.source.substring(start, name_end);
|
|
82
|
-
let node = this.arena.create_node(str_equals("url", func_name_substr) ? 18 : 15, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
83
|
-
this.arena.set_content_start_delta(node, 0);
|
|
84
|
-
this.arena.set_content_length(node, name_end - start);
|
|
85
|
-
if (str_equals("url", func_name_substr) || str_equals("src", func_name_substr)) {
|
|
86
|
-
let save_pos = this.lexer.save_position();
|
|
87
|
-
this.lexer.next_token_fast(false);
|
|
88
|
-
while (this.is_whitespace_inline() && this.lexer.pos < this.value_end) this.lexer.next_token_fast(false);
|
|
89
|
-
let first_token_type = this.lexer.token_type;
|
|
90
|
-
this.lexer.restore_position(save_pos);
|
|
91
|
-
if (first_token_type === 5) {} else {
|
|
92
|
-
let paren_depth = 1;
|
|
93
|
-
let func_end = end;
|
|
94
|
-
let content_start = end;
|
|
95
|
-
let content_end = end;
|
|
96
|
-
while (paren_depth > 0) {
|
|
97
|
-
this.lexer.next_token_fast(false);
|
|
98
|
-
let token_type = this.lexer.token_type;
|
|
99
|
-
if (token_type === 26) break;
|
|
100
|
-
if (token_type === 21 || token_type === 2) paren_depth++;
|
|
101
|
-
else if (token_type === 22) {
|
|
102
|
-
paren_depth--;
|
|
103
|
-
if (paren_depth === 0) {
|
|
104
|
-
content_end = this.lexer.token_start;
|
|
105
|
-
func_end = this.lexer.token_end;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
this.arena.set_length(node, func_end - start);
|
|
111
|
-
this.arena.set_value_start_delta(node, content_start - start);
|
|
112
|
-
this.arena.set_value_length(node, content_end - content_start);
|
|
113
|
-
return node;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
let first_arg = 0;
|
|
117
|
-
let last_arg = 0;
|
|
118
|
-
let paren_depth = 1;
|
|
119
|
-
let func_end = end;
|
|
120
|
-
let content_start = end;
|
|
121
|
-
let content_end = end;
|
|
122
|
-
while (this.lexer.pos < this.value_end && paren_depth > 0) {
|
|
123
|
-
this.lexer.next_token_fast(false);
|
|
124
|
-
let token_type = this.lexer.token_type;
|
|
125
|
-
if (token_type === 26) break;
|
|
126
|
-
if (this.lexer.token_start >= this.value_end) break;
|
|
127
|
-
if (token_type === 22) {
|
|
128
|
-
paren_depth--;
|
|
129
|
-
if (paren_depth === 0) {
|
|
130
|
-
content_end = this.lexer.token_start;
|
|
131
|
-
func_end = this.lexer.token_end;
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (this.is_whitespace_inline()) continue;
|
|
136
|
-
let arg_node = this.parse_value_node();
|
|
137
|
-
if (arg_node !== null) {
|
|
138
|
-
if (first_arg === 0) first_arg = arg_node;
|
|
139
|
-
else this.arena.set_next_sibling(last_arg, arg_node);
|
|
140
|
-
last_arg = arg_node;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
this.arena.set_length(node, func_end - start);
|
|
144
|
-
this.arena.set_value_start_delta(node, content_start - start);
|
|
145
|
-
this.arena.set_value_length(node, content_end - content_start);
|
|
146
|
-
if (first_arg !== 0) this.arena.set_first_child(node, first_arg);
|
|
147
|
-
return node;
|
|
148
|
-
}
|
|
149
|
-
parse_parenthesis_node(start, end) {
|
|
150
|
-
let node = this.arena.create_node(17, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
151
|
-
let first_child = 0;
|
|
152
|
-
let last_child = 0;
|
|
153
|
-
let paren_depth = 1;
|
|
154
|
-
let paren_end = end;
|
|
155
|
-
while (this.lexer.pos < this.value_end && paren_depth > 0) {
|
|
156
|
-
this.lexer.next_token_fast(false);
|
|
157
|
-
let token_type = this.lexer.token_type;
|
|
158
|
-
if (token_type === 26) break;
|
|
159
|
-
if (this.lexer.token_start >= this.value_end) break;
|
|
160
|
-
if (token_type === 22) {
|
|
161
|
-
paren_depth--;
|
|
162
|
-
if (paren_depth === 0) {
|
|
163
|
-
paren_end = this.lexer.token_end;
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (this.is_whitespace_inline()) continue;
|
|
168
|
-
let child_node = this.parse_value_node();
|
|
169
|
-
if (child_node !== null) {
|
|
170
|
-
if (first_child === 0) first_child = child_node;
|
|
171
|
-
else this.arena.set_next_sibling(last_child, child_node);
|
|
172
|
-
last_child = child_node;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
this.arena.set_length(node, paren_end - start);
|
|
176
|
-
if (first_child !== 0) this.arena.set_first_child(node, first_child);
|
|
177
|
-
return node;
|
|
178
|
-
}
|
|
179
23
|
};
|
|
180
24
|
/**
|
|
181
25
|
* Parse a CSS declaration value string and return a VALUE node
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { l as CSSDataArena } from "./arena-Bx5vp6Sl.js";
|
|
2
2
|
import { t as CommentInfo } from "./tokenize-DeZYFa9R.js";
|
|
3
|
-
import { z as StyleSheet } from "./node-types-
|
|
3
|
+
import { z as StyleSheet } from "./node-types-D41wr72y.js";
|
|
4
4
|
//#region src/parse.d.ts
|
|
5
5
|
interface ParserOptions {
|
|
6
6
|
parse_values?: boolean;
|
package/dist/parse.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as Lexer } from "./tokenize-BiRLfVbm.js";
|
|
2
2
|
import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
|
|
3
|
-
import { t as CSSNode } from "./css-node-
|
|
3
|
+
import { t as CSSNode } from "./css-node-Cf8K9nWd.js";
|
|
4
4
|
import { i as trim_boundaries } from "./parse-utils-D7srNG13.js";
|
|
5
5
|
import { SelectorParser } from "./parse-selector.js";
|
|
6
6
|
import { AtRulePreludeParser } from "./parse-atrule-prelude.js";
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { t as Lexer } from "./tokenize-BiRLfVbm.js";
|
|
2
|
+
import "./arena-CFwM4uQs.js";
|
|
3
|
+
import { a as is_whitespace, o as str_equals } from "./parse-dimension-ouWXNHdx.js";
|
|
4
|
+
//#region src/value-node-parser.ts
|
|
5
|
+
/** @internal */
|
|
6
|
+
var ValueNodeParser = class {
|
|
7
|
+
lexer;
|
|
8
|
+
arena;
|
|
9
|
+
source;
|
|
10
|
+
end = 0;
|
|
11
|
+
last_chain_node = 0;
|
|
12
|
+
constructor(arena, source) {
|
|
13
|
+
this.arena = arena;
|
|
14
|
+
this.source = source;
|
|
15
|
+
this.lexer = new Lexer(source);
|
|
16
|
+
}
|
|
17
|
+
parse_chain(start, end, start_line, start_column) {
|
|
18
|
+
this.end = end;
|
|
19
|
+
this.lexer.seek(start, start_line, start_column);
|
|
20
|
+
let first_node = 0;
|
|
21
|
+
let last_node = 0;
|
|
22
|
+
while (this.lexer.pos < this.end) {
|
|
23
|
+
this.lexer.next_token_fast(false);
|
|
24
|
+
if (this.lexer.token_start >= this.end) break;
|
|
25
|
+
if (this.lexer.token_type === 26) break;
|
|
26
|
+
if (this.is_whitespace_inline()) continue;
|
|
27
|
+
let node = this.parse_value_node();
|
|
28
|
+
if (node !== null) {
|
|
29
|
+
if (first_node === 0) first_node = node;
|
|
30
|
+
else this.arena.set_next_sibling(last_node, node);
|
|
31
|
+
last_node = node;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
this.last_chain_node = last_node;
|
|
35
|
+
return first_node;
|
|
36
|
+
}
|
|
37
|
+
is_whitespace_inline() {
|
|
38
|
+
if (this.lexer.token_start >= this.lexer.token_end) return false;
|
|
39
|
+
for (let i = this.lexer.token_start; i < this.lexer.token_end; i++) if (!is_whitespace(this.source.charCodeAt(i))) return false;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
parse_value_node() {
|
|
43
|
+
let token_type = this.lexer.token_type;
|
|
44
|
+
let start = this.lexer.token_start;
|
|
45
|
+
let end = this.lexer.token_end;
|
|
46
|
+
switch (token_type) {
|
|
47
|
+
case 1: return this.create_node(10, start, end);
|
|
48
|
+
case 10: return this.create_node(11, start, end);
|
|
49
|
+
case 11:
|
|
50
|
+
case 12: return this.create_node(12, start, end);
|
|
51
|
+
case 5: return this.create_node(13, start, end);
|
|
52
|
+
case 4: return this.create_node(14, start, end);
|
|
53
|
+
case 27: return this.create_node(19, start, end);
|
|
54
|
+
case 2: return this.parse_function_node(start, end);
|
|
55
|
+
case 9: return this.parse_operator_node(start, end);
|
|
56
|
+
case 18: return this.create_node(16, start, end);
|
|
57
|
+
case 21: return this.parse_parenthesis_node(start, end);
|
|
58
|
+
default: return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
create_node(node_type, start, end) {
|
|
62
|
+
let node = this.arena.create_node(node_type, start, end - start, this.lexer.token_line, this.lexer.token_column);
|
|
63
|
+
this.arena.set_content_length(node, end - start);
|
|
64
|
+
return node;
|
|
65
|
+
}
|
|
66
|
+
create_operator_node(start, end) {
|
|
67
|
+
return this.create_node(16, start, end);
|
|
68
|
+
}
|
|
69
|
+
parse_operator_node(start, end) {
|
|
70
|
+
let ch = this.source.charCodeAt(start);
|
|
71
|
+
if (ch === 43 || ch === 45 || ch === 42 || ch === 47) return this.create_operator_node(start, end);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
parse_function_node(start, end) {
|
|
75
|
+
let name_end = end - 1;
|
|
76
|
+
let func_name_substr = this.source.substring(start, name_end);
|
|
77
|
+
let node = this.arena.create_node(str_equals("url", func_name_substr) ? 18 : 15, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
78
|
+
this.arena.set_content_start_delta(node, 0);
|
|
79
|
+
this.arena.set_content_length(node, name_end - start);
|
|
80
|
+
if (str_equals("url", func_name_substr) || str_equals("src", func_name_substr)) {
|
|
81
|
+
let save_pos = this.lexer.save_position();
|
|
82
|
+
this.lexer.next_token_fast(false);
|
|
83
|
+
while (this.is_whitespace_inline() && this.lexer.pos < this.end) this.lexer.next_token_fast(false);
|
|
84
|
+
let first_token_type = this.lexer.token_type;
|
|
85
|
+
this.lexer.restore_position(save_pos);
|
|
86
|
+
if (first_token_type === 5) {} else {
|
|
87
|
+
let paren_depth = 1;
|
|
88
|
+
let func_end = end;
|
|
89
|
+
let content_start = end;
|
|
90
|
+
let content_end = end;
|
|
91
|
+
while (paren_depth > 0) {
|
|
92
|
+
this.lexer.next_token_fast(false);
|
|
93
|
+
let token_type = this.lexer.token_type;
|
|
94
|
+
if (token_type === 26) break;
|
|
95
|
+
if (token_type === 21 || token_type === 2) paren_depth++;
|
|
96
|
+
else if (token_type === 22) {
|
|
97
|
+
paren_depth--;
|
|
98
|
+
if (paren_depth === 0) {
|
|
99
|
+
content_end = this.lexer.token_start;
|
|
100
|
+
func_end = this.lexer.token_end;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
this.arena.set_length(node, func_end - start);
|
|
106
|
+
this.arena.set_value_start_delta(node, content_start - start);
|
|
107
|
+
this.arena.set_value_length(node, content_end - content_start);
|
|
108
|
+
return node;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
let first_arg = 0;
|
|
112
|
+
let last_arg = 0;
|
|
113
|
+
let paren_depth = 1;
|
|
114
|
+
let func_end = end;
|
|
115
|
+
let content_start = end;
|
|
116
|
+
let content_end = end;
|
|
117
|
+
while (this.lexer.pos < this.end && paren_depth > 0) {
|
|
118
|
+
this.lexer.next_token_fast(false);
|
|
119
|
+
let token_type = this.lexer.token_type;
|
|
120
|
+
if (token_type === 26) break;
|
|
121
|
+
if (this.lexer.token_start >= this.end) break;
|
|
122
|
+
if (token_type === 22) {
|
|
123
|
+
paren_depth--;
|
|
124
|
+
if (paren_depth === 0) {
|
|
125
|
+
content_end = this.lexer.token_start;
|
|
126
|
+
func_end = this.lexer.token_end;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (this.is_whitespace_inline()) continue;
|
|
131
|
+
let arg_node = this.parse_value_node();
|
|
132
|
+
if (arg_node !== null) {
|
|
133
|
+
if (first_arg === 0) first_arg = arg_node;
|
|
134
|
+
else this.arena.set_next_sibling(last_arg, arg_node);
|
|
135
|
+
last_arg = arg_node;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
this.arena.set_length(node, func_end - start);
|
|
139
|
+
this.arena.set_value_start_delta(node, content_start - start);
|
|
140
|
+
this.arena.set_value_length(node, content_end - content_start);
|
|
141
|
+
if (first_arg !== 0) this.arena.set_first_child(node, first_arg);
|
|
142
|
+
return node;
|
|
143
|
+
}
|
|
144
|
+
parse_parenthesis_node(start, end) {
|
|
145
|
+
let node = this.arena.create_node(17, start, 0, this.lexer.token_line, this.lexer.token_column);
|
|
146
|
+
let first_child = 0;
|
|
147
|
+
let last_child = 0;
|
|
148
|
+
let paren_depth = 1;
|
|
149
|
+
let paren_end = end;
|
|
150
|
+
while (this.lexer.pos < this.end && paren_depth > 0) {
|
|
151
|
+
this.lexer.next_token_fast(false);
|
|
152
|
+
let token_type = this.lexer.token_type;
|
|
153
|
+
if (token_type === 26) break;
|
|
154
|
+
if (this.lexer.token_start >= this.end) break;
|
|
155
|
+
if (token_type === 22) {
|
|
156
|
+
paren_depth--;
|
|
157
|
+
if (paren_depth === 0) {
|
|
158
|
+
paren_end = this.lexer.token_end;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (this.is_whitespace_inline()) continue;
|
|
163
|
+
let child_node = this.parse_value_node();
|
|
164
|
+
if (child_node !== null) {
|
|
165
|
+
if (first_child === 0) first_child = child_node;
|
|
166
|
+
else this.arena.set_next_sibling(last_child, child_node);
|
|
167
|
+
last_child = child_node;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
this.arena.set_length(node, paren_end - start);
|
|
171
|
+
if (first_child !== 0) this.arena.set_first_child(node, first_child);
|
|
172
|
+
return node;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
//#endregion
|
|
176
|
+
export { ValueNodeParser as t };
|
package/dist/walk.d.ts
CHANGED
package/dist/walk.js
CHANGED