single-file-core 1.3.17 → 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
|
@@ -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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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");
|
|
@@ -91,6 +91,7 @@ async function process(pageData, options, lastModDate = new Date()) {
|
|
|
91
91
|
zipDataWriter.writable.size = 0;
|
|
92
92
|
let extraDataOffset, extraData, embeddedImageDataOffset, endTag;
|
|
93
93
|
if (options.embeddedImage) {
|
|
94
|
+
options.embeddedImage = Array.from(options.embeddedImage);
|
|
94
95
|
const embeddedImageData = options.embeddedImage.slice(PNG_SIGNATURE_LENGTH + PNG_IHDR_LENGTH, options.embeddedImage.length - PNG_IEND_LENGTH);
|
|
95
96
|
await writeData(zipDataWriter.writable, options.embeddedImage.slice(0, PNG_SIGNATURE_LENGTH + PNG_IHDR_LENGTH));
|
|
96
97
|
if (options.selfExtractingArchive) {
|
|
@@ -250,13 +251,16 @@ async function prependHTMLData(pageData, zipDataWriter, script, options) {
|
|
|
250
251
|
textBody = textBody.replace(/</g, "<").replace(/>/g, ">").replace(/\n +/g, "\n").replace(/\n\n\n+/g, "\n\n").trim();
|
|
251
252
|
pageContent += "\n<main hidden>\n" + textBody + "\n</main>\n";
|
|
252
253
|
}
|
|
254
|
+
const displayOptions = {
|
|
255
|
+
insertEmbeddedImage: Boolean(options.embeddedImage),
|
|
256
|
+
};
|
|
253
257
|
script = "<script>" +
|
|
254
258
|
script +
|
|
255
259
|
"document.currentScript.remove();" +
|
|
256
260
|
"globalThis.addEventListener('load', () => {" +
|
|
257
261
|
"globalThis.bootstrap=(()=>{let bootstrapStarted;return async content=>{if (bootstrapStarted) return bootstrapStarted; bootstrapStarted = (" +
|
|
258
262
|
extract.toString().replace(/\n|\t/g, "") + ")(content,{prompt}).then(({docContent}) => " +
|
|
259
|
-
display.toString().replace(/\n|\t/g, "") + "(document,docContent));return bootstrapStarted;}})();(" +
|
|
263
|
+
display.toString().replace(/\n|\t/g, "") + "(document,docContent," + JSON.stringify(displayOptions) + "));return bootstrapStarted;}})();(" +
|
|
260
264
|
getContent.toString().replace(/\n|\t/g, "") + ")().then(globalThis.bootstrap).then(() => document.dispatchEvent(new CustomEvent(\"single-file-display-infobar\"))).catch(()=>{});" +
|
|
261
265
|
"});" +
|
|
262
266
|
"</script>";
|