@d-i-t-a/reader 3.0.0-alpha.6 → 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) {
@@ -14676,7 +14739,7 @@ var require_lodash = __commonJS({
14676
14739
  } else if (isPlainObject(srcValue) || isArguments(srcValue)) {
14677
14740
  newValue = objValue;
14678
14741
  if (isArguments(objValue)) {
14679
- newValue = toPlainObject(objValue);
14742
+ newValue = toPlainObject2(objValue);
14680
14743
  } else if (!isObject(objValue) || isFunction(objValue)) {
14681
14744
  newValue = initCloneObject(srcValue);
14682
14745
  }
@@ -17317,7 +17380,7 @@ var require_lodash = __commonJS({
17317
17380
  var isBinary = reIsBinary.test(value);
17318
17381
  return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
17319
17382
  }
17320
- function toPlainObject(value) {
17383
+ function toPlainObject2(value) {
17321
17384
  return copyObject(value, keysIn(value));
17322
17385
  }
17323
17386
  function toSafeInteger(value) {
@@ -18197,7 +18260,7 @@ var require_lodash = __commonJS({
18197
18260
  lodash4.toPairs = toPairs;
18198
18261
  lodash4.toPairsIn = toPairsIn;
18199
18262
  lodash4.toPath = toPath;
18200
- lodash4.toPlainObject = toPlainObject;
18263
+ lodash4.toPlainObject = toPlainObject2;
18201
18264
  lodash4.transform = transform;
18202
18265
  lodash4.unary = unary;
18203
18266
  lodash4.union = union;
@@ -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) {
@@ -68637,7 +68708,7 @@ var Link = class extends U {
68637
68708
  // src/model/v3/Publication.ts
68638
68709
  function toLink(link) {
68639
68710
  if (link instanceof Link) return link;
68640
- return Object.assign(new Link({ href: link.href }), {
68711
+ return new Link({
68641
68712
  href: link.href,
68642
68713
  templated: link.templated,
68643
68714
  type: link.type,
@@ -68663,6 +68734,27 @@ var Publication = class _Publication {
68663
68734
  this.manifest = manifest;
68664
68735
  this.manifestUrl = manifestUrl;
68665
68736
  }
68737
+ /**
68738
+ * Create a Publication from a raw JSON object.
68739
+ * Handles both RWPM (camelCase) and legacy (PascalCase) key formats.
68740
+ * Returns null if the JSON cannot be parsed.
68741
+ */
68742
+ static fromJSON(json, url) {
68743
+ const normalized = {
68744
+ metadata: json.metadata ?? json.Metadata ?? { title: "" },
68745
+ links: json.links ?? json.Links ?? [],
68746
+ readingOrder: json.readingOrder ?? json.spine ?? json.Spine ?? [],
68747
+ resources: json.resources ?? json.Resources,
68748
+ toc: json.toc ?? json.TOC
68749
+ };
68750
+ if (!normalized.metadata.title) {
68751
+ normalized.metadata.title = normalized.metadata.Title ?? "";
68752
+ }
68753
+ const manifest = Ue.deserialize(normalized);
68754
+ if (!manifest) return null;
68755
+ manifest.setSelfLink(url.href);
68756
+ return new _Publication(manifest, url);
68757
+ }
68666
68758
  static async fromUrl(url, requestConfig) {
68667
68759
  const response = await fetch(url.href, requestConfig);
68668
68760
  const manifestJSON = await response.json();
@@ -68717,7 +68809,7 @@ var Publication = class _Publication {
68717
68809
  // ── Layout detection ─────────────────────────────────────────
68718
68810
  get isFixedLayout() {
68719
68811
  if (this.metadata?.layout === "fixed") return true;
68720
- const renditionLayout = this.metadata?.otherMetadata?.["rendition:layout"];
68812
+ const renditionLayout = this.metadata?.otherMetadata?.["rendition:layout"] ?? this.metadata?.otherMetadata?.rendition?.layout;
68721
68813
  return renditionLayout === "pre-paginated" || renditionLayout === "fixed";
68722
68814
  }
68723
68815
  get isReflowable() {
@@ -71591,6 +71683,9 @@ var import_debounce2 = __toESM(require_debounce());
71591
71683
  // src/modules/highlight/common/highlight.ts
71592
71684
  init_polyfills();
71593
71685
 
71686
+ // src/modules/highlight/TextHighlighter.ts
71687
+ init_Events();
71688
+
71594
71689
  // src/modules/highlight/common/rect-utils.ts
71595
71690
  init_polyfills();
71596
71691
  var import_loglevel3 = __toESM(require_loglevel());
@@ -72557,18 +72652,25 @@ var TextHighlighter = class _TextHighlighter {
72557
72652
  if (!this.isSelectionMenuOpen) {
72558
72653
  this.isSelectionMenuOpen = true;
72559
72654
  if (this.api?.selectionMenuOpen) this.api?.selectionMenuOpen();
72560
- 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
+ }
72561
72663
  }
72562
72664
  }, 100);
72563
72665
  this.selectionMenuClosed = (0, import_debounce2.default)(() => {
72564
72666
  if (this.isSelectionMenuOpen) {
72565
72667
  this.isSelectionMenuOpen = false;
72566
72668
  if (this.api?.selectionMenuClose) this.api?.selectionMenuClose();
72567
- this.navigator.emit("toolbox.closed", "closed");
72669
+ this.navigator.emit(ReaderEvent.ToolboxClosed, "closed");
72568
72670
  }
72569
72671
  }, 100);
72570
- this.selection = (0, import_debounce2.default)((text, selection) => {
72571
- 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) => {
72572
72674
  }, 100);
72573
72675
  this.getScrollingElement = (doc) => {
72574
72676
  if (doc?.scrollingElement) {
@@ -73548,6 +73650,10 @@ var TextHighlighter = class _TextHighlighter {
73548
73650
  if (menuItem?.note) {
73549
73651
  if (anno.highlight) {
73550
73652
  self3.navigator.annotationModule?.api?.addCommentToAnnotation(anno).then((result) => {
73653
+ self3.navigator.emit(
73654
+ ReaderEvent.AnnotationCommentAdded,
73655
+ result
73656
+ );
73551
73657
  self3.navigator.annotationModule?.updateAnnotation(result).then(async () => {
73552
73658
  import_loglevel5.default.log(
73553
73659
  "update highlight " + result.id
@@ -74340,6 +74446,7 @@ var TextHighlighter = class _TextHighlighter {
74340
74446
  if (payload.highlight.type === 0 /* Annotation */) {
74341
74447
  this.navigator.annotationModule?.api?.selectedAnnotation(anno).then(async () => {
74342
74448
  });
74449
+ this.navigator.emit(ReaderEvent.AnnotationSelected, anno);
74343
74450
  }
74344
74451
  if (anno?.id) {
74345
74452
  import_loglevel5.default.log("selected highlight " + anno.id);
@@ -74351,6 +74458,10 @@ var TextHighlighter = class _TextHighlighter {
74351
74458
  if (getComputedStyle(toolbox).display === "none") {
74352
74459
  let noteH = function() {
74353
74460
  self2.navigator.annotationModule?.api?.addCommentToAnnotation(anno).then((result) => {
74461
+ self2.navigator.emit(
74462
+ ReaderEvent.AnnotationCommentAdded,
74463
+ result
74464
+ );
74354
74465
  self2.navigator.annotationModule?.updateAnnotation(result).then(async () => {
74355
74466
  import_loglevel5.default.log("update highlight " + result.id);
74356
74467
  if (toolbox) {
@@ -74453,7 +74564,11 @@ var TextHighlighter = class _TextHighlighter {
74453
74564
  lodash.omit(result, "callbacks"),
74454
74565
  lodash.omit(foundHighlight, "definition")
74455
74566
  );
74456
- this.navigator.emit("definition.click", result, foundHighlight);
74567
+ this.navigator.emit(
74568
+ ReaderEvent.DefinitionClick,
74569
+ result,
74570
+ foundHighlight
74571
+ );
74457
74572
  }
74458
74573
  }
74459
74574
  }
@@ -75020,6 +75135,7 @@ var TextHighlighter = class _TextHighlighter {
75020
75135
  );
75021
75136
  self2.navigator.annotationModule?.api?.selectedAnnotation(anno).then(async () => {
75022
75137
  });
75138
+ self2.navigator.emit(ReaderEvent.AnnotationSelected, anno);
75023
75139
  } else if (self2.navigator.rights.enableBookmarks) {
75024
75140
  anno = await self2.navigator.bookmarkModule?.getAnnotationByID(
75025
75141
  highlight.id
@@ -75238,6 +75354,7 @@ var import_loglevel8 = __toESM(require_loglevel());
75238
75354
 
75239
75355
  // src/modules/consumption/ConsumptionModule.ts
75240
75356
  init_polyfills();
75357
+ init_Events();
75241
75358
  var import_loglevel7 = __toESM(require_loglevel());
75242
75359
  var ConsumptionModule = class {
75243
75360
  constructor(publication, properties, api) {
@@ -75288,6 +75405,7 @@ var ConsumptionModule = class {
75288
75405
  }
75289
75406
  trackAction(locator, action) {
75290
75407
  this.api?.actionTracked(locator, action);
75408
+ this.navigator.emit(ReaderEvent.ActionTracked, { locator, action });
75291
75409
  }
75292
75410
  startReadingSession(locator) {
75293
75411
  if (this.firstReadingLocator && this.lastReadingLocator) {
@@ -75379,6 +75497,7 @@ var ConsumptionModule = class {
75379
75497
  this.currSeconds++;
75380
75498
  if (this.currSeconds === this.properties.idleTimeout) {
75381
75499
  this.api?.idleSince(this.currSeconds);
75500
+ this.navigator.emit(ReaderEvent.IdleSince, this.currSeconds);
75382
75501
  if (this.startResearchTimer !== void 0) {
75383
75502
  this.updateResearchSession();
75384
75503
  } else {
@@ -75400,6 +75519,7 @@ var ConsumptionModule = class {
75400
75519
  };
75401
75520
 
75402
75521
  // src/modules/AnnotationModule.ts
75522
+ init_Events();
75403
75523
  var AnnotationModule = class _AnnotationModule {
75404
75524
  constructor(annotator, rights, publication, initialAnnotations, properties, highlighter, api, headerMenu) {
75405
75525
  this.hide = findElement(
@@ -75610,9 +75730,11 @@ var AnnotationModule = class _AnnotationModule {
75610
75730
  }
75611
75731
  async deleteAnnotation(highlight) {
75612
75732
  await this.deleteLocalHighlight(highlight.id);
75733
+ this.navigator.emit(ReaderEvent.AnnotationDeleted, highlight);
75613
75734
  }
75614
75735
  async addAnnotation(highlight) {
75615
75736
  await this.annotator?.saveAnnotation(highlight);
75737
+ this.navigator.emit(ReaderEvent.AnnotationCreated, highlight);
75616
75738
  await this.showHighlights();
75617
75739
  await this.drawHighlights();
75618
75740
  }
@@ -75620,27 +75742,33 @@ var AnnotationModule = class _AnnotationModule {
75620
75742
  if (this.api?.deleteAnnotation) {
75621
75743
  this.api?.deleteAnnotation(highlight).then(async () => {
75622
75744
  this.deleteLocalHighlight(highlight.id);
75745
+ this.navigator.emit(ReaderEvent.AnnotationDeleted, highlight);
75623
75746
  });
75624
75747
  } else {
75625
75748
  this.deleteLocalHighlight(highlight.id);
75749
+ this.navigator.emit(ReaderEvent.AnnotationDeleted, highlight);
75626
75750
  }
75627
75751
  }
75628
75752
  async deleteSelectedHighlight(highlight) {
75629
75753
  if (this.api?.deleteAnnotation) {
75630
75754
  this.api.deleteAnnotation(highlight).then(async () => {
75631
75755
  this.deleteLocalHighlight(highlight.id);
75756
+ this.navigator.emit(ReaderEvent.AnnotationDeleted, highlight);
75632
75757
  });
75633
75758
  } else {
75634
75759
  this.deleteLocalHighlight(highlight.id);
75760
+ this.navigator.emit(ReaderEvent.AnnotationDeleted, highlight);
75635
75761
  }
75636
75762
  }
75637
75763
  async updateAnnotation(highlight) {
75638
75764
  if (this.api?.updateAnnotation) {
75639
75765
  this.api.updateAnnotation(highlight).then(async () => {
75640
75766
  this.updateLocalHighlight(highlight);
75767
+ this.navigator.emit(ReaderEvent.AnnotationUpdated, highlight);
75641
75768
  });
75642
75769
  } else {
75643
75770
  this.updateLocalHighlight(highlight);
75771
+ this.navigator.emit(ReaderEvent.AnnotationUpdated, highlight);
75644
75772
  }
75645
75773
  }
75646
75774
  async saveAnnotation(highlight) {
@@ -75718,6 +75846,7 @@ var AnnotationModule = class _AnnotationModule {
75718
75846
  try {
75719
75847
  let result = await this.api.addAnnotation(annotation);
75720
75848
  const saved = await this.annotator.saveAnnotation(result);
75849
+ this.navigator.emit(ReaderEvent.AnnotationCreated, saved);
75721
75850
  await this.showHighlights();
75722
75851
  await this.drawHighlights();
75723
75852
  return new Promise((resolve) => resolve(saved));
@@ -75727,6 +75856,7 @@ var AnnotationModule = class _AnnotationModule {
75727
75856
  }
75728
75857
  } else {
75729
75858
  const saved = await this.annotator.saveAnnotation(annotation);
75859
+ this.navigator.emit(ReaderEvent.AnnotationCreated, saved);
75730
75860
  await this.showHighlights();
75731
75861
  await this.drawHighlights();
75732
75862
  return new Promise((resolve) => resolve(saved));
@@ -76227,6 +76357,7 @@ init_HTMLUtilities();
76227
76357
  init_EventHandler();
76228
76358
  init_IconLib();
76229
76359
  var import_loglevel9 = __toESM(require_loglevel());
76360
+ init_Events();
76230
76361
  var BookmarkModule = class _BookmarkModule {
76231
76362
  static async create(config2) {
76232
76363
  const module = new this(
@@ -76312,12 +76443,14 @@ var BookmarkModule = class _BookmarkModule {
76312
76443
  await this.api?.deleteBookmark(bookmark);
76313
76444
  let deleted = await this.annotator.deleteBookmark(bookmark);
76314
76445
  import_loglevel9.default.log("Bookmark deleted " + JSON.stringify(deleted));
76446
+ this.navigator.emit(ReaderEvent.BookmarkDeleted, bookmark);
76315
76447
  await this.showBookmarks();
76316
76448
  await this.drawBookmarks();
76317
76449
  return deleted;
76318
76450
  } else {
76319
76451
  let deleted = await this.annotator.deleteBookmark(bookmark);
76320
76452
  import_loglevel9.default.log("Bookmark deleted " + JSON.stringify(deleted));
76453
+ this.navigator.emit(ReaderEvent.BookmarkDeleted, bookmark);
76321
76454
  await this.showBookmarks();
76322
76455
  await this.drawBookmarks();
76323
76456
  return deleted;
@@ -76392,12 +76525,14 @@ var BookmarkModule = class _BookmarkModule {
76392
76525
  import_loglevel9.default.log(bookmark);
76393
76526
  let saved = this.annotator.saveBookmark(bookmark);
76394
76527
  import_loglevel9.default.log("Bookmark added " + JSON.stringify(saved));
76528
+ this.navigator.emit(ReaderEvent.BookmarkCreated, bookmark);
76395
76529
  this.showBookmarks();
76396
76530
  await this.drawBookmarks();
76397
76531
  return saved;
76398
76532
  } else {
76399
76533
  let saved = this.annotator.saveBookmark(bookmark);
76400
76534
  import_loglevel9.default.log("Bookmark added " + JSON.stringify(saved));
76535
+ this.navigator.emit(ReaderEvent.BookmarkCreated, bookmark);
76401
76536
  this.showBookmarks();
76402
76537
  await this.drawBookmarks();
76403
76538
  return saved;
@@ -76592,11 +76727,13 @@ var BookmarkModule = class _BookmarkModule {
76592
76727
  if (this.api?.addBookmark) {
76593
76728
  let result = await this.api.addBookmark(annotation);
76594
76729
  const saved = await this.annotator.saveAnnotation(result);
76730
+ this.navigator.emit(ReaderEvent.BookmarkCreated, annotation);
76595
76731
  await this.showBookmarks();
76596
76732
  await this.drawBookmarks();
76597
76733
  return new Promise((resolve) => resolve(saved));
76598
76734
  } else {
76599
76735
  const saved = await this.annotator.saveAnnotation(annotation);
76736
+ this.navigator.emit(ReaderEvent.BookmarkCreated, annotation);
76600
76737
  await this.showBookmarks();
76601
76738
  await this.drawBookmarks();
76602
76739
  return new Promise((resolve) => resolve(saved));
@@ -76886,6 +77023,7 @@ var BookmarkModule = class _BookmarkModule {
76886
77023
 
76887
77024
  // src/modules/mediaoverlays/MediaOverlayModule.ts
76888
77025
  init_polyfills();
77026
+ init_Events();
76889
77027
 
76890
77028
  // src/model/v3/MediaOverlayNode.ts
76891
77029
  init_polyfills();
@@ -76921,16 +77059,6 @@ var MediaOverlayNode = class _MediaOverlayNode {
76921
77059
  }
76922
77060
  };
76923
77061
 
76924
- // src/utils/JsonUtil.ts
76925
- init_polyfills();
76926
- function TaJsonDeserialize(json, type) {
76927
- if (type && typeof type.deserialize === "function") {
76928
- const result = type.deserialize(json);
76929
- if (result) return result;
76930
- }
76931
- return Object.assign(new type(), json);
76932
- }
76933
-
76934
77062
  // src/modules/mediaoverlays/MediaOverlaySettings.ts
76935
77063
  init_polyfills();
76936
77064
  init_HTMLUtilities();
@@ -77341,6 +77469,7 @@ var MediaOverlayModule = class {
77341
77469
  config2.settings,
77342
77470
  config2
77343
77471
  );
77472
+ mediaOverlay.api = config2.api;
77344
77473
  mediaOverlay.start();
77345
77474
  return mediaOverlay;
77346
77475
  }
@@ -77393,10 +77522,7 @@ var MediaOverlayModule = class {
77393
77522
  import_loglevel11.default.log("## moJson" + moJson);
77394
77523
  return;
77395
77524
  }
77396
- link.mediaOverlayNode = TaJsonDeserialize(
77397
- moJson,
77398
- MediaOverlayNode
77399
- );
77525
+ link.mediaOverlayNode = MediaOverlayNode.deserialize(moJson);
77400
77526
  link.mediaOverlayNode.initialized = true;
77401
77527
  const href = link.hrefDecoded || link.href;
77402
77528
  const hrefUrlObj = new URL("https://dita.digital/" + href);
@@ -77414,10 +77540,28 @@ var MediaOverlayModule = class {
77414
77540
  await this.playLink();
77415
77541
  } else {
77416
77542
  if (this.settings.autoTurn && this.settings.playing) {
77417
- if (this.audioElement) {
77418
- 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
+ });
77419
77558
  }
77420
- 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
+ });
77421
77565
  } else {
77422
77566
  await this.stopReadAloud();
77423
77567
  }
@@ -77475,10 +77619,7 @@ var MediaOverlayModule = class {
77475
77619
  if (response.ok) {
77476
77620
  const moJson = await response.json();
77477
77621
  if (moJson) {
77478
- link.mediaOverlayNode = TaJsonDeserialize(
77479
- moJson,
77480
- MediaOverlayNode
77481
- );
77622
+ link.mediaOverlayNode = MediaOverlayNode.deserialize(moJson);
77482
77623
  link.mediaOverlayNode.initialized = true;
77483
77624
  }
77484
77625
  }
@@ -77533,6 +77674,10 @@ var MediaOverlayModule = class {
77533
77674
  if (this.play) this.play.style.display = "none";
77534
77675
  if (this.pause) this.pause.style.removeProperty("display");
77535
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
+ });
77536
77681
  }
77537
77682
  }
77538
77683
  async stopReadAloud() {
@@ -77550,6 +77695,10 @@ var MediaOverlayModule = class {
77550
77695
  this.audioElement.pause();
77551
77696
  if (this.play) this.play.style.removeProperty("display");
77552
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
+ });
77553
77702
  }
77554
77703
  }
77555
77704
  async resumeReadAloud() {
@@ -77558,6 +77707,10 @@ var MediaOverlayModule = class {
77558
77707
  await this.audioElement.play();
77559
77708
  if (this.play) this.play.style.display = "none";
77560
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
+ });
77561
77714
  }
77562
77715
  }
77563
77716
  findDepthFirstTextAudioPair(textHref, mo, textFragmentIDChain) {
@@ -77668,8 +77821,25 @@ var MediaOverlayModule = class {
77668
77821
  } else {
77669
77822
  this.audioElement.pause();
77670
77823
  if (this.settings.autoTurn && this.settings.playing) {
77671
- this.audioElement.pause();
77672
- 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
+ });
77673
77843
  } else {
77674
77844
  this.stopReadAloud();
77675
77845
  }
@@ -81801,6 +81971,7 @@ var TTSSettings = class {
81801
81971
 
81802
81972
  // src/navigator/IFrameNavigator.ts
81803
81973
  init_polyfills();
81974
+ init_Events();
81804
81975
  init_EventHandler();
81805
81976
  init_HTMLUtilities();
81806
81977
  init_HTMLTemplates();
@@ -82279,6 +82450,7 @@ var PageBreakModule = class {
82279
82450
 
82280
82451
  // src/modules/TTS/TTSModule2.ts
82281
82452
  init_polyfills();
82453
+ init_Events();
82282
82454
  init_HTMLUtilities();
82283
82455
  init_EventHandler();
82284
82456
  var import_sanitize_html2 = __toESM(require_sanitize_html());
@@ -82449,9 +82621,11 @@ var TTSModule2 = class {
82449
82621
  });
82450
82622
  }
82451
82623
  cancel(api = true) {
82452
- if (api) {
82624
+ if (api && this.speaking) {
82453
82625
  if (this.api?.stopped) this.api?.stopped();
82454
- this.navigator.emit("readaloud.stopped", "stopped");
82626
+ this.navigator.emit(ReaderEvent.ReadAloudStopped, "stopped", {
82627
+ locator: this.navigator.currentLocator()
82628
+ });
82455
82629
  }
82456
82630
  this.userScrolled = false;
82457
82631
  this.speaking = false;
@@ -82470,7 +82644,9 @@ var TTSModule2 = class {
82470
82644
  }
82471
82645
  }
82472
82646
  if (this.api?.started) this.api?.started();
82473
- this.navigator.emit("readaloud.started", "started");
82647
+ this.navigator.emit(ReaderEvent.ReadAloudStarted, "started", {
82648
+ locator: this.navigator.currentLocator()
82649
+ });
82474
82650
  const self2 = this;
82475
82651
  this.userScrolled = false;
82476
82652
  this.cancel(false);
@@ -82639,14 +82815,18 @@ var TTSModule2 = class {
82639
82815
  import_loglevel18.default.log("utterance ended");
82640
82816
  self2.highlighter.doneSpeaking();
82641
82817
  self2.api?.finished();
82642
- self2.navigator.emit("readaloud.finished", "finished");
82818
+ self2.navigator.emit(ReaderEvent.ReadAloudFinished, "finished", {
82819
+ locator: this.navigator.currentLocator()
82820
+ });
82643
82821
  }
82644
82822
  }
82645
82823
  } else {
82646
82824
  import_loglevel18.default.log("utterance ended");
82647
82825
  self2.highlighter.doneSpeaking();
82648
82826
  self2.api?.finished();
82649
- self2.navigator.emit("readaloud.finished", "finished");
82827
+ self2.navigator.emit(ReaderEvent.ReadAloudFinished, "finished", {
82828
+ locator: this.navigator.currentLocator()
82829
+ });
82650
82830
  }
82651
82831
  };
82652
82832
  }
@@ -82753,7 +82933,9 @@ var TTSModule2 = class {
82753
82933
  this.scrollPartial = true;
82754
82934
  this.cancel(false);
82755
82935
  if (this.api?.started) this.api?.started();
82756
- this.navigator.emit("readaloud.started", "started");
82936
+ this.navigator.emit(ReaderEvent.ReadAloudStarted, "started", {
82937
+ locator: this.navigator.currentLocator()
82938
+ });
82757
82939
  let self2 = this;
82758
82940
  let iframe = document.querySelector(
82759
82941
  "main#iframe-wrapper iframe"
@@ -82813,7 +82995,9 @@ var TTSModule2 = class {
82813
82995
  speakPause() {
82814
82996
  if (window.speechSynthesis.speaking) {
82815
82997
  if (this.api?.paused) this.api?.paused();
82816
- this.navigator.emit("readaloud.paused", "paused");
82998
+ this.navigator.emit(ReaderEvent.ReadAloudPaused, "paused", {
82999
+ locator: this.navigator.currentLocator()
83000
+ });
82817
83001
  this.userScrolled = false;
82818
83002
  window.speechSynthesis.pause();
82819
83003
  this.speaking = false;
@@ -82826,7 +83010,9 @@ var TTSModule2 = class {
82826
83010
  speakResume() {
82827
83011
  if (window.speechSynthesis.speaking) {
82828
83012
  if (this.api?.resumed) this.api?.resumed();
82829
- this.navigator.emit("readaloud.resumed", "resumed");
83013
+ this.navigator.emit(ReaderEvent.ReadAloudResumed, "resumed", {
83014
+ locator: this.navigator.currentLocator()
83015
+ });
82830
83016
  this.userScrolled = false;
82831
83017
  window.speechSynthesis.resume();
82832
83018
  this.speaking = true;
@@ -83264,6 +83450,7 @@ function getTtsQueueItemRefText(obj) {
83264
83450
  // src/modules/search/DefinitionsModule.ts
83265
83451
  init_polyfills();
83266
83452
  var lodash3 = __toESM(require_lodash());
83453
+ init_Events();
83267
83454
  var import_debounce6 = __toESM(require_debounce());
83268
83455
  var import_loglevel19 = __toESM(require_loglevel());
83269
83456
  var DefinitionsModule = class {
@@ -83356,7 +83543,9 @@ var DefinitionsModule = class {
83356
83543
  await this.searchAndPaint(item, async (result) => {
83357
83544
  if (this.api?.success) {
83358
83545
  this.api?.success(lodash3.omit(item, "callbacks"), result);
83359
- this.navigator.emit("definition.success", result);
83546
+ if (result && result.length > 0) {
83547
+ this.navigator.emit(ReaderEvent.DefinitionSuccess, result);
83548
+ }
83360
83549
  if (this.api?.visible) {
83361
83550
  result.forEach((highlight) => {
83362
83551
  let highlightParent = this.navigator.iframes[0].contentDocument?.querySelector(
@@ -83373,7 +83562,11 @@ var DefinitionsModule = class {
83373
83562
  lodash3.omit(item, "callbacks"),
83374
83563
  lodash3.omit(highlight, "definition")
83375
83564
  );
83376
- this.navigator.emit("definition.visible", item, highlight);
83565
+ this.navigator.emit(
83566
+ ReaderEvent.DefinitionVisible,
83567
+ item,
83568
+ highlight
83569
+ );
83377
83570
  }
83378
83571
  });
83379
83572
  },
@@ -84110,6 +84303,7 @@ var HistoryModule = class {
84110
84303
  // src/modules/citation/CitationModule.ts
84111
84304
  init_polyfills();
84112
84305
  var import_loglevel22 = __toESM(require_loglevel());
84306
+ init_Events();
84113
84307
  var CitationStyle = /* @__PURE__ */ ((CitationStyle2) => {
84114
84308
  CitationStyle2[CitationStyle2["Chicago"] = 0] = "Chicago";
84115
84309
  CitationStyle2[CitationStyle2["MLA"] = 1] = "MLA";
@@ -84155,7 +84349,13 @@ var CitationModule = class {
84155
84349
  tmp.innerHTML = textToClipboard;
84156
84350
  const plainText = tmp.textContent ?? tmp.innerText ?? textToClipboard;
84157
84351
  navigator.clipboard.writeText(plainText).then(
84158
- () => 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
+ },
84159
84359
  () => this.legacyCopyToClipboard(textToClipboard)
84160
84360
  );
84161
84361
  } else {
@@ -84182,8 +84382,16 @@ var CitationModule = class {
84182
84382
  document.body.removeChild(forExecElement);
84183
84383
  if (success) {
84184
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
+ );
84185
84389
  } else {
84186
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
+ );
84187
84395
  }
84188
84396
  }
84189
84397
  selectContent(element) {
@@ -84472,13 +84680,19 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
84472
84680
  this.checkResourcePosition = (0, import_debounce7.default)(() => {
84473
84681
  if (this.view?.atStart() && this.view?.atEnd()) {
84474
84682
  if (this.api?.resourceFitsScreen) this.api?.resourceFitsScreen();
84475
- this.emit("resource.fits");
84683
+ this.emit(ReaderEvent.ResourceFits, {
84684
+ href: this.currentChapterLink.href
84685
+ });
84476
84686
  } else if (this.view?.atEnd()) {
84477
84687
  if (this.api?.resourceAtEnd) this.api?.resourceAtEnd();
84478
- this.emit("resource.end");
84688
+ this.emit(ReaderEvent.ResourceEnd, {
84689
+ href: this.currentChapterLink.href
84690
+ });
84479
84691
  } else if (this.view?.atStart()) {
84480
84692
  if (this.api?.resourceAtStart) this.api?.resourceAtStart();
84481
- this.emit("resource.start");
84693
+ this.emit(ReaderEvent.ResourceStart, {
84694
+ href: this.currentChapterLink.href
84695
+ });
84482
84696
  }
84483
84697
  }, 200);
84484
84698
  this.highlighter = highlighter;
@@ -84639,7 +84853,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
84639
84853
  if (dir === "ltr") this.spreads.style.flexDirection = "row";
84640
84854
  this.keyboardEventHandler.rtl = dir === "rtl";
84641
84855
  if (this.api?.direction) this.api?.direction(dir);
84642
- this.emit("direction", dir);
84856
+ this.emit(ReaderEvent.Direction, dir);
84643
84857
  }
84644
84858
  }
84645
84859
  async start(mainElement, headerMenu, footerMenu) {
@@ -85416,12 +85630,12 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
85416
85630
  this.chapterTitle.innerHTML = "(" + this.currentChapterLink.title + ")";
85417
85631
  if (this.api?.chapterInfo)
85418
85632
  this.api.chapterInfo(this.currentChapterLink.title);
85419
- this.emit("chapterinfo", this.currentChapterLink.title);
85633
+ this.emit(ReaderEvent.ChapterInfo, this.currentChapterLink.title);
85420
85634
  } else {
85421
85635
  if (this.chapterTitle)
85422
85636
  this.chapterTitle.innerHTML = "(Current Chapter)";
85423
85637
  if (this.api?.chapterInfo) this.api.chapterInfo(void 0);
85424
- this.emit("chapterinfo", void 0);
85638
+ this.emit(ReaderEvent.ChapterInfo, void 0);
85425
85639
  }
85426
85640
  await this.injectInjectablesIntoIframeHead(iframe);
85427
85641
  if (this.view?.layout !== "fixed" && this.highlighter !== void 0) {
@@ -85593,6 +85807,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
85593
85807
  if (this.api?.onError) {
85594
85808
  const trueError = e7 instanceof Error ? e7 : typeof e7 === "string" ? new Error(e7) : new Error("An unknown error occurred in the IFrameNavigator.");
85595
85809
  this.api.onError(trueError);
85810
+ this.emit(ReaderEvent.Error, trueError);
85596
85811
  } else {
85597
85812
  if (this.errorMessage) this.errorMessage.style.display = "block";
85598
85813
  if (this.isLoading) {
@@ -86053,7 +86268,11 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86053
86268
  }
86054
86269
  stopReadAlong() {
86055
86270
  if (this.rights.enableMediaOverlays && this.mediaOverlayModule !== void 0 && this.hasMediaOverlays) {
86271
+ const wasPlaying = this.mediaOverlayModule.settings.playing;
86056
86272
  this.mediaOverlayModule?.stopReadAloud();
86273
+ if (wasPlaying) {
86274
+ this.emit(ReaderEvent.ReadAlongStopped, "stopped");
86275
+ }
86057
86276
  }
86058
86277
  }
86059
86278
  pauseReadAloud() {
@@ -86289,7 +86508,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86289
86508
  }
86290
86509
  handleClickThrough(event) {
86291
86510
  if (this.api?.clickThrough) this.api?.clickThrough(event);
86292
- this.emit("click", event);
86511
+ this.emit(ReaderEvent.Click, event);
86293
86512
  }
86294
86513
  handleInternalLink(event) {
86295
86514
  const element = event.target;
@@ -86488,7 +86707,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86488
86707
  if (this.api?.positionInfo) {
86489
86708
  this.api.positionInfo(locator);
86490
86709
  }
86491
- this.emit("positioninfo", locator);
86710
+ this.emit(ReaderEvent.PositionInfo, locator);
86492
86711
  }
86493
86712
  } else {
86494
86713
  if (this.chapterPosition) this.chapterPosition.innerHTML = "";
@@ -86572,7 +86791,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86572
86791
  }
86573
86792
  handleKeydownFallthrough(event) {
86574
86793
  if (this.api?.keydownFallthrough) this.api?.keydownFallthrough(event);
86575
- this.emit("keydown", event);
86794
+ this.emit(ReaderEvent.KeyDown, event);
86576
86795
  }
86577
86796
  hideView() {
86578
86797
  if (this.view?.layout !== "fixed") {
@@ -86732,12 +86951,12 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86732
86951
  this.chapterTitle.innerHTML = "(" + this.currentChapterLink.title + ")";
86733
86952
  if (this.api?.chapterInfo)
86734
86953
  this.api.chapterInfo(this.currentChapterLink.title);
86735
- this.emit("chapterinfo", this.currentChapterLink.title);
86954
+ this.emit(ReaderEvent.ChapterInfo, this.currentChapterLink.title);
86736
86955
  } else {
86737
86956
  if (this.chapterTitle)
86738
86957
  this.chapterTitle.innerHTML = "(Current Chapter)";
86739
86958
  if (this.api?.chapterInfo) this.api.chapterInfo(void 0);
86740
- this.emit("chapterinfo", void 0);
86959
+ this.emit(ReaderEvent.ChapterInfo, void 0);
86741
86960
  }
86742
86961
  await this.updatePositionInfo();
86743
86962
  } else {
@@ -86796,7 +87015,9 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86796
87015
  if (this.previousChapterTopAnchorElement)
86797
87016
  this.previousChapterTopAnchorElement.style.display = "none";
86798
87017
  if (this.api?.resourceFitsScreen) this.api?.resourceFitsScreen();
86799
- this.emit("resource.fits");
87018
+ this.emit(ReaderEvent.ResourceFits, {
87019
+ href: this.currentChapterLink.href
87020
+ });
86800
87021
  } else {
86801
87022
  this.settings.isPaginated().then((paginated) => {
86802
87023
  if (!paginated) {
@@ -86883,17 +87104,25 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86883
87104
  this.view?.padOddColumns?.();
86884
87105
  if (this.view?.atStart() && this.view?.atEnd()) {
86885
87106
  if (this.api?.resourceFitsScreen) this.api?.resourceFitsScreen();
86886
- this.emit("resource.fits");
87107
+ this.emit(ReaderEvent.ResourceFits, {
87108
+ href: this.currentChapterLink.href
87109
+ });
86887
87110
  } else if (this.view?.atEnd()) {
86888
87111
  if (this.api?.resourceAtEnd) this.api?.resourceAtEnd();
86889
- this.emit("resource.end");
87112
+ this.emit(ReaderEvent.ResourceEnd, {
87113
+ href: this.currentChapterLink.href
87114
+ });
86890
87115
  } else if (this.view?.atStart()) {
86891
87116
  if (this.api?.resourceAtStart) this.api?.resourceAtStart();
86892
- this.emit("resource.start");
87117
+ this.emit(ReaderEvent.ResourceStart, {
87118
+ href: this.currentChapterLink.href
87119
+ });
86893
87120
  }
86894
87121
  }
86895
87122
  if (this.api?.resourceReady) this.api?.resourceReady();
86896
- this.emit("resource.ready");
87123
+ this.emit(ReaderEvent.ResourceReady, {
87124
+ href: this.currentChapterLink.href
87125
+ });
86897
87126
  }, 150);
86898
87127
  }
86899
87128
  saveCurrentReadingPosition() {
@@ -86962,6 +87191,7 @@ var IFrameNavigator = class _IFrameNavigator extends eventemitter3_default {
86962
87191
  import_loglevel23.default.log("save last reading position", position);
86963
87192
  this.annotator.saveLastReadingPosition(position);
86964
87193
  }
87194
+ this.emit(ReaderEvent.LocationChanged, position);
86965
87195
  if (this.consumptionModule) {
86966
87196
  this.consumptionModule.continueReadingSession(position);
86967
87197
  }
@@ -87512,41 +87742,18 @@ init_HTMLUtilities();
87512
87742
 
87513
87743
  // src/model/Link.ts
87514
87744
  init_polyfills();
87515
- function convertAndCamel(o) {
87745
+ function toPlainObject(o) {
87516
87746
  if (o == null) return o;
87517
- if (o.items && Array.isArray(o.items)) {
87518
- return convertAndCamel(o.items);
87519
- }
87520
- let newO, origKey, newKey, value;
87521
- if (o instanceof Array) {
87522
- return o.map(function(value2) {
87523
- if (typeof value2 === "object") {
87524
- value2 = convertAndCamel(value2);
87525
- }
87526
- return value2;
87527
- });
87528
- } else {
87529
- newO = {};
87530
- for (origKey in o) {
87531
- if (o.hasOwnProperty(origKey)) {
87532
- newKey = (origKey.charAt(0).toLowerCase() + origKey.slice(1) || origKey).toString();
87533
- value = o[origKey];
87534
- if (value && value.items && Array.isArray(value.items)) {
87535
- value = convertAndCamel(value.items);
87536
- } else if (value instanceof Array || value !== null && value !== void 0 && value.constructor === Object) {
87537
- value = convertAndCamel(value);
87538
- }
87539
- if (newKey === "href1") {
87540
- newO["href"] = value;
87541
- } else if (newKey === "typeLink") {
87542
- newO["type"] = value;
87543
- } else {
87544
- newO[newKey] = value;
87545
- }
87546
- }
87547
- }
87747
+ if (o instanceof Set) return Array.from(o);
87748
+ if (o.items && Array.isArray(o.items)) return o.items.map(toPlainObject);
87749
+ if (Array.isArray(o)) return o.map(toPlainObject);
87750
+ if (typeof o !== "object") return o;
87751
+ const result = {};
87752
+ for (const key in o) {
87753
+ if (!o.hasOwnProperty(key)) continue;
87754
+ result[key] = toPlainObject(o[key]);
87548
87755
  }
87549
- return newO;
87756
+ return result;
87550
87757
  }
87551
87758
 
87552
87759
  // src/modules/highlight/LayerSettings.ts
@@ -88022,27 +88229,10 @@ var D2Reader = class _D2Reader {
88022
88229
  if (pubInput instanceof Publication) {
88023
88230
  publication = pubInput;
88024
88231
  } else {
88025
- const json = {
88026
- metadata: pubInput.metadata ?? pubInput.Metadata ?? { title: "" },
88027
- links: pubInput.links ?? pubInput.Links ?? [],
88028
- readingOrder: pubInput.readingOrder ?? pubInput.spine ?? pubInput.Spine ?? [],
88029
- resources: pubInput.resources ?? pubInput.Resources,
88030
- toc: pubInput.toc ?? pubInput.TOC
88031
- };
88032
- if (!json.metadata.title && !json.metadata.Title) {
88033
- json.metadata.title = "";
88034
- }
88035
- if (json.metadata.Title && !json.metadata.title) {
88036
- json.metadata.title = json.metadata.Title;
88037
- }
88038
- const manifest = Ue.deserialize(json);
88039
- if (!manifest) {
88040
- throw new Error("Failed to parse publication manifest from config");
88041
- }
88042
- manifest.setSelfLink(webPubManifestUrl.href);
88043
- publication = new Publication(manifest, new URL(webPubManifestUrl));
88232
+ publication = Publication.fromJSON(pubInput, webPubManifestUrl);
88044
88233
  }
88045
- } else {
88234
+ }
88235
+ if (!publication) {
88046
88236
  publication = await Publication.fromUrl(
88047
88237
  webPubManifestUrl,
88048
88238
  initialConfig.requestConfig
@@ -88266,19 +88456,19 @@ var D2Reader = class _D2Reader {
88266
88456
  }
88267
88457
  /** Table of Contents */
88268
88458
  get tableOfContents() {
88269
- return convertAndCamel(this.navigator.tableOfContents()) ?? [];
88459
+ return toPlainObject(this.navigator.tableOfContents()) ?? [];
88270
88460
  }
88271
88461
  /** Landmarks */
88272
88462
  get landmarks() {
88273
- return convertAndCamel(this.navigator.landmarks()) ?? [];
88463
+ return toPlainObject(this.navigator.landmarks()) ?? [];
88274
88464
  }
88275
88465
  /** Page List */
88276
88466
  get pageList() {
88277
- return convertAndCamel(this.navigator.pageList()) ?? [];
88467
+ return toPlainObject(this.navigator.pageList()) ?? [];
88278
88468
  }
88279
88469
  /** Reading Order or Spine */
88280
88470
  get readingOrder() {
88281
- return convertAndCamel(this.navigator.readingOrder()) ?? [];
88471
+ return toPlainObject(this.navigator.readingOrder()) ?? [];
88282
88472
  }
88283
88473
  /** Current Bookmarks */
88284
88474
  get bookmarks() {
@@ -88408,11 +88598,13 @@ function updateConfig(rights, publication) {
88408
88598
  }
88409
88599
 
88410
88600
  // src/index.ts
88601
+ init_Events();
88411
88602
  var index_default = D2Reader;
88412
88603
  var load = D2Reader.load;
88413
88604
  export {
88414
88605
  AnnotationMarker,
88415
88606
  Link,
88607
+ ReaderEvent,
88416
88608
  index_default as default,
88417
88609
  load
88418
88610
  };