single-file-core 1.3.18 → 1.3.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.3.18",
3
+ "version": "1.3.19",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -27,10 +27,21 @@ export {
27
27
  display
28
28
  };
29
29
 
30
- async function display(document, docContent, { disableFramePointerEvents } = {}) {
30
+ async function display(document, docContent, { disableFramePointerEvents, insertEmbeddedImage }) {
31
31
  docContent = docContent.replace(/<noscript/gi, "<template disabled-noscript");
32
32
  docContent = docContent.replaceAll(/<\/noscript/gi, "</template");
33
33
  const doc = (new DOMParser()).parseFromString(docContent, "text/html");
34
+ if (!insertEmbeddedImage) {
35
+ if (doc.doctype) {
36
+ if (document.doctype) {
37
+ document.replaceChild(doc.doctype, document.doctype);
38
+ } else {
39
+ document.insertBefore(doc.doctype, document.documentElement);
40
+ }
41
+ } else if (document.doctype) {
42
+ document.doctype.remove();
43
+ }
44
+ }
34
45
  if (disableFramePointerEvents) {
35
46
  doc.querySelectorAll("iframe").forEach(element => {
36
47
  const pointerEvents = "pointer-events";
@@ -38,10 +49,14 @@ async function display(document, docContent, { disableFramePointerEvents } = {})
38
49
  element.style.setProperty(pointerEvents, "none", "important");
39
50
  });
40
51
  }
41
- document.open();
42
- document.write(getDoctypeString(doc));
43
- document.write(doc.documentElement.outerHTML);
44
- document.close();
52
+ if (insertEmbeddedImage) {
53
+ document.open();
54
+ document.write(getDoctypeString(doc));
55
+ document.write(doc.documentElement.outerHTML);
56
+ document.close();
57
+ } else {
58
+ document.replaceChild(document.importNode(doc.documentElement, true), document.documentElement);
59
+ }
45
60
  document.querySelectorAll("template[disabled-noscript]").forEach(element => {
46
61
  const noscriptElement = document.createElement("noscript");
47
62
  element.removeAttribute("disabled-noscript");
@@ -251,13 +251,16 @@ async function prependHTMLData(pageData, zipDataWriter, script, options) {
251
251
  textBody = textBody.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n +/g, "\n").replace(/\n\n\n+/g, "\n\n").trim();
252
252
  pageContent += "\n<main hidden>\n" + textBody + "\n</main>\n";
253
253
  }
254
+ const displayOptions = {
255
+ insertEmbeddedImage: Boolean(options.embeddedImage),
256
+ };
254
257
  script = "<script>" +
255
258
  script +
256
259
  "document.currentScript.remove();" +
257
260
  "globalThis.addEventListener('load', () => {" +
258
261
  "globalThis.bootstrap=(()=>{let bootstrapStarted;return async content=>{if (bootstrapStarted) return bootstrapStarted; bootstrapStarted = (" +
259
262
  extract.toString().replace(/\n|\t/g, "") + ")(content,{prompt}).then(({docContent}) => " +
260
- display.toString().replace(/\n|\t/g, "") + "(document,docContent));return bootstrapStarted;}})();(" +
263
+ display.toString().replace(/\n|\t/g, "") + "(document,docContent," + JSON.stringify(displayOptions) + "));return bootstrapStarted;}})();(" +
261
264
  getContent.toString().replace(/\n|\t/g, "") + ")().then(globalThis.bootstrap).then(() => document.dispatchEvent(new CustomEvent(\"single-file-display-infobar\"))).catch(()=>{});" +
262
265
  "});" +
263
266
  "</script>";