single-file-core 1.2.11 → 1.2.13

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);
package/core/index.js CHANGED
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -58,7 +58,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
58
58
  const REGEXP_MATCH_SCRIPT = /scripts\/[0-9]+\.js/;
59
59
  const REGEXP_MATCH_ROOT_INDEX = /^([0-9_]+\/)?index\.html$/;
60
60
  const REGEXP_MATCH_INDEX = /index\.html$/;
61
- const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
61
+ const REGEXP_MATCH_FRAMES = /frames\//;
62
62
  const CHARSET_UTF8 = ";charset=utf-8";
63
63
  if (Array.isArray(content)) {
64
64
  content = new Blob([new Uint8Array(content)]);
@@ -87,7 +87,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
87
87
  mimeType = "text/javascript" + CHARSET_UTF8;
88
88
  }
89
89
  if (textContent !== undefined) {
90
- content = await getDataURI(textContent, mimeType);
90
+ content = noBlobURL ? await getDataURI(textContent, mimeType) : URL.createObjectURL(new Blob([textContent], { type: mimeType }));
91
91
  } else {
92
92
  content = "data:text/plain,";
93
93
  }
@@ -99,7 +99,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
99
99
  } else {
100
100
  mimeType = "application/octet-stream";
101
101
  }
102
- if (filename.match(/frames\//) || noBlobURL) {
102
+ if (filename.match(REGEXP_MATCH_FRAMES) || noBlobURL) {
103
103
  content = await entry.getData(new zip.Data64URIWriter(mimeType), options);
104
104
  } else {
105
105
  const blob = await entry.getData(new zip.BlobWriter(mimeType), options);
@@ -129,16 +129,19 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
129
129
  if (filename.startsWith(prefixPath) && filename != resourceFilename) {
130
130
  const relativeFilename = filename.substring(prefixPath.length);
131
131
  if (!relativeFilename.match(/manifest\.json$/)) {
132
- const searchRegExp = new RegExp(relativeFilename.replace(REGEXP_ESCAPE, "\\$1"), "g");
133
- const position = textContent.search(searchRegExp);
132
+ const position = textContent.indexOf(relativeFilename);
134
133
  if (position != -1) {
135
134
  parentResources.push(resourceFilename);
136
- textContent = textContent.replace(searchRegExp, content);
135
+ textContent = textContent.replaceAll(relativeFilename, content);
137
136
  }
138
137
  }
139
138
  }
140
139
  }));
141
- resource.content = await getDataURI(textContent, mimeType);
140
+ if (filename.match(REGEXP_MATCH_INDEX) || filename.match(REGEXP_MATCH_FRAMES) || noBlobURL) {
141
+ resource.content = await getDataURI(textContent, mimeType);
142
+ } else {
143
+ resource.content = URL.createObjectURL(new Blob([textContent], { type: mimeType }));
144
+ }
142
145
  resource.textContent = textContent;
143
146
  }
144
147
  if (filename.match(REGEXP_MATCH_INDEX)) {
@@ -158,7 +161,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
158
161
  const reader = new FileReader();
159
162
  reader.readAsDataURL(new Blob([textContent], { type: mimeType }));
160
163
  return new Promise((resolve, reject) => {
161
- reader.onload = () => resolve(reader.result);
164
+ reader.onload = () => resolve(reader.result.replace(CHARSET_UTF8, ""));
162
165
  reader.onerror = reject;
163
166
  });
164
167
  }