single-file-core 1.5.96 → 1.5.97

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
@@ -93,6 +93,7 @@ const URL = globalThis.URL;
93
93
  const DOMParser = globalThis.DOMParser;
94
94
  const Uint8Array = globalThis.Uint8Array;
95
95
  const btoa = globalThis.btoa;
96
+ const FileReader = globalThis.FileReader;
96
97
 
97
98
  export {
98
99
  initUserScriptHandler,
@@ -800,12 +801,21 @@ function getContentSize(content) {
800
801
  }
801
802
 
802
803
  async function getDataURI(blob) {
803
- const bytes = new Uint8Array(await blob.arrayBuffer());
804
- let content = "";
805
- for (let offset = 0; offset < bytes.length; offset += 8192) {
806
- content += String.fromCharCode(...bytes.subarray(offset, offset + 8192));
804
+ if (FileReader) {
805
+ const reader = new FileReader();
806
+ reader.readAsDataURL(blob);
807
+ return new Promise((resolve, reject) => {
808
+ reader.addEventListener("load", () => resolve(reader.result), false);
809
+ reader.addEventListener("error", reject, false);
810
+ });
811
+ } else {
812
+ const bytes = new Uint8Array(await blob.arrayBuffer());
813
+ let content = "";
814
+ for (let offset = 0; offset < bytes.length; offset += 8192) {
815
+ content += String.fromCharCode(...bytes.subarray(offset, offset + 8192));
816
+ }
817
+ return "data:" + (blob.type || "application/octet-stream") + ";base64," + btoa(content);
807
818
  }
808
- return "data:" + (blob.type || "application/octet-stream") + ";base64," + btoa(content);
809
819
  }
810
820
 
811
821
  async function digest(algo, text) {
@@ -17264,7 +17264,18 @@ function getLastSegment(url, replacementCharacter) {
17264
17264
 
17265
17265
  async function truncateText(content, maxSize) {
17266
17266
  const blob = new Blob([content]);
17267
- const result = await blob.slice(0, maxSize).text();
17267
+ const truncatedBlob = blob.slice(0, maxSize);
17268
+ let result;
17269
+ if (globalThis.FileReader) {
17270
+ const reader = new globalThis.FileReader();
17271
+ reader.readAsText(truncatedBlob);
17272
+ result = await new Promise((resolve, reject) => {
17273
+ reader.addEventListener("load", () => resolve(reader.result), false);
17274
+ reader.addEventListener("error", reject, false);
17275
+ });
17276
+ } else {
17277
+ result = await truncatedBlob.text();
17278
+ }
17268
17279
  if (content.startsWith(result)) {
17269
17280
  return result;
17270
17281
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.5.96",
3
+ "version": "1.5.97",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -401,6 +401,7 @@
401
401
  };
402
402
  globalThis.FontFace.prototype = origFontFace.prototype;
403
403
  globalThis.FontFace.toString = function () { return "function FontFace() { [native code] }"; };
404
+ setFunctionName(globalThis.FontFace, "FontFace");
404
405
  const deleteFont = document.fonts.delete;
405
406
  document.fonts.delete = function (fontFace) {
406
407
  try {
@@ -426,12 +427,12 @@
426
427
  }
427
428
 
428
429
  if (globalThis.IntersectionObserver) {
429
- const IntersectionObserver = globalThis.IntersectionObserver;
430
- globalThis.IntersectionObserver = function () {
430
+ const origIntersectionObserver = globalThis.IntersectionObserver;
431
+ globalThis.IntersectionObserver = function IntersectionObserver() {
431
432
  try {
432
- const intersectionObserver = new IntersectionObserver(...arguments);
433
- const observeIntersection = IntersectionObserver.prototype.observe || intersectionObserver.observe;
434
- const unobserveIntersection = IntersectionObserver.prototype.unobserve || intersectionObserver.unobserve;
433
+ const intersectionObserver = new origIntersectionObserver(...arguments);
434
+ const observeIntersection = origIntersectionObserver.prototype.observe || intersectionObserver.observe;
435
+ const unobserveIntersection = origIntersectionObserver.prototype.unobserve || intersectionObserver.unobserve;
435
436
  const callback = arguments[0];
436
437
  const options = arguments[1];
437
438
  if (observeIntersection) {
@@ -479,8 +480,9 @@
479
480
  throw error;
480
481
  }
481
482
  };
482
- globalThis.IntersectionObserver.prototype = IntersectionObserver.prototype;
483
+ globalThis.IntersectionObserver.prototype = origIntersectionObserver.prototype;
483
484
  globalThis.IntersectionObserver.toString = function () { return "function IntersectionObserver() { [native code] }"; };
485
+ setFunctionName(globalThis.IntersectionObserver, "IntersectionObserver");
484
486
  }
485
487
 
486
488
  const originalReplaceSync = CSSStyleSheet.prototype.replaceSync;
@@ -575,6 +577,10 @@
575
577
  return detail;
576
578
  }
577
579
 
580
+ function setFunctionName(fn, name) {
581
+ Object.defineProperty(fn, "name", { value: name, configurable: true });
582
+ }
583
+
578
584
  function dispatchResizeEvent() {
579
585
  try {
580
586
  globalThis.dispatchEvent(new UIEvent("resize"));
package/single-file.js CHANGED
@@ -128,7 +128,18 @@ async function getPageData(options = {}, initOptions, doc, win) {
128
128
  embeddedPdf: options.embeddedPdf
129
129
  });
130
130
  delete pageData.resources;
131
- pageData.content = Array.from(new Uint8Array(await blob.arrayBuffer()));
131
+ let arrayBuffer;
132
+ if (globalThis.FileReader) {
133
+ const reader = new globalThis.FileReader();
134
+ reader.readAsArrayBuffer(blob);
135
+ arrayBuffer = await new Promise((resolve, reject) => {
136
+ reader.addEventListener("load", () => resolve(reader.result), false);
137
+ reader.addEventListener("error", reject, false);
138
+ });
139
+ } else {
140
+ arrayBuffer = await blob.arrayBuffer();
141
+ }
142
+ pageData.content = Array.from(new Uint8Array(arrayBuffer));
132
143
  }
133
144
  return pageData;
134
145
  }