@d-i-t-a/reader 3.0.0-alpha.7 → 3.0.0-alpha.8

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
@@ -12860,6 +12860,69 @@ var require_debounce = __commonJS({
12860
12860
  }
12861
12861
  });
12862
12862
 
12863
+ // src/utils/Events.ts
12864
+ var ReaderEvent;
12865
+ var init_Events = __esm({
12866
+ "src/utils/Events.ts"() {
12867
+ init_polyfills();
12868
+ ReaderEvent = {
12869
+ // Resource lifecycle
12870
+ ResourceReady: "resource.ready",
12871
+ ResourceStart: "resource.start",
12872
+ ResourceEnd: "resource.end",
12873
+ ResourceFits: "resource.fits",
12874
+ ResourceError: "resource.error",
12875
+ // Navigation info
12876
+ Direction: "direction",
12877
+ ChapterInfo: "chapterinfo",
12878
+ PositionInfo: "positioninfo",
12879
+ LocationChanged: "location.changed",
12880
+ // User interaction
12881
+ Click: "click",
12882
+ KeyDown: "keydown",
12883
+ // Error
12884
+ Error: "error",
12885
+ // TTS / Read Aloud
12886
+ ReadAloudStarted: "readaloud.started",
12887
+ ReadAloudStopped: "readaloud.stopped",
12888
+ ReadAloudPaused: "readaloud.paused",
12889
+ ReadAloudResumed: "readaloud.resumed",
12890
+ ReadAloudFinished: "readaloud.finished",
12891
+ // Media Overlays / Read Along
12892
+ ReadAlongStarted: "readalong.started",
12893
+ ReadAlongStopped: "readalong.stopped",
12894
+ ReadAlongPaused: "readalong.paused",
12895
+ ReadAlongResumed: "readalong.resumed",
12896
+ ReadAlongFinished: "readalong.finished",
12897
+ // Bookmarks
12898
+ BookmarkCreated: "bookmark.created",
12899
+ BookmarkDeleted: "bookmark.deleted",
12900
+ // Annotations
12901
+ AnnotationCreated: "annotation.created",
12902
+ AnnotationDeleted: "annotation.deleted",
12903
+ AnnotationUpdated: "annotation.updated",
12904
+ AnnotationSelected: "annotation.selected",
12905
+ AnnotationCommentAdded: "annotation.comment.added",
12906
+ // Text selection / Toolbox
12907
+ ToolboxOpened: "toolbox.opened",
12908
+ ToolboxClosed: "toolbox.closed",
12909
+ TextSelected: "text.selected",
12910
+ // Definitions
12911
+ DefinitionSuccess: "definition.success",
12912
+ DefinitionClick: "definition.click",
12913
+ DefinitionVisible: "definition.visible",
12914
+ // Citation
12915
+ CitationCreated: "citation.created",
12916
+ CitationFailed: "citation.failed",
12917
+ // Content Protection
12918
+ InspectDetected: "inspect.detected",
12919
+ // Consumption tracking
12920
+ ActionTracked: "consumption.action",
12921
+ IdleSince: "consumption.idle"
12922
+ };
12923
+ }
12924
+ });
12925
+
12863
12926
  // node_modules/cssesc/cssesc.js
12864
12927
  var require_cssesc = __commonJS({
12865
12928
  "node_modules/cssesc/cssesc.js"(exports, module) {
@@ -65355,6 +65418,7 @@ var init_PDFNavigator = __esm({
65355
65418
  init_polyfills();
65356
65419
  import_debounce8 = __toESM(require_debounce());
65357
65420
  init_eventemitter3();
65421
+ init_Events();
65358
65422
  init_pdf();
65359
65423
  init_pdf_viewer();
65360
65424
  init_EventHandler();
@@ -65476,10 +65540,14 @@ var init_PDFNavigator = __esm({
65476
65540
  this.saveLastReadingPosition();
65477
65541
  if (this.atStart()) {
65478
65542
  this.api?.resourceAtStart?.();
65479
- this.emit("resource.start");
65543
+ this.emit(ReaderEvent.ResourceStart, {
65544
+ href: this.publication.readingOrder[0]?.href
65545
+ });
65480
65546
  } else if (this.atEnd()) {
65481
65547
  this.api?.resourceAtEnd?.();
65482
- this.emit("resource.end");
65548
+ this.emit(ReaderEvent.ResourceEnd, {
65549
+ href: this.publication.readingOrder[0]?.href
65550
+ });
65483
65551
  }
65484
65552
  }
65485
65553
  );
@@ -65489,7 +65557,9 @@ var init_PDFNavigator = __esm({
65489
65557
  this._numPages = pagesCount;
65490
65558
  this.hideLoading();
65491
65559
  this.api?.resourceReady?.();
65492
- this.emit("resource.ready");
65560
+ this.emit(ReaderEvent.ResourceReady, {
65561
+ href: this.publication.readingOrder[0]?.href
65562
+ });
65493
65563
  if (!this._positionRestored) {
65494
65564
  this._positionRestored = true;
65495
65565
  await this.restoreLastReadingPosition();
@@ -65590,7 +65660,7 @@ var init_PDFNavigator = __esm({
65590
65660
  const error = err instanceof Error ? err : new Error(String(err));
65591
65661
  console.error("PDFNavigator: failed to load document", url, error);
65592
65662
  this.api?.onError?.(error);
65593
- this.emit("resource.error", error);
65663
+ this.emit(ReaderEvent.ResourceError, error);
65594
65664
  }
65595
65665
  }
65596
65666
  // ── Navigator interface ────────────────────────────────────────────────────
@@ -66027,6 +66097,7 @@ var init_PDFNavigator = __esm({
66027
66097
  } else {
66028
66098
  this.annotator.saveLastReadingPosition(position);
66029
66099
  }
66100
+ this.emit(ReaderEvent.LocationChanged, position);
66030
66101
  }
66031
66102
  async restoreLastReadingPosition() {
66032
66103
  if (this.initialLastReadingPosition) {
@@ -68738,7 +68809,7 @@ var Publication = class _Publication {
68738
68809
  // ── Layout detection ─────────────────────────────────────────
68739
68810
  get isFixedLayout() {
68740
68811
  if (this.metadata?.layout === "fixed") return true;
68741
- const renditionLayout = this.metadata?.otherMetadata?.["rendition:layout"];
68812
+ const renditionLayout = this.metadata?.otherMetadata?.["rendition:layout"] ?? this.metadata?.otherMetadata?.rendition?.layout;
68742
68813
  return renditionLayout === "pre-paginated" || renditionLayout === "fixed";
68743
68814
  }
68744
68815
  get isReflowable() {
@@ -71612,6 +71683,9 @@ var import_debounce2 = __toESM(require_debounce());
71612
71683
  // src/modules/highlight/common/highlight.ts
71613
71684
  init_polyfills();
71614
71685
 
71686
+ // src/modules/highlight/TextHighlighter.ts
71687
+ init_Events();
71688
+
71615
71689
  // src/modules/highlight/common/rect-utils.ts
71616
71690
  init_polyfills();
71617
71691
  var import_loglevel3 = __toESM(require_loglevel());
@@ -72578,18 +72652,25 @@ var TextHighlighter = class _TextHighlighter {
72578
72652
  if (!this.isSelectionMenuOpen) {
72579
72653
  this.isSelectionMenuOpen = true;
72580
72654
  if (this.api?.selectionMenuOpen) this.api?.selectionMenuOpen();
72581
- this.navigator.emit("toolbox.opened", "opened");
72655
+ const doc = this.navigator.iframes[0].contentDocument;
72656
+ const sel = doc ? this.dom(doc.body)?.getSelection() : null;
72657
+ const text = sel && !sel.isCollapsed ? sel.toString() : void 0;
72658
+ this.navigator.emit(ReaderEvent.ToolboxOpened, "opened", { text });
72659
+ if (text && sel) {
72660
+ if (this.api?.selection) this.api.selection(text, sel);
72661
+ this.navigator.emit(ReaderEvent.TextSelected, { text, selection: sel });
72662
+ }
72582
72663
  }
72583
72664
  }, 100);
72584
72665
  this.selectionMenuClosed = (0, import_debounce2.default)(() => {
72585
72666
  if (this.isSelectionMenuOpen) {
72586
72667
  this.isSelectionMenuOpen = false;
72587
72668
  if (this.api?.selectionMenuClose) this.api?.selectionMenuClose();
72588
- this.navigator.emit("toolbox.closed", "closed");
72669
+ this.navigator.emit(ReaderEvent.ToolboxClosed, "closed");
72589
72670
  }
72590
72671
  }, 100);
72591
- this.selection = (0, import_debounce2.default)((text, selection) => {
72592
- if (this.api?.selection) this.api?.selection(text, selection);
72672
+ /** @deprecated Selection callback now fires from selectionMenuOpened */
72673
+ this.selection = (0, import_debounce2.default)((_text, _selection) => {
72593
72674
  }, 100);
72594
72675
  this.getScrollingElement = (doc) => {
72595
72676
  if (doc?.scrollingElement) {
@@ -73569,6 +73650,10 @@ var TextHighlighter = class _TextHighlighter {
73569
73650
  if (menuItem?.note) {
73570
73651
  if (anno.highlight) {
73571
73652
  self3.navigator.annotationModule?.api?.addCommentToAnnotation(anno).then((result) => {
73653
+ self3.navigator.emit(
73654
+ ReaderEvent.AnnotationCommentAdded,
73655
+ result
73656
+ );
73572
73657
  self3.navigator.annotationModule?.updateAnnotation(result).then(async () => {
73573
73658
  import_loglevel5.default.log(
73574
73659
  "update highlight " + result.id
@@ -74361,6 +74446,7 @@ var TextHighlighter = class _TextHighlighter {
74361
74446
  if (payload.highlight.type === 0 /* Annotation */) {
74362
74447
  this.navigator.annotationModule?.api?.selectedAnnotation(anno).then(async () => {
74363
74448
  });
74449
+ this.navigator.emit(ReaderEvent.AnnotationSelected, anno);
74364
74450
  }
74365
74451
  if (anno?.id) {
74366
74452
  import_loglevel5.default.log("selected highlight " + anno.id);
@@ -74372,6 +74458,10 @@ var TextHighlighter = class _TextHighlighter {
74372
74458
  if (getComputedStyle(toolbox).display === "none") {
74373
74459
  let noteH = function() {
74374
74460
  self2.navigator.annotationModule?.api?.addCommentToAnnotation(anno).then((result) => {
74461
+ self2.navigator.emit(
74462
+ ReaderEvent.AnnotationCommentAdded,
74463
+ result
74464
+ );
74375
74465
  self2.navigator.annotationModule?.updateAnnotation(result).then(async () => {
74376
74466
  import_loglevel5.default.log("update highlight " + result.id);
74377
74467
  if (toolbox) {
@@ -74474,7 +74564,11 @@ var TextHighlighter = class _TextHighlighter {
74474
74564
  lodash.omit(result, "callbacks"),
74475
74565
  lodash.omit(foundHighlight, "definition")
74476
74566
  );
74477
- this.navigator.emit("definition.click", result, foundHighlight);
74567
+ this.navigator.emit(
74568
+ ReaderEvent.DefinitionClick,
74569
+ result,
74570
+ foundHighlight
74571
+ );
74478
74572
  }
74479
74573
  }
74480
74574
  }
@@ -75041,6 +75135,7 @@ var TextHighlighter = class _TextHighlighter {
75041
75135
  );
75042
75136
  self2.navigator.annotationModule?.api?.selectedAnnotation(anno).then(async () => {
75043
75137
  });
75138
+ self2.navigator.emit(ReaderEvent.AnnotationSelected, anno);
75044
75139
  } else if (self2.navigator.rights.enableBookmarks) {
75045
75140
  anno = await self2.navigator.bookmarkModule?.getAnnotationByID(
75046
75141
  highlight.id
@@ -75259,6 +75354,7 @@ var import_loglevel8 = __toESM(require_loglevel());
75259
75354
 
75260
75355
  // src/modules/consumption/ConsumptionModule.ts
75261
75356
  init_polyfills();
75357
+ init_Events();
75262
75358
  var import_loglevel7 = __toESM(require_loglevel());
75263
75359
  var ConsumptionModule = class {
75264
75360
  constructor(publication, properties, api) {
@@ -75309,6 +75405,7 @@ var ConsumptionModule = class {
75309
75405
  }
75310
75406
  trackAction(locator, action) {
75311
75407
  this.api?.actionTracked(locator, action);
75408
+ this.navigator.emit(ReaderEvent.ActionTracked, { locator, action });
75312
75409
  }
75313
75410
  startReadingSession(locator) {
75314
75411
  if (this.firstReadingLocator && this.lastReadingLocator) {
@@ -75400,6 +75497,7 @@ var ConsumptionModule = class {
75400
75497
  this.currSeconds++;
75401
75498
  if (this.currSeconds === this.properties.idleTimeout) {
75402
75499
  this.api?.idleSince(this.currSeconds);
75500
+ this.navigator.emit(ReaderEvent.IdleSince, this.currSeconds);
75403
75501
  if (this.startResearchTimer !== void 0) {
75404
75502
  this.updateResearchSession();
75405
75503
  } else {
@@ -75421,6 +75519,7 @@ var ConsumptionModule = class {
75421
75519
  };
75422
75520
 
75423
75521
  // src/modules/AnnotationModule.ts
75522
+ init_Events();
75424
75523
  var AnnotationModule = class _AnnotationModule {
75425
75524
  constructor(annotator, rights, publication, initialAnnotations, properties, highlighter, api, headerMenu) {
75426
75525
  this.hide = findElement(
@@ -75631,9 +75730,11 @@ var AnnotationModule = class _AnnotationModule {
75631
75730
  }
75632
75731
  async deleteAnnotation(highlight) {
75633
75732
  await this.deleteLocalHighlight(highlight.id);
75733
+ this.navigator.emit(ReaderEvent.AnnotationDeleted, highlight);
75634
75734
  }
75635
75735
  async addAnnotation(highlight) {
75636
75736
  await this.annotator?.saveAnnotation(highlight);
75737
+ this.navigator.emit(ReaderEvent.AnnotationCreated, highlight);
75637
75738
  await this.showHighlights();
75638
75739
  await this.drawHighlights();
75639
75740
  }
@@ -75641,27 +75742,33 @@ var AnnotationModule = class _AnnotationModule {
75641
75742
  if (this.api?.deleteAnnotation) {
75642
75743
  this.api?.deleteAnnotation(highlight).then(async () => {
75643
75744
  this.deleteLocalHighlight(highlight.id);
75745
+ this.navigator.emit(ReaderEvent.AnnotationDeleted, highlight);
75644
75746
  });
75645
75747
  } else {
75646
75748
  this.deleteLocalHighlight(highlight.id);
75749
+ this.navigator.emit(ReaderEvent.AnnotationDeleted, highlight);
75647
75750
  }
75648
75751
  }
75649
75752
  async deleteSelectedHighlight(highlight) {
75650
75753
  if (this.api?.deleteAnnotation) {
75651
75754
  this.api.deleteAnnotation(highlight).then(async () => {
75652
75755
  this.deleteLocalHighlight(highlight.id);
75756
+ this.navigator.emit(ReaderEvent.AnnotationDeleted, highlight);
75653
75757
  });
75654
75758
  } else {
75655
75759
  this.deleteLocalHighlight(highlight.id);
75760
+ this.navigator.emit(ReaderEvent.AnnotationDeleted, highlight);
75656
75761
  }
75657
75762
  }
75658
75763
  async updateAnnotation(highlight) {
75659
75764
  if (this.api?.updateAnnotation) {
75660
75765
  this.api.updateAnnotation(highlight).then(async () => {
75661
75766
  this.updateLocalHighlight(highlight);
75767
+ this.navigator.emit(ReaderEvent.AnnotationUpdated, highlight);
75662
75768
  });
75663
75769
  } else {
75664
75770
  this.updateLocalHighlight(highlight);
75771
+ this.navigator.emit(ReaderEvent.AnnotationUpdated, highlight);
75665
75772
  }
75666
75773
  }
75667
75774
  async saveAnnotation(highlight) {
@@ -75739,6 +75846,7 @@ var AnnotationModule = class _AnnotationModule {
75739
75846
  try {
75740
75847
  let result = await this.api.addAnnotation(annotation);
75741
75848
  const saved = await this.annotator.saveAnnotation(result);
75849
+ this.navigator.emit(ReaderEvent.AnnotationCreated, saved);
75742
75850
  await this.showHighlights();
75743
75851
  await this.drawHighlights();
75744
75852
  return new Promise((resolve) => resolve(saved));
@@ -75748,6 +75856,7 @@ var AnnotationModule = class _AnnotationModule {
75748
75856
  }
75749
75857
  } else {
75750
75858
  const saved = await this.annotator.saveAnnotation(annotation);
75859
+ this.navigator.emit(ReaderEvent.AnnotationCreated, saved);
75751
75860
  await this.showHighlights();
75752
75861
  await this.drawHighlights();
75753
75862
  return new Promise((resolve) => resolve(saved));
@@ -76248,6 +76357,7 @@ init_HTMLUtilities();
76248
76357
  init_EventHandler();
76249
76358
  init_IconLib();
76250
76359
  var import_loglevel9 = __toESM(require_loglevel());
76360
+ init_Events();
76251
76361
  var BookmarkModule = class _BookmarkModule {
76252
76362
  static async create(config2) {
76253
76363
  const module = new this(
@@ -76333,12 +76443,14 @@ var BookmarkModule = class _BookmarkModule {
76333
76443
  await this.api?.deleteBookmark(bookmark);
76334
76444
  let deleted = await this.annotator.deleteBookmark(bookmark);
76335
76445
  import_loglevel9.default.log("Bookmark deleted " + JSON.stringify(deleted));
76446
+ this.navigator.emit(ReaderEvent.BookmarkDeleted, bookmark);
76336
76447
  await this.showBookmarks();
76337
76448
  await this.drawBookmarks();
76338
76449
  return deleted;
76339
76450
  } else {
76340
76451
  let deleted = await this.annotator.deleteBookmark(bookmark);
76341
76452
  import_loglevel9.default.log("Bookmark deleted " + JSON.stringify(deleted));
76453
+ this.navigator.emit(ReaderEvent.BookmarkDeleted, bookmark);
76342
76454
  await this.showBookmarks();
76343
76455
  await this.drawBookmarks();
76344
76456
  return deleted;
@@ -76413,12 +76525,14 @@ var BookmarkModule = class _BookmarkModule {
76413
76525
  import_loglevel9.default.log(bookmark);
76414
76526
  let saved = this.annotator.saveBookmark(bookmark);
76415
76527
  import_loglevel9.default.log("Bookmark added " + JSON.stringify(saved));
76528
+ this.navigator.emit(ReaderEvent.BookmarkCreated, bookmark);
76416
76529
  this.showBookmarks();
76417
76530
  await this.drawBookmarks();
76418
76531
  return saved;
76419
76532
  } else {
76420
76533
  let saved = this.annotator.saveBookmark(bookmark);
76421
76534
  import_loglevel9.default.log("Bookmark added " + JSON.stringify(saved));
76535
+ this.navigator.emit(ReaderEvent.BookmarkCreated, bookmark);
76422
76536
  this.showBookmarks();
76423
76537
  await this.drawBookmarks();
76424
76538
  return saved;
@@ -76613,11 +76727,13 @@ var BookmarkModule = class _BookmarkModule {
76613
76727
  if (this.api?.addBookmark) {
76614
76728
  let result = await this.api.addBookmark(annotation);
76615
76729
  const saved = await this.annotator.saveAnnotation(result);
76730
+ this.navigator.emit(ReaderEvent.BookmarkCreated, annotation);
76616
76731
  await this.showBookmarks();
76617
76732
  await this.drawBookmarks();
76618
76733
  return new Promise((resolve) => resolve(saved));
76619
76734
  } else {
76620
76735
  const saved = await this.annotator.saveAnnotation(annotation);
76736
+ this.navigator.emit(ReaderEvent.BookmarkCreated, annotation);
76621
76737
  await this.showBookmarks();
76622
76738
  await this.drawBookmarks();
76623
76739
  return new Promise((resolve) => resolve(saved));
@@ -76907,6 +77023,7 @@ var BookmarkModule = class _BookmarkModule {
76907
77023
 
76908
77024
  // src/modules/mediaoverlays/MediaOverlayModule.ts
76909
77025
  init_polyfills();
77026
+ init_Events();
76910
77027
 
76911
77028
  // src/model/v3/MediaOverlayNode.ts
76912
77029
  init_polyfills();
@@ -77352,6 +77469,7 @@ var MediaOverlayModule = class {
77352
77469
  config2.settings,
77353
77470
  config2
77354
77471
  );
77472
+ mediaOverlay.api = config2.api;
77355
77473
  mediaOverlay.start();
77356
77474
  return mediaOverlay;
77357
77475
  }
@@ -77422,10 +77540,28 @@ var MediaOverlayModule = class {
77422
77540
  await this.playLink();
77423
77541
  } else {
77424
77542
  if (this.settings.autoTurn && this.settings.playing) {
77425
- if (this.audioElement) {
77426
- await this.audioElement.pause();
77543
+ const currentLink = this.currentLinks[this.currentLinkIndex];
77544
+ const nextLink = currentLink ? this.publication.getNextSpineItem(
77545
+ this.publication.getAbsoluteHref(currentLink.href)
77546
+ ) : void 0;
77547
+ if (nextLink) {
77548
+ if (this.audioElement) {
77549
+ await this.audioElement.pause();
77550
+ }
77551
+ this.navigator.nextResource();
77552
+ } else {
77553
+ await this.stopReadAloud();
77554
+ if (this.api?.finished) this.api.finished();
77555
+ this.navigator.emit(ReaderEvent.ReadAlongFinished, "finished", {
77556
+ href: this.currentLinks[this.currentLinkIndex]?.href
77557
+ });
77427
77558
  }
77428
- this.navigator.nextResource();
77559
+ } else if (this.settings.playing) {
77560
+ await this.stopReadAloud();
77561
+ if (this.api?.stopped) this.api.stopped();
77562
+ this.navigator.emit(ReaderEvent.ReadAlongStopped, "stopped", {
77563
+ href: this.currentLinks[this.currentLinkIndex]?.href
77564
+ });
77429
77565
  } else {
77430
77566
  await this.stopReadAloud();
77431
77567
  }
@@ -77538,6 +77674,10 @@ var MediaOverlayModule = class {
77538
77674
  if (this.play) this.play.style.display = "none";
77539
77675
  if (this.pause) this.pause.style.removeProperty("display");
77540
77676
  this.bindClickHandler();
77677
+ if (this.api?.started) this.api.started();
77678
+ this.navigator.emit(ReaderEvent.ReadAlongStarted, "started", {
77679
+ href: this.currentLinks[this.currentLinkIndex]?.href
77680
+ });
77541
77681
  }
77542
77682
  }
77543
77683
  async stopReadAloud() {
@@ -77555,6 +77695,10 @@ var MediaOverlayModule = class {
77555
77695
  this.audioElement.pause();
77556
77696
  if (this.play) this.play.style.removeProperty("display");
77557
77697
  if (this.pause) this.pause.style.display = "none";
77698
+ if (this.api?.paused) this.api.paused();
77699
+ this.navigator.emit(ReaderEvent.ReadAlongPaused, "paused", {
77700
+ href: this.currentLinks[this.currentLinkIndex]?.href
77701
+ });
77558
77702
  }
77559
77703
  }
77560
77704
  async resumeReadAloud() {
@@ -77563,6 +77707,10 @@ var MediaOverlayModule = class {
77563
77707
  await this.audioElement.play();
77564
77708
  if (this.play) this.play.style.display = "none";
77565
77709
  if (this.pause) this.pause.style.removeProperty("display");
77710
+ if (this.api?.resumed) this.api.resumed();
77711
+ this.navigator.emit(ReaderEvent.ReadAlongResumed, "resumed", {
77712
+ href: this.currentLinks[this.currentLinkIndex]?.href
77713
+ });
77566
77714
  }
77567
77715
  }
77568
77716
  findDepthFirstTextAudioPair(textHref, mo, textFragmentIDChain) {
@@ -77673,8 +77821,25 @@ var MediaOverlayModule = class {
77673
77821
  } else {
77674
77822
  this.audioElement.pause();
77675
77823
  if (this.settings.autoTurn && this.settings.playing) {
77676
- this.audioElement.pause();
77677
- this.navigator.nextResource();
77824
+ const currentLink = this.currentLinks[this.currentLinkIndex];
77825
+ const nextLink = currentLink ? this.publication.getNextSpineItem(
77826
+ this.publication.getAbsoluteHref(currentLink.href)
77827
+ ) : void 0;
77828
+ if (nextLink) {
77829
+ this.navigator.nextResource();
77830
+ } else {
77831
+ this.stopReadAloud();
77832
+ if (this.api?.finished) this.api.finished();
77833
+ this.navigator.emit(ReaderEvent.ReadAlongFinished, "finished", {
77834
+ href: this.currentLinks[this.currentLinkIndex]?.href
77835
+ });
77836
+ }
77837
+ } else if (this.settings.playing) {
77838
+ this.stopReadAloud();
77839
+ if (this.api?.stopped) this.api.stopped();
77840
+ this.navigator.emit(ReaderEvent.ReadAlongStopped, "stopped", {
77841
+ href: this.currentLinks[this.currentLinkIndex]?.href
77842
+ });
77678
77843
  } else {
77679
77844
  this.stopReadAloud();
77680
77845
  }
@@ -81806,6 +81971,7 @@ var TTSSettings = class {
81806
81971
 
81807
81972
  // src/navigator/IFrameNavigator.ts
81808
81973
  init_polyfills();
81974
+ init_Events();
81809
81975
  init_EventHandler();
81810
81976
  init_HTMLUtilities();
81811
81977
  init_HTMLTemplates();
@@ -82284,6 +82450,7 @@ var PageBreakModule = class {
82284
82450
 
82285
82451
  // src/modules/TTS/TTSModule2.ts
82286
82452
  init_polyfills();
82453
+ init_Events();
82287
82454
  init_HTMLUtilities();
82288
82455
  init_EventHandler();
82289
82456
  var import_sanitize_html2 = __toESM(require_sanitize_html());
@@ -82454,9 +82621,11 @@ var TTSModule2 = class {
82454
82621
  });
82455
82622
  }
82456
82623
  cancel(api = true) {
82457
- if (api) {
82624
+ if (api && this.speaking) {
82458
82625
  if (this.api?.stopped) this.api?.stopped();
82459
- this.navigator.emit("readaloud.stopped", "stopped");
82626
+ this.navigator.emit(ReaderEvent.ReadAloudStopped, "stopped", {
82627
+ locator: this.navigator.currentLocator()
82628
+ });
82460
82629
  }
82461
82630
  this.userScrolled = false;
82462
82631
  this.speaking = false;
@@ -82475,7 +82644,9 @@ var TTSModule2 = class {
82475
82644
  }
82476
82645
  }
82477
82646
  if (this.api?.started) this.api?.started();
82478
- this.navigator.emit("readaloud.started", "started");
82647
+ this.navigator.emit(ReaderEvent.ReadAloudStarted, "started", {
82648
+ locator: this.navigator.currentLocator()
82649
+ });
82479
82650
  const self2 = this;
82480
82651
  this.userScrolled = false;
82481
82652
  this.cancel(false);
@@ -82644,14 +82815,18 @@ var TTSModule2 = class {
82644
82815
  import_loglevel18.default.log("utterance ended");
82645
82816
  self2.highlighter.doneSpeaking();
82646
82817
  self2.api?.finished();
82647
- self2.navigator.emit("readaloud.finished", "finished");
82818
+ self2.navigator.emit(ReaderEvent.ReadAloudFinished, "finished", {
82819
+ locator: this.navigator.currentLocator()
82820
+ });
82648
82821
  }
82649
82822
  }
82650
82823
  } else {
82651
82824
  import_loglevel18.default.log("utterance ended");
82652
82825
  self2.highlighter.doneSpeaking();
82653
82826
  self2.api?.finished();
82654
- self2.navigator.emit("readaloud.finished", "finished");
82827
+ self2.navigator.emit(ReaderEvent.ReadAloudFinished, "finished", {
82828
+ locator: this.navigator.currentLocator()
82829
+ });
82655
82830
  }
82656
82831
  };
82657
82832
  }
@@ -82758,7 +82933,9 @@ var TTSModule2 = class {
82758
82933
  this.scrollPartial = true;
82759
82934
  this.cancel(false);
82760
82935
  if (this.api?.started) this.api?.started();
82761
- this.navigator.emit("readaloud.started", "started");
82936
+ this.navigator.emit(ReaderEvent.ReadAloudStarted, "started", {
82937
+ locator: this.navigator.currentLocator()
82938
+ });
82762
82939
  let self2 = this;
82763
82940
  let iframe = document.querySelector(
82764
82941
  "main#iframe-wrapper iframe"
@@ -82818,7 +82995,9 @@ var TTSModule2 = class {
82818
82995
  speakPause() {
82819
82996
  if (window.speechSynthesis.speaking) {
82820
82997
  if (this.api?.paused) this.api?.paused();
82821
- this.navigator.emit("readaloud.paused", "paused");
82998
+ this.navigator.emit(ReaderEvent.ReadAloudPaused, "paused", {
82999
+ locator: this.navigator.currentLocator()
83000
+ });
82822
83001
  this.userScrolled = false;
82823
83002
  window.speechSynthesis.pause();
82824
83003
  this.speaking = false;
@@ -82831,7 +83010,9 @@ var TTSModule2 = class {
82831
83010
  speakResume() {
82832
83011
  if (window.speechSynthesis.speaking) {
82833
83012
  if (this.api?.resumed) this.api?.resumed();
82834
- this.navigator.emit("readaloud.resumed", "resumed");
83013
+ this.navigator.emit(ReaderEvent.ReadAloudResumed, "resumed", {
83014
+ locator: this.navigator.currentLocator()
83015
+ });
82835
83016
  this.userScrolled = false;
82836
83017
  window.speechSynthesis.resume();
82837
83018
  this.speaking = true;
@@ -83269,6 +83450,7 @@ function getTtsQueueItemRefText(obj) {
83269
83450
  // src/modules/search/DefinitionsModule.ts
83270
83451
  init_polyfills();
83271
83452
  var lodash3 = __toESM(require_lodash());
83453
+ init_Events();
83272
83454
  var import_debounce6 = __toESM(require_debounce());
83273
83455
  var import_loglevel19 = __toESM(require_loglevel());
83274
83456
  var DefinitionsModule = class {
@@ -83361,7 +83543,9 @@ var DefinitionsModule = class {
83361
83543
  await this.searchAndPaint(item, async (result) => {
83362
83544
  if (this.api?.success) {
83363
83545
  this.api?.success(lodash3.omit(item, "callbacks"), result);
83364
- this.navigator.emit("definition.success", result);
83546
+ if (result && result.length > 0) {
83547
+ this.navigator.emit(ReaderEvent.DefinitionSuccess, result);
83548
+ }
83365
83549
  if (this.api?.visible) {
83366
83550
  result.forEach((highlight) => {
83367
83551
  let highlightParent = this.navigator.iframes[0].contentDocument?.querySelector(
@@ -83378,7 +83562,11 @@ var DefinitionsModule = class {
83378
83562
  lodash3.omit(item, "callbacks"),
83379
83563
  lodash3.omit(highlight, "definition")
83380
83564
  );
83381
- this.navigator.emit("definition.visible", item, highlight);
83565
+ this.navigator.emit(
83566
+ ReaderEvent.DefinitionVisible,
83567
+ item,
83568
+ highlight
83569
+ );
83382
83570
  }
83383
83571
  });
83384
83572
  },
@@ -84115,6 +84303,7 @@ var HistoryModule = class {
84115
84303
  // src/modules/citation/CitationModule.ts
84116
84304
  init_polyfills();
84117
84305
  var import_loglevel22 = __toESM(require_loglevel());
84306
+ init_Events();
84118
84307
  var CitationStyle = /* @__PURE__ */ ((CitationStyle2) => {
84119
84308
  CitationStyle2[CitationStyle2["Chicago"] = 0] = "Chicago";
84120
84309
  CitationStyle2[CitationStyle2["MLA"] = 1] = "MLA";
@@ -84160,7 +84349,13 @@ var CitationModule = class {
84160
84349
  tmp.innerHTML = textToClipboard;
84161
84350
  const plainText = tmp.textContent ?? tmp.innerText ?? textToClipboard;
84162
84351
  navigator.clipboard.writeText(plainText).then(
84163
- () => this.api?.citationCreated("The text was copied to the clipboard!"),
84352
+ () => {
84353
+ this.api?.citationCreated("The text was copied to the clipboard!");
84354
+ this.navigator.emit(
84355
+ ReaderEvent.CitationCreated,
84356
+ "The text was copied to the clipboard!"
84357
+ );
84358
+ },
84164
84359
  () => this.legacyCopyToClipboard(textToClipboard)
84165
84360
  );
84166
84361
  } else {
@@ -84187,8 +84382,16 @@ var CitationModule = class {
84187
84382
  document.body.removeChild(forExecElement);
84188
84383
  if (success) {
84189
84384
  this.api?.citationCreated("The text was copied to the clipboard!");
84385
+ this.navigator.emit(
84386
+ ReaderEvent.CitationCreated,
84387
+ "The text was copied to the clipboard!"
84388
+ );
84190
84389
  } else {
84191
84390
  this.api?.citationFailed("Your browser doesn't allow clipboard access!");
84391
+ this.navigator.emit(
84392
+ ReaderEvent.CitationFailed,
84393
+ "Your browser doesn't allow clipboard access!"
84394
+ );
84192
84395
  }
84193
84396
  }
84194
84397
  selectContent(element) {
@@ -84477,13 +84680,19 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
84477
84680
  this.checkResourcePosition = (0, import_debounce7.default)(() => {
84478
84681
  if (this.view?.atStart() && this.view?.atEnd()) {
84479
84682
  if (this.api?.resourceFitsScreen) this.api?.resourceFitsScreen();
84480
- this.emit("resource.fits");
84683
+ this.emit(ReaderEvent.ResourceFits, {
84684
+ href: this.currentChapterLink.href
84685
+ });
84481
84686
  } else if (this.view?.atEnd()) {
84482
84687
  if (this.api?.resourceAtEnd) this.api?.resourceAtEnd();
84483
- this.emit("resource.end");
84688
+ this.emit(ReaderEvent.ResourceEnd, {
84689
+ href: this.currentChapterLink.href
84690
+ });
84484
84691
  } else if (this.view?.atStart()) {
84485
84692
  if (this.api?.resourceAtStart) this.api?.resourceAtStart();
84486
- this.emit("resource.start");
84693
+ this.emit(ReaderEvent.ResourceStart, {
84694
+ href: this.currentChapterLink.href
84695
+ });
84487
84696
  }
84488
84697
  }, 200);
84489
84698
  this.highlighter = highlighter;
@@ -84644,7 +84853,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
84644
84853
  if (dir === "ltr") this.spreads.style.flexDirection = "row";
84645
84854
  this.keyboardEventHandler.rtl = dir === "rtl";
84646
84855
  if (this.api?.direction) this.api?.direction(dir);
84647
- this.emit("direction", dir);
84856
+ this.emit(ReaderEvent.Direction, dir);
84648
84857
  }
84649
84858
  }
84650
84859
  async start(mainElement, headerMenu, footerMenu) {
@@ -85421,12 +85630,12 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
85421
85630
  this.chapterTitle.innerHTML = "(" + this.currentChapterLink.title + ")";
85422
85631
  if (this.api?.chapterInfo)
85423
85632
  this.api.chapterInfo(this.currentChapterLink.title);
85424
- this.emit("chapterinfo", this.currentChapterLink.title);
85633
+ this.emit(ReaderEvent.ChapterInfo, this.currentChapterLink.title);
85425
85634
  } else {
85426
85635
  if (this.chapterTitle)
85427
85636
  this.chapterTitle.innerHTML = "(Current Chapter)";
85428
85637
  if (this.api?.chapterInfo) this.api.chapterInfo(void 0);
85429
- this.emit("chapterinfo", void 0);
85638
+ this.emit(ReaderEvent.ChapterInfo, void 0);
85430
85639
  }
85431
85640
  await this.injectInjectablesIntoIframeHead(iframe);
85432
85641
  if (this.view?.layout !== "fixed" && this.highlighter !== void 0) {
@@ -85598,6 +85807,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
85598
85807
  if (this.api?.onError) {
85599
85808
  const trueError = e7 instanceof Error ? e7 : typeof e7 === "string" ? new Error(e7) : new Error("An unknown error occurred in the IFrameNavigator.");
85600
85809
  this.api.onError(trueError);
85810
+ this.emit(ReaderEvent.Error, trueError);
85601
85811
  } else {
85602
85812
  if (this.errorMessage) this.errorMessage.style.display = "block";
85603
85813
  if (this.isLoading) {
@@ -86058,7 +86268,11 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86058
86268
  }
86059
86269
  stopReadAlong() {
86060
86270
  if (this.rights.enableMediaOverlays && this.mediaOverlayModule !== void 0 && this.hasMediaOverlays) {
86271
+ const wasPlaying = this.mediaOverlayModule.settings.playing;
86061
86272
  this.mediaOverlayModule?.stopReadAloud();
86273
+ if (wasPlaying) {
86274
+ this.emit(ReaderEvent.ReadAlongStopped, "stopped");
86275
+ }
86062
86276
  }
86063
86277
  }
86064
86278
  pauseReadAloud() {
@@ -86294,7 +86508,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86294
86508
  }
86295
86509
  handleClickThrough(event) {
86296
86510
  if (this.api?.clickThrough) this.api?.clickThrough(event);
86297
- this.emit("click", event);
86511
+ this.emit(ReaderEvent.Click, event);
86298
86512
  }
86299
86513
  handleInternalLink(event) {
86300
86514
  const element = event.target;
@@ -86493,7 +86707,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86493
86707
  if (this.api?.positionInfo) {
86494
86708
  this.api.positionInfo(locator);
86495
86709
  }
86496
- this.emit("positioninfo", locator);
86710
+ this.emit(ReaderEvent.PositionInfo, locator);
86497
86711
  }
86498
86712
  } else {
86499
86713
  if (this.chapterPosition) this.chapterPosition.innerHTML = "";
@@ -86577,7 +86791,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86577
86791
  }
86578
86792
  handleKeydownFallthrough(event) {
86579
86793
  if (this.api?.keydownFallthrough) this.api?.keydownFallthrough(event);
86580
- this.emit("keydown", event);
86794
+ this.emit(ReaderEvent.KeyDown, event);
86581
86795
  }
86582
86796
  hideView() {
86583
86797
  if (this.view?.layout !== "fixed") {
@@ -86737,12 +86951,12 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86737
86951
  this.chapterTitle.innerHTML = "(" + this.currentChapterLink.title + ")";
86738
86952
  if (this.api?.chapterInfo)
86739
86953
  this.api.chapterInfo(this.currentChapterLink.title);
86740
- this.emit("chapterinfo", this.currentChapterLink.title);
86954
+ this.emit(ReaderEvent.ChapterInfo, this.currentChapterLink.title);
86741
86955
  } else {
86742
86956
  if (this.chapterTitle)
86743
86957
  this.chapterTitle.innerHTML = "(Current Chapter)";
86744
86958
  if (this.api?.chapterInfo) this.api.chapterInfo(void 0);
86745
- this.emit("chapterinfo", void 0);
86959
+ this.emit(ReaderEvent.ChapterInfo, void 0);
86746
86960
  }
86747
86961
  await this.updatePositionInfo();
86748
86962
  } else {
@@ -86801,7 +87015,9 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86801
87015
  if (this.previousChapterTopAnchorElement)
86802
87016
  this.previousChapterTopAnchorElement.style.display = "none";
86803
87017
  if (this.api?.resourceFitsScreen) this.api?.resourceFitsScreen();
86804
- this.emit("resource.fits");
87018
+ this.emit(ReaderEvent.ResourceFits, {
87019
+ href: this.currentChapterLink.href
87020
+ });
86805
87021
  } else {
86806
87022
  this.settings.isPaginated().then((paginated) => {
86807
87023
  if (!paginated) {
@@ -86888,17 +87104,25 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86888
87104
  this.view?.padOddColumns?.();
86889
87105
  if (this.view?.atStart() && this.view?.atEnd()) {
86890
87106
  if (this.api?.resourceFitsScreen) this.api?.resourceFitsScreen();
86891
- this.emit("resource.fits");
87107
+ this.emit(ReaderEvent.ResourceFits, {
87108
+ href: this.currentChapterLink.href
87109
+ });
86892
87110
  } else if (this.view?.atEnd()) {
86893
87111
  if (this.api?.resourceAtEnd) this.api?.resourceAtEnd();
86894
- this.emit("resource.end");
87112
+ this.emit(ReaderEvent.ResourceEnd, {
87113
+ href: this.currentChapterLink.href
87114
+ });
86895
87115
  } else if (this.view?.atStart()) {
86896
87116
  if (this.api?.resourceAtStart) this.api?.resourceAtStart();
86897
- this.emit("resource.start");
87117
+ this.emit(ReaderEvent.ResourceStart, {
87118
+ href: this.currentChapterLink.href
87119
+ });
86898
87120
  }
86899
87121
  }
86900
87122
  if (this.api?.resourceReady) this.api?.resourceReady();
86901
- this.emit("resource.ready");
87123
+ this.emit(ReaderEvent.ResourceReady, {
87124
+ href: this.currentChapterLink.href
87125
+ });
86902
87126
  }, 150);
86903
87127
  }
86904
87128
  saveCurrentReadingPosition() {
@@ -86967,6 +87191,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86967
87191
  import_loglevel23.default.log("save last reading position", position);
86968
87192
  this.annotator.saveLastReadingPosition(position);
86969
87193
  }
87194
+ this.emit(ReaderEvent.LocationChanged, position);
86970
87195
  if (this.consumptionModule) {
86971
87196
  this.consumptionModule.continueReadingSession(position);
86972
87197
  }
@@ -88373,11 +88598,13 @@ function updateConfig(rights, publication) {
88373
88598
  }
88374
88599
 
88375
88600
  // src/index.ts
88601
+ init_Events();
88376
88602
  var index_default = D2Reader;
88377
88603
  var load = D2Reader.load;
88378
88604
  export {
88379
88605
  AnnotationMarker,
88380
88606
  Link,
88607
+ ReaderEvent,
88381
88608
  index_default as default,
88382
88609
  load
88383
88610
  };