UNPKG

html-minifier

Version:

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

71 lines • 2.94 kB
/** * Script and style merging */ export type MergeAttribute = { name: string; value?: string; customAssign?: string; customOpen?: string; customClose?: string; }; /** * What a `script` or `style` element’s attributes make of it, equal for elements that may be * merged: classic inline scripts and CSS style sheets whose attributes match, as tools that * rewrite the page in the browser or at the edge may read them (e.g., `data-cfasync`); `null` * for one that is to stay apart, as one with an `id`, which two elements can’t share * * @param {'script' | 'style'} kind * @param {MergeAttribute[]} attrs * @param {(text: string) => string} resolve - Restores custom fragments * @returns {string | null} */ declare function getMergeKey(kind: 'script' | 'style', attrs: MergeAttribute[], resolve: (text: string) => string): string | null; /** * Whether script code starts with a hashbang, which only works at the very start of a script, * so that the script stays apart (where whitespace comes first, it’s an error, which would * spread to what is merged with it) * * @param {string} code * @returns {boolean} */ declare function holdsHashbang(code: string): boolean; /** * Whether a script may follow merged script code, which, holding `<!--`, would not end at * `</script>` after one holding `<script` * * @param {boolean} holdsCommentStart - Whether the merged script holds `<!--` so far * @param {string} next * @returns {boolean} */ declare function canScriptFollow(holdsCommentStart: boolean, next: string): boolean; /** * Scripts joined as one, with a semicolon: after a newline where the last line may end in a * comment (`//`, `<!--`, or `-->`, all of which browsers read as running to the end of the * line), and before one where the next starts with `-->`, a comment only there. A custom * fragment at either end may write any of these. * * @param {string[]} parts * @param {string[]} markers - Custom fragment placeholder markers * @returns {string} */ declare function joinScripts(parts: string[], markers: string[]): string; /** * Style sheets joined as one, without the whitespace where they meet (CSS whitespace only, as * other spaces may be part of a name) * * @param {string[]} parts * @returns {string} */ declare function joinStyleSheets(parts: string[]): string; /** * Whether CSS may follow a style sheet’s: The style sheet has to end cleanly and declare * no namespaces, which would apply to what follows, and the CSS can’t hold rules that * only work at the start of a style sheet * * @param {string} css - The last CSS of the style sheets merged so far that isn’t blank * @param {string} next * @returns {boolean} */ declare function canStyleSheetsJoin(css: string, next: string): boolean; export { canScriptFollow, canStyleSheetsJoin, getMergeKey, holdsHashbang, joinScripts, joinStyleSheets }; //# sourceMappingURL=merging.d.ts.map