single-file-core 1.5.27 → 1.5.29
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/index.js
CHANGED
|
@@ -1298,6 +1298,7 @@ class Processor {
|
|
|
1298
1298
|
options.saveFilenameTemplateData = false;
|
|
1299
1299
|
options.selected = false;
|
|
1300
1300
|
options.embeddedImage = null;
|
|
1301
|
+
options.embeddedPdf = null;
|
|
1301
1302
|
options.url = frameData.baseURI;
|
|
1302
1303
|
options.windowId = frameWindowId;
|
|
1303
1304
|
options.content = frameData.content;
|
|
@@ -129,6 +129,9 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
129
129
|
styleElement.textContent = this.generateStylesheetContent(stylesheetInfo.stylesheet, options);
|
|
130
130
|
} else {
|
|
131
131
|
const linkElement = linkElements.get(stylesheetRefIndex).cloneNode(true);
|
|
132
|
+
if (stylesheetInfo.mediaText) {
|
|
133
|
+
linkElement.media = stylesheetInfo.mediaText;
|
|
134
|
+
}
|
|
132
135
|
styleElement.replaceWith(linkElement);
|
|
133
136
|
key.element = linkElement;
|
|
134
137
|
}
|
package/package.json
CHANGED
|
@@ -43,21 +43,29 @@ const NO_COMPRESSION_EXTENSIONS = [".jpg", ".jpeg", ".png", ".avi", ".apng", ".p
|
|
|
43
43
|
const SCRIPT_PATH = "/lib/single-file-zip.min.js";
|
|
44
44
|
const EXTRA_DATA_TAGS = [
|
|
45
45
|
["<noscript>", "</noscript>"],
|
|
46
|
+
["<noframes>", "</noframes>"],
|
|
47
|
+
["<noembed>", "</noembed>"],
|
|
46
48
|
["<script type=sfz-data>", "</script>"],
|
|
49
|
+
["<style type=sfz-data>", "</style>"],
|
|
50
|
+
["<iframe>", "</iframe>"],
|
|
47
51
|
["<xmp>", "</xmp>"],
|
|
48
52
|
["<plaintext>", "</plaintext>"]
|
|
49
53
|
];
|
|
50
|
-
const
|
|
54
|
+
const EMBEDDED_DATA_TAGS = [
|
|
51
55
|
["<!--", "-->"],
|
|
52
56
|
...EXTRA_DATA_TAGS,
|
|
53
57
|
];
|
|
54
58
|
const EXTRA_DATA_REGEXPS = [
|
|
55
59
|
[/<noscript/i, /<\/noscript>/i],
|
|
60
|
+
[/<noframes/i, /<\/noframes>/i],
|
|
61
|
+
[/<noembed/i, /<\/noembed>/i],
|
|
56
62
|
[/<script/i, /<\/script>/i],
|
|
63
|
+
[/<style/i, /<\/style>/i],
|
|
64
|
+
[/<iframe/i, /<\/iframe>/i],
|
|
57
65
|
[/<xmp/i, /<\/xmp>/i],
|
|
58
66
|
[/<plaintext/i, /<\/plaintext>/i]
|
|
59
67
|
];
|
|
60
|
-
const
|
|
68
|
+
const EMBEDDED_DATA_REGEXPS = [
|
|
61
69
|
[/<!--/i, /-->/i],
|
|
62
70
|
...EXTRA_DATA_REGEXPS,
|
|
63
71
|
];
|
|
@@ -96,11 +104,11 @@ async function process(pageData, options, lastModDate = new Date()) {
|
|
|
96
104
|
await writeData(zipDataWriter.writable, options.embeddedImage.slice(0, PNG_SIGNATURE_LENGTH + PNG_IHDR_LENGTH));
|
|
97
105
|
if (options.selfExtractingArchive) {
|
|
98
106
|
const embeddedImageText = embeddedImageData.reduce((text, charCode) => text + String.fromCharCode(charCode), "");
|
|
99
|
-
const tagIndex =
|
|
107
|
+
const tagIndex = EMBEDDED_DATA_REGEXPS.findIndex(tests => !embeddedImageText.match(tests[1]));
|
|
100
108
|
let startTag;
|
|
101
|
-
[startTag, endTag] = tagIndex == -1 ? ["", ""] :
|
|
102
|
-
const
|
|
103
|
-
const hmtlData = new Uint8Array([...getLength(
|
|
109
|
+
[startTag, endTag] = tagIndex == -1 ? ["", ""] : EMBEDDED_DATA_TAGS[tagIndex];
|
|
110
|
+
const htmlArray = getStartHTMLArray(pageData, options, startTag);
|
|
111
|
+
const hmtlData = new Uint8Array([...getLength(htmlArray.length + 4), ...[0x74, 0x45, 0x58, 0x74, 0x50, 0x4e, 0x47, 0], ...htmlArray]);
|
|
104
112
|
await writeData(zipDataWriter.writable, hmtlData);
|
|
105
113
|
await writeData(zipDataWriter.writable, getCRC32(hmtlData, 4));
|
|
106
114
|
}
|
|
@@ -225,7 +233,7 @@ function setUint32(data, value) {
|
|
|
225
233
|
async function prependHTMLData(pageData, zipDataWriter, script, options) {
|
|
226
234
|
let pageContent = "";
|
|
227
235
|
if (!options.embeddedImage) {
|
|
228
|
-
|
|
236
|
+
await writeData(zipDataWriter.writable, getStartHTMLArray(pageData, options));
|
|
229
237
|
}
|
|
230
238
|
pageContent += "<div id=sfz-wait-message>Please wait...</div>";
|
|
231
239
|
if (!options.extractDataFromPage) {
|
|
@@ -281,17 +289,38 @@ async function prependHTMLData(pageData, zipDataWriter, script, options) {
|
|
|
281
289
|
return extraDataOffset;
|
|
282
290
|
}
|
|
283
291
|
|
|
284
|
-
function
|
|
285
|
-
let
|
|
292
|
+
function getStartHTMLArray(pageData, options, startTag = "") {
|
|
293
|
+
let html = "";
|
|
286
294
|
if (options.includeBOM && !options.extractDataFromPage && !options.embeddedImage) {
|
|
287
|
-
|
|
295
|
+
html += "\ufeff";
|
|
288
296
|
}
|
|
297
|
+
html += options.embeddedImage ? "" : pageData.doctype;
|
|
298
|
+
html += "<html data-sfz>";
|
|
299
|
+
html += pageData.comment && !options.embeddedImage ? "<!--" + pageData.comment + "-->" : "";
|
|
289
300
|
const charset = options.extractDataFromPage ? "windows-1252" : "utf-8";
|
|
301
|
+
html += "<meta charset=" + charset + ">";
|
|
302
|
+
const htmlHeadData = getHTMLHeadData(pageData, options);
|
|
303
|
+
let htmlArray;
|
|
304
|
+
if (options.embeddedPdf) {
|
|
305
|
+
const embeddedPdfText = options.embeddedPdf.reduce((text, charCode) => text + String.fromCharCode(charCode), "");
|
|
306
|
+
const pdfTagIndex = EMBEDDED_DATA_REGEXPS.findIndex(tests => !embeddedPdfText.match(tests[1]));
|
|
307
|
+
const [pdfStartTag, pdfEndTag] = pdfTagIndex == -1 ? ["", ""] : EMBEDDED_DATA_TAGS[pdfTagIndex];
|
|
308
|
+
const htmlArray1 = new TextEncoder().encode(html + pdfStartTag);
|
|
309
|
+
const htmlArray2 = new TextEncoder().encode(pdfEndTag + htmlHeadData + startTag);
|
|
310
|
+
htmlArray = new Uint8Array(htmlArray1.length + htmlArray2.length + options.embeddedPdf.length);
|
|
311
|
+
htmlArray.set(htmlArray1);
|
|
312
|
+
htmlArray.set(options.embeddedPdf, htmlArray1.length);
|
|
313
|
+
htmlArray.set(htmlArray2, htmlArray1.length + options.embeddedPdf.length);
|
|
314
|
+
} else {
|
|
315
|
+
htmlArray = new TextEncoder().encode(html + htmlHeadData + startTag);
|
|
316
|
+
}
|
|
317
|
+
return htmlArray;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function getHTMLHeadData(pageData, options) {
|
|
321
|
+
let pageContent = "";
|
|
290
322
|
const title = options.extractDataFromPage ? "" : getPageTitle(pageData);
|
|
291
|
-
pageContent +=
|
|
292
|
-
pageContent += "<html data-sfz>";
|
|
293
|
-
pageContent += pageData.comment && !options.embeddedImage ? "<!--" + pageData.comment + "-->" : "";
|
|
294
|
-
pageContent += "<meta charset=" + charset + "><title>" + title + "</title>";
|
|
323
|
+
pageContent += "<title>" + title + "</title>";
|
|
295
324
|
if (options.insertCanonicalLink) {
|
|
296
325
|
pageContent += "<link rel=canonical href=\"" + options.url + "\">";
|
|
297
326
|
}
|
|
@@ -151,8 +151,12 @@
|
|
|
151
151
|
});
|
|
152
152
|
document.addEventListener(GET_ADOPTED_STYLESHEETS_REQUEST_EVENT, getAdoptedStylesheetsListener);
|
|
153
153
|
document.addEventListener(BOOTSTRAP_EVENT, event => {
|
|
154
|
-
|
|
155
|
-
globalThis.bootstrap
|
|
154
|
+
try {
|
|
155
|
+
if (globalThis.bootstrap && event.detail.data) {
|
|
156
|
+
globalThis.bootstrap(event.detail.data);
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
// ignored
|
|
156
160
|
}
|
|
157
161
|
});
|
|
158
162
|
}
|
package/single-file.js
CHANGED
|
@@ -119,7 +119,8 @@ async function getPageData(options = {}, initOptions, doc = globalThis.document,
|
|
|
119
119
|
insertMetaCSP: options.insertMetaCSP,
|
|
120
120
|
password: options.password,
|
|
121
121
|
zipScript: options.zipScript,
|
|
122
|
-
embeddedImage: options.embeddedImage
|
|
122
|
+
embeddedImage: options.embeddedImage,
|
|
123
|
+
embeddedPdf: options.embeddedPdf
|
|
123
124
|
});
|
|
124
125
|
delete pageData.resources;
|
|
125
126
|
const reader = new globalThis.FileReader();
|