1 | // Type definitions for csso 3.5
|
2 | // Project: https://github.com/css/csso
|
3 | // Definitions by: Christian Rackerseder <https://github.com/screendriver>
|
4 | // Erik Källén <https://github.com/erik-kallen>
|
5 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
6 | // TypeScript Version: 2.7
|
7 |
|
8 | import * as csstree from 'css-tree';
|
9 |
|
10 | declare namespace csso {
|
11 | interface Result {
|
12 | /**
|
13 | * Resulting CSS.
|
14 | */
|
15 | css: string;
|
16 | /**
|
17 | * Instance of SourceMapGenerator or null.
|
18 | */
|
19 | map: object | null;
|
20 | }
|
21 |
|
22 | interface Usage {
|
23 | tags?: string[];
|
24 | ids?: string[];
|
25 | classes?: string[];
|
26 | scopes?: string[][];
|
27 | blacklist?: {
|
28 | tags?: string[];
|
29 | ids?: string[];
|
30 | classes?: string[];
|
31 | };
|
32 | }
|
33 |
|
34 | interface CompressOptions {
|
35 | /**
|
36 | * Disable or enable a structure optimisations.
|
37 | * @default true
|
38 | */
|
39 | restructure?: boolean;
|
40 | /**
|
41 | * Enables merging of @media rules with the same media query by splitted by other rules.
|
42 | * The optimisation is unsafe in general, but should work fine in most cases. Use it on your own risk.
|
43 | * @default false
|
44 | */
|
45 | forceMediaMerge?: boolean;
|
46 | /**
|
47 | * Transform a copy of input AST if true. Useful in case of AST reuse.
|
48 | * @default false
|
49 | */
|
50 | clone?: boolean;
|
51 | /**
|
52 | * Specify what comments to leave:
|
53 | * - 'exclamation' or true – leave all exclamation comments
|
54 | * - 'first-exclamation' – remove every comment except first one
|
55 | * - false – remove all comments
|
56 | * @default true
|
57 | */
|
58 | comments?: string | boolean;
|
59 | /**
|
60 | * Usage data for advanced optimisations.
|
61 | */
|
62 | usage?: Usage;
|
63 | /**
|
64 | * Function to track every step of transformation.
|
65 | */
|
66 | logger?: () => void;
|
67 | }
|
68 |
|
69 | interface MinifyOptions {
|
70 | /**
|
71 | * Generate a source map when true.
|
72 | * @default false
|
73 | */
|
74 | sourceMap?: boolean;
|
75 | /**
|
76 | * Filename of input CSS, uses for source map generation.
|
77 | * @default '<unknown>'
|
78 | */
|
79 | filename?: string;
|
80 | /**
|
81 | * Output debug information to stderr.
|
82 | * @default false
|
83 | */
|
84 | debug?: boolean;
|
85 | /**
|
86 | * Called right after parse is run.
|
87 | */
|
88 | beforeCompress?: BeforeCompressFn | BeforeCompressFn[];
|
89 | /**
|
90 | * Called right after compress() is run.
|
91 | */
|
92 | afterCompress?: AfterCompressFn | AfterCompressFn[];
|
93 | restructure?: boolean;
|
94 | }
|
95 |
|
96 | type BeforeCompressFn = (ast: object, options: CompressOptions) => void;
|
97 | type AfterCompressFn = (compressResult: string, options: CompressOptions) => void;
|
98 | }
|
99 |
|
100 | interface Csso {
|
101 | /**
|
102 | * Minify source CSS passed as String
|
103 | * @param source
|
104 | * @param options
|
105 | */
|
106 | minify(source: string, options?: csso.MinifyOptions & csso.CompressOptions): csso.Result;
|
107 |
|
108 | /**
|
109 | * The same as minify() but for list of declarations. Usually it's a style attribute value.
|
110 | * @param source
|
111 | * @param options
|
112 | */
|
113 | minifyBlock(source: string, options?: csso.MinifyOptions & csso.CompressOptions): csso.Result;
|
114 |
|
115 | /**
|
116 | * Does the main task – compress an AST.
|
117 | */
|
118 | compress(ast: csstree.CssNode, options?: csso.CompressOptions): { ast: csstree.CssNode };
|
119 |
|
120 | syntax: typeof csstree;
|
121 | }
|
122 |
|
123 | declare const csso: Csso;
|
124 | export = csso;
|