@tbela99/css-parser 0.7.1 → 0.9.0
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/.editorconfig +484 -0
- package/README.md +140 -84
- package/dist/index-umd-web.js +8461 -51655
- package/dist/index.cjs +8437 -51636
- package/dist/index.d.ts +220 -68
- package/dist/lib/ast/expand.js +46 -9
- package/dist/lib/ast/features/calc.js +76 -12
- package/dist/lib/ast/features/inlinecssvariables.js +6 -1
- package/dist/lib/ast/features/prefix.js +17 -9
- package/dist/lib/ast/features/shorthand.js +1 -0
- package/dist/lib/ast/math/expression.js +299 -11
- package/dist/lib/ast/math/math.js +7 -1
- package/dist/lib/ast/minify.js +30 -16
- package/dist/lib/ast/types.js +59 -49
- package/dist/lib/ast/walk.js +92 -18
- package/dist/lib/parser/declaration/list.js +1 -0
- package/dist/lib/parser/declaration/map.js +60 -52
- package/dist/lib/parser/declaration/set.js +1 -12
- package/dist/lib/parser/parse.js +371 -119
- package/dist/lib/parser/tokenize.js +31 -6
- package/dist/lib/parser/utils/declaration.js +2 -2
- package/dist/lib/parser/utils/type.js +6 -6
- package/dist/lib/renderer/color/a98rgb.js +1 -0
- package/dist/lib/renderer/color/color.js +1 -0
- package/dist/lib/renderer/color/colormix.js +1 -0
- package/dist/lib/renderer/color/hex.js +2 -1
- package/dist/lib/renderer/color/hsl.js +2 -1
- package/dist/lib/renderer/color/hwb.js +3 -2
- package/dist/lib/renderer/color/lab.js +2 -1
- package/dist/lib/renderer/color/lch.js +2 -1
- package/dist/lib/renderer/color/oklab.js +3 -2
- package/dist/lib/renderer/color/oklch.js +2 -1
- package/dist/lib/renderer/color/p3.js +2 -1
- package/dist/lib/renderer/color/prophotoRgb.js +56 -0
- package/dist/lib/renderer/color/prophotorgb.js +1 -1
- package/dist/lib/renderer/color/rec2020.js +1 -0
- package/dist/lib/renderer/color/relativecolor.js +52 -28
- package/dist/lib/renderer/color/rgb.js +2 -1
- package/dist/lib/renderer/color/srgb.js +3 -2
- package/dist/lib/renderer/color/utils/components.js +1 -0
- package/dist/lib/renderer/color/utils/constants.js +2 -1
- package/dist/lib/renderer/color/xyz.js +2 -1
- package/dist/lib/renderer/color/xyzd50.js +1 -0
- package/dist/lib/renderer/render.js +62 -12
- package/dist/lib/syntax/syntax.js +362 -4
- package/dist/lib/validation/at-rules/container.js +353 -0
- package/dist/lib/validation/at-rules/counter-style.js +78 -0
- package/dist/lib/validation/at-rules/custom-media.js +52 -0
- package/dist/lib/validation/at-rules/document.js +114 -0
- package/dist/lib/validation/at-rules/else.js +5 -0
- package/dist/lib/validation/at-rules/font-feature-values.js +52 -0
- package/dist/lib/validation/at-rules/import.js +199 -0
- package/dist/lib/validation/at-rules/keyframes.js +70 -0
- package/dist/lib/validation/at-rules/layer.js +30 -0
- package/dist/lib/validation/at-rules/media.js +254 -0
- package/dist/lib/validation/at-rules/namespace.js +85 -0
- package/dist/lib/validation/at-rules/page-margin-box.js +56 -0
- package/dist/lib/validation/at-rules/page.js +88 -0
- package/dist/lib/validation/at-rules/supports.js +262 -0
- package/dist/lib/validation/at-rules/when.js +178 -0
- package/dist/lib/validation/atrule.js +187 -0
- package/dist/lib/validation/config.js +35 -2
- package/dist/lib/validation/config.json.js +1683 -50905
- package/dist/lib/validation/declaration.js +102 -0
- package/dist/lib/validation/parser/parse.js +1137 -7
- package/dist/lib/validation/parser/types.js +28 -12
- package/dist/lib/validation/selector.js +26 -444
- package/dist/lib/validation/syntax.js +1475 -0
- package/dist/lib/validation/syntaxes/complex-selector-list.js +45 -0
- package/dist/lib/validation/syntaxes/complex-selector.js +53 -0
- package/dist/lib/validation/syntaxes/compound-selector.js +226 -0
- package/dist/lib/validation/syntaxes/family-name.js +91 -0
- package/dist/lib/validation/syntaxes/image.js +29 -0
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +27 -0
- package/dist/lib/validation/syntaxes/keyframe-selector.js +137 -0
- package/dist/lib/validation/syntaxes/layer-name.js +67 -0
- package/dist/lib/validation/syntaxes/relative-selector-list.js +57 -0
- package/dist/lib/validation/syntaxes/relative-selector.js +36 -0
- package/dist/lib/validation/syntaxes/selector-list.js +5 -0
- package/dist/lib/validation/syntaxes/selector.js +5 -0
- package/dist/lib/validation/syntaxes/url.js +75 -0
- package/dist/lib/validation/utils/list.js +24 -0
- package/dist/lib/validation/utils/whitespace.js +22 -0
- package/dist/node/index.js +5 -5
- package/dist/web/index.js +5 -1
- package/dist/web/load.js +1 -0
- package/package.json +16 -14
- package/dist/lib/ast/utils/minifyfeature.js +0 -9
- package/dist/lib/iterable/weakset.js +0 -58
- package/dist/lib/parser/utils/syntax.js +0 -450
package/dist/index.d.ts
CHANGED
|
@@ -38,57 +38,66 @@ declare enum EnumToken {
|
|
|
38
38
|
WhitespaceTokenType = 36,
|
|
39
39
|
IncludeMatchTokenType = 37,
|
|
40
40
|
DashMatchTokenType = 38,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
41
|
+
EqualMatchTokenType = 39,
|
|
42
|
+
LtTokenType = 40,
|
|
43
|
+
LteTokenType = 41,
|
|
44
|
+
GtTokenType = 42,
|
|
45
|
+
GteTokenType = 43,
|
|
46
|
+
PseudoClassTokenType = 44,
|
|
47
|
+
PseudoClassFuncTokenType = 45,
|
|
48
|
+
DelimTokenType = 46,
|
|
49
|
+
UrlTokenTokenType = 47,
|
|
50
|
+
EOFTokenType = 48,
|
|
51
|
+
ImportantTokenType = 49,
|
|
52
|
+
ColorTokenType = 50,
|
|
53
|
+
AttrTokenType = 51,
|
|
54
|
+
BadCommentTokenType = 52,
|
|
55
|
+
BadCdoTokenType = 53,
|
|
56
|
+
BadUrlTokenType = 54,
|
|
57
|
+
BadStringTokenType = 55,
|
|
58
|
+
BinaryExpressionTokenType = 56,
|
|
59
|
+
UnaryExpressionTokenType = 57,
|
|
60
|
+
FlexTokenType = 58,
|
|
61
|
+
ListToken = 59,
|
|
62
|
+
Add = 60,
|
|
63
|
+
Mul = 61,
|
|
64
|
+
Div = 62,
|
|
65
|
+
Sub = 63,
|
|
66
|
+
ColumnCombinatorTokenType = 64,
|
|
67
|
+
ContainMatchTokenType = 65,
|
|
68
|
+
StartMatchTokenType = 66,
|
|
69
|
+
EndMatchTokenType = 67,
|
|
70
|
+
MatchExpressionTokenType = 68,
|
|
71
|
+
NameSpaceAttributeTokenType = 69,
|
|
72
|
+
FractionTokenType = 70,
|
|
73
|
+
IdenListTokenType = 71,
|
|
74
|
+
GridTemplateFuncTokenType = 72,
|
|
75
|
+
KeyFrameRuleNodeType = 73,
|
|
76
|
+
ClassSelectorTokenType = 74,
|
|
77
|
+
UniversalSelectorTokenType = 75,
|
|
78
|
+
ChildCombinatorTokenType = 76,// >
|
|
79
|
+
DescendantCombinatorTokenType = 77,// whitespace
|
|
80
|
+
NextSiblingCombinatorTokenType = 78,// +
|
|
81
|
+
SubsequentSiblingCombinatorTokenType = 79,// ~
|
|
82
|
+
NestingSelectorTokenType = 80,// &
|
|
83
|
+
InvalidRuleTokenType = 81,
|
|
84
|
+
InvalidClassSelectorTokenType = 82,
|
|
85
|
+
InvalidAttrTokenType = 83,
|
|
86
|
+
InvalidAtRuleTokenType = 84,
|
|
87
|
+
MediaQueryConditionTokenType = 85,
|
|
88
|
+
MediaFeatureTokenType = 86,
|
|
89
|
+
MediaFeatureOnlyTokenType = 87,
|
|
90
|
+
MediaFeatureNotTokenType = 88,
|
|
91
|
+
MediaFeatureAndTokenType = 89,
|
|
92
|
+
MediaFeatureOrTokenType = 90,
|
|
93
|
+
PseudoPageTokenType = 91,
|
|
85
94
|
Time = 25,
|
|
86
95
|
Iden = 7,
|
|
87
|
-
EOF =
|
|
96
|
+
EOF = 48,
|
|
88
97
|
Hash = 28,
|
|
89
|
-
Flex =
|
|
98
|
+
Flex = 58,
|
|
90
99
|
Angle = 24,
|
|
91
|
-
Color =
|
|
100
|
+
Color = 50,
|
|
92
101
|
Comma = 9,
|
|
93
102
|
String = 20,
|
|
94
103
|
Length = 23,
|
|
@@ -101,9 +110,9 @@ declare enum EnumToken {
|
|
|
101
110
|
Frequency = 26,
|
|
102
111
|
Resolution = 27,
|
|
103
112
|
Whitespace = 36,
|
|
104
|
-
IdenList =
|
|
113
|
+
IdenList = 71,
|
|
105
114
|
DashedIden = 8,
|
|
106
|
-
GridTemplateFunc =
|
|
115
|
+
GridTemplateFunc = 72,
|
|
107
116
|
ImageFunc = 19,
|
|
108
117
|
CommentNodeType = 0,
|
|
109
118
|
CDOCOMMNodeType = 1,
|
|
@@ -111,22 +120,73 @@ declare enum EnumToken {
|
|
|
111
120
|
TimelineFunction = 16
|
|
112
121
|
}
|
|
113
122
|
|
|
123
|
+
/**
|
|
124
|
+
* minify ast
|
|
125
|
+
* @param ast
|
|
126
|
+
* @param options
|
|
127
|
+
* @param recursive
|
|
128
|
+
* @param errors
|
|
129
|
+
* @param nestingContent
|
|
130
|
+
* @param context
|
|
131
|
+
*/
|
|
114
132
|
declare function minify(ast: AstNode, options?: ParserOptions | MinifyOptions, recursive?: boolean, errors?: ErrorDescription[], nestingContent?: boolean, context?: {
|
|
115
133
|
[key: string]: any;
|
|
116
134
|
}): AstNode;
|
|
117
135
|
|
|
136
|
+
declare enum WalkerValueEvent {
|
|
137
|
+
Enter = 0,
|
|
138
|
+
Leave = 1
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* walk ast nodes
|
|
142
|
+
* @param node
|
|
143
|
+
* @param filter
|
|
144
|
+
*/
|
|
118
145
|
declare function walk(node: AstNode, filter?: WalkerFilter): Generator<WalkResult>;
|
|
119
|
-
|
|
146
|
+
/**
|
|
147
|
+
* walk ast values
|
|
148
|
+
* @param values
|
|
149
|
+
* @param root
|
|
150
|
+
* @param filter
|
|
151
|
+
* @param reverse
|
|
152
|
+
*/
|
|
153
|
+
declare function walkValues(values: Token[], root?: AstNode | Token | null, filter?: WalkerValueFilter | {
|
|
154
|
+
event: WalkerValueEvent;
|
|
155
|
+
fn?: WalkerValueFilter;
|
|
156
|
+
type?: EnumToken | EnumToken[] | ((token: Token) => boolean);
|
|
157
|
+
}, reverse?: boolean): Generator<WalkAttributesResult>;
|
|
120
158
|
|
|
159
|
+
/**
|
|
160
|
+
* expand nested css ast
|
|
161
|
+
* @param ast
|
|
162
|
+
*/
|
|
121
163
|
declare function expand(ast: AstNode): AstNode;
|
|
122
164
|
|
|
165
|
+
/**
|
|
166
|
+
* render ast token
|
|
167
|
+
* @param token
|
|
168
|
+
* @param options
|
|
169
|
+
* @param cache
|
|
170
|
+
* @param reducer
|
|
171
|
+
* @param errors
|
|
172
|
+
*/
|
|
123
173
|
declare function renderToken(token: Token, options?: RenderOptions, cache?: {
|
|
124
174
|
[key: string]: any;
|
|
125
175
|
}, reducer?: (acc: string, curr: Token) => string, errors?: ErrorDescription[]): string;
|
|
126
176
|
|
|
177
|
+
/**
|
|
178
|
+
* parse string
|
|
179
|
+
* @param src
|
|
180
|
+
* @param options
|
|
181
|
+
*/
|
|
127
182
|
declare function parseString(src: string, options?: {
|
|
128
183
|
location: boolean;
|
|
129
184
|
}): Token[];
|
|
185
|
+
/**
|
|
186
|
+
* parse token list
|
|
187
|
+
* @param tokens
|
|
188
|
+
* @param options
|
|
189
|
+
*/
|
|
130
190
|
declare function parseTokens(tokens: Token[], options?: ParseTokenOptions): Token[];
|
|
131
191
|
|
|
132
192
|
export declare interface LiteralToken extends BaseToken {
|
|
@@ -201,6 +261,7 @@ export declare interface AtRuleToken extends BaseToken {
|
|
|
201
261
|
|
|
202
262
|
typ: EnumToken.AtRuleTokenType,
|
|
203
263
|
val: string;
|
|
264
|
+
pre: string;
|
|
204
265
|
}
|
|
205
266
|
|
|
206
267
|
export declare interface PercentageToken extends BaseToken {
|
|
@@ -401,6 +462,12 @@ export declare interface DashMatchToken extends BaseToken {
|
|
|
401
462
|
// val: '|=';
|
|
402
463
|
}
|
|
403
464
|
|
|
465
|
+
export declare interface EqualMatchToken extends BaseToken {
|
|
466
|
+
|
|
467
|
+
typ: EnumToken.EqualMatchTokenType;
|
|
468
|
+
// val: '|=';
|
|
469
|
+
}
|
|
470
|
+
|
|
404
471
|
export declare interface StartMatchToken extends BaseToken {
|
|
405
472
|
|
|
406
473
|
typ: EnumToken.StartMatchTokenType;
|
|
@@ -450,6 +517,12 @@ export declare interface PseudoClassToken extends BaseToken {
|
|
|
450
517
|
val: string;
|
|
451
518
|
}
|
|
452
519
|
|
|
520
|
+
export declare interface PseudoPageToken extends BaseToken {
|
|
521
|
+
|
|
522
|
+
typ: EnumToken.PseudoPageTokenType;
|
|
523
|
+
val: string;
|
|
524
|
+
}
|
|
525
|
+
|
|
453
526
|
export declare interface PseudoClassFunctionToken extends BaseToken {
|
|
454
527
|
|
|
455
528
|
typ: EnumToken.PseudoClassFuncTokenType;
|
|
@@ -531,6 +604,42 @@ export declare interface ChildCombinatorToken extends BaseToken {
|
|
|
531
604
|
typ: EnumToken.ChildCombinatorTokenType
|
|
532
605
|
}
|
|
533
606
|
|
|
607
|
+
export declare interface MediaFeatureToken extends BaseToken {
|
|
608
|
+
|
|
609
|
+
typ: EnumToken.MediaFeatureTokenType,
|
|
610
|
+
val: string;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
export declare interface MediaFeatureNotToken extends BaseToken {
|
|
614
|
+
|
|
615
|
+
typ: EnumToken.MediaFeatureNotTokenType,
|
|
616
|
+
val: Token;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
export declare interface MediaFeatureOnlyToken extends BaseToken {
|
|
620
|
+
|
|
621
|
+
typ: EnumToken.MediaFeatureOnlyTokenType,
|
|
622
|
+
val: Token;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
export declare interface MediaFeatureAndToken extends BaseToken {
|
|
626
|
+
|
|
627
|
+
typ: EnumToken.MediaFeatureAndTokenType;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export declare interface MediaFeatureOrToken extends BaseToken {
|
|
631
|
+
|
|
632
|
+
typ: EnumToken.MediaFeatureOrTokenType;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
export declare interface MediaQueryConditionToken extends BaseToken {
|
|
636
|
+
|
|
637
|
+
typ: EnumToken.MediaQueryConditionTokenType,
|
|
638
|
+
l: Token,
|
|
639
|
+
op: ColonToken | GreaterThanToken | LessThanToken | GreaterThanOrEqualToken | LessThanOrEqualToken,
|
|
640
|
+
r: Token[]
|
|
641
|
+
}
|
|
642
|
+
|
|
534
643
|
export declare interface DescendantCombinatorToken extends BaseToken {
|
|
535
644
|
|
|
536
645
|
typ: EnumToken.DescendantCombinatorTokenType
|
|
@@ -591,7 +700,7 @@ export declare interface BinaryExpressionToken extends BaseToken {
|
|
|
591
700
|
export declare interface MatchExpressionToken extends BaseToken {
|
|
592
701
|
|
|
593
702
|
typ: EnumToken.MatchExpressionTokenType
|
|
594
|
-
op:
|
|
703
|
+
op: EqualMatchToken | DashMatchToken | StartMatchToken | ContainMatchToken | EndMatchToken | IncludeMatchToken;
|
|
595
704
|
l: Token;
|
|
596
705
|
r: Token;
|
|
597
706
|
attr?: 'i' | 's';
|
|
@@ -642,6 +751,14 @@ export declare type Token =
|
|
|
642
751
|
| ColumnCombinatorToken
|
|
643
752
|
| NestingSelectorToken
|
|
644
753
|
|
|
|
754
|
+
MediaQueryConditionToken
|
|
755
|
+
| MediaFeatureToken
|
|
756
|
+
| MediaFeatureNotToken
|
|
757
|
+
| MediaFeatureOnlyToken
|
|
758
|
+
| MediaFeatureAndToken
|
|
759
|
+
| MediaFeatureOrToken
|
|
760
|
+
| AstDeclaration
|
|
761
|
+
|
|
|
645
762
|
NumberToken
|
|
646
763
|
| AtRuleToken
|
|
647
764
|
| PercentageToken
|
|
@@ -686,6 +803,7 @@ export declare type Token =
|
|
|
686
803
|
| NameSpaceAttributeToken
|
|
687
804
|
|
|
|
688
805
|
DashMatchToken
|
|
806
|
+
| EqualMatchToken
|
|
689
807
|
| LessThanToken
|
|
690
808
|
| LessThanOrEqualToken
|
|
691
809
|
| GreaterThanToken
|
|
@@ -693,6 +811,7 @@ export declare type Token =
|
|
|
693
811
|
|
|
|
694
812
|
ListToken
|
|
695
813
|
| PseudoClassToken
|
|
814
|
+
| PseudoPageToken
|
|
696
815
|
| PseudoClassFunctionToken
|
|
697
816
|
| DelimToken
|
|
698
817
|
| BinaryExpressionToken
|
|
@@ -729,6 +848,8 @@ export declare interface BaseToken {
|
|
|
729
848
|
|
|
730
849
|
typ: EnumToken;
|
|
731
850
|
loc?: Location;
|
|
851
|
+
tokens?: Token[];
|
|
852
|
+
parent?: AstRuleList;
|
|
732
853
|
}
|
|
733
854
|
|
|
734
855
|
export declare interface AstComment extends BaseToken {
|
|
@@ -754,6 +875,32 @@ export declare interface AstRule extends BaseToken {
|
|
|
754
875
|
raw?: RawSelectorTokens;
|
|
755
876
|
}
|
|
756
877
|
|
|
878
|
+
export declare interface AstInvalidRule extends BaseToken {
|
|
879
|
+
|
|
880
|
+
typ: EnumToken.InvalidRuleTokenType;
|
|
881
|
+
sel: string;
|
|
882
|
+
chi: Array<AstDeclaration | AstComment | AstRuleList>;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
export declare interface AstInvalidAtRule extends BaseToken {
|
|
886
|
+
|
|
887
|
+
typ: EnumToken.InvalidAtRuleTokenType;
|
|
888
|
+
val: string;
|
|
889
|
+
chi?: Array<AstNode>;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
export declare interface AstKeyFrameRule extends BaseToken {
|
|
895
|
+
|
|
896
|
+
typ: EnumToken.KeyFrameRuleNodeType;
|
|
897
|
+
sel: string;
|
|
898
|
+
chi: Array<AstDeclaration | AstComment>;
|
|
899
|
+
optimized?: OptimizedSelector;
|
|
900
|
+
raw?: RawSelectorTokens;
|
|
901
|
+
tokens?: Token[]
|
|
902
|
+
}
|
|
903
|
+
|
|
757
904
|
export declare type RawSelectorTokens = string[][];
|
|
758
905
|
|
|
759
906
|
export declare interface OptimizedSelector {
|
|
@@ -765,7 +912,7 @@ export declare interface OptimizedSelector {
|
|
|
765
912
|
|
|
766
913
|
export declare interface AstAtRule extends BaseToken {
|
|
767
914
|
|
|
768
|
-
typ: AtRuleNodeType,
|
|
915
|
+
typ: EnumToken.AtRuleNodeType,
|
|
769
916
|
nam: string;
|
|
770
917
|
val: string;
|
|
771
918
|
chi?: Array<AstDeclaration | AstComment> | Array<AstRule | AstComment>
|
|
@@ -773,12 +920,12 @@ export declare interface AstAtRule extends BaseToken {
|
|
|
773
920
|
|
|
774
921
|
export declare interface AstRuleList extends BaseToken {
|
|
775
922
|
|
|
776
|
-
typ:
|
|
777
|
-
chi: Array<BaseToken | AstComment
|
|
923
|
+
typ: EnumToken.StyleSheetNodeType | EnumToken.RuleNodeType | EnumToken.AtRuleNodeType,
|
|
924
|
+
chi: Array<BaseToken | AstComment>;
|
|
778
925
|
}
|
|
779
926
|
|
|
780
927
|
export declare interface AstRuleStyleSheet extends AstRuleList {
|
|
781
|
-
typ:
|
|
928
|
+
typ: EnumToken.StyleSheetNodeType,
|
|
782
929
|
chi: Array<AstRuleList | AstComment>
|
|
783
930
|
}
|
|
784
931
|
|
|
@@ -788,7 +935,10 @@ export declare type AstNode =
|
|
|
788
935
|
| AstComment
|
|
789
936
|
| AstAtRule
|
|
790
937
|
| AstRule
|
|
791
|
-
| AstDeclaration
|
|
938
|
+
| AstDeclaration
|
|
939
|
+
| AstKeyFrameRule
|
|
940
|
+
| AstInvalidRule
|
|
941
|
+
| AstInvalidAtRule;
|
|
792
942
|
|
|
793
943
|
/**
|
|
794
944
|
* Declaration visitor handler
|
|
@@ -826,7 +976,13 @@ declare class SourceMap {
|
|
|
826
976
|
toJSON(): SourceMapObject;
|
|
827
977
|
}
|
|
828
978
|
|
|
829
|
-
export declare
|
|
979
|
+
export declare interface PropertyListOptions {
|
|
980
|
+
|
|
981
|
+
removeDuplicateDeclarations?: boolean;
|
|
982
|
+
computeShorthand?: boolean;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
export declare type WalkerOption = 'ignore' | 'stop' | 'children' | 'ignore-children' | Token | null;
|
|
830
986
|
/**
|
|
831
987
|
* returned value:
|
|
832
988
|
* - 'ignore': ignore this node and its children
|
|
@@ -843,20 +999,21 @@ export declare type WalkerFilter = (node: AstNode) => WalkerOption;
|
|
|
843
999
|
* - 'children': walk the children and ignore the node itself
|
|
844
1000
|
* - 'ignore-children': walk the node and ignore children
|
|
845
1001
|
*/
|
|
846
|
-
export declare type WalkerValueFilter = (node: Token) => WalkerOption;
|
|
1002
|
+
export declare type WalkerValueFilter = (node: AstNode | Token, parent: FunctionToken | ParensToken | BinaryExpressionToken, event?: WalkerValueEvent) => WalkerOption | null;
|
|
847
1003
|
|
|
848
1004
|
export declare interface WalkResult {
|
|
849
1005
|
node: AstNode;
|
|
850
1006
|
parent?: AstRuleList;
|
|
851
|
-
root?:
|
|
1007
|
+
root?: AstNode;
|
|
852
1008
|
}
|
|
853
1009
|
|
|
854
1010
|
export declare interface WalkAttributesResult {
|
|
855
1011
|
value: Token;
|
|
856
1012
|
previousValue: Token | null;
|
|
857
|
-
nextValue:
|
|
1013
|
+
nextValue: Token | null;
|
|
858
1014
|
root?: AstNode;
|
|
859
1015
|
parent: FunctionToken | ParensToken | BinaryExpressionToken | null;
|
|
1016
|
+
list: Token[] | null;
|
|
860
1017
|
}
|
|
861
1018
|
|
|
862
1019
|
export declare interface ErrorDescription {
|
|
@@ -875,6 +1032,7 @@ export declare interface ErrorDescription {
|
|
|
875
1032
|
interface ValidationOptions {
|
|
876
1033
|
|
|
877
1034
|
validation?: boolean;
|
|
1035
|
+
lenient?: boolean;
|
|
878
1036
|
}
|
|
879
1037
|
|
|
880
1038
|
export declare interface ParserOptions extends ValidationOptions, PropertyListOptions {
|
|
@@ -925,9 +1083,7 @@ export declare interface MinifyFeature {
|
|
|
925
1083
|
export declare interface MinifyFeature {
|
|
926
1084
|
|
|
927
1085
|
ordering: number;
|
|
928
|
-
|
|
929
1086
|
register: (options: MinifyOptions | ParserOptions) => void;
|
|
930
|
-
|
|
931
1087
|
run: (ast: AstRule | AstAtRule, options: ParserOptions, parent: AstRule | AstAtRule | AstRuleStyleSheet, context: {
|
|
932
1088
|
[key: string]: any
|
|
933
1089
|
}) => void;
|
|
@@ -941,6 +1097,8 @@ export declare interface ResolvedPath {
|
|
|
941
1097
|
export declare interface RenderOptions {
|
|
942
1098
|
|
|
943
1099
|
minify?: boolean;
|
|
1100
|
+
beautify?: boolean;
|
|
1101
|
+
removeEmpty?: boolean;
|
|
944
1102
|
expandNestingRules?: boolean;
|
|
945
1103
|
preserveLicense?: boolean;
|
|
946
1104
|
sourcemap?: boolean;
|
|
@@ -953,7 +1111,6 @@ export declare interface RenderOptions {
|
|
|
953
1111
|
cwd?: string;
|
|
954
1112
|
load?: (url: string, currentUrl: string) => Promise<string>;
|
|
955
1113
|
resolve?: (url: string, currentUrl: string, currentWorkingDirectory?: string) => ResolvedPath;
|
|
956
|
-
|
|
957
1114
|
}
|
|
958
1115
|
|
|
959
1116
|
export declare interface TransformOptions extends ParserOptions, RenderOptions {
|
|
@@ -1013,11 +1170,6 @@ declare function resolve(url: string, currentDirectory: string, cwd?: string): {
|
|
|
1013
1170
|
|
|
1014
1171
|
declare function load(url: string, currentFile: string): Promise<string>;
|
|
1015
1172
|
|
|
1016
|
-
/**
|
|
1017
|
-
* entry point for node and other runtimes
|
|
1018
|
-
* @module
|
|
1019
|
-
*/
|
|
1020
|
-
|
|
1021
1173
|
/**
|
|
1022
1174
|
* render ast node
|
|
1023
1175
|
*/
|
package/dist/lib/ast/expand.js
CHANGED
|
@@ -6,6 +6,10 @@ import { renderToken } from '../renderer/render.js';
|
|
|
6
6
|
import '../renderer/color/utils/constants.js';
|
|
7
7
|
import '../parser/utils/config.js';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* expand nested css ast
|
|
11
|
+
* @param ast
|
|
12
|
+
*/
|
|
9
13
|
function expand(ast) {
|
|
10
14
|
//
|
|
11
15
|
if (![EnumToken.RuleNodeType, EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType].includes(ast.typ)) {
|
|
@@ -34,6 +38,7 @@ function expand(ast) {
|
|
|
34
38
|
let hasRule = false;
|
|
35
39
|
let j = node.chi.length;
|
|
36
40
|
while (j--) {
|
|
41
|
+
// @ts-ignore
|
|
37
42
|
if (node.chi[j].typ == EnumToken.RuleNodeType || node.chi[j].typ == EnumToken.AtRuleNodeType) {
|
|
38
43
|
hasRule = true;
|
|
39
44
|
break;
|
|
@@ -72,20 +77,21 @@ function expandRule(node) {
|
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
else {
|
|
75
|
-
let
|
|
80
|
+
let childSelectorCompound = [];
|
|
76
81
|
let withCompound = [];
|
|
77
82
|
let withoutCompound = [];
|
|
78
83
|
const rules = splitRule(ast.sel);
|
|
84
|
+
const parentSelector = !node.sel.includes('&');
|
|
79
85
|
for (const sel of (rule.raw ?? splitRule(rule.sel))) {
|
|
80
86
|
const s = sel.join('');
|
|
81
|
-
if (s.includes('&')) {
|
|
87
|
+
if (s.includes('&') || parentSelector) {
|
|
82
88
|
if (s.indexOf('&', 1) == -1) {
|
|
83
89
|
if (s.at(0) == '&') {
|
|
84
90
|
if (s.at(1) == ' ') {
|
|
85
|
-
|
|
91
|
+
childSelectorCompound.push(s.slice(2));
|
|
86
92
|
}
|
|
87
93
|
else {
|
|
88
|
-
if (s == '&') {
|
|
94
|
+
if (s == '&' || parentSelector) {
|
|
89
95
|
withCompound.push(s);
|
|
90
96
|
}
|
|
91
97
|
else {
|
|
@@ -93,6 +99,9 @@ function expandRule(node) {
|
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
}
|
|
102
|
+
else {
|
|
103
|
+
withoutCompound.push(s);
|
|
104
|
+
}
|
|
96
105
|
}
|
|
97
106
|
else {
|
|
98
107
|
withCompound.push(s);
|
|
@@ -104,12 +113,18 @@ function expandRule(node) {
|
|
|
104
113
|
}
|
|
105
114
|
const selectors = [];
|
|
106
115
|
const selector = rules.length > 1 ? ':is(' + rules.map(a => a.join('')).join(',') + ')' : rules[0].join('');
|
|
107
|
-
if (
|
|
108
|
-
if (
|
|
109
|
-
selectors.push(replaceCompound('& ' +
|
|
116
|
+
if (childSelectorCompound.length > 0) {
|
|
117
|
+
if (childSelectorCompound.length == 1) {
|
|
118
|
+
selectors.push(replaceCompound('& ' + childSelectorCompound[0].trim(), selector));
|
|
110
119
|
}
|
|
111
120
|
else {
|
|
112
|
-
selectors.push(replaceCompound('& :is(' +
|
|
121
|
+
selectors.push(replaceCompound('& :is(' + childSelectorCompound.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.trim(), '') + ')', selector));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (withCompound.length > 0) {
|
|
125
|
+
if (withCompound.every((t) => t[0] == '&' && t.indexOf('&', 1) == -1)) {
|
|
126
|
+
withoutCompound.push(...withCompound.map(t => t.slice(1)));
|
|
127
|
+
withCompound.length = 0;
|
|
113
128
|
}
|
|
114
129
|
}
|
|
115
130
|
if (withoutCompound.length > 0) {
|
|
@@ -144,7 +159,10 @@ function expandRule(node) {
|
|
|
144
159
|
if (astAtRule.val.includes('&')) {
|
|
145
160
|
astAtRule.val = replaceCompound(astAtRule.val, ast.sel);
|
|
146
161
|
}
|
|
147
|
-
|
|
162
|
+
const slice = astAtRule.chi.slice().filter(t => t.typ == EnumToken.RuleNodeType && t.sel.includes('&'));
|
|
163
|
+
if (slice.length > 0) {
|
|
164
|
+
expandRule({ ...node, chi: astAtRule.chi.slice() });
|
|
165
|
+
}
|
|
148
166
|
}
|
|
149
167
|
else {
|
|
150
168
|
// @ts-ignore
|
|
@@ -183,11 +201,30 @@ function expandRule(node) {
|
|
|
183
201
|
// @ts-ignore
|
|
184
202
|
return ast.chi.length > 0 ? [ast].concat(result) : result;
|
|
185
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* replace compound selector
|
|
206
|
+
* @param input
|
|
207
|
+
* @param replace
|
|
208
|
+
*/
|
|
186
209
|
function replaceCompound(input, replace) {
|
|
187
210
|
const tokens = parseString(input);
|
|
211
|
+
let replacement = null;
|
|
188
212
|
for (const t of walkValues(tokens)) {
|
|
189
213
|
if (t.value.typ == EnumToken.LiteralTokenType) {
|
|
190
214
|
if (t.value.val == '&') {
|
|
215
|
+
if (tokens.length == 2) {
|
|
216
|
+
if (replacement == null) {
|
|
217
|
+
replacement = parseString(replace);
|
|
218
|
+
}
|
|
219
|
+
if (tokens[1].typ == EnumToken.IdenTokenType) {
|
|
220
|
+
t.value.val = replacement.length == 1 || (!replace.includes(' ') && replace.charAt(0).match(/[:.]/)) ? tokens[1].val + replace : replaceCompoundLiteral(tokens[1].val + '&', replace);
|
|
221
|
+
tokens.splice(1, 1);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
t.value.val = replaceCompoundLiteral(t.value.val, replace);
|
|
225
|
+
}
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
191
228
|
const rule = splitRule(replace);
|
|
192
229
|
t.value.val = rule.length > 1 ? ':is(' + replace + ')' : replace;
|
|
193
230
|
}
|