single-file-core 1.11.0 → 1.13.0
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/constants.js +3 -1
- package/core/helper.js +2 -2
- package/core/index.js +12 -0
- package/core/lib/processor-helper-common.js +101 -51
- package/core/notes.js +943 -0
- package/modules/css-selector-sanitizer.js +1 -1
- package/modules/template-formatter.js +5 -0
- package/package.json +1 -1
- package/processors/hooks/content/content-hooks-frames-web.js +19 -0
- package/processors/lazy/content/content-lazy-loader.js +30 -0
- package/single-file-editor-helper.js +2 -0
- package/single-file-notes.js +43 -0
|
@@ -99,7 +99,7 @@ function normalizeSelectorNode(selector) {
|
|
|
99
99
|
} else if (childNode.type === "PseudoClassSelector") {
|
|
100
100
|
if (matchUnqueryablePseudoClass(childNode)) {
|
|
101
101
|
removeNode(selector.children, current);
|
|
102
|
-
} else if (childNode.children && MATCHING_FUNCTIONAL_PSEUDO_CLASSES.includes(childNode.name.toLowerCase())) {
|
|
102
|
+
} else if (childNode.children && childNode.children.head && MATCHING_FUNCTIONAL_PSEUDO_CLASSES.includes(childNode.name.toLowerCase())) {
|
|
103
103
|
normalizeSelectorNode(childNode.children.head.data);
|
|
104
104
|
}
|
|
105
105
|
} else if (childNode.type === "AttributeSelector") {
|
|
@@ -17024,6 +17024,11 @@ async function evalTemplate(template = "", options, content, doc, context = {})
|
|
|
17024
17024
|
"if-not-equals": (value, otherValue, trueValue, falseValue) => value != otherValue ? trueValue : falseValue,
|
|
17025
17025
|
"if-contains": (value, otherValue, trueValue, falseValue) => otherValue && value.includes(otherValue) ? trueValue : falseValue,
|
|
17026
17026
|
"if-not-contains": (value, otherValue, trueValue, falseValue) => otherValue && !value.includes(otherValue) ? trueValue : falseValue,
|
|
17027
|
+
"switch": (value, ...cases) => {
|
|
17028
|
+
const defaultValue = cases.length % 2 ? cases.pop() : undefined;
|
|
17029
|
+
const index = cases.findIndex((caseValue, caseIndex) => caseIndex % 2 == 0 && caseValue == value);
|
|
17030
|
+
return index == -1 ? defaultValue : cases[index + 1];
|
|
17031
|
+
},
|
|
17027
17032
|
"substring": (value, start, end) => value.substring(start, end),
|
|
17028
17033
|
"lowercase": value => value.toLowerCase(),
|
|
17029
17034
|
"uppercase": value => value.toUpperCase(),
|
package/package.json
CHANGED
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
const MutationObserver = globalThis.MutationObserver;
|
|
93
93
|
const URL = globalThis.URL;
|
|
94
94
|
const CSSStyleSheet = globalThis.CSSStyleSheet;
|
|
95
|
+
const DOMRect = globalThis.DOMRect;
|
|
95
96
|
|
|
96
97
|
const observers = new Map();
|
|
97
98
|
const observedElements = new Map();
|
|
@@ -188,6 +189,10 @@
|
|
|
188
189
|
document.documentElement.style.removeProperty("-sf-transform");
|
|
189
190
|
document.documentElement.style.removeProperty("-sf-transform-origin");
|
|
190
191
|
document.documentElement.style.removeProperty("-sf-min-height");
|
|
192
|
+
if (globalThis._singleFile_getBoundingClientRect) {
|
|
193
|
+
Element.prototype.getBoundingClientRect = globalThis._singleFile_getBoundingClientRect;
|
|
194
|
+
delete globalThis._singleFile_getBoundingClientRect;
|
|
195
|
+
}
|
|
191
196
|
resetScreenSize();
|
|
192
197
|
}
|
|
193
198
|
|
|
@@ -351,6 +356,20 @@
|
|
|
351
356
|
document.documentElement.style.setProperty("transform-origin", horizontalOrigin + " 0 0", "important");
|
|
352
357
|
document.documentElement.style.setProperty("transform", translation + "scale3d(" + zoomFactor + ", " + zoomFactor + ", 1)", "important");
|
|
353
358
|
document.documentElement.style.setProperty("min-height", (100 / zoomFactor) + "vh", "important");
|
|
359
|
+
if (keepZoomLevel && !globalThis._singleFile_getBoundingClientRect) {
|
|
360
|
+
const originX = horizontalOrigin == "0" ? 0 : document.documentElement.offsetWidth / 2;
|
|
361
|
+
const translationX = horizontalOrigin == "0" ? scrollPosition.x : 0;
|
|
362
|
+
const translationY = scrollPosition.y;
|
|
363
|
+
globalThis._singleFile_getBoundingClientRect = Element.prototype.getBoundingClientRect;
|
|
364
|
+
Element.prototype.getBoundingClientRect = function () {
|
|
365
|
+
const boundingRect = globalThis._singleFile_getBoundingClientRect.call(this);
|
|
366
|
+
const x = originX + (boundingRect.x + globalThis.scrollX - originX - translationX) / zoomFactor - globalThis.scrollX;
|
|
367
|
+
const y = (boundingRect.y + globalThis.scrollY - translationY) / zoomFactor - globalThis.scrollY;
|
|
368
|
+
return new DOMRect(x, y, boundingRect.width / zoomFactor, boundingRect.height / zoomFactor);
|
|
369
|
+
};
|
|
370
|
+
Element.prototype.getBoundingClientRect.toString = function () { return "function getBoundingClientRect() { [native code] }"; };
|
|
371
|
+
setFunctionName(Element.prototype.getBoundingClientRect, "getBoundingClientRect");
|
|
372
|
+
}
|
|
354
373
|
dispatchResizeEvent();
|
|
355
374
|
if (keepZoomLevel || keepEmulatedScreenSize) {
|
|
356
375
|
document.documentElement.style.setProperty("-sf-transform", transform, transformPriority);
|
|
@@ -35,6 +35,8 @@ const MAX_IDLE_TIMEOUT_CALLS = 10;
|
|
|
35
35
|
const ATTRIBUTES_MUTATION_TYPE = "attributes";
|
|
36
36
|
const CHILD_LIST_MUTATION_TYPE = "childList";
|
|
37
37
|
const STYLESHEET_TAG_NAMES = ["STYLE", "LINK"];
|
|
38
|
+
const SCROLLABLE_OVERFLOW_VALUES = ["auto", "scroll", "overlay"];
|
|
39
|
+
const SCROLLABLE_ELEMENT_MIN_SIZE_RATIO = 1 / 3;
|
|
38
40
|
|
|
39
41
|
const browser = globalThis.browser;
|
|
40
42
|
const document = globalThis.document;
|
|
@@ -76,10 +78,38 @@ async function process(options) {
|
|
|
76
78
|
if (globalThis.scrollY < maxScrollY || globalThis.scrollX < maxScrollX) {
|
|
77
79
|
return triggerLazyLoading(options);
|
|
78
80
|
}
|
|
81
|
+
} else if (findScrollableElement()) {
|
|
82
|
+
return triggerLazyLoading(options);
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
|
|
87
|
+
function findScrollableElement() {
|
|
88
|
+
const minHeight = globalThis.innerHeight * SCROLLABLE_ELEMENT_MIN_SIZE_RATIO;
|
|
89
|
+
const minWidth = globalThis.innerWidth * SCROLLABLE_ELEMENT_MIN_SIZE_RATIO;
|
|
90
|
+
let elements = [document.documentElement];
|
|
91
|
+
while (elements.length) {
|
|
92
|
+
const descendants = [];
|
|
93
|
+
for (const element of elements) {
|
|
94
|
+
for (const child of element.children) {
|
|
95
|
+
if (child.clientHeight >= minHeight && child.clientWidth >= minWidth) {
|
|
96
|
+
if (isScrollable(child)) {
|
|
97
|
+
return child;
|
|
98
|
+
}
|
|
99
|
+
descendants.push(child);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
elements = descendants;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isScrollable(element) {
|
|
108
|
+
const style = globalThis.getComputedStyle(element);
|
|
109
|
+
return (SCROLLABLE_OVERFLOW_VALUES.includes(style.overflowY) && element.scrollHeight > element.clientHeight) ||
|
|
110
|
+
(SCROLLABLE_OVERFLOW_VALUES.includes(style.overflowX) && element.scrollWidth > element.clientWidth);
|
|
111
|
+
}
|
|
112
|
+
|
|
83
113
|
function resetZoomLevel(options) {
|
|
84
114
|
hooksFrames.loadDeferredContentResetZoomLevel(options);
|
|
85
115
|
}
|
|
@@ -28,6 +28,7 @@ import { getInstance } from "./core/util.js";
|
|
|
28
28
|
import * as zip from "./vendor/zip/zip.js";
|
|
29
29
|
import { extract } from "./processors/compression/compression-extract.js";
|
|
30
30
|
import { display } from "./processors/compression/compression-display.js";
|
|
31
|
+
import * as notes from "./core/notes.js";
|
|
31
32
|
|
|
32
33
|
const util = getInstance();
|
|
33
34
|
const helper = {
|
|
@@ -56,6 +57,7 @@ const helper = {
|
|
|
56
57
|
extract,
|
|
57
58
|
display,
|
|
58
59
|
formatFilename,
|
|
60
|
+
notes,
|
|
59
61
|
INFOBAR_TAGNAME: infobar.INFOBAR_TAGNAME,
|
|
60
62
|
NESTING_TRACK_ID_ATTRIBUTE_NAME: util.NESTING_TRACK_ID_ATTRIBUTE_NAME
|
|
61
63
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2010-2025 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 document */
|
|
25
|
+
|
|
26
|
+
import { init, restoreShadowRoots, repairNesting, NOTE_TAGNAME } from "./core/notes.js";
|
|
27
|
+
|
|
28
|
+
(() => {
|
|
29
|
+
|
|
30
|
+
if (document.currentScript) {
|
|
31
|
+
document.currentScript.remove();
|
|
32
|
+
}
|
|
33
|
+
const notes = init(document);
|
|
34
|
+
globalThis.onresize = notes.reflowNotes;
|
|
35
|
+
document.documentElement.onmouseup = document.documentElement.ontouchend = notes.onMouseUp;
|
|
36
|
+
restoreShadowRoots(document);
|
|
37
|
+
notes.reflowNotes();
|
|
38
|
+
document.querySelectorAll(NOTE_TAGNAME).forEach(containerElement => notes.attachNoteListeners(containerElement));
|
|
39
|
+
notes.waitResourcesLoad().then(notes.reflowNotes);
|
|
40
|
+
notes.watchNotesLayout();
|
|
41
|
+
repairNesting(document);
|
|
42
|
+
|
|
43
|
+
})();
|