@d-i-t-a/reader 2.0.0-beta.13 → 2.0.0-beta.16
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 +92 -72
- 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 +37 -37
- package/dist/reader.js.map +2 -2
- package/dist/reader.map.css +1 -1
- package/dist/types/modules/TTS/TTSModule2.d.ts +1 -1
- package/dist/types/modules/linefocus/LineFocusModule.d.ts +3 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -46855,7 +46855,7 @@ var ReflowableBookView = class {
|
|
|
46855
46855
|
const wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
46856
46856
|
if (this.scrollMode) {
|
|
46857
46857
|
const leftHeight = wrapper.scrollTop;
|
|
46858
|
-
const height = this.getScreenHeight();
|
|
46858
|
+
const height = this.getScreenHeight() - 40;
|
|
46859
46859
|
const offset = leftHeight - height;
|
|
46860
46860
|
if (offset >= 0) {
|
|
46861
46861
|
wrapper.scrollTop = offset;
|
|
@@ -46881,7 +46881,7 @@ var ReflowableBookView = class {
|
|
|
46881
46881
|
const wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
46882
46882
|
if (this.scrollMode) {
|
|
46883
46883
|
const leftHeight = wrapper.scrollTop;
|
|
46884
|
-
const height = this.getScreenHeight();
|
|
46884
|
+
const height = this.getScreenHeight() - 40;
|
|
46885
46885
|
const scrollHeight = this.scrollingElement.scrollHeight;
|
|
46886
46886
|
const offset = leftHeight + height;
|
|
46887
46887
|
if (offset < scrollHeight) {
|
|
@@ -52800,6 +52800,7 @@ var MediaOverlayModule = class {
|
|
|
52800
52800
|
const timeToSeekTo = this.currentAudioBegin ? this.currentAudioBegin : 0;
|
|
52801
52801
|
this.audioElement.currentTime = timeToSeekTo;
|
|
52802
52802
|
await this.audioElement.play();
|
|
52803
|
+
this.ensureOnTimeUpdate(false, true);
|
|
52803
52804
|
this.audioElement.volume = this.settings.volume;
|
|
52804
52805
|
this.audioElement.playbackRate = this.settings.rate;
|
|
52805
52806
|
} else {
|
|
@@ -53124,7 +53125,7 @@ var MediaOverlayModule = class {
|
|
|
53124
53125
|
setTimeout(async () => {
|
|
53125
53126
|
await self2.audioElement.play();
|
|
53126
53127
|
self2.ensureOnTimeUpdate(false, true);
|
|
53127
|
-
}, self2.settings.wait *
|
|
53128
|
+
}, self2.settings.wait * 1e3);
|
|
53128
53129
|
}
|
|
53129
53130
|
};
|
|
53130
53131
|
let self2 = this;
|
|
@@ -53151,7 +53152,7 @@ var MediaOverlayModule = class {
|
|
|
53151
53152
|
setTimeout(async () => {
|
|
53152
53153
|
await self2.audioElement.play();
|
|
53153
53154
|
self2.ensureOnTimeUpdate(false, true);
|
|
53154
|
-
}, self2.settings.wait *
|
|
53155
|
+
}, self2.settings.wait * 1e3);
|
|
53155
53156
|
}
|
|
53156
53157
|
};
|
|
53157
53158
|
let self2 = this;
|
|
@@ -58748,10 +58749,12 @@ var TTSModule2 = class {
|
|
|
58748
58749
|
}
|
|
58749
58750
|
});
|
|
58750
58751
|
}
|
|
58751
|
-
cancel() {
|
|
58752
|
-
if (
|
|
58753
|
-
this.api?.stopped
|
|
58754
|
-
|
|
58752
|
+
cancel(api = true) {
|
|
58753
|
+
if (api) {
|
|
58754
|
+
if (this.api?.stopped)
|
|
58755
|
+
this.api?.stopped();
|
|
58756
|
+
this.delegate.emit("readaloud.stopped", "stopped");
|
|
58757
|
+
}
|
|
58755
58758
|
this.userScrolled = false;
|
|
58756
58759
|
this.speaking = false;
|
|
58757
58760
|
setTimeout(() => {
|
|
@@ -58768,7 +58771,7 @@ var TTSModule2 = class {
|
|
|
58768
58771
|
this.delegate.emit("readaloud.started", "started");
|
|
58769
58772
|
const self2 = this;
|
|
58770
58773
|
this.userScrolled = false;
|
|
58771
|
-
this.cancel();
|
|
58774
|
+
this.cancel(false);
|
|
58772
58775
|
let utterance;
|
|
58773
58776
|
if (partial) {
|
|
58774
58777
|
let iframe = document.querySelector("main#iframe-wrapper iframe");
|
|
@@ -58908,7 +58911,9 @@ var TTSModule2 = class {
|
|
|
58908
58911
|
callback();
|
|
58909
58912
|
}
|
|
58910
58913
|
speakPlay() {
|
|
58911
|
-
this.cancel();
|
|
58914
|
+
this.cancel(false);
|
|
58915
|
+
if (this.api?.started)
|
|
58916
|
+
this.api?.started();
|
|
58912
58917
|
this.delegate.emit("readaloud.started", "started");
|
|
58913
58918
|
let self2 = this;
|
|
58914
58919
|
let iframe = document.querySelector("main#iframe-wrapper iframe");
|
|
@@ -58918,47 +58923,27 @@ var TTSModule2 = class {
|
|
|
58918
58923
|
let node = self2.highlighter.visibleTextRects[0];
|
|
58919
58924
|
let doc = self2.delegate.iframes[0].contentDocument;
|
|
58920
58925
|
if (doc) {
|
|
58921
|
-
let isOutsideViewport = function(rect) {
|
|
58922
|
-
const windowLeft = window.scrollX;
|
|
58923
|
-
const windowRight = windowLeft + window.innerWidth;
|
|
58924
|
-
const right = rect.left + rect.width;
|
|
58925
|
-
const bottom = rect.top + rect.height;
|
|
58926
|
-
const windowTop = window.scrollY;
|
|
58927
|
-
const windowBottom = windowTop + window.innerHeight;
|
|
58928
|
-
const isAbove = bottom < windowTop;
|
|
58929
|
-
const isBelow = rect.top > windowBottom;
|
|
58930
|
-
const isLeft = right < windowLeft;
|
|
58931
|
-
const isRight = rect.left > windowRight;
|
|
58932
|
-
return isAbove || isBelow || isLeft || isRight;
|
|
58933
|
-
};
|
|
58934
58926
|
const range = self2.highlighter.dom(doc.body).getWindow().document.createRange();
|
|
58935
58927
|
const selection = self2.highlighter.dom(self2.delegate.iframes[0].contentDocument?.body).getSelection();
|
|
58936
58928
|
selection.removeAllRanges();
|
|
58937
58929
|
range.selectNodeContents(node.node);
|
|
58938
58930
|
selection.addRange(range);
|
|
58939
|
-
const clientRects = getClientRectsNoOverlap(range, false);
|
|
58940
58931
|
let index2 = 0;
|
|
58941
|
-
|
|
58942
|
-
|
|
58943
|
-
|
|
58944
|
-
|
|
58945
|
-
|
|
58946
|
-
|
|
58947
|
-
|
|
58948
|
-
|
|
58949
|
-
|
|
58950
|
-
|
|
58951
|
-
|
|
58952
|
-
|
|
58953
|
-
if (idx >= 0) {
|
|
58954
|
-
ttsQueueIndex = idx;
|
|
58955
|
-
}
|
|
58956
|
-
}
|
|
58957
|
-
selection.removeAllRanges();
|
|
58958
|
-
break;
|
|
58932
|
+
const endNode = selection.focusNode;
|
|
58933
|
+
const endOffset = selection.focusOffset;
|
|
58934
|
+
selection.collapse(selection.anchorNode, selection.anchorOffset);
|
|
58935
|
+
for (let i = 0; i < index2; i++) {
|
|
58936
|
+
selection.modify("move", "forward", "line");
|
|
58937
|
+
}
|
|
58938
|
+
selection.extend(endNode, endOffset);
|
|
58939
|
+
selection.collapse(selection.anchorNode, selection.anchorOffset);
|
|
58940
|
+
if (rootEl) {
|
|
58941
|
+
const idx = self2.findTtsQueueItemIndex(ttsQueue, selection.anchorNode, selection.focusNode, selection.focusOffset, rootEl);
|
|
58942
|
+
if (idx >= 0) {
|
|
58943
|
+
ttsQueueIndex = idx;
|
|
58959
58944
|
}
|
|
58960
|
-
index2++;
|
|
58961
58945
|
}
|
|
58946
|
+
selection.removeAllRanges();
|
|
58962
58947
|
}
|
|
58963
58948
|
};
|
|
58964
58949
|
const ttsQueue = this.generateTtsQueue(rootEl, true);
|
|
@@ -58972,7 +58957,7 @@ var TTSModule2 = class {
|
|
|
58972
58957
|
}
|
|
58973
58958
|
setTimeout(() => {
|
|
58974
58959
|
this.startTTSSession(ttsQueue, ttsQueueIndex);
|
|
58975
|
-
},
|
|
58960
|
+
}, 200);
|
|
58976
58961
|
}
|
|
58977
58962
|
}
|
|
58978
58963
|
speakPause() {
|
|
@@ -59660,7 +59645,7 @@ var DefinitionsModule = class {
|
|
|
59660
59645
|
}
|
|
59661
59646
|
});
|
|
59662
59647
|
}, { threshold: 1 });
|
|
59663
|
-
if (highlightFragments) {
|
|
59648
|
+
if (highlightFragments && highlightFragments.length > 0) {
|
|
59664
59649
|
observer.observe(highlightFragments[0]);
|
|
59665
59650
|
}
|
|
59666
59651
|
});
|
|
@@ -59727,6 +59712,7 @@ var LineFocusModule = class {
|
|
|
59727
59712
|
this.isActive = false;
|
|
59728
59713
|
this.isDebug = false;
|
|
59729
59714
|
this.lineFocusContainer = document.getElementById(`lineFocusContainer`);
|
|
59715
|
+
this.readerContainer = document.getElementById(`D2Reader-Container`);
|
|
59730
59716
|
this.lineFocusTopBlinder = document.getElementById(`lineFocusTopBlinder`);
|
|
59731
59717
|
this.lineFocusBottomBlinder = document.getElementById(`lineFocusBottomBlinder`);
|
|
59732
59718
|
this.wrapperHeight = void 0;
|
|
@@ -59747,6 +59733,18 @@ var LineFocusModule = class {
|
|
|
59747
59733
|
}
|
|
59748
59734
|
async start() {
|
|
59749
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 && this.lineFocusContainer.style.height.length == 0)
|
|
59740
|
+
this.lineFocusContainer.style.height = this.wrapperHeight;
|
|
59741
|
+
if (this.readerContainer && this.readerContainer.style.height.length == 0) {
|
|
59742
|
+
this.readerContainer.style.height = this.wrapperHeight;
|
|
59743
|
+
}
|
|
59744
|
+
if (this.readerContainer) {
|
|
59745
|
+
this.readerContainer.style.overflow = "hidden";
|
|
59746
|
+
}
|
|
59747
|
+
}
|
|
59750
59748
|
}
|
|
59751
59749
|
handleResize() {
|
|
59752
59750
|
if (this.isActive) {
|
|
@@ -59754,14 +59752,6 @@ var LineFocusModule = class {
|
|
|
59754
59752
|
}
|
|
59755
59753
|
}
|
|
59756
59754
|
async enableLineFocus() {
|
|
59757
|
-
if (!this.isActive) {
|
|
59758
|
-
const wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
59759
|
-
wrapper.style.overflow = "hidden";
|
|
59760
|
-
if (wrapper.style.height.length > 0) {
|
|
59761
|
-
this.wrapperHeight = wrapper.style.height;
|
|
59762
|
-
}
|
|
59763
|
-
wrapper.style.height = "100vh";
|
|
59764
|
-
}
|
|
59765
59755
|
this.isActive = true;
|
|
59766
59756
|
await this.delegate.settings.scroll(true);
|
|
59767
59757
|
this.lineFocus();
|
|
@@ -59769,12 +59759,18 @@ var LineFocusModule = class {
|
|
|
59769
59759
|
disableLineFocus(resetHeight = true) {
|
|
59770
59760
|
this.isActive = false;
|
|
59771
59761
|
const wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
59772
|
-
wrapper.style.overflow = "auto";
|
|
59773
59762
|
if (this.wrapperHeight) {
|
|
59774
59763
|
wrapper.style.height = this.wrapperHeight;
|
|
59775
59764
|
} else if (resetHeight) {
|
|
59765
|
+
this.index = 0;
|
|
59776
59766
|
wrapper.style.removeProperty("height");
|
|
59777
59767
|
}
|
|
59768
|
+
if (!resetHeight) {
|
|
59769
|
+
this.index = 0;
|
|
59770
|
+
}
|
|
59771
|
+
const doc = this.delegate.iframes[0].contentDocument;
|
|
59772
|
+
const html = findIframeElement(doc, "html");
|
|
59773
|
+
html.style.removeProperty("--USER__maxMediaHeight");
|
|
59778
59774
|
this.wrapperHeight = void 0;
|
|
59779
59775
|
if (this.lineFocusContainer)
|
|
59780
59776
|
this.lineFocusContainer.style.display = "none";
|
|
@@ -59794,6 +59790,10 @@ var LineFocusModule = class {
|
|
|
59794
59790
|
}
|
|
59795
59791
|
lineFocus() {
|
|
59796
59792
|
const wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
59793
|
+
const doc = this.delegate.iframes[0].contentDocument;
|
|
59794
|
+
const html = findIframeElement(doc, "html");
|
|
59795
|
+
let maxHeight = this.properties.maxHeight ? getHeight() * this.properties.maxHeight / 100 : getHeight() / 2;
|
|
59796
|
+
html.style.setProperty("--USER__maxMediaHeight", maxHeight + "px");
|
|
59797
59797
|
function insertAfter(referenceNode, newNode) {
|
|
59798
59798
|
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
|
|
59799
59799
|
}
|
|
@@ -59825,8 +59825,6 @@ var LineFocusModule = class {
|
|
|
59825
59825
|
insertAfter(wrapper, divAfter2);
|
|
59826
59826
|
}
|
|
59827
59827
|
this.lines = [];
|
|
59828
|
-
const self2 = this;
|
|
59829
|
-
const doc = self2.delegate.iframes[0].contentDocument;
|
|
59830
59828
|
if (doc) {
|
|
59831
59829
|
let random_rgba = function() {
|
|
59832
59830
|
const o = Math.round, r = Math.random, s = 255;
|
|
@@ -59989,10 +59987,8 @@ var LineFocusModule = class {
|
|
|
59989
59987
|
}
|
|
59990
59988
|
currentLine() {
|
|
59991
59989
|
let current = this.lines[this.index];
|
|
59992
|
-
let
|
|
59993
|
-
let
|
|
59994
|
-
let top = previous.style.top;
|
|
59995
|
-
let bottom = parseInt(next.style.top.replace("px", "")) + parseInt(next.style.height.replace("px", ""));
|
|
59990
|
+
let top = current.style.top;
|
|
59991
|
+
let bottom = parseInt(current.style.top.replace("px", "")) + parseInt(current.style.height.replace("px", ""));
|
|
59996
59992
|
let height = bottom - parseInt(top.replace("px", ""));
|
|
59997
59993
|
if (this.lineFocusContainer) {
|
|
59998
59994
|
let lineFocusHeight = parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px", ""));
|
|
@@ -60015,10 +60011,8 @@ var LineFocusModule = class {
|
|
|
60015
60011
|
this.index = this.lines.length - 1;
|
|
60016
60012
|
}
|
|
60017
60013
|
let current = this.lines[this.index];
|
|
60018
|
-
let
|
|
60019
|
-
let
|
|
60020
|
-
let top = previous.style.top;
|
|
60021
|
-
let bottom = parseInt(next.style.top.replace("px", "")) + parseInt(next.style.height.replace("px", ""));
|
|
60014
|
+
let top = current.style.top;
|
|
60015
|
+
let bottom = parseInt(current.style.top.replace("px", "")) + parseInt(current.style.height.replace("px", ""));
|
|
60022
60016
|
let height = bottom - parseInt(top.replace("px", ""));
|
|
60023
60017
|
if (this.lineFocusContainer) {
|
|
60024
60018
|
let lineFocusHeight = parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px", ""));
|
|
@@ -60042,10 +60036,8 @@ var LineFocusModule = class {
|
|
|
60042
60036
|
this.index = 0;
|
|
60043
60037
|
}
|
|
60044
60038
|
let current = this.lines[this.index];
|
|
60045
|
-
let
|
|
60046
|
-
let
|
|
60047
|
-
let top = previous.style.top;
|
|
60048
|
-
let bottom = parseInt(next.style.top.replace("px", "")) + parseInt(next.style.height.replace("px", ""));
|
|
60039
|
+
let top = current.style.top;
|
|
60040
|
+
let bottom = parseInt(current.style.top.replace("px", "")) + parseInt(current.style.height.replace("px", ""));
|
|
60049
60041
|
let height = bottom - parseInt(top.replace("px", ""));
|
|
60050
60042
|
if (this.lineFocusContainer) {
|
|
60051
60043
|
let lineFocusHeight = parseInt(getComputedStyle(this.lineFocusContainer).height.replace("px", ""));
|
|
@@ -60067,10 +60059,14 @@ var LineFocusModule = class {
|
|
|
60067
60059
|
}
|
|
60068
60060
|
findRects(parent) {
|
|
60069
60061
|
const textNodes = this.findTextNodes(parent);
|
|
60062
|
+
const imageNodes = Array.from(parent.getElementsByTagName("img"));
|
|
60070
60063
|
let newNodes = [];
|
|
60071
60064
|
textNodes.forEach((node) => {
|
|
60072
60065
|
newNodes.push(...this.measureTextNodes(node));
|
|
60073
60066
|
});
|
|
60067
|
+
imageNodes.forEach((node) => {
|
|
60068
|
+
newNodes.push(...this.measureImageNodes(node));
|
|
60069
|
+
});
|
|
60074
60070
|
return newNodes;
|
|
60075
60071
|
}
|
|
60076
60072
|
findTextNodes(parentElement, nodes = []) {
|
|
@@ -60103,6 +60099,21 @@ var LineFocusModule = class {
|
|
|
60103
60099
|
}
|
|
60104
60100
|
}
|
|
60105
60101
|
}
|
|
60102
|
+
measureImageNodes(node) {
|
|
60103
|
+
try {
|
|
60104
|
+
const range = document.createRange();
|
|
60105
|
+
range.selectNode(node);
|
|
60106
|
+
const rect = Array.from(range.getClientRects());
|
|
60107
|
+
range.detach();
|
|
60108
|
+
return rect;
|
|
60109
|
+
} catch (error) {
|
|
60110
|
+
if (IS_DEV) {
|
|
60111
|
+
console.log("measureTextNode " + error);
|
|
60112
|
+
console.log("measureTextNode " + node);
|
|
60113
|
+
console.log(node.textContent);
|
|
60114
|
+
}
|
|
60115
|
+
}
|
|
60116
|
+
}
|
|
60106
60117
|
};
|
|
60107
60118
|
|
|
60108
60119
|
// src/reader.ts
|
|
@@ -60532,14 +60543,23 @@ var D2Reader = class {
|
|
|
60532
60543
|
}
|
|
60533
60544
|
async applyLineFocusSettings(userSettings) {
|
|
60534
60545
|
if (userSettings.lines) {
|
|
60535
|
-
if (this.lineFocusModule)
|
|
60546
|
+
if (this.lineFocusModule) {
|
|
60547
|
+
const lines = this.lineFocusModule.properties.lines ?? 1;
|
|
60548
|
+
this.lineFocusModule.index = this.lineFocusModule.index * lines / parseInt(userSettings.lines);
|
|
60549
|
+
this.lineFocusModule.index = Math.abs(parseInt(this.lineFocusModule.index.toFixed()));
|
|
60536
60550
|
this.lineFocusModule.properties.lines = parseInt(userSettings.lines);
|
|
60537
|
-
|
|
60551
|
+
if (this.lineFocusModule.isActive) {
|
|
60552
|
+
await this.lineFocusModule.enableLineFocus();
|
|
60553
|
+
}
|
|
60554
|
+
}
|
|
60538
60555
|
}
|
|
60539
60556
|
if (userSettings.debug !== void 0) {
|
|
60540
|
-
if (this.lineFocusModule)
|
|
60557
|
+
if (this.lineFocusModule) {
|
|
60541
60558
|
this.lineFocusModule.isDebug = userSettings.debug;
|
|
60542
|
-
|
|
60559
|
+
if (this.lineFocusModule.isActive) {
|
|
60560
|
+
await this.lineFocusModule.enableLineFocus();
|
|
60561
|
+
}
|
|
60562
|
+
}
|
|
60543
60563
|
}
|
|
60544
60564
|
}
|
|
60545
60565
|
lineUp() {
|