single-file-core 1.5.83 → 1.5.85

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.
@@ -140,7 +140,7 @@ function getProcessorHelperClass(utilInstance) {
140
140
  doc.head.appendChild(styleElement);
141
141
  }
142
142
  element.textContent = "/* */";
143
- element.setAttribute("onload", "this.textContent=document.querySelector('style[" + DUPLICATE_STYLESHEET_ATTRIBUTE_NAME + "=\"" + stylesheetRefIndex + "\"]')?.textContent;this.removeAttribute(\"onload\")");
143
+ element.setAttribute("onload", "this.textContent=document.querySelector('style[" + DUPLICATE_STYLESHEET_ATTRIBUTE_NAME + "=\"" + stylesheetRefIndex + "\"]')?.textContent;this.removeAttribute('onload')");
144
144
  } else {
145
145
  element.textContent = options.inlineStylesheets.get(stylesheetRefIndex).content;
146
146
  }
@@ -113,7 +113,8 @@ const redundantAttributes = {
113
113
  };
114
114
 
115
115
  const REGEXP_WHITESPACE = /[ \t\f\r]+/g;
116
- const REGEXP_NEWLINE = /[\n]+/g;
116
+ const REGEXP_WHITESPACE_COLLAPSE = /[ \t\f\r]{2,}|[\t\f\r]/g;
117
+ const REGEXP_NEWLINE = /\n{2,}/g;
117
118
  const REGEXP_ENDS_WHITESPACE = /^\s+$/;
118
119
  const NodeFilter_SHOW_ALL = 4294967295;
119
120
  const Node_ELEMENT_NODE = 1;
@@ -179,7 +180,17 @@ function collapseWhitespace(node, options) {
179
180
  noWhitespace = element && noWhitespaceCollapse(element);
180
181
  }
181
182
  if ((!element || noWhitespace) && textContent.length > 1) {
182
- node.textContent = textContent.replace(REGEXP_WHITESPACE, getWhiteSpace(node)).replace(REGEXP_NEWLINE, "\n");
183
+ const whitespace = getWhiteSpace(node);
184
+ let newTextContent;
185
+ if (whitespace == " ") {
186
+ newTextContent = textContent.replace(REGEXP_WHITESPACE_COLLAPSE, " ");
187
+ } else {
188
+ newTextContent = textContent.replace(REGEXP_WHITESPACE, whitespace);
189
+ }
190
+ newTextContent = newTextContent.replace(REGEXP_NEWLINE, "\n");
191
+ if (newTextContent != textContent) {
192
+ node.textContent = newTextContent;
193
+ }
183
194
  }
184
195
  }
185
196
  }
@@ -26,7 +26,7 @@
26
26
  /*
27
27
  * Generated by PEG.js 0.10.0.
28
28
  *
29
- * http://pegjs.org/
29
+ * https://github.com/pegjs/pegjs
30
30
  */
31
31
 
32
32
  /* Modified manually by Gildas Lormeau in order to support async/await callbacks */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.5.83",
3
+ "version": "1.5.85",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -29,7 +29,7 @@ export {
29
29
 
30
30
  async function display(document, docContent, { disableFramePointerEvents } = {}) {
31
31
  docContent = docContent.replace(/<noscript/gi, "<template disabled-noscript");
32
- docContent = docContent.replaceAll(/<\/noscript/gi, "</template");
32
+ docContent = docContent.replace(/<\/noscript/gi, "</template");
33
33
  const doc = (new DOMParser()).parseFromString(docContent, "text/html");
34
34
  if (disableFramePointerEvents) {
35
35
  doc.querySelectorAll("iframe").forEach(element => {
@@ -27,7 +27,7 @@ export {
27
27
  extract
28
28
  };
29
29
 
30
- async function extract(content, { password, prompt = () => { }, zipOptions = { useWebWorkers: false }, noBlobURL } = {}) {
30
+ async function extract(content, { password, prompt = () => { }, zipOptions = { useWebWorkers: true }, noBlobURL } = {}) {
31
31
  const KNOWN_MIMETYPES = {
32
32
  "gif": "image/gif",
33
33
  "jpg": "image/jpeg",
@@ -74,13 +74,17 @@ async function extract(content, { password, prompt = () => { }, zipOptions = { u
74
74
  const REGEXP_MATCH_MANIFEST = /manifest\.json$/;
75
75
  const CHARSET_UTF8 = ";charset=utf-8";
76
76
  const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
77
-
78
- if (Array.isArray(content)) {
79
- content = new Blob([new Uint8Array(content)]);
80
- }
77
+ let reader;
81
78
  zip.configure(zipOptions);
82
- const blobReader = new zip.BlobReader(content);
83
- const zipReader = new zip.ZipReader(blobReader);
79
+ if (content.readUint8Array) {
80
+ reader = content;
81
+ } else {
82
+ if (Array.isArray(content)) {
83
+ content = new Blob([new Uint8Array(content)]);
84
+ }
85
+ reader = new zip.BlobReader(content);
86
+ }
87
+ const zipReader = new zip.ZipReader(reader);
84
88
  const entries = await zipReader.getEntries();
85
89
  const options = { password };
86
90
  let docContent, origDocContent, url, resources = [], indexPages = [], textResources = [];
@@ -98,7 +102,11 @@ async function extract(content, { password, prompt = () => { }, zipOptions = { u
98
102
  textResources.push(resourceInfo);
99
103
  }
100
104
  dataWriter = new zip.TextWriter();
101
- textContent = await entry.getData(dataWriter, options);
105
+ if (entry.uncompressedSize > 0) {
106
+ textContent = await entry.getData(dataWriter, options);
107
+ } else {
108
+ textContent = "";
109
+ }
102
110
  if (filename.match(REGEXP_MATCH_INDEX)) {
103
111
  mimeType = "text/html" + CHARSET_UTF8;
104
112
  } else {