Socket
Socket
Sign inDemoInstall

purgecss

Package Overview
Dependencies
19
Maintainers
2
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0 to 4.0.1

508

lib/purgecss.d.ts
import * as postcss from "postcss";
interface RawContent<T = string> {
extension: string;
raw: T;
extension: string;
raw: T;
}
interface RawCSS {
raw: string;
raw: string;
}
interface ExtractorResultDetailed {
attributes: {
names: string[];
values: string[];
};
classes: string[];
ids: string[];
tags: string[];
undetermined: string[];
attributes: {
names: string[];
values: string[];
};
classes: string[];
ids: string[];
tags: string[];
undetermined: string[];
}

@@ -22,70 +22,72 @@ type ExtractorResult = ExtractorResultDetailed | string[];

interface Extractors {
extensions: string[];
extractor: ExtractorFunction;
extensions: string[];
extractor: ExtractorFunction;
}
type StringRegExpArray = Array<RegExp | string>;
type ComplexSafelist = {
standard?: StringRegExpArray;
deep?: RegExp[];
greedy?: RegExp[];
variables?: StringRegExpArray;
keyframes?: StringRegExpArray;
standard?: StringRegExpArray;
deep?: RegExp[];
greedy?: RegExp[];
variables?: StringRegExpArray;
keyframes?: StringRegExpArray;
};
type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
interface UserDefinedOptions {
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor?: ExtractorFunction;
extractors?: Array<Extractors>;
fontFace?: boolean;
keyframes?: boolean;
output?: string;
rejected?: boolean;
stdin?: boolean;
stdout?: boolean;
variables?: boolean;
safelist?: UserDefinedSafelist;
blocklist?: StringRegExpArray;
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor?: ExtractorFunction;
extractors?: Array<Extractors>;
fontFace?: boolean;
keyframes?: boolean;
output?: string;
rejected?: boolean;
stdin?: boolean;
stdout?: boolean;
variables?: boolean;
safelist?: UserDefinedSafelist;
blocklist?: StringRegExpArray;
}
interface Options {
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor: ExtractorFunction;
extractors: Array<Extractors>;
fontFace: boolean;
keyframes: boolean;
output?: string;
rejected: boolean;
stdin: boolean;
stdout: boolean;
variables: boolean;
safelist: Required<ComplexSafelist>;
blocklist: StringRegExpArray;
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor: ExtractorFunction;
extractors: Array<Extractors>;
fontFace: boolean;
keyframes: boolean;
output?: string;
rejected: boolean;
stdin: boolean;
stdout: boolean;
variables: boolean;
safelist: Required<ComplexSafelist>;
blocklist: StringRegExpArray;
}
interface ResultPurge {
css: string;
file?: string;
rejected?: string[];
css: string;
file?: string;
rejected?: string[];
}
declare const defaultOptions: Options;
declare class ExtractorResultSets {
private undetermined;
private attrNames;
private attrValues;
private classes;
private ids;
private tags;
constructor(er: ExtractorResult);
merge(that: ExtractorResult | ExtractorResultSets): this;
hasAttrName(name: string): boolean;
private someAttrValue;
hasAttrPrefix(prefix: string): boolean;
hasAttrSuffix(suffix: string): boolean;
hasAttrSubstr(substr: string): boolean;
hasAttrValue(value: string): boolean;
hasClass(name: string): boolean;
hasId(id: string): boolean;
hasTag(tag: string): boolean;
private undetermined;
private attrNames;
private attrValues;
private classes;
private ids;
private tags;
constructor(er: ExtractorResult);
merge(that: ExtractorResult | ExtractorResultSets): this;
hasAttrName(name: string): boolean;
private someAttrValue;
hasAttrPrefix(prefix: string): boolean;
hasAttrSuffix(suffix: string): boolean;
hasAttrSubstr(substr: string): boolean;
hasAttrValue(value: string): boolean;
hasClass(name: string): boolean;
hasId(id: string): boolean;
hasTag(tag: string): boolean;
}
declare function standardizeSafelist(userDefinedSafelist?: UserDefinedSafelist): Required<ComplexSafelist>;
declare function standardizeSafelist(
userDefinedSafelist?: UserDefinedSafelist
): Required<ComplexSafelist>;
/**

@@ -101,181 +103,201 @@ * Load the configuration file from the path

*/
declare function mergeExtractorSelectors(...extractors: (ExtractorResultDetailed | ExtractorResultSets)[]): ExtractorResultSets;
declare function mergeExtractorSelectors(
...extractors: (ExtractorResultDetailed | ExtractorResultSets)[]
): ExtractorResultSets;
declare class PurgeCSS {
private ignore;
private atRules;
private usedAnimations;
private usedFontFaces;
selectorsRemoved: Set<string>;
private variablesStructure;
options: Options;
private collectDeclarationsData;
/**
* Get the extractor corresponding to the extension file
* @param filename Name of the file
* @param extractors Array of extractors definition
*/
/**
* Get the extractor corresponding to the extension file
* @param filename Name of the file
* @param extractors Array of extractors definition
*/
private getFileExtractor;
/**
* Extract the selectors present in the files using a purgecss extractor
* @param files Array of files path or glob pattern
* @param extractors Array of extractors
*/
/**
* Extract the selectors present in the files using a purgecss extractor
* @param files Array of files path or glob pattern
* @param extractors Array of extractors
*/
extractSelectorsFromFiles(files: string[], extractors: Extractors[]): Promise<ExtractorResultSets>;
/**
* Extract the selectors present in the passed string using a PurgeCSS extractor
* @param content Array of content
* @param extractors Array of extractors
*/
/**
* Extract the selectors present in the passed string using a PurgeCSS extractor
* @param content Array of content
* @param extractors Array of extractors
*/
extractSelectorsFromString(content: RawContent[], extractors: Extractors[]): Promise<ExtractorResultSets>;
/**
* Evaluate at-rule and register it for future reference
* @param node node of postcss AST
*/
/**
* Evaluate at-rule and register it for future reference
* @param node node of postcss AST
*/
private evaluateAtRule;
/**
* Evaluate css selector and decide if it should be removed or not
* @param node node of postcss AST
* @param selectors selectors used in content files
*/
/**
* Evaluate css selector and decide if it should be removed or not
* @param node node of postcss AST
* @param selectors selectors used in content files
*/
private evaluateRule;
/**
* Get the purged version of the css based on the files
* @param cssOptions css options, files or raw strings
* @param selectors set of extracted css selectors
*/
/**
* Get the purged version of the css based on the files
* @param cssOptions css options, files or raw strings
* @param selectors set of extracted css selectors
*/
getPurgedCSS(cssOptions: Array<string | RawCSS>, selectors: ExtractorResultSets): Promise<ResultPurge[]>;
/**
* Check if the keyframe is safelisted with the option safelist keyframes
* @param keyframesName name of the keyframe animation
*/
/**
* Check if the keyframe is safelisted with the option safelist keyframes
* @param keyframesName name of the keyframe animation
*/
private isKeyframesSafelisted;
/**
* Check if the selector is blocklisted with the option blocklist
* @param selector css selector
*/
/**
* Check if the selector is blocklisted with the option blocklist
* @param selector css selector
*/
private isSelectorBlocklisted;
/**
* Check if the selector is safelisted with the option safelist standard
* @param selector css selector
*/
/**
* Check if the selector is safelisted with the option safelist standard
* @param selector css selector
*/
private isSelectorSafelisted;
/**
* Check if the selector is safelisted with the option safelist deep
* @param selector selector
*/
/**
* Check if the selector is safelisted with the option safelist deep
* @param selector selector
*/
private isSelectorSafelistedDeep;
/**
* Check if the selector is safelisted with the option safelist greedy
* @param selector selector
*/
/**
* Check if the selector is safelisted with the option safelist greedy
* @param selector selector
*/
private isSelectorSafelistedGreedy;
/**
* Remove unused css
* @param userOptions PurgeCSS options
*/
/**
* Remove unused css
* @param userOptions PurgeCSS options
*/
purge(userOptions: UserDefinedOptions | string | undefined): Promise<ResultPurge[]>;
/**
* Remove unused CSS variables
*/
/**
* Remove unused CSS variables
*/
removeUnusedCSSVariables(): void;
/**
* Remove unused font-faces
*/
/**
* Remove unused font-faces
*/
removeUnusedFontFaces(): void;
/**
* Remove unused keyframes
*/
/**
* Remove unused keyframes
*/
removeUnusedKeyframes(): void;
/**
* Transform a selector node into a string
*/
/**
* Transform a selector node into a string
*/
private getSelectorValue;
/**
* Determine if the selector should be kept, based on the selectors found in the files
* @param selector set of css selectors found in the content files or string
* @param selectorsFromExtractor selectors in the css rule
*/
/**
* Determine if the selector should be kept, based on the selectors found in the files
* @param selector set of css selectors found in the content files or string
* @param selectorsFromExtractor selectors in the css rule
*/
private shouldKeepSelector;
/**
* Walk through the CSS AST and remove unused CSS
* @param root root node of the postcss AST
* @param selectors selectors used in content files
*/
/**
* Walk through the CSS AST and remove unused CSS
* @param root root node of the postcss AST
* @param selectors selectors used in content files
*/
walkThroughCSS(root: postcss.Root, selectors: ExtractorResultSets): void;
private ignore;
private atRules;
private usedAnimations;
private usedFontFaces;
selectorsRemoved: Set<string>;
private variablesStructure;
options: Options;
private collectDeclarationsData;
/**
* Get the extractor corresponding to the extension file
* @param filename Name of the file
* @param extractors Array of extractors definition
*/
/**
* Get the extractor corresponding to the extension file
* @param filename Name of the file
* @param extractors Array of extractors definition
*/
private getFileExtractor;
/**
* Extract the selectors present in the files using a purgecss extractor
* @param files Array of files path or glob pattern
* @param extractors Array of extractors
*/
/**
* Extract the selectors present in the files using a purgecss extractor
* @param files Array of files path or glob pattern
* @param extractors Array of extractors
*/
extractSelectorsFromFiles(
files: string[],
extractors: Extractors[]
): Promise<ExtractorResultSets>;
/**
* Extract the selectors present in the passed string using a PurgeCSS extractor
* @param content Array of content
* @param extractors Array of extractors
*/
/**
* Extract the selectors present in the passed string using a PurgeCSS extractor
* @param content Array of content
* @param extractors Array of extractors
*/
extractSelectorsFromString(
content: RawContent[],
extractors: Extractors[]
): Promise<ExtractorResultSets>;
/**
* Evaluate at-rule and register it for future reference
* @param node node of postcss AST
*/
/**
* Evaluate at-rule and register it for future reference
* @param node node of postcss AST
*/
private evaluateAtRule;
/**
* Evaluate css selector and decide if it should be removed or not
* @param node node of postcss AST
* @param selectors selectors used in content files
*/
/**
* Evaluate css selector and decide if it should be removed or not
* @param node node of postcss AST
* @param selectors selectors used in content files
*/
private evaluateRule;
/**
* Get the purged version of the css based on the files
* @param cssOptions css options, files or raw strings
* @param selectors set of extracted css selectors
*/
/**
* Get the purged version of the css based on the files
* @param cssOptions css options, files or raw strings
* @param selectors set of extracted css selectors
*/
getPurgedCSS(
cssOptions: Array<string | RawCSS>,
selectors: ExtractorResultSets
): Promise<ResultPurge[]>;
/**
* Check if the keyframe is safelisted with the option safelist keyframes
* @param keyframesName name of the keyframe animation
*/
/**
* Check if the keyframe is safelisted with the option safelist keyframes
* @param keyframesName name of the keyframe animation
*/
private isKeyframesSafelisted;
/**
* Check if the selector is blocklisted with the option blocklist
* @param selector css selector
*/
/**
* Check if the selector is blocklisted with the option blocklist
* @param selector css selector
*/
private isSelectorBlocklisted;
/**
* Check if the selector is safelisted with the option safelist standard
* @param selector css selector
*/
/**
* Check if the selector is safelisted with the option safelist standard
* @param selector css selector
*/
private isSelectorSafelisted;
/**
* Check if the selector is safelisted with the option safelist deep
* @param selector selector
*/
/**
* Check if the selector is safelisted with the option safelist deep
* @param selector selector
*/
private isSelectorSafelistedDeep;
/**
* Check if the selector is safelisted with the option safelist greedy
* @param selector selector
*/
/**
* Check if the selector is safelisted with the option safelist greedy
* @param selector selector
*/
private isSelectorSafelistedGreedy;
/**
* Remove unused css
* @param userOptions PurgeCSS options
*/
/**
* Remove unused css
* @param userOptions PurgeCSS options
*/
purge(
userOptions: UserDefinedOptions | string | undefined
): Promise<ResultPurge[]>;
/**
* Remove unused CSS variables
*/
/**
* Remove unused CSS variables
*/
removeUnusedCSSVariables(): void;
/**
* Remove unused font-faces
*/
/**
* Remove unused font-faces
*/
removeUnusedFontFaces(): void;
/**
* Remove unused keyframes
*/
/**
* Remove unused keyframes
*/
removeUnusedKeyframes(): void;
/**
* Transform a selector node into a string
*/
/**
* Transform a selector node into a string
*/
private getSelectorValue;
/**
* Determine if the selector should be kept, based on the selectors found in the files
* @param selector set of css selectors found in the content files or string
* @param selectorsFromExtractor selectors in the css rule
*/
/**
* Determine if the selector should be kept, based on the selectors found in the files
* @param selector set of css selectors found in the content files or string
* @param selectorsFromExtractor selectors in the css rule
*/
private shouldKeepSelector;
/**
* Walk through the CSS AST and remove unused CSS
* @param root root node of the postcss AST
* @param selectors selectors used in content files
*/
/**
* Walk through the CSS AST and remove unused CSS
* @param root root node of the postcss AST
* @param selectors selectors used in content files
*/
walkThroughCSS(root: postcss.Root, selectors: ExtractorResultSets): void;
}
export { PurgeCSS as default, PurgeCSS, defaultOptions, standardizeSafelist, setOptions, mergeExtractorSelectors };
export {
PurgeCSS as default,
PurgeCSS,
defaultOptions,
standardizeSafelist,
setOptions,
mergeExtractorSelectors,
};
import * as postcss from "postcss";
interface RawContent<T = string> {
extension: string;
raw: T;
extension: string;
raw: T;
}
interface RawCSS {
raw: string;
raw: string;
}
interface ExtractorResultDetailed {
attributes: {
names: string[];
values: string[];
};
classes: string[];
ids: string[];
tags: string[];
undetermined: string[];
attributes: {
names: string[];
values: string[];
};
classes: string[];
ids: string[];
tags: string[];
undetermined: string[];
}

@@ -22,70 +22,72 @@ type ExtractorResult = ExtractorResultDetailed | string[];

interface Extractors {
extensions: string[];
extractor: ExtractorFunction;
extensions: string[];
extractor: ExtractorFunction;
}
type StringRegExpArray = Array<RegExp | string>;
type ComplexSafelist = {
standard?: StringRegExpArray;
deep?: RegExp[];
greedy?: RegExp[];
variables?: StringRegExpArray;
keyframes?: StringRegExpArray;
standard?: StringRegExpArray;
deep?: RegExp[];
greedy?: RegExp[];
variables?: StringRegExpArray;
keyframes?: StringRegExpArray;
};
type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
interface UserDefinedOptions {
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor?: ExtractorFunction;
extractors?: Array<Extractors>;
fontFace?: boolean;
keyframes?: boolean;
output?: string;
rejected?: boolean;
stdin?: boolean;
stdout?: boolean;
variables?: boolean;
safelist?: UserDefinedSafelist;
blocklist?: StringRegExpArray;
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor?: ExtractorFunction;
extractors?: Array<Extractors>;
fontFace?: boolean;
keyframes?: boolean;
output?: string;
rejected?: boolean;
stdin?: boolean;
stdout?: boolean;
variables?: boolean;
safelist?: UserDefinedSafelist;
blocklist?: StringRegExpArray;
}
interface Options {
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor: ExtractorFunction;
extractors: Array<Extractors>;
fontFace: boolean;
keyframes: boolean;
output?: string;
rejected: boolean;
stdin: boolean;
stdout: boolean;
variables: boolean;
safelist: Required<ComplexSafelist>;
blocklist: StringRegExpArray;
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor: ExtractorFunction;
extractors: Array<Extractors>;
fontFace: boolean;
keyframes: boolean;
output?: string;
rejected: boolean;
stdin: boolean;
stdout: boolean;
variables: boolean;
safelist: Required<ComplexSafelist>;
blocklist: StringRegExpArray;
}
interface ResultPurge {
css: string;
file?: string;
rejected?: string[];
css: string;
file?: string;
rejected?: string[];
}
declare const defaultOptions: Options;
declare class ExtractorResultSets {
private undetermined;
private attrNames;
private attrValues;
private classes;
private ids;
private tags;
constructor(er: ExtractorResult);
merge(that: ExtractorResult | ExtractorResultSets): this;
hasAttrName(name: string): boolean;
private someAttrValue;
hasAttrPrefix(prefix: string): boolean;
hasAttrSuffix(suffix: string): boolean;
hasAttrSubstr(substr: string): boolean;
hasAttrValue(value: string): boolean;
hasClass(name: string): boolean;
hasId(id: string): boolean;
hasTag(tag: string): boolean;
private undetermined;
private attrNames;
private attrValues;
private classes;
private ids;
private tags;
constructor(er: ExtractorResult);
merge(that: ExtractorResult | ExtractorResultSets): this;
hasAttrName(name: string): boolean;
private someAttrValue;
hasAttrPrefix(prefix: string): boolean;
hasAttrSuffix(suffix: string): boolean;
hasAttrSubstr(substr: string): boolean;
hasAttrValue(value: string): boolean;
hasClass(name: string): boolean;
hasId(id: string): boolean;
hasTag(tag: string): boolean;
}
declare function standardizeSafelist(userDefinedSafelist?: UserDefinedSafelist): Required<ComplexSafelist>;
declare function standardizeSafelist(
userDefinedSafelist?: UserDefinedSafelist
): Required<ComplexSafelist>;
/**

@@ -101,181 +103,201 @@ * Load the configuration file from the path

*/
declare function mergeExtractorSelectors(...extractors: (ExtractorResultDetailed | ExtractorResultSets)[]): ExtractorResultSets;
declare function mergeExtractorSelectors(
...extractors: (ExtractorResultDetailed | ExtractorResultSets)[]
): ExtractorResultSets;
declare class PurgeCSS {
private ignore;
private atRules;
private usedAnimations;
private usedFontFaces;
selectorsRemoved: Set<string>;
private variablesStructure;
options: Options;
private collectDeclarationsData;
/**
* Get the extractor corresponding to the extension file
* @param filename Name of the file
* @param extractors Array of extractors definition
*/
/**
* Get the extractor corresponding to the extension file
* @param filename Name of the file
* @param extractors Array of extractors definition
*/
private getFileExtractor;
/**
* Extract the selectors present in the files using a purgecss extractor
* @param files Array of files path or glob pattern
* @param extractors Array of extractors
*/
/**
* Extract the selectors present in the files using a purgecss extractor
* @param files Array of files path or glob pattern
* @param extractors Array of extractors
*/
extractSelectorsFromFiles(files: string[], extractors: Extractors[]): Promise<ExtractorResultSets>;
/**
* Extract the selectors present in the passed string using a PurgeCSS extractor
* @param content Array of content
* @param extractors Array of extractors
*/
/**
* Extract the selectors present in the passed string using a PurgeCSS extractor
* @param content Array of content
* @param extractors Array of extractors
*/
extractSelectorsFromString(content: RawContent[], extractors: Extractors[]): Promise<ExtractorResultSets>;
/**
* Evaluate at-rule and register it for future reference
* @param node node of postcss AST
*/
/**
* Evaluate at-rule and register it for future reference
* @param node node of postcss AST
*/
private evaluateAtRule;
/**
* Evaluate css selector and decide if it should be removed or not
* @param node node of postcss AST
* @param selectors selectors used in content files
*/
/**
* Evaluate css selector and decide if it should be removed or not
* @param node node of postcss AST
* @param selectors selectors used in content files
*/
private evaluateRule;
/**
* Get the purged version of the css based on the files
* @param cssOptions css options, files or raw strings
* @param selectors set of extracted css selectors
*/
/**
* Get the purged version of the css based on the files
* @param cssOptions css options, files or raw strings
* @param selectors set of extracted css selectors
*/
getPurgedCSS(cssOptions: Array<string | RawCSS>, selectors: ExtractorResultSets): Promise<ResultPurge[]>;
/**
* Check if the keyframe is safelisted with the option safelist keyframes
* @param keyframesName name of the keyframe animation
*/
/**
* Check if the keyframe is safelisted with the option safelist keyframes
* @param keyframesName name of the keyframe animation
*/
private isKeyframesSafelisted;
/**
* Check if the selector is blocklisted with the option blocklist
* @param selector css selector
*/
/**
* Check if the selector is blocklisted with the option blocklist
* @param selector css selector
*/
private isSelectorBlocklisted;
/**
* Check if the selector is safelisted with the option safelist standard
* @param selector css selector
*/
/**
* Check if the selector is safelisted with the option safelist standard
* @param selector css selector
*/
private isSelectorSafelisted;
/**
* Check if the selector is safelisted with the option safelist deep
* @param selector selector
*/
/**
* Check if the selector is safelisted with the option safelist deep
* @param selector selector
*/
private isSelectorSafelistedDeep;
/**
* Check if the selector is safelisted with the option safelist greedy
* @param selector selector
*/
/**
* Check if the selector is safelisted with the option safelist greedy
* @param selector selector
*/
private isSelectorSafelistedGreedy;
/**
* Remove unused css
* @param userOptions PurgeCSS options
*/
/**
* Remove unused css
* @param userOptions PurgeCSS options
*/
purge(userOptions: UserDefinedOptions | string | undefined): Promise<ResultPurge[]>;
/**
* Remove unused CSS variables
*/
/**
* Remove unused CSS variables
*/
removeUnusedCSSVariables(): void;
/**
* Remove unused font-faces
*/
/**
* Remove unused font-faces
*/
removeUnusedFontFaces(): void;
/**
* Remove unused keyframes
*/
/**
* Remove unused keyframes
*/
removeUnusedKeyframes(): void;
/**
* Transform a selector node into a string
*/
/**
* Transform a selector node into a string
*/
private getSelectorValue;
/**
* Determine if the selector should be kept, based on the selectors found in the files
* @param selector set of css selectors found in the content files or string
* @param selectorsFromExtractor selectors in the css rule
*/
/**
* Determine if the selector should be kept, based on the selectors found in the files
* @param selector set of css selectors found in the content files or string
* @param selectorsFromExtractor selectors in the css rule
*/
private shouldKeepSelector;
/**
* Walk through the CSS AST and remove unused CSS
* @param root root node of the postcss AST
* @param selectors selectors used in content files
*/
/**
* Walk through the CSS AST and remove unused CSS
* @param root root node of the postcss AST
* @param selectors selectors used in content files
*/
walkThroughCSS(root: postcss.Root, selectors: ExtractorResultSets): void;
private ignore;
private atRules;
private usedAnimations;
private usedFontFaces;
selectorsRemoved: Set<string>;
private variablesStructure;
options: Options;
private collectDeclarationsData;
/**
* Get the extractor corresponding to the extension file
* @param filename Name of the file
* @param extractors Array of extractors definition
*/
/**
* Get the extractor corresponding to the extension file
* @param filename Name of the file
* @param extractors Array of extractors definition
*/
private getFileExtractor;
/**
* Extract the selectors present in the files using a purgecss extractor
* @param files Array of files path or glob pattern
* @param extractors Array of extractors
*/
/**
* Extract the selectors present in the files using a purgecss extractor
* @param files Array of files path or glob pattern
* @param extractors Array of extractors
*/
extractSelectorsFromFiles(
files: string[],
extractors: Extractors[]
): Promise<ExtractorResultSets>;
/**
* Extract the selectors present in the passed string using a PurgeCSS extractor
* @param content Array of content
* @param extractors Array of extractors
*/
/**
* Extract the selectors present in the passed string using a PurgeCSS extractor
* @param content Array of content
* @param extractors Array of extractors
*/
extractSelectorsFromString(
content: RawContent[],
extractors: Extractors[]
): Promise<ExtractorResultSets>;
/**
* Evaluate at-rule and register it for future reference
* @param node node of postcss AST
*/
/**
* Evaluate at-rule and register it for future reference
* @param node node of postcss AST
*/
private evaluateAtRule;
/**
* Evaluate css selector and decide if it should be removed or not
* @param node node of postcss AST
* @param selectors selectors used in content files
*/
/**
* Evaluate css selector and decide if it should be removed or not
* @param node node of postcss AST
* @param selectors selectors used in content files
*/
private evaluateRule;
/**
* Get the purged version of the css based on the files
* @param cssOptions css options, files or raw strings
* @param selectors set of extracted css selectors
*/
/**
* Get the purged version of the css based on the files
* @param cssOptions css options, files or raw strings
* @param selectors set of extracted css selectors
*/
getPurgedCSS(
cssOptions: Array<string | RawCSS>,
selectors: ExtractorResultSets
): Promise<ResultPurge[]>;
/**
* Check if the keyframe is safelisted with the option safelist keyframes
* @param keyframesName name of the keyframe animation
*/
/**
* Check if the keyframe is safelisted with the option safelist keyframes
* @param keyframesName name of the keyframe animation
*/
private isKeyframesSafelisted;
/**
* Check if the selector is blocklisted with the option blocklist
* @param selector css selector
*/
/**
* Check if the selector is blocklisted with the option blocklist
* @param selector css selector
*/
private isSelectorBlocklisted;
/**
* Check if the selector is safelisted with the option safelist standard
* @param selector css selector
*/
/**
* Check if the selector is safelisted with the option safelist standard
* @param selector css selector
*/
private isSelectorSafelisted;
/**
* Check if the selector is safelisted with the option safelist deep
* @param selector selector
*/
/**
* Check if the selector is safelisted with the option safelist deep
* @param selector selector
*/
private isSelectorSafelistedDeep;
/**
* Check if the selector is safelisted with the option safelist greedy
* @param selector selector
*/
/**
* Check if the selector is safelisted with the option safelist greedy
* @param selector selector
*/
private isSelectorSafelistedGreedy;
/**
* Remove unused css
* @param userOptions PurgeCSS options
*/
/**
* Remove unused css
* @param userOptions PurgeCSS options
*/
purge(
userOptions: UserDefinedOptions | string | undefined
): Promise<ResultPurge[]>;
/**
* Remove unused CSS variables
*/
/**
* Remove unused CSS variables
*/
removeUnusedCSSVariables(): void;
/**
* Remove unused font-faces
*/
/**
* Remove unused font-faces
*/
removeUnusedFontFaces(): void;
/**
* Remove unused keyframes
*/
/**
* Remove unused keyframes
*/
removeUnusedKeyframes(): void;
/**
* Transform a selector node into a string
*/
/**
* Transform a selector node into a string
*/
private getSelectorValue;
/**
* Determine if the selector should be kept, based on the selectors found in the files
* @param selector set of css selectors found in the content files or string
* @param selectorsFromExtractor selectors in the css rule
*/
/**
* Determine if the selector should be kept, based on the selectors found in the files
* @param selector set of css selectors found in the content files or string
* @param selectorsFromExtractor selectors in the css rule
*/
private shouldKeepSelector;
/**
* Walk through the CSS AST and remove unused CSS
* @param root root node of the postcss AST
* @param selectors selectors used in content files
*/
/**
* Walk through the CSS AST and remove unused CSS
* @param root root node of the postcss AST
* @param selectors selectors used in content files
*/
walkThroughCSS(root: postcss.Root, selectors: ExtractorResultSets): void;
}
export { PurgeCSS as default, PurgeCSS, defaultOptions, standardizeSafelist, setOptions, mergeExtractorSelectors };
export {
PurgeCSS as default,
PurgeCSS,
defaultOptions,
standardizeSafelist,
setOptions,
mergeExtractorSelectors,
};

@@ -1,1 +0,1 @@

import{parse as e}from"postcss";import t from"postcss-selector-parser";import{access as s,readFile as r,constants as i}from"fs";import{promisify as a}from"util";import n from"glob";import o from"path";const c={css:[],content:[],defaultExtractor:e=>e.match(/[A-Za-z0-9_-]+/g)||[],extractors:[],fontFace:!1,keyframes:!1,rejected:!1,stdin:!1,stdout:!1,variables:!1,safelist:{standard:[],deep:[],greedy:[],variables:[],keyframes:[]},blocklist:[]},l=["*","::-webkit-scrollbar","::selection",":root","::before","::after"];class u{constructor(e){this.nodes=[],this.isUsed=!1,this.value=e}}class h{constructor(){this.nodes=new Map,this.usedVariables=new Set,this.safelist=[]}addVariable(e){const{prop:t}=e;if(!this.nodes.has(t)){const s=new u(e);this.nodes.set(t,s)}}addVariableUsage(e,t){const{prop:s}=e,r=this.nodes.get(s);for(const e of t){const t=e[1];if(this.nodes.has(t)){const e=this.nodes.get(t);null==r||r.nodes.push(e)}}}addVariableUsageInProperties(e){for(const t of e){const e=t[1];this.usedVariables.add(e)}}setAsUsed(e){const t=[this.nodes.get(e)];for(;0!==t.length;){const e=t.pop();e&&!e.isUsed&&(e.isUsed=!0,t.push(...e.nodes))}}removeUnused(){for(const e of this.usedVariables)this.setAsUsed(e);for(const[e,t]of this.nodes)t.isUsed||this.isVariablesSafelisted(e)||t.value.remove()}isVariablesSafelisted(e){return this.safelist.some((t=>"string"==typeof t?t===e:t.test(e)))}}function d(e,t){t&&t.forEach(e.add,e)}class f{constructor(e){this.undetermined=new Set,this.attrNames=new Set,this.attrValues=new Set,this.classes=new Set,this.ids=new Set,this.tags=new Set,this.merge(e)}merge(e){return Array.isArray(e)?d(this.undetermined,e):e instanceof f?(d(this.undetermined,e.undetermined),d(this.attrNames,e.attrNames),d(this.attrValues,e.attrValues),d(this.classes,e.classes),d(this.ids,e.ids),d(this.tags,e.tags)):(d(this.undetermined,e.undetermined),e.attributes&&(d(this.attrNames,e.attributes.names),d(this.attrValues,e.attributes.values)),d(this.classes,e.classes),d(this.ids,e.ids),d(this.tags,e.tags)),this}hasAttrName(e){return this.attrNames.has(e)||this.undetermined.has(e)}someAttrValue(e){for(const t of this.attrValues)if(e(t))return!0;for(const t of this.undetermined)if(e(t))return!0;return!1}hasAttrPrefix(e){return this.someAttrValue((t=>t.startsWith(e)))}hasAttrSuffix(e){return this.someAttrValue((t=>t.endsWith(e)))}hasAttrSubstr(e){return this.someAttrValue((t=>t.includes(e)))}hasAttrValue(e){return this.attrValues.has(e)||this.undetermined.has(e)}hasClass(e){return this.classes.has(e)||this.undetermined.has(e)}hasId(e){return this.ids.has(e)||this.undetermined.has(e)}hasTag(e){return this.tags.has(e)||this.undetermined.has(e)}}const m={access:a(s),readFile:a(r)};function p(e=[]){return Array.isArray(e)?{...c.safelist,standard:e}:{...c.safelist,...e}}async function g(e="purgecss.config.js"){let t;try{const s=o.join(process.cwd(),e);t=await import(s)}catch(e){throw new Error("Error loading the config file "+e.message)}return{...c,...t,safelist:p(t.safelist)}}async function v(e,t){return new f(await t(e))}function y(e,t){switch(t){case"next":return e.text.includes("purgecss ignore");case"start":return e.text.includes("purgecss start ignore");case"end":return e.text.includes("purgecss end ignore")}}function S(...e){const t=new f([]);return e.forEach(t.merge,t),t}function b(e){return e.replace(/(^["'])|(["']$)/g,"")}function w(e,t){if(!t.hasAttrName(e.attribute))return!1;if(void 0===e.value)return!0;switch(e.operator){case"$=":return t.hasAttrSuffix(e.value);case"~=":case"*=":return t.hasAttrSubstr(e.value);case"=":return t.hasAttrValue(e.value);case"|=":case"^=":return t.hasAttrPrefix(e.value);default:return!0}}function F(e,t){return t.hasId(e.value)}function A(e,t){return t.hasTag(e.value)}function V(e){return"atrule"===(null==e?void 0:e.type)}function x(e){return"rule"===(null==e?void 0:e.type)}class k{constructor(){this.ignore=!1,this.atRules={fontFace:[],keyframes:[]},this.usedAnimations=new Set,this.usedFontFaces=new Set,this.selectorsRemoved=new Set,this.variablesStructure=new h,this.options=c}collectDeclarationsData(e){const{prop:t,value:s}=e;if(this.options.variables){const r=function(e,t){const s=[];return e.replace(t,(function(){const t=arguments,r=Array.prototype.slice.call(t,0,-2);return r.input=t[t.length-1],r.index=t[t.length-2],s.push(r),e})),s}(s,/var\((.+?)[,)]/g);t.startsWith("--")?(this.variablesStructure.addVariable(e),r.length>0&&this.variablesStructure.addVariableUsage(e,r)):r.length>0&&this.variablesStructure.addVariableUsageInProperties(r)}if(!this.options.keyframes||"animation"!==t&&"animation-name"!==t)if(this.options.fontFace){if("font-family"===t)for(const e of s.split(",")){const t=b(e.trim());this.usedFontFaces.add(t)}}else;else for(const e of s.split(/[\s,]+/))this.usedAnimations.add(e)}getFileExtractor(e,t){const s=t.find((t=>t.extensions.find((t=>e.endsWith(t)))));return void 0===s?this.options.defaultExtractor:s.extractor}async extractSelectorsFromFiles(e,t){const s=new f([]);for(const r of e){let e=[];try{await m.access(r,i.F_OK),e.push(r)}catch(t){e=n.sync(r,{nodir:!0})}for(const r of e){const e=await m.readFile(r,"utf-8"),i=this.getFileExtractor(r,t),a=await v(e,i);s.merge(a)}}return s}async extractSelectorsFromString(e,t){const s=new f([]);for(const{raw:r,extension:i}of e){const e=this.getFileExtractor("."+i,t),a=await v(r,e);s.merge(a)}return s}evaluateAtRule(e){if(this.options.keyframes&&e.name.endsWith("keyframes"))this.atRules.keyframes.push(e);else if(this.options.fontFace&&"font-face"===e.name&&e.nodes)for(const t of e.nodes)"decl"===t.type&&"font-family"===t.prop&&this.atRules.fontFace.push({name:b(t.value),node:e})}async evaluateRule(e,s){if(this.ignore)return;const r=e.prev();if(function(e){return"comment"===(null==e?void 0:e.type)}(r)&&y(r,"next"))return void r.remove();if(e.parent&&V(e.parent)&&"keyframes"===e.parent.name)return;if(!x(e))return;if(function(e){let t=!1;return e.walkComments((e=>{e&&"comment"===e.type&&e.text.includes("purgecss ignore current")&&(t=!0,e.remove())})),t}(e))return;let i=!0;if(e.selector=t((e=>{e.walk((e=>{"selector"===e.type&&(i=this.shouldKeepSelector(e,s),i||(this.options.rejected&&this.selectorsRemoved.add(e.toString()),e.remove()))}))})).processSync(e.selector),i&&void 0!==e.nodes)for(const t of e.nodes)"decl"===t.type&&this.collectDeclarationsData(t);const a=e.parent;e.selector||e.remove(),function(e){return!!(x(e)&&!e.selector||(null==e?void 0:e.nodes)&&!e.nodes.length||V(e)&&(!e.nodes&&!e.params||!e.params&&e.nodes&&!e.nodes.length))}(a)&&(null==a||a.remove())}async getPurgedCSS(t,s){const r=[],i=[];for(const e of t)"string"==typeof e?i.push(...n.sync(e,{nodir:!0})):i.push(e);for(const t of i){const i="string"==typeof t?this.options.stdin?t:await m.readFile(t,"utf-8"):t.raw,a=e(i);this.walkThroughCSS(a,s),this.options.fontFace&&this.removeUnusedFontFaces(),this.options.keyframes&&this.removeUnusedKeyframes(),this.options.variables&&this.removeUnusedCSSVariables();const n={css:a.toString(),file:"string"==typeof t?t:void 0};"string"==typeof t&&(n.file=t),this.options.rejected&&(n.rejected=Array.from(this.selectorsRemoved),this.selectorsRemoved.clear()),r.push(n)}return r}isKeyframesSafelisted(e){return this.options.safelist.keyframes.some((t=>"string"==typeof t?t===e:t.test(e)))}isSelectorBlocklisted(e){return this.options.blocklist.some((t=>"string"==typeof t?t===e:t.test(e)))}isSelectorSafelisted(e){const t=this.options.safelist.standard.some((t=>"string"==typeof t?t===e:t.test(e)));return l.includes(e)||t}isSelectorSafelistedDeep(e){return this.options.safelist.deep.some((t=>t.test(e)))}isSelectorSafelistedGreedy(e){return this.options.safelist.greedy.some((t=>t.test(e)))}async purge(e){this.options="object"!=typeof e?await g(e):{...c,...e,safelist:p(e.safelist)};const{content:t,css:s,extractors:r,safelist:i}=this.options;this.options.variables&&(this.variablesStructure.safelist=i.variables||[]);const a=t.filter((e=>"string"==typeof e)),n=t.filter((e=>"object"==typeof e)),o=await this.extractSelectorsFromFiles(a,r),l=await this.extractSelectorsFromString(n,r);return this.getPurgedCSS(s,S(o,l))}removeUnusedCSSVariables(){this.variablesStructure.removeUnused()}removeUnusedFontFaces(){for(const{name:e,node:t}of this.atRules.fontFace)this.usedFontFaces.has(e)||t.remove()}removeUnusedKeyframes(){for(const e of this.atRules.keyframes)this.usedAnimations.has(e.params)||this.isKeyframesSafelisted(e.params)||e.remove()}getSelectorValue(e){return"attribute"===e.type&&e.attribute||e.value}shouldKeepSelector(e,t){if(function(e){return e.parent&&"pseudo"===e.parent.type&&e.parent.value.startsWith(":")||!1}(e))return!0;if(this.options.safelist.greedy.length>0){if(e.nodes.map(this.getSelectorValue).some((e=>e&&this.isSelectorSafelistedGreedy(e))))return!0}let s=!1;for(const i of e.nodes){const e=this.getSelectorValue(i);if(e&&this.isSelectorSafelistedDeep(e))return!0;if(e&&(l.includes(e)||this.isSelectorSafelisted(e)))s=!0;else{if(e&&this.isSelectorBlocklisted(e))return!1;switch(i.type){case"attribute":s=!!["value","checked","selected","open"].includes(i.attribute)||w(i,t);break;case"class":r=i,s=t.hasClass(r.value);break;case"id":s=F(i,t);break;case"tag":s=A(i,t);break;default:continue}if(!s)return!1}}var r;return s}walkThroughCSS(e,t){e.walk((e=>"rule"===e.type?this.evaluateRule(e,t):"atrule"===e.type?this.evaluateAtRule(e):void("comment"===e.type&&(y(e,"start")?(this.ignore=!0,e.remove()):y(e,"end")&&(this.ignore=!1,e.remove())))))}}export default k;export{k as PurgeCSS,c as defaultOptions,S as mergeExtractorSelectors,g as setOptions,p as standardizeSafelist};
import{parse as e}from"postcss";import t from"postcss-selector-parser";import{access as s,readFile as r,constants as i}from"fs";import{promisify as a}from"util";import n from"glob";import o from"path";const c={css:[],content:[],defaultExtractor:e=>e.match(/[A-Za-z0-9_-]+/g)||[],extractors:[],fontFace:!1,keyframes:!1,rejected:!1,stdin:!1,stdout:!1,variables:!1,safelist:{standard:[],deep:[],greedy:[],variables:[],keyframes:[]},blocklist:[]},l=["*","::-webkit-scrollbar","::selection",":root","::before","::after"];class u{constructor(e){this.nodes=[],this.isUsed=!1,this.value=e}}class h{constructor(){this.nodes=new Map,this.usedVariables=new Set,this.safelist=[]}addVariable(e){const{prop:t}=e;if(!this.nodes.has(t)){const s=new u(e);this.nodes.set(t,s)}}addVariableUsage(e,t){const{prop:s}=e,r=this.nodes.get(s);for(const e of t){const t=e[1];if(this.nodes.has(t)){const e=this.nodes.get(t);null==r||r.nodes.push(e)}}}addVariableUsageInProperties(e){for(const t of e){const e=t[1];this.usedVariables.add(e)}}setAsUsed(e){const t=[this.nodes.get(e)];for(;0!==t.length;){const e=t.pop();e&&!e.isUsed&&(e.isUsed=!0,t.push(...e.nodes))}}removeUnused(){for(const e of this.usedVariables)this.setAsUsed(e);for(const[e,t]of this.nodes)t.isUsed||this.isVariablesSafelisted(e)||t.value.remove()}isVariablesSafelisted(e){return this.safelist.some((t=>"string"==typeof t?t===e:t.test(e)))}}function d(e,t){t&&t.forEach(e.add,e)}class f{constructor(e){this.undetermined=new Set,this.attrNames=new Set,this.attrValues=new Set,this.classes=new Set,this.ids=new Set,this.tags=new Set,this.merge(e)}merge(e){return Array.isArray(e)?d(this.undetermined,e):e instanceof f?(d(this.undetermined,e.undetermined),d(this.attrNames,e.attrNames),d(this.attrValues,e.attrValues),d(this.classes,e.classes),d(this.ids,e.ids),d(this.tags,e.tags)):(d(this.undetermined,e.undetermined),e.attributes&&(d(this.attrNames,e.attributes.names),d(this.attrValues,e.attributes.values)),d(this.classes,e.classes),d(this.ids,e.ids),d(this.tags,e.tags)),this}hasAttrName(e){return this.attrNames.has(e)||this.undetermined.has(e)}someAttrValue(e){for(const t of this.attrValues)if(e(t))return!0;for(const t of this.undetermined)if(e(t))return!0;return!1}hasAttrPrefix(e){return this.someAttrValue((t=>t.startsWith(e)))}hasAttrSuffix(e){return this.someAttrValue((t=>t.endsWith(e)))}hasAttrSubstr(e){return e.trim().split(" ").every((e=>this.someAttrValue((t=>t.includes(e)))))}hasAttrValue(e){return this.attrValues.has(e)||this.undetermined.has(e)}hasClass(e){return this.classes.has(e)||this.undetermined.has(e)}hasId(e){return this.ids.has(e)||this.undetermined.has(e)}hasTag(e){return this.tags.has(e)||this.undetermined.has(e)}}const m={access:a(s),readFile:a(r)};function p(e=[]){return Array.isArray(e)?{...c.safelist,standard:e}:{...c.safelist,...e}}async function g(e="purgecss.config.js"){let t;try{const s=o.join(process.cwd(),e);t=await import(s)}catch(e){throw new Error("Error loading the config file "+e.message)}return{...c,...t,safelist:p(t.safelist)}}async function v(e,t){return new f(await t(e))}function y(e,t){switch(t){case"next":return e.text.includes("purgecss ignore");case"start":return e.text.includes("purgecss start ignore");case"end":return e.text.includes("purgecss end ignore")}}function S(...e){const t=new f([]);return e.forEach(t.merge,t),t}function b(e){return e.replace(/(^["'])|(["']$)/g,"")}function w(e,t){if(!t.hasAttrName(e.attribute))return!1;if(void 0===e.value)return!0;switch(e.operator){case"$=":return t.hasAttrSuffix(e.value);case"~=":case"*=":return t.hasAttrSubstr(e.value);case"=":return t.hasAttrValue(e.value);case"|=":case"^=":return t.hasAttrPrefix(e.value);default:return!0}}function F(e,t){return t.hasId(e.value)}function A(e,t){return t.hasTag(e.value)}function V(e){return"atrule"===(null==e?void 0:e.type)}function x(e){return"rule"===(null==e?void 0:e.type)}class k{constructor(){this.ignore=!1,this.atRules={fontFace:[],keyframes:[]},this.usedAnimations=new Set,this.usedFontFaces=new Set,this.selectorsRemoved=new Set,this.variablesStructure=new h,this.options=c}collectDeclarationsData(e){const{prop:t,value:s}=e;if(this.options.variables){const r=function(e,t){const s=[];return e.replace(t,(function(){const t=arguments,r=Array.prototype.slice.call(t,0,-2);return r.input=t[t.length-1],r.index=t[t.length-2],s.push(r),e})),s}(s,/var\((.+?)[,)]/g);t.startsWith("--")?(this.variablesStructure.addVariable(e),r.length>0&&this.variablesStructure.addVariableUsage(e,r)):r.length>0&&this.variablesStructure.addVariableUsageInProperties(r)}if(!this.options.keyframes||"animation"!==t&&"animation-name"!==t)if(this.options.fontFace){if("font-family"===t)for(const e of s.split(",")){const t=b(e.trim());this.usedFontFaces.add(t)}}else;else for(const e of s.split(/[\s,]+/))this.usedAnimations.add(e)}getFileExtractor(e,t){const s=t.find((t=>t.extensions.find((t=>e.endsWith(t)))));return void 0===s?this.options.defaultExtractor:s.extractor}async extractSelectorsFromFiles(e,t){const s=new f([]);for(const r of e){let e=[];try{await m.access(r,i.F_OK),e.push(r)}catch(t){e=n.sync(r,{nodir:!0})}for(const r of e){const e=await m.readFile(r,"utf-8"),i=this.getFileExtractor(r,t),a=await v(e,i);s.merge(a)}}return s}async extractSelectorsFromString(e,t){const s=new f([]);for(const{raw:r,extension:i}of e){const e=this.getFileExtractor("."+i,t),a=await v(r,e);s.merge(a)}return s}evaluateAtRule(e){if(this.options.keyframes&&e.name.endsWith("keyframes"))this.atRules.keyframes.push(e);else if(this.options.fontFace&&"font-face"===e.name&&e.nodes)for(const t of e.nodes)"decl"===t.type&&"font-family"===t.prop&&this.atRules.fontFace.push({name:b(t.value),node:e})}async evaluateRule(e,s){if(this.ignore)return;const r=e.prev();if(function(e){return"comment"===(null==e?void 0:e.type)}(r)&&y(r,"next"))return void r.remove();if(e.parent&&V(e.parent)&&"keyframes"===e.parent.name)return;if(!x(e))return;if(function(e){let t=!1;return e.walkComments((e=>{e&&"comment"===e.type&&e.text.includes("purgecss ignore current")&&(t=!0,e.remove())})),t}(e))return;let i=!0;if(e.selector=t((e=>{e.walk((e=>{"selector"===e.type&&(i=this.shouldKeepSelector(e,s),i||(this.options.rejected&&this.selectorsRemoved.add(e.toString()),e.remove()))}))})).processSync(e.selector),i&&void 0!==e.nodes)for(const t of e.nodes)"decl"===t.type&&this.collectDeclarationsData(t);const a=e.parent;e.selector||e.remove(),function(e){return!!(x(e)&&!e.selector||(null==e?void 0:e.nodes)&&!e.nodes.length||V(e)&&(!e.nodes&&!e.params||!e.params&&e.nodes&&!e.nodes.length))}(a)&&(null==a||a.remove())}async getPurgedCSS(t,s){const r=[],i=[];for(const e of t)"string"==typeof e?i.push(...n.sync(e,{nodir:!0})):i.push(e);for(const t of i){const i="string"==typeof t?this.options.stdin?t:await m.readFile(t,"utf-8"):t.raw,a=e(i);this.walkThroughCSS(a,s),this.options.fontFace&&this.removeUnusedFontFaces(),this.options.keyframes&&this.removeUnusedKeyframes(),this.options.variables&&this.removeUnusedCSSVariables();const n={css:a.toString(),file:"string"==typeof t?t:void 0};"string"==typeof t&&(n.file=t),this.options.rejected&&(n.rejected=Array.from(this.selectorsRemoved),this.selectorsRemoved.clear()),r.push(n)}return r}isKeyframesSafelisted(e){return this.options.safelist.keyframes.some((t=>"string"==typeof t?t===e:t.test(e)))}isSelectorBlocklisted(e){return this.options.blocklist.some((t=>"string"==typeof t?t===e:t.test(e)))}isSelectorSafelisted(e){const t=this.options.safelist.standard.some((t=>"string"==typeof t?t===e:t.test(e)));return l.includes(e)||t}isSelectorSafelistedDeep(e){return this.options.safelist.deep.some((t=>t.test(e)))}isSelectorSafelistedGreedy(e){return this.options.safelist.greedy.some((t=>t.test(e)))}async purge(e){this.options="object"!=typeof e?await g(e):{...c,...e,safelist:p(e.safelist)};const{content:t,css:s,extractors:r,safelist:i}=this.options;this.options.variables&&(this.variablesStructure.safelist=i.variables||[]);const a=t.filter((e=>"string"==typeof e)),n=t.filter((e=>"object"==typeof e)),o=await this.extractSelectorsFromFiles(a,r),l=await this.extractSelectorsFromString(n,r);return this.getPurgedCSS(s,S(o,l))}removeUnusedCSSVariables(){this.variablesStructure.removeUnused()}removeUnusedFontFaces(){for(const{name:e,node:t}of this.atRules.fontFace)this.usedFontFaces.has(e)||t.remove()}removeUnusedKeyframes(){for(const e of this.atRules.keyframes)this.usedAnimations.has(e.params)||this.isKeyframesSafelisted(e.params)||e.remove()}getSelectorValue(e){return"attribute"===e.type&&e.attribute||e.value}shouldKeepSelector(e,t){if(function(e){return e.parent&&"pseudo"===e.parent.type&&e.parent.value.startsWith(":")||!1}(e))return!0;if(this.options.safelist.greedy.length>0){if(e.nodes.map(this.getSelectorValue).some((e=>e&&this.isSelectorSafelistedGreedy(e))))return!0}let s=!1;for(const i of e.nodes){const e=this.getSelectorValue(i);if(e&&this.isSelectorSafelistedDeep(e))return!0;if(e&&(l.includes(e)||this.isSelectorSafelisted(e)))s=!0;else{if(e&&this.isSelectorBlocklisted(e))return!1;switch(i.type){case"attribute":s=!!["value","checked","selected","open"].includes(i.attribute)||w(i,t);break;case"class":r=i,s=t.hasClass(r.value);break;case"id":s=F(i,t);break;case"tag":s=A(i,t);break;default:continue}if(!s)return!1}}var r;return s}walkThroughCSS(e,t){e.walk((e=>"rule"===e.type?this.evaluateRule(e,t):"atrule"===e.type?this.evaluateAtRule(e):void("comment"===e.type&&(y(e,"start")?(this.ignore=!0,e.remove()):y(e,"end")&&(this.ignore=!1,e.remove())))))}}export default k;export{k as PurgeCSS,c as defaultOptions,S as mergeExtractorSelectors,g as setOptions,p as standardizeSafelist};

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("postcss"),t=require("postcss-selector-parser"),s=require("fs"),r=require("util"),i=require("glob"),a=require("path");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var u=n(t),c=n(i),l=n(a);const d={css:[],content:[],defaultExtractor:e=>e.match(/[A-Za-z0-9_-]+/g)||[],extractors:[],fontFace:!1,keyframes:!1,rejected:!1,stdin:!1,stdout:!1,variables:!1,safelist:{standard:[],deep:[],greedy:[],variables:[],keyframes:[]},blocklist:[]},f=["*","::-webkit-scrollbar","::selection",":root","::before","::after"];class h{constructor(e){this.nodes=[],this.isUsed=!1,this.value=e}}class p{constructor(){this.nodes=new Map,this.usedVariables=new Set,this.safelist=[]}addVariable(e){const{prop:t}=e;if(!this.nodes.has(t)){const s=new h(e);this.nodes.set(t,s)}}addVariableUsage(e,t){const{prop:s}=e,r=this.nodes.get(s);for(const e of t){const t=e[1];if(this.nodes.has(t)){const e=this.nodes.get(t);null==r||r.nodes.push(e)}}}addVariableUsageInProperties(e){for(const t of e){const e=t[1];this.usedVariables.add(e)}}setAsUsed(e){const t=[this.nodes.get(e)];for(;0!==t.length;){const e=t.pop();e&&!e.isUsed&&(e.isUsed=!0,t.push(...e.nodes))}}removeUnused(){for(const e of this.usedVariables)this.setAsUsed(e);for(const[e,t]of this.nodes)t.isUsed||this.isVariablesSafelisted(e)||t.value.remove()}isVariablesSafelisted(e){return this.safelist.some((t=>"string"==typeof t?t===e:t.test(e)))}}function m(e,t){t&&t.forEach(e.add,e)}class g{constructor(e){this.undetermined=new Set,this.attrNames=new Set,this.attrValues=new Set,this.classes=new Set,this.ids=new Set,this.tags=new Set,this.merge(e)}merge(e){return Array.isArray(e)?m(this.undetermined,e):e instanceof g?(m(this.undetermined,e.undetermined),m(this.attrNames,e.attrNames),m(this.attrValues,e.attrValues),m(this.classes,e.classes),m(this.ids,e.ids),m(this.tags,e.tags)):(m(this.undetermined,e.undetermined),e.attributes&&(m(this.attrNames,e.attributes.names),m(this.attrValues,e.attributes.values)),m(this.classes,e.classes),m(this.ids,e.ids),m(this.tags,e.tags)),this}hasAttrName(e){return this.attrNames.has(e)||this.undetermined.has(e)}someAttrValue(e){for(const t of this.attrValues)if(e(t))return!0;for(const t of this.undetermined)if(e(t))return!0;return!1}hasAttrPrefix(e){return this.someAttrValue((t=>t.startsWith(e)))}hasAttrSuffix(e){return this.someAttrValue((t=>t.endsWith(e)))}hasAttrSubstr(e){return this.someAttrValue((t=>t.includes(e)))}hasAttrValue(e){return this.attrValues.has(e)||this.undetermined.has(e)}hasClass(e){return this.classes.has(e)||this.undetermined.has(e)}hasId(e){return this.ids.has(e)||this.undetermined.has(e)}hasTag(e){return this.tags.has(e)||this.undetermined.has(e)}}const v={access:r.promisify(s.access),readFile:r.promisify(s.readFile)};function y(e=[]){return Array.isArray(e)?{...d.safelist,standard:e}:{...d.safelist,...e}}async function S(e="purgecss.config.js"){let t;try{const s=l.default.join(process.cwd(),e);t=await Promise.resolve().then((function(){return o(require(s))}))}catch(e){throw new Error("Error loading the config file "+e.message)}return{...d,...t,safelist:y(t.safelist)}}async function b(e,t){return new g(await t(e))}function w(e,t){switch(t){case"next":return e.text.includes("purgecss ignore");case"start":return e.text.includes("purgecss start ignore");case"end":return e.text.includes("purgecss end ignore")}}function x(...e){const t=new g([]);return e.forEach(t.merge,t),t}function F(e){return e.replace(/(^["'])|(["']$)/g,"")}function A(e,t){if(!t.hasAttrName(e.attribute))return!1;if(void 0===e.value)return!0;switch(e.operator){case"$=":return t.hasAttrSuffix(e.value);case"~=":case"*=":return t.hasAttrSubstr(e.value);case"=":return t.hasAttrValue(e.value);case"|=":case"^=":return t.hasAttrPrefix(e.value);default:return!0}}function V(e,t){return t.hasId(e.value)}function k(e,t){return t.hasTag(e.value)}function U(e){return"atrule"===(null==e?void 0:e.type)}function j(e){return"rule"===(null==e?void 0:e.type)}class R{constructor(){this.ignore=!1,this.atRules={fontFace:[],keyframes:[]},this.usedAnimations=new Set,this.usedFontFaces=new Set,this.selectorsRemoved=new Set,this.variablesStructure=new p,this.options=d}collectDeclarationsData(e){const{prop:t,value:s}=e;if(this.options.variables){const r=function(e,t){const s=[];return e.replace(t,(function(){const t=arguments,r=Array.prototype.slice.call(t,0,-2);return r.input=t[t.length-1],r.index=t[t.length-2],s.push(r),e})),s}(s,/var\((.+?)[,)]/g);t.startsWith("--")?(this.variablesStructure.addVariable(e),r.length>0&&this.variablesStructure.addVariableUsage(e,r)):r.length>0&&this.variablesStructure.addVariableUsageInProperties(r)}if(!this.options.keyframes||"animation"!==t&&"animation-name"!==t)if(this.options.fontFace){if("font-family"===t)for(const e of s.split(",")){const t=F(e.trim());this.usedFontFaces.add(t)}}else;else for(const e of s.split(/[\s,]+/))this.usedAnimations.add(e)}getFileExtractor(e,t){const s=t.find((t=>t.extensions.find((t=>e.endsWith(t)))));return void 0===s?this.options.defaultExtractor:s.extractor}async extractSelectorsFromFiles(e,t){const r=new g([]);for(const i of e){let e=[];try{await v.access(i,s.constants.F_OK),e.push(i)}catch(t){e=c.default.sync(i,{nodir:!0})}for(const s of e){const e=await v.readFile(s,"utf-8"),i=this.getFileExtractor(s,t),a=await b(e,i);r.merge(a)}}return r}async extractSelectorsFromString(e,t){const s=new g([]);for(const{raw:r,extension:i}of e){const e=this.getFileExtractor("."+i,t),a=await b(r,e);s.merge(a)}return s}evaluateAtRule(e){if(this.options.keyframes&&e.name.endsWith("keyframes"))this.atRules.keyframes.push(e);else if(this.options.fontFace&&"font-face"===e.name&&e.nodes)for(const t of e.nodes)"decl"===t.type&&"font-family"===t.prop&&this.atRules.fontFace.push({name:F(t.value),node:e})}async evaluateRule(e,t){if(this.ignore)return;const s=e.prev();if(function(e){return"comment"===(null==e?void 0:e.type)}(s)&&w(s,"next"))return void s.remove();if(e.parent&&U(e.parent)&&"keyframes"===e.parent.name)return;if(!j(e))return;if(function(e){let t=!1;return e.walkComments((e=>{e&&"comment"===e.type&&e.text.includes("purgecss ignore current")&&(t=!0,e.remove())})),t}(e))return;let r=!0;if(e.selector=u.default((e=>{e.walk((e=>{"selector"===e.type&&(r=this.shouldKeepSelector(e,t),r||(this.options.rejected&&this.selectorsRemoved.add(e.toString()),e.remove()))}))})).processSync(e.selector),r&&void 0!==e.nodes)for(const t of e.nodes)"decl"===t.type&&this.collectDeclarationsData(t);const i=e.parent;e.selector||e.remove(),function(e){return!!(j(e)&&!e.selector||(null==e?void 0:e.nodes)&&!e.nodes.length||U(e)&&(!e.nodes&&!e.params||!e.params&&e.nodes&&!e.nodes.length))}(i)&&(null==i||i.remove())}async getPurgedCSS(t,s){const r=[],i=[];for(const e of t)"string"==typeof e?i.push(...c.default.sync(e,{nodir:!0})):i.push(e);for(const t of i){const i="string"==typeof t?this.options.stdin?t:await v.readFile(t,"utf-8"):t.raw,a=e.parse(i);this.walkThroughCSS(a,s),this.options.fontFace&&this.removeUnusedFontFaces(),this.options.keyframes&&this.removeUnusedKeyframes(),this.options.variables&&this.removeUnusedCSSVariables();const n={css:a.toString(),file:"string"==typeof t?t:void 0};"string"==typeof t&&(n.file=t),this.options.rejected&&(n.rejected=Array.from(this.selectorsRemoved),this.selectorsRemoved.clear()),r.push(n)}return r}isKeyframesSafelisted(e){return this.options.safelist.keyframes.some((t=>"string"==typeof t?t===e:t.test(e)))}isSelectorBlocklisted(e){return this.options.blocklist.some((t=>"string"==typeof t?t===e:t.test(e)))}isSelectorSafelisted(e){const t=this.options.safelist.standard.some((t=>"string"==typeof t?t===e:t.test(e)));return f.includes(e)||t}isSelectorSafelistedDeep(e){return this.options.safelist.deep.some((t=>t.test(e)))}isSelectorSafelistedGreedy(e){return this.options.safelist.greedy.some((t=>t.test(e)))}async purge(e){this.options="object"!=typeof e?await S(e):{...d,...e,safelist:y(e.safelist)};const{content:t,css:s,extractors:r,safelist:i}=this.options;this.options.variables&&(this.variablesStructure.safelist=i.variables||[]);const a=t.filter((e=>"string"==typeof e)),n=t.filter((e=>"object"==typeof e)),o=await this.extractSelectorsFromFiles(a,r),u=await this.extractSelectorsFromString(n,r);return this.getPurgedCSS(s,x(o,u))}removeUnusedCSSVariables(){this.variablesStructure.removeUnused()}removeUnusedFontFaces(){for(const{name:e,node:t}of this.atRules.fontFace)this.usedFontFaces.has(e)||t.remove()}removeUnusedKeyframes(){for(const e of this.atRules.keyframes)this.usedAnimations.has(e.params)||this.isKeyframesSafelisted(e.params)||e.remove()}getSelectorValue(e){return"attribute"===e.type&&e.attribute||e.value}shouldKeepSelector(e,t){if(function(e){return e.parent&&"pseudo"===e.parent.type&&e.parent.value.startsWith(":")||!1}(e))return!0;if(this.options.safelist.greedy.length>0){if(e.nodes.map(this.getSelectorValue).some((e=>e&&this.isSelectorSafelistedGreedy(e))))return!0}let s=!1;for(const i of e.nodes){const e=this.getSelectorValue(i);if(e&&this.isSelectorSafelistedDeep(e))return!0;if(e&&(f.includes(e)||this.isSelectorSafelisted(e)))s=!0;else{if(e&&this.isSelectorBlocklisted(e))return!1;switch(i.type){case"attribute":s=!!["value","checked","selected","open"].includes(i.attribute)||A(i,t);break;case"class":r=i,s=t.hasClass(r.value);break;case"id":s=V(i,t);break;case"tag":s=k(i,t);break;default:continue}if(!s)return!1}}var r;return s}walkThroughCSS(e,t){e.walk((e=>"rule"===e.type?this.evaluateRule(e,t):"atrule"===e.type?this.evaluateAtRule(e):void("comment"===e.type&&(w(e,"start")?(this.ignore=!0,e.remove()):w(e,"end")&&(this.ignore=!1,e.remove())))))}}exports.PurgeCSS=R,exports.default=R,exports.defaultOptions=d,exports.mergeExtractorSelectors=x,exports.setOptions=S,exports.standardizeSafelist=y;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("postcss"),t=require("postcss-selector-parser"),s=require("fs"),r=require("util"),i=require("glob"),a=require("path");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(s){if("default"!==s){var r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:function(){return e[s]}})}})),t.default=e,Object.freeze(t)}var u=n(t),c=n(i),l=n(a);const d={css:[],content:[],defaultExtractor:e=>e.match(/[A-Za-z0-9_-]+/g)||[],extractors:[],fontFace:!1,keyframes:!1,rejected:!1,stdin:!1,stdout:!1,variables:!1,safelist:{standard:[],deep:[],greedy:[],variables:[],keyframes:[]},blocklist:[]},f=["*","::-webkit-scrollbar","::selection",":root","::before","::after"];class h{constructor(e){this.nodes=[],this.isUsed=!1,this.value=e}}class p{constructor(){this.nodes=new Map,this.usedVariables=new Set,this.safelist=[]}addVariable(e){const{prop:t}=e;if(!this.nodes.has(t)){const s=new h(e);this.nodes.set(t,s)}}addVariableUsage(e,t){const{prop:s}=e,r=this.nodes.get(s);for(const e of t){const t=e[1];if(this.nodes.has(t)){const e=this.nodes.get(t);null==r||r.nodes.push(e)}}}addVariableUsageInProperties(e){for(const t of e){const e=t[1];this.usedVariables.add(e)}}setAsUsed(e){const t=[this.nodes.get(e)];for(;0!==t.length;){const e=t.pop();e&&!e.isUsed&&(e.isUsed=!0,t.push(...e.nodes))}}removeUnused(){for(const e of this.usedVariables)this.setAsUsed(e);for(const[e,t]of this.nodes)t.isUsed||this.isVariablesSafelisted(e)||t.value.remove()}isVariablesSafelisted(e){return this.safelist.some((t=>"string"==typeof t?t===e:t.test(e)))}}function m(e,t){t&&t.forEach(e.add,e)}class g{constructor(e){this.undetermined=new Set,this.attrNames=new Set,this.attrValues=new Set,this.classes=new Set,this.ids=new Set,this.tags=new Set,this.merge(e)}merge(e){return Array.isArray(e)?m(this.undetermined,e):e instanceof g?(m(this.undetermined,e.undetermined),m(this.attrNames,e.attrNames),m(this.attrValues,e.attrValues),m(this.classes,e.classes),m(this.ids,e.ids),m(this.tags,e.tags)):(m(this.undetermined,e.undetermined),e.attributes&&(m(this.attrNames,e.attributes.names),m(this.attrValues,e.attributes.values)),m(this.classes,e.classes),m(this.ids,e.ids),m(this.tags,e.tags)),this}hasAttrName(e){return this.attrNames.has(e)||this.undetermined.has(e)}someAttrValue(e){for(const t of this.attrValues)if(e(t))return!0;for(const t of this.undetermined)if(e(t))return!0;return!1}hasAttrPrefix(e){return this.someAttrValue((t=>t.startsWith(e)))}hasAttrSuffix(e){return this.someAttrValue((t=>t.endsWith(e)))}hasAttrSubstr(e){return e.trim().split(" ").every((e=>this.someAttrValue((t=>t.includes(e)))))}hasAttrValue(e){return this.attrValues.has(e)||this.undetermined.has(e)}hasClass(e){return this.classes.has(e)||this.undetermined.has(e)}hasId(e){return this.ids.has(e)||this.undetermined.has(e)}hasTag(e){return this.tags.has(e)||this.undetermined.has(e)}}const v={access:r.promisify(s.access),readFile:r.promisify(s.readFile)};function y(e=[]){return Array.isArray(e)?{...d.safelist,standard:e}:{...d.safelist,...e}}async function S(e="purgecss.config.js"){let t;try{const s=l.default.join(process.cwd(),e);t=await Promise.resolve().then((function(){return o(require(s))}))}catch(e){throw new Error("Error loading the config file "+e.message)}return{...d,...t,safelist:y(t.safelist)}}async function b(e,t){return new g(await t(e))}function w(e,t){switch(t){case"next":return e.text.includes("purgecss ignore");case"start":return e.text.includes("purgecss start ignore");case"end":return e.text.includes("purgecss end ignore")}}function x(...e){const t=new g([]);return e.forEach(t.merge,t),t}function F(e){return e.replace(/(^["'])|(["']$)/g,"")}function A(e,t){if(!t.hasAttrName(e.attribute))return!1;if(void 0===e.value)return!0;switch(e.operator){case"$=":return t.hasAttrSuffix(e.value);case"~=":case"*=":return t.hasAttrSubstr(e.value);case"=":return t.hasAttrValue(e.value);case"|=":case"^=":return t.hasAttrPrefix(e.value);default:return!0}}function V(e,t){return t.hasId(e.value)}function k(e,t){return t.hasTag(e.value)}function U(e){return"atrule"===(null==e?void 0:e.type)}function j(e){return"rule"===(null==e?void 0:e.type)}class R{constructor(){this.ignore=!1,this.atRules={fontFace:[],keyframes:[]},this.usedAnimations=new Set,this.usedFontFaces=new Set,this.selectorsRemoved=new Set,this.variablesStructure=new p,this.options=d}collectDeclarationsData(e){const{prop:t,value:s}=e;if(this.options.variables){const r=function(e,t){const s=[];return e.replace(t,(function(){const t=arguments,r=Array.prototype.slice.call(t,0,-2);return r.input=t[t.length-1],r.index=t[t.length-2],s.push(r),e})),s}(s,/var\((.+?)[,)]/g);t.startsWith("--")?(this.variablesStructure.addVariable(e),r.length>0&&this.variablesStructure.addVariableUsage(e,r)):r.length>0&&this.variablesStructure.addVariableUsageInProperties(r)}if(!this.options.keyframes||"animation"!==t&&"animation-name"!==t)if(this.options.fontFace){if("font-family"===t)for(const e of s.split(",")){const t=F(e.trim());this.usedFontFaces.add(t)}}else;else for(const e of s.split(/[\s,]+/))this.usedAnimations.add(e)}getFileExtractor(e,t){const s=t.find((t=>t.extensions.find((t=>e.endsWith(t)))));return void 0===s?this.options.defaultExtractor:s.extractor}async extractSelectorsFromFiles(e,t){const r=new g([]);for(const i of e){let e=[];try{await v.access(i,s.constants.F_OK),e.push(i)}catch(t){e=c.default.sync(i,{nodir:!0})}for(const s of e){const e=await v.readFile(s,"utf-8"),i=this.getFileExtractor(s,t),a=await b(e,i);r.merge(a)}}return r}async extractSelectorsFromString(e,t){const s=new g([]);for(const{raw:r,extension:i}of e){const e=this.getFileExtractor("."+i,t),a=await b(r,e);s.merge(a)}return s}evaluateAtRule(e){if(this.options.keyframes&&e.name.endsWith("keyframes"))this.atRules.keyframes.push(e);else if(this.options.fontFace&&"font-face"===e.name&&e.nodes)for(const t of e.nodes)"decl"===t.type&&"font-family"===t.prop&&this.atRules.fontFace.push({name:F(t.value),node:e})}async evaluateRule(e,t){if(this.ignore)return;const s=e.prev();if(function(e){return"comment"===(null==e?void 0:e.type)}(s)&&w(s,"next"))return void s.remove();if(e.parent&&U(e.parent)&&"keyframes"===e.parent.name)return;if(!j(e))return;if(function(e){let t=!1;return e.walkComments((e=>{e&&"comment"===e.type&&e.text.includes("purgecss ignore current")&&(t=!0,e.remove())})),t}(e))return;let r=!0;if(e.selector=u.default((e=>{e.walk((e=>{"selector"===e.type&&(r=this.shouldKeepSelector(e,t),r||(this.options.rejected&&this.selectorsRemoved.add(e.toString()),e.remove()))}))})).processSync(e.selector),r&&void 0!==e.nodes)for(const t of e.nodes)"decl"===t.type&&this.collectDeclarationsData(t);const i=e.parent;e.selector||e.remove(),function(e){return!!(j(e)&&!e.selector||(null==e?void 0:e.nodes)&&!e.nodes.length||U(e)&&(!e.nodes&&!e.params||!e.params&&e.nodes&&!e.nodes.length))}(i)&&(null==i||i.remove())}async getPurgedCSS(t,s){const r=[],i=[];for(const e of t)"string"==typeof e?i.push(...c.default.sync(e,{nodir:!0})):i.push(e);for(const t of i){const i="string"==typeof t?this.options.stdin?t:await v.readFile(t,"utf-8"):t.raw,a=e.parse(i);this.walkThroughCSS(a,s),this.options.fontFace&&this.removeUnusedFontFaces(),this.options.keyframes&&this.removeUnusedKeyframes(),this.options.variables&&this.removeUnusedCSSVariables();const n={css:a.toString(),file:"string"==typeof t?t:void 0};"string"==typeof t&&(n.file=t),this.options.rejected&&(n.rejected=Array.from(this.selectorsRemoved),this.selectorsRemoved.clear()),r.push(n)}return r}isKeyframesSafelisted(e){return this.options.safelist.keyframes.some((t=>"string"==typeof t?t===e:t.test(e)))}isSelectorBlocklisted(e){return this.options.blocklist.some((t=>"string"==typeof t?t===e:t.test(e)))}isSelectorSafelisted(e){const t=this.options.safelist.standard.some((t=>"string"==typeof t?t===e:t.test(e)));return f.includes(e)||t}isSelectorSafelistedDeep(e){return this.options.safelist.deep.some((t=>t.test(e)))}isSelectorSafelistedGreedy(e){return this.options.safelist.greedy.some((t=>t.test(e)))}async purge(e){this.options="object"!=typeof e?await S(e):{...d,...e,safelist:y(e.safelist)};const{content:t,css:s,extractors:r,safelist:i}=this.options;this.options.variables&&(this.variablesStructure.safelist=i.variables||[]);const a=t.filter((e=>"string"==typeof e)),n=t.filter((e=>"object"==typeof e)),o=await this.extractSelectorsFromFiles(a,r),u=await this.extractSelectorsFromString(n,r);return this.getPurgedCSS(s,x(o,u))}removeUnusedCSSVariables(){this.variablesStructure.removeUnused()}removeUnusedFontFaces(){for(const{name:e,node:t}of this.atRules.fontFace)this.usedFontFaces.has(e)||t.remove()}removeUnusedKeyframes(){for(const e of this.atRules.keyframes)this.usedAnimations.has(e.params)||this.isKeyframesSafelisted(e.params)||e.remove()}getSelectorValue(e){return"attribute"===e.type&&e.attribute||e.value}shouldKeepSelector(e,t){if(function(e){return e.parent&&"pseudo"===e.parent.type&&e.parent.value.startsWith(":")||!1}(e))return!0;if(this.options.safelist.greedy.length>0){if(e.nodes.map(this.getSelectorValue).some((e=>e&&this.isSelectorSafelistedGreedy(e))))return!0}let s=!1;for(const i of e.nodes){const e=this.getSelectorValue(i);if(e&&this.isSelectorSafelistedDeep(e))return!0;if(e&&(f.includes(e)||this.isSelectorSafelisted(e)))s=!0;else{if(e&&this.isSelectorBlocklisted(e))return!1;switch(i.type){case"attribute":s=!!["value","checked","selected","open"].includes(i.attribute)||A(i,t);break;case"class":r=i,s=t.hasClass(r.value);break;case"id":s=V(i,t);break;case"tag":s=k(i,t);break;default:continue}if(!s)return!1}}var r;return s}walkThroughCSS(e,t){e.walk((e=>"rule"===e.type?this.evaluateRule(e,t):"atrule"===e.type?this.evaluateAtRule(e):void("comment"===e.type&&(w(e,"start")?(this.ignore=!0,e.remove()):w(e,"end")&&(this.ignore=!1,e.remove())))))}}exports.PurgeCSS=R,exports.default=R,exports.defaultOptions=d,exports.mergeExtractorSelectors=x,exports.setOptions=S,exports.standardizeSafelist=y;
{
"name": "purgecss",
"version": "4.0.0",
"version": "4.0.1",
"description": "Remove unused css selectors",

@@ -53,3 +53,3 @@ "author": "Ffloriel",

},
"gitHead": "96703445aff78ac147b95b43f57aadaad6520fa2"
"gitHead": "61a9f5345fe4c5aa9ea3fd7a8706d9492260274c"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc