@d-i-t-a/reader 2.0.6-beta.1 → 2.0.6-beta.2
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
|
@@ -35020,7 +35020,7 @@ var Publication = class extends import_publication.Publication {
|
|
|
35020
35020
|
}
|
|
35021
35021
|
for (const locator of positions) {
|
|
35022
35022
|
const resource = positions.filter((el) => el.href === decodeURI(locator.href));
|
|
35023
|
-
const positionIndex = Math.ceil(locator.locations.progression ? locator.locations.progression : 0 * (resource.length - 1));
|
|
35023
|
+
const positionIndex = Math.ceil((locator.locations.progression ? locator.locations.progression : 0) * (resource.length - 1));
|
|
35024
35024
|
if (locator.locations.position) {
|
|
35025
35025
|
locator.locations.totalProgression = (locator.locations.position - 1) / positions.length;
|
|
35026
35026
|
}
|
|
@@ -38342,7 +38342,6 @@ var TextHighlighter = class {
|
|
|
38342
38342
|
let doc = el.ownerDocument;
|
|
38343
38343
|
el.addEventListener("mouseup", this.toolboxShowDelayed.bind(this));
|
|
38344
38344
|
el.addEventListener("touchend", this.toolboxShowDelayed.bind(this));
|
|
38345
|
-
doc.addEventListener("selectstart", this.toolboxShowDelayed.bind(this));
|
|
38346
38345
|
if (!hasEventListener) {
|
|
38347
38346
|
window.addEventListener("resize", this.toolboxPlacement.bind(this));
|
|
38348
38347
|
}
|
|
@@ -38376,7 +38375,6 @@ var TextHighlighter = class {
|
|
|
38376
38375
|
let doc = el.ownerDocument;
|
|
38377
38376
|
el.removeEventListener("mouseup", this.toolboxShowDelayed.bind(this));
|
|
38378
38377
|
el.removeEventListener("touchend", this.toolboxShowDelayed.bind(this));
|
|
38379
|
-
doc.removeEventListener("selectstart", this.toolboxShowDelayed.bind(this));
|
|
38380
38378
|
window.removeEventListener("resize", this.toolboxPlacement.bind(this));
|
|
38381
38379
|
doc.removeEventListener("selectionchange", this.toolboxPlacement.bind(this));
|
|
38382
38380
|
el.removeEventListener("mousedown", this.toolboxHide.bind(this));
|
|
@@ -38555,41 +38553,70 @@ var TextHighlighter = class {
|
|
|
38555
38553
|
toolbox.style.display = "none";
|
|
38556
38554
|
this.selectionMenuClosed();
|
|
38557
38555
|
}
|
|
38558
|
-
toolboxShowDelayed() {
|
|
38556
|
+
toolboxShowDelayed(ev) {
|
|
38559
38557
|
let self2 = this;
|
|
38560
38558
|
setTimeout(function() {
|
|
38561
38559
|
if (!self2.isAndroid()) {
|
|
38562
|
-
self2.snapSelectionToWord();
|
|
38560
|
+
self2.snapSelectionToWord(ev.detail === 1);
|
|
38563
38561
|
}
|
|
38564
38562
|
self2.toolboxShow();
|
|
38565
38563
|
}, 100);
|
|
38566
38564
|
}
|
|
38567
|
-
snapSelectionToWord() {
|
|
38565
|
+
snapSelectionToWord(trimmed = false) {
|
|
38568
38566
|
let self2 = this;
|
|
38569
38567
|
let doc = this.delegate.iframes[0].contentDocument;
|
|
38570
38568
|
if (doc) {
|
|
38571
38569
|
let selection = self2.dom(doc.body)?.getWindow()?.getSelection();
|
|
38572
38570
|
if (self2.dom(doc.body)) {
|
|
38573
38571
|
if (selection && !selection?.isCollapsed) {
|
|
38574
|
-
|
|
38575
|
-
|
|
38576
|
-
|
|
38572
|
+
let removeTrailingPunctuation = function(text2) {
|
|
38573
|
+
const match = text2.match(new RegExp(`[^a-zA-Z0-9]+$`));
|
|
38574
|
+
if (!match || !match.index) {
|
|
38575
|
+
return text2;
|
|
38576
|
+
}
|
|
38577
|
+
return text2.slice(0, match.index);
|
|
38578
|
+
};
|
|
38579
|
+
let text = selection.toString();
|
|
38580
|
+
let startOffsetTemp = text.length - text.trimStart().length;
|
|
38581
|
+
let endOffsetTemp = text.length - text.trimEnd().length;
|
|
38582
|
+
let length = text.length;
|
|
38583
|
+
var regex_symbols = /[-!$%^&*()_+|~=`{}\[\]:\/;<>?,.@#]/;
|
|
38584
|
+
text = text.replace(regex_symbols, "");
|
|
38585
|
+
startOffsetTemp = length - text.trimStart().length;
|
|
38586
|
+
text = removeTrailingPunctuation(text);
|
|
38587
|
+
endOffsetTemp = length - text.trimEnd().length;
|
|
38577
38588
|
let range = document.createRange();
|
|
38578
|
-
|
|
38579
|
-
|
|
38589
|
+
if (trimmed) {
|
|
38590
|
+
range.setStart(selection.anchorNode, selection.anchorOffset + startOffsetTemp);
|
|
38591
|
+
range.setEnd(selection.focusNode, selection.focusOffset - endOffsetTemp);
|
|
38592
|
+
} else {
|
|
38593
|
+
range.setStart(selection.anchorNode, selection.anchorOffset);
|
|
38594
|
+
range.setEnd(selection.focusNode, selection.focusOffset);
|
|
38595
|
+
}
|
|
38580
38596
|
let backwards = range.collapsed;
|
|
38581
38597
|
range.detach();
|
|
38582
|
-
let endNode = selection.focusNode
|
|
38583
|
-
|
|
38598
|
+
let endNode = selection.focusNode;
|
|
38599
|
+
let endOffset;
|
|
38600
|
+
if (trimmed) {
|
|
38601
|
+
endOffset = selection.focusOffset - endOffsetTemp;
|
|
38602
|
+
selection.collapse(selection.anchorNode, selection.anchorOffset + startOffsetTemp);
|
|
38603
|
+
} else {
|
|
38604
|
+
endOffset = selection.focusOffset;
|
|
38605
|
+
selection.collapse(selection.anchorNode, selection.anchorOffset);
|
|
38606
|
+
}
|
|
38584
38607
|
let direction = ["forward", "backward"];
|
|
38585
38608
|
if (backwards) {
|
|
38586
38609
|
direction = ["backward", "forward"];
|
|
38587
38610
|
}
|
|
38588
|
-
|
|
38589
|
-
|
|
38590
|
-
|
|
38591
|
-
|
|
38592
|
-
|
|
38611
|
+
if (trimmed) {
|
|
38612
|
+
selection.modify("move", direction[0], "character");
|
|
38613
|
+
selection.modify("move", direction[1], "word");
|
|
38614
|
+
selection.extend(endNode, endOffset);
|
|
38615
|
+
selection.modify("extend", direction[1], "character");
|
|
38616
|
+
selection.modify("extend", direction[0], "word");
|
|
38617
|
+
} else {
|
|
38618
|
+
selection.extend(endNode, endOffset);
|
|
38619
|
+
}
|
|
38593
38620
|
this.selection(selection.toString(), selection);
|
|
38594
38621
|
}
|
|
38595
38622
|
}
|
|
@@ -46896,6 +46923,7 @@ var TTSModule2 = class {
|
|
|
46896
46923
|
allowedTags: [],
|
|
46897
46924
|
allowedAttributes: {}
|
|
46898
46925
|
});
|
|
46926
|
+
this.wrapper = findRequiredElement(document, "#iframe-wrapper");
|
|
46899
46927
|
window.speechSynthesis.getVoices();
|
|
46900
46928
|
this.initVoices(true);
|
|
46901
46929
|
if (!this.hasEventListener) {
|
|
@@ -47704,7 +47732,10 @@ var TTSModule2 = class {
|
|
|
47704
47732
|
}, HighlightType.ReadAloud, "R2_READALOUD_");
|
|
47705
47733
|
if (result) {
|
|
47706
47734
|
this._ttsQueueItemHighlightsWord = result[0];
|
|
47707
|
-
|
|
47735
|
+
const viewportOffset = result[1]?.firstChild?.getBoundingClientRect();
|
|
47736
|
+
const top = viewportOffset.top - this.wrapper.scrollTop;
|
|
47737
|
+
const shouldScroll = top > window.innerHeight / 2 - 65;
|
|
47738
|
+
if (this.delegate.view?.isScrollMode() && this.tts.autoScroll && !this.userScrolled && this.scrollPartial && shouldScroll) {
|
|
47708
47739
|
result[1]?.firstChild?.scrollIntoView({
|
|
47709
47740
|
block: "center",
|
|
47710
47741
|
behavior: "smooth"
|