UNPKG

html-minifier

Version:

Highly effective, super-configurable, well-tested web page minifier

99 lines • 4.41 kB
/** * Options processing and per-document minification state */ import { LRU } from './utils.js'; import type { MinifierOptions, HTMLAttribute } from '../htmlminifier.js'; export type CSSContext = { usedSymbols?: Set<string>; usedElements?: Set<string>; usedElementsKey?: string; warned: Set<string>; }; export type CSSResult = { css: string; warnings: string[]; }; export type ProcessedOptions = Omit<MinifierOptions, 'preset' | 'canCollapseWhitespace' | 'canTrimWhitespace' | 'ignoreCustomComments' | 'log' | 'minifyCSS' | 'minifyJS' | 'minifyURLs' | 'minifySVG' | 'removeUnusedCSS'> & { name: (name: string) => string; log: (message: any) => unknown; ignoreCustomComments: RegExp[]; canCollapseWhitespace: (tag: string, attrs: HTMLAttribute[], defaultFn: (tag: string) => boolean) => boolean; canTrimWhitespace: (tag: string, attrs: HTMLAttribute[], defaultFn: (tag: string) => boolean) => boolean; minifyCSS: (text: string, type?: string, context?: CSSContext) => string | Promise<string>; minifyJS: (text: string, inline?: boolean, isModule?: boolean) => string | Promise<string>; minifyURLs: (text: string) => string | Promise<string>; minifySVG: ((svgContent: string) => string | Promise<string>) | null; canMinifyCSS: ((text: string, type?: 'inline' | 'media') => boolean) | null; canMinifyJS: ((text: string, inline?: boolean) => boolean) | null; canMinifySVG: ((text: string) => boolean) | null; removeUnusedCSS: { safelist: Array<string | RegExp>; scripts: boolean; } | null; cssContext?: CSSContext; baseState?: { hasBase: boolean | undefined; selectedAttrs?: Set<string>; source: string; }; parallelJS?: boolean; nameParent?: ((name: string) => string) | undefined; namesAsWritten?: boolean; keepClosingSlashHTML?: boolean | undefined; insideSVG?: boolean; insideForeignContent?: boolean; namespaceForeign?: 'svg' | 'math' | undefined; optionsParent?: ProcessedOptions | undefined; }; /** @param {ProcessedOptions} options */ declare function shouldMinifyInnerHTML(options: ProcessedOptions): boolean; declare const optionKeysExtra: Set<string>; export type OptionDependency = OptionDependency[]; /** * Options that do nothing on their own, and the option each one needs to take effect * * Cache sizes are deliberately absent: They never change output, so they are * configuration for a subsystem rather than a transform that silently fails. * * @typedef {object} OptionDependency * @property {string} option * @property {string} requires * @property {(input: Record<string, any>) => string | false} [unusable] Clause saying why the prerequisite does not count even though it is set * @property {boolean} [clear] Whether to null the option out, where leaving it set would cost work downstream * * @type {OptionDependency[]} */ declare const optionDependencies: ({ option: string; requires: string; unusable: (input: Record<string, any>) => "which a function of your own replaces" | false; clear: boolean; } | { unusable?: never; clear?: never; option: string; requires: string; })[]; /** * @param {ProcessedOptions} options - Processed options * @param {'canMinifyCSS' | 'canMinifyJS' | 'canMinifySVG'} name - Hook to consult * @param {...any} args - Arguments for the hook * @returns {boolean} */ declare function declinesMinify(options: ProcessedOptions, name: 'canMinifyCSS' | 'canMinifyJS' | 'canMinifySVG', ...args: any[]): boolean; /** * @param {MinifierOptions} inputOptions - User-provided options * @param {{getLightningCSS: Function, getTerser: Function, getSwc: Function, getSvgo: Function, cssMinifyCache: LRU, jsMinifyCache: LRU, svgMinifyCache: LRU}} deps - Dependencies from htmlminifier.js * @returns {ProcessedOptions} Normalized options with defaults applied */ declare const processOptions: (inputOptions: MinifierOptions, { getLightningCSS, getTerser, getSwc, getSvgo, cssMinifyCache, jsMinifyCache, svgMinifyCache }: { getLightningCSS: Function; getTerser: Function; getSwc: Function; getSvgo: Function; cssMinifyCache: LRU; jsMinifyCache: LRU; svgMinifyCache: LRU; }) => ProcessedOptions; export { declinesMinify, optionDependencies, optionKeysExtra, shouldMinifyInnerHTML, processOptions }; //# sourceMappingURL=options.d.ts.map