single-file-core 1.2.12 → 1.2.14

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
@@ -203,12 +203,12 @@ function preProcessDoc(doc, win, options) {
203
203
 
204
204
  function getElementsInfo(win, doc, element, options, data = { usedFonts: new Map(), canvases: [], images: [], posters: [], videos: [], shadowRoots: [], markedElements: [] }, ascendantHidden) {
205
205
  if (element.childNodes) {
206
- const elements = Array.from(element.childNodes).filter(node => (node instanceof win.HTMLElement) || (node instanceof win.SVGElement));
206
+ const elements = Array.from(element.childNodes).filter(node => (node instanceof win.HTMLElement) || (node instanceof win.SVGElement) || (node instanceof globalThis.HTMLElement) || (node instanceof globalThis.SVGElement));
207
207
  elements.forEach(element => {
208
208
  let elementHidden, elementKept, computedStyle;
209
209
  if (!options.autoSaveExternalSave && (options.removeHiddenElements || options.removeUnusedFonts || options.compressHTML)) {
210
210
  computedStyle = getComputedStyle(win, element);
211
- if (element instanceof win.HTMLElement) {
211
+ if ((element instanceof win.HTMLElement) || (element instanceof globalThis.HTMLElement)) {
212
212
  if (options.removeHiddenElements) {
213
213
  elementKept = ((ascendantHidden || element.closest("html > head")) && KEPT_TAG_NAMES.includes(element.tagName.toUpperCase())) || element.closest("details");
214
214
  if (!elementKept) {
@@ -237,7 +237,7 @@ function getElementsInfo(win, doc, element, options, data = { usedFonts: new Map
237
237
  }
238
238
  }
239
239
  getResourcesInfo(win, doc, element, options, data, elementHidden, computedStyle);
240
- const shadowRoot = !(element instanceof win.SVGElement) && getShadowRoot(element);
240
+ const shadowRoot = !((element instanceof win.SVGElement) || (element instanceof globalThis.SVGElement)) && getShadowRoot(element);
241
241
  if (shadowRoot && !element.classList.contains(SINGLE_FILE_UI_ELEMENT_CLASS)) {
242
242
  const shadowRootInfo = {};
243
243
  element.setAttribute(SHADOW_ROOT_ATTRIBUTE_NAME, data.shadowRoots.length);
@@ -496,7 +496,9 @@ function getStylesheetsData(doc) {
496
496
  doc.body.appendChild(tempStyleElement);
497
497
  const stylesheet = tempStyleElement.sheet;
498
498
  tempStyleElement.remove();
499
- if (!stylesheet || stylesheet.cssRules.length != styleElement.sheet.cssRules.length) {
499
+ const textContentStylesheet = Array.from(stylesheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
500
+ const sheetStylesheet = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
501
+ if (!stylesheet || textContentStylesheet != sheetStylesheet) {
500
502
  styleElement.setAttribute(STYLESHEET_ATTRIBUTE_NAME, styleIndex);
501
503
  contents[styleIndex] = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
502
504
  }
package/core/index.js CHANGED
@@ -569,7 +569,7 @@ class Processor {
569
569
  this.stats.set("processed", "HTML bytes", contentSize);
570
570
  this.stats.add("discarded", "HTML bytes", size - contentSize);
571
571
  }
572
- const filename = await util.formatFilename(content, this.options);
572
+ const filename = await util.formatFilename(content, this.doc, this.options);
573
573
  const matchTitle = this.baseURI.match(/([^/]*)\/?(\.html?.*)$/) || this.baseURI.match(/\/\/([^/]*)\/?$/);
574
574
  const additionalData = this.processorHelper.getAdditionalPageData(this.doc, content, this.resources);
575
575
  const pageData = Object.assign({
@@ -588,9 +588,7 @@ class Processor {
588
588
  }
589
589
 
590
590
  preProcessPage() {
591
- if (this.options.win) {
592
- this.doc.body.querySelectorAll(":not(svg) title, meta, link[href][rel*=\"icon\"]").forEach(element => element instanceof this.options.win.HTMLElement && this.doc.head.appendChild(element));
593
- }
591
+ this.doc.body.querySelectorAll(":not(svg) title, meta, link[href][rel*=\"icon\"]").forEach(element => ((element instanceof (this.options.win && this.options.win.HTMLElement)) || (element instanceof globalThis.HTMLElement)) && this.doc.head.appendChild(element));
594
592
  if (this.options.images && !this.options.saveRawPage) {
595
593
  this.doc.querySelectorAll("img[" + util.IMAGE_ATTRIBUTE_NAME + "]").forEach(imgElement => {
596
594
  const attributeValue = imgElement.getAttribute(util.IMAGE_ATTRIBUTE_NAME);
@@ -1429,7 +1427,7 @@ class Processor {
1429
1427
  publisher: publisherElement && publisherElement.content ? publisherElement.content.trim() : "",
1430
1428
  heading: headingElement && headingElement.textContent ? headingElement.textContent.trim() : ""
1431
1429
  };
1432
- this.options.infobarContent = await util.evalTemplate(this.options.infobarTemplate, this.options, null, true);
1430
+ this.options.infobarContent = await util.evalTemplate(this.options.infobarTemplate, this.options, null, this.doc, true);
1433
1431
  }
1434
1432
  }
1435
1433
 
package/core/util.js CHANGED
@@ -130,11 +130,11 @@ function getInstance(utilOptions) {
130
130
  getContentSize(content) {
131
131
  return new Blob([content]).size;
132
132
  },
133
- formatFilename(content, options) {
134
- return modules.templateFormatter.formatFilename(content, options, this);
133
+ formatFilename(content, doc, options) {
134
+ return modules.templateFormatter.formatFilename(content, doc, options, this);
135
135
  },
136
- evalTemplate(template, options, content, dontReplaceSlash) {
137
- return modules.templateFormatter.evalTemplate(template, options, this, content, dontReplaceSlash);
136
+ async evalTemplate(template, options, content, doc, dontReplaceSlash) {
137
+ return modules.templateFormatter.evalTemplate(template, options, this, content, doc, dontReplaceSlash);
138
138
  },
139
139
  minifyHTML(doc, options) {
140
140
  return modules.htmlMinifier.process(doc, options);
@@ -313,7 +313,7 @@ function getInstance(utilOptions) {
313
313
  async function getFetchResponse(resourceURL, options, data, charset, contentType) {
314
314
  if (data) {
315
315
  if (options.asBinary) {
316
- if (options.inline) {
316
+ if (options.inline) {
317
317
  const reader = new FileReader();
318
318
  reader.readAsDataURL(new Blob([data], { type: contentType + (options.charset ? ";charset=" + options.charset : "") }));
319
319
  data = await new Promise((resolve, reject) => {