single-file-core 1.1.76 → 1.1.78

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.
Files changed (37) hide show
  1. package/.eslintrc.js +0 -0
  2. package/LICENSE +0 -0
  3. package/core/constants.js +13 -0
  4. package/core/helper.js +604 -596
  5. package/core/index.js +2234 -2231
  6. package/core/infobar.js +276 -272
  7. package/core/util.js +408 -407
  8. package/modules/css-fonts-alt-minifier.js +342 -342
  9. package/modules/css-fonts-minifier.js +376 -376
  10. package/modules/css-matched-rules.js +0 -0
  11. package/modules/css-medias-alt-minifier.js +90 -90
  12. package/modules/css-rules-minifier.js +0 -0
  13. package/modules/html-images-alt-minifier.js +0 -0
  14. package/modules/html-minifier.js +0 -0
  15. package/modules/html-serializer.js +0 -0
  16. package/modules/index.js +0 -0
  17. package/modules/template-formatter.js +0 -0
  18. package/package.json +18 -18
  19. package/processors/frame-tree/content/content-frame-tree.js +426 -424
  20. package/processors/hooks/content/content-hooks-frames-web.js +0 -0
  21. package/processors/hooks/content/content-hooks-frames.js +0 -0
  22. package/processors/index.js +0 -0
  23. package/processors/lazy/content/content-lazy-loader.js +233 -233
  24. package/single-file-bootstrap.js +55 -55
  25. package/single-file-editor-helper.js +49 -49
  26. package/single-file-frames.js +0 -0
  27. package/single-file-hooks-frames.js +0 -0
  28. package/single-file-infobar.js +62 -62
  29. package/single-file.js +101 -101
  30. package/vendor/css-font-property-parser.js +0 -0
  31. package/vendor/css-media-query-parser.js +0 -0
  32. package/vendor/css-minifier.js +0 -0
  33. package/vendor/css-tree.js +0 -0
  34. package/vendor/css-unescape.js +0 -0
  35. package/vendor/html-srcset-parser.js +0 -0
  36. package/vendor/index.js +0 -0
  37. package/vendor/mime-type-parser.js +0 -0
package/core/infobar.js CHANGED
@@ -1,273 +1,277 @@
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 getComputedStyle, XPathResult, Node */
25
-
26
- const INFOBAR_TAGNAME = "single-file-infobar";
27
- const INFOBAR_STYLES = `
28
- .infobar,
29
- .infobar .infobar-icon,
30
- .infobar .infobar-link-icon {
31
- min-inline-size: 28px;
32
- min-block-size: 28px;
33
- box-sizing: border-box;
34
- }
35
-
36
- .infobar,
37
- .infobar .infobar-close-icon,
38
- .infobar .infobar-link-icon {
39
- opacity: 0.7;
40
- transition: opacity 250ms;
41
- }
42
-
43
- .infobar:hover,
44
- .infobar .infobar-close-icon:hover,
45
- .infobar .infobar-link-icon:hover {
46
- opacity: 1;
47
- }
48
-
49
- .infobar,
50
- .infobar-content {
51
- display: flex;
52
- }
53
-
54
- .infobar {
55
- position: fixed;
56
- top: 16px;
57
- right: 16px;
58
- margin-inline-start: 16px;
59
- margin-block-end: 16px;
60
- color: #2d2d2d;
61
- background-color: #737373;
62
- border: 2px solid;
63
- border-color: #eee;
64
- border-radius: 16px;
65
- z-index: 2147483647;
66
- }
67
-
68
- .infobar:valid, .infobar:not(:focus-within) .infobar-content {
69
- display: none;
70
- }
71
-
72
- .infobar:focus-within {
73
- background-color: #f9f9f9;
74
- border-color: #878787;
75
- border-radius: 8px;
76
- opacity: 1;
77
- transition-property: opacity, background-color, border-color, border-radius,
78
- color;
79
- }
80
-
81
- .infobar-content {
82
- align-items: center;
83
- }
84
-
85
- .infobar-content span {
86
- font-family: Arial, Helvetica, sans-serif;
87
- font-size: 14px;
88
- line-height: 18px;
89
- word-break: break-word;
90
- white-space: pre-wrap;
91
- margin-inline: 4px;
92
- margin-block: 4px;
93
- }
94
-
95
- .infobar .infobar-icon,
96
- .infobar .infobar-close-icon,
97
- .infobar .infobar-link-icon {
98
- cursor: pointer;
99
- background-position: center;
100
- background-repeat: no-repeat;
101
- }
102
-
103
- .infobar .infobar-close-icon,
104
- .infobar .infobar-link-icon {
105
- align-self: flex-start;
106
- }
107
-
108
- .infobar .infobar-icon {
109
- position: absolute;
110
- min-inline-size: 24px;
111
- min-block-size: 24px;
112
- }
113
-
114
- .infobar:focus-within .infobar-icon {
115
- z-index: -1;
116
- background-image: none;
117
- }
118
-
119
- .infobar .infobar-close-icon {
120
- min-inline-size: 22px;
121
- min-block-size: 22px;
122
- }
123
-
124
- .infobar .infobar-icon {
125
- background-color: transparent;
126
- background-size: 70%;
127
- background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw0AYht+mSkUrDnYQcchQnSyIijqWKhbBQmkrtOpgcukfNGlIUlwcBdeCgz+LVQcXZ10dXAVB8AfEydFJ0UVK/C4ptIjx4LiH9+59+e67A4RGhalm1wSgapaRisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHADIRLMaOHwAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAPUExURQAAAIqKioyNjY2OjvDw8L2y1DEAAAABdFJOUwBA5thmAAAAAWJLR0QB/wIt3gAAAGNJREFUSMdjYCAJsLi4OBCQx6/CBQwIGIDPCBcXAkYQUsACU+AwlBVQHg6Eg5pgZBGOboIJZugDFwRwoJECJCUOhJI1wZwzqmBUwagCuipgIqTABG9h7YIKaKGAURAFEF/6AQAO4HqSoDP8bgAAAABJRU5ErkJggg==);
128
- }
129
-
130
- .infobar .infobar-link-icon {
131
- background-size: 60%;
132
- background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw0AYht+mSkUrDnYQcchQnSyIijqWKhbBQmkrtOpgcukfNGlIUlwcBdeCgz+LVQcXZ10dXAVB8AfEydFJ0UVK/C4ptIjx4LiH9+59+e67A4RGhalm1wSgapaRisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHAB8H+DhhoQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAJUExURQAAAICHi4qKioTuJAkAAAABdFJOUwBA5thmAAAAAWJLR0QCZgt8ZAAAAJJJREFUOI3t070NRCEMA2CnYAOyDyPwpHj/Va7hJ3FzV7zy3ET5JIwoAF6Jk4wzAJAkzxAYG9YRTgB+24wBgKmfrGAKTcEfAY4KRlRoIeBTgKOCERVaCPgU4Khge2GqKOBTgKOCERVaAEC/4PNcnyoSWHpjqkhwKxbcig0Q6AorXYF/+A6eIYD1lVbwG/jdA6/kA2THRAURVubcAAAAAElFTkSuQmCC);
133
- }
134
-
135
- .infobar .infobar-close-icon {
136
- appearance: none;
137
- background-size: 80%;
138
- background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw0AYht+mSkUrDnYQcchQnSyIijqWKhbBQmkrtOpgcukfNGlIUlwcBdeCgz+LVQcXZ10dXAVB8AfEydFJ0UVK/C4ptIjx4LiH9+59+e67A4RGhalm1wSgapaRisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHAB8VC4EQ6QAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAJUExURQAAAICHi4qKioTuJAkAAAABdFJOUwBA5thmAAAAAWJLR0QCZgt8ZAAAAJtJREFUOI3NkrsBgCAMRLFwBPdxBArcfxXFkO8rbKWAAJfHJ9faf9vuYX/749T5NmShm3bEwbe2SxeuM4+2oxDL1cDoKtVUjRy+tH78Cv2CS+wIiQNC1AEhk4AQeUTMWUJMfUJMSEJMSEY8kIx4IONroaYAimNxsXp1PA7PxwfVL8QnowwoVC0lig07wDDVUjAdbAnjwtow/z/bDW7eI4M2KruJAAAAAElFTkSuQmCC);
139
- }
140
- `;
141
-
142
- export { displayIcon, appendInfobar, refreshInfobarInfo, extractInfobarData, INFOBAR_TAGNAME };
143
-
144
- function appendInfobar(doc, options, useShadowRoot) {
145
- if (!doc.querySelector(INFOBAR_TAGNAME)) {
146
- let infoData;
147
- if (options.infobarContent) {
148
- infoData = options.infobarContent.replace(/\\n/g, "\n").replace(/\\t/g, "\t");
149
- } else if (options.saveDate) {
150
- infoData = options.saveDate;
151
- }
152
- infoData = infoData || "No info";
153
- const infobarElement = createElement(doc, INFOBAR_TAGNAME, doc.body);
154
- let infobarContainer;
155
- if (useShadowRoot) {
156
- infobarContainer = infobarElement.attachShadow({ mode: "open" });
157
- } else {
158
- const shadowRootTemplate = doc.createElement("template");
159
- shadowRootTemplate.setAttribute("shadowroot", "open");
160
- infobarElement.appendChild(shadowRootTemplate);
161
- infobarContainer = shadowRootTemplate;
162
- }
163
- const shadowRootContent = doc.createElement("div");
164
- const styleElement = doc.createElement("style");
165
- styleElement.textContent = INFOBAR_STYLES
166
- .replace(/ {2}/g, "")
167
- .replace(/\n/g, "")
168
- .replace(/: /g, ":")
169
- .replace(/, /g, ",");
170
- shadowRootContent.appendChild(styleElement);
171
- const infobarContent = doc.createElement("form");
172
- infobarContent.classList.add("infobar");
173
- shadowRootContent.appendChild(infobarContent);
174
- const iconElement = doc.createElement("span");
175
- iconElement.tabIndex = -1;
176
- iconElement.classList.add("infobar-icon");
177
- infobarContent.appendChild(iconElement);
178
- const contentElement = doc.createElement("span");
179
- contentElement.tabIndex = -1;
180
- contentElement.classList.add("infobar-content");
181
- const closeButtonElement = doc.createElement("input");
182
- closeButtonElement.type = "checkbox";
183
- closeButtonElement.required = true;
184
- closeButtonElement.classList.add("infobar-close-icon");
185
- closeButtonElement.title = "Close";
186
- contentElement.appendChild(closeButtonElement);
187
- const textElement = doc.createElement("span");
188
- textElement.textContent = infoData;
189
- contentElement.appendChild(textElement);
190
- const linkElement = doc.createElement("a");
191
- linkElement.classList.add("infobar-link-icon");
192
- linkElement.target = "_blank";
193
- linkElement.rel = "noopener noreferrer";
194
- linkElement.title = "Open source URL: " + options.saveUrl;
195
- linkElement.href = options.saveUrl;
196
- contentElement.appendChild(linkElement);
197
- infobarContent.appendChild(contentElement);
198
- if (useShadowRoot) {
199
- infobarContainer.appendChild(shadowRootContent);
200
- } else {
201
- const scriptElement = doc.createElement("script");
202
- let scriptContent = refreshInfobarInfo.toString();
203
- scriptContent += extractInfobarData.toString();
204
- scriptContent += "(" + initInfobar.toString() + ")(document)";
205
- scriptElement.textContent = scriptContent;
206
- shadowRootContent.appendChild(scriptElement);
207
- infobarContainer.innerHTML = shadowRootContent.outerHTML;
208
- }
209
- doc.body.appendChild(infobarElement);
210
- }
211
- }
212
-
213
- function extractInfobarData(doc) {
214
- const result = doc.evaluate("//comment()", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
215
- let singleFileComment = result && result.singleNodeValue;
216
- if (singleFileComment && singleFileComment.nodeType == Node.COMMENT_NODE && singleFileComment.textContent.includes("SingleFile")) {
217
- const info = singleFileComment.textContent.split("\n");
218
- const [, , urlData, ...optionalData] = info;
219
- const urlMatch = urlData.match(/^ url: (.*) ?$/);
220
- const saveUrl = urlMatch && urlMatch[1];
221
- if (saveUrl) {
222
- let infobarContent, saveDate;
223
- if (optionalData.length) {
224
- saveDate = optionalData[0].split("saved date: ")[1];
225
- if (saveDate) {
226
- optionalData.shift();
227
- }
228
- if (optionalData.length > 1) {
229
- let content = optionalData[0].split("info: ")[1].trim();
230
- for (let indexLine = 1; indexLine < optionalData.length - 1; indexLine++) {
231
- content += "\n" + optionalData[indexLine].trim();
232
- }
233
- infobarContent = content.trim();
234
- }
235
- }
236
- return { saveUrl, infobarContent, saveDate };
237
- }
238
- }
239
- }
240
-
241
- function refreshInfobarInfo(doc, { saveUrl, infobarContent, saveDate }) {
242
- if (saveUrl) {
243
- const infobarElement = doc.querySelector("single-file-infobar");
244
- const shadowRootFragment = infobarElement.shadowRoot;
245
- const infobarContentElement = shadowRootFragment.querySelector(".infobar-content span");
246
- infobarContentElement.textContent = infobarContent || saveDate;
247
- const linkElement = shadowRootFragment.querySelector(".infobar-content .infobar-link-icon");
248
- linkElement.href = saveUrl;
249
- linkElement.title = "Open source URL: " + saveUrl;
250
- }
251
- }
252
-
253
- function displayIcon(doc, useShadowRoot) {
254
- const infoData = extractInfobarData(doc);
255
- if (infoData.saveUrl) {
256
- appendInfobar(doc, infoData, useShadowRoot);
257
- refreshInfobarInfo(doc, infoData);
258
- }
259
- }
260
-
261
- function initInfobar(doc) {
262
- const infoData = extractInfobarData(doc);
263
- if (infoData && infoData.saveUrl) {
264
- refreshInfobarInfo(doc, infoData);
265
- }
266
- }
267
-
268
- function createElement(doc, tagName, parentElement) {
269
- const element = doc.createElement(tagName);
270
- parentElement.appendChild(element);
271
- Array.from(getComputedStyle(element)).forEach(property => element.style.setProperty(property, "initial", "important"));
272
- return element;
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 getComputedStyle, XPathResult, Node */
25
+
26
+ import {
27
+ SINGLE_FILE_SIGNATURE,
28
+ } from "./constants.js";
29
+
30
+ const INFOBAR_TAGNAME = "single-file-infobar";
31
+ const INFOBAR_STYLES = `
32
+ .infobar,
33
+ .infobar .infobar-icon,
34
+ .infobar .infobar-link-icon {
35
+ min-inline-size: 28px;
36
+ min-block-size: 28px;
37
+ box-sizing: border-box;
38
+ }
39
+
40
+ .infobar,
41
+ .infobar .infobar-close-icon,
42
+ .infobar .infobar-link-icon {
43
+ opacity: 0.7;
44
+ transition: opacity 250ms;
45
+ }
46
+
47
+ .infobar:hover,
48
+ .infobar .infobar-close-icon:hover,
49
+ .infobar .infobar-link-icon:hover {
50
+ opacity: 1;
51
+ }
52
+
53
+ .infobar,
54
+ .infobar-content {
55
+ display: flex;
56
+ }
57
+
58
+ .infobar {
59
+ position: fixed;
60
+ top: 16px;
61
+ right: 16px;
62
+ margin-inline-start: 16px;
63
+ margin-block-end: 16px;
64
+ color: #2d2d2d;
65
+ background-color: #737373;
66
+ border: 2px solid;
67
+ border-color: #eee;
68
+ border-radius: 16px;
69
+ z-index: 2147483647;
70
+ }
71
+
72
+ .infobar:valid, .infobar:not(:focus-within) .infobar-content {
73
+ display: none;
74
+ }
75
+
76
+ .infobar:focus-within {
77
+ background-color: #f9f9f9;
78
+ border-color: #878787;
79
+ border-radius: 8px;
80
+ opacity: 1;
81
+ transition-property: opacity, background-color, border-color, border-radius,
82
+ color;
83
+ }
84
+
85
+ .infobar-content {
86
+ align-items: center;
87
+ }
88
+
89
+ .infobar-content span {
90
+ font-family: Arial, Helvetica, sans-serif;
91
+ font-size: 14px;
92
+ line-height: 18px;
93
+ word-break: break-word;
94
+ white-space: pre-wrap;
95
+ margin-inline: 4px;
96
+ margin-block: 4px;
97
+ }
98
+
99
+ .infobar .infobar-icon,
100
+ .infobar .infobar-close-icon,
101
+ .infobar .infobar-link-icon {
102
+ cursor: pointer;
103
+ background-position: center;
104
+ background-repeat: no-repeat;
105
+ }
106
+
107
+ .infobar .infobar-close-icon,
108
+ .infobar .infobar-link-icon {
109
+ align-self: flex-start;
110
+ }
111
+
112
+ .infobar .infobar-icon {
113
+ position: absolute;
114
+ min-inline-size: 24px;
115
+ min-block-size: 24px;
116
+ }
117
+
118
+ .infobar:focus-within .infobar-icon {
119
+ z-index: -1;
120
+ background-image: none;
121
+ }
122
+
123
+ .infobar .infobar-close-icon {
124
+ min-inline-size: 22px;
125
+ min-block-size: 22px;
126
+ }
127
+
128
+ .infobar .infobar-icon {
129
+ background-color: transparent;
130
+ background-size: 70%;
131
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw0AYht+mSkUrDnYQcchQnSyIijqWKhbBQmkrtOpgcukfNGlIUlwcBdeCgz+LVQcXZ10dXAVB8AfEydFJ0UVK/C4ptIjx4LiH9+59+e67A4RGhalm1wSgapaRisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHADIRLMaOHwAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAPUExURQAAAIqKioyNjY2OjvDw8L2y1DEAAAABdFJOUwBA5thmAAAAAWJLR0QB/wIt3gAAAGNJREFUSMdjYCAJsLi4OBCQx6/CBQwIGIDPCBcXAkYQUsACU+AwlBVQHg6Eg5pgZBGOboIJZugDFwRwoJECJCUOhJI1wZwzqmBUwagCuipgIqTABG9h7YIKaKGAURAFEF/6AQAO4HqSoDP8bgAAAABJRU5ErkJggg==);
132
+ }
133
+
134
+ .infobar .infobar-link-icon {
135
+ background-size: 60%;
136
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw0AYht+mSkUrDnYQcchQnSyIijqWKhbBQmkrtOpgcukfNGlIUlwcBdeCgz+LVQcXZ10dXAVB8AfEydFJ0UVK/C4ptIjx4LiH9+59+e67A4RGhalm1wSgapaRisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHAB8H+DhhoQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAJUExURQAAAICHi4qKioTuJAkAAAABdFJOUwBA5thmAAAAAWJLR0QCZgt8ZAAAAJJJREFUOI3t070NRCEMA2CnYAOyDyPwpHj/Va7hJ3FzV7zy3ET5JIwoAF6Jk4wzAJAkzxAYG9YRTgB+24wBgKmfrGAKTcEfAY4KRlRoIeBTgKOCERVaCPgU4Khge2GqKOBTgKOCERVaAEC/4PNcnyoSWHpjqkhwKxbcig0Q6AorXYF/+A6eIYD1lVbwG/jdA6/kA2THRAURVubcAAAAAElFTkSuQmCC);
137
+ }
138
+
139
+ .infobar .infobar-close-icon {
140
+ appearance: none;
141
+ background-size: 80%;
142
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kj1Iw0AYht+mSkUrDnYQcchQnSyIijqWKhbBQmkrtOpgcukfNGlIUlwcBdeCgz+LVQcXZ10dXAVB8AfEydFJ0UVK/C4ptIjx4LiH9+59+e67A4RGhalm1wSgapaRisfEbG5VDLyiDwEAvZiVmKkn0osZeI6ve/j4ehfhWd7n/hz9St5kgE8kjjLdsIg3iGc2LZ3zPnGIlSSF+Jx43KACiR+5Lrv8xrnosMAzQ0YmNU8cIhaLHSx3MCsZKvE0cVhRNcoXsi4rnLc4q5Uaa9XJbxjMaytprtMcQRxLSCAJETJqKKMCCxFaNVJMpGg/5uEfdvxJcsnkKoORYwFVqJAcP/gb/O6tWZiadJOCMaD7xbY/RoHALtCs2/b3sW03TwD/M3Cltf3VBjD3SXq9rYWPgIFt4OK6rcl7wOUOMPSkS4bkSH6aQqEAvJ/RM+WAwVv6EGtu31r7OH0AMtSr5Rvg4BAYK1L2use9ezr79u+ZVv9+AFlNcp0UUpiqAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5AsHAB8VC4EQ6QAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAAJUExURQAAAICHi4qKioTuJAkAAAABdFJOUwBA5thmAAAAAWJLR0QCZgt8ZAAAAJtJREFUOI3NkrsBgCAMRLFwBPdxBArcfxXFkO8rbKWAAJfHJ9faf9vuYX/749T5NmShm3bEwbe2SxeuM4+2oxDL1cDoKtVUjRy+tH78Cv2CS+wIiQNC1AEhk4AQeUTMWUJMfUJMSEJMSEY8kIx4IONroaYAimNxsXp1PA7PxwfVL8QnowwoVC0lig07wDDVUjAdbAnjwtow/z/bDW7eI4M2KruJAAAAAElFTkSuQmCC);
143
+ }
144
+ `;
145
+
146
+ export { displayIcon, appendInfobar, refreshInfobarInfo, extractInfobarData, INFOBAR_TAGNAME };
147
+
148
+ function appendInfobar(doc, options, useShadowRoot) {
149
+ if (!doc.querySelector(INFOBAR_TAGNAME)) {
150
+ let infoData;
151
+ if (options.infobarContent) {
152
+ infoData = options.infobarContent.replace(/\\n/g, "\n").replace(/\\t/g, "\t");
153
+ } else if (options.saveDate) {
154
+ infoData = options.saveDate;
155
+ }
156
+ infoData = infoData || "No info";
157
+ const infobarElement = createElement(doc, INFOBAR_TAGNAME, doc.body);
158
+ let infobarContainer;
159
+ if (useShadowRoot) {
160
+ infobarContainer = infobarElement.attachShadow({ mode: "open" });
161
+ } else {
162
+ const shadowRootTemplate = doc.createElement("template");
163
+ shadowRootTemplate.setAttribute("shadowroot", "open");
164
+ infobarElement.appendChild(shadowRootTemplate);
165
+ infobarContainer = shadowRootTemplate;
166
+ }
167
+ const shadowRootContent = doc.createElement("div");
168
+ const styleElement = doc.createElement("style");
169
+ styleElement.textContent = INFOBAR_STYLES
170
+ .replace(/ {2}/g, "")
171
+ .replace(/\n/g, "")
172
+ .replace(/: /g, ":")
173
+ .replace(/, /g, ",");
174
+ shadowRootContent.appendChild(styleElement);
175
+ const infobarContent = doc.createElement("form");
176
+ infobarContent.classList.add("infobar");
177
+ shadowRootContent.appendChild(infobarContent);
178
+ const iconElement = doc.createElement("span");
179
+ iconElement.tabIndex = -1;
180
+ iconElement.classList.add("infobar-icon");
181
+ infobarContent.appendChild(iconElement);
182
+ const contentElement = doc.createElement("span");
183
+ contentElement.tabIndex = -1;
184
+ contentElement.classList.add("infobar-content");
185
+ const closeButtonElement = doc.createElement("input");
186
+ closeButtonElement.type = "checkbox";
187
+ closeButtonElement.required = true;
188
+ closeButtonElement.classList.add("infobar-close-icon");
189
+ closeButtonElement.title = "Close";
190
+ contentElement.appendChild(closeButtonElement);
191
+ const textElement = doc.createElement("span");
192
+ textElement.textContent = infoData;
193
+ contentElement.appendChild(textElement);
194
+ const linkElement = doc.createElement("a");
195
+ linkElement.classList.add("infobar-link-icon");
196
+ linkElement.target = "_blank";
197
+ linkElement.rel = "noopener noreferrer";
198
+ linkElement.title = "Open source URL: " + options.saveUrl;
199
+ linkElement.href = options.saveUrl;
200
+ contentElement.appendChild(linkElement);
201
+ infobarContent.appendChild(contentElement);
202
+ if (useShadowRoot) {
203
+ infobarContainer.appendChild(shadowRootContent);
204
+ } else {
205
+ const scriptElement = doc.createElement("script");
206
+ let scriptContent = refreshInfobarInfo.toString();
207
+ scriptContent += extractInfobarData.toString();
208
+ scriptContent += "(" + initInfobar.toString() + ")(document)";
209
+ scriptElement.textContent = scriptContent;
210
+ shadowRootContent.appendChild(scriptElement);
211
+ infobarContainer.innerHTML = shadowRootContent.outerHTML;
212
+ }
213
+ doc.body.appendChild(infobarElement);
214
+ }
215
+ }
216
+
217
+ function extractInfobarData(doc) {
218
+ const result = doc.evaluate("//comment()", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
219
+ let singleFileComment = result && result.singleNodeValue;
220
+ if (singleFileComment && singleFileComment.nodeType == Node.COMMENT_NODE && singleFileComment.textContent.includes(SINGLE_FILE_SIGNATURE)) {
221
+ const info = singleFileComment.textContent.split("\n");
222
+ const [, , urlData, ...optionalData] = info;
223
+ const urlMatch = urlData.match(/^ url: (.*) ?$/);
224
+ const saveUrl = urlMatch && urlMatch[1];
225
+ if (saveUrl) {
226
+ let infobarContent, saveDate;
227
+ if (optionalData.length) {
228
+ saveDate = optionalData[0].split("saved date: ")[1];
229
+ if (saveDate) {
230
+ optionalData.shift();
231
+ }
232
+ if (optionalData.length > 1) {
233
+ let content = optionalData[0].split("info: ")[1].trim();
234
+ for (let indexLine = 1; indexLine < optionalData.length - 1; indexLine++) {
235
+ content += "\n" + optionalData[indexLine].trim();
236
+ }
237
+ infobarContent = content.trim();
238
+ }
239
+ }
240
+ return { saveUrl, infobarContent, saveDate };
241
+ }
242
+ }
243
+ }
244
+
245
+ function refreshInfobarInfo(doc, { saveUrl, infobarContent, saveDate }) {
246
+ if (saveUrl) {
247
+ const infobarElement = doc.querySelector("single-file-infobar");
248
+ const shadowRootFragment = infobarElement.shadowRoot;
249
+ const infobarContentElement = shadowRootFragment.querySelector(".infobar-content span");
250
+ infobarContentElement.textContent = infobarContent || saveDate;
251
+ const linkElement = shadowRootFragment.querySelector(".infobar-content .infobar-link-icon");
252
+ linkElement.href = saveUrl;
253
+ linkElement.title = "Open source URL: " + saveUrl;
254
+ }
255
+ }
256
+
257
+ function displayIcon(doc, useShadowRoot) {
258
+ const infoData = extractInfobarData(doc);
259
+ if (infoData.saveUrl) {
260
+ appendInfobar(doc, infoData, useShadowRoot);
261
+ refreshInfobarInfo(doc, infoData);
262
+ }
263
+ }
264
+
265
+ function initInfobar(doc) {
266
+ const infoData = extractInfobarData(doc);
267
+ if (infoData && infoData.saveUrl) {
268
+ refreshInfobarInfo(doc, infoData);
269
+ }
270
+ }
271
+
272
+ function createElement(doc, tagName, parentElement) {
273
+ const element = doc.createElement(tagName);
274
+ parentElement.appendChild(element);
275
+ Array.from(getComputedStyle(element)).forEach(property => element.style.setProperty(property, "initial", "important"));
276
+ return element;
273
277
  }