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

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
@@ -10118,9 +10118,9 @@ var require_source_map = __commonJS({
10118
10118
  }
10119
10119
  });
10120
10120
 
10121
- // (disabled):path
10121
+ // (disabled):node_modules/path/path.js
10122
10122
  var require_path = __commonJS({
10123
- "(disabled):path"() {
10123
+ "(disabled):node_modules/path/path.js"() {
10124
10124
  init_polyfills();
10125
10125
  }
10126
10126
  });
@@ -13677,6 +13677,231 @@ and ensure you are accounting for this risk.
13677
13677
  }
13678
13678
  });
13679
13679
 
13680
+ // node_modules/loglevel/lib/loglevel.js
13681
+ var require_loglevel = __commonJS({
13682
+ "node_modules/loglevel/lib/loglevel.js"(exports, module) {
13683
+ init_polyfills();
13684
+ (function(root, definition) {
13685
+ "use strict";
13686
+ if (typeof define === "function" && define.amd) {
13687
+ define(definition);
13688
+ } else if (typeof module === "object" && module.exports) {
13689
+ module.exports = definition();
13690
+ } else {
13691
+ root.log = definition();
13692
+ }
13693
+ })(exports, function() {
13694
+ "use strict";
13695
+ var noop = function() {
13696
+ };
13697
+ var undefinedType = "undefined";
13698
+ var isIE2 = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
13699
+ var logMethods = [
13700
+ "trace",
13701
+ "debug",
13702
+ "info",
13703
+ "warn",
13704
+ "error"
13705
+ ];
13706
+ function bindMethod(obj, methodName) {
13707
+ var method = obj[methodName];
13708
+ if (typeof method.bind === "function") {
13709
+ return method.bind(obj);
13710
+ } else {
13711
+ try {
13712
+ return Function.prototype.bind.call(method, obj);
13713
+ } catch (e) {
13714
+ return function() {
13715
+ return Function.prototype.apply.apply(method, [obj, arguments]);
13716
+ };
13717
+ }
13718
+ }
13719
+ }
13720
+ function traceForIE() {
13721
+ if (console.log) {
13722
+ if (console.log.apply) {
13723
+ console.log.apply(console, arguments);
13724
+ } else {
13725
+ Function.prototype.apply.apply(console.log, [console, arguments]);
13726
+ }
13727
+ }
13728
+ if (console.trace)
13729
+ console.trace();
13730
+ }
13731
+ function realMethod(methodName) {
13732
+ if (methodName === "debug") {
13733
+ methodName = "log";
13734
+ }
13735
+ if (typeof console === undefinedType) {
13736
+ return false;
13737
+ } else if (methodName === "trace" && isIE2) {
13738
+ return traceForIE;
13739
+ } else if (console[methodName] !== void 0) {
13740
+ return bindMethod(console, methodName);
13741
+ } else if (console.log !== void 0) {
13742
+ return bindMethod(console, "log");
13743
+ } else {
13744
+ return noop;
13745
+ }
13746
+ }
13747
+ function replaceLoggingMethods(level, loggerName) {
13748
+ for (var i = 0; i < logMethods.length; i++) {
13749
+ var methodName = logMethods[i];
13750
+ this[methodName] = i < level ? noop : this.methodFactory(methodName, level, loggerName);
13751
+ }
13752
+ this.log = this.debug;
13753
+ }
13754
+ function enableLoggingWhenConsoleArrives(methodName, level, loggerName) {
13755
+ return function() {
13756
+ if (typeof console !== undefinedType) {
13757
+ replaceLoggingMethods.call(this, level, loggerName);
13758
+ this[methodName].apply(this, arguments);
13759
+ }
13760
+ };
13761
+ }
13762
+ function defaultMethodFactory(methodName, level, loggerName) {
13763
+ return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
13764
+ }
13765
+ function Logger(name, defaultLevel, factory) {
13766
+ var self2 = this;
13767
+ var currentLevel;
13768
+ defaultLevel = defaultLevel == null ? "WARN" : defaultLevel;
13769
+ var storageKey = "loglevel";
13770
+ if (typeof name === "string") {
13771
+ storageKey += ":" + name;
13772
+ } else if (typeof name === "symbol") {
13773
+ storageKey = void 0;
13774
+ }
13775
+ function persistLevelIfPossible(levelNum) {
13776
+ var levelName = (logMethods[levelNum] || "silent").toUpperCase();
13777
+ if (typeof window === undefinedType || !storageKey)
13778
+ return;
13779
+ try {
13780
+ window.localStorage[storageKey] = levelName;
13781
+ return;
13782
+ } catch (ignore) {
13783
+ }
13784
+ try {
13785
+ window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
13786
+ } catch (ignore) {
13787
+ }
13788
+ }
13789
+ function getPersistedLevel() {
13790
+ var storedLevel;
13791
+ if (typeof window === undefinedType || !storageKey)
13792
+ return;
13793
+ try {
13794
+ storedLevel = window.localStorage[storageKey];
13795
+ } catch (ignore) {
13796
+ }
13797
+ if (typeof storedLevel === undefinedType) {
13798
+ try {
13799
+ var cookie = window.document.cookie;
13800
+ var location = cookie.indexOf(encodeURIComponent(storageKey) + "=");
13801
+ if (location !== -1) {
13802
+ storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
13803
+ }
13804
+ } catch (ignore) {
13805
+ }
13806
+ }
13807
+ if (self2.levels[storedLevel] === void 0) {
13808
+ storedLevel = void 0;
13809
+ }
13810
+ return storedLevel;
13811
+ }
13812
+ function clearPersistedLevel() {
13813
+ if (typeof window === undefinedType || !storageKey)
13814
+ return;
13815
+ try {
13816
+ window.localStorage.removeItem(storageKey);
13817
+ return;
13818
+ } catch (ignore) {
13819
+ }
13820
+ try {
13821
+ window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
13822
+ } catch (ignore) {
13823
+ }
13824
+ }
13825
+ self2.name = name;
13826
+ self2.levels = {
13827
+ "TRACE": 0,
13828
+ "DEBUG": 1,
13829
+ "INFO": 2,
13830
+ "WARN": 3,
13831
+ "ERROR": 4,
13832
+ "SILENT": 5
13833
+ };
13834
+ self2.methodFactory = factory || defaultMethodFactory;
13835
+ self2.getLevel = function() {
13836
+ return currentLevel;
13837
+ };
13838
+ self2.setLevel = function(level, persist) {
13839
+ if (typeof level === "string" && self2.levels[level.toUpperCase()] !== void 0) {
13840
+ level = self2.levels[level.toUpperCase()];
13841
+ }
13842
+ if (typeof level === "number" && level >= 0 && level <= self2.levels.SILENT) {
13843
+ currentLevel = level;
13844
+ if (persist !== false) {
13845
+ persistLevelIfPossible(level);
13846
+ }
13847
+ replaceLoggingMethods.call(self2, level, name);
13848
+ if (typeof console === undefinedType && level < self2.levels.SILENT) {
13849
+ return "No console available for logging";
13850
+ }
13851
+ } else {
13852
+ throw "log.setLevel() called with invalid level: " + level;
13853
+ }
13854
+ };
13855
+ self2.setDefaultLevel = function(level) {
13856
+ defaultLevel = level;
13857
+ if (!getPersistedLevel()) {
13858
+ self2.setLevel(level, false);
13859
+ }
13860
+ };
13861
+ self2.resetLevel = function() {
13862
+ self2.setLevel(defaultLevel, false);
13863
+ clearPersistedLevel();
13864
+ };
13865
+ self2.enableAll = function(persist) {
13866
+ self2.setLevel(self2.levels.TRACE, persist);
13867
+ };
13868
+ self2.disableAll = function(persist) {
13869
+ self2.setLevel(self2.levels.SILENT, persist);
13870
+ };
13871
+ var initialLevel = getPersistedLevel();
13872
+ if (initialLevel == null) {
13873
+ initialLevel = defaultLevel;
13874
+ }
13875
+ self2.setLevel(initialLevel, false);
13876
+ }
13877
+ var defaultLogger = new Logger();
13878
+ var _loggersByName = {};
13879
+ defaultLogger.getLogger = function getLogger(name) {
13880
+ if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
13881
+ throw new TypeError("You must supply a name when creating a logger.");
13882
+ }
13883
+ var logger = _loggersByName[name];
13884
+ if (!logger) {
13885
+ logger = _loggersByName[name] = new Logger(name, defaultLogger.getLevel(), defaultLogger.methodFactory);
13886
+ }
13887
+ return logger;
13888
+ };
13889
+ var _log = typeof window !== undefinedType ? window.log : void 0;
13890
+ defaultLogger.noConflict = function() {
13891
+ if (typeof window !== undefinedType && window.log === defaultLogger) {
13892
+ window.log = _log;
13893
+ }
13894
+ return defaultLogger;
13895
+ };
13896
+ defaultLogger.getLoggers = function getLoggers() {
13897
+ return _loggersByName;
13898
+ };
13899
+ defaultLogger["default"] = defaultLogger;
13900
+ return defaultLogger;
13901
+ });
13902
+ }
13903
+ });
13904
+
13680
13905
  // node_modules/debounce/index.js
13681
13906
  var require_debounce = __commonJS({
13682
13907
  "node_modules/debounce/index.js"(exports, module) {
@@ -34139,10 +34364,8 @@ function TaJsonDeserialize(json, type) {
34139
34364
 
34140
34365
  // src/model/Publication.ts
34141
34366
  var Publication = class extends import_publication.Publication {
34142
- static async fromUrl(url) {
34143
- const response = await fetch(url.href, {
34144
- credentials: "same-origin"
34145
- });
34367
+ static async fromUrl(url, requestConfig) {
34368
+ const response = await fetch(url.href, requestConfig);
34146
34369
  const manifestJSON = await response.json();
34147
34370
  let publication = TaJsonDeserialize(manifestJSON, Publication);
34148
34371
  publication.manifestUrl = url;
@@ -34318,7 +34541,7 @@ var Publication = class extends import_publication.Publication {
34318
34541
  const decodedHref = decodeURI(href) ?? "";
34319
34542
  return this.positions?.filter((p) => decodedHref.includes(p.href));
34320
34543
  }
34321
- async autoGeneratePositions(getContentBytesLength = fetchContentBytesLength) {
34544
+ async autoGeneratePositions(requestConfig, getContentBytesLength = fetchContentBytesLength) {
34322
34545
  let startPosition = 0;
34323
34546
  let totalContentLength = 0;
34324
34547
  const positions = [];
@@ -34337,7 +34560,7 @@ var Publication = class extends import_publication.Publication {
34337
34560
  startPosition = startPosition + 1;
34338
34561
  } else {
34339
34562
  let href = this.getAbsoluteHref(link.Href);
34340
- let length = await getContentBytesLength(href);
34563
+ let length = await getContentBytesLength(href, requestConfig);
34341
34564
  link.contentLength = length;
34342
34565
  totalContentLength += length;
34343
34566
  let positionLength = 1024;
@@ -34381,17 +34604,17 @@ var Publication = class extends import_publication.Publication {
34381
34604
  }
34382
34605
  this.positions = positions;
34383
34606
  }
34384
- async fetchPositionsFromService(href) {
34385
- const result = await fetch(href);
34607
+ async fetchPositionsFromService(href, requestConfig) {
34608
+ const result = await fetch(href, requestConfig);
34386
34609
  const content = await result.json();
34387
34610
  this.positions = content.positions;
34388
34611
  }
34389
- async fetchWeightsFromService(href) {
34612
+ async fetchWeightsFromService(href, requestConfig) {
34390
34613
  if (this.isFixedLayout) {
34391
34614
  console.warn("Not fetching weights from service for fixed layout publication.");
34392
34615
  return;
34393
34616
  }
34394
- const result = await fetch(href);
34617
+ const result = await fetch(href, requestConfig);
34395
34618
  const weights = await result.json();
34396
34619
  if (this.readingOrder !== void 0) {
34397
34620
  this.readingOrder.forEach((link) => {
@@ -34403,8 +34626,8 @@ var Publication = class extends import_publication.Publication {
34403
34626
  Publication = __decorateClass([
34404
34627
  (0, import_ta_json_x2.JsonObject)()
34405
34628
  ], Publication);
34406
- var fetchContentBytesLength = async (href) => {
34407
- const r = await fetch(href);
34629
+ var fetchContentBytesLength = async (href, requestConfig) => {
34630
+ const r = await fetch(href, requestConfig);
34408
34631
  const b = await r.blob();
34409
34632
  return b.size;
34410
34633
  };
@@ -34599,15 +34822,6 @@ function setAttr(element, attr, value) {
34599
34822
  element.setAttribute(attr, value);
34600
34823
  }
34601
34824
 
34602
- // src/utils/index.ts
34603
- init_polyfills();
34604
- function delay(t, v) {
34605
- return new Promise(function(resolve) {
34606
- setTimeout(resolve.bind(null, v), t);
34607
- });
34608
- }
34609
- var IS_DEV = false;
34610
-
34611
34825
  // src/utils/EventHandler.ts
34612
34826
  init_polyfills();
34613
34827
 
@@ -34637,7 +34851,7 @@ var Popup = class {
34637
34851
  absolute = absolute.substring(0, absolute.indexOf("#"));
34638
34852
  event.preventDefault();
34639
34853
  event.stopPropagation();
34640
- await fetch(absolute).then((r) => r.text()).then(async (data) => {
34854
+ await fetch(absolute, this.navigator.requestConfig).then((r) => r.text()).then(async (data) => {
34641
34855
  const parser = new DOMParser();
34642
34856
  const doc = parser.parseFromString(data, "text/html");
34643
34857
  const element = doc.querySelector("#" + id2);
@@ -34687,7 +34901,7 @@ var Popup = class {
34687
34901
  const d2content = document.createElement("div");
34688
34902
  d2content.className = "d2-popover-content";
34689
34903
  d2wrapper.appendChild(d2content);
34690
- await fetch(absolute).then((r) => r.text()).then(async (data) => {
34904
+ await fetch(absolute, this.navigator.requestConfig).then((r) => r.text()).then(async (data) => {
34691
34905
  d2content.innerHTML = data;
34692
34906
  let doc = this.navigator.iframes[0].contentDocument;
34693
34907
  if (doc) {
@@ -34813,6 +35027,7 @@ var Popup = class {
34813
35027
  };
34814
35028
 
34815
35029
  // src/utils/EventHandler.ts
35030
+ var import_loglevel = __toModule(require_loglevel());
34816
35031
  function addEventListenerOptional(element, eventType, eventListener) {
34817
35032
  if (element) {
34818
35033
  element.addEventListener(eventType, eventListener, true);
@@ -34844,20 +35059,17 @@ var EventHandler = class {
34844
35059
  return !link.Rel?.includes("external") && this.navigator.publication.getRelativeHref(clickedHref).includes(link.Href);
34845
35060
  });
34846
35061
  this.isReadingOrderInternal = (clickedLink) => {
34847
- if (IS_DEV)
34848
- console.log("clickedLink: ", clickedLink);
35062
+ import_loglevel.default.log("clickedLink: ", clickedLink);
34849
35063
  const isEpubInternal = this.linkInPublication(this.navigator.publication.readingOrder, clickedLink.href);
34850
35064
  return isEpubInternal;
34851
35065
  };
34852
35066
  this.isResourceInternal = (clickedLink) => {
34853
- if (IS_DEV)
34854
- console.log("clickedLink: ", clickedLink);
35067
+ import_loglevel.default.log("clickedLink: ", clickedLink);
34855
35068
  const isEpubInternal = this.linkInPublication(this.navigator.publication.resources, clickedLink.href);
34856
35069
  return isEpubInternal;
34857
35070
  };
34858
35071
  this.handleLinks = async (event) => {
34859
- if (IS_DEV)
34860
- console.log("R2 Click Handler");
35072
+ import_loglevel.default.log("R2 Click Handler");
34861
35073
  const link = this.checkForLink(event);
34862
35074
  if (link) {
34863
35075
  const isSameOrigin = window.location.protocol === link.protocol && window.location.port === link.port && window.location.hostname === link.hostname;
@@ -34867,8 +35079,8 @@ var EventHandler = class {
34867
35079
  await this.popup.hidePopover();
34868
35080
  }
34869
35081
  const isInternal = link.href.indexOf("#");
34870
- if (!isSameOrigin && !isEpubInternal && !isResourceInternal) {
34871
- window.open(link.href, "_blank");
35082
+ if (!isEpubInternal && !isResourceInternal) {
35083
+ window.open(link.href, link.target ?? "_blank");
34872
35084
  event.preventDefault();
34873
35085
  event.stopPropagation();
34874
35086
  } else {
@@ -35354,6 +35566,7 @@ var FixedBookView = class {
35354
35566
  };
35355
35567
 
35356
35568
  // src/model/user-settings/UserSettings.ts
35569
+ var import_loglevel2 = __toModule(require_loglevel());
35357
35570
  var _UserSettings = class {
35358
35571
  constructor(store, headerMenu, api, injectables, layout) {
35359
35572
  this.USERSETTINGS = "userSetting";
@@ -35392,7 +35605,7 @@ var _UserSettings = class {
35392
35605
  }
35393
35606
  async isPaginated() {
35394
35607
  let scroll = await this.getPropertyAndFallback("verticalScroll", ReadiumCSS.SCROLL_KEY);
35395
- return scroll === false;
35608
+ return !scroll;
35396
35609
  }
35397
35610
  async isScrollMode() {
35398
35611
  return !await this.isPaginated();
@@ -35412,8 +35625,7 @@ var _UserSettings = class {
35412
35625
  prop.value = settings.verticalScroll;
35413
35626
  await settings.saveProperty(prop);
35414
35627
  }
35415
- if (IS_DEV)
35416
- console.log(settings.verticalScroll);
35628
+ import_loglevel2.default.log(settings.verticalScroll);
35417
35629
  }
35418
35630
  if (initialUserSettings.appearance) {
35419
35631
  settings.appearance = _UserSettings.appearanceValues.findIndex((el) => el === initialUserSettings.appearance);
@@ -35422,8 +35634,7 @@ var _UserSettings = class {
35422
35634
  prop.value = settings.appearance;
35423
35635
  await settings.saveProperty(prop);
35424
35636
  }
35425
- if (IS_DEV)
35426
- console.log(settings.appearance);
35637
+ import_loglevel2.default.log(settings.appearance);
35427
35638
  }
35428
35639
  if (initialUserSettings.fontSize) {
35429
35640
  settings.fontSize = initialUserSettings.fontSize;
@@ -35432,8 +35643,7 @@ var _UserSettings = class {
35432
35643
  prop.value = settings.fontSize;
35433
35644
  await settings.saveProperty(prop);
35434
35645
  }
35435
- if (IS_DEV)
35436
- console.log(settings.fontSize);
35646
+ import_loglevel2.default.log(settings.fontSize);
35437
35647
  }
35438
35648
  if (initialUserSettings.fontFamily) {
35439
35649
  settings.fontFamily = _UserSettings.fontFamilyValues.findIndex((el) => el === initialUserSettings.fontFamily);
@@ -35442,8 +35652,7 @@ var _UserSettings = class {
35442
35652
  prop.value = settings.fontFamily;
35443
35653
  await settings.saveProperty(prop);
35444
35654
  }
35445
- if (IS_DEV)
35446
- console.log(settings.fontFamily);
35655
+ import_loglevel2.default.log(settings.fontFamily);
35447
35656
  if (settings.fontFamily !== 0) {
35448
35657
  settings.fontOverride = true;
35449
35658
  }
@@ -35455,8 +35664,7 @@ var _UserSettings = class {
35455
35664
  prop.value = settings.textAlignment;
35456
35665
  await settings.saveProperty(prop);
35457
35666
  }
35458
- if (IS_DEV)
35459
- console.log(settings.textAlignment);
35667
+ import_loglevel2.default.log(settings.textAlignment);
35460
35668
  }
35461
35669
  if (initialUserSettings.columnCount) {
35462
35670
  settings.columnCount = _UserSettings.columnCountValues.findIndex((el) => el === initialUserSettings.columnCount);
@@ -35465,8 +35673,7 @@ var _UserSettings = class {
35465
35673
  prop.value = settings.columnCount;
35466
35674
  await settings.saveProperty(prop);
35467
35675
  }
35468
- if (IS_DEV)
35469
- console.log(settings.columnCount);
35676
+ import_loglevel2.default.log(settings.columnCount);
35470
35677
  }
35471
35678
  if (initialUserSettings.wordSpacing) {
35472
35679
  settings.wordSpacing = initialUserSettings.wordSpacing;
@@ -35475,8 +35682,7 @@ var _UserSettings = class {
35475
35682
  prop.value = settings.wordSpacing;
35476
35683
  await settings.saveProperty(prop);
35477
35684
  }
35478
- if (IS_DEV)
35479
- console.log(settings.wordSpacing);
35685
+ import_loglevel2.default.log(settings.wordSpacing);
35480
35686
  }
35481
35687
  if (initialUserSettings.letterSpacing) {
35482
35688
  settings.letterSpacing = initialUserSettings.letterSpacing;
@@ -35485,8 +35691,7 @@ var _UserSettings = class {
35485
35691
  prop.value = settings.letterSpacing;
35486
35692
  await settings.saveProperty(prop);
35487
35693
  }
35488
- if (IS_DEV)
35489
- console.log(settings.letterSpacing);
35694
+ import_loglevel2.default.log(settings.letterSpacing);
35490
35695
  }
35491
35696
  if (initialUserSettings.pageMargins) {
35492
35697
  settings.pageMargins = initialUserSettings.pageMargins;
@@ -35495,8 +35700,7 @@ var _UserSettings = class {
35495
35700
  prop.value = settings.pageMargins;
35496
35701
  await settings.saveProperty(prop);
35497
35702
  }
35498
- if (IS_DEV)
35499
- console.log(settings.pageMargins);
35703
+ import_loglevel2.default.log(settings.pageMargins);
35500
35704
  }
35501
35705
  if (initialUserSettings.lineHeight) {
35502
35706
  settings.lineHeight = initialUserSettings.lineHeight;
@@ -35505,8 +35709,7 @@ var _UserSettings = class {
35505
35709
  prop.value = settings.lineHeight;
35506
35710
  await settings.saveProperty(prop);
35507
35711
  }
35508
- if (IS_DEV)
35509
- console.log(settings.lineHeight);
35712
+ import_loglevel2.default.log(settings.lineHeight);
35510
35713
  }
35511
35714
  settings.userProperties = settings.getUserSettings();
35512
35715
  await settings.initialise();
@@ -35515,9 +35718,7 @@ var _UserSettings = class {
35515
35718
  return new Promise((resolve) => resolve(settings));
35516
35719
  }
35517
35720
  stop() {
35518
- if (IS_DEV) {
35519
- console.log("book settings stop");
35520
- }
35721
+ import_loglevel2.default.log("book settings stop");
35521
35722
  }
35522
35723
  async initialise() {
35523
35724
  this.appearance = await this.getPropertyAndFallback("appearance", ReadiumCSS.APPEARANCE_KEY);
@@ -35675,9 +35876,9 @@ var _UserSettings = class {
35675
35876
  this.view.iframe = iframe;
35676
35877
  }
35677
35878
  if (this.settingsView)
35678
- this.renderControls(this.settingsView);
35879
+ _UserSettings.renderControls(this.settingsView);
35679
35880
  }
35680
- renderControls(element) {
35881
+ static renderControls(element) {
35681
35882
  addEventListenerOptional(findElement(element, "ul"), "click", (event) => {
35682
35883
  event.stopPropagation();
35683
35884
  });
@@ -35724,9 +35925,7 @@ var _UserSettings = class {
35724
35925
  };
35725
35926
  if (this.api?.updateSettings) {
35726
35927
  this.api?.updateSettings(userSettings).then((_) => {
35727
- if (IS_DEV) {
35728
- console.log("api updated user settings", userSettings);
35729
- }
35928
+ import_loglevel2.default.log("api updated user settings", JSON.stringify(userSettings));
35730
35929
  });
35731
35930
  }
35732
35931
  }
@@ -36457,11 +36656,12 @@ var HighlightType;
36457
36656
  HighlightType2[HighlightType2["PageBreak"] = 3] = "PageBreak";
36458
36657
  HighlightType2[HighlightType2["Definition"] = 4] = "Definition";
36459
36658
  HighlightType2[HighlightType2["LineFocus"] = 5] = "LineFocus";
36659
+ HighlightType2[HighlightType2["Comment"] = 6] = "Comment";
36460
36660
  })(HighlightType || (HighlightType = {}));
36461
36661
 
36462
36662
  // src/modules/highlight/common/rect-utils.ts
36463
36663
  init_polyfills();
36464
- var IS_DEV2 = false;
36664
+ var import_loglevel3 = __toModule(require_loglevel());
36465
36665
  function getClientRectsNoOverlap(range, doNotMergeHorizontallyAlignedRects) {
36466
36666
  const rangeClientRects = range.getClientRects();
36467
36667
  return getClientRectsNoOverlap_(rangeClientRects, doNotMergeHorizontallyAlignedRects);
@@ -36488,24 +36688,16 @@ function getClientRectsNoOverlap_(clientRects, doNotMergeHorizontallyAlignedRect
36488
36688
  const bigEnough = rect.width * rect.height > minArea;
36489
36689
  if (!bigEnough) {
36490
36690
  if (newRects.length > 1) {
36491
- if (IS_DEV2) {
36492
- console.log("CLIENT RECT: remove small");
36493
- }
36691
+ import_loglevel3.default.log("CLIENT RECT: remove small");
36494
36692
  newRects.splice(j, 1);
36495
36693
  } else {
36496
- if (IS_DEV2) {
36497
- console.log("CLIENT RECT: remove small, but keep otherwise empty!");
36498
- }
36694
+ import_loglevel3.default.log("CLIENT RECT: remove small, but keep otherwise empty!");
36499
36695
  break;
36500
36696
  }
36501
36697
  }
36502
36698
  }
36503
- if (IS_DEV2) {
36504
- checkOverlaps(newRects);
36505
- }
36506
- if (IS_DEV2) {
36507
- console.log(`CLIENT RECT: reduced ${originalRects.length} --> ${newRects.length}`);
36508
- }
36699
+ checkOverlaps(newRects);
36700
+ import_loglevel3.default.log(`CLIENT RECT: reduced ${originalRects.length} --> ${newRects.length}`);
36509
36701
  return newRects;
36510
36702
  }
36511
36703
  function almostEqual(a, b, tolerance) {
@@ -36622,9 +36814,7 @@ function mergeTouchingRects(rects, tolerance, doNotMergeHorizontallyAlignedRects
36622
36814
  const rect1 = rects[i];
36623
36815
  const rect2 = rects[j];
36624
36816
  if (rect1 === rect2) {
36625
- if (IS_DEV2) {
36626
- console.log("mergeTouchingRects rect1 === rect2 ??!");
36627
- }
36817
+ import_loglevel3.default.log("mergeTouchingRects rect1 === rect2 ??!");
36628
36818
  continue;
36629
36819
  }
36630
36820
  const rectsLineUpVertically = almostEqual(rect1.top, rect2.top, tolerance) && almostEqual(rect1.bottom, rect2.bottom, tolerance);
@@ -36633,9 +36823,7 @@ function mergeTouchingRects(rects, tolerance, doNotMergeHorizontallyAlignedRects
36633
36823
  const aligned = rectsLineUpHorizontally && horizontalAllowed || rectsLineUpVertically && !rectsLineUpHorizontally;
36634
36824
  const canMerge = aligned && rectsTouchOrOverlap(rect1, rect2, tolerance);
36635
36825
  if (canMerge) {
36636
- if (IS_DEV2) {
36637
- console.log(`CLIENT RECT: merging two into one, VERTICAL: ${rectsLineUpVertically} HORIZONTAL: ${rectsLineUpHorizontally} (${doNotMergeHorizontallyAlignedRects})`);
36638
- }
36826
+ import_loglevel3.default.log(`CLIENT RECT: merging two into one, VERTICAL: ${rectsLineUpVertically} HORIZONTAL: ${rectsLineUpHorizontally} (${doNotMergeHorizontallyAlignedRects})`);
36639
36827
  const newRects = rects.filter((rect) => {
36640
36828
  return rect !== rect1 && rect !== rect2;
36641
36829
  });
@@ -36653,9 +36841,7 @@ function replaceOverlappingRects(rects) {
36653
36841
  const rect1 = rects[i];
36654
36842
  const rect2 = rects[j];
36655
36843
  if (rect1 === rect2) {
36656
- if (IS_DEV2) {
36657
- console.log("replaceOverlappingRects rect1 === rect2 ??!");
36658
- }
36844
+ import_loglevel3.default.log("replaceOverlappingRects rect1 === rect2 ??!");
36659
36845
  continue;
36660
36846
  }
36661
36847
  if (rectsTouchOrOverlap(rect1, rect2, -1)) {
@@ -36679,15 +36865,11 @@ function replaceOverlappingRects(rects) {
36679
36865
  toPreserve = rect1;
36680
36866
  }
36681
36867
  }
36682
- if (IS_DEV2) {
36683
- const toCheck = [];
36684
- toCheck.push(toPreserve);
36685
- Array.prototype.push.apply(toCheck, toAdd);
36686
- checkOverlaps(toCheck);
36687
- }
36688
- if (IS_DEV2) {
36689
- console.log(`CLIENT RECT: overlap, cut one rect into ${toAdd.length}`);
36690
- }
36868
+ const toCheck = [];
36869
+ toCheck.push(toPreserve);
36870
+ Array.prototype.push.apply(toCheck, toAdd);
36871
+ checkOverlaps(toCheck);
36872
+ import_loglevel3.default.log(`CLIENT RECT: overlap, cut one rect into ${toAdd.length}`);
36691
36873
  const newRects = rects.filter((rect) => {
36692
36874
  return rect !== toRemove;
36693
36875
  });
@@ -36709,9 +36891,7 @@ function removeContainedRects(rects, tolerance) {
36709
36891
  for (const rect of rects) {
36710
36892
  const bigEnough = rect.width > 1 && rect.height > 1;
36711
36893
  if (!bigEnough) {
36712
- if (IS_DEV2) {
36713
- console.log("CLIENT RECT: remove tiny");
36714
- }
36894
+ import_loglevel3.default.log("CLIENT RECT: remove tiny");
36715
36895
  rectsToKeep.delete(rect);
36716
36896
  continue;
36717
36897
  }
@@ -36723,9 +36903,7 @@ function removeContainedRects(rects, tolerance) {
36723
36903
  continue;
36724
36904
  }
36725
36905
  if (rectContains(possiblyContainingRect, rect, tolerance)) {
36726
- if (IS_DEV2) {
36727
- console.log("CLIENT RECT: remove contained");
36728
- }
36906
+ import_loglevel3.default.log("CLIENT RECT: remove contained");
36729
36907
  rectsToKeep.delete(rect);
36730
36908
  break;
36731
36909
  }
@@ -36750,46 +36928,38 @@ function checkOverlaps(rects) {
36750
36928
  if (!has2) {
36751
36929
  stillOverlappingRects.push(rect2);
36752
36930
  }
36753
- if (IS_DEV2) {
36754
- console.log("CLIENT RECT: overlap ---");
36755
- console.log(`#1 TOP:${rect1.top} BOTTOM:${rect1.bottom} LEFT:${rect1.left} RIGHT:${rect1.right} WIDTH:${rect1.width} HEIGHT:${rect1.height}`);
36756
- console.log(`#2 TOP:${rect2.top} BOTTOM:${rect2.bottom} LEFT:${rect2.left} RIGHT:${rect2.right} WIDTH:${rect2.width} HEIGHT:${rect2.height}`);
36757
- const xOverlap = getRectOverlapX(rect1, rect2);
36758
- console.log(`xOverlap: ${xOverlap}`);
36759
- const yOverlap = getRectOverlapY(rect1, rect2);
36760
- console.log(`yOverlap: ${yOverlap}`);
36761
- }
36931
+ import_loglevel3.default.log("CLIENT RECT: overlap ---");
36932
+ import_loglevel3.default.log(`#1 TOP:${rect1.top} BOTTOM:${rect1.bottom} LEFT:${rect1.left} RIGHT:${rect1.right} WIDTH:${rect1.width} HEIGHT:${rect1.height}`);
36933
+ import_loglevel3.default.log(`#2 TOP:${rect2.top} BOTTOM:${rect2.bottom} LEFT:${rect2.left} RIGHT:${rect2.right} WIDTH:${rect2.width} HEIGHT:${rect2.height}`);
36934
+ const xOverlap = getRectOverlapX(rect1, rect2);
36935
+ import_loglevel3.default.log(`xOverlap: ${xOverlap}`);
36936
+ const yOverlap = getRectOverlapY(rect1, rect2);
36937
+ import_loglevel3.default.log(`yOverlap: ${yOverlap}`);
36762
36938
  }
36763
36939
  }
36764
36940
  }
36765
36941
  }
36766
36942
  if (stillOverlappingRects.length) {
36767
- if (IS_DEV2) {
36768
- console.log(`CLIENT RECT: overlaps ${stillOverlappingRects.length}`);
36769
- }
36943
+ import_loglevel3.default.log(`CLIENT RECT: overlaps ${stillOverlappingRects.length}`);
36770
36944
  }
36771
36945
  }
36772
36946
 
36773
36947
  // src/modules/highlight/renderer/iframe/selection.ts
36774
36948
  init_polyfills();
36775
- var IS_DEV3 = false;
36949
+ var import_loglevel4 = __toModule(require_loglevel());
36776
36950
  function getCurrentSelectionInfo(win, getCssSelector) {
36777
36951
  const selection = win ? win.getSelection() : null;
36778
36952
  if (!selection) {
36779
36953
  return void 0;
36780
36954
  }
36781
36955
  if (selection.isCollapsed) {
36782
- if (IS_DEV3) {
36783
- console.log("^^^ SELECTION COLLAPSED.");
36784
- }
36956
+ import_loglevel4.default.log("^^^ SELECTION COLLAPSED.");
36785
36957
  return void 0;
36786
36958
  }
36787
36959
  const rawText = selection.toString();
36788
36960
  const cleanText = rawText.trim().replace(/\n/g, " ").replace(/\s\s+/g, " ");
36789
36961
  if (cleanText.length === 0) {
36790
- if (IS_DEV3) {
36791
- console.log("^^^ SELECTION TEXT EMPTY.");
36792
- }
36962
+ import_loglevel4.default.log("^^^ SELECTION TEXT EMPTY.");
36793
36963
  return void 0;
36794
36964
  }
36795
36965
  if (!selection.anchorNode || !selection.focusNode) {
@@ -36797,45 +36967,31 @@ function getCurrentSelectionInfo(win, getCssSelector) {
36797
36967
  }
36798
36968
  const r = selection.rangeCount === 1 ? selection.getRangeAt(0) : createOrderedRange(selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
36799
36969
  if (!r || r.collapsed) {
36800
- if (IS_DEV3) {
36801
- console.log("$$$$$$$$$$$$$$$$$ CANNOT GET NON-COLLAPSED SELECTION RANGE?!");
36802
- }
36970
+ import_loglevel4.default.log("$$$$$$$$$$$$$$$$$ CANNOT GET NON-COLLAPSED SELECTION RANGE?!");
36803
36971
  return void 0;
36804
36972
  }
36805
36973
  const range = normalizeRange(r);
36806
- if (IS_DEV3) {
36807
- if (range.startContainer !== r.startContainer) {
36808
- if (IS_DEV3) {
36809
- console.log(">>>>>>>>>>>>>>>>>>>>>>> SELECTION RANGE NORMALIZE diff: startContainer");
36810
- console.log(range.startContainer);
36811
- console.log(r.startContainer);
36812
- }
36813
- }
36814
- if (range.startOffset !== r.startOffset) {
36815
- if (IS_DEV3) {
36816
- console.log(">>>>>>>>>>>>>>>>>>>>>>> SELECTION RANGE NORMALIZE diff: startOffset");
36817
- console.log(`${range.startOffset} !== ${r.startOffset}`);
36818
- }
36819
- }
36820
- if (range.endContainer !== r.endContainer) {
36821
- if (IS_DEV3) {
36822
- console.log(">>>>>>>>>>>>>>>>>>>>>>> SELECTION RANGE NORMALIZE diff: endContainer");
36823
- console.log(range.endContainer);
36824
- console.log(r.endContainer);
36825
- }
36826
- }
36827
- if (range.endOffset !== r.endOffset) {
36828
- if (IS_DEV3) {
36829
- console.log(">>>>>>>>>>>>>>>>>>>>>>> SELECTION RANGE NORMALIZE diff: endOffset");
36830
- console.log(`${range.endOffset} !== ${r.endOffset}`);
36831
- }
36832
- }
36974
+ if (range.startContainer !== r.startContainer) {
36975
+ import_loglevel4.default.log(">>>>>>>>>>>>>>>>>>>>>>> SELECTION RANGE NORMALIZE diff: startContainer");
36976
+ import_loglevel4.default.log(range.startContainer);
36977
+ import_loglevel4.default.log(r.startContainer);
36978
+ }
36979
+ if (range.startOffset !== r.startOffset) {
36980
+ import_loglevel4.default.log(">>>>>>>>>>>>>>>>>>>>>>> SELECTION RANGE NORMALIZE diff: startOffset");
36981
+ import_loglevel4.default.log(`${range.startOffset} !== ${r.startOffset}`);
36982
+ }
36983
+ if (range.endContainer !== r.endContainer) {
36984
+ import_loglevel4.default.log(">>>>>>>>>>>>>>>>>>>>>>> SELECTION RANGE NORMALIZE diff: endContainer");
36985
+ import_loglevel4.default.log(range.endContainer);
36986
+ import_loglevel4.default.log(r.endContainer);
36987
+ }
36988
+ if (range.endOffset !== r.endOffset) {
36989
+ import_loglevel4.default.log(">>>>>>>>>>>>>>>>>>>>>>> SELECTION RANGE NORMALIZE diff: endOffset");
36990
+ import_loglevel4.default.log(`${range.endOffset} !== ${r.endOffset}`);
36833
36991
  }
36834
36992
  const rangeInfo = convertRange(range, getCssSelector);
36835
36993
  if (!rangeInfo) {
36836
- if (IS_DEV3) {
36837
- console.log("^^^ SELECTION RANGE INFO FAIL?!");
36838
- }
36994
+ import_loglevel4.default.log("^^^ SELECTION RANGE INFO FAIL?!");
36839
36995
  return void 0;
36840
36996
  }
36841
36997
  return { rangeInfo, cleanText, rawText, range };
@@ -36846,26 +37002,18 @@ function createOrderedRange(startNode, startOffset, endNode, endOffset) {
36846
37002
  range.setStart(startNode, startOffset);
36847
37003
  range.setEnd(endNode, endOffset);
36848
37004
  if (!range.collapsed) {
36849
- if (IS_DEV3) {
36850
- console.log(">>> createOrderedRange RANGE OK");
36851
- }
37005
+ import_loglevel4.default.log(">>> createOrderedRange RANGE OK");
36852
37006
  return range;
36853
37007
  }
36854
- if (IS_DEV3) {
36855
- console.log(">>> createOrderedRange COLLAPSED ... RANGE REVERSE?");
36856
- }
37008
+ import_loglevel4.default.log(">>> createOrderedRange COLLAPSED ... RANGE REVERSE?");
36857
37009
  const rangeReverse = new Range();
36858
37010
  rangeReverse.setStart(endNode, endOffset);
36859
37011
  rangeReverse.setEnd(startNode, startOffset);
36860
37012
  if (!rangeReverse.collapsed) {
36861
- if (IS_DEV3) {
36862
- console.log(">>> createOrderedRange RANGE REVERSE OK.");
36863
- }
37013
+ import_loglevel4.default.log(">>> createOrderedRange RANGE REVERSE OK.");
36864
37014
  return range;
36865
37015
  }
36866
- if (IS_DEV3) {
36867
- console.log(">>> createOrderedRange RANGE REVERSE ALSO COLLAPSED?!");
36868
- }
37016
+ import_loglevel4.default.log(">>> createOrderedRange RANGE REVERSE ALSO COLLAPSED?!");
36869
37017
  return void 0;
36870
37018
  } catch (err) {
36871
37019
  console.warn(err.message);
@@ -36895,20 +37043,16 @@ function convertRange(range, getCssSelector) {
36895
37043
  const endContainerElementCssSelector = getCssSelector(endContainerElement);
36896
37044
  const commonElementAncestor = getCommonAncestorElement(range.startContainer, range.endContainer);
36897
37045
  if (!commonElementAncestor) {
36898
- if (IS_DEV3) {
36899
- console.log("^^^ NO RANGE COMMON ANCESTOR?!");
36900
- }
37046
+ import_loglevel4.default.log("^^^ NO RANGE COMMON ANCESTOR?!");
36901
37047
  return void 0;
36902
37048
  }
36903
37049
  if (range.commonAncestorContainer) {
36904
37050
  const rangeCommonAncestorElement = range.commonAncestorContainer.nodeType === Node.ELEMENT_NODE ? range.commonAncestorContainer : range.commonAncestorContainer.parentNode;
36905
37051
  if (rangeCommonAncestorElement && rangeCommonAncestorElement.nodeType === Node.ELEMENT_NODE) {
36906
37052
  if (commonElementAncestor !== rangeCommonAncestorElement) {
36907
- if (IS_DEV3) {
36908
- console.log(">>>>>> COMMON ANCESTOR CONTAINER DIFF??!");
36909
- console.log(getCssSelector(commonElementAncestor));
36910
- console.log(getCssSelector(rangeCommonAncestorElement));
36911
- }
37053
+ import_loglevel4.default.log(">>>>>> COMMON ANCESTOR CONTAINER DIFF??!");
37054
+ import_loglevel4.default.log(getCssSelector(commonElementAncestor));
37055
+ import_loglevel4.default.log(getCssSelector(rangeCommonAncestorElement));
36912
37056
  }
36913
37057
  }
36914
37058
  }
@@ -36928,47 +37072,35 @@ function convertRange(range, getCssSelector) {
36928
37072
  function convertRangeInfo(documant, rangeInfo) {
36929
37073
  const startElement = documant.querySelector(rangeInfo.startContainerElementCssSelector);
36930
37074
  if (!startElement) {
36931
- if (IS_DEV3) {
36932
- console.log("^^^ convertRangeInfo NO START ELEMENT CSS SELECTOR?!");
36933
- }
37075
+ import_loglevel4.default.log("^^^ convertRangeInfo NO START ELEMENT CSS SELECTOR?!");
36934
37076
  return void 0;
36935
37077
  }
36936
37078
  let startContainer = startElement;
36937
37079
  if (rangeInfo.startContainerChildTextNodeIndex >= 0) {
36938
37080
  if (rangeInfo.startContainerChildTextNodeIndex >= startElement.childNodes.length) {
36939
- if (IS_DEV3) {
36940
- console.log("^^^ convertRangeInfo rangeInfo.startContainerChildTextNodeIndex >= startElement.childNodes.length?!");
36941
- }
37081
+ import_loglevel4.default.log("^^^ convertRangeInfo rangeInfo.startContainerChildTextNodeIndex >= startElement.childNodes.length?!");
36942
37082
  return void 0;
36943
37083
  }
36944
37084
  startContainer = startElement.childNodes[rangeInfo.startContainerChildTextNodeIndex];
36945
37085
  if (startContainer.nodeType !== Node.TEXT_NODE) {
36946
- if (IS_DEV3) {
36947
- console.log("^^^ convertRangeInfo startContainer.nodeType !== Node.TEXT_NODE?!");
36948
- }
37086
+ import_loglevel4.default.log("^^^ convertRangeInfo startContainer.nodeType !== Node.TEXT_NODE?!");
36949
37087
  return void 0;
36950
37088
  }
36951
37089
  }
36952
37090
  const endElement = documant.querySelector(rangeInfo.endContainerElementCssSelector);
36953
37091
  if (!endElement) {
36954
- if (IS_DEV3) {
36955
- console.log("^^^ convertRangeInfo NO END ELEMENT CSS SELECTOR?!");
36956
- }
37092
+ import_loglevel4.default.log("^^^ convertRangeInfo NO END ELEMENT CSS SELECTOR?!");
36957
37093
  return void 0;
36958
37094
  }
36959
37095
  let endContainer = endElement;
36960
37096
  if (rangeInfo.endContainerChildTextNodeIndex >= 0) {
36961
37097
  if (rangeInfo.endContainerChildTextNodeIndex >= endElement.childNodes.length) {
36962
- if (IS_DEV3) {
36963
- console.log("^^^ convertRangeInfo rangeInfo.endContainerChildTextNodeIndex >= endElement.childNodes.length?!");
36964
- }
37098
+ import_loglevel4.default.log("^^^ convertRangeInfo rangeInfo.endContainerChildTextNodeIndex >= endElement.childNodes.length?!");
36965
37099
  return void 0;
36966
37100
  }
36967
37101
  endContainer = endElement.childNodes[rangeInfo.endContainerChildTextNodeIndex];
36968
37102
  if (endContainer.nodeType !== Node.TEXT_NODE) {
36969
- if (IS_DEV3) {
36970
- console.log("^^^ convertRangeInfo endContainer.nodeType !== Node.TEXT_NODE?!");
36971
- }
37103
+ import_loglevel4.default.log("^^^ convertRangeInfo endContainer.nodeType !== Node.TEXT_NODE?!");
36972
37104
  return void 0;
36973
37105
  }
36974
37106
  }
@@ -37335,6 +37467,7 @@ var AnnotationMarker;
37335
37467
  AnnotationMarker2[AnnotationMarker2["Underline"] = 1] = "Underline";
37336
37468
  AnnotationMarker2[AnnotationMarker2["Bookmark"] = 2] = "Bookmark";
37337
37469
  AnnotationMarker2[AnnotationMarker2["Custom"] = 3] = "Custom";
37470
+ AnnotationMarker2[AnnotationMarker2["Comment"] = 4] = "Comment";
37338
37471
  })(AnnotationMarker || (AnnotationMarker = {}));
37339
37472
 
37340
37473
  // src/utils/IconLib.ts
@@ -37375,6 +37508,7 @@ var icons = {
37375
37508
 
37376
37509
  // src/modules/highlight/TextHighlighter.ts
37377
37510
  var lodash = __toModule(require_lodash());
37511
+ var import_loglevel5 = __toModule(require_loglevel());
37378
37512
  var HighlightContainer;
37379
37513
  (function(HighlightContainer2) {
37380
37514
  HighlightContainer2["R2_ID_HIGHLIGHTS_CONTAINER"] = "R2_ID_HIGHLIGHTS_CONTAINER";
@@ -37384,6 +37518,7 @@ var HighlightContainer;
37384
37518
  HighlightContainer2["R2_ID_SEARCH_CONTAINER"] = "R2_ID_SEARCH_CONTAINER";
37385
37519
  HighlightContainer2["R2_ID_DEFINITIONS_CONTAINER"] = "R2_ID_DEFINITIONS_CONTAINER";
37386
37520
  HighlightContainer2["R2_ID_LINEFOCUS_CONTAINER"] = "R2_ID_LINEFOCUS_CONTAINER";
37521
+ HighlightContainer2["R2_ID_GUTTER_RIGHT_CONTAINER"] = "R2_ID_GUTTER_RIGHT_CONTAINER";
37387
37522
  })(HighlightContainer || (HighlightContainer = {}));
37388
37523
  var CLASS_HIGHLIGHT_CONTAINER = "R2_CLASS_HIGHLIGHT_CONTAINER";
37389
37524
  var CLASS_HIGHLIGHT_BOUNDING_AREA = "R2_CLASS_HIGHLIGHT_BOUNDING_AREA";
@@ -37411,6 +37546,7 @@ var _blacklistIdClassForCssSelectors = [
37411
37546
  HighlightContainer.R2_ID_BOOKMAKRS_CONTAINER,
37412
37547
  HighlightContainer.R2_ID_DEFINITIONS_CONTAINER,
37413
37548
  HighlightContainer.R2_ID_LINEFOCUS_CONTAINER,
37549
+ HighlightContainer.R2_ID_GUTTER_RIGHT_CONTAINER,
37414
37550
  CLASS_HIGHLIGHT_CONTAINER,
37415
37551
  CLASS_HIGHLIGHT_AREA,
37416
37552
  CLASS_HIGHLIGHT_BOUNDING_AREA
@@ -37421,6 +37557,12 @@ var TextHighlighter = class {
37421
37557
  constructor(delegate, layerSettings, properties, hasEventListener, options, api) {
37422
37558
  this.lastSelectedHighlight = void 0;
37423
37559
  this.activeAnnotationMarkerId = void 0;
37560
+ this.showTool = (0, import_debounce2.debounce)((b) => {
37561
+ if (!this.isAndroid()) {
37562
+ this.snapSelectionToWord(b);
37563
+ }
37564
+ this.toolboxShow();
37565
+ }, navigator.userAgent.toLowerCase().indexOf("firefox") > -1 ? 200 : 100);
37424
37566
  this.isSelectionMenuOpen = false;
37425
37567
  this.selectionMenuOpened = (0, import_debounce2.debounce)(() => {
37426
37568
  if (!this.isSelectionMenuOpen) {
@@ -37825,8 +37967,6 @@ var TextHighlighter = class {
37825
37967
  colorButton.style.position = "relative";
37826
37968
  colorButton.style.display = "unset";
37827
37969
  colorElements.push(colorButton);
37828
- const highlightIcon2 = document.getElementById("highlightIcon");
37829
- const underlineIcon = document.getElementById("underlineIcon");
37830
37970
  if (colorIcon) {
37831
37971
  colorButton.addEventListener("click", function() {
37832
37972
  self2.setColor(color);
@@ -37834,12 +37974,18 @@ var TextHighlighter = class {
37834
37974
  if (colorIconSymbol) {
37835
37975
  colorIconSymbol.style.backgroundColor = color;
37836
37976
  }
37977
+ const highlightIcon2 = document.getElementById("highlightIcon");
37978
+ const underlineIcon = document.getElementById("underlineIcon");
37979
+ const noteIcon = document.getElementById("noteIcon");
37837
37980
  if ((highlightIcon2?.getElementsByTagName?.("span").length ?? 0) > 0) {
37838
37981
  (highlightIcon2?.getElementsByTagName("span")[0]).style.background = self2.getColor();
37839
37982
  }
37840
37983
  if ((underlineIcon?.getElementsByTagName?.("span").length ?? 0) > 0) {
37841
37984
  (underlineIcon?.getElementsByTagName("span")[0]).style.borderBottomColor = self2.getColor();
37842
37985
  }
37986
+ if ((noteIcon?.getElementsByTagName?.("span").length ?? 0) > 0) {
37987
+ (noteIcon?.getElementsByTagName("span")[0]).style.borderBottomColor = self2.getColor();
37988
+ }
37843
37989
  self2.toolboxMode("add");
37844
37990
  });
37845
37991
  }
@@ -37907,20 +38053,14 @@ var TextHighlighter = class {
37907
38053
  toolbox.style.display = "none";
37908
38054
  this.selectionMenuClosed();
37909
38055
  }
37910
- toolboxShowDelayed(ev) {
37911
- let self2 = this;
37912
- setTimeout(function() {
37913
- if (!self2.isAndroid()) {
37914
- self2.snapSelectionToWord(ev.detail === 1);
37915
- }
37916
- self2.toolboxShow();
37917
- }, 100);
38056
+ toolboxShowDelayed(event) {
38057
+ this.showTool(event.detail === 1);
37918
38058
  }
37919
38059
  snapSelectionToWord(trimmed = false) {
37920
38060
  let self2 = this;
37921
38061
  let doc = this.delegate.iframes[0].contentDocument;
37922
38062
  if (doc) {
37923
- let selection = self2.dom(doc.body)?.getWindow()?.getSelection();
38063
+ let selection = self2.dom(doc.body)?.getSelection();
37924
38064
  if (self2.dom(doc.body)) {
37925
38065
  if (selection && !selection?.isCollapsed) {
37926
38066
  let removeTrailingPunctuation = function(text2) {
@@ -37934,7 +38074,7 @@ var TextHighlighter = class {
37934
38074
  let startOffsetTemp = text.length - text.trimStart().length;
37935
38075
  let endOffsetTemp = text.length - text.trimEnd().length;
37936
38076
  let length = text.length;
37937
- var regex_symbols = /[-!$%^&*()_+|~=`{}\[\]:\/;<>?,.@#]/;
38077
+ var regex_symbols = /[-!$%^&*()_+|~=`{}[\]:/;<>?,.@#]/;
37938
38078
  text = text.replace(regex_symbols, "");
37939
38079
  startOffsetTemp = length - text.trimStart().length;
37940
38080
  text = removeTrailingPunctuation(text);
@@ -37989,7 +38129,6 @@ var TextHighlighter = class {
37989
38129
  return;
37990
38130
  }
37991
38131
  if (this.isIOS()) {
37992
- this.delegate.iframes[0].contentDocument?.body.removeEventListener("selectionchange", this.toolboxPlacement.bind(this));
37993
38132
  setTimeout(function() {
37994
38133
  let doc = self2.delegate.iframes[0].contentDocument;
37995
38134
  if (doc) {
@@ -37997,6 +38136,25 @@ var TextHighlighter = class {
37997
38136
  selection.removeAllRanges();
37998
38137
  setTimeout(function() {
37999
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);
38000
38158
  }, 5);
38001
38159
  }
38002
38160
  }, 100);
@@ -38039,6 +38197,7 @@ var TextHighlighter = class {
38039
38197
  let highlightIcon = document.getElementById("highlightIcon");
38040
38198
  let collapseIcon = document.getElementById("collapseIcon");
38041
38199
  let underlineIcon = document.getElementById("underlineIcon");
38200
+ let noteIcon = document.getElementById("noteIcon");
38042
38201
  let colorIcon = document.getElementById("colorIcon");
38043
38202
  let speakIcon = document.getElementById("speakIcon");
38044
38203
  if (this.delegate.rights.enableAnnotations) {
@@ -38058,6 +38217,14 @@ var TextHighlighter = class {
38058
38217
  }
38059
38218
  }
38060
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
+ }
38061
38228
  if (colorIcon) {
38062
38229
  colorIcon.style.display = "unset";
38063
38230
  let colorIconSymbol = colorIcon.lastChild;
@@ -38069,7 +38236,10 @@ var TextHighlighter = class {
38069
38236
  self2.toolboxHide();
38070
38237
  highlightIcon?.removeEventListener("click", highlightEvent);
38071
38238
  };
38072
- 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);
38073
38243
  }
38074
38244
  if (underlineIcon) {
38075
38245
  let commentEvent = function() {
@@ -38077,7 +38247,21 @@ var TextHighlighter = class {
38077
38247
  self2.toolboxHide();
38078
38248
  underlineIcon?.removeEventListener("click", commentEvent);
38079
38249
  };
38080
- 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);
38081
38265
  }
38082
38266
  } else {
38083
38267
  if (highlightIcon) {
@@ -38086,6 +38270,9 @@ var TextHighlighter = class {
38086
38270
  if (underlineIcon) {
38087
38271
  underlineIcon.style.setProperty("display", "none");
38088
38272
  }
38273
+ if (noteIcon) {
38274
+ noteIcon.style.setProperty("display", "none");
38275
+ }
38089
38276
  if (colorIcon) {
38090
38277
  colorIcon.style.setProperty("display", "none");
38091
38278
  }
@@ -38099,7 +38286,10 @@ var TextHighlighter = class {
38099
38286
  speakIcon?.removeEventListener("click", speakEvent);
38100
38287
  self2.speak();
38101
38288
  };
38102
- 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);
38103
38293
  }
38104
38294
  } else {
38105
38295
  if (speakIcon) {
@@ -38111,7 +38301,7 @@ var TextHighlighter = class {
38111
38301
  if (menuItem.icon) {
38112
38302
  menuItem.icon.id = menuItem.id;
38113
38303
  }
38114
- const itemElement = document.getElementById(menuItem.id);
38304
+ let itemElement = document.getElementById(menuItem.id);
38115
38305
  const self3 = this;
38116
38306
  function itemEvent() {
38117
38307
  itemElement?.removeEventListener("click", itemEvent);
@@ -38133,7 +38323,11 @@ var TextHighlighter = class {
38133
38323
  }
38134
38324
  let win = self3.delegate.iframes[0].contentWindow;
38135
38325
  if (win) {
38136
- 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
+ }
38137
38331
  if (selectionInfo !== void 0) {
38138
38332
  if (menuItem.callback) {
38139
38333
  menuItem.callback(selectionInfo.cleanText, selectionInfo.range?.startContainer.parentElement);
@@ -38149,13 +38343,12 @@ var TextHighlighter = class {
38149
38343
  self3.delegate.annotationModule?.saveAnnotation(highlight[0]).then((anno) => {
38150
38344
  if (menuItem?.note) {
38151
38345
  if (anno.highlight) {
38152
- 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
+ });
38153
38351
  }
38154
- self3.delegate.annotationModule?.updateAnnotation(anno).then(async () => {
38155
- if (IS_DEV) {
38156
- console.log("update highlight " + anno.id);
38157
- }
38158
- });
38159
38352
  }
38160
38353
  });
38161
38354
  } else if (self3.delegate.rights.enableBookmarks) {
@@ -38169,7 +38362,10 @@ var TextHighlighter = class {
38169
38362
  self3.callbackComplete();
38170
38363
  }
38171
38364
  if (itemElement) {
38172
- 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);
38173
38369
  }
38174
38370
  });
38175
38371
  }
@@ -38196,7 +38392,11 @@ var TextHighlighter = class {
38196
38392
  }
38197
38393
  let win = self2.delegate.iframes[0].contentWindow;
38198
38394
  if (win) {
38199
- 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
+ }
38200
38400
  if (selectionInfo) {
38201
38401
  if (this.options.onBeforeHighlight(selectionInfo) === true) {
38202
38402
  let createColor;
@@ -38246,7 +38446,11 @@ var TextHighlighter = class {
38246
38446
  let self2 = this;
38247
38447
  let win = self2.delegate.iframes[0].contentWindow;
38248
38448
  if (win) {
38249
- 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
+ }
38250
38454
  if (selectionInfo !== void 0) {
38251
38455
  this.delegate.ttsModule.speak(selectionInfo, true, () => {
38252
38456
  });
@@ -38341,11 +38545,9 @@ var TextHighlighter = class {
38341
38545
  range.detach();
38342
38546
  return rect;
38343
38547
  } catch (error) {
38344
- if (IS_DEV) {
38345
- console.log("measureTextNode " + error);
38346
- console.log("measureTextNode " + node);
38347
- console.log(node.textContent);
38348
- }
38548
+ import_loglevel5.default.log("measureTextNode " + error);
38549
+ import_loglevel5.default.log("measureTextNode " + node);
38550
+ import_loglevel5.default.log(`${node.textContent}`);
38349
38551
  }
38350
38552
  };
38351
38553
  const body = findRequiredIframeElement(doc, "body");
@@ -38537,7 +38739,7 @@ var TextHighlighter = class {
38537
38739
  highlightArea.classList.remove("hover");
38538
38740
  }
38539
38741
  }
38540
- } else if (highlight.marker === AnnotationMarker.Underline) {
38742
+ } else if (highlight.marker === AnnotationMarker.Underline || highlight.marker === AnnotationMarker.Comment) {
38541
38743
  if (typeof highlight.color === "object") {
38542
38744
  let color = highlight.color;
38543
38745
  highlightArea.style.setProperty("background-color", `rgba(${color.red}, ${color.green}, ${color.blue}, ${0})`, "important");
@@ -38611,7 +38813,7 @@ var TextHighlighter = class {
38611
38813
  highlightArea.classList.add("hover");
38612
38814
  }
38613
38815
  }
38614
- } else if (highlight.marker === AnnotationMarker.Underline) {
38816
+ } else if (highlight.marker === AnnotationMarker.Underline || highlight.marker === AnnotationMarker.Comment) {
38615
38817
  if (typeof highlight.color === "object") {
38616
38818
  let color = highlight.color;
38617
38819
  highlightArea.style.setProperty("background-color", `rgba(${color.red}, ${color.green}, ${color.blue}, ${0.1})`, "important");
@@ -38797,9 +38999,7 @@ var TextHighlighter = class {
38797
38999
  const payload = {
38798
39000
  highlight: foundHighlight
38799
39001
  };
38800
- if (IS_DEV) {
38801
- console.log(payload);
38802
- }
39002
+ import_loglevel5.default.log(JSON.stringify(payload));
38803
39003
  let self2 = this;
38804
39004
  let anno;
38805
39005
  if (self2.delegate.rights.enableAnnotations) {
@@ -38812,9 +39012,7 @@ var TextHighlighter = class {
38812
39012
  });
38813
39013
  }
38814
39014
  if (anno?.id) {
38815
- if (IS_DEV) {
38816
- console.log("selected highlight " + anno.id);
38817
- }
39015
+ import_loglevel5.default.log("selected highlight " + anno.id);
38818
39016
  self2.lastSelectedHighlight = anno.id;
38819
39017
  let toolbox = document.getElementById("highlight-toolbox");
38820
39018
  if (toolbox) {
@@ -38822,27 +39020,24 @@ var TextHighlighter = class {
38822
39020
  toolbox.style.left = ev.clientX + "px";
38823
39021
  if (getComputedStyle(toolbox).display === "none") {
38824
39022
  let noteH = function() {
38825
- anno.highlight.note = prompt("Add your note here:");
38826
- self2.delegate.annotationModule?.updateAnnotation(anno).then(async () => {
38827
- if (IS_DEV) {
38828
- console.log("update highlight " + anno.id);
38829
- }
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
+ });
38830
39031
  if (toolbox) {
38831
39032
  toolbox.style.display = "none";
38832
39033
  }
38833
39034
  self2.selectionMenuClosed();
39035
+ commentIcon?.removeEventListener("click", noteH, false);
38834
39036
  });
38835
- if (toolbox) {
38836
- toolbox.style.display = "none";
38837
- }
38838
- self2.selectionMenuClosed();
38839
- commentIcon?.removeEventListener("click", noteH, false);
38840
39037
  }, deleteH = function() {
38841
39038
  if (self2.delegate.rights.enableAnnotations) {
38842
39039
  self2.delegate.annotationModule?.deleteSelectedHighlight(anno).then(async () => {
38843
- if (IS_DEV) {
38844
- console.log("delete highlight " + anno.id);
38845
- }
39040
+ import_loglevel5.default.log("delete highlight " + anno.id);
38846
39041
  if (toolbox) {
38847
39042
  toolbox.style.display = "none";
38848
39043
  }
@@ -38850,9 +39045,7 @@ var TextHighlighter = class {
38850
39045
  });
38851
39046
  } else if (self2.delegate.rights.enableBookmarks) {
38852
39047
  self2.delegate.bookmarkModule?.deleteSelectedHighlight(anno).then(async () => {
38853
- if (IS_DEV) {
38854
- console.log("delete highlight " + anno.id);
38855
- }
39048
+ import_loglevel5.default.log("delete highlight " + anno.id);
38856
39049
  if (toolbox) {
38857
39050
  toolbox.style.display = "none";
38858
39051
  }
@@ -38921,7 +39114,7 @@ var TextHighlighter = class {
38921
39114
  popup.showPopup(foundElement.dataset.definition, ev);
38922
39115
  }
38923
39116
  let result = this.delegate.definitionsModule?.properties?.definitions?.filter((el) => el.order === Number(foundElement?.dataset.order))[0];
38924
- console.log(result);
39117
+ import_loglevel5.default.log(result);
38925
39118
  if (this.delegate.definitionsModule?.api?.click) {
38926
39119
  this.delegate.definitionsModule.api?.click(lodash.omit(result, "callbacks"), lodash.omit(foundHighlight, "definition"));
38927
39120
  this.delegate.emit("definition.click", result, foundHighlight);
@@ -38940,7 +39133,9 @@ var TextHighlighter = class {
38940
39133
  if (!doc.getElementById(id2)) {
38941
39134
  let container = doc.createElement("div");
38942
39135
  container.setAttribute("id", id2);
38943
- container.style.setProperty("pointer-events", "none");
39136
+ if (id2 !== HighlightContainer.R2_ID_GUTTER_RIGHT_CONTAINER) {
39137
+ container.style.setProperty("pointer-events", "none");
39138
+ }
38944
39139
  if (this.delegate.view?.layout === "fixed") {
38945
39140
  container.style.setProperty("position", "absolute");
38946
39141
  container.style.setProperty("top", "0");
@@ -39006,6 +39201,12 @@ var TextHighlighter = class {
39006
39201
  this.removeAllChildNodes(container);
39007
39202
  }
39008
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;
39009
39210
  default:
39010
39211
  container = doc.getElementById(HighlightContainer.R2_ID_HIGHLIGHTS_CONTAINER);
39011
39212
  if (container) {
@@ -39104,7 +39305,7 @@ var TextHighlighter = class {
39104
39305
  highlightArea.setAttribute("class", CLASS_HIGHLIGHT_AREA);
39105
39306
  highlightArea.dataset.marker = "" + highlight.marker;
39106
39307
  let extra = "";
39107
- 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) {
39108
39309
  let color = highlight.color;
39109
39310
  if (TextHighlighter.isHexColor(color)) {
39110
39311
  color = TextHighlighter.hexToRgbChannels(color);
@@ -39122,7 +39323,7 @@ var TextHighlighter = class {
39122
39323
  highlightArea.classList.add(highlight.style?.defaultClass);
39123
39324
  highlightArea.setAttribute("style", `mix-blend-mode: multiply; border-radius: ${roundedCorner}px !important; ${extra}`);
39124
39325
  }
39125
- } else if (highlight.marker === AnnotationMarker.Underline) {
39326
+ } else if (highlight.marker === AnnotationMarker.Underline || highlight.marker === AnnotationMarker.Comment) {
39126
39327
  if (typeof highlight.color === "object") {
39127
39328
  let color = highlight.color;
39128
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}`);
@@ -39255,8 +39456,10 @@ var TextHighlighter = class {
39255
39456
  let half = third * 2;
39256
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;`);
39257
39458
  } else {
39258
- 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) {
39259
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;`);
39260
39463
  } else {
39261
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;`);
39262
39465
  }
@@ -39267,7 +39470,7 @@ var TextHighlighter = class {
39267
39470
  highlightAreaIcon.id = highlight.icon?.id;
39268
39471
  } else if (highlight.icon?.svgPath) {
39269
39472
  highlightAreaIcon.innerHTML = iconTemplateColored(`${highlight.icon?.id}`, `${highlight.icon?.title}`, `${highlight.icon?.svgPath}`, `icon open`, size, `${highlight.icon?.color} !important`);
39270
- } else {
39473
+ } else if (highlight.icon?.title) {
39271
39474
  highlightAreaIcon.innerHTML = highlight.icon?.title;
39272
39475
  }
39273
39476
  } else {
@@ -39276,7 +39479,11 @@ var TextHighlighter = class {
39276
39479
  if (TextHighlighter.isHexColor(color)) {
39277
39480
  color = TextHighlighter.hexToRgbChannels(color);
39278
39481
  }
39279
- 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
+ }
39280
39487
  }
39281
39488
  }
39282
39489
  highlightAreaIcon.style.setProperty("pointer-events", "all");
@@ -39291,9 +39498,7 @@ var TextHighlighter = class {
39291
39498
  } else if (self2.delegate.rights.enableBookmarks) {
39292
39499
  anno = await self2.delegate.bookmarkModule?.getAnnotationByID(highlight.id);
39293
39500
  }
39294
- if (IS_DEV) {
39295
- console.log("selected highlight " + anno.id);
39296
- }
39501
+ import_loglevel5.default.log("selected highlight " + anno.id);
39297
39502
  self2.lastSelectedHighlight = anno.id;
39298
39503
  let toolbox = document.getElementById("highlight-toolbox");
39299
39504
  if (toolbox) {
@@ -39301,30 +39506,25 @@ var TextHighlighter = class {
39301
39506
  toolbox.style.left = ev.clientX + "px";
39302
39507
  if (getComputedStyle(toolbox).display === "none") {
39303
39508
  let noteH = function() {
39304
- anno.highlight.note = prompt("Add your note here:");
39305
- self2.delegate.annotationModule?.updateAnnotation(anno).then(async () => {
39306
- if (IS_DEV) {
39307
- console.log("update highlight " + anno.id);
39308
- }
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
+ });
39309
39515
  toolbox.style.display = "none";
39310
39516
  self2.selectionMenuClosed();
39311
39517
  });
39312
- toolbox.style.display = "none";
39313
- self2.selectionMenuClosed();
39314
39518
  }, deleteH = function() {
39315
39519
  if (self2.delegate.rights.enableAnnotations) {
39316
39520
  self2.delegate.annotationModule?.deleteSelectedHighlight(anno).then(async () => {
39317
- if (IS_DEV) {
39318
- console.log("delete highlight " + anno.id);
39319
- }
39521
+ import_loglevel5.default.log("delete highlight " + anno.id);
39320
39522
  toolbox.style.display = "none";
39321
39523
  self2.selectionMenuClosed();
39322
39524
  });
39323
39525
  } else if (self2.delegate.rights.enableBookmarks) {
39324
39526
  self2.delegate.bookmarkModule?.deleteSelectedHighlight(anno).then(async () => {
39325
- if (IS_DEV) {
39326
- console.log("delete highlight " + anno.id);
39327
- }
39527
+ import_loglevel5.default.log("delete highlight " + anno.id);
39328
39528
  toolbox.style.display = "none";
39329
39529
  self2.selectionMenuClosed();
39330
39530
  });
@@ -39407,7 +39607,6 @@ var TextHighlighter = class {
39407
39607
  tooltip.style.setProperty("background", "lightyellow");
39408
39608
  tooltip.style.setProperty("color", "black");
39409
39609
  }
39410
- highlightAreaIcon.insertBefore(tooltip, highlightAreaIcon.childNodes[0]);
39411
39610
  }
39412
39611
  if (highlight.note || highlight.marker === AnnotationMarker.Custom || highlight.marker === AnnotationMarker.Bookmark) {
39413
39612
  highlightParent.append(highlightAreaIcon);
@@ -39443,6 +39642,7 @@ var import_uuid = __toModule(require_uuid());
39443
39642
 
39444
39643
  // src/modules/highlight/common/selection.ts
39445
39644
  init_polyfills();
39645
+ var import_loglevel6 = __toModule(require_loglevel());
39446
39646
  var _getCssSelectorOptions = {
39447
39647
  className: (_str) => {
39448
39648
  return true;
@@ -39457,6 +39657,7 @@ var _getCssSelectorOptions = {
39457
39657
 
39458
39658
  // src/modules/AnnotationModule.ts
39459
39659
  var lodash2 = __toModule(require_lodash());
39660
+ var import_loglevel7 = __toModule(require_loglevel());
39460
39661
  var AnnotationModule = class {
39461
39662
  constructor(annotator, rights, publication, delegate, initialAnnotations, properties, highlighter, api, headerMenu) {
39462
39663
  this.hide = findElement(document, "#menu-button-hide");
@@ -39477,9 +39678,7 @@ var AnnotationModule = class {
39477
39678
  return annotations;
39478
39679
  }
39479
39680
  async stop() {
39480
- if (IS_DEV) {
39481
- console.log("Annotation module stop");
39482
- }
39681
+ import_loglevel7.default.log("Annotation module stop");
39483
39682
  }
39484
39683
  async start() {
39485
39684
  this.delegate.annotationModule = this;
@@ -39525,7 +39724,7 @@ var AnnotationModule = class {
39525
39724
  setTimeout(async () => {
39526
39725
  await this.drawHighlights();
39527
39726
  await this.showHighlights();
39528
- }, 100);
39727
+ }, 200);
39529
39728
  }
39530
39729
  initialize() {
39531
39730
  return new Promise(async (resolve) => {
@@ -39562,8 +39761,8 @@ var AnnotationModule = class {
39562
39761
  return "";
39563
39762
  }
39564
39763
  } catch (err) {
39565
- console.log("uniqueCssSelector:");
39566
- console.log(err);
39764
+ import_loglevel7.default.log("uniqueCssSelector:");
39765
+ import_loglevel7.default.error(err);
39567
39766
  return "";
39568
39767
  }
39569
39768
  };
@@ -39584,9 +39783,7 @@ var AnnotationModule = class {
39584
39783
  let book = this.delegate.highlighter?.createHighlight(this.delegate.highlighter?.dom(doc.body).getWindow(), selectionInfo, menuItem.highlight.color, true, AnnotationMarker.Bookmark, menuItem.icon, menuItem.popup, menuItem.highlight.style);
39585
39784
  if (book) {
39586
39785
  this.saveAnnotation(book[0]).then((anno) => {
39587
- if (IS_DEV) {
39588
- console.log("saved bookmark " + anno.id);
39589
- }
39786
+ import_loglevel7.default.log("saved bookmark " + anno.id);
39590
39787
  });
39591
39788
  }
39592
39789
  }
@@ -39596,20 +39793,19 @@ var AnnotationModule = class {
39596
39793
  }
39597
39794
  }
39598
39795
  async scrollToHighlight(id2) {
39599
- if (IS_DEV) {
39600
- console.log("still need to scroll to " + id2);
39601
- }
39602
- var position = await this.annotator?.getAnnotationPosition(id2, this.delegate.iframes[0].contentWindow);
39603
- window.scrollTo(0, position - window.innerHeight / 3);
39796
+ import_loglevel7.default.log("still need to scroll to " + id2);
39797
+ var element = await this.annotator?.getAnnotationElement(id2, this.delegate.iframes[0].contentWindow);
39798
+ element.scrollIntoView({
39799
+ block: "center",
39800
+ behavior: "smooth"
39801
+ });
39604
39802
  }
39605
39803
  async updateLocalHighlight(annotation) {
39606
39804
  if (this.annotator) {
39607
39805
  let deleted = await this.annotator.deleteAnnotation(annotation.id);
39608
39806
  let added = await this.addAnnotation(annotation);
39609
- if (IS_DEV) {
39610
- console.log("Highlight deleted " + JSON.stringify(deleted));
39611
- console.log("Highlight added " + JSON.stringify(added));
39612
- }
39807
+ import_loglevel7.default.log("Highlight deleted " + JSON.stringify(deleted));
39808
+ import_loglevel7.default.log("Highlight added " + JSON.stringify(added));
39613
39809
  await this.showHighlights();
39614
39810
  await this.drawHighlights();
39615
39811
  return added;
@@ -39620,9 +39816,7 @@ var AnnotationModule = class {
39620
39816
  async deleteLocalHighlight(id2) {
39621
39817
  if (this.annotator) {
39622
39818
  var deleted = await this.annotator.deleteAnnotation(id2);
39623
- if (IS_DEV) {
39624
- console.log("Highlight deleted " + JSON.stringify(deleted));
39625
- }
39819
+ import_loglevel7.default.log("Highlight deleted " + JSON.stringify(deleted));
39626
39820
  await this.showHighlights();
39627
39821
  await this.drawHighlights();
39628
39822
  return deleted;
@@ -39719,11 +39913,16 @@ var AnnotationModule = class {
39719
39913
  }
39720
39914
  if (annotation) {
39721
39915
  if (this.api?.addAnnotation) {
39722
- let result = await this.api.addAnnotation(annotation);
39723
- const saved = await this.annotator.saveAnnotation(result);
39724
- await this.showHighlights();
39725
- await this.drawHighlights();
39726
- 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
+ }
39727
39926
  } else {
39728
39927
  const saved = await this.annotator.saveAnnotation(annotation);
39729
39928
  await this.showHighlights();
@@ -39853,6 +40052,65 @@ var AnnotationModule = class {
39853
40052
  if (this.properties?.initialAnnotationColor) {
39854
40053
  this.highlighter.setColor(this.properties?.initialAnnotationColor);
39855
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
+ }
39856
40114
  }
39857
40115
  }
39858
40116
  createTree(type, annotations, view) {
@@ -39985,23 +40243,17 @@ var AnnotationModule = class {
39985
40243
  this.delegate.stopReadAloud();
39986
40244
  this.delegate.navigate(locator);
39987
40245
  } else {
39988
- if (IS_DEV) {
39989
- console.log("annotation data missing: ", event);
39990
- }
40246
+ import_loglevel7.default.log("annotation data missing: ", event);
39991
40247
  }
39992
40248
  }
39993
40249
  handleAnnotationLinkDeleteClick(type, event, locator) {
39994
- if (IS_DEV) {
39995
- console.log("annotation data locator: ", locator);
39996
- }
40250
+ import_loglevel7.default.log("annotation data locator: ", locator);
39997
40251
  if (locator) {
39998
40252
  if (type === AnnotationType.Annotation) {
39999
40253
  this.deleteHighlight(locator);
40000
40254
  }
40001
40255
  } else {
40002
- if (IS_DEV) {
40003
- console.log("annotation data missing: ", event);
40004
- }
40256
+ import_loglevel7.default.log("annotation data missing: ", event);
40005
40257
  }
40006
40258
  }
40007
40259
  static readableTimestamp(timestamp) {
@@ -40014,11 +40266,62 @@ var AnnotationModule = class {
40014
40266
  async getAnnotationByID(id2) {
40015
40267
  return this.annotator?.getAnnotationByID(id2);
40016
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
+ }
40017
40319
  };
40018
40320
 
40019
40321
  // src/modules/BookmarkModule.ts
40020
40322
  init_polyfills();
40021
40323
  var import_uuid2 = __toModule(require_uuid());
40324
+ var import_loglevel8 = __toModule(require_loglevel());
40022
40325
  var BookmarkModule = class {
40023
40326
  static async create(config2) {
40024
40327
  const module = new this(config2.annotator, config2.rights || { enableBookmarks: false }, config2.publication, config2.delegate, config2, config2.initialAnnotations, config2.api, config2.headerMenu);
@@ -40036,9 +40339,7 @@ var BookmarkModule = class {
40036
40339
  this.api = api;
40037
40340
  }
40038
40341
  stop() {
40039
- if (IS_DEV) {
40040
- console.log("Bookmark module stop");
40041
- }
40342
+ import_loglevel8.default.log("Bookmark module stop");
40042
40343
  }
40043
40344
  async start() {
40044
40345
  this.delegate.bookmarkModule = this;
@@ -40088,17 +40389,13 @@ var BookmarkModule = class {
40088
40389
  if (this.api?.deleteBookmark) {
40089
40390
  await this.api?.deleteBookmark(bookmark);
40090
40391
  let deleted = await this.annotator.deleteBookmark(bookmark);
40091
- if (IS_DEV) {
40092
- console.log("Bookmark deleted " + JSON.stringify(deleted));
40093
- }
40392
+ import_loglevel8.default.log("Bookmark deleted " + JSON.stringify(deleted));
40094
40393
  await this.showBookmarks();
40095
40394
  await this.drawBookmarks();
40096
40395
  return deleted;
40097
40396
  } else {
40098
40397
  let deleted = await this.annotator.deleteBookmark(bookmark);
40099
- if (IS_DEV) {
40100
- console.log("Bookmark deleted " + JSON.stringify(deleted));
40101
- }
40398
+ import_loglevel8.default.log("Bookmark deleted " + JSON.stringify(deleted));
40102
40399
  await this.showBookmarks();
40103
40400
  await this.drawBookmarks();
40104
40401
  return deleted;
@@ -40155,20 +40452,15 @@ var BookmarkModule = class {
40155
40452
  if (result) {
40156
40453
  bookmark = result;
40157
40454
  }
40158
- if (IS_DEV)
40159
- console.log(bookmark);
40455
+ import_loglevel8.default.log(bookmark);
40160
40456
  let saved = this.annotator.saveBookmark(bookmark);
40161
- if (IS_DEV) {
40162
- console.log("Bookmark added " + JSON.stringify(saved));
40163
- }
40457
+ import_loglevel8.default.log("Bookmark added " + JSON.stringify(saved));
40164
40458
  this.showBookmarks();
40165
40459
  await this.drawBookmarks();
40166
40460
  return saved;
40167
40461
  } else {
40168
40462
  let saved = this.annotator.saveBookmark(bookmark);
40169
- if (IS_DEV) {
40170
- console.log("Bookmark added " + JSON.stringify(saved));
40171
- }
40463
+ import_loglevel8.default.log("Bookmark added " + JSON.stringify(saved));
40172
40464
  this.showBookmarks();
40173
40465
  await this.drawBookmarks();
40174
40466
  return saved;
@@ -40257,16 +40549,18 @@ var BookmarkModule = class {
40257
40549
  }
40258
40550
  };
40259
40551
  if (win !== null) {
40260
- 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
+ }
40261
40557
  let doc2 = self2.delegate.iframes[0].contentDocument;
40262
40558
  if (selectionInfo && doc2) {
40263
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);
40264
40560
  this.delegate.iframes[0].contentDocument?.getSelection()?.removeAllRanges();
40265
40561
  if (book) {
40266
40562
  return this.saveAnnotation(book[0]).then((anno) => {
40267
- if (IS_DEV) {
40268
- console.log("saved bookmark " + anno?.id);
40269
- }
40563
+ import_loglevel8.default.log("saved bookmark " + anno?.id);
40270
40564
  });
40271
40565
  }
40272
40566
  }
@@ -40444,9 +40738,7 @@ var BookmarkModule = class {
40444
40738
  async deleteLocalHighlight(id2) {
40445
40739
  if (this.annotator) {
40446
40740
  var deleted = await this.annotator.deleteAnnotation(id2);
40447
- if (IS_DEV) {
40448
- console.log("Highlight deleted " + JSON.stringify(deleted));
40449
- }
40741
+ import_loglevel8.default.log("Highlight deleted " + JSON.stringify(deleted));
40450
40742
  await this.showBookmarks();
40451
40743
  await this.drawBookmarks();
40452
40744
  return deleted;
@@ -40556,23 +40848,17 @@ var BookmarkModule = class {
40556
40848
  this.delegate.stopReadAloud();
40557
40849
  this.delegate.navigate(locator);
40558
40850
  } else {
40559
- if (IS_DEV) {
40560
- console.log("bookmark data missing: ", event);
40561
- }
40851
+ import_loglevel8.default.log("bookmark data missing: ", event);
40562
40852
  }
40563
40853
  }
40564
40854
  handleAnnotationLinkDeleteClick(type, event, locator) {
40565
- if (IS_DEV) {
40566
- console.log("bookmark data locator: ", locator);
40567
- }
40855
+ import_loglevel8.default.log("bookmark data locator: ", locator);
40568
40856
  if (locator) {
40569
40857
  if (type === AnnotationType.Bookmark) {
40570
40858
  this.deleteBookmark(locator);
40571
40859
  }
40572
40860
  } else {
40573
- if (IS_DEV) {
40574
- console.log("bookmark data missing: ", event);
40575
- }
40861
+ import_loglevel8.default.log("bookmark data missing: ", event);
40576
40862
  }
40577
40863
  }
40578
40864
  static readableTimestamp(timestamp) {
@@ -40593,6 +40879,7 @@ var import_media_overlay = __toModule(require_media_overlay());
40593
40879
 
40594
40880
  // src/modules/mediaoverlays/MediaOverlaySettings.ts
40595
40881
  init_polyfills();
40882
+ var import_loglevel9 = __toModule(require_loglevel());
40596
40883
  var R2_MO_CLASS_ACTIVE = "r2-mo-active";
40597
40884
  var _MEDIAOVERLAYREFS = class {
40598
40885
  };
@@ -40624,7 +40911,7 @@ var MediaOverlaySettings = class {
40624
40911
  this.api = api;
40625
40912
  this.headerMenu = headerMenu;
40626
40913
  this.initialise();
40627
- console.log(this.api);
40914
+ import_loglevel9.default.log(this.api);
40628
40915
  }
40629
40916
  static create(config2) {
40630
40917
  const settings = new this(config2.store, config2.api, config2.headerMenu);
@@ -40632,42 +40919,34 @@ var MediaOverlaySettings = class {
40632
40919
  let initialSettings = config2.initialMediaOverlaySettings;
40633
40920
  if (initialSettings?.color) {
40634
40921
  settings.color = initialSettings.color;
40635
- if (IS_DEV)
40636
- console.log(settings.color);
40922
+ import_loglevel9.default.log(settings.color);
40637
40923
  }
40638
40924
  if (initialSettings?.autoScroll) {
40639
40925
  settings.autoScroll = initialSettings.autoScroll;
40640
- if (IS_DEV)
40641
- console.log(settings.autoScroll);
40926
+ import_loglevel9.default.log(settings.autoScroll);
40642
40927
  }
40643
40928
  if (initialSettings?.autoTurn) {
40644
40929
  settings.autoTurn = initialSettings.autoTurn;
40645
- if (IS_DEV)
40646
- console.log(settings.autoTurn);
40930
+ import_loglevel9.default.log(settings.autoScroll);
40647
40931
  }
40648
40932
  if (initialSettings?.volume) {
40649
40933
  settings.volume = initialSettings.volume;
40650
- if (IS_DEV)
40651
- console.log(settings.volume);
40934
+ import_loglevel9.default.log(settings.volume);
40652
40935
  }
40653
40936
  if (initialSettings?.rate) {
40654
40937
  settings.rate = initialSettings.rate;
40655
- if (IS_DEV)
40656
- console.log(settings.rate);
40938
+ import_loglevel9.default.log(settings.rate);
40657
40939
  }
40658
40940
  if (initialSettings?.wait) {
40659
40941
  settings.wait = initialSettings.wait;
40660
- if (IS_DEV)
40661
- console.log(settings.wait);
40942
+ import_loglevel9.default.log(settings.wait);
40662
40943
  }
40663
40944
  }
40664
40945
  settings.initializeSelections();
40665
40946
  return settings;
40666
40947
  }
40667
40948
  stop() {
40668
- if (IS_DEV) {
40669
- console.log("MediaOverlay settings stop");
40670
- }
40949
+ import_loglevel9.default.log("MediaOverlay settings stop");
40671
40950
  }
40672
40951
  initialise() {
40673
40952
  this.autoScroll = this.getProperty(MEDIAOVERLAYREFS.AUTO_SCROLL_KEY) != null ? this.getProperty(MEDIAOVERLAYREFS.AUTO_SCROLL_KEY).value : this.autoScroll;
@@ -40733,9 +41012,7 @@ var MediaOverlaySettings = class {
40733
41012
  this.applyMediaOverlaySettings(syncSettings);
40734
41013
  if (this.api?.updateSettings) {
40735
41014
  this.api?.updateSettings(syncSettings).then(async (settings) => {
40736
- if (IS_DEV) {
40737
- console.log("api updated sync settings", settings);
40738
- }
41015
+ import_loglevel9.default.log("api updated sync settings", settings);
40739
41016
  });
40740
41017
  }
40741
41018
  }
@@ -40790,8 +41067,7 @@ var MediaOverlaySettings = class {
40790
41067
  this.settingsChangeCallback();
40791
41068
  }
40792
41069
  if (mediaOverlaySettings.autoScroll !== void 0) {
40793
- if (IS_DEV)
40794
- console.log("autoScroll " + this.autoScroll);
41070
+ import_loglevel9.default.log("autoScroll " + this.autoScroll);
40795
41071
  this.autoScroll = mediaOverlaySettings.autoScroll;
40796
41072
  let prop = this.userProperties.getByRef(MEDIAOVERLAYREFS.AUTO_SCROLL_REF);
40797
41073
  if (prop) {
@@ -40801,8 +41077,7 @@ var MediaOverlaySettings = class {
40801
41077
  this.settingsChangeCallback();
40802
41078
  }
40803
41079
  if (mediaOverlaySettings.autoTurn !== void 0) {
40804
- if (IS_DEV)
40805
- console.log("autoTurn " + this.autoTurn);
41080
+ import_loglevel9.default.log("autoTurn " + this.autoTurn);
40806
41081
  this.autoTurn = mediaOverlaySettings.autoTurn;
40807
41082
  let prop = this.userProperties.getByRef(MEDIAOVERLAYREFS.AUTO_TURN_REF);
40808
41083
  if (prop) {
@@ -40812,8 +41087,7 @@ var MediaOverlaySettings = class {
40812
41087
  this.settingsChangeCallback();
40813
41088
  }
40814
41089
  if (mediaOverlaySettings.volume) {
40815
- if (IS_DEV)
40816
- console.log("volume " + this.volume);
41090
+ import_loglevel9.default.log("volume " + this.volume);
40817
41091
  this.volume = mediaOverlaySettings.volume;
40818
41092
  let prop = this.userProperties.getByRef(MEDIAOVERLAYREFS.VOLUME_REF);
40819
41093
  if (prop) {
@@ -40823,8 +41097,7 @@ var MediaOverlaySettings = class {
40823
41097
  this.settingsChangeCallback();
40824
41098
  }
40825
41099
  if (mediaOverlaySettings.rate) {
40826
- if (IS_DEV)
40827
- console.log("rate " + this.rate);
41100
+ import_loglevel9.default.log("rate " + this.rate);
40828
41101
  this.rate = mediaOverlaySettings.rate;
40829
41102
  let prop = this.userProperties.getByRef(MEDIAOVERLAYREFS.RATE_REF);
40830
41103
  if (prop) {
@@ -40902,6 +41175,7 @@ var MediaOverlaySettings = class {
40902
41175
  };
40903
41176
 
40904
41177
  // src/modules/mediaoverlays/MediaOverlayModule.ts
41178
+ var import_loglevel10 = __toModule(require_loglevel());
40905
41179
  var MediaOverlayModule = class {
40906
41180
  constructor(delegate, publication, settings, properties) {
40907
41181
  this.play = findElement(document, "#menu-button-play");
@@ -40910,8 +41184,7 @@ var MediaOverlayModule = class {
40910
41184
  this.pid = void 0;
40911
41185
  this.__ontimeupdate = false;
40912
41186
  this.ontimeupdate = async (_v) => {
40913
- if (IS_DEV)
40914
- console.log("ontimeupdate");
41187
+ import_loglevel10.default.log("ontimeupdate");
40915
41188
  this.trackCurrentTime();
40916
41189
  };
40917
41190
  this.ensureOnTimeUpdate = (remove, replace) => {
@@ -40944,13 +41217,11 @@ var MediaOverlayModule = class {
40944
41217
  return mediaOverlay;
40945
41218
  }
40946
41219
  stop() {
40947
- if (IS_DEV)
40948
- console.log("MediaOverlay module stop");
41220
+ import_loglevel10.default.log("MediaOverlay module stop");
40949
41221
  }
40950
41222
  start() {
40951
41223
  this.delegate.mediaOverlayModule = this;
40952
- if (IS_DEV)
40953
- console.log("MediaOverlay module start");
41224
+ import_loglevel10.default.log("MediaOverlay module start");
40954
41225
  }
40955
41226
  async initialize() {
40956
41227
  return new Promise(async (resolve) => {
@@ -40977,14 +41248,13 @@ var MediaOverlayModule = class {
40977
41248
  const moUrlFull = moUrlObjFull.toString();
40978
41249
  let response;
40979
41250
  try {
40980
- response = await fetch(moUrlFull);
41251
+ response = await fetch(moUrlFull, this.delegate.requestConfig);
40981
41252
  } catch (e) {
40982
41253
  console.error(e, moUrlFull);
40983
41254
  return;
40984
41255
  }
40985
41256
  if (!response.ok) {
40986
- if (IS_DEV)
40987
- console.log("BAD RESPONSE?!");
41257
+ import_loglevel10.default.log("BAD RESPONSE?!");
40988
41258
  }
40989
41259
  let moJson;
40990
41260
  try {
@@ -40993,8 +41263,7 @@ var MediaOverlayModule = class {
40993
41263
  console.error(e);
40994
41264
  }
40995
41265
  if (!moJson) {
40996
- if (IS_DEV)
40997
- console.log("## moJson" + moJson);
41266
+ import_loglevel10.default.log("## moJson" + moJson);
40998
41267
  return;
40999
41268
  }
41000
41269
  link.MediaOverlays = TaJsonDeserialize(moJson, import_media_overlay.MediaOverlayNode);
@@ -41080,8 +41349,7 @@ var MediaOverlayModule = class {
41080
41349
  }
41081
41350
  }
41082
41351
  findDepthFirstTextAudioPair(textHref, mo, textFragmentIDChain) {
41083
- if (IS_DEV)
41084
- console.log("findDepthFirstTextAudioPair()");
41352
+ import_loglevel10.default.log("findDepthFirstTextAudioPair()");
41085
41353
  let isTextUrlMatch;
41086
41354
  let isFragmentIDMatch;
41087
41355
  if (mo.Text) {
@@ -41102,21 +41370,16 @@ var MediaOverlayModule = class {
41102
41370
  isTextUrlMatch = false;
41103
41371
  }
41104
41372
  }
41105
- if (IS_DEV) {
41106
- console.log("isFragmentIDMatch: " + isFragmentIDMatch);
41107
- console.log("isTextUrlMatch: " + isTextUrlMatch);
41108
- }
41373
+ import_loglevel10.default.log("isFragmentIDMatch: " + isFragmentIDMatch);
41374
+ import_loglevel10.default.log("isTextUrlMatch: " + isTextUrlMatch);
41109
41375
  if (!mo.Children || !mo.Children.length) {
41110
- if (IS_DEV)
41111
- console.log("findDepthFirstTextAudioPair() - leaf text/audio pair");
41376
+ import_loglevel10.default.log("findDepthFirstTextAudioPair() - leaf text/audio pair");
41112
41377
  if (!isTextUrlMatch) {
41113
- if (IS_DEV)
41114
- console.log("findDepthFirstTextAudioPair() - leaf - !isTextUrlMatch");
41378
+ import_loglevel10.default.log("findDepthFirstTextAudioPair() - leaf - !isTextUrlMatch");
41115
41379
  return void 0;
41116
41380
  }
41117
41381
  if (isFragmentIDMatch || isTextUrlMatch && !textFragmentIDChain) {
41118
- if (IS_DEV)
41119
- console.log("findDepthFirstTextAudioPair() - leaf - isFragmentIDMatch || (isTextUrlMatch && !textFragmentIDChain");
41382
+ import_loglevel10.default.log("findDepthFirstTextAudioPair() - leaf - isFragmentIDMatch || (isTextUrlMatch && !textFragmentIDChain");
41120
41383
  return mo;
41121
41384
  }
41122
41385
  return void 0;
@@ -41124,34 +41387,25 @@ var MediaOverlayModule = class {
41124
41387
  const textFragmentIDChainOriginal = textFragmentIDChain;
41125
41388
  let frags = textFragmentIDChain;
41126
41389
  for (const child of mo.Children) {
41127
- if (IS_DEV) {
41128
- console.log("findDepthFirstTextAudioPair() - child");
41129
- console.log(JSON.stringify(child));
41130
- }
41390
+ import_loglevel10.default.log("findDepthFirstTextAudioPair() - child");
41391
+ import_loglevel10.default.log(JSON.stringify(child));
41131
41392
  const match = this.findDepthFirstTextAudioPair(textHref, child, frags);
41132
41393
  if (match === null) {
41133
- if (IS_DEV) {
41134
- console.log("findDepthFirstTextAudioPair() - child - match null (skip)");
41135
- }
41394
+ import_loglevel10.default.log("findDepthFirstTextAudioPair() - child - match null (skip)");
41136
41395
  frags = void 0;
41137
41396
  }
41138
41397
  if (match) {
41139
- if (IS_DEV) {
41140
- console.log("findDepthFirstTextAudioPair() - child - match");
41141
- console.log(JSON.stringify(match));
41142
- }
41398
+ import_loglevel10.default.log("findDepthFirstTextAudioPair() - child - match");
41399
+ import_loglevel10.default.log(JSON.stringify(match));
41143
41400
  return match;
41144
41401
  }
41145
41402
  }
41146
41403
  if (isFragmentIDMatch) {
41147
- if (IS_DEV)
41148
- console.log("findDepthFirstTextAudioPair() - post isFragmentIDMatch");
41404
+ import_loglevel10.default.log("findDepthFirstTextAudioPair() - post isFragmentIDMatch");
41149
41405
  const match = this.findDepthFirstTextAudioPair(textHref, mo, void 0);
41150
41406
  if (match) {
41151
- if (IS_DEV) {
41152
- console.log("findDepthFirstTextAudioPair() - post isFragmentIDMatch - match");
41153
- console.log(JSON.stringify(match));
41154
- }
41407
+ import_loglevel10.default.log("findDepthFirstTextAudioPair() - post isFragmentIDMatch - match");
41408
+ import_loglevel10.default.log(JSON.stringify(match));
41155
41409
  return match;
41156
41410
  } else {
41157
41411
  return match;
@@ -41167,8 +41421,7 @@ var MediaOverlayModule = class {
41167
41421
  if (this.mediaOverlayTextAudioPair) {
41168
41422
  try {
41169
41423
  if (this.currentAudioEnd && this.audioElement.currentTime >= this.currentAudioEnd - 0.05) {
41170
- if (IS_DEV)
41171
- console.log("ontimeupdate - mediaOverlaysNext()");
41424
+ import_loglevel10.default.log("ontimeupdate - mediaOverlaysNext()");
41172
41425
  this.mediaOverlaysNext();
41173
41426
  }
41174
41427
  const match_i = this.mediaOverlayTextAudioPair.Text.lastIndexOf("#");
@@ -41180,13 +41433,11 @@ var MediaOverlayModule = class {
41180
41433
  }
41181
41434
  }
41182
41435
  mediaOverlaysNext(escape2) {
41183
- if (IS_DEV)
41184
- console.log("mediaOverlaysNext()");
41436
+ import_loglevel10.default.log("mediaOverlaysNext()");
41185
41437
  if (this.mediaOverlayRoot && this.mediaOverlayTextAudioPair) {
41186
41438
  const nextTextAudioPair = this.findNextTextAudioPair(this.mediaOverlayRoot, this.mediaOverlayTextAudioPair, { prev: void 0 }, escape2 ? true : false);
41187
41439
  if (!nextTextAudioPair) {
41188
- if (IS_DEV)
41189
- console.log("mediaOverlaysNext() - navLeftOrRight()");
41440
+ import_loglevel10.default.log("mediaOverlaysNext() - navLeftOrRight()");
41190
41441
  this.mediaOverlaysStop();
41191
41442
  if (this.currentLinks.length > 1 && this.currentLinkIndex === 0) {
41192
41443
  this.currentLinkIndex++;
@@ -41206,25 +41457,21 @@ var MediaOverlayModule = class {
41206
41457
  const hrefUrlObj1 = new URL("https://dita.digital/" + this.mediaOverlayTextAudioPair.Text);
41207
41458
  const hrefUrlObj2 = new URL("https://dita.digital/" + nextTextAudioPair.Text);
41208
41459
  if (hrefUrlObj1.pathname !== hrefUrlObj2.pathname) {
41209
- if (IS_DEV) {
41210
- console.log("mediaOverlaysNext() SWITCH! " + hrefUrlObj1.pathname + " != " + hrefUrlObj2.pathname);
41211
- }
41460
+ import_loglevel10.default.log("mediaOverlaysNext() SWITCH! " + hrefUrlObj1.pathname + " != " + hrefUrlObj2.pathname);
41212
41461
  switchDoc = true;
41213
41462
  }
41214
41463
  }
41215
41464
  if (switchDoc) {
41216
41465
  this.mediaOverlaysStop();
41217
41466
  } else {
41218
- if (IS_DEV)
41219
- console.log("mediaOverlaysNext() - playMediaOverlaysAudio()");
41467
+ import_loglevel10.default.log("mediaOverlaysNext() - playMediaOverlaysAudio()");
41220
41468
  setTimeout(async () => {
41221
41469
  await this.playMediaOverlaysAudio(nextTextAudioPair, void 0, void 0);
41222
41470
  }, 0);
41223
41471
  }
41224
41472
  }
41225
41473
  } else {
41226
- if (IS_DEV)
41227
- console.log("mediaOverlaysNext() - navLeftOrRight() 2");
41474
+ import_loglevel10.default.log("mediaOverlaysNext() - navLeftOrRight() 2");
41228
41475
  this.mediaOverlaysStop();
41229
41476
  if (this.currentLinks.length > 1 && this.currentLinkIndex === 0) {
41230
41477
  this.currentLinkIndex++;
@@ -41241,15 +41488,13 @@ var MediaOverlayModule = class {
41241
41488
  }
41242
41489
  }
41243
41490
  mediaOverlaysStop() {
41244
- if (IS_DEV)
41245
- console.log("mediaOverlaysStop()");
41491
+ import_loglevel10.default.log("mediaOverlaysStop()");
41246
41492
  this.mediaOverlaysPause();
41247
41493
  this.mediaOverlayRoot = void 0;
41248
41494
  this.mediaOverlayTextAudioPair = void 0;
41249
41495
  }
41250
41496
  mediaOverlaysPause() {
41251
- if (IS_DEV)
41252
- console.log("mediaOverlaysPause()");
41497
+ import_loglevel10.default.log("mediaOverlaysPause()");
41253
41498
  this.mediaOverlayHighlight(void 0);
41254
41499
  if (this.audioElement) {
41255
41500
  this.audioElement.pause();
@@ -41258,36 +41503,28 @@ var MediaOverlayModule = class {
41258
41503
  findNextTextAudioPair(mo, moToMatch, previousMo, escape2) {
41259
41504
  if (!mo.Children || !mo.Children.length) {
41260
41505
  if (previousMo?.prev === moToMatch) {
41261
- if (IS_DEV)
41262
- console.log("findNextTextAudioPair() - prevMo === moToMatch");
41506
+ import_loglevel10.default.log("findNextTextAudioPair() - prevMo === moToMatch");
41263
41507
  return mo;
41264
41508
  }
41265
- if (IS_DEV) {
41266
- console.log("findNextTextAudioPair() - set previous");
41267
- console.log(JSON.stringify(mo));
41268
- }
41509
+ import_loglevel10.default.log("findNextTextAudioPair() - set previous");
41510
+ import_loglevel10.default.log(JSON.stringify(mo));
41269
41511
  previousMo.prev = mo;
41270
41512
  return void 0;
41271
41513
  }
41272
41514
  for (const child of mo.Children) {
41273
- if (IS_DEV) {
41274
- console.log("findNextTextAudioPair() - child");
41275
- console.log(JSON.stringify(child));
41276
- }
41515
+ import_loglevel10.default.log("findNextTextAudioPair() - child");
41516
+ import_loglevel10.default.log(JSON.stringify(child));
41277
41517
  const match = this.findNextTextAudioPair(child, moToMatch, previousMo, escape2);
41278
41518
  if (match) {
41279
- if (IS_DEV) {
41280
- console.log("findNextTextAudioPair() - match");
41281
- console.log(JSON.stringify(match));
41282
- }
41519
+ import_loglevel10.default.log("findNextTextAudioPair() - match");
41520
+ import_loglevel10.default.log(JSON.stringify(match));
41283
41521
  return match;
41284
41522
  }
41285
41523
  }
41286
41524
  return void 0;
41287
41525
  }
41288
41526
  async playMediaOverlaysAudio(moTextAudioPair, begin, end) {
41289
- if (IS_DEV)
41290
- console.log("playMediaOverlaysAudio()");
41527
+ import_loglevel10.default.log("playMediaOverlaysAudio()");
41291
41528
  this.mediaOverlayTextAudioPair = moTextAudioPair;
41292
41529
  if (!moTextAudioPair.Audio) {
41293
41530
  return;
@@ -41311,14 +41548,14 @@ var MediaOverlayModule = class {
41311
41548
  try {
41312
41549
  this.currentAudioBegin = parseFloat(b);
41313
41550
  } catch (err) {
41314
- console.log(err);
41551
+ import_loglevel10.default.error(err);
41315
41552
  }
41316
41553
  if (matches.length >= 3) {
41317
41554
  const e = matches[3];
41318
41555
  try {
41319
41556
  this.currentAudioEnd = parseFloat(e);
41320
41557
  } catch (err) {
41321
- console.log(err);
41558
+ import_loglevel10.default.error(err);
41322
41559
  }
41323
41560
  }
41324
41561
  }
@@ -41327,9 +41564,7 @@ var MediaOverlayModule = class {
41327
41564
  this.currentAudioBegin = begin;
41328
41565
  this.currentAudioEnd = end;
41329
41566
  }
41330
- if (IS_DEV) {
41331
- console.log(`${urlFull} => [${this.currentAudioBegin}-${this.currentAudioEnd}]`);
41332
- }
41567
+ import_loglevel10.default.log(`${urlFull} => [${this.currentAudioBegin}-${this.currentAudioEnd}]`);
41333
41568
  const playClip = async (initial) => {
41334
41569
  if (!this.audioElement) {
41335
41570
  return;
@@ -41337,9 +41572,7 @@ var MediaOverlayModule = class {
41337
41572
  const timeToSeekTo = this.currentAudioBegin ? this.currentAudioBegin : 0;
41338
41573
  if (initial || this.audioElement.paused) {
41339
41574
  if (initial && !timeToSeekTo || this.audioElement.currentTime === timeToSeekTo) {
41340
- if (IS_DEV) {
41341
- console.log("playMediaOverlaysAudio() - playClip() - _currentAudioElement.play()");
41342
- }
41575
+ import_loglevel10.default.log("playMediaOverlaysAudio() - playClip() - _currentAudioElement.play()");
41343
41576
  this.ensureOnTimeUpdate(false, false);
41344
41577
  this.audioElement.playbackRate = this.settings.rate;
41345
41578
  this.audioElement.volume = this.settings.volume;
@@ -41358,14 +41591,10 @@ var MediaOverlayModule = class {
41358
41591
  checkReady();
41359
41592
  }
41360
41593
  } else {
41361
- if (IS_DEV) {
41362
- console.log("playMediaOverlaysAudio() - playClip() - ontimeupdateSeeked");
41363
- }
41594
+ import_loglevel10.default.log("playMediaOverlaysAudio() - playClip() - ontimeupdateSeeked");
41364
41595
  const ontimeupdateSeeked = async (_ev) => {
41365
41596
  this.audioElement.removeEventListener("timeupdate", ontimeupdateSeeked);
41366
- if (IS_DEV) {
41367
- console.log("playMediaOverlaysAudio() - playClip() - ontimeupdateSeeked - .play()");
41368
- }
41597
+ import_loglevel10.default.log("playMediaOverlaysAudio() - playClip() - ontimeupdateSeeked - .play()");
41369
41598
  this.ensureOnTimeUpdate(false, false);
41370
41599
  if (this.audioElement) {
41371
41600
  this.audioElement.playbackRate = this.settings.rate;
@@ -41393,13 +41622,9 @@ var MediaOverlayModule = class {
41393
41622
  const contiguous = this.previousAudioUrl === this.currentAudioUrl && typeof this.previousAudioEnd !== "undefined" && this.previousAudioEnd > timeToSeekTo - 0.02 && this.previousAudioEnd <= timeToSeekTo && this.audioElement.currentTime >= timeToSeekTo - 0.1;
41394
41623
  this.ensureOnTimeUpdate(false, false);
41395
41624
  if (contiguous) {
41396
- if (IS_DEV) {
41397
- console.log("playMediaOverlaysAudio() - playClip() - ensureOnTimeUpdate");
41398
- }
41625
+ import_loglevel10.default.log("playMediaOverlaysAudio() - playClip() - ensureOnTimeUpdate");
41399
41626
  } else {
41400
- if (IS_DEV) {
41401
- console.log("playMediaOverlaysAudio() - playClip() - currentTime = timeToSeekTo");
41402
- }
41627
+ import_loglevel10.default.log("playMediaOverlaysAudio() - playClip() - currentTime = timeToSeekTo");
41403
41628
  this.audioElement.currentTime = timeToSeekTo;
41404
41629
  }
41405
41630
  }
@@ -41407,9 +41632,7 @@ var MediaOverlayModule = class {
41407
41632
  this.previousAudioUrl = this.currentAudioUrl;
41408
41633
  if (!this.currentAudioUrl || urlNoQuery !== this.currentAudioUrl) {
41409
41634
  this.currentAudioUrl = urlNoQuery;
41410
- if (IS_DEV) {
41411
- console.log("playMediaOverlaysAudio() - RESET: " + this.previousAudioUrl + " => " + this.currentAudioUrl);
41412
- }
41635
+ import_loglevel10.default.log("playMediaOverlaysAudio() - RESET: " + this.previousAudioUrl + " => " + this.currentAudioUrl);
41413
41636
  this.audioElement = document.getElementById("AUDIO_MO_ID");
41414
41637
  if (this.audioElement) {
41415
41638
  this.audioElement.pause();
@@ -41426,23 +41649,21 @@ var MediaOverlayModule = class {
41426
41649
  this.audioElement.playbackRate = this.settings.rate;
41427
41650
  document.body.appendChild(this.audioElement);
41428
41651
  this.audioElement.addEventListener("error", (ev) => {
41429
- console.log("-1) error: " + (this.currentAudioUrl !== ev.currentTarget.src ? this.currentAudioUrl + " -- " : "") + ev.currentTarget.src.substr(ev.currentTarget.src.lastIndexOf("/")));
41652
+ import_loglevel10.default.log("-1) error: " + (this.currentAudioUrl !== ev.currentTarget.src ? this.currentAudioUrl + " -- " : "") + ev.currentTarget.src.substr(ev.currentTarget.src.lastIndexOf("/")));
41430
41653
  if (this.audioElement && this.audioElement.error) {
41431
- console.log(this.audioElement.error.code);
41432
- console.log(this.audioElement.error.message);
41654
+ import_loglevel10.default.log(this.audioElement.error.code);
41655
+ import_loglevel10.default.log(this.audioElement.error.message);
41433
41656
  }
41434
41657
  });
41435
41658
  const oncanplaythrough = async (ev) => {
41436
41659
  const currentAudioElement = ev.currentTarget;
41437
41660
  currentAudioElement.removeEventListener("canplaythrough", oncanplaythrough);
41438
- if (IS_DEV)
41439
- console.log("oncanplaythrough");
41661
+ import_loglevel10.default.log("oncanplaythrough");
41440
41662
  await playClip(true);
41441
41663
  };
41442
41664
  this.audioElement.addEventListener("canplaythrough", oncanplaythrough);
41443
41665
  const onended = async (_ev) => {
41444
- if (IS_DEV)
41445
- console.log("onended");
41666
+ import_loglevel10.default.log("onended");
41446
41667
  if (this.currentLinks.length > 1 && this.currentLinkIndex === 0) {
41447
41668
  this.currentLinkIndex++;
41448
41669
  await this.playLink();
@@ -41459,42 +41680,35 @@ var MediaOverlayModule = class {
41459
41680
  this.audioElement.playbackRate = this.settings.rate;
41460
41681
  this.audioElement.setAttribute("src", this.currentAudioUrl);
41461
41682
  } else {
41462
- if (IS_DEV)
41463
- console.log("playMediaOverlaysAudio() - playClip()");
41683
+ import_loglevel10.default.log("playMediaOverlaysAudio() - playClip()");
41464
41684
  await playClip(false);
41465
41685
  }
41466
41686
  }
41467
41687
  async playMediaOverlays(textHref, rootMo, textFragmentIDChain) {
41468
- if (IS_DEV)
41469
- console.log("playMediaOverlays()");
41688
+ import_loglevel10.default.log("playMediaOverlays()");
41470
41689
  let textFragmentIDChain_ = textFragmentIDChain ? textFragmentIDChain.filter((id2) => id2) : void 0;
41471
41690
  if (textFragmentIDChain_ && textFragmentIDChain_.length === 0) {
41472
41691
  textFragmentIDChain_ = void 0;
41473
41692
  }
41474
41693
  let moTextAudioPair = this.findDepthFirstTextAudioPair(textHref, rootMo, textFragmentIDChain_);
41475
41694
  if (!moTextAudioPair && textFragmentIDChain_) {
41476
- if (IS_DEV) {
41477
- console.log("playMediaOverlays() - findDepthFirstTextAudioPair() SECOND CHANCE ");
41478
- console.log(JSON.stringify(textFragmentIDChain_, null, 4));
41479
- console.log(JSON.stringify(rootMo, null, 4));
41480
- }
41695
+ import_loglevel10.default.log("playMediaOverlays() - findDepthFirstTextAudioPair() SECOND CHANCE ");
41696
+ import_loglevel10.default.log(JSON.stringify(textFragmentIDChain_, null, 4));
41697
+ import_loglevel10.default.log(JSON.stringify(rootMo, null, 4));
41481
41698
  moTextAudioPair = this.findDepthFirstTextAudioPair(textHref, rootMo, void 0);
41482
41699
  }
41483
41700
  if (moTextAudioPair) {
41484
41701
  if (moTextAudioPair.Audio) {
41485
- if (IS_DEV)
41486
- console.log("playMediaOverlays() - playMediaOverlaysAudio()");
41702
+ import_loglevel10.default.log("playMediaOverlays() - playMediaOverlaysAudio()");
41487
41703
  this.mediaOverlayRoot = rootMo;
41488
41704
  await this.playMediaOverlaysAudio(moTextAudioPair, void 0, void 0);
41489
41705
  }
41490
41706
  } else {
41491
- if (IS_DEV)
41492
- console.log("playMediaOverlays() - !moTextAudioPair " + textHref);
41707
+ import_loglevel10.default.log("playMediaOverlays() - !moTextAudioPair " + textHref);
41493
41708
  }
41494
41709
  }
41495
41710
  mediaOverlayHighlight(id2) {
41496
- if (IS_DEV)
41497
- console.log("moHighlight: ## " + id2);
41711
+ import_loglevel10.default.log("moHighlight: ## " + id2);
41498
41712
  let classActive = this.publication.Metadata?.MediaOverlay?.ActiveClass;
41499
41713
  if (!classActive) {
41500
41714
  classActive = this.settings.color;
@@ -41539,6 +41753,7 @@ var MediaOverlayModule = class {
41539
41753
 
41540
41754
  // src/modules/positions/TimelineModule.ts
41541
41755
  init_polyfills();
41756
+ var import_loglevel11 = __toModule(require_loglevel());
41542
41757
  var TimelineModule = class {
41543
41758
  static async create(config2) {
41544
41759
  const timeline = new this(config2.delegate, config2.publication);
@@ -41550,9 +41765,7 @@ var TimelineModule = class {
41550
41765
  this.publication = publication;
41551
41766
  }
41552
41767
  async stop() {
41553
- if (IS_DEV) {
41554
- console.log("Timeline module stop");
41555
- }
41768
+ import_loglevel11.default.log("Timeline module stop");
41556
41769
  }
41557
41770
  async start() {
41558
41771
  this.delegate.timelineModule = this;
@@ -41621,8 +41834,7 @@ var TimelineModule = class {
41621
41834
  title: link.Title
41622
41835
  };
41623
41836
  }
41624
- if (IS_DEV)
41625
- console.log(position);
41837
+ import_loglevel11.default.log(position);
41626
41838
  this.delegate.navigate(position);
41627
41839
  });
41628
41840
  if (tocHrefAbs === this.delegate.currentChapterLink.href) {
@@ -41642,8 +41854,22 @@ var TimelineModule = class {
41642
41854
  // src/modules/protection/ContentProtectionModule.ts
41643
41855
  init_polyfills();
41644
41856
  var import_debounce3 = __toModule(require_debounce());
41857
+
41858
+ // src/utils/index.ts
41859
+ init_polyfills();
41860
+ var import_loglevel12 = __toModule(require_loglevel());
41861
+ function delay(t, v) {
41862
+ return new Promise(function(resolve) {
41863
+ setTimeout(resolve.bind(null, v), t);
41864
+ });
41865
+ }
41866
+ var IS_DEV = false;
41867
+ import_loglevel12.default.setLevel(IS_DEV ? "trace" : "warn", true);
41868
+
41869
+ // src/modules/protection/ContentProtectionModule.ts
41645
41870
  var import_browserslist_useragent_regexp = __toModule(require_lib7());
41646
41871
  var import_devtools_detector = __toModule(require_devtools_detector());
41872
+ var import_loglevel13 = __toModule(require_loglevel());
41647
41873
  var ContentProtectionModule = class {
41648
41874
  constructor(delegate, properties) {
41649
41875
  this.hasEventListener = false;
@@ -41674,7 +41900,7 @@ var ContentProtectionModule = class {
41674
41900
  window.sessionStorage.clear();
41675
41901
  window.location.replace(window.location.origin);
41676
41902
  }
41677
- if (typeof config2.api?.inspectDetected === "function") {
41903
+ if (config2.detectInspect && typeof config2.api?.inspectDetected === "function") {
41678
41904
  config2.api.inspectDetected();
41679
41905
  }
41680
41906
  }
@@ -41705,18 +41931,14 @@ var ContentProtectionModule = class {
41705
41931
  var self2 = this;
41706
41932
  this.mutationObserver = new MutationObserver(function(mutations) {
41707
41933
  mutations.forEach(function(mutation) {
41708
- if (IS_DEV) {
41709
- console.log(mutation.type);
41710
- }
41934
+ import_loglevel13.default.log(mutation.type);
41711
41935
  self2.isHacked = true;
41712
41936
  });
41713
41937
  });
41714
41938
  }
41715
41939
  }
41716
41940
  async stop() {
41717
- if (IS_DEV) {
41718
- console.log("Protection module stop");
41719
- }
41941
+ import_loglevel13.default.log("Protection module stop");
41720
41942
  this.mutationObserver.disconnect();
41721
41943
  if (this.properties?.disableKeys) {
41722
41944
  removeEventListenerOptional(this.delegate.mainElement, "keydown", this.disableSave);
@@ -41948,18 +42170,14 @@ var ContentProtectionModule = class {
41948
42170
  return true;
41949
42171
  }
41950
42172
  preventCopy(event) {
41951
- if (IS_DEV) {
41952
- console.log("copy action initiated");
41953
- }
42173
+ import_loglevel13.default.log("copy action initiated");
41954
42174
  event.clipboardData.setData("text/plain", "copy not allowed");
41955
42175
  event.stopPropagation();
41956
42176
  event.preventDefault();
41957
42177
  return false;
41958
42178
  }
41959
42179
  beforePrint(event) {
41960
- if (IS_DEV) {
41961
- console.log("before print");
41962
- }
42180
+ import_loglevel13.default.log("before print");
41963
42181
  if (this.delegate && this.delegate.headerMenu) {
41964
42182
  this.delegate.headerMenu.style.display = "none";
41965
42183
  this.delegate.mainElement.style.display = "none";
@@ -41969,9 +42187,7 @@ var ContentProtectionModule = class {
41969
42187
  return false;
41970
42188
  }
41971
42189
  afterPrint(event) {
41972
- if (IS_DEV) {
41973
- console.log("after print");
41974
- }
42190
+ import_loglevel13.default.log("after print");
41975
42191
  if (this.delegate && this.delegate.headerMenu) {
41976
42192
  this.delegate.headerMenu.style.removeProperty("display");
41977
42193
  this.delegate.mainElement.style.removeProperty("display");
@@ -42061,14 +42277,12 @@ var ContentProtectionModule = class {
42061
42277
  rect.width = width;
42062
42278
  rect.left = left;
42063
42279
  } catch (error) {
42064
- if (IS_DEV) {
42065
- console.log("error " + error);
42066
- console.log(rect);
42067
- console.log(rect.node);
42068
- console.log("scrambledTextContent " + rect.scrambledTextContent);
42069
- console.log("textContent " + rect.textContent);
42070
- console.log("isObfuscated " + rect.isObfuscated);
42071
- }
42280
+ import_loglevel13.default.log("error " + error);
42281
+ import_loglevel13.default.log(rect);
42282
+ import_loglevel13.default.log(rect.node);
42283
+ import_loglevel13.default.log("scrambledTextContent " + rect.scrambledTextContent);
42284
+ import_loglevel13.default.log("textContent " + rect.textContent);
42285
+ import_loglevel13.default.log("isObfuscated " + rect.isObfuscated);
42072
42286
  }
42073
42287
  });
42074
42288
  }
@@ -42124,17 +42338,14 @@ var ContentProtectionModule = class {
42124
42338
  range.detach();
42125
42339
  return rect;
42126
42340
  } catch (error) {
42127
- if (IS_DEV) {
42128
- console.log("measureTextNode " + error);
42129
- console.log("measureTextNode " + node);
42130
- console.log(node.textContent);
42131
- }
42341
+ import_loglevel13.default.log("measureTextNode " + error);
42342
+ import_loglevel13.default.log("measureTextNode " + node);
42343
+ import_loglevel13.default.log(node.textContent);
42132
42344
  }
42133
42345
  }
42134
42346
  isBeingHacked(element) {
42135
42347
  if (element.style.animation || element.style.transition || element.style.position || element.hasAttribute("style")) {
42136
- if (IS_DEV)
42137
- console.log("content being hacked");
42348
+ import_loglevel13.default.log("content being hacked");
42138
42349
  return true;
42139
42350
  }
42140
42351
  return false;
@@ -42298,6 +42509,7 @@ async function searchDocDomSeek(searchInput, doc, href, title, fullWordSearch =
42298
42509
  }
42299
42510
 
42300
42511
  // src/modules/search/SearchModule.ts
42512
+ var import_loglevel14 = __toModule(require_loglevel());
42301
42513
  var SearchModule = class {
42302
42514
  constructor(delegate, publication, properties, highlighter, api, headerMenu) {
42303
42515
  this.currentChapterSearchResult = [];
@@ -42316,9 +42528,7 @@ var SearchModule = class {
42316
42528
  return search;
42317
42529
  }
42318
42530
  async stop() {
42319
- if (IS_DEV) {
42320
- console.log("Search module stop");
42321
- }
42531
+ import_loglevel14.default.log("Search module stop");
42322
42532
  removeEventListenerOptional(this.searchInput, "keypress", this.handleSearch.bind(this));
42323
42533
  removeEventListenerOptional(this.searchGo, "click", this.handleSearch.bind(this));
42324
42534
  }
@@ -42737,9 +42947,9 @@ var SearchModule = class {
42737
42947
  }
42738
42948
  if (tocItem) {
42739
42949
  let href = this.publication.getAbsoluteHref(tocItem.Href);
42740
- await fetch(href).then((r) => r.text()).then(async (data) => {
42950
+ await fetch(href, this.delegate.requestConfig).then((r) => r.text()).then(async (data) => {
42741
42951
  let parser = new DOMParser();
42742
- let doc = parser.parseFromString(data, "application/xhtml+xml");
42952
+ let doc = parser.parseFromString(this.delegate.requestConfig?.encoded ? this.decodeBase64(data) : data, "application/xhtml+xml");
42743
42953
  if (tocItem) {
42744
42954
  searchDocDomSeek(term, doc, tocItem.Href, tocItem.Title).then((result) => {
42745
42955
  result.forEach((searchItem) => {
@@ -42755,6 +42965,16 @@ var SearchModule = class {
42755
42965
  }
42756
42966
  }
42757
42967
  }
42968
+ decodeBase64(base64) {
42969
+ const text = atob(base64);
42970
+ const length = text.length;
42971
+ const bytes = new Uint8Array(length);
42972
+ for (let i = 0; i < length; i++) {
42973
+ bytes[i] = text.charCodeAt(i);
42974
+ }
42975
+ const decoder = new TextDecoder();
42976
+ return decoder.decode(bytes);
42977
+ }
42758
42978
  async searchChapter(term) {
42759
42979
  let localSearchResultBook = [];
42760
42980
  const linkHref = this.publication.getAbsoluteHref(this.publication.readingOrder[this.delegate.currentResource() ?? 0].Href);
@@ -42764,9 +42984,9 @@ var SearchModule = class {
42764
42984
  }
42765
42985
  if (tocItem) {
42766
42986
  let href = this.publication.getAbsoluteHref(tocItem.Href);
42767
- await fetch(href).then((r) => r.text()).then(async (data) => {
42987
+ await fetch(href, this.delegate.requestConfig).then((r) => r.text()).then(async (data) => {
42768
42988
  let parser = new DOMParser();
42769
- let doc = parser.parseFromString(data, "application/xhtml+xml");
42989
+ let doc = parser.parseFromString(this.delegate.requestConfig?.encoded ? this.decodeBase64(data) : data, "application/xhtml+xml");
42770
42990
  if (tocItem) {
42771
42991
  searchDocDomSeek(term, doc, tocItem.Href, tocItem.Title).then((result) => {
42772
42992
  result.forEach((searchItem) => {
@@ -42835,6 +43055,7 @@ var SearchModule = class {
42835
43055
 
42836
43056
  // src/modules/TTS/TTSSettings.ts
42837
43057
  init_polyfills();
43058
+ var import_loglevel15 = __toModule(require_loglevel());
42838
43059
  var _TTSREFS = class {
42839
43060
  };
42840
43061
  var TTSREFS = _TTSREFS;
@@ -42876,42 +43097,34 @@ var TTSSettings = class {
42876
43097
  let initialTTSSettings = config2.initialTTSSettings;
42877
43098
  if (initialTTSSettings?.rate) {
42878
43099
  settings.rate = initialTTSSettings.rate;
42879
- if (IS_DEV)
42880
- console.log(settings.rate);
43100
+ import_loglevel15.default.log(settings.rate);
42881
43101
  }
42882
43102
  if (initialTTSSettings?.pitch) {
42883
43103
  settings.pitch = initialTTSSettings.pitch;
42884
- if (IS_DEV)
42885
- console.log(settings.pitch);
43104
+ import_loglevel15.default.log(settings.pitch);
42886
43105
  }
42887
43106
  if (initialTTSSettings?.volume) {
42888
43107
  settings.volume = initialTTSSettings.volume;
42889
- if (IS_DEV)
42890
- console.log(settings.volume);
43108
+ import_loglevel15.default.log(settings.volume);
42891
43109
  }
42892
43110
  if (initialTTSSettings?.color) {
42893
43111
  settings.color = initialTTSSettings.color;
42894
- if (IS_DEV)
42895
- console.log(settings.color);
43112
+ import_loglevel15.default.log(settings.color);
42896
43113
  }
42897
43114
  if (initialTTSSettings?.autoScroll) {
42898
43115
  settings.autoScroll = initialTTSSettings.autoScroll;
42899
- if (IS_DEV)
42900
- console.log(settings.autoScroll);
43116
+ import_loglevel15.default.log(settings.autoScroll);
42901
43117
  }
42902
43118
  if (initialTTSSettings?.voice) {
42903
43119
  settings.voice = initialTTSSettings.voice;
42904
- if (IS_DEV)
42905
- console.log(settings.voice);
43120
+ import_loglevel15.default.log(settings.voice);
42906
43121
  }
42907
43122
  }
42908
43123
  settings.initializeSelections();
42909
43124
  return settings;
42910
43125
  }
42911
43126
  stop() {
42912
- if (IS_DEV) {
42913
- console.log("tts settings stop");
42914
- }
43127
+ import_loglevel15.default.log("tts settings stop");
42915
43128
  }
42916
43129
  initialise() {
42917
43130
  this.autoScroll = this.getProperty(TTSREFS.AUTO_SCROLL_KEY) != null ? this.getProperty(TTSREFS.AUTO_SCROLL_KEY).value : this.autoScroll;
@@ -42984,9 +43197,7 @@ var TTSSettings = class {
42984
43197
  this.applyTTSSettings(ttsSettings);
42985
43198
  if (this.api?.updateSettings) {
42986
43199
  this.api?.updateSettings(ttsSettings).then(async (settings) => {
42987
- if (IS_DEV) {
42988
- console.log("api updated tts settings", settings);
42989
- }
43200
+ import_loglevel15.default.log("api updated tts settings", settings);
42990
43201
  });
42991
43202
  }
42992
43203
  }
@@ -43034,8 +43245,7 @@ var TTSSettings = class {
43034
43245
  }
43035
43246
  applyTTSSettings(ttsSettings) {
43036
43247
  if (ttsSettings.rate) {
43037
- if (IS_DEV)
43038
- console.log("rate " + this.rate);
43248
+ import_loglevel15.default.log("rate " + this.rate);
43039
43249
  this.rate = ttsSettings.rate;
43040
43250
  let prop = this.userProperties.getByRef(TTSREFS.RATE_REF);
43041
43251
  if (prop) {
@@ -43046,8 +43256,7 @@ var TTSSettings = class {
43046
43256
  this.restartCallback();
43047
43257
  }
43048
43258
  if (ttsSettings.pitch) {
43049
- if (IS_DEV)
43050
- console.log("pitch " + this.pitch);
43259
+ import_loglevel15.default.log("pitch " + this.pitch);
43051
43260
  this.pitch = ttsSettings.pitch;
43052
43261
  let prop = this.userProperties.getByRef(TTSREFS.PITCH_REF);
43053
43262
  if (prop) {
@@ -43058,8 +43267,7 @@ var TTSSettings = class {
43058
43267
  this.restartCallback();
43059
43268
  }
43060
43269
  if (ttsSettings.volume) {
43061
- if (IS_DEV)
43062
- console.log("volume " + this.volume);
43270
+ import_loglevel15.default.log("volume " + this.volume);
43063
43271
  this.volume = ttsSettings.volume;
43064
43272
  let prop = this.userProperties.getByRef(TTSREFS.VOLUME_REF);
43065
43273
  if (prop) {
@@ -43079,8 +43287,7 @@ var TTSSettings = class {
43079
43287
  this.settingsChangeCallback();
43080
43288
  }
43081
43289
  if (ttsSettings.autoScroll !== void 0) {
43082
- if (IS_DEV)
43083
- console.log("autoScroll " + this.autoScroll);
43290
+ import_loglevel15.default.log("autoScroll " + this.autoScroll);
43084
43291
  this.autoScroll = ttsSettings.autoScroll;
43085
43292
  let prop = this.userProperties.getByRef(TTSREFS.AUTO_SCROLL_REF);
43086
43293
  if (prop) {
@@ -43090,8 +43297,7 @@ var TTSSettings = class {
43090
43297
  this.settingsChangeCallback();
43091
43298
  }
43092
43299
  if (ttsSettings.voice) {
43093
- if (IS_DEV)
43094
- console.log("voice " + this.voice);
43300
+ import_loglevel15.default.log("voice " + this.voice);
43095
43301
  this.voice = ttsSettings.voice;
43096
43302
  let prop = this.userProperties.getByRef(TTSREFS.VOICE_REF);
43097
43303
  if (prop) {
@@ -43180,9 +43386,6 @@ init_polyfills();
43180
43386
 
43181
43387
  // src/utils/HTMLTemplates.ts
43182
43388
  init_polyfills();
43183
- var simpleUpLinkTemplate = (href, _label, ariaLabel) => `
43184
- <a rel="up" href='${href}' aria-label="${ariaLabel}" style="padding: 0px"><i class="material-icons show-on-large">arrow_back_ios</i></a>
43185
- `;
43186
43389
  var readerLoading = `${icons.loading}`;
43187
43390
  var readerError = `
43188
43391
  <span>
@@ -43430,15 +43633,14 @@ var SampleReadEventHandler = class {
43430
43633
 
43431
43634
  // src/navigator/IFrameNavigator.ts
43432
43635
  var import_eventemitter3 = __toModule(require_eventemitter3());
43636
+ var import_loglevel16 = __toModule(require_loglevel());
43433
43637
  var IFrameNavigator = class extends import_eventemitter3.default {
43434
- constructor(settings, annotator = void 0, upLinkConfig = void 0, initialLastReadingPosition = void 0, publication, material, api, rights, tts, injectables, attributes, services, sample) {
43638
+ constructor(settings, annotator = void 0, initialLastReadingPosition = void 0, publication, api, rights, tts, injectables, attributes, services, sample, requestConfig) {
43435
43639
  super();
43436
43640
  this.iframes = [];
43437
43641
  this.sideNavExpanded = false;
43438
- this.material = false;
43439
43642
  this.currentChapterLink = { href: "" };
43440
43643
  this.currentSpreadLinks = {};
43441
- this.upLink = void 0;
43442
43644
  this.rights = {
43443
43645
  autoGeneratePositions: false,
43444
43646
  enableAnnotations: false,
@@ -43467,10 +43669,8 @@ var IFrameNavigator = class extends import_eventemitter3.default {
43467
43669
  }
43468
43670
  if (lastReadingPosition) {
43469
43671
  const linkHref = this.publication.getAbsoluteHref(lastReadingPosition.href);
43470
- if (IS_DEV)
43471
- console.log(lastReadingPosition.href);
43472
- if (IS_DEV)
43473
- console.log(linkHref);
43672
+ import_loglevel16.default.log(lastReadingPosition.href);
43673
+ import_loglevel16.default.log(linkHref);
43474
43674
  lastReadingPosition.href = linkHref;
43475
43675
  await this.navigate(lastReadingPosition);
43476
43676
  }
@@ -43503,10 +43703,8 @@ var IFrameNavigator = class extends import_eventemitter3.default {
43503
43703
  this.eventHandler = new EventHandler(this);
43504
43704
  this.touchEventHandler = new TouchEventHandler(this);
43505
43705
  this.keyboardEventHandler = new KeyboardEventHandler(this);
43506
- this.upLinkConfig = upLinkConfig;
43507
43706
  this.initialLastReadingPosition = initialLastReadingPosition;
43508
43707
  this.publication = publication;
43509
- this.material = material;
43510
43708
  this.api = api;
43511
43709
  this.rights = rights ?? {
43512
43710
  autoGeneratePositions: false,
@@ -43529,17 +43727,16 @@ var IFrameNavigator = class extends import_eventemitter3.default {
43529
43727
  this.attributes = attributes || { margin: 0 };
43530
43728
  this.services = services;
43531
43729
  this.sample = sample;
43730
+ this.requestConfig = requestConfig;
43532
43731
  this.sampleReadEventHandler = new SampleReadEventHandler(this);
43533
43732
  }
43534
43733
  static async create(config2) {
43535
- const navigator2 = new this(config2.settings, config2.annotator || void 0, config2.upLink || void 0, config2.initialLastReadingPosition || void 0, config2.publication, config2.material, config2.api, config2.rights, config2.tts, config2.injectables, config2.attributes || { margin: 0 }, config2.services, config2.sample);
43734
+ const navigator2 = new this(config2.settings, config2.annotator || void 0, config2.initialLastReadingPosition || void 0, config2.publication, config2.api, config2.rights, config2.tts, config2.injectables, config2.attributes || { margin: 0 }, config2.services, config2.sample, config2.requestConfig);
43536
43735
  await navigator2.start(config2.mainElement, config2.headerMenu, config2.footerMenu);
43537
43736
  return new Promise((resolve) => resolve(navigator2));
43538
43737
  }
43539
43738
  stop() {
43540
- if (IS_DEV) {
43541
- console.log("Iframe navigator stop");
43542
- }
43739
+ import_loglevel16.default.log("Iframe navigator stop");
43543
43740
  removeEventListenerOptional(this.previousChapterAnchorElement, "click", this.handlePreviousChapterClick.bind(this));
43544
43741
  removeEventListenerOptional(this.nextChapterAnchorElement, "click", this.handleNextChapterClick.bind(this));
43545
43742
  removeEventListenerOptional(this.previousChapterTopAnchorElement, "click", this.handlePreviousPageClick.bind(this));
@@ -43747,7 +43944,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
43747
43944
  this.setupEvents();
43748
43945
  return await this.loadManifest();
43749
43946
  } catch (err) {
43750
- console.error(err);
43947
+ import_loglevel16.default.error(err);
43751
43948
  this.abortOnError(err);
43752
43949
  return Promise.reject(err);
43753
43950
  }
@@ -44030,22 +44227,6 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44030
44227
  this.landmarksSection.parentElement?.removeChild(this.landmarksSection);
44031
44228
  }
44032
44229
  }
44033
- if ((this.links || this.linksTopLeft) && this.upLinkConfig && this.upLinkConfig.url) {
44034
- const upUrl = this.upLinkConfig.url;
44035
- const upLabel = this.upLinkConfig.label || "";
44036
- const upAriaLabel = this.upLinkConfig.ariaLabel || upLabel;
44037
- var upHTML = simpleUpLinkTemplate(upUrl.href, upLabel, upAriaLabel);
44038
- const upParent = document.createElement("li");
44039
- upParent.classList.add("uplink-wrapper");
44040
- upParent.innerHTML = upHTML;
44041
- if (this.links) {
44042
- this.links.insertBefore(upParent, this.links.firstChild);
44043
- this.upLink = findRequiredElement(this.links, "a[rel=up]");
44044
- } else {
44045
- this.linksTopLeft.insertBefore(upParent, this.linksTopLeft.firstChild);
44046
- this.upLink = findRequiredElement(this.linksTopLeft, "a[rel=up]");
44047
- }
44048
- }
44049
44230
  let lastReadingPosition = void 0;
44050
44231
  if (this.annotator) {
44051
44232
  lastReadingPosition = await this.annotator.getLastReadingPosition();
@@ -44057,10 +44238,8 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44057
44238
  }
44058
44239
  if (lastReadingPosition) {
44059
44240
  const linkHref = this.publication.getAbsoluteHref(lastReadingPosition.href);
44060
- if (IS_DEV)
44061
- console.log(lastReadingPosition.href);
44062
- if (IS_DEV)
44063
- console.log(linkHref);
44241
+ import_loglevel16.default.log(lastReadingPosition.href);
44242
+ import_loglevel16.default.log(linkHref);
44064
44243
  lastReadingPosition.href = linkHref;
44065
44244
  await this.navigate(lastReadingPosition);
44066
44245
  } else if (startUrl) {
@@ -44076,7 +44255,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44076
44255
  }
44077
44256
  return new Promise((resolve) => resolve());
44078
44257
  } catch (err) {
44079
- console.error(err);
44258
+ import_loglevel16.default.error(err);
44080
44259
  this.abortOnError(err);
44081
44260
  return new Promise((_, reject) => reject(err)).catch(() => {
44082
44261
  });
@@ -44258,7 +44437,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44258
44437
  }, 200);
44259
44438
  return new Promise((resolve) => resolve());
44260
44439
  } catch (err) {
44261
- console.error(err);
44440
+ import_loglevel16.default.error(err);
44262
44441
  this.abortOnError(err);
44263
44442
  return Promise.reject(err);
44264
44443
  }
@@ -44385,7 +44564,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44385
44564
  if (isSameOrigin) {
44386
44565
  this.iframes[0].src = this.currentChapterLink.href;
44387
44566
  } else {
44388
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content2) => {
44567
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44389
44568
  writeIframeDoc.call(this, content2, this.currentChapterLink.href);
44390
44569
  });
44391
44570
  }
@@ -44406,7 +44585,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44406
44585
  if (isSameOrigin) {
44407
44586
  this.iframes[1].src = href;
44408
44587
  } else {
44409
- fetch(href).then((r) => r.text()).then(async (content2) => {
44588
+ fetch(href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44410
44589
  writeIframe2Doc.call(this, content2, href);
44411
44590
  this.currentSpreadLinks.right = {
44412
44591
  href
@@ -44435,7 +44614,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44435
44614
  if (isSameOrigin) {
44436
44615
  this.iframes[0].src = href;
44437
44616
  } else {
44438
- fetch(href).then((r) => r.text()).then(async (content2) => {
44617
+ fetch(href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44439
44618
  writeIframeDoc.call(this, content2, href);
44440
44619
  });
44441
44620
  }
@@ -44456,7 +44635,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44456
44635
  if (isSameOrigin) {
44457
44636
  this.iframes[1].src = this.currentChapterLink.href;
44458
44637
  } else {
44459
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content2) => {
44638
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44460
44639
  writeIframe2Doc.call(this, content2, this.currentChapterLink.href);
44461
44640
  });
44462
44641
  }
@@ -44475,7 +44654,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44475
44654
  if (isSameOrigin) {
44476
44655
  this.iframes[0].src = this.currentChapterLink.href;
44477
44656
  } else {
44478
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content2) => {
44657
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44479
44658
  writeIframeDoc.call(this, content2, this.currentChapterLink.href);
44480
44659
  });
44481
44660
  }
@@ -44493,7 +44672,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44493
44672
  if (isSameOrigin) {
44494
44673
  this.iframes[0].src = this.currentChapterLink.href;
44495
44674
  } else {
44496
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content2) => {
44675
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content2) => {
44497
44676
  writeIframeDoc.call(this, content2, this.currentChapterLink.href);
44498
44677
  });
44499
44678
  }
@@ -44526,7 +44705,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44526
44705
  }
44527
44706
  }
44528
44707
  } else {
44529
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content) => {
44708
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44530
44709
  writeIframeDoc.call(this, content, this.currentChapterLink.href);
44531
44710
  });
44532
44711
  if (this.iframes.length === 2) {
@@ -44537,7 +44716,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44537
44716
  this.currentSpreadLinks.right = {
44538
44717
  href
44539
44718
  };
44540
- fetch(href).then((r) => r.text()).then(async (content) => {
44719
+ fetch(href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44541
44720
  writeIframe2Doc.call(this, content, href);
44542
44721
  });
44543
44722
  }
@@ -44560,14 +44739,14 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44560
44739
  this.iframes[1].src = this.currentChapterLink.href;
44561
44740
  }
44562
44741
  } else {
44563
- fetch(href).then((r) => r.text()).then(async (content) => {
44742
+ fetch(href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44564
44743
  writeIframeDoc.call(this, content, href);
44565
44744
  });
44566
44745
  if (this.iframes.length === 2) {
44567
44746
  this.currentSpreadLinks.right = {
44568
44747
  href: this.currentChapterLink.href
44569
44748
  };
44570
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content) => {
44749
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44571
44750
  writeIframe2Doc.call(this, content, this.currentChapterLink.href);
44572
44751
  });
44573
44752
  }
@@ -44583,7 +44762,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44583
44762
  if (isSameOrigin) {
44584
44763
  this.iframes[1].src = this.currentChapterLink.href;
44585
44764
  } else {
44586
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content) => {
44765
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44587
44766
  writeIframe2Doc.call(this, content, this.currentChapterLink.href);
44588
44767
  });
44589
44768
  }
@@ -44596,7 +44775,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44596
44775
  if (isSameOrigin) {
44597
44776
  this.iframes[0].src = this.currentChapterLink.href;
44598
44777
  } else {
44599
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content) => {
44778
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44600
44779
  writeIframeDoc.call(this, content, this.currentChapterLink.href);
44601
44780
  });
44602
44781
  }
@@ -44608,7 +44787,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44608
44787
  if (isSameOrigin) {
44609
44788
  this.iframes[0].src = this.currentChapterLink.href;
44610
44789
  } else {
44611
- fetch(this.currentChapterLink.href).then((r) => r.text()).then(async (content) => {
44790
+ fetch(this.currentChapterLink.href, this.requestConfig).then((r) => r.text()).then(async (content) => {
44612
44791
  writeIframeDoc.call(this, content, this.currentChapterLink.href);
44613
44792
  });
44614
44793
  }
@@ -44793,10 +44972,8 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44793
44972
  const position = __spreadValues({}, locator);
44794
44973
  position.locations = locations;
44795
44974
  const linkHref = this.publication.getAbsoluteHref(locator.href);
44796
- if (IS_DEV)
44797
- console.log(locator.href);
44798
- if (IS_DEV)
44799
- console.log(linkHref);
44975
+ import_loglevel16.default.log(locator.href);
44976
+ import_loglevel16.default.log(linkHref);
44800
44977
  position.href = linkHref;
44801
44978
  this.stopReadAloud();
44802
44979
  this.navigate(position);
@@ -44847,7 +45024,7 @@ var IFrameNavigator = class extends import_eventemitter3.default {
44847
45024
  snapToSelector(selector2) {
44848
45025
  const doc = this.iframes[0].contentDocument;
44849
45026
  if (doc) {
44850
- console.log(selector2);
45027
+ import_loglevel16.default.log(selector2);
44851
45028
  let result = doc.querySelectorAll(selector2);
44852
45029
  if (result.length > 0)
44853
45030
  this.view?.snap(result[0]);
@@ -45543,15 +45720,11 @@ var IFrameNavigator = class extends import_eventemitter3.default {
45543
45720
  }
45544
45721
  if (this.api?.updateCurrentLocation) {
45545
45722
  this.api?.updateCurrentLocation(position).then(async (_) => {
45546
- if (IS_DEV) {
45547
- console.log("api updated current location", position);
45548
- }
45723
+ import_loglevel16.default.log("api updated current location", position);
45549
45724
  return this.annotator?.saveLastReadingPosition(position);
45550
45725
  });
45551
45726
  } else {
45552
- if (IS_DEV) {
45553
- console.log("save last reading position", position);
45554
- }
45727
+ import_loglevel16.default.log("save last reading position", position);
45555
45728
  this.annotator.saveLastReadingPosition(position);
45556
45729
  }
45557
45730
  }
@@ -45788,8 +45961,12 @@ var _LocalAnnotator = class {
45788
45961
  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}`;
45789
45962
  const sha256Hex = SHA256.hash(uniqueStr);
45790
45963
  rangeRepresentation.highlight.id = "R2_HIGHLIGHT_" + sha256Hex;
45791
- var rangeColor;
45792
- rangeColor = rangeRepresentation.color;
45964
+ let rangeColor;
45965
+ if (rangeRepresentation.highlight.color) {
45966
+ rangeColor = rangeRepresentation.highlight.color;
45967
+ } else if (rangeRepresentation.color) {
45968
+ rangeColor = rangeRepresentation.color;
45969
+ }
45793
45970
  if (TextHighlighter.isHexColor(rangeColor)) {
45794
45971
  rangeColor = TextHighlighter.hexToRgbString(rangeColor);
45795
45972
  }
@@ -45801,6 +45978,21 @@ var _LocalAnnotator = class {
45801
45978
  this.store.set(_LocalAnnotator.ANNOTATIONS, JSON.stringify(annotationsToStore));
45802
45979
  return annotationsToStore;
45803
45980
  }
45981
+ saveTemporarySelectionInfo(selectionInfo) {
45982
+ this.store.set(_LocalAnnotator.SELECTIONINFO, JSON.stringify(selectionInfo));
45983
+ }
45984
+ getTemporarySelectionInfo(doc) {
45985
+ const selectionInfos = this.store.get(_LocalAnnotator.SELECTIONINFO);
45986
+ if (selectionInfos) {
45987
+ let selectionInfo = JSON.parse(selectionInfos);
45988
+ selectionInfo.range = convertRangeInfo(doc, selectionInfo.rangeInfo);
45989
+ return selectionInfo;
45990
+ }
45991
+ return [];
45992
+ }
45993
+ deleteTemporarySelectionInfo() {
45994
+ this.store.remove(_LocalAnnotator.SELECTIONINFO);
45995
+ }
45804
45996
  saveAnnotation(annotation) {
45805
45997
  let savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
45806
45998
  if (savedAnnotations) {
@@ -45851,7 +46043,7 @@ var _LocalAnnotator = class {
45851
46043
  const savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
45852
46044
  if (savedAnnotations) {
45853
46045
  const annotations = JSON.parse(savedAnnotations);
45854
- const filtered = annotations.filter((el) => el.id === id2);
46046
+ const filtered = annotations.filter((el) => el.highlight?.id === id2 || el.id === id2);
45855
46047
  if (filtered.length > 0) {
45856
46048
  let foundElement = iframeWin.document.getElementById(`${filtered[0].highlight.id}`);
45857
46049
  if (foundElement) {
@@ -45873,6 +46065,33 @@ var _LocalAnnotator = class {
45873
46065
  }
45874
46066
  return null;
45875
46067
  }
46068
+ getAnnotationElement(id2, iframeWin) {
46069
+ const savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
46070
+ if (savedAnnotations) {
46071
+ const annotations = JSON.parse(savedAnnotations);
46072
+ const filtered = annotations.filter((el) => el.highlight?.id === id2);
46073
+ if (filtered.length > 0) {
46074
+ let foundElement = iframeWin.document.getElementById(`${filtered[0].highlight.id}`);
46075
+ if (foundElement) {
46076
+ let position = 0;
46077
+ if (foundElement.hasChildNodes) {
46078
+ for (let i = 0; i < foundElement.childNodes.length; i++) {
46079
+ let childNode = foundElement.childNodes[i];
46080
+ let top = parseInt(childNode.style.top.replace("px", ""));
46081
+ if (top < position || position === 0) {
46082
+ position = top;
46083
+ return childNode;
46084
+ }
46085
+ }
46086
+ } else {
46087
+ position = parseInt(foundElement.style.top.replace("px", ""));
46088
+ }
46089
+ return foundElement;
46090
+ }
46091
+ }
46092
+ }
46093
+ return null;
46094
+ }
45876
46095
  getAnnotation(highlight) {
45877
46096
  const savedAnnotations = this.store.get(_LocalAnnotator.ANNOTATIONS);
45878
46097
  if (savedAnnotations) {
@@ -45900,6 +46119,7 @@ var LocalAnnotator = _LocalAnnotator;
45900
46119
  LocalAnnotator.LAST_READING_POSITION = "last-reading-position";
45901
46120
  LocalAnnotator.BOOKMARKS = "bookmarks";
45902
46121
  LocalAnnotator.ANNOTATIONS = "annotations";
46122
+ LocalAnnotator.SELECTIONINFO = "selectionInfo";
45903
46123
 
45904
46124
  // src/store/LocalStorageStore.ts
45905
46125
  init_polyfills();
@@ -46022,6 +46242,7 @@ function convertAndCamel(o) {
46022
46242
 
46023
46243
  // src/modules/highlight/LayerSettings.ts
46024
46244
  init_polyfills();
46245
+ var import_loglevel17 = __toModule(require_loglevel());
46025
46246
  var LayerSettings = class {
46026
46247
  constructor(store) {
46027
46248
  this.LAYERSETTINGS = "layerSetting";
@@ -46033,9 +46254,7 @@ var LayerSettings = class {
46033
46254
  return new Promise((resolve) => resolve(settings));
46034
46255
  }
46035
46256
  async stop() {
46036
- if (IS_DEV) {
46037
- console.log("MediaOverlay settings stop");
46038
- }
46257
+ import_loglevel17.default.log("MediaOverlay settings stop");
46039
46258
  }
46040
46259
  async initialize() {
46041
46260
  this.userProperties = await this.getLayerSettings();
@@ -46079,6 +46298,7 @@ var LayerSettings = class {
46079
46298
 
46080
46299
  // src/modules/pagebreak/PageBreakModule.ts
46081
46300
  init_polyfills();
46301
+ var import_loglevel18 = __toModule(require_loglevel());
46082
46302
  var PageBreakModule = class {
46083
46303
  static async create(config2) {
46084
46304
  const pageBreak = new this(config2.delegate, config2.publication, config2, config2.headerMenu);
@@ -46092,9 +46312,7 @@ var PageBreakModule = class {
46092
46312
  this.properties = properties;
46093
46313
  }
46094
46314
  async stop() {
46095
- if (IS_DEV) {
46096
- console.log("Page Break module stop");
46097
- }
46315
+ import_loglevel18.default.log("Page Break module stop");
46098
46316
  }
46099
46317
  async start() {
46100
46318
  this.delegate.pageBreakModule = this;
@@ -46160,16 +46378,15 @@ var PageBreakModule = class {
46160
46378
  return "";
46161
46379
  }
46162
46380
  } catch (err) {
46163
- console.log("uniqueCssSelector:");
46164
- console.log(err);
46381
+ import_loglevel18.default.log("uniqueCssSelector:");
46382
+ import_loglevel18.default.error(err);
46165
46383
  return "";
46166
46384
  }
46167
46385
  }
46168
46386
  if (pageBreaks) {
46169
46387
  for (let i = 0; i < pageBreaks.length; i++) {
46170
46388
  let img = pageBreaks[i];
46171
- if (IS_DEV)
46172
- console.log(img);
46389
+ import_loglevel18.default.log(img);
46173
46390
  let title = img.innerHTML;
46174
46391
  let hide = false;
46175
46392
  if (img.innerHTML.length === 0) {
@@ -46242,6 +46459,7 @@ var PageBreakModule = class {
46242
46459
  init_polyfills();
46243
46460
  var import_sanitize_html2 = __toModule(require_sanitize_html());
46244
46461
  var import_debounce6 = __toModule(require_debounce());
46462
+ var import_loglevel19 = __toModule(require_loglevel());
46245
46463
  var TTSModule2 = class {
46246
46464
  constructor(delegate, tts, rights, highlighter, properties, api, headerMenu) {
46247
46465
  this.voices = [];
@@ -46316,7 +46534,12 @@ var TTSModule2 = class {
46316
46534
  if (window.speechSynthesis.speaking && this.speaking && startX === this.startX && startY === this.startY) {
46317
46535
  let doc = this.delegate.iframes[0].contentDocument;
46318
46536
  if (doc) {
46319
- const selection = this.highlighter.dom(doc.body).getSelection();
46537
+ let selection = this.highlighter.dom(doc.body).getSelection();
46538
+ if (selection.isCollapsed) {
46539
+ let doc2 = this.delegate.iframes[0].contentDocument;
46540
+ const selectionInfo = this.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc2);
46541
+ selection.addRange(selectionInfo.range);
46542
+ }
46320
46543
  let range = selection.getRangeAt(0);
46321
46544
  let node = selection.anchorNode;
46322
46545
  while (range.toString().indexOf(" ") !== 0) {
@@ -46359,16 +46582,14 @@ var TTSModule2 = class {
46359
46582
  }
46360
46583
  let s = setSpeech();
46361
46584
  s.then(async (voices) => {
46362
- if (IS_DEV)
46363
- console.log(voices);
46585
+ import_loglevel19.default.log(voices);
46364
46586
  this.voices = [];
46365
46587
  voices.forEach((voice) => {
46366
46588
  if (voice.localService === true) {
46367
46589
  this.voices.push(voice);
46368
46590
  }
46369
46591
  });
46370
- if (IS_DEV)
46371
- console.log(this.voices);
46592
+ import_loglevel19.default.log(this.voices);
46372
46593
  if (first) {
46373
46594
  if (this.headerMenu) {
46374
46595
  var preferredLanguageSelector = findElement(this.headerMenu, "#preferred-languages");
@@ -46413,20 +46634,25 @@ var TTSModule2 = class {
46413
46634
  let rootEl = iframe.contentWindow?.document.body;
46414
46635
  let doc = this.delegate.iframes[0].contentDocument;
46415
46636
  if (doc) {
46416
- const selection = this.highlighter.dom(doc.body).getSelection();
46637
+ let selection = this.highlighter.dom(doc.body).getSelection();
46638
+ if (selection.isCollapsed) {
46639
+ let doc2 = self2.delegate.iframes[0].contentDocument;
46640
+ const selectionInfo2 = self2.delegate.annotationModule?.annotator?.getTemporarySelectionInfo(doc2);
46641
+ selection.addRange(selectionInfo2.range);
46642
+ }
46417
46643
  if (rootEl) {
46418
46644
  var ttsQueue = this.generateTtsQueue(rootEl);
46419
46645
  if (!ttsQueue.length) {
46420
46646
  return;
46421
46647
  }
46422
46648
  var idx = this.findTtsQueueItemIndex(ttsQueue, selection.anchorNode, selection.anchorNode, selection.anchorOffset, rootEl);
46423
- const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
46424
46649
  var idxEnd = this.findTtsQueueItemIndex(ttsQueue, selection.focusNode, selection.focusNode, selection.focusOffset, rootEl);
46650
+ const ttsQueueItem = getTtsQueueItemRef(ttsQueue, idx);
46425
46651
  const ttsQueueItemEnd = getTtsQueueItemRef(ttsQueue, idxEnd);
46426
46652
  var restOfTheText;
46427
46653
  if (ttsQueueItem && selectionInfo && selectionInfo.cleanText) {
46428
46654
  const sentence = getTtsQueueItemRefText(ttsQueueItem);
46429
- let startIndex = sentence.indexOf(selectionInfo.cleanText);
46655
+ let startIndex = selectionInfo.rangeInfo.startOffset;
46430
46656
  let textToBeSpoken = selectionInfo.cleanText;
46431
46657
  if (ttsQueueItemEnd && idx + 1 === idxEnd) {
46432
46658
  const sentenceEnd = getTtsQueueItemRefText(ttsQueueItemEnd);
@@ -46434,26 +46660,36 @@ var TTSModule2 = class {
46434
46660
  textToBeSpoken = sentence.slice(startIndex, sentence.length);
46435
46661
  restOfTheText = selectionInfo.cleanText.replace(textToBeSpoken, "").trim();
46436
46662
  } else if (idxEnd > idx) {
46437
- let mergedSentenses = "";
46663
+ let mergedSentences = "";
46438
46664
  for (let i = idx + 1; i < idxEnd; i++) {
46439
46665
  const ttsQueueItemInBetween = getTtsQueueItemRef(ttsQueue, i);
46440
46666
  if (ttsQueueItemInBetween) {
46441
46667
  const sentenceInBetween = getTtsQueueItemRefText(ttsQueueItemInBetween);
46442
- mergedSentenses += sentenceInBetween;
46668
+ mergedSentences += sentenceInBetween;
46443
46669
  restOfTheText = selectionInfo.cleanText.replace(sentenceInBetween, "");
46444
46670
  }
46445
46671
  }
46446
46672
  if (ttsQueueItemEnd) {
46447
46673
  const sentenceEnd = getTtsQueueItemRefText(ttsQueueItemEnd);
46448
- mergedSentenses += " " + sentenceEnd;
46674
+ mergedSentences += " " + sentenceEnd;
46449
46675
  }
46450
- startIndex = (sentence + " " + mergedSentenses).indexOf(selectionInfo.cleanText);
46676
+ startIndex = (sentence + " " + mergedSentences).indexOf(selectionInfo.cleanText);
46451
46677
  textToBeSpoken = sentence.slice(startIndex, sentence.length);
46452
46678
  restOfTheText = restOfTheText.replace(textToBeSpoken, "").trim();
46453
46679
  }
46454
46680
  utterance = new SpeechSynthesisUtterance(textToBeSpoken);
46681
+ import_loglevel19.default.log(selectionInfo);
46682
+ import_loglevel19.default.log(textToBeSpoken, selectionInfo.range?.commonAncestorContainer.textContent);
46683
+ import_loglevel19.default.log(ttsQueueItem);
46684
+ import_loglevel19.default.log(ttsQueueItem.item.textNodes);
46685
+ import_loglevel19.default.log(startIndex);
46686
+ import_loglevel19.default.log(ttsQueueItem.item.combinedText);
46687
+ let node = ttsQueueItem.item.textNodes.filter((node2) => {
46688
+ return node2 === selectionInfo.range?.commonAncestorContainer;
46689
+ })[0];
46690
+ import_loglevel19.default.log(node);
46455
46691
  utterance.onboundary = (ev) => {
46456
- this.updateTTSInfo(ttsQueueItem, ev.charIndex + startIndex, ev.charLength, utterance.text);
46692
+ this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, startIndex, utterance.text);
46457
46693
  };
46458
46694
  }
46459
46695
  }
@@ -46464,8 +46700,7 @@ var TTSModule2 = class {
46464
46700
  utterance.rate = this.tts.rate;
46465
46701
  utterance.pitch = this.tts.pitch;
46466
46702
  utterance.volume = this.tts.volume;
46467
- if (IS_DEV)
46468
- console.log("this.tts.voice.lang", this.tts.voice.lang);
46703
+ import_loglevel19.default.log("this.tts.voice.lang", this.tts.voice.lang);
46469
46704
  var initialVoiceHasHyphen = true;
46470
46705
  if (this.tts.voice && this.tts.voice.lang) {
46471
46706
  initialVoiceHasHyphen = this.tts.voice.lang.indexOf("-") !== -1;
@@ -46474,10 +46709,8 @@ var TTSModule2 = class {
46474
46709
  initialVoiceHasHyphen = true;
46475
46710
  }
46476
46711
  }
46477
- if (IS_DEV)
46478
- console.log("initialVoiceHasHyphen", initialVoiceHasHyphen);
46479
- if (IS_DEV)
46480
- console.log("voices", this.voices);
46712
+ import_loglevel19.default.log("initialVoiceHasHyphen", initialVoiceHasHyphen);
46713
+ import_loglevel19.default.log("voices", this.voices);
46481
46714
  var initialVoice;
46482
46715
  if (initialVoiceHasHyphen === true) {
46483
46716
  initialVoice = this.tts.voice && this.tts.voice.lang && this.tts.voice.name ? this.voices.filter((v) => {
@@ -46495,11 +46728,9 @@ var TTSModule2 = class {
46495
46728
  initialVoice = this.tts.voice && this.tts.voice.lang ? this.voices.filter((v) => v.lang === this.tts.voice.lang)[0] : void 0;
46496
46729
  }
46497
46730
  }
46498
- if (IS_DEV)
46499
- console.log("initialVoice", initialVoice);
46731
+ import_loglevel19.default.log("initialVoice", initialVoice);
46500
46732
  var publicationVoiceHasHyphen = self2.delegate.publication.Metadata.Language[0].indexOf("-") !== -1;
46501
- if (IS_DEV)
46502
- console.log("publicationVoiceHasHyphen", publicationVoiceHasHyphen);
46733
+ import_loglevel19.default.log("publicationVoiceHasHyphen", publicationVoiceHasHyphen);
46503
46734
  var publicationVoice;
46504
46735
  if (publicationVoiceHasHyphen === true) {
46505
46736
  publicationVoice = this.tts.voice && this.tts.voice.usePublication ? this.voices.filter((v) => {
@@ -46511,11 +46742,9 @@ var TTSModule2 = class {
46511
46742
  return v.lang.startsWith(self2.delegate.publication.Metadata.Language[0]) || v.lang.endsWith(self2.delegate.publication.Metadata.Language[0].toUpperCase());
46512
46743
  })[0] : void 0;
46513
46744
  }
46514
- if (IS_DEV)
46515
- console.log("publicationVoice", publicationVoice);
46745
+ import_loglevel19.default.log("publicationVoice", publicationVoice);
46516
46746
  var defaultVoiceHasHyphen = navigator.language.indexOf("-") !== -1;
46517
- if (IS_DEV)
46518
- console.log("defaultVoiceHasHyphen", defaultVoiceHasHyphen);
46747
+ import_loglevel19.default.log("defaultVoiceHasHyphen", defaultVoiceHasHyphen);
46519
46748
  var defaultVoice;
46520
46749
  if (defaultVoiceHasHyphen === true) {
46521
46750
  defaultVoice = this.voices.filter((voice) => {
@@ -46534,30 +46763,23 @@ var TTSModule2 = class {
46534
46763
  return lang.includes(navigator.language) && voice.localService === true;
46535
46764
  })[0];
46536
46765
  }
46537
- if (IS_DEV)
46538
- console.log("defaultVoice", defaultVoice);
46766
+ import_loglevel19.default.log("defaultVoice", defaultVoice);
46539
46767
  if (initialVoice) {
46540
- if (IS_DEV)
46541
- console.log("initialVoice");
46768
+ import_loglevel19.default.log("initialVoice");
46542
46769
  utterance.voice = initialVoice;
46543
46770
  } else if (publicationVoice) {
46544
- if (IS_DEV)
46545
- console.log("publicationVoice");
46771
+ import_loglevel19.default.log("publicationVoice");
46546
46772
  utterance.voice = publicationVoice;
46547
46773
  } else if (defaultVoice) {
46548
- if (IS_DEV)
46549
- console.log("defaultVoice");
46774
+ import_loglevel19.default.log("defaultVoice");
46550
46775
  utterance.voice = defaultVoice;
46551
46776
  }
46552
46777
  if (utterance.voice !== void 0 && utterance.voice !== null) {
46553
46778
  utterance.lang = utterance.voice.lang;
46554
- if (IS_DEV)
46555
- console.log("utterance.voice.lang", utterance.voice.lang);
46556
- if (IS_DEV)
46557
- console.log("utterance.lang", utterance.lang);
46779
+ import_loglevel19.default.log("utterance.voice.lang", utterance.voice.lang);
46780
+ import_loglevel19.default.log("utterance.lang", utterance.lang);
46558
46781
  }
46559
- if (IS_DEV)
46560
- console.log("navigator.language", navigator.language);
46782
+ import_loglevel19.default.log("navigator.language", navigator.language);
46561
46783
  setTimeout(() => {
46562
46784
  window.speechSynthesis.speak(utterance);
46563
46785
  }, 0);
@@ -46572,7 +46794,7 @@ var TTSModule2 = class {
46572
46794
  const sentence = getTtsQueueItemRefText(ttsQueueItem);
46573
46795
  utterance = new SpeechSynthesisUtterance(sentence);
46574
46796
  utterance.onboundary = (ev) => {
46575
- self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, utterance.text);
46797
+ self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
46576
46798
  };
46577
46799
  setTimeout(() => {
46578
46800
  window.speechSynthesis.speak(utterance);
@@ -46584,7 +46806,7 @@ var TTSModule2 = class {
46584
46806
  if (ttsQueueItem) {
46585
46807
  utterance = new SpeechSynthesisUtterance(restOfTheText);
46586
46808
  utterance.onboundary = (ev) => {
46587
- self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, utterance.text);
46809
+ self2.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
46588
46810
  };
46589
46811
  setTimeout(() => {
46590
46812
  window.speechSynthesis.speak(utterance);
@@ -46592,16 +46814,14 @@ var TTSModule2 = class {
46592
46814
  onend();
46593
46815
  }
46594
46816
  if (idx > idxEnd) {
46595
- if (IS_DEV)
46596
- console.log("utterance ended");
46817
+ import_loglevel19.default.log("utterance ended");
46597
46818
  self2.highlighter.doneSpeaking();
46598
46819
  self2.api?.finished();
46599
46820
  self2.delegate.emit("readaloud.finished", "finished");
46600
46821
  }
46601
46822
  }
46602
46823
  } else {
46603
- if (IS_DEV)
46604
- console.log("utterance ended");
46824
+ import_loglevel19.default.log("utterance ended");
46605
46825
  self2.highlighter.doneSpeaking();
46606
46826
  self2.api?.finished();
46607
46827
  self2.delegate.emit("readaloud.finished", "finished");
@@ -46718,9 +46938,7 @@ var TTSModule2 = class {
46718
46938
  }
46719
46939
  }
46720
46940
  stop() {
46721
- if (IS_DEV) {
46722
- console.log("TTS module stop");
46723
- }
46941
+ import_loglevel19.default.log("TTS module stop");
46724
46942
  removeEventListenerOptional(document, "wheel", this.wheel.bind(this));
46725
46943
  removeEventListenerOptional(this.body, "wheel", this.wheel.bind(this));
46726
46944
  removeEventListenerOptional(document, "keydown", this.wheel.bind(this));
@@ -46878,8 +47096,7 @@ var TTSModule2 = class {
46878
47096
  utterance.rate = this.tts.rate;
46879
47097
  utterance.pitch = this.tts.pitch;
46880
47098
  utterance.volume = this.tts.volume;
46881
- if (IS_DEV)
46882
- console.log("this.tts.voice.lang", this.tts.voice.lang);
47099
+ import_loglevel19.default.log("this.tts.voice.lang", this.tts.voice.lang);
46883
47100
  var initialVoiceHasHyphen = true;
46884
47101
  if (this.tts.voice && this.tts.voice.lang) {
46885
47102
  initialVoiceHasHyphen = this.tts.voice.lang.indexOf("-") !== -1;
@@ -46888,10 +47105,8 @@ var TTSModule2 = class {
46888
47105
  initialVoiceHasHyphen = true;
46889
47106
  }
46890
47107
  }
46891
- if (IS_DEV)
46892
- console.log("initialVoiceHasHyphen", initialVoiceHasHyphen);
46893
- if (IS_DEV)
46894
- console.log("voices", this.voices);
47108
+ import_loglevel19.default.log("initialVoiceHasHyphen", initialVoiceHasHyphen);
47109
+ import_loglevel19.default.log("voices", this.voices);
46895
47110
  var initialVoice;
46896
47111
  if (initialVoiceHasHyphen === true) {
46897
47112
  initialVoice = this.tts.voice && this.tts.voice.lang && this.tts.voice.name ? this.voices.filter((v) => {
@@ -46909,12 +47124,10 @@ var TTSModule2 = class {
46909
47124
  initialVoice = this.tts.voice && this.tts.voice.lang ? this.voices.filter((v) => v.lang === this.tts.voice.lang)[0] : void 0;
46910
47125
  }
46911
47126
  }
46912
- if (IS_DEV)
46913
- console.log("initialVoice", initialVoice);
47127
+ import_loglevel19.default.log("initialVoice", initialVoice);
46914
47128
  var self2 = this;
46915
47129
  var publicationVoiceHasHyphen = self2.delegate.publication.Metadata.Language[0].indexOf("-") !== -1;
46916
- if (IS_DEV)
46917
- console.log("publicationVoiceHasHyphen", publicationVoiceHasHyphen);
47130
+ import_loglevel19.default.log("publicationVoiceHasHyphen", publicationVoiceHasHyphen);
46918
47131
  var publicationVoice;
46919
47132
  if (publicationVoiceHasHyphen === true) {
46920
47133
  publicationVoice = this.tts.voice && this.tts.voice.usePublication ? this.voices.filter((v) => {
@@ -46926,11 +47139,9 @@ var TTSModule2 = class {
46926
47139
  return v.lang.startsWith(self2.delegate.publication.Metadata.Language[0]) || v.lang.endsWith(self2.delegate.publication.Metadata.Language[0].toUpperCase());
46927
47140
  })[0] : void 0;
46928
47141
  }
46929
- if (IS_DEV)
46930
- console.log("publicationVoice", publicationVoice);
47142
+ import_loglevel19.default.log("publicationVoice", publicationVoice);
46931
47143
  var defaultVoiceHasHyphen = navigator.language.indexOf("-") !== -1;
46932
- if (IS_DEV)
46933
- console.log("defaultVoiceHasHyphen", defaultVoiceHasHyphen);
47144
+ import_loglevel19.default.log("defaultVoiceHasHyphen", defaultVoiceHasHyphen);
46934
47145
  var defaultVoice;
46935
47146
  if (defaultVoiceHasHyphen === true) {
46936
47147
  defaultVoice = this.voices.filter((voice) => {
@@ -46949,33 +47160,26 @@ var TTSModule2 = class {
46949
47160
  return lang.includes(navigator.language) && voice.localService === true;
46950
47161
  })[0];
46951
47162
  }
46952
- if (IS_DEV)
46953
- console.log("defaultVoice", defaultVoice);
47163
+ import_loglevel19.default.log("defaultVoice", defaultVoice);
46954
47164
  if (initialVoice) {
46955
- if (IS_DEV)
46956
- console.log("initialVoice");
47165
+ import_loglevel19.default.log("initialVoice");
46957
47166
  utterance.voice = initialVoice;
46958
47167
  } else if (publicationVoice) {
46959
- if (IS_DEV)
46960
- console.log("publicationVoice");
47168
+ import_loglevel19.default.log("publicationVoice");
46961
47169
  utterance.voice = publicationVoice;
46962
47170
  } else if (defaultVoice) {
46963
- if (IS_DEV)
46964
- console.log("defaultVoice");
47171
+ import_loglevel19.default.log("defaultVoice");
46965
47172
  utterance.voice = defaultVoice;
46966
47173
  }
46967
47174
  if (utterance.voice !== void 0 && utterance.voice !== null) {
46968
47175
  utterance.lang = utterance.voice.lang;
46969
- if (IS_DEV)
46970
- console.log("utterance.voice.lang", utterance.voice.lang);
46971
- if (IS_DEV)
46972
- console.log("utterance.lang", utterance.lang);
47176
+ import_loglevel19.default.log("utterance.voice.lang", utterance.voice.lang);
47177
+ import_loglevel19.default.log("utterance.lang", utterance.lang);
46973
47178
  }
46974
- if (IS_DEV)
46975
- console.log("navigator.language", navigator.language);
47179
+ import_loglevel19.default.log("navigator.language", navigator.language);
46976
47180
  utterance.onboundary = (ev) => {
46977
- console.log(ev.name);
46978
- this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, utterance.text);
47181
+ import_loglevel19.default.log(ev.name);
47182
+ this.updateTTSInfo(ttsQueueItem, ev.charIndex, ev.charLength, 0, utterance.text);
46979
47183
  };
46980
47184
  setTimeout(() => {
46981
47185
  window.speechSynthesis.speak(utterance);
@@ -46989,44 +47193,40 @@ var TTSModule2 = class {
46989
47193
  }
46990
47194
  };
46991
47195
  }
46992
- updateTTSInfo(ttsQueueItem, charIndex, charLength, utteranceText) {
47196
+ updateTTSInfo(ttsQueueItem, charIndex, charLength, startIndex, utteranceText) {
46993
47197
  if (!ttsQueueItem) {
46994
47198
  return void 0;
46995
47199
  }
47200
+ import_loglevel19.default.log(ttsQueueItem, charIndex, charLength, utteranceText);
46996
47201
  const ttsQueueItemText = utteranceText ? utteranceText : getTtsQueueItemRefText(ttsQueueItem);
46997
47202
  if (charIndex >= 0 && utteranceText) {
46998
47203
  const start = utteranceText.slice(0, charIndex + 1).search(/\S+$/);
46999
47204
  const right = utteranceText.slice(charIndex).search(/\s/);
47000
47205
  const word = right < 0 ? utteranceText.slice(start) : utteranceText.slice(start, right + charIndex);
47001
47206
  const end = start + word.length;
47002
- let useStart = false;
47003
- if (!charLength) {
47207
+ if (charLength === void 0) {
47208
+ const match = utteranceText.substring(charIndex).match(/^[a-z\d']*/i);
47209
+ if (match) {
47210
+ charLength = match[0].length;
47211
+ }
47212
+ }
47213
+ if (charLength === void 0) {
47004
47214
  charLength = word.length;
47005
- useStart = true;
47006
- } else {
47007
- useStart = false;
47008
47215
  }
47009
- this.wrapHighlightWord(ttsQueueItem, utteranceText, useStart ? start : charIndex, charLength, word, start, end);
47216
+ this.wrapHighlightWord(ttsQueueItem, utteranceText, charIndex + startIndex, charLength, word, start, end);
47010
47217
  }
47011
47218
  return ttsQueueItemText;
47012
47219
  }
47013
47220
  wrapHighlightWord(ttsQueueItemRef, utteranceText, charIndex, charLength, word, start, end) {
47221
+ import_loglevel19.default.log(ttsQueueItemRef);
47222
+ import_loglevel19.default.log(utteranceText);
47223
+ import_loglevel19.default.log(charIndex, charLength, word, start, end);
47014
47224
  if (this._ttsQueueItemHighlightsWord) {
47015
47225
  this.delegate.highlighter?.destroyHighlights(HighlightType.ReadAloud);
47016
47226
  this._ttsQueueItemHighlightsWord = void 0;
47017
47227
  }
47018
47228
  const ttsQueueItem = ttsQueueItemRef.item;
47019
- let txtToCheck = ttsQueueItemRef.item.combinedText;
47020
47229
  let charIndexAdjusted = charIndex;
47021
- if (IS_DEV) {
47022
- if (utteranceText !== txtToCheck) {
47023
- console.log("TTS utteranceText DIFF?? ", `[[${utteranceText}]]`, `[[${txtToCheck}]]`);
47024
- }
47025
- const ttsWord = utteranceText.substr(charIndex, charLength);
47026
- if (ttsWord !== word) {
47027
- console.log("TTS word DIFF?? ", `[[${ttsWord}]]`, `[[${word}]]`, `${charIndex}--${charLength}`, `${start}--${end - start}`);
47028
- }
47029
- }
47030
47230
  let acc = 0;
47031
47231
  let rangeStartNode;
47032
47232
  let rangeStartOffset = -1;
@@ -47063,8 +47263,8 @@ var TTSModule2 = class {
47063
47263
  return "";
47064
47264
  }
47065
47265
  } catch (err) {
47066
- console.log("uniqueCssSelector:");
47067
- console.log(err);
47266
+ import_loglevel19.default.log("uniqueCssSelector:");
47267
+ import_loglevel19.default.error(err);
47068
47268
  return "";
47069
47269
  }
47070
47270
  };
@@ -47171,6 +47371,7 @@ function getTtsQueueItemRefText(obj) {
47171
47371
  init_polyfills();
47172
47372
  var lodash3 = __toModule(require_lodash());
47173
47373
  var import_debounce7 = __toModule(require_debounce());
47374
+ var import_loglevel20 = __toModule(require_loglevel());
47174
47375
  var DefinitionsModule = class {
47175
47376
  constructor(delegate, publication, properties, highlighter, api) {
47176
47377
  this.currentChapterPopupResult = [];
@@ -47195,9 +47396,7 @@ var DefinitionsModule = class {
47195
47396
  return search;
47196
47397
  }
47197
47398
  async stop() {
47198
- if (IS_DEV) {
47199
- console.log("Definitions module stop");
47200
- }
47399
+ import_loglevel20.default.log("Definitions module stop");
47201
47400
  }
47202
47401
  async start() {
47203
47402
  this.delegate.definitionsModule = this;
@@ -47319,6 +47518,7 @@ var DefinitionsModule = class {
47319
47518
 
47320
47519
  // src/modules/linefocus/LineFocusModule.ts
47321
47520
  init_polyfills();
47521
+ var import_loglevel21 = __toModule(require_loglevel());
47322
47522
  var DEFAULT_BACKGROUND_COLOR_OPACITY2 = 0.5;
47323
47523
  var LineFocusModule = class {
47324
47524
  constructor(delegate, properties, highlighter, api) {
@@ -47343,9 +47543,7 @@ var LineFocusModule = class {
47343
47543
  return search;
47344
47544
  }
47345
47545
  async stop() {
47346
- if (IS_DEV) {
47347
- console.log("Definitions module stop");
47348
- }
47546
+ import_loglevel21.default.log("Definitions module stop");
47349
47547
  this.hasEventListener = false;
47350
47548
  removeEventListenerOptional(document, "keydown", this.keydown.bind(this));
47351
47549
  removeEventListenerOptional(document, "keyup", this.keyup.bind(this));
@@ -47740,11 +47938,9 @@ var LineFocusModule = class {
47740
47938
  range.detach();
47741
47939
  return rect;
47742
47940
  } catch (error) {
47743
- if (IS_DEV) {
47744
- console.log("measureTextNode " + error);
47745
- console.log("measureTextNode " + node);
47746
- console.log(node.textContent);
47747
- }
47941
+ import_loglevel21.default.log("measureTextNode " + error);
47942
+ import_loglevel21.default.log("measureTextNode " + node);
47943
+ import_loglevel21.default.log(`${node.textContent}`);
47748
47944
  }
47749
47945
  }
47750
47946
  measureImageNodes(node) {
@@ -47755,17 +47951,16 @@ var LineFocusModule = class {
47755
47951
  range.detach();
47756
47952
  return rect;
47757
47953
  } catch (error) {
47758
- if (IS_DEV) {
47759
- console.log("measureTextNode " + error);
47760
- console.log("measureTextNode " + node);
47761
- console.log(node.textContent);
47762
- }
47954
+ import_loglevel21.default.log("measureTextNode " + error);
47955
+ import_loglevel21.default.log("measureTextNode " + node);
47956
+ import_loglevel21.default.log(`${node.textContent}`);
47763
47957
  }
47764
47958
  }
47765
47959
  };
47766
47960
 
47767
47961
  // src/modules/history/HistoryModule.ts
47768
47962
  init_polyfills();
47963
+ var import_loglevel22 = __toModule(require_loglevel());
47769
47964
  var HistoryModule = class {
47770
47965
  constructor(annotator, delegate, publication, properties, headerMenu) {
47771
47966
  this.history = [];
@@ -47781,9 +47976,7 @@ var HistoryModule = class {
47781
47976
  return pageBreak;
47782
47977
  }
47783
47978
  async stop() {
47784
- if (IS_DEV) {
47785
- console.log("Page Break module stop");
47786
- }
47979
+ import_loglevel22.default.log("Page Break module stop");
47787
47980
  removeEventListenerOptional(this.historyForwardAnchorElement, "click", this.handleHistoryForwardClick.bind(this));
47788
47981
  removeEventListenerOptional(this.historyBackAnchorElement, "click", this.handleHistoryBackClick.bind(this));
47789
47982
  }
@@ -47821,10 +48014,8 @@ var HistoryModule = class {
47821
48014
  lastInHistory = this.history[this.history.length - 1];
47822
48015
  if (lastInHistory && lastInHistory.href !== lastReadingPosition.href || lastInHistory === void 0) {
47823
48016
  const linkHref = this.publication.getAbsoluteHref(lastReadingPosition.href);
47824
- if (IS_DEV)
47825
- console.log(lastReadingPosition.href);
47826
- if (IS_DEV)
47827
- console.log(linkHref);
48017
+ import_loglevel22.default.log(lastReadingPosition.href);
48018
+ import_loglevel22.default.log(linkHref);
47828
48019
  lastReadingPosition.href = linkHref;
47829
48020
  this.history.push(lastReadingPosition);
47830
48021
  this.historyCurrentIndex = this.history.length - 1;
@@ -47874,6 +48065,7 @@ var HistoryModule = class {
47874
48065
 
47875
48066
  // src/modules/citation/CitationModule.ts
47876
48067
  init_polyfills();
48068
+ var import_loglevel23 = __toModule(require_loglevel());
47877
48069
  var CitationStyle;
47878
48070
  (function(CitationStyle2) {
47879
48071
  CitationStyle2[CitationStyle2["Chicago"] = 0] = "Chicago";
@@ -47888,21 +48080,20 @@ var ContributorType;
47888
48080
  ContributorType2["Compiler"] = "Compiler";
47889
48081
  })(ContributorType || (ContributorType = {}));
47890
48082
  var CitationModule = class {
47891
- constructor(delegate, publication, highlighter, properties) {
48083
+ constructor(delegate, publication, highlighter, properties, api) {
47892
48084
  this.highlighter = highlighter;
47893
48085
  this.delegate = delegate;
47894
48086
  this.properties = properties;
47895
48087
  this.publication = publication;
48088
+ this.api = api;
47896
48089
  }
47897
48090
  static async create(config2) {
47898
- const module = new this(config2.delegate, config2.publication, config2.highlighter, config2);
48091
+ const module = new this(config2.delegate, config2.publication, config2.highlighter, config2, config2.api);
47899
48092
  await module.start();
47900
48093
  return module;
47901
48094
  }
47902
48095
  async stop() {
47903
- if (IS_DEV) {
47904
- console.log("Timeline module stop");
47905
- }
48096
+ import_loglevel23.default.log("Timeline module stop");
47906
48097
  }
47907
48098
  copyToClipboard(textToClipboard) {
47908
48099
  let success = true;
@@ -47922,9 +48113,9 @@ var CitationModule = class {
47922
48113
  document.body.removeChild(forExecElement);
47923
48114
  }
47924
48115
  if (success) {
47925
- alert("The text was copied to the clipboard!");
48116
+ this.api?.citationCreated("The text was copied to the clipboard!");
47926
48117
  } else {
47927
- alert("Your browser doesn't allow clipboard access!");
48118
+ this.api?.citationFailed("Your browser doesn't allow clipboard access!");
47928
48119
  }
47929
48120
  }
47930
48121
  createElementForExecCommand(textToClipboard) {
@@ -48317,9 +48508,16 @@ var D2Reader = class {
48317
48508
  const mainElement = findRequiredElement(document, "#D2Reader-Container");
48318
48509
  const headerMenu = findElement(document, "#headerMenu");
48319
48510
  const footerMenu = findElement(document, "#footerMenu");
48320
- const webPubManifestUrl = initialConfig.url;
48511
+ let webPubManifestUrl = initialConfig.url;
48512
+ let publication;
48513
+ if (initialConfig.publication) {
48514
+ publication = TaJsonDeserialize(initialConfig.publication, Publication);
48515
+ publication.manifestUrl = new URL(webPubManifestUrl);
48516
+ } else {
48517
+ publication = await Publication.fromUrl(webPubManifestUrl, initialConfig.requestConfig);
48518
+ }
48321
48519
  const store = new LocalStorageStore({
48322
- prefix: webPubManifestUrl.href,
48520
+ prefix: publication.manifestUrl,
48323
48521
  useLocalStorage: initialConfig.useLocalStorage ?? false
48324
48522
  });
48325
48523
  const settingsStore = new LocalStorageStore({
@@ -48331,18 +48529,16 @@ var D2Reader = class {
48331
48529
  useLocalStorage: initialConfig.useLocalStorage ?? false
48332
48530
  });
48333
48531
  const annotator = new LocalAnnotator({ store });
48334
- const upLink = initialConfig.upLinkUrl ?? void 0;
48335
- const publication = await Publication.fromUrl(webPubManifestUrl);
48336
48532
  publication.sample = initialConfig.sample;
48337
48533
  rights = updateConfig(rights, publication);
48338
48534
  if (rights.autoGeneratePositions) {
48339
- await publication.autoGeneratePositions();
48535
+ await publication.autoGeneratePositions(initialConfig.requestConfig);
48340
48536
  } else {
48341
48537
  if (initialConfig.services?.positions) {
48342
- await publication.fetchPositionsFromService(initialConfig.services?.positions.href);
48538
+ await publication.fetchPositionsFromService(initialConfig.services?.positions.href, initialConfig.requestConfig);
48343
48539
  }
48344
48540
  if (initialConfig.services?.weight) {
48345
- await publication.fetchWeightsFromService(initialConfig.services?.weight.href);
48541
+ await publication.fetchWeightsFromService(initialConfig.services?.weight.href, initialConfig.requestConfig);
48346
48542
  }
48347
48543
  }
48348
48544
  const layers = await LayerSettings.create({ store: layerStore });
@@ -48350,7 +48546,6 @@ var D2Reader = class {
48350
48546
  store: settingsStore,
48351
48547
  initialUserSettings: initialConfig.userSettings,
48352
48548
  headerMenu,
48353
- material: initialConfig.material,
48354
48549
  api: initialConfig.api,
48355
48550
  injectables: (publication.Metadata.Rendition?.Layout ?? "unknown") === "fixed" ? initialConfig.injectablesFixed : initialConfig.injectables,
48356
48551
  layout: (publication.Metadata.Rendition?.Layout ?? "unknown") === "fixed" ? "fixed" : "reflowable"
@@ -48362,14 +48557,13 @@ var D2Reader = class {
48362
48557
  publication,
48363
48558
  settings,
48364
48559
  annotator,
48365
- upLink,
48366
48560
  initialLastReadingPosition: initialConfig.lastReadingPosition,
48367
- material: initialConfig.material,
48368
48561
  api: initialConfig.api,
48369
48562
  rights,
48370
48563
  tts: initialConfig.tts,
48371
48564
  sample: initialConfig.sample,
48372
- injectables: (publication.Metadata.Rendition?.Layout ?? "unknown") === "fixed" ? initialConfig.injectablesFixed : initialConfig.injectables,
48565
+ requestConfig: initialConfig.requestConfig,
48566
+ injectables: (publication.Metadata.Rendition?.Layout ?? "unknown") === "fixed" ? initialConfig.injectablesFixed ?? [] : initialConfig.injectables,
48373
48567
  attributes: initialConfig.attributes,
48374
48568
  services: initialConfig.services
48375
48569
  });