@tbela99/css-parser 1.3.2 → 1.3.4

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +59 -20
  3. package/dist/index-umd-web.js +1846 -1075
  4. package/dist/index.cjs +1941 -1202
  5. package/dist/index.d.ts +914 -181
  6. package/dist/lib/ast/expand.js +5 -10
  7. package/dist/lib/ast/features/calc.js +8 -8
  8. package/dist/lib/ast/features/inlinecssvariables.js +9 -8
  9. package/dist/lib/ast/features/prefix.js +5 -15
  10. package/dist/lib/ast/features/shorthand.js +5 -6
  11. package/dist/lib/ast/features/transform.js +18 -25
  12. package/dist/lib/ast/features/type.js +4 -2
  13. package/dist/lib/ast/minify.js +56 -112
  14. package/dist/lib/ast/transform/compute.js +2 -4
  15. package/dist/lib/ast/transform/matrix.js +20 -20
  16. package/dist/lib/ast/transform/minify.js +105 -12
  17. package/dist/lib/ast/transform/rotate.js +11 -11
  18. package/dist/lib/ast/transform/scale.js +6 -6
  19. package/dist/lib/ast/transform/skew.js +4 -4
  20. package/dist/lib/ast/transform/translate.js +3 -3
  21. package/dist/lib/ast/transform/utils.js +30 -37
  22. package/dist/lib/ast/types.js +16 -4
  23. package/dist/lib/ast/walk.js +172 -70
  24. package/dist/lib/fs/resolve.js +12 -7
  25. package/dist/lib/parser/declaration/list.js +3 -1
  26. package/dist/lib/parser/parse.js +441 -161
  27. package/dist/lib/parser/tokenize.js +12 -14
  28. package/dist/lib/renderer/render.js +7 -7
  29. package/dist/lib/syntax/color/cmyk.js +6 -3
  30. package/dist/lib/syntax/color/color-mix.js +2 -3
  31. package/dist/lib/syntax/color/color.js +28 -6
  32. package/dist/lib/syntax/color/hex.js +3 -0
  33. package/dist/lib/syntax/color/hsl.js +18 -7
  34. package/dist/lib/syntax/color/hwb.js +3 -3
  35. package/dist/lib/syntax/color/lab.js +4 -4
  36. package/dist/lib/syntax/color/lch.js +7 -4
  37. package/dist/lib/syntax/color/oklab.js +4 -4
  38. package/dist/lib/syntax/color/oklch.js +18 -6
  39. package/dist/lib/syntax/color/relativecolor.js +9 -56
  40. package/dist/lib/syntax/color/srgb.js +1 -1
  41. package/dist/lib/syntax/syntax.js +36 -18
  42. package/dist/lib/validation/at-rules/container.js +11 -0
  43. package/dist/lib/validation/at-rules/counter-style.js +11 -0
  44. package/dist/lib/validation/at-rules/font-feature-values.js +11 -0
  45. package/dist/lib/validation/at-rules/keyframes.js +11 -0
  46. package/dist/lib/validation/at-rules/layer.js +11 -0
  47. package/dist/lib/validation/at-rules/media.js +11 -0
  48. package/dist/lib/validation/at-rules/page-margin-box.js +11 -0
  49. package/dist/lib/validation/at-rules/page.js +11 -0
  50. package/dist/lib/validation/at-rules/supports.js +11 -0
  51. package/dist/lib/validation/at-rules/when.js +11 -0
  52. package/dist/lib/validation/config.js +0 -2
  53. package/dist/lib/validation/config.json.js +21 -9
  54. package/dist/lib/validation/parser/parse.js +53 -2
  55. package/dist/lib/validation/syntax.js +199 -36
  56. package/dist/node.js +63 -36
  57. package/dist/web.js +84 -25
  58. package/package.json +7 -5
  59. package/dist/lib/validation/parser/types.js +0 -54
package/dist/index.d.ts CHANGED
@@ -17,14 +17,26 @@ declare enum ValidationLevel {
17
17
  * disable validation
18
18
  */
19
19
  None = 0,
20
+ /**
21
+ * validate selectors
22
+ */
23
+ Selector = 1,
24
+ /**
25
+ * validate at-rules
26
+ */
27
+ AtRule = 2,
28
+ /**
29
+ * validate declarations
30
+ */
31
+ Declaration = 4,
20
32
  /**
21
33
  * validate selectors and at-rules
22
34
  */
23
- Default = 1,// selectors + at-rules
35
+ Default = 3,// selectors + at-rules
24
36
  /**
25
37
  * validate selectors, at-rules and declarations
26
38
  */
27
- All = 2
39
+ All = 7
28
40
  }
29
41
  /**
30
42
  * enum of all token types
@@ -325,7 +337,7 @@ declare enum EnumToken {
325
337
  /**
326
338
  * keyframe rule node type
327
339
  */
328
- KeyFrameRuleNodeType = 73,
340
+ KeyFramesRuleNodeType = 73,
329
341
  /**
330
342
  * class selector token type
331
343
  */
@@ -405,7 +417,7 @@ declare enum EnumToken {
405
417
  /**
406
418
  * keyframe at rule node type
407
419
  */
408
- KeyframeAtRuleNodeType = 93,
420
+ KeyframesAtRuleNodeType = 93,
409
421
  /**
410
422
  * invalid declaration node type
411
423
  */
@@ -643,53 +655,167 @@ declare enum ColorType {
643
655
  *
644
656
  * @private
645
657
  */
646
- declare function minify(ast: AstNode, options: ParserOptions | MinifyFeatureOptions, recursive: boolean, errors?: ErrorDescription[], nestingContent?: boolean): AstNode;
658
+ declare function minify(ast: AstNode$1, options: ParserOptions | MinifyFeatureOptions, recursive: boolean, errors?: ErrorDescription[], nestingContent?: boolean): AstNode$1;
647
659
 
660
+ /**
661
+ * options for the walk function
662
+ */
648
663
  declare enum WalkerOptionEnum {
649
664
  /**
650
665
  * ignore the current node and its children
651
666
  */
652
- Ignore = 0,
667
+ Ignore = 1,
653
668
  /**
654
669
  * stop walking the tree
655
670
  */
656
- Stop = 1,
671
+ Stop = 2,
657
672
  /**
658
- * ignore node and process children
673
+ * ignore the current node and process its children
659
674
  */
660
- Children = 2,
675
+ Children = 4,
661
676
  /**
662
- * ignore children
677
+ * ignore the current node children
663
678
  */
664
- IgnoreChildren = 3
679
+ IgnoreChildren = 8
665
680
  }
666
- declare enum WalkerValueEvent {
681
+ /**
682
+ * event types for the walkValues function
683
+ */
684
+ declare enum WalkerEvent {
667
685
  /**
668
686
  * enter node
669
687
  */
670
- Enter = 0,
688
+ Enter = 1,
671
689
  /**
672
690
  * leave node
673
691
  */
674
- Leave = 1
692
+ Leave = 2
675
693
  }
676
694
  /**
677
695
  * walk ast nodes
678
- * @param node
679
- * @param filter
696
+ * @param node initial node
697
+ * @param filter control the walk process
698
+ * @param reverse walk in reverse order
699
+ *
700
+ * ```ts
701
+ *
702
+ * import {walk} from '@tbela99/css-parser';
703
+ *
704
+ * const css = `
705
+ * body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
706
+ *
707
+ * html,
708
+ * body {
709
+ * line-height: 1.474;
710
+ * }
711
+ *
712
+ * .ruler {
713
+ *
714
+ * height: 10px;
715
+ * }
716
+ * `;
717
+ *
718
+ * for (const {node, parent, root} of walk(ast)) {
719
+ *
720
+ * // do something with node
721
+ * }
722
+ * ```
723
+ *
724
+ * Using a {@link filter} function to control the ast traversal. the filter function returns a value of type {@link WalkerOption}.
725
+ *
726
+ * ```ts
727
+ * import {EnumToken, transform, walk, WalkerOptionEnum} from '@tbela99/css-parser';
728
+ *
729
+ * const css = `
730
+ * body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
731
+ *
732
+ * html,
733
+ * body {
734
+ * line-height: 1.474;
735
+ * }
736
+ *
737
+ * .ruler {
738
+ *
739
+ * height: 10px;
740
+ * }
741
+ * `;
742
+ *
743
+ * function filter(node) {
744
+ *
745
+ * if (node.typ == EnumToken.AstRule && node.sel.includes('html')) {
746
+ *
747
+ * // skip the children of the current node
748
+ * return WalkerOptionEnum.IgnoreChildren;
749
+ * }
750
+ * }
751
+ *
752
+ * const result = await transform(css);
753
+ * for (const {node} of walk(result.ast, filter)) {
754
+ *
755
+ * console.error([EnumToken[node.typ]]);
756
+ * }
757
+ *
758
+ * // [ "StyleSheetNodeType" ]
759
+ * // [ "RuleNodeType" ]
760
+ * // [ "DeclarationNodeType" ]
761
+ * // [ "RuleNodeType" ]
762
+ * // [ "DeclarationNodeType" ]
763
+ * // [ "RuleNodeType" ]
764
+ * // [ "DeclarationNodeType" ]
765
+ * ```
680
766
  */
681
- declare function walk(node: AstNode, filter?: WalkerFilter): Generator<WalkResult>;
767
+ declare function walk(node: AstNode$1, filter?: WalkerFilter | null, reverse?: boolean): Generator<WalkResult>;
682
768
  /**
683
769
  * walk ast node value tokens
684
770
  * @param values
685
771
  * @param root
686
772
  * @param filter
687
773
  * @param reverse
774
+ *
775
+ * Example:
776
+ *
777
+ * ```ts
778
+ *
779
+ * import {AstDeclaration, EnumToken, transform, walkValues} from '@tbela99/css-parser';
780
+ *
781
+ * const css = `
782
+ * body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
783
+ * `;
784
+ *
785
+ * const result = await transform(css);
786
+ * const declaration = result.ast.chi[0].chi[0] as AstDeclaration;
787
+ *
788
+ * // walk the node attribute's tokens in reverse order
789
+ * for (const {value} of walkValues(declaration.val, null, null,true)) {
790
+ *
791
+ * console.error([EnumToken[value.typ], value.val]);
792
+ * }
793
+ *
794
+ * // [ "Color", "color" ]
795
+ * // [ "FunctionTokenType", "calc" ]
796
+ * // [ "Number", 0.15 ]
797
+ * // [ "Add", undefined ]
798
+ * // [ "Iden", "b" ]
799
+ * // [ "Whitespace", undefined ]
800
+ * // [ "FunctionTokenType", "calc" ]
801
+ * // [ "Number", 0.24 ]
802
+ * // [ "Add", undefined ]
803
+ * // [ "Iden", "g" ]
804
+ * // [ "Whitespace", undefined ]
805
+ * // [ "Iden", "r" ]
806
+ * // [ "Whitespace", undefined ]
807
+ * // [ "Iden", "display-p3" ]
808
+ * // [ "Whitespace", undefined ]
809
+ * // [ "FunctionTokenType", "var" ]
810
+ * // [ "DashedIden", "--base-color" ]
811
+ * // [ "Whitespace", undefined ]
812
+ * // [ "Iden", "from" ]
813
+ * ```
688
814
  */
689
- declare function walkValues(values: Token[], root?: AstNode | Token | null, filter?: WalkerValueFilter | {
690
- event?: WalkerValueEvent;
815
+ declare function walkValues(values: Token$1[], root?: AstNode$1 | Token$1 | null, filter?: WalkerValueFilter | null | {
816
+ event?: WalkerEvent;
691
817
  fn?: WalkerValueFilter;
692
- type?: EnumToken | EnumToken[] | ((token: Token) => boolean);
818
+ type?: EnumToken | EnumToken[] | ((token: Token$1) => boolean);
693
819
  }, reverse?: boolean): Generator<WalkAttributesResult>;
694
820
 
695
821
  /**
@@ -698,7 +824,7 @@ declare function walkValues(values: Token[], root?: AstNode | Token | null, filt
698
824
  *
699
825
  * @private
700
826
  */
701
- declare function expand(ast: AstNode): AstNode;
827
+ declare function expand(ast: AstStyleSheet | AstAtRule | AstRule): AstNode$1;
702
828
 
703
829
  /**
704
830
  *
@@ -707,9 +833,9 @@ declare function expand(ast: AstNode): AstNode;
707
833
  *
708
834
  * @private
709
835
  */
710
- declare function renderToken(token: Token, options?: RenderOptions, cache?: {
836
+ declare function renderToken(token: Token$1, options?: RenderOptions, cache?: {
711
837
  [key: string]: any;
712
- }, reducer?: (acc: string, curr: Token) => string, errors?: ErrorDescription[]): string;
838
+ }, reducer?: (acc: string, curr: Token$1) => string, errors?: ErrorDescription[]): string;
713
839
 
714
840
  /**
715
841
  * Source map class
@@ -748,7 +874,7 @@ declare class SourceMap {
748
874
  * console.log(declarations);
749
875
  * ```
750
876
  */
751
- declare function parseDeclarations(declaration: string): Promise<AstDeclaration[]>;
877
+ declare function parseDeclarations(declaration: string): Promise<Array<AstDeclaration | AstComment>>;
752
878
  /**
753
879
  * parse css string and return an array of tokens
754
880
  * @param src
@@ -771,7 +897,7 @@ declare function parseDeclarations(declaration: string): Promise<AstDeclaration[
771
897
  */
772
898
  declare function parseString(src: string, options?: {
773
899
  location: boolean;
774
- }): Token[];
900
+ }): Token$1[];
775
901
  /**
776
902
  * parse function tokens in a token array
777
903
  * @param tokens
@@ -792,76 +918,114 @@ declare function parseString(src: string, options?: {
792
918
  *
793
919
  * @private
794
920
  */
795
- declare function parseTokens(tokens: Token[], options?: ParseTokenOptions): Token[];
921
+ declare function parseTokens(tokens: Token$1[], options?: ParseTokenOptions): Token$1[];
796
922
 
923
+ /**
924
+ * Literal token
925
+ */
797
926
  export declare interface LiteralToken extends BaseToken {
798
927
 
799
928
  typ: EnumToken.LiteralTokenType;
800
929
  val: string;
801
930
  }
802
931
 
932
+ /**
933
+ * Class selector token
934
+ */
803
935
  export declare interface ClassSelectorToken extends BaseToken {
804
936
 
805
937
  typ: EnumToken.ClassSelectorTokenType;
806
938
  val: string;
807
939
  }
808
940
 
941
+ /**
942
+ * Invalid class selector token
943
+ */
809
944
  export declare interface InvalidClassSelectorToken extends BaseToken {
810
945
 
811
946
  typ: EnumToken.InvalidClassSelectorTokenType;
812
947
  val: string;
813
948
  }
814
949
 
950
+ /**
951
+ * Universal selector token
952
+ */
815
953
  export declare interface UniversalSelectorToken extends BaseToken {
816
954
 
817
955
  typ: EnumToken.UniversalSelectorTokenType;
818
956
  }
819
957
 
820
-
958
+ /**
959
+ * Ident token
960
+ */
821
961
  export declare interface IdentToken extends BaseToken {
822
962
 
823
963
  typ: EnumToken.IdenTokenType,
824
964
  val: string;
825
965
  }
826
966
 
967
+ /**
968
+ * Ident list token
969
+ */
827
970
  export declare interface IdentListToken extends BaseToken {
828
971
 
829
972
  typ: EnumToken.IdenListTokenType,
830
973
  val: string;
831
974
  }
832
975
 
976
+ /**
977
+ * Dashed ident token
978
+ */
833
979
  export declare interface DashedIdentToken extends BaseToken {
834
980
 
835
981
  typ: EnumToken.DashedIdenTokenType,
836
982
  val: string;
837
983
  }
838
984
 
985
+ /**
986
+ * Comma token
987
+ */
839
988
  export declare interface CommaToken extends BaseToken {
840
989
 
841
990
  typ: EnumToken.CommaTokenType
842
991
  }
843
992
 
993
+ /**
994
+ * Colon token
995
+ */
844
996
  export declare interface ColonToken extends BaseToken {
845
997
 
846
998
  typ: EnumToken.ColonTokenType
847
999
  }
848
1000
 
1001
+ /**
1002
+ * Semicolon token
1003
+ */
849
1004
  export declare interface SemiColonToken extends BaseToken {
850
1005
 
851
1006
  typ: EnumToken.SemiColonTokenType
852
1007
  }
853
1008
 
1009
+ /**
1010
+ * Nesting selector token
1011
+ */
854
1012
  export declare interface NestingSelectorToken extends BaseToken {
855
1013
 
856
1014
  typ: EnumToken.NestingSelectorTokenType
857
1015
  }
858
1016
 
1017
+ /**
1018
+ * Number token
1019
+ */
859
1020
  export declare interface NumberToken extends BaseToken {
860
1021
 
861
1022
  typ: EnumToken.NumberTokenType,
862
1023
  val: number | FractionToken;
863
1024
  }
864
1025
 
1026
+ /**
1027
+ * At rule token
1028
+ */
865
1029
  export declare interface AtRuleToken extends BaseToken {
866
1030
 
867
1031
  typ: EnumToken.AtRuleTokenType,
@@ -869,32 +1033,47 @@ export declare interface AtRuleToken extends BaseToken {
869
1033
  pre: string;
870
1034
  }
871
1035
 
1036
+ /**
1037
+ * Percentage token
1038
+ */
872
1039
  export declare interface PercentageToken extends BaseToken {
873
1040
 
874
1041
  typ: EnumToken.PercentageTokenType,
875
1042
  val: number | FractionToken;
876
1043
  }
877
1044
 
1045
+ /**
1046
+ * Flex token
1047
+ */
878
1048
  export declare interface FlexToken extends BaseToken {
879
1049
 
880
1050
  typ: EnumToken.FlexTokenType,
881
1051
  val: number | FractionToken;
882
1052
  }
883
1053
 
1054
+ /**
1055
+ * Function token
1056
+ */
884
1057
  export declare interface FunctionToken extends BaseToken {
885
1058
 
886
1059
  typ: EnumToken.FunctionTokenType,
887
1060
  val: string;
888
- chi: Token[];
1061
+ chi: Token$1[];
889
1062
  }
890
1063
 
1064
+ /**
1065
+ * Grid template function token
1066
+ */
891
1067
  export declare interface GridTemplateFuncToken extends BaseToken {
892
1068
 
893
1069
  typ: EnumToken.GridTemplateFuncTokenType,
894
1070
  val: string;
895
- chi: Token[];
1071
+ chi: Token$1[];
896
1072
  }
897
1073
 
1074
+ /**
1075
+ * Function URL token
1076
+ */
898
1077
  export declare interface FunctionURLToken extends BaseToken {
899
1078
 
900
1079
  typ: EnumToken.UrlFunctionTokenType,
@@ -902,6 +1081,9 @@ export declare interface FunctionURLToken extends BaseToken {
902
1081
  chi: Array<UrlToken | CommentToken>;
903
1082
  }
904
1083
 
1084
+ /**
1085
+ * Function image token
1086
+ */
905
1087
  export declare interface FunctionImageToken extends BaseToken {
906
1088
 
907
1089
  typ: EnumToken.ImageFunctionTokenType,
@@ -909,38 +1091,56 @@ export declare interface FunctionImageToken extends BaseToken {
909
1091
  chi: Array<UrlToken | CommentToken>;
910
1092
  }
911
1093
 
1094
+ /**
1095
+ * Timing function token
1096
+ */
912
1097
  export declare interface TimingFunctionToken extends BaseToken {
913
1098
 
914
1099
  typ: EnumToken.TimingFunctionTokenType;
915
1100
  val: string;
916
- chi: Token[];
1101
+ chi: Token$1[];
917
1102
  }
918
1103
 
1104
+ /**
1105
+ * Timeline function token
1106
+ */
919
1107
  export declare interface TimelineFunctionToken extends BaseToken {
920
1108
 
921
1109
  typ: EnumToken.TimelineFunctionTokenType;
922
1110
  val: string;
923
- chi: Token[];
1111
+ chi: Token$1[];
924
1112
  }
925
1113
 
1114
+ /**
1115
+ * String token
1116
+ */
926
1117
  export declare interface StringToken extends BaseToken {
927
1118
 
928
1119
  typ: EnumToken.StringTokenType;
929
1120
  val: string;
930
1121
  }
931
1122
 
1123
+ /**
1124
+ * Bad string token
1125
+ */
932
1126
  export declare interface BadStringToken extends BaseToken {
933
1127
 
934
1128
  typ: EnumToken.BadStringTokenType;
935
1129
  val: string;
936
1130
  }
937
1131
 
1132
+ /**
1133
+ * Unclosed string token
1134
+ */
938
1135
  export declare interface UnclosedStringToken extends BaseToken {
939
1136
 
940
1137
  typ: EnumToken.UnclosedStringTokenType;
941
1138
  val: string;
942
1139
  }
943
1140
 
1141
+ /**
1142
+ * Dimension token
1143
+ */
944
1144
  export declare interface DimensionToken extends BaseToken {
945
1145
 
946
1146
  typ: EnumToken.DimensionTokenType;
@@ -948,6 +1148,9 @@ export declare interface DimensionToken extends BaseToken {
948
1148
  unit: string;
949
1149
  }
950
1150
 
1151
+ /**
1152
+ * Length token
1153
+ */
951
1154
  export declare interface LengthToken extends BaseToken {
952
1155
 
953
1156
  typ: EnumToken.LengthTokenType;
@@ -955,6 +1158,9 @@ export declare interface LengthToken extends BaseToken {
955
1158
  unit: string;
956
1159
  }
957
1160
 
1161
+ /**
1162
+ * Angle token
1163
+ */
958
1164
  export declare interface AngleToken extends BaseToken {
959
1165
 
960
1166
  typ: EnumToken.AngleTokenType;
@@ -962,6 +1168,9 @@ export declare interface AngleToken extends BaseToken {
962
1168
  unit: string;
963
1169
  }
964
1170
 
1171
+ /**
1172
+ * Time token
1173
+ */
965
1174
  export declare interface TimeToken extends BaseToken {
966
1175
 
967
1176
  typ: EnumToken.TimeTokenType;
@@ -969,6 +1178,9 @@ export declare interface TimeToken extends BaseToken {
969
1178
  unit: 'ms' | 's';
970
1179
  }
971
1180
 
1181
+ /**
1182
+ * Frequency token
1183
+ */
972
1184
  export declare interface FrequencyToken extends BaseToken {
973
1185
 
974
1186
  typ: EnumToken.FrequencyTokenType;
@@ -976,6 +1188,9 @@ export declare interface FrequencyToken extends BaseToken {
976
1188
  unit: 'Hz' | 'Khz';
977
1189
  }
978
1190
 
1191
+ /**
1192
+ * Resolution token
1193
+ */
979
1194
  export declare interface ResolutionToken extends BaseToken {
980
1195
 
981
1196
  typ: EnumToken.ResolutionTokenType;
@@ -983,289 +1198,442 @@ export declare interface ResolutionToken extends BaseToken {
983
1198
  unit: 'dpi' | 'dpcm' | 'dppx' | 'x';
984
1199
  }
985
1200
 
1201
+ /**
1202
+ * Hash token
1203
+ */
986
1204
  export declare interface HashToken extends BaseToken {
987
1205
 
988
1206
  typ: EnumToken.HashTokenType;
989
1207
  val: string;
990
1208
  }
991
1209
 
1210
+ /**
1211
+ * Block start token
1212
+ */
992
1213
  export declare interface BlockStartToken extends BaseToken {
993
1214
 
994
1215
  typ: EnumToken.BlockStartTokenType
995
1216
  }
996
1217
 
1218
+ /**
1219
+ * Block end token
1220
+ */
997
1221
  export declare interface BlockEndToken extends BaseToken {
998
1222
 
999
1223
  typ: EnumToken.BlockEndTokenType
1000
1224
  }
1001
1225
 
1226
+ /**
1227
+ * Attribute start token
1228
+ */
1002
1229
  export declare interface AttrStartToken extends BaseToken {
1003
1230
 
1004
1231
  typ: EnumToken.AttrStartTokenType;
1005
- chi?: Token[];
1232
+ chi?: Token$1[];
1006
1233
  }
1007
1234
 
1235
+ /**
1236
+ * Attribute end token
1237
+ */
1008
1238
  export declare interface AttrEndToken extends BaseToken {
1009
1239
 
1010
1240
  typ: EnumToken.AttrEndTokenType
1011
1241
  }
1012
1242
 
1243
+ /**
1244
+ * Parenthesis start token
1245
+ */
1013
1246
  export declare interface ParensStartToken extends BaseToken {
1014
1247
 
1015
1248
  typ: EnumToken.StartParensTokenType;
1016
1249
  }
1017
1250
 
1251
+ /**
1252
+ * Parenthesis end token
1253
+ */
1018
1254
  export declare interface ParensEndToken extends BaseToken {
1019
1255
 
1020
1256
  typ: EnumToken.EndParensTokenType
1021
1257
  }
1022
1258
 
1259
+ /**
1260
+ * Parenthesis token
1261
+ */
1023
1262
  export declare interface ParensToken extends BaseToken {
1024
1263
 
1025
1264
  typ: EnumToken.ParensTokenType;
1026
- chi: Token[];
1265
+ chi: Token$1[];
1027
1266
  }
1028
1267
 
1268
+ /**
1269
+ * Whitespace token
1270
+ */
1029
1271
  export declare interface WhitespaceToken extends BaseToken {
1030
1272
 
1031
1273
  typ: EnumToken.WhitespaceTokenType
1032
1274
  }
1033
1275
 
1276
+ /**
1277
+ * Comment token
1278
+ */
1034
1279
  export declare interface CommentToken extends BaseToken {
1035
1280
 
1036
1281
  typ: EnumToken.CommentTokenType;
1037
1282
  val: string;
1038
1283
  }
1039
1284
 
1285
+ /**
1286
+ * Bad comment token
1287
+ */
1040
1288
  export declare interface BadCommentToken extends BaseToken {
1041
1289
 
1042
1290
  typ: EnumToken.BadCommentTokenType;
1043
1291
  val: string;
1044
1292
  }
1045
1293
 
1294
+ /**
1295
+ * CDO comment token
1296
+ */
1046
1297
  export declare interface CDOCommentToken extends BaseToken {
1047
1298
 
1048
1299
  typ: EnumToken.CDOCOMMTokenType;
1049
1300
  val: string;
1050
1301
  }
1051
1302
 
1303
+ /**
1304
+ * Bad CDO comment token
1305
+ */
1052
1306
  export declare interface BadCDOCommentToken extends BaseToken {
1053
1307
 
1054
1308
  typ: EnumToken.BadCdoTokenType;
1055
1309
  val: string;
1056
1310
  }
1057
1311
 
1312
+ /**
1313
+ * Include match token
1314
+ */
1058
1315
  export declare interface IncludeMatchToken extends BaseToken {
1059
1316
 
1060
1317
  typ: EnumToken.IncludeMatchTokenType;
1061
1318
  // val: '~=';
1062
1319
  }
1063
1320
 
1321
+ /**
1322
+ * Dash match token
1323
+ */
1064
1324
  export declare interface DashMatchToken extends BaseToken {
1065
1325
 
1066
1326
  typ: EnumToken.DashMatchTokenType;
1067
1327
  // val: '|=';
1068
1328
  }
1069
1329
 
1330
+ /**
1331
+ * Equal match token
1332
+ */
1070
1333
  export declare interface EqualMatchToken extends BaseToken {
1071
1334
 
1072
1335
  typ: EnumToken.EqualMatchTokenType;
1073
1336
  // val: '|=';
1074
1337
  }
1075
1338
 
1339
+ /**
1340
+ * Start match token
1341
+ */
1076
1342
  export declare interface StartMatchToken extends BaseToken {
1077
1343
 
1078
1344
  typ: EnumToken.StartMatchTokenType;
1079
1345
  // val: '^=';
1080
1346
  }
1081
1347
 
1348
+ /**
1349
+ * End match token
1350
+ */
1082
1351
  export declare interface EndMatchToken extends BaseToken {
1083
1352
 
1084
1353
  typ: EnumToken.EndMatchTokenType;
1085
1354
  // val: '|=';
1086
1355
  }
1087
1356
 
1357
+ /**
1358
+ * Contain match token
1359
+ */
1088
1360
  export declare interface ContainMatchToken extends BaseToken {
1089
1361
 
1090
1362
  typ: EnumToken.ContainMatchTokenType;
1091
1363
  // val: '|=';
1092
1364
  }
1093
1365
 
1366
+ /**
1367
+ * Less than token
1368
+ */
1094
1369
  export declare interface LessThanToken extends BaseToken {
1095
1370
 
1096
1371
  typ: EnumToken.LtTokenType;
1097
1372
  }
1098
1373
 
1374
+ /**
1375
+ * Less than or equal token
1376
+ */
1099
1377
  export declare interface LessThanOrEqualToken extends BaseToken {
1100
1378
 
1101
1379
  typ: EnumToken.LteTokenType;
1102
1380
  }
1103
1381
 
1382
+ /**
1383
+ * Greater than token
1384
+ */
1104
1385
  export declare interface GreaterThanToken extends BaseToken {
1105
1386
 
1106
1387
  typ: EnumToken.GtTokenType;
1107
1388
  }
1108
1389
 
1390
+ /**
1391
+ * Greater than or equal token
1392
+ */
1109
1393
  export declare interface GreaterThanOrEqualToken extends BaseToken {
1110
1394
 
1111
1395
  typ: EnumToken.GteTokenType;
1112
1396
  }
1113
1397
 
1398
+ /**
1399
+ * Column combinator token
1400
+ */
1114
1401
  export declare interface ColumnCombinatorToken extends BaseToken {
1115
1402
 
1116
1403
  typ: EnumToken.ColumnCombinatorTokenType;
1117
1404
  }
1118
1405
 
1406
+ /**
1407
+ * Pseudo class token
1408
+ */
1119
1409
  export declare interface PseudoClassToken extends BaseToken {
1120
1410
 
1121
1411
  typ: EnumToken.PseudoClassTokenType;
1122
1412
  val: string;
1123
1413
  }
1124
1414
 
1415
+ /**
1416
+ * Pseudo element token
1417
+ */
1125
1418
  export declare interface PseudoElementToken extends BaseToken {
1126
1419
 
1127
1420
  typ: EnumToken.PseudoElementTokenType;
1128
1421
  val: string;
1129
1422
  }
1130
1423
 
1424
+ /**
1425
+ * Pseudo page token
1426
+ */
1131
1427
  export declare interface PseudoPageToken extends BaseToken {
1132
1428
 
1133
1429
  typ: EnumToken.PseudoPageTokenType;
1134
1430
  val: string;
1135
1431
  }
1136
1432
 
1433
+ /**
1434
+ * Pseudo class function token
1435
+ */
1137
1436
  export declare interface PseudoClassFunctionToken extends BaseToken {
1138
1437
 
1139
1438
  typ: EnumToken.PseudoClassFuncTokenType;
1140
1439
  val: string;
1141
- chi: Token[];
1440
+ chi: Token$1[];
1142
1441
  }
1143
1442
 
1443
+ /**
1444
+ * Delim token
1445
+ */
1144
1446
  export declare interface DelimToken extends BaseToken {
1145
1447
 
1146
1448
  typ: EnumToken.DelimTokenType;
1147
1449
  }
1148
1450
 
1451
+ /**
1452
+ * Bad URL token
1453
+ */
1149
1454
  export declare interface BadUrlToken extends BaseToken {
1150
1455
 
1151
1456
  typ: EnumToken.BadUrlTokenType,
1152
1457
  val: string;
1153
1458
  }
1154
1459
 
1460
+ /**
1461
+ * URL token
1462
+ */
1155
1463
  export declare interface UrlToken extends BaseToken {
1156
1464
 
1157
1465
  typ: EnumToken.UrlTokenTokenType,
1158
1466
  val: string;
1159
1467
  }
1160
1468
 
1469
+ /**
1470
+ * EOF token
1471
+ */
1161
1472
  export declare interface EOFToken extends BaseToken {
1162
1473
 
1163
1474
  typ: EnumToken.EOFTokenType;
1164
1475
  }
1165
1476
 
1477
+ /**
1478
+ * Important token
1479
+ */
1166
1480
  export declare interface ImportantToken extends BaseToken {
1167
1481
 
1168
1482
  typ: EnumToken.ImportantTokenType;
1169
1483
  }
1170
1484
 
1485
+ /**
1486
+ * Color token
1487
+ */
1171
1488
  export declare interface ColorToken extends BaseToken {
1172
1489
 
1173
1490
  typ: EnumToken.ColorTokenType;
1174
1491
  val: string;
1175
1492
  kin: ColorType;
1176
- chi?: Token[];
1493
+ chi?: Token$1[];
1177
1494
  /* calculated */
1178
1495
  cal?: 'rel' | 'mix';
1179
1496
  }
1180
1497
 
1498
+ /**
1499
+ * Attribute token
1500
+ */
1181
1501
  export declare interface AttrToken extends BaseToken {
1182
1502
 
1183
1503
  typ: EnumToken.AttrTokenType,
1184
- chi: Token[]
1504
+ chi: Token$1[]
1185
1505
  }
1186
1506
 
1507
+ /**
1508
+ * Invalid attribute token
1509
+ */
1187
1510
  export declare interface InvalidAttrToken extends BaseToken {
1188
1511
 
1189
1512
  typ: EnumToken.InvalidAttrTokenType,
1190
- chi: Token[]
1513
+ chi: Token$1[]
1191
1514
  }
1192
1515
 
1516
+ /**
1517
+ * Child combinator token
1518
+ */
1193
1519
  export declare interface ChildCombinatorToken extends BaseToken {
1194
1520
 
1195
1521
  typ: EnumToken.ChildCombinatorTokenType
1196
1522
  }
1197
1523
 
1524
+ /**
1525
+ * Media feature token
1526
+ */
1198
1527
  export declare interface MediaFeatureToken extends BaseToken {
1199
1528
 
1200
1529
  typ: EnumToken.MediaFeatureTokenType,
1201
1530
  val: string;
1202
1531
  }
1203
1532
 
1533
+ /**
1534
+ * Media feature not token
1535
+ */
1204
1536
  export declare interface MediaFeatureNotToken extends BaseToken {
1205
1537
 
1206
1538
  typ: EnumToken.MediaFeatureNotTokenType,
1207
- val: Token;
1539
+ val: Token$1;
1208
1540
  }
1209
1541
 
1542
+ /**
1543
+ * Media feature only token
1544
+ */
1210
1545
  export declare interface MediaFeatureOnlyToken extends BaseToken {
1211
1546
 
1212
1547
  typ: EnumToken.MediaFeatureOnlyTokenType,
1213
- val: Token;
1548
+ val: Token$1;
1214
1549
  }
1215
1550
 
1551
+ /**
1552
+ * Media feature and token
1553
+ */
1216
1554
  export declare interface MediaFeatureAndToken extends BaseToken {
1217
1555
 
1218
1556
  typ: EnumToken.MediaFeatureAndTokenType;
1219
1557
  }
1220
1558
 
1559
+ /**
1560
+ * Media feature or token
1561
+ */
1221
1562
  export declare interface MediaFeatureOrToken extends BaseToken {
1222
1563
 
1223
1564
  typ: EnumToken.MediaFeatureOrTokenType;
1224
1565
  }
1225
1566
 
1567
+ /**
1568
+ * Media query condition token
1569
+ */
1226
1570
  export declare interface MediaQueryConditionToken extends BaseToken {
1227
1571
 
1228
1572
  typ: EnumToken.MediaQueryConditionTokenType,
1229
- l: Token,
1573
+ l: Token$1,
1230
1574
  op: ColonToken | GreaterThanToken | LessThanToken | GreaterThanOrEqualToken | LessThanOrEqualToken,
1231
- r: Token[]
1575
+ r: Token$1[]
1232
1576
  }
1233
1577
 
1578
+ /**
1579
+ * Descendant combinator token
1580
+ */
1234
1581
  export declare interface DescendantCombinatorToken extends BaseToken {
1235
1582
 
1236
1583
  typ: EnumToken.DescendantCombinatorTokenType
1237
1584
  }
1238
1585
 
1586
+ /**
1587
+ * Next sibling combinator token
1588
+ */
1239
1589
  export declare interface NextSiblingCombinatorToken extends BaseToken {
1240
1590
 
1241
1591
  typ: EnumToken.NextSiblingCombinatorTokenType
1242
1592
  }
1243
1593
 
1594
+ /**
1595
+ * Subsequent sibling combinator token
1596
+ */
1244
1597
  export declare interface SubsequentCombinatorToken extends BaseToken {
1245
1598
 
1246
1599
  typ: EnumToken.SubsequentSiblingCombinatorTokenType
1247
1600
  }
1248
1601
 
1602
+ /**
1603
+ * Add token
1604
+ */
1249
1605
  export declare interface AddToken extends BaseToken {
1250
1606
 
1251
1607
  typ: EnumToken.Add;
1252
1608
  }
1253
1609
 
1610
+ /**
1611
+ * Sub token
1612
+ */
1254
1613
  export declare interface SubToken extends BaseToken {
1255
1614
 
1256
1615
  typ: EnumToken.Sub;
1257
1616
  }
1258
1617
 
1618
+ /**
1619
+ * Div token
1620
+ */
1259
1621
  export declare interface DivToken extends BaseToken {
1260
1622
 
1261
1623
  typ: EnumToken.Div;
1262
1624
  }
1263
1625
 
1626
+ /**
1627
+ * Mul token
1628
+ */
1264
1629
  export declare interface MulToken extends BaseToken {
1265
1630
 
1266
1631
  typ: EnumToken.Mul;
1267
1632
  }
1268
1633
 
1634
+ /**
1635
+ * Unary expression token
1636
+ */
1269
1637
  export declare interface UnaryExpression extends BaseToken {
1270
1638
 
1271
1639
  typ: EnumToken.UnaryExpressionTokenType
@@ -1273,6 +1641,9 @@ export declare interface UnaryExpression extends BaseToken {
1273
1641
  val: UnaryExpressionNode;
1274
1642
  }
1275
1643
 
1644
+ /**
1645
+ * Fraction token
1646
+ */
1276
1647
  export declare interface FractionToken extends BaseToken {
1277
1648
 
1278
1649
  typ: EnumToken.FractionTokenType;
@@ -1280,36 +1651,51 @@ export declare interface FractionToken extends BaseToken {
1280
1651
  r: NumberToken;
1281
1652
  }
1282
1653
 
1654
+ /**
1655
+ * Binary expression token
1656
+ */
1283
1657
  export declare interface BinaryExpressionToken extends BaseToken {
1284
1658
 
1285
1659
  typ: EnumToken.BinaryExpressionTokenType
1286
1660
  op: EnumToken.Add | EnumToken.Sub | EnumToken.Div | EnumToken.Mul;
1287
- l: BinaryExpressionNode | Token;
1288
- r: BinaryExpressionNode | Token;
1661
+ l: BinaryExpressionNode | Token$1;
1662
+ r: BinaryExpressionNode | Token$1;
1289
1663
  }
1290
1664
 
1665
+ /**
1666
+ * Match expression token
1667
+ */
1291
1668
  export declare interface MatchExpressionToken extends BaseToken {
1292
1669
 
1293
1670
  typ: EnumToken.MatchExpressionTokenType
1294
1671
  op: EqualMatchToken | DashMatchToken | StartMatchToken | ContainMatchToken | EndMatchToken | IncludeMatchToken;
1295
- l: Token;
1296
- r: Token;
1672
+ l: Token$1;
1673
+ r: Token$1;
1297
1674
  attr?: 'i' | 's';
1298
1675
  }
1299
1676
 
1677
+ /**
1678
+ * Name space attribute token
1679
+ */
1300
1680
  export declare interface NameSpaceAttributeToken extends BaseToken {
1301
1681
 
1302
1682
  typ: EnumToken.NameSpaceAttributeTokenType
1303
- l?: Token;
1304
- r: Token;
1683
+ l?: Token$1;
1684
+ r: Token$1;
1305
1685
  }
1306
1686
 
1687
+ /**
1688
+ * List token
1689
+ */
1307
1690
  export declare interface ListToken extends BaseToken {
1308
1691
 
1309
1692
  typ: EnumToken.ListToken
1310
- chi: Token[];
1693
+ chi: Token$1[];
1311
1694
  }
1312
1695
 
1696
+ /**
1697
+ * Unary expression node
1698
+ */
1313
1699
  export declare type UnaryExpressionNode =
1314
1700
  BinaryExpressionNode
1315
1701
  | NumberToken
@@ -1319,10 +1705,16 @@ export declare type UnaryExpressionNode =
1319
1705
  | AngleToken
1320
1706
  | FrequencyToken;
1321
1707
 
1708
+ /**
1709
+ * Binary expression node
1710
+ */
1322
1711
  export declare type BinaryExpressionNode = NumberToken | DimensionToken | PercentageToken | FlexToken | FractionToken |
1323
1712
  AngleToken | LengthToken | FrequencyToken | BinaryExpressionToken | FunctionToken | ParensToken;
1324
1713
 
1325
- export declare type Token =
1714
+ /**
1715
+ * Token
1716
+ */
1717
+ export declare type Token$1 =
1326
1718
  InvalidClassSelectorToken
1327
1719
  | InvalidAttrToken
1328
1720
  |
@@ -1472,12 +1864,16 @@ declare const enum ValidationSyntaxGroupEnum {
1472
1864
  Selectors = "selectors",
1473
1865
  AtRules = "atRules"
1474
1866
  }
1867
+
1475
1868
  interface Position$1 {
1869
+
1476
1870
  ind: number;
1477
1871
  lin: number;
1478
1872
  col: number;
1479
1873
  }
1480
- interface ValidationToken {
1874
+
1875
+ interface ValidationToken$1 {
1876
+
1481
1877
  typ: ValidationTokenEnum;
1482
1878
  pos: Position$1;
1483
1879
  isList?: boolean;
@@ -1489,13 +1885,13 @@ interface ValidationToken {
1489
1885
  occurence?: {
1490
1886
  min: number;
1491
1887
  max: number | null;
1492
- };
1888
+ }
1493
1889
  }
1494
1890
 
1495
1891
  export declare interface ValidationSyntaxNode {
1496
1892
 
1497
1893
  syntax: string;
1498
- ast?: ValidationToken[];
1894
+ ast?: ValidationToken$1[];
1499
1895
  }
1500
1896
 
1501
1897
  interface ValidationSelectorOptions extends ValidationOptions {
@@ -1517,16 +1913,16 @@ export declare interface ValidationConfiguration {
1517
1913
  interface ValidationResult {
1518
1914
 
1519
1915
  valid: SyntaxValidationResult;
1520
- node: AstNode | Token | null;
1521
- syntax: ValidationToken | string | null;
1916
+ node: AstNode$1 | Token$1 | null;
1917
+ syntax: ValidationToken$1 | string | null;
1522
1918
  error: string;
1523
1919
  cycle?: boolean;
1524
1920
  }
1525
1921
 
1526
1922
  interface ValidationSyntaxResult extends ValidationResult {
1527
1923
 
1528
- syntax: ValidationToken | string | null;
1529
- context: Context<Token> | Token[];
1924
+ syntax: ValidationToken$1 | string | null;
1925
+ context: Context<Token$1> | Token$1[];
1530
1926
  }
1531
1927
 
1532
1928
  interface Context<Type> {
@@ -1565,6 +1961,8 @@ interface Context<Type> {
1565
1961
  * @param token
1566
1962
  * @param to
1567
1963
  *
1964
+ * @private
1965
+ *
1568
1966
  * <code>
1569
1967
  *
1570
1968
  * const token = {typ: EnumToken.ColorTokenType, kin: ColorType.HEX, val: '#F00'}
@@ -1632,67 +2030,115 @@ export declare interface Location {
1632
2030
 
1633
2031
  export declare interface BaseToken {
1634
2032
 
2033
+ /**
2034
+ * token type
2035
+ */
1635
2036
  typ: EnumToken;
2037
+ /**
2038
+ * location info
2039
+ */
1636
2040
  loc?: Location;
1637
- tokens?: Token[];
1638
- parent?: AstRuleList;
2041
+ /**
2042
+ * prelude or selector tokens
2043
+ */
2044
+ tokens?: Token$1[] | null;
2045
+ /**
2046
+ * parent node
2047
+ */
2048
+ parent?: AstAtRule | astRule | AstKeyframesAtRule | AstKeyFrameRule | AstInvalidRule | AstInvalidAtRule | null;
2049
+ /**
2050
+ * @private
2051
+ */
1639
2052
  validSyntax?: boolean;
1640
2053
  }
1641
2054
 
2055
+ /**
2056
+ * comment node
2057
+ */
1642
2058
  export declare interface AstComment extends BaseToken {
1643
2059
 
1644
2060
  typ: EnumToken.CommentNodeType | EnumToken.CDOCOMMNodeType,
2061
+ tokens?: null;
1645
2062
  val: string;
1646
2063
  }
1647
2064
 
2065
+ /**
2066
+ * declaration node
2067
+ */
1648
2068
  export declare interface AstDeclaration extends BaseToken {
1649
2069
 
1650
2070
  nam: string,
1651
- val: Token[];
2071
+ tokens?: null;
2072
+ val: Token$1[];
1652
2073
  typ: EnumToken.DeclarationNodeType
1653
2074
  }
1654
2075
 
2076
+ /**
2077
+ * rule node
2078
+ */
1655
2079
  export declare interface AstRule extends BaseToken {
1656
2080
 
1657
2081
  typ: EnumToken.RuleNodeType;
1658
2082
  sel: string;
1659
- chi: Array<AstDeclaration | AstComment | AstRuleList>;
2083
+ chi: Array<AstDeclaration | AstComment | AstRule | AstAtRule | AstInvalidRule | AstInvalidDeclaration | AstInvalidAtRule>;
1660
2084
  optimized?: OptimizedSelector | null;
1661
2085
  raw?: RawSelectorTokens | null;
1662
2086
  }
1663
2087
 
2088
+ /**
2089
+ * invalid rule node
2090
+ */
1664
2091
  export declare interface AstInvalidRule extends BaseToken {
1665
2092
 
1666
2093
  typ: EnumToken.InvalidRuleTokenType;
1667
2094
  sel: string;
1668
- chi: Array<AstNode>;
2095
+ chi: Array<AstNode$1>;
1669
2096
  }
1670
2097
 
2098
+ /**
2099
+ * invalid declaration node
2100
+ */
1671
2101
  export declare interface AstInvalidDeclaration extends BaseToken {
1672
2102
 
1673
2103
  typ: EnumToken.InvalidDeclarationNodeType;
1674
- val: Array<AstNode>;
2104
+ tokens?: null;
2105
+ val: Array<Token$1>;
1675
2106
  }
1676
2107
 
2108
+ /**
2109
+ * invalid at rule node
2110
+ */
1677
2111
  export declare interface AstInvalidAtRule extends BaseToken {
1678
2112
 
1679
2113
  typ: EnumToken.InvalidAtRuleTokenType;
2114
+ nam: string;
1680
2115
  val: string;
1681
- chi?: Array<AstNode>;
2116
+ chi?: Array<AstNode$1>;
1682
2117
  }
1683
2118
 
2119
+ /**
2120
+ * keyframe rule node
2121
+ */
1684
2122
  export declare interface AstKeyFrameRule extends BaseToken {
1685
2123
 
1686
- typ: EnumToken.KeyFrameRuleNodeType;
2124
+ typ: EnumToken.KeyFramesRuleNodeType;
1687
2125
  sel: string;
1688
- chi: Array<AstDeclaration | AstComment>;
2126
+ chi: Array<AstDeclaration | AstComment | AstInvalidDeclaration>;
1689
2127
  optimized?: OptimizedSelector;
1690
2128
  raw?: RawSelectorTokens;
1691
- tokens?: Token[]
2129
+ tokens?: Token$1[]
1692
2130
  }
1693
2131
 
1694
- export declare type RawSelectorTokens = string[][];
2132
+ /**
2133
+ * raw selector tokens
2134
+ */
2135
+ export declare type RawSelectorTokens = string[][];
1695
2136
 
2137
+ /**
2138
+ * optimized selector
2139
+ *
2140
+ * @private
2141
+ */
1696
2142
  export declare interface OptimizedSelector {
1697
2143
  match: boolean;
1698
2144
  optimized: string[];
@@ -1700,13 +2146,21 @@ export declare interface OptimizedSelector {
1700
2146
  reducible: boolean;
1701
2147
  }
1702
2148
 
2149
+ /**
2150
+ * optimized selector token
2151
+ *
2152
+ * @private
2153
+ */
1703
2154
  export declare interface OptimizedSelectorToken {
1704
2155
  match: boolean;
1705
- optimized: Token[];
1706
- selector: Token[][],
2156
+ optimized: Token$1[];
2157
+ selector: Token$1[][],
1707
2158
  reducible: boolean;
1708
2159
  }
1709
2160
 
2161
+ /**
2162
+ * at rule node
2163
+ */
1710
2164
  export declare interface AstAtRule extends BaseToken {
1711
2165
 
1712
2166
  typ: EnumToken.AtRuleNodeType,
@@ -1715,59 +2169,88 @@ export declare interface AstAtRule extends BaseToken {
1715
2169
  chi?: Array<AstDeclaration | AstInvalidDeclaration | AstComment> | Array<AstRule | AstComment>
1716
2170
  }
1717
2171
 
1718
- export declare interface AstKeyframeRule extends BaseToken {
2172
+ /**
2173
+ * keyframe rule node
2174
+ */
2175
+ export declare interface AstKeyframesRule extends BaseToken {
1719
2176
 
1720
- typ: EnumToken.KeyFrameRuleNodeType;
2177
+ typ: EnumToken.KeyFramesRuleNodeType;
1721
2178
  sel: string;
1722
2179
  chi: Array<AstDeclaration | AstInvalidDeclaration | AstComment | AstRuleList>;
1723
2180
  optimized?: OptimizedSelector;
1724
2181
  raw?: RawSelectorTokens;
1725
2182
  }
1726
2183
 
1727
- export declare interface AstKeyframAtRule extends BaseToken {
2184
+ /**
2185
+ * keyframe at rule node
2186
+ */
2187
+ export declare interface AstKeyframesAtRule extends BaseToken {
1728
2188
 
1729
- typ: EnumToken.KeyframeAtRuleNodeType,
2189
+ typ: EnumToken.KeyframesAtRuleNodeType,
1730
2190
  nam: string;
1731
2191
  val: string;
1732
- chi: Array<AstKeyframeRule | AstComment>;
2192
+ chi: Array<AstKeyframesRule | AstComment>;
1733
2193
  }
1734
2194
 
1735
- export declare interface AstRuleList extends BaseToken {
1736
-
1737
- typ: EnumToken.StyleSheetNodeType | EnumToken.RuleNodeType | EnumToken.AtRuleNodeType | EnumToken.KeyframeAtRuleNodeType | EnumToken.KeyFrameRuleNodeType | EnumToken.InvalidRuleTokenType | EnumToken.InvalidAtRuleTokenType,
1738
- chi: Array<BaseToken | AstComment>;
1739
- }
2195
+ /**
2196
+ * rule list node
2197
+ */
2198
+ export declare type AstRuleList =
2199
+ AstStyleSheet
2200
+ | AstAtRule
2201
+ | AstRule
2202
+ | AstKeyframesAtRule
2203
+ | AstKeyFrameRule
2204
+ | AstInvalidRule;
1740
2205
 
1741
- export declare interface AstRuleStyleSheet extends AstRuleList {
2206
+ /**
2207
+ * stylesheet node
2208
+ */
2209
+ export declare interface AstStyleSheet extends BaseToken {
1742
2210
  typ: EnumToken.StyleSheetNodeType,
1743
- chi: Array<AstRuleList | AstComment>
2211
+ chi: Array<AstRule | AstAtRule | astKeyframesAtRule | AstComment | AstInvalidAtRule | AstInvalidRule>;
2212
+ tokens?: null;
1744
2213
  }
1745
2214
 
1746
- export declare type AstNode =
1747
- AstRuleStyleSheet
2215
+ /**
2216
+ * ast node
2217
+ */
2218
+ export declare type AstNode$1 =
2219
+ AstStyleSheet
1748
2220
  | AstRuleList
1749
2221
  | AstComment
1750
2222
  | AstAtRule
1751
2223
  | AstRule
1752
2224
  | AstDeclaration
1753
- | AstKeyframAtRule
2225
+ | AstKeyframesAtRule
1754
2226
  | AstKeyFrameRule
1755
2227
  | AstInvalidRule
2228
+ | AstInvalidAtRule
1756
2229
  | AstInvalidDeclaration;
1757
2230
 
2231
+ export declare type GenericVisitorResult<T> = T | T[] | Promise<T> | Promise<T[]> | null | Promise<null>;
2232
+ export declare type GenericVisitorHandler<T> = ((node: T, parent?: AstNode | Token, root?: AstNode | Token) => GenericVisitorResult<T>);
2233
+ export declare type GenericVisitorAstNodeHandlerMap<T> =
2234
+ Record<string, GenericVisitorHandler<T>>
2235
+ | GenericVisitorHandler<T>
2236
+ | { type: WalkerEvent, handler: GenericVisitorHandler<T> }
2237
+ | { type: WalkerEvent, handler: Record<string, GenericVisitorHandler<T>> };
2238
+
2239
+ export declare type ValueVisitorHandler = GenericVisitorHandler<Token>;
2240
+
1758
2241
  /**
1759
2242
  * Declaration visitor handler
1760
2243
  */
1761
- export declare type DeclarationVisitorHandler = (node: AstDeclaration) => (AstDeclaration | AstDeclaration[] | null | Promise<AstDeclaration> | Promise<AstDeclaration[]> | Promise<null>);
2244
+ export declare type DeclarationVisitorHandler = GenericVisitorHandler<AstDeclaration>;
1762
2245
  /**
1763
2246
  * Rule visitor handler
1764
2247
  */
1765
- export declare type RuleVisitorHandler = (node: AstRule) => (AstRule | AstRule[] | null | Promise<AstRule> | Promise<AstRule[]> | Promise<null>);
2248
+ export declare type RuleVisitorHandler = GenericVisitorHandler<AstRule>;
1766
2249
 
1767
2250
  /**
1768
2251
  * AtRule visitor handler
1769
2252
  */
1770
- export declare type AtRuleVisitorHandler = (node: AstAtRule) => (AstAtRule | AstAtRule[] | null | Promise<AstAtRule> | Promise<AstAtRule[]> | Promise<null>);
2253
+ export declare type AtRuleVisitorHandler = GenericVisitorHandler<AstAtRule>;
1771
2254
 
1772
2255
  /**
1773
2256
  * node visitor callback map
@@ -1817,7 +2300,7 @@ export declare interface VisitorNodeMap {
1817
2300
  * // @media tv,screen{.foo{height:calc(40px/3)}}
1818
2301
  * ```
1819
2302
  */
1820
- AtRule?: Record<string, AtRuleVisitorHandler> | AtRuleVisitorHandler;
2303
+ AtRule?: GenericVisitorAstNodeHandlerMap<AstAtRule>;
1821
2304
  /**
1822
2305
  * declaration visitor
1823
2306
  *
@@ -1919,7 +2402,7 @@ export declare interface VisitorNodeMap {
1919
2402
  * // .foo{width:calc(40px/3);padding:10px}.selector{padding:20px}
1920
2403
  * ```
1921
2404
  */
1922
- Declaration?: Record<string, DeclarationVisitorHandler> | DeclarationVisitorHandler;
2405
+ Declaration?: GenericVisitorAstNodeHandlerMap<AstDeclaration>;
1923
2406
 
1924
2407
  /**
1925
2408
  * rule visitor
@@ -1961,35 +2444,110 @@ export declare interface VisitorNodeMap {
1961
2444
  * // .foo{width:3px;.foo{width:3px}}
1962
2445
  * ```
1963
2446
  */
1964
- Rule?: RuleVisitorHandler;
2447
+ Rule?: GenericVisitorAstNodeHandlerMap<AstRule>;
2448
+
2449
+ KeyframesRule?: GenericVisitorAstNodeHandlerMap<AstKeyframesRule>;
2450
+
2451
+ KeyframesAtRule?: GenericVisitorAstNodeHandlerMap<AstKeyframesAtRule>;
2452
+
2453
+ /**
2454
+ * value visitor
2455
+ */
2456
+ Value?: GenericVisitorAstNodeHandlerMap<Token>;
2457
+
2458
+ /**
2459
+ * generic token visitor. the key name is of type keyof EnumToken.
2460
+ * generic tokens are called for every token of the specified type.
2461
+ *
2462
+ * ```ts
2463
+ *
2464
+ * import {transform, parse, parseDeclarations} from "@tbela99/css-parser";
2465
+ *
2466
+ * const options: ParserOptions = {
2467
+ *
2468
+ * inlineCssVariables: true,
2469
+ * visitor: {
2470
+ *
2471
+ * // Stylesheet node visitor
2472
+ * StyleSheetNodeType: async (node) => {
2473
+ *
2474
+ * // insert a new rule
2475
+ * node.chi.unshift(await parse('html {--base-color: pink}').then(result => result.ast.chi[0]))
2476
+ * },
2477
+ * ColorTokenType: (node) => {
2478
+ *
2479
+ * // dump all color tokens
2480
+ * // console.debug(node);
2481
+ * },
2482
+ * FunctionTokenType: (node) => {
2483
+ *
2484
+ * // dump all function tokens
2485
+ * // console.debug(node);
2486
+ * },
2487
+ * DeclarationNodeType: (node) => {
2488
+ *
2489
+ * // dump all declaration nodes
2490
+ * // console.debug(node);
2491
+ * }
2492
+ * }
2493
+ * };
2494
+ *
2495
+ * const css = `
2496
+ *
2497
+ * body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
2498
+ * `;
2499
+ *
2500
+ * console.debug(await transform(css, options));
2501
+ *
2502
+ * // body {color:#f3fff0}
2503
+ * ```
2504
+ */
2505
+ [key: keyof typeof EnumToken]: GenericVisitorAstNodeHandlerMap<Token> | GenericVisitorAstNodeHandlerMap<AstNode>;
1965
2506
  }
1966
2507
 
1967
2508
  export declare interface PropertyListOptions {
1968
2509
 
1969
- removeDuplicateDeclarations?: boolean;
2510
+ removeDuplicateDeclarations?: boolean | string | string[];
1970
2511
  computeShorthand?: boolean;
1971
2512
  }
1972
2513
 
2514
+ /**
2515
+ * parse info
2516
+ */
1973
2517
  export declare interface ParseInfo {
1974
2518
 
2519
+ /**
2520
+ * read buffer
2521
+ */
1975
2522
  buffer: string;
2523
+ /**
2524
+ * stream
2525
+ */
1976
2526
  stream: string;
2527
+ /**
2528
+ * last token position
2529
+ */
1977
2530
  position: Position;
2531
+ /**
2532
+ * current parsing position
2533
+ */
1978
2534
  currentPosition: Position;
1979
2535
  }
1980
2536
 
1981
2537
  /**
1982
2538
  * feature walk mode
2539
+ *
2540
+ * @internal
1983
2541
  */
1984
2542
  declare enum FeatureWalkMode {
1985
2543
  /**
1986
2544
  * pre process
1987
2545
  */
1988
- Pre = 0,
2546
+ Pre = 1,
1989
2547
  /**
1990
2548
  * post process
1991
2549
  */
1992
- Post = 1
2550
+ Post = 2
1993
2551
  }
1994
2552
 
1995
2553
  /**
@@ -2100,11 +2658,17 @@ interface ShorthandType {
2100
2658
 
2101
2659
  // generated from config.json at https://app.quicktype.io/?l=ts
2102
2660
 
2661
+ /**
2662
+ * @private
2663
+ */
2103
2664
  export declare interface PropertiesConfig {
2104
2665
  properties: PropertiesConfigProperties;
2105
2666
  map: Map$1;
2106
2667
  }
2107
2668
 
2669
+ /**
2670
+ * @private
2671
+ */
2108
2672
  interface Map$1 {
2109
2673
  border: Border;
2110
2674
  "border-color": BackgroundPositionClass;
@@ -2133,6 +2697,9 @@ interface Map$1 {
2133
2697
  "background-size": BackgroundPositionClass;
2134
2698
  }
2135
2699
 
2700
+ /**
2701
+ * @private
2702
+ */
2136
2703
  interface Background {
2137
2704
  shorthand: string;
2138
2705
  pattern: string;
@@ -2143,6 +2710,9 @@ interface Background {
2143
2710
  properties: BackgroundProperties;
2144
2711
  }
2145
2712
 
2713
+ /**
2714
+ * @private
2715
+ */
2146
2716
  interface BackgroundProperties {
2147
2717
  "background-repeat": BackgroundRepeat;
2148
2718
  "background-color": PurpleBackgroundAttachment;
@@ -2154,6 +2724,9 @@ interface BackgroundProperties {
2154
2724
  "background-size": BackgroundSize;
2155
2725
  }
2156
2726
 
2727
+ /**
2728
+ * @private
2729
+ */
2157
2730
  interface PurpleBackgroundAttachment {
2158
2731
  types: string[];
2159
2732
  default: string[];
@@ -2162,6 +2735,9 @@ interface PurpleBackgroundAttachment {
2162
2735
  mapping?: BackgroundAttachmentMapping;
2163
2736
  }
2164
2737
 
2738
+ /**
2739
+ * @private
2740
+ */
2165
2741
  interface BackgroundAttachmentMapping {
2166
2742
  "ultra-condensed": string;
2167
2743
  "extra-condensed": string;
@@ -2174,6 +2750,9 @@ interface BackgroundAttachmentMapping {
2174
2750
  "ultra-expanded": string;
2175
2751
  }
2176
2752
 
2753
+ /**
2754
+ * @private
2755
+ */
2177
2756
  interface BackgroundPosition {
2178
2757
  multiple: boolean;
2179
2758
  types: string[];
@@ -2183,14 +2762,23 @@ interface BackgroundPosition {
2183
2762
  constraints: BackgroundPositionConstraints;
2184
2763
  }
2185
2764
 
2765
+ /**
2766
+ * @private
2767
+ */
2186
2768
  interface BackgroundPositionConstraints {
2187
2769
  mapping: ConstraintsMapping;
2188
2770
  }
2189
2771
 
2772
+ /**
2773
+ * @private
2774
+ */
2190
2775
  interface ConstraintsMapping {
2191
2776
  max: number;
2192
2777
  }
2193
2778
 
2779
+ /**
2780
+ * @private
2781
+ */
2194
2782
  interface BackgroundPositionMapping {
2195
2783
  left: string;
2196
2784
  top: string;
@@ -2199,6 +2787,9 @@ interface BackgroundPositionMapping {
2199
2787
  right: string;
2200
2788
  }
2201
2789
 
2790
+ /**
2791
+ * @private
2792
+ */
2202
2793
  interface BackgroundRepeat {
2203
2794
  types: any[];
2204
2795
  default: string[];
@@ -2207,6 +2798,9 @@ interface BackgroundRepeat {
2207
2798
  mapping: BackgroundRepeatMapping;
2208
2799
  }
2209
2800
 
2801
+ /**
2802
+ * @private
2803
+ */
2210
2804
  interface BackgroundRepeatMapping {
2211
2805
  "repeat no-repeat": string;
2212
2806
  "no-repeat repeat": string;
@@ -2216,6 +2810,9 @@ interface BackgroundRepeatMapping {
2216
2810
  "no-repeat no-repeat": string;
2217
2811
  }
2218
2812
 
2813
+ /**
2814
+ * @private
2815
+ */
2219
2816
  interface BackgroundSize {
2220
2817
  multiple: boolean;
2221
2818
  previous: string;
@@ -2226,23 +2823,38 @@ interface BackgroundSize {
2226
2823
  mapping: BackgroundSizeMapping;
2227
2824
  }
2228
2825
 
2826
+ /**
2827
+ * @private
2828
+ */
2229
2829
  interface BackgroundSizeMapping {
2230
2830
  "auto auto": string;
2231
2831
  }
2232
2832
 
2833
+ /**
2834
+ * @private
2835
+ */
2233
2836
  interface Prefix {
2234
2837
  typ: string;
2235
2838
  val: string;
2236
2839
  }
2237
2840
 
2841
+ /**
2842
+ * @private
2843
+ */
2238
2844
  interface Separator {
2239
2845
  typ: string;
2240
2846
  }
2241
2847
 
2848
+ /**
2849
+ * @private
2850
+ */
2242
2851
  interface BackgroundPositionClass {
2243
2852
  shorthand: string;
2244
2853
  }
2245
2854
 
2855
+ /**
2856
+ * @private
2857
+ */
2246
2858
  interface Border {
2247
2859
  shorthand: string;
2248
2860
  pattern: string;
@@ -2251,15 +2863,24 @@ interface Border {
2251
2863
  properties: BorderProperties;
2252
2864
  }
2253
2865
 
2866
+ /**
2867
+ * @private
2868
+ */
2254
2869
  interface BorderProperties {
2255
2870
  "border-color": BorderColorClass;
2256
2871
  "border-style": BorderColorClass;
2257
2872
  "border-width": BorderColorClass;
2258
2873
  }
2259
2874
 
2875
+ /**
2876
+ * @private
2877
+ */
2260
2878
  interface BorderColorClass {
2261
2879
  }
2262
2880
 
2881
+ /**
2882
+ * @private
2883
+ */
2263
2884
  interface Font {
2264
2885
  shorthand: string;
2265
2886
  pattern: string;
@@ -2268,6 +2889,9 @@ interface Font {
2268
2889
  properties: FontProperties;
2269
2890
  }
2270
2891
 
2892
+ /**
2893
+ * @private
2894
+ */
2271
2895
  interface FontProperties {
2272
2896
  "font-weight": FontWeight;
2273
2897
  "font-style": PurpleBackgroundAttachment;
@@ -2278,6 +2902,9 @@ interface FontProperties {
2278
2902
  "font-family": FontFamily;
2279
2903
  }
2280
2904
 
2905
+ /**
2906
+ * @private
2907
+ */
2281
2908
  interface FontFamily {
2282
2909
  types: string[];
2283
2910
  default: any[];
@@ -2287,6 +2914,9 @@ interface FontFamily {
2287
2914
  separator: Separator;
2288
2915
  }
2289
2916
 
2917
+ /**
2918
+ * @private
2919
+ */
2290
2920
  interface FontWeight {
2291
2921
  types: string[];
2292
2922
  default: string[];
@@ -2295,15 +2925,24 @@ interface FontWeight {
2295
2925
  mapping: FontWeightMapping;
2296
2926
  }
2297
2927
 
2928
+ /**
2929
+ * @private
2930
+ */
2298
2931
  interface FontWeightConstraints {
2299
2932
  value: Value;
2300
2933
  }
2301
2934
 
2935
+ /**
2936
+ * @private
2937
+ */
2302
2938
  interface Value {
2303
2939
  min: string;
2304
2940
  max: string;
2305
2941
  }
2306
2942
 
2943
+ /**
2944
+ * @private
2945
+ */
2307
2946
  interface FontWeightMapping {
2308
2947
  thin: string;
2309
2948
  hairline: string;
@@ -2324,6 +2963,9 @@ interface FontWeightMapping {
2324
2963
  "ultra black": string;
2325
2964
  }
2326
2965
 
2966
+ /**
2967
+ * @private
2968
+ */
2327
2969
  interface LineHeight {
2328
2970
  types: string[];
2329
2971
  default: string[];
@@ -2332,6 +2974,9 @@ interface LineHeight {
2332
2974
  prefix: Prefix;
2333
2975
  }
2334
2976
 
2977
+ /**
2978
+ * @private
2979
+ */
2335
2980
  interface Outline {
2336
2981
  shorthand: string;
2337
2982
  pattern: string;
@@ -2340,12 +2985,18 @@ interface Outline {
2340
2985
  properties: OutlineProperties;
2341
2986
  }
2342
2987
 
2988
+ /**
2989
+ * @private
2990
+ */
2343
2991
  interface OutlineProperties {
2344
2992
  "outline-color": PurpleBackgroundAttachment;
2345
2993
  "outline-style": PurpleBackgroundAttachment;
2346
2994
  "outline-width": PurpleBackgroundAttachment;
2347
2995
  }
2348
2996
 
2997
+ /**
2998
+ * @private
2999
+ */
2349
3000
  interface PropertiesConfigProperties {
2350
3001
  inset: BorderRadius;
2351
3002
  top: BackgroundPositionClass;
@@ -2384,6 +3035,9 @@ interface PropertiesConfigProperties {
2384
3035
  "border-left-color": BackgroundPositionClass;
2385
3036
  }
2386
3037
 
3038
+ /**
3039
+ * @private
3040
+ */
2387
3041
  interface BorderColor {
2388
3042
  shorthand: string;
2389
3043
  map?: string;
@@ -2392,6 +3046,9 @@ interface BorderColor {
2392
3046
  keywords: string[];
2393
3047
  }
2394
3048
 
3049
+ /**
3050
+ * @private
3051
+ */
2395
3052
  interface BorderRadius {
2396
3053
  shorthand: string;
2397
3054
  properties: string[];
@@ -2401,38 +3058,38 @@ interface BorderRadius {
2401
3058
  keywords: string[];
2402
3059
  }
2403
3060
 
2404
- export declare type WalkerOption = WalkerOptionEnum | Token | null;
3061
+ /**
3062
+ * node walker option
3063
+ */
3064
+ export declare type WalkerOption = WalkerOptionEnum | AstNode$1 | Token$1 | null;
2405
3065
  /**
2406
3066
  * returned value:
2407
- * - WalkerOptionEnum.Ignore: ignore this node and its children
2408
- * - WalkerOptionEnum.Stop: stop walking the tree
2409
- * - WalkerOptionEnum.Children: walk the children and ignore the node itself
2410
- * - WalkerOptionEnum.IgnoreChildren: walk the node and ignore children
3067
+ * - {@link WalkerOptionEnum.Ignore}: ignore this node and its children
3068
+ * - {@link WalkerOptionEnum.Stop}: stop walking the tree
3069
+ * - {@link WalkerOptionEnum.Children}: walk the children and ignore the current node
3070
+ * - {@link WalkerOptionEnum.IgnoreChildren}: walk the node and ignore children
3071
+ * - {@link AstNode}:
3072
+ * - {@link Token}:
2411
3073
  */
2412
- export declare type WalkerFilter = (node: AstNode) => WalkerOption;
3074
+ export declare type WalkerFilter = (node: AstNode$1) => WalkerOption;
2413
3075
 
2414
3076
  /**
2415
- * returned value:
2416
- * - 'ignore': ignore this node and its children
2417
- * - 'stop': stop walking the tree
2418
- * - 'children': walk the children and ignore the node itself
2419
- * - 'ignore-children': walk the node and ignore children
3077
+ * filter nod
2420
3078
  */
2421
- export declare type WalkerValueFilter = (node: AstNode | Token, parent?: FunctionToken | ParensToken | BinaryExpressionToken, event?: WalkerValueEvent) => WalkerOption | null;
3079
+ export declare type WalkerValueFilter = (node: AstNode$1 | Token$1, parent?: AstNode$1 | Token$1 | null, event?: WalkerEvent) => WalkerOption | null;
2422
3080
 
2423
3081
  export declare interface WalkResult {
2424
- node: AstNode;
3082
+ node: AstNode$1;
2425
3083
  parent?: AstRuleList;
2426
- root?: AstNode;
3084
+ root?: AstNode$1;
2427
3085
  }
2428
3086
 
2429
3087
  export declare interface WalkAttributesResult {
2430
- value: Token;
2431
- previousValue: Token | null;
2432
- nextValue: Token | null;
2433
- root?: AstNode;
2434
- parent: AstNode | Token | null;
2435
- list: Token[] | null;
3088
+ value: Token$1;
3089
+ previousValue: Token$1 | null;
3090
+ nextValue: Token$1 | null;
3091
+ root?: AstNode$1 | Token$1 | null;
3092
+ parent: AstNode$1 | Token$1 | null;
2436
3093
  }
2437
3094
 
2438
3095
  /**
@@ -2456,7 +3113,7 @@ export declare interface ErrorDescription {
2456
3113
  /**
2457
3114
  * error node
2458
3115
  */
2459
- node?: Token | AstNode | null;
3116
+ node?: Token$1 | AstNode$1 | null;
2460
3117
  /**
2461
3118
  * error location
2462
3119
  */
@@ -2491,7 +3148,7 @@ interface ValidationOptions {
2491
3148
  *
2492
3149
  * @private
2493
3150
  */
2494
- visited?: WeakMap<Token, Map<string, Set<ValidationToken>>>;
3151
+ visited?: WeakMap<Token$1, Map<string, Set<ValidationToken>>>;
2495
3152
  /**
2496
3153
  * is optional
2497
3154
  *
@@ -2515,7 +3172,7 @@ interface ValidationOptions {
2515
3172
  *
2516
3173
  * @private
2517
3174
  */
2518
- occurence?: boolean | null;
3175
+ occurrence?: boolean | null;
2519
3176
  /**
2520
3177
  * at least once
2521
3178
  *
@@ -2542,13 +3199,37 @@ interface MinifyOptions {
2542
3199
  */
2543
3200
  nestingRules?: boolean;
2544
3201
  /**
2545
- * expand nested rules
2546
- */
2547
- expandNestingRules?: boolean;
2548
- /**
2549
- * remove duplicate declarations from the same rule
3202
+ * remove duplicate declarations from the same rule. if passed as a string array, duplicated declarations are removed, except for those in the array
3203
+ *
3204
+ *
3205
+ * ```ts
3206
+ *
3207
+ * import {transform} from '@tbela99/css-parser';
3208
+ *
3209
+ * const css = `
3210
+ *
3211
+ * .table {
3212
+ *
3213
+ * width: 100%;
3214
+ * width: calc(100% + 40px);
3215
+ * margin-left: 20px;
3216
+ * margin-left: min(100% , 20px)
3217
+ * }
3218
+ *
3219
+ * `;
3220
+ * const result = await transform(css, {
3221
+ *
3222
+ * beautify: true,
3223
+ * validation: true,
3224
+ * removeDuplicateDeclarations: ['width']
3225
+ * }
3226
+ * );
3227
+ *
3228
+ * console.log(result.code);
3229
+ *
3230
+ * ```
2550
3231
  */
2551
- removeDuplicateDeclarations?: boolean;
3232
+ removeDuplicateDeclarations?: boolean | string | string[];
2552
3233
  /**
2553
3234
  * compute shorthand properties
2554
3235
  */
@@ -2571,12 +3252,22 @@ interface MinifyOptions {
2571
3252
  * remove empty ast nodes
2572
3253
  */
2573
3254
  removeEmpty?: boolean;
3255
+ /**
3256
+ * remove css prefix
3257
+ */
3258
+ removePrefix?: boolean;
2574
3259
  /**
2575
3260
  * define minification passes.
2576
3261
  */
2577
3262
  pass?: number;
2578
3263
  }
2579
3264
 
3265
+ export declare type LoadResult =
3266
+ Promise<ReadableStream<Uint8Array>>
3267
+ | ReadableStream<Uint8Array>
3268
+ | string
3269
+ | Promise<string>;
3270
+
2580
3271
  /**
2581
3272
  * parser options
2582
3273
  */
@@ -2591,34 +3282,31 @@ export declare interface ParserOptions extends MinifyOptions, MinifyFeatureOptio
2591
3282
  */
2592
3283
  sourcemap?: boolean | 'inline';
2593
3284
  /**
2594
- * remove @charset at-rule
3285
+ * remove at-rule charset
2595
3286
  */
2596
3287
  removeCharset?: boolean;
2597
- /**
2598
- * resolve urls
2599
- */
2600
- resolveUrls?: boolean;
2601
3288
  /**
2602
3289
  * resolve import
2603
3290
  */
2604
3291
  resolveImport?: boolean;
2605
3292
  /**
2606
3293
  * current working directory
2607
- * @ignore
3294
+ *
3295
+ * @internal
2608
3296
  */
2609
3297
  cwd?: string;
2610
3298
  /**
2611
- * remove css prefix
3299
+ * expand nested rules
2612
3300
  */
2613
- removePrefix?: boolean;
3301
+ expandNestingRules?: boolean;
2614
3302
  /**
2615
- * get file or url as stream
3303
+ * url and file loader
2616
3304
  * @param url
2617
3305
  * @param currentUrl
3306
+ * @param asStream
2618
3307
  *
2619
- * @private
2620
3308
  */
2621
- getStream?: (url: string, currentUrl: string) => Promise<ReadableStream<string>>;
3309
+ load?: (url: string, currentUrl: string, asStream?: boolean) => LoadResult;
2622
3310
  /**
2623
3311
  * get directory name
2624
3312
  * @param path
@@ -2627,22 +3315,26 @@ export declare interface ParserOptions extends MinifyOptions, MinifyFeatureOptio
2627
3315
  */
2628
3316
  dirname?: (path: string) => string;
2629
3317
  /**
2630
- * resolve path
3318
+ * resolve urls
3319
+ */
3320
+ resolveUrls?: boolean;
3321
+ /**
3322
+ * url and path resolver
2631
3323
  * @param url
2632
3324
  * @param currentUrl
2633
3325
  * @param currentWorkingDirectory
2634
3326
  *
2635
- * @private
2636
3327
  */
2637
3328
  resolve?: (url: string, currentUrl: string, currentWorkingDirectory?: string) => {
2638
3329
  absolute: string;
2639
3330
  relative: string;
2640
3331
  };
3332
+
2641
3333
  /**
2642
3334
  * node visitor
2643
- * {@link VisitorNodeMap}
3335
+ * {@link VisitorNodeMap | VisitorNodeMap[]}
2644
3336
  */
2645
- visitor?: VisitorNodeMap;
3337
+ visitor?: VisitorNodeMap | VisitorNodeMap[];
2646
3338
  /**
2647
3339
  * abort signal
2648
3340
  *
@@ -2658,6 +3350,8 @@ export declare interface ParserOptions extends MinifyOptions, MinifyFeatureOptio
2658
3350
  signal?: AbortSignal;
2659
3351
  /**
2660
3352
  * set parent node
3353
+ *
3354
+ * @private
2661
3355
  */
2662
3356
  setParent?: boolean;
2663
3357
  /**
@@ -2665,7 +3359,7 @@ export declare interface ParserOptions extends MinifyOptions, MinifyFeatureOptio
2665
3359
  *
2666
3360
  * @private
2667
3361
  */
2668
- cache?: WeakMap<AstNode, string>;
3362
+ cache?: WeakMap<AstNode$1, string>;
2669
3363
  }
2670
3364
 
2671
3365
  /**
@@ -2678,7 +3372,7 @@ export declare interface MinifyFeatureOptions {
2678
3372
  /**
2679
3373
  * minify features
2680
3374
  *
2681
- * @internal
3375
+ * @private
2682
3376
  */
2683
3377
  features?: MinifyFeature[];
2684
3378
  }
@@ -2691,17 +3385,18 @@ export declare interface MinifyFeatureOptions {
2691
3385
  export declare interface MinifyFeature {
2692
3386
 
2693
3387
  /**
2694
- * ordering
3388
+ * accepted tokens
2695
3389
  */
2696
- ordering: number;
3390
+ accept?: Set<EnumToken>;
3391
+
2697
3392
  /**
2698
- * use in pre process
3393
+ * ordering
2699
3394
  */
2700
- preProcess: boolean;
3395
+ ordering: number;
2701
3396
  /**
2702
- * use in post process
3397
+ * process mode
2703
3398
  */
2704
- postProcess: boolean;
3399
+ processMode: FeatureWalkMode;
2705
3400
  /**
2706
3401
  * register feature
2707
3402
  * @param options
@@ -2715,9 +3410,9 @@ export declare interface MinifyFeature {
2715
3410
  * @param context
2716
3411
  * @param mode
2717
3412
  */
2718
- run: (ast: AstRule | AstAtRule, options: ParserOptions, parent: AstRule | AstAtRule | AstRuleStyleSheet, context: {
3413
+ run: (ast: AstRule | AstAtRule, options: ParserOptions, parent: AstRule | AstAtRule | AstStyleSheet, context: {
2719
3414
  [key: string]: any
2720
- }, mode: FeatureWalkMode) => void;
3415
+ }, mode: FeatureWalkMode) => AstNode$1 | null;
2721
3416
  }
2722
3417
 
2723
3418
  /**
@@ -2741,15 +3436,31 @@ export declare interface ResolvedPath {
2741
3436
  export declare interface RenderOptions {
2742
3437
 
2743
3438
  /**
2744
- * minify ast node.
3439
+ * minify css values.
2745
3440
  */
2746
3441
  minify?: boolean;
2747
3442
  /**
2748
3443
  * pretty print css
3444
+ *
3445
+ * ```ts
3446
+ * const result = await transform(css, {beautify: true});
3447
+ * ```
2749
3448
  */
2750
3449
  beautify?: boolean;
2751
3450
  /**
2752
- * remove empty rule lists from the ast
3451
+ * remove empty nodes. empty nodes are removed by default
3452
+ *
3453
+ * ```ts
3454
+ *
3455
+ * const css = `
3456
+ * @supports selector(:-ms-input-placeholder) {
3457
+ *
3458
+ * :-ms-input-placeholder {
3459
+ *
3460
+ * }
3461
+ * }`;
3462
+ * const result = await transform(css, {removeEmpty: false});
3463
+ * ```
2753
3464
  */
2754
3465
  removeEmpty?: boolean;
2755
3466
  /**
@@ -2781,7 +3492,7 @@ export declare interface RenderOptions {
2781
3492
  */
2782
3493
  convertColor?: boolean | ColorType;
2783
3494
  /**
2784
- * ernder the node along with its parents
3495
+ * render the node along with its parents
2785
3496
  */
2786
3497
  withParents?: boolean;
2787
3498
  /**
@@ -2839,7 +3550,17 @@ export declare interface ParseResultStats {
2839
3550
  /**
2840
3551
  * imported files stats
2841
3552
  */
2842
- imports: ParseResultStats[]
3553
+ imports: ParseResultStats[],
3554
+
3555
+ /**
3556
+ * nodes count
3557
+ */
3558
+ nodesCount: number;
3559
+
3560
+ /**
3561
+ * tokens count
3562
+ */
3563
+ tokensCount: number;
2843
3564
  }
2844
3565
 
2845
3566
  /**
@@ -2849,7 +3570,7 @@ export declare interface ParseResult {
2849
3570
  /**
2850
3571
  * parsed ast tree
2851
3572
  */
2852
- ast: AstRuleStyleSheet;
3573
+ ast: AstStyleSheet;
2853
3574
  /**
2854
3575
  * parse errors
2855
3576
  */
@@ -3023,7 +3744,7 @@ export declare interface VariableScopeInfo {
3023
3744
  /**
3024
3745
  * declaration values
3025
3746
  */
3026
- values: Token[];
3747
+ values: Token$1[];
3027
3748
  }
3028
3749
 
3029
3750
  /**
@@ -3043,7 +3764,8 @@ export declare interface SourceMapObject {
3043
3764
  /**
3044
3765
  * return the directory name of a path
3045
3766
  * @param path
3046
- * @internal
3767
+ *
3768
+ * @private
3047
3769
  */
3048
3770
  declare function dirname(path: string): string;
3049
3771
  /**
@@ -3059,21 +3781,18 @@ declare function resolve(url: string, currentDirectory: string, cwd?: string): {
3059
3781
  relative: string;
3060
3782
  };
3061
3783
 
3062
- /**
3063
- * node module entry point
3064
- * @module node
3065
- */
3066
-
3067
3784
  /**
3068
3785
  * load file or url as stream
3069
3786
  * @param url
3070
3787
  * @param currentFile
3788
+ * @param asStream
3789
+ * @throws Error file not found
3071
3790
  *
3072
3791
  * @private
3073
3792
  */
3074
- declare function getStream(url: string, currentFile?: string): Promise<ReadableStream<string>>;
3793
+ declare function load(url: string, currentFile?: string, asStream?: boolean): Promise<string | ReadableStream<Uint8Array<ArrayBufferLike>>>;
3075
3794
  /**
3076
- * render ast tree
3795
+ * render the ast tree
3077
3796
  * @param data
3078
3797
  * @param options
3079
3798
  *
@@ -3083,20 +3802,31 @@ declare function getStream(url: string, currentFile?: string): Promise<ReadableS
3083
3802
  *
3084
3803
  * import {render, ColorType} from '@tbela99/css-parser';
3085
3804
  *
3086
- * // remote file
3087
- * let result = render(ast);
3088
- * console.log(result.code);
3805
+ * const css = 'body { color: color(from hsl(0 100% 50%) xyz x y z); }';
3806
+ * const parseResult = await parse(css);
3089
3807
  *
3090
- * // local file
3091
- * result = await parseFile(ast, {beatify: true, convertColor: ColorType.SRGB});
3808
+ * let renderResult = render(parseResult.ast);
3092
3809
  * console.log(result.code);
3810
+ *
3811
+ * // body{color:red}
3812
+ *
3813
+ *
3814
+ * renderResult = render(parseResult.ast, {beautify: true, convertColor: ColorType.SRGB});
3815
+ * console.log(renderResult.code);
3816
+ *
3817
+ * // body {
3818
+ * // color: color(srgb 1 0 0)
3819
+ * // }
3093
3820
  * ```
3094
3821
  */
3095
- declare function render(data: AstNode, options?: RenderOptions): RenderResult;
3822
+ declare function render(data: AstNode$1, options?: RenderOptions): RenderResult;
3096
3823
  /**
3097
3824
  * parse css file
3098
3825
  * @param file url or path
3099
3826
  * @param options
3827
+ * @param asStream load file as stream
3828
+ *
3829
+ * @throws Error file not found
3100
3830
  *
3101
3831
  * Example:
3102
3832
  *
@@ -3113,21 +3843,21 @@ declare function render(data: AstNode, options?: RenderOptions): RenderResult;
3113
3843
  * console.log(result.ast);
3114
3844
  * ```
3115
3845
  */
3116
- declare function parseFile(file: string, options?: ParserOptions): Promise<ParseResult>;
3846
+ declare function parseFile(file: string, options?: ParserOptions, asStream?: boolean): Promise<ParseResult>;
3117
3847
  /**
3118
3848
  * parse css
3119
3849
  * @param stream
3120
- * @param opt
3850
+ * @param options
3121
3851
  *
3122
3852
  * Example:
3123
3853
  *
3124
3854
  * ```ts
3125
3855
  *
3126
- * import {transform} from '@tbela99/css-parser';
3856
+ * import {parse} from '@tbela99/css-parser';
3127
3857
  *
3128
3858
  * // css string
3129
- * let result = await transform(css);
3130
- * console.log(result.code);
3859
+ * let result = await parse(css);
3860
+ * console.log(result.ast);
3131
3861
  * ```
3132
3862
  *
3133
3863
  * Example using stream
@@ -3140,28 +3870,31 @@ declare function parseFile(file: string, options?: ParserOptions): Promise<Parse
3140
3870
  * // usage: node index.ts < styles.css or cat styles.css | node index.ts
3141
3871
  *
3142
3872
  * const readableStream = Readable.toWeb(process.stdin);
3143
- * const result = await parse(readableStream, {beautify: true});
3873
+ * let result = await parse(readableStream, {beautify: true});
3144
3874
  *
3145
3875
  * console.log(result.ast);
3146
3876
  * ```
3147
3877
  *
3148
- * Example using fetch
3878
+ * Example using fetch and readable stream
3149
3879
  *
3150
3880
  * ```ts
3151
3881
  *
3152
3882
  * import {parse} from '@tbela99/css-parser';
3153
3883
  *
3154
3884
  * const response = await fetch('https://docs.deno.com/styles.css');
3155
- * result = await parse(response.body, {beautify: true});
3885
+ * const result = await parse(response.body, {beautify: true});
3156
3886
  *
3157
3887
  * console.log(result.ast);
3158
3888
  * ```
3159
3889
  */
3160
- declare function parse(stream: string | ReadableStream<string>, opt?: ParserOptions): Promise<ParseResult>;
3890
+ declare function parse(stream: string | ReadableStream<Uint8Array>, options?: ParserOptions): Promise<ParseResult>;
3161
3891
  /**
3162
3892
  * transform css file
3163
3893
  * @param file url or path
3164
3894
  * @param options
3895
+ * @param asStream load file as stream
3896
+ *
3897
+ * @throws Error file not found
3165
3898
  *
3166
3899
  * Example:
3167
3900
  *
@@ -3178,7 +3911,7 @@ declare function parse(stream: string | ReadableStream<string>, opt?: ParserOpti
3178
3911
  * console.log(result.code);
3179
3912
  * ```
3180
3913
  */
3181
- declare function transformFile(file: string, options?: TransformOptions): Promise<TransformResult>;
3914
+ declare function transformFile(file: string, options?: TransformOptions, asStream?: boolean): Promise<TransformResult>;
3182
3915
  /**
3183
3916
  * transform css
3184
3917
  * @param css
@@ -3191,7 +3924,7 @@ declare function transformFile(file: string, options?: TransformOptions): Promis
3191
3924
  * import {transform} from '@tbela99/css-parser';
3192
3925
  *
3193
3926
  * // css string
3194
- * let result = await transform(css);
3927
+ * const result = await transform(css);
3195
3928
  * console.log(result.code);
3196
3929
  * ```
3197
3930
  *
@@ -3222,7 +3955,7 @@ declare function transformFile(file: string, options?: TransformOptions): Promis
3222
3955
  * console.log(result.code);
3223
3956
  * ```
3224
3957
  */
3225
- declare function transform(css: string | ReadableStream<string>, options?: TransformOptions): Promise<TransformResult>;
3958
+ declare function transform(css: string | ReadableStream<Uint8Array>, options?: TransformOptions): Promise<TransformResult>;
3226
3959
 
3227
- export { ColorType, EnumToken, FeatureWalkMode, SourceMap, ValidationLevel, WalkerOptionEnum, WalkerValueEvent, convertColor, dirname, expand, getStream, isOkLabClose, mathFuncs, minify, okLabDistance, parse, parseDeclarations, parseFile, parseString, parseTokens, render, renderToken, resolve, transform, transformFile, transformFunctions, walk, walkValues };
3228
- export type { AddToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyFrameRule, AstKeyframAtRule, AstKeyframeRule, AstNode, AstRule, AstRuleList, AstRuleStyleSheet, AtRuleToken, AtRuleVisitorHandler, AttrEndToken, AttrStartToken, AttrToken, Background, BackgroundAttachmentMapping, BackgroundPosition, BackgroundPositionClass, BackgroundPositionConstraints, BackgroundPositionMapping, BackgroundProperties, BackgroundRepeat, BackgroundRepeatMapping, BackgroundSize, BackgroundSizeMapping, BadCDOCommentToken, BadCommentToken, BadStringToken, BadUrlToken, BaseToken, BinaryExpressionNode, BinaryExpressionToken, BlockEndToken, BlockStartToken, Border, BorderColor, BorderColorClass, BorderProperties, BorderRadius, CDOCommentToken, ChildCombinatorToken, ClassSelectorToken, ColonToken, ColorToken, ColumnCombinatorToken, CommaToken, CommentToken, ConstraintsMapping, ContainMatchToken, Context, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionImageToken, FunctionToken, FunctionURLToken, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, ImportantToken, IncludeMatchToken, InvalidAttrToken, InvalidClassSelectorToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, Location, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureAndToken, MediaFeatureNotToken, MediaFeatureOnlyToken, MediaFeatureOrToken, MediaFeatureToken, MediaQueryConditionToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, MulToken, NameSpaceAttributeToken, NestingSelectorToken, NextSiblingCombinatorToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo, ParseResult, ParseResultStats, ParseTokenOptions, ParserOptions, PercentageToken, Position, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawSelectorTokens, RenderOptions, RenderResult, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token, TokenizeResult, TransformOptions, TransformResult, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, Value, VariableScopeInfo, VisitorNodeMap, WalkAttributesResult, WalkResult, WalkerFilter, WalkerOption, WalkerValueFilter, WhitespaceToken };
3960
+ export { ColorType, EnumToken, FeatureWalkMode, SourceMap, ValidationLevel, WalkerEvent, WalkerOptionEnum, convertColor, dirname, expand, isOkLabClose, load, mathFuncs, minify, okLabDistance, parse, parseDeclarations, parseFile, parseString, parseTokens, render, renderToken, resolve, transform, transformFile, transformFunctions, walk, walkValues };
3961
+ export type { AddToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyFrameRule, AstKeyframesAtRule, AstKeyframesRule, AstNode$1 as AstNode, AstRule, AstRuleList, AstStyleSheet, AtRuleToken, AtRuleVisitorHandler, AttrEndToken, AttrStartToken, AttrToken, Background, BackgroundAttachmentMapping, BackgroundPosition, BackgroundPositionClass, BackgroundPositionConstraints, BackgroundPositionMapping, BackgroundProperties, BackgroundRepeat, BackgroundRepeatMapping, BackgroundSize, BackgroundSizeMapping, BadCDOCommentToken, BadCommentToken, BadStringToken, BadUrlToken, BaseToken, BinaryExpressionNode, BinaryExpressionToken, BlockEndToken, BlockStartToken, Border, BorderColor, BorderColorClass, BorderProperties, BorderRadius, CDOCommentToken, ChildCombinatorToken, ClassSelectorToken, ColonToken, ColorToken, ColumnCombinatorToken, CommaToken, CommentToken, ConstraintsMapping, ContainMatchToken, Context, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionImageToken, FunctionToken, FunctionURLToken, GenericVisitorAstNodeHandlerMap, GenericVisitorHandler, GenericVisitorResult, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, ImportantToken, IncludeMatchToken, InvalidAttrToken, InvalidClassSelectorToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult, Location, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureAndToken, MediaFeatureNotToken, MediaFeatureOnlyToken, MediaFeatureOrToken, MediaFeatureToken, MediaQueryConditionToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, MulToken, NameSpaceAttributeToken, NestingSelectorToken, NextSiblingCombinatorToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo, ParseResult, ParseResultStats, ParseTokenOptions, ParserOptions, PercentageToken, Position, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawSelectorTokens, RenderOptions, RenderResult, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token$1 as Token, TokenizeResult, TransformOptions, TransformResult, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, Value, ValueVisitorHandler, VariableScopeInfo, VisitorNodeMap, WalkAttributesResult, WalkResult, WalkerFilter, WalkerOption, WalkerValueFilter, WhitespaceToken };