purgecss 4.0.1 → 4.1.1

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