UNPKG

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