html-crush 5.0.5 → 5.0.11
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/CHANGELOG.md +18 -0
- package/LICENSE +1 -1
- package/README.md +4 -5
- package/dist/html-crush.esm.js +16 -573
- package/dist/html-crush.umd.js +68 -41
- package/examples/_quickTake.js +2 -0
- package/package.json +29 -92
- package/types/index.d.ts +26 -25
- package/examples/api.json +0 -1
package/dist/html-crush.esm.js
CHANGED
|
@@ -1,581 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name html-crush
|
|
3
3
|
* @fileoverview Minifies HTML/CSS: valid or broken, pure or mixed with other languages
|
|
4
|
-
* @version 5.0.
|
|
4
|
+
* @version 5.0.11
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/html-crush/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
removeLineBreaks: false,
|
|
26
|
-
removeHTMLComments: false,
|
|
27
|
-
removeCSSComments: true,
|
|
28
|
-
reportProgressFunc: null,
|
|
29
|
-
reportProgressFuncFrom: 0,
|
|
30
|
-
reportProgressFuncTo: 100,
|
|
31
|
-
breakToTheLeftOf: ["</td", "<html", "</html", "<head", "</head", "<meta", "<link", "<table", "<script", "</script", "<!DOCTYPE", "<style", "</style", "<title", "<body", "@media", "</body", "<!--[if", "<!--<![endif", "<![endif]"],
|
|
32
|
-
mindTheInlineTags: ["a", "abbr", "acronym", "audio", "b", "bdi", "bdo", "big", "br", "button", "canvas", "cite", "code", "data", "datalist", "del", "dfn", "em", "embed", "i", "iframe", "img", "input", "ins", "kbd", "label", "map", "mark", "meter", "noscript", "object", "output", "picture", "progress", "q", "ruby", "s", "samp", "script", "select", "slot", "small", "span", "strong", "sub", "sup", "svg", "template", "textarea", "time", "u", "tt", "var", "video", "wbr"]
|
|
33
|
-
};
|
|
34
|
-
const applicableOpts = {
|
|
35
|
-
removeHTMLComments: false,
|
|
36
|
-
removeCSSComments: false
|
|
37
|
-
};
|
|
38
|
-
function isStr(something) {
|
|
39
|
-
return typeof something === "string";
|
|
40
|
-
}
|
|
41
|
-
function isLetter(something) {
|
|
42
|
-
return typeof something === "string" && something.toUpperCase() !== something.toLowerCase();
|
|
43
|
-
}
|
|
44
|
-
function crush(str, originalOpts) {
|
|
45
|
-
const start = Date.now();
|
|
46
|
-
if (!isStr(str)) {
|
|
47
|
-
if (str === undefined) {
|
|
48
|
-
throw new Error("html-crush: [THROW_ID_01] the first input argument is completely missing! It should be given as string.");
|
|
49
|
-
} else {
|
|
50
|
-
throw new Error(`html-crush: [THROW_ID_02] the first input argument must be string! It was given as "${typeof str}", equal to:\n${JSON.stringify(str, null, 4)}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (originalOpts && typeof originalOpts !== "object") {
|
|
54
|
-
throw new Error(`html-crush: [THROW_ID_03] the second input argument, options object, should be a plain object but it was given as type ${typeof originalOpts}, equal to ${JSON.stringify(originalOpts, null, 4)}`);
|
|
55
|
-
}
|
|
56
|
-
if (originalOpts && Array.isArray(originalOpts.breakToTheLeftOf) && originalOpts.breakToTheLeftOf.length) {
|
|
57
|
-
for (let z = 0, len = originalOpts.breakToTheLeftOf.length; z < len; z++) {
|
|
58
|
-
if (!isStr(originalOpts.breakToTheLeftOf[z])) {
|
|
59
|
-
throw new TypeError(`html-crush: [THROW_ID_05] the opts.breakToTheLeftOf array contains non-string elements! For example, element at index ${z} is of a type "${typeof originalOpts.breakToTheLeftOf[z]}" and is equal to:\n${JSON.stringify(originalOpts.breakToTheLeftOf[z], null, 4)}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const opts = { ...defaults,
|
|
64
|
-
...originalOpts
|
|
65
|
-
};
|
|
66
|
-
if (typeof opts.removeHTMLComments === "boolean") {
|
|
67
|
-
opts.removeHTMLComments = opts.removeHTMLComments ? 1 : 0;
|
|
68
|
-
}
|
|
69
|
-
let breakToTheLeftOfFirstLetters = "";
|
|
70
|
-
if (Array.isArray(opts.breakToTheLeftOf) && opts.breakToTheLeftOf.length) {
|
|
71
|
-
breakToTheLeftOfFirstLetters = [...new Set(opts.breakToTheLeftOf.map(val => val[0]))].join("");
|
|
72
|
-
}
|
|
73
|
-
let lastLinebreak = null;
|
|
74
|
-
let whitespaceStartedAt = null;
|
|
75
|
-
let nonWhitespaceCharMet = false;
|
|
76
|
-
let countCharactersPerLine = 0;
|
|
77
|
-
let cpl = 0;
|
|
78
|
-
let withinStyleTag = false;
|
|
79
|
-
let withinHTMLConditional = false;
|
|
80
|
-
let withinInlineStyle = null;
|
|
81
|
-
let styleCommentStartedAt = null;
|
|
82
|
-
let htmlCommentStartedAt = null;
|
|
83
|
-
let scriptStartedAt = null;
|
|
84
|
-
let doNothing;
|
|
85
|
-
let stageFrom = null;
|
|
86
|
-
let stageTo = null;
|
|
87
|
-
let stageAdd = null;
|
|
88
|
-
let tagName = null;
|
|
89
|
-
let tagNameStartsAt = null;
|
|
90
|
-
let leftTagName = null;
|
|
91
|
-
const CHARS_BREAK_ON_THE_RIGHT_OF_THEM = `>};`;
|
|
92
|
-
const CHARS_BREAK_ON_THE_LEFT_OF_THEM = `<`;
|
|
93
|
-
const CHARS_DONT_BREAK_ON_THE_LEFT_OF_THEM = `!`;
|
|
94
|
-
const DELETE_TIGHTLY_IF_ON_LEFT_IS = `>`;
|
|
95
|
-
const DELETE_TIGHTLY_IF_ON_RIGHT_IS = `<`;
|
|
96
|
-
const set = `{},:;<>~+`;
|
|
97
|
-
const DELETE_IN_STYLE_TIGHTLY_IF_ON_LEFT_IS = set;
|
|
98
|
-
const DELETE_IN_STYLE_TIGHTLY_IF_ON_RIGHT_IS = set;
|
|
99
|
-
let beginningOfAFile = true;
|
|
100
|
-
const len = str.length;
|
|
101
|
-
const midLen = Math.floor(len / 2);
|
|
102
|
-
const leavePercForLastStage = 0.01;
|
|
103
|
-
let ceil;
|
|
104
|
-
if (opts.reportProgressFunc) {
|
|
105
|
-
ceil = Math.floor(opts.reportProgressFuncTo - (opts.reportProgressFuncTo - opts.reportProgressFuncFrom) * leavePercForLastStage - opts.reportProgressFuncFrom);
|
|
106
|
-
}
|
|
107
|
-
let currentPercentageDone;
|
|
108
|
-
let lastPercentage = 0;
|
|
109
|
-
let lineEnding = `\n`;
|
|
110
|
-
if (str.includes(`\r\n`)) {
|
|
111
|
-
lineEnding = `\r\n`;
|
|
112
|
-
} else if (str.includes(`\r`)) {
|
|
113
|
-
lineEnding = `\r`;
|
|
114
|
-
}
|
|
115
|
-
if (len) {
|
|
116
|
-
for (let i = 0; i < len; i++) {
|
|
117
|
-
if (opts.reportProgressFunc) {
|
|
118
|
-
if (len > 1000 && len < 2000) {
|
|
119
|
-
if (i === midLen) {
|
|
120
|
-
opts.reportProgressFunc(Math.floor((opts.reportProgressFuncTo - opts.reportProgressFuncFrom) / 2));
|
|
121
|
-
}
|
|
122
|
-
} else if (len >= 2000) {
|
|
123
|
-
currentPercentageDone = opts.reportProgressFuncFrom + Math.floor(i / len * (ceil || 1));
|
|
124
|
-
if (currentPercentageDone !== lastPercentage) {
|
|
125
|
-
lastPercentage = currentPercentageDone;
|
|
126
|
-
opts.reportProgressFunc(currentPercentageDone);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
cpl++;
|
|
131
|
-
if (!doNothing && withinStyleTag && str[i] === "}" && str[i - 1] === "}") {
|
|
132
|
-
if (countCharactersPerLine + 1 >= opts.lineLengthLimit) {
|
|
133
|
-
finalIndexesToDelete.push(i, i, lineEnding);
|
|
134
|
-
countCharactersPerLine = 0;
|
|
135
|
-
} else {
|
|
136
|
-
stageFrom = i;
|
|
137
|
-
stageTo = i;
|
|
138
|
-
stageAdd = " ";
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (doNothing && typeof doNothing === "number" && i >= doNothing) {
|
|
142
|
-
doNothing = undefined;
|
|
143
|
-
}
|
|
144
|
-
if (scriptStartedAt !== null && str.startsWith("</script", i) && !isLetter(str[i + 8])) {
|
|
145
|
-
if ((opts.removeIndentations || opts.removeLineBreaks) && i > 0 && str[~-i] && !str[~-i].trim()) {
|
|
146
|
-
for (let y = i; y--;) {
|
|
147
|
-
if (str[y] === "\n" || str[y] === "\r" || str[y].trim()) {
|
|
148
|
-
if (y + 1 < i) {
|
|
149
|
-
finalIndexesToDelete.push(y + 1, i);
|
|
150
|
-
}
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
scriptStartedAt = null;
|
|
156
|
-
doNothing = false;
|
|
157
|
-
i += 8;
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (!doNothing && !withinStyleTag && str.startsWith("<script", i) && !isLetter(str[i + 7])) {
|
|
161
|
-
scriptStartedAt = i;
|
|
162
|
-
doNothing = true;
|
|
163
|
-
let whatToInsert = "";
|
|
164
|
-
if ((opts.removeLineBreaks || opts.removeIndentations) && whitespaceStartedAt !== null) {
|
|
165
|
-
if (whitespaceStartedAt > 0) {
|
|
166
|
-
whatToInsert = lineEnding;
|
|
167
|
-
}
|
|
168
|
-
finalIndexesToDelete.push(whitespaceStartedAt, i, whatToInsert);
|
|
169
|
-
}
|
|
170
|
-
whitespaceStartedAt = null;
|
|
171
|
-
lastLinebreak = null;
|
|
172
|
-
}
|
|
173
|
-
if (tagNameStartsAt !== null && tagName === null && !/\w/.test(str[i])
|
|
174
|
-
) {
|
|
175
|
-
tagName = str.slice(tagNameStartsAt, i);
|
|
176
|
-
const idxOnTheRight = right(str, ~-i);
|
|
177
|
-
if (typeof idxOnTheRight === "number" && str[idxOnTheRight] === ">" && !str[i].trim() && right(str, i)) {
|
|
178
|
-
finalIndexesToDelete.push(i, right(str, i));
|
|
179
|
-
} else if (idxOnTheRight && str[idxOnTheRight] === "/" && str[right(str, idxOnTheRight)] === ">") {
|
|
180
|
-
if (!str[i].trim() && right(str, i)) {
|
|
181
|
-
finalIndexesToDelete.push(i, right(str, i));
|
|
182
|
-
}
|
|
183
|
-
if (str[idxOnTheRight + 1] !== ">" && right(str, idxOnTheRight + 1)) {
|
|
184
|
-
finalIndexesToDelete.push(idxOnTheRight + 1, right(str, idxOnTheRight + 1));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (!doNothing && !withinStyleTag && !withinInlineStyle && str[~-i] === "<" && tagNameStartsAt === null) {
|
|
189
|
-
if (/\w/.test(str[i])) {
|
|
190
|
-
tagNameStartsAt = i;
|
|
191
|
-
} else if (str[right(str, ~-i)] === "/" && /\w/.test(str[right(str, right(str, ~-i))] || "")) {
|
|
192
|
-
tagNameStartsAt = right(str, right(str, ~-i));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (!doNothing && (withinStyleTag || withinInlineStyle) && styleCommentStartedAt !== null && str[i] === "*" && str[i + 1] === "/") {
|
|
196
|
-
[stageFrom, stageTo] = expander({
|
|
197
|
-
str,
|
|
198
|
-
from: styleCommentStartedAt,
|
|
199
|
-
to: i + 2,
|
|
200
|
-
ifLeftSideIncludesThisThenCropTightly: DELETE_IN_STYLE_TIGHTLY_IF_ON_LEFT_IS ,
|
|
201
|
-
ifRightSideIncludesThisThenCropTightly: DELETE_IN_STYLE_TIGHTLY_IF_ON_RIGHT_IS
|
|
202
|
-
});
|
|
203
|
-
styleCommentStartedAt = null;
|
|
204
|
-
if (stageFrom != null) {
|
|
205
|
-
finalIndexesToDelete.push(stageFrom, stageTo);
|
|
206
|
-
} else {
|
|
207
|
-
countCharactersPerLine += 1;
|
|
208
|
-
i += 1;
|
|
209
|
-
}
|
|
210
|
-
doNothing = i + 2;
|
|
211
|
-
}
|
|
212
|
-
if (!doNothing && (withinStyleTag || withinInlineStyle) && styleCommentStartedAt === null && str[i] === "/" && str[i + 1] === "*") {
|
|
213
|
-
if (!applicableOpts.removeCSSComments) {
|
|
214
|
-
applicableOpts.removeCSSComments = true;
|
|
215
|
-
}
|
|
216
|
-
if (opts.removeCSSComments) {
|
|
217
|
-
styleCommentStartedAt = i;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (withinHTMLConditional && str.startsWith("![endif", i + 1)) {
|
|
221
|
-
withinHTMLConditional = false;
|
|
222
|
-
}
|
|
223
|
-
if (!doNothing && !withinStyleTag && !withinInlineStyle && htmlCommentStartedAt !== null) {
|
|
224
|
-
let distanceFromHereToCommentEnding;
|
|
225
|
-
if (str.startsWith("-->", i)) {
|
|
226
|
-
distanceFromHereToCommentEnding = 3;
|
|
227
|
-
} else if (str[i] === ">" && str[i - 1] === "]") {
|
|
228
|
-
distanceFromHereToCommentEnding = 1;
|
|
229
|
-
}
|
|
230
|
-
if (distanceFromHereToCommentEnding) {
|
|
231
|
-
[stageFrom, stageTo] = expander({
|
|
232
|
-
str,
|
|
233
|
-
from: htmlCommentStartedAt,
|
|
234
|
-
to: i + distanceFromHereToCommentEnding
|
|
235
|
-
});
|
|
236
|
-
htmlCommentStartedAt = null;
|
|
237
|
-
if (stageFrom != null) {
|
|
238
|
-
if (opts.lineLengthLimit && cpl - (stageTo - stageFrom) >= opts.lineLengthLimit) {
|
|
239
|
-
finalIndexesToDelete.push(stageFrom, stageTo, lineEnding);
|
|
240
|
-
cpl = -distanceFromHereToCommentEnding;
|
|
241
|
-
} else {
|
|
242
|
-
finalIndexesToDelete.push(stageFrom, stageTo);
|
|
243
|
-
cpl -= stageTo - stageFrom;
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
countCharactersPerLine += distanceFromHereToCommentEnding - 1;
|
|
247
|
-
i += distanceFromHereToCommentEnding - 1;
|
|
248
|
-
}
|
|
249
|
-
doNothing = i + distanceFromHereToCommentEnding;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
if (!doNothing && !withinStyleTag && !withinInlineStyle && str.startsWith("<!--", i) && htmlCommentStartedAt === null) {
|
|
253
|
-
if (str.startsWith("[if", i + 4)) {
|
|
254
|
-
if (!withinHTMLConditional) {
|
|
255
|
-
withinHTMLConditional = true;
|
|
256
|
-
}
|
|
257
|
-
if (opts.removeHTMLComments === 2) {
|
|
258
|
-
htmlCommentStartedAt = i;
|
|
259
|
-
}
|
|
260
|
-
} else if (
|
|
261
|
-
opts.removeHTMLComments && (
|
|
262
|
-
!withinHTMLConditional || opts.removeHTMLComments === 2)) {
|
|
263
|
-
htmlCommentStartedAt = i;
|
|
264
|
-
}
|
|
265
|
-
if (!applicableOpts.removeHTMLComments) {
|
|
266
|
-
applicableOpts.removeHTMLComments = true;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
if (!doNothing && withinStyleTag && styleCommentStartedAt === null && str.startsWith("</style", i) && !isLetter(str[i + 7])) {
|
|
270
|
-
withinStyleTag = false;
|
|
271
|
-
} else if (!doNothing && !withinStyleTag && styleCommentStartedAt === null && str.startsWith("<style", i) && !isLetter(str[i + 6])) {
|
|
272
|
-
withinStyleTag = true;
|
|
273
|
-
if ((opts.removeLineBreaks || opts.removeIndentations) && opts.breakToTheLeftOf.includes("<style") && str.startsWith(` type="text/css">`, i + 6) && str[i + 24]) {
|
|
274
|
-
finalIndexesToDelete.push(i + 23, i + 23, lineEnding);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
if (!doNothing && !withinInlineStyle && `"'`.includes(str[i]) && str.endsWith("style=", i)) {
|
|
278
|
-
withinInlineStyle = i;
|
|
279
|
-
}
|
|
280
|
-
if (!doNothing && !str[i].trim()) {
|
|
281
|
-
if (whitespaceStartedAt === null) {
|
|
282
|
-
whitespaceStartedAt = i;
|
|
283
|
-
}
|
|
284
|
-
} else if (!doNothing && !((withinStyleTag || withinInlineStyle) && styleCommentStartedAt !== null)) {
|
|
285
|
-
if (whitespaceStartedAt !== null) {
|
|
286
|
-
if (opts.removeLineBreaks) {
|
|
287
|
-
countCharactersPerLine += 1;
|
|
288
|
-
}
|
|
289
|
-
if (beginningOfAFile) {
|
|
290
|
-
beginningOfAFile = false;
|
|
291
|
-
if (opts.removeIndentations || opts.removeLineBreaks) {
|
|
292
|
-
finalIndexesToDelete.push(0, i);
|
|
293
|
-
}
|
|
294
|
-
} else {
|
|
295
|
-
if (opts.removeIndentations && !opts.removeLineBreaks) {
|
|
296
|
-
if (!nonWhitespaceCharMet && lastLinebreak !== null && i > lastLinebreak) {
|
|
297
|
-
finalIndexesToDelete.push(lastLinebreak + 1, i);
|
|
298
|
-
} else if (whitespaceStartedAt + 1 < i) {
|
|
299
|
-
if (
|
|
300
|
-
str.endsWith("]>", whitespaceStartedAt) ||
|
|
301
|
-
str.endsWith("-->", whitespaceStartedAt) ||
|
|
302
|
-
str.startsWith("<![", i) ||
|
|
303
|
-
str.startsWith("<!--<![", i)) {
|
|
304
|
-
finalIndexesToDelete.push(whitespaceStartedAt, i);
|
|
305
|
-
} else if (str[whitespaceStartedAt] === " ") {
|
|
306
|
-
finalIndexesToDelete.push(whitespaceStartedAt + 1, i);
|
|
307
|
-
} else if (str[~-i] === " ") {
|
|
308
|
-
finalIndexesToDelete.push(whitespaceStartedAt, ~-i);
|
|
309
|
-
} else {
|
|
310
|
-
finalIndexesToDelete.push(whitespaceStartedAt, i, " ");
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
if (opts.removeLineBreaks || withinInlineStyle) {
|
|
315
|
-
if (breakToTheLeftOfFirstLetters.includes(str[i]) && matchRightIncl(str, i, opts.breakToTheLeftOf)) {
|
|
316
|
-
if (
|
|
317
|
-
!(`\r\n`.includes(str[~-i]) && whitespaceStartedAt === ~-i) &&
|
|
318
|
-
!(str[~-i] === "\n" && str[i - 2] === "\r" && whitespaceStartedAt === i - 2)) {
|
|
319
|
-
finalIndexesToDelete.push(whitespaceStartedAt, i, lineEnding);
|
|
320
|
-
}
|
|
321
|
-
stageFrom = null;
|
|
322
|
-
stageTo = null;
|
|
323
|
-
stageAdd = null;
|
|
324
|
-
whitespaceStartedAt = null;
|
|
325
|
-
countCharactersPerLine = 1;
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
let whatToAdd = " ";
|
|
329
|
-
if (
|
|
330
|
-
str[i] === "<" && matchRight(str, i, opts.mindTheInlineTags, {
|
|
331
|
-
cb: nextChar => !nextChar || !/\w/.test(nextChar)
|
|
332
|
-
})
|
|
333
|
-
) ; else if (str[~-whitespaceStartedAt] && DELETE_TIGHTLY_IF_ON_LEFT_IS.includes(str[~-whitespaceStartedAt]) && DELETE_TIGHTLY_IF_ON_RIGHT_IS.includes(str[i]) || (withinStyleTag || withinInlineStyle) && styleCommentStartedAt === null && (DELETE_IN_STYLE_TIGHTLY_IF_ON_LEFT_IS.includes(str[~-whitespaceStartedAt]) || DELETE_IN_STYLE_TIGHTLY_IF_ON_RIGHT_IS.includes(str[i])) || str.startsWith("!important", i) && !withinHTMLConditional || withinInlineStyle && (str[~-whitespaceStartedAt] === "'" || str[~-whitespaceStartedAt] === '"') || str[~-whitespaceStartedAt] === "}" && str.startsWith("</style", i) || str[i] === ">" && (`'"`.includes(str[left(str, i)]) || str[right(str, i)] === "<") || str[i] === "/" && str[right(str, i)] === ">") {
|
|
334
|
-
whatToAdd = "";
|
|
335
|
-
if (str[i] === "/" && str[i + 1] === ">" && right(str, i) && right(str, i) > i + 1) {
|
|
336
|
-
finalIndexesToDelete.push(i + 1, right(str, i));
|
|
337
|
-
countCharactersPerLine -= right(str, i) - i + 1;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
if (withinStyleTag && str[i] === "}" && whitespaceStartedAt && str[whitespaceStartedAt - 1] === "}") {
|
|
341
|
-
whatToAdd = " ";
|
|
342
|
-
}
|
|
343
|
-
if (whatToAdd && whatToAdd.length) {
|
|
344
|
-
countCharactersPerLine += 1;
|
|
345
|
-
}
|
|
346
|
-
if (!opts.lineLengthLimit) {
|
|
347
|
-
if (!(i === whitespaceStartedAt + 1 &&
|
|
348
|
-
whatToAdd === " ")) {
|
|
349
|
-
finalIndexesToDelete.push(whitespaceStartedAt, i, whatToAdd);
|
|
350
|
-
}
|
|
351
|
-
} else {
|
|
352
|
-
if (countCharactersPerLine >= opts.lineLengthLimit || !str[i + 1] || str[i] === ">" || str[i] === "/" && str[i + 1] === ">") {
|
|
353
|
-
if (countCharactersPerLine > opts.lineLengthLimit || countCharactersPerLine === opts.lineLengthLimit && str[i + 1] && str[i + 1].trim() && !CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[i]) && !CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i + 1])) {
|
|
354
|
-
whatToAdd = lineEnding;
|
|
355
|
-
countCharactersPerLine = 1;
|
|
356
|
-
}
|
|
357
|
-
if (countCharactersPerLine > opts.lineLengthLimit || !(whatToAdd === " " && i === whitespaceStartedAt + 1)) {
|
|
358
|
-
finalIndexesToDelete.push(whitespaceStartedAt, i, whatToAdd);
|
|
359
|
-
lastLinebreak = null;
|
|
360
|
-
}
|
|
361
|
-
stageFrom = null;
|
|
362
|
-
stageTo = null;
|
|
363
|
-
stageAdd = null;
|
|
364
|
-
} else if (stageFrom === null || whitespaceStartedAt < stageFrom) {
|
|
365
|
-
stageFrom = whitespaceStartedAt;
|
|
366
|
-
stageTo = i;
|
|
367
|
-
stageAdd = whatToAdd;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
whitespaceStartedAt = null;
|
|
373
|
-
if (!nonWhitespaceCharMet) {
|
|
374
|
-
nonWhitespaceCharMet = true;
|
|
375
|
-
}
|
|
376
|
-
} else {
|
|
377
|
-
if (beginningOfAFile) {
|
|
378
|
-
beginningOfAFile = false;
|
|
379
|
-
}
|
|
380
|
-
if (opts.removeLineBreaks) {
|
|
381
|
-
countCharactersPerLine += 1;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
if (!nonWhitespaceCharMet) {
|
|
385
|
-
nonWhitespaceCharMet = true;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
if (!doNothing && !beginningOfAFile && i !== 0 && opts.removeLineBreaks && (opts.lineLengthLimit || breakToTheLeftOfFirstLetters) && !str.startsWith("</a", i)) {
|
|
389
|
-
if (breakToTheLeftOfFirstLetters && matchRightIncl(str, i, opts.breakToTheLeftOf) && str.slice(0, i).trim() && (!str.startsWith("<![endif]", i) || !matchLeft(str, i, "<!--"))) {
|
|
390
|
-
finalIndexesToDelete.push(i, i, lineEnding);
|
|
391
|
-
stageFrom = null;
|
|
392
|
-
stageTo = null;
|
|
393
|
-
stageAdd = null;
|
|
394
|
-
countCharactersPerLine = 1;
|
|
395
|
-
continue;
|
|
396
|
-
} else if (opts.lineLengthLimit && countCharactersPerLine <= opts.lineLengthLimit) {
|
|
397
|
-
if (!str[i + 1] || CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) && !CHARS_DONT_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) || CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[i]) || !str[i].trim()) {
|
|
398
|
-
if (stageFrom !== null && stageTo !== null && (stageFrom !== stageTo || stageAdd && stageAdd.length)) {
|
|
399
|
-
let whatToAdd = stageAdd;
|
|
400
|
-
if (str[i].trim() && str[i + 1] && str[i + 1].trim() && countCharactersPerLine + (stageAdd ? stageAdd.length : 0) > opts.lineLengthLimit) {
|
|
401
|
-
whatToAdd = lineEnding;
|
|
402
|
-
}
|
|
403
|
-
if (countCharactersPerLine + (whatToAdd ? whatToAdd.length : 0) > opts.lineLengthLimit || !(whatToAdd === " " && stageTo === stageFrom + 1 && str[stageFrom] === " ")) {
|
|
404
|
-
if (!(str[~-stageFrom] === "}" && str[stageTo] === "{")) {
|
|
405
|
-
finalIndexesToDelete.push(stageFrom, stageTo, whatToAdd);
|
|
406
|
-
lastLinebreak = null;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
if (str[i].trim() && (CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) || str[~-i] && CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[~-i])) && isStr(leftTagName) && (!tagName || !opts.mindTheInlineTags.includes(tagName)) && !(str[i] === "<" && matchRight(str, i, opts.mindTheInlineTags, {
|
|
411
|
-
cb: nextChar => !nextChar || !/\w/.test(nextChar)
|
|
412
|
-
})) && !(str[i] === "<" && matchRight(str, i, opts.mindTheInlineTags, {
|
|
413
|
-
trimCharsBeforeMatching: "/",
|
|
414
|
-
cb: nextChar => !nextChar || !/\w/.test(nextChar)
|
|
415
|
-
}))) {
|
|
416
|
-
stageFrom = i;
|
|
417
|
-
stageTo = i;
|
|
418
|
-
stageAdd = null;
|
|
419
|
-
} else if (styleCommentStartedAt === null && stageFrom !== null && (withinInlineStyle || !opts.mindTheInlineTags || !Array.isArray(opts.mindTheInlineTags) || Array.isArray(opts.mindTheInlineTags.length) && !opts.mindTheInlineTags.length || !isStr(tagName) || Array.isArray(opts.mindTheInlineTags) && opts.mindTheInlineTags.length && isStr(tagName) && !opts.mindTheInlineTags.includes(tagName)) && !(str[i] === "<" && matchRight(str, i, opts.mindTheInlineTags, {
|
|
420
|
-
trimCharsBeforeMatching: "/",
|
|
421
|
-
cb: nextChar => !nextChar || !/\w/.test(nextChar)
|
|
422
|
-
}))) {
|
|
423
|
-
stageFrom = null;
|
|
424
|
-
stageTo = null;
|
|
425
|
-
stageAdd = null;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
} else if (opts.lineLengthLimit) {
|
|
429
|
-
if (CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) && !(str[i] === "<" && matchRight(str, i, opts.mindTheInlineTags, {
|
|
430
|
-
trimCharsBeforeMatching: "/",
|
|
431
|
-
cb: nextChar => !nextChar || !/\w/.test(nextChar)
|
|
432
|
-
}))) {
|
|
433
|
-
if (stageFrom !== null && stageTo !== null && (stageFrom !== stageTo || stageAdd && stageAdd.length)) {
|
|
434
|
-
const whatToAddLength = stageAdd && stageAdd.length ? stageAdd.length : 0;
|
|
435
|
-
if (countCharactersPerLine - (stageTo - stageFrom - whatToAddLength) - 1 > opts.lineLengthLimit) ; else {
|
|
436
|
-
finalIndexesToDelete.push(stageFrom, stageTo, stageAdd);
|
|
437
|
-
if (countCharactersPerLine - (stageTo - stageFrom - whatToAddLength) - 1 === opts.lineLengthLimit) {
|
|
438
|
-
finalIndexesToDelete.push(i, i, lineEnding);
|
|
439
|
-
countCharactersPerLine = 0;
|
|
440
|
-
}
|
|
441
|
-
stageFrom = null;
|
|
442
|
-
stageTo = null;
|
|
443
|
-
stageAdd = null;
|
|
444
|
-
}
|
|
445
|
-
} else {
|
|
446
|
-
finalIndexesToDelete.push(i, i, lineEnding);
|
|
447
|
-
countCharactersPerLine = 0;
|
|
448
|
-
}
|
|
449
|
-
} else if (str[i + 1] && CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[i]) && isStr(tagName) && Array.isArray(opts.mindTheInlineTags) && opts.mindTheInlineTags.length && !opts.mindTheInlineTags.includes(tagName)) {
|
|
450
|
-
if (stageFrom !== null && stageTo !== null && (stageFrom !== stageTo || stageAdd && stageAdd.length)) ; else {
|
|
451
|
-
finalIndexesToDelete.push(i + 1, i + 1, lineEnding);
|
|
452
|
-
countCharactersPerLine = 0;
|
|
453
|
-
}
|
|
454
|
-
} else if (!str[i].trim()) ; else if (!str[i + 1]) {
|
|
455
|
-
if (stageFrom !== null && stageTo !== null && (stageFrom !== stageTo || stageAdd && stageAdd.length)) {
|
|
456
|
-
finalIndexesToDelete.push(stageFrom, stageTo, lineEnding);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
if (!doNothing && !beginningOfAFile && opts.removeLineBreaks && opts.lineLengthLimit && countCharactersPerLine >= opts.lineLengthLimit && stageFrom !== null && stageTo !== null && !CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[i]) && !CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) && !"/".includes(str[i])) {
|
|
462
|
-
if (!(countCharactersPerLine === opts.lineLengthLimit && str[i + 1] && !str[i + 1].trim())) {
|
|
463
|
-
let whatToAdd = lineEnding;
|
|
464
|
-
if (str[i + 1] && !str[i + 1].trim() && countCharactersPerLine === opts.lineLengthLimit) {
|
|
465
|
-
whatToAdd = stageAdd;
|
|
466
|
-
}
|
|
467
|
-
if (whatToAdd === lineEnding && !str[~-stageFrom].trim() && left(str, stageFrom)) {
|
|
468
|
-
stageFrom = left(str, stageFrom) + 1;
|
|
469
|
-
}
|
|
470
|
-
finalIndexesToDelete.push(stageFrom, stageTo, whatToAdd);
|
|
471
|
-
countCharactersPerLine = i - stageTo;
|
|
472
|
-
if (str[i].length) {
|
|
473
|
-
countCharactersPerLine += 1;
|
|
474
|
-
}
|
|
475
|
-
stageFrom = null;
|
|
476
|
-
stageTo = null;
|
|
477
|
-
stageAdd = null;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
if (!doNothing && str[i] === "\n" || str[i] === "\r" && (!str[i + 1] || str[i + 1] && str[i + 1] !== "\n")) {
|
|
481
|
-
lastLinebreak = i;
|
|
482
|
-
if (nonWhitespaceCharMet) {
|
|
483
|
-
nonWhitespaceCharMet = false;
|
|
484
|
-
}
|
|
485
|
-
if (!opts.removeLineBreaks && whitespaceStartedAt !== null && whitespaceStartedAt < i && str[i + 1] && str[i + 1] !== "\r" && str[i + 1] !== "\n") {
|
|
486
|
-
finalIndexesToDelete.push(whitespaceStartedAt, i);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if (!str[i + 1]) {
|
|
490
|
-
if (withinStyleTag && styleCommentStartedAt !== null) {
|
|
491
|
-
finalIndexesToDelete.push(...expander({
|
|
492
|
-
str,
|
|
493
|
-
from: styleCommentStartedAt,
|
|
494
|
-
to: i,
|
|
495
|
-
ifLeftSideIncludesThisThenCropTightly: DELETE_IN_STYLE_TIGHTLY_IF_ON_LEFT_IS ,
|
|
496
|
-
ifRightSideIncludesThisThenCropTightly: DELETE_IN_STYLE_TIGHTLY_IF_ON_RIGHT_IS
|
|
497
|
-
}));
|
|
498
|
-
} else if (whitespaceStartedAt && str[i] !== "\n" && str[i] !== "\r") {
|
|
499
|
-
finalIndexesToDelete.push(whitespaceStartedAt, i + 1);
|
|
500
|
-
} else if (whitespaceStartedAt && (str[i] === "\r" && str[i + 1] === "\n" || str[i] === "\n" && str[i - 1] !== "\r")) {
|
|
501
|
-
finalIndexesToDelete.push(whitespaceStartedAt, i);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
if (!doNothing && withinInlineStyle && withinInlineStyle < i && str[withinInlineStyle] === str[i]) {
|
|
505
|
-
withinInlineStyle = null;
|
|
506
|
-
}
|
|
507
|
-
if (!doNothing && !withinStyleTag && str.startsWith("<pre", i) && !isLetter(str[i + 4])) {
|
|
508
|
-
const locationOfClosingPre = str.indexOf("</pre", i + 5);
|
|
509
|
-
if (locationOfClosingPre > 0) {
|
|
510
|
-
doNothing = locationOfClosingPre;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
if (!doNothing && !withinStyleTag && str.startsWith("<code", i) && !isLetter(str[i + 5])) {
|
|
514
|
-
const locationOfClosingCode = str.indexOf("</code", i + 5);
|
|
515
|
-
if (locationOfClosingCode > 0) {
|
|
516
|
-
doNothing = locationOfClosingCode;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
if (!doNothing && str.startsWith("<![CDATA[", i)) {
|
|
520
|
-
const locationOfClosingCData = str.indexOf("]]>", i + 9);
|
|
521
|
-
if (locationOfClosingCData > 0) {
|
|
522
|
-
doNothing = locationOfClosingCData;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
if (!doNothing && !withinStyleTag && !withinInlineStyle && tagNameStartsAt !== null && str[i] === ">") {
|
|
526
|
-
if (str[right(str, i)] === "<") {
|
|
527
|
-
leftTagName = tagName;
|
|
528
|
-
}
|
|
529
|
-
tagNameStartsAt = null;
|
|
530
|
-
tagName = null;
|
|
531
|
-
}
|
|
532
|
-
if (str[i] === "<" && leftTagName !== null) {
|
|
533
|
-
leftTagName = null;
|
|
534
|
-
}
|
|
535
|
-
if (withinStyleTag && str[i] === "{" && str[i + 1] === "{" && str.indexOf("}}") !== -1) {
|
|
536
|
-
doNothing = str.indexOf("}}") + 2;
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
if (finalIndexesToDelete.current()) {
|
|
540
|
-
const ranges = finalIndexesToDelete.current();
|
|
541
|
-
finalIndexesToDelete.wipe();
|
|
542
|
-
const startingPercentageDone = opts.reportProgressFuncTo - (opts.reportProgressFuncTo - opts.reportProgressFuncFrom) * leavePercForLastStage;
|
|
543
|
-
const res = rApply(str, ranges, applyPercDone => {
|
|
544
|
-
if (opts.reportProgressFunc && len >= 2000) {
|
|
545
|
-
currentPercentageDone = Math.floor(startingPercentageDone + (opts.reportProgressFuncTo - startingPercentageDone) * (applyPercDone / 100));
|
|
546
|
-
if (currentPercentageDone !== lastPercentage) {
|
|
547
|
-
lastPercentage = currentPercentageDone;
|
|
548
|
-
opts.reportProgressFunc(currentPercentageDone);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
const resLen = res.length;
|
|
553
|
-
return {
|
|
554
|
-
log: {
|
|
555
|
-
timeTakenInMilliseconds: Date.now() - start,
|
|
556
|
-
originalLength: len,
|
|
557
|
-
cleanedLength: resLen,
|
|
558
|
-
bytesSaved: Math.max(len - resLen, 0),
|
|
559
|
-
percentageReducedOfOriginal: len ? Math.round(Math.max(len - resLen, 0) * 100 / len) : 0
|
|
560
|
-
},
|
|
561
|
-
ranges,
|
|
562
|
-
applicableOpts,
|
|
563
|
-
result: res
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return {
|
|
568
|
-
log: {
|
|
569
|
-
timeTakenInMilliseconds: Date.now() - start,
|
|
570
|
-
originalLength: len,
|
|
571
|
-
cleanedLength: len,
|
|
572
|
-
bytesSaved: 0,
|
|
573
|
-
percentageReducedOfOriginal: 0
|
|
574
|
-
},
|
|
575
|
-
applicableOpts,
|
|
576
|
-
ranges: null,
|
|
577
|
-
result: str
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
export { crush, defaults, version };
|
|
10
|
+
import{rApply as ne}from"ranges-apply";import{Ranges as le}from"ranges-push";import{matchLeft as oe,matchRight as F,matchRightIncl as X}from"string-match-left-right";import{expander as _}from"string-range-expander";import{left as G,right as a}from"string-left-right";var Y="5.0.11";var ge=Y,$=new le({limitToBeAddedWhitespace:!0}),te={lineLengthLimit:500,removeIndentations:!0,removeLineBreaks:!1,removeHTMLComments:!1,removeCSSComments:!0,reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100,breakToTheLeftOf:["</td","<html","</html","<head","</head","<meta","<link","<table","<script","<\/script","<!DOCTYPE","<style","</style","<title","<body","@media","</body","<!--[if","<!--<![endif","<![endif]"],mindTheInlineTags:["a","abbr","acronym","audio","b","bdi","bdo","big","br","button","canvas","cite","code","data","datalist","del","dfn","em","embed","i","iframe","img","input","ins","kbd","label","map","mark","meter","noscript","object","output","picture","progress","q","ruby","s","samp","script","select","slot","small","span","strong","sub","sup","svg","template","textarea","time","u","tt","var","video","wbr"]};function y(n){return typeof n=="string"}function A(n){return typeof n=="string"&&n.toUpperCase()!==n.toLowerCase()}function ce(n,E){let W=Date.now();if(!y(n))throw n===void 0?new Error("html-crush: [THROW_ID_01] the first input argument is completely missing! It should be given as string."):new Error(`html-crush: [THROW_ID_02] the first input argument must be string! It was given as "${typeof n}", equal to:
|
|
11
|
+
${JSON.stringify(n,null,4)}`);if(E&&typeof E!="object")throw new Error(`html-crush: [THROW_ID_03] the second input argument, options object, should be a plain object but it was given as type ${typeof E}, equal to ${JSON.stringify(E,null,4)}`);if(E&&Array.isArray(E.breakToTheLeftOf)&&E.breakToTheLeftOf.length){for(let e=0,w=E.breakToTheLeftOf.length;e<w;e++)if(!y(E.breakToTheLeftOf[e]))throw new TypeError(`html-crush: [THROW_ID_05] the opts.breakToTheLeftOf array contains non-string elements! For example, element at index ${e} is of a type "${typeof E.breakToTheLeftOf[e]}" and is equal to:
|
|
12
|
+
${JSON.stringify(E.breakToTheLeftOf[e],null,4)}`)}let l={...te,...E};typeof l.removeHTMLComments=="boolean"&&(l.removeHTMLComments=l.removeHTMLComments?1:0);let H="";Array.isArray(l.breakToTheLeftOf)&&l.breakToTheLeftOf.length&&(H=[...new Set(l.breakToTheLeftOf.map(e=>e[0]))].join(""));let D={removeHTMLComments:!1,removeCSSComments:!1},S=null,i=null,p=!1,m=0,M=0,g=!1,V=!1,c=null,f=null,C=null,U=null,s,t=null,u=null,r=null,T=null,L=null,v=null,P=">};",I="<",K="!",q=">",z="<",B="{},:;<>~+",k=B,J=B,O=!0,h=n.length,Q=Math.floor(h/2),x=.01,j;l.reportProgressFunc&&(j=Math.floor(l.reportProgressFuncTo-(l.reportProgressFuncTo-l.reportProgressFuncFrom)*x-l.reportProgressFuncFrom));let d,R=0,b=`
|
|
13
|
+
`;if(n.includes(`\r
|
|
14
|
+
`)?b=`\r
|
|
15
|
+
`:n.includes("\r")&&(b="\r"),h){for(let e=0;e<h;e++){if(l.reportProgressFunc&&(h>1e3&&h<2e3?e===Q&&l.reportProgressFunc(Math.floor((l.reportProgressFuncTo-l.reportProgressFuncFrom)/2)):h>=2e3&&(d=l.reportProgressFuncFrom+Math.floor(e/h*(j||1)),d!==R&&(R=d,l.reportProgressFunc(d)))),M++,!s&&g&&n[e]==="}"&&n[e-1]==="}"&&(m+1>=l.lineLengthLimit?($.push(e,e,b),m=0):(t=e,u=e,r=" ")),s&&typeof s=="number"&&e>=s&&(s=void 0),U!==null&&n.startsWith("<\/script",e)&&!A(n[e+8])){if((l.removeIndentations||l.removeLineBreaks)&&e>0&&n[~-e]&&!n[~-e].trim()){for(let o=e;o--;)if(n[o]===`
|
|
16
|
+
`||n[o]==="\r"||n[o].trim()){o+1<e&&$.push(o+1,e);break}}U=null,s=!1,e+=8;continue}if(!s&&!g&&n.startsWith("<script",e)&&!A(n[e+7])){U=e,s=!0;let o="";(l.removeLineBreaks||l.removeIndentations)&&i!==null&&(i>0&&(o=b),$.push(i,e,o)),i=null,S=null}if(L!==null&&T===null&&!/\w/.test(n[e])){T=n.slice(L,e);let o=a(n,~-e);typeof o=="number"&&n[o]===">"&&!n[e].trim()&&a(n,e)?$.push(e,a(n,e)):o&&n[o]==="/"&&n[a(n,o)]===">"&&(!n[e].trim()&&a(n,e)&&$.push(e,a(n,e)),n[o+1]!==">"&&a(n,o+1)&&$.push(o+1,a(n,o+1)))}if(!s&&!g&&!c&&n[~-e]==="<"&&L===null&&(/\w/.test(n[e])?L=e:n[a(n,~-e)]==="/"&&/\w/.test(n[a(n,a(n,~-e))]||"")&&(L=a(n,a(n,~-e)))),!s&&(g||c)&&f!==null&&n[e]==="*"&&n[e+1]==="/"&&([t,u]=_({str:n,from:f,to:e+2,ifLeftSideIncludesThisThenCropTightly:k||"",ifRightSideIncludesThisThenCropTightly:J||""}),f=null,t!=null?$.push(t,u):(m+=1,e+=1),s=e+2),!s&&(g||c)&&f===null&&n[e]==="/"&&n[e+1]==="*"&&(D.removeCSSComments||(D.removeCSSComments=!0),l.removeCSSComments&&(f=e)),V&&n.startsWith("![endif",e+1)&&(V=!1),!s&&!g&&!c&&C!==null){let o;n.startsWith("-->",e)?o=3:n[e]===">"&&n[e-1]==="]"&&(o=1),o&&([t,u]=_({str:n,from:C,to:e+o}),C=null,t!=null?l.lineLengthLimit&&M-(u-t)>=l.lineLengthLimit?($.push(t,u,b),M=-o):($.push(t,u),M-=u-t):(m+=o-1,e+=o-1),s=e+o)}if(!s&&!g&&!c&&(n.startsWith("<!--",e)||l.removeHTMLComments===2&&n.startsWith("<![endif",e))&&C===null&&(n.startsWith("[if",e+4)?(V||(V=!0),l.removeHTMLComments===2&&(C=e)):l.removeHTMLComments&&(!V||l.removeHTMLComments===2)&&(C=e),D.removeHTMLComments||(D.removeHTMLComments=!0)),!s&&g&&f===null&&n.startsWith("</style",e)&&!A(n[e+7])?g=!1:!s&&!g&&f===null&&n.startsWith("<style",e)&&!A(n[e+6])&&(g=!0,(l.removeLineBreaks||l.removeIndentations)&&l.breakToTheLeftOf.includes("<style")&&n.startsWith(' type="text/css">',e+6)&&n[e+24]&&$.push(e+23,e+23,b)),!s&&!c&&`"'`.includes(n[e])&&n.endsWith("style=",e)&&(c=e),!s&&!n[e].trim())i===null&&(i=e);else if(!s&&!((g||c)&&f!==null)){if(i!==null){if(l.removeLineBreaks&&(m+=1),O)O=!1,(l.removeIndentations||l.removeLineBreaks)&&$.push(0,e);else if(l.removeIndentations&&!l.removeLineBreaks&&(!p&&S!==null&&e>S?$.push(S+1,e):i+1<e&&(n.endsWith("]>",i)||n.endsWith("-->",i)||n.startsWith("<![",e)||n.startsWith("<!--<![",e)?$.push(i,e):n[i]===" "?$.push(i+1,e):n[~-e]===" "?$.push(i,~-e):$.push(i,e," "))),l.removeLineBreaks||c){if(H.includes(n[e])&&X(n,e,l.breakToTheLeftOf)){!(`\r
|
|
17
|
+
`.includes(n[~-e])&&i===~-e)&&!(n[~-e]===`
|
|
18
|
+
`&&n[e-2]==="\r"&&i===e-2)&&$.push(i,e,b),t=null,u=null,r=null,i=null,m=1;continue}let o=" ";n[e]==="<"&&F(n,e,l.mindTheInlineTags,{cb:N=>!N||!/\w/.test(N)})||(n[~-i]&&q.includes(n[~-i])&&z.includes(n[e])||(g||c)&&f===null&&(k.includes(n[~-i])||J.includes(n[e]))||n.startsWith("!important",e)&&!V||c&&(n[~-i]==="'"||n[~-i]==='"')||n[~-i]==="}"&&n.startsWith("</style",e)||n[e]===">"&&(`'"`.includes(n[G(n,e)])||n[a(n,e)]==="<")||n[e]==="/"&&n[a(n,e)]===">")&&(o="",n[e]==="/"&&n[e+1]===">"&&a(n,e)&&a(n,e)>e+1&&($.push(e+1,a(n,e)),m-=a(n,e)-e+1)),g&&n[e]==="}"&&i&&n[i-1]==="}"&&(o=" "),o?.length&&(m+=1),l.lineLengthLimit?m>=l.lineLengthLimit||!n[e+1]||n[e]===">"||n[e]==="/"&&n[e+1]===">"?((m>l.lineLengthLimit||m===l.lineLengthLimit&&n[e+1]&&n[e+1].trim()&&!P.includes(n[e])&&!I.includes(n[e+1]))&&(o=b,m=1),(m>l.lineLengthLimit||!(o===" "&&e===i+1))&&($.push(i,e,o),S=null),t=null,u=null,r=null):(t===null||i<t)&&(t=i,u=e,r=o):e===i+1&&o===" "||$.push(i,e,o)}i=null,p||(p=!0)}else O&&(O=!1),l.removeLineBreaks&&(m+=1);p||(p=!0)}if(!s&&!O&&e!==0&&l.removeLineBreaks&&(l.lineLengthLimit||H)&&!n.startsWith("</a",e)){if(H&&X(n,e,l.breakToTheLeftOf)&&n.slice(0,e).trim()&&(!n.startsWith("<![endif]",e)||!oe(n,e,"<!--"))){$.push(e,e,b),t=null,u=null,r=null,m=1;continue}else if(l.lineLengthLimit&&m<=l.lineLengthLimit){if(!n[e+1]||I.includes(n[e])&&!K.includes(n[e])||P.includes(n[e])||!n[e].trim()){if(t!==null&&u!==null&&(t!==u||r?.length)){let o=r;n[e].trim()&&n[e+1]&&n[e+1].trim()&&m+(r?r.length:0)>l.lineLengthLimit&&(o=b),(m+(o?o.length:0)>l.lineLengthLimit||!(o===" "&&u===t+1&&n[t]===" "))&&(n[~-t]==="}"&&n[u]==="{"||($.push(t,u,o),S=null))}n[e].trim()&&(I.includes(n[e])||n[~-e]&&P.includes(n[~-e]))&&y(v)&&(!T||!l.mindTheInlineTags.includes(T))&&!(n[e]==="<"&&F(n,e,l.mindTheInlineTags,{cb:o=>!o||!/\w/.test(o)}))&&!(n[e]==="<"&&F(n,e,l.mindTheInlineTags,{trimCharsBeforeMatching:"/",cb:o=>!o||!/\w/.test(o)}))?(t=e,u=e,r=null):f===null&&t!==null&&(c||!l.mindTheInlineTags||!Array.isArray(l.mindTheInlineTags)||Array.isArray(l.mindTheInlineTags.length)&&!l.mindTheInlineTags.length||!y(T)||Array.isArray(l.mindTheInlineTags)&&l.mindTheInlineTags.length&&y(T)&&!l.mindTheInlineTags.includes(T))&&!(n[e]==="<"&&F(n,e,l.mindTheInlineTags,{trimCharsBeforeMatching:"/",cb:o=>!o||!/\w/.test(o)}))&&(t=null,u=null,r=null)}}else if(l.lineLengthLimit)if(I.includes(n[e])&&!(n[e]==="<"&&F(n,e,l.mindTheInlineTags,{trimCharsBeforeMatching:"/",cb:o=>!o||!/\w/.test(o)})))if(t!==null&&u!==null&&(t!==u||r?.length)){let o=r?.length?r.length:0;m-(u-t-o)-1>l.lineLengthLimit||($.push(t,u,r),m-(u-t-o)-1===l.lineLengthLimit&&($.push(e,e,b),m=0),t=null,u=null,r=null)}else $.push(e,e,b),m=0;else n[e+1]&&P.includes(n[e])&&y(T)&&Array.isArray(l.mindTheInlineTags)&&l.mindTheInlineTags.length&&!l.mindTheInlineTags.includes(T)?t!==null&&u!==null&&(t!==u||r?.length)||($.push(e+1,e+1,b),m=0):n[e].trim()&&(n[e+1]||t!==null&&u!==null&&(t!==u||r?.length)&&$.push(t,u,b))}if(!s&&!O&&l.removeLineBreaks&&l.lineLengthLimit&&m>=l.lineLengthLimit&&t!==null&&u!==null&&!P.includes(n[e])&&!I.includes(n[e])&&!"/".includes(n[e])&&!(m===l.lineLengthLimit&&n[e+1]&&!n[e+1].trim())){let o=b;n[e+1]&&!n[e+1].trim()&&m===l.lineLengthLimit&&(o=r),o===b&&!n[~-t].trim()&&G(n,t)&&(t=G(n,t)+1),$.push(t,u,o),m=e-u,n[e].length&&(m+=1),t=null,u=null,r=null}if((!s&&n[e]===`
|
|
19
|
+
`||n[e]==="\r"&&(!n[e+1]||n[e+1]&&n[e+1]!==`
|
|
20
|
+
`))&&(S=e,p&&(p=!1),!l.removeLineBreaks&&i!==null&&i<e&&n[e+1]&&n[e+1]!=="\r"&&n[e+1]!==`
|
|
21
|
+
`&&$.push(i,e)),n[e+1]||(g&&f!==null?$.push(..._({str:n,from:f,to:e,ifLeftSideIncludesThisThenCropTightly:k||"",ifRightSideIncludesThisThenCropTightly:J||""})):i&&n[e]!==`
|
|
22
|
+
`&&n[e]!=="\r"?$.push(i,e+1):i&&(n[e]==="\r"&&n[e+1]===`
|
|
23
|
+
`||n[e]===`
|
|
24
|
+
`&&n[e-1]!=="\r")&&$.push(i,e)),!s&&c&&c<e&&n[c]===n[e]&&(c=null),!s&&!g&&n.startsWith("<pre",e)&&!A(n[e+4])){let o=n.indexOf("</pre",e+5);o>0&&(s=o)}if(!s&&!g&&n.startsWith("<code",e)&&!A(n[e+5])){let o=n.indexOf("</code",e+5);o>0&&(s=o)}if(!s&&n.startsWith("<![CDATA[",e)){let o=n.indexOf("]]>",e+9);o>0&&(s=o)}!s&&!g&&!c&&L!==null&&n[e]===">"&&(n[a(n,e)]==="<"&&(v=T),L=null,T=null),n[e]==="<"&&v!==null&&(v=null),g&&n[e]==="{"&&n[e+1]==="{"&&n.indexOf("}}")!==-1&&(s=n.indexOf("}}")+2);let w=!0}if($.current()){let e=$.current();$.wipe();let w=l.reportProgressFuncTo-(l.reportProgressFuncTo-l.reportProgressFuncFrom)*x,o=ne(n,e,Z=>{l.reportProgressFunc&&h>=2e3&&(d=Math.floor(w+(l.reportProgressFuncTo-w)*(Z/100)),d!==R&&(R=d,l.reportProgressFunc(d)))}),N=o.length;return{log:{timeTakenInMilliseconds:Date.now()-W,originalLength:h,cleanedLength:N,bytesSaved:Math.max(h-N,0),percentageReducedOfOriginal:h?Math.round(Math.max(h-N,0)*100/h):0},ranges:e,applicableOpts:D,result:o}}}return{log:{timeTakenInMilliseconds:Date.now()-W,originalLength:h,cleanedLength:h,bytesSaved:0,percentageReducedOfOriginal:0},applicableOpts:D,ranges:null,result:n}}export{ce as crush,te as defaults,ge as version};
|