@d-i-t-a/reader 2.0.0-beta.14 → 2.0.0-beta.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/dist/esm/index.js +56 -20
- package/dist/esm/index.js.map +2 -2
- package/dist/injectables/style/linefocus.css +1 -1
- package/dist/injectables/style/style.css +6 -0
- package/dist/reader.css +2 -2
- package/dist/reader.js +36 -36
- package/dist/reader.js.map +2 -2
- package/dist/reader.map.css +1 -1
- package/dist/types/modules/linefocus/LineFocusModule.d.ts +3 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -59712,6 +59712,7 @@ var LineFocusModule = class {
|
|
|
59712
59712
|
this.isActive = false;
|
|
59713
59713
|
this.isDebug = false;
|
|
59714
59714
|
this.lineFocusContainer = document.getElementById(`lineFocusContainer`);
|
|
59715
|
+
this.readerContainer = document.getElementById(`D2Reader-Container`);
|
|
59715
59716
|
this.lineFocusTopBlinder = document.getElementById(`lineFocusTopBlinder`);
|
|
59716
59717
|
this.lineFocusBottomBlinder = document.getElementById(`lineFocusBottomBlinder`);
|
|
59717
59718
|
this.wrapperHeight = void 0;
|
|
@@ -59732,6 +59733,16 @@ var LineFocusModule = class {
|
|
|
59732
59733
|
}
|
|
59733
59734
|
async start() {
|
|
59734
59735
|
this.delegate.lineFocusModule = this;
|
|
59736
|
+
const wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
59737
|
+
if (wrapper.style.height.length > 0) {
|
|
59738
|
+
this.wrapperHeight = wrapper.style.height;
|
|
59739
|
+
if (this.lineFocusContainer)
|
|
59740
|
+
this.lineFocusContainer.style.height = this.wrapperHeight;
|
|
59741
|
+
if (this.readerContainer) {
|
|
59742
|
+
this.readerContainer.style.height = this.wrapperHeight;
|
|
59743
|
+
this.readerContainer.style.overflow = "hidden";
|
|
59744
|
+
}
|
|
59745
|
+
}
|
|
59735
59746
|
}
|
|
59736
59747
|
handleResize() {
|
|
59737
59748
|
if (this.isActive) {
|
|
@@ -59741,7 +59752,6 @@ var LineFocusModule = class {
|
|
|
59741
59752
|
async enableLineFocus() {
|
|
59742
59753
|
if (!this.isActive) {
|
|
59743
59754
|
const wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
59744
|
-
wrapper.style.overflow = "hidden";
|
|
59745
59755
|
if (wrapper.style.height.length > 0) {
|
|
59746
59756
|
this.wrapperHeight = wrapper.style.height;
|
|
59747
59757
|
}
|
|
@@ -59754,12 +59764,14 @@ var LineFocusModule = class {
|
|
|
59754
59764
|
disableLineFocus(resetHeight = true) {
|
|
59755
59765
|
this.isActive = false;
|
|
59756
59766
|
const wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
59757
|
-
wrapper.style.overflow = "auto";
|
|
59758
59767
|
if (this.wrapperHeight) {
|
|
59759
59768
|
wrapper.style.height = this.wrapperHeight;
|
|
59760
59769
|
} else if (resetHeight) {
|
|
59761
59770
|
wrapper.style.removeProperty("height");
|
|
59762
59771
|
}
|
|
59772
|
+
const doc = this.delegate.iframes[0].contentDocument;
|
|
59773
|
+
const html = findIframeElement(doc, "html");
|
|
59774
|
+
html.style.removeProperty("--USER__maxMediaHeight");
|
|
59763
59775
|
this.wrapperHeight = void 0;
|
|
59764
59776
|
if (this.lineFocusContainer)
|
|
59765
59777
|
this.lineFocusContainer.style.display = "none";
|
|
@@ -59779,6 +59791,10 @@ var LineFocusModule = class {
|
|
|
59779
59791
|
}
|
|
59780
59792
|
lineFocus() {
|
|
59781
59793
|
const wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
59794
|
+
const doc = this.delegate.iframes[0].contentDocument;
|
|
59795
|
+
const html = findIframeElement(doc, "html");
|
|
59796
|
+
let maxHeight = this.properties.maxHeight ? getHeight() * this.properties.maxHeight / 100 : getHeight() / 2;
|
|
59797
|
+
html.style.setProperty("--USER__maxMediaHeight", maxHeight + "px");
|
|
59782
59798
|
function insertAfter(referenceNode, newNode) {
|
|
59783
59799
|
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
|
|
59784
59800
|
}
|
|
@@ -59810,8 +59826,6 @@ var LineFocusModule = class {
|
|
|
59810
59826
|
insertAfter(wrapper, divAfter2);
|
|
59811
59827
|
}
|
|
59812
59828
|
this.lines = [];
|
|
59813
|
-
const self2 = this;
|
|
59814
|
-
const doc = self2.delegate.iframes[0].contentDocument;
|
|
59815
59829
|
if (doc) {
|
|
59816
59830
|
let random_rgba = function() {
|
|
59817
59831
|
const o = Math.round, r = Math.random, s = 255;
|
|
@@ -59974,10 +59988,8 @@ var LineFocusModule = class {
|
|
|
59974
59988
|
}
|
|
59975
59989
|
currentLine() {
|
|
59976
59990
|
let current = this.lines[this.index];
|
|
59977
|
-
let
|
|
59978
|
-
let
|
|
59979
|
-
let top = previous.style.top;
|
|
59980
|
-
let bottom = parseInt(next.style.top.replace("px", "")) + parseInt(next.style.height.replace("px", ""));
|
|
59991
|
+
let top = current.style.top;
|
|
59992
|
+
let bottom = parseInt(current.style.top.replace("px", "")) + parseInt(current.style.height.replace("px", ""));
|
|
59981
59993
|
let height = bottom - parseInt(top.replace("px", ""));
|
|
59982
59994
|
if (this.lineFocusContainer) {
|
|
59983
59995
|
let lineFocusHeight = parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px", ""));
|
|
@@ -60000,10 +60012,8 @@ var LineFocusModule = class {
|
|
|
60000
60012
|
this.index = this.lines.length - 1;
|
|
60001
60013
|
}
|
|
60002
60014
|
let current = this.lines[this.index];
|
|
60003
|
-
let
|
|
60004
|
-
let
|
|
60005
|
-
let top = previous.style.top;
|
|
60006
|
-
let bottom = parseInt(next.style.top.replace("px", "")) + parseInt(next.style.height.replace("px", ""));
|
|
60015
|
+
let top = current.style.top;
|
|
60016
|
+
let bottom = parseInt(current.style.top.replace("px", "")) + parseInt(current.style.height.replace("px", ""));
|
|
60007
60017
|
let height = bottom - parseInt(top.replace("px", ""));
|
|
60008
60018
|
if (this.lineFocusContainer) {
|
|
60009
60019
|
let lineFocusHeight = parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px", ""));
|
|
@@ -60027,10 +60037,8 @@ var LineFocusModule = class {
|
|
|
60027
60037
|
this.index = 0;
|
|
60028
60038
|
}
|
|
60029
60039
|
let current = this.lines[this.index];
|
|
60030
|
-
let
|
|
60031
|
-
let
|
|
60032
|
-
let top = previous.style.top;
|
|
60033
|
-
let bottom = parseInt(next.style.top.replace("px", "")) + parseInt(next.style.height.replace("px", ""));
|
|
60040
|
+
let top = current.style.top;
|
|
60041
|
+
let bottom = parseInt(current.style.top.replace("px", "")) + parseInt(current.style.height.replace("px", ""));
|
|
60034
60042
|
let height = bottom - parseInt(top.replace("px", ""));
|
|
60035
60043
|
if (this.lineFocusContainer) {
|
|
60036
60044
|
let lineFocusHeight = parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px", ""));
|
|
@@ -60052,10 +60060,14 @@ var LineFocusModule = class {
|
|
|
60052
60060
|
}
|
|
60053
60061
|
findRects(parent) {
|
|
60054
60062
|
const textNodes = this.findTextNodes(parent);
|
|
60063
|
+
const imageNodes = Array.from(parent.getElementsByTagName("img"));
|
|
60055
60064
|
let newNodes = [];
|
|
60056
60065
|
textNodes.forEach((node) => {
|
|
60057
60066
|
newNodes.push(...this.measureTextNodes(node));
|
|
60058
60067
|
});
|
|
60068
|
+
imageNodes.forEach((node) => {
|
|
60069
|
+
newNodes.push(...this.measureImageNodes(node));
|
|
60070
|
+
});
|
|
60059
60071
|
return newNodes;
|
|
60060
60072
|
}
|
|
60061
60073
|
findTextNodes(parentElement, nodes = []) {
|
|
@@ -60088,6 +60100,21 @@ var LineFocusModule = class {
|
|
|
60088
60100
|
}
|
|
60089
60101
|
}
|
|
60090
60102
|
}
|
|
60103
|
+
measureImageNodes(node) {
|
|
60104
|
+
try {
|
|
60105
|
+
const range = document.createRange();
|
|
60106
|
+
range.selectNode(node);
|
|
60107
|
+
const rect = Array.from(range.getClientRects());
|
|
60108
|
+
range.detach();
|
|
60109
|
+
return rect;
|
|
60110
|
+
} catch (error) {
|
|
60111
|
+
if (IS_DEV) {
|
|
60112
|
+
console.log("measureTextNode " + error);
|
|
60113
|
+
console.log("measureTextNode " + node);
|
|
60114
|
+
console.log(node.textContent);
|
|
60115
|
+
}
|
|
60116
|
+
}
|
|
60117
|
+
}
|
|
60091
60118
|
};
|
|
60092
60119
|
|
|
60093
60120
|
// src/reader.ts
|
|
@@ -60517,14 +60544,23 @@ var D2Reader = class {
|
|
|
60517
60544
|
}
|
|
60518
60545
|
async applyLineFocusSettings(userSettings) {
|
|
60519
60546
|
if (userSettings.lines) {
|
|
60520
|
-
if (this.lineFocusModule)
|
|
60547
|
+
if (this.lineFocusModule) {
|
|
60548
|
+
const lines = this.lineFocusModule.properties.lines ?? 1;
|
|
60549
|
+
this.lineFocusModule.index = this.lineFocusModule.index * lines / parseInt(userSettings.lines);
|
|
60550
|
+
this.lineFocusModule.index = Math.abs(parseInt(this.lineFocusModule.index.toFixed()));
|
|
60521
60551
|
this.lineFocusModule.properties.lines = parseInt(userSettings.lines);
|
|
60522
|
-
|
|
60552
|
+
if (this.lineFocusModule.isActive) {
|
|
60553
|
+
await this.lineFocusModule.enableLineFocus();
|
|
60554
|
+
}
|
|
60555
|
+
}
|
|
60523
60556
|
}
|
|
60524
60557
|
if (userSettings.debug !== void 0) {
|
|
60525
|
-
if (this.lineFocusModule)
|
|
60558
|
+
if (this.lineFocusModule) {
|
|
60526
60559
|
this.lineFocusModule.isDebug = userSettings.debug;
|
|
60527
|
-
|
|
60560
|
+
if (this.lineFocusModule.isActive) {
|
|
60561
|
+
await this.lineFocusModule.enableLineFocus();
|
|
60562
|
+
}
|
|
60563
|
+
}
|
|
60528
60564
|
}
|
|
60529
60565
|
}
|
|
60530
60566
|
lineUp() {
|