html-crush 5.0.6 → 5.0.12

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.
@@ -1,901 +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.6
4
+ * @version 5.0.12
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 { rApply } from 'ranges-apply';
11
- import { Ranges } from 'ranges-push';
12
- import { matchRightIncl, matchRight, matchLeft } from 'string-match-left-right';
13
- import { expander } from 'string-range-expander';
14
- import { right, left } from 'string-left-right';
15
-
16
- var version$1 = "5.0.6";
17
-
18
- const version = version$1;
19
- const finalIndexesToDelete = new Ranges({ limitToBeAddedWhitespace: true });
20
- const defaults = {
21
- lineLengthLimit: 500,
22
- removeIndentations: true,
23
- removeLineBreaks: false,
24
- removeHTMLComments: false,
25
- removeCSSComments: true,
26
- reportProgressFunc: null,
27
- reportProgressFuncFrom: 0,
28
- reportProgressFuncTo: 100,
29
- breakToTheLeftOf: [
30
- "</td",
31
- "<html",
32
- "</html",
33
- "<head",
34
- "</head",
35
- "<meta",
36
- "<link",
37
- "<table",
38
- "<script",
39
- "</script",
40
- "<!DOCTYPE",
41
- "<style",
42
- "</style",
43
- "<title",
44
- "<body",
45
- "@media",
46
- "</body",
47
- "<!--[if",
48
- "<!--<![endif",
49
- "<![endif]",
50
- ],
51
- mindTheInlineTags: [
52
- "a",
53
- "abbr",
54
- "acronym",
55
- "audio",
56
- "b",
57
- "bdi",
58
- "bdo",
59
- "big",
60
- "br",
61
- "button",
62
- "canvas",
63
- "cite",
64
- "code",
65
- "data",
66
- "datalist",
67
- "del",
68
- "dfn",
69
- "em",
70
- "embed",
71
- "i",
72
- "iframe",
73
- "img",
74
- "input",
75
- "ins",
76
- "kbd",
77
- "label",
78
- "map",
79
- "mark",
80
- "meter",
81
- "noscript",
82
- "object",
83
- "output",
84
- "picture",
85
- "progress",
86
- "q",
87
- "ruby",
88
- "s",
89
- "samp",
90
- "script",
91
- "select",
92
- "slot",
93
- "small",
94
- "span",
95
- "strong",
96
- "sub",
97
- "sup",
98
- "svg",
99
- "template",
100
- "textarea",
101
- "time",
102
- "u",
103
- "tt",
104
- "var",
105
- "video",
106
- "wbr",
107
- ],
108
- };
109
- const applicableOpts = {
110
- removeHTMLComments: false,
111
- removeCSSComments: false,
112
- };
113
- function isStr(something) {
114
- return typeof something === "string";
115
- }
116
- function isLetter(something) {
117
- return (typeof something === "string" &&
118
- something.toUpperCase() !== something.toLowerCase());
119
- }
120
- function crush(str, originalOpts) {
121
- const start = Date.now();
122
- if (!isStr(str)) {
123
- if (str === undefined) {
124
- throw new Error("html-crush: [THROW_ID_01] the first input argument is completely missing! It should be given as string.");
125
- }
126
- else {
127
- 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)}`);
128
- }
129
- }
130
- if (originalOpts && typeof originalOpts !== "object") {
131
- 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)}`);
132
- }
133
- if (originalOpts &&
134
- Array.isArray(originalOpts.breakToTheLeftOf) &&
135
- originalOpts.breakToTheLeftOf.length) {
136
- for (let z = 0, len = originalOpts.breakToTheLeftOf.length; z < len; z++) {
137
- if (!isStr(originalOpts.breakToTheLeftOf[z])) {
138
- 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
139
- .breakToTheLeftOf[z]}" and is equal to:\n${JSON.stringify(originalOpts.breakToTheLeftOf[z], null, 4)}`);
140
- }
141
- }
142
- }
143
- const opts = { ...defaults, ...originalOpts };
144
- if (typeof opts.removeHTMLComments === "boolean") {
145
- opts.removeHTMLComments = opts.removeHTMLComments ? 1 : 0;
146
- }
147
- let breakToTheLeftOfFirstLetters = "";
148
- if (Array.isArray(opts.breakToTheLeftOf) && opts.breakToTheLeftOf.length) {
149
- breakToTheLeftOfFirstLetters = [
150
- ...new Set(opts.breakToTheLeftOf.map((val) => val[0])),
151
- ].join("");
152
- }
153
- let lastLinebreak = null;
154
- let whitespaceStartedAt = null;
155
- let nonWhitespaceCharMet = false;
156
- let countCharactersPerLine = 0;
157
- let cpl = 0;
158
- let withinStyleTag = false;
159
- let withinHTMLConditional = false;
160
- let withinInlineStyle = null;
161
- let styleCommentStartedAt = null;
162
- let htmlCommentStartedAt = null;
163
- let scriptStartedAt = null;
164
- let doNothing;
165
- let stageFrom = null;
166
- let stageTo = null;
167
- let stageAdd = null;
168
- let tagName = null;
169
- let tagNameStartsAt = null;
170
- let leftTagName = null;
171
- const CHARS_BREAK_ON_THE_RIGHT_OF_THEM = `>};`;
172
- const CHARS_BREAK_ON_THE_LEFT_OF_THEM = `<`;
173
- const CHARS_DONT_BREAK_ON_THE_LEFT_OF_THEM = `!`;
174
- const DELETE_TIGHTLY_IF_ON_LEFT_IS = `>`;
175
- const DELETE_TIGHTLY_IF_ON_RIGHT_IS = `<`;
176
- const set = `{},:;<>~+`;
177
- const DELETE_IN_STYLE_TIGHTLY_IF_ON_LEFT_IS = set;
178
- const DELETE_IN_STYLE_TIGHTLY_IF_ON_RIGHT_IS = set;
179
- let beginningOfAFile = true;
180
- const len = str.length;
181
- const midLen = Math.floor(len / 2);
182
- const leavePercForLastStage = 0.01;
183
- let ceil;
184
- if (opts.reportProgressFunc) {
185
- ceil = Math.floor(opts.reportProgressFuncTo -
186
- (opts.reportProgressFuncTo - opts.reportProgressFuncFrom) *
187
- leavePercForLastStage -
188
- opts.reportProgressFuncFrom);
189
- }
190
- let currentPercentageDone;
191
- let lastPercentage = 0;
192
- let lineEnding = `\n`;
193
- if (str.includes(`\r\n`)) {
194
- lineEnding = `\r\n`;
195
- }
196
- else if (str.includes(`\r`)) {
197
- lineEnding = `\r`;
198
- }
199
- if (len) {
200
- for (let i = 0; i < len; i++) {
201
- if (opts.reportProgressFunc) {
202
- if (len > 1000 && len < 2000) {
203
- if (i === midLen) {
204
- opts.reportProgressFunc(Math.floor((opts.reportProgressFuncTo - opts.reportProgressFuncFrom) / 2));
205
- }
206
- }
207
- else if (len >= 2000) {
208
- currentPercentageDone =
209
- opts.reportProgressFuncFrom + Math.floor((i / len) * (ceil || 1));
210
- if (currentPercentageDone !== lastPercentage) {
211
- lastPercentage = currentPercentageDone;
212
- opts.reportProgressFunc(currentPercentageDone);
213
- }
214
- }
215
- }
216
- cpl++;
217
- if (!doNothing &&
218
- withinStyleTag &&
219
- str[i] === "}" &&
220
- str[i - 1] === "}") {
221
- if (countCharactersPerLine + 1 >= opts.lineLengthLimit) {
222
- finalIndexesToDelete.push(i, i, lineEnding);
223
- countCharactersPerLine = 0;
224
- }
225
- else {
226
- stageFrom = i;
227
- stageTo = i;
228
- stageAdd = " ";
229
- }
230
- }
231
- if (doNothing && typeof doNothing === "number" && i >= doNothing) {
232
- doNothing = undefined;
233
- }
234
- if (scriptStartedAt !== null &&
235
- str.startsWith("</script", i) &&
236
- !isLetter(str[i + 8])) {
237
- if ((opts.removeIndentations || opts.removeLineBreaks) &&
238
- i > 0 &&
239
- str[~-i] &&
240
- !str[~-i].trim()) {
241
- for (let y = i; y--;) {
242
- if (str[y] === "\n" || str[y] === "\r" || str[y].trim()) {
243
- if (y + 1 < i) {
244
- finalIndexesToDelete.push(y + 1, i);
245
- }
246
- break;
247
- }
248
- }
249
- }
250
- scriptStartedAt = null;
251
- doNothing = false;
252
- i += 8;
253
- continue;
254
- }
255
- if (!doNothing &&
256
- !withinStyleTag &&
257
- str.startsWith("<script", i) &&
258
- !isLetter(str[i + 7])) {
259
- scriptStartedAt = i;
260
- doNothing = true;
261
- let whatToInsert = "";
262
- if ((opts.removeLineBreaks || opts.removeIndentations) &&
263
- whitespaceStartedAt !== null) {
264
- if (whitespaceStartedAt > 0) {
265
- whatToInsert = lineEnding;
266
- }
267
- finalIndexesToDelete.push(whitespaceStartedAt, i, whatToInsert);
268
- }
269
- whitespaceStartedAt = null;
270
- lastLinebreak = null;
271
- }
272
- if (tagNameStartsAt !== null &&
273
- tagName === null &&
274
- !/\w/.test(str[i])
275
- ) {
276
- tagName = str.slice(tagNameStartsAt, i);
277
- const idxOnTheRight = right(str, ~-i);
278
- if (typeof idxOnTheRight === "number" &&
279
- str[idxOnTheRight] === ">" &&
280
- !str[i].trim() &&
281
- right(str, i)) {
282
- finalIndexesToDelete.push(i, right(str, i));
283
- }
284
- else if (idxOnTheRight &&
285
- str[idxOnTheRight] === "/" &&
286
- str[right(str, idxOnTheRight)] === ">") {
287
- if (!str[i].trim() && right(str, i)) {
288
- finalIndexesToDelete.push(i, right(str, i));
289
- }
290
- if (str[idxOnTheRight + 1] !== ">" && right(str, idxOnTheRight + 1)) {
291
- finalIndexesToDelete.push(idxOnTheRight + 1, right(str, idxOnTheRight + 1));
292
- }
293
- }
294
- }
295
- if (!doNothing &&
296
- !withinStyleTag &&
297
- !withinInlineStyle &&
298
- str[~-i] === "<" &&
299
- tagNameStartsAt === null) {
300
- if (/\w/.test(str[i])) {
301
- tagNameStartsAt = i;
302
- }
303
- else if (str[right(str, ~-i)] === "/" &&
304
- /\w/.test(str[right(str, right(str, ~-i))] || "")) {
305
- tagNameStartsAt = right(str, right(str, ~-i));
306
- }
307
- }
308
- if (!doNothing &&
309
- (withinStyleTag || withinInlineStyle) &&
310
- styleCommentStartedAt !== null &&
311
- str[i] === "*" &&
312
- str[i + 1] === "/") {
313
- [stageFrom, stageTo] = expander({
314
- str,
315
- from: styleCommentStartedAt,
316
- to: i + 2,
317
- ifLeftSideIncludesThisThenCropTightly: DELETE_IN_STYLE_TIGHTLY_IF_ON_LEFT_IS ,
318
- ifRightSideIncludesThisThenCropTightly: DELETE_IN_STYLE_TIGHTLY_IF_ON_RIGHT_IS ,
319
- });
320
- styleCommentStartedAt = null;
321
- if (stageFrom != null) {
322
- finalIndexesToDelete.push(stageFrom, stageTo);
323
- }
324
- else {
325
- countCharactersPerLine += 1;
326
- i += 1;
327
- }
328
- doNothing = i + 2;
329
- }
330
- if (!doNothing &&
331
- (withinStyleTag || withinInlineStyle) &&
332
- styleCommentStartedAt === null &&
333
- str[i] === "/" &&
334
- str[i + 1] === "*") {
335
- if (!applicableOpts.removeCSSComments) {
336
- applicableOpts.removeCSSComments = true;
337
- }
338
- if (opts.removeCSSComments) {
339
- styleCommentStartedAt = i;
340
- }
341
- }
342
- if (withinHTMLConditional && str.startsWith("![endif", i + 1)) {
343
- withinHTMLConditional = false;
344
- }
345
- if (!doNothing &&
346
- !withinStyleTag &&
347
- !withinInlineStyle &&
348
- htmlCommentStartedAt !== null) {
349
- let distanceFromHereToCommentEnding;
350
- if (str.startsWith("-->", i)) {
351
- distanceFromHereToCommentEnding = 3;
352
- }
353
- else if (str[i] === ">" && str[i - 1] === "]") {
354
- distanceFromHereToCommentEnding = 1;
355
- }
356
- if (distanceFromHereToCommentEnding) {
357
- [stageFrom, stageTo] = expander({
358
- str,
359
- from: htmlCommentStartedAt,
360
- to: i + distanceFromHereToCommentEnding,
361
- });
362
- htmlCommentStartedAt = null;
363
- if (stageFrom != null) {
364
- if (opts.lineLengthLimit &&
365
- cpl - (stageTo - stageFrom) >= opts.lineLengthLimit) {
366
- finalIndexesToDelete.push(stageFrom, stageTo, lineEnding);
367
- cpl = -distanceFromHereToCommentEnding;
368
- }
369
- else {
370
- finalIndexesToDelete.push(stageFrom, stageTo);
371
- cpl -= stageTo - stageFrom;
372
- }
373
- }
374
- else {
375
- countCharactersPerLine += distanceFromHereToCommentEnding - 1;
376
- i += distanceFromHereToCommentEnding - 1;
377
- }
378
- doNothing = i + distanceFromHereToCommentEnding;
379
- }
380
- }
381
- if (!doNothing &&
382
- !withinStyleTag &&
383
- !withinInlineStyle &&
384
- str.startsWith("<!--", i) &&
385
- htmlCommentStartedAt === null) {
386
- if (str.startsWith("[if", i + 4)) {
387
- if (!withinHTMLConditional) {
388
- withinHTMLConditional = true;
389
- }
390
- if (opts.removeHTMLComments === 2) {
391
- htmlCommentStartedAt = i;
392
- }
393
- }
394
- else if (
395
- opts.removeHTMLComments &&
396
- (!withinHTMLConditional || opts.removeHTMLComments === 2)) {
397
- htmlCommentStartedAt = i;
398
- }
399
- if (!applicableOpts.removeHTMLComments) {
400
- applicableOpts.removeHTMLComments = true;
401
- }
402
- }
403
- if (!doNothing &&
404
- withinStyleTag &&
405
- styleCommentStartedAt === null &&
406
- str.startsWith("</style", i) &&
407
- !isLetter(str[i + 7])) {
408
- withinStyleTag = false;
409
- }
410
- else if (!doNothing &&
411
- !withinStyleTag &&
412
- styleCommentStartedAt === null &&
413
- str.startsWith("<style", i) &&
414
- !isLetter(str[i + 6])) {
415
- withinStyleTag = true;
416
- if ((opts.removeLineBreaks || opts.removeIndentations) &&
417
- opts.breakToTheLeftOf.includes("<style") &&
418
- str.startsWith(` type="text/css">`, i + 6) &&
419
- str[i + 24]) {
420
- finalIndexesToDelete.push(i + 23, i + 23, lineEnding);
421
- }
422
- }
423
- if (!doNothing &&
424
- !withinInlineStyle &&
425
- `"'`.includes(str[i]) &&
426
- str.endsWith("style=", i)) {
427
- withinInlineStyle = i;
428
- }
429
- if (!doNothing && !str[i].trim()) {
430
- if (whitespaceStartedAt === null) {
431
- whitespaceStartedAt = i;
432
- }
433
- }
434
- else if (!doNothing &&
435
- !((withinStyleTag || withinInlineStyle) &&
436
- styleCommentStartedAt !== null)) {
437
- if (whitespaceStartedAt !== null) {
438
- if (opts.removeLineBreaks) {
439
- countCharactersPerLine += 1;
440
- }
441
- if (beginningOfAFile) {
442
- beginningOfAFile = false;
443
- if (opts.removeIndentations || opts.removeLineBreaks) {
444
- finalIndexesToDelete.push(0, i);
445
- }
446
- }
447
- else {
448
- if (opts.removeIndentations && !opts.removeLineBreaks) {
449
- if (!nonWhitespaceCharMet &&
450
- lastLinebreak !== null &&
451
- i > lastLinebreak) {
452
- finalIndexesToDelete.push(lastLinebreak + 1, i);
453
- }
454
- else if (whitespaceStartedAt + 1 < i) {
455
- if (
456
- str.endsWith("]>", whitespaceStartedAt) ||
457
- str.endsWith("-->", whitespaceStartedAt) ||
458
- str.startsWith("<![", i) ||
459
- str.startsWith("<!--<![", i)) {
460
- finalIndexesToDelete.push(whitespaceStartedAt, i);
461
- }
462
- else if (str[whitespaceStartedAt] === " ") {
463
- finalIndexesToDelete.push(whitespaceStartedAt + 1, i);
464
- }
465
- else if (str[~-i] === " ") {
466
- finalIndexesToDelete.push(whitespaceStartedAt, ~-i);
467
- }
468
- else {
469
- finalIndexesToDelete.push(whitespaceStartedAt, i, " ");
470
- }
471
- }
472
- }
473
- if (opts.removeLineBreaks || withinInlineStyle) {
474
- if (breakToTheLeftOfFirstLetters.includes(str[i]) &&
475
- matchRightIncl(str, i, opts.breakToTheLeftOf)) {
476
- if (
477
- !(`\r\n`.includes(str[~-i]) && whitespaceStartedAt === ~-i) &&
478
- !(str[~-i] === "\n" &&
479
- str[i - 2] === "\r" &&
480
- whitespaceStartedAt === i - 2)) {
481
- finalIndexesToDelete.push(whitespaceStartedAt, i, lineEnding);
482
- }
483
- stageFrom = null;
484
- stageTo = null;
485
- stageAdd = null;
486
- whitespaceStartedAt = null;
487
- countCharactersPerLine = 1;
488
- continue;
489
- }
490
- let whatToAdd = " ";
491
- if (
492
- str[i] === "<" &&
493
- matchRight(str, i, opts.mindTheInlineTags, {
494
- cb: (nextChar) => !nextChar || !/\w/.test(nextChar),
495
- })
496
- ) ;
497
- else if ((str[~-whitespaceStartedAt] &&
498
- DELETE_TIGHTLY_IF_ON_LEFT_IS.includes(str[~-whitespaceStartedAt]) &&
499
- DELETE_TIGHTLY_IF_ON_RIGHT_IS.includes(str[i])) ||
500
- ((withinStyleTag || withinInlineStyle) &&
501
- styleCommentStartedAt === null &&
502
- (DELETE_IN_STYLE_TIGHTLY_IF_ON_LEFT_IS.includes(str[~-whitespaceStartedAt]) ||
503
- DELETE_IN_STYLE_TIGHTLY_IF_ON_RIGHT_IS.includes(str[i]))) ||
504
- (str.startsWith("!important", i) && !withinHTMLConditional) ||
505
- (withinInlineStyle &&
506
- (str[~-whitespaceStartedAt] === "'" ||
507
- str[~-whitespaceStartedAt] === '"')) ||
508
- (str[~-whitespaceStartedAt] === "}" &&
509
- str.startsWith("</style", i)) ||
510
- (str[i] === ">" &&
511
- (`'"`.includes(str[left(str, i)]) ||
512
- str[right(str, i)] === "<")) ||
513
- (str[i] === "/" && str[right(str, i)] === ">")) {
514
- whatToAdd = "";
515
- if (str[i] === "/" &&
516
- str[i + 1] === ">" &&
517
- right(str, i) &&
518
- right(str, i) > i + 1) {
519
- finalIndexesToDelete.push(i + 1, right(str, i));
520
- countCharactersPerLine -= right(str, i) - i + 1;
521
- }
522
- }
523
- if (withinStyleTag &&
524
- str[i] === "}" &&
525
- whitespaceStartedAt &&
526
- str[whitespaceStartedAt - 1] === "}") {
527
- whatToAdd = " ";
528
- }
529
- if (whatToAdd && whatToAdd.length) {
530
- countCharactersPerLine += 1;
531
- }
532
- if (!opts.lineLengthLimit) {
533
- if (!(i === whitespaceStartedAt + 1 &&
534
- whatToAdd === " ")) {
535
- finalIndexesToDelete.push(whitespaceStartedAt, i, whatToAdd);
536
- }
537
- }
538
- else {
539
- if (countCharactersPerLine >= opts.lineLengthLimit ||
540
- !str[i + 1] ||
541
- str[i] === ">" ||
542
- (str[i] === "/" && str[i + 1] === ">")) {
543
- if (countCharactersPerLine > opts.lineLengthLimit ||
544
- (countCharactersPerLine === opts.lineLengthLimit &&
545
- str[i + 1] &&
546
- str[i + 1].trim() &&
547
- !CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[i]) &&
548
- !CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i + 1]))) {
549
- whatToAdd = lineEnding;
550
- countCharactersPerLine = 1;
551
- }
552
- if (countCharactersPerLine > opts.lineLengthLimit ||
553
- !(whatToAdd === " " && i === whitespaceStartedAt + 1)) {
554
- finalIndexesToDelete.push(whitespaceStartedAt, i, whatToAdd);
555
- lastLinebreak = null;
556
- }
557
- stageFrom = null;
558
- stageTo = null;
559
- stageAdd = null;
560
- }
561
- else if (stageFrom === null ||
562
- whitespaceStartedAt < stageFrom) {
563
- stageFrom = whitespaceStartedAt;
564
- stageTo = i;
565
- stageAdd = whatToAdd;
566
- }
567
- }
568
- }
569
- }
570
- whitespaceStartedAt = null;
571
- if (!nonWhitespaceCharMet) {
572
- nonWhitespaceCharMet = true;
573
- }
574
- }
575
- else {
576
- if (beginningOfAFile) {
577
- beginningOfAFile = false;
578
- }
579
- if (opts.removeLineBreaks) {
580
- countCharactersPerLine += 1;
581
- }
582
- }
583
- if (!nonWhitespaceCharMet) {
584
- nonWhitespaceCharMet = true;
585
- }
586
- }
587
- if (!doNothing &&
588
- !beginningOfAFile &&
589
- i !== 0 &&
590
- opts.removeLineBreaks &&
591
- (opts.lineLengthLimit || breakToTheLeftOfFirstLetters) &&
592
- !str.startsWith("</a", i)) {
593
- if (breakToTheLeftOfFirstLetters &&
594
- matchRightIncl(str, i, opts.breakToTheLeftOf) &&
595
- str.slice(0, i).trim() &&
596
- (!str.startsWith("<![endif]", i) || !matchLeft(str, i, "<!--"))) {
597
- finalIndexesToDelete.push(i, i, lineEnding);
598
- stageFrom = null;
599
- stageTo = null;
600
- stageAdd = null;
601
- countCharactersPerLine = 1;
602
- continue;
603
- }
604
- else if (opts.lineLengthLimit &&
605
- countCharactersPerLine <= opts.lineLengthLimit) {
606
- if (!str[i + 1] ||
607
- (CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) &&
608
- !CHARS_DONT_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i])) ||
609
- CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[i]) ||
610
- !str[i].trim()) {
611
- if (stageFrom !== null &&
612
- stageTo !== null &&
613
- (stageFrom !== stageTo || (stageAdd && stageAdd.length))) {
614
- let whatToAdd = stageAdd;
615
- if (str[i].trim() &&
616
- str[i + 1] &&
617
- str[i + 1].trim() &&
618
- countCharactersPerLine + (stageAdd ? stageAdd.length : 0) >
619
- opts.lineLengthLimit) {
620
- whatToAdd = lineEnding;
621
- }
622
- if (countCharactersPerLine + (whatToAdd ? whatToAdd.length : 0) >
623
- opts.lineLengthLimit ||
624
- !(whatToAdd === " " &&
625
- stageTo === stageFrom + 1 &&
626
- str[stageFrom] === " ")) {
627
- if (!(str[~-stageFrom] === "}" && str[stageTo] === "{")) {
628
- finalIndexesToDelete.push(stageFrom, stageTo, whatToAdd);
629
- lastLinebreak = null;
630
- }
631
- }
632
- }
633
- if (str[i].trim() &&
634
- (CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) ||
635
- (str[~-i] &&
636
- CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[~-i]))) &&
637
- isStr(leftTagName) &&
638
- (!tagName || !opts.mindTheInlineTags.includes(tagName)) &&
639
- !(str[i] === "<" &&
640
- matchRight(str, i, opts.mindTheInlineTags, {
641
- cb: (nextChar) => !nextChar || !/\w/.test(nextChar),
642
- })) &&
643
- !(str[i] === "<" &&
644
- matchRight(str, i, opts.mindTheInlineTags, {
645
- trimCharsBeforeMatching: "/",
646
- cb: (nextChar) => !nextChar || !/\w/.test(nextChar),
647
- }))) {
648
- stageFrom = i;
649
- stageTo = i;
650
- stageAdd = null;
651
- }
652
- else if (styleCommentStartedAt === null &&
653
- stageFrom !== null &&
654
- (withinInlineStyle ||
655
- !opts.mindTheInlineTags ||
656
- !Array.isArray(opts.mindTheInlineTags) ||
657
- (Array.isArray(opts.mindTheInlineTags.length) &&
658
- !opts.mindTheInlineTags.length) ||
659
- !isStr(tagName) ||
660
- (Array.isArray(opts.mindTheInlineTags) &&
661
- opts.mindTheInlineTags.length &&
662
- isStr(tagName) &&
663
- !opts.mindTheInlineTags.includes(tagName))) &&
664
- !(str[i] === "<" &&
665
- matchRight(str, i, opts.mindTheInlineTags, {
666
- trimCharsBeforeMatching: "/",
667
- cb: (nextChar) => !nextChar || !/\w/.test(nextChar),
668
- }))) {
669
- stageFrom = null;
670
- stageTo = null;
671
- stageAdd = null;
672
- }
673
- }
674
- }
675
- else if (opts.lineLengthLimit) {
676
- if (CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) &&
677
- !(str[i] === "<" &&
678
- matchRight(str, i, opts.mindTheInlineTags, {
679
- trimCharsBeforeMatching: "/",
680
- cb: (nextChar) => !nextChar || !/\w/.test(nextChar),
681
- }))) {
682
- if (stageFrom !== null &&
683
- stageTo !== null &&
684
- (stageFrom !== stageTo || (stageAdd && stageAdd.length))) {
685
- const whatToAddLength = stageAdd && stageAdd.length ? stageAdd.length : 0;
686
- if (countCharactersPerLine -
687
- (stageTo - stageFrom - whatToAddLength) -
688
- 1 >
689
- opts.lineLengthLimit) ;
690
- else {
691
- finalIndexesToDelete.push(stageFrom, stageTo, stageAdd);
692
- if (countCharactersPerLine -
693
- (stageTo - stageFrom - whatToAddLength) -
694
- 1 ===
695
- opts.lineLengthLimit) {
696
- finalIndexesToDelete.push(i, i, lineEnding);
697
- countCharactersPerLine = 0;
698
- }
699
- stageFrom = null;
700
- stageTo = null;
701
- stageAdd = null;
702
- }
703
- }
704
- else {
705
- finalIndexesToDelete.push(i, i, lineEnding);
706
- countCharactersPerLine = 0;
707
- }
708
- }
709
- else if (str[i + 1] &&
710
- CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[i]) &&
711
- isStr(tagName) &&
712
- Array.isArray(opts.mindTheInlineTags) &&
713
- opts.mindTheInlineTags.length &&
714
- !opts.mindTheInlineTags.includes(tagName)) {
715
- if (stageFrom !== null &&
716
- stageTo !== null &&
717
- (stageFrom !== stageTo || (stageAdd && stageAdd.length))) ;
718
- else {
719
- finalIndexesToDelete.push(i + 1, i + 1, lineEnding);
720
- countCharactersPerLine = 0;
721
- }
722
- }
723
- else if (!str[i].trim()) ;
724
- else if (!str[i + 1]) {
725
- if (stageFrom !== null &&
726
- stageTo !== null &&
727
- (stageFrom !== stageTo || (stageAdd && stageAdd.length))) {
728
- finalIndexesToDelete.push(stageFrom, stageTo, lineEnding);
729
- }
730
- }
731
- }
732
- }
733
- if (!doNothing &&
734
- !beginningOfAFile &&
735
- opts.removeLineBreaks &&
736
- opts.lineLengthLimit &&
737
- countCharactersPerLine >= opts.lineLengthLimit &&
738
- stageFrom !== null &&
739
- stageTo !== null &&
740
- !CHARS_BREAK_ON_THE_RIGHT_OF_THEM.includes(str[i]) &&
741
- !CHARS_BREAK_ON_THE_LEFT_OF_THEM.includes(str[i]) &&
742
- !"/".includes(str[i])) {
743
- if (!(countCharactersPerLine === opts.lineLengthLimit &&
744
- str[i + 1] &&
745
- !str[i + 1].trim())) {
746
- let whatToAdd = lineEnding;
747
- if (str[i + 1] &&
748
- !str[i + 1].trim() &&
749
- countCharactersPerLine === opts.lineLengthLimit) {
750
- whatToAdd = stageAdd;
751
- }
752
- if (whatToAdd === lineEnding &&
753
- !str[~-stageFrom].trim() &&
754
- left(str, stageFrom)) {
755
- stageFrom = left(str, stageFrom) + 1;
756
- }
757
- finalIndexesToDelete.push(stageFrom, stageTo, whatToAdd);
758
- countCharactersPerLine = i - stageTo;
759
- if (str[i].length) {
760
- countCharactersPerLine += 1;
761
- }
762
- stageFrom = null;
763
- stageTo = null;
764
- stageAdd = null;
765
- }
766
- }
767
- if ((!doNothing && str[i] === "\n") ||
768
- (str[i] === "\r" &&
769
- (!str[i + 1] || (str[i + 1] && str[i + 1] !== "\n")))) {
770
- lastLinebreak = i;
771
- if (nonWhitespaceCharMet) {
772
- nonWhitespaceCharMet = false;
773
- }
774
- if (!opts.removeLineBreaks &&
775
- whitespaceStartedAt !== null &&
776
- whitespaceStartedAt < i &&
777
- str[i + 1] &&
778
- str[i + 1] !== "\r" &&
779
- str[i + 1] !== "\n") {
780
- finalIndexesToDelete.push(whitespaceStartedAt, i);
781
- }
782
- }
783
- if (!str[i + 1]) {
784
- if (withinStyleTag && styleCommentStartedAt !== null) {
785
- finalIndexesToDelete.push(...expander({
786
- str,
787
- from: styleCommentStartedAt,
788
- to: i,
789
- ifLeftSideIncludesThisThenCropTightly: DELETE_IN_STYLE_TIGHTLY_IF_ON_LEFT_IS ,
790
- ifRightSideIncludesThisThenCropTightly: DELETE_IN_STYLE_TIGHTLY_IF_ON_RIGHT_IS ,
791
- }));
792
- }
793
- else if (whitespaceStartedAt && str[i] !== "\n" && str[i] !== "\r") {
794
- finalIndexesToDelete.push(whitespaceStartedAt, i + 1);
795
- }
796
- else if (whitespaceStartedAt &&
797
- ((str[i] === "\r" && str[i + 1] === "\n") ||
798
- (str[i] === "\n" && str[i - 1] !== "\r"))) {
799
- finalIndexesToDelete.push(whitespaceStartedAt, i);
800
- }
801
- }
802
- if (!doNothing &&
803
- withinInlineStyle &&
804
- withinInlineStyle < i &&
805
- str[withinInlineStyle] === str[i]) {
806
- withinInlineStyle = null;
807
- }
808
- if (!doNothing &&
809
- !withinStyleTag &&
810
- str.startsWith("<pre", i) &&
811
- !isLetter(str[i + 4])) {
812
- const locationOfClosingPre = str.indexOf("</pre", i + 5);
813
- if (locationOfClosingPre > 0) {
814
- doNothing = locationOfClosingPre;
815
- }
816
- }
817
- if (!doNothing &&
818
- !withinStyleTag &&
819
- str.startsWith("<code", i) &&
820
- !isLetter(str[i + 5])) {
821
- const locationOfClosingCode = str.indexOf("</code", i + 5);
822
- if (locationOfClosingCode > 0) {
823
- doNothing = locationOfClosingCode;
824
- }
825
- }
826
- if (!doNothing && str.startsWith("<![CDATA[", i)) {
827
- const locationOfClosingCData = str.indexOf("]]>", i + 9);
828
- if (locationOfClosingCData > 0) {
829
- doNothing = locationOfClosingCData;
830
- }
831
- }
832
- if (!doNothing &&
833
- !withinStyleTag &&
834
- !withinInlineStyle &&
835
- tagNameStartsAt !== null &&
836
- str[i] === ">") {
837
- if (str[right(str, i)] === "<") {
838
- leftTagName = tagName;
839
- }
840
- tagNameStartsAt = null;
841
- tagName = null;
842
- }
843
- if (str[i] === "<" && leftTagName !== null) {
844
- leftTagName = null;
845
- }
846
- if (withinStyleTag &&
847
- str[i] === "{" &&
848
- str[i + 1] === "{" &&
849
- str.indexOf("}}") !== -1) {
850
- doNothing = str.indexOf("}}") + 2;
851
- }
852
- }
853
- if (finalIndexesToDelete.current()) {
854
- const ranges = finalIndexesToDelete.current();
855
- finalIndexesToDelete.wipe();
856
- const startingPercentageDone = opts.reportProgressFuncTo -
857
- (opts.reportProgressFuncTo - opts.reportProgressFuncFrom) *
858
- leavePercForLastStage;
859
- const res = rApply(str, ranges, (applyPercDone) => {
860
- if (opts.reportProgressFunc && len >= 2000) {
861
- currentPercentageDone = Math.floor(startingPercentageDone +
862
- (opts.reportProgressFuncTo - startingPercentageDone) *
863
- (applyPercDone / 100));
864
- if (currentPercentageDone !== lastPercentage) {
865
- lastPercentage = currentPercentageDone;
866
- opts.reportProgressFunc(currentPercentageDone);
867
- }
868
- }
869
- });
870
- const resLen = res.length;
871
- return {
872
- log: {
873
- timeTakenInMilliseconds: Date.now() - start,
874
- originalLength: len,
875
- cleanedLength: resLen,
876
- bytesSaved: Math.max(len - resLen, 0),
877
- percentageReducedOfOriginal: len
878
- ? Math.round((Math.max(len - resLen, 0) * 100) / len)
879
- : 0,
880
- },
881
- ranges,
882
- applicableOpts,
883
- result: res,
884
- };
885
- }
886
- }
887
- return {
888
- log: {
889
- timeTakenInMilliseconds: Date.now() - start,
890
- originalLength: len,
891
- cleanedLength: len,
892
- bytesSaved: 0,
893
- percentageReducedOfOriginal: 0,
894
- },
895
- applicableOpts,
896
- ranges: null,
897
- result: str,
898
- };
899
- }
900
-
901
- 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.12";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 N(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(!N(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(!N(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 L={removeHTMLComments:!1,removeCSSComments:!1},p=null,i=null,S=!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,D=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,p=null}if(D!==null&&T===null&&!/\w/.test(n[e])){T=n.slice(D,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]==="<"&&D===null&&(/\w/.test(n[e])?D=e:n[a(n,~-e)]==="/"&&/\w/.test(n[a(n,a(n,~-e))]||"")&&(D=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]==="*"&&(L.removeCSSComments||(L.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),L.removeHTMLComments||(L.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&&(!S&&p!==null&&e>p?$.push(p+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:y=>!y||!/\w/.test(y)})||(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),p=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,S||(S=!0)}else O&&(O=!1),l.removeLineBreaks&&(m+=1);S||(S=!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),p=null))}n[e].trim()&&(I.includes(n[e])||n[~-e]&&P.includes(n[~-e]))&&N(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||!N(T)||Array.isArray(l.mindTheInlineTags)&&l.mindTheInlineTags.length&&N(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])&&N(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
+ `))&&(p=e,S&&(S=!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&&D!==null&&n[e]===">"&&(n[a(n,e)]==="<"&&(v=T),D=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)))}),y=o.length;return{log:{timeTakenInMilliseconds:Date.now()-W,originalLength:h,cleanedLength:y,bytesSaved:Math.max(h-y,0),percentageReducedOfOriginal:h?Math.round(Math.max(h-y,0)*100/h):0},ranges:e,applicableOpts:L,result:o}}}return{log:{timeTakenInMilliseconds:Date.now()-W,originalLength:h,cleanedLength:h,bytesSaved:0,percentageReducedOfOriginal:0},applicableOpts:L,ranges:null,result:n}}export{ce as crush,te as defaults,ge as version};