@d-i-t-a/reader 2.0.5 → 2.0.6-beta.1
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
CHANGED
|
@@ -38571,13 +38571,16 @@ var TextHighlighter = class {
|
|
|
38571
38571
|
let selection = self2.dom(doc.body)?.getWindow()?.getSelection();
|
|
38572
38572
|
if (self2.dom(doc.body)) {
|
|
38573
38573
|
if (selection && !selection?.isCollapsed) {
|
|
38574
|
+
const text = selection.toString();
|
|
38575
|
+
const startOffsetTemp = text.length - text.trimStart().length;
|
|
38576
|
+
const endOffsetTemp = text.length - text.trimEnd().length;
|
|
38574
38577
|
let range = document.createRange();
|
|
38575
|
-
range.setStart(selection.anchorNode, selection.anchorOffset);
|
|
38576
|
-
range.setEnd(selection.focusNode, selection.focusOffset);
|
|
38578
|
+
range.setStart(selection.anchorNode, selection.anchorOffset + startOffsetTemp);
|
|
38579
|
+
range.setEnd(selection.focusNode, selection.focusOffset - endOffsetTemp);
|
|
38577
38580
|
let backwards = range.collapsed;
|
|
38578
38581
|
range.detach();
|
|
38579
|
-
let endNode = selection.focusNode, endOffset = selection.focusOffset;
|
|
38580
|
-
selection.collapse(selection.anchorNode, selection.anchorOffset);
|
|
38582
|
+
let endNode = selection.focusNode, endOffset = selection.focusOffset - endOffsetTemp;
|
|
38583
|
+
selection.collapse(selection.anchorNode, selection.anchorOffset + startOffsetTemp);
|
|
38581
38584
|
let direction = ["forward", "backward"];
|
|
38582
38585
|
if (backwards) {
|
|
38583
38586
|
direction = ["backward", "forward"];
|
|
@@ -38885,59 +38888,6 @@ var TextHighlighter = class {
|
|
|
38885
38888
|
this.doneSpeaking();
|
|
38886
38889
|
}
|
|
38887
38890
|
}
|
|
38888
|
-
speakAll() {
|
|
38889
|
-
if (this.delegate.rights.enableTTS) {
|
|
38890
|
-
let getCssSelector = function(element) {
|
|
38891
|
-
const options = {
|
|
38892
|
-
className: (str) => {
|
|
38893
|
-
return _blacklistIdClassForCssSelectors.indexOf(str) < 0;
|
|
38894
|
-
},
|
|
38895
|
-
idName: (str) => {
|
|
38896
|
-
return _blacklistIdClassForCssSelectors.indexOf(str) < 0;
|
|
38897
|
-
}
|
|
38898
|
-
};
|
|
38899
|
-
let doc2 = self2.delegate.iframes[0].contentDocument;
|
|
38900
|
-
if (doc2) {
|
|
38901
|
-
return uniqueCssSelector(element, self2.dom(doc2.body).getDocument(), options);
|
|
38902
|
-
} else {
|
|
38903
|
-
return void 0;
|
|
38904
|
-
}
|
|
38905
|
-
};
|
|
38906
|
-
let self2 = this;
|
|
38907
|
-
let doc = this.delegate.iframes[0].contentDocument;
|
|
38908
|
-
if (doc) {
|
|
38909
|
-
const selectionInfo = getCurrentSelectionInfo(this.dom(doc.body).getWindow(), getCssSelector);
|
|
38910
|
-
if (selectionInfo !== void 0) {
|
|
38911
|
-
self2.speak();
|
|
38912
|
-
} else {
|
|
38913
|
-
var node = this.dom(self2.delegate.iframes[0].contentDocument?.body).getWindow().document.body;
|
|
38914
|
-
if (IS_DEV)
|
|
38915
|
-
console.log(doc);
|
|
38916
|
-
const selection = self2.dom(doc.body).getSelection();
|
|
38917
|
-
const range = this.dom(doc.body).getWindow().document.createRange();
|
|
38918
|
-
range.selectNodeContents(node);
|
|
38919
|
-
selection.removeAllRanges();
|
|
38920
|
-
selection.addRange(range);
|
|
38921
|
-
let win = this.delegate.iframes[0].contentWindow;
|
|
38922
|
-
if (win) {
|
|
38923
|
-
const selectionInfo2 = getCurrentSelectionInfo(win, getCssSelector);
|
|
38924
|
-
if (selectionInfo2 !== void 0 && selectionInfo2.cleanText) {
|
|
38925
|
-
this.delegate.ttsModule.speak(selectionInfo2, false, () => {
|
|
38926
|
-
if (doc) {
|
|
38927
|
-
let selection2 = self2.dom(doc.body).getSelection();
|
|
38928
|
-
selection2.removeAllRanges();
|
|
38929
|
-
}
|
|
38930
|
-
self2.toolboxHide();
|
|
38931
|
-
});
|
|
38932
|
-
} else {
|
|
38933
|
-
self2.dom(doc.body).getSelection().removeAllRanges();
|
|
38934
|
-
self2.toolboxHide();
|
|
38935
|
-
}
|
|
38936
|
-
}
|
|
38937
|
-
}
|
|
38938
|
-
}
|
|
38939
|
-
}
|
|
38940
|
-
}
|
|
38941
38891
|
callbackComplete() {
|
|
38942
38892
|
this.toolboxHide();
|
|
38943
38893
|
let doc = this.delegate.iframes[0].contentDocument;
|
|
@@ -38948,7 +38898,7 @@ var TextHighlighter = class {
|
|
|
38948
38898
|
isOutsideViewport(rect) {
|
|
38949
38899
|
let wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
38950
38900
|
const windowLeft = wrapper.scrollLeft;
|
|
38951
|
-
const windowRight = windowLeft + wrapper.
|
|
38901
|
+
const windowRight = windowLeft + wrapper.clientWidth;
|
|
38952
38902
|
const right = rect.left + rect.width;
|
|
38953
38903
|
const bottom = rect.top + rect.height;
|
|
38954
38904
|
const windowTop = wrapper.scrollTop;
|
|
@@ -38959,6 +38909,19 @@ var TextHighlighter = class {
|
|
|
38959
38909
|
const isRight = rect.left > windowRight;
|
|
38960
38910
|
return isAbove || isBelow || isLeft || isRight;
|
|
38961
38911
|
}
|
|
38912
|
+
isInsideViewport(rect) {
|
|
38913
|
+
let wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
38914
|
+
const windowTop = wrapper.scrollTop;
|
|
38915
|
+
const windowBottom = windowTop + wrapper.clientHeight;
|
|
38916
|
+
const isAbove = rect.top + 20 >= windowTop;
|
|
38917
|
+
const isBelow = rect.top <= windowBottom;
|
|
38918
|
+
const windowLeft = wrapper.scrollLeft;
|
|
38919
|
+
const windowRight = windowLeft + wrapper.clientWidth;
|
|
38920
|
+
const right = rect.left + rect.width;
|
|
38921
|
+
const isLeft = rect.left > windowLeft;
|
|
38922
|
+
const isRight = right < windowRight;
|
|
38923
|
+
return isAbove && isBelow && isLeft && isRight;
|
|
38924
|
+
}
|
|
38962
38925
|
get visibleTextRects() {
|
|
38963
38926
|
let doc = this.delegate.iframes[0].contentDocument;
|
|
38964
38927
|
if (doc) {
|
|
@@ -39006,7 +38969,7 @@ var TextHighlighter = class {
|
|
|
39006
38969
|
};
|
|
39007
38970
|
const body = findRequiredIframeElement(doc, "body");
|
|
39008
38971
|
const textNodes = findRects(body);
|
|
39009
|
-
return textNodes.filter((rect) =>
|
|
38972
|
+
return textNodes.filter((rect) => this.isInsideViewport(rect));
|
|
39010
38973
|
}
|
|
39011
38974
|
return [];
|
|
39012
38975
|
}
|
|
@@ -43197,11 +43160,11 @@ var SearchModule = class {
|
|
|
43197
43160
|
var absolutehref = this.publication.getAbsoluteHref(href);
|
|
43198
43161
|
let filteredIndexes = this.bookSearchResult.filter((el) => el.href === href);
|
|
43199
43162
|
if (current) {
|
|
43200
|
-
item = this.currentChapterSearchResult.filter((el) => el.uuid
|
|
43201
|
-
filteredIndex = this.currentChapterSearchResult.findIndex((el) => el.uuid
|
|
43163
|
+
item = this.currentChapterSearchResult.filter((el) => el.uuid === index2)[0];
|
|
43164
|
+
filteredIndex = this.currentChapterSearchResult.findIndex((el) => el.uuid === index2);
|
|
43202
43165
|
} else {
|
|
43203
|
-
item = filteredIndexes.filter((el) => el.uuid
|
|
43204
|
-
filteredIndex = filteredIndexes.findIndex((el) => el.uuid
|
|
43166
|
+
item = filteredIndexes.filter((el) => el.uuid === index2)[0];
|
|
43167
|
+
filteredIndex = filteredIndexes.findIndex((el) => el.uuid === index2);
|
|
43205
43168
|
}
|
|
43206
43169
|
if (item !== void 0) {
|
|
43207
43170
|
if (currentLocation === absolutehref) {
|
|
@@ -46897,8 +46860,11 @@ var TTSModule2 = class {
|
|
|
46897
46860
|
constructor(delegate, tts, rights, highlighter, properties, api, headerMenu) {
|
|
46898
46861
|
this.voices = [];
|
|
46899
46862
|
this.hasEventListener = false;
|
|
46863
|
+
this.startX = 0;
|
|
46864
|
+
this.startY = 0;
|
|
46900
46865
|
this.index = 0;
|
|
46901
46866
|
this.userScrolled = false;
|
|
46867
|
+
this.scrollPartial = false;
|
|
46902
46868
|
this.speaking = false;
|
|
46903
46869
|
this.restartIndex = -1;
|
|
46904
46870
|
this.ttsQueueIndex = -1;
|
|
@@ -46939,11 +46905,28 @@ var TTSModule2 = class {
|
|
|
46939
46905
|
addEventListenerOptional(document, "keydown", this.wheel.bind(this));
|
|
46940
46906
|
addEventListenerOptional(this.delegate.iframes[0].contentDocument, "keydown", this.wheel.bind(this));
|
|
46941
46907
|
}
|
|
46942
|
-
addEventListenerOptional(this.body, "
|
|
46908
|
+
addEventListenerOptional(this.body, "mousedown", this.clickStart.bind(this));
|
|
46909
|
+
addEventListenerOptional(this.body, "mouseup", this.click.bind(this));
|
|
46943
46910
|
}
|
|
46944
46911
|
}
|
|
46945
|
-
|
|
46946
|
-
if (
|
|
46912
|
+
clickStart(event) {
|
|
46913
|
+
if ("clientX" in event) {
|
|
46914
|
+
this.startX = event.clientX;
|
|
46915
|
+
}
|
|
46916
|
+
if ("clientY" in event) {
|
|
46917
|
+
this.startY = event.clientY;
|
|
46918
|
+
}
|
|
46919
|
+
}
|
|
46920
|
+
click(event) {
|
|
46921
|
+
let startX = 0;
|
|
46922
|
+
let startY = 0;
|
|
46923
|
+
if ("clientX" in event) {
|
|
46924
|
+
startX = event.clientX;
|
|
46925
|
+
}
|
|
46926
|
+
if ("clientY" in event) {
|
|
46927
|
+
startY = event.clientY;
|
|
46928
|
+
}
|
|
46929
|
+
if (window.speechSynthesis.speaking && this.speaking && startX === this.startX && startY === this.startY) {
|
|
46947
46930
|
let doc = this.delegate.iframes[0].contentDocument;
|
|
46948
46931
|
if (doc) {
|
|
46949
46932
|
const selection = this.highlighter.dom(doc.body).getSelection();
|
|
@@ -47176,6 +47159,7 @@ var TTSModule2 = class {
|
|
|
47176
47159
|
callback();
|
|
47177
47160
|
}
|
|
47178
47161
|
speakPlay() {
|
|
47162
|
+
this.scrollPartial = true;
|
|
47179
47163
|
this.cancel(false);
|
|
47180
47164
|
if (this.api?.started)
|
|
47181
47165
|
this.api?.started();
|
|
@@ -47720,11 +47704,13 @@ var TTSModule2 = class {
|
|
|
47720
47704
|
}, HighlightType.ReadAloud, "R2_READALOUD_");
|
|
47721
47705
|
if (result) {
|
|
47722
47706
|
this._ttsQueueItemHighlightsWord = result[0];
|
|
47723
|
-
if (this.delegate.view?.isScrollMode() && this.tts.autoScroll && !this.userScrolled) {
|
|
47707
|
+
if (this.delegate.view?.isScrollMode() && this.tts.autoScroll && !this.userScrolled && this.scrollPartial) {
|
|
47724
47708
|
result[1]?.firstChild?.scrollIntoView({
|
|
47725
47709
|
block: "center",
|
|
47726
47710
|
behavior: "smooth"
|
|
47727
47711
|
});
|
|
47712
|
+
} else if (this.delegate.view?.isPaginated()) {
|
|
47713
|
+
self2.delegate.view?.snap(result[1]?.firstChild);
|
|
47728
47714
|
}
|
|
47729
47715
|
}
|
|
47730
47716
|
}
|