@d-i-t-a/reader 2.3.8 → 2.3.9
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 +100 -153
- package/dist/esm/index.js.map +2 -2
- package/dist/reader.js +19 -19
- package/dist/reader.js.map +2 -2
- package/dist/types/modules/TTS/TTSModule2.d.ts +1 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -57473,11 +57473,6 @@ var TTSModule2 = class {
|
|
|
57473
57473
|
let doc = this.navigator.iframes[0].contentDocument;
|
|
57474
57474
|
if (doc) {
|
|
57475
57475
|
let selection = this.highlighter.dom(doc.body).getSelection();
|
|
57476
|
-
if (selection.isCollapsed) {
|
|
57477
|
-
let doc2 = this.navigator.iframes[0].contentDocument;
|
|
57478
|
-
const selectionInfo = this.navigator.annotationModule?.annotator?.getTemporarySelectionInfo(doc2);
|
|
57479
|
-
selection.addRange(selectionInfo.range);
|
|
57480
|
-
}
|
|
57481
57476
|
let range = selection.getRangeAt(0);
|
|
57482
57477
|
let node = selection.anchorNode;
|
|
57483
57478
|
while (range.toString().indexOf(" ") !== 0) {
|
|
@@ -57560,6 +57555,11 @@ var TTSModule2 = class {
|
|
|
57560
57555
|
}
|
|
57561
57556
|
}
|
|
57562
57557
|
async speak(selectionInfo, partial, callback) {
|
|
57558
|
+
if (!partial) {
|
|
57559
|
+
if (this.navigator.rights.enableContentProtection) {
|
|
57560
|
+
this.navigator.contentProtectionModule?.deactivate();
|
|
57561
|
+
}
|
|
57562
|
+
}
|
|
57563
57563
|
if (this.api?.started)
|
|
57564
57564
|
this.api?.started();
|
|
57565
57565
|
this.navigator.emit("readaloud.started", "started");
|
|
@@ -57616,6 +57616,10 @@ var TTSModule2 = class {
|
|
|
57616
57616
|
restOfTheText = restOfTheText.replace(textToBeSpoken, "").trim();
|
|
57617
57617
|
}
|
|
57618
57618
|
utterance = new SpeechSynthesisUtterance(textToBeSpoken);
|
|
57619
|
+
utterance.rate = this.tts.rate;
|
|
57620
|
+
utterance.pitch = this.tts.pitch;
|
|
57621
|
+
utterance.volume = this.tts.volume;
|
|
57622
|
+
this.setVoice(this, utterance);
|
|
57619
57623
|
import_loglevel18.default.log(selectionInfo);
|
|
57620
57624
|
import_loglevel18.default.log(textToBeSpoken, selectionInfo.range?.commonAncestorContainer.textContent);
|
|
57621
57625
|
import_loglevel18.default.log(ttsQueueItem);
|
|
@@ -57638,19 +57642,85 @@ var TTSModule2 = class {
|
|
|
57638
57642
|
utterance.rate = this.tts.rate;
|
|
57639
57643
|
utterance.pitch = this.tts.pitch;
|
|
57640
57644
|
utterance.volume = this.tts.volume;
|
|
57645
|
+
this.setVoice(self2, utterance);
|
|
57646
|
+
this.index = 0;
|
|
57647
|
+
function onend() {
|
|
57648
|
+
utterance.onend = function() {
|
|
57649
|
+
if (idxEnd > idx) {
|
|
57650
|
+
idx = idx + 1;
|
|
57651
|
+
if (idx !== idxEnd) {
|
|
57652
|
+
const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
|
|
57653
|
+
if (ttsQueueItem) {
|
|
57654
|
+
const sentence = getTtsQueueItemRefText(ttsQueueItem);
|
|
57655
|
+
utterance = new SpeechSynthesisUtterance(sentence);
|
|
57656
|
+
utterance.rate = self2.tts.rate;
|
|
57657
|
+
utterance.pitch = self2.tts.pitch;
|
|
57658
|
+
utterance.volume = self2.tts.volume;
|
|
57659
|
+
self2.setVoice(self2, utterance);
|
|
57660
|
+
utterance.onboundary = (ev) => {
|
|
57661
|
+
self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
|
|
57662
|
+
};
|
|
57663
|
+
setTimeout(() => {
|
|
57664
|
+
window.speechSynthesis.speak(utterance);
|
|
57665
|
+
}, 0);
|
|
57666
|
+
onend();
|
|
57667
|
+
}
|
|
57668
|
+
} else {
|
|
57669
|
+
const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
|
|
57670
|
+
if (ttsQueueItem) {
|
|
57671
|
+
utterance = new SpeechSynthesisUtterance(restOfTheText);
|
|
57672
|
+
utterance.rate = self2.tts.rate;
|
|
57673
|
+
utterance.pitch = self2.tts.pitch;
|
|
57674
|
+
utterance.volume = self2.tts.volume;
|
|
57675
|
+
self2.setVoice(self2, utterance);
|
|
57676
|
+
utterance.onboundary = (ev) => {
|
|
57677
|
+
self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
|
|
57678
|
+
};
|
|
57679
|
+
setTimeout(() => {
|
|
57680
|
+
window.speechSynthesis.speak(utterance);
|
|
57681
|
+
}, 0);
|
|
57682
|
+
onend();
|
|
57683
|
+
}
|
|
57684
|
+
if (idx > idxEnd) {
|
|
57685
|
+
import_loglevel18.default.log("utterance ended");
|
|
57686
|
+
self2.highlighter.doneSpeaking();
|
|
57687
|
+
self2.api?.finished();
|
|
57688
|
+
self2.navigator.emit("readaloud.finished", "finished");
|
|
57689
|
+
}
|
|
57690
|
+
}
|
|
57691
|
+
} else {
|
|
57692
|
+
import_loglevel18.default.log("utterance ended");
|
|
57693
|
+
self2.highlighter.doneSpeaking();
|
|
57694
|
+
self2.api?.finished();
|
|
57695
|
+
self2.navigator.emit("readaloud.finished", "finished");
|
|
57696
|
+
}
|
|
57697
|
+
};
|
|
57698
|
+
}
|
|
57699
|
+
setTimeout(() => {
|
|
57700
|
+
window.speechSynthesis.speak(utterance);
|
|
57701
|
+
if (!partial) {
|
|
57702
|
+
if (this.navigator.rights.enableContentProtection) {
|
|
57703
|
+
this.navigator.contentProtectionModule?.recalculate(200);
|
|
57704
|
+
}
|
|
57705
|
+
}
|
|
57706
|
+
}, 0);
|
|
57707
|
+
onend();
|
|
57708
|
+
callback();
|
|
57709
|
+
}
|
|
57710
|
+
setVoice(self2, utterance) {
|
|
57641
57711
|
import_loglevel18.default.log("this.tts.voice.lang", this.tts.voice.lang);
|
|
57642
|
-
|
|
57712
|
+
let initialVoiceHasHyphen = true;
|
|
57643
57713
|
if (this.tts.voice && this.tts.voice.lang) {
|
|
57644
57714
|
initialVoiceHasHyphen = this.tts.voice.lang.indexOf("-") !== -1;
|
|
57645
|
-
if (initialVoiceHasHyphen
|
|
57715
|
+
if (!initialVoiceHasHyphen) {
|
|
57646
57716
|
this.tts.voice.lang = this.tts.voice.lang.replace("_", "-");
|
|
57647
57717
|
initialVoiceHasHyphen = true;
|
|
57648
57718
|
}
|
|
57649
57719
|
}
|
|
57650
57720
|
import_loglevel18.default.log("initialVoiceHasHyphen", initialVoiceHasHyphen);
|
|
57651
57721
|
import_loglevel18.default.log("voices", this.voices);
|
|
57652
|
-
|
|
57653
|
-
if (initialVoiceHasHyphen
|
|
57722
|
+
let initialVoice;
|
|
57723
|
+
if (initialVoiceHasHyphen) {
|
|
57654
57724
|
initialVoice = this.tts.voice && this.tts.voice.lang && this.tts.voice.name ? this.voices.filter((v) => {
|
|
57655
57725
|
var lang = v.lang.replace("_", "-");
|
|
57656
57726
|
return lang === this.tts.voice.lang && v.name === this.tts.voice.name;
|
|
@@ -57667,10 +57737,10 @@ var TTSModule2 = class {
|
|
|
57667
57737
|
}
|
|
57668
57738
|
}
|
|
57669
57739
|
import_loglevel18.default.log("initialVoice", initialVoice);
|
|
57670
|
-
|
|
57740
|
+
const publicationVoiceHasHyphen = self2.navigator.publication.Metadata.Language[0].indexOf("-") !== -1;
|
|
57671
57741
|
import_loglevel18.default.log("publicationVoiceHasHyphen", publicationVoiceHasHyphen);
|
|
57672
|
-
|
|
57673
|
-
if (publicationVoiceHasHyphen
|
|
57742
|
+
let publicationVoice;
|
|
57743
|
+
if (publicationVoiceHasHyphen) {
|
|
57674
57744
|
publicationVoice = this.tts.voice && this.tts.voice.usePublication ? this.voices.filter((v) => {
|
|
57675
57745
|
var lang = v.lang.replace("_", "-");
|
|
57676
57746
|
return lang.startsWith(self2.navigator.publication.Metadata.Language[0]) || lang.endsWith(self2.navigator.publication.Metadata.Language[0].toUpperCase());
|
|
@@ -57681,24 +57751,24 @@ var TTSModule2 = class {
|
|
|
57681
57751
|
})[0] : void 0;
|
|
57682
57752
|
}
|
|
57683
57753
|
import_loglevel18.default.log("publicationVoice", publicationVoice);
|
|
57684
|
-
|
|
57754
|
+
const defaultVoiceHasHyphen = navigator.language.indexOf("-") !== -1;
|
|
57685
57755
|
import_loglevel18.default.log("defaultVoiceHasHyphen", defaultVoiceHasHyphen);
|
|
57686
|
-
|
|
57687
|
-
if (defaultVoiceHasHyphen
|
|
57756
|
+
let defaultVoice;
|
|
57757
|
+
if (defaultVoiceHasHyphen) {
|
|
57688
57758
|
defaultVoice = this.voices.filter((voice) => {
|
|
57689
|
-
|
|
57690
|
-
return lang === navigator.language && voice.localService
|
|
57759
|
+
const lang = voice.lang.replace("_", "-");
|
|
57760
|
+
return lang === navigator.language && voice.localService;
|
|
57691
57761
|
})[0];
|
|
57692
57762
|
} else {
|
|
57693
57763
|
defaultVoice = this.voices.filter((voice) => {
|
|
57694
|
-
|
|
57695
|
-
return lang === navigator.language && voice.localService
|
|
57764
|
+
const lang = voice.lang;
|
|
57765
|
+
return lang === navigator.language && voice.localService;
|
|
57696
57766
|
})[0];
|
|
57697
57767
|
}
|
|
57698
57768
|
if (defaultVoice === void 0) {
|
|
57699
57769
|
defaultVoice = this.voices.filter((voice) => {
|
|
57700
|
-
|
|
57701
|
-
return lang.includes(navigator.language) && voice.localService
|
|
57770
|
+
const lang = voice.lang;
|
|
57771
|
+
return lang.includes(navigator.language) && voice.localService;
|
|
57702
57772
|
})[0];
|
|
57703
57773
|
}
|
|
57704
57774
|
import_loglevel18.default.log("defaultVoice", defaultVoice);
|
|
@@ -57718,58 +57788,11 @@ var TTSModule2 = class {
|
|
|
57718
57788
|
import_loglevel18.default.log("utterance.lang", utterance.lang);
|
|
57719
57789
|
}
|
|
57720
57790
|
import_loglevel18.default.log("navigator.language", navigator.language);
|
|
57721
|
-
setTimeout(() => {
|
|
57722
|
-
window.speechSynthesis.speak(utterance);
|
|
57723
|
-
}, 0);
|
|
57724
|
-
this.index = 0;
|
|
57725
|
-
function onend() {
|
|
57726
|
-
utterance.onend = function() {
|
|
57727
|
-
if (idxEnd > idx) {
|
|
57728
|
-
idx = idx + 1;
|
|
57729
|
-
if (idx !== idxEnd) {
|
|
57730
|
-
const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
|
|
57731
|
-
if (ttsQueueItem) {
|
|
57732
|
-
const sentence = getTtsQueueItemRefText(ttsQueueItem);
|
|
57733
|
-
utterance = new SpeechSynthesisUtterance(sentence);
|
|
57734
|
-
utterance.onboundary = (ev) => {
|
|
57735
|
-
self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
|
|
57736
|
-
};
|
|
57737
|
-
setTimeout(() => {
|
|
57738
|
-
window.speechSynthesis.speak(utterance);
|
|
57739
|
-
}, 0);
|
|
57740
|
-
onend();
|
|
57741
|
-
}
|
|
57742
|
-
} else {
|
|
57743
|
-
const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
|
|
57744
|
-
if (ttsQueueItem) {
|
|
57745
|
-
utterance = new SpeechSynthesisUtterance(restOfTheText);
|
|
57746
|
-
utterance.onboundary = (ev) => {
|
|
57747
|
-
self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
|
|
57748
|
-
};
|
|
57749
|
-
setTimeout(() => {
|
|
57750
|
-
window.speechSynthesis.speak(utterance);
|
|
57751
|
-
}, 0);
|
|
57752
|
-
onend();
|
|
57753
|
-
}
|
|
57754
|
-
if (idx > idxEnd) {
|
|
57755
|
-
import_loglevel18.default.log("utterance ended");
|
|
57756
|
-
self2.highlighter.doneSpeaking();
|
|
57757
|
-
self2.api?.finished();
|
|
57758
|
-
self2.navigator.emit("readaloud.finished", "finished");
|
|
57759
|
-
}
|
|
57760
|
-
}
|
|
57761
|
-
} else {
|
|
57762
|
-
import_loglevel18.default.log("utterance ended");
|
|
57763
|
-
self2.highlighter.doneSpeaking();
|
|
57764
|
-
self2.api?.finished();
|
|
57765
|
-
self2.navigator.emit("readaloud.finished", "finished");
|
|
57766
|
-
}
|
|
57767
|
-
};
|
|
57768
|
-
}
|
|
57769
|
-
onend();
|
|
57770
|
-
callback();
|
|
57771
57791
|
}
|
|
57772
57792
|
speakPlay() {
|
|
57793
|
+
if (this.navigator.rights.enableContentProtection) {
|
|
57794
|
+
this.navigator.contentProtectionModule?.deactivate();
|
|
57795
|
+
}
|
|
57773
57796
|
this.scrollPartial = true;
|
|
57774
57797
|
this.cancel(false);
|
|
57775
57798
|
if (this.api?.started)
|
|
@@ -57819,6 +57842,9 @@ var TTSModule2 = class {
|
|
|
57819
57842
|
this.startTTSSession(ttsQueue, ttsQueueIndex);
|
|
57820
57843
|
}, 200);
|
|
57821
57844
|
}
|
|
57845
|
+
if (this.navigator.rights.enableContentProtection) {
|
|
57846
|
+
this.navigator.contentProtectionModule?.recalculate(200);
|
|
57847
|
+
}
|
|
57822
57848
|
}
|
|
57823
57849
|
speakPause() {
|
|
57824
57850
|
if (window.speechSynthesis.speaking) {
|
|
@@ -58033,87 +58059,8 @@ var TTSModule2 = class {
|
|
|
58033
58059
|
utterance.rate = this.tts.rate;
|
|
58034
58060
|
utterance.pitch = this.tts.pitch;
|
|
58035
58061
|
utterance.volume = this.tts.volume;
|
|
58036
|
-
|
|
58037
|
-
|
|
58038
|
-
if (this.tts.voice && this.tts.voice.lang) {
|
|
58039
|
-
initialVoiceHasHyphen = this.tts.voice.lang.indexOf("-") !== -1;
|
|
58040
|
-
if (initialVoiceHasHyphen === false) {
|
|
58041
|
-
this.tts.voice.lang = this.tts.voice.lang.replace("_", "-");
|
|
58042
|
-
initialVoiceHasHyphen = true;
|
|
58043
|
-
}
|
|
58044
|
-
}
|
|
58045
|
-
import_loglevel18.default.log("initialVoiceHasHyphen", initialVoiceHasHyphen);
|
|
58046
|
-
import_loglevel18.default.log("voices", this.voices);
|
|
58047
|
-
var initialVoice;
|
|
58048
|
-
if (initialVoiceHasHyphen === true) {
|
|
58049
|
-
initialVoice = this.tts.voice && this.tts.voice.lang && this.tts.voice.name ? this.voices.filter((v) => {
|
|
58050
|
-
var lang = v.lang.replace("_", "-");
|
|
58051
|
-
return lang === this.tts.voice.lang && v.name === this.tts.voice.name;
|
|
58052
|
-
})[0] : void 0;
|
|
58053
|
-
if (initialVoice === void 0) {
|
|
58054
|
-
initialVoice = this.tts.voice && this.tts.voice.lang ? this.voices.filter((v) => v.lang.replace("_", "-") === this.tts.voice.lang)[0] : void 0;
|
|
58055
|
-
}
|
|
58056
|
-
} else {
|
|
58057
|
-
initialVoice = this.tts.voice && this.tts.voice.lang && this.tts.voice.name ? this.voices.filter((v) => {
|
|
58058
|
-
return v.lang === this.tts.voice.lang && v.name === this.tts.voice.name;
|
|
58059
|
-
})[0] : void 0;
|
|
58060
|
-
if (initialVoice === void 0) {
|
|
58061
|
-
initialVoice = this.tts.voice && this.tts.voice.lang ? this.voices.filter((v) => v.lang === this.tts.voice.lang)[0] : void 0;
|
|
58062
|
-
}
|
|
58063
|
-
}
|
|
58064
|
-
import_loglevel18.default.log("initialVoice", initialVoice);
|
|
58065
|
-
var self2 = this;
|
|
58066
|
-
var publicationVoiceHasHyphen = self2.navigator.publication.Metadata.Language[0].indexOf("-") !== -1;
|
|
58067
|
-
import_loglevel18.default.log("publicationVoiceHasHyphen", publicationVoiceHasHyphen);
|
|
58068
|
-
var publicationVoice;
|
|
58069
|
-
if (publicationVoiceHasHyphen === true) {
|
|
58070
|
-
publicationVoice = this.tts.voice && this.tts.voice.usePublication ? this.voices.filter((v) => {
|
|
58071
|
-
var lang = v.lang.replace("_", "-");
|
|
58072
|
-
return lang.startsWith(self2.navigator.publication.Metadata.Language[0]) || lang.endsWith(self2.navigator.publication.Metadata.Language[0].toUpperCase());
|
|
58073
|
-
})[0] : void 0;
|
|
58074
|
-
} else {
|
|
58075
|
-
publicationVoice = this.tts.voice && this.tts.voice.usePublication ? this.voices.filter((v) => {
|
|
58076
|
-
return v.lang.startsWith(self2.navigator.publication.Metadata.Language[0]) || v.lang.endsWith(self2.navigator.publication.Metadata.Language[0].toUpperCase());
|
|
58077
|
-
})[0] : void 0;
|
|
58078
|
-
}
|
|
58079
|
-
import_loglevel18.default.log("publicationVoice", publicationVoice);
|
|
58080
|
-
var defaultVoiceHasHyphen = navigator.language.indexOf("-") !== -1;
|
|
58081
|
-
import_loglevel18.default.log("defaultVoiceHasHyphen", defaultVoiceHasHyphen);
|
|
58082
|
-
var defaultVoice;
|
|
58083
|
-
if (defaultVoiceHasHyphen === true) {
|
|
58084
|
-
defaultVoice = this.voices.filter((voice) => {
|
|
58085
|
-
var lang = voice.lang.replace("_", "-");
|
|
58086
|
-
return lang === navigator.language && voice.localService === true;
|
|
58087
|
-
})[0];
|
|
58088
|
-
} else {
|
|
58089
|
-
defaultVoice = this.voices.filter((voice) => {
|
|
58090
|
-
var lang = voice.lang;
|
|
58091
|
-
return lang === navigator.language && voice.localService === true;
|
|
58092
|
-
})[0];
|
|
58093
|
-
}
|
|
58094
|
-
if (defaultVoice === void 0) {
|
|
58095
|
-
defaultVoice = this.voices.filter((voice) => {
|
|
58096
|
-
var lang = voice.lang;
|
|
58097
|
-
return lang.includes(navigator.language) && voice.localService === true;
|
|
58098
|
-
})[0];
|
|
58099
|
-
}
|
|
58100
|
-
import_loglevel18.default.log("defaultVoice", defaultVoice);
|
|
58101
|
-
if (initialVoice) {
|
|
58102
|
-
import_loglevel18.default.log("initialVoice");
|
|
58103
|
-
utterance.voice = initialVoice;
|
|
58104
|
-
} else if (publicationVoice) {
|
|
58105
|
-
import_loglevel18.default.log("publicationVoice");
|
|
58106
|
-
utterance.voice = publicationVoice;
|
|
58107
|
-
} else if (defaultVoice) {
|
|
58108
|
-
import_loglevel18.default.log("defaultVoice");
|
|
58109
|
-
utterance.voice = defaultVoice;
|
|
58110
|
-
}
|
|
58111
|
-
if (utterance.voice !== void 0 && utterance.voice !== null) {
|
|
58112
|
-
utterance.lang = utterance.voice.lang;
|
|
58113
|
-
import_loglevel18.default.log("utterance.voice.lang", utterance.voice.lang);
|
|
58114
|
-
import_loglevel18.default.log("utterance.lang", utterance.lang);
|
|
58115
|
-
}
|
|
58116
|
-
import_loglevel18.default.log("navigator.language", navigator.language);
|
|
58062
|
+
const self2 = this;
|
|
58063
|
+
this.setVoice(self2, utterance);
|
|
58117
58064
|
utterance.onboundary = (ev) => {
|
|
58118
58065
|
import_loglevel18.default.log(ev.name);
|
|
58119
58066
|
this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
|
|
@@ -58208,7 +58155,7 @@ var TTSModule2 = class {
|
|
|
58208
58155
|
const range = new Range();
|
|
58209
58156
|
range.setStart(rangeStartNode, rangeStartOffset);
|
|
58210
58157
|
range.setEnd(rangeEndNode, rangeEndOffset);
|
|
58211
|
-
|
|
58158
|
+
const self2 = this;
|
|
58212
58159
|
const rangeInfo = convertRange(range, getCssSelector);
|
|
58213
58160
|
if (!rangeInfo) {
|
|
58214
58161
|
return;
|