@ohos-ports/html-minifier-next 8.4.2-beta.0
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/LICENSE.txt +23 -0
- package/README.md +776 -0
- package/cli.js +1209 -0
- package/dist/types/htmlminifier.d.ts +556 -0
- package/dist/types/htmlminifier.d.ts.map +1 -0
- package/dist/types/htmlparser.d.ts +25 -0
- package/dist/types/htmlparser.d.ts.map +1 -0
- package/dist/types/lib/attributes.d.ts +155 -0
- package/dist/types/lib/attributes.d.ts.map +1 -0
- package/dist/types/lib/constants.d.ts +110 -0
- package/dist/types/lib/constants.d.ts.map +1 -0
- package/dist/types/lib/content.d.ts +51 -0
- package/dist/types/lib/content.d.ts.map +1 -0
- package/dist/types/lib/elements.d.ts +57 -0
- package/dist/types/lib/elements.d.ts.map +1 -0
- package/dist/types/lib/fragments.d.ts +46 -0
- package/dist/types/lib/fragments.d.ts.map +1 -0
- package/dist/types/lib/option-definitions.d.ts +33 -0
- package/dist/types/lib/option-definitions.d.ts.map +1 -0
- package/dist/types/lib/options.d.ts +120 -0
- package/dist/types/lib/options.d.ts.map +1 -0
- package/dist/types/lib/unused-css.d.ts +46 -0
- package/dist/types/lib/unused-css.d.ts.map +1 -0
- package/dist/types/lib/urls.d.ts +15 -0
- package/dist/types/lib/urls.d.ts.map +1 -0
- package/dist/types/lib/utils.d.ts +102 -0
- package/dist/types/lib/utils.d.ts.map +1 -0
- package/dist/types/lib/whitespace.d.ts +45 -0
- package/dist/types/lib/whitespace.d.ts.map +1 -0
- package/dist/types/presets.d.ts +49 -0
- package/dist/types/presets.d.ts.map +1 -0
- package/dist/types/tokenchain.d.ts +26 -0
- package/dist/types/tokenchain.d.ts.map +1 -0
- package/html-minifier-next.schema.json +306 -0
- package/package.json +100 -0
- package/src/htmlminifier.js +2294 -0
- package/src/htmlparser.js +1069 -0
- package/src/lib/attributes.js +928 -0
- package/src/lib/constants.js +285 -0
- package/src/lib/content.js +190 -0
- package/src/lib/elements.js +274 -0
- package/src/lib/file-pool.js +177 -0
- package/src/lib/fragments.js +274 -0
- package/src/lib/option-definitions.js +231 -0
- package/src/lib/options.js +730 -0
- package/src/lib/unused-css.js +379 -0
- package/src/lib/urls.js +155 -0
- package/src/lib/utils.js +861 -0
- package/src/lib/whitespace.js +321 -0
- package/src/presets.js +57 -0
- package/src/tokenchain.js +123 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML attribute parsing, decoding, and minification
|
|
3
|
+
*/
|
|
4
|
+
import type { ProcessedOptions } from './options.js';
|
|
5
|
+
export type HTMLAttribute = {
|
|
6
|
+
name: string;
|
|
7
|
+
value?: string | undefined;
|
|
8
|
+
quote?: string;
|
|
9
|
+
customAssign?: string;
|
|
10
|
+
customOpen?: string;
|
|
11
|
+
customClose?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} text
|
|
15
|
+
* @param {ProcessedOptions} options
|
|
16
|
+
*/
|
|
17
|
+
declare function isIgnoredComment(text: string, options: ProcessedOptions): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} attrName
|
|
20
|
+
* @param {{customEventAttributes?: RegExp[]}} options
|
|
21
|
+
*/
|
|
22
|
+
declare function isEventAttribute(attrName: string, options: {
|
|
23
|
+
customEventAttributes?: RegExp[];
|
|
24
|
+
}): boolean;
|
|
25
|
+
/** @param {string} value */
|
|
26
|
+
declare function canRemoveAttributeQuotes(value: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @param {HTMLAttribute[]} attributes
|
|
29
|
+
* @param {string} attribute
|
|
30
|
+
*/
|
|
31
|
+
declare function attributesInclude(attributes: HTMLAttribute[], attribute: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Remove duplicate attributes from an attribute list.
|
|
34
|
+
* Per HTML spec, when an attribute appears multiple times, the first occurrence wins.
|
|
35
|
+
* Duplicate attributes result in invalid HTML, so only the first is kept.
|
|
36
|
+
* @param {HTMLAttribute[]} attrs - Array of attribute objects with `name` property
|
|
37
|
+
* @param {boolean} caseSensitive - Whether to compare names case-sensitively (for XML/SVG)
|
|
38
|
+
* @returns {HTMLAttribute[]} Deduplicated attribute array (modifies in place and returns)
|
|
39
|
+
*/
|
|
40
|
+
declare function deduplicateAttributes(attrs: HTMLAttribute[], caseSensitive: boolean): HTMLAttribute[];
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} tag
|
|
43
|
+
* @param {string} attrName
|
|
44
|
+
* @param {string} attrValue
|
|
45
|
+
* @param {HTMLAttribute[]} attrs
|
|
46
|
+
*/
|
|
47
|
+
declare function isAttributeRedundant(tag: string, attrName: string, attrValue: string, attrs: HTMLAttribute[]): boolean;
|
|
48
|
+
declare function isScriptTypeAttribute(attrValue?: string): boolean;
|
|
49
|
+
declare function keepScriptTypeAttribute(attrValue?: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* @param {string} tag
|
|
52
|
+
* @param {HTMLAttribute[]} attrs
|
|
53
|
+
*/
|
|
54
|
+
declare function isExecutableScript(tag: string, attrs: HTMLAttribute[]): boolean;
|
|
55
|
+
declare function isStyleLinkTypeAttribute(attrValue?: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* @param {string} tag
|
|
58
|
+
* @param {HTMLAttribute[]} attrs
|
|
59
|
+
*/
|
|
60
|
+
declare function isStyleElement(tag: string, attrs: HTMLAttribute[]): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* @param {string} attrName
|
|
63
|
+
* @param {string} attrValue
|
|
64
|
+
*/
|
|
65
|
+
declare function isBooleanAttribute(attrName: string, attrValue: string): boolean | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* @param {string} attrName
|
|
68
|
+
* @param {string} tag
|
|
69
|
+
*/
|
|
70
|
+
declare function isUriTypeAttribute(attrName: string, tag: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* @param {string} attrName
|
|
73
|
+
* @param {string} tag
|
|
74
|
+
*/
|
|
75
|
+
declare function isNumberTypeAttribute(attrName: string, tag: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* @param {string} tag
|
|
78
|
+
* @param {HTMLAttribute[]} attrs
|
|
79
|
+
* @param {string} value
|
|
80
|
+
*/
|
|
81
|
+
declare function isLinkType(tag: string, attrs: HTMLAttribute[], value: string): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* @param {string} tag
|
|
84
|
+
* @param {HTMLAttribute[]} attrs
|
|
85
|
+
* @param {string} attrName
|
|
86
|
+
*/
|
|
87
|
+
declare function isMediaQuery(tag: string, attrs: HTMLAttribute[], attrName: string): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* @param {string} attrName
|
|
90
|
+
* @param {string} tag
|
|
91
|
+
*/
|
|
92
|
+
declare function isSrcset(attrName: string, tag: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} tag
|
|
95
|
+
* @param {HTMLAttribute[]} attrs
|
|
96
|
+
*/
|
|
97
|
+
declare function isMetaViewport(tag: string, attrs: HTMLAttribute[]): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* @param {string} tag
|
|
100
|
+
* @param {HTMLAttribute[]} attrs
|
|
101
|
+
*/
|
|
102
|
+
declare function isContentSecurityPolicy(tag: string, attrs: HTMLAttribute[]): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* @param {string} tag
|
|
105
|
+
* @param {string} attrName
|
|
106
|
+
* @param {string | undefined} attrValue
|
|
107
|
+
* @param {{removeEmptyAttributes?: boolean | Function}} options
|
|
108
|
+
*/
|
|
109
|
+
declare function canDeleteEmptyAttribute(tag: string, attrName: string, attrValue: string | undefined, options: {
|
|
110
|
+
removeEmptyAttributes?: boolean | Function;
|
|
111
|
+
}): any;
|
|
112
|
+
/**
|
|
113
|
+
* @param {string} name
|
|
114
|
+
* @param {HTMLAttribute[]} attrs
|
|
115
|
+
*/
|
|
116
|
+
declare function hasAttrName(name: string, attrs: HTMLAttribute[]): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* @param {string} tag
|
|
119
|
+
* @param {string} attrName
|
|
120
|
+
* @param {string} attrValue
|
|
121
|
+
* @param {ProcessedOptions} options
|
|
122
|
+
* @param {HTMLAttribute[]} attrs
|
|
123
|
+
* @param {Function} minifyHTMLSelf
|
|
124
|
+
*/
|
|
125
|
+
declare function cleanAttributeValue(tag: string, attrName: string, attrValue: string, options: ProcessedOptions, attrs: HTMLAttribute[], minifyHTMLSelf: Function): string | Promise<string>;
|
|
126
|
+
/**
|
|
127
|
+
* @param {HTMLAttribute} attr
|
|
128
|
+
* @param {HTMLAttribute[]} attrs
|
|
129
|
+
* @param {string} tag
|
|
130
|
+
* @param {ProcessedOptions} options
|
|
131
|
+
* @param {Function} minifyHTML
|
|
132
|
+
*/
|
|
133
|
+
declare function normalizeAttr(attr: HTMLAttribute, attrs: HTMLAttribute[], tag: string, options: ProcessedOptions, minifyHTML: Function): Promise<{
|
|
134
|
+
attr: HTMLAttribute;
|
|
135
|
+
name: string;
|
|
136
|
+
value: string | undefined;
|
|
137
|
+
} | undefined> | {
|
|
138
|
+
attr: HTMLAttribute;
|
|
139
|
+
name: string;
|
|
140
|
+
value: string | undefined;
|
|
141
|
+
} | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* @param {{name: string, value: string | undefined, attr: HTMLAttribute}} normalized
|
|
144
|
+
* @param {string | boolean | undefined} hasUnarySlash
|
|
145
|
+
* @param {ProcessedOptions} options
|
|
146
|
+
* @param {boolean} isLast
|
|
147
|
+
* @param {string | undefined} uidAttr
|
|
148
|
+
*/
|
|
149
|
+
declare function buildAttr(normalized: {
|
|
150
|
+
name: string;
|
|
151
|
+
value: string | undefined;
|
|
152
|
+
attr: HTMLAttribute;
|
|
153
|
+
}, hasUnarySlash: string | boolean | undefined, options: ProcessedOptions, isLast: boolean, uidAttr: string | undefined): string;
|
|
154
|
+
export { isIgnoredComment, isEventAttribute, canRemoveAttributeQuotes, attributesInclude, isAttributeRedundant, isScriptTypeAttribute, keepScriptTypeAttribute, isExecutableScript, isStyleLinkTypeAttribute, isStyleElement, isBooleanAttribute, isUriTypeAttribute, isNumberTypeAttribute, isLinkType, isMediaQuery, isSrcset, isMetaViewport, isContentSecurityPolicy, canDeleteEmptyAttribute, hasAttrName, cleanAttributeValue, normalizeAttr, buildAttr, deduplicateAttributes };
|
|
155
|
+
//# sourceMappingURL=attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../src/lib/attributes.js"],"names":[],"mappings":"AAAA;;GAEG;AAyBC,OAAQ,KAAA,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAKjD,YAA0I,aAAa,GAA7I;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAE1I;AAyBD;;;GAGG;AACH,iBAAS,gBAAgB,CAAC,IAAI,EAHnB,MAGmB,EAAE,OAAO,EAF5B,gBAE4B,WAOtC;AAED;;;GAGG;AACH,iBAAS,gBAAgB,CAAC,QAAQ,EAHvB,MAGuB,EAAE,OAAO,EAFhC;IAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAA;CAED,WAW1C;AAED,4BAA4B;AAC5B,iBAAS,wBAAwB,CAAC,KAAK,EAD3B,MAC2B,WAGtC;AAED;;;GAGG;AACH,iBAAS,iBAAiB,CAAC,UAAU,EAH1B,aAAa,EAGa,EAAE,SAAS,EAFrC,MAEqC,WAO/C;AAED;;;;;;;GAOG;AACH,iBAAS,qBAAqB,CAAC,KAAK,EAJzB,aAAa,EAIY,EAAE,aAAa,EAHxC,OAGwC,GAFtC,aAAa,EAAE,CAqB3B;AAED;;;;;GAKG;AACH,iBAAS,oBAAoB,C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BAAqB,EACrB,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,uBAAuB,EACvB,uBAAuB,EACvB,WAAW,EAGX,mBAAmB,EACnB,aAAa,EACb,SAAS,EACT,qBAAqB,EACtB,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regex patterns, element sets, and default configuration
|
|
3
|
+
*/
|
|
4
|
+
declare const RE_WS_START: RegExp;
|
|
5
|
+
declare const RE_WS_END: RegExp;
|
|
6
|
+
declare const RE_WS_ONLY: RegExp;
|
|
7
|
+
declare const RE_WS_NBSP_END: RegExp;
|
|
8
|
+
declare const RE_ALL_WS_NBSP: RegExp;
|
|
9
|
+
declare const RE_NBSP_LEADING_GROUP: RegExp;
|
|
10
|
+
declare const RE_NBSP_LEAD_GROUP: RegExp;
|
|
11
|
+
declare const RE_NBSP_TRAILING_GROUP: RegExp;
|
|
12
|
+
declare const RE_NBSP_TRAILING_STRIP: RegExp;
|
|
13
|
+
declare const RE_EVENT_ATTR_DEFAULT: RegExp;
|
|
14
|
+
declare const RE_CAN_REMOVE_ATTR_QUOTES: RegExp;
|
|
15
|
+
declare const RE_TRAILING_SEMICOLON: RegExp;
|
|
16
|
+
declare const RE_AMP_ENTITY: RegExp;
|
|
17
|
+
declare const RE_LEGACY_ENTITIES: RegExp;
|
|
18
|
+
declare const RE_ESCAPE_LT: RegExp;
|
|
19
|
+
declare const RE_ESCAPE_LT_RAW_TEXT: Record<string, RegExp>;
|
|
20
|
+
declare const RE_HTML_ENCODING: RegExp;
|
|
21
|
+
declare const RE_ATTR_WS_CHECK: RegExp;
|
|
22
|
+
declare const RE_ATTR_WS_COLLAPSE: RegExp;
|
|
23
|
+
declare const RE_ATTR_WS_TRIM: RegExp;
|
|
24
|
+
declare const RE_STYLE_ELEMENT: RegExp;
|
|
25
|
+
declare const RE_EMPTY_ATTRIBUTE: RegExp;
|
|
26
|
+
declare const inlineElementsToKeepWhitespaceAround: Set<string>;
|
|
27
|
+
declare const inlineElementsToKeepWhitespaceWithin: Set<string>;
|
|
28
|
+
declare const inlineElementsToKeepWhitespace: Set<string>;
|
|
29
|
+
declare const formControlElements: Set<string>;
|
|
30
|
+
declare const generalDefaults: {
|
|
31
|
+
autocorrect: string;
|
|
32
|
+
fetchpriority: string;
|
|
33
|
+
loading: string;
|
|
34
|
+
popovertargetaction: string;
|
|
35
|
+
};
|
|
36
|
+
declare const tagDefaults: {
|
|
37
|
+
area: {
|
|
38
|
+
shape: string;
|
|
39
|
+
};
|
|
40
|
+
button: {
|
|
41
|
+
type: string;
|
|
42
|
+
};
|
|
43
|
+
form: {
|
|
44
|
+
enctype: string;
|
|
45
|
+
method: string;
|
|
46
|
+
};
|
|
47
|
+
html: {
|
|
48
|
+
dir: string;
|
|
49
|
+
};
|
|
50
|
+
img: {
|
|
51
|
+
decoding: string;
|
|
52
|
+
};
|
|
53
|
+
input: {
|
|
54
|
+
colorspace: string;
|
|
55
|
+
type: string;
|
|
56
|
+
};
|
|
57
|
+
link: {
|
|
58
|
+
media: string;
|
|
59
|
+
};
|
|
60
|
+
marquee: {
|
|
61
|
+
behavior: string;
|
|
62
|
+
direction: string;
|
|
63
|
+
};
|
|
64
|
+
meta: {
|
|
65
|
+
media: string;
|
|
66
|
+
};
|
|
67
|
+
source: {
|
|
68
|
+
media: string;
|
|
69
|
+
};
|
|
70
|
+
style: {
|
|
71
|
+
media: string;
|
|
72
|
+
};
|
|
73
|
+
textarea: {
|
|
74
|
+
wrap: string;
|
|
75
|
+
};
|
|
76
|
+
track: {
|
|
77
|
+
kind: string;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
declare const executableScriptsMimetypes: Set<string>;
|
|
81
|
+
declare const keepScriptsMimetypes: Set<string>;
|
|
82
|
+
declare const isSimpleBoolean: Set<string>;
|
|
83
|
+
declare const isBooleanValue: Set<string>;
|
|
84
|
+
declare const collapsibleValues: Map<string, Set<string>>;
|
|
85
|
+
declare const srcsetElements: Set<string>;
|
|
86
|
+
declare const jsonScriptTypes: Set<string>;
|
|
87
|
+
declare const optionalStartTags: Set<string>;
|
|
88
|
+
declare const optionalEndTags: Set<string>;
|
|
89
|
+
declare const headerElements: Set<string>;
|
|
90
|
+
declare const descriptionElements: Set<string>;
|
|
91
|
+
declare const pBlockElements: Set<string>;
|
|
92
|
+
declare const pInlineElements: Set<string>;
|
|
93
|
+
declare const rubyEndTagOmission: Set<string>;
|
|
94
|
+
declare const rubyRtcEndTagOmission: Set<string>;
|
|
95
|
+
declare const optionElements: Set<string>;
|
|
96
|
+
declare const tableContentElements: Set<string>;
|
|
97
|
+
declare const tableSectionElements: Set<string>;
|
|
98
|
+
declare const cellElements: Set<string>;
|
|
99
|
+
declare const topLevelElements: Set<string>;
|
|
100
|
+
declare const compactElements: Set<string>;
|
|
101
|
+
declare const looseElements: Set<string>;
|
|
102
|
+
declare const trailingElements: Set<string>;
|
|
103
|
+
declare const htmlElements: Set<string>;
|
|
104
|
+
declare const specialContentElements: Set<string>;
|
|
105
|
+
declare const genericRawTextElements: Set<string>;
|
|
106
|
+
declare const endlessRawTextElements: Set<string>;
|
|
107
|
+
declare const escapableRawTextElements: Set<string>;
|
|
108
|
+
declare const rawTextElements: Set<string>;
|
|
109
|
+
export { RE_WS_START, RE_WS_END, RE_WS_ONLY, RE_WS_NBSP_END, RE_ALL_WS_NBSP, RE_NBSP_LEADING_GROUP, RE_NBSP_LEAD_GROUP, RE_NBSP_TRAILING_GROUP, RE_NBSP_TRAILING_STRIP, RE_EVENT_ATTR_DEFAULT, RE_CAN_REMOVE_ATTR_QUOTES, RE_TRAILING_SEMICOLON, RE_AMP_ENTITY, RE_LEGACY_ENTITIES, RE_ESCAPE_LT, RE_ESCAPE_LT_RAW_TEXT, RE_HTML_ENCODING, RE_ATTR_WS_CHECK, RE_ATTR_WS_COLLAPSE, RE_ATTR_WS_TRIM, RE_STYLE_ELEMENT, RE_EMPTY_ATTRIBUTE, inlineElementsToKeepWhitespaceAround, inlineElementsToKeepWhitespaceWithin, inlineElementsToKeepWhitespace, formControlElements, generalDefaults, tagDefaults, executableScriptsMimetypes, keepScriptsMimetypes, jsonScriptTypes, isSimpleBoolean, isBooleanValue, collapsibleValues, srcsetElements, optionalStartTags, optionalEndTags, headerElements, descriptionElements, pBlockElements, pInlineElements, rubyEndTagOmission, rubyRtcEndTagOmission, optionElements, tableContentElements, tableSectionElements, cellElements, topLevelElements, compactElements, looseElements, trailingElements, htmlElements, specialContentElements, genericRawTextElements, endlessRawTextElements, escapableRawTextElements, rawTextElements };
|
|
110
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/lib/constants.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH,QAAA,MAAM,WAAW,QAAkB,CAAC;AACpC,QAAA,MAAM,SAAS,QAAkB,CAAC;AAClC,QAAA,MAAM,UAAU,QAAmB,CAAC;AACpC,QAAA,MAAM,cAAc,QAAqB,CAAC;AAC1C,QAAA,MAAM,cAAc,QAAsB,CAAC;AAC3C,QAAA,MAAM,qBAAqB,QAAuB,CAAC;AACnD,QAAA,MAAM,kBAAkB,QAAqB,CAAC;AAC9C,QAAA,MAAM,sBAAsB,QAAqB,CAAC;AAClD,QAAA,MAAM,sBAAsB,QAAc,CAAC;AAC3C,QAAA,MAAM,qBAAqB,QAAkB,CAAC;AAC9C,QAAA,MAAM,yBAAyB,QAA0B,CAAC;AAC1D,QAAA,MAAM,qBAAqB,QAAO,CAAC;AACnC,QAAA,MAAM,aAAa,QAAwB,CAAC;AAC5C,QAAA,MAAM,kBAAkB,QAA+oB,CAAC;AACxqB,QAAA,MAAM,YAAY,QAAO,CAAC;AAK1B,QAAA,MAAM,qBAAqB,EAAc,MAAM,CAAC,MAAM,EAAE,MAAM,CAG3D,CAAC;AAGJ,QAAA,MAAM,gBAAgB,QAA4C,CAAC;AACnE,QAAA,MAAM,gBAAgB,QAAgB,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,EACnB,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,YAAY,EAGZ,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,eAAe,EAChB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS and script content wrapping for minification
|
|
3
|
+
*/
|
|
4
|
+
import type { ProcessedOptions } from './options.js';
|
|
5
|
+
/** @import { ProcessedOptions } from './options.js' */
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} text
|
|
8
|
+
* @param {string} [type]
|
|
9
|
+
*/
|
|
10
|
+
declare function wrapCSS(text: string, type?: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} text
|
|
13
|
+
* @param {string} [type]
|
|
14
|
+
*/
|
|
15
|
+
declare function unwrapCSS(text: string, type?: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} text
|
|
18
|
+
* @param {{continueOnMinifyError?: boolean, log?: Function}} options
|
|
19
|
+
*/
|
|
20
|
+
declare function minifyJson(text: string, options: {
|
|
21
|
+
continueOnMinifyError?: boolean;
|
|
22
|
+
log?: Function;
|
|
23
|
+
}): string;
|
|
24
|
+
/** @param {Array<{name: string, value?: string}>} attrs */
|
|
25
|
+
declare function hasJsonScriptType(attrs: Array<{
|
|
26
|
+
name: string;
|
|
27
|
+
value?: string;
|
|
28
|
+
}>): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* @param {string} text
|
|
31
|
+
* @param {ProcessedOptions} options
|
|
32
|
+
* @param {Array<{name: string, value?: string | undefined}>} currentAttrs
|
|
33
|
+
* @param {Function} minifyHTML
|
|
34
|
+
*/
|
|
35
|
+
declare function processScript(text: string, options: ProcessedOptions, currentAttrs: Array<{
|
|
36
|
+
name: string;
|
|
37
|
+
value?: string | undefined;
|
|
38
|
+
}>, minifyHTML: Function): Promise<any>;
|
|
39
|
+
/**
|
|
40
|
+
* Collects the bodies of executable inline scripts, in document order, so they can be
|
|
41
|
+
* minified as one batch ahead of the parse. Duplicates are dropped: The minifier is
|
|
42
|
+
* content-keyed, so the same body only needs dispatching once.
|
|
43
|
+
* @param {string} html
|
|
44
|
+
* @returns {Array<{code: string, isModule: boolean}>}
|
|
45
|
+
*/
|
|
46
|
+
declare function extractScriptBodies(html: string): Array<{
|
|
47
|
+
code: string;
|
|
48
|
+
isModule: boolean;
|
|
49
|
+
}>;
|
|
50
|
+
export { wrapCSS, unwrapCSS, minifyJson, hasJsonScriptType, extractScriptBodies, processScript };
|
|
51
|
+
//# sourceMappingURL=content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../../src/lib/content.js"],"names":[],"mappings":"AAAA;;GAEG;AASC,OAAQ,KAAA,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAApD,uDAAuD;AAMvD;;;GAGG;AACH,iBAAS,OAAO,CAAC,IAAI,EAHV,MAGU,EAAE,IAAI,AAFxB,CAAsB,EAAd,MAEgB,UAS1B;AAED;;;GAGG;AACH,iBAAS,SAAS,CAAC,IAAI,EAHZ,MAGY,EAAE,IAAI,AAF1B,CAAsB,EAAd,MAEkB,UAW5B;AAKD;;;GAGG;AACH,iBAAS,UAAU,CAAC,IAAI,EAHb,MAGa,EAAE,OAAO,EAFtB;IAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,WAAU;CAE1B,UAWhC;AAED,2DAA2D;AAC3D,iBAAS,iBAAiB,CAAC,KAAK,EADpB,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAC,CAChB,WAU/B;AAED;;;;;GAKG;AACH,iBAAe,aAAa,CAAC,IAAI,EALtB,MAKsB,EAAE,OAAO,EAJ/B,gBAI+B,EAAE,YAAY,EAH7C,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAC,CAGH,EAAE,UAAU,UAAA,gBAiBnE;AAWD;;;;;;GAMG;AACH,iBAAS,mBAAmB,CAAC,IAAI,EAHtB,MAGsB,GAFpB,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAC,CAAC,CAsDpD;AAID,OAAO,EAEL,OAAO,EACP,SAAS,EAGT,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACd,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML element tag omission rules
|
|
3
|
+
*/
|
|
4
|
+
import type { HTMLAttribute } from './attributes.js';
|
|
5
|
+
import type { ProcessedOptions } from './options.js';
|
|
6
|
+
/** @import { HTMLAttribute } from './attributes.js' */
|
|
7
|
+
/** @import { ProcessedOptions } from './options.js' */
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} optionalStartTag
|
|
10
|
+
* @param {string} tag
|
|
11
|
+
*/
|
|
12
|
+
declare function canRemoveParentTag(optionalStartTag: string, tag: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} optionalEndTag
|
|
15
|
+
* @param {string} tag
|
|
16
|
+
*/
|
|
17
|
+
declare function isStartTagMandatory(optionalEndTag: string, tag: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} optionalEndTag
|
|
20
|
+
* @param {string} tag
|
|
21
|
+
*/
|
|
22
|
+
declare function canRemovePrecedingTag(optionalEndTag: string, tag: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} tag
|
|
25
|
+
* @param {HTMLAttribute[]} attrs
|
|
26
|
+
*/
|
|
27
|
+
declare function canRemoveElement(tag: string, attrs: HTMLAttribute[]): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} str - Tag name or HTML-like element spec (e.g., `td` or `<span aria-hidden='true'>`)
|
|
30
|
+
* @param {ProcessedOptions} options - Options object for name normalization
|
|
31
|
+
* @returns {{tag: string, attrs: Object.<string, string|undefined>|null}|null} Parsed spec or null if invalid
|
|
32
|
+
*/
|
|
33
|
+
declare function parseElementSpec(str: string, options: ProcessedOptions): {
|
|
34
|
+
tag: string;
|
|
35
|
+
attrs: Record<string, string | undefined> | null;
|
|
36
|
+
} | null;
|
|
37
|
+
/**
|
|
38
|
+
* @param {string[]} input - Array of element specifications from `removeEmptyElementsExcept` option
|
|
39
|
+
* @param {ProcessedOptions} options - Options object for parsing
|
|
40
|
+
* @returns {Array<{tag: string, attrs: Object.<string, string|undefined>|null}>} Array of parsed element specs
|
|
41
|
+
*/
|
|
42
|
+
declare function parseRemoveEmptyElementsExcept(input: string[], options: ProcessedOptions): Array<{
|
|
43
|
+
tag: string;
|
|
44
|
+
attrs: Record<string, string | undefined> | null;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} tag - Element tag name
|
|
48
|
+
* @param {HTMLAttribute[]} attrs - Array of element attributes
|
|
49
|
+
* @param {Array<{tag: string, attrs: Object.<string, string|undefined>|null}>} preserveList - Parsed preserve specs
|
|
50
|
+
* @returns {boolean} True if the empty element should be preserved
|
|
51
|
+
*/
|
|
52
|
+
declare function shouldPreserveEmptyElement(tag: string, attrs: HTMLAttribute[], preserveList: Array<{
|
|
53
|
+
tag: string;
|
|
54
|
+
attrs: Record<string, string | undefined> | null;
|
|
55
|
+
}>): boolean;
|
|
56
|
+
export { canRemoveParentTag, isStartTagMandatory, canRemovePrecedingTag, canRemoveElement, parseElementSpec, parseRemoveEmptyElementsExcept, shouldPreserveEmptyElement };
|
|
57
|
+
//# sourceMappingURL=elements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../../src/lib/elements.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qBAAqB,EAGrB,gBAAgB,EAChB,gBAAgB,EAChB,8BAA8B,EAC9B,0BAA0B,EAC3B,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom fragment matching
|
|
3
|
+
*
|
|
4
|
+
* `ignoreCustomFragments` patterns nearly always describe the same shape: a literal
|
|
5
|
+
* opening delimiter, an any-character or negated-class body, and a literal closing
|
|
6
|
+
* delimiter, as in `<%[\s\S]*?%>` or `\{\{[^}]*?\}\}`. Such a fragment can be found
|
|
7
|
+
* with `indexOf` in linear time, where running the pattern as a regex costs O(n²)
|
|
8
|
+
* on input that opens fragments it never closes—and can cost far more than that when
|
|
9
|
+
* the pattern itself backtracks. Patterns of other shapes keep running as regexes,
|
|
10
|
+
* one per pattern, so each keeps its own flags.
|
|
11
|
+
*/
|
|
12
|
+
export type DelimitedFragment = {
|
|
13
|
+
open: string;
|
|
14
|
+
close: string;
|
|
15
|
+
min: number;
|
|
16
|
+
max: number;
|
|
17
|
+
excluded: RegExp | null;
|
|
18
|
+
};
|
|
19
|
+
export type PatternFragment = {
|
|
20
|
+
search: RegExp;
|
|
21
|
+
anchored: RegExp;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Describe a fragment pattern as literal delimiters around an any-character body
|
|
25
|
+
* @param {RegExp} pattern
|
|
26
|
+
* @returns {DelimitedFragment | null} Null when the pattern has another shape, which
|
|
27
|
+
* the caller answers by running it as a regex
|
|
28
|
+
*/
|
|
29
|
+
declare function toDelimitedFragment(pattern: RegExp): DelimitedFragment | null;
|
|
30
|
+
/**
|
|
31
|
+
* Prepare a fragment pattern for matching, by scanning where the shape allows it
|
|
32
|
+
* @param {RegExp} pattern
|
|
33
|
+
* @returns {DelimitedFragment | PatternFragment}
|
|
34
|
+
*/
|
|
35
|
+
declare function toFragment(pattern: RegExp): DelimitedFragment | PatternFragment;
|
|
36
|
+
/**
|
|
37
|
+
* Replace runs of custom fragments, and the whitespace padding them
|
|
38
|
+
* @param {string} value - Document to scan
|
|
39
|
+
* @param {(DelimitedFragment | PatternFragment)[]} fragments - In the order the patterns
|
|
40
|
+
* were given, since the earliest match wins and ties go to the pattern listed first
|
|
41
|
+
* @param {(match: string) => string} replacer - Called with each match, as `replace` would
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
declare function replaceCustomFragments(value: string, fragments: (DelimitedFragment | PatternFragment)[], replacer: (match: string) => string): string;
|
|
45
|
+
export { toDelimitedFragment, toFragment, replaceCustomFragments };
|
|
46
|
+
//# sourceMappingURL=fragments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragments.d.ts","sourceRoot":"","sources":["../../../src/lib/fragments.js"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAaA,YAA4F,iBAAiB,GAAnG;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAC,CAI1F;AAAA,YAA8C,eAAe,GAAnD;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAC,CAE9C;AAmCD;;;;;GAKG;AACH,iBAAS,mBAAmB,CAAC,OAAO,EAJzB,MAIyB,GAHvB,iBAAiB,GAAG,IAAI,CAwBpC;AAED;;;;GAIG;AACH,iBAAS,UAAU,CAAC,OAAO,EAHhB,MAGgB,GAFd,iBAAiB,GAAG,eAAe,CAS/C;AAED;;;;;;;GAOG;AACH,iBAAS,sBAAsB,CAAC,KAAK,EAN1B,MAM0B,EAAE,SAAS,EALrC,CAAC,iBAAiB,GAAG,eAAe,CAAC,EAKA,EAAE,QAAQ,EAH/C,CAAC,KAAK,EAAE,MAAM,KAAK,MAG4B,GAF7C,MAAM,CAwJlB;AAID,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,sBAAsB,EACvB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for minifier option names, descriptions, types, and shared defaults
|
|
3
|
+
*/
|
|
4
|
+
export type OptionDefinition = {
|
|
5
|
+
/**
|
|
6
|
+
* Help text, phrased for the option’s primary CLI form
|
|
7
|
+
*/
|
|
8
|
+
description: string;
|
|
9
|
+
/**
|
|
10
|
+
* Help text for what enabling the option does, where `description` describes the negated form
|
|
11
|
+
*/
|
|
12
|
+
descriptionAffirmative?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Key into the parser and JSON Schema type maps in cli.js and scripts/build-schema.js
|
|
15
|
+
*/
|
|
16
|
+
type: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {object} OptionDefinition
|
|
20
|
+
* @property {string} description Help text, phrased for the option’s primary CLI form
|
|
21
|
+
* @property {string} [descriptionAffirmative] Help text for what enabling the option does, where `description` describes the negated form
|
|
22
|
+
* @property {string} type Key into the parser and JSON Schema type maps in cli.js and scripts/build-schema.js
|
|
23
|
+
*/
|
|
24
|
+
/** @type {Record<string, OptionDefinition>} */
|
|
25
|
+
declare const optionDefinitions: Record<string, OptionDefinition>;
|
|
26
|
+
declare const optionDefaults: {
|
|
27
|
+
continueOnMinifyError: boolean;
|
|
28
|
+
ignoreCustomComments: RegExp[];
|
|
29
|
+
ignoreCustomFragments: RegExp[];
|
|
30
|
+
includeAutoGeneratedTags: boolean;
|
|
31
|
+
};
|
|
32
|
+
export { optionDefinitions, optionDefaults };
|
|
33
|
+
//# sourceMappingURL=option-definitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option-definitions.d.ts","sourceRoot":"","sources":["../../../src/lib/option-definitions.js"],"names":[],"mappings":"AAAA;;GAEG;AAGA,YAAkB,gBAAgB,GAClC;;;;IAAmB,WAAW,EAAnB,MAAM,CACjB;;;;IAAoB,sBAAsB,AAA1C,CACA,EADW,MAAM,CACjB;;;;IAAmB,IAAI,EAAZ,MAAM,CACnB;CAAA,CAAA;AALD;;;;;GAKG;AAEH,+CAA+C;AAC/C,QAAA,MAAM,iBAAiB,EADZ,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAuMzC,CAAC;AAEF,QAAA,MAAM,cAAc;IAClB,qBAAqB;IACrB,oBAAoB;IAIpB,qBAAqB;IAIrB,wBAAwB;CACzB,CAAC;AAIF,OAAO,EACL,iBAAiB,EACjB,cAAc,EACf,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options processing and per-document minification state
|
|
3
|
+
*/
|
|
4
|
+
import { LRU } from './utils.js';
|
|
5
|
+
import type { MinifierOptions, HTMLAttribute } from '../htmlminifier.js';
|
|
6
|
+
export type CSSContext = {
|
|
7
|
+
usedSymbols?: Set<string>;
|
|
8
|
+
warned: Set<string>;
|
|
9
|
+
};
|
|
10
|
+
export type CSSResult = {
|
|
11
|
+
css: string;
|
|
12
|
+
warnings: string[];
|
|
13
|
+
};
|
|
14
|
+
export type ProcessedOptions = Omit<MinifierOptions, 'preset' | 'canCollapseWhitespace' | 'canTrimWhitespace' | 'ignoreCustomComments' | 'log' | 'minifyCSS' | 'minifyJS' | 'minifyURLs' | 'minifySVG' | 'removeUnusedCSS'> & {
|
|
15
|
+
name: (name: string) => string;
|
|
16
|
+
log: (message: any) => unknown;
|
|
17
|
+
ignoreCustomComments: RegExp[];
|
|
18
|
+
canCollapseWhitespace: (tag: string, attrs: HTMLAttribute[], defaultFn: (tag: string) => boolean) => boolean;
|
|
19
|
+
canTrimWhitespace: (tag: string, attrs: HTMLAttribute[], defaultFn: (tag: string) => boolean) => boolean;
|
|
20
|
+
minifyCSS: (text: string, type?: string, context?: CSSContext) => string | Promise<string>;
|
|
21
|
+
minifyJS: (text: string, inline?: boolean, isModule?: boolean) => string | Promise<string>;
|
|
22
|
+
minifyURLs: (text: string) => string | Promise<string>;
|
|
23
|
+
minifySVG: ((svgContent: string) => string | Promise<string>) | null;
|
|
24
|
+
removeUnusedCSS: {
|
|
25
|
+
safelist: Array<string | RegExp>;
|
|
26
|
+
scripts: boolean;
|
|
27
|
+
} | null;
|
|
28
|
+
cssContext?: CSSContext;
|
|
29
|
+
parallelJS?: boolean;
|
|
30
|
+
nameParent?: (name: string) => string;
|
|
31
|
+
nameHTML?: (name: string) => string;
|
|
32
|
+
keepClosingSlashHTML?: boolean;
|
|
33
|
+
insideSVG?: boolean;
|
|
34
|
+
insideForeignContent?: boolean;
|
|
35
|
+
};
|
|
36
|
+
/** @import { MinifierOptions, HTMLAttribute } from '../htmlminifier.js' */
|
|
37
|
+
/**
|
|
38
|
+
* Per-document state handed to `minifyCSS`. Its closure hangs off the memoized
|
|
39
|
+
* options object that every `minify()` call with those options shares, so state
|
|
40
|
+
* belonging to one document has to be passed in rather than captured.
|
|
41
|
+
*
|
|
42
|
+
* @typedef {{usedSymbols?: Set<string>, warned: Set<string>}} CSSContext
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* Minified style sheet plus the warnings its transform produced, cached together
|
|
46
|
+
* so that a cache hit can report what the transform reported
|
|
47
|
+
*
|
|
48
|
+
* @typedef {{css: string, warnings: string[]}} CSSResult
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* Options object produced by `processOptions` and consumed by `minifyHTML` and
|
|
52
|
+
* the lib/ helpers; normalization guarantees that the function-valued options
|
|
53
|
+
* below are always present (defaulting to identity/built-in functions), and
|
|
54
|
+
* minification adds writable internal state on top of the public options
|
|
55
|
+
* (set on prototype-chain forks during SVG/MathML namespace transitions)
|
|
56
|
+
*
|
|
57
|
+
* @typedef {Omit<MinifierOptions, 'preset' | 'canCollapseWhitespace' | 'canTrimWhitespace' | 'ignoreCustomComments' | 'log' | 'minifyCSS' | 'minifyJS' | 'minifyURLs' | 'minifySVG' | 'removeUnusedCSS'> & {
|
|
58
|
+
* name: (name: string) => string,
|
|
59
|
+
* log: (message: any) => unknown,
|
|
60
|
+
* ignoreCustomComments: RegExp[],
|
|
61
|
+
* canCollapseWhitespace: (tag: string, attrs: HTMLAttribute[], defaultFn: (tag: string) => boolean) => boolean,
|
|
62
|
+
* canTrimWhitespace: (tag: string, attrs: HTMLAttribute[], defaultFn: (tag: string) => boolean) => boolean,
|
|
63
|
+
* minifyCSS: (text: string, type?: string, context?: CSSContext) => string | Promise<string>,
|
|
64
|
+
* minifyJS: (text: string, inline?: boolean, isModule?: boolean) => string | Promise<string>,
|
|
65
|
+
* minifyURLs: (text: string) => string | Promise<string>,
|
|
66
|
+
* minifySVG: ((svgContent: string) => string | Promise<string>) | null,
|
|
67
|
+
* removeUnusedCSS: {safelist: Array<string | RegExp>, scripts: boolean} | null,
|
|
68
|
+
* cssContext?: CSSContext,
|
|
69
|
+
* parallelJS?: boolean,
|
|
70
|
+
* nameParent?: (name: string) => string,
|
|
71
|
+
* nameHTML?: (name: string) => string,
|
|
72
|
+
* keepClosingSlashHTML?: boolean,
|
|
73
|
+
* insideSVG?: boolean,
|
|
74
|
+
* insideForeignContent?: boolean
|
|
75
|
+
* }} ProcessedOptions
|
|
76
|
+
*/
|
|
77
|
+
/** @param {ProcessedOptions} options */
|
|
78
|
+
declare function shouldMinifyInnerHTML(options: ProcessedOptions): boolean;
|
|
79
|
+
export type OptionDependency = OptionDependency[];
|
|
80
|
+
/**
|
|
81
|
+
* Options that do nothing on their own, and the option each one needs to take effect
|
|
82
|
+
*
|
|
83
|
+
* Cache sizes are deliberately absent: They never change output, so they are
|
|
84
|
+
* configuration for a subsystem rather than a transform that silently fails.
|
|
85
|
+
*
|
|
86
|
+
* @typedef {object} OptionDependency
|
|
87
|
+
* @property {string} option
|
|
88
|
+
* @property {string} requires
|
|
89
|
+
* @property {(input: Record<string, any>) => string | false} [unusable] Clause saying why the prerequisite does not count even though it is set
|
|
90
|
+
* @property {boolean} [clear] Whether to null the option out, where leaving it set would cost work downstream
|
|
91
|
+
*
|
|
92
|
+
* @type {OptionDependency[]}
|
|
93
|
+
*/
|
|
94
|
+
declare const optionDependencies: ({
|
|
95
|
+
option: string;
|
|
96
|
+
requires: string;
|
|
97
|
+
unusable?: never;
|
|
98
|
+
clear?: never;
|
|
99
|
+
} | {
|
|
100
|
+
option: string;
|
|
101
|
+
requires: string;
|
|
102
|
+
unusable: (/** @type {Record<string, any>} */ input: Record<string, any>) => "which a function of your own replaces" | false;
|
|
103
|
+
clear: boolean;
|
|
104
|
+
})[];
|
|
105
|
+
/**
|
|
106
|
+
* @param {MinifierOptions} inputOptions - User-provided options
|
|
107
|
+
* @param {{getLightningCSS?: Function | undefined, getTerser?: Function | undefined, getSwc?: Function | undefined, getSvgo?: Function | undefined, cssMinifyCache?: LRU | undefined, jsMinifyCache?: LRU | undefined, svgMinifyCache?: LRU | undefined}} [deps] - Dependencies from htmlminifier.js
|
|
108
|
+
* @returns {ProcessedOptions} Normalized options with defaults applied
|
|
109
|
+
*/
|
|
110
|
+
declare const processOptions: (inputOptions: MinifierOptions, { getLightningCSS, getTerser, getSwc, getSvgo, cssMinifyCache, jsMinifyCache, svgMinifyCache }?: {
|
|
111
|
+
getLightningCSS?: Function | undefined;
|
|
112
|
+
getTerser?: Function | undefined;
|
|
113
|
+
getSwc?: Function | undefined;
|
|
114
|
+
getSvgo?: Function | undefined;
|
|
115
|
+
cssMinifyCache?: LRU | undefined;
|
|
116
|
+
jsMinifyCache?: LRU | undefined;
|
|
117
|
+
svgMinifyCache?: LRU | undefined;
|
|
118
|
+
}) => ProcessedOptions;
|
|
119
|
+
export { optionDependencies, shouldMinifyInnerHTML, processOptions };
|
|
120
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/lib/options.js"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,GAAG,EAAmJ,MAAM,YAAY,CAAC;AAQ9K,OAAQ,KAAA,EAAE,eAAe,EAAE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