UNPKG

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