html-minifier
Version:
Highly effective, super-configurable, well-tested web page minifier
76 lines • 4.07 kB
TypeScript
/**
* Unused-CSS removal
*/
/**
* Collect the class names and IDs a document references.
*
* Style sheet contents are excluded, so that a style sheet never counts as
* evidence for its own selectors. An `iframe srcdoc` value is not scanned,
* either: It holds a document of its own, minified against its own symbol set.
* Over-collecting is safe here (a symbol wrongly considered used is merely
* kept), under-collecting is not.
*
* @param {string} html - Raw document markup
* @param {boolean} includeScripts - Also treat identifiers inside inline `script` elements as used
* @param {((text: string) => string)} [decode] - Resolves character references in attribute values and foreign script contents
* @param {Set<string>} [elements] - Receives the element names the markup uses, lowercased, and the identifiers found in scripts, as possible element names
* @returns {Set<string>} Symbols to keep
*/
declare function collectUsedSymbols(html: string, includeScripts: boolean, decode?: ((text: string) => string), elements?: Set<string>): Set<string>;
/**
* Determine which class/ID symbols a style sheet defines but the document doesn’t reference.
* @param {string} css - Style sheet contents
* @param {Set<string>} used - Symbols the document references
* @param {Array<string | RegExp>} safelist - Symbols to keep regardless
* @returns {string[]} Symbols safe to remove
*/
declare function findUnusedSymbols(css: string, used: Set<string>, safelist: Array<string | RegExp>): string[];
/**
* Build the unused-CSS context for a document.
* @param {string} html - Raw document markup
* @param {boolean} includeScripts - Also treat identifiers inside inline `script` elements as used
* @param {((text: string) => string)} [decode] - Resolves character references in attribute values and foreign script contents
* @returns {{usedSymbols: Set<string>, usedElements: Set<string>, usedElementsKey: string}}
*/
declare function collectUsage(html: string, includeScripts: boolean, decode?: ((text: string) => string)): {
usedSymbols: Set<string>;
usedElements: Set<string>;
usedElementsKey: string;
};
/**
* Create a Lightning CSS `Selector` visitor that drops selectors naming an unused
* class, ID, or element from their list, so the rule stays for the selectors that
* remain (`unusedSymbols` alone only removes rules whose selectors are all unused).
*
* Only a selector’s own compounds are judged: Names inside pseudo-class and
* pseudo-element arguments (`:not(.x)`, `:host(.x)`) are left alone.
*
* @param {string[]} unusedSymbols - Class/ID symbols safe to remove, from `findUnusedSymbols`
* @param {Set<string>} usedElements - Lowercase element names the document contains or its scripts name
* @param {Array<string | RegExp>} safelist - Symbols to keep regardless
* @returns {(selector: Array<{type: string, name?: string}>) => [] | undefined}
*/
declare function createSelectorPruner(unusedSymbols: string[], usedElements: Set<string>, safelist: Array<string | RegExp>): (selector: Array<{
type: string;
name?: string;
}>) => [] | undefined;
/**
* Normalize the `removeUnusedCSS` option into a settled configuration.
*
* A misspelled key or a safelist that is not an array would otherwise protect
* nothing, and that only surfaces as a missing rule much later—so every value
* that gets dropped is reported.
*
* @param {boolean | {safelist?: Array<string | RegExp>, scripts?: boolean} | undefined} option
* @param {(message: string) => unknown} [warn] - Receives one message per ignored value
* @returns {{safelist: Array<string | RegExp>, scripts: boolean} | null} Null when disabled
*/
declare function normalizeUnusedCSSOptions(option: boolean | {
safelist?: Array<string | RegExp>;
scripts?: boolean;
} | undefined, warn?: (message: string) => unknown): {
safelist: Array<string | RegExp>;
scripts: boolean;
} | null;
export { collectUsage, collectUsedSymbols, createSelectorPruner, findUnusedSymbols, normalizeUnusedCSSOptions };
//# sourceMappingURL=unused-css.d.ts.map