@d-i-t-a/reader 2.1.0-beta.8 → 2.1.0

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 {
@@ -36656,6 +36656,7 @@ var HighlightType;
36656
36656
  HighlightType2[HighlightType2["PageBreak"] = 3] = "PageBreak";
36657
36657
  HighlightType2[HighlightType2["Definition"] = 4] = "Definition";
36658
36658
  HighlightType2[HighlightType2["LineFocus"] = 5] = "LineFocus";
36659
+ HighlightType2[HighlightType2["Comment"] = 6] = "Comment";
36659
36660
  })(HighlightType || (HighlightType = {}));
36660
36661
 
36661
36662
  // src/modules/highlight/common/rect-utils.ts
@@ -37466,6 +37467,7 @@ var AnnotationMarker;
37466
37467
  AnnotationMarker2[AnnotationMarker2["Underline"] = 1] = "Underline";
37467
37468
  AnnotationMarker2[AnnotationMarker2["Bookmark"] = 2] = "Bookmark";
37468
37469
  AnnotationMarker2[AnnotationMarker2["Custom"] = 3] = "Custom";
37470
+ AnnotationMarker2[AnnotationMarker2["Comment"] = 4] = "Comment";
37469
37471
  })(AnnotationMarker || (AnnotationMarker = {}));
37470
37472
 
37471
37473
  // src/utils/IconLib.ts
@@ -37516,6 +37518,7 @@ var HighlightContainer;
37516
37518
  HighlightContainer2["R2_ID_SEARCH_CONTAINER"] = "R2_ID_SEARCH_CONTAINER";
37517
37519
  HighlightContainer2["R2_ID_DEFINITIONS_CONTAINER"] = "R2_ID_DEFINITIONS_CONTAINER";
37518
37520
  HighlightContainer2["R2_ID_LINEFOCUS_CONTAINER"] = "R2_ID_LINEFOCUS_CONTAINER";
37521
+ HighlightContainer2["R2_ID_GUTTER_RIGHT_CONTAINER"] = "R2_ID_GUTTER_RIGHT_CONTAINER";
37519
37522
  })(HighlightContainer || (HighlightContainer = {}));
37520
37523
  var CLASS_HIGHLIGHT_CONTAINER = "R2_CLASS_HIGHLIGHT_CONTAINER";
37521
37524
  var CLASS_HIGHLIGHT_BOUNDING_AREA = "R2_CLASS_HIGHLIGHT_BOUNDING_AREA";
@@ -37543,6 +37546,7 @@ var _blacklistIdClassForCssSelectors = [
37543
37546
  HighlightContainer.R2_ID_BOOKMAKRS_CONTAINER,
37544
37547
  HighlightContainer.R2_ID_DEFINITIONS_CONTAINER,
37545
37548
  HighlightContainer.R2_ID_LINEFOCUS_CONTAINER,
37549
+ HighlightContainer.R2_ID_GUTTER_RIGHT_CONTAINER,
37546
37550
  CLASS_HIGHLIGHT_CONTAINER,
37547
37551
  CLASS_HIGHLIGHT_AREA,
37548
37552
  CLASS_HIGHLIGHT_BOUNDING_AREA
@@ -37963,8 +37967,6 @@ var TextHighlighter = class {
37963
37967
  colorButton.style.position = "relative";
37964
37968
  colorButton.style.display = "unset";
37965
37969
  colorElements.push(colorButton);
37966
- const highlightIcon2 = document.getElementById("highlightIcon");
37967
- const underlineIcon = document.getElementById("underlineIcon");
37968
37970
  if (colorIcon) {
37969
37971
  colorButton.addEventListener("click", function() {
37970
37972
  self2.setColor(color);
@@ -37972,12 +37974,18 @@ var TextHighlighter = class {
37972
37974
  if (colorIconSymbol) {
37973
37975
  colorIconSymbol.style.backgroundColor = color;
37974
37976
  }
37977
+ const highlightIcon2 = document.getElementById("highlightIcon");
37978
+ const underlineIcon = document.getElementById("underlineIcon");
37979
+ const noteIcon = document.getElementById("noteIcon");
37975
37980
  if ((highlightIcon2?.getElementsByTagName?.("span").length ?? 0) > 0) {
37976
37981
  (highlightIcon2?.getElementsByTagName("span")[0]).style.background = self2.getColor();
37977
37982
  }
37978
37983
  if ((underlineIcon?.getElementsByTagName?.("span").length ?? 0) > 0) {
37979
37984
  (underlineIcon?.getElementsByTagName("span")[0]).style.borderBottomColor = self2.getColor();
37980
37985
  }
37986
+ if ((noteIcon?.getElementsByTagName?.("span").length ?? 0) > 0) {
37987
+ (noteIcon?.getElementsByTagName("span")[0]).style.borderBottomColor = self2.getColor();
37988
+ }
37981
37989
  self2.toolboxMode("add");
37982
37990
  });
37983
37991
  }
@@ -38052,7 +38060,7 @@ var TextHighlighter = class {
38052
38060
  let self2 = this;
38053
38061
  let doc = this.delegate.iframes[0].contentDocument;
38054
38062
  if (doc) {
38055
- let selection = self2.dom(doc.body)?.getWindow()?.getSelection();
38063
+ let selection = self2.dom(doc.body)?.getSelection();
38056
38064
  if (self2.dom(doc.body)) {
38057
38065
  if (selection && !selection?.isCollapsed) {
38058
38066
  let removeTrailingPunctuation = function(text2) {
@@ -38066,7 +38074,7 @@ var TextHighlighter = class {
38066
38074
  let startOffsetTemp = text.length - text.trimStart().length;
38067
38075
  let endOffsetTemp = text.length - text.trimEnd().length;
38068
38076
  let length = text.length;
38069
- var regex_symbols = /[-!$%^&*()_+|~=`{}\[\]:\/;<>?,.@#]/;
38077
+ var regex_symbols = /[-!$%^&*()_+|~=`{}[\]:/;<>?,.@#]/;
38070
38078
  text = text.replace(regex_symbols, "");
38071
38079
  startOffsetTemp = length - text.trimStart().length;
38072
38080
  text = removeTrailingPunctuation(text);
@@ -38121,7 +38129,6 @@ var TextHighlighter = class {
38121
38129
  return;
38122
38130
  }
38123
38131
  if (this.isIOS()) {
38124
- this.delegate.iframes[0].contentDocument?.body.removeEventListener("selectionchange", this.toolboxPlacement.bind(this));
38125
38132
  setTimeout(function() {
38126
38133
  let doc = self2.delegate.iframes[0].contentDocument;
38127
38134
  if (doc) {
@@ -38129,6 +38136,25 @@ var TextHighlighter = class {
38129
38136
  selection.removeAllRanges();
38130
38137
  setTimeout(function() {
38131
38138
  selection.addRange(range);
38139
+ function getCssSelector(element) {
38140
+ const options = {
38141
+ className: (str) => {
38142
+ return _blacklistIdClassForCssSelectors.indexOf(str) < 0;
38143
+ },
38144
+ idName: (str) => {
38145
+ return _blacklistIdClassForCssSelectors.indexOf(str) < 0;
38146
+ }
38147
+ };
38148
+ let doc2 = self2.delegate.iframes[0].contentDocument;
38149
+ if (doc2) {
38150
+ return uniqueCssSelector(element, doc2, options);
38151
+ } else {
38152
+ return void 0;
38153
+ }
38154
+ }
38155
+ let win = self2.delegate.iframes[0].contentWindow;
38156
+ const selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38157
+ self2.delegate.annotationModule?.annotator?.saveTemporarySelectionInfo(selectionInfo);
38132
38158
  }, 5);
38133
38159
  }
38134
38160
  }, 100);
@@ -38171,6 +38197,7 @@ var TextHighlighter = class {
38171
38197
  let highlightIcon = document.getElementById("highlightIcon");
38172
38198
  let collapseIcon = document.getElementById("collapseIcon");
38173
38199
  let underlineIcon = document.getElementById("underlineIcon");
38200
+ let noteIcon = document.getElementById("noteIcon");
38174
38201
  let colorIcon = document.getElementById("colorIcon");
38175
38202
  let speakIcon = document.getElementById("speakIcon");
38176
38203
  if (this.delegate.rights.enableAnnotations) {
@@ -38190,6 +38217,14 @@ var TextHighlighter = class {
38190
38217
  }
38191
38218
  }
38192
38219
  }
38220
+ if (noteIcon) {
38221
+ noteIcon.style.display = "unset";
38222
+ if (colorIcon) {
38223
+ if (noteIcon.getElementsByTagName("span").length > 0) {
38224
+ noteIcon.getElementsByTagName("span")[0].style.borderBottomColor = this.getColor();
38225
+ }
38226
+ }
38227
+ }
38193
38228
  if (colorIcon) {
38194
38229
  colorIcon.style.display = "unset";
38195
38230
  let colorIconSymbol = colorIcon.lastChild;
@@ -38201,7 +38236,10 @@ var TextHighlighter = class {
38201
38236
  self2.toolboxHide();
38202
38237
  highlightIcon?.removeEventListener("click", highlightEvent);
38203
38238
  };
38204
- highlightIcon.addEventListener("click", highlightEvent);
38239
+ const clone = highlightIcon.cloneNode(true);
38240
+ highlightIcon?.parentNode?.replaceChild(clone, highlightIcon);
38241
+ highlightIcon = document.getElementById("highlightIcon");
38242
+ highlightIcon?.addEventListener("click", highlightEvent);
38205
38243
  }
38206
38244
  if (underlineIcon) {
38207
38245
  let commentEvent = function() {
@@ -38209,7 +38247,21 @@ var TextHighlighter = class {
38209
38247
  self2.toolboxHide();
38210
38248
  underlineIcon?.removeEventListener("click", commentEvent);
38211
38249
  };
38212
- underlineIcon.addEventListener("click", commentEvent);
38250
+ const clone = underlineIcon.cloneNode(true);
38251
+ underlineIcon?.parentNode?.replaceChild(clone, underlineIcon);
38252
+ underlineIcon = document.getElementById("underlineIcon");
38253
+ underlineIcon?.addEventListener("click", commentEvent);
38254
+ }
38255
+ if (noteIcon) {
38256
+ let commentEvent = function() {
38257
+ self2.doHighlight(false, AnnotationMarker.Comment);
38258
+ self2.toolboxHide();
38259
+ noteIcon?.removeEventListener("click", commentEvent);
38260
+ };
38261
+ const clone = noteIcon.cloneNode(true);
38262
+ noteIcon?.parentNode?.replaceChild(clone, noteIcon);
38263
+ noteIcon = document.getElementById("noteIcon");
38264
+ noteIcon?.addEventListener("click", commentEvent);
38213
38265
  }
38214
38266
  } else {
38215
38267
  if (highlightIcon) {
@@ -38218,6 +38270,9 @@ var TextHighlighter = class {
38218
38270
  if (underlineIcon) {
38219
38271
  underlineIcon.style.setProperty("display", "none");
38220
38272
  }
38273
+ if (noteIcon) {
38274
+ noteIcon.style.setProperty("display", "none");
38275
+ }
38221
38276
  if (colorIcon) {
38222
38277
  colorIcon.style.setProperty("display", "none");
38223
38278
  }
@@ -38231,7 +38286,10 @@ var TextHighlighter = class {
38231
38286
  speakIcon?.removeEventListener("click", speakEvent);
38232
38287
  self2.speak();
38233
38288
  };
38234
- speakIcon.addEventListener("click", speakEvent);
38289
+ const clone = speakIcon.cloneNode(true);
38290
+ speakIcon?.parentNode?.replaceChild(clone, speakIcon);
38291
+ speakIcon = document.getElementById("speakIcon");
38292
+ speakIcon?.addEventListener("click", speakEvent);
38235
38293
  }
38236
38294
  } else {
38237
38295
  if (speakIcon) {
@@ -38243,7 +38301,7 @@ var TextHighlighter = class {
38243
38301
  if (menuItem.icon) {
38244
38302
  menuItem.icon.id = menuItem.id;
38245
38303
  }
38246
- const itemElement = document.getElementById(menuItem.id);
38304
+ let itemElement = document.getElementById(menuItem.id);
38247
38305
  const self3 = this;
38248
38306
  function itemEvent() {
38249
38307
  itemElement?.removeEventListener("click", itemEvent);
@@ -38265,7 +38323,11 @@ var TextHighlighter = class {
38265
38323
  }
38266
38324
  let win = self3.delegate.iframes[0].contentWindow;
38267
38325
  if (win) {
38268
- const selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38326
+ let selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38327
+ if (selectionInfo === void 0) {
38328
+ let doc = self3.delegate.iframes[0].contentDocument;
38329
+ selectionInfo = self3.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc);
38330
+ }
38269
38331
  if (selectionInfo !== void 0) {
38270
38332
  if (menuItem.callback) {
38271
38333
  menuItem.callback(selectionInfo.cleanText, selectionInfo.range?.startContainer.parentElement);
@@ -38281,11 +38343,12 @@ var TextHighlighter = class {
38281
38343
  self3.delegate.annotationModule?.saveAnnotation(highlight[0]).then((anno) => {
38282
38344
  if (menuItem?.note) {
38283
38345
  if (anno.highlight) {
38284
- anno.highlight.note = prompt("Add your note here:");
38346
+ self3.delegate.annotationModule?.api?.addCommentToAnnotation(anno).then((result) => {
38347
+ self3.delegate.annotationModule?.updateAnnotation(result).then(async () => {
38348
+ import_loglevel5.default.log("update highlight " + result.id);
38349
+ });
38350
+ });
38285
38351
  }
38286
- self3.delegate.annotationModule?.updateAnnotation(anno).then(async () => {
38287
- import_loglevel5.default.log("update highlight " + anno.id);
38288
- });
38289
38352
  }
38290
38353
  });
38291
38354
  } else if (self3.delegate.rights.enableBookmarks) {
@@ -38299,7 +38362,10 @@ var TextHighlighter = class {
38299
38362
  self3.callbackComplete();
38300
38363
  }
38301
38364
  if (itemElement) {
38302
- itemElement.addEventListener("click", itemEvent);
38365
+ const clone = itemElement.cloneNode(true);
38366
+ itemElement?.parentNode?.replaceChild(clone, itemElement);
38367
+ itemElement = document.getElementById(menuItem.id);
38368
+ itemElement?.addEventListener("click", itemEvent);
38303
38369
  }
38304
38370
  });
38305
38371
  }
@@ -38326,7 +38392,11 @@ var TextHighlighter = class {
38326
38392
  }
38327
38393
  let win = self2.delegate.iframes[0].contentWindow;
38328
38394
  if (win) {
38329
- const selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38395
+ let selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38396
+ if (selectionInfo === void 0) {
38397
+ let doc = self2.delegate.iframes[0].contentDocument;
38398
+ selectionInfo = this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc);
38399
+ }
38330
38400
  if (selectionInfo) {
38331
38401
  if (this.options.onBeforeHighlight(selectionInfo) === true) {
38332
38402
  let createColor;
@@ -38376,7 +38446,11 @@ var TextHighlighter = class {
38376
38446
  let self2 = this;
38377
38447
  let win = self2.delegate.iframes[0].contentWindow;
38378
38448
  if (win) {
38379
- const selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38449
+ let selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
38450
+ if (selectionInfo === void 0) {
38451
+ let doc2 = self2.delegate.iframes[0].contentDocument;
38452
+ selectionInfo = self2.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc2);
38453
+ }
38380
38454
  if (selectionInfo !== void 0) {
38381
38455
  this.delegate.ttsModule.speak(selectionInfo, true, () => {
38382
38456
  });
@@ -38665,7 +38739,7 @@ var TextHighlighter = class {
38665
38739
  highlightArea.classList.remove("hover");
38666
38740
  }
38667
38741
  }
38668
- } else if (highlight.marker === AnnotationMarker.Underline) {
38742
+ } else if (highlight.marker === AnnotationMarker.Underline || highlight.marker === AnnotationMarker.Comment) {
38669
38743
  if (typeof highlight.color === "object") {
38670
38744
  let color = highlight.color;
38671
38745
  highlightArea.style.setProperty("background-color", `rgba(${color.red}, ${color.green}, ${color.blue}, ${0})`, "important");
@@ -38739,7 +38813,7 @@ var TextHighlighter = class {
38739
38813
  highlightArea.classList.add("hover");
38740
38814
  }
38741
38815
  }
38742
- } else if (highlight.marker === AnnotationMarker.Underline) {
38816
+ } else if (highlight.marker === AnnotationMarker.Underline || highlight.marker === AnnotationMarker.Comment) {
38743
38817
  if (typeof highlight.color === "object") {
38744
38818
  let color = highlight.color;
38745
38819
  highlightArea.style.setProperty("background-color", `rgba(${color.red}, ${color.green}, ${color.blue}, ${0.1})`, "important");
@@ -38946,19 +39020,20 @@ var TextHighlighter = class {
38946
39020
  toolbox.style.left = ev.clientX + "px";
38947
39021
  if (getComputedStyle(toolbox).display === "none") {
38948
39022
  let noteH = function() {
38949
- anno.highlight.note = prompt("Add your note here:");
38950
- self2.delegate.annotationModule?.updateAnnotation(anno).then(async () => {
38951
- import_loglevel5.default.log("update highlight " + anno.id);
39023
+ self2.delegate.annotationModule?.api?.addCommentToAnnotation(anno).then((result) => {
39024
+ self2.delegate.annotationModule?.updateAnnotation(result).then(async () => {
39025
+ import_loglevel5.default.log("update highlight " + result.id);
39026
+ if (toolbox) {
39027
+ toolbox.style.display = "none";
39028
+ }
39029
+ self2.selectionMenuClosed();
39030
+ });
38952
39031
  if (toolbox) {
38953
39032
  toolbox.style.display = "none";
38954
39033
  }
38955
39034
  self2.selectionMenuClosed();
39035
+ commentIcon?.removeEventListener("click", noteH, false);
38956
39036
  });
38957
- if (toolbox) {
38958
- toolbox.style.display = "none";
38959
- }
38960
- self2.selectionMenuClosed();
38961
- commentIcon?.removeEventListener("click", noteH, false);
38962
39037
  }, deleteH = function() {
38963
39038
  if (self2.delegate.rights.enableAnnotations) {
38964
39039
  self2.delegate.annotationModule?.deleteSelectedHighlight(anno).then(async () => {
@@ -39058,7 +39133,9 @@ var TextHighlighter = class {
39058
39133
  if (!doc.getElementById(id2)) {
39059
39134
  let container = doc.createElement("div");
39060
39135
  container.setAttribute("id", id2);
39061
- container.style.setProperty("pointer-events", "none");
39136
+ if (id2 !== HighlightContainer.R2_ID_GUTTER_RIGHT_CONTAINER) {
39137
+ container.style.setProperty("pointer-events", "none");
39138
+ }
39062
39139
  if (this.delegate.view?.layout === "fixed") {
39063
39140
  container.style.setProperty("position", "absolute");
39064
39141
  container.style.setProperty("top", "0");
@@ -39124,6 +39201,12 @@ var TextHighlighter = class {
39124
39201
  this.removeAllChildNodes(container);
39125
39202
  }
39126
39203
  break;
39204
+ case HighlightType.Comment:
39205
+ container = doc.getElementById(HighlightContainer.R2_ID_GUTTER_RIGHT_CONTAINER);
39206
+ if (container) {
39207
+ this.removeAllChildNodes(container);
39208
+ }
39209
+ break;
39127
39210
  default:
39128
39211
  container = doc.getElementById(HighlightContainer.R2_ID_HIGHLIGHTS_CONTAINER);
39129
39212
  if (container) {
@@ -39222,7 +39305,7 @@ var TextHighlighter = class {
39222
39305
  highlightArea.setAttribute("class", CLASS_HIGHLIGHT_AREA);
39223
39306
  highlightArea.dataset.marker = "" + highlight.marker;
39224
39307
  let extra = "";
39225
- if (drawUnderline && highlight.marker !== AnnotationMarker.Custom && highlight.marker !== AnnotationMarker.Bookmark) {
39308
+ if (drawUnderline && highlight.marker !== AnnotationMarker.Custom && highlight.marker !== AnnotationMarker.Bookmark && highlight.marker !== AnnotationMarker.Comment) {
39226
39309
  let color = highlight.color;
39227
39310
  if (TextHighlighter.isHexColor(color)) {
39228
39311
  color = TextHighlighter.hexToRgbChannels(color);
@@ -39240,7 +39323,7 @@ var TextHighlighter = class {
39240
39323
  highlightArea.classList.add(highlight.style?.defaultClass);
39241
39324
  highlightArea.setAttribute("style", `mix-blend-mode: multiply; border-radius: ${roundedCorner}px !important; ${extra}`);
39242
39325
  }
39243
- } else if (highlight.marker === AnnotationMarker.Underline) {
39326
+ } else if (highlight.marker === AnnotationMarker.Underline || highlight.marker === AnnotationMarker.Comment) {
39244
39327
  if (typeof highlight.color === "object") {
39245
39328
  let color = highlight.color;
39246
39329
  highlightArea.setAttribute("style", `mix-blend-mode: multiply; border-radius: ${roundedCorner}px !important; background-color: rgba(${color.red}, ${color.green}, ${color.blue}, ${0}) !important; ${extra}`);
@@ -39373,8 +39456,10 @@ var TextHighlighter = class {
39373
39456
  let half = third * 2;
39374
39457
  highlightAreaIcon.setAttribute("style", `position: absolute;top:${position}px;left:${parseInt(highlightBounding.style.left.replace("px", "")) + parseInt(highlightBounding.style.width.replace("px", "")) - half}px;height:${size}px; width:${size}px;`);
39375
39458
  } else {
39376
- if (highlight.note && highlight.marker !== AnnotationMarker.Custom && highlight.marker !== AnnotationMarker.Bookmark) {
39459
+ if (highlight.note && highlight.marker !== AnnotationMarker.Custom && highlight.marker !== AnnotationMarker.Bookmark && highlight.marker !== AnnotationMarker.Comment && highlight.marker !== AnnotationMarker.Highlight && highlight.marker !== AnnotationMarker.Underline) {
39377
39460
  highlightAreaIcon.setAttribute("style", `position: absolute;top:${position - size / 2}px;left:${parseInt(highlightBounding.style.left.replace("px", "")) + parseInt(highlightBounding.style.width.replace("px", "")) - size / 2}px;height:${size}px; width:${size}px;`);
39461
+ } else if (highlight.note && highlight.marker === AnnotationMarker.Comment || highlight.marker === AnnotationMarker.Highlight || highlight.marker === AnnotationMarker.Underline) {
39462
+ highlightAreaIcon.setAttribute("style", `position: absolute;top:${position}px;left:${left + this.delegate.iframes[0].contentDocument?.scrollingElement?.scrollLeft}px;height:${size}px; width:${size}px;`);
39378
39463
  } else {
39379
39464
  highlightAreaIcon.setAttribute("style", `position: absolute;top:${position}px;left:${left + this.delegate.iframes[0].contentDocument?.scrollingElement?.scrollLeft}px;height:${size}px; width:${size}px;`);
39380
39465
  }
@@ -39385,7 +39470,7 @@ var TextHighlighter = class {
39385
39470
  highlightAreaIcon.id = highlight.icon?.id;
39386
39471
  } else if (highlight.icon?.svgPath) {
39387
39472
  highlightAreaIcon.innerHTML = iconTemplateColored(`${highlight.icon?.id}`, `${highlight.icon?.title}`, `${highlight.icon?.svgPath}`, `icon open`, size, `${highlight.icon?.color} !important`);
39388
- } else {
39473
+ } else if (highlight.icon?.title) {
39389
39474
  highlightAreaIcon.innerHTML = highlight.icon?.title;
39390
39475
  }
39391
39476
  } else {
@@ -39394,7 +39479,11 @@ var TextHighlighter = class {
39394
39479
  if (TextHighlighter.isHexColor(color)) {
39395
39480
  color = TextHighlighter.hexToRgbChannels(color);
39396
39481
  }
39397
- highlightAreaIcon.innerHTML = iconTemplateColored(`note-icon`, `Note`, `<rect fill="none" height="24" width="24"/><path d="M19,5v9l-5,0l0,5H5V5H19 M19,3H5C3.9,3,3,3.9,3,5v14c0,1.1,0.9,2,2,2h10l6-6V5C21,3.9,20.1,3,19,3z M12,14H7v-2h5V14z M17,10H7V8h10V10z"/>`, `icon open`, size, `rgba(${color.red}, ${color.green}, ${color.blue}, 1) !important`);
39482
+ if (highlight.marker === AnnotationMarker.Comment || highlight.marker === AnnotationMarker.Highlight || highlight.marker === AnnotationMarker.Underline) {
39483
+ highlightAreaIcon.innerHTML = iconTemplateColored(``, ``, `<path d="M24 24H0V0h24v24z" fill="none"/><circle cx="12" cy="12" r="14"/>`, `icon open`, size / 2, `rgba(${color.red}, ${color.green}, ${color.blue}, 1) !important`);
39484
+ } else {
39485
+ highlightAreaIcon.innerHTML = iconTemplateColored(`note-icon`, `Note`, `<rect fill="none" height="24" width="24"/><path d="M19,5v9l-5,0l0,5H5V5H19 M19,3H5C3.9,3,3,3.9,3,5v14c0,1.1,0.9,2,2,2h10l6-6V5C21,3.9,20.1,3,19,3z M12,14H7v-2h5V14z M17,10H7V8h10V10z"/>`, `icon open`, size, `rgba(${color.red}, ${color.green}, ${color.blue}, 1) !important`);
39486
+ }
39398
39487
  }
39399
39488
  }
39400
39489
  highlightAreaIcon.style.setProperty("pointer-events", "all");
@@ -39417,14 +39506,15 @@ var TextHighlighter = class {
39417
39506
  toolbox.style.left = ev.clientX + "px";
39418
39507
  if (getComputedStyle(toolbox).display === "none") {
39419
39508
  let noteH = function() {
39420
- anno.highlight.note = prompt("Add your note here:");
39421
- self2.delegate.annotationModule?.updateAnnotation(anno).then(async () => {
39422
- import_loglevel5.default.log("update highlight " + anno.id);
39509
+ self2.delegate.annotationModule?.api?.addCommentToAnnotation(anno).then((result) => {
39510
+ self2.delegate.annotationModule?.updateAnnotation(result).then(async () => {
39511
+ import_loglevel5.default.log("update highlight " + result.id);
39512
+ toolbox.style.display = "none";
39513
+ self2.selectionMenuClosed();
39514
+ });
39423
39515
  toolbox.style.display = "none";
39424
39516
  self2.selectionMenuClosed();
39425
39517
  });
39426
- toolbox.style.display = "none";
39427
- self2.selectionMenuClosed();
39428
39518
  }, deleteH = function() {
39429
39519
  if (self2.delegate.rights.enableAnnotations) {
39430
39520
  self2.delegate.annotationModule?.deleteSelectedHighlight(anno).then(async () => {
@@ -39517,7 +39607,6 @@ var TextHighlighter = class {
39517
39607
  tooltip.style.setProperty("background", "lightyellow");
39518
39608
  tooltip.style.setProperty("color", "black");
39519
39609
  }
39520
- highlightAreaIcon.insertBefore(tooltip, highlightAreaIcon.childNodes[0]);
39521
39610
  }
39522
39611
  if (highlight.note || highlight.marker === AnnotationMarker.Custom || highlight.marker === AnnotationMarker.Bookmark) {
39523
39612
  highlightParent.append(highlightAreaIcon);
@@ -39635,7 +39724,7 @@ var AnnotationModule = class {
39635
39724
  setTimeout(async () => {
39636
39725
  await this.drawHighlights();
39637
39726
  await this.showHighlights();
39638
- }, 100);
39727
+ }, 200);
39639
39728
  }
39640
39729
  initialize() {
39641
39730
  return new Promise(async (resolve) => {
@@ -39705,8 +39794,11 @@ var AnnotationModule = class {
39705
39794
  }
39706
39795
  async scrollToHighlight(id2) {
39707
39796
  import_loglevel7.default.log("still need to scroll to " + id2);
39708
- var position = await this.annotator?.getAnnotationPosition(id2, this.delegate.iframes[0].contentWindow);
39709
- window.scrollTo(0, position - window.innerHeight / 3);
39797
+ var element = await this.annotator?.getAnnotationElement(id2, this.delegate.iframes[0].contentWindow);
39798
+ element.scrollIntoView({
39799
+ block: "center",
39800
+ behavior: "smooth"
39801
+ });
39710
39802
  }
39711
39803
  async updateLocalHighlight(annotation) {
39712
39804
  if (this.annotator) {
@@ -39821,11 +39913,16 @@ var AnnotationModule = class {
39821
39913
  }
39822
39914
  if (annotation) {
39823
39915
  if (this.api?.addAnnotation) {
39824
- let result = await this.api.addAnnotation(annotation);
39825
- const saved = await this.annotator.saveAnnotation(result);
39826
- await this.showHighlights();
39827
- await this.drawHighlights();
39828
- return new Promise((resolve) => resolve(saved));
39916
+ try {
39917
+ let result = await this.api.addAnnotation(annotation);
39918
+ const saved = await this.annotator.saveAnnotation(result);
39919
+ await this.showHighlights();
39920
+ await this.drawHighlights();
39921
+ return new Promise((resolve) => resolve(saved));
39922
+ } catch (error) {
39923
+ await this.showHighlights();
39924
+ await this.drawHighlights();
39925
+ }
39829
39926
  } else {
39830
39927
  const saved = await this.annotator.saveAnnotation(annotation);
39831
39928
  await this.showHighlights();
@@ -39955,6 +40052,65 @@ var AnnotationModule = class {
39955
40052
  if (this.properties?.initialAnnotationColor) {
39956
40053
  this.highlighter.setColor(this.properties?.initialAnnotationColor);
39957
40054
  }
40055
+ this.repositionGutters();
40056
+ }
40057
+ }
40058
+ repositionGutters() {
40059
+ let doc = this.delegate.iframes[0].contentDocument;
40060
+ if (doc) {
40061
+ this.commentGutter = doc.getElementById(HighlightContainer.R2_ID_GUTTER_RIGHT_CONTAINER);
40062
+ if (this.delegate.view?.isScrollMode() && this.properties?.enableComments) {
40063
+ this.commentGutter.style.removeProperty("display");
40064
+ } else {
40065
+ this.commentGutter.style.setProperty("display", "none");
40066
+ }
40067
+ if (this.commentGutter && this.delegate.view?.isScrollMode()) {
40068
+ this.commentGutter.innerHTML = "";
40069
+ let highlights = [];
40070
+ if (this.annotator) {
40071
+ highlights = this.annotator.getAnnotations();
40072
+ if (highlights) {
40073
+ highlights = highlights.filter((rangeRepresentation) => rangeRepresentation.highlight?.note?.length > 0);
40074
+ highlights = this.syncPosition(highlights);
40075
+ highlights = this.reposition(highlights);
40076
+ highlights.forEach((rangeRepresentation) => {
40077
+ let icon = document.createElement("i");
40078
+ icon.innerHTML = "sticky_note_2";
40079
+ icon.className = "material-icons";
40080
+ icon.style.color = rangeRepresentation.highlight.color;
40081
+ let container = doc.getElementById("R2_ID_HIGHLIGHTS_CONTAINER");
40082
+ let highlightArea;
40083
+ let highlightIcon;
40084
+ if (container) {
40085
+ highlightArea = container.querySelector(`#${rangeRepresentation.highlight.id}`);
40086
+ }
40087
+ let nodeList = highlightArea.getElementsByClassName(CLASS_HIGHLIGHT_AREA);
40088
+ highlightIcon = nodeList[0];
40089
+ const size = parseInt(highlightIcon.style.height.replace("px", ""));
40090
+ const position = rangeRepresentation.highlight.position;
40091
+ const highlightAreaIcon = doc.createElement("div");
40092
+ highlightAreaIcon.setAttribute("style", `position: absolute;top:${position}px;display: flex;max-width: 250px !important;height:${size}px;width: 200px;align-items: center;`);
40093
+ const iconSpan = doc.createElement("div");
40094
+ highlightAreaIcon.appendChild(iconSpan);
40095
+ let color = rangeRepresentation.highlight.color;
40096
+ if (TextHighlighter.isHexColor(color)) {
40097
+ color = TextHighlighter.hexToRgbChannels(color);
40098
+ }
40099
+ highlightAreaIcon.innerHTML = iconTemplateColored(``, ``, `<path d="M24 24H0V0h24v24z" fill="none"/><circle cx="12" cy="12" r="8"/>`, `icon open`, 10, `rgba(${color.red}, ${color.green}, ${color.blue}, 1) !important`);
40100
+ const span = doc.createElement("div");
40101
+ span.innerHTML = rangeRepresentation.highlight?.note;
40102
+ span.setAttribute("style", `height:${size}px;overflow: hidden;padding-left: 5px;`);
40103
+ highlightAreaIcon.appendChild(span);
40104
+ addEventListenerOptional(highlightAreaIcon, "click", (event) => {
40105
+ event.preventDefault();
40106
+ event.stopPropagation();
40107
+ this.scrollToHighlight(rangeRepresentation.highlight.id);
40108
+ });
40109
+ this.commentGutter?.appendChild(highlightAreaIcon);
40110
+ });
40111
+ }
40112
+ }
40113
+ }
39958
40114
  }
39959
40115
  }
39960
40116
  createTree(type, annotations, view) {
@@ -40110,6 +40266,56 @@ var AnnotationModule = class {
40110
40266
  async getAnnotationByID(id2) {
40111
40267
  return this.annotator?.getAnnotationByID(id2);
40112
40268
  }
40269
+ syncPosition(highlights) {
40270
+ let doc = this.delegate.iframes[0].contentDocument;
40271
+ const positionAnnotations = (newArray, currentElement) => {
40272
+ let container = doc.getElementById("R2_ID_HIGHLIGHTS_CONTAINER");
40273
+ let highlightArea;
40274
+ let highlightIcon;
40275
+ if (container) {
40276
+ highlightArea = container.querySelector(`#${currentElement.highlight.id}`);
40277
+ }
40278
+ let nodeList = highlightArea.getElementsByClassName(CLASS_HIGHLIGHT_AREA);
40279
+ highlightIcon = nodeList[0];
40280
+ const newY = parseInt(highlightIcon.style.top.replace("px", ""));
40281
+ const updatedAnnotation = __spreadProps(__spreadValues({}, currentElement), {
40282
+ highlight: __spreadProps(__spreadValues({}, currentElement.highlight), {
40283
+ position: newY
40284
+ })
40285
+ });
40286
+ return [...newArray, updatedAnnotation];
40287
+ };
40288
+ return highlights.reduce(positionAnnotations, []);
40289
+ }
40290
+ reposition(highlights) {
40291
+ let doc = this.delegate.iframes[0].contentDocument;
40292
+ const positionAnnotations = (newArray, currentElement, currentIndex) => {
40293
+ const high = highlights[0];
40294
+ let container = doc.getElementById("R2_ID_HIGHLIGHTS_CONTAINER");
40295
+ let highlightArea;
40296
+ let highlightIcon;
40297
+ if (container) {
40298
+ highlightArea = container.querySelector(`#${high.highlight.id}`);
40299
+ }
40300
+ let nodeList = highlightArea.getElementsByClassName(CLASS_HIGHLIGHT_AREA);
40301
+ highlightIcon = nodeList[0];
40302
+ const size = parseInt(highlightIcon.style.height.replace("px", ""));
40303
+ let originY = currentElement.highlight.position;
40304
+ const preY = newArray[currentIndex - 1] && newArray[currentIndex - 1].highlight.position;
40305
+ const preHeight = size;
40306
+ const preBottomY = currentIndex === 0 ? 0 : preY + preHeight + 0;
40307
+ const newY = preBottomY > originY ? preBottomY : originY;
40308
+ const updatedAnnotation = __spreadProps(__spreadValues({}, currentElement), {
40309
+ highlight: __spreadProps(__spreadValues({}, currentElement.highlight), {
40310
+ position: newY
40311
+ })
40312
+ });
40313
+ return [...newArray, updatedAnnotation];
40314
+ };
40315
+ return highlights.sort(function(a, b) {
40316
+ return a.highlight.position - b.highlight.position;
40317
+ }).reduce(positionAnnotations, []);
40318
+ }
40113
40319
  };
40114
40320
 
40115
40321
  // src/modules/BookmarkModule.ts
@@ -40343,7 +40549,11 @@ var BookmarkModule = class {
40343
40549
  }
40344
40550
  };
40345
40551
  if (win !== null) {
40346
- const selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
40552
+ let selectionInfo = getCurrentSelectionInfo(win, getCssSelector);
40553
+ if (selectionInfo === void 0) {
40554
+ let doc3 = self2.delegate.iframes[0].contentDocument;
40555
+ selectionInfo = this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc3);
40556
+ }
40347
40557
  let doc2 = self2.delegate.iframes[0].contentDocument;
40348
40558
  if (selectionInfo && doc2) {
40349
40559
  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);
@@ -40978,17 +41188,19 @@ var MediaOverlayModule = class {
40978
41188
  this.trackCurrentTime();
40979
41189
  };
40980
41190
  this.ensureOnTimeUpdate = (remove, replace) => {
40981
- if (this.audioElement) {
40982
- if (remove) {
40983
- if (this.__ontimeupdate) {
40984
- this.__ontimeupdate = false;
41191
+ if (remove) {
41192
+ if (this.__ontimeupdate) {
41193
+ this.__ontimeupdate = false;
41194
+ if (this.audioElement) {
40985
41195
  this.audioElement.removeEventListener("timeupdate", this.ontimeupdate);
40986
- cancelAnimationFrame(this.myReq);
40987
41196
  }
40988
- } else {
40989
- if (!this.__ontimeupdate || replace) {
40990
- this.__ontimeupdate = true;
40991
- if (replace) {
41197
+ cancelAnimationFrame(this.myReq);
41198
+ }
41199
+ } else {
41200
+ if (!this.__ontimeupdate || replace) {
41201
+ this.__ontimeupdate = true;
41202
+ if (replace) {
41203
+ if (this.audioElement) {
40992
41204
  this.audioElement.removeEventListener("timeupdate", this.ontimeupdate);
40993
41205
  }
40994
41206
  this.audioElement.addEventListener("timeupdate", this.ontimeupdate);
@@ -41070,10 +41282,12 @@ var MediaOverlayModule = class {
41070
41282
  await this.playLink();
41071
41283
  } else {
41072
41284
  if (this.settings.autoTurn && this.settings.playing) {
41073
- this.audioElement.pause();
41285
+ if (this.audioElement) {
41286
+ await this.audioElement.pause();
41287
+ }
41074
41288
  this.delegate.nextResource();
41075
41289
  } else {
41076
- this.stopReadAloud();
41290
+ await this.stopReadAloud();
41077
41291
  }
41078
41292
  }
41079
41293
  }
@@ -41081,7 +41295,7 @@ var MediaOverlayModule = class {
41081
41295
  async startReadAloud() {
41082
41296
  if (this.delegate.rights.enableMediaOverlays) {
41083
41297
  this.settings.playing = true;
41084
- if (this.audioElement) {
41298
+ if (this.audioElement && this.currentLinks[this.currentLinkIndex]?.Properties.MediaOverlay) {
41085
41299
  const timeToSeekTo = this.currentAudioBegin ? this.currentAudioBegin : 0;
41086
41300
  this.audioElement.currentTime = timeToSeekTo;
41087
41301
  await this.audioElement.play();
@@ -41108,10 +41322,8 @@ var MediaOverlayModule = class {
41108
41322
  }
41109
41323
  async stopReadAloud() {
41110
41324
  if (this.delegate.rights.enableMediaOverlays) {
41111
- if (this.currentLinkIndex > 0)
41112
- await this.playLink();
41113
41325
  this.settings.playing = false;
41114
- this.audioElement?.pause();
41326
+ this.audioElement.pause();
41115
41327
  if (this.play)
41116
41328
  this.play.style.removeProperty("display");
41117
41329
  if (this.pause)
@@ -45751,8 +45963,12 @@ var _LocalAnnotator = class {
45751
45963
  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
45964
  const sha256Hex = SHA256.hash(uniqueStr);
45753
45965
  rangeRepresentation.highlight.id = "R2_HIGHLIGHT_" + sha256Hex;
45754
- var rangeColor;
45755
- rangeColor = rangeRepresentation.color;
45966
+ let rangeColor;
45967
+ if (rangeRepresentation.highlight.color) {
45968
+ rangeColor = rangeRepresentation.highlight.color;
45969
+ } else if (rangeRepresentation.color) {
45970
+ rangeColor = rangeRepresentation.color;
45971
+ }
45756
45972
  if (TextHighlighter.isHexColor(rangeColor)) {
45757
45973
  rangeColor = TextHighlighter.hexToRgbString(rangeColor);
45758
45974
  }
@@ -45764,6 +45980,21 @@ var _LocalAnnotator = class {
45764
45980
  this.store.set(_LocalAnnotator.ANNOTATIONS, JSON.stringify(annotationsToStore));
45765
45981
  return annotationsToStore;
45766
45982
  }
45983
+ saveTemporarySelectionInfo(selectionInfo) {
45984
+ this.store.set(_LocalAnnotator.SELECTIONINFO, JSON.stringify(selectionInfo));
45985
+ }
45986
+ getTemporarySelectionInfo(doc) {
45987
+ const selectionInfos = this.store.get(_LocalAnnotator.SELECTIONINFO);
45988
+ if (selectionInfos) {
45989
+ let selectionInfo = JSON.parse(selectionInfos);
45990
+ selectionInfo.range = convertRangeInfo(doc, selectionInfo.rangeInfo);
45991
+ return selectionInfo;
45992
+ }
45993
+ return [];
45994
+ }
45995
+ deleteTemporarySelectionInfo() {
45996
+ this.store.remove(_LocalAnnotator.SELECTIONINFO);
45997
+ }
45767
45998
  saveAnnotation(annotation) {
45768
45999
  let savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
45769
46000
  if (savedAnnotations) {
@@ -45814,7 +46045,7 @@ var _LocalAnnotator = class {
45814
46045
  const savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
45815
46046
  if (savedAnnotations) {
45816
46047
  const annotations = JSON.parse(savedAnnotations);
45817
- const filtered = annotations.filter((el) => el.id === id2);
46048
+ const filtered = annotations.filter((el) => el.highlight?.id === id2 || el.id === id2);
45818
46049
  if (filtered.length > 0) {
45819
46050
  let foundElement = iframeWin.document.getElementById(`${filtered[0].highlight.id}`);
45820
46051
  if (foundElement) {
@@ -45836,6 +46067,33 @@ var _LocalAnnotator = class {
45836
46067
  }
45837
46068
  return null;
45838
46069
  }
46070
+ getAnnotationElement(id2, iframeWin) {
46071
+ const savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
46072
+ if (savedAnnotations) {
46073
+ const annotations = JSON.parse(savedAnnotations);
46074
+ const filtered = annotations.filter((el) => el.highlight?.id === id2);
46075
+ if (filtered.length > 0) {
46076
+ let foundElement = iframeWin.document.getElementById(`${filtered[0].highlight.id}`);
46077
+ if (foundElement) {
46078
+ let position = 0;
46079
+ if (foundElement.hasChildNodes) {
46080
+ for (let i = 0; i < foundElement.childNodes.length; i++) {
46081
+ let childNode = foundElement.childNodes[i];
46082
+ let top = parseInt(childNode.style.top.replace("px", ""));
46083
+ if (top < position || position === 0) {
46084
+ position = top;
46085
+ return childNode;
46086
+ }
46087
+ }
46088
+ } else {
46089
+ position = parseInt(foundElement.style.top.replace("px", ""));
46090
+ }
46091
+ return foundElement;
46092
+ }
46093
+ }
46094
+ }
46095
+ return null;
46096
+ }
45839
46097
  getAnnotation(highlight) {
45840
46098
  const savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
45841
46099
  if (savedAnnotations) {
@@ -45863,6 +46121,7 @@ var LocalAnnotator = _LocalAnnotator;
45863
46121
  LocalAnnotator.LAST_READING_POSITION = "last-reading-position";
45864
46122
  LocalAnnotator.BOOKMARKS = "bookmarks";
45865
46123
  LocalAnnotator.ANNOTATIONS = "annotations";
46124
+ LocalAnnotator.SELECTIONINFO = "selectionInfo";
45866
46125
 
45867
46126
  // src/store/LocalStorageStore.ts
45868
46127
  init_polyfills();
@@ -46277,7 +46536,12 @@ var TTSModule2 = class {
46277
46536
  if (window.speechSynthesis.speaking && this.speaking && startX === this.startX && startY === this.startY) {
46278
46537
  let doc = this.delegate.iframes[0].contentDocument;
46279
46538
  if (doc) {
46280
- const selection = this.highlighter.dom(doc.body).getSelection();
46539
+ let selection = this.highlighter.dom(doc.body).getSelection();
46540
+ if (selection.isCollapsed) {
46541
+ let doc2 = this.delegate.iframes[0].contentDocument;
46542
+ const selectionInfo = this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc2);
46543
+ selection.addRange(selectionInfo.range);
46544
+ }
46281
46545
  let range = selection.getRangeAt(0);
46282
46546
  let node = selection.anchorNode;
46283
46547
  while (range.toString().indexOf(" ") !== 0) {
@@ -46372,15 +46636,20 @@ var TTSModule2 = class {
46372
46636
  let rootEl = iframe.contentWindow?.document.body;
46373
46637
  let doc = this.delegate.iframes[0].contentDocument;
46374
46638
  if (doc) {
46375
- const selection = this.highlighter.dom(doc.body).getSelection();
46639
+ let selection = this.highlighter.dom(doc.body).getSelection();
46640
+ if (selection.isCollapsed) {
46641
+ let doc2 = self2.delegate.iframes[0].contentDocument;
46642
+ const selectionInfo2 = self2.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc2);
46643
+ selection.addRange(selectionInfo2.range);
46644
+ }
46376
46645
  if (rootEl) {
46377
46646
  var ttsQueue = this.generateTtsQueue(rootEl);
46378
46647
  if (!ttsQueue.length) {
46379
46648
  return;
46380
46649
  }
46381
46650
  var idx = this.findTtsQueueItemIndex(ttsQueue, selection.anchorNode, selection.anchorNode, selection.anchorOffset, rootEl);
46382
- const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
46383
46651
  var idxEnd = this.findTtsQueueItemIndex(ttsQueue, selection.focusNode, selection.focusNode, selection.focusOffset, rootEl);
46652
+ const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
46384
46653
  const ttsQueueItemEnd = getTtsQueueItemRef(ttsQueue, idxEnd);
46385
46654
  var restOfTheText;
46386
46655
  if (ttsQueueItem && selectionInfo && selectionInfo.cleanText) {
@@ -46417,22 +46686,12 @@ var TTSModule2 = class {
46417
46686
  import_loglevel19.default.log(ttsQueueItem.item.textNodes);
46418
46687
  import_loglevel19.default.log(startIndex);
46419
46688
  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
46689
  let node = ttsQueueItem.item.textNodes.filter((node2) => {
46431
46690
  return node2 === selectionInfo.range?.commonAncestorContainer;
46432
46691
  })[0];
46433
46692
  import_loglevel19.default.log(node);
46434
46693
  utterance.onboundary = (ev) => {
46435
- this.updateTTSInfo(ttsQueueItem, ev.charIndex + startIndex, ev.charLength, utterance.text);
46694
+ this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, startIndex, utterance.text);
46436
46695
  };
46437
46696
  }
46438
46697
  }
@@ -46537,7 +46796,7 @@ var TTSModule2 = class {
46537
46796
  const sentence = getTtsQueueItemRefText(ttsQueueItem);
46538
46797
  utterance = new SpeechSynthesisUtterance(sentence);
46539
46798
  utterance.onboundary = (ev) => {
46540
- self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, utterance.text);
46799
+ self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
46541
46800
  };
46542
46801
  setTimeout(() => {
46543
46802
  window.speechSynthesis.speak(utterance);
@@ -46549,7 +46808,7 @@ var TTSModule2 = class {
46549
46808
  if (ttsQueueItem) {
46550
46809
  utterance = new SpeechSynthesisUtterance(restOfTheText);
46551
46810
  utterance.onboundary = (ev) => {
46552
- self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, utterance.text);
46811
+ self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
46553
46812
  };
46554
46813
  setTimeout(() => {
46555
46814
  window.speechSynthesis.speak(utterance);
@@ -46922,7 +47181,7 @@ var TTSModule2 = class {
46922
47181
  import_loglevel19.default.log("navigator.language", navigator.language);
46923
47182
  utterance.onboundary = (ev) => {
46924
47183
  import_loglevel19.default.log(ev.name);
46925
- this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, utterance.text);
47184
+ this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
46926
47185
  };
46927
47186
  setTimeout(() => {
46928
47187
  window.speechSynthesis.speak(utterance);
@@ -46936,7 +47195,7 @@ var TTSModule2 = class {
46936
47195
  }
46937
47196
  };
46938
47197
  }
46939
- updateTTSInfo(ttsQueueItem, charIndex, charLength, utteranceText) {
47198
+ updateTTSInfo(ttsQueueItem, charIndex, charLength, startIndex, utteranceText) {
46940
47199
  if (!ttsQueueItem) {
46941
47200
  return void 0;
46942
47201
  }
@@ -46947,14 +47206,16 @@ var TTSModule2 = class {
46947
47206
  const right = utteranceText.slice(charIndex).search(/\s/);
46948
47207
  const word = right < 0 ? utteranceText.slice(start) : utteranceText.slice(start, right + charIndex);
46949
47208
  const end = start + word.length;
46950
- let useStart = false;
46951
- if (!charLength) {
47209
+ if (charLength === void 0) {
47210
+ const match = utteranceText.substring(charIndex).match(/^[a-z\d']*/i);
47211
+ if (match) {
47212
+ charLength = match[0].length;
47213
+ }
47214
+ }
47215
+ if (charLength === void 0) {
46952
47216
  charLength = word.length;
46953
- useStart = true;
46954
- } else {
46955
- useStart = false;
46956
47217
  }
46957
- this.wrapHighlightWord(ttsQueueItem, utteranceText, useStart ? start : charIndex, charLength, word, start, end);
47218
+ this.wrapHighlightWord(ttsQueueItem, utteranceText, charIndex + startIndex, charLength, word, start, end);
46958
47219
  }
46959
47220
  return ttsQueueItemText;
46960
47221
  }
@@ -46967,15 +47228,7 @@ var TTSModule2 = class {
46967
47228
  this._ttsQueueItemHighlightsWord = void 0;
46968
47229
  }
46969
47230
  const ttsQueueItem = ttsQueueItemRef.item;
46970
- let txtToCheck = ttsQueueItemRef.item.combinedText;
46971
47231
  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
47232
  let acc = 0;
46980
47233
  let rangeStartNode;
46981
47234
  let rangeStartOffset = -1;
@@ -47829,14 +48082,15 @@ var ContributorType;
47829
48082
  ContributorType2["Compiler"] = "Compiler";
47830
48083
  })(ContributorType || (ContributorType = {}));
47831
48084
  var CitationModule = class {
47832
- constructor(delegate, publication, highlighter, properties) {
48085
+ constructor(delegate, publication, highlighter, properties, api) {
47833
48086
  this.highlighter = highlighter;
47834
48087
  this.delegate = delegate;
47835
48088
  this.properties = properties;
47836
48089
  this.publication = publication;
48090
+ this.api = api;
47837
48091
  }
47838
48092
  static async create(config2) {
47839
- const module = new this(config2.delegate, config2.publication, config2.highlighter, config2);
48093
+ const module = new this(config2.delegate, config2.publication, config2.highlighter, config2, config2.api);
47840
48094
  await module.start();
47841
48095
  return module;
47842
48096
  }
@@ -47861,9 +48115,9 @@ var CitationModule = class {
47861
48115
  document.body.removeChild(forExecElement);
47862
48116
  }
47863
48117
  if (success) {
47864
- alert("The text was copied to the clipboard!");
48118
+ this.api?.citationCreated("The text was copied to the clipboard!");
47865
48119
  } else {
47866
- alert("Your browser doesn't allow clipboard access!");
48120
+ this.api?.citationFailed("Your browser doesn't allow clipboard access!");
47867
48121
  }
47868
48122
  }
47869
48123
  createElementForExecCommand(textToClipboard) {