@d-i-t-a/reader 2.0.0-beta.11 → 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) {
@@ -52688,7 +52688,7 @@ var MediaOverlayModule = class {
52688
52688
  console.log("ontimeupdate");
52689
52689
  this.trackCurrentTime();
52690
52690
  };
52691
- this.ensureOnTimeUpdate = (remove) => {
52691
+ this.ensureOnTimeUpdate = (remove, replace) => {
52692
52692
  if (this.audioElement) {
52693
52693
  if (remove) {
52694
52694
  if (this.__ontimeupdate) {
@@ -52697,8 +52697,11 @@ var MediaOverlayModule = class {
52697
52697
  cancelAnimationFrame(this.myReq);
52698
52698
  }
52699
52699
  } else {
52700
- if (!this.__ontimeupdate) {
52700
+ if (!this.__ontimeupdate || replace) {
52701
52701
  this.__ontimeupdate = true;
52702
+ if (replace) {
52703
+ this.audioElement.removeEventListener("timeupdate", this.ontimeupdate);
52704
+ }
52702
52705
  this.audioElement.addEventListener("timeupdate", this.ontimeupdate);
52703
52706
  }
52704
52707
  }
@@ -52742,7 +52745,7 @@ var MediaOverlayModule = class {
52742
52745
  async playLink() {
52743
52746
  let link = this.currentLinks[this.currentLinkIndex];
52744
52747
  if (link?.Properties?.MediaOverlay) {
52745
- this.ensureOnTimeUpdate(false);
52748
+ this.ensureOnTimeUpdate(false, false);
52746
52749
  const moUrl = link.Properties?.MediaOverlay;
52747
52750
  const moUrlObjFull = new URL(moUrl, this.publication.manifestUrl);
52748
52751
  const moUrlFull = moUrlObjFull.toString();
@@ -52797,6 +52800,7 @@ var MediaOverlayModule = class {
52797
52800
  const timeToSeekTo = this.currentAudioBegin ? this.currentAudioBegin : 0;
52798
52801
  this.audioElement.currentTime = timeToSeekTo;
52799
52802
  await this.audioElement.play();
52803
+ this.ensureOnTimeUpdate(false, true);
52800
52804
  this.audioElement.volume = this.settings.volume;
52801
52805
  this.audioElement.playbackRate = this.settings.rate;
52802
52806
  } else {
@@ -53110,25 +53114,22 @@ var MediaOverlayModule = class {
53110
53114
  if (IS_DEV) {
53111
53115
  console.log("playMediaOverlaysAudio() - playClip() - _currentAudioElement.play()");
53112
53116
  }
53113
- this.ensureOnTimeUpdate(false);
53117
+ this.ensureOnTimeUpdate(false, false);
53114
53118
  this.audioElement.playbackRate = this.settings.rate;
53115
53119
  this.audioElement.volume = this.settings.volume;
53116
53120
  if (this.settings.playing) {
53117
- if (!initial) {
53118
- let checkReady = function() {
53119
- if (!self2.settings.resourceReady) {
53120
- setTimeout(checkReady, 200);
53121
- } else {
53122
- setTimeout(async () => {
53123
- await self2.audioElement.play();
53124
- }, self2.settings.wait * 1200);
53125
- }
53126
- };
53127
- let self2 = this;
53128
- checkReady();
53129
- } else {
53130
- await this.audioElement.play();
53131
- }
53121
+ let checkReady = function() {
53122
+ if (!self2.settings.resourceReady) {
53123
+ setTimeout(checkReady, 200);
53124
+ } else {
53125
+ setTimeout(async () => {
53126
+ await self2.audioElement.play();
53127
+ self2.ensureOnTimeUpdate(false, true);
53128
+ }, self2.settings.wait * 1e3);
53129
+ }
53130
+ };
53131
+ let self2 = this;
53132
+ checkReady();
53132
53133
  }
53133
53134
  } else {
53134
53135
  if (IS_DEV) {
@@ -53139,26 +53140,23 @@ var MediaOverlayModule = class {
53139
53140
  if (IS_DEV) {
53140
53141
  console.log("playMediaOverlaysAudio() - playClip() - ontimeupdateSeeked - .play()");
53141
53142
  }
53142
- this.ensureOnTimeUpdate(false);
53143
+ this.ensureOnTimeUpdate(false, false);
53143
53144
  if (this.audioElement) {
53144
53145
  this.audioElement.playbackRate = this.settings.rate;
53145
53146
  this.audioElement.volume = this.settings.volume;
53146
53147
  if (this.settings.playing) {
53147
- if (!initial) {
53148
- let checkReady = function() {
53149
- if (!self2.settings.resourceReady) {
53150
- setTimeout(checkReady, 200);
53151
- } else {
53152
- setTimeout(async () => {
53153
- await self2.audioElement.play();
53154
- }, self2.settings.wait * 1200);
53155
- }
53156
- };
53157
- let self2 = this;
53158
- checkReady();
53159
- } else {
53160
- await this.audioElement.play();
53161
- }
53148
+ let checkReady = function() {
53149
+ if (!self2.settings.resourceReady) {
53150
+ setTimeout(checkReady, 200);
53151
+ } else {
53152
+ setTimeout(async () => {
53153
+ await self2.audioElement.play();
53154
+ self2.ensureOnTimeUpdate(false, true);
53155
+ }, self2.settings.wait * 1e3);
53156
+ }
53157
+ };
53158
+ let self2 = this;
53159
+ checkReady();
53162
53160
  }
53163
53161
  }
53164
53162
  };
@@ -53167,7 +53165,7 @@ var MediaOverlayModule = class {
53167
53165
  }
53168
53166
  } else {
53169
53167
  const contiguous = this.previousAudioUrl === this.currentAudioUrl && typeof this.previousAudioEnd !== "undefined" && this.previousAudioEnd > timeToSeekTo - 0.02 && this.previousAudioEnd <= timeToSeekTo && this.audioElement.currentTime >= timeToSeekTo - 0.1;
53170
- this.ensureOnTimeUpdate(false);
53168
+ this.ensureOnTimeUpdate(false, false);
53171
53169
  if (contiguous) {
53172
53170
  if (IS_DEV) {
53173
53171
  console.log("playMediaOverlaysAudio() - playClip() - ensureOnTimeUpdate");
@@ -53816,18 +53814,25 @@ var ContentProtectionModule = class {
53816
53814
  }
53817
53815
  }
53818
53816
  recalculate(delay2 = 0) {
53819
- if (this.properties?.enableObfuscation) {
53820
- const onDoResize = (0, import_debounce3.debounce)(() => {
53821
- this.calcRects(this.rects);
53822
- if (this.rects !== void 0) {
53823
- this.rects.forEach((rect) => this.toggleRect(rect, this.securityContainer, this.isHacked));
53817
+ return new Promise((resolve) => {
53818
+ if (this.properties?.enableObfuscation) {
53819
+ const onDoResize = (0, import_debounce3.debounce)(() => {
53820
+ this.calcRects(this.rects);
53821
+ if (this.rects !== void 0) {
53822
+ this.rects.forEach((rect) => this.toggleRect(rect, this.securityContainer, this.isHacked));
53823
+ }
53824
+ resolve(true);
53825
+ }, delay2);
53826
+ if (this.rects) {
53827
+ this.observe();
53828
+ onDoResize();
53829
+ } else {
53830
+ resolve(false);
53824
53831
  }
53825
- }, delay2);
53826
- if (this.rects) {
53827
- this.observe();
53828
- onDoResize();
53832
+ } else {
53833
+ resolve(false);
53829
53834
  }
53830
- }
53835
+ });
53831
53836
  }
53832
53837
  calcRects(rects) {
53833
53838
  if (rects !== void 0) {
@@ -56110,6 +56115,11 @@ var IFrameNavigator = class extends import_events.default {
56110
56115
  this.view?.goToProgression(bookViewPosition);
56111
56116
  }
56112
56117
  this.newPosition = void 0;
56118
+ if (this.rights?.enableContentProtection) {
56119
+ if (this.contentProtectionModule !== void 0) {
56120
+ await this.contentProtectionModule.recalculate(10);
56121
+ }
56122
+ }
56113
56123
  this.hideLoadingMessage();
56114
56124
  this.showIframeContents();
56115
56125
  if (this.rights.enableMediaOverlays && this.mediaOverlayModule !== void 0 && this.hasMediaOverlays) {
@@ -58739,10 +58749,12 @@ var TTSModule2 = class {
58739
58749
  }
58740
58750
  });
58741
58751
  }
58742
- cancel() {
58743
- if (this.api?.stopped)
58744
- this.api?.stopped();
58745
- 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
+ }
58746
58758
  this.userScrolled = false;
58747
58759
  this.speaking = false;
58748
58760
  setTimeout(() => {
@@ -58759,7 +58771,7 @@ var TTSModule2 = class {
58759
58771
  this.delegate.emit("readaloud.started", "started");
58760
58772
  const self2 = this;
58761
58773
  this.userScrolled = false;
58762
- this.cancel();
58774
+ this.cancel(false);
58763
58775
  let utterance;
58764
58776
  if (partial) {
58765
58777
  let iframe = document.querySelector("main#iframe-wrapper iframe");
@@ -58899,7 +58911,9 @@ var TTSModule2 = class {
58899
58911
  callback();
58900
58912
  }
58901
58913
  speakPlay() {
58902
- this.cancel();
58914
+ this.cancel(false);
58915
+ if (this.api?.started)
58916
+ this.api?.started();
58903
58917
  this.delegate.emit("readaloud.started", "started");
58904
58918
  let self2 = this;
58905
58919
  let iframe = document.querySelector("main#iframe-wrapper iframe");
@@ -58909,47 +58923,27 @@ var TTSModule2 = class {
58909
58923
  let node = self2.highlighter.visibleTextRects[0];
58910
58924
  let doc = self2.delegate.iframes[0].contentDocument;
58911
58925
  if (doc) {
58912
- let isOutsideViewport = function(rect) {
58913
- const windowLeft = window.scrollX;
58914
- const windowRight = windowLeft + window.innerWidth;
58915
- const right = rect.left + rect.width;
58916
- const bottom = rect.top + rect.height;
58917
- const windowTop = window.scrollY;
58918
- const windowBottom = windowTop + window.innerHeight;
58919
- const isAbove = bottom < windowTop;
58920
- const isBelow = rect.top > windowBottom;
58921
- const isLeft = right < windowLeft;
58922
- const isRight = rect.left > windowRight;
58923
- return isAbove || isBelow || isLeft || isRight;
58924
- };
58925
58926
  const range = self2.highlighter.dom(doc.body).getWindow().document.createRange();
58926
58927
  const selection = self2.highlighter.dom(self2.delegate.iframes[0].contentDocument?.body).getSelection();
58927
58928
  selection.removeAllRanges();
58928
58929
  range.selectNodeContents(node.node);
58929
58930
  selection.addRange(range);
58930
- const clientRects = getClientRectsNoOverlap(range, false);
58931
58931
  let index2 = 0;
58932
- for (const rect of clientRects) {
58933
- if (!isOutsideViewport(rect)) {
58934
- const endNode = selection.focusNode;
58935
- const endOffset = selection.focusOffset;
58936
- selection.collapse(selection.anchorNode, selection.anchorOffset);
58937
- for (let i = 0; i < index2; i++) {
58938
- selection.modify("move", "forward", "line");
58939
- }
58940
- selection.extend(endNode, endOffset);
58941
- selection.collapse(selection.anchorNode, selection.anchorOffset);
58942
- if (rootEl) {
58943
- const idx = self2.findTtsQueueItemIndex(ttsQueue, selection.anchorNode, selection.focusNode, selection.focusOffset, rootEl);
58944
- if (idx >= 0) {
58945
- ttsQueueIndex = idx;
58946
- }
58947
- }
58948
- selection.removeAllRanges();
58949
- 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;
58950
58944
  }
58951
- index2++;
58952
58945
  }
58946
+ selection.removeAllRanges();
58953
58947
  }
58954
58948
  };
58955
58949
  const ttsQueue = this.generateTtsQueue(rootEl, true);
@@ -58963,7 +58957,7 @@ var TTSModule2 = class {
58963
58957
  }
58964
58958
  setTimeout(() => {
58965
58959
  this.startTTSSession(ttsQueue, ttsQueueIndex);
58966
- }, 100);
58960
+ }, 200);
58967
58961
  }
58968
58962
  }
58969
58963
  speakPause() {
@@ -59651,7 +59645,7 @@ var DefinitionsModule = class {
59651
59645
  }
59652
59646
  });
59653
59647
  }, { threshold: 1 });
59654
- if (highlightFragments) {
59648
+ if (highlightFragments && highlightFragments.length > 0) {
59655
59649
  observer.observe(highlightFragments[0]);
59656
59650
  }
59657
59651
  });