@projectwallace/css-parser 0.18.0 → 0.18.2
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 +2 -2
- package/dist/index.js +2 -2
- 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 +2 -2
- package/dist/parse-atrule-prelude.d.ts +4 -1
- package/dist/parse-atrule-prelude.js +82 -97
- package/dist/parse-declaration.d.ts +2 -2
- package/dist/parse-declaration.js +55 -21
- package/dist/parse-selector.d.ts +1 -2
- package/dist/parse-selector.js +14 -33
- package/dist/parse-value.d.ts +1 -1
- package/dist/parse-value.js +4 -3
- package/dist/parse.d.ts +3 -2
- package/dist/parse.js +33 -59
- package/dist/{tokenize-DeZYFa9R.d.ts → tokenize-CDEnYcVG.d.ts} +22 -0
- package/dist/{tokenize-BiRLfVbm.js → tokenize-DK24ACbY.js} +236 -103
- package/dist/tokenize.d.ts +1 -1
- package/dist/tokenize.js +1 -1
- package/dist/{value-node-parser-CZ47v3hp.js → value-node-parser-jRoWXgOr.js} +2 -5
- package/dist/walk.d.ts +1 -1
- package/dist/walk.js +4 -30
- package/package.json +3 -3
|
@@ -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
|
-
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-
|
|
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-
|
|
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-CDEnYcVG.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-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
|
-
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-
|
|
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-DK24ACbY.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
|
-
import { t as Lexer } from "./tokenize-
|
|
1
|
+
import { t as Lexer } from "./tokenize-DK24ACbY.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 {
|
|
@@ -8,12 +8,15 @@ declare class AtRulePreludeParser {
|
|
|
8
8
|
private source;
|
|
9
9
|
private prelude_end;
|
|
10
10
|
private value_node_parser;
|
|
11
|
+
private selector_parser;
|
|
11
12
|
constructor(arena: CSSDataArena, source: string);
|
|
12
13
|
parse_prelude(at_rule_name: string, start: number, end: number, line?: number, column?: number): number[];
|
|
13
14
|
private parse_prelude_dispatch;
|
|
14
15
|
private parse_media_query_list;
|
|
15
16
|
private create_node;
|
|
16
17
|
private is_and_or_not;
|
|
18
|
+
private scan_matching_paren;
|
|
19
|
+
private parse_function_condition;
|
|
17
20
|
private parse_single_media_query;
|
|
18
21
|
private parse_media_feature;
|
|
19
22
|
private parse_container_query;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-
|
|
1
|
+
import { t as Lexer } from "./tokenize-DK24ACbY.js";
|
|
2
2
|
import { l as CSSDataArena } from "./arena-CFwM4uQs.js";
|
|
3
3
|
import { l as strip_vendor_prefix, 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 { i as trim_boundaries, n as skip_whitespace_and_comments_forward } from "./parse-utils-D7srNG13.js";
|
|
6
|
-
import {
|
|
6
|
+
import { SelectorParser } from "./parse-selector.js";
|
|
7
|
+
import { t as ValueNodeParser } from "./value-node-parser-jRoWXgOr.js";
|
|
7
8
|
//#region src/parse-atrule-prelude.ts
|
|
8
9
|
/** @internal */
|
|
9
10
|
var AtRulePreludeParser = class {
|
|
@@ -12,12 +13,14 @@ var AtRulePreludeParser = class {
|
|
|
12
13
|
source;
|
|
13
14
|
prelude_end;
|
|
14
15
|
value_node_parser;
|
|
16
|
+
selector_parser;
|
|
15
17
|
constructor(arena, source) {
|
|
16
18
|
this.arena = arena;
|
|
17
19
|
this.source = source;
|
|
18
20
|
this.lexer = new Lexer(source);
|
|
19
21
|
this.prelude_end = 0;
|
|
20
22
|
this.value_node_parser = new ValueNodeParser(arena, source);
|
|
23
|
+
this.selector_parser = new SelectorParser(arena, source);
|
|
21
24
|
}
|
|
22
25
|
parse_prelude(at_rule_name, start, end, line = 1, column = 1) {
|
|
23
26
|
this.prelude_end = end;
|
|
@@ -67,18 +70,65 @@ var AtRulePreludeParser = class {
|
|
|
67
70
|
is_and_or_not(str) {
|
|
68
71
|
return str_equals("and", str) || str_equals("or", str) || str_equals("not", str);
|
|
69
72
|
}
|
|
73
|
+
scan_matching_paren() {
|
|
74
|
+
let depth = 1;
|
|
75
|
+
let content_end = this.lexer.pos;
|
|
76
|
+
let close_end = this.lexer.token_end;
|
|
77
|
+
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
78
|
+
let token_type = this.next_token();
|
|
79
|
+
if (token_type === 21 || token_type === 2) depth++;
|
|
80
|
+
else if (token_type === 22) {
|
|
81
|
+
depth--;
|
|
82
|
+
if (depth === 0) {
|
|
83
|
+
content_end = this.lexer.token_start;
|
|
84
|
+
close_end = this.lexer.token_end;
|
|
85
|
+
}
|
|
86
|
+
} else if (token_type === 26) break;
|
|
87
|
+
}
|
|
88
|
+
return [
|
|
89
|
+
content_end,
|
|
90
|
+
close_end,
|
|
91
|
+
depth === 0
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
parse_function_condition() {
|
|
95
|
+
let func_name = this.source.substring(this.lexer.token_start, this.lexer.token_end - 1);
|
|
96
|
+
let func_start = this.lexer.token_start;
|
|
97
|
+
let content_start = this.lexer.token_end;
|
|
98
|
+
let [content_end, func_end] = this.scan_matching_paren();
|
|
99
|
+
let func_node = this.create_node(15, func_start, func_end);
|
|
100
|
+
this.arena.set_content_start_delta(func_node, 0);
|
|
101
|
+
this.arena.set_content_length(func_node, func_name.length);
|
|
102
|
+
this.arena.set_value_start_delta(func_node, content_start - func_start);
|
|
103
|
+
this.arena.set_value_length(func_node, content_end - content_start);
|
|
104
|
+
if (str_equals("selector", func_name)) {
|
|
105
|
+
let selector_list = this.selector_parser.parse_selector(content_start, content_end, this.lexer.line, this.lexer.column);
|
|
106
|
+
if (selector_list !== null) this.arena.set_first_child(func_node, selector_list);
|
|
107
|
+
} else if (str_equals("style", func_name)) {
|
|
108
|
+
let colon_pos = this.find_colon_at_depth_zero(content_start, content_end);
|
|
109
|
+
if (colon_pos !== -1) {
|
|
110
|
+
let decl_child = this.create_supports_declaration(content_start, content_end, colon_pos);
|
|
111
|
+
this.arena.set_first_child(func_node, decl_child);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return func_node;
|
|
115
|
+
}
|
|
70
116
|
parse_single_media_query() {
|
|
71
117
|
let query_start = this.lexer.pos;
|
|
72
118
|
this.skip_whitespace();
|
|
73
119
|
if (this.lexer.pos >= this.prelude_end) return null;
|
|
120
|
+
let first_component = 0;
|
|
121
|
+
let last_component = 0;
|
|
74
122
|
const saved_token_start = this.lexer.save_position();
|
|
75
123
|
this.next_token();
|
|
76
124
|
if (this.lexer.token_type === 1) {
|
|
77
125
|
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
78
|
-
if (
|
|
126
|
+
if (str_equals("only", text) || str_equals("not", text)) {
|
|
127
|
+
let modifier = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
128
|
+
first_component = modifier;
|
|
129
|
+
last_component = modifier;
|
|
130
|
+
} else this.lexer.restore_position(saved_token_start);
|
|
79
131
|
} else this.lexer.restore_position(saved_token_start);
|
|
80
|
-
let first_component = 0;
|
|
81
|
-
let last_component = 0;
|
|
82
132
|
while (this.lexer.pos < this.prelude_end) {
|
|
83
133
|
this.skip_whitespace();
|
|
84
134
|
if (this.lexer.pos >= this.prelude_end) break;
|
|
@@ -105,17 +155,9 @@ var AtRulePreludeParser = class {
|
|
|
105
155
|
}
|
|
106
156
|
parse_media_feature() {
|
|
107
157
|
let feature_start = this.lexer.token_start;
|
|
108
|
-
let depth = 1;
|
|
109
158
|
let content_start = this.lexer.pos;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
let token_type = this.lexer.token_type;
|
|
113
|
-
if (token_type === 21 || token_type === 2) depth++;
|
|
114
|
-
else if (token_type === 22) depth--;
|
|
115
|
-
}
|
|
116
|
-
if (depth !== 0) return null;
|
|
117
|
-
let content_end = this.lexer.token_start;
|
|
118
|
-
let feature_end = this.lexer.token_end;
|
|
159
|
+
let [content_end, feature_end, matched] = this.scan_matching_paren();
|
|
160
|
+
if (!matched) return null;
|
|
119
161
|
let has_comparison = false;
|
|
120
162
|
let i = content_start;
|
|
121
163
|
while (i < content_end) {
|
|
@@ -172,32 +214,8 @@ var AtRulePreludeParser = class {
|
|
|
172
214
|
let token_type = this.lexer.token_type;
|
|
173
215
|
let component = null;
|
|
174
216
|
if (token_type === 21) component = this.parse_media_feature();
|
|
175
|
-
else if (token_type === 2)
|
|
176
|
-
|
|
177
|
-
let func_start = this.lexer.token_start;
|
|
178
|
-
let content_start = this.lexer.token_end;
|
|
179
|
-
let paren_depth = 1;
|
|
180
|
-
let func_end = this.lexer.token_end;
|
|
181
|
-
let content_end = content_start;
|
|
182
|
-
while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
|
|
183
|
-
this.next_token();
|
|
184
|
-
let inner_token = this.lexer.token_type;
|
|
185
|
-
if (inner_token === 21 || inner_token === 2) paren_depth++;
|
|
186
|
-
else if (inner_token === 22) {
|
|
187
|
-
paren_depth--;
|
|
188
|
-
if (paren_depth === 0) {
|
|
189
|
-
content_end = this.lexer.token_start;
|
|
190
|
-
func_end = this.lexer.token_end;
|
|
191
|
-
}
|
|
192
|
-
} else if (inner_token === 26) break;
|
|
193
|
-
}
|
|
194
|
-
let func_node = this.create_node(15, func_start, func_end);
|
|
195
|
-
this.arena.set_content_start_delta(func_node, 0);
|
|
196
|
-
this.arena.set_content_length(func_node, func_name.length);
|
|
197
|
-
this.arena.set_value_start_delta(func_node, content_start - func_start);
|
|
198
|
-
this.arena.set_value_length(func_node, content_end - content_start);
|
|
199
|
-
component = func_node;
|
|
200
|
-
} else if (token_type === 1) {
|
|
217
|
+
else if (token_type === 2) component = this.parse_function_condition();
|
|
218
|
+
else if (token_type === 1) {
|
|
201
219
|
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
202
220
|
if (this.is_and_or_not(text)) component = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
203
221
|
else component = this.create_node(10, this.lexer.token_start, this.lexer.token_end);
|
|
@@ -222,17 +240,9 @@ var AtRulePreludeParser = class {
|
|
|
222
240
|
let token_type = this.lexer.token_type;
|
|
223
241
|
if (token_type === 21) {
|
|
224
242
|
let feature_start = this.lexer.token_start;
|
|
225
|
-
let depth = 1;
|
|
226
243
|
let content_start = this.lexer.pos;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
let inner_token_type = this.lexer.token_type;
|
|
230
|
-
if (inner_token_type === 21 || inner_token_type === 2) depth++;
|
|
231
|
-
else if (inner_token_type === 22) depth--;
|
|
232
|
-
}
|
|
233
|
-
if (depth === 0) {
|
|
234
|
-
let content_end = this.lexer.token_start;
|
|
235
|
-
let feature_end = this.lexer.token_end;
|
|
244
|
+
let [content_end, feature_end, matched] = this.scan_matching_paren();
|
|
245
|
+
if (matched) {
|
|
236
246
|
let query = this.create_node(36, feature_start, feature_end);
|
|
237
247
|
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
238
248
|
if (trimmed) {
|
|
@@ -252,7 +262,7 @@ var AtRulePreludeParser = class {
|
|
|
252
262
|
let op = this.create_node(38, this.lexer.token_start, this.lexer.token_end);
|
|
253
263
|
nodes.push(op);
|
|
254
264
|
}
|
|
255
|
-
}
|
|
265
|
+
} else if (token_type === 2) nodes.push(this.parse_function_condition());
|
|
256
266
|
}
|
|
257
267
|
return nodes;
|
|
258
268
|
}
|
|
@@ -286,6 +296,8 @@ var AtRulePreludeParser = class {
|
|
|
286
296
|
this.arena.set_first_child(decl, value_node);
|
|
287
297
|
}
|
|
288
298
|
let supports_decl = this.create_node(57, content_start, content_end);
|
|
299
|
+
this.arena.set_content_start_delta(supports_decl, prop_trimmed[0] - content_start);
|
|
300
|
+
this.arena.set_content_length(supports_decl, prop_trimmed[1] - prop_trimmed[0]);
|
|
289
301
|
this.arena.set_first_child(supports_decl, decl);
|
|
290
302
|
return supports_decl;
|
|
291
303
|
}
|
|
@@ -371,15 +383,8 @@ var AtRulePreludeParser = class {
|
|
|
371
383
|
let url_start = this.lexer.token_start;
|
|
372
384
|
let url_end = this.lexer.token_end;
|
|
373
385
|
if (this.lexer.token_type === 2) {
|
|
374
|
-
let
|
|
375
|
-
|
|
376
|
-
let tokenType = this.next_token();
|
|
377
|
-
if (tokenType === 21 || tokenType === 2) paren_depth++;
|
|
378
|
-
else if (tokenType === 22) {
|
|
379
|
-
paren_depth--;
|
|
380
|
-
if (paren_depth === 0) url_end = this.lexer.token_end;
|
|
381
|
-
} else if (tokenType === 26) break;
|
|
382
|
-
}
|
|
386
|
+
let [, close_end] = this.scan_matching_paren();
|
|
387
|
+
url_end = close_end;
|
|
383
388
|
}
|
|
384
389
|
return this.create_node(18, url_start, url_end);
|
|
385
390
|
}
|
|
@@ -396,17 +401,10 @@ var AtRulePreludeParser = class {
|
|
|
396
401
|
let content_length = 0;
|
|
397
402
|
if (this.lexer.token_type === 2) {
|
|
398
403
|
content_start = this.lexer.pos;
|
|
399
|
-
let
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
else if (tokenType === 22) {
|
|
404
|
-
paren_depth--;
|
|
405
|
-
if (paren_depth === 0) {
|
|
406
|
-
content_length = this.lexer.token_start - content_start;
|
|
407
|
-
layer_end = this.lexer.token_end;
|
|
408
|
-
}
|
|
409
|
-
} else if (tokenType === 26) break;
|
|
404
|
+
let [content_end, close_end, matched] = this.scan_matching_paren();
|
|
405
|
+
if (matched) {
|
|
406
|
+
content_length = content_end - content_start;
|
|
407
|
+
layer_end = close_end;
|
|
410
408
|
}
|
|
411
409
|
}
|
|
412
410
|
let layer_node = this.create_node(37, layer_start, layer_end);
|
|
@@ -427,28 +425,21 @@ var AtRulePreludeParser = class {
|
|
|
427
425
|
const saved = this.lexer.save_position();
|
|
428
426
|
this.next_token();
|
|
429
427
|
if (this.lexer.token_type === 2) {
|
|
430
|
-
|
|
428
|
+
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end - 1);
|
|
429
|
+
if (str_equals("supports", text)) {
|
|
431
430
|
let supports_start = this.lexer.token_start;
|
|
432
431
|
let content_start = this.lexer.token_end;
|
|
433
|
-
let
|
|
434
|
-
let supports_end = this.lexer.token_end;
|
|
435
|
-
let content_end = content_start;
|
|
436
|
-
while (this.lexer.pos < this.prelude_end && paren_depth > 0) {
|
|
437
|
-
let tokenType = this.next_token();
|
|
438
|
-
if (tokenType === 21 || tokenType === 2) paren_depth++;
|
|
439
|
-
else if (tokenType === 22) {
|
|
440
|
-
paren_depth--;
|
|
441
|
-
if (paren_depth === 0) {
|
|
442
|
-
content_end = this.lexer.token_start;
|
|
443
|
-
supports_end = this.lexer.token_end;
|
|
444
|
-
}
|
|
445
|
-
} else if (tokenType === 26) break;
|
|
446
|
-
}
|
|
432
|
+
let [content_end, supports_end] = this.scan_matching_paren();
|
|
447
433
|
let supports_node = this.create_node(36, supports_start, supports_end);
|
|
448
434
|
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
449
435
|
if (trimmed) {
|
|
450
436
|
this.arena.set_value_start_delta(supports_node, trimmed[0] - supports_start);
|
|
451
437
|
this.arena.set_value_length(supports_node, trimmed[1] - trimmed[0]);
|
|
438
|
+
let colon_pos = this.find_colon_at_depth_zero(trimmed[0], trimmed[1]);
|
|
439
|
+
if (colon_pos !== -1) {
|
|
440
|
+
let decl_child = this.create_supports_declaration(trimmed[0], trimmed[1], colon_pos);
|
|
441
|
+
this.arena.set_first_child(supports_node, decl_child);
|
|
442
|
+
}
|
|
452
443
|
}
|
|
453
444
|
return supports_node;
|
|
454
445
|
}
|
|
@@ -500,14 +491,7 @@ var AtRulePreludeParser = class {
|
|
|
500
491
|
this.next_token();
|
|
501
492
|
let paren_start = this.lexer.token_start;
|
|
502
493
|
let content_start = this.lexer.pos;
|
|
503
|
-
let
|
|
504
|
-
while (this.lexer.pos < this.prelude_end && depth > 0) {
|
|
505
|
-
this.next_token();
|
|
506
|
-
if (this.lexer.token_type === 21 || this.lexer.token_type === 2) depth++;
|
|
507
|
-
else if (this.lexer.token_type === 22) depth--;
|
|
508
|
-
}
|
|
509
|
-
let content_end = this.lexer.token_start;
|
|
510
|
-
let paren_end = this.lexer.token_end;
|
|
494
|
+
let [content_end, paren_end] = this.scan_matching_paren();
|
|
511
495
|
let scope_node = this.create_node(41, paren_start, paren_end);
|
|
512
496
|
let trimmed = trim_boundaries(this.source, content_start, content_end);
|
|
513
497
|
if (trimmed) {
|
|
@@ -517,7 +501,8 @@ var AtRulePreludeParser = class {
|
|
|
517
501
|
nodes.push(scope_node);
|
|
518
502
|
} else if (token_type === 1) {
|
|
519
503
|
this.next_token();
|
|
520
|
-
|
|
504
|
+
let text = this.source.substring(this.lexer.token_start, this.lexer.token_end);
|
|
505
|
+
if (str_equals("to", text)) nodes.push(this.create_node(38, this.lexer.token_start, this.lexer.token_end));
|
|
521
506
|
} else this.next_token();
|
|
522
507
|
}
|
|
523
508
|
return nodes;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { l as CSSDataArena } from "./arena-Bx5vp6Sl.js";
|
|
2
|
-
import { n as Lexer } from "./tokenize-
|
|
3
|
-
import { d as Declaration } from "./node-types-
|
|
2
|
+
import { n as Lexer } from "./tokenize-CDEnYcVG.js";
|
|
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,8 +1,8 @@
|
|
|
1
|
-
import { t as Lexer } from "./tokenize-
|
|
1
|
+
import { t as Lexer } from "./tokenize-DK24ACbY.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-
|
|
5
|
-
import { i as trim_boundaries } from "./parse-utils-D7srNG13.js";
|
|
4
|
+
import { t as CSSNode } from "./css-node-Cf8K9nWd.js";
|
|
5
|
+
import { i as trim_boundaries, t as skip_whitespace_and_comments_backward } from "./parse-utils-D7srNG13.js";
|
|
6
6
|
import { ValueParser } from "./parse-value.js";
|
|
7
7
|
//#region src/parse-declaration.ts
|
|
8
8
|
/** @internal */
|
|
@@ -70,39 +70,70 @@ var DeclarationParser = class {
|
|
|
70
70
|
lexer.restore_position(has_delimiter_prefix ? initial_saved : saved);
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
|
-
lexer.
|
|
73
|
+
lexer.pos = lexer.token_end;
|
|
74
|
+
lexer.skip_whitespace_in_range(this.source.length);
|
|
74
75
|
let declaration = this.arena.create_node(4, prop_start, 0, decl_line, decl_column);
|
|
75
76
|
this.arena.set_content_start_delta(declaration, 0);
|
|
76
77
|
this.arena.set_content_length(declaration, prop_end - prop_start);
|
|
77
|
-
let value_start = lexer.
|
|
78
|
-
let value_start_line = lexer.
|
|
79
|
-
let value_start_column = lexer.
|
|
78
|
+
let value_start = lexer.pos;
|
|
79
|
+
let value_start_line = lexer.line;
|
|
80
|
+
let value_start_column = lexer.column;
|
|
80
81
|
let value_end = value_start;
|
|
81
82
|
let has_important = false;
|
|
82
|
-
let last_end =
|
|
83
|
+
let last_end = value_start;
|
|
83
84
|
let paren_depth = 0;
|
|
84
|
-
while (
|
|
85
|
-
let
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
while (true) {
|
|
86
|
+
let stop_ch = lexer.skip_to_declaration_stop(end);
|
|
87
|
+
if (stop_ch === 40) {
|
|
88
|
+
paren_depth++;
|
|
89
|
+
lexer.pos++;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (stop_ch === 41) {
|
|
93
|
+
paren_depth--;
|
|
94
|
+
lexer.pos++;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (stop_ch === 59 && paren_depth === 0) {
|
|
98
|
+
value_end = skip_whitespace_and_comments_backward(this.source, lexer.pos, value_start);
|
|
99
|
+
lexer.next_token_fast(false);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
if (stop_ch === 125 && paren_depth === 0) {
|
|
103
|
+
if (lexer.pos === value_start) {
|
|
104
|
+
last_end = lexer.pos + 1;
|
|
105
|
+
value_end = value_start;
|
|
106
|
+
} else {
|
|
107
|
+
last_end = skip_whitespace_and_comments_backward(this.source, lexer.pos, value_start);
|
|
108
|
+
value_end = last_end;
|
|
109
|
+
}
|
|
110
|
+
lexer.next_token_fast(false);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
if (stop_ch === 123) {
|
|
91
114
|
lexer.restore_position(saved);
|
|
92
115
|
return null;
|
|
93
116
|
}
|
|
94
|
-
if (
|
|
95
|
-
value_end = lexer.
|
|
117
|
+
if (stop_ch === 33) {
|
|
118
|
+
value_end = lexer.pos;
|
|
119
|
+
lexer.pos++;
|
|
96
120
|
if (lexer.next_token_fast(true) === 1) {
|
|
97
121
|
has_important = true;
|
|
98
122
|
last_end = lexer.token_end;
|
|
99
123
|
lexer.next_token_fast(true);
|
|
100
124
|
break;
|
|
101
125
|
}
|
|
126
|
+
last_end = lexer.token_end;
|
|
127
|
+
value_end = last_end;
|
|
128
|
+
continue;
|
|
102
129
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
130
|
+
if (stop_ch === 0) {
|
|
131
|
+
last_end = skip_whitespace_and_comments_backward(this.source, lexer.pos, value_start);
|
|
132
|
+
value_end = last_end;
|
|
133
|
+
lexer.next_token_fast(false);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
lexer.pos++;
|
|
106
137
|
}
|
|
107
138
|
let trimmed = trim_boundaries(this.source, value_start, value_end);
|
|
108
139
|
if (trimmed) {
|
|
@@ -141,7 +172,10 @@ var DeclarationParser = class {
|
|
|
141
172
|
function parse_declaration(source) {
|
|
142
173
|
const arena = new CSSDataArena(CSSDataArena.capacity_for_source(source.length));
|
|
143
174
|
const decl_index = new DeclarationParser(arena, source).parse_declaration(0, source.length);
|
|
144
|
-
if (decl_index === null)
|
|
175
|
+
if (decl_index === null) {
|
|
176
|
+
const empty = arena.create_node(4, 0, 0, 1, 1);
|
|
177
|
+
return new CSSNode(arena, source, empty);
|
|
178
|
+
}
|
|
145
179
|
return new CSSNode(arena, source, decl_index);
|
|
146
180
|
}
|
|
147
181
|
//#endregion
|
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 {
|
|
@@ -30,7 +30,6 @@ declare class SelectorParser {
|
|
|
30
30
|
private parse_nth_expression;
|
|
31
31
|
private find_of_keyword;
|
|
32
32
|
private create_node;
|
|
33
|
-
private create_node_at;
|
|
34
33
|
private skip_whitespace;
|
|
35
34
|
}
|
|
36
35
|
declare function parse_selector_list(source: string): SelectorList;
|