@tbela99/css-parser 0.9.1 → 1.1.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/CHANGELOG.md +265 -0
- package/LICENSE.md +1 -1
- package/README.md +29 -17
- package/dist/index-umd-web.js +7461 -4360
- package/dist/index.cjs +8608 -5507
- package/dist/index.d.ts +203 -61
- package/dist/lib/ast/expand.js +2 -1
- package/dist/lib/ast/features/calc.js +19 -11
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.js +47 -29
- package/dist/lib/ast/features/prefix.js +117 -91
- package/dist/lib/ast/features/shorthand.js +34 -14
- package/dist/lib/ast/features/transform.js +67 -0
- package/dist/lib/ast/features/type.js +7 -0
- package/dist/lib/ast/math/expression.js +20 -10
- package/dist/lib/ast/math/math.js +20 -2
- package/dist/lib/ast/minify.js +209 -80
- package/dist/lib/ast/transform/compute.js +337 -0
- package/dist/lib/ast/transform/convert.js +33 -0
- package/dist/lib/ast/transform/matrix.js +112 -0
- package/dist/lib/ast/transform/minify.js +296 -0
- package/dist/lib/ast/transform/perspective.js +10 -0
- package/dist/lib/ast/transform/rotate.js +40 -0
- package/dist/lib/ast/transform/scale.js +32 -0
- package/dist/lib/ast/transform/skew.js +23 -0
- package/dist/lib/ast/transform/translate.js +32 -0
- package/dist/lib/ast/transform/utils.js +198 -0
- package/dist/lib/ast/types.js +18 -15
- package/dist/lib/ast/walk.js +54 -22
- package/dist/lib/fs/resolve.js +10 -0
- package/dist/lib/parser/declaration/list.js +48 -45
- package/dist/lib/parser/declaration/map.js +1 -0
- package/dist/lib/parser/declaration/set.js +2 -1
- package/dist/lib/parser/parse.js +449 -340
- package/dist/lib/parser/tokenize.js +147 -72
- package/dist/lib/parser/utils/declaration.js +5 -4
- package/dist/lib/parser/utils/type.js +2 -1
- package/dist/lib/renderer/color/a98rgb.js +2 -1
- package/dist/lib/renderer/color/{colormix.js → color-mix.js} +16 -7
- package/dist/lib/renderer/color/color.js +264 -170
- package/dist/lib/renderer/color/hex.js +19 -8
- package/dist/lib/renderer/color/hsl.js +9 -3
- package/dist/lib/renderer/color/hwb.js +2 -1
- package/dist/lib/renderer/color/lab.js +10 -1
- package/dist/lib/renderer/color/lch.js +10 -1
- package/dist/lib/renderer/color/oklab.js +10 -1
- package/dist/lib/renderer/color/oklch.js +10 -1
- package/dist/lib/renderer/color/p3.js +2 -1
- package/dist/lib/renderer/color/rec2020.js +2 -1
- package/dist/lib/renderer/color/relativecolor.js +27 -32
- package/dist/lib/renderer/color/rgb.js +14 -10
- package/dist/lib/renderer/color/srgb.js +48 -23
- package/dist/lib/renderer/color/utils/components.js +18 -6
- package/dist/lib/renderer/color/utils/constants.js +47 -3
- package/dist/lib/renderer/color/xyz.js +2 -1
- package/dist/lib/renderer/color/xyzd50.js +2 -1
- package/dist/lib/renderer/render.js +108 -43
- package/dist/lib/syntax/syntax.js +267 -136
- package/dist/lib/validation/at-rules/container.js +81 -103
- package/dist/lib/validation/at-rules/counter-style.js +9 -8
- package/dist/lib/validation/at-rules/custom-media.js +13 -15
- package/dist/lib/validation/at-rules/document.js +22 -27
- package/dist/lib/validation/at-rules/font-feature-values.js +8 -8
- package/dist/lib/validation/at-rules/import.js +30 -81
- package/dist/lib/validation/at-rules/keyframes.js +19 -23
- package/dist/lib/validation/at-rules/layer.js +5 -5
- package/dist/lib/validation/at-rules/media.js +42 -53
- package/dist/lib/validation/at-rules/namespace.js +19 -23
- package/dist/lib/validation/at-rules/page-margin-box.js +15 -18
- package/dist/lib/validation/at-rules/page.js +8 -7
- package/dist/lib/validation/at-rules/supports.js +73 -82
- package/dist/lib/validation/at-rules/when.js +32 -36
- package/dist/lib/validation/atrule.js +15 -18
- package/dist/lib/validation/config.js +24 -1
- package/dist/lib/validation/config.json.js +563 -63
- package/dist/lib/validation/parser/parse.js +196 -185
- package/dist/lib/validation/parser/types.js +1 -1
- package/dist/lib/validation/selector.js +8 -5
- package/dist/lib/validation/syntax.js +724 -1405
- package/dist/lib/validation/syntaxes/complex-selector-list.js +10 -11
- package/dist/lib/validation/syntaxes/complex-selector.js +10 -11
- package/dist/lib/validation/syntaxes/compound-selector.js +40 -50
- package/dist/lib/validation/syntaxes/family-name.js +9 -8
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +6 -5
- package/dist/lib/validation/syntaxes/keyframe-selector.js +23 -105
- package/dist/lib/validation/syntaxes/layer-name.js +6 -5
- package/dist/lib/validation/syntaxes/relative-selector-list.js +7 -6
- package/dist/lib/validation/syntaxes/relative-selector.js +17 -15
- package/dist/lib/validation/syntaxes/url.js +18 -22
- package/dist/lib/validation/utils/list.js +20 -2
- package/dist/lib/validation/utils/whitespace.js +2 -1
- package/dist/node/index.js +4 -2
- package/dist/node/load.js +6 -1
- package/dist/web/index.js +4 -2
- package/dist/web/load.js +5 -0
- package/package.json +16 -15
- package/dist/lib/renderer/color/prophotoRgb.js +0 -56
- package/dist/lib/validation/declaration.js +0 -94
- package/dist/lib/validation/syntaxes/image.js +0 -29
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* validation level enum
|
|
3
|
+
*/
|
|
4
|
+
declare enum ValidationLevel {
|
|
5
|
+
None = 0,
|
|
6
|
+
Default = 1,// selectors + at-rules
|
|
7
|
+
All = 2
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* token types enum
|
|
11
|
+
*/
|
|
1
12
|
declare enum EnumToken {
|
|
2
13
|
CommentTokenType = 0,
|
|
3
14
|
CDOCOMMTokenType = 1,
|
|
@@ -92,6 +103,8 @@ declare enum EnumToken {
|
|
|
92
103
|
MediaFeatureOrTokenType = 90,
|
|
93
104
|
PseudoPageTokenType = 91,
|
|
94
105
|
PseudoElementTokenType = 92,
|
|
106
|
+
KeyframeAtRuleNodeType = 93,
|
|
107
|
+
InvalidDeclarationNodeType = 94,
|
|
95
108
|
Time = 25,
|
|
96
109
|
Iden = 7,
|
|
97
110
|
EOF = 48,
|
|
@@ -130,10 +143,16 @@ declare enum EnumToken {
|
|
|
130
143
|
* @param nestingContent
|
|
131
144
|
* @param context
|
|
132
145
|
*/
|
|
133
|
-
declare function minify(ast: AstNode, options?: ParserOptions
|
|
146
|
+
declare function minify(ast: AstNode, options?: ParserOptions, recursive?: boolean, errors?: ErrorDescription[], nestingContent?: boolean, context?: {
|
|
134
147
|
[key: string]: any;
|
|
135
148
|
}): AstNode;
|
|
136
149
|
|
|
150
|
+
declare enum WalkerOptionEnum {
|
|
151
|
+
Ignore = 0,
|
|
152
|
+
Stop = 1,
|
|
153
|
+
Children = 2,
|
|
154
|
+
IgnoreChildren = 3
|
|
155
|
+
}
|
|
137
156
|
declare enum WalkerValueEvent {
|
|
138
157
|
Enter = 0,
|
|
139
158
|
Leave = 1
|
|
@@ -145,14 +164,14 @@ declare enum WalkerValueEvent {
|
|
|
145
164
|
*/
|
|
146
165
|
declare function walk(node: AstNode, filter?: WalkerFilter): Generator<WalkResult>;
|
|
147
166
|
/**
|
|
148
|
-
* walk ast
|
|
167
|
+
* walk ast node value tokens
|
|
149
168
|
* @param values
|
|
150
169
|
* @param root
|
|
151
170
|
* @param filter
|
|
152
171
|
* @param reverse
|
|
153
172
|
*/
|
|
154
173
|
declare function walkValues(values: Token[], root?: AstNode | Token | null, filter?: WalkerValueFilter | {
|
|
155
|
-
event
|
|
174
|
+
event?: WalkerValueEvent;
|
|
156
175
|
fn?: WalkerValueFilter;
|
|
157
176
|
type?: EnumToken | EnumToken[] | ((token: Token) => boolean);
|
|
158
177
|
}, reverse?: boolean): Generator<WalkAttributesResult>;
|
|
@@ -175,8 +194,37 @@ declare function renderToken(token: Token, options?: RenderOptions, cache?: {
|
|
|
175
194
|
[key: string]: any;
|
|
176
195
|
}, reducer?: (acc: string, curr: Token) => string, errors?: ErrorDescription[]): string;
|
|
177
196
|
|
|
197
|
+
declare enum ColorKind {
|
|
198
|
+
SYS = 0,
|
|
199
|
+
DPSYS = 1,
|
|
200
|
+
LIT = 2,
|
|
201
|
+
HEX = 3,
|
|
202
|
+
RGB = 4,
|
|
203
|
+
RGBA = 5,
|
|
204
|
+
HSL = 6,
|
|
205
|
+
HSLA = 7,
|
|
206
|
+
HWB = 8,
|
|
207
|
+
DEVICE_CMYK = 9,
|
|
208
|
+
OKLAB = 10,
|
|
209
|
+
OKLCH = 11,
|
|
210
|
+
LAB = 12,
|
|
211
|
+
LCH = 13,
|
|
212
|
+
COLOR = 14,
|
|
213
|
+
SRGB = 15,
|
|
214
|
+
PROPHOTO_RGB = 16,
|
|
215
|
+
A98_RGB = 17,
|
|
216
|
+
REC2020 = 18,
|
|
217
|
+
DISPLAY_P3 = 19,
|
|
218
|
+
SRGB_LINEAR = 20,
|
|
219
|
+
XYZ = 21,
|
|
220
|
+
XYZ_D50 = 22,
|
|
221
|
+
XYZ_D65 = 23,
|
|
222
|
+
LIGHT_DARK = 24,
|
|
223
|
+
COLOR_MIX = 25
|
|
224
|
+
}
|
|
225
|
+
|
|
178
226
|
/**
|
|
179
|
-
* parse string
|
|
227
|
+
* parse css string
|
|
180
228
|
* @param src
|
|
181
229
|
* @param options
|
|
182
230
|
*/
|
|
@@ -184,7 +232,7 @@ declare function parseString(src: string, options?: {
|
|
|
184
232
|
location: boolean;
|
|
185
233
|
}): Token[];
|
|
186
234
|
/**
|
|
187
|
-
* parse token
|
|
235
|
+
* parse token array into a tree structure
|
|
188
236
|
* @param tokens
|
|
189
237
|
* @param options
|
|
190
238
|
*/
|
|
@@ -564,26 +612,6 @@ export declare interface ImportantToken extends BaseToken {
|
|
|
564
612
|
typ: EnumToken.ImportantTokenType;
|
|
565
613
|
}
|
|
566
614
|
|
|
567
|
-
export declare type ColorKind =
|
|
568
|
-
'sys'
|
|
569
|
-
| 'dpsys'
|
|
570
|
-
| 'lit'
|
|
571
|
-
| 'hex'
|
|
572
|
-
| 'rgb'
|
|
573
|
-
| 'rgba'
|
|
574
|
-
| 'hsl'
|
|
575
|
-
| 'hsla'
|
|
576
|
-
| 'hwb'
|
|
577
|
-
| 'device-cmyk'
|
|
578
|
-
| 'oklab'
|
|
579
|
-
| 'oklch'
|
|
580
|
-
| 'lab'
|
|
581
|
-
| 'lch'
|
|
582
|
-
| 'color'
|
|
583
|
-
| 'light-dark';
|
|
584
|
-
|
|
585
|
-
// export declare type HueInterpolationMethod = 'shorter' | 'longer' | 'increasing' | 'decreasing';
|
|
586
|
-
|
|
587
615
|
export declare interface ColorToken extends BaseToken {
|
|
588
616
|
|
|
589
617
|
typ: EnumToken.ColorTokenType;
|
|
@@ -838,6 +866,69 @@ export declare type Token =
|
|
|
838
866
|
| AttrToken
|
|
839
867
|
| EOFToken;
|
|
840
868
|
|
|
869
|
+
declare enum ValidationTokenEnum {
|
|
870
|
+
Root = 0,
|
|
871
|
+
Keyword = 1,
|
|
872
|
+
PropertyType = 2,
|
|
873
|
+
DeclarationType = 3,
|
|
874
|
+
AtRule = 4,
|
|
875
|
+
ValidationFunctionDefinition = 5,
|
|
876
|
+
OpenBracket = 6,
|
|
877
|
+
CloseBracket = 7,
|
|
878
|
+
OpenParenthesis = 8,
|
|
879
|
+
CloseParenthesis = 9,
|
|
880
|
+
Comma = 10,
|
|
881
|
+
Pipe = 11,
|
|
882
|
+
Column = 12,
|
|
883
|
+
Star = 13,
|
|
884
|
+
OpenCurlyBrace = 14,
|
|
885
|
+
CloseCurlyBrace = 15,
|
|
886
|
+
HashMark = 16,
|
|
887
|
+
QuestionMark = 17,
|
|
888
|
+
Function = 18,
|
|
889
|
+
Number = 19,
|
|
890
|
+
Whitespace = 20,
|
|
891
|
+
Parenthesis = 21,
|
|
892
|
+
Bracket = 22,
|
|
893
|
+
Block = 23,
|
|
894
|
+
AtLeastOnce = 24,
|
|
895
|
+
Separator = 25,
|
|
896
|
+
Exclamation = 26,
|
|
897
|
+
Ampersand = 27,
|
|
898
|
+
PipeToken = 28,
|
|
899
|
+
ColumnToken = 29,
|
|
900
|
+
AmpersandToken = 30,
|
|
901
|
+
Parens = 31,
|
|
902
|
+
PseudoClassToken = 32,
|
|
903
|
+
PseudoClassFunctionToken = 33,
|
|
904
|
+
StringToken = 34,
|
|
905
|
+
AtRuleDefinition = 35,
|
|
906
|
+
DeclarationNameToken = 36,
|
|
907
|
+
DeclarationDefinitionToken = 37,
|
|
908
|
+
SemiColon = 38,
|
|
909
|
+
Character = 39,
|
|
910
|
+
InfinityToken = 40
|
|
911
|
+
}
|
|
912
|
+
interface Position$1 {
|
|
913
|
+
ind: number;
|
|
914
|
+
lin: number;
|
|
915
|
+
col: number;
|
|
916
|
+
}
|
|
917
|
+
interface ValidationToken {
|
|
918
|
+
typ: ValidationTokenEnum;
|
|
919
|
+
pos: Position$1;
|
|
920
|
+
isList?: boolean;
|
|
921
|
+
text?: string;
|
|
922
|
+
isRepeatable?: boolean;
|
|
923
|
+
atLeastOnce?: boolean;
|
|
924
|
+
isOptional?: boolean;
|
|
925
|
+
isRepeatableGroup?: boolean;
|
|
926
|
+
occurence?: {
|
|
927
|
+
min: number;
|
|
928
|
+
max: number | null;
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
|
|
841
932
|
export declare interface Position {
|
|
842
933
|
|
|
843
934
|
ind: number;
|
|
@@ -848,7 +939,7 @@ export declare interface Position {
|
|
|
848
939
|
export declare interface Location {
|
|
849
940
|
|
|
850
941
|
sta: Position;
|
|
851
|
-
|
|
942
|
+
end: Position;
|
|
852
943
|
src: string;
|
|
853
944
|
}
|
|
854
945
|
|
|
@@ -858,6 +949,7 @@ export declare interface BaseToken {
|
|
|
858
949
|
loc?: Location;
|
|
859
950
|
tokens?: Token[];
|
|
860
951
|
parent?: AstRuleList;
|
|
952
|
+
validSyntax?: boolean;
|
|
861
953
|
}
|
|
862
954
|
|
|
863
955
|
export declare interface AstComment extends BaseToken {
|
|
@@ -873,32 +965,28 @@ export declare interface AstDeclaration extends BaseToken {
|
|
|
873
965
|
typ: EnumToken.DeclarationNodeType
|
|
874
966
|
}
|
|
875
967
|
|
|
876
|
-
|
|
877
968
|
export declare interface AstRule extends BaseToken {
|
|
878
969
|
|
|
879
970
|
typ: EnumToken.RuleNodeType;
|
|
880
971
|
sel: string;
|
|
881
972
|
chi: Array<AstDeclaration | AstComment | AstRuleList>;
|
|
882
|
-
optimized?: OptimizedSelector;
|
|
883
|
-
raw?: RawSelectorTokens;
|
|
973
|
+
optimized?: OptimizedSelector | null;
|
|
974
|
+
raw?: RawSelectorTokens | null;
|
|
884
975
|
}
|
|
885
976
|
|
|
886
977
|
export declare interface AstInvalidRule extends BaseToken {
|
|
887
978
|
|
|
888
979
|
typ: EnumToken.InvalidRuleTokenType;
|
|
889
980
|
sel: string;
|
|
890
|
-
chi: Array<
|
|
981
|
+
chi: Array<AstNode>;
|
|
891
982
|
}
|
|
892
983
|
|
|
893
|
-
export declare interface
|
|
984
|
+
export declare interface AstInvalidDeclaration extends BaseToken {
|
|
894
985
|
|
|
895
|
-
typ: EnumToken.
|
|
896
|
-
val:
|
|
897
|
-
chi?: Array<AstNode>;
|
|
986
|
+
typ: EnumToken.InvalidDeclarationNodeType;
|
|
987
|
+
val: Array<AstNode>;
|
|
898
988
|
}
|
|
899
989
|
|
|
900
|
-
|
|
901
|
-
|
|
902
990
|
export declare interface AstKeyFrameRule extends BaseToken {
|
|
903
991
|
|
|
904
992
|
typ: EnumToken.KeyFrameRuleNodeType;
|
|
@@ -923,17 +1011,34 @@ export declare interface AstAtRule extends BaseToken {
|
|
|
923
1011
|
typ: EnumToken.AtRuleNodeType,
|
|
924
1012
|
nam: string;
|
|
925
1013
|
val: string;
|
|
926
|
-
chi?: Array<AstDeclaration | AstComment> | Array<AstRule | AstComment>
|
|
1014
|
+
chi?: Array<AstDeclaration | AstInvalidDeclaration | AstComment> | Array<AstRule | AstComment>
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
export declare interface AstKeyframeRule extends BaseToken {
|
|
1018
|
+
|
|
1019
|
+
typ: EnumToken.KeyFrameRuleNodeType;
|
|
1020
|
+
sel: string;
|
|
1021
|
+
chi: Array<AstDeclaration | AstInvalidDeclaration | AstComment | AstRuleList>;
|
|
1022
|
+
optimized?: OptimizedSelector;
|
|
1023
|
+
raw?: RawSelectorTokens;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
export declare interface AstKeyframAtRule extends BaseToken {
|
|
1027
|
+
|
|
1028
|
+
typ: EnumToken.KeyframeAtRuleNodeType,
|
|
1029
|
+
nam: string;
|
|
1030
|
+
val: string;
|
|
1031
|
+
chi: Array<AstKeyframeRule | AstComment>;
|
|
927
1032
|
}
|
|
928
1033
|
|
|
929
1034
|
export declare interface AstRuleList extends BaseToken {
|
|
930
1035
|
|
|
931
|
-
typ:
|
|
1036
|
+
typ: EnumToken.StyleSheetNodeType | EnumToken.RuleNodeType | EnumToken.AtRuleNodeType | EnumToken.KeyframeAtRuleNodeType | EnumToken.KeyFrameRuleNodeType | EnumToken.InvalidRuleTokenType | EnumToken.InvalidAtRuleTokenType,
|
|
932
1037
|
chi: Array<BaseToken | AstComment>;
|
|
933
1038
|
}
|
|
934
1039
|
|
|
935
1040
|
export declare interface AstRuleStyleSheet extends AstRuleList {
|
|
936
|
-
typ:
|
|
1041
|
+
typ: EnumToken.StyleSheetNodeType,
|
|
937
1042
|
chi: Array<AstRuleList | AstComment>
|
|
938
1043
|
}
|
|
939
1044
|
|
|
@@ -944,9 +1049,10 @@ export declare type AstNode =
|
|
|
944
1049
|
| AstAtRule
|
|
945
1050
|
| AstRule
|
|
946
1051
|
| AstDeclaration
|
|
1052
|
+
| AstKeyframAtRule
|
|
947
1053
|
| AstKeyFrameRule
|
|
948
1054
|
| AstInvalidRule
|
|
949
|
-
|
|
|
1055
|
+
| AstInvalidDeclaration;
|
|
950
1056
|
|
|
951
1057
|
/**
|
|
952
1058
|
* Declaration visitor handler
|
|
@@ -990,13 +1096,18 @@ export declare interface PropertyListOptions {
|
|
|
990
1096
|
computeShorthand?: boolean;
|
|
991
1097
|
}
|
|
992
1098
|
|
|
993
|
-
|
|
1099
|
+
declare enum FeatureWalkMode {
|
|
1100
|
+
Pre = 0,
|
|
1101
|
+
Post = 1
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
export declare type WalkerOption = WalkerOptionEnum | Token | null;
|
|
994
1105
|
/**
|
|
995
1106
|
* returned value:
|
|
996
|
-
* -
|
|
997
|
-
* -
|
|
998
|
-
* -
|
|
999
|
-
* -
|
|
1107
|
+
* - WalkerOptionEnum.Ignore: ignore this node and its children
|
|
1108
|
+
* - WalkerOptionEnum.Stop: stop walking the tree
|
|
1109
|
+
* - WalkerOptionEnum.Children: walk the children and ignore the node itself
|
|
1110
|
+
* - WalkerOptionEnum.IgnoreChildren: walk the node and ignore children
|
|
1000
1111
|
*/
|
|
1001
1112
|
export declare type WalkerFilter = (node: AstNode) => WalkerOption;
|
|
1002
1113
|
|
|
@@ -1007,7 +1118,7 @@ export declare type WalkerFilter = (node: AstNode) => WalkerOption;
|
|
|
1007
1118
|
* - 'children': walk the children and ignore the node itself
|
|
1008
1119
|
* - 'ignore-children': walk the node and ignore children
|
|
1009
1120
|
*/
|
|
1010
|
-
export declare type WalkerValueFilter = (node: AstNode | Token, parent
|
|
1121
|
+
export declare type WalkerValueFilter = (node: AstNode | Token, parent?: FunctionToken | ParensToken | BinaryExpressionToken, event?: WalkerValueEvent) => WalkerOption | null;
|
|
1011
1122
|
|
|
1012
1123
|
export declare interface WalkResult {
|
|
1013
1124
|
node: AstNode;
|
|
@@ -1020,7 +1131,7 @@ export declare interface WalkAttributesResult {
|
|
|
1020
1131
|
previousValue: Token | null;
|
|
1021
1132
|
nextValue: Token | null;
|
|
1022
1133
|
root?: AstNode;
|
|
1023
|
-
parent:
|
|
1134
|
+
parent: AstNode | Token | null;
|
|
1024
1135
|
list: Token[] | null;
|
|
1025
1136
|
}
|
|
1026
1137
|
|
|
@@ -1029,18 +1140,21 @@ export declare interface ErrorDescription {
|
|
|
1029
1140
|
// drop rule or declaration | fix rule or declaration
|
|
1030
1141
|
action: 'drop' | 'ignore';
|
|
1031
1142
|
message: string;
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
lin: number,
|
|
1035
|
-
col: number;
|
|
1036
|
-
};
|
|
1143
|
+
syntax?: string;
|
|
1144
|
+
location?: Location;
|
|
1037
1145
|
error?: Error;
|
|
1146
|
+
rawTokens?: TokenizeResult[];
|
|
1038
1147
|
}
|
|
1039
1148
|
|
|
1040
1149
|
interface ValidationOptions {
|
|
1041
1150
|
|
|
1042
|
-
validation?: boolean;
|
|
1151
|
+
validation?: boolean | ValidationLevel;
|
|
1043
1152
|
lenient?: boolean;
|
|
1153
|
+
visited?: WeakMap<Token, Map<string, Set<ValidationToken>>>;
|
|
1154
|
+
isRepeatable?:boolean | null;
|
|
1155
|
+
isList?:boolean | null;
|
|
1156
|
+
occurence?:boolean | null;
|
|
1157
|
+
atLeastOnce?: boolean | null;
|
|
1044
1158
|
}
|
|
1045
1159
|
|
|
1046
1160
|
interface MinifyOptions {
|
|
@@ -1050,16 +1164,17 @@ interface MinifyOptions {
|
|
|
1050
1164
|
expandNestingRules?: boolean;
|
|
1051
1165
|
removeDuplicateDeclarations?: boolean;
|
|
1052
1166
|
computeShorthand?: boolean;
|
|
1167
|
+
computeTransform?: boolean;
|
|
1053
1168
|
computeCalcExpression?: boolean;
|
|
1054
1169
|
inlineCssVariables?: boolean;
|
|
1055
1170
|
removeEmpty?: boolean;
|
|
1056
1171
|
pass?: number;
|
|
1057
1172
|
}
|
|
1058
1173
|
|
|
1059
|
-
export declare interface ParserOptions extends MinifyOptions, ValidationOptions, PropertyListOptions {
|
|
1174
|
+
export declare interface ParserOptions extends MinifyOptions, MinifyFeatureOptions, ValidationOptions, PropertyListOptions {
|
|
1060
1175
|
|
|
1061
1176
|
src?: string;
|
|
1062
|
-
sourcemap?: boolean;
|
|
1177
|
+
sourcemap?: boolean | 'inline';
|
|
1063
1178
|
removeCharset?: boolean;
|
|
1064
1179
|
resolveUrls?: boolean;
|
|
1065
1180
|
resolveImport?: boolean;
|
|
@@ -1075,11 +1190,12 @@ export declare interface ParserOptions extends MinifyOptions, ValidationOptions,
|
|
|
1075
1190
|
visitor?: VisitorNodeMap;
|
|
1076
1191
|
signal?: AbortSignal;
|
|
1077
1192
|
setParent?: boolean;
|
|
1193
|
+
cache?: WeakMap<AstNode, string>;
|
|
1078
1194
|
}
|
|
1079
1195
|
|
|
1080
|
-
export declare interface MinifyFeatureOptions
|
|
1196
|
+
export declare interface MinifyFeatureOptions {
|
|
1081
1197
|
|
|
1082
|
-
features
|
|
1198
|
+
features?: MinifyFeature[];
|
|
1083
1199
|
}
|
|
1084
1200
|
|
|
1085
1201
|
export declare interface MinifyFeature {
|
|
@@ -1096,10 +1212,12 @@ export declare interface MinifyFeature {
|
|
|
1096
1212
|
export declare interface MinifyFeature {
|
|
1097
1213
|
|
|
1098
1214
|
ordering: number;
|
|
1215
|
+
preProcess: boolean;
|
|
1216
|
+
postProcess: boolean;
|
|
1099
1217
|
register: (options: MinifyFeatureOptions | ParserOptions) => void;
|
|
1100
1218
|
run: (ast: AstRule | AstAtRule, options: ParserOptions, parent: AstRule | AstAtRule | AstRuleStyleSheet, context: {
|
|
1101
1219
|
[key: string]: any
|
|
1102
|
-
}) => void;
|
|
1220
|
+
}, mode: FeatureWalkMode) => void;
|
|
1103
1221
|
}
|
|
1104
1222
|
|
|
1105
1223
|
export declare interface ResolvedPath {
|
|
@@ -1114,7 +1232,7 @@ export declare interface RenderOptions {
|
|
|
1114
1232
|
removeEmpty?: boolean;
|
|
1115
1233
|
expandNestingRules?: boolean;
|
|
1116
1234
|
preserveLicense?: boolean;
|
|
1117
|
-
sourcemap?: boolean;
|
|
1235
|
+
sourcemap?: boolean | 'inline';
|
|
1118
1236
|
indent?: string;
|
|
1119
1237
|
newLine?: string;
|
|
1120
1238
|
removeComments?: boolean;
|
|
@@ -1165,6 +1283,15 @@ export declare interface TransformResult extends ParseResult, RenderResult {
|
|
|
1165
1283
|
export declare interface ParseTokenOptions extends ParserOptions {
|
|
1166
1284
|
}
|
|
1167
1285
|
|
|
1286
|
+
export declare interface TokenizeResult {
|
|
1287
|
+
token: string;
|
|
1288
|
+
len: number;
|
|
1289
|
+
hint?: EnumToken;
|
|
1290
|
+
sta: Position;
|
|
1291
|
+
end: Position;
|
|
1292
|
+
bytesIn: number;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1168
1295
|
export declare interface SourceMapObject {
|
|
1169
1296
|
version: number;
|
|
1170
1297
|
file?: string;
|
|
@@ -1175,13 +1302,28 @@ export declare interface SourceMapObject {
|
|
|
1175
1302
|
mappings: string;
|
|
1176
1303
|
}
|
|
1177
1304
|
|
|
1305
|
+
/**
|
|
1306
|
+
* return the directory name of a path
|
|
1307
|
+
* @param path
|
|
1308
|
+
*/
|
|
1178
1309
|
declare function dirname(path: string): string;
|
|
1310
|
+
/**
|
|
1311
|
+
* resolve path
|
|
1312
|
+
* @param url
|
|
1313
|
+
* @param currentDirectory
|
|
1314
|
+
* @param cwd
|
|
1315
|
+
*/
|
|
1179
1316
|
declare function resolve(url: string, currentDirectory: string, cwd?: string): {
|
|
1180
1317
|
absolute: string;
|
|
1181
1318
|
relative: string;
|
|
1182
1319
|
};
|
|
1183
1320
|
|
|
1184
|
-
|
|
1321
|
+
/**
|
|
1322
|
+
* load file
|
|
1323
|
+
* @param url
|
|
1324
|
+
* @param currentFile
|
|
1325
|
+
*/
|
|
1326
|
+
declare function load(url: string, currentFile?: string): Promise<string>;
|
|
1185
1327
|
|
|
1186
1328
|
/**
|
|
1187
1329
|
* render ast node
|
|
@@ -1196,4 +1338,4 @@ declare function parse(iterator: string, opt?: ParserOptions): Promise<ParseResu
|
|
|
1196
1338
|
*/
|
|
1197
1339
|
declare function transform(css: string, options?: TransformOptions): Promise<TransformResult>;
|
|
1198
1340
|
|
|
1199
|
-
export { EnumToken, dirname, expand, load, minify, parse, parseString, parseTokens, render, renderToken, resolve, transform, walk, walkValues };
|
|
1341
|
+
export { EnumToken, ValidationLevel, dirname, expand, load, minify, parse, parseString, parseTokens, render, renderToken, resolve, transform, walk, walkValues };
|
package/dist/lib/ast/expand.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { splitRule, combinators } from './minify.js';
|
|
2
2
|
import { parseString } from '../parser/parse.js';
|
|
3
|
+
import '../parser/tokenize.js';
|
|
4
|
+
import '../parser/utils/config.js';
|
|
3
5
|
import { EnumToken } from './types.js';
|
|
4
6
|
import { walkValues } from './walk.js';
|
|
5
7
|
import { renderToken } from '../renderer/render.js';
|
|
6
8
|
import '../renderer/color/utils/constants.js';
|
|
7
|
-
import '../parser/utils/config.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* expand nested css ast
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import { EnumToken } from '../types.js';
|
|
2
|
-
import { walkValues, WalkerValueEvent } from '../walk.js';
|
|
2
|
+
import { walkValues, WalkerValueEvent, WalkerOptionEnum } from '../walk.js';
|
|
3
3
|
import { evaluate } from '../math/expression.js';
|
|
4
4
|
import { renderToken } from '../../renderer/render.js';
|
|
5
|
+
import '../../renderer/color/utils/constants.js';
|
|
6
|
+
import '../minify.js';
|
|
7
|
+
import '../../parser/parse.js';
|
|
8
|
+
import '../../parser/tokenize.js';
|
|
9
|
+
import '../../parser/utils/config.js';
|
|
5
10
|
import { mathFuncs } from '../../syntax/syntax.js';
|
|
6
11
|
|
|
7
12
|
class ComputeCalcExpressionFeature {
|
|
8
|
-
|
|
13
|
+
get ordering() {
|
|
9
14
|
return 1;
|
|
10
15
|
}
|
|
16
|
+
get preProcess() {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
get postProcess() {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
11
22
|
static register(options) {
|
|
12
23
|
if (options.computeCalcExpression) {
|
|
13
|
-
for (const feature of options.features) {
|
|
14
|
-
if (feature instanceof ComputeCalcExpressionFeature) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
24
|
// @ts-ignore
|
|
19
25
|
options.features.push(new ComputeCalcExpressionFeature());
|
|
20
26
|
}
|
|
@@ -23,7 +29,6 @@ class ComputeCalcExpressionFeature {
|
|
|
23
29
|
if (!('chi' in ast)) {
|
|
24
30
|
return;
|
|
25
31
|
}
|
|
26
|
-
// @ts-ignore
|
|
27
32
|
for (const node of ast.chi) {
|
|
28
33
|
if (node.typ != EnumToken.DeclarationNodeType) {
|
|
29
34
|
continue;
|
|
@@ -31,15 +36,18 @@ class ComputeCalcExpressionFeature {
|
|
|
31
36
|
const set = new Set;
|
|
32
37
|
for (const { value, parent } of walkValues(node.val, node, {
|
|
33
38
|
event: WalkerValueEvent.Enter,
|
|
34
|
-
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
fn(node, parent) {
|
|
35
41
|
if (parent != null &&
|
|
42
|
+
// @ts-ignore
|
|
36
43
|
parent.typ == EnumToken.DeclarationNodeType &&
|
|
44
|
+
// @ts-ignore
|
|
37
45
|
parent.val.length == 1 &&
|
|
38
46
|
node.typ == EnumToken.FunctionTokenType &&
|
|
39
47
|
mathFuncs.includes(node.val) &&
|
|
40
48
|
node.chi.length == 1 &&
|
|
41
49
|
node.chi[0].typ == EnumToken.IdenTokenType) {
|
|
42
|
-
return
|
|
50
|
+
return WalkerOptionEnum.Ignore;
|
|
43
51
|
}
|
|
44
52
|
if ((node.typ == EnumToken.FunctionTokenType && node.val == 'var') || (!mathFuncs.includes(parent.val) && [EnumToken.ColorTokenType, EnumToken.DeclarationNodeType, EnumToken.RuleNodeType, EnumToken.AtRuleNodeType, EnumToken.StyleSheetNodeType].includes(parent?.typ))) {
|
|
45
53
|
return null;
|
|
@@ -61,7 +69,7 @@ class ComputeCalcExpressionFeature {
|
|
|
61
69
|
// @ts-ignore
|
|
62
70
|
node[key] = values;
|
|
63
71
|
}
|
|
64
|
-
return
|
|
72
|
+
return WalkerOptionEnum.Ignore;
|
|
65
73
|
}
|
|
66
74
|
return null;
|
|
67
75
|
}
|
|
@@ -2,3 +2,4 @@ export { ComputePrefixFeature } from './prefix.js';
|
|
|
2
2
|
export { InlineCssVariablesFeature } from './inlinecssvariables.js';
|
|
3
3
|
export { ComputeShorthandFeature } from './shorthand.js';
|
|
4
4
|
export { ComputeCalcExpressionFeature } from './calc.js';
|
|
5
|
+
export { TransformCssFeature } from './transform.js';
|