single-file-core 1.0.14 → 1.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -41,7 +41,6 @@ const NEW_FONT_FACE_EVENT = "single-file-new-font-face";
41
41
  const DELETE_FONT_EVENT = "single-file-delete-font";
42
42
  const CLEAR_FONTS_EVENT = "single-file-clear-fonts";
43
43
 
44
- const browser = globalThis.browser;
45
44
  const addEventListener = (type, listener, options) => globalThis.addEventListener(type, listener, options);
46
45
  const dispatchEvent = event => { try { globalThis.dispatchEvent(event); } catch (error) { /* ignored */ } };
47
46
  const CustomEvent = globalThis.CustomEvent;
@@ -69,17 +68,6 @@ if (document instanceof Document) {
69
68
  fontFaces.delete(JSON.stringify(key));
70
69
  });
71
70
  addEventListener(CLEAR_FONTS_EVENT, () => fontFaces = new Map());
72
- let scriptElement = document.createElement("script");
73
- scriptElement.src = "data:," + "(" + injectedScript.toString() + ")()";
74
- (document.documentElement || document).appendChild(scriptElement);
75
- scriptElement.remove();
76
- if (browser && browser.runtime && browser.runtime.getURL) {
77
- scriptElement = document.createElement("script");
78
- scriptElement.src = browser.runtime.getURL("/lib/single-file-hooks-frames.js");
79
- scriptElement.async = false;
80
- (document.documentElement || document).appendChild(scriptElement);
81
- scriptElement.remove();
82
- }
83
71
  }
84
72
 
85
73
  export {
@@ -135,80 +123,4 @@ function loadDeferredImagesResetZoomLevel(options) {
135
123
  } else {
136
124
  dispatchEvent(new CustomEvent(LOAD_DEFERRED_IMAGES_RESET_EVENT));
137
125
  }
138
- }
139
-
140
- function injectedScript() {
141
- if (typeof globalThis == "undefined") {
142
- window.globalThis = window;
143
- }
144
- const document = globalThis.document;
145
- const console = globalThis.console;
146
- const dispatchEvent = event => globalThis.dispatchEvent(event);
147
- const CustomEvent = globalThis.CustomEvent;
148
- const FileReader = globalThis.FileReader;
149
- const Blob = globalThis.Blob;
150
- const warn = (console && console.warn && ((...args) => console.warn(...args))) || (() => { });
151
- const NEW_FONT_FACE_EVENT = "single-file-new-font-face";
152
- const DELETE_FONT_EVENT = "single-file-delete-font";
153
- const CLEAR_FONTS_EVENT = "single-file-clear-fonts";
154
- const FONT_STYLE_PROPERTIES = {
155
- family: "font-family",
156
- style: "font-style",
157
- weight: "font-weight",
158
- stretch: "font-stretch",
159
- unicodeRange: "unicode-range",
160
- variant: "font-variant",
161
- featureSettings: "font-feature-settings"
162
- };
163
-
164
- if (globalThis.FontFace) {
165
- const FontFace = globalThis.FontFace;
166
- let warningFontFaceDisplayed;
167
- globalThis.FontFace = function () {
168
- if (!warningFontFaceDisplayed) {
169
- warn("SingleFile is hooking the FontFace constructor, document.fonts.delete and document.fonts.clear to handle dynamically loaded fonts.");
170
- warningFontFaceDisplayed = true;
171
- }
172
- getDetailObject(...arguments).then(detail => dispatchEvent(new CustomEvent(NEW_FONT_FACE_EVENT, { detail })));
173
- return new FontFace(...arguments);
174
- };
175
- globalThis.FontFace.toString = function () { return "function FontFace() { [native code] }"; };
176
- const deleteFont = document.fonts.delete;
177
- document.fonts.delete = function (fontFace) {
178
- getDetailObject(fontFace.family).then(detail => dispatchEvent(new CustomEvent(DELETE_FONT_EVENT, { detail })));
179
- return deleteFont.call(document.fonts, fontFace);
180
- };
181
- document.fonts.delete.toString = function () { return "function delete() { [native code] }"; };
182
- const clearFonts = document.fonts.clear;
183
- document.fonts.clear = function () {
184
- dispatchEvent(new CustomEvent(CLEAR_FONTS_EVENT));
185
- return clearFonts.call(document.fonts);
186
- };
187
- document.fonts.clear.toString = function () { return "function clear() { [native code] }"; };
188
- }
189
-
190
- async function getDetailObject(fontFamily, src, descriptors) {
191
- const detail = {};
192
- detail["font-family"] = fontFamily;
193
- detail.src = src;
194
- if (descriptors) {
195
- Object.keys(descriptors).forEach(descriptor => {
196
- if (FONT_STYLE_PROPERTIES[descriptor]) {
197
- detail[FONT_STYLE_PROPERTIES[descriptor]] = descriptors[descriptor];
198
- }
199
- });
200
- }
201
- return new Promise(resolve => {
202
- if (detail.src instanceof ArrayBuffer) {
203
- const reader = new FileReader();
204
- reader.readAsDataURL(new Blob([detail.src]));
205
- reader.addEventListener("load", () => {
206
- detail.src = "url(" + reader.result + ")";
207
- resolve(detail);
208
- });
209
- } else {
210
- resolve(detail);
211
- }
212
- });
213
- }
214
126
  }
@@ -22,13 +22,11 @@
22
22
  */
23
23
 
24
24
  import * as frameTree from "./frame-tree/content/content-frame-tree.js";
25
- import * as hooks from "./hooks/content/content-hooks.js";
26
25
  import * as hooksFrames from "./hooks/content/content-hooks-frames.js";
27
26
  import * as lazy from "./lazy/content/content-lazy-loader.js";
28
27
 
29
28
  export {
30
29
  frameTree,
31
- hooks,
32
30
  hooksFrames,
33
31
  lazy
34
32
  };
@@ -1,39 +0,0 @@
1
- /*
2
- * Copyright 2010-2022 Gildas Lormeau
3
- * contact : gildas.lormeau <at> gmail.com
4
- *
5
- * This file is part of SingleFile.
6
- *
7
- * The code in this file is free software: you can redistribute it and/or
8
- * modify it under the terms of the GNU Affero General Public License
9
- * (GNU AGPL) as published by the Free Software Foundation, either version 3
10
- * of the License, or (at your option) any later version.
11
- *
12
- * The code in this file is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
15
- * General Public License for more details.
16
- *
17
- * As additional permission under GNU AGPL version 3 section 7, you may
18
- * distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
19
- * AGPL normally required by section 4, provided you include this license
20
- * notice and a URL through which recipients can access the Corresponding
21
- * Source.
22
- */
23
-
24
- /* global globalThis */
25
-
26
- const browser = globalThis.browser;
27
- const document = globalThis.document;
28
- const Document = globalThis.Document;
29
-
30
- if (document instanceof Document) {
31
- const scriptElement = document.createElement("script");
32
- scriptElement.async = false;
33
- if (browser && browser.runtime && browser.runtime.getURL) {
34
- scriptElement.src = browser.runtime.getURL("/lib/single-file-hooks.js");
35
- scriptElement.async = false;
36
- }
37
- (document.documentElement || document).appendChild(scriptElement);
38
- scriptElement.remove();
39
- }