@d-i-t-a/reader 2.1.0-beta.9 → 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
@@ -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
  }
@@ -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);
@@ -38189,6 +38197,7 @@ var TextHighlighter = class {
38189
38197
  let highlightIcon = document.getElementById("highlightIcon");
38190
38198
  let collapseIcon = document.getElementById("collapseIcon");
38191
38199
  let underlineIcon = document.getElementById("underlineIcon");
38200
+ let noteIcon = document.getElementById("noteIcon");
38192
38201
  let colorIcon = document.getElementById("colorIcon");
38193
38202
  let speakIcon = document.getElementById("speakIcon");
38194
38203
  if (this.delegate.rights.enableAnnotations) {
@@ -38208,6 +38217,14 @@ var TextHighlighter = class {
38208
38217
  }
38209
38218
  }
38210
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
+ }
38211
38228
  if (colorIcon) {
38212
38229
  colorIcon.style.display = "unset";
38213
38230
  let colorIconSymbol = colorIcon.lastChild;
@@ -38235,6 +38252,17 @@ var TextHighlighter = class {
38235
38252
  underlineIcon = document.getElementById("underlineIcon");
38236
38253
  underlineIcon?.addEventListener("click", commentEvent);
38237
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);
38265
+ }
38238
38266
  } else {
38239
38267
  if (highlightIcon) {
38240
38268
  highlightIcon.style.setProperty("display", "none");
@@ -38242,6 +38270,9 @@ var TextHighlighter = class {
38242
38270
  if (underlineIcon) {
38243
38271
  underlineIcon.style.setProperty("display", "none");
38244
38272
  }
38273
+ if (noteIcon) {
38274
+ noteIcon.style.setProperty("display", "none");
38275
+ }
38245
38276
  if (colorIcon) {
38246
38277
  colorIcon.style.setProperty("display", "none");
38247
38278
  }
@@ -38270,7 +38301,7 @@ var TextHighlighter = class {
38270
38301
  if (menuItem.icon) {
38271
38302
  menuItem.icon.id = menuItem.id;
38272
38303
  }
38273
- const itemElement = document.getElementById(menuItem.id);
38304
+ let itemElement = document.getElementById(menuItem.id);
38274
38305
  const self3 = this;
38275
38306
  function itemEvent() {
38276
38307
  itemElement?.removeEventListener("click", itemEvent);
@@ -38312,11 +38343,12 @@ var TextHighlighter = class {
38312
38343
  self3.delegate.annotationModule?.saveAnnotation(highlight[0]).then((anno) => {
38313
38344
  if (menuItem?.note) {
38314
38345
  if (anno.highlight) {
38315
- 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
+ });
38316
38351
  }
38317
- self3.delegate.annotationModule?.updateAnnotation(anno).then(async () => {
38318
- import_loglevel5.default.log("update highlight " + anno.id);
38319
- });
38320
38352
  }
38321
38353
  });
38322
38354
  } else if (self3.delegate.rights.enableBookmarks) {
@@ -38330,7 +38362,10 @@ var TextHighlighter = class {
38330
38362
  self3.callbackComplete();
38331
38363
  }
38332
38364
  if (itemElement) {
38333
- 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);
38334
38369
  }
38335
38370
  });
38336
38371
  }
@@ -38704,7 +38739,7 @@ var TextHighlighter = class {
38704
38739
  highlightArea.classList.remove("hover");
38705
38740
  }
38706
38741
  }
38707
- } else if (highlight.marker === AnnotationMarker.Underline) {
38742
+ } else if (highlight.marker === AnnotationMarker.Underline || highlight.marker === AnnotationMarker.Comment) {
38708
38743
  if (typeof highlight.color === "object") {
38709
38744
  let color = highlight.color;
38710
38745
  highlightArea.style.setProperty("background-color", `rgba(${color.red}, ${color.green}, ${color.blue}, ${0})`, "important");
@@ -38778,7 +38813,7 @@ var TextHighlighter = class {
38778
38813
  highlightArea.classList.add("hover");
38779
38814
  }
38780
38815
  }
38781
- } else if (highlight.marker === AnnotationMarker.Underline) {
38816
+ } else if (highlight.marker === AnnotationMarker.Underline || highlight.marker === AnnotationMarker.Comment) {
38782
38817
  if (typeof highlight.color === "object") {
38783
38818
  let color = highlight.color;
38784
38819
  highlightArea.style.setProperty("background-color", `rgba(${color.red}, ${color.green}, ${color.blue}, ${0.1})`, "important");
@@ -38985,19 +39020,20 @@ var TextHighlighter = class {
38985
39020
  toolbox.style.left = ev.clientX + "px";
38986
39021
  if (getComputedStyle(toolbox).display === "none") {
38987
39022
  let noteH = function() {
38988
- anno.highlight.note = prompt("Add your note here:");
38989
- self2.delegate.annotationModule?.updateAnnotation(anno).then(async () => {
38990
- 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
+ });
38991
39031
  if (toolbox) {
38992
39032
  toolbox.style.display = "none";
38993
39033
  }
38994
39034
  self2.selectionMenuClosed();
39035
+ commentIcon?.removeEventListener("click", noteH, false);
38995
39036
  });
38996
- if (toolbox) {
38997
- toolbox.style.display = "none";
38998
- }
38999
- self2.selectionMenuClosed();
39000
- commentIcon?.removeEventListener("click", noteH, false);
39001
39037
  }, deleteH = function() {
39002
39038
  if (self2.delegate.rights.enableAnnotations) {
39003
39039
  self2.delegate.annotationModule?.deleteSelectedHighlight(anno).then(async () => {
@@ -39097,7 +39133,9 @@ var TextHighlighter = class {
39097
39133
  if (!doc.getElementById(id2)) {
39098
39134
  let container = doc.createElement("div");
39099
39135
  container.setAttribute("id", id2);
39100
- container.style.setProperty("pointer-events", "none");
39136
+ if (id2 !== HighlightContainer.R2_ID_GUTTER_RIGHT_CONTAINER) {
39137
+ container.style.setProperty("pointer-events", "none");
39138
+ }
39101
39139
  if (this.delegate.view?.layout === "fixed") {
39102
39140
  container.style.setProperty("position", "absolute");
39103
39141
  container.style.setProperty("top", "0");
@@ -39163,6 +39201,12 @@ var TextHighlighter = class {
39163
39201
  this.removeAllChildNodes(container);
39164
39202
  }
39165
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;
39166
39210
  default:
39167
39211
  container = doc.getElementById(HighlightContainer.R2_ID_HIGHLIGHTS_CONTAINER);
39168
39212
  if (container) {
@@ -39261,7 +39305,7 @@ var TextHighlighter = class {
39261
39305
  highlightArea.setAttribute("class", CLASS_HIGHLIGHT_AREA);
39262
39306
  highlightArea.dataset.marker = "" + highlight.marker;
39263
39307
  let extra = "";
39264
- 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) {
39265
39309
  let color = highlight.color;
39266
39310
  if (TextHighlighter.isHexColor(color)) {
39267
39311
  color = TextHighlighter.hexToRgbChannels(color);
@@ -39279,7 +39323,7 @@ var TextHighlighter = class {
39279
39323
  highlightArea.classList.add(highlight.style?.defaultClass);
39280
39324
  highlightArea.setAttribute("style", `mix-blend-mode: multiply; border-radius: ${roundedCorner}px !important; ${extra}`);
39281
39325
  }
39282
- } else if (highlight.marker === AnnotationMarker.Underline) {
39326
+ } else if (highlight.marker === AnnotationMarker.Underline || highlight.marker === AnnotationMarker.Comment) {
39283
39327
  if (typeof highlight.color === "object") {
39284
39328
  let color = highlight.color;
39285
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}`);
@@ -39412,8 +39456,10 @@ var TextHighlighter = class {
39412
39456
  let half = third * 2;
39413
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;`);
39414
39458
  } else {
39415
- 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) {
39416
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;`);
39417
39463
  } else {
39418
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;`);
39419
39465
  }
@@ -39424,7 +39470,7 @@ var TextHighlighter = class {
39424
39470
  highlightAreaIcon.id = highlight.icon?.id;
39425
39471
  } else if (highlight.icon?.svgPath) {
39426
39472
  highlightAreaIcon.innerHTML = iconTemplateColored(`${highlight.icon?.id}`, `${highlight.icon?.title}`, `${highlight.icon?.svgPath}`, `icon open`, size, `${highlight.icon?.color} !important`);
39427
- } else {
39473
+ } else if (highlight.icon?.title) {
39428
39474
  highlightAreaIcon.innerHTML = highlight.icon?.title;
39429
39475
  }
39430
39476
  } else {
@@ -39433,7 +39479,11 @@ var TextHighlighter = class {
39433
39479
  if (TextHighlighter.isHexColor(color)) {
39434
39480
  color = TextHighlighter.hexToRgbChannels(color);
39435
39481
  }
39436
- 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
+ }
39437
39487
  }
39438
39488
  }
39439
39489
  highlightAreaIcon.style.setProperty("pointer-events", "all");
@@ -39456,14 +39506,15 @@ var TextHighlighter = class {
39456
39506
  toolbox.style.left = ev.clientX + "px";
39457
39507
  if (getComputedStyle(toolbox).display === "none") {
39458
39508
  let noteH = function() {
39459
- anno.highlight.note = prompt("Add your note here:");
39460
- self2.delegate.annotationModule?.updateAnnotation(anno).then(async () => {
39461
- 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
+ });
39462
39515
  toolbox.style.display = "none";
39463
39516
  self2.selectionMenuClosed();
39464
39517
  });
39465
- toolbox.style.display = "none";
39466
- self2.selectionMenuClosed();
39467
39518
  }, deleteH = function() {
39468
39519
  if (self2.delegate.rights.enableAnnotations) {
39469
39520
  self2.delegate.annotationModule?.deleteSelectedHighlight(anno).then(async () => {
@@ -39556,7 +39607,6 @@ var TextHighlighter = class {
39556
39607
  tooltip.style.setProperty("background", "lightyellow");
39557
39608
  tooltip.style.setProperty("color", "black");
39558
39609
  }
39559
- highlightAreaIcon.insertBefore(tooltip, highlightAreaIcon.childNodes[0]);
39560
39610
  }
39561
39611
  if (highlight.note || highlight.marker === AnnotationMarker.Custom || highlight.marker === AnnotationMarker.Bookmark) {
39562
39612
  highlightParent.append(highlightAreaIcon);
@@ -39674,7 +39724,7 @@ var AnnotationModule = class {
39674
39724
  setTimeout(async () => {
39675
39725
  await this.drawHighlights();
39676
39726
  await this.showHighlights();
39677
- }, 100);
39727
+ }, 200);
39678
39728
  }
39679
39729
  initialize() {
39680
39730
  return new Promise(async (resolve) => {
@@ -39744,8 +39794,11 @@ var AnnotationModule = class {
39744
39794
  }
39745
39795
  async scrollToHighlight(id2) {
39746
39796
  import_loglevel7.default.log("still need to scroll to " + id2);
39747
- var position = await this.annotator?.getAnnotationPosition(id2, this.delegate.iframes[0].contentWindow);
39748
- 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
+ });
39749
39802
  }
39750
39803
  async updateLocalHighlight(annotation) {
39751
39804
  if (this.annotator) {
@@ -39860,11 +39913,16 @@ var AnnotationModule = class {
39860
39913
  }
39861
39914
  if (annotation) {
39862
39915
  if (this.api?.addAnnotation) {
39863
- let result = await this.api.addAnnotation(annotation);
39864
- const saved = await this.annotator.saveAnnotation(result);
39865
- await this.showHighlights();
39866
- await this.drawHighlights();
39867
- 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
+ }
39868
39926
  } else {
39869
39927
  const saved = await this.annotator.saveAnnotation(annotation);
39870
39928
  await this.showHighlights();
@@ -39994,6 +40052,65 @@ var AnnotationModule = class {
39994
40052
  if (this.properties?.initialAnnotationColor) {
39995
40053
  this.highlighter.setColor(this.properties?.initialAnnotationColor);
39996
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
+ }
39997
40114
  }
39998
40115
  }
39999
40116
  createTree(type, annotations, view) {
@@ -40149,6 +40266,56 @@ var AnnotationModule = class {
40149
40266
  async getAnnotationByID(id2) {
40150
40267
  return this.annotator?.getAnnotationByID(id2);
40151
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
+ }
40152
40319
  };
40153
40320
 
40154
40321
  // src/modules/BookmarkModule.ts
@@ -41021,17 +41188,19 @@ var MediaOverlayModule = class {
41021
41188
  this.trackCurrentTime();
41022
41189
  };
41023
41190
  this.ensureOnTimeUpdate = (remove, replace) => {
41024
- if (this.audioElement) {
41025
- if (remove) {
41026
- if (this.__ontimeupdate) {
41027
- this.__ontimeupdate = false;
41191
+ if (remove) {
41192
+ if (this.__ontimeupdate) {
41193
+ this.__ontimeupdate = false;
41194
+ if (this.audioElement) {
41028
41195
  this.audioElement.removeEventListener("timeupdate", this.ontimeupdate);
41029
- cancelAnimationFrame(this.myReq);
41030
41196
  }
41031
- } else {
41032
- if (!this.__ontimeupdate || replace) {
41033
- this.__ontimeupdate = true;
41034
- 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) {
41035
41204
  this.audioElement.removeEventListener("timeupdate", this.ontimeupdate);
41036
41205
  }
41037
41206
  this.audioElement.addEventListener("timeupdate", this.ontimeupdate);
@@ -41113,10 +41282,12 @@ var MediaOverlayModule = class {
41113
41282
  await this.playLink();
41114
41283
  } else {
41115
41284
  if (this.settings.autoTurn && this.settings.playing) {
41116
- this.audioElement.pause();
41285
+ if (this.audioElement) {
41286
+ await this.audioElement.pause();
41287
+ }
41117
41288
  this.delegate.nextResource();
41118
41289
  } else {
41119
- this.stopReadAloud();
41290
+ await this.stopReadAloud();
41120
41291
  }
41121
41292
  }
41122
41293
  }
@@ -41124,7 +41295,7 @@ var MediaOverlayModule = class {
41124
41295
  async startReadAloud() {
41125
41296
  if (this.delegate.rights.enableMediaOverlays) {
41126
41297
  this.settings.playing = true;
41127
- if (this.audioElement) {
41298
+ if (this.audioElement && this.currentLinks[this.currentLinkIndex]?.Properties.MediaOverlay) {
41128
41299
  const timeToSeekTo = this.currentAudioBegin ? this.currentAudioBegin : 0;
41129
41300
  this.audioElement.currentTime = timeToSeekTo;
41130
41301
  await this.audioElement.play();
@@ -41151,10 +41322,8 @@ var MediaOverlayModule = class {
41151
41322
  }
41152
41323
  async stopReadAloud() {
41153
41324
  if (this.delegate.rights.enableMediaOverlays) {
41154
- if (this.currentLinkIndex > 0)
41155
- await this.playLink();
41156
41325
  this.settings.playing = false;
41157
- this.audioElement?.pause();
41326
+ this.audioElement.pause();
41158
41327
  if (this.play)
41159
41328
  this.play.style.removeProperty("display");
41160
41329
  if (this.pause)
@@ -45898,6 +46067,33 @@ var _LocalAnnotator = class {
45898
46067
  }
45899
46068
  return null;
45900
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
+ }
45901
46097
  getAnnotation(highlight) {
45902
46098
  const savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
45903
46099
  if (savedAnnotations) {
@@ -47886,14 +48082,15 @@ var ContributorType;
47886
48082
  ContributorType2["Compiler"] = "Compiler";
47887
48083
  })(ContributorType || (ContributorType = {}));
47888
48084
  var CitationModule = class {
47889
- constructor(delegate, publication, highlighter, properties) {
48085
+ constructor(delegate, publication, highlighter, properties, api) {
47890
48086
  this.highlighter = highlighter;
47891
48087
  this.delegate = delegate;
47892
48088
  this.properties = properties;
47893
48089
  this.publication = publication;
48090
+ this.api = api;
47894
48091
  }
47895
48092
  static async create(config2) {
47896
- 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);
47897
48094
  await module.start();
47898
48095
  return module;
47899
48096
  }
@@ -47918,9 +48115,9 @@ var CitationModule = class {
47918
48115
  document.body.removeChild(forExecElement);
47919
48116
  }
47920
48117
  if (success) {
47921
- alert("The text was copied to the clipboard!");
48118
+ this.api?.citationCreated("The text was copied to the clipboard!");
47922
48119
  } else {
47923
- alert("Your browser doesn't allow clipboard access!");
48120
+ this.api?.citationFailed("Your browser doesn't allow clipboard access!");
47924
48121
  }
47925
48122
  }
47926
48123
  createElementForExecCommand(textToClipboard) {