single-file-core 1.5.44 → 1.5.46

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/core/helper.js CHANGED
@@ -21,8 +21,6 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- /* global globalThis */
25
-
26
24
  import * as cssUnescape from "./../vendor/css-unescape.js";
27
25
  import * as hooksFrames from "./../processors/hooks/content/content-hooks-frames.js";
28
26
  import * as infobar from "./infobar.js";
@@ -80,6 +78,7 @@ const DEFAULT_REPLACED_CHARACTERS = ["~", "+", "?", "%", "*", ":", "|", "\"", "<
80
78
  const DEFAULT_REPLACEMENT_CHARACTER = "_";
81
79
  const DEFAULT_REPLACEMENT_CHARACTERS = ["~", "+", "?", "%", "*", ":", "|", """, "<", ">", "\"];
82
80
  const addEventListener = (type, listener, options) => globalThis.addEventListener(type, listener, options);
81
+ // eslint-disable-next-line no-unused-vars
83
82
  const dispatchEvent = event => { try { globalThis.dispatchEvent(event); } catch (error) { /* ignored */ } };
84
83
  const JSON = globalThis.JSON;
85
84
  const crypto = globalThis.crypto;
@@ -147,6 +146,7 @@ function initUserScriptHandler() {
147
146
  let detailUserScript;
148
147
  try {
149
148
  detailUserScript = detail == "jsonDetail" ? JSON.stringify({ options: userScriptOptions }) : { options: userScriptOptions };
149
+ // eslint-disable-next-line no-unused-vars
150
150
  } catch (error) {
151
151
  // ignored
152
152
  }
@@ -161,6 +161,7 @@ function initUserScriptHandler() {
161
161
  if (detail.options) {
162
162
  Object.assign(options, detail.options);
163
163
  }
164
+ // eslint-disable-next-line no-unused-vars
164
165
  } catch (error) {
165
166
  // ignored
166
167
  }
@@ -236,6 +237,7 @@ function preProcessDoc(doc, win, options) {
236
237
  if (doc.referrer) {
237
238
  try {
238
239
  referrer = new URL("/", new URL(doc.referrer).origin).href;
240
+ // eslint-disable-next-line no-unused-vars
239
241
  } catch (error) {
240
242
  // ignored
241
243
  }
@@ -314,6 +316,7 @@ function getElementsInfo(win, doc, element, options, data = { usedFonts: new Map
314
316
  shadowRoot.removeEventListener(GET_ADOPTED_STYLESHEETS_RESPONSE_EVENT, listener);
315
317
  }
316
318
  }
319
+ // eslint-disable-next-line no-unused-vars
317
320
  } catch (error) {
318
321
  // ignored
319
322
  }
@@ -327,6 +330,7 @@ function getElementsInfo(win, doc, element, options, data = { usedFonts: new Map
327
330
  if (shadowRoot.adoptedStyleSheets && shadowRoot.adoptedStyleSheets.length === undefined) {
328
331
  shadowRoot.dispatchEvent(new CustomEvent(UNREGISTER_GET_ADOPTED_STYLESHEETS_REQUEST_EVENT, { bubbles: true }));
329
332
  }
333
+ // eslint-disable-next-line no-unused-vars
330
334
  } catch (error) {
331
335
  // ignored
332
336
  }
@@ -381,6 +385,7 @@ function getResourcesInfo(win, doc, element, options, data, elementHidden, compu
381
385
  });
382
386
  element.setAttribute(CANVAS_ATTRIBUTE_NAME, data.canvases.length - 1);
383
387
  data.markedElements.push(element);
388
+ // eslint-disable-next-line no-unused-vars
384
389
  } catch (error) {
385
390
  // ignored
386
391
  }
@@ -436,6 +441,7 @@ function getResourcesInfo(win, doc, element, options, data, elementHidden, compu
436
441
  data.posters.push(canvasElement.toDataURL("image/png", ""));
437
442
  element.setAttribute(POSTER_ATTRIBUTE_NAME, data.posters.length - 1);
438
443
  data.markedElements.push(element);
444
+ // eslint-disable-next-line no-unused-vars
439
445
  } catch (error) {
440
446
  // ignored
441
447
  }
@@ -500,6 +506,7 @@ function getShadowRoot(element) {
500
506
  } else if (chrome && chrome.dom && chrome.dom.openOrClosedShadowRoot) {
501
507
  try {
502
508
  return chrome.dom.openOrClosedShadowRoot(element);
509
+ // eslint-disable-next-line no-unused-vars
503
510
  } catch (error) {
504
511
  return element.shadowRoot;
505
512
  }
@@ -587,6 +594,7 @@ function getStylesheetsData(doc) {
587
594
  contents[styleIndex] = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
588
595
  }
589
596
  }
597
+ // eslint-disable-next-line no-unused-vars
590
598
  } catch (error) {
591
599
  // ignored
592
600
  }
@@ -693,6 +701,7 @@ async function digest(algo, text) {
693
701
  try {
694
702
  const hash = await crypto.subtle.digest(algo, new TextEncoder("utf-8").encode(text));
695
703
  return hex(hash);
704
+ // eslint-disable-next-line no-unused-vars
696
705
  } catch (error) {
697
706
  return "";
698
707
  }
@@ -719,6 +728,7 @@ function flatten(array) {
719
728
  function getComputedStyle(win, element, pseudoElement) {
720
729
  try {
721
730
  return win.getComputedStyle(element, pseudoElement);
731
+ // eslint-disable-next-line no-unused-vars
722
732
  } catch (error) {
723
733
  // ignored
724
734
  }
package/core/index.js CHANGED
@@ -21,8 +21,6 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- /* global globalThis */
25
-
26
24
  import {
27
25
  getProcessorHelperClass,
28
26
  cssTree
@@ -516,6 +514,7 @@ class Processor {
516
514
  infobarURL = url.split("url: ")[1].trim();
517
515
  infobarSaveDate = saveDate.split("saved date: ")[1];
518
516
  firstComment.remove();
517
+ // eslint-disable-next-line no-unused-vars
519
518
  } catch (error) {
520
519
  // ignored
521
520
  }
@@ -905,6 +904,7 @@ class Processor {
905
904
  Array.from(originalElement.attributes).forEach(attribute => {
906
905
  try {
907
906
  placeHolderElement.setAttribute(attribute.name, attribute.value);
907
+ // eslint-disable-next-line no-unused-vars
908
908
  } catch (error) {
909
909
  // ignored
910
910
  }
@@ -914,6 +914,7 @@ class Processor {
914
914
  }
915
915
  try {
916
916
  templateElement.replaceWith(placeHolderElement);
917
+ // eslint-disable-next-line no-unused-vars
917
918
  } catch (error) {
918
919
  if (originalElement) {
919
920
  templateElement.replaceWith(originalElement);
@@ -1107,6 +1108,7 @@ class Processor {
1107
1108
  let resolvedURL;
1108
1109
  try {
1109
1110
  resolvedURL = util.resolveURL(href, this.options.baseURI || this.options.url);
1111
+ // eslint-disable-next-line no-unused-vars
1110
1112
  } catch (error) {
1111
1113
  // ignored
1112
1114
  }
@@ -1117,6 +1119,7 @@ class Processor {
1117
1119
  }
1118
1120
  try {
1119
1121
  element.setAttribute("href", resolvedURL);
1122
+ // eslint-disable-next-line no-unused-vars
1120
1123
  } catch (error) {
1121
1124
  // ignored
1122
1125
  }
@@ -1133,12 +1136,14 @@ class Processor {
1133
1136
  let resolvedURL;
1134
1137
  try {
1135
1138
  resolvedURL = util.resolveURL(href, this.options.baseURI || this.options.url);
1139
+ // eslint-disable-next-line no-unused-vars
1136
1140
  } catch (error) {
1137
1141
  // ignored
1138
1142
  }
1139
1143
  if (resolvedURL) {
1140
1144
  try {
1141
1145
  element.setAttribute("href", resolvedURL);
1146
+ // eslint-disable-next-line no-unused-vars
1142
1147
  } catch (error) {
1143
1148
  // ignored
1144
1149
  }
@@ -1178,6 +1183,7 @@ class Processor {
1178
1183
  context.drawImage(temporaryVideoElement, 0, 0, canvasElement.width, canvasElement.height);
1179
1184
  try {
1180
1185
  videoElement.poster = canvasElement.toDataURL("image/png", "");
1186
+ // eslint-disable-next-line no-unused-vars
1181
1187
  } catch (error) {
1182
1188
  // ignored
1183
1189
  }
@@ -1269,6 +1275,7 @@ class Processor {
1269
1275
  if (src && !testIgnoredPath(src)) {
1270
1276
  try {
1271
1277
  url = util.resolveURL(src, this.baseURI);
1278
+ // eslint-disable-next-line no-unused-vars
1272
1279
  } catch (error) {
1273
1280
  // ignored
1274
1281
  }
@@ -1446,6 +1453,7 @@ class Processor {
1446
1453
  element.textContent = "";
1447
1454
  try {
1448
1455
  resourceURL = util.resolveURL(scriptSrc, this.baseURI);
1456
+ // eslint-disable-next-line no-unused-vars
1449
1457
  } catch (error) {
1450
1458
  // ignored
1451
1459
  }
@@ -1653,14 +1661,13 @@ function normalizeURL(url) {
1653
1661
  }
1654
1662
 
1655
1663
  function getOnEventAttributeNames(doc) {
1656
- const element = doc.createElement("div");
1664
+ const element = doc.body || doc.createElement("div");
1657
1665
  const attributeNames = [];
1658
1666
  for (const propertyName in element) {
1659
1667
  if (propertyName.startsWith("on")) {
1660
1668
  attributeNames.push(propertyName);
1661
1669
  }
1662
1670
  }
1663
- attributeNames.push("onunload");
1664
1671
  return attributeNames;
1665
1672
  }
1666
1673
 
package/core/infobar.js CHANGED
@@ -103,7 +103,6 @@ const INFOBAR_STYLES = `
103
103
  white-space: pre-wrap;
104
104
  margin-inline: 4px;
105
105
  margin-block: 4px;
106
- padding-inline: 24px;
107
106
  }
108
107
 
109
108
  .infobar .infobar-icon,
@@ -116,7 +115,6 @@ const INFOBAR_STYLES = `
116
115
 
117
116
  .infobar .infobar-close-icon,
118
117
  .infobar .infobar-link-icon {
119
- position: fixed;
120
118
  align-self: flex-start;
121
119
  }
122
120
 
@@ -153,7 +151,7 @@ const INFOBAR_STYLES = `
153
151
  }
154
152
 
155
153
  .infobar .infobar-link-icon {
156
- right: 20px;
154
+ right: 4px;
157
155
  background-size: 60%;
158
156
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw0AYht+mSkUrDnYQcchQnSyIijqWKhbBQmkrtOpgcukfNGlIUlwcBdeCgz+LVQcXZ10dXAVB8AfEydFJ0UVK/C4ptIjx4LiH9+59+e67A4RGhalm1wSgapaRisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHAB8H+DhhoQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAJUExURQAAAICHi4qKioTuJAkAAAABdFJOUwBA5thmAAAAAWJLR0QCZgt8ZAAAAJJJREFUOI3t070NRCEMA2CnYAOyDyPwpHj/Va7hJ3FzV7zy3ET5JIwoAF6Jk4wzAJAkzxAYG9YRTgB+24wBgKmfrGAKTcEfAY4KRlRoIeBTgKOCERVaCPgU4Khge2GqKOBTgKOCERVaAEC/4PNcnyoSWHpjqkhwKxbcig0Q6AorXYF/+A6eIYD1lVbwG/jdA6/kA2THRAURVubcAAAAAElFTkSuQmCC);
159
157
  }
@@ -189,7 +187,25 @@ function appendInfobar(doc, options, useShadowRoot) {
189
187
  }
190
188
  const shadowRootContent = doc.createElement("div");
191
189
  const styleElement = doc.createElement("style");
192
- styleElement.textContent = INFOBAR_STYLES
190
+ styleElement.textContent = INFOBAR_STYLES;
191
+ if (options.infobarPositionAbsolute) {
192
+ styleElement.textContent += ".infobar { position: absolute; }";
193
+ const parentElementStyle = getComputedStyle(parentElement);
194
+ if (parentElementStyle.position == "static") {
195
+ parentElement.style.setProperty("position", "relative", "important");
196
+ }
197
+ }
198
+ if (options.infobarPositionTop) {
199
+ styleElement.textContent += `.infobar { top: ${options.infobarPositionTop}; bottom: auto; }`;
200
+ } else if (options.infobarPositionBottom) {
201
+ styleElement.textContent += `.infobar { bottom: ${options.infobarPositionBottom}; top: auto; }`;
202
+ }
203
+ if (options.infobarPositionRight) {
204
+ styleElement.textContent += `.infobar { right: ${options.infobarPositionRight}; left: auto; }`;
205
+ } else if (options.infobarPositionLeft) {
206
+ styleElement.textContent += `.infobar { left: ${options.infobarPositionLeft}; right: auto; }`;
207
+ }
208
+ styleElement.textContent = styleElement.textContent
193
209
  .replace(/ {2}/g, "")
194
210
  .replace(/\n/g, "")
195
211
  .replace(/: /g, ":")
@@ -284,6 +300,11 @@ function displayIcon(doc, useShadowRoot, options = {}) {
284
300
  const infoData = extractInfobarData(doc);
285
301
  if (infoData.saveUrl) {
286
302
  infoData.openInfobar = options.openInfobar;
303
+ infoData.infobarPositionAbsolute = options.infobarPositionAbsolute;
304
+ infoData.infobarPositionTop = options.infobarPositionTop;
305
+ infoData.infobarPositionRight = options.infobarPositionRight;
306
+ infoData.infobarPositionBottom = options.infobarPositionBottom;
307
+ infoData.infobarPositionLeft = options.infobarPositionLeft;
287
308
  appendInfobar(doc, infoData, useShadowRoot);
288
309
  refreshInfobarInfo(doc, infoData);
289
310
  }
@@ -21,8 +21,6 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- /* global globalThis */
25
-
26
24
  import {
27
25
  normalizeFontFamily,
28
26
  getFontWeight
@@ -139,6 +137,7 @@ class ProcessorHelperCommon {
139
137
  resourceElement.setAttribute(attributeName, util.EMPTY_RESOURCE);
140
138
  try {
141
139
  resourceURL = util.resolveURL(resourceURL, baseURI);
140
+ // eslint-disable-next-line no-unused-vars
142
141
  } catch (error) {
143
142
  // ignored
144
143
  }
@@ -153,6 +152,7 @@ class ProcessorHelperCommon {
153
152
  let symbolElement;
154
153
  try {
155
154
  symbolElement = svgDoc.querySelector(hashMatch[0]);
155
+ // eslint-disable-next-line no-unused-vars
156
156
  } catch (error) {
157
157
  // ignored
158
158
  }
@@ -225,6 +225,7 @@ class ProcessorHelperCommon {
225
225
  if (testValidPath(resourceURL)) {
226
226
  try {
227
227
  resourceURL = util.resolveURL(resourceURL, baseURI);
228
+ // eslint-disable-next-line no-unused-vars
228
229
  } catch (error) {
229
230
  // ignored
230
231
  }
@@ -377,6 +378,7 @@ class ProcessorHelperCommon {
377
378
  if (!originalResourceURL.startsWith("#")) {
378
379
  try {
379
380
  resolvedURL = util.resolveURL(resourceURL, baseURI);
381
+ // eslint-disable-next-line no-unused-vars
380
382
  } catch (error) {
381
383
  // ignored
382
384
  }
@@ -538,6 +540,7 @@ class ProcessorHelperCommon {
538
540
  property = ruleData.block.children.filter(node => {
539
541
  try {
540
542
  return node.property == propertyName && !cssTree.generate(node.value).match(/\\9$/);
543
+ // eslint-disable-next-line no-unused-vars
541
544
  } catch (error) {
542
545
  return node.property == propertyName;
543
546
  }
@@ -546,6 +549,7 @@ class ProcessorHelperCommon {
546
549
  if (property) {
547
550
  try {
548
551
  return cssTree.generate(property.data.value);
552
+ // eslint-disable-next-line no-unused-vars
549
553
  } catch (error) {
550
554
  // ignored
551
555
  }
@@ -21,8 +21,6 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- /* global globalThis */
25
-
26
24
  import * as cssTree from "./../../vendor/css-tree.js";
27
25
 
28
26
  const JSON = globalThis.JSON;
@@ -169,6 +167,7 @@ function getProcessorHelperClass(utilInstance) {
169
167
  urlNode.value = util.EMPTY_RESOURCE;
170
168
  try {
171
169
  resourceURL = util.resolveURL(resourceURL, baseURI);
170
+ // eslint-disable-next-line no-unused-vars
172
171
  } catch (error) {
173
172
  // ignored
174
173
  }
@@ -319,6 +318,7 @@ function getProcessorHelperClass(utilInstance) {
319
318
  if (testValidPath(resourceURL)) {
320
319
  try {
321
320
  resourceURL = util.resolveURL(resourceURL, baseURI);
321
+ // eslint-disable-next-line no-unused-vars
322
322
  } catch (error) {
323
323
  // ignored
324
324
  }
@@ -332,6 +332,7 @@ function getProcessorHelperClass(utilInstance) {
332
332
  if (this.testEmptyResource(content)) {
333
333
  try {
334
334
  originURL = util.resolveURL(originURL, baseURI);
335
+ // eslint-disable-next-line no-unused-vars
335
336
  } catch (error) {
336
337
  // ignored
337
338
  }
@@ -349,6 +350,7 @@ function getProcessorHelperClass(utilInstance) {
349
350
  acceptHeaders: options.acceptHeaders,
350
351
  networkTimeout: options.networkTimeout
351
352
  })).data;
353
+ // eslint-disable-next-line no-unused-vars
352
354
  } catch (error) {
353
355
  // ignored
354
356
  }
@@ -416,7 +418,9 @@ function getProcessorHelperClass(utilInstance) {
416
418
  if (forbiddenPrefixFound) {
417
419
  return "";
418
420
  }
419
- return content + (srcsetValue.w ? " " + srcsetValue.w + "w" : srcsetValue.d ? " " + srcsetValue.d + "x" : "");
421
+ return content + (srcsetValue.w ? " " + srcsetValue.w + "w" :
422
+ srcsetValue.h ? " " + srcsetValue.h + "h" :
423
+ srcsetValue.d ? " " + srcsetValue.d + "x" : "");
420
424
  }
421
425
 
422
426
  testEmptyResource(resource) {
@@ -562,6 +566,7 @@ function getProcessorHelperClass(utilInstance) {
562
566
  fontFace.load().then(() => fontFace.loaded).then(() => { source.valid = true; globalThis.clearTimeout(timeout); }),
563
567
  new Promise(resolve => timeout = globalThis.setTimeout(() => { source.valid = true; resolve(); }, FONT_MAX_LOAD_DELAY))
564
568
  ]);
569
+ // eslint-disable-next-line no-unused-vars
565
570
  } catch (error) {
566
571
  // ignored
567
572
  }
@@ -604,8 +609,8 @@ function getProcessorHelperClass(utilInstance) {
604
609
  fontInfo.reverse();
605
610
  try {
606
611
  srcDeclaration.data.value = cssTree.parse(fontInfo.map(fontSource => fontSource.src).join(","), { context: "value", parseCustomProperty: true });
607
- }
608
- catch (error) {
612
+ // eslint-disable-next-line no-unused-vars
613
+ } catch (error) {
609
614
  // ignored
610
615
  }
611
616
  }
@@ -21,8 +21,6 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- /* global globalThis */
25
-
26
24
  import * as cssTree from "./../../vendor/css-tree.js";
27
25
 
28
26
  const JSON = globalThis.JSON;
@@ -158,6 +156,7 @@ function getProcessorHelperClass(utilInstance) {
158
156
  urlNode.value = util.EMPTY_RESOURCE;
159
157
  try {
160
158
  resourceURL = util.resolveURL(resourceURL, baseURI);
159
+ // eslint-disable-next-line no-unused-vars
161
160
  } catch (error) {
162
161
  // ignored
163
162
  }
@@ -303,6 +302,7 @@ function getProcessorHelperClass(utilInstance) {
303
302
  if (testValidPath(resourceURL)) {
304
303
  try {
305
304
  resourceURL = util.resolveURL(resourceURL, baseURI);
305
+ // eslint-disable-next-line no-unused-vars
306
306
  } catch (error) {
307
307
  // ignored
308
308
  }
@@ -314,6 +314,7 @@ function getProcessorHelperClass(utilInstance) {
314
314
  if (this.testEmptyResource(content)) {
315
315
  try {
316
316
  originURL = util.resolveURL(originURL, baseURI);
317
+ // eslint-disable-next-line no-unused-vars
317
318
  } catch (error) {
318
319
  // ignored
319
320
  }
@@ -330,6 +331,7 @@ function getProcessorHelperClass(utilInstance) {
330
331
  acceptHeaders: options.acceptHeaders,
331
332
  networkTimeout: options.networkTimeout
332
333
  })).data;
334
+ // eslint-disable-next-line no-unused-vars
333
335
  } catch (error) {
334
336
  // ignored
335
337
  }
@@ -364,7 +366,9 @@ function getProcessorHelperClass(utilInstance) {
364
366
  const { content, indexResource, extension, contentType } = await batchRequest.addURL(resourceURL, { asBinary: true, expectedType: "image" });
365
367
  const name = "images/" + indexResource + extension;
366
368
  resources.images.set(indexResource, { name, content, extension, contentType, url: resourceURL });
367
- return name + (srcsetValue.w ? " " + srcsetValue.w + "w" : srcsetValue.d ? " " + srcsetValue.d + "x" : "");
369
+ return name + (srcsetValue.w ? " " + srcsetValue.w + "w" :
370
+ srcsetValue.h ? " " + srcsetValue.h + "h" :
371
+ srcsetValue.d ? " " + srcsetValue.d + "x" : "");
368
372
  }
369
373
 
370
374
  testEmptyResource(resource) {
@@ -482,6 +486,7 @@ function getProcessorHelperClass(utilInstance) {
482
486
  fontFace.load().then(() => fontFace.loaded).then(() => { source.valid = true; globalThis.clearTimeout(timeout); }),
483
487
  new Promise(resolve => timeout = globalThis.setTimeout(() => { source.valid = true; resolve(); }, FONT_MAX_LOAD_DELAY))
484
488
  ]);
489
+ // eslint-disable-next-line no-unused-vars
485
490
  } catch (error) {
486
491
  // ignored
487
492
  }
@@ -537,8 +542,8 @@ function getProcessorHelperClass(utilInstance) {
537
542
  fontInfo.reverse();
538
543
  try {
539
544
  srcDeclaration.data.value = cssTree.parse(fontInfo.map(fontSource => fontSource.src).join(","), { context: "value", parseCustomProperty: true });
540
- }
541
- catch (error) {
545
+ // eslint-disable-next-line no-unused-vars
546
+ } catch (error) {
542
547
  // ignored
543
548
  }
544
549
  }
package/core/util.js CHANGED
@@ -21,8 +21,6 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- /* global globalThis */
25
-
26
24
  import * as vendor from "./../vendor/index.js";
27
25
  import * as modules from "./../modules/index.js";
28
26
  import * as helper from "./helper.js";
@@ -91,6 +89,7 @@ function getInstance(utilOptions) {
91
89
  let matchExtension;
92
90
  try {
93
91
  matchExtension = new URL(resourceURL).pathname.match(/(\.[^\\/.]*)$/);
92
+ // eslint-disable-next-line no-unused-vars
94
93
  } catch (error) {
95
94
  // ignored
96
95
  }
@@ -265,6 +264,7 @@ function getInstance(utilOptions) {
265
264
  fetchFrameResource(resourceURL, { frameId: options.frameId, referrer: options.resourceReferrer, headers: { accept } }),
266
265
  networkTimeoutPromise
267
266
  ]);
267
+ // eslint-disable-next-line no-unused-vars
268
268
  } catch (error) {
269
269
  response = await Promise.race([
270
270
  fetchResource(resourceURL, { headers: { accept } }),
@@ -277,6 +277,7 @@ function getInstance(utilOptions) {
277
277
  networkTimeoutPromise
278
278
  ]);
279
279
  }
280
+ // eslint-disable-next-line no-unused-vars
280
281
  } catch (error) {
281
282
  return getFetchResponse(resourceURL, options);
282
283
  } finally {
@@ -288,6 +289,7 @@ function getInstance(utilOptions) {
288
289
  let buffer;
289
290
  try {
290
291
  buffer = await response.arrayBuffer();
292
+ // eslint-disable-next-line no-unused-vars
291
293
  } catch (error) {
292
294
  return options.inline ? { data: options.asBinary ? helper.EMPTY_RESOURCE : "", resourceURL } : { resourceURL };
293
295
  }
@@ -297,6 +299,7 @@ function getInstance(utilOptions) {
297
299
  const mimeType = new vendor.MIMEType(response.headers.get("content-type"));
298
300
  contentType = mimeType.type + "/" + mimeType.subtype;
299
301
  charset = mimeType.parameters.get("charset");
302
+ // eslint-disable-next-line no-unused-vars
300
303
  } catch (error) {
301
304
  // ignored
302
305
  }
@@ -322,6 +325,7 @@ function getInstance(utilOptions) {
322
325
  } else {
323
326
  return getFetchResponse(resourceURL, options, buffer, null, contentType);
324
327
  }
328
+ // eslint-disable-next-line no-unused-vars
325
329
  } catch (error) {
326
330
  return getFetchResponse(resourceURL, options);
327
331
  }
@@ -340,6 +344,7 @@ function getInstance(utilOptions) {
340
344
  } else {
341
345
  try {
342
346
  return getFetchResponse(resourceURL, options, buffer, charset, contentType);
347
+ // eslint-disable-next-line no-unused-vars
343
348
  } catch (error) {
344
349
  return getFetchResponse(resourceURL, options, null, charset);
345
350
  }
@@ -372,6 +377,7 @@ async function getFetchResponse(resourceURL, options, data, charset, contentType
372
377
  }
373
378
  try {
374
379
  data = new TextDecoder(charset).decode(data);
380
+ // eslint-disable-next-line no-unused-vars
375
381
  } catch (error) {
376
382
  charset = "utf-8";
377
383
  data = new TextDecoder(charset).decode(data);
@@ -0,0 +1,31 @@
1
+ import js from "@eslint/js";
2
+
3
+ export default [
4
+ js.configs.recommended,
5
+ {
6
+ languageOptions: {
7
+ ecmaVersion: 2025,
8
+ sourceType: "module",
9
+ globals: {
10
+ console: "readonly",
11
+ }
12
+ },
13
+ rules: {
14
+ "linebreak-style": [
15
+ "error",
16
+ "unix"
17
+ ],
18
+ "quotes": [
19
+ "error",
20
+ "double"
21
+ ],
22
+ "semi": [
23
+ "error",
24
+ "always"
25
+ ],
26
+ "no-console": [
27
+ "warn"
28
+ ]
29
+ }
30
+ }
31
+ ];
@@ -21,8 +21,6 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- /* global globalThis */
25
-
26
24
  import * as cssTree from "./../vendor/css-tree.js";
27
25
  import * as fontPropertyParser from "./../vendor/css-font-property-parser.js";
28
26
  import {
@@ -248,6 +246,7 @@ function getDeclarationValue(declarations, propertyName) {
248
246
  if (property) {
249
247
  try {
250
248
  return helper.removeQuotes(cssTree.generate(property.data.value)).toLowerCase();
249
+ // eslint-disable-next-line no-unused-vars
251
250
  } catch (error) {
252
251
  // ignored
253
252
  }
@@ -278,6 +277,7 @@ function getFontFamilyNames(declarations, options) {
278
277
  }
279
278
  const parsedFont = fontPropertyParser.parse(value);
280
279
  parsedFont.family.forEach(familyName => fontFamilyNames.push(helper.normalizeFontFamily(familyName)));
280
+ // eslint-disable-next-line no-unused-vars
281
281
  } catch (error) {
282
282
  // ignored
283
283
  }
@@ -158,6 +158,7 @@ function getMatchedElementsSelector(doc, selectorInfo, styles, matchedElementsCa
158
158
  (matchedElement.style.getPropertyValue(DISPLAY_STYLE) != "none" || matchedElement.style.getPropertyPriority("display") != "important")
159
159
  );
160
160
  }
161
+ // eslint-disable-next-line no-unused-vars
161
162
  } catch (error) {
162
163
  // ignored
163
164
  }
@@ -106,6 +106,7 @@ function getSourceSrc(sourceSrcSet) {
106
106
  if (srcset.length) {
107
107
  return (srcset.find(srcset => srcset.url)).url;
108
108
  }
109
+ // eslint-disable-next-line no-unused-vars
109
110
  } catch (error) {
110
111
  // ignored
111
112
  }
@@ -230,6 +230,7 @@ function compressJSONLD(node) {
230
230
  if (node.nodeType == Node_ELEMENT_NODE && getTagName(node) == "SCRIPT" && node.type == "application/ld+json" && node.textContent.trim()) {
231
231
  try {
232
232
  node.textContent = JSON.stringify(JSON.parse(node.textContent));
233
+ // eslint-disable-next-line no-unused-vars
233
234
  } catch (error) {
234
235
  // ignored
235
236
  }
@@ -245,5 +246,5 @@ function removeEmptyInlineElements(doc) {
245
246
  }
246
247
 
247
248
  function getTagName(element) {
248
- return element.tagName && element.tagName.toUpperCase();
249
+ return element.tagName && element.tagName.toUpperCase();
249
250
  }
@@ -21,7 +21,7 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- const SELF_CLOSED_TAG_NAMES = ["AREA", "BASE", "BR", "COL", "COMMAND", "EMBED", "HR", "IMG", "INPUT", "KEYGEN", "LINK", "META", "PARAM", "SOURCE", "TRACK", "WBR"];
24
+ const VOID_TAG_NAMES = ["AREA", "BASE", "BASEFONT", "BGSOUND", "BR", "COL", "COMMAND", "EMBED", "FRAME", "HR", "IMG", "INPUT", "KEYGEN", "LINK", "META", "PARAM", "SOURCE", "TRACK", "WBR"];
25
25
 
26
26
  const Node_ELEMENT_NODE = 1;
27
27
  const Node_TEXT_NODE = 3;
@@ -122,7 +122,7 @@ function serializeElement(element, compressHTML, isSVG) {
122
122
  Array.from(element.childNodes).forEach(childNode => content += serialize(childNode, compressHTML, isSVG || tagName == "svg"));
123
123
  }
124
124
  const omittedEndTag = compressHTML && OMITTED_END_TAGS.find(omittedEndTag => tagName == getTagName(omittedEndTag) && omittedEndTag.accept(element.nextSibling, element));
125
- if (isSVG || (!omittedEndTag && !SELF_CLOSED_TAG_NAMES.includes(tagName))) {
125
+ if (isSVG || (!omittedEndTag && !VOID_TAG_NAMES.includes(tagName))) {
126
126
  content += "</" + tagName.toLowerCase() + ">";
127
127
  }
128
128
  return content;