single-file-core 1.0.4 → 1.0.7
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/common/content-infobar-web.js +289 -0
- package/package.json +1 -1
- package/single-file-core.js +15 -0
- package/single-file-helper.js +6 -2
- package/single-file-util.js +1 -0
- package/single-file-frames.js +0 -24
|
@@ -0,0 +1,289 @@
|
|
|
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, window, document, Node, getComputedStyle, XPathResult */
|
|
25
|
+
|
|
26
|
+
(globalThis => {
|
|
27
|
+
|
|
28
|
+
const INFOBAR_TAGNAME = "singlefile-infobar";
|
|
29
|
+
const LINK_ICON = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw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RisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHADIRLMaOHwAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAPUExURQAAAIqKioyNjY2OjvDw8L2y1DEAAAABdFJOUwBA5thmAAAAAWJLR0QB/wIt3gAAAGNJREFUSMdjYCAJsLi4OBCQx6/CBQwIGIDPCBcXAkYQUsACU+AwlBVQHg6Eg5pgZBGOboIJZugDFwRwoJECJCUOhJI1wZwzqmBUwagCuipgIqTABG9h7YIKaKGAURAFEF/6AQAO4HqSoDP8bgAAAABJRU5ErkJggg==";
|
|
32
|
+
const SINGLEFILE_COMMENT = "SingleFile";
|
|
33
|
+
const SINGLE_FILE_UI_ELEMENT_CLASS = "single-file-ui-element";
|
|
34
|
+
const INFOBAR_STYLES = `
|
|
35
|
+
.infobar {
|
|
36
|
+
background-color: #737373;
|
|
37
|
+
color: white;
|
|
38
|
+
display: flex;
|
|
39
|
+
position: fixed;
|
|
40
|
+
top: 16px;
|
|
41
|
+
right: 16px;
|
|
42
|
+
height: auto;
|
|
43
|
+
width: auto;
|
|
44
|
+
min-height: 24px;
|
|
45
|
+
min-width: 24px;
|
|
46
|
+
background-position: center;
|
|
47
|
+
background-repeat: no-repeat;
|
|
48
|
+
z-index: 2147483647;
|
|
49
|
+
margin: 0 0 0 16px;
|
|
50
|
+
background-image: url(${IMAGE_ICON});
|
|
51
|
+
border-radius: 16px;
|
|
52
|
+
user-select: none;
|
|
53
|
+
-moz-user-select: none;
|
|
54
|
+
opacity: .7;
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
padding-left: 0;
|
|
57
|
+
padding-right: 0;
|
|
58
|
+
padding-top: 0;
|
|
59
|
+
padding-bottom: 0;
|
|
60
|
+
border: 2px solid #eee;
|
|
61
|
+
background-size: 70% 70%;
|
|
62
|
+
transition: all 250ms;
|
|
63
|
+
font-size: 13px;
|
|
64
|
+
}
|
|
65
|
+
.infobar:hover {
|
|
66
|
+
opacity: 1;
|
|
67
|
+
}
|
|
68
|
+
.infobar-open {
|
|
69
|
+
opacity: 1;
|
|
70
|
+
background-color: #f9f9f9;
|
|
71
|
+
cursor: auto;
|
|
72
|
+
color: #2d2d2d;
|
|
73
|
+
padding-top: 2px;
|
|
74
|
+
padding-bottom: 2px;
|
|
75
|
+
border: 2px solid #878787;
|
|
76
|
+
background-image: none;
|
|
77
|
+
border-radius: 8px;
|
|
78
|
+
user-select: initial;
|
|
79
|
+
-moz-user-select: initial;
|
|
80
|
+
}
|
|
81
|
+
.infobar-close-button {
|
|
82
|
+
display: none;
|
|
83
|
+
opacity: .7;
|
|
84
|
+
padding-top: 4px;
|
|
85
|
+
padding-left: 8px;
|
|
86
|
+
padding-right: 8px;
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
transition: opacity 250ms;
|
|
89
|
+
height: 16px;
|
|
90
|
+
}
|
|
91
|
+
.infobar-close-button:hover {
|
|
92
|
+
opacity: 1;
|
|
93
|
+
}
|
|
94
|
+
.infobar-content {
|
|
95
|
+
display: none;
|
|
96
|
+
font-family: Arial;
|
|
97
|
+
font-size: 14px;
|
|
98
|
+
line-height: 22px;
|
|
99
|
+
word-break: break-word;
|
|
100
|
+
white-space: pre-wrap;
|
|
101
|
+
position: relative;
|
|
102
|
+
top: 1px;
|
|
103
|
+
text-align: left;
|
|
104
|
+
}
|
|
105
|
+
.infobar-link {
|
|
106
|
+
display: none;
|
|
107
|
+
padding-left: 8px;
|
|
108
|
+
padding-right: 8px;
|
|
109
|
+
line-height: 11px;
|
|
110
|
+
cursor: pointer;
|
|
111
|
+
user-select: none;
|
|
112
|
+
outline: 0;
|
|
113
|
+
}
|
|
114
|
+
.infobar-link-icon {
|
|
115
|
+
padding-top: 4px;
|
|
116
|
+
padding-left: 2px;
|
|
117
|
+
cursor: pointer;
|
|
118
|
+
opacity: .7;
|
|
119
|
+
transition: opacity 250ms;
|
|
120
|
+
height: 16px;
|
|
121
|
+
}
|
|
122
|
+
.infobar-link-icon:hover {
|
|
123
|
+
opacity: 1;
|
|
124
|
+
}
|
|
125
|
+
.infobar-open .infobar-close-button, .infobar-open .infobar-content, .infobar-open .infobar-link {
|
|
126
|
+
display: inline-block;
|
|
127
|
+
}`;
|
|
128
|
+
let SHADOW_DOM_SUPPORTED = true;
|
|
129
|
+
|
|
130
|
+
const browser = globalThis.browser;
|
|
131
|
+
|
|
132
|
+
if (globalThis.window == globalThis.top) {
|
|
133
|
+
if (document.readyState == "loading") {
|
|
134
|
+
document.addEventListener("DOMContentLoaded", displayIcon, false);
|
|
135
|
+
} else {
|
|
136
|
+
displayIcon();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function displayIcon() {
|
|
141
|
+
const result = document.evaluate("//comment()", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
|
142
|
+
let singleFileComment = result && result.singleNodeValue;
|
|
143
|
+
if (singleFileComment && isSingleFileComment(singleFileComment)) {
|
|
144
|
+
const info = singleFileComment.textContent.split("\n");
|
|
145
|
+
const [, , url, saveDate, ...infoData] = info;
|
|
146
|
+
if (url && saveDate) {
|
|
147
|
+
let options;
|
|
148
|
+
if (browser && browser.runtime && browser.runtime.sendMessage) {
|
|
149
|
+
options = await browser.runtime.sendMessage({ method: "tabs.getOptions", url });
|
|
150
|
+
} else {
|
|
151
|
+
options = { displayInfobar: true };
|
|
152
|
+
}
|
|
153
|
+
if (options.displayInfobar) {
|
|
154
|
+
await initInfobar(url, saveDate, infoData);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function isSingleFileComment(node) {
|
|
161
|
+
return node.nodeType == Node.COMMENT_NODE && node.textContent.includes(SINGLEFILE_COMMENT);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function initInfobar(url, saveDate, infoData) {
|
|
165
|
+
let infobarElement = document.querySelector(INFOBAR_TAGNAME);
|
|
166
|
+
if (!infobarElement) {
|
|
167
|
+
url = url.split("url: ")[1];
|
|
168
|
+
saveDate = saveDate.split("saved date: ")[1];
|
|
169
|
+
if (infoData && infoData.length > 1) {
|
|
170
|
+
let content = infoData[0].split("info: ")[1].trim();
|
|
171
|
+
for (let indexLine = 1; indexLine < infoData.length - 1; indexLine++) {
|
|
172
|
+
content += "\n" + infoData[indexLine].trim();
|
|
173
|
+
}
|
|
174
|
+
infoData = content.trim();
|
|
175
|
+
} else {
|
|
176
|
+
infoData = saveDate;
|
|
177
|
+
}
|
|
178
|
+
infobarElement = createElement(INFOBAR_TAGNAME, document.body);
|
|
179
|
+
infobarElement.className = SINGLE_FILE_UI_ELEMENT_CLASS;
|
|
180
|
+
const shadowRoot = await getShadowRoot(infobarElement);
|
|
181
|
+
const styleElement = document.createElement("style");
|
|
182
|
+
styleElement.textContent = INFOBAR_STYLES;
|
|
183
|
+
shadowRoot.appendChild(styleElement);
|
|
184
|
+
const infobarContent = document.createElement("div");
|
|
185
|
+
infobarContent.classList.add("infobar");
|
|
186
|
+
shadowRoot.appendChild(infobarContent);
|
|
187
|
+
const closeElement = document.createElement("img");
|
|
188
|
+
closeElement.classList.add("infobar-close-button");
|
|
189
|
+
infobarContent.appendChild(closeElement);
|
|
190
|
+
closeElement.src = CLOSE_ICON;
|
|
191
|
+
closeElement.onclick = event => {
|
|
192
|
+
if (event.button === 0) {
|
|
193
|
+
infobarElement.remove();
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
const infoElement = document.createElement("span");
|
|
197
|
+
infobarContent.appendChild(infoElement);
|
|
198
|
+
infoElement.classList.add("infobar-content");
|
|
199
|
+
infoElement.textContent = infoData;
|
|
200
|
+
const linkElement = document.createElement("a");
|
|
201
|
+
linkElement.classList.add("infobar-link");
|
|
202
|
+
infobarContent.appendChild(linkElement);
|
|
203
|
+
linkElement.target = "_blank";
|
|
204
|
+
linkElement.rel = "noopener noreferrer";
|
|
205
|
+
linkElement.title = "Open source URL: " + url;
|
|
206
|
+
linkElement.href = url;
|
|
207
|
+
const imgElement = document.createElement("img");
|
|
208
|
+
imgElement.classList.add("infobar-link-icon");
|
|
209
|
+
linkElement.appendChild(imgElement);
|
|
210
|
+
imgElement.src = LINK_ICON;
|
|
211
|
+
hideInfobar(infobarContent);
|
|
212
|
+
|
|
213
|
+
document.addEventListener("click", event => {
|
|
214
|
+
if (event.button === 0) {
|
|
215
|
+
let element = event.target;
|
|
216
|
+
while (element && element != infobarElement) {
|
|
217
|
+
element = element.parentElement;
|
|
218
|
+
}
|
|
219
|
+
if (element != infobarElement) {
|
|
220
|
+
hideInfobar(infobarContent);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function displayInfobar(infobarContent) {
|
|
228
|
+
if (!SHADOW_DOM_SUPPORTED) {
|
|
229
|
+
const infobarElement = document.querySelector(INFOBAR_TAGNAME);
|
|
230
|
+
const frameElement = infobarElement.childNodes[0];
|
|
231
|
+
frameElement.contentWindow.getSelection().removeAllRanges();
|
|
232
|
+
}
|
|
233
|
+
infobarContent.classList.add("infobar-open");
|
|
234
|
+
infobarContent.onclick = null;
|
|
235
|
+
infobarContent.onmouseout = null;
|
|
236
|
+
if (!SHADOW_DOM_SUPPORTED) {
|
|
237
|
+
const infobarElement = document.querySelector(INFOBAR_TAGNAME);
|
|
238
|
+
const frameElement = infobarElement.childNodes[0];
|
|
239
|
+
frameElement.style.setProperty("width", "100vw", "important");
|
|
240
|
+
frameElement.style.setProperty("height", "100vh", "important");
|
|
241
|
+
frameElement.style.setProperty("width", (infobarContent.getBoundingClientRect().width + 33) + "px", "important");
|
|
242
|
+
frameElement.style.setProperty("height", (infobarContent.getBoundingClientRect().height + 21) + "px", "important");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function hideInfobar(infobarContent) {
|
|
247
|
+
infobarContent.classList.remove("infobar-open");
|
|
248
|
+
infobarContent.onclick = event => {
|
|
249
|
+
if (event.button === 0) {
|
|
250
|
+
displayInfobar(infobarContent);
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
if (!SHADOW_DOM_SUPPORTED) {
|
|
255
|
+
const infobarElement = document.querySelector(INFOBAR_TAGNAME);
|
|
256
|
+
const frameElement = infobarElement.childNodes[0];
|
|
257
|
+
frameElement.style.setProperty("width", "44px", "important");
|
|
258
|
+
frameElement.style.setProperty("height", "48px", "important");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function createElement(tagName, parentElement) {
|
|
263
|
+
const element = document.createElement(tagName);
|
|
264
|
+
parentElement.appendChild(element);
|
|
265
|
+
Array.from(getComputedStyle(element)).forEach(property => element.style.setProperty(property, "initial", "important"));
|
|
266
|
+
return element;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async function getShadowRoot(element) {
|
|
270
|
+
if (element.attachShadow) {
|
|
271
|
+
return element.attachShadow({ mode: "open" });
|
|
272
|
+
} else {
|
|
273
|
+
SHADOW_DOM_SUPPORTED = false;
|
|
274
|
+
const iframe = createElement("iframe", element);
|
|
275
|
+
iframe.style.setProperty("background-color", "transparent", "important");
|
|
276
|
+
iframe.style.setProperty("position", "fixed", "important");
|
|
277
|
+
iframe.style.setProperty("top", 0, "important");
|
|
278
|
+
iframe.style.setProperty("right", 0, "important");
|
|
279
|
+
iframe.style.setProperty("width", "44px", "important");
|
|
280
|
+
iframe.style.setProperty("height", "48px", "important");
|
|
281
|
+
iframe.style.setProperty("z-index", 2147483647, "important");
|
|
282
|
+
return new Promise(resolve => {
|
|
283
|
+
iframe.contentDocument.body.style.setProperty("margin", 0);
|
|
284
|
+
iframe.onload = () => resolve(iframe.contentDocument.body);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
})(typeof globalThis == "object" ? globalThis : window);
|
package/package.json
CHANGED
package/single-file-core.js
CHANGED
|
@@ -95,6 +95,7 @@ const STAGES = [{
|
|
|
95
95
|
{ action: "preProcessPage" },
|
|
96
96
|
{ option: "loadDeferredImagesKeepZoomLevel", action: "resetZoomLevel" },
|
|
97
97
|
{ action: "replaceStyleContents" },
|
|
98
|
+
{ action: "replaceInvalidElements" },
|
|
98
99
|
{ action: "resetCharsetMeta" },
|
|
99
100
|
{ option: "saveFavicon", action: "saveFavicon" },
|
|
100
101
|
{ action: "replaceCanvasElements" },
|
|
@@ -795,6 +796,20 @@ class Processor {
|
|
|
795
796
|
this.doc.querySelectorAll("a[ping]").forEach(element => element.removeAttribute("ping"));
|
|
796
797
|
}
|
|
797
798
|
|
|
799
|
+
replaceInvalidElements() {
|
|
800
|
+
this.doc.querySelectorAll("template[" + util.INVALID_ELEMENT_ATTRIBUTE_NAME + "]").forEach(templateElement => {
|
|
801
|
+
const placeHolderElement = this.doc.createElement("span");
|
|
802
|
+
const originalElement = templateElement.content.firstChild;
|
|
803
|
+
if (originalElement) {
|
|
804
|
+
if (originalElement.hasAttributes()) {
|
|
805
|
+
Array.from(originalElement.attributes).forEach(attribute => placeHolderElement.setAttribute(attribute.name, attribute.value));
|
|
806
|
+
}
|
|
807
|
+
originalElement.childNodes.forEach(childNode => placeHolderElement.appendChild(childNode.cloneNode(true)));
|
|
808
|
+
}
|
|
809
|
+
templateElement.replaceWith(placeHolderElement);
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
|
|
798
813
|
resetCharsetMeta() {
|
|
799
814
|
let charset;
|
|
800
815
|
this.doc.querySelectorAll("meta[charset], meta[http-equiv=\"content-type\"]").forEach(element => {
|
package/single-file-helper.js
CHANGED
|
@@ -46,6 +46,7 @@ const LAZY_SRC_ATTRIBUTE_NAME = "data-single-file-lazy-loaded-src";
|
|
|
46
46
|
const STYLESHEET_ATTRIBUTE_NAME = "data-single-file-stylesheet";
|
|
47
47
|
const DISABLED_NOSCRIPT_ATTRIBUTE_NAME = "data-single-file-disabled-noscript";
|
|
48
48
|
const SELECTED_CONTENT_ATTRIBUTE_NAME = "data-single-file-selected-content";
|
|
49
|
+
const INVALID_ELEMENT_ATTRIBUTE_NAME = "data-single-file-invalid-element";
|
|
49
50
|
const ASYNC_SCRIPT_ATTRIBUTE_NAME = "data-single-file-async-script";
|
|
50
51
|
const FLOW_ELEMENTS_SELECTOR = "*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)";
|
|
51
52
|
const KEPT_TAG_NAMES = ["NOSCRIPT", "DISABLED-NOSCRIPT", "META", "LINK", "STYLE", "TITLE", "TEMPLATE", "SOURCE", "OBJECT", "SCRIPT", "HEAD"];
|
|
@@ -94,6 +95,7 @@ export {
|
|
|
94
95
|
LAZY_SRC_ATTRIBUTE_NAME,
|
|
95
96
|
STYLESHEET_ATTRIBUTE_NAME,
|
|
96
97
|
SELECTED_CONTENT_ATTRIBUTE_NAME,
|
|
98
|
+
INVALID_ELEMENT_ATTRIBUTE_NAME,
|
|
97
99
|
ASYNC_SCRIPT_ATTRIBUTE_NAME,
|
|
98
100
|
COMMENT_HEADER,
|
|
99
101
|
COMMENT_HEADER_LEGACY,
|
|
@@ -138,8 +140,10 @@ function preProcessDoc(doc, win, options) {
|
|
|
138
140
|
const invalidElements = new Map();
|
|
139
141
|
let elementsInfo;
|
|
140
142
|
if (win && doc.documentElement) {
|
|
141
|
-
doc.querySelectorAll("button button").forEach(element => {
|
|
142
|
-
const placeHolderElement = doc.
|
|
143
|
+
doc.querySelectorAll("button button, a a, p div").forEach(element => {
|
|
144
|
+
const placeHolderElement = doc.createElement("template");
|
|
145
|
+
placeHolderElement.setAttribute(INVALID_ELEMENT_ATTRIBUTE_NAME, "");
|
|
146
|
+
placeHolderElement.content.appendChild(element.cloneNode(true));
|
|
143
147
|
invalidElements.set(element, placeHolderElement);
|
|
144
148
|
element.replaceWith(placeHolderElement);
|
|
145
149
|
});
|
package/single-file-util.js
CHANGED
|
@@ -186,6 +186,7 @@ function getInstance(utilOptions) {
|
|
|
186
186
|
PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME: helper.PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME,
|
|
187
187
|
STYLESHEET_ATTRIBUTE_NAME: helper.STYLESHEET_ATTRIBUTE_NAME,
|
|
188
188
|
SELECTED_CONTENT_ATTRIBUTE_NAME: helper.SELECTED_CONTENT_ATTRIBUTE_NAME,
|
|
189
|
+
INVALID_ELEMENT_ATTRIBUTE_NAME: helper.INVALID_ELEMENT_ATTRIBUTE_NAME,
|
|
189
190
|
COMMENT_HEADER: helper.COMMENT_HEADER,
|
|
190
191
|
COMMENT_HEADER_LEGACY: helper.COMMENT_HEADER_LEGACY,
|
|
191
192
|
SINGLE_FILE_UI_ELEMENT_CLASS: helper.SINGLE_FILE_UI_ELEMENT_CLASS,
|
package/single-file-frames.js
DELETED
|
@@ -1,24 +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
|
-
import "./processors/frame-tree/content/content-frame-tree.js";
|