@d-i-t-a/reader 2.1.0-beta.8 → 2.1.0-beta.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
@@ -35079,8 +35079,8 @@ var EventHandler = class {
35079
35079
  await this.popup.hidePopover();
35080
35080
  }
35081
35081
  const isInternal = link.href.indexOf("#");
35082
- if (!isSameOrigin && !isEpubInternal && !isResourceInternal) {
35083
- window.open(link.href, "_blank");
35082
+ if (!isEpubInternal && !isResourceInternal) {
35083
+ window.open(link.href, link.target ?? "_blank");
35084
35084
  event.preventDefault();
35085
35085
  event.stopPropagation();
35086
35086
  } else {
@@ -38052,7 +38052,7 @@ var TextHighlighter = class {
38052
38052
  let self2 = this;
38053
38053
  let doc = this.delegate.iframes[0].contentDocument;
38054
38054
  if (doc) {
38055
- let selection = self2.dom(doc.body)?.getWindow()?.getSelection();
38055
+ let selection = self2.dom(doc.body)?.getSelection();
38056
38056
  if (self2.dom(doc.body)) {
38057
38057
  if (selection && !selection?.isCollapsed) {
38058
38058
  let removeTrailingPunctuation = function(text2) {
@@ -38121,7 +38121,6 @@ var TextHighlighter = class {
38121
38121
  return;
38122
38122
  }
38123
38123
  if (this.isIOS()) {
38124
- this.delegate.iframes[0].contentDocument?.body.removeEventListener("selectionchange", this.toolboxPlacement.bind(this));
38125
38124
  setTimeout(function() {
38126
38125
  let doc = self2.delegate.iframes[0].contentDocument;
38127
38126
  if (doc) {
@@ -38129,6 +38128,25 @@ var TextHighlighter = class {
38129
38128
  selection.removeAllRanges();
38130
38129
  setTimeout(function() {
38131
38130
  selection.addRange(range);
38131
+ function getCssSelector(element) {
38132
+ const options = {
38133
+ className: (str) => {
38134
+ return _blacklistIdClassForCssSelectors.indexOf(str) < 0;
38135
+ },
38136
+ idName: (str) => {
38137
+ return _blacklistIdClassForCssSelectors.indexOf(str) < 0;
38138
+ }
38139
+ };
38140
+ let doc2 = self2.delegate.iframes[0].contentDocument;
38141
+ if (doc2) {
38142
+ return uniqueCssSelector(element, doc2, options);
38143
+ } else {
38144
+ return void 0;
38145
+ }
38146
+ }
38147
+ let win = self2.delegate.iframes[0].contentWindow;
38148
+ const selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38149
+ self2.delegate.annotationModule?.annotator?.saveTemporarySelectionInfo(selectionInfo);
38132
38150
  }, 5);
38133
38151
  }
38134
38152
  }, 100);
@@ -38201,7 +38219,10 @@ var TextHighlighter = class {
38201
38219
  self2.toolboxHide();
38202
38220
  highlightIcon?.removeEventListener("click", highlightEvent);
38203
38221
  };
38204
- highlightIcon.addEventListener("click", highlightEvent);
38222
+ const clone = highlightIcon.cloneNode(true);
38223
+ highlightIcon?.parentNode?.replaceChild(clone, highlightIcon);
38224
+ highlightIcon = document.getElementById("highlightIcon");
38225
+ highlightIcon?.addEventListener("click", highlightEvent);
38205
38226
  }
38206
38227
  if (underlineIcon) {
38207
38228
  let commentEvent = function() {
@@ -38209,7 +38230,10 @@ var TextHighlighter = class {
38209
38230
  self2.toolboxHide();
38210
38231
  underlineIcon?.removeEventListener("click", commentEvent);
38211
38232
  };
38212
- underlineIcon.addEventListener("click", commentEvent);
38233
+ const clone = underlineIcon.cloneNode(true);
38234
+ underlineIcon?.parentNode?.replaceChild(clone, underlineIcon);
38235
+ underlineIcon = document.getElementById("underlineIcon");
38236
+ underlineIcon?.addEventListener("click", commentEvent);
38213
38237
  }
38214
38238
  } else {
38215
38239
  if (highlightIcon) {
@@ -38231,7 +38255,10 @@ var TextHighlighter = class {
38231
38255
  speakIcon?.removeEventListener("click", speakEvent);
38232
38256
  self2.speak();
38233
38257
  };
38234
- speakIcon.addEventListener("click", speakEvent);
38258
+ const clone = speakIcon.cloneNode(true);
38259
+ speakIcon?.parentNode?.replaceChild(clone, speakIcon);
38260
+ speakIcon = document.getElementById("speakIcon");
38261
+ speakIcon?.addEventListener("click", speakEvent);
38235
38262
  }
38236
38263
  } else {
38237
38264
  if (speakIcon) {
@@ -38265,7 +38292,11 @@ var TextHighlighter = class {
38265
38292
  }
38266
38293
  let win = self3.delegate.iframes[0].contentWindow;
38267
38294
  if (win) {
38268
- const selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38295
+ let selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38296
+ if (selectionInfo === void 0) {
38297
+ let doc = self3.delegate.iframes[0].contentDocument;
38298
+ selectionInfo = self3.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc);
38299
+ }
38269
38300
  if (selectionInfo !== void 0) {
38270
38301
  if (menuItem.callback) {
38271
38302
  menuItem.callback(selectionInfo.cleanText, selectionInfo.range?.startContainer.parentElement);
@@ -38326,7 +38357,11 @@ var TextHighlighter = class {
38326
38357
  }
38327
38358
  let win = self2.delegate.iframes[0].contentWindow;
38328
38359
  if (win) {
38329
- const selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38360
+ let selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38361
+ if (selectionInfo === void 0) {
38362
+ let doc = self2.delegate.iframes[0].contentDocument;
38363
+ selectionInfo = this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc);
38364
+ }
38330
38365
  if (selectionInfo) {
38331
38366
  if (this.options.onBeforeHighlight(selectionInfo) === true) {
38332
38367
  let createColor;
@@ -38376,7 +38411,11 @@ var TextHighlighter = class {
38376
38411
  let self2 = this;
38377
38412
  let win = self2.delegate.iframes[0].contentWindow;
38378
38413
  if (win) {
38379
- const selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38414
+ let selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38415
+ if (selectionInfo === void 0) {
38416
+ let doc2 = self2.delegate.iframes[0].contentDocument;
38417
+ selectionInfo = self2.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc2);
38418
+ }
38380
38419
  if (selectionInfo !== void 0) {
38381
38420
  this.delegate.ttsModule.speak(selectionInfo, true, () => {
38382
38421
  });
@@ -40343,7 +40382,11 @@ var BookmarkModule = class {
40343
40382
  }
40344
40383
  };
40345
40384
  if (win !== null) {
40346
- const selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
40385
+ let selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
40386
+ if (selectionInfo === void 0) {
40387
+ let doc3 = self2.delegate.iframes[0].contentDocument;
40388
+ selectionInfo = this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc3);
40389
+ }
40347
40390
  let doc2 = self2.delegate.iframes[0].contentDocument;
40348
40391
  if (selectionInfo && doc2) {
40349
40392
  let book = this.delegate.highlighter?.createHighlight(this.delegate.highlighter?.dom(doc2.body).getWindow(), selectionInfo, menuItem.highlight?.color, true, AnnotationMarker.Bookmark, menuItem.icon, menuItem.popup, menuItem.highlight?.style);
@@ -45751,8 +45794,12 @@ var _LocalAnnotator = class {
45751
45794
  const uniqueStr = `${rangeRepresentation.highlight.selectionInfo.rangeInfo.startContainerElementCssSelector}${rangeRepresentation.highlight.selectionInfo.rangeInfo.startContainerChildTextNodeIndex}${rangeRepresentation.highlight.selectionInfo.rangeInfo.startOffset}${rangeRepresentation.highlight.selectionInfo.rangeInfo.endContainerElementCssSelector}${rangeRepresentation.highlight.selectionInfo.rangeInfo.endContainerChildTextNodeIndex}${rangeRepresentation.highlight.selectionInfo.rangeInfo.endOffset}`;
45752
45795
  const sha256Hex = SHA256.hash(uniqueStr);
45753
45796
  rangeRepresentation.highlight.id = "R2_HIGHLIGHT_" + sha256Hex;
45754
- var rangeColor;
45755
- rangeColor = rangeRepresentation.color;
45797
+ let rangeColor;
45798
+ if (rangeRepresentation.highlight.color) {
45799
+ rangeColor = rangeRepresentation.highlight.color;
45800
+ } else if (rangeRepresentation.color) {
45801
+ rangeColor = rangeRepresentation.color;
45802
+ }
45756
45803
  if (TextHighlighter.isHexColor(rangeColor)) {
45757
45804
  rangeColor = TextHighlighter.hexToRgbString(rangeColor);
45758
45805
  }
@@ -45764,6 +45811,21 @@ var _LocalAnnotator = class {
45764
45811
  this.store.set(_LocalAnnotator.ANNOTATIONS, JSON.stringify(annotationsToStore));
45765
45812
  return annotationsToStore;
45766
45813
  }
45814
+ saveTemporarySelectionInfo(selectionInfo) {
45815
+ this.store.set(_LocalAnnotator.SELECTIONINFO, JSON.stringify(selectionInfo));
45816
+ }
45817
+ getTemporarySelectionInfo(doc) {
45818
+ const selectionInfos = this.store.get(_LocalAnnotator.SELECTIONINFO);
45819
+ if (selectionInfos) {
45820
+ let selectionInfo = JSON.parse(selectionInfos);
45821
+ selectionInfo.range = convertRangeInfo(doc, selectionInfo.rangeInfo);
45822
+ return selectionInfo;
45823
+ }
45824
+ return [];
45825
+ }
45826
+ deleteTemporarySelectionInfo() {
45827
+ this.store.remove(_LocalAnnotator.SELECTIONINFO);
45828
+ }
45767
45829
  saveAnnotation(annotation) {
45768
45830
  let savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
45769
45831
  if (savedAnnotations) {
@@ -45814,7 +45876,7 @@ var _LocalAnnotator = class {
45814
45876
  const savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
45815
45877
  if (savedAnnotations) {
45816
45878
  const annotations = JSON.parse(savedAnnotations);
45817
- const filtered = annotations.filter((el) => el.id === id2);
45879
+ const filtered = annotations.filter((el) => el.highlight?.id === id2 || el.id === id2);
45818
45880
  if (filtered.length > 0) {
45819
45881
  let foundElement = iframeWin.document.getElementById(`${filtered[0].highlight.id}`);
45820
45882
  if (foundElement) {
@@ -45863,6 +45925,7 @@ var LocalAnnotator = _LocalAnnotator;
45863
45925
  LocalAnnotator.LAST_READING_POSITION = "last-reading-position";
45864
45926
  LocalAnnotator.BOOKMARKS = "bookmarks";
45865
45927
  LocalAnnotator.ANNOTATIONS = "annotations";
45928
+ LocalAnnotator.SELECTIONINFO = "selectionInfo";
45866
45929
 
45867
45930
  // src/store/LocalStorageStore.ts
45868
45931
  init_polyfills();
@@ -46277,7 +46340,12 @@ var TTSModule2 = class {
46277
46340
  if (window.speechSynthesis.speaking && this.speaking && startX === this.startX && startY === this.startY) {
46278
46341
  let doc = this.delegate.iframes[0].contentDocument;
46279
46342
  if (doc) {
46280
- const selection = this.highlighter.dom(doc.body).getSelection();
46343
+ let selection = this.highlighter.dom(doc.body).getSelection();
46344
+ if (selection.isCollapsed) {
46345
+ let doc2 = this.delegate.iframes[0].contentDocument;
46346
+ const selectionInfo = this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc2);
46347
+ selection.addRange(selectionInfo.range);
46348
+ }
46281
46349
  let range = selection.getRangeAt(0);
46282
46350
  let node = selection.anchorNode;
46283
46351
  while (range.toString().indexOf(" ") !== 0) {
@@ -46372,15 +46440,20 @@ var TTSModule2 = class {
46372
46440
  let rootEl = iframe.contentWindow?.document.body;
46373
46441
  let doc = this.delegate.iframes[0].contentDocument;
46374
46442
  if (doc) {
46375
- const selection = this.highlighter.dom(doc.body).getSelection();
46443
+ let selection = this.highlighter.dom(doc.body).getSelection();
46444
+ if (selection.isCollapsed) {
46445
+ let doc2 = self2.delegate.iframes[0].contentDocument;
46446
+ const selectionInfo2 = self2.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc2);
46447
+ selection.addRange(selectionInfo2.range);
46448
+ }
46376
46449
  if (rootEl) {
46377
46450
  var ttsQueue = this.generateTtsQueue(rootEl);
46378
46451
  if (!ttsQueue.length) {
46379
46452
  return;
46380
46453
  }
46381
46454
  var idx = this.findTtsQueueItemIndex(ttsQueue, selection.anchorNode, selection.anchorNode, selection.anchorOffset, rootEl);
46382
- const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
46383
46455
  var idxEnd = this.findTtsQueueItemIndex(ttsQueue, selection.focusNode, selection.focusNode, selection.focusOffset, rootEl);
46456
+ const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
46384
46457
  const ttsQueueItemEnd = getTtsQueueItemRef(ttsQueue, idxEnd);
46385
46458
  var restOfTheText;
46386
46459
  if (ttsQueueItem && selectionInfo && selectionInfo.cleanText) {
@@ -46417,22 +46490,12 @@ var TTSModule2 = class {
46417
46490
  import_loglevel19.default.log(ttsQueueItem.item.textNodes);
46418
46491
  import_loglevel19.default.log(startIndex);
46419
46492
  import_loglevel19.default.log(ttsQueueItem.item.combinedText);
46420
- if (!ttsQueueItem.item.combinedText?.startsWith(textToBeSpoken)) {
46421
- for (let i = 0; i < ttsQueueItem.item.textNodes.length; i++) {
46422
- let node2 = ttsQueueItem.item.textNodes[i];
46423
- if (node2 === selectionInfo.range?.commonAncestorContainer) {
46424
- break;
46425
- }
46426
- import_loglevel19.default.log(node2.length);
46427
- startIndex += node2.length;
46428
- }
46429
- }
46430
46493
  let node = ttsQueueItem.item.textNodes.filter((node2) => {
46431
46494
  return node2 === selectionInfo.range?.commonAncestorContainer;
46432
46495
  })[0];
46433
46496
  import_loglevel19.default.log(node);
46434
46497
  utterance.onboundary = (ev) => {
46435
- this.updateTTSInfo(ttsQueueItem, ev.charIndex + startIndex, ev.charLength, utterance.text);
46498
+ this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, startIndex, utterance.text);
46436
46499
  };
46437
46500
  }
46438
46501
  }
@@ -46537,7 +46600,7 @@ var TTSModule2 = class {
46537
46600
  const sentence = getTtsQueueItemRefText(ttsQueueItem);
46538
46601
  utterance = new SpeechSynthesisUtterance(sentence);
46539
46602
  utterance.onboundary = (ev) => {
46540
- self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, utterance.text);
46603
+ self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
46541
46604
  };
46542
46605
  setTimeout(() => {
46543
46606
  window.speechSynthesis.speak(utterance);
@@ -46549,7 +46612,7 @@ var TTSModule2 = class {
46549
46612
  if (ttsQueueItem) {
46550
46613
  utterance = new SpeechSynthesisUtterance(restOfTheText);
46551
46614
  utterance.onboundary = (ev) => {
46552
- self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, utterance.text);
46615
+ self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
46553
46616
  };
46554
46617
  setTimeout(() => {
46555
46618
  window.speechSynthesis.speak(utterance);
@@ -46922,7 +46985,7 @@ var TTSModule2 = class {
46922
46985
  import_loglevel19.default.log("navigator.language", navigator.language);
46923
46986
  utterance.onboundary = (ev) => {
46924
46987
  import_loglevel19.default.log(ev.name);
46925
- this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, utterance.text);
46988
+ this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
46926
46989
  };
46927
46990
  setTimeout(() => {
46928
46991
  window.speechSynthesis.speak(utterance);
@@ -46936,7 +46999,7 @@ var TTSModule2 = class {
46936
46999
  }
46937
47000
  };
46938
47001
  }
46939
- updateTTSInfo(ttsQueueItem, charIndex, charLength, utteranceText) {
47002
+ updateTTSInfo(ttsQueueItem, charIndex, charLength, startIndex, utteranceText) {
46940
47003
  if (!ttsQueueItem) {
46941
47004
  return void 0;
46942
47005
  }
@@ -46947,14 +47010,16 @@ var TTSModule2 = class {
46947
47010
  const right = utteranceText.slice(charIndex).search(/\s/);
46948
47011
  const word = right < 0 ? utteranceText.slice(start) : utteranceText.slice(start, right + charIndex);
46949
47012
  const end = start + word.length;
46950
- let useStart = false;
46951
- if (!charLength) {
47013
+ if (charLength === void 0) {
47014
+ const match = utteranceText.substring(charIndex).match(/^[a-z\d']*/i);
47015
+ if (match) {
47016
+ charLength = match[0].length;
47017
+ }
47018
+ }
47019
+ if (charLength === void 0) {
46952
47020
  charLength = word.length;
46953
- useStart = true;
46954
- } else {
46955
- useStart = false;
46956
47021
  }
46957
- this.wrapHighlightWord(ttsQueueItem, utteranceText, useStart ? start : charIndex, charLength, word, start, end);
47022
+ this.wrapHighlightWord(ttsQueueItem, utteranceText, charIndex + startIndex, charLength, word, start, end);
46958
47023
  }
46959
47024
  return ttsQueueItemText;
46960
47025
  }
@@ -46967,15 +47032,7 @@ var TTSModule2 = class {
46967
47032
  this._ttsQueueItemHighlightsWord = void 0;
46968
47033
  }
46969
47034
  const ttsQueueItem = ttsQueueItemRef.item;
46970
- let txtToCheck = ttsQueueItemRef.item.combinedText;
46971
47035
  let charIndexAdjusted = charIndex;
46972
- if (utteranceText !== txtToCheck) {
46973
- import_loglevel19.default.log("TTS utteranceText DIFF?? ", `[[${utteranceText}]]`, `[[${txtToCheck}]]`);
46974
- }
46975
- const ttsWord = utteranceText.substr(charIndex, charLength);
46976
- if (ttsWord !== word) {
46977
- import_loglevel19.default.log("TTS word DIFF?? ", `[[${ttsWord}]]`, `[[${word}]]`, `${charIndex}--${charLength}`, `${start}--${end - start}`);
46978
- }
46979
47036
  let acc = 0;
46980
47037
  let rangeStartNode;
46981
47038
  let rangeStartOffset = -1;