@d-i-t-a/reader 2.0.0-beta.13 → 2.0.0-beta.14

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
@@ -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 * 1200);
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 * 1200);
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 (this.api?.stopped)
58753
- this.api?.stopped();
58754
- this.delegate.emit("readaloud.stopped", "stopped");
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
- for (const rect of clientRects) {
58942
- if (!isOutsideViewport(rect)) {
58943
- const endNode = selection.focusNode;
58944
- const endOffset = selection.focusOffset;
58945
- selection.collapse(selection.anchorNode, selection.anchorOffset);
58946
- for (let i = 0; i < index2; i++) {
58947
- selection.modify("move", "forward", "line");
58948
- }
58949
- selection.extend(endNode, endOffset);
58950
- selection.collapse(selection.anchorNode, selection.anchorOffset);
58951
- if (rootEl) {
58952
- const idx = self2.findTtsQueueItemIndex(ttsQueue, selection.anchorNode, selection.focusNode, selection.focusOffset, rootEl);
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
- }, 100);
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
  });