|
@@ -21,9 +21,9 @@
|
|
|
* Source.
|
|
* Source.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-/* global window */
|
|
|
|
|
|
|
+/* global window, globalThis */
|
|
|
|
|
|
|
|
-(() => {
|
|
|
|
|
|
|
+(globalThis => {
|
|
|
|
|
|
|
|
const LOAD_DEFERRED_IMAGES_START_EVENT = "single-file-load-deferred-images-start";
|
|
const LOAD_DEFERRED_IMAGES_START_EVENT = "single-file-load-deferred-images-start";
|
|
|
const LOAD_DEFERRED_IMAGES_END_EVENT = "single-file-load-deferred-images-end";
|
|
const LOAD_DEFERRED_IMAGES_END_EVENT = "single-file-load-deferred-images-end";
|
|
@@ -49,16 +49,16 @@
|
|
|
featureSettings: "font-feature-settings"
|
|
featureSettings: "font-feature-settings"
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const addEventListener = (type, listener, options) => window.addEventListener(type, listener, options);
|
|
|
|
|
- const dispatchEvent = event => window.dispatchEvent(event);
|
|
|
|
|
- const CustomEvent = window.CustomEvent;
|
|
|
|
|
- const document = window.document;
|
|
|
|
|
- const screen = window.screen;
|
|
|
|
|
- const Element = window.Element;
|
|
|
|
|
- const UIEvent = window.UIEvent;
|
|
|
|
|
- const FileReader = window.FileReader;
|
|
|
|
|
- const Blob = window.Blob;
|
|
|
|
|
- const console = window.console;
|
|
|
|
|
|
|
+ const addEventListener = (type, listener, options) => globalThis.addEventListener(type, listener, options);
|
|
|
|
|
+ const dispatchEvent = event => globalThis.dispatchEvent(event);
|
|
|
|
|
+ const CustomEvent = globalThis.CustomEvent;
|
|
|
|
|
+ const document = globalThis.document;
|
|
|
|
|
+ const screen = globalThis.screen;
|
|
|
|
|
+ const Element = globalThis.Element;
|
|
|
|
|
+ const UIEvent = globalThis.UIEvent;
|
|
|
|
|
+ const FileReader = globalThis.FileReader;
|
|
|
|
|
+ const Blob = globalThis.Blob;
|
|
|
|
|
+ const console = globalThis.console;
|
|
|
const warn = (console && console.warn && ((...args) => console.warn(...args))) || (() => { });
|
|
const warn = (console && console.warn && ((...args) => console.warn(...args))) || (() => { });
|
|
|
|
|
|
|
|
const observers = new Map();
|
|
const observers = new Map();
|
|
@@ -81,15 +81,15 @@
|
|
|
scrollingElement.__defineGetter__("clientWidth", () => scrollWidth);
|
|
scrollingElement.__defineGetter__("clientWidth", () => scrollWidth);
|
|
|
screen.__defineGetter__("height", () => scrollHeight);
|
|
screen.__defineGetter__("height", () => scrollHeight);
|
|
|
screen.__defineGetter__("width", () => scrollWidth);
|
|
screen.__defineGetter__("width", () => scrollWidth);
|
|
|
- window._singleFile_innerHeight = window.innerHeight;
|
|
|
|
|
- window._singleFile_innerWidth = window.innerWidth;
|
|
|
|
|
- window.__defineGetter__("innerHeight", () => scrollHeight);
|
|
|
|
|
- window.__defineGetter__("innerWidth", () => scrollWidth);
|
|
|
|
|
|
|
+ globalThis._singleFile_innerHeight = globalThis.innerHeight;
|
|
|
|
|
+ globalThis._singleFile_innerWidth = globalThis.innerWidth;
|
|
|
|
|
+ globalThis.__defineGetter__("innerHeight", () => scrollHeight);
|
|
|
|
|
+ globalThis.__defineGetter__("innerWidth", () => scrollWidth);
|
|
|
if (!keepZoomLevel) {
|
|
if (!keepZoomLevel) {
|
|
|
- if (!window._singleFile_getBoundingClientRect) {
|
|
|
|
|
- window._singleFile_getBoundingClientRect = Element.prototype.getBoundingClientRect;
|
|
|
|
|
|
|
+ if (!globalThis._singleFile_getBoundingClientRect) {
|
|
|
|
|
+ globalThis._singleFile_getBoundingClientRect = Element.prototype.getBoundingClientRect;
|
|
|
Element.prototype.getBoundingClientRect = function () {
|
|
Element.prototype.getBoundingClientRect = function () {
|
|
|
- const boundingRect = window._singleFile_getBoundingClientRect.call(this);
|
|
|
|
|
|
|
+ const boundingRect = globalThis._singleFile_getBoundingClientRect.call(this);
|
|
|
if (this == scrollingElement) {
|
|
if (this == scrollingElement) {
|
|
|
boundingRect.__defineGetter__("height", () => scrollHeight);
|
|
boundingRect.__defineGetter__("height", () => scrollHeight);
|
|
|
boundingRect.__defineGetter__("bottom", () => scrollHeight + boundingRect.top);
|
|
boundingRect.__defineGetter__("bottom", () => scrollHeight + boundingRect.top);
|
|
@@ -100,10 +100,10 @@
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (!window._singleFileImage) {
|
|
|
|
|
- const Image = window.Image;
|
|
|
|
|
- window._singleFileImage = window.Image;
|
|
|
|
|
- window.__defineGetter__("Image", function () {
|
|
|
|
|
|
|
+ if (!globalThis._singleFileImage) {
|
|
|
|
|
+ const Image = globalThis.Image;
|
|
|
|
|
+ globalThis._singleFileImage = globalThis.Image;
|
|
|
|
|
+ globalThis.__defineGetter__("Image", function () {
|
|
|
return function () {
|
|
return function () {
|
|
|
const image = new Image(...arguments);
|
|
const image = new Image(...arguments);
|
|
|
const result = new Image(...arguments);
|
|
const result = new Image(...arguments);
|
|
@@ -137,8 +137,8 @@
|
|
|
zoomFactorX = clientHeight / scrollHeight;
|
|
zoomFactorX = clientHeight / scrollHeight;
|
|
|
zoomFactorY = clientWidth / scrollWidth;
|
|
zoomFactorY = clientWidth / scrollWidth;
|
|
|
} else {
|
|
} else {
|
|
|
- zoomFactorX = (clientHeight + window.scrollY) / scrollHeight;
|
|
|
|
|
- zoomFactorY = (clientWidth + window.scrollX) / scrollWidth;
|
|
|
|
|
|
|
+ zoomFactorX = (clientHeight + globalThis.scrollY) / scrollHeight;
|
|
|
|
|
+ zoomFactorY = (clientWidth + globalThis.scrollX) / scrollWidth;
|
|
|
}
|
|
}
|
|
|
const zoomFactor = Math.min(zoomFactorX, zoomFactorY);
|
|
const zoomFactor = Math.min(zoomFactorX, zoomFactorY);
|
|
|
if (zoomFactor < 1) {
|
|
if (zoomFactor < 1) {
|
|
@@ -208,15 +208,15 @@
|
|
|
element.removeAttribute(LAZY_LOAD_ATTRIBUTE);
|
|
element.removeAttribute(LAZY_LOAD_ATTRIBUTE);
|
|
|
});
|
|
});
|
|
|
if (!keepZoomLevel) {
|
|
if (!keepZoomLevel) {
|
|
|
- if (window._singleFile_getBoundingClientRect) {
|
|
|
|
|
- Element.prototype.getBoundingClientRect = window._singleFile_getBoundingClientRect;
|
|
|
|
|
- delete window._singleFile_getBoundingClientRect;
|
|
|
|
|
|
|
+ if (globalThis._singleFile_getBoundingClientRect) {
|
|
|
|
|
+ Element.prototype.getBoundingClientRect = globalThis._singleFile_getBoundingClientRect;
|
|
|
|
|
+ delete globalThis._singleFile_getBoundingClientRect;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (window._singleFileImage) {
|
|
|
|
|
- delete window.Image;
|
|
|
|
|
- window.Image = window._singleFileImage;
|
|
|
|
|
- delete window._singleFileImage;
|
|
|
|
|
|
|
+ if (globalThis._singleFileImage) {
|
|
|
|
|
+ delete globalThis.Image;
|
|
|
|
|
+ globalThis.Image = globalThis._singleFileImage;
|
|
|
|
|
+ delete globalThis._singleFileImage;
|
|
|
}
|
|
}
|
|
|
if (!keepZoomLevel) {
|
|
if (!keepZoomLevel) {
|
|
|
dispatchResizeEvent();
|
|
dispatchResizeEvent();
|
|
@@ -225,13 +225,13 @@
|
|
|
|
|
|
|
|
function resetScreenSize() {
|
|
function resetScreenSize() {
|
|
|
const scrollingElement = document.scrollingElement || document.documentElement;
|
|
const scrollingElement = document.scrollingElement || document.documentElement;
|
|
|
- if (window._singleFile_innerHeight != null) {
|
|
|
|
|
- window.innerHeight = window._singleFile_innerHeight;
|
|
|
|
|
- delete window._singleFile_innerHeight;
|
|
|
|
|
|
|
+ if (globalThis._singleFile_innerHeight != null) {
|
|
|
|
|
+ globalThis.innerHeight = globalThis._singleFile_innerHeight;
|
|
|
|
|
+ delete globalThis._singleFile_innerHeight;
|
|
|
}
|
|
}
|
|
|
- if (window._singleFile_innerWidth != null) {
|
|
|
|
|
- window.innerWidth = window._singleFile_innerWidth;
|
|
|
|
|
- delete window._singleFile_innerWidth;
|
|
|
|
|
|
|
+ if (globalThis._singleFile_innerWidth != null) {
|
|
|
|
|
+ globalThis.innerWidth = globalThis._singleFile_innerWidth;
|
|
|
|
|
+ delete globalThis._singleFile_innerWidth;
|
|
|
}
|
|
}
|
|
|
delete scrollingElement.clientHeight;
|
|
delete scrollingElement.clientHeight;
|
|
|
delete scrollingElement.clientWidth;
|
|
delete scrollingElement.clientWidth;
|
|
@@ -252,33 +252,33 @@
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
addEventListener(BLOCK_STORAGE_START_EVENT, () => {
|
|
addEventListener(BLOCK_STORAGE_START_EVENT, () => {
|
|
|
- if (!window._singleFile_localStorage) {
|
|
|
|
|
- window._singleFile_localStorage = window.localStorage;
|
|
|
|
|
- window.__defineGetter__("localStorage", () => { throw new Error("localStorage temporary blocked by SingleFile"); });
|
|
|
|
|
|
|
+ if (!globalThis._singleFile_localStorage) {
|
|
|
|
|
+ globalThis._singleFile_localStorage = globalThis.localStorage;
|
|
|
|
|
+ globalThis.__defineGetter__("localStorage", () => { throw new Error("localStorage temporary blocked by SingleFile"); });
|
|
|
}
|
|
}
|
|
|
- if (!window._singleFile_indexedDB) {
|
|
|
|
|
- window._singleFile_indexedDB = window.indexedDB;
|
|
|
|
|
- window.__defineGetter__("indexedDB", () => { throw new Error("indexedDB temporary blocked by SingleFile"); });
|
|
|
|
|
|
|
+ if (!globalThis._singleFile_indexedDB) {
|
|
|
|
|
+ globalThis._singleFile_indexedDB = globalThis.indexedDB;
|
|
|
|
|
+ globalThis.__defineGetter__("indexedDB", () => { throw new Error("indexedDB temporary blocked by SingleFile"); });
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
addEventListener(BLOCK_STORAGE_END_EVENT, () => {
|
|
addEventListener(BLOCK_STORAGE_END_EVENT, () => {
|
|
|
- if (window._singleFile_localStorage) {
|
|
|
|
|
- delete window.localStorage;
|
|
|
|
|
- window.localStorage = window._singleFile_localStorage;
|
|
|
|
|
- delete window._singleFile_localStorage;
|
|
|
|
|
|
|
+ if (globalThis._singleFile_localStorage) {
|
|
|
|
|
+ delete globalThis.localStorage;
|
|
|
|
|
+ globalThis.localStorage = globalThis._singleFile_localStorage;
|
|
|
|
|
+ delete globalThis._singleFile_localStorage;
|
|
|
}
|
|
}
|
|
|
- if (!window._singleFile_indexedDB) {
|
|
|
|
|
- delete window.indexedDB;
|
|
|
|
|
- window.indexedDB = window._singleFile_indexedDB;
|
|
|
|
|
- delete window._singleFile_indexedDB;
|
|
|
|
|
|
|
+ if (!globalThis._singleFile_indexedDB) {
|
|
|
|
|
+ delete globalThis.indexedDB;
|
|
|
|
|
+ globalThis.indexedDB = globalThis._singleFile_indexedDB;
|
|
|
|
|
+ delete globalThis._singleFile_indexedDB;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- if (window.FontFace) {
|
|
|
|
|
- const FontFace = window.FontFace;
|
|
|
|
|
|
|
+ if (globalThis.FontFace) {
|
|
|
|
|
+ const FontFace = globalThis.FontFace;
|
|
|
let warningFontFaceDisplayed;
|
|
let warningFontFaceDisplayed;
|
|
|
- window.FontFace = function () {
|
|
|
|
|
|
|
+ globalThis.FontFace = function () {
|
|
|
if (!warningFontFaceDisplayed) {
|
|
if (!warningFontFaceDisplayed) {
|
|
|
warn("SingleFile is hooking the FontFace constructor to get font URLs."); // eslint-disable-line no-console
|
|
warn("SingleFile is hooking the FontFace constructor to get font URLs."); // eslint-disable-line no-console
|
|
|
warningFontFaceDisplayed = true;
|
|
warningFontFaceDisplayed = true;
|
|
@@ -306,13 +306,13 @@
|
|
|
}
|
|
}
|
|
|
return new FontFace(...arguments);
|
|
return new FontFace(...arguments);
|
|
|
};
|
|
};
|
|
|
- window.FontFace.toString = function () { return "function FontFace() { [native code] }"; };
|
|
|
|
|
|
|
+ globalThis.FontFace.toString = function () { return "function FontFace() { [native code] }"; };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (window.IntersectionObserver) {
|
|
|
|
|
- const IntersectionObserver = window.IntersectionObserver;
|
|
|
|
|
|
|
+ if (globalThis.IntersectionObserver) {
|
|
|
|
|
+ const IntersectionObserver = globalThis.IntersectionObserver;
|
|
|
let warningIntersectionObserverDisplayed;
|
|
let warningIntersectionObserverDisplayed;
|
|
|
- window.IntersectionObserver = function () {
|
|
|
|
|
|
|
+ globalThis.IntersectionObserver = function () {
|
|
|
if (!warningIntersectionObserverDisplayed) {
|
|
if (!warningIntersectionObserverDisplayed) {
|
|
|
warn("SingleFile is hooking the IntersectionObserver API to detect and load deferred images."); // eslint-disable-line no-console
|
|
warn("SingleFile is hooking the IntersectionObserver API to detect and load deferred images."); // eslint-disable-line no-console
|
|
|
warningIntersectionObserverDisplayed = true;
|
|
warningIntersectionObserverDisplayed = true;
|
|
@@ -351,8 +351,8 @@
|
|
|
observers.set(intersectionObserver, { callback, options });
|
|
observers.set(intersectionObserver, { callback, options });
|
|
|
return intersectionObserver;
|
|
return intersectionObserver;
|
|
|
};
|
|
};
|
|
|
- window.IntersectionObserver.prototype = IntersectionObserver.prototype;
|
|
|
|
|
- window.IntersectionObserver.toString = function () { return "function IntersectionObserver() { [native code] }"; };
|
|
|
|
|
|
|
+ globalThis.IntersectionObserver.prototype = IntersectionObserver.prototype;
|
|
|
|
|
+ globalThis.IntersectionObserver.toString = function () { return "function IntersectionObserver() { [native code] }"; };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function dispatchResizeEvent() {
|
|
function dispatchResizeEvent() {
|
|
@@ -363,4 +363,4 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-})();
|
|
|
|
|
|
|
+})(typeof globalThis == "object" ? globalThis : window);
|