purgecss 4.0.3 → 4.1.3

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/lib/purgecss.d.ts CHANGED
@@ -1,96 +1,111 @@
1
1
  import * as postcss from "postcss";
2
+ type PostCSSRoot = postcss.Root;
3
+ interface AtRules {
4
+ fontFace: Array<{
5
+ name: string;
6
+ node: postcss.AtRule;
7
+ }>;
8
+ keyframes: postcss.AtRule[];
9
+ }
2
10
  interface RawContent<T = string> {
3
- extension: string;
4
- raw: T;
11
+ extension: string;
12
+ raw: T;
5
13
  }
6
14
  interface RawCSS {
7
- raw: string;
15
+ raw: string;
16
+ name?: string;
8
17
  }
9
18
  interface ExtractorResultDetailed {
10
- attributes: {
11
- names: string[];
12
- values: string[];
13
- };
14
- classes: string[];
15
- ids: string[];
16
- tags: string[];
17
- undetermined: string[];
19
+ attributes: {
20
+ names: string[];
21
+ values: string[];
22
+ };
23
+ classes: string[];
24
+ ids: string[];
25
+ tags: string[];
26
+ undetermined: string[];
18
27
  }
19
28
  type ExtractorResult = ExtractorResultDetailed | string[];
20
29
  type ExtractorFunction<T = string> = (content: T) => ExtractorResult;
21
30
  interface Extractors {
22
- extensions: string[];
23
- extractor: ExtractorFunction;
31
+ extensions: string[];
32
+ extractor: ExtractorFunction;
24
33
  }
34
+ type IgnoreType = "end" | "start" | "next";
25
35
  type StringRegExpArray = Array<RegExp | string>;
26
36
  type ComplexSafelist = {
27
- standard?: StringRegExpArray;
28
- deep?: RegExp[];
29
- greedy?: RegExp[];
30
- variables?: StringRegExpArray;
31
- keyframes?: StringRegExpArray;
37
+ standard?: StringRegExpArray;
38
+ deep?: RegExp[];
39
+ greedy?: RegExp[];
40
+ variables?: StringRegExpArray;
41
+ keyframes?: StringRegExpArray;
32
42
  };
33
43
  type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
34
44
  interface UserDefinedOptions {
35
- content: Array<string | RawContent>;
36
- css: Array<string | RawCSS>;
37
- defaultExtractor?: ExtractorFunction;
38
- extractors?: Array<Extractors>;
39
- fontFace?: boolean;
40
- keyframes?: boolean;
41
- output?: string;
42
- rejected?: boolean;
43
- stdin?: boolean;
44
- stdout?: boolean;
45
- variables?: boolean;
46
- safelist?: UserDefinedSafelist;
47
- blocklist?: StringRegExpArray;
48
- skippedContentGlobs?: Array<string>;
49
- dynamicAttributes?: string[];
45
+ content: Array<string | RawContent>;
46
+ css: Array<string | RawCSS>;
47
+ defaultExtractor?: ExtractorFunction;
48
+ extractors?: Array<Extractors>;
49
+ fontFace?: boolean;
50
+ keyframes?: boolean;
51
+ output?: string;
52
+ rejected?: boolean;
53
+ rejectedCss?: boolean;
54
+ stdin?: boolean;
55
+ stdout?: boolean;
56
+ variables?: boolean;
57
+ safelist?: UserDefinedSafelist;
58
+ blocklist?: StringRegExpArray;
59
+ skippedContentGlobs?: Array<string>;
60
+ dynamicAttributes?: string[];
50
61
  }
51
62
  interface Options {
52
- content: Array<string | RawContent>;
53
- css: Array<string | RawCSS>;
54
- defaultExtractor: ExtractorFunction;
55
- extractors: Array<Extractors>;
56
- fontFace: boolean;
57
- keyframes: boolean;
58
- output?: string;
59
- rejected: boolean;
60
- stdin: boolean;
61
- stdout: boolean;
62
- variables: boolean;
63
- safelist: Required<ComplexSafelist>;
64
- blocklist: StringRegExpArray;
65
- skippedContentGlobs: Array<string>;
66
- dynamicAttributes: string[];
63
+ content: Array<string | RawContent>;
64
+ css: Array<string | RawCSS>;
65
+ defaultExtractor: ExtractorFunction;
66
+ extractors: Array<Extractors>;
67
+ fontFace: boolean;
68
+ keyframes: boolean;
69
+ output?: string;
70
+ rejected: boolean;
71
+ rejectedCss: boolean;
72
+ stdin: boolean;
73
+ stdout: boolean;
74
+ variables: boolean;
75
+ safelist: Required<ComplexSafelist>;
76
+ blocklist: StringRegExpArray;
77
+ skippedContentGlobs: Array<string>;
78
+ dynamicAttributes: string[];
67
79
  }
68
80
  interface ResultPurge {
69
- css: string;
70
- file?: string;
71
- rejected?: string[];
81
+ css: string;
82
+ rejectedCss?: string;
83
+ file?: string;
84
+ rejected?: string[];
72
85
  }
73
86
  declare class ExtractorResultSets {
74
- private undetermined;
75
- private attrNames;
76
- private attrValues;
77
- private classes;
78
- private ids;
79
- private tags;
80
- constructor(er: ExtractorResult);
81
- merge(that: ExtractorResult | ExtractorResultSets): this;
82
- hasAttrName(name: string): boolean;
83
- private someAttrValue;
84
- hasAttrPrefix(prefix: string): boolean;
85
- hasAttrSuffix(suffix: string): boolean;
86
- hasAttrSubstr(substr: string): boolean;
87
- hasAttrValue(value: string): boolean;
88
- hasClass(name: string): boolean;
89
- hasId(id: string): boolean;
90
- hasTag(tag: string): boolean;
87
+ private undetermined;
88
+ private attrNames;
89
+ private attrValues;
90
+ private classes;
91
+ private ids;
92
+ private tags;
93
+ constructor(er: ExtractorResult);
94
+ merge(that: ExtractorResult | ExtractorResultSets): this;
95
+ hasAttrName(name: string): boolean;
96
+ private someAttrValue;
97
+ hasAttrPrefix(prefix: string): boolean;
98
+ hasAttrSuffix(suffix: string): boolean;
99
+ hasAttrSubstr(substr: string): boolean;
100
+ hasAttrValue(value: string): boolean;
101
+ hasClass(name: string): boolean;
102
+ hasId(id: string): boolean;
103
+ hasTag(tag: string): boolean;
91
104
  }
92
105
  declare const defaultOptions: Options;
93
- declare function standardizeSafelist(userDefinedSafelist?: UserDefinedSafelist): Required<ComplexSafelist>;
106
+ declare function standardizeSafelist(
107
+ userDefinedSafelist?: UserDefinedSafelist
108
+ ): Required<ComplexSafelist>;
94
109
  /**
95
110
  * Load the configuration file from the path
96
111
  * @param configFile Path of the config file
@@ -101,183 +116,219 @@ declare function setOptions(configFile?: string): Promise<Options>;
101
116
  * @param extractorSelectorsA extractor selectors A
102
117
  * @param extractorSelectorsB extractor selectors B
103
118
  */
104
- declare function mergeExtractorSelectors(...extractors: (ExtractorResultDetailed | ExtractorResultSets)[]): ExtractorResultSets;
119
+ declare function mergeExtractorSelectors(
120
+ ...extractors: (ExtractorResultDetailed | ExtractorResultSets)[]
121
+ ): ExtractorResultSets;
105
122
  declare class PurgeCSS {
106
- private ignore;
107
- private atRules;
108
- private usedAnimations;
109
- private usedFontFaces;
110
- selectorsRemoved: Set<string>;
111
- private variablesStructure;
112
- options: Options;
113
- private collectDeclarationsData;
114
- /**
115
- * Get the extractor corresponding to the extension file
116
- * @param filename Name of the file
117
- * @param extractors Array of extractors definition
118
- */
119
- /**
120
- * Get the extractor corresponding to the extension file
121
- * @param filename Name of the file
122
- * @param extractors Array of extractors definition
123
- */
124
- private getFileExtractor;
125
- /**
126
- * Extract the selectors present in the files using a purgecss extractor
127
- * @param files Array of files path or glob pattern
128
- * @param extractors Array of extractors
129
- */
130
- /**
131
- * Extract the selectors present in the files using a purgecss extractor
132
- * @param files Array of files path or glob pattern
133
- * @param extractors Array of extractors
134
- */
135
- extractSelectorsFromFiles(files: string[], extractors: Extractors[]): Promise<ExtractorResultSets>;
136
- /**
137
- * Extract the selectors present in the passed string using a PurgeCSS extractor
138
- * @param content Array of content
139
- * @param extractors Array of extractors
140
- */
141
- /**
142
- * Extract the selectors present in the passed string using a PurgeCSS extractor
143
- * @param content Array of content
144
- * @param extractors Array of extractors
145
- */
146
- extractSelectorsFromString(content: RawContent[], extractors: Extractors[]): Promise<ExtractorResultSets>;
147
- /**
148
- * Evaluate at-rule and register it for future reference
149
- * @param node node of postcss AST
150
- */
151
- /**
152
- * Evaluate at-rule and register it for future reference
153
- * @param node node of postcss AST
154
- */
155
- private evaluateAtRule;
156
- /**
157
- * Evaluate css selector and decide if it should be removed or not
158
- * @param node node of postcss AST
159
- * @param selectors selectors used in content files
160
- */
161
- /**
162
- * Evaluate css selector and decide if it should be removed or not
163
- * @param node node of postcss AST
164
- * @param selectors selectors used in content files
165
- */
166
- private evaluateRule;
167
- /**
168
- * Get the purged version of the css based on the files
169
- * @param cssOptions css options, files or raw strings
170
- * @param selectors set of extracted css selectors
171
- */
172
- /**
173
- * Get the purged version of the css based on the files
174
- * @param cssOptions css options, files or raw strings
175
- * @param selectors set of extracted css selectors
176
- */
177
- getPurgedCSS(cssOptions: Array<string | RawCSS>, selectors: ExtractorResultSets): Promise<ResultPurge[]>;
178
- /**
179
- * Check if the keyframe is safelisted with the option safelist keyframes
180
- * @param keyframesName name of the keyframe animation
181
- */
182
- /**
183
- * Check if the keyframe is safelisted with the option safelist keyframes
184
- * @param keyframesName name of the keyframe animation
185
- */
186
- private isKeyframesSafelisted;
187
- /**
188
- * Check if the selector is blocklisted with the option blocklist
189
- * @param selector css selector
190
- */
191
- /**
192
- * Check if the selector is blocklisted with the option blocklist
193
- * @param selector css selector
194
- */
195
- private isSelectorBlocklisted;
196
- /**
197
- * Check if the selector is safelisted with the option safelist standard
198
- * @param selector css selector
199
- */
200
- /**
201
- * Check if the selector is safelisted with the option safelist standard
202
- * @param selector css selector
203
- */
204
- private isSelectorSafelisted;
205
- /**
206
- * Check if the selector is safelisted with the option safelist deep
207
- * @param selector selector
208
- */
209
- /**
210
- * Check if the selector is safelisted with the option safelist deep
211
- * @param selector selector
212
- */
213
- private isSelectorSafelistedDeep;
214
- /**
215
- * Check if the selector is safelisted with the option safelist greedy
216
- * @param selector selector
217
- */
218
- /**
219
- * Check if the selector is safelisted with the option safelist greedy
220
- * @param selector selector
221
- */
222
- private isSelectorSafelistedGreedy;
223
- /**
224
- * Remove unused css
225
- * @param userOptions PurgeCSS options
226
- */
227
- /**
228
- * Remove unused css
229
- * @param userOptions PurgeCSS options
230
- */
231
- purge(userOptions: UserDefinedOptions | string | undefined): Promise<ResultPurge[]>;
232
- /**
233
- * Remove unused CSS variables
234
- */
235
- /**
236
- * Remove unused CSS variables
237
- */
238
- removeUnusedCSSVariables(): void;
239
- /**
240
- * Remove unused font-faces
241
- */
242
- /**
243
- * Remove unused font-faces
244
- */
245
- removeUnusedFontFaces(): void;
246
- /**
247
- * Remove unused keyframes
248
- */
249
- /**
250
- * Remove unused keyframes
251
- */
252
- removeUnusedKeyframes(): void;
253
- /**
254
- * Transform a selector node into a string
255
- */
256
- /**
257
- * Transform a selector node into a string
258
- */
259
- private getSelectorValue;
260
- /**
261
- * Determine if the selector should be kept, based on the selectors found in the files
262
- * @param selector set of css selectors found in the content files or string
263
- * @param selectorsFromExtractor selectors in the css rule
264
- */
265
- /**
266
- * Determine if the selector should be kept, based on the selectors found in the files
267
- * @param selector set of css selectors found in the content files or string
268
- * @param selectorsFromExtractor selectors in the css rule
269
- */
270
- private shouldKeepSelector;
271
- /**
272
- * Walk through the CSS AST and remove unused CSS
273
- * @param root root node of the postcss AST
274
- * @param selectors selectors used in content files
275
- */
276
- /**
277
- * Walk through the CSS AST and remove unused CSS
278
- * @param root root node of the postcss AST
279
- * @param selectors selectors used in content files
280
- */
281
- walkThroughCSS(root: postcss.Root, selectors: ExtractorResultSets): void;
123
+ private ignore;
124
+ private atRules;
125
+ private usedAnimations;
126
+ private usedFontFaces;
127
+ selectorsRemoved: Set<string>;
128
+ removedNodes: postcss.Node[];
129
+ private variablesStructure;
130
+ options: Options;
131
+ private collectDeclarationsData;
132
+ /**
133
+ * Get the extractor corresponding to the extension file
134
+ * @param filename Name of the file
135
+ * @param extractors Array of extractors definition
136
+ */
137
+ /**
138
+ * Get the extractor corresponding to the extension file
139
+ * @param filename Name of the file
140
+ * @param extractors Array of extractors definition
141
+ */
142
+ private getFileExtractor;
143
+ /**
144
+ * Extract the selectors present in the files using a purgecss extractor
145
+ * @param files Array of files path or glob pattern
146
+ * @param extractors Array of extractors
147
+ */
148
+ /**
149
+ * Extract the selectors present in the files using a purgecss extractor
150
+ * @param files Array of files path or glob pattern
151
+ * @param extractors Array of extractors
152
+ */
153
+ extractSelectorsFromFiles(
154
+ files: string[],
155
+ extractors: Extractors[]
156
+ ): Promise<ExtractorResultSets>;
157
+ /**
158
+ * Extract the selectors present in the passed string using a PurgeCSS extractor
159
+ * @param content Array of content
160
+ * @param extractors Array of extractors
161
+ */
162
+ /**
163
+ * Extract the selectors present in the passed string using a PurgeCSS extractor
164
+ * @param content Array of content
165
+ * @param extractors Array of extractors
166
+ */
167
+ extractSelectorsFromString(
168
+ content: RawContent[],
169
+ extractors: Extractors[]
170
+ ): Promise<ExtractorResultSets>;
171
+ /**
172
+ * Evaluate at-rule and register it for future reference
173
+ * @param node node of postcss AST
174
+ */
175
+ /**
176
+ * Evaluate at-rule and register it for future reference
177
+ * @param node node of postcss AST
178
+ */
179
+ private evaluateAtRule;
180
+ /**
181
+ * Evaluate css selector and decide if it should be removed or not
182
+ * @param node node of postcss AST
183
+ * @param selectors selectors used in content files
184
+ */
185
+ /**
186
+ * Evaluate css selector and decide if it should be removed or not
187
+ * @param node node of postcss AST
188
+ * @param selectors selectors used in content files
189
+ */
190
+ private evaluateRule;
191
+ /**
192
+ * Get the purged version of the css based on the files
193
+ * @param cssOptions css options, files or raw strings
194
+ * @param selectors set of extracted css selectors
195
+ */
196
+ /**
197
+ * Get the purged version of the css based on the files
198
+ * @param cssOptions css options, files or raw strings
199
+ * @param selectors set of extracted css selectors
200
+ */
201
+ getPurgedCSS(
202
+ cssOptions: Array<string | RawCSS>,
203
+ selectors: ExtractorResultSets
204
+ ): Promise<ResultPurge[]>;
205
+ /**
206
+ * Check if the keyframe is safelisted with the option safelist keyframes
207
+ * @param keyframesName name of the keyframe animation
208
+ */
209
+ /**
210
+ * Check if the keyframe is safelisted with the option safelist keyframes
211
+ * @param keyframesName name of the keyframe animation
212
+ */
213
+ private isKeyframesSafelisted;
214
+ /**
215
+ * Check if the selector is blocklisted with the option blocklist
216
+ * @param selector css selector
217
+ */
218
+ /**
219
+ * Check if the selector is blocklisted with the option blocklist
220
+ * @param selector css selector
221
+ */
222
+ private isSelectorBlocklisted;
223
+ /**
224
+ * Check if the selector is safelisted with the option safelist standard
225
+ * @param selector css selector
226
+ */
227
+ /**
228
+ * Check if the selector is safelisted with the option safelist standard
229
+ * @param selector css selector
230
+ */
231
+ private isSelectorSafelisted;
232
+ /**
233
+ * Check if the selector is safelisted with the option safelist deep
234
+ * @param selector selector
235
+ */
236
+ /**
237
+ * Check if the selector is safelisted with the option safelist deep
238
+ * @param selector selector
239
+ */
240
+ private isSelectorSafelistedDeep;
241
+ /**
242
+ * Check if the selector is safelisted with the option safelist greedy
243
+ * @param selector selector
244
+ */
245
+ /**
246
+ * Check if the selector is safelisted with the option safelist greedy
247
+ * @param selector selector
248
+ */
249
+ private isSelectorSafelistedGreedy;
250
+ /**
251
+ * Remove unused css
252
+ * @param userOptions PurgeCSS options
253
+ */
254
+ /**
255
+ * Remove unused css
256
+ * @param userOptions PurgeCSS options
257
+ */
258
+ purge(
259
+ userOptions: UserDefinedOptions | string | undefined
260
+ ): Promise<ResultPurge[]>;
261
+ /**
262
+ * Remove unused CSS variables
263
+ */
264
+ /**
265
+ * Remove unused CSS variables
266
+ */
267
+ removeUnusedCSSVariables(): void;
268
+ /**
269
+ * Remove unused font-faces
270
+ */
271
+ /**
272
+ * Remove unused font-faces
273
+ */
274
+ removeUnusedFontFaces(): void;
275
+ /**
276
+ * Remove unused keyframes
277
+ */
278
+ /**
279
+ * Remove unused keyframes
280
+ */
281
+ removeUnusedKeyframes(): void;
282
+ /**
283
+ * Transform a selector node into a string
284
+ */
285
+ /**
286
+ * Transform a selector node into a string
287
+ */
288
+ private getSelectorValue;
289
+ /**
290
+ * Determine if the selector should be kept, based on the selectors found in the files
291
+ * @param selector set of css selectors found in the content files or string
292
+ * @param selectorsFromExtractor selectors in the css rule
293
+ */
294
+ /**
295
+ * Determine if the selector should be kept, based on the selectors found in the files
296
+ * @param selector set of css selectors found in the content files or string
297
+ * @param selectorsFromExtractor selectors in the css rule
298
+ */
299
+ private shouldKeepSelector;
300
+ /**
301
+ * Walk through the CSS AST and remove unused CSS
302
+ * @param root root node of the postcss AST
303
+ * @param selectors selectors used in content files
304
+ */
305
+ /**
306
+ * Walk through the CSS AST and remove unused CSS
307
+ * @param root root node of the postcss AST
308
+ * @param selectors selectors used in content files
309
+ */
310
+ walkThroughCSS(root: PostCSSRoot, selectors: ExtractorResultSets): void;
282
311
  }
283
- export { PurgeCSS as default, PurgeCSS, defaultOptions, standardizeSafelist, setOptions, mergeExtractorSelectors };
312
+ export {
313
+ PurgeCSS as default,
314
+ PurgeCSS,
315
+ defaultOptions,
316
+ PostCSSRoot,
317
+ AtRules,
318
+ RawContent,
319
+ RawCSS,
320
+ ExtractorResultDetailed,
321
+ ExtractorResult,
322
+ ExtractorFunction,
323
+ Extractors,
324
+ IgnoreType,
325
+ StringRegExpArray,
326
+ ComplexSafelist,
327
+ UserDefinedSafelist,
328
+ UserDefinedOptions,
329
+ Options,
330
+ ResultPurge,
331
+ standardizeSafelist,
332
+ setOptions,
333
+ mergeExtractorSelectors,
334
+ };