@d-i-t-a/reader 2.3.7 → 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 CHANGED
@@ -56120,9 +56120,6 @@ var SearchModule = class {
56120
56120
  self2.currentChapterSearchResult = [];
56121
56121
  self2.currentSearchHighlights = [];
56122
56122
  var localSearchResultChapter = [];
56123
- if (this.navigator.rights.enableContentProtection) {
56124
- this.navigator.contentProtectionModule?.deactivate();
56125
- }
56126
56123
  await this.searchAndPaintChapter(searchVal, index2, async (result) => {
56127
56124
  localSearchResultChapter = result;
56128
56125
  goToResultPage(1);
@@ -56210,6 +56207,9 @@ var SearchModule = class {
56210
56207
  }
56211
56208
  }
56212
56209
  async searchAndPaintChapter(term, index2 = 0, callback) {
56210
+ if (this.navigator.rights.enableContentProtection) {
56211
+ this.navigator.contentProtectionModule?.deactivate();
56212
+ }
56213
56213
  const linkHref = this.publication.getAbsoluteHref(this.publication.readingOrder[this.navigator.currentResource() ?? 0].Href);
56214
56214
  let tocItem = this.publication.getTOCItem(linkHref);
56215
56215
  if (tocItem === null) {
@@ -56289,6 +56289,9 @@ var SearchModule = class {
56289
56289
  this.bookSearchResult = [];
56290
56290
  reset();
56291
56291
  await this.searchAndPaintChapter(term, 0, async () => {
56292
+ if (this.navigator.rights.enableContentProtection) {
56293
+ this.navigator.contentProtectionModule?.recalculate(200);
56294
+ }
56292
56295
  });
56293
56296
  if (current) {
56294
56297
  await this.searchBook(term);
@@ -56326,6 +56329,9 @@ var SearchModule = class {
56326
56329
  this.navigator.navigate(position);
56327
56330
  setTimeout(() => {
56328
56331
  this.searchAndPaintChapter(item.textMatch, filteredIndex, async () => {
56332
+ if (this.navigator.rights.enableContentProtection) {
56333
+ this.navigator.contentProtectionModule?.recalculate(200);
56334
+ }
56329
56335
  });
56330
56336
  }, 300);
56331
56337
  }
@@ -56357,6 +56363,9 @@ var SearchModule = class {
56357
56363
  this.navigator.navigate(position);
56358
56364
  setTimeout(() => {
56359
56365
  this.searchAndPaintChapter(item.textMatch, filteredIndex, async () => {
56366
+ if (this.navigator.rights.enableContentProtection) {
56367
+ this.navigator.contentProtectionModule?.recalculate(200);
56368
+ }
56360
56369
  });
56361
56370
  }, 300);
56362
56371
  }
@@ -57464,11 +57473,6 @@ var TTSModule2 = class {
57464
57473
  let doc = this.navigator.iframes[0].contentDocument;
57465
57474
  if (doc) {
57466
57475
  let selection = this.highlighter.dom(doc.body).getSelection();
57467
- if (selection.isCollapsed) {
57468
- let doc2 = this.navigator.iframes[0].contentDocument;
57469
- const selectionInfo = this.navigator.annotationModule?.annotator?.getTemporarySelectionInfo(doc2);
57470
- selection.addRange(selectionInfo.range);
57471
- }
57472
57476
  let range = selection.getRangeAt(0);
57473
57477
  let node = selection.anchorNode;
57474
57478
  while (range.toString().indexOf(" ") !== 0) {
@@ -57551,6 +57555,11 @@ var TTSModule2 = class {
57551
57555
  }
57552
57556
  }
57553
57557
  async speak(selectionInfo, partial, callback) {
57558
+ if (!partial) {
57559
+ if (this.navigator.rights.enableContentProtection) {
57560
+ this.navigator.contentProtectionModule?.deactivate();
57561
+ }
57562
+ }
57554
57563
  if (this.api?.started)
57555
57564
  this.api?.started();
57556
57565
  this.navigator.emit("readaloud.started", "started");
@@ -57607,6 +57616,10 @@ var TTSModule2 = class {
57607
57616
  restOfTheText = restOfTheText.replace(textToBeSpoken, "").trim();
57608
57617
  }
57609
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);
57610
57623
  import_loglevel18.default.log(selectionInfo);
57611
57624
  import_loglevel18.default.log(textToBeSpoken, selectionInfo.range?.commonAncestorContainer.textContent);
57612
57625
  import_loglevel18.default.log(ttsQueueItem);
@@ -57629,19 +57642,85 @@ var TTSModule2 = class {
57629
57642
  utterance.rate = this.tts.rate;
57630
57643
  utterance.pitch = this.tts.pitch;
57631
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) {
57632
57711
  import_loglevel18.default.log("this.tts.voice.lang", this.tts.voice.lang);
57633
- var initialVoiceHasHyphen = true;
57712
+ let initialVoiceHasHyphen = true;
57634
57713
  if (this.tts.voice && this.tts.voice.lang) {
57635
57714
  initialVoiceHasHyphen = this.tts.voice.lang.indexOf("-") !== -1;
57636
- if (initialVoiceHasHyphen === false) {
57715
+ if (!initialVoiceHasHyphen) {
57637
57716
  this.tts.voice.lang = this.tts.voice.lang.replace("_", "-");
57638
57717
  initialVoiceHasHyphen = true;
57639
57718
  }
57640
57719
  }
57641
57720
  import_loglevel18.default.log("initialVoiceHasHyphen", initialVoiceHasHyphen);
57642
57721
  import_loglevel18.default.log("voices", this.voices);
57643
- var initialVoice;
57644
- if (initialVoiceHasHyphen === true) {
57722
+ let initialVoice;
57723
+ if (initialVoiceHasHyphen) {
57645
57724
  initialVoice = this.tts.voice && this.tts.voice.lang && this.tts.voice.name ? this.voices.filter((v) => {
57646
57725
  var lang = v.lang.replace("_", "-");
57647
57726
  return lang === this.tts.voice.lang && v.name === this.tts.voice.name;
@@ -57658,10 +57737,10 @@ var TTSModule2 = class {
57658
57737
  }
57659
57738
  }
57660
57739
  import_loglevel18.default.log("initialVoice", initialVoice);
57661
- var publicationVoiceHasHyphen = self2.navigator.publication.Metadata.Language[0].indexOf("-") !== -1;
57740
+ const publicationVoiceHasHyphen = self2.navigator.publication.Metadata.Language[0].indexOf("-") !== -1;
57662
57741
  import_loglevel18.default.log("publicationVoiceHasHyphen", publicationVoiceHasHyphen);
57663
- var publicationVoice;
57664
- if (publicationVoiceHasHyphen === true) {
57742
+ let publicationVoice;
57743
+ if (publicationVoiceHasHyphen) {
57665
57744
  publicationVoice = this.tts.voice && this.tts.voice.usePublication ? this.voices.filter((v) => {
57666
57745
  var lang = v.lang.replace("_", "-");
57667
57746
  return lang.startsWith(self2.navigator.publication.Metadata.Language[0]) || lang.endsWith(self2.navigator.publication.Metadata.Language[0].toUpperCase());
@@ -57672,24 +57751,24 @@ var TTSModule2 = class {
57672
57751
  })[0] : void 0;
57673
57752
  }
57674
57753
  import_loglevel18.default.log("publicationVoice", publicationVoice);
57675
- var defaultVoiceHasHyphen = navigator.language.indexOf("-") !== -1;
57754
+ const defaultVoiceHasHyphen = navigator.language.indexOf("-") !== -1;
57676
57755
  import_loglevel18.default.log("defaultVoiceHasHyphen", defaultVoiceHasHyphen);
57677
- var defaultVoice;
57678
- if (defaultVoiceHasHyphen === true) {
57756
+ let defaultVoice;
57757
+ if (defaultVoiceHasHyphen) {
57679
57758
  defaultVoice = this.voices.filter((voice) => {
57680
- var lang = voice.lang.replace("_", "-");
57681
- return lang === navigator.language && voice.localService === true;
57759
+ const lang = voice.lang.replace("_", "-");
57760
+ return lang === navigator.language && voice.localService;
57682
57761
  })[0];
57683
57762
  } else {
57684
57763
  defaultVoice = this.voices.filter((voice) => {
57685
- var lang = voice.lang;
57686
- return lang === navigator.language && voice.localService === true;
57764
+ const lang = voice.lang;
57765
+ return lang === navigator.language && voice.localService;
57687
57766
  })[0];
57688
57767
  }
57689
57768
  if (defaultVoice === void 0) {
57690
57769
  defaultVoice = this.voices.filter((voice) => {
57691
- var lang = voice.lang;
57692
- return lang.includes(navigator.language) && voice.localService === true;
57770
+ const lang = voice.lang;
57771
+ return lang.includes(navigator.language) && voice.localService;
57693
57772
  })[0];
57694
57773
  }
57695
57774
  import_loglevel18.default.log("defaultVoice", defaultVoice);
@@ -57709,58 +57788,11 @@ var TTSModule2 = class {
57709
57788
  import_loglevel18.default.log("utterance.lang", utterance.lang);
57710
57789
  }
57711
57790
  import_loglevel18.default.log("navigator.language", navigator.language);
57712
- setTimeout(() => {
57713
- window.speechSynthesis.speak(utterance);
57714
- }, 0);
57715
- this.index = 0;
57716
- function onend() {
57717
- utterance.onend = function() {
57718
- if (idxEnd > idx) {
57719
- idx = idx + 1;
57720
- if (idx !== idxEnd) {
57721
- const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
57722
- if (ttsQueueItem) {
57723
- const sentence = getTtsQueueItemRefText(ttsQueueItem);
57724
- utterance = new SpeechSynthesisUtterance(sentence);
57725
- utterance.onboundary = (ev) => {
57726
- self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
57727
- };
57728
- setTimeout(() => {
57729
- window.speechSynthesis.speak(utterance);
57730
- }, 0);
57731
- onend();
57732
- }
57733
- } else {
57734
- const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
57735
- if (ttsQueueItem) {
57736
- utterance = new SpeechSynthesisUtterance(restOfTheText);
57737
- utterance.onboundary = (ev) => {
57738
- self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
57739
- };
57740
- setTimeout(() => {
57741
- window.speechSynthesis.speak(utterance);
57742
- }, 0);
57743
- onend();
57744
- }
57745
- if (idx > idxEnd) {
57746
- import_loglevel18.default.log("utterance ended");
57747
- self2.highlighter.doneSpeaking();
57748
- self2.api?.finished();
57749
- self2.navigator.emit("readaloud.finished", "finished");
57750
- }
57751
- }
57752
- } else {
57753
- import_loglevel18.default.log("utterance ended");
57754
- self2.highlighter.doneSpeaking();
57755
- self2.api?.finished();
57756
- self2.navigator.emit("readaloud.finished", "finished");
57757
- }
57758
- };
57759
- }
57760
- onend();
57761
- callback();
57762
57791
  }
57763
57792
  speakPlay() {
57793
+ if (this.navigator.rights.enableContentProtection) {
57794
+ this.navigator.contentProtectionModule?.deactivate();
57795
+ }
57764
57796
  this.scrollPartial = true;
57765
57797
  this.cancel(false);
57766
57798
  if (this.api?.started)
@@ -57810,6 +57842,9 @@ var TTSModule2 = class {
57810
57842
  this.startTTSSession(ttsQueue, ttsQueueIndex);
57811
57843
  }, 200);
57812
57844
  }
57845
+ if (this.navigator.rights.enableContentProtection) {
57846
+ this.navigator.contentProtectionModule?.recalculate(200);
57847
+ }
57813
57848
  }
57814
57849
  speakPause() {
57815
57850
  if (window.speechSynthesis.speaking) {
@@ -58024,87 +58059,8 @@ var TTSModule2 = class {
58024
58059
  utterance.rate = this.tts.rate;
58025
58060
  utterance.pitch = this.tts.pitch;
58026
58061
  utterance.volume = this.tts.volume;
58027
- import_loglevel18.default.log("this.tts.voice.lang", this.tts.voice.lang);
58028
- var initialVoiceHasHyphen = true;
58029
- if (this.tts.voice && this.tts.voice.lang) {
58030
- initialVoiceHasHyphen = this.tts.voice.lang.indexOf("-") !== -1;
58031
- if (initialVoiceHasHyphen === false) {
58032
- this.tts.voice.lang = this.tts.voice.lang.replace("_", "-");
58033
- initialVoiceHasHyphen = true;
58034
- }
58035
- }
58036
- import_loglevel18.default.log("initialVoiceHasHyphen", initialVoiceHasHyphen);
58037
- import_loglevel18.default.log("voices", this.voices);
58038
- var initialVoice;
58039
- if (initialVoiceHasHyphen === true) {
58040
- initialVoice = this.tts.voice && this.tts.voice.lang && this.tts.voice.name ? this.voices.filter((v) => {
58041
- var lang = v.lang.replace("_", "-");
58042
- return lang === this.tts.voice.lang && v.name === this.tts.voice.name;
58043
- })[0] : void 0;
58044
- if (initialVoice === void 0) {
58045
- initialVoice = this.tts.voice && this.tts.voice.lang ? this.voices.filter((v) => v.lang.replace("_", "-") === this.tts.voice.lang)[0] : void 0;
58046
- }
58047
- } else {
58048
- initialVoice = this.tts.voice && this.tts.voice.lang && this.tts.voice.name ? this.voices.filter((v) => {
58049
- return v.lang === this.tts.voice.lang && v.name === this.tts.voice.name;
58050
- })[0] : void 0;
58051
- if (initialVoice === void 0) {
58052
- initialVoice = this.tts.voice && this.tts.voice.lang ? this.voices.filter((v) => v.lang === this.tts.voice.lang)[0] : void 0;
58053
- }
58054
- }
58055
- import_loglevel18.default.log("initialVoice", initialVoice);
58056
- var self2 = this;
58057
- var publicationVoiceHasHyphen = self2.navigator.publication.Metadata.Language[0].indexOf("-") !== -1;
58058
- import_loglevel18.default.log("publicationVoiceHasHyphen", publicationVoiceHasHyphen);
58059
- var publicationVoice;
58060
- if (publicationVoiceHasHyphen === true) {
58061
- publicationVoice = this.tts.voice && this.tts.voice.usePublication ? this.voices.filter((v) => {
58062
- var lang = v.lang.replace("_", "-");
58063
- return lang.startsWith(self2.navigator.publication.Metadata.Language[0]) || lang.endsWith(self2.navigator.publication.Metadata.Language[0].toUpperCase());
58064
- })[0] : void 0;
58065
- } else {
58066
- publicationVoice = this.tts.voice && this.tts.voice.usePublication ? this.voices.filter((v) => {
58067
- return v.lang.startsWith(self2.navigator.publication.Metadata.Language[0]) || v.lang.endsWith(self2.navigator.publication.Metadata.Language[0].toUpperCase());
58068
- })[0] : void 0;
58069
- }
58070
- import_loglevel18.default.log("publicationVoice", publicationVoice);
58071
- var defaultVoiceHasHyphen = navigator.language.indexOf("-") !== -1;
58072
- import_loglevel18.default.log("defaultVoiceHasHyphen", defaultVoiceHasHyphen);
58073
- var defaultVoice;
58074
- if (defaultVoiceHasHyphen === true) {
58075
- defaultVoice = this.voices.filter((voice) => {
58076
- var lang = voice.lang.replace("_", "-");
58077
- return lang === navigator.language && voice.localService === true;
58078
- })[0];
58079
- } else {
58080
- defaultVoice = this.voices.filter((voice) => {
58081
- var lang = voice.lang;
58082
- return lang === navigator.language && voice.localService === true;
58083
- })[0];
58084
- }
58085
- if (defaultVoice === void 0) {
58086
- defaultVoice = this.voices.filter((voice) => {
58087
- var lang = voice.lang;
58088
- return lang.includes(navigator.language) && voice.localService === true;
58089
- })[0];
58090
- }
58091
- import_loglevel18.default.log("defaultVoice", defaultVoice);
58092
- if (initialVoice) {
58093
- import_loglevel18.default.log("initialVoice");
58094
- utterance.voice = initialVoice;
58095
- } else if (publicationVoice) {
58096
- import_loglevel18.default.log("publicationVoice");
58097
- utterance.voice = publicationVoice;
58098
- } else if (defaultVoice) {
58099
- import_loglevel18.default.log("defaultVoice");
58100
- utterance.voice = defaultVoice;
58101
- }
58102
- if (utterance.voice !== void 0 && utterance.voice !== null) {
58103
- utterance.lang = utterance.voice.lang;
58104
- import_loglevel18.default.log("utterance.voice.lang", utterance.voice.lang);
58105
- import_loglevel18.default.log("utterance.lang", utterance.lang);
58106
- }
58107
- import_loglevel18.default.log("navigator.language", navigator.language);
58062
+ const self2 = this;
58063
+ this.setVoice(self2, utterance);
58108
58064
  utterance.onboundary = (ev) => {
58109
58065
  import_loglevel18.default.log(ev.name);
58110
58066
  this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
@@ -58199,7 +58155,7 @@ var TTSModule2 = class {
58199
58155
  const range = new Range();
58200
58156
  range.setStart(rangeStartNode, rangeStartOffset);
58201
58157
  range.setEnd(rangeEndNode, rangeEndOffset);
58202
- var self2 = this;
58158
+ const self2 = this;
58203
58159
  const rangeInfo = convertRange(range, getCssSelector);
58204
58160
  if (!rangeInfo) {
58205
58161
  return;